This is pdfTeX, Version 3.1415926-1.40.11 (TeX Live 2010) (format=pdflatex 2010.7.21)  28 MAY 2011 21:38
entering extended mode
 restricted \write18 enabled.
 %&-line parsing enabled.
**sagebook
(./sagebook.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, dumylang, nohyphenation, ge
rman-x-2009-06-19, ngerman-x-2009-06-19, ancientgreek, ibycus, arabic, armenian
, basque, bulgarian, catalan, pinyin, coptic, croatian, czech, danish, dutch, u
kenglish, usenglishmax, esperanto, estonian, farsi, finnish, french, galician, 
german, ngerman, swissgerman, monogreek, greek, hungarian, icelandic, assamese,
 bengali, gujarati, hindi, kannada, malayalam, marathi, oriya, panjabi, tamil, 
telugu, indonesian, interlingua, irish, italian, kurmanji, lao, latin, latvian,
 lithuanian, mongolian, mongolianlmc, bokmal, nynorsk, polish, portuguese, roma
nian, russian, sanskrit, serbian, slovak, slovenian, spanish, swedish, turkish,
 turkmen, ukrainian, uppersorbian, welsh, loaded.
(/usr/local/texlive/2010/texmf-dist/tex/latex/base/report.cls
Document Class: report 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2010/texmf-dist/tex/latex/base/size10.clo
File: size10.clo 2007/10/19 v1.4h Standard LaTeX file (size option)
)
\c@part=\count79
\c@chapter=\count80
\c@section=\count81
\c@subsection=\count82
\c@subsubsection=\count83
\c@paragraph=\count84
\c@subparagraph=\count85
\c@figure=\count86
\c@table=\count87
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
)
\@input{macros.aux}
\openout2 = `macros.aux'.

(./macros.tex (/usr/local/texlive/2010/texmf-dist/tex/latex/amsmath/amsmath.sty
Package: amsmath 2000/07/18 v2.13 AMS math features
\@mathmargin=\skip43
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2010/texmf-dist/tex/latex/amsmath/amstext.sty
Package: amstext 2000/06/29 v2.01

(/usr/local/texlive/2010/texmf-dist/tex/latex/amsmath/amsgen.sty
File: amsgen.sty 1999/11/30 v2.0
\@emptytoks=\toks14
\ex@=\dimen103
))
(/usr/local/texlive/2010/texmf-dist/tex/latex/amsmath/amsbsy.sty
Package: amsbsy 1999/11/29 v1.2d
\pmbraise@=\dimen104
)
(/usr/local/texlive/2010/texmf-dist/tex/latex/amsmath/amsopn.sty
Package: amsopn 1999/12/14 v2.01 operator names
)
\inf@bad=\count88
LaTeX Info: Redefining \frac on input line 211.
\uproot@=\count89
\leftroot@=\count90
LaTeX Info: Redefining \overline on input line 307.
\classnum@=\count91
\DOTSCASE@=\count92
LaTeX Info: Redefining \ldots on input line 379.
LaTeX Info: Redefining \dots on input line 382.
LaTeX Info: Redefining \cdots on input line 467.
\Mathstrutbox@=\box26
\strutbox@=\box27
\big@size=\dimen105
LaTeX Font Info:    Redeclaring font encoding OML on input line 567.
LaTeX Font Info:    Redeclaring font encoding OMS on input line 568.
\macc@depth=\count93
\c@MaxMatrixCols=\count94
\dotsspace@=\muskip10
\c@parentequation=\count95
\dspbrk@lvl=\count96
\tag@help=\toks15
\row@=\count97
\column@=\count98
\maxfields@=\count99
\andhelp@=\toks16
\eqnshift@=\dimen106
\alignsep@=\dimen107
\tagshift@=\dimen108
\tagwidth@=\dimen109
\totwidth@=\dimen110
\lineht@=\dimen111
\@envbody=\toks17
\multlinegap=\skip44
\multlinetaggap=\skip45
\mathdisplay@stack=\toks18
LaTeX Info: Redefining \[ on input line 2666.
LaTeX Info: Redefining \] on input line 2667.
)
(/usr/local/texlive/2010/texmf-dist/tex/latex/amsfonts/amsfonts.sty
Package: amsfonts 2009/06/22 v3.00 Basic AMSFonts support
\symAMSa=\mathgroup4
\symAMSb=\mathgroup5
LaTeX Font Info:    Overwriting math alphabet `\mathfrak' in version `bold'
(Font)                  U/euf/m/n --> U/euf/b/n on input line 96.
)
(/usr/local/texlive/2010/texmf-dist/tex/latex/amsfonts/amssymb.sty
Package: amssymb 2009/06/22 v3.00
)
(/usr/local/texlive/2010/texmf-dist/tex/latex/amscls/amsthm.sty
Package: amsthm 2004/08/06 v2.20
\thm@style=\toks19
\thm@bodyfont=\toks20
\thm@headfont=\toks21
\thm@notefont=\toks22
\thm@headpunct=\toks23
\thm@preskip=\skip46
\thm@postskip=\skip47
\thm@headsep=\skip48
\dth@everypar=\toks24
)
(/usr/local/texlive/2010/texmf-dist/tex/latex/url/url.sty
\Urlmuskip=\muskip11
Package: url 2006/04/12  ver 3.3  Verb mode for urls, etc.
)
(/usr/local/texlive/2010/texmf-dist/tex/latex/tools/xspace.sty
Package: xspace 2006/05/08 v1.12 Space after command names (DPC,MH)
)
\c@theorem=\count100
\c@listnum=\count101

(/usr/local/texlive/2010/texmf-dist/tex/latex/graphics/color.sty
Package: color 2005/11/14 v1.0j Standard LaTeX Color (DPC)

(/usr/local/texlive/2010/texmf-dist/tex/latex/latexconfig/color.cfg
File: color.cfg 2007/01/18 v1.5 color configuration of teTeX/TeXLive
)
Package color Info: Driver file: pdftex.def on input line 130.

(/usr/local/texlive/2010/texmf-dist/tex/latex/pdftex-def/pdftex.def
File: pdftex.def 2010/02/14 v0.04n Graphics/color for pdfTeX
\Gread@gobject=\count102
))
(/usr/local/texlive/2010/texmf-dist/tex/latex/listings/listings.sty
(/usr/local/texlive/2010/texmf-dist/tex/latex/graphics/keyval.sty
Package: keyval 1999/03/16 v1.13 key=value parser (DPC)
\KV@toks@=\toks25
)
\lst@mode=\count103
\lst@gtempboxa=\box28
\lst@token=\toks26
\lst@length=\count104
\lst@currlwidth=\dimen112
\lst@column=\count105
\lst@pos=\count106
\lst@lostspace=\dimen113
\lst@width=\dimen114
\lst@newlines=\count107
\lst@lineno=\count108
\lst@maxwidth=\dimen115

(/usr/local/texlive/2010/texmf-dist/tex/latex/listings/lstmisc.sty
File: lstmisc.sty 2007/02/22 1.4 (Carsten Heinz)
\c@lstnumber=\count109
\lst@skipnumbers=\count110
\lst@framebox=\box29
)
(/usr/local/texlive/2010/texmf-dist/tex/latex/listings/listings.cfg
File: listings.cfg 2007/02/22 1.4 listings configuration
))
Package: listings 2007/02/22 1.4 (Carsten Heinz)

(/usr/local/texlive/2010/texmf-dist/tex/latex/listings/lstlang1.sty
File: lstlang1.sty 2004/09/05 1.3 listings language file
))
(/usr/local/texlive/2010/texmf-dist/tex/latex/pdfsync/pdfsync.sty
Package: pdfsync 2008/01/26 v1.1
)
(/usr/local/texlive/2010/texmf-dist/tex/latex/hyperref/hyperref.sty
Package: hyperref 2010/06/18 v6.81g Hypertext links for LaTeX

(/usr/local/texlive/2010/texmf-dist/tex/generic/oberdiek/ltxcmds.sty
Package: ltxcmds 2010/04/26 v1.7 LaTeX kernel commands for general use (HO)
)
(/usr/local/texlive/2010/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
Package: kvsetkeys 2010/03/01 v1.9 Key value parser (HO)

(/usr/local/texlive/2010/texmf-dist/tex/generic/oberdiek/infwarerr.sty
Package: infwarerr 2010/04/08 v1.3 Providing info/warning/message (HO)
)
(/usr/local/texlive/2010/texmf-dist/tex/generic/oberdiek/etexcmds.sty
Package: etexcmds 2010/01/28 v1.3 Prefix for e-TeX command names (HO)
Package etexcmds Info: Could not find \expanded.
(etexcmds)             That can mean that you are not using pdfTeX 1.50 or
(etexcmds)             that some package has redefined \expanded.
(etexcmds)             In the latter case, load this package earlier.
))
(/usr/local/texlive/2010/texmf-dist/tex/generic/oberdiek/pdfescape.sty
Package: pdfescape 2010/03/01 v1.9 Provides hex, PDF name and string conversion
s (HO)

(/usr/local/texlive/2010/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty
Package: pdftexcmds 2010/04/01 v0.9 Utility functions of pdfTeX for LuaTeX (HO)


(/usr/local/texlive/2010/texmf-dist/tex/generic/oberdiek/ifluatex.sty
Package: ifluatex 2010/03/01 v1.3 Provides the ifluatex switch (HO)
Package ifluatex Info: LuaTeX not detected.
)
Package pdftexcmds Info: LuaTeX not detected.
Package pdftexcmds Info: \pdf@primitive is available.
Package pdftexcmds Info: \pdf@ifprimitive is available.
))
(/usr/local/texlive/2010/texmf-dist/tex/generic/oberdiek/ifpdf.sty
Package: ifpdf 2010/01/28 v2.1 Provides the ifpdf switch (HO)
Package ifpdf Info: pdfTeX in pdf mode detected.
)
(/usr/local/texlive/2010/texmf-dist/tex/generic/oberdiek/ifvtex.sty
Package: ifvtex 2010/03/01 v1.5 Switches for detecting VTeX and its modes (HO)
Package ifvtex Info: VTeX not detected.
)
(/usr/local/texlive/2010/texmf-dist/tex/generic/ifxetex/ifxetex.sty
Package: ifxetex 2009/01/23 v0.5 Provides ifxetex conditional
)
(/usr/local/texlive/2010/texmf-dist/tex/latex/oberdiek/hycolor.sty
Package: hycolor 2009/12/12 v1.6 Color options of hyperref/bookmark (HO)

(/usr/local/texlive/2010/texmf-dist/tex/latex/oberdiek/xcolor-patch.sty
Package: xcolor-patch 2009/12/12 xcolor patch
))
(/usr/local/texlive/2010/texmf-dist/tex/latex/oberdiek/letltxmacro.sty
Package: letltxmacro 2008/06/24 v1.3 Let assignment for LaTeX macros (HO)
)
\@linkdim=\dimen116
\Hy@linkcounter=\count111
\Hy@pagecounter=\count112

(/usr/local/texlive/2010/texmf-dist/tex/latex/hyperref/pd1enc.def
File: pd1enc.def 2010/06/18 v6.81g Hyperref: PDFDocEncoding definition (HO)
)
(/usr/local/texlive/2010/texmf-dist/tex/generic/oberdiek/intcalc.sty
Package: intcalc 2007/09/27 v1.1 Expandable integer calculations (HO)
)
(/usr/local/texlive/2010/texmf-dist/tex/latex/latexconfig/hyperref.cfg
File: hyperref.cfg 2002/06/06 v1.2 hyperref configuration of TeXLive
)
(/usr/local/texlive/2010/texmf-dist/tex/latex/oberdiek/kvoptions.sty
Package: kvoptions 2010/02/22 v3.7 Keyval support for LaTeX options (HO)
)
Package hyperref Info: Hyper figures OFF on input line 3658.
Package hyperref Info: Link nesting OFF on input line 3663.
Package hyperref Info: Hyper index ON on input line 3666.
Package hyperref Info: Plain pages OFF on input line 3673.
Package hyperref Info: Backreferencing OFF on input line 3678.

Implicit mode ON; LaTeX internals redefined
Package hyperref Info: Bookmarks ON on input line 3874.
LaTeX Info: Redefining \url on input line 4159.
(/usr/local/texlive/2010/texmf-dist/tex/generic/oberdiek/bitset.sty
Package: bitset 2007/09/28 v1.0 Data type bit set (HO)

(/usr/local/texlive/2010/texmf-dist/tex/generic/oberdiek/bigintcalc.sty
Package: bigintcalc 2007/11/11 v1.1 Expandable big integer calculations (HO)
))
\Fld@menulength=\count113
\Field@Width=\dimen117
\Fld@charsize=\dimen118
\Field@toks=\toks27
Package hyperref Info: Hyper figures OFF on input line 5137.
Package hyperref Info: Link nesting OFF on input line 5142.
Package hyperref Info: Hyper index ON on input line 5145.
Package hyperref Info: backreferencing OFF on input line 5152.
Package hyperref Info: Link coloring OFF on input line 5157.
Package hyperref Info: Link coloring with OCG OFF on input line 5162.
Package hyperref Info: PDF/A mode OFF on input line 5167.
LaTeX Info: Redefining \ref on input line 5207.
LaTeX Info: Redefining \pageref on input line 5211.

(/usr/local/texlive/2010/texmf-dist/tex/generic/oberdiek/atbegshi.sty
Package: atbegshi 2010/03/25 v1.12 At begin shipout hook (HO)
)
\Hy@abspage=\count114
\c@Item=\count115
\c@Hfootnote=\count116
)

Package hyperref Warning: Wrong driver `hypertex.def';
(hyperref)                pdfTeX is running in PDF mode.
(hyperref)                Forcing driver `hpdftex.def'.

* hyperref using driver hpdftex *
(/usr/local/texlive/2010/texmf-dist/tex/latex/hyperref/hpdftex.def
File: hpdftex.def 2010/06/18 v6.81g Hyperref driver for pdfTeX

(/usr/local/texlive/2010/texmf-dist/tex/latex/oberdiek/atveryend.sty
Package: atveryend 2010/03/24 v1.5 Hooks at very end of document (HO)
Package atveryend Info: \enddocument detected (standard).
)
\Fld@listcount=\count117
\c@bookmark@seq@number=\count118

(/usr/local/texlive/2010/texmf-dist/tex/latex/oberdiek/rerunfilecheck.sty
Package: rerunfilecheck 2010/03/16 v1.6 Rerun checks for auxiliary files (HO)

(/usr/local/texlive/2010/texmf-dist/tex/generic/oberdiek/uniquecounter.sty
Package: uniquecounter 2009/12/18 v1.1 Provides unlimited unique counter (HO)
)
Package uniquecounter Info: New unique counter `rerunfilecheck' on input line 2
71.
)
\Hy@SectionHShift=\skip49
)
(/usr/local/texlive/2010/texmf-dist/tex/latex/graphics/graphicx.sty
Package: graphicx 1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR)

(/usr/local/texlive/2010/texmf-dist/tex/latex/graphics/graphics.sty
Package: graphics 2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR)

(/usr/local/texlive/2010/texmf-dist/tex/latex/graphics/trig.sty
Package: trig 1999/03/16 v1.09 sin cos tan (DPC)
)
(/usr/local/texlive/2010/texmf-dist/tex/latex/latexconfig/graphics.cfg
File: graphics.cfg 2010/04/23 v1.9 graphics configuration of TeX Live
)
Package graphics Info: Driver file: pdftex.def on input line 91.
)
\Gin@req@height=\dimen119
\Gin@req@width=\dimen120
)
(./sagebook.aux)
\openout1 = `sagebook.aux'.

LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 27.
LaTeX Font Info:    ... okay on input line 27.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 27.
LaTeX Font Info:    ... okay on input line 27.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 27.
LaTeX Font Info:    ... okay on input line 27.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 27.
LaTeX Font Info:    ... okay on input line 27.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 27.
LaTeX Font Info:    ... okay on input line 27.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 27.
LaTeX Font Info:    ... okay on input line 27.
LaTeX Font Info:    Checking defaults for OT2/cmr/m/n on input line 27.
LaTeX Font Info:    Try loading font information for OT2+cmr on input line 27.

(/usr/local/texlive/2010/texmf-dist/tex/latex/cyrillic/ot2cmr.fd
File: ot2cmr.fd 2001/08/11 v3.2c Computer Modern Cyrillic font definitions
)
LaTeX Font Info:    ... okay on input line 27.
LaTeX Font Info:    Checking defaults for PD1/pdf/m/n on input line 27.
LaTeX Font Info:    ... okay on input line 27.

(/usr/local/texlive/2010/texmf-dist/tex/context/base/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
\scratchcounter=\count119
\scratchdimen=\dimen121
\scratchbox=\box30
\nofMPsegments=\count120
\nofMParguments=\count121
\everyMPshowfont=\toks28
\MPscratchCnt=\count122
\MPscratchDim=\dimen122
\MPnumerator=\count123
\everyMPtoPDFconversion=\toks29
)
\c@lstlisting=\count124
Configuring pdfsync
\PDFSYNC@ut=\write3
\openout3 = `sagebook.pdfsync'.

\PDFSYNCf@li@=\count125
\PDFSYNC@rder=\count126
**** pdfsync.sty: Synchronizing at \everypar
\PDFSYNCeveryp@r=\toks30
**** pdfsync.sty: Synchronizing at \everymath
\PDFSYNCeverym@th=\toks31
**** pdfsync.sty: Synchronizing at \everyhbox
\PDFSYNCeveryhb@x=\toks32
**** pdfsync.sty: Synchronizing at \everyvbox
\PDFSYNCeveryvb@x=\toks33
**** pdfsync.sty: started
\AtBeginShipoutBox=\box31
Package hyperref Info: Link coloring OFF on input line 27.
 (/usr/local/texlive/2010/texmf-dist/tex/latex/hyperref/nameref.sty
Package: nameref 2010/04/30 v2.40 Cross-referencing by name of section

(/usr/local/texlive/2010/texmf-dist/tex/latex/oberdiek/refcount.sty
Package: refcount 2008/08/11 v3.1 Data extraction from references (HO)
)
(/usr/local/texlive/2010/texmf-dist/tex/generic/oberdiek/gettitlestring.sty
Package: gettitlestring 2009/12/18 v1.3 Cleanup title references (HO)
)
\c@section@level=\count127
)
LaTeX Info: Redefining \ref on input line 27.
LaTeX Info: Redefining \pageref on input line 27.
LaTeX Info: Redefining \nameref on input line 27.

(./sagebook.out) (./sagebook.out)
\@outlinefile=\write4
\openout4 = `sagebook.out'.


(/usr/local/texlive/2010/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty
Package: epstopdf-base 2010/02/09 v2.5 Base part for package epstopdf

(/usr/local/texlive/2010/texmf-dist/tex/latex/oberdiek/grfext.sty
Package: grfext 2007/09/30 v1.0 Managing graphics extensions (HO)
)
Package grfext Info: Graphics extension search list:
(grfext)             [.png,.pdf,.jpg,.mps,.jpeg,.jbig2,.jb2,.PNG,.PDF,.JPG,.JPE
G,.JBIG2,.JB2,.eps]
(grfext)             \AppendGraphicsExtensions on input line 436.

(/usr/local/texlive/2010/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg
File: epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Liv
e
))
LaTeX Font Info:    Try loading font information for U+msa on input line 31.

(/usr/local/texlive/2010/texmf-dist/tex/latex/amsfonts/umsa.fd
File: umsa.fd 2009/06/22 v3.00 AMS symbols A
)
LaTeX Font Info:    Try loading font information for U+msb on input line 31.

(/usr/local/texlive/2010/texmf-dist/tex/latex/amsfonts/umsb.fd
File: umsb.fd 2009/06/22 v3.00 AMS symbols B
) [1



{/usr/local/texlive/2010/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] (./sage
book.tocpdfTeX warning (ext4): destination with the same identifier (name{page.
1}) has been already used, duplicate ignored
<to be read again> 
                   \relax 
l.37 ...Types and Functions}{45}{subsection.3.3.3}
                                                   [1

] [2])
\tf@toc=\write5
\openout5 = `sagebook.toc'.

 [3]
Chapter 1.

Overfull \hbox (1.13757pt too wide) in paragraph at lines 63--71
[][][]\OT1/cmr/m/n/10 Sage uses a main-stream pro-gram-ming lan-guage, un-like 
Maple, Math-e-mat-ica, Magma,
 []

[4

]
LaTeX Font Info:    Try loading font information for OMS+cmr on input line 107.

 (/usr/local/texlive/2010/texmf-dist/tex/latex/base/omscmr.fd
File: omscmr.fd 1999/05/25 v2.5h Standard LaTeX font definitions
)
LaTeX Font Info:    Font shape `OMS/cmr/m/n' in size <10> not available
(Font)              Font shape `OMS/cmsy/m/n' tried instead on input line 107.
 [5]
Overfull \hbox (6.92914pt too wide) in paragraph at lines 156--156
[][][]\OT1/cmr/bx/n/14.4 ``This unique Amer-i-can idea of the en-trepreneurial
 []

[6]

LaTeX Warning: Reference `ch:profdeb' on page 7 undefined on input line 230.


LaTeX Warning: Reference `ch:contrib' on page 7 undefined on input line 231.

LaTeX Font Info:    Font shape `OT1/cmtt/bx/n' in size <9> not available
(Font)              Font shape `OT1/cmtt/m/n' tried instead on input line 251.
[7] <graphics/plot1.pdf, id=481, 366.28622pt x 228.84752pt>
File: graphics/plot1.pdf Graphic file (type pdf)

<use graphics/plot1.pdf> [8 <./graphics/plot1.pdf>]
Overfull \hbox (0.38675pt too wide) in paragraph at lines 331--332
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][][][][][][][][][][][][][][] 
 []

[9] [10

]
Chapter 2.
[11

] [12]
Overfull \hbox (17.3967pt too wide) in paragraph at lines 481--482
[][][][][][] 
 []


Overfull \hbox (11.72672pt too wide) in paragraph at lines 482--483
[][][][][][][][][][][][][][][][][][][][][]
 []


Overfull \hbox (11.72672pt too wide) in paragraph at lines 483--484
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
 []


Overfull \hbox (17.3967pt too wide) in paragraph at lines 484--485
[][][][][][] 
 []

[13] [14] [15] [16] [17]
<graphics/3dplot1.png, id=770, 440.64626pt x 332.24126pt>
File: graphics/3dplot1.png Graphic file (type png)

<use graphics/3dplot1.png> [18 <./graphics/3dplot1.png (PNG copy)>] [19]
[20]
Overfull \hbox (11.72672pt too wide) in paragraph at lines 954--955
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] 
 []


Overfull \hbox (0.38675pt too wide) in paragraph at lines 961--962
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] 
 []

[21] [22] [23]
Overfull \hbox (51.4166pt too wide) in paragraph at lines 1172--1173
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] 
 []

[24]
Overfull \hbox (130.79636pt too wide) in paragraph at lines 1230--1231
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][] 
 []

[25] [26] [27]
Overfull \hbox (29.99432pt too wide) in paragraph at lines 1463--1469
\OT1/cmtt/m/n/10 ArithmeticError, ValueError, RuntimeError, NotImplementedError
, OverflowError,
 []

[28]
Overfull \hbox (57.08658pt too wide) in paragraph at lines 1474--1475
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] 
 []


Overfull \hbox (34.40665pt too wide) in paragraph at lines 1486--1487
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] 
 []


Overfull \hbox (40.07663pt too wide) in paragraph at lines 1490--1491
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] 
 []

[29]
Overfull \hbox (0.38675pt too wide) in paragraph at lines 1527--1528
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][] 
 []


Overfull \hbox (68.42654pt too wide) in paragraph at lines 1544--1545
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][] 
 []


Overfull \hbox (28.73666pt too wide) in paragraph at lines 1576--1577
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] 
 []

[30] [31] <graphics/interact.png, id=1263, 1030.85126pt x 330.23375pt>
File: graphics/interact.png Graphic file (type png)

<use graphics/interact.png> [32 <./graphics/interact.png (PNG copy)>] [33]
[34] [35] [36]
Overfull \hbox (1.83188pt too wide) in paragraph at lines 1948--1951
[][][]\OT1/cmr/m/n/10 For more in-for-ma-tion about how the Python source code 
is laid out, see the README
 []

[37]
Chapter 3.

Overfull \hbox (0.38675pt too wide) in paragraph at lines 1970--1971
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][] 
 []

[38

]
Missing character: There is no Â in font cmtt9!
Missing character: There is no µ in font cmtt9!
 [39] [40] [41]
Overfull \hbox (28.73666pt too wide) in paragraph at lines 2227--2228
[][][][][][][][][][][][][][] 
 []

Missing character: There is no Â in font cmtt9!
Missing character: There is no µ in font cmtt9!
Missing character: There is no Â in font cmtt9!
Missing character: There is no µ in font cmtt9!
Missing character: There is no Â in font cmtt9!
Missing character: There is no µ in font cmtt9!
[42] [43]
Overfull \hbox (10.69199pt too wide) in paragraph at lines 2323--2327
[][][]\OT1/cmr/m/n/10 For the Cython source code of Sage in-te-gers, in the Sag
e li-brary see []\OT1/cmtt/m/n/10 rings/integer.pxd
 []

[44] [45] [46] [47]
Missing character: There is no Â in font cmtt9!
Missing character: There is no µ in font cmtt9!
 [48] [49]
Overfull \hbox (3.74455pt too wide) in paragraph at lines 3175--3175
[][][]\OT1/cmtt/m/n/10 <h1 style="text-align: center;">Lecture 12: Numpy + Cyth
on = AWESOME</h1>[] 
 []


Overfull \hbox (155.99323pt too wide) in paragraph at lines 3175--3175
[][][]\OT1/cmtt/m/n/10 <p>This lecture is about how to efficiently combine Nump
y and Cython to write fast numerical code.</p>[] 
 []


Overfull \hbox (1415.98224pt too wide) in paragraph at lines 3175--3175
[][][]\OT1/cmtt/m/n/10 <p>We will focus on the problem of computing the <em>sta
ndard deviation</em>&nbsp;of a list of floating point numbers. &nbsp; Let $x_1,
 \ldots, x_n$ be a list of $n$ real numbers, and let $$\mu = \frac{1}{n}\sum_{i
=1}^n x_i$$ be their mean. &nbsp; We define their standard deviation to be $$\s
qrt{\frac{1}{n}\sum_{i=1}^n (x_i - \mu)^2}.$$</p>[] 
 []


Overfull \hbox (1363.4827pt too wide) in paragraph at lines 3175--3175
[][][]\OT1/cmtt/m/n/10 <p><strong>Note</strong>: In statistics it is common to 
divide by $n-1$ instead of $n$ when computing the standard deviation of a sampl
e and using it to estimate the standard deviation of a population. &nbsp;We wil
l not do this, since our goal today is illustrating programming techniques, not
 learning techniques of statistics.</p>[] 
 []


Overfull \hbox (917.23659pt too wide) in paragraph at lines 3175--3175
[][][]\OT1/cmtt/m/n/10 <p><strong>Running Example:</strong> Compute the standar
d deviation of a list of 64-bit floating point numbers. &nbsp; Our data set is 
computed using the random.random method, which generates numbers <strong>unifor
mly</strong> between 0 and 1.</p>[] 
 []


Overfull \hbox (1809.7288pt too wide) in paragraph at lines 3175--3175
[][][]\OT1/cmtt/m/n/10 [0.43811732887872634, 0.78344784289564662, 0.79176725313
41533, 0.43546157784257289, 0.99879630143646858, 0.21470214570255253, 0.5281800
2353940696, 0.51667692205628102, 0.67726646422202585, 0.92183464863760212, 0.54
553592061123968, 0.2143866131543859, 0.90130600825854523, 0.71144055233831971, 
0.080614713472959898, 0.81024524942438758, 0.8403186842969067, 0.26527690630696
821, 0.9755892062984004, 0.94353224947123771][] 
 []


Overfull \hbox (155.99323pt too wide) in paragraph at lines 3175--3175
[][][]\OT1/cmtt/m/n/10 <p>First we write a naive straightforward implementation
 of computation of the standard deviation.</p>[] 
 []

[50]
Overfull \hbox (423.74089pt too wide) in paragraph at lines 3175--3175
[][][]\OT1/cmtt/m/n/10 <p>Next we try the std function in Sage, which was imple
mented by UW undergrad Andrew Hou as part of paid work he did on Sage after he 
took Math 480.</p>[] 
 []

[51]
Overfull \hbox (560.2397pt too wide) in paragraph at lines 3175--3175
[][][]\OT1/cmtt/m/n/10 <p>Sage also has code for working with TimeSeries, which
 happens to have a method for computing the standard deviation. &nbsp;It is a c
ouple of times faster than Numpy. &nbsp;</p>[] 
 []

Missing character: There is no Â in font cmtt10!
Missing character: There is no µ in font cmtt10!

Overfull \hbox (922.48654pt too wide) in paragraph at lines 3175--3175
[][][]\OT1/cmtt/m/n/10 <p>The TimeSeries code is nearly optimal. &nbsp;A TimeSe
ries is represented by a contiguous array of double's, and the code for computi
ng standard deviation is very straightforward Cython that maps directly to C. &
nbsp;(I wrote it, by the way.)</p>[] 
 []


Overfull \hbox (523.49002pt too wide) in paragraph at lines 3175--3175
[][][]\OT1/cmtt/m/n/10 <p><strong>Goal: </strong>Write a function that computes
 the standard deviation of a numpy array as quickly as stats.TimeSeries does, h
ence is faster than Numpy itself.</p>[] 
 []


Overfull \hbox (323.99176pt too wide) in paragraph at lines 3175--3175
[][][]\OT1/cmtt/m/n/10 <p>First approach: Use numpy "vectorized operations". &n
bsp;This doesn't help at all (and is also wasteful of memory, by the way).</p>[
] 
 []

[52]
Overfull \hbox (255.74236pt too wide) in paragraph at lines 3175--3175
[][][]\OT1/cmtt/m/n/10 <p>Let's see how the time gets spent between each step. 
&nbsp;It turns out to be about equally spent among each line.</p>[] 
 []

[53]
Missing character: There is no Â in font cmtt10!
Missing character: There is no µ in font cmtt10!
Missing character: There is no Â in font cmtt10!
Missing character: There is no µ in font cmtt10!
Missing character: There is no Â in font cmtt10!
Missing character: There is no µ in font cmtt10!
Missing character: There is no Â in font cmtt10!
Missing character: There is no µ in font cmtt10!
 [54]
Overfull \hbox (239.9925pt too wide) in paragraph at lines 3175--3175
[][][]\OT1/cmtt/m/n/10 <p>Next try Cython with no special type declarations. &n
bsp;Not surprisingly, this does not help in the least bit.</p>[] 
 []


Overfull \hbox (134.99341pt too wide) in paragraph at lines 3175--3175
[][][]\OT1/cmtt/m/n/10 <p>Next try Cython with special support for Numpy. &nbsp
;This gets powerful... as we will see.</p>[] 
 []

[55]
Overfull \hbox (906.73668pt too wide) in paragraph at lines 3175--3175
[][][]    \OT1/cmtt/m/n/10 exec compile(u'open("___code___.py","w").write("# -*
- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("c
3RkX251bXB5MyhOb25lKQ=="),globals())+"\\n"); execfile(os.path.abspath("___code_
__.py"))' + '\n', '', 'single')[] 
 []


Overfull \hbox (1090.48508pt too wide) in paragraph at lines 3175--3175
[][][]  \OT1/cmtt/m/n/10 File "_sagenb_flask_sage_notebook_sagenb_home_openidSf
mMv1OuVE_44_code_sage70_spyx_0.pyx", line 8, in _sagenb_flask_sage_notebook_sag
enb_home_openidSfmMv1OuVE_44_code_sage70_spyx_0.std_numpy3 (_sagenb_flask_sage_
notebook_sagenb_home_openidSfmMv1OuVE_44_code_sage70_spyx_0.c:713)[] 
 []


Overfull \hbox (45.74419pt too wide) in paragraph at lines 3175--3175
[][][]\OT1/cmtt/m/n/10 TypeError: Argument 'v' has incorrect type (expected num
py.ndarray, got NoneType)[] 
 []


Overfull \hbox (649.48892pt too wide) in paragraph at lines 3175--3175
[][][]\OT1/cmtt/m/n/10 <p>Look at Cython + Numpy documentation (by Googling "cy
thon numpy"), and we learn that if we declare v a little more precisely, then w
e get fast direct access to the underlying elements in v.</p>[] 
 []

[56]
Missing character: There is no Â in font cmtt10!
Missing character: There is no µ in font cmtt10!
 [57]
Missing character: There is no Â in font cmtt10!
Missing character: There is no µ in font cmtt10!
Missing character: There is no Â in font cmtt10!
Missing character: There is no µ in font cmtt10!

Overfull \hbox (281.99213pt too wide) in paragraph at lines 3175--3175
[][][]\OT1/cmtt/m/n/10 <p>Finally, we try again, after disabling bounds checkin
g. &nbsp; This is even better; almost as good as stats.TimeSeries.</p>[] 
 []

[58]
Missing character: There is no Â in font cmtt10!
Missing character: There is no µ in font cmtt10!
Missing character: There is no Â in font cmtt10!
Missing character: There is no µ in font cmtt10!

Overfull \hbox (19.49442pt too wide) in paragraph at lines 3175--3175
[][][]\OT1/cmtt/m/n/10 <h1><span style="color: #800000;">Yeah, we did it!! &nbs
p;</span>&nbsp;</h1>[] 
 []


Overfull \hbox (659.98883pt too wide) in paragraph at lines 3175--3175
[][][]\OT1/cmtt/m/n/10 <p>For smaller input, interestingly we get a massive win
 over Numpy. &nbsp; If you were, e.g., computing a sliding window of standard d
eviations (say) for a time series, this would be important.</p>[] 
 []

Missing character: There is no Â in font cmtt10!
Missing character: There is no µ in font cmtt10!
[59]
Chapter 4.
[60

]
Overfull \hbox (6.0159pt too wide) in paragraph at lines 3239--3242
[][][]\OT1/cmr/m/n/10 To search the def-i-ni-tions of func-tion, use []\OT1/cmt
t/m/n/10 search_def\OT1/cmr/m/n/10 . This works just like []\OT1/cmtt/m/n/10 se
arch_src
 []

[61] [62]
Chapter 5.
Missing character: There is no Ã in font cmtt9!
Missing character: There is no © in font cmtt9!
[63

]
Overfull \hbox (17.3967pt too wide) in paragraph at lines 3375--3377
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][] 
 []

[64]
Overfull \hbox (27.96887pt too wide) in paragraph at lines 3460--3467
[][][]\OT1/cmr/m/n/10 Fortunately, the pro-cess is well doc-u-mented (see []$[]
[]\OT1/cmtt/m/n/10 http : / / sagemath . org / doc / developer/$[]\OT1/cmr/m/n/
10 ),
 []


Overfull \hbox (164.81625pt too wide) in paragraph at lines 3482--3483
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] 
 []

[65]
Overfull \hbox (113.7864pt too wide) in paragraph at lines 3484--3485
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] 
 []


Overfull \hbox (11.72672pt too wide) in paragraph at lines 3487--3488
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][] 
 []


Overfull \hbox (51.4166pt too wide) in paragraph at lines 3488--3489
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] 
 []


Overfull \hbox (17.3967pt too wide) in paragraph at lines 3491--3492
[][][][][][] 
 []


Overfull \hbox (11.72672pt too wide) in paragraph at lines 3492--3493
[][][][][][][][][][][][][][][][][][][][][]
 []


Overfull \hbox (11.72672pt too wide) in paragraph at lines 3493--3494
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
 []


Overfull \hbox (17.3967pt too wide) in paragraph at lines 3494--3495
[][][][][][] 
 []


Overfull \hbox (428.99084pt too wide) in paragraph at lines 3518--3518
[][][]     \OT1/cmtt/m/n/10 0. Turn on screen capture using Quicktime (plus I'l
l do this all in one terminal and paste the session log below, though editing w
on't get recorded).[] 
 []


Overfull \hbox (953.98627pt too wide) in paragraph at lines 3518--3518
[][][]     \OT1/cmtt/m/n/10 1. Login to the math480@sage.math.washington.edu ac
count.  NOTE: On Windows, install [http://www.chiark.greenend.org.uk/~sgtatham/
putty/ Putty]. On Linux and OS X use the command line (e.g., Terminal) and type
 "ssh math480@sage.math.washington.edu".[] 
 []


Overfull \hbox (66.744pt too wide) in paragraph at lines 3518--3518
[][][]     \OT1/cmtt/m/n/10 2. Change to directory with my sage install in it a
nd type "here" to setup PATH.[] 
 []


Overfull \hbox (140.24336pt too wide) in paragraph at lines 3518--3518
[][][]     \OT1/cmtt/m/n/10 2. Make a change to the Sage library source code us
ing pico, based on a suggestion from class.[] 
 []


Overfull \hbox (287.24208pt too wide) in paragraph at lines 3518--3518
[][][]     \OT1/cmtt/m/n/10 4. Type "hg diff" to see the change (your shell cur
rent working directory must be a subdirectory of SAGE_ROOT/devel/sage/)[] 
 []


Overfull \hbox (680.98865pt too wide) in paragraph at lines 3518--3518
[][][]     \OT1/cmtt/m/n/10 5. Type "hg commit" to save changes as a commit.  T
ype "hg revert --all" to instead undo everything you have done.  Enter a log me
ssage on the first line and save the file, when you do "hg commit".[] 
 []


Overfull \hbox (785.98773pt too wide) in paragraph at lines 3518--3518
[][][]     \OT1/cmtt/m/n/10 7. Type "hg export tip > file.patch" to create a pa
tch file.   You can get the patch by navigating to the directory in which you t
yped this command, starting here: http://sage.math.washington.edu/home/math480/
scratch/[] 
 []


Overfull \hbox (607.48929pt too wide) in paragraph at lines 3518--3518
[][][]     \OT1/cmtt/m/n/10 8. Congrats, we have our patch.   If we don't like 
it and want to start over, do "hg rollback".  This will reset things to be exac
tly like they were before we typed "hg commit" above.[] 
 []


Overfull \hbox (854.23714pt too wide) in paragraph at lines 3518--3518
[][][]     \OT1/cmtt/m/n/10 9. Remark: For much finer control over making patch
es, people usually use "Mercurial Queues", as described here in [http://sagemat
h.org/doc/developer/ The Sage developers guide].      You do not have to use th
em for your homework.[] 
 []

[66]
Chapter 6.

Overfull \hbox (386.99121pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p>The goal of this lecture is to give you a deeper unde
rstanding of some of the fundamental and unique architectural issues involved i
n Sage.</p>[] 
 []


Overfull \hbox (397.49112pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p>I built Sage partly from other complete mathematical 
software systems because I wanted to finish Sage (for my use!) in at most 5 yea
rs.&nbsp;</p>[] 
 []


Overfull \hbox (87.74382pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <h3 style="text-align: center;">"Building the car instea
d of reinventing the wheel."</h3>[] 
 []


Overfull \hbox (1337.23293pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p>Each of the above is a full standalone project with i
ts own custom programming language, history, culture, etc. &nbsp;And each has u
nique, powerful, debugged code that I don't want to have to rewrite from scratc
h, since it would take too long, and writing code from scratch is incredibly di
fficult and frustrating.&nbsp;</p>[] 
 []


Overfull \hbox (554.98975pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p>I also wanted to make it easy to call the following s
ystems from Sage for the purposes of benchmarking, porting, migration of users 
and code, optional functionality, etc.:</p>[] 
 []


Overfull \hbox (113.99359pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p><strong>The Big Problem:</strong> How can we make use
 of the above systems from Python?</p>[] 
 []


Overfull \hbox (444.7407pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p>This question is difficult partly because there are s
o many answers, each with pros and cons, and I had to choose (then be criticize
d for my choices).</p>[] 
 []


Overfull \hbox (3090.71764pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 [[10], [9, 1], [8, 2], [8, 1, 1], [7, 3], [7, 2, 1], [7,
 1, 1, 1], [6, 4], [6, 3, 1], [6, 2, 2], [6, 2, 1, 1], [6, 1, 1, 1, 1], [5, 5],
 [5, 4, 1], [5, 3, 2], [5, 3, 1, 1], [5, 2, 2, 1], [5, 2, 1, 1, 1], [5, 1, 1, 1
, 1, 1], [4, 4, 2], [4, 4, 1, 1], [4, 3, 3], [4, 3, 2, 1], [4, 3, 1, 1, 1], [4,
 2, 2, 2], [4, 2, 2, 1, 1], [4, 2, 1, 1, 1, 1], [4, 1, 1, 1, 1, 1, 1], [3, 3, 3
, 1], [3, 3, 2, 2], [3, 3, 2, 1, 1], [3, 3, 1, 1, 1, 1], [3, 2, 2, 2, 1], [3, 2
, 2, 1, 1, 1], [3, 2, 1, 1, 1, 1, 1], [3, 1, 1, 1, 1, 1, 1, 1], [2, 2, 2, 2, 2]
, [2, 2, 2, 2, 1, 1], [2, 2, 2, 1, 1, 1, 1], [2, 2, 1, 1, 1, 1, 1, 1], [2, 1, 1
, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]][] 
 []


Overfull \hbox (18074.08699pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 92027175502604546685596278166825605430729405281023979395
3285763517412985262323501978822916547103339332198764311128926694429965192014469
3371805742588542551019656697136927224393688612370494439001184662672422293588388
0949646021554674211449712293631879438242092222979701858787035045131791561718499
0942766797810155029441933075045772129188981041614489343545384206438995186836592
2625931251702234301276800624906634777438422420020049142313578994862871246786261
0060006610227873354093344771970346402912468019502617741296485750068965727678736
5748796835192363570613191348609145244276270764465804777408575949440508551447566
4188114896304641911150453092801316525477317827937471411504849803193674306114639
9094602347281946619566715867818368113040887581799683872172944577575391666322871
2954510481120704923859087275241592392223665876910286300131474621294645735699401
7362846975817551519000164134514089936709319085908026718561179217042946519785796
8117435299141079155705662249617336911859509285578584413441733816964914269258918
7435301742615221458864914330678814703958326474085781955660425664604942849123726
1204850512724398725459766069032380425223714808312168530010647379469068980174750
4661946299472005981442948094926764563853171727831538610914056742150737497538427
5021240249642090800336572787686941682199463463099066866702204042926855402821066
6766158414720115574024352181802062923401192416721410067481998267445932984517612
6920689181532303574746823885977198276651255478126323692431978852519785180336170
5413947686093663891147724061366833494127467087092245969359401102159299184733830
1438906563276480526765759086551359397824424431168085421773553659282321900119956
9770431572718888108452817614295777255622715362408122265800848932276196267545354
4265567233476857358975517683731089773908740330164186182660688614126800469264172
9957436799211806554382447196471158568214661865173011689077327922743213795448845
7335074000412015820488115033194548391813526724286716271750346470118187739995800
4314416087296985163324282563458624844066236399562733354725457411347627828347256
5930336271866741519736879804021922337163713433125642662988743051959019602770323
1191899072357523708159719377437782971846471928181434133277347743728346062720786
9478917449115162489982657581564116298023459732495270075351700956243598913730840
1334549711182650855857066766448864363318347642642193870541917675024873002552707
9093923132020478303851642054200888831310378483811088425548758508373324093873479
7302734376936793420810867020185209718779670927269908884747550412550772822753523
0866798095362455247464529577455482381783027175201590517548765620068098696273250
3598211618667111264793583287147032328796244469851598884862190118775508811358918
5457016501136471407349024158013999313263656227842088073986822774216895311418550
7699828983806874612655437732175065228812853327497124638951381805103781784970476
9088911818484659276794986806465634286299339344423718490667472287384981129496643
9997475566061223014020274110963671727713854372115721224489228469570767118124546
4557214332012897163090638216734538158656594031674831608270687758454094849618839
8233399350019423833682423300814059493159013417591894979385650634324308841947277
1218165592793359389269115106835490432906902871027335713152227618464826154317860
6181345463363441597417941394202470612998672573447155234616773861350947076075833
8637870579921007168514417341548481513953296373455058614174692678013759737246724
6969311252404574068882891540550303875935489428805492623836212595940806996986432
45355453826567378500963781681659096276126857969078217677288980[] 
 []


Overfull \hbox (197.99286pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p><strong>Problem 1:</strong> Availability of a specifi
c known version of a third party software package.</p>[] 
 []

[67

]
Overfull \hbox (1736.22945pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p>Even if we solve the big problem above, a "vendor" wi
ll often just release a new version of their software with numerous changes tha
t break our solution. &nbsp;This happens <em>constantly</em>. &nbsp;And the act
ual versions of software that people have installed (under OS X, various Linuxe
s, Solaris, etc.) will be widely distributed over versions of software from the
 last decade. &nbsp; &nbsp;</p>[] 
 []


Overfull \hbox (2329.47427pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p><strong>Solution: </strong>For the free open systems 
that (1) we really need, and (2) we can build from source easily enough, we shi
p and build a very specific version as part of Sage. &nbsp; This completely sol
ves problem 1, at the expense of a lot of (misplaced) criticism from people who
 don't understand the problem; at the same time, this accidentally creates a so
lution to a different problem (easy-to-install distribution of a bunch of usefu
l math software), which many people greatly appreciate.&nbsp;</p>[] 
 []


Overfull \hbox (1478.98169pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p>For the non-free systems or the free systems that are
 hard to build, the problem just doesn't get solved. &nbsp;And indeed our inter
faces and code that relies on those systems is sadly fairly brittle; often a ne
w version of Magma just breaks with Sage. &nbsp; Fortunately, of course very li
ttle functionality in Sage depends on such systems.&nbsp;</p>[] 
 []


Overfull \hbox (245.24245pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p><strong>Problem 2</strong>: Make a specific version o
f some mathematics software (call it M) usable from Python.</p>[] 
 []


Overfull \hbox (932.98645pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <li><strong>Naive Subprocess. </strong>Start up M, tell 
it to read in a file, and save the results in a file, and terminate. &nbsp;<em>
This doesn't preserve state between calls, and startup time can easily be secon
ds, so this is not viable.</em></li>[] 
 []


Overfull \hbox (3720.71214pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <li><strong>Create network protocols.</strong> &nbsp;Def
ine an openmath/XML based protocol for well-defined communication of "arbitrary
 mathematics" (whatever that is) between software, e.g., between M and Python. 
&nbsp;Design and implement client and server protocols. &nbsp;<a href="http://w
ww.symbolic-computation.org/The_SCIEnce_Project" target="_blank">The SCIEnce pr
oject</a>, started in 2006, and costing many millions of dollars, is an example
. &nbsp; <em>This seems like the right approach, but it it is slow in certain r
elevant benchmarks and too challenging (for me) to develop. &nbsp;It's probably
 very useful for something (e.g., writing research papers), but is massively to
o complicated for what we need for Sage, which is focused on what is practical 
now.</em></li>[] 
 []


Overfull \hbox (2502.72276pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <li><strong>Pseudo-tty's (ptty) = pexpect. </strong>&nbs
p; Create a simulated command line prompt that is controled by Python. &nbsp;Ab
solutely anything that one can do at the command line with M immediately become
s usable from a Python program. &nbsp; &nbsp;This is relatively easy to impleme
nt and extremely flexible -- one can create a useful interface to any math soft
ware system out there in a day. &nbsp;It is slow in some sense, but still much 
better than (1) and (2). &nbsp; <em>This approach has been used in Sage for a l
ong time.</em></li>[] 
 []


Overfull \hbox (1646.98022pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <li><strong>C/C++ library interfaces.</strong> &nbsp;Cre
ate a C/C++ library interface and link the other program into Python itself, us
ing Cython. &nbsp; This is extremely difficult, because none of the M's (except
 PARI) are designed to be used this way. &nbsp;However, it is extremely fast. &
nbsp;For basic arithmetic, it can be several hundred times faster than (3) abov
e. &nbsp;</li>[] 
 []


Overfull \hbox (1200.73412pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p>As of now, people have written fairly polished versio
ns of both (3) and (4) for all of: PARI, GAP, Singular, Maxima, and R. &nbsp; &
nbsp;In case of (4), these are all hard work, and aren't necessarily used much 
in Sage yet, or even included in Sage, but they exist, and are on the way in.&n
bsp;</p>[] 
 []


Overfull \hbox (1662.73009pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p>The rest of this worksheet is about how to use (3) ab
ove: the pexpect based interfaces. &nbsp; This is <em>well worth learning</em>,
 because these interface all work in almost exactly the same way, and there are
 interfaces to pretty much every math software system out there. &nbsp; Sage is
 the only software in existence that can talk to so many other math software sy
stems. &nbsp;</p>[] 
 []


Overfull \hbox (528.73997pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p>Here are the basic points, which we'll follow with se
veral examples illustrating them. &nbsp;Suppose m is one of math software syste
ms, e.g., r or singular or maxima:</p>[] 
 []


Overfull \hbox (780.73778pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <li><strong>x = m.eval(s): </strong>sets x equal to the 
string obtained by typing the string s into M. &nbsp; The string s can be sever
al lines long. &nbsp;(This is how many % modes in the noteboook are implemented
.)</li>[] 
 []


Overfull \hbox (1258.48361pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <li><strong>x = m(s): </strong>creates a new Python obje
ct that "wraps" the result of evaluating s in M. &nbsp;It's like typing "x.name
() = s" into M. &nbsp;You can then do arithmetic with x, and call functions on 
it, e.g., <strong>x.function(...)</strong> or <strong>m.function(..., x, ...)</
strong>.&nbsp;</li>[] 
 []


Overfull \hbox (2607.72185pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p><strong>WARNING:</strong> There is latency. &nbsp;<st
rong>Any</strong> time you call any function involving a pexpect interface, exp
ect it to take on the order of at least <strong>1ms (=one millisecond), </stron
g>even if the actual operation in the system M takes almost no time. &nbsp; &nb
sp;For comparison, adding or multiplying most simple objects in Python/Sage tak
es about 1 microsecond (i.e., 1/1000 the time of a call involving pexpect), and
 adding/multiping objects in Cython can take only a few nanoseconds (1/1000000 
the time of a pexpect call). &nbsp;</p>[] 
 []


Overfull \hbox (292.49203pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p>Another note: the very first time you do m.eval(...) 
it may take surprisingly long, since another program is starting up.</p>[] 
 []

[68]
Overfull \hbox (203.24281pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p>There is now a separate Maxima subprocess running. &n
bsp;Each process has an id number associated to it:</p>[] 
 []


Overfull \hbox (82.49387pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p>Next will illustrate creating a Python object that wr
aps an expression in Maxima.</p>[] 
 []


Overfull \hbox (77.24391pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <html><div class="math">\newcommand{\Bold}[1]{\mathbf{#1
}}\sin x^3\,\tan y</div></html>[] 
 []


Overfull \hbox (365.9914pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p>The result is another Python object (which wraps anot
her object defined in Maxima). &nbsp;We can call functions on that object as we
ll.</p>[] 
 []


Overfull \hbox (974.98608pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p><strong>Conclusion:</strong> If you understand the ab
ove, you are in extremely good shape. &nbsp;All the other interfaces work the s
ame way. &nbsp; The examples below are just to illustrate some subtle points an
d show how interfaces are useful. &nbsp;</p>[] 
 []

[69]
Overfull \hbox (2161.47574pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p>It is possible in some systems to seriously mess thin
gs up and get things "out of sync". &nbsp;This is nearly impossible with Maxima
, since we use it so heavily and have debugged the heck out of it. &nbsp;Howeve
r, with other systems (like Magma) this can happen. &nbsp;If it does, do, e.g.,
 <strong>maxima.quit()</strong>. &nbsp;This completely kills the subprocess, in
valides any Python objects that wrap variables in that session, and starts a br
and new fresh session. &nbsp;</p>[] 
 []


Overfull \hbox (24.74437pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p>Here is an example with each of the five big systems 
included in Sage:</p>[] 
 []


Overfull \hbox (570.73961pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p>You can follow standard R tutorials and have the comp
utations (except graphics at present) to all definitely "just work". &nbsp;(Unl
ike the potentially confusing rpy2.)&nbsp;</p>[] 
 []


Overfull \hbox (82.49387pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p>There is also an interface to Octave, which is very s
imilar to Matlab (but free).</p>[] 
 []


Overfull \hbox (428.99084pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p><strong>Bonus:</strong> There is even a pexpect inter
face to Sage itself. &nbsp; (Trivia: this is used in the implementation of the 
Sage notebook.)</p>[] 
 []

[70]
Overfull \hbox (481.49039pt too wide) in paragraph at lines 3728--3728
[][][]\OT1/cmtt/m/n/10 <p>Let's get crazy: a pexpect interface inside a pexpect
 interface. &nbsp;And of course, this code is going from the notebook to Sage v
ia yet another interface.</p>[] 
 []

[71] [72

]
Chapter 7.

Overfull \hbox (3.74455pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 <li>most 2d plotting that Mathematica has (with a simila
r interface)</li>[] 
 []


Overfull \hbox (1169.23439pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 <p>Sage uses the Python library Matplotlib (<a href="htt
p://matplotlib.sourceforge.net/" target="_blank">http://matplotlib.sourceforge.
net/</a>) is used under the hood to render 2d graphics; for 3d graphics, Sage c
an use a Java applet (jmol), an HTML5 canvas renderer, or a raytracer. &nbsp;</
p>[] 
 []


Overfull \hbox (187.49295pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 <p>In this worksheet, we'll explain how to use the "math
ematica-style" 2d plotting capabilities of Sage.</p>[] 
 []


Overfull \hbox (1583.98077pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 <p>First, we'll discuss a simple but very powerful plott
ing command in Sage called "line". &nbsp;It takes as input a list of points, an
d draws a sequence of line segments connecting them. &nbsp; &nbsp;The points ar
e given as 2-tuples (x,y), which are the x and y coordinates of a point in the 
plane. &nbsp; The output of calling the line command is a line object. &nbsp;</
p>[] 
 []


Overfull \hbox (255.74236pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 <p>To <em><strong>see</strong></em> the actual plot of L
, just put L by itself on a line or type show(L) or L.show():</p>[] 
 []


Overfull \hbox (260.99231pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 <p>Incidentally, there are many, many options that you c
an pass to the show command. &nbsp; The three most useful are:</p>[] 
 []


Overfull \hbox (334.49167pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 <li>frame=True: &nbsp; Make it so the x-y axis are repla
ced by a frame, which is much better when looking at certain types of plots</li
>[] 
 []


Overfull \hbox (187.49295pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 <li>gridlines=True: Adds a background grid, which makes 
it easier to understand the plot in some cases.</li>[] 
 []


Overfull \hbox (355.49149pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 <li>figsize=[w,h]: &nbsp;Allows you to adjust the size o
f the output. &nbsp;Think of w and h as the width and height in "inches".&nbsp;
</li>[] 
 []


Overfull \hbox (3783.7116pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 <p>&nbsp;In the notebook you can just click and download
 the default plots displayed above, since they are png images. &nbsp; However, 
if you want to include images in a paper you're writing, or use an image in an 
editor such as Inkscape, it's much better to save the images in other formats. 
&nbsp; Thus a&nbsp;critically useful command is L.save('filename.ext'), which e
nables you to save a graphics object to a file. &nbsp;The extension of the file
name determines the type of the file. &nbsp;For example, below we save L to pdf
, eps, and svg formats. &nbsp;Note that the svg image just appears embedded in 
your web browser, and you can pan around. &nbsp;In any case, you can always (ri
ght or control) click on the link or image to save it as a file on your compute
r. &nbsp; &nbsp;&nbsp;</p>[] 
 []


Overfull \hbox (554.98975pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 <p>Lines (and all other graphics objects) have numerous 
properties that you can adjust, which you find in the documentation. &nbsp;The 
most important properties of lines are:</p>[] 
 []

[73

]
Overfull \hbox (292.49203pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 <li>color=...: where for the color you can give a string
, e.g., 'red'; or an html color, e.g., '#042a99', or an rgb triple.</li>[] 
 []


Overfull \hbox (14.24446pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 <li>linestyle='--': &nbsp; the style of the line: '--', 
'-.', '-', ':'</li>[] 
 []


Overfull \hbox (45.74419pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 sage: line([(-2,-2), (3,8), (5, 5)], color='purple', thi
ckness=3, linestyle='--')[] 
 []


Overfull \hbox (56.2441pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 sage: line([(-2,-2), (3,8), (5, 5)], color='#042a99', th
ickness=1.5, linestyle=':')[] 
 []


Overfull \hbox (318.7418pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 <p>Arithmetic: a key unusual idea in Sage graphics is th
at you combine together different graphics using +, as illustrated below:</p>[]
 
 []


Overfull \hbox (155.99323pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 sage: L2 = line([(1,0), (2,5), (3,0)], color='purple', t
hickness=10, alpha=.7)  # alpha = transparency[] 
 []


Overfull \hbox (360.74144pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 <p>There are numerous other important plotting commands 
in Sage, including point, circle, polygon, arrow, and text, as illustrated belo
w:</p>[] 
 []


Overfull \hbox (35.24428pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 sage: G += text(r"$\sqrt{\sin(\pi x^2)}$",(1.8,1.35),col
or='black',fontsize=20)[] 
 []


Overfull \hbox (1405.48233pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 <p>There are also a function just called "plot" that mak
es a plot of a wide range of Sage objects. &nbsp;It is very useful especially f
or plotting functions of one variable. &nbsp;It is probably the most used Sage 
plotting function. &nbsp;The result is a graphics object, which you can use jus
t like any graphics object discussed above.</p>[] 
 []


Overfull \hbox (124.4935pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 <p>matrix_plot is another similar plotting function, whi
ch allows you to visualize a matrix.</p>[] 
 []


Overfull \hbox (266.24226pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 <p>Finally, there is a graphics_array function that lets
 you assemble several independent plots into a single big plot.</p>[] 
 []


Overfull \hbox (113.99359pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 sage: graphics_array([[matrix_plot(A), matrix_plot(A^2)]
, [plot(sin), plot(cos,color='red')]])[] 
 []


Overfull \hbox (523.49002pt too wide) in paragraph at lines 3815--3815
[][][]\OT1/cmtt/m/n/10 <p>Bonus -- you can animate graphics. &nbsp;Given any li
st of graphics objects, the animate command will make a single animated GIF fil
e out of them. &nbsp;For example:</p>[] 
 []


Overfull \hbox (481.49039pt too wide) in paragraph at lines 3883--3883
[][][]\OT1/cmtt/m/n/10 <p>In Sage, just as with 2d graphics, you make 3d graphi
cs by creating various primitives and combining them together using addition to
 create a 3d scene.&nbsp;</p>[] 
 []


Overfull \hbox (3741.71196pt too wide) in paragraph at lines 3883--3883
[][][]\OT1/cmtt/m/n/10 <p>There are many 3d graphics primitives in Sage. &nbsp;
 For example, you can draw platonic solids using <strong>tetrahedron, cube, oct
ahedron, dodecahedron, icosahedron</strong>.&nbsp; You can plot round objects u
sing <strong>sphere</strong> and <strong>point3d</strong>.&nbsp;&nbsp; You can 
plot 1d arrows, lines, and curves in space using <strong>arrow3d, bezier3d, lin
e3d</strong>.&nbsp;&nbsp; There are also numerous powerful tools for plotting d
ata, functions, and surfaces in 3d, including<strong> cylindrical_plot3d, impli
cit_plot3d, list_plot3d, parametric_plot3d, plot3d, plot_vector_field3d, polygo
n3d, revolution_plot3d, spherical_plot3d</strong>, and <strong>implicit_plot3d<
/strong>.&nbsp; Finally, you can place text in 3d using the <strong>text3d</str
ong> function.</p>[] 
 []


Overfull \hbox (833.23732pt too wide) in paragraph at lines 3883--3883
[][][]\OT1/cmtt/m/n/10 <p>All 3d graphics objects have <strong>translate</stron
g> and <strong>rotate</strong> (and <strong>rotateX, rotateY, rotateZ</strong>)
 methods, which allow you to position the object or collection of objects anywh
ere you want.</p>[] 
 []


Overfull \hbox (192.7429pt too wide) in paragraph at lines 3883--3883
[][][]\OT1/cmtt/m/n/10 <p>Also, you can set the color and opacity of any 3d obj
ect when you create it, as an optional parameter.</p>[] 
 []


Overfull \hbox (1678.47995pt too wide) in paragraph at lines 3883--3883
[][][]\OT1/cmtt/m/n/10 <p>Finally, you can display a 3d scene G using either&nb
sp; jmol (java) via <strong>G.show()</strong>, the Tachyon raytracer via <stron
g>G.show(viewer='tachyon')</strong>, or HTML5 canvas via <strong>G.show(viewer=
'canvas3d')</strong>.&nbsp; The show command also takes an aspect_ratio option;
 e.g., sometimes <strong>aspect_ratio=1</strong> is useful, in order to make sp
here round, etc.</p>[] 
 []

[74]
Overfull \hbox (1022.23567pt too wide) in paragraph at lines 3883--3883
[][][]\OT1/cmtt/m/n/10 <p>There are also some rudimentary 3d plotting capabilit
ies in matplotlib.&nbsp; I had once announced an intention to improve those for
 Sage, but upon closer inspection one finds that matplotlib is very 2d oriented
 and the 3d stuff just doesn't feel right at all.</p>[] 
 []


Overfull \hbox (4796.95276pt too wide) in paragraph at lines 3883--3883
[][][]\OT1/cmtt/m/n/10 <p><strong>History:</strong> William Stein included Tach
yon in Sage, then Tom Boothby, Josh Kantor and William Stein wrote some very pr
eliminary 3d plotting functionality that relied entirely on tachyon, and could 
plot functions $z=f(x,y)$.&nbsp; A year later, during Christmas break, William 
stumbled on the jmol Java viewer (that only uses Java's 2d render!) for molecul
es and he and Robert Bradshaw snuck off and figured out how to make jmol show m
ore general mathematical graphics, and also wrote most of the 3d plotting libra
ry on top of this, motivated by the upcoming joint math meetings in San Diego (
Jan 2008).&nbsp;&nbsp; David Joyner then submitted many examples to the documen
tation.&nbsp; Next, William Cauchois (as a UW freshman project) and Carl Witty 
added an implicit_plot3d function, and Cauchois also added HTML5 canvas renderi
ng.&nbsp; Other people added plotting of vector fields, cylindrical plotting, e
tc., driven by Calculus teaching needs.&nbsp;&nbsp;&nbsp;</p>[] 
 []


Overfull \hbox (2560.47226pt too wide) in paragraph at lines 3883--3883
[][][]\OT1/cmtt/m/n/10 <p><strong>Note: </strong>The 3d plotting in Sage is mai
nly oriented toward mathematical  visualization, rather than visualizing large 
3d datasets that come up in  Scientific computing.&nbsp;&nbsp; Scientsts are ru
mored to make great use of other Python-friendly options, none of which are inc
luded with Sage or are easy to install in Sage at present, though all are free,
 open source, and can be installed if one is <em>"sufficiently motivated"</em>:
&nbsp;&nbsp; MyaVI (which uses the VTK C++ library),&nbsp;&nbsp; ScientificPyth
on,&nbsp;&nbsp; ...?&nbsp;</p>[] 
 []


Overfull \hbox (2051.2267pt too wide) in paragraph at lines 3883--3883
[][][]\OT1/cmtt/m/n/10 <p><strong>Shortcoming:</strong> The biggest shortcoming
s are that (1) realtime interaction with 3d graphics is not supported in any wa
y, (2) there is no easy way to make high quality movie animations of 3d scenes 
(it is possible, but requires optional tools), and (3) your browser can run out
 of Java memory if you display too many jmol java-based 3d plots at once, and r
efuse to display anymore -- this has been fixed in a patch that has gone into S
age yet.</p>[] 
 []


Overfull \hbox (119.24355pt too wide) in paragraph at lines 3883--3883
[][][]\OT1/cmtt/m/n/10 <p>The rest of this worksheet illustrates with examples 
how to create 3d images using Sage.</p>[] 
 []


Overfull \hbox (255.74236pt too wide) in paragraph at lines 3883--3883
[][][]\OT1/cmtt/m/n/10 <p><strong>Problem</strong>: Draw all of the platonic so
lids next to each other in different colors in a single plot.</p>[] 
 []


Overfull \hbox (302.99194pt too wide) in paragraph at lines 3883--3883
[][][]\OT1/cmtt/m/n/10 <p><strong>Problem: </strong>Plot 40 semi-transparent ra
ndom spheres.&nbsp;&nbsp; Similarly, plot a few hundred random points.</p>[] 
 []


Overfull \hbox (8.9945pt too wide) in paragraph at lines 3883--3883
[][][]\OT1/cmtt/m/n/10 sage: G = sum( sphere((random(), random(), random()), co
lor=hue(random()),[] 
 []


Overfull \hbox (134.99341pt too wide) in paragraph at lines 3883--3883
[][][]\OT1/cmtt/m/n/10 sage: G = sum( point3d((random(), random(), random()), c
olor=hue(random())) for _ in range(1000) )[] 
 []


Overfull \hbox (98.24373pt too wide) in paragraph at lines 3883--3883
[][][]\OT1/cmtt/m/n/10 sage: G = sum([text3d('%.1f'%n, (cos(n),sin(n),n), color
=hue(n/8)) for n in [0,0.3,..,12]])[] 
 []


Overfull \hbox (61.49405pt too wide) in paragraph at lines 3883--3883
[][][]\OT1/cmtt/m/n/10 sage: plot3d( sin(pi*(x^2+y^2))/2,(x,-B,B),(y,-B,B), plo
t_points=100, color='gree' )[] 
 []


Overfull \hbox (129.74345pt too wide) in paragraph at lines 3883--3883
[][][]\OT1/cmtt/m/n/10 <p><strong>Problem: </strong>Plot an implicit 3d surface
 defined by an equation $f(x,y,z)=0$.</p>[] 
 []


Overfull \hbox (197.99286pt too wide) in paragraph at lines 3883--3883
[][][]\OT1/cmtt/m/n/10 sage: p(x,y,z) = 2 - (cos(x + T*y) + cos(x - T*y) + cos(
y + T*z) + cos(y - T*z) + cos(z - T*x) + cos(z + T*x))[] 
 []


Overfull \hbox (19.49442pt too wide) in paragraph at lines 3883--3883
[][][]\OT1/cmtt/m/n/10 sage: implicit_plot3d(p, (x, -r, r), (y, -r, r), (z, -r,
 r), plot_points=40)[] 
 []


Overfull \hbox (113.99359pt too wide) in paragraph at lines 3883--3883
[][][]\OT1/cmtt/m/n/10 sage: implicit_plot3d(p==1, (x, -r, r), (y, -r, r), (z, 
-r, r), plot_points=40, color='green')[] 
 []


Overfull \hbox (1221.73393pt too wide) in paragraph at lines 3883--3883
[][][]\OT1/cmtt/m/n/10 <p><strong>Solution:</strong> use a standard mesh one fi
nds online as follows, which describes a model of Yoda that has over 50,000 tri
angles.&nbsp;&nbsp; Here we use the scipy module "io" to load the model, then u
se the IndexFaceSet 3d primitive to construct the 3d image from the triangulati
on data.</p>[] 
 []

[75]
Overfull \hbox (119.24355pt too wide) in paragraph at lines 3883--3883
[][][]\OT1/cmtt/m/n/10 sage: Y = IndexFaceSet(F3,V,color=Color('#444444')) + In
dexFaceSet(F4,V,color=Color('#007700'))[] 
 []


Overfull \hbox (2770.47043pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 <p>Though Sage provides its own functions (e.g,. plot, l
ine, point, text, circle, etc.) for drawing 2d graphics, they are all very orie
nted toward visualizing the sorts of mathematical objects that come up in more 
pure mathematics (so more like Mathematica). &nbsp;For the sort of scientific v
isualizing that comes up in applications, the matplotlib library provides funct
ionality that is very similar to Matlab for plotting. &nbsp; &nbsp; Also, matpl
otlib can be used on any major operating system without using Sage; it only dep
ends on numpy, and has a very open license (BSD-compatible).&nbsp;</p>[] 
 []


Overfull \hbox (1085.23512pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 <p>Also, if you're drawing an image that involves a huge
 amount of data points, directly using matplotlib can be <em>more efficient</em
> than using Sage's plotting, since Sage's plotting is built on top of matplotl
ib -- using matplotlib directly gets you closer to the metal.</p>[] 
 []


Overfull \hbox (192.7429pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 <p>There are<strong> two absolutely critical</strong> th
ings to remember when using matplotlib from Sage:</p>[] 
 []


Overfull \hbox (1851.72844pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 <li>Instead of <strong>plt.show()</strong> use <strong>p
lt.savefig('a.png'). &nbsp;Memorize this now. &nbsp;</strong>This will make a n
ice smooth antialised png image of the plot appear in the Sage notebook. &nbsp;
 Using plt.show() may just do nothing in Sage, depending on your setup (it migh
t also popup a window). &nbsp; You can also do <strong>plt.savefig('a.pdf')</st
rong> and <strong>plt.savefig('a.svg')</strong>.</li>[] 
 []


Overfull \hbox (402.74107pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 <li>You might have to put your input in a <strong>%pytho
n</strong> cell or turn off the preparser (by typing <strong>preparser(False)</
strong>).</li>[] 
 []


Overfull \hbox (749.23805pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 <p>With these two hints, you should be able to to try ou
t the examples at <a href="http://matplotlib.sourceforge.net/gallery.html" targ
et="_blank">http://matplotlib.sourceforge.net/gallery.html</a>. &nbsp;&nbsp;</p
>[] 
 []


Overfull \hbox (182.243pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 <p>In fact, try it now [in class, go to the above websit
e, scroll, and let students choose an example]:</p>[] 
 []


Overfull \hbox (308.2419pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 <p>Note: There are some images in the gallery that requi
re some external data file (e.g, the brain image), so those won't work.</p>[] 
 []


Overfull \hbox (455.24062pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 <p>For example, if students choose <a href="http://matpl
otlib.sourceforge.net/examples/api/artist_demo.html" target="_blank">the first 
example</a>, we get:</p>[] 
 []


Overfull \hbox (14.24446pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 sage: Several examples of standard matplotlib graphics p
rimitives (artists)[] 
 []

[76]
Overfull \hbox (24.74437pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 sage: art = mpatches.Rectangle(pos[:,1] - np.array([0.02
5, 0.05]), 0.05, 0.1,[] 
 []


Overfull \hbox (35.24428pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 sage: arrow = mpatches.Arrow(pos[0,5]-0.05, pos[1,5]-0.0
5, 0.1, 0.1, width=0.1)[] 
 []

[77]
Overfull \hbox (29.99432pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 sage: collection = PatchCollection(patches, cmap=matplot
lib.cm.jet, alpha=0.4)[] 
 []


Overfull \hbox (1909.47794pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 <p>Matplotlib has an interface that works much like Matl
ab. &nbsp;This will be very helpful if you know Matlab, and of some value other
wise since there is a lot of Matlab code and documentation out there. This mode
 is called "pyplot", and there is a now tutorial for it at h<a href="http://mat
plotlib.sourceforge.net/users/pyplot_tutorial.html" target="_blank">ttp://matpl
otlib.sourceforge.net/users/pyplot_tutorial.html</a>. &nbsp;</p>[] 
 []


Overfull \hbox (1541.98114pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 <p>Below we replicate several examples from this tutoria
l in Sage, and you should read this tutorial. &nbsp;The main point you should r
ealize when looking at these examples is how easily one can express scientific 
data visualization in terms of this interface; many equivalent plots are possib
ly directly with Sage's plotting commands, but they are less natural.</p>[] 
 []

[78]
Overfull \hbox (24.74437pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 sage: n, bins, patches = plt.hist(x, 50, normed=1, facec
olor='g', alpha=0.75)[] 
 []


Overfull \hbox (45.74419pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 <p>Incidentally, you can of course combine matplotlib gr
aphics with @interact</p>[] 
 []

[79]
Overfull \hbox (56.2441pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 ...       n, bins, patches = plt.hist(x, bins, normed=1,
 facecolor='g', alpha=0.75)[] 
 []


Overfull \hbox (822.73741pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 <p>There are tons of other examples of pyplot at the mat
plotlib website here: <a href="http://matplotlib.sourceforge.net/examples/pylab
_examples/" target="_blank">http://matplotlib.sourceforge.net/examples/pylab_ex
amples/</a></p>[] 
 []


Overfull \hbox (14.24446pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 sage: # open, close, volume, adj_close from the mpl-data
/example directory.[] 
 []


Overfull \hbox (8.9945pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 sage: # The record array stores python datetime.date as 
an object array in[] 
 []

[80]
Overfull \hbox (2171.97565pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 <p>There is more to matplotlib than just a Matlab like i
nterface. &nbsp; &nbsp;Matplotlib has its own library interface, primitives, et
c., which are documented here: <a href="http://matplotlib.sourceforge.net/conte
nts.html" target="_blank">http://matplotlib.sourceforge.net/contents.html</a>. 
&nbsp;Also, there is an strong community with much momentum behind matplotlib d
evelopment. &nbsp;It is the <em>de facto</em> standard for 2d plotting in Pytho
n, and it keeps getting better.</p>[] 
 []


Overfull \hbox (722.98828pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 <p>This is basically this example: <a href="http://matpl
otlib.sourceforge.net/examples/mplot3d/surface3d_demo.html" target="_blank">htt
p://matplotlib.sourceforge.net/examples/mplot3d/surface3d_demo.html</a></p>[] 
 []


Overfull \hbox (56.2441pt too wide) in paragraph at lines 4163--4163
[][][]\OT1/cmtt/m/n/10 sage: from matplotlib.ticker import LinearLocator, Fixed
Locator, FormatStrFormatter[] 
 []

[81]
Chapter 8.
[82

] [83] [84]
Overfull \hbox (0.38675pt too wide) in paragraph at lines 4345--4346
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] 
 []

<graphics/primepi100.pdf, id=2198, 364.93039pt x 236.33043pt>
File: graphics/primepi100.pdf Graphic file (type pdf)

<use graphics/primepi100.pdf> [85]

LaTeX Warning: Command \d invalid in math mode on input line 4420.


Overfull \hbox (0.80115pt too wide) in paragraph at lines 4434--4438
\OT1/cmr/m/n/10 dol-lar prize prob-lems: []$[][]\OT1/cmtt/m/n/10 http : / / www
 . claymath . org / millennium / Riemann _ Hypothesis/$[] 
 []


Overfull \hbox (0.38675pt too wide) in paragraph at lines 4446--4447
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][][][][][][][][][][][][][][] 
 []

[86 <./graphics/primepi100.pdf>]
<graphics/rhpic.pdf, id=2265, 380.25014pt x 235.55531pt>
File: graphics/rhpic.pdf Graphic file (type pdf)

<use graphics/rhpic.pdf> [87 <./graphics/rhpic.pdf>]
<graphics/zeta0.pdf, id=2309, 233.89346pt x 228.84752pt>
File: graphics/zeta0.pdf Graphic file (type pdf)

<use graphics/zeta0.pdf>
<graphics/zeta1.pdf, id=2310, 362.4908pt x 236.40259pt>
File: graphics/zeta1.pdf Graphic file (type pdf)

<use graphics/zeta1.pdf> [88 <./graphics/zeta0.pdf> <./graphics/zeta1.pdf>]
<graphics/zeta2.png, id=2355, 400.49625pt x 377.41pt>
File: graphics/zeta2.png Graphic file (type png)
 <use graphics/zeta2.png>
Overfull \hbox (150.74327pt too wide) in paragraph at lines 4601--4601
[][][]\OT1/cmtt/m/n/10 10000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000267[] 
 []


Overfull \hbox (145.49332pt too wide) in paragraph at lines 4601--4601
[][][]\OT1/cmtt/m/n/10 38994629840785861384457662111217990522007745403201488128
25084038333387229965957683578348930338929160[] 
 []

[89 <./graphics/zeta2.png (PNG copy)>]
Overfull \hbox (145.49332pt too wide) in paragraph at lines 4601--4601
[][][]\OT1/cmtt/m/n/10 79473887545115165760984304429323579667762572891406147323
45836374084514192683933294095474801360397543[] 
 []

Missing character: There is no Â in font cmtt10!
Missing character: There is no µ in font cmtt10!

Overfull \hbox (1237.4838pt too wide) in paragraph at lines 4601--4601
[][][]\OT1/cmtt/m/n/10 89884656743115795386465259539451236680898848947115328636
7150405788663379027504815663542386612037680105600569399356966788293948844072083
1124642371531973706218888394671243274263815110980062304705972654147604250288441
9075341171231440736956555270413618581675255342293149119973622969239858152417678
164812112069763[] 
 []


Overfull \hbox (234.74254pt too wide) in paragraph at lines 4601--4601
[][][]\OT1/cmtt/m/n/10 <li>For math -- see <a href="http://wstein.org/ent " tar
get="_blank">http://wstein.org/ent&nbsp;</a>(chapter 3).</li>[] 
 []


Overfull \hbox (533.98993pt too wide) in paragraph at lines 4601--4601
[][][]\OT1/cmtt/m/n/10 <li>More on cryptography using Sage -- see the book by D
avid Kohel that is <a href="http://sagemath.org/library-publications.html#books
" target="_blank">listed here</a>.</li>[] 
 []


Overfull \hbox (392.24117pt too wide) in paragraph at lines 4601--4601
[][][]\OT1/cmtt/m/n/10 <li>There is a library called <a href="http://www.dlitz.
net/software/pycrypto/" target="_blank">PyCrypto</a> that is included with Sage
.&nbsp;</li>[] 
 []

[90] <graphics/group_law.pdf, id=2368, 179.29308pt x 350.5095pt>
File: graphics/group_law.pdf Graphic file (type pdf)

<use graphics/group_law.pdf> [91] [92 <./graphics/group_law.pdf>]
<graphics/birch.png, id=2412, 1368.11125pt x 681.54625pt>
File: graphics/birch.png Graphic file (type png)

<use graphics/birch.png> [93 <./graphics/birch.png (PNG copy)>]
<graphics/birch_paper.png, id=2433, 568.1225pt x 445.665pt>
File: graphics/birch_paper.png Graphic file (type png)

<use graphics/birch_paper.png>
<graphics/bsd_plot.pdf, id=2434, 479.88705pt x 196.78653pt>
File: graphics/bsd_plot.pdf Graphic file (type pdf)

<use graphics/bsd_plot.pdf> [94 <./graphics/birch_paper.png (PNG copy)>]
Overfull \hbox (7.35771pt too wide) in paragraph at lines 4817--4819
[][][]\OT1/cmr/m/n/10 This is a Clay Mil-lion Dol-lar prize prob-lem: []$[][]\O
T1/cmtt/m/n/10 http : / / www . claymath . org / millennium /
 []

[95 <./graphics/bsd_plot.pdf>] [96]
Chapter 9.

Overfull \hbox (533.98993pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 <p>See <a href="http://rpy.sourceforge.net/rpy2/doc-2.0/
html/introduction.html" target="_blank">http://rpy.sourceforge.net/rpy2/doc-2.0
/html/introduction.html</a>. &nbsp;</p>[] 
 []


Overfull \hbox (29.99432pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 <p>Note that we have to explicitly use print to see a ni
ce representation:</p>[] 
 []


Overfull \hbox (801.7376pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 <p>There is a pexpect interface to r called "r" by defau
lt when you start Sage. &nbsp;This tutorial is not about that interface, but in
stead about the C library interface called rpy2, which is much faster and more 
robust.</p>[] 
 []

Missing character: There is no Â in font cmtt10!
Missing character: There is no µ in font cmtt10!
Missing character: There is no Â in font cmtt10!
Missing character: There is no µ in font cmtt10!

Overfull \hbox (19.49442pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 <p>(frankly, I'm shocked at how slow the rpy2 interface 
actually is...!)</p>[] 
 []

[97

]
Overfull \hbox (119.24355pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 ValueError: Nothing can be done for the type <type 'sage
.rings.integer.Integer'> at the moment.[] 
 []


Overfull \hbox (24.74437pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 <p>WARNING: &nbsp;Python indexing starts at 0 and R inde
xing starts at 1.</p>[] 
 []

Missing character: There is no Â in font cmtt10!
Missing character: There is no µ in font cmtt10!
Missing character: There is no Â in font cmtt10!
Missing character: There is no µ in font cmtt10!

Overfull \hbox (166.49313pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 <p>Most R objects have a string representation that can 
be directly parsed by R, which can be handy.</p>[] 
 []

[98]
Missing character: There is no Â in font cmtt10!
Missing character: There is no µ in font cmtt10!

Overfull \hbox (40.49423pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 <p>You can also create R matrices, which are R vectors w
ith a dim attribute:</p>[] 
 []


Overfull \hbox (449.99066pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 <p>The above illustrates how to call an R function. &nbs
p;You get it from the R namespace, then call it in the standard way. &nbsp;Here
's another example:</p>[] 
 []

[99]
Missing character: There is no Â in font cmtt10!
Missing character: There is no µ in font cmtt10!
Missing character: There is no Â in font cmtt10!
Missing character: There is no µ in font cmtt10!

Overfull \hbox (1478.98169pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 <p>GOTCHA: In R variable names with dots in them are all
owed, but in Python they are not. &nbsp; The example below illustrates how to d
eal with this (use **kwds). &nbsp;In this example, we make an R vector with a "
NA" in it, which means we don't know that entry; the na.rm option to R's sum co
mmand controls how it behaves on lists with NA's in them.</p>[] 
 []


Overfull \hbox (113.99359pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 <p>Directly in R, we would just type na.rm=TRUE. &nbsp;I
n Python this does not make sense.</p>[] 
 []

[100]
Overfull \hbox (203.24281pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 <li>Call the R.png function to tell R where the output i
mage should be saved (and what size it should be).</li>[] 
 []


Overfull \hbox (140.24336pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 <li>Tell R to turn the plotting device off, which causes
 the output file to be written. &nbsp;</li>[] 
 []


Overfull \hbox (649.48892pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 <p>IMPORTANT: This must all happen in the same notebook 
cell. &nbsp;Otherwise the output file gets written in temp directory for a cell
 that was already evaluated, and the plot may not appear.</p>[] 
 []


Overfull \hbox (3.74455pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 ...       x = robjects.IntVector(range(points)); y = R.r
norm(int(points))[] 
 []


Overfull \hbox (87.74382pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 <p><strong>Warning again -- Do NOT do this:</strong> cal
l dev.off in a separate cell!</p>[] 
 []


Overfull \hbox (355.49149pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 <p>This is how we would do this directly in R, which we 
can use from Sage by using the "%r" mode in the notebook (or r.eval("""..."""))
:</p>[] 
 []

[101]
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ˜ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ™ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ˜ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ™ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ˜ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ™ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ˜ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ™ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ˜ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ™ in font cmtt10!

Overfull \hbox (124.4935pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 <p>Next, we do the same computation, but via rpy2 (which
 is unfortunately more complicated):</p>[] 
 []


Overfull \hbox (66.744pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 sage: ctl = robjects.FloatVector([4.17,5.58,5.18,6.11,4.
50,4.61,5.17,4.53,5.33,5.14])[] 
 []


Overfull \hbox (66.744pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 sage: trt = robjects.FloatVector([4.81,4.17,4.41,3.59,5.
87,3.83,6.03,4.89,4.32,4.69])[] 
 []

[102]
Overfull \hbox (113.99359pt too wide) in paragraph at lines 5319--5319
[][][]            \OT1/cmtt/m/n/10 stop(gettextf("number of offsets is %d, shou
ld equal %d (number of observations)",[] 
 []


Overfull \hbox (113.99359pt too wide) in paragraph at lines 5319--5319
[][][]            \OT1/cmtt/m/n/10 y, weights = w, rank = 0L, df.residual = if 
(is.matrix(y)) nrow(y) else length(y))[] 
 []


Overfull \hbox (3.74455pt too wide) in paragraph at lines 5319--5319
[][][]        \OT1/cmtt/m/n/10 else lm.wfit(x, y, w, offset = offset, singular.
ok = singular.ok,[] 
 []

[103]
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ˜ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ™ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ˜ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ™ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ˜ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ™ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ˜ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ™ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ˜ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ™ in font cmtt10!
 [104]
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ˜ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ™ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ˜ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ™ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ˜ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ™ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ˜ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ™ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ˜ in font cmtt10!
Missing character: There is no â in font cmtt10!
Missing character: There is no € in font cmtt10!
Missing character: There is no ™ in font cmtt10!

Overfull \hbox (801.7376pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 <p>In R a "data frame" is an array of values with labele
d rows and columns (like part of a spreadsheet). &nbsp;Typically one thinks of 
a data frame as a table where the rows are observations and the columns are var
iables.</p>[] 
 []


Overfull \hbox (1557.731pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 <p>If you are using rpy2 and Sage together to deal with 
large real-world data sets, then it is critical that you can quickly move data 
back and forth. &nbsp; If you're working with big data in Sage, you're probably
 using numpy arrays. &nbsp;Fortunately, there is a way to very quickly convert 
a big numpy array to an R vector and conversely, as we illustrate below.</p>[] 

 []


Overfull \hbox (1006.48581pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 <p>NOTE: The rpy2 documentation suggests doing "import r
py2.robjects.numpy2ri" but this is broken (at least with the versions of R, rpy
2, and numpy in Sage), and gives totally wrong results. &nbsp;So just explicitl
y use FloatVector, etc., as illustrated below.</p>[] 
 []


Overfull \hbox (50.99414pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 ValueError: Nothing can be done for the type <type 'nump
y.ndarray'> at the moment.[] 
 []

[105]
Overfull \hbox (276.74217pt too wide) in paragraph at lines 5319--5319
[][][]\OT1/cmtt/m/n/10 <p>... CRAP, this seems to be just totally broken in rpy
2. &nbsp;Maybe it is fixed in a newer version. &nbsp;Sorry folks.</p>[] 
 []

[106]
Chapter 10.

Overfull \hbox (712.48837pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 <p>The first page of "abstract mathematics" that I ever 
saw, accidentally misfiled in a the computer book section of Bookman's in Flags
taff.  (Burton W. Jones's "An Introduction to Modern Algebra", 1975.)</p>[] 
 []


Overfull \hbox (329.24171pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 <p>A group is a set $G$ equipped with a binary operation
 $G \times G \to G$ that we write as a dot below that has three properties:</p>
[] 
 []


Overfull \hbox (66.744pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 <li><strong>Associativity</strong>: &nbsp;$(a\cdot b)\cd
ot c = a\cdot(b\cdot c)$</li>[] 
 []


Overfull \hbox (255.74236pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 <li><strong>Existence of identity</strong>: There is $1\
in G$ such that $1\cdot a = a\cdot 1 = a$ for all $a \in G$.</li>[] 
 []


Overfull \hbox (339.74162pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 <li><strong>Existence of inverse</strong>: For each $a\i
n G$ there is $a^{-1} \in G$ such that $a^{-1} \cdot a = a\cdot a^{-1} = 1$.</l
i>[] 
 []


Overfull \hbox (129.74345pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 <p>We construct objects in Sage that have a binary opera
tion satisfying the above properties.</p>[] 
 []


Overfull \hbox (35.24428pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 <p>If it is 7am, what time will it be 10 hours from now?
 &nbsp;Answer: 5pm.</p>[] 
 []

[107

]
Overfull \hbox (134.99341pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 Abelian group of points on Elliptic Curve defined by y^2
 + y = x^3 + x^2 - 2*x over Rational Field[] 
 []


Overfull \hbox (35.24428pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 Elliptic Curve defined by y^2 + y = x^3 + x^2 + 5*x over
 Finite Field of size 7[] 
 []


Overfull \hbox (176.99304pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 Abelian group of points on Elliptic Curve defined by y^2
 + y = x^3 + x^2 + 5*x over Finite Field of size 7[] 
 []

[108]
Overfull \hbox (24.74437pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 <h3>The Group of orientation preserving symmetries of th
e icosahedron...</h3>[] 
 []


Overfull \hbox (61.49405pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 <html><div class="math">\newcommand{\Bold}[1]{\mathbf{#1
}}\left(\begin{array}{rrrrr}[] 
 []


Overfull \hbox (50.99414pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 3 & -1 & 0 & \zeta_{5}^{3} + \zeta_{5}^{2} + 1 & -\zeta_
{5}^{3} - \zeta_{5}^{2} \\[] 
 []


Overfull \hbox (50.99414pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 3 & -1 & 0 & -\zeta_{5}^{3} - \zeta_{5}^{2} & \zeta_{5}^
{3} + \zeta_{5}^{2} + 1 \\[] 
 []


Overfull \hbox (1767.72917pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 <html><div class="math">\newcommand{\Bold}[1]{\mathbf{#1
}}x = \frac{{\left(-i \, \sqrt{3} + 1\right)} a}{6 \, {\left(\frac{1}{18} \, \s
qrt{4 \, a^{3} + 27 \, b^{2}} \sqrt{3} - \frac{1}{2} \, b\right)}^{\left(\frac{
1}{3}\right)}} - \frac{1}{2} \, {\left(i \, \sqrt{3} + 1\right)} {\left(\frac{1
}{18} \, \sqrt{4 \, a^{3} + 27 \, b^{2}} \sqrt{3} - \frac{1}{2} \, b\right)}^{\
left(\frac{1}{3}\right)}</div></html>[] 
 []


Overfull \hbox (14.24446pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 sage: G = GL(2, GF(5)); G   # 2x2 invertible matrices wi
th entries modulo 5[] 
 []

[109]
Overfull \hbox (134.99341pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 AttributeError: 'SpecialLinearGroup_finite_field_with_ca
tegory' object has no attribute 'subgroup'[] 
 []


Overfull \hbox (1368.73265pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 <p>See the <a href="http://www.sagemath.org/doc/referenc
e/sage/groups/perm_gps/cubegroup.html" target="_blank">Sage docs</a>&nbsp;and <
a href="http://en.wikipedia.org/wiki/Rubik's_cube_group" target="_blank">Wikipe
dia</a>. &nbsp;See also <a href="http://trac.sagemath.org/sage_trac/ticket/1136
0" target="_blank">my complaint.</a></p>[] 
 []


Overfull \hbox (1793.97894pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 ['(33,35,40,38)(34,37,39,36)( 3, 9,46,32)( 2,12,47,29)( 
1,14,48,27)', '(41,43,48,46)(42,45,47,44)(14,22,30,38)(15,23,31,39)(16,24,32,40
)', '(17,19,24,22)(18,21,23,20)( 6,25,43,16)( 7,28,42,13)( 8,30,41,11)', '( 9,1
1,16,14)(10,13,15,12)( 1,17,41,40)( 4,20,44,37)( 6,22,46,35)', '(25,27,32,30)(2
6,29,31,28)( 3,38,43,19)( 5,36,45,21)( 8,33,48,24)', '( 1, 3, 8, 6)( 2, 5, 7, 4
)( 9,33,25,17)(10,34,26,18)(11,35,27,19)'][] 
 []


Overfull \hbox (218.99268pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 <p>An <strong>abelian group</strong> is a group $G$ wher
e for every $a,b \in G$ we have $a\cdot b = b\cdot a$.</p>[] 
 []


Overfull \hbox (192.7429pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 <p>An<strong> monoid</strong> is the same as a group, ex
cept we do not require the existence of inverses.</p>[] 
 []


Overfull \hbox (134.99341pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 <p>A <strong>ring</strong> $R$ is a set with two binary 
operations, $+$ and $\cdot$ such that:</p>[] 
 []


Overfull \hbox (119.24355pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 <li>$(R^*,\cdot)$ is an abelian monoid, where $R^*$ is t
he set of nonzero elements of $R$,</li>[] 
 []


Overfull \hbox (19.49442pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 <li>For all $a,b,c \in R$ we have $a\cdot (b+c) = a\cdot
 b + a\cdot c$.</li>[] 
 []


Overfull \hbox (50.99414pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 <p>A <strong>field</strong> $K$ is a ring such that $(R^
*, \cdot)$ is a group.</p>[] 
 []


Overfull \hbox (108.74364pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 <p>Like with groups, Sage (and mathematics!) comes loade
d with numerous rings and fields.</p>[] 
 []

[110]
Overfull \hbox (334.49167pt too wide) in paragraph at lines 5519--5519
[][][]\OT1/cmtt/m/n/10 <p>Just as for groups, there is much advanced functional
ity available for rings (e.g., Groebner basis), but this is another story...</p
>[] 
 []

[111]
Overfull \hbox (0.38675pt too wide) in paragraph at lines 5582--5583
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][] 
 []


Overfull \hbox (0.38675pt too wide) in paragraph at lines 5583--5584
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] 
 []


Overfull \hbox (0.38675pt too wide) in paragraph at lines 5588--5589
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][] 
 []


Overfull \hbox (0.38675pt too wide) in paragraph at lines 5589--5590
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] 
 []

[112]
Overfull \hbox (11.72672pt too wide) in paragraph at lines 5627--5628
[][][][][][] 
 []


Overfull \hbox (11.72672pt too wide) in paragraph at lines 5628--5629
[][][][][][][][] 
 []


Overfull \hbox (11.72672pt too wide) in paragraph at lines 5629--5630
[][][][][][] 
 []


Overfull \hbox (11.72672pt too wide) in paragraph at lines 5630--5631
[][][][][][] 
 []


Overfull \hbox (11.72672pt too wide) in paragraph at lines 5631--5632
[][][][][][] 
 []


Overfull \hbox (11.72672pt too wide) in paragraph at lines 5639--5640
[][][][][][] 
 []


Overfull \hbox (11.72672pt too wide) in paragraph at lines 5640--5641
[][][][][][][][] 
 []


Overfull \hbox (11.72672pt too wide) in paragraph at lines 5641--5642
[][][][][][] 
 []


Overfull \hbox (11.72672pt too wide) in paragraph at lines 5642--5643
[][][][][][] 
 []


Overfull \hbox (11.72672pt too wide) in paragraph at lines 5643--5644
[][][][][][] 
 []


Overfull \hbox (57.08658pt too wide) in paragraph at lines 5663--5664
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][][][][][][][][][] 
 []

[113]
Overfull \hbox (0.38675pt too wide) in paragraph at lines 5694--5695
[][][][][][][][][][][][][][][][][][][][][][][][][][][][] 
 []

[114] [115] [116]
Overfull \hbox (6.05673pt too wide) in paragraph at lines 5888--5889
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] 
 []

[117]
Chapter 11.

Overfull \hbox (0.38675pt too wide) in paragraph at lines 5947--5948
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] 
 []

[118

]
Overfull \hbox (2.02596pt too wide) in paragraph at lines 5977--5984
[][]\OT1/cmr/m/n/10 The \OT1/cmtt/m/n/10 save \OT1/cmr/m/n/10 and \OT1/cmtt/m/n
/10 load \OT1/cmr/m/n/10 com-mands from Sec-tion []11.1.1[] above are im-ple-me
nted us-ing Python's
 []

[119]
Overfull \hbox (147.8063pt too wide) in paragraph at lines 6041--6042
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] 
 []


Overfull \hbox (23.06668pt too wide) in paragraph at lines 6043--6044
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][] 
 []


Overfull \hbox (23.06668pt too wide) in paragraph at lines 6068--6069
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][] 
 []

Missing character: There is no Â in font cmtt9!
Missing character: There is no µ in font cmtt9!
Missing character: There is no Â in font cmtt9!
Missing character: There is no µ in font cmtt9!
[120]
Missing character: There is no Â in font cmtt9!
Missing character: There is no µ in font cmtt9!
Missing character: There is no Â in font cmtt9!
Missing character: There is no µ in font cmtt9!

Overfull \hbox (539.03513pt too wide) in paragraph at lines 6104--6105
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][] 
 []

[121] [122]
Overfull \hbox (119.45639pt too wide) in paragraph at lines 6225--6226
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] 
 []


Overfull \hbox (816.86429pt too wide) in paragraph at lines 6260--6261
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][
][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][] 
 []


Overfull \hbox (497.24025pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 <p>loads can parse both the compressed and uncompressed 
pickles (it figures out which is right by assuming compressed, getting an error
, then trying uncompressed).</p>[] 
 []

[123]
Missing character: There is no Â in font cmtt10!
Missing character: There is no µ in font cmtt10!
Missing character: There is no Â in font cmtt10!
Missing character: There is no µ in font cmtt10!

Overfull \hbox (103.49368pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 sage: X = load('http://wiki.wstein.org/11/480a/5-25?acti
on=AttachFile&do=get&target=A.sobj')[] 
 []


Overfull \hbox (176.99304pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 Attempting to load remote file: http://wiki.wstein.org/1
1/480a/5-25?action=AttachFile&do=get&target=A.sobj[] 
 []


Overfull \hbox (197.99286pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 sage: X = load('http://wiki.wstein.org/11/480a/5-25?acti
on=AttachFile&do=get&target=A.sobj', verbose=False); X[] 
 []


Overfull \hbox (686.2386pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 <li>Understanding object serialization is useful if you 
do some research computations, and want to record the results in a way that you
 can later easily recover. As long as later isn't "too late".  </li>[] 
 []


Overfull \hbox (334.49167pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 <li>It requires very little thought to use.  <strong>sav
e(obj, 'filename.sobj') </strong>and <strong>load('filename.sobj')</strong></li
>[] 
 []


Overfull \hbox (1011.73576pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 <li>You could make a simple "database" that anybody can 
easily use over the web by: (1) putting a bunch of sobj's on a webpage, and (2)
 writing a Python function that uses Sage's load command to remotely grab them 
off that webpage when requested. Very simple. </li>[] 
 []


Overfull \hbox (1730.97949pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 <p>If you want to store a plain string to disk, and load
 it later, it is critical to master the Python <strong>open</strong> command.  
This is very similar to the C library open command, hence to the open command i
n most programming languages.  You can use this one builtin Python command to b
oth read and write files, and also to iterate through the lines of a file, seek
 to given positions, etc. </p>[] 
 []

[124]
Overfull \hbox (806.98755pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 <p>One can do a lot with a file, or a bunch of files in 
a directory.  Don't use a sophisticated database just because you don't underst
and or know how to use files.  Now you do.  In some cases, they are a great sol
ution.  </p>[] 
 []


Overfull \hbox (103.49368pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 <p>Here's a nice decorator (written by Tom Boothby) that
 combines files with pickling.  </p>[] 
 []


Overfull \hbox (213.74272pt too wide) in paragraph at lines 6407--6407
[][][]  \OT1/cmtt/m/n/10 <p><strong>File:</strong> /sagenb/flask/sage-4.6.2/loc
al/lib/python2.6/site-packages/sage/misc/cachefunc.py</p>[] 
 []


Overfull \hbox (229.49258pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 <p>Decorator for <tt class="xref py py-class docutils li
teral"><span class="pre">DiskCachedFunction</span></tt>.</p>[] 
 []


Overfull \hbox (764.98792pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 <div class="highlight-python"><div class="highlight"><pr
e class="literal-block"><span class="gp">sage: </span><span class="nb">dir</spa
n> <span class="o">=</span> <span class="n">tmp_dir</span><span class="p">()</s
pan>[] 
 []


Overfull \hbox (407.99103pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 <span class="gp">sage: </span><span class="nd">@disk_cac
hed_function</span><span class="p">(</span><span class="nb">dir</span><span cla
ss="p">)</span>[] 
 []


Overfull \hbox (1657.48013pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 <span class="gp">... </span><span class="k">def</span> <
span class="nf">foo</span><span class="p">(</span><span class="n">x</span><span
 class="p">):</span> <span class="k">return</span> <span class="n">next_prime</
span><span class="p">(</span><span class="mi">2</span><span class="o">^</span><
span class="n">x</span><span class="p">)</span><span class="o">%</span><span cl
ass="n">x</span>[] 
 []


Overfull \hbox (701.98846pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 <span class="gp">sage: </span><span class="n">x</span> <
span class="o">=</span> <span class="n">foo</span><span class="p">(</span><span
 class="mi">200</span><span class="p">);</span><span class="n">x</span>[] 
 []


Overfull \hbox (407.99103pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 <span class="gp">sage: </span><span class="nd">@disk_cac
hed_function</span><span class="p">(</span><span class="nb">dir</span><span cla
ss="p">)</span>[] 
 []


Overfull \hbox (980.23604pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 <span class="gp">... </span><span class="k">def</span> <
span class="nf">foo</span><span class="p">(</span><span class="n">x</span><span
 class="p">):</span> <span class="k">return</span> <span class="mi">1</span><sp
an class="o">/</span><span class="n">x</span>[] 
 []


Overfull \hbox (308.2419pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 <span class="gp">sage: </span><span class="n">foo</span>
<span class="p">(</span><span class="mi">200</span><span class="p">)</span>[] 
 []


Overfull \hbox (350.24153pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 <span class="gp">sage: </span><span class="n">foo</span>
<span class="o">.</span><span class="n">clear_cache</span><span class="p">()</s
pan>[] 
 []


Overfull \hbox (308.2419pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 <span class="gp">sage: </span><span class="n">foo</span>
<span class="p">(</span><span class="mi">200</span><span class="p">)</span>[] 
 []

[125]
Overfull \hbox (344.99158pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 ['my_factor-18268770466636286477546060408953537745699156
7873.sobj', 'my_factor-182687704666362864775460604089535377456991567873.key.sob
j'][] 
 []


Overfull \hbox (1069.48526pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 ['my_factor-18268770466636286477546060408953537745699156
7875.sobj', 'my_factor-182687704666362864775460604089535377456991567875.key.sob
j', 'my_factor-182687704666362864775460604089535377456991567873.sobj', 'my_fact
or-182687704666362864775460604089535377456991567873.key.sobj'][] 
 []


Overfull \hbox (229.49258pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 (((182687704666362864775460604089535377456991567875,), (
)), 5^3 * 557 * 2623880856967509727475197186205175977838299)[] 
 []


Overfull \hbox (560.2397pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 <li><strong>save/load:</strong> If you remember nothing 
else from today's lecture, remember these two commands, which allow you to very
 easily store and load most any object.</li>[] 
 []


Overfull \hbox (113.99359pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 <li><strong>open</strong>: It is easy to open and write 
to and read from files in Python.</li>[] 
 []


Overfull \hbox (2754.72057pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 <li><strong>disk_cached_function:</strong> provides a fu
nction decorator that makes a function only ever have to evaluate a given input
 once, and in the future it just remembers the inputs automatically.  It combin
es pickling with using open to read and write data to the filesystem. You can m
anage the cached inputs to the function outside of Sage, just by adding files t
o the cache directory (e.g., if you computed values of a disk_cached_function o
n different computers, you could just dump all the directories of files that re
sult into a single big directory and have the combined cache).</li>[] 
 []


Overfull \hbox (1720.47958pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 <li><a href="http://www.sqlite.org/" target="_blank">SQL
ite</a>: a <em>relational database </em>that is included in Sage.  This is not 
at all Python specific, but it has excellent support for using it from Python. 
 It's an extremely popular database -- according to their website it is <em>the
 most widely deployed database</em> there is.  For example, iPhone apps all use
 it track their data...</li>[] 
 []


Overfull \hbox (1106.23494pt too wide) in paragraph at lines 6407--6407
[][][]\OT1/cmtt/m/n/10 <li>(Maybe) <a href="http://www.sqlalchemy.org/" target=
"_blank">SQLalchemy</a>: an <em>object relational mapper </em>that is included 
in Sage.  SQLalchemy provides much more Python-friendly support on top of some 
relational database, but built on SQLite or MySQL or PostgreSQL.</li>[] 
 []


Overfull \hbox (239.9925pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <p>Check out <a href="http://www.sqlite.org/" target="_b
lank">the SQLite website.</a>&nbsp; &nbsp;Some key points:</p>[] 
 []


Overfull \hbox (82.49387pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <li>SQLite is surely the most widely deployed database i
n the world, in some sense.</li>[] 
 []


Overfull \hbox (108.74364pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <li>SQLite is vastly simpler to use and administer than 
pretty much all other databases.</li>[] 
 []


Overfull \hbox (239.9925pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <li>SQLite is <strong>public domain. &nbsp;</strong>You 
can do absolutely anything you want with the source code.</li>[] 
 []


Overfull \hbox (213.74272pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <li>Learning about SQLite may server you well in non-Sag
e related projects, since it can be used on its own.</li>[] 
 []

[126]
Overfull \hbox (113.99359pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <p>Here's a complete example of using SQLite to make a d
atabase of integer factorizations.</p>[] 
 []


Overfull \hbox (14.24446pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 sage: # Make sure the database file isn't left over from
 a previous demo...[] 
 []


Overfull \hbox (45.74419pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 sage: cursor.execute("CREATE INDEX factorizations_idx ON
 factorizations(number)")[] 
 []


Overfull \hbox (145.49332pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <p>We can look at our new database on the command line, 
completely independently of Sage/Python:</p>[] 
 []


Overfull \hbox (171.74309pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <p>By the way, the UNIQUE above makes it so you can't en
ter another factorization of the same number.</p>[] 
 []


Overfull \hbox (24.74437pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 ...           z = cursor.execute('INSERT INTO factorizat
ions VALUES(?,?)', t)[] 
 []

[127]
Overfull \hbox (3.74455pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 sage: a = cursor.execute('SELECT * FROM factorizations O
RDER BY number;')[] 
 []


Overfull \hbox (187.49295pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <p>We use the command line again (we <strong><em>do not<
/em></strong> have to exit or reload!) and find:</p>[] 
 []


Overfull \hbox (890.98682pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <p>Obviously, to use SQLite effectively, it helps enormo
usly to know the SQL language. &nbsp; Fortunately, you don't need to know very 
much, there are tons of examples on the web, many tutorials, books, and SQL isn
't hard to learn. &nbsp;</p>[] 
 []


Overfull \hbox (507.74016pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <p>Python documentation for the sqlite3 module: <a href=
"http://docs.python.org/library/sqlite3.html" target="_blank">http://docs.pytho
n.org/library/sqlite3.html</a></p>[] 
 []


Overfull \hbox (827.98737pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <p>Next we'll spend a few moments on <a href="http://www
.sqlalchemy.org/" target="_blank">SQLAlchemy</a>, which is a Python package inc
luded standard with Sage, which can also be installed easily into any Python in
stall.&nbsp;</p>[] 
 []


Overfull \hbox (197.99286pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <li>SQLAlchemy is the <strong><em>canonical</em></strong
> "object relational database mapper" for Python.</li>[] 
 []


Overfull \hbox (350.24153pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <li>SQLAlchemy abstracts away the database backend, so t
he same code/application can work with SQLite, PostgreSQL, Oracle, MySQL, etc.<
/li>[] 
 []


Overfull \hbox (192.7429pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <li>SQLAlchemy has a large test suite, good documentatio
n, and is a high quality polished product.&nbsp;</li>[] 
 []


Overfull \hbox (1405.48233pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <p><strong>WARNING:</strong> As of this writing (May 27,
 2011) the version of SQLAlchemy in the newest Sage (which is Sage-4.7) is the 
"ancient" 0.5.8 version. &nbsp;So make sure to look at the right version of the
 SQLAlchemy docs here: <a href="http://www.sqlalchemy.org/docs/05/" target="_bl
ank">http://www.sqlalchemy.org/docs/05/</a></p>[] 
 []


Overfull \hbox (66.744pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <p>We will use the file /tmp/sqlite1 for our demo. &nbsp
;Make sure it is deleted.</p>[] 
 []

[128]
Overfull \hbox (297.74199pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <p>Create a SQLite engine, which SQLalchemy will use. &n
bsp;This is the only place below that SQLite is explicitly mentioned.</p>[] 
 []


Overfull \hbox (229.49258pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <p>Use SQLalchemy to declare a new Python class, which w
ill get mapped to a table in the above SQLlite database.</p>[] 
 []


Overfull \hbox (19.49442pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 ...           self.factorization = str(list(factor(numbe
r))).replace(' ','')[] 
 []


Overfull \hbox (208.49277pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <p>Create the tables. &nbsp;In this case, there is exact
ly one, which corresponds to the IntFac class above.</p>[] 
 []


Overfull \hbox (3.74455pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <p>And add it to our session, so it will get tracked by 
the database.</p>[] 
 []


Overfull \hbox (575.98956pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <p>Commit everything we have done so far. &nbsp;After th
is commit, the database exists separately on a disk on file, and we can inspect
 it using the sqlite3 command line program.</p>[] 
 []


Overfull \hbox (350.24153pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <p>We try adding the factorization of 6 again. &nbsp;Thi
s should give an error because number is the primary key, hence must be unique.
</p>[] 
 []

[129]
Overfull \hbox (533.98993pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 sqlalchemy.orm.exc.FlushError: New instance <IntFac at 0
x596d790> with identity key (<class '__main__.IntFac'>, (6,)) conflicts with pe
rsistent instance <IntFac at 0x579d190>[] 
 []


Overfull \hbox (45.74419pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <p>Once an error occurs the only option is to rollback t
he whole transaction.</p>[] 
 []


Overfull \hbox (266.24226pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <p>Let's make a few thousand factorization (like we did 
above) and include them all in one transaction in the database.</p>[] 
 []


Overfull \hbox (40.49423pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <p>Using add_all should be more efficient than calling a
dd many times.&nbsp;</p>[] 
 []


Overfull \hbox (134.99341pt too wide) in paragraph at lines 6613--6613
[][][]\OT1/cmtt/m/n/10 <p>Now we have factorizations of all integers up to 1000
0. &nbsp;We can do a query like above.</p>[] 
 []

(./sagebook.bbl [130])
Package atveryend Info: Empty hook `BeforeClearDocument' on input line 6621.
 [131

]
Package atveryend Info: Empty hook `AfterLastShipout' on input line 6621.
 (./sagebook.aux)
Package atveryend Info: Executing hook `AtVeryEndDocument' on input line 6621.
Package rerunfilecheck Info: File `sagebook.out' has not changed.
(rerunfilecheck)             Checksum: E46E2EF70CCF0A89E41E762E395B4EAB;5597.


LaTeX Warning: There were undefined references.

 ) 
Here is how much of TeX's memory you used:
 10513 strings out of 493747
 148630 string characters out of 3143546
 290592 words of memory out of 3000000
 11555 multiletter control sequences out of 15000+200000
 14812 words of font info for 58 fonts, out of 3000000 for 9000
 714 hyphenation exceptions out of 8191
 36i,16n,51p,3526b,1732s stack positions out of 5000i,500n,10000p,200000b,50000s
</usr/local/texlive/2010/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx10.pfb
></usr/local/texlive/2010/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx12.pfb>
</usr/local/texlive/2010/texmf-dist/fonts/type1/public/amsfonts/cm/cmex10.pfb><
/usr/local/texlive/2010/texmf-dist/fonts/type1/public/amsfonts/cmextra/cmex8.pf
b></usr/local/texlive/2010/texmf-dist/fonts/type1/public/amsfonts/cm/cmmi10.pfb
></usr/local/texlive/2010/texmf-dist/fonts/type1/public/amsfonts/cm/cmmi5.pfb><
/usr/local/texlive/2010/texmf-dist/fonts/type1/public/amsfonts/cm/cmmi6.pfb></u
sr/local/texlive/2010/texmf-dist/fonts/type1/public/amsfonts/cm/cmmi7.pfb></usr
/local/texlive/2010/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb></usr/l
ocal/texlive/2010/texmf-dist/fonts/type1/public/amsfonts/cm/cmr12.pfb></usr/loc
al/texlive/2010/texmf-dist/fonts/type1/public/amsfonts/cm/cmr17.pfb></usr/local
/texlive/2010/texmf-dist/fonts/type1/public/amsfonts/cm/cmr5.pfb></usr/local/te
xlive/2010/texmf-dist/fonts/type1/public/amsfonts/cm/cmr6.pfb></usr/local/texli
ve/2010/texmf-dist/fonts/type1/public/amsfonts/cm/cmr7.pfb></usr/local/texlive/
2010/texmf-dist/fonts/type1/public/amsfonts/cm/cmr8.pfb></usr/local/texlive/201
0/texmf-dist/fonts/type1/public/amsfonts/cm/cmss10.pfb></usr/local/texlive/2010
/texmf-dist/fonts/type1/public/amsfonts/cm/cmsy10.pfb></usr/local/texlive/2010/
texmf-dist/fonts/type1/public/amsfonts/cm/cmsy7.pfb></usr/local/texlive/2010/te
xmf-dist/fonts/type1/public/amsfonts/cm/cmsy8.pfb></usr/local/texlive/2010/texm
f-dist/fonts/type1/public/amsfonts/cm/cmti10.pfb></usr/local/texlive/2010/texmf
-dist/fonts/type1/public/amsfonts/cm/cmtt10.pfb></usr/local/texlive/2010/texmf-
dist/fonts/type1/public/amsfonts/cm/cmtt12.pfb></usr/local/texlive/2010/texmf-d
ist/fonts/type1/public/amsfonts/cm/cmtt8.pfb></usr/local/texlive/2010/texmf-dis
t/fonts/type1/public/amsfonts/cm/cmtt9.pfb></usr/local/texlive/2010/texmf-dist/
fonts/type1/public/amsfonts/symbols/msbm10.pfb>
Output written on sagebook.pdf (132 pages, 2623637 bytes).
PDF statistics:
 3581 PDF objects out of 4296 (max. 8388607)
 3325 compressed objects within 34 object streams
 2087 named destinations out of 2487 (max. 500000)
 709 words of extra memory for PDF output out of 10000 (max. 10000000)

