sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.34k stars 460 forks source link

Maxima does not know that 1 > 0 #30816

Open mwageringel opened 3 years ago

mwageringel commented 3 years ago

When computing this integral, Maxima asks whether 1 is zero or nonzero:

sage: var('x1,x2,y')
sage: assume(x1 > 0, x2 > 0, cos(y) != 0)
sage: f = sqrt(x1^2 - 2*x1*x2*cos(y) + x2^2)
sage: f.integrate(x1, algorithm='maxima')
...
ValueError: Computation failed since Maxima requested additional constraints; using the 'assume' command before evaluation *may* help (example of legal syntax
 is 'assume(1>0)', see `assume?` for more details)
Is 1 zero or nonzero?

Attempting to add this as an assumption fails:

sage: assume(SR(1) > SR(0))
...
ValueError: Assumption is redundant

See also this upstream bug https://sourceforge.net/p/maxima/bugs/3218/ and this thread on sage-support.

Component: symbolics

Keywords: maxima, integral

Issue created by migration from https://trac.sagemath.org/ticket/30816

760856ab-9fee-4c74-b881-c4ba67eaa847 commented 3 years ago
comment:1

I get a slightly different behavior, but still buggy. Working w/ Maxima 5.44.0 on macOS.

With domain: real (default), I get "Is 1 zero or nonzero?" for the question, and if I respond nz, then I get a result (I didn't check it):

(-(x2^2*cos(y)^2*log(2*sqrt((-2*x1*x2*cos(y))+x2^2+x1^2)-2*x2*cos(y)+2*x1))/2)
 +(x2^2*log(2*sqrt((-2*x1*x2*cos(y))+x2^2+x1^2)-2*x2*cos(y)+2*x1))/2
 -(x2*cos(y)*sqrt((-2*x1*x2*cos(y))+x2^2+x1^2))/2
 +(x1*sqrt((-2*x1*x2*cos(y))+x2^2+x1^2))/2

With domain: complex, I get the same question and same result.

Not sure where the question is coming from. I will try to investigate a little.

760856ab-9fee-4c74-b881-c4ba67eaa847 commented 3 years ago
comment:2

trace(?asksign1) and then trying it again shows the expression which confuses asksign is 4*x2<sup>2*cos(y)</sup>2-4*x2^2. In a fresh session, I get the buggy behavior with just

(%i1) asksign (4*x2^2*cos(y)^2-4*x2^2);
Is x2 zero or nonzero?

nz;
(%o1)                                 pos
(%i2) assume(x2 > 0);
(%o2)                              [x2 > 0]
(%i3) asksign (4*x2^2*cos(y)^2-4*x2^2);
Is 1 zero or nonzero?

nz;
(%o3)                                 pos
(%i4) asksign(4*x*cos(y)-4*x);
Is x positive, negative or zero?

p;
(%o4)                                 pos
(%i5) assume(x>0);
(%o5)                               [x > 0]
(%i6) asksign(4*x*cos(y)-4*x);
Is 1 zero or nonzero?

nz;
(%o6)                                 pos
(%i7) asksign(x*cos(y)-x);
Is 1 zero or nonzero?

nz;
(%o7)                                 pos

That's the simplest example I found. The presence of cos(y) seems important; without it I don't see the bug:

(%i8) asksign(x*y-x);
Is y - 1 positive, negative or zero?

p;
(%o8)                                 pos
(%i9) asksign(x*foo(y) - x);
Is foo(y) - 1 positive, negative or zero?

p;
(%o9)                                 pos

Just to be clear, assume(x > 0) is enough; assumptions on other variables, and the setting of domain, and the presence of integrate aren't required.

760856ab-9fee-4c74-b881-c4ba67eaa847 commented 3 years ago
comment:3

I've opened https://sourceforge.net/p/maxima/bugs/3677/ to track this bug.

mkoeppe commented 3 years ago
comment:4

Sage development has entered the release candidate phase for 9.3. Setting a new milestone for this ticket based on a cursory review of ticket status, priority, and last modification date.