Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168772
Image: ubuntu2004

Twin Primes

def twin_primes_upto(n): v = prime_range(n+1) return len([i for i in range(len(v)-1) if v[i+1]-v[i]==2])
twin_primes_upto(10)
\newcommand{\Bold}[1]{\mathbf{#1}}2
for n in [1..7]: print n, twin_primes_upto(10^n)
1 2 2 8 3 35 4 205 5 1224 6 8169 7 58980

Goldbach's Conjecture

def goldbach(n): if n%2 or n <= 2: raise ValueError, "n must be even and > 2" for p in primes(n): if is_prime(n - p): return p, n - p raise RuntimeError, "bug in sage or Golbach's conjecture is false for n=%s"%n
goldbach(2010)
\newcommand{\Bold}[1]{\mathbf{#1}}\left(7, 2003\right)
goldbach(2012)
\newcommand{\Bold}[1]{\mathbf{#1}}\left(13, 1999\right)

Mersenne Primes

for p in primes(30): print p, is_prime(2^p-1), 2^p-1
2 True 3 3 True 7 5 True 31 7 True 127 11 False 2047 13 True 8191 17 True 131071 19 True 524287 23 False 8388607 29 False 536870911
factor(2047)
\newcommand{\Bold}[1]{\mathbf{#1}}23 \cdot 89

Prime Gaps

def Gap(n,k): v = prime_range(n+1) return len([i for i in range(len(v)-1) if v[i+1]-v[i] == k])
for n in [10,10^2,10^4,10^6]: print n, Gap(n,2), Gap(n,4), Gap(n,6), Gap(n,8)
10 2 0 0 0 100 8 7 7 1 10000 205 202 299 101 1000000 8169 8143 13549 5569
prod([2,3,5,7,11])
2310

Formulation of the Riemann Hypothesis

for x in [10,10^2,10^3,10^4,10^5,10^6]: print x, prime_pi(x)
10 4 100 25 1000 168 10000 1229 100000 9592 1000000 78498
for x in [10,10^3,10^6,10^9, 10^10, 10^11]: print x, float(prime_pi(x)/(x/(log(x)-1)))
10 0.521034037198 1000 0.992502886869 1000000 1.00599194778 1000000000 1.00287943024 10000000000 1.00229187726 100000000000 1.00185833057
prime_pi(10^11)
4118054813
float(10^11 / (log(10^11)-1))
4110416300.7325931
x=10^11; float(prime_pi(x) - x/(log(x)-1))
7638512.2674069405
x=10^11; float(sqrt(x) * log(x))
8009554.7402329827