Sage Quick Reference: Calculus
William Stein
Sage Version 3.4
http://wiki.sagemath.org/quickref
GNU Free Document License, extend for your own use

Simplifying and expanding
Below f must be symbolic (so not a Python function):
Simplify: f.simplify_exp(), f.simplify_full(),f.simplify_log(), f.simplify_radical(),f.simplify_rational(), f.simplify_trig()
Expand: f.expand(), f.expand_rational()

Builtin constants and functions
Constants: π = pi e = e i = I = i
Equations∞ = oo = infinity NaN=NaN log(2) =log2Relations: f = g: f == g, f 6= g: f != g,
φ = golden_ratio γ = euler_gammaf ≤ g: f <= g, f ≥ g: f >= g,0.915 ≈ catalan 2.685 ≈ khinchinf < g: f < g, f > g: f > g
0.660 ≈ twinprime 0.261 ≈ merten 1.902 ≈ brun
Solve f = g: solve(f == g, x), andApproximate: pi.n(digits=18) = 3.14159265358979324
solve([f == 0, g == 0], x,y)
Builtin functions:sin cos tan sec csc cot sinh
solve([x^2+y^2==1, (x-1)^2+y^2==1],x,y)
cosh tanh sech csch coth log ln exp ...
Solutions:S = solve(x^2+x+1==0, x, solution_dict=True)
Defining symbolic expressions
S[0]["x"]S[1]["x"] are the solutions
Create symbolic variables:
Exact roots: (x^3+2*x+1).roots(x)var("t u theta") or var("t,u,theta")
Real roots:(x^3+2*x+1).roots(x,ring=RR)
Complexroots:(x^3+2*x+1).roots(x,ring=CC)
Use * for multiplication
and^for
exponentiation:√2x5 + 2 = 2*x^5 + sqrt(2)√Typeset: show(2*theta^5 + sqrt(2)) −→ 2θ5 + 2
Factorization
Factored form: (x^3-y^3).factor()
Symbolic functions
List of (factor, exponent) pairs:
Symbolic function (can integrate, differentiate, etc.):(x^3-y^3).factor_list()f(a,b,theta) = a + b*theta^2Also, a “formal” function of theta:
Limitsf = function(’f’,theta)
lim f (x) = limit(f(x), x=a)
Piecewise symbolic functions:
x→aPiecewise([[(0,pi/2),sin(1/x)],[(pi/2,pi),x^2+1]]) limit(sin(x)/x, x=0)
lim+ f (x) = limit(f(x), x=a, dir=’plus’)
10
x→a

7.5
5
2.5

1

2

3

Python functions
Defining:
def f(a, b, theta=1):
c = a + b*theta^2
return c
Inline functions:f = lambda a, b, theta = 1: a + b*theta^2limit(1/x, x=0, dir=’plus’)
lim− f (x) = limit(f(x), x=a, dir=’minus’)

x→alimit(1/x, x=0, dir=’minus’)
Derivatives
ddx (f (x)) = diff(f(x),x) = f.diff(x)∂∂x (f (x, y)) = diff(f(x,y),x)diff = differentiate = derivativediff(x*y + sin(x^2) + e^(-x), x)

Integrals
Rf (x)dx = integral(f,x) = f.integrate(x)integral(x*cos(x^2), x)
Rbf (x)dx = integral(f,x,a,b)
aintegral(x*cos(x^2), x, 0, sqrt(pi))
Rbf (x)dx ≈ numerical_integral(f(x),a,b)[0]anumerical_integral(x*cos(x^2),0,1)[0]assume(...): use if integration asks a question
assume(x>0)
Taylor and partial fraction expansion
Taylor polynomial, deg n about a:taylor(f,x,a,n)≈ c0 + c1 (x − a) + · · · + cn (x − a)ntaylor(sqrt(x+1), x, 0, 5)Partial fraction:(x^2/(x+1)^3).partial_fraction()
Numerical roots and optimization
Numerical root: f.find_root(a, b, x)(x^2 - 2).find_root(1,2,x)
Maximize: find (m, x0 ) with f (x0 ) = m maximal
f.find_maximum_on_interval(a, b, x)
Minimize: find (m, x0 ) with f (x0 ) = m minimal
f.find_minimum_on_interval(a, b, x)
Minimization: minimize(f, start point)
minimize(x^2+x*y^3+(1-z)^2-1, [1,1,1])Multivariable calculus
Gradient: f.gradient() or f.gradient(vars)(x^2+y^2).gradient([x,y])
Hessian: f.hessian()(x^2+y^2).hessian()
Jacobian matrix: jacobian(f, vars)
jacobian(x^2 - 2*x*y, (x,y))Summing infinite series
∞X
1
n=1

n2

=π26

Not yet implemented, but you can use Maxima:s = ’sum (1/n^2,n,1,inf), simpsum’SR(sage.calculus.calculus.maxima(s)) −→ π 2 /6