doc-src/AxClass/Group/Group.thy
changeset 12338 de0f4a63baa5
parent 11099 b301d1f72552
child 12344 7237c6497cb1
equal deleted inserted replaced
12337:7c6a970f0808 12338:de0f4a63baa5
     2 header {* Basic group theory *}
     2 header {* Basic group theory *}
     3 
     3 
     4 theory Group = Main:
     4 theory Group = Main:
     5 
     5 
     6 text {*
     6 text {*
     7  \medskip\noindent The meta-level type system of Isabelle supports
     7   \medskip\noindent The meta-level type system of Isabelle supports
     8  \emph{intersections} and \emph{inclusions} of type classes. These
     8   \emph{intersections} and \emph{inclusions} of type classes. These
     9  directly correspond to intersections and inclusions of type
     9   directly correspond to intersections and inclusions of type
    10  predicates in a purely set theoretic sense. This is sufficient as a
    10   predicates in a purely set theoretic sense. This is sufficient as a
    11  means to describe simple hierarchies of structures.  As an
    11   means to describe simple hierarchies of structures.  As an
    12  illustration, we use the well-known example of semigroups, monoids,
    12   illustration, we use the well-known example of semigroups, monoids,
    13  general groups and Abelian groups.
    13   general groups and Abelian groups.
    14 *}
    14 *}
    15 
    15 
    16 subsection {* Monoids and Groups *}
    16 subsection {* Monoids and Groups *}
    17 
    17 
    18 text {*
    18 text {*
    19  First we declare some polymorphic constants required later for the
    19   First we declare some polymorphic constants required later for the
    20  signature parts of our structures.
    20   signature parts of our structures.
    21 *}
    21 *}
    22 
    22 
    23 consts
    23 consts
    24   times :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"    (infixl "\<odot>" 70)
    24   times :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"    (infixl "\<odot>" 70)
    25   invers :: "'a \<Rightarrow> 'a"    ("(_\<inv>)" [1000] 999)
    25   invers :: "'a \<Rightarrow> 'a"    ("(_\<inv>)" [1000] 999)
    26   one :: 'a    ("\<unit>")
    26   one :: 'a    ("\<unit>")
    27 
    27 
    28 text {*
    28 text {*
    29  \noindent Next we define class @{text monoid} of monoids with
    29   \noindent Next we define class @{text monoid} of monoids with
    30  operations @{text \<odot>} and @{text \<unit>}.  Note that multiple class
    30   operations @{text \<odot>} and @{text \<unit>}.  Note that multiple class
    31  axioms are allowed for user convenience --- they simply represent the
    31   axioms are allowed for user convenience --- they simply represent
    32  conjunction of their respective universal closures.
    32   the conjunction of their respective universal closures.
    33 *}
    33 *}
    34 
    34 
    35 axclass monoid \<subseteq> "term"
    35 axclass monoid \<subseteq> type
    36   assoc: "(x \<odot> y) \<odot> z = x \<odot> (y \<odot> z)"
    36   assoc: "(x \<odot> y) \<odot> z = x \<odot> (y \<odot> z)"
    37   left_unit: "\<unit> \<odot> x = x"
    37   left_unit: "\<unit> \<odot> x = x"
    38   right_unit: "x \<odot> \<unit> = x"
    38   right_unit: "x \<odot> \<unit> = x"
    39 
    39 
    40 text {*
    40 text {*
    41  \noindent So class @{text monoid} contains exactly those types @{text
    41   \noindent So class @{text monoid} contains exactly those types
    42  \<tau>} where @{text "\<odot> \<Colon> \<tau> \<Rightarrow> \<tau> \<Rightarrow> \<tau>"} and @{text "\<unit> \<Colon> \<tau>"} are
    42   @{text \<tau>} where @{text "\<odot> \<Colon> \<tau> \<Rightarrow> \<tau> \<Rightarrow> \<tau>"} and @{text "\<unit> \<Colon> \<tau>"}
    43  specified appropriately, such that @{text \<odot>} is associative and
    43   are specified appropriately, such that @{text \<odot>} is associative and
    44  @{text \<unit>} is a left and right unit element for the @{text \<odot>}
    44   @{text \<unit>} is a left and right unit element for the @{text \<odot>}
    45  operation.
    45   operation.
    46 *}
    46 *}
    47 
    47 
    48 text {*
    48 text {*
    49  \medskip Independently of @{text monoid}, we now define a linear
    49   \medskip Independently of @{text monoid}, we now define a linear
    50  hierarchy of semigroups, general groups and Abelian groups.  Note
    50   hierarchy of semigroups, general groups and Abelian groups.  Note
    51  that the names of class axioms are automatically qualified with each
    51   that the names of class axioms are automatically qualified with each
    52  class name, so we may re-use common names such as @{text assoc}.
    52   class name, so we may re-use common names such as @{text assoc}.
    53 *}
    53 *}
    54 
    54 
    55 axclass semigroup \<subseteq> "term"
    55 axclass semigroup \<subseteq> type
    56   assoc: "(x \<odot> y) \<odot> z = x \<odot> (y \<odot> z)"
    56   assoc: "(x \<odot> y) \<odot> z = x \<odot> (y \<odot> z)"
    57 
    57 
    58 axclass group \<subseteq> semigroup
    58 axclass group \<subseteq> semigroup
    59   left_unit: "\<unit> \<odot> x = x"
    59   left_unit: "\<unit> \<odot> x = x"
    60   left_inverse: "x\<inv> \<odot> x = \<unit>"
    60   left_inverse: "x\<inv> \<odot> x = \<unit>"
    61 
    61 
    62 axclass agroup \<subseteq> group
    62 axclass agroup \<subseteq> group
    63   commute: "x \<odot> y = y \<odot> x"
    63   commute: "x \<odot> y = y \<odot> x"
    64 
    64 
    65 text {*
    65 text {*
    66  \noindent Class @{text group} inherits associativity of @{text \<odot>}
    66   \noindent Class @{text group} inherits associativity of @{text \<odot>}
    67  from @{text semigroup} and adds two further group axioms. Similarly,
    67   from @{text semigroup} and adds two further group axioms. Similarly,
    68  @{text agroup} is defined as the subset of @{text group} such that
    68   @{text agroup} is defined as the subset of @{text group} such that
    69  for all of its elements @{text \<tau>}, the operation @{text "\<odot> \<Colon> \<tau> \<Rightarrow> \<tau> \<Rightarrow>
    69   for all of its elements @{text \<tau>}, the operation @{text "\<odot> \<Colon> \<tau> \<Rightarrow> \<tau> \<Rightarrow>
    70  \<tau>"} is even commutative.
    70   \<tau>"} is even commutative.
    71 *}
    71 *}
    72 
    72 
    73 
    73 
    74 subsection {* Abstract reasoning *}
    74 subsection {* Abstract reasoning *}
    75 
    75 
    76 text {*
    76 text {*
    77  In a sense, axiomatic type classes may be viewed as \emph{abstract
    77   In a sense, axiomatic type classes may be viewed as \emph{abstract
    78  theories}.  Above class definitions gives rise to abstract axioms
    78   theories}.  Above class definitions gives rise to abstract axioms
    79  @{text assoc}, @{text left_unit}, @{text left_inverse}, @{text
    79   @{text assoc}, @{text left_unit}, @{text left_inverse}, @{text
    80  commute}, where any of these contain a type variable @{text "'a \<Colon> c"}
    80   commute}, where any of these contain a type variable @{text "'a \<Colon>
    81  that is restricted to types of the corresponding class @{text c}.
    81   c"} that is restricted to types of the corresponding class @{text
    82  \emph{Sort constraints} like this express a logical precondition for
    82   c}.  \emph{Sort constraints} like this express a logical
    83  the whole formula.  For example, @{text assoc} states that for all
    83   precondition for the whole formula.  For example, @{text assoc}
    84  @{text \<tau>}, provided that @{text "\<tau> \<Colon> semigroup"}, the operation
    84   states that for all @{text \<tau>}, provided that @{text "\<tau> \<Colon>
    85  @{text "\<odot> \<Colon> \<tau> \<Rightarrow> \<tau> \<Rightarrow> \<tau>"} is associative.
    85   semigroup"}, the operation @{text "\<odot> \<Colon> \<tau> \<Rightarrow> \<tau> \<Rightarrow> \<tau>"} is associative.
    86 
    86 
    87  \medskip From a technical point of view, abstract axioms are just
    87   \medskip From a technical point of view, abstract axioms are just
    88  ordinary Isabelle theorems, which may be used in proofs without
    88   ordinary Isabelle theorems, which may be used in proofs without
    89  special treatment.  Such ``abstract proofs'' usually yield new
    89   special treatment.  Such ``abstract proofs'' usually yield new
    90  ``abstract theorems''.  For example, we may now derive the following
    90   ``abstract theorems''.  For example, we may now derive the following
    91  well-known laws of general groups.
    91   well-known laws of general groups.
    92 *}
    92 *}
    93 
    93 
    94 theorem group_right_inverse: "x \<odot> x\<inv> = (\<unit>\<Colon>'a\<Colon>group)"
    94 theorem group_right_inverse: "x \<odot> x\<inv> = (\<unit>\<Colon>'a\<Colon>group)"
    95 proof -
    95 proof -
    96   have "x \<odot> x\<inv> = \<unit> \<odot> (x \<odot> x\<inv>)"
    96   have "x \<odot> x\<inv> = \<unit> \<odot> (x \<odot> x\<inv>)"
   111     by (simp only: group.left_inverse)
   111     by (simp only: group.left_inverse)
   112   finally show ?thesis .
   112   finally show ?thesis .
   113 qed
   113 qed
   114 
   114 
   115 text {*
   115 text {*
   116  \noindent With @{text group_right_inverse} already available, @{text
   116   \noindent With @{text group_right_inverse} already available, @{text
   117  group_right_unit}\label{thm:group-right-unit} is now established much
   117   group_right_unit}\label{thm:group-right-unit} is now established
   118  easier.
   118   much easier.
   119 *}
   119 *}
   120 
   120 
   121 theorem group_right_unit: "x \<odot> \<unit> = (x\<Colon>'a\<Colon>group)"
   121 theorem group_right_unit: "x \<odot> \<unit> = (x\<Colon>'a\<Colon>group)"
   122 proof -
   122 proof -
   123   have "x \<odot> \<unit> = x \<odot> (x\<inv> \<odot> x)"
   123   have "x \<odot> \<unit> = x \<odot> (x\<inv> \<odot> x)"
   130     by (simp only: group.left_unit)
   130     by (simp only: group.left_unit)
   131   finally show ?thesis .
   131   finally show ?thesis .
   132 qed
   132 qed
   133 
   133 
   134 text {*
   134 text {*
   135  \medskip Abstract theorems may be instantiated to only those types
   135   \medskip Abstract theorems may be instantiated to only those types
   136  @{text \<tau>} where the appropriate class membership @{text "\<tau> \<Colon> c"} is
   136   @{text \<tau>} where the appropriate class membership @{text "\<tau> \<Colon> c"} is
   137  known at Isabelle's type signature level.  Since we have @{text
   137   known at Isabelle's type signature level.  Since we have @{text
   138  "agroup \<subseteq> group \<subseteq> semigroup"} by definition, all theorems of @{text
   138   "agroup \<subseteq> group \<subseteq> semigroup"} by definition, all theorems of @{text
   139  semigroup} and @{text group} are automatically inherited by @{text
   139   semigroup} and @{text group} are automatically inherited by @{text
   140  group} and @{text agroup}.
   140   group} and @{text agroup}.
   141 *}
   141 *}
   142 
   142 
   143 
   143 
   144 subsection {* Abstract instantiation *}
   144 subsection {* Abstract instantiation *}
   145 
   145 
   146 text {*
   146 text {*
   147  From the definition, the @{text monoid} and @{text group} classes
   147   From the definition, the @{text monoid} and @{text group} classes
   148  have been independent.  Note that for monoids, @{text right_unit} had
   148   have been independent.  Note that for monoids, @{text right_unit}
   149  to be included as an axiom, but for groups both @{text right_unit}
   149   had to be included as an axiom, but for groups both @{text
   150  and @{text right_inverse} are derivable from the other axioms.  With
   150   right_unit} and @{text right_inverse} are derivable from the other
   151  @{text group_right_unit} derived as a theorem of group theory (see
   151   axioms.  With @{text group_right_unit} derived as a theorem of group
   152  page~\pageref{thm:group-right-unit}), we may now instantiate @{text
   152   theory (see page~\pageref{thm:group-right-unit}), we may now
   153  "monoid \<subseteq> semigroup"} and @{text "group \<subseteq> monoid"} properly as
   153   instantiate @{text "monoid \<subseteq> semigroup"} and @{text "group \<subseteq>
   154  follows (cf.\ \figref{fig:monoid-group}).
   154   monoid"} properly as follows (cf.\ \figref{fig:monoid-group}).
   155 
   155 
   156  \begin{figure}[htbp]
   156  \begin{figure}[htbp]
   157    \begin{center}
   157    \begin{center}
   158      \small
   158      \small
   159      \unitlength 0.6mm
   159      \unitlength 0.6mm
   161        \put(15,10){\line(0,1){10}} \put(15,30){\line(0,1){10}}
   161        \put(15,10){\line(0,1){10}} \put(15,30){\line(0,1){10}}
   162        \put(15,50){\line(1,1){10}} \put(35,60){\line(1,-1){10}}
   162        \put(15,50){\line(1,1){10}} \put(35,60){\line(1,-1){10}}
   163        \put(15,5){\makebox(0,0){@{text agroup}}}
   163        \put(15,5){\makebox(0,0){@{text agroup}}}
   164        \put(15,25){\makebox(0,0){@{text group}}}
   164        \put(15,25){\makebox(0,0){@{text group}}}
   165        \put(15,45){\makebox(0,0){@{text semigroup}}}
   165        \put(15,45){\makebox(0,0){@{text semigroup}}}
   166        \put(30,65){\makebox(0,0){@{text "term"}}} \put(50,45){\makebox(0,0){@{text monoid}}}
   166        \put(30,65){\makebox(0,0){@{text type}}} \put(50,45){\makebox(0,0){@{text monoid}}}
   167      \end{picture}
   167      \end{picture}
   168      \hspace{4em}
   168      \hspace{4em}
   169      \begin{picture}(30,90)(0,0)
   169      \begin{picture}(30,90)(0,0)
   170        \put(15,10){\line(0,1){10}} \put(15,30){\line(0,1){10}}
   170        \put(15,10){\line(0,1){10}} \put(15,30){\line(0,1){10}}
   171        \put(15,50){\line(0,1){10}} \put(15,70){\line(0,1){10}}
   171        \put(15,50){\line(0,1){10}} \put(15,70){\line(0,1){10}}
   172        \put(15,5){\makebox(0,0){@{text agroup}}}
   172        \put(15,5){\makebox(0,0){@{text agroup}}}
   173        \put(15,25){\makebox(0,0){@{text group}}}
   173        \put(15,25){\makebox(0,0){@{text group}}}
   174        \put(15,45){\makebox(0,0){@{text monoid}}}
   174        \put(15,45){\makebox(0,0){@{text monoid}}}
   175        \put(15,65){\makebox(0,0){@{text semigroup}}}
   175        \put(15,65){\makebox(0,0){@{text semigroup}}}
   176        \put(15,85){\makebox(0,0){@{text term}}}
   176        \put(15,85){\makebox(0,0){@{text type}}}
   177      \end{picture}
   177      \end{picture}
   178      \caption{Monoids and groups: according to definition, and by proof}
   178      \caption{Monoids and groups: according to definition, and by proof}
   179      \label{fig:monoid-group}
   179      \label{fig:monoid-group}
   180    \end{center}
   180    \end{center}
   181  \end{figure}
   181  \end{figure}
   198   show "x \<odot> \<unit> = x"
   198   show "x \<odot> \<unit> = x"
   199     by (rule group_right_unit)
   199     by (rule group_right_unit)
   200 qed
   200 qed
   201 
   201 
   202 text {*
   202 text {*
   203  \medskip The $\INSTANCE$ command sets up an appropriate goal that
   203   \medskip The $\INSTANCE$ command sets up an appropriate goal that
   204  represents the class inclusion (or type arity, see
   204   represents the class inclusion (or type arity, see
   205  \secref{sec:inst-arity}) to be proven (see also
   205   \secref{sec:inst-arity}) to be proven (see also
   206  \cite{isabelle-isar-ref}).  The initial proof step causes
   206   \cite{isabelle-isar-ref}).  The initial proof step causes
   207  back-chaining of class membership statements wrt.\ the hierarchy of
   207   back-chaining of class membership statements wrt.\ the hierarchy of
   208  any classes defined in the current theory; the effect is to reduce to
   208   any classes defined in the current theory; the effect is to reduce
   209  the initial statement to a number of goals that directly correspond
   209   to the initial statement to a number of goals that directly
   210  to any class axioms encountered on the path upwards through the class
   210   correspond to any class axioms encountered on the path upwards
   211  hierarchy.
   211   through the class hierarchy.
   212 *}
   212 *}
   213 
   213 
   214 
   214 
   215 subsection {* Concrete instantiation \label{sec:inst-arity} *}
   215 subsection {* Concrete instantiation \label{sec:inst-arity} *}
   216 
   216 
   217 text {*
   217 text {*
   218  So far we have covered the case of the form $\INSTANCE$~@{text
   218   So far we have covered the case of the form $\INSTANCE$~@{text
   219  "c\<^sub>1 \<subseteq> c\<^sub>2"}, namely \emph{abstract instantiation} ---
   219   "c\<^sub>1 \<subseteq> c\<^sub>2"}, namely \emph{abstract instantiation} ---
   220  $c@1$ is more special than @{text "c\<^sub>1"} and thus an instance
   220   $c@1$ is more special than @{text "c\<^sub>1"} and thus an instance
   221  of @{text "c\<^sub>2"}.  Even more interesting for practical
   221   of @{text "c\<^sub>2"}.  Even more interesting for practical
   222  applications are \emph{concrete instantiations} of axiomatic type
   222   applications are \emph{concrete instantiations} of axiomatic type
   223  classes.  That is, certain simple schemes @{text "(\<alpha>\<^sub>1, \<dots>,
   223   classes.  That is, certain simple schemes @{text "(\<alpha>\<^sub>1, \<dots>,
   224  \<alpha>\<^sub>n) t \<Colon> c"} of class membership may be established at the
   224   \<alpha>\<^sub>n) t \<Colon> c"} of class membership may be established at the
   225  logical level and then transferred to Isabelle's type signature
   225   logical level and then transferred to Isabelle's type signature
   226  level.
   226   level.
   227 
   227 
   228  \medskip As a typical example, we show that type @{typ bool} with
   228   \medskip As a typical example, we show that type @{typ bool} with
   229  exclusive-or as @{text \<odot>} operation, identity as @{text \<inv>}, and
   229   exclusive-or as @{text \<odot>} operation, identity as @{text \<inv>}, and
   230  @{term False} as @{text \<unit>} forms an Abelian group.
   230   @{term False} as @{text \<unit>} forms an Abelian group.
   231 *}
   231 *}
   232 
   232 
   233 defs (overloaded)
   233 defs (overloaded)
   234   times_bool_def: "x \<odot> y \<equiv> x \<noteq> (y\<Colon>bool)"
   234   times_bool_def: "x \<odot> y \<equiv> x \<noteq> (y\<Colon>bool)"
   235   inverse_bool_def: "x\<inv> \<equiv> x\<Colon>bool"
   235   inverse_bool_def: "x\<inv> \<equiv> x\<Colon>bool"
   236   unit_bool_def: "\<unit> \<equiv> False"
   236   unit_bool_def: "\<unit> \<equiv> False"
   237 
   237 
   238 text {*
   238 text {*
   239  \medskip It is important to note that above $\DEFS$ are just
   239   \medskip It is important to note that above $\DEFS$ are just
   240  overloaded meta-level constant definitions, where type classes are
   240   overloaded meta-level constant definitions, where type classes are
   241  not yet involved at all.  This form of constant definition with
   241   not yet involved at all.  This form of constant definition with
   242  overloading (and optional recursion over the syntactic structure of
   242   overloading (and optional recursion over the syntactic structure of
   243  simple types) are admissible as definitional extensions of plain HOL
   243   simple types) are admissible as definitional extensions of plain HOL
   244  \cite{Wenzel:1997:TPHOL}.  The Haskell-style type system is not
   244   \cite{Wenzel:1997:TPHOL}.  The Haskell-style type system is not
   245  required for overloading.  Nevertheless, overloaded definitions are
   245   required for overloading.  Nevertheless, overloaded definitions are
   246  best applied in the context of type classes.
   246   best applied in the context of type classes.
   247 
   247 
   248  \medskip Since we have chosen above $\DEFS$ of the generic group
   248   \medskip Since we have chosen above $\DEFS$ of the generic group
   249  operations on type @{typ bool} appropriately, the class membership
   249   operations on type @{typ bool} appropriately, the class membership
   250  @{text "bool \<Colon> agroup"} may be now derived as follows.
   250   @{text "bool \<Colon> agroup"} may be now derived as follows.
   251 *}
   251 *}
   252 
   252 
   253 instance bool :: agroup
   253 instance bool :: agroup
   254 proof (intro_classes,
   254 proof (intro_classes,
   255     unfold times_bool_def inverse_bool_def unit_bool_def)
   255     unfold times_bool_def inverse_bool_def unit_bool_def)
   259   show "(x \<noteq> x) = False" by blast
   259   show "(x \<noteq> x) = False" by blast
   260   show "(x \<noteq> y) = (y \<noteq> x)" by blast
   260   show "(x \<noteq> y) = (y \<noteq> x)" by blast
   261 qed
   261 qed
   262 
   262 
   263 text {*
   263 text {*
   264  The result of an $\INSTANCE$ statement is both expressed as a theorem
   264   The result of an $\INSTANCE$ statement is both expressed as a
   265  of Isabelle's meta-logic, and as a type arity of the type signature.
   265   theorem of Isabelle's meta-logic, and as a type arity of the type
   266  The latter enables type-inference system to take care of this new
   266   signature.  The latter enables type-inference system to take care of
   267  instance automatically.
   267   this new instance automatically.
   268 
   268 
   269  \medskip We could now also instantiate our group theory classes to
   269   \medskip We could now also instantiate our group theory classes to
   270  many other concrete types.  For example, @{text "int \<Colon> agroup"}
   270   many other concrete types.  For example, @{text "int \<Colon> agroup"}
   271  (e.g.\ by defining @{text \<odot>} as addition, @{text \<inv>} as negation
   271   (e.g.\ by defining @{text \<odot>} as addition, @{text \<inv>} as negation
   272  and @{text \<unit>} as zero) or @{text "list \<Colon> (term) semigroup"}
   272   and @{text \<unit>} as zero) or @{text "list \<Colon> (type) semigroup"}
   273  (e.g.\ if @{text \<odot>} is defined as list append).  Thus, the
   273   (e.g.\ if @{text \<odot>} is defined as list append).  Thus, the
   274  characteristic constants @{text \<odot>}, @{text \<inv>}, @{text \<unit>}
   274   characteristic constants @{text \<odot>}, @{text \<inv>}, @{text \<unit>}
   275  really become overloaded, i.e.\ have different meanings on different
   275   really become overloaded, i.e.\ have different meanings on different
   276  types.
   276   types.
   277 *}
   277 *}
   278 
   278 
   279 
   279 
   280 subsection {* Lifting and Functors *}
   280 subsection {* Lifting and Functors *}
   281 
   281 
   282 text {*
   282 text {*
   283  As already mentioned above, overloading in the simply-typed HOL
   283   As already mentioned above, overloading in the simply-typed HOL
   284  systems may include recursion over the syntactic structure of types.
   284   systems may include recursion over the syntactic structure of types.
   285  That is, definitional equations @{text "c\<^sup>\<tau> \<equiv> t"} may also
   285   That is, definitional equations @{text "c\<^sup>\<tau> \<equiv> t"} may also
   286  contain constants of name @{text c} on the right-hand side --- if
   286   contain constants of name @{text c} on the right-hand side --- if
   287  these have types that are structurally simpler than @{text \<tau>}.
   287   these have types that are structurally simpler than @{text \<tau>}.
   288 
   288 
   289  This feature enables us to \emph{lift operations}, say to Cartesian
   289   This feature enables us to \emph{lift operations}, say to Cartesian
   290  products, direct sums or function spaces.  Subsequently we lift
   290   products, direct sums or function spaces.  Subsequently we lift
   291  @{text \<odot>} component-wise to binary products @{typ "'a \<times> 'b"}.
   291   @{text \<odot>} component-wise to binary products @{typ "'a \<times> 'b"}.
   292 *}
   292 *}
   293 
   293 
   294 defs (overloaded)
   294 defs (overloaded)
   295   times_prod_def: "p \<odot> q \<equiv> (fst p \<odot> fst q, snd p \<odot> snd q)"
   295   times_prod_def: "p \<odot> q \<equiv> (fst p \<odot> fst q, snd p \<odot> snd q)"
   296 
   296 
   297 text {*
   297 text {*
   298  It is very easy to see that associativity of @{text \<odot>} on @{typ 'a}
   298   It is very easy to see that associativity of @{text \<odot>} on @{typ 'a}
   299  and @{text \<odot>} on @{typ 'b} transfers to @{text \<odot>} on @{typ "'a \<times>
   299   and @{text \<odot>} on @{typ 'b} transfers to @{text \<odot>} on @{typ "'a \<times>
   300  'b"}.  Hence the binary type constructor @{text \<odot>} maps semigroups to
   300   'b"}.  Hence the binary type constructor @{text \<odot>} maps semigroups
   301  semigroups.  This may be established formally as follows.
   301   to semigroups.  This may be established formally as follows.
   302 *}
   302 *}
   303 
   303 
   304 instance * :: (semigroup, semigroup) semigroup
   304 instance * :: (semigroup, semigroup) semigroup
   305 proof (intro_classes, unfold times_prod_def)
   305 proof (intro_classes, unfold times_prod_def)
   306   fix p q r :: "'a\<Colon>semigroup \<times> 'b\<Colon>semigroup"
   306   fix p q r :: "'a\<Colon>semigroup \<times> 'b\<Colon>semigroup"
   311         snd p \<odot> snd (fst q \<odot> fst r, snd q \<odot> snd r))"
   311         snd p \<odot> snd (fst q \<odot> fst r, snd q \<odot> snd r))"
   312     by (simp add: semigroup.assoc)
   312     by (simp add: semigroup.assoc)
   313 qed
   313 qed
   314 
   314 
   315 text {*
   315 text {*
   316  Thus, if we view class instances as ``structures'', then overloaded
   316   Thus, if we view class instances as ``structures'', then overloaded
   317  constant definitions with recursion over types indirectly provide
   317   constant definitions with recursion over types indirectly provide
   318  some kind of ``functors'' --- i.e.\ mappings between abstract
   318   some kind of ``functors'' --- i.e.\ mappings between abstract
   319  theories.
   319   theories.
   320 *}
   320 *}
   321 
   321 
   322 end
   322 end