Updates:
        Cc: [email protected]
        Labels: WrongResult

Comment #20 on issue 2607 by asmeurer: as_numer_denom() is too slow
http://code.google.com/p/sympy/issues/detail?id=2607

Regarding the cancelation strategy from as_numer_denom4():

- First, it seems that my fears of non-cancelation were indeed well founded. Here is an example from the tests:

In [7]: a = (-2*z/5 + z*(-z/5 + 1/5)/(-z + 1))

In [8]: a.as_numer_denom_orig()
Out[8]: (-2⋅z⋅(-5⋅z + 5) + 5⋅z⋅(-z + 1.0), -25⋅z + 25)

In [9]: a.as_numer_denom4()
Out[9]:
⎛  2⋅z⋅(-25⋅z + 25)   z⋅(-25⋅z + 25)⋅(-z + 1.0)            ⎞
⎜- ──────────────── + ─────────────────────────, -25⋅z + 25⎟
⎝         5                    -5⋅z + 5                    ⎠

You see that the 5 distributed over one of the terms, preventing it from canceling. Any ideas on how to get around this, short of fixing issue 1497? Perhaps we can carefully keep track of numerical factors and prevent them from multiplying an Add. It sounds a bit shaky at best, though. Chris, any ideas here?

- Second, it seems that Add.as_numer_denom() can indeed be called on non-commutatives. See the together tests in sympy/polys/tests/test_rationaltools.py. One example is assert together(1/(A*B) + 1/(B*A)) in [(A*B + B*A)/(B*A**2*B), (A*B + B*A)/(A*B**2*A)] (A and B are non-commutative). So we will have to special case non-commutatives if we use this strategy.

Actually, even the current implementation does this wrong:

In [19]: var('a1 a2 d1 d2', commutative=False)
Out[19]: (a₁, a₂, d₁, d₂)

In [20]: (a1*d1**-1 + a2*d2**-1 ).as_numer_denom_orig()
Out[20]: (a₁⋅d₂ + d₁⋅a₂, d₁⋅d₂)

Indeed, now that I look at it, I don't even see how together(1/(A*B) + 1/(B*A)) in [(A*B + B*A)/(B*A**2*B), (A*B + B*A)/(A*B**2*A)] can be right. First off, what does A/B mean for A, B noncommutative? If it means A*B**-1, then this is wrong. The first would be A*B*A**-1*B**-2*A**-1 + B**-1*A**-1, for example. It's similarly wrong if you interpret A/B as B**-1*A.

I know as_numer_denom can make sense in at least some non-commutative cases (like A*B**-1 + C*B**-1), but how to completely identify these cases and gather the common numerator and denominator I don't know. I think that unless someone can find a solution to this that we make as_numer_denom() raise NotImplementedError when it encounters non-commutatives.

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