-
Notifications
You must be signed in to change notification settings - Fork 0
/
complete-constraints-core.agda
151 lines (143 loc) · 5.24 KB
/
complete-constraints-core.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
open import List
open import Nat
open import Prelude
open import constraints-core
open import core
module complete-constraints-core where
-- complete match constraints
data comp-constr : Set where
·⊤ : comp-constr
·⊥ : comp-constr
N : Nat → comp-constr
N̸ : Nat → comp-constr
inl : comp-constr → comp-constr
inr : comp-constr → comp-constr
⟨_,_⟩ : comp-constr → comp-constr → comp-constr
_∨_ : comp-constr → comp-constr → comp-constr
_∧_ : comp-constr → comp-constr → comp-constr
-- ξ constrains final expressions of type τ
data _:cc:_ : (ξ : comp-constr) → (τ : htyp) → Set where
CTTruth : ∀{τ} →
·⊤ :cc: τ
CTFalsity : ∀{τ} →
·⊥ :cc: τ
CTNum : ∀{n} →
N n :cc: num
CTNotNum : ∀{n} →
N̸ n :cc: num
CTInl : ∀{ξ τ1 τ2} →
ξ :cc: τ1 →
inl ξ :cc: τ1 ⊕ τ2
CTInr : ∀{ξ τ1 τ2} →
ξ :cc: τ2 →
inr ξ :cc: τ1 ⊕ τ2
CTPair : ∀{ξ1 ξ2 τ1 τ2} →
ξ1 :cc: τ1 →
ξ2 :cc: τ2 →
⟨ ξ1 , ξ2 ⟩ :cc: τ1 ⊠ τ2
CTOr : ∀{ξ1 ξ2 τ} →
ξ1 :cc: τ →
ξ2 :cc: τ →
(ξ1 ∨ ξ2) :cc: τ
CTnd : ∀{ξ1 ξ2 τ} →
ξ1 :cc: τ →
ξ2 :cc: τ →
(ξ1 ∧ ξ2) :cc: τ
-- e satisfies ξ
data _⊧_ : (e : ihexp) → (ξ : comp-constr) → Set where
CSTruth : ∀{e} →
e ⊧ ·⊤
CSNum : ∀{n} →
(N n) ⊧ (N n)
CSNotNum : ∀{n1 n2} →
n1 ≠ n2 →
(N n1) ⊧ (N̸ n2)
CSInl : ∀{e τ ξ} →
e ⊧ ξ →
(inl τ e) ⊧ (inl ξ)
CSInr : ∀{e τ ξ} →
e ⊧ ξ →
(inr τ e) ⊧ (inr ξ)
CSPair : ∀{e1 e2 ξ1 ξ2} →
e1 ⊧ ξ1 →
e2 ⊧ ξ2 →
⟨ e1 , e2 ⟩ ⊧ ⟨ ξ1 , ξ2 ⟩
CSOrL : ∀{e ξ1 ξ2} →
e ⊧ ξ1 →
e ⊧ (ξ1 ∨ ξ2)
CSOrR : ∀{e ξ1 ξ2} →
e ⊧ ξ2 →
e ⊧ (ξ1 ∨ ξ2)
CSAnd : ∀{e ξ1 ξ2} →
e ⊧ ξ1 →
e ⊧ ξ2 →
e ⊧ (ξ1 ∧ ξ2)
-- compute the dual of a constraint
_◆d : comp-constr → comp-constr
·⊤ ◆d = ·⊥
·⊥ ◆d = ·⊤
(N n) ◆d = N̸ n
(N̸ n) ◆d = N n
(inl ξ) ◆d = inl (ξ ◆d) ∨ inr ·⊤
(inr ξ) ◆d = inr (ξ ◆d) ∨ inl ·⊤
⟨ ξ1 , ξ2 ⟩ ◆d =
(⟨ ξ1 , ξ2 ◆d ⟩ ∨ ⟨ ξ1 ◆d , ξ2 ⟩) ∨ ⟨ ξ1 ◆d , ξ2 ◆d ⟩
(ξ1 ∨ ξ2) ◆d = (ξ1 ◆d) ∧ (ξ2 ◆d)
(ξ1 ∧ ξ2) ◆d = (ξ1 ◆d) ∨ (ξ2 ◆d)
-- substitute ⊤ for ? in ξ
_◆⊤ : constr → comp-constr
·⊤ ◆⊤ = ·⊤
·⊥ ◆⊤ = ·⊥
·? ◆⊤ = ·⊤
(N n) ◆⊤ = N n
(inl ξ) ◆⊤ = inl (ξ ◆⊤)
(inr ξ) ◆⊤ = inr (ξ ◆⊤)
⟨ ξ1 , ξ2 ⟩ ◆⊤ = ⟨ ξ1 ◆⊤ , ξ2 ◆⊤ ⟩
(ξ1 ∨ ξ2) ◆⊤ = (ξ1 ◆⊤) ∨ (ξ2 ◆⊤)
-- substitute ⊥ for ? in ξ
_◆⊥ : constr → comp-constr
·⊤ ◆⊥ = ·⊤
·⊥ ◆⊥ = ·⊥
·? ◆⊥ = ·⊥
(N n) ◆⊥ = N n
(inl ξ) ◆⊥ = inl (ξ ◆⊥)
(inr ξ) ◆⊥ = inr (ξ ◆⊥)
⟨ ξ1 , ξ2 ⟩ ◆⊥ = ⟨ ξ1 ◆⊥ , ξ2 ◆⊥ ⟩
(ξ1 ∨ ξ2) ◆⊥ = (ξ1 ◆⊥) ∨ (ξ2 ◆⊥)
dual-same-type : ∀{ξ τ} →
ξ :cc: τ →
(ξ ◆d) :cc: τ
dual-same-type CTTruth = CTFalsity
dual-same-type CTFalsity = CTTruth
dual-same-type CTNum = CTNotNum
dual-same-type CTNotNum = CTNum
dual-same-type (CTInl ct) =
CTOr (CTInl (dual-same-type ct)) (CTInr CTTruth)
dual-same-type (CTInr ct) =
CTOr (CTInr (dual-same-type ct)) (CTInl CTTruth)
dual-same-type (CTPair ct1 ct2) =
CTOr (CTOr (CTPair ct1 (dual-same-type ct2))
(CTPair (dual-same-type ct1) ct2))
(CTPair (dual-same-type ct1) (dual-same-type ct2))
dual-same-type (CTOr ct1 ct2) =
CTnd (dual-same-type ct1) (dual-same-type ct2)
dual-same-type (CTnd ct1 ct2) =
CTOr (dual-same-type ct1) (dual-same-type ct2)
same-type-dual : ∀{ξ τ} →
(ξ ◆d) :cc: τ →
ξ :cc: τ
same-type-dual {ξ = ·⊤} CTFalsity = CTTruth
same-type-dual {ξ = ·⊥} CTTruth = CTFalsity
same-type-dual {ξ = N n} CTNotNum = CTNum
same-type-dual {ξ = N̸ n} CTNum = CTNotNum
same-type-dual {ξ = inl ξ} {τ = τ1 ⊕ τ2} (CTOr (CTInl dct1) dct2) =
CTInl (same-type-dual dct1)
same-type-dual {ξ = inr ξ} {τ = τ1 ⊕ τ2} (CTOr (CTInr dct1) dct2) =
CTInr (same-type-dual dct1)
same-type-dual {ξ = ⟨ ξ1 , ξ2 ⟩} {τ = τ1 ⊠ τ2}
(CTOr (CTOr (CTPair dct1 dct2) (CTPair dct3 dct4)) dct5) =
CTPair dct1 dct4
same-type-dual {ξ = ξ1 ∨ ξ2} (CTnd dct1 dct2) =
CTOr (same-type-dual dct1) (same-type-dual dct2)
same-type-dual {ξ = ξ1 ∧ ξ2} (CTOr dct1 dct2) =
CTnd (same-type-dual dct1) (same-type-dual dct2)