Here's a simpler example:

In [155]: -(x - y)/(y - x)**2
  1
──────
-x + y

In [156]: z-(x - y)/(y - x)**2
      x - y
z - ─────────
            2
    (-x + y)

Personally, I don't think that anything should rely on automatic
cancelation, especially rref().  If you have a matrix with symbolic
terms, and you want to do an rref, you have to pass the flag
simplified=True, or you will get wrong answers.

For the inconsistency, it will be fixed when
http://code.google.com/p/sympy/issues/detail?id=1497 is fixed.

Aaron Meurer

On Fri, Mar 16, 2012 at 1:08 AM, smichr <[email protected]> wrote:
> In this difference, the right term is not simplified
>
>    >>> b - (-x + 1/x)/(x*(x - 1/x)**2)
>    b - (-x + 1/x)/(x*(x - 1/x)**2)
>
>
> Here, it is treated like a negated term (not a subtracted term) and
> the result is different
>
>    >>> - (-x + 1/x)/(x*(x - 1/x)**2)
>    1/(x*(x - 1/x))
>
> This allows rref to generate huge expressions which (if the
> subtraction were handled as the addition of a negated term) would
> otherwise be much simpler.
>
> Consider `r[0][8, 16]` of the following:
>
>
>    m = Matrix([[ 0,    -1,     0,     0,     0,  0,    -1,  0,
> 0],
>    [-1, x,    -1,     0,     0,  0,     0, -1,     0],
>    [ 0,    -1, x,     0,     0,  0,     0,  0,    -1],
>    [ 0,     0,     0, x,    -1,  0,    -1,  0,     0],
>    [ 0,     0,     0,    -1, x, -1,     0, -1,     0],
>    [ 0,     0,     0,     0,    -1,  0,     0,  0,    -1],
>    [-1,     0,     0,    -1,     0,  0, x, -1,     0],
>    [ 0,    -1,     0,     0,    -1,  0,    -1,  0,    -1],
>    [ 0,     0,    -1,     0,     0, -1,     0, -1, x]])
>
>    r=m.row_join(eye(9)).rref()
>
> Here's the value of `r[0][8,16]`:
>
>    -(-(-x + 1/x)/(x - 1/x) - (-(-x + 1/x)/(x*(x - 1/x)**2) - 1/(x*(x
> -
>    1/x)))*(-(-x + 1/x)/(x*(x - 1/x)) + 1/x)/(2*x - 2/x - (-x +
>    1/x)/(x**2*(x - 1/x)**2) - 1/(x**2*(x - 1/x))) - 1)/((-(-x + 1/x)/
> (x -
>    1/x)**2 - (-(-x + 1/x)/(x*(x - 1/x)**2) - 1/(x*(x - 1/x)))**2/(2*x
> -
>    2/x - (-x + 1/x)/(x**2*(x - 1/x)**2) - 1/(x**2*(x - 1/x))) - 1/(x
> -
>    1/x))*(2*x + 2*(-(-x + 1/x)/(x*(x - 1/x)**2) - 1/(x*(x - 1/x)))*(-
> (-x
>    + 1/x)/(x - 1/x) - (-(-x + 1/x)/(x*(x - 1/x)**2) - 1/(x*(x -
>    1/x)))*(-(-x + 1/x)/(x*(x - 1/x)) + 1/x)/(2*x - 2/x - (-x +
>    1/x)/(x**2*(x - 1/x)**2) - 1/(x**2*(x - 1/x))) - 1)/(x*(-(-x + 1/
> x)/(x
>    - 1/x)**2 - (-(-x + 1/x)/(x*(x - 1/x)**2) - 1/(x*(x - 1/x)))**2/
> (2*x -
>    2/x - (-x + 1/x)/(x**2*(x - 1/x)**2) - 1/(x**2*(x - 1/x))) - 1/(x
> -
>    1/x))*(2*x - 2/x - (-x + 1/x)/(x**2*(x - 1/x)**2) - 1/(x**2*(x -
>    1/x)))) - 2*(-(-x + 1/x)/(x*(x - 1/x)) + 1/x)/(x*(2*x - 2/x - (-x
> +
>    1/x)/(x**2*(x - 1/x)**2) - 1/(x**2*(x - 1/x)))) - 2/x))
>
> It's just a fancy nan:
>
>    >>> cse(r[0][8, 16])
>    ([], [nan])
>
> /c
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sympy" 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?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" 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?hl=en.

Reply via email to