Comment #4 on issue 1902 by alberthilbert: 'has' method fails when argument is 'Symbol' or 'Wild'
http://code.google.com/p/sympy/issues/detail?id=1902

From what I can see from source code, 'has' method accepts 'BasicType' object as parameter and return 'True' if 'self' contains some instance of that type, 'False' if
doesn't.
Some working examples:

x, y, z = symbols('xyz')
f = Function('f')
(f(x)).has(Function)
True
(f(x)).has(Piecewise)
False
(f(x)).has(Pow)
False
(x + y).has(Add)
True
(x*y + 1).has(Mul)
True

I think there is no reason why this should not work when you pass 'Symbol' or 'Wild'
as parameter, so to have:

(x + y).has(Wild)
False
(x**y + 1).has(Symbol)
True
p = Wild('p')
(x + p).has(Wild)
True

'atoms' is supposed to have a completely different behaviour, it list all the
instances of a certain type present in an expression.
But in a lot of circumstances, you need only to know if at least one of them is present.
In those cases you can use something like:

bool(expr.atoms(Symbol))

but this is by far less elegant than:

expr.has(Symbol)

Moreover, it is a waste of resources, walking the entire expression tree to collect all the informations needed by 'atoms' when you can stop at the first occurrence of a
specific object.
To be honest, as now, there is not such resource advantage, because of the
implementation of 'has' that use 'bool(self.atoms(type))' to calculate its answer,
but that may change in future... ;)

Raffaele

--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" 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-issues?hl=en.

Reply via email to