| author | haftmann | 
| Sun, 26 Apr 2009 08:34:53 +0200 | |
| changeset 30988 | b53800e3ee47 | 
| parent 30863 | 5dc392a59bb7 | 
| child 31017 | 2c227493ea56 | 
| permissions | -rw-r--r-- | 
| 12396 | 1  | 
(* Title: HOL/Finite_Set.thy  | 
2  | 
Author: Tobias Nipkow, Lawrence C Paulson and Markus Wenzel  | 
|
| 
16775
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16760 
diff
changeset
 | 
3  | 
with contributions by Jeremy Avigad  | 
| 12396 | 4  | 
*)  | 
5  | 
||
6  | 
header {* Finite sets *}
 | 
|
7  | 
||
| 15131 | 8  | 
theory Finite_Set  | 
| 29609 | 9  | 
imports Nat Product_Type Power  | 
| 15131 | 10  | 
begin  | 
| 12396 | 11  | 
|
| 15392 | 12  | 
subsection {* Definition and basic properties *}
 | 
| 12396 | 13  | 
|
| 23736 | 14  | 
inductive finite :: "'a set => bool"  | 
| 22262 | 15  | 
where  | 
16  | 
    emptyI [simp, intro!]: "finite {}"
 | 
|
17  | 
| insertI [simp, intro!]: "finite A ==> finite (insert a A)"  | 
|
| 12396 | 18  | 
|
| 13737 | 19  | 
lemma ex_new_if_finite: -- "does not depend on def of finite at all"  | 
| 14661 | 20  | 
assumes "\<not> finite (UNIV :: 'a set)" and "finite A"  | 
21  | 
shows "\<exists>a::'a. a \<notin> A"  | 
|
22  | 
proof -  | 
|
| 28823 | 23  | 
from assms have "A \<noteq> UNIV" by blast  | 
| 14661 | 24  | 
thus ?thesis by blast  | 
25  | 
qed  | 
|
| 12396 | 26  | 
|
| 22262 | 27  | 
lemma finite_induct [case_names empty insert, induct set: finite]:  | 
| 12396 | 28  | 
"finite F ==>  | 
| 
15327
 
0230a10582d3
changed the order of !!-quantifiers in finite set induction.
 
nipkow 
parents: 
15318 
diff
changeset
 | 
29  | 
    P {} ==> (!!x F. finite F ==> x \<notin> F ==> P F ==> P (insert x F)) ==> P F"
 | 
| 12396 | 30  | 
  -- {* Discharging @{text "x \<notin> F"} entails extra work. *}
 | 
31  | 
proof -  | 
|
| 13421 | 32  | 
  assume "P {}" and
 | 
| 
15327
 
0230a10582d3
changed the order of !!-quantifiers in finite set induction.
 
nipkow 
parents: 
15318 
diff
changeset
 | 
33  | 
insert: "!!x F. finite F ==> x \<notin> F ==> P F ==> P (insert x F)"  | 
| 12396 | 34  | 
assume "finite F"  | 
35  | 
thus "P F"  | 
|
36  | 
proof induct  | 
|
| 23389 | 37  | 
    show "P {}" by fact
 | 
| 
15327
 
0230a10582d3
changed the order of !!-quantifiers in finite set induction.
 
nipkow 
parents: 
15318 
diff
changeset
 | 
38  | 
fix x F assume F: "finite F" and P: "P F"  | 
| 12396 | 39  | 
show "P (insert x F)"  | 
40  | 
proof cases  | 
|
41  | 
assume "x \<in> F"  | 
|
42  | 
hence "insert x F = F" by (rule insert_absorb)  | 
|
43  | 
with P show ?thesis by (simp only:)  | 
|
44  | 
next  | 
|
45  | 
assume "x \<notin> F"  | 
|
46  | 
from F this P show ?thesis by (rule insert)  | 
|
47  | 
qed  | 
|
48  | 
qed  | 
|
49  | 
qed  | 
|
50  | 
||
| 15484 | 51  | 
lemma finite_ne_induct[case_names singleton insert, consumes 2]:  | 
52  | 
assumes fin: "finite F" shows "F \<noteq> {} \<Longrightarrow>
 | 
|
53  | 
 \<lbrakk> \<And>x. P{x};
 | 
|
54  | 
   \<And>x F. \<lbrakk> finite F; F \<noteq> {}; x \<notin> F; P F \<rbrakk> \<Longrightarrow> P (insert x F) \<rbrakk>
 | 
|
55  | 
\<Longrightarrow> P F"  | 
|
56  | 
using fin  | 
|
57  | 
proof induct  | 
|
58  | 
case empty thus ?case by simp  | 
|
59  | 
next  | 
|
60  | 
case (insert x F)  | 
|
61  | 
show ?case  | 
|
62  | 
proof cases  | 
|
| 23389 | 63  | 
    assume "F = {}"
 | 
64  | 
    thus ?thesis using `P {x}` by simp
 | 
|
| 15484 | 65  | 
next  | 
| 23389 | 66  | 
    assume "F \<noteq> {}"
 | 
67  | 
thus ?thesis using insert by blast  | 
|
| 15484 | 68  | 
qed  | 
69  | 
qed  | 
|
70  | 
||
| 12396 | 71  | 
lemma finite_subset_induct [consumes 2, case_names empty insert]:  | 
| 23389 | 72  | 
assumes "finite F" and "F \<subseteq> A"  | 
73  | 
    and empty: "P {}"
 | 
|
74  | 
and insert: "!!a F. finite F ==> a \<in> A ==> a \<notin> F ==> P F ==> P (insert a F)"  | 
|
75  | 
shows "P F"  | 
|
| 12396 | 76  | 
proof -  | 
| 23389 | 77  | 
from `finite F` and `F \<subseteq> A`  | 
78  | 
show ?thesis  | 
|
| 12396 | 79  | 
proof induct  | 
| 23389 | 80  | 
    show "P {}" by fact
 | 
81  | 
next  | 
|
82  | 
fix x F  | 
|
83  | 
assume "finite F" and "x \<notin> F" and  | 
|
84  | 
P: "F \<subseteq> A ==> P F" and i: "insert x F \<subseteq> A"  | 
|
| 12396 | 85  | 
show "P (insert x F)"  | 
86  | 
proof (rule insert)  | 
|
87  | 
from i show "x \<in> A" by blast  | 
|
88  | 
from i have "F \<subseteq> A" by blast  | 
|
89  | 
with P show "P F" .  | 
|
| 23389 | 90  | 
show "finite F" by fact  | 
91  | 
show "x \<notin> F" by fact  | 
|
| 12396 | 92  | 
qed  | 
93  | 
qed  | 
|
94  | 
qed  | 
|
95  | 
||
| 29923 | 96  | 
text{* A finite choice principle. Does not need the SOME choice operator. *}
 | 
97  | 
lemma finite_set_choice:  | 
|
98  | 
"finite A \<Longrightarrow> ALL x:A. (EX y. P x y) \<Longrightarrow> EX f. ALL x:A. P x (f x)"  | 
|
99  | 
proof (induct set: finite)  | 
|
100  | 
case empty thus ?case by simp  | 
|
101  | 
next  | 
|
102  | 
case (insert a A)  | 
|
103  | 
then obtain f b where f: "ALL x:A. P x (f x)" and ab: "P a b" by auto  | 
|
104  | 
show ?case (is "EX f. ?P f")  | 
|
105  | 
proof  | 
|
106  | 
show "?P(%x. if x = a then b else f x)" using f ab by auto  | 
|
107  | 
qed  | 
|
108  | 
qed  | 
|
109  | 
||
| 23878 | 110  | 
|
| 15392 | 111  | 
text{* Finite sets are the images of initial segments of natural numbers: *}
 | 
112  | 
||
| 15510 | 113  | 
lemma finite_imp_nat_seg_image_inj_on:  | 
114  | 
assumes fin: "finite A"  | 
|
115  | 
  shows "\<exists> (n::nat) f. A = f ` {i. i<n} & inj_on f {i. i<n}"
 | 
|
| 15392 | 116  | 
using fin  | 
117  | 
proof induct  | 
|
118  | 
case empty  | 
|
| 15510 | 119  | 
show ?case  | 
120  | 
  proof show "\<exists>f. {} = f ` {i::nat. i < 0} & inj_on f {i. i<0}" by simp 
 | 
|
121  | 
qed  | 
|
| 15392 | 122  | 
next  | 
123  | 
case (insert a A)  | 
|
| 23389 | 124  | 
have notinA: "a \<notin> A" by fact  | 
| 15510 | 125  | 
from insert.hyps obtain n f  | 
126  | 
    where "A = f ` {i::nat. i < n}" "inj_on f {i. i < n}" by blast
 | 
|
127  | 
  hence "insert a A = f(n:=a) ` {i. i < Suc n}"
 | 
|
128  | 
        "inj_on (f(n:=a)) {i. i < Suc n}" using notinA
 | 
|
129  | 
by (auto simp add: image_def Ball_def inj_on_def less_Suc_eq)  | 
|
| 15392 | 130  | 
thus ?case by blast  | 
131  | 
qed  | 
|
132  | 
||
133  | 
lemma nat_seg_image_imp_finite:  | 
|
134  | 
  "!!f A. A = f ` {i::nat. i<n} \<Longrightarrow> finite A"
 | 
|
135  | 
proof (induct n)  | 
|
136  | 
case 0 thus ?case by simp  | 
|
137  | 
next  | 
|
138  | 
case (Suc n)  | 
|
139  | 
  let ?B = "f ` {i. i < n}"
 | 
|
140  | 
have finB: "finite ?B" by(rule Suc.hyps[OF refl])  | 
|
141  | 
show ?case  | 
|
142  | 
proof cases  | 
|
143  | 
assume "\<exists>k<n. f n = f k"  | 
|
144  | 
hence "A = ?B" using Suc.prems by(auto simp:less_Suc_eq)  | 
|
145  | 
thus ?thesis using finB by simp  | 
|
146  | 
next  | 
|
147  | 
assume "\<not>(\<exists> k<n. f n = f k)"  | 
|
148  | 
hence "A = insert (f n) ?B" using Suc.prems by(auto simp:less_Suc_eq)  | 
|
149  | 
thus ?thesis using finB by simp  | 
|
150  | 
qed  | 
|
151  | 
qed  | 
|
152  | 
||
153  | 
lemma finite_conv_nat_seg_image:  | 
|
154  | 
  "finite A = (\<exists> (n::nat) f. A = f ` {i::nat. i<n})"
 | 
|
| 15510 | 155  | 
by(blast intro: nat_seg_image_imp_finite dest: finite_imp_nat_seg_image_inj_on)  | 
| 15392 | 156  | 
|
| 29920 | 157  | 
lemma finite_Collect_less_nat[iff]: "finite{n::nat. n<k}"
 | 
158  | 
by(fastsimp simp: finite_conv_nat_seg_image)  | 
|
159  | 
||
| 26441 | 160  | 
|
| 15392 | 161  | 
subsubsection{* Finiteness and set theoretic constructions *}
 | 
162  | 
||
| 12396 | 163  | 
lemma finite_UnI: "finite F ==> finite G ==> finite (F Un G)"  | 
| 29901 | 164  | 
by (induct set: finite) simp_all  | 
| 12396 | 165  | 
|
166  | 
lemma finite_subset: "A \<subseteq> B ==> finite B ==> finite A"  | 
|
167  | 
  -- {* Every subset of a finite set is finite. *}
 | 
|
168  | 
proof -  | 
|
169  | 
assume "finite B"  | 
|
170  | 
thus "!!A. A \<subseteq> B ==> finite A"  | 
|
171  | 
proof induct  | 
|
172  | 
case empty  | 
|
173  | 
thus ?case by simp  | 
|
174  | 
next  | 
|
| 
15327
 
0230a10582d3
changed the order of !!-quantifiers in finite set induction.
 
nipkow 
parents: 
15318 
diff
changeset
 | 
175  | 
case (insert x F A)  | 
| 23389 | 176  | 
    have A: "A \<subseteq> insert x F" and r: "A - {x} \<subseteq> F ==> finite (A - {x})" by fact+
 | 
| 12396 | 177  | 
show "finite A"  | 
178  | 
proof cases  | 
|
179  | 
assume x: "x \<in> A"  | 
|
180  | 
      with A have "A - {x} \<subseteq> F" by (simp add: subset_insert_iff)
 | 
|
181  | 
      with r have "finite (A - {x})" .
 | 
|
182  | 
      hence "finite (insert x (A - {x}))" ..
 | 
|
| 23389 | 183  | 
      also have "insert x (A - {x}) = A" using x by (rule insert_Diff)
 | 
| 12396 | 184  | 
finally show ?thesis .  | 
185  | 
next  | 
|
| 23389 | 186  | 
show "A \<subseteq> F ==> ?thesis" by fact  | 
| 12396 | 187  | 
assume "x \<notin> A"  | 
188  | 
with A show "A \<subseteq> F" by (simp add: subset_insert_iff)  | 
|
189  | 
qed  | 
|
190  | 
qed  | 
|
191  | 
qed  | 
|
192  | 
||
193  | 
lemma finite_Un [iff]: "finite (F Un G) = (finite F & finite G)"  | 
|
| 29901 | 194  | 
by (blast intro: finite_subset [of _ "X Un Y", standard] finite_UnI)  | 
195  | 
||
| 29916 | 196  | 
lemma finite_Collect_disjI[simp]:  | 
| 29901 | 197  | 
  "finite{x. P x | Q x} = (finite{x. P x} & finite{x. Q x})"
 | 
198  | 
by(simp add:Collect_disj_eq)  | 
|
| 12396 | 199  | 
|
200  | 
lemma finite_Int [simp, intro]: "finite F | finite G ==> finite (F Int G)"  | 
|
201  | 
  -- {* The converse obviously fails. *}
 | 
|
| 29901 | 202  | 
by (blast intro: finite_subset)  | 
203  | 
||
| 29916 | 204  | 
lemma finite_Collect_conjI [simp, intro]:  | 
| 29901 | 205  | 
  "finite{x. P x} | finite{x. Q x} ==> finite{x. P x & Q x}"
 | 
206  | 
  -- {* The converse obviously fails. *}
 | 
|
207  | 
by(simp add:Collect_conj_eq)  | 
|
| 12396 | 208  | 
|
| 29920 | 209  | 
lemma finite_Collect_le_nat[iff]: "finite{n::nat. n<=k}"
 | 
210  | 
by(simp add: le_eq_less_or_eq)  | 
|
211  | 
||
| 12396 | 212  | 
lemma finite_insert [simp]: "finite (insert a A) = finite A"  | 
213  | 
apply (subst insert_is_Un)  | 
|
| 14208 | 214  | 
apply (simp only: finite_Un, blast)  | 
| 12396 | 215  | 
done  | 
216  | 
||
| 15281 | 217  | 
lemma finite_Union[simp, intro]:  | 
218  | 
"\<lbrakk> finite A; !!M. M \<in> A \<Longrightarrow> finite M \<rbrakk> \<Longrightarrow> finite(\<Union>A)"  | 
|
219  | 
by (induct rule:finite_induct) simp_all  | 
|
220  | 
||
| 12396 | 221  | 
lemma finite_empty_induct:  | 
| 23389 | 222  | 
assumes "finite A"  | 
223  | 
and "P A"  | 
|
224  | 
    and "!!a A. finite A ==> a:A ==> P A ==> P (A - {a})"
 | 
|
225  | 
  shows "P {}"
 | 
|
| 12396 | 226  | 
proof -  | 
227  | 
have "P (A - A)"  | 
|
228  | 
proof -  | 
|
| 23389 | 229  | 
    {
 | 
230  | 
fix c b :: "'a set"  | 
|
231  | 
assume c: "finite c" and b: "finite b"  | 
|
232  | 
	and P1: "P b" and P2: "!!x y. finite y ==> x \<in> y ==> P y ==> P (y - {x})"
 | 
|
233  | 
have "c \<subseteq> b ==> P (b - c)"  | 
|
234  | 
using c  | 
|
235  | 
proof induct  | 
|
236  | 
case empty  | 
|
237  | 
from P1 show ?case by simp  | 
|
238  | 
next  | 
|
239  | 
case (insert x F)  | 
|
240  | 
	have "P (b - F - {x})"
 | 
|
241  | 
proof (rule P2)  | 
|
242  | 
from _ b show "finite (b - F)" by (rule finite_subset) blast  | 
|
243  | 
from insert show "x \<in> b - F" by simp  | 
|
244  | 
from insert show "P (b - F)" by simp  | 
|
245  | 
qed  | 
|
246  | 
	also have "b - F - {x} = b - insert x F" by (rule Diff_insert [symmetric])
 | 
|
247  | 
finally show ?case .  | 
|
| 12396 | 248  | 
qed  | 
| 23389 | 249  | 
}  | 
250  | 
then show ?thesis by this (simp_all add: assms)  | 
|
| 12396 | 251  | 
qed  | 
| 23389 | 252  | 
then show ?thesis by simp  | 
| 12396 | 253  | 
qed  | 
254  | 
||
| 29901 | 255  | 
lemma finite_Diff [simp]: "finite A ==> finite (A - B)"  | 
256  | 
by (rule Diff_subset [THEN finite_subset])  | 
|
257  | 
||
258  | 
lemma finite_Diff2 [simp]:  | 
|
259  | 
assumes "finite B" shows "finite (A - B) = finite A"  | 
|
260  | 
proof -  | 
|
261  | 
have "finite A \<longleftrightarrow> finite((A-B) Un (A Int B))" by(simp add: Un_Diff_Int)  | 
|
262  | 
also have "\<dots> \<longleftrightarrow> finite(A-B)" using `finite B` by(simp)  | 
|
263  | 
finally show ?thesis ..  | 
|
264  | 
qed  | 
|
265  | 
||
266  | 
lemma finite_compl[simp]:  | 
|
267  | 
"finite(A::'a set) \<Longrightarrow> finite(-A) = finite(UNIV::'a set)"  | 
|
268  | 
by(simp add:Compl_eq_Diff_UNIV)  | 
|
| 12396 | 269  | 
|
| 29916 | 270  | 
lemma finite_Collect_not[simp]:  | 
| 29903 | 271  | 
  "finite{x::'a. P x} \<Longrightarrow> finite{x. ~P x} = finite(UNIV::'a set)"
 | 
272  | 
by(simp add:Collect_neg_eq)  | 
|
273  | 
||
| 12396 | 274  | 
lemma finite_Diff_insert [iff]: "finite (A - insert a B) = finite (A - B)"  | 
275  | 
apply (subst Diff_insert)  | 
|
276  | 
apply (case_tac "a : A - B")  | 
|
277  | 
apply (rule finite_insert [symmetric, THEN trans])  | 
|
| 14208 | 278  | 
apply (subst insert_Diff, simp_all)  | 
| 12396 | 279  | 
done  | 
280  | 
||
281  | 
||
| 15392 | 282  | 
text {* Image and Inverse Image over Finite Sets *}
 | 
| 13825 | 283  | 
|
284  | 
lemma finite_imageI[simp]: "finite F ==> finite (h ` F)"  | 
|
285  | 
  -- {* The image of a finite set is finite. *}
 | 
|
| 22262 | 286  | 
by (induct set: finite) simp_all  | 
| 13825 | 287  | 
|
| 
14430
 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 
paulson 
parents: 
14331 
diff
changeset
 | 
288  | 
lemma finite_surj: "finite A ==> B <= f ` A ==> finite B"  | 
| 
 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 
paulson 
parents: 
14331 
diff
changeset
 | 
289  | 
apply (frule finite_imageI)  | 
| 
 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 
paulson 
parents: 
14331 
diff
changeset
 | 
290  | 
apply (erule finite_subset, assumption)  | 
| 
 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 
paulson 
parents: 
14331 
diff
changeset
 | 
291  | 
done  | 
| 
 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 
paulson 
parents: 
14331 
diff
changeset
 | 
292  | 
|
| 13825 | 293  | 
lemma finite_range_imageI:  | 
294  | 
"finite (range g) ==> finite (range (%x. f (g x)))"  | 
|
| 27418 | 295  | 
apply (drule finite_imageI, simp add: range_composition)  | 
| 13825 | 296  | 
done  | 
297  | 
||
| 12396 | 298  | 
lemma finite_imageD: "finite (f`A) ==> inj_on f A ==> finite A"  | 
299  | 
proof -  | 
|
300  | 
  have aux: "!!A. finite (A - {}) = finite A" by simp
 | 
|
301  | 
fix B :: "'a set"  | 
|
302  | 
assume "finite B"  | 
|
303  | 
thus "!!A. f`A = B ==> inj_on f A ==> finite A"  | 
|
304  | 
apply induct  | 
|
305  | 
apply simp  | 
|
306  | 
    apply (subgoal_tac "EX y:A. f y = x & F = f ` (A - {y})")
 | 
|
307  | 
apply clarify  | 
|
308  | 
apply (simp (no_asm_use) add: inj_on_def)  | 
|
| 14208 | 309  | 
apply (blast dest!: aux [THEN iffD1], atomize)  | 
| 12396 | 310  | 
apply (erule_tac V = "ALL A. ?PP (A)" in thin_rl)  | 
| 14208 | 311  | 
apply (frule subsetD [OF equalityD2 insertI1], clarify)  | 
| 12396 | 312  | 
apply (rule_tac x = xa in bexI)  | 
313  | 
apply (simp_all add: inj_on_image_set_diff)  | 
|
314  | 
done  | 
|
315  | 
qed (rule refl)  | 
|
316  | 
||
317  | 
||
| 13825 | 318  | 
lemma inj_vimage_singleton: "inj f ==> f-`{a} \<subseteq> {THE x. f x = a}"
 | 
319  | 
  -- {* The inverse image of a singleton under an injective function
 | 
|
320  | 
is included in a singleton. *}  | 
|
| 
14430
 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 
paulson 
parents: 
14331 
diff
changeset
 | 
321  | 
apply (auto simp add: inj_on_def)  | 
| 
 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 
paulson 
parents: 
14331 
diff
changeset
 | 
322  | 
apply (blast intro: the_equality [symmetric])  | 
| 13825 | 323  | 
done  | 
324  | 
||
325  | 
lemma finite_vimageI: "[|finite F; inj h|] ==> finite (h -` F)"  | 
|
326  | 
  -- {* The inverse image of a finite set under an injective function
 | 
|
327  | 
is finite. *}  | 
|
| 22262 | 328  | 
apply (induct set: finite)  | 
| 21575 | 329  | 
apply simp_all  | 
| 
14430
 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 
paulson 
parents: 
14331 
diff
changeset
 | 
330  | 
apply (subst vimage_insert)  | 
| 
 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 
paulson 
parents: 
14331 
diff
changeset
 | 
331  | 
apply (simp add: finite_Un finite_subset [OF inj_vimage_singleton])  | 
| 13825 | 332  | 
done  | 
333  | 
||
334  | 
||
| 15392 | 335  | 
text {* The finite UNION of finite sets *}
 | 
| 12396 | 336  | 
|
337  | 
lemma finite_UN_I: "finite A ==> (!!a. a:A ==> finite (B a)) ==> finite (UN a:A. B a)"  | 
|
| 22262 | 338  | 
by (induct set: finite) simp_all  | 
| 12396 | 339  | 
|
340  | 
text {*
 | 
|
341  | 
Strengthen RHS to  | 
|
| 
14430
 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 
paulson 
parents: 
14331 
diff
changeset
 | 
342  | 
  @{prop "((ALL x:A. finite (B x)) & finite {x. x:A & B x \<noteq> {}})"}?
 | 
| 12396 | 343  | 
|
344  | 
We'd need to prove  | 
|
| 
14430
 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 
paulson 
parents: 
14331 
diff
changeset
 | 
345  | 
  @{prop "finite C ==> ALL A B. (UNION A B) <= C --> finite {x. x:A & B x \<noteq> {}}"}
 | 
| 12396 | 346  | 
by induction. *}  | 
347  | 
||
| 29918 | 348  | 
lemma finite_UN [simp]:  | 
349  | 
"finite A ==> finite (UNION A B) = (ALL x:A. finite (B x))"  | 
|
350  | 
by (blast intro: finite_UN_I finite_subset)  | 
|
| 12396 | 351  | 
|
| 29920 | 352  | 
lemma finite_Collect_bex[simp]: "finite A \<Longrightarrow>  | 
353  | 
  finite{x. EX y:A. Q x y} = (ALL y:A. finite{x. Q x y})"
 | 
|
354  | 
apply(subgoal_tac "{x. EX y:A. Q x y} = UNION A (%y. {x. Q x y})")
 | 
|
355  | 
apply auto  | 
|
356  | 
done  | 
|
357  | 
||
358  | 
lemma finite_Collect_bounded_ex[simp]: "finite{y. P y} \<Longrightarrow>
 | 
|
359  | 
  finite{x. EX y. P y & Q x y} = (ALL y. P y \<longrightarrow> finite{x. Q x y})"
 | 
|
360  | 
apply(subgoal_tac "{x. EX y. P y & Q x y} = UNION {y. P y} (%y. {x. Q x y})")
 | 
|
361  | 
apply auto  | 
|
362  | 
done  | 
|
363  | 
||
364  | 
||
| 17022 | 365  | 
lemma finite_Plus: "[| finite A; finite B |] ==> finite (A <+> B)"  | 
366  | 
by (simp add: Plus_def)  | 
|
367  | 
||
| 15392 | 368  | 
text {* Sigma of finite sets *}
 | 
| 12396 | 369  | 
|
370  | 
lemma finite_SigmaI [simp]:  | 
|
371  | 
"finite A ==> (!!a. a:A ==> finite (B a)) ==> finite (SIGMA a:A. B a)"  | 
|
372  | 
by (unfold Sigma_def) (blast intro!: finite_UN_I)  | 
|
373  | 
||
| 15402 | 374  | 
lemma finite_cartesian_product: "[| finite A; finite B |] ==>  | 
375  | 
finite (A <*> B)"  | 
|
376  | 
by (rule finite_SigmaI)  | 
|
377  | 
||
| 12396 | 378  | 
lemma finite_Prod_UNIV:  | 
379  | 
    "finite (UNIV::'a set) ==> finite (UNIV::'b set) ==> finite (UNIV::('a * 'b) set)"
 | 
|
380  | 
  apply (subgoal_tac "(UNIV:: ('a * 'b) set) = Sigma UNIV (%x. UNIV)")
 | 
|
381  | 
apply (erule ssubst)  | 
|
| 14208 | 382  | 
apply (erule finite_SigmaI, auto)  | 
| 12396 | 383  | 
done  | 
384  | 
||
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
385  | 
lemma finite_cartesian_productD1:  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
386  | 
     "[| finite (A <*> B); B \<noteq> {} |] ==> finite A"
 | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
387  | 
apply (auto simp add: finite_conv_nat_seg_image)  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
388  | 
apply (drule_tac x=n in spec)  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
389  | 
apply (drule_tac x="fst o f" in spec)  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
390  | 
apply (auto simp add: o_def)  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
391  | 
prefer 2 apply (force dest!: equalityD2)  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
392  | 
apply (drule equalityD1)  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
393  | 
apply (rename_tac y x)  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
394  | 
apply (subgoal_tac "\<exists>k. k<n & f k = (x,y)")  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
395  | 
prefer 2 apply force  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
396  | 
apply clarify  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
397  | 
apply (rule_tac x=k in image_eqI, auto)  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
398  | 
done  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
399  | 
|
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
400  | 
lemma finite_cartesian_productD2:  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
401  | 
     "[| finite (A <*> B); A \<noteq> {} |] ==> finite B"
 | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
402  | 
apply (auto simp add: finite_conv_nat_seg_image)  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
403  | 
apply (drule_tac x=n in spec)  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
404  | 
apply (drule_tac x="snd o f" in spec)  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
405  | 
apply (auto simp add: o_def)  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
406  | 
prefer 2 apply (force dest!: equalityD2)  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
407  | 
apply (drule equalityD1)  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
408  | 
apply (rename_tac x y)  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
409  | 
apply (subgoal_tac "\<exists>k. k<n & f k = (x,y)")  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
410  | 
prefer 2 apply force  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
411  | 
apply clarify  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
412  | 
apply (rule_tac x=k in image_eqI, auto)  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
413  | 
done  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
414  | 
|
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
415  | 
|
| 15392 | 416  | 
text {* The powerset of a finite set *}
 | 
| 12396 | 417  | 
|
418  | 
lemma finite_Pow_iff [iff]: "finite (Pow A) = finite A"  | 
|
419  | 
proof  | 
|
420  | 
assume "finite (Pow A)"  | 
|
421  | 
  with _ have "finite ((%x. {x}) ` A)" by (rule finite_subset) blast
 | 
|
422  | 
thus "finite A" by (rule finite_imageD [unfolded inj_on_def]) simp  | 
|
423  | 
next  | 
|
424  | 
assume "finite A"  | 
|
425  | 
thus "finite (Pow A)"  | 
|
426  | 
by induct (simp_all add: finite_UnI finite_imageI Pow_insert)  | 
|
427  | 
qed  | 
|
428  | 
||
| 29916 | 429  | 
lemma finite_Collect_subsets[simp,intro]: "finite A \<Longrightarrow> finite{B. B \<subseteq> A}"
 | 
430  | 
by(simp add: Pow_def[symmetric])  | 
|
| 15392 | 431  | 
|
| 29918 | 432  | 
|
| 15392 | 433  | 
lemma finite_UnionD: "finite(\<Union>A) \<Longrightarrow> finite A"  | 
434  | 
by(blast intro: finite_subset[OF subset_Pow_Union])  | 
|
435  | 
||
436  | 
||
| 26441 | 437  | 
subsection {* Class @{text finite}  *}
 | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
438  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
439  | 
setup {* Sign.add_path "finite" *} -- {*FIXME: name tweaking*}
 | 
| 29797 | 440  | 
class finite =  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
441  | 
assumes finite_UNIV: "finite (UNIV \<Colon> 'a set)"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
442  | 
setup {* Sign.parent_path *}
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
443  | 
hide const finite  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
444  | 
|
| 27430 | 445  | 
context finite  | 
446  | 
begin  | 
|
447  | 
||
448  | 
lemma finite [simp]: "finite (A \<Colon> 'a set)"  | 
|
| 26441 | 449  | 
by (rule subset_UNIV finite_UNIV finite_subset)+  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
450  | 
|
| 27430 | 451  | 
end  | 
452  | 
||
| 26146 | 453  | 
lemma UNIV_unit [noatp]:  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
454  | 
  "UNIV = {()}" by auto
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
455  | 
|
| 26146 | 456  | 
instance unit :: finite  | 
457  | 
by default (simp add: UNIV_unit)  | 
|
458  | 
||
459  | 
lemma UNIV_bool [noatp]:  | 
|
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
460  | 
  "UNIV = {False, True}" by auto
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
461  | 
|
| 26146 | 462  | 
instance bool :: finite  | 
463  | 
by default (simp add: UNIV_bool)  | 
|
464  | 
||
465  | 
instance * :: (finite, finite) finite  | 
|
466  | 
by default (simp only: UNIV_Times_UNIV [symmetric] finite_cartesian_product finite)  | 
|
467  | 
||
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
468  | 
lemma inj_graph: "inj (%f. {(x, y). y = f x})"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
469  | 
by (rule inj_onI, auto simp add: expand_set_eq expand_fun_eq)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
470  | 
|
| 26146 | 471  | 
instance "fun" :: (finite, finite) finite  | 
472  | 
proof  | 
|
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
473  | 
  show "finite (UNIV :: ('a => 'b) set)"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
474  | 
proof (rule finite_imageD)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
475  | 
    let ?graph = "%f::'a => 'b. {(x, y). y = f x}"
 | 
| 26792 | 476  | 
have "range ?graph \<subseteq> Pow UNIV" by simp  | 
477  | 
    moreover have "finite (Pow (UNIV :: ('a * 'b) set))"
 | 
|
478  | 
by (simp only: finite_Pow_iff finite)  | 
|
479  | 
ultimately show "finite (range ?graph)"  | 
|
480  | 
by (rule finite_subset)  | 
|
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
481  | 
show "inj ?graph" by (rule inj_graph)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
482  | 
qed  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
483  | 
qed  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
484  | 
|
| 27981 | 485  | 
instance "+" :: (finite, finite) finite  | 
486  | 
by default (simp only: UNIV_Plus_UNIV [symmetric] finite_Plus finite)  | 
|
487  | 
||
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
488  | 
|
| 15392 | 489  | 
subsection {* A fold functional for finite sets *}
 | 
490  | 
||
491  | 
text {* The intended behaviour is
 | 
|
| 29966 | 492  | 
@{text "fold f z {x\<^isub>1, ..., x\<^isub>n} = f x\<^isub>1 (\<dots> (f x\<^isub>n z)\<dots>)"}
 | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
493  | 
if @{text f} is ``left-commutative'':
 | 
| 15392 | 494  | 
*}  | 
495  | 
||
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
496  | 
locale fun_left_comm =  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
497  | 
fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
498  | 
assumes fun_left_comm: "f x (f y z) = f y (f x z)"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
499  | 
begin  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
500  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
501  | 
text{* On a functional level it looks much nicer: *}
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
502  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
503  | 
lemma fun_comp_comm: "f x \<circ> f y = f y \<circ> f x"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
504  | 
by (simp add: fun_left_comm expand_fun_eq)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
505  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
506  | 
end  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
507  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
508  | 
inductive fold_graph :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> bool"
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
509  | 
for f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" and z :: 'b where  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
510  | 
  emptyI [intro]: "fold_graph f z {} z" |
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
511  | 
insertI [intro]: "x \<notin> A \<Longrightarrow> fold_graph f z A y  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
512  | 
\<Longrightarrow> fold_graph f z (insert x A) (f x y)"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
513  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
514  | 
inductive_cases empty_fold_graphE [elim!]: "fold_graph f z {} x"
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
515  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
516  | 
definition fold :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b" where
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
517  | 
[code del]: "fold f z A = (THE y. fold_graph f z A y)"  | 
| 15392 | 518  | 
|
| 15498 | 519  | 
text{*A tempting alternative for the definiens is
 | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
520  | 
@{term "if finite A then THE y. fold_graph f z A y else e"}.
 | 
| 15498 | 521  | 
It allows the removal of finiteness assumptions from the theorems  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
522  | 
@{text fold_comm}, @{text fold_reindex} and @{text fold_distrib}.
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
523  | 
The proofs become ugly. It is not worth the effort. (???) *}  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
524  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
525  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
526  | 
lemma Diff1_fold_graph:  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
527  | 
  "fold_graph f z (A - {x}) y \<Longrightarrow> x \<in> A \<Longrightarrow> fold_graph f z A (f x y)"
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
528  | 
by (erule insert_Diff [THEN subst], rule fold_graph.intros, auto)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
529  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
530  | 
lemma fold_graph_imp_finite: "fold_graph f z A x \<Longrightarrow> finite A"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
531  | 
by (induct set: fold_graph) auto  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
532  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
533  | 
lemma finite_imp_fold_graph: "finite A \<Longrightarrow> \<exists>x. fold_graph f z A x"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
534  | 
by (induct set: finite) auto  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
535  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
536  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
537  | 
subsubsection{*From @{const fold_graph} to @{term fold}*}
 | 
| 15392 | 538  | 
|
| 15510 | 539  | 
lemma image_less_Suc: "h ` {i. i < Suc m} = insert (h m) (h ` {i. i < m})"
 | 
| 19868 | 540  | 
by (auto simp add: less_Suc_eq)  | 
| 15510 | 541  | 
|
542  | 
lemma insert_image_inj_on_eq:  | 
|
543  | 
     "[|insert (h m) A = h ` {i. i < Suc m}; h m \<notin> A; 
 | 
|
544  | 
        inj_on h {i. i < Suc m}|] 
 | 
|
545  | 
      ==> A = h ` {i. i < m}"
 | 
|
546  | 
apply (auto simp add: image_less_Suc inj_on_def)  | 
|
547  | 
apply (blast intro: less_trans)  | 
|
548  | 
done  | 
|
549  | 
||
550  | 
lemma insert_inj_onE:  | 
|
551  | 
  assumes aA: "insert a A = h`{i::nat. i<n}" and anot: "a \<notin> A" 
 | 
|
552  | 
      and inj_on: "inj_on h {i::nat. i<n}"
 | 
|
553  | 
  shows "\<exists>hm m. inj_on hm {i::nat. i<m} & A = hm ` {i. i<m} & m < n"
 | 
|
554  | 
proof (cases n)  | 
|
555  | 
case 0 thus ?thesis using aA by auto  | 
|
556  | 
next  | 
|
557  | 
case (Suc m)  | 
|
| 23389 | 558  | 
have nSuc: "n = Suc m" by fact  | 
| 15510 | 559  | 
have mlessn: "m<n" by (simp add: nSuc)  | 
| 15532 | 560  | 
from aA obtain k where hkeq: "h k = a" and klessn: "k<n" by (blast elim!: equalityE)  | 
| 27165 | 561  | 
let ?hm = "Fun.swap k m h"  | 
| 15520 | 562  | 
  have inj_hm: "inj_on ?hm {i. i < n}" using klessn mlessn 
 | 
563  | 
by (simp add: inj_on_swap_iff inj_on)  | 
|
| 15510 | 564  | 
show ?thesis  | 
| 15520 | 565  | 
proof (intro exI conjI)  | 
566  | 
    show "inj_on ?hm {i. i < m}" using inj_hm
 | 
|
| 15510 | 567  | 
by (auto simp add: nSuc less_Suc_eq intro: subset_inj_on)  | 
| 15520 | 568  | 
show "m<n" by (rule mlessn)  | 
569  | 
    show "A = ?hm ` {i. i < m}" 
 | 
|
570  | 
proof (rule insert_image_inj_on_eq)  | 
|
| 27165 | 571  | 
      show "inj_on (Fun.swap k m h) {i. i < Suc m}" using inj_hm nSuc by simp
 | 
| 15520 | 572  | 
show "?hm m \<notin> A" by (simp add: swap_def hkeq anot)  | 
573  | 
      show "insert (?hm m) A = ?hm ` {i. i < Suc m}"
 | 
|
574  | 
using aA hkeq nSuc klessn  | 
|
575  | 
by (auto simp add: swap_def image_less_Suc fun_upd_image  | 
|
576  | 
less_Suc_eq inj_on_image_set_diff [OF inj_on])  | 
|
| 15479 | 577  | 
qed  | 
578  | 
qed  | 
|
579  | 
qed  | 
|
580  | 
||
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
581  | 
context fun_left_comm  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
582  | 
begin  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
583  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
584  | 
lemma fold_graph_determ_aux:  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
585  | 
  "A = h`{i::nat. i<n} \<Longrightarrow> inj_on h {i. i<n}
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
586  | 
\<Longrightarrow> fold_graph f z A x \<Longrightarrow> fold_graph f z A x'  | 
| 15392 | 587  | 
\<Longrightarrow> x' = x"  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
588  | 
proof (induct n arbitrary: A x x' h rule: less_induct)  | 
| 15510 | 589  | 
case (less n)  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
590  | 
  have IH: "\<And>m h A x x'. m < n \<Longrightarrow> A = h ` {i. i<m}
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
591  | 
      \<Longrightarrow> inj_on h {i. i<m} \<Longrightarrow> fold_graph f z A x
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
592  | 
\<Longrightarrow> fold_graph f z A x' \<Longrightarrow> x' = x" by fact  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
593  | 
have Afoldx: "fold_graph f z A x" and Afoldx': "fold_graph f z A x'"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
594  | 
    and A: "A = h`{i. i<n}" and injh: "inj_on h {i. i<n}" by fact+
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
595  | 
show ?case  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
596  | 
proof (rule fold_graph.cases [OF Afoldx])  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
597  | 
    assume "A = {}" and "x = z"
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
598  | 
with Afoldx' show "x' = x" by auto  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
599  | 
next  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
600  | 
fix B b u  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
601  | 
assume AbB: "A = insert b B" and x: "x = f b u"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
602  | 
and notinB: "b \<notin> B" and Bu: "fold_graph f z B u"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
603  | 
show "x'=x"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
604  | 
proof (rule fold_graph.cases [OF Afoldx'])  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
605  | 
      assume "A = {}" and "x' = z"
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
606  | 
with AbB show "x' = x" by blast  | 
| 15392 | 607  | 
next  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
608  | 
fix C c v  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
609  | 
assume AcC: "A = insert c C" and x': "x' = f c v"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
610  | 
and notinC: "c \<notin> C" and Cv: "fold_graph f z C v"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
611  | 
      from A AbB have Beq: "insert b B = h`{i. i<n}" by simp
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
612  | 
from insert_inj_onE [OF Beq notinB injh]  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
613  | 
      obtain hB mB where inj_onB: "inj_on hB {i. i < mB}" 
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
614  | 
        and Beq: "B = hB ` {i. i < mB}" and lessB: "mB < n" by auto 
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
615  | 
      from A AcC have Ceq: "insert c C = h`{i. i<n}" by simp
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
616  | 
from insert_inj_onE [OF Ceq notinC injh]  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
617  | 
      obtain hC mC where inj_onC: "inj_on hC {i. i < mC}"
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
618  | 
        and Ceq: "C = hC ` {i. i < mC}" and lessC: "mC < n" by auto 
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
619  | 
show "x'=x"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
620  | 
proof cases  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
621  | 
assume "b=c"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
622  | 
then moreover have "B = C" using AbB AcC notinB notinC by auto  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
623  | 
ultimately show ?thesis using Bu Cv x x' IH [OF lessC Ceq inj_onC]  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
624  | 
by auto  | 
| 15392 | 625  | 
next  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
626  | 
assume diff: "b \<noteq> c"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
627  | 
	let ?D = "B - {c}"
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
628  | 
have B: "B = insert c ?D" and C: "C = insert b ?D"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
629  | 
using AbB AcC notinB notinC diff by(blast elim!:equalityE)+  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
630  | 
have "finite A" by(rule fold_graph_imp_finite [OF Afoldx])  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
631  | 
with AbB have "finite ?D" by simp  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
632  | 
then obtain d where Dfoldd: "fold_graph f z ?D d"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
633  | 
using finite_imp_fold_graph by iprover  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
634  | 
moreover have cinB: "c \<in> B" using B by auto  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
635  | 
ultimately have "fold_graph f z B (f c d)" by(rule Diff1_fold_graph)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
636  | 
hence "f c d = u" by (rule IH [OF lessB Beq inj_onB Bu])  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
637  | 
moreover have "f b d = v"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
638  | 
proof (rule IH[OF lessC Ceq inj_onC Cv])  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
639  | 
show "fold_graph f z C (f b d)" using C notinB Dfoldd by fastsimp  | 
| 15392 | 640  | 
qed  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
641  | 
ultimately show ?thesis  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
642  | 
using fun_left_comm [of c b] x x' by (auto simp add: o_def)  | 
| 15392 | 643  | 
qed  | 
644  | 
qed  | 
|
645  | 
qed  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
646  | 
qed  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
647  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
648  | 
lemma fold_graph_determ:  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
649  | 
"fold_graph f z A x \<Longrightarrow> fold_graph f z A y \<Longrightarrow> y = x"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
650  | 
apply (frule fold_graph_imp_finite [THEN finite_imp_nat_seg_image_inj_on])  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
651  | 
apply (blast intro: fold_graph_determ_aux [rule_format])  | 
| 15392 | 652  | 
done  | 
653  | 
||
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
654  | 
lemma fold_equality:  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
655  | 
"fold_graph f z A y \<Longrightarrow> fold f z A = y"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
656  | 
by (unfold fold_def) (blast intro: fold_graph_determ)  | 
| 15392 | 657  | 
|
658  | 
text{* The base case for @{text fold}: *}
 | 
|
659  | 
||
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
660  | 
lemma (in -) fold_empty [simp]: "fold f z {} = z"
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
661  | 
by (unfold fold_def) blast  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
662  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
663  | 
text{* The various recursion equations for @{const fold}: *}
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
664  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
665  | 
lemma fold_insert_aux: "x \<notin> A  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
666  | 
\<Longrightarrow> fold_graph f z (insert x A) v \<longleftrightarrow>  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
667  | 
(\<exists>y. fold_graph f z A y \<and> v = f x y)"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
668  | 
apply auto  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
669  | 
apply (rule_tac A1 = A and f1 = f in finite_imp_fold_graph [THEN exE])  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
670  | 
apply (fastsimp dest: fold_graph_imp_finite)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
671  | 
apply (blast intro: fold_graph_determ)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
672  | 
done  | 
| 15392 | 673  | 
|
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
674  | 
lemma fold_insert [simp]:  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
675  | 
"finite A ==> x \<notin> A ==> fold f z (insert x A) = f x (fold f z A)"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
676  | 
apply (simp add: fold_def fold_insert_aux)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
677  | 
apply (rule the_equality)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
678  | 
apply (auto intro: finite_imp_fold_graph  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
679  | 
cong add: conj_cong simp add: fold_def[symmetric] fold_equality)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
680  | 
done  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
681  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
682  | 
lemma fold_fun_comm:  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
683  | 
"finite A \<Longrightarrow> f x (fold f z A) = fold f (f x z) A"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
684  | 
proof (induct rule: finite_induct)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
685  | 
case empty then show ?case by simp  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
686  | 
next  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
687  | 
case (insert y A) then show ?case  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
688  | 
by (simp add: fun_left_comm[of x])  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
689  | 
qed  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
690  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
691  | 
lemma fold_insert2:  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
692  | 
"finite A \<Longrightarrow> x \<notin> A \<Longrightarrow> fold f z (insert x A) = fold f (f x z) A"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
693  | 
by (simp add: fold_insert fold_fun_comm)  | 
| 15392 | 694  | 
|
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
695  | 
lemma fold_rec:  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
696  | 
assumes "finite A" and "x \<in> A"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
697  | 
shows "fold f z A = f x (fold f z (A - {x}))"
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
698  | 
proof -  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
699  | 
  have A: "A = insert x (A - {x})" using `x \<in> A` by blast
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
700  | 
  then have "fold f z A = fold f z (insert x (A - {x}))" by simp
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
701  | 
  also have "\<dots> = f x (fold f z (A - {x}))"
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
702  | 
by (rule fold_insert) (simp add: `finite A`)+  | 
| 15535 | 703  | 
finally show ?thesis .  | 
704  | 
qed  | 
|
705  | 
||
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
706  | 
lemma fold_insert_remove:  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
707  | 
assumes "finite A"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
708  | 
  shows "fold f z (insert x A) = f x (fold f z (A - {x}))"
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
709  | 
proof -  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
710  | 
from `finite A` have "finite (insert x A)" by auto  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
711  | 
moreover have "x \<in> insert x A" by auto  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
712  | 
  ultimately have "fold f z (insert x A) = f x (fold f z (insert x A - {x}))"
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
713  | 
by (rule fold_rec)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
714  | 
then show ?thesis by simp  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
715  | 
qed  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
716  | 
|
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
717  | 
end  | 
| 15392 | 718  | 
|
| 15480 | 719  | 
text{* A simplified version for idempotent functions: *}
 | 
720  | 
||
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
721  | 
locale fun_left_comm_idem = fun_left_comm +  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
722  | 
assumes fun_left_idem: "f x (f x z) = f x z"  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
723  | 
begin  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
724  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
725  | 
text{* The nice version: *}
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
726  | 
lemma fun_comp_idem : "f x o f x = f x"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
727  | 
by (simp add: fun_left_idem expand_fun_eq)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
728  | 
|
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
729  | 
lemma fold_insert_idem:  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
730  | 
assumes fin: "finite A"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
731  | 
shows "fold f z (insert x A) = f x (fold f z A)"  | 
| 15480 | 732  | 
proof cases  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
733  | 
assume "x \<in> A"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
734  | 
then obtain B where "A = insert x B" and "x \<notin> B" by (rule set_insert)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
735  | 
then show ?thesis using assms by (simp add:fun_left_idem)  | 
| 15480 | 736  | 
next  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
737  | 
assume "x \<notin> A" then show ?thesis using assms by simp  | 
| 15480 | 738  | 
qed  | 
739  | 
||
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
740  | 
declare fold_insert[simp del] fold_insert_idem[simp]  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
741  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
742  | 
lemma fold_insert_idem2:  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
743  | 
"finite A \<Longrightarrow> fold f z (insert x A) = fold f (f x z) A"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
744  | 
by(simp add:fold_fun_comm)  | 
| 15484 | 745  | 
|
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
746  | 
end  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
747  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
748  | 
subsubsection{* The derived combinator @{text fold_image} *}
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
749  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
750  | 
definition fold_image :: "('b \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b"
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
751  | 
where "fold_image f g = fold (%x y. f (g x) y)"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
752  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
753  | 
lemma fold_image_empty[simp]: "fold_image f g z {} = z"
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
754  | 
by(simp add:fold_image_def)  | 
| 15392 | 755  | 
|
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
756  | 
context ab_semigroup_mult  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
757  | 
begin  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
758  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
759  | 
lemma fold_image_insert[simp]:  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
760  | 
assumes "finite A" and "a \<notin> A"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
761  | 
shows "fold_image times g z (insert a A) = g a * (fold_image times g z A)"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
762  | 
proof -  | 
| 29223 | 763  | 
interpret I: fun_left_comm "%x y. (g x) * y"  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
764  | 
by unfold_locales (simp add: mult_ac)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
765  | 
show ?thesis using assms by(simp add:fold_image_def I.fold_insert)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
766  | 
qed  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
767  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
768  | 
(*  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
769  | 
lemma fold_commute:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
770  | 
"finite A ==> (!!z. x * (fold times g z A) = fold times g (x * z) A)"  | 
| 22262 | 771  | 
apply (induct set: finite)  | 
| 21575 | 772  | 
apply simp  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
773  | 
apply (simp add: mult_left_commute [of x])  | 
| 15392 | 774  | 
done  | 
775  | 
||
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
776  | 
lemma fold_nest_Un_Int:  | 
| 15392 | 777  | 
"finite A ==> finite B  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
778  | 
==> fold times g (fold times g z B) A = fold times g (fold times g z (A Int B)) (A Un B)"  | 
| 22262 | 779  | 
apply (induct set: finite)  | 
| 21575 | 780  | 
apply simp  | 
| 15392 | 781  | 
apply (simp add: fold_commute Int_insert_left insert_absorb)  | 
782  | 
done  | 
|
783  | 
||
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
784  | 
lemma fold_nest_Un_disjoint:  | 
| 15392 | 785  | 
  "finite A ==> finite B ==> A Int B = {}
 | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
786  | 
==> fold times g z (A Un B) = fold times g (fold times g z B) A"  | 
| 15392 | 787  | 
by (simp add: fold_nest_Un_Int)  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
788  | 
*)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
789  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
790  | 
lemma fold_image_reindex:  | 
| 15487 | 791  | 
assumes fin: "finite A"  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
792  | 
shows "inj_on h A \<Longrightarrow> fold_image times g z (h`A) = fold_image times (g\<circ>h) z A"  | 
| 15506 | 793  | 
using fin apply induct  | 
| 15392 | 794  | 
apply simp  | 
795  | 
apply simp  | 
|
796  | 
done  | 
|
797  | 
||
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
798  | 
(*  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
799  | 
text{*
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
800  | 
Fusion theorem, as described in Graham Hutton's paper,  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
801  | 
A Tutorial on the Universality and Expressiveness of Fold,  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
802  | 
JFP 9:4 (355-372), 1999.  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
803  | 
*}  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
804  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
805  | 
lemma fold_fusion:  | 
| 27611 | 806  | 
assumes "ab_semigroup_mult g"  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
807  | 
assumes fin: "finite A"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
808  | 
and hyp: "\<And>x y. h (g x y) = times x (h y)"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
809  | 
shows "h (fold g j w A) = fold times j (h w) A"  | 
| 27611 | 810  | 
proof -  | 
| 29223 | 811  | 
class_interpret ab_semigroup_mult [g] by fact  | 
| 27611 | 812  | 
show ?thesis using fin hyp by (induct set: finite) simp_all  | 
813  | 
qed  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
814  | 
*)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
815  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
816  | 
lemma fold_image_cong:  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
817  | 
"finite A \<Longrightarrow>  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
818  | 
(!!x. x:A ==> g x = h x) ==> fold_image times g z A = fold_image times h z A"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
819  | 
apply (subgoal_tac "ALL C. C <= A --> (ALL x:C. g x = h x) --> fold_image times g z C = fold_image times h z C")  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
820  | 
apply simp  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
821  | 
apply (erule finite_induct, simp)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
822  | 
apply (simp add: subset_insert_iff, clarify)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
823  | 
apply (subgoal_tac "finite C")  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
824  | 
prefer 2 apply (blast dest: finite_subset [COMP swap_prems_rl])  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
825  | 
apply (subgoal_tac "C = insert x (C - {x})")
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
826  | 
prefer 2 apply blast  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
827  | 
apply (erule ssubst)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
828  | 
apply (drule spec)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
829  | 
apply (erule (1) notE impE)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
830  | 
apply (simp add: Ball_def del: insert_Diff_single)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
831  | 
done  | 
| 15392 | 832  | 
|
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
833  | 
end  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
834  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
835  | 
context comm_monoid_mult  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
836  | 
begin  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
837  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
838  | 
lemma fold_image_Un_Int:  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
839  | 
"finite A ==> finite B ==>  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
840  | 
fold_image times g 1 A * fold_image times g 1 B =  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
841  | 
fold_image times g 1 (A Un B) * fold_image times g 1 (A Int B)"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
842  | 
by (induct set: finite)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
843  | 
(auto simp add: mult_ac insert_absorb Int_insert_left)  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
844  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
845  | 
corollary fold_Un_disjoint:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
846  | 
  "finite A ==> finite B ==> A Int B = {} ==>
 | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
847  | 
fold_image times g 1 (A Un B) =  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
848  | 
fold_image times g 1 A * fold_image times g 1 B"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
849  | 
by (simp add: fold_image_Un_Int)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
850  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
851  | 
lemma fold_image_UN_disjoint:  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
852  | 
"\<lbrakk> finite I; ALL i:I. finite (A i);  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
853  | 
     ALL i:I. ALL j:I. i \<noteq> j --> A i Int A j = {} \<rbrakk>
 | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
854  | 
\<Longrightarrow> fold_image times g 1 (UNION I A) =  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
855  | 
fold_image times (%i. fold_image times g 1 (A i)) 1 I"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
856  | 
apply (induct set: finite, simp, atomize)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
857  | 
apply (subgoal_tac "ALL i:F. x \<noteq> i")  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
858  | 
prefer 2 apply blast  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
859  | 
apply (subgoal_tac "A x Int UNION F A = {}")
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
860  | 
prefer 2 apply blast  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
861  | 
apply (simp add: fold_Un_disjoint)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
862  | 
done  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
863  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
864  | 
lemma fold_image_Sigma: "finite A ==> ALL x:A. finite (B x) ==>  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
865  | 
fold_image times (%x. fold_image times (g x) 1 (B x)) 1 A =  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
866  | 
fold_image times (split g) 1 (SIGMA x:A. B x)"  | 
| 15392 | 867  | 
apply (subst Sigma_def)  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
868  | 
apply (subst fold_image_UN_disjoint, assumption, simp)  | 
| 15392 | 869  | 
apply blast  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
870  | 
apply (erule fold_image_cong)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
871  | 
apply (subst fold_image_UN_disjoint, simp, simp)  | 
| 15392 | 872  | 
apply blast  | 
| 15506 | 873  | 
apply simp  | 
| 15392 | 874  | 
done  | 
875  | 
||
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
876  | 
lemma fold_image_distrib: "finite A \<Longrightarrow>  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
877  | 
fold_image times (%x. g x * h x) 1 A =  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
878  | 
fold_image times g 1 A * fold_image times h 1 A"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
879  | 
by (erule finite_induct) (simp_all add: mult_ac)  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
880  | 
|
| 
30260
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
881  | 
lemma fold_image_related:  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
882  | 
assumes Re: "R e e"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
883  | 
and Rop: "\<forall>x1 y1 x2 y2. R x1 x2 \<and> R y1 y2 \<longrightarrow> R (x1 * y1) (x2 * y2)"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
884  | 
and fS: "finite S" and Rfg: "\<forall>x\<in>S. R (h x) (g x)"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
885  | 
shows "R (fold_image (op *) h e S) (fold_image (op *) g e S)"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
886  | 
using fS by (rule finite_subset_induct) (insert assms, auto)  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
887  | 
|
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
888  | 
lemma fold_image_eq_general:  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
889  | 
assumes fS: "finite S"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
890  | 
and h: "\<forall>y\<in>S'. \<exists>!x. x\<in> S \<and> h(x) = y"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
891  | 
and f12: "\<forall>x\<in>S. h x \<in> S' \<and> f2(h x) = f1 x"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
892  | 
shows "fold_image (op *) f1 e S = fold_image (op *) f2 e S'"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
893  | 
proof-  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
894  | 
from h f12 have hS: "h ` S = S'" by auto  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
895  | 
  {fix x y assume H: "x \<in> S" "y \<in> S" "h x = h y"
 | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
896  | 
from f12 h H have "x = y" by auto }  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
897  | 
hence hinj: "inj_on h S" unfolding inj_on_def Ex1_def by blast  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
898  | 
from f12 have th: "\<And>x. x \<in> S \<Longrightarrow> (f2 \<circ> h) x = f1 x" by auto  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
899  | 
from hS have "fold_image (op *) f2 e S' = fold_image (op *) f2 e (h ` S)" by simp  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
900  | 
also have "\<dots> = fold_image (op *) (f2 o h) e S"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
901  | 
using fold_image_reindex[OF fS hinj, of f2 e] .  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
902  | 
also have "\<dots> = fold_image (op *) f1 e S " using th fold_image_cong[OF fS, of "f2 o h" f1 e]  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
903  | 
by blast  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
904  | 
finally show ?thesis ..  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
905  | 
qed  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
906  | 
|
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
907  | 
lemma fold_image_eq_general_inverses:  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
908  | 
assumes fS: "finite S"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
909  | 
and kh: "\<And>y. y \<in> T \<Longrightarrow> k y \<in> S \<and> h (k y) = y"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
910  | 
and hk: "\<And>x. x \<in> S \<Longrightarrow> h x \<in> T \<and> k (h x) = x \<and> g (h x) = f x"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
911  | 
shows "fold_image (op *) f e S = fold_image (op *) g e T"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
912  | 
(* metis solves it, but not yet available here *)  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
913  | 
apply (rule fold_image_eq_general[OF fS, of T h g f e])  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
914  | 
apply (rule ballI)  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
915  | 
apply (frule kh)  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
916  | 
apply (rule ex1I[])  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
917  | 
apply blast  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
918  | 
apply clarsimp  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
919  | 
apply (drule hk) apply simp  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
920  | 
apply (rule sym)  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
921  | 
apply (erule conjunct1[OF conjunct2[OF hk]])  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
922  | 
apply (rule ballI)  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
923  | 
apply (drule hk)  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
924  | 
apply blast  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
925  | 
done  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
926  | 
|
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
927  | 
end  | 
| 22917 | 928  | 
|
| 15402 | 929  | 
subsection {* Generalized summation over a set *}
 | 
930  | 
||
| 
30729
 
461ee3e49ad3
interpretation/interpret: prefixes are mandatory by default;
 
wenzelm 
parents: 
30325 
diff
changeset
 | 
931  | 
interpretation comm_monoid_add: comm_monoid_mult "0::'a::comm_monoid_add" "op +"  | 
| 28823 | 932  | 
proof qed (auto intro: add_assoc add_commute)  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
933  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
934  | 
definition setsum :: "('a => 'b) => 'a set => 'b::comm_monoid_add"
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
935  | 
where "setsum f A == if finite A then fold_image (op +) f 0 A else 0"  | 
| 15402 | 936  | 
|
| 19535 | 937  | 
abbreviation  | 
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21249 
diff
changeset
 | 
938  | 
  Setsum  ("\<Sum>_" [1000] 999) where
 | 
| 19535 | 939  | 
"\<Sum>A == setsum (%x. x) A"  | 
940  | 
||
| 15402 | 941  | 
text{* Now: lot's of fancy syntax. First, @{term "setsum (%x. e) A"} is
 | 
942  | 
written @{text"\<Sum>x\<in>A. e"}. *}
 | 
|
943  | 
||
944  | 
syntax  | 
|
| 17189 | 945  | 
  "_setsum" :: "pttrn => 'a set => 'b => 'b::comm_monoid_add"    ("(3SUM _:_. _)" [0, 51, 10] 10)
 | 
| 15402 | 946  | 
syntax (xsymbols)  | 
| 17189 | 947  | 
  "_setsum" :: "pttrn => 'a set => 'b => 'b::comm_monoid_add"    ("(3\<Sum>_\<in>_. _)" [0, 51, 10] 10)
 | 
| 15402 | 948  | 
syntax (HTML output)  | 
| 17189 | 949  | 
  "_setsum" :: "pttrn => 'a set => 'b => 'b::comm_monoid_add"    ("(3\<Sum>_\<in>_. _)" [0, 51, 10] 10)
 | 
| 15402 | 950  | 
|
951  | 
translations -- {* Beware of argument permutation! *}
 | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
952  | 
"SUM i:A. b" == "CONST setsum (%i. b) A"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
953  | 
"\<Sum>i\<in>A. b" == "CONST setsum (%i. b) A"  | 
| 15402 | 954  | 
|
955  | 
text{* Instead of @{term"\<Sum>x\<in>{x. P}. e"} we introduce the shorter
 | 
|
956  | 
 @{text"\<Sum>x|P. e"}. *}
 | 
|
957  | 
||
958  | 
syntax  | 
|
| 17189 | 959  | 
  "_qsetsum" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a" ("(3SUM _ |/ _./ _)" [0,0,10] 10)
 | 
| 15402 | 960  | 
syntax (xsymbols)  | 
| 17189 | 961  | 
  "_qsetsum" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a" ("(3\<Sum>_ | (_)./ _)" [0,0,10] 10)
 | 
| 15402 | 962  | 
syntax (HTML output)  | 
| 17189 | 963  | 
  "_qsetsum" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a" ("(3\<Sum>_ | (_)./ _)" [0,0,10] 10)
 | 
| 15402 | 964  | 
|
965  | 
translations  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
966  | 
  "SUM x|P. t" => "CONST setsum (%x. t) {x. P}"
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
967  | 
  "\<Sum>x|P. t" => "CONST setsum (%x. t) {x. P}"
 | 
| 15402 | 968  | 
|
969  | 
print_translation {*
 | 
|
970  | 
let  | 
|
| 19535 | 971  | 
  fun setsum_tr' [Abs(x,Tx,t), Const ("Collect",_) $ Abs(y,Ty,P)] = 
 | 
972  | 
if x<>y then raise Match  | 
|
973  | 
else let val x' = Syntax.mark_bound x  | 
|
974  | 
val t' = subst_bound(x',t)  | 
|
975  | 
val P' = subst_bound(x',P)  | 
|
976  | 
in Syntax.const "_qsetsum" $ Syntax.mark_bound x $ P' $ t' end  | 
|
977  | 
in [("setsum", setsum_tr')] end
 | 
|
| 15402 | 978  | 
*}  | 
979  | 
||
| 19535 | 980  | 
|
| 15402 | 981  | 
lemma setsum_empty [simp]: "setsum f {} = 0"
 | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
982  | 
by (simp add: setsum_def)  | 
| 15402 | 983  | 
|
984  | 
lemma setsum_insert [simp]:  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
985  | 
"finite F ==> a \<notin> F ==> setsum f (insert a F) = f a + setsum f F"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
986  | 
by (simp add: setsum_def)  | 
| 15402 | 987  | 
|
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
988  | 
lemma setsum_infinite [simp]: "~ finite A ==> setsum f A = 0"  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
989  | 
by (simp add: setsum_def)  | 
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
990  | 
|
| 15402 | 991  | 
lemma setsum_reindex:  | 
992  | 
"inj_on f B ==> setsum h (f ` B) = setsum (h \<circ> f) B"  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
993  | 
by(auto simp add: setsum_def comm_monoid_add.fold_image_reindex dest!:finite_imageD)  | 
| 15402 | 994  | 
|
995  | 
lemma setsum_reindex_id:  | 
|
996  | 
"inj_on f B ==> setsum f B = setsum id (f ` B)"  | 
|
997  | 
by (auto simp add: setsum_reindex)  | 
|
998  | 
||
| 
29674
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
999  | 
lemma setsum_reindex_nonzero:  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1000  | 
assumes fS: "finite S"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1001  | 
and nz: "\<And> x y. x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> x \<noteq> y \<Longrightarrow> f x = f y \<Longrightarrow> h (f x) = 0"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1002  | 
shows "setsum h (f ` S) = setsum (h o f) S"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1003  | 
using nz  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1004  | 
proof(induct rule: finite_induct[OF fS])  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1005  | 
case 1 thus ?case by simp  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1006  | 
next  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1007  | 
case (2 x F)  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1008  | 
  {assume fxF: "f x \<in> f ` F" hence "\<exists>y \<in> F . f y = f x" by auto
 | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1009  | 
then obtain y where y: "y \<in> F" "f x = f y" by auto  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1010  | 
from "2.hyps" y have xy: "x \<noteq> y" by auto  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1011  | 
|
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1012  | 
from "2.prems"[of x y] "2.hyps" xy y have h0: "h (f x) = 0" by simp  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1013  | 
have "setsum h (f ` insert x F) = setsum h (f ` F)" using fxF by auto  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1014  | 
also have "\<dots> = setsum (h o f) (insert x F)"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1015  | 
unfolding setsum_insert[OF `finite F` `x\<notin>F`]  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1016  | 
using h0  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1017  | 
apply simp  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1018  | 
apply (rule "2.hyps"(3))  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1019  | 
apply (rule_tac y="y" in "2.prems")  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1020  | 
apply simp_all  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1021  | 
done  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1022  | 
finally have ?case .}  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1023  | 
moreover  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1024  | 
  {assume fxF: "f x \<notin> f ` F"
 | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1025  | 
have "setsum h (f ` insert x F) = h (f x) + setsum h (f ` F)"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1026  | 
using fxF "2.hyps" by simp  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1027  | 
also have "\<dots> = setsum (h o f) (insert x F)"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1028  | 
unfolding setsum_insert[OF `finite F` `x\<notin>F`]  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1029  | 
apply simp  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1030  | 
apply (rule cong[OF refl[of "op + (h (f x))"]])  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1031  | 
apply (rule "2.hyps"(3))  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1032  | 
apply (rule_tac y="y" in "2.prems")  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1033  | 
apply simp_all  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1034  | 
done  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1035  | 
finally have ?case .}  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1036  | 
ultimately show ?case by blast  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1037  | 
qed  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1038  | 
|
| 15402 | 1039  | 
lemma setsum_cong:  | 
1040  | 
"A = B ==> (!!x. x:B ==> f x = g x) ==> setsum f A = setsum g B"  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1041  | 
by(fastsimp simp: setsum_def intro: comm_monoid_add.fold_image_cong)  | 
| 15402 | 1042  | 
|
| 
16733
 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 
nipkow 
parents: 
16632 
diff
changeset
 | 
1043  | 
lemma strong_setsum_cong[cong]:  | 
| 
 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 
nipkow 
parents: 
16632 
diff
changeset
 | 
1044  | 
"A = B ==> (!!x. x:B =simp=> f x = g x)  | 
| 
 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 
nipkow 
parents: 
16632 
diff
changeset
 | 
1045  | 
==> setsum (%x. f x) A = setsum (%x. g x) B"  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1046  | 
by(fastsimp simp: simp_implies_def setsum_def intro: comm_monoid_add.fold_image_cong)  | 
| 
16632
 
ad2895beef79
Added strong_setsum_cong and strong_setprod_cong.
 
berghofe 
parents: 
16550 
diff
changeset
 | 
1047  | 
|
| 15554 | 1048  | 
lemma setsum_cong2: "\<lbrakk>\<And>x. x \<in> A \<Longrightarrow> f x = g x\<rbrakk> \<Longrightarrow> setsum f A = setsum g A";  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1049  | 
by (rule setsum_cong[OF refl], auto);  | 
| 15554 | 1050  | 
|
| 15402 | 1051  | 
lemma setsum_reindex_cong:  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1052  | 
"[|inj_on f A; B = f ` A; !!a. a:A \<Longrightarrow> g a = h (f a)|]  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1053  | 
==> setsum h B = setsum g A"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1054  | 
by (simp add: setsum_reindex cong: setsum_cong)  | 
| 15402 | 1055  | 
|
| 
29674
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1056  | 
|
| 15542 | 1057  | 
lemma setsum_0[simp]: "setsum (%i. 0) A = 0"  | 
| 15402 | 1058  | 
apply (clarsimp simp: setsum_def)  | 
| 15765 | 1059  | 
apply (erule finite_induct, auto)  | 
| 15402 | 1060  | 
done  | 
1061  | 
||
| 15543 | 1062  | 
lemma setsum_0': "ALL a:A. f a = 0 ==> setsum f A = 0"  | 
1063  | 
by(simp add:setsum_cong)  | 
|
| 15402 | 1064  | 
|
1065  | 
lemma setsum_Un_Int: "finite A ==> finite B ==>  | 
|
1066  | 
setsum g (A Un B) + setsum g (A Int B) = setsum g A + setsum g B"  | 
|
1067  | 
  -- {* The reversed orientation looks more natural, but LOOPS as a simprule! *}
 | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1068  | 
by(simp add: setsum_def comm_monoid_add.fold_image_Un_Int [symmetric])  | 
| 15402 | 1069  | 
|
1070  | 
lemma setsum_Un_disjoint: "finite A ==> finite B  | 
|
1071  | 
  ==> A Int B = {} ==> setsum g (A Un B) = setsum g A + setsum g B"
 | 
|
1072  | 
by (subst setsum_Un_Int [symmetric], auto)  | 
|
1073  | 
||
| 
29674
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1074  | 
lemma setsum_mono_zero_left:  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1075  | 
assumes fT: "finite T" and ST: "S \<subseteq> T"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1076  | 
and z: "\<forall>i \<in> T - S. f i = 0"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1077  | 
shows "setsum f S = setsum f T"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1078  | 
proof-  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1079  | 
have eq: "T = S \<union> (T - S)" using ST by blast  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1080  | 
  have d: "S \<inter> (T - S) = {}" using ST by blast
 | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1081  | 
from fT ST have f: "finite S" "finite (T - S)" by (auto intro: finite_subset)  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1082  | 
show ?thesis  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1083  | 
by (simp add: setsum_Un_disjoint[OF f d, unfolded eq[symmetric]] setsum_0'[OF z])  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1084  | 
qed  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1085  | 
|
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1086  | 
lemma setsum_mono_zero_right:  | 
| 
30837
 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 
nipkow 
parents: 
30729 
diff
changeset
 | 
1087  | 
"finite T \<Longrightarrow> S \<subseteq> T \<Longrightarrow> \<forall>i \<in> T - S. f i = 0 \<Longrightarrow> setsum f T = setsum f S"  | 
| 
 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 
nipkow 
parents: 
30729 
diff
changeset
 | 
1088  | 
by(blast intro!: setsum_mono_zero_left[symmetric])  | 
| 
29674
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1089  | 
|
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1090  | 
lemma setsum_mono_zero_cong_left:  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1091  | 
assumes fT: "finite T" and ST: "S \<subseteq> T"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1092  | 
and z: "\<forall>i \<in> T - S. g i = 0"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1093  | 
and fg: "\<And>x. x \<in> S \<Longrightarrow> f x = g x"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1094  | 
shows "setsum f S = setsum g T"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1095  | 
proof-  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1096  | 
have eq: "T = S \<union> (T - S)" using ST by blast  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1097  | 
  have d: "S \<inter> (T - S) = {}" using ST by blast
 | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1098  | 
from fT ST have f: "finite S" "finite (T - S)" by (auto intro: finite_subset)  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1099  | 
show ?thesis  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1100  | 
using fg by (simp add: setsum_Un_disjoint[OF f d, unfolded eq[symmetric]] setsum_0'[OF z])  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1101  | 
qed  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1102  | 
|
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1103  | 
lemma setsum_mono_zero_cong_right:  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1104  | 
assumes fT: "finite T" and ST: "S \<subseteq> T"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1105  | 
and z: "\<forall>i \<in> T - S. f i = 0"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1106  | 
and fg: "\<And>x. x \<in> S \<Longrightarrow> f x = g x"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1107  | 
shows "setsum f T = setsum g S"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1108  | 
using setsum_mono_zero_cong_left[OF fT ST z] fg[symmetric] by auto  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1109  | 
|
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1110  | 
lemma setsum_delta:  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1111  | 
assumes fS: "finite S"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1112  | 
shows "setsum (\<lambda>k. if k=a then b k else 0) S = (if a \<in> S then b a else 0)"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1113  | 
proof-  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1114  | 
let ?f = "(\<lambda>k. if k=a then b k else 0)"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1115  | 
  {assume a: "a \<notin> S"
 | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1116  | 
hence "\<forall> k\<in> S. ?f k = 0" by simp  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1117  | 
hence ?thesis using a by simp}  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1118  | 
moreover  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1119  | 
  {assume a: "a \<in> S"
 | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1120  | 
    let ?A = "S - {a}"
 | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1121  | 
    let ?B = "{a}"
 | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1122  | 
have eq: "S = ?A \<union> ?B" using a by blast  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1123  | 
    have dj: "?A \<inter> ?B = {}" by simp
 | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1124  | 
from fS have fAB: "finite ?A" "finite ?B" by auto  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1125  | 
have "setsum ?f S = setsum ?f ?A + setsum ?f ?B"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1126  | 
using setsum_Un_disjoint[OF fAB dj, of ?f, unfolded eq[symmetric]]  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1127  | 
by simp  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1128  | 
then have ?thesis using a by simp}  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1129  | 
ultimately show ?thesis by blast  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1130  | 
qed  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1131  | 
lemma setsum_delta':  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1132  | 
assumes fS: "finite S" shows  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1133  | 
"setsum (\<lambda>k. if a = k then b k else 0) S =  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1134  | 
(if a\<in> S then b a else 0)"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1135  | 
using setsum_delta[OF fS, of a b, symmetric]  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1136  | 
by (auto intro: setsum_cong)  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1137  | 
|
| 
30260
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1138  | 
lemma setsum_restrict_set:  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1139  | 
assumes fA: "finite A"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1140  | 
shows "setsum f (A \<inter> B) = setsum (\<lambda>x. if x \<in> B then f x else 0) A"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1141  | 
proof-  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1142  | 
from fA have fab: "finite (A \<inter> B)" by auto  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1143  | 
have aba: "A \<inter> B \<subseteq> A" by blast  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1144  | 
let ?g = "\<lambda>x. if x \<in> A\<inter>B then f x else 0"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1145  | 
from setsum_mono_zero_left[OF fA aba, of ?g]  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1146  | 
show ?thesis by simp  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1147  | 
qed  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1148  | 
|
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1149  | 
lemma setsum_cases:  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1150  | 
assumes fA: "finite A"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1151  | 
shows "setsum (\<lambda>x. if x \<in> B then f x else g x) A =  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1152  | 
setsum f (A \<inter> B) + setsum g (A \<inter> - B)"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1153  | 
proof-  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1154  | 
  have a: "A = A \<inter> B \<union> A \<inter> -B" "(A \<inter> B) \<inter> (A \<inter> -B) = {}" 
 | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1155  | 
by blast+  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1156  | 
from fA  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1157  | 
have f: "finite (A \<inter> B)" "finite (A \<inter> -B)" by auto  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1158  | 
let ?g = "\<lambda>x. if x \<in> B then f x else g x"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1159  | 
from setsum_Un_disjoint[OF f a(2), of ?g] a(1)  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1160  | 
show ?thesis by simp  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1161  | 
qed  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1162  | 
|
| 
29674
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1163  | 
|
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1164  | 
(*But we can't get rid of finite I. If infinite, although the rhs is 0,  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1165  | 
the lhs need not be, since UNION I A could still be finite.*)  | 
| 15402 | 1166  | 
lemma setsum_UN_disjoint:  | 
1167  | 
"finite I ==> (ALL i:I. finite (A i)) ==>  | 
|
1168  | 
        (ALL i:I. ALL j:I. i \<noteq> j --> A i Int A j = {}) ==>
 | 
|
1169  | 
setsum f (UNION I A) = (\<Sum>i\<in>I. setsum f (A i))"  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1170  | 
by(simp add: setsum_def comm_monoid_add.fold_image_UN_disjoint cong: setsum_cong)  | 
| 15402 | 1171  | 
|
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1172  | 
text{*No need to assume that @{term C} is finite.  If infinite, the rhs is
 | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1173  | 
directly 0, and @{term "Union C"} is also infinite, hence the lhs is also 0.*}
 | 
| 15402 | 1174  | 
lemma setsum_Union_disjoint:  | 
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1175  | 
"[| (ALL A:C. finite A);  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1176  | 
      (ALL A:C. ALL B:C. A \<noteq> B --> A Int B = {}) |]
 | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1177  | 
==> setsum f (Union C) = setsum (setsum f) C"  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1178  | 
apply (cases "finite C")  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1179  | 
prefer 2 apply (force dest: finite_UnionD simp add: setsum_def)  | 
| 15402 | 1180  | 
apply (frule setsum_UN_disjoint [of C id f])  | 
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1181  | 
apply (unfold Union_def id_def, assumption+)  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1182  | 
done  | 
| 15402 | 1183  | 
|
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1184  | 
(*But we can't get rid of finite A. If infinite, although the lhs is 0,  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1185  | 
the rhs need not be, since SIGMA A B could still be finite.*)  | 
| 15402 | 1186  | 
lemma setsum_Sigma: "finite A ==> ALL x:A. finite (B x) ==>  | 
| 17189 | 1187  | 
(\<Sum>x\<in>A. (\<Sum>y\<in>B x. f x y)) = (\<Sum>(x,y)\<in>(SIGMA x:A. B x). f x y)"  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1188  | 
by(simp add:setsum_def comm_monoid_add.fold_image_Sigma split_def cong:setsum_cong)  | 
| 15402 | 1189  | 
|
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1190  | 
text{*Here we can eliminate the finiteness assumptions, by cases.*}
 | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1191  | 
lemma setsum_cartesian_product:  | 
| 17189 | 1192  | 
"(\<Sum>x\<in>A. (\<Sum>y\<in>B. f x y)) = (\<Sum>(x,y) \<in> A <*> B. f x y)"  | 
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1193  | 
apply (cases "finite A")  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1194  | 
apply (cases "finite B")  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1195  | 
apply (simp add: setsum_Sigma)  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1196  | 
 apply (cases "A={}", simp)
 | 
| 15543 | 1197  | 
apply (simp)  | 
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1198  | 
apply (auto simp add: setsum_def  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1199  | 
dest: finite_cartesian_productD1 finite_cartesian_productD2)  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1200  | 
done  | 
| 15402 | 1201  | 
|
1202  | 
lemma setsum_addf: "setsum (%x. f x + g x) A = (setsum f A + setsum g A)"  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1203  | 
by(simp add:setsum_def comm_monoid_add.fold_image_distrib)  | 
| 15402 | 1204  | 
|
1205  | 
||
1206  | 
subsubsection {* Properties in more restricted classes of structures *}
 | 
|
1207  | 
||
1208  | 
lemma setsum_SucD: "setsum f A = Suc n ==> EX a:A. 0 < f a"  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1209  | 
apply (case_tac "finite A")  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1210  | 
prefer 2 apply (simp add: setsum_def)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1211  | 
apply (erule rev_mp)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1212  | 
apply (erule finite_induct, auto)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1213  | 
done  | 
| 15402 | 1214  | 
|
1215  | 
lemma setsum_eq_0_iff [simp]:  | 
|
1216  | 
"finite F ==> (setsum f F = 0) = (ALL a:F. f a = (0::nat))"  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1217  | 
by (induct set: finite) auto  | 
| 15402 | 1218  | 
|
| 30859 | 1219  | 
lemma setsum_eq_Suc0_iff: "finite A \<Longrightarrow>  | 
1220  | 
(setsum f A = Suc 0) = (EX a:A. f a = Suc 0 & (ALL b:A. a\<noteq>b \<longrightarrow> f b = 0))"  | 
|
1221  | 
apply(erule finite_induct)  | 
|
1222  | 
apply (auto simp add:add_is_1)  | 
|
1223  | 
done  | 
|
1224  | 
||
1225  | 
lemmas setsum_eq_1_iff = setsum_eq_Suc0_iff[simplified One_nat_def[symmetric]]  | 
|
1226  | 
||
| 15402 | 1227  | 
lemma setsum_Un_nat: "finite A ==> finite B ==>  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1228  | 
(setsum f (A Un B) :: nat) = setsum f A + setsum f B - setsum f (A Int B)"  | 
| 15402 | 1229  | 
  -- {* For the natural numbers, we have subtraction. *}
 | 
| 29667 | 1230  | 
by (subst setsum_Un_Int [symmetric], auto simp add: algebra_simps)  | 
| 15402 | 1231  | 
|
1232  | 
lemma setsum_Un: "finite A ==> finite B ==>  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1233  | 
(setsum f (A Un B) :: 'a :: ab_group_add) =  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1234  | 
setsum f A + setsum f B - setsum f (A Int B)"  | 
| 29667 | 1235  | 
by (subst setsum_Un_Int [symmetric], auto simp add: algebra_simps)  | 
| 15402 | 1236  | 
|
| 
30260
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1237  | 
lemma (in comm_monoid_mult) fold_image_1: "finite S \<Longrightarrow> (\<forall>x\<in>S. f x = 1) \<Longrightarrow> fold_image op * f 1 S = 1"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1238  | 
apply (induct set: finite)  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1239  | 
apply simp by (auto simp add: fold_image_insert)  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1240  | 
|
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1241  | 
lemma (in comm_monoid_mult) fold_image_Un_one:  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1242  | 
assumes fS: "finite S" and fT: "finite T"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1243  | 
and I0: "\<forall>x \<in> S\<inter>T. f x = 1"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1244  | 
shows "fold_image (op *) f 1 (S \<union> T) = fold_image (op *) f 1 S * fold_image (op *) f 1 T"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1245  | 
proof-  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1246  | 
have "fold_image op * f 1 (S \<inter> T) = 1"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1247  | 
apply (rule fold_image_1)  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1248  | 
using fS fT I0 by auto  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1249  | 
with fold_image_Un_Int[OF fS fT] show ?thesis by simp  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1250  | 
qed  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1251  | 
|
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1252  | 
lemma setsum_eq_general_reverses:  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1253  | 
assumes fS: "finite S" and fT: "finite T"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1254  | 
and kh: "\<And>y. y \<in> T \<Longrightarrow> k y \<in> S \<and> h (k y) = y"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1255  | 
and hk: "\<And>x. x \<in> S \<Longrightarrow> h x \<in> T \<and> k (h x) = x \<and> g (h x) = f x"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1256  | 
shows "setsum f S = setsum g T"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1257  | 
apply (simp add: setsum_def fS fT)  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1258  | 
apply (rule comm_monoid_add.fold_image_eq_general_inverses[OF fS])  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1259  | 
apply (erule kh)  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1260  | 
apply (erule hk)  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1261  | 
done  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1262  | 
|
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1263  | 
|
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1264  | 
|
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1265  | 
lemma setsum_Un_zero:  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1266  | 
assumes fS: "finite S" and fT: "finite T"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1267  | 
and I0: "\<forall>x \<in> S\<inter>T. f x = 0"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1268  | 
shows "setsum f (S \<union> T) = setsum f S + setsum f T"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1269  | 
using fS fT  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1270  | 
apply (simp add: setsum_def)  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1271  | 
apply (rule comm_monoid_add.fold_image_Un_one)  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1272  | 
using I0 by auto  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1273  | 
|
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1274  | 
|
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1275  | 
lemma setsum_UNION_zero:  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1276  | 
assumes fS: "finite S" and fSS: "\<forall>T \<in> S. finite T"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1277  | 
and f0: "\<And>T1 T2 x. T1\<in>S \<Longrightarrow> T2\<in>S \<Longrightarrow> T1 \<noteq> T2 \<Longrightarrow> x \<in> T1 \<Longrightarrow> x \<in> T2 \<Longrightarrow> f x = 0"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1278  | 
shows "setsum f (\<Union>S) = setsum (\<lambda>T. setsum f T) S"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1279  | 
using fSS f0  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1280  | 
proof(induct rule: finite_induct[OF fS])  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1281  | 
case 1 thus ?case by simp  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1282  | 
next  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1283  | 
case (2 T F)  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1284  | 
then have fTF: "finite T" "\<forall>T\<in>F. finite T" "finite F" and TF: "T \<notin> F"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1285  | 
and H: "setsum f (\<Union> F) = setsum (setsum f) F" by (auto simp add: finite_insert)  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1286  | 
from fTF have fUF: "finite (\<Union>F)" by (auto intro: finite_Union)  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1287  | 
from "2.prems" TF fTF  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1288  | 
show ?case  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1289  | 
by (auto simp add: H[symmetric] intro: setsum_Un_zero[OF fTF(1) fUF, of f])  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1290  | 
qed  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1291  | 
|
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1292  | 
|
| 15402 | 1293  | 
lemma setsum_diff1_nat: "(setsum f (A - {a}) :: nat) =
 | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1294  | 
(if a:A then setsum f A - f a else setsum f A)"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1295  | 
apply (case_tac "finite A")  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1296  | 
prefer 2 apply (simp add: setsum_def)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1297  | 
apply (erule finite_induct)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1298  | 
apply (auto simp add: insert_Diff_if)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1299  | 
apply (drule_tac a = a in mk_disjoint_insert, auto)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1300  | 
done  | 
| 15402 | 1301  | 
|
1302  | 
lemma setsum_diff1: "finite A \<Longrightarrow>  | 
|
1303  | 
  (setsum f (A - {a}) :: ('a::ab_group_add)) =
 | 
|
1304  | 
(if a:A then setsum f A - f a else setsum f A)"  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1305  | 
by (erule finite_induct) (auto simp add: insert_Diff_if)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1306  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1307  | 
lemma setsum_diff1'[rule_format]:  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1308  | 
  "finite A \<Longrightarrow> a \<in> A \<longrightarrow> (\<Sum> x \<in> A. f x) = f a + (\<Sum> x \<in> (A - {a}). f x)"
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1309  | 
apply (erule finite_induct[where F=A and P="% A. (a \<in> A \<longrightarrow> (\<Sum> x \<in> A. f x) = f a + (\<Sum> x \<in> (A - {a}). f x))"])
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1310  | 
apply (auto simp add: insert_Diff_if add_ac)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1311  | 
done  | 
| 
15552
 
8ab8e425410b
added setsum_diff1' which holds in more general cases than setsum_diff1
 
obua 
parents: 
15543 
diff
changeset
 | 
1312  | 
|
| 15402 | 1313  | 
(* By Jeremy Siek: *)  | 
1314  | 
||
1315  | 
lemma setsum_diff_nat:  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1316  | 
assumes "finite B" and "B \<subseteq> A"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1317  | 
shows "(setsum f (A - B) :: nat) = (setsum f A) - (setsum f B)"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1318  | 
using assms  | 
| 19535 | 1319  | 
proof induct  | 
| 15402 | 1320  | 
  show "setsum f (A - {}) = (setsum f A) - (setsum f {})" by simp
 | 
1321  | 
next  | 
|
1322  | 
fix F x assume finF: "finite F" and xnotinF: "x \<notin> F"  | 
|
1323  | 
and xFinA: "insert x F \<subseteq> A"  | 
|
1324  | 
and IH: "F \<subseteq> A \<Longrightarrow> setsum f (A - F) = setsum f A - setsum f F"  | 
|
1325  | 
from xnotinF xFinA have xinAF: "x \<in> (A - F)" by simp  | 
|
1326  | 
  from xinAF have A: "setsum f ((A - F) - {x}) = setsum f (A - F) - f x"
 | 
|
1327  | 
by (simp add: setsum_diff1_nat)  | 
|
1328  | 
from xFinA have "F \<subseteq> A" by simp  | 
|
1329  | 
with IH have "setsum f (A - F) = setsum f A - setsum f F" by simp  | 
|
1330  | 
  with A have B: "setsum f ((A - F) - {x}) = setsum f A - setsum f F - f x"
 | 
|
1331  | 
by simp  | 
|
1332  | 
  from xnotinF have "A - insert x F = (A - F) - {x}" by auto
 | 
|
1333  | 
with B have C: "setsum f (A - insert x F) = setsum f A - setsum f F - f x"  | 
|
1334  | 
by simp  | 
|
1335  | 
from finF xnotinF have "setsum f (insert x F) = setsum f F + f x" by simp  | 
|
1336  | 
with C have "setsum f (A - insert x F) = setsum f A - setsum f (insert x F)"  | 
|
1337  | 
by simp  | 
|
1338  | 
thus "setsum f (A - insert x F) = setsum f A - setsum f (insert x F)" by simp  | 
|
1339  | 
qed  | 
|
1340  | 
||
1341  | 
lemma setsum_diff:  | 
|
1342  | 
assumes le: "finite A" "B \<subseteq> A"  | 
|
1343  | 
  shows "setsum f (A - B) = setsum f A - ((setsum f B)::('a::ab_group_add))"
 | 
|
1344  | 
proof -  | 
|
1345  | 
from le have finiteB: "finite B" using finite_subset by auto  | 
|
1346  | 
show ?thesis using finiteB le  | 
|
| 21575 | 1347  | 
proof induct  | 
| 19535 | 1348  | 
case empty  | 
1349  | 
thus ?case by auto  | 
|
1350  | 
next  | 
|
1351  | 
case (insert x F)  | 
|
1352  | 
thus ?case using le finiteB  | 
|
1353  | 
by (simp add: Diff_insert[where a=x and B=F] setsum_diff1 insert_absorb)  | 
|
| 15402 | 1354  | 
qed  | 
| 19535 | 1355  | 
qed  | 
| 15402 | 1356  | 
|
1357  | 
lemma setsum_mono:  | 
|
1358  | 
  assumes le: "\<And>i. i\<in>K \<Longrightarrow> f (i::'a) \<le> ((g i)::('b::{comm_monoid_add, pordered_ab_semigroup_add}))"
 | 
|
1359  | 
shows "(\<Sum>i\<in>K. f i) \<le> (\<Sum>i\<in>K. g i)"  | 
|
1360  | 
proof (cases "finite K")  | 
|
1361  | 
case True  | 
|
1362  | 
thus ?thesis using le  | 
|
| 19535 | 1363  | 
proof induct  | 
| 15402 | 1364  | 
case empty  | 
1365  | 
thus ?case by simp  | 
|
1366  | 
next  | 
|
1367  | 
case insert  | 
|
| 19535 | 1368  | 
thus ?case using add_mono by fastsimp  | 
| 15402 | 1369  | 
qed  | 
1370  | 
next  | 
|
1371  | 
case False  | 
|
1372  | 
thus ?thesis  | 
|
1373  | 
by (simp add: setsum_def)  | 
|
1374  | 
qed  | 
|
1375  | 
||
| 15554 | 1376  | 
lemma setsum_strict_mono:  | 
| 19535 | 1377  | 
  fixes f :: "'a \<Rightarrow> 'b::{pordered_cancel_ab_semigroup_add,comm_monoid_add}"
 | 
1378  | 
  assumes "finite A"  "A \<noteq> {}"
 | 
|
1379  | 
and "!!x. x:A \<Longrightarrow> f x < g x"  | 
|
1380  | 
shows "setsum f A < setsum g A"  | 
|
1381  | 
using prems  | 
|
| 15554 | 1382  | 
proof (induct rule: finite_ne_induct)  | 
1383  | 
case singleton thus ?case by simp  | 
|
1384  | 
next  | 
|
1385  | 
case insert thus ?case by (auto simp: add_strict_mono)  | 
|
1386  | 
qed  | 
|
1387  | 
||
| 15535 | 1388  | 
lemma setsum_negf:  | 
| 19535 | 1389  | 
"setsum (%x. - (f x)::'a::ab_group_add) A = - setsum f A"  | 
| 15535 | 1390  | 
proof (cases "finite A")  | 
| 22262 | 1391  | 
case True thus ?thesis by (induct set: finite) auto  | 
| 15535 | 1392  | 
next  | 
1393  | 
case False thus ?thesis by (simp add: setsum_def)  | 
|
1394  | 
qed  | 
|
| 15402 | 1395  | 
|
| 15535 | 1396  | 
lemma setsum_subtractf:  | 
| 19535 | 1397  | 
"setsum (%x. ((f x)::'a::ab_group_add) - g x) A =  | 
1398  | 
setsum f A - setsum g A"  | 
|
| 15535 | 1399  | 
proof (cases "finite A")  | 
1400  | 
case True thus ?thesis by (simp add: diff_minus setsum_addf setsum_negf)  | 
|
1401  | 
next  | 
|
1402  | 
case False thus ?thesis by (simp add: setsum_def)  | 
|
1403  | 
qed  | 
|
| 15402 | 1404  | 
|
| 15535 | 1405  | 
lemma setsum_nonneg:  | 
| 19535 | 1406  | 
  assumes nn: "\<forall>x\<in>A. (0::'a::{pordered_ab_semigroup_add,comm_monoid_add}) \<le> f x"
 | 
1407  | 
shows "0 \<le> setsum f A"  | 
|
| 15535 | 1408  | 
proof (cases "finite A")  | 
1409  | 
case True thus ?thesis using nn  | 
|
| 21575 | 1410  | 
proof induct  | 
| 19535 | 1411  | 
case empty then show ?case by simp  | 
1412  | 
next  | 
|
1413  | 
case (insert x F)  | 
|
1414  | 
then have "0 + 0 \<le> f x + setsum f F" by (blast intro: add_mono)  | 
|
1415  | 
with insert show ?case by simp  | 
|
1416  | 
qed  | 
|
| 15535 | 1417  | 
next  | 
1418  | 
case False thus ?thesis by (simp add: setsum_def)  | 
|
1419  | 
qed  | 
|
| 15402 | 1420  | 
|
| 15535 | 1421  | 
lemma setsum_nonpos:  | 
| 19535 | 1422  | 
  assumes np: "\<forall>x\<in>A. f x \<le> (0::'a::{pordered_ab_semigroup_add,comm_monoid_add})"
 | 
1423  | 
shows "setsum f A \<le> 0"  | 
|
| 15535 | 1424  | 
proof (cases "finite A")  | 
1425  | 
case True thus ?thesis using np  | 
|
| 21575 | 1426  | 
proof induct  | 
| 19535 | 1427  | 
case empty then show ?case by simp  | 
1428  | 
next  | 
|
1429  | 
case (insert x F)  | 
|
1430  | 
then have "f x + setsum f F \<le> 0 + 0" by (blast intro: add_mono)  | 
|
1431  | 
with insert show ?case by simp  | 
|
1432  | 
qed  | 
|
| 15535 | 1433  | 
next  | 
1434  | 
case False thus ?thesis by (simp add: setsum_def)  | 
|
1435  | 
qed  | 
|
| 15402 | 1436  | 
|
| 15539 | 1437  | 
lemma setsum_mono2:  | 
1438  | 
fixes f :: "'a \<Rightarrow> 'b :: {pordered_ab_semigroup_add_imp_le,comm_monoid_add}"
 | 
|
1439  | 
assumes fin: "finite B" and sub: "A \<subseteq> B" and nn: "\<And>b. b \<in> B-A \<Longrightarrow> 0 \<le> f b"  | 
|
1440  | 
shows "setsum f A \<le> setsum f B"  | 
|
1441  | 
proof -  | 
|
1442  | 
have "setsum f A \<le> setsum f A + setsum f (B-A)"  | 
|
1443  | 
by(simp add: add_increasing2[OF setsum_nonneg] nn Ball_def)  | 
|
1444  | 
also have "\<dots> = setsum f (A \<union> (B-A))" using fin finite_subset[OF sub fin]  | 
|
1445  | 
by (simp add:setsum_Un_disjoint del:Un_Diff_cancel)  | 
|
1446  | 
also have "A \<union> (B-A) = B" using sub by blast  | 
|
1447  | 
finally show ?thesis .  | 
|
1448  | 
qed  | 
|
| 15542 | 1449  | 
|
| 
16775
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16760 
diff
changeset
 | 
1450  | 
lemma setsum_mono3: "finite B ==> A <= B ==>  | 
| 
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16760 
diff
changeset
 | 
1451  | 
ALL x: B - A.  | 
| 
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16760 
diff
changeset
 | 
1452  | 
      0 <= ((f x)::'a::{comm_monoid_add,pordered_ab_semigroup_add}) ==>
 | 
| 
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16760 
diff
changeset
 | 
1453  | 
setsum f A <= setsum f B"  | 
| 
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16760 
diff
changeset
 | 
1454  | 
apply (subgoal_tac "setsum f B = setsum f A + setsum f (B - A)")  | 
| 
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16760 
diff
changeset
 | 
1455  | 
apply (erule ssubst)  | 
| 
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16760 
diff
changeset
 | 
1456  | 
apply (subgoal_tac "setsum f A + 0 <= setsum f A + setsum f (B - A)")  | 
| 
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16760 
diff
changeset
 | 
1457  | 
apply simp  | 
| 
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16760 
diff
changeset
 | 
1458  | 
apply (rule add_left_mono)  | 
| 
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16760 
diff
changeset
 | 
1459  | 
apply (erule setsum_nonneg)  | 
| 
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16760 
diff
changeset
 | 
1460  | 
apply (subst setsum_Un_disjoint [THEN sym])  | 
| 
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16760 
diff
changeset
 | 
1461  | 
apply (erule finite_subset, assumption)  | 
| 
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16760 
diff
changeset
 | 
1462  | 
apply (rule finite_subset)  | 
| 
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16760 
diff
changeset
 | 
1463  | 
prefer 2  | 
| 
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16760 
diff
changeset
 | 
1464  | 
apply assumption  | 
| 
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16760 
diff
changeset
 | 
1465  | 
apply auto  | 
| 
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16760 
diff
changeset
 | 
1466  | 
apply (rule setsum_cong)  | 
| 
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16760 
diff
changeset
 | 
1467  | 
apply auto  | 
| 
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16760 
diff
changeset
 | 
1468  | 
done  | 
| 
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16760 
diff
changeset
 | 
1469  | 
|
| 19279 | 1470  | 
lemma setsum_right_distrib:  | 
| 
22934
 
64ecb3d6790a
generalize setsum lemmas from semiring_0_cancel to semiring_0
 
huffman 
parents: 
22917 
diff
changeset
 | 
1471  | 
  fixes f :: "'a => ('b::semiring_0)"
 | 
| 15402 | 1472  | 
shows "r * setsum f A = setsum (%n. r * f n) A"  | 
1473  | 
proof (cases "finite A")  | 
|
1474  | 
case True  | 
|
1475  | 
thus ?thesis  | 
|
| 21575 | 1476  | 
proof induct  | 
| 15402 | 1477  | 
case empty thus ?case by simp  | 
1478  | 
next  | 
|
1479  | 
case (insert x A) thus ?case by (simp add: right_distrib)  | 
|
1480  | 
qed  | 
|
1481  | 
next  | 
|
1482  | 
case False thus ?thesis by (simp add: setsum_def)  | 
|
1483  | 
qed  | 
|
1484  | 
||
| 
17149
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1485  | 
lemma setsum_left_distrib:  | 
| 
22934
 
64ecb3d6790a
generalize setsum lemmas from semiring_0_cancel to semiring_0
 
huffman 
parents: 
22917 
diff
changeset
 | 
1486  | 
"setsum f A * (r::'a::semiring_0) = (\<Sum>n\<in>A. f n * r)"  | 
| 
17149
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1487  | 
proof (cases "finite A")  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1488  | 
case True  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1489  | 
then show ?thesis  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1490  | 
proof induct  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1491  | 
case empty thus ?case by simp  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1492  | 
next  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1493  | 
case (insert x A) thus ?case by (simp add: left_distrib)  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1494  | 
qed  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1495  | 
next  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1496  | 
case False thus ?thesis by (simp add: setsum_def)  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1497  | 
qed  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1498  | 
|
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1499  | 
lemma setsum_divide_distrib:  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1500  | 
"setsum f A / (r::'a::field) = (\<Sum>n\<in>A. f n / r)"  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1501  | 
proof (cases "finite A")  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1502  | 
case True  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1503  | 
then show ?thesis  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1504  | 
proof induct  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1505  | 
case empty thus ?case by simp  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1506  | 
next  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1507  | 
case (insert x A) thus ?case by (simp add: add_divide_distrib)  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1508  | 
qed  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1509  | 
next  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1510  | 
case False thus ?thesis by (simp add: setsum_def)  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1511  | 
qed  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1512  | 
|
| 15535 | 1513  | 
lemma setsum_abs[iff]:  | 
| 
25303
 
0699e20feabd
renamed lordered_*_* to lordered_*_add_*; further localization
 
haftmann 
parents: 
25205 
diff
changeset
 | 
1514  | 
  fixes f :: "'a => ('b::pordered_ab_group_add_abs)"
 | 
| 15402 | 1515  | 
shows "abs (setsum f A) \<le> setsum (%i. abs(f i)) A"  | 
| 15535 | 1516  | 
proof (cases "finite A")  | 
1517  | 
case True  | 
|
1518  | 
thus ?thesis  | 
|
| 21575 | 1519  | 
proof induct  | 
| 15535 | 1520  | 
case empty thus ?case by simp  | 
1521  | 
next  | 
|
1522  | 
case (insert x A)  | 
|
1523  | 
thus ?case by (auto intro: abs_triangle_ineq order_trans)  | 
|
1524  | 
qed  | 
|
| 15402 | 1525  | 
next  | 
| 15535 | 1526  | 
case False thus ?thesis by (simp add: setsum_def)  | 
| 15402 | 1527  | 
qed  | 
1528  | 
||
| 15535 | 1529  | 
lemma setsum_abs_ge_zero[iff]:  | 
| 
25303
 
0699e20feabd
renamed lordered_*_* to lordered_*_add_*; further localization
 
haftmann 
parents: 
25205 
diff
changeset
 | 
1530  | 
  fixes f :: "'a => ('b::pordered_ab_group_add_abs)"
 | 
| 15402 | 1531  | 
shows "0 \<le> setsum (%i. abs(f i)) A"  | 
| 15535 | 1532  | 
proof (cases "finite A")  | 
1533  | 
case True  | 
|
1534  | 
thus ?thesis  | 
|
| 21575 | 1535  | 
proof induct  | 
| 15535 | 1536  | 
case empty thus ?case by simp  | 
1537  | 
next  | 
|
| 21733 | 1538  | 
case (insert x A) thus ?case by (auto simp: add_nonneg_nonneg)  | 
| 15535 | 1539  | 
qed  | 
| 15402 | 1540  | 
next  | 
| 15535 | 1541  | 
case False thus ?thesis by (simp add: setsum_def)  | 
| 15402 | 1542  | 
qed  | 
1543  | 
||
| 15539 | 1544  | 
lemma abs_setsum_abs[simp]:  | 
| 
25303
 
0699e20feabd
renamed lordered_*_* to lordered_*_add_*; further localization
 
haftmann 
parents: 
25205 
diff
changeset
 | 
1545  | 
  fixes f :: "'a => ('b::pordered_ab_group_add_abs)"
 | 
| 15539 | 1546  | 
shows "abs (\<Sum>a\<in>A. abs(f a)) = (\<Sum>a\<in>A. abs(f a))"  | 
1547  | 
proof (cases "finite A")  | 
|
1548  | 
case True  | 
|
1549  | 
thus ?thesis  | 
|
| 21575 | 1550  | 
proof induct  | 
| 15539 | 1551  | 
case empty thus ?case by simp  | 
1552  | 
next  | 
|
1553  | 
case (insert a A)  | 
|
1554  | 
hence "\<bar>\<Sum>a\<in>insert a A. \<bar>f a\<bar>\<bar> = \<bar>\<bar>f a\<bar> + (\<Sum>a\<in>A. \<bar>f a\<bar>)\<bar>" by simp  | 
|
1555  | 
also have "\<dots> = \<bar>\<bar>f a\<bar> + \<bar>\<Sum>a\<in>A. \<bar>f a\<bar>\<bar>\<bar>" using insert by simp  | 
|
| 
16775
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16760 
diff
changeset
 | 
1556  | 
also have "\<dots> = \<bar>f a\<bar> + \<bar>\<Sum>a\<in>A. \<bar>f a\<bar>\<bar>"  | 
| 
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16760 
diff
changeset
 | 
1557  | 
by (simp del: abs_of_nonneg)  | 
| 15539 | 1558  | 
also have "\<dots> = (\<Sum>a\<in>insert a A. \<bar>f a\<bar>)" using insert by simp  | 
1559  | 
finally show ?case .  | 
|
1560  | 
qed  | 
|
1561  | 
next  | 
|
1562  | 
case False thus ?thesis by (simp add: setsum_def)  | 
|
1563  | 
qed  | 
|
1564  | 
||
| 15402 | 1565  | 
|
| 
17149
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1566  | 
text {* Commuting outer and inner summation *}
 | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1567  | 
|
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1568  | 
lemma swap_inj_on:  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1569  | 
"inj_on (%(i, j). (j, i)) (A \<times> B)"  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1570  | 
by (unfold inj_on_def) fast  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1571  | 
|
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1572  | 
lemma swap_product:  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1573  | 
"(%(i, j). (j, i)) ` (A \<times> B) = B \<times> A"  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1574  | 
by (simp add: split_def image_def) blast  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1575  | 
|
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1576  | 
lemma setsum_commute:  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1577  | 
"(\<Sum>i\<in>A. \<Sum>j\<in>B. f i j) = (\<Sum>j\<in>B. \<Sum>i\<in>A. f i j)"  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1578  | 
proof (simp add: setsum_cartesian_product)  | 
| 17189 | 1579  | 
have "(\<Sum>(x,y) \<in> A <*> B. f x y) =  | 
1580  | 
(\<Sum>(y,x) \<in> (%(i, j). (j, i)) ` (A \<times> B). f x y)"  | 
|
| 
17149
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1581  | 
(is "?s = _")  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1582  | 
apply (simp add: setsum_reindex [where f = "%(i, j). (j, i)"] swap_inj_on)  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1583  | 
apply (simp add: split_def)  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1584  | 
done  | 
| 17189 | 1585  | 
also have "... = (\<Sum>(y,x)\<in>B \<times> A. f x y)"  | 
| 
17149
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1586  | 
(is "_ = ?t")  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1587  | 
apply (simp add: swap_product)  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1588  | 
done  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1589  | 
finally show "?s = ?t" .  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1590  | 
qed  | 
| 
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1591  | 
|
| 19279 | 1592  | 
lemma setsum_product:  | 
| 
22934
 
64ecb3d6790a
generalize setsum lemmas from semiring_0_cancel to semiring_0
 
huffman 
parents: 
22917 
diff
changeset
 | 
1593  | 
  fixes f :: "'a => ('b::semiring_0)"
 | 
| 19279 | 1594  | 
shows "setsum f A * setsum g B = (\<Sum>i\<in>A. \<Sum>j\<in>B. f i * g j)"  | 
1595  | 
by (simp add: setsum_right_distrib setsum_left_distrib) (rule setsum_commute)  | 
|
1596  | 
||
| 
17149
 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 
ballarin 
parents: 
17085 
diff
changeset
 | 
1597  | 
|
| 15402 | 1598  | 
subsection {* Generalized product over a set *}
 | 
1599  | 
||
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1600  | 
definition setprod :: "('a => 'b) => 'a set => 'b::comm_monoid_mult"
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1601  | 
where "setprod f A == if finite A then fold_image (op *) f 1 A else 1"  | 
| 15402 | 1602  | 
|
| 19535 | 1603  | 
abbreviation  | 
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21249 
diff
changeset
 | 
1604  | 
  Setprod  ("\<Prod>_" [1000] 999) where
 | 
| 19535 | 1605  | 
"\<Prod>A == setprod (%x. x) A"  | 
1606  | 
||
| 15402 | 1607  | 
syntax  | 
| 17189 | 1608  | 
  "_setprod" :: "pttrn => 'a set => 'b => 'b::comm_monoid_mult"  ("(3PROD _:_. _)" [0, 51, 10] 10)
 | 
| 15402 | 1609  | 
syntax (xsymbols)  | 
| 17189 | 1610  | 
  "_setprod" :: "pttrn => 'a set => 'b => 'b::comm_monoid_mult"  ("(3\<Prod>_\<in>_. _)" [0, 51, 10] 10)
 | 
| 15402 | 1611  | 
syntax (HTML output)  | 
| 17189 | 1612  | 
  "_setprod" :: "pttrn => 'a set => 'b => 'b::comm_monoid_mult"  ("(3\<Prod>_\<in>_. _)" [0, 51, 10] 10)
 | 
| 16550 | 1613  | 
|
1614  | 
translations -- {* Beware of argument permutation! *}
 | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1615  | 
"PROD i:A. b" == "CONST setprod (%i. b) A"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1616  | 
"\<Prod>i\<in>A. b" == "CONST setprod (%i. b) A"  | 
| 16550 | 1617  | 
|
1618  | 
text{* Instead of @{term"\<Prod>x\<in>{x. P}. e"} we introduce the shorter
 | 
|
1619  | 
 @{text"\<Prod>x|P. e"}. *}
 | 
|
1620  | 
||
1621  | 
syntax  | 
|
| 17189 | 1622  | 
  "_qsetprod" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a" ("(3PROD _ |/ _./ _)" [0,0,10] 10)
 | 
| 16550 | 1623  | 
syntax (xsymbols)  | 
| 17189 | 1624  | 
  "_qsetprod" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a" ("(3\<Prod>_ | (_)./ _)" [0,0,10] 10)
 | 
| 16550 | 1625  | 
syntax (HTML output)  | 
| 17189 | 1626  | 
  "_qsetprod" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a" ("(3\<Prod>_ | (_)./ _)" [0,0,10] 10)
 | 
| 16550 | 1627  | 
|
| 15402 | 1628  | 
translations  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1629  | 
  "PROD x|P. t" => "CONST setprod (%x. t) {x. P}"
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1630  | 
  "\<Prod>x|P. t" => "CONST setprod (%x. t) {x. P}"
 | 
| 16550 | 1631  | 
|
| 15402 | 1632  | 
|
1633  | 
lemma setprod_empty [simp]: "setprod f {} = 1"
 | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1634  | 
by (auto simp add: setprod_def)  | 
| 15402 | 1635  | 
|
1636  | 
lemma setprod_insert [simp]: "[| finite A; a \<notin> A |] ==>  | 
|
1637  | 
setprod f (insert a A) = f a * setprod f A"  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1638  | 
by (simp add: setprod_def)  | 
| 15402 | 1639  | 
|
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1640  | 
lemma setprod_infinite [simp]: "~ finite A ==> setprod f A = 1"  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1641  | 
by (simp add: setprod_def)  | 
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1642  | 
|
| 15402 | 1643  | 
lemma setprod_reindex:  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1644  | 
"inj_on f B ==> setprod h (f ` B) = setprod (h \<circ> f) B"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1645  | 
by(auto simp: setprod_def fold_image_reindex dest!:finite_imageD)  | 
| 15402 | 1646  | 
|
1647  | 
lemma setprod_reindex_id: "inj_on f B ==> setprod f B = setprod id (f ` B)"  | 
|
1648  | 
by (auto simp add: setprod_reindex)  | 
|
1649  | 
||
1650  | 
lemma setprod_cong:  | 
|
1651  | 
"A = B ==> (!!x. x:B ==> f x = g x) ==> setprod f A = setprod g B"  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1652  | 
by(fastsimp simp: setprod_def intro: fold_image_cong)  | 
| 15402 | 1653  | 
|
| 
30837
 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 
nipkow 
parents: 
30729 
diff
changeset
 | 
1654  | 
lemma strong_setprod_cong[cong]:  | 
| 
16632
 
ad2895beef79
Added strong_setsum_cong and strong_setprod_cong.
 
berghofe 
parents: 
16550 
diff
changeset
 | 
1655  | 
"A = B ==> (!!x. x:B =simp=> f x = g x) ==> setprod f A = setprod g B"  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1656  | 
by(fastsimp simp: simp_implies_def setprod_def intro: fold_image_cong)  | 
| 
16632
 
ad2895beef79
Added strong_setsum_cong and strong_setprod_cong.
 
berghofe 
parents: 
16550 
diff
changeset
 | 
1657  | 
|
| 15402 | 1658  | 
lemma setprod_reindex_cong: "inj_on f A ==>  | 
1659  | 
B = f ` A ==> g = h \<circ> f ==> setprod h B = setprod g A"  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1660  | 
by (frule setprod_reindex, simp)  | 
| 15402 | 1661  | 
|
| 
29674
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1662  | 
lemma strong_setprod_reindex_cong: assumes i: "inj_on f A"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1663  | 
and B: "B = f ` A" and eq: "\<And>x. x \<in> A \<Longrightarrow> g x = (h \<circ> f) x"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1664  | 
shows "setprod h B = setprod g A"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1665  | 
proof-  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1666  | 
have "setprod h B = setprod (h o f) A"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1667  | 
by (simp add: B setprod_reindex[OF i, of h])  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1668  | 
then show ?thesis apply simp  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1669  | 
apply (rule setprod_cong)  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1670  | 
apply simp  | 
| 
30837
 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 
nipkow 
parents: 
30729 
diff
changeset
 | 
1671  | 
by (simp add: eq)  | 
| 
29674
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1672  | 
qed  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1673  | 
|
| 
30260
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1674  | 
lemma setprod_Un_one:  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1675  | 
assumes fS: "finite S" and fT: "finite T"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1676  | 
and I0: "\<forall>x \<in> S\<inter>T. f x = 1"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1677  | 
shows "setprod f (S \<union> T) = setprod f S * setprod f T"  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1678  | 
using fS fT  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1679  | 
apply (simp add: setprod_def)  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1680  | 
apply (rule fold_image_Un_one)  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1681  | 
using I0 by auto  | 
| 
 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 
chaieb 
parents: 
29966 
diff
changeset
 | 
1682  | 
|
| 15402 | 1683  | 
|
1684  | 
lemma setprod_1: "setprod (%i. 1) A = 1"  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1685  | 
apply (case_tac "finite A")  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1686  | 
apply (erule finite_induct, auto simp add: mult_ac)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1687  | 
done  | 
| 15402 | 1688  | 
|
1689  | 
lemma setprod_1': "ALL a:F. f a = 1 ==> setprod f F = 1"  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1690  | 
apply (subgoal_tac "setprod f F = setprod (%x. 1) F")  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1691  | 
apply (erule ssubst, rule setprod_1)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1692  | 
apply (rule setprod_cong, auto)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1693  | 
done  | 
| 15402 | 1694  | 
|
1695  | 
lemma setprod_Un_Int: "finite A ==> finite B  | 
|
1696  | 
==> setprod g (A Un B) * setprod g (A Int B) = setprod g A * setprod g B"  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1697  | 
by(simp add: setprod_def fold_image_Un_Int[symmetric])  | 
| 15402 | 1698  | 
|
1699  | 
lemma setprod_Un_disjoint: "finite A ==> finite B  | 
|
1700  | 
  ==> A Int B = {} ==> setprod g (A Un B) = setprod g A * setprod g B"
 | 
|
1701  | 
by (subst setprod_Un_Int [symmetric], auto)  | 
|
1702  | 
||
| 
30837
 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 
nipkow 
parents: 
30729 
diff
changeset
 | 
1703  | 
lemma setprod_mono_one_left:  | 
| 
 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 
nipkow 
parents: 
30729 
diff
changeset
 | 
1704  | 
assumes fT: "finite T" and ST: "S \<subseteq> T"  | 
| 
 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 
nipkow 
parents: 
30729 
diff
changeset
 | 
1705  | 
and z: "\<forall>i \<in> T - S. f i = 1"  | 
| 
 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 
nipkow 
parents: 
30729 
diff
changeset
 | 
1706  | 
shows "setprod f S = setprod f T"  | 
| 
 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 
nipkow 
parents: 
30729 
diff
changeset
 | 
1707  | 
proof-  | 
| 
 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 
nipkow 
parents: 
30729 
diff
changeset
 | 
1708  | 
have eq: "T = S \<union> (T - S)" using ST by blast  | 
| 
 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 
nipkow 
parents: 
30729 
diff
changeset
 | 
1709  | 
  have d: "S \<inter> (T - S) = {}" using ST by blast
 | 
| 
 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 
nipkow 
parents: 
30729 
diff
changeset
 | 
1710  | 
from fT ST have f: "finite S" "finite (T - S)" by (auto intro: finite_subset)  | 
| 
 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 
nipkow 
parents: 
30729 
diff
changeset
 | 
1711  | 
show ?thesis  | 
| 
 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 
nipkow 
parents: 
30729 
diff
changeset
 | 
1712  | 
by (simp add: setprod_Un_disjoint[OF f d, unfolded eq[symmetric]] setprod_1'[OF z])  | 
| 
 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 
nipkow 
parents: 
30729 
diff
changeset
 | 
1713  | 
qed  | 
| 
 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 
nipkow 
parents: 
30729 
diff
changeset
 | 
1714  | 
|
| 
 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 
nipkow 
parents: 
30729 
diff
changeset
 | 
1715  | 
lemmas setprod_mono_one_right = setprod_mono_one_left [THEN sym]  | 
| 
 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 
nipkow 
parents: 
30729 
diff
changeset
 | 
1716  | 
|
| 
29674
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1717  | 
lemma setprod_delta:  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1718  | 
assumes fS: "finite S"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1719  | 
shows "setprod (\<lambda>k. if k=a then b k else 1) S = (if a \<in> S then b a else 1)"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1720  | 
proof-  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1721  | 
let ?f = "(\<lambda>k. if k=a then b k else 1)"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1722  | 
  {assume a: "a \<notin> S"
 | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1723  | 
hence "\<forall> k\<in> S. ?f k = 1" by simp  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1724  | 
hence ?thesis using a by (simp add: setprod_1 cong add: setprod_cong) }  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1725  | 
moreover  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1726  | 
  {assume a: "a \<in> S"
 | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1727  | 
    let ?A = "S - {a}"
 | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1728  | 
    let ?B = "{a}"
 | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1729  | 
have eq: "S = ?A \<union> ?B" using a by blast  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1730  | 
    have dj: "?A \<inter> ?B = {}" by simp
 | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1731  | 
from fS have fAB: "finite ?A" "finite ?B" by auto  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1732  | 
have fA1: "setprod ?f ?A = 1" apply (rule setprod_1') by auto  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1733  | 
have "setprod ?f ?A * setprod ?f ?B = setprod ?f S"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1734  | 
using setprod_Un_disjoint[OF fAB dj, of ?f, unfolded eq[symmetric]]  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1735  | 
by simp  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1736  | 
then have ?thesis using a by (simp add: fA1 cong add: setprod_cong cong del: if_weak_cong)}  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1737  | 
ultimately show ?thesis by blast  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1738  | 
qed  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1739  | 
|
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1740  | 
lemma setprod_delta':  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1741  | 
assumes fS: "finite S" shows  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1742  | 
"setprod (\<lambda>k. if a = k then b k else 1) S =  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1743  | 
(if a\<in> S then b a else 1)"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1744  | 
using setprod_delta[OF fS, of a b, symmetric]  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1745  | 
by (auto intro: setprod_cong)  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1746  | 
|
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
1747  | 
|
| 15402 | 1748  | 
lemma setprod_UN_disjoint:  | 
1749  | 
"finite I ==> (ALL i:I. finite (A i)) ==>  | 
|
1750  | 
        (ALL i:I. ALL j:I. i \<noteq> j --> A i Int A j = {}) ==>
 | 
|
1751  | 
setprod f (UNION I A) = setprod (%i. setprod f (A i)) I"  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1752  | 
by(simp add: setprod_def fold_image_UN_disjoint cong: setprod_cong)  | 
| 15402 | 1753  | 
|
1754  | 
lemma setprod_Union_disjoint:  | 
|
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1755  | 
"[| (ALL A:C. finite A);  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1756  | 
      (ALL A:C. ALL B:C. A \<noteq> B --> A Int B = {}) |] 
 | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1757  | 
==> setprod f (Union C) = setprod (setprod f) C"  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1758  | 
apply (cases "finite C")  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1759  | 
prefer 2 apply (force dest: finite_UnionD simp add: setprod_def)  | 
| 15402 | 1760  | 
apply (frule setprod_UN_disjoint [of C id f])  | 
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1761  | 
apply (unfold Union_def id_def, assumption+)  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1762  | 
done  | 
| 15402 | 1763  | 
|
1764  | 
lemma setprod_Sigma: "finite A ==> ALL x:A. finite (B x) ==>  | 
|
| 16550 | 1765  | 
(\<Prod>x\<in>A. (\<Prod>y\<in> B x. f x y)) =  | 
| 17189 | 1766  | 
(\<Prod>(x,y)\<in>(SIGMA x:A. B x). f x y)"  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1767  | 
by(simp add:setprod_def fold_image_Sigma split_def cong:setprod_cong)  | 
| 15402 | 1768  | 
|
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1769  | 
text{*Here we can eliminate the finiteness assumptions, by cases.*}
 | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1770  | 
lemma setprod_cartesian_product:  | 
| 17189 | 1771  | 
"(\<Prod>x\<in>A. (\<Prod>y\<in> B. f x y)) = (\<Prod>(x,y)\<in>(A <*> B). f x y)"  | 
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1772  | 
apply (cases "finite A")  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1773  | 
apply (cases "finite B")  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1774  | 
apply (simp add: setprod_Sigma)  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1775  | 
 apply (cases "A={}", simp)
 | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1776  | 
apply (simp add: setprod_1)  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1777  | 
apply (auto simp add: setprod_def  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1778  | 
dest: finite_cartesian_productD1 finite_cartesian_productD2)  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1779  | 
done  | 
| 15402 | 1780  | 
|
1781  | 
lemma setprod_timesf:  | 
|
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1782  | 
"setprod (%x. f x * g x) A = (setprod f A * setprod g A)"  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1783  | 
by(simp add:setprod_def fold_image_distrib)  | 
| 15402 | 1784  | 
|
1785  | 
||
1786  | 
subsubsection {* Properties in more restricted classes of structures *}
 | 
|
1787  | 
||
1788  | 
lemma setprod_eq_1_iff [simp]:  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1789  | 
"finite F ==> (setprod f F = 1) = (ALL a:F. f a = (1::nat))"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1790  | 
by (induct set: finite) auto  | 
| 15402 | 1791  | 
|
1792  | 
lemma setprod_zero:  | 
|
| 23277 | 1793  | 
"finite A ==> EX x: A. f x = (0::'a::comm_semiring_1) ==> setprod f A = 0"  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1794  | 
apply (induct set: finite, force, clarsimp)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1795  | 
apply (erule disjE, auto)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1796  | 
done  | 
| 15402 | 1797  | 
|
1798  | 
lemma setprod_nonneg [rule_format]:  | 
|
| 
30841
 
0813afc97522
generalized setprod_nonneg and setprod_pos to ordered_semidom, simplified proofs
 
huffman 
parents: 
30729 
diff
changeset
 | 
1799  | 
"(ALL x: A. (0::'a::ordered_semidom) \<le> f x) --> 0 \<le> setprod f A"  | 
| 
 
0813afc97522
generalized setprod_nonneg and setprod_pos to ordered_semidom, simplified proofs
 
huffman 
parents: 
30729 
diff
changeset
 | 
1800  | 
by (cases "finite A", induct set: finite, simp_all add: mult_nonneg_nonneg)  | 
| 
 
0813afc97522
generalized setprod_nonneg and setprod_pos to ordered_semidom, simplified proofs
 
huffman 
parents: 
30729 
diff
changeset
 | 
1801  | 
|
| 
 
0813afc97522
generalized setprod_nonneg and setprod_pos to ordered_semidom, simplified proofs
 
huffman 
parents: 
30729 
diff
changeset
 | 
1802  | 
lemma setprod_pos [rule_format]: "(ALL x: A. (0::'a::ordered_semidom) < f x)  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1803  | 
--> 0 < setprod f A"  | 
| 
30841
 
0813afc97522
generalized setprod_nonneg and setprod_pos to ordered_semidom, simplified proofs
 
huffman 
parents: 
30729 
diff
changeset
 | 
1804  | 
by (cases "finite A", induct set: finite, simp_all add: mult_pos_pos)  | 
| 15402 | 1805  | 
|
| 30843 | 1806  | 
lemma setprod_zero_iff[simp]: "finite A ==>  | 
1807  | 
  (setprod f A = (0::'a::{comm_semiring_1,no_zero_divisors})) =
 | 
|
1808  | 
(EX x: A. f x = 0)"  | 
|
1809  | 
by (erule finite_induct, auto simp:no_zero_divisors)  | 
|
1810  | 
||
1811  | 
lemma setprod_pos_nat:  | 
|
1812  | 
"finite S ==> (ALL x : S. f x > (0::nat)) ==> setprod f S > 0"  | 
|
1813  | 
using setprod_zero_iff by(simp del:neq0_conv add:neq0_conv[symmetric])  | 
|
| 15402 | 1814  | 
|
| 30863 | 1815  | 
lemma setprod_pos_nat_iff[simp]:  | 
1816  | 
"finite S ==> (setprod f S > 0) = (ALL x : S. f x > (0::nat))"  | 
|
1817  | 
using setprod_zero_iff by(simp del:neq0_conv add:neq0_conv[symmetric])  | 
|
1818  | 
||
| 15402 | 1819  | 
lemma setprod_Un: "finite A ==> finite B ==> (ALL x: A Int B. f x \<noteq> 0) ==>  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1820  | 
  (setprod f (A Un B) :: 'a ::{field})
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1821  | 
= setprod f A * setprod f B / setprod f (A Int B)"  | 
| 30843 | 1822  | 
by (subst setprod_Un_Int [symmetric], auto)  | 
| 15402 | 1823  | 
|
1824  | 
lemma setprod_diff1: "finite A ==> f a \<noteq> 0 ==>  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1825  | 
  (setprod f (A - {a}) :: 'a :: {field}) =
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1826  | 
(if a:A then setprod f A / f a else setprod f A)"  | 
| 
23413
 
5caa2710dd5b
tuned laws for cancellation in divisions for fields.
 
nipkow 
parents: 
23398 
diff
changeset
 | 
1827  | 
by (erule finite_induct) (auto simp add: insert_Diff_if)  | 
| 15402 | 1828  | 
|
1829  | 
lemma setprod_inversef: "finite A ==>  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1830  | 
  ALL x: A. f x \<noteq> (0::'a::{field,division_by_zero}) ==>
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1831  | 
setprod (inverse \<circ> f) A = inverse (setprod f A)"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1832  | 
by (erule finite_induct) auto  | 
| 15402 | 1833  | 
|
1834  | 
lemma setprod_dividef:  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1835  | 
"[|finite A;  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1836  | 
      \<forall>x \<in> A. g x \<noteq> (0::'a::{field,division_by_zero})|]
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1837  | 
==> setprod (%x. f x / g x) A = setprod f A / setprod g A"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1838  | 
apply (subgoal_tac  | 
| 15402 | 1839  | 
"setprod (%x. f x / g x) A = setprod (%x. f x * (inverse \<circ> g) x) A")  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1840  | 
apply (erule ssubst)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1841  | 
apply (subst divide_inverse)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1842  | 
apply (subst setprod_timesf)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1843  | 
apply (subst setprod_inversef, assumption+, rule refl)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1844  | 
apply (rule setprod_cong, rule refl)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1845  | 
apply (subst divide_inverse, auto)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1846  | 
done  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1847  | 
|
| 29925 | 1848  | 
lemma setprod_dvd_setprod [rule_format]:  | 
1849  | 
"(ALL x : A. f x dvd g x) \<longrightarrow> setprod f A dvd setprod g A"  | 
|
1850  | 
apply (cases "finite A")  | 
|
1851  | 
apply (induct set: finite)  | 
|
1852  | 
apply (auto simp add: dvd_def)  | 
|
1853  | 
apply (rule_tac x = "k * ka" in exI)  | 
|
1854  | 
apply (simp add: algebra_simps)  | 
|
1855  | 
done  | 
|
1856  | 
||
1857  | 
lemma setprod_dvd_setprod_subset:  | 
|
1858  | 
"finite B \<Longrightarrow> A <= B \<Longrightarrow> setprod f A dvd setprod f B"  | 
|
1859  | 
apply (subgoal_tac "setprod f B = setprod f A * setprod f (B - A)")  | 
|
1860  | 
apply (unfold dvd_def, blast)  | 
|
1861  | 
apply (subst setprod_Un_disjoint [symmetric])  | 
|
1862  | 
apply (auto elim: finite_subset intro: setprod_cong)  | 
|
1863  | 
done  | 
|
1864  | 
||
1865  | 
lemma setprod_dvd_setprod_subset2:  | 
|
1866  | 
"finite B \<Longrightarrow> A <= B \<Longrightarrow> ALL x : A. (f x::'a::comm_semiring_1) dvd g x \<Longrightarrow>  | 
|
1867  | 
setprod f A dvd setprod g B"  | 
|
1868  | 
apply (rule dvd_trans)  | 
|
1869  | 
apply (rule setprod_dvd_setprod, erule (1) bspec)  | 
|
1870  | 
apply (erule (1) setprod_dvd_setprod_subset)  | 
|
1871  | 
done  | 
|
1872  | 
||
1873  | 
lemma dvd_setprod: "finite A \<Longrightarrow> i:A \<Longrightarrow>  | 
|
1874  | 
(f i ::'a::comm_semiring_1) dvd setprod f A"  | 
|
1875  | 
by (induct set: finite) (auto intro: dvd_mult)  | 
|
1876  | 
||
1877  | 
lemma dvd_setsum [rule_format]: "(ALL i : A. d dvd f i) \<longrightarrow>  | 
|
1878  | 
(d::'a::comm_semiring_1) dvd (SUM x : A. f x)"  | 
|
1879  | 
apply (cases "finite A")  | 
|
1880  | 
apply (induct set: finite)  | 
|
1881  | 
apply auto  | 
|
1882  | 
done  | 
|
1883  | 
||
| 15402 | 1884  | 
|
| 12396 | 1885  | 
subsection {* Finite cardinality *}
 | 
1886  | 
||
| 15402 | 1887  | 
text {* This definition, although traditional, is ugly to work with:
 | 
1888  | 
@{text "card A == LEAST n. EX f. A = {f i | i. i < n}"}.
 | 
|
1889  | 
But now that we have @{text setsum} things are easy:
 | 
|
| 12396 | 1890  | 
*}  | 
1891  | 
||
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1892  | 
definition card :: "'a set \<Rightarrow> nat"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1893  | 
where "card A = setsum (\<lambda>x. 1) A"  | 
| 12396 | 1894  | 
|
1895  | 
lemma card_empty [simp]: "card {} = 0"
 | 
|
| 24853 | 1896  | 
by (simp add: card_def)  | 
| 15402 | 1897  | 
|
| 24427 | 1898  | 
lemma card_infinite [simp]: "~ finite A ==> card A = 0"  | 
| 24853 | 1899  | 
by (simp add: card_def)  | 
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1900  | 
|
| 15402 | 1901  | 
lemma card_eq_setsum: "card A = setsum (%x. 1) A"  | 
1902  | 
by (simp add: card_def)  | 
|
| 12396 | 1903  | 
|
1904  | 
lemma card_insert_disjoint [simp]:  | 
|
1905  | 
"finite A ==> x \<notin> A ==> card (insert x A) = Suc(card A)"  | 
|
| 15765 | 1906  | 
by(simp add: card_def)  | 
| 15402 | 1907  | 
|
1908  | 
lemma card_insert_if:  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1909  | 
"finite A ==> card (insert x A) = (if x:A then card A else Suc(card(A)))"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1910  | 
by (simp add: insert_absorb)  | 
| 12396 | 1911  | 
|
| 
24286
 
7619080e49f0
ATP blacklisting is now in theory data, attribute noatp
 
paulson 
parents: 
24268 
diff
changeset
 | 
1912  | 
lemma card_0_eq [simp,noatp]: "finite A ==> (card A = 0) = (A = {})"
 | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1913  | 
apply auto  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1914  | 
apply (drule_tac a = x in mk_disjoint_insert, clarify, auto)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1915  | 
done  | 
| 12396 | 1916  | 
|
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1917  | 
lemma card_eq_0_iff: "(card A = 0) = (A = {} | ~ finite A)"
 | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1918  | 
by auto  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
1919  | 
|
| 24853 | 1920  | 
|
| 12396 | 1921  | 
lemma card_Suc_Diff1: "finite A ==> x: A ==> Suc (card (A - {x})) = card A"
 | 
| 14302 | 1922  | 
apply(rule_tac t = A in insert_Diff [THEN subst], assumption)  | 
1923  | 
apply(simp del:insert_Diff_single)  | 
|
1924  | 
done  | 
|
| 12396 | 1925  | 
|
1926  | 
lemma card_Diff_singleton:  | 
|
| 24853 | 1927  | 
  "finite A ==> x: A ==> card (A - {x}) = card A - 1"
 | 
1928  | 
by (simp add: card_Suc_Diff1 [symmetric])  | 
|
| 12396 | 1929  | 
|
1930  | 
lemma card_Diff_singleton_if:  | 
|
| 24853 | 1931  | 
  "finite A ==> card (A-{x}) = (if x : A then card A - 1 else card A)"
 | 
1932  | 
by (simp add: card_Diff_singleton)  | 
|
1933  | 
||
1934  | 
lemma card_Diff_insert[simp]:  | 
|
1935  | 
assumes "finite A" and "a:A" and "a ~: B"  | 
|
1936  | 
shows "card(A - insert a B) = card(A - B) - 1"  | 
|
1937  | 
proof -  | 
|
1938  | 
  have "A - insert a B = (A - B) - {a}" using assms by blast
 | 
|
1939  | 
then show ?thesis using assms by(simp add:card_Diff_singleton)  | 
|
1940  | 
qed  | 
|
| 12396 | 1941  | 
|
1942  | 
lemma card_insert: "finite A ==> card (insert x A) = Suc (card (A - {x}))"
 | 
|
| 24853 | 1943  | 
by (simp add: card_insert_if card_Suc_Diff1 del:card_Diff_insert)  | 
| 12396 | 1944  | 
|
1945  | 
lemma card_insert_le: "finite A ==> card A <= card (insert x A)"  | 
|
| 24853 | 1946  | 
by (simp add: card_insert_if)  | 
| 12396 | 1947  | 
|
| 15402 | 1948  | 
lemma card_mono: "\<lbrakk> finite B; A \<subseteq> B \<rbrakk> \<Longrightarrow> card A \<le> card B"  | 
| 15539 | 1949  | 
by (simp add: card_def setsum_mono2)  | 
| 15402 | 1950  | 
|
| 12396 | 1951  | 
lemma card_seteq: "finite B ==> (!!A. A <= B ==> card B <= card A ==> A = B)"  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1952  | 
apply (induct set: finite, simp, clarify)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1953  | 
apply (subgoal_tac "finite A & A - {x} <= F")
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1954  | 
prefer 2 apply (blast intro: finite_subset, atomize)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1955  | 
apply (drule_tac x = "A - {x}" in spec)
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1956  | 
apply (simp add: card_Diff_singleton_if split add: split_if_asm)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1957  | 
apply (case_tac "card A", auto)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1958  | 
done  | 
| 12396 | 1959  | 
|
1960  | 
lemma psubset_card_mono: "finite B ==> A < B ==> card A < card B"  | 
|
| 26792 | 1961  | 
apply (simp add: psubset_eq linorder_not_le [symmetric])  | 
| 24853 | 1962  | 
apply (blast dest: card_seteq)  | 
1963  | 
done  | 
|
| 12396 | 1964  | 
|
1965  | 
lemma card_Un_Int: "finite A ==> finite B  | 
|
1966  | 
==> card A + card B = card (A Un B) + card (A Int B)"  | 
|
| 15402 | 1967  | 
by(simp add:card_def setsum_Un_Int)  | 
| 12396 | 1968  | 
|
1969  | 
lemma card_Un_disjoint: "finite A ==> finite B  | 
|
1970  | 
    ==> A Int B = {} ==> card (A Un B) = card A + card B"
 | 
|
| 24853 | 1971  | 
by (simp add: card_Un_Int)  | 
| 12396 | 1972  | 
|
1973  | 
lemma card_Diff_subset:  | 
|
| 15402 | 1974  | 
"finite B ==> B <= A ==> card (A - B) = card A - card B"  | 
1975  | 
by(simp add:card_def setsum_diff_nat)  | 
|
| 12396 | 1976  | 
|
1977  | 
lemma card_Diff1_less: "finite A ==> x: A ==> card (A - {x}) < card A"
 | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1978  | 
apply (rule Suc_less_SucD)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1979  | 
apply (simp add: card_Suc_Diff1 del:card_Diff_insert)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1980  | 
done  | 
| 12396 | 1981  | 
|
1982  | 
lemma card_Diff2_less:  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1983  | 
  "finite A ==> x: A ==> y: A ==> card (A - {x} - {y}) < card A"
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1984  | 
apply (case_tac "x = y")  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1985  | 
apply (simp add: card_Diff1_less del:card_Diff_insert)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1986  | 
apply (rule less_trans)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1987  | 
prefer 2 apply (auto intro!: card_Diff1_less simp del:card_Diff_insert)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1988  | 
done  | 
| 12396 | 1989  | 
|
1990  | 
lemma card_Diff1_le: "finite A ==> card (A - {x}) <= card A"
 | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1991  | 
apply (case_tac "x : A")  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1992  | 
apply (simp_all add: card_Diff1_less less_imp_le)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
1993  | 
done  | 
| 12396 | 1994  | 
|
1995  | 
lemma card_psubset: "finite B ==> A \<subseteq> B ==> card A < card B ==> A < B"  | 
|
| 14208 | 1996  | 
by (erule psubsetI, blast)  | 
| 12396 | 1997  | 
|
| 14889 | 1998  | 
lemma insert_partition:  | 
| 15402 | 1999  | 
  "\<lbrakk> x \<notin> F; \<forall>c1 \<in> insert x F. \<forall>c2 \<in> insert x F. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {} \<rbrakk>
 | 
2000  | 
  \<Longrightarrow> x \<inter> \<Union> F = {}"
 | 
|
| 14889 | 2001  | 
by auto  | 
2002  | 
||
| 19793 | 2003  | 
text{* main cardinality theorem *}
 | 
| 14889 | 2004  | 
lemma card_partition [rule_format]:  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2005  | 
"finite C ==>  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2006  | 
finite (\<Union> C) -->  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2007  | 
(\<forall>c\<in>C. card c = k) -->  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2008  | 
     (\<forall>c1 \<in> C. \<forall>c2 \<in> C. c1 \<noteq> c2 --> c1 \<inter> c2 = {}) -->
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2009  | 
k * card(C) = card (\<Union> C)"  | 
| 14889 | 2010  | 
apply (erule finite_induct, simp)  | 
2011  | 
apply (simp add: card_insert_disjoint card_Un_disjoint insert_partition  | 
|
2012  | 
finite_subset [of _ "\<Union> (insert x F)"])  | 
|
2013  | 
done  | 
|
2014  | 
||
| 12396 | 2015  | 
|
| 19793 | 2016  | 
text{*The form of a finite set of given cardinality*}
 | 
2017  | 
||
2018  | 
lemma card_eq_SucD:  | 
|
| 24853 | 2019  | 
assumes "card A = Suc k"  | 
2020  | 
shows "\<exists>b B. A = insert b B & b \<notin> B & card B = k & (k=0 \<longrightarrow> B={})"
 | 
|
| 19793 | 2021  | 
proof -  | 
| 24853 | 2022  | 
have fin: "finite A" using assms by (auto intro: ccontr)  | 
2023  | 
moreover have "card A \<noteq> 0" using assms by auto  | 
|
2024  | 
ultimately obtain b where b: "b \<in> A" by auto  | 
|
| 19793 | 2025  | 
show ?thesis  | 
2026  | 
proof (intro exI conjI)  | 
|
2027  | 
    show "A = insert b (A-{b})" using b by blast
 | 
|
2028  | 
    show "b \<notin> A - {b}" by blast
 | 
|
| 24853 | 2029  | 
    show "card (A - {b}) = k" and "k = 0 \<longrightarrow> A - {b} = {}"
 | 
2030  | 
using assms b fin by(fastsimp dest:mk_disjoint_insert)+  | 
|
| 19793 | 2031  | 
qed  | 
2032  | 
qed  | 
|
2033  | 
||
2034  | 
lemma card_Suc_eq:  | 
|
| 24853 | 2035  | 
"(card A = Suc k) =  | 
2036  | 
   (\<exists>b B. A = insert b B & b \<notin> B & card B = k & (k=0 \<longrightarrow> B={}))"
 | 
|
2037  | 
apply(rule iffI)  | 
|
2038  | 
apply(erule card_eq_SucD)  | 
|
2039  | 
apply(auto)  | 
|
2040  | 
apply(subst card_insert)  | 
|
2041  | 
apply(auto intro:ccontr)  | 
|
2042  | 
done  | 
|
| 19793 | 2043  | 
|
| 15539 | 2044  | 
lemma setsum_constant [simp]: "(\<Sum>x \<in> A. y) = of_nat(card A) * y"  | 
2045  | 
apply (cases "finite A")  | 
|
2046  | 
apply (erule finite_induct)  | 
|
| 29667 | 2047  | 
apply (auto simp add: algebra_simps)  | 
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
2048  | 
done  | 
| 15402 | 2049  | 
|
| 
21199
 
2d83f93c3580
* Added annihilation axioms ("x * 0 = 0") to axclass semiring_0.
 
krauss 
parents: 
19984 
diff
changeset
 | 
2050  | 
lemma setprod_constant: "finite A ==> (\<Prod>x\<in> A. (y::'a::{recpower, comm_monoid_mult})) = y^(card A)"
 | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2051  | 
apply (erule finite_induct)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2052  | 
apply (auto simp add: power_Suc)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2053  | 
done  | 
| 15402 | 2054  | 
|
| 
29674
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2055  | 
lemma setprod_gen_delta:  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2056  | 
assumes fS: "finite S"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2057  | 
  shows "setprod (\<lambda>k. if k=a then b k else c) S = (if a \<in> S then (b a ::'a::{comm_monoid_mult, recpower}) * c^ (card S - 1) else c^ card S)"
 | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2058  | 
proof-  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2059  | 
let ?f = "(\<lambda>k. if k=a then b k else c)"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2060  | 
  {assume a: "a \<notin> S"
 | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2061  | 
hence "\<forall> k\<in> S. ?f k = c" by simp  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2062  | 
hence ?thesis using a setprod_constant[OF fS, of c] by (simp add: setprod_1 cong add: setprod_cong) }  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2063  | 
moreover  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2064  | 
  {assume a: "a \<in> S"
 | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2065  | 
    let ?A = "S - {a}"
 | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2066  | 
    let ?B = "{a}"
 | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2067  | 
have eq: "S = ?A \<union> ?B" using a by blast  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2068  | 
    have dj: "?A \<inter> ?B = {}" by simp
 | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2069  | 
from fS have fAB: "finite ?A" "finite ?B" by auto  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2070  | 
have fA0:"setprod ?f ?A = setprod (\<lambda>i. c) ?A"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2071  | 
apply (rule setprod_cong) by auto  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2072  | 
have cA: "card ?A = card S - 1" using fS a by auto  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2073  | 
have fA1: "setprod ?f ?A = c ^ card ?A" unfolding fA0 apply (rule setprod_constant) using fS by auto  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2074  | 
have "setprod ?f ?A * setprod ?f ?B = setprod ?f S"  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2075  | 
using setprod_Un_disjoint[OF fAB dj, of ?f, unfolded eq[symmetric]]  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2076  | 
by simp  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2077  | 
then have ?thesis using a cA  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2078  | 
by (simp add: fA1 ring_simps cong add: setprod_cong cong del: if_weak_cong)}  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2079  | 
ultimately show ?thesis by blast  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2080  | 
qed  | 
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2081  | 
|
| 
 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 
chaieb 
parents: 
29609 
diff
changeset
 | 
2082  | 
|
| 15542 | 2083  | 
lemma setsum_bounded:  | 
| 23277 | 2084  | 
  assumes le: "\<And>i. i\<in>A \<Longrightarrow> f i \<le> (K::'a::{semiring_1, pordered_ab_semigroup_add})"
 | 
| 15542 | 2085  | 
shows "setsum f A \<le> of_nat(card A) * K"  | 
2086  | 
proof (cases "finite A")  | 
|
2087  | 
case True  | 
|
2088  | 
thus ?thesis using le setsum_mono[where K=A and g = "%x. K"] by simp  | 
|
2089  | 
next  | 
|
2090  | 
case False thus ?thesis by (simp add: setsum_def)  | 
|
2091  | 
qed  | 
|
2092  | 
||
| 15402 | 2093  | 
|
2094  | 
subsubsection {* Cardinality of unions *}
 | 
|
2095  | 
||
2096  | 
lemma card_UN_disjoint:  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2097  | 
"finite I ==> (ALL i:I. finite (A i)) ==>  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2098  | 
   (ALL i:I. ALL j:I. i \<noteq> j --> A i Int A j = {})
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2099  | 
==> card (UNION I A) = (\<Sum>i\<in>I. card(A i))"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2100  | 
apply (simp add: card_def del: setsum_constant)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2101  | 
apply (subgoal_tac  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2102  | 
"setsum (%i. card (A i)) I = setsum (%i. (setsum (%x. 1) (A i))) I")  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2103  | 
apply (simp add: setsum_UN_disjoint del: setsum_constant)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2104  | 
apply (simp cong: setsum_cong)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2105  | 
done  | 
| 15402 | 2106  | 
|
2107  | 
lemma card_Union_disjoint:  | 
|
2108  | 
"finite C ==> (ALL A:C. finite A) ==>  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2109  | 
   (ALL A:C. ALL B:C. A \<noteq> B --> A Int B = {})
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2110  | 
==> card (Union C) = setsum card C"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2111  | 
apply (frule card_UN_disjoint [of C id])  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2112  | 
apply (unfold Union_def id_def, assumption+)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2113  | 
done  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2114  | 
|
| 15402 | 2115  | 
|
| 12396 | 2116  | 
subsubsection {* Cardinality of image *}
 | 
2117  | 
||
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2118  | 
text{*The image of a finite set can be expressed using @{term fold_image}.*}
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2119  | 
lemma image_eq_fold_image:  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2120  | 
  "finite A ==> f ` A = fold_image (op Un) (%x. {f x}) {} A"
 | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2121  | 
proof (induct rule: finite_induct)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2122  | 
case empty then show ?case by simp  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2123  | 
next  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2124  | 
interpret ab_semigroup_mult "op Un"  | 
| 28823 | 2125  | 
proof qed auto  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2126  | 
case insert  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2127  | 
then show ?case by simp  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2128  | 
qed  | 
| 15447 | 2129  | 
|
| 12396 | 2130  | 
lemma card_image_le: "finite A ==> card (f ` A) <= card A"  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2131  | 
apply (induct set: finite)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2132  | 
apply simp  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2133  | 
apply (simp add: le_SucI finite_imageI card_insert_if)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2134  | 
done  | 
| 12396 | 2135  | 
|
| 15402 | 2136  | 
lemma card_image: "inj_on f A ==> card (f ` A) = card A"  | 
| 15539 | 2137  | 
by(simp add:card_def setsum_reindex o_def del:setsum_constant)  | 
| 12396 | 2138  | 
|
2139  | 
lemma endo_inj_surj: "finite A ==> f ` A \<subseteq> A ==> inj_on f A ==> f ` A = A"  | 
|
| 25162 | 2140  | 
by (simp add: card_seteq card_image)  | 
| 12396 | 2141  | 
|
| 15111 | 2142  | 
lemma eq_card_imp_inj_on:  | 
2143  | 
"[| finite A; card(f ` A) = card A |] ==> inj_on f A"  | 
|
| 21575 | 2144  | 
apply (induct rule:finite_induct)  | 
2145  | 
apply simp  | 
|
| 15111 | 2146  | 
apply(frule card_image_le[where f = f])  | 
2147  | 
apply(simp add:card_insert_if split:if_splits)  | 
|
2148  | 
done  | 
|
2149  | 
||
2150  | 
lemma inj_on_iff_eq_card:  | 
|
2151  | 
"finite A ==> inj_on f A = (card(f ` A) = card A)"  | 
|
2152  | 
by(blast intro: card_image eq_card_imp_inj_on)  | 
|
2153  | 
||
| 12396 | 2154  | 
|
| 15402 | 2155  | 
lemma card_inj_on_le:  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2156  | 
"[|inj_on f A; f ` A \<subseteq> B; finite B |] ==> card A \<le> card B"  | 
| 15402 | 2157  | 
apply (subgoal_tac "finite A")  | 
2158  | 
apply (force intro: card_mono simp add: card_image [symmetric])  | 
|
2159  | 
apply (blast intro: finite_imageD dest: finite_subset)  | 
|
2160  | 
done  | 
|
2161  | 
||
2162  | 
lemma card_bij_eq:  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2163  | 
"[|inj_on f A; f ` A \<subseteq> B; inj_on g B; g ` B \<subseteq> A;  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2164  | 
finite A; finite B |] ==> card A = card B"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2165  | 
by (auto intro: le_anti_sym card_inj_on_le)  | 
| 15402 | 2166  | 
|
2167  | 
||
2168  | 
subsubsection {* Cardinality of products *}
 | 
|
2169  | 
||
2170  | 
(*  | 
|
2171  | 
lemma SigmaI_insert: "y \<notin> A ==>  | 
|
2172  | 
  (SIGMA x:(insert y A). B x) = (({y} <*> (B y)) \<union> (SIGMA x: A. B x))"
 | 
|
2173  | 
by auto  | 
|
2174  | 
*)  | 
|
2175  | 
||
2176  | 
lemma card_SigmaI [simp]:  | 
|
2177  | 
"\<lbrakk> finite A; ALL a:A. finite (B a) \<rbrakk>  | 
|
2178  | 
\<Longrightarrow> card (SIGMA x: A. B x) = (\<Sum>a\<in>A. card (B a))"  | 
|
| 15539 | 2179  | 
by(simp add:card_def setsum_Sigma del:setsum_constant)  | 
| 15402 | 2180  | 
|
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
2181  | 
lemma card_cartesian_product: "card (A <*> B) = card(A) * card(B)"  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
2182  | 
apply (cases "finite A")  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
2183  | 
apply (cases "finite B")  | 
| 
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
2184  | 
apply (auto simp add: card_eq_0_iff  | 
| 15539 | 2185  | 
dest: finite_cartesian_productD1 finite_cartesian_productD2)  | 
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
2186  | 
done  | 
| 15402 | 2187  | 
|
2188  | 
lemma card_cartesian_product_singleton:  "card({x} <*> A) = card(A)"
 | 
|
| 15539 | 2189  | 
by (simp add: card_cartesian_product)  | 
| 
15409
 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 
paulson 
parents: 
15402 
diff
changeset
 | 
2190  | 
|
| 15402 | 2191  | 
|
| 
29025
 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 
huffman 
parents: 
28853 
diff
changeset
 | 
2192  | 
subsubsection {* Cardinality of sums *}
 | 
| 
 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 
huffman 
parents: 
28853 
diff
changeset
 | 
2193  | 
|
| 
 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 
huffman 
parents: 
28853 
diff
changeset
 | 
2194  | 
lemma card_Plus:  | 
| 
 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 
huffman 
parents: 
28853 
diff
changeset
 | 
2195  | 
assumes "finite A" and "finite B"  | 
| 
 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 
huffman 
parents: 
28853 
diff
changeset
 | 
2196  | 
shows "card (A <+> B) = card A + card B"  | 
| 
 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 
huffman 
parents: 
28853 
diff
changeset
 | 
2197  | 
proof -  | 
| 
 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 
huffman 
parents: 
28853 
diff
changeset
 | 
2198  | 
  have "Inl`A \<inter> Inr`B = {}" by fast
 | 
| 
 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 
huffman 
parents: 
28853 
diff
changeset
 | 
2199  | 
with assms show ?thesis  | 
| 
 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 
huffman 
parents: 
28853 
diff
changeset
 | 
2200  | 
unfolding Plus_def  | 
| 
 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 
huffman 
parents: 
28853 
diff
changeset
 | 
2201  | 
by (simp add: card_Un_disjoint card_image)  | 
| 
 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 
huffman 
parents: 
28853 
diff
changeset
 | 
2202  | 
qed  | 
| 
 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 
huffman 
parents: 
28853 
diff
changeset
 | 
2203  | 
|
| 15402 | 2204  | 
|
| 12396 | 2205  | 
subsubsection {* Cardinality of the Powerset *}
 | 
2206  | 
||
2207  | 
lemma card_Pow: "finite A ==> card (Pow A) = Suc (Suc 0) ^ card A" (* FIXME numeral 2 (!?) *)  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2208  | 
apply (induct set: finite)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2209  | 
apply (simp_all add: Pow_insert)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2210  | 
apply (subst card_Un_disjoint, blast)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2211  | 
apply (blast intro: finite_imageI, blast)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2212  | 
apply (subgoal_tac "inj_on (insert x) (Pow F)")  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2213  | 
apply (simp add: card_image Pow_insert)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2214  | 
apply (unfold inj_on_def)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2215  | 
apply (blast elim!: equalityE)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2216  | 
done  | 
| 12396 | 2217  | 
|
| 24342 | 2218  | 
text {* Relates to equivalence classes.  Based on a theorem of F. Kammüller.  *}
 | 
| 12396 | 2219  | 
|
2220  | 
lemma dvd_partition:  | 
|
| 15392 | 2221  | 
"finite (Union C) ==>  | 
| 12396 | 2222  | 
ALL c : C. k dvd card c ==>  | 
| 
14430
 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 
paulson 
parents: 
14331 
diff
changeset
 | 
2223  | 
    (ALL c1: C. ALL c2: C. c1 \<noteq> c2 --> c1 Int c2 = {}) ==>
 | 
| 12396 | 2224  | 
k dvd card (Union C)"  | 
| 15392 | 2225  | 
apply(frule finite_UnionD)  | 
2226  | 
apply(rotate_tac -1)  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2227  | 
apply (induct set: finite, simp_all, clarify)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2228  | 
apply (subst card_Un_disjoint)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2229  | 
apply (auto simp add: dvd_add disjoint_eq_subset_Compl)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2230  | 
done  | 
| 12396 | 2231  | 
|
2232  | 
||
| 25162 | 2233  | 
subsubsection {* Relating injectivity and surjectivity *}
 | 
2234  | 
||
2235  | 
lemma finite_surj_inj: "finite(A) \<Longrightarrow> A <= f`A \<Longrightarrow> inj_on f A"  | 
|
2236  | 
apply(rule eq_card_imp_inj_on, assumption)  | 
|
2237  | 
apply(frule finite_imageI)  | 
|
2238  | 
apply(drule (1) card_seteq)  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2239  | 
apply(erule card_image_le)  | 
| 25162 | 2240  | 
apply simp  | 
2241  | 
done  | 
|
2242  | 
||
2243  | 
lemma finite_UNIV_surj_inj: fixes f :: "'a \<Rightarrow> 'a"  | 
|
2244  | 
shows "finite(UNIV:: 'a set) \<Longrightarrow> surj f \<Longrightarrow> inj f"  | 
|
2245  | 
by (blast intro: finite_surj_inj subset_UNIV dest:surj_range)  | 
|
2246  | 
||
2247  | 
lemma finite_UNIV_inj_surj: fixes f :: "'a \<Rightarrow> 'a"  | 
|
2248  | 
shows "finite(UNIV:: 'a set) \<Longrightarrow> inj f \<Longrightarrow> surj f"  | 
|
2249  | 
by(fastsimp simp:surj_def dest!: endo_inj_surj)  | 
|
2250  | 
||
2251  | 
corollary infinite_UNIV_nat: "~finite(UNIV::nat set)"  | 
|
2252  | 
proof  | 
|
2253  | 
assume "finite(UNIV::nat set)"  | 
|
2254  | 
with finite_UNIV_inj_surj[of Suc]  | 
|
2255  | 
show False by simp (blast dest: Suc_neq_Zero surjD)  | 
|
2256  | 
qed  | 
|
2257  | 
||
| 29879 | 2258  | 
lemma infinite_UNIV_char_0:  | 
2259  | 
"\<not> finite (UNIV::'a::semiring_char_0 set)"  | 
|
2260  | 
proof  | 
|
2261  | 
assume "finite (UNIV::'a set)"  | 
|
2262  | 
with subset_UNIV have "finite (range of_nat::'a set)"  | 
|
2263  | 
by (rule finite_subset)  | 
|
2264  | 
moreover have "inj (of_nat::nat \<Rightarrow> 'a)"  | 
|
2265  | 
by (simp add: inj_on_def)  | 
|
2266  | 
ultimately have "finite (UNIV::nat set)"  | 
|
2267  | 
by (rule finite_imageD)  | 
|
2268  | 
then show "False"  | 
|
2269  | 
by (simp add: infinite_UNIV_nat)  | 
|
2270  | 
qed  | 
|
| 25162 | 2271  | 
|
| 15392 | 2272  | 
subsection{* A fold functional for non-empty sets *}
 | 
2273  | 
||
2274  | 
text{* Does not require start value. *}
 | 
|
| 12396 | 2275  | 
|
| 23736 | 2276  | 
inductive  | 
| 22262 | 2277  | 
  fold1Set :: "('a => 'a => 'a) => 'a set => 'a => bool"
 | 
2278  | 
for f :: "'a => 'a => 'a"  | 
|
2279  | 
where  | 
|
| 15506 | 2280  | 
fold1Set_insertI [intro]:  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2281  | 
"\<lbrakk> fold_graph f a A x; a \<notin> A \<rbrakk> \<Longrightarrow> fold1Set f (insert a A) x"  | 
| 12396 | 2282  | 
|
| 15392 | 2283  | 
constdefs  | 
2284  | 
  fold1 :: "('a => 'a => 'a) => 'a set => 'a"
 | 
|
| 22262 | 2285  | 
"fold1 f A == THE x. fold1Set f A x"  | 
| 15506 | 2286  | 
|
2287  | 
lemma fold1Set_nonempty:  | 
|
| 22917 | 2288  | 
  "fold1Set f A x \<Longrightarrow> A \<noteq> {}"
 | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2289  | 
by(erule fold1Set.cases, simp_all)  | 
| 15392 | 2290  | 
|
| 23736 | 2291  | 
inductive_cases empty_fold1SetE [elim!]: "fold1Set f {} x"
 | 
2292  | 
||
2293  | 
inductive_cases insert_fold1SetE [elim!]: "fold1Set f (insert a X) x"  | 
|
| 22262 | 2294  | 
|
2295  | 
||
2296  | 
lemma fold1Set_sing [iff]: "(fold1Set f {a} b) = (a = b)"
 | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2297  | 
by (blast intro: fold_graph.intros elim: fold_graph.cases)  | 
| 15392 | 2298  | 
|
| 22917 | 2299  | 
lemma fold1_singleton [simp]: "fold1 f {a} = a"
 | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2300  | 
by (unfold fold1_def) blast  | 
| 12396 | 2301  | 
|
| 15508 | 2302  | 
lemma finite_nonempty_imp_fold1Set:  | 
| 22262 | 2303  | 
  "\<lbrakk> finite A; A \<noteq> {} \<rbrakk> \<Longrightarrow> EX x. fold1Set f A x"
 | 
| 15508 | 2304  | 
apply (induct A rule: finite_induct)  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2305  | 
apply (auto dest: finite_imp_fold_graph [of _ f])  | 
| 15508 | 2306  | 
done  | 
| 15506 | 2307  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2308  | 
text{*First, some lemmas about @{const fold_graph}.*}
 | 
| 15392 | 2309  | 
|
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2310  | 
context ab_semigroup_mult  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2311  | 
begin  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2312  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2313  | 
lemma fun_left_comm: "fun_left_comm(op *)"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2314  | 
by unfold_locales (simp add: mult_ac)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2315  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2316  | 
lemma fold_graph_insert_swap:  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2317  | 
assumes fold: "fold_graph times (b::'a) A y" and "b \<notin> A"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2318  | 
shows "fold_graph times z (insert b A) (z * y)"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2319  | 
proof -  | 
| 29223 | 2320  | 
interpret fun_left_comm "op *::'a \<Rightarrow> 'a \<Rightarrow> 'a" by (rule fun_left_comm)  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2321  | 
from assms show ?thesis  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2322  | 
proof (induct rule: fold_graph.induct)  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2323  | 
case emptyI thus ?case by (force simp add: fold_insert_aux mult_commute)  | 
| 15508 | 2324  | 
next  | 
| 22262 | 2325  | 
case (insertI x A y)  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2326  | 
have "fold_graph times z (insert x (insert b A)) (x * (z * y))"  | 
| 15521 | 2327  | 
      using insertI by force  --{*how does @{term id} get unfolded?*}
 | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2328  | 
thus ?case by (simp add: insert_commute mult_ac)  | 
| 15508 | 2329  | 
qed  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2330  | 
qed  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2331  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2332  | 
lemma fold_graph_permute_diff:  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2333  | 
assumes fold: "fold_graph times b A x"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2334  | 
shows "!!a. \<lbrakk>a \<in> A; b \<notin> A\<rbrakk> \<Longrightarrow> fold_graph times a (insert b (A-{a})) x"
 | 
| 15508 | 2335  | 
using fold  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2336  | 
proof (induct rule: fold_graph.induct)  | 
| 15508 | 2337  | 
case emptyI thus ?case by simp  | 
2338  | 
next  | 
|
| 22262 | 2339  | 
case (insertI x A y)  | 
| 15521 | 2340  | 
have "a = x \<or> a \<in> A" using insertI by simp  | 
2341  | 
thus ?case  | 
|
2342  | 
proof  | 
|
2343  | 
assume "a = x"  | 
|
2344  | 
with insertI show ?thesis  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2345  | 
by (simp add: id_def [symmetric], blast intro: fold_graph_insert_swap)  | 
| 15521 | 2346  | 
next  | 
2347  | 
assume ainA: "a \<in> A"  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2348  | 
    hence "fold_graph times a (insert x (insert b (A - {a}))) (x * y)"
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2349  | 
using insertI by force  | 
| 15521 | 2350  | 
moreover  | 
2351  | 
    have "insert x (insert b (A - {a})) = insert b (insert x A - {a})"
 | 
|
2352  | 
using ainA insertI by blast  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2353  | 
ultimately show ?thesis by simp  | 
| 15508 | 2354  | 
qed  | 
2355  | 
qed  | 
|
2356  | 
||
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2357  | 
lemma fold1_eq_fold:  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2358  | 
assumes "finite A" "a \<notin> A" shows "fold1 times (insert a A) = fold times a A"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2359  | 
proof -  | 
| 29223 | 2360  | 
interpret fun_left_comm "op *::'a \<Rightarrow> 'a \<Rightarrow> 'a" by (rule fun_left_comm)  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2361  | 
from assms show ?thesis  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2362  | 
apply (simp add: fold1_def fold_def)  | 
| 15508 | 2363  | 
apply (rule the_equality)  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2364  | 
apply (best intro: fold_graph_determ theI dest: finite_imp_fold_graph [of _ times])  | 
| 15508 | 2365  | 
apply (rule sym, clarify)  | 
2366  | 
apply (case_tac "Aa=A")  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2367  | 
apply (best intro: the_equality fold_graph_determ)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2368  | 
apply (subgoal_tac "fold_graph times a A x")  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2369  | 
apply (best intro: the_equality fold_graph_determ)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2370  | 
apply (subgoal_tac "insert aa (Aa - {a}) = A")
 | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2371  | 
prefer 2 apply (blast elim: equalityE)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2372  | 
apply (auto dest: fold_graph_permute_diff [where a=a])  | 
| 15508 | 2373  | 
done  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2374  | 
qed  | 
| 15508 | 2375  | 
|
| 15521 | 2376  | 
lemma nonempty_iff: "(A \<noteq> {}) = (\<exists>x B. A = insert x B & x \<notin> B)"
 | 
2377  | 
apply safe  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2378  | 
apply simp  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2379  | 
apply (drule_tac x=x in spec)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2380  | 
 apply (drule_tac x="A-{x}" in spec, auto)
 | 
| 15508 | 2381  | 
done  | 
2382  | 
||
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2383  | 
lemma fold1_insert:  | 
| 15521 | 2384  | 
  assumes nonempty: "A \<noteq> {}" and A: "finite A" "x \<notin> A"
 | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2385  | 
shows "fold1 times (insert x A) = x * fold1 times A"  | 
| 15521 | 2386  | 
proof -  | 
| 29223 | 2387  | 
interpret fun_left_comm "op *::'a \<Rightarrow> 'a \<Rightarrow> 'a" by (rule fun_left_comm)  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2388  | 
from nonempty obtain a A' where "A = insert a A' & a ~: A'"  | 
| 15521 | 2389  | 
by (auto simp add: nonempty_iff)  | 
2390  | 
with A show ?thesis  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2391  | 
by (simp add: insert_commute [of x] fold1_eq_fold eq_commute)  | 
| 15521 | 2392  | 
qed  | 
2393  | 
||
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2394  | 
end  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2395  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2396  | 
context ab_semigroup_idem_mult  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2397  | 
begin  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2398  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2399  | 
lemma fun_left_comm_idem: "fun_left_comm_idem(op *)"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2400  | 
apply unfold_locales  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2401  | 
apply (simp add: mult_ac)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2402  | 
apply (simp add: mult_idem mult_assoc[symmetric])  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2403  | 
done  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2404  | 
|
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2405  | 
|
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2406  | 
lemma fold1_insert_idem [simp]:  | 
| 15521 | 2407  | 
  assumes nonempty: "A \<noteq> {}" and A: "finite A" 
 | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2408  | 
shows "fold1 times (insert x A) = x * fold1 times A"  | 
| 15521 | 2409  | 
proof -  | 
| 29223 | 2410  | 
interpret fun_left_comm_idem "op *::'a \<Rightarrow> 'a \<Rightarrow> 'a"  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2411  | 
by (rule fun_left_comm_idem)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2412  | 
from nonempty obtain a A' where A': "A = insert a A' & a ~: A'"  | 
| 15521 | 2413  | 
by (auto simp add: nonempty_iff)  | 
2414  | 
show ?thesis  | 
|
2415  | 
proof cases  | 
|
2416  | 
assume "a = x"  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2417  | 
thus ?thesis  | 
| 15521 | 2418  | 
proof cases  | 
2419  | 
      assume "A' = {}"
 | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2420  | 
with prems show ?thesis by (simp add: mult_idem)  | 
| 15521 | 2421  | 
next  | 
2422  | 
      assume "A' \<noteq> {}"
 | 
|
2423  | 
with prems show ?thesis  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2424  | 
by (simp add: fold1_insert mult_assoc [symmetric] mult_idem)  | 
| 15521 | 2425  | 
qed  | 
2426  | 
next  | 
|
2427  | 
assume "a \<noteq> x"  | 
|
2428  | 
with prems show ?thesis  | 
|
2429  | 
by (simp add: insert_commute fold1_eq_fold fold_insert_idem)  | 
|
2430  | 
qed  | 
|
2431  | 
qed  | 
|
| 15506 | 2432  | 
|
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2433  | 
lemma hom_fold1_commute:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2434  | 
assumes hom: "!!x y. h (x * y) = h x * h y"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2435  | 
and N: "finite N" "N \<noteq> {}" shows "h (fold1 times N) = fold1 times (h ` N)"
 | 
| 22917 | 2436  | 
using N proof (induct rule: finite_ne_induct)  | 
2437  | 
case singleton thus ?case by simp  | 
|
2438  | 
next  | 
|
2439  | 
case (insert n N)  | 
|
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2440  | 
then have "h (fold1 times (insert n N)) = h (n * fold1 times N)" by simp  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2441  | 
also have "\<dots> = h n * h (fold1 times N)" by(rule hom)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2442  | 
also have "h (fold1 times N) = fold1 times (h ` N)" by(rule insert)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2443  | 
also have "times (h n) \<dots> = fold1 times (insert (h n) (h ` N))"  | 
| 22917 | 2444  | 
using insert by(simp)  | 
2445  | 
also have "insert (h n) (h ` N) = h ` insert n N" by simp  | 
|
2446  | 
finally show ?case .  | 
|
2447  | 
qed  | 
|
2448  | 
||
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2449  | 
end  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2450  | 
|
| 15506 | 2451  | 
|
| 15508 | 2452  | 
text{* Now the recursion rules for definitions: *}
 | 
2453  | 
||
| 22917 | 2454  | 
lemma fold1_singleton_def: "g = fold1 f \<Longrightarrow> g {a} = a"
 | 
| 15508 | 2455  | 
by(simp add:fold1_singleton)  | 
2456  | 
||
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2457  | 
lemma (in ab_semigroup_mult) fold1_insert_def:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2458  | 
  "\<lbrakk> g = fold1 times; finite A; x \<notin> A; A \<noteq> {} \<rbrakk> \<Longrightarrow> g (insert x A) = x * g A"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2459  | 
by (simp add:fold1_insert)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2460  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2461  | 
lemma (in ab_semigroup_idem_mult) fold1_insert_idem_def:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2462  | 
  "\<lbrakk> g = fold1 times; finite A; A \<noteq> {} \<rbrakk> \<Longrightarrow> g (insert x A) = x * g A"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2463  | 
by simp  | 
| 15508 | 2464  | 
|
2465  | 
subsubsection{* Determinacy for @{term fold1Set} *}
 | 
|
2466  | 
||
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2467  | 
(*Not actually used!!*)  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2468  | 
(*  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2469  | 
context ab_semigroup_mult  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2470  | 
begin  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2471  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2472  | 
lemma fold_graph_permute:  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2473  | 
"[|fold_graph times id b (insert a A) x; a \<notin> A; b \<notin> A|]  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2474  | 
==> fold_graph times id a (insert b A) x"  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2475  | 
apply (cases "a=b")  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2476  | 
apply (auto dest: fold_graph_permute_diff)  | 
| 15506 | 2477  | 
done  | 
| 15376 | 2478  | 
|
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2479  | 
lemma fold1Set_determ:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2480  | 
"fold1Set times A x ==> fold1Set times A y ==> y = x"  | 
| 15506 | 2481  | 
proof (clarify elim!: fold1Set.cases)  | 
2482  | 
fix A x B y a b  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2483  | 
assume Ax: "fold_graph times id a A x"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2484  | 
assume By: "fold_graph times id b B y"  | 
| 15506 | 2485  | 
assume anotA: "a \<notin> A"  | 
2486  | 
assume bnotB: "b \<notin> B"  | 
|
2487  | 
assume eq: "insert a A = insert b B"  | 
|
2488  | 
show "y=x"  | 
|
2489  | 
proof cases  | 
|
2490  | 
assume same: "a=b"  | 
|
2491  | 
hence "A=B" using anotA bnotB eq by (blast elim!: equalityE)  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2492  | 
thus ?thesis using Ax By same by (blast intro: fold_graph_determ)  | 
| 15392 | 2493  | 
next  | 
| 15506 | 2494  | 
assume diff: "a\<noteq>b"  | 
2495  | 
    let ?D = "B - {a}"
 | 
|
2496  | 
have B: "B = insert a ?D" and A: "A = insert b ?D"  | 
|
2497  | 
and aB: "a \<in> B" and bA: "b \<in> A"  | 
|
2498  | 
using eq anotA bnotB diff by (blast elim!:equalityE)+  | 
|
2499  | 
with aB bnotB By  | 
|
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2500  | 
have "fold_graph times id a (insert b ?D) y"  | 
| 
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2501  | 
by (auto intro: fold_graph_permute simp add: insert_absorb)  | 
| 15506 | 2502  | 
moreover  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2503  | 
have "fold_graph times id a (insert b ?D) x"  | 
| 15506 | 2504  | 
by (simp add: A [symmetric] Ax)  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2505  | 
ultimately show ?thesis by (blast intro: fold_graph_determ)  | 
| 15392 | 2506  | 
qed  | 
| 12396 | 2507  | 
qed  | 
2508  | 
||
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2509  | 
lemma fold1Set_equality: "fold1Set times A y ==> fold1 times A = y"  | 
| 15506 | 2510  | 
by (unfold fold1_def) (blast intro: fold1Set_determ)  | 
2511  | 
||
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2512  | 
end  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2513  | 
*)  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2514  | 
|
| 15506 | 2515  | 
declare  | 
| 
28853
 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 
nipkow 
parents: 
28823 
diff
changeset
 | 
2516  | 
empty_fold_graphE [rule del] fold_graph.intros [rule del]  | 
| 15506 | 2517  | 
empty_fold1SetE [rule del] insert_fold1SetE [rule del]  | 
| 
19931
 
fb32b43e7f80
Restructured locales with predicates: import is now an interpretation.
 
ballarin 
parents: 
19870 
diff
changeset
 | 
2518  | 
  -- {* No more proofs involve these relations. *}
 | 
| 15376 | 2519  | 
|
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2520  | 
subsubsection {* Lemmas about @{text fold1} *}
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2521  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2522  | 
context ab_semigroup_mult  | 
| 22917 | 2523  | 
begin  | 
2524  | 
||
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2525  | 
lemma fold1_Un:  | 
| 15484 | 2526  | 
assumes A: "finite A" "A \<noteq> {}"
 | 
2527  | 
shows "finite B \<Longrightarrow> B \<noteq> {} \<Longrightarrow> A Int B = {} \<Longrightarrow>
 | 
|
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2528  | 
fold1 times (A Un B) = fold1 times A * fold1 times B"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2529  | 
using A by (induct rule: finite_ne_induct)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2530  | 
(simp_all add: fold1_insert mult_assoc)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2531  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2532  | 
lemma fold1_in:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2533  | 
  assumes A: "finite (A)" "A \<noteq> {}" and elem: "\<And>x y. x * y \<in> {x,y}"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2534  | 
shows "fold1 times A \<in> A"  | 
| 15484 | 2535  | 
using A  | 
2536  | 
proof (induct rule:finite_ne_induct)  | 
|
| 15506 | 2537  | 
case singleton thus ?case by simp  | 
| 15484 | 2538  | 
next  | 
2539  | 
case insert thus ?case using elem by (force simp add:fold1_insert)  | 
|
2540  | 
qed  | 
|
2541  | 
||
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2542  | 
end  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2543  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2544  | 
lemma (in ab_semigroup_idem_mult) fold1_Un2:  | 
| 
15497
 
53bca254719a
Added semi-lattice locales and reorganized fold1 lemmas
 
nipkow 
parents: 
15487 
diff
changeset
 | 
2545  | 
assumes A: "finite A" "A \<noteq> {}"
 | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2546  | 
shows "finite B \<Longrightarrow> B \<noteq> {} \<Longrightarrow>
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2547  | 
fold1 times (A Un B) = fold1 times A * fold1 times B"  | 
| 
15497
 
53bca254719a
Added semi-lattice locales and reorganized fold1 lemmas
 
nipkow 
parents: 
15487 
diff
changeset
 | 
2548  | 
using A  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2549  | 
proof(induct rule:finite_ne_induct)  | 
| 
15497
 
53bca254719a
Added semi-lattice locales and reorganized fold1 lemmas
 
nipkow 
parents: 
15487 
diff
changeset
 | 
2550  | 
case singleton thus ?case by simp  | 
| 15484 | 2551  | 
next  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2552  | 
case insert thus ?case by (simp add: mult_assoc)  | 
| 18423 | 2553  | 
qed  | 
2554  | 
||
2555  | 
||
| 22917 | 2556  | 
subsubsection {* Fold1 in lattices with @{const inf} and @{const sup} *}
 | 
2557  | 
||
2558  | 
text{*
 | 
|
2559  | 
  As an application of @{text fold1} we define infimum
 | 
|
2560  | 
and supremum in (not necessarily complete!) lattices  | 
|
2561  | 
  over (non-empty) sets by means of @{text fold1}.
 | 
|
2562  | 
*}  | 
|
2563  | 
||
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2564  | 
context lower_semilattice  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2565  | 
begin  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2566  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2567  | 
lemma ab_semigroup_idem_mult_inf:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2568  | 
"ab_semigroup_idem_mult inf"  | 
| 28823 | 2569  | 
proof qed (rule inf_assoc inf_commute inf_idem)+  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2570  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2571  | 
lemma below_fold1_iff:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2572  | 
  assumes "finite A" "A \<noteq> {}"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2573  | 
shows "x \<le> fold1 inf A \<longleftrightarrow> (\<forall>a\<in>A. x \<le> a)"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2574  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2575  | 
interpret ab_semigroup_idem_mult inf  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2576  | 
by (rule ab_semigroup_idem_mult_inf)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2577  | 
show ?thesis using assms by (induct rule: finite_ne_induct) simp_all  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2578  | 
qed  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2579  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2580  | 
lemma fold1_belowI:  | 
| 
26757
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2581  | 
assumes "finite A"  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2582  | 
and "a \<in> A"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2583  | 
shows "fold1 inf A \<le> a"  | 
| 
26757
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2584  | 
proof -  | 
| 
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2585  | 
  from assms have "A \<noteq> {}" by auto
 | 
| 
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2586  | 
  from `finite A` `A \<noteq> {}` `a \<in> A` show ?thesis
 | 
| 
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2587  | 
proof (induct rule: finite_ne_induct)  | 
| 
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2588  | 
case singleton thus ?case by simp  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2589  | 
next  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2590  | 
interpret ab_semigroup_idem_mult inf  | 
| 
26757
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2591  | 
by (rule ab_semigroup_idem_mult_inf)  | 
| 
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2592  | 
case (insert x F)  | 
| 
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2593  | 
from insert(5) have "a = x \<or> a \<in> F" by simp  | 
| 
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2594  | 
thus ?case  | 
| 
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2595  | 
proof  | 
| 
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2596  | 
assume "a = x" thus ?thesis using insert  | 
| 29667 | 2597  | 
by (simp add: mult_ac)  | 
| 
26757
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2598  | 
next  | 
| 
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2599  | 
assume "a \<in> F"  | 
| 
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2600  | 
hence bel: "fold1 inf F \<le> a" by (rule insert)  | 
| 
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2601  | 
have "inf (fold1 inf (insert x F)) a = inf x (inf (fold1 inf F) a)"  | 
| 29667 | 2602  | 
using insert by (simp add: mult_ac)  | 
| 
26757
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2603  | 
also have "inf (fold1 inf F) a = fold1 inf F"  | 
| 
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2604  | 
using bel by (auto intro: antisym)  | 
| 
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2605  | 
also have "inf x \<dots> = fold1 inf (insert x F)"  | 
| 29667 | 2606  | 
using insert by (simp add: mult_ac)  | 
| 
26757
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2607  | 
finally have aux: "inf (fold1 inf (insert x F)) a = fold1 inf (insert x F)" .  | 
| 
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2608  | 
moreover have "inf (fold1 inf (insert x F)) a \<le> a" by simp  | 
| 
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2609  | 
ultimately show ?thesis by simp  | 
| 
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2610  | 
qed  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2611  | 
qed  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2612  | 
qed  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2613  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2614  | 
end  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2615  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2616  | 
lemma (in upper_semilattice) ab_semigroup_idem_mult_sup:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2617  | 
"ab_semigroup_idem_mult sup"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2618  | 
by (rule lower_semilattice.ab_semigroup_idem_mult_inf)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2619  | 
(rule dual_lattice)  | 
| 15500 | 2620  | 
|
| 24342 | 2621  | 
context lattice  | 
| 22917 | 2622  | 
begin  | 
2623  | 
||
2624  | 
definition  | 
|
| 29966 | 2625  | 
  Inf_fin :: "'a set \<Rightarrow> 'a" ("\<Sqinter>\<^bsub>fin\<^esub>_" [900] 900)
 | 
| 22917 | 2626  | 
where  | 
| 25062 | 2627  | 
"Inf_fin = fold1 inf"  | 
| 22917 | 2628  | 
|
2629  | 
definition  | 
|
| 29966 | 2630  | 
  Sup_fin :: "'a set \<Rightarrow> 'a" ("\<Squnion>\<^bsub>fin\<^esub>_" [900] 900)
 | 
| 22917 | 2631  | 
where  | 
| 25062 | 2632  | 
"Sup_fin = fold1 sup"  | 
2633  | 
||
| 29966 | 2634  | 
lemma Inf_le_Sup [simp]: "\<lbrakk> finite A; A \<noteq> {} \<rbrakk> \<Longrightarrow> \<Sqinter>\<^bsub>fin\<^esub>A \<le> \<Squnion>\<^bsub>fin\<^esub>A"
 | 
| 24342 | 2635  | 
apply(unfold Sup_fin_def Inf_fin_def)  | 
| 15500 | 2636  | 
apply(subgoal_tac "EX a. a:A")  | 
2637  | 
prefer 2 apply blast  | 
|
2638  | 
apply(erule exE)  | 
|
| 22388 | 2639  | 
apply(rule order_trans)  | 
| 
26757
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2640  | 
apply(erule (1) fold1_belowI)  | 
| 
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2641  | 
apply(erule (1) lower_semilattice.fold1_belowI [OF dual_lattice])  | 
| 15500 | 2642  | 
done  | 
2643  | 
||
| 24342 | 2644  | 
lemma sup_Inf_absorb [simp]:  | 
| 29966 | 2645  | 
"finite A \<Longrightarrow> a \<in> A \<Longrightarrow> sup a (\<Sqinter>\<^bsub>fin\<^esub>A) = a"  | 
| 
15512
 
ed1fa4617f52
Extracted generic lattice stuff to new Lattice_Locales.thy
 
nipkow 
parents: 
15510 
diff
changeset
 | 
2646  | 
apply(subst sup_commute)  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2647  | 
apply(simp add: Inf_fin_def sup_absorb2 fold1_belowI)  | 
| 15504 | 2648  | 
done  | 
2649  | 
||
| 24342 | 2650  | 
lemma inf_Sup_absorb [simp]:  | 
| 29966 | 2651  | 
"finite A \<Longrightarrow> a \<in> A \<Longrightarrow> inf a (\<Squnion>\<^bsub>fin\<^esub>A) = a"  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2652  | 
by (simp add: Sup_fin_def inf_absorb1  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2653  | 
lower_semilattice.fold1_belowI [OF dual_lattice])  | 
| 24342 | 2654  | 
|
2655  | 
end  | 
|
2656  | 
||
2657  | 
context distrib_lattice  | 
|
2658  | 
begin  | 
|
2659  | 
||
2660  | 
lemma sup_Inf1_distrib:  | 
|
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2661  | 
assumes "finite A"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2662  | 
    and "A \<noteq> {}"
 | 
| 29966 | 2663  | 
  shows "sup x (\<Sqinter>\<^bsub>fin\<^esub>A) = \<Sqinter>\<^bsub>fin\<^esub>{sup x a|a. a \<in> A}"
 | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2664  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2665  | 
interpret ab_semigroup_idem_mult inf  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2666  | 
by (rule ab_semigroup_idem_mult_inf)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2667  | 
from assms show ?thesis  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2668  | 
by (simp add: Inf_fin_def image_def  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2669  | 
hom_fold1_commute [where h="sup x", OF sup_inf_distrib1])  | 
| 26792 | 2670  | 
(rule arg_cong [where f="fold1 inf"], blast)  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2671  | 
qed  | 
| 18423 | 2672  | 
|
| 24342 | 2673  | 
lemma sup_Inf2_distrib:  | 
2674  | 
  assumes A: "finite A" "A \<noteq> {}" and B: "finite B" "B \<noteq> {}"
 | 
|
| 29966 | 2675  | 
  shows "sup (\<Sqinter>\<^bsub>fin\<^esub>A) (\<Sqinter>\<^bsub>fin\<^esub>B) = \<Sqinter>\<^bsub>fin\<^esub>{sup a b|a b. a \<in> A \<and> b \<in> B}"
 | 
| 24342 | 2676  | 
using A proof (induct rule: finite_ne_induct)  | 
| 15500 | 2677  | 
case singleton thus ?case  | 
| 24342 | 2678  | 
by (simp add: sup_Inf1_distrib [OF B] fold1_singleton_def [OF Inf_fin_def])  | 
| 15500 | 2679  | 
next  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2680  | 
interpret ab_semigroup_idem_mult inf  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2681  | 
by (rule ab_semigroup_idem_mult_inf)  | 
| 15500 | 2682  | 
case (insert x A)  | 
| 25062 | 2683  | 
  have finB: "finite {sup x b |b. b \<in> B}"
 | 
2684  | 
by(rule finite_surj[where f = "sup x", OF B(1)], auto)  | 
|
2685  | 
  have finAB: "finite {sup a b |a b. a \<in> A \<and> b \<in> B}"
 | 
|
| 15500 | 2686  | 
proof -  | 
| 25062 | 2687  | 
    have "{sup a b |a b. a \<in> A \<and> b \<in> B} = (UN a:A. UN b:B. {sup a b})"
 | 
| 15500 | 2688  | 
by blast  | 
| 15517 | 2689  | 
thus ?thesis by(simp add: insert(1) B(1))  | 
| 15500 | 2690  | 
qed  | 
| 25062 | 2691  | 
  have ne: "{sup a b |a b. a \<in> A \<and> b \<in> B} \<noteq> {}" using insert B by blast
 | 
| 29966 | 2692  | 
have "sup (\<Sqinter>\<^bsub>fin\<^esub>(insert x A)) (\<Sqinter>\<^bsub>fin\<^esub>B) = sup (inf x (\<Sqinter>\<^bsub>fin\<^esub>A)) (\<Sqinter>\<^bsub>fin\<^esub>B)"  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2693  | 
using insert by (simp add: fold1_insert_idem_def [OF Inf_fin_def])  | 
| 29966 | 2694  | 
also have "\<dots> = inf (sup x (\<Sqinter>\<^bsub>fin\<^esub>B)) (sup (\<Sqinter>\<^bsub>fin\<^esub>A) (\<Sqinter>\<^bsub>fin\<^esub>B))" by(rule sup_inf_distrib2)  | 
2695  | 
  also have "\<dots> = inf (\<Sqinter>\<^bsub>fin\<^esub>{sup x b|b. b \<in> B}) (\<Sqinter>\<^bsub>fin\<^esub>{sup a b|a b. a \<in> A \<and> b \<in> B})"
 | 
|
| 15500 | 2696  | 
using insert by(simp add:sup_Inf1_distrib[OF B])  | 
| 29966 | 2697  | 
  also have "\<dots> = \<Sqinter>\<^bsub>fin\<^esub>({sup x b |b. b \<in> B} \<union> {sup a b |a b. a \<in> A \<and> b \<in> B})"
 | 
2698  | 
(is "_ = \<Sqinter>\<^bsub>fin\<^esub>?M")  | 
|
| 15500 | 2699  | 
using B insert  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2700  | 
by (simp add: Inf_fin_def fold1_Un2 [OF finB _ finAB ne])  | 
| 25062 | 2701  | 
  also have "?M = {sup a b |a b. a \<in> insert x A \<and> b \<in> B}"
 | 
| 15500 | 2702  | 
by blast  | 
2703  | 
finally show ?case .  | 
|
2704  | 
qed  | 
|
2705  | 
||
| 24342 | 2706  | 
lemma inf_Sup1_distrib:  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2707  | 
  assumes "finite A" and "A \<noteq> {}"
 | 
| 29966 | 2708  | 
  shows "inf x (\<Squnion>\<^bsub>fin\<^esub>A) = \<Squnion>\<^bsub>fin\<^esub>{inf x a|a. a \<in> A}"
 | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2709  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2710  | 
interpret ab_semigroup_idem_mult sup  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2711  | 
by (rule ab_semigroup_idem_mult_sup)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2712  | 
from assms show ?thesis  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2713  | 
by (simp add: Sup_fin_def image_def hom_fold1_commute [where h="inf x", OF inf_sup_distrib1])  | 
| 26792 | 2714  | 
(rule arg_cong [where f="fold1 sup"], blast)  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2715  | 
qed  | 
| 18423 | 2716  | 
|
| 24342 | 2717  | 
lemma inf_Sup2_distrib:  | 
2718  | 
  assumes A: "finite A" "A \<noteq> {}" and B: "finite B" "B \<noteq> {}"
 | 
|
| 29966 | 2719  | 
  shows "inf (\<Squnion>\<^bsub>fin\<^esub>A) (\<Squnion>\<^bsub>fin\<^esub>B) = \<Squnion>\<^bsub>fin\<^esub>{inf a b|a b. a \<in> A \<and> b \<in> B}"
 | 
| 24342 | 2720  | 
using A proof (induct rule: finite_ne_induct)  | 
| 18423 | 2721  | 
case singleton thus ?case  | 
| 24342 | 2722  | 
by(simp add: inf_Sup1_distrib [OF B] fold1_singleton_def [OF Sup_fin_def])  | 
| 18423 | 2723  | 
next  | 
2724  | 
case (insert x A)  | 
|
| 25062 | 2725  | 
  have finB: "finite {inf x b |b. b \<in> B}"
 | 
2726  | 
by(rule finite_surj[where f = "%b. inf x b", OF B(1)], auto)  | 
|
2727  | 
  have finAB: "finite {inf a b |a b. a \<in> A \<and> b \<in> B}"
 | 
|
| 18423 | 2728  | 
proof -  | 
| 25062 | 2729  | 
    have "{inf a b |a b. a \<in> A \<and> b \<in> B} = (UN a:A. UN b:B. {inf a b})"
 | 
| 18423 | 2730  | 
by blast  | 
2731  | 
thus ?thesis by(simp add: insert(1) B(1))  | 
|
2732  | 
qed  | 
|
| 25062 | 2733  | 
  have ne: "{inf a b |a b. a \<in> A \<and> b \<in> B} \<noteq> {}" using insert B by blast
 | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2734  | 
interpret ab_semigroup_idem_mult sup  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2735  | 
by (rule ab_semigroup_idem_mult_sup)  | 
| 29966 | 2736  | 
have "inf (\<Squnion>\<^bsub>fin\<^esub>(insert x A)) (\<Squnion>\<^bsub>fin\<^esub>B) = inf (sup x (\<Squnion>\<^bsub>fin\<^esub>A)) (\<Squnion>\<^bsub>fin\<^esub>B)"  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2737  | 
using insert by (simp add: fold1_insert_idem_def [OF Sup_fin_def])  | 
| 29966 | 2738  | 
also have "\<dots> = sup (inf x (\<Squnion>\<^bsub>fin\<^esub>B)) (inf (\<Squnion>\<^bsub>fin\<^esub>A) (\<Squnion>\<^bsub>fin\<^esub>B))" by(rule inf_sup_distrib2)  | 
2739  | 
  also have "\<dots> = sup (\<Squnion>\<^bsub>fin\<^esub>{inf x b|b. b \<in> B}) (\<Squnion>\<^bsub>fin\<^esub>{inf a b|a b. a \<in> A \<and> b \<in> B})"
 | 
|
| 18423 | 2740  | 
using insert by(simp add:inf_Sup1_distrib[OF B])  | 
| 29966 | 2741  | 
  also have "\<dots> = \<Squnion>\<^bsub>fin\<^esub>({inf x b |b. b \<in> B} \<union> {inf a b |a b. a \<in> A \<and> b \<in> B})"
 | 
2742  | 
(is "_ = \<Squnion>\<^bsub>fin\<^esub>?M")  | 
|
| 18423 | 2743  | 
using B insert  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2744  | 
by (simp add: Sup_fin_def fold1_Un2 [OF finB _ finAB ne])  | 
| 25062 | 2745  | 
  also have "?M = {inf a b |a b. a \<in> insert x A \<and> b \<in> B}"
 | 
| 18423 | 2746  | 
by blast  | 
2747  | 
finally show ?case .  | 
|
2748  | 
qed  | 
|
2749  | 
||
| 24342 | 2750  | 
end  | 
2751  | 
||
2752  | 
context complete_lattice  | 
|
2753  | 
begin  | 
|
2754  | 
||
| 22917 | 2755  | 
text {*
 | 
| 24342 | 2756  | 
Coincidence on finite sets in complete lattices:  | 
| 22917 | 2757  | 
*}  | 
2758  | 
||
| 24342 | 2759  | 
lemma Inf_fin_Inf:  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2760  | 
  assumes "finite A" and "A \<noteq> {}"
 | 
| 29966 | 2761  | 
shows "\<Sqinter>\<^bsub>fin\<^esub>A = Inf A"  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2762  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2763  | 
interpret ab_semigroup_idem_mult inf  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2764  | 
by (rule ab_semigroup_idem_mult_inf)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2765  | 
from assms show ?thesis  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2766  | 
unfolding Inf_fin_def by (induct A set: finite)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2767  | 
(simp_all add: Inf_insert_simp)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2768  | 
qed  | 
| 22917 | 2769  | 
|
| 24342 | 2770  | 
lemma Sup_fin_Sup:  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2771  | 
  assumes "finite A" and "A \<noteq> {}"
 | 
| 29966 | 2772  | 
shows "\<Squnion>\<^bsub>fin\<^esub>A = Sup A"  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2773  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2774  | 
interpret ab_semigroup_idem_mult sup  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2775  | 
by (rule ab_semigroup_idem_mult_sup)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2776  | 
from assms show ?thesis  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2777  | 
unfolding Sup_fin_def by (induct A set: finite)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2778  | 
(simp_all add: Sup_insert_simp)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2779  | 
qed  | 
| 22917 | 2780  | 
|
| 24342 | 2781  | 
end  | 
2782  | 
||
| 22917 | 2783  | 
|
2784  | 
subsubsection {* Fold1 in linear orders with @{const min} and @{const max} *}
 | 
|
2785  | 
||
2786  | 
text{*
 | 
|
2787  | 
  As an application of @{text fold1} we define minimum
 | 
|
2788  | 
and maximum in (not necessarily complete!) linear orders  | 
|
2789  | 
  over (non-empty) sets by means of @{text fold1}.
 | 
|
2790  | 
*}  | 
|
2791  | 
||
| 24342 | 2792  | 
context linorder  | 
| 22917 | 2793  | 
begin  | 
2794  | 
||
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2795  | 
lemma ab_semigroup_idem_mult_min:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2796  | 
"ab_semigroup_idem_mult min"  | 
| 28823 | 2797  | 
proof qed (auto simp add: min_def)  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2798  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2799  | 
lemma ab_semigroup_idem_mult_max:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2800  | 
"ab_semigroup_idem_mult max"  | 
| 28823 | 2801  | 
proof qed (auto simp add: max_def)  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2802  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2803  | 
lemma min_lattice:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2804  | 
"lower_semilattice (op \<le>) (op <) min"  | 
| 28823 | 2805  | 
proof qed (auto simp add: min_def)  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2806  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2807  | 
lemma max_lattice:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2808  | 
"lower_semilattice (op \<ge>) (op >) max"  | 
| 28823 | 2809  | 
proof qed (auto simp add: max_def)  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2810  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2811  | 
lemma dual_max:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2812  | 
"ord.max (op \<ge>) = min"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2813  | 
by (auto simp add: ord.max_def_raw min_def_raw expand_fun_eq)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2814  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2815  | 
lemma dual_min:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2816  | 
"ord.min (op \<ge>) = max"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2817  | 
by (auto simp add: ord.min_def_raw max_def_raw expand_fun_eq)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2818  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2819  | 
lemma strict_below_fold1_iff:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2820  | 
  assumes "finite A" and "A \<noteq> {}"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2821  | 
shows "x < fold1 min A \<longleftrightarrow> (\<forall>a\<in>A. x < a)"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2822  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2823  | 
interpret ab_semigroup_idem_mult min  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2824  | 
by (rule ab_semigroup_idem_mult_min)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2825  | 
from assms show ?thesis  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2826  | 
by (induct rule: finite_ne_induct)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2827  | 
(simp_all add: fold1_insert)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2828  | 
qed  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2829  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2830  | 
lemma fold1_below_iff:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2831  | 
  assumes "finite A" and "A \<noteq> {}"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2832  | 
shows "fold1 min A \<le> x \<longleftrightarrow> (\<exists>a\<in>A. a \<le> x)"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2833  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2834  | 
interpret ab_semigroup_idem_mult min  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2835  | 
by (rule ab_semigroup_idem_mult_min)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2836  | 
from assms show ?thesis  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2837  | 
by (induct rule: finite_ne_induct)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2838  | 
(simp_all add: fold1_insert min_le_iff_disj)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2839  | 
qed  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2840  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2841  | 
lemma fold1_strict_below_iff:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2842  | 
  assumes "finite A" and "A \<noteq> {}"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2843  | 
shows "fold1 min A < x \<longleftrightarrow> (\<exists>a\<in>A. a < x)"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2844  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2845  | 
interpret ab_semigroup_idem_mult min  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2846  | 
by (rule ab_semigroup_idem_mult_min)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2847  | 
from assms show ?thesis  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2848  | 
by (induct rule: finite_ne_induct)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2849  | 
(simp_all add: fold1_insert min_less_iff_disj)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2850  | 
qed  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2851  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2852  | 
lemma fold1_antimono:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2853  | 
  assumes "A \<noteq> {}" and "A \<subseteq> B" and "finite B"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2854  | 
shows "fold1 min B \<le> fold1 min A"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2855  | 
proof cases  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2856  | 
assume "A = B" thus ?thesis by simp  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2857  | 
next  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2858  | 
interpret ab_semigroup_idem_mult min  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2859  | 
by (rule ab_semigroup_idem_mult_min)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2860  | 
assume "A \<noteq> B"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2861  | 
have B: "B = A \<union> (B-A)" using `A \<subseteq> B` by blast  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2862  | 
have "fold1 min B = fold1 min (A \<union> (B-A))" by(subst B)(rule refl)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2863  | 
also have "\<dots> = min (fold1 min A) (fold1 min (B-A))"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2864  | 
proof -  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2865  | 
have "finite A" by(rule finite_subset[OF `A \<subseteq> B` `finite B`])  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2866  | 
moreover have "finite(B-A)" by(rule finite_Diff[OF `finite B`]) (* by(blast intro:finite_Diff prems) fails *)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2867  | 
    moreover have "(B-A) \<noteq> {}" using prems by blast
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2868  | 
    moreover have "A Int (B-A) = {}" using prems by blast
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2869  | 
    ultimately show ?thesis using `A \<noteq> {}` by (rule_tac fold1_Un)
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2870  | 
qed  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2871  | 
also have "\<dots> \<le> fold1 min A" by (simp add: min_le_iff_disj)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2872  | 
finally show ?thesis .  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2873  | 
qed  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2874  | 
|
| 22917 | 2875  | 
definition  | 
2876  | 
Min :: "'a set \<Rightarrow> 'a"  | 
|
2877  | 
where  | 
|
2878  | 
"Min = fold1 min"  | 
|
2879  | 
||
2880  | 
definition  | 
|
2881  | 
Max :: "'a set \<Rightarrow> 'a"  | 
|
2882  | 
where  | 
|
2883  | 
"Max = fold1 max"  | 
|
2884  | 
||
2885  | 
lemmas Min_singleton [simp] = fold1_singleton_def [OF Min_def]  | 
|
2886  | 
lemmas Max_singleton [simp] = fold1_singleton_def [OF Max_def]  | 
|
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2887  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2888  | 
lemma Min_insert [simp]:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2889  | 
  assumes "finite A" and "A \<noteq> {}"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2890  | 
shows "Min (insert x A) = min x (Min A)"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2891  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2892  | 
interpret ab_semigroup_idem_mult min  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2893  | 
by (rule ab_semigroup_idem_mult_min)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2894  | 
from assms show ?thesis by (rule fold1_insert_idem_def [OF Min_def])  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2895  | 
qed  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2896  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2897  | 
lemma Max_insert [simp]:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2898  | 
  assumes "finite A" and "A \<noteq> {}"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2899  | 
shows "Max (insert x A) = max x (Max A)"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2900  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2901  | 
interpret ab_semigroup_idem_mult max  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2902  | 
by (rule ab_semigroup_idem_mult_max)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2903  | 
from assms show ?thesis by (rule fold1_insert_idem_def [OF Max_def])  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2904  | 
qed  | 
| 15392 | 2905  | 
|
| 24427 | 2906  | 
lemma Min_in [simp]:  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2907  | 
  assumes "finite A" and "A \<noteq> {}"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2908  | 
shows "Min A \<in> A"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2909  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2910  | 
interpret ab_semigroup_idem_mult min  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2911  | 
by (rule ab_semigroup_idem_mult_min)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2912  | 
from assms fold1_in show ?thesis by (fastsimp simp: Min_def min_def)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2913  | 
qed  | 
| 15392 | 2914  | 
|
| 24427 | 2915  | 
lemma Max_in [simp]:  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2916  | 
  assumes "finite A" and "A \<noteq> {}"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2917  | 
shows "Max A \<in> A"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2918  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2919  | 
interpret ab_semigroup_idem_mult max  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2920  | 
by (rule ab_semigroup_idem_mult_max)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2921  | 
from assms fold1_in [of A] show ?thesis by (fastsimp simp: Max_def max_def)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2922  | 
qed  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2923  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2924  | 
lemma Min_Un:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2925  | 
  assumes "finite A" and "A \<noteq> {}" and "finite B" and "B \<noteq> {}"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2926  | 
shows "Min (A \<union> B) = min (Min A) (Min B)"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2927  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2928  | 
interpret ab_semigroup_idem_mult min  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2929  | 
by (rule ab_semigroup_idem_mult_min)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2930  | 
from assms show ?thesis  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2931  | 
by (simp add: Min_def fold1_Un2)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2932  | 
qed  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2933  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2934  | 
lemma Max_Un:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2935  | 
  assumes "finite A" and "A \<noteq> {}" and "finite B" and "B \<noteq> {}"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2936  | 
shows "Max (A \<union> B) = max (Max A) (Max B)"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2937  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2938  | 
interpret ab_semigroup_idem_mult max  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2939  | 
by (rule ab_semigroup_idem_mult_max)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2940  | 
from assms show ?thesis  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2941  | 
by (simp add: Max_def fold1_Un2)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2942  | 
qed  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2943  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2944  | 
lemma hom_Min_commute:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2945  | 
assumes "\<And>x y. h (min x y) = min (h x) (h y)"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2946  | 
    and "finite N" and "N \<noteq> {}"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2947  | 
shows "h (Min N) = Min (h ` N)"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2948  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2949  | 
interpret ab_semigroup_idem_mult min  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2950  | 
by (rule ab_semigroup_idem_mult_min)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2951  | 
from assms show ?thesis  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2952  | 
by (simp add: Min_def hom_fold1_commute)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2953  | 
qed  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2954  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2955  | 
lemma hom_Max_commute:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2956  | 
assumes "\<And>x y. h (max x y) = max (h x) (h y)"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2957  | 
    and "finite N" and "N \<noteq> {}"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2958  | 
shows "h (Max N) = Max (h ` N)"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2959  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2960  | 
interpret ab_semigroup_idem_mult max  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2961  | 
by (rule ab_semigroup_idem_mult_max)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2962  | 
from assms show ?thesis  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2963  | 
by (simp add: Max_def hom_fold1_commute [of h])  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2964  | 
qed  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2965  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2966  | 
lemma Min_le [simp]:  | 
| 
26757
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2967  | 
assumes "finite A" and "x \<in> A"  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2968  | 
shows "Min A \<le> x"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2969  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2970  | 
interpret lower_semilattice "op \<le>" "op <" min  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2971  | 
by (rule min_lattice)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2972  | 
from assms show ?thesis by (simp add: Min_def fold1_belowI)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2973  | 
qed  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2974  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2975  | 
lemma Max_ge [simp]:  | 
| 
26757
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
2976  | 
assumes "finite A" and "x \<in> A"  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2977  | 
shows "x \<le> Max A"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2978  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2979  | 
interpret lower_semilattice "op \<ge>" "op >" max  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2980  | 
by (rule max_lattice)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2981  | 
from assms show ?thesis by (simp add: Max_def fold1_belowI)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2982  | 
qed  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2983  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2984  | 
lemma Min_ge_iff [simp, noatp]:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2985  | 
  assumes "finite A" and "A \<noteq> {}"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2986  | 
shows "x \<le> Min A \<longleftrightarrow> (\<forall>a\<in>A. x \<le> a)"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2987  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2988  | 
interpret lower_semilattice "op \<le>" "op <" min  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2989  | 
by (rule min_lattice)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2990  | 
from assms show ?thesis by (simp add: Min_def below_fold1_iff)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2991  | 
qed  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2992  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2993  | 
lemma Max_le_iff [simp, noatp]:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2994  | 
  assumes "finite A" and "A \<noteq> {}"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2995  | 
shows "Max A \<le> x \<longleftrightarrow> (\<forall>a\<in>A. a \<le> x)"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2996  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
2997  | 
interpret lower_semilattice "op \<ge>" "op >" max  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2998  | 
by (rule max_lattice)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
2999  | 
from assms show ?thesis by (simp add: Max_def below_fold1_iff)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3000  | 
qed  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3001  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3002  | 
lemma Min_gr_iff [simp, noatp]:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3003  | 
  assumes "finite A" and "A \<noteq> {}"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3004  | 
shows "x < Min A \<longleftrightarrow> (\<forall>a\<in>A. x < a)"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3005  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
3006  | 
interpret lower_semilattice "op \<le>" "op <" min  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3007  | 
by (rule min_lattice)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3008  | 
from assms show ?thesis by (simp add: Min_def strict_below_fold1_iff)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3009  | 
qed  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3010  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3011  | 
lemma Max_less_iff [simp, noatp]:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3012  | 
  assumes "finite A" and "A \<noteq> {}"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3013  | 
shows "Max A < x \<longleftrightarrow> (\<forall>a\<in>A. a < x)"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3014  | 
proof -  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3015  | 
note Max = Max_def  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
3016  | 
interpret linorder "op \<ge>" "op >"  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3017  | 
by (rule dual_linorder)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3018  | 
from assms show ?thesis  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3019  | 
by (simp add: Max strict_below_fold1_iff [folded dual_max])  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3020  | 
qed  | 
| 18493 | 3021  | 
|
| 
24286
 
7619080e49f0
ATP blacklisting is now in theory data, attribute noatp
 
paulson 
parents: 
24268 
diff
changeset
 | 
3022  | 
lemma Min_le_iff [noatp]:  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3023  | 
  assumes "finite A" and "A \<noteq> {}"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3024  | 
shows "Min A \<le> x \<longleftrightarrow> (\<exists>a\<in>A. a \<le> x)"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3025  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
3026  | 
interpret lower_semilattice "op \<le>" "op <" min  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3027  | 
by (rule min_lattice)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3028  | 
from assms show ?thesis  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3029  | 
by (simp add: Min_def fold1_below_iff)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3030  | 
qed  | 
| 
15497
 
53bca254719a
Added semi-lattice locales and reorganized fold1 lemmas
 
nipkow 
parents: 
15487 
diff
changeset
 | 
3031  | 
|
| 
24286
 
7619080e49f0
ATP blacklisting is now in theory data, attribute noatp
 
paulson 
parents: 
24268 
diff
changeset
 | 
3032  | 
lemma Max_ge_iff [noatp]:  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3033  | 
  assumes "finite A" and "A \<noteq> {}"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3034  | 
shows "x \<le> Max A \<longleftrightarrow> (\<exists>a\<in>A. x \<le> a)"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3035  | 
proof -  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3036  | 
note Max = Max_def  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
3037  | 
interpret linorder "op \<ge>" "op >"  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3038  | 
by (rule dual_linorder)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3039  | 
from assms show ?thesis  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3040  | 
by (simp add: Max fold1_below_iff [folded dual_max])  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3041  | 
qed  | 
| 22917 | 3042  | 
|
| 
24286
 
7619080e49f0
ATP blacklisting is now in theory data, attribute noatp
 
paulson 
parents: 
24268 
diff
changeset
 | 
3043  | 
lemma Min_less_iff [noatp]:  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3044  | 
  assumes "finite A" and "A \<noteq> {}"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3045  | 
shows "Min A < x \<longleftrightarrow> (\<exists>a\<in>A. a < x)"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3046  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
3047  | 
interpret lower_semilattice "op \<le>" "op <" min  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3048  | 
by (rule min_lattice)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3049  | 
from assms show ?thesis  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3050  | 
by (simp add: Min_def fold1_strict_below_iff)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3051  | 
qed  | 
| 22917 | 3052  | 
|
| 
24286
 
7619080e49f0
ATP blacklisting is now in theory data, attribute noatp
 
paulson 
parents: 
24268 
diff
changeset
 | 
3053  | 
lemma Max_gr_iff [noatp]:  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3054  | 
  assumes "finite A" and "A \<noteq> {}"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3055  | 
shows "x < Max A \<longleftrightarrow> (\<exists>a\<in>A. x < a)"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3056  | 
proof -  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3057  | 
note Max = Max_def  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
3058  | 
interpret linorder "op \<ge>" "op >"  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3059  | 
by (rule dual_linorder)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3060  | 
from assms show ?thesis  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3061  | 
by (simp add: Max fold1_strict_below_iff [folded dual_max])  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3062  | 
qed  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3063  | 
|
| 30325 | 3064  | 
lemma Min_eqI:  | 
3065  | 
assumes "finite A"  | 
|
3066  | 
assumes "\<And>y. y \<in> A \<Longrightarrow> y \<ge> x"  | 
|
3067  | 
and "x \<in> A"  | 
|
3068  | 
shows "Min A = x"  | 
|
3069  | 
proof (rule antisym)  | 
|
3070  | 
  from `x \<in> A` have "A \<noteq> {}" by auto
 | 
|
3071  | 
with assms show "Min A \<ge> x" by simp  | 
|
3072  | 
next  | 
|
3073  | 
from assms show "x \<ge> Min A" by simp  | 
|
3074  | 
qed  | 
|
3075  | 
||
3076  | 
lemma Max_eqI:  | 
|
3077  | 
assumes "finite A"  | 
|
3078  | 
assumes "\<And>y. y \<in> A \<Longrightarrow> y \<le> x"  | 
|
3079  | 
and "x \<in> A"  | 
|
3080  | 
shows "Max A = x"  | 
|
3081  | 
proof (rule antisym)  | 
|
3082  | 
  from `x \<in> A` have "A \<noteq> {}" by auto
 | 
|
3083  | 
with assms show "Max A \<le> x" by simp  | 
|
3084  | 
next  | 
|
3085  | 
from assms show "x \<le> Max A" by simp  | 
|
3086  | 
qed  | 
|
3087  | 
||
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3088  | 
lemma Min_antimono:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3089  | 
  assumes "M \<subseteq> N" and "M \<noteq> {}" and "finite N"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3090  | 
shows "Min N \<le> Min M"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3091  | 
proof -  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
3092  | 
interpret distrib_lattice "op \<le>" "op <" min max  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3093  | 
by (rule distrib_lattice_min_max)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3094  | 
from assms show ?thesis by (simp add: Min_def fold1_antimono)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3095  | 
qed  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3096  | 
|
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3097  | 
lemma Max_mono:  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3098  | 
  assumes "M \<subseteq> N" and "M \<noteq> {}" and "finite N"
 | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3099  | 
shows "Max M \<le> Max N"  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3100  | 
proof -  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3101  | 
note Max = Max_def  | 
| 
29509
 
1ff0f3f08a7b
migrated class package to new locale implementation
 
haftmann 
parents: 
29223 
diff
changeset
 | 
3102  | 
interpret linorder "op \<ge>" "op >"  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3103  | 
by (rule dual_linorder)  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3104  | 
from assms show ?thesis  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3105  | 
by (simp add: Max fold1_antimono [folded dual_max])  | 
| 
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25571 
diff
changeset
 | 
3106  | 
qed  | 
| 22917 | 3107  | 
|
| 
26748
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3108  | 
lemma finite_linorder_induct[consumes 1, case_names empty insert]:  | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3109  | 
 "finite A \<Longrightarrow> P {} \<Longrightarrow>
 | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3110  | 
(!!A b. finite A \<Longrightarrow> ALL a:A. a < b \<Longrightarrow> P A \<Longrightarrow> P(insert b A))  | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3111  | 
\<Longrightarrow> P A"  | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3112  | 
proof (induct A rule: measure_induct_rule[where f=card])  | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3113  | 
fix A :: "'a set"  | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3114  | 
  assume IH: "!! B. card B < card A \<Longrightarrow> finite B \<Longrightarrow> P {} \<Longrightarrow>
 | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3115  | 
(!!A b. finite A \<Longrightarrow> (\<forall>a\<in>A. a<b) \<Longrightarrow> P A \<Longrightarrow> P (insert b A))  | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3116  | 
\<Longrightarrow> P B"  | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3117  | 
  and "finite A" and "P {}"
 | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3118  | 
and step: "!!A b. \<lbrakk>finite A; \<forall>a\<in>A. a < b; P A\<rbrakk> \<Longrightarrow> P (insert b A)"  | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3119  | 
show "P A"  | 
| 
26757
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
3120  | 
  proof (cases "A = {}")
 | 
| 
26748
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3121  | 
    assume "A = {}" thus "P A" using `P {}` by simp
 | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3122  | 
next  | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3123  | 
    let ?B = "A - {Max A}" let ?A = "insert (Max A) ?B"
 | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3124  | 
    assume "A \<noteq> {}"
 | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3125  | 
with `finite A` have "Max A : A" by auto  | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3126  | 
hence A: "?A = A" using insert_Diff_single insert_absorb by auto  | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3127  | 
note card_Diff1_less[OF `finite A` `Max A : A`]  | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3128  | 
moreover have "finite ?B" using `finite A` by simp  | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3129  | 
    ultimately have "P ?B" using `P {}` step IH by blast
 | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3130  | 
moreover have "\<forall>a\<in>?B. a < Max A"  | 
| 
26757
 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 
haftmann 
parents: 
26748 
diff
changeset
 | 
3131  | 
using Max_ge [OF `finite A`] by fastsimp  | 
| 
26748
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3132  | 
ultimately show "P A"  | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3133  | 
using A insert_Diff_single step[OF `finite ?B`] by fastsimp  | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3134  | 
qed  | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3135  | 
qed  | 
| 
 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 
krauss 
parents: 
26465 
diff
changeset
 | 
3136  | 
|
| 22917 | 3137  | 
end  | 
3138  | 
||
| 
24380
 
c215e256beca
moved ordered_ab_semigroup_add to OrderedGroup.thy
 
haftmann 
parents: 
24342 
diff
changeset
 | 
3139  | 
context ordered_ab_semigroup_add  | 
| 22917 | 3140  | 
begin  | 
3141  | 
||
3142  | 
lemma add_Min_commute:  | 
|
3143  | 
fixes k  | 
|
| 25062 | 3144  | 
  assumes "finite N" and "N \<noteq> {}"
 | 
3145  | 
  shows "k + Min N = Min {k + m | m. m \<in> N}"
 | 
|
3146  | 
proof -  | 
|
3147  | 
have "\<And>x y. k + min x y = min (k + x) (k + y)"  | 
|
3148  | 
by (simp add: min_def not_le)  | 
|
3149  | 
(blast intro: antisym less_imp_le add_left_mono)  | 
|
3150  | 
with assms show ?thesis  | 
|
3151  | 
using hom_Min_commute [of "plus k" N]  | 
|
3152  | 
by simp (blast intro: arg_cong [where f = Min])  | 
|
3153  | 
qed  | 
|
| 22917 | 3154  | 
|
3155  | 
lemma add_Max_commute:  | 
|
3156  | 
fixes k  | 
|
| 25062 | 3157  | 
  assumes "finite N" and "N \<noteq> {}"
 | 
3158  | 
  shows "k + Max N = Max {k + m | m. m \<in> N}"
 | 
|
3159  | 
proof -  | 
|
3160  | 
have "\<And>x y. k + max x y = max (k + x) (k + y)"  | 
|
3161  | 
by (simp add: max_def not_le)  | 
|
3162  | 
(blast intro: antisym less_imp_le add_left_mono)  | 
|
3163  | 
with assms show ?thesis  | 
|
3164  | 
using hom_Max_commute [of "plus k" N]  | 
|
3165  | 
by simp (blast intro: arg_cong [where f = Max])  | 
|
3166  | 
qed  | 
|
| 22917 | 3167  | 
|
3168  | 
end  | 
|
3169  | 
||
| 
25571
 
c9e39eafc7a0
instantiation target rather than legacy instance
 
haftmann 
parents: 
25502 
diff
changeset
 | 
3170  | 
end  |