src/HOL/Tools/ATP/atp_proof_reconstruct.ML
changeset 57199 472360558b22
parent 56854 ddd3af5a683d
child 57255 488046fdda59
equal deleted inserted replaced
57198:159e1b043495 57199:472360558b22
   191     val thy = Proof_Context.theory_of ctxt
   191     val thy = Proof_Context.theory_of ctxt
   192     (* For Metis, we use 1 rather than 0 because variable references in clauses may otherwise
   192     (* For Metis, we use 1 rather than 0 because variable references in clauses may otherwise
   193        conflict with variable constraints in the goal. At least, type inference often fails
   193        conflict with variable constraints in the goal. At least, type inference often fails
   194        otherwise. See also "axiom_inference" in "Metis_Reconstruct". *)
   194        otherwise. See also "axiom_inference" in "Metis_Reconstruct". *)
   195     val var_index = if textual then 0 else 1
   195     val var_index = if textual then 0 else 1
       
   196 
   196     fun do_term extra_ts opt_T u =
   197     fun do_term extra_ts opt_T u =
   197       (case u of
   198       (case u of
   198         ATerm ((s, tys), us) =>
   199         ATerm ((s, tys), us) =>
   199         if s = ""
   200         if s = "" then
   200           then error "Isar proof reconstruction failed because the ATP proof \
   201           error "Isar proof reconstruction failed because the ATP proof contains unparsable \
   201                      \contains unparsable material."
   202             \material."
   202         else if String.isPrefix native_type_prefix s then
   203         else if String.isPrefix native_type_prefix s then
   203           @{const True} (* ignore TPTP type information *)
   204           @{const True} (* ignore TPTP type information *)
   204         else if s = tptp_equal then
   205         else if s = tptp_equal then
   205           let val ts = map (do_term [] NONE) us in
   206           let val ts = map (do_term [] NONE) us in
   206             if textual andalso length ts = 2 andalso loose_aconv (hd ts, List.last ts) then
   207             if textual andalso length ts = 2 andalso loose_aconv (hd ts, List.last ts) then
   219               else if s' = predicator_name then
   220               else if s' = predicator_name then
   220                 do_term [] (SOME @{typ bool}) (hd us)
   221                 do_term [] (SOME @{typ bool}) (hd us)
   221               else if s' = app_op_name then
   222               else if s' = app_op_name then
   222                 let val extra_t = do_term [] NONE (List.last us) in
   223                 let val extra_t = do_term [] NONE (List.last us) in
   223                   do_term (extra_t :: extra_ts)
   224                   do_term (extra_t :: extra_ts)
   224                           (case opt_T of
   225                     (case opt_T of SOME T => SOME (slack_fastype_of extra_t --> T) | NONE => NONE)
   225                              SOME T => SOME (slack_fastype_of extra_t --> T)
   226                     (nth us (length us - 2))
   226                            | NONE => NONE)
       
   227                           (nth us (length us - 2))
       
   228                 end
   227                 end
   229               else if s' = type_guard_name then
   228               else if s' = type_guard_name then
   230                 @{const True} (* ignore type predicates *)
   229                 @{const True} (* ignore type predicates *)
   231               else
   230               else
   232                 let
   231                 let
   236                   val term_ts = map (do_term [] NONE) term_us
   235                   val term_ts = map (do_term [] NONE) term_us
   237 
   236 
   238                   val Ts = map (typ_of_atp_type ctxt) tys @ map (typ_of_atp_term ctxt) type_us
   237                   val Ts = map (typ_of_atp_type ctxt) tys @ map (typ_of_atp_term ctxt) type_us
   239                   val T =
   238                   val T =
   240                     (if not (null Ts) andalso robust_const_num_type_args thy s' = length Ts then
   239                     (if not (null Ts) andalso robust_const_num_type_args thy s' = length Ts then
   241                        if new_skolem then
   240                        if new_skolem then SOME (Type_Infer.paramify_vars (tl Ts ---> hd Ts))
   242                          SOME (Type_Infer.paramify_vars (tl Ts ---> hd Ts))
   241                        else if textual then try (Sign.const_instance thy) (s', Ts)
   243                        else if textual then
   242                        else NONE
   244                          try (Sign.const_instance thy) (s', Ts)
       
   245                        else
       
   246                          NONE
       
   247                      else
   243                      else
   248                        NONE)
   244                        NONE)
   249                     |> (fn SOME T => T
   245                     |> (fn SOME T => T
   250                          | NONE =>
   246                          | NONE =>
   251                            map slack_fastype_of term_ts --->
   247                            map slack_fastype_of term_ts --->
   252                             the_default (Type_Infer.anyT @{sort type}) opt_T)
   248                            the_default (Type_Infer.anyT @{sort type}) opt_T)
   253                   val t =
   249                   val t =
   254                     if new_skolem then Var ((new_skolem_var_name_of_const s'', var_index), T)
   250                     if new_skolem then Var ((new_skolem_var_name_of_const s'', var_index), T)
   255                     else Const (unproxify_const s', T)
   251                     else Const (unproxify_const s', T)
   256                 in list_comb (t, term_ts @ extra_ts) end
   252                 in list_comb (t, term_ts @ extra_ts) end
   257             end
   253             end
   259             let
   255             let
   260               (* This assumes that distinct names are mapped to distinct names by
   256               (* This assumes that distinct names are mapped to distinct names by
   261                  "Variable.variant_frees". This does not hold in general but should hold for
   257                  "Variable.variant_frees". This does not hold in general but should hold for
   262                  ATP-generated Skolem function names, since these end with a digit and
   258                  ATP-generated Skolem function names, since these end with a digit and
   263                  "variant_frees" appends letters. *)
   259                  "variant_frees" appends letters. *)
   264               fun fresh_up s =
   260               fun fresh_up s = [(s, ())] |> Variable.variant_frees ctxt [] |> hd |> fst
   265                 [(s, ())] |> Variable.variant_frees ctxt [] |> hd |> fst
   261 
   266               val term_ts =
   262               val term_ts =
   267                 map (do_term [] NONE) us
   263                 map (do_term [] NONE) us
   268                 (* SPASS (3.8ds) and Vampire (2.6) pass arguments to Skolem functions in reverse
   264                 (* SPASS (3.8ds) and Vampire (2.6) pass arguments to Skolem functions in reverse
   269                    order, which is incompatible with the new Metis skolemizer. *)
   265                    order, which is incompatible with the new Metis skolemizer. *)
   270                 |> exists (fn pre => String.isPrefix pre s)
   266                 |> exists (fn pre => String.isPrefix pre s)