Functions
NonArchimedeanMachineLearning.AbsolutePolynomialSum — Type
AbsolutePolynomialSum{S}A structure representing absolute polynomial sums.
Represents a function as a sum of multivariate polynomials, where absolute values are taken to define the evaluation at arbitrary polydiscs.
Fields
polys::Vector{AbstractAlgebra.Generic.MPoly{S}}: Vector of multivariate polynomials
Type Parameters
S: The coefficient type (typically p-adic numbers)
Note
We may later want to generalise to allow polydiscs as coefficients.
NonArchimedeanMachineLearning.ConstantEvaluator — Type
ConstantEvaluator{S,T,N}Typed evaluator for Constant functions.
NonArchimedeanMachineLearning.LinearAbsolutePolynomialSum — Type
LinearAbsolutePolynomialSum{S}A structure representing a sum of linear polynomials.
Composed of multiple linear polynomials, allowing for efficient evaluation and gradient computation over polydisc spaces.
Fields
polys::Vector{LinearPolynomial{S}}: Vector of linear polynomials
Type Parameters
S: The coefficient type (typically p-adic numbers)
NonArchimedeanMachineLearning.LinearPolynomial — Type
LinearPolynomial{S}A structure representing a linear polynomial.
Encodes a polynomial of the form $a_1 T_1 + \cdots + a_n T_n + b$ where $a_i$ are coefficients and $b$ is a constant term.
Fields
coefficients::Vector{S}: Array of coefficients for each variableconstant::S: The constant term
Type Parameters
S: The coefficient type (typically p-adic numbers)
NonArchimedeanMachineLearning.LinearPolynomialEvaluator — Type
LinearPolynomialEvaluator{S,T,N}Typed evaluator for LinearPolynomial functions.
Precomputes coefficient valuations for efficient evaluation.
NonArchimedeanMachineLearning.PolydiscFunction — Type
PolydiscFunction{S}Abstract base type for functions on polydisc spaces.
Represents any function that can be evaluated on polydisc points and whose directional derivatives can be computed.
Type Parameters
S: The coefficient type (typically p-adic numbers)
NonArchimedeanMachineLearning.PolydiscFunctionEvaluator — Type
PolydiscFunctionEvaluator{S,T,N}Abstract base type for typed function evaluators.
Separates mathematical function definition (PolydiscFunction) from efficient computation (PolydiscFunctionEvaluator). Encodes full type information S, T, N at compile time for optimization.
Type Parameters
S: Coefficient type (e.g., ValuedFieldPoint{P,Prec,PadicFieldElem})T: Radius type (typically Int)N: Dimension of polydisc space
Design Philosophy
- PolydiscFunction{S}: "What is the function?" (mathematical definition)
- PolydiscFunctionEvaluator{S,T,N}: "How do we efficiently evaluate it?" (computation)
Usage
Evaluators are callable structs created via batch_evaluate_init:
f = LinearPolynomial([K(1), K(2)], K(0))
eval = batch_evaluate_init(f, ValuationPolydisc{S,T,N})
result = eval(polydisc) # Fully typed, no closuresNonArchimedeanMachineLearning.batch_evaluate_init — Method
batch_evaluate_init(f::PolydiscFunction{S}, ::Type{ValuationPolydisc{S,T,N}}) where {S,T,N}Create a typed evaluator for efficient batch evaluation.
NEW INTERFACE: Takes a polydisc type parameter and returns a fully-typed callable struct instead of an untyped closure. This enables compile-time specialization.
Arguments
f::PolydiscFunction{S}: The function to evaluate::Type{ValuationPolydisc{S,T,N}}: The polydisc type (determines T and N at compile time)
Returns
PolydiscFunctionEvaluator{S,T,N}: A typed, callable evaluator struct
Example
f = LinearPolynomial([K(1), K(2)], K(0))
eval = batch_evaluate_init(f, ValuationPolydisc{ValuedFieldPoint{2,20,PadicFieldElem},Int,2})
result = eval(some_polydisc) # Fully specializedDesign Benefits
- Type stability: S, T, N known at compile time
- No closures: Evaluators are concrete structs, not function objects
- Inlining: Julia can inline evaluator calls
- Specialization: Full method specialization on all type parameters
NonArchimedeanMachineLearning.batch_evaluate_init — Method
batch_evaluate_init(f::PolydiscFunction{S})::Function where SLegacy interface returning untyped closures. Retained for backwards compatibility.
DEPRECATED: Use the typed interface batch_evaluate_init(f, ::Type{ValuationPolydisc{S,T,N}}) instead.
This interface returns untyped closures which prevent compile-time specialization on T and N.
NonArchimedeanMachineLearning.directional_derivative — Method
directional_derivative(poly::LinearPolynomial{S}, v::ValuationTangent{S,T,N}) where {S, T, N}Compute the directional derivative of a linear polynomial along a tangent direction.
For poly = Σᵢ aᵢTᵢ + b, expanding around v.direction gives a constant term c₀ = b + Σᵢ aᵢdᵢ and linear terms with coefficients aᵢ. The winning term is found by minimizing the valuation weight v(aₙ) + ⟨r, n⟩, breaking ties via dot(n, v.magnitude). Since all non-constant terms have degree 1, the derivative is:
0if the constant term wins (degree 0)-p^{-best_val}if a linear term wins
Arguments
poly::LinearPolynomial{S}: The linear polynomialv::ValuationTangent{S,T,N}: The tangent direction
Returns
Float64: The directional derivative
NonArchimedeanMachineLearning.directional_derivative — Method
directional_derivative(fun::AbsolutePolynomialSum{S}, v::ValuationTangent{S,T}) where {S, T}Compute the directional derivative of a polynomial sum along a tangent direction.
Arguments
fun::AbsolutePolynomialSum{S}: The polynomial sumv::ValuationTangent{S,T}: The tangent direction
Returns
Float64: The directional derivative in direction v
NonArchimedeanMachineLearning.directional_derivative — Method
directional_derivative(f::AbstractAlgebra.Generic.MPoly{S}, v::ValuationTangent{S,T}) where {S, T}Compute the directional derivative of a multivariate polynomial along a tangent direction.
Uses the formula: if locally $|f| = a_n r^n$ for exponent $n$, then $d_v |f| = -|n| |a_n| r^n$ where $r$ is the radius of the basepoint.
Arguments
f::AbstractAlgebra.Generic.MPoly{S}: The polynomialv::ValuationTangent{S,T}: The tangent direction
Returns
Float64: The directional derivative
NonArchimedeanMachineLearning.directional_derivative — Method
directional_derivative(fun::PolydiscFunction{S}, v::ValuationTangent{S,T}) where {S, T}Compute the directional derivative of a polydisc function (sum of polynomials).
Arguments
fun::PolydiscFunction{S}: The polydisc functionv::ValuationTangent{S,T}: The tangent direction
Returns
Float64: Sum of directional derivatives across all polynomials
NonArchimedeanMachineLearning.directional_exponent — Method
directional_exponent(f::AbstractAlgebra.Generic.MPoly{S}, v::ValuationTangent{S,T}) where {S, T}Find the exponent vector(s) along which a polynomial achieves its maximum absolute value.
For a polynomial $f$ and tangent vector $v$, finds all exponent vectors $n$ such that locally in the direction of $v$, $|f| = a_n r^n$ for some coefficient $a_n$.
The maximum of $|a_n| \cdot p^{-\langle r, n \rangle}$ is equivalent to minimizing the integer quantity $v(a_n) + \langle r, n \rangle$ over non-zero terms.
Arguments
f::AbstractAlgebra.Generic.MPoly{S}: A multivariate polynomialv::ValuationTangent{S,T}: The tangent vector defining the direction
Returns
Vector: The exponent vector with minimum valuation weight, breaking ties by minimizing dot(n, v.magnitude)
NonArchimedeanMachineLearning.evaluate — Method
evaluate(fun::PolydiscFunction{S}, var::ValuationPolydisc{ValuedFieldPoint{P,Prec,S},T,N}) where {S,P,Prec,T,N}Lifting adapter: evaluate a function with coefficients of type S on a polydisc with ValuedFieldPoint{P,Prec,S} coordinates. Unwraps the polydisc and delegates to the standard evaluate method.
NonArchimedeanMachineLearning.evaluate — Method
evaluate(fun::AbsolutePolynomialSum{S}, var::ValuationPolydisc{S,T,N}) where {S, T, N}Evaluate an absolute polynomial sum at a polydisc.
Computes the sum of absolute values of each polynomial in the sum evaluated at the point.
Arguments
fun::AbsolutePolynomialSum{S}: The polynomial sumvar::ValuationPolydisc{S,T,N}: The evaluation point
Returns
Float64: The sum of polynomial evaluations
NonArchimedeanMachineLearning.evaluate — Method
evaluate(f::AbstractAlgebra.Generic.MPoly{S}, p::ValuationPolydisc{S,T,N}) where {S, T, N}Evaluate the absolute value of a multivariate polynomial at a polydisc.
Computes the p-adic absolute value by expanding the polynomial around the center and finding the maximum absolute value term weighted by the radius.
Arguments
f::AbstractAlgebra.Generic.MPoly{S}: A multivariate polynomialp::ValuationPolydisc{S,T,N}: The evaluation point (polydisc)
Returns
Float64: The absolute value of the polynomial at the polydisc
NonArchimedeanMachineLearning.evaluate — Method
evaluate(f::LinearAbsolutePolynomialSum{S}, p::ValuationPolydisc{S,T,N}) where {S, T, N}Evaluate a sum of linear polynomials at a polydisc.
For each linear polynomial $a_1 T_1 + \cdots + a_n T_n + b$, computes $\max(|a_1| r_1, \ldots, |a_n| r_n, |b + a_1 c_1 + \cdots + a_n c_n|)$ where $r$ is the radius and $c$ the center of the polydisc.
Arguments
f::LinearAbsolutePolynomialSum{S}: The sum of linear polynomialsp::ValuationPolydisc{S,T,N}: The evaluation point
Returns
Float64: The sum of evaluations across all linear polynomials
NonArchimedeanMachineLearning.evaluate — Method
evaluate(poly::LinearPolynomial{S}, p::ValuationPolydisc{S,T,N}) where {S, T, N}Evaluate a single linear polynomial at a polydisc.
For a linear polynomial $a_1 T_1 + \cdots + a_n T_n + b$, computes $\max(|a_1| r_1, \ldots, |a_n| r_n, |b + a_1 c_1 + \cdots + a_n c_n|)$
Arguments
poly::LinearPolynomial{S}: The linear polynomialp::ValuationPolydisc{S,T,N}: The evaluation point
Returns
Float64: The maximum absolute value term
NonArchimedeanMachineLearning.evaluate — Method
evaluate(f::PolydiscFunction{S}, p::ValuationPolydisc{S,T,N}) where {S, T, N}Evaluate a polydisc function at a polydisc.
Arguments
f::PolydiscFunction{S}: The polydisc functionp::ValuationPolydisc{S,T,N}: The evaluation point
Returns
The function value at the point
NonArchimedeanMachineLearning.grad — Method
grad(f, v::ValuationTangent{S,T}) where {S, T}Compute the gradient of a polynomial by evaluating directional derivatives along all coordinates.
Arguments
f: The polynomial or functionv::ValuationTangent{S,T}: A reference tangent vector defining the space
Returns
Vector: Gradient components, one for each coordinate direction
NonArchimedeanMachineLearning.parent — Method
parent(F::AbsolutePolynomialSum{S}) where SGet the polynomial ring of an absolute polynomial sum.
Arguments
F::AbsolutePolynomialSum{S}: The absolute polynomial sum
Returns
Ring: The parent ring of the first polynomial
NonArchimedeanMachineLearning.parent — Method
parent(F::PolydiscFunction{S}) where SGet the polynomial ring of a polydisc function.
Arguments
F::PolydiscFunction{S}: The polydisc function
Returns
The parent polynomial ring
NonArchimedeanMachineLearning.partial_gradient — Method
partial_gradient(f, v::ValuationTangent{S,T}, gradient_indices) where {S, T}Compute partial derivatives along specified coordinate directions.
Arguments
f: The polynomial or functionv::ValuationTangent{S,T}: A reference tangent vectorgradient_indices: Indices of coordinates for which to compute derivatives
Returns
Vector: Directional derivatives for the specified coordinates