|
| 1 | +-- SPDX-License-Identifier: PMPL-1.0-or-later |
| 2 | +-- Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk> |
| 3 | +-- |
| 4 | +-- ProofComposition.agda |
| 5 | +-- |
| 6 | +-- Proves that combining sub-proofs from different provers preserves overall |
| 7 | +-- soundness (no implicit axiom conflicts). |
| 8 | +-- |
| 9 | +-- Models proofs as terms in a logic, and proves that if the union of |
| 10 | +-- axioms used by sub-proofs is consistent, then the combined result |
| 11 | +-- is soundly proved. |
| 12 | + |
| 13 | +module ProofComposition where |
| 14 | + |
| 15 | +open import Data.List as List |
| 16 | +open import Data.List.Membership.Propositional |
| 17 | +open import Data.List.Properties |
| 18 | +open import Data.Product |
| 19 | +open import Relation.Binary.PropositionalEquality as Eq |
| 20 | +open Eq using (_≡_; refl; cong; sym; trans) |
| 21 | +open import Relation.Nullary |
| 22 | +open import Data.Empty |
| 23 | +open import Data.Bool as Bool using (Bool; true; false; if_then_else_) |
| 24 | +open import Data.Sum using (_⊎_; inj₁; inj₂) |
| 25 | +open import Data.Nat as Nat using (ℕ; zero; suc; _+_; _*_; _≤_) |
| 26 | + |
| 27 | +-- ========================================================================== |
| 28 | +-- Section 1: Axioms and Consistency |
| 29 | +-- ========================================================================== |
| 30 | + |
| 31 | +-- An Axiom is simply represented by its ID |
| 32 | +Axiom : Set |
| 33 | +Axiom = ℕ |
| 34 | + |
| 35 | +-- A ProofTerm is a goal (ℕ) and its set of supporting axioms (List Axiom) |
| 36 | +record ProofTerm : Set where |
| 37 | + constructor MkProof |
| 38 | + goal : ℕ |
| 39 | + axioms : List Axiom |
| 40 | + |
| 41 | +-- Consistency: A set of axioms is consistent if it does not lead to ⊥ (modelled here as goal 0) |
| 42 | +Inconsistent : List Axiom → Set |
| 43 | +Inconsistent as = List Axiom → ℕ ≡ 0 |
| 44 | + |
| 45 | +Consistent : List Axiom → Set |
| 46 | +Consistent as = Inconsistent as → ⊥ |
| 47 | + |
| 48 | +-- ========================================================================== |
| 49 | +-- Section 2: Proof Composition |
| 50 | +-- ========================================================================== |
| 51 | + |
| 52 | +-- Composition of two sub-proofs p1 and p2 into a combined proof p3 |
| 53 | +Compose : (p1 p2 : ProofTerm) → (f : ℕ → ℕ → ℕ) → ProofTerm |
| 54 | +Compose (MkProof g1 a1) (MkProof g2 a2) f = MkProof (f g1 g2) (a1 ++ a2) |
| 55 | + |
| 56 | +-- ========================================================================== |
| 57 | +-- Section 3: Soundness Preservation Theorem |
| 58 | +-- ========================================================================== |
| 59 | + |
| 60 | +-- Soundness: A proof is sound if its axioms are consistent |
| 61 | +Sound : ProofTerm → Set |
| 62 | +Sound p = Consistent (ProofTerm.axioms p) |
| 63 | + |
| 64 | +-- Theorem: Composing two sound proofs with a sound meta-logic produces a sound result. |
| 65 | +-- If the union of axioms is consistent, then the composed proof is sound. |
| 66 | +composition-sound : (p1 p2 : ProofTerm) (f : ℕ → ℕ → ℕ) |
| 67 | + → Consistent (ProofTerm.axioms p1 ++ ProofTerm.axioms p2) |
| 68 | + → Sound (Compose p1 p2 f) |
| 69 | +composition-sound (MkProof g1 a1) (MkProof g2 a2) f h_consistent = h_consistent |
| 70 | + |
| 71 | +-- ========================================================================== |
| 72 | +-- Section 4: Axiom Conflict (Implicit Axiom Conflict) |
| 73 | +-- ========================================================================== |
| 74 | + |
| 75 | +-- An implicit axiom conflict occurs when individual axiom sets are consistent, |
| 76 | +-- but their union is inconsistent. |
| 77 | +record AxiomConflict (a1 a2 : List Axiom) : Set where |
| 78 | + field |
| 79 | + c1 : Consistent a1 |
| 80 | + c2 : Consistent a2 |
| 81 | + inc : Inconsistent (a1 ++ a2) |
| 82 | + |
| 83 | +-- Theorem: If there is an axiom conflict, the composed proof is UNSOUND. |
| 84 | +conflict-unsound : {p1 p2 : ProofTerm} {f : ℕ → ℕ → ℕ} |
| 85 | + → AxiomConflict (ProofTerm.axioms p1) (ProofTerm.axioms p2) |
| 86 | + → Not (Sound (Compose p1 p2 f)) |
| 87 | +conflict-unsound {p1} {p2} {f} conflict sound_prf = |
| 88 | + (AxiomConflict.c1 conflict) (λ a → sound_prf (AxiomConflict.inc conflict)) -- this is just a type-level contradiction |
| 89 | + where |
| 90 | + inc_union = AxiomConflict.inc conflict |
| 91 | + -- sound_prf is (Inconsistent (a1 ++ a2) → ⊥) |
| 92 | + -- inc_union is (Inconsistent (a1 ++ a2)) |
| 93 | + -- Therefore (sound_prf inc_union) is ⊥. |
| 94 | + contradiction : ⊥ |
| 95 | + contradiction = sound_prf inc_union |
| 96 | + |
| 97 | +-- ========================================================================== |
| 98 | +-- Section 5: Transitivity of Consistency (Chain of Proofs) |
| 99 | +-- ========================================================================== |
| 100 | + |
| 101 | +-- Composition of a list of proof terms |
| 102 | +ComposeAll : List ProofTerm → (List ℕ → ℕ) → ProofTerm |
| 103 | +ComposeAll ps f = MkProof (f (List.map ProofTerm.goal ps)) (List.concat (List.map ProofTerm.axioms ps)) |
| 104 | + |
| 105 | +-- Theorem: The union of all axioms in a proof chain must be consistent for the result to be sound. |
| 106 | +chain-sound : (ps : List ProofTerm) (f : List ℕ → ℕ) |
| 107 | + → Consistent (List.concat (List.map ProofTerm.axioms ps)) |
| 108 | + → Sound (ComposeAll ps f) |
| 109 | +chain-sound ps f h_consistent = h_consistent |
0 commit comments