-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathBool.lp
More file actions
220 lines (173 loc) · 4.72 KB
/
Bool.lp
File metadata and controls
220 lines (173 loc) · 4.72 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/* Library on booleans. */
require open Stdlib.FOL Stdlib.Eq;
inductive 𝔹 : TYPE ≔ // `dB or \BbbB
| true : 𝔹
| false : 𝔹;
constant symbol bool : Set;
rule τ bool ↪ 𝔹;
// induction principle with equalities
opaque symbol case_𝔹 b : π (b = true ∨ b = false) ≔
begin
induction
{ apply ∨ᵢ₁; reflexivity; }
{ apply ∨ᵢ₂; reflexivity; }
end;
opaque symbol ind_𝔹_eq p b:
(π(b = true) → π(p b)) → (π(b = false) → π(p b)) → π(p b) ≔
begin
assume p b t f; refine ∨ₑ (case_𝔹 b) t f;
end;
// istrue predicate
injective symbol istrue : 𝔹 → Prop;
rule istrue true ↪ ⊤
with istrue false ↪ ⊥;
coerce_rule coerce 𝔹 Prop $x ↪ istrue $x;
opaque symbol istrue=true [x] : π (istrue x) → π (x = true) ≔
begin
assume x h;
refine ∨ₑ (case_𝔹 x) _ _
{ assume h1; refine h1 }
{ assume h1;
have H1: π (istrue false) { rewrite eq_sym h1; refine h };
refine ⊥ₑ H1 };
end;
opaque symbol true=istrue [x] : π (x = true) → π (istrue x) ≔
begin
assume x h;
refine ∨ₑ (case_𝔹 x) _ _
{ assume h1; rewrite h1; refine ⊤ᵢ}
{ assume h1; rewrite h; refine ⊤ᵢ}
end;
opaque symbol ¬istrue=false [x : 𝔹]:
π (¬ x) → π (x = false) ≔
begin
assume x h;
refine ∨ₑ (case_𝔹 x) _ _
{ assume h1; refine ⊥ₑ (h (true=istrue h1))}
{ assume h1; refine h1};
end;
opaque symbol false=¬istrue [x : 𝔹]:
π (x = false) → π (¬ x) ≔
begin
assume x h0; rewrite h0;
assume h1; refine h1;
end;
// non confusion of constructors
opaque symbol false≠true : π (false ≠ true) ≔
begin
assume h; refine ind_eq h istrue ⊤ᵢ
end;
opaque symbol true≠false : π (true ≠ false) ≔
begin
assume h; apply false≠true; symmetry; apply h
end;
// not
symbol not : 𝔹 → 𝔹;
rule not true ↪ false
with not false ↪ true;
opaque symbol ¬_istrue [p: 𝔹]:
π(¬ p) → π(not p) ≔
begin
induction
{ simplify; assume h; refine h ⊤ᵢ }
{ simplify; assume h; refine ⊤ᵢ }
end;
opaque symbol istrue_not [p: 𝔹]:
π(not p) → π(¬ p)≔
begin
induction
{ simplify; assume h0 h1; refine h0 }
{ simplify; assume h0 h1; refine h1 }
end;
// or
symbol or : 𝔹 → 𝔹 → 𝔹;
notation or infix left 20;
rule true or _ ↪ true
with _ or true ↪ true
with false or $b ↪ $b
with $b or false ↪ $b;
opaque symbol ∨_istrue [p q : 𝔹] : π(p or q) → π(p ∨ q) ≔
begin
induction
{ assume q h; apply ∨ᵢ₁; apply ⊤ᵢ; }
{ assume q h; apply ∨ᵢ₂; apply h; }
end;
opaque symbol istrue_or [p q : 𝔹] : π(p ∨ q) → π(p or q) ≔
begin
induction
{ assume q h; apply ⊤ᵢ; }
{ assume q h; apply ∨ₑ h { assume i; apply ⊥ₑ i; } { assume i; apply i; } }
end;
opaque symbol orᵢ₁ [p : 𝔹] q : π p → π (p or q) ≔
begin
induction
{ simplify; assume b h; apply ⊤ᵢ }
{ simplify; assume b h; apply ⊥ₑ h }
end;
opaque symbol orᵢ₂ p [q : 𝔹] : π q → π (p or q) ≔
begin
induction
{ simplify; assume b h; apply ⊤ᵢ }
{ simplify; assume b h; apply h }
end;
opaque symbol orₑ [p q : 𝔹] (r : 𝔹) :
π (p or q) → (π p → π r) → (π q → π r) → π r ≔
begin
assume p q r pq pr qr;
have h: π(p ∨ q) { apply ∨_istrue pq };
apply ∨ₑ h pr qr;
end;
opaque symbol orC p q : π (p or q = q or p) ≔
begin
induction
{ reflexivity; }
{ reflexivity; }
end;
opaque symbol orA p q r : π ((p or q) or r = p or (q or r)) ≔
begin
induction
{ reflexivity; }
{ reflexivity; }
end;
// and
symbol and : 𝔹 → 𝔹 → 𝔹;
notation and infix left 7;
rule true and $b ↪ $b
with $b and true ↪ $b
with false and _ ↪ false
with _ and false ↪ false;
opaque symbol ∧_istrue [p q : 𝔹] : π(p and q) → π(p ∧ q) ≔
begin
induction
{ induction
{ assume h; apply ∧ᵢ { apply ⊤ᵢ } { apply ⊤ᵢ } }
{ assume h; apply ⊥ₑ h; }
}
{ assume q h; apply ⊥ₑ h; }
end;
opaque symbol istrue_and [p q : 𝔹] : π(p ∧ q) → π(p and q) ≔
begin
induction
{ assume q h; apply ∧ₑ₂ h; }
{ assume q h; apply ∧ₑ₁ h; }
end;
opaque symbol andᵢ [p q : 𝔹] : π p → π q → π(p and q) ≔
begin
assume p q h i; apply @istrue_and p q; apply ∧ᵢ h i;
end;
opaque symbol andₑ₁ [p q : 𝔹] : π (p and q) → π p ≔
begin
induction
{ assume q i; apply ⊤ᵢ; }
{ assume q i; apply i; }
end;
opaque symbol andₑ₂ [p q : 𝔹] : π (p and q) → π q ≔
begin
induction
{ assume q i; apply i; }
{ assume q i; apply ⊥ₑ i; }
end;
// if-then-else
symbol if : 𝔹 → Π [a], τ a → τ a → τ a;
rule if true $x _ ↪ $x
with if false _ $y ↪ $y;