src/HOL/Tools/ATP/atp_problem_generate.ML
changeset 62718 27333dc58e28
parent 62218 42202671777c
child 63692 1bc4bc2c9fd1
equal deleted inserted replaced
62717:8adf274f5988 62718:27333dc58e28
    13   type ('a, 'b, 'c, 'd) atp_formula = ('a, 'b, 'c, 'd) ATP_Problem.atp_formula
    13   type ('a, 'b, 'c, 'd) atp_formula = ('a, 'b, 'c, 'd) ATP_Problem.atp_formula
    14   type atp_format = ATP_Problem.atp_format
    14   type atp_format = ATP_Problem.atp_format
    15   type atp_formula_role = ATP_Problem.atp_formula_role
    15   type atp_formula_role = ATP_Problem.atp_formula_role
    16   type 'a atp_problem = 'a ATP_Problem.atp_problem
    16   type 'a atp_problem = 'a ATP_Problem.atp_problem
    17 
    17 
    18   datatype mode = Metis | Sledgehammer | Sledgehammer_Completish | Exporter | Translator
    18   datatype mode = Metis | Sledgehammer | Sledgehammer_Completish of int | Exporter | Translator
    19 
    19 
    20   datatype scope = Global | Local | Assum | Chained
    20   datatype scope = Global | Local | Assum | Chained
    21   datatype status = General | Induction | Intro | Inductive | Elim | Simp | Non_Rec_Def | Rec_Def
    21   datatype status = General | Induction | Intro | Inductive | Elim | Simp | Non_Rec_Def | Rec_Def
    22 
    22 
    23   type stature = scope * status
    23   type stature = scope * status
   124 struct
   124 struct
   125 
   125 
   126 open ATP_Util
   126 open ATP_Util
   127 open ATP_Problem
   127 open ATP_Problem
   128 
   128 
   129 datatype mode = Metis | Sledgehammer | Sledgehammer_Completish | Exporter | Translator
   129 datatype mode = Metis | Sledgehammer | Sledgehammer_Completish of int | Exporter | Translator
   130 
   130 
   131 datatype scope = Global | Local | Assum | Chained
   131 datatype scope = Global | Local | Assum | Chained
   132 datatype status = General | Induction | Intro | Inductive | Elim | Simp | Non_Rec_Def | Rec_Def
   132 datatype status = General | Induction | Intro | Inductive | Elim | Simp | Non_Rec_Def | Rec_Def
   133 
   133 
   134 type stature = scope * status
   134 type stature = scope * status
  1528 
  1528 
  1529 val fTrue_iconst = IConst ((const_prefix ^ "fTrue", @{const_name fTrue}), @{typ bool}, [])
  1529 val fTrue_iconst = IConst ((const_prefix ^ "fTrue", @{const_name fTrue}), @{typ bool}, [])
  1530 val predicator_iconst = IConst (`(make_fixed_const NONE) predicator_name, @{typ "bool => bool"}, [])
  1530 val predicator_iconst = IConst (`(make_fixed_const NONE) predicator_name, @{typ "bool => bool"}, [])
  1531 
  1531 
  1532 fun predicatify completish tm =
  1532 fun predicatify completish tm =
  1533   if completish then
  1533   if completish > 0 then
  1534     IApp (IApp (IConst (`I tptp_equal, @{typ "bool => bool => bool"}, []), tm), fTrue_iconst)
  1534     IApp (IApp (IConst (`I tptp_equal, @{typ "bool => bool => bool"}, []), tm), fTrue_iconst)
  1535   else
  1535   else
  1536     IApp (predicator_iconst, tm)
  1536     IApp (predicator_iconst, tm)
  1537 
  1537 
  1538 val app_op = `(make_fixed_const NONE) app_op_name
  1538 val app_op = `(make_fixed_const NONE) app_op_name
  1732       val could_specialize = could_specialize_helpers type_enc
  1732       val could_specialize = could_specialize_helpers type_enc
  1733     in
  1733     in
  1734       fold (fn ((helper_s, needs_sound), ths) =>
  1734       fold (fn ((helper_s, needs_sound), ths) =>
  1735                if (needs_sound andalso not sound) orelse
  1735                if (needs_sound andalso not sound) orelse
  1736                   (helper_s <> unmangled_s andalso
  1736                   (helper_s <> unmangled_s andalso
  1737                    (not completish orelse could_specialize)) then
  1737                    (completish < 2 orelse could_specialize)) then
  1738                  I
  1738                  I
  1739                else
  1739                else
  1740                  ths ~~ (1 upto length ths)
  1740                  ths ~~ (1 upto length ths)
  1741                  |> maps (dub_and_inst needs_sound o apfst (apsnd Thm.prop_of))
  1741                  |> maps (dub_and_inst needs_sound o apfst (apsnd Thm.prop_of))
  1742                  |> make_facts
  1742                  |> make_facts
  1743                  |> union (op = o apply2 #iformula))
  1743                  |> union (op = o apply2 #iformula))
  1744            (if completish then completish_helper_table else helper_table)
  1744            (if completish >= 2 then completish_helper_table else helper_table)
  1745     end
  1745     end
  1746   | NONE => I)
  1746   | NONE => I)
  1747 fun helper_facts_of_sym_table ctxt format type_enc completish sym_tab =
  1747 fun helper_facts_of_sym_table ctxt format type_enc completish sym_tab =
  1748   Symtab.fold_rev (add_helper_facts_of_sym ctxt format type_enc completish) sym_tab []
  1748   Symtab.fold_rev (add_helper_facts_of_sym ctxt format type_enc completish) sym_tab []
  1749 
  1749 
  2167 
  2167 
  2168 (* We add "bool" in case the helper "True_or_False" is included later. *)
  2168 (* We add "bool" in case the helper "True_or_False" is included later. *)
  2169 fun default_mono level completish =
  2169 fun default_mono level completish =
  2170   {maybe_finite_Ts = [@{typ bool}],
  2170   {maybe_finite_Ts = [@{typ bool}],
  2171    surely_infinite_Ts = (case level of Nonmono_Types (Strict, _) => [] | _ => known_infinite_types),
  2171    surely_infinite_Ts = (case level of Nonmono_Types (Strict, _) => [] | _ => known_infinite_types),
  2172    maybe_nonmono_Ts = [if completish then tvar_a else @{typ bool}]}
  2172    maybe_nonmono_Ts = [if completish >= 2 then tvar_a else @{typ bool}]}
  2173 
  2173 
  2174 (* This inference is described in section 4 of Blanchette et al., "Encoding
  2174 (* This inference is described in section 4 of Blanchette et al., "Encoding
  2175    monomorphic and polymorphic types", TACAS 2013. *)
  2175    monomorphic and polymorphic types", TACAS 2013. *)
  2176 fun add_iterm_mononotonicity_info _ _ (SOME false) _ mono = mono
  2176 fun add_iterm_mononotonicity_info _ _ (SOME false) _ mono = mono
  2177   | add_iterm_mononotonicity_info ctxt level _
  2177   | add_iterm_mononotonicity_info ctxt level _
  2570 fun generate_atp_problem ctxt generate_info format prem_role type_enc mode lam_trans
  2570 fun generate_atp_problem ctxt generate_info format prem_role type_enc mode lam_trans
  2571     uncurried_aliases readable_names presimp hyp_ts concl_t facts =
  2571     uncurried_aliases readable_names presimp hyp_ts concl_t facts =
  2572   let
  2572   let
  2573     val thy = Proof_Context.theory_of ctxt
  2573     val thy = Proof_Context.theory_of ctxt
  2574     val type_enc = type_enc |> adjust_type_enc format
  2574     val type_enc = type_enc |> adjust_type_enc format
  2575     val completish = (mode = Sledgehammer_Completish)
  2575     val completish = (case mode of Sledgehammer_Completish k => k | _ => 0)
  2576     (* Forcing explicit applications is expensive for polymorphic encodings,
  2576     (* Forcing explicit applications is expensive for polymorphic encodings,
  2577        because it takes only one existential variable ranging over "'a => 'b" to
  2577        because it takes only one existential variable ranging over "'a => 'b" to
  2578        ruin everything. Hence we do it only if there are few facts (which is
  2578        ruin everything. Hence we do it only if there are few facts (which is
  2579        normally the case for "metis" and the minimizer). *)
  2579        normally the case for "metis" and the minimizer). *)
  2580     val app_op_level =
  2580     val app_op_level =
  2581       if completish then
  2581       if completish > 0 then
  2582         Full_App_Op_And_Predicator
  2582         Full_App_Op_And_Predicator
  2583       else if length facts + length hyp_ts >= app_op_and_predicator_threshold then
  2583       else if length facts + length hyp_ts >= app_op_and_predicator_threshold then
  2584         if is_type_enc_polymorphic type_enc then Min_App_Op else Sufficient_App_Op
  2584         if is_type_enc_polymorphic type_enc then Min_App_Op else Sufficient_App_Op
  2585       else
  2585       else
  2586         Sufficient_App_Op_And_Predicator
  2586         Sufficient_App_Op_And_Predicator