Le dimanche 22 juillet 2012 à 11:36 +0200, [email protected] a
écrit :
> >> could also expand the class structure so that there is a base class to
> >> Symbol that is only a string encapsulation, and subclasses for Symbol,
> >> and other things like BooleanSymbol.
> >
> > Having a base class for named objects would be good, but it can only
> > work for atoms, as non-atoms can't have strings in their args.
> 
> It seems that you are wrong about this. The idea of Symbol is exactly
> that it provides a hack for having a name and not storing it in args.
> See MatrixSymbol for instance. There is no algorithm in sympy that
> should not consider it an atom, it has non-empty args, it has a name
> that is not in its args.

Symbol is perfectly consistent with sympy's existing object model. Since
it's an Atom, it doesn't have args and is free to use whatever
attributes it needs.

OTOH, what MatrixSymbol does is wrong and unsupported. Being an Atom and
having args is inconsistent and causes problems for algorithms that
don't expect it, eg.:

>>> MatrixSymbol('m', 3, 4).xreplace({4:5}).args
('m', 3, 4)
>>> MatrixSymbol('m', 3, 4).subs({4:5}).args
('m', 3, 5)

Also, putting a string in .args causes it to fail test_args.py.

> 
> So basically my question is. what do you prefer. Hacks like what is
> done to the name string of Symbol or permitting non-Basic objects in
> the args of the leafs of the sympy expression tree. Basically, the
> presence of non-Basic objects in the args will be what defines the end
> of the recursion.

By definition, a leaf can't have args, so I don't understand what you
mean. If you're saying that leaves should be either Atoms or non-Basic
objects, that's de facto the way it works now, though making it the rule
would contradict issue 2070 and test_args.py. 
> 
> @Aaron
> > Why False?  Wouldn't atom(obj) == False mean that obj can be recursed
> > into, which would not hold for non-Basic objects?
> Yes, you are right, it should be True instead of False.
> 


-- 
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.

Reply via email to