| author | wenzelm | 
| Tue, 28 Jul 2009 14:35:27 +0200 | |
| changeset 32249 | 3e48bf962e05 | 
| parent 32244 | a99723d77ae0 | 
| child 32462 | c33faa289520 | 
| permissions | -rw-r--r-- | 
| 7701 | 1 | (* Title: HOL/Recdef.thy | 
| 10773 | 2 | Author: Konrad Slind and Markus Wenzel, TU Muenchen | 
| 12023 | 3 | *) | 
| 5123 | 4 | |
| 12023 | 5 | header {* TFL: recursive function definitions *}
 | 
| 7701 | 6 | |
| 15131 | 7 | theory Recdef | 
| 29654 
24e73987bfe2
Plain, Main form meeting points in import hierarchy
 haftmann parents: 
26748diff
changeset | 8 | imports FunDef Plain | 
| 16417 | 9 | uses | 
| 23150 | 10 |   ("Tools/TFL/casesplit.ML")
 | 
| 11 |   ("Tools/TFL/utils.ML")
 | |
| 12 |   ("Tools/TFL/usyntax.ML")
 | |
| 13 |   ("Tools/TFL/dcterm.ML")
 | |
| 14 |   ("Tools/TFL/thms.ML")
 | |
| 15 |   ("Tools/TFL/rules.ML")
 | |
| 16 |   ("Tools/TFL/thry.ML")
 | |
| 17 |   ("Tools/TFL/tfl.ML")
 | |
| 18 |   ("Tools/TFL/post.ML")
 | |
| 31723 
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
 haftmann parents: 
29654diff
changeset | 19 |   ("Tools/recdef.ML")
 | 
| 15131 | 20 | begin | 
| 10773 | 21 | |
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 22 | text{** This form avoids giant explosions in proofs.  NOTE USE OF ==*}
 | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 23 | lemma def_wfrec: "[| f==wfrec r H; wf(r) |] ==> f(a) = H (cut f r a) a" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 24 | apply auto | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 25 | apply (blast intro: wfrec) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 26 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 27 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 28 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 29 | lemma tfl_wf_induct: "ALL R. wf R --> | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 30 | (ALL P. (ALL x. (ALL y. (y,x):R --> P y) --> P x) --> (ALL x. P x))" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 31 | apply clarify | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 32 | apply (rule_tac r = R and P = P and a = x in wf_induct, assumption, blast) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 33 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 34 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 35 | lemma tfl_cut_apply: "ALL f R. (x,a):R --> (cut f R a)(x) = f(x)" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 36 | apply clarify | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 37 | apply (rule cut_apply, assumption) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 38 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 39 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 40 | lemma tfl_wfrec: | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 41 | "ALL M R f. (f=wfrec R M) --> wf R --> (ALL x. f x = M (cut f R x) x)" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 42 | apply clarify | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 43 | apply (erule wfrec) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 44 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
23742diff
changeset | 45 | |
| 10773 | 46 | lemma tfl_eq_True: "(x = True) --> x" | 
| 47 | by blast | |
| 48 | ||
| 49 | lemma tfl_rev_eq_mp: "(x = y) --> y --> x"; | |
| 50 | by blast | |
| 51 | ||
| 52 | lemma tfl_simp_thm: "(x --> y) --> (x = x') --> (x' --> y)" | |
| 53 | by blast | |
| 6438 | 54 | |
| 10773 | 55 | lemma tfl_P_imp_P_iff_True: "P ==> P = True" | 
| 56 | by blast | |
| 57 | ||
| 58 | lemma tfl_imp_trans: "(A --> B) ==> (B --> C) ==> (A --> C)" | |
| 59 | by blast | |
| 60 | ||
| 12023 | 61 | lemma tfl_disj_assoc: "(a \<or> b) \<or> c == a \<or> (b \<or> c)" | 
| 10773 | 62 | by simp | 
| 63 | ||
| 12023 | 64 | lemma tfl_disjE: "P \<or> Q ==> P --> R ==> Q --> R ==> R" | 
| 10773 | 65 | by blast | 
| 66 | ||
| 12023 | 67 | lemma tfl_exE: "\<exists>x. P x ==> \<forall>x. P x --> Q ==> Q" | 
| 10773 | 68 | by blast | 
| 69 | ||
| 23150 | 70 | use "Tools/TFL/casesplit.ML" | 
| 71 | use "Tools/TFL/utils.ML" | |
| 72 | use "Tools/TFL/usyntax.ML" | |
| 73 | use "Tools/TFL/dcterm.ML" | |
| 74 | use "Tools/TFL/thms.ML" | |
| 75 | use "Tools/TFL/rules.ML" | |
| 76 | use "Tools/TFL/thry.ML" | |
| 77 | use "Tools/TFL/tfl.ML" | |
| 78 | use "Tools/TFL/post.ML" | |
| 31723 
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
 haftmann parents: 
29654diff
changeset | 79 | use "Tools/recdef.ML" | 
| 
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
 haftmann parents: 
29654diff
changeset | 80 | setup Recdef.setup | 
| 6438 | 81 | |
| 32244 | 82 | text {*Wellfoundedness of @{text same_fst}*}
 | 
| 83 | ||
| 84 | definition | |
| 85 |  same_fst :: "('a => bool) => ('a => ('b * 'b)set) => (('a*'b)*('a*'b))set"
 | |
| 86 | where | |
| 87 |     "same_fst P R == {((x',y'),(x,y)) . x'=x & P x & (y',y) : R x}"
 | |
| 88 |    --{*For @{text rec_def} declarations where the first n parameters
 | |
| 89 | stay unchanged in the recursive call. *} | |
| 90 | ||
| 91 | lemma same_fstI [intro!]: | |
| 92 | "[| P x; (y',y) : R x |] ==> ((x,y'),(x,y)) : same_fst P R" | |
| 93 | by (simp add: same_fst_def) | |
| 94 | ||
| 95 | lemma wf_same_fst: | |
| 96 | assumes prem: "(!!x. P x ==> wf(R x))" | |
| 97 | shows "wf(same_fst P R)" | |
| 98 | apply (simp cong del: imp_cong add: wf_def same_fst_def) | |
| 99 | apply (intro strip) | |
| 100 | apply (rename_tac a b) | |
| 101 | apply (case_tac "wf (R a)") | |
| 102 | apply (erule_tac a = b in wf_induct, blast) | |
| 103 | apply (blast intro: prem) | |
| 104 | done | |
| 105 | ||
| 106 | text {*Rule setup*}
 | |
| 107 | ||
| 9855 | 108 | lemmas [recdef_simp] = | 
| 109 | inv_image_def | |
| 110 | measure_def | |
| 111 | lex_prod_def | |
| 11284 | 112 | same_fst_def | 
| 9855 | 113 | less_Suc_eq [THEN iffD2] | 
| 114 | ||
| 23150 | 115 | lemmas [recdef_cong] = | 
| 22622 
25693088396b
Moving "FunDef" up in the HOL development graph, since it is independent from "Recdef" and "Datatype" now.
 krauss parents: 
22399diff
changeset | 116 | if_cong let_cong image_cong INT_cong UN_cong bex_cong ball_cong imp_cong | 
| 9855 | 117 | |
| 118 | lemmas [recdef_wf] = | |
| 119 | wf_trancl | |
| 120 | wf_less_than | |
| 121 | wf_lex_prod | |
| 122 | wf_inv_image | |
| 123 | wf_measure | |
| 124 | wf_pred_nat | |
| 10653 | 125 | wf_same_fst | 
| 9855 | 126 | wf_empty | 
| 127 | ||
| 6438 | 128 | end |