Browse Source

Start working on ISM ideas.

master
Thomas Kerber 8 months ago
parent
commit
4ca10bba09
Signed by: Thomas Kerber <t.kerber@ed.ac.uk> GPG Key ID: 8489B911F9ED617B
1 changed files with 346 additions and 196 deletions
  1. 346
    196
      Yggdrasil/World.agda

+ 346
- 196
Yggdrasil/World.agda View File

@@ -1,209 +1,355 @@
module Yggdrasil.World where

open import Data.Bool using (Bool; true; false)
open import Data.Empty using (⊥-elim)
open import Data.Bool using (Bool; T)
open import Data.List using (List; _∷_; []; map)
open import Data.Maybe using (Maybe; nothing; just) renaming (map to mmap)
open import Data.Nat using (ℕ; zero; suc)
open import Data.Product using (_×_; ∃; ∃-syntax; proj₁; proj₂) renaming (_,_ to ⟨_,_⟩)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Function using (_∘_)
open import Relation.Binary.PropositionalEquality using (_≡_; _≢_; refl)
open import Level using (Level; Lift) renaming (suc to lsuc; lift to llift)
open import Yggdrasil.Probability using (Dist; pure; _>>=′_; lift)
open import Yggdrasil.List using (_∈_; here; there)

open import Data.List.Any using (here; there)
open import Data.List.Membership.Propositional using (_∈_)
open import Data.Maybe using (Maybe; just; nothing) renaming (map to mmap)
open import Data.Nat using (ℕ; suc)
open import Data.Product as Π using (_×_; ∃; ∃-syntax; proj₁; proj₂) renaming (_,_ to ⟨_,_⟩)
open import Data.String using (String)
import Data.String.Unsafe as S
open import Function using (id)
open import Level using (Level; _⊔_; Lift) renaming (suc to lsuc; zero to lzero)
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
open import Relation.Nullary using (Dec; yes; no)

-- Auto-lifted variant of ⊤.
data ⊤ {ℓ : Level} : Set ℓ where
tt : ⊤

data ⊥ {ℓ : Level} : Set ℓ where

T : ∀ {ℓ} → Bool → Set ℓ
T true = ⊤
T false = ⊥

record Query (ℓ : Level) : Set (lsuc ℓ) where
constructor mkquery
field
A : Set ℓ
B : A → Set ℓ

mknquery : {ℓ : Level} → Set ℓ → Set ℓ → Query ℓ
mknquery A B = mkquery A (λ _ → B)

record Node (ℓ : Level) : Set (lsuc ℓ)
record WorldType (ℓ : Level) : Set (lsuc ℓ)
data Action↑ {ℓ : Level} (N : Node ℓ) : Set ℓ → Set (lsuc ℓ)
data Action⊤ {ℓ : Level} (S : Set ℓ) (Γ : WorldType ℓ) : Set ℓ → Set (lsuc ℓ)

data WorldState {ℓ : Level} (Γ : WorldType ℓ) : Set (lsuc ℓ)
data WorldStates {ℓ : Level} : List (WorldType ℓ) → Set (lsuc ℓ)

record Node ℓ where
inductive
constructor mknode
field
state : Set ℓ
chld : List (WorldType ℓ)
qry : List (Query ℓ)

open Node


record Call (ℓ : Level) (N : Node ℓ) : Set (lsuc ℓ) where
Table : ∀ {ℓ} → Set ℓ → Set ℓ
Table A = List (String × A)

lookup : ∀ {ℓ A} → Table {ℓ} A → String → Maybe A
lookup [] _ = nothing
lookup (⟨ s₁ , x ⟩ ∷ xs) s₂ with s₁ S.≟ s₂
... | yes _ = just x
... | no _ = lookup xs s₂

module Weak where
record WeakState {ℓ : Level} : Set (lsuc ℓ)

record WeakTransition {ℓ : Level} : Set (lsuc ℓ) where
inductive
field
A : Set ℓ
B : A → Set ℓ
Σ : A → WeakState {ℓ}

record WeakState {ℓ} where
inductive
field
δ↑ : Table (WeakTransition {ℓ})
δ↓ : Table (WeakTransition {ℓ})

open Weak using (WeakState; WeakTransition)

record State {ℓ : Level} (Σʷ : WeakState {ℓ}) : Set (lsuc ℓ)
data Action {ℓ : Level} : {Σʷ₁ Σʷ₂ : WeakState {ℓ}} → (Σ₁ : Π.Σ (Set ℓ) id) →
(Σ₂ : State Σʷ₂) → Set ℓ → Set (lsuc ℓ)

Transition↑ : {ℓ : Level} {Σʷ : WeakState {ℓ}} → (Σ₁ : Π.Σ (Set ℓ) id) →
WeakTransition {ℓ} → Set (lsuc ℓ)
Transition↑ {Σʷ = Σʷ} Σ₁ T = (x : A T) → Π.Σ (State (Σ T x))
(λ Σ₂ → Action {Σʷ₁ = Σʷ} Σ₁ Σ₂ (B T x))
where open WeakTransition using (A; B; Σ)

Transition↓ : {ℓ : Level} → WeakTransition {ℓ} → Set (lsuc ℓ)
Transition↓ T = (x : A T) → State (Σ T x)
where open WeakTransition using (A; Σ)

data Transitions↑ {ℓ : Level} (Σ : Π.Σ (Set ℓ) id) :
Table (WeakTransition {ℓ}) → Set (lsuc ℓ) where
[] : Transitions↑ Σ []