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
weird conversion from QQ to RDF #14416
Comments
comment:1
Tracing things back, the conversion eventually gets done by:
since |
comment:2
ok, then the explanation is that One could call I propose to close this ticket. Paul |
comment:3
So it's okay that
as Thierry pointed out here? Just asking. Or is it RR that is behaving sub-optimally in this case? I assume that three roundings is ordinarily worse than one - my apologies for asking dumb questions. |
comment:4
The reason why However instead of closing this ticket, I propose someone should implement a tutorial and/or improve the documentation and/or sage basics. I can do it if needbe. |
comment:5
Whoops, didn't mean to change the milestone. |
comment:6
As Paul explained, the rounding is the same for RR and RDF: RDF rounds its computations to the nearest. Actually, the problem is somewhere else: the conversion from QQ to RDF rounds towards zero, which is not consistent with the general behaviour of RDF. IMHO, this conversion from QQ to RDF should be fixed, if possible. |
comment:7
Ah I see. I misread/misinterpreted Paul's explanation. I also agree that this should be fixed for consistency:
|
comment:8
Karl-Dieter, Replying to @kcrisman:
what is annoying is that RDF and RR give different results. The fact that RR gives
Paul |
comment:9
it is possible: first call the MPFR function Converting separately the numerator and the denominator to RDF, then dividing in RDF does not work,
Paul |
comment:10
RDF is for when you want your computations to be fast, at the expense of a little bit of accuracy/less control of rounding/platform dependence. As such, I think different behavior than RR is completely acceptable. It would be nice if |
comment:11
Robert, would the following be ok in what concerns speed? Let p/q the fraction to be converted to RDF, I assume p, q > 0.
5a) if s=0, return (r-1)*2k if the bit of weight 1 of r is 0, otherwise (r+1)*2k I guess mpq_get_d does basically steps 1-4, thus it should be comparable in speed. Paul |
comment:12
here is some tentative code which converts from QQ to RDF with rounding to nearest.
However I don't know where to incorporate that code in Sage. Could someone help? Paul |
comment:13
Volker points to here in sage/rings/rational.pyx. I imagine that one could just replace that |
comment:14
That looks like pure C code. Isn't there an mpz/mpq package with the underlying C(++) code, and wouldn't this go in there...? |
comment:48
Some tests might be machine-specific, but at least on most machines, all tests pass indeed. |
comment:50
Rebased for doctest failures with #14336. Paul: are you sure you don't want to review the patch? If the both of us look at the patch, that should be sufficient, no? |
comment:51
I will try to review it next week. But if someone beats me, no problem! Paul |
Reviewer: Paul Zimmermann |
comment:52
Jeroen, a few tiny comments:
Apart from that (and if tests still pass) I'm fine with the patch. Paul |
comment:53
Replying to @zimmermann6:
Sure, but I wanted some safety margin.
OK, but then for all covergents (before throwing away the first 20).
Yes, because |
comment:54
I could not apply the patch to 5.9 (after applying successfully the two dependencies):
Thus I cannot check all tests still pass. We'll have to rely on the testbot. Paul |
comment:55
Attachment: 14416_QQ_to_RDF_v2.patch.gz Replying to @zimmermann6:
Since essentially every hunk fails, it looks like you're applying the patch on top of itself. Anyway, I updated the patch with your suggestions. |
comment:57
Paul, any chance for a review again? |
comment:58
yes, will do. |
comment:59
on top of Sage 5.9, I get doctest failures:
Paul |
comment:60
None of these failures look related to this ticket, what does a "clean" Sage 5.9 (without any applied patches) give? Please attach the actual doctest failures, not just the summary at the end, otherwise it is impossible to find out what went wrong. |
comment:61
maybe the doctest failures are due to some interaction with a spkg I installed in another clone of Sage (I installed the patches needed for #9880, and I believe there is side effect from one clone to the other ones for installed spkgs). Is there any way to get a "clean" Sage 5.9 without recompiling the sources again? Anyway my remarks from comment [comment:52] are taken into account, thus provided all tests pass with the testbot, I give a positive review. Paul |
Merged: sage-5.11.beta0 |
the following is weird:
One would expect that the conversion from 1/10 to RDF is done as follows:
For RR we get as a comparison:
More examples:
and for RR:
Apply attachment: 14416_QQ_to_RDF_v2.patch
Depends on #14335
Depends on #14336
CC: @robertwb
Component: basic arithmetic
Author: Paul Zimmermann, Jeroen Demeyer
Reviewer: Paul Zimmermann
Merged: sage-5.11.beta0
Issue created by migration from https://trac.sagemath.org/ticket/14416
The text was updated successfully, but these errors were encountered: