Hi,

On Wed, Dec 02, 2009 at 11:49:24PM -0800, smichr wrote:
> > Is gcdfactor() any different from the following?
> >
> > In [1]: f = x**2*exp(x)+exp(x+y)*x/y
> >
> > In [2]: f
> > Out[2]:
> >            x + y
> >  2  x   x⋅ℯ    
> > x ⋅ℯ  + ────────
> >            y    
> >
> > In [3]: factor(f)
> > Out[3]:
> >   ⎛     y⎞  
> >   ⎜    ℯ ⎟  x
> > x⋅⎜x + ──⎟⋅ℯ
> >   ⎝    y ⎠  
> >
> 
> In this case, no. But gcdfactor would do nothing to 1-x**2 whereas
> factor would return (1+x)*(1-x). Removing a common factor from all
> terms before beginning the formal factoring process makes the regular
> factoring a lot easier. I think the place for this type of function is
> in simplify. It's like collect but it's not collecting for a given
> term, it's collecting from every term whatever is in common and can be
> extracted multiplicatively.
> 

I see your point. There is however terms_gcd() method in new Poly class
which does the thing, e.g.:

In [5]: factor(x**3*y-x*y**3)
Out[5]: x⋅y⋅(x - y)⋅(x + y)

In [6]: Poly(x**3*y-x*y**3).terms_gcd()
Out[6]: ((1, 1), Poly(x**2 - y**2, x, y, domain='ZZ'))

The last line should be interpreted as x**1*y**1 * (x**2 - y**2), so
no factorization is performed. Currently there is no terms_gcd()
function which would return Basic expression, as factor() does,
but this is trivial to implement. Moreover, terms_gcd() is being
used as a preprocessing procedure in factor().

Also note that you can pass `expand=False` to Poly and most polynomial
manipulation functions, to keep input expression intact, e.g.:

In [11]: Poly((x-1)*y**2 - (x-1)*y).terms_gcd()
Out[11]: ((0, 1), Poly(x*y - x - y + 1, x, y, domain='ZZ'))

In [12]: Poly((x-1)*y**2 - (x-1)*y, expand=False).terms_gcd()
Out[12]: ((1, 1), Poly(-y + 1, 1 - x, y, domain='ZZ'))

> --
> 
> You received this message because you are subscribed to the Google Groups 
> "sympy-patches" group.
> To post to this group, send email to sympy-patc...@googlegroups.com.
> To unsubscribe from this group, send email to 
> sympy-patches+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sympy-patches?hl=en.
> 
> 

-- 
Mateusz

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

Reply via email to