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