src/HOL/Library/cconv.ML
changeset 60049 e4a5dfee0f9c
parent 60048 e9c30726ca8e
child 60050 dc6ac152d864
equal deleted inserted replaced
60048:e9c30726ca8e 60049:e4a5dfee0f9c
   124        let
   124        let
   125          (* Instantiate the rule properly and apply it to the eq theorem. *)
   125          (* Instantiate the rule properly and apply it to the eq theorem. *)
   126          fun abstract_rule u v eq =
   126          fun abstract_rule u v eq =
   127            let
   127            let
   128              (* Take a variable v and an equality theorem of form:
   128              (* Take a variable v and an equality theorem of form:
   129                   P1 Pure.imp ... Pure.imp Pn Pure.imp L v == R v
   129                   P1 \<Longrightarrow> ... \<Longrightarrow> Pn \<Longrightarrow> L v \<equiv> R v
   130                 And build a term of form:
   130                 And build a term of form:
   131                   !!v. (%x. L x) v == (%x. R x) v *)
   131                   \<And>v. (\<lambda>x. L x) v \<equiv> (\<lambda>x. R x) v *)
   132              fun mk_concl var eq =
   132              fun mk_concl var eq =
   133                let
   133                let
   134                  val certify = Thm.cterm_of ctxt
   134                  val certify = Thm.cterm_of ctxt
   135                  fun abs term = (Term.lambda var term) $ var
   135                  fun abs term = (Term.lambda var term) $ var
   136                  fun equals_cong f t =
   136                  fun equals_cong f t =
   163 val arg1_cconv = fun_cconv o arg_cconv
   163 val arg1_cconv = fun_cconv o arg_cconv
   164 val fun2_cconv = fun_cconv o fun_cconv
   164 val fun2_cconv = fun_cconv o fun_cconv
   165 
   165 
   166 (* conversions on HHF rules *)
   166 (* conversions on HHF rules *)
   167 
   167 
   168 (*rewrite B in !!x1 ... xn. B*)
   168 (*rewrite B in \<And>x1 ... xn. B*)
   169 fun params_cconv n cv ctxt ct =
   169 fun params_cconv n cv ctxt ct =
   170   if n <> 0 andalso Logic.is_all (Thm.term_of ct)
   170   if n <> 0 andalso Logic.is_all (Thm.term_of ct)
   171   then arg_cconv (abs_cconv (params_cconv (n - 1) cv o #2) ctxt) ct
   171   then arg_cconv (abs_cconv (params_cconv (n - 1) cv o #2) ctxt) ct
   172   else cv ctxt ct
   172   else cv ctxt ct
   173 
   173 
   174 (* TODO: This code behaves not exactly like Conv.prems_cconv does.
   174 (* TODO: This code behaves not exactly like Conv.prems_cconv does.
   175          Fix this! *)
   175          Fix this! *)
   176 (*rewrite the A's in A1 Pure.imp ... Pure.imp An Pure.imp B*)
   176 (*rewrite the A's in A1 \<Longrightarrow> ... \<Longrightarrow> An \<Longrightarrow> B*)
   177 fun prems_cconv 0 cv ct = cv ct
   177 fun prems_cconv 0 cv ct = cv ct
   178   | prems_cconv n cv ct =
   178   | prems_cconv n cv ct =
   179       (case ct |> Thm.term_of of
   179       (case ct |> Thm.term_of of
   180         (Const (@{const_name "Pure.imp"}, _) $ _) $ _ =>
   180         (Const (@{const_name "Pure.imp"}, _) $ _) $ _ =>
   181           ((if n = 1 then fun_cconv else I) o arg_cconv) (prems_cconv (n-1) cv) ct
   181           ((if n = 1 then fun_cconv else I) o arg_cconv) (prems_cconv (n-1) cv) ct
   182       | _ =>  cv ct)
   182       | _ =>  cv ct)
   183 
   183 
   184 (*rewrite B in A1 Pure.imp ... Pure.imp An Pure.imp B*)
   184 (*rewrite B in A1 \<Longrightarrow> ... \<Longrightarrow> An \<Longrightarrow> B*)
   185 fun concl_cconv 0 cv ct = cv ct
   185 fun concl_cconv 0 cv ct = cv ct
   186   | concl_cconv n cv ct =
   186   | concl_cconv n cv ct =
   187       (case ct |> Thm.term_of of
   187       (case ct |> Thm.term_of of
   188         (Const (@{const_name "Pure.imp"}, _) $ _) $ _ => arg_cconv (concl_cconv (n-1) cv) ct
   188         (Const (@{const_name "Pure.imp"}, _) $ _) $ _ => arg_cconv (concl_cconv (n-1) cv) ct
   189       | _ =>  cv ct)
   189       | _ =>  cv ct)