qU
_TextCell__idqMp`ub(csage.server.notebook.cell
Cell
qoq}q(U _Cell__inqT %hideall
#auto
def number_grid(c, box_args={}, font_args={},offset=0):
"""
INPUT:
c -- list of length n^2, where n is an integer.
The entries of c are RGB colors.
box_args -- additional arguments passed to box.
font_args -- all additional arguments are passed
to the text function, e.g., fontsize.
offset -- use to fine tune text placement in the squares
OUTPUT:
Graphics -- a plot of a grid that illustrates
those n^2 numbers colored according to c.
"""
try:
n = square_root(ZZ(len(c)))
except ArithmeticError:
raise ArithmeticError, "c must have square length"
G = Graphics()
k = 0
for j in reversed(range(n)):
for i in range(n):
col = c[int(k)]
R = line([(i,j),(i+1,j),(i+1,j+1),(i,j+1),(i,j)], thickness=.2, **box_args)
P = polygon([(i,j),(i+1,j),(i+1,j+1),(i,j+1),(i,j)], rgbcolor=col, **box_args)
G += P + R
if col != (1,1,1):
G += text(str(k+1), (i+.5+offset,j+.5), **font_args)
k += 1
G.axes(False)
G.range(0,n,0,n)
return GqU_Cell__introspect_htmlqU!qU_Cell__worksheetqhU_Cell__completionsqU_Cell__out_htmlqU U _Cell__idqMq`U_Cell__is_htmlq U_before_preparseq!TJ os.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/sieve/cells/113")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
%hideall
#auto
def number_grid(c, box_args={}, font_args={},offset=0):
"""
INPUT:
c -- list of length n^2, where n is an integer.
The entries of c are RGB colors.
box_args -- additional arguments passed to box.
font_args -- all additional arguments are passed
to the text function, e.g., fontsize.
offset -- use to fine tune text placement in the squares
OUTPUT:
Graphics -- a plot of a grid that illustrates
those n^2 numbers colored according to c.
"""
try:
n = square_root(ZZ(len(c)))
except ArithmeticError:
raise ArithmeticError, "c must have square length"
G = Graphics()
k = 0
for j in reversed(range(n)):
for i in range(n):
col = c[int(k)]
R = line([(i,j),(i+1,j),(i+1,j+1),(i,j+1),(i,j)], thickness=.2, **box_args)
P = polygon([(i,j),(i+1,j),(i+1,j+1),(i,j+1),(i,j)], rgbcolor=col, **box_args)
G += P + R
if col != (1,1,1):
G += text(str(k+1), (i+.5+offset,j+.5), **font_args)
k += 1
G.axes(False)
G.range(0,n,0,n)
return Gq"U
_Cell__dirq#U(sage_notebook/worksheets/sieve/cells/113q$U
_Cell__outq%U'
CPU time: 0.00 s, Wall time: 0.00 s
q&Uhas_new_outputq'U_Cell__versionq(KU_Cell__sageq)csage.interfaces.sage0
reduce_load_Sage
q*)Rq+U_Cell__interruptedq,ub(hoq-}q.(hT %hideall
#auto
def sieve_step(p, n, gone=(1,1,1), prime=(1,0,0), \
multiple=(.6,.6,.6), remaining=(.9,.9,.9),
fontsize=11,offset=0):
"""
Return graphics that illustrates sieving out
multiples of p. Numbers that are a nontrivial
multiple of primes < p are shown in the gone color.
Numbers that are a multiple of p are shown in
a different color. The number p is shown in
yet a third color.
INPUT:
p -- a prime (or 1, in which case all points are colored "remaining")
n -- a SQUARE integer
gone -- rgb color for integers that have been sieved out
prime -- rgb color for p
multiple -- rgb color for multiples of p
remaining -- rgb color for integers that have not been sieved out yet
and are not multiples of p.
"""
if p == 1:
c = [remaining]*n
else:
exclude = prod(prime_range(p)) # exclude multiples of primes < p
c = []
for k in range(1,n+1):
if k <= p and is_prime(k):
c.append(prime)
elif k == 1 or (gcd(k,exclude) != 1 and not is_prime(k)):
c.append(gone)
elif k%p == 0:
c.append(multiple)
else:
c.append(remaining)
# end for
# end if
return number_grid(c,{},{'fontsize':fontsize},offset=offset)q/hU!q0hhhhU hMr`h h!T2 os.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/sieve/cells/114")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
%hideall
#auto
def sieve_step(p, n, gone=(1,1,1), prime=(1,0,0), \
multiple=(.6,.6,.6), remaining=(.9,.9,.9),
fontsize=11,offset=0):
"""
Return graphics that illustrates sieving out
multiples of p. Numbers that are a nontrivial
multiple of primes < p are shown in the gone color.
Numbers that are a multiple of p are shown in
a different color. The number p is shown in
yet a third color.
INPUT:
p -- a prime (or 1, in which case all points are colored "remaining")
n -- a SQUARE integer
gone -- rgb color for integers that have been sieved out
prime -- rgb color for p
multiple -- rgb color for multiples of p
remaining -- rgb color for integers that have not been sieved out yet
and are not multiples of p.
"""
if p == 1:
c = [remaining]*n
else:
exclude = prod(prime_range(p)) # exclude multiples of primes < p
c = []
for k in range(1,n+1):
if k <= p and is_prime(k):
c.append(prime)
elif k == 1 or (gcd(k,exclude) != 1 and not is_prime(k)):
c.append(gone)
elif k%p == 0:
c.append(multiple)
else:
c.append(remaining)
# end for
# end if
return number_grid(c,{},{'fontsize':fontsize},offset=offset)q1h#U(sage_notebook/worksheets/sieve/cells/114q2h%U'
CPU time: 0.00 s, Wall time: 0.00 s
q3h'h(Kh)h+h,ub(hoq4}q5(hhhUV
The integers up to 100
Each square contains one of the integers up to 100.q6hMs`ub(hoq7}q8(hUshow(sieve_step(1,100))q9hU!q:hhhU_Cell__introspectq;hU@qh#U(sage_notebook/worksheets/sieve/cells/116q?h%U
q@h'h(Kh)h+U_Cell__typeqAUwrapqBh,ub(hoqC}qD(hhhUc
We sieve out the even integers
We remove each integer (besides 2) that is divisible by 2.qEhMu`ub(hoqF}qG(hUshow(sieve_step(2,100))qHhU!qIhhhh;hU@qJhMv`h=h h!Uqos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/sieve/cells/118")
show(sieve_step(2,100))qKh#U(sage_notebook/worksheets/sieve/cells/118qLh%U
qMh'h(Kh)h*)RqNhAUwrapqOh,ub(hoqP}qQ(hhhU.
q~hM`ub(hoq}q(hUXs = [sieve_step(p,100) for p in [2,3,5,7]]
G = graphics_array(s, 2,2)
G.show(axes=False)qhU!qhhhh;hU@qhM`h=h h!Uos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/sieve/cells/128")
s = [sieve_step(p,100) for p in [2,3,5,7]]
G = graphics_array(s, 2,2)
G.show(axes=False)qh#U(sage_notebook/worksheets/sieve/cells/128qh%U
qh'h(Kh)hNhAhOh,ub(hoq}q(hU#show(sieve_step(13,400,fontsize=6))qhU!qhhhh;hU@qhM`h=h h!U}os.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/sieve/cells/135")
show(sieve_step(13,400,fontsize=6))qh#U(sage_notebook/worksheets/sieve/cells/135qh%U
qh'h(Kh)hNhAUwrapqh,ub(hoq}q(hU hhhhU hM`h#U(sage_notebook/worksheets/sieve/cells/141qh%U h'h(Kh)NhAhh,ubeU_Worksheet__synchroqK5U_Worksheet__comp_is_runningqU_Worksheet__attachedq}qU/Users/was/.sage/init.sageqGAje sU_Worksheet__dirqUsage_notebook/worksheets/sieveqU_Worksheet__queueq]qU_Worksheet__next_idqM`U_Worksheet__notebookqhU_Worksheet__passcryptqU_Worksheet__nameqUsieveqU_Worksheet__saltqU1168947677.540541qU_Worksheet__passcodeqU
11G3BJNEUV/PkqU_Worksheet__idqKU_Worksheet__next_block_idqKU_Worksheet__systemqNubUfeaturesq(hoq}q(h
Ufeaturesqh]q((hoq}q(hhhT
Some Notebook Features
Images.
Multiple input cells can be queued up for computation, and cancelled at any time.
Persistent:
Close browser and come back later to see what is happening
Everything saved every few seconds
List of currently defined variables.
Save/load individual objects
qhMPub(hoq}q(hU>show(plot(sin(x),-pi,6*pi,rgbcolor=(0.5,0,0.5)),figsize=[8,3])qhU!qhhhh;hUBqhMPh=h h!Uos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/features/cells/24")
show(plot(sin(x),-pi,6*pi,rgbcolor=(0.5,0,0.5)),figsize=[8,3])qh#U*sage_notebook/worksheets/features/cells/24qh%U
qh'h(Kh)h*)RqhAhBh,ub(hoq}q(hT> %hide
t = Tachyon(xres=700, yres=500, camera_center=(2,7,4), look_at=(2,0,0), raydepth=4)
t.light((10,3,2), 1, (1,1,1))
t.light((10,-3,2), 1, (1,1,1))
t.texture('black', color=(0,0,0))
t.texture('red', color=(1,0,0))
t.texture('grey', color=(.9,.9,.9))
t.plane((0,0,0),(0,0,1),'grey')
t.cylinder((0,0,0),(1,0,0),.01,'black')
t.cylinder((0,0,0),(0,1,0),.01,'black')
E = EllipticCurve('37a'); show(E)
P = E([0,0])
Q = P
n = 60
for i in range(n):
Q = Q + P
c = i/n + .1
t.texture('r%s'%i,color=(float(i/n),0,0))
t.sphere((Q[0], -Q[1], .01), .04, 'r%s'%i)
show(t)qhU!qhhhh;hUBqhMPh=h h!T os.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/features/cells/25")
%hide
t = Tachyon(xres=700, yres=500, camera_center=(2,7,4), look_at=(2,0,0), raydepth=4)
t.light((10,3,2), 1, (1,1,1))
t.light((10,-3,2), 1, (1,1,1))
t.texture('black', color=(0,0,0))
t.texture('red', color=(1,0,0))
t.texture('grey', color=(.9,.9,.9))
t.plane((0,0,0),(0,0,1),'grey')
t.cylinder((0,0,0),(1,0,0),.01,'black')
t.cylinder((0,0,0),(0,1,0),.01,'black')
E = EllipticCurve('37a'); show(E)
P = E([0,0])
Q = P
n = 60
for i in range(n):
Q = Q + P
c = i/n + .1
t.texture('r%s'%i,color=(float(i/n),0,0))
t.sphere((Q[0], -Q[1], .01), .04, 'r%s'%i)
show(t)qh#U*sage_notebook/worksheets/features/cells/25qU_word_being_completedqUTachyonqh'h(Kh)hNh,hAhh%U:
y^2 + y = x^3 - x
qub(hoq}q(hUa = (x-10)^5; show(a)qhU!qhhhh;hU hMPh=h h!Uqos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/features/cells/26")
a = (x-10)^5; show(a)qh#U*sage_notebook/worksheets/features/cells/26qh%Uc
r h܉hhhKhhBhhub(hor }r (hU hhhщhU hMPhU*sage_notebook/worksheets/features/cells/30r
hU h܉hK hhBhubehK$hh}r U/Users/was/.sage/init.sager GAje shU!sage_notebook/worksheets/featuresr
h]r hM#PhhhhUfeaturesr hU1168945214.888470r hU
11G3BJNEUV/Pkr hKhKhNubU bernoullir (hor }r (U_Worksheet__filenamer U bernoullir U_Worksheet__cellsr ]r ((hor }r (U_TextCell__worksheetr j U_TextCell__textr Uv
Bernoulli Numbers
$$ \frac{x}{e^x - 1} = \sum_{n=0}^{\infty} B_n \frac{x^n}{n!}$$
r U
_TextCell__idr Mpub(hor }r (U _Cell__inr! Utime a = bernoulli(10^4)r" hU!r# U_Cell__worksheetr$ j U_Cell__completionsr% h҉U_Cell__out_htmlr& U U _Cell__idr' MphhՉhUos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/bernoulli/cells/18")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
a = bernoulli(10^4)r( U
_Cell__dirr) U+sage_notebook/worksheets/bernoulli/cells/18r* U
_Cell__outr+ U'
CPU time: 0.34 s, Wall time: 0.36 s
r, Uhas_new_outputr- U_Cell__versionr. KU_Cell__sager/ h*)Rr0 U_Cell__typer1 hBU_Cell__interruptedr2 ub(hor3 }r4 (j! Ulen(str(a))r5 hU!r6 j$ j j% h҉j& U j' MphhՉhUhos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/bernoulli/cells/19")
len(str(a))r7 j) U+sage_notebook/worksheets/bernoulli/cells/19r8 j+ U
27706
r9 j- j. Kj/ j0 j1 hBj2 ub(hor: }r; (j! U*time v = bernoulli_mod_p(next_prime(10^4))r< hU!r= j$ j j% h҉j& U j' MphhՉhUos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/bernoulli/cells/20")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
v = bernoulli_mod_p(next_prime(10^4))r> j) U+sage_notebook/worksheets/bernoulli/cells/20r? j+ U'
CPU time: 0.06 s, Wall time: 0.06 s
r@ j- j. Kj/ j0 j1 hBj2 ub(horA }rB (j! U,time v = bernoulli_mod_p(next_prime(2*10^5))rC hU!rD j$ j j% h҉j& U j' MphhՉhUos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/bernoulli/cells/21")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
v = bernoulli_mod_p(next_prime(2*10^5))rE j) U+sage_notebook/worksheets/bernoulli/cells/21rF j+ U'
CPU time: 1.57 s, Wall time: 1.58 s
rG j- j. Kj/ j0 j1 hBj2 ub(horH }rI (j! Uv[:10]rJ hU!rK j$ j j% h҉j& U j' MphhՉhUcos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/bernoulli/cells/22")
v[:10]rL j) U+sage_notebook/worksheets/bernoulli/cells/22rM j+ U<
[1, 1668, 7672, 4527, 7672, 8036, 3603, 1669, 5899, 6162]
rN j- j. Kj/ j0 j1 hBj2 ub(horO }rP (j! U!bernoulli(2) % next_prime(2*10^5)rQ j$ j j% j& U j' Mpj) U+sage_notebook/worksheets/bernoulli/cells/23rR j+ U33334rS j- j. Kj/ Nj1 hOj2 ub(horT }rU (j! U j$ j j% j& U j' Mpj) U+sage_notebook/worksheets/bernoulli/cells/24rV j+ U j- j. Kj/ Nj1 hOj2 ubeU_Worksheet__synchrorW KU_Worksheet__namerX U bernoullirY U_Worksheet__attachedrZ }r[ U/Users/was/.sage/init.sager\ GAje sU_Worksheet__saltr] U1168977577.570778r^ U_Worksheet__dirr_ U"sage_notebook/worksheets/bernoullir` U_Worksheet__queuera ]rb U_Worksheet__next_idrc MpU_Worksheet__passcryptrd U_Worksheet__comp_is_runningre U_Worksheet__passcoderf U
11G3BJNEUV/Pkrg U_Worksheet__notebookrh hU_Worksheet__idri KU_Worksheet__next_block_idrj KU_Worksheet__systemrk NubUriemannrl (horm }rn (h
Uriemannro h]rp ((horq }rr (hjm hT
What is Riemann's Hypothesis?
The Riemann Hypothesis approximates $\pi(X)$, the number of primes $ Riemann Hypothesis:
We have $ |\pi(x) - \mbox{Li}(x)| < \sqrt{x}\cdot \log(x) $
Here is a graph of the three functions $X/\log X$, ${\rm Li}(X)$, and $\pi(X)$ for $X<1000$:
We first define two SAGE functions (Li is built into SAGE):
def f(x):
return x / log(x)
def p(x):
return prime_pi(x)
r hM0ub(hor }r (hUSdef is2pow(n):
while n != 0 and n%2 == 0:
n = n >> 1
return n == 1r hU!r hj hh҉hU hM0hhՉhUos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/sagex/cells/6")
def is2pow(n):
while n != 0 and n%2 == 0:
n = n >> 1
return n == 1r h#U&sage_notebook/worksheets/sagex/cells/6r h%U
r h'h(Kh)h*)Rr hAhBh,ub(hor }r (hU1time v = [n for n in range(10^5) if is2pow(n)]; vr hU!r hj hh҉hU hM0hhՉhUos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/sagex/cells/7")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
v = [n for n in range(10^5) if is2pow(n)]; vr h#U&sage_notebook/worksheets/sagex/cells/7r h%U|
[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536]
CPU time: 3.29 s, Wall time: 3.31 s
r h'h(Kh)j hAhBh,ub(hor }r (hUp%sagex
def is2pow_compiled(unsigned int n):
while n != 0 and n%2 == 0:
n = n >> 1
return n == 1r hU!r hj hh҉hUf_sage5.cr hM0hhՉhUos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/sagex/cells/8")
%sagex
def is2pow_compiled(unsigned int n):
while n != 0 and n%2 == 0:
n = n >> 1
return n == 1r h#U&sage_notebook/worksheets/sagex/cells/8r h%U
r h'h(Kh)j hAhBh,ub(hor }r (hU