Here's a trick worth knowing if you are trying to get an expression to
not autosimplify on you wrt negated terms:
>>> s='-(1+x)*x + x*(1+x)'
>>> S(s)
x*(-x - 1) + x*(x + 1)
>>> S(s.replace('-(', '-one*(')).subs('one', 1)
0
Say I want to show that factor has a problem with some expressions:
Here's the expression:
>>> s=('''(1 - 2*(-(-x + 1/x)/(x*(x - 1/x)**2) - 1/(x*(x - 1/x)))/(x*(2*x -
... 2/x)))*(-(-x + 1/x)/(x*(x - 1/x)) + 1/x)/((2*x - 2/x)*(2*x - 2/x -
... 4/(x**2*(2*x - 2/x)))) - (-(-x + 1/x)/(x*(x - 1/x)**2) - 1/(x*(x -
... 1/x)))*(-(1 - 2*(-(-x + 1/x)/(x*(x - 1/x)**2) - 1/(x*(x -
... 1/x)))/(x*(2*x - 2/x)))*(-(-x + 1/x)*(-(-x + 1/x)/(x*(x - 1/x)) +
... 1/x)/(2*x - 2/x) - 1/x)/(2*x - 2/x - 4/(x**2*(2*x - 2/x))) - (-x +
... 1/x)*(-(-x + 1/x)/(x*(x - 1/x)**2) - 1/(x*(x - 1/x)))/(2*x -
... 2/x))/(2*x - 2/x) - (-(-x + 1/x)/(x*(x - 1/x)**2) - 1/(x*(x -
... 1/x)))/(2*x - 2/x)''')
I sympify and factor...
>>> S(s)
2/(x*(2*x - 2/x)*(2*x - 2/x - 4/(x**2*(2*x - 2/x))))
>>> factor(_)
1/(2*x*(x**2 - 2))
hmmm...no problem (but look at how the expression was autosimplified).
Now use the trick:
>>> S(s.replace('-(', '-one*(')).subs('one', 1)
(1 - (-2*(-x + 1/x)/(x*(x - 1/x)**2) - 2/(x*(x - 1/x)))/(x*(2*x - 2/
x)))*(-(-x +
1/x)/(x*(x - 1/x)) + 1/x)/((2*x - 2/x)*(2*x - 2/x - 4/(x**2*(2*x - 2/
x)))) - (-
(-x + 1/x)/(x*(x - 1/x)**2) - 1/(x*(x - 1/x)))*(-(1 - (-2*(-x + 1/x)/
(x*(x - 1/x
)**2) - 2/(x*(x - 1/x)))/(x*(2*x - 2/x)))*(-(-x + 1/x)*(-(-x + 1/x)/
(x*(x - 1/x)
) + 1/x)/(2*x - 2/x) - 1/x)/(2*x - 2/x - 4/(x**2*(2*x - 2/x))) - (-x +
1/x)*(-(-
x + 1/x)/(x*(x - 1/x)**2) - 1/(x*(x - 1/x)))/(2*x - 2/x))/(2*x - 2/x)
- (-(-x +
1/x)/(x*(x - 1/x)**2) - 1/(x*(x - 1/x)))/(2*x - 2/x)
>>> factor(_)
nan
It's not exactly the same as the original string:
>>> str(S(s.replace('-(', '-one*(')).subs('one', 1)) == s
False
I suppose one would have to replace leading numbers before parentheses
with a trailing "*one*(" to get that to work.
/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.