You are on page 1of 4

11/ 10/ 12

A Tour of Sage A Tour of Sage v5. 3

A Tour of Sage
This is a tour of Sage that closely follows the tour of Mathematica that is at the beginning of the Mathematica Book.

Sage as a Calculator
The Sage command line has a s g : prompt; you do not have to add it. If you use the Sage ae notebook, then put everything after the s g : prompt in an input cell, and press shift-enter to ae compute the corresponding output.
sg:3+5 ae 8

The caret symbol means raise to a power.


sg:5. ^10 ae 71 0 46946619e7 .003863615

We compute the inverse of a

matrix in Sage.

sg:mti([,] [,])(1 ae arx[12, 34]^-) [ 2 1 ] [32-/] / 12

Here we integrate a simple function.

sg:x=vr'' ae a(x) #cet asmoi vral rae yblc aibe sg:itgaesr()sr(+) x ae nert(qtx*qt1x, ) 14(x+1^32/^32 +sr( +1/qtx)(x+1^/^ -2( +1/ +1 +1 /*( )(/)x(/) qtx )sr()/( )2x2 *x )x ) /

This asks Sage to solve a quadratic equation. The symbol = represents equality in Sage. =
sg:a=vr'' ae a(a) sg:S=slex2+x= a x;S ae ov(^ = , ) [ = -/*qt4a+1 -12 x= 12sr(* +1 -12 x = 12sr(* ) /, = /*qt4a ) /]

The result is a list of equalities.


sg:S0.h( ae []rs) -/*qt4a+1 -12 12sr(* ) / sg:so(ltsnx +sn16x,0 4) ae hwpo(i() i(.*) , 0)

w w sagem at h. or g/ doc/ a_t our _of _sage/ w.

1/ 4

11/ 10/ 12

A Tour of Sage A Tour of Sage v5. 3

Power Computing with Sage


First we create a matrix of random numbers.
sg:m=rno_arxRF50 ae admmti(D,0)

It takes Sage a few seconds to compute the eigenvalues of the matrix and plot them.
sg:e=megnaus) #bu 2scns ae .ievle( aot eod sg:w=[i asei) frii rnelne) ae (, b([]) o n ag(e()] sg:so(onsw) ae hwpit()

w w sagem at h. or g/ doc/ a_t our _of _sage/ w.

2/ 4

11/ 10/ 12

A Tour of Sage A Tour of Sage v5. 3

Thanks to the GNU Multiprecision Library (GMP), Sage can handle very large numbers, even numbers with millions or billions of digits.

sg:fcoil10 ae atra(0) 93614341286938667097562486165268515992916844 32254945619285260401986312489939279932950916 sg:n=fcoil1000 #bu 25scns ae atra(000) aot . eod

This computes at least 100 digits of .

sg:Np,dgt=0) ae (i iis10 31196387334243375281763971529445208602609820 .4525599286638290849199350807949371468289683

This asks Sage to factor a polynomial in two variables.


sg:R<,>=Q[ ae .xy Q] sg:F=fco(^9+y9) ae atrx9 ^9 sg:F ae ( +y *(^ -xy+y2 *(^ -x3y3+y6 * x ) x2 * ^) x6 ^*^ ^) (^0-x9y+x8y2-x7y3+x6y4-x5y5+ x1 ^* ^*^ ^*^ ^*^ ^*^ x4y6-x3y7+x2y8-xy9+y1)* ^*^ ^*^ ^*^ *^ ^0
w w sagem at h. or g/ doc/ a_t our _of _sage/ w. 3/ 4

11/ 10/ 12

A Tour of Sage A Tour of Sage v5. 3

(^0+x1* -x1*^ -x1*^ +x1*^ +x1*^ x2 ^9y ^7y3 ^6y4 ^4y6 ^3y7 x1*^ -x1*^0-x9y1 +x7y1 +x6y1 ^1y9 ^0y1 ^*^1 ^*^3 ^*^4 x4y1 -x3y1 +xy1 +y2)*(^0+x5*^ ^*^6 ^*^7 *^9 ^0 x6 ^7y3 x5*^ -x4*^2+x4*^8+x3*^1-x3*^7^1y9 ^8y1 ^2y1 ^9y2 ^3y2 x3*^0-x2*^3+x2*^9+x1*^2-x1*^8^0y3 ^7y3 ^1y3 ^8y4 ^2y4 x9y5 +x3y5 +y6) ^*^1 ^*^7 ^0 sg:Fepn( ae .xad) x9 +y9 ^9 ^9

Sage takes just under 5 seconds to compute the numbers of ways to partition one hundred million as a sum of positive integers.
sg:z=Priin(08.adnlt( #bu 45scns ae attos1^)criaiy) aot . eod sg:srz[4] ae t():0 '70105429430784715009 16574964116339693240'

Accessing Algorithms in Sage


Whenever you use Sage you are accessing one of the worlds largest collections of open source computational algorithms.

w w sagem at h. or g/ doc/ a_t our _of _sage/ w.

4/ 4

You might also like