-
-
Notifications
You must be signed in to change notification settings - Fork 704
Fix inconsistency of != with is_zero() and matrix symmetry #41212
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
base: develop
Are you sure you want to change the base?
Conversation
Ensure consistency between != and is_zero() for variables with domain constraints and fix matrix symmetry issue.
|
Why did you close this? |
This bool method is very fragile Some small changes will break doctests. And maybe will raise bugs I do not know |
|
For the record: the proposed fix leads to The specification of So, in principle, returning a wrong Is there documentation for |
But the fixes will break somethings, I think it will need to refactor the whole sage's lib |
|
Yes, that's what I said. The proposed fix is incorrect, but is simply a bug. |
Refactor checks for variable inequality and zero consistency, including domain constraints and assumptions.
|
@mantepse I have fixed it minimally, and it do not affect other parts. |
|
Just try to patch this in this way, it does not involved many changes. real complex integer do not provide information about whether it is zero or not. |
|
I think that the direction is good, but we are not quite there yet. I think it should depend on the operator which assumptions we have to take into account. Currently (i.e., without your patch), do we reach |
|
CC: @orlitzky |
Yes, we reach this maxima part directly after it return NotImplement from gianc without this patch. Because the system think it is with assumptions. But these assumptions do not provide any informations |
|
And you can see the domain assumptions are GenericDeclaration. |
|
And I think it is also not a good ideal. Because it will not fix the root cause. And I believe there are new bugs we do not discover. This patch only patches for this case. |
I thought so until yesterday, when I learned on the maxima mailing list that this is not the case:
I now see that I was not as precise as I should have been. What I meant to say is that
In particular, this explains why the maxima manual contains However, with our specification, |
|
It seems Ok. Do not affect other parts doctests |
Interesting! Indeed even |
In fact, many mathematical software use tristate logic, including mathematica sympy and so on. But our sagelib codes have many != and they use if !=. python if only accept bool. So it will affect the whole sagelib. It need much work. |
In that case it may make sense to make a (partial) inventory of This would definitely require discussion on sage-devel: the current behaviour in sage has been around for quite a while, so there are going to be people out there who rely on that behaviour. For the change to happen, one would need to argue that correct behaviour throughout the sagemath library is more important than the convenience of backwards compatibility. The thing is: a lot of the functionality in sagemath doesn't work well with SR anyway, so there is little use in increasing correctness for this particular thing. That's why a convincing inventory will help make a case. |
My idea is that the == behavior in expression is clear, which means we can verify its equal as expressions clearly. So we can write in document that we define != by not ==. Then I think it is a uniform way to define nonequal. we should make each part to define in this way. |
It only affects the behavior of expression. It is the cost that we need to be compatible for bool system in fact it is a tristate logic system. sometimes we need to be stricter. |
|
I agree that defining I do think it's cleaner to implement the changed behaviour in sage/src/sage/symbolic/expression.pyx Lines 3437 to 3441 in 5c8d9e9
maxima_check_relation (because that routine is well-documented and does what it claims). There is some shenanigans with == vs. != earlier on in the file already, so perhaps that can be used to straighten out the code.
|
|
Particularly this fragment: sage/src/sage/symbolic/expression.pyx Lines 3391 to 3401 in 5c8d9e9
It deals with a similar problem but does its own conversion to/from maxima. That's not a smart idea: the purely strings-based conversion there is significantly less sophisticated than what our standard to/from maxima interface does (and probably a bit slower too!). I'd expect this can be refactored together with the invocation of maxima further down below. |
But one problem is that the check_relation_maxima we use in this bool function has already violate the document of bool function. It said that only we can verify it is zero return False. the behavior of check_relation_maxima and bool will be contradict in the documents with only bool system. @nbruin @mantepse |
|
Another way is that we can add a check_maxima_relation_2 function or other names is only for bool on expression used |
|
bool want to check != by not ==. But check_maxima want to check != if it is really noequal at all. It is contradict in bool system we just have True and False. |
|
@nbruin Do you think it is OK to add a new function such that regards != as not == |
|
I think it would be important to do this systematically, rather than fiddling around. Let
Assuming that the above is true (which I somewhat doubt), we have two possibilities for a definition of 1.) it could be the same as I think it would be good to make this consistent with lazy power series, where we cannot test for zero either: Apart from that, we also need to decide what a) return (Note that this has no relevance to the original bug report, because in that case SageMath should have no trouble deciding that the matrix is non-symmetric.) Finally, is it possible to have a general policy for methods like |
We can not do that. Because like this issue Do you expect it is True or False. In fact because x in RR, It can be True and can be False. It is undecided. This is said in the document of |
|
some strange things, In this https://groups.google.com/g/sage-devel/c/hGOw9X2X9xQ/m/UpsjvNfOBQAJ It is also preserve that != is not ==. But the mathemtical behavior looks like strange |
|
just my little grain of sand: maybe #38707 is relevant |
Thank you very much. |
I think that's a different issue. There are some further issues, particularly in
On top of that,
So I think three things need to happen:
So @cxzhong : no I don't think just adding another version of |
|
maybe the code is written very long ago. I try to make it more clear and readable and speed up it. @nbruin Thank you very much |
|
I found that we do not have compare equal and inequal in the maxima interface. we have to use |
|
@nbruin Thank you for your reviewing. I found that pynac can deal with assumptions too. and it will True for the absolutely right case. So we can delete such maxima logic in pynac. But and if pynac return notimplement (for this bug issue it will return notimplement instead of False or True, I just check this), then turn to assumption check, if no assumption, turn to interval field check logic. Otherwise turn to maxima path. I do not use special cases like before. they all turn to by maxima_init logic. I think in this way we can deal with assumptions better. But I do not find how to deal with equal and inequal in maxima interface. I have to use |
Make sure to check some more complicated examples! Blame shows that the more elaborate handling of I expect the code can be refactored, but it looks like they had a particular reason to give extra attention to Avoiding string parsing for maxima is a matter of reaching into maxima_lib a little more. That's straightforward. I can do that in a few weeks, when I may have a bit more time. EDIT: Here's a quick fragment for doing the equality tests without relying on string conversions (mostly). Part of this code would probably be best incorporated in maxima_lib, where it would live most comfortably. Then you can just import The code just uses the ECL interface to construct the appropriate lisp structure for the desired maxima operation and then calls the maxima evaluator on that. We're doing this construction via the basic (and hopefully fast) lisp library constructors. The wrapper objects of lisp functions (this is what As background info, |
I just test #1163 It is right now. I think some bugs in gianc and maxima have been fixed. is wrong. we can not |
Problem Description
The Bug
When symbolic variables are declared with domain constraints (e.g.,
domain='real'), there was an inconsistency between the behavior of the!=operator and theis_zero()method:Impact
This bug caused incorrect behavior in matrix operations. For example, a triangular matrix was incorrectly identified as symmetric:
Root Cause
The
_bool_method inexpression.pyxis not compatible with thecheck_relation_maximafunction. When they deal withne. Because maxima saida!=bis unknown,check_relation_maximareturnsFalse. But when we usea!=b, python consider it asnot a==b. so it return True.Fix #41125
📝 Checklist
⌛ Dependencies