From 4da4095aba7cd1dced1dbbd1902e0a1261084c01 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 14:34:58 +0000 Subject: [PATCH 1/2] proof(KM): transport K-CUT-LOSS along strict and lax morphisms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Owner ruling 12a. New module Choreographic.KCutTransport (A B): - KM-1 structure for any grade map: gmap commutes with cutting and projection; consistent cuts map to consistent cuts. - KM-2/KM-3 strict Hom: h (grade↾ p G) ≡ grade↾ p (gmap G); K-CUT-LOSS transports as an equality via KCut.kcut-loss in the target. - KM-4/KM-5 LaxHom + IsOrdered target: the same as a ≼ bound. Uses map-𝟙, map-⊗ (≼), exact map-⊕, ⊕-mono and ⊗-monoˡ only. - KM-6 discharged: Loss → MaxPlus strict (support-hom, zero-test-hom), HWM → MaxPlus lax (peak-lax). KM-7 worked broker: 5 vs 8. - KM-8 the 𝟘 gap: tests/reject/LaxZeroLeaf. grade never reaches 𝟘, so no side condition is needed. Re-pin resource-algebra b2c9f1f → 7ab9840 (main; brings Morphism.agda; resource-algebra#60 is unmerged). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0136P7ZpV9yCwqzui31hETLm --- PROOF-STATUS.adoc | 32 +++- scripts/fetch-siblings.sh | 2 +- src/Choreographic/All.agda | 2 +- src/Choreographic/Instances.agda | 36 +++++ src/Choreographic/KCutTransport.agda | 231 +++++++++++++++++++++++++++ tests/reject/LaxZeroLeaf.agda | 23 +++ 6 files changed, 322 insertions(+), 4 deletions(-) create mode 100644 src/Choreographic/KCutTransport.agda create mode 100644 tests/reject/LaxZeroLeaf.agda diff --git a/PROOF-STATUS.adoc b/PROOF-STATUS.adoc index e89f77a..221cc36 100644 --- a/PROOF-STATUS.adoc +++ b/PROOF-STATUS.adoc @@ -98,6 +98,33 @@ lacks `EpistemicTypes.PartialRecovery`, which `Choreographic.PartialRecovery` imports, so keep the pin at `6ce8c74`. Only steps 2 to 4 of that plan (the local integration) remain. +== K-CUT-LOSS transport along morphisms (KCutTransport.agda) + +Owner ruling 12a (2026-11-19). resource-algebra's `Morphism.agda` (pinned +`7ab9840`, resource-algebra#3) gives strict maps `Hom` (preserve 𝟘, 𝟙, ⊕, ⊗) +and lax maps `LaxHom` (preserve 𝟙 and ⊕ exactly; `h (a ⊗ b) ≼ h a ⊗ h b`). +A grade map f carries a choreography graded in A to the same choreography +graded in B (`gmap`), its cuts (`cmap`) and its local types (`lmap`). + +[cols="1,3,1",options="header"] +|=== +| ID | Claim | Status +| KM-1 | Structure, for any grade map and no algebra laws: mapping commutes with cutting (`gmap (G ↾ c) ≡ gmap G ↾ cmap c`) and with projection (`proj p (gmap G) ≡ lmap (proj p G)`), and a p-consistent cut maps to a p-consistent cut | PROVEN (`KCutTransport.gmap-cut`, `proj-gmap`, `consistent-map`) +| KM-2 | Strict: for `h : Hom A B`, `h (grade G) ≡ grade (gmap h G)` and `h (grade↾ p G) ≡ grade↾ p (gmap h G)` | PROVEN (`KCutTransport.hom-grade`, `hom-grade↾`) +| KM-3 | *Strict transport of K-CUT-LOSS*: for `h : Hom A B` and `Consistent p c`, `h (grade↾ p (G ↾ c)) ≡ lgrade (proj p (gmap G) ↾ₗ cutproj p (cmap c))`, by K-1 in B on the transported cut; and the square closes: h of A's local grade equals B's | PROVEN (`KCutTransport.kcut-loss-hom`, `kcut-square`) +| KM-4 | Lax: for `h : LaxHom A B` and `IsOrdered B`, `h (grade G) ≼ grade (gmap h G)` and `h (grade↾ p G) ≼ grade↾ p (gmap h G)`. Uses only map-𝟙, map-⊗ (≼), exact map-⊕, `⊕-mono` and `⊗-monoˡ`; the ⊗ factor passes through h exactly | PROVEN (`KCutTransport.lax-grade`, `lax-grade↾`) +| KM-5 | *Lax transport of K-CUT-LOSS*: for `h : LaxHom A B`, `IsOrdered B` and `Consistent p c`, `h (grade↾ p (G ↾ c)) ≼ lgrade (proj p (gmap G) ↾ₗ cutproj p (cmap c))`, and h of A's local grade is ≼ B's. No side condition: grade and grade↾ never reach 𝟘, so LaxHom's 𝟘 gap does not arise (KM-8) | PROVEN (`KCutTransport.kcut-loss-lax`, `kcut-square-lax`) +| KM-6 | Discharged: Loss → MaxPlus strict along both strict maps resource-algebra classifies (`support-hom`, `zero-test-hom`; its F-5); HWM → MaxPlus lax along `peak-lax` (its F-2) | PROVEN (`Instances.kcut-loss-support`, `kcut-loss-zero-test`, `kcut-loss-peak`) +| KM-7 | The lax bound is not an equality: the worked broker's occupancy peak maps to `val 5`, the summed cost of the same protocol in MaxPlus is `val 8` | TESTED (`Instances.peak-broker-mapped`, `peak-broker-target`) +| KM-8 | The 𝟘 gap: a LaxHom gives only `B.𝟘 ≼ h A.𝟘`, so the lax bound fails for a ⊕-fold over lists at the empty list (`peak-lax` sends HWM's 𝟘 to `val 0`, MaxPlus's 𝟘 is `bot`) | TESTED (`tests/reject/LaxZeroLeaf`, refused with `val … != bot`) +|=== + +Not claimed: a strict map out of HWM (resource-algebra proves none exists +into an algebra with 𝟘 ≢ 𝟙), the SHWM maps (resource-algebra#60, unmerged +at the pin), transport of the asynchronous K-CUT-LOSS (Y-2), and a K-4-style +minimal-laws certificate for KCutTransport (it imports `Morphism.agda`, +which needs the full Core). + == Asynchrony (Async.agda, AsyncKnowledge.agda, AsyncBound.agda) Ladder increment I3a, pre-registered before any proof in @@ -417,10 +444,11 @@ proof irrelevance nor choice. for swap-equivalence. Not attempted. * *Lean→Agda bridge (resource-algebra M-2).* `MaxPlus` is a port of tropical-types' Lean 4 `instance : CommSemiring Tropical`; no mechanical - link exists or is claimed. Every MaxPlus discharge above (K-6, W-6, A-2) + link exists or is claimed. Every MaxPlus discharge above (K-6, W-6, A-2, KM-6) inherits that obligation: the Lean theorem is provenance, never an import. * *Sibling pins.* resource-algebra at - `b2c9f1f6bc7ed7cc83c7573014cdf88d49d2a881`, epistemic-types at + `7ab98404fc2f6540f239f8fbd09222b659ba8d4f` (since KM, 2026-11-19, for + `Morphism.agda`; previously `b2c9f1f6`; resource-algebra#60 unmerged), epistemic-types at `6ce8c74e8a91e5021cb0c1fb4fc805bdff837178`, echo-types at `ebde9ac4e1a9f115b441c642c82aced1316c5983` (`scripts/fetch-siblings.sh`, full SHAs verified after checkout). Correction to the 2026-10-12 entry: the diff --git a/scripts/fetch-siblings.sh b/scripts/fetch-siblings.sh index 2516bae..33e3c8a 100755 --- a/scripts/fetch-siblings.sh +++ b/scripts/fetch-siblings.sh @@ -16,7 +16,7 @@ set -euo pipefail cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." -RESOURCE_ALGEBRA_COMMIT="${RESOURCE_ALGEBRA_COMMIT:-b2c9f1f6bc7ed7cc83c7573014cdf88d49d2a881}" +RESOURCE_ALGEBRA_COMMIT="${RESOURCE_ALGEBRA_COMMIT:-7ab98404fc2f6540f239f8fbd09222b659ba8d4f}" EPISTEMIC_TYPES_COMMIT="${EPISTEMIC_TYPES_COMMIT:-6ce8c74e8a91e5021cb0c1fb4fc805bdff837178}" ECHO_TYPES_COMMIT="${ECHO_TYPES_COMMIT:-ebde9ac4e1a9f115b441c642c82aced1316c5983}" DEPENDENCIES_DIR="${DEPENDENCIES_DIR:-_build/dependencies}" diff --git a/src/Choreographic/All.agda b/src/Choreographic/All.agda index 4f2be65..961f816 100644 --- a/src/Choreographic/All.agda +++ b/src/Choreographic/All.agda @@ -6,7 +6,7 @@ module Choreographic.All where import Choreographic.Party -import Choreographic.Instances -- instantiates Global/Local/Projection/KCut/Kripke/Bound/Transport +import Choreographic.Instances -- instantiates Global/Local/Projection/KCut/Kripke/Bound/Transport/KCutTransport import Choreographic.Swap -- (parametric; instantiated in Instances.Diamond) import Choreographic.Operational -- (parametric; instantiated in Instances.GradeNotStateInvariant) import Choreographic.Async -- (parametric; instantiated in Instances, with AsyncKnowledge diff --git a/src/Choreographic/Instances.agda b/src/Choreographic/Instances.agda index 89969b7..069deb9 100644 --- a/src/Choreographic/Instances.agda +++ b/src/Choreographic/Instances.agda @@ -386,3 +386,39 @@ module Acknowledgement (R : ResourceAlgebra) (a b : ResourceAlgebra.Grade R) whe -- Ledger Y-8. reply-in-flight-is-not-enough : ¬ AKnows 0 replied (λ w' → Delivered (acut w')) reply-in-flight-is-not-enough K = K unreceived refl + +---------------------------------------------------------------------- +-- K-CUT-LOSS transported along morphisms (KCutTransport.agda), at the +-- maps resource-algebra's Morphism.agda provides. +import Choreographic.KCutTransport +open import ResourceAlgebra.Morphism using (zero-test-hom; support-hom; peak-lax) + +module TLM = Choreographic.KCutTransport Loss MaxPlus +module THM = Choreographic.KCutTransport HWM MaxPlus + +-- Strict, Loss → MaxPlus: both strict maps resource-algebra classifies. +-- Ledger KM-6. +kcut-loss-support = TLM.Strict.kcut-loss-hom support-hom +-- Ledger KM-6. +kcut-loss-zero-test = TLM.Strict.kcut-loss-hom zero-test-hom + +-- Lax, HWM → MaxPlus: occupancy peak against summed cost. +-- Ledger KM-6. +kcut-loss-peak = THM.Lax.kcut-loss-lax peak-lax MaxPlus-ordered + +-- The lax bound is not an equality: for the worked broker the peak of the +-- occupancy is 5, the summed cost of the same protocol 8 (TESTED). +module _ where + open import ResourceAlgebra.Instances.HWM using (peak) + open THM.Lax peak-lax MaxPlus-ordered using (gmap) + open import Choreographic.Global HWM as GH using () + open import Choreographic.Global MaxPlus as GM using () + private module W = Worked HWM (hwm 1 0 z≤n) (hwm 2 0 z≤n) (hwm 5 0 z≤n) + + -- Ledger KM-7. + peak-broker-mapped : val (peak (GH.grade↾ 1 W.G)) ≡ val 5 + peak-broker-mapped = refl + + -- Ledger KM-7. + peak-broker-target : GM.grade↾ 1 (gmap W.G) ≡ val 8 + peak-broker-target = refl diff --git a/src/Choreographic/KCutTransport.agda b/src/Choreographic/KCutTransport.agda new file mode 100644 index 0000000..fb159de --- /dev/null +++ b/src/Choreographic/KCutTransport.agda @@ -0,0 +1,231 @@ +{-# OPTIONS --safe --without-K #-} +-- SPDX-License-Identifier: MPL-2.0 +-- SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +-- +-- K-CUT-LOSS transported along morphisms of resource algebras +-- (resource-algebra's Morphism.agda: Hom strict, LaxHom lax). +-- +-- A grade map f : A → B maps a choreography graded in A to the same +-- choreography graded in B (gmap), its cuts with it (cmap), and its local +-- types with it (lmap). The structural part needs nothing of f: mapping +-- commutes with cutting and with projection, and consistency transports. +-- +-- Then: +-- strict h (grade↾ p G) ≡ grade↾ p (gmap G), so K-CUT-LOSS holds in B +-- for the mapped protocol and the mapped A-side grade equals the +-- B-side local grade on the nose (kcut-loss-hom). +-- lax with IsOrdered B, h (grade↾ p G) ≼ grade↾ p (gmap G), so the +-- mapped A-side grade is bounded by the B-side local grade +-- (kcut-loss-lax). Uses map-𝟙, map-⊗ (≼), exact map-⊕, ⊕-mono +-- and ⊗-monoˡ only: the ⊗ factor passes through h exactly. +-- +-- The 𝟘 gap. A LaxHom need not preserve 𝟘 (only B.𝟘 ≼ h A.𝟘), so a fold +-- with a 𝟘 leaf would break the lax bound (tests/reject/LaxZeroLeaf). +-- grade and grade↾ never reach 𝟘: end and `outside` contribute 𝟙, and choice +-- is binary. So no side condition is needed here. +open import ResourceAlgebra.Core + +module Choreographic.KCutTransport (A B : ResourceAlgebra) where + +open import ResourceAlgebra.Prelude +open import ResourceAlgebra.Morphism using (Hom; LaxHom) +open import Choreographic.Party + +private + module A where + open ResourceAlgebra A public + open import Choreographic.Global A public + open import Choreographic.Local A public + open import Choreographic.Projection A public + open import Choreographic.KCut A public + module B where + open ResourceAlgebra B public + open import Choreographic.Global B public + open import Choreographic.Local B public + open import Choreographic.Projection B public + open import Choreographic.KCut B public + +---------------------------------------------------------------------- +-- (S) Structure: any grade map, no laws. +module Map (f : A.Grade → B.Grade) where + + gmap : A.Global → B.Global + gmap A.end = B.end + gmap (A.msg s r g G) = B.msg s r (f g) (gmap G) + gmap (A.choice s r g G₁ G₂) = B.choice s r (f g) (gmap G₁) (gmap G₂) + + lmap : A.Local → B.Local + lmap A.end = B.end + lmap (A.send q g L) = B.send q (f g) (lmap L) + lmap (A.recv q g L) = B.recv q (f g) (lmap L) + lmap (A.select q g L₁ L₂) = B.select q (f g) (lmap L₁) (lmap L₂) + lmap (A.branch q g L₁ L₂) = B.branch q (f g) (lmap L₁) (lmap L₂) + + cmap : ∀ {G} → A.Cut G → B.Cut (gmap G) + cmap A.stop = B.stop + cmap (A.cont-msg c) = B.cont-msg (cmap c) + cmap (A.cont-choice c₁ c₂) = B.cont-choice (cmap c₁) (cmap c₂) + + -- Ledger KM-1. + gmap-cut : ∀ G (c : A.Cut G) → gmap (G A.↾ c) ≡ (gmap G B.↾ cmap c) + gmap-cut G A.stop = refl + gmap-cut (A.msg s r g G) (A.cont-msg c) = cong (B.msg s r (f g)) (gmap-cut G c) + gmap-cut (A.choice s r g G₁ G₂) (A.cont-choice c₁ c₂) = + cong₂ (B.choice s r (f g)) (gmap-cut G₁ c₁) (gmap-cut G₂ c₂) + + proj-msg-map : ∀ {p s r} (ρ : Role p s r) g L + → B.proj-msg ρ (f g) (lmap L) ≡ lmap (A.proj-msg ρ g L) + proj-msg-map (sender _) g L = refl + proj-msg-map (receiver _ _) g L = refl + proj-msg-map (outside _ _) g L = refl + + proj-choice-map : ∀ {p s r} (ρ : Role p s r) g L₁ L₂ + → B.proj-choice ρ (f g) (lmap L₁) (lmap L₂) ≡ lmap (A.proj-choice ρ g L₁ L₂) + proj-choice-map (sender _) g L₁ L₂ = refl + proj-choice-map (receiver _ _) g L₁ L₂ = refl + proj-choice-map (outside _ _) g L₁ L₂ = refl + + -- Ledger KM-1. + proj-gmap : ∀ p G → B.proj p (gmap G) ≡ lmap (A.proj p G) + proj-gmap p A.end = refl + proj-gmap p (A.msg s r g G) = + trans (cong (B.proj-msg (role p s r) (f g)) (proj-gmap p G)) + (proj-msg-map (role p s r) g (A.proj p G)) + proj-gmap p (A.choice s r g G₁ G₂) = + trans (cong₂ (B.proj-choice (role p s r) (f g)) (proj-gmap p G₁) (proj-gmap p G₂)) + (proj-choice-map (role p s r) g (A.proj p G₁) (A.proj p G₂)) + + merge-map : ∀ p {s r} (ρ : Role p s r) G₁ G₂ + → A.Merge p ρ G₁ G₂ → B.Merge p ρ (gmap G₁) (gmap G₂) + merge-map p (sender _) G₁ G₂ m = tt + merge-map p (receiver _ _) G₁ G₂ m = tt + merge-map p (outside _ _) G₁ G₂ m = + trans (proj-gmap p G₁) (trans (cong lmap m) (sym (proj-gmap p G₂))) + + -- Ledger KM-1. + consistent-map : ∀ p {G} (c : A.Cut G) → A.Consistent p c → B.Consistent p (cmap c) + consistent-map p A.stop A.stop = B.stop + consistent-map p (A.cont-msg c) (A.cont-msg k) = B.cont-msg (consistent-map p c k) + consistent-map p (A.cont-choice {s} {r} {g} {G₁} {G₂} c₁ c₂) (A.cont-choice k₁ k₂ m) = + B.cont-choice (consistent-map p c₁ k₁) (consistent-map p c₂ k₂) + (subst₂′ (B.Merge p (role p s r)) (gmap-cut G₁ c₁) (gmap-cut G₂ c₂) + (merge-map p (role p s r) (G₁ A.↾ c₁) (G₂ A.↾ c₂) m)) + where + subst₂′ : ∀ {X : Set} (P : X → X → Set) {a b c d : X} → a ≡ b → c ≡ d → P a c → P b d + subst₂′ P refl refl x = x + +---------------------------------------------------------------------- +-- (H) Strict morphisms: equality. +module Strict (h : Hom A B) where + open Hom h + open Map map public + + at-map : ∀ {p s r} (ρ : Role p s r) g → map (A.at ρ g) ≡ B.at ρ (map g) + at-map (sender _) g = refl + at-map (receiver _ _) g = refl + at-map (outside _ _) g = map-𝟙 + + -- Ledger KM-2. + hom-grade : ∀ G → map (A.grade G) ≡ B.grade (gmap G) + hom-grade A.end = map-𝟙 + hom-grade (A.msg s r g G) = + trans (map-⊗ g (A.grade G)) (cong (map g B.⊗_) (hom-grade G)) + hom-grade (A.choice s r g G₁ G₂) = + trans (map-⊗ g (A.grade G₁ A.⊕ A.grade G₂)) + (cong (map g B.⊗_) + (trans (map-⊕ (A.grade G₁) (A.grade G₂)) + (cong₂ B._⊕_ (hom-grade G₁) (hom-grade G₂)))) + + -- Ledger KM-2. + hom-grade↾ : ∀ p G → map (A.grade↾ p G) ≡ B.grade↾ p (gmap G) + hom-grade↾ p A.end = map-𝟙 + hom-grade↾ p (A.msg s r g G) = + trans (map-⊗ (A.at (role p s r) g) (A.grade↾ p G)) + (cong₂ B._⊗_ (at-map (role p s r) g) (hom-grade↾ p G)) + hom-grade↾ p (A.choice s r g G₁ G₂) = + trans (map-⊗ (A.at (role p s r) g) (A.grade↾ p G₁ A.⊕ A.grade↾ p G₂)) + (cong₂ B._⊗_ (at-map (role p s r) g) + (trans (map-⊕ (A.grade↾ p G₁) (A.grade↾ p G₂)) + (cong₂ B._⊕_ (hom-grade↾ p G₁) (hom-grade↾ p G₂)))) + + -- Strict transport of K-CUT-LOSS: the A-side restricted grade at the cut, + -- mapped, is the B-side local grade of the mapped protocol at the mapped + -- cut. K-CUT-LOSS is used in B, on the transported consistent cut. + -- Ledger KM-3. + kcut-loss-hom : ∀ p G (c : A.Cut G) → A.Consistent p c + → map (A.grade↾ p (G A.↾ c)) ≡ B.lgrade (B.proj p (gmap G) B.↾ₗ B.cutproj p (cmap c)) + kcut-loss-hom p G c k = + trans (hom-grade↾ p (G A.↾ c)) + (trans (cong (B.grade↾ p) (gmap-cut G c)) + (B.kcut-loss p (gmap G) (cmap c) (consistent-map p c k))) + + -- The square: K-CUT-LOSS in A, mapped, agrees with K-CUT-LOSS in B. + -- Ledger KM-3. + kcut-square : ∀ p G (c : A.Cut G) → A.Consistent p c + → map (A.lgrade (A.proj p G A.↾ₗ A.cutproj p c)) + ≡ B.lgrade (B.proj p (gmap G) B.↾ₗ B.cutproj p (cmap c)) + kcut-square p G c k = + trans (cong map (sym (A.kcut-loss p G c k))) (kcut-loss-hom p G c k) + +---------------------------------------------------------------------- +-- (L) Lax morphisms: a bound, given ⊗ monotone (in its second argument) +-- in the target. +module Lax (h : LaxHom A B) (o : IsOrdered B) where + open LaxHom h + open Map map public + + private + ≡-≼ : ∀ {x y z} → x ≡ y → y B.≼ z → x B.≼ z + ≡-≼ refl q = q + + ≼-≡ : ∀ {x y z} → x B.≼ y → y ≡ z → x B.≼ z + ≼-≡ q refl = q + + -- One ⊗ node: the factor passes exactly when its image is known. + step : ∀ a b {a' y} → map a ≡ a' → map b B.≼ y → map (a A.⊗ b) B.≼ (a' B.⊗ y) + step a b refl q = B.≼-trans (map-⊗ a b) (IsOrdered.⊗-monoˡ o (map a) q) + + -- One ⊕ node: exact, then monotone. + alt : ∀ a b {x y} → map a B.≼ x → map b B.≼ y → map (a A.⊕ b) B.≼ (x B.⊕ y) + alt a b p q = ≡-≼ (map-⊕ a b) (B.⊕-mono p q) + + at-map : ∀ {p s r} (ρ : Role p s r) g → map (A.at ρ g) ≡ B.at ρ (map g) + at-map (sender _) g = refl + at-map (receiver _ _) g = refl + at-map (outside _ _) g = map-𝟙 + + -- Ledger KM-4. + lax-grade : ∀ G → map (A.grade G) B.≼ B.grade (gmap G) + lax-grade A.end = ≡-≼ map-𝟙 (B.≼-refl B.𝟙) + lax-grade (A.msg s r g G) = step g (A.grade G) refl (lax-grade G) + lax-grade (A.choice s r g G₁ G₂) = + step g (A.grade G₁ A.⊕ A.grade G₂) refl + (alt (A.grade G₁) (A.grade G₂) (lax-grade G₁) (lax-grade G₂)) + + -- Ledger KM-4. + lax-grade↾ : ∀ p G → map (A.grade↾ p G) B.≼ B.grade↾ p (gmap G) + lax-grade↾ p A.end = ≡-≼ map-𝟙 (B.≼-refl B.𝟙) + lax-grade↾ p (A.msg s r g G) = + step (A.at (role p s r) g) (A.grade↾ p G) (at-map (role p s r) g) (lax-grade↾ p G) + lax-grade↾ p (A.choice s r g G₁ G₂) = + step (A.at (role p s r) g) (A.grade↾ p G₁ A.⊕ A.grade↾ p G₂) (at-map (role p s r) g) + (alt (A.grade↾ p G₁) (A.grade↾ p G₂) (lax-grade↾ p G₁) (lax-grade↾ p G₂)) + + -- Lax transport of K-CUT-LOSS: the A-side restricted grade at the cut, + -- mapped, is at most the B-side local grade of the mapped protocol at + -- the mapped cut. + -- Ledger KM-5. + kcut-loss-lax : ∀ p G (c : A.Cut G) → A.Consistent p c + → map (A.grade↾ p (G A.↾ c)) B.≼ B.lgrade (B.proj p (gmap G) B.↾ₗ B.cutproj p (cmap c)) + kcut-loss-lax p G c k = + ≼-≡ (lax-grade↾ p (G A.↾ c)) + (trans (cong (B.grade↾ p) (gmap-cut G c)) + (B.kcut-loss p (gmap G) (cmap c) (consistent-map p c k))) + + -- The lax square: K-CUT-LOSS in A, mapped, is bounded by K-CUT-LOSS in B. + -- Ledger KM-5. + kcut-square-lax : ∀ p G (c : A.Cut G) → A.Consistent p c + → map (A.lgrade (A.proj p G A.↾ₗ A.cutproj p c)) + B.≼ B.lgrade (B.proj p (gmap G) B.↾ₗ B.cutproj p (cmap c)) + kcut-square-lax p G c k = + ≡-≼ (cong map (sym (A.kcut-loss p G c k))) (kcut-loss-lax p G c k) diff --git a/tests/reject/LaxZeroLeaf.agda b/tests/reject/LaxZeroLeaf.agda new file mode 100644 index 0000000..b227e11 --- /dev/null +++ b/tests/reject/LaxZeroLeaf.agda @@ -0,0 +1,23 @@ +{-# OPTIONS --safe --without-K #-} +-- SPDX-License-Identifier: MPL-2.0 +-- SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +-- Ledger KM-8. +module LaxZeroLeaf where +open import ResourceAlgebra.Prelude +open import ResourceAlgebra.Core +open import ResourceAlgebra.Instances.HWM using (HWM) +open import ResourceAlgebra.Instances.MaxPlus using (MaxPlus) +open import ResourceAlgebra.Morphism using (LaxHom; peak-lax) +open import Agda.Builtin.List using (List; []; _∷_) + +-- Must fail: the lax bound h (fold xs) ≼ fold (map h xs) does NOT hold for a +-- ⊕-fold over lists, whose empty case is 𝟘. A LaxHom gives only +-- B.𝟘 ≼ h A.𝟘, the opposite direction: peak-lax sends HWM's 𝟘 (its 𝟙, +-- peak 0) to val 0, while MaxPlus's 𝟘 is bot. KCutTransport needs no side +-- condition because grade and grade↾ never reach 𝟘. +altFold : (R : ResourceAlgebra) → List (ResourceAlgebra.Grade R) → ResourceAlgebra.Grade R +altFold R [] = ResourceAlgebra.𝟘 R +altFold R (x ∷ xs) = ResourceAlgebra._⊕_ R x (altFold R xs) + +invalid : ResourceAlgebra._≼_ MaxPlus (LaxHom.map peak-lax (altFold HWM [])) (altFold MaxPlus []) +invalid = refl From e53cd4ffdbc1a64157d8e7b874dce17eb47ee9eb Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 14:42:56 +0000 Subject: [PATCH 2/2] =?UTF-8?q?docs(KM):=20state=20the=20absence=20of=20a?= =?UTF-8?q?=20=F0=9D=9F=98=20base=20case,=20not=20of=20=F0=9D=9F=98=20resu?= =?UTF-8?q?lts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CodeRabbit on #48: in HWM 𝟘 ≡ 𝟙, so grade end is 𝟘 there. The lax proof needs only that no fold has a 𝟘 base case; it uses map-𝟙, never map-𝟘. Comments and PROOF-STATUS KM-5 only. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0136P7ZpV9yCwqzui31hETLm --- PROOF-STATUS.adoc | 2 +- src/Choreographic/KCutTransport.agda | 6 ++++-- tests/reject/LaxZeroLeaf.agda | 5 ++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/PROOF-STATUS.adoc b/PROOF-STATUS.adoc index 221cc36..630a01e 100644 --- a/PROOF-STATUS.adoc +++ b/PROOF-STATUS.adoc @@ -113,7 +113,7 @@ graded in B (`gmap`), its cuts (`cmap`) and its local types (`lmap`). | KM-2 | Strict: for `h : Hom A B`, `h (grade G) ≡ grade (gmap h G)` and `h (grade↾ p G) ≡ grade↾ p (gmap h G)` | PROVEN (`KCutTransport.hom-grade`, `hom-grade↾`) | KM-3 | *Strict transport of K-CUT-LOSS*: for `h : Hom A B` and `Consistent p c`, `h (grade↾ p (G ↾ c)) ≡ lgrade (proj p (gmap G) ↾ₗ cutproj p (cmap c))`, by K-1 in B on the transported cut; and the square closes: h of A's local grade equals B's | PROVEN (`KCutTransport.kcut-loss-hom`, `kcut-square`) | KM-4 | Lax: for `h : LaxHom A B` and `IsOrdered B`, `h (grade G) ≼ grade (gmap h G)` and `h (grade↾ p G) ≼ grade↾ p (gmap h G)`. Uses only map-𝟙, map-⊗ (≼), exact map-⊕, `⊕-mono` and `⊗-monoˡ`; the ⊗ factor passes through h exactly | PROVEN (`KCutTransport.lax-grade`, `lax-grade↾`) -| KM-5 | *Lax transport of K-CUT-LOSS*: for `h : LaxHom A B`, `IsOrdered B` and `Consistent p c`, `h (grade↾ p (G ↾ c)) ≼ lgrade (proj p (gmap G) ↾ₗ cutproj p (cmap c))`, and h of A's local grade is ≼ B's. No side condition: grade and grade↾ never reach 𝟘, so LaxHom's 𝟘 gap does not arise (KM-8) | PROVEN (`KCutTransport.kcut-loss-lax`, `kcut-square-lax`) +| KM-5 | *Lax transport of K-CUT-LOSS*: for `h : LaxHom A B`, `IsOrdered B` and `Consistent p c`, `h (grade↾ p (G ↾ c)) ≼ lgrade (proj p (gmap G) ↾ₗ cutproj p (cmap c))`, and h of A's local grade is ≼ B's. No side condition: grade and grade↾ never use 𝟘 as a base case (end and `outside` give 𝟙, choice is binary), so the lax proof never needs map-𝟘 and LaxHom's 𝟘 gap (KM-8) does not arise. In an algebra where 𝟘 ≡ 𝟙, such as HWM, a grade can equal 𝟘; the bound still holds because the step uses map-𝟙, not map-𝟘 | PROVEN (`KCutTransport.kcut-loss-lax`, `kcut-square-lax`) | KM-6 | Discharged: Loss → MaxPlus strict along both strict maps resource-algebra classifies (`support-hom`, `zero-test-hom`; its F-5); HWM → MaxPlus lax along `peak-lax` (its F-2) | PROVEN (`Instances.kcut-loss-support`, `kcut-loss-zero-test`, `kcut-loss-peak`) | KM-7 | The lax bound is not an equality: the worked broker's occupancy peak maps to `val 5`, the summed cost of the same protocol in MaxPlus is `val 8` | TESTED (`Instances.peak-broker-mapped`, `peak-broker-target`) | KM-8 | The 𝟘 gap: a LaxHom gives only `B.𝟘 ≼ h A.𝟘`, so the lax bound fails for a ⊕-fold over lists at the empty list (`peak-lax` sends HWM's 𝟘 to `val 0`, MaxPlus's 𝟘 is `bot`) | TESTED (`tests/reject/LaxZeroLeaf`, refused with `val … != bot`) diff --git a/src/Choreographic/KCutTransport.agda b/src/Choreographic/KCutTransport.agda index fb159de..949e6e3 100644 --- a/src/Choreographic/KCutTransport.agda +++ b/src/Choreographic/KCutTransport.agda @@ -21,8 +21,10 @@ -- -- The 𝟘 gap. A LaxHom need not preserve 𝟘 (only B.𝟘 ≼ h A.𝟘), so a fold -- with a 𝟘 leaf would break the lax bound (tests/reject/LaxZeroLeaf). --- grade and grade↾ never reach 𝟘: end and `outside` contribute 𝟙, and choice --- is binary. So no side condition is needed here. +-- grade and grade↾ never use 𝟘 as a base case: end and `outside` give 𝟙 and +-- choice is binary, so the lax proof never needs map-𝟘. (In an algebra where +-- 𝟘 ≡ 𝟙, such as HWM, a grade can equal 𝟘; the bound still holds because the +-- step uses map-𝟙, not map-𝟘.) So no 𝟘 side condition is needed here. open import ResourceAlgebra.Core module Choreographic.KCutTransport (A B : ResourceAlgebra) where diff --git a/tests/reject/LaxZeroLeaf.agda b/tests/reject/LaxZeroLeaf.agda index b227e11..8995622 100644 --- a/tests/reject/LaxZeroLeaf.agda +++ b/tests/reject/LaxZeroLeaf.agda @@ -14,7 +14,10 @@ open import Agda.Builtin.List using (List; []; _∷_) -- ⊕-fold over lists, whose empty case is 𝟘. A LaxHom gives only -- B.𝟘 ≼ h A.𝟘, the opposite direction: peak-lax sends HWM's 𝟘 (its 𝟙, -- peak 0) to val 0, while MaxPlus's 𝟘 is bot. KCutTransport needs no side --- condition because grade and grade↾ never reach 𝟘. +-- condition because grade and grade↾ never use 𝟘 as a base case: end and +-- `outside` give 𝟙 and choice is binary, so the lax proof never needs map-𝟘. +-- (In HWM, where 𝟘 ≡ 𝟙, a grade can equal 𝟘; the bound still holds because +-- the step uses map-𝟙, not map-𝟘.) altFold : (R : ResourceAlgebra) → List (ResourceAlgebra.Grade R) → ResourceAlgebra.Grade R altFold R [] = ResourceAlgebra.𝟘 R altFold R (x ∷ xs) = ResourceAlgebra._⊕_ R x (altFold R xs)