annotate automaton-in-agda/src/temporal-logic.agda @ 330:407684f806e4

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 16 Nov 2022 17:43:10 +0900
parents cd73fe566291
children 6f3636fbc481
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
327
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
1 module temporal-logic where
21
ddf5f2f5fde8 add omega
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
ddf5f2f5fde8 add omega
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 open import Level renaming ( suc to succ ; zero to Zero )
ddf5f2f5fde8 add omega
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 open import Data.Nat
ddf5f2f5fde8 add omega
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 open import Data.List
ddf5f2f5fde8 add omega
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 open import Data.Maybe
139
3be1afb87f82 add utm
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 24
diff changeset
7 -- open import Data.Bool using ( Bool ; true ; false ; _∧_ ) renaming ( not to negate )
21
ddf5f2f5fde8 add omega
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 open import Relation.Binary.PropositionalEquality hiding ( [_] )
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 139
diff changeset
9 open import Relation.Nullary -- using (not_; Dec; yes; no)
21
ddf5f2f5fde8 add omega
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 open import Data.Empty
ddf5f2f5fde8 add omega
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
139
3be1afb87f82 add utm
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 24
diff changeset
12 open import logic
21
ddf5f2f5fde8 add omega
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 open import automaton
ddf5f2f5fde8 add omega
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14
ddf5f2f5fde8 add omega
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 open Automaton
ddf5f2f5fde8 add omega
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
ddf5f2f5fde8 add omega
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
326
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
18 open import nat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
19 open import Data.Nat.Properties
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
20
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
21 data LTTL ( V : Set ) : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
22 s : V → LTTL V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
23 ○ : LTTL V → LTTL V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
24 □ : LTTL V → LTTL V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
25 ⋄ : LTTL V → LTTL V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
26 _U_ : LTTL V → LTTL V → LTTL V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
27 t-not : LTTL V → LTTL V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
28 _t\/_ : LTTL V → LTTL V → LTTL V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
29 _t/\_ : LTTL V → LTTL V → LTTL V
21
ddf5f2f5fde8 add omega
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
326
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
31 {-# TERMINATING #-}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
32 M1 : { V : Set } → (ℕ → V → Bool) → ℕ → LTTL V → Set
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
33 M1 σ i (s x) = σ i x ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
34 M1 σ i (○ x) = M1 σ (suc i) x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
35 M1 σ i (□ p) = (j : ℕ) → i ≤ j → M1 σ j p
328
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
36 M1 σ i (⋄ p) = ¬ ( M1 σ i (□ (t-not p) ))
326
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
37 M1 σ i (p U q) = ¬ ( ( j : ℕ) → i ≤ j → ¬ (M1 σ j q ∧ (( k : ℕ) → i ≤ k → k < j → M1 σ j p )) )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
38 M1 σ i (t-not p) = ¬ ( M1 σ i p )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
39 M1 σ i (p t\/ p₁) = M1 σ i p ∧ M1 σ i p₁
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
40 M1 σ i (p t/\ p₁) = M1 σ i p ∨ M1 σ i p₁
21
ddf5f2f5fde8 add omega
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41
326
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
42 data LITL ( V : Set ) : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
43 iv : V → LITL V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
44 i○ : LITL V → LITL V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
45 _&_ : LITL V → LITL V → LITL V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
46 i-not : LITL V → LITL V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
47 _i\/_ : LITL V → LITL V → LITL V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
48 _i/\_ : LITL V → LITL V → LITL V
21
ddf5f2f5fde8 add omega
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
326
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
50 open import Relation.Binary.Definitions
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
51 open import Data.Unit using ( tt ; ⊤ )
21
ddf5f2f5fde8 add omega
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52
326
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
53 {-# TERMINATING #-}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
54 MI : { V : Set } → (ℕ → V → Bool) → (i j : ℕ) → i ≤ j → LITL V → Set
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
55 MI σ i j lt (iv x) = σ i x ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
56 MI σ i j lt (i○ x) with <-cmp i j
328
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
57 ... | tri< a ¬b ¬c = MI σ (suc i) j a x
326
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
58 ... | tri≈ ¬a b ¬c = ⊤
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
59 ... | tri> ¬a ¬b c = ⊥-elim ( nat-≤> lt c)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
60 MI σ i j lt (p & q) = ¬ ( ( k : ℕ) → (i<k : i ≤ k) → (k<j : k ≤ j) → ¬ ( MI σ i k i<k p ∧ MI σ k j k<j p))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
61 MI σ i j lt (i-not p) = ¬ ( MI σ i j lt p )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
62 MI σ i j lt (p i\/ p₁) = MI σ i j lt p ∧ MI σ i j lt p₁
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
63 MI σ i j lt (p i/\ p₁) = MI σ i j lt p ∨ MI σ i j lt p₁
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
64
327
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
65 data QBool ( V : Set ) : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
66 qb : Bool → QBool V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
67 qv : V → QBool V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
68 exists : V → QBool V → QBool V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
69 b-not : QBool V → QBool V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
70 _b\/_ : QBool V → QBool V → QBool V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
71 _b/\_ : QBool V → QBool V → QBool V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
72
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
73 {-# TERMINATING #-}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
74 SQ1 : { V : Set } → ((x y : V) → Dec ( x ≡ y)) → QBool V → V → Bool → QBool V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
75 SQ1 {V} dec (qb x) v t = qb x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
76 SQ1 {V} dec (qv x) v t with dec x v
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
77 ... | yes _ = qb t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
78 ... | no _ = qv x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
79 SQ1 {V} dec (exists x p) v t = SQ1 dec (SQ1 dec p x true) v t b\/ SQ1 dec (SQ1 dec p x false) v t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
80 SQ1 {V} dec (b-not p) v t = b-not (SQ1 dec p v t )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
81 SQ1 {V} dec (p b\/ p₁) v t = SQ1 dec p v t b\/ SQ1 dec p₁ v t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
82 SQ1 {V} dec (p b/\ p₁) v t = SQ1 dec p v t b/\ SQ1 dec p₁ v t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
83
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
84 {-# TERMINATING #-}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
85 MQ : { V : Set } → (V → Bool) → ((x y : V) → Dec ( x ≡ y)) → QBool V → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
86 MQ {V} val dec (qb x) = x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
87 MQ {V} val dec (qv x) = val x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
88 MQ {V} val dec (exists x p) = MQ val dec ( SQ1 dec p x true b\/ SQ1 dec p x false )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
89 MQ {V} val dec (b-not p) = not ( MQ val dec p )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
90 MQ {V} val dec (p b\/ p₁) = MQ val dec p \/ MQ val dec p₁
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
91 MQ {V} val dec (p b/\ p₁) = MQ val dec p /\ MQ val dec p₁
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
92
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
93 data QPTL ( V : Set ) : Set where
328
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
94 qt : Bool → QPTL V
327
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
95 qs : V → QPTL V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
96 q○ : QPTL V → QPTL V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
97 q□ : QPTL V → QPTL V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
98 q⋄ : QPTL V → QPTL V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
99 q-exists : V → QPTL V → QPTL V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
100 q-not : QPTL V → QPTL V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
101 _q\/_ : QPTL V → QPTL V → QPTL V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
102 _q/\_ : QPTL V → QPTL V → QPTL V
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
103
330
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 328
diff changeset
104 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 328
diff changeset
105 -- ∃ p ( <> p → ? )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 328
diff changeset
106 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 328
diff changeset
107
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 328
diff changeset
108
328
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
109 {-# TERMINATING #-}
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
110 SQP1 : { V : Set } → ((x y : V) → Dec ( x ≡ y)) → QPTL V → V → Bool → QPTL V
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
111 SQP1 {V} dec (qt x) v t = qt x
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
112 SQP1 {V} dec (qs x) v t with dec x v
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
113 ... | yes _ = qt t
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
114 ... | no _ = qs x
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
115 SQP1 {V} dec (q-exists x p) v t = SQP1 dec (SQP1 dec p x true) v t q\/ SQP1 dec (SQP1 dec p x false) v t
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
116 SQP1 {V} dec (q○ p) v t = q○ p
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
117 SQP1 {V} dec (q□ p) v t = SQP1 {V} dec p v t q/\ q□ p
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
118 SQP1 {V} dec (q⋄ p) v t = q-not ( SQP1 dec (q□ (q-not p)) v t)
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
119 SQP1 {V} dec (q-not p) v t = q-not ( SQP1 dec p v t )
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
120 SQP1 {V} dec (p q\/ p₁) v t = SQP1 {V} dec p v t q\/ SQP1 {V} dec p₁ v t
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
121 SQP1 {V} dec (p q/\ p₁) v t = SQP1 {V} dec p v t q/\ SQP1 {V} dec p₁ v t
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
122
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
123 {-# TERMINATING #-}
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
124 MQPTL : { V : Set } → (ℕ → V → Bool) → ℕ → ((x y : V) → Dec ( x ≡ y)) → QPTL V → Set
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
125 MQPTL σ i dec (qt x) = x ≡ true
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
126 MQPTL σ i dec (qs x) = σ i x ≡ true
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
127 MQPTL σ i dec (q○ x) = MQPTL σ (suc i) dec x
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
128 MQPTL σ i dec (q□ p) = (j : ℕ) → i ≤ j → MQPTL σ j dec p
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
129 MQPTL σ i dec (q⋄ p) = ¬ ( MQPTL σ i dec (q□ (q-not p) ))
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
130 MQPTL σ i dec (q-not p) = ¬ ( MQPTL σ i dec p )
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
131 MQPTL σ i dec (q-exists x p) = MQPTL σ i dec ( SQP1 dec p x true q\/ (SQP1 dec p x false))
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
132 MQPTL σ i dec (p q\/ p₁) = MQPTL σ i dec p ∧ MQPTL σ i dec p₁
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
133 MQPTL σ i dec (p q/\ p₁) = MQPTL σ i dec p ∨ MQPTL σ i dec p₁
cd73fe566291 temporal logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
134