diff --git a/docs/proposals/same-world-ladder/Bridge.agda b/docs/proposals/same-world-ladder/Bridge.agda new file mode 100644 index 00000000..bb45b936 --- /dev/null +++ b/docs/proposals/same-world-ladder/Bridge.agda @@ -0,0 +1,21 @@ +{-# OPTIONS --cubical --safe #-} +-- SPDX-License-Identifier: MPL-2.0 +-- Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) +-- Scratch sketch. Rung B0: a Cubical module imports the Ladder A module. +module Bridge where + +open import Agda.Builtin.Cubical.Path using (_≡_) +import Agda.Builtin.Equality as Id +open import Agda.Builtin.List using (List) +open import SameWorld using (module World) + +toPath : {A : Set} {x y : A} → x Id.≡ y → x ≡ y +toPath {x = x} Id.refl = λ _ → x + +module _ (In W : Set) (step : W → In → W) {P : Set} (see : W → P) where + open World In W step + open View see + + -- The Ladder A relation gives a path between experiences. + lift : ∀ {w w′} → w ~ w′ → beh w ≡ beh w′ + lift e k is = toPath (e is) k diff --git a/docs/proposals/same-world-ladder/README.adoc b/docs/proposals/same-world-ladder/README.adoc new file mode 100644 index 00000000..2e674a99 --- /dev/null +++ b/docs/proposals/same-world-ladder/README.adoc @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: CC-BY-SA-4.0 += Same-world proof ladder: sketches +:toc: preamble + +Status: *sketch, not admitted* (2026-11-22). These files are a backup of +work in progress. They are not on the theory shelf, they are not in +`verification/proofs/agda/MANIFEST`, and no receipt exists for them. Every +theorem here is `ungraded`. + +== What the files are + +The question is: when do two subjects see "the same world"? The world is a +deterministic machine (`step : W → In → W`). A view is a function from the +world state to a percept (`see : W → P`). + +[cols="2,3,3"] +|=== +| File | Content | Invocation that passed + +| `SameWorld.agda` +| Ladder A, rungs A0 to A3, A5, A6: `Coherent`, `SameWorld`, `sound`, + `stable`, `_~_`, `Bisimulation`, `greatest`, `weaker`, `Secret.no-leak`, + `Gaslight.not-same` +| `agda --safe --without-K --cubical-compatible --double-check` + +| `SameWorldCo.agda` +| Rung A4: the coinductive form (`Beh`, `_≋_`, `Lift`, `one-world`) +| The same flags plus `--guardedness`, which is outside PROOF-POLICY section 2.1 + +| `Bridge.agda` +| Rung B0: a full Cubical module imports the section 2.1 module +| `agda --cubical --safe --double-check` + +| `SameWorldCubical.agda` +| Ladder B, rungs B1 to B4: function extensionality, bisimilar is equal, + the set quotient `W / ~`, `SameWorld` as a fibre +| `agda --cubical --safe --guardedness --double-check` +|=== + +== What is not established + +* The runs used Agda 2.6.3 from an Ubuntu package, on 2026-11-21. The pinned + Guix shell has Agda 2.7.0.1. No run used the pinned shell. +* No Rocq recheck and no Lean recheck exists. +* `SameWorldCo.agda`, `Bridge.agda` and `SameWorldCubical.agda` need an + explicit, separately reviewed proof profile (PROOF-POLICY section 2.1). + No such profile exists. +* Full Cubical Agda supplies postulates in `Agda.Primitive.Cubical`. A + receipt must list them (PROOF-POLICY section 8.4). +* Rungs B5 (univalence) and B6 (pushout) are design only. No file exists. +* `collapse` in rung B3 holds for classes of states only. +* No rung proves that a host program obeys this model. `sound` is true by + construction only if a view is a pure function of the one world state. + +== Owner rulings (2026-11-22) + +. Home: the general theorems go on the theory shelf of this repository, with + an admission that names `enaction-umwelt/1` as the dependant. The Enaction + instance stays in `enaction-engine`. +. Order: Ladder A first (rungs A0 to A3, A5, A6) under section 2.1. No + profile for `--guardedness` or `--cubical` is written now. + +The admission waits for `enaction-umwelt/1`, which does not exist yet. diff --git a/docs/proposals/same-world-ladder/SameWorld.agda b/docs/proposals/same-world-ladder/SameWorld.agda new file mode 100644 index 00000000..1ac0f1c1 --- /dev/null +++ b/docs/proposals/same-world-ladder/SameWorld.agda @@ -0,0 +1,166 @@ +{-# OPTIONS --safe --without-K --cubical-compatible #-} +-- SPDX-License-Identifier: MPL-2.0 +-- Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) +-- Scratch sketch, not a receipt. Ladder A, rungs A0 to A3, A5 and A6. +-- No coinduction here. The import cone is Agda.Builtin only. +module SameWorld where + +open import Agda.Builtin.Equality using (_≡_; refl) +open import Agda.Builtin.Sigma using (Σ; _,_) +open import Agda.Builtin.List using (List; []; _∷_) +open import Agda.Builtin.Bool using (Bool; true; false) +open import Agda.Builtin.Unit using (⊤; tt) + +data ⊥ : Set where + +infixr 2 _×_ +_×_ : Set → Set → Set +A × B = Σ A (λ _ → B) + +sym : {A : Set} {x y : A} → x ≡ y → y ≡ x +sym refl = refl + +trans : {A : Set} {x y z : A} → x ≡ y → y ≡ z → x ≡ z +trans refl q = q + +subst : {A : Set} (C : A → Set) {x y : A} → x ≡ y → C x → C y +subst C refl c = c + +------------------------------------------------------------------------ +-- A0. Vocabulary. A world is a deterministic machine. +-- In is the input of one tick. W is the world state. + +module World (In W : Set) (step : W → In → W) where + + run : W → List In → W + run w [] = w + run w (i ∷ is) = run (step w i) is + + -- A view (an Umwelt) is a function from the world state to a percept. + module View {P : Set} (see : W → P) where + + -- The experience of the subject: the percept after each input word. + beh : W → List In → P + beh w is = see (run w is) + + -- A3. Two states that this subject cannot tell apart, whatever happens. + _~_ : W → W → Set + w ~ w′ = ∀ is → beh w is ≡ beh w′ is + + ~-refl : ∀ {w} → w ~ w + ~-refl is = refl + + ~-sym : ∀ {w w′} → w ~ w′ → w′ ~ w + ~-sym e is = sym (e is) + + ~-trans : ∀ {w w′ w″} → w ~ w′ → w′ ~ w″ → w ~ w″ + ~-trans e f is = trans (e is) (f is) + + record Bisimulation (R : W → W → Set) : Set where + field + now : ∀ {w w′} → R w w′ → see w ≡ see w′ + later : ∀ {w w′} → R w w′ → ∀ i → R (step w i) (step w′ i) + open Bisimulation + + ~-bisim : Bisimulation _~_ + now ~-bisim e = e [] + later ~-bisim e i is = e (i ∷ is) + + -- The coinduction principle, proved by induction on the input word: + -- every bisimulation is inside _~_. + greatest : ∀ {R} → Bisimulation R → ∀ {w w′} → R w w′ → w ~ w′ + greatest b r [] = now b r + greatest b r (i ∷ is) = greatest b (later b r i) is + + ---------------------------------------------------------------------- + -- Two subjects. + + module Two {P₁ P₂ : Set} (see₁ : W → P₁) (see₂ : W → P₂) where + open View see₁ using () renaming (beh to beh₁) + open View see₂ using () renaming (beh to beh₂) + + -- A1. Two percepts of one state. The witness is the state. + Coherent : P₁ → P₂ → Set + Coherent p₁ p₂ = Σ W (λ w → (see₁ w ≡ p₁) × (see₂ w ≡ p₂)) + + -- A2. Two experiences of one world. The witness is the start state. + SameWorld : (List In → P₁) → (List In → P₂) → Set + SameWorld b₁ b₂ = + Σ W (λ w → (∀ is → beh₁ w is ≡ b₁ is) × (∀ is → beh₂ w is ≡ b₂ is)) + + -- What a host shows to two seats from one state is of the same world. + sound : ∀ w → SameWorld (beh₁ w) (beh₂ w) + sound w = w , (λ _ → refl) , (λ _ → refl) + + after : {P : Set} → (List In → P) → In → List In → P + after b i is = b (i ∷ is) + + -- The same world stays the same world after any input. + stable : ∀ {b₁ b₂} → SameWorld b₁ b₂ → + ∀ i → SameWorld (after b₁ i) (after b₂ i) + stable (w , e₁ , e₂) i = + step w i , (λ is → e₁ (i ∷ is)) , (λ is → e₂ (i ∷ is)) + + -- A5. Coherent at each moment. This is weaker than SameWorld. + Moments : (List In → P₁) → (List In → P₂) → Set + Moments b₁ b₂ = ∀ is → Coherent (b₁ is) (b₂ is) + + weaker : ∀ {b₁ b₂} → SameWorld b₁ b₂ → Moments b₁ b₂ + weaker (w , e₁ , e₂) is = run w is , e₁ is , e₂ is + + ---------------------------------------------------------------------- + -- A6. Unwinding: a hidden input does not change what a seat sees. + + module Secret {P : Set} (see : W → P) (hidden : In → Bool) + (_≈_ : W → W → Set) + (≈-trans : ∀ {a b c} → a ≈ b → b ≈ c → a ≈ c) + (out : ∀ {w w′} → w ≈ w′ → see w ≡ see w′) + (same : ∀ {w w′} → w ≈ w′ → ∀ i → step w i ≈ step w′ i) + (hide : ∀ w i → hidden i ≡ true → step w i ≈ w) where + + purge : List In → List In + purge [] = [] + purge (i ∷ is) with hidden i + ... | true = purge is + ... | false = i ∷ purge is + + lemma : ∀ {w w′} → w ≈ w′ → ∀ is → run w is ≈ run w′ (purge is) + lemma r [] = r + lemma {w} r (i ∷ is) with hidden i in eq + ... | true = lemma (≈-trans (hide w i eq) r) is + ... | false = lemma (same r i) is + + no-leak : ∀ {w} → w ≈ w → ∀ is → see (run w is) ≡ see (run w (purge is)) + no-leak r is = out (lemma r is) + +------------------------------------------------------------------------ +-- A5, the converse fails. Each moment is possible. The story is not. + +module Gaslight where + + -- The world is one bit that never changes. + -- Subject 1 sees the bit. Subject 2 sees nothing. + still : Bool → ⊤ → Bool + still b _ = b + + open World ⊤ Bool still + open Two (λ b → b) (λ _ → tt) + + -- An experience that shows true first, and false after that. + turn : List ⊤ → Bool + turn [] = true + turn (_ ∷ _) = false + + blank : List ⊤ → ⊤ + blank _ = tt + + moments : Moments turn blank + moments [] = true , refl , refl + moments (_ ∷ _) = false , refl , refl + + T : Bool → Set + T true = ⊤ + T false = ⊥ + + not-same : SameWorld turn blank → ⊥ + not-same (w , e₁ , _) = subst T (trans (sym (e₁ [])) (e₁ (tt ∷ []))) tt diff --git a/docs/proposals/same-world-ladder/SameWorldCo.agda b/docs/proposals/same-world-ladder/SameWorldCo.agda new file mode 100644 index 00000000..d9bb6bc9 --- /dev/null +++ b/docs/proposals/same-world-ladder/SameWorldCo.agda @@ -0,0 +1,63 @@ +{-# OPTIONS --safe --without-K --cubical-compatible --guardedness #-} +-- SPDX-License-Identifier: MPL-2.0 +-- Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) +-- Scratch sketch, not a receipt. Ladder A, rung A4: the coinductive form. +-- This rung needs --guardedness, which is outside the section 2.1 invocation. +module SameWorldCo where + +open import Agda.Builtin.Equality using (_≡_; refl) +open import Agda.Builtin.Sigma using (_,_) +open import Agda.Builtin.List using (List; []; _∷_) +open import SameWorld using (module World) + +-- The experience as one infinite object (the final coalgebra). +record Beh (In P : Set) : Set where + coinductive + field + head : P + tail : In → Beh In P +open Beh public + +-- Bisimilar experiences. In this profile it is a relation, not equality. +record _≋_ {In P : Set} (b b′ : Beh In P) : Set where + coinductive + field + head≡ : head b ≡ head b′ + tail≋ : ∀ i → tail b i ≋ tail b′ i +open _≋_ public + +-- Two percept alphabets: bisimilar up to a relation between percepts. +record Lift {In P₁ P₂ : Set} (T : P₁ → P₂ → Set) + (b₁ : Beh In P₁) (b₂ : Beh In P₂) : Set where + coinductive + field + headT : T (head b₁) (head b₂) + tailT : ∀ i → Lift T (tail b₁ i) (tail b₂ i) +open Lift public + +module _ (In W : Set) (step : W → In → W) where + open World In W step + + module _ {P : Set} (see : W → P) where + open View see + + unfold : W → Beh In P + head (unfold w) = see w + tail (unfold w) i = unfold (step w i) + + -- The coinductive relation and the word relation agree. + ~→≋ : ∀ {w w′} → w ~ w′ → unfold w ≋ unfold w′ + head≡ (~→≋ e) = e [] + tail≋ (~→≋ e) i = ~→≋ (λ is → e (i ∷ is)) + + ≋→~ : ∀ {w w′} → unfold w ≋ unfold w′ → w ~ w′ + ≋→~ r [] = head≡ r + ≋→~ r (i ∷ is) = ≋→~ (tail≋ r i) is + + module _ {P₁ P₂ : Set} (see₁ : W → P₁) (see₂ : W → P₂) where + open Two see₁ see₂ + + -- One world gives two experiences that agree up to Coherent, for ever. + one-world : ∀ w → Lift Coherent (unfold see₁ w) (unfold see₂ w) + headT (one-world w) = w , refl , refl + tailT (one-world w) i = one-world (step w i) diff --git a/docs/proposals/same-world-ladder/SameWorldCubical.agda b/docs/proposals/same-world-ladder/SameWorldCubical.agda new file mode 100644 index 00000000..0977b26f --- /dev/null +++ b/docs/proposals/same-world-ladder/SameWorldCubical.agda @@ -0,0 +1,208 @@ +{-# OPTIONS --cubical --safe --guardedness #-} +-- SPDX-License-Identifier: MPL-2.0 +-- Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) +-- Scratch sketch, not a receipt. Ladder B, rungs B1 to B4, full Cubical Agda. +-- The import cone is Agda.Primitive and Agda.Builtin only (no cubical library). +module SameWorldCubical where + +open import Agda.Primitive.Cubical + using (I; i0; i1) + renaming (primINeg to ~_; primHComp to hcomp) +open import Agda.Builtin.Cubical.Path using (_≡_) +open import Agda.Builtin.Sigma using (Σ; _,_; fst; snd) +open import Agda.Builtin.List using (List; []; _∷_) + +infixr 2 _×_ +_×_ : Set → Set → Set +A × B = Σ A (λ _ → B) + +refl : {A : Set} {x : A} → x ≡ x +refl {x = x} _ = x + +sym : {A : Set} {x y : A} → x ≡ y → y ≡ x +sym p k = p (~ k) + +cong : {A B : Set} (f : A → B) {x y : A} → x ≡ y → f x ≡ f y +cong f p k = f (p k) + +infixr 30 _∙_ +_∙_ : {A : Set} {x y z : A} → x ≡ y → y ≡ z → x ≡ z +_∙_ {x = x} p q k = hcomp (λ j → λ { (k = i0) → x ; (k = i1) → q j }) (p k) + +isSet : Set → Set +isSet A = (x y : A) (p q : x ≡ y) → p ≡ q + +------------------------------------------------------------------------ +-- B1. Function extensionality is a theorem. So "cannot tell apart" is +-- the same thing as "equal experience". + +module World (In W : Set) (step : W → In → W) where + + run : W → List In → W + run w [] = w + run w (i ∷ is) = run (step w i) is + + module View {P : Set} (see : W → P) where + + beh : W → List In → P + beh w is = see (run w is) + + _~_ : W → W → Set + w ~ w′ = ∀ is → beh w is ≡ beh w′ is + + ~→≡ : ∀ {w w′} → w ~ w′ → beh w ≡ beh w′ + ~→≡ e k is = e is k + + ≡→~ : ∀ {w w′} → beh w ≡ beh w′ → w ~ w′ + ≡→~ p is k = p k is + + -- The two maps are inverse by computation alone. + there-back : ∀ {w w′} (e : w ~ w′) → ≡→~ (~→≡ e) ≡ e + there-back e = refl + + back-there : ∀ {w w′} (p : beh w ≡ beh w′) → ~→≡ (≡→~ p) ≡ p + back-there p = refl + +------------------------------------------------------------------------ +-- B2. Coinduction is a theorem. Bisimilar experiences are equal. + +record Beh (In P : Set) : Set where + coinductive + field + head : P + tail : In → Beh In P +open Beh + +record _≋_ {In P : Set} (b b′ : Beh In P) : Set where + coinductive + field + head≡ : head b ≡ head b′ + tail≋ : ∀ i → tail b i ≋ tail b′ i +open _≋_ + +path : ∀ {In P} {b b′ : Beh In P} → b ≋ b′ → b ≡ b′ +head (path r k) = head≡ r k +tail (path r k) i = path (tail≋ r i) k + +bisim : ∀ {In P} {b b′ : Beh In P} → b ≡ b′ → b ≋ b′ +head≡ (bisim p) k = head (p k) +tail≋ (bisim p) i = bisim (λ k → tail (p k) i) + +path-bisim : ∀ {In P} {b b′ : Beh In P} (p : b ≡ b′) → path (bisim p) ≡ p +head (path-bisim p j k) = head (p k) +tail (path-bisim p j k) i = path-bisim (λ k → tail (p k) i) j k + +bisim-path : ∀ {In P} {b b′ : Beh In P} (r : b ≋ b′) → bisim (path r) ≡ r +head≡ (bisim-path r j) = head≡ r +tail≋ (bisim-path r j) i = bisim-path (tail≋ r i) j + +-- Finality: unfold is the only map that respects head and tail. +module Final (In W : Set) (step : W → In → W) {P : Set} (see : W → P) where + + unfold : W → Beh In P + head (unfold w) = see w + tail (unfold w) i = unfold (step w i) + + module _ (h : W → Beh In P) + (hh : ∀ w → head (h w) ≡ see w) + (ht : ∀ w i → tail (h w) i ≡ h (step w i)) where + + lemma : ∀ b w → b ≡ h w → b ≋ unfold w + head≡ (lemma b w p) = cong head p ∙ hh w + tail≋ (lemma b w p) i = + lemma (tail b i) (step w i) (cong (λ x → tail x i) p ∙ ht w i) + + unique : ∀ w → h w ≡ unfold w + unique w = path (lemma (h w) w refl) + +------------------------------------------------------------------------ +-- B3. The world as one subject can know it is a type: a set quotient. + +data _/_ (A : Set) (R : A → A → Set) : Set where + [_] : A → A / R + eq/ : ∀ a b → R a b → [ a ] ≡ [ b ] + squash/ : (x y : A / R) (p q : x ≡ y) → p ≡ q + +rec : {A B : Set} {R : A → A → Set} → isSet B → + (f : A → B) → (∀ a b → R a b → f a ≡ f b) → A / R → B +rec s f e [ a ] = f a +rec s f e (eq/ a b r k) = e a b r k +rec s f e (squash/ x y p q j k) = + s (rec s f e x) (rec s f e y) + (λ k → rec s f e (p k)) (λ k → rec s f e (q k)) j k + +module Seen (In W : Set) (step : W → In → W) + {P : Set} (Pset : isSet P) (see : W → P) where + open World In W step + open View see + + Known : Set + Known = W / _~_ + + step/ : Known → In → Known + step/ x i = rec squash/ (λ w → [ step w i ]) + (λ a b e → eq/ _ _ (λ is → e (i ∷ is))) x + + see/ : Known → P + see/ = rec Pset see (λ a b e → e []) + + -- The quotient is a world again, and the experience does not change. + module K = World In Known step/ + module KV = K.View see/ + + same : ∀ w is → KV.beh [ w ] is ≡ beh w is + same w [] = refl + same w (i ∷ is) = same (step w i) is + + -- In the known world, "cannot tell apart" gives "equal". + cls : W → Known + cls = [_] + + collapse : ∀ w w′ → KV._~_ (cls w) (cls w′) → cls w ≡ cls w′ + collapse w w′ e = eq/ w w′ (λ is → sym (same w is) ∙ e is ∙ same w′ is) + +------------------------------------------------------------------------ +-- B4. "Same world" is the fibre (the Echo) of the joint view. + +fiber : {A B : Set} (f : A → B) → B → Set +fiber {A = A} f y = Σ A (λ x → f x ≡ y) + +data ∥_∥ (A : Set) : Set where + ∣_∣ : A → ∥ A ∥ + squash : (x y : ∥ A ∥) → x ≡ y + +module Two (In W : Set) (step : W → In → W) + {P₁ P₂ : Set} (see₁ : W → P₁) (see₂ : W → P₂) where + open World In W step + open View see₁ using () renaming (beh to beh₁; _~_ to _~₁_) + open View see₂ using () renaming (beh to beh₂; _~_ to _~₂_) + + both : W → (List In → P₁) × (List In → P₂) + both w = beh₁ w , beh₂ w + + SameWorld : (List In → P₁) → (List In → P₂) → Set + SameWorld b₁ b₂ = fiber both (b₁ , b₂) + + -- The mere statement. The witness (the residue) is forgotten. + MerelySameWorld : (List In → P₁) → (List In → P₂) → Set + MerelySameWorld b₁ b₂ = ∥ SameWorld b₁ b₂ ∥ + + sound : ∀ w → SameWorld (beh₁ w) (beh₂ w) + sound w = w , refl + + -- The residue is exactly the set of states that neither subject can + -- tell apart from w. + Hidden : W → Set + Hidden w = Σ W (λ w′ → (w′ ~₁ w) × (w′ ~₂ w)) + + to : ∀ {w} → SameWorld (beh₁ w) (beh₂ w) → Hidden w + to (w′ , p) = w′ , (λ is k → fst (p k) is) , (λ is k → snd (p k) is) + + from : ∀ {w} → Hidden w → SameWorld (beh₁ w) (beh₂ w) + from (w′ , e₁ , e₂) = w′ , (λ k → (λ is → e₁ is k) , (λ is → e₂ is k)) + + to-from : ∀ {w} (h : Hidden w) → to (from h) ≡ h + to-from h = refl + + from-to : ∀ {w} (s : SameWorld (beh₁ w) (beh₂ w)) → from (to s) ≡ s + from-to s = refl