Proof wording for appointment

Consider the following code from assignment. The goal here is to prove that account transactions are commutative. From what I understand, there are two accounts e1 {cash 10} and e2 {cash 20}. So if I do a transaction on e1 giving 10 and then on e2 giving 10 and then I do it in reverse, then at the end the account state is the same. To do this, I have to prove that the account states between them are equivalent. as account status [e1 {10} e2 {20}] β†’ [e1 {0} e2 {20}] β†’ [e1 {0} e2 {10}] and [e1 {10} e2 {20}] β†’ [e1 {10} e2 {10}] β†’ [e1 {0} e2 {10}], i.e. the states in between lead to the same state. Am I correct? How to formulate this? At first glance, this looked trivial, but it is not that simple.

module Acc where

open import Data.Nat hiding (_β‰Ÿ_; _+_; _≀_)
open import Data.Integer hiding (_β‰Ÿ_; suc)
open import Data.String
open import Data.Product
open import Relation.Nullary
open import Relation.Nullary.Decidable
open import Relation.Binary.PropositionalEquality

-- Trivial example of an EDSL inspired by
-- http://www.lpenz.org/articles/hedsl-sharedexpenses/

-- We have n people who go on a trip
-- they pay for things
-- they give each other money
-- at the end we want to have the balance on each account

-- Syntax

infixr 10 _β€’_
infixr 10 _and_
infix 20 _β‡’_

data Person : Set where
  P : String β†’ Person

data Exp : Set where
  _β‡’_ : Person β†’ β„• β†’ Exp
  _[_]β‡’_ : Person β†’ β„• β†’ Person β†’ Exp
  _and_ : Exp β†’ Exp β†’ Exp


data Accounts : Set where
  β–‘   : Accounts
  _,_ : (String Γ— β„€) β†’ Accounts β†’ Accounts

data _∈ᡣ_ : (String Γ— β„€) β†’ Accounts β†’ Set where
  hereα΅£ : βˆ€ {ρ s v} β†’ (s , v) ∈ᡣ ((s , v) , ρ)
  skipα΅£ : βˆ€ {ρ s v s' v'} β†’
     {Ξ± : False (s β‰Ÿ s')} β†’ (s , v) ∈ᡣ ρ β†’ (s , v) ∈ᡣ ((s' , v') , ρ)

update : Accounts β†’ String β†’ β„€ β†’ Accounts
update β–‘ s amount = (s , amount) , β–‘
update ((s₁ , amount₁) , accounts) sβ‚‚ amountβ‚‚ with (s₁ β‰Ÿ sβ‚‚)
... | yes _ = (s₁ , (amount₁ + amountβ‚‚)) , accounts 
... | no _ = (s₁ , amount₁) , update accounts sβ‚‚ amountβ‚‚ 

data account : Exp β†’ Accounts β†’ Accounts β†’ Set where
  spend : βˆ€ {s n Οƒ} β†’ account (P s β‡’ (suc n)) Οƒ (update Οƒ s -[1+ n ])
  give : βˆ€ {s₁ sβ‚‚ n Οƒ} β†’ account (P s₁ [ suc n ]β‡’ P sβ‚‚) Οƒ
  (update (update Οƒ s₁ -[1+ n ]) sβ‚‚ (+ (suc n)))
  _β€’_ : βˆ€ {e₁ eβ‚‚ σ₁ Οƒβ‚‚ σ₃} β†’
account e₁ σ₁ Οƒβ‚‚ β†’ account eβ‚‚ Οƒβ‚‚ σ₃ β†’ account (e₁ and eβ‚‚) σ₁ σ₃

andComm : βˆ€ {Οƒ Οƒ' Οƒ'' e₁ eβ‚‚} β†’ account (e₁ and eβ‚‚) Οƒ Οƒ' β†’
      account (eβ‚‚ and e₁) Οƒ Οƒ'' β†’ Οƒ' ≑ Οƒ''
andComm (a₁ β€’ a) (b β€’ b₁) = {!!}

      

+3


source to share





All Articles