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__variablesq]q(Unumber_grid-functionqUsieve_step-functionqeU_Worksheet__dirqUsage_notebook/worksheets/sieveqU_Worksheet__queueq]qU_Worksheet__next_idqM`U_Worksheet__notebookqhU_Worksheet__sageqh+U_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
"""qh#U*sage_notebook/worksheets/features/cells/28qh%U
qh'h(Kh)hhAhBh,ub(hoq}q(hUtclass Tensor:
def __repr__(self):
return "I'm a tensor"
def __mul__(self, right):
return "abc"qhU!qhhh։hhU hM"PhډhUos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/features/cells/34")
class Tensor:
def __repr__(self):
return "I'm a tensor"
def __mul__(self, right):
return "abc"qhU*sage_notebook/worksheets/features/cells/34qhU
qhhhhKhhBhhub(hoq}q(hUt = Tensor()qhU!qhhh։hhU hM!PhډhUhos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/features/cells/33")
t = Tensor()r hU*sage_notebook/worksheets/features/cells/33r hU
r hhhhKhhBhhub(hor }r (hU hhh։hU hM PhU*sage_notebook/worksheets/features/cells/32r hU hhK hhBhub(hor }r (hUfoo()r hU!r hhh։hhU hMPhډhUaos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/features/cells/29")
foo()r
hU*sage_notebook/worksheets/features/cells/29r hUQ
2 + 2
2
23
r hhhhKhhBhhub(hor
}r (hU hhh։hU hMPhU*sage_notebook/worksheets/features/cells/30r hU hhK hhBhubehK$hh}r U/Users/was/.sage/init.sager GAje sh]r (UTensor-classobjr U9a-sage.rings.polynomial_element.Polynomial_rational_denser Ufoo-functionr U
t-instancer ehU!sage_notebook/worksheets/featuresr h]r hM#PhhhhhhUfeaturesr 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/ hU_Cell__out_htmlr0 U U _Cell__idr1 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)r2 U
_Cell__dirr3 U+sage_notebook/worksheets/bernoulli/cells/18r4 U
_Cell__outr5 U'
CPU time: 0.34 s, Wall time: 0.36 s
r6 Uhas_new_outputr7 U_Cell__versionr8 KU_Cell__sager9 h*)Rr: U_Cell__typer; hBU_Cell__interruptedr< ub(hor= }r> (j+ Ulen(str(a))r? hU!r@ j. j j/ hj0 U j1 MphhډhUhos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/bernoulli/cells/19")
len(str(a))rA j3 U+sage_notebook/worksheets/bernoulli/cells/19rB j5 U
27706
rC j7 j8 Kj9 j: j; hBj< ub(horD }rE (j+ U*time v = bernoulli_mod_p(next_prime(10^4))rF hU!rG j. j j/ hj0 U j1 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))rH j3 U+sage_notebook/worksheets/bernoulli/cells/20rI j5 U'
CPU time: 0.06 s, Wall time: 0.06 s
rJ j7 j8 Kj9 j: j; hBj< ub(horK }rL (j+ U,time v = bernoulli_mod_p(next_prime(2*10^5))rM hU!rN j. j j/ hj0 U j1 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))rO j3 U+sage_notebook/worksheets/bernoulli/cells/21rP j5 U'
CPU time: 1.57 s, Wall time: 1.58 s
rQ j7 j8 Kj9 j: j; hBj< ub(horR }rS (j+ Uv[:10]rT hU!rU j. j j/ hj0 U j1 MphhډhUcos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/bernoulli/cells/22")
v[:10]rV j3 U+sage_notebook/worksheets/bernoulli/cells/22rW j5 U<
[1, 1668, 7672, 4527, 7672, 8036, 3603, 1669, 5899, 6162]
rX j7 j8 Kj9 j: j; hBj< ub(horY }rZ (j+ U!bernoulli(2) % next_prime(2*10^5)r[ j. j j/ j0 U j1 Mpj3 U+sage_notebook/worksheets/bernoulli/cells/23r\ j5 U33334r] j7 j8 Kj9 Nj; hOj< ub(hor^ }r_ (j+ U j. j j/ j0 U j1 Mpj3 U+sage_notebook/worksheets/bernoulli/cells/24r` j5 U j7 j8 Kj9 Nj; hOj< ubeU_Worksheet__synchrora KU_Worksheet__namerb U bernoullirc U_Worksheet__attachedrd }re U/Users/was/.sage/init.sagerf GAje sU_Worksheet__saltrg U1168977577.570778rh h]ri (Ua-sage.rings.rational.Rationalrj Uv-listrk eU_Worksheet__dirrl U"sage_notebook/worksheets/bernoullirm U_Worksheet__queuern ]ro U_Worksheet__next_idrp Mphj: U_Worksheet__passcryptrq U_Worksheet__comp_is_runningrr U_Worksheet__passcoders U
11G3BJNEUV/Pkrt U_Worksheet__notebookru hU_Worksheet__idrv KU_Worksheet__next_block_idrw KU_Worksheet__systemrx NubUriemannry (horz }r{ (h
Uriemannr| h]r} ((hor~ }r (hjz 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 hM@ub(hor }r (hUG#auto
def f(x):
return x / log(x)
def p(x):
return prime_pi(x)r hU!r hjz hh;hU hM@h=h h!Uos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/riemann/cells/2")
#auto
def f(x):
return x / log(x)
def p(x):
return prime_pi(x)r h#U(sage_notebook/worksheets/riemann/cells/2r h%U
r h'h(Kh)h*)Rr hAhBh,ub(hor }r (hjz hUNow we plot them:
r h'h(Kh)jb hAhBh,ub(hor }r (hU:m = matrix(5,5,[randint(0,1) for _ in range(25)]); show(m)r hU!r hjR hh;hU hMah=h h!Uos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/talk/cells/97")
m = matrix(5,5,[randint(0,1) for _ in range(25)]); show(m)r h#U&sage_notebook/worksheets/talk/cells/97r h%U
r hM0ub(hor }r (hUSdef is2pow(n):
while n != 0 and n%2 == 0:
n = n >> 1
return n == 1r hU!r hj hhhU 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 hhhU 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 hhhUf_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