src/HOL/Tools/Metis/metis_tactics.ML
changeset 43159 29b55f292e0b
parent 43136 cf5cda219058
child 43160 d4f347508cd4
equal deleted inserted replaced
43158:686fa0a0696e 43159:29b55f292e0b
    44 val metisX_N = Binding.qualified_name_of (method_binding_for_mode MX)
    44 val metisX_N = Binding.qualified_name_of (method_binding_for_mode MX)
    45 
    45 
    46 val new_skolemizer =
    46 val new_skolemizer =
    47   Attrib.setup_config_bool @{binding metis_new_skolemizer} (K false)
    47   Attrib.setup_config_bool @{binding metis_new_skolemizer} (K false)
    48 
    48 
    49 fun is_false t = t aconv (HOLogic.mk_Trueprop HOLogic.false_const);
       
    50 
       
    51 (* Designed to work also with monomorphic instances of polymorphic theorems. *)
    49 (* Designed to work also with monomorphic instances of polymorphic theorems. *)
    52 fun have_common_thm ths1 ths2 =
    50 fun have_common_thm ths1 ths2 =
    53   exists (member (untyped_aconv o pairself prop_of) ths1)
    51   exists (member (untyped_aconv o pairself prop_of) ths1)
    54          (map Meson.make_meta_clause ths2)
    52          (map Meson.make_meta_clause ths2)
    55 
    53 
    58   | used_axioms _ _ = NONE
    56   | used_axioms _ _ = NONE
    59 
    57 
    60 (* Lightweight predicate type information comes in two flavors, "t = t'" and
    58 (* Lightweight predicate type information comes in two flavors, "t = t'" and
    61    "t => t'", where "t" and "t'" are the same term modulo type tags.
    59    "t => t'", where "t" and "t'" are the same term modulo type tags.
    62    In Isabelle, type tags are stripped away, so we are left with "t = t" or
    60    In Isabelle, type tags are stripped away, so we are left with "t = t" or
    63    "t => t". *)
    61    "t => t". Type tag idempotence is also handled this way. *)
    64 fun lightweight_tags_sym_theorem_from_metis ctxt sym_tab mth =
    62 fun reflexive_or_trivial_from_metis ctxt sym_tab mth =
    65   let val thy = Proof_Context.theory_of ctxt in
    63   let val thy = Proof_Context.theory_of ctxt in
    66     case hol_clause_from_metis_MX ctxt sym_tab
    64     case hol_clause_from_metis ctxt sym_tab mth of
    67              (Metis_LiteralSet.toList (Metis_Thm.clause mth)) of
       
    68       Const (@{const_name HOL.eq}, _) $ _ $ t =>
    65       Const (@{const_name HOL.eq}, _) $ _ $ t =>
    69       t |> cterm_of thy |> Thm.reflexive RS @{thm meta_eq_to_obj_eq}
    66       t |> cterm_of thy |> Thm.reflexive RS @{thm meta_eq_to_obj_eq}
    70     | Const (@{const_name disj}, _) $ t1 $ t2 =>
    67     | Const (@{const_name disj}, _) $ t1 $ t2 =>
    71       (if can HOLogic.dest_not t1 then t2 else t1)
    68       (if can HOLogic.dest_not t1 then t2 else t1)
    72       |> HOLogic.mk_Trueprop |> cterm_of thy |> Thm.trivial
    69       |> HOLogic.mk_Trueprop |> cterm_of thy |> Thm.trivial
    73     | _ => raise Fail "unexpected tags sym clause"
    70     | _ => raise Fail "unexpected tags sym clause"
    74   end
    71   end
    75   |> Meson.make_meta_clause
    72   |> Meson.make_meta_clause
       
    73 
       
    74 (* FIXME: implement using "hol_clause_from_metis ctxt sym_tab mth" *)
       
    75 fun specialize_helper mth ith = ith
    76 
    76 
    77 val clause_params =
    77 val clause_params =
    78   {ordering = Metis_KnuthBendixOrder.default,
    78   {ordering = Metis_KnuthBendixOrder.default,
    79    orderLiterals = Metis_Clause.UnsignedLiteralOrder,
    79    orderLiterals = Metis_Clause.UnsignedLiteralOrder,
    80    orderTerms = true}
    80    orderTerms = true}
   105       val _ = app (fn th => trace_msg ctxt (fn () => Display.string_of_thm ctxt th)) cls
   105       val _ = app (fn th => trace_msg ctxt (fn () => Display.string_of_thm ctxt th)) cls
   106       val _ = trace_msg ctxt (fn () => "THEOREM CLAUSES")
   106       val _ = trace_msg ctxt (fn () => "THEOREM CLAUSES")
   107       val _ = app (fn th => trace_msg ctxt (fn () => Display.string_of_thm ctxt th)) ths
   107       val _ = app (fn th => trace_msg ctxt (fn () => Display.string_of_thm ctxt th)) ths
   108       val (mode, sym_tab, {axioms, old_skolems, ...}) =
   108       val (mode, sym_tab, {axioms, old_skolems, ...}) =
   109         prepare_metis_problem ctxt mode type_sys cls ths
   109         prepare_metis_problem ctxt mode type_sys cls ths
   110       val axioms =
   110       fun get_isa_thm mth Isa_Reflexive_or_Trivial =
   111         axioms |> map
   111           reflexive_or_trivial_from_metis ctxt sym_tab mth
   112             (fn (mth, SOME th) => (mth, th)
   112         | get_isa_thm mth (Isa_Helper ith) =
   113               | (mth, NONE) =>
   113           ith |> should_specialize_helper (the type_sys) (prop_of ith)
   114                 (mth, lightweight_tags_sym_theorem_from_metis ctxt sym_tab mth))
   114                  ? specialize_helper mth
       
   115         | get_isa_thm _ (Isa_Raw ith) = ith
       
   116       val axioms = axioms |> map (fn (mth, ith) => (mth, get_isa_thm mth ith))
   115       val _ = trace_msg ctxt (fn () => "CLAUSES GIVEN TO METIS")
   117       val _ = trace_msg ctxt (fn () => "CLAUSES GIVEN TO METIS")
   116       val thms = map #1 axioms
   118       val thms = axioms |> map fst
   117       val _ = app (fn th => trace_msg ctxt (fn () => Metis_Thm.toString th)) thms
   119       val _ = app (fn th => trace_msg ctxt (fn () => Metis_Thm.toString th)) thms
   118       val _ = trace_msg ctxt (fn () => "mode = " ^ string_of_mode mode)
   120       val _ = trace_msg ctxt (fn () => "mode = " ^ string_of_mode mode)
   119       val _ = trace_msg ctxt (fn () => "START METIS PROVE PROCESS")
   121       val _ = trace_msg ctxt (fn () => "START METIS PROVE PROCESS")
   120   in
   122   in
   121       case filter (is_false o prop_of) cls of
   123       case filter (fn t => prop_of t aconv @{prop False}) cls of
   122           false_th::_ => [false_th RS @{thm FalseE}]
   124           false_th :: _ => [false_th RS @{thm FalseE}]
   123         | [] =>
   125         | [] =>
   124       case Metis_Resolution.new resolution_params {axioms = thms, conjecture = []}
   126       case Metis_Resolution.new resolution_params {axioms = thms, conjecture = []}
   125            |> Metis_Resolution.loop of
   127            |> Metis_Resolution.loop of
   126           Metis_Resolution.Contradiction mth =>
   128           Metis_Resolution.Contradiction mth =>
   127             let val _ = trace_msg ctxt (fn () => "METIS RECONSTRUCTION START: " ^
   129             let val _ = trace_msg ctxt (fn () => "METIS RECONSTRUCTION START: " ^