doc-src/IsarAdvanced/Classes/Thy/document/Classes.tex
author haftmann
Wed, 09 Jan 2008 08:33:01 +0100
changeset 25871 45753d56d935
parent 25868 97c6787099bc
child 26991 2aa686443859
permissions -rw-r--r--
some more primrec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
     1
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
     2
\begin{isabellebody}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
     3
\def\isabellecontext{Classes}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
     4
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
     5
\isadelimtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
     6
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
     7
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
     8
\endisadelimtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
     9
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    10
\isatagtheory
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
    11
%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    12
\endisatagtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    13
{\isafoldtheory}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    14
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    15
\isadelimtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    16
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    17
\endisadelimtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    18
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    19
\isadelimML
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    20
%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    21
\endisadelimML
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    22
%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    23
\isatagML
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    24
%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    25
\endisatagML
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    26
{\isafoldML}%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    27
%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    28
\isadelimML
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    29
%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    30
\endisadelimML
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    31
%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    32
\isadelimML
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    33
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    34
\endisadelimML
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    35
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    36
\isatagML
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    37
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    38
\endisatagML
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    39
{\isafoldML}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    40
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    41
\isadelimML
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    42
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    43
\endisadelimML
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    44
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    45
\isamarkupchapter{Haskell-style classes with Isabelle/Isar%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    46
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    47
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    48
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    49
\isamarkupsection{Introduction%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    50
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    51
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    52
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    53
\begin{isamarkuptext}%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    54
Type classes were introduces by Wadler and Blott \cite{wadler89how}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    55
  into the Haskell language, to allow for a reasonable implementation
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    56
  of overloading\footnote{throughout this tutorial, we are referring
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    57
  to classical Haskell 1.0 type classes, not considering
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    58
  later additions in expressiveness}.
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    59
  As a canonical example, a polymorphic equality function
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    60
  \isa{eq\ {\isasymColon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ bool} which is overloaded on different
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
    61
  types for \isa{{\isasymalpha}}, which is achieved by splitting introduction
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    62
  of the \isa{eq} function from its overloaded definitions by means
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    63
  of \isa{class} and \isa{instance} declarations:
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    64
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    65
  \medskip\noindent\hspace*{2ex}\isa{class\ eq\ where}\footnote{syntax here is a kind of isabellized Haskell} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    66
  \hspace*{4ex}\isa{eq\ {\isasymColon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ bool}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    67
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    68
  \medskip\noindent\hspace*{2ex}\isa{instance\ nat\ {\isasymColon}\ eq\ where} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    69
  \hspace*{4ex}\isa{eq\ {\isadigit{0}}\ {\isadigit{0}}\ {\isacharequal}\ True} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    70
  \hspace*{4ex}\isa{eq\ {\isadigit{0}}\ {\isacharunderscore}\ {\isacharequal}\ False} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    71
  \hspace*{4ex}\isa{eq\ {\isacharunderscore}\ {\isadigit{0}}\ {\isacharequal}\ False} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    72
  \hspace*{4ex}\isa{eq\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isacharparenleft}Suc\ m{\isacharparenright}\ {\isacharequal}\ eq\ n\ m}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    73
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    74
  \medskip\noindent\hspace*{2ex}\isa{instance\ {\isacharparenleft}{\isasymalpha}{\isasymColon}eq{\isacharcomma}\ {\isasymbeta}{\isasymColon}eq{\isacharparenright}\ pair\ {\isasymColon}\ eq\ where} \\
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
    75
  \hspace*{4ex}\isa{eq\ {\isacharparenleft}x{\isadigit{1}}{\isacharcomma}\ y{\isadigit{1}}{\isacharparenright}\ {\isacharparenleft}x{\isadigit{2}}{\isacharcomma}\ y{\isadigit{2}}{\isacharparenright}\ {\isacharequal}\ eq\ x{\isadigit{1}}\ x{\isadigit{2}}\ {\isasymand}\ eq\ y{\isadigit{1}}\ y{\isadigit{2}}}
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    76
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    77
  \medskip\noindent\hspace*{2ex}\isa{class\ ord\ extends\ eq\ where} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    78
  \hspace*{4ex}\isa{less{\isacharunderscore}eq\ {\isasymColon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ bool} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    79
  \hspace*{4ex}\isa{less\ {\isasymColon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ bool}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    80
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
    81
  \medskip\noindent Type variables are annotated with (finitly many) classes;
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    82
  these annotations are assertions that a particular polymorphic type
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    83
  provides definitions for overloaded functions.
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    84
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    85
  Indeed, type classes not only allow for simple overloading
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    86
  but form a generic calculus, an instance of order-sorted
23956
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
    87
  algebra \cite{Nipkow-Prehofer:1993,nipkow-sorts93,Wenzel:1997:TPHOL}.
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    88
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    89
  From a software enigineering point of view, type classes
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    90
  correspond to interfaces in object-oriented languages like Java;
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    91
  so, it is naturally desirable that type classes do not only
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
    92
  provide functions (class parameters) but also state specifications
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    93
  implementations must obey.  For example, the \isa{class\ eq}
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
    94
  above could be given the following specification, demanding that
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
    95
  \isa{class\ eq} is an equivalence relation obeying reflexivity,
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
    96
  symmetry and transitivity:
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    97
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    98
  \medskip\noindent\hspace*{2ex}\isa{class\ eq\ where} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    99
  \hspace*{4ex}\isa{eq\ {\isasymColon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ bool} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   100
  \hspace*{2ex}\isa{satisfying} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   101
  \hspace*{4ex}\isa{refl{\isacharcolon}\ eq\ x\ x} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   102
  \hspace*{4ex}\isa{sym{\isacharcolon}\ eq\ x\ y\ {\isasymlongleftrightarrow}\ eq\ x\ y} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   103
  \hspace*{4ex}\isa{trans{\isacharcolon}\ eq\ x\ y\ {\isasymand}\ eq\ y\ z\ {\isasymlongrightarrow}\ eq\ x\ z}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   104
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   105
  \medskip\noindent From a theoretic point of view, type classes are leightweight
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   106
  modules; Haskell type classes may be emulated by
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   107
  SML functors \cite{classes_modules}. 
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   108
  Isabelle/Isar offers a discipline of type classes which brings
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   109
  all those aspects together:
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   110
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   111
  \begin{enumerate}
25004
c62c5209487b updated
haftmann
parents: 24991
diff changeset
   112
    \item specifying abstract parameters together with
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   113
       corresponding specifications,
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   114
    \item instantating those abstract parameters by a particular
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   115
       type
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   116
    \item in connection with a ``less ad-hoc'' approach to overloading,
23956
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   117
    \item with a direct link to the Isabelle module system
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   118
      (aka locales \cite{kammueller-locales}).
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   119
  \end{enumerate}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   120
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   121
  \noindent Isar type classes also directly support code generation
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   122
  in a Haskell like fashion.
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   123
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   124
  This tutorial demonstrates common elements of structured specifications
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   125
  and abstract reasoning with type classes by the algebraic hierarchy of
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   126
  semigroups, monoids and groups.  Our background theory is that of
23956
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   127
  Isabelle/HOL \cite{isa-tutorial}, for which some
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   128
  familiarity is assumed.
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   129
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   130
  Here we merely present the look-and-feel for end users.
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   131
  Internally, those are mapped to more primitive Isabelle concepts.
23956
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   132
  See \cite{Haftmann-Wenzel:2006:classes} for more detail.%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   133
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   134
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   135
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   136
\isamarkupsection{A simple algebra example \label{sec:example}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   137
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   138
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   139
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   140
\isamarkupsubsection{Class definition%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   141
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   142
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   143
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   144
\begin{isamarkuptext}%
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   145
Depending on an arbitrary type \isa{{\isasymalpha}}, class \isa{semigroup} introduces a binary operator \isa{{\isasymotimes}} that is
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   146
  assumed to be associative:%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   147
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   148
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   149
\ \ \ \ \isacommand{class}\isamarkupfalse%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   150
\ semigroup\ {\isacharequal}\ type\ {\isacharplus}\isanewline
25200
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   151
\ \ \ \ \ \ \isakeyword{fixes}\ mult\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequoteopen}{\isasymotimes}{\isachardoublequoteclose}\ {\isadigit{7}}{\isadigit{0}}{\isacharparenright}\isanewline
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   152
\ \ \ \ \ \ \isakeyword{assumes}\ assoc{\isacharcolon}\ {\isachardoublequoteopen}{\isacharparenleft}x\ {\isasymotimes}\ y{\isacharparenright}\ {\isasymotimes}\ z\ {\isacharequal}\ x\ {\isasymotimes}\ {\isacharparenleft}y\ {\isasymotimes}\ z{\isacharparenright}{\isachardoublequoteclose}%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   153
\begin{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   154
\noindent This \isa{{\isasymCLASS}} specification consists of two
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   155
  parts: the \qn{operational} part names the class parameter (\isa{{\isasymFIXES}}), the \qn{logical} part specifies properties on them
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   156
  (\isa{{\isasymASSUMES}}).  The local \isa{{\isasymFIXES}} and \isa{{\isasymASSUMES}} are lifted to the theory toplevel, yielding the global
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   157
  parameter \isa{{\isachardoublequote}mult\ {\isasymColon}\ {\isasymalpha}{\isasymColon}semigroup\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequote}} and the
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   158
  global theorem \isa{semigroup{\isachardot}assoc{\isacharcolon}}~\isa{{\isachardoublequote}{\isasymAnd}x\ y\ z\ {\isasymColon}\ {\isasymalpha}{\isasymColon}semigroup{\isachardot}\ {\isacharparenleft}x\ {\isasymotimes}\ y{\isacharparenright}\ {\isasymotimes}\ z\ {\isacharequal}\ x\ {\isasymotimes}\ {\isacharparenleft}y\ {\isasymotimes}\ z{\isacharparenright}{\isachardoublequote}}.%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   159
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   160
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   161
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   162
\isamarkupsubsection{Class instantiation \label{sec:class_inst}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   163
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   164
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   165
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   166
\begin{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   167
The concrete type \isa{int} is made a \isa{semigroup}
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   168
  instance by providing a suitable definition for the class parameter
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   169
  \isa{mult} and a proof for the specification of \isa{assoc}.
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   170
  This is accomplished by the \isa{{\isasymINSTANTIATION}} target:%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   171
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   172
\isamarkuptrue%
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   173
\ \ \ \ \isacommand{instantiation}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   174
\ int\ {\isacharcolon}{\isacharcolon}\ semigroup\isanewline
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   175
\ \ \ \ \isakeyword{begin}\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   176
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   177
\ \ \ \ \isacommand{definition}\isamarkupfalse%
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   178
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   179
\ \ \ \ \ \ mult{\isacharunderscore}int{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}i\ {\isasymotimes}\ j\ {\isacharequal}\ i\ {\isacharplus}\ {\isacharparenleft}j{\isasymColon}int{\isacharparenright}{\isachardoublequoteclose}\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   180
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   181
\ \ \ \ \isacommand{instance}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   182
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   183
\isadelimproof
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   184
\ %
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   185
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   186
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   187
\isatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   188
\isacommand{proof}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   189
\isanewline
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   190
\ \ \ \ \ \ \isacommand{fix}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   191
\ i\ j\ k\ {\isacharcolon}{\isacharcolon}\ int\ \isacommand{have}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   192
\ {\isachardoublequoteopen}{\isacharparenleft}i\ {\isacharplus}\ j{\isacharparenright}\ {\isacharplus}\ k\ {\isacharequal}\ i\ {\isacharplus}\ {\isacharparenleft}j\ {\isacharplus}\ k{\isacharparenright}{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   193
\ simp\isanewline
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   194
\ \ \ \ \ \ \isacommand{then}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   195
\ \isacommand{show}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   196
\ {\isachardoublequoteopen}{\isacharparenleft}i\ {\isasymotimes}\ j{\isacharparenright}\ {\isasymotimes}\ k\ {\isacharequal}\ i\ {\isasymotimes}\ {\isacharparenleft}j\ {\isasymotimes}\ k{\isacharparenright}{\isachardoublequoteclose}\isanewline
haftmann
parents: 25200
diff changeset
   197
\ \ \ \ \ \ \ \ \isacommand{unfolding}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   198
\ mult{\isacharunderscore}int{\isacharunderscore}def\ \isacommand{{\isachardot}}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   199
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   200
\ \ \ \ \isacommand{qed}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   201
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   202
\endisatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   203
{\isafoldproof}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   204
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   205
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   206
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   207
\endisadelimproof
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   208
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   209
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   210
\ \ \ \ \isacommand{end}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   211
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   212
\begin{isamarkuptext}%
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   213
\noindent \isa{{\isasymINSTANTIATION}} allows to define class parameters
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   214
  at a particular instance using common specification tools (here,
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   215
  \isa{{\isasymDEFINITION}}).  The concluding \isa{{\isasymINSTANCE}}
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   216
  opens a proof that the given parameters actually conform
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   217
  to the class specification.  Note that the first proof step
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   218
  is the \isa{default} method,
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   219
  which for such instance proofs maps to the \isa{intro{\isacharunderscore}classes} method.
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   220
  This boils down an instance judgement to the relevant primitive
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   221
  proof goals and should conveniently always be the first method applied
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   222
  in an instantiation proof.
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   223
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   224
  From now on, the type-checker will consider \isa{int}
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   225
  as a \isa{semigroup} automatically, i.e.\ any general results
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   226
  are immediately available on concrete instances.
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   227
  \medskip Another instance of \isa{semigroup} are the natural numbers:%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   228
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   229
\isamarkuptrue%
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   230
\ \ \ \ \isacommand{instantiation}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   231
\ nat\ {\isacharcolon}{\isacharcolon}\ semigroup\isanewline
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   232
\ \ \ \ \isakeyword{begin}\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   233
\isanewline
25871
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   234
\ \ \ \ \isacommand{primrec}\isamarkupfalse%
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   235
\ mult{\isacharunderscore}nat\ \isakeyword{where}\isanewline
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   236
\ \ \ \ \ \ {\isachardoublequoteopen}{\isacharparenleft}{\isadigit{0}}{\isasymColon}nat{\isacharparenright}\ {\isasymotimes}\ n\ {\isacharequal}\ n{\isachardoublequoteclose}\isanewline
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   237
\ \ \ \ \ \ {\isacharbar}\ {\isachardoublequoteopen}Suc\ m\ {\isasymotimes}\ n\ {\isacharequal}\ Suc\ {\isacharparenleft}m\ {\isasymotimes}\ n{\isacharparenright}{\isachardoublequoteclose}\isanewline
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   238
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   239
\ \ \ \ \isacommand{instance}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   240
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   241
\isadelimproof
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   242
\ %
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   243
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   244
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   245
\isatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   246
\isacommand{proof}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   247
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   248
\ \ \ \ \ \ \isacommand{fix}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   249
\ m\ n\ q\ {\isacharcolon}{\isacharcolon}\ nat\ \isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   250
\ \ \ \ \ \ \isacommand{show}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   251
\ {\isachardoublequoteopen}m\ {\isasymotimes}\ n\ {\isasymotimes}\ q\ {\isacharequal}\ m\ {\isasymotimes}\ {\isacharparenleft}n\ {\isasymotimes}\ q{\isacharparenright}{\isachardoublequoteclose}\isanewline
25871
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   252
\ \ \ \ \ \ \ \ \isacommand{by}\isamarkupfalse%
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   253
\ {\isacharparenleft}induct\ m{\isacharparenright}\ auto\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   254
\ \ \ \ \isacommand{qed}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   255
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   256
\endisatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   257
{\isafoldproof}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   258
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   259
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   260
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   261
\endisadelimproof
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   262
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   263
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   264
\ \ \ \ \isacommand{end}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   265
%
25871
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   266
\begin{isamarkuptext}%
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   267
\noindent Note the occurence of the name \isa{mult{\isacharunderscore}nat}
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   268
  in the primrec declaration;  by default, the local name of
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   269
  a class operation \isa{f} to instantiate on type constructor
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   270
  \isa{{\isasymkappa}} are mangled as \isa{f{\isacharunderscore}{\isasymkappa}}.  In case of uncertainty,
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   271
  these names may be inspected using the \isa{{\isasymPRINTCONTEXT}} command
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   272
  or the corresponding ProofGeneral button.%
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   273
\end{isamarkuptext}%
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   274
\isamarkuptrue%
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   275
%
25247
haftmann
parents: 25200
diff changeset
   276
\isamarkupsubsection{Lifting and parametric types%
haftmann
parents: 25200
diff changeset
   277
}
haftmann
parents: 25200
diff changeset
   278
\isamarkuptrue%
haftmann
parents: 25200
diff changeset
   279
%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   280
\begin{isamarkuptext}%
25247
haftmann
parents: 25200
diff changeset
   281
Overloaded definitions giving on class instantiation
haftmann
parents: 25200
diff changeset
   282
  may include recursion over the syntactic structure of types.
haftmann
parents: 25200
diff changeset
   283
  As a canonical example, we model product semigroups
haftmann
parents: 25200
diff changeset
   284
  using our simple algebra:%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   285
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   286
\isamarkuptrue%
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   287
\ \ \ \ \isacommand{instantiation}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   288
\ {\isacharasterisk}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}semigroup{\isacharcomma}\ semigroup{\isacharparenright}\ semigroup\isanewline
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   289
\ \ \ \ \isakeyword{begin}\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   290
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   291
\ \ \ \ \isacommand{definition}\isamarkupfalse%
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   292
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   293
\ \ \ \ \ \ mult{\isacharunderscore}prod{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}p\isactrlisub {\isadigit{1}}\ {\isasymotimes}\ p\isactrlisub {\isadigit{2}}\ {\isacharequal}\ {\isacharparenleft}fst\ p\isactrlisub {\isadigit{1}}\ {\isasymotimes}\ fst\ p\isactrlisub {\isadigit{2}}{\isacharcomma}\ snd\ p\isactrlisub {\isadigit{1}}\ {\isasymotimes}\ snd\ p\isactrlisub {\isadigit{2}}{\isacharparenright}{\isachardoublequoteclose}\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   294
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   295
\ \ \ \ \isacommand{instance}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   296
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   297
\isadelimproof
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   298
\ %
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   299
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   300
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   301
\isatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   302
\isacommand{proof}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   303
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   304
\ \ \ \ \ \ \isacommand{fix}\isamarkupfalse%
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   305
\ p\isactrlisub {\isadigit{1}}\ p\isactrlisub {\isadigit{2}}\ p\isactrlisub {\isadigit{3}}\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}{\isasymColon}semigroup\ {\isasymtimes}\ {\isasymbeta}{\isasymColon}semigroup{\isachardoublequoteclose}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   306
\ \ \ \ \ \ \isacommand{show}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   307
\ {\isachardoublequoteopen}p\isactrlisub {\isadigit{1}}\ {\isasymotimes}\ p\isactrlisub {\isadigit{2}}\ {\isasymotimes}\ p\isactrlisub {\isadigit{3}}\ {\isacharequal}\ p\isactrlisub {\isadigit{1}}\ {\isasymotimes}\ {\isacharparenleft}p\isactrlisub {\isadigit{2}}\ {\isasymotimes}\ p\isactrlisub {\isadigit{3}}{\isacharparenright}{\isachardoublequoteclose}\isanewline
haftmann
parents: 25200
diff changeset
   308
\ \ \ \ \ \ \ \ \isacommand{unfolding}\isamarkupfalse%
haftmann
parents: 25200
diff changeset
   309
\ mult{\isacharunderscore}prod{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
haftmann
parents: 25200
diff changeset
   310
\ {\isacharparenleft}simp\ add{\isacharcolon}\ assoc{\isacharparenright}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   311
\ \ \ \ \isacommand{qed}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   312
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   313
\endisatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   314
{\isafoldproof}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   315
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   316
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   317
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   318
\endisadelimproof
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   319
\ \ \ \ \ \ \isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   320
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   321
\ \ \ \ \isacommand{end}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   322
%
25247
haftmann
parents: 25200
diff changeset
   323
\begin{isamarkuptext}%
haftmann
parents: 25200
diff changeset
   324
\noindent Associativity from product semigroups is
haftmann
parents: 25200
diff changeset
   325
  established using
haftmann
parents: 25200
diff changeset
   326
  the definition of \isa{{\isasymotimes}} on products and the hypothetical
haftmann
parents: 25200
diff changeset
   327
  associativety of the type components;  these hypothesis
haftmann
parents: 25200
diff changeset
   328
  are facts due to the \isa{semigroup} constraints imposed
haftmann
parents: 25200
diff changeset
   329
  on the type components by the \isa{instance} proposition.
haftmann
parents: 25200
diff changeset
   330
  Indeed, this pattern often occurs with parametric types
haftmann
parents: 25200
diff changeset
   331
  and type classes.%
haftmann
parents: 25200
diff changeset
   332
\end{isamarkuptext}%
haftmann
parents: 25200
diff changeset
   333
\isamarkuptrue%
haftmann
parents: 25200
diff changeset
   334
%
haftmann
parents: 25200
diff changeset
   335
\isamarkupsubsection{Subclassing%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   336
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   337
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   338
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   339
\begin{isamarkuptext}%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   340
We define a subclass \isa{monoidl} (a semigroup with a left-hand neutral)
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   341
  by extending \isa{semigroup}
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   342
  with one additional parameter \isa{neutral} together
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   343
  with its property:%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   344
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   345
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   346
\ \ \ \ \isacommand{class}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   347
\ monoidl\ {\isacharequal}\ semigroup\ {\isacharplus}\isanewline
25200
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   348
\ \ \ \ \ \ \isakeyword{fixes}\ neutral\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}{\isachardoublequoteclose}\ {\isacharparenleft}{\isachardoublequoteopen}{\isasymone}{\isachardoublequoteclose}{\isacharparenright}\isanewline
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   349
\ \ \ \ \ \ \isakeyword{assumes}\ neutl{\isacharcolon}\ {\isachardoublequoteopen}{\isasymone}\ {\isasymotimes}\ x\ {\isacharequal}\ x{\isachardoublequoteclose}%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   350
\begin{isamarkuptext}%
25247
haftmann
parents: 25200
diff changeset
   351
\noindent Again, we prove some instances, by
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   352
  providing suitable parameter definitions and proofs for the
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   353
  additional specifications.  Obverve that instantiations
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   354
  for types with the same arity may be simultaneous:%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   355
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   356
\isamarkuptrue%
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   357
\ \ \ \ \isacommand{instantiation}\isamarkupfalse%
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   358
\ nat\ \isakeyword{and}\ int\ {\isacharcolon}{\isacharcolon}\ monoidl\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   359
\ \ \ \ \isakeyword{begin}\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   360
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   361
\ \ \ \ \isacommand{definition}\isamarkupfalse%
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   362
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   363
\ \ \ \ \ \ neutral{\isacharunderscore}nat{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}{\isasymone}\ {\isacharequal}\ {\isacharparenleft}{\isadigit{0}}{\isasymColon}nat{\isacharparenright}{\isachardoublequoteclose}\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   364
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   365
\ \ \ \ \isacommand{definition}\isamarkupfalse%
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   366
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   367
\ \ \ \ \ \ neutral{\isacharunderscore}int{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}{\isasymone}\ {\isacharequal}\ {\isacharparenleft}{\isadigit{0}}{\isasymColon}int{\isacharparenright}{\isachardoublequoteclose}\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   368
\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   369
\ \ \ \ \isacommand{instance}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   370
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   371
\isadelimproof
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   372
\ %
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   373
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   374
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   375
\isatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   376
\isacommand{proof}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   377
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   378
\ \ \ \ \ \ \isacommand{fix}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   379
\ n\ {\isacharcolon}{\isacharcolon}\ nat\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   380
\ \ \ \ \ \ \isacommand{show}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   381
\ {\isachardoublequoteopen}{\isasymone}\ {\isasymotimes}\ n\ {\isacharequal}\ n{\isachardoublequoteclose}\isanewline
haftmann
parents: 25200
diff changeset
   382
\ \ \ \ \ \ \ \ \isacommand{unfolding}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   383
\ neutral{\isacharunderscore}nat{\isacharunderscore}def\ mult{\isacharunderscore}nat{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   384
\ simp\isanewline
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   385
\ \ \ \ \isacommand{next}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   386
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   387
\ \ \ \ \ \ \isacommand{fix}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   388
\ k\ {\isacharcolon}{\isacharcolon}\ int\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   389
\ \ \ \ \ \ \isacommand{show}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   390
\ {\isachardoublequoteopen}{\isasymone}\ {\isasymotimes}\ k\ {\isacharequal}\ k{\isachardoublequoteclose}\isanewline
haftmann
parents: 25200
diff changeset
   391
\ \ \ \ \ \ \ \ \isacommand{unfolding}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   392
\ neutral{\isacharunderscore}int{\isacharunderscore}def\ mult{\isacharunderscore}int{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   393
\ simp\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   394
\ \ \ \ \isacommand{qed}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   395
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   396
\endisatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   397
{\isafoldproof}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   398
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   399
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   400
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   401
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   402
\isanewline
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   403
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   404
\ \ \ \ \isacommand{end}\isamarkupfalse%
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   405
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   406
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   407
\ \ \ \ \isacommand{instantiation}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   408
\ {\isacharasterisk}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}monoidl{\isacharcomma}\ monoidl{\isacharparenright}\ monoidl\isanewline
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   409
\ \ \ \ \isakeyword{begin}\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   410
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   411
\ \ \ \ \isacommand{definition}\isamarkupfalse%
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   412
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   413
\ \ \ \ \ \ neutral{\isacharunderscore}prod{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}{\isasymone}\ {\isacharequal}\ {\isacharparenleft}{\isasymone}{\isacharcomma}\ {\isasymone}{\isacharparenright}{\isachardoublequoteclose}\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   414
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   415
\ \ \ \ \isacommand{instance}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   416
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   417
\isadelimproof
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   418
\ %
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   419
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   420
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   421
\isatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   422
\isacommand{proof}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   423
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   424
\ \ \ \ \ \ \isacommand{fix}\isamarkupfalse%
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   425
\ p\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}{\isasymColon}monoidl\ {\isasymtimes}\ {\isasymbeta}{\isasymColon}monoidl{\isachardoublequoteclose}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   426
\ \ \ \ \ \ \isacommand{show}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   427
\ {\isachardoublequoteopen}{\isasymone}\ {\isasymotimes}\ p\ {\isacharequal}\ p{\isachardoublequoteclose}\isanewline
haftmann
parents: 25200
diff changeset
   428
\ \ \ \ \ \ \ \ \isacommand{unfolding}\isamarkupfalse%
haftmann
parents: 25200
diff changeset
   429
\ neutral{\isacharunderscore}prod{\isacharunderscore}def\ mult{\isacharunderscore}prod{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
haftmann
parents: 25200
diff changeset
   430
\ {\isacharparenleft}simp\ add{\isacharcolon}\ neutl{\isacharparenright}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   431
\ \ \ \ \isacommand{qed}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   432
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   433
\endisatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   434
{\isafoldproof}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   435
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   436
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   437
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   438
\endisadelimproof
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   439
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   440
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   441
\ \ \ \isacommand{end}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   442
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   443
\begin{isamarkuptext}%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   444
\noindent Fully-fledged monoids are modelled by another subclass
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   445
  which does not add new parameters but tightens the specification:%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   446
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   447
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   448
\ \ \ \ \isacommand{class}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   449
\ monoid\ {\isacharequal}\ monoidl\ {\isacharplus}\isanewline
25247
haftmann
parents: 25200
diff changeset
   450
\ \ \ \ \ \ \isakeyword{assumes}\ neutr{\isacharcolon}\ {\isachardoublequoteopen}x\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ x{\isachardoublequoteclose}\isanewline
haftmann
parents: 25200
diff changeset
   451
\isanewline
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   452
\ \ \ \ \isacommand{instantiation}\isamarkupfalse%
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   453
\ nat\ \isakeyword{and}\ int\ {\isacharcolon}{\isacharcolon}\ monoid\ \isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   454
\ \ \ \ \isakeyword{begin}\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   455
\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   456
\ \ \ \ \isacommand{instance}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   457
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   458
\isadelimproof
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   459
\ %
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   460
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   461
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   462
\isatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   463
\isacommand{proof}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   464
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   465
\ \ \ \ \ \ \isacommand{fix}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   466
\ n\ {\isacharcolon}{\isacharcolon}\ nat\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   467
\ \ \ \ \ \ \isacommand{show}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   468
\ {\isachardoublequoteopen}n\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ n{\isachardoublequoteclose}\isanewline
haftmann
parents: 25200
diff changeset
   469
\ \ \ \ \ \ \ \ \isacommand{unfolding}\isamarkupfalse%
25871
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   470
\ neutral{\isacharunderscore}nat{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   471
\ {\isacharparenleft}induct\ n{\isacharparenright}\ simp{\isacharunderscore}all\isanewline
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   472
\ \ \ \ \isacommand{next}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   473
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   474
\ \ \ \ \ \ \isacommand{fix}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   475
\ k\ {\isacharcolon}{\isacharcolon}\ int\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   476
\ \ \ \ \ \ \isacommand{show}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   477
\ {\isachardoublequoteopen}k\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ k{\isachardoublequoteclose}\isanewline
haftmann
parents: 25200
diff changeset
   478
\ \ \ \ \ \ \ \ \isacommand{unfolding}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   479
\ neutral{\isacharunderscore}int{\isacharunderscore}def\ mult{\isacharunderscore}int{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   480
\ simp\isanewline
25247
haftmann
parents: 25200
diff changeset
   481
\ \ \ \ \isacommand{qed}\isamarkupfalse%
haftmann
parents: 25200
diff changeset
   482
%
haftmann
parents: 25200
diff changeset
   483
\endisatagproof
haftmann
parents: 25200
diff changeset
   484
{\isafoldproof}%
haftmann
parents: 25200
diff changeset
   485
%
haftmann
parents: 25200
diff changeset
   486
\isadelimproof
haftmann
parents: 25200
diff changeset
   487
%
haftmann
parents: 25200
diff changeset
   488
\endisadelimproof
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   489
\isanewline
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   490
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   491
\ \ \ \ \isacommand{end}\isamarkupfalse%
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   492
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   493
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   494
\ \ \ \ \isacommand{instantiation}\isamarkupfalse%
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   495
\ {\isacharasterisk}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}monoid{\isacharcomma}\ monoid{\isacharparenright}\ monoid\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   496
\ \ \ \ \isakeyword{begin}\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   497
\isanewline
25247
haftmann
parents: 25200
diff changeset
   498
\ \ \ \ \isacommand{instance}\isamarkupfalse%
haftmann
parents: 25200
diff changeset
   499
%
haftmann
parents: 25200
diff changeset
   500
\isadelimproof
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   501
\ %
25247
haftmann
parents: 25200
diff changeset
   502
\endisadelimproof
haftmann
parents: 25200
diff changeset
   503
%
haftmann
parents: 25200
diff changeset
   504
\isatagproof
haftmann
parents: 25200
diff changeset
   505
\isacommand{proof}\isamarkupfalse%
haftmann
parents: 25200
diff changeset
   506
\ \isanewline
haftmann
parents: 25200
diff changeset
   507
\ \ \ \ \ \ \isacommand{fix}\isamarkupfalse%
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   508
\ p\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}{\isasymColon}monoid\ {\isasymtimes}\ {\isasymbeta}{\isasymColon}monoid{\isachardoublequoteclose}\isanewline
25247
haftmann
parents: 25200
diff changeset
   509
\ \ \ \ \ \ \isacommand{show}\isamarkupfalse%
haftmann
parents: 25200
diff changeset
   510
\ {\isachardoublequoteopen}p\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ p{\isachardoublequoteclose}\isanewline
haftmann
parents: 25200
diff changeset
   511
\ \ \ \ \ \ \ \ \isacommand{unfolding}\isamarkupfalse%
haftmann
parents: 25200
diff changeset
   512
\ neutral{\isacharunderscore}prod{\isacharunderscore}def\ mult{\isacharunderscore}prod{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
haftmann
parents: 25200
diff changeset
   513
\ {\isacharparenleft}simp\ add{\isacharcolon}\ neutr{\isacharparenright}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   514
\ \ \ \ \isacommand{qed}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   515
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   516
\endisatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   517
{\isafoldproof}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   518
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   519
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   520
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   521
\endisadelimproof
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   522
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   523
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   524
\ \ \ \ \isacommand{end}\isamarkupfalse%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   525
%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   526
\begin{isamarkuptext}%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   527
\noindent To finish our small algebra example, we add a \isa{group} class
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   528
  with a corresponding instance:%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   529
\end{isamarkuptext}%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   530
\isamarkuptrue%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   531
\ \ \ \ \isacommand{class}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   532
\ group\ {\isacharequal}\ monoidl\ {\isacharplus}\isanewline
25200
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   533
\ \ \ \ \ \ \isakeyword{fixes}\ inverse\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\ \ \ \ {\isacharparenleft}{\isachardoublequoteopen}{\isacharparenleft}{\isacharunderscore}{\isasymdiv}{\isacharparenright}{\isachardoublequoteclose}\ {\isacharbrackleft}{\isadigit{1}}{\isadigit{0}}{\isadigit{0}}{\isadigit{0}}{\isacharbrackright}\ {\isadigit{9}}{\isadigit{9}}{\isadigit{9}}{\isacharparenright}\isanewline
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   534
\ \ \ \ \ \ \isakeyword{assumes}\ invl{\isacharcolon}\ {\isachardoublequoteopen}x{\isasymdiv}\ {\isasymotimes}\ x\ {\isacharequal}\ {\isasymone}{\isachardoublequoteclose}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   535
\isanewline
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   536
\ \ \ \ \isacommand{instantiation}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   537
\ int\ {\isacharcolon}{\isacharcolon}\ group\isanewline
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   538
\ \ \ \ \isakeyword{begin}\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   539
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   540
\ \ \ \ \isacommand{definition}\isamarkupfalse%
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   541
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   542
\ \ \ \ \ \ inverse{\isacharunderscore}int{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}i{\isasymdiv}\ {\isacharequal}\ {\isacharminus}\ {\isacharparenleft}i{\isasymColon}int{\isacharparenright}{\isachardoublequoteclose}\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   543
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   544
\ \ \ \ \isacommand{instance}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   545
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   546
\isadelimproof
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   547
\ %
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   548
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   549
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   550
\isatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   551
\isacommand{proof}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   552
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   553
\ \ \ \ \ \ \isacommand{fix}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   554
\ i\ {\isacharcolon}{\isacharcolon}\ int\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   555
\ \ \ \ \ \ \isacommand{have}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   556
\ {\isachardoublequoteopen}{\isacharminus}i\ {\isacharplus}\ i\ {\isacharequal}\ {\isadigit{0}}{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   557
\ simp\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   558
\ \ \ \ \ \ \isacommand{then}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   559
\ \isacommand{show}\isamarkupfalse%
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   560
\ {\isachardoublequoteopen}i{\isasymdiv}\ {\isasymotimes}\ i\ {\isacharequal}\ {\isasymone}{\isachardoublequoteclose}\isanewline
25247
haftmann
parents: 25200
diff changeset
   561
\ \ \ \ \ \ \ \ \isacommand{unfolding}\isamarkupfalse%
haftmann
parents: 25200
diff changeset
   562
\ mult{\isacharunderscore}int{\isacharunderscore}def\ neutral{\isacharunderscore}int{\isacharunderscore}def\ inverse{\isacharunderscore}int{\isacharunderscore}def\ \isacommand{{\isachardot}}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   563
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   564
\ \ \ \ \isacommand{qed}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   565
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   566
\endisatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   567
{\isafoldproof}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   568
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   569
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   570
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   571
\endisadelimproof
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   572
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   573
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   574
\ \ \ \ \isacommand{end}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   575
%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   576
\isamarkupsection{Type classes as locales%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   577
}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   578
\isamarkuptrue%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   579
%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   580
\isamarkupsubsection{A look behind the scene%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   581
}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   582
\isamarkuptrue%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   583
%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   584
\begin{isamarkuptext}%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   585
The example above gives an impression how Isar type classes work
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   586
  in practice.  As stated in the introduction, classes also provide
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   587
  a link to Isar's locale system.  Indeed, the logical core of a class
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   588
  is nothing else than a locale:%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   589
\end{isamarkuptext}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   590
\isamarkuptrue%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   591
\isacommand{class}\isamarkupfalse%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   592
\ idem\ {\isacharequal}\ type\ {\isacharplus}\isanewline
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   593
\ \ \isakeyword{fixes}\ f\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\isanewline
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   594
\ \ \isakeyword{assumes}\ idem{\isacharcolon}\ {\isachardoublequoteopen}f\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharequal}\ f\ x{\isachardoublequoteclose}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   595
\begin{isamarkuptext}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   596
\noindent essentially introduces the locale%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   597
\end{isamarkuptext}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   598
\isamarkuptrue%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   599
%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   600
\isadelimML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   601
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   602
\endisadelimML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   603
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   604
\isatagML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   605
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   606
\endisatagML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   607
{\isafoldML}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   608
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   609
\isadelimML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   610
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   611
\endisadelimML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   612
\isacommand{locale}\isamarkupfalse%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   613
\ idem\ {\isacharequal}\isanewline
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   614
\ \ \isakeyword{fixes}\ f\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\isanewline
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   615
\ \ \isakeyword{assumes}\ idem{\isacharcolon}\ {\isachardoublequoteopen}f\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharequal}\ f\ x{\isachardoublequoteclose}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   616
\begin{isamarkuptext}%
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   617
\noindent together with corresponding constant(s):%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   618
\end{isamarkuptext}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   619
\isamarkuptrue%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   620
\isacommand{consts}\isamarkupfalse%
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   621
\ f\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}%
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   622
\begin{isamarkuptext}%
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   623
\noindent The connection to the type system is done by means
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   624
  of a primitive axclass%
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   625
\end{isamarkuptext}%
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   626
\isamarkuptrue%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   627
\isacommand{axclass}\isamarkupfalse%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   628
\ idem\ {\isacharless}\ type\isanewline
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   629
\ \ idem{\isacharcolon}\ {\isachardoublequoteopen}f\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharequal}\ f\ x{\isachardoublequoteclose}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   630
\begin{isamarkuptext}%
22649
6cf96b9f7b9e updated;
wenzelm
parents: 22550
diff changeset
   631
\noindent together with a corresponding interpretation:%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   632
\end{isamarkuptext}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   633
\isamarkuptrue%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   634
\isacommand{interpretation}\isamarkupfalse%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   635
\ idem{\isacharunderscore}class{\isacharcolon}\isanewline
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   636
\ \ idem\ {\isacharbrackleft}{\isachardoublequoteopen}f\ {\isasymColon}\ {\isacharparenleft}{\isasymalpha}{\isasymColon}idem{\isacharparenright}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}{\isacharbrackright}\isanewline
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   637
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   638
\isadelimproof
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   639
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   640
\endisadelimproof
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   641
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   642
\isatagproof
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   643
\isacommand{by}\isamarkupfalse%
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   644
\ unfold{\isacharunderscore}locales\ {\isacharparenleft}rule\ idem{\isacharparenright}%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   645
\endisatagproof
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   646
{\isafoldproof}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   647
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   648
\isadelimproof
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   649
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   650
\endisadelimproof
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   651
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   652
\isadelimML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   653
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   654
\endisadelimML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   655
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   656
\isatagML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   657
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   658
\endisatagML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   659
{\isafoldML}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   660
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   661
\isadelimML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   662
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   663
\endisadelimML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   664
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   665
\begin{isamarkuptext}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   666
This give you at hand the full power of the Isabelle module system;
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   667
  conclusions in locale \isa{idem} are implicitly propagated
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   668
  to class \isa{idem}.%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   669
\end{isamarkuptext}%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   670
\isamarkuptrue%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   671
%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   672
\isamarkupsubsection{Abstract reasoning%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   673
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   674
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   675
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   676
\begin{isamarkuptext}%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   677
Isabelle locales enable reasoning at a general level, while results
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   678
  are implicitly transferred to all instances.  For example, we can
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   679
  now establish the \isa{left{\isacharunderscore}cancel} lemma for groups, which
25247
haftmann
parents: 25200
diff changeset
   680
  states that the function \isa{{\isacharparenleft}x\ {\isasymotimes}{\isacharparenright}} is injective:%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   681
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   682
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   683
\ \ \ \ \isacommand{lemma}\isamarkupfalse%
25200
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   684
\ {\isacharparenleft}\isakeyword{in}\ group{\isacharparenright}\ left{\isacharunderscore}cancel{\isacharcolon}\ {\isachardoublequoteopen}x\ {\isasymotimes}\ y\ {\isacharequal}\ x\ {\isasymotimes}\ z\ {\isasymlongleftrightarrow}\ y\ {\isacharequal}\ z{\isachardoublequoteclose}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   685
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   686
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   687
\ \ \ \ %
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   688
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   689
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   690
\isatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   691
\isacommand{proof}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   692
\isanewline
25247
haftmann
parents: 25200
diff changeset
   693
\ \ \ \ \ \ \isacommand{assume}\isamarkupfalse%
25200
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   694
\ {\isachardoublequoteopen}x\ {\isasymotimes}\ y\ {\isacharequal}\ x\ {\isasymotimes}\ z{\isachardoublequoteclose}\isanewline
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   695
\ \ \ \ \ \ \isacommand{then}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   696
\ \isacommand{have}\isamarkupfalse%
25200
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   697
\ {\isachardoublequoteopen}x{\isasymdiv}\ {\isasymotimes}\ {\isacharparenleft}x\ {\isasymotimes}\ y{\isacharparenright}\ {\isacharequal}\ x{\isasymdiv}\ {\isasymotimes}\ {\isacharparenleft}x\ {\isasymotimes}\ z{\isacharparenright}{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   698
\ simp\isanewline
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   699
\ \ \ \ \ \ \isacommand{then}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   700
\ \isacommand{have}\isamarkupfalse%
25200
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   701
\ {\isachardoublequoteopen}{\isacharparenleft}x{\isasymdiv}\ {\isasymotimes}\ x{\isacharparenright}\ {\isasymotimes}\ y\ {\isacharequal}\ {\isacharparenleft}x{\isasymdiv}\ {\isasymotimes}\ x{\isacharparenright}\ {\isasymotimes}\ z{\isachardoublequoteclose}\ \isacommand{using}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   702
\ assoc\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   703
\ simp\isanewline
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   704
\ \ \ \ \ \ \isacommand{then}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   705
\ \isacommand{show}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   706
\ {\isachardoublequoteopen}y\ {\isacharequal}\ z{\isachardoublequoteclose}\ \isacommand{using}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   707
\ neutl\ \isakeyword{and}\ invl\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   708
\ simp\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   709
\ \ \ \ \isacommand{next}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   710
\isanewline
25247
haftmann
parents: 25200
diff changeset
   711
\ \ \ \ \ \ \isacommand{assume}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   712
\ {\isachardoublequoteopen}y\ {\isacharequal}\ z{\isachardoublequoteclose}\isanewline
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   713
\ \ \ \ \ \ \isacommand{then}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   714
\ \isacommand{show}\isamarkupfalse%
25200
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   715
\ {\isachardoublequoteopen}x\ {\isasymotimes}\ y\ {\isacharequal}\ x\ {\isasymotimes}\ z{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   716
\ simp\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   717
\ \ \ \ \isacommand{qed}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   718
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   719
\endisatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   720
{\isafoldproof}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   721
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   722
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   723
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   724
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   725
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   726
\begin{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   727
\noindent Here the \qt{\isa{{\isasymIN}\ group}} target specification
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   728
  indicates that the result is recorded within that context for later
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   729
  use.  This local theorem is also lifted to the global one \isa{group{\isachardot}left{\isacharunderscore}cancel{\isacharcolon}} \isa{{\isachardoublequote}{\isasymAnd}x\ y\ z\ {\isasymColon}\ {\isasymalpha}{\isasymColon}group{\isachardot}\ x\ {\isasymotimes}\ y\ {\isacharequal}\ x\ {\isasymotimes}\ z\ {\isasymlongleftrightarrow}\ y\ {\isacharequal}\ z{\isachardoublequote}}.  Since type \isa{int} has been made an instance of
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   730
  \isa{group} before, we may refer to that fact as well: \isa{{\isachardoublequote}{\isasymAnd}x\ y\ z\ {\isasymColon}\ int{\isachardot}\ x\ {\isasymotimes}\ y\ {\isacharequal}\ x\ {\isasymotimes}\ z\ {\isasymlongleftrightarrow}\ y\ {\isacharequal}\ z{\isachardoublequote}}.%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   731
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   732
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   733
%
23956
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   734
\isamarkupsubsection{Derived definitions%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   735
}
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   736
\isamarkuptrue%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   737
%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   738
\begin{isamarkuptext}%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   739
Isabelle locales support a concept of local definitions
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   740
  in locales:%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   741
\end{isamarkuptext}%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   742
\isamarkuptrue%
25871
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   743
\ \ \ \ \isacommand{primrec}\isamarkupfalse%
23956
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   744
\ {\isacharparenleft}\isakeyword{in}\ monoid{\isacharparenright}\isanewline
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   745
\ \ \ \ \ \ pow{\isacharunderscore}nat\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
25200
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   746
\ \ \ \ \ \ {\isachardoublequoteopen}pow{\isacharunderscore}nat\ {\isadigit{0}}\ x\ {\isacharequal}\ {\isasymone}{\isachardoublequoteclose}\isanewline
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   747
\ \ \ \ \ \ {\isacharbar}\ {\isachardoublequoteopen}pow{\isacharunderscore}nat\ {\isacharparenleft}Suc\ n{\isacharparenright}\ x\ {\isacharequal}\ x\ {\isasymotimes}\ pow{\isacharunderscore}nat\ n\ x{\isachardoublequoteclose}%
23956
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   748
\begin{isamarkuptext}%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   749
\noindent If the locale \isa{group} is also a class, this local
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   750
  definition is propagated onto a global definition of
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   751
  \isa{{\isachardoublequote}pow{\isacharunderscore}nat\ {\isasymColon}\ nat\ {\isasymRightarrow}\ {\isasymalpha}{\isasymColon}monoid\ {\isasymRightarrow}\ {\isasymalpha}{\isasymColon}monoid{\isachardoublequote}}
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   752
  with corresponding theorems
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   753
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   754
  \isa{pow{\isacharunderscore}nat\ {\isadigit{0}}\ x\ {\isacharequal}\ {\isasymone}\isasep\isanewline%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   755
pow{\isacharunderscore}nat\ {\isacharparenleft}Suc\ n{\isacharparenright}\ x\ {\isacharequal}\ x\ {\isasymotimes}\ pow{\isacharunderscore}nat\ n\ x}.
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   756
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   757
  \noindent As you can see from this example, for local
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   758
  definitions you may use any specification tool
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   759
  which works together with locales (e.g. \cite{krauss2006}).%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   760
\end{isamarkuptext}%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   761
\isamarkuptrue%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   762
%
25247
haftmann
parents: 25200
diff changeset
   763
\isamarkupsubsection{A functor analogy%
haftmann
parents: 25200
diff changeset
   764
}
haftmann
parents: 25200
diff changeset
   765
\isamarkuptrue%
haftmann
parents: 25200
diff changeset
   766
%
haftmann
parents: 25200
diff changeset
   767
\begin{isamarkuptext}%
haftmann
parents: 25200
diff changeset
   768
We introduced Isar classes by analogy to type classes
haftmann
parents: 25200
diff changeset
   769
  functional programming;  if we reconsider this in the
haftmann
parents: 25200
diff changeset
   770
  context of what has been said about type classes and locales,
haftmann
parents: 25200
diff changeset
   771
  we can drive this analogy further by stating that type
haftmann
parents: 25200
diff changeset
   772
  classes essentially correspond to functors which have
haftmann
parents: 25200
diff changeset
   773
  a canonical interpretation as type classes.
haftmann
parents: 25200
diff changeset
   774
  Anyway, there is also the possibility of other interpretations.
haftmann
parents: 25200
diff changeset
   775
  For example, also \isa{list}s form a monoid with
haftmann
parents: 25200
diff changeset
   776
  \isa{op\ {\isacharat}} and \isa{{\isacharbrackleft}{\isacharbrackright}} as operations, but it
haftmann
parents: 25200
diff changeset
   777
  seems inappropriate to apply to lists
haftmann
parents: 25200
diff changeset
   778
  the same operations as for genuinly algebraic types.
haftmann
parents: 25200
diff changeset
   779
  In such a case, we simply can do a particular interpretation
haftmann
parents: 25200
diff changeset
   780
  of monoids for lists:%
haftmann
parents: 25200
diff changeset
   781
\end{isamarkuptext}%
haftmann
parents: 25200
diff changeset
   782
\isamarkuptrue%
haftmann
parents: 25200
diff changeset
   783
\ \ \ \ \isacommand{interpretation}\isamarkupfalse%
haftmann
parents: 25200
diff changeset
   784
\ list{\isacharunderscore}monoid{\isacharcolon}\ monoid\ {\isacharbrackleft}{\isachardoublequoteopen}op\ {\isacharat}{\isachardoublequoteclose}\ {\isachardoublequoteopen}{\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}{\isacharbrackright}\isanewline
haftmann
parents: 25200
diff changeset
   785
%
haftmann
parents: 25200
diff changeset
   786
\isadelimproof
haftmann
parents: 25200
diff changeset
   787
\ \ \ \ \ \ %
haftmann
parents: 25200
diff changeset
   788
\endisadelimproof
haftmann
parents: 25200
diff changeset
   789
%
haftmann
parents: 25200
diff changeset
   790
\isatagproof
haftmann
parents: 25200
diff changeset
   791
\isacommand{by}\isamarkupfalse%
haftmann
parents: 25200
diff changeset
   792
\ unfold{\isacharunderscore}locales\ auto%
haftmann
parents: 25200
diff changeset
   793
\endisatagproof
haftmann
parents: 25200
diff changeset
   794
{\isafoldproof}%
haftmann
parents: 25200
diff changeset
   795
%
haftmann
parents: 25200
diff changeset
   796
\isadelimproof
haftmann
parents: 25200
diff changeset
   797
%
haftmann
parents: 25200
diff changeset
   798
\endisadelimproof
haftmann
parents: 25200
diff changeset
   799
%
haftmann
parents: 25200
diff changeset
   800
\begin{isamarkuptext}%
haftmann
parents: 25200
diff changeset
   801
\noindent This enables us to apply facts on monoids
haftmann
parents: 25200
diff changeset
   802
  to lists, e.g. \isa{{\isacharbrackleft}{\isacharbrackright}\ {\isacharat}\ x\ {\isacharequal}\ x}.
haftmann
parents: 25200
diff changeset
   803
haftmann
parents: 25200
diff changeset
   804
  When using this interpretation pattern, it may also
haftmann
parents: 25200
diff changeset
   805
  be appropriate to map derived definitions accordingly:%
haftmann
parents: 25200
diff changeset
   806
\end{isamarkuptext}%
haftmann
parents: 25200
diff changeset
   807
\isamarkuptrue%
haftmann
parents: 25200
diff changeset
   808
\ \ \ \ \isacommand{fun}\isamarkupfalse%
haftmann
parents: 25200
diff changeset
   809
\isanewline
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   810
\ \ \ \ \ \ replicate\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ {\isasymalpha}\ list\ {\isasymRightarrow}\ {\isasymalpha}\ list{\isachardoublequoteclose}\isanewline
25247
haftmann
parents: 25200
diff changeset
   811
\ \ \ \ \isakeyword{where}\isanewline
haftmann
parents: 25200
diff changeset
   812
\ \ \ \ \ \ {\isachardoublequoteopen}replicate\ {\isadigit{0}}\ {\isacharunderscore}\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}\isanewline
haftmann
parents: 25200
diff changeset
   813
\ \ \ \ \ \ {\isacharbar}\ {\isachardoublequoteopen}replicate\ {\isacharparenleft}Suc\ n{\isacharparenright}\ xs\ {\isacharequal}\ xs\ {\isacharat}\ replicate\ n\ xs{\isachardoublequoteclose}\isanewline
haftmann
parents: 25200
diff changeset
   814
\isanewline
haftmann
parents: 25200
diff changeset
   815
\ \ \ \ \isacommand{interpretation}\isamarkupfalse%
haftmann
parents: 25200
diff changeset
   816
\ list{\isacharunderscore}monoid{\isacharcolon}\ monoid\ {\isacharbrackleft}{\isachardoublequoteopen}op\ {\isacharat}{\isachardoublequoteclose}\ {\isachardoublequoteopen}{\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}{\isacharbrackright}\ \isakeyword{where}\isanewline
haftmann
parents: 25200
diff changeset
   817
\ \ \ \ \ \ {\isachardoublequoteopen}monoid{\isachardot}pow{\isacharunderscore}nat\ {\isacharparenleft}op\ {\isacharat}{\isacharparenright}\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ replicate{\isachardoublequoteclose}\isanewline
haftmann
parents: 25200
diff changeset
   818
%
haftmann
parents: 25200
diff changeset
   819
\isadelimproof
haftmann
parents: 25200
diff changeset
   820
\ \ \ \ %
haftmann
parents: 25200
diff changeset
   821
\endisadelimproof
haftmann
parents: 25200
diff changeset
   822
%
haftmann
parents: 25200
diff changeset
   823
\isatagproof
haftmann
parents: 25200
diff changeset
   824
\isacommand{proof}\isamarkupfalse%
haftmann
parents: 25200
diff changeset
   825
\isanewline
haftmann
parents: 25200
diff changeset
   826
\ \ \ \ \ \ \isacommand{fix}\isamarkupfalse%
haftmann
parents: 25200
diff changeset
   827
\ n\ {\isacharcolon}{\isacharcolon}\ nat\isanewline
haftmann
parents: 25200
diff changeset
   828
\ \ \ \ \ \ \isacommand{show}\isamarkupfalse%
haftmann
parents: 25200
diff changeset
   829
\ {\isachardoublequoteopen}monoid{\isachardot}pow{\isacharunderscore}nat\ {\isacharparenleft}op\ {\isacharat}{\isacharparenright}\ {\isacharbrackleft}{\isacharbrackright}\ n\ {\isacharequal}\ replicate\ n{\isachardoublequoteclose}\isanewline
haftmann
parents: 25200
diff changeset
   830
\ \ \ \ \ \ \ \ \isacommand{by}\isamarkupfalse%
haftmann
parents: 25200
diff changeset
   831
\ {\isacharparenleft}induct\ n{\isacharparenright}\ auto\isanewline
haftmann
parents: 25200
diff changeset
   832
\ \ \ \ \isacommand{qed}\isamarkupfalse%
haftmann
parents: 25200
diff changeset
   833
%
haftmann
parents: 25200
diff changeset
   834
\endisatagproof
haftmann
parents: 25200
diff changeset
   835
{\isafoldproof}%
haftmann
parents: 25200
diff changeset
   836
%
haftmann
parents: 25200
diff changeset
   837
\isadelimproof
haftmann
parents: 25200
diff changeset
   838
%
haftmann
parents: 25200
diff changeset
   839
\endisadelimproof
haftmann
parents: 25200
diff changeset
   840
%
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   841
\isamarkupsubsection{Additional subclass relations%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   842
}
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   843
\isamarkuptrue%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   844
%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   845
\begin{isamarkuptext}%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   846
Any \isa{group} is also a \isa{monoid};  this
25247
haftmann
parents: 25200
diff changeset
   847
  can be made explicit by claiming an additional
haftmann
parents: 25200
diff changeset
   848
  subclass relation,
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   849
  together with a proof of the logical difference:%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   850
\end{isamarkuptext}%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   851
\isamarkuptrue%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   852
\ \ \ \ \isacommand{subclass}\isamarkupfalse%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   853
\ {\isacharparenleft}\isakeyword{in}\ group{\isacharparenright}\ monoid\isanewline
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   854
%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   855
\isadelimproof
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   856
\ \ \ \ %
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   857
\endisadelimproof
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   858
%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   859
\isatagproof
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   860
\isacommand{proof}\isamarkupfalse%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   861
\ unfold{\isacharunderscore}locales\isanewline
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   862
\ \ \ \ \ \ \isacommand{fix}\isamarkupfalse%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   863
\ x\isanewline
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   864
\ \ \ \ \ \ \isacommand{from}\isamarkupfalse%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   865
\ invl\ \isacommand{have}\isamarkupfalse%
25200
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   866
\ {\isachardoublequoteopen}x{\isasymdiv}\ {\isasymotimes}\ x\ {\isacharequal}\ {\isasymone}{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   867
\ simp\isanewline
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   868
\ \ \ \ \ \ \isacommand{with}\isamarkupfalse%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   869
\ assoc\ {\isacharbrackleft}symmetric{\isacharbrackright}\ neutl\ invl\ \isacommand{have}\isamarkupfalse%
25200
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   870
\ {\isachardoublequoteopen}x{\isasymdiv}\ {\isasymotimes}\ {\isacharparenleft}x\ {\isasymotimes}\ {\isasymone}{\isacharparenright}\ {\isacharequal}\ x{\isasymdiv}\ {\isasymotimes}\ x{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   871
\ simp\isanewline
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   872
\ \ \ \ \ \ \isacommand{with}\isamarkupfalse%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   873
\ left{\isacharunderscore}cancel\ \isacommand{show}\isamarkupfalse%
25200
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   874
\ {\isachardoublequoteopen}x\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ x{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   875
\ simp\isanewline
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   876
\ \ \ \ \isacommand{qed}\isamarkupfalse%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   877
%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   878
\endisatagproof
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   879
{\isafoldproof}%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   880
%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   881
\isadelimproof
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   882
%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   883
\endisadelimproof
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   884
%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   885
\begin{isamarkuptext}%
25200
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   886
\noindent The logical proof is carried out on the locale level
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   887
  and thus conveniently is opened using the \isa{unfold{\isacharunderscore}locales}
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   888
  method which only leaves the logical differences still
25200
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   889
  open to proof to the user.  Afterwards it is propagated
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   890
  to the type system, making \isa{group} an instance of
25247
haftmann
parents: 25200
diff changeset
   891
  \isa{monoid} by adding an additional edge
haftmann
parents: 25200
diff changeset
   892
  to the graph of subclass relations
haftmann
parents: 25200
diff changeset
   893
  (cf.\ \figref{fig:subclass}).
haftmann
parents: 25200
diff changeset
   894
haftmann
parents: 25200
diff changeset
   895
  \begin{figure}[htbp]
haftmann
parents: 25200
diff changeset
   896
   \begin{center}
haftmann
parents: 25200
diff changeset
   897
     \small
haftmann
parents: 25200
diff changeset
   898
     \unitlength 0.6mm
haftmann
parents: 25200
diff changeset
   899
     \begin{picture}(40,60)(0,0)
haftmann
parents: 25200
diff changeset
   900
       \put(20,60){\makebox(0,0){\isa{semigroup}}}
haftmann
parents: 25200
diff changeset
   901
       \put(20,40){\makebox(0,0){\isa{monoidl}}}
haftmann
parents: 25200
diff changeset
   902
       \put(00,20){\makebox(0,0){\isa{monoid}}}
haftmann
parents: 25200
diff changeset
   903
       \put(40,00){\makebox(0,0){\isa{group}}}
haftmann
parents: 25200
diff changeset
   904
       \put(20,55){\vector(0,-1){10}}
haftmann
parents: 25200
diff changeset
   905
       \put(15,35){\vector(-1,-1){10}}
haftmann
parents: 25200
diff changeset
   906
       \put(25,35){\vector(1,-3){10}}
haftmann
parents: 25200
diff changeset
   907
     \end{picture}
haftmann
parents: 25200
diff changeset
   908
     \hspace{8em}
haftmann
parents: 25200
diff changeset
   909
     \begin{picture}(40,60)(0,0)
haftmann
parents: 25200
diff changeset
   910
       \put(20,60){\makebox(0,0){\isa{semigroup}}}
haftmann
parents: 25200
diff changeset
   911
       \put(20,40){\makebox(0,0){\isa{monoidl}}}
haftmann
parents: 25200
diff changeset
   912
       \put(00,20){\makebox(0,0){\isa{monoid}}}
haftmann
parents: 25200
diff changeset
   913
       \put(40,00){\makebox(0,0){\isa{group}}}
haftmann
parents: 25200
diff changeset
   914
       \put(20,55){\vector(0,-1){10}}
haftmann
parents: 25200
diff changeset
   915
       \put(15,35){\vector(-1,-1){10}}
haftmann
parents: 25200
diff changeset
   916
       \put(05,15){\vector(3,-1){30}}
haftmann
parents: 25200
diff changeset
   917
     \end{picture}
haftmann
parents: 25200
diff changeset
   918
     \caption{Subclass relationship of monoids and groups:
haftmann
parents: 25200
diff changeset
   919
        before and after establishing the relationship
haftmann
parents: 25200
diff changeset
   920
        \isa{group\ {\isasymsubseteq}\ monoid};  transitive edges left out.}
haftmann
parents: 25200
diff changeset
   921
     \label{fig:subclass}
haftmann
parents: 25200
diff changeset
   922
   \end{center}
haftmann
parents: 25200
diff changeset
   923
  \end{figure}
haftmann
parents: 25200
diff changeset
   924
haftmann
parents: 25200
diff changeset
   925
  For illustration, a derived definition
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   926
  in \isa{group} which uses \isa{pow{\isacharunderscore}nat}:%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   927
\end{isamarkuptext}%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   928
\isamarkuptrue%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   929
\ \ \ \ \isacommand{definition}\isamarkupfalse%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   930
\ {\isacharparenleft}\isakeyword{in}\ group{\isacharparenright}\isanewline
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   931
\ \ \ \ \ \ pow{\isacharunderscore}int\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}int\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   932
\ \ \ \ \ \ {\isachardoublequoteopen}pow{\isacharunderscore}int\ k\ x\ {\isacharequal}\ {\isacharparenleft}if\ k\ {\isachargreater}{\isacharequal}\ {\isadigit{0}}\isanewline
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   933
\ \ \ \ \ \ \ \ then\ pow{\isacharunderscore}nat\ {\isacharparenleft}nat\ k{\isacharparenright}\ x\isanewline
25200
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   934
\ \ \ \ \ \ \ \ else\ {\isacharparenleft}pow{\isacharunderscore}nat\ {\isacharparenleft}nat\ {\isacharparenleft}{\isacharminus}\ k{\isacharparenright}{\isacharparenright}\ x{\isacharparenright}{\isasymdiv}{\isacharparenright}{\isachardoublequoteclose}%
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   935
\begin{isamarkuptext}%
25247
haftmann
parents: 25200
diff changeset
   936
\noindent yields the global definition of
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   937
  \isa{{\isachardoublequote}pow{\isacharunderscore}int\ {\isasymColon}\ int\ {\isasymRightarrow}\ {\isasymalpha}{\isasymColon}group\ {\isasymRightarrow}\ {\isasymalpha}{\isasymColon}group{\isachardoublequote}}
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   938
  with the corresponding theorem \isa{pow{\isacharunderscore}int\ k\ x\ {\isacharequal}\ {\isacharparenleft}if\ {\isadigit{0}}\ {\isasymle}\ k\ then\ pow{\isacharunderscore}nat\ {\isacharparenleft}nat\ k{\isacharparenright}\ x\ else\ {\isacharparenleft}pow{\isacharunderscore}nat\ {\isacharparenleft}nat\ {\isacharparenleft}{\isacharminus}\ k{\isacharparenright}{\isacharparenright}\ x{\isacharparenright}{\isasymdiv}{\isacharparenright}}.%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   939
\end{isamarkuptext}%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   940
\isamarkuptrue%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   941
%
25868
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   942
\isamarkupsubsection{A note on syntax%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   943
}
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   944
\isamarkuptrue%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   945
%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   946
\begin{isamarkuptext}%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   947
As a commodity, class context syntax allows to refer
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   948
  to local class operations and their global conuterparts
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   949
  uniformly;  type inference resolves ambiguities.  For example:%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   950
\end{isamarkuptext}%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   951
\isamarkuptrue%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   952
\isacommand{context}\isamarkupfalse%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   953
\ semigroup\isanewline
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   954
\isakeyword{begin}\isanewline
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   955
\isanewline
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   956
\isacommand{term}\isamarkupfalse%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   957
\ {\isachardoublequoteopen}x\ {\isasymotimes}\ y{\isachardoublequoteclose}\ %
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   958
\isamarkupcmt{example 1%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   959
}
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   960
\isanewline
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   961
\isacommand{term}\isamarkupfalse%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   962
\ {\isachardoublequoteopen}{\isacharparenleft}x{\isasymColon}nat{\isacharparenright}\ {\isasymotimes}\ y{\isachardoublequoteclose}\ %
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   963
\isamarkupcmt{example 2%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   964
}
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   965
\isanewline
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   966
\isanewline
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   967
\isacommand{end}\isamarkupfalse%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   968
\isanewline
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   969
\isanewline
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   970
\isacommand{term}\isamarkupfalse%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   971
\ {\isachardoublequoteopen}x\ {\isasymotimes}\ y{\isachardoublequoteclose}\ %
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   972
\isamarkupcmt{example 3%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   973
}
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   974
%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   975
\begin{isamarkuptext}%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   976
\noindent Here in example 1, the term refers to the local class operation
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   977
  \isa{mult\ {\isacharbrackleft}{\isasymalpha}{\isacharbrackright}}, whereas in example 2 the type constraint
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   978
  enforces the global class operation \isa{mult\ {\isacharbrackleft}nat{\isacharbrackright}}.
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   979
  In the global context in example 3, the reference is
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   980
  to the polymorphic global class operation \isa{mult\ {\isacharbrackleft}{\isacharquery}{\isasymalpha}\ {\isasymColon}\ semigroup{\isacharbrackright}}.%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   981
\end{isamarkuptext}%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   982
\isamarkuptrue%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
   983
%
25247
haftmann
parents: 25200
diff changeset
   984
\isamarkupsection{Type classes and code generation%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   985
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   986
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   987
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   988
\begin{isamarkuptext}%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   989
Turning back to the first motivation for type classes,
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   990
  namely overloading, it is obvious that overloading
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   991
  stemming from \isa{{\isasymCLASS}} statements and
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   992
  \isa{{\isasymINSTANTIATION}}
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   993
  targets naturally maps to Haskell type classes.
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   994
  The code generator framework \cite{isabelle-codegen} 
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   995
  takes this into account.  Concerning target languages
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   996
  lacking type classes (e.g.~SML), type classes
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   997
  are implemented by explicit dictionary construction.
23956
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   998
  For example, lets go back to the power function:%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   999
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1000
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1001
\ \ \ \ \isacommand{definition}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1002
\isanewline
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
  1003
\ \ \ \ \ \ example\ {\isacharcolon}{\isacharcolon}\ int\ \isakeyword{where}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1004
\ \ \ \ \ \ {\isachardoublequoteopen}example\ {\isacharequal}\ pow{\isacharunderscore}int\ {\isadigit{1}}{\isadigit{0}}\ {\isacharparenleft}{\isacharminus}{\isadigit{2}}{\isacharparenright}{\isachardoublequoteclose}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1005
\begin{isamarkuptext}%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
  1006
\noindent This maps to Haskell as:%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1007
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1008
\isamarkuptrue%
24628
33137422d7fd updated
haftmann
parents: 23956
diff changeset
  1009
\isacommand{export{\isacharunderscore}code}\isamarkupfalse%
33137422d7fd updated
haftmann
parents: 23956
diff changeset
  1010
\ example\ \isakeyword{in}\ Haskell\ \isakeyword{module{\isacharunderscore}name}\ Classes\ \isakeyword{file}\ {\isachardoublequoteopen}code{\isacharunderscore}examples{\isacharslash}{\isachardoublequoteclose}%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1011
\begin{isamarkuptext}%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
  1012
\lsthaskell{Thy/code_examples/Classes.hs}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
  1013
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
  1014
  \noindent The whole code in SML with explicit dictionary passing:%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
  1015
\end{isamarkuptext}%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
  1016
\isamarkuptrue%
24628
33137422d7fd updated
haftmann
parents: 23956
diff changeset
  1017
\isacommand{export{\isacharunderscore}code}\isamarkupfalse%
33137422d7fd updated
haftmann
parents: 23956
diff changeset
  1018
\ example\ \isakeyword{in}\ SML\ \isakeyword{module{\isacharunderscore}name}\ Classes\ \isakeyword{file}\ {\isachardoublequoteopen}code{\isacharunderscore}examples{\isacharslash}classes{\isachardot}ML{\isachardoublequoteclose}%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
  1019
\begin{isamarkuptext}%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
  1020
\lstsml{Thy/code_examples/classes.ML}%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1021
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1022
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1023
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1024
\isadelimtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1025
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1026
\endisadelimtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1027
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1028
\isatagtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1029
\isacommand{end}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1030
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1031
\endisatagtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1032
{\isafoldtheory}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1033
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1034
\isadelimtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1035
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1036
\endisadelimtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1037
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1038
\end{isabellebody}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1039
%%% Local Variables:
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1040
%%% mode: latex
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1041
%%% TeX-master: "root"
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1042
%%% End: