numbers.basic

numbers.basic.binomial(n, k)

Calculates the binomial coefficient of n,k (n choose k).

Parameters

n : Int

Number of available choices.

k : Int

Number of choices selected.

Returns

num : Int

The number of combinations of choices, n choose k.

Errors

This function does not raise any errors.


numbers.basic.divMod(a, b)

Calculates the divisor (quotient) and modulus (remainder) amongst two integers a,b.

Parameters

a : Int

First integer.

b : Int

Second integer.

Returns

arr : Array

An array whose first element is the divisor (a/b) and second element is the modulus (a%b). Returns false if a or b is not an integer.

Errors

This function does not raise any errors.


numbers.basic.egcd(a, b)

Performs the extended Euclidean algorithm (calculates x,y such that ax + by = gcd(a,b) ).

Parameters

a : Int

First integer.

b : Int

Second integer.

Returns

arr : Array

An array whose first element is gcd(a,b), second element is x, and third element is y such that ax + by = gcd(a,b) is satisfied.

Errors

This function does not raise any errors.


numbers.basic.factorial(n)

Calculates the factorial of a positive integer, n.

Parameters

n : Int

A positive integer.

Returns

num : Int

Factorial of n

Errors

This function does not raise any errors.


numbers.basic.fallingFactorial(n, k)

Calculates the falling factorial of a positive integer n with k steps: n!/(n-k)!

Parameters

n : Int

A positive integer.

k : Int

The number of steps to fall.

Returns

r : Int

Falling factorial of n with k steps. If k > n then 0 is returned.

Errors

This function does not raise any errors.


numbers.basic.gcd(a, b)

Calculates the greatest common divisor (gcd) amongst two integers.

Parameters

a : Int

First integer.

b : Int

Second integer.

Returns

num : Int

The gcd of a,b. If a or b are Infinity or -Infinity, then Infinity is returned. If a or b are not numbers, then NaN is returned.

Errors

An error is thrown if:

  • a or b is not an integer.

numbers.basic.isInt(n)

Determines if a number is an integer.

Parameters

n : Number

A number.

Returns

bool : Boolean

true if n is an integer, false otherwise.

Errors

This function does not raise any errors.


numbers.basic.lcm(a, b)

Calculates the lowest common multiple (lcm) amongst two integers.

Parameters

a : Int

First integer.

b : Int

Second integer.

Returns

num : Int

The lcm of a,b. If a or b are Infinity or -Infinity, then 0 is returned. If a or b are not numbers, then NaN is returned.

Errors

An error is thrown if:

  • a or b is not an integer.

numbers.basic.max(arr)

Finds the maximum value in an array.

Parameters

arr : Array

An array of numbers.

Returns

num : Int

Maximum value inside arr. -Infinity is returned if arr is empty.

Errors

An error is thrown if:

  • arr is not an array.

numbers.basic.min(arr)

Finds the minimum value in an array.

Parameters

arr : Array

An array of numbers.

Returns

numfct : Int

Minimum value inside arr. Infinity is returned if arr is empty.

Errors

An error is thrown if:

  • arr is not an array.

numbers.basic.modInverse(a, m)

Calculates the modular multiplicative inverse x of an integer a and modulus m, ax = 1 (mod m).

Parameters

a : Int

An integer.

m : Int

Modulus.

Returns

x : Int

An integer such that ax = 1 (mod m).

Errors

An error is thrown if:

  • x cannot be calculated (i.e. no modular multiplicative inverse exists).

numbers.basic.numbersEqual(a, b, epsilon)

Determines if two numbers, a,b, are equal within a given margin of precision, epsilon.

Parameters

a : Number

First number.

b : Number

Second number.

epsilon : Number

Precision.

Returns

bool : Boolean

true if they are equal within the precision, false otherwise

Errors

This function does not raise any errors.


numbers.basic.permutation(n, k)

Calculate the permutation (n choose k)

Parameters

n : Int

Number of total elements

k : Int

Fixed number of elements

Returns

num : Number

Number of ordered variations

Errors

An error is thrown if:

  • n cannot be less than or equal to 0.
  • k cannot be greater than n.

numbers.basic.powerMod(a, b, m)

Calculates the modulus of an exponential number, a^b mod m.

Parameters

a : Int

Base.

b : Int

Exponent.

m : Int

Modulus.

Returns

num : Int

a^b mod m.

Errors

This function does not raise any errors.


numbers.basic.product(arr)

Calculates the product of the elements of an array.

Parameters

arr : Array

An array of numbers.

Returns

num : Number

The product of the elements of arr.

Errors

An error is thrown if:

  • not all elements of arr are numbers
  • arr is not an array

numbers.basic.random(arr, quant, allowDuplicates)

Retrieves a specified quantity, quant of elements from an array, arr at random. If allowDuplicates is true, then the resulting array is allowed to duplicates of numbers.

Parameters

arr : Array

Array of values to pick from.

quant : Int

Number of values to retrieve.

allowDuplicates : Boolean

Allow numbers to be returned more than once.

Returns

randomArr : Array

An array of randomly chosen numbers from arr.

Errors

An error is thrown if:

  • arr is empty
  • quant is greater than the number of elements in arr and allowDuplicates is false

numbers.basic.range(start, stop, step)

Creates a range of numbers from start (inclusive) to stop (exclusive), increasing by step each iteration. All arguments optional.

Parameters

start : Int

Start of range (included). Default value is 0.

stop : Int

End of range (excluded). Default value is the value of start.

step : Int

Increment size. Default value is 1.

Returns

arr : Array

An array of numbers. If no arguments are given, then [0] is returned.

Errors

This function does not raise any errors.


numbers.basic.shuffle(arr)

Shuffles the elements of an array in place.

Parameters

arr : Array

An array.

Returns

shuffledArr : Number

A shuffled version of arr.

Errors

This function does not raise any errors.


numbers.basic.square(n)

Calculates the square of a number.

Parameters

n : Number

A number.

Returns

num : Number

n squared.

Errors

This function does not raise any errors.


numbers.basic.subtraction(arr)

Calculates the differences of elements of an array, using the first element as the starting point.

Parameters

arr : Array

An array of numbers.

Returns

num : Number

The difference of the elements of arr.

Errors

An error is thrown if:

  • not all elements of arr are numbers
  • arr is not an array

numbers.basic.sum(arr)

Calculates the sum of the elements of an array.

Parameters

arr : Array

An array of numbers.

Returns

num : Number

The sum of the elements of arr.

Errors

An error is thrown if:

  • not all elements of arr are numbers
  • arr is not an array