src/HOL/Tools/Metis/metis_tactic.ML
changeset 57408 39b3562e9edc
parent 57263 2b6a96cc64c9
child 58818 ee85e7b82d00
equal deleted inserted replaced
57407:140e16bc2a40 57408:39b3562e9edc
    44    "t => t'", where "t" and "t'" are the same term modulo type tags.
    44    "t => t'", where "t" and "t'" are the same term modulo type tags.
    45    In Isabelle, type tags are stripped away, so we are left with "t = t" or
    45    In Isabelle, type tags are stripped away, so we are left with "t = t" or
    46    "t => t". Type tag idempotence is also handled this way. *)
    46    "t => t". Type tag idempotence is also handled this way. *)
    47 fun reflexive_or_trivial_of_metis ctxt type_enc sym_tab concealed mth =
    47 fun reflexive_or_trivial_of_metis ctxt type_enc sym_tab concealed mth =
    48   let val thy = Proof_Context.theory_of ctxt in
    48   let val thy = Proof_Context.theory_of ctxt in
    49     case hol_clause_of_metis ctxt type_enc sym_tab concealed mth of
    49     (case hol_clause_of_metis ctxt type_enc sym_tab concealed mth of
    50       Const (@{const_name HOL.eq}, _) $ _ $ t =>
    50       Const (@{const_name HOL.eq}, _) $ _ $ t =>
    51       let
    51       let
    52         val ct = cterm_of thy t
    52         val ct = cterm_of thy t
    53         val cT = ctyp_of_term ct
    53         val cT = ctyp_of_term ct
    54       in refl |> Drule.instantiate' [SOME cT] [SOME ct] end
    54       in refl |> Drule.instantiate' [SOME cT] [SOME ct] end
    55     | Const (@{const_name disj}, _) $ t1 $ t2 =>
    55     | Const (@{const_name disj}, _) $ t1 $ t2 =>
    56       (if can HOLogic.dest_not t1 then t2 else t1)
    56       (if can HOLogic.dest_not t1 then t2 else t1)
    57       |> HOLogic.mk_Trueprop |> cterm_of thy |> Thm.trivial
    57       |> HOLogic.mk_Trueprop |> cterm_of thy |> Thm.trivial
    58     | _ => raise Fail "expected reflexive or trivial clause"
    58     | _ => raise Fail "expected reflexive or trivial clause")
    59   end
    59   end
    60   |> Meson.make_meta_clause
    60   |> Meson.make_meta_clause
    61 
    61 
    62 fun lam_lifted_of_metis ctxt type_enc sym_tab concealed mth =
    62 fun lam_lifted_of_metis ctxt type_enc sym_tab concealed mth =
    63   let
    63   let
    80     let
    80     let
    81       val thy = Proof_Context.theory_of ctxt
    81       val thy = Proof_Context.theory_of ctxt
    82       fun conv first ctxt ct =
    82       fun conv first ctxt ct =
    83         if Meson_Clausify.is_quasi_lambda_free (term_of ct) then
    83         if Meson_Clausify.is_quasi_lambda_free (term_of ct) then
    84           Thm.reflexive ct
    84           Thm.reflexive ct
    85         else case term_of ct of
    85         else
    86           Abs (_, _, u) =>
    86           (case term_of ct of
    87           if first then
    87             Abs (_, _, u) =>
    88             case add_vars_and_frees u [] of
    88             if first then
    89               [] =>
    89               (case add_vars_and_frees u [] of
       
    90                 [] =>
       
    91                 Conv.abs_conv (conv false o snd) ctxt ct
       
    92                 |> (fn th => Meson.first_order_resolve th @{thm Metis.eq_lambdaI})
       
    93               | v :: _ =>
       
    94                 Abs (Name.uu, fastype_of v, abstract_over (v, term_of ct)) $ v
       
    95                 |> cterm_of thy
       
    96                 |> Conv.comb_conv (conv true ctxt))
       
    97             else
    90               Conv.abs_conv (conv false o snd) ctxt ct
    98               Conv.abs_conv (conv false o snd) ctxt ct
    91               |> (fn th => Meson.first_order_resolve th @{thm Metis.eq_lambdaI})
    99           | Const (@{const_name Meson.skolem}, _) $ _ => Thm.reflexive ct
    92             | v :: _ =>
   100           | _ => Conv.comb_conv (conv true ctxt) ct)
    93               Abs (Name.uu, fastype_of v, abstract_over (v, term_of ct)) $ v
       
    94               |> cterm_of thy
       
    95               |> Conv.comb_conv (conv true ctxt)
       
    96           else
       
    97             Conv.abs_conv (conv false o snd) ctxt ct
       
    98         | Const (@{const_name Meson.skolem}, _) $ _ => Thm.reflexive ct
       
    99         | _ => Conv.comb_conv (conv true ctxt) ct
       
   100       val eq_th = conv true ctxt (cprop_of th)
   101       val eq_th = conv true ctxt (cprop_of th)
   101       (* We replace the equation's left-hand side with a beta-equivalent term
   102       (* We replace the equation's left-hand side with a beta-equivalent term
   102          so that "Thm.equal_elim" works below. *)
   103          so that "Thm.equal_elim" works below. *)
   103       val t0 $ _ $ t2 = prop_of eq_th
   104       val t0 $ _ $ t2 = prop_of eq_th
   104       val eq_ct = t0 $ prop_of th $ t2 |> cterm_of thy
   105       val eq_ct = t0 $ prop_of th $ t2 |> cterm_of thy
   124 fun kbo_advisory_simp_ordering ord_info =
   125 fun kbo_advisory_simp_ordering ord_info =
   125   let
   126   let
   126     fun weight (m, _) =
   127     fun weight (m, _) =
   127       AList.lookup (op =) ord_info (Metis_Name.toString m) |> the_default 1
   128       AList.lookup (op =) ord_info (Metis_Name.toString m) |> the_default 1
   128     fun precedence p =
   129     fun precedence p =
   129       case int_ord (pairself weight p) of
   130       (case int_ord (pairself weight p) of
   130         EQUAL => #precedence Metis_KnuthBendixOrder.default p
   131         EQUAL => #precedence Metis_KnuthBendixOrder.default p
   131       | ord => ord
   132       | ord => ord)
   132   in {weight = weight, precedence = precedence} end
   133   in {weight = weight, precedence = precedence} end
   133 
   134 
   134 fun metis_call type_enc lam_trans =
   135 fun metis_call type_enc lam_trans =
   135   let
   136   let
   136     val type_enc =
   137     val type_enc =