Research-Stack/0-Core-Formalism/lean/Semantics/Semantics/SieveLemmas.lean
allaun c23280c83f feat(lean): add SieveLemmas.lean with depth_token_coprime_intersect
- Formalizes coprime sieve observers and CRT reconstruction
- depth_token_coprime_intersect: two coprime observations uniquely
  determine the semantic coordinate modulo ℓ₁·ℓ₂
- Witness: human ℓ=7 and dolphin ℓ=11 reconstruct shared coordinate 61 mod 77
- Add to Semantics.lean imports; builds under Compiler surface
2026-06-20 20:05:05 -05:00

112 lines
5.9 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/-
SieveLemmas.lean -- Number-theoretic lemmas for coprime sieve observers
This module formalizes the CRT reconstruction principle referenced in
ImaginarySemanticTime.lean: two observers with coprime native sieve moduli
hold independent, complementary shadows of the same underlying manifold
coordinate. Neither observer can recover the other's view without a CRT
exchange, but together they reconstruct the coordinate modulo the product.
Key lemma: depth_token_coprime_intersect — the observations of two coprime
sieves intersect in exactly one residue class modulo ℓ₁·ℓ₂, which is the
original semantic coordinate's residue class.
-/
import Mathlib.Data.Nat.GCD.BigOperators
import Mathlib.Data.ZMod.Basic
namespace Semantics.SieveLemmas
open Nat
-- ═══════════════════════════════════════════════════════════════════════════
-- §1 Sieve observations and coprimality
-- ═══════════════════════════════════════════════════════════════════════════
/-- A sieve modulus is a positive natural number used as a native resolution.
We bundle the positivity proof so that modular operations are well-behaved. -/
structure SieveModulus where
val : Nat
pos : val > 0
deriving Repr
/-- Observation of a semantic coordinate `x` through a sieve modulus ``. -/
def observe ( : SieveModulus) (x : Nat) : Nat := x % .val
/-- Two sieve moduli are coprime observers when their values are coprime. -/
def CoprimeObservers (1 2 : SieveModulus) : Prop :=
Coprime 1.val 2.val
instance {1 2 : SieveModulus} : Decidable (CoprimeObservers 1 2) := by
unfold CoprimeObservers; infer_instance
/-- An observation is always smaller than its sieve modulus. -/
lemma observe_lt ( : SieveModulus) (x : Nat) : observe x < .val := by
simp only [observe]
apply mod_lt
exact .pos
-- ═══════════════════════════════════════════════════════════════════════════
-- §2 CRT reconstruction
-- ═══════════════════════════════════════════════════════════════════════════
/-- Reconstruct the unique residue modulo ℓ₁·ℓ₂ that projects to `r1` and `r2`.
Returns 0 if either modulus is invalid (defensive, since SieveModulus is positive). -/
def crtReconstruct (1 2 : SieveModulus) (r1 r2 : Nat) (hc : CoprimeObservers 1 2) : Nat :=
(chineseRemainder hc r1 r2).val
/-- The CRT reconstruction is correct modulo the first observer's modulus. -/
theorem crtReconstruct_mod_1 (1 2 : SieveModulus) (r1 r2 : Nat)
(hc : CoprimeObservers 1 2) :
crtReconstruct 1 2 r1 r2 hc % 1.val = r1 % 1.val := by
simp [crtReconstruct]
exact (chineseRemainder hc r1 r2).property.left
/-- The CRT reconstruction is correct modulo the second observer's modulus. -/
theorem crtReconstruct_mod_2 (1 2 : SieveModulus) (r1 r2 : Nat)
(hc : CoprimeObservers 1 2) :
crtReconstruct 1 2 r1 r2 hc % 2.val = r2 % 2.val := by
simp [crtReconstruct]
exact (chineseRemainder hc r1 r2).property.right
-- ═══════════════════════════════════════════════════════════════════════════
-- §3 The coprime-intersection theorem (depth-token view)
-- ═══════════════════════════════════════════════════════════════════════════
/-- The observations of two coprime sieve observers uniquely determine the
semantic coordinate modulo ℓ₁·ℓ₂. This is the "depth-token coprime
intersection": two independent sieve depths coincide at exactly one
residue class of the product modulus. -/
theorem depth_token_coprime_intersect
(1 2 : SieveModulus) (x : Nat) (hc : CoprimeObservers 1 2) :
let r1 := observe 1 x
let r2 := observe 2 x
crtReconstruct 1 2 r1 r2 hc % (1.val * 2.val) = x % (1.val * 2.val) := by
intro r1 r2
have h1 : crtReconstruct 1 2 r1 r2 hc % 1.val = x % 1.val := by
rw [crtReconstruct_mod_1 1 2 r1 r2 hc]
simp [observe, r1]
have h2 : crtReconstruct 1 2 r1 r2 hc % 2.val = x % 2.val := by
rw [crtReconstruct_mod_2 1 2 r1 r2 hc]
simp [observe, r2]
exact (modEq_and_modEq_iff_modEq_mul hc).mp ⟨h1, h2⟩
-- ═══════════════════════════════════════════════════════════════════════════
-- §4 Witness
-- ═══════════════════════════════════════════════════════════════════════════
/-- Human (=7) and dolphin (=11) reconstruct 61 mod 77. -/
def human : SieveModulus := ⟨7, by decide⟩
def dolphin : SieveModulus := ⟨11, by decide⟩
def shared : Nat := 61
def humanShadow : Nat := observe human shared
def dolphinShadow : Nat := observe dolphin shared
def reconciled : Nat :=
crtReconstruct human dolphin humanShadow dolphinShadow (by decide)
#eval humanShadow -- 5
#eval dolphinShadow -- 6
#eval! reconciled -- 61
end Semantics.SieveLemmas