src/HOL/Isar_examples/Group.thy
author wenzelm
Mon, 22 May 2000 12:05:23 +0200
changeset 8910 981ac87f905c
parent 7982 d534b897ce39
child 10007 64bf7da1994a
permissions -rw-r--r--
tuned;
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
7748
5b9c45b21782 improved presentation;
wenzelm
parents: 7740
diff changeset
     6
header {* Basic group theory *};
5b9c45b21782 improved presentation;
wenzelm
parents: 7740
diff changeset
     7
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
     8
theory Group = Main:;
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
     9
7874
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
    10
subsection {* Groups and calculational reasoning *}; 
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    11
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    12
text {*
7968
964b65b4e433 improved presentation;
wenzelm
parents: 7874
diff changeset
    13
 Groups over signature $({\times} :: \alpha \To \alpha \To \alpha,
964b65b4e433 improved presentation;
wenzelm
parents: 7874
diff changeset
    14
 \idt{one} :: \alpha, \idt{inv} :: \alpha \To \alpha)$ are defined as
964b65b4e433 improved presentation;
wenzelm
parents: 7874
diff changeset
    15
 an axiomatic type class as follows.  Note that the parent class
964b65b4e433 improved presentation;
wenzelm
parents: 7874
diff changeset
    16
 $\idt{times}$ is provided by the basic HOL theory.
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    17
*};
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
    18
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
    19
consts
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    20
  one :: "'a"
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    21
  inv :: "'a => 'a";
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
    22
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
    23
axclass
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
    24
  group < times
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    25
  group_assoc:         "(x * y) * z = x * (y * z)"
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    26
  group_left_unit:     "one * x = x"
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    27
  group_left_inverse:  "inv x * x = one";
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
    28
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    29
text {*
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    30
 The group axioms only state the properties of left unit and inverse,
7874
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
    31
 the right versions may be derived as follows.
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);
8910
wenzelm
parents: 7982
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 {*
7982
d534b897ce39 improved presentation;
wenzelm
parents: 7968
diff changeset
    56
 With \name{group-right-inverse} already available,
d534b897ce39 improved presentation;
wenzelm
parents: 7968
diff changeset
    57
 \name{group-right-unit}\label{thm:group-right-unit} is now
d534b897ce39 improved presentation;
wenzelm
parents: 7968
diff changeset
    58
 established much easier.
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    59
*};
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
    60
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    61
theorem group_right_unit: "x * one = (x::'a::group)";
7133
64c9f2364dae renamed 'same' to '-';
wenzelm
parents: 7005
diff changeset
    62
proof -;
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    63
  have "x * one = x * (inv x * x)";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
    64
    by (simp only: group_left_inverse);
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    65
  also; have "... = x * inv x * x";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
    66
    by (simp only: group_assoc);
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    67
  also; have "... = one * x";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
    68
    by (simp only: group_right_inverse);
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    69
  also; have "... = x";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
    70
    by (simp only: group_left_unit);
7480
0a0e0dbe1269 replaced ?? by ?;
wenzelm
parents: 7433
diff changeset
    71
  finally; show ?thesis; .;
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    72
qed;
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
    73
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    74
text {*
7874
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
    75
 \medskip The calculational proof style above follows typical
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
    76
 presentations given in any introductory course on algebra.  The basic
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
    77
 technique is to form a transitive chain of equations, which in turn
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
    78
 are established by simplifying with appropriate rules.  The low-level
7982
d534b897ce39 improved presentation;
wenzelm
parents: 7968
diff changeset
    79
 logical details of equational reasoning are left implicit.
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    80
7982
d534b897ce39 improved presentation;
wenzelm
parents: 7968
diff changeset
    81
 Note that ``$\dots$'' is just a special term variable that is bound
d534b897ce39 improved presentation;
wenzelm
parents: 7968
diff changeset
    82
 automatically to the argument\footnote{The argument of a curried
d534b897ce39 improved presentation;
wenzelm
parents: 7968
diff changeset
    83
 infix expression happens to be its right-hand side.} of the last fact
d534b897ce39 improved presentation;
wenzelm
parents: 7968
diff changeset
    84
 achieved by any local assumption or proven statement.  In contrast to
d534b897ce39 improved presentation;
wenzelm
parents: 7968
diff changeset
    85
 $\var{thesis}$, the ``$\dots$'' variable is bound \emph{after} the
d534b897ce39 improved presentation;
wenzelm
parents: 7968
diff changeset
    86
 proof is finished, though.
7874
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
    87
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
    88
 There are only two separate Isar language elements for calculational
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
    89
 proofs: ``\isakeyword{also}'' for initial or intermediate
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
    90
 calculational steps, and ``\isakeyword{finally}'' for exhibiting the
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
    91
 result of a calculation.  These constructs are not hardwired into
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
    92
 Isabelle/Isar, but defined on top of the basic Isar/VM interpreter.
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
    93
 Expanding the \isakeyword{also} and \isakeyword{finally} derived
7982
d534b897ce39 improved presentation;
wenzelm
parents: 7968
diff changeset
    94
 language elements, calculations may be simulated by hand as
d534b897ce39 improved presentation;
wenzelm
parents: 7968
diff changeset
    95
 demonstrated below.
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    96
*};
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
    97
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
    98
theorem "x * one = (x::'a::group)";
7133
64c9f2364dae renamed 'same' to '-';
wenzelm
parents: 7005
diff changeset
    99
proof -;
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
   100
  have "x * one = x * (inv x * x)";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
   101
    by (simp only: group_left_inverse);
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
   102
7433
27887c52b9c8 "this";
wenzelm
parents: 7356
diff changeset
   103
  note calculation = this
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   104
    -- {* first calculational step: init calculation register *};
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
   105
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
   106
  have "... = x * inv x * x";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
   107
    by (simp only: group_assoc);
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
   108
7433
27887c52b9c8 "this";
wenzelm
parents: 7356
diff changeset
   109
  note calculation = trans [OF calculation this]
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
   110
    -- {* general calculational step: compose with transitivity rule *};
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
   111
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
   112
  have "... = one * x";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
   113
    by (simp only: group_right_inverse);
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
   114
7433
27887c52b9c8 "this";
wenzelm
parents: 7356
diff changeset
   115
  note calculation = trans [OF calculation this]
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
   116
    -- {* general calculational step: compose with transitivity rule *};
6763
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
  have "... = x";
6908
1bf0590f4790 simp only;
wenzelm
parents: 6892
diff changeset
   119
    by (simp only: group_left_unit);
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
   120
7433
27887c52b9c8 "this";
wenzelm
parents: 7356
diff changeset
   121
  note calculation = trans [OF calculation this]
6784
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
   122
    -- {* final calculational step: compose with transitivity rule ... *};
687ddcad8581 proper calculation;
wenzelm
parents: 6763
diff changeset
   123
  from calculation
7874
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
   124
    -- {* ... and pick up the final result *};
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
   125
7480
0a0e0dbe1269 replaced ?? by ?;
wenzelm
parents: 7433
diff changeset
   126
  show ?thesis; .;
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
   127
qed;
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
   128
7874
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
   129
text {*
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
   130
 Note that this scheme of calculations is not restricted to plain
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
   131
 transitivity.  Rules like anti-symmetry, or even forward and backward
7982
d534b897ce39 improved presentation;
wenzelm
parents: 7968
diff changeset
   132
 substitution work as well.  For the actual implementation of
d534b897ce39 improved presentation;
wenzelm
parents: 7968
diff changeset
   133
 \isacommand{also} and \isacommand{finally}, Isabelle/Isar maintains
d534b897ce39 improved presentation;
wenzelm
parents: 7968
diff changeset
   134
 separate context information of ``transitivity'' rules.  Rule
d534b897ce39 improved presentation;
wenzelm
parents: 7968
diff changeset
   135
 selection takes place automatically by higher-order unification.
7874
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
   136
*};
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
   137
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
   138
7761
7fab9592384f improved presentation;
wenzelm
parents: 7748
diff changeset
   139
subsection {* Groups as monoids *};
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   140
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   141
text {*
7874
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
   142
 Monoids over signature $({\times} :: \alpha \To \alpha \To \alpha,
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
   143
 \idt{one} :: \alpha)$ are defined like this.
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   144
*};
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   145
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   146
axclass monoid < times
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   147
  monoid_assoc:       "(x * y) * z = x * (y * z)"
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   148
  monoid_left_unit:   "one * x = x"
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   149
  monoid_right_unit:  "x * one = x";
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   150
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   151
text {*
7748
5b9c45b21782 improved presentation;
wenzelm
parents: 7740
diff changeset
   152
 Groups are \emph{not} yet monoids directly from the definition.  For
5b9c45b21782 improved presentation;
wenzelm
parents: 7740
diff changeset
   153
 monoids, \name{right-unit} had to be included as an axiom, but for
7982
d534b897ce39 improved presentation;
wenzelm
parents: 7968
diff changeset
   154
 groups both \name{right-unit} and \name{right-inverse} are derivable
d534b897ce39 improved presentation;
wenzelm
parents: 7968
diff changeset
   155
 from the other axioms.  With \name{group-right-unit} derived as a
d534b897ce39 improved presentation;
wenzelm
parents: 7968
diff changeset
   156
 theorem of group theory (see page~\pageref{thm:group-right-unit}), we
d534b897ce39 improved presentation;
wenzelm
parents: 7968
diff changeset
   157
 may still instantiate $\idt{group} \subset \idt{monoid}$ properly as
d534b897ce39 improved presentation;
wenzelm
parents: 7968
diff changeset
   158
 follows.
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   159
*};
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   160
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   161
instance group < monoid;
7356
1714c91b8729 expand_classes renamed to intro_classes;
wenzelm
parents: 7133
diff changeset
   162
  by (intro_classes,
6793
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   163
       rule group_assoc,
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   164
       rule group_left_unit,
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   165
       rule group_right_unit);
88aba7f486cb groups as monoids;
wenzelm
parents: 6784
diff changeset
   166
7874
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
   167
text {*
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
   168
 The \isacommand{instance} command actually is a version of
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
   169
 \isacommand{theorem}, setting up a goal that reflects the intended
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
   170
 class relation (or type constructor arity).  Thus any Isar proof
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
   171
 language element may be involved to establish this statement.  When
7982
d534b897ce39 improved presentation;
wenzelm
parents: 7968
diff changeset
   172
 concluding the proof, the result is transformed into the intended
7874
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
   173
 type signature extension behind the scenes.
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
   174
*};
180364256231 improved presentation;
wenzelm
parents: 7800
diff changeset
   175
6763
df12aef00932 Some bits of group theory. Demonstrate calculational proofs.
wenzelm
parents:
diff changeset
   176
end;