src/HOL/Tools/Metis/metis_tactic.ML
changeset 52031 9a9238342963
parent 51717 9e7d1c139569
child 52732 b4da1f2ec73f
equal deleted inserted replaced
52030:9f6f0a89d16b 52031:9a9238342963
    45 
    45 
    46 (* Lightweight predicate type information comes in two flavors, "t = t'" and
    46 (* Lightweight predicate type information comes in two flavors, "t = t'" and
    47    "t => t'", where "t" and "t'" are the same term modulo type tags.
    47    "t => t'", where "t" and "t'" are the same term modulo type tags.
    48    In Isabelle, type tags are stripped away, so we are left with "t = t" or
    48    In Isabelle, type tags are stripped away, so we are left with "t = t" or
    49    "t => t". Type tag idempotence is also handled this way. *)
    49    "t => t". Type tag idempotence is also handled this way. *)
    50 fun reflexive_or_trivial_from_metis ctxt type_enc sym_tab concealed mth =
    50 fun reflexive_or_trivial_of_metis ctxt type_enc sym_tab concealed mth =
    51   let val thy = Proof_Context.theory_of ctxt in
    51   let val thy = Proof_Context.theory_of ctxt in
    52     case hol_clause_from_metis ctxt type_enc sym_tab concealed mth of
    52     case hol_clause_of_metis ctxt type_enc sym_tab concealed mth of
    53       Const (@{const_name HOL.eq}, _) $ _ $ t =>
    53       Const (@{const_name HOL.eq}, _) $ _ $ t =>
    54       let
    54       let
    55         val ct = cterm_of thy t
    55         val ct = cterm_of thy t
    56         val cT = ctyp_of_term ct
    56         val cT = ctyp_of_term ct
    57       in refl |> Drule.instantiate' [SOME cT] [SOME ct] end
    57       in refl |> Drule.instantiate' [SOME cT] [SOME ct] end
    60       |> HOLogic.mk_Trueprop |> cterm_of thy |> Thm.trivial
    60       |> HOLogic.mk_Trueprop |> cterm_of thy |> Thm.trivial
    61     | _ => raise Fail "expected reflexive or trivial clause"
    61     | _ => raise Fail "expected reflexive or trivial clause"
    62   end
    62   end
    63   |> Meson.make_meta_clause
    63   |> Meson.make_meta_clause
    64 
    64 
    65 fun lam_lifted_from_metis ctxt type_enc sym_tab concealed mth =
    65 fun lam_lifted_of_metis ctxt type_enc sym_tab concealed mth =
    66   let
    66   let
    67     val thy = Proof_Context.theory_of ctxt
    67     val thy = Proof_Context.theory_of ctxt
    68     val tac = rewrite_goals_tac @{thms lambda_def [abs_def]} THEN rtac refl 1
    68     val tac = rewrite_goals_tac @{thms lambda_def [abs_def]} THEN rtac refl 1
    69     val t = hol_clause_from_metis ctxt type_enc sym_tab concealed mth
    69     val t = hol_clause_of_metis ctxt type_enc sym_tab concealed mth
    70     val ct = cterm_of thy (HOLogic.mk_Trueprop t)
    70     val ct = cterm_of thy (HOLogic.mk_Trueprop t)
    71   in Goal.prove_internal [] ct (K tac) |> Meson.make_meta_clause end
    71   in Goal.prove_internal [] ct (K tac) |> Meson.make_meta_clause end
    72 
    72 
    73 fun add_vars_and_frees (t $ u) = fold (add_vars_and_frees) [t, u]
    73 fun add_vars_and_frees (t $ u) = fold (add_vars_and_frees) [t, u]
    74   | add_vars_and_frees (Abs (_, _, t)) = add_vars_and_frees t
    74   | add_vars_and_frees (Abs (_, _, t)) = add_vars_and_frees t
   156       val dischargers = map (fst o snd) th_cls_pairs
   156       val dischargers = map (fst o snd) th_cls_pairs
   157       val cls = cls |> map (Drule.eta_contraction_rule #> do_lams)
   157       val cls = cls |> map (Drule.eta_contraction_rule #> do_lams)
   158       val _ = trace_msg ctxt (fn () => "FOL_SOLVE: CONJECTURE CLAUSES")
   158       val _ = trace_msg ctxt (fn () => "FOL_SOLVE: CONJECTURE CLAUSES")
   159       val _ = app (fn th => trace_msg ctxt (fn () => Display.string_of_thm ctxt th)) cls
   159       val _ = app (fn th => trace_msg ctxt (fn () => Display.string_of_thm ctxt th)) cls
   160       val _ = trace_msg ctxt (fn () => "type_enc = " ^ type_enc)
   160       val _ = trace_msg ctxt (fn () => "type_enc = " ^ type_enc)
   161       val type_enc = type_enc_from_string Strict type_enc
   161       val type_enc = type_enc_of_string Strict type_enc
   162       val (sym_tab, axioms, ord_info, concealed) =
   162       val (sym_tab, axioms, ord_info, concealed) =
   163         prepare_metis_problem ctxt type_enc lam_trans cls ths
   163         prepare_metis_problem ctxt type_enc lam_trans cls ths
   164       fun get_isa_thm mth Isa_Reflexive_or_Trivial =
   164       fun get_isa_thm mth Isa_Reflexive_or_Trivial =
   165           reflexive_or_trivial_from_metis ctxt type_enc sym_tab concealed mth
   165           reflexive_or_trivial_of_metis ctxt type_enc sym_tab concealed mth
   166         | get_isa_thm mth Isa_Lambda_Lifted =
   166         | get_isa_thm mth Isa_Lambda_Lifted =
   167           lam_lifted_from_metis ctxt type_enc sym_tab concealed mth
   167           lam_lifted_of_metis ctxt type_enc sym_tab concealed mth
   168         | get_isa_thm _ (Isa_Raw ith) = ith
   168         | get_isa_thm _ (Isa_Raw ith) = ith
   169       val axioms = axioms |> map (fn (mth, ith) => (mth, get_isa_thm mth ith))
   169       val axioms = axioms |> map (fn (mth, ith) => (mth, get_isa_thm mth ith))
   170       val _ = trace_msg ctxt (fn () => "ISABELLE CLAUSES")
   170       val _ = trace_msg ctxt (fn () => "ISABELLE CLAUSES")
   171       val _ = app (fn (_, ith) => trace_msg ctxt (fn () => Display.string_of_thm ctxt ith)) axioms
   171       val _ = app (fn (_, ith) => trace_msg ctxt (fn () => Display.string_of_thm ctxt ith)) axioms
   172       val _ = trace_msg ctxt (fn () => "METIS CLAUSES")
   172       val _ = trace_msg ctxt (fn () => "METIS CLAUSES")