Tips
-
Press the up and down arrow keys for command history.
-
Enter X^Y to raise X to the power Y.
-
Enter A B or A*B to multiply A times B.
AB is the symbol A sub B.
-
To use the symbol e for the natural number, first define it as e=exp(1).
-
Most functions can be used without arguments.
The previous result is used as a default argument.
-
The simplify function converts tensor zero to scalar zero.
-
A=B evaluates B and binds the result to the symbol A.
On the other hand, the function definition A(X)=B does not evaluate B until A
itself is evaluated.
-
How to use the scripting feature
-
Tensor calculus
The following examples can be pasted into the Edit Script window.
Index
Returns the absolute value (vector length, magnitude) of x.
Enter
abs((a,b,c))
Result
1/2
2 2 2
(a + b + c )
Returns the adjunct of matrix m.
Enter
A = ((a,b),(c,d))
adj(A)
Result
d -b
-c a
The inverse of a matrix is equal to the adjunct divided by the determinant.
Enter
inv(A) - adj(A) / det(A)
Result
0
Logical-and of predicate expressions.
Example
and(A = B, B = C)
Returns the inverse cosine of x.
Returns the inverse hyperbolic cosine of x.
Returns the inverse sine of x.
Returns the inverse hyperbolic sine of x.
Returns the inverse tangent of x.
Returns the inverse hyperbolic tangent of x.
Returns the argument (angle) of complex z.
Symbols in expression z are presumed to be positive and real.
Enter
arg(1 + exp(i pi/3))
Result
1/6 pi
Returns the binomial coefficient.
Enter
binomial(10,5)
Result
252
Causes an immediate return from a for function.
Expression x is evaluated and returned as the for function
value.
A break with no argument returns the symbol nil.
A break can be evaluated at any function level.
For example, for() can evaluate f() which evaluates
g() which evaluates break().
Returns the smallest integer not less than x.
If x is true then continue, else stop.
Example
check(A = B)
Returns the coefficient of x^n in polynomial p.
The x argument can be omitted for polynomials in x.
Returns the cofactor of m for row i and column j.
Attempts to simplify x by factoring common terms.
Enter
2 a (x + 1)
Result
2 a + 2 a x
Enter
condense(last)
Result
2 a (x + 1)
Returns the complex conjugate of z.
Enter
conj(3 + 4 i)
Result
3 - 4 i
Returns the contraction of tensor a across indices i
and j.
If i and j are omitted then indices 1 and 2 are used.
The following example shows how contract adds diagonal elements.
Enter
A = ((a,b),(c,d))
contract(A,1,2)
Result
a + d
Returns the cosine of x.
Returns the hyperbolic cosine of x.
Returns the partial derivative of f with respect to x.
The second argument can be omitted in which case the computer will guess which
symbol to use.
Returns the gradient of f when x is a vector.
Note that gradient raises the rank of f by 1.
Enter
d(x^2,x)
Result
2 x
For tensor f the derivative of each element is computed.
Enter
d((x,x^2),x)
Result
1
2 x
Functions with no arguments are treated as dependent on any variable.
Enter
d(f(),(x,y))
Result
d(f(),x)
d(f(),y)
Since partial derivatives commute, multi-derivatives are ordered to produce a
canonical form.
Enter
d(d(f(),y),x)
Result
d(d(f(),x),y)
The following table shows the various forms that can be used to compute
multiderivatives.
Form Equivalent form
d(f,2) d(d(f,x),x)
d(f,x,2) d(d(f,x),x)
d(f,x,x) d(d(f,x),x)
d(f,x,2,y,2) d(d(d(d(f,x),x),y),y)
d(f,x,x,y,y) d(d(d(d(f,x),x),y),y)
Returns the degree of polynomial p in x.
The x argument can be omitted.
If omitted, the computer will guess x from the contents of p.
Returns the denominator of expression x.
Enter
denominator(a/b)
Result
b
Returns the determinant of matrix m.
Enter
A = ((a,b),(c,d))
det(A)
Result
a d - b c
Returns the dimension of the ith index of tensor a.
If i is omitted then the dimension of the first index is returned.
Enter
A = (1,2,3,4)
dim(A)
Result
4
Enter
A = ((1,2,3),(4,5,6))
dim(A,1)
Result
2
Enter
dim(A,2)
Result
3
Evaluates expression x and displays the result using Times and Symbol
fonts.
User symbols are scanned for the keywords shown below.
Each keyword is replaced with its associated Greek letter glyph.
Multiglyph symbols are displayed using subscripts.
This function can be selected as the default display mode by setting tty = 0.
Gamma | Γ |
|
alpha | α |
|
mu | μ |
Delta | Δ |
|
beta | β |
|
nu | ν |
Theta | Θ |
|
gamma | γ |
|
xi | ξ |
Lambda | Λ |
|
delta | δ |
|
pi | π |
Xi | Ξ |
|
epsilon | ε |
|
rho | ρ |
Pi | Π |
|
zeta | ζ |
|
sigma | σ |
Sigma | Σ |
|
eta | η |
|
tau | τ |
Upsilon | Υ |
|
theta | θ |
|
upsilon | υ |
Phi | Φ |
|
iota | ι |
|
phi | φ |
Psi | Ψ |
|
kappa | κ |
|
chi | χ |
Omega | Ω |
|
lambda | λ |
|
psi | ψ |
| |
|
| |
|
omega | ω |
Evaluates each argument from left to right.
Returns the value of the last argument.
Returns the dot product of tensors (aka inner product).
Enter
A = (A1,A2,A3)
B = (B1,B2,B3)
dot(A,B)
Result
A1 B1 + A2 B2 + A3 B3
The dot product is equivalent to an outer product followed by a contraction
across the inner indices.
Enter
A = hilbert(10)
dot(A,A) - contract(outer(A,A),2,3)
Result
0
Draws a graph of f.
The second argument can be omitted in which case the computer will
guess what variable to use.
Parametric drawing occurs when f returns a vector.
Ranges are set with xrange and yrange.
The defaults are xrange = (-10,10) and
yrange = (-10,10).
The parametric variable range is set with trange.
The default is trange = (-pi,pi).
Example 1.
Enter
draw(5(cos(t),sin(t)))
Example 2.
Enter
draw(5(cos(3t),sin(5t)))
eigenval(m)
eigenvec(m)
These functions compute eigenvalues and eigenvectors numerically.
Matrix m must be both numerical and symmetric.
The eigenval function returns a matrix with the eigenvalues along
the diagonal.
The eigenvec function returns a matrix with the eigenvectors arranged as row
vectors.
The eigen function does not return anything but stores the eigenvalue matrix
in D and the eigenvector matrix in Q.
Example 1. Check the relation AX = lambda X where lambda is an eigenvalue and
X is the associated eigenvector.
Enter
A = hilbert(3)
eigen(A)
lambda = D[1,1]
X = Q[1]
dot(A,X) - lambda X
Result
-1.16435e-14
-6.46705e-15
-4.55191e-15
Example 2: Check the relation A = QTDQ.
Enter
A - dot(transpose(Q),D,Q)
Result
6.27365e-12 -1.58236e-11 1.81902e-11
-1.58236e-11 -1.95365e-11 2.56514e-12
1.81902e-11 2.56514e-12 1.32627e-11
Error function of x.
Enter
draw(erf(x))
Complementary error function of x.
Enter
draw(erfc(x))
Returns the evaluation of expression x.
Enter
A = quote(sin(pi/6))
A
Result
1
sin(--- pi)
6
Enter
eval(A)
Result
1
---
2
Returns the exponential of x.
The expression exp(1) should be used to represent the natural number e.
Enter
exp(1.0)
Result
2.71828
Enter
exp(a) exp(b)
Result
exp(a + b)
Returns the exponential cosine of x.
Enter
expcos(x)
Result
1 1
--- exp(-i x) + --- exp(i x)
2 2
Returns the exponential sine of x.
Enter
expsin(x)
Result
1 1
--- i exp(-i x) - --- i exp(i x)
2 2
factor(p,x)
The first form returns the prime factors for integer n.
Enter
factor(12345)
Result
3 5 823
The second form factors polynomial p in x.
The argument x can be omitted in which case the computer will
guess which symbol to use.
Enter
factor(x^3 + x^2 + x + 1)
Result
2
(1 + x) (1 + x )
Returns the factorial of x.
The syntax x! can also be used.
Enter
100!
Result
93326215443944152681699238856266700490715968264381621468592963895217599993229915
608941463976156518286253697920827223758251185210916864000000000000000000000000
Returns f with terms containing a (or b or...) removed.
Useful for implementing a "poor man's" Fourier transform.
Enter
Y = A exp(-i k x) + B exp(i k x)
filter(Y exp(-i k x), x)
Result
B
Converts rational numbers and integers in x to floating
point values. The symbol pi is also converted.
Enter
float(100!)
Result
9.33262e+157
Returns the largest integer not greater than x.
For a equals i through j evaluate b.
Normally for() returns the symbol nil.
A break() function can be used to return a different value.
The variable a has local scope within the for function.
The variable a remains unmodified after for returns.
The expressions i and j must evaluate to integers.
Usually b is a do() function.
Enter
for(k,1,4,print(1/k,tab(10),1/k^2))
Result
1 1
1 1
--- ---
2 4
1 1
--- ---
3 9
1 1
--- ----
4 16
Returns the greatest common divisor.
Returns the nth Hermite polynomial in x.
Enter
hermite(x,3)
Result
3
-12 x + 8 x
Returns a Hilbert matrix of order n.
Enter
hilbert(3)
Result
1 1
1 --- ---
2 3
1 1 1
--- --- ---
2 3 4
1 1 1
--- --- ---
3 4 5
Returns the imaginary part of complex z.
Symbols in expression z are presumed to be positive and real.
Enter
imag(1 + exp(i pi/3))
Result
1/2 3^(1/2)
Returns the inner product of tensors.
This is the same function as the dot product.
Enter
A = (A1,A2,A3)
B = (B1,B2,B3)
inner(A,B)
Result
A1 B1 + A2 B2 + A3 B3
Returns the integral of f with respect to x.
The second argument can be omitted in which case the computer will guess which
symbol to use.
Enter
integral(log(x),x)
Result
-x + x log(x)
Returns the inverse of matrix m.
Enter
A = ((a,b),(c,d))
inv(A)
Result
d b
----------- - -----------
a d - b c a d - b c
c a
- ----------- -----------
a d - b c a d - b c
Returns 1 if integer n is a prime number. Returns 0 if n is not
a prime number.
Enter
isprime(9007199254740991)
Result
0
Enter
isprime(2^53 - 111)
Result
1
Returns the nth Laguerre polynomial in x.
If the argument a is omitted or a equals zero
then the function returns the non-associated Laguerre polynomial.
Enter
laguerre(x,2)
Result
1 2
1 - 2 x + --- x
2
Enter
laguerre(x,2,a)
Result
3 1 2 1 2
1 + --- a - 2 x - a x + --- a + --- x
2 2 2
Returns the least common multiple.
Enter
lcm(2,3,4,x)
Result
12 x
Returns the nth Legendre polynomial in x.
Enter
legendre(x,2)
Result
1 3 2
- --- + --- x
2 2
Enter
legendre(x,2,0)
Result
1 3 2
- --- + --- x
2 2
Enter
legendre(x,2,1)
Result
1/2
2
-3 x (1 - x )
Returns the natural logarithm of x.
Enter
log(-10.0)
Result
2.30259 + i π
Returns the magnitude of complex z.
Symbols in expression z are presumed to be positive and real.
Enter
mag(1 + exp(i pi/3))
Result
3^(1/2)
Negates a predicate expression.
Example
not(A = B)
Returns the remainder of a divided by b.
Returns the numerator of expression x.
Enter
numerator(a/b)
Result
a
Logical-or of predicate expressions.
Example
or(A = B, A = C)
Returns the outer product of tensors (aka tensor product).
Enter
A = (A1,A2,A3)
B = (B1,B2,B3)
outer(A,B)
Result
A1 B1 A1 B2 A1 B3
A2 B1 A2 B2 A2 B3
A3 B1 A3 B2 A3 B3
Converts complex z to polar form.
Enter
polar(1 + exp(i pi/3))
Result
1/6 1/2
(-1) 3
Returns the nth prime number, n ≤ 10000.
Enter
prime(10000)
Result
104729
Print args in tty mode.
For i equals j through k evaluate y.
Returns the product of all y.
Enter
product(k,1,3,1/(1-(1/prime(k)^s)))
Result
1
----------------------------------
1 1 1
(1 - ----) (1 - ----) (1 - ----)
s s s
2 3 5
The prog function evaluates f.
The result of the evaluation of f is returned as the prog
value.
The variables a,b,... have local scope within prog.
The variables a,b,... remain unmodified after prog returns.
Usually f is a do function.
Returns expression x without evaluating symbols or functions.
Can be used to clear symbolic values.
Enter
n = 3
n
Result
3
Enter
n = quote(n)
n
Result
n
Returns the quotient of polynomial p(x) over q(x).
The last argument can be omitted when the polynomials are in x.
The remainder can be calculated as p - q * quotient(p,q).
Returns the rank (number of indices) of tensor a.
Enter
U = (u1,u2,u3,u4)
rank(U)
Result
1
Puts terms in x over a common denominator.
Enter
rationalize(1/x + 1/y)
Result
x + y
-------
x y
Rationalize can often simplify expressions.
Enter
A = ((a,b),(c,d))
B = inv(A)
dot(A,B)
Result
a d b c
----------- - ----------- 0
a d - b c a d - b c
a d b c
0 ----------- - -----------
a d - b c a d - b c
Enter
rationalize(last)
Result
1 0
0 1
Returns the real part of complex z.
Symbols in expression z are presumed to be positive and real.
Enter
real(1 + exp(i pi/3))
Result
3/2
Returns complex z in rectangular form.
Symbols in expression z are presumed to be positive and real.
Enter
rect(1 + exp(i pi/3))
Result
3/2 + 1/2 i 3^(1/2)
Evaluation of return causes an immediate exit from prog.
Expression x is evaluated and returned as the prog value.
A return with no argument returns the symbol nil.
A return can be evaluated at any function level.
For example, prog() can evaluate f() which evaluates
g() which evaluates return().
Finds the values of x for which the polynomial p(x) = 0.
Returns a vector for multiple roots.
Enter
(x + 1)(x + 2)
Result
2
x + 3 x + 2
Enter
roots
Result
-2
-1
Evaluates expression x and then attempts to simplify the result.
Enter
(A-B)/(B-A)
Result
A B
-------- - --------
-A + B -A + B
Enter
simplify(last)
Result
-1
Enter
A = ((A11,A12),(A21,A22))
det(A) inv(A) - adj(A)
Result
((-A22 + A11 A22^2 / (A11 A22 - A12 A21) - A12 A21 A22 / (A11 A22 - A12 A21),
A12 - A11 A12 A22 / (A11 A22 - A12 A21) + A12^2 A21 / (A11 A22 - A12 A21)),
(A21 - A11 A21 A22 / (A11 A22 - A12 A21) + A12 A21^2 / (A11 A22 - A12 A21),
-A11 - A11 A12 A21 / (A11 A22 - A12 A21) + A11^2 A22 / (A11 A22 - A12 A21)))
Enter
simplify(last)
Result
0
The simplify function can return factored
(unexpanded)
expressions.
Factored expressions can fail in tests for equality.
The eval function can be used to expand factored expressions.
Returns the sine of x.
Returns the hyperbolic sine of x.
Returns the square root of x.
When evaluated in a script, the stop function exits run mode and
returns to interactive mode.
Substitutes a for b in c and returns the result.
Note that this operation can return a denormalized expression.
Use eval to normalize the result of subst.
Enter
f = x^2
subst(sqrt(x),x,f)
Result
2
1/2
(x )
Enter
eval(last)
Result
x
For a equals i through j evaluate b.
Returns the sum of all b.
The variable a has local scope within the sum function,
a remains unchanged after the sum function returns.
The expressions i and j should evaluate to integers.
Enter
sum(k,1,3,1/k^s)
Result
1 1
1 + ---- + ----
s s
2 3
Returns the tangent of x.
Returns the hyperbolic tangent of x.
Returns the Taylor expansion of f at a.
If a is omitted then zero is used.
The argument x is the free variable in f
and n is the power of the expansion.
Enter
taylor(1/cos(x),x,6)
Result
1 2 5 4 61 6
1 + --- x + ---- x + ----- x
2 24 720
If argument a is true then b is returned
else if c is true then d is returned, etc.
If the number of arguments is odd then the last argument is the default case.
Example
f(x) = test(x < 0, g(x), h(x))
Returns the trace of matrix m.
Enter
A = ((a,b),(c,d))
trace(A)
Result
a + d
Note that trace is equivalent to contract.
Enter
trace(A) - contract(A,1,2)
Result
0
Returns the transpose of tensor a across indices i and
j.
If i and j are omitted then indices 1 and 2 are used.
Returns a unit matrix with dimension n.
Enter
unit(4)
Result
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
Returns a zero tensor with dimensions i,j,...
The zero function is useful for creating a tensor and then setting the component values.
Enter
A = zero(2,2)
A[1,2] = a
A
Result
0 a
0 0