@@ -101,10 +101,25 @@ getCoin-∪ˡ-overwrite acc c v =
101101 open ≡-Reasoning
102102 open Equivalence
103103 module ≡ᵉ = IsEquivalence (≡ᵉ-isEquivalence {Credential × Coin})
104- -- `∪ˡ` is `_∪ (_ ∣ dom _ ᶜ)`, and `filterᵐ` is idempotent, so dropping
105- -- the inner `∣ ❴ c ❵ ᶜ` on the right operand doesn't change the result.
104+ -- `res-decomp ❴ c , v ❵ᵐ acc` proves
105+ -- (❴ c , v ❵ᵐ ∪ˡ acc) ˢ ≡ᵉ (❴ c , v ❵ᵐ ∪ˡ (acc ∣ dom (❴ c , v ❵ᵐ ˢ) ᶜ)) ˢ
106+ -- but the bridge wants `❴ c ❵ ᶜ` on the right (a set-singleton built via
107+ -- the `listing` axiom of `Theory`), not `dom (❴ c , v ❵ᵐ ˢ) ᶜ` (built via
108+ -- `mapˢ`, i.e. the `replacement` axiom). The two restriction sets are
109+ -- extensionally equal by `dom-single≡single`, so we chain `res-decomp`
110+ -- with an `∪ˡ`-cong step on the right operand to translate the
111+ -- restriction set. ('Listing vs. replacement' is exactly what Agda's
112+ -- MismatchedProjectionsError flagged in the previous formulation.)
113+
114+ -- `_≡ᵐ_` on `Map A B` is defined as `_≡ᵉ_` on the underlying relations
115+ -- (`Map.agda`: `(x , _) ≡ᵐ (y , _) = x ≡ᵉ y`), so `res-comp-cong`
116+ -- (from `Axiom.Set.Rel`) lifts straight to the Map level.
117+ restrict-cong' : (❴ c , v ❵ᵐ ∪ˡ (acc ∣ dom (❴ c , v ❵ᵐ ˢ) ᶜ)) ˢ ≡ᵉ (❴ c , v ❵ᵐ ∪ˡ (acc ∣ ❴ c ❵ ᶜ)) ˢ
118+ restrict-cong' = ∪ˡ-cong (≡ᵉ.refl {x = ❴ c , v ❵ᵐ ˢ}) (res-comp-cong dom-single≡single)
119+
106120 bridge : (❴ c , v ❵ ∪ˡ acc) ˢ ≡ᵉ (❴ c , v ❵ ∪ˡ (acc ∣ ❴ c ❵ ᶜ)) ˢ
107- bridge = res-decomp ❴ c , v ❵ᵐ acc
121+ bridge = ≡ᵉ.trans (res-decomp ❴ c , v ❵ᵐ acc) restrict-cong'
122+
108123 disj : disjoint (dom ❴ c , v ❵ᵐ) (dom (acc ∣ ❴ c ❵ ᶜ))
109124 disj x y = res-comp-dom y (dom-single→single x)
110125```
@@ -250,8 +265,8 @@ This is the form needed by `PRE-CERT-pov`.
250265 begin
251266 getCoin rwds
252267 ≡⟨ foldl-applyOne-pov rwds (setToList (wdrls ˢ)) inv (setToList-Unique wdrls) ⟩
253- getCoin (foldl applyOne rwds (setToList (wdrls ˢ))) + sum (map proj₂ (setToList (wdrls ˢ)))
254- ≡⟨ cong (getCoin (foldl applyOne rwds (setToList (wdrls ˢ))) +_) (sum-map-proj₂≡getCoin wdrls) ⟩
268+ getCoin (foldl ( applyOne _∸_) rwds (setToList (wdrls ˢ))) + sum (map proj₂ (setToList (wdrls ˢ)))
269+ ≡⟨ cong (getCoin (foldl ( applyOne _∸_) rwds (setToList (wdrls ˢ))) +_) (sum-map-proj₂≡getCoin wdrls) ⟩
255270 getCoin (applyWithdrawals wdrls rwds) + getCoin wdrls
256271 ∎
257272 where
@@ -292,7 +307,8 @@ This is the form needed by `PRE-CERT-pov`.
292307 → (∀ {addr amt} → (addr , amt) ∈ˡ entries
293308 → stake addr ∈ dom acc × amt ≤ maybe id 0 (lookupᵐ? acc (stake addr)))
294309 → Unique (map (stake ∘ proj₁) entries) -- needed for invariant preservation
295- → getCoin acc ≡ getCoin (foldl applyOne acc entries) + sum (map proj₂ entries)
310+ → getCoin acc ≡ getCoin (foldl (applyOne _∸_) acc entries) + sum (map proj₂ entries)
311+
296312
297313 foldl-applyOne-pov acc [] _ _ = sym (+-identityʳ (indexedSumᵛ' id acc))
298314
@@ -304,7 +320,7 @@ This is the form needed by `PRE-CERT-pov`.
304320 let amt≤0 = subst (amt ≤_) (cong (maybe id 0) eq) (h (here refl) .proj₂)
305321 amt≡0 = n≤0⇒n≡0 amt≤0
306322 in -- amt ≤ maybe id 0 nothing = amt ≤ 0
307- subst (λ a → getCoin acc ≡ getCoin (foldl applyOne acc xs) + (a + sum (map proj₂ xs)))
323+ subst (λ a → getCoin acc ≡ getCoin (foldl ( applyOne _∸_) acc xs) + (a + sum (map proj₂ xs)))
308324 (sym amt≡0)
309325 (foldl-applyOne-pov acc xs (λ mem → h (there mem)) uniq-xs)
310326
@@ -314,11 +330,11 @@ This is the form needed by `PRE-CERT-pov`.
314330 ≡⟨ applyOne-pov acc addr amt bal eq amt≤bal ⟩
315331 getCoin acc' + amt
316332 ≡⟨ cong (_+ amt) (foldl-applyOne-pov acc' xs h' uniq-xs) ⟩
317- (getCoin (foldl applyOne acc' xs) + sum (map proj₂ xs)) + amt
318- ≡⟨ +-assoc (getCoin (foldl applyOne acc' xs)) (sum (map proj₂ xs)) amt ⟩
319- getCoin (foldl applyOne acc' xs) + (sum (map proj₂ xs) + amt)
320- ≡⟨ cong (getCoin (foldl applyOne acc' xs) +_) (+-comm (sum (map proj₂ xs)) amt) ⟩
321- getCoin (foldl applyOne acc' xs) + (amt + sum (map proj₂ xs))
333+ (getCoin (foldl ( applyOne _∸_) acc' xs) + sum (map proj₂ xs)) + amt
334+ ≡⟨ +-assoc (getCoin (foldl ( applyOne _∸_) acc' xs)) (sum (map proj₂ xs)) amt ⟩
335+ getCoin (foldl ( applyOne _∸_) acc' xs) + (sum (map proj₂ xs) + amt)
336+ ≡⟨ cong (getCoin (foldl ( applyOne _∸_) acc' xs) +_) (+-comm (sum (map proj₂ xs)) amt) ⟩
337+ getCoin (foldl ( applyOne _∸_) acc' xs) + (amt + sum (map proj₂ xs))
322338 ∎
323339 where
324340 c = stake addr
0 commit comments