src/HOL/Tools/Meson/meson_clausify.ML
changeset 57466 feb414dadfd1
parent 56811 b66639331db5
child 58839 ccda99401bc8
equal deleted inserted replaced
57465:ed826e2053c9 57466:feb414dadfd1
   188       handle CTERM _ => (ct0, rev vars);
   188       handle CTERM _ => (ct0, rev vars);
   189 
   189 
   190 (* Given the definition of a Skolem function, return a theorem to replace
   190 (* Given the definition of a Skolem function, return a theorem to replace
   191    an existential formula by a use of that function.
   191    an existential formula by a use of that function.
   192    Example: "EX x. x : A & x ~: B ==> sko A B : A & sko A B ~: B"  [.] *)
   192    Example: "EX x. x : A & x ~: B ==> sko A B : A & sko A B ~: B"  [.] *)
   193 fun old_skolem_theorem_of_def thy rhs0 =
   193 fun old_skolem_theorem_of_def ctxt rhs0 =
   194   let
   194   let
   195     val ctxt = Proof_Context.init_global thy  (* FIXME proper context!? *)
   195     val thy = Proof_Context.theory_of ctxt
   196 
       
   197     val rhs = rhs0 |> Type.legacy_freeze_thaw |> #1 |> cterm_of thy
   196     val rhs = rhs0 |> Type.legacy_freeze_thaw |> #1 |> cterm_of thy
   198     val rhs' = rhs |> Thm.dest_comb |> snd
   197     val rhs' = rhs |> Thm.dest_comb |> snd
   199     val (ch, frees) = c_variant_abs_multi (rhs', [])
   198     val (ch, frees) = c_variant_abs_multi (rhs', [])
   200     val (hilbert, cabs) = ch |> Thm.dest_comb |>> term_of
   199     val (hilbert, cabs) = ch |> Thm.dest_comb |>> term_of
   201     val T =
   200     val T =
   202       case hilbert of
   201       case hilbert of
   203         Const (_, Type (@{type_name fun}, [_, T])) => T
   202         Const (_, Type (@{type_name fun}, [_, T])) => T
   204       | _ => raise TERM ("old_skolem_theorem_of_def: expected \"Eps\"",
   203       | _ => raise TERM ("old_skolem_theorem_of_def: expected \"Eps\"", [hilbert])
   205                          [hilbert])
       
   206     val cex = cterm_of thy (HOLogic.exists_const T)
   204     val cex = cterm_of thy (HOLogic.exists_const T)
   207     val ex_tm = Thm.apply cTrueprop (Thm.apply cex cabs)
   205     val ex_tm = Thm.apply cTrueprop (Thm.apply cex cabs)
   208     val conc =
   206     val conc =
   209       Drule.list_comb (rhs, frees)
   207       Drule.list_comb (rhs, frees)
   210       |> Drule.beta_conv cabs |> Thm.apply cTrueprop
   208       |> Drule.beta_conv cabs |> Thm.apply cTrueprop
   371     val choice_ths = choice_theorems thy
   369     val choice_ths = choice_theorems thy
   372     val (opt, (nnf_th, ctxt)) =
   370     val (opt, (nnf_th, ctxt)) =
   373       nnf_axiom choice_ths new_skolem ax_no th ctxt0
   371       nnf_axiom choice_ths new_skolem ax_no th ctxt0
   374     fun clausify th =
   372     fun clausify th =
   375       make_cnf (if new_skolem orelse null choice_ths then []
   373       make_cnf (if new_skolem orelse null choice_ths then []
   376                 else map (old_skolem_theorem_of_def thy) (old_skolem_defs th))
   374                 else map (old_skolem_theorem_of_def ctxt) (old_skolem_defs th))
   377                th ctxt ctxt
   375                th ctxt ctxt
   378     val (cnf_ths, ctxt) = clausify nnf_th
   376     val (cnf_ths, ctxt) = clausify nnf_th
   379     fun intr_imp ct th =
   377     fun intr_imp ct th =
   380       Thm.instantiate ([], map (pairself (cterm_of thy))
   378       Thm.instantiate ([], map (pairself (cterm_of thy))
   381                                [(Var (("i", 0), @{typ nat}),
   379                                [(Var (("i", 0), @{typ nat}),