Skip to content

Commit f67c92e

Browse files
committed
Use Expr.equals to do zero-equivalence test in Matrix.rref
Fix is similar to sympy/sympy#10650, thanks to @rpisarev. In case of zero-decision problem - we raise NotImplementedError. Closes diofant#288 Closes sympy/sympy#9480 (Maybe it fixes also sympy/sympy#11238) See sympy/sympy#10280 for alternative.
1 parent dee0f49 commit f67c92e

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

sympy/matrices/matrices.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424

2525
def _iszero(x):
2626
"""Returns True if x is zero."""
27-
return x.is_zero
27+
r = x.equals(0)
28+
if r is None:
29+
raise NotImplementedError("Zero-decision problem for %s" % x)
30+
return r
2831

2932

3033
class MatrixError(Exception):

sympy/matrices/tests/test_matrices.py

+28
Original file line numberDiff line numberDiff line change
@@ -2495,3 +2495,31 @@ def test_issue_9422():
24952495
assert x*M1 != M1*x
24962496
assert a*M1 == M1*a
24972497
assert y*x*M == Matrix([[y*x, 0], [0, y*x]])
2498+
2499+
2500+
def test_issue_9480():
2501+
m = Matrix([[-5 + 5*sqrt(2), -5],
2502+
[-5*sqrt(2)/2 + 5, -5*sqrt(2)/2]])
2503+
assert m.rank() == 1
2504+
2505+
2506+
def test_diofantissue_288():
2507+
k = Symbol('k')
2508+
m = Matrix([[-exp(I*k)*I/(4*k) + S.Half + exp(-I*k)*I/(4*k),
2509+
exp(I*k)*I/(4*k) + S.Half - exp(-I*k)*I/(4*k),
2510+
exp(I*k)/4 + S.Half + exp(-I*k)/4,
2511+
-exp(I*k)/4 - S.Half - exp(-I*k)/4],
2512+
[exp(I*k)*I/(4*k) + S.Half - exp(-I*k)*I/(4*k),
2513+
-exp(I*k)*I/(4*k) + S.Half + exp(-I*k)*I/(4*k),
2514+
-exp(I*k)/4 - S.Half - exp(-I*k)/4,
2515+
exp(I*k)/4 + S.Half + exp(-I*k)/4],
2516+
[exp(I*k)/4 + S.Half + exp(-I*k)/4,
2517+
-exp(I*k)/4 - S.Half - exp(-I*k)/4,
2518+
exp(I*k)*I*k/4 - exp(-I*k)*I*k/4,
2519+
-exp(I*k)*I*k/4 + exp(-I*k)*I*k/4],
2520+
[-exp(I*k)/4 - 1/2 - exp(-I*k)/4,
2521+
exp(I*k)/4 + 1/2 + exp(-I*k)/4,
2522+
-exp(I*k)*I*k/4 + exp(-I*k)*I*k/4,
2523+
exp(I*k)*I*k/4 - exp(-I*k)*I*k/4]])
2524+
assert m.det() == 0
2525+
assert m.rank() != 4

0 commit comments

Comments
 (0)