On Dec 3, 2008, at 7:38 PM, Jason Grout wrote: > > Robert Bradshaw wrote: >> On Dec 3, 2008, at 10:42 AM, Jason Grout wrote: >> >>> So, bringing up an issue that has come up before, there is no >>> way to do >>> the equivalent of the Hold or HoldAll commands in Mma? See >>> http://reference.wolfram.com/mathematica/ref/Hold.html? >>> q=Hold&lang=en >>> for example. >> >> Not without some preparsing magic, and even then it might be tricky >> as there is not a simple one-to-one correspondence between the python >> parse tree and the mathematical expression. > > Huh, maybe that's why it's so natural in Mathematica; their entire > language is literally a parse tree for the mathematical expression. > > Okay, here's some brainstorming that may not even make sense, or > may be > completely obvious... > > You know a lot more about the python parsing trees than I do, but > maybe > we could only pay attention to the subexpression tree formed by Sage > symbolic components? For example, surely the ginac parse tree is > fairly > close to the mathematical expression. > > Maybe the preparser could set a flag that tells any new symbolic > composition whether it should try to simplify itself or whether it > should just hold an inert copy of its arguments. Or maybe even > better, > we could attack the problem at the coercion level (since that is the > level that things are combined, like addition, etc.) If a global flag > is set, then something in the coercion system somehow uses inert > form of > operators, that basically just construct an expression tree, but > doesn't > evaluate the tree.
I am not a fan of slowing down every arithmetic operation (even by a dozen clock cycles) to add checking this flag into the coercion model. > I guess I'm saying that one way to do things would be to have Sage > construct an expression tree before doing anything, then evaluate the > expression tree if it needs to, or it can just return the tree. > Wow, it > seems like a lot of work; I guess it's basically replacing the python > parser. I already wrote such a thing, see http://hg.sagemath.org/sage-main/ file/5be1d5ad8339/sage/misc/parser.pyx . To implement hold, one would modify the preparser to do something like hold(...) -> SR("...", no_simplification=True) and of course make sure it propagates the no_simplification (or whatever it's called) flag so that when it's printed it doesn't simplify itself with maxima. This would of course only work for symbolic expressions, not arbitrary chunks of Python code. (Arbitrary chunks of Python code could be handled as well, using the ast and compile modules, but that's a whole different type type of thing, and one couldn't expect to pass them to maxima.) Modifying the preparser is not something that should be IMHO taken lightly. - Robert --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---