csage.server.notebook.notebook Notebook q)q}q(U_Notebook__worksheetsq}q(Usieveq(csage.server.notebook.worksheet Worksheet qoq}q (U_Worksheet__filenameq Usieveq U_Worksheet__cellsq ]q ((csage.server.notebook.cell TextCell qoq}q(U_TextCell__worksheetqhU_TextCell__textqU

Sieve Worksheet

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_htmlqUU	_Cell__idqMq`U_Cell__is_htmlq U_before_preparseq!TJos.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!
q0hhhhUhMr`h h!T2os.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.

We sieve out the multiples of 2 and 3

qRhMw`ub(hoqS}qT(hUshow(sieve_step(3,100))qUhU!
qVhhhh;hU@qWhMx`h=h h!Uqos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/sieve/cells/120")
show(sieve_step(3,100))qXh#U(sage_notebook/worksheets/sieve/cells/120qYh%U

qZh'h(Kh)hNhAhOh,ub(hoq[}q\(hhhU1

We sieve out the multiples of 2, 3 and 5

q]hMy`ub(hoq^}q_(hUshow(sieve_step(5,100))q`hU!
qahhhh;hU@qbhMz`h=h h!Uqos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/sieve/cells/122")
show(sieve_step(5,100))qch#U(sage_notebook/worksheets/sieve/cells/122qdh%U

qeh'h(Kh)hNhAhOh,ub(hoqf}qg(hhhU4

We sieve out the multiples of 2, 3, 5 and 7

qhhM{`ub(hoqi}qj(hUshow(sieve_step(7,100))qkhU!
qlhhhh;hU@qmhM|`h=h h!Uqos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/sieve/cells/124")
show(sieve_step(7,100))qnh#U(sage_notebook/worksheets/sieve/cells/124qoh%U

qph'h(Kh)hNhAhOh,ub(hoqq}qr(hhhU7

There are no multiples of 11 left to sieve out

qshM}`ub(hoqt}qu(hUshow(sieve_step(11,100))qvhU!
qwhhhh;hU@qxhM~`h=h h!Uros.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/sieve/cells/126")
show(sieve_step(11,100))qyh#U(sage_notebook/worksheets/sieve/cells/126qzh%U

q{h'h(Kh)hNhAhOh,ub(hoq|}q}(hhhU

Sieving up to 100

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(hUhhhhUhM`h#U(sage_notebook/worksheets/sieve/cells/141qh%Uh'h(Kh)NhAhh,ubeU_Worksheet__synchroqK5U_Worksheet__comp_is_runningqU_Worksheet__attachedq}qU/Users/was/.sage/init.sageqGAjesU_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

  1. Images.
  2. Multiple input cells can be queued up for computation, and cancelled at any time.
  3. Persistent:
    • Close browser and come back later to see what is happening
    • Everything saved every few seconds
  4. List of currently defined variables.
  5. 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!Tos.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;hUhMPh=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
x^{5} - 50x^{4} + 1000x^{3} - 10000x^{2} + 50000x - 100000
qh'h(Kh)hhAhBh,ub(hoq}q(U _Cell__inqUlatex(a)qU_Cell__introspect_htmlqU!
qU_Cell__worksheetqhU_Cell__completionsq։U_Cell__introspectq׉U_Cell__out_htmlqUU	_Cell__idqMPU_Cell__is_htmlqډU_before_preparseqUdos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/features/cells/31")
latex(a)qU
_Cell__dirqU*sage_notebook/worksheets/features/cells/31qU
_Cell__outqU=
x^{5} - 50x^{4} + 1000x^{3} - 10000x^{2} + 50000x - 100000

qUhas_new_outputqU_Cell__sageqhU_Cell__versionqKU_Cell__typeqhBU_Cell__timeqU_Cell__interruptedqub(hoq}q(hUsave aqhU!
qhhhh;hUhMPh=h h!Ubos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/features/cells/27")
save aqh#U*sage_notebook/worksheets/features/cells/27qh%U

qh'h(Kh)hNhAhh,ub(hoq}q(hUidef foo():
    print """

2 + 2
2 23
"""qhU!
qhhhh׉hUhMPhhډhUos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/features/cells/28")
def foo():
    print """

2 + 2
2 23
"""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։h׉hUhM"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(hUt = Tensor()qhU!
qhhh։h׉hUhM!PhډhUhos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/features/cells/33")
t = Tensor()rhU*sage_notebook/worksheets/features/cells/33rhU

rhhhhKhhBhhub(hor}r(hUhhh։hUhM PhU*sage_notebook/worksheets/features/cells/32rhUhhKhhBhub(hor}r(hUfoo()rhU!
r	hhh։h׉hUhMPhډhUaos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/features/cells/29")
foo()r
hU*sage_notebook/worksheets/features/cells/29rhUQ


2 + 2
2 23
r hhhhKhhBhhub(hor }r(hUhhh։hUhMPhU*sage_notebook/worksheets/features/cells/30rhUhhKhhBhubehK$hh}rU/Users/was/.sage/init.sagerGAjesh]r(UTensor-classobjrU9a-sage.rings.polynomial_element.Polynomial_rational_denserU foo-functionrU t-instancerehU!sage_notebook/worksheets/featuresrh]rhM#PhhhhhhUfeaturesrhU1168945214.888470rhU 11G3BJNEUV/PkrhKhKhNubU bernoullir(hor}r(U_Worksheet__filenamerU bernoullir U_Worksheet__cellsr!]r"((hor#}r$(U_TextCell__worksheetr%jU_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.jU_Cell__completionsr/h׉U_Cell__out_htmlr0UU	_Cell__idr1Mphhډ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)r2U
_Cell__dirr3U+sage_notebook/worksheets/bernoulli/cells/18r4U
_Cell__outr5U'
CPU time: 0.34 s,  Wall time: 0.36 s

r6Uhas_new_outputr7U_Cell__versionr8KU_Cell__sager9h*)Rr:U_Cell__typer;hBU_Cell__interruptedr<ub(hor=}r>(j+Ulen(str(a))r?hU!
r@j.jj/h׉j0Uj1MphhډhUhos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/bernoulli/cells/19")
len(str(a))rAj3U+sage_notebook/worksheets/bernoulli/cells/19rBj5U
27706

rCj7j8Kj9j:j;hBj<ub(horD}rE(j+U*time v = bernoulli_mod_p(next_prime(10^4))rFhU!
rGj.jj/h׉j0Uj1Mphhډ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))rHj3U+sage_notebook/worksheets/bernoulli/cells/20rIj5U'
CPU time: 0.06 s,  Wall time: 0.06 s

rJj7j8Kj9j:j;hBj<ub(horK}rL(j+U,time v = bernoulli_mod_p(next_prime(2*10^5))rMhU!
rNj.jj/h׉j0Uj1Mphhډ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))rOj3U+sage_notebook/worksheets/bernoulli/cells/21rPj5U'
CPU time: 1.57 s,  Wall time: 1.58 s

rQj7j8Kj9j:j;hBj<ub(horR}rS(j+Uv[:10]rThU!
rUj.jj/h׉j0Uj1MphhډhUcos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/bernoulli/cells/22")
v[:10]rVj3U+sage_notebook/worksheets/bernoulli/cells/22rWj5U<
[1, 1668, 7672, 4527, 7672, 8036, 3603, 1669, 5899, 6162]

rXj7j8Kj9j:j;hBj<ub(horY}rZ(j+U!bernoulli(2) % next_prime(2*10^5)r[j.jj/j0Uj1Mpj3U+sage_notebook/worksheets/bernoulli/cells/23r\j5U33334r]j7j8Kj9Nj;hOj<ub(hor^}r_(j+Uj.jj/j0Uj1Mpj3U+sage_notebook/worksheets/bernoulli/cells/24r`j5Uj7j8Kj9Nj;hOj<ubeU_Worksheet__synchroraKU_Worksheet__namerbU	bernoullircU_Worksheet__attachedrd}reU/Users/was/.sage/init.sagerfGAjesU_Worksheet__saltrgU1168977577.570778rhh]ri(Ua-sage.rings.rational.RationalrjUv-listrkeU_Worksheet__dirrlU"sage_notebook/worksheets/bernoullirmU_Worksheet__queuern]roU_Worksheet__next_idrpMphj:U_Worksheet__passcryptrqU_Worksheet__comp_is_runningrrU_Worksheet__passcodersU
11G3BJNEUV/PkrtU_Worksheet__notebookruhU_Worksheet__idrvKU_Worksheet__next_block_idrwKU_Worksheet__systemrxNubUriemannry(horz}r{(h
Uriemannr|h]r}((hor~}r(hjzhT

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)
rhM@ub(hor}r(hUG#auto def f(x): return x / log(x) def p(x): return prime_pi(x)rhU!
rhjzhh;hUhM@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)rh#U(sage_notebook/worksheets/riemann/cells/2rh%U

rh'h(Kh)h*)RrhAhBh,ub(hor}r(hjzhUNow we plot them:
xmax = 1000
G = plot(f,2,xmax, linestyle=':', label='x/log(x)') + \
    plot(Li,2,xmax, marker='.', plot_points=30, plot_division=0, label='Li(x)') + \
    plot(p, 2,xmax, label='pi(x)', rgbcolor=(1,0,0))
G.show()
rhM@ub(hor}r(hUxmax = 20 G = plot(f, 2,xmax, linestyle='--', label='x/log(x)') + \ plot(Li,2,xmax, plot_points=30, plot_division=0, label='Li(x)') + \ plot(p, 2,xmax, label='P(X)', rgbcolor=(1,0,0)) G.show(xmax=xmax)rhU!
rhjzhh;hU@rhM@h=h h!T'os.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/riemann/cells/4")
xmax = 20
G = plot(f, 2,xmax, linestyle='--', label='x/log(x)') +     plot(Li,2,xmax, plot_points=30, plot_division=0, label='Li(x)') +     plot(p, 2,xmax, label='P(X)', rgbcolor=(1,0,0))
G.show(xmax=xmax)rh#U(sage_notebook/worksheets/riemann/cells/4rh%U

rh'h(Kh)hNhAhh,ub(hor}r(hUxmax = 500
G = plot(f, 2,xmax, linestyle='--', label='x/log(x)') + \
    plot(Li,2,xmax, plot_points=30, plot_division=0, label='Li(x)') + \
    plot(p, 2,xmax, label='P(X)', rgbcolor=(1,0,0))
G.show(xmax=xmax)rhU!
rhjzhh;hU@rhM@h=h h!T(os.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/riemann/cells/5")
xmax = 500
G = plot(f, 2,xmax, linestyle='--', label='x/log(x)') +     plot(Li,2,xmax, plot_points=30, plot_division=0, label='Li(x)') +     plot(p, 2,xmax, label='P(X)', rgbcolor=(1,0,0))
G.show(xmax=xmax)rh#U(sage_notebook/worksheets/riemann/cells/5rh%U

rh'h(Kh)hNhAhh,ub(hor}r(hUxmax = 20000
G = plot(f, 2,xmax, linestyle='--', label='x/log(x)') + \
    plot(Li,2,xmax, plot_points=30, plot_division=0, label='Li(x)') + \
    plot(p, 2,xmax, label='P(X)', rgbcolor=(1,0,0))
G.show(xmax=xmax)rhU!
rhjzhh;hU@rhM@h=h h!T*os.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/riemann/cells/6")
xmax = 20000
G = plot(f, 2,xmax, linestyle='--', label='x/log(x)') +     plot(Li,2,xmax, plot_points=30, plot_division=0, label='Li(x)') +     plot(p, 2,xmax, label='P(X)', rgbcolor=(1,0,0))
G.show(xmax=xmax)rh#U(sage_notebook/worksheets/riemann/cells/6rh%U

rh'h(Kh)hNhAhh,ub(hor}r(hUhjzhhUhM@h#U(sage_notebook/worksheets/riemann/cells/7rh%Uh'h(Kh)NhAhh,ubehKhh}rU/Users/was/.sage/init.sagerGAjesh]r(U
f-functionrU
p-functionrehU sage_notebook/worksheets/riemannrh]rhM@hhhjhhUriemannrhU1168948561.443285rhU
11G3BJNEUV/PkrhKhKhNubU	interfacer(hor}r(h
U	interfacerh]r((hor}r(hjhU3

Example: Interface to GP/PARI and Singular

rhM ub(hor}r(hUf = maple('sin(x^2)')rhU!
rhjh։h׉hUhM hډhUros.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/interface/cells/27")
f = maple('sin(x^2)')rhU+sage_notebook/worksheets/interface/cells/27rhU

rhhh*)RrhKhhBhhub(hor}r(hUfhU!
rhjh։h׉hUhM hډhU^os.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/interface/cells/28")
frhU+sage_notebook/worksheets/interface/cells/28rhU
sin(x^2)

rhhjhKhhBhhub(hor}r(hUs = str(f.integrate('x'))rhU!
rhjh։h׉hUhM hډhUvos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/interface/cells/29")
s = str(f.integrate('x'))rhU+sage_notebook/worksheets/interface/cells/29rhU

rhhjhKhhBhhub(hor}r(hUshU!
rhjh։h׉hUhM hډhU^os.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/interface/cells/30")
srhU+sage_notebook/worksheets/interface/cells/30rhU6
'1/2*2^(1/2)*Pi^(1/2)*FresnelS(2^(1/2)/Pi^(1/2)*x)'

rhhjhKhhBhhub(hor}r(hUgp.eval('b = 2^3')rhU!
rhjh։h׉hUhM hډhUoos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/interface/cells/25")
gp.eval('b = 2^3')rhU+sage_notebook/worksheets/interface/cells/25rhU
'8'

rhhjhKhhBhhub(hor}r(hUgp.eval('b^2')rhU!
rhjh։h׉hUhM hډhUkos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/interface/cells/26")
gp.eval('b^2')rhU+sage_notebook/worksheets/interface/cells/26rhU
'64'

rhhjhKhhBhhub(hor}r(hUa = gp('x^3 - y^3'); arU_Cell__introspect_htmlrU!
rhjhU_Cell__introspectrhUhM U_Cell__timerU_Cell__is_htmlrU_before_preparserUsos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/interface/cells/16")
a = gp('x^3 - y^3'); arh#U+sage_notebook/worksheets/interface/cells/16rh%U
x^3 - y^3

rh'h(Kh)jhAhBh,ub(hor}r(hUa.newtonpoly()rjU!
rhjhjhUhM jjjUkos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/interface/cells/17")
a.newtonpoly()rU_word_being_completedrUa.rh#U+sage_notebook/worksheets/interface/cells/17rh%T#
Traceback (most recent call last):
  File "", line 1, in 
  File "/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/interface/code/6.py", line 4, in 
    exec compile(ur'a.newtonpoly()' + '\n', '', 'single')
  File "/Users/was/talks/2007-01-15-sage-cse/", line 1, in 
    
  File "/Users/was/s/local/lib/python2.5/site-packages/sage/interfaces/expect.py", line 684, in __call__
    return self._obj.parent().function_call(self._name, [self._obj] + list(args))
  File "/Users/was/s/local/lib/python2.5/site-packages/sage/interfaces/expect.py", line 631, in function_call
    return self.new("%s(%s)"%(function, ",".join([s.name() for s in args])))
  File "/Users/was/s/local/lib/python2.5/site-packages/sage/interfaces/expect.py", line 533, in new
    return self(code)
  File "/Users/was/s/local/lib/python2.5/site-packages/sage/interfaces/expect.py", line 489, in __call__
    return cls(self, x)
  File "/Users/was/s/local/lib/python2.5/site-packages/sage/interfaces/expect.py", line 718, in __init__
    raise TypeError, x
TypeError: Error executing code in GP/PARI:
CODE:
	sage[3]=newtonpoly(sage[2]);
GP/PARI ERROR:
  ***   expected character: ',' instead of: ...age[3]=newtonpoly(sage[2]);
                                                                        ^--rh'h(Kh)jhAUhiddenrh,ub(hor}r(hUtype(a)rjU!
rhjhjhUhM jjjUdos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/interface/cells/18")
type(a)rh#U+sage_notebook/worksheets/interface/cells/18rh%U)


rh'h(Kh)hNhAhOh,ub(hor}r(hU	parent(a)rjU!
rhjhjhUhM jjjUfos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/interface/cells/19")
parent(a)rh#U+sage_notebook/worksheets/interface/cells/19rh%U
GP/PARI interpreter

rh'h(Kh)hNhAhOh,ub(hor}r(hU
a.factor()rjU!
r	hjhjhUhM jjjUgos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/interface/cells/20")
a.factor()r
h#U+sage_notebook/worksheets/interface/cells/20rh%T
Traceback (most recent call last):
  File "", line 1, in 
  File "/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/interface/code/16.py", line 4, in 
    exec compile(ur'a.factor()' + '\n', '', 'single')
  File "/Users/was/talks/2007-01-15-sage-cse/", line 1, in 
    
  File "/Users/was/s/local/lib/python2.5/site-packages/sage/interfaces/expect.py", line 684, in __call__
    return self._obj.parent().function_call(self._name, [self._obj] + list(args))
  File "/Users/was/s/local/lib/python2.5/site-packages/sage/interfaces/expect.py", line 631, in function_call
    return self.new("%s(%s)"%(function, ",".join([s.name() for s in args])))
  File "/Users/was/s/local/lib/python2.5/site-packages/sage/interfaces/expect.py", line 533, in new
    return self(code)
  File "/Users/was/s/local/lib/python2.5/site-packages/sage/interfaces/expect.py", line 489, in __call__
    return cls(self, x)
  File "/Users/was/s/local/lib/python2.5/site-packages/sage/interfaces/expect.py", line 718, in __init__
    raise TypeError, x
TypeError: Error executing code in GP/PARI:
CODE:
	sage[5]=factor(sage[4]);
GP/PARI ERROR:
  *** factor: sorry, factor for general polynomials is not yet implemented.rh'h(Kh)hNhAhOh,ub(hor
}r(hUR. = QQ[x,y]
b = R(str(a))rjU!
rhjhjhUhM jjjU|os.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/interface/cells/21")
R. = QQ[x,y]
b = R(str(a))rh#U+sage_notebook/worksheets/interface/cells/21rh%U

rh'h(Kh)hNhAhOh,ub(hor}r(hU
b.factor()rjU!
rhjhjhUhM jjjUgos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/interface/cells/22")
b.factor()rh#U+sage_notebook/worksheets/interface/cells/22rh%U!
(-1*y + x) * (y^2 + x*y + x^2)

rh'h(Kh)hNhAhOh,ub(hor}r(hUjU!
rhjhjhUhM jjjU]os.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/interface/cells/23")
rh#U+sage_notebook/worksheets/interface/cells/23rh%U

r h'h(Kh)hNhAhOh,ubehK;hh}r!U/Users/was/.sage/init.sager"GAjesh]r#(Ua-sage.interfaces.gp.GpElementr$U$f-sage.interfaces.maple.MapleElementr%Us-strr&ehU"sage_notebook/worksheets/interfacer'h]r(hM hhhjhhU	interfacer)hU1168948633.588002r*hU
11G3BJNEUV/Pkr+hKhKhNubU	_scratch_r,(hor-}r.(U_Worksheet__filenamer/U	_scratch_r0U_Worksheet__cellsr1]r2((hor3}r4(hj-hT

SAGE: Software for Algebra and Geometry Experimentation



r5hM6ub(hor6}r7(hUhj-hhUhM7h#U,sage_notebook/worksheets/_scratch_/cells/311r8h%Uh'h(Kh)NhAhh,ub(hor9}r:(hUhj-hhUhM8h#U,sage_notebook/worksheets/_scratch_/cells/312r;h%Uh'h(Kh)NhAhh,ubeU_Worksheet__synchror<KU_Worksheet__namer=U _scratch_r>U_Worksheet__dirr?U"sage_notebook/worksheets/_scratch_r@U_Worksheet__attachedrA}rBU/Users/was/.sage/init.sagerCGAjesU_Worksheet__queuerD]rEU_Worksheet__next_idrFM9U_Worksheet__passcryptrGU_Worksheet__comp_is_runningrHU_Worksheet__saltrIU1168543793.388489rJU_Worksheet__notebookrKhU_Worksheet__idrLKU_Worksheet__next_block_idrMK U_Worksheet__systemrNNU_Worksheet__passcoderOU 11G3BJNEUV/PkrPubUtalkrQ(horR}rS(U_Worksheet__filenamerTUtalkrUU_Worksheet__cellsrV]rW((horX}rY(hjRhU(

A Few Introductory Calculations

rZhMZub(hor[}r\(hU122 + 3939^100r]hU!
r^hjRhh;hUhM[h=h h!Ufos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/talk/cells/91")
122 + 3939^100r_h#U&sage_notebook/worksheets/talk/cells/91r`h%Tk
345619375323669975367860807124255037076153194188885931584246755620617168037547598722532539129249459087563155698072067777782990662920343395325000445341613889629673957434153020923227407467827494067876849537309882945198261109518655022861231720822535378266349041507766551309275258117413203506790245934260655896057550180870173070732758020223605128239775421756626123

rah'h(Kh)h*)RrbhAUwraprch,ub(hord}re(hUtime v = prime_range(10000)rfhU!
rghjRhh;hUhM\h=h h!Uos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/talk/cells/92")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
v = prime_range(10000)rhh#U&sage_notebook/worksheets/talk/cells/92rih%U'
CPU time: 0.00 s,  Wall time: 0.01 s

rjh'h(Kh)jbhAhBh,ub(hork}rl(hUhjRh։hUhMehU'sage_notebook/worksheets/talk/cells/101rmhUhhKhhBhub(horn}ro(hUpreparse('2 ^ 3')rphU!
rqhjRhh;hUhM]h=h h!Uios.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/talk/cells/93")
preparse('2 ^ 3')rrh#U&sage_notebook/worksheets/talk/cells/93rsh%U
'Integer(2) ** Integer(3)'

rth'h(Kh)jbhAhBh,ub(horu}rv(hU%python
2 ** 3rwhU!
rxhjRhh;hUhM^h=h h!Ufos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/talk/cells/94")
%python
2 ** 3ryh#U&sage_notebook/worksheets/talk/cells/94rzh%U
8


r{h'h(Kh)jbhAhBh,ub(hor|}r}(hUtime n=factorial(10^6)r~hU!
rhjRhh;hUhM_h=h h!Uos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/talk/cells/95")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
n=factorial(10^6)rh#U&sage_notebook/worksheets/talk/cells/95rh%U'
CPU time: 2.20 s,  Wall time: 2.24 s

rh'h(Kh)jbhAhBh,ub(hor}r(hUshow(factor( factorial(40) ))rhU!
rhjRhh;hUhM`h=h h!Uuos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/talk/cells/96")
show(factor( factorial(40) ))rh#U&sage_notebook/worksheets/talk/cells/96rh%U
2^{38} \cdot 3^{18} \cdot 5^{9} \cdot 7^{5} \cdot 11^{3} \cdot 13^{3} \cdot 17^{2} \cdot 19^{2} \cdot 23 \cdot 29 \cdot 31 \cdot 37
rh'h(Kh)jbhAhBh,ub(hor}r(hU:m = matrix(5,5,[randint(0,1) for _ in range(25)]); show(m)rhU!
rhjRhh;hUhMah=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)rh#U&sage_notebook/worksheets/talk/cells/97rh%U
\left(\begin{array}{rrrrr} 1&1&1&1&0\\ 0&1&0&0&1\\ 0&0&0&1&0\\ 1&0&0&1&1\\ 1&0&0&1&1 \end{array}\right)
rh'h(Kh)jbhAhBh,ub(hor}r(hUf = m.charpoly('T'); show(f)rhU!
rhjRhh;hUhMbh=h h!Utos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/talk/cells/98")
f = m.charpoly('T'); show(f)rh#U&sage_notebook/worksheets/talk/cells/98rh%UM
T^{5} - 4T^{4} + 4T^{3} - 3T^{2} + T
rh'h(Kh)jbhAhBh,ub(hor}r(hUshow(factor(f))rhU!
rhjRhh;hUhMch=h h!Ugos.chdir("/Users/was/talks/2007-01-15-sage-cse/sage_notebook/worksheets/talk/cells/99")
show(factor(f))rh#U&sage_notebook/worksheets/talk/cells/99rh%US
T \cdot (T^{4} - 4T^{3} + 4T^{2} - 3T + 1)
rh'h(Kh)jbhAhBh,ub(hor}r(hUhjRhhUhMdh#U'sage_notebook/worksheets/talk/cells/100rh%Uh'h(Kh)NhAhh,ubeU_Worksheet__synchrorKU_Worksheet__comp_is_runningrU_Worksheet__attachedr}rU/Users/was/.sage/init.sagerGAjesh]r(U_-intrU8f-sage.rings.polynomial_element.Polynomial_integer_denserU7m-sage.matrix.matrix_integer_dense.Matrix_integer_denserUn-sage.rings.integer.IntegerrUv-listreU_Worksheet__dirrUsage_notebook/worksheets/talkrU_Worksheet__queuer]rU_Worksheet__next_idrMfhjbU_Worksheet__passcryptrU_Worksheet__namerUtalkrU_Worksheet__saltrU1168942707.757150rU_Worksheet__notebookrhU_Worksheet__idrKU_Worksheet__next_block_idrKU_Worksheet__systemrNU_Worksheet__passcoderU 11G3BJNEUV/PkrubUsagexr(hor}r(h Usagexrh ]r((hor}r(hjhU0

Compiled code... right in the notebook!

rhM0ub(hor}r(hUSdef is2pow(n): while n != 0 and n%2 == 0: n = n >> 1 return n == 1rhU!
rhjhh׉hUhM0hhډ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 == 1rh#U&sage_notebook/worksheets/sagex/cells/6rh%U

rh'h(Kh)h*)RrhAhBh,ub(hor}r(hU1time v = [n for n in range(10^5) if is2pow(n)]; vrhU!
rhjhh׉hUhM0hhډ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)]; vrh#U&sage_notebook/worksheets/sagex/cells/7rh%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

rh'h(Kh)jhAhBh,ub(hor}r(hUp%sagex
def is2pow_compiled(unsigned int n):
    while n != 0 and n%2 == 0: 
        n = n >> 1
    return n == 1rhU!
rhjhh׉hUf_sage5.crhM0hhډ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 == 1rh#U&sage_notebook/worksheets/sagex/cells/8rh%U

rh'h(Kh)jhAhBh,ub(hor}r(hU