src/HOL/Isar_examples/Group.thy
changeset 10007 64bf7da1994a
parent 8910 981ac87f905c
child 10141 964d9dc47041
equal deleted inserted replaced
10006:ede5f78b9398 10007:64bf7da1994a
     1 (*  Title:      HOL/Isar_examples/Group.thy
     1 (*  Title:      HOL/Isar_examples/Group.thy
     2     ID:         $Id$
     2     ID:         $Id$
     3     Author:     Markus Wenzel, TU Muenchen
     3     Author:     Markus Wenzel, TU Muenchen
     4 *)
     4 *)
     5 
     5 
     6 header {* Basic group theory *};
     6 header {* Basic group theory *}
     7 
     7 
     8 theory Group = Main:;
     8 theory Group = Main:
     9 
     9 
    10 subsection {* Groups and calculational reasoning *}; 
    10 subsection {* Groups and calculational reasoning *} 
    11 
    11 
    12 text {*
    12 text {*
    13  Groups over signature $({\times} :: \alpha \To \alpha \To \alpha,
    13  Groups over signature $({\times} :: \alpha \To \alpha \To \alpha,
    14  \idt{one} :: \alpha, \idt{inv} :: \alpha \To \alpha)$ are defined as
    14  \idt{one} :: \alpha, \idt{inv} :: \alpha \To \alpha)$ are defined as
    15  an axiomatic type class as follows.  Note that the parent class
    15  an axiomatic type class as follows.  Note that the parent class
    16  $\idt{times}$ is provided by the basic HOL theory.
    16  $\idt{times}$ is provided by the basic HOL theory.
    17 *};
    17 *}
    18 
    18 
    19 consts
    19 consts
    20   one :: "'a"
    20   one :: "'a"
    21   inv :: "'a => 'a";
    21   inv :: "'a => 'a"
    22 
    22 
    23 axclass
    23 axclass
    24   group < times
    24   group < times
    25   group_assoc:         "(x * y) * z = x * (y * z)"
    25   group_assoc:         "(x * y) * z = x * (y * z)"
    26   group_left_unit:     "one * x = x"
    26   group_left_unit:     "one * x = x"
    27   group_left_inverse:  "inv x * x = one";
    27   group_left_inverse:  "inv x * x = one"
    28 
    28 
    29 text {*
    29 text {*
    30  The group axioms only state the properties of left unit and inverse,
    30  The group axioms only state the properties of left unit and inverse,
    31  the right versions may be derived as follows.
    31  the right versions may be derived as follows.
    32 *};
    32 *}
    33 
    33 
    34 theorem group_right_inverse: "x * inv x = (one::'a::group)";
    34 theorem group_right_inverse: "x * inv x = (one::'a::group)"
    35 proof -;
    35 proof -
    36   have "x * inv x = one * (x * inv x)";
    36   have "x * inv x = one * (x * inv x)"
    37     by (simp only: group_left_unit);
    37     by (simp only: group_left_unit)
    38   also; have "... = one * x * inv x";
    38   also have "... = one * x * inv x"
    39     by (simp only: group_assoc);
    39     by (simp only: group_assoc)
    40   also; have "... = inv (inv x) * inv x * x * inv x";
    40   also have "... = inv (inv x) * inv x * x * inv x"
    41     by (simp only: group_left_inverse);
    41     by (simp only: group_left_inverse)
    42   also; have "... = inv (inv x) * (inv x * x) * inv x";
    42   also have "... = inv (inv x) * (inv x * x) * inv x"
    43     by (simp only: group_assoc);
    43     by (simp only: group_assoc)
    44   also; have "... = inv (inv x) * one * inv x";
    44   also have "... = inv (inv x) * one * inv x"
    45     by (simp only: group_left_inverse);
    45     by (simp only: group_left_inverse)
    46   also; have "... = inv (inv x) * (one * inv x)";
    46   also have "... = inv (inv x) * (one * inv x)"
    47     by (simp only: group_assoc);
    47     by (simp only: group_assoc)
    48   also; have "... = inv (inv x) * inv x";
    48   also have "... = inv (inv x) * inv x"
    49     by (simp only: group_left_unit);
    49     by (simp only: group_left_unit)
    50   also; have "... = one";
    50   also have "... = one"
    51     by (simp only: group_left_inverse);
    51     by (simp only: group_left_inverse)
    52   finally; show ?thesis; .;
    52   finally show ?thesis .
    53 qed;
    53 qed
    54 
    54 
    55 text {*
    55 text {*
    56  With \name{group-right-inverse} already available,
    56  With \name{group-right-inverse} already available,
    57  \name{group-right-unit}\label{thm:group-right-unit} is now
    57  \name{group-right-unit}\label{thm:group-right-unit} is now
    58  established much easier.
    58  established much easier.
    59 *};
    59 *}
    60 
    60 
    61 theorem group_right_unit: "x * one = (x::'a::group)";
    61 theorem group_right_unit: "x * one = (x::'a::group)"
    62 proof -;
    62 proof -
    63   have "x * one = x * (inv x * x)";
    63   have "x * one = x * (inv x * x)"
    64     by (simp only: group_left_inverse);
    64     by (simp only: group_left_inverse)
    65   also; have "... = x * inv x * x";
    65   also have "... = x * inv x * x"
    66     by (simp only: group_assoc);
    66     by (simp only: group_assoc)
    67   also; have "... = one * x";
    67   also have "... = one * x"
    68     by (simp only: group_right_inverse);
    68     by (simp only: group_right_inverse)
    69   also; have "... = x";
    69   also have "... = x"
    70     by (simp only: group_left_unit);
    70     by (simp only: group_left_unit)
    71   finally; show ?thesis; .;
    71   finally show ?thesis .
    72 qed;
    72 qed
    73 
    73 
    74 text {*
    74 text {*
    75  \medskip The calculational proof style above follows typical
    75  \medskip The calculational proof style above follows typical
    76  presentations given in any introductory course on algebra.  The basic
    76  presentations given in any introductory course on algebra.  The basic
    77  technique is to form a transitive chain of equations, which in turn
    77  technique is to form a transitive chain of equations, which in turn
    91  result of a calculation.  These constructs are not hardwired into
    91  result of a calculation.  These constructs are not hardwired into
    92  Isabelle/Isar, but defined on top of the basic Isar/VM interpreter.
    92  Isabelle/Isar, but defined on top of the basic Isar/VM interpreter.
    93  Expanding the \isakeyword{also} and \isakeyword{finally} derived
    93  Expanding the \isakeyword{also} and \isakeyword{finally} derived
    94  language elements, calculations may be simulated by hand as
    94  language elements, calculations may be simulated by hand as
    95  demonstrated below.
    95  demonstrated below.
    96 *};
    96 *}
    97 
    97 
    98 theorem "x * one = (x::'a::group)";
    98 theorem "x * one = (x::'a::group)"
    99 proof -;
    99 proof -
   100   have "x * one = x * (inv x * x)";
   100   have "x * one = x * (inv x * x)"
   101     by (simp only: group_left_inverse);
   101     by (simp only: group_left_inverse)
   102 
   102 
   103   note calculation = this
   103   note calculation = this
   104     -- {* first calculational step: init calculation register *};
   104     -- {* first calculational step: init calculation register *}
   105 
   105 
   106   have "... = x * inv x * x";
   106   have "... = x * inv x * x"
   107     by (simp only: group_assoc);
   107     by (simp only: group_assoc)
   108 
   108 
   109   note calculation = trans [OF calculation this]
   109   note calculation = trans [OF calculation this]
   110     -- {* general calculational step: compose with transitivity rule *};
   110     -- {* general calculational step: compose with transitivity rule *}
   111 
   111 
   112   have "... = one * x";
   112   have "... = one * x"
   113     by (simp only: group_right_inverse);
   113     by (simp only: group_right_inverse)
   114 
   114 
   115   note calculation = trans [OF calculation this]
   115   note calculation = trans [OF calculation this]
   116     -- {* general calculational step: compose with transitivity rule *};
   116     -- {* general calculational step: compose with transitivity rule *}
   117 
   117 
   118   have "... = x";
   118   have "... = x"
   119     by (simp only: group_left_unit);
   119     by (simp only: group_left_unit)
   120 
   120 
   121   note calculation = trans [OF calculation this]
   121   note calculation = trans [OF calculation this]
   122     -- {* final calculational step: compose with transitivity rule ... *};
   122     -- {* final calculational step: compose with transitivity rule ... *}
   123   from calculation
   123   from calculation
   124     -- {* ... and pick up the final result *};
   124     -- {* ... and pick up the final result *}
   125 
   125 
   126   show ?thesis; .;
   126   show ?thesis .
   127 qed;
   127 qed
   128 
   128 
   129 text {*
   129 text {*
   130  Note that this scheme of calculations is not restricted to plain
   130  Note that this scheme of calculations is not restricted to plain
   131  transitivity.  Rules like anti-symmetry, or even forward and backward
   131  transitivity.  Rules like anti-symmetry, or even forward and backward
   132  substitution work as well.  For the actual implementation of
   132  substitution work as well.  For the actual implementation of
   133  \isacommand{also} and \isacommand{finally}, Isabelle/Isar maintains
   133  \isacommand{also} and \isacommand{finally}, Isabelle/Isar maintains
   134  separate context information of ``transitivity'' rules.  Rule
   134  separate context information of ``transitivity'' rules.  Rule
   135  selection takes place automatically by higher-order unification.
   135  selection takes place automatically by higher-order unification.
   136 *};
   136 *}
   137 
   137 
   138 
   138 
   139 subsection {* Groups as monoids *};
   139 subsection {* Groups as monoids *}
   140 
   140 
   141 text {*
   141 text {*
   142  Monoids over signature $({\times} :: \alpha \To \alpha \To \alpha,
   142  Monoids over signature $({\times} :: \alpha \To \alpha \To \alpha,
   143  \idt{one} :: \alpha)$ are defined like this.
   143  \idt{one} :: \alpha)$ are defined like this.
   144 *};
   144 *}
   145 
   145 
   146 axclass monoid < times
   146 axclass monoid < times
   147   monoid_assoc:       "(x * y) * z = x * (y * z)"
   147   monoid_assoc:       "(x * y) * z = x * (y * z)"
   148   monoid_left_unit:   "one * x = x"
   148   monoid_left_unit:   "one * x = x"
   149   monoid_right_unit:  "x * one = x";
   149   monoid_right_unit:  "x * one = x"
   150 
   150 
   151 text {*
   151 text {*
   152  Groups are \emph{not} yet monoids directly from the definition.  For
   152  Groups are \emph{not} yet monoids directly from the definition.  For
   153  monoids, \name{right-unit} had to be included as an axiom, but for
   153  monoids, \name{right-unit} had to be included as an axiom, but for
   154  groups both \name{right-unit} and \name{right-inverse} are derivable
   154  groups both \name{right-unit} and \name{right-inverse} are derivable
   155  from the other axioms.  With \name{group-right-unit} derived as a
   155  from the other axioms.  With \name{group-right-unit} derived as a
   156  theorem of group theory (see page~\pageref{thm:group-right-unit}), we
   156  theorem of group theory (see page~\pageref{thm:group-right-unit}), we
   157  may still instantiate $\idt{group} \subset \idt{monoid}$ properly as
   157  may still instantiate $\idt{group} \subset \idt{monoid}$ properly as
   158  follows.
   158  follows.
   159 *};
   159 *}
   160 
   160 
   161 instance group < monoid;
   161 instance group < monoid
   162   by (intro_classes,
   162   by (intro_classes,
   163        rule group_assoc,
   163        rule group_assoc,
   164        rule group_left_unit,
   164        rule group_left_unit,
   165        rule group_right_unit);
   165        rule group_right_unit)
   166 
   166 
   167 text {*
   167 text {*
   168  The \isacommand{instance} command actually is a version of
   168  The \isacommand{instance} command actually is a version of
   169  \isacommand{theorem}, setting up a goal that reflects the intended
   169  \isacommand{theorem}, setting up a goal that reflects the intended
   170  class relation (or type constructor arity).  Thus any Isar proof
   170  class relation (or type constructor arity).  Thus any Isar proof
   171  language element may be involved to establish this statement.  When
   171  language element may be involved to establish this statement.  When
   172  concluding the proof, the result is transformed into the intended
   172  concluding the proof, the result is transformed into the intended
   173  type signature extension behind the scenes.
   173  type signature extension behind the scenes.
   174 *};
   174 *}
   175 
   175 
   176 end;
   176 end