In [1]: a=Wild('a')

In [2]: b=Wild('b')

In [3]: w = Wild('w')

In [4]: (z*cos(x)*cos(y)).replace(w*cos(a)*cos(b), w*(cos(a+b)+cos(a-b))/2)
Out[4]: 
z*(cos(x - y) + cos(x + y))
---------------------------
             2     

The problem is quite simple: SymPy's pattern matcher will only match an 
entire node of the expression tree.

You have a multiplication *Mul(z, cos(x), cos(y))*, that is a list *(z, 
cos(x), cos(y))*. SymPy doesn't appear to have the ability to match a 
sublist.

On Wednesday, 2 December 2015 04:22:24 UTC+1, Andrey Grozin wrote:
>
> вторник, 1 декабря 2015 г., 12:58:34 UTC+6 пользователь Andrey Grozin 
> написал:
>>
>> I need the action inverse to expand_trig (I think it is needed more often 
>> than expand_trig; suppose I want to multiply two truncated Fourier series, 
>> I do expand, what next?).
>>
> No easy way to do this? In Mathematica I could use substitutions like
> Cos[x_]*Cos[y_]->(Cos[x+y]+Cos[x-y])/2
> (similarly in Reduce, Maxima,...). But in sympy .replace(...) will not 
> find cos(x)*cos(y) in a larger product:
>
> >>> a=Wild('a')
> >>> b=Wild('b')
> >>> (z*cos(x)*cos(y)).replace(cos(a)*cos(b),(cos(a+b)+cos(a-b))/2)
> z*cos(x)*cos(y)
>
> So, how to do this?
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/fdfa64ee-5ee0-4757-9d0b-3d4fae2696f6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to