-
-
Notifications
You must be signed in to change notification settings - Fork 401
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
rationals enumeration not monotone in height #309
Comments
comment:2
As a thought experiment, I implemented the naive algorithm for enumerating the rationals according to the height. To my surprise, it seems to have the same speed as the version implemented by Nils (which is not monotone in height, hence this ticket -- see below for sample timings). So I think we should just use the naive algorithm, which is in the attached patch. It seemed a shame to throw out Nils' code so I just commented it out and fixed its references. with old code:
with new code:
|
comment:5
I prefer this, and would definitely want to use it in preference to the clever one. In fact I do exactly the same thing somewhere in the modular symbols code in eclib... It would be nice to make it easier for users to create iterators to (say) loop through all rationals up to a certain height, without having to resort to "import itertools" magic. Something like this:
which would loop through all rationals of height <H. Anyway, this patch applies fine to 3.1.2.alpha3, but doctesting rational_field.py threw up this for me:
|
comment:6
Thanks for looking at this, John. I don't know enough about Python iterators at the moment to implement the more user-friendly version, but I do agree with you. The doctest failure makes no sense, because if you look at the patch it clearly removes the line with the first 10 rationals and replaces it with the first 17 rationals. Something must have gone wrong when you applied the patch? |
comment:7
I applied and tested the patch with alpha3 on x86-64 linux and 32 bit OSX and cannot reproduce the failure? Maybe something went wrong with the merge as Alex suspected? Cheers, Michael |
comment:8
Attachment: 309-rational_iter_height.patch.gz mhansen gave me a crash course on iterators and I have implemented a method QQ.range_by_height(). John's request from above becomes then
I have replaced the old patch with one that contains this method as well. |
comment:9
With Alex's old patch I am actually seeing one doctest failure in interact:
I am trying the new patch now, but I expect the same result. Cheers, Michael |
comment:10
With the new patch I get:
Cheers, Michael |
Attachment: 309-rational_iter_height_interactive.patch.gz apply on top of 309-rational_iter_height.patch and the patch from #4037 |
comment:11
The doctest in interact.py needs a trivial fix. The second patch file puts this in, but it has to be applied after the patch from #4037. |
comment:12
Brilliant! I'm impressed with the way my suggested enhancement was added so well and so quickly! I successfully applied both patches after the one from #4037, which also has a positive review, and everything works fine. |
comment:13
Merged both patches in Sage 3.1.2.alpha4 |
While the new
Rationals().__iter__ method
is really nice and quick, I realized there is one drawback: The enumeration is not completely wrt increasing height:yields
so the jumps in height actually do get big. Many people will expect that if a certain number occurs in the enumeration, then all numbers of smaller height have also appeared. Therefore, we should perhaps have a choice of algorithm (since the present formula (sage 2.2) is so cool, I think it should be left in, but perhaps not as default enumeration order).
On the other hand, I realize that nobody will be using this routine anyway, so any change to this routine is essentially a waste of time.
Component: basic arithmetic
Issue created by migration from https://trac.sagemath.org/ticket/309
The text was updated successfully, but these errors were encountered: