a sidebyside 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  
interpreter 
$ gp q foo.gp  
repl 
$ math  $ gp  
block delimiters 
( stmt; …)  { … }  
statement separator  ; or sometimes newline ; before a newline suppresses output 
newline or ; a trailing semicolon suppresses output 

endofline 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}] 
none  
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 
Null  
null test 

undefined variable access 
treated as an unknown number  treated as an unknown number  
remove variable binding  Clear[x] Remove[x] 
kill(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 
falsehoods 
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: Indeterminate otherwise: ComplexInfinity 
error  
float division  exact division: a / b 
exact division: a / b 

float division by zero  dividend is zero: Indeterminate otherwise: ComplexInfinity 
error  
power  2 ^ 16 Power[2, 16] 
2 ^ 16  
sqrt  returns symbolic expression: Sqrt[2] 
returns float: sqrt(2) 

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 Conjugate 
real imag ?? abs conj 

random number uniform integer, uniform float 
RandomInteger[{0, 99}] RandomReal[] 
random(100) ?? 

random seed set, get 
SeedRandom[17] ?? 
setrand(17) getrand() 

bit operators  BitAnd[5, 1] BitOr[5, 1] BitXor[5, 1] BitNot[5] BitShiftLeft[5, 1] BitShiftRight[5, 1] 

binary, octal, and hex literals  2^^101010 8^^52 16^^2a 

radix  BaseForm[42, 7] BaseForm[7^^60, 10] 
\\ 42 as powers of 7 up to 9th power: 42 + O(7^10) 

strings  
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}] ToCharacterCode["A"][[1]] 

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"] ToLowerCase["FOO"] 

regular expressions  
mathematica  sympy  pari/gp  
regex test  re = RegularExpression["[az]+"] 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"] 

arrays  
mathematica  sympy  pari/gp  
literal  {1, 2, 3} List[1, 2, 3] 
\\ [1, 2, 3] is a vector literal: List([1, 2, 3]) 

size 
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] 

update 
a[[1]] = 7  listput(a, 7, 1)  
outofbounds 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] 
none  
slice 
{1, 2, 3}[[1 ;; 2]]  none  
array of integers as index  (* evaluates to {7, 9, 9} *) {7, 8, 9}[[{1, 3, 3}]] 
none  
manipulate back  a = {6,7,8} AppendTo[a, 9] elem = a[[Length[a]]] a = Delete[a, Length[a]] elem 
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] elem 
a = List([6, 7, 8]); listinsert(a, 5, 1); elem = a[1]; listpop(a, 1); 

head 
First[{1, 2, 3}]  List([1, 2, 3])[1]  
tail 
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); 

concatenate 
Join[{1, 2, 3}, {4, 5, 6}]  concat(List([1, 2, 3]), List([4, 5, 6]))  
replicate 
ten_zeros = Table[0, {i, 0, 9}]  
copy 
a2 = a  a2 = a  
iterate 
Function[x, Print[x]] /@ {1, 2, 3}  a = List([1, 2, 3]) for(i=1, length(a), print(a[i])) 

reverse 
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]) listsort(a) a 

dedupe 
Union[{1, 2, 2, 3}]  
membership 
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 
Union[{1, 2}, {2, 3, 4}]  setunion(Set([1, 2]), Set([2, 3, 4]))  
relative complement, symmetric difference  Complement[{1, 2, 3}, {2}] none 
setminus(Set([1, 2, 3]), Set([2]))  
map  Function[x, x x] /@ {1, 2, 3} Map[Function[x, x x], {1, 2, 3}] 

filter 
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] RandomSample[x, 3] 

zip  (* list of six elements: *) Riffle[{1, 2, 3}, {"a", "b", "c"}] 

sequences  
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]  
multidimensionalarrays  
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}]  
size number of elements, number of dimensions, dimension lengths 
a = 1, 2, 3}, {4, 5, 6 Length[Flatten[a]] Length[Dimensions[a]] Dimensions[a] 

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

dictionaries  
mathematica  sympy  pari/gp  
record literal  r = { n > 10, avg > 3.7, sd > 0.4}  
record member access  n /. r  
functions  
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, Print["positive"], If[x < 0, Print["negative"], Print["zero"]]] 
if(x > 0, \ print("positive"), \ if(x < 0, \ print("negative"), \ print("zero"))) 

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  
files  
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  
load  
reflection  
mathematica  sympy  pari/gp  
list function documentation  ?  
get function documentation  ?Tan Information[Tan] 
? tan  
grep documentation  
query data type  Head[x]  type(x)  
list variables in scope  ? 0  
algebra  
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)) 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)]  
calculus  
mathematica  sympy  pari/gp  
differentiation  D[x^3 + x + 3, x]  diff(x**3 + x + 3, x)  P = x^3 + x + 3 P' sin(x)' 
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] PrimeQ[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}} FactorInteger[84] 
factorint(84)  returns [2,2; 3,1; 7,1] factor(84) 
Euler totient  EulerPhi[256]  
vectors  
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])  
elementwise arithmetic operators  +  * / adjacent lists are multiplied elementwise 
+   
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] 

matrices  
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}] IdentityMatrix[3] ConstantArray[1, {3, 3}] DiagonalMatrix[{1, 2, 3}] 

dimensions rows, columns 
Length[A] Length[A[[1]]] 

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 

elementwise operators  +  * / adjacent matrices are multiplied elementwise 

multiplication  A . B  
kronecker product  KroneckerProduct[A, B]  
comparison  A == B A != B 

norms  Norm[A, 1] Norm[A] Norm[A, Infinity] Norm[A, "Frobenius"] 

transpose  Transpose[A]  
conjugate transpose  A = {{I, 2 I}, {3 I, 4 I}} ConjugateTranspose[A] 

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}]  
distributions  
mathematica  sympy  pari/gp  
normal  nd = NormalDistribution[0,1] RandomVariate[nd] 

exponential  ed = ExponentialDistribution[1] RandomVariate[ed] 

poisson  pd = PoissonDistribution[1] RandomVariate[pd] 

univariate charts  
mathematica  sympy  pari/gp  
vertical bar chart  BarChart[{7, 3, 8, 5, 5}, ChartLegends> {"a","b","c","d","e"}] 

horizontal bar chart 
BarChart[{7, 3, 8, 5, 5}, BarOrigin > Left]  
pie chart  PieChart[{7, 3, 8, 5, 5}]  
stemandleaf plot 
Needs["StatisticalPlots`"] nd = NormalDistribution[0, 1] n100 = RandomVariate[nd, 100] StemLeafPlot[20 * n100] 

histogram  nd = NormalDistribution[0, 1] Histogram[RandomReal[nd, 100], 10] 

boxandwhisker plot  nd = NormalDistribution[0, 1] n100 = RandomVariate[nd, 100] BoxWhiskerChart[d] ed = ExponentialDistribution[1] e100 = RandomVariate[ed, 100] u100 = RandomReal[1, 100] d = {n100, e100, u100} BoxWhiskerChart[d] 

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 > "Stacked"] 

scatter plot  nd = NormalDistribution[0, 1] rn = Function[RandomReal[nd]] d = {rn[],rn[]} & /@ Range[1,50] ListPlot[d] 

linear regression line  d = Table[{i, 2 i + RandomReal[{5, 5}]}, {i, 0, 20}] model = LinearModelFit[d, x, x] Show[ListPlot[d], Plot[model["BestFit"], {x, 0, 20}]] 

polygonal line plot  f = Function[i, {i, rn[]}] d = f /@ Range[1, 20] ListLinePlot[d] 

area 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}}] 

cubic spline  d = Table[{i, RandomReal[nd]}, {i, 0, 20}] f = Interpolation[d, InterpolationOrder > 3] Show[ListPlot[d], Plot[f[x], {x, 0, 20}]] 

function plot  Plot[Sin[x], {x, 4, 4}]  ploth(x=4, 4, sin(x))  
quantilequantile 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}] ListLinePlot[d, AxesLabel > {x, x^2}] 

logarithmic yaxis  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}] ListPointPlot3D[d] 

additional 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}] BubbleChart[d] 

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
interpreter
How to execute a script.
pari/gp
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!")
quit
repl
How to launch a command line readevalprint loop for the language.
mathematica:
One can create a REPL called math on Mac OS X with the following command:
$ sudo ln s /Applications/Mathematica.app/Contents/MacOS/MathKernel /usr/local/bin/math
$ math
block delimiters
How blocks are delimited.
statement separator
How statements are separated.
endofline comment
Character used to start a comment that goes to the end of the line.
multiple line comment
Variables and Expressions
assignment
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.
mathematica:
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 reevaluated each time the variable is used.
mathematica:
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
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
Arithmetic and Logic
true and false
The boolean literals.
falsehoods
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.
power
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.
sqrt
The square root function.
For positive arguments the positive square root is returned.
sqrt 1
How the square root function handles negative arguments.
mathematica:
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.
pari/gip:
The seed is set to a fixed value at start up.
mathematica:
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.
mathematica:
The notation works for any base from 2 to 36.
Strings
string literals
newline in literal
character access
chr and ord
length
concatenate
index of substring
extract substring
split
convert from string, to string
How to convert strings to numbers and vice versa.
join
trim
case manipulation
sprintf
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.
Arrays
literal
The notation for an array literal.
size
The number of elements in the array.
empty test
How to test whether an array is empty.
lookup
How to access an array element by its index.
update
How to change the value stored at an array index.
outofbounds behavior
What happens when an attempt is made to access an element at an outofbounds index.
element index
How to get the index of an element in an array.
slice
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
head
tail
cons
concatenate
replicate
copy
How to copy an array. Updating the copy will not alter the original.
iterate
reverse
sort
dedupe
membership
How to test whether a value is an element of a list.
intersection
How to to find the intersection of two lists.
union
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.
map
filter
reduce
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.
zip
Sequences
Multidimensional Arrays
Dictionaries
record literal
record member access
Functions
definition
invocation
function value
Execution Control
if
How to write a branch statement.
mathematica:
The 3rd argument (the else clause) of an If expression is optional.
while
How to write a conditional loop.
mathematica:
Do can be used for a finite unconditional loop:
Do[Print[foo], {10}]
for
How to write a Cstyle for statement.
break/continue
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.
Files
Libraries and Namespaces
Reflection
function documentation
How to get the documentation for a function.
Algebra
Calculus
Number Theory
Vectors
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.
elementwise arithmetic operators
How to perform an elementwise arithmetic operation on vectors.
vector length mismatch
What happens when an elementwise 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 threedimensional vectors.
norms
How to compute the norm of a vector.
Matrices
literal or constructor
Literal syntax or constructor for creating a matrix.
mathematica:
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.
dimensions
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.
elementwise operators
Operators which act on two identically sized matrices element by element. Note that elementwise multiplication of two matrices is used less frequently in mathematics than matrix multiplication.
multiplication
How to multiply matrices. Matrix multiplication should not be confused with elementwise multiplication of matrices. Matrix multiplication in noncommutative and only requires that the number of columns of the matrix on the left match the number of rows of the matrix. Elementwise multiplication, by contrast, is commutative and requires that the dimensions of the two matrices be equal.
kronecker product
The Kronecker product is a noncommutative 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.
comparison
How to test two matrices for equality.
norms
How to compute the 1norm, the 2norm, the infinity norm, and the frobenius norm.
Distributions
univariatecharts 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 yaxis 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.
mathematica
horizontal bar chart
A bar chart in which zero is the yaxis 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.
stemandleaf plot
histogram
boxandwhisker plot
set chart title
Bivariate Charts
stacked bar chart
Trivariate Charts
Mathematica
Mathematica Documentation Center
WolframAlpha
SymPy
Welcome to SymPy’s documentation!
When using SymPy in IPython, the following command enables LaTeX formatted output:
from sympy import *
interactive.printing.init_printing(use_latex=True)
Pari/GP
A Tutorial for Pari/GP (pdf)
Pari/GP Functions by Category
Pari/GP Reference Card (pdf)