-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathBool.lp
179 lines (138 loc) Β· 3.82 KB
/
Bool.lp
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
/* Library on booleans. */
require open Stdlib.Set Stdlib.Prop 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;
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;
// 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;
// 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;