Canonical Euclidean Domains #
This module defines CanonicalEuclideanDomain and provides instances for ℤ, Polynomial F,
and Field.
Canonical Euclidean Domains #
A CanonicalEuclideanDomain is a restriction of EuclideanDomain. It introduces a selection
rule for canonical remainders and guarantees there exists exactly one
canonical quotient (q) and remainder (r) for any pair of dividend (a) and divisor (b)
(assuming b ≠ 0), no matter how the division is implemented (i.e. the division result is
unique and consistent across different implementations).
Motivation: The unpredictable behaviors of / and % in EuclideanDomain #
In a standard EuclideanDomain, the operators / and % are viewed as black-boxes and are
only required to return some valid pair satisfying a = b * q + r and r ≺ b. This loose
specification allows implementations to be unpredictable and inconsistent:
- Unprovable Algebraic Identities:
An implementation is permitted to switch strategies arbitrarily (e.g., rounding up for input
xbut down for inputy; or following truncation-towards-zero as in C/Rust/Java, ...). This makes natural identities like(a + b * k) / b = a / b + kfalse in the general case, as the termb * kmight trigger a strategy switch. - Non-Determinism Accumulation (Unit Drift):
Algorithms that chain multiple operations (like GCD) accumulate arbitrary unit factors
at every step. For example,
gcd(a, b)is only unique up to a unit.
The Solution: CanonicalEuclideanDomain solves this by enforcing a strict
is_canonical_remainder predicate. This restricts the implementation space to exactly one
valid function, ensuring the bit-exact uniqueness of the outputs, no matter what
implementations are used.
Advantages #
Algebraic Stability: Restores critical algebraic properties, enabling a suite of powerful rewrite rules (e.g.,
add_mod_eq,add_mul_div_right,mul_mod_eq,mod_eq_of_eq_add_mul) that are unprovable in the normalEuclideanDomainsetting. This brings canonical regularity to domains with non-unique remainders (e.g.,ℤ,Polynomial F).Generic Algorithms over Rings: Guarantees strictly normalized outputs (positive GCDs, monic generators) for high-level algorithms (Smith Normal Form, Hermite Normal Form). It prevents the
unit driftdescribed above, allowing generic algorithms to run deterministically on complex domains likePolynomial F.Protocol Determinism: Essential for cryptographic protocols (ZK transcripts, Fiat-Shamir) where objects must have bit-exact representations. It ensures that every implementation (Lean, Rust, ZK circuits) converges to the same remainder given the same canonical remainder rule, guaranteeing correctness and hash consistency.
Supported Instances #
This abstraction unifies commonly used mathematical objects under one interface:
- Integers (
ℤ): The canonical rule enforces non-negative remainders (0 ≤ r < |b|). This matches the behavior of Python's%or Rust'srem_euclid. - Polynomials (
Polynomial F): Uniqueness is naturally enforced by the degree structure. Any remainder withdegree(r) < degree(b)is automatically unique due to the ultrametric property of polynomial degrees (i.e.,degree(a - b) ≤ max(degree a, degree b)). - Fields (
ℚ,ℝ,ZMod pwhere p is prime, ...): Division is exact; the canonical remainder is always0. - Other Euclidean Rings: Gaussian Integers (
ℤ[i]), Eisenstein Integers (ℤ[ω]), and Discrete Valuation Rings (DVRs) can potentially be adapted to this interface by defining strict geometric or valuation-based selection rules.
Definition #
It extends EuclideanDomain with:
is_canonical_remainder b r: A predicate deciding if a remainderris the "chosen one".remainder_is_canonical: A proof that the built-in%operator satisfies this predicate.unique_division: TheUniqueness Axiomstating that if(q1, r1)and(q2, r2)both satisfy the division equation and the canonical rule, they must be equal.
- zero : R
- add : R → R → R
- one : R
- mul : R → R → R
- neg : R → R
- sub : R → R → R
- exists_pair_ne : ∃ (x : R) (y : R), x ≠ y
- quotient : R → R → R
- remainder : R → R → R
- quotient_mul_add_remainder_eq (a b : R) : b * EuclideanDomain.quotient a b + EuclideanDomain.remainder a b = a
- is_canonical_remainder (b r : R) : Prop
- remainder_is_canonical (a b : R) (hb : b ≠ 0) : is_canonical_remainder b (EuclideanDomain.remainder a b)
Instances
The Fundamental Theorem of Canonical Euclidean Domains. If you find ANY pair (q, r) that satisfies the division equation AND the canonical condition, then q MUST be the result of the division operation.
The Fundamental Theorem of CEDs: Satisfying the division equation + size constraint is EQUIVALENT to being the output of the division function.
Division Properties #
Generalized add_mul_div_right: (a + b * r) / b = a / b + r
In a standard ED, this isn't always true (the quotient is not unique).
In a CED, it is always true.
Generalized add_mul_mod_right: (a + b * r) % b = a % b
The remainder ignores multiples of the divisor.
Generalized add_mul_mod_left: (a * r + b) % a = b % a`
The remainder ignores multiples of the divisor.
Arithmetic Modulo Properties #
(a * b) % n = 0 if a % n = 0
(a % n) % n = a % n
b | a - (a % b)