-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.input
268 lines (201 loc) · 9.59 KB
/
test.input
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
id :: Forall (A : Type). A -> A;;
id := \A. \x. x;;
id_impli :: Forall {A : Type}. A -> A;;
id_impli := \x. x;;
id_nat :: Nat -> Nat;;
id_nat := id Nat;;
eq_refl :: Forall (A : Type). Forall (x : A). x = x;;
eq_refl := \A. \x. Refl A x;;
two :: Nat;;
two := Succ (Succ Zero);;
three :: Nat;;
three := Succ two;;
succ :: Nat -> Nat;;
succ := \x. Succ x;;
plus :: Nat -> Nat -> Nat;;
plus := \x. \y. nat_elim (\_. Nat) y (\_. \h. Succ h) x;;
test_plus_1 :: Forall (x : Nat). plus Zero (succ x) = (succ x);;
test_plus_1 := \x. Refl Nat (Succ x);;
f_eq :: Forall (A : Type). Forall (B : Type). Forall (x : A). Forall (y : A). Forall (f : Forall (x : A). B). Forall (eq : (x = y)). (f x) = (f y);;
f_eq := \A. \B. \x. \y. \f. \eqf.
eq_elim A
(\u. \v. (f u) = (f v))
(\w. Refl B (f w))
eqf;;
eq_trans :: Forall (A : Type). Forall (a : A). Forall (b : A). Forall (c : A). a = b -> b = c -> a = c;;
eq_trans := \A. \a. \b. \c.\Eab.
eq_elim A (\u. \v. v = c -> u = c)
(\w : A. id (w = c))
Eab;;
eq_sym :: Forall (A : Type). Forall (a : A). Forall (b : A). a = b -> b = a;;
eq_sym := \A. \a. \b. \eq.
eq_elim A (\u.\v. v = u)
(\w. Refl A w)
eq;;
eq_sym_again :: Forall (A : Type). Forall (a : A). Forall (b : A). Forall (eq : (a = b)). b = a;;
eq_sym_again := \A. \x. \y. \eq. eq_sym A x y eq;;
two_eq_two :: two = (plus (Succ Zero) (Succ Zero));;
two_eq_two := Refl Nat two;;
test_plus :: Forall (x : Nat). (plus Zero x) = x;;
test_plus := \n. Refl Nat n;;
plus_Z :: Forall (x : Nat). (plus x Zero) = x;;
plus_Z := \x. nat_elim (\z. (plus z Zero) = z)
(Refl Nat Zero)
(\n. \h. f_eq Nat Nat (plus n Zero) n succ h)
x;;
plus_nSm :: Forall (x : Nat). Forall (y : Nat). (plus x (succ y)) = (succ (plus x y));;
plus_nSm := \x. \y.
nat_elim (\z. (plus z (succ y)) = (succ (plus z y)))
(f_eq Nat Nat y y succ (Refl Nat y))
(\n. \IH : ((plus n (succ y)) = (succ (plus y n))). f_eq Nat Nat (plus n (Succ y)) (Succ (plus n y)) succ IH)
x;;
plus_comm :: Forall (x : Nat). Forall (y : Nat). (plus x y) = (plus y x);;
plus_comm := \x. \y.
nat_elim (\z. (plus z y) = (plus y z))
(eq_sym Nat (plus y Zero) y (plus_Z y))
(\n. \IH.
eq_trans Nat
(succ (plus n y))
(succ (plus y n))
(plus y (succ n))
(f_eq Nat Nat (plus n y) (plus y n) succ IH)
(eq_sym Nat (plus y (succ n)) (succ (plus y n)) (plus_nSm y n)))
x;;
times_two :: Nat -> Nat;;
times_two := \x : Nat. plus x x;;
times :: Nat -> Nat -> Nat;;
times := \x : Nat. \y : Nat.
nat_elim (\_. Nat)
Zero
(\n : Nat. \rec : Nat. plus rec y)
x;;
test_times :: Forall (x : Nat). times two x = times_two x;;
test_times := \x : Nat. Refl Nat (times two x);;
apply :: Forall (A : Type). Forall (B : Type). (A -> B) -> A -> B;;
apply := \A. \B. \f. \x. f x;;
dependent_apply :: Forall (A : Type). Forall (B : A -> Type). Forall (x : A). (A -> (B x)) -> B x;;
dependent_apply := \A. \B. \x. \f. f x;;
# Postulate
my_nat_elim :: Forall (goal : (Nat -> Type)). goal Zero -> Forall (ind : (Forall (n : Nat). Forall (IH : goal n). goal (Succ n))). Forall (x : Nat). goal x;;
plus_Z_again :: Forall (x : Nat). (plus x Zero) = x;;
plus_Z_again := \x. my_nat_elim
(\z. (plus z Zero) = z)
(Refl Nat Zero)
(\n. \h. f_eq Nat Nat (plus n Zero) n succ h)
x;;
six :: Nat;;
six := plus (plus two two) two;;
sum :: Nat -> Nat;;
sum := \x. nat_elim (\_. Nat) Zero (\n : Nat. \rec : Nat. plus n rec) (Succ x);;
test_plus_2 :: six = (sum three);;
test_plus_2 := Refl Nat six;;
test_sum_prop :: (sum (times_two two)) = times two (Succ (times_two two));;
test_sum_prop := Refl Nat (sum (times_two two));;
Normalize (sum three);;
or_nat :: Nat | Nat;;
or_nat := inl Zero;;
or_id :: (Nat -> Nat) | (Forall (A : Type). A -> A);;
or_id := inr id;;
Normalize (id_nat (sum six));;
test_id_nat :: (id_nat (sum six)) = sum six;;
test_id_nat := Refl Nat (sum six);;
test_pair :: Nat * Nat;;
test_pair := < Zero , Zero >;;
Normalize (Fst test_pair);;
# CH Correspondence
case_sum :: Forall (A : Type). Forall (B : Type). Forall (C : Type). (A -> C) -> (B -> C) -> (A | B) -> C;;
case_sum := \A. \B. \C. \fac. \fbc. \ab.
sum_elim (\_. C) (\l. fac l) (\r. fbc r) ab;;
case_prod :: Forall {A : Type}. Forall {B : Type}. Forall {C : Type}. (A -> C) -> (B -> C) -> (A * B) -> C;;
case_prod := \ac. \_. \ab. ac (Fst ab);;
weaken :: Forall (A : Type). Forall (B : Type). Forall (C : Type). (C -> A) -> (C -> (A | B));;
weaken := \A. \B. \C. \fca. \c. inl (fca c);;
prod_weaken :: Forall (A : Type). Forall (B : Type). (A * B) -> (A | B);;
prod_weaken := \A. \B. \prod. inl (Fst prod);;
f_comp :: Forall (A : Type). Forall (B : Type). Forall (C : Type). (B -> C) -> (A -> B) -> (A -> C);;
f_comp := \A. \B. \C. \bc. \ab. (\x. bc (ab x));;
dependent_comp :: Forall (A : Type).
Forall (B : A -> Type).
Forall (C : (Forall (x : A). B x -> Type)).
Forall (f : (Forall (x : A). Forall (y : (B x)). C x y)).
Forall (g : Forall (x : A). B x).
Forall (x : A). C x (g x);;
dependent_comp := \A. \B. \C. \f. \g. \x : A. f x (g x);;
proj_1 :: Forall (A : Type). Forall (B : Type). Forall (x : A * B). A;;
proj_1 := \A. \B. \p. Fst p;;
proj_2 :: Forall (A : Type). Forall (B : Type). Forall (x : A * B). B;;
proj_2 := \A. \B. \p. Snd p;;
inj_1 :: Forall (A : Type). Forall (B : Type). Forall (x : A). A | B;;
inj_1 := \A. \B. \x. inl x;;
inj_2 :: Forall (A : Type). Forall (B : Type). Forall (x : B). A | B;;
inj_2 := \A. \B. \x. inr x;;
arr_distrib :: Forall (A : Type). Forall (B : Type). Forall (C : Type). ((A | B) -> C) -> ((A -> C) * (B -> C));;
arr_distrib := \A. \B. \C. \f. < f_comp A (A | B) C f (inj_1 A B) , f_comp B (A | B) C f (inj_2 A B) >;;
inj_1_impli :: Forall {A : Type}. Forall {B : Type}. Forall (x : A). A | B;;
inj_1_impli := \x. inl x;;
inj_2_impli :: Forall {A : Type}. Forall {B : Type}. Forall (x : B). A | B;;
inj_2_impli := \x. inr x;;
f_comp_impli :: Forall {A : Type}. Forall {B : Type}. Forall {C : Type}. (B -> C) -> (A -> B) -> (A -> C);;
f_comp_impli := \bc. \ab. (\x. bc (ab x));;
arr_distrib_impli :: Forall {A : Type}. Forall {B : Type}. Forall {C : Type}. ((A | B) -> C) -> ((A -> C) * (B -> C));;
arr_distrib_impli := \f. < f_comp_impli f inj_1_impli , f_comp_impli f inj_2_impli >;;
Normalize (inj_1_impli Zero);;
refl :: Forall {A : Type}. Forall {x : A}. x = x;;
refl := \{A}. \{x}. Refl A x;;
eq_number :: six = six;;
eq_number := refl;;
eq_trans_impli :: Forall {A : Type}. Forall {a : A}. Forall {b : A}. Forall {c : A}. a = b -> b = c -> a = c;;
eq_trans_impli := \{A}. \{a}. \{b}. \{c}. \Eab.
eq_elim A (\u. \v. v = c -> u = c)
(\w : A. id_impli)
Eab;;
eq_sym_impli :: Forall {A : Type}. Forall {a : A}. Forall {b : A}. a = b -> b = a;;
eq_sym_impli := \{A}. \{a}. \{b}. \eq.
eq_elim A (\u.\v. v = u)
(\w. refl)
eq;;
f_eq_impli :: Forall {A : Type}. Forall {B : Type}. Forall {x : A}. Forall {y : A}. Forall (f : A -> B). x = y -> (f x) = (f y);;
f_eq_impli := \{A}. \{B}. \{x}. \{y}. \f. \eqf.
eq_elim A
(\u. \v. (f u) = (f v))
(\w. refl)
eqf;;
plus_Z_simpler :: Forall (x : Nat). (plus x Zero) = x;;
plus_Z_simpler := \x. nat_elim (\z. (plus z Zero) = z)
refl
(\n. \h. f_eq_impli succ h)
x;;
plus_nSm_simpler :: Forall (x : Nat). Forall (y : Nat). (plus x (succ y)) = (succ (plus x y));;
plus_nSm_simpler := \x. \y.
nat_elim (\z. (plus z (succ y)) = (succ (plus z y)))
(f_eq_impli succ refl)
(\n. \IH : ((plus n (succ y)) = (succ (plus y n))). f_eq_impli succ IH)
x;;
plus_comm_simpler :: Forall (x : Nat). Forall (y : Nat). (plus x y) = (plus y x);;
plus_comm_simpler := \x. \y.
nat_elim (\z. (plus z y) = (plus y z))
(eq_sym_impli (plus_Z y))
(\n. \IH.
eq_trans_impli
(f_eq_impli succ IH)
(eq_sym_impli (plus_nSm y n)))
x;;
uip :: Forall {A : Type}. Forall {x : A}. Forall {y : A}. Forall {p : x = y}. Forall {q : x = y}. p = q;;
uip := refl;;
Normalize (id_impli six);;
application :: Nat;;
application := succ two;;
Normalize application;;
trivial_prop :: Forall {x : Nat}. Forall {y : Nat}. x = y -> succ x = succ y;;
trivial_prop := \{x}. \{y}. \eq_xy. eq_elim Nat (\n. \m. succ n = succ m) (\w. refl) eq_xy;;
Data Natural : Type where
Z : Natural
| S : Natural -> Natural;;
Data NatTree : Type where
Leaf : (Natural -> NatTree)
| Branch : (Natural -> NatTree -> NatTree -> NatTree);;
# NaturalElim : Forall (n : Natural).
# Forall (goal : Natural -> Type).
# Forall (base : goal Z).
# Forall (x : Natural). goal x -> goal (S x).
# goal n;;