Updates:
Labels: NeedsReview
Comment #19 on issue 1337 by mattpap: find all instances in an expression
http://code.google.com/p/sympy/issues/detail?id=1337
As a side effect of my work on improving polynomial systems solver I
introduced a similar find() method in Basic (commit
2c965f0f78542be9369e7854890f67bb8f5ab795 in polys11). Later I realized that
this issue exists, so I went ahead and extended find() with syntax proposed
in this issue (8955256498c90e32baff1b87b492616fcbafe75c). I also added
count() method which allows to quickly figure out the number of matching
subexpressions.
Examples:
In [1]: a = Wild('a')
In [2]: f = -(1 - log(tan(x**2)))/(-tan(tan(1 - x)) + cos(tan(1))) + tan(1)
In [3]: f.find(tan)
Out[3]:
⎛ ⎛ 2⎞ ⎞
set⎝tan(1), tan⎝x ⎠, tan(1 - x), tan(tan(1 - x))⎠
In [4]: f.find(tan(a))
Out[4]:
⎛ ⎛ 2⎞ ⎞
set⎝tan(1), tan⎝x ⎠, tan(1 - x), tan(tan(1 - x))⎠
In [5]: f.find(tan(tan(a)))
Out[5]: set(tan(tan(1 - x)))
In [6]: f.find(lambda expr: type(expr) is tan)
Out[6]:
⎛ ⎛ 2⎞ ⎞
set⎝tan(1), tan⎝x ⎠, tan(1 - x), tan(tan(1 - x))⎠
In [7]: f.find(lambda u: u.is_Symbol)
Out[7]: set(x)
In [8]: f.find(lambda u: u.is_Symbol, group=True)
Out[8]: {x: 2}
In [9]: f.count(Symbol)
Out[9]: 2
--
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.