moved Wfrec to Main, since it is a dependency of cardinals, hence BNFs
authorblanchet
Thu Jan 16 15:47:33 2014 +0100 (2014-01-16)
changeset 550169fc7e7753d86
parent 55015 e33c5bd729ff
child 55017 2df6ad1dbd66
moved Wfrec to Main, since it is a dependency of cardinals, hence BNFs
src/HOL/Library/Wfrec.thy
src/HOL/Wfrec.thy
     1.1 --- a/src/HOL/Library/Wfrec.thy	Wed Jan 15 23:25:28 2014 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,121 +0,0 @@
     1.4 -(*  Title:      HOL/Library/Wfrec.thy
     1.5 -    Author:     Tobias Nipkow
     1.6 -    Author:     Lawrence C Paulson
     1.7 -    Author:     Konrad Slind
     1.8 -*)
     1.9 -
    1.10 -header {* Well-Founded Recursion Combinator *}
    1.11 -
    1.12 -theory Wfrec
    1.13 -imports Main
    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 -lemma cuts_eq: "(cut f r x = cut g r x) = (ALL y. (y,x):r --> f(y)=g(y))"
    1.38 -by (simp add: fun_eq_iff cut_def)
    1.39 -
    1.40 -lemma cut_apply: "(x,a):r ==> (cut f r a)(x) = f(x)"
    1.41 -by (simp add: cut_def)
    1.42 -
    1.43 -text{*Inductive characterization of wfrec combinator; for details see:
    1.44 -John Harrison, "Inductive definitions: automation and application"*}
    1.45 -
    1.46 -lemma wfrec_unique: "[| adm_wf R F; wf R |] ==> EX! y. wfrec_rel R F x y"
    1.47 -apply (simp add: adm_wf_def)
    1.48 -apply (erule_tac a=x in wf_induct)
    1.49 -apply (rule ex1I)
    1.50 -apply (rule_tac g = "%x. THE y. wfrec_rel R F x y" in wfrec_rel.wfrecI)
    1.51 -apply (fast dest!: theI')
    1.52 -apply (erule wfrec_rel.cases, simp)
    1.53 -apply (erule allE, erule allE, erule allE, erule mp)
    1.54 -apply (blast intro: the_equality [symmetric])
    1.55 -done
    1.56 -
    1.57 -lemma adm_lemma: "adm_wf R (%f x. F (cut f R x) x)"
    1.58 -apply (simp add: adm_wf_def)
    1.59 -apply (intro strip)
    1.60 -apply (rule cuts_eq [THEN iffD2, THEN subst], assumption)
    1.61 -apply (rule refl)
    1.62 -done
    1.63 -
    1.64 -lemma wfrec: "wf(r) ==> wfrec r H a = H (cut (wfrec r H) r a) a"
    1.65 -apply (simp add: wfrec_def)
    1.66 -apply (rule adm_lemma [THEN wfrec_unique, THEN the1_equality], assumption)
    1.67 -apply (rule wfrec_rel.wfrecI)
    1.68 -apply (intro strip)
    1.69 -apply (erule adm_lemma [THEN wfrec_unique, THEN theI'])
    1.70 -done
    1.71 -
    1.72 -
    1.73 -text{** This form avoids giant explosions in proofs.  NOTE USE OF ==*}
    1.74 -lemma def_wfrec: "[| f==wfrec r H;  wf(r) |] ==> f(a) = H (cut f r a) a"
    1.75 -apply auto
    1.76 -apply (blast intro: wfrec)
    1.77 -done
    1.78 -
    1.79 -
    1.80 -subsection {* Nitpick setup *}
    1.81 -
    1.82 -axiomatization wf_wfrec :: "('a \<times> 'a) set \<Rightarrow> (('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b"
    1.83 -
    1.84 -definition wf_wfrec' :: "('a \<times> 'a) set \<Rightarrow> (('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b" where
    1.85 -[nitpick_simp]: "wf_wfrec' R F x = F (cut (wf_wfrec R F) R x) x"
    1.86 -
    1.87 -definition wfrec' ::  "('a \<times> 'a) set \<Rightarrow> (('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b" where
    1.88 -"wfrec' R F x \<equiv> if wf R then wf_wfrec' R F x
    1.89 -                else THE y. wfrec_rel R (%f x. F (cut f R x) x) x y"
    1.90 -
    1.91 -setup {*
    1.92 -  Nitpick_HOL.register_ersatz_global
    1.93 -    [(@{const_name wf_wfrec}, @{const_name wf_wfrec'}),
    1.94 -     (@{const_name wfrec}, @{const_name wfrec'})]
    1.95 -*}
    1.96 -
    1.97 -hide_const (open) wf_wfrec wf_wfrec' wfrec'
    1.98 -hide_fact (open) wf_wfrec'_def wfrec'_def
    1.99 -
   1.100 -subsection {* Wellfoundedness of @{text same_fst} *}
   1.101 -
   1.102 -definition
   1.103 - same_fst :: "('a => bool) => ('a => ('b * 'b)set) => (('a*'b)*('a*'b))set"
   1.104 -where
   1.105 -    "same_fst P R == {((x',y'),(x,y)) . x'=x & P x & (y',y) : R x}"
   1.106 -   --{*For @{text rec_def} declarations where the first n parameters
   1.107 -       stay unchanged in the recursive call. *}
   1.108 -
   1.109 -lemma same_fstI [intro!]:
   1.110 -     "[| P x; (y',y) : R x |] ==> ((x,y'),(x,y)) : same_fst P R"
   1.111 -by (simp add: same_fst_def)
   1.112 -
   1.113 -lemma wf_same_fst:
   1.114 -  assumes prem: "(!!x. P x ==> wf(R x))"
   1.115 -  shows "wf(same_fst P R)"
   1.116 -apply (simp cong del: imp_cong add: wf_def same_fst_def)
   1.117 -apply (intro strip)
   1.118 -apply (rename_tac a b)
   1.119 -apply (case_tac "wf (R a)")
   1.120 - apply (erule_tac a = b in wf_induct, blast)
   1.121 -apply (blast intro: prem)
   1.122 -done
   1.123 -
   1.124 -end
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/HOL/Wfrec.thy	Thu Jan 16 15:47:33 2014 +0100
     2.3 @@ -0,0 +1,121 @@
     2.4 +(*  Title:      HOL/Library/Wfrec.thy
     2.5 +    Author:     Tobias Nipkow
     2.6 +    Author:     Lawrence C Paulson
     2.7 +    Author:     Konrad Slind
     2.8 +*)
     2.9 +
    2.10 +header {* Well-Founded Recursion Combinator *}
    2.11 +
    2.12 +theory Wfrec
    2.13 +imports Main
    2.14 +begin
    2.15 +
    2.16 +inductive
    2.17 +  wfrec_rel :: "('a * 'a) set => (('a => 'b) => 'a => 'b) => 'a => 'b => bool"
    2.18 +  for R :: "('a * 'a) set"
    2.19 +  and F :: "('a => 'b) => 'a => 'b"
    2.20 +where
    2.21 +  wfrecI: "ALL z. (z, x) : R --> wfrec_rel R F z (g z) ==>
    2.22 +            wfrec_rel R F x (F g x)"
    2.23 +
    2.24 +definition
    2.25 +  cut        :: "('a => 'b) => ('a * 'a)set => 'a => 'a => 'b" where
    2.26 +  "cut f r x == (%y. if (y,x):r then f y else undefined)"
    2.27 +
    2.28 +definition
    2.29 +  adm_wf :: "('a * 'a) set => (('a => 'b) => 'a => 'b) => bool" where
    2.30 +  "adm_wf R F == ALL f g x.
    2.31 +     (ALL z. (z, x) : R --> f z = g z) --> F f x = F g x"
    2.32 +
    2.33 +definition
    2.34 +  wfrec :: "('a * 'a) set => (('a => 'b) => 'a => 'b) => 'a => 'b" where
    2.35 +  "wfrec R F == %x. THE y. wfrec_rel R (%f x. F (cut f R x) x) x y"
    2.36 +
    2.37 +lemma cuts_eq: "(cut f r x = cut g r x) = (ALL y. (y,x):r --> f(y)=g(y))"
    2.38 +by (simp add: fun_eq_iff cut_def)
    2.39 +
    2.40 +lemma cut_apply: "(x,a):r ==> (cut f r a)(x) = f(x)"
    2.41 +by (simp add: cut_def)
    2.42 +
    2.43 +text{*Inductive characterization of wfrec combinator; for details see:
    2.44 +John Harrison, "Inductive definitions: automation and application"*}
    2.45 +
    2.46 +lemma wfrec_unique: "[| adm_wf R F; wf R |] ==> EX! y. wfrec_rel R F x y"
    2.47 +apply (simp add: adm_wf_def)
    2.48 +apply (erule_tac a=x in wf_induct)
    2.49 +apply (rule ex1I)
    2.50 +apply (rule_tac g = "%x. THE y. wfrec_rel R F x y" in wfrec_rel.wfrecI)
    2.51 +apply (fast dest!: theI')
    2.52 +apply (erule wfrec_rel.cases, simp)
    2.53 +apply (erule allE, erule allE, erule allE, erule mp)
    2.54 +apply (blast intro: the_equality [symmetric])
    2.55 +done
    2.56 +
    2.57 +lemma adm_lemma: "adm_wf R (%f x. F (cut f R x) x)"
    2.58 +apply (simp add: adm_wf_def)
    2.59 +apply (intro strip)
    2.60 +apply (rule cuts_eq [THEN iffD2, THEN subst], assumption)
    2.61 +apply (rule refl)
    2.62 +done
    2.63 +
    2.64 +lemma wfrec: "wf(r) ==> wfrec r H a = H (cut (wfrec r H) r a) a"
    2.65 +apply (simp add: wfrec_def)
    2.66 +apply (rule adm_lemma [THEN wfrec_unique, THEN the1_equality], assumption)
    2.67 +apply (rule wfrec_rel.wfrecI)
    2.68 +apply (intro strip)
    2.69 +apply (erule adm_lemma [THEN wfrec_unique, THEN theI'])
    2.70 +done
    2.71 +
    2.72 +
    2.73 +text{** This form avoids giant explosions in proofs.  NOTE USE OF ==*}
    2.74 +lemma def_wfrec: "[| f==wfrec r H;  wf(r) |] ==> f(a) = H (cut f r a) a"
    2.75 +apply auto
    2.76 +apply (blast intro: wfrec)
    2.77 +done
    2.78 +
    2.79 +
    2.80 +subsection {* Nitpick setup *}
    2.81 +
    2.82 +axiomatization wf_wfrec :: "('a \<times> 'a) set \<Rightarrow> (('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b"
    2.83 +
    2.84 +definition wf_wfrec' :: "('a \<times> 'a) set \<Rightarrow> (('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b" where
    2.85 +[nitpick_simp]: "wf_wfrec' R F x = F (cut (wf_wfrec R F) R x) x"
    2.86 +
    2.87 +definition wfrec' ::  "('a \<times> 'a) set \<Rightarrow> (('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b" where
    2.88 +"wfrec' R F x \<equiv> if wf R then wf_wfrec' R F x
    2.89 +                else THE y. wfrec_rel R (%f x. F (cut f R x) x) x y"
    2.90 +
    2.91 +setup {*
    2.92 +  Nitpick_HOL.register_ersatz_global
    2.93 +    [(@{const_name wf_wfrec}, @{const_name wf_wfrec'}),
    2.94 +     (@{const_name wfrec}, @{const_name wfrec'})]
    2.95 +*}
    2.96 +
    2.97 +hide_const (open) wf_wfrec wf_wfrec' wfrec'
    2.98 +hide_fact (open) wf_wfrec'_def wfrec'_def
    2.99 +
   2.100 +subsection {* Wellfoundedness of @{text same_fst} *}
   2.101 +
   2.102 +definition
   2.103 + same_fst :: "('a => bool) => ('a => ('b * 'b)set) => (('a*'b)*('a*'b))set"
   2.104 +where
   2.105 +    "same_fst P R == {((x',y'),(x,y)) . x'=x & P x & (y',y) : R x}"
   2.106 +   --{*For @{text rec_def} declarations where the first n parameters
   2.107 +       stay unchanged in the recursive call. *}
   2.108 +
   2.109 +lemma same_fstI [intro!]:
   2.110 +     "[| P x; (y',y) : R x |] ==> ((x,y'),(x,y)) : same_fst P R"
   2.111 +by (simp add: same_fst_def)
   2.112 +
   2.113 +lemma wf_same_fst:
   2.114 +  assumes prem: "(!!x. P x ==> wf(R x))"
   2.115 +  shows "wf(same_fst P R)"
   2.116 +apply (simp cong del: imp_cong add: wf_def same_fst_def)
   2.117 +apply (intro strip)
   2.118 +apply (rename_tac a b)
   2.119 +apply (case_tac "wf (R a)")
   2.120 + apply (erule_tac a = b in wf_induct, blast)
   2.121 +apply (blast intro: prem)
   2.122 +done
   2.123 +
   2.124 +end