sagemath / sage

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

maxima asks for assumption but then rejects it as redundant #29616

Open DaveWitteMorris opened 4 years ago

DaveWitteMorris commented 4 years ago

As reported in #29608, maxima sometimes asks for additional information, but then reports that the information is redundant when an attempt is made to provide the appropriate assumption. The problem seems to go away if the assumption is put inside a with hold clause.

sage: var('m');
sage: assume(m, 'integer')
sage: D = cos((4 * m + 1)*arcsin(1/sqrt(x^2 + 1)))/sqrt(x^2/(x^2 + 1));
sage: limit(D, x=0)
---------------------------------------------------------------------------
RuntimeError               Traceback (most recent call last)
    <snip>
RuntimeError: ECL says: Maxima asks: Is cos((4*%pi*_SAGE_VAR_m+%pi)/2) 
positive, negative or zero?

During handling of the above exception, another exception occurred:
    <snip>
ValueError: Computation failed since Maxima requested additional constraints; 
using the 'assume' command before evaluation *may* help (example of legal syntax 
is 'assume(cos((4*%pi*m+%pi)/2)>0)', see `assume?` for more details)
Is cos((4*%pi*m+%pi)/2) positive, negative or zero?

sage: assume(cos((4*pi*m+pi)/2) == 0)
---------------------------------------------------------------------------
ValueError                 Traceback (most recent call last)
    <snip>
ValueError: Assumption is redundant

sage: with hold:
....:     assume(cos((4*pi*m+pi)/2) == 0)
....:     
sage: limit(D, x=0)
0

Component: symbolics

Keywords: maxima, assume

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

DaveWitteMorris commented 4 years ago
comment:1

I'm no expert, but my guess is that pynac (or somebody else) knows that the left side of the assumption is 0, and decides to be helpful by simplifying it to 0. Thus, maxima receives the assumption 0 == 0, and quite reasonably rejects this as being redundant.

sage: var('m');
sage: assume(m, 'integer')
sage: cos((4*pi*m+pi)/2)
0

Suggestions for how to fix this? If my diagnosis is correct, I think pynac (or whoever) should be prevented from messing up assumptions before they are passed to maxima.

DaveWitteMorris commented 4 years ago

Changed keywords from maxima to maxima, assume

DaveWitteMorris commented 4 years ago
comment:2

I now see that my previous comment largely states the obvious; since assume is a function, the evaluation of assume(statement) entails evaluating statement, and then calling assume on the result. I think the bug is that the evaluation of statement is done by a different backend than the one that needs statement.

Can this be fixed somehow? If not, and there is no harm in surrounding assumptions with with hold, perhaps this workaround should be suggested in the documentation.

mkoeppe commented 3 years ago
comment:4

Setting new milestone based on a cursory review of ticket status, priority, and last modification date.

DaveWitteMorris commented 2 years ago
comment:8

Another problem is that sagemath (following maxima) is giving the wrong value for the limit. The correct answer is 4*m + 1, not 0. A ticket to fix this is at #34140.