src/HOL/Algebra/Group.thy
author ballarin
Fri Feb 14 17:35:56 2003 +0100 (2003-02-14)
changeset 13817 7e031a968443
parent 13813 722593f2f068
child 13835 12b2ffbe543a
permissions -rw-r--r--
Product operator added --- preliminary.
ballarin@13813
     1
(*
ballarin@13813
     2
  Title:  HOL/Algebra/Group.thy
ballarin@13813
     3
  Id:     $Id$
ballarin@13813
     4
  Author: Clemens Ballarin, started 4 February 2003
ballarin@13813
     5
ballarin@13813
     6
Based on work by Florian Kammueller, L C Paulson and Markus Wenzel.
ballarin@13813
     7
*)
ballarin@13813
     8
ballarin@13813
     9
header {* Algebraic Structures up to Abelian Groups *}
ballarin@13813
    10
ballarin@13817
    11
theory Group = FuncSet + FoldSet:
ballarin@13813
    12
ballarin@13813
    13
text {*
ballarin@13813
    14
  Definitions follow Jacobson, Basic Algebra I, Freeman, 1985; with
ballarin@13813
    15
  the exception of \emph{magma} which, following Bourbaki, is a set
ballarin@13813
    16
  together with a binary, closed operation.
ballarin@13813
    17
*}
ballarin@13813
    18
ballarin@13813
    19
section {* From Magmas to Groups *}
ballarin@13813
    20
ballarin@13813
    21
subsection {* Definitions *}
ballarin@13813
    22
ballarin@13817
    23
record 'a semigroup =
ballarin@13813
    24
  carrier :: "'a set"
ballarin@13813
    25
  mult :: "['a, 'a] => 'a" (infixl "\<otimes>\<index>" 70)
ballarin@13813
    26
ballarin@13817
    27
record 'a monoid = "'a semigroup" +
ballarin@13813
    28
  one :: 'a ("\<one>\<index>")
ballarin@13817
    29
ballarin@13817
    30
record 'a group = "'a monoid" +
ballarin@13813
    31
  m_inv :: "'a => 'a" ("inv\<index> _" [81] 80)
ballarin@13813
    32
ballarin@13813
    33
locale magma = struct G +
ballarin@13813
    34
  assumes m_closed [intro, simp]:
ballarin@13813
    35
    "[| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y \<in> carrier G"
ballarin@13813
    36
ballarin@13813
    37
locale semigroup = magma +
ballarin@13813
    38
  assumes m_assoc:
ballarin@13813
    39
    "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13813
    40
     (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)"
ballarin@13813
    41
ballarin@13817
    42
locale l_one = struct G +
ballarin@13813
    43
  assumes one_closed [intro, simp]: "\<one> \<in> carrier G"
ballarin@13813
    44
    and l_one [simp]: "x \<in> carrier G ==> \<one> \<otimes> x = x"
ballarin@13817
    45
ballarin@13817
    46
locale group = semigroup + l_one +
ballarin@13817
    47
  assumes inv_closed [intro, simp]: "x \<in> carrier G ==> inv x \<in> carrier G"
ballarin@13813
    48
    and l_inv: "x \<in> carrier G ==> inv x \<otimes> x = \<one>"
ballarin@13813
    49
ballarin@13813
    50
subsection {* Cancellation Laws and Basic Properties *}
ballarin@13813
    51
ballarin@13813
    52
lemma (in group) l_cancel [simp]:
ballarin@13813
    53
  "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13813
    54
   (x \<otimes> y = x \<otimes> z) = (y = z)"
ballarin@13813
    55
proof
ballarin@13813
    56
  assume eq: "x \<otimes> y = x \<otimes> z"
ballarin@13813
    57
    and G: "x \<in> carrier G" "y \<in> carrier G" "z \<in> carrier G"
ballarin@13813
    58
  then have "(inv x \<otimes> x) \<otimes> y = (inv x \<otimes> x) \<otimes> z" by (simp add: m_assoc)
ballarin@13813
    59
  with G show "y = z" by (simp add: l_inv)
ballarin@13813
    60
next
ballarin@13813
    61
  assume eq: "y = z"
ballarin@13813
    62
    and G: "x \<in> carrier G" "y \<in> carrier G" "z \<in> carrier G"
ballarin@13813
    63
  then show "x \<otimes> y = x \<otimes> z" by simp
ballarin@13813
    64
qed
ballarin@13813
    65
ballarin@13813
    66
lemma (in group) r_one [simp]:  
ballarin@13813
    67
  "x \<in> carrier G ==> x \<otimes> \<one> = x"
ballarin@13813
    68
proof -
ballarin@13813
    69
  assume x: "x \<in> carrier G"
ballarin@13813
    70
  then have "inv x \<otimes> (x \<otimes> \<one>) = inv x \<otimes> x"
ballarin@13813
    71
    by (simp add: m_assoc [symmetric] l_inv)
ballarin@13813
    72
  with x show ?thesis by simp 
ballarin@13813
    73
qed
ballarin@13813
    74
ballarin@13813
    75
lemma (in group) r_inv:
ballarin@13813
    76
  "x \<in> carrier G ==> x \<otimes> inv x = \<one>"
ballarin@13813
    77
proof -
ballarin@13813
    78
  assume x: "x \<in> carrier G"
ballarin@13813
    79
  then have "inv x \<otimes> (x \<otimes> inv x) = inv x \<otimes> \<one>"
ballarin@13813
    80
    by (simp add: m_assoc [symmetric] l_inv)
ballarin@13813
    81
  with x show ?thesis by (simp del: r_one)
ballarin@13813
    82
qed
ballarin@13813
    83
ballarin@13813
    84
lemma (in group) r_cancel [simp]:
ballarin@13813
    85
  "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13813
    86
   (y \<otimes> x = z \<otimes> x) = (y = z)"
ballarin@13813
    87
proof
ballarin@13813
    88
  assume eq: "y \<otimes> x = z \<otimes> x"
ballarin@13813
    89
    and G: "x \<in> carrier G" "y \<in> carrier G" "z \<in> carrier G"
ballarin@13813
    90
  then have "y \<otimes> (x \<otimes> inv x) = z \<otimes> (x \<otimes> inv x)"
ballarin@13813
    91
    by (simp add: m_assoc [symmetric])
ballarin@13813
    92
  with G show "y = z" by (simp add: r_inv)
ballarin@13813
    93
next
ballarin@13813
    94
  assume eq: "y = z"
ballarin@13813
    95
    and G: "x \<in> carrier G" "y \<in> carrier G" "z \<in> carrier G"
ballarin@13813
    96
  then show "y \<otimes> x = z \<otimes> x" by simp
ballarin@13813
    97
qed
ballarin@13813
    98
ballarin@13813
    99
lemma (in group) inv_inv [simp]:
ballarin@13813
   100
  "x \<in> carrier G ==> inv (inv x) = x"
ballarin@13813
   101
proof -
ballarin@13813
   102
  assume x: "x \<in> carrier G"
ballarin@13813
   103
  then have "inv x \<otimes> inv (inv x) = inv x \<otimes> x" by (simp add: l_inv r_inv)
ballarin@13813
   104
  with x show ?thesis by simp
ballarin@13813
   105
qed
ballarin@13813
   106
ballarin@13813
   107
lemma (in group) inv_mult:
ballarin@13813
   108
  "[| x \<in> carrier G; y \<in> carrier G |] ==> inv (x \<otimes> y) = inv y \<otimes> inv x"
ballarin@13813
   109
proof -
ballarin@13813
   110
  assume G: "x \<in> carrier G" "y \<in> carrier G"
ballarin@13813
   111
  then have "inv (x \<otimes> y) \<otimes> (x \<otimes> y) = (inv y \<otimes> inv x) \<otimes> (x \<otimes> y)"
ballarin@13813
   112
    by (simp add: m_assoc l_inv) (simp add: m_assoc [symmetric] l_inv)
ballarin@13813
   113
  with G show ?thesis by simp
ballarin@13813
   114
qed
ballarin@13813
   115
ballarin@13813
   116
subsection {* Substructures *}
ballarin@13813
   117
ballarin@13813
   118
locale submagma = var H + struct G +
ballarin@13813
   119
  assumes subset [intro, simp]: "H \<subseteq> carrier G"
ballarin@13813
   120
    and m_closed [intro, simp]: "[| x \<in> H; y \<in> H |] ==> x \<otimes> y \<in> H"
ballarin@13813
   121
ballarin@13813
   122
declare (in submagma) magma.intro [intro] semigroup.intro [intro]
ballarin@13813
   123
ballarin@13813
   124
(*
ballarin@13813
   125
alternative definition of submagma
ballarin@13813
   126
ballarin@13813
   127
locale submagma = var H + struct G +
ballarin@13813
   128
  assumes subset [intro, simp]: "carrier H \<subseteq> carrier G"
ballarin@13813
   129
    and m_equal [simp]: "mult H = mult G"
ballarin@13813
   130
    and m_closed [intro, simp]:
ballarin@13813
   131
      "[| x \<in> carrier H; y \<in> carrier H |] ==> x \<otimes> y \<in> carrier H"
ballarin@13813
   132
*)
ballarin@13813
   133
ballarin@13813
   134
lemma submagma_imp_subset:
ballarin@13813
   135
  "submagma H G ==> H \<subseteq> carrier G"
ballarin@13813
   136
  by (rule submagma.subset)
ballarin@13813
   137
ballarin@13813
   138
lemma (in submagma) subsetD [dest, simp]:
ballarin@13813
   139
  "x \<in> H ==> x \<in> carrier G"
ballarin@13813
   140
  using subset by blast
ballarin@13813
   141
ballarin@13813
   142
lemma (in submagma) magmaI [intro]:
ballarin@13813
   143
  includes magma G
ballarin@13813
   144
  shows "magma (G(| carrier := H |))"
ballarin@13813
   145
  by rule simp
ballarin@13813
   146
ballarin@13813
   147
lemma (in submagma) semigroup_axiomsI [intro]:
ballarin@13813
   148
  includes semigroup G
ballarin@13813
   149
  shows "semigroup_axioms (G(| carrier := H |))"
ballarin@13813
   150
    by rule (simp add: m_assoc)
ballarin@13813
   151
ballarin@13813
   152
lemma (in submagma) semigroupI [intro]:
ballarin@13813
   153
  includes semigroup G
ballarin@13813
   154
  shows "semigroup (G(| carrier := H |))"
ballarin@13813
   155
  using prems by fast
ballarin@13813
   156
ballarin@13813
   157
locale subgroup = submagma H G +
ballarin@13813
   158
  assumes one_closed [intro, simp]: "\<one> \<in> H"
ballarin@13813
   159
    and m_inv_closed [intro, simp]: "x \<in> H ==> inv x \<in> H"
ballarin@13813
   160
ballarin@13813
   161
declare (in subgroup) group.intro [intro]
ballarin@13813
   162
ballarin@13817
   163
lemma (in subgroup) l_oneI [intro]:
ballarin@13817
   164
  includes l_one G
ballarin@13817
   165
  shows "l_one (G(| carrier := H |))"
ballarin@13817
   166
  by rule simp_all
ballarin@13817
   167
ballarin@13813
   168
lemma (in subgroup) group_axiomsI [intro]:
ballarin@13813
   169
  includes group G
ballarin@13813
   170
  shows "group_axioms (G(| carrier := H |))"
ballarin@13813
   171
  by rule (simp_all add: l_inv)
ballarin@13813
   172
ballarin@13813
   173
lemma (in subgroup) groupI [intro]:
ballarin@13813
   174
  includes group G
ballarin@13813
   175
  shows "group (G(| carrier := H |))"
ballarin@13813
   176
  using prems by fast
ballarin@13813
   177
ballarin@13813
   178
text {*
ballarin@13813
   179
  Since @{term H} is nonempty, it contains some element @{term x}.  Since
ballarin@13813
   180
  it is closed under inverse, it contains @{text "inv x"}.  Since
ballarin@13813
   181
  it is closed under product, it contains @{text "x \<otimes> inv x = \<one>"}.
ballarin@13813
   182
*}
ballarin@13813
   183
ballarin@13813
   184
lemma (in group) one_in_subset:
ballarin@13813
   185
  "[| H \<subseteq> carrier G; H \<noteq> {}; \<forall>a \<in> H. inv a \<in> H; \<forall>a\<in>H. \<forall>b\<in>H. a \<otimes> b \<in> H |]
ballarin@13813
   186
   ==> \<one> \<in> H"
ballarin@13813
   187
by (force simp add: l_inv)
ballarin@13813
   188
ballarin@13813
   189
text {* A characterization of subgroups: closed, non-empty subset. *}
ballarin@13813
   190
ballarin@13813
   191
lemma (in group) subgroupI:
ballarin@13813
   192
  assumes subset: "H \<subseteq> carrier G" and non_empty: "H \<noteq> {}"
ballarin@13813
   193
    and inv: "!!a. a \<in> H ==> inv a \<in> H"
ballarin@13813
   194
    and mult: "!!a b. [|a \<in> H; b \<in> H|] ==> a \<otimes> b \<in> H"
ballarin@13813
   195
  shows "subgroup H G"
ballarin@13813
   196
proof
ballarin@13813
   197
  from subset and mult show "submagma H G" ..
ballarin@13813
   198
next
ballarin@13813
   199
  have "\<one> \<in> H" by (rule one_in_subset) (auto simp only: prems)
ballarin@13813
   200
  with inv show "subgroup_axioms H G"
ballarin@13813
   201
    by (intro subgroup_axioms.intro) simp_all
ballarin@13813
   202
qed
ballarin@13813
   203
ballarin@13813
   204
text {*
ballarin@13813
   205
  Repeat facts of submagmas for subgroups.  Necessary???
ballarin@13813
   206
*}
ballarin@13813
   207
ballarin@13813
   208
lemma (in subgroup) subset:
ballarin@13813
   209
  "H \<subseteq> carrier G"
ballarin@13813
   210
  ..
ballarin@13813
   211
ballarin@13813
   212
lemma (in subgroup) m_closed:
ballarin@13813
   213
  "[| x \<in> H; y \<in> H |] ==> x \<otimes> y \<in> H"
ballarin@13813
   214
  ..
ballarin@13813
   215
ballarin@13813
   216
declare magma.m_closed [simp]
ballarin@13813
   217
ballarin@13817
   218
declare l_one.one_closed [iff] group.inv_closed [simp]
ballarin@13817
   219
  l_one.l_one [simp] group.r_one [simp] group.inv_inv [simp]
ballarin@13813
   220
ballarin@13813
   221
lemma subgroup_nonempty:
ballarin@13813
   222
  "~ subgroup {} G"
ballarin@13813
   223
  by (blast dest: subgroup.one_closed)
ballarin@13813
   224
ballarin@13813
   225
lemma (in subgroup) finite_imp_card_positive:
ballarin@13813
   226
  "finite (carrier G) ==> 0 < card H"
ballarin@13813
   227
proof (rule classical)
ballarin@13813
   228
  have sub: "subgroup H G" using prems ..
ballarin@13813
   229
  assume fin: "finite (carrier G)"
ballarin@13813
   230
    and zero: "~ 0 < card H"
ballarin@13813
   231
  then have "finite H" by (blast intro: finite_subset dest: subset)
ballarin@13813
   232
  with zero sub have "subgroup {} G" by simp
ballarin@13813
   233
  with subgroup_nonempty show ?thesis by contradiction
ballarin@13813
   234
qed
ballarin@13813
   235
ballarin@13813
   236
subsection {* Direct Products *}
ballarin@13813
   237
ballarin@13813
   238
constdefs
ballarin@13817
   239
  DirProdSemigroup ::
ballarin@13817
   240
    "[('a, 'c) semigroup_scheme, ('b, 'd) semigroup_scheme]
ballarin@13817
   241
    => ('a \<times> 'b) semigroup"
ballarin@13817
   242
    (infixr "\<times>\<^sub>s" 80)
ballarin@13817
   243
  "G \<times>\<^sub>s H == (| carrier = carrier G \<times> carrier H,
ballarin@13817
   244
    mult = (%(xg, xh) (yg, yh). (mult G xg yg, mult H xh yh)) |)"
ballarin@13817
   245
ballarin@13817
   246
  DirProdMonoid ::
ballarin@13817
   247
    "[('a, 'c) monoid_scheme, ('b, 'd) monoid_scheme] => ('a \<times> 'b) monoid"
ballarin@13813
   248
    (infixr "\<times>\<^sub>m" 80)
ballarin@13817
   249
  "G \<times>\<^sub>m H == (| carrier = carrier (G \<times>\<^sub>s H),
ballarin@13817
   250
    mult = mult (G \<times>\<^sub>s H),
ballarin@13817
   251
    one = (one G, one H) |)"
ballarin@13813
   252
ballarin@13813
   253
  DirProdGroup ::
ballarin@13813
   254
    "[('a, 'c) group_scheme, ('b, 'd) group_scheme] => ('a \<times> 'b) group"
ballarin@13813
   255
    (infixr "\<times>\<^sub>g" 80)
ballarin@13813
   256
  "G \<times>\<^sub>g H == (| carrier = carrier (G \<times>\<^sub>m H),
ballarin@13813
   257
    mult = mult (G \<times>\<^sub>m H),
ballarin@13817
   258
    one = one (G \<times>\<^sub>m H),
ballarin@13813
   259
    m_inv = (%(g, h). (m_inv G g, m_inv H h)) |)"
ballarin@13813
   260
ballarin@13817
   261
lemma DirProdSemigroup_magma:
ballarin@13813
   262
  includes magma G + magma H
ballarin@13817
   263
  shows "magma (G \<times>\<^sub>s H)"
ballarin@13817
   264
  by rule (auto simp add: DirProdSemigroup_def)
ballarin@13813
   265
ballarin@13817
   266
lemma DirProdSemigroup_semigroup_axioms:
ballarin@13813
   267
  includes semigroup G + semigroup H
ballarin@13817
   268
  shows "semigroup_axioms (G \<times>\<^sub>s H)"
ballarin@13817
   269
  by rule (auto simp add: DirProdSemigroup_def G.m_assoc H.m_assoc)
ballarin@13813
   270
ballarin@13817
   271
lemma DirProdSemigroup_semigroup:
ballarin@13813
   272
  includes semigroup G + semigroup H
ballarin@13817
   273
  shows "semigroup (G \<times>\<^sub>s H)"
ballarin@13813
   274
  using prems
ballarin@13813
   275
  by (fast intro: semigroup.intro
ballarin@13817
   276
    DirProdSemigroup_magma DirProdSemigroup_semigroup_axioms)
ballarin@13813
   277
ballarin@13813
   278
lemma DirProdGroup_magma:
ballarin@13813
   279
  includes magma G + magma H
ballarin@13813
   280
  shows "magma (G \<times>\<^sub>g H)"
ballarin@13817
   281
  by rule
ballarin@13817
   282
    (auto simp add: DirProdGroup_def DirProdMonoid_def DirProdSemigroup_def)
ballarin@13813
   283
ballarin@13813
   284
lemma DirProdGroup_semigroup_axioms:
ballarin@13813
   285
  includes semigroup G + semigroup H
ballarin@13813
   286
  shows "semigroup_axioms (G \<times>\<^sub>g H)"
ballarin@13813
   287
  by rule
ballarin@13817
   288
    (auto simp add: DirProdGroup_def DirProdMonoid_def DirProdSemigroup_def
ballarin@13817
   289
      G.m_assoc H.m_assoc)
ballarin@13813
   290
ballarin@13813
   291
lemma DirProdGroup_semigroup:
ballarin@13813
   292
  includes semigroup G + semigroup H
ballarin@13813
   293
  shows "semigroup (G \<times>\<^sub>g H)"
ballarin@13813
   294
  using prems
ballarin@13813
   295
  by (fast intro: semigroup.intro
ballarin@13813
   296
    DirProdGroup_magma DirProdGroup_semigroup_axioms)
ballarin@13813
   297
ballarin@13813
   298
(* ... and further lemmas for group ... *)
ballarin@13813
   299
ballarin@13817
   300
lemma DirProdGroup_group:
ballarin@13813
   301
  includes group G + group H
ballarin@13813
   302
  shows "group (G \<times>\<^sub>g H)"
ballarin@13813
   303
by rule
ballarin@13817
   304
  (auto intro: magma.intro l_one.intro
ballarin@13817
   305
      semigroup_axioms.intro group_axioms.intro
ballarin@13817
   306
    simp add: DirProdGroup_def DirProdMonoid_def DirProdSemigroup_def
ballarin@13813
   307
      G.m_assoc H.m_assoc G.l_inv H.l_inv)
ballarin@13813
   308
ballarin@13813
   309
subsection {* Homomorphisms *}
ballarin@13813
   310
ballarin@13813
   311
constdefs
ballarin@13817
   312
  hom :: "[('a, 'c) semigroup_scheme, ('b, 'd) semigroup_scheme]
ballarin@13817
   313
    => ('a => 'b)set"
ballarin@13813
   314
  "hom G H ==
ballarin@13813
   315
    {h. h \<in> carrier G -> carrier H &
ballarin@13813
   316
      (\<forall>x \<in> carrier G. \<forall>y \<in> carrier G. h (mult G x y) = mult H (h x) (h y))}"
ballarin@13813
   317
ballarin@13813
   318
lemma (in semigroup) hom:
ballarin@13813
   319
  includes semigroup G
ballarin@13813
   320
  shows "semigroup (| carrier = hom G G, mult = op o |)"
ballarin@13813
   321
proof
ballarin@13813
   322
  show "magma (| carrier = hom G G, mult = op o |)"
ballarin@13813
   323
    by rule (simp add: Pi_def hom_def)
ballarin@13813
   324
next
ballarin@13813
   325
  show "semigroup_axioms (| carrier = hom G G, mult = op o |)"
ballarin@13813
   326
    by rule (simp add: o_assoc)
ballarin@13813
   327
qed
ballarin@13813
   328
ballarin@13813
   329
lemma hom_mult:
ballarin@13813
   330
  "[| h \<in> hom G H; x \<in> carrier G; y \<in> carrier G |] 
ballarin@13813
   331
   ==> h (mult G x y) = mult H (h x) (h y)"
ballarin@13813
   332
  by (simp add: hom_def) 
ballarin@13813
   333
ballarin@13813
   334
lemma hom_closed:
ballarin@13813
   335
  "[| h \<in> hom G H; x \<in> carrier G |] ==> h x \<in> carrier H"
ballarin@13813
   336
  by (auto simp add: hom_def funcset_mem)
ballarin@13813
   337
ballarin@13813
   338
locale group_hom = group G + group H + var h +
ballarin@13813
   339
  assumes homh: "h \<in> hom G H"
ballarin@13813
   340
  notes hom_mult [simp] = hom_mult [OF homh]
ballarin@13813
   341
    and hom_closed [simp] = hom_closed [OF homh]
ballarin@13813
   342
ballarin@13813
   343
lemma (in group_hom) one_closed [simp]:
ballarin@13813
   344
  "h \<one> \<in> carrier H"
ballarin@13813
   345
  by simp
ballarin@13813
   346
ballarin@13813
   347
lemma (in group_hom) hom_one [simp]:
ballarin@13813
   348
  "h \<one> = \<one>\<^sub>2"
ballarin@13813
   349
proof -
ballarin@13813
   350
  have "h \<one> \<otimes>\<^sub>2 \<one>\<^sub>2 = h \<one> \<otimes>\<^sub>2 h \<one>"
ballarin@13813
   351
    by (simp add: hom_mult [symmetric] del: hom_mult)
ballarin@13813
   352
  then show ?thesis by (simp del: r_one)
ballarin@13813
   353
qed
ballarin@13813
   354
ballarin@13813
   355
lemma (in group_hom) inv_closed [simp]:
ballarin@13813
   356
  "x \<in> carrier G ==> h (inv x) \<in> carrier H"
ballarin@13813
   357
  by simp
ballarin@13813
   358
ballarin@13813
   359
lemma (in group_hom) hom_inv [simp]:
ballarin@13813
   360
  "x \<in> carrier G ==> h (inv x) = inv\<^sub>2 (h x)"
ballarin@13813
   361
proof -
ballarin@13813
   362
  assume x: "x \<in> carrier G"
ballarin@13813
   363
  then have "h x \<otimes>\<^sub>2 h (inv x) = \<one>\<^sub>2"
ballarin@13813
   364
    by (simp add: hom_mult [symmetric] G.r_inv del: hom_mult)
ballarin@13813
   365
  also from x have "... = h x \<otimes>\<^sub>2 inv\<^sub>2 (h x)"
ballarin@13813
   366
    by (simp add: hom_mult [symmetric] H.r_inv del: hom_mult)
ballarin@13813
   367
  finally have "h x \<otimes>\<^sub>2 h (inv x) = h x \<otimes>\<^sub>2 inv\<^sub>2 (h x)" .
ballarin@13813
   368
  with x show ?thesis by simp
ballarin@13813
   369
qed
ballarin@13813
   370
ballarin@13813
   371
section {* Abelian Structures *}
ballarin@13813
   372
ballarin@13813
   373
subsection {* Definition *}
ballarin@13813
   374
ballarin@13813
   375
locale abelian_semigroup = semigroup +
ballarin@13813
   376
  assumes m_comm: "[| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y = y \<otimes> x"
ballarin@13813
   377
ballarin@13813
   378
lemma (in abelian_semigroup) m_lcomm:
ballarin@13813
   379
  "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13813
   380
   x \<otimes> (y \<otimes> z) = y \<otimes> (x \<otimes> z)"
ballarin@13813
   381
proof -
ballarin@13813
   382
  assume xyz: "x \<in> carrier G" "y \<in> carrier G" "z \<in> carrier G"
ballarin@13813
   383
  from xyz have "x \<otimes> (y \<otimes> z) = (x \<otimes> y) \<otimes> z" by (simp add: m_assoc)
ballarin@13813
   384
  also from xyz have "... = (y \<otimes> x) \<otimes> z" by (simp add: m_comm)
ballarin@13813
   385
  also from xyz have "... = y \<otimes> (x \<otimes> z)" by (simp add: m_assoc)
ballarin@13813
   386
  finally show ?thesis .
ballarin@13813
   387
qed
ballarin@13813
   388
ballarin@13813
   389
lemmas (in abelian_semigroup) ac = m_assoc m_comm m_lcomm
ballarin@13813
   390
ballarin@13817
   391
locale abelian_monoid = abelian_semigroup + l_one
ballarin@13817
   392
ballarin@13817
   393
lemma (in abelian_monoid) l_one [simp]:
ballarin@13817
   394
  "x \<in> carrier G ==> x \<otimes> \<one> = x"
ballarin@13817
   395
proof -
ballarin@13817
   396
  assume G: "x \<in> carrier G"
ballarin@13817
   397
  then have "x \<otimes> \<one> = \<one> \<otimes> x" by (simp add: m_comm)
ballarin@13817
   398
  also from G have "... = x" by simp
ballarin@13817
   399
  finally show ?thesis .
ballarin@13817
   400
qed
ballarin@13817
   401
ballarin@13817
   402
locale abelian_group = abelian_monoid + group
ballarin@13817
   403
ballarin@13817
   404
subsection {* Products over Finite Sets *}
ballarin@13817
   405
ballarin@13817
   406
locale finite_prod = abelian_monoid + var prod +
ballarin@13817
   407
  defines "prod == (%f A. if finite A
ballarin@13817
   408
      then foldD (carrier G) (op \<otimes> o f) \<one> A
ballarin@13817
   409
      else arbitrary)"
ballarin@13817
   410
ballarin@13817
   411
(* TODO: nice syntax for the summation operator inside the locale
ballarin@13817
   412
   like \<Otimes>\<index> i\<in>A. f i, probably needs hand-coded translation *)
ballarin@13817
   413
ballarin@13817
   414
ML_setup {* 
ballarin@13817
   415
ballarin@13817
   416
Context.>> (fn thy => (simpset_ref_of thy :=
ballarin@13817
   417
  simpset_of thy setsubgoaler asm_full_simp_tac; thy)) *}
ballarin@13817
   418
ballarin@13817
   419
lemma (in finite_prod) prod_empty [simp]: 
ballarin@13817
   420
  "prod f {} = \<one>"
ballarin@13817
   421
  by (simp add: prod_def)
ballarin@13817
   422
ballarin@13817
   423
ML_setup {* 
ballarin@13817
   424
ballarin@13817
   425
Context.>> (fn thy => (simpset_ref_of thy :=
ballarin@13817
   426
  simpset_of thy setsubgoaler asm_simp_tac; thy)) *}
ballarin@13817
   427
ballarin@13817
   428
declare funcsetI [intro]
ballarin@13817
   429
  funcset_mem [dest]
ballarin@13817
   430
ballarin@13817
   431
lemma (in finite_prod) prod_insert [simp]:
ballarin@13817
   432
  "[| finite F; a \<notin> F; f \<in> F -> carrier G; f a \<in> carrier G |] ==>
ballarin@13817
   433
   prod f (insert a F) = f a \<otimes> prod f F"
ballarin@13817
   434
  apply (rule trans)
ballarin@13817
   435
  apply (simp add: prod_def)
ballarin@13817
   436
  apply (rule trans)
ballarin@13817
   437
  apply (rule LCD.foldD_insert [OF LCD.intro [of "insert a F"]])
ballarin@13817
   438
    apply simp
ballarin@13817
   439
    apply (rule m_lcomm)
ballarin@13817
   440
      apply fast apply fast apply assumption
ballarin@13817
   441
    apply (fastsimp intro: m_closed)
ballarin@13817
   442
    apply simp+ apply fast
ballarin@13817
   443
  apply (auto simp add: prod_def)
ballarin@13817
   444
  done
ballarin@13817
   445
ballarin@13817
   446
lemma (in finite_prod) prod_one:
ballarin@13817
   447
  "finite A ==> prod (%i. \<one>) A = \<one>"
ballarin@13817
   448
proof (induct set: Finites)
ballarin@13817
   449
  case empty show ?case by simp
ballarin@13817
   450
next
ballarin@13817
   451
  case (insert A a)
ballarin@13817
   452
  have "(%i. \<one>) \<in> A -> carrier G" by auto
ballarin@13817
   453
  with insert show ?case by simp
ballarin@13817
   454
qed
ballarin@13817
   455
ballarin@13817
   456
(*
ballarin@13817
   457
lemma prod_eq_0_iff [simp]:
ballarin@13817
   458
    "finite F ==> (prod f F = 0) = (ALL a:F. f a = (0::nat))"
ballarin@13817
   459
  by (induct set: Finites) auto
ballarin@13817
   460
ballarin@13817
   461
lemma prod_SucD: "prod f A = Suc n ==> EX a:A. 0 < f a"
ballarin@13817
   462
  apply (case_tac "finite A")
ballarin@13817
   463
   prefer 2 apply (simp add: prod_def)
ballarin@13817
   464
  apply (erule rev_mp)
ballarin@13817
   465
  apply (erule finite_induct)
ballarin@13817
   466
   apply auto
ballarin@13817
   467
  done
ballarin@13817
   468
ballarin@13817
   469
lemma card_eq_prod: "finite A ==> card A = prod (\<lambda>x. 1) A"
ballarin@13817
   470
*)  -- {* Could allow many @{text "card"} proofs to be simplified. *}
ballarin@13817
   471
(*
ballarin@13817
   472
  by (induct set: Finites) auto
ballarin@13817
   473
*)
ballarin@13817
   474
ballarin@13817
   475
lemma (in finite_prod) prod_closed:
ballarin@13817
   476
  fixes A
ballarin@13817
   477
  assumes fin: "finite A" and f: "f \<in> A -> carrier G" 
ballarin@13817
   478
  shows "prod f A \<in> carrier G"
ballarin@13817
   479
using fin f
ballarin@13817
   480
proof induct
ballarin@13817
   481
  case empty show ?case by simp
ballarin@13817
   482
next
ballarin@13817
   483
  case (insert A a)
ballarin@13817
   484
  then have a: "f a \<in> carrier G" by fast
ballarin@13817
   485
  from insert have A: "f \<in> A -> carrier G" by fast
ballarin@13817
   486
  from insert A a show ?case by simp
ballarin@13817
   487
qed
ballarin@13817
   488
ballarin@13817
   489
lemma funcset_Int_left [simp, intro]:
ballarin@13817
   490
  "[| f \<in> A -> C; f \<in> B -> C |] ==> f \<in> A Int B -> C"
ballarin@13817
   491
  by fast
ballarin@13817
   492
ballarin@13817
   493
lemma funcset_Un_left [iff]:
ballarin@13817
   494
  "(f \<in> A Un B -> C) = (f \<in> A -> C & f \<in> B -> C)"
ballarin@13817
   495
  by fast
ballarin@13817
   496
ballarin@13817
   497
lemma (in finite_prod) prod_Un_Int:
ballarin@13817
   498
  "[| finite A; finite B; g \<in> A -> carrier G; g \<in> B -> carrier G |] ==>
ballarin@13817
   499
   prod g (A Un B) \<otimes> prod g (A Int B) = prod g A \<otimes> prod g B"
ballarin@13817
   500
  -- {* The reversed orientation looks more natural, but LOOPS as a simprule! *}
ballarin@13817
   501
proof (induct set: Finites)
ballarin@13817
   502
  case empty then show ?case by (simp add: prod_closed)
ballarin@13817
   503
next
ballarin@13817
   504
  case (insert A a)
ballarin@13817
   505
  then have a: "g a \<in> carrier G" by fast
ballarin@13817
   506
  from insert have A: "g \<in> A -> carrier G" by fast
ballarin@13817
   507
  from insert A a show ?case
ballarin@13817
   508
    by (simp add: ac Int_insert_left insert_absorb prod_closed
ballarin@13817
   509
          Int_mono2 Un_subset_iff) 
ballarin@13817
   510
qed
ballarin@13817
   511
ballarin@13817
   512
lemma (in finite_prod) prod_Un_disjoint:
ballarin@13817
   513
  "[| finite A; finite B; A Int B = {};
ballarin@13817
   514
      g \<in> A -> carrier G; g \<in> B -> carrier G |]
ballarin@13817
   515
   ==> prod g (A Un B) = prod g A \<otimes> prod g B"
ballarin@13817
   516
  apply (subst prod_Un_Int [symmetric])
ballarin@13817
   517
    apply (auto simp add: prod_closed)
ballarin@13817
   518
  done
ballarin@13817
   519
ballarin@13817
   520
(*
ballarin@13817
   521
lemma prod_UN_disjoint:
ballarin@13817
   522
  fixes f :: "'a => 'b::plus_ac0"
ballarin@13817
   523
  shows
ballarin@13817
   524
    "finite I ==> (ALL i:I. finite (A i)) ==>
ballarin@13817
   525
        (ALL i:I. ALL j:I. i \<noteq> j --> A i Int A j = {}) ==>
ballarin@13817
   526
      prod f (UNION I A) = prod (\<lambda>i. prod f (A i)) I"
ballarin@13817
   527
  apply (induct set: Finites)
ballarin@13817
   528
   apply simp
ballarin@13817
   529
  apply atomize
ballarin@13817
   530
  apply (subgoal_tac "ALL i:F. x \<noteq> i")
ballarin@13817
   531
   prefer 2 apply blast
ballarin@13817
   532
  apply (subgoal_tac "A x Int UNION F A = {}")
ballarin@13817
   533
   prefer 2 apply blast
ballarin@13817
   534
  apply (simp add: prod_Un_disjoint)
ballarin@13817
   535
  done
ballarin@13817
   536
*)
ballarin@13817
   537
ballarin@13817
   538
lemma (in finite_prod) prod_addf:
ballarin@13817
   539
  "[| finite A; f \<in> A -> carrier G; g \<in> A -> carrier G |] ==>
ballarin@13817
   540
   prod (%x. f x \<otimes> g x) A = (prod f A \<otimes> prod g A)"
ballarin@13817
   541
proof (induct set: Finites)
ballarin@13817
   542
  case empty show ?case by simp
ballarin@13817
   543
next
ballarin@13817
   544
  case (insert A a) then
ballarin@13817
   545
  have fA: "f : A -> carrier G" by fast
ballarin@13817
   546
  from insert have fa: "f a : carrier G" by fast
ballarin@13817
   547
  from insert have gA: "g : A -> carrier G" by fast
ballarin@13817
   548
  from insert have ga: "g a : carrier G" by fast
ballarin@13817
   549
  from insert have fga: "(%x. f x \<otimes> g x) a : carrier G" by (simp add: Pi_def)
ballarin@13817
   550
  from insert have fgA: "(%x. f x \<otimes> g x) : A -> carrier G"
ballarin@13817
   551
    by (simp add: Pi_def)
ballarin@13817
   552
  show ?case  (* check if all simps are really necessary *)
ballarin@13817
   553
    by (simp add: insert fA fa gA ga fgA fga ac prod_closed Int_insert_left insert_absorb Int_mono2 Un_subset_iff)
ballarin@13817
   554
qed
ballarin@13817
   555
ballarin@13817
   556
(*
ballarin@13817
   557
lemma prod_Un: "finite A ==> finite B ==>
ballarin@13817
   558
    (prod f (A Un B) :: nat) = prod f A + prod f B - prod f (A Int B)"
ballarin@13817
   559
  -- {* For the natural numbers, we have subtraction. *}
ballarin@13817
   560
  apply (subst prod_Un_Int [symmetric])
ballarin@13817
   561
    apply auto
ballarin@13817
   562
  done
ballarin@13817
   563
ballarin@13817
   564
lemma prod_diff1: "(prod f (A - {a}) :: nat) =
ballarin@13817
   565
    (if a:A then prod f A - f a else prod f A)"
ballarin@13817
   566
  apply (case_tac "finite A")
ballarin@13817
   567
   prefer 2 apply (simp add: prod_def)
ballarin@13817
   568
  apply (erule finite_induct)
ballarin@13817
   569
   apply (auto simp add: insert_Diff_if)
ballarin@13817
   570
  apply (drule_tac a = a in mk_disjoint_insert)
ballarin@13817
   571
  apply auto
ballarin@13817
   572
  done
ballarin@13817
   573
*)
ballarin@13817
   574
ballarin@13817
   575
lemma (in finite_prod) prod_cong:
ballarin@13817
   576
  "[| A = B; g : B -> carrier G;
ballarin@13817
   577
      !!i. i : B ==> f i = g i |] ==> prod f A = prod g B"
ballarin@13817
   578
proof -
ballarin@13817
   579
  assume prems: "A = B" "g : B -> carrier G"
ballarin@13817
   580
    "!!i. i : B ==> f i = g i"
ballarin@13817
   581
  show ?thesis
ballarin@13817
   582
  proof (cases "finite B")
ballarin@13817
   583
    case True
ballarin@13817
   584
    then have "!!A. [| A = B; g : B -> carrier G;
ballarin@13817
   585
      !!i. i : B ==> f i = g i |] ==> prod f A = prod g B"
ballarin@13817
   586
    proof induct
ballarin@13817
   587
      case empty thus ?case by simp
ballarin@13817
   588
    next
ballarin@13817
   589
      case (insert B x)
ballarin@13817
   590
      then have "prod f A = prod f (insert x B)" by simp
ballarin@13817
   591
      also from insert have "... = f x \<otimes> prod f B"
ballarin@13817
   592
      proof (intro prod_insert)
ballarin@13817
   593
	show "finite B" .
ballarin@13817
   594
      next
ballarin@13817
   595
	show "x ~: B" .
ballarin@13817
   596
      next
ballarin@13817
   597
	assume "x ~: B" "!!i. i \<in> insert x B \<Longrightarrow> f i = g i"
ballarin@13817
   598
	  "g \<in> insert x B \<rightarrow> carrier G"
ballarin@13817
   599
	thus "f : B -> carrier G" by fastsimp
ballarin@13817
   600
      next
ballarin@13817
   601
	assume "x ~: B" "!!i. i \<in> insert x B \<Longrightarrow> f i = g i"
ballarin@13817
   602
	  "g \<in> insert x B \<rightarrow> carrier G"
ballarin@13817
   603
	thus "f x \<in> carrier G" by fastsimp
ballarin@13817
   604
      qed
ballarin@13817
   605
      also from insert have "... = g x \<otimes> prod g B" by fastsimp
ballarin@13817
   606
      also from insert have "... = prod g (insert x B)"
ballarin@13817
   607
      by (intro prod_insert [THEN sym]) auto
ballarin@13817
   608
      finally show ?case .
ballarin@13817
   609
    qed
ballarin@13817
   610
    with prems show ?thesis by simp
ballarin@13817
   611
  next
ballarin@13817
   612
    case False with prems show ?thesis by (simp add: prod_def)
ballarin@13817
   613
  qed
ballarin@13817
   614
qed
ballarin@13817
   615
ballarin@13817
   616
lemma (in finite_prod) prod_cong1 [cong]:
ballarin@13817
   617
  "[| A = B; !!i. i : B ==> f i = g i;
ballarin@13817
   618
      g : B -> carrier G = True |] ==> prod f A = prod g B"
ballarin@13817
   619
  by (rule prod_cong) fast+
ballarin@13817
   620
ballarin@13817
   621
text {*Usually, if this rule causes a failed congruence proof error,
ballarin@13817
   622
   the reason is that the premise @{text "g : B -> carrier G"} cannot be shown.
ballarin@13817
   623
   Adding @{thm [source] Pi_def} to the simpset is often useful. *}
ballarin@13817
   624
ballarin@13817
   625
declare funcsetI [rule del]
ballarin@13817
   626
  funcset_mem [rule del]
ballarin@13817
   627
ballarin@13817
   628
subsection {* Summation over the integer interval @{term "{..n}"} *}
ballarin@13817
   629
ballarin@13817
   630
text {*
ballarin@13817
   631
  For technical reasons (locales) a new locale where the index set is
ballarin@13817
   632
  restricted to @{term "nat"} is necessary.
ballarin@13817
   633
*}
ballarin@13817
   634
ballarin@13817
   635
locale finite_prod_nat = finite_prod +
ballarin@13817
   636
  assumes "False ==> prod f (A::nat set) = prod f A"
ballarin@13817
   637
ballarin@13817
   638
lemma (in finite_prod_nat) natSum_0 [simp]:
ballarin@13817
   639
  "f : {0::nat} -> carrier G ==> prod f {..0} = f 0"
ballarin@13817
   640
by (simp add: Pi_def)
ballarin@13817
   641
ballarin@13817
   642
lemma (in finite_prod_nat) natsum_Suc [simp]:
ballarin@13817
   643
  "f : {..Suc n} -> carrier G ==>
ballarin@13817
   644
   prod f {..Suc n} = (f (Suc n) \<otimes> prod f {..n})"
ballarin@13817
   645
by (simp add: Pi_def atMost_Suc)
ballarin@13817
   646
ballarin@13817
   647
lemma (in finite_prod_nat) natsum_Suc2:
ballarin@13817
   648
  "f : {..Suc n} -> carrier G ==>
ballarin@13817
   649
   prod f {..Suc n} = (prod (%i. f (Suc i)) {..n} \<otimes> f 0)"
ballarin@13817
   650
proof (induct n)
ballarin@13817
   651
  case 0 thus ?case by (simp add: Pi_def)
ballarin@13817
   652
next
ballarin@13817
   653
  case Suc thus ?case by (simp add: m_assoc Pi_def prod_closed)
ballarin@13817
   654
qed
ballarin@13817
   655
ballarin@13817
   656
lemma (in finite_prod_nat) natsum_zero [simp]:
ballarin@13817
   657
  "prod (%i. \<one>) {..n::nat} = \<one>"
ballarin@13817
   658
by (induct n) (simp_all add: Pi_def)
ballarin@13817
   659
ballarin@13817
   660
lemma (in finite_prod_nat) natsum_add [simp]:
ballarin@13817
   661
  "[| f : {..n} -> carrier G; g : {..n} -> carrier G |] ==>
ballarin@13817
   662
   prod (%i. f i \<otimes> g i) {..n::nat} = prod f {..n} \<otimes> prod g {..n}"
ballarin@13817
   663
by (induct n) (simp_all add: ac Pi_def prod_closed)
ballarin@13817
   664
ballarin@13817
   665
thm setsum_cong
ballarin@13817
   666
ballarin@13817
   667
ML_setup {* 
ballarin@13817
   668
ballarin@13817
   669
Context.>> (fn thy => (simpset_ref_of thy :=
ballarin@13817
   670
  simpset_of thy setsubgoaler asm_full_simp_tac; thy)) *}
ballarin@13817
   671
ballarin@13817
   672
lemma "(\<Sum>i\<in>{..10::nat}. if i<=10 then 0 else 1) = (0::nat)"
ballarin@13817
   673
apply simp done
ballarin@13817
   674
ballarin@13817
   675
lemma (in finite_prod_nat) "prod (%i. if i<=10 then \<one> else x) {..10} = \<one>"
ballarin@13817
   676
apply (simp add: Pi_def)
ballarin@13813
   677
ballarin@13813
   678
end