Source file core.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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
module Id = Dolmen.Std.Id
module Ast = Dolmen.Std.Term
module Ae = struct
module Tff
(Type : Tff_intf.S)
(Tag : Dolmen.Intf.Tag.Ae_Base with type 'a t = 'a Type.Tag.t
and type term := Type.T.t)
(Ty : Dolmen.Intf.Ty.Ae_Base with type t = Type.Ty.t)
(T : Dolmen.Intf.Term.Ae_Base with type t = Type.T.t
and type term_var := Type.T.Var.t) = struct
let mk_or a b = T._or [a; b]
let mk_and a b = T._and [a; b]
let parse_trigger env ast = function
| { Ast.term = Ast.App (
{ Ast.term = Ast.Builtin And; _ }, l
); _} ->
List.map (Type.parse_term env) l
| _ ->
Type._error env (Ast ast)
(Type.Expected ("A multi-trigger (i.e. a list of term patterns)", None))
let parse env s =
match s with
| Type.Builtin Ast.Bool ->
`Ty (Base.app0 (module Type) env s Ty.bool)
| Type.Builtin Ast.Prop ->
`Ty (Base.app0 (module Type) env s Ty.bool)
| Type.Builtin Ast.Unit ->
`Ty (Base.app0 (module Type) env s Ty.unit)
| Type.Builtin Ast.Void ->
`Term (Base.app0 (module Type) env s T.void)
| Type.Builtin Ast.True ->
`Term (Base.app0 (module Type) env s T._true)
| Type.Builtin Ast.False ->
`Term (Base.app0 (module Type) env s T._false)
| Type.Builtin Ast.Not ->
`Term (Base.term_app1 (module Type) env s T.neg)
| Type.Builtin Ast.And ->
`Term (Base.term_app_left (module Type) env s mk_and)
| Type.Builtin Ast.Or ->
`Term (Base.term_app_left (module Type) env s mk_or)
| Type.Builtin Ast.Xor ->
`Term (Base.term_app_left (module Type) env s T.xor)
| Type.Builtin Ast.Imply ->
`Term (Base.term_app_right (module Type) env s T.imply)
| Type.Builtin Ast.Equiv ->
`Term (Base.term_app_right (module Type) env s T.equiv)
| Type.Builtin Ast.Ite ->
`Term (
Base.make_op3 (module Type) env s (fun _ (a, b, c) ->
let cond = Type.parse_prop env a in
let then_ = Type.parse_term env b in
let else_ = Type.parse_term env c in
T.ite cond then_ else_
)
)
| Type.Builtin Ast.Eq ->
`Term (
fun ast args ->
match args with
| [Ast.{
term = App ( { term = Builtin Eq; _ }, [_; lr_st] ); _
} as l_st; r_st] ->
Base.term_app_list (module Type) env s
T._and ast [l_st; Ast.eq lr_st r_st]
| _ ->
Base.term_app2 (module Type) env s T.eq ast args
)
| Type.Builtin Ast.Distinct ->
`Term (Base.term_app_list (module Type) env s T.distinct)
| Type.Id { name = Simple "ac"; ns = Attr; }->
`Tags (fun _ _ -> [Type.Set (Tag.ac, ())])
| Type.Id { name = Simple n; ns = Track; }->
`Tags (fun _ _ -> [Type.Set (Tag.named, n)])
| Type.Id { name = Simple "triggers"; ns = Attr; } ->
`Tags (fun ast l ->
let l = List.map (parse_trigger env ast) l in
[Type.Set (Tag.triggers, l)]
)
| Type.Id { name = Simple "filters"; ns = Attr; } ->
`Tags (fun _ l ->
let l = List.map (Type.parse_prop env) l in
[Type.Set (Tag.filters, l)]
)
| Type.Builtin (Ast.In_interval (b1, b2)) ->
`Term (Base.term_app3_ast (module Type) env s
(fun _ast _a1 _a2 _a3 ->
T.in_interval _a1 (b1, b2) _a2 _a3))
| Type.Builtin Ast.Maps_to ->
`Term (
fun ast args ->
begin match args with
| [var; t] ->
let t = Type.parse_term env t in
begin match var with
| { Ast.term = Ast.Symbol sym; _ }
| { Ast.term =
Ast.App ({ Ast.term = Ast.Symbol sym; _ }, []); _
} ->
begin
match Type.find_bound env sym with
| `Term_var v -> T.maps_to v t
| _ -> Type._error env (Ast ast) (Type.Cannot_find (sym, ""))
end
| _ -> Type._error env (Ast ast) (Type.Expected ("Variable name", None))
end
| l -> Type._error env (Ast ast) (Type.Bad_op_arity (s, [2], List.length l))
end
)
| _ -> `Not_found
end
end
module Dimacs = struct
module Tff
(Type : Tff_intf.S)
(T : Dolmen.Intf.Term.Dimacs with type t = Type.T.t) = struct
let parse env s =
match s with
| Type.Builtin Ast.Not ->
`Term (Base.term_app1 (module Type) env s T.neg)
| _ -> `Not_found
end
end
module Tptp = struct
module Tff
(Type : Tff_intf.S)
(Ty : Dolmen.Intf.Ty.Tptp_Base with type t = Type.Ty.t)
(T : Dolmen.Intf.Term.Tptp_Tff_Core with type t = Type.T.t) = struct
let mk_or a b = T._or [a; b]
let mk_and a b = T._and [a; b]
let parse _version env s =
match s with
| Type.Id { name = Simple "$tType"; ns = Term } ->
`Ttype (Base.app0 (module Type) env s ())
| Type.Id { name = Simple "$o"; ns = Term } ->
`Ty (Base.app0 (module Type) env s Ty.prop)
| Type.Id { name = Simple "$i"; ns = Term } ->
`Ty (Base.app0 (module Type) env s Ty.base)
| Type.Id { name = Simple "$true"; ns = Term } ->
`Term (Base.app0 (module Type) env s T._true)
| Type.Id { name = Simple "$false"; ns = Term } ->
`Term (Base.app0 (module Type) env s T._false)
| Type.Builtin Ast.Eq ->
`Term (Base.term_app2 (module Type) env s T.eq)
| Type.Builtin Ast.Distinct ->
`Term (Base.term_app_list (module Type) env s T.distinct)
| Type.Id { name = Simple "$distinct"; ns = Term; } ->
`Term (Base.term_app_list (module Type) env s T.distinct)
| Type.Builtin Ast.Not ->
`Term (Base.term_app1 (module Type) env s T.neg)
| Type.Builtin Ast.Or ->
`Term (Base.term_app2 (module Type) env s mk_or)
| Type.Builtin Ast.And ->
`Term (Base.term_app2 (module Type) env s mk_and)
| Type.Builtin Ast.Xor ->
`Term (Base.term_app2 (module Type) env s T.xor)
| Type.Builtin Ast.Nor ->
`Term (Base.term_app2 (module Type) env s T.nor)
| Type.Builtin Ast.Nand ->
`Term (Base.term_app2 (module Type) env s T.nand)
| Type.Builtin Ast.Equiv ->
`Term (Base.term_app2 (module Type) env s T.equiv)
| Type.Builtin Ast.Imply ->
`Term (Base.term_app2 (module Type) env s T.imply)
| Type.Builtin Ast.Implied ->
`Term (Base.term_app2 (module Type) env s T.implied)
| Type.Builtin Ast.Ite ->
`Term (
Base.make_op3 (module Type) env s (fun _ (a, b, c) ->
let cond = Type.parse_prop env a in
let then_ = Type.parse_term env b in
let else_ = Type.parse_term env c in
T.ite cond then_ else_
)
)
| Type.Id id when Id.equal id Id.tptp_role ->
`Tags (fun _ast _args -> [])
| Type.Id id when Id.equal id Id.tptp_kind ->
`Tags (fun _ast _args -> [])
| _ -> `Not_found
end
module Thf
(Type : Thf_intf.S)
(Ty : Dolmen.Intf.Ty.Tptp_Base with type t = Type.Ty.t)
(T : Dolmen.Intf.Term.Tptp_Thf_Core with type t = Type.T.t
and type Const.t = Type.T.Const.t) = struct
let parse _version env s =
match s with
| Type.Id { name = Simple "$tType"; ns = Term } ->
`Ttype (Base.app0 (module Type) env s ())
| Type.Id { name = Simple "$o"; ns = Term } ->
`Ty (Base.app0 (module Type) env s Ty.prop)
| Type.Id { name = Simple "$i"; ns = Term } ->
`Ty (Base.app0 (module Type) env s Ty.base)
| Type.Id { name = Simple "$true"; ns = Term } ->
`Term (Base.term_app_cst (module Type) env T.Const._true)
| Type.Id { name = Simple "$false"; ns = Term } ->
`Term (Base.term_app_cst (module Type) env T.Const._false)
| Type.Builtin Ast.Eq ->
`Term (Base.term_app_ho_ast (module Type) env
(fun ast -> Type.monomorphize env ast (T.of_cst T.Const.eq)))
| Type.Builtin Ast.Distinct ->
`Term (Base.term_app_list (module Type) env s T.distinct)
| Type.Id { name = Simple "$distinct"; ns = Term; } ->
`Term (Base.term_app_list (module Type) env s T.distinct)
| Type.Builtin Ast.Not ->
`Term (Base.term_app_cst (module Type) env T.Const.neg)
| Type.Builtin Ast.Or ->
`Term (Base.term_app_cst (module Type) env T.Const.or_)
| Type.Builtin Ast.And ->
`Term (Base.term_app_cst (module Type) env T.Const.and_)
| Type.Builtin Ast.Xor ->
`Term (Base.term_app_cst (module Type) env T.Const.xor)
| Type.Builtin Ast.Nor ->
`Term (Base.term_app_cst (module Type) env T.Const.nor)
| Type.Builtin Ast.Nand ->
`Term (Base.term_app_cst (module Type) env T.Const.nand)
| Type.Builtin Ast.Equiv ->
`Term (Base.term_app_cst (module Type) env T.Const.equiv)
| Type.Builtin Ast.Imply ->
`Term (Base.term_app_cst (module Type) env T.Const.imply)
| Type.Builtin Ast.Implied ->
`Term (Base.term_app_cst (module Type) env T.Const.implied)
| Type.Builtin Ast.Ite ->
`Term (Base.term_app_ho_ast (module Type) env
(fun ast -> Type.monomorphize env ast (T.of_cst T.Const.ite)))
| Type.Builtin Ast.Pi ->
`Term (Base.term_app_ho_ast (module Type) env
(fun ast -> Type.monomorphize env ast (T.of_cst T.Const.pi)))
| Type.Builtin Ast.Sigma ->
`Term (Base.term_app_ho_ast (module Type) env
(fun ast -> Type.monomorphize env ast (T.of_cst T.Const.sigma)))
| Type.Id id when Id.equal id Id.tptp_role ->
`Tags (fun _ast _args -> [])
| Type.Id id when Id.equal id Id.tptp_kind ->
`Tags (fun _ast _args -> [])
| _ -> `Not_found
end
end
module Smtlib2 = struct
module Tff
(Type : Tff_intf.S)
(Tag : Dolmen.Intf.Tag.Smtlib_Base with type 'a t = 'a Type.Tag.t
and type term := Type.T.t)
(Ty : Dolmen.Intf.Ty.Smtlib_Base with type t = Type.Ty.t)
(T : Dolmen.Intf.Term.Smtlib_Base with type t = Type.T.t
and type cstr := Type.T.Cstr.t) = struct
let parse_name env = function
| ({ Ast.term = Ast.Symbol s; _ } as ast)
| ({ Ast.term = Ast.App ({ Ast.term = Ast.Symbol s; _ }, []); _ } as ast) ->
begin match Dolmen.Std.Id.name s with
| Simple s -> s
| _ -> Type._error env (Ast ast) (Type.Expected ("simple name", None))
end
| ast ->
Type._error env (Ast ast) (Type.Expected ("symbol", None))
let parse_sexpr_list env = function
| { Ast.term = Ast.App (
{ Ast.term = Ast.Symbol { name = Simple "$data"; ns = Attr }; _ },
l); _} ->
l
| ast ->
Type._error env (Ast ast)
(Type.Expected ("a list of terms in a sexpr", None))
let mk_or a b = T._or [a; b]
let mk_and a b = T._and [a; b]
let parse_f env ast cstr args =
let loc = Ast.(ast.loc) in
let t = Ast.apply ~loc cstr args in
Type.parse_term env t
let parse _version env s =
match s with
| Type.Id { name = Simple "Bool"; ns = Sort } ->
`Ty (Base.app0 (module Type) env s Ty.prop)
| Type.Id { name = Simple "true"; ns = Term } ->
`Term (Base.app0 (module Type) env s T._true)
| Type.Id { name = Simple "false"; ns = Term } ->
`Term (Base.app0 (module Type) env s T._false)
| Type.Id { name = Simple "not"; ns = Term } ->
`Term (Base.term_app1 (module Type) env s T.neg)
| Type.Id { name = Simple "and"; ns = Term } ->
`Term (Base.term_app_left (module Type) env s mk_and)
| Type.Id { name = Simple "or"; ns = Term } ->
`Term (Base.term_app_left (module Type) env s mk_or)
| Type.Id { name = Simple "xor"; ns = Term } ->
`Term (Base.term_app_left (module Type) env s T.xor)
| Type.Id { name = Simple "=>"; ns = Term } ->
`Term (Base.term_app_right (module Type) env s T.imply)
| Type.Id { name = Simple "ite"; ns = Term } ->
`Term (
Base.make_op3 (module Type) env s (fun _ (a, b, c) ->
let cond = Type.parse_prop env a in
let then_ = Type.parse_term env b in
let else_ = Type.parse_term env c in
T.ite cond then_ else_
)
)
| Type.Id { name = Simple "distinct"; ns = Term } ->
`Term (fun _ast args ->
let args = List.map (Type.parse_term env) args in
T.distinct args)
| Type.Id { name = Simple "="; ns = Term } ->
`Term (Base.term_app_chain (module Type) env s T.eq)
| Type.Id { name = Simple ":named"; ns = Attr } ->
`Tags (Base.make_op1 (module Type) env s (fun _ t ->
let name = parse_name env t in
[Type.Set (Tag.named, name)]
))
| Type.Id { name = Simple ":pattern"; ns = Attr } ->
`Tags (Base.make_op1 (module Type) env s (fun _ t ->
let l = parse_sexpr_list env t in
let l = List.map (Type.parse_term env) l in
[Type.Add (Tag.triggers, l)]
))
| Type.Id { name = Simple "$data"; ns = Attr } ->
`Term (fun ast args ->
begin match args with
| f :: r -> parse_f env ast f r
| [] -> Type._error env (Ast ast)
(Type.Expected ("a non-empty s-expr", None))
end)
| Type.Id id when Id.equal id Id.rwrt_rule ->
`Tags (fun _ast _args -> [Type.Set (Tag.rwrt, ())])
| Type.Id { Id.ns = Term; name = Indexed { basename; indexes; } } as symbol ->
Base.parse_indexed basename indexes
~k:(fun _ -> `Not_found)
~err:(fun _ _ _ -> `Not_found) (function
| "is" -> `Unary (function s ->
let id = Id.mk Term s in
begin match Type.find_bound env id with
| `Cstr c ->
`Term (Base.term_app1 (module Type) env symbol (Type.T.cstr_tester c))
| _ -> `Not_found
end)
| _ -> `Not_indexed
)
| _ -> `Not_found
end
end
module Zf = struct
module Tff
(Type : Tff_intf.S)
(Tag : Dolmen.Intf.Tag.Zf_Base with type 'a t = 'a Type.Tag.t)
(Ty : Dolmen.Intf.Ty.Zf_Base with type t = Type.Ty.t)
(T : Dolmen.Intf.Term.Zf_Base with type t = Type.T.t) = struct
let mk_or a b = T._or [a; b]
let mk_and a b = T._and [a; b]
let parse env s =
match s with
| Type.Builtin Ast.Prop ->
`Ty (Base.app0 (module Type) env s Ty.prop)
| Type.Builtin Ast.True ->
`Term (Base.app0 (module Type) env s T._true)
| Type.Builtin Ast.False ->
`Term (Base.app0 (module Type) env s T._false)
| Type.Builtin Ast.Not ->
`Term (Base.term_app1 (module Type) env s T.neg)
| Type.Builtin Ast.Or ->
`Term (Base.term_app2 (module Type) env s mk_or)
| Type.Builtin Ast.And ->
`Term (Base.term_app2 (module Type) env s mk_and)
| Type.Builtin Ast.Imply ->
`Term (Base.term_app2 (module Type) env s T.imply)
| Type.Builtin Ast.Equiv ->
`Term (Base.term_app2 (module Type) env s T.equiv)
| Type.Builtin Ast.Eq ->
`Term (Base.term_app2 (module Type) env s T.eq)
| Type.Builtin Ast.Distinct ->
`Term (Base.term_app2 (module Type) env s T.neq)
| Type.Builtin Ast.Ite ->
`Term (
Base.make_op3 (module Type) env s (fun _ (a, b, c) ->
let cond = Type.parse_prop env a in
let then_ = Type.parse_term env b in
let else_ = Type.parse_term env c in
T.ite cond then_ else_
)
)
| Type.Id id when Id.equal id Id.rwrt_rule ->
`Tags (fun _ast _args -> [Type.Set (Tag.rwrt, ())])
| Type.Id { name = Simple "infix"; ns = Term } ->
`Tags (fun ast args -> match args with
| [ { Ast.term = Ast.Symbol { name = Simple name; _ }; _ } ] -> [
Type.Set (Tag.name, Tag.exact name);
Type.Set (Tag.pos, Tag.infix);
]
| _ ->
Type._error env (Ast ast)
(Type.Expected ("a symbol", None))
)
| Type.Id { name = Simple "prefix"; ns = Term } ->
`Tags (fun ast args -> match args with
| [ { Ast.term = Ast.Symbol { name = Simple name; _ }; _ } ] -> [
Type.Set (Tag.name, Tag.exact name);
Type.Set (Tag.pos, Tag.prefix);
]
| _ ->
Type._error env (Ast ast)
(Type.Expected ("a symbol", None))
)
| _ -> `Not_found
end
end