I came across another weird pattern matching behaviour:
a*b*c*d /. a*b -> 1
Out[554]= c d
a*b*c*d /. c*d -> 1
Out[555]= a b
a*b*c*d /. a*b -> 1 /. c*d -> 1
Out[556]= 1
a*b*c*d /. a*b | c*d -> 1
Out[557]= a b c d
Anyone have a clue why it no longer matches once I use Alternatives? Am I missing something obvious or is this worth a question on main?
@MartinEnder If you have a*b*c*d /. a*b -> 1then Mathematica is picking out the a and b although the general structure does not match.
@MartinEnder This behavior is connected to the Flat attribute.
Try
g[a, b, c, d] /. g[a, b] -> 1
and then
SetAttributes[g, Flat]
and the replacement above again.
@MartinEnder So what seems to happen is that Alternative prevents that all combinations are tried because basically a structure g[a,b,c,d] could come from all kinds of combinations with nested g
I'm aware that the first two examples work because of the flat attribute, but that doesn't explain to me why Alternatives prevents Mathematica from attempting the same matches.
Adding Flat to Alternatives does it: Unprotect[Alternatives]; SetAttributes[Alternatives, Flat]; SetAttributes[g, Flat]; g[a, b, c, d] //. (g[a, b ] | g[c, d]) -> 1 gives g[1,1]. So the question is why Alternatives is not Flat.
@R.M. I've always used latexmk for compilation, I believe it's included in TexLive. It takes care of any needed re-compilations automatically. I've also used it successfully with .tex files that make external commands to sed and awk. But mostly I just run pdflatex (latexmk figures out how many times it needs to run in order to get references and bibtex entries)
@BenNiehoff The biggest drawback of LaTeX in scientific writing is currently, that I'm in a dilemma. To write good English as a non-native speaker, I need to use an excellent grammar-checker, but such systems need to see plain text. This doesn't work if you have small formulas or even things like latex abbreviations in the text.
So I could write the text in a different system and add it to LaTeX later with all the cite, emph, etc commands which is annoying.
Or I write TeX first and check the text after compilation which is annoying too.
@halirutan I did start using Grammarly after you recommended it, but its suggestions aren't always correct. It likes to suggest too many commas (when the sentence would be fine either with or without that comma) and sometimes its suggestions are plainly wrong. It is true that when it makes a mistake, it often because of sentences that are too complicated.
@halirutan Your grammar sounds native to me, you probably don't need to worry as much as you think you do. My opinion (as someone who also does scientific writing and uses loads of formulas!) is that one should stick to simpler grammatical constructions anyway, and focus on writing in a way that flows more like speech. The end goal is to explain what you've done (as opposed to encode it, which is a style of writing I see a lot of)
@Szabolcs Yes, you still need to think. What I really like is that it points me to suspicious places and that I can double click on a word to get synonyms.
@halirutan I agree that spell checking LaTeX is a pain. I have practically given up on it. I know you don't have a perfect solution, but what is the best you could find? TeXStudio with LanguageTool?
TeXStudio seems to do decent spellchecking. I have no idea if it does grammar checking, but I've never seen a grammar checker that gives sensible results
@BenNiehoff Unfortunately there are lots of academics who are not satisfied until they managed to make their sentences convoluted and hard to understand. Or at least replace even everyday word with a synonym that I need to look up in the dictionary. I hate this.
@Szabolcs bleh, I hate that...the only thing worse are the ones who think they need to have a mathematical notation for everything, and that math written in words isn't real
@Szabolcs It seems to work with latest version of LT. Just download and unzip the package and in TS use Options -> Language Checking and point the LT Path to the languagetool-server.jar
Can someone point me to the question about creating graphical representations for own arbitrary expression e.g. how to recreate what e.g. Interpolation or LinearModelFit do with their output?
The display forms for objects like ClassifierFunction are nice clickable summary boxes
I like this, and now I'm trying to create my a custom version of this for my functions, so I dissected the code in the output cell and trimmed it down to this:
CellPrint@
Cell[BoxData[
Interpret...
Should (136098) be closed as a duplicate of (135952)? I can close it myself, but I'd rather not act unilaterally. rcollyer thinks it's the same bug, but didn't cast a close vote. Maybe didn't think of it, but it's left me in some doubt.
One of these questions again... how do I compute (analytically or numerically) minumum distance of two points on an algebraic surface, along the surface?
@BenNiehoff Just the points, but I guess at least one could find numerically some path between them by moving a point along the surface using NDSolve of a point with velocity always being projection of direction of destination point to the surface normal. Well, this wouldn't work if the projection is a zero vector.
@BenNiehoff Sometimes, when you read a paper, you get the sinking feeling that they actually don't want you to implement their results. So, not unlike patents... ;P
@J.M. haha, yes. This goes back to the earlier discussion about writing styles
From scanning the paper in the first link, it looks like the best generic option is to first put a mesh on your surface, then use graph theory algorithms to get a decent initial guess; then use Newton-Raphson and the geodesic equation to refine until you get the shortest path
In general... more I think of my problem (intelligent discretization of constructive solids geometry of algebraic surfaces), more it makes me think trying to find distances along the surface is an unnecessarily complex approach. And actually, even that most things beyond some sort of augmented marching cubes algorithm is not worth the effort.
I'm really somewhat disappointed of the fact Mma doesn't really have any serious attempt on discretizing semialgebraic sets better than essentially running marching cubes over them...
BTW, is there an (easy or "obvious") method to perform surface discretization on Mma so that mean distance between discretized and algebraic surfaces would be minimized, instead of maintaining discretized points on the surface?
let's simplify the question into a 2D circle. You can draw a triangle inside it with all vertices on the circle, but if you want to minimize average distance from the circle to the triangle (not just vertices but also edges), you want your triangle to be larger.
That may be a very expensive operation for generic surfaces, since you'll be asking to minimize a continuous integral
but there are probably algorithms that use points at both the vertices and the centroids of the faces, and then use some sort of weighted minimization between the two
there are approximation methods for surfaces that are similar to Simpson's parabola rule, but they are way more complicated, and I'm afraid I don't even remember the name of the book where I saw them