-
-
Notifications
You must be signed in to change notification settings - Fork 528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solve and assumptions too aggressive with cube root of negative numbers #11941
Comments
Milestone sage-4.7.3 deleted |
comment:2
The fact that Maxima normally returns
So if we fix that problem, then at least it would
(Note that the I am new, however, and I am not sure where next to look. |
comment:3
Well, in general we do not want to do this. It's been discussed ad nauseam many times, and the sense is that:
This ticket is about the fact that Maxima returns three solutions to the equation, but when we do the |
comment:4
Here's what maple does:
I wonder why maxima is returning |
comment:5
No, no! See this example from the description:
We are somehow getting the |
comment:6
It seems that sage sets domain: complex (I was made aware of this by burcin in IRC). You do get this result as follows: {{{(%i8) domain:complex; (%o8) complex (%o9) [x = ((-1)(1/3)sqrt(3)%i-(-1)(1/3))/2, |
comment:7
Ugh, all my comments have screwed up formatting. I wish I could edit them (can I?). I should have been:
|
comment:8
Replying to @mboratko:
Yes, we do, but I didn't bother checking that. Good work. So of course now the question becomes what the "right" thing to do is? I don't think we want to set and unset
Typically we would want the latter answer, e.g in
|
comment:9
I've attached a fairly limited workaround, but it does give (semi?) desirable behavior:
If it is then up to the user to interpret the result, this seems ok. If they want to programmatically use the result later, it's really no good. I suppose if they were aware of this and wanted to fix the result to be real then they could manually employ the same method as in my patch to the result. I guess, as a more general question, do we want the results of solve to always return a result with domain: real, and if so can we make this change for just this function? If there is a use case where this is undesirable, then I think the only option is make the assumptions file not only check the returned value, but also modify it (so that if assume is real, then the value is actually replaced with the real values). Perhaps another option is to allow the user to specify the desired domain of results from solve. |
Attachment: trac_11941.patch.gz limited workaround for assumption and solve |
comment:14
You need to set "needs review" if you want someone to look at your code. I'll do that now. |
comment:15
As Karl-Dieter says in comment:8 it is not desirable to switch back and forth with Maxima domain commands, so I don't think your patch is the right way to solve it, esp. since you don't get the right result, either. Presumably the failure of assumption should be reported upstream. |
Upstream: Not yet reported upstream; Will do shortly. |
Work Issues: report upstream |
comment:16
As found in #22017 SymPy gets it right. If SymPy is better than Maxima with symbolic polynomial roots then I think we should switch to SymPy for the special case. |
comment:17
Note that sympy also incorporates assumptions into the solver: In [2]: x = var('x', real=True)
In [3]: solve(Eq(x**3, -8))
Out[3]: [-2] |
comment:18
Switching to SymPy would also depend on something like #22024. |
comment:19
With #22024 we have now:
which, as I understand the notorious discussion, isn't right either because in the complex domain Maxima's results are not reproduced? |
comment:20
Replying to @rwst:
Hmmm... things seems to have changed on Maxima's front. Compare :
[ Note : this is "our" Maxima ; but Maxima 5.40.0 as packaged in Debian and Cocalc's version both give the same answers... ] and :
Maxima's second answer may be disputable (it doesn't account for the declaration of I'm painfully tempted to file a new ticket and flag it as critical. Advice ? |
comment:21
As pointed out earlier, this is due to
|
comment:22
And if you can figure out how to deal with this - in Maxima or elsewhere - please do! I don't think this was ever reported upstream. |
comment:23
Replying to @kcrisman:
OK. I agree that this is only disputable. My beef is with Sage's second answer, which tells us that Sage is unable to find a real root to |
comment:24
You can definitely feel free to fix it or report upstream though! It is ugly to say the least. The second answer I can't quite explain. Typically
However, note that without
as perhaps noted above. Here is the relevant code for how Sage checks for assumptions with solving.
Apparently something is going wrong here with |
comment:25
Replying to @kcrisman:
Inded. But the point of not replacing (-1)!^(1/n) by -1 is well taken : the first expression may, after all, be any nth root of -1 (see an example below). So I'm not sure it's a bug. But yes, it's ugly as hell... (more tolerable in \LaTeX...).
I think that our code for testing that an expression is real is too weak. After all,
A workaround is to force the evaluation of each root "in Sage terms", as demonstrates the following crock :
None of these roots is known as real (in direct contradiction of d'Alembert's theorem, no less...). Try to force a re-evaluation of these expressions :
(Note that this implies that, in that specific case, Now, these re-evaluated quantities can be effectively tested for "reality" :
I do not know what code uses the The problem is now to know what code is to be fixed : assumptions ? Or more general algebraic code ? Is this problem specific to Maxima-generated expressions, or more general ? How to force re-evaluation ( Advice more than welcome... |
comment:26
One more data point : Maxima seems to be able to solve the specific test which is problematic for the current Sage assumption code. Consider :
Questions :
Advice necessary... |
comment:27
Replying to @EmmanuelCharpentier:
The False from is_real (and any of these functions) just means "I don't know" in absence of a Python tri-state logic. It may be possible to return Unknown here by implementing |
comment:28
Replying to @EmmanuelCharpentier:
Is that root really real? In what domain is Maxima at that point? |
comment:29
Replying to @rwst:
That's what Maxima says. Whatever it does is probably more credible than what we do (see below).
Look for yourself :
The numerical values tend to confirm that the first root is real. And that is our problem : the That said, I stumbled on another problem. Our current code doesn't pass declarations to Maxima correctly :
I haven't (yet) checked trac to see if this is known. If not, that's a nice ticket to file. I don't (yet) have a solution. |
#6515 did a great job helping us start to catch some assumptions when we do solving.
However, this ask.sagemath.org post catches a case where it's too aggressive, because Sage says that
(-1)^(1/3)
is not real.What's weird about this is that the Maxima in Sage should just return
x==-1
.Not sure what's going on with that.
Upstream: Not yet reported upstream; Will do shortly.
CC: @pelegm
Component: symbolics
Work Issues: report upstream
Issue created by migration from https://trac.sagemath.org/ticket/11941
The text was updated successfully, but these errors were encountered: