# HG changeset patch # User hoelzl # Date 1409832157 -7200 # Node ID db1381d811abfd89080783f122617ab9c199cf8b # Parent 285fbec02fb01ef123ae8824cf342381f179567b cleanup Wfrec; introduce dependent_wf/wellorder_choice diff -r 285fbec02fb0 -r db1381d811ab src/HOL/Library/Old_Recdef.thy --- a/src/HOL/Library/Old_Recdef.thy Thu Sep 04 11:53:39 2014 +0200 +++ b/src/HOL/Library/Old_Recdef.thy Thu Sep 04 14:02:37 2014 +0200 @@ -20,6 +20,9 @@ apply (rule_tac r = R and P = P and a = x in wf_induct, assumption, blast) done +lemma tfl_cut_def: "cut f r x \ (\y. if (y,x) \ r then f y else undefined)" + unfolding cut_def . + lemma tfl_cut_apply: "ALL f R. (x,a):R --> (cut f R a)(x) = f(x)" apply clarify apply (rule cut_apply, assumption) diff -r 285fbec02fb0 -r db1381d811ab src/HOL/MicroJava/Comp/LemmasComp.thy --- a/src/HOL/MicroJava/Comp/LemmasComp.thy Thu Sep 04 11:53:39 2014 +0200 +++ b/src/HOL/MicroJava/Comp/LemmasComp.thy Thu Sep 04 14:02:37 2014 +0200 @@ -200,7 +200,7 @@ (* case class G x = None *) apply (simp (no_asm_simp) add: class_rec_def comp_subcls1 - wfrec [where r="(subcls1 G)^-1", simplified]) + wfrec [where R="(subcls1 G)^-1", simplified]) apply (simp add: comp_class_None) (* case \ D fs ms. (class G x = Some (D, fs, ms)) *) diff -r 285fbec02fb0 -r db1381d811ab src/HOL/MicroJava/J/TypeRel.thy --- a/src/HOL/MicroJava/J/TypeRel.thy Thu Sep 04 11:53:39 2014 +0200 +++ b/src/HOL/MicroJava/J/TypeRel.thy Thu Sep 04 14:02:37 2014 +0200 @@ -66,14 +66,8 @@ assumes wf: "wf ((subcls1 G)^-1)" and cls: "class G C = Some (D, fs, ms)" shows "class_rec G C t f = f C fs ms (if C=Object then t else class_rec G D t f)" -proof - - from wf have step: "\H a. wfrec ((subcls1 G)\) H a = - H (cut (wfrec ((subcls1 G)\) H) ((subcls1 G)\) a) a" - by (rule wfrec) - have cut: "\f. C \ Object \ cut f ((subcls1 G)\) C D = f D" - by (rule cut_apply [where r="(subcls1 G)^-1", simplified, OF subcls1I, OF cls]) - from cls show ?thesis by (simp add: step cut class_rec_def) -qed + by (subst wfrec_def_adm[OF class_rec_def]) + (auto simp: assms adm_wf_def fun_eq_iff subcls1I split: option.split) definition "wf_class G = wf ((subcls1 G)^-1)" diff -r 285fbec02fb0 -r db1381d811ab src/HOL/Multivariate_Analysis/Topology_Euclidean_Space.thy --- a/src/HOL/Multivariate_Analysis/Topology_Euclidean_Space.thy Thu Sep 04 11:53:39 2014 +0200 +++ b/src/HOL/Multivariate_Analysis/Topology_Euclidean_Space.thy Thu Sep 04 14:02:37 2014 +0200 @@ -3734,64 +3734,39 @@ shows "\t. infinite t \ t \ s --> (\x \ s. x islimpt t) \ seq_compact s" by (rule countable_acc_point_imp_seq_compact) (metis islimpt_eq_acc_point) -subsubsection{* Total boundedness *} +subsubsection{* Totally bounded *} lemma cauchy_def: "Cauchy s \ (\e>0. \N. \m n. m \ N \ n \ N --> dist(s m)(s n) < e)" unfolding Cauchy_def by metis -fun helper_1 :: "('a::metric_space set) \ real \ nat \ 'a" -where - "helper_1 s e n = (SOME y::'a. y \ s \ (\m (dist (helper_1 s e m) y < e)))" -declare helper_1.simps[simp del] - lemma seq_compact_imp_totally_bounded: assumes "seq_compact s" - shows "\e>0. \k. finite k \ k \ s \ s \ (\((\x. ball x e) ` k))" -proof (rule, rule, rule ccontr) - fix e::real - assume "e > 0" - assume assm: "\ (\k. finite k \ k \ s \ s \ \((\x. ball x e) ` k))" - def x \ "helper_1 s e" - { - fix n - have "x n \ s \ (\m dist (x m) (x n) < e)" - proof (induct n rule: nat_less_induct) - fix n - def Q \ "(\y. y \ s \ (\m dist (x m) y < e))" - assume as: "\m s \ (\ma dist (x ma) (x m) < e)" - have "\ s \ (\x\x ` {0..e>0. \k. finite k \ k \ s \ s \ (\x\k. ball x e)" +proof - + { fix e::real assume "e > 0" assume *: "\k. finite k \ k \ s \ \ s \ (\x\k. ball x e)" + let ?Q = "\x n r. r \ s \ (\m < (n::nat). \ (dist (x m) r < e))" + have "\x. \n::nat. ?Q x n (x n)" + proof (rule dependent_wellorder_choice) + fix n x assume "\y. y < n \ ?Q x y (x y)" + then have "\ s \ (\x\x ` {0..s" "z \ (\x\x ` {0.. s \ (\m dist (x m) (x n) < e)" - unfolding Q_def by auto - qed - } - then have "\n::nat. x n \ s" and x:"\n. \m < n. \ (dist (x m) (x n) < e)" - by blast+ - then obtain l r where "l\s" and r:"subseq r" and "((x \ r) ---> l) sequentially" - using assms(1)[unfolded seq_compact_def, THEN spec[where x=x]] by auto - from this(3) have "Cauchy (x \ r)" - using LIMSEQ_imp_Cauchy by auto - then obtain N::nat where N:"\m n. N \ m \ N \ n \ dist ((x \ r) m) ((x \ r) n) < e" - unfolding cauchy_def using `e>0` by auto - show False - using N[THEN spec[where x=N], THEN spec[where x="N+1"]] - using r[unfolded subseq_def, THEN spec[where x=N], THEN spec[where x="N+1"]] - using x[THEN spec[where x="r (N+1)"], THEN spec[where x="r (N)"]] - by auto + show "\r. ?Q x n r" + using z by auto + qed simp + then obtain x where "\n::nat. x n \ s" and x:"\n m. m < n \ \ (dist (x m) (x n) < e)" + by blast + then obtain l r where "l \ s" and r:"subseq r" and "((x \ r) ---> l) sequentially" + using assms by (metis seq_compact_def) + from this(3) have "Cauchy (x \ r)" + using LIMSEQ_imp_Cauchy by auto + then obtain N::nat where "\m n. N \ m \ N \ n \ dist ((x \ r) m) ((x \ r) n) < e" + unfolding cauchy_def using `e > 0` by blast + then have False + using x[of "r N" "r (N+1)"] r by (auto simp: subseq_def) } + then show ?thesis + by metis qed subsubsection{* Heine-Borel theorem *} @@ -3802,7 +3777,7 @@ shows "compact s" proof - from seq_compact_imp_totally_bounded[OF `seq_compact s`] - obtain f where f: "\e>0. finite (f e) \ f e \ s \ s \ \((\x. ball x e) ` f e)" + obtain f where f: "\e>0. finite (f e) \ f e \ s \ s \ (\x\f e. ball x e)" unfolding choice_iff' .. def K \ "(\(x, r). ball x r) ` ((\e \ \ \ {0 <..}. f e) \ \)" have "countably_compact s" @@ -4137,7 +4112,7 @@ qed lemma compact_eq_totally_bounded: - "compact s \ complete s \ (\e>0. \k. finite k \ s \ (\((\x. ball x e) ` k)))" + "compact s \ complete s \ (\e>0. \k. finite k \ s \ (\x\k. ball x e))" (is "_ \ ?rhs") proof assume assms: "?rhs" diff -r 285fbec02fb0 -r db1381d811ab src/HOL/Order_Relation.thy --- a/src/HOL/Order_Relation.thy Thu Sep 04 11:53:39 2014 +0200 +++ b/src/HOL/Order_Relation.thy Thu Sep 04 14:02:37 2014 +0200 @@ -319,27 +319,6 @@ *} -subsubsection {* Well-founded recursion via genuine fixpoints *} - -lemma wfrec_fixpoint: -fixes r :: "('a * 'a) set" and - H :: "('a \ 'b) \ 'a \ 'b" -assumes WF: "wf r" and ADM: "adm_wf r H" -shows "wfrec r H = H (wfrec r H)" -proof(rule ext) - fix x - have "wfrec r H x = H (cut (wfrec r H) r x) x" - using wfrec[of r H] WF by simp - also - {have "\ y. (y,x) : r \ (cut (wfrec r H) r x) y = (wfrec r H) y" - by (auto simp add: cut_apply) - hence "H (cut (wfrec r H) r x) x = H (wfrec r H) x" - using ADM adm_wf_def[of r H] by auto - } - finally show "wfrec r H x = H (wfrec r H) x" . -qed - - subsubsection {* Characterizations of well-foundedness *} text {* A transitive relation is well-founded iff it is ``locally'' well-founded, diff -r 285fbec02fb0 -r db1381d811ab src/HOL/Probability/Infinite_Product_Measure.thy --- a/src/HOL/Probability/Infinite_Product_Measure.thy Thu Sep 04 11:53:39 2014 +0200 +++ b/src/HOL/Probability/Infinite_Product_Measure.thy Thu Sep 04 14:02:37 2014 +0200 @@ -184,70 +184,51 @@ let ?q = "\k n y. \G (?M (J k) (A n) y)" - have "\n. ?a / 2 ^ 0 \ \G (A n)" by (auto intro: INF_lower) - from Ex_w[OF A(1,2) this J(1-3), of 0] guess w0 .. note w0 = this - - let ?P = - "\k wk w. w \ space (Pi\<^sub>M (J (Suc k)) M) \ restrict w (J k) = wk \ - (\n. ?a / 2 ^ (Suc k + 1) \ ?q (Suc k) n w)" - def w \ "rec_nat w0 (\k wk. Eps (?P k wk))" - - { fix k have w: "w k \ space (Pi\<^sub>M (J k) M) \ - (\n. ?a / 2 ^ (k + 1) \ ?q k n (w k)) \ (k \ 0 \ restrict (w k) (J (k - 1)) = w (k - 1))" - proof (induct k) - case 0 with w0 show ?case - unfolding w_def nat.rec(1) by auto + let ?P = "\w k. w \ space (Pi\<^sub>M (J k) M) \ (\n. ?a / 2 ^ (Suc k) \ ?q k n w)" + have "\w. \k. ?P (w k) k \ restrict (w (Suc k)) (J k) = w k" + proof (rule dependent_nat_choice) + have "\n. ?a / 2 ^ 0 \ \G (A n)" by (auto intro: INF_lower) + from Ex_w[OF A(1,2) this J(1-3), of 0] show "\w. ?P w 0" by auto + next + fix w k assume Suc: "?P w k" + show "\w'. ?P w' (Suc k) \ restrict w' (J k) = w" + proof cases + assume [simp]: "J k = J (Suc k)" + have "?a / 2 ^ (Suc (Suc k)) \ ?a / 2 ^ (k + 1)" + using `0 < ?a` `?a \ 1` by (cases ?a) (auto simp: field_simps) + with Suc show ?thesis + by (auto intro!: exI[of _ w] simp: extensional_restrict space_PiM intro: order_trans) next - case (Suc k) - then have wk: "w k \ space (Pi\<^sub>M (J k) M)" by auto - have "\w'. ?P k (w k) w'" - proof cases - assume [simp]: "J k = J (Suc k)" - show ?thesis - proof (intro exI[of _ "w k"] conjI allI) - fix n - have "?a / 2 ^ (Suc k + 1) \ ?a / 2 ^ (k + 1)" - using `0 < ?a` `?a \ 1` by (cases ?a) (auto simp: field_simps) - also have "\ \ ?q k n (w k)" using Suc by auto - finally show "?a / 2 ^ (Suc k + 1) \ ?q (Suc k) n (w k)" by simp - next - show "w k \ space (Pi\<^sub>M (J (Suc k)) M)" - using Suc by simp - then show "restrict (w k) (J k) = w k" - by (simp add: extensional_restrict space_PiM) - qed - next - assume "J k \ J (Suc k)" - with J_mono[of k "Suc k"] have "J (Suc k) - J k \ {}" (is "?D \ {}") by auto - have "range (\n. ?M (J k) (A n) (w k)) \ ?G" - "decseq (\n. ?M (J k) (A n) (w k))" - "\n. ?a / 2 ^ (k + 1) \ \G (?M (J k) (A n) (w k))" - using `decseq A` fold(4)[OF J(1-3) A_eq(2), of "w k" k] Suc - by (auto simp: decseq_def) - from Ex_w[OF this `?D \ {}`] J[of "Suc k"] - obtain w' where w': "w' \ space (Pi\<^sub>M ?D M)" - "\n. ?a / 2 ^ (Suc k + 1) \ \G (?M ?D (?M (J k) (A n) (w k)) w')" by auto - let ?w = "merge (J k) ?D (w k, w')" - have [simp]: "\x. merge (J k) (I - J k) (w k, merge ?D (I - ?D) (w', x)) = - merge (J (Suc k)) (I - (J (Suc k))) (?w, x)" - using J(3)[of "Suc k"] J(3)[of k] J_mono[of k "Suc k"] - by (auto intro!: ext split: split_merge) - have *: "\n. ?M ?D (?M (J k) (A n) (w k)) w' = ?M (J (Suc k)) (A n) ?w" - using w'(1) J(3)[of "Suc k"] - by (auto simp: space_PiM split: split_merge intro!: extensional_merge_sub) force+ - show ?thesis - using w' J_mono[of k "Suc k"] wk unfolding * - by (intro exI[of _ ?w]) - (auto split: split_merge intro!: extensional_merge_sub ext simp: space_PiM PiE_iff) - qed - then have "?P k (w k) (w (Suc k))" - unfolding w_def nat.rec(2) unfolding w_def[symmetric] - by (rule someI_ex) - then show ?case by auto + assume "J k \ J (Suc k)" + with J_mono[of k "Suc k"] have "J (Suc k) - J k \ {}" (is "?D \ {}") by auto + have "range (\n. ?M (J k) (A n) w) \ ?G" "decseq (\n. ?M (J k) (A n) w)" + "\n. ?a / 2 ^ (k + 1) \ \G (?M (J k) (A n) w)" + using `decseq A` fold(4)[OF J(1-3) A_eq(2), of w k] Suc + by (auto simp: decseq_def) + from Ex_w[OF this `?D \ {}`] J[of "Suc k"] + obtain w' where w': "w' \ space (Pi\<^sub>M ?D M)" + "\n. ?a / 2 ^ (Suc k + 1) \ \G (?M ?D (?M (J k) (A n) w) w')" by auto + let ?w = "merge (J k) ?D (w, w')" + have [simp]: "\x. merge (J k) (I - J k) (w, merge ?D (I - ?D) (w', x)) = + merge (J (Suc k)) (I - (J (Suc k))) (?w, x)" + using J(3)[of "Suc k"] J(3)[of k] J_mono[of k "Suc k"] + by (auto intro!: ext split: split_merge) + have *: "\n. ?M ?D (?M (J k) (A n) w) w' = ?M (J (Suc k)) (A n) ?w" + using w'(1) J(3)[of "Suc k"] + by (auto simp: space_PiM split: split_merge intro!: extensional_merge_sub) force+ + show ?thesis + using Suc w' J_mono[of k "Suc k"] unfolding * + by (intro exI[of _ ?w]) + (auto split: split_merge intro!: extensional_merge_sub ext simp: space_PiM PiE_iff) qed - moreover - from w have "w k \ space (Pi\<^sub>M (J k) M)" by auto - moreover + qed + then obtain w where w: + "\k. w k \ space (Pi\<^sub>M (J k) M)" + "\k n. ?a / 2 ^ (Suc k) \ ?q k n (w k)" + "\k. restrict (w (Suc k)) (J k) = w k" + by metis + + { fix k from w have "?a / 2 ^ (k + 1) \ ?q k k (w k)" by auto then have "?M (J k) (A k) (w k) \ {}" using positive_mu_G[OF I_not_empty, unfolded positive_def] `0 < ?a` `?a \ 1` @@ -256,19 +237,15 @@ then have "merge (J k) (I - J k) (w k, x) \ A k" by auto then have "\x\A k. restrict x (J k) = w k" using `w k \ space (Pi\<^sub>M (J k) M)` - by (intro rev_bexI) (auto intro!: ext simp: extensional_def space_PiM) - ultimately have "w k \ space (Pi\<^sub>M (J k) M)" - "\x\A k. restrict x (J k) = w k" - "k \ 0 \ restrict (w k) (J (k - 1)) = w (k - 1)" - by auto } - note w = this + by (intro rev_bexI) (auto intro!: ext simp: extensional_def space_PiM) } + note w_ext = this { fix k l i assume "k \ l" "i \ J k" { fix l have "w k i = w (k + l) i" proof (induct l) case (Suc l) from `i \ J k` J_mono[of k "k + l"] have "i \ J (k + l)" by auto - with w(3)[of "k + Suc l"] + with w(3)[of "k + l"] have "w (k + l) i = w (k + Suc l) i" by (auto simp: restrict_def fun_eq_iff split: split_if_asm) with Suc show ?case by simp @@ -297,7 +274,8 @@ { fix n have "restrict w' (J n) = w n" using w(1)[of n] by (auto simp add: fun_eq_iff space_PiM) - with w[of n] obtain x where "x \ A n" "restrict x (J n) = restrict w' (J n)" by auto + with w_ext[of n] obtain x where "x \ A n" "restrict x (J n) = restrict w' (J n)" + by auto then have "w' \ A n" unfolding A_eq using w' by (auto simp: prod_emb_def space_PiM) } then have "w' \ (\i. A i)" by auto with `(\i. A i) = {}` show False by auto diff -r 285fbec02fb0 -r db1381d811ab src/HOL/Probability/Radon_Nikodym.thy --- a/src/HOL/Probability/Radon_Nikodym.thy Thu Sep 04 11:53:39 2014 +0200 +++ b/src/HOL/Probability/Radon_Nikodym.thy Thu Sep 04 14:02:37 2014 +0200 @@ -233,42 +233,34 @@ proof - interpret N: finite_measure N by fact let ?d = "\A. measure M A - measure N A" - let ?P = "\A B n. A \ sets M \ A \ B \ ?d B \ ?d A \ (\C\sets M. C \ A \ - 1 / real (Suc n) < ?d C)" - let ?r = "\S. restricted_space S" - { fix S n assume S: "S \ sets M" - then have "finite_measure (density M (indicator S))" "0 < 1 / real (Suc n)" - "finite_measure (density N (indicator S))" "sets (density N (indicator S)) = sets (density M (indicator S))" + let ?P = "\A n. if n = 0 then A = space M else (\C\sets M. C \ A \ - 1 / real (Suc n) < ?d C)" + let ?Q = "\A B. A \ B \ ?d B \ ?d A" + + have "\A. \n. (A n \ sets M \ ?P (A n) n) \ ?Q (A (Suc n)) (A n)" + proof (rule dependent_nat_choice) + show "\A. A \ sets M \ ?P A 0" + by auto + next + fix A n assume "A \ sets M \ ?P A n" + then have A: "A \ sets M" by auto + then have "finite_measure (density M (indicator A))" "0 < 1 / real (Suc (Suc n))" + "finite_measure (density N (indicator A))" "sets (density N (indicator A)) = sets (density M (indicator A))" by (auto simp: finite_measure_restricted N.finite_measure_restricted sets_eq) from finite_measure.Radon_Nikodym_aux_epsilon[OF this] guess X .. note X = this - with S have "?P (S \ X) S n" + with A have "A \ X \ sets M \ ?P (A \ X) (Suc n) \ ?Q (A \ X) A" by (simp add: measure_restricted sets_eq sets.Int) (metis inf_absorb2) - hence "\A. ?P A S n" .. } - note Ex_P = this - def A \ "rec_nat (space M) (\n A. SOME B. ?P B A n)" - have A_Suc: "\n. A (Suc n) = (SOME B. ?P B (A n) n)" by (simp add: A_def) - have A_0[simp]: "A 0 = space M" unfolding A_def by simp - { fix i have "A i \ sets M" unfolding A_def - proof (induct i) - case (Suc i) - from Ex_P[OF this, of i] show ?case unfolding nat.rec(2) - by (rule someI2_ex) simp - qed simp } - note A_in_sets = this - { fix n have "?P (A (Suc n)) (A n) n" - using Ex_P[OF A_in_sets] unfolding A_Suc - by (rule someI2_ex) simp } - note P_A = this - have "range A \ sets M" using A_in_sets by auto - have A_mono: "\i. A (Suc i) \ A i" using P_A by simp - have mono_dA: "mono (\i. ?d (A i))" using P_A by (simp add: mono_iff_le_Suc) - have epsilon: "\C i. \ C \ sets M; C \ A (Suc i) \ \ - 1 / real (Suc i) < ?d C" - using P_A by auto + then show "\B. (B \ sets M \ ?P B (Suc n)) \ ?Q B A" + by blast + qed + then obtain A where A: "\n. A n \ sets M" "\n. ?P (A n) n" "\n. ?Q (A (Suc n)) (A n)" + by metis + then have mono_dA: "mono (\i. ?d (A i))" and A_0[simp]: "A 0 = space M" + by (auto simp add: mono_iff_le_Suc) show ?thesis proof (safe intro!: bexI[of _ "\i. A i"]) - show "(\i. A i) \ sets M" using A_in_sets by auto - have A: "decseq A" using A_mono by (auto intro!: decseq_SucI) - from `range A \ sets M` - finite_Lim_measure_decseq[OF _ A] N.finite_Lim_measure_decseq[OF _ A] + show "(\i. A i) \ sets M" using `\n. A n \ sets M` by auto + have "decseq A" using A by (auto intro!: decseq_SucI) + from A(1) finite_Lim_measure_decseq[OF _ this] N.finite_Lim_measure_decseq[OF _ this] have "(\i. ?d (A i)) ----> ?d (\i. A i)" by (auto intro!: tendsto_diff simp: sets_eq) thus "?d (space M) \ ?d (\i. A i)" using mono_dA[THEN monoD, of 0 _] by (rule_tac LIMSEQ_le_const) auto @@ -280,10 +272,11 @@ hence "0 < - ?d B" by auto from ex_inverse_of_nat_Suc_less[OF this] obtain n where *: "?d B < - 1 / real (Suc n)" - by (auto simp: real_eq_of_nat inverse_eq_divide field_simps) - have "B \ A (Suc n)" using B by (auto simp del: nat.rec(2)) - from epsilon[OF B(1) this] * - show False by auto + by (auto simp: real_eq_of_nat field_simps) + also have "\ \ - 1 / real (Suc (Suc n))" + by (auto simp: field_simps) + finally show False + using * A(2)[of "Suc n"] B by (auto elim!: ballE[of _ _ B]) qed qed qed diff -r 285fbec02fb0 -r db1381d811ab src/HOL/Probability/Regularity.thy --- a/src/HOL/Probability/Regularity.thy Thu Sep 04 11:53:39 2014 +0200 +++ b/src/HOL/Probability/Regularity.thy Thu Sep 04 14:02:37 2014 +0200 @@ -163,7 +163,7 @@ by blast then obtain k where k: "\e\{0<..}. \n\{0<..}. measure M (space M) - e * 2 powr - real (n::nat) \ measure M (\i\{0..k e n}. cball (from_nat_into X i) (1 / n))" - apply atomize_elim unfolding bchoice_iff . + by metis hence k: "\e n. e > 0 \ n > 0 \ measure M (space M) - e * 2 powr - n \ measure M (\i\{0..k e n}. cball (from_nat_into X i) (1 / n))" unfolding Ball_def by blast @@ -209,8 +209,8 @@ from nat_approx_posE[OF this] guess n . note n = this let ?k = "from_nat_into X ` {0..k e (Suc n)}" have "finite ?k" by simp - moreover have "K \ \((\x. ball x e') ` ?k)" unfolding K_def B_def using n by force - ultimately show "\k. finite k \ K \ \((\x. ball x e') ` k)" by blast + moreover have "K \ (\x\?k. ball x e')" unfolding K_def B_def using n by force + ultimately show "\k. finite k \ K \ (\x\k. ball x e')" by blast qed ultimately show "?thesis e " by (auto simp: sU) diff -r 285fbec02fb0 -r db1381d811ab src/HOL/Tools/TFL/thms.ML --- a/src/HOL/Tools/TFL/thms.ML Thu Sep 04 11:53:39 2014 +0200 +++ b/src/HOL/Tools/TFL/thms.ML Thu Sep 04 14:02:37 2014 +0200 @@ -7,7 +7,7 @@ struct val WFREC_COROLLARY = @{thm tfl_wfrec}; val WF_INDUCTION_THM = @{thm tfl_wf_induct}; - val CUT_DEF = @{thm cut_def}; + val CUT_DEF = @{thm tfl_cut_def}; val eqT = @{thm tfl_eq_True}; val rev_eq_mp = @{thm tfl_rev_eq_mp}; val simp_thm = @{thm tfl_simp_thm}; diff -r 285fbec02fb0 -r db1381d811ab src/HOL/Wfrec.thy --- a/src/HOL/Wfrec.thy Thu Sep 04 11:53:39 2014 +0200 +++ b/src/HOL/Wfrec.thy Thu Sep 04 14:02:37 2014 +0200 @@ -10,86 +10,88 @@ imports Wellfounded begin -inductive - wfrec_rel :: "('a * 'a) set => (('a => 'b) => 'a => 'b) => 'a => 'b => bool" - for R :: "('a * 'a) set" - and F :: "('a => 'b) => 'a => 'b" -where - wfrecI: "ALL z. (z, x) : R --> wfrec_rel R F z (g z) ==> - wfrec_rel R F x (F g x)" +inductive wfrec_rel :: "('a \ 'a) set \ (('a \ 'b) \ ('a \ 'b)) \ 'a \ 'b \ bool" for R F where + wfrecI: "(\z. (z, x) \ R \ wfrec_rel R F z (g z)) \ wfrec_rel R F x (F g x)" -definition - cut :: "('a => 'b) => ('a * 'a)set => 'a => 'a => 'b" where - "cut f r x == (%y. if (y,x):r then f y else undefined)" +definition cut :: "('a \ 'b) \ ('a \ 'a) set \ 'a \ 'a \ 'b" where + "cut f R x = (\y. if (y, x) \ R then f y else undefined)" + +definition adm_wf :: "('a \ 'a) set \ (('a \ 'b) \ ('a \ 'b)) \ bool" where + "adm_wf R F \ (\f g x. (\z. (z, x) \ R \ f z = g z) \ F f x = F g x)" -definition - adm_wf :: "('a * 'a) set => (('a => 'b) => 'a => 'b) => bool" where - "adm_wf R F == ALL f g x. - (ALL z. (z, x) : R --> f z = g z) --> F f x = F g x" +definition wfrec :: "('a \ 'a) set \ (('a \ 'b) \ ('a \ 'b)) \ ('a \ 'b)" where + "wfrec R F = (\x. THE y. wfrec_rel R (\f x. F (cut f R x) x) x y)" -definition - wfrec :: "('a * 'a) set => (('a => 'b) => 'a => 'b) => 'a => 'b" where - "wfrec R F == %x. THE y. wfrec_rel R (%f x. F (cut f R x) x) x y" +lemma cuts_eq: "(cut f R x = cut g R x) \ (\y. (y, x) \ R \ f y = g y)" + by (simp add: fun_eq_iff cut_def) -lemma cuts_eq: "(cut f r x = cut g r x) = (ALL y. (y,x):r --> f(y)=g(y))" -by (simp add: fun_eq_iff cut_def) - -lemma cut_apply: "(x,a):r ==> (cut f r a)(x) = f(x)" -by (simp add: cut_def) +lemma cut_apply: "(x, a) \ R \ cut f R a x = f x" + by (simp add: cut_def) text{*Inductive characterization of wfrec combinator; for details see: John Harrison, "Inductive definitions: automation and application"*} -lemma wfrec_unique: "[| adm_wf R F; wf R |] ==> EX! y. wfrec_rel R F x y" -apply (simp add: adm_wf_def) -apply (erule_tac a=x in wf_induct) -apply (rule ex1I) -apply (rule_tac g = "%x. THE y. wfrec_rel R F x y" in wfrec_rel.wfrecI) -apply (fast dest!: theI') -apply (erule wfrec_rel.cases, simp) -apply (erule allE, erule allE, erule allE, erule mp) -apply (blast intro: the_equality [symmetric]) -done +lemma theI_unique: "\!x. P x \ P x \ x = The P" + by (auto intro: the_equality[symmetric] theI) -lemma adm_lemma: "adm_wf R (%f x. F (cut f R x) x)" -apply (simp add: adm_wf_def) -apply (intro strip) -apply (rule cuts_eq [THEN iffD2, THEN subst], assumption) -apply (rule refl) -done +lemma wfrec_unique: assumes "adm_wf R F" "wf R" shows "\!y. wfrec_rel R F x y" + using `wf R` +proof induct + def f \ "\y. THE z. wfrec_rel R F y z" + case (less x) + then have "\y z. (y, x) \ R \ wfrec_rel R F y z \ z = f y" + unfolding f_def by (rule theI_unique) + with `adm_wf R F` show ?case + by (subst wfrec_rel.simps) (auto simp: adm_wf_def) +qed -lemma wfrec: "wf(r) ==> wfrec r H a = H (cut (wfrec r H) r a) a" +lemma adm_lemma: "adm_wf R (\f x. F (cut f R x) x)" + by (auto simp add: adm_wf_def + intro!: arg_cong[where f="\x. F x y" for y] cuts_eq[THEN iffD2]) + +lemma wfrec: "wf R \ wfrec R F a = F (cut (wfrec R F) R a) a" apply (simp add: wfrec_def) apply (rule adm_lemma [THEN wfrec_unique, THEN the1_equality], assumption) apply (rule wfrec_rel.wfrecI) -apply (intro strip) apply (erule adm_lemma [THEN wfrec_unique, THEN theI']) done text{** This form avoids giant explosions in proofs. NOTE USE OF ==*} -lemma def_wfrec: "[| f==wfrec r H; wf(r) |] ==> f(a) = H (cut f r a) a" -apply auto -apply (blast intro: wfrec) -done +lemma def_wfrec: "f \ wfrec R F \ wf R \ f a = F (cut f R a) a" + by (auto intro: wfrec) + + +subsubsection {* Well-founded recursion via genuine fixpoints *} +lemma wfrec_fixpoint: + assumes WF: "wf R" and ADM: "adm_wf R F" + shows "wfrec R F = F (wfrec R F)" +proof (rule ext) + fix x + have "wfrec R F x = F (cut (wfrec R F) R x) x" + using wfrec[of R F] WF by simp + also + { have "\ y. (y,x) \ R \ (cut (wfrec R F) R x) y = (wfrec R F) y" + by (auto simp add: cut_apply) + hence "F (cut (wfrec R F) R x) x = F (wfrec R F) x" + using ADM adm_wf_def[of R F] by auto } + finally show "wfrec R F x = F (wfrec R F) x" . +qed subsection {* Wellfoundedness of @{text same_fst} *} -definition - same_fst :: "('a => bool) => ('a => ('b * 'b)set) => (('a*'b)*('a*'b))set" -where - "same_fst P R == {((x',y'),(x,y)) . x'=x & P x & (y',y) : R x}" - --{*For @{text rec_def} declarations where the first n parameters +definition same_fst :: "('a \ bool) \ ('a \ ('b \ 'b) set) \ (('a \ 'b) \ ('a \ 'b)) set" where + "same_fst P R = {((x', y'), (x, y)) . x' = x \ P x \ (y',y) \ R x}" + --{*For @{const wfrec} declarations where the first n parameters stay unchanged in the recursive call. *} -lemma same_fstI [intro!]: - "[| P x; (y',y) : R x |] ==> ((x,y'),(x,y)) : same_fst P R" -by (simp add: same_fst_def) +lemma same_fstI [intro!]: "P x \ (y', y) \ R x \ ((x, y'), (x, y)) \ same_fst P R" + by (simp add: same_fst_def) lemma wf_same_fst: - assumes prem: "(!!x. P x ==> wf(R x))" - shows "wf(same_fst P R)" + assumes prem: "\x. P x \ wf (R x)" + shows "wf (same_fst P R)" apply (simp cong del: imp_cong add: wf_def same_fst_def) apply (intro strip) apply (rename_tac a b) diff -r 285fbec02fb0 -r db1381d811ab src/HOL/Zorn.thy --- a/src/HOL/Zorn.thy Thu Sep 04 11:53:39 2014 +0200 +++ b/src/HOL/Zorn.thy Thu Sep 04 14:02:37 2014 +0200 @@ -720,4 +720,36 @@ with 1 show ?thesis by auto qed +(* Move this to Hilbert Choice and wfrec to Wellfounded*) + +lemma wfrec_def_adm: "f \ wfrec R F \ wf R \ adm_wf R F \ f = F f" + using wfrec_fixpoint by simp + +lemma dependent_wf_choice: + fixes P :: "('a \ 'b) \ 'a \ 'b \ bool" + assumes "wf R" and adm: "\f g x r. (\z. (z, x) \ R \ f z = g z) \ P f x r = P g x r" + assumes P: "\x f. (\y. (y, x) \ R \ P f y (f y)) \ \r. P f x r" + shows "\f. \x. P f x (f x)" +proof (intro exI allI) + fix x + def f \ "wfrec R (\f x. SOME r. P f x r)" + from `wf R` show "P f x (f x)" + proof (induct x) + fix x assume "\y. (y, x) \ R \ P f y (f y)" + show "P f x (f x)" + proof (subst (2) wfrec_def_adm[OF f_def `wf R`]) + show "adm_wf R (\f x. SOME r. P f x r)" + by (auto simp add: adm_wf_def intro!: arg_cong[where f=Eps] ext adm) + show "P f x (Eps (P f x))" + using P by (rule someI_ex) fact + qed + qed +qed + +lemma (in wellorder) dependent_wellorder_choice: + assumes "\r f g x. (\y. y < x \ f y = g y) \ P f x r = P g x r" + assumes P: "\x f. (\y. y < x \ P f y (f y)) \ \r. P f x r" + shows "\f. \x. P f x (f x)" + using wf by (rule dependent_wf_choice) (auto intro!: assms) + end