Worked examples
Examples of how to use the solver in each topic. Open one to see its solution, then change it to solve your own problem.
Algebra
- Expand
expand((x + 1)^5) - Partial fractions
apart(1/(x^2 - 1)) - Combine fractions
together(1/x + 1/(x + 1)) - Simplify
simplify((x^2 - 1)/(x - 1)) - A trig identity
simplify(sin(x)^2 + cos(x)^2) - Factor a cubic
factor(x^3 - 6x^2 + 11x - 6) - Polynomial GCD
polynomial_gcd(x^3 - 1, x^2 - 1) - Under an assumption
full_simplify(sqrt(x^2), assuming = x > 0)
Equations
- Quadratic
solve(2x^2 + 3x - 1 = 0, x) - Radical
solve(sqrt(x + 2) = x, x) - Absolute value
solve(abs(2x - 1) = 3, x) - Logarithms
solve(ln(x) + ln(x - 2) = ln(3), x) - Exponential
solve(2^x = 8, x) - Trigonometric
solve(sin(x) = 1/2, x) - Nonlinear system
solve([x^2 + y^2 = 25, x + y = 7], [x, y]) - Three unknowns
solve([x + y + z = 6, 2x - y + z = 3, x + 2y - z = 2], [x, y, z])
Inequalities
Derivatives
Integrals
- By parts
integrate(x·sin(x), x) - Substitution
integrate(x·exp(x^2), x) - Partial fractions
integrate(1/(x^2 - 1), x) - Powers of sine
integrate(sin(x)^3, x) - Definite
integrate(x^2, x = 0..3) - Improper
integrate(1/x^2, x = 1..inf) - Dirichlet integral
integrate(sin(x)/x, x = 0..inf) - Double integral
integrate(integrate(x·y, x = 0..1), y = 0..2)
Limits
- The number e
limit((1 + 1/n)^n, n = inf) - L'Hôpital's rule
limit((exp(x) - 1)/x, x = 0) - Three times over
limit((tan(x) - x)/x^3, x = 0) - One-sided
limit(1/x, x = 0, direction = right) - At infinity
limit((3x^2 + 1)/(x^2 - 5), x = inf) - Zero times infinity
limit(x·ln(x), x = 0, direction = right) - Infinity minus infinity
limit(sqrt(x^2 + x) - x, x = inf) - A cosine
limit((1 - cos(x))/x^2, x = 0)
Series and sums
- Taylor series
series(sin(x), x = 0, order = 7) - Geometric series
series(1/(1 - x), x = 0, order = 5) - Laurent series
series(1/sin(x), x = 0, order = 3) - Geometric sum
sum(1/2^k, k = 0..inf) - Sum of squares
sum(k^2, k = 1..n) - Alternating harmonic
sum((-1)^(k + 1)/k, k = 1..inf) - Does it converge?
sum_convergence(1/k, k) - Infinite product
product(1 - 1/k^2, k = 2..inf)
Sequences
- Squares
find_sequence_function([1, 4, 9, 16, 25], n) - Fibonacci
find_sequence_function([1, 1, 2, 3, 5, 8, 13], n) - Triangular numbers
find_sequence_function([1, 3, 6, 10, 15, 21, 28], n) - Powers of two
find_sequence_function([2, 4, 8, 16, 32], n) - Factorials
find_sequence_function([1, 2, 6, 24, 120, 720], n) - Catalan numbers
find_sequence_function([1, 1, 2, 5, 14, 42, 132], n) - What comes next
next_terms([5, 11, 23, 47, 95, 191]) - A recurrence
find_linear_recurrence([1, 3, 4, 7, 11, 18, 29])
Statistics
- Mean
mean([2, 4, 4, 4, 5, 5, 7, 9]) - Median
median([3, 1, 4, 1, 5, 9, 2, 6]) - Standard deviation
standard_deviation([2, 4, 4, 4, 5, 5, 7, 9]) - Correlation
correlation([1, 2, 3, 4], [2, 4, 5, 9]) - Line of best fit
fit([[0, 1], [1, 3], [2, 5], [3, 8]], [1, x], x) - Normal probability
probability(x > 1, distributed(x, normal_distribution(0, 1))) - Binomial probability
probability(1 < x < 4, distributed(x, binomial_distribution(5, 1/2))) - Expected value
expectation(x^2, distributed(x, poisson_distribution(lambda)))
Linear algebra
- Determinant
det([[2, 0, 1], [1, 3, 2], [0, 1, 4]]) - Eigenvalues
eigenvalues([[2, 1], [1, 2]]) - Eigenvectors
eigenvectors([[4, 1], [2, 3]]) - Rank
rank([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) - Null space
null_space([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) - Row reduce
row_reduce([[1, 2, 3], [4, 5, 6]]) - Linear system
linear_solve([[2, 1], [1, 3]], [3, 5]) - Matrix exponential
matrix_exp([[0, 1], [-1, 0]]) - Matrix product
dot([[1, 2], [3, 4]], [[5, 6], [7, 8]]) - Matrix power
matrix_power([[1, 1], [1, 0]], 10) - Transpose
transpose([[1, 2, 3], [4, 5, 6]]) - Cross product
cross([1, 2, 3], [4, 5, 6])
Differential equations
- Exponential growth
solve_ode(y'(x) = y(x), y, x) - First-order linear
solve_ode(y'(x) + y(x) = x, y, x) - Separable
solve_ode(y'(x) = x·y(x), y, x) - Initial values
solve_ode([y''(x) + y(x) = 0, y(0) = 1, y'(0) = 0], y, x) - Second order
solve_ode(y''(x) - 3y'(x) + 2y(x) = 0, y, x) - A recurrence
solve_recurrence([a(n + 1) = 2a(n) + 1, a(0) = 0], a, n)
Stochastic calculus
- Itô's formula
ito_formula(x^2, x, mu·x, sigma·x, t) - Logarithm of a GBM
ito_formula(ln(x), x, mu·x, sigma·x, t) - Brownian motion squared
ito_formula(x^2, x, 0, 1, t) - Itô integral of W dW
ito_integral(w, w, s, t) - Itô integral of W²
ito_integral(w^2, w, s, t) - Integral of a function of time
ito_integral(exp(s), w, s, t) - Itô's isometry
variance(ito_integral(w, w, s, t)) - Explicit GBM path
geometric_sde_path(mu, sigma, x0, w, t) - Mean of an OU process
mean(ornstein_uhlenbeck_process(mu, sigma, theta, x0), t) - Variance of an OU process
variance(ornstein_uhlenbeck_process(mu, sigma, theta, x0), t) - Variance of a GBM
variance(geometric_brownian_motion_process(mu, sigma, x0), t) - Stationary law of an OU process
stationary_distribution(ornstein_uhlenbeck_process(mu, sigma, theta, x0)) - Moments of an affine SDE
affine_sde_moments(a, b, sigma, x0, t)
Complex numbers
Optimization
- Minimum
minimize(x^2 - 4x + 7, x) - Maximum
maximize(x·(10 - x), x) - Two variables
minimize(x^2 + y^2 - 2x, [x, y]) - A linear program
minimize([x + y, x + 2y >= 4, 3x + y >= 6, x >= 0, y >= 0], [x, y]) - Whole numbers
maximize([5x + 4y, 6x + 4y <= 24, x + 2y <= 6, x >= 0, y >= 0, [x, y] : integer], [x, y]) - Absolute values
minimize([abs(x - 2) + abs(y + 1) + abs(x + y - 5), x >= 0, y >= 0], [x, y]) - The largest of several
minimize([max(x + y, 2x - y, 3 - x), x >= -5, x <= 5, y >= -5, y <= 5], [x, y]) - Sum of distances
minimize([norm([x - 1, y - 2]) + norm([x + 1, y]), x + y >= 0], [x, y]) - Non-convex, whole numbers
minimize([x·y - 3x + 2y, x >= -2, x <= 3, y >= -1, y <= 4, [x, y] : integer], [x, y]) - A global numeric search
numeric_minimize([sin(3x) + (x - 1)^2/10, x >= -10, x <= 10], x)
Special functions
Transforms
- Laplace transform
laplace_transform(t^2·exp(-t), t, s) - Laplace of a sine
laplace_transform(sin(t), t, s) - Inverse Laplace
inverse_laplace_transform(1/(s^2 + 1), s, t) - Partial fractions, inverted
inverse_laplace_transform(1/(s·(s + 1)), s, t) - Fourier transform
fourier_transform(exp(-t^2), t, w) - Z-transform
z_transform(2^n, n, z)
Number theory
Logic
- Simplify a condition
boolean_minimize((p and q) or (p and not q)) - Majority vote
boolean_minimize((a and b) or (a and c) or (b and c and not a)) - De Morgan's law
is_tautology(not (p and q) == (not p or not q)) - A tautology
is_tautology(implies(p, q) or implies(q, p)) - Make it true
satisfiability_instances(p and (q or not p)) - Count the ways
satisfiability_count(a or b or c) - Distribute
logical_expand((p or q) and r) - A contradiction
is_satisfiable(p and not p) - Chained rules
is_tautology(implies(implies(p, q) and implies(q, r), implies(p, r)))
Rules
- Rules in conflict
is_satisfiable((x > 1 or y > 1) and x <= 0 and y < 0) - Which pricing rules clash
conflicting_rules([implies(premium, d <= 3/10), premium, d > 1/2, p >= 0]) - Two clashes in one policy
conflicting_rules([implies(premium, d <= 3/10), premium, d > 1/2, s >= 2, s <= 1]) - A policy against itself
conflicting_rules([implies(admin, mfa), implies(mfa, phone), admin, not phone, audit]) - Two bookings overlap
eliminate_quantifiers(exists(x, a <= x <= b and c <= x <= d)) - One window inside another
eliminate_quantifiers(for_all(x, implies(a <= x <= b, c <= x <= d))) - An order worth over 100
eliminate_quantifiers(exists(n, n > 0 and n < 10 and n·p > 100)) - A deadline for two tasks
eliminate_quantifiers(exists([s, t], s >= 0 and t >= s + 3 and t + 2 <= d)) - A discount within budget
eliminate_quantifiers(exists(d, d >= 0 and d <= 1/5 and p·(1 - d) <= 100)) - A point that meets the rules
find_instance(x + y > 10 and x - y < 2 and x < 5, [x, y], real) - A rational point on the circle
find_instance(x^2 + y^2 = 1 and x > 3/5 and y > 3/5, [x, y], real) - A parabola never negative
eliminate_quantifiers(for_all(x, x^2 + b·x + c >= 0)) - A line above zero
eliminate_quantifiers(for_all(t, implies(0 <= t <= 1, a·t + b >= 0))) - Tables of 6 and 4 for 40 guests
conflicting_rules([6·t + 4·u = 40, t >= 5, u >= 2], integer) - Packs that never add up
find_instance(2·x + 4·y = 7, [x, y], integer)
Algorithms
- Merge sort
solve_recurrence([t(n) = 2·t(n/2) + n, t(1) = 1], t, n) - Binary search
solve_recurrence([t(n) = t(n/2) + 1, t(1) = 1], t, n) - Karatsuba multiplication
solve_recurrence([t(n) = 3·t(n/2) + n, t(1) = 1], t, n) - Strassen matrix product
solve_recurrence([t(n) = 7·t(n/2) + n^2, t(1) = 1], t, n) - Master theorem
recurrence_growth(t(n) = 2·t(n/2) + n^2, t, n) - Unequal split
recurrence_growth(t(n) = t(n/3) + t(2·n/3) + n, t, n)
Cryptography
Finance
- Mean of a stock price
mean(geometric_brownian_motion_process(mu, sigma, x0), t) - Least-risk portfolio
minimize(w^2·s1^2 + (1 - w)^2·s2^2, w) - Kelly fraction
maximize([mu·f - sigma^2·f^2/2, sigma > 0], f) - Growing perpetuity
sum(c·(1 + g)^(k - 1)/(1 + r)^k, k = 1..inf) - Risk-neutral probability
solve(q·u + (1 - q)·d = exp(r·h), q)
Queues and reliability
- Customers in an M/M/1 queue
sum(n·(1 - rho)·rho^n, n = 0..inf) - Repairable unit
solve([-l·p0 + m·p1 = 0, p0 + p1 = 1], [p0, p1]) - Weibull survival
probability(x > 50, distributed(x, weibull_distribution(2, 100))) - Series system
integrate(exp(-(l1 + l2 + l3)·t), t = 0..inf, assuming = [l1 > 0, l2 > 0, l3 > 0]) - Two out of three
integrate(3·exp(-2·l·t) - 2·exp(-3·l·t), t = 0..inf, assuming = l > 0)
Control and signals
- Inverse Laplace, two poles
inverse_laplace_transform(1/((s + 1)·(s + 2)), s, t) - Split a transfer function
apart((s + 3)/(s·(s + 1)·(s + 2)), s) - Stability limit of a loop
solve([K - 3·w^2 = 0, 2·w - w^3 = 0], [K, w]) - Z-transform of a geometric sequence
z_transform(a^n, n, z) - Inverse Z-transform
inverse_z_transform(z^2/((z - 1)·(z - 1/2)), z, n)
Biological models
- Drug in the blood
solve_ode([c'(t) = -k·c(t), c(0) = c0], c, t) - Basic reproduction number
eigenvalues(dot([[0, beta], [0, 0]], inverse([[sigma, 0], [-sigma, gamma]]))) - Predator and prey
solve([a·x - b·x·y = 0, d·x·y - c·y = 0], [x, y]) - Endemic infection
solve(b·I·(1 - I) - g·I = 0, I) - Enzyme rate
solve(V·s/(K + s) = v, s)