NumCalc Reference

Javascript support

Numcalc relies on a superset of Javascript. The main difference with Javascript are: The exact differences are listed in the paper jsbignum.pdf.

Global definitions


norm2(x)Norm of x. For a real number, return x^2. For a complex number, return re(x)^2+im(x)^2
abs(x)Absolute value of x. For a complex number, return sqrt(re(x)^2+im(x)^2)
trunc(x)Largest integer in absolute value <= x. If x is a rational fonction, return its integer part.
floor(x)Largest integer <= x
ceil(x)Smallest integer >= x
fact(n)Factorial of n
comb(n, p)Binomial coefficient (n, p)
bestappr(x,b)Fractional approximation of x using a denominator <= b
sqrt(x)Square root of x
conj(x)Complex conjugate of x
arg(x)Argument of x
gcd(a,b)Greatest Common Divisor of a and b (integers or polynomials)
isprime(n[,t])Return true if n is prime, 0 if not. A probabilistic Miller Rabin test is done. If true is returned, the probability that n is not prime is 1-0.5^t. By default, t = 30
nextprime(n)Next pseudo prime following n. It is called a pseudo prime because a probabilistic primality test is done.
factor(n)Factorization of n. Return a vector containing the prime factors of n sorted in increasing order
invmod(x,m)Inverse of x modulo m (integer or polynomial)
pmod(a,b,m)a^b modulo m (integer or polynomial)
ISquare root of -1
a+bAdd two numbers, polynomials or matrixes
a-bSubstract two numbers, polynomials or matrixes
a*bMultiply two numbers, polynomials or matrixes
a/bDivide two numbers, polynomials or matrixes
a%bEuclidian remainder of a divided by b, i.e. always positive
a^b or a**ba raised to the power of y
Integer(x)Convert x to integer
Float(x)Convert x to floating point
Fraction(a,b)Return the fraction a/b
Mod(a,m)Represents a modulo m

Bit Manipulation

a&bBitwise and between the integers a and b
a|bBitwise or between the integers a and b
a^^bBitwise exclusive or between the integers a and b
~nBitwise not of the integer n
a<<nShift left by n bits. Equivalent to floor(a*2^(-n))
a>>nShift right by n bits. Equivalent to floor(a/2^n)


exp(x)Exponential of x
log(x)Natural logarithm of x
log2(x)Logarithm of x in base 2
log10(x)Logarithm of x in base 10
sin(x)Sine of x
cos(x)Cosine of x
tan(x)Tangent of x
asin(x)Inverse sine of x
acos(x)Inverse cosine of x
atan(x)Inverse tangent of x
atan2(y, x)Inverse tangent of y/x (same as arg(x+I*y))
sinc(x)Normalized sinc function, defined as sin(PI*x)/(PI*x)
PIPi constant
todb(x)Convert x to decibels
torad(x)Convert from degrees to radians
todeg(x)Convert from radians to degrees

Linear Algebra, Matrixes

Matrix(h, w)Zero filled matrix of h rows and w columns
[1,2,3]Enter a vector
[[1,2],[3,4]]Enter a matrix
x[n]x[n] is the nth element of vector x (zero based)
x[n][m]x[n][m] is the matrix element at row n and column m (zero based)
dp(x,y)Dot product of vectors x and y
cp(x,y)Cross product of vectors x and y
idn(n)Identity matrix of order n
diag(v)Creates the diagonal matrix whose diagonal entries are the entries of the vector v
trans(a)Transpose of the matrix or vector a
det(a)Determinant of matrix a
trace(a)Trace of matrix a
charpoly(x)characteristic polynomial of the matrix x (=det(x*Id-x))
eigenvals(x)Return a vector containing the eigen values of the matrix x
rank(x)Rank of matrix x (only works with integer matrixes)
ker(x)Basis of the kernel of matrix x (only works with integer matrixes)
Matrix.hilbert(n)Hilbert matrix of order n

Polynomial, Rational functions, Power series

Polynomial(a)Build a polynomial from vector a.
PolyMod(p, q)Represents the polynomial p modulo q (p and q are polynomials)
RationalFunction(p,q)Return the rational function p/q (p and q are polynomials).
XSame as Polynomial([0, 1])
p.deg()Degree of the polynomial or rational function p. Return -Infinity if p is the zero polynomial
p.apply(a)Evaluate the the polynomial, rational fonction or power series p by replacing the variable with a
deriv(p)Derivative of the polynomial, rational fonction or power series p
integ(p)Formal integration of the polynomial or power series p. The constant term is set to zero
polroots(p)Return a vector containing the roots of polynomial p.
Series(p, n)Return a power series by truncating the polynomial p to 'n' terms
O(x)Return a power series of zero term matching the degree of the polynomial or rational fonction x

Object properties


isInteger(a)Return true if a is of the Integer type.
tdiv(a, b)trunc(a/b)
fdiv(a, b)floor(a/b)
cdiv(a, b)ceil(a/b)
ediv(a, b)floor(a/b)*sign(b) (Euclidian division)
tdivrem(a, b)Division and remainder (trunc)
fdivrem(a, b)Division and remainder (floor)
cdivrem(a, b)Division and remainder (ceil)
edivrem(a, b)Euclidian division and remainder
sqrtrem(a)if r=floor(sqrt(a), return [r, a-r^2]
ctz(a)Return e such as a=m 2^e with m an odd integer (count trailing zeros). Return 0 if a = 0.


isFloat(a)Return true if a is a floating point number.

Fraction instances

numNumerator (integer)
denDenominator (integer)

Complex instances

reReal part
imImaginary part

Mod instances

resResidue modulo mod (integer)
modModulo (integer)

RationalFunction instances

numNumerator (polynomial)
denDenominator (polynomial)

PolyMod instances

resResidue modulo mod (polynomial)
modModulo (polynomial)