src/HOL/Tools/Sledgehammer/clausifier.ML
changeset 38280 577f138af235
parent 38278 aee5862973e0
child 38282 319c59682c51
equal deleted inserted replaced
38279:7497c22bb185 38280:577f138af235
    53     fun dec_sko (Const (@{const_name Ex}, _) $ (body as Abs (s', T, p))) rhss =
    53     fun dec_sko (Const (@{const_name Ex}, _) $ (body as Abs (s', T, p))) rhss =
    54         (*Existential: declare a Skolem function, then insert into body and continue*)
    54         (*Existential: declare a Skolem function, then insert into body and continue*)
    55         let
    55         let
    56           val args = OldTerm.term_frees body
    56           val args = OldTerm.term_frees body
    57           val Ts = map type_of args
    57           val Ts = map type_of args
    58           val cT = Ts ---> T (* FIXME: use "skolem_type_and_args" *)
    58           val cT = Ts ---> T
    59           (* Forms a lambda-abstraction over the formal parameters *)
    59           (* Forms a lambda-abstraction over the formal parameters *)
    60           val rhs =
    60           val rhs =
    61             list_abs_free (map dest_Free args,
    61             list_abs_free (map dest_Free args,
    62                            HOLogic.choice_const T $ beta_eta_under_lambdas body)
    62                            HOLogic.choice_const T $ beta_eta_under_lambdas body)
    63             |> mk_skolem_id
    63             |> mk_skolem_id
    76 
    76 
    77 (**** REPLACING ABSTRACTIONS BY COMBINATORS ****)
    77 (**** REPLACING ABSTRACTIONS BY COMBINATORS ****)
    78 
    78 
    79 (*Returns the vars of a theorem*)
    79 (*Returns the vars of a theorem*)
    80 fun vars_of_thm th =
    80 fun vars_of_thm th =
    81   map (Thm.cterm_of (theory_of_thm th) o Var) (Thm.fold_terms Term.add_vars th []);
    81   map (cterm_of (theory_of_thm th) o Var) (Thm.fold_terms Term.add_vars th []);
    82 
    82 
    83 val fun_cong_all = @{thm expand_fun_eq [THEN iffD1]}
    83 val fun_cong_all = @{thm expand_fun_eq [THEN iffD1]}
    84 
    84 
    85 (* Removes the lambdas from an equation of the form "t = (%x. u)".
    85 (* Removes the lambdas from an equation of the form "t = (%x. u)".
    86    (Cf. "extensionalize_term" in "ATP_Systems".) *)
    86    (Cf. "extensionalize_term" in "ATP_Systems".) *)
   179                      "\nException message: " ^ msg ^ ".");
   179                      "\nException message: " ^ msg ^ ".");
   180             (* A type variable of sort "{}" will make abstraction fail. *)
   180             (* A type variable of sort "{}" will make abstraction fail. *)
   181             TrueI)
   181             TrueI)
   182 
   182 
   183 (*cterms are used throughout for efficiency*)
   183 (*cterms are used throughout for efficiency*)
   184 val cTrueprop = Thm.cterm_of @{theory HOL} HOLogic.Trueprop;
   184 val cTrueprop = cterm_of @{theory HOL} HOLogic.Trueprop;
   185 
   185 
   186 (*Given an abstraction over n variables, replace the bound variables by free
   186 (*Given an abstraction over n variables, replace the bound variables by free
   187   ones. Return the body, along with the list of free variables.*)
   187   ones. Return the body, along with the list of free variables.*)
   188 fun c_variant_abs_multi (ct0, vars) =
   188 fun c_variant_abs_multi (ct0, vars) =
   189       let val (cv,ct) = Thm.dest_abs NONE ct0
   189       let val (cv,ct) = Thm.dest_abs NONE ct0
   195 (* Given the definition of a Skolem function, return a theorem to replace
   195 (* Given the definition of a Skolem function, return a theorem to replace
   196    an existential formula by a use of that function.
   196    an existential formula by a use of that function.
   197    Example: "EX x. x : A & x ~: B ==> sko A B : A & sko A B ~: B"  [.] *)
   197    Example: "EX x. x : A & x ~: B ==> sko A B : A & sko A B ~: B"  [.] *)
   198 fun skolem_theorem_of_def thy rhs0 =
   198 fun skolem_theorem_of_def thy rhs0 =
   199   let
   199   let
   200     val rhs = rhs0 |> Type.legacy_freeze_thaw |> #1 |> Thm.cterm_of thy
   200     val rhs = rhs0 |> Type.legacy_freeze_thaw |> #1 |> cterm_of thy
   201     val rhs' = rhs |> Thm.dest_comb |> snd
   201     val rhs' = rhs |> Thm.dest_comb |> snd
   202     val (ch, frees) = c_variant_abs_multi (rhs', [])
   202     val (ch, frees) = c_variant_abs_multi (rhs', [])
   203     val (hilbert, cabs) = ch |> Thm.dest_comb |>> term_of
   203     val (hilbert, cabs) = ch |> Thm.dest_comb |>> term_of
   204     val T =
   204     val T =
   205       case hilbert of
   205       case hilbert of
   206         Const (@{const_name Eps}, Type (@{type_name fun}, [_, T])) => T
   206         Const (@{const_name Eps}, Type (@{type_name fun}, [_, T])) => T
   207       | _ => raise TERM ("skolem_theorem_of_def: expected \"Eps\"", [hilbert])
   207       | _ => raise TERM ("skolem_theorem_of_def: expected \"Eps\"", [hilbert])
   208     val cex = Thm.cterm_of thy (HOLogic.exists_const T)
   208     val cex = cterm_of thy (HOLogic.exists_const T)
   209     val ex_tm = Thm.capply cTrueprop (Thm.capply cex cabs)
   209     val ex_tm = Thm.capply cTrueprop (Thm.capply cex cabs)
   210     val conc =
   210     val conc =
   211       Drule.list_comb (rhs, frees)
   211       Drule.list_comb (rhs, frees)
   212       |> Drule.beta_conv cabs |> Thm.capply cTrueprop
   212       |> Drule.beta_conv cabs |> Thm.capply cTrueprop
   213     fun tacf [prem] =
   213     fun tacf [prem] =