Comment #9 on issue 2032 by asmeurer: Ability to work with K[x, 1/x] in Polys
http://code.google.com/p/sympy/issues/detail?id=2032

Well, I don't have any problem with Poly only partially handling 1/x type generators and raising NotImplementedError when it encounters something it can't handle. But silently accepting it and then returning what can then only be interpreted as wrong results is something else, which I think should be avoided. Unfortunately, due to the nature of domains in Polys, I fear that it may not be really possible to only have a "half" implementation (though I could be wrong).

By the way, this would be an awesome thing to include whenever an implementation of Frac() (issue 2042) comes.

Regarding my algorithm from comment 7, I was close (the spirit was right, but I had a typo or two). The correct implementation is

def aspoly1t(p, t):
    pa, pd = cancel(p.as_basic()).as_numer_denom()
    pa, pd = Poly(pa, t), Poly(pd, t)
    assert pd.is_monomial
    d = pd.degree(t)
    one_t_part = pa.slice(0, d + 1) # requires polys11
    t_part = pa - one_t_part
    t_part = t_part.to_field().quo(pd)
    # Compute the negative degree parts.  Also requires polys11.
one_t_part = Poly.from_list(reversed(one_t_part.rep.rep), *one_t_part.gens, domain=one_t_part.domain)
    one_t_part = one_t_part.replace(t, z) # z will be 1/t
    ans = t_part.as_poly(t, z) + one_t_part.as_poly(t, z)
    return ans


In [106]: p1 = random_poly(x, 10, -10, 10)

In [107]: p2 = random_poly(x, 10, -10, 10)

In [108]: p = p1 + p2.subs(x, 1/x)

In [109]: p
Out[109]:
6 8 8 6 6 4 4 9 5 3 3 4 5 6 7 8 9 10 3 - 7⋅x - ─ - ─── + ── - ── + ── - ── - ── - ── + ── + ── - 9⋅x + 10⋅x + 2⋅x + 9⋅x + 4⋅x - 6⋅x - x + 7⋅x
          x    10    9    8    7    6    5    4    3    2
              x     x    x    x    x    x    x    x    x

In [110]: aspoly1t(p, x)
Out[110]: Poly(7*x**10 - x**9 - 6*x**8 + 4*x**7 + 9*x**6 + 2*x**5 + 10*x**4 - 9*x**3 - 7*x - 8*z**10 + 8*z**9 - 6*z**8 + 6*z**7 - 4*z**6 - 4*z**5 - 9*z**4 + 5*z**3 + 3*z**2 - 6*z + 3, x, z, domain='ZZ')

In [111]: aspoly1t(p, x).as_basic().subs(z, 1/x) == p
Out[111]: True

Now, some of this is kind of hackish, so if you know of better ways to do things, feel free to let me know. Otherwise, I am including this in the relevant part of the Risch Algorithm, as mentioned in comment 0.

--
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.

Reply via email to