Open EmmanuelCharpentier opened 1 year ago
The problem seems to reside in Sage :
sage: reset()
sage: x, m, n = var("x, m, n")
sage: hh = (e^x*(1-x))^n/x^m
sage: maxima_calculus("hh: (%e^x*(1-x))^n/x^m;")
((1-x)*%e^x)^n/x^m
sage: Ex = diff(hh, x);
sage: maxima_calculus("Ex: diff(hh, x);")
(n*%e^-x*((1-x)*%e^x)^n*((1-x)*%e^x-%e^x))/((1-x)*x^m)-m*x^((-m)-1)*((1-x)*%e^x)^n
sage: S1 = solve(Ex, x)
sage: maxima_calculus("S1: solve(Ex, x);")
[x = 1,x = -(sqrt(m^2-4*m*n)-m)/(2*n),x = (sqrt(m^2-4*m*n)+m)/(2*n)]
sage: bool(hh==maxima_calculus("hh").sage())
True
sage: bool(Ex==maxima_calculus("Ex").sage())
True
So far, so good. But :
sage: bool(S1==maxima_calculus("S1").sage())
False
Uh, oh... Let's see :
sage: S1
[x^2 == (m*x^2 - m)/n]
sage: maxima_calculus("S1").sage()
[x == 1,
x == 1/2*(m - sqrt(m^2 - 4*m*n))/n,
x == 1/2*(m + sqrt(m^2 - 4*m*n))/n]
sage: [Ex.subs(s).is_zero() for s in S1]
[False]
sage: [Ex.subs(s).is_zero() for s in maxima_calculus("S1").sage()]
[True, True, True]
Here, Sage is wrong and Maxima, used directly through the maxima_calculus
interface is (almost) right (it misses the x=0
solution found in the initial report).
This is quite serious, since Sage silently reports wrong results. I raise the severity to critical
for this reason.
The problem appears to be independent of the interface (library or pexpect
) and the way the interface is used :
sage: Ex.maxima_methods().solve(x)
[x^2 == (m*x^2 - m)/n]
sage: maxima_calculus.solve(Ex, x)
[_SAGE_VAR_x^2 = (_SAGE_VAR_m*_SAGE_VAR_x^2-_SAGE_VAR_m)/_SAGE_VAR_n]
sage: [u.sage() for u in maxima_calculus.solve(Ex, x)]
[x^2 == (m*x^2 - m)/n]
sage: maxima.solve(Ex, x).sage()
[x^2 == (m*x^2 - m)/n]
Attaching the interfaces
keyword component...
No mystery here. If maxima is directly fed the form of Ex as computed it produces the same error. Just a normal error in maxima that should probably be reported. I'm not sure if garbage output from solve should be interpreted as an "implicit solution". Shouldn't solve just solve for x? If it doesn't then I think you have your error there already.
Maxima code that shows the problem:
E : (-m*x^((-m)-1) *(-(x-1)*%e^x)^n) -(n*(-(x-1)*%e^x)^(n-1) *((x-1)*%e^x+%e^x)) /x^m;
solve(E,x);
This is just maxima(Ex) with the variables backsubstituted, to confirm it's not some weird conversion bug due to the variable name decorations. Note that hh.diff(x) does NOT call maxima, so the derivative may not be in the identical format that maxima itself would generate.
Is there an existing issue for this?
Did you read the documentation and troubleshoot guide?
Environment
Steps To Reproduce
See this
ask.sagemath.org
question.Expected Behavior
One can expect the solutions set of the equation.
Actual Behavior
Implicit solution. Let's try a recursive call :
Explicit solution, indeed... But :
doesn't check.
However :
Much better...
Additional Information
One notes that S1 doesn't check with S3 (checked) solutions :
FWIW, "the competition" doesn't make the same error, bit misses two solutions :
Sympy isn't much better :
and factoring doesn't help it :
Giac gets the same two roots :
Trying
algorithm="fricas"
gives us the same problematic answer as the default algorithm :Interestingly, this problematic answer is also returned by :
HTH,