153 fun add_var (key, z) = Vartab.map_default (key, []) (cons z) |
153 fun add_var (key, z) = Vartab.map_default (key, []) (cons z) |
154 fun add_type_constraint false (cl, TFree (a ,_)) = add_var ((a, ~1), cl) |
154 fun add_type_constraint false (cl, TFree (a ,_)) = add_var ((a, ~1), cl) |
155 | add_type_constraint false (cl, TVar (ix, _)) = add_var (ix, cl) |
155 | add_type_constraint false (cl, TVar (ix, _)) = add_var (ix, cl) |
156 | add_type_constraint _ _ = I |
156 | add_type_constraint _ _ = I |
157 |
157 |
158 fun repair_var_name s = |
158 fun repair_var_name_raw s = |
159 let |
159 let |
160 fun subscript_name s n = s ^ nat_subscript n |
160 fun subscript_name s n = s ^ nat_subscript n |
161 val s = s |> String.map Char.toLower |
161 val s = s |> String.map Char.toLower |
162 in |
162 in |
163 (case space_explode "_" s of |
163 (case space_explode "_" s of |
167 subscript_name (String.implode cs1) (the (Int.fromString (String.implode cs2))) |
167 subscript_name (String.implode cs1) (the (Int.fromString (String.implode cs2))) |
168 | (_, _) => s) |
168 | (_, _) => s) |
169 | [s1, s2] => (case Int.fromString s2 of SOME n => subscript_name s1 n | NONE => s) |
169 | [s1, s2] => (case Int.fromString s2 of SOME n => subscript_name s1 n | NONE => s) |
170 | _ => s) |
170 | _ => s) |
171 end |
171 end |
|
172 |
|
173 fun repair_var_name textual s = |
|
174 (case unprefix_and_unascii schematic_var_prefix s of |
|
175 SOME s => s |
|
176 | NONE => s |> textual ? repair_var_name_raw) |
172 |
177 |
173 (* The number of type arguments of a constant, zero if it's monomorphic. For (instances of) Skolem |
178 (* The number of type arguments of a constant, zero if it's monomorphic. For (instances of) Skolem |
174 pseudoconstants, this information is encoded in the constant name. *) |
179 pseudoconstants, this information is encoded in the constant name. *) |
175 fun robust_const_num_type_args thy s = |
180 fun robust_const_num_type_args thy s = |
176 if String.isPrefix skolem_const_prefix s then |
181 if String.isPrefix skolem_const_prefix s then |
282 (case tys of [ty] => typ_of_atp_type ctxt ty | _ => HOLogic.typeT)) |
287 (case tys of [ty] => typ_of_atp_type ctxt ty | _ => HOLogic.typeT)) |
283 val t = |
288 val t = |
284 (case unprefix_and_unascii fixed_var_prefix s of |
289 (case unprefix_and_unascii fixed_var_prefix s of |
285 SOME s => Free (s, T) |
290 SOME s => Free (s, T) |
286 | NONE => |
291 | NONE => |
287 (case unprefix_and_unascii schematic_var_prefix s of |
292 if textual andalso not (is_tptp_variable s) then |
288 SOME s => Var ((s, var_index), T) |
293 Free (s |> textual ? (repair_var_name_raw #> fresh_up), T) |
289 | NONE => |
294 else |
290 if textual andalso not (is_tptp_variable s) then |
295 Var ((repair_var_name textual s, var_index), T)) |
291 Free (s |> textual ? (repair_var_name #> fresh_up), T) |
|
292 else |
|
293 Var ((s |> textual ? repair_var_name, var_index), T))) |
|
294 in list_comb (t, ts) end)) |
296 in list_comb (t, ts) end)) |
295 in do_term [] end |
297 in do_term [] end |
296 |
298 |
297 fun term_of_atom ctxt textual sym_tab pos (u as ATerm ((s, _), _)) = |
299 fun term_of_atom ctxt textual sym_tab pos (u as ATerm ((s, _), _)) = |
298 if String.isPrefix class_prefix s then |
300 if String.isPrefix class_prefix s then |
317 | do_term (t1 $ t2) = do_term t1 $ do_term t2 |
319 | do_term (t1 $ t2) = do_term t1 $ do_term t2 |
318 in t |> not (Vartab.is_empty tvar_tab) ? do_term end |
320 in t |> not (Vartab.is_empty tvar_tab) ? do_term end |
319 |
321 |
320 fun quantify_over_var quant_of var_s t = |
322 fun quantify_over_var quant_of var_s t = |
321 let |
323 let |
322 val vars = [] |> Term.add_vars t |> filter (fn ((s, _), _) => s = var_s) |
324 val vars = filter (fn ((s, _), _) => s = var_s) (Term.add_vars t []) |
323 val normTs = vars |> AList.group (op =) |> map (apsnd hd) |
325 val normTs = vars |> AList.group (op =) |> map (apsnd hd) |
324 fun norm_var_types (Var (x, T)) = |
326 fun norm_var_types (Var (x, T)) = |
325 Var (x, (case AList.lookup (op =) normTs x of NONE => T | SOME T' => T')) |
327 Var (x, (case AList.lookup (op =) normTs x of NONE => T | SOME T' => T')) |
326 | norm_var_types t = t |
328 | norm_var_types t = t |
327 in t |> map_aterms norm_var_types |> fold_rev quant_of (map Var normTs) end |
329 in t |> map_aterms norm_var_types |> fold_rev quant_of (map Var normTs) end |
335 AQuant (_, [], phi) => do_formula pos phi |
337 AQuant (_, [], phi) => do_formula pos phi |
336 | AQuant (q, (s, _) :: xs, phi') => |
338 | AQuant (q, (s, _) :: xs, phi') => |
337 do_formula pos (AQuant (q, xs, phi')) |
339 do_formula pos (AQuant (q, xs, phi')) |
338 (* FIXME: TFF *) |
340 (* FIXME: TFF *) |
339 #>> quantify_over_var (case q of AForall => forall_of | AExists => exists_of) |
341 #>> quantify_over_var (case q of AForall => forall_of | AExists => exists_of) |
340 (s |> textual ? repair_var_name) |
342 (repair_var_name textual s) |
341 | AConn (ANot, [phi']) => do_formula (not pos) phi' #>> s_not |
343 | AConn (ANot, [phi']) => do_formula (not pos) phi' #>> s_not |
342 | AConn (c, [phi1, phi2]) => |
344 | AConn (c, [phi1, phi2]) => |
343 do_formula (pos |> c = AImplies ? not) phi1 |
345 do_formula (pos |> c = AImplies ? not) phi1 |
344 ##>> do_formula pos phi2 |
346 ##>> do_formula pos phi2 |
345 #>> (case c of |
347 #>> (case c of |
587 let |
589 let |
588 val (ss', role', t') = |
590 val (ss', role', t') = |
589 (case resolve_conjecture ss of |
591 (case resolve_conjecture ss of |
590 [j] => |
592 [j] => |
591 if j = length hyp_ts then ([], Conjecture, concl_t) else ([], Hypothesis, nth hyp_ts j) |
593 if j = length hyp_ts then ([], Conjecture, concl_t) else ([], Hypothesis, nth hyp_ts j) |
592 | _ => |
594 | _ => |
593 (case resolve_fact fact_names ss of |
595 (case resolve_fact fact_names ss of |
594 [] => (ss, Plain, t) |
596 [] => (ss, Plain, t) |
595 | facts => (map fst facts, Axiom, t))) |
597 | facts => (map fst facts, Axiom, t))) |
596 in |
598 in |
597 ((num, ss'), role', t', rule, deps) |
599 ((num, ss'), role', t', rule, deps) |
598 end |
600 end |
599 |
601 |
600 val atp_proof = map factify_step atp_proof |
602 val atp_proof = map factify_step atp_proof |