Factor fails !

48 views
Skip to first unread message

Arnaud Usciati

unread,
Apr 11, 2015, 7:39:30 AM4/11/15
to sy...@googlegroups.com
Hello,

I found two issues with factor().

If x = symbols('x', real=True)
f =  Lambda(x, (-2*x + Abs(x))*Abs(x**2 - 1))
g = Lambda(x, diff(f(x), x))

Input : g(x)
Ouput : 2*x*(-2*x + Abs(x))*sign(x**2 - 1) + (sign(x) - 2)*Abs(x**2 - 1)
Input : factor(g(x))
Ouput : -4*x**2*sign(x**2 - 1) + 2*x*Abs(x)*sign(x**2 - 1) + Abs(x**2 - 1)*sign(x) - 2*Abs(x**2 - 1)
1st issue : it's expanded, but factor(g(x)) is always equal to g(x)

Then, I replace 'sign' function by sign(u(x)) = u(x)/abs(u(x))

h = Lambda(x, g(x).subs(sign(x), x/abs(x)).subs(sign(x**2-1), (x**2-1)/abs(x**2-1)))
Input : h(x)
Ouput : 2*x*(-2*x + Abs(x))*(x**2 - 1)/Abs(x**2 - 1) + (x/Abs(x) - 2)*Abs(x**2 - 1)
That's correct.

But :

hFactor = Lambda(x, factor(h(x)))
Input : hFactor(x)
Output : (x - 1)*(x**4 - 6*x**3*Abs(x) + x**3 - 6*x**2*Abs(x) + x**2 + 2*x*Abs(x) - x + 2*Abs(x))/(Abs(x)*Abs(x**2 - 1))
2nd issue : hFactor(x) is not equal to h(x) !!

For examples :
h(2) = -11 and hFactor(2) = -53/3
h(S.Half) = -1/4 and hFactor(S.Half) = -5/12

Aaron Meurer

unread,
Nov 19, 2015, 4:55:34 PM11/19/15
to sy...@googlegroups.com
I've reported this on the issue tracker
https://github.com/sympy/sympy/issues/10161.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/3c465ab0-7787-4ad2-ac3f-f8fd4cfb7cb8%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages