# HG changeset patch # User wenzelm # Date 1132942856 -3600 # Node ID 836491e9b7d521340095a551b17aa619b3347615 # Parent 2124b24454dd91aef840fca256131e666c8a7f39 tuned induct proofs; diff -r 2124b24454dd -r 836491e9b7d5 src/HOL/Library/List_Prefix.thy --- a/src/HOL/Library/List_Prefix.thy Fri Nov 25 19:09:44 2005 +0100 +++ b/src/HOL/Library/List_Prefix.thy Fri Nov 25 19:20:56 2005 +0100 @@ -242,12 +242,12 @@ by(auto simp add: postfix_def) lemma postfix_is_subset_lemma: "xs = zs @ ys \ set ys \ set xs" - by (induct zs, auto) + by (induct zs) auto lemma postfix_is_subset: "xs >>= ys \ set ys \ set xs" by (unfold postfix_def, erule exE, erule postfix_is_subset_lemma) -lemma postfix_ConsD2_lemma [rule_format]: "x#xs = zs @ y#ys \ xs >>= ys" - by (induct zs, auto intro!: postfix_appendI postfix_ConsI) +lemma postfix_ConsD2_lemma: "x#xs = zs @ y#ys \ xs >>= ys" + by (induct zs) (auto intro!: postfix_appendI postfix_ConsI) lemma postfix_ConsD2: "x#xs >>= y#ys \ xs >>= ys" by (auto simp add: postfix_def dest!: postfix_ConsD2_lemma) diff -r 2124b24454dd -r 836491e9b7d5 src/HOL/Library/Multiset.thy --- a/src/HOL/Library/Multiset.thy Fri Nov 25 19:09:44 2005 +0100 +++ b/src/HOL/Library/Multiset.thy Fri Nov 25 19:20:56 2005 +0100 @@ -173,7 +173,7 @@ lemma setsum_count_Int: "finite A ==> setsum (count N) (A \ set_of N) = setsum (count N) A" - apply (erule finite_induct) + apply (induct rule: finite_induct) apply simp apply (simp add: Int_insert_left set_of_def) done @@ -285,7 +285,8 @@ lemma setsum_decr: "finite F ==> (0::nat) < f a ==> setsum (f (a := f a - 1)) F = (if a\F then setsum f F - 1 else setsum f F)" - apply (erule finite_induct, auto) + apply (induct rule: finite_induct) + apply auto apply (drule_tac a = a in mk_disjoint_insert, auto) done @@ -333,22 +334,22 @@ (!!f b. f \ multiset ==> P f ==> P (f (b := f b + 1))) ==> P f" using rep_multiset_induct_aux by blast -theorem multiset_induct [induct type: multiset]: - assumes prem1: "P {#}" - and prem2: "!!M x. P M ==> P (M + {#x#})" +theorem multiset_induct [case_names empty add, induct type: multiset]: + assumes empty: "P {#}" + and add: "!!M x. P M ==> P (M + {#x#})" shows "P M" proof - note defns = union_def single_def Mempty_def show ?thesis apply (rule Rep_multiset_inverse [THEN subst]) apply (rule Rep_multiset [THEN rep_multiset_induct]) - apply (rule prem1 [unfolded defns]) + apply (rule empty [unfolded defns]) apply (subgoal_tac "f(b := f b + 1) = (\a. f a + (if a=b then 1 else 0))") prefer 2 apply (simp add: expand_fun_eq) apply (erule ssubst) apply (erule Abs_multiset_inverse [THEN subst]) - apply (erule prem2 [unfolded defns, simplified]) + apply (erule add [unfolded defns, simplified]) done qed @@ -402,21 +403,21 @@ let ?case1 = "?case1 {(N, M). ?R N M}" assume "(N, M0 + {#a#}) \ {(N, M). ?R N M}" - hence "\a' M0' K. + then have "\a' M0' K. M0 + {#a#} = M0' + {#a'#} \ N = M0' + K \ ?r K a'" by simp - thus "?case1 \ ?case2" + then show "?case1 \ ?case2" proof (elim exE conjE) fix a' M0' K assume N: "N = M0' + K" and r: "?r K a'" assume "M0 + {#a#} = M0' + {#a'#}" - hence "M0 = M0' \ a = a' \ + then have "M0 = M0' \ a = a' \ (\K'. M0 = K' + {#a'#} \ M0' = K' + {#a#})" by (simp only: add_eq_conv_ex) - thus ?thesis + then show ?thesis proof (elim disjE conjE exE) assume "M0 = M0'" "a = a'" with N r have "?r K a \ N = M0 + K" by simp - hence ?case2 .. thus ?thesis .. + then have ?case2 .. then show ?thesis .. next fix K' assume "M0' = K' + {#a#}" @@ -424,7 +425,7 @@ assume "M0 = K' + {#a'#}" with r have "?R (K' + K) M0" by blast - with n have ?case1 by simp thus ?thesis .. + with n have ?case1 by simp then show ?thesis .. qed qed qed @@ -442,38 +443,32 @@ proof (rule accI [of "M0 + {#a#}"]) fix N assume "(N, M0 + {#a#}) \ ?R" - hence "((\M. (M, M0) \ ?R \ N = M + {#a#}) \ + then have "((\M. (M, M0) \ ?R \ N = M + {#a#}) \ (\K. (\b. b :# K --> (b, a) \ r) \ N = M0 + K))" by (rule less_add) - thus "N \ ?W" + then show "N \ ?W" proof (elim exE disjE conjE) fix M assume "(M, M0) \ ?R" and N: "N = M + {#a#}" from acc_hyp have "(M, M0) \ ?R --> M + {#a#} \ ?W" .. - hence "M + {#a#} \ ?W" .. - thus "N \ ?W" by (simp only: N) + then have "M + {#a#} \ ?W" .. + then show "N \ ?W" by (simp only: N) next fix K assume N: "N = M0 + K" assume "\b. b :# K --> (b, a) \ r" - have "?this --> M0 + K \ ?W" (is "?P K") + then have "M0 + K \ ?W" proof (induct K) - from M0 have "M0 + {#} \ ?W" by simp - thus "?P {#}" .. - - fix K x assume hyp: "?P K" - show "?P (K + {#x#})" - proof - assume a: "\b. b :# (K + {#x#}) --> (b, a) \ r" - hence "(x, a) \ r" by simp - with wf_hyp have b: "\M \ ?W. M + {#x#} \ ?W" by blast - - from a hyp have "M0 + K \ ?W" by simp - with b have "(M0 + K) + {#x#} \ ?W" .. - thus "M0 + (K + {#x#}) \ ?W" by (simp only: union_assoc) - qed + case empty + from M0 show "M0 + {#} \ ?W" by simp + next + case (add K x) + from add.prems have "(x, a) \ r" by simp + with wf_hyp have "\M \ ?W. M + {#x#} \ ?W" by blast + moreover from add have "M0 + K \ ?W" by simp + ultimately have "(M0 + K) + {#x#} \ ?W" .. + then show "M0 + (K + {#x#}) \ ?W" by (simp only: union_assoc) qed - hence "M0 + K \ ?W" .. - thus "N \ ?W" by (simp only: N) + then show "N \ ?W" by (simp only: N) qed qed } note tedious_reasoning = this @@ -496,11 +491,11 @@ show "\M \ ?W. M + {#a#} \ ?W" proof fix M assume "M \ ?W" - thus "M + {#a#} \ ?W" + then show "M + {#a#} \ ?W" by (rule acc_induct) (rule tedious_reasoning) qed qed - thus "M + {#a#} \ ?W" .. + then show "M + {#a#} \ ?W" .. qed qed @@ -616,8 +611,8 @@ *} lemma mult_irrefl_aux: - "finite A ==> (\x \ A. \y \ A. x < (y::'a::order)) --> A = {}" - apply (erule finite_induct) + "finite A ==> (\x \ A. \y \ A. x < (y::'a::order)) \ A = {}" + apply (induct rule: finite_induct) apply (auto intro: order_less_trans) done @@ -731,11 +726,11 @@ lemma union_upper1: "A <= A + (B::'a::order multiset)" proof - have "A + {#} <= A + B" by (blast intro: union_le_mono) - thus ?thesis by simp + then show ?thesis by simp qed lemma union_upper2: "B <= A + (B::'a::order multiset)" -by (subst union_commute, rule union_upper1) + by (subst union_commute) (rule union_upper1) subsection {* Link with lists *} @@ -747,21 +742,21 @@ "multiset_of (a # x) = multiset_of x + {# a #}" lemma multiset_of_zero_iff[simp]: "(multiset_of x = {#}) = (x = [])" - by (induct_tac x, auto) + by (induct x) auto lemma multiset_of_zero_iff_right[simp]: "({#} = multiset_of x) = (x = [])" - by (induct_tac x, auto) + by (induct x) auto lemma set_of_multiset_of[simp]: "set_of(multiset_of x) = set x" - by (induct_tac x, auto) + by (induct x) auto lemma mem_set_multiset_eq: "x \ set xs = (x :# multiset_of xs)" by (induct xs) auto -lemma multiset_of_append[simp]: - "multiset_of (xs @ ys) = multiset_of xs + multiset_of ys" - by (rule_tac x=ys in spec, induct_tac xs, auto simp: union_ac) - +lemma multiset_of_append [simp]: + "multiset_of (xs @ ys) = multiset_of xs + multiset_of ys" + by (induct xs fixing: ys) (auto simp: union_ac) + lemma surj_multiset_of: "surj multiset_of" apply (unfold surj_def, rule allI) apply (rule_tac M=y in multiset_induct, auto) @@ -769,11 +764,11 @@ done lemma set_count_greater_0: "set x = {a. 0 < count (multiset_of x) a}" - by (induct_tac x, auto) + by (induct x) auto lemma distinct_count_atmost_1: "distinct x = (! a. count (multiset_of x) a = (if a \ set x then 1 else 0))" - apply ( induct_tac x, simp, rule iffI, simp_all) + apply (induct x, simp, rule iffI, simp_all) apply (rule conjI) apply (simp_all add: set_of_multiset_of [THEN sym] del: set_of_multiset_of) apply (erule_tac x=a in allE, simp, clarify) @@ -798,13 +793,13 @@ apply simp done -lemma multiset_of_compl_union[simp]: - "multiset_of [x\xs. P x] + multiset_of [x\xs. \P x] = multiset_of xs" +lemma multiset_of_compl_union [simp]: + "multiset_of [x\xs. P x] + multiset_of [x\xs. \P x] = multiset_of xs" by (induct xs) (auto simp: union_ac) lemma count_filter: - "count (multiset_of xs) x = length [y \ xs. y = x]" - by (induct xs, auto) + "count (multiset_of xs) x = length [y \ xs. y = x]" + by (induct xs) auto subsection {* Pointwise ordering induced by count *}