-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlpprint.ml
379 lines (362 loc) · 13.2 KB
/
lpprint.ml
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
open Printf
open Dkterm
(* taken on 25/06/24 from
https://github.com/Deducteam/lambdapi/blob/master/src/parsing/lpLexer.ml *)
let forbidden_idents = [
"abort"
; "admit"
; "admitted"
; "apply"
; "as"
; "assert"
; "assertnot"
; "associative"
; "assume"
; "begin"
; "builtin"
; "coerce_rule"
; "commutative"
; "compute"
; "constant"
; "debug"
; "end"
; "fail"
; "flag"
; "generalize"
; "have"
; "in"
; "induction"
; "inductive"
; "infix"
; "injective"
; "left"
; "let"
; "notation"
; "off"
; "on"
; "opaque"
; "open"
; "postfix"
; "prefix"
; "print"
; "private"
; "proofterm"
; "protected"
; "prover"
; "prover_timeout"
; "quantifier"
; "refine"
; "reflexivity"
; "remove"
; "require"
; "rewrite"
; "right"
; "rule"
; "search"
; "sequential"
; "simplify"
; "solve"
; "symbol"
; "symmetry"
; "try"
; "type"
; "TYPE"
; "unif_rule"
; "verbose"
; "why3"
; "with"
; "`"
; ","
; ":"
; "|"
; "_"
]
let escape_name s =
let id_regex = Str.regexp "^[a-zA-Z_][a-zA-Z0-9_]*$" in
if Str.string_match id_regex s 0
&& List.for_all ((<>) s) forbidden_idents
then s else "{|" ^ s ^ "|}"
let rec print_dk_type_aux o (t, var_context) =
match t with
| Dktypetype -> fprintf o "Set"
| Dktypeprop -> fprintf o "Prop"
| Dkarrow (l, r) ->
begin
List.iter (fun x -> fprintf o "%a → " print_dk_type_aux (x, var_context)) l;
print_dk_type_aux o (r, var_context);
end
| Dkpi (Dkvar (_, t1) as var, t2) ->
let pvar = escape_name (get_var_newname var) in
fprintf o "Π (%s : %a),\n %a"
pvar print_dk_type_aux (t1, var_context) print_dk_type_aux (t2, pvar::var_context)
| Dkpi _ -> assert false
| Dkproof (t) ->
fprintf o "π (%a)" print_dk_term_aux (t, var_context)
| t -> fprintf o "τ (%a)" print_dk_zentype_aux (t, var_context)
and print_dk_type o t = print_dk_type_aux o (t, [])
and print_dk_zentype_aux o (t, l) =
match t with
| Dktypeiota -> fprintf o "ι"
| t -> print_dk_term_aux o (t, l)
(* and print_dk_zentype o t = print_dk_zentype_aux o (t, []) *)
and print_dk_cst typ o (t, var_context) =
let is_formula = match typ with Dkproof _ -> true | _ -> false in
match t with
| "Is_true" -> fprintf o "dk_logic.ebP"
| "FOCAL.ifthenelse" -> fprintf o "dk_bool.ite"
| s ->
if Mltoll.is_meta s then fprintf o "select (%a)" print_dk_zentype_aux (typ, var_context)
else
begin
fprintf o (if !Globals.lp_package = "" then "%s"
else if is_formula then "F.%s"
else "S.%s")
(escape_name s);
if !Globals.conjecture <> "" && is_formula
&& not !Globals.check_axiom && Typetptp.is_axiom s then
fprintf o " __negated_conjecture_proof__"
end
and print_dk_term_aux o (t, var_context) =
match t with
| Dkvar (v, t) as var ->
let pvar = (escape_name (get_var_newname var)) in
if not (List.mem pvar var_context)
then fprintf o "select (%a)" print_dk_zentype_aux (t, var_context)
else fprintf o "%s" pvar
| Dklam (Dkvar (_, t1) as var, t2) ->
let pvar = (escape_name (get_var_newname var)) in
fprintf o "λ (%s : %a),\n %a"
pvar
print_dk_type_aux (t1, var_context) print_dk_term_aux (t2, (pvar::var_context))
| Dklam (Dkapp (v, t1, []), t2) ->
let pvar = escape_name v in
fprintf o "λ (%s : %a),\n %a"
pvar print_dk_type_aux (t1, var_context) print_dk_term_aux (t2, (pvar::var_context))
| Dklam _ -> assert false
| Dkapp (v, t, l) ->
begin
print_dk_cst t o (v, var_context);
List.iter (fun x -> fprintf o " (%a)" print_dk_term_aux (x, var_context)) l;
(* fprintf o "\n ";*)
end
| Dkseq -> fprintf o "π ⊥"
| Dknot (t) ->
fprintf o "¬\n (%a)" print_dk_term_aux (t, var_context)
| Dkand (t1, t2) ->
fprintf o "(%a)\n∧\n(%a)\n" print_dk_term_aux (t1, var_context) print_dk_term_aux (t2, var_context)
| Dkor (t1, t2) ->
fprintf o "(%a)\n∨\n(%a)\n" print_dk_term_aux (t1, var_context) print_dk_term_aux (t2, var_context)
| Dkimply (t1, t2) ->
fprintf o "(%a)\n⇒\n(%a)\n" print_dk_term_aux (t1, var_context) print_dk_term_aux (t2, var_context)
| Dkequiv (t1, t2) ->
fprintf o "(%a)\n⇔\n(%a)\n" print_dk_term_aux (t1, var_context) print_dk_term_aux (t2, var_context)
| Dkforall (_, t2) ->
fprintf o "∀ (%a)" print_dk_term_aux (t2, var_context)
(* fprintf o "@∀ (%a)\n (%a)" print_dk_zentype_aux (t1, var_context) print_dk_term_aux (t2, var_context) *)
| Dkexists (_, t2) ->
fprintf o "∃ (%a)" print_dk_term_aux (t2, var_context)
(* fprintf o "@∃ (%a)\n (%a)" print_dk_zentype_aux (t1, var_context) print_dk_term_aux (t2, var_context) *)
| Dkforalltype (t) ->
fprintf o "foralltype\n (%a)" print_dk_term_aux (t, var_context)
| Dkexiststype (t) ->
fprintf o "existstype\n (%a)" print_dk_term_aux (t, var_context)
| Dktrue -> fprintf o "⊤"
| Dkfalse -> fprintf o "⊥"
| Dkequal (_, t2, t3) ->
fprintf o "(%a) = (%a)"
print_dk_term_aux (t2, var_context)
print_dk_term_aux (t3, var_context)
| DkRfalse (pr) -> fprintf o "Rfalse\n (%a)" print_dk_term_aux (pr, var_context)
| DkRnottrue (pr) -> fprintf o "Rnottrue\n (%a)" print_dk_term_aux (pr, var_context)
| DkRaxiom (p, pr1, pr2) ->
fprintf o "Raxiom\n (%a)\n (%a)\n (%a)\n"
print_dk_term_aux (p, var_context)
print_dk_term_aux (pr1, var_context)
print_dk_term_aux (pr2, var_context)
| DkRnoteq (a, t, pr) ->
fprintf o "Rnoteq\n (%a)\n (%a)\n (%a)\n"
print_dk_zentype_aux (a, var_context)
print_dk_term_aux (t, var_context)
print_dk_term_aux (pr, var_context)
| DkReqsym (a, t, u, pr1, pr2) ->
fprintf o "Reqsym\n (%a)\n (%a)\n (%a)\n (%a)\n (%a)\n"
print_dk_zentype_aux (a, var_context)
print_dk_term_aux (t, var_context)
print_dk_term_aux (u, var_context)
print_dk_term_aux (pr1, var_context)
print_dk_term_aux (pr2, var_context)
| DkRcut (p, pr1, pr2) ->
fprintf o "Rcut\n (%a)\n (%a)\n (%a)\n"
print_dk_term_aux (p, var_context)
print_dk_term_aux (pr1, var_context)
print_dk_term_aux (pr2, var_context)
| DkRnotnot (p, pr1, pr2) ->
fprintf o "Rnotnot\n (%a)\n (%a)\n (%a)\n"
print_dk_term_aux (p, var_context)
print_dk_term_aux (pr1, var_context)
print_dk_term_aux (pr2, var_context)
| DkRand (p, q, pr1, pr2) ->
fprintf o "Rand\n (%a)\n (%a)\n (%a)\n (%a)\n"
print_dk_term_aux (p, var_context)
print_dk_term_aux (q, var_context)
print_dk_term_aux (pr1, var_context)
print_dk_term_aux (pr2, var_context)
| DkRor (p, q, pr1, pr2, pr3) ->
fprintf o "Ror\n (%a)\n (%a)\n (%a)\n (%a)\n (%a)\n"
print_dk_term_aux (p, var_context)
print_dk_term_aux (q, var_context)
print_dk_term_aux (pr1, var_context)
print_dk_term_aux (pr2, var_context)
print_dk_term_aux (pr3, var_context)
| DkRimply (p, q, pr1, pr2, pr3) ->
fprintf o "Rimply\n (%a)\n (%a)\n (%a)\n (%a)\n (%a)\n"
print_dk_term_aux (p, var_context)
print_dk_term_aux (q, var_context)
print_dk_term_aux (pr1, var_context)
print_dk_term_aux (pr2, var_context)
print_dk_term_aux (pr3, var_context)
| DkRequiv (p, q, pr1, pr2, pr3) ->
fprintf o "Requiv\n (%a)\n (%a)\n (%a)\n (%a)\n (%a)\n"
print_dk_term_aux (p, var_context)
print_dk_term_aux (q, var_context)
print_dk_term_aux (pr1, var_context)
print_dk_term_aux (pr2, var_context)
print_dk_term_aux (pr3, var_context)
| DkRnotand (p, q, pr1, pr2, pr3) ->
fprintf o "Rnotand\n (%a)\n (%a)\n (%a)\n (%a)\n (%a)\n"
print_dk_term_aux (p, var_context)
print_dk_term_aux (q, var_context)
print_dk_term_aux (pr1, var_context)
print_dk_term_aux (pr2, var_context)
print_dk_term_aux (pr3, var_context)
| DkRnotor (p, q, pr1, pr2) ->
fprintf o "Rnotor\n (%a)\n (%a)\n (%a)\n (%a)\n"
print_dk_term_aux (p, var_context)
print_dk_term_aux (q, var_context)
print_dk_term_aux (pr1, var_context)
print_dk_term_aux (pr2, var_context)
| DkRnotimply (p, q, pr1, pr2) ->
fprintf o "Rnotimply\n (%a)\n (%a)\n (%a)\n (%a)\n"
print_dk_term_aux (p, var_context)
print_dk_term_aux (q, var_context)
print_dk_term_aux (pr1, var_context)
print_dk_term_aux (pr2, var_context)
| DkRnotequiv (p, q, pr1, pr2, pr3) ->
fprintf o "Rnotequiv\n (%a)\n (%a)\n (%a)\n (%a)\n (%a)\n"
print_dk_term_aux (p, var_context)
print_dk_term_aux (q, var_context)
print_dk_term_aux (pr1, var_context)
print_dk_term_aux (pr2, var_context)
print_dk_term_aux (pr3, var_context)
| DkRex (a, p, pr1, pr2) ->
fprintf o "Rex\n (%a)\n (%a)\n (%a)\n (%a)\n"
print_dk_zentype_aux (a, var_context)
print_dk_term_aux (p, var_context)
print_dk_term_aux (pr1, var_context)
print_dk_term_aux (pr2, var_context)
| DkRall (a, p, t, pr1, pr2) ->
fprintf o "Rall\n (%a)\n (%a)\n (%a)\n (%a)\n (%a)\n"
print_dk_zentype_aux (a, var_context)
print_dk_term_aux (p, var_context)
print_dk_term_aux (t, var_context)
print_dk_term_aux (pr1, var_context)
print_dk_term_aux (pr2, var_context)
| DkRnotex (a, p, t, pr1, pr2) ->
fprintf o "Rnotex\n (%a)\n (%a)\n (%a)\n (%a)\n (%a)\n"
print_dk_zentype_aux (a, var_context)
print_dk_term_aux (p, var_context)
print_dk_term_aux (t, var_context)
print_dk_term_aux (pr1, var_context)
print_dk_term_aux (pr2, var_context)
| DkRnotall (a, p, pr1, pr2) ->
fprintf o "Rnotall\n (%a)\n (%a)\n (%a)\n (%a)\n"
print_dk_zentype_aux (a, var_context)
print_dk_term_aux (p, var_context)
print_dk_term_aux (pr1, var_context)
print_dk_term_aux (pr2, var_context)
| DkRextype (p, pr1, pr2) ->
fprintf o "Rextype\n (%a)\n (%a)\n (%a)\n"
print_dk_term_aux (p, var_context)
print_dk_term_aux (pr1, var_context)
print_dk_term_aux (pr2, var_context)
| DkRalltype (p, a, pr1, pr2) ->
fprintf o "Ralltype\n (%a)\n (%a)\n (%a)\n (%a)\n"
print_dk_term_aux (p, var_context)
print_dk_zentype_aux (a, var_context)
print_dk_term_aux (pr1, var_context)
print_dk_term_aux (pr2, var_context)
| DkRnotextype (p, a, pr1, pr2) ->
fprintf o "Rnotextype\n (%a)\n (%a)\n (%a)\n (%a)\n"
print_dk_term_aux (p, var_context)
print_dk_zentype_aux (a, var_context)
print_dk_term_aux (pr1, var_context)
print_dk_term_aux (pr2, var_context)
| DkRnotalltype (p, pr1, pr2) ->
fprintf o "Rnotalltype\n (%a)\n (%a)\n (%a)\n"
print_dk_term_aux (p, var_context)
print_dk_term_aux (pr1, var_context)
print_dk_term_aux (pr2, var_context)
| DkRsubst (a, p, t1, t2, pr1, pr2, pr3) ->
fprintf o "Rsubst\n (%a)\n (%a)\n (%a)\n (%a)\n (%a)\n (%a)\n (%a)\n"
print_dk_zentype_aux (a, var_context)
print_dk_term_aux (p, var_context)
print_dk_term_aux (t1, var_context)
print_dk_term_aux (t2, var_context)
print_dk_term_aux (pr1, var_context)
print_dk_term_aux (pr2, var_context)
print_dk_term_aux (pr3, var_context)
| DkRconglr (a, p, t1, t2, pr1, pr2, pr3) ->
fprintf o "Rconglr\n (%a)\n (%a)\n (%a)\n (%a)\n (%a)\n (%a)\n (%a)\n"
print_dk_zentype_aux (a, var_context)
print_dk_term_aux (p, var_context)
print_dk_term_aux (t1, var_context)
print_dk_term_aux (t2, var_context)
print_dk_term_aux (pr1, var_context)
print_dk_term_aux (pr2, var_context)
print_dk_term_aux (pr3, var_context)
| DkRcongrl (a, p, t1, t2, pr1, pr2, pr3) ->
fprintf o "Rcongrl\n (%a)\n (%a)\n (%a)\n (%a)\n (%a)\n (%a)\n (%a)\n"
print_dk_zentype_aux (a, var_context)
print_dk_term_aux (p, var_context)
print_dk_term_aux (t1, var_context)
print_dk_term_aux (t2, var_context)
print_dk_term_aux (pr1, var_context)
print_dk_term_aux (pr2, var_context)
print_dk_term_aux (pr3, var_context)
| _ -> assert false
and print_dk_term o t = print_dk_term_aux o (t, [])
(* let rec pr_list_var o l =
match l with
| [] -> ()
| [Dkvar (v, t) as var] ->
fprintf o "%s : %a" (get_var_newname var) print_dk_type t
| (Dkvar (v, t) as var) :: tl ->
fprintf o "%s : %a, %a"
(get_var_newname var)
print_dk_type t
pr_list_var tl
| _ -> assert false *)
let rec get_var_names l =
match l with
| [] -> []
| (Dkvar (_, _) as var) :: l' -> (escape_name (get_var_newname var)) :: (get_var_names l')
| _ -> assert false
let print_line o line =
match line with
| Dkdecl (v, _) when String.contains v '.' ->
()
| Dkdecl (v, t) ->
fprintf o "symbol %s : %a;\n\n" (escape_name v) print_dk_type t
| Dkrwrt (_, Dkapp (s, _, _), _) when String.contains s '.' || s = "Is_true" ->
()
| Dkrwrt (l, t1, t2) ->
(* fprintf o "[%a]\n %a \n → %a\n\n"
pr_list_var l print_dk_term_aux (t1, get_var_names l) print_dk_term_aux (t2, get_var_names l) *)
fprintf o "rule %a \n ↪ %a;\n\n"
print_dk_term_aux (t1, get_var_names l) print_dk_term_aux (t2, get_var_names l)
let print_goal_type o name goal =
fprintf o "symbol %s :\n %a\n → %a\n"
(escape_name name) print_dk_type goal print_dk_term mk_seq
let print_proof o _ proof =
fprintf o "%a\n"
print_dk_term proof