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
random_prime does not handle erroneous input gracefully - it hangs #10112
Comments
Author: Mike Hansen |
comment:2
Mike, Should the example on line 1127 be
Currently it's the same as the previous example. One thing that would be nice is if you did like John did at #10105 and have doctests for the commands that currently hang Sage. Then if there are any regressions, and the bug(s) get back in, this will be detected. Perhaps I'll get bored of running my little script that supplies junk to commands to see what ones crash sage (like #10113) or hang Sage like this ticket, #10108 and #10105. |
comment:3
Attachment: trac_10112.patch.gz I've updated the patch. |
comment:4
Thank you, I will take a look later today and test it. |
comment:5
The patch deals with the cases listed. But there are other cases which hang, like
and some that almost do, like
They can be very easily dealt with. The additional patch does this. |
Attachment: trac_10112-extra.patch.gz to apply after trac_10112.patch |
comment:6
Those two patches are a definite improvement, so I'm giving it a positive review. I've opened #10277 for another issue with Sage's implementation is also incredibly slow compared to Mathematica. After 20 minutes of CPU time on a 3.33 GHz machine I was unable to generate one up to 101000 with Sage. Yet Mathematica can do that in 7 seconds! Dave |
Reviewer: David Kirkby |
Changed author from Mike Hansen to Mike Hansen, Francis Clarke |
comment:8
I'm setting this to 'needs info', as William remarked on sage-devel that he did not see this issue with 4,6 that I get at. It seems highly unlikely, but these patches could just be whats casing that problem for me. |
comment:9
The issue raised in #10277 (which surely arises from using |
comment:10
A replacement patch is attached. It uses Betrand's postulate and refinements due to Nakura and Schoenfield. Only when the ratio of the upper and lower bounds is quite close to one is the smallest prime in the interval computed. |
comment:11
Can we create a fast but unsafe function ATM, the When this change is made, there should be a clear and loud warning in the release notes to notify people who rely on the current behavior of |
Attachment: trac_10112-replacement-extra.patch.gz Apply after trac_10112.patch INSTEAD of trac_10112-extra.patch |
comment:12
Replying to @burcin:
A good idea. But the slowdown is, for most cases, far less significant with the new patch. |
comment:13
Probably the way forward would be to have a "check" option. But to quantify my earlier remark, I note that for the default bounds used in |
comment:14
Is there any reason this should not be changed to positive review if the slowdown is very small? Unless there's universal agreement on this, I suggest the changes in documentation, are put on #10111. That ticket was supposed to address the deficiencies in the documentation. The only comment on that ticket is from Mike, and is See the patch at #10112. But if Mikes patch here, which changes both the documentation and the code is going to stall, we might as well just fix the documentation for now on #10111. The changes needed to the documentation appear to be
If there is no agreement to merge the two patches here, I'll create one patch which just fixes the above 3 documentation problems and add that to #10111. Does that make sense? Dave |
This comment has been minimized.
This comment has been minimized.
comment:15
Replying to @sagetrac-drkirkby:
I don't think so. The code looks okay, is well documented, and passes all tests. |
Changed reviewer from David Kirkby to David Kirkby, Johan Bosman |
This comment has been minimized.
This comment has been minimized.
Merged: sage-4.8.alpha1 |
comment:18
The patch contains non-ASCII characters which Sphinx 1.1.2 (#10620) rejects. |
comment:19
We could put |
apply on top of other patches |
comment:20
Attachment: trac_10112-ascii.patch.gz |
As noted at #10111 and
http://groups.google.com/group/sage-devel/browse_thread/thread/6e8d6f28c915830d?hl=en
random_prime()
is not well documented.But
random_prime()
is also broken for some erroneous input. Programs should always handle poor input properly, which is the case of Sage probably means generating an error message.Having a negative lower bound can cause the function to hang, but this is not always the case, as the example below shows. Here an error message is generated.
Dave
Apply
to the Sage library.
Component: number theory
Author: Mike Hansen, Francis Clarke
Reviewer: David Kirkby, Johan Bosman
Merged: sage-4.8.alpha1
Issue created by migration from https://trac.sagemath.org/ticket/10112
The text was updated successfully, but these errors were encountered: