src/HOL/Tools/ATP/atp_proof_reconstruct.ML
changeset 57789 a73255cffb5b
parent 57788 0a38c47ebb69
child 57790 a04e8a39ca9a
equal deleted inserted replaced
57788:0a38c47ebb69 57789:a73255cffb5b
   198 fun add_var (key, z) = Vartab.map_default (key, []) (cons z)
   198 fun add_var (key, z) = Vartab.map_default (key, []) (cons z)
   199 fun add_type_constraint false (cl, TFree (a ,_)) = add_var ((a, ~1), cl)
   199 fun add_type_constraint false (cl, TFree (a ,_)) = add_var ((a, ~1), cl)
   200   | add_type_constraint false (cl, TVar (ix, _)) = add_var (ix, cl)
   200   | add_type_constraint false (cl, TVar (ix, _)) = add_var (ix, cl)
   201   | add_type_constraint _ _ = I
   201   | add_type_constraint _ _ = I
   202 
   202 
   203 fun repair_var_name_raw s =
   203 fun repair_var_name s =
   204   let
       
   205     fun subscript_name s n = s ^ nat_subscript n
       
   206     val s = s |> String.map Char.toLower
       
   207   in
       
   208     (case space_explode "_" s of
       
   209       [_] =>
       
   210       (case take_suffix Char.isDigit (String.explode s) of
       
   211         (cs1 as _ :: _, cs2 as _ :: _) =>
       
   212         subscript_name (String.implode cs1) (the (Int.fromString (String.implode cs2)))
       
   213       | (_, _) => s)
       
   214     | [s1, s2] => (case Int.fromString s2 of SOME n => subscript_name s1 n | NONE => s)
       
   215     | _ => s)
       
   216   end
       
   217 
       
   218 fun repair_var_name textual s =
       
   219   (case unprefix_and_unascii schematic_var_prefix s of
   204   (case unprefix_and_unascii schematic_var_prefix s of
   220     SOME s => s
   205     SOME s' => s'
   221   | NONE => s |> textual ? repair_var_name_raw)
   206   | NONE => s)
   222 
   207 
   223 (* The number of type arguments of a constant, zero if it's monomorphic. For (instances of) Skolem
   208 (* The number of type arguments of a constant, zero if it's monomorphic. For (instances of) Skolem
   224    pseudoconstants, this information is encoded in the constant name. *)
   209    pseudoconstants, this information is encoded in the constant name. *)
   225 fun robust_const_num_type_args thy s =
   210 fun robust_const_num_type_args thy s =
   226   if String.isPrefix skolem_const_prefix s then
   211   if String.isPrefix skolem_const_prefix s then
   257     fun do_term opt_T u =
   242     fun do_term opt_T u =
   258       (case u of
   243       (case u of
   259         AAbs (((var, ty), term), []) =>
   244         AAbs (((var, ty), term), []) =>
   260         let
   245         let
   261           val typ = typ_of_atp_type ctxt ty
   246           val typ = typ_of_atp_type ctxt ty
   262           val var_name = repair_var_name true var
   247           val var_name = repair_var_name var
   263           val tm = do_term NONE term
   248           val tm = do_term NONE term
   264         in quantify_over_var true lambda' var_name typ tm end
   249         in quantify_over_var true lambda' var_name typ tm end
   265       | ATerm ((s, tys), us) =>
   250       | ATerm ((s, tys), us) =>
   266         if s = ""
   251         if s = ""
   267         then error "Isar proof reconstruction failed because the ATP proof \
   252         then error "Isar proof reconstruction failed because the ATP proof \
   323                     | _ => Type_Infer.anyT @{sort type}))
   308                     | _ => Type_Infer.anyT @{sort type}))
   324               val t =
   309               val t =
   325                 (case unprefix_and_unascii fixed_var_prefix s of
   310                 (case unprefix_and_unascii fixed_var_prefix s of
   326                   SOME s => Free (s, T)
   311                   SOME s => Free (s, T)
   327                 | NONE =>
   312                 | NONE =>
   328                   if not (is_tptp_variable s) then Free (s |> repair_var_name_raw |> fresh_up, T)
   313                   if not (is_tptp_variable s) then Free (s |> fresh_up, T)
   329                   else Var ((repair_var_name true s, var_index), T))
   314                   else Var ((repair_var_name s, var_index), T))
   330             in list_comb (t, ts) end))
   315             in list_comb (t, ts) end))
   331   in do_term end
   316   in do_term end
   332 
   317 
   333 (* First-order translation. No types are known for variables. "Type_Infer.anyT @{sort type}"
   318 (* First-order translation. No types are known for variables. "Type_Infer.anyT @{sort type}"
   334    should allow them to be inferred. *)
   319    should allow them to be inferred. *)
   419               val t =
   404               val t =
   420                 (case unprefix_and_unascii fixed_var_prefix s of
   405                 (case unprefix_and_unascii fixed_var_prefix s of
   421                   SOME s => Free (s, T)
   406                   SOME s => Free (s, T)
   422                 | NONE =>
   407                 | NONE =>
   423                   if textual andalso not (is_tptp_variable s) then
   408                   if textual andalso not (is_tptp_variable s) then
   424                     Free (s |> textual ? (repair_var_name_raw #> fresh_up), T)
   409                     Free (s |> textual ? fresh_up, T)
   425                   else
   410                   else
   426                     Var ((repair_var_name textual s, var_index), T))
   411                     Var ((repair_var_name s, var_index), T))
   427             in list_comb (t, ts) end))
   412             in list_comb (t, ts) end))
   428   in do_term [] end
   413   in do_term [] end
   429 
   414 
   430 fun term_of_atp ctxt (ATP_Problem.THF _) type_enc =
   415 fun term_of_atp ctxt (ATP_Problem.THF _) type_enc =
   431     if ATP_Problem_Generate.is_type_enc_higher_order type_enc then K (term_of_atp_ho ctxt)
   416     if ATP_Problem_Generate.is_type_enc_higher_order type_enc then K (term_of_atp_ho ctxt)
   466         AQuant (_, [], phi) => do_formula pos phi
   451         AQuant (_, [], phi) => do_formula pos phi
   467       | AQuant (q, (s, _) :: xs, phi') =>
   452       | AQuant (q, (s, _) :: xs, phi') =>
   468         do_formula pos (AQuant (q, xs, phi'))
   453         do_formula pos (AQuant (q, xs, phi'))
   469         (* FIXME: TFF *)
   454         (* FIXME: TFF *)
   470         #>> quantify_over_var textual (case q of AForall => forall_of | AExists => exists_of)
   455         #>> quantify_over_var textual (case q of AForall => forall_of | AExists => exists_of)
   471           (repair_var_name textual s) dummyT
   456           (repair_var_name s) dummyT
   472       | AConn (ANot, [phi']) => do_formula (not pos) phi' #>> s_not
   457       | AConn (ANot, [phi']) => do_formula (not pos) phi' #>> s_not
   473       | AConn (c, [phi1, phi2]) =>
   458       | AConn (c, [phi1, phi2]) =>
   474         do_formula (pos |> c = AImplies ? not) phi1
   459         do_formula (pos |> c = AImplies ? not) phi1
   475         ##>> do_formula pos phi2
   460         ##>> do_formula pos phi2
   476         #>> (case c of
   461         #>> (case c of