Computer Algebra Software: Mathematica, SymPy, Pari/GP

a side-by-side reference sheet

grammar and invocation | variables and expressions | arithmetic and logic | strings | regexes | arrays | sequences | multidimensional arrays | dictionaries | functions | execution control | files | libraries and namespaces | reflection

algebra | calculus | number theory | vectors | matrices | distributions | univariate charts | bivariate charts
trivariate charts

mathematica sympy pari/gp
version used
8.0 Python 2.7; SymPy 0.7 2.3
show version
select About Mathematica in Mathematica menu sympy.__version__ $ gp --version
implicit prologue from sympy import *

x, y, z, w = symbols('x y z w')
grammar and invocation
mathematica sympy pari/gp
$ gp -q
$ math $ gp
block delimiters
( stmt; ) { }
statement separator ; or sometimes newline

; before a newline suppresses output
newline or ;

a trailing semicolon suppresses output
end-of-line comment
none 1 + 1 \\ addition
multiple line comment
1 + (* addition *) 1 1 + /* addition */ 1
variables and expressions
mathematica sympy pari/gp
assignment a = 3
Set[a, 3]
a = 3
delayed assignment a := x + 3
SetDelayed[a, x + 3]
parallel assignment {a, b} = {3, 4}
Set[{a, b}, {3, 4}]
compound assignment += -= *= /=
corresponding functions:
AddTo SubtractFrom TimeBy DivideBy
+= -= *= /= %=
increment and decrement ++x --x
PreIncrement[x] PreDecrement[x]
x++ x--
Increment[x] Decrement[x]
return value after increment or decrement:
x++ x--
null test
undefined variable access
treated as an unknown number treated as an unknown number
remove variable binding Clear[x]
conditional expression
If[x > 0, x, -x] if(x > 0, x, -x)
arithmetic and logic
mathematica sympy pari/gp
true and false
True False True False 1 0
False False None 0 0.0 '' [] {} 0
logical operators ! True || (True && False)
Or[Not[True], And[True, False]]
! 1 || (1 && 0)
relational operators == != > < >= <=
corresponding functions:
Equal Unequal Greater Less GreaterEqual LessEqual
== != > < >= <=
arithmetic operators + - * / Quotient Mod
adjacent terms are multiplied, so * is not necessary. Quotient and Mod are functions, not binary infix operators. These functions are also available:
Plus Subtract Times Divide
+ - * / none %
integer division
Quotient[a, b] divrem(a, b)[1]
integer division by zero dividend is zero:
float division exact division:
a / b
exact division:
a / b
float division by zero dividend is zero:
power 2 ^ 16
Power[2, 16]
2 ^ 16
sqrt returns symbolic expression:
returns float:
sqrt -1
I I 1.000 * I
transcendental functions Exp Log Sin Cos Tan ArcSin ArcCos ArcTan ArcTan
ArcTan accepts 1 or 2 arguments
exp log sin cos tan asin acos atan atan2 exp log sin cos tan asin acos atan none
transcendental constants
pi and the euler constant
Pi E pi e Pi exp(1)
float truncation
round towards zero, round to nearest integer, round down, round up
IntegerPart Round Floor Ceiling truncate round floor ceil
absolute value
and signum
Abs Sign abs sign abs sign
integer overflow
none, has arbitrary length integer type none, has arbitrary length integer type
float overflow
none error
rational construction use integer division:
1 / 7
use integer division:
1 / 7
rational decomposition
Numerator Denominator numerator denominator
complex construction
1 + 3I 1 + 3 * I
complex decomposition
real and imaginary part, argument and modulus, conjugate
Re Im
Arg Abs
real imag
?? abs
random number
uniform integer, uniform float
RandomInteger[{0, 99}]
random seed
set, get
bit operators BitAnd[5, 1]
BitOr[5, 1]
BitXor[5, 1]
BitShiftLeft[5, 1]
BitShiftRight[5, 1]
binary, octal, and hex literals 2^^101010
radix BaseForm[42, 7]
BaseForm[7^^60, 10]
\\ 42 as powers of 7 up to 9th power:
42 + O(7^10)
mathematica sympy pari/gp
string literals "don't say \"no\"" "don't say \"no\""
newline in literal yes no; use \n escape
string literal escapes \\ \" \b \f \n \r \t \ooo \n \t \" \\
character access Characters["hello"][[1]]
chr and ord FromCharacterCode[{65}]
length StringLength["hello"] length("hello")
concatenate "one " <> "two " <> "three" Str("one", "two", "three")
index of substring StringPosition["hello", "el"][[1]][[1]]
StringPosition returns an array of pairs, one for each occurrence of the substring. Each pair contains the index of the first and last character of the occurrence.
extract substring StringTake["hello", {1, 4}]
split StringSplit["foo,bar,baz", ","]
join StringJoin[Riffle[{"foo", "bar", "baz"}, ","]]
trim StringTrim[" foo "]
convert from string, to string 7 + ToExpression["12"]
73.9 + ToExpression[".037"]
"value: " <> ToString[8]
case manipulation ToUpperCase["foo"]
regular expressions
mathematica sympy pari/gp
regex test re = RegularExpression["[a-z]+"]
sc = StringCases["hello", re]
Length[sc] > 0
regex substitution s = "foo bar bar"
re = RegularExpression["bar"]
StringReplace[s, re -> "baz", 1]
StringReplace[s, re -> "baz"]
mathematica sympy pari/gp
literal {1, 2, 3}

List[1, 2, 3]
\\ [1, 2, 3] is a vector literal:
List([1, 2, 3])
Length[{1, 2, 3}] length(List([1, 2, 3]))
empty test
Length[{}] == 0 length(List([])) == 0
lookup (* access time is O(1) *)
(* indices start at one: *)
{1, 2, 3}[[1]]

Part[{1, 2, 3}, 1]
\\ access time is O(1).
\\ indices start at one:
List([1, 2, 3])[1]
a[[1]] = 7 listput(a, 7, 1)
out-of-bounds behavior left as unevaluated Part[] expression out of allowed range error
element index (* Position returns list of all positions: *)
First /@ Position[{7, 8, 9, 9}, 9]
{1, 2, 3}[[1 ;; 2]] none
array of integers as index (* evaluates to {7, 9, 9} *)
{7, 8, 9}[[{1, 3, 3}]]
manipulate back a = {6,7,8}
AppendTo[a, 9]
elem = a[[Length[a]]]
a = Delete[a, Length[a]]
a = List([6, 7, 8])
listput(a, 9)
elem = listpop(a)
manipulate front a = {6,7,8}
PrependTo[a, 5]
elem = a[[1]]
a = Delete[a, 1]
a = List([6, 7, 8]);
listinsert(a, 5, 1);
elem = a[1];
listpop(a, 1);
First[{1, 2, 3}] List([1, 2, 3])[1]
Rest[{1, 2, 3}] none
cons (* first arg must be an array *)
Prepend[{2, 3}, 1]
a = List([1, 2, 3]);
listinsert(a, 1, 1);
Join[{1, 2, 3}, {4, 5, 6}] concat(List([1, 2, 3]), List([4, 5, 6]))
ten_zeros = Table[0, {i, 0, 9}]
a2 = a a2 = a
Function[x, Print[x]] /@ {1, 2, 3} a = List([1, 2, 3])

for(i=1, length(a), print(a[i]))
Reverse[{1, 2, 3}] a = List([1, 2, 3])
a2 = listcreate()
while(i > 0, listput(a2, a[i]); i—)
sort Sort[{3, 1, 4, 2}] a = List([3,1,4,2])
Union[{1, 2, 2, 3}]
MemberQ[{1, 2, 3}, 2] /* The Set() constructor takes an array or vector as
  an argument. It converts the elements to strings
  and sorts them, discarding duplicates.
  setsearch() returns the index of the element or zero
  if not in the set. */

setsearch(Set([1, 2, 3]), 2)
intersection Intersect[{1, 2}, {2, 3, 4}] setintersect(Set([1, 2]), Set([2, 3, 4]))
Union[{1, 2}, {2, 3, 4}] setunion(Set([1, 2]), Set([2, 3, 4]))
relative complement, symmetric difference Complement[{1, 2, 3}, {2}]
setminus(Set([1, 2, 3]), Set([2]))
map Function[x, x x] /@ {1, 2, 3}

Map[Function[x, x x], {1, 2, 3}]
Select[{1, 2, 3}, # > 2 &]
reduce Fold[Plus, 0, {1, 2, 3}]
universal and existential tests none
min and max element Min[{1, 2, 3}]
Max[{1, 2, 3}]
shuffle and sample x = {3, 7, 5, 12, 19, 8, 4}

RandomSample[x, 3]
zip (* list of six elements: *)
Riffle[{1, 2, 3}, {"a", "b", "c"}]
mathematica sympy pari/gp
range Range[1, 100]
arithmetic sequence of integers with difference 10 Range[1, 100, 10]
arithmetic sequence of floats with difference 0.1 Range[1, 100, .1]
mathematica sympy pari/gp
literal—1d {1, 2, 3} [1, 2, 3]
literal—2d (* used a nested array for each row: *)
{{1, 2}, {3, 4}}

(* display as grid with aligned columns: *)
MatrixForm[{{1, 2}, {3, 4}}]
[1, 2, 3; 4, 5, 6]
construct from sequence—2d ArrayReshape[{1, 2, 3, 4, 5, 6}, {2, 3}]
number of elements, number of dimensions, dimension lengths
a = 1, 2, 3}, {4, 5, 6

lookup—1d {1, 2, 3}[[1]]
lookup—2d 1, 2}, {3, 4[[1, 1]]

Part[1, 2}, {3, 4, 1, 1]
mathematica sympy pari/gp
record literal r = { n -> 10, avg -> 3.7, sd -> 0.4}
record member access n /. r
mathematica sympy pari/gp
define function Add[a_, b_] := a + b

(* alternate syntax: *)
Add = Function[{a, b}, a + b]
add(x, y) = x + y
invoke function Add[3, 7]

Add @@ {3, 7}

(* syntax for unary functions: *)
2 // Log
add(3, 7)
undefine function Clear[Add]
redefine function Add[a_, b_] := b + a
overload function
missing function behavior The expression is left unevaluated. The head is the function name as a symbol, and the parts are the arguments.
missing argument behavior The expression is left unevaluated. The head is the function name as a symbol, and the parts are the arguments.
extra argument behavior
return value
function value
anonymous function Function[{a, b}, a + b]

(#1 + #2) &
default argument
variable number of arguments
execution control
mathematica sympy pari/gp
if If[x > 0,
  If[x < 0,
if(x > 0, \
  print("positive"), \
  if(x < 0, \
    print("negative"), \
while i = 0
While[i < 10, Print[i]; i++]
i = 0
while(i < 10, print(i); i++)
for For[i = 0, i < 10, i++, Print[i]] for(i=0, 9, print(i))
break/continue Break[] Continue[] break continue
raise exception Throw["failed"] error("failed")
handle exception Print[Catch[Throw["failed"]]]
finally block none
mathematica sympy pari/gp
write to stdout Print["hello"] print("hello")
read entire file into string or array s = Import["/etc/hosts"]
a = StringSplit[s, "\n"]
redirect to file
libraries and namespaces
mathematica sympy pari/gp
mathematica sympy pari/gp
list function documentation ?
get function documentation ?Tan
? tan
grep documentation
query data type Head[x] type(x)
list variables in scope ? 0
mathematica sympy pari/gp
solution to an equation Solve[x^3 + x + 3 == 0, x] solve(x**3 + x + 3, x)
solution to two equations Solve[x + y == 3 && x == 2y,
  {x, y}]
solve([x + y - 3, 3*x - 2*y], [x, y])
numerical approximation N[Exp[1]]
Exp[1] + 0.
N[Exp[1], 10]
N(exp(1), 10)
1/7 + 0.
expand polynomial Expand[(1 + x)^5] expand((1+x)**5)
factor polynomial Factor[3 + 10 x + 9 x^2 + 2 x^3] factor(3 + 10*x + 9*x**2 + 2*x**3)
add fractions Together[a/b + c/d] together(x/y + z/w)
decompose fraction Apart[(b c + a d)/(b d)]
mathematica sympy pari/gp
differentiation D[x^3 + x + 3, x] diff(x**3 + x + 3, x) P = x^3 + x + 3
higher order differentiation D[Log[x], {x, 3}] diff(log(x), x, 3)
antiderivative Integrate[x^3 + x + 3, x] integrate(x**3 + x + 3, x)
definite integral Integrate[x^3 + x + 3, {x, 0, 1}] integrate(x**3 + x + 3, [x, 0, 1])
improper integral
find minimal value Minimize[Sqrt[a^2 + x^2] + Sqrt[(b - x)^2 + c^2], x]
number theory
mathematica sympy pari/gp
number tests IntegerQ[7]
rational test?
real test?
solve diophantine equation Solve[a^2 + b^2 == c^2 &&
a > 0 && a < 10 &&
b > 0 && b < 10 &&
c > 0 && c < 10,
{a, b, c}, Integers]
factorial 10! factorial(10) 10!
binomial coefficient Binomial[10,3] binomial(10, 3)
greatest common divisor GCD[14, 21] gcd(14, 21) gcd(14, 21)
prime factors returns {{2, 2}, {3, 1}, {7, 1}}
factorint(84) returns [2,2; 3,1; 7,1]
Euler totient EulerPhi[256]
mathematica sympy pari/gp
vector literal (* same as array: *)
{1, 2, 3}
[1, 2, 3]
vector coordinate indices start at one:
{1,v2, 3}[[1]]
indices start at one:
[1, 2, 3][1]
vector dimension
Length[{1, 2, 3}] length([1, 2, 3])
element-wise arithmetic operators + - * /
adjacent lists are multiplied element-wise
+ -
vector length mismatch
error error
scalar multiplication 3 {1, 2, 3}
{1, 2, 3} 3
* may also be used
3 * [1, 2, 3]
[1, 2, 3] * 3
dot product {1, 1, 1} . {2, 2, 2}
Dot[{1, 1, 1}, {2, 2, 2}]
cross product Cross[{1, 0, 0}, {0, 1, 0}]
norms Norm[{1, 2, 3}, 1]
Norm[{1, 2, 3}]
Norm[{1, 2, 3}, Infinity]
mathematica sympy pari/gp
literal or constructor A = {{1, 2}, {3, 4}}
B = {{4, 3}, {2, 1}}
A = [1, 2; 3, 4]
B = [4, 3; 2, 1]
zero, identity, ones, diagonal matrix ConstantArray[0, {3, 3}]
ConstantArray[1, {3, 3}]
DiagonalMatrix[{1, 2, 3}]
rows, columns
element access A[[1, 1]] A[1, 1]
row access A[[1]]
column access
submatrix access # [[1]] & /@ A
scalar multiplication 3 A
A 3
* can also be used
element-wise operators + - * /
adjacent matrices are multiplied element-wise
multiplication A . B
kronecker product KroneckerProduct[A, B]
comparison A == B
A != B
norms Norm[A, 1]
Norm[A, Infinity]
Norm[A, "Frobenius"]
transpose Transpose[A]
conjugate transpose A = {{I, 2 I}, {3 I, 4 I}}
inverse Inverse[A]
determinant Det[A] matdet(A)
trace Tr[A] trace(A)
eigenvalues Eigenvalues[A]
eigenvectors Eigenvectors[A]
system of equations Solve[A. {x, y} == { 2, 3}, {x, y}]
mathematica sympy pari/gp
normal nd = NormalDistribution[0,1]
exponential ed = ExponentialDistribution[1]
poisson pd = PoissonDistribution[1]
univariate charts
mathematica sympy pari/gp
5039793334_f76edece33_m.jpgvertical bar chart BarChart[{7, 3, 8, 5, 5},
horizontal bar chart
BarChart[{7, 3, 8, 5, 5}, BarOrigin -> Left]
5037819710_d932767cd5_m.jpgpie chart PieChart[{7, 3, 8, 5, 5}]
stem-and-leaf plot
nd = NormalDistribution[0, 1]
n100 = RandomVariate[nd, 100]
StemLeafPlot[20 * n100]
5037415497_4c6fbfcab2_m.jpghistogram nd = NormalDistribution[0, 1]
Histogram[RandomReal[nd, 100], 10]
5037525393_7ac86e81c3_m.jpgbox-and-whisker plot nd = NormalDistribution[0, 1]
n100 = RandomVariate[nd, 100]

ed = ExponentialDistribution[1]
e100 = RandomVariate[ed, 100]
u100 = RandomReal[1, 100]
d = {n100, e100, u100}
set chart title BoxWhiskerChart[data,
  PlotLabel -> "chart example"]
chart options PlotLabel -> "an example"

AxisLabel -> {"time", "distance"}
bivariate charts
mathematica sympy pari/gp
stacked bar chart
d = {{7, 1}, {3, 2}, {8, 1},
  {5, 3}, {5, 1}}
BarChart[d, ChartLayout ->
5267212089_a7749bbe3e_s.jpgscatter plot nd = NormalDistribution[0, 1]
rn = Function[RandomReal[nd]]
d = {rn[],rn[]} & /@ Range[1,50]
5267975488_2216ae147e_s.jpglinear regression line d = Table[{i,
  2 i + RandomReal[{-5, 5}]},
  {i, 0, 20}]
model = LinearModelFit[d, x, x]
    {x, 0, 20}]]
5267434941_f8537c9d26_s.jpgpolygonal line plot f = Function[i, {i, rn[]}]
d = f /@ Range[1, 20]
5268071368_75c3aee42e_t.jpgarea chart d = {{7, 1, 3, 2, 8},
  {1, 5, 3, 5, 1}}
sd = {d[[1]], d[[1]] + d[[2]]}
ListLinePlot[sd, Filling ->
  {1 -> {Axis, LightBlue},
   2 -> {{1}, LightRed}}]
5268229340_0b96b5e223_s.jpgcubic spline d = Table[{i, RandomReal[nd]},
  {i, 0, 20}]
f = Interpolation[d,
  InterpolationOrder -> 3]
  Plot[f[x], {x, 0, 20}]]
5268208606_b745646ea6_s.jpgfunction plot Plot[Sin[x], {x, -4, 4}] ploth(x=-4, 4, sin(x))
5267567389_27a19429e4_s.jpgquantile-quantile plot nd = NormalDistribution[0, 1]
d1 = RandomReal[1, 50]
d2 = RandomReal[nd, 50]
QuantilePlot[d1, d2]
axis label d = Table[{i, i^2}, {i, 1, 20}]
  AxesLabel -> {x, x^2}]
logarithmic y-axis LogPlot[{x^2, x^3, x^4, x^5},
  {x, 0, 20}]
trivariate charts
mathematica sympy pari/gp
3d scatter plot nd = NormalDistribution[0,1]
d = RandomReal[nd, {50, 3}]
5268191292_a75a367c39_s.jpgadditional data set nd = NormalDistribution[0, 1]
x1 = RandomReal[nd, 20]
x2 = RandomReal[nd, 20]
ListLinePlot[{x1, x2}]
bubble chart nd = NormalDistribution[0,1]
d = RandomReal[nd, {50, 3}]
surface plot Plot3D[Sinc[Sqrt[x^2 + y^2]],
  {x, -25, 25},
  {y, -25, 25}]
__________________________________________________________ __________________________________________________________ __________________________________________________________

version used

The version of software used to check the examples in the reference sheet.

show version

How to determine the version of an installation.

Grammar and Invocation


How to execute a script.


The shebang style notation doesn't work because GP doesn't recognize the hash tag # as the start of a comment.

The -q option suppresses the GP startup message.

After the script finishes it will drop the user into the REPL unless there is a quit statement in the script:

print("Hello, World!")



How to launch a command line read-eval-print loop for the language.


One can create a REPL called math on Mac OS X with the following command:

$ sudo ln -s /Applications/ /usr/local/bin/math

$ math

block delimiters

How blocks are delimited.

statement separator

How statements are separated.

end-of-line comment

Character used to start a comment that goes to the end of the line.

multiple line comment

Variables and Expressions


How to perform assignment.

In all three languages an assignment is an expression that evaluates to the right side of the expression. Assignments can be chained to assign the same value to multiple variables.


The Set function behaves identically to assignment and can be nested:

Set[a, Set[b, 3]]

delayed assignment

How to assign an expression to a variable name. The expression is re-evaluated each time the variable is used.


GNU make also supports assignment and delayed assignment, but = is used for delayed assignment and := is used for immediate assignment. This is the opposite of how Mathematica uses the symbols.

The POSIX standard for make only has = for delayed assignment.

parallel assignment

How to assign values in parallel.

Parallel assignment can be used to swap the values held in two variables.

compound assignment

The compound assignment operators.

increment and decrement


null test

How to test if a value is null.

undefined variable access

remove variable binding

How to remove a variable. Subsequent references to the variable will be treated as if the variable were undefined.

conditional expression

A conditional expression.

Arithmetic and Logic

true and false

The boolean literals.


Values which evaluate to false in a conditional test.

logical operators

The boolean operators.

relational operators

The relational operators.

arithmetic operators

The arithmetic operators.

integer division

How to compute the quotient of two integers.

integer division by zero

The result of dividing an integer by zero.

float division

How to perform float division, even if the arguments are integers.

float division by zero

The result of dividing a float by zero.


How to compute exponentiation.

Note that zero to a negative power is equivalent to division by zero, and negative numbers to a fractional power may have multiple complex solutions.


The square root function.

For positive arguments the positive square root is returned.

sqrt -1

How the square root function handles negative arguments.


An uppercase I is used to enter the imaginary unit, but Mathematica displays it as a lowercase i.

transcendental functions

The standard transcendental functions such as one might find on a scientific calculator.

The functions are the exponential (not to be confused with exponentiation), natural logarithm, sine, cosine, tangent, arcsine, arccosine, arctangent, and the two argument arctangent.

transcendental constants

The transcendental constants pi and e.

The transcendental functions can used to computed to compute the transcendental constants:

pi = acos(-1)
pi = 4 * atan(1)
e = exp(1)

float truncation

Ways to convert a float to a nearby integer.

absolute value

How to get the absolute value and signum of a number.

integer overflow

What happens when the value of an integer expression cannot be stored in an integer.

The languages in this sheet all support arbitrary length integers so the situation does not happen.

float overflow

What happens when the value of a floating point expression cannot be stored in a float.

rational construction

How to construct a rational number.

rational decomposition

How to extract the numerator and denominator from a rational number.

complex construction

How to construct a complex number.

complex decomposition

How to extract the real and imaginary part from a complex number; how to extract the argument and modulus; how to get the complex conjugate.

random number

How to generate a random integer or a random float.

random seed

How to set or get the random seed.


The seed is set to a fixed value at start up.


The seed is not set to the same value at start up.

bit operators

binary, octal, and hex literals

Binary, octal, and hex integer literals.


The notation works for any base from 2 to 36.


string literals

newline in literal

character access

chr and ord



index of substring

extract substring


convert from string, to string

How to convert strings to numbers and vice versa.



case manipulation


Regular Expressions

regex test

How to test whether a string matches a regular expression.

regex substitution

How to replace substrings which match a regular expression.



The notation for an array literal.


The number of elements in the array.

empty test

How to test whether an array is empty.


How to access an array element by its index.


How to change the value stored at an array index.

out-of-bounds behavior

What happens when an attempt is made to access an element at an out-of-bounds index.

element index

How to get the index of an element in an array.


How to extract a subset of the elements. The indices for the elements must be contiguous.

array of integers as index

manipulate back

manipulate front







How to copy an array. Updating the copy will not alter the original.






How to test whether a value is an element of a list.


How to to find the intersection of two lists.


How to find the union of two lists.

relative complement, symmetric difference

How to find all elements in one list which are not in another; how to find all elements which are in one of two lists but not both.




universal and existential tests

min and max element

shuffle and sample

How to shuffle an array. How to extract a random sample from an array without replacement.


How to interleave two arrays.


Multidimensional Arrays


record literal

record member access




function value

Execution Control


How to write a branch statement.


The 3rd argument (the else clause) of an If expression is optional.


How to write a conditional loop.


Do can be used for a finite unconditional loop:

Do[Print[foo], {10}]


How to write a C-style for statement.


How to break out of a loop. How to jump to the next iteration of a loop.

raise exception

How to raise an exception.

handle exception

How to handle an exception.

finally block

How to write code that executes even if an exception is raised.


Libraries and Namespaces


function documentation

How to get the documentation for a function.



Number Theory


vector literal

The notation for a vector literal.

vector coordinate

How to get one of the coordinates of a vector.

vector dimension

How to get the number of coordinates of a vector.

element-wise arithmetic operators

How to perform an element-wise arithmetic operation on vectors.

vector length mismatch

What happens when an element-wise arithmetic operation is performed on vectors of different dimension.

scalar multiplication

How to multiply a scalar with a vector.

dot product

How to compute the dot product of two vectors.

cross product

How to compute the cross product of two three-dimensional vectors.


How to compute the norm of a vector.


literal or constructor

Literal syntax or constructor for creating a matrix.


Matrices are represented as lists of lists. No error is generated if one of the rows contains too many or two few elements. The MatrixQ predicate can be used to test whether a list of lists is matrix: i.e. all of the sublists contain numbers and are of the same length.

Matrices are displayed by Mathematica using list notation. To see a matrix as it would be displayed in mathematical notation, use the MatrixForm function.


How to get the dimensions of a matrix.

element access

How to access an element of a matrix. All languages described here follow the convention from mathematics of specifying the row index before the column index.

row access

How to access a row.

column access

How to access a column.

submatrix access

How to access a submatrix.

scalar multiplication

How to multiply a matrix by a scalar.

element-wise operators

Operators which act on two identically sized matrices element by element. Note that element-wise multiplication of two matrices is used less frequently in mathematics than matrix multiplication.


How to multiply matrices. Matrix multiplication should not be confused with element-wise multiplication of matrices. Matrix multiplication in non-commutative and only requires that the number of columns of the matrix on the left match the number of rows of the matrix. Element-wise multiplication, by contrast, is commutative and requires that the dimensions of the two matrices be equal.

kronecker product

The Kronecker product is a non-commutative operation defined on any two matrices. If A is m x n and B is p x q, then the Kronecker product is a matrix with dimensions mp x nq.


How to test two matrices for equality.


How to compute the 1-norm, the 2-norm, the infinity norm, and the frobenius norm.


univariate-charts Univariate Charts

A univariate chart can be used to display a list or array of numerical values. Univariate data can be displayed in a table with a single column or two columns if each numerical value is given a name. A multivariate chart, by contrast, is used to display a list or array of tuples of numerical values.

In order for a list of numerical values to be meaningfully displayed in a univariate chart, it must be meaningful to perform comparisons (<, >, =) on the values. Hence the values should have the same unit of measurement.

vertical bar chart

A chart which represents values with rectangular bars which line up on the bottom. It is a deceptive practice for the bottom not to represent zero, even if a y-axis with labelled tick marks or grid lines is provided. A cut in the vertical axis and one of the bars may be desirable if the cut value is a large outlier. Putting such a cut all of the bars near the bottom is a deceptive practice similar not taking to the base of the bars to be zero, however.

Another bad practice is the 3D bar chart. In such a chart heights are represented by the height of what appear to be three dimensional blocks. Such charts impress an undiscriminating audience but make it more difficult to make a visual comparison of the charted quantities.


horizontal bar chart

A bar chart in which zero is the y-axis and the bars extend to the right.

pie chart

A bar chart displays values using the areas of circular sectors or equivalently, the lengths of the arcs of those sectors. A pie chart implies that the values are percentages of a whole. The viewer is likely to make an assumption about what the whole circle represents. Thus, using a pie chart to show the revenue of some companies in a line of business could be regarded as deceptive if there are other companies in the same line of business which are left out. The viewer may mistakenly assume the whole circle represents the total market.

If two values are close in value, people cannot determine visually which of the corresponding sectors in a pie chart is larger without the aid of a protractor. For this reason many consider bar charts superior to pie charts.

Many software packages make 3D versions of pie charts which communicate no additional information and in fact make it harder to interpret the data.

stem-and-leaf plot


box-and-whisker plot

set chart title

Bivariate Charts

stacked bar chart

Trivariate Charts


Mathematica Documentation Center


Welcome to SymPy’s documentation!

When using SymPy in IPython, the following command enables LaTeX formatted output:

from sympy import *


A Tutorial for Pari/GP (pdf)
Pari/GP Functions by Category
Pari/GP Reference Card (pdf)

issue tracker | content of this page licensed under creative commons attribution-sharealike 3.0