User's Manual Screenshot Examples Additional resources
Eigenmath
abs(x)
Returns the absolute value or vector length of x.
abs(3 + 4 i)
5
adj(m)
Returns the adjunct of matrix m.
The inverse of m equals adjunct divided by determinant.
A = ((a,b),(c,d))
adj(A)
┌ ┐
│ d −b │
│ │
│ −c a │
└ ┘
and(a,b,...)
Returns 1 if all arguments have nonzero values, returns 0 otherwise.
Arguments can use the relational operators
==
<
<=
>
>=
and(a,b)
1
arg(z)
Returns the angle of complex z.
Symbols are treated as representing real numbers.
If z is a vector, matrix, or higher order tensor then
arg is applied to each component.
arg(x + i y)
arctan(y,x)
binding(s)
The result of evaluating a symbol can differ from the symbol's binding.
For example, the result may be expanded.
The binding function returns the actual binding of a symbol.
p = quote((x + 1)^2)
p
2
p = x + 2 x + 1
binding(p)
2
(x + 1)
break
Break out of a loop or for function.
k = 0
loop(k = k + 1, test(k == 4, break), print(k))
k = 1
k = 2
k = 3
ceiling(x)
Returns the smallest integer greater than or equal to x.
ceiling(1/2)
1
check(x)
If x is true (nonzero) then continue, else stop.
check(exp(i pi) == -1)
choose(n,k)
Returns the binomial coefficient n choose k.
choose(52,5) -- number of poker hands
2598960
clear
Clears all symbol definitions.
clock(z)
Returns complex z in polar form with base of negative 1 instead of e.
Symbols are treated as representing real numbers.
If z is a vector, matrix, or higher order tensor then
clock is applied to each component.
clock(x + i y)
arctan(y,x)
╶───────────╴ ┌ ┐1/2
π │ 2 2│
(−1) │x + y │
│ │
└ ┘
conj(z)
Returns the complex conjugate of z.
Symbols are treated as representing real numbers.
If z is a vector, matrix, or higher order tensor then
conj is applied to each component.
conj(x + i y)
x - i y
contract(a,i,j,...)
Returns the contraction of tensor a with respect to indices i, j, etc.
If i and j are omitted then 1 and 2 are used.
The argument list can be extended for multiple contract operations.
The arguments are evaluated from left to right.
For example,
contract(A,1,2,2,3)
is equivalent to
contract(contract(A,1,2),2,3).
A = ((a,b),(c,d))
contract(A) -- trace of matrix A
a + d
cos(x)
Returns the cosine of x.
The inverse is arccos(x).
cosh(x)
Returns the hyperbolic cosine of x.
The inverse is arccosh(x).
cross(u,v)
Returns the cross product of vectors u and v.
curl(v)
Returns the curl of vector v with respect to symbols
x, y, and z.
d(f,x,...)
Returns the derivative of f with respect to x and any additional arguments.
d(sin(x),x)
cos(x)
Multiderivatives are computed by extending the argument list.
d(sin(x),x,x)
−sin(x)
A numeric argument n computes the nth derivative with respect to the previous symbol.
d(sin(x),x,2)
−sin(x)
Argument f can be a tensor of any rank.
Argument x can be a vector.
When x is a vector the result is the gradient of f.
F = (f(),g(),h())
X = (x,y,z)
d(F,X)
┌ ┐
│ d(f(),x) d(f(),y) d(f(),z) │
│ │
│ d(g(),x) d(g(),y) d(g(),z) │
│ │
│ d(h(),x) d(h(),y) d(h(),z) │
└ ┘
Symbol d can be used as a variable name.
Doing so does not conflict with function d.
Function derivative is a synonym for d.
Symbol d can be redefined as a different function in which case
derivative is still available.
defint(f,x,a,b,...)
Returns the definite integral of f with respect to x
evaluated from a to b.
The argument list can be extended for multiple integrals.
The following example integrates over theta then over phi.
defint(sin(theta), theta, 0, pi, phi, 0, 2 pi)
4 π
denominator(x)
Returns the denominator of expression x.
denominator(a/b)
b
det(m)
Returns the determinant of matrix m.
A = ((a,b),(c,d))
det(A)
a d - b c
dim(a,n)
Returns the dimension of the nth index of tensor a.
Index numbering starts with 1.
A = ((1,2),(3,4),(5,6))
dim(A,1)
3
div(v)
Returns the divergence of vector v with respect to symbols
x,
y, and
z.
do(a,b,...)
Evaluates each argument from left to right.
Returns the result of the final argument.
do(A=1,B=2,A+B)
3
dot(a,b,...)
Returns the inner product of arguments a, b, etc.
Arguments can have any rank and are evaluated from right to left.
dot((a,b),(c,d))
a c + b d
draw(f,x)
Draws a graph of f(x).
Drawing ranges can be set with
xrange
and
yrange.
xrange = (0,1)
yrange = (0,1)
draw(x^2,x)
eigenvec(m)
Returns eigenvectors for matrix m.
Matrix m is required to be numerical, real, and symmetric.
The return value is a matrix with each column an eigenvector.
Eigenvalues are obtained as shown.
A = ((3,5),(5,3))
Q = eigenvec(A)
D = dot(transpose(Q),A,Q) -- eigenvalues on diagonal of D
D
┌ ┐
│ 8 0 │
D = │ │
│ 0 -2 │
└ ┘
erf(x)
Returns the error function of x.
Returns a numerical value if x is a real number.
d(erf(x),x)
┌ ┐
│ 2│
2 exp│−x │
│ │
└ ┘
╶──────────╴
1/2
π
erfc(x)
Returns the complementary error function of x.
Returns a numerical value if x is a real number.
d(erfc(x),x)
┌ ┐
│ 2│
2 exp│−x │
│ │
└ ┘
−╶──────────╴
1/2
π
eval(f,a,b,c,d,...)
Returns f evaluated with expression a replaced by expression b,
c by d, etc.
f = exp(i x)
eval(f,x,pi)
-1
exit
Terminate and return to the shell (only for shell-mode Eigenmath).
exp(x)
Returns the exponential of x.
exp(i pi)
-1
Returns expression x with trigonometric and hyperbolic functions converted to exponentials.
expform(cos(x))
1 1
╶─╴ exp(i x) + ╶─╴ exp(−i x)
2 2
factorial(n)
Returns the factorial of n.
The expression
n!
can also be used.
20!
2432902008176640000
fdist(x,df1,df2)
Returns the probability that a random sample from an F-distribution is less than or equal to x.
float(x)
Returns expression x with rational numbers and integers converted to
floating point values.
The symbol
pi
and the natural number are also converted.
float(212^17)
39
3.52947 10
floor(x)
Returns the largest integer less than or equal to x.
floor(1/2)
0
for(k,a,b,c,...)
For k equals a to b inclusive, evaluate the remaining arguments in a loop.
Symbol k is advanced by plus or minus 1 in the direction of b each time through the loop.
Use break to exit the loop immediately.
The original value of k is restored after for completes.
If i is used for k then the imaginary unit is overridden in the scope of for.
for(k,1,3,print(k))
k = 1
k = 2
k = 3
grad(f)
Returns the gradient
d(f,(x,y,z)).
grad(f())
┌ ┐
│ d(f(),x) │
│ │
│ d(f(),y) │
│ │
│ d(f(),z) │
└ ┘
hadamard(a,b,...)
Returns the Hadamard (element-wise) product.
The arguments are required to have the same dimensions.
The Hadamard product is also accomplished by simply multiplying the arguments.
A = ((A11,A12),(A21,A22))
B = ((B11,B12),(B21,B22))
A B
┌ ┐
│ A B A B │
│ 11 11 12 12 │
│ │
│ A B A B │
│ 21 21 22 22 │
└ ┘
i
Symbol i is the imaginary unit.
i^2
-1
imag(z)
Returns the imaginary part of complex z.
Symbols are treated as representing real numbers.
If z is a vector, matrix, or higher order tensor then
imag is applied to each component.
imag(x + i y)
y
incbeta(x,a,b)
Returns the incomplete beta function of x.
Converts expression x to a string and returns the result.
p = (x + 1)^2
infixform(p)
x^2 + 2 x + 1
inner(a,b,...)
Returns the inner product of arguments a, b, etc.
Arguments can have any rank and are evaluated from right to left.
inner((a,b),(c,d))
a c + b d
integral(f,x,...)
Returns the integral of f with respect to x and any additional arguments.
integral(x^2,x)
1 3
╶─╴ x
3
inv(m)
Returns the inverse of matrix m.
A = ((1,2),(3,4))
inv(A)
┌ ┐
│ −2 1 │
│ │
│ 3 1 │
│ ╶─╴ −╶─╴ │
│ 2 2 │
└ ┘
kronecker(a,b,...)
Returns the Kronecker product of a, b, etc.
I = ((1,0),(0,1))
A = ((a,b),(c,d))
kronecker(I,A)
┌ ┐
│ a b 0 0 │
│ │
│ c d 0 0 │
│ │
│ 0 0 a b │
│ │
│ 0 0 c d │
└ ┘
last
Symbol last holds the previous result.
212^17
3529471145760275132301897342055866171392
last
3529471145760275132301897342055866171392
Symbol last is an implied argument when a function has no argument list.
212^17
3529471145760275132301897342055866171392
float
39
3.52947 10
lgamma(x)
Returns the log of the absolute value of the Gamma function of x.
lgamma(0.5)
0.572365
log(x)
Returns the natural logarithm of x.
log(x^y)
y log(x)
Returns expression x with inverse trigonometric and
inverse hyperbolic functions converted to logarithms.
logform(arccos(x))
┌ ┐
│ ┌ ┐1/2│
│ │ 2 │ │
−i log│x + i │−abs(x) + 1│ │
│ │ │ │
│ └ ┘ │
└ ┘
loop(a,b,c,...)
Evaluates arguments in a loop.
Use break to break out of the loop.
k = 0
loop(k = k + 1, test(k == 4, break), print(k))
k = 1
k = 2
k = 3
mag(z)
Returns the magnitude of complex z.
Symbols are treated as representing real numbers.
If z is a vector, matrix, or higher order tensor then
mag is applied to each component.
mag(x + i y)
┌ ┐1/2
│ 2 2│
│x + y │
│ │
└ ┘
minor(m,i,j)
Returns the minor of matrix m for row i and column j.
A = ((1,2,3),(4,5,6),(7,8,9))
minor(A,1,1) == det(minormatrix(A,1,1))
1
minormatrix(m,i,j)
Returns a copy of matrix m with row i and column j removed.
A = ((1,2,3),(4,5,6),(7,8,9))
minormatrix(A,1,1)
┌ ┐
│ 5 6 │
│ │
│ 8 9 │
└ ┘
mod(a,b)
Returns the remainder of a over b.
mod(5,3/8)
1
╶─╴
8
noexpand(x)
Evaluates expression x without expanding products of sums.
noexpand((x + 1)^2 / (x + 1))
x + 1
not(x)
Returns 1 if x has a value of zero, returns 0 otherwise.
not(a == b)
1
nroots(p,x)
Returns the approximate roots of polynomials with real or complex coefficients.
Multiple roots are returned as a vector.
p = x^5 - 1
nroots(p,x)
┌ ┐
│ 1 │
│ │
│ −0.809017 + 0.587785 i │
│ │
│ −0.809017 − 0.587785 i │
│ │
│ 0.309017 + 0.951057 i │
│ │
│ 0.309017 − 0.951057 i │
└ ┘
number(x)
Returns 1 if x is a real number.
Returns 0 otherwise.
number(1/2)
1
number(x)
0
numerator(x)
Returns the numerator of expression x.
numerator(a/b)
a
or(a,b,...)
Returns 1 if any argument has a nonzero value, returns 0 otherwise.
Arguments can use the relational operators
==
<
<=
>
>=
or(a,b)
1
outer(a,b,...)
Returns the outer product of vectors, matrices, and tensors.
A = (a,b,c)
B = (x,y,z)
outer(A,B)
┌ ┐
│ a x a y a z │
│ │
│ b x b y b z │
│ │
│ c x c y c z │
└ ┘
pi
Symbol for π.
exp(i pi)
-1
polar(z)
Returns complex z in polar form.
Symbols are treated as representing real numbers.
If z is a vector, matrix, or higher order tensor then
polar is applied to each component.
polar(x + i y)
┌ ┐1/2
│ 2 2│
│x + y │ exp(i arctan(y,x))
│ │
└ ┘
power
Use
^
to raise something to a power.
Use parentheses for negative powers.
x^(-1/2)
1
╶────╴
1/2
x
print(a,b,...)
Evaluate arguments and print the results.
Useful for printing from inside a
for
loop.
for(j,1,3,print(j))
j = 1
j = 2
j = 3
product(k,a,b,f)
For k equals a to b evaluate f.
Returns the product of all f.
The original value of k is restored after product completes.
If i is used for k then the imaginary unit is overridden in the scope of product.
product(k,1,3,x+k)
3 2
x + 6 x + 11 x + 6
product(y)
Returns the product of components of y.
y = (1,2,3,4)
product(y)
24
quote(x)
Returns expression x without evaluating it first.
quote((x + 1)^2)
2
(x + 1)
rand
Returns a random floating point value from the interval [0,1).
rand
0.655424
rank(a)
Returns the number of indices that tensor a has.
A = ((a,b),(c,d))
rank(A)
2
rationalize(x)
Returns expression x with everything over a common denominator.
rationalize(1/a + 1/b + 1/2)
2 a + a b + 2 b
╶───────────────╴
2 a b
Note:
rationalize
returns an unexpanded expression.
If the result is assigned to a symbol, evaluating the symbol will expand the result.
Use
binding
to retrieve the unexpanded expression.
f = rationalize(1/a + 1/b + 1/2)
binding(f)
2 a + a b + 2 b
╶───────────────╴
2 a b
real(z)
Returns the real part of complex z.
Symbols are treated as representing real numbers.
If z is a vector, matrix, or higher order tensor then
real is applied to each component.
real(x + i y)
x
rect(z)
Returns complex z in rectangular form.
Symbols are treated as representing real numbers.
If z is a vector, matrix, or higher order tensor then
rect is applied to each component.
rect(exp(i x))
cos(x) + i sin(x)
roots(p,x)
Returns the rational roots of a polynomial.
Multiple roots are returned as a vector.
p = (x + 1) (x - 2)
roots(p,x)
┌ ┐
│ −1 │
│ │
│ 2 │
└ ┘
If no roots are found then
nil
is returned.
A
nil
result prints as blank so the following example uses
infixform
to print
nil
as a string.
p = x^2 + 1
infixform(roots(p,x))
nil
rotate(u,s,k,...)
Rotates vector u and returns the result.
Vector u is required to have 2n elements
where n is an integer from 1 to 15.
Arguments s,k,... are a sequence of rotation codes
where s is an upper case letter and k is a qubit number
0 to n − 1.
Rotations are evaluated from left to right.
The available rotations are
| C, k | Control prefix |
| H, k | Hadamard |
| P, k, φ | Phase modifier (use φ = 1/4 π for T rotation) |
| Q, k | Quantum Fourier transform |
| V, k | Inverse quantum Fourier transform |
| W, k, j | Swap qubits |
| X, k | Pauli X |
| Y, k | Pauli Y |
| Z, k | Pauli Z |
Control prefix C, k modifies the next rotation code so that it is
a controlled rotation with k as the control qubit.
Use two or more prefixes to specify multiple control qubits.
For example, C, k, C, j, X, m is a Toffoli rotation.
Fourier rotations Q, k and V, k are applied
to qubits 0 through k.
(Q and V ignore any control prefix.)
See also the quantum computing section of the Eigenmath manual.
psi = (1,0,0,0)
rotate(psi,H,0)
┌ ┐
│ 1 │
│ ╶────╴ │
│ 1/2 │
│ 2 │
│ │
│ 1 │
│ ╶────╴ │
│ 1/2 │
│ 2 │
│ │
│ 0 │
│ │
│ 0 │
└ ┘
run(x)
Run script x where x evaluates to a filename string.
Useful for importing function libraries.
run("/Users/heisenberg/EVA2.txt")
For Eigenmath installed from the Mac App Store, run files need to be put in the directory
~/Library/Containers/com.gweigt.eigenmath/Data/
and the filename does not require a path.
run("EVA2.txt")
sgn(x)
Returns the sign of x if x is a real number.
sgn(0)
0
sgn(1/2)
1
sgn(-1/2)
-1
sgn(-x)
sgn(-x)
simplify(x)
Returns expression x in a simpler form.
simplify(sin(x)^2 + cos(x)^2)
1
The equality operator simplifies automatically.
sin(x)^2 + cos(x)^2 == 1
1
sin(x)
Returns the sine of x.
The inverse is arcsin(x).
sinh(x)
Returns the hyperbolic sine of x.
The inverse is arcsinh(x).
sqrt(x)
Returns the square root of x.
sqrt(10!)
1/2
720 7
stop
In a script, it does what it says.
sum(k,a,b,f)
For k equals a to b evaluate f.
Returns the sum of all f.
The original value of k is restored after sum completes.
If i is used for k then the imaginary unit is overridden in the scope of sum.
sum(k,1,3,x^k)
3 2
x + x + x
sum(y)
Returns the sum of components of y.
y = (1,2,3,4)
sum(y)
10
tan(x)
Returns the tangent of x.
The inverse is arctan(x).
Also arctan(y,x) for y over x.
tanh(x)
Returns the hyperbolic tangent of x.
The inverse is arctanh(x).
taylor(f,x,n,a)
Returns the nth order Taylor series expansion of f(x) at a.
If argument a is omitted then zero is used for the expansion point.
taylor(1/(1-x),x,5)
5 4 3 2
x + x + x + x + x + 1
tdist(x,df)
Returns the probability that a random sample from a t-distribution is less than or equal to x.
The inverse is tdistinv(x,df).
test(a,b,c,d,...)
If argument a is true (nonzero) then b is returned, else if c is true then d is returned, etc.
If the number of arguments is odd then the final argument is returned if all else fails.
Arguments can use the relational operators
==
<
<=
>
>=
test(a == b, "yes", "no")
no
tgamma(x)
Returns the Gamma function of x if x is a real number.
tgamma(4)
6
trace
Set
trace=1
in a script to print the script as it is evaluated.
Useful for debugging.
(To obtain the trace of a matrix, use
contract.)
transpose(a,i,j,...)
Returns the transpose of tensor a with respect to indices i, j, etc.
If i and j are omitted then 1 and 2 are used,
hence a matrix can be transposed with a single argument.
The argument list can be extended by pairs of indices for multiple transpose operations.
The arguments are evaluated from left to right.
For example,
transpose(A,1,2,2,3)
is equivalent to
transpose(transpose(A,1,2),2,3).
A = ((a,b),(c,d))
transpose(A)
┌ ┐
│ a c │
│ │
│ b d │
└ ┘
tty
Set
tty=1
to show results in string format.
Set
tty=0
to turn off.
Can be useful when displayed results exceed window size.
tty = 1
(x + 1)^2
x^2 + 2 x + 1
unit(n)
Returns an n by n identity matrix.
unit(3)
┌ ┐
│ 1 0 0 │
│ │
│ 0 1 0 │
│ │
│ 0 0 1 │
└ ┘
zero(a,b,...)
Returns a null tensor with dimensions a, b, etc.
zero(2,3,3)
┌ ┐
│ ┌ ┐ │
│ │ 0 0 0 │ │
│ │ │ │
│ │ 0 0 0 │ │
│ │ │ │
│ │ 0 0 0 │ │
│ └ ┘ │
│ │
│ ┌ ┐ │
│ │ 0 0 0 │ │
│ │ │ │
│ │ 0 0 0 │ │
│ │ │ │
│ │ 0 0 0 │ │
│ └ ┘ │
└ ┘