Sage Quick Reference (Basic Math)Peter Jipsen, version 1.1
latest version at wiki.sagemath.org/quickref
GNU Free Document License, extend for your own use
Aim: map standard math notation to Sage commands
Notebook (and commandline)
Evaluate cell: hshift-enteri
comhtabi tries to complete command
command ?htabi shows documentationcommand ??htabi shows sourcea.htabi shows all methods for object a (more: dir(a))
search_doc(’string or regexp’) shows links to docs
search_src(’string or regexp’) shows links to source
lprint() toggle LaTeX output modeversion() print version of Sage
Insert cell: click on blue line between cells
Delete cell: delete content then backspace
Numerical types
Integers: Z = ZZ e.g. -2 -1 0 1 10^100
Rationals: Q = QQ e.g. 1/2 1/1000 314/100 -42
Decimals: R ≈ RR e.g. .5 0.001 3.14 -42.
Complex: C ≈ CC e.g. 1+i 2.5-3*i

find_root(f(x), a, b) find x ∈ [a, b] s.t. f (x) ≈ 0nXf (i) = sum([f(i) for i in [k..n]])i=kn
Yf (i) = prod([f(i) for i in [k..n]])i=kCalculus
lim f (x) = limit(f(x), x=a)x→alim f (x) = limit(f(x), x=a, dir=’minus’)x→a−lim f (x) = limit(f(x), x=a, dir=’plus’)

x→a+ddx (f (x)) = diff(f(x),x)∂∂x (f (x, y)) = diff(f(x,y),x)diff = differentiate = derivativeRf (x)dx = integral(f(x),x)
integral = integrateRbf (x)dx = integral(f(x),x,a,b)
aTaylor polynomial, deg n about a: taylor(f(x),x,a,n)

options e.g. aspect ratio=[1, 1, 1] color=’red’ opacity
plot3d(f(x, y),[xb ,xe ],[yb ,ye ],options)add option plot_points=[m, n] or use plot3d adaptive
parametric plot3d((f(t),g(t),h(t)),[tb ,te ],options)parametric plot3d((f(u, v),g(u, v),h(u, v)),
[ub ,ue ],[vb ,ve ],options)use + to combine graphics objects
Discrete mathbxc = floor(x) dxe = ceil(x)Remainder of n divided by k = n%k
k|n iff n%k==0
xn! = factorial(n)m = binomial(x,m)φ = golden_ratio
φ(n) = euler phi(n)Strings: e.g. s = ’Hello’ = "Hello" = ""+"He"+’llo’
s[0]=’H’s[-1]=’o’s[1:3]=’el’s[3:]=’lo’
Lists: e.g. [1,’Hello’,x] = []+[1,’Hello’]+[x]Tuples: e.g. (1,’Hello’,x) (immutable)
Sets: e.g. {1, 2, 1, a} = Set([1,2,1,’a’]) (= {1, 2, a})
List comprehension ≈ set builder notation, e.g.
{f (x) : x ∈ X, x > 0} = Set([f(x) for x in X if x>0])

2d graphicsline([(x1 ,y1 ),. . .,(xn ,yn )],options)Linear algebra
polygon([(x1 ,y1 ),. . .,(xn ,yn )],options) 
1circle((x,y),r,options)= vector([1,2])
2
text("txt",(x,y),options)
1 2Basic constants and functions
options as in plot.options, e.g. thickness=pixel ,= matrix([[1,2],[3,4]])3 4Constants: π = pi e = e i = i ∞ = oo
rgbcolor=(r,g,b), hue=h where 0 ≤ r, b, g, h ≤ 1
1 2
Approximate: pi.n(digits=18) = 3.14159265358979324= det(matrix([[1,2],[3,4]]))use option figsize=[w,h] to adjust aspect ratio
3 4Functions: sin cos tan sec csc cot sinh cosh tanhplot(f(x),xmin ,xmax ,options)
Av = A*v A−1 = A^-1 At = A.transpose()sech csch coth log ln exp√
parametric plot((f(t),g(t)),tmin ,tmax ,options)abmethods: nrows() ncols() nullity() rank() trace()...
ab = a*b b = a/b a = a^bx = sqrt(x)√polar plot(f(t),tmin ,tmax ,options)nx = x^(1/n) |x| = abs(x) logb (x) = log(x,b)
combine graphs: circle((1,1),1)+line([(0,0),(2,2)]) Sage modules and packages
Symbolic variables: e.g. t,u,v,y,z = var(’t u v y z’)
animate(list of graphics objects, options).show(delay=20) from module name import *(many preloaded)
Define function: e.g. f (x) = x2
f(x)=x^2e.g.
calculus coding combinat crypto functions
or f=lambda x: x^2 or def f(x): return x^23d graphics
games geometry graphs groups logic matrix
line3d([(x1 ,y1 ,z1 ),. . .,(xn ,yn ,zn )],options)numerical plot probability rings sets stats
Operations on expressions
sphere((x,y,z),r,options)sage.module name.all.htabi shows exported commands
factor(...)
expand(...)(...).simplify_...
tetrahedron((x,y,z),size,options)
Std packages: Maxima GP/PARI GAP Singular R Shell ...
Symbolic equations: f(x)==g(x)cube((x,y,z),size,options)
Opt packages: Biopython Fricas(Axiom) Gnuplot Kash ...
_ is previous output
octahedron((x,y,z),size,options)%package name then use package command syntax_+a _-a _*a _/a manipulates equation
dodecahedron((x,y,z),size,options)time command to show timing information
Solve f (x) = g(x): solve(f(x)==g(x),x)
icosahedron((x,y,z),size,options)solve([f(x,y)==0, g(x,y)==0], x,y)