src/HOL/Algebra/FiniteProduct.thy
author wenzelm
Wed, 13 Jun 2007 00:01:41 +0200
changeset 23350 50c5b0912a0c
parent 22265 3c5c6bdf61de
child 23746 a455e69c31cc
permissions -rw-r--r--
tuned proofs: avoid implicit prems;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14706
71590b7733b7 tuned document;
wenzelm
parents: 14666
diff changeset
     1
(*  Title:      HOL/Algebra/FiniteProduct.thy
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
     2
    ID:         $Id$
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
     3
    Author:     Clemens Ballarin, started 19 November 2002
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
     4
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
     5
This file is largely based on HOL/Finite_Set.thy.
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
     6
*)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
     7
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents: 16638
diff changeset
     8
theory FiniteProduct imports Group begin
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents: 16638
diff changeset
     9
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    10
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents: 16638
diff changeset
    11
section {* Product Operator for Commutative Monoids *}
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents: 16638
diff changeset
    12
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents: 16638
diff changeset
    13
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents: 16638
diff changeset
    14
subsection {* Inductive Definition of a Relation for Products over Sets *}
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    15
14750
paulson
parents: 14706
diff changeset
    16
text {* Instantiation of locale @{text LC} of theory @{text Finite_Set} is not
paulson
parents: 14706
diff changeset
    17
  possible, because here we have explicit typing rules like 
paulson
parents: 14706
diff changeset
    18
  @{text "x \<in> carrier G"}.  We introduce an explicit argument for the domain
14651
02b8f3bcf7fe improved notation;
wenzelm
parents: 14590
diff changeset
    19
  @{text D}. *}
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    20
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    21
consts
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    22
  foldSetD :: "['a set, 'b => 'a => 'a, 'a] => ('b set * 'a) set"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    23
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    24
inductive "foldSetD D f e"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    25
  intros
14750
paulson
parents: 14706
diff changeset
    26
    emptyI [intro]: "e \<in> D ==> ({}, e) \<in> foldSetD D f e"
paulson
parents: 14706
diff changeset
    27
    insertI [intro]: "[| x ~: A; f x y \<in> D; (A, y) \<in> foldSetD D f e |] ==>
paulson
parents: 14706
diff changeset
    28
                      (insert x A, f x y) \<in> foldSetD D f e"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    29
14750
paulson
parents: 14706
diff changeset
    30
inductive_cases empty_foldSetDE [elim!]: "({}, x) \<in> foldSetD D f e"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    31
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    32
constdefs
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    33
  foldD :: "['a set, 'b => 'a => 'a, 'a, 'b set] => 'a"
14750
paulson
parents: 14706
diff changeset
    34
  "foldD D f e A == THE x. (A, x) \<in> foldSetD D f e"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    35
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    36
lemma foldSetD_closed:
14750
paulson
parents: 14706
diff changeset
    37
  "[| (A, z) \<in> foldSetD D f e ; e \<in> D; !!x y. [| x \<in> A; y \<in> D |] ==> f x y \<in> D 
paulson
parents: 14706
diff changeset
    38
      |] ==> z \<in> D";
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    39
  by (erule foldSetD.elims) auto
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    40
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    41
lemma Diff1_foldSetD:
14750
paulson
parents: 14706
diff changeset
    42
  "[| (A - {x}, y) \<in> foldSetD D f e; x \<in> A; f x y \<in> D |] ==>
paulson
parents: 14706
diff changeset
    43
   (A, f x y) \<in> foldSetD D f e"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    44
  apply (erule insert_Diff [THEN subst], rule foldSetD.intros)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    45
    apply auto
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    46
  done
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    47
14750
paulson
parents: 14706
diff changeset
    48
lemma foldSetD_imp_finite [simp]: "(A, x) \<in> foldSetD D f e ==> finite A"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    49
  by (induct set: foldSetD) auto
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    50
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    51
lemma finite_imp_foldSetD:
14750
paulson
parents: 14706
diff changeset
    52
  "[| finite A; e \<in> D; !!x y. [| x \<in> A; y \<in> D |] ==> f x y \<in> D |] ==>
paulson
parents: 14706
diff changeset
    53
   EX x. (A, x) \<in> foldSetD D f e"
22265
3c5c6bdf61de Adapted to changes in Finite_Set theory.
berghofe
parents: 20318
diff changeset
    54
proof (induct set: finite)
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    55
  case empty then show ?case by auto
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    56
next
15328
35951e6a7855 mod because of change in finite set induction
nipkow
parents: 15095
diff changeset
    57
  case (insert x F)
14750
paulson
parents: 14706
diff changeset
    58
  then obtain y where y: "(F, y) \<in> foldSetD D f e" by auto
paulson
parents: 14706
diff changeset
    59
  with insert have "y \<in> D" by (auto dest: foldSetD_closed)
paulson
parents: 14706
diff changeset
    60
  with y and insert have "(insert x F, f x y) \<in> foldSetD D f e"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    61
    by (intro foldSetD.intros) auto
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    62
  then show ?case ..
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    63
qed
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    64
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents: 16638
diff changeset
    65
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents: 16638
diff changeset
    66
subsection {* Left-Commutative Operations *}
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    67
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    68
locale LCD =
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    69
  fixes B :: "'b set"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    70
  and D :: "'a set"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    71
  and f :: "'b => 'a => 'a"    (infixl "\<cdot>" 70)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    72
  assumes left_commute:
14750
paulson
parents: 14706
diff changeset
    73
    "[| x \<in> B; y \<in> B; z \<in> D |] ==> x \<cdot> (y \<cdot> z) = y \<cdot> (x \<cdot> z)"
paulson
parents: 14706
diff changeset
    74
  and f_closed [simp, intro!]: "!!x y. [| x \<in> B; y \<in> D |] ==> f x y \<in> D"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    75
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    76
lemma (in LCD) foldSetD_closed [dest]:
14750
paulson
parents: 14706
diff changeset
    77
  "(A, z) \<in> foldSetD D f e ==> z \<in> D";
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    78
  by (erule foldSetD.elims) auto
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    79
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    80
lemma (in LCD) Diff1_foldSetD:
14750
paulson
parents: 14706
diff changeset
    81
  "[| (A - {x}, y) \<in> foldSetD D f e; x \<in> A; A \<subseteq> B |] ==>
paulson
parents: 14706
diff changeset
    82
  (A, f x y) \<in> foldSetD D f e"
paulson
parents: 14706
diff changeset
    83
  apply (subgoal_tac "x \<in> B")
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    84
   prefer 2 apply fast
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    85
  apply (erule insert_Diff [THEN subst], rule foldSetD.intros)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    86
    apply auto
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    87
  done
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    88
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    89
lemma (in LCD) foldSetD_imp_finite [simp]:
14750
paulson
parents: 14706
diff changeset
    90
  "(A, x) \<in> foldSetD D f e ==> finite A"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    91
  by (induct set: foldSetD) auto
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    92
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    93
lemma (in LCD) finite_imp_foldSetD:
14750
paulson
parents: 14706
diff changeset
    94
  "[| finite A; A \<subseteq> B; e \<in> D |] ==> EX x. (A, x) \<in> foldSetD D f e"
22265
3c5c6bdf61de Adapted to changes in Finite_Set theory.
berghofe
parents: 20318
diff changeset
    95
proof (induct set: finite)
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    96
  case empty then show ?case by auto
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
    97
next
15328
35951e6a7855 mod because of change in finite set induction
nipkow
parents: 15095
diff changeset
    98
  case (insert x F)
14750
paulson
parents: 14706
diff changeset
    99
  then obtain y where y: "(F, y) \<in> foldSetD D f e" by auto
paulson
parents: 14706
diff changeset
   100
  with insert have "y \<in> D" by auto
paulson
parents: 14706
diff changeset
   101
  with y and insert have "(insert x F, f x y) \<in> foldSetD D f e"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   102
    by (intro foldSetD.intros) auto
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   103
  then show ?case ..
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   104
qed
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   105
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   106
lemma (in LCD) foldSetD_determ_aux:
14750
paulson
parents: 14706
diff changeset
   107
  "e \<in> D ==> \<forall>A x. A \<subseteq> B & card A < n --> (A, x) \<in> foldSetD D f e -->
paulson
parents: 14706
diff changeset
   108
    (\<forall>y. (A, y) \<in> foldSetD D f e --> y = x)"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   109
  apply (induct n)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   110
   apply (auto simp add: less_Suc_eq) (* slow *)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   111
  apply (erule foldSetD.cases)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   112
   apply blast
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   113
  apply (erule foldSetD.cases)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   114
   apply blast
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   115
  apply clarify
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   116
  txt {* force simplification of @{text "card A < card (insert ...)"}. *}
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   117
  apply (erule rev_mp)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   118
  apply (simp add: less_Suc_eq_le)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   119
  apply (rule impI)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   120
  apply (rename_tac Aa xa ya Ab xb yb, case_tac "xa = xb")
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   121
   apply (subgoal_tac "Aa = Ab")
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   122
    prefer 2 apply (blast elim!: equalityE)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   123
   apply blast
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   124
  txt {* case @{prop "xa \<notin> xb"}. *}
14750
paulson
parents: 14706
diff changeset
   125
  apply (subgoal_tac "Aa - {xb} = Ab - {xa} & xb \<in> Aa & xa \<in> Ab")
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   126
   prefer 2 apply (blast elim!: equalityE)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   127
  apply clarify
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   128
  apply (subgoal_tac "Aa = insert xb Ab - {xa}")
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   129
   prefer 2 apply blast
14750
paulson
parents: 14706
diff changeset
   130
  apply (subgoal_tac "card Aa \<le> card Ab")
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   131
   prefer 2
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   132
   apply (rule Suc_le_mono [THEN subst])
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   133
   apply (simp add: card_Suc_Diff1)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   134
  apply (rule_tac A1 = "Aa - {xb}" in finite_imp_foldSetD [THEN exE])
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   135
     apply (blast intro: foldSetD_imp_finite finite_Diff)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   136
    apply best
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   137
   apply assumption
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   138
  apply (frule (1) Diff1_foldSetD)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   139
   apply best
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   140
  apply (subgoal_tac "ya = f xb x")
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   141
   prefer 2
14750
paulson
parents: 14706
diff changeset
   142
   apply (subgoal_tac "Aa \<subseteq> B")
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   143
    prefer 2 apply best (* slow *)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   144
   apply (blast del: equalityCE)
14750
paulson
parents: 14706
diff changeset
   145
  apply (subgoal_tac "(Ab - {xa}, x) \<in> foldSetD D f e")
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   146
   prefer 2 apply simp
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   147
  apply (subgoal_tac "yb = f xa x")
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   148
   prefer 2 
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   149
   apply (blast del: equalityCE dest: Diff1_foldSetD)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   150
  apply (simp (no_asm_simp))
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   151
  apply (rule left_commute)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   152
    apply assumption
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   153
   apply best (* slow *)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   154
  apply best
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   155
  done
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   156
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   157
lemma (in LCD) foldSetD_determ:
14750
paulson
parents: 14706
diff changeset
   158
  "[| (A, x) \<in> foldSetD D f e; (A, y) \<in> foldSetD D f e; e \<in> D; A \<subseteq> B |]
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   159
  ==> y = x"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   160
  by (blast intro: foldSetD_determ_aux [rule_format])
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   161
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   162
lemma (in LCD) foldD_equality:
14750
paulson
parents: 14706
diff changeset
   163
  "[| (A, y) \<in> foldSetD D f e; e \<in> D; A \<subseteq> B |] ==> foldD D f e A = y"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   164
  by (unfold foldD_def) (blast intro: foldSetD_determ)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   165
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   166
lemma foldD_empty [simp]:
14750
paulson
parents: 14706
diff changeset
   167
  "e \<in> D ==> foldD D f e {} = e"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   168
  by (unfold foldD_def) blast
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   169
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   170
lemma (in LCD) foldD_insert_aux:
14750
paulson
parents: 14706
diff changeset
   171
  "[| x ~: A; x \<in> B; e \<in> D; A \<subseteq> B |] ==>
paulson
parents: 14706
diff changeset
   172
    ((insert x A, v) \<in> foldSetD D f e) =
paulson
parents: 14706
diff changeset
   173
    (EX y. (A, y) \<in> foldSetD D f e & v = f x y)"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   174
  apply auto
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   175
  apply (rule_tac A1 = A in finite_imp_foldSetD [THEN exE])
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   176
     apply (fastsimp dest: foldSetD_imp_finite)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   177
    apply assumption
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   178
   apply assumption
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   179
  apply (blast intro: foldSetD_determ)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   180
  done
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   181
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   182
lemma (in LCD) foldD_insert:
14750
paulson
parents: 14706
diff changeset
   183
    "[| finite A; x ~: A; x \<in> B; e \<in> D; A \<subseteq> B |] ==>
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   184
     foldD D f e (insert x A) = f x (foldD D f e A)"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   185
  apply (unfold foldD_def)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   186
  apply (simp add: foldD_insert_aux)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   187
  apply (rule the_equality)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   188
   apply (auto intro: finite_imp_foldSetD
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   189
     cong add: conj_cong simp add: foldD_def [symmetric] foldD_equality)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   190
  done
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   191
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   192
lemma (in LCD) foldD_closed [simp]:
14750
paulson
parents: 14706
diff changeset
   193
  "[| finite A; e \<in> D; A \<subseteq> B |] ==> foldD D f e A \<in> D"
22265
3c5c6bdf61de Adapted to changes in Finite_Set theory.
berghofe
parents: 20318
diff changeset
   194
proof (induct set: finite)
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   195
  case empty then show ?case by (simp add: foldD_empty)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   196
next
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   197
  case insert then show ?case by (simp add: foldD_insert)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   198
qed
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   199
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   200
lemma (in LCD) foldD_commute:
14750
paulson
parents: 14706
diff changeset
   201
  "[| finite A; x \<in> B; e \<in> D; A \<subseteq> B |] ==>
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   202
   f x (foldD D f e A) = foldD D f (f x e) A"
22265
3c5c6bdf61de Adapted to changes in Finite_Set theory.
berghofe
parents: 20318
diff changeset
   203
  apply (induct set: finite)
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   204
   apply simp
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   205
  apply (auto simp add: left_commute foldD_insert)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   206
  done
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   207
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   208
lemma Int_mono2:
14750
paulson
parents: 14706
diff changeset
   209
  "[| A \<subseteq> C; B \<subseteq> C |] ==> A Int B \<subseteq> C"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   210
  by blast
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   211
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   212
lemma (in LCD) foldD_nest_Un_Int:
14750
paulson
parents: 14706
diff changeset
   213
  "[| finite A; finite C; e \<in> D; A \<subseteq> B; C \<subseteq> B |] ==>
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   214
   foldD D f (foldD D f e C) A = foldD D f (foldD D f e (A Int C)) (A Un C)"
22265
3c5c6bdf61de Adapted to changes in Finite_Set theory.
berghofe
parents: 20318
diff changeset
   215
  apply (induct set: finite)
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   216
   apply simp
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   217
  apply (simp add: foldD_insert foldD_commute Int_insert_left insert_absorb
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   218
    Int_mono2 Un_subset_iff)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   219
  done
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   220
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   221
lemma (in LCD) foldD_nest_Un_disjoint:
14750
paulson
parents: 14706
diff changeset
   222
  "[| finite A; finite B; A Int B = {}; e \<in> D; A \<subseteq> B; C \<subseteq> B |]
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   223
    ==> foldD D f e (A Un B) = foldD D f (foldD D f e B) A"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   224
  by (simp add: foldD_nest_Un_Int)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   225
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   226
-- {* Delete rules to do with @{text foldSetD} relation. *}
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   227
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   228
declare foldSetD_imp_finite [simp del]
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   229
  empty_foldSetDE [rule del]
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   230
  foldSetD.intros [rule del]
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   231
declare (in LCD)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   232
  foldSetD_closed [rule del]
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   233
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents: 16638
diff changeset
   234
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents: 16638
diff changeset
   235
subsection {* Commutative Monoids *}
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   236
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   237
text {*
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   238
  We enter a more restrictive context, with @{text "f :: 'a => 'a => 'a"}
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   239
  instead of @{text "'b => 'a => 'a"}.
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   240
*}
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   241
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   242
locale ACeD =
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   243
  fixes D :: "'a set"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   244
    and f :: "'a => 'a => 'a"    (infixl "\<cdot>" 70)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   245
    and e :: 'a
14750
paulson
parents: 14706
diff changeset
   246
  assumes ident [simp]: "x \<in> D ==> x \<cdot> e = x"
paulson
parents: 14706
diff changeset
   247
    and commute: "[| x \<in> D; y \<in> D |] ==> x \<cdot> y = y \<cdot> x"
paulson
parents: 14706
diff changeset
   248
    and assoc: "[| x \<in> D; y \<in> D; z \<in> D |] ==> (x \<cdot> y) \<cdot> z = x \<cdot> (y \<cdot> z)"
paulson
parents: 14706
diff changeset
   249
    and e_closed [simp]: "e \<in> D"
paulson
parents: 14706
diff changeset
   250
    and f_closed [simp]: "[| x \<in> D; y \<in> D |] ==> x \<cdot> y \<in> D"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   251
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   252
lemma (in ACeD) left_commute:
14750
paulson
parents: 14706
diff changeset
   253
  "[| x \<in> D; y \<in> D; z \<in> D |] ==> x \<cdot> (y \<cdot> z) = y \<cdot> (x \<cdot> z)"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   254
proof -
14750
paulson
parents: 14706
diff changeset
   255
  assume D: "x \<in> D" "y \<in> D" "z \<in> D"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   256
  then have "x \<cdot> (y \<cdot> z) = (y \<cdot> z) \<cdot> x" by (simp add: commute)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   257
  also from D have "... = y \<cdot> (z \<cdot> x)" by (simp add: assoc)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   258
  also from D have "z \<cdot> x = x \<cdot> z" by (simp add: commute)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   259
  finally show ?thesis .
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   260
qed
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   261
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   262
lemmas (in ACeD) AC = assoc commute left_commute
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   263
14750
paulson
parents: 14706
diff changeset
   264
lemma (in ACeD) left_ident [simp]: "x \<in> D ==> e \<cdot> x = x"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   265
proof -
23350
50c5b0912a0c tuned proofs: avoid implicit prems;
wenzelm
parents: 22265
diff changeset
   266
  assume "x \<in> D"
50c5b0912a0c tuned proofs: avoid implicit prems;
wenzelm
parents: 22265
diff changeset
   267
  then have "x \<cdot> e = x" by (rule ident)
50c5b0912a0c tuned proofs: avoid implicit prems;
wenzelm
parents: 22265
diff changeset
   268
  with `x \<in> D` show ?thesis by (simp add: commute)
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   269
qed
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   270
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   271
lemma (in ACeD) foldD_Un_Int:
14750
paulson
parents: 14706
diff changeset
   272
  "[| finite A; finite B; A \<subseteq> D; B \<subseteq> D |] ==>
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   273
    foldD D f e A \<cdot> foldD D f e B =
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   274
    foldD D f e (A Un B) \<cdot> foldD D f e (A Int B)"
22265
3c5c6bdf61de Adapted to changes in Finite_Set theory.
berghofe
parents: 20318
diff changeset
   275
  apply (induct set: finite)
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   276
   apply (simp add: left_commute LCD.foldD_closed [OF LCD.intro [of D]])
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   277
  apply (simp add: AC insert_absorb Int_insert_left
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   278
    LCD.foldD_insert [OF LCD.intro [of D]]
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   279
    LCD.foldD_closed [OF LCD.intro [of D]]
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   280
    Int_mono2 Un_subset_iff)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   281
  done
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   282
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   283
lemma (in ACeD) foldD_Un_disjoint:
14750
paulson
parents: 14706
diff changeset
   284
  "[| finite A; finite B; A Int B = {}; A \<subseteq> D; B \<subseteq> D |] ==>
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   285
    foldD D f e (A Un B) = foldD D f e A \<cdot> foldD D f e B"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   286
  by (simp add: foldD_Un_Int
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   287
    left_commute LCD.foldD_closed [OF LCD.intro [of D]] Un_subset_iff)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   288
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents: 16638
diff changeset
   289
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   290
subsection {* Products over Finite Sets *}
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   291
14651
02b8f3bcf7fe improved notation;
wenzelm
parents: 14590
diff changeset
   292
constdefs (structure G)
15095
63f5f4c265dd Theories now take advantage of recent syntax improvements with (structure).
ballarin
parents: 14750
diff changeset
   293
  finprod :: "[('b, 'm) monoid_scheme, 'a => 'b, 'a set] => 'b"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   294
  "finprod G f A == if finite A
14651
02b8f3bcf7fe improved notation;
wenzelm
parents: 14590
diff changeset
   295
      then foldD (carrier G) (mult G o f) \<one> A
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   296
      else arbitrary"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   297
14651
02b8f3bcf7fe improved notation;
wenzelm
parents: 14590
diff changeset
   298
syntax
02b8f3bcf7fe improved notation;
wenzelm
parents: 14590
diff changeset
   299
  "_finprod" :: "index => idt => 'a set => 'b => 'b"
14666
65f8680c3f16 improved notation;
wenzelm
parents: 14651
diff changeset
   300
      ("(3\<Otimes>__:_. _)" [1000, 0, 51, 10] 10)
14651
02b8f3bcf7fe improved notation;
wenzelm
parents: 14590
diff changeset
   301
syntax (xsymbols)
02b8f3bcf7fe improved notation;
wenzelm
parents: 14590
diff changeset
   302
  "_finprod" :: "index => idt => 'a set => 'b => 'b"
14666
65f8680c3f16 improved notation;
wenzelm
parents: 14651
diff changeset
   303
      ("(3\<Otimes>__\<in>_. _)" [1000, 0, 51, 10] 10)
14651
02b8f3bcf7fe improved notation;
wenzelm
parents: 14590
diff changeset
   304
syntax (HTML output)
02b8f3bcf7fe improved notation;
wenzelm
parents: 14590
diff changeset
   305
  "_finprod" :: "index => idt => 'a set => 'b => 'b"
14666
65f8680c3f16 improved notation;
wenzelm
parents: 14651
diff changeset
   306
      ("(3\<Otimes>__\<in>_. _)" [1000, 0, 51, 10] 10)
14651
02b8f3bcf7fe improved notation;
wenzelm
parents: 14590
diff changeset
   307
translations
15095
63f5f4c265dd Theories now take advantage of recent syntax improvements with (structure).
ballarin
parents: 14750
diff changeset
   308
  "\<Otimes>\<index>i:A. b" == "finprod \<struct>\<index> (%i. b) A"
63f5f4c265dd Theories now take advantage of recent syntax improvements with (structure).
ballarin
parents: 14750
diff changeset
   309
  -- {* Beware of argument permutation! *}
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   310
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   311
lemma (in comm_monoid) finprod_empty [simp]: 
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   312
  "finprod G f {} = \<one>"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   313
  by (simp add: finprod_def)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   314
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   315
declare funcsetI [intro]
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   316
  funcset_mem [dest]
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   317
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   318
lemma (in comm_monoid) finprod_insert [simp]:
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   319
  "[| finite F; a \<notin> F; f \<in> F -> carrier G; f a \<in> carrier G |] ==>
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   320
   finprod G f (insert a F) = f a \<otimes> finprod G f F"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   321
  apply (rule trans)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   322
   apply (simp add: finprod_def)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   323
  apply (rule trans)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   324
   apply (rule LCD.foldD_insert [OF LCD.intro [of "insert a F"]])
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   325
         apply simp
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   326
         apply (rule m_lcomm)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   327
           apply fast
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   328
          apply fast
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   329
         apply assumption
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   330
        apply (fastsimp intro: m_closed)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   331
       apply simp+
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   332
   apply fast
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   333
  apply (auto simp add: finprod_def)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   334
  done
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   335
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   336
lemma (in comm_monoid) finprod_one [simp]:
14651
02b8f3bcf7fe improved notation;
wenzelm
parents: 14590
diff changeset
   337
  "finite A ==> (\<Otimes>i:A. \<one>) = \<one>"
22265
3c5c6bdf61de Adapted to changes in Finite_Set theory.
berghofe
parents: 20318
diff changeset
   338
proof (induct set: finite)
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   339
  case empty show ?case by simp
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   340
next
15328
35951e6a7855 mod because of change in finite set induction
nipkow
parents: 15095
diff changeset
   341
  case (insert a A)
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   342
  have "(%i. \<one>) \<in> A -> carrier G" by auto
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   343
  with insert show ?case by simp
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   344
qed
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   345
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   346
lemma (in comm_monoid) finprod_closed [simp]:
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   347
  fixes A
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   348
  assumes fin: "finite A" and f: "f \<in> A -> carrier G" 
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   349
  shows "finprod G f A \<in> carrier G"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   350
using fin f
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   351
proof induct
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   352
  case empty show ?case by simp
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   353
next
15328
35951e6a7855 mod because of change in finite set induction
nipkow
parents: 15095
diff changeset
   354
  case (insert a A)
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   355
  then have a: "f a \<in> carrier G" by fast
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   356
  from insert have A: "f \<in> A -> carrier G" by fast
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   357
  from insert A a show ?case by simp
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   358
qed
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   359
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   360
lemma funcset_Int_left [simp, intro]:
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   361
  "[| f \<in> A -> C; f \<in> B -> C |] ==> f \<in> A Int B -> C"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   362
  by fast
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   363
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   364
lemma funcset_Un_left [iff]:
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   365
  "(f \<in> A Un B -> C) = (f \<in> A -> C & f \<in> B -> C)"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   366
  by fast
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   367
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   368
lemma (in comm_monoid) finprod_Un_Int:
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   369
  "[| finite A; finite B; g \<in> A -> carrier G; g \<in> B -> carrier G |] ==>
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   370
     finprod G g (A Un B) \<otimes> finprod G g (A Int B) =
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   371
     finprod G g A \<otimes> finprod G g B"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   372
-- {* The reversed orientation looks more natural, but LOOPS as a simprule! *}
22265
3c5c6bdf61de Adapted to changes in Finite_Set theory.
berghofe
parents: 20318
diff changeset
   373
proof (induct set: finite)
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   374
  case empty then show ?case by (simp add: finprod_closed)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   375
next
15328
35951e6a7855 mod because of change in finite set induction
nipkow
parents: 15095
diff changeset
   376
  case (insert a A)
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   377
  then have a: "g a \<in> carrier G" by fast
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   378
  from insert have A: "g \<in> A -> carrier G" by fast
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   379
  from insert A a show ?case
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   380
    by (simp add: m_ac Int_insert_left insert_absorb finprod_closed
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   381
          Int_mono2 Un_subset_iff) 
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   382
qed
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   383
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   384
lemma (in comm_monoid) finprod_Un_disjoint:
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   385
  "[| finite A; finite B; A Int B = {};
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   386
      g \<in> A -> carrier G; g \<in> B -> carrier G |]
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   387
   ==> finprod G g (A Un B) = finprod G g A \<otimes> finprod G g B"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   388
  apply (subst finprod_Un_Int [symmetric])
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   389
      apply (auto simp add: finprod_closed)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   390
  done
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   391
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   392
lemma (in comm_monoid) finprod_multf:
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   393
  "[| finite A; f \<in> A -> carrier G; g \<in> A -> carrier G |] ==>
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   394
   finprod G (%x. f x \<otimes> g x) A = (finprod G f A \<otimes> finprod G g A)"
22265
3c5c6bdf61de Adapted to changes in Finite_Set theory.
berghofe
parents: 20318
diff changeset
   395
proof (induct set: finite)
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   396
  case empty show ?case by simp
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   397
next
15328
35951e6a7855 mod because of change in finite set induction
nipkow
parents: 15095
diff changeset
   398
  case (insert a A) then
14750
paulson
parents: 14706
diff changeset
   399
  have fA: "f \<in> A -> carrier G" by fast
paulson
parents: 14706
diff changeset
   400
  from insert have fa: "f a \<in> carrier G" by fast
paulson
parents: 14706
diff changeset
   401
  from insert have gA: "g \<in> A -> carrier G" by fast
paulson
parents: 14706
diff changeset
   402
  from insert have ga: "g a \<in> carrier G" by fast
paulson
parents: 14706
diff changeset
   403
  from insert have fgA: "(%x. f x \<otimes> g x) \<in> A -> carrier G"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   404
    by (simp add: Pi_def)
15095
63f5f4c265dd Theories now take advantage of recent syntax improvements with (structure).
ballarin
parents: 14750
diff changeset
   405
  show ?case
63f5f4c265dd Theories now take advantage of recent syntax improvements with (structure).
ballarin
parents: 14750
diff changeset
   406
    by (simp add: insert fA fa gA ga fgA m_ac)
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   407
qed
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   408
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   409
lemma (in comm_monoid) finprod_cong':
14750
paulson
parents: 14706
diff changeset
   410
  "[| A = B; g \<in> B -> carrier G;
paulson
parents: 14706
diff changeset
   411
      !!i. i \<in> B ==> f i = g i |] ==> finprod G f A = finprod G g B"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   412
proof -
14750
paulson
parents: 14706
diff changeset
   413
  assume prems: "A = B" "g \<in> B -> carrier G"
paulson
parents: 14706
diff changeset
   414
    "!!i. i \<in> B ==> f i = g i"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   415
  show ?thesis
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   416
  proof (cases "finite B")
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   417
    case True
14750
paulson
parents: 14706
diff changeset
   418
    then have "!!A. [| A = B; g \<in> B -> carrier G;
paulson
parents: 14706
diff changeset
   419
      !!i. i \<in> B ==> f i = g i |] ==> finprod G f A = finprod G g B"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   420
    proof induct
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   421
      case empty thus ?case by simp
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   422
    next
15328
35951e6a7855 mod because of change in finite set induction
nipkow
parents: 15095
diff changeset
   423
      case (insert x B)
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   424
      then have "finprod G f A = finprod G f (insert x B)" by simp
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   425
      also from insert have "... = f x \<otimes> finprod G f B"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   426
      proof (intro finprod_insert)
23350
50c5b0912a0c tuned proofs: avoid implicit prems;
wenzelm
parents: 22265
diff changeset
   427
	show "finite B" by fact
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   428
      next
23350
50c5b0912a0c tuned proofs: avoid implicit prems;
wenzelm
parents: 22265
diff changeset
   429
	show "x ~: B" by fact
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   430
      next
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   431
	assume "x ~: B" "!!i. i \<in> insert x B \<Longrightarrow> f i = g i"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   432
	  "g \<in> insert x B \<rightarrow> carrier G"
14750
paulson
parents: 14706
diff changeset
   433
	thus "f \<in> B -> carrier G" by fastsimp
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   434
      next
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   435
	assume "x ~: B" "!!i. i \<in> insert x B \<Longrightarrow> f i = g i"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   436
	  "g \<in> insert x B \<rightarrow> carrier G"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   437
	thus "f x \<in> carrier G" by fastsimp
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   438
      qed
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   439
      also from insert have "... = g x \<otimes> finprod G g B" by fastsimp
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   440
      also from insert have "... = finprod G g (insert x B)"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   441
      by (intro finprod_insert [THEN sym]) auto
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   442
      finally show ?case .
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   443
    qed
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   444
    with prems show ?thesis by simp
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   445
  next
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   446
    case False with prems show ?thesis by (simp add: finprod_def)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   447
  qed
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   448
qed
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   449
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   450
lemma (in comm_monoid) finprod_cong:
14750
paulson
parents: 14706
diff changeset
   451
  "[| A = B; f \<in> B -> carrier G = True;
paulson
parents: 14706
diff changeset
   452
      !!i. i \<in> B ==> f i = g i |] ==> finprod G f A = finprod G g B"
14213
7bf882b0a51e Changed order of prems in finprod_cong. Slight speedup.
ballarin
parents: 13936
diff changeset
   453
  (* This order of prems is slightly faster (3%) than the last two swapped. *)
7bf882b0a51e Changed order of prems in finprod_cong. Slight speedup.
ballarin
parents: 13936
diff changeset
   454
  by (rule finprod_cong') force+
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   455
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   456
text {*Usually, if this rule causes a failed congruence proof error,
14750
paulson
parents: 14706
diff changeset
   457
  the reason is that the premise @{text "g \<in> B -> carrier G"} cannot be shown.
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   458
  Adding @{thm [source] Pi_def} to the simpset is often useful.
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   459
  For this reason, @{thm [source] comm_monoid.finprod_cong}
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   460
  is not added to the simpset by default.
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   461
*}
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   462
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   463
declare funcsetI [rule del]
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   464
  funcset_mem [rule del]
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   465
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   466
lemma (in comm_monoid) finprod_0 [simp]:
14750
paulson
parents: 14706
diff changeset
   467
  "f \<in> {0::nat} -> carrier G ==> finprod G f {..0} = f 0"
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   468
by (simp add: Pi_def)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   469
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   470
lemma (in comm_monoid) finprod_Suc [simp]:
14750
paulson
parents: 14706
diff changeset
   471
  "f \<in> {..Suc n} -> carrier G ==>
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   472
   finprod G f {..Suc n} = (f (Suc n) \<otimes> finprod G f {..n})"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   473
by (simp add: Pi_def atMost_Suc)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   474
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   475
lemma (in comm_monoid) finprod_Suc2:
14750
paulson
parents: 14706
diff changeset
   476
  "f \<in> {..Suc n} -> carrier G ==>
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   477
   finprod G f {..Suc n} = (finprod G (%i. f (Suc i)) {..n} \<otimes> f 0)"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   478
proof (induct n)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   479
  case 0 thus ?case by (simp add: Pi_def)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   480
next
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   481
  case Suc thus ?case by (simp add: m_assoc Pi_def)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   482
qed
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   483
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   484
lemma (in comm_monoid) finprod_mult [simp]:
14750
paulson
parents: 14706
diff changeset
   485
  "[| f \<in> {..n} -> carrier G; g \<in> {..n} -> carrier G |] ==>
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   486
     finprod G (%i. f i \<otimes> g i) {..n::nat} =
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   487
     finprod G f {..n} \<otimes> finprod G g {..n}"
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   488
  by (induct n) (simp_all add: m_ac Pi_def)
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   489
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   490
end
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents:
diff changeset
   491