On Jul 30, 2009, at 9:05 AM, Mateusz Paprocki wrote:
> 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. How long will it be until this polys module comes out? Will it be before the end of the summer? I really need better simplification for Variation of Parameters for my Google Summer of Code project, because otherwise about a quarter of the time the wronskian of the independent general solutions returns something like: 8*a**(7/2)*cos(x*a**(1/2))**2*exp(15*x*a**(1/2))*sin(x*a**(1/2))/ (a**(1/2)*exp(15*x*a**(1/2))*sin(x*a**(1/2)) + a**(1/2)*cos(x*a**(1/2))*exp(15*x*a**(1/2))) + 8*a**(7/2)*sin(x*a**(1/2))**3*exp(15*x*a**(1/2))/ (a**(1/2)*exp(15*x*a**(1/2))*sin(x*a**(1/2)) + a**(1/2)*cos(x*a**(1/2))*exp(15*x*a**(1/2))) + 8*a**(7/2)*cos(x*a**(1/2))*exp(15*x*a**(1/2))/ (a**(1/2)*exp(15*x*a**(1/2))*sin(x*a**(1/2)) + a**(1/2)*cos(x*a**(1/2))*exp(15*x*a**(1/2))) Which is equal to 8*a**3. Simplify does nothing to it, but if you substitute all the cos, sin, and exp terms for symbols, as well as sqrt(a), you then can run together(), factor the numerator and denominator, cancel again, back substitute, and run trigsimp (actually, trigsimp needs to be a little better here too. It needs to know to try substituting cos**2 for 1 - sin**2), and cancel one more time, and it will reduce. simplify() could do all of this, but only if cancel and factor worked in the general cases. I could try to manually substitute independent solutions for symbols in the wronskian in dsolve(), because I know what they are, but factor still fails if any of the coeficients are non-rational, like sqrt(2). Aaron Meurer > 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 > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sympy?hl=en -~----------~----~----~----~------~----~------~--~---