src/HOL/Tools/ATP/atp_translate.ML
changeset 44754 265174356212
parent 44742 68e34e7f01ab
child 44768 a7bc1bdb8bb4
equal deleted inserted replaced
44753:3c73f4068978 44754:265174356212
     9 signature ATP_TRANSLATE =
     9 signature ATP_TRANSLATE =
    10 sig
    10 sig
    11   type ('a, 'b) ho_term = ('a, 'b) ATP_Problem.ho_term
    11   type ('a, 'b) ho_term = ('a, 'b) ATP_Problem.ho_term
    12   type connective = ATP_Problem.connective
    12   type connective = ATP_Problem.connective
    13   type ('a, 'b, 'c) formula = ('a, 'b, 'c) ATP_Problem.formula
    13   type ('a, 'b, 'c) formula = ('a, 'b, 'c) ATP_Problem.formula
    14   type format = ATP_Problem.format
    14   type tptp_format = ATP_Problem.tptp_format
    15   type formula_kind = ATP_Problem.formula_kind
    15   type formula_kind = ATP_Problem.formula_kind
    16   type 'a problem = 'a ATP_Problem.problem
    16   type 'a problem = 'a ATP_Problem.problem
    17 
    17 
    18   datatype locality =
    18   datatype locality =
    19     General | Helper | Induction | Extensionality | Intro | Elim | Simp |
    19     General | Helper | Induction | Extensionality | Intro | Elim | Simp |
    90   val is_type_enc_higher_order : type_enc -> bool
    90   val is_type_enc_higher_order : type_enc -> bool
    91   val polymorphism_of_type_enc : type_enc -> polymorphism
    91   val polymorphism_of_type_enc : type_enc -> polymorphism
    92   val level_of_type_enc : type_enc -> type_level
    92   val level_of_type_enc : type_enc -> type_level
    93   val is_type_enc_quasi_sound : type_enc -> bool
    93   val is_type_enc_quasi_sound : type_enc -> bool
    94   val is_type_enc_fairly_sound : type_enc -> bool
    94   val is_type_enc_fairly_sound : type_enc -> bool
    95   val adjust_type_enc : format -> type_enc -> type_enc
    95   val adjust_type_enc : tptp_format -> type_enc -> type_enc
    96   val mk_aconns :
    96   val mk_aconns :
    97     connective -> ('a, 'b, 'c) formula list -> ('a, 'b, 'c) formula
    97     connective -> ('a, 'b, 'c) formula list -> ('a, 'b, 'c) formula
    98   val unmangled_const : string -> string * (string, 'b) ho_term list
    98   val unmangled_const : string -> string * (string, 'b) ho_term list
    99   val unmangled_const_name : string -> string
    99   val unmangled_const_name : string -> string
   100   val helper_table : ((string * bool) * thm list) list
   100   val helper_table : ((string * bool) * thm list) list
   101   val factsN : string
   101   val factsN : string
   102   val prepare_atp_problem :
   102   val prepare_atp_problem :
   103     Proof.context -> format -> formula_kind -> formula_kind -> type_enc
   103     Proof.context -> tptp_format -> formula_kind -> formula_kind -> type_enc
   104     -> bool -> string -> bool -> bool -> term list -> term
   104     -> bool -> string -> bool -> bool -> term list -> term
   105     -> ((string * locality) * term) list
   105     -> ((string * locality) * term) list
   106     -> string problem * string Symtab.table * int * int
   106     -> string problem * string Symtab.table * int * int
   107        * (string * locality) list vector * int list * int Symtab.table
   107        * (string * locality) list vector * int list * int Symtab.table
   108   val atp_problem_weights : string problem -> (string * real) list
   108   val atp_problem_weights : string problem -> (string * real) list
   140 val simpN = "simp"
   140 val simpN = "simp"
   141 
   141 
   142 (* TFF1 is still in development, and it is still unclear whether symbols will be
   142 (* TFF1 is still in development, and it is still unclear whether symbols will be
   143    allowed to have types like "$tType > $o" (i.e., "![A : $tType] : $o"), with
   143    allowed to have types like "$tType > $o" (i.e., "![A : $tType] : $o"), with
   144    "dummy" type variables. *)
   144    "dummy" type variables. *)
   145 val exploit_tff1_dummy_type_vars = false
   145 val avoid_first_order_dummy_type_vars = true
   146 
   146 
   147 val bound_var_prefix = "B_"
   147 val bound_var_prefix = "B_"
   148 val all_bound_var_prefix = "BA_"
   148 val all_bound_var_prefix = "BA_"
   149 val exist_bound_var_prefix = "BE_"
   149 val exist_bound_var_prefix = "BE_"
   150 val schematic_var_prefix = "V_"
   150 val schematic_var_prefix = "V_"
   323 local
   323 local
   324   val choice_const = (fst o dest_Const o HOLogic.choice_const) Term.dummyT
   324   val choice_const = (fst o dest_Const o HOLogic.choice_const) Term.dummyT
   325   fun default c = const_prefix ^ lookup_const c
   325   fun default c = const_prefix ^ lookup_const c
   326 in
   326 in
   327   fun make_fixed_const _ @{const_name HOL.eq} = tptp_old_equal
   327   fun make_fixed_const _ @{const_name HOL.eq} = tptp_old_equal
   328     | make_fixed_const (SOME (THF0 THF_With_Choice)) c =
   328     | make_fixed_const (SOME (THF (_, _, THF_With_Choice))) c =
   329         if c = choice_const then tptp_choice else default c
   329       if c = choice_const then tptp_choice else default c
   330     | make_fixed_const _ c = default c
   330     | make_fixed_const _ c = default c
   331 end
   331 end
   332 
   332 
   333 fun make_fixed_type_const c = type_const_prefix ^ lookup_const c
   333 fun make_fixed_type_const c = type_const_prefix ^ lookup_const c
   334 
   334 
   585             | (Mangled_Monomorphic, _) =>
   585             | (Mangled_Monomorphic, _) =>
   586               Simple_Types (First_Order, Mangled_Monomorphic, level)
   586               Simple_Types (First_Order, Mangled_Monomorphic, level)
   587             | _ => raise Same.SAME)
   587             | _ => raise Same.SAME)
   588          | ("simple_higher", (SOME poly, _, Nonuniform)) =>
   588          | ("simple_higher", (SOME poly, _, Nonuniform)) =>
   589            (case (poly, level) of
   589            (case (poly, level) of
   590               (_, Noninf_Nonmono_Types _) => raise Same.SAME
   590               (Polymorphic, All_Types) =>
       
   591               Simple_Types (Higher_Order, Polymorphic, All_Types)
       
   592             | (_, Noninf_Nonmono_Types _) => raise Same.SAME
   591             | (Mangled_Monomorphic, _) =>
   593             | (Mangled_Monomorphic, _) =>
   592               Simple_Types (Higher_Order, Mangled_Monomorphic, level)
   594               Simple_Types (Higher_Order, Mangled_Monomorphic, level)
   593             | _ => raise Same.SAME)
   595             | _ => raise Same.SAME)
   594          | ("guards", (SOME poly, _, _)) => Guards (poly, level, uniformity)
   596          | ("guards", (SOME poly, _, _)) => Guards (poly, level, uniformity)
   595          | ("tags", (SOME Polymorphic, _, _)) =>
   597          | ("tags", (SOME Polymorphic, _, _)) =>
   629 
   631 
   630 fun is_type_level_monotonicity_based (Noninf_Nonmono_Types _) = true
   632 fun is_type_level_monotonicity_based (Noninf_Nonmono_Types _) = true
   631   | is_type_level_monotonicity_based Fin_Nonmono_Types = true
   633   | is_type_level_monotonicity_based Fin_Nonmono_Types = true
   632   | is_type_level_monotonicity_based _ = false
   634   | is_type_level_monotonicity_based _ = false
   633 
   635 
   634 fun adjust_type_enc (THF0 _) (Simple_Types (order, Polymorphic, level)) =
   636 fun adjust_type_enc (THF (TPTP_Monomorphic, _, _))
       
   637                     (Simple_Types (order, _, level)) =
   635     Simple_Types (order, Mangled_Monomorphic, level)
   638     Simple_Types (order, Mangled_Monomorphic, level)
   636   | adjust_type_enc (THF0 _) type_enc = type_enc
   639   | adjust_type_enc (THF _) type_enc = type_enc
   637   | adjust_type_enc (TFF (TFF_Monomorphic, _)) (Simple_Types (_, _, level)) =
   640   | adjust_type_enc (TFF (TPTP_Monomorphic, _)) (Simple_Types (_, _, level)) =
   638     Simple_Types (First_Order, Mangled_Monomorphic, level)
   641     Simple_Types (First_Order, Mangled_Monomorphic, level)
   639   | adjust_type_enc (TFF (_, _)) (Simple_Types (_, poly, level)) =
   642   | adjust_type_enc (TFF _) (Simple_Types (_, poly, level)) =
   640     Simple_Types (First_Order, poly, level)
   643     Simple_Types (First_Order, poly, level)
   641   | adjust_type_enc format (Simple_Types (_, poly, level)) =
   644   | adjust_type_enc format (Simple_Types (_, poly, level)) =
   642     adjust_type_enc format (Guards (poly, level, Uniform))
   645     adjust_type_enc format (Guards (poly, level, Uniform))
   643   | adjust_type_enc CNF_UEQ (type_enc as Guards stuff) =
   646   | adjust_type_enc CNF_UEQ (type_enc as Guards stuff) =
   644     (if is_type_enc_fairly_sound type_enc then Tags else Guards) stuff
   647     (if is_type_enc_fairly_sound type_enc then Tags else Guards) stuff
   744 val a_itself_atype = AType (itself_name, [tvar_a_atype])
   747 val a_itself_atype = AType (itself_name, [tvar_a_atype])
   745 
   748 
   746 fun type_class_formula type_enc class arg =
   749 fun type_class_formula type_enc class arg =
   747   AAtom (ATerm (class, arg ::
   750   AAtom (ATerm (class, arg ::
   748       (case type_enc of
   751       (case type_enc of
   749          Simple_Types (_, Polymorphic, _) =>
   752          Simple_Types (First_Order, Polymorphic, _) =>
   750          if exploit_tff1_dummy_type_vars then [] else [ATerm (TYPE_name, [arg])]
   753          if avoid_first_order_dummy_type_vars then [ATerm (TYPE_name, [arg])]
       
   754          else []
   751        | _ => [])))
   755        | _ => [])))
   752 fun formulas_for_types type_enc add_sorts_on_typ Ts =
   756 fun formulas_for_types type_enc add_sorts_on_typ Ts =
   753   [] |> level_of_type_enc type_enc <> No_Types ? fold add_sorts_on_typ Ts
   757   [] |> level_of_type_enc type_enc <> No_Types ? fold add_sorts_on_typ Ts
   754      |> map (fn (class, name) =>
   758      |> map (fn (class, name) =>
   755                 type_class_formula type_enc class (ATerm (name, [])))
   759                 type_class_formula type_enc class (ATerm (name, [])))
  1777       |> formulas_for_types type_enc add_sorts_on_tfree
  1781       |> formulas_for_types type_enc add_sorts_on_tfree
  1778   in map2 formula_line_for_free_type (0 upto length phis - 1) phis end
  1782   in map2 formula_line_for_free_type (0 upto length phis - 1) phis end
  1779 
  1783 
  1780 (** Symbol declarations **)
  1784 (** Symbol declarations **)
  1781 
  1785 
  1782 fun decl_line_for_class s =
  1786 fun decl_line_for_class order s =
  1783   let val name as (s, _) = `make_type_class s in
  1787   let val name as (s, _) = `make_type_class s in
  1784     Decl (sym_decl_prefix ^ s, name,
  1788     Decl (sym_decl_prefix ^ s, name,
  1785           if exploit_tff1_dummy_type_vars then
  1789           if order = First_Order andalso avoid_first_order_dummy_type_vars then
  1786             AFun (atype_of_types, bool_atype)
  1790             ATyAbs ([tvar_a_name], AFun (a_itself_atype, bool_atype))
  1787           else
  1791           else
  1788             ATyAbs ([tvar_a_name], AFun (a_itself_atype, bool_atype)))
  1792             AFun (atype_of_types, bool_atype))
  1789   end
  1793   end
  1790 
  1794 
  1791 fun decl_lines_for_classes type_enc classes =
  1795 fun decl_lines_for_classes type_enc classes =
  1792   case type_enc of
  1796   case type_enc of
  1793     Simple_Types (_, Polymorphic, _) => map decl_line_for_class classes
  1797     Simple_Types (order, Polymorphic, _) =>
       
  1798     map (decl_line_for_class order) classes
  1794   | _ => []
  1799   | _ => []
  1795 
  1800 
  1796 fun sym_decl_table_for_facts ctxt format type_enc repaired_sym_tab
  1801 fun sym_decl_table_for_facts ctxt format type_enc repaired_sym_tab
  1797                              (conjs, facts) =
  1802                              (conjs, facts) =
  1798   let
  1803   let
  2230       problem
  2235       problem
  2231       |> (case format of
  2236       |> (case format of
  2232             CNF => ensure_cnf_problem
  2237             CNF => ensure_cnf_problem
  2233           | CNF_UEQ => filter_cnf_ueq_problem
  2238           | CNF_UEQ => filter_cnf_ueq_problem
  2234           | FOF => I
  2239           | FOF => I
  2235           | TFF (_, TFF_Implicit) => I
  2240           | TFF (_, TPTP_Implicit) => I
       
  2241           | THF (_, TPTP_Implicit, _) => I
  2236           | _ => declare_undeclared_syms_in_atp_problem type_decl_prefix
  2242           | _ => declare_undeclared_syms_in_atp_problem type_decl_prefix
  2237                                                         implicit_declsN)
  2243                                                         implicit_declsN)
  2238     val (problem, pool) = problem |> nice_atp_problem readable_names
  2244     val (problem, pool) = problem |> nice_atp_problem readable_names
  2239     val helpers_offset = offset_of_heading_in_problem helpersN problem 0
  2245     val helpers_offset = offset_of_heading_in_problem helpersN problem 0
  2240     val typed_helpers =
  2246     val typed_helpers =