diff -r c09598a97436 -r d8d85a8172b5 src/HOL/Wellfounded.thy --- a/src/HOL/Wellfounded.thy Sat Jul 18 21:44:18 2015 +0200 +++ b/src/HOL/Wellfounded.thy Sat Jul 18 22:58:50 2015 +0200 @@ -6,13 +6,13 @@ Author: Andrei Popescu, TU Muenchen *) -section {*Well-founded Recursion*} +section \Well-founded Recursion\ theory Wellfounded imports Transitive_Closure begin -subsection {* Basic Definitions *} +subsection \Basic Definitions\ definition wf :: "('a * 'a) set => bool" where "wf r \ (!P. (!x. (!y. (y,x):r --> P(y)) --> P(x)) --> (!x. P(x)))" @@ -29,8 +29,8 @@ lemmas wfPUNIVI = wfUNIVI [to_pred] -text{*Restriction to domain @{term A} and range @{term B}. If @{term r} is - well-founded over their intersection, then @{term "wf r"}*} +text\Restriction to domain @{term A} and range @{term B}. If @{term r} is + well-founded over their intersection, then @{term "wf r"}\ lemma wfI: "[| r \ A <*> B; !!x P. [|\x. (\y. (y,x) : r --> P y) --> P x; x : A; x : B |] ==> P x |] @@ -75,9 +75,9 @@ unfolding wf_def by (blast intro: less_induct) -subsection {* Basic Results *} +subsection \Basic Results\ -text {* Point-free characterization of well-foundedness *} +text \Point-free characterization of well-foundedness\ lemma wfE_pf: assumes wf: "wf R" @@ -105,7 +105,7 @@ with a show "P x" by blast qed -text{*Minimal-element characterization of well-foundedness*} +text\Minimal-element characterization of well-foundedness\ lemma wfE_min: assumes wf: "wf R" and Q: "x \ Q" @@ -131,7 +131,7 @@ lemmas wfP_eq_minimal = wf_eq_minimal [to_pred] -text{* Well-foundedness of transitive closure *} +text\Well-foundedness of transitive closure\ lemma wf_trancl: assumes "wf r" @@ -143,17 +143,17 @@ have "P x" proof (rule induct_step) fix y assume "(y, x) : r^+" - with `wf r` show "P y" + with \wf r\ show "P y" proof (induct x arbitrary: y) case (less x) - note hyp = `\x' y'. (x', x) : r ==> (y', x') : r^+ ==> P y'` - from `(y, x) : r^+` show "P y" + note hyp = \\x' y'. (x', x) : r ==> (y', x') : r^+ ==> P y'\ + from \(y, x) : r^+\ show "P y" proof cases case base show "P y" proof (rule induct_step) fix y' assume "(y', y) : r^+" - with `(y, x) : r` show "P y'" by (rule hyp [of y y']) + with \(y, x) : r\ show "P y'" by (rule hyp [of y y']) qed next case step @@ -172,7 +172,7 @@ apply (erule wf_trancl) done -text {* Well-foundedness of subsets *} +text \Well-foundedness of subsets\ lemma wf_subset: "[| wf(r); p<=r |] ==> wf(p)" apply (simp (no_asm_use) add: wf_eq_minimal) @@ -181,7 +181,7 @@ lemmas wfP_subset = wf_subset [to_pred] -text {* Well-foundedness of the empty relation *} +text \Well-foundedness of the empty relation\ lemma wf_empty [iff]: "wf {}" by (simp add: wf_def) @@ -203,7 +203,7 @@ apply (rule Int_lower2) done -text {* Exponentiation *} +text \Exponentiation\ lemma wf_exp: assumes "wf (R ^^ n)" @@ -211,11 +211,11 @@ proof (rule wfI_pf) fix A assume "A \ R `` A" then have "A \ (R ^^ n) `` A" by (induct n) force+ - with `wf (R ^^ n)` + with \wf (R ^^ n)\ show "A = {}" by (rule wfE_pf) qed -text {* Well-foundedness of insert *} +text \Well-foundedness of insert\ lemma wf_insert [iff]: "wf(insert (y,x) r) = (wf(r) & (x,y) ~: r^*)" apply (rule iffI) @@ -233,12 +233,12 @@ apply (rule_tac x = "{z. z:Q & (z,y) : r^*}" in allE) apply assumption apply (erule_tac V = "ALL Q. (EX x. x : Q) --> P Q" for P in thin_rl) - --{*essential for speed*} -txt{*Blast with new substOccur fails*} + --\essential for speed\ +txt\Blast with new substOccur fails\ apply (fast intro: converse_rtrancl_into_rtrancl) done -text{*Well-foundedness of image*} +text\Well-foundedness of image\ lemma wf_map_prod_image: "[| wf r; inj f |] ==> wf (map_prod f f ` r)" apply (simp only: wf_eq_minimal, clarify) @@ -248,7 +248,7 @@ done -subsection {* Well-Foundedness Results for Unions *} +subsection \Well-Foundedness Results for Unions\ lemma wf_union_compatible: assumes "wf R" "wf S" @@ -259,8 +259,8 @@ let ?Q' = "{x \ Q. \y. (y, x) \ R \ y \ Q}" assume "x \ Q" obtain a where "a \ ?Q'" - by (rule wfE_min [OF `wf R` `x \ Q`]) blast - with `wf S` + by (rule wfE_min [OF \wf R\ \x \ Q\]) blast + with \wf S\ obtain z where "z \ ?Q'" and zmin: "\y. (y, z) \ S \ y \ ?Q'" by (erule wfE_min) { fix y assume "(y, z) \ S" @@ -269,19 +269,19 @@ have "y \ Q" proof assume "y \ Q" - with `y \ ?Q'` + with \y \ ?Q'\ obtain w where "(w, y) \ R" and "w \ Q" by auto - from `(w, y) \ R` `(y, z) \ S` have "(w, z) \ R O S" by (rule relcompI) - with `R O S \ R` have "(w, z) \ R" .. - with `z \ ?Q'` have "w \ Q" by blast - with `w \ Q` show False by contradiction + from \(w, y) \ R\ \(y, z) \ S\ have "(w, z) \ R O S" by (rule relcompI) + with \R O S \ R\ have "(w, z) \ R" .. + with \z \ ?Q'\ have "w \ Q" by blast + with \w \ Q\ show False by contradiction qed } - with `z \ ?Q'` show "\z\Q. \y. (y, z) \ R \ S \ y \ Q" by blast + with \z \ ?Q'\ show "\z\Q. \y. (y, z) \ R \ S \ y \ Q" by blast qed -text {* Well-foundedness of indexed union with disjoint domains and ranges *} +text \Well-foundedness of indexed union with disjoint domains and ranges\ lemma wf_UN: "[| ALL i:I. wf(r i); ALL i:I. ALL j:I. r i ~= r j --> Domain(r i) Int Range(r j) = {} @@ -340,7 +340,7 @@ fix Q :: "'a set" and x assume "x \ Q" - with `wf ?B` + with \wf ?B\ obtain z where "z \ Q" and "\y. (y, z) \ ?B \ y \ Q" by (erule wfE_min) then have A1: "\y. (y, z) \ R O R \ y \ Q" @@ -351,7 +351,7 @@ show "\z\Q. \y. (y, z) \ ?A \ y \ Q" proof (cases "\y. (y, z) \ R \ y \ Q") case True - with `z \ Q` A3 show ?thesis by blast + with \z \ Q\ A3 show ?thesis by blast next case False then obtain z' where "z'\Q" "(z', z) \ R" by blast @@ -362,24 +362,24 @@ then show "y \ Q" proof assume "(y, z') \ R" - then have "(y, z) \ R O R" using `(z', z) \ R` .. + then have "(y, z) \ R O R" using \(z', z) \ R\ .. with A1 show "y \ Q" . next assume "(y, z') \ S" - then have "(y, z) \ S O R" using `(z', z) \ R` .. + then have "(y, z) \ S O R" using \(z', z) \ R\ .. with A2 show "y \ Q" . qed qed - with `z' \ Q` show ?thesis .. + with \z' \ Q\ show ?thesis .. qed qed qed -lemma wf_comp_self: "wf R = wf (R O R)" -- {* special case *} +lemma wf_comp_self: "wf R = wf (R O R)" -- \special case\ by (rule wf_union_merge [where S = "{}", simplified]) -subsection {* Well-Foundedness of Composition *} +subsection \Well-Foundedness of Composition\ text \Bachmair and Dershowitz 1986, Lemma 2. [Provided by Tjark Weber]\ @@ -437,7 +437,7 @@ qed -subsection {* Acyclic relations *} +subsection \Acyclic relations\ lemma wf_acyclic: "wf r ==> acyclic r" apply (simp add: acyclic_def) @@ -446,7 +446,7 @@ lemmas wfP_acyclicP = wf_acyclic [to_pred] -text{* Wellfoundedness of finite acyclic relations*} +text\Wellfoundedness of finite acyclic relations\ lemma finite_acyclic_wf [rule_format]: "finite r ==> acyclic r --> wf r" apply (erule finite_induct, blast) @@ -463,7 +463,7 @@ by (blast intro: finite_acyclic_wf wf_acyclic) -subsection {* @{typ nat} is well-founded *} +subsection \@{typ nat} is well-founded\ lemma less_nat_rel: "op < = (\m n. n = Suc m)^++" proof (rule ext, rule ext, rule iffI) @@ -517,12 +517,12 @@ by (rule Wellfounded.wellorder_class.wf) -subsection {* Accessible Part *} +subsection \Accessible Part\ -text {* +text \ Inductive definition of the accessible part @{term "acc r"} of a relation; see also @{cite "paulin-tlca"}. -*} +\ inductive_set acc :: "('a * 'a) set => 'a set" @@ -545,7 +545,7 @@ by (simp add: acc_def) -text {* Induction rules *} +text \Induction rules\ theorem accp_induct: assumes major: "accp r a" @@ -613,7 +613,7 @@ done -text {* Smaller relations have bigger accessible parts: *} +text \Smaller relations have bigger accessible parts:\ lemma accp_subset: assumes sub: "R1 \ R2" @@ -630,8 +630,8 @@ qed -text {* This is a generalized induction theorem that works on - subsets of the accessible part. *} +text \This is a generalized induction theorem that works on + subsets of the accessible part.\ lemma accp_subset_induct: assumes subset: "D \ accp R" @@ -640,9 +640,9 @@ and istep: "\x. \D x; (\z. R z x \ P z)\ \ P x" shows "P x" proof - - from subset and `D x` + from subset and \D x\ have "accp R x" .. - then show "P x" using `D x` + then show "P x" using \D x\ proof (induct x) fix x assume "D x" @@ -652,7 +652,7 @@ qed -text {* Set versions of the above theorems *} +text \Set versions of the above theorems\ lemmas acc_induct = accp_induct [to_set] @@ -677,9 +677,9 @@ lemmas acc_subset_induct = accp_subset_induct [to_set] -subsection {* Tools for building wellfounded relations *} +subsection \Tools for building wellfounded relations\ -text {* Inverse Image *} +text \Inverse Image\ lemma wf_inv_image [simp,intro!]: "wf(r) ==> wf(inv_image r (f::'a=>'b))" apply (simp (no_asm_use) add: inv_image_def wf_eq_minimal) @@ -691,7 +691,7 @@ apply blast done -text {* Measure functions into @{typ nat} *} +text \Measure functions into @{typ nat}\ definition measure :: "('a => nat) => ('a * 'a)set" where "measure = inv_image less_than" @@ -713,7 +713,7 @@ done -text{* Lexicographic combinations *} +text\Lexicographic combinations\ definition lex_prod :: "('a \'a) set \ ('b \ 'b) set \ (('a \ 'b) \ ('a \ 'b)) set" (infixr "<*lex*>" 80) where "ra <*lex*> rb = {((a, b), (a', b')). (a, a') \ ra \ a = a' \ (b, b') \ rb}" @@ -731,13 +731,13 @@ "(((a,b),(a',b')): r <*lex*> s) = ((a,a'): r \ (a = a' \ (b, b') : s))" by (auto simp:lex_prod_def) -text{* @{term "op <*lex*>"} preserves transitivity *} +text\@{term "op <*lex*>"} preserves transitivity\ lemma trans_lex_prod [intro!]: "[| trans R1; trans R2 |] ==> trans (R1 <*lex*> R2)" by (unfold trans_def lex_prod_def, blast) -text {* lexicographic combinations with measure functions *} +text \lexicographic combinations with measure functions\ definition mlex_prod :: "('a \ nat) \ ('a \ 'a) set \ ('a \ 'a) set" (infixr "<*mlex*>" 80) @@ -754,7 +754,7 @@ lemma mlex_leq: "f x \ f y \ (x, y) \ R \ (x, y) \ f <*mlex*> R" unfolding mlex_prod_def by auto -text {* proper subset relation on finite sets *} +text \proper subset relation on finite sets\ definition finite_psubset :: "('a set * 'a set) set" where "finite_psubset = {(A,B). A < B & finite B}" @@ -772,7 +772,7 @@ lemma in_finite_psubset[simp]: "(A, B) \ finite_psubset = (A < B & finite B)" unfolding finite_psubset_def by auto -text {* max- and min-extension of order to finite sets *} +text \max- and min-extension of order to finite sets\ inductive_set max_ext :: "('a \ 'a) set \ ('a set \ 'a set) set" for R :: "('a \ 'a) set" @@ -828,9 +828,9 @@ next assume "M \ {}" from asm1 finites have N2: "(?N2, M) \ max_ext r" - by (rule_tac max_extI[OF _ _ `M \ {}`]) auto + by (rule_tac max_extI[OF _ _ \M \ {}\]) auto - with `M \ ?W` show "?N2 \ ?W" by (rule acc_downward) + with \M \ ?W\ show "?N2 \ ?W" by (rule acc_downward) qed with finites have "?N1 \ ?N2 \ ?W" by (rule add_less) simp @@ -869,22 +869,22 @@ with nonempty obtain e x where "x \ Q" "e \ x" by force then have eU: "e \ \Q" by auto - with `wf r` + with \wf r\ obtain z where z: "z \ \Q" "\y. (y, z) \ r \ y \ \Q" by (erule wfE_min) from z obtain m where "m \ Q" "z \ m" by auto - from `m \ Q` + from \m \ Q\ show ?thesis proof (rule, intro bexI allI impI) fix n assume smaller: "(n, m) \ min_ext r" - with `z \ m` obtain y where y: "y \ n" "(y, z) \ r" by (auto simp: min_ext_def) + with \z \ m\ obtain y where y: "y \ n" "(y, z) \ r" by (auto simp: min_ext_def) then show "n \ Q" using z(2) by auto qed qed qed -text{* Bounded increase must terminate: *} +text\Bounded increase must terminate:\ lemma wf_bounded_measure: fixes ub :: "'a \ nat" and f :: "'a \ nat"