sympy: test subexpression for trig function -
i trying test whether sub-expression contains sin function (or trig function)
from sympy import sin, symbols, wild a, b, x, y = symbols('a, b, x, y') w1=wild('w1')
i can this:
>> (a*sin(x)+b*sin(y)).has(sin(x)) out: true
but not work:
>>: (a*sin(x)+b*sin(y)).has(sin(w1)) out: false
how test 1 or more sin functions regardless of argument?
if want use wild
s, use find
:
in [11]: (a*sin(x)+b*sin(y)).find(sin(w1)) out[11]: set([sin(x), sin(y)])
but if searching single function sin, , not generic expressions, easier , faster way use atoms
:
in [12]: (a*sin(x)+b*sin(y)).atoms(sin) out[12]: set([sin(x), sin(y)])
if want check multiple trig functions, atoms
takes multiple arguments, more efficient calling multiple times
in [14]: (a*sin(x)+b*cos(y)).atoms(sin, cos) out[14]: set([sin(x), cos(y)])
Comments
Post a Comment