Maxima (v5.42.2) Cheatsheet

typeset by Cheng Tan | Kyoto University | i@c-tan.com | https://c-tan.com | 2019-03-05

Basic Operations

Fundamental Mathematics? foo;/* exact search π */?? foo;/* inexact search */%;/* most recent calculated result */%%;/* '%' in compound statements */%th(i);/* the i-th previous output */load("SomePackage");demo("SomePackage");example("SomeFunction");values;/* a list of all bound user variables */kill(all);/* removes all bindings */reset();/* reset many global variables and options */to_lisp();/* from Maxima to Lisp */(to-maxima)/* from Lisp to Maxima */

%pi;
%e;
%i;
%phi;
%gamma;infinity;

display(a, b, c);disp("a = ", a);print(a, b, c);/* similar to 'display' but no equations *//* similar to 'display' but all in one line */r: [x, y, z];r[3];r[1] : 2;
first(r);length(r);member(x, [x, y, z]);create_list(x^i, i, [2, 3, 5]);makelist(x=y, y, [a, b, c]);copylist(r);append(r1, r2, r3);
join([x, y, z], [a, b, c]);cons(w, [x, y, z]);endcons(a, [b, c, d]);endcons(a, f(b, c, d));delete(y, [w, x, y, z, y, x, w]);delete(sin(x), x + sin(x) + y);r2 = push(w, r);pop(r);/* z *//* [2, y, z] *//* x *//* true *//* [x2 , x3 , x5 ] *//* [x = a, x = b, x = c] *//* [x, a, y, b, z, c] *//* [w, x, y, z] *//* [b, c, d, a] *//* f (b, c, d, a) *//* [w, x, z, x, w] *//* x + y *//* r2 = [w, x, y, z] is a copy *//* r = [x, y, z], r2 = [w, x, y, z] */array(aa, 2, 3);arrays;/* 2 × 3 array aa *//* all allocated arrays */a["foo"]: 1;
a[bar]: 2;a["foo"];a[bar];

s1: "Hello";s2: " World!";
concat(s1, s2); /* "Hello World!" */concat (1, 2) + 3;/* "12" + 3, not a number! */(a: 5, b: 40);
concat(a, b/2);
c: concat('a, b/2);
c:: sqrt(3);a20;√/* (1 + 5)/2 *//* 0.57721566 . . . */

inf;
minf;
ind;
und;
zeroa;
zerob;/* ∞ *//* −∞ *//* limx→0 sin(1/x) *//* limx→∞ x sin(x) *//* 0+ *//* 0− *//* non-commutative *//* ab *//* non-commutative */a + b;
a - b;
a * b;
a / b;/* a + b *//* a − b *//* a × b *//* a ÷ b */a . b;a ^ b;a ^^ b;a = b;
a # b;
a > b;
a >= b;a < b;
a <= b;/* a = b *//* a ̸= b *//* a > b *//* a ≥ b *//* a < b *//* a ≤ b */true and false;
not true;
true or false;
is(%pi > %e);compare(%i, %i + 1);

abs([-4, 1+%i]);floor(x);ceiling(x);max(x, y, z);min(x, y, z);Data Structures

Equations√/* [−4, 2] *//* ⌊x⌋ *//* ⌈x⌉ */cabs(a + b * %i);carg(1 + %i);
conjugate(z);sin(x);
csc(x);
cos(x);
sec(x);
tan(x);
cot(x);

sinh(x);csch(x);cosh(x);sech(x);tanh(x);coth(x);asin(x);acsc(x);acos(x);asec(x);atan(x);acot(x);√/* a2 + b2 *//* π/4 *//* z̄ */
asinh(x);acsch(x);acosh(x);asech(x);atanh(x);acoth(x);trigreduce(-sin(x)^2 + cos(x)^2);
trigsimp(sin(x)^3 + cos(x)^3);

random(100);

random(5.0);

Program Flow
# if-else
if sqrt(99) - sqrt(98) > sqrt(98) - sqrt(97) thenprint("No way.")elseif 99 / 98 > 98 / 97 thenprint("Stupid.")
elseprint("Oh man.");# for loop
for i : 1 thru 10 step 3 do disp(sqrt(i));
for i : 1 step 3 while i <= 10 do disp(sqrt(i));
for i : 1 step 3 unless i > 10 do disp(sqrt(i));
for i in [1, 4, 7, 10] do disp(sqrt(i));/* 520 *//* c: a20 */
/*

√

3 */

declare(n, integer); /* sin(nπ) = 0 */opproperties;/* op prop */features;/* var prop */remove(n, integer);assume(x > 0);facts();
forget(x > 0);/* 3.643515335 */combine(a/2+b/3);/* (2b + 3a)/6 */expand((x+1)^2);/* x2 + 2x + 1 */factor(x^2+2*x+1);/* (x + 1)2 */radcan(log(x+x^2)-log(x));
coeff(expand((x+a)^6), x, 3);
subst([x=cos(t), y=sin(t)], x*y);

Functions/* x/∥x∥ */T : matrix([30, -18, 9],[8, 4, 7],[16, -16, 26]);
eivals(T);eivects(T);Simplification/* 1 *//* 2 */

M0 : matrix([0,0],[0,0]);I3 : ident(3);D3 : diagmatrix(3, z);
M3 : genmatrix(lambda ([i, j], j - i), 3, 3);col(M0, 2);row(M3, 1);uvect(x);atan2(y, x);/* arctan(y/x) */trigexpand(sin(x + y));/* 12 */

Linear Algebraload("eigen");

n!;
n!!;
binomial(x, y);log(x);
exp(x);

realpart(z);imagpart(z);polarform(z);/* ∥z∥eiθ */rectform(%e^(%i*t)); /* i sin θ + cos θ */solve(sin(x)^2=1, x);
solve([x^2 + y = 1, x + y^2 = 2], [x, y]);gramschmidt(T);
ip(f, g) := integrate(f * g, u, a, b);gramschmidt([1, sin(u), cos(u)], ip), a= -%pi/2, b=%pi/2;transpose(T);invert(T);mattrace(T);rank(M);

Calculus/* Limits */limit(sin(x)/x, x, 0, plus);
limit(f(n)/f(n+1), n, inf);/* Differentiation */diff(log(x));
diff(exp(x*y), x, 2, y, 2);
laplace(exp(x), x, s);/* Integration */integrate(sin(x), x);

Differential Equations
eqn_1: 'diff(f(x),x,2) = sin(x) + 'diff(g(x),x,2);
eqn_2: 'diff(f(x),x) - f(x) = 2*'diff(g(x),x);
desolve([eqn_1, eqn_2], [f(x),g(x)]);'diff(y,x,2) = exp(x)*x^2;
ode2(%,y,x);# Ordinary function
f(x, y) := exp(x^2 + y^2);# Memoizing Functions
f[a, b] := b! / (a! * (b-a)!);# Anonymous Functions
map(lambda([x], %e^(x*%pi*%i)), [1, 2, 3]);

Sums Products Seriessum(1/2^n, n, 1, inf), simpsum;
product(a[i], i, 1, inf);
powerseries(log(x), x, 1);
taylor(log(1-x), x, 0, 6);
taylor(sin(y + x), x, 0, 3, y, 0, 3);