Skip to content
Paul Lipkowski edited this page Apr 8, 2023 · 38 revisions

Math is a package of functions for PapajScript. This package contains advanced mathematical functions. It was released on May 14, 2020.

List of current Math functions

Notes:

  • If you do not want to type Math. every time, just type @use(Math) before. However, if you want to stop using the package, type @unuse(Math).
  • The version 0.5.1.1 is the last version where you can use Math. functions without running @use(Math). Starting from April 16, 2021, all Math functions require to be activated by @use(Math)

Constants

Package Function Syntax Output type Purpose Since
Math.PI (no args) function Number π (pi) number, π ≈ 3.1415926535897 0.4.3
Math.EU (no args) function Number Euler's number, e ≈ 2.7182818284590 0.4.3
Math.FI (no args) function Number Golden ratio, φ ≈ 1.6180339887498 0.4.3
Math.EM (no args) function Number Euler-Mascheroni constant γ ≈ 0.5772156649015 0.4.3

General purpose

Package Function Syntax Output type Purpose Since
Math.choose NUM1 NUM2 function Number Binomial coefficient; N1 = n, N2 = k 0.4.3
Math.gcd NUM1 NUM2 function Number Greatest Common Divisor 0.4.3
Math.lcm NUM1 NUM2 function Number Least Common Multiplier 0.4.3
Math.fibonacci NUM1 function Number Fibonacci number 0.4.3
Math.divides NUM1 NUM2 function Boolean Returns TRUE if NUM1 divides NUM2 (i.e. NUM1 mod NUM2 = 0), and returns FALSE otherwise 0.5.1.1
Math.gamma NUM1 function Number Returns a Gamma function value 0.5.1
Math.gammaln NUM1 function Number Returns a natural logarithm of Gamma function value 0.5.1
Math.erf NUM1 function Number error function 0.5.2
Math.erfc NUM1 function Number complementary error function 0.5.2
Math.randomIntRange NUM1 NUM2 function Number Get a random integer from the range of [a, b] 0.5.2
Math.randomRealRange NUM1 NUM2 function Number Get a random real number from the range of [a, b) 0.5.2

Trigonometric and hyperbolic functions

Package Function Syntax Output type Purpose Since
Math.sin NUM1 function Number sine 0.4.3
Math.cos NUM1 function Number cosine 0.4.3
Math.tan NUM1 function Number tangent 0.4.3
Math.cot NUM1 function Number cotangent 0.4.3
Math.sec NUM1 function Number secant 0.4.3
Math.csc NUM1 function Number cosecant 0.4.3
Math.arcsin NUM1 function Number arcsine 0.5.0
Math.arccos NUM1 function Number arccosine 0.5.0
Math.arctan NUM1 function Number arctangent 0.5.0
Math.arccot NUM1 function Number arccotangent 0.5.0
Math.arcsec NUM1 function Number arcsecant 0.5.2
Math.arccsc NUM1 function Number arccosecant 0.5.2
Math.sinh NUM1 function Number hyperbolic sine 0.5.0
Math.cosh NUM1 function Number hyperbolic cosine 0.5.0
Math.tanh NUM1 function Number hyperbolic tangent 0.5.0
Math.coth NUM1 function Number hyperbolic cotangent 0.5.0
Math.sech NUM1 function Number hyperbolic secant 0.5.0
Math.csch NUM1 function Number hyperbolic cosecant 0.5.0
Math.arsinh NUM1 function Number hyperbolic area sine 0.5.2
Math.arcosh NUM1 function Number hyperbolic area cosine 0.5.2
Math.artanh NUM1 function Number hyperbolic area tangent 0.5.2
Math.arcoth NUM1 function Number hyperbolic area cotangent 0.5.2
Math.arsech NUM1 function Number hyperbolic area secant 0.5.2
Math.arcsch NUM1 function Number hyperbolic area cosecant 0.5.2
Math.toDegrees NUM1 function Number convert radians to degrees 0.5.0
Math.toRadians NUM1 function Number convert degrees to radians 0.5.0

Statistics – general functions

Package Function Syntax Output type Purpose Since
Math.moment ARR1 NUM1 function Number N-th moment of the elements of A1 0.5.2
Math.quantile ARR1 NUM1 function Number a (1/N)-quantile of A1 (i.e. if N1 = 0.25 = 1/4, then the first 4-quantile, and if N1 = 0.5 = 2/4 then the second 4-quantile etc.) 0.5.2
Math.tertile ARR1 NUM1 function Number the N1-th tertile (3-quantile) 0.5.2
Math.quartile ARR1 NUM1 function Number the N1-th quartile (4-quantile) 0.5.2
Math.octile ARR1 NUM1 function Number the N1-th octile (8-quantile) 0.5.2
Math.decile ARR1 NUM1 function Number the N1-th decile (10-quantile) 0.5.2
Math.hexadecile ARR1 NUM1 function Number the N1-th hexadecile (16-quantile) 0.5.2
Math.percentile ARR1 NUM1 function Number the N1-th percentile (100-quantile) 0.5.2
Math.skewness ARR1 function Number skewness coefficient of A1 0.5.3
Math.kurtosis ARR1 function Number kurtosis coefficient of A1 0.5.3
Math.kurtosis3 ARR1 function Number excess kurtosis coefficient of A1 (kurtosis - 3) 0.5.3
Math.excessKurtosis ARR1 function Number same as Math.kurtosis3 0.5.3

Statistics – distribution functions

Package Function Syntax Output type Purpose Since
Math.distNormStd NUM1 function Number Returns a CDF (i.e. P(X ≤ NUM1)) of standard normal distribution (μ = 0, σ = 1) 0.4.3
Math.funcNormStd NUM1 function Number Returns a PDF (i.e. f(NUM1)) of standard normal distribution (μ = 0, σ = 1) 0.5.0
Math.randomNormStd (no args) function Number Generate a random number using standard normal distribution (μ = 0, σ = 1) 0.5.0
Math.genNormStd NUM1 function set of Number Generate N1 random numbers using standard normal distribution (μ = 0, σ = 1) 0.5.0
Math.distNorm NUM1 NUM2 NUM3 function Number Returns a CDF (i.e. P(X ≤ NUM1)) of normal distribution (μ = NUM2, σ = NUM3) 0.4.3
Math.funcNorm NUM1 NUM2 NUM3 function Number Returns a PDF (i.e. f(NUM1)) of normal distribution (μ = NUM2, σ = NUM3) 0.5.0
Math.randomNorm NUM1 NUM2 function Number Generate a random number using normal distribution (μ = NUM1, σ = NUM2) 0.5.0
Math.genNorm NUM1 NUM2 NUM3 function set of Number Generate N1 random numbers using normal distribution (μ = NUM2, σ = NUM3) 0.5.0
Math.distBinom NUM1 NUM2 NUM3 function Number Returns a CDF (i.e. P(X ≤ NUM1)) of binomial distribution (n = NUM2, p = NUM3) 0.5.0
Math.funcBinom NUM1 NUM2 NUM3 function Number Returns a PMF (i.e. P(X = NUM1)) of binomial distribution (n = NUM2, p = NUM3) 0.5.0
Math.randomBinom NUM1 NUM2 function Number Generate a random number using binomial distribution (n = NUM1, p = NUM2) 0.5.0
Math.genBinom NUM1 NUM2 NUM3 function set of Number Generate N1 random numbers using binomial distribution (n = NUM2, p = NUM3) 0.5.0
Math.distGeom NUM1 NUM2 function Number Returns a CDF (i.e. P(X ≤ NUM1)) of geometrical distribution (p = NUM2) 0.5.0
Math.funcGeom NUM1 NUM2 function Number Returns a PMF (i.e. P(X = NUM1)) of geometrical distribution (p = NUM2) 0.5.0
Math.randomGeom NUM1 function Number Generate a random number using geometrical distribution (p = NUM1) 0.5.0
Math.genGeom NUM1 NUM2 function set of Number Generate N1 random numbers using geometrical distribution (p = NUM2) 0.5.0
Math.distExp NUM1 NUM2 function Number Returns a CDF (i.e. P(X ≤ NUM1)) of exponential distribution (λ = NUM2) 0.5.0
Math.funcExp NUM1 NUM2 function Number Returns a PDF (i.e. f(NUM1)) of exponential distribution (λ = NUM2) 0.5.0
Math.randomExp NUM1 function Number Generate a random number using exponential distribution (λ = NUM1) 0.5.0
Math.genExp NUM1 NUM2 function set of Number Generate N1 random numbers using exponential distribution (λ = NUM2) 0.5.0
Math.distPoisson NUM1 NUM2 function Number Returns a CDF (i.e. P(X ≤ NUM1)) of Poisson distribution (λ = NUM2) 0.5.0
Math.funcPoisson NUM1 NUM2 function Number Returns a PMF (i.e. P(X = NUM1)) of Poisson distribution (λ = NUM2) 0.5.0
Math.randomPoisson NUM1 function Number Generate a random number using Poisson distribution (λ = NUM1) 0.5.0
Math.genPoisson NUM1 NUM2 function set of Number Generate N1 random numbers using Poisson distribution (λ = NUM2) 0.5.0
Math.distGamma NUM1 NUM2 NUM3 function Number Returns a CDF (i.e. P(X ≤ NUM1)) of the shape-rate gamma distribution (α = k = NUM2, β = 1/θ = NUM3) 0.5.1
Math.funcGamma NUM1 NUM2 NUM3 function Number Returns a PDF (i.e. f(NUM1)) of the shape-rate gamma distribution (α = k = NUM2, β = 1/θ = NUM3) 0.5.1
Math.randomGamma NUM1 NUM2 function Number Generate a random number using the shape-rate gamma distribution (α = k = NUM1, β = 1/θ = NUM2) 0.5.1
Math.genGamma NUM1 NUM2 NUM3 function set of Number Generate N1 random numbers using the shape-rate gamma distribution (α = k = NUM2, β = 1/θ = NUM3) 0.5.1
Math.distChiSq NUM1 NUM2 function Number Returns a CDF (i.e. P(X ≤ NUM1)) of chi-squared distribution (ν = NUM2) 0.5.1
Math.funcChiSq NUM1 NUM2 function Number Returns a PDF (i.e. f(NUM1)) of chi-squared distribution (ν = NUM2) 0.5.1
Math.randomChiSq NUM1 function Number Generate a random number using chi-squared distribution (ν = NUM1) 0.5.1
Math.genChiSq NUM1 NUM2 function set of Number Generate N1 random numbers using chi-squared distribution (ν = NUM2) 0.5.1
Math.distErlang NUM1 NUM2 NUM3 function Number Returns a CDF (i.e. P(X ≤ NUM1)) of the shape-rate Erlang distribution (α = k = NUM2, β = λ = NUM3) 0.5.1
Math.funcErlang NUM1 NUM2 NUM3 function Number Returns a PDF (i.e. f(NUM1)) of the shape-rate Erlang distribution (α = k = NUM2, β = λ = NUM3) 0.5.1
Math.randomErlang NUM1 NUM2 function Number Generate a random number using the shape-rate Erlang distribution (α = k = NUM1, β = λ = NUM2) 0.5.1
Math.genErlang NUM1 NUM2 NUM3 function set of Number Generate N1 random numbers using the shape-rate Erlang distribution (α = k = NUM2, β = λ = NUM3) 0.5.1
Math.distT NUM1 NUM2 function Number Returns a CDF (i.e. P(X ≤ NUM1)) of Student's t-distribution (ν = NUM2) 0.5.1
Math.funcT NUM1 NUM2 function Number Returns a PDF (i.e. f(NUM1)) of Student's t-distribution (ν = NUM2) 0.5.1
Math.randomT NUM1 function Number Generate a random number using Student's t-distribution (ν = NUM1) 0.5.1
Math.genT NUM1 NUM2 function set of Number Generate N1 random numbers using Student's t-distribution (ν = NUM2) 0.5.1
Math.distBeta NUM1 NUM2 NUM3 function Number Returns a CDF (i.e. P(X ≤ NUM1)) of the beta distribution (α = NUM2, β = NUM3) 0.5.2
Math.funcBeta NUM1 NUM2 NUM3 function Number Returns a PDF (i.e. f(NUM1)) of the beta distribution (α = NUM2, β = NUM3) 0.5.2
Math.randomBeta NUM1 NUM2 function Number Generate a random number using the beta distribution (α = NUM1, β = NUM2) 0.5.2
Math.genBeta NUM1 NUM2 NUM3 function set of Number Generate N1 random numbers using the beta distribution (α = NUM2, β = NUM3) 0.5.2
Math.distF NUM1 NUM2 NUM3 function Number Returns a CDF (i.e. P(X ≤ NUM1)) of Fisher-Snedecor (F) distribution (d1 = NUM2, d2 = NUM3) 0.5.2
Math.funcF NUM1 NUM2 NUM3 function Number Returns a PDF (i.e. f(NUM1)) of Fisher-Snedecor (F) distribution (d1 = NUM2, d2 = NUM3) 0.5.2
Math.randomF NUM1 NUM2 function Number Generate a random number using Fisher-Snedecor (F) distribution (d1 = NUM1, d2 = NUM2) 0.5.2
Math.genF NUM1 NUM2 NUM3 function set of Number Generate N1 random numbers using Fisher-Snedecor (F) distribution (d1 = NUM2, d2 = NUM3) 0.5.2
Math.distArcsine NUM1 function Number Returns a CDF (i.e. P(X ≤ NUM1)) of the arcsine distribution 0.5.3
Math.funcArcsine NUM1 function Number Returns a PDF (i.e. f(NUM1)) of the arcsine distribution 0.5.3
Math.randomArcsine (no args) function Number Generate a random number using the arcsine distribution 0.5.3
Math.genArcsine NUM1 function set of Number Generate N1 random numbers using the arcsine distribution 0.5.3

Number theory

Package Function Syntax Output type Purpose Since
Math.genDivisors NUM1 function set of Number Generate all divisors of NUM1 (including negative ones) 0.5.1.1
Math.genNaturalDivisors NUM1 function set of Number Generate all positive divisors of NUM1 0.5.1.1
Math.countNaturalDivisors NUM1 function Number Return the count of N1's natural divisors 0.5.1.2
Math.sumNaturalDivisors NUM1 function Number Return the sum of N1's natural divisors 0.5.1.2
Math.factorize NUM1 function set(2) of Number Divides N1 to 2 factors, one of which is prime 0.5.2
Math.primeDistribution NUM1 function set of Number Divides N1 to all prime factors 0.5.2
Math.leastPrimeDivisor NUM1 function Number Get the least prime divisor of N1 0.5.2
Math.euclidean NUM1 NUM2 function Number Get the Bezout coefficients of N1 and N2 using extended Euclidean algorithm 0.5.2
Math.bezoutCoefs NUM1 NUM2 function Number Same as Math.euclidean 0.5.2
Math.coprimes NUM1 NUM2 function Boolean Checks if N1 and N2 are coprimes 0.5.2.2
Math.countDistinctFactors NUM1 function Number Count all distinct prime factors of N1 0.5.2
Math.countAllFactors NUM1 function Number Count all prime factors of N1 0.5.2
Math.fEuler NUM1 function Number Return the value of Euler's totient function for NUM1 number 0.5.1.2
Math.fLiouville NUM1 function Number Liouville function 0.5.2
Math.fLambda NUM1 function Number Same as Math.fLiouville 0.5.2
Math.fMobius NUM1 function Number Return the value of Möbius function for NUM1 number 0.5.1.2
Math.fMu NUM1 function Number Alias for Math.fMobius 0.5.1.2
Math.fomega NUM1 function Number Same as Math.countDistinctFactors 0.5.2
Math.fOmega NUM1 function Number Same as Math.countAllFactors 0.5.2
Math.fPhi NUM1 function Number Alias for Math.fEuler 0.5.1.2
Math.fPi NUM1 function Number Return the value of pi function for NUM1 number 0.5.1.2
Math.fSigma NUM1 function Number Alias for Math.sumNaturalDivisors 0.5.1.2
Math.fTau NUM1 function Number Alias for Math.countNaturalDivisors 0.5.1.2
Math.isSquareFree NUM1 function Boolean Determine if a number is square-free 0.5.2
Math.isCarmichael NUM1 function Boolean Checks if N1 is a Carmichael number 0.5.2.2
Math.modularPower NUM1 NUM2 NUM3 function Boolean Raise N1 to the power of N2 modulo N3 (all numbers are integers) 0.5.2.2
Math.modPower NUM1 NUM2 NUM3 function Boolean Alias for Math.modularPower 0.5.2.2
Math.modPow NUM1 NUM2 NUM3 function Boolean Alias for Math.modularPower 0.5.2.2
Math.modularInverse NUM1 NUM2 function Boolean Find the smallest multiplicative inverse of N1 modulo N2 0.5.2.2
Math.modularMulInverse NUM1 NUM2 function Boolean Alias for Math.modularInverse 0.5.2.2
Math.modMulInv NUM1 NUM2 function Boolean Alias for Math.modularInverse 0.5.2.2

List of obsolete Math functions

Package Function Syntax Output type Purpose Since Latest version
Math.Gamma NUM1 function Number Returns a Gamma function value 0.4.3 0.5.0
Math.arcsinh NUM1 function Number hyperbolic area sine 0.5.0 0.5.1.2
Math.arccosh NUM1 function Number hyperbolic area cosine 0.5.0 0.5.1.2
Math.arctanh NUM1 function Number hyperbolic area tangent 0.5.0 0.5.1.2
Math.arccoth NUM1 function Number hyperbolic area cotangent 0.5.0 0.5.1.2
Math.sqr NUM1 function Number Raise a number to the power of 2 0.5.1 0.5.2.2
Math.cub NUM1 function Number Raise a number to the power of 3 0.5.1.2 0.5.2.2
Math.inv NUM1 function Number Return 1/x 0.5.1.2 0.5.2.2
Math.cbrt NUM1 function Number cubic root 0.5.1 0.5.2.2
Math.log NUM1 NUM2 function Number Logarithm of N1 to base N2 0.4.3 0.5.2.2
Math.lbin NUM1 function Number Binary logarithm of N1 0.4.3 0.5.2.2
Math.log2 NUM1 function Number Binary logarithm of N1 0.5.1 0.5.2.2
Math.ldec NUM1 function Number Decimal logarithm of N1 (to base 10) 0.5.1 0.5.2.2
Math.log10 NUM1 function Number Decimal logarithm of N1 (to base 10) 0.5.1 0.5.2.2
Math.lhex NUM1 function Number Hexadecimal logarithm of N1 (to base 16) 0.5.1 0.5.2.2
Math.log16 NUM1 function Number Hexadecimal logarithm of N1 (to base 16) 0.5.1 0.5.2.2
Math.abs NUM1 function Number Absolute value 0.4.3 0.5.2.2
Math.factorial NUM1 function Number Factorial 0.4.3 0.5.2.2
Math.sign NUM1 function Number Sign function (-1 if N1 is negative, 1 if N is positive, 0 if N1 = 0) 0.5.2 0.5.2.2
Math.sgn NUM1 function Number Alias for Math.sign 0.5.2 0.5.2.2
Math.round NUM1 function Number round 0.4.3 0.5.2.2
Math.floor NUM1 function Number floor 0.4.3 0.5.2.2
Math.ceiling NUM1 function Number ceiling 0.4.3 0.5.2.2
Math.isPrime NUM1 function Boolean returns TRUE if a number is a prime, otherwise it returns FALSE 0.4.3 0.5.2.2
Math.isEven NUM1 function Boolean checks if a number is even 0.4.3 0.5.2.2
Math.isOdd NUM1 function Boolean checks if a number is odd 0.4.3 0.5.2.2
Math.isInteger NUM1 function Boolean checks if a number is integer 0.4.3 0.5.2.2
Math.isNatural NUM1 function Boolean checks if a number is natural (non-negative integer) 0.5.1 0.5.2.2
Math.! NUM1 function Number Factorial 0.4.3 0.5.2.2
Math.ln NUM1 function Number natural logarithm 0.4.3 0.5.2.2
Math.exp NUM1 function Number Euler's number raised to the power of N1 0.4.3 0.5.2.2
Clone this wiki locally