Comment #41 on issue 1598 by mattpap: New polynomials manipulation module
http://code.google.com/p/sympy/issues/detail?id=1598
> Also, is there a way to make monic work even when coefficients don't
> reduce to
> multiples of the leading coefficient?
Yes, there is only one issue:
In [1]: f = 3*x**3+5*x**2+7*x+11
In [2]: g = Poly(f)
In [3]: g.get_domain()
Out[3]: ZZ
By default Poly tries to find a minimal domain for coefficients. In this
case it's ZZ
which supports only exact division. There are several solutions to fix this,
depending what you are actually doing.
You can use monic() function:
In [4]: monic(f)
Out[4]:
2
7⋅x 5⋅x 3
11/3 + ─── + ──── + x
3 3
If it is given basic expression it will default to a field (QQ in this
case). Or you
can force field usage in Poly directly:
In [5]: g = Poly(f, field=True)
In [6]: g.get_domain()
Out[6]: QQ
In [7]: g.monic()
Out[7]: Poly(x**3 + 5/3*x**2 + 7/3*x + 11/3, x, domain='QQ')
You can always set an explicit domain:
In [8]: g = Poly(f, domain='QQ')
In [9]: g.monic()
Out[9]: Poly(x**3 + 5/3*x**2 + 7/3*x + 11/3, x, domain='QQ')
Most functions in polytools.py are strict and they won't change initial
ground
domain. There are however some which do this intentionally, e.g.
Poly.integrate(),
for users' convenience.
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy-issues?hl=en.