A framework for executable UC specifications.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

World.agda 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. module Yggdrasil.World where
  2. open import Data.Bool using (Bool; T)
  3. open import Data.List using (List; _∷_; []; map; _++_; length; lookup)
  4. open import Data.List.Any using (here; there)
  5. open import Data.List.Membership.Propositional using (_∈_)
  6. open import Data.Fin using (Fin)
  7. open import Data.Maybe using (Maybe; just; nothing) renaming (map to mmap)
  8. open import Data.Nat using (ℕ; suc)
  9. open import Data.Product as Π using (_×_; ∃; ∃-syntax; proj₁; proj₂; map₂) renaming (_,_ to ⟨_,_⟩)
  10. open import Data.String using (String)
  11. import Data.String.Unsafe as S
  12. open import Function using (id)
  13. open import Level using (Level; _⊔_; Lift) renaming (suc to lsuc; zero to lzero)
  14. open import Relation.Binary.PropositionalEquality using (_≡_; _≢_; refl)
  15. open import Relation.Nullary using (Dec; yes; no)
  16. -- Auto-lifted variant of ⊤.
  17. data ⊤ {ℓ : Level} : Set ℓ where
  18. tt : ⊤
  19. Table : ∀ {ℓ} → Set ℓ → Set ℓ
  20. Table A = List (String × A)
  21. _∪_ : ∀ {ℓ A} → Table {ℓ} A → Table {ℓ} A → Table {ℓ} A
  22. _∪_ = _++_
  23. module Weak where
  24. record WeakState {ℓ : Level} : Set (lsuc ℓ)
  25. record WeakTransition {ℓ : Level} (n : ℕ) : Set (lsuc ℓ) where
  26. inductive
  27. field
  28. A : Set ℓ
  29. B : A → Set ℓ
  30. Σ : A → Fin n
  31. record WeakState {ℓ} where
  32. inductive
  33. field
  34. states : List (Set ℓ)
  35. current : Fin (length states)
  36. δ↑ : Fin (length states) → Table (WeakTransition {ℓ} (length states))
  37. δ↓ : Fin (length states) → Table (WeakTransition {ℓ} (length states))
  38. open Weak using (WeakState; WeakTransition)
  39. open WeakState
  40. record State {ℓ : Level} (Σʷ : WeakState {ℓ}) : Set (lsuc ℓ)
  41. data Action {ℓ : Level} : {Σʷ₁ Σʷ₂ : WeakState {ℓ}} →
  42. (Σ₁ : Fin (length (states Σʷ₁))) →
  43. (Σ₂ : State Σʷ₂) → Set ℓ → Set (lsuc ℓ)
  44. Transition↑ : {ℓ : Level} {Σʷ : WeakState {ℓ}} →
  45. (Σ₁ : Fin (length (states Σʷ))) → WeakTransition {ℓ} (length (states Σʷ)) →
  46. Set (lsuc ℓ)
  47. Transition↑ {Σʷ = Σʷ} Σ₁ T = (x : A T) → Π.Σ
  48. (State (record Σʷ { current = Σ T x }))
  49. (λ Σ₂ → Action {Σʷ₁ = Σʷ} Σ₁ Σ₂ (B T x))
  50. where open WeakTransition using (A; B; Σ)
  51. Transition↓ : {ℓ : Level} {Σʷ : WeakState {ℓ}} →
  52. WeakTransition {ℓ} (length (states Σʷ)) → Set ℓ
  53. Transition↓ {Σʷ = Σʷ} T = (x : A T) → Π.Σ (Fin (length (states Σʷ)))
  54. (λ n → lookup (states Σʷ) n)
  55. where open WeakTransition using (A; Σ)
  56. --data Transitions↑ {ℓ : Level} (Σ : Π.Σ (Set ℓ) id) :
  57. -- Table (WeakTransition {ℓ}) → Set (lsuc ℓ) where
  58. -- [] : Transitions↑ Σ []
  59. -- _∷_ : ∀ {Σʷ T Ts name} → Transition↑ {Σʷ = Σʷ} Σ T → Transitions↑ Σ Ts →
  60. -- Transitions↑ Σ (⟨ name , T ⟩ ∷ Ts)
  61. --
  62. --data Transitions↓ {ℓ : Level} :
  63. -- Table (WeakTransition {ℓ}) → Set (lsuc ℓ) where
  64. -- [] : Transitions↓ []
  65. -- _∷_ : ∀ {T Ts name} → Transition↓ T → Transitions↓ Ts →
  66. -- Transitions↓ (⟨ name , T ⟩ ∷ Ts)
  67. --
  68. record State {ℓ} Σʷ where
  69. open WeakState
  70. field
  71. n : Fin (length (states Σʷ))
  72. σ : lookup (states Σʷ) n
  73. -- δ↑ : Transitions↑ ⟨ Σ , σ ⟩ (WeakState.δ↑ Σʷ)
  74. -- δ↓ : Transitions↓ (WeakState.δ↓ Σʷ)
  75. --
  76. --⌊_⌋ : ∀ {ℓ Σʷ} → (Σ : State {ℓ} Σʷ) → Π.Σ (Set ℓ) id
  77. --⌊ Σ ⌋ = ⟨ State.Σ Σ , State.σ Σ ⟩
  78. --
  79. --lookup↓ : ∀ {ℓ xs δ} → δ ∈ xs → (Ts : Transitions↓ {ℓ} xs) → Transition↓ (proj₂ δ)
  80. --lookup↓ (here refl) (x ∷ _) = x
  81. --lookup↓ (there ∈xs) (_ ∷ xs) = lookup↓ ∈xs xs
  82. --
  83. --∈↓ʷ⇒∈↓ : ∀ {ℓ Σʷ δ} {Σ : State Σʷ} → δ ∈ (WeakState.δ↓ Σʷ) →
  84. -- Transition↓ {ℓ} (proj₂ δ)
  85. --∈↓ʷ⇒∈↓ {Σ = Σ} δ∈ = lookup↓ δ∈ (State.δ↓ Σ)
  86. ----
  87. ----open Weak
  88. ----
  89. --
  90. data Action {ℓ} where
  91. -- get : ∀ {Σʷ Σ} → Action {ℓ} {Σʷ} {Σʷ} ⌊ Σ ⌋ Σ (State.Σ Σ)
  92. -- set : ∀ {Σʷ₁ Σʷ₂ Σ₁ Σ₂} → State.Σ Σ₂ → Action {ℓ} {Σʷ₁} {Σʷ₂} Σ₁ Σ₂ ⊤
  93. -- call : ∀ {Σʷ δ} {Σ : State Σʷ} → (δ∈ : δ ∈ WeakState.δ↓ Σʷ) →
  94. -- (x : WeakTransition.A (proj₂ δ)) →
  95. -- Action {ℓ} {Σʷ} {WeakTransition.Σ (proj₂ δ) x} ⌊ Σ ⌋
  96. -- (∈↓ʷ⇒∈↓ {Σ = Σ} δ∈ x)
  97. -- (WeakTransition.B (proj₂ δ) x)
  98. -- return : ∀ {Σʷ Σ A} → Action {ℓ} {Σʷ} {Σʷ} ⌊ Σ ⌋ Σ A
  99. -- _>>=_ : ∀ {Σʷ₁ Σʷ₂ Σʷ₃ Σ₁ Σ₂ Σ₃ A B} →
  100. -- Action {ℓ} {Σʷ₁} {Σʷ₂} (⌊_⌋ {Σʷ = Σʷ₁} Σ₁) Σ₂ A →
  101. -- (A → Action {ℓ} {Σʷ₂} {Σʷ₃} ⌊ Σ₂ ⌋ Σ₃ B) →
  102. -- Action {ℓ} {Σʷ₁} {Σʷ₃} ⌊ Σ₁ ⌋ Σ₃ B
  103. --
  104. --record ParallelComposable {ℓ₁ ℓ₂ : Level} (A : Set ℓ₁) {P : A → A → Set ℓ₂} :
  105. -- Set (ℓ₁ ⊔ ℓ₂) where
  106. -- field
  107. -- _||_ : A → A → A
  108. -- _∘_ : (x : A) → (y : A) → {_ : P x y} → A
  109. --
  110. --data InterfaceMatches {ℓ : Level} : ℕ → (Σʷ₁ Σʷ₂ : WeakState {ℓ}) → Set (lsuc ℓ) where
  111. -- unreachable : ∀ {Σʷ₁ Σʷ₂} → InterfaceMatches 0 Σʷ₁ Σʷ₂
  112. -- match : ∀ {n Σʷ₁ Σʷ₂ δ₁} →
  113. -- -- For each interface in the outgoing to Σʷ₁
  114. -- δ₁ ∈ WeakState.δ↓ Σʷ₁ →
  115. -- Π.Σ (String × WeakTransition {ℓ}) (λ δ₂ →
  116. -- -- A corresponding interface exists in the incoming of Σʷ₂
  117. -- (δ₂ ∈ WeakState.δ↑ Σʷ₂) ×
  118. -- -- With the same name
  119. -- (proj₁ δ₁ ≡ proj₁ δ₂) ×
  120. -- -- The same input type
  121. -- Π.Σ (WeakTransition.A (proj₂ δ₁) ≡ WeakTransition.A (proj₂ δ₂)) (λ{
  122. -- refl → (x : WeakTransition.A (proj₂ δ₁)) →
  123. -- -- The same output type
  124. -- WeakTransition.B (proj₂ δ₁) x ≡ WeakTransition.B (proj₂ δ₂) x ×
  125. -- -- And preserving the fact that interfaces keep matching.
  126. -- InterfaceMatches n (WeakTransition.Σ (proj₂ δ₁) x)
  127. -- (WeakTransition.Σ (proj₂ δ₂) x)
  128. -- })) →
  129. -- InterfaceMatches (suc n) Σʷ₁ Σʷ₂
  130. --
  131. --instance
  132. -- WeakStateParallelComposable : ∀ {ℓ : Level} → ParallelComposable {lsuc ℓ} (WeakState {ℓ}) {λ Σʷ₁ Σʷ₂ → ∀ n → InterfaceMatches n Σʷ₁ Σʷ₂}
  133. -- WeakStateParallelComposable = record
  134. -- { _||_ = _||_
  135. -- ; _∘_ = λ Σʷ₁ Σʷ₂ → record
  136. -- { δ↑ = ?
  137. -- ; δ↓ = ?
  138. -- }
  139. -- }
  140. -- where
  141. -- open WeakState
  142. -- open WeakTransition
  143. -- invariant₁ : ∀ {ℓ} → WeakState {ℓ} → WeakTransition {ℓ} → WeakTransition {ℓ}
  144. -- invariant₂ : ∀ {ℓ} → WeakState {ℓ} → WeakTransition {ℓ} → WeakTransition {ℓ}
  145. -- _||_ : ∀ {ℓ} → WeakState {ℓ} → WeakState {ℓ} → WeakState {ℓ}
  146. -- Σʷ₁ || Σʷ₂ = record
  147. -- { δ↑ = map (map₂ (invariant₂ Σʷ₂)) (δ↑ Σʷ₁) ∪ map (map₂ (invariant₁ Σʷ₁)) (δ↑ Σʷ₂)
  148. -- ; δ↓ = map (map₂ (invariant₂ Σʷ₂)) (δ↓ Σʷ₁) ∪ map (map₂ (invariant₁ Σʷ₁)) (δ↓ Σʷ₂)
  149. -- }
  150. -- invariant₁ Σʷ δ = record { A = A δ ; B = B δ ; Σ = λ x → Σʷ || Σ δ x }
  151. -- invariant₂ Σʷ δ = record { A = A δ ; B = B δ ; Σ = λ x → Σ δ x || Σʷ }
  152. -- ActionParallelComposable : ∀ {ℓ : Level} {Σʷ : WeakState {ℓ}} → (Σ : State Σʷ) → (A : Set ℓ) → ParallelComposable {ℓ} {P = InterfaceMatches
  153. --ParallelComposable
  154. -- open import Data.Bool using (Bool; true; false)
  155. -- open import Data.Empty using (⊥-elim)
  156. -- open import Data.List using (List; _∷_; []; map)
  157. -- open import Data.Maybe using (Maybe; nothing; just) renaming (map to mmap)
  158. -- open import Data.Nat using (ℕ; zero; suc)
  159. -- open import Data.Product using (_×_; ∃; ∃-syntax; proj₁; proj₂) renaming (_,_ to ⟨_,_⟩)
  160. -- open import Data.Sum using (_⊎_; inj₁; inj₂)
  161. -- open import Function using (_∘_)
  162. -- open import Relation.Binary.PropositionalEquality using (_≡_; _≢_; refl)
  163. -- open import Level using (Level; Lift) renaming (suc to lsuc; lift to llift)
  164. -- open import Yggdrasil.Probability using (Dist; pure; _>>=′_; lift)
  165. -- open import Yggdrasil.List using (_∈_; here; there)
  166. --
  167. -- data ⊤ {ℓ : Level} : Set ℓ where
  168. -- tt : ⊤
  169. --
  170. -- data ⊥ {ℓ : Level} : Set ℓ where
  171. --
  172. -- T : ∀ {ℓ} → Bool → Set ℓ
  173. -- T true = ⊤
  174. -- T false = ⊥
  175. --
  176. -- record Query (ℓ : Level) : Set (lsuc ℓ) where
  177. -- constructor mkquery
  178. -- field
  179. -- A : Set ℓ
  180. -- B : A → Set ℓ
  181. --
  182. -- mknquery : {ℓ : Level} → Set ℓ → Set ℓ → Query ℓ
  183. -- mknquery A B = mkquery A (λ _ → B)
  184. --
  185. -- record Node (ℓ : Level) : Set (lsuc ℓ)
  186. -- record WorldType (ℓ : Level) : Set (lsuc ℓ)
  187. -- data Action↑ {ℓ : Level} (N : Node ℓ) : Set ℓ → Set (lsuc ℓ)
  188. -- data Action⊤ {ℓ : Level} (S : Set ℓ) (Γ : WorldType ℓ) : Set ℓ → Set (lsuc ℓ)
  189. --
  190. -- data WorldState {ℓ : Level} (Γ : WorldType ℓ) : Set (lsuc ℓ)
  191. -- data WorldStates {ℓ : Level} : List (WorldType ℓ) → Set (lsuc ℓ)
  192. --
  193. -- record Node ℓ where
  194. -- inductive
  195. -- constructor mknode
  196. -- field
  197. -- state : Set ℓ
  198. -- chld : List (WorldType ℓ)
  199. -- qry : List (Query ℓ)
  200. --
  201. -- open Node
  202. --
  203. --
  204. -- record Call (ℓ : Level) (N : Node ℓ) : Set (lsuc ℓ) where
  205. -- inductive
  206. -- constructor call
  207. -- field
  208. -- A : Set ℓ
  209. -- B : A → Set ℓ
  210. -- δ : (x : A) → Action↑ N (B x)
  211. --
  212. -- -- A non-dependently typed instance of call.
  213. -- ncall : {ℓ : Level} {N : Node ℓ} → (A B : Set ℓ) → (A → Action↑ N B) → Call ℓ N
  214. -- ncall A B δ = call A (λ _ → B) δ
  215. --
  216. -- weaken : ∀ {ℓ N} → Call ℓ N → Query ℓ
  217. -- weaken c = record { A = Call.A c; B = Call.B c }
  218. --
  219. -- record WorldType ℓ where
  220. -- inductive
  221. -- constructor tynode
  222. -- field
  223. -- node : Node ℓ
  224. -- adv : List (Call ℓ node)
  225. -- hon : List (Call ℓ node)
  226. --
  227. -- open WorldType
  228. --
  229. -- data _⊑_ {ℓ : Level} : (Γ₁ Γ₂ : WorldType ℓ) → Set (lsuc ℓ) where
  230. -- here : ∀ {Γ} → Γ ⊑ Γ
  231. -- there : ∀ {Γ₁ Γ₂ Γ₃} → Γ₂ ∈ chld (node Γ₃) → Γ₁ ⊑ Γ₂ → Γ₁ ⊑ Γ₃
  232. --
  233. -- ⊑-trans : ∀ {ℓ} {Γ₁ Γ₂ Γ₃ : WorldType ℓ} → Γ₁ ⊑ Γ₂ → Γ₂ ⊑ Γ₃ → Γ₁ ⊑ Γ₃
  234. -- ⊑-trans ⊑Γ here = ⊑Γ
  235. -- ⊑-trans ⊑Γ (there Γ′∈ ⊑Γ′) = there Γ′∈ (⊑-trans ⊑Γ ⊑Γ′)
  236. --
  237. -- ⊑-right : ∀ {ℓ} {Γ₁ Γ₂ Γ₃ : WorldType ℓ} → Γ₂ ⊑ Γ₃ → Γ₁ ∈ chld (node Γ₂) → Γ₁ ⊑ Γ₃
  238. -- ⊑-right Γ⊑ ∈Γ = ⊑-trans (there ∈Γ here) Γ⊑
  239. --
  240. -- data Action⊤ {ℓ} S Γ where
  241. -- read : Action⊤ S Γ S
  242. -- write : S → Action⊤ S Γ ⊤
  243. -- call↓ : ∀ {f} → f ∈ (hon Γ) → (x : Call.A f) → Action⊤ S Γ (Call.B f x)
  244. -- abort : ∀ {A} → Action⊤ S Γ A
  245. -- dist : ∀ {A} → Dist A → Action⊤ S Γ A
  246. -- call↯ : ∀ {Γ′} {f : Call ℓ (node Γ′)} → f ∈ (adv Γ′) → Γ′ ⊑ Γ →
  247. -- (x : Call.A f) → Action⊤ S Γ (Call.B f x)
  248. -- _>>=_ : ∀ {A B} → Action⊤ S Γ A → (A → Action⊤ S Γ B) → Action⊤ S Γ B
  249. --
  250. -- data Action↑ {ℓ} N where
  251. -- read : Action↑ N (state N)
  252. -- write : state N → Action↑ N ⊤
  253. -- call↓ : ∀ {Γ f} → f ∈ (hon Γ) → Γ ∈ chld N → (x : Call.A f) →
  254. -- Action↑ N (Call.B f x)
  255. -- abort : ∀ {A} → Action↑ N A
  256. -- dist : ∀ {A} → Dist A → Action↑ N A
  257. -- query : ∀ {q} → q ∈ qry N → (x : Query.A q) → Action↑ N (Query.B q x)
  258. -- _>>=_ : ∀ {A B} → Action↑ N A → (A → Action↑ N B) → Action↑ N B
  259. --
  260. -- -- TODO: build full monad instances of all actions, and Dist -- once I figure
  261. -- -- out how that works in agda.
  262. -- return : ∀ {ℓ N A} → A → Action↑ {ℓ} N A
  263. -- return x = dist (pure x)
  264. --
  265. -- infixl 1 _>>=_ _>>_
  266. --
  267. -- _>>_ : ∀ {ℓ N A B} → Action↑ {ℓ} N A → Action↑ {ℓ} N B → Action↑ {ℓ} N B
  268. -- α >> β = α >>= (λ _ → β)
  269. --
  270. -- data WorldStates {ℓ} where
  271. -- [] : WorldStates []
  272. -- _∷_ : ∀ {Γ Γs} → WorldState Γ → WorldStates Γs → WorldStates (Γ ∷ Γs)
  273. --
  274. -- data WorldState {ℓ} Γ where
  275. -- stnode : state (node Γ) → WorldStates (chld (node Γ)) → WorldState Γ
  276. --
  277. -- record World (ℓ : Level) : Set (lsuc ℓ) where
  278. -- field
  279. -- Γ : WorldType ℓ
  280. -- Σ : WorldState Γ
  281. --
  282. -- data _∈↑_ {ℓ : Level} (q : Query ℓ) (Γ : WorldType ℓ) : Set (lsuc ℓ) where
  283. -- path : ∀ {Γ′} → Γ′ ⊑ Γ → q ∈ qry (node Γ′) → q ∈↑ Γ
  284. --
  285. -- Oracle : ∀ {ℓ} → Set ℓ → WorldType ℓ → Set (lsuc ℓ)
  286. -- Oracle S Γ = ∀ {q} → q ∈↑ Γ → (x : Query.A q) → Action⊤ S Γ (Query.B q x)
  287. --
  288. -- record Strategy {ℓ : Level} (Γ : WorldType ℓ) (A : Set ℓ) {S : Set ℓ} : Set (lsuc ℓ) where
  289. -- constructor strat
  290. -- field
  291. -- state : S
  292. -- init : Action⊤ S Γ A
  293. -- oracle : Oracle S Γ
  294. --
  295. --
  296. --
  297. -- get : ∀ {ℓ Γ₁ Γ₂} → Γ₁ ⊑ Γ₂ → WorldState {ℓ} Γ₂ → state (node Γ₁)
  298. -- get here (stnode Σ _) = Σ
  299. -- get (there Γ′∈ ⊑Γ) (stnode _ Σs) = get ⊑Γ (lookup Γ′∈ Σs)
  300. -- where
  301. -- lookup : ∀ {Γ Γs} → Γ ∈ Γs → WorldStates Γs → WorldState Γ
  302. -- lookup here (Σ ∷ _) = Σ
  303. -- lookup (there Γ′∈) (_ ∷ Σs) = lookup Γ′∈ Σs
  304. --
  305. -- set : ∀ {ℓ Γ₁ Γ₂} → Γ₁ ⊑ Γ₂ → WorldState {ℓ} Γ₂ → state (node Γ₁) →
  306. -- WorldState {ℓ} Γ₂
  307. -- set here (stnode Σ Σs) Σ′ = stnode Σ′ Σs
  308. -- set (there Γ′∈ ⊑Γ) (stnode Σ Σs) Σ′ = stnode Σ (set′ Γ′∈ ⊑Γ Σs Σ′)
  309. -- where
  310. -- set′ : ∀ {Γ₁ Γ₂ Γs} → Γ₂ ∈ Γs → Γ₁ ⊑ Γ₂ → WorldStates Γs →
  311. -- state (node Γ₁) → WorldStates Γs
  312. -- set′ here ⊑Γ (Σ ∷ Σs) Σ′ = set ⊑Γ Σ Σ′ ∷ Σs
  313. -- set′ (there Γ∈) ⊑Γ (Σ ∷ Σs) Σ′ = Σ ∷ set′ Γ∈ ⊑Γ Σs Σ′
  314. --
  315. -- data Result {ℓ : Level} (A : Set ℓ) : Set ℓ where
  316. -- abort : Result A
  317. -- out-of-gas : Result A
  318. -- result : A → Result A
  319. --
  320. -- rmap : ∀ {ℓ A B} → (A → B) → Result {ℓ} A → Result {ℓ} B
  321. -- rmap _ abort = abort
  322. -- rmap _ out-of-gas = out-of-gas
  323. -- rmap f (result x) = result (f x)
  324. --
  325. -- exec : ∀ {ℓ S Γ A} → Strategy {ℓ} Γ A {S} → WorldState {ℓ} Γ → ℕ →
  326. -- Dist (Result (Lift (lsuc ℓ) A))
  327. -- exec⊤ : ∀ {ℓ S Γ A} → Oracle S Γ → Action⊤ S Γ A → S × WorldState {ℓ} Γ → ℕ →
  328. -- Dist (Result (A × (S × WorldState {ℓ} Γ)))
  329. -- exec↑ : ∀ {ℓ S Γ₁ Γ₂ A} → Oracle S Γ₁ → Action↑ (node Γ₂) A →
  330. -- (S × WorldState {ℓ} Γ₁) → Γ₂ ⊑ Γ₁ → ℕ → Dist (Result (A × (S × WorldState {ℓ} Γ₁)))
  331. --
  332. -- -- NOTE: Gas is only used for termination here, it is NOT a computational model.
  333. -- exec (strat S α O) Σ g = (exec⊤ O α ⟨ S , Σ ⟩ g) >>=′ (pure ∘ rmap (llift ∘ proj₁))
  334. --
  335. -- exec⊤ O read Σ g = pure (result ⟨ proj₁ Σ , Σ ⟩)
  336. -- exec⊤ O (write σ) Σ g = pure (result ⟨ tt , ⟨ σ , proj₂ Σ ⟩ ⟩)
  337. -- exec⊤ O (call↓ {f = f} ∈Γ x) Σ g = exec↑ O (Call.δ f x) Σ here g
  338. -- exec⊤ O abort Σ g = pure abort
  339. -- exec⊤ O (dist D) Σ g = lift D >>=′ λ{
  340. -- (llift x) → pure (result ⟨ x , Σ ⟩ ) }
  341. -- exec⊤ O (call↯ {f = f} f∈ ⊑Γ x) Σ g = exec↑ O (Call.δ f x) Σ ⊑Γ g
  342. -- exec⊤ O (α >>= β) Σ g = (exec⊤ O α Σ g) >>=′ λ{
  343. -- (result ⟨ x , Σ′ ⟩) → exec⊤ O (β x) Σ′ g ;
  344. -- abort → pure abort ;
  345. -- out-of-gas → pure out-of-gas }
  346. --
  347. -- exec↑ O read Σ ⊑Γ g = pure (result
  348. -- ⟨ get ⊑Γ (proj₂ Σ) , Σ ⟩)
  349. -- exec↑ O (write σ) Σ ⊑Γ g = pure (result
  350. -- ⟨ tt , ⟨ proj₁ Σ , set ⊑Γ (proj₂ Σ) σ ⟩ ⟩)
  351. -- exec↑ O abort Σ ⊑Γ g = pure abort
  352. -- exec↑ O (dist D) Σ ⊑Γ g = lift D >>=′
  353. -- λ{ (llift x) → pure (result ⟨ x , Σ ⟩) }
  354. -- exec↑ O (query {q = q} q∈ x) Σ ⊑Γ zero = pure out-of-gas
  355. -- exec↑ O (query {q = q} q∈ x) Σ ⊑Γ (suc g) = exec⊤ O (O (path ⊑Γ q∈) x) Σ g
  356. -- exec↑ O (call↓ {f = f} ∈Γ Γ∈ x) Σ ⊑Γ g = exec↑ O (Call.δ f x) Σ (⊑-right ⊑Γ Γ∈) g
  357. -- exec↑ O (α >>= β) Σ ⊑Γ g = (exec↑ O α Σ ⊑Γ g) >>=′ λ{
  358. -- (result ⟨ x , Σ′ ⟩) → exec↑ O (β x) Σ′ ⊑Γ g ;
  359. -- abort → pure abort ;
  360. -- out-of-gas → pure out-of-gas }