-
-
Notifications
You must be signed in to change notification settings - Fork 729
Fix incorrect tests and override canonical associate #41288
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
Because one use roundtieeven, one use roundawayzero
Removed unused variable 'b' from test loop.
|
Documentation preview for this PR (built with commit 746b07c; changes) is ready! 🎉 |
Added tests for rounding behavior with quadratic fields and implemented a canonical associate method.
|
Related to the rounding problem: #39486 and linked pull requests from there. The rounding results are supposed to agree. That it doesn't is a bug, it's just nobody have gotten around to decide what to do with it yet. (Changing it is sort of a breaking change) |
OK, I know. I think maybe this file is a wrapper of mpfr library. and |
|
The discussion from #41268 is relevant here: There it was proposed to bring RealField's rounding in line with TieToEven. The discussion there did not take into account that the failures are a knock-on effect of changing the default rounding on QQ, which then triggered the change in the rounding on quadratic integers. There it bumped into the rounding on RealField. I think this clearly illustrates that these are indeed breaking changes (if only for the tests in sagemath!) Without extensive context, the sensible thing to do on RealField is "just do what MPFR does", since that's the main provider for functionality. MPFR decided to round away from zero on ties. I don't know why, but I think that's been compatible with most of sage until recently. It would be good to know if they have good reasons. IEEE-754 is silent about what "round to nearest integer" should do; probably because for many floats it's a nonsensical operation. There are many applications where one just actively ensures that rounding does make sense. Those cases tend to stay away from ties, so the boundary behaviour doesn't really matter for actual applications. IEEE-754 does have comments on how to round to the nearest representable float and does give a preference to TiesToEven. MPFR has a whole slew of rounding modes available. They are set in a "context". In In a variable precision implementation like [EDIT: this is a sensible rounding method but it's NOT This code is obviously not how one should actually implement this, but it illustrates the process. so I think an argument can be made that it's reasonable to use the rounding mode on RealField to round nearest integers as well. Once again, I think this is a lot of work for something that basically doesn't matter for floats. But if people think it's really important to align float rounding with rounding on exact types like QQ and number fields then I think this would be the way to go. Changing this would have ripple effects for RIF and possibly RealBallField (and then their complex counterparts as well) because those types are supposed to track provably what happens with intervals of real numbers (with the boundaries specified by mprf represented floats). Rounding may not be the most important operation there (and certainly not cases where the boundary comes into play!), but you do risk introducing inconsistencies in float-based code that IS trying to be rigorous. The code in those libraries has been informed by So I think it's not so much the MPFR round itself that we need to respect but the whole MPFI and Arb beasts that are lurking behind it. A more careful analysis may show it's not so bad, but there is definitely cause for treading carefully. |
Edit: I argue that the new behavior is "correct" (with respect to the new
they have Since they provide both, it's hard to say
A non-breaking way would be
|
|
From the documentation https://www.mpfr.org/mpfr-current/mpfr.html#index-mpfr_005frint I would say that I wasn't aware that mpfr had all these different rounding functions; basically on equal footing. Clearly they didn't make a choice for what the "default" should be. It actually looks like the original author of RealField just took the thing that happened to have the same name in mpfr. Looking at the blame: this routine goes back a LONG time. The rounding was always away from zero. First , Note that mpfr also has the If we let "round" use the rounding of the parent through What you call "nonbreaking" will be very disruptive: anyone who happens to use rounding will be affected, whereas the change in reality probably doesn't affect any meaningful uses of "round" (given that rounding a tie is a red flag for an unreliable result already). It's a matter of fact that float operations are not guaranteed to be bit-for-bit compatible between different versions of the software. Our doctests even acknowledge that. If this is felt to be important enough to change, then I think it is less disruptive to deal with this through as a "bit change in float behaviour" than to go through the deprecation song-and-dance. The pain of that will outweigh benefits for a very long time. |
so basically #41268 ? side note, I also propose global setting to set to new version, which I think is not very disruptive. |
|
Yes, it would be largely #41268, with the refinement that, instead of hardcoding The mechanism of a "global setting" is problematic because of scope and even -- possibly -- parallelism. In any case, I think that is still very disruptive, because now you'll require everyone who uses round to still change their code to set a global flag. It's probably a good idea to give run this by sage-devel because we only have a limited number of voices represented here and it is, technically, a breaking change (particularly because the documented behaviour of |
I think what you have in mind is
which is a reasonable choice. (1)
agree. Unimportant nitpicking: (1): this is not what
in other words,
There's
not necessarily. My proposal is to provide two options, either different method name (round/round_away_from_zero/round_even) or global flag. Then everyone who uses round should change the method name. |
Oops. Indeed. I think that's actually important. It shows that they were right in implementing all these different functions (of course! why would they have done so otherwise!). And I guess they left out "round ties to even" because It's not clear to me that there is demand for two rounding routines. It makes the most sense to run a proposal by sage-devel on whether the semantics of round should be changed from TiesAway ot TiesToEven. If only our floats were base 3 ... Renaming, ContextVars and threadlocal stuff just makes this all more complicated and it would be unavoidable for someone who needs rounding somewhere. I don't think that will be welcomed by anyone for something as trivial as deciding where a rounding tie goes. You can make that part of the question to sage-devel. |
Because one use roundtieeven, one use roundawayzero. They are not equal when half integers
And also move passagemath/passagemath#1770 into this file
📝 Checklist
⌛ Dependencies