Comment #13 on issue 2587 by [email protected]: Strange printing at SymPy
Live
http://code.google.com/p/sympy/issues/detail?id=2587
This explains why the order matters. Assumptions are not computed until
they are accessed. Remember that f is, internally, x**-2*(x**2 + 1). So it
has a 2 and a -2. If you ask if the 2 is negative first, it gives the
right answer, but comes out wrong for the 2:
n [1]: import pickle
In [2]: f = 1/(x**2*(x**2 + 1))
In [3]: g = pickle.loads(pickle.dumps(f))
In [4]: a = g.args[1].args[0].args[1].args[1]
In [5]: b = f.args[1].args[0].args[1].args[1]
In [6]: a.is_negative
Out[6]: False
In [7]: b.is_negative
Out[7]: False
In [8]: g
Out[8]:
-2
x
──────
2
x + 1
In [9]: g.args[0]
Out[9]:
-2
x
In [10]: g.args[0].args
Out[10]: (x, -2)
In [11]: g.args[0].args[1]
Out[11]: -2
In [12]: g.args[0].args[1].is_negative
Out[12]: False
If you ask if the -2 is negative first, it comes out right, but then thinks
the 2 is negative:
In [1]: import pickle
In [2]: f = 1/(x**2*(x**2 + 1))
In [3]: g = pickle.loads(pickle.dumps(f))
In [4]: g.args[0].args[1].is_negative
Out[4]: True
In [5]: a = g.args[1].args[0].args[1].args[1]
In [6]: a.is_negative
Out[6]: True
In [7]: g
Out[7]:
1
─────────────
2 ⎛ 1 ⎞
x ⋅⎜──── + 1⎟
⎜⎛1 ⎞ ⎟
⎜⎜──⎟ ⎟
⎜⎜ 2⎟ ⎟
⎝⎝x ⎠ ⎠
In other words, it wants them both to be the same.
--
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.