Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
sage.rings.bern*: rst fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mezzarobba committed Apr 25, 2015
1 parent f7c0fa2 commit 9ed1b17
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
22 changes: 15 additions & 7 deletions src/sage/rings/bernmm.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ r"""
Cython wrapper for bernmm library
AUTHOR:
- David Harvey (2008-06): initial version
"""

Expand Down Expand Up @@ -34,14 +35,17 @@ def bernmm_bern_rat(long k, int num_threads = 1):
(Wrapper for bernmm library.)
INPUT:
k -- non-negative integer
num_threads -- integer >= 1, number of threads to use
- k -- non-negative integer
- num_threads -- integer >= 1, number of threads to use
COMPLEXITY:
Pretty much quadratic in $k$. See the paper ``A multimodular algorithm
for computing Bernoulli numbers'', David Harvey, 2008, for more details.
EXAMPLES:
Pretty much quadratic in $k$. See the paper "A multimodular algorithm
for computing Bernoulli numbers", David Harvey, 2008, for more details.
EXAMPLES::
sage: from sage.rings.bernmm import bernmm_bern_rat
sage: bernmm_bern_rat(0)
Expand All @@ -57,7 +61,8 @@ def bernmm_bern_rat(long k, int num_threads = 1):
sage: bernmm_bern_rat(100, 3)
-94598037819122125295227433069493721872702841533066936133385696204311395415197247711/33330
TESTS:
TESTS::
sage: lst1 = [ bernoulli(2*k, algorithm='bernmm', num_threads=2) for k in [2932, 2957, 3443, 3962, 3973] ]
sage: lst2 = [ bernoulli(2*k, algorithm='pari') for k in [2932, 2957, 3443, 3962, 3973] ]
sage: lst1 == lst2
Expand Down Expand Up @@ -87,13 +92,16 @@ def bernmm_bern_modp(long p, long k):
If $B_k$ is not $p$-integral, returns -1.
INPUT:
p -- a prime
k -- non-negative integer
COMPLEXITY:
Pretty much linear in $p$.
EXAMPLES:
EXAMPLES::
sage: from sage.rings.bernmm import bernmm_bern_modp
sage: bernoulli(0) % 5, bernmm_bern_modp(5, 0)
Expand Down
36 changes: 26 additions & 10 deletions src/sage/rings/bernoulli_mod_p.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ r"""
Bernoulli numbers modulo p
AUTHOR:
- David Harvey (2006-07-26): initial version
- William Stein (2006-07-28): some touch up.
- David Harvey (2006-08-06): new, faster algorithm, also using faster NTL interface
- David Harvey (2007-08-31): algorithm for a single Bernoulli number mod p
- David Harvey (2008-06): added interface to bernmm, removed old code
- David Harvey (2006-07-26): initial version
- William Stein (2006-07-28): some touch up.
- David Harvey (2006-08-06): new, faster algorithm, also using faster NTL interface
- David Harvey (2007-08-31): algorithm for a single Bernoulli number mod p
- David Harvey (2008-06): added interface to bernmm, removed old code
"""

#*****************************************************************************
Expand Down Expand Up @@ -46,12 +47,15 @@ def verify_bernoulli_mod_p(data):
(see "Irregular Primes to One Million", Buhler et al)
INPUT:
data -- list, same format as output of bernoulli_mod_p function
OUTPUT:
bool -- True if checksum passed
EXAMPLES:
EXAMPLES::
sage: from sage.rings.bernoulli_mod_p import verify_bernoulli_mod_p
sage: verify_bernoulli_mod_p(bernoulli_mod_p(next_prime(3)))
True
Expand All @@ -62,7 +66,8 @@ def verify_bernoulli_mod_p(data):
sage: verify_bernoulli_mod_p([1, 2, 3, 4, 5])
False
This one should test that long longs are working:
This one should test that long longs are working::
sage: verify_bernoulli_mod_p(bernoulli_mod_p(next_prime(20000)))
True
Expand Down Expand Up @@ -91,19 +96,24 @@ def bernoulli_mod_p(int p):
Returns the bernoulli numbers `B_0, B_2, ... B_{p-3}` modulo `p`.
INPUT:
p -- integer, a prime
OUTPUT:
list -- Bernoulli numbers modulo `p` as a list
of integers [B(0), B(2), ... B(p-3)].
ALGORITHM:
Described in accompanying latex file.
PERFORMANCE:
Should be complexity `O(p \log p)`.
EXAMPLES:
Check the results against PARI's C-library implementation (that
computes exact rationals) for `p = 37`::
Expand All @@ -112,11 +122,13 @@ def bernoulli_mod_p(int p):
sage: [bernoulli(n) % 37 for n in xrange(0, 36, 2)]
[1, 31, 16, 15, 16, 4, 17, 32, 22, 31, 15, 15, 17, 12, 29, 2, 0, 2]
Boundary case:
Boundary case::
sage: bernoulli_mod_p(3)
[1]
AUTHOR:
-- David Harvey (2006-08-06)
"""
Expand Down Expand Up @@ -219,13 +231,16 @@ def bernoulli_mod_p_single(long p, long k):
If `B_k` is not `p`-integral, an ArithmeticError is raised.
INPUT:
p -- integer, a prime
k -- non-negative integer
OUTPUT:
The `k`-th bernoulli number mod `p`.
EXAMPLES:
EXAMPLES::
sage: bernoulli_mod_p_single(1009, 48)
628
sage: bernoulli(48) % 1009
Expand Down Expand Up @@ -254,7 +269,7 @@ def bernoulli_mod_p_single(long p, long k):
...
ValueError: k must be non-negative
Check results against bernoulli_mod_p:
Check results against bernoulli_mod_p::
sage: bernoulli_mod_p(37)
[1, 31, 16, 15, 16, 4, 17, 32, 22, 31, 15, 15, 17, 12, 29, 2, 0, 2]
Expand Down Expand Up @@ -282,6 +297,7 @@ def bernoulli_mod_p_single(long p, long k):
[1, 6, 3]
AUTHOR:
-- David Harvey (2007-08-31)
-- David Harvey (2008-06): rewrote to use bernmm library
Expand Down

0 comments on commit 9ed1b17

Please sign in to comment.