Skip to content

Commit 11c8ec1

Browse files
committed
temporarily committing old stuff before rebase
1 parent 7991a40 commit 11c8ec1

3 files changed

Lines changed: 79 additions & 22 deletions

File tree

src/Ledger/Dijkstra/Specification/Ledger/Properties/PoV.lagda.md

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ intermediate stage of the main chain.
118118
To close, add `Σ directDeps_i` to both sides of the goal (eliminated at the end via
119119
`+-cancelʳ-≡`):
120120

121-
(U₀ + R₀ + D₀) + Σ directDeps_i
121+
U₀ + R₀ + D₀ + Σ directDeps_i
122122
≡ U₀ + (R₀ + Σ directDeps_i) + D₀
123123
≡ U₀ + (R₂ + Σ wdrls_i) + D₀ by (2)
124124
≡ U₀ + Σ wdrls_i + D₀ + R₂ (rearrange)
125125
≡ U₂ + Σ directDeps_i + D₂ + R₂ by (★)
126-
(U₂ + R₂ + D₂) + Σ directDeps_i (rearrange)
126+
≡ U₂ + R₂ + D₂ + Σ directDeps_i (rearrange)
127127

128128

129129
### `LEDGER-I` proof outline
@@ -163,9 +163,6 @@ module _
163163
164164
( split-balance : ∀ (u : UTxO) (keys : ℙ TxIn) → cbalance u ≡ cbalance (u ∣ keys ᶜ) + cbalance (u ∣ keys) )
165165
166-
-- New CIP-159 assumption (forwarded to Certs-Pov-lemmas): see PoVLemmas.
167-
( indexedSumᵛ'-∪⁺ : ∀ (m m' : Rewards) → getCoin (m ∪⁺ m') ≡ getCoin m + getCoin m' )
168-
169166
-- Per-step SUBUTXOW coin equation. Assumed for now; a local proof
170167
-- would require, in addition to `balance-∪` and `split-balance`, a
171168
-- batch-wide "spend inputs preserved" invariant (the running UTxO
@@ -201,26 +198,35 @@ module _
201198
→ subΓ ⊢ s ⇀⦇ SubTransactionsOf tx ,SUBLEDGERS⦈ ⟦ utxoSt₁ , govSt₁ , certState₁ ⟧ˡ
202199
→ TxIdOf tx ∉ mapˢ proj₁ (dom (UTxOOf utxoSt₁)) )
203200
204-
-- Deposit-change posPart/negPart identity. Provable from the definition
205-
-- of `calculateDepositsChange` and the standard
206-
-- `y + posPart (x - y) ≡ x + negPart (x - y)` lemma (per-component, then
207-
-- composed across top and sub). Deferred to the follow-up PR.
208-
( posNeg-deposits : (cs₀ cs₁ cs₂ : CertState)
209-
→ let dc = calculateDepositsChange cs₀ cs₁ cs₂ in
210-
coinFromDeposits cs₀ + posPart (DepositsChangeTopOf dc) + posPart (DepositsChangeSubOf dc)
211-
≡ coinFromDeposits cs₂ + negPart (DepositsChangeTopOf dc) + negPart (DepositsChangeSubOf dc) )
212-
213-
-- Sum distribution (standard list algebra):
214-
( sum-map-+ : ∀ {A : Type} (f g : A → ℕ) (xs : List A)
215-
→ sum (map (λ x → f x + g x) xs) ≡ sum (map f xs) + sum (map g xs) )
216-
217201
where
218-
open Certs-PoV ∪ˡ-res-lookup-preserve sum-map-proj₂≡getCoin setToList-Unique indexedSumᵛ'-∪⁺
202+
open Certs-PoV ∪ˡ-res-lookup-preserve sum-map-proj₂≡getCoin setToList-Unique
219203
-- Note: The `λ {u}{u'} →` η-wrapper may be needed for Agda eta-expansion issue.
220204
221205
open UTXOW-PoV tx (λ {u} {u'} → balance-∪ {u} {u'}) split-balance noMintTx noMintSubTx (λ {u} → outs-disjoint {u})
222206
open ≡-Reasoning
223207
208+
posNeg-deposits : (cs₀ cs₁ cs₂ : CertState)
209+
→ let dc = calculateDepositsChange cs₀ cs₁ cs₂ in
210+
coinFromDeposits cs₀ + posPart (DepositsChangeTopOf dc) + posPart (DepositsChangeSubOf dc)
211+
≡ coinFromDeposits cs₂ + negPart (DepositsChangeTopOf dc) + negPart (DepositsChangeSubOf dc)
212+
posNeg-deposits cs₀ cs₁ cs₂ = begin
213+
coin₀ + pt + psp ≡⟨ swap-right coin₀ pt psp ⟩
214+
coin₀ + psp + pt ≡⟨ cong (_+ pt) (posPart-negPart-sym coin₁ coin₀) ⟩
215+
coin₁ + ns + pt ≡⟨ swap-right coin₁ ns pt ⟩
216+
coin₁ + pt + ns ≡⟨ cong (_+ ns) (posPart-negPart-sym coin₂ coin₁) ⟩
217+
coin₂ + nt + ns ∎
218+
where
219+
open ≡-Reasoning
220+
coin₀ = coinFromDeposits cs₀
221+
coin₁ = coinFromDeposits cs₁
222+
coin₂ = coinFromDeposits cs₂
223+
psp = posPart (coin₁ ⊖ coin₀) -- DepositsChangeSubOf dc
224+
ns = negPart (coin₁ ⊖ coin₀)
225+
pt = posPart (coin₂ ⊖ coin₁) -- DepositsChangeTopOf dc
226+
nt = negPart (coin₂ ⊖ coin₁)
227+
swap-right : ∀ a b c → a + b + c ≡ a + c + b
228+
swap-right a b c = trans (+-assoc a b c) (trans (cong (a +_) (+-comm b c)) (sym (+-assoc a c b)))
229+
224230
-- Per-sub-tx withdrawal totals.
225231
wdrwl : SubLevelTx → Coin
226232
wdrwl = getCoin ∘ WithdrawalsOf
@@ -334,7 +340,7 @@ module _
334340
-- Sub-level CERTS-pov (NEW signature: dd on LHS, wdrl on RHS).
335341
sub-certs : getCoin (CertStateOf s₀) + getCoin (DirectDepositsOf stx)
336342
≡ getCoin (CertStateOf s₁) + getCoin (WithdrawalsOf stx)
337-
sub-certs = CERTS-pov (extract-subutxo-netId subutxowStep) certsStep
343+
sub-certs = ? -- CERTS-pov (extract-subutxo-netId subutxowStep) certsStep
338344
339345
-- IH: same form as the outer goal, just one element shorter.
340346
ih : getCoin (CertStateOf s₁) + sum (map ddwl sigs)

src/Ledger/Prelude.lagda.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ open import Data.Integer using (0ℤ) public
5959
import Data.Rational as ℚ
6060
open import Data.Rational using (ℚ)
6161
62-
open import Data.Nat.Properties using (+-identityʳ)
62+
open import Data.Nat.Properties using (+-identityʳ; +-comm; +-assoc)
6363
6464
6565
dec-de-morgan : ∀{P Q : Type} → ⦃ P ⁇ ⦄ → ¬ (P × Q) → ¬ P ⊎ ¬ Q
@@ -115,6 +115,17 @@ indexedSumL-proj₂-zero ((a , v) ∷ xs) all-zero =
115115
trans (cong (_+ indexedSumL proj₂ xs) (all-zero (Prelude.Init.here refl)))
116116
(indexedSumL-proj₂-zero xs (all-zero ∘ Prelude.Init.there))
117117
118+
119+
+-interleave : {a b c d : ℕ} → a + b + (c + d) ≡ a + c + (b + d)
120+
+-interleave {a}{b}{c}{d} = begin
121+
a + b + (c + d) ≡⟨ +-assoc a b (c + d) ⟩
122+
a + (b + (c + d)) ≡⟨ cong (a +_) (sym (+-assoc b c d)) ⟩
123+
a + (b + c + d) ≡⟨ cong (λ y → a + (y + d)) (+-comm b c) ⟩
124+
a + (c + b + d) ≡⟨ cong (a +_) (+-assoc c b d) ⟩
125+
a + (c + (b + d)) ≡⟨ sym (+-assoc a c (b + d)) ⟩
126+
a + c + (b + d) ∎
127+
where open ≡-Reasoning
128+
118129
module _ {A : Type} ⦃ _ : DecEq A ⦄ where
119130
120131
getCoin-singleton : {(a , c) : A × Coin} → indexedSumᵛ' id ❴ (a , c) ❵ ≡ c
@@ -154,6 +165,16 @@ module _ {A : Type} ⦃ _ : DecEq A ⦄ where
154165
... | yes a∈dom = ∪ˡsingleton∈dom m a∈dom
155166
... | no a∉dom = trans (∪ˡsingleton∉dom m a∉dom) (+-identityʳ (getCoin m))
156167
168+
sum-map-+ : ∀ {A : Type} (f g : A → ℕ) (xs : List A)
169+
→ sum (map (λ x → f x + g x) xs) ≡ sum (map f xs) + sum (map g xs)
170+
sum-map-+ _ _ [] = refl
171+
sum-map-+ f g (x ∷ xs) =
172+
begin
173+
f x + g x + sum (map (λ x → f x + g x) xs) ≡⟨ cong (f x + g x +_) (sum-map-+ f g xs) ⟩
174+
f x + g x + (sum (map f xs) + sum (map g xs)) ≡⟨ +-interleave {f x} ⟩
175+
f x + sum (map f xs) + (g x + sum (map g xs)) ∎
176+
where open ≡-Reasoning
177+
157178
opaque
158179
unfolding List-Model finiteness
159180

src/Prelude.lagda.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,13 @@ instance
103103
~? {A} {x} {y} ⦃ deqEq ⦄ = ⁇ (connected? (DecEq._≟_ deqEq) x y)
104104
105105
-- Positive and negative part of integers
106-
open import Data.Integer using (sign; ∣_∣; _⊖_)
106+
open import Data.Integer using (_⊖_) public
107+
open import Data.Integer using (sign; ∣_∣)
107108
open import Data.Integer.Properties using ([1+m]⊖[1+n]≡m⊖n)
108109
open import Data.Sign using (Sign)
109110
111+
open import Data.Nat.Properties using (m+[n∸m]≡n; m≤n⇒m∸n≡0; ≤-total; +-identityʳ)
112+
110113
posPart : ℤ → ℕ
111114
posPart x with sign x
112115
... | Sign.+ = ∣ x ∣
@@ -123,6 +126,33 @@ negPart x with sign x
123126
∸≡posPart⊖ {ℕ.suc m} {zero} = _≡_.refl
124127
∸≡posPart⊖ {ℕ.suc m} {ℕ.suc n} = trans (∸≡posPart⊖{m}{n}) (sym (cong posPart (([1+m]⊖[1+n]≡m⊖n m n))))
125128
129+
∸≡negPart⊖ : {m n : ℕ} → (n ∸ m) ≡ negPart (m ⊖ n)
130+
∸≡negPart⊖ {zero} {zero} = refl
131+
∸≡negPart⊖ {zero} {ℕ.suc n} = refl
132+
∸≡negPart⊖ {ℕ.suc m} {zero} = refl
133+
∸≡negPart⊖ {ℕ.suc m} {ℕ.suc n} =
134+
trans (∸≡negPart⊖ {m} {n})
135+
(sym (cong negPart ([1+m]⊖[1+n]≡m⊖n m n)))
136+
137+
+∸≡∸+ : (a b : ℕ) → a +ℕ (b ∸ a) ≡ b +ℕ (a ∸ b)
138+
+∸≡∸+ a b with ≤-total a b
139+
... | inj₁ a≤b =
140+
trans (m+[n∸m]≡n a≤b)
141+
(sym (trans (cong (b +ℕ_) (m≤n⇒m∸n≡0 a≤b)) (+-identityʳ b)))
142+
... | inj₂ b≤a =
143+
trans (cong (a +ℕ_) (m≤n⇒m∸n≡0 b≤a))
144+
(trans (+-identityʳ a) (sym (m+[n∸m]≡n b≤a)))
145+
146+
-- y + posPart (x ⊖ y) ≡ x + negPart (x ⊖ y)
147+
posPart-negPart-sym : ∀ x y → y +ℕ posPart (x ⊖ y) ≡ x +ℕ negPart (x ⊖ y)
148+
posPart-negPart-sym x y = let _+_ = _+ℕ_ in
149+
begin
150+
y + posPart (x ⊖ y) ≡⟨ cong (y +_) (sym (∸≡posPart⊖ {x} {y})) ⟩
151+
y + (x ∸ y) ≡⟨ +∸≡∸+ y x ⟩
152+
x + (y ∸ x) ≡⟨ cong (x +_) (∸≡negPart⊖ {x} {y}) ⟩
153+
x + negPart (x ⊖ y) ∎
154+
where open ≡-Reasoning
155+
126156
instance
127157
Dec-NonZero : ∀ {n} → NonZero n ⁇
128158
Dec-NonZero {zero} .dec = no λ ()

0 commit comments

Comments
 (0)