Переглянути джерело

Not sure if this is working.

master
Thomas Kerber 8 місяці тому
джерело
коміт
e9c05e676b
Підписано: Thomas Kerber <t.kerber@ed.ac.uk> Ідентифікатор GPG ключа: 8489B911F9ED617B
1 змінених файлів з 117 додано та 97 видалено
  1. 117
    97
      Yggdrasil/World.agda

+ 117
- 97
Yggdrasil/World.agda Переглянути файл

@@ -1,17 +1,18 @@
module Yggdrasil.World where

open import Data.Bool using (Bool; T)
open import Data.List using (List; _∷_; []; map)
open import Data.List using (List; _∷_; []; map; _++_; length; lookup)
open import Data.List.Any using (here; there)
open import Data.List.Membership.Propositional using (_∈_)
open import Data.Fin using (Fin)
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.Product as Π using (_×_; ∃; ∃-syntax; proj₁; proj₂; map₂) 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.Binary.PropositionalEquality using (_≡_; _≢_; refl)
open import Relation.Nullary using (Dec; yes; no)

-- Auto-lifted variant of ⊤.
@@ -21,128 +22,147 @@ data ⊤ {ℓ : Level} : Set ℓ 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₂
_∪_ : ∀ {ℓ A} → Table {ℓ} A → Table {ℓ} A → Table {ℓ} A
_∪_ = _++_

module Weak where

record WeakState {ℓ : Level} : Set (lsuc ℓ)

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

record WeakState {ℓ} where
inductive
field
δ↑ : Table (WeakTransition {ℓ})
δ↓ : Table (WeakTransition {ℓ})
states : List (Set ℓ)
current : Fin (length states)
δ↑ : Fin (length states) → Table (WeakTransition {ℓ} (length states))
δ↓ : Fin (length states) → Table (WeakTransition {ℓ} (length states))

open Weak using (WeakState; WeakTransition)
open WeakState

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

data Action {ℓ : Level} : {Σʷ₁ Σʷ₂ : WeakState {ℓ}} →
(Σ₁ : Fin (length (states Σʷ₁))) →
(Σ₂ : State Σʷ₂) → Set ℓ → Set (lsuc ℓ)

Transition↑ : {ℓ : Level} {Σʷ : WeakState {ℓ}} → (Σ₁ : Π.Σ (Set ℓ) id) →
WeakTransition {ℓ} → Set (lsuc ℓ)
Transition↑ {Σʷ = Σʷ} Σ₁ T = (x : A T) → Π.Σ (State (Σ T x))
Transition↑ : {ℓ : Level} {Σʷ : WeakState {ℓ}} →
(Σ₁ : Fin (length (states Σʷ))) → WeakTransition {ℓ} (length (states Σʷ)) →
Set (lsuc ℓ)
Transition↑ {Σʷ = Σʷ} Σ₁ T = (x : A T) → Π.Σ
(State (record Σʷ { current = Σ 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)
Transition↓ : {ℓ : Level} {Σʷ : WeakState {ℓ}} →
WeakTransition {ℓ} (length (states Σʷ)) → Set ℓ
Transition↓ {Σʷ = Σʷ} T = (x : A T) → Π.Σ (Fin (length (states Σʷ)))
(λ n → lookup (states Σʷ) n)
where open WeakTransition using (A; Σ)

data Transitions↑ {ℓ : Level} (Σ : Π.Σ (Set ℓ) id) :
Table (WeakTransition {ℓ}) → Set (lsuc ℓ) where
[] : Transitions↑ Σ []
_∷_ : ∀ {Σʷ T Ts name} → Transition↑ {Σʷ = Σʷ} Σ T → Transitions↑ Σ Ts →
Transitions↑ Σ (⟨ name , T ⟩ ∷ Ts)
data Transitions↓ {ℓ : Level} :
Table (WeakTransition {ℓ}) → Set (lsuc ℓ) where
[] : Transitions↓ []
_∷_ : ∀ {T Ts name} → Transition↓ T → Transitions↓ Ts →
Transitions↓ (⟨ name , T ⟩ ∷ Ts)
--data Transitions↑ {ℓ : Level} (Σ : Π.Σ (Set ℓ) id) :
-- Table (WeakTransition {ℓ}) → Set (lsuc ℓ) where
-- [] : Transitions↑ Σ []
-- _∷_ : ∀ {Σʷ T Ts name} → Transition↑ {Σʷ = Σʷ} Σ T → Transitions↑ Σ Ts →
-- Transitions↑ Σ (⟨ name , T ⟩ ∷ Ts)
--
--data Transitions↓ {ℓ : Level} :
-- Table (WeakTransition {ℓ}) → Set (lsuc ℓ) where