Manual I. Function Reference

Some mathematical functions have restrictions on their arguments. Arguments outside the legal range will result an invalid number (INVALID) or an empty list. Note that ALL subsequent computations involving INVALID become INVALID.

We list all the built-in functions here. Each entry starts with the function name and its 'signature'.The signature is an informal (and suggestive) rule that tells us how the function is used. It should be self-evident how to interpret the signature. For example: frac means a fraction, fraclist means a list of fractions enclosed inside '[' and ']', int>0 means positive integer.

Example(s) are included at the end of most entries. Please refer to the <a href='#chap_cuecard'>cuecards</a> for additional examples, which are especially valuable for the understanding of the interpretation of lists in the contexts of polynomials, matrices, etc.

Index:
abs ceil cmp comb eqfd eqfn floor gcd getd getn isint lcd lcm max min m#add m#det m#dimc m#dimr m#inv m#mul m#smul m#sub m#tr m#tsp n#facp n#facr orad orae parf pari perm p#add p#comp p#deg p#div p#eval p#mod p#mul p#pow p#sub q#add q#conj q#div q#mul q#sub ran round sgn s#add s#det s#dim s#inv s#mul s#smul s#sub s#tr s#tsp x#solve

I1.   abs(frac):frac    absolute value
abs(a) = |a| = magnitude of a (without the sign)

See also: index

  • abs(4.7) = 4.7
  • abs(-2.5) = 2.5
  • abs(0) = 0

I2.   ceil(frac):int    ceiling
ceil(a) = the smallest integer ≥ a

See also: round floor     index

  • ceil(7.8) = 8
  • ceil(7.5) = 8
  • ceil(7.2) = 8
  • ceil(7) = 7
  • ceil(0) = 0
  • ceil(-7) = -7
  • ceil(-7.2) = -7
  • ceil(-7.5) = -7
  • ceil(-7.8) = -7

I3.   cmp(frac,frac):-1,0,1    comparison of numerical values
cmp(a,b) = -1, 0 or 1 according to if a<b, a=b, or a>b

See also: index

  • cmp(6,7) = -1
  • cmp(6,6) = 0
  • cmp(6,5) = 1

I4.   comb(int≥0,int≥0):int≥1    number of combinations
comb(n,k) = k-combination of n
Number of combinations of k objects from a set of n objects.

Note: 0 ≤ k ≤ n

See also: perm     index

  • comb(6,3) = 20
  • comb(5,2) = 10
  • comb(7,1) = 7
  • comb(8,8) = 1
  • comb(8,0) = 1
  • comb(8,9) = INVALID

I5.   eqfd(frac,frac):frac    denominator of equivalent fraction with given numerator
eqfd(a,b) = the denominator of the fraction, whose numerator is b, equivalent to a
It is the solution to the equation: a = ?/b.

Note: The intent of eqfn is to perform the opposite of 'reduction to lowest terms'. Hence if the question is posed correctly, then the signature is eqfn(frac,int):int as illustrated by the examples.

See also: eqfn     index

  • eqfd(2:5,40) = 100        because 2/5 = 40/100
  • eqfd(-11:4,33) = -12        because -11/4 = 33/(-12)

I6.   eqfn(frac,frac):frac    numerator of equivalent fraction with given denominator
eqfn(a,b) = the numerator of the fraction, whose denominator is b, equivalent to a. It is the solution to the equation: a = b/?.

Note: The intent of eqfn is to perform the opposite of 'reduction to lowest terms'. Hence if the question is posed correctly, then the signature is eqfn(frac,int):int as illustrated by the examples.

See also: eqfd     index

  • eqfn(2:5,15) = 6
  • eqfn(-25:45,360) = -200

I7.   floor(frac):int    floor
floor(a) = the largest integer ≤ a

See also: round ceil     index

  • floor(7.8) = 7
  • floor(7.5) = 7
  • floor(7.2) = 7
  • floor(7) = 7
  • floor(0) = 0
  • floor(-7) = -7
  • floor(-7.2) = -8
  • floor(-7.5) = -8
  • floor(-7.8) = -8

I8.   gcd(int,...):int    greatest common divisor
gcd(a,b,...) = the greatest common divisor of integers a, b, ...

Note: Signs are ignored, the result is a positive integer.

See also: lcm     index

  • gcd(10,20) = 10
  • gcd(12,20) = 4
  • gcd(17,20) = 1
  • gcd(-4,6) = 2        the answer is positive
  • gcd(100,40,36,60) = 4

I9.   getd(frac):int>0    get denominator
getd(a) = the denominator of a (after a is reduced to the lowest terms)

Note: the result is always a positive integer

See also: getn     index

  • getd(5) = 1
  • getd(7:3) = 3
  • getd(24:6) = 1

I10.   getn(frac):int    get numerator
getn(a) = the numerator of a (after a is reduced to the lowest terms)

See also: getd     index

  • getn(5) = 5
  • getn(7:3) = 7
  • getn(24:6) = 4

I11.   isint(frac):0,1    the quot;booleanquot; function: isInteger
isint(a) = 0 or 1 according to if a is an integer or not

Note: isint is a quot;booleanquot; function if we interpret 0 as false, and 1 as true.

See also: index

  • isint(5) = 1
  • isint(7.8) = 0
  • isint(24:6) = 1        24:6=4 is an integer

I12.   lcd(frac,...):int>0    least common denominator
comd(a,b,...) = the least common denominator of fractions a, b, ...

Note: The result is always a positive integer.

See also: index

  • lcd(2:12,1:18) = 18
  • lcd(3:10,2:15) = 30
  • lcd(3:10,2:15,7:12) = 60
  • lcd(-5:3,1:2,-9:4) = 12
  • lcd(2:15,3:15,4:21) = 105

I13.   lcm(int,...):int    least common multiple
lcm(a,b,...) = the least (positive) common multiple of integers a, b, ...

Note: Signs are ignored, the result is a positive integer.

See also: gcd     index

  • lcm(10,20) = 20
  • lcm(12,20) = 60
  • lcm(17,20) = 340
  • lcm(-4,6) = 12        the answer is positive
  • lcm(100,40,36,60) = 1800

I14.   max(frac,...):frac    maxium
max(a,b,...) = the maxium of a, b, ...

See also: min     index

  • max(10,20) = 20
  • max(2,3,5) = 5
  • max(6,7,3,2,2,7,5) = 7

I15.   min(frac,...):frac    minimum
min(a,b,...) = the minimum of a, b, ...

See also: max     index

  • min(10,20) = 10
  • min(2,3,5) = 2
  • min(6,7,3,2,2,7,5) = 2

I16.   m#add(fraclist,fraclist):fraclist    addition of two matrices

Note: The matrix representation lists contain matrix dimensions.

See also: s#add     index

  • m#add([2,3,3,0,-2,4,0,1],[2,3,4,-2,5,-7,10,3]) = [2,3,7,-2,3,-3,10,4]

I17.   m#det(fraclist):frac    determinant of a matrix

Note: The matrix must be square, its representation list contains the dimensions.

See also: s#det     index

  • m#det([3,3,-2,2,3,-1,1,3,2,0,-1]) = 6

I18.   m#dimc(fraclist):int>0    column-dimension (number of columns) of a matrix

Note: The matrix representation list contains matrix dimensions.

See also: m#dimr s#dim     index

  • m#dimc([2,3,3,0,-2,4,0,1]) = 3

I19.   m#dimr(fraclist):int>0    row-dimension (number of rows) of a matrix

Note: The matrix representation list contains matrix dimensions.

See also: m#dimc s#dim     index

  • m#dimr([2,3,3,0,-2,4,0,1]) = 2

I20.   m#inv(fraclist):frac    inverse of a matrix

Note: The matrix must be square, and its representation list contains matrix dimension. The result is an empty list if the matrix is NOT invertible.

See also: s#inv     index

  • m#inv([3,3,4,3,6,3,2,8,6,5,1]) = [3,3,-38,27,12,45,-32,-14,3,-2,-1]

I21.   m#mul(fraclist,fraclist):fraclist    multiplication of two matrices

Note: The matrix representation lists contain matrix dimensions.

See also: s#mul     index

  • m#mul([3,2,7,1,1,5,0,3],[2,3,4,-6,-2,1,2,-2]) = [3,3,29,-40,-16,9,4,-12,3,6,-6]

I22.   m#smul(frac,fraclist):fraclist    scalar multiplication of matrix

Note: The matrix representation list contains matrix dimensions.

See also: s#smul     index

  • m#smul(3,[2,3,7,1,-4,5,0,3]) = [2,3,21,3,-12,15,0,9]

I23.   m#sub(fraclist,fraclist):fraclist    subtraction of two matrices

Note: The matrix representation lists contain matrix dimensions.

See also: s#sub     index

  • m#sub([2,3,13,20,5,4,-2,8],[2,3,-4,6,5,1,5,3]) = [2,3,17,14,0,3,-7,5]

I24.   m#tr(fraclist):frac    trace of a matrix

Note: The matrix must be square, its representation list contains the dimensions.

See also: s#tr     index

  • m#tr([3,3,-5,2,3,-1,1,3,2,0,-1]) = -5

I25.   m#tsp(fraclist):frac    transpose of a matrix

Note: The matrix representation list contains matrix dimensions.

See also: s#tsp     index

  • m#tsp([2,3,1,2,3,4,5,6]) = [3,2,1,4,2,5,3,6]

I26.   n#facp(int>1):fraclist    prime factorization of an integer
n#facp(n) returns a list of n's unique prime factors and their respective powers\

See also: n#facr     index

  • n#facp(60) = [2,2,3,1,5,1]        60 = 2*2*3*5 = 2^2 * 3^1 * 5^1
  • n#facp(77) = [7,1,11,1]        77 = 7 * 11 = 7^1 * 11^1
  • n#facp(81000) = [2,3,3,4,5,3]        81000 = 2^3 * 3^4 * 5^3
  • n#facp(123456789) = [3,2,3607,1,3803,1]        123456789 = 3*3 * 3607 * 3803 = 3^2 * 3607^1 * 3803^1

I27.   n#facr(int>1):fraclist    prime factorization of an integer
n#facr(n) returns a list of n's prime factors, repeated as many times as necessary

See also: n#facp     index

  • n#facr(60) = [2,2,3,5]        60 = 2*2*3*5
  • n#facr(77) = [7,11]        77 = 7*11
  • n#facr(81000) = [2,2,2,3,3,3,3,5,5,5]        81000 = 2*2*2 * 3*3*3*3 * 5*5*5
  • n#facr(123456789) = [3,3,3607,3803]        123456789 = 3*3 * 3607 * 3803

I28.   orad(frac,int>0):frac    optimal rational approximation constrainted by denominator
orad(a,b) = optimal approximation of fraction a subject to the constraint that the denominator does not exceed b. The fraction b must be a positive integer.

See also: orae     index

  • orad(3.1416,10) = 22/7
  • orad(3.14159265,100) = 22/7
  • orad(3.14159265,10000) = 355/113        for denominator<10000, 355/113 is the best approx to pi.
  • orad(3.14159_26535_89793_23846,1@10) = 21053343141/6701487259

I29.   orae(frac,frac≥0):frac    optimal rational approximation constrainted by error
orae(a,b) = optimal approximation of fraction a subject to the constraint that the error does not not exceed b. The fraction b must be zero or positive.

See also: orad     index

  • orae(3.1416,1) = 3
  • orae(3.1416,0.4) = 3
  • orae(3.1416,0.1) = 22/7
  • orae(3.1416,0.05) = 22/7
  • orae(3.14159265,1@-2) = 22/7
  • orae(3.14159265,1@-4) = 333/106
  • orae(3.14159265,1@-5) = 355/113
  • orae(3.14159_26535_89793_23846,1@-10) = 312689/99532
  • orae(3.14159_26535_89793_23846,1@-20) = 21053343141/6701487259

I30.   parf(frac):0≤frac<1    fractional part
parf(a) = the fractional part of a

Note: The result is always between 0 (inclusive) and 1 (exclusive).

See also: parti     index

  • parf(7.8) = 0.8
  • parf(7.5) = 0.5
  • parf(7.2) = 0.2
  • parf(7) = 0
  • parf(0) = 0
  • parf(-7) = 0
  • parf(-7.2) = 0.8        Note: the result is NOT -0.2 nor 0.2
  • parf(-7.5) = 0.5        Note: the result is NOT -0.5
  • parf(-7.8) = 0.2        Note: the result is NOT -0.8 nor 0.8

I31.   pari(frac):int    integer part
parti(a) = the integral part of a

Note: It is actually truncation away from zero.

See also: parf     index

  • pari(7.8) = 7
  • pari(7.5) = 7
  • pari(7.2) = 7
  • pari(7) = 7
  • pari(0) = 0
  • pari(-7) = -7
  • pari(-7.2) = -8        Note: the result is NOT -7
  • pari(-7.5) = -8        Note: the result is NOT -7
  • pari(-7.8) = -8        Note: the result is NOT -7

I32.   perm(int≥0,int≥0):int≥1    number of permutations
perm(n,k) = k-permutation of n
Number of permutations of k objects from a set of n objects.

Note: 0 ≤ k ≤ n

See also: comb     index

  • perm(6,3) = 120
  • perm(5,2) = 20
  • perm(7,1) = 7
  • perm(8,8) = 40320
  • perm(8,0) = 1
  • perm(8,9) = INVALID

I33.   p#add(fraclist,fraclist):fraclist    addition of two polynomials

See also: index

  • p#add([1,2,3],[1,-2,0,8]) = [2,0,3,8]

I34.   p#comp(fraclist,fraclist):fraclist    composition of two polynomials
When polynomials are regarded as functions of x, p#(f,g) is the polynomial defined by (fog)(x) = f(g(x)).

See also: index

  • p#comp([1,2,3],[1,-2,0,8]) = [6,-16,12,64,-96,0,192]

I35.   p#deg(fraclist):int≥0    degree of a polynomial

See also: index

  • p#deg([3,-5,0,8,7]) = 4

I36.   p#div(fraclist,fraclist):fraclist    quotient of long division of two polynomials

See also: index

  • p#div([1,2,0,3,4],[2,1,1]) = [-7,-1,4]

I37.   p#eval(fraclist,frac):frac    evaluation of polynomial

See also: index

  • p#eval([1/4,3,5,0],2) = 105/4

I38.   p#mod(fraclist,fraclist):fraclist    remainder of long division of two polynomials

See also: index

  • p#mod([1,2,0,3,4],[2,1,1]) = [15,11]

I39.   p#mul(fraclist,fraclist):fraclist    multiplication of two polynomials

See also: index

  • p#mul([3,4,0,-5],[1,-2,8]) = [3,-2,16,27,10,-40]

I40.   p#pow(fraclist,int≥0):fraclist    power of a polynomial

Note: The exponent must be a non-negative integer: 0, 1, 2, 3, ...

See also: index

  • p#pow([1,1],5) = [1,5,10,10,5,1]
  • p#pow([1,2,3],3) = [1,6,21,44,63,54,27]

I41.   p#sub(fraclist,fraclist):fraclist    subtraction of two polynomials

See also: index

  • p#sub([8,5,7],[3,-2,0,2]) = [5,7,7,-2]

I42.   q#add(fraclist,fraclist):fraclist    addition of two quadratic surd expressions

See also: index

  • q#add([1,2,3],[1,-2,1/3,8,5]) = [2,4/3,3,8,5]

I43.   q#conj(fraclist):fraclist    conjugation of a quadratic surd expression

See also: index

  • q#conj([1,2,3,7,5]) = [1,-2,3,-7,5]

I44.   q#div(fraclist,fraclist):fraclist    quotient of two quadratic surd expressions

See also: index

  • q#div([1,2/5,2,3,3],[2,1,3]) = [-7,4/5,2,5,3,-2/5,6]

I45.   q#mul(fraclist,fraclist):fraclist    multiplication of two quadratic surd expressions

See also: index

  • q#mul([3,5/4,2,-2,12],[1,-2,8]) = [-7,-43/4,2,-4,3,16,6]

I46.   q#sub(fraclist,fraclist):fraclist    subtraction of two quadratic surd expressions

See also: index

  • q#sub([8,5,20],[0,-3,4/75]) = [8,2/5,3,10,5]

I47.    ran(int):int     ran(frac,frac):frac    random number
  • ran(n) = a random integer in the range: 0, 1, ..., n-1; where n is a positive integer
  • ran(f,g) = a random fraction between f and g inclusive. The granularity of the random numbers depend on the least common denominators of the arguments. Specifically, if the least common denominator is c, and the arguments are a/c and b/c respectively, then the random number is d/c where d is an integer between a and b inclusive.

Note: The result is random, it changes from run to run.

See also: index

  • ran(3)        returns one of the following values: 0, 1, 2
  • ran(2:7,3:4)        returns one of the following valaues: 8:28, 9:28, ..., 20:28, 21:28.

I47.   ran(int):int    ran(frac,frac):frac random number
ran(n) = a random integer in the range: 0, 1, ..., n-1; where n is a positive integer
ran(f,g) = a random fraction between f and g inclusive. The granularity of the random numbers depend on the least common denominators of the arguments. Specifically, if the least common denominator is c, and the arguments are a/c and b/c respectively, then the random number is d/c where d is an integer between a and b inclusive.

Note: The result is random, it changes from run to run.
The result is random, it changes from run to run.

See also: index

  • ran(3) = 0        returns one of the following values: 0, 1, 2
  • ran(2:7,3:4) = 17/28        returns one of the following valaues: 8:28, 9:28, ..., 20:28, 21:28.

I48.   round(frac):int    round
round(a) = the integer closest to a; or the integer further from zero if there is a tie

Note: round(-a) = -round(a)

See also: ceil floor     index

  • round(7.8) = 8
  • round(7.5) = 8        7.5 is half way between 7 and 8; choose 8 to break the tie
  • round(7.2) = 7
  • round(0) = 0
  • round(-7.2) = -7
  • round(-7.5) = -8        -7.5 is half way between -7 and -8; choose -8 to break the tie
  • round(-7.8) = -8

I49.   sgn(frac):-1,0,1    sign
sgn(a) = -1, 0, or 1 according to if a is negative, zero, or positive.

Note: The sign of INVALID is INVALID.

See also: index

  • sgn(5.1) = 1
  • sgn(-3.2) = -1
  • sgn(0) = 0

I50.   s#add(fraclist,fraclist):fraclist    addition of two square matrices

Note: The matrix representation lists do NOT contain matrix dimensions.

See also: m#add     index

  • s#add([8,9,3,0],[4,-2,5,-7]) = [12,7,8,-7]

I51.   s#det(fraclist):frac    determinant of a square matrix

Note: The matrix representation list does NOT contain matrix dimension.

See also: m#det     index

  • s#det([1,2,3,5,6,7,8,9,4]) = 24

I52.   s#dim(fraclist):int>0    dimension (number of rows and columns) of a square matrix

Note: The matrix representation list does NOT contain matrix dimension.

See also: m#dimr m#dimc     index

  • s#dim([5,8,-3,3,0,-2,4,0,1]) = 3

I53.   s#inv(fraclist):frac    inverse of a square matrix

Note: The matrix representation list does NOT contain matrix dimension. The result is an empty list if the matrix is NOT invertible.

See also: m#inv     index

  • s#inv([4,3,6,3,2,8,6,5,1]) = [-38,27,12,45,-32,-14,3,-2,-1]

I54.   s#mul(fraclist,fraclist):fraclist    multiplication of two square matrices

Note: The matrix representation lists do NOT contain matrix dimensions.

See also: m#mul     index

  • s#mul([1,2,3,4],[5,6,7,8]) = [19,22,43,50]

I55.   s#smul(frac,fraclist):fraclist    scalar multiplication of square matrix

Note: The matrix representation list does NOT contain matrix dimension.

See also: m#smul     index

  • s#smul(4,[3,2,0,-1]) = [12,8,0,-4]

I56.   s#sub(fraclist,fraclist):fraclist    subtraction of two matrices

Note: The matrix representation lists do NOT contain matrix dimensions.

See also: m#sub     index

  • s#sub([2,3,7,8],[2,-3,4,6]) = [0,6,3,2]

I57.   s#tr(fraclist):frac    trace of a square matrix

Note: The matrix representation list does NOT contain matrix dimension.

See also: m#tr     index

  • s#tr([-2,2,3,-1,1,3,2,0,-1]) = -2

I58.   s#tsp(fraclist):frac    transpose of a square matrix

Note: The matrix representation list does NOT contain matrix dimension.

See also: m#tsp     index

  • s#tsp([1,2,3,4,5,6,7,8,9]) = [1,4,7,2,5,8,3,6,9]

I59.   x#solve(fraclist):fraclist    solving system of linear equations

See also: index

  • x#solve([1:2,3:2,-2,3:4,3,2,5:4,3,5,6,7:2,-2]) = [511/181,-725/362,-212/181]