On 30/08/12 20:16, Aaron Meurer wrote: > On Thu, Aug 30, 2012 at 12:41 AM, Juha Jeronen <[email protected]> wrote: >> It seems, though, that just the string is not enough information. For >> example, in 0.7.x there is the LT() function (to get the leading term), >> but e.g. the following is nevertheless valid: >> >> expr = sy.sympify("LT*a") # no error, expr will have Symbols "LT" and "a" >> # artificial example: let's replace the symbol "LT" by sin(x) >> my_LT = sy.symbols("LT") # refer to the Symbol "LT", not function LT() >> expr.subs( {my_LT : sy.sympify("sin(x)")} ) > This works in the latest version. The reason is that LT was not added > until 0.7.0.
Ah, I was originally running on 0.7.1, which does have LT(), but it turns out there was a mistake in the above artificial example. What my original code actually did in the case I tested, was only the last two lines. The my_LT = ... line does work on 0.7.1, but as you say, it's not possible to sympify() strings containing "LT" as a custom symbol; instead, the string "LT" will always be interpreted as referring to the function LT(). The catch is that while I did use sympify() in the original code, the expression did not contain any "LT". If it did, the TypeError would have been triggered... so there is a bug in my code. Thanks for discovering it ;) (The using code has later been optimized so that it won't do unnecessary subs(); the artificial example was based on how I recalled to have discovered this.) So, please disregard my previous comment - correcting, it seems the string alone *is* enough information to decide whether the name is reserved or not. Thus, dir(sympy) and some processing should give a proper list... -J -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
