# Incorrect result with rref() #15141

Open
opened this Issue Aug 24, 2018 · 4 comments

Projects
None yet
3 participants
Contributor

### sylee957 commented Aug 24, 2018 • edited by smichr

While tracing down the issue #15118, #15125, I had found another issue from rref.

``````from sympy import *

q = symbols("q", positive = True)
m = Matrix([
[-2*cosh(q/3),      exp(-q),            1],
[      exp(q), -2*cosh(q/3),            1],
[           1,            1, -2*cosh(q/3)]])
m.rref()
``````
``````(Matrix([
[1, 0, 0],
[0, 1, 0],
[0, 0, 1]]), (0, 1, 2))
``````

While the result from Mathematica is

``````\$Assumptions = q>0;
RowReduce[
{
{-2*Cosh[q/3], Exp[-q],1},
{Exp[q], -2*Cosh[q/3], 1},
{1, 1, -2*Cosh[q/3]}
}
]//FullSimplify
``````
``````{{1, 0, -E^(-q/3)}, {0, 1, -E^(q/3)}, {0, 0, 0}}
``````

I think there are some fundamental issue from the algorithm, that it fails to detect some complex formula like below

``````(-exp(q) - 2*cosh(q/3))*(-2*cosh(q/3) - exp(-q)) - (4*cosh(q/3)**2 - 1)**2
``````

that it is zero, some weird cross canceling occurs after recognizing it as a pivot rather than zero, and then the row multiplied with these kinds of formula gets broken.

Member

### jksuom commented Aug 25, 2018

 This is a known issue. It has been suggested that `rref` should call `simplify` by default but that may be time consuming (see e.g. #10120).
Contributor

### sylee957 commented Aug 25, 2018

 @jksuom Interesting. But I can confirm that even simplify fails on this particular expression for determining zero. ``````expr = ((-exp(q) - 2*cosh(q/3))*(-2*cosh(q/3) - exp(-q)) - (4*cosh(q/3)**2 - 1)**2) expr.simplify() `````` ``````2*exp(q)*cosh(q/3) - 16*cosh(q/3)**4 + 12*cosh(q/3)**2 + 2*exp(-q)*cosh(q/3) ``````
Member

### jksuom commented Aug 25, 2018

 It seems that simplification of hyperbolic functions should be improved. For trigonometric functions, there is `fu`, but support for hyperbolic functions is minimal.
Member

### smichr commented Aug 25, 2018

 support for hyperbolic functions is minimal. As I recall, it converts hyperbolics to trigs and runs the simplification on them. In this case, however, simplifying `expr.rewrite(exp)` returns 0.

Merged