-
-
Notifications
You must be signed in to change notification settings - Fork 488
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
disallow dangerous coercions to RIF #15114
Comments
This comment has been minimized.
This comment has been minimized.
comment:4
I think this change will cause many more problems than it solves. In practice: I expect this will break a lot of existing code. I often use the RR --> RIF coercion intentionally, because it makes it more convenient to do exactly what I want. For instance:
In theory: I think the motivation is flawed. The change was proposed to avoid accidental coercion of exact ring values to RIF via potentially inexact RR. But the problem in this case is the first step, not the second, and reflects the need for a direct coercion from the exact ring to RIF. In such a case, the lack of such a coercion is the bug. Whereas each value in RR does have a valid coercion to RIF, and the lack of this coercion would also be a bug. Realistically, I think anyone who is actually
is going to be sufficiently aware of the potential problem that they will handle/check the conversion explicitly. Better to expect this than to inconvenience many users who use this coercion in far less arcane circumstances. |
comment:5
Replying to @sagetrac-tcoffee:
Thanks for the comments. I mentioned them in the sage-devel thread where the original discussion took place. Let's move the discussion there. |
Branch: u/dkrenn/remove-coerce-RR-RIF |
comment:10
Does your branch pass the tests? I tried doing something similar a while ago (see New commits:
|
Commit: |
comment:11
Replying to @mezzarobba:
I am cleaning up my SageMath-versions and found this partial work. As no branch was attached to this ticket, I've uploaded it. So it will, for sure, need some work. |
Replying to @mstreng:
What's wrong with this? I honestly don't really see a problem with coercion |
comment:13
Replying to @jdemeyer:
With
For me it is similar to the way coercions are implemented between In conclusion: if any coercion, it should be the other way around (by taking the center). |
comment:14
I think a lot depends on how you model mathematically elements of interval fields. There are two ways to interpret them: either as real numbers with some uncertainty or actually as intervals of real numbers. In the "interval" model, the coercion RR -> RIF makes sense: you identify a real number with a singleton, which is a special case of an interval. On the other hand, the "choose the middle point map" RIF -> RR is neither natural (the middle point is an arbitrary choice) nor a morphism, which are two requirements for a coercion. In the "real number with uncertainty" model, you could see RIF -> RR as the forgetful map which keeps the real number but forgets about the uncertainty. In that case, this map is more natural than the opposite. For me, it is pretty clear that MPFI is really meant to model intervals while arb models real numbers with uncertainty. |
comment:15
Replying to @jdemeyer:
I sort of agree, but still, the key property is that operations on MPFI intervals return over-approximations of the set of possible results (in particular, they round the endpoints of the results in the correct direction), and having a coercion from plain floating-point numbers would effectively break that. What would make sense to me if you want ”intervals of real numbers” with a coercion from the corresponding real numbers themselves would be a separate parent |
comment:16
Replying to @mezzarobba:
So, is this an argument in favor of the coercion |
comment:17
Replying to @jdemeyer:
No: operations in
Certainly not. |
comment:18
Replying to @mezzarobba:
Yes, obviously because that's the right thing to do.
Technically not, but that is just an implementation detail. |
comment:19
Replying to @videlec:
Huge +1. (Having reliable numerical computations is a (the) major application of interval arithmetic.) |
comment:21
Replying to @jdemeyer:
It is not to me. I found various texts (by MPFI developers) that motivate why MPFI exists and they all start by saying things about "guaranteeing results" and "certified enclosures" for floating point real arithmetic. And if an automatic silent coercion mixes a guaranteed result with a non-guaranteed result, this is bad. People prove theorems using I did not know that people also use the outward-rounding RIF for "arithmetic with intervals" without caring about guaranteed inclusion. I understand that for them it is convenient that the following works:
to get the interval [5, 8]. However, it is hardly any extra work to do the direct thing that the coercion model currently does for you, which is:
And we can also implement additional functions, e.g.
So I am very much in favour of removing automatic coercions between RR and RIF. Perhaps with a |
comment:22
Replying to @mstreng:
If it is considered a bug, then no deprecation is needed... |
comment:24
The problem with this ticket is that various places in Sage use this coercion. In particular
|
comment:25
Replying to @dkrenn:
It's documented behaviour so it's maybe a misfeature but not a bug. Anyway, it seems that most people think that the coercion |
comment:35
I could not test everything locally due to version issues with pari and giac, so the patchbot may still uncover problems, but this is starting to take shape, and comments are already welcome. @bhutz: You may want to check the commit touching @JohnCremona, @pjbruin: Same remark regarding the changes to |
comment:36
I see no problems with the minor code changes to elliptic curve heights, though I don't think that any of the affected functions was written by me. |
comment:37
I don't think I contributed much to this precise code either, but the changes certainly look fine to me. |
comment:38
Thank you both for your comments. John: indeed, |
comment:39
Replying to @mezzarobba:
That agrees with my memory. heegner.py was from his thesis, I think, and he rewrote the unpleasant complex interval stuff from a script I had in (I think) gp. |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
comment:41
The changes in binary_form_reduce.py look fine to me. The use of .lower() and .upper() I expect should have been there in the first place and we've just never come across an example where being that careful with the errors mattered. |
comment:42
Replying to @bhutz:
Thank you. All tests pass now, reviewers welcome! |
comment:43
This is great. I am positively surprised for seeing only few changes for making this happen! The only trouble I see is that it might break user code without deprecation notice. |
comment:44
Replying to @videlec:
The switch to Python 3 (and, I think, also the change to make
I agree. But I don't know what to to to ease the transition. Do you see a way to display a deprecation warning when a coercion map is used while keeping the corresponding conversion map working? That being said, between the issues it indirectly causes and the inconsistency with other interval fields, I would almost call the existence of this coercion a bug. |
comment:45
Replying to @mezzarobba:
One possibility would be to support the operations (with a warning) without having the coercions. One cumbersome way to do this is to implement custom
But I don't see a simple way to do it in order to also handle functorial constructions such as vectors or polynomials. Though, given the changes you had to do in the doctests, I think it makes sense to only consider scalars.
Agreed, but https://xkcd.com/1172/ |
comment:46
Replying to @videlec:
Unless we do it for floating-point types too (which would be a bit invasive), it will work for |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
comment:48
Replying to @mezzarobba:
Ok, for lack of a better option, I have done that—for |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
comment:50
Rebased to fix a merge conflict due to whitespace changes... |
comment:51
Vincent, do you think you will finish the review, or should I look for someone willing to take over? |
Reviewer: Vincent Delecroix |
comment:53
Great, thank you! |
Changed branch from u/mmezzarobba/15114_RR_to_RIF to |
Remove the following coercions because they make interval arithmetic much less trustworthy.
RealField
-->RealIntervalField
float
-->ComplexIntervalField
SR
-->ComplexIntervalField
For example, one could easily do the following by accident.
See also this topic on sage-devel
Already removed in other tickets:
ComplexField
-->ComplexIntervalField
CC: @videlec @mezzarobba @dkrenn @cheuberg @bhutz @JohnCremona @pjbruin
Component: coercion
Keywords: RIF RR interval coercion
Author: Marc Mezzarobba
Branch/Commit:
3c7644f
Reviewer: Vincent Delecroix
Issue created by migration from https://trac.sagemath.org/ticket/15114
The text was updated successfully, but these errors were encountered: