src/HOL/Tools/ATP/atp_proof_reconstruct.ML
changeset 48132 9aa0fad4e864
parent 48085 ff5e900d7b1a
child 48135 a44f34694406
equal deleted inserted replaced
48131:1016664b8feb 48132:9aa0fad4e864
   329 exception FORMULA of (string, string, (string, string) ho_term) formula list
   329 exception FORMULA of (string, string, (string, string) ho_term) formula list
   330 exception SAME of unit
   330 exception SAME of unit
   331 
   331 
   332 (* Type variables are given the basic sort "HOL.type". Some will later be
   332 (* Type variables are given the basic sort "HOL.type". Some will later be
   333    constrained by information from type literals, or by type inference. *)
   333    constrained by information from type literals, or by type inference. *)
   334 fun typ_from_atp ctxt (u as ATerm (a, us)) =
   334 fun typ_from_atp ctxt (u as ATerm ((a, _), us)) =
   335   let val Ts = map (typ_from_atp ctxt) us in
   335   let val Ts = map (typ_from_atp ctxt) us in
   336     case unprefix_and_unascii type_const_prefix a of
   336     case unprefix_and_unascii type_const_prefix a of
   337       SOME b => Type (invert_const b, Ts)
   337       SOME b => Type (invert_const b, Ts)
   338     | NONE =>
   338     | NONE =>
   339       if not (null us) then
   339       if not (null us) then
   349         |> Type_Infer.param 0
   349         |> Type_Infer.param 0
   350   end
   350   end
   351 
   351 
   352 (* Type class literal applied to a type. Returns triple of polarity, class,
   352 (* Type class literal applied to a type. Returns triple of polarity, class,
   353    type. *)
   353    type. *)
   354 fun type_constraint_from_term ctxt (u as ATerm (a, us)) =
   354 fun type_constraint_from_term ctxt (u as ATerm ((a, _), us)) =
   355   case (unprefix_and_unascii class_prefix a, map (typ_from_atp ctxt) us) of
   355   case (unprefix_and_unascii class_prefix a, map (typ_from_atp ctxt) us) of
   356     (SOME b, [T]) => (b, T)
   356     (SOME b, [T]) => (b, T)
   357   | _ => raise HO_TERM [u]
   357   | _ => raise HO_TERM [u]
   358 
   358 
   359 (* Accumulate type constraints in a formula: negative type literals. *)
   359 (* Accumulate type constraints in a formula: negative type literals. *)
   402        type inference often fails otherwise. See also "axiom_inference" in
   402        type inference often fails otherwise. See also "axiom_inference" in
   403        "Metis_Reconstruct". *)
   403        "Metis_Reconstruct". *)
   404     val var_index = if textual then 0 else 1
   404     val var_index = if textual then 0 else 1
   405     fun do_term extra_ts opt_T u =
   405     fun do_term extra_ts opt_T u =
   406       case u of
   406       case u of
   407         ATerm (s, us) =>
   407         ATerm ((s, _), us) =>
   408         if String.isPrefix native_type_prefix s then
   408         if String.isPrefix native_type_prefix s then
   409           @{const True} (* ignore TPTP type information *)
   409           @{const True} (* ignore TPTP type information *)
   410         else if s = tptp_equal then
   410         else if s = tptp_equal then
   411           let val ts = map (do_term [] NONE) us in
   411           let val ts = map (do_term [] NONE) us in
   412             if textual andalso length ts = 2 andalso
   412             if textual andalso length ts = 2 andalso
   490                   Var ((s |> textual ? repair_variable_name Char.toLower,
   490                   Var ((s |> textual ? repair_variable_name Char.toLower,
   491                         var_index), T)
   491                         var_index), T)
   492           in list_comb (t, ts) end
   492           in list_comb (t, ts) end
   493   in do_term [] end
   493   in do_term [] end
   494 
   494 
   495 fun term_from_atom ctxt textual sym_tab pos (u as ATerm (s, _)) =
   495 fun term_from_atom ctxt textual sym_tab pos (u as ATerm ((s, _), _)) =
   496   if String.isPrefix class_prefix s then
   496   if String.isPrefix class_prefix s then
   497     add_type_constraint pos (type_constraint_from_term ctxt u)
   497     add_type_constraint pos (type_constraint_from_term ctxt u)
   498     #> pair @{const True}
   498     #> pair @{const True}
   499   else
   499   else
   500     pair (term_from_atp ctxt textual sym_tab (SOME @{typ bool}) u)
   500     pair (term_from_atp ctxt textual sym_tab (SOME @{typ bool}) u)