src/HOL/Tools/Metis/metis_tactic.ML
changeset 69593 3dda49e08b9d
parent 67379 c2dfc510a38c
child 70488 c7ef6685c943
equal deleted inserted replaced
69592:a80d8ec6c998 69593:3dda49e08b9d
    28 open ATP_Problem_Generate
    28 open ATP_Problem_Generate
    29 open ATP_Proof_Reconstruct
    29 open ATP_Proof_Reconstruct
    30 open Metis_Generate
    30 open Metis_Generate
    31 open Metis_Reconstruct
    31 open Metis_Reconstruct
    32 
    32 
    33 val new_skolem = Attrib.setup_config_bool @{binding metis_new_skolem} (K false)
    33 val new_skolem = Attrib.setup_config_bool \<^binding>\<open>metis_new_skolem\<close> (K false)
    34 val advisory_simp = Attrib.setup_config_bool @{binding metis_advisory_simp} (K true)
    34 val advisory_simp = Attrib.setup_config_bool \<^binding>\<open>metis_advisory_simp\<close> (K true)
    35 
    35 
    36 (* Designed to work also with monomorphic instances of polymorphic theorems. *)
    36 (* Designed to work also with monomorphic instances of polymorphic theorems. *)
    37 fun have_common_thm ctxt ths1 ths2 =
    37 fun have_common_thm ctxt ths1 ths2 =
    38   exists (member (Term.aconv_untyped o apply2 Thm.prop_of) ths1)
    38   exists (member (Term.aconv_untyped o apply2 Thm.prop_of) ths1)
    39     (map (Meson.make_meta_clause ctxt) ths2)
    39     (map (Meson.make_meta_clause ctxt) ths2)
    46    "t => t'", where "t" and "t'" are the same term modulo type tags.
    46    "t => t'", where "t" and "t'" are the same term modulo type tags.
    47    In Isabelle, type tags are stripped away, so we are left with "t = t" or
    47    In Isabelle, type tags are stripped away, so we are left with "t = t" or
    48    "t => t". Type tag idempotence is also handled this way. *)
    48    "t => t". Type tag idempotence is also handled this way. *)
    49 fun reflexive_or_trivial_of_metis ctxt type_enc sym_tab concealed mth =
    49 fun reflexive_or_trivial_of_metis ctxt type_enc sym_tab concealed mth =
    50   (case hol_clause_of_metis ctxt type_enc sym_tab concealed mth of
    50   (case hol_clause_of_metis ctxt type_enc sym_tab concealed mth of
    51     Const (@{const_name HOL.eq}, _) $ _ $ t =>
    51     Const (\<^const_name>\<open>HOL.eq\<close>, _) $ _ $ t =>
    52     let
    52     let
    53       val ct = Thm.cterm_of ctxt t
    53       val ct = Thm.cterm_of ctxt t
    54       val cT = Thm.ctyp_of_cterm ct
    54       val cT = Thm.ctyp_of_cterm ct
    55     in refl |> Thm.instantiate' [SOME cT] [SOME ct] end
    55     in refl |> Thm.instantiate' [SOME cT] [SOME ct] end
    56   | Const (@{const_name disj}, _) $ t1 $ t2 =>
    56   | Const (\<^const_name>\<open>disj\<close>, _) $ t1 $ t2 =>
    57     (if can HOLogic.dest_not t1 then t2 else t1)
    57     (if can HOLogic.dest_not t1 then t2 else t1)
    58     |> HOLogic.mk_Trueprop |> Thm.cterm_of ctxt |> Thm.trivial
    58     |> HOLogic.mk_Trueprop |> Thm.cterm_of ctxt |> Thm.trivial
    59   | _ => raise Fail "expected reflexive or trivial clause")
    59   | _ => raise Fail "expected reflexive or trivial clause")
    60   |> Meson.make_meta_clause ctxt
    60   |> Meson.make_meta_clause ctxt
    61 
    61 
    92                 Abs (Name.uu, fastype_of v, abstract_over (v, Thm.term_of ct)) $ v
    92                 Abs (Name.uu, fastype_of v, abstract_over (v, Thm.term_of ct)) $ v
    93                 |> Thm.cterm_of ctxt
    93                 |> Thm.cterm_of ctxt
    94                 |> Conv.comb_conv (conv true ctxt))
    94                 |> Conv.comb_conv (conv true ctxt))
    95             else
    95             else
    96               Conv.abs_conv (conv false o snd) ctxt ct
    96               Conv.abs_conv (conv false o snd) ctxt ct
    97           | Const (@{const_name Meson.skolem}, _) $ _ => Thm.reflexive ct
    97           | Const (\<^const_name>\<open>Meson.skolem\<close>, _) $ _ => Thm.reflexive ct
    98           | _ => Conv.comb_conv (conv true ctxt) ct)
    98           | _ => Conv.comb_conv (conv true ctxt) ct)
    99       val eq_th = conv true ctxt (Thm.cprop_of th)
    99       val eq_th = conv true ctxt (Thm.cprop_of th)
   100       (* We replace the equation's left-hand side with a beta-equivalent term
   100       (* We replace the equation's left-hand side with a beta-equivalent term
   101          so that "Thm.equal_elim" works below. *)
   101          so that "Thm.equal_elim" works below. *)
   102       val t0 $ _ $ t2 = Thm.prop_of eq_th
   102       val t0 $ _ $ t2 = Thm.prop_of eq_th
   186     fun fall_back () =
   186     fun fall_back () =
   187       (verbose_warning ctxt
   187       (verbose_warning ctxt
   188            ("Falling back on " ^ quote (metis_call (hd fallback_type_encs) lam_trans) ^ "...");
   188            ("Falling back on " ^ quote (metis_call (hd fallback_type_encs) lam_trans) ^ "...");
   189        FOL_SOLVE unused fallback_type_encs lam_trans ctxt cls ths0)
   189        FOL_SOLVE unused fallback_type_encs lam_trans ctxt cls ths0)
   190   in
   190   in
   191     (case filter (fn t => Thm.prop_of t aconv @{prop False}) cls of
   191     (case filter (fn t => Thm.prop_of t aconv \<^prop>\<open>False\<close>) cls of
   192        false_th :: _ => [false_th RS @{thm FalseE}]
   192        false_th :: _ => [false_th RS @{thm FalseE}]
   193      | [] =>
   193      | [] =>
   194      (case Metis_Resolution.loop (Metis_Resolution.new (resolution_params ordering)
   194      (case Metis_Resolution.loop (Metis_Resolution.new (resolution_params ordering)
   195          {axioms = axioms |> map fst, conjecture = []}) of
   195          {axioms = axioms |> map fst, conjecture = []}) of
   196        Metis_Resolution.Contradiction mth =>
   196        Metis_Resolution.Contradiction mth =>
   286 fun consider_opt s =
   286 fun consider_opt s =
   287   if member (op =) metis_lam_transs s then apsnd (set_opt I s) else apfst (set_opt hd [s])
   287   if member (op =) metis_lam_transs s then apsnd (set_opt I s) else apfst (set_opt hd [s])
   288 
   288 
   289 val parse_metis_options =
   289 val parse_metis_options =
   290   Scan.optional
   290   Scan.optional
   291       (Args.parens (Args.name -- Scan.option (@{keyword ","} |-- Args.name))
   291       (Args.parens (Args.name -- Scan.option (\<^keyword>\<open>,\<close> |-- Args.name))
   292        >> (fn (s, s') =>
   292        >> (fn (s, s') =>
   293               (NONE, NONE) |> consider_opt s
   293               (NONE, NONE) |> consider_opt s
   294                            |> (case s' of SOME s' => consider_opt s' | _ => I)))
   294                            |> (case s' of SOME s' => consider_opt s' | _ => I)))
   295       (NONE, NONE)
   295       (NONE, NONE)
   296 
   296 
   297 val _ =
   297 val _ =
   298   Theory.setup
   298   Theory.setup
   299     (Method.setup @{binding metis}
   299     (Method.setup \<^binding>\<open>metis\<close>
   300       (Scan.lift parse_metis_options -- Attrib.thms >> (METHOD oo metis_method))
   300       (Scan.lift parse_metis_options -- Attrib.thms >> (METHOD oo metis_method))
   301       "Metis for FOL and HOL problems")
   301       "Metis for FOL and HOL problems")
   302 
   302 
   303 end;
   303 end;