Comment #21 on issue 2607 by [email protected]: as_numer_denom() is too slow
http://code.google.com/p/sympy/issues/detail?id=2607
Your method 4 is the same as the one I tested out and didn't post results
for because it had more significant failures. Besides the one you noted
involving non-commutatives,
_______________ sympy\matrices\tests\test_matrices.py:test_eigen
_______________
File "c:\users\leslie\sympy\sympy\matrices\tests\test_matrices.py",
line 574,
in test_eigen
r = M.eigenvects()
File "C:\Users\leslie\sympy\sympy\matrices\matrices.py", line 2131,
in eigenve
cts
raise NotImplementedError("Can't evaluate eigenvector for
eigenvalue %s" % r
)
NotImplementedError: Can't evaluate eigenvector for eigenvalue 15/2 +
3*33**(1/2
)/2
________________________________________________________________________________
________ sympy\simplify\tests\test_hyperexpand.py:test_plan_derivatives
________
File "c:\users\leslie\sympy\sympy\simplify\tests\test_hyperexpand.py", line
18
6, in test_plan_derivatives
tn(apply_operators(f.C, ops, deriv)[0], h2, z)
File "C:\Users\leslie\sympy\sympy\simplify\hyperexpand.py", line
1033, in appl
y_operators
res = o.apply(res, op)
File "C:\Users\leslie\sympy\sympy\simplify\hyperexpand.py", line 755,
in apply
diffs.append(op(diffs[-1]))
File "C:\Users\leslie\sympy\sympy\simplify\hyperexpand.py", line
1022, in doit
r = r.applyfunc(make_simp(z))
File "C:\Users\leslie\sympy\sympy\matrices\matrices.py", line 1031,
in applyfu
nc
out = Matrix(self.rows,self.cols,map(f,self.mat))
File "C:\Users\leslie\sympy\sympy\simplify\hyperexpand.py", line 186,
in simp
c, numer, denom = poly(numer, z).cancel(poly(denom, z))
File "C:\Users\leslie\sympy\sympy\polys\polytools.py", line 5402, in
poly
return _poly(expr, opt)
File "C:\Users\leslie\sympy\sympy\polys\polytools.py", line 5352, in
_poly
poly_factors.append(_poly(factor.base, opt).pow(factor.exp))
File "C:\Users\leslie\sympy\sympy\polys\polytools.py", line 1346, in
pow
result = f.rep.pow(n)
File "C:\Users\leslie\sympy\sympy\polys\polyclasses.py", line 439, in
pow
return f.per(dmp_pow(f.rep, n, f.lev, f.dom))
File "C:\Users\leslie\sympy\sympy\polys\densearith.py", line 1000, in
dmp_pow
return dup_pow(f, n, K)
File "C:\Users\leslie\sympy\sympy\polys\densearith.py", line 964, in
dup_pow
raise ValueError("can't raise polynomial to a negative power")
ValueError: can't raise polynomial to a negative power
Regarding the cancellation problem, just use
den = Mul(*denoms, evaluate=False)
Then they give the same result:
>>> a.as_numer_denom_orig()
(-5*z**2 - 2*z*(-5*z + 5), -25*z + 25)
>>> a.as_numer_denom4()
(-5*z**2 - 2*z*(-5*z + 5), 5*(-5*z + 5))
If you prefer the bottom result distributed then 'touch' it by adding 0 or
multiplying by 1 before returning it `return Add(*nums), den + 0:
>>> a.as_numer_denom4()[1]+0
-25*z + 25
Regarding non-commutatives, at least for matrices, IIRC, A/B means A*B**-1.
I think as_numer_denom of a noncommutative power should always return (NC,
1); that would solve the problem without having to raise an error. I agree
that the together results look wrong. I would expect the expression to be
unchanged. But for `1/x + 1/A` I would expect `(1 + x/A, x)`.
--
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.