src/HOL/AxClasses/Group.thy
author kleing
Mon Jun 21 10:25:57 2004 +0200 (2004-06-21)
changeset 14981 e73f8140af78
parent 12338 de0f4a63baa5
child 16417 9bc16273c2d4
permissions -rw-r--r--
Merged in license change from Isabelle2004
wenzelm@10134
     1
(*  Title:      HOL/AxClasses/Group.thy
wenzelm@10134
     2
    ID:         $Id$
wenzelm@10134
     3
    Author:     Markus Wenzel, TU Muenchen
wenzelm@10134
     4
*)
wenzelm@10134
     5
wenzelm@10134
     6
theory Group = Main:
wenzelm@10134
     7
wenzelm@10134
     8
subsection {* Monoids and Groups *}
wenzelm@10134
     9
wenzelm@10134
    10
consts
wenzelm@10134
    11
  times :: "'a => 'a => 'a"    (infixl "[*]" 70)
wenzelm@11072
    12
  invers :: "'a => 'a"
wenzelm@10134
    13
  one :: 'a
wenzelm@10134
    14
wenzelm@10134
    15
wenzelm@12338
    16
axclass monoid < type
wenzelm@10134
    17
  assoc:      "(x [*] y) [*] z = x [*] (y [*] z)"
wenzelm@10134
    18
  left_unit:  "one [*] x = x"
wenzelm@10134
    19
  right_unit: "x [*] one = x"
wenzelm@10134
    20
wenzelm@12338
    21
axclass semigroup < type
wenzelm@10134
    22
  assoc: "(x [*] y) [*] z = x [*] (y [*] z)"
wenzelm@10134
    23
wenzelm@10134
    24
axclass group < semigroup
wenzelm@10134
    25
  left_unit:    "one [*] x = x"
wenzelm@11072
    26
  left_inverse: "invers x [*] x = one"
wenzelm@10134
    27
wenzelm@10134
    28
axclass agroup < group
wenzelm@10134
    29
  commute: "x [*] y = y [*] x"
wenzelm@10134
    30
wenzelm@10134
    31
wenzelm@10134
    32
subsection {* Abstract reasoning *}
wenzelm@10134
    33
wenzelm@11072
    34
theorem group_right_inverse: "x [*] invers x = (one::'a::group)"
wenzelm@10134
    35
proof -
wenzelm@11072
    36
  have "x [*] invers x = one [*] (x [*] invers x)"
wenzelm@10134
    37
    by (simp only: group.left_unit)
wenzelm@11072
    38
  also have "... = one [*] x [*] invers x"
wenzelm@10134
    39
    by (simp only: semigroup.assoc)
wenzelm@11072
    40
  also have "... = invers (invers x) [*] invers x [*] x [*] invers x"
wenzelm@10134
    41
    by (simp only: group.left_inverse)
wenzelm@11072
    42
  also have "... = invers (invers x) [*] (invers x [*] x) [*] invers x"
wenzelm@10134
    43
    by (simp only: semigroup.assoc)
wenzelm@11072
    44
  also have "... = invers (invers x) [*] one [*] invers x"
wenzelm@10134
    45
    by (simp only: group.left_inverse)
wenzelm@11072
    46
  also have "... = invers (invers x) [*] (one [*] invers x)"
wenzelm@10134
    47
    by (simp only: semigroup.assoc)
wenzelm@11072
    48
  also have "... = invers (invers x) [*] invers x"
wenzelm@10134
    49
    by (simp only: group.left_unit)
wenzelm@10134
    50
  also have "... = one"
wenzelm@10134
    51
    by (simp only: group.left_inverse)
wenzelm@10134
    52
  finally show ?thesis .
wenzelm@10134
    53
qed
wenzelm@10134
    54
wenzelm@10134
    55
theorem group_right_unit: "x [*] one = (x::'a::group)"
wenzelm@10134
    56
proof -
wenzelm@11072
    57
  have "x [*] one = x [*] (invers x [*] x)"
wenzelm@10134
    58
    by (simp only: group.left_inverse)
wenzelm@11072
    59
  also have "... = x [*] invers x [*] x"
wenzelm@10134
    60
    by (simp only: semigroup.assoc)
wenzelm@10134
    61
  also have "... = one [*] x"
wenzelm@10134
    62
    by (simp only: group_right_inverse)
wenzelm@10134
    63
  also have "... = x"
wenzelm@10134
    64
    by (simp only: group.left_unit)
wenzelm@10134
    65
  finally show ?thesis .
wenzelm@10134
    66
qed
wenzelm@10134
    67
wenzelm@10134
    68
wenzelm@10134
    69
subsection {* Abstract instantiation *}
wenzelm@10134
    70
wenzelm@10134
    71
instance monoid < semigroup
wenzelm@10134
    72
proof intro_classes
wenzelm@10134
    73
  fix x y z :: "'a::monoid"
wenzelm@10134
    74
  show "x [*] y [*] z = x [*] (y [*] z)"
wenzelm@10134
    75
    by (rule monoid.assoc)
wenzelm@10134
    76
qed
wenzelm@10134
    77
wenzelm@10134
    78
instance group < monoid
wenzelm@10134
    79
proof intro_classes
wenzelm@10134
    80
  fix x y z :: "'a::group"
wenzelm@10134
    81
  show "x [*] y [*] z = x [*] (y [*] z)"
wenzelm@10134
    82
    by (rule semigroup.assoc)
wenzelm@10134
    83
  show "one [*] x = x"
wenzelm@10134
    84
    by (rule group.left_unit)
wenzelm@10134
    85
  show "x [*] one = x"
wenzelm@10134
    86
    by (rule group_right_unit)
wenzelm@10134
    87
qed
wenzelm@10134
    88
wenzelm@10134
    89
wenzelm@10134
    90
subsection {* Concrete instantiation *}
wenzelm@10134
    91
wenzelm@10134
    92
defs (overloaded)
wenzelm@10134
    93
  times_bool_def:   "x [*] y == x ~= (y::bool)"
wenzelm@11072
    94
  inverse_bool_def: "invers x == x::bool"
wenzelm@10134
    95
  unit_bool_def:    "one == False"
wenzelm@10134
    96
wenzelm@10134
    97
instance bool :: agroup
wenzelm@10134
    98
proof (intro_classes,
wenzelm@10134
    99
    unfold times_bool_def inverse_bool_def unit_bool_def)
wenzelm@10134
   100
  fix x y z
wenzelm@10134
   101
  show "((x ~= y) ~= z) = (x ~= (y ~= z))" by blast
wenzelm@10134
   102
  show "(False ~= x) = x" by blast
wenzelm@10134
   103
  show "(x ~= x) = False" by blast
wenzelm@10134
   104
  show "(x ~= y) = (y ~= x)" by blast
wenzelm@10134
   105
qed
wenzelm@10134
   106
wenzelm@10134
   107
wenzelm@10134
   108
subsection {* Lifting and Functors *}
wenzelm@10134
   109
wenzelm@10134
   110
defs (overloaded)
wenzelm@10134
   111
  times_prod_def: "p [*] q == (fst p [*] fst q, snd p [*] snd q)"
wenzelm@10134
   112
wenzelm@10134
   113
instance * :: (semigroup, semigroup) semigroup
wenzelm@10134
   114
proof (intro_classes, unfold times_prod_def)
wenzelm@10134
   115
  fix p q r :: "'a::semigroup * 'b::semigroup"
wenzelm@10134
   116
  show
wenzelm@10134
   117
    "(fst (fst p [*] fst q, snd p [*] snd q) [*] fst r,
wenzelm@10134
   118
      snd (fst p [*] fst q, snd p [*] snd q) [*] snd r) =
wenzelm@10134
   119
       (fst p [*] fst (fst q [*] fst r, snd q [*] snd r),
wenzelm@10134
   120
        snd p [*] snd (fst q [*] fst r, snd q [*] snd r))"
wenzelm@10134
   121
    by (simp add: semigroup.assoc)
wenzelm@10134
   122
qed
wenzelm@10134
   123
wenzelm@10134
   124
end