Hi,

On Thu, Jul 30, 2009 at 07:43:43AM -0700, smichr wrote:
> 
> > Would your routine help any for the expression in issue 1562?
> > simplify() doesn't do anything to it because Poly.cancel() doesn't
> > cancel the sin and cos terms.  The same for factor.
> >
> 
> I'm happy to report that factor is able to do the heavy lifting after
> you polify the expression you asked about in issue 1562:
> 
> >>> x=var('x')
> >>> eq=8*x**15*cos(x)**6*sin(x)**21/(-2*x**15*cos(x)**2*sin(x)**21 - 
> >>> x**15*sin(x)**23) + 
> >>> 20*x**15*cos(x)**4*sin(x)**23/(-2*x**15*cos(x)**2*sin(x)**21 - 
> >>> x**15*sin(x)**23) + 
> >>> 16*x**15*cos(x)**2*sin(x)**25/(-2*x**15*cos(x)**2*sin(x)**21 - 
> >>> x**15*sin(x)**23) + 4*x**15*sin(x)**27/(-2*x**15*cos(x)**2*sin(x)**21 - 
> >>> x**15*sin(x)**23)
> >>> repl,p=polify(eq)
> >>> p
> 4*x**15*x1**27/(-2*x**15*x0**2*x1**21 - x**15*x1**23) +
> 8*x**15*x0**6*x1**21/(-2*x**15*x0**2*x1**21 - x**15*x1**23) +
> 16*x**15*x0**2*x1**25/(-2*x**15*x0**2*x1**21 - x**15*x1**23) +
> 20*x**15*x0**4*x1**23/(-2*x**15*x0**2*x1**21 - x**15*x1**23)
> >>> n,d=p.as_numer_denom() #it's rational and factor won't work with that 
> >>> but...
> >>> factor(n)/factor(d)
> -4*(x0**2 + x1**2)**2
> >>> _.subs(r)
> -4*(cos(x)**2 + sin(x)**2)**2
> >>> trigsimp(_)
> -4
> 
> The routine I've got just completely reduces the expression to symbols
> with numerical coefficients and integer powers. I'm not sure where to
> work this routine in. Perhaps it should go into the cse section since
> it can (but doesn't right now) use cse to get close to the desired
> expression and then just do clean up. It could also go into polys
> module. It's more like the cse routine in that it gives you an
> expression (that is more polynomial-like than cse) but it also gives
> you the replacements that you have to carry around. I'm open to some
> discussion.
> 

support for polynomial-like expressions will be included in new version
of polys module, so you should be just patient.

In [1]: eq=8*x**15*cos(x)**6*sin(x)**21/(-2*x**15*cos(x)**2*sin(x)**21 -
x**15*sin(x)**23) +
20*x**15*cos(x)**4*sin(x)**23/(-2*x**15*cos(x)**2*sin(x)**21 -
x**15*sin(x)**23) +
16*x**15*cos(x)**2*sin(x)**25/(-2*x**15*cos(x)**2*sin(x)**21 -
x**15*sin(x)**23) + 4*x**15*sin(x)**27/(-2*x**15*cos(x)**2*sin(x)**21 -
x**15*sin(x)**23)

In [2]: p, q = eq.as_numer_denom()

In [3]: from sympy.polys.polytools import *

In [4]: gcd, pp, qq = cofactors(p, q)

In [5]: pp
Out[5]: 
       2       2           4           4   
- 8⋅cos (x)⋅sin (x) - 4⋅cos (x) - 4⋅sin (x)

In [6]: qq
Out[6]: 1

-- 
Mateusz

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to