abs
adj
and
arccos
arccosh
arcsin
arcsinh
arctan
arctanh
arg
binding
ceiling
check
choose
circexp
clear
clock
cofactor
conj
contract
cos
cosh
cross
curl
d
defint
denominator
det
dim
div
do
dot
draw
eigenvec
eval
exp
expcos
expcosh
expsin
expsinh
exptan
exptanh
factorial
float
floor
for
grad
hadamard
i
imag
infixform
inner
integral
inv
j
kronecker
last
log
mag
minor
minormatrix
mod
noexpand
not
nroots
numerator
or
outer
pi
polar
power
print
product
quote
rank
rationalize
real
rect
roots
rotate
run
simplify
sin
sinh
sqrt
stop
sum
tan
tanh
taylor
test
trace
transpose
tty
unit
zero

abs(x)

Returns the absolute value or vector length of x.

X = (x,y,z)
abs(X)
┌            ┐1/2
│ 2    2    2│   
│x  + y  + z │   
│            │   
└            ┘   

adj(m)

Returns the adjunct of matrix m. Adjunct is equal to determinant times inverse.

A = ((a,b),(c,d))
adj(A) == det(A) inv(A)
1

and(a,b,...)

Returns 1 if all arguments are true (nonzero). Returns 0 otherwise.

and(1=1,2=2)
1

arccos(x)

Returns the arc cosine of x.

arccos(1/2)
 1   
╶─╴ π
 3   

arccosh(x)

Returns the arc hyperbolic cosine of x.

arcsin(x)

Returns the arc sine of x.

arcsin(1/2)
 1   
╶─╴ π
 6   

arcsinh(x)

Returns the arc hyperbolic sine of x.

arctan(y,x)

Returns the arc tangent of y over x. If x is omitted then x = 1 is used.

arctan(1,0)
 1   
╶─╴ π
 2   

arctanh(x)

Returns the arc hyperbolic tangent of x.

arg(z)

Returns the angle of complex z.

arg(2 - 3i)
-arctan(3,2)

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)

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 in a script, else stop. Expression x can include the relational operators =, ==, <, <=, >, >=. Use the not function to test for inequality.

A = exp(i pi)
B = -1
check(A == B) -- stop here if A not equal to B

choose(n,k)

Returns the binomial coefficient n choose k.

choose(52,5) -- number of poker hands
2598960

circexp(x)

Returns expression x with circular and hyperbolic functions converted to exponentials.

circexp(cos(x) + i sin(x))
exp(i x)

clear

Clears all symbol definitions.

clock(z)

Returns complex z in polar form with base of negative 1 instead of e.

clock(2 - 3i)
            arctan(3,2) 
          -╶───────────╴
  1/2            π      
13    (−1)              

cofactor(m,i,j)

Returns the cofactor of matrix m for row i and column j.

A = ((a,b),(c,d))
cofactor(A,1,2) == adj(A)[2,1]
1

conj(z)

Returns the complex conjugate of z.

conj(2 - 3i)
2 + 3 i

contract(a,i,j)

Returns tensor a summed over indices i and j. If i and j are omitted then 1 and 2 are used. The expression contract(m) computes the trace of matrix m.

A = ((a,b),(c,d))
contract(A)
a + d

cos(x)

Returns the cosine of x.

cos(pi/4)
  1   
╶────╴
  1/2 
 2    

cosh(x)

Returns the hyperbolic cosine of x.

circexp(cosh(x))
 1             1        
╶─╴ exp(−x) + ╶─╴ exp(x)
 2             2        

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 y),x,2,y,2)
 2  2                                       
x  y  sin(x y) − 4 x y cos(x y) − 2 sin(x y)

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.

Symbol d can be redefined as a different function. The function derivative, a synonym for d, can be used to obtain a partial derivative.

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 as shown in the following example.

f = (1 + cos(theta)^2) sin(theta)
defint(f, theta, 0, pi, phi, 0, 2 pi) -- integrate over theta then over phi
 16   
╶──╴ π
 3    

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 dot product of vectors, matrices, and tensors. Also known as the matrix product. Arguments are evaluated from right to left. The following example solves for X in AX = B.

A = ((1,2),(3,4))
B = (5,6)
X = dot(inv(A),B)
X
    ┌     ┐
    │ −4  │
    │     │
X = │  9  │
    │ ╶─╴ │
    │  2  │
    └     ┘

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 = ((1,2),(3,4))
A = A + transpose(A) -- symmetrize
Q = eigenvec(A)
D = dot(transpose(Q),A,Q) -- eigenvalues are on the diagonal of D
dot(Q,D,transpose(Q))
    ┌       ┐
    │ 2   5 │
A = │       │
    │ 5   8 │
    └       ┘

eval(f,x,a,y,b,...)

Returns f evaluated with x replaced by a, y replaced by b, etc. All arguments can be expressions.

f = sqrt(x^2 + y^2)
eval(f,x,3,y,4)
5

In the following example, eval is used to replace x with cos(theta).

-- associated legendre of cos theta
P(l,m,x) = test(m < 0, (-1)^m (l + m)! / (l - m)! P(l,-m),
           1 / (2^l l!) sin(theta)^m *
           eval(d((x^2 - 1)^l, x, l + m), x, cos(theta)))

P(2,-1)
  1
−╶─╴ cos(θ) sin(θ)
  2

exp(x)

Returns the exponential of x.

exp(i pi)
-1

expcos(z)

Returns the cosine of z in exponential form.

expcos(z)
 1              1           
╶─╴ exp(i z) + ╶─╴ exp(−i z)
 2              2           

expcosh(z)

Returns the hyperbolic cosine of z in exponential form.

expcosh(z)
 1             1        
╶─╴ exp(−z) + ╶─╴ exp(z)
 2             2        

expsin(z)

Returns the sine of z in exponential form.

expsin(z)
  1                1             
−╶─╴ i exp(i z) + ╶─╴ i exp(−i z)
  2                2             

expsinh(z)

Returns the hyperbolic sine of z in exponential form.

expsinh(z)
  1             1        
−╶─╴ exp(−z) + ╶─╴ exp(z)
  2             2        

exptan(z)

Returns the tangent of z in exponential form.

exptan(z)
       i             i exp(2 i z)  
╶──────────────╴ − ╶──────────────╴
 exp(2 i z) + 1     exp(2 i z) + 1 

exptanh(z)

Returns the hyperbolic tangent of z in exponential form.

exptanh(z)
       1             exp(2 z)   
−╶────────────╴ + ╶────────────╴
  exp(2 z) + 1     exp(2 z) + 1 

factorial(n)

Returns the factorial of n. The expression n! can also be used.

20!
2432902008176640000

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(i,j,k,a,b,...)

For i equals j through k evaluate a, b, etc.

for(k,1,3,A=k,print(A))
A = 1
A = 2
A = 3

Note: The original value of i is restored after for completes. If symbol i is used for index variable i then the imaginary unit is overridden in the scope of for.

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 initialized to the imaginary unit (−1)1/2.

exp(i pi)
-1

Note: It is OK to clear or redefine i and use the symbol for something else.

imag(z)

Returns the imaginary part of complex z.

imag(2 - 3i)
-3

infixform(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 vectors, matrices, and tensors. Also known as the matrix product. Arguments are evaluated from right to left.

A = ((a,b),(c,d))
B = (x,y)
inner(A,B)
┌           ┐
│ a x + b y │
│           │
│ c x + d y │
└           ┘

Note: inner and dot are the same function.

integral(f,x)

Returns the integral of f with respect to x.

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  │
└            ┘

j

Set j=sqrt(-1) to use j for the imaginary unit instead of i.

j = sqrt(-1)
1/sqrt(-1)
-j

kronecker(a,b,...)

Returns the Kronecker product of vectors and matrices.

A = ((1,2),(3,4))
B = ((a,b),(c,d))
kronecker(A,B)
┌                       ┐
│  a     b    2 a   2 b │
│                       │
│  c     d    2 c   2 d │
│                       │
│ 3 a   3 b   4 a   4 b │
│                       │
│ 3 c   3 d   4 c   4 d │
└                       ┘

last

The result of the previous calculation is stored in last.

212^17
3529471145760275132301897342055866171392
last^(1/17)
212

Note: Symbol last is an implied argument when a function has no argument list.

212^17
3529471145760275132301897342055866171392
float
          39
3.52947 10

log(x)

Returns the natural logarithm of x.

log(x^y)
y log(x)

mag(z)

Returns the magnitude of complex z.

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 0 if x is true (nonzero). Returns 1 otherwise.

not(1=1)
0

nroots(p,x)

Returns the approximate roots of polynomials with real or complex coefficients. Multiple roots are returned as a vector. See also roots.

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  │
└                        ┘

numerator(x)

Returns the numerator of expression x.

numerator(a/b)
a

or(a,b,...)

Returns 1 if at least one argument is true (nonzero). Returns 0 otherwise.

or(1=1,2=2)
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.

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 expressions 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(i,j,k,f)

For i equals j through k evaluate f. Returns the product of all f.

product(j,1,3,x + j)
 3      2
x  + 6 x  + 11 x + 6

The original value of i is restored after product completes. If symbol i is used for index variable i then the imaginary unit is overridden in the scope of product.

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)

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.

real(2 - 3i)
2

rect(z)

Returns complex z in rectangular form.

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. See also nroots.

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, kControl prefix
H, kHadamard
P, k, φPhase modifier (use φ = 1/4 π for T rotation)
Q, kQuantum Fourier transform
V, kInverse quantum Fourier transform
W, k, j Swap qubits
X, kPauli X
Y, kPauli Y
Z, kPauli 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/eigenmath/Data/ and the filename does not require a path.

run("EVA2.txt")

simplify(x)

Returns expression x in a simpler form.

simplify(sin(x)^2 + cos(x)^2)
1

sin(x)

Returns the sine of x.

sin(pi/4)
  1   
╶────╴
  1/2 
 2    

sinh(x)

Returns the hyperbolic sine of x.

circexp(sinh(x))
  1             1        
−╶─╴ exp(−x) + ╶─╴ exp(x)
  2             2        

sqrt(x)

Returns the square root of x.

sqrt(10!)
     1/2
720 7

stop

In a script, it does what it says.

sum(i,j,k,f)

For i equals j through k evaluate f. Returns the sum of all f.

sum(j,1,5,x^j)
 5    4    3    2
x  + x  + x  + x  + x

The original value of i is restored after sum completes. If symbol i is used for index variable i then the imaginary unit is overridden in the scope of sum.

sum(y)

Returns the sum of components of y.

y = (1,2,3,4)
sum(y)
10

tan(x)

Returns the tangent of x.

tanh(x)

Returns the hyperbolic tangent of x.

circexp(tanh(x))
       1             exp(2 x)   
−╶────────────╴ + ╶────────────╴
  exp(2 x) + 1     exp(2 x) + 1 

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

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. Expressions can include the relational operators =, ==, <, <=, >, >=. Use the not function to test for inequality. (The equality operator == is available for contexts in which = is the assignment operator.)

A = 1
B = 1
test(A=B,"yes","no")
yes

trace

Set trace=1 in a script to print the script as it is evaluated. Useful for debugging.

trace = 1

Note: The contract function is used to obtain the trace of a matrix.

transpose(a,i,j)

Returns the transpose of tensor a with respect to indices i and j. If i and j are omitted then 1 and 2 are used. Hence a matrix can be transposed with a single argument.

A = ((a,b),(c,d))
transpose(A)
┌       ┐
│ a   c │
│       │
│ b   d │
└       ┘

Note: The argument list can be extended 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).

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(i,j,...)

Returns a null tensor with dimensions i, j, etc. Useful for creating a tensor and then setting the component values.

A = zero(3,3)
for(k,1,3,A[k,k]=k)
A
    ┌           ┐
    │ 1   0   0 │
    │           │
A = │ 0   2   0 │
    │           │
    │ 0   0   3 │
    └           ┘