15.04.2014 Views

Efficient implementation of the Hardy-Ramanujan ... - William Stein

Efficient implementation of the Hardy-Ramanujan ... - William Stein

Efficient implementation of the Hardy-Ramanujan ... - William Stein

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Page 4 <strong>of</strong> 19<br />

FREDRIK JOHANSSON<br />

Algorithm 1 Simple algorithm for evaluating A k (n)<br />

Input: Integers k,n ≥ 0<br />

Output: s = A k (n), where A k (n) is defined as in (1.6)<br />

if k ≤ 1 <strong>the</strong>n<br />

return k<br />

else if k = 2 <strong>the</strong>n<br />

return (−1) n<br />

end if<br />

(s,r,m) ← (0,2,(n mod k))<br />

for 0 ≤ l < 2k do<br />

if m = 0 <strong>the</strong>n<br />

s ← s+(−1) l cos(π(6l+1)/(6k))<br />

end if<br />

m ← m+r<br />

if m ≥ k <strong>the</strong>n m ← m−k {m ← m mod k}<br />

r ← r+3<br />

if r ≥ k <strong>the</strong>n r ← r−k {r ← r mod k}<br />

end for<br />

return s<br />

First consider <strong>the</strong> case when k is a power <strong>of</strong> a prime. Clearly A 1 (n) = 1 and A 2 (n) = (−1) n .<br />

O<strong>the</strong>rwise let k = p λ and v = 1−24n. Then, using <strong>the</strong> notation (a|m) for Jacobi symbols to<br />

avoid confusion with fractions, we have<br />

⎧<br />

⎪⎨ (−1) λ (−1|m 2 )k 1/2 sin(4πm 2 /8k) if p = 2<br />

A k (n) = 2(−1)<br />

⎪⎩<br />

λ+1 (m 3 |3)(k/3) 1/2 sin(4πm 3 /3k) if p = 3 (2.2)<br />

2(3|k)k 1/2 cos(4πm p /k) if p > 3<br />

where m 2 , m 3 and m p respectively are any solutions <strong>of</strong><br />

(3m 2 ) 2 ≡ v mod 8k (2.3)<br />

(8m 3 ) 2 ≡ v mod 3k (2.4)<br />

(24m p ) 2 ≡ v mod k (2.5)<br />

provided, when p > 3, that such an m p exists and that gcd(v,k) = 1. If, on <strong>the</strong> o<strong>the</strong>r hand,<br />

p > 3 and ei<strong>the</strong>r <strong>of</strong> <strong>the</strong>se two conditions do not hold, we have<br />

⎧<br />

⎪⎨ 0 if v is not a quadratic residue modulo k<br />

A k (n) = (3|k)k<br />

⎪⎩<br />

1/2 if v ≡ 0 mod p,λ = 0<br />

(2.6)<br />

0 if v ≡ 0 mod p,λ > 1.<br />

If k is not a prime power, assume that k = k 1 k 2 where gcd(k 1 ,k 2 ) = 1. Then we can factor<br />

A k (n) as A k (n) = A k1 (n 1 )A k2 (n 2 ), where n 1 ,n 2 are any solutions <strong>of</strong> <strong>the</strong> following equations.<br />

If k 1 = 2, <strong>the</strong>n<br />

{<br />

32n 2 ≡ 8n+1 mod k 2<br />

n 1 ≡ n−(k2 2 −1)/8 mod 2, (2.7)<br />

if k 1 = 4, <strong>the</strong>n<br />

{<br />

128n 2 ≡ 8n+5 mod k 2<br />

k 2 2 n 1 ≡ n−2−(k 2 2 −1)/8 mod 4, (2.8)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!