Wolfram: Mathematica Notation Basics
Here's a list of the most commonly used Mathematica (Wolfram language) syntax.
Arithmetic Operator
x ^ y
means x raised to power of y.- space is implicit multiplication. e.g.
a b
meansa * b
.
Brackets
- Square brackets means function argument. e.g.
Sin[x]
- Parenthesis means order of operation. e.g.
(3 + 5) * 2
- Curly braces means list. e.g.
{a,b,c}
, also for vector. Nested list represent a matrx or tree. - Double Square brackets means getting an element from a list. e.g.
{x,y,z}[[1]]
returnsx
.
Vector and Matrix
{a,b}
is a 2D vector.{a,b,c}
is 3D vector.{{a,b},{c,d}}
is a matrix, with 1st row{a,b}
, second row{c,d}
.
{a,b} . {x,y}
means dot product.{{a,b},{c,d}} . {x,y}
means matrix multiplication with the vector{x,y}
.
{a,b} + {x,y}
means vector addition{a + x, b + y}
.{a,b} + c
means{a + c, b + c}
.{x,y} * c
means{x c, y c}
.{x,y} / c
means{x/z, y/z}
.
Norm[v]
is the length of a vector v.Normalize[v]
is the unit vector of v.
Function
f[x]
is a function f applied on x.f@x
is the prefix notation forf[x]
. e.g.Cos@x
meansCos[x]
.x//f
is the postfix notation forf[x]
. e.g.x//Cos
meansCos[x]
.
Function Definition
Function[{x},x+1]
is a lambda function, adding 1 to arg.Function[{x,y},x+y]
is a lambda function, sum of the args.
#
the hash sign stand for parameter of a function.#
or#1
is first parameter,#2
second, etc. For example,Function[#1+#2]
is equivalent toFunction[{x,y},x+y]
.&
(ampersand) means the expression before is a function, with hash sign#
meaning its parameters. e.g.(#1 + #2 &)
is the same asFunction[ {x, y}, x + y ]
f[x_,y_] := x + y
is a definition of function using pattern matching. Here it is a sum of 2 args.
Complex Number
I
(Capital letter I) is the imaginary number.