On Sat, Jul 21, 2012 at 1:30 PM, [email protected] <[email protected]> wrote: > At least once it was stated that the preferred way to get a named > object is to subclass from Symbol and basically use Symbol as a string > class. > > This is so because many recursion algorithms in SymPy assume that > every element of args subclasses Basic. This is a reasonable > requirement for all objects except the leafs of the tree that have > names. A hack around this is the way that Symbol does not contain its > name string in its args and thus it fails on obj.func(*obj.args)==obj. > And now everybody who needs a name string resorts to encapsulating it > in a Symbol. > > The root of the problem is that there is no notion of an atom or a > leaf **consistently** used in sympy. There are the classes Atom and > the property is_atom, however very few of the algorithms in sympy > actually check those. > > I have raised this issue a few times already, however it got stalled. > > Can we settle on a definition for an atom that works including for > named objects (i.e. objects that need to have strings in their args). > > What about defining a function atom() in utilities that does something like: > > def atom(obj): > try: > return bool(obj.args) and obj.is_Atom > # captures Atom instances and > # shortcircuits on empty args > except AttributeError: > return False # strings work
Why False? Wouldn't atom(obj) == False mean that obj can be recursed into, which would not hold for non-Basic objects? Aaron Meurer > > Then each time an issue arises, we find the offending recursive > algorithm and reimplement it with atom(). Step by step all of sympy > will have consistent recursion routines. > > -- > 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. > -- 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.
