Functions

NonArchimedeanMachineLearning.AbsolutePolynomialSumType
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.

source
NonArchimedeanMachineLearning.LinearAbsolutePolynomialSumType
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)
source
NonArchimedeanMachineLearning.LinearPolynomialType
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 variable
  • constant::S: The constant term

Type Parameters

  • S: The coefficient type (typically p-adic numbers)
source
NonArchimedeanMachineLearning.PolydiscFunctionType
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)
source
NonArchimedeanMachineLearning.PolydiscFunctionEvaluatorType
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 closures
source
NonArchimedeanMachineLearning.batch_evaluate_initMethod
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 specialized

Design 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
source
NonArchimedeanMachineLearning.batch_evaluate_initMethod
batch_evaluate_init(f::PolydiscFunction{S})::Function where S

Legacy 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.

source
NonArchimedeanMachineLearning.directional_derivativeMethod
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:

  • 0 if the constant term wins (degree 0)
  • -p^{-best_val} if a linear term wins

Arguments

  • poly::LinearPolynomial{S}: The linear polynomial
  • v::ValuationTangent{S,T,N}: The tangent direction

Returns

Float64: The directional derivative

source
NonArchimedeanMachineLearning.directional_derivativeMethod
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 sum
  • v::ValuationTangent{S,T}: The tangent direction

Returns

Float64: The directional derivative in direction v

source
NonArchimedeanMachineLearning.directional_derivativeMethod
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 polynomial
  • v::ValuationTangent{S,T}: The tangent direction

Returns

Float64: The directional derivative

source
NonArchimedeanMachineLearning.directional_derivativeMethod
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 function
  • v::ValuationTangent{S,T}: The tangent direction

Returns

Float64: Sum of directional derivatives across all polynomials

source
NonArchimedeanMachineLearning.directional_exponentMethod
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 polynomial
  • v::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)

source
NonArchimedeanMachineLearning.evaluateMethod
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.

source
NonArchimedeanMachineLearning.evaluateMethod
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 sum
  • var::ValuationPolydisc{S,T,N}: The evaluation point

Returns

Float64: The sum of polynomial evaluations

source
NonArchimedeanMachineLearning.evaluateMethod
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 polynomial
  • p::ValuationPolydisc{S,T,N}: The evaluation point (polydisc)

Returns

Float64: The absolute value of the polynomial at the polydisc

source
NonArchimedeanMachineLearning.evaluateMethod
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 polynomials
  • p::ValuationPolydisc{S,T,N}: The evaluation point

Returns

Float64: The sum of evaluations across all linear polynomials

source
NonArchimedeanMachineLearning.evaluateMethod
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 polynomial
  • p::ValuationPolydisc{S,T,N}: The evaluation point

Returns

Float64: The maximum absolute value term

source
NonArchimedeanMachineLearning.evaluateMethod
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 function
  • p::ValuationPolydisc{S,T,N}: The evaluation point

Returns

The function value at the point

source
NonArchimedeanMachineLearning.gradMethod
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 function
  • v::ValuationTangent{S,T}: A reference tangent vector defining the space

Returns

Vector: Gradient components, one for each coordinate direction

source
NonArchimedeanMachineLearning.parentMethod
parent(F::AbsolutePolynomialSum{S}) where S

Get 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

source
NonArchimedeanMachineLearning.parentMethod
parent(F::PolydiscFunction{S}) where S

Get the polynomial ring of a polydisc function.

Arguments

  • F::PolydiscFunction{S}: The polydisc function

Returns

The parent polynomial ring

source
NonArchimedeanMachineLearning.partial_gradientMethod
partial_gradient(f, v::ValuationTangent{S,T}, gradient_indices) where {S, T}

Compute partial derivatives along specified coordinate directions.

Arguments

  • f: The polynomial or function
  • v::ValuationTangent{S,T}: A reference tangent vector
  • gradient_indices: Indices of coordinates for which to compute derivatives

Returns

Vector: Directional derivatives for the specified coordinates

source