-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprf_of_xml.ml
339 lines (273 loc) · 12.7 KB
/
prf_of_xml.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
(******************************************************************************
Rainbow, a termination proof certification tool
See the COPYRIGHTS and LICENSE files.
- Frederic Blanqui, 2006-05-31
- Adam Koprowski, 2007-04-20, adding matrix interpretations
- Ducas Leo, 2007-08-10
from xml to the rainbow internal representation of termination proofs
******************************************************************************)
open Proof;;
open Xml;;
open Pb_of_xml;;
open Libxml;;
open Error;;
(*****************************************************************************)
(* Number, vectors and matrices *)
(*****************************************************************************)
let arcticNumber = function
| Element ("minus_infinite", _, _, _) -> MinusInf
| Element ("finite", _, _, x :: _) -> Fin (get_int x)
| x -> error_xml x "not an arcticNumber";;
let tropicalNumber = function
| Element ("plus_infinite", _, _, _) -> PlusInf
| Element ("finite", _, _, x :: _) -> TroFin (get_int x)
| x -> error_xml x "not a tropicalNumber";;
let natVector = List.map (get_first_son "velem" get_nonNegativeInteger);;
let arcticVector = List.map (get_first_son "velem" arcticNumber);;
let tropicalVector = List.map (get_first_son "velem" tropicalNumber);;
let natMatrix = List.map (get_sons "row" natVector);;
let arcticMatrix = List.map (get_sons "row" arcticVector);;
let tropicalMatrix = List.map (get_sons "row" tropicalVector);;
(*****************************************************************************)
(* Polynomials *)
(*****************************************************************************)
let monomial = function
| Element ("monomial", _, _, x :: xs) ->
get_first_son "coef" get_nonNegativeInteger x,
List.map (get_first_son "var" get_nonNegativeInteger) xs
| x -> error_xml x "not a monomial";;
let polynomial = get_sons "polynomial" (List.map monomial);;
(*****************************************************************************)
(* Polynomial and matrix interpretations *)
(*****************************************************************************)
let polynomialMapping = function
| Element ("mapping", _, _, x1 :: x2 :: _) -> fun_symbol x1, polynomial x2
| x -> error_xml x "not a polynomialMapping";;
let dimension = get_first_son "dimension" get_positiveInteger;;
let funMatrixInterpretation = function
| Element ("mi_fun", _, _, x :: xs) ->
{ mi_const = get_sons "const" natVector x;
mi_args = List.map (get_sons "arg" natMatrix) xs }
| x -> error_xml x "not a funMatrixInterpretation";;
let matrixMapping = function
| Element ("mapping", _, _, x1 :: x2 :: _) ->
fun_symbol x1, funMatrixInterpretation x2
| x -> error_xml x "not a matrixMapping";;
let mi_map f = get_sons "mi_map" (List.map f);;
let funArcticInterpretation = function
| Element ("mi_fun", _, _, x :: xs) ->
{ mi_const = get_sons "const" arcticVector x;
mi_args = List.map (get_sons "arg" arcticMatrix) xs }
| x -> error_xml x "not a funArcticInterpretation";;
let funTropcialInterpretation = function
| Element ("mi_fun", _, _, x :: xs) ->
{ mi_const = get_sons "const" tropicalVector x;
mi_args = List.map (get_sons "arg" tropicalMatrix) xs }
| x -> error_xml x "not a funTropicalInterpretation";;
let arcticMapping = function
| Element ("mapping", _, _, x1 :: x2 :: _) ->
fun_symbol x1, funArcticInterpretation x2
| x -> error_xml x "not an arcticMapping";;
let tropicalMapping = function
| Element ("mapping", _, _, x1 :: x2 :: _) ->
fun_symbol x1, funTropcialInterpretation x2
| x -> error_xml x "not a tropicalMapping";;
(*****************************************************************************)
(* Argument filterings *)
(*****************************************************************************)
let get_bool = function
| Element ("true",_, _, _) -> true
| Element ("false",_, _, _) -> false
| x -> error_xml x "not a boolean";;
let vectorBool = List.map get_bool;;
let argBoolMapping = function
| Element ("mapping", _, _, x1 :: x2 :: _) ->
fun_symbol x1, get_sons "bool" vectorBool x2
| x -> error_xml x "not an argFilterMapping";;
let proj = function
| [] -> None
| x :: _ -> Some (get_nonNegativeInteger x);;
let argProjMapping = function
| Element ("mapping", _, _, x1 :: x2 :: _) ->
fun_symbol x1, get_sons "proj" proj x2
| x -> error_xml x "not an argProjMapping";;
let arg = get_first_son "arg" get_nonNegativeInteger;;
let listArg = List.map arg;;
let argPermMapping = function
| Element ("mapping", _, _, x1 :: x2 :: _) ->
fun_symbol x1, get_sons "perm" listArg x2
| x -> error_xml x "not an argPermMapping";;
let filter = function
| Element ("bool", _, _, xs) -> Bool (vectorBool xs)
| Element ("proj", _, _, x :: _) -> Proj (get_nonNegativeInteger x)
| Element ("perm", _, _, xs) -> Perm (listArg xs)
| x -> error_xml x "not a filter";;
let argFilterMapping = function
| Element ("mapping", _, _, x1 :: []) -> fun_symbol x1, None
| Element ("mapping", _, _, x1 :: x2 :: _) -> fun_symbol x1, Some (filter x2)
| x -> error_xml x "not an argFilterMapping";;
let af_def f = get_sons "def" (List.map f);;
let simpleProjMapping = function
| Element ("mapping", _, _, x1 :: x2 :: _) ->
fun_symbol x1, get_first_son "proj" get_nonNegativeInteger x2
| x -> error_xml x "not a simpleProjMapping";;
(*****************************************************************************)
(* RPO *)
(*****************************************************************************)
let get_status = function
| Element ("lex", _, _, _) -> Lex
| Element ("mul", _, _, _) -> Mul
| x -> error_xml x "not a status";;
let status = get_first_son "status" get_status;;
let precedence = get_first_son "prec" get_int;;
let statusMapping = function
| Element ("mapping", _, _, x1 :: x2 :: x3 :: _) ->
fun_symbol x1, (status x2, precedence x3)
| x -> error_xml x "not a statusMapping";;
(*****************************************************************************)
(* Reduction orderings *)
(*****************************************************************************)
let rec reductionOrder = function
| Element ("poly_int", _, _, xs) ->
PolyInt (List.map polynomialMapping xs)
| Element ("matrix_int", _, _, x1 :: x2 :: _) ->
MatrixInt { mi_dim = dimension x1; mi_int = mi_map matrixMapping x2 }
| Element ("arctic_int", _, _, x1 :: x2 :: _) ->
ArcticInt { mi_dim = dimension x1; mi_int = mi_map arcticMapping x2 }
| Element ("tropical_int", _, _, x1 :: x2 :: _) ->
TropicalInt { mi_dim = dimension x1; mi_int = mi_map tropicalMapping x2 }
| Element ("arctic_bz_int", _, _, x1 :: x2 :: _) ->
ArcticBZInt { mi_dim = dimension x1; mi_int = mi_map arcticMapping x2 }
| Element ("arg_bool", _, _, x1 :: x2 :: _) ->
ArgBoolOrd (af_def argBoolMapping x1, order x2)
| Element ("arg_proj", _, _, x1 :: x2 :: _) ->
ArgProjOrd (af_def argProjMapping x1, order x2)
| Element ("arg_filter", _, _, x1 :: x2 :: _) ->
ArgFilterOrd (af_def argFilterMapping x1, order x2)
| Element ("rpo", _, _, xs) -> Rpo (List.map statusMapping xs)
| x -> error_xml x "not a reductionOrder"
and order x = get_first_son "order" reductionOrder x;;
(*****************************************************************************)
(* Dependency graph approximations *)
(*****************************************************************************)
let overDpGraph = function
| Element ("hde", _, _, _) -> HDE
| Element ("hde_marked", _, _, _) -> HDE_Marked
| Element ("unif", _, _, _) -> Unif
| (Element _ | PCData _) as x -> error_xml x "not an overDPGraph";;
(*****************************************************************************)
(* Counter-examples *)
(*****************************************************************************)
let trs_pos = get_sons "position" listArg;;
let trsModStep = function
| Element ("step", _, _, x1 :: x2 :: _) ->
{ cet_mod_step_pos = trs_pos x1;
cet_mod_step_rule = trsRule x2 }
| x -> error_xml x "not a trsModStep";;
let trsModSteps = List.map trsModStep;;
let trsStep = function
| Element ("step", _, _, x1 :: x2 :: []) ->
{ cet_step_mod_steps = [];
cet_step_pos = trs_pos x1;
cet_step_rule = trsRule x2 }
| Element ("step", _, _, x1 :: x2 :: x3 :: _) ->
{ cet_step_mod_steps = get_sons "modulo" trsModSteps x1;
cet_step_pos = trs_pos x2;
cet_step_rule = trsRule x3 }
| x -> error_xml x "not a trsStep";;
let trsSteps = List.map trsStep;;
let trsCounterExample = function
| Element ("var_cond", _, _, _) -> CET_var_cond
| Element ("loop", _, _, x1 :: x2 :: x3 :: x4 :: _) ->
CET_loop { cet_start = get_first_son "start" term x1;
cet_steps = get_sons "steps" trsSteps x2;
cet_mod = get_sons "modulo" trsModSteps x3;
cet_pos = trs_pos x4 }
| Element ("loop", _, _, x1 :: x2 :: x3 :: _) ->
CET_loop { cet_start = get_first_son "start" term x1;
cet_steps = get_sons "steps" trsSteps x2;
cet_mod = [];
cet_pos = trs_pos x3 }
| x -> error_xml x "not a trsCounterExample";;
let srs_pos = get_first_son "position" get_nonNegativeInteger;;
let srsModStep = function
| Element ("step", _, _, x1 :: x2 :: _) ->
{ ces_mod_step_pos = srs_pos x1;
ces_mod_step_rule = srsRule x2 }
| x -> error_xml x "not an srsModStep";;
let srsModSteps = List.map srsModStep;;
let srsStep = function
| Element ("step", _, _, x1 :: x2 :: []) ->
{ ces_step_mod_steps = [];
ces_step_pos = srs_pos x1;
ces_step_rule = srsRule x2 }
| Element ("step", _, _, x1 :: x2 :: x3 :: _) ->
{ ces_step_mod_steps = get_sons "modulo" srsModSteps x1;
ces_step_pos = srs_pos x2;
ces_step_rule = srsRule x3 }
| x -> error_xml x "not a srsStep";;
let srsSteps = List.map srsStep;;
let srsCounterExample = function
| Element ("loop", _, _, x1 :: x2 :: x3 :: x4 :: _) ->
CES_loop { ces_start = get_sons "start" word x1;
ces_steps = get_sons "steps" srsSteps x2;
ces_mod = get_sons "modulo" srsModSteps x3;
ces_pos = srs_pos x4 }
| Element ("loop", _, _, x1 :: x2 :: x3 :: _) ->
CES_loop { ces_start = get_sons "start" word x1;
ces_steps = get_sons "steps" srsSteps x2;
ces_mod = [];
ces_pos = srs_pos x3 }
| x -> error_xml x "not an srsCounterExample";;
let counterExample = function
| Element ("trs_counter_example", _, _, x :: _) ->
CE_trs (trsCounterExample x)
| Element ("srs_counter_example", _, _, x :: _) ->
CE_srs (srsCounterExample x)
| x -> error_xml x "not a counterExample";;
(*****************************************************************************)
(* Proof kinds *)
(*****************************************************************************)
let rec proofKind = function
| Element ("trivial", _, _, _) -> Trivial
| Element ("manna_ness", _, _, x1 :: x2 :: _ :: _) ->
MannaNess (true, order x1, proof x2)
| Element ("manna_ness", _, _, x1 :: x2 :: _) ->
MannaNess (false, order x1, proof x2)
| Element ("dp", _, _, x :: _) -> DP (proof x)
| Element ("mark_symbols", _, _, x :: _) -> MarkSymb (proof x)
| Element ("decomp", _, _, x :: xs) ->
Decomp (get_first_son "graph" overDpGraph x, List.map component xs)
| Element ("arg_bool", _, _, x1 :: x2 :: _) ->
ArgBool (af_def argBoolMapping x1, proof x2)
| Element ("arg_proj", _, _, x1 :: x2 :: _) ->
ArgProj (af_def argProjMapping x1, proof x2)
| Element ("arg_perm", _, _, x1 :: x2 :: _) ->
ArgPerm (af_def argPermMapping x1, proof x2)
| Element ("arg_filter", _, _, x1 :: x2 :: _) ->
ArgFilter (af_def argFilterMapping x1, proof x2)
| Element ("as_trs", _, _, x :: _) -> AsTrs (proof x)
| Element ("as_srs", _, _, x :: _) -> AsSrs (proof x)
| Element ("srs_rev", _, _, x :: _) -> SrsRev (proof x)
| Element ("trs_rev", _, _, x :: _) -> TrsRev (proof x)
| Element ("flat_cc", _, _, x :: _) -> FlatCC (proof x)
| Element ("root_lab", _, _, x :: _) -> RootLab (proof x)
| Element ("unlab", _, _, x :: _) -> Unlab (proof x)
| Element ("subterm_crit", _, _, x1 :: x2 :: _) ->
SubtermCrit (af_def simpleProjMapping x1, proof x2)
| x -> error_xml x "not a proofKind"
and proof x = get_first_son "proof" proofKind x
and component = function
| Element ("component", _, _, x1 :: x2 :: _) ->
get_sons "rules" trsRules x1, Some (proof x2)
| Element ("component", _, _, x :: _) ->
get_sons "rules" trsRules x, None
| x -> error_xml x "not a component";;
(*****************************************************************************)
(* Certificates *)
(*****************************************************************************)
let certificate = function
| Element ("proof", _, _, x :: _) -> Proof (proofKind x)
| Element ("counter_example", _, _, x :: _) ->
Counter_example (counterExample x)
| x -> error_xml x "not a certificate";;