# NumCalc Reference

## Javascript support

Numcalc relies on a superset of Javascript. The main difference with Javascript are:
• Integer and Float are different types. Float constants contain a decimal point or exponent. Integers are bignums by default and Floats have an arbitrary precision.
• Standard operators can be overloaded.
• A new math mode is available where the ^ operator is interpreted as the power operator **. The xor operator is available as ^^.
The exact differences are listed in the paper jsbignum.pdf.

## Global definitions

### Arithmetic

 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) I Square root of -1 a+b Add two numbers, polynomials or matrixes a-b Substract two numbers, polynomials or matrixes a*b Multiply two numbers, polynomials or matrixes a/b Divide two numbers, polynomials or matrixes a%b Euclidian remainder of a divided by b, i.e. always positive a^b or a**b a 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&b Bitwise and between the integers a and b a|b Bitwise or between the integers a and b a^^b Bitwise exclusive or between the integers a and b ~n Bitwise not of the integer n a<>n Shift right by n bits. Equivalent to floor(a/2^n)

### Transcendental

 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) PI Pi 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). X Same 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

### Integer

 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 sqrt(a) floor(sqrt(a)) sqrtrem(a) if r=floor(sqrt(a), return [r, a-r^2] floorLog2(a) floor(log2(a)) ctz(a) Return e such as a=m 2^e with m an odd integer (count trailing zeros). Return 0 if a = 0.

### Float

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

### Fraction instances

 num Numerator (integer) den Denominator (integer)

### Complex instances

 re Real part im Imaginary part

### Mod instances

 res Residue modulo mod (integer) mod Modulo (integer)

### RationalFunction instances

 num Numerator (polynomial) den Denominator (polynomial)

### PolyMod instances

 res Residue modulo mod (polynomial) mod Modulo (polynomial)