Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions PROOF-STATUS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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 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`)
|===

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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/fetch-siblings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion src/Choreographic/All.agda
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions src/Choreographic/Instances.agda
Original file line number Diff line number Diff line change
Expand Up @@ -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
233 changes: 233 additions & 0 deletions src/Choreographic/KCutTransport.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
{-# 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 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

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)
Loading