I want a function that takes expressions of the following form: a$x and converts them to a[x].
In particular, consider the following test cases
exp = a$x + b$x$y + a$x[d] + a$x[d$y]
Should become, with some ToFunctionNotation:
ToFunctionNotation[exp] == a[x] + b[x][y] + a[x][d] + a[x][d[y]]
Note: I want to keep this as an expression for further processing. I tried using matches with SymbolName and string patterns, but couldn't figure it out.
$for the naming of the variables, then using http://mathematica.stackexchange.com/questions/30884/displaying-index-as-subscript-on-output-e-g-ci-c-i-with-notation-or for display and LaTex output (i.e.,a$x-> $a_x$ after the Notation is used. – jlperla Jun 12 '14 at 16:45StringReplace[exp, "$" -> "@"]does not result in your stated precedence ;-( – Yves Klett Jun 12 '14 at 16:45b$x$y->b[x][y]– jlperla Jun 12 '14 at 16:51a$1are used internally. If you use it yourself, it might lead to conflicts and random breakage. Generally, it's a bad idea to try to manipulate code as strings (e.g. rewrite names programmatically) in Mathematica. Expression rewriting is almost always better than string rewriting. – Szabolcs Jun 12 '14 at 17:12$character as the first character in a symbol name? Nothing would make me happier than to avoid the $, but I am limited in the symbol name separators available in mathematica. Of course, the_I would use in C++ doesn't work, and the ` as a separator introduces namespaces. Do I have any other options? All of this is to ensure that I can still do algebra with subscripts, hats, etc. and get it to display correctly, and I can't figure out any other ways. – jlperla Jun 12 '14 at 17:30Module[{a}, a]– Kuba Jun 12 '14 at 17:31$is not reserved as the first character. It is common practice to use$namesfor constants. You will run into trouble specifically when the$is preceded by something and followed by a number. If usinga[x]instead ofa$xreally doesn't work in your case, you can trya$x, but I definitely wouldn't trya$1. – Szabolcs Jun 12 '14 at 17:44Module[{a},a]approach? – jlperla Jun 12 '14 at 17:59