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