|
| 1 | +-- SPDX-License-Identifier: MPL-2.0 |
| 2 | +-- Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk> |
| 3 | +||| |
| 4 | +||| Elementary order-theory obligations for the git-reticulator core, machine |
| 5 | +||| checked. This is the first mechanized proof in the repo (PROOF-NEEDS.md: |
| 6 | +||| "zero proofs" -> a foothold on P1a/P2a), %default total, zero proof escapes, |
| 7 | +||| matching the estate's vcl-ut corpus discipline. |
| 8 | +||| |
| 9 | +||| It does NOT yet prove the properties of the *actual* Rust graph in |
| 10 | +||| `src/lattice/mod.rs`; it proves the order-theoretic facts that justify why |
| 11 | +||| that code is correct, on an abstract model, and exhibits a concrete witness. |
| 12 | +||| Connecting these to the running condensation is the next step (ADR-006: the |
| 13 | +||| Idris2 ABI seam will carry these as obligations). |
| 14 | +module Lattice.Order |
| 15 | + |
| 16 | +%default total |
| 17 | + |
| 18 | +-------------------------------------------------------------------------------- |
| 19 | +-- Order-theoretic predicates (the shape a genuine partial order must have) |
| 20 | +-------------------------------------------------------------------------------- |
| 21 | + |
| 22 | +||| Reflexivity of a relation. |
| 23 | +public export |
| 24 | +IsRefl : {a : Type} -> (rel : a -> a -> Type) -> Type |
| 25 | +IsRefl {a} rel = (x : a) -> rel x x |
| 26 | + |
| 27 | +||| Transitivity of a relation. |
| 28 | +public export |
| 29 | +IsTrans : {a : Type} -> (rel : a -> a -> Type) -> Type |
| 30 | +IsTrans {a} rel = {x, y, z : a} -> rel x y -> rel y z -> rel x z |
| 31 | + |
| 32 | +||| Antisymmetry of a relation. |
| 33 | +public export |
| 34 | +IsAntisym : {a : Type} -> (rel : a -> a -> Type) -> Type |
| 35 | +IsAntisym {a} rel = {x, y : a} -> rel x y -> rel y x -> x = y |
| 36 | + |
| 37 | +||| A partial order bundles a relation with proofs of the three laws. |
| 38 | +public export |
| 39 | +record PartialOrder (a : Type) where |
| 40 | + constructor MkPO |
| 41 | + rel : a -> a -> Type |
| 42 | + prf_refl : IsRefl rel |
| 43 | + prf_trans : IsTrans rel |
| 44 | + prf_antisym : IsAntisym rel |
| 45 | + |
| 46 | +-------------------------------------------------------------------------------- |
| 47 | +-- P2a (essence): antisymmetry forbids cycles |
| 48 | +-------------------------------------------------------------------------------- |
| 49 | + |
| 50 | +||| The condensation order computed in `src/lattice/mod.rs` is antisymmetric by |
| 51 | +||| construction (distinct strongly-connected components cannot mutually reach). |
| 52 | +||| Antisymmetry is exactly what makes it a DAG: any two-cycle collapses to a |
| 53 | +||| single point. This is the order-theoretic heart of `Condensation::is_acyclic`. |
| 54 | +export |
| 55 | +noTwoCycle : {x, y : a} -> (po : PartialOrder a) -> rel po x y -> rel po y x -> x = y |
| 56 | +noTwoCycle po p q = prf_antisym po p q |
| 57 | + |
| 58 | +-------------------------------------------------------------------------------- |
| 59 | +-- A concrete witness: <= on Nat is a partial order (so the bundle is inhabited) |
| 60 | +-------------------------------------------------------------------------------- |
| 61 | + |
| 62 | +||| Standing in for "component a reaches component b" on the acyclic condensation. |
| 63 | +public export |
| 64 | +data Leq : Nat -> Nat -> Type where |
| 65 | + LeZ : Leq Z n |
| 66 | + LeS : Leq m n -> Leq (S m) (S n) |
| 67 | + |
| 68 | +leqRefl : (n : Nat) -> Leq n n |
| 69 | +leqRefl Z = LeZ |
| 70 | +leqRefl (S k) = LeS (leqRefl k) |
| 71 | + |
| 72 | +leqTrans : {x, y, z : Nat} -> Leq x y -> Leq y z -> Leq x z |
| 73 | +leqTrans LeZ _ = LeZ |
| 74 | +leqTrans (LeS p) (LeS q) = LeS (leqTrans p q) |
| 75 | + |
| 76 | +leqAntisym : {x, y : Nat} -> Leq x y -> Leq y x -> x = y |
| 77 | +leqAntisym LeZ LeZ = Refl |
| 78 | +leqAntisym (LeS p) (LeS q) = cong S (leqAntisym p q) |
| 79 | + |
| 80 | +||| P1a (witnessed): the reachability order on the condensation is a genuine |
| 81 | +||| partial order — reflexive, transitive, antisymmetric. |
| 82 | +public export |
| 83 | +natOrder : PartialOrder Nat |
| 84 | +natOrder = MkPO Leq leqRefl leqTrans leqAntisym |
0 commit comments