API Reference

Complete reference for all public functions. All functions are accessed via mathfunctionize.functionName() after importing with from mathfunctionize import mathfunctionize.

Constants

const pi

The ratio of a circle's circumference to its diameter, approximately 3.14159. Value: 3.141592653589793

const e

Euler's number, the base of the natural logarithm, approximately 2.71828. Value: 2.718281828459045

Arithmetic

Basic arithmetic operations. All functions take a list of numbers and apply the operation across all elements.

function addition(arr)

Takes a list of numbers and returns the sum of all elements.

ParameterTypeDescription
arrlist[int | float]List of numbers to sum.

Returns: int | float

mathfunctionize.addition([1, 2, 3])   # 6
function subtraction(arr)

Takes a list of numbers and subtracts each subsequent element from the first.

ParameterTypeDescription
arrlist[int | float]List of numbers. The first element is subtracted from by all subsequent elements.

Returns: int | float

mathfunctionize.subtraction([10, 3, 2])   # 5
function multiplication(arr)

Takes a list of numbers and returns the product of all elements.

ParameterTypeDescription
arrlist[int | float]List of numbers to multiply.

Returns: int | float

mathfunctionize.multiplication([2, 3, 4])   # 24
function division(arr)

Takes a list of numbers and divides the first element by each subsequent element.

ParameterTypeDescription
arrlist[int | float]List of numbers. The first element is divided by all subsequent elements.

Returns: float

mathfunctionize.division([100, 5, 2])   # 10.0
function power(arr)

Takes a list of numbers and exponentiates left-to-right.

ParameterTypeDescription
arrlist[int | float]List of numbers to exponentiate sequentially.

Returns: int | float

mathfunctionize.power([2, 3])     # 8
mathfunctionize.power([2, 3, 2])  # 64
function modulo(arr)

Takes a list of numbers and applies the modulo operator left-to-right.

ParameterTypeDescription
arrlist[int | float]List of numbers.

Returns: int | float

mathfunctionize.modulo([10, 3])   # 1
function flatDivision(arr)

Takes a list of numbers and performs floor division left-to-right.

ParameterTypeDescription
arrlist[int | float]List of numbers.

Returns: int

mathfunctionize.flatDivision([10, 3])   # 3

Algebra

Factorial, gamma function, absolute value, roots, and rounding.

function factorial(x)

Returns the factorial of a non-negative integer x, i.e. x! = x * (x-1) * ... * 1.

ParameterTypeDescription
xintNon-negative integer.

Returns: int x!

mathfunctionize.factorial(5)    # 120
mathfunctionize.factorial(0)    # 1
function gamma(x)

Computes the gamma function of x, a generalization of the factorial to real and complex numbers where Γ(n) = (n−1)! for positive integers. Raises an exception for zero and negative integers.

ParameterTypeDescription
xint | floatInput value. Must not be zero or a negative integer.

Returns: int | float

Raises: Exception if x is 0 or a negative integer.

mathfunctionize.gamma(5)      # 24
mathfunctionize.gamma(0.5)    # sqrt(pi) ≈ 1.7724...
function absolute(x)

Returns the absolute value of x.

ParameterTypeDescription
xint | floatInput value.

Returns: int | float |x|

mathfunctionize.absolute(-7)    # 7
mathfunctionize.absolute(3.5)   # 3.5
function squareRoot(x)

Returns the square root of x.

ParameterTypeDescription
xint | floatNon-negative number.

Returns: float

mathfunctionize.squareRoot(144)   # 12.0
function cubeRoot(x)

Returns the cube root of x.

ParameterTypeDescription
xint | floatInput value.

Returns: float

mathfunctionize.cubeRoot(27)   # 3.0
function nthRoot(x, n)

Returns the n-th root of x.

ParameterTypeDescription
xint | floatInput value.
nintRoot degree.

Returns: float x1/n

mathfunctionize.nthRoot(625, 4)   # 5.0
function round(x, place)

Rounds x to the nearest specified place value (e.g. 1, 10, 100).

ParameterTypeDescription
xint | floatNumber to round.
placeintRounding granularity (1, 10, 100, …).

Returns: int | float

mathfunctionize.round(47, 10)    # 50
mathfunctionize.round(123, 100)  # 100

Counting

Combinatorial counting functions.

function combinations(n, r)

Returns the number of ways to choose r items from n items without regard to order, i.e. n! / (r! * (n-r)!).

ParameterTypeDescription
nintTotal items.
rintItems to choose.

Returns: float

mathfunctionize.combinations(10, 3)   # 120.0
function permutations(n, r)

Returns the number of ways to arrange r items from n items where order matters, i.e. n! / (n-r)!

ParameterTypeDescription
nintTotal items.
rintItems to arrange.

Returns: float

mathfunctionize.permutations(5, 3)   # 60.0
function circularPermutations(n)

Returns the number of ways to arrange n items in a circle, i.e. (n−1)!

ParameterTypeDescription
nintNumber of elements.

Returns: int

mathfunctionize.circularPermutations(5)   # 24
function derangements(n)

Returns the number of permutations of n elements where no element appears in its original position.

ParameterTypeDescription
nintNumber of elements.

Returns: int

mathfunctionize.derangements(4)   # 9
mathfunctionize.derangements(5)   # 44

Probability

Probability distributions and Bayes' theorem.

function bayes_theorem(priorA, priorB, likelihoodA, likelihoodB)

Computes the posterior probability using Bayes' theorem given prior probabilities and likelihoods for two hypotheses.

ParameterTypeDescription
priorAfloatPrior probability of A.
priorBfloatPrior probability of B.
likelihoodAfloatLikelihood of evidence given A.
likelihoodBfloatLikelihood of evidence given B.

Returns: float

mathfunctionize.bayes_theorem(0.01, 0.99, 0.9, 0.05)
# 0.154...
function uniformPDF(a, b)

Returns the probability density for a continuous uniform distribution over the interval [a, b].

ParameterTypeDescription
afloatLower bound.
bfloatUpper bound.

Returns: float 1 / (b − a)

mathfunctionize.uniformPDF(0, 10)   # 0.1
function uniformCDF(X, a, b)

Returns the cumulative distribution function value for a uniform distribution, giving the probability that a random variable is less than or equal to X.

ParameterTypeDescription
XfloatPoint to evaluate.
afloatLower bound.
bfloatUpper bound.

Returns: float 0 if X < a, 1 if X > b, (X − a)/(b − a) otherwise.

mathfunctionize.uniformCDF(3, 0, 10)   # 0.3
function normalPDF(X, mean, stdDev)

Returns the probability density of the normal (Gaussian) distribution at point X given a mean and standard deviation.

ParameterTypeDescription
XfloatPoint to evaluate.
meanfloatMean (μ) of the distribution.
stdDevfloatStandard deviation (σ).

Returns: float

mathfunctionize.normalPDF(0, 0, 1)   # 0.3989... (standard normal at 0)
function normalCDF(x, mean, stdDev)

Returns the cumulative distribution function value for the normal distribution, approximating the probability that a random variable is less than or equal to x.

ParameterTypeDescription
xfloatPoint to evaluate.
meanfloatMean (μ) of the distribution.
stdDevfloatStandard deviation (σ).

Returns: float

mathfunctionize.normalCDF(0, 0, 1)   # 0.5 (50th percentile)
function gammaPDF(x, a, b)

Returns the probability density of the gamma distribution at point x with shape parameter a and rate parameter b.

ParameterTypeDescription
xfloatPoint to evaluate (x > 0).
afloatShape parameter (α).
bfloatRate parameter (β).

Returns: float

mathfunctionize.gammaPDF(2, 2, 1)   # ~0.2706...

Complex Numbers

Operations on complex numbers represented as strings (e.g. "3+4i", "2-1i").

function complex_addition(a, b)

Adds two complex numbers given as strings.

ParameterTypeDescription
astrFirst complex number (e.g. "3+4i").
bstrSecond complex number.

Returns: str the sum as a complex number string.

mathfunctionize.complex_addition("3+4i", "1+2i")   # "4.0+6.0i"
mathfunctionize.complex_addition("5-3i", "2+1i")   # "7.0-2.0i"
function complex_subtraction(a, b)

Subtracts the second complex number from the first. Both given as strings.

ParameterTypeDescription
astrFirst complex number.
bstrSecond complex number.

Returns: str the difference as a complex number string.

mathfunctionize.complex_subtraction("5+3i", "2+1i")   # "3.0+2.0i"

Trigonometry

Trigonometric functions computed via Taylor series expansions. Angles in radians unless otherwise noted.

function sin(x) / sine(x)

Returns the sine of x (in radians) using a Taylor series approximation. sin is a shorthand alias for sine.

ParameterTypeDescription
xfloatAngle in radians.

Returns: float

mathfunctionize.sin(mathfunctionize.pi / 2)   # ~1.0
function cos(x) / cosine(x)

Returns the cosine of x (in radians) using a Taylor series approximation.

ParameterTypeDescription
xfloatAngle in radians.

Returns: float

mathfunctionize.cos(0)   # ~1.0
function tan(x) / tangent(x)

Returns the tangent of x (in radians), computed as sine(x) / cosine(x). Raises an exception if cos(x) = 0.

ParameterTypeDescription
xfloatAngle in radians.

Returns: float

Raises: Exception if cos(x) = 0.

mathfunctionize.tan(mathfunctionize.pi / 4)   # ~1.0
function csc(x) / cosecant(x)

Returns the cosecant of x (in radians), computed as 1 / sine(x). Raises an exception if sin(x) = 0.

ParameterTypeDescription
xfloatAngle in radians.

Returns: float

mathfunctionize.csc(mathfunctionize.pi / 2)   # ~1.0
function sec(x) / secant(x)

Returns the secant of x (in radians), computed as 1 / cosine(x). Raises an exception if cos(x) = 0.

ParameterTypeDescription
xfloatAngle in radians.

Returns: float

mathfunctionize.sec(0)   # ~1.0
function cot(x) / cotangent(x)

Returns the cotangent of x (in radians), computed as cosine(x) / sine(x). Raises an exception if sin(x) = 0.

ParameterTypeDescription
xfloatAngle in radians.

Returns: float

mathfunctionize.cot(mathfunctionize.pi / 4)   # ~1.0
function arcsine(x)

Returns the inverse sine of x (where -1 <= x <= 1) using a Taylor series approximation.

ParameterTypeDescription
xfloatValue in [−1, 1].

Returns: float angle in radians.

Raises: Exception if x is outside [−1, 1].

mathfunctionize.arcsine(0.5)   # ~0.5236... (≈ π/6)
function arccosine(x)

Returns the inverse cosine of x (where -1 <= x <= 1) using a Taylor series approximation.

ParameterTypeDescription
xfloatValue in [−1, 1].

Returns: float angle in radians.

Raises: Exception if x is outside [−1, 1].

mathfunctionize.arccosine(0.5)   # ~1.0472... (≈ π/3)
function arctangent(x)

Returns the inverse tangent of x (where -1 <= x <= 1) using a Taylor series approximation.

ParameterTypeDescription
xfloatValue in [−1, 1].

Returns: float angle in radians.

mathfunctionize.arctangent(1)   # ~0.7854... (≈ π/4)
function arccotangent(x)

Returns the inverse cotangent of x (x cannot be 0).

ParameterTypeDescription
xfloatInput value (x ≠ 0).

Returns: float angle in radians.

mathfunctionize.arccotangent(1)   # ~0.7854...
function arcsecant(x)

Returns the inverse secant of x (where |x| >= 1).

ParameterTypeDescription
xfloatInput value (|x| ≥ 1).

Returns: float angle in radians.

mathfunctionize.arcsecant(2)   # ~0.5235...
function arccosecant(x)

Returns the inverse cosecant of x (where |x| >= 1).

ParameterTypeDescription
xfloatInput value (|x| ≥ 1).

Returns: float angle in radians.

mathfunctionize.arccosecant(2)   # ~0.5235...
function degreeToRadian(degree)

Converts an angle from degrees to radians, normalizing to the range [0, 2π].

ParameterTypeDescription
degreefloatAngle in degrees.

Returns: float angle in radians.

mathfunctionize.degreeToRadian(180)   # 3.14159...
mathfunctionize.degreeToRadian(45)    # 0.7853...
function radianToDegree(radian)

Converts an angle from radians (in the range [0, 2π]) to degrees.

ParameterTypeDescription
radianfloatAngle in radians (0 ≤ radian ≤ 2π).

Returns: float angle in degrees.

Raises: Exception if radian is outside [0, 2π].

mathfunctionize.radianToDegree(mathfunctionize.pi)   # 180.0

Statistics

Descriptive statistics on numerical arrays.

function mean(arr)

Returns the arithmetic mean (average) of a list of numbers.

ParameterTypeDescription
arrlist[int | float]List of numbers.

Returns: float

mathfunctionize.mean([2, 4, 6, 8])   # 5.0
function median(arr)

Returns the median (middle value) of a sorted list of numbers, averaging the two middle values for even-length lists.

ParameterTypeDescription
arrlist[int | float]List of numbers.

Returns: float | None returns None for empty arrays.

mathfunctionize.median([1, 3, 5, 7])   # 4.0
mathfunctionize.median([1, 2, 3])      # 2
function mode(arr)

Returns the most frequently occurring value in a list of numbers.

ParameterTypeDescription
arrlistList of values.

Returns: int | float

Raises: Exception for empty arrays.

mathfunctionize.mode([1, 2, 2, 3, 3, 3])   # 3
function standardDevation(arr)

Returns the population standard deviation of a list of numbers, measuring the spread of data around the mean.

ParameterTypeDescription
arrlist[int | float]List of numbers.

Returns: float

mathfunctionize.standardDevation([2, 4, 4, 4, 5, 5, 7, 9])   # 2.0
function variance(arr)

Returns the population variance of a list of numbers, measuring how far each value is from the mean.

ParameterTypeDescription
arrlist[int | float]List of numbers.

Returns: float

mathfunctionize.variance([2, 4, 4, 4, 5, 5, 7, 9])   # 4.0

Quantitative Analysis

Finding extrema (minima and maxima) in numerical arrays.

function localMinimum(arr)

Finds all local minima in an array and returns a list containing the count and their positions.

ParameterTypeDescription
arrlist[int | float]List of numbers.

Returns: [int, list[int]] a list containing [count, [indices]].

mathfunctionize.localMinimum([5, 2, 8, 1, 9])   # [2, [1, 3]]
function localMaximum(arr)

Finds all local maxima in an array and returns a list containing the count and their positions.

ParameterTypeDescription
arrlist[int | float]List of numbers.

Returns: [int, list[int]] a list containing [count, [indices]].

mathfunctionize.localMaximum([1, 5, 2, 8, 3])   # [2, [1, 3]]
function globalMinimum(arr)

Finds the smallest value in an array and returns a list containing the value and all positions where it occurs.

ParameterTypeDescription
arrlist[int | float]Non-empty list of numbers.

Returns: [number, list[int]] [min_value, [indices]].

Raises: Exception for empty arrays.

mathfunctionize.globalMinimum([5, 2, 8, 2, 9])   # [2, [1, 3]]
function globalMaximum(arr)

Finds the largest value in an array and returns a list containing the value and all positions where it occurs.

ParameterTypeDescription
arrlist[int | float]Non-empty list of numbers.

Returns: [number, list[int]] [max_value, [indices]].

Raises: Exception for empty arrays.

mathfunctionize.globalMaximum([5, 9, 8, 9, 1])   # [9, [1, 3]]

Linear Algebra

Matrix operations. Matrices are represented as lists of lists (rows).

function additionMatrix(arr1, arr2)

Adds two matrices of the same dimensions element-wise and returns the resulting matrix.

ParameterTypeDescription
arr1list[list]First matrix.
arr2list[list]Second matrix (same dimensions as arr1).

Returns: list[list]

Raises: Exception if dimensions don't match.

A = [[1, 2], [3, 4]]
B = [[5, 6], [7, 8]]
mathfunctionize.additionMatrix(A, B)   # [[6, 8], [10, 12]]
function subtractionMatrix(arr1, arr2)

Subtracts two matrices of the same dimensions element-wise and returns the resulting matrix.

ParameterTypeDescription
arr1list[list]First matrix.
arr2list[list]Second matrix.

Returns: list[list]

Raises: Exception if dimensions don't match.

A = [[5, 6], [7, 8]]
B = [[1, 2], [3, 4]]
mathfunctionize.subtractionMatrix(A, B)   # [[4, 4], [4, 4]]
function multiplicationMatrix(arr1, arr2)

Performs matrix multiplication on two matrices where the number of columns in arr1 equals the number of rows in arr2.

ParameterTypeDescription
arr1list[list]First matrix (m × n).
arr2list[list]Second matrix (n × p).

Returns: list[list] resulting m × p matrix.

Raises: Exception if dimensions are incompatible.

A = [[1, 2], [3, 4]]
B = [[5, 6], [7, 8]]
mathfunctionize.multiplicationMatrix(A, B)   # [[19, 22], [43, 50]]
function determinant(arr)

Computes the determinant of a square matrix using cofactor expansion.

ParameterTypeDescription
arrlist[list]Square matrix.

Returns: int | float

Raises: Exception if the matrix is empty or not square.

mathfunctionize.determinant([[1, 2], [3, 4]])   # -2
mathfunctionize.determinant([[6, 1, 1], [4, -2, 5], [2, 8, 7]])   # -306
function transpose(arr)

Returns the transpose of a matrix, swapping rows and columns.

ParameterTypeDescription
arrlist[list]Input matrix.

Returns: list[list]

Raises: Exception if the matrix is empty.

mathfunctionize.transpose([[1, 2, 3], [4, 5, 6]])
# [[1, 4], [2, 5], [3, 6]]

Naive Set Theory

Set operations using lists as set representations.

function set(arr)

Removes all duplicate elements from a list and returns a new list containing only unique values in their original order.

ParameterTypeDescription
arrlistInput list.

Returns: list

mathfunctionize.set([1, 2, 2, 3, 3, 3])   # [1, 2, 3]
function union(set1, set2)

Returns the union of two sets, containing all unique elements that are in either set1 or set2.

ParameterTypeDescription
set1listFirst set.
set2listSecond set.

Returns: list

mathfunctionize.union([1, 2], [2, 3])   # [1, 2, 3]
function intersection(set1, set2)

Returns the intersection of two sets, containing only the elements present in both set1 and set2.

ParameterTypeDescription
set1listFirst set.
set2listSecond set.

Returns: list

mathfunctionize.intersection([1, 2, 3], [2, 3, 4])   # [2, 3]
function difference(set1, set2)

Returns the difference of two sets, containing elements that are in set1 but not in set2.

ParameterTypeDescription
set1listFirst set.
set2listSecond set.

Returns: list

mathfunctionize.difference([1, 2, 3], [2, 3, 4])   # [1]
function symmetricDifference(set1, set2)

Returns the symmetric difference of two sets, containing elements that are in either set but not in both.

ParameterTypeDescription
set1listFirst set.
set2listSecond set.

Returns: list

mathfunctionize.symmetricDifference([1, 2, 3], [2, 3, 4])   # [1, 4]
function powerSet(set)

Returns the power set of a given set, which is the list of all possible subsets including the empty set.

ParameterTypeDescription
setlistInput set.

Returns: list[list]

mathfunctionize.powerSet([1, 2])   # [[], [1], [2], [1, 2]]
function isOpenSet(set, topology)

Determines whether a given set is an open set within a specified topology by checking if every element of the set belongs to the topology.

ParameterTypeDescription
setlistThe set to check.
topologylistThe topology (collection of open sets).

Returns: bool

mathfunctionize.isOpenSet([1, 2], [1, 2, 3])   # True
function cartesianProduct(set1, set2)

Returns the Cartesian product of two sets, producing a list of all ordered pairs [a, b] where a is from set1 and b is from set2.

ParameterTypeDescription
set1listFirst set.
set2listSecond set.

Returns: list[list]

mathfunctionize.cartesianProduct([1, 2], [3, 4])
# [[1, 3], [1, 4], [2, 3], [2, 4]]
function isMemberOfSet(x, set)

Returns True if element x is a member of the given set, False otherwise.

ParameterTypeDescription
xanyElement to check.
setlistThe set.

Returns: bool

mathfunctionize.isMemberOfSet(2, [1, 2, 3])   # True
function isSubset(set1, set2)

Returns True if every element of set1 is also in set2, False otherwise.

ParameterTypeDescription
set1listCandidate subset.
set2listSuperset to check against.

Returns: bool

mathfunctionize.isSubset([1, 2], [1, 2, 3])   # True
function setEquality(set1, set2)

Returns True if both sets contain exactly the same elements, regardless of order.

ParameterTypeDescription
set1listFirst set.
set2listSecond set.

Returns: bool

mathfunctionize.setEquality([3, 1, 2], [1, 2, 3])   # True
function complement(set, universal)

Returns the complement of a set with respect to a universal set, containing all elements in the universal set that are not in the given set.

ParameterTypeDescription
setlistThe set.
universallistThe universal set.

Returns: list

mathfunctionize.complement([1, 2], [1, 2, 3, 4])   # [3, 4]
function cardinality(set)

Returns the number of elements in a set.

ParameterTypeDescription
setlistThe set.

Returns: int

mathfunctionize.cardinality([1, 2, 3])   # 3
function isProperSubset(set1, set2)

Returns True if set1 is a subset of set2 but the two sets are not equal.

ParameterTypeDescription
set1listCandidate subset.
set2listSuperset.

Returns: bool

mathfunctionize.isProperSubset([1, 2], [1, 2, 3])   # True
function isSuperset(set1, set2)

Returns True if every element of set2 is also in set1.

ParameterTypeDescription
set1listCandidate superset.
set2listSubset to check.

Returns: bool

mathfunctionize.isSuperset([1, 2, 3], [1, 2])   # True
function isProperSuperset(set1, set2)

Returns True if set1 is a superset of set2 but the two sets are not equal.

ParameterTypeDescription
set1listCandidate superset.
set2listSubset.

Returns: bool

mathfunctionize.isProperSuperset([1, 2, 3], [1, 2])   # True
function isDisjoint(set1, set2)

Returns True if the two sets share no elements in common.

ParameterTypeDescription
set1listFirst set.
set2listSecond set.

Returns: bool

mathfunctionize.isDisjoint([1, 2], [3, 4])   # True
function isEmpty(set)

Returns True if the set contains no elements.

ParameterTypeDescription
setlistThe set.

Returns: bool

mathfunctionize.isEmpty([])   # True

ZFC Axiomatic Set Theory

Functions corresponding to the axioms of Zermelo–Fraenkel set theory with the Axiom of Choice.

function extensionality(set1, set2)

Verifies the Axiom of Extensionality by checking whether two sets are equal iff they contain exactly the same elements.

ParameterTypeDescription
set1listFirst set.
set2listSecond set.

Returns: bool

mathfunctionize.extensionality([1, 2], [2, 1])   # True
function emptySet()

Returns the empty set, affirming the Axiom of Empty Set.

Returns: list

mathfunctionize.emptySet()   # []
function pairing(a, b)

Returns a set containing exactly two elements a and b, applying the Axiom of Pairing.

ParameterTypeDescription
aanyFirst element.
banySecond element.

Returns: list

mathfunctionize.pairing(1, 2)   # [1, 2]
function axiomOfUnion(collection)

Takes a list of sets and returns the union of all their elements, applying the Axiom of Union.

ParameterTypeDescription
collectionlist[list]A collection of sets.

Returns: list

mathfunctionize.axiomOfUnion([[1, 2], [2, 3], [4]])   # [1, 2, 3, 4]
function separation(set, predicate)

Returns the subset of elements from a set that satisfy a given predicate function, applying the Axiom of Separation.

ParameterTypeDescription
setlistThe set to filter.
predicateCallableA function returning True/False for each element.

Returns: list

mathfunctionize.separation([1, 2, 3, 4, 5], lambda x: x > 3)   # [4, 5]
function replacement(set, func)

Maps a function over a set and returns the set of all outputs with duplicates removed, applying the Axiom of Replacement.

ParameterTypeDescription
setlistThe input set.
funcCallableFunction to apply to each element.

Returns: list

mathfunctionize.replacement([1, 2, 3], lambda x: x * 2)   # [2, 4, 6]
function infinitySet(n)

Returns the first n elements of the von Neumann ordinal construction of the natural numbers, demonstrating the Axiom of Infinity.

ParameterTypeDescription
nintNumber of ordinals to generate.

Returns: list

mathfunctionize.infinitySet(3)   # [[], [[]], [[], [[]]]]
function regularity(set)

Verifies the Axiom of Regularity (Foundation) by checking that no element of the set is equal to the set itself. Returns True if the axiom holds.

ParameterTypeDescription
setlistThe set to check.

Returns: bool

mathfunctionize.regularity([1, 2, 3])   # True
function axiomOfChoice(collection)

Given a collection of non-empty sets, selects one element from each set and returns them as a list, applying the Axiom of Choice.

ParameterTypeDescription
collectionlist[list]A list of non-empty sets.

Returns: list

mathfunctionize.axiomOfChoice([[1, 2], [3, 4], [5]])   # [1, 3, 5]

Metric Spaces

Distance functions and metric space verification.

function dist(x, y, metric="euclidean")

Computes the distance between two points x and y in n-dimensional space under a specified metric. Supports "euclidean" (default), "manhattan", and "chebyshev".

ParameterTypeDescription
xlist[float]First point.
ylist[float]Second point.
metricstr"euclidean", "manhattan", or "chebyshev".

Returns: float

mathfunctionize.dist([0, 0], [3, 4])                    # 5.0
mathfunctionize.dist([0, 0], [3, 4], "manhattan")        # 7
mathfunctionize.dist([0, 0], [3, 4], "chebyshev")        # 4
function isMetricSpace(d, S)

Determines whether a distance function d satisfies the three metric space axioms (non-negativity with identity of indiscernibles, symmetry, and the triangle inequality) over a set S.

ParameterTypeDescription
dCallableDistance function taking two elements.
SlistSet of points to verify over.

Returns: bool

d = lambda a, b: mathfunctionize.dist(a, b)
S = [[0, 0], [1, 0], [0, 1]]
mathfunctionize.isMetricSpace(d, S)   # True

Calculus

Numerical calculus: limits, derivatives, integrals, concavity, and continuity.

function limit(f, x, a)

Evaluates the limit of a function f as x approaches a value a using numerical approximation from both sides. Returns None if the two-sided limit does not exist.

ParameterTypeDescription
fCallableThe function.
xstrVariable name (unused, for signature clarity).
afloatThe value to approach.

Returns: float | None

f = lambda x: (x**2 - 1) / (x - 1)
mathfunctionize.limit(f, "x", 1)   # 2.0
function derivative(f, x)

Computes the numerical derivative of a function f at a point x using the central difference method.

ParameterTypeDescription
fCallableThe function.
xfloatPoint to evaluate.

Returns: float

mathfunctionize.derivative(lambda x: x**2, 3)   # ~6.0
function concavity(f, x)

Determines the concavity of a function f at a point x by computing the second derivative. Returns "concave up", "concave down", or "inflection point".

ParameterTypeDescription
fCallableThe function.
xfloatPoint to evaluate.

Returns: str

mathfunctionize.concavity(lambda x: x**2, 0)    # "concave up"
mathfunctionize.concavity(lambda x: -x**2, 0)   # "concave down"
function integral(f, a, b)

Computes the definite integral of a function f over the interval [a, b] using Simpson's rule.

ParameterTypeDescription
fCallableThe function to integrate.
afloatLower bound.
bfloatUpper bound.

Returns: float

mathfunctionize.integral(lambda x: x**2, 0, 1)   # ~0.3333...
function continuity(f, x)

Tests whether a function f is continuous at a point x by checking that the left-hand limit, right-hand limit, and function value are all equal. Returns a boolean.

ParameterTypeDescription
fCallableThe function.
xfloatPoint to check.

Returns: bool

mathfunctionize.continuity(lambda x: x**2, 1)   # True

Complex Analysis

Operations on complex numbers as strings.

function conjugate(z)

Returns the complex conjugate of a complex number z represented as a string. For z = "a+bi", returns "a-bi".

ParameterTypeDescription
zstrComplex number string.

Returns: str

mathfunctionize.conjugate("3+4i")   # "3-4i"
mathfunctionize.conjugate("5-2i")   # "5+2i"
function rootsOfUnity(n)

Computes all n-th roots of unity, returning them as a list of complex number strings evenly spaced on the unit circle.

ParameterTypeDescription
nintThe degree (number of roots).

Returns: list[str]

mathfunctionize.rootsOfUnity(4)
# ["1.0+0.0i", "0.0+1.0i", "-1.0+0.0i", "0.0-1.0i"]

Number Theory

function isPrime(x)

Determines whether a positive integer x is a prime number. Returns a boolean.

ParameterTypeDescription
xintPositive integer.

Returns: bool

mathfunctionize.isPrime(17)   # True
mathfunctionize.isPrime(4)    # False

Topology

function smooth(f, x)

Tests whether a function f appears to be infinitely differentiable (smooth) at a point x by computing successive numerical derivatives and checking for convergence. Returns a boolean.

ParameterTypeDescription
fCallableThe function.
xfloatPoint to check.

Returns: bool

mathfunctionize.smooth(lambda x: x**3, 0)   # True

Polynomials

Polynomial evaluation, division, root finding, and factoring. Coefficients are ordered from highest degree to lowest.

function polyEval(coefficients, x)

Evaluates a polynomial at a given value x, where coefficients are ordered from highest degree to lowest.

ParameterTypeDescription
coefficientslist[float]Coefficients, highest degree first.
xfloatValue to evaluate at.

Returns: float

# 2x^2 + 3x + 1 at x = 2
mathfunctionize.polyEval([2, 3, 1], 2)   # 15
function divide(dividend, divisor)

Performs polynomial long division on two polynomials represented by their coefficient lists. Returns [quotient, remainder].

ParameterTypeDescription
dividendlist[float]Dividend polynomial coefficients.
divisorlist[float]Divisor polynomial coefficients.

Returns: [list, list] [quotient, remainder]

# (x^2 + 3x + 2) / (x + 1)
mathfunctionize.divide([1, 3, 2], [1, 1])   # [[1.0, 2.0], []]
function zeros(coefficients)

Finds the real roots of a polynomial given its coefficients. Supports linear, quadratic, and higher-degree polynomials via rational root search.

ParameterTypeDescription
coefficientslist[float]Polynomial coefficients, highest degree first.

Returns: list[float]

# x^2 - 5x + 6 = (x-2)(x-3)
mathfunctionize.zeros([1, -5, 6])   # [3.0, 2.0]
function factor(coefficients)

Factors a polynomial given its coefficients into irreducible factors. Returns a list of [factor, multiplicity] pairs.

ParameterTypeDescription
coefficientslist[float]Polynomial coefficients, highest degree first.

Returns: list of [[coefficients], multiplicity] pairs

# x^2 - 5x + 6 = (x-2)(x-3)
mathfunctionize.factor([1, -5, 6])
# [[[1, -3], 1], [[1, -2], 1]]