src/HOL/ex/Rewrite_Examples.thy
changeset 74395 5399dfe9141c
parent 69597 ff784d5a5bfb
equal deleted inserted replaced
74392:b9331caf92c3 74395:5399dfe9141c
   220   apply (tactic \<open>
   220   apply (tactic \<open>
   221     let
   221     let
   222       val (x, ctxt) = yield_singleton Variable.add_fixes "x" \<^context>
   222       val (x, ctxt) = yield_singleton Variable.add_fixes "x" \<^context>
   223       (* Note that the pattern order is reversed *)
   223       (* Note that the pattern order is reversed *)
   224       val pat = [
   224       val pat = [
   225         Rewrite.For [(x, SOME \<^typ>\<open>nat\<close>)],
   225         Rewrite.For [(x, SOME \<^Type>\<open>nat\<close>)],
   226         Rewrite.In,
   226         Rewrite.In,
   227         Rewrite.Term (@{const plus(nat)} $ Free (x, \<^typ>\<open>nat\<close>) $ \<^term>\<open>1 :: nat\<close>, [])]
   227         Rewrite.Term (\<^Const>\<open>plus \<^Type>\<open>nat\<close> for \<open>Free (x, \<^Type>\<open>nat\<close>)\<close> \<^term>\<open>1 :: nat\<close>\<close>, [])]
   228       val to = NONE
   228       val to = NONE
   229     in CCONVERSION (Rewrite.rewrite_conv ctxt (pat, to) @{thms add.commute}) 1 end
   229     in CCONVERSION (Rewrite.rewrite_conv ctxt (pat, to) @{thms add.commute}) 1 end
   230   \<close>)
   230   \<close>)
   231   apply (fact assms)
   231   apply (fact assms)
   232   done
   232   done
   238     let
   238     let
   239       val (x, ctxt) = yield_singleton Variable.add_fixes "x" \<^context>
   239       val (x, ctxt) = yield_singleton Variable.add_fixes "x" \<^context>
   240       val pat = [
   240       val pat = [
   241         Rewrite.Concl,
   241         Rewrite.Concl,
   242         Rewrite.In,
   242         Rewrite.In,
   243         Rewrite.Term (Free ("Q", (\<^typ>\<open>int\<close> --> TVar (("'b",0), [])) --> \<^typ>\<open>bool\<close>)
   243         Rewrite.Term (Free ("Q", (\<^Type>\<open>int\<close> --> TVar (("'b",0), [])) --> \<^Type>\<open>bool\<close>)
   244           $ Abs ("x", \<^typ>\<open>int\<close>, Rewrite.mk_hole 1 (\<^typ>\<open>int\<close> --> TVar (("'b",0), [])) $ Bound 0), [(x, \<^typ>\<open>int\<close>)]),
   244           $ Abs ("x", \<^Type>\<open>int\<close>, Rewrite.mk_hole 1 (\<^Type>\<open>int\<close> --> TVar (("'b",0), [])) $ Bound 0), [(x, \<^Type>\<open>int\<close>)]),
   245         Rewrite.In,
   245         Rewrite.In,
   246         Rewrite.Term (@{const plus(int)} $ Free (x, \<^typ>\<open>int\<close>) $ Var (("c", 0), \<^typ>\<open>int\<close>), [])
   246         Rewrite.Term (\<^Const>\<open>plus \<^Type>\<open>int\<close> for \<open>Free (x, \<^Type>\<open>int\<close>)\<close> \<open>Var (("c", 0), \<^Type>\<open>int\<close>)\<close>\<close>, [])
   247         ]
   247         ]
   248       val to = NONE
   248       val to = NONE
   249     in CCONVERSION (Rewrite.rewrite_conv ctxt (pat, to) @{thms add.commute}) 1 end
   249     in CCONVERSION (Rewrite.rewrite_conv ctxt (pat, to) @{thms add.commute}) 1 end
   250   \<close>)
   250   \<close>)
   251   apply (fact assms)
   251   apply (fact assms)
   259     Rewrite.Concl,
   259     Rewrite.Concl,
   260     Rewrite.In,
   260     Rewrite.In,
   261     Rewrite.Term (Free ("Q", (\<^typ>\<open>int\<close> --> TVar (("'b",0), [])) --> \<^typ>\<open>bool\<close>)
   261     Rewrite.Term (Free ("Q", (\<^typ>\<open>int\<close> --> TVar (("'b",0), [])) --> \<^typ>\<open>bool\<close>)
   262       $ Abs ("x", \<^typ>\<open>int\<close>, Rewrite.mk_hole 1 (\<^typ>\<open>int\<close> --> TVar (("'b",0), [])) $ Bound 0), [(x, \<^typ>\<open>int\<close>)]),
   262       $ Abs ("x", \<^typ>\<open>int\<close>, Rewrite.mk_hole 1 (\<^typ>\<open>int\<close> --> TVar (("'b",0), [])) $ Bound 0), [(x, \<^typ>\<open>int\<close>)]),
   263     Rewrite.In,
   263     Rewrite.In,
   264     Rewrite.Term (@{const plus(int)} $ Free (x, \<^typ>\<open>int\<close>) $ Var (("c", 0), \<^typ>\<open>int\<close>), [])
   264     Rewrite.Term (\<^Const>\<open>plus \<^Type>\<open>int\<close> for \<open>Free (x, \<^Type>\<open>int\<close>)\<close> \<open>Var (("c", 0), \<^Type>\<open>int\<close>)\<close>\<close>, [])
   265     ]
   265     ]
   266   val to = NONE
   266   val to = NONE
   267   val th = Rewrite.rewrite_conv ctxt (pat, to) @{thms add.commute} ct
   267   val th = Rewrite.rewrite_conv ctxt (pat, to) @{thms add.commute} ct
   268 \<close>
   268 \<close>
   269 
   269 
   272 ML \<open>
   272 ML \<open>
   273   val ct = \<^cterm>\<open>(\<lambda>b :: int. (\<lambda>a. b + a))\<close>
   273   val ct = \<^cterm>\<open>(\<lambda>b :: int. (\<lambda>a. b + a))\<close>
   274   val (x, ctxt) = yield_singleton Variable.add_fixes "x" \<^context>
   274   val (x, ctxt) = yield_singleton Variable.add_fixes "x" \<^context>
   275   val pat = [
   275   val pat = [
   276     Rewrite.In,
   276     Rewrite.In,
   277     Rewrite.Term (@{const plus(int)} $ Var (("c", 0), \<^typ>\<open>int\<close>) $ Var (("c", 0), \<^typ>\<open>int\<close>), [])
   277     Rewrite.Term (\<^Const>\<open>plus \<^Type>\<open>int\<close> for \<open>Var (("c", 0), \<^Type>\<open>int\<close>)\<close> \<open>Var (("c", 0), \<^Type>\<open>int\<close>)\<close>\<close>, [])
   278     ]
   278     ]
   279   val to = NONE
   279   val to = NONE
   280   val _ =
   280   val _ =
   281     case try (Rewrite.rewrite_conv ctxt (pat, to) @{thms add.commute}) ct of
   281     case try (Rewrite.rewrite_conv ctxt (pat, to) @{thms add.commute}) ct of
   282       NONE => ()
   282       NONE => ()