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