src/HOL/Library/Old_Recdef.thy
 changeset 44014 88bd7d74a2c1 parent 44013 5cfc1c36ae97 child 46942 f5c2d66faa04
```     1.1 --- a/src/HOL/Library/Old_Recdef.thy	Tue Aug 02 10:36:50 2011 +0200
1.2 +++ b/src/HOL/Library/Old_Recdef.thy	Tue Aug 02 11:52:57 2011 +0200
1.3 @@ -5,7 +5,7 @@
1.4  header {* TFL: recursive function definitions *}
1.5
1.6  theory Old_Recdef
1.7 -imports Main
1.8 +imports Wfrec
1.9  uses
1.10    ("~~/src/HOL/Tools/TFL/casesplit.ML")
1.11    ("~~/src/HOL/Tools/TFL/utils.ML")
1.12 @@ -19,95 +19,6 @@
1.13    ("~~/src/HOL/Tools/recdef.ML")
1.14  begin
1.15
1.16 -inductive
1.17 -  wfrec_rel :: "('a * 'a) set => (('a => 'b) => 'a => 'b) => 'a => 'b => bool"
1.18 -  for R :: "('a * 'a) set"
1.19 -  and F :: "('a => 'b) => 'a => 'b"
1.20 -where
1.21 -  wfrecI: "ALL z. (z, x) : R --> wfrec_rel R F z (g z) ==>
1.22 -            wfrec_rel R F x (F g x)"
1.23 -
1.24 -definition
1.25 -  cut        :: "('a => 'b) => ('a * 'a)set => 'a => 'a => 'b" where
1.26 -  "cut f r x == (%y. if (y,x):r then f y else undefined)"
1.27 -
1.28 -definition
1.29 -  adm_wf :: "('a * 'a) set => (('a => 'b) => 'a => 'b) => bool" where
1.30 -  "adm_wf R F == ALL f g x.
1.31 -     (ALL z. (z, x) : R --> f z = g z) --> F f x = F g x"
1.32 -
1.33 -definition
1.34 -  wfrec :: "('a * 'a) set => (('a => 'b) => 'a => 'b) => 'a => 'b" where
1.35 -  "wfrec R F == %x. THE y. wfrec_rel R (%f x. F (cut f R x) x) x y"
1.36 -
1.37 -subsection{*Well-Founded Recursion*}
1.38 -
1.39 -text{*cut*}
1.40 -
1.41 -lemma cuts_eq: "(cut f r x = cut g r x) = (ALL y. (y,x):r --> f(y)=g(y))"
1.42 -by (simp add: fun_eq_iff cut_def)
1.43 -
1.44 -lemma cut_apply: "(x,a):r ==> (cut f r a)(x) = f(x)"
1.46 -
1.47 -text{*Inductive characterization of wfrec combinator; for details see:
1.48 -John Harrison, "Inductive definitions: automation and application"*}
1.49 -
1.50 -lemma wfrec_unique: "[| adm_wf R F; wf R |] ==> EX! y. wfrec_rel R F x y"
1.52 -apply (erule_tac a=x in wf_induct)
1.53 -apply (rule ex1I)
1.54 -apply (rule_tac g = "%x. THE y. wfrec_rel R F x y" in wfrec_rel.wfrecI)
1.55 -apply (fast dest!: theI')
1.56 -apply (erule wfrec_rel.cases, simp)
1.57 -apply (erule allE, erule allE, erule allE, erule mp)
1.58 -apply (fast intro: the_equality [symmetric])
1.59 -done
1.60 -
1.61 -lemma adm_lemma: "adm_wf R (%f x. F (cut f R x) x)"
1.63 -apply (intro strip)
1.64 -apply (rule cuts_eq [THEN iffD2, THEN subst], assumption)
1.65 -apply (rule refl)
1.66 -done
1.67 -
1.68 -lemma wfrec: "wf(r) ==> wfrec r H a = H (cut (wfrec r H) r a) a"
1.70 -apply (rule adm_lemma [THEN wfrec_unique, THEN the1_equality], assumption)
1.71 -apply (rule wfrec_rel.wfrecI)
1.72 -apply (intro strip)
1.73 -apply (erule adm_lemma [THEN wfrec_unique, THEN theI'])
1.74 -done
1.75 -
1.76 -
1.77 -text{** This form avoids giant explosions in proofs.  NOTE USE OF ==*}
1.78 -lemma def_wfrec: "[| f==wfrec r H;  wf(r) |] ==> f(a) = H (cut f r a) a"
1.79 -apply auto
1.80 -apply (blast intro: wfrec)
1.81 -done
1.82 -
1.83 -
1.84 -subsection {* Nitpick setup *}
1.85 -
1.86 -axiomatization wf_wfrec :: "('a \<times> 'a \<Rightarrow> bool) \<Rightarrow> (('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b"
1.87 -
1.88 -definition wf_wfrec' :: "('a \<times> 'a \<Rightarrow> bool) \<Rightarrow> (('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b" where
1.89 -[nitpick_simp]: "wf_wfrec' R F x = F (cut (wf_wfrec R F) R x) x"
1.90 -
1.91 -definition wfrec' ::  "('a \<times> 'a \<Rightarrow> bool) \<Rightarrow> (('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b" where
1.92 -"wfrec' R F x \<equiv> if wf R then wf_wfrec' R F x
1.93 -                else THE y. wfrec_rel R (%f x. F (cut f R x) x) x y"
1.94 -
1.95 -setup {*
1.96 -  Nitpick_HOL.register_ersatz_global
1.97 -    [(@{const_name wf_wfrec}, @{const_name wf_wfrec'}),
1.98 -     (@{const_name wfrec}, @{const_name wfrec'})]
1.99 -*}
1.100 -
1.101 -hide_const (open) wf_wfrec wf_wfrec' wfrec'
1.102 -hide_fact (open) wf_wfrec'_def wfrec'_def
1.103 -
1.104 -
1.105  subsection {* Lemmas for TFL *}
1.106
1.107  lemma tfl_wf_induct: "ALL R. wf R -->
1.108 @@ -163,31 +74,7 @@
1.109  use "~~/src/HOL/Tools/recdef.ML"
1.110  setup Recdef.setup
1.111
1.112 -text {*Wellfoundedness of @{text same_fst}*}
1.113 -
1.114 -definition
1.115 - same_fst :: "('a => bool) => ('a => ('b * 'b)set) => (('a*'b)*('a*'b))set"
1.116 -where
1.117 -    "same_fst P R == {((x',y'),(x,y)) . x'=x & P x & (y',y) : R x}"
1.118 -   --{*For @{text rec_def} declarations where the first n parameters
1.119 -       stay unchanged in the recursive call. *}
1.120 -
1.121 -lemma same_fstI [intro!]:
1.122 -     "[| P x; (y',y) : R x |] ==> ((x,y'),(x,y)) : same_fst P R"
1.124 -
1.125 -lemma wf_same_fst:
1.126 -  assumes prem: "(!!x. P x ==> wf(R x))"
1.127 -  shows "wf(same_fst P R)"
1.128 -apply (simp cong del: imp_cong add: wf_def same_fst_def)
1.129 -apply (intro strip)
1.130 -apply (rename_tac a b)
1.131 -apply (case_tac "wf (R a)")
1.132 - apply (erule_tac a = b in wf_induct, blast)
1.133 -apply (blast intro: prem)
1.134 -done
1.135 -
1.136 -text {*Rule setup*}
1.137 +subsection {* Rule setup *}
1.138
1.139  lemmas [recdef_simp] =
1.140    inv_image_def
```