src/HOL/Isar_examples/Group.thy
author wenzelm
Sat, 04 Sep 1999 21:13:01 +0200
changeset 7480 0a0e0dbe1269
parent 7433 27887c52b9c8
child 7740 2fbe5ce9845f
permissions -rw-r--r--
replaced ?? by ?;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/Isar_examples/Group.thy
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
     4
*)
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
     5
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
     6
theory Group = Main:;
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
     7
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
     8
title {* Basic group theory *};
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
     9
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    10
section {* Groups *}; 
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    11
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    12
text {*
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    13
 We define an axiomatic type class of general groups over signature
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    14
 (op *, one, inv).
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    15
*};
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
    16
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
    17
consts
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    18
  one :: "'a"
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    19
  inv :: "'a => 'a";
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
    20
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
    21
axclass
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
    22
  group < times
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    23
  group_assoc:         "(x * y) * z = x * (y * z)"
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    24
  group_left_unit:     "one * x = x"
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    25
  group_left_inverse:  "inv x * x = one";
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
    26
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    27
text {*
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    28
 The group axioms only state the properties of left unit and inverse,
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    29
 the right versions are derivable as follows.  The calculational proof
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    30
 style below closely follows typical presentations given in any basic
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    31
 course on algebra.
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    32
*};
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
    33
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    34
theorem group_right_inverse: "x * inv x = (one::'a::group)";
7133
64c9f2364dae renamed 'same' to '-';
wenzelm
parents: 7005
diff changeset
    35
proof -;
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    36
  have "x * inv x = one * (x * inv x)";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
    37
    by (simp only: group_left_unit);
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    38
  also; have "... = (one * x) * inv x";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
    39
    by (simp only: group_assoc);
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    40
  also; have "... = inv (inv x) * inv x * x * inv x";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
    41
    by (simp only: group_left_inverse);
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    42
  also; have "... = inv (inv x) * (inv x * x) * inv x";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
    43
    by (simp only: group_assoc);
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    44
  also; have "... = inv (inv x) * one * inv x";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
    45
    by (simp only: group_left_inverse);
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    46
  also; have "... = inv (inv x) * (one * inv x)";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
    47
    by (simp only: group_assoc);
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    48
  also; have "... = inv (inv x) * inv x";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
    49
    by (simp only: group_left_unit);
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    50
  also; have "... = one";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
    51
    by (simp only: group_left_inverse);
7480
0a0e0dbe1269 replaced ?? by ?;
wenzelm
parents: 7433
diff changeset
    52
  finally; show ?thesis; .;
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    53
qed;
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
    54
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    55
text {*
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    56
 With group_right_inverse already at our disposal, group_right_unit is
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    57
 now obtained much easier as follows.
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    58
*};
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
    59
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    60
theorem group_right_unit: "x * one = (x::'a::group)";
7133
64c9f2364dae renamed 'same' to '-';
wenzelm
parents: 7005
diff changeset
    61
proof -;
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    62
  have "x * one = x * (inv x * x)";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
    63
    by (simp only: group_left_inverse);
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    64
  also; have "... = x * inv x * x";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
    65
    by (simp only: group_assoc);
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    66
  also; have "... = one * x";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
    67
    by (simp only: group_right_inverse);
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    68
  also; have "... = x";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
    69
    by (simp only: group_left_unit);
7480
0a0e0dbe1269 replaced ?? by ?;
wenzelm
parents: 7433
diff changeset
    70
  finally; show ?thesis; .;
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    71
qed;
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
    72
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    73
text {*
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    74
 There are only two Isar language elements for calculational proofs:
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    75
 'also' for initial or intermediate calculational steps, and 'finally'
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    76
 for building the result of a calculation.  These constructs are not
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    77
 hardwired into Isabelle/Isar, but defined on top of the basic Isar/VM
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    78
 interpreter.  Expanding the 'also' or 'finally' derived language
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    79
 elements, calculations may be simulated as demonstrated below.
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    80
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    81
 Note that "..." is just a special term binding that happens to be
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    82
 bound automatically to the argument of the last fact established by
7480
0a0e0dbe1269 replaced ?? by ?;
wenzelm
parents: 7433
diff changeset
    83
 assume or any local goal.  In contrast to ?thesis, "..." is bound
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    84
 after the proof is finished.
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    85
*};
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    86
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    87
theorem "x * one = (x::'a::group)";
7133
64c9f2364dae renamed 'same' to '-';
wenzelm
parents: 7005
diff changeset
    88
proof -;
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    89
  have "x * one = x * (inv x * x)";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
    90
    by (simp only: group_left_inverse);
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
    91
7433
27887c52b9c8 "this";
wenzelm
parents: 7356
diff changeset
    92
  note calculation = this
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    93
    -- {* first calculational step: init calculation register *};
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
    94
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    95
  have "... = x * inv x * x";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
    96
    by (simp only: group_assoc);
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
    97
7433
27887c52b9c8 "this";
wenzelm
parents: 7356
diff changeset
    98
  note calculation = trans [OF calculation this]
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    99
    -- {* general calculational step: compose with transitivity rule *};
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
   100
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
   101
  have "... = one * x";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
   102
    by (simp only: group_right_inverse);
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
   103
7433
27887c52b9c8 "this";
wenzelm
parents: 7356
diff changeset
   104
  note calculation = trans [OF calculation this]
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
   105
    -- {* general calculational step: compose with transitivity rule *};
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
   106
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
   107
  have "... = x";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
   108
    by (simp only: group_left_unit);
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
   109
7433
27887c52b9c8 "this";
wenzelm
parents: 7356
diff changeset
   110
  note calculation = trans [OF calculation this]
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
   111
    -- {* final calculational step: compose with transitivity rule ... *};
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
   112
  from calculation
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
   113
    -- {* ... and pick up final result *};
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
   114
7480
0a0e0dbe1269 replaced ?? by ?;
wenzelm
parents: 7433
diff changeset
   115
  show ?thesis; .;
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
   116
qed;
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
   117
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
   118
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   119
section {* Groups and monoids *};
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   120
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   121
text {*
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   122
  Monoids are usually defined like this.
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   123
*};
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   124
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   125
axclass monoid < times
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   126
  monoid_assoc:       "(x * y) * z = x * (y * z)"
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   127
  monoid_left_unit:   "one * x = x"
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   128
  monoid_right_unit:  "x * one = x";
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   129
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   130
text {*
7005
cc778d613217 tuned comments;
wenzelm
parents: 6908
diff changeset
   131
 Groups are *not* yet monoids directly from the definition.  For
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   132
 monoids, right_unit had to be included as an axiom, but for groups
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   133
 both right_unit and right_inverse are derivable from the other
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   134
 axioms.  With group_right_unit derived as a theorem of group theory
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   135
 (see above), we may still instantiate group < monoid properly as
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   136
 follows.
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   137
*};
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   138
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   139
instance group < monoid;
7356
1714c91b8729 expand_classes renamed to intro_classes;
wenzelm
parents: 7133
diff changeset
   140
  by (intro_classes,
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   141
       rule group_assoc,
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   142
       rule group_left_unit,
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   143
       rule group_right_unit);
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   144
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   145
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
   146
end;