On 31.08.2012 13:03, Chris Smith wrote:
On Fri, Aug 31, 2012 at 3:30 PM, Juha Jeronen <[email protected]> wrote:
Hi all (again),
And here's a fixed version. The code I just posted returned some nonsensical
results, because it didn't filter out modules and classes.
Another way to maybe approach this problem (getting a non-clashing
form of an expression sympified) is this:
* the user must know what functions they are using: they/you give a
list of these and this list must agree with the representation of that
function's name in sympy
* they give an expressions
* let python parse this (I don't recall which does that now -- there's
some module for parsing python code character by character) and when
it identifies a variable either 1) it is a function that has already
been identified or it is intended as a symbol and 2a) sympy agrees or
2b) sympy disagrees and wants to make it a class or anything other
than a symbol.
* in case of 2b the user's symbol must be de-clashed, by appending
underscores until the clash goes away; this symbol replaces what the
user chose
* the modified input function is returned.
Thanks for the idea! I hadn't considered this approach.
This would be pretty easy to do the other way around: undefined symbols
are not allowed in my particular use case, and the code already builds a
list of user-defined symbols. Anything not explicitly defined is
intended to be taken from the library...
Related to which, I have one more question. In 0.6.x sympify() used to
add an undefined_Function attribute to unknown functions in the expression:
import sympy as sy
s = sy.sympify("a*f(x) + b + c*x")
L = list(s.atoms(sy.Function))
f = L[0]
hasattr(f, "undefined_Function")
=> True
but 0.7.x no longer does this.
Is it possible to dynamically detect in the new version whether a
function object is evaluatable or not, and user-defined or not? At least
I couldn't find anything obvious in the attributes...
What I'd like to do with this is to check that all function references
in a user-given expression refer to existing library functions only. I
could utilize the get-reserved-symbols-by-dir(sympy) hack and check the
object type, but that's hardly an elegant solution.
-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.