-
Notifications
You must be signed in to change notification settings - Fork 0
/
PFA.agda
102 lines (83 loc) · 2.91 KB
/
PFA.agda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
{-# OPTIONS --cubical --allow-unsolved-metas #-}
module PFA where
open import Cubical.Foundations.Prelude hiding (_∎)
open import Cubical.Foundations.Logic
open import Cubical.Foundations.Function
open import Cubical.HITs.PropositionalTruncation.Base
open import Cubical.Data.List hiding ([_])
open import Cubical.Data.Maybe
open import Cubical.Data.Prod
open import Common
open import Lang
open import Fin
private variable ℓ : Level
isEmpty : Type ℓ → Type ℓ
isEmpty X = X → [ ⊥ ]
Subset : {X : Type ℓ} (P : ℙ X) → Type ℓ
Subset {X = X} P = Σ X (_∈ P)
module _ (A : Type₀) {{isFinSetA : isFinSet A}} where
record PFA : Type₁ where
field
Q : Type₀
instance isFinSetQ : isFinSet Q
S : Type₀
instance isFinSetS : isFinSet S
δ : Q → Maybe A → S → ℙ (Q × List S)
instance δ-fin : ∀ {q a s} → isFinSet (Subset (δ q a s))
--δ : Q → Maybe A → S → Σ (ℙ (Q × List S)) (IsFinite ∘ Subset)
--δ : Q → Maybe A → S → LFSet (Q × List S)
initial-state : Q
initial-symbol : S
F : ℙ Q
record Config : Type₀ where
constructor config
field
state : Q
word : Word A
stack : List S
data _⊢_ : Config → Config → Type₀ where
step-nothing
: ∀ {q p w X α β}
→ (p , α) ∈ δ q nothing X
→ config q w (X ∷ β) ⊢ config p w (α ++ β)
step-just
: ∀ {q p a w X α β}
→ (p , α) ∈ δ q (just a) X
→ config q (a ∷ w) (X ∷ β) ⊢ config p w (α ++ β)
infix 3 _∎
infixr 2 _⊢⟨_⟩_
data _⊢*_ : Config → Config → Type₀ where
_∎
: ∀ I
→ I ⊢* I
_⊢⟨_⟩_
: ∀ I {J K}
→ I ⊢ J
→ J ⊢* K
→ I ⊢* K
final-state-lang : Lang A
final-state-lang w =
∃[ q ∶ Q ] ∃[ α ∶ List S ]
F q ⊓
∥ config initial-state w (initial-symbol ∷ []) ⊢* config q [] α ∥ₚ
empty-stack-lang : Lang A
empty-stack-lang w =
∃[ q ∶ Q ]
∥ config initial-state w (initial-symbol ∷ []) ⊢* config q [] [] ∥ₚ
record Deterministic (M : PFA) : Type₁ where
open PFA M
field
δ-isSubsingleton : ∀ q a X → isProp (Subset (δ q a X)) -- is this defined correctly?
δ-char-inhabited→ε-empty : ∀ q a X → ∥ Subset (δ q (just a) X) ∥ → Subset (δ q nothing X) → [ ⊥ ]
open PFA
FinalStatePfaLangs : ℙ (Lang A)
FinalStatePfaLangs N = ∃[ M ∶ PFA ] (final-state-lang M ≡ N) , powersets-are-sets _ _
EmptyStackPfaLangs : ℙ (Lang A)
EmptyStackPfaLangs N = ∃[ M ∶ PFA ] (empty-stack-lang M ≡ N) , powersets-are-sets _ _
_ : FinalStatePfaLangs ≡ EmptyStackPfaLangs
_ = TODO
{-
Languages definable by pushdown finite automata
-}
PfaLangs : ℙ (Lang A)
PfaLangs = FinalStatePfaLangs