-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
executable file
·262 lines (162 loc) · 4.65 KB
/
tests.py
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
from main import *
####################################################################################################
# TODO: need some test cases around beta reduction
# TODO: need some test cases around renaming equivelence
@dependent
def ident(A: Prop) -> Prop:
return A
A = VAR("A")
@dependent
def ident(A: Prop, a: A) -> A:
return a
# but not
try:
A = VAR("A")
@dependent
def ident_bad(a: A) -> A:
return a
except:
pass
else:
assert False, "should throw error"
try:
A = VAR("A")
@dependent
def ident_bad(A: Prop, a: Prop) -> A:
return a
except:
pass
else:
assert False, "should throw error"
try:
A = VAR("A")
@dependent
def ident_bad(A: Prop, a: A) -> Prop:
return a
except:
pass
else:
assert False, "should throw error"
try:
A = VAR("A")
@dependent
def ident_bad(A: Prop, a: A) -> A:
return A
except:
pass
else:
assert False, "should throw error"
#############################################
_ = VAR("_")
A = VAR("A")
B = VAR("B")
a = VAR("a")
@dependent
def impl(A: Prop, B: Prop, a: A, a_to_b: Π(a, A, B)) -> B:
return a_to_b(a)
assert impl(str, int, "hi", len) == 2, "this might seem crazy... but these are perfectly valid python functions"
assert impl(_, _, "hi", len) == 2, "for now I'm begrudgingly accepting the python convention of erasing type constraints at runtime"
A = VAR("A")
B = VAR("B")
C = VAR("C")
@dependent
def cut_elim(A: Prop, B: Prop, C: Prop, a_to_b: Π(_, A, B), b_to_c: Π(_, B, C)) -> Π(_, A, C):
@dependent
def inner(a: A) -> C:
return b_to_c(
a_to_b(a)
)
return inner
try:
A = VAR("A")
B = VAR("B")
C = VAR("C")
@dependent
def func2bad(A: Prop, B: Prop, C: Prop, a_to_b: Π(_, A, B), b_to_c: Π(_, B, C)) -> Π(_, A, C):
@dependent
def inner(a: A) -> C:
return b_to_c(a)
return inner
except:
pass
else:
assert False, "should throw error"
A = VAR("A")
@dependent
def ident2(A: Prop) -> Π(_, A, A):
@dependent
def inner(a: A) -> A:
return a
return inner
################################################
# TODO: now obvously we want and_def as an implicit assumption, defined in a library somewhere
# for all A,B. A and B is a prop which means that any output created by any function that takes in A and B is achivable
# note that this funciton chould have been defined in any scope
@dependent
def and_def(A: Prop, B: Prop) -> Prop:
Output = VAR("Output")
AnyFunc = VAR("AnyFunc")
return Π(Output, Prop,
Π(AnyFunc, Π(_, A, Π(_, B, Output)),
Output))
A = VAR("A")
B = VAR("B")
# aa = and_def(A, B)
# print("hi")
# print(type(and_def)==function)
@dependent
def and_left_elim(A: Prop, B: Prop,
AandB: and_def(A, B)) -> A:
# TODO: need to handle the super akward case where, dependent vars are computed on (could lead to unsoundness)(?)
@dependent
def take_A_ignore_B(a: A, b: B) -> A:
return a
return AandB(A, take_A_ignore_B)
A = VAR("A")
B = VAR("B")
def and_intro(A: Prop, B: Prop, a: A, b: B) -> and_def(A, B):
Output = VAR("Output")
def any_output_any_func(Output: Prop, AnyFunc: Π(_, A, Π(_, B, Output))) -> Output:
return AnyFunc(a, b)
return any_output_any_func
# type level equality
def eq_def(A: Prop, B: Prop) -> Prop:
P = VAR("P")
x = VAR("x")
return Π(P, Π(_, Prop, Π(_, Prop, Prop)), # any porperty
Π(_, Π(x, Prop, P(x, x)), # (evidence) that respects equivelence
P(A, B) # will have the pair A B
))
A = VAR("A")
# for all types A. A=A
# note that this also denotes the inhabiteant refl
def proof_eq_reflexive(
A: Prop,
) -> eq_def(A, A):
P = VAR("P")
x = VAR("x")
def inner(P: Π(_, Prop, Π(_, Prop, Prop)),
pxx: Π(x, Prop, P(x, x)) # TODO: rename pcc
) -> P(A, A):
return pxx(A)
return inner
def swap_args(P: Π(_, Prop, Π(_, Prop, Prop))) -> Π(_, Prop, Π(_, Prop, Prop)):
def inner(A: Prop, B: Prop) -> Prop:
return P(B, A)
return inner
A = VAR("A")
B = VAR("B")
# for all types A. A=A
# note that this also denotes the inhabiteant refl
def proof_eq_sym(
A: Prop, B: Prop,
AandB: eq_def(A, B)
) -> eq_def(B, A):
P = VAR("P")
x = VAR("x")
def inner(P: Π(_, Prop, Π(_, Prop, Prop)),
pxx: Π(x, Prop, P(x, x)) # TODO: rename pcc
) -> P(B, A):
return AandB(swap_args(P), pxx)
return inner
# TODO: eq transitive