Mathematics
Module math
Elementary mathematical functions.
- e
- Euler's number:
2.71828...
- pi
- Half length of the unit circle:
3.14159...
- tau
- Length of the unit circle:
2*pi
.
- nan
- Not a number.
- inf
- Infinity.
- floor(x)
- Round down. Returns floating point numbers.
- ceil(x)
- Round up. Returns floating point numbers.
- sqrt(x)
- Square root of
x
.
- exp(x)
- Exponential function.
- log2(x)
- Logarithm to base 2.
- ln(x)
- Logarithm to base e.
- lg(x)
- Logarithm to base 10.
- lg(x,b)
- Logarithm to base
b
.
- sin(x), cos(x), tan(x)
- Sine, cosine and tangent.
- asin(x), acos(x), atan(x)
- Arc sine, arc cosine and arc tangent.
- sinh(x), cosh(x), tanh(x)
- Hyperbolic sine, hyperbolic cosine and hyperbolic tangent.
- asinh(x), acosh(x), atanh(x)
- Inverse functions of the hyperbolic functions.
- fac(x)
- Factorial function. Returns floating point numbers.
- gamma(x)
- Gamma function.
- lgamma(x)
- Return
ln(abs(gamma(x)))
.
- sgngamma(x)
- Return
sgn(gamma(x))
.
- erf(x)
- Error function.
- hypot(x1,...,xn)
- Return
sqrt(x1^2+...+xn^2)
.
- atan2(y,x)
- Return the phase angle of the coordinate vector
[x,y]
.
- expm1(x)
- Return
exp(x)-1
.
- ln1p(x)
- Return
ln(1+x)
.
- isfinite(x)
- Return true if
x
is not infinite and not a NaN.
- isnan(x)
- Return true if
x
is a NaN.
- isinf(x)
- Return true if
x
is infinite.
- frexp(x)
- Take
x==m*2^n
and return [m,n]
.
The type of m
is float, the type of n
is int.
- ldexp(m,n)
- Return
m*2^n
.
Module cmath
Elementary mathematical functions that can take or return complex
numbers.
- re(z)
- Real part of
z
.
- im(z)
- Imaginary part of
z
.
- conj(z)
- Complex conjugate.
- sqrt(z)
- Square root.
- exp(z)
- Exponential function.
- ln(z)
- Natural logarithm.
- sin(z), cos(z), tan(z)
- Sine, cosine and tangent.
- sinh(z), cosh(z), tanh(z)
- Hyperbolic sine, hyperbolic cosine and hyperbolic tangent.
- asinh(z), acosh(z), atanh(z)
- Inverse functions of the hyperbolic functions.
- gamma(z)
- Gamma function.
Module math.rational
- Rat
- Rational numbers data type.
- rat(n,d=1)
- Rational number
n/d
.
- r.n
- Numerator.
- r.d
- Denominator.
Module math.nt
Number theory.
- base(n,b)
- Transform the number
n
into positional notation
by base b
. The result is in little endian
(least significant digit first).
- base(n,b).rev()
- Big endian (least significant digit last) of the
positional notation above.
- isprime(n)
- Deterministic primality test.
- isprime(n,e)
- Probalistic primality test with false positive probability of less than
1/(4^e)
.
- gcd(a,b)
- Greatest common divisor of
a
and b
.
- lcm(a,b)
- Least common multiple of
a
and b
.
- lcm(a)
- Least common multiple of the numbers in the iterable
a
.
- factor(n)
- Prime factorization of
n
.
- divisors(n)
- The list of divisors of
n
.
- phi(n)
- Euler's totient function.
- lambda(n)
- Carmichael function.
Module math.cf
Combinatorical functions.
- fac(n)
- Factorial function.
- rf(n,k)
- Raising factorial.
- ff(n,k)
- Falling factorial.
- bc(n,k)
- Binomial coefficient.
- mc([k1,...,kn])
- Multinomial coefficient.
- stirling1(n,k)
- Stirling number of the first kind.
- stirling2(n,k)
- Stirling number of the second kind.
- euler1(n,k)
- Eulerian number.
- euler2(n,k)
- Eulerian number of the second order.
- bell(n)
- Bell numbers.
- pf(n)
- Partition function.
- pf(n,k)
- Number of partitions of
n
into exactly k
parts.
- permutations(a)
- Permutations of the list
a
.
- combinations(k,s)
- Combinations of set/list/string
s
into
sets of k
elements.
- partitions(n,k)
- Partitions of
n
into k
parts.
Module math.sf
Special functions.
- PP(n,m,x)
- Associated Legendre function
Pn,m(x).
- PH(n,x)
- Hermite polynomial
Hn(x).
- PT(n,x)
- Chebyshev polynomial of the first kind:
Tn(x).
- PU(n,x)
- Chebyshev polynomial of the second kind:
Un(x).
- gamma(s,x)
- Lower incomplete gamma function
γ(s,x).
- Gamma(s,x)
- Upper incomplete gamma function
Γ(s,x).
- zeta(x)
- Zeta function.
- B(n)
- Bernoulli number,
B(1) = +1/2
.
Module math.sf.ei
Elliptic integrals.
- K(m), m=k^2
- Complete elliptic integral of the first kind.
- E(m), m=k^2
- Complete elliptic integral of the second kind.
- F(phi,m), m=k^2
- Incomplete elliptic integral of the first kind.
- E(phi,m), m=k^2
- Incomplete elliptic integral of the second kind.
- Pi(phi,n,m), m=k^2
- Incomplete elliptic integral of the third kind.
- RF(x,y,z)
- Carlson symmetric form
RF(x, y, z).
- RC(x,y)
- Carlson symmetric form
RC(x, y)
= RF(x, y, y).
- RJ(x,y,z,p)
- Carlson symmetric form
RJ(x, y, z, p).
- RD(x,y,z)
- Carlson symmetric form
RD(x, y, z)
= RJ(x, y, z, z).
Module math.la
Linear algebra by polymorphic multidimensional arrays.
- vector(a1,...,an)
- Build a coordinate vector.
- matrix([a11,...,a1n],...,[am1,...,amn])
- Build a matrix.
- matrix(vector(a11,...,am1),...,vector(a1n,...,amn))
- Build a matrix from column vectors.
- array(N,data)
- Return a coordinate tensor of order
N
.
Note that:
array(1,a) = vector(*a),
array(2,a) = matrix(*a).
- diag(a1,...,an)
- Return a diagonal matrix.
- scalar(n,lambda,zero)
- Return a scalar n×n matrix.
- scalar(n,1,0)
- Return the n×n identity matrix.
Type Array, a,b,A,B,v,w: Array
- a.T
- Transposed matrix.
- a.H
- Conjugate transpose.
- a.conj
- Conjugated complex matrix.
- a.tr
- Trace.
- a.diag
- Main diagonal as a coordinate vector.
- a.shape
- Shape of the array.
- a.copy
- Shallow copy of the array.
- a.list
- Convert the array into a list.
- impl abs(a)
- Absolute value of a vector. Frobenius norm of a matrix.
- a+b, a-b, -a, r*a, a/r
- Pointwise operations.
- v*w, v.conj*w
- Scalar product, scalar product of complex vectors.
- v.T*w, v.H*w
- Scalar product of column matrices, scalar product of complex
column matrices.
- A*v, A*B
- Multiplication matrix*vector, multiplication matrix*matrix.
- A^n
- Matrix power.
- a.map(f)
- Applies
f
to every element of a
.
- a[k]
- Component of a vector (
k=0
up to k=n-1
).
Row of a matrix.
- a[i,j]
- Component of a matrix.
Module math.na
Numerical algorithms.
- pli(x0,d,a)
- Return a function that computes a piecewise linear interpolation
of the given equidistant nodes
[x[k],y[k]]=[x0+k*d,a[k]]
for k
in 0..len(a)-1
. Note that
a
may contain vectors or a matrices. Vectors are
interpolated componentwise.
- inv(f,y,a,b)
- Calculate the preimage
x0
by bisection
such that y
≈f(x0)
. The function
f(x)-y
should change its sign on x∈[a,b]
only once at x=x0
.
- diffh({h=0.001,order=false,fast=false})
- Create a numerical derivative operation
diff=diffh()
.
Apply diff(f,a)
to calculate f'(x)
at x=a
. If order
is true,
apply diff(f,a,n)
instead to calculate the nth
derivative. If fast
is true, use a slightly faster
algorithm for the first derivative. Note that f
may also
be a complex function or a vector-valued function.
For a given smooth function, a smaller h
leads to
a better approximation, unless h
is too small.
- diffvh({h=0.001,order=false,fast=false})
- Create a directional derivative operation
diffv=diffvh()
. Apply diffv(v,f,a)
to calculate diff(|t| f(a+t*v),0)
.
- integral(a,b,f,n=1)
- Calculate the definite integral of
f(x)
for x=a
to x=b
. Uses a Gauss-Legendre
quadrature with 32 nodes. To increase accuracy, the interval
[a,b]
can be subdivided into n
parts.
Note that f
may be a complex-valued or vector-valued
function.
Module math.na.quad
Numerical quadrature.
- gauss_legendre(N)
- Return a new integral operation, using the Gauss-Legendre
quadrature with
N
nodes.
integral = gauss_legendre(64)
ln = |x| integral(1,x,|t| 1/t)
# integral(a,b,f,n=1)
- legendre_nodes(N)
- The nodes for the Gauss-Legendre quadrature.
- gauss(nodes)
- Take
nodes
and return a new integral operation by
Gaussian quadrature.
integral = gauss(legendre_nodes(64))