csage.server.notebook.notebook Notebook q)q}q(U_Notebook__worksheetsq}qU _scratch_q(csage.server.notebook.worksheet Worksheet qoq}q (U_Worksheet__filenameq U _scratch_q U_Worksheet__cellsq ]q ((csage.server.notebook.cell TextCell qoq}q(U_TextCell__worksheetqhU_TextCell__textqT

SAGE

Software for Algebra and Geometry Experimentation DEMO


Warm up

qU _TextCell__idqKub(csage.server.notebook.cell Cell qoq}q(U _Cell__inqU2 ^ 3qU_Cell__introspect_htmlqU!
qU_Cell__worksheetqhU_Cell__completionsqU_Cell__introspectqU_Cell__out_htmlqUU	_Cell__idq KU_Cell__timeq!U_Cell__is_htmlq"U_before_preparseq#Uhos.chdir("/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/cells/241")
2 ^ 3q$U
_Cell__dirq%U,sage_notebook/worksheets/_scratch_/cells/241q&U
_Cell__outq'U
8

q(Uhas_new_outputq)U_Cell__versionq*KU_Cell__sageq+csage.interfaces.sage0
reduce_load_Sage
q,)Rq-U_Cell__typeq.Uwrapq/U_Cell__interruptedq0ub(hoq1}q2(hU
%python
2 ^ 3q3hU!
q4hhhhhUh Kh!h"h#Upos.chdir("/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/cells/242")
%python
2 ^ 3q5h%U,sage_notebook/worksheets/_scratch_/cells/242q6h'U
1


q7h)h*Kh+h-h.h/h0ub(hoq8}q9(hhhUOSAGE has interfaces to most other computer algebra systems, commercial or free.q:hKub(hoq;}q<(U	_Cell__inq=U	factorialq>hT	
File: /Users/was/s/local/lib/python2.5/site-packages/sage/rings/arith.py
Source Code (starting at line 194):
def factorial(n, algorithm='gmp'):
    r"""
    Compute the factorial of $n$, which is the product
    $1\cdot 2\cdot 3 \cdots (n-1) n$.

    INPUT:
        n -- an integer
        algorithm -- string (default: 'gmp')
             'gmp' -- use the GMP C-library factorial function
             'pari' -- use PARI's factorial function
        
    OUTPUT:
        an integer

    EXAMPLES:
        sage: factorial(0)
        1
        sage: factorial(4)
        24
        sage: factorial(10)
        3628800
        sage: factorial(1) == factorial(0)
        True
        sage: factorial(6) == 6*5*4*3*2
        True
        sage: factorial(1) == factorial(0)
        True
        sage: factorial(71) == 71* factorial(70)
        True
        sage: factorial(-32)
        Traceback (most recent call last):
        ...
        ValueError: factorial -- must be nonnegative

    PERFORMANCE:
    This discussion is valid as of April 2006.  All timings
    below are on a Pentium Core Duo 2Ghz MacBook Pro running Linux
    with a 2.6.16.1 kernel.
    
    \begin{itemize}
       \item It takes less than a minute to compute the factorial of
          $10^7$ using the GMP algorithm, and the factorial of $10^6$
          takes less than 4 seconds.

       \item The GMP algorithm is faster and more memory efficient
          than the PARI algorithm.  E.g., PARI computes $10^7$
          factorial in 100 seconds on the core duo 2Ghz.

       \item For comparison, computation in Magma $\leq$ 2.12-10 of
             $n!$ is best done using \code{&*[1..n]}.  
             It takes 113 seconds to compute the factorial of $10^7$
             and 6 seconds to compute the factorial of $10^6$.
             Mathematica V5.2 compute the factorial of $10^7$ in
             136 seconds and the factorial of $10^6$ in 7 seconds.
             (Mathematica is notably very efficient at memory usage
             when doing factorial calculations.)
    \end{itemize}

    """
    if n < 0:
        raise ValueError, "factorial -- must be nonnegative"
    Z = sage.rings.integer.Integer
    if algorithm == 'gmp':
        return Z(n).factorial()
    elif algorithm == 'pari':
        return Z(pari('%s!'%Z(n)))
    else:
        raise ValueError, 'unknown algorithm'
q?U_Cell__worksheetq@hU_Cell__completionsqAh]qB(U factorial??qCUeU_Cell__out_htmlqDUU _Cell__outqEUU _Cell__idqFM h"h#Unos.chdir("/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/cells/267") factorial??qGU _Cell__dirqHU,sage_notebook/worksheets/_scratch_/cells/267qIU_word_being_completedqJh>Uhas_new_outputqKU_Cell__versionqLKU _Cell__typeqMh/h!U_Cell__interruptedqNub(hoqO}qP(hU%%maple integrate(sin(x)*cos(x)+1/x,x)qQU_Cell__introspect_htmlqRU!
qShhhU_Cell__introspectqThUh KU_Cell__timeqUU_Cell__is_htmlqVU_before_preparseqWUos.chdir("/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/cells/244")
%maple
integrate(sin(x)*cos(x)+1/x,x)qXh%U,sage_notebook/worksheets/_scratch_/cells/244qYh'U
1/2*sin(x)^2+ln(x)

qZh)h*Kh+h-h.h/h0ub(hoq[}q\(hUmagma('Factorization(-2006)')q]hRU!
q^hhhhThUh KhUhVhWUos.chdir("/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/cells/245")
magma('Factorization(-2006)')q_h%U,sage_notebook/worksheets/_scratch_/cells/245q`h'U
[ <2, 1>, <17, 1>, <59, 1> ]

qah)h*Kh+h-h.Uwrapqbh0ub(hoqc}qd(hhhU

Matrices

qehKub(hoqf}qg(hUm = matrix(5,5, range(25)); mqhhU!
qihhhhhUh Kh!h"h#Uos.chdir("/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/cells/247")
m = matrix(5,5, range(25)); mqjh%U,sage_notebook/worksheets/_scratch_/cells/247qkh'UW
[ 0  1  2  3  4]
[ 5  6  7  8  9]
[10 11 12 13 14]
[15 16 17 18 19]
[20 21 22 23 24]

qlh)h*Kh+h-h.h/h0ub(hoqm}qn(hUf = m.charpoly()qohU!
qphhhhhUh Kh!h"h#Usos.chdir("/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/cells/248")
f = m.charpoly()qqh%U,sage_notebook/worksheets/_scratch_/cells/248qrh'U

qsh)h*Kh+h-h.h/h0ub(hoqt}qu(hUfhU!
qvhhhhhUh Kh!h"h#Udos.chdir("/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/cells/249")
fqwh%U,sage_notebook/worksheets/_scratch_/cells/249qxh'U
x^5 - 60*x^4 - 250*x^3

qyh)h*Kh+h-h.h/h0ub(hoqz}q{(hUshow(f)q|hU!
q}hhhhhUh Kh!h"h#Ujos.chdir("/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/cells/250")
show(f)q~h%U,sage_notebook/worksheets/_scratch_/cells/250qh'UC
x^{5} - 60x^{4} - 250x^{3}
qh)h*Kh+h-h.h/h0ub(hoq}q(hUshow(factor(f))qhU!
qhhhhhUh Kh!h"h#Uros.chdir("/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/cells/251")
show(factor(f))qh%U,sage_notebook/worksheets/_scratch_/cells/251qh'UH
(x^{2} - 60x - 250) \cdot x^{3}
qh)h*Kh+h-h.h/h0ub(hoq}q(hhhU

Some Graphics

Integer Factorization Tree

We illustrate integer factorization as a product of primes using the ``factor trees''...qhKub(hoq}q(hT%hideall #auto # The source code to draw factorization trees... import random def factor_tree(n, font=10): rows = [] v = [(n,None,0)] ftree(rows, v, 0, factor(n)) return draw_ftree(rows, font) def ftree(rows, v, i, F): if len(v) > 0: # add a row to g at the ith level. rows.append(v) w = [] for i in range(len(v)): k, _,_ = v[i] if k is None or is_prime(k): w.append((None,None,None)) else: d = random.choice(divisors(k)[1:-1]) w.append((d,k,i)) e = k//d if e == 1: w.append((None,None)) else: w.append((e,k,i)) if len(w) > len(v): ftree(rows, w, i+1, F) def draw_ftree(rows,font): g = Graphics() for i in range(len(rows)): cur = rows[i] for j in range(len(cur)): e, f, k = cur[j] if not e is None: if is_prime(e): c = (1,0,0) else: c = (0,0,.4) g += text(str(e), (j*2-len(cur),-i), fontsize=font, rgbcolor=c) if not k is None and not f is None: g += line([(j*2-len(cur),-i), (k*2-len(rows[i-1]),-i+1)], alpha=0.4, thickness=1) return g def factor_trees(n, cols=4, rows=3, font=10): return graphics_array([[factor_tree(n,font) for _ in range(cols)] for _ in range(rows)])qhRU!
qhhhhUh KhVhWTgos.chdir("/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/cells/253")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
%hideall
#auto

# The source code to draw factorization trees...

import random

def factor_tree(n, font=10):
    rows = []
    v = [(n,None,0)]
    ftree(rows, v, 0, factor(n))
    return draw_ftree(rows, font)

def ftree(rows, v, i, F):
    if len(v) > 0:
        # add a row to g at the ith level. 
        rows.append(v)
    w = []
    for i in range(len(v)):
        k, _,_ = v[i]
        if k is None or is_prime(k):
            w.append((None,None,None))
        else:
            d = random.choice(divisors(k)[1:-1])
            w.append((d,k,i))
            e = k//d
            if e == 1:
                w.append((None,None))
            else:
                w.append((e,k,i))
    if len(w) > len(v):
        ftree(rows, w, i+1, F)


def draw_ftree(rows,font):
    g = Graphics()
    for i in range(len(rows)):
        cur = rows[i]
        for j in range(len(cur)):
            e, f, k = cur[j]
            if not e is None:
                if is_prime(e):
                     c = (1,0,0)
                else:
                     c = (0,0,.4)
                g += text(str(e), (j*2-len(cur),-i), fontsize=font, rgbcolor=c)
                if not k is None and not f is None:
                    g += line([(j*2-len(cur),-i), (k*2-len(rows[i-1]),-i+1)], alpha=0.4, thickness=1) 
    return g

def factor_trees(n, cols=4, rows=3, font=10):
    return graphics_array([[factor_tree(n,font) for _ in range(cols)] for _ in range(rows)])qh%U,sage_notebook/worksheets/_scratch_/cells/253qh'U'
CPU time: 0.00 s,  Wall time: 0.00 s

qh)h*Kh+h-h0ub(hoq}q(hhhU
qhKub(hoq}q(hU[F = factor_trees(factorial(10), rows=1, cols=1, font=14) F.show(axes=False, figsize=[10,6])qhU!
qhhhhhUDqh Kh!h"h#Uos.chdir("/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/cells/255")
F = factor_trees(factorial(10), rows=1, cols=1, font=14)
F.show(axes=False, figsize=[10,6])qh%U,sage_notebook/worksheets/_scratch_/cells/255qh'U

qh)h*Kh+h-h.h/h0ub(hoq}q(hhhU|

A 3d Raytracer is Built into SAGE

The following is a picture of rational points on a rank 1 elliptic curve.qhMub(hoq}q(hT7t = 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!
qhhhhhUDqh Mh!h"h#Tos.chdir("/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/cells/257")
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/_scratch_/cells/257qh'U:
y^2 + y = x^3 - x
qh)h*Kh+h-h.h/h0ub(hoq}q(hhhT

Some Basic Calculus

This is work in progress with Bobby Moretti. SAGE includes Maxima, which is a program that started at the AI lab at MIT in the 1960s!. It is capable of very sophisticated symbolic and numerical calculus. One can use it from SAGE via "maxima.[tab]", but we are writing new code so its functionality can be used naturally in SAGE without any knowledge of Maxima.qhMub(hoq}q(hUfrom sage.calculus.all import *qhU!
qhhhhhUh Mh!h"h#Uos.chdir("/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/cells/259")
from sage.calculus.all import *qh%U,sage_notebook/worksheets/_scratch_/cells/259qh'U

qh)h*Kh+h-h.h/h0ub(hoq}q(hU f = sin(x)*cos(x) + 1/x; show(f)qhU!
qhhhhhUh Mh!h"h#Uos.chdir("/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/cells/260")
f = sin(x)*cos(x) + 1/x; show(f)qh%U,sage_notebook/worksheets/_scratch_/cells/260qh'Uh
\sin \left( x \right) \cdot \cos \left( x \right) + \frac{1}{x}
qh)h*Kh+h-h.h/h0ub(hoq}q(hUg = f.integral(x); show(g)qhU!
qhhhhhUh Mh!h"h#U}os.chdir("/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/cells/261")
g = f.integral(x); show(g)qh%U,sage_notebook/worksheets/_scratch_/cells/261qh'T
/Users/was/s/local/bin/maxima ['/Users/was/s/local/bin/maxima', '--disable-readline']
End Of File (EOF) in read_nonblocking(). Empty string style platform.

version: 2.0 ($Revision: 1.151 $)
command: /Users/was/s/local/bin/maxima
args: ['/Users/was/s/local/bin/maxima', '--disable-readline']
patterns:
    \(\%i[0-9]+\)
buffer (last 100 chars): 
before (last 100 chars): 
after: 
match: None
match_index: None
exitstatus: None
flag_eof: 1
pid: 26166
child_fd: 3
timeout: 30
delimiter: 
logfile: None
maxread: 1
searchwindowsize: None
delaybeforesend: 0
Maxima 5.11.0 http://maxima.sourceforge.net
Using Lisp CLISP 2.41 (2006-10-13)
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
This is a development version of Maxima. The function bug_report()
provides bug reporting information.
(%i1) print "\x01r\x01e118"
Incorrect syntax: x01rx01e118 is not an infix operator
rint "\x01r\x01e118"
                  ^
(%i1)qh)h*Kh+Nh.h/h0ub(hoq}q(hUf = sin(x+y)*cos(x+z); show(f)qhU!
qhhhhhUh Mh!h"h#Uos.chdir("/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/cells/262")
f = sin(x+y)*cos(x+z); show(f)qh%U,sage_notebook/worksheets/_scratch_/cells/262qh'Ub
\sin \left( x + y \right) \cdot \cos \left( x + z \right)
qh)h*Kh+h-h.h/h0ub(hoq}q(hUh = f.trig_expand(); show(h)qhT
File:        /Users/was/s/local/lib/python2.5/site-packages/sage/calculus/calculus.py
Type:        <type 'instancemethod'>
Definition:  f.trig_expand()
Docstring: 

        EXAMPLES:
            sage: sin(5*x).expand_trig()
            sin(x)^5 - 10*cos(x)^2*sin(x)^3 + 5*cos(x)^4*sin(x)

            sage: cos(2*x + y).trig_expand()
            cos(2*x)*cos(y) - sin(2*x)*sin(y)

        ALIAS: trig_expand
qhhhh]q(Uf.trig_expand?qUehUh Mh!h"h#Uqos.chdir("/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/cells/263") f.trig_expand?qh%U,sage_notebook/worksheets/_scratch_/cells/263qh'U
\cos \left( x \right) \cdot \sin \left( y \right) + \sin \left( x \right) \cdot \cos \left( y \right) \cdot \cos \left( x \right) \cdot \cos \left( z \right) - \sin \left( x \right) \cdot \sin \left( z \right)
qh)h*Kh+h-h.h/h0ub(hoq}q(hU/for i in range(10): print "hello world ", iqhU!
qhhhhhUh Mh!h"h#Uos.chdir("/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/cells/264")
for i in range(10):
    print "hello world ", iqh%U,sage_notebook/worksheets/_scratch_/cells/264qh'U
hello world  0
hello world  1
hello world  2
hello world  3
hello world  4
hello world  5
hello world  6
hello world  7
hello world  8
hello world  9

qh)h*Kh+h-h.h/h0ub(hoq}q(h=T        sage: t = Tachyon(xres=800,yres=800, camera_center=(2,5,2), look_at=(2.5,0,0))
        sage: t.light((0,0,100), 1, (1,1,1))
        sage: t.texture('r', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(1,0,0))
        sage: for i in srange(0,50,0.1):
        ...    t.sphere((i/10,sin(i),cos(i)), 0.05, 'r')
        ...
        sage: t.texture('white', color=(1,1,1), opacity=1, specular=1, diffuse=1)
        sage: t.plane((0,0,-100), (0,0,-100), 'white')
        sage: t.save('sage.png')qhU!
qh@hhAhhDUCqhFM	h"h#TWos.chdir("/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/cells/265")
sage: t = Tachyon(xres=800,yres=800, camera_center=(2,5,2), look_at=(2.5,0,0))
        sage: t.light((0,0,100), 1, (1,1,1))
        sage: t.texture('r', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(1,0,0))
        sage: for i in srange(0,50,0.1):
        ...    t.sphere((i/10,sin(i),cos(i)), 0.05, 'r')
        ...
        sage: t.texture('white', color=(1,1,1), opacity=1, specular=1, diffuse=1)
        sage: t.plane((0,0,-100), (0,0,-100), 'white')
        sage: t.save('sage.png')qhHU,sage_notebook/worksheets/_scratch_/cells/265qhEU

qhKhLKU_Cell__sageqh-hMh/h!hNub(hoq}q(h=Uh@hhAhDUhFM
hHU,sage_notebook/worksheets/_scratch_/cells/266qhEUhKhLKhMh/hNubeU_Worksheet__synchroqK{U_Worksheet__nameqU	_scratch_qU_Worksheet__dirqU"sage_notebook/worksheets/_scratch_qU_Worksheet__attachedq}qU_Worksheet__queueq]qU_Worksheet__next_idqMU_Worksheet__passcryptqU_Worksheet__comp_is_runningqU_Worksheet__saltqU1168543793.388489qU_Worksheet__notebookqhU_Worksheet__idqKU_Worksheet__next_block_idqKU_Worksheet__systemqNU_Worksheet__passcodeqU
11G3BJNEUV/PkqubsU_Notebook__historyq]q(U;# Worksheet '_scratch_' (2007-01-11 at 11:33)
sage: 2 + 3
5qU# Worksheet '_scratch_' (2007-01-11 at 11:33)
sage: m = matrix(5,5, range(25)); m
[ 0  1  2  3  4]
[ 5  6  7  8  9]
[10 11 12 13 14]
[15 16 17 18 19]
[20 21 22 23 24]qUE# Worksheet '_scratch_' (2007-01-11 at 11:34)
sage: f = m.charpoly()
qUL# Worksheet '_scratch_' (2007-01-11 at 11:34)
sage: f
x^5 - 60*x^4 - 250*x^3qU{# Worksheet '_scratch_' (2007-01-11 at 11:34)
sage: show(f)
x^{5} - 60x^{4} - 250x^{3}
qU# Worksheet '_scratch_' (2007-01-11 at 11:34) sage: show(factor(f))
(x^{2} - 60x - 250) \cdot x^{3}
qU;# Worksheet '_scratch_' (2007-01-11 at 11:37) sage: 2 ^ 3 8qUI# Worksheet '_scratch_' (2007-01-11 at 11:37) sage: %python sage: 2 ^ 3 1rUb# Worksheet '_scratch_' (2007-01-11 at 11:38) sage: %maple sage: integrate(Sin[x],x) int(Sin[x],x)rU\# Worksheet '_scratch_' (2007-01-11 at 11:38) sage: %maple sage: integrate(sin(x),x) -cos(x)rU# Worksheet '_scratch_' (2007-01-11 at 11:38) sage: %maple sage: integrate(sin(x^2),x) 1/2*2^(1/2)*Pi^(1/2)*FresnelS(2^(1/2)/Pi^(1/2)*x)rT## Worksheet '_scratch_' (2007-01-11 at 11:40) sage: t = Tachyon(xres=800,yres=800, camera_center=(2,5,2), look_at=(2.5,0,0)) sage: t.light((0,0,100), 1, (1,1,1)) sage: t.texture('r', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(1,0,0)) sage: for i in srange(0,50,0.1): ... t.sphere((i/10,sin(i),cos(i)), 0.05, 'r') ... sage: t.texture('white', color=(1,1,1), opacity=1, specular=1, diffuse=1) sage: t.plane((0,0,-100), (0,0,-100), 'white') sage: t.save('sage.png') rT# Worksheet '_scratch_' (2007-01-11 at 11:41) A beautiful picture of rational points on a rank 1 elliptic curve. sage: t = Tachyon(xres=1000, yres=800, camera_center=(2,7,4), look_at=(2,0,0), raydepth=4) sage: t.light((10,3,2), 1, (1,1,1)) sage: t.light((10,-3,2), 1, (1,1,1)) sage: t.texture('black', color=(0,0,0)) sage: t.texture('red', color=(1,0,0)) sage: t.texture('grey', color=(.9,.9,.9)) sage: t.plane((0,0,0),(0,0,1),'grey') sage: t.cylinder((0,0,0),(1,0,0),.01,'black') sage: t.cylinder((0,0,0),(0,1,0),.01,'black') sage: E = EllipticCurve('37a') sage: P = E([0,0]) sage: Q = P sage: n = 100 sage: 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) ... ... sage: t.save('sage.png') # long time, e.g., 10-20 seconds rT# Worksheet '_scratch_' (2007-01-11 at 11:41) A beautiful picture of rational points on a rank 1 elliptic curve. sage: t = Tachyon(xres=1000, yres=800, camera_center=(2,7,4), look_at=(2,0,0), raydepth=4) sage: t.light((10,3,2), 1, (1,1,1)) sage: t.light((10,-3,2), 1, (1,1,1)) sage: t.texture('black', color=(0,0,0)) sage: t.texture('red', color=(1,0,0)) sage: t.texture('grey', color=(.9,.9,.9)) sage: t.plane((0,0,0),(0,0,1),'grey') sage: t.cylinder((0,0,0),(1,0,0),.01,'black') sage: t.cylinder((0,0,0),(0,1,0),.01,'black') sage: E = EllipticCurve('37a') sage: P = E([0,0]) sage: Q = P sage: n = 40 sage: 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) ... ... sage: t.save('sage.png') # long time, e.g., 10-20 seconds rT# Worksheet '_scratch_' (2007-01-11 at 11:43) sage: t = Tachyon(xres=1000, yres=800, camera_center=(2,7,4), look_at=(2,0,0), raydepth=4) sage: t.light((10,3,2), 1, (1,1,1)) sage: t.light((10,-3,2), 1, (1,1,1)) sage: t.texture('black', color=(0,0,0)) sage: t.texture('red', color=(1,0,0)) sage: t.texture('grey', color=(.9,.9,.9)) sage: t.plane((0,0,0),(0,0,1),'grey') sage: t.cylinder((0,0,0),(1,0,0),.01,'black') sage: t.cylinder((0,0,0),(0,1,0),.01,'black') sage: E = EllipticCurve('37a'); show(E) sage: P = E([0,0]) sage: Q = P sage: n = 40 sage: 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) ... sage: show(t)
y^2 + y = x^3 - x
rT# Worksheet '_scratch_' (2007-01-11 at 11:43) sage: t = Tachyon(xres=1000, yres=800, camera_center=(2,7,4), look_at=(2,0,0), raydepth=4) sage: t.light((10,3,2), 1, (1,1,1)) sage: t.light((10,-3,2), 1, (1,1,1)) sage: t.texture('black', color=(0,0,0)) sage: t.texture('red', color=(1,0,0)) sage: t.texture('grey', color=(.9,.9,.9)) sage: t.plane((0,0,0),(0,0,1),'grey') sage: t.cylinder((0,0,0),(1,0,0),.01,'black') sage: t.cylinder((0,0,0),(0,1,0),.01,'black') sage: E = EllipticCurve('37a'); show(E) sage: P = E([0,0]) sage: Q = P sage: n = 60 sage: 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) ... sage: show(t)
y^2 + y = x^3 - x
rT# Worksheet '_scratch_' (2007-01-11 at 11:43) sage: t = Tachyon(xres=700, yres=500, camera_center=(2,7,4), look_at=(2,0,0), raydepth=4) sage: t.light((10,3,2), 1, (1,1,1)) sage: t.light((10,-3,2), 1, (1,1,1)) sage: t.texture('black', color=(0,0,0)) sage: t.texture('red', color=(1,0,0)) sage: t.texture('grey', color=(.9,.9,.9)) sage: t.plane((0,0,0),(0,0,1),'grey') sage: t.cylinder((0,0,0),(1,0,0),.01,'black') sage: t.cylinder((0,0,0),(0,1,0),.01,'black') sage: E = EllipticCurve('37a'); show(E) sage: P = E([0,0]) sage: Q = P sage: n = 60 sage: 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) ... sage: show(t)
y^2 + y = x^3 - x
r UA# Worksheet '_scratch_' (2007-01-11 at 11:45) sage: f = sin(x^2) r U# Worksheet '_scratch_' (2007-01-11 at 11:45) sage: g = f.integrate(x); g Traceback (most recent call last): ... AttributeError: 'Function_composition' object has no attribute 'integrate'r U~# Worksheet '_scratch_' (2007-01-11 at 11:45) sage: g = f.integral(x); g Traceback (most recent call last): ... AssertionErrorr UT# Worksheet '_scratch_' (2007-01-11 at 11:45) sage: from sage.calculus.all import * r UA# Worksheet '_scratch_' (2007-01-11 at 11:45) sage: f = sin(x^2) rT# Worksheet '_scratch_' (2007-01-11 at 11:45) sage: g = f.integral(x); g Traceback (most recent call last): ... SyntaxError: invalid syntax (, line 1) Error using SAGE to evaluate 'sqrt(%pi)*((sqrt(Integer(2))*%i + sqrt(Integer(2)))*erf((sqrt(Integer(2))*%i + sqrt(Integer(2)))*x/Integer(2)) + (sqrt(Integer(2))*%i - sqrt(Integer(2)))*erf((sqrt(Integer(2))*%i - sqrt(Integer(2)))*x/Integer(2)))/Integer(8)'rUH# Worksheet '_scratch_' (2007-01-11 at 11:47) sage: I 1.00000000000000*IrT# Worksheet '_scratch_' (2007-01-11 at 11:48) sage: %hideall sage: #auto sage: sage: # The source code to draw factorization trees... sage: sage: import random sage: sage: def factor_tree(n, font=10): ... rows = [] ... v = [(n,None,0)] ... ftree(rows, v, 0, factor(n)) ... return draw_ftree(rows, font) ... sage: sage: def ftree(rows, v, i, F): ... if len(v) > 0: ... # add a row to g at the ith level. ... rows.append(v) ... w = [] ... for i in range(len(v)): ... k, _,_ = v[i] ... if k is None or is_prime(k): ... w.append((None,None,None)) ... else: ... d = random.choice(divisors(k)[1:-1]) ... w.append((d,k,i)) ... e = k//d ... if e == 1: ... w.append((None,None)) ... else: ... w.append((e,k,i)) ... if len(w) > len(v): ... ftree(rows, w, i+1, F) ... sage: sage: sage: def draw_ftree(rows,font): ... g = Graphics() ... for i in range(len(rows)): ... cur = rows[i] ... for j in range(len(cur)): ... e, f, k = cur[j] ... if not e is None: ... if is_prime(e): ... c = (1,0,0) ... else: ... c = (0,0,.4) ... g += text(str(e), (j*2-len(cur),-i), fontsize=font, rgbcolor=c) ... if not k is None and not f is None: ... g += line([(j*2-len(cur),-i), (k*2-len(rows[i-1]),-i+1)], alpha=0.4, thickness=1) ... return g ... sage: sage: def factor_trees(n, cols=4, rows=3, font=10): ... return graphics_array([[factor_tree(n,font) for _ in range(cols)] for _ in range(rows)]) CPU time: 0.00 s, Wall time: 0.00 srUT# Worksheet '_scratch_' (2007-01-11 at 11:48) sage: from sage.calculus.all import * rUA# Worksheet '_scratch_' (2007-01-11 at 11:48) sage: f = sin(x^2) rT# Worksheet '_scratch_' (2007-01-11 at 11:49) sage: %hideall sage: #auto sage: sage: # The source code to draw factorization trees... sage: sage: import random sage: sage: def factor_tree(n, font=10): ... rows = [] ... v = [(n,None,0)] ... ftree(rows, v, 0, factor(n)) ... return draw_ftree(rows, font) ... sage: sage: def ftree(rows, v, i, F): ... if len(v) > 0: ... # add a row to g at the ith level. ... rows.append(v) ... w = [] ... for i in range(len(v)): ... k, _,_ = v[i] ... if k is None or is_prime(k): ... w.append((None,None,None)) ... else: ... d = random.choice(divisors(k)[1:-1]) ... w.append((d,k,i)) ... e = k//d ... if e == 1: ... w.append((None,None)) ... else: ... w.append((e,k,i)) ... if len(w) > len(v): ... ftree(rows, w, i+1, F) ... sage: sage: sage: def draw_ftree(rows,font): ... g = Graphics() ... for i in range(len(rows)): ... cur = rows[i] ... for j in range(len(cur)): ... e, f, k = cur[j] ... if not e is None: ... if is_prime(e): ... c = (1,0,0) ... else: ... c = (0,0,.4) ... g += text(str(e), (j*2-len(cur),-i), fontsize=font, rgbcolor=c) ... if not k is None and not f is None: ... g += line([(j*2-len(cur),-i), (k*2-len(rows[i-1]),-i+1)], alpha=0.4, thickness=1) ... return g ... sage: sage: def factor_trees(n, cols=4, rows=3, font=10): ... return graphics_array([[factor_tree(n,font) for _ in range(cols)] for _ in range(rows)]) CPU time: 0.00 s, Wall time: 0.00 srUT# Worksheet '_scratch_' (2007-01-11 at 11:49) sage: from sage.calculus.all import * rUA# Worksheet '_scratch_' (2007-01-11 at 11:49) sage: f = sin(x^2) rU# Worksheet '_scratch_' (2007-01-11 at 11:49) sage: g = f.integral(x); g Traceback (most recent call last): ... ValueError: too many values to unpackrT# Worksheet '_scratch_' (2007-01-11 at 11:49) sage: %hideall sage: #auto sage: sage: # The source code to draw factorization trees... sage: sage: import random sage: sage: def factor_tree(n, font=10): ... rows = [] ... v = [(n,None,0)] ... ftree(rows, v, 0, factor(n)) ... return draw_ftree(rows, font) ... sage: sage: def ftree(rows, v, i, F): ... if len(v) > 0: ... # add a row to g at the ith level. ... rows.append(v) ... w = [] ... for i in range(len(v)): ... k, _,_ = v[i] ... if k is None or is_prime(k): ... w.append((None,None,None)) ... else: ... d = random.choice(divisors(k)[1:-1]) ... w.append((d,k,i)) ... e = k//d ... if e == 1: ... w.append((None,None)) ... else: ... w.append((e,k,i)) ... if len(w) > len(v): ... ftree(rows, w, i+1, F) ... sage: sage: sage: def draw_ftree(rows,font): ... g = Graphics() ... for i in range(len(rows)): ... cur = rows[i] ... for j in range(len(cur)): ... e, f, k = cur[j] ... if not e is None: ... if is_prime(e): ... c = (1,0,0) ... else: ... c = (0,0,.4) ... g += text(str(e), (j*2-len(cur),-i), fontsize=font, rgbcolor=c) ... if not k is None and not f is None: ... g += line([(j*2-len(cur),-i), (k*2-len(rows[i-1]),-i+1)], alpha=0.4, thickness=1) ... return g ... sage: sage: def factor_trees(n, cols=4, rows=3, font=10): ... return graphics_array([[factor_tree(n,font) for _ in range(cols)] for _ in range(rows)]) CPU time: 0.00 s, Wall time: 0.00 srUT# Worksheet '_scratch_' (2007-01-11 at 11:49) sage: from sage.calculus.all import * rUA# Worksheet '_scratch_' (2007-01-11 at 11:49) sage: f = sin(x^2) rT# Worksheet '_scratch_' (2007-01-11 at 11:49) sage: g = f.integral(x); g sqrt(_Pi_)*((sqrt(2)*_I_ + sqrt(2))*erf((sqrt(2)*_I_ + sqrt(2))*x/2) + (sqrt(2)*_I_ - sqrt(2))*erf((sqrt(2)*_I_ - sqrt(2))*x/2))/8 Traceback (most recent call last): File "", line 1, in File "/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/code/4.py", line 4, in exec compile(ur'g = f.integral(x); g' + '\n', '', 'single') File "/Users/was/talks/2007-01-11-uw-undergrads/", line 1, in ...rUM# Worksheet '_scratch_' (2007-01-11 at 11:50) sage: SER(I) 1.00000000000000*IrT# Worksheet '_scratch_' (2007-01-11 at 11:50) sage: %hideall sage: #auto sage: sage: # The source code to draw factorization trees... sage: sage: import random sage: sage: def factor_tree(n, font=10): ... rows = [] ... v = [(n,None,0)] ... ftree(rows, v, 0, factor(n)) ... return draw_ftree(rows, font) ... sage: sage: def ftree(rows, v, i, F): ... if len(v) > 0: ... # add a row to g at the ith level. ... rows.append(v) ... w = [] ... for i in range(len(v)): ... k, _,_ = v[i] ... if k is None or is_prime(k): ... w.append((None,None,None)) ... else: ... d = random.choice(divisors(k)[1:-1]) ... w.append((d,k,i)) ... e = k//d ... if e == 1: ... w.append((None,None)) ... else: ... w.append((e,k,i)) ... if len(w) > len(v): ... ftree(rows, w, i+1, F) ... sage: sage: sage: def draw_ftree(rows,font): ... g = Graphics() ... for i in range(len(rows)): ... cur = rows[i] ... for j in range(len(cur)): ... e, f, k = cur[j] ... if not e is None: ... if is_prime(e): ... c = (1,0,0) ... else: ... c = (0,0,.4) ... g += text(str(e), (j*2-len(cur),-i), fontsize=font, rgbcolor=c) ... if not k is None and not f is None: ... g += line([(j*2-len(cur),-i), (k*2-len(rows[i-1]),-i+1)], alpha=0.4, thickness=1) ... return g ... sage: sage: def factor_trees(n, cols=4, rows=3, font=10): ... return graphics_array([[factor_tree(n,font) for _ in range(cols)] for _ in range(rows)]) CPU time: 0.00 s, Wall time: 0.00 srUT# Worksheet '_scratch_' (2007-01-11 at 11:50) sage: from sage.calculus.all import * rUA# Worksheet '_scratch_' (2007-01-11 at 11:50) sage: f = sin(x^2) rT# Worksheet '_scratch_' (2007-01-11 at 11:50) sage: g = f.integral(x); g sqrt(_Pi_)*((sqrt(2)*_I_ + sqrt(2))*erf((sqrt(2)*_I_ + sqrt(2))*x/2) + (sqrt(2)*_I_ - sqrt(2))*erf((sqrt(2)*_I_ - sqrt(2))*x/2))/8 Traceback (most recent call last): File "", line 1, in File "/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/code/4.py", line 4, in exec compile(ur'g = f.integral(x); g' + '\n', '', 'single') File "/Users/was/talks/2007-01-11-uw-undergrads/", line 1, in ...r T# Worksheet '_scratch_' (2007-01-11 at 11:51) sage: %hideall sage: #auto sage: sage: # The source code to draw factorization trees... sage: sage: import random sage: sage: def factor_tree(n, font=10): ... rows = [] ... v = [(n,None,0)] ... ftree(rows, v, 0, factor(n)) ... return draw_ftree(rows, font) ... sage: sage: def ftree(rows, v, i, F): ... if len(v) > 0: ... # add a row to g at the ith level. ... rows.append(v) ... w = [] ... for i in range(len(v)): ... k, _,_ = v[i] ... if k is None or is_prime(k): ... w.append((None,None,None)) ... else: ... d = random.choice(divisors(k)[1:-1]) ... w.append((d,k,i)) ... e = k//d ... if e == 1: ... w.append((None,None)) ... else: ... w.append((e,k,i)) ... if len(w) > len(v): ... ftree(rows, w, i+1, F) ... sage: sage: sage: def draw_ftree(rows,font): ... g = Graphics() ... for i in range(len(rows)): ... cur = rows[i] ... for j in range(len(cur)): ... e, f, k = cur[j] ... if not e is None: ... if is_prime(e): ... c = (1,0,0) ... else: ... c = (0,0,.4) ... g += text(str(e), (j*2-len(cur),-i), fontsize=font, rgbcolor=c) ... if not k is None and not f is None: ... g += line([(j*2-len(cur),-i), (k*2-len(rows[i-1]),-i+1)], alpha=0.4, thickness=1) ... return g ... sage: sage: def factor_trees(n, cols=4, rows=3, font=10): ... return graphics_array([[factor_tree(n,font) for _ in range(cols)] for _ in range(rows)]) CPU time: 0.00 s, Wall time: 0.00 sr!UT# Worksheet '_scratch_' (2007-01-11 at 11:51) sage: from sage.calculus.all import * r"UA# Worksheet '_scratch_' (2007-01-11 at 11:51) sage: f = sin(x^2) r#T# Worksheet '_scratch_' (2007-01-11 at 11:51) sage: g = f.integral(x); g sqrt(_Pi_)*((sqrt(2)*_I_ + sqrt(2))*erf((sqrt(2)*_I_ + sqrt(2))*x/2) + (sqrt(2)*_I_ - sqrt(2))*erf((sqrt(2)*_I_ - sqrt(2))*x/2))/8 {'_I_': 1.00000000000000*I, 'cos': cos, '_Pi_': , 'sec': sec, 'x': x, '_E_': , 'sin': sin} Traceback (most recent call last): File "", line 1, in File "/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/code/4....r$UF# Worksheet '_scratch_' (2007-01-11 at 11:51) sage: f = sin(x)*cos(y) r%T# Worksheet '_scratch_' (2007-01-11 at 11:51) sage: g = f.integral(x); g -cos(x)*cos(y) {'_I_': 1.00000000000000*I, 'cos': cos, '_Pi_': , 'sec': sec, 'x': x, 'y': y, '_E_': , 'sin': sin} ((-1)*cos(x))*cos(y)r&Uh# Worksheet '_scratch_' (2007-01-11 at 11:52) sage: %maple sage: integrate(sin(x)*cos(x),x) 1/2*sin(x)^2r'Uk# Worksheet '_scratch_' (2007-01-11 at 11:52) sage: %maple sage: integrate(sin(x)*cos(x)^2,x) -1/3*cos(x)^3r(Ur# Worksheet '_scratch_' (2007-01-11 at 11:52) sage: %maple sage: integrate(sin(x)*cos(x)+1/x,x) 1/2*sin(x)^2+ln(x)r)UL# Worksheet '_scratch_' (2007-01-11 at 11:52) sage: f = sin(x)*cos(x) + 1/x r*T# Worksheet '_scratch_' (2007-01-11 at 11:52) sage: g = f.integral(x); g log(x) - cos(x)^2/2 {'_I_': 1.00000000000000*I, 'cos': cos, '_Pi_': , 'sec': sec, 'x': x, 'y': y, '_E_': , 'sin': sin} Traceback (most recent call last): File "", line 1, in File "/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/worksheets/_scratch_/code/11.py", line 4, in exec compile(ur'g = f.integral(x); g' + '\n', '', 'single') File "/User...r+T# Worksheet '_scratch_' (2007-01-11 at 11:53) sage: %hideall sage: #auto sage: sage: # The source code to draw factorization trees... sage: sage: import random sage: sage: def factor_tree(n, font=10): ... rows = [] ... v = [(n,None,0)] ... ftree(rows, v, 0, factor(n)) ... return draw_ftree(rows, font) ... sage: sage: def ftree(rows, v, i, F): ... if len(v) > 0: ... # add a row to g at the ith level. ... rows.append(v) ... w = [] ... for i in range(len(v)): ... k, _,_ = v[i] ... if k is None or is_prime(k): ... w.append((None,None,None)) ... else: ... d = random.choice(divisors(k)[1:-1]) ... w.append((d,k,i)) ... e = k//d ... if e == 1: ... w.append((None,None)) ... else: ... w.append((e,k,i)) ... if len(w) > len(v): ... ftree(rows, w, i+1, F) ... sage: sage: sage: def draw_ftree(rows,font): ... g = Graphics() ... for i in range(len(rows)): ... cur = rows[i] ... for j in range(len(cur)): ... e, f, k = cur[j] ... if not e is None: ... if is_prime(e): ... c = (1,0,0) ... else: ... c = (0,0,.4) ... g += text(str(e), (j*2-len(cur),-i), fontsize=font, rgbcolor=c) ... if not k is None and not f is None: ... g += line([(j*2-len(cur),-i), (k*2-len(rows[i-1]),-i+1)], alpha=0.4, thickness=1) ... return g ... sage: sage: def factor_trees(n, cols=4, rows=3, font=10): ... return graphics_array([[factor_tree(n,font) for _ in range(cols)] for _ in range(rows)]) CPU time: 0.00 s, Wall time: 0.00 sr,UT# Worksheet '_scratch_' (2007-01-11 at 11:53) sage: from sage.calculus.all import * r-UL# Worksheet '_scratch_' (2007-01-11 at 11:53) sage: f = sin(x)*cos(x) + 1/x r.U\# Worksheet '_scratch_' (2007-01-11 at 11:53) sage: g = f.integral(x); g log(x) - cos(x)^2/2r/U# Worksheet '_scratch_' (2007-01-11 at 11:53) sage: show(g)
\log \left( x \right) - \frac{\cos \left( x \right)^{2}}{2}
r0U# Worksheet '_scratch_' (2007-01-11 at 11:53) sage: f = sin(x)*cos(x) + 1/x; show(f)
\sin \left( x \right) \cdot \cos \left( x \right) + \frac{1}{x}
r1U# Worksheet '_scratch_' (2007-01-11 at 11:53) sage: g = f.integral(x); show(g)
\log \left( x \right) - \frac{\cos \left( x \right)^{2}}{2}
r2UJ# Worksheet '_scratch_' (2007-01-11 at 11:53) sage: f = sin(x+y)*cos(x+z) r3U# Worksheet '_scratch_' (2007-01-11 at 11:54) sage: f.trig_expand() (cos(x)*sin(y) + sin(x)*cos(y))*(cos(x)*cos(z) - sin(x)*sin(z))r4TG# Worksheet '_scratch_' (2007-01-11 at 11:54) sage: h = f.trig_expand(); show(h)
\cos \left( x \right) \cdot \sin \left( y \right) + \sin \left( x \right) \cdot \cos \left( y \right) \cdot \cos \left( x \right) \cdot \cos \left( z \right) - \sin \left( x \right) \cdot \sin \left( z \right)
r5U# Worksheet '_scratch_' (2007-01-11 at 11:54) sage: h.trig_simplify() ((((-1)*cos(x))*sin(x))*sin(y) - sin(x)^2*cos(y))*sin(z) + (cos(x)^2*sin(y) + cos(x)*sin(x)*cos(y))*cos(z)r6U# Worksheet '_scratch_' (2007-01-11 at 11:54) sage: f = sin(x+y)*cos(x+z); show(f)
\sin \left( x + y \right) \cdot \cos \left( x + z \right)
r7TG# Worksheet '_scratch_' (2007-01-11 at 11:54) sage: h = f.trig_expand(); show(h)
\cos \left( x \right) \cdot \sin \left( y \right) + \sin \left( x \right) \cdot \cos \left( y \right) \cdot \cos \left( x \right) \cdot \cos \left( z \right) - \sin \left( x \right) \cdot \sin \left( z \right)
r8U/# Worksheet '_scratch_' (2007-01-11 at 11:54) r9T# Worksheet '_scratch_' (2007-01-11 at 12:04) sage: %hideall sage: #auto sage: sage: # The source code to draw factorization trees... sage: sage: import random sage: sage: def factor_tree(n, font=10): ... rows = [] ... v = [(n,None,0)] ... ftree(rows, v, 0, factor(n)) ... return draw_ftree(rows, font) ... sage: sage: def ftree(rows, v, i, F): ... if len(v) > 0: ... # add a row to g at the ith level. ... rows.append(v) ... w = [] ... for i in range(len(v)): ... k, _,_ = v[i] ... if k is None or is_prime(k): ... w.append((None,None,None)) ... else: ... d = random.choice(divisors(k)[1:-1]) ... w.append((d,k,i)) ... e = k//d ... if e == 1: ... w.append((None,None)) ... else: ... w.append((e,k,i)) ... if len(w) > len(v): ... ftree(rows, w, i+1, F) ... sage: sage: sage: def draw_ftree(rows,font): ... g = Graphics() ... for i in range(len(rows)): ... cur = rows[i] ... for j in range(len(cur)): ... e, f, k = cur[j] ... if not e is None: ... if is_prime(e): ... c = (1,0,0) ... else: ... c = (0,0,.4) ... g += text(str(e), (j*2-len(cur),-i), fontsize=font, rgbcolor=c) ... if not k is None and not f is None: ... g += line([(j*2-len(cur),-i), (k*2-len(rows[i-1]),-i+1)], alpha=0.4, thickness=1) ... return g ... sage: sage: def factor_trees(n, cols=4, rows=3, font=10): ... return graphics_array([[factor_tree(n,font) for _ in range(cols)] for _ in range(rows)]) CPU time: 0.00 s, Wall time: 0.00 sr:T# Worksheet '_scratch_' (2007-01-11 at 12:04) sage: %hideall sage: #auto sage: sage: # The source code to draw factorization trees... sage: sage: import random sage: sage: def factor_tree(n, font=10): ... rows = [] ... v = [(n,None,0)] ... ftree(rows, v, 0, factor(n)) ... return draw_ftree(rows, font) ... sage: sage: def ftree(rows, v, i, F): ... if len(v) > 0: ... # add a row to g at the ith level. ... rows.append(v) ... w = [] ... for i in range(len(v)): ... k, _,_ = v[i] ... if k is None or is_prime(k): ... w.append((None,None,None)) ... else: ... d = random.choice(divisors(k)[1:-1]) ... w.append((d,k,i)) ... e = k//d ... if e == 1: ... w.append((None,None)) ... else: ... w.append((e,k,i)) ... if len(w) > len(v): ... ftree(rows, w, i+1, F) ... sage: sage: sage: def draw_ftree(rows,font): ... g = Graphics() ... for i in range(len(rows)): ... cur = rows[i] ... for j in range(len(cur)): ... e, f, k = cur[j] ... if not e is None: ... if is_prime(e): ... c = (1,0,0) ... else: ... c = (0,0,.4) ... g += text(str(e), (j*2-len(cur),-i), fontsize=font, rgbcolor=c) ... if not k is None and not f is None: ... g += line([(j*2-len(cur),-i), (k*2-len(rows[i-1]),-i+1)], alpha=0.4, thickness=1) ... return g ... sage: sage: def factor_trees(n, cols=4, rows=3, font=10): ... return graphics_array([[factor_tree(n,font) for _ in range(cols)] for _ in range(rows)]) CPU time: 0.00 s, Wall time: 0.00 sr;T# Worksheet '_scratch_' (2007-01-11 at 12:05) sage: %hideall sage: #auto sage: sage: # The source code to draw factorization trees... sage: sage: import random sage: sage: def factor_tree(n, font=10): ... rows = [] ... v = [(n,None,0)] ... ftree(rows, v, 0, factor(n)) ... return draw_ftree(rows, font) ... sage: sage: def ftree(rows, v, i, F): ... if len(v) > 0: ... # add a row to g at the ith level. ... rows.append(v) ... w = [] ... for i in range(len(v)): ... k, _,_ = v[i] ... if k is None or is_prime(k): ... w.append((None,None,None)) ... else: ... d = random.choice(divisors(k)[1:-1]) ... w.append((d,k,i)) ... e = k//d ... if e == 1: ... w.append((None,None)) ... else: ... w.append((e,k,i)) ... if len(w) > len(v): ... ftree(rows, w, i+1, F) ... sage: sage: sage: def draw_ftree(rows,font): ... g = Graphics() ... for i in range(len(rows)): ... cur = rows[i] ... for j in range(len(cur)): ... e, f, k = cur[j] ... if not e is None: ... if is_prime(e): ... c = (1,0,0) ... else: ... c = (0,0,.4) ... g += text(str(e), (j*2-len(cur),-i), fontsize=font, rgbcolor=c) ... if not k is None and not f is None: ... g += line([(j*2-len(cur),-i), (k*2-len(rows[i-1]),-i+1)], alpha=0.4, thickness=1) ... return g ... sage: sage: def factor_trees(n, cols=4, rows=3, font=10): ... return graphics_array([[factor_tree(n,font) for _ in range(cols)] for _ in range(rows)]) CPU time: 0.00 s, Wall time: 0.00 sr<Ur# Worksheet '_scratch_' (2007-01-11 at 12:05) sage: %maple sage: integrate(sin(x)*cos(x)+1/x,x) 1/2*sin(x)^2+ln(x)r=UR# Worksheet '_scratch_' (2007-01-11 at 12:05) sage: magma('Factorization(-2006)') r>UR# Worksheet '_scratch_' (2007-01-11 at 12:05) sage: magma('Factorization(-2006)') r?UR# Worksheet '_scratch_' (2007-01-11 at 12:06) sage: magma('Factorization(-2006)') r@T# Worksheet '_scratch_' (2007-01-11 at 12:06) sage: %hideall sage: #auto sage: sage: # The source code to draw factorization trees... sage: sage: import random sage: sage: def factor_tree(n, font=10): ... rows = [] ... v = [(n,None,0)] ... ftree(rows, v, 0, factor(n)) ... return draw_ftree(rows, font) ... sage: sage: def ftree(rows, v, i, F): ... if len(v) > 0: ... # add a row to g at the ith level. ... rows.append(v) ... w = [] ... for i in range(len(v)): ... k, _,_ = v[i] ... if k is None or is_prime(k): ... w.append((None,None,None)) ... else: ... d = random.choice(divisors(k)[1:-1]) ... w.append((d,k,i)) ... e = k//d ... if e == 1: ... w.append((None,None)) ... else: ... w.append((e,k,i)) ... if len(w) > len(v): ... ftree(rows, w, i+1, F) ... sage: sage: sage: def draw_ftree(rows,font): ... g = Graphics() ... for i in range(len(rows)): ... cur = rows[i] ... for j in range(len(cur)): ... e, f, k = cur[j] ... if not e is None: ... if is_prime(e): ... c = (1,0,0) ... else: ... c = (0,0,.4) ... g += text(str(e), (j*2-len(cur),-i), fontsize=font, rgbcolor=c) ... if not k is None and not f is None: ... g += line([(j*2-len(cur),-i), (k*2-len(rows[i-1]),-i+1)], alpha=0.4, thickness=1) ... return g ... sage: sage: def factor_trees(n, cols=4, rows=3, font=10): ... return graphics_array([[factor_tree(n,font) for _ in range(cols)] for _ in range(rows)]) CPU time: 0.00 s, Wall time: 0.00 srAUn# Worksheet '_scratch_' (2007-01-11 at 12:06) sage: magma('Factorization(-2006)') [ <2, 1>, <17, 1>, <59, 1> ]rBUr# Worksheet '_scratch_' (2007-01-11 at 12:06) sage: %maple sage: integrate(sin(x)*cos(x)+1/x,x) 1/2*sin(x)^2+ln(x)rCT# Worksheet '_scratch_' (2007-01-11 at 12:07) sage: %hideall sage: #auto sage: sage: # The source code to draw factorization trees... sage: sage: import random sage: sage: def factor_tree(n, font=10): ... rows = [] ... v = [(n,None,0)] ... ftree(rows, v, 0, factor(n)) ... return draw_ftree(rows, font) ... sage: sage: def ftree(rows, v, i, F): ... if len(v) > 0: ... # add a row to g at the ith level. ... rows.append(v) ... w = [] ... for i in range(len(v)): ... k, _,_ = v[i] ... if k is None or is_prime(k): ... w.append((None,None,None)) ... else: ... d = random.choice(divisors(k)[1:-1]) ... w.append((d,k,i)) ... e = k//d ... if e == 1: ... w.append((None,None)) ... else: ... w.append((e,k,i)) ... if len(w) > len(v): ... ftree(rows, w, i+1, F) ... sage: sage: sage: def draw_ftree(rows,font): ... g = Graphics() ... for i in range(len(rows)): ... cur = rows[i] ... for j in range(len(cur)): ... e, f, k = cur[j] ... if not e is None: ... if is_prime(e): ... c = (1,0,0) ... else: ... c = (0,0,.4) ... g += text(str(e), (j*2-len(cur),-i), fontsize=font, rgbcolor=c) ... if not k is None and not f is None: ... g += line([(j*2-len(cur),-i), (k*2-len(rows[i-1]),-i+1)], alpha=0.4, thickness=1) ... return g ... sage: sage: def factor_trees(n, cols=4, rows=3, font=10): ... return graphics_array([[factor_tree(n,font) for _ in range(cols)] for _ in range(rows)]) CPU time: 0.00 s, Wall time: 0.00 srDUr# Worksheet '_scratch_' (2007-01-11 at 12:07) sage: %maple sage: integrate(sin(x)*cos(x)+1/x,x) 1/2*sin(x)^2+ln(x)rET# Worksheet '_scratch_' (2007-01-11 at 13:10) sage: %hideall sage: #auto sage: sage: # The source code to draw factorization trees... sage: sage: import random sage: sage: def factor_tree(n, font=10): ... rows = [] ... v = [(n,None,0)] ... ftree(rows, v, 0, factor(n)) ... return draw_ftree(rows, font) ... sage: sage: def ftree(rows, v, i, F): ... if len(v) > 0: ... # add a row to g at the ith level. ... rows.append(v) ... w = [] ... for i in range(len(v)): ... k, _,_ = v[i] ... if k is None or is_prime(k): ... w.append((None,None,None)) ... else: ... d = random.choice(divisors(k)[1:-1]) ... w.append((d,k,i)) ... e = k//d ... if e == 1: ... w.append((None,None)) ... else: ... w.append((e,k,i)) ... if len(w) > len(v): ... ftree(rows, w, i+1, F) ... sage: sage: sage: def draw_ftree(rows,font): ... g = Graphics() ... for i in range(len(rows)): ... cur = rows[i] ... for j in range(len(cur)): ... e, f, k = cur[j] ... if not e is None: ... if is_prime(e): ... c = (1,0,0) ... else: ... c = (0,0,.4) ... g += text(str(e), (j*2-len(cur),-i), fontsize=font, rgbcolor=c) ... if not k is None and not f is None: ... g += line([(j*2-len(cur),-i), (k*2-len(rows[i-1]),-i+1)], alpha=0.4, thickness=1) ... return g ... sage: sage: def factor_trees(n, cols=4, rows=3, font=10): ... return graphics_array([[factor_tree(n,font) for _ in range(cols)] for _ in range(rows)]) CPU time: 0.00 s, Wall time: 0.00 srFU;# Worksheet '_scratch_' (2007-01-11 at 13:10) sage: 2 ^ 3 8rGUI# Worksheet '_scratch_' (2007-01-11 at 13:10) sage: %python sage: 2 ^ 3 1rHUr# Worksheet '_scratch_' (2007-01-11 at 13:10) sage: %maple sage: integrate(sin(x)*cos(x)+1/x,x) 1/2*sin(x)^2+ln(x)rIU# Worksheet '_scratch_' (2007-01-11 at 13:11) sage: m = matrix(5,5, range(25)); m [ 0 1 2 3 4] [ 5 6 7 8 9] [10 11 12 13 14] [15 16 17 18 19] [20 21 22 23 24]rJUE# Worksheet '_scratch_' (2007-01-11 at 13:11) sage: f = m.charpoly() rKUL# Worksheet '_scratch_' (2007-01-11 at 13:11) sage: f x^5 - 60*x^4 - 250*x^3rLU{# Worksheet '_scratch_' (2007-01-11 at 13:11) sage: show(f)
x^{5} - 60x^{4} - 250x^{3}
rMU# Worksheet '_scratch_' (2007-01-11 at 13:11) sage: show(factor(f))
(x^{2} - 60x - 250) \cdot x^{3}
rNU# Worksheet '_scratch_' (2007-01-11 at 13:11) sage: F = factor_trees(factorial(10), rows=1, cols=1, font=14) sage: F.show(axes=False, figsize=[10,6]) rOU# Worksheet '_scratch_' (2007-01-11 at 13:11) sage: F = factor_trees(factorial(10), rows=1, cols=1, font=14) sage: F.show(axes=False, figsize=[10,6]) rPT# Worksheet '_scratch_' (2007-01-11 at 13:12) sage: t = Tachyon(xres=700, yres=500, camera_center=(2,7,4), look_at=(2,0,0), raydepth=4) sage: t.light((10,3,2), 1, (1,1,1)) sage: t.light((10,-3,2), 1, (1,1,1)) sage: t.texture('black', color=(0,0,0)) sage: t.texture('red', color=(1,0,0)) sage: t.texture('grey', color=(.9,.9,.9)) sage: t.plane((0,0,0),(0,0,1),'grey') sage: t.cylinder((0,0,0),(1,0,0),.01,'black') sage: t.cylinder((0,0,0),(0,1,0),.01,'black') sage: E = EllipticCurve('37a'); show(E) sage: P = E([0,0]) sage: Q = P sage: n = 60 sage: 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) ... sage: show(t)
y^2 + y = x^3 - x
rQUT# Worksheet '_scratch_' (2007-01-11 at 13:13) sage: from sage.calculus.all import * rRU# Worksheet '_scratch_' (2007-01-11 at 13:13) sage: f = sin(x)*cos(x) + 1/x; show(f)
\sin \left( x \right) \cdot \cos \left( x \right) + \frac{1}{x}
rSU# Worksheet '_scratch_' (2007-01-11 at 13:13) sage: g = f.integral(x); show(g)
\log \left( x \right) - \frac{\cos \left( x \right)^{2}}{2}
rTU# Worksheet '_scratch_' (2007-01-11 at 13:13) sage: f = sin(x+y)*cos(x+z); show(f)
\sin \left( x + y \right) \cdot \cos \left( x + z \right)
rUTG# Worksheet '_scratch_' (2007-01-11 at 13:13) sage: h = f.trig_expand(); show(h)
\cos \left( x \right) \cdot \sin \left( y \right) + \sin \left( x \right) \cdot \cos \left( y \right) \cdot \cos \left( x \right) \cdot \cos \left( z \right) - \sin \left( x \right) \cdot \sin \left( z \right)
rVU# Worksheet '_scratch_' (2007-01-11 at 13:15) sage: for i in range(10): ... print "hello world ", i hello world 0 hello world 1 hello world 2 hello world 3 hello world 4 hello world 5 hello world 6 hello world 7 hello world 8 hello world 9rWT# Worksheet '_scratch_' (2007-01-11 at 13:17) sage: t = Tachyon(xres=800,yres=800, camera_center=(2,5,2), look_at=(2.5,0,0)) sage: t.light((0,0,100), 1, (1,1,1)) sage: t.texture('r', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(1,0,0)) sage: for i in srange(0,50,0.1): ... t.sphere((i/10,sin(i),cos(i)), 0.05, 'r') ... sage: t.texture('white', color=(1,1,1), opacity=1, specular=1, diffuse=1) sage: t.plane((0,0,-100), (0,0,-100), 'white') sage: t.save('sage.png') Traceback (most recent call last): ... TypeError: float() argument must be a string or a numberrXT# Worksheet '_scratch_' (2007-01-11 at 13:18) sage: %hideall sage: #auto sage: sage: # The source code to draw factorization trees... sage: sage: import random sage: sage: def factor_tree(n, font=10): ... rows = [] ... v = [(n,None,0)] ... ftree(rows, v, 0, factor(n)) ... return draw_ftree(rows, font) ... sage: sage: def ftree(rows, v, i, F): ... if len(v) > 0: ... # add a row to g at the ith level. ... rows.append(v) ... w = [] ... for i in range(len(v)): ... k, _,_ = v[i] ... if k is None or is_prime(k): ... w.append((None,None,None)) ... else: ... d = random.choice(divisors(k)[1:-1]) ... w.append((d,k,i)) ... e = k//d ... if e == 1: ... w.append((None,None)) ... else: ... w.append((e,k,i)) ... if len(w) > len(v): ... ftree(rows, w, i+1, F) ... sage: sage: sage: def draw_ftree(rows,font): ... g = Graphics() ... for i in range(len(rows)): ... cur = rows[i] ... for j in range(len(cur)): ... e, f, k = cur[j] ... if not e is None: ... if is_prime(e): ... c = (1,0,0) ... else: ... c = (0,0,.4) ... g += text(str(e), (j*2-len(cur),-i), fontsize=font, rgbcolor=c) ... if not k is None and not f is None: ... g += line([(j*2-len(cur),-i), (k*2-len(rows[i-1]),-i+1)], alpha=0.4, thickness=1) ... return g ... sage: sage: def factor_trees(n, cols=4, rows=3, font=10): ... return graphics_array([[factor_tree(n,font) for _ in range(cols)] for _ in range(rows)]) CPU time: 0.00 s, Wall time: 0.00 srYT## Worksheet '_scratch_' (2007-01-11 at 13:18) sage: t = Tachyon(xres=800,yres=800, camera_center=(2,5,2), look_at=(2.5,0,0)) sage: t.light((0,0,100), 1, (1,1,1)) sage: t.texture('r', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(1,0,0)) sage: for i in srange(0,50,0.1): ... t.sphere((i/10,sin(i),cos(i)), 0.05, 'r') ... sage: t.texture('white', color=(1,1,1), opacity=1, specular=1, diffuse=1) sage: t.plane((0,0,-100), (0,0,-100), 'white') sage: t.save('sage.png') rZUT# Worksheet '_scratch_' (2007-01-11 at 13:26) sage: from sage.calculus.all import * r[U# Worksheet '_scratch_' (2007-01-11 at 13:26) sage: f = sin(x)*cos(x) + 1/x; show(f)
\sin \left( x \right) \cdot \cos \left( x \right) + \frac{1}{x}
r\eU_Notebook__defaultsr]}r^(Ucell_output_colorr_U#0000EEr`Umax_history_lengthraMUcell_input_colorrbU#0000000rcUword_wrap_colsrdKPuU_Notebook__worksheet_dirreUsage_notebook/worksheetsrfU_Notebook__history_countrgKU_Notebook__log_serverrhU_Notebook__filenameriUsage_notebook/nb.sobjrjU_Notebook__default_worksheetrkhU_Notebook__server_logrl]rmU_Notebook__next_worksheet_idrnKU_Notebook__kill_idleroKU_Notebook__systemrpNU_Notebook__show_debugrqU_Notebook__dirrrU sage_notebookrsU_Notebook__authrtU:U_Notebook__colorruNU_Notebook__object_dirrvUsage_notebook/objectsrwU_default_filenamerxU?/Users/was/talks/2007-01-11-uw-undergrads/sage_notebook/nb.sobjryU_Notebook__splashpagerzub.