Documentation

CslibFrontier.Computability.Complexity.Classes.CountingHierarchy.ModularArithmetic

Same-level total modular subtraction #

modularSub subtracts binary residues without constructing a negative natural number. Its polynomial-time certificate is total, including modulus zero, and its counting-function certificate preserves the common level of all three inputs. At every positive modulus the output casts to the actual difference in ZMod p.

Ported from LeanCanny.CountingHierarchy.ModularArithmetic at lean-canny commit 970f28a5ecefc1327402ade16c068aa4b1b2c183. This shared arithmetic supports modular evaluators without importing the real-arithmetic applications.

Total modular subtraction; modulus zero returns the natural value x.

Binary modular subtraction preserves a common counting-function level.

theorem Cslib.Complexity.modularSub_cast {p : ℕ} (hp : 0 < p) (x y : ℕ) :
↑(modularSub p x y) = ↑x - ↑y

At a positive modulus, the evaluator represents subtraction in ZMod p.