Closed videlec closed 9 years ago
Branch: u/vdelecroix/16878
Description changed:
---
+++
@@ -15,7 +15,7 @@
10000 loops, best of 3: 4.19 µs per loop
-The patch do some tiny modifications in integer.pyx
and we get
+The patch does some tiny modifications in integer.pyx
and we get
sage: timeit("121.is_prime()", number=10000)
I would prefer not to include stuff from pari/pari.h
directly, but instead use the declarations from src/sage/libs/pari/decl.pxi
. And please rebase this over #15767.
Reviewer: Jeroen Demeyer
Can you also change the value of PARI_PSEUDOPRIME_LIMIT
(see PARI docs) to 2^64
and use mpz_fits_ui()
before calling mpz_get_ui()
Instead of changing _pari_()
to _pari_c()
everywhere, wouldn't
cpdef _pari_(self)
accomplish the same thing?
Thanks for the remark. One question: are we sure that 264 fits into an unsigned long on any platform? Otherwise we can not safely call uisprime
and uisprimepower
. If not I will use a double check
if mpz_cmp(PARI_PSEUDOPRIME_LIMIT, v) > 0 and mpz_cmp_ui(v, ULONG_MAX) < 0:
# use uisprime or uisprimepower
Vincent
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
37fc8e8 | Upgrade to PARI-2.7.1 |
5db54b6 | Trac 15767: reviewer patch |
1d103da | Trac 15767: fix doctest in Ser() |
62ca821 | Trac 15767: explain application of Sturm's theorem |
bf435f8 | Merge tag '6.4.beta1' into ticket/15767 |
6e9f686 | trac #16878: faster is_prime |
d7dc389 | trac #16878: review |
Dependencies: #15767
10000000000000000 != 2^64
:-)
I don't think we should lower PARI_PSEUDOPRIME_LIMIT
because it's also used in places where it's not bounded by ULONG_MAX
, see next_prime()
for example.
Personally, I would assume that ULONG_MAX
< 2^64
and just use mpz_fits_uint_p()
.
Also, you wrote "set set" instead of "set".
Branch pushed to git repo; I updated commit sha1. New commits:
175d6b5 | trac #16878: review 2 |
This is bikeshedding I know, but wouldn't
mpz_ui_pow_ui(PARI_PSEUDOPRIME_LIMIT, 2, 64)
be easier to understand?
Branch pushed to git repo; I updated commit sha1. New commits:
d55dc67 | trac #16878: bikeshedding |
ping! (applies cleanly on 6.4.beta2)
Description changed:
---
+++
@@ -23,3 +23,5 @@
sage: timeit("1009.is_prime()", number=10000)
10000 loops, best of 3: 730 ns per loop
+
+We also modify is_prime_power()
to return False
for 1.
Big reviewer patch coming up...
Description changed:
---
+++
@@ -24,4 +24,4 @@
10000 loops, best of 3: 730 ns per loop
-We also modify is_prime_power()
to return False
for 1.
+We also modify is_prime_power()
to return False
for 1 or non-integral rationals like 1/2
.
Description changed:
---
+++
@@ -24,4 +24,4 @@
10000 loops, best of 3: 730 ns per loop
-We also modify is_prime_power()
to return False
for 1 or non-integral rationals like 1/2
.
+We also modify is_prime_power()
to return False
for 1 and raise an error for non-integral rationals like 1/2
.
Changed branch from u/vdelecroix/16878 to u/jdemeyer/ticket/16878
Changed author from Vincent Delecroix to Vincent Delecroix, Jeroen Demeyer
As you can see, I made quite a lot of additional changes, mostly trying to make the code cleaner. I am currently running doctests.
Can you review this extra commit?
New commits:
7f61321 | Reorganize is_prime_power() and next_prime() logic |
Branch pushed to git repo; I updated commit sha1. New commits:
5937af5 | Sloane considers 1 to be a prime power |
Great! I especially like that now isprimepower
is accessible.
In my last commit, I added the keyword certificate
to is_prime_power
in order to get back the pair (n,p) such that the integer is pn (following pari convention). I think it is worth it!
Vincent
New commits:
f0d716f | trac #16878: certificate flag in is_prime_power |
Changed branch from u/jdemeyer/ticket/16878 to u/vdelecroix/16878
Note the treatment of 1 is different inis_prime_powers
and prime_powers
... either we fix it in that ticket or it can wait #16880.
Vincent
Replying to @videlec:
Great! I especially like that now
isprimepower
is accessible.In my last commit, I added the keyword
certificate
tois_prime_power
in order to get back the pair (n,p) such that the integer is pn (following pari convention). I think it is worth it!
I like the idea, but I'm not sure that I like the interface with the certificate
keyword.
How about a separate method write_as_prime_power()
(raising ArithmeticError
if it's not a prime power) or something?
Replying to @videlec:
Note the treatment of 1 is different in
is_prime_powers
andprime_powers
... either we fix it in that ticket or it can wait #16880.
Let's ignore that for now and try to merge this ticket first.
Replying to @jdemeyer:
Replying to @videlec:
Great! I especially like that now
isprimepower
is accessible.In my last commit, I added the keyword
certificate
tois_prime_power
in order to get back the pair (n,p) such that the integer is pn (following pari convention). I think it is worth it!I like the idea, but I'm not sure that I like the interface with the
certificate
keyword.How about a separate method
write_as_prime_power()
(raisingArithmeticError
if it's not a prime power) or something?
Note that there is already factor
that does the job. Moreover, having two methods (is_prime_power
and write_as_prime_power
) with the exact same code looks bad as well. From my implementation, it is clear that the certificate
keyword only modifies the output.
My design choice also comes from the fact that this certifcate
keyword is already in use (see sage.graphs
or sage.combinat.designs
). I am not particularly happy with it but I find it better than having two functions.
On the other hand, treating a Python exception takes time, and this is_prime_power
is the kind of function that I might use in time critical code.
Vincent
Changed branch from u/vdelecroix/16878 to u/jdemeyer/ticket/16878
I am happy with the current version (at commit bfd69d3). Do you agree to set to positive review?
Vincent
Changed reviewer from Jeroen Demeyer to Jeroen Demeyer, Vincent Delecroix
Changed branch from u/jdemeyer/ticket/16878 to bfd69d3
This takes about a second before this ticket and really long after this ticket:
sage: with proof.WithProof('arithmetic', False):
....: sage.rings.arith.is_prime_power((10^1000 + 453)^2)
In fact, it get so slow that the ARM buildbot times out in
sage -t --long src/sage/rings/finite_rings/constructor.py
Timed out
**********************************************************************
...
sage: k = FiniteField(10^1000 + 453, proof=False) ## line 230 ##
sage: k = FiniteField((10^1000 + 453)^2, 'a', proof=False) # long time -- about 5 seconds ## line 231 ##
**********************************************************************
very strange indeed
sage: sage.rings.arith.is_prime_power((10^999 + 453)^2) # very fast
False
sage: sage.rings.arith.is_prime_power((10^1001 + 453)^2) # very fast
False
sage: sage.rings.arith.is_prime_power((10^1000 + 453)^2)
... <still waiting> ...
I see... seems to be because we do not care about the flag proof=True
or proof=False
anymore in is_prime_power
. We should still rely on is_pseudoprime_small_power
when proof=False
.
And by the way, in is_pseudoprime_small_power
the choice of the keyword to return (n,p)
is get_data
. I guess we should change the certificate
in is_prime_power
to get_data
as well.
Vincent
Changed branch from bfd69d3
to u/vdelecroix/16878
Right now to test if a Sage integer is prime it is faster to call
prime_range
rather than.is_prime()
...versus
The patch does some tiny modifications in
integer.pyx
and we getWe also modify
is_prime_power()
to returnFalse
for 1 and raise an error for non-integral rationals like1/2
.See also this sage-devel discussion.
Depends on #16997
CC: @nathanncohen
Component: number theory
Author: Vincent Delecroix, Jeroen Demeyer
Branch:
1f8abd9
Reviewer: Jeroen Demeyer, Vincent Delecroix
Issue created by migration from https://trac.sagemath.org/ticket/16878