In [1]: var('zr zc') Out[1]: (zr, zc) In [2]: zup, zlow = zr, 1/(1/zc + 1/(zc+zr))
In [3]: zc/(zc+zr) * zlow/(zlow+zup) Out[3]: zc ──────────────────────────────────────────── ⎛1 1 ⎞ ⎛ 1 ⎞ (zc + zr)⋅⎜── + ───────⎟⋅⎜zr + ────────────⎟ ⎝zc zc + zr⎠ ⎜ 1 1 ⎟ ⎜ ── + ───────⎟ ⎝ zc zc + zr⎠ In [4]: simplify(_) Out[4]: 2 zc ─────────────────── 2 2 3⋅zc⋅zr + zc + zr Previously, both numerator and denominator in the above fraction returned by simplify() (in fact Poly.cancel) were multiplied by a constant. Signed-off-by: Mateusz Paprocki <matt...@gmail.com> --- sympy/polys/polynomial.py | 10 ++++++++++ sympy/polys/tests/test_polynomial.py | 4 ++++ 2 files changed, 14 insertions(+), 0 deletions(-) diff --git a/sympy/polys/polynomial.py b/sympy/polys/polynomial.py index 1ccd894..11e0596 100644 --- a/sympy/polys/polynomial.py +++ b/sympy/polys/polynomial.py @@ -642,6 +642,15 @@ def cancel(f, *symbols): p = sympy.polys.algorithms.poly_div(p, g)[0] q = sympy.polys.algorithms.poly_div(q, g)[0] + pc = int(p.content) + qc = int(q.content) + + cont = igcd(pc, qc) + + if cont != 1: + p = p.div_term(cont) + q = q.div_term(cont) + return p.as_basic() / q.as_basic() def as_basic(self): @@ -2157,3 +2166,4 @@ def multinomial_as_basic(multinomial, *symbols): l.append(Mul(*term)) result = Add(*l) return result + diff --git a/sympy/polys/tests/test_polynomial.py b/sympy/polys/tests/test_polynomial.py index 5d7a338..0891a25 100644 --- a/sympy/polys/tests/test_polynomial.py +++ b/sympy/polys/tests/test_polynomial.py @@ -185,6 +185,10 @@ def test_poly_cancel(): assert Poly.cancel(f) == -2 + sqrt(2) + a, b = x, 1/(1/y + 1/(x+y)) + + assert Poly.cancel(y/(x+y) * b/(a+b), x, y) == y**2/(x**2 + 3*x*y + y**2 ) + raises(SymbolsError, "Poly.cancel((x**2-y**2, x-y))") def test_poly_characteristics(): -- 1.6.1 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy-patches" group. To post to this group, send email to sympy-patches@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 -~----------~----~----~----~------~----~------~--~---