Documentation

CslibFrontier.Logics.RealArithmetic.ModularEvaluation

Modular evaluation and size bounds for real-arithmetic terms #

The evaluator follows the arithmetic syntax, reducing every intermediate modulo the supplied modulus. For a positive modulus it gives the canonical residue of the integer polynomial. The same computation can consume the constructor tokens directly from right to left, using a stack of residues and rejecting operators with too few operands. The term's binary word length bounds the polynomial degree and the exponent of a dyadic coefficient norm bound, regardless of the ambient dimension.

Adapted from TermEvaluationContext and EncodedTermPolynomial in lean-canny at 970f28a5ecefc1327402ade16c068aa4b1b2c183, using the frontier syntax and constructor stream.

Main results #

Evaluate an arithmetic term modulo p, reading absent coordinates as zero.

theorem Cslib.Logic.RealArithmetic.Term.evalResidue_eq {n p : ℕ} (hp : 0 < p) (point : List ℕ) (t : Term n) :
evalResidue p point t = (MvPolynomial.eval₂ (Int.castRingHom (ZMod p)) (fun (i : Fin n) => ↑(point[↑i]?.getD 0)) t.toPolynomial).val

For a positive modulus the result is the canonical residue of the term polynomial with each coordinate read from the supplied list and missing coordinates set to zero.

Process one constructor token from the right of a prefix stream. A leaf pushes a residue. A binary operator replaces the top two residues and fails if fewer than two are available.

Process prefix tokens from right to left, starting with an existing residue stack. Failure propagates if any operator has too few operands.

theorem Cslib.Logic.RealArithmetic.Term.evalTokenStack_tokens {n : ℕ} (p : ℕ) (point : List ℕ) (t : Term n) (stack : List ℕ) :
evalTokenStack p point (List.map TermToken.ofFin (encTerm_tokens n t)) stack = some (evalResidue p point t :: stack)

Processing a complete term stream pushes its modular value above the initial stack.

theorem Cslib.Logic.RealArithmetic.Term.evalTokenStack_bounds {p : ℕ} (hp : 0 < p) (point : List ℕ) (tokens : List TermToken) {stack result : List ℕ} (hs : ∀ x ∈ stack, x < p) (h : evalTokenStack p point tokens stack = some result) :
result.length ≤ stack.length + tokens.length ∧ ∀ x ∈ result, x < p

Each successful suffix of the prefix stream grows the stack by at most one entry per token. For positive p, every entry stays below p if the initial entries do.

The encoding length bounds both the total degree and the binary coefficient norm exponent of the term polynomial. Negative constants use their binary magnitudes in this bound.