doc-src/IsarRef/Thy/document/HOL_Specific.tex
author haftmann
Tue, 11 Jan 2011 14:14:13 +0100
changeset 41753 4c717333b0cc
parent 41752 6d19301074cf
child 42719 f53e0e0baa4f
permissions -rw-r--r--
tuned text
wenzelm@26840
     1
%
wenzelm@26840
     2
\begin{isabellebody}%
wenzelm@40685
     3
\def\isabellecontext{HOL{\isaliteral{5F}{\isacharunderscore}}Specific}%
wenzelm@26840
     4
%
wenzelm@26840
     5
\isadelimtheory
wenzelm@26840
     6
%
wenzelm@26840
     7
\endisadelimtheory
wenzelm@26840
     8
%
wenzelm@26840
     9
\isatagtheory
wenzelm@26840
    10
\isacommand{theory}\isamarkupfalse%
wenzelm@40685
    11
\ HOL{\isaliteral{5F}{\isacharunderscore}}Specific\isanewline
wenzelm@26849
    12
\isakeyword{imports}\ Main\isanewline
wenzelm@26849
    13
\isakeyword{begin}%
wenzelm@26849
    14
\endisatagtheory
wenzelm@26849
    15
{\isafoldtheory}%
wenzelm@26849
    16
%
wenzelm@26849
    17
\isadelimtheory
wenzelm@26849
    18
%
wenzelm@26849
    19
\endisadelimtheory
wenzelm@26849
    20
%
wenzelm@26852
    21
\isamarkupchapter{Isabelle/HOL \label{ch:hol}%
wenzelm@26849
    22
}
wenzelm@26849
    23
\isamarkuptrue%
wenzelm@26849
    24
%
wenzelm@35757
    25
\isamarkupsection{Typedef axiomatization \label{sec:hol-typedef}%
wenzelm@26849
    26
}
wenzelm@26849
    27
\isamarkuptrue%
wenzelm@26849
    28
%
wenzelm@26849
    29
\begin{isamarkuptext}%
wenzelm@26849
    30
\begin{matharray}{rcl}
wenzelm@40685
    31
    \indexdef{HOL}{command}{typedef}\hypertarget{command.HOL.typedef}{\hyperlink{command.HOL.typedef}{\mbox{\isa{\isacommand{typedef}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}local{\isaliteral{5F}{\isacharunderscore}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ proof{\isaliteral{28}{\isacharparenleft}}prove{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@26849
    32
  \end{matharray}
wenzelm@26849
    33
wenzelm@26849
    34
  \begin{rail}
wenzelm@26849
    35
    'typedef' altname? abstype '=' repset
wenzelm@26849
    36
    ;
wenzelm@26849
    37
wenzelm@26849
    38
    altname: '(' (name | 'open' | 'open' name) ')'
wenzelm@26849
    39
    ;
wenzelm@35841
    40
    abstype: typespecsorts mixfix?
wenzelm@26849
    41
    ;
wenzelm@26849
    42
    repset: term ('morphisms' name name)?
wenzelm@26849
    43
    ;
wenzelm@26849
    44
  \end{rail}
wenzelm@26849
    45
wenzelm@28788
    46
  \begin{description}
wenzelm@26849
    47
  
wenzelm@40685
    48
  \item \hyperlink{command.HOL.typedef}{\mbox{\isa{\isacommand{typedef}}}}~\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C616C7068613E}{\isasymalpha}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C616C7068613E}{\isasymalpha}}\isaliteral{5C3C5E7375623E}{}\isactrlsub n{\isaliteral{29}{\isacharparenright}}\ t\ {\isaliteral{3D}{\isacharequal}}\ A{\isaliteral{22}{\isachardoublequote}}}
wenzelm@35757
    49
  axiomatizes a Gordon/HOL-style type definition in the background
wenzelm@35757
    50
  theory of the current context, depending on a non-emptiness result
wenzelm@35757
    51
  of the set \isa{A} (which needs to be proven interactively).
wenzelm@35757
    52
wenzelm@35757
    53
  The raw type may not depend on parameters or assumptions of the
wenzelm@35757
    54
  context --- this is logically impossible in Isabelle/HOL --- but the
wenzelm@35757
    55
  non-emptiness property can be local, potentially resulting in
wenzelm@35757
    56
  multiple interpretations in target contexts.  Thus the established
wenzelm@35757
    57
  bijection between the representing set \isa{A} and the new type
wenzelm@35757
    58
  \isa{t} may semantically depend on local assumptions.
wenzelm@26849
    59
  
wenzelm@35757
    60
  By default, \hyperlink{command.HOL.typedef}{\mbox{\isa{\isacommand{typedef}}}} defines both a type \isa{t}
wenzelm@35757
    61
  and a set (term constant) of the same name, unless an alternative
wenzelm@40685
    62
  base name is given in parentheses, or the ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{28}{\isacharparenleft}}open{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequote}}}''
wenzelm@35757
    63
  declaration is used to suppress a separate constant definition
wenzelm@40685
    64
  altogether.  The injection from type to set is called \isa{Rep{\isaliteral{5F}{\isacharunderscore}}t},
wenzelm@40685
    65
  its inverse \isa{Abs{\isaliteral{5F}{\isacharunderscore}}t} --- this may be changed via an explicit
wenzelm@35757
    66
  \hyperlink{keyword.HOL.morphisms}{\mbox{\isa{\isakeyword{morphisms}}}} declaration.
wenzelm@26849
    67
  
wenzelm@40685
    68
  Theorems \isa{Rep{\isaliteral{5F}{\isacharunderscore}}t}, \isa{Rep{\isaliteral{5F}{\isacharunderscore}}t{\isaliteral{5F}{\isacharunderscore}}inverse}, and \isa{Abs{\isaliteral{5F}{\isacharunderscore}}t{\isaliteral{5F}{\isacharunderscore}}inverse} provide the most basic characterization as a
wenzelm@26849
    69
  corresponding injection/surjection pair (in both directions).  Rules
wenzelm@40685
    70
  \isa{Rep{\isaliteral{5F}{\isacharunderscore}}t{\isaliteral{5F}{\isacharunderscore}}inject} and \isa{Abs{\isaliteral{5F}{\isacharunderscore}}t{\isaliteral{5F}{\isacharunderscore}}inject} provide a slightly
wenzelm@26849
    71
  more convenient view on the injectivity part, suitable for automated
wenzelm@26902
    72
  proof tools (e.g.\ in \hyperlink{attribute.simp}{\mbox{\isa{simp}}} or \hyperlink{attribute.iff}{\mbox{\isa{iff}}}
wenzelm@40685
    73
  declarations).  Rules \isa{Rep{\isaliteral{5F}{\isacharunderscore}}t{\isaliteral{5F}{\isacharunderscore}}cases}/\isa{Rep{\isaliteral{5F}{\isacharunderscore}}t{\isaliteral{5F}{\isacharunderscore}}induct}, and
wenzelm@40685
    74
  \isa{Abs{\isaliteral{5F}{\isacharunderscore}}t{\isaliteral{5F}{\isacharunderscore}}cases}/\isa{Abs{\isaliteral{5F}{\isacharunderscore}}t{\isaliteral{5F}{\isacharunderscore}}induct} provide alternative views
wenzelm@26895
    75
  on surjectivity; these are already declared as set or type rules for
wenzelm@26902
    76
  the generic \hyperlink{method.cases}{\mbox{\isa{cases}}} and \hyperlink{method.induct}{\mbox{\isa{induct}}} methods.
wenzelm@26849
    77
  
wenzelm@35757
    78
  An alternative name for the set definition (and other derived
wenzelm@35757
    79
  entities) may be specified in parentheses; the default is to use
wenzelm@35757
    80
  \isa{t} as indicated before.
wenzelm@26849
    81
wenzelm@35757
    82
  \end{description}%
wenzelm@26849
    83
\end{isamarkuptext}%
wenzelm@26849
    84
\isamarkuptrue%
wenzelm@26849
    85
%
wenzelm@26849
    86
\isamarkupsection{Adhoc tuples%
wenzelm@26849
    87
}
wenzelm@26849
    88
\isamarkuptrue%
wenzelm@26849
    89
%
wenzelm@26849
    90
\begin{isamarkuptext}%
wenzelm@26849
    91
\begin{matharray}{rcl}
wenzelm@40685
    92
    \hyperlink{attribute.HOL.split-format}{\mbox{\isa{split{\isaliteral{5F}{\isacharunderscore}}format}}}\isa{{\isaliteral{22}{\isachardoublequote}}\isaliteral{5C3C5E7375703E}{}\isactrlsup {\isaliteral{2A}{\isacharasterisk}}{\isaliteral{22}{\isachardoublequote}}} & : & \isa{attribute} \\
wenzelm@26849
    93
  \end{matharray}
wenzelm@26849
    94
wenzelm@26849
    95
  \begin{rail}
krauss@40634
    96
    'split_format' '(' 'complete' ')'
wenzelm@26849
    97
    ;
wenzelm@26849
    98
  \end{rail}
wenzelm@26849
    99
wenzelm@28788
   100
  \begin{description}
wenzelm@26849
   101
  
wenzelm@40685
   102
  \item \hyperlink{attribute.HOL.split-format}{\mbox{\isa{split{\isaliteral{5F}{\isacharunderscore}}format}}}\ \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{28}{\isacharparenleft}}complete{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequote}}} causes
wenzelm@28788
   103
  arguments in function applications to be represented canonically
wenzelm@28788
   104
  according to their tuple type structure.
wenzelm@26849
   105
krauss@40634
   106
  Note that this operation tends to invent funny names for new local
krauss@40634
   107
  parameters introduced.
wenzelm@26849
   108
wenzelm@28788
   109
  \end{description}%
wenzelm@26849
   110
\end{isamarkuptext}%
wenzelm@26849
   111
\isamarkuptrue%
wenzelm@26849
   112
%
wenzelm@26849
   113
\isamarkupsection{Records \label{sec:hol-record}%
wenzelm@26849
   114
}
wenzelm@26849
   115
\isamarkuptrue%
wenzelm@26849
   116
%
wenzelm@26849
   117
\begin{isamarkuptext}%
wenzelm@26849
   118
In principle, records merely generalize the concept of tuples, where
wenzelm@26849
   119
  components may be addressed by labels instead of just position.  The
wenzelm@26849
   120
  logical infrastructure of records in Isabelle/HOL is slightly more
wenzelm@26849
   121
  advanced, though, supporting truly extensible record schemes.  This
wenzelm@26849
   122
  admits operations that are polymorphic with respect to record
wenzelm@26849
   123
  extension, yielding ``object-oriented'' effects like (single)
wenzelm@26849
   124
  inheritance.  See also \cite{NaraschewskiW-TPHOLs98} for more
wenzelm@26849
   125
  details on object-oriented verification and record subtyping in HOL.%
wenzelm@26849
   126
\end{isamarkuptext}%
wenzelm@26849
   127
\isamarkuptrue%
wenzelm@26849
   128
%
wenzelm@26849
   129
\isamarkupsubsection{Basic concepts%
wenzelm@26849
   130
}
wenzelm@26849
   131
\isamarkuptrue%
wenzelm@26849
   132
%
wenzelm@26849
   133
\begin{isamarkuptext}%
wenzelm@26849
   134
Isabelle/HOL supports both \emph{fixed} and \emph{schematic} records
wenzelm@26849
   135
  at the level of terms and types.  The notation is as follows:
wenzelm@26849
   136
wenzelm@26849
   137
  \begin{center}
wenzelm@26849
   138
  \begin{tabular}{l|l|l}
wenzelm@26849
   139
    & record terms & record types \\ \hline
wenzelm@40685
   140
    fixed & \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6C706172723E}{\isasymlparr}}x\ {\isaliteral{3D}{\isacharequal}}\ a{\isaliteral{2C}{\isacharcomma}}\ y\ {\isaliteral{3D}{\isacharequal}}\ b{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}} & \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6C706172723E}{\isasymlparr}}x\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ A{\isaliteral{2C}{\isacharcomma}}\ y\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ B{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
   141
    schematic & \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6C706172723E}{\isasymlparr}}x\ {\isaliteral{3D}{\isacharequal}}\ a{\isaliteral{2C}{\isacharcomma}}\ y\ {\isaliteral{3D}{\isacharequal}}\ b{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{3D}{\isacharequal}}\ m{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}} &
wenzelm@40685
   142
      \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6C706172723E}{\isasymlparr}}x\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ A{\isaliteral{2C}{\isacharcomma}}\ y\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ B{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ M{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@26849
   143
  \end{tabular}
wenzelm@26849
   144
  \end{center}
wenzelm@26849
   145
wenzelm@40685
   146
  \noindent The ASCII representation of \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6C706172723E}{\isasymlparr}}x\ {\isaliteral{3D}{\isacharequal}}\ a{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}} is \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{28}{\isacharparenleft}}{\isaliteral{7C}{\isacharbar}}\ x\ {\isaliteral{3D}{\isacharequal}}\ a\ {\isaliteral{7C}{\isacharbar}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequote}}}.
wenzelm@26849
   147
wenzelm@40685
   148
  A fixed record \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6C706172723E}{\isasymlparr}}x\ {\isaliteral{3D}{\isacharequal}}\ a{\isaliteral{2C}{\isacharcomma}}\ y\ {\isaliteral{3D}{\isacharequal}}\ b{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}} has field \isa{x} of value
wenzelm@26849
   149
  \isa{a} and field \isa{y} of value \isa{b}.  The corresponding
wenzelm@40685
   150
  type is \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6C706172723E}{\isasymlparr}}x\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ A{\isaliteral{2C}{\isacharcomma}}\ y\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ B{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}}, assuming that \isa{{\isaliteral{22}{\isachardoublequote}}a\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ A{\isaliteral{22}{\isachardoublequote}}}
wenzelm@40685
   151
  and \isa{{\isaliteral{22}{\isachardoublequote}}b\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ B{\isaliteral{22}{\isachardoublequote}}}.
wenzelm@26849
   152
wenzelm@40685
   153
  A record scheme like \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6C706172723E}{\isasymlparr}}x\ {\isaliteral{3D}{\isacharequal}}\ a{\isaliteral{2C}{\isacharcomma}}\ y\ {\isaliteral{3D}{\isacharequal}}\ b{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{3D}{\isacharequal}}\ m{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}} contains fields
wenzelm@26849
   154
  \isa{x} and \isa{y} as before, but also possibly further fields
wenzelm@40685
   155
  as indicated by the ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{22}{\isachardoublequote}}}'' notation (which is actually part
wenzelm@40685
   156
  of the syntax).  The improper field ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{22}{\isachardoublequote}}}'' of a record
wenzelm@26849
   157
  scheme is called the \emph{more part}.  Logically it is just a free
wenzelm@26849
   158
  variable, which is occasionally referred to as ``row variable'' in
wenzelm@26849
   159
  the literature.  The more part of a record scheme may be
wenzelm@26849
   160
  instantiated by zero or more further components.  For example, the
wenzelm@40685
   161
  previous scheme may get instantiated to \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6C706172723E}{\isasymlparr}}x\ {\isaliteral{3D}{\isacharequal}}\ a{\isaliteral{2C}{\isacharcomma}}\ y\ {\isaliteral{3D}{\isacharequal}}\ b{\isaliteral{2C}{\isacharcomma}}\ z\ {\isaliteral{3D}{\isacharequal}}\ c{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{3D}{\isacharequal}}\ m{\isaliteral{27}{\isacharprime}}{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}}, where \isa{m{\isaliteral{27}{\isacharprime}}} refers to a different more part.
wenzelm@26849
   162
  Fixed records are special instances of record schemes, where
wenzelm@40685
   163
  ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{22}{\isachardoublequote}}}'' is properly terminated by the \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{28}{\isacharparenleft}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ unit{\isaliteral{22}{\isachardoublequote}}}
wenzelm@40685
   164
  element.  In fact, \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6C706172723E}{\isasymlparr}}x\ {\isaliteral{3D}{\isacharequal}}\ a{\isaliteral{2C}{\isacharcomma}}\ y\ {\isaliteral{3D}{\isacharequal}}\ b{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}} is just an abbreviation
wenzelm@40685
   165
  for \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6C706172723E}{\isasymlparr}}x\ {\isaliteral{3D}{\isacharequal}}\ a{\isaliteral{2C}{\isacharcomma}}\ y\ {\isaliteral{3D}{\isacharequal}}\ b{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}}.
wenzelm@26849
   166
  
wenzelm@26849
   167
  \medskip Two key observations make extensible records in a simply
wenzelm@26849
   168
  typed language like HOL work out:
wenzelm@26849
   169
wenzelm@26849
   170
  \begin{enumerate}
wenzelm@26849
   171
wenzelm@26849
   172
  \item the more part is internalized, as a free term or type
wenzelm@26849
   173
  variable,
wenzelm@26849
   174
wenzelm@26852
   175
  \item field names are externalized, they cannot be accessed within
wenzelm@26852
   176
  the logic as first-class values.
wenzelm@26849
   177
wenzelm@26849
   178
  \end{enumerate}
wenzelm@26849
   179
wenzelm@26849
   180
  \medskip In Isabelle/HOL record types have to be defined explicitly,
wenzelm@26849
   181
  fixing their field names and types, and their (optional) parent
wenzelm@26849
   182
  record.  Afterwards, records may be formed using above syntax, while
wenzelm@26849
   183
  obeying the canonical order of fields as given by their declaration.
wenzelm@26849
   184
  The record package provides several standard operations like
wenzelm@26849
   185
  selectors and updates.  The common setup for various generic proof
wenzelm@26849
   186
  tools enable succinct reasoning patterns.  See also the Isabelle/HOL
wenzelm@26849
   187
  tutorial \cite{isabelle-hol-book} for further instructions on using
wenzelm@26849
   188
  records in practice.%
wenzelm@26849
   189
\end{isamarkuptext}%
wenzelm@26849
   190
\isamarkuptrue%
wenzelm@26849
   191
%
wenzelm@26849
   192
\isamarkupsubsection{Record specifications%
wenzelm@26849
   193
}
wenzelm@26849
   194
\isamarkuptrue%
wenzelm@26849
   195
%
wenzelm@26849
   196
\begin{isamarkuptext}%
wenzelm@26849
   197
\begin{matharray}{rcl}
wenzelm@40685
   198
    \indexdef{HOL}{command}{record}\hypertarget{command.HOL.record}{\hyperlink{command.HOL.record}{\mbox{\isa{\isacommand{record}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@26849
   199
  \end{matharray}
wenzelm@26849
   200
wenzelm@26849
   201
  \begin{rail}
wenzelm@36158
   202
    'record' typespecsorts '=' (type '+')? (constdecl +)
wenzelm@26849
   203
    ;
wenzelm@26849
   204
  \end{rail}
wenzelm@26849
   205
wenzelm@28788
   206
  \begin{description}
wenzelm@26849
   207
wenzelm@40685
   208
  \item \hyperlink{command.HOL.record}{\mbox{\isa{\isacommand{record}}}}~\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C616C7068613E}{\isasymalpha}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C616C7068613E}{\isasymalpha}}\isaliteral{5C3C5E7375623E}{}\isactrlsub m{\isaliteral{29}{\isacharparenright}}\ t\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{5C3C7461753E}{\isasymtau}}\ {\isaliteral{2B}{\isacharplus}}\ c\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ c\isaliteral{5C3C5E7375623E}{}\isactrlsub n\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E7375623E}{}\isactrlsub n{\isaliteral{22}{\isachardoublequote}}} defines extensible record type \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C616C7068613E}{\isasymalpha}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C616C7068613E}{\isasymalpha}}\isaliteral{5C3C5E7375623E}{}\isactrlsub m{\isaliteral{29}{\isacharparenright}}\ t{\isaliteral{22}{\isachardoublequote}}},
wenzelm@40685
   209
  derived from the optional parent record \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C7461753E}{\isasymtau}}{\isaliteral{22}{\isachardoublequote}}} by adding new
wenzelm@40685
   210
  field components \isa{{\isaliteral{22}{\isachardoublequote}}c\isaliteral{5C3C5E7375623E}{}\isactrlsub i\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E7375623E}{}\isactrlsub i{\isaliteral{22}{\isachardoublequote}}} etc.
wenzelm@26849
   211
wenzelm@40685
   212
  The type variables of \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C7461753E}{\isasymtau}}{\isaliteral{22}{\isachardoublequote}}} and \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E7375623E}{}\isactrlsub i{\isaliteral{22}{\isachardoublequote}}} need to be
wenzelm@40685
   213
  covered by the (distinct) parameters \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C616C7068613E}{\isasymalpha}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C616C7068613E}{\isasymalpha}}\isaliteral{5C3C5E7375623E}{}\isactrlsub m{\isaliteral{22}{\isachardoublequote}}}.  Type constructor \isa{t} has to be new, while \isa{{\isaliteral{5C3C7461753E}{\isasymtau}}} needs to specify an instance of an existing record type.  At
wenzelm@40685
   214
  least one new field \isa{{\isaliteral{22}{\isachardoublequote}}c\isaliteral{5C3C5E7375623E}{}\isactrlsub i{\isaliteral{22}{\isachardoublequote}}} has to be specified.
wenzelm@26849
   215
  Basically, field names need to belong to a unique record.  This is
wenzelm@26849
   216
  not a real restriction in practice, since fields are qualified by
wenzelm@26849
   217
  the record name internally.
wenzelm@26849
   218
wenzelm@40685
   219
  The parent record specification \isa{{\isaliteral{5C3C7461753E}{\isasymtau}}} is optional; if omitted
wenzelm@26849
   220
  \isa{t} becomes a root record.  The hierarchy of all records
wenzelm@26849
   221
  declared within a theory context forms a forest structure, i.e.\ a
wenzelm@26849
   222
  set of trees starting with a root record each.  There is no way to
wenzelm@26849
   223
  merge multiple parent records!
wenzelm@26849
   224
wenzelm@40685
   225
  For convenience, \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C616C7068613E}{\isasymalpha}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C616C7068613E}{\isasymalpha}}\isaliteral{5C3C5E7375623E}{}\isactrlsub m{\isaliteral{29}{\isacharparenright}}\ t{\isaliteral{22}{\isachardoublequote}}} is made a
wenzelm@40685
   226
  type abbreviation for the fixed record type \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6C706172723E}{\isasymlparr}}c\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{2C}{\isacharcomma}}\ c\isaliteral{5C3C5E7375623E}{}\isactrlsub n\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E7375623E}{}\isactrlsub n{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}}, likewise is \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C616C7068613E}{\isasymalpha}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C616C7068613E}{\isasymalpha}}\isaliteral{5C3C5E7375623E}{}\isactrlsub m{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C7A6574613E}{\isasymzeta}}{\isaliteral{29}{\isacharparenright}}\ t{\isaliteral{5F}{\isacharunderscore}}scheme{\isaliteral{22}{\isachardoublequote}}} made an abbreviation for
wenzelm@40685
   227
  \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6C706172723E}{\isasymlparr}}c\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{2C}{\isacharcomma}}\ c\isaliteral{5C3C5E7375623E}{}\isactrlsub n\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E7375623E}{}\isactrlsub n{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C7A6574613E}{\isasymzeta}}{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}}.
wenzelm@26849
   228
wenzelm@28788
   229
  \end{description}%
wenzelm@26849
   230
\end{isamarkuptext}%
wenzelm@26849
   231
\isamarkuptrue%
wenzelm@26849
   232
%
wenzelm@26849
   233
\isamarkupsubsection{Record operations%
wenzelm@26849
   234
}
wenzelm@26849
   235
\isamarkuptrue%
wenzelm@26849
   236
%
wenzelm@26849
   237
\begin{isamarkuptext}%
wenzelm@26849
   238
Any record definition of the form presented above produces certain
wenzelm@26849
   239
  standard operations.  Selectors and updates are provided for any
wenzelm@26849
   240
  field, including the improper one ``\isa{more}''.  There are also
wenzelm@26849
   241
  cumulative record constructor functions.  To simplify the
wenzelm@40685
   242
  presentation below, we assume for now that \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C616C7068613E}{\isasymalpha}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C616C7068613E}{\isasymalpha}}\isaliteral{5C3C5E7375623E}{}\isactrlsub m{\isaliteral{29}{\isacharparenright}}\ t{\isaliteral{22}{\isachardoublequote}}} is a root record with fields \isa{{\isaliteral{22}{\isachardoublequote}}c\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{2C}{\isacharcomma}}\ c\isaliteral{5C3C5E7375623E}{}\isactrlsub n\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E7375623E}{}\isactrlsub n{\isaliteral{22}{\isachardoublequote}}}.
wenzelm@26849
   243
wenzelm@26849
   244
  \medskip \textbf{Selectors} and \textbf{updates} are available for
wenzelm@26849
   245
  any field (including ``\isa{more}''):
wenzelm@26849
   246
wenzelm@26849
   247
  \begin{matharray}{lll}
wenzelm@40685
   248
    \isa{{\isaliteral{22}{\isachardoublequote}}c\isaliteral{5C3C5E7375623E}{}\isactrlsub i{\isaliteral{22}{\isachardoublequote}}} & \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}{\isaliteral{22}{\isachardoublequote}}} & \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6C706172723E}{\isasymlparr}}\isaliteral{5C3C5E7665633E}{}\isactrlvec c\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C7369676D613E}{\isasymsigma}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C7A6574613E}{\isasymzeta}}{\isaliteral{5C3C72706172723E}{\isasymrparr}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E7375623E}{}\isactrlsub i{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
   249
    \isa{{\isaliteral{22}{\isachardoublequote}}c\isaliteral{5C3C5E7375623E}{}\isactrlsub i{\isaliteral{5F}{\isacharunderscore}}update{\isaliteral{22}{\isachardoublequote}}} & \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}{\isaliteral{22}{\isachardoublequote}}} & \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E7375623E}{}\isactrlsub i\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{5C3C6C706172723E}{\isasymlparr}}\isaliteral{5C3C5E7665633E}{}\isactrlvec c\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C7369676D613E}{\isasymsigma}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C7A6574613E}{\isasymzeta}}{\isaliteral{5C3C72706172723E}{\isasymrparr}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{5C3C6C706172723E}{\isasymlparr}}\isaliteral{5C3C5E7665633E}{}\isactrlvec c\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C7369676D613E}{\isasymsigma}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C7A6574613E}{\isasymzeta}}{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@26849
   250
  \end{matharray}
wenzelm@26849
   251
wenzelm@40685
   252
  There is special syntax for application of updates: \isa{{\isaliteral{22}{\isachardoublequote}}r{\isaliteral{5C3C6C706172723E}{\isasymlparr}}x\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3D}{\isacharequal}}\ a{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}} abbreviates term \isa{{\isaliteral{22}{\isachardoublequote}}x{\isaliteral{5F}{\isacharunderscore}}update\ a\ r{\isaliteral{22}{\isachardoublequote}}}.  Further notation for
wenzelm@40685
   253
  repeated updates is also available: \isa{{\isaliteral{22}{\isachardoublequote}}r{\isaliteral{5C3C6C706172723E}{\isasymlparr}}x\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3D}{\isacharequal}}\ a{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{5C3C6C706172723E}{\isasymlparr}}y\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3D}{\isacharequal}}\ b{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{5C3C6C706172723E}{\isasymlparr}}z\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3D}{\isacharequal}}\ c{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}} may be written \isa{{\isaliteral{22}{\isachardoublequote}}r{\isaliteral{5C3C6C706172723E}{\isasymlparr}}x\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3D}{\isacharequal}}\ a{\isaliteral{2C}{\isacharcomma}}\ y\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3D}{\isacharequal}}\ b{\isaliteral{2C}{\isacharcomma}}\ z\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3D}{\isacharequal}}\ c{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}}.  Note that
wenzelm@26849
   254
  because of postfix notation the order of fields shown here is
wenzelm@26849
   255
  reverse than in the actual term.  Since repeated updates are just
wenzelm@40685
   256
  function applications, fields may be freely permuted in \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6C706172723E}{\isasymlparr}}x\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3D}{\isacharequal}}\ a{\isaliteral{2C}{\isacharcomma}}\ y\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3D}{\isacharequal}}\ b{\isaliteral{2C}{\isacharcomma}}\ z\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3D}{\isacharequal}}\ c{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}}, as far as logical equality is concerned.
wenzelm@26849
   257
  Thus commutativity of independent updates can be proven within the
wenzelm@26849
   258
  logic for any two fields, but not as a general theorem.
wenzelm@26849
   259
wenzelm@26849
   260
  \medskip The \textbf{make} operation provides a cumulative record
wenzelm@26849
   261
  constructor function:
wenzelm@26849
   262
wenzelm@26849
   263
  \begin{matharray}{lll}
wenzelm@40685
   264
    \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}make{\isaliteral{22}{\isachardoublequote}}} & \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}{\isaliteral{22}{\isachardoublequote}}} & \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E7375623E}{}\isactrlsub n\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{5C3C6C706172723E}{\isasymlparr}}\isaliteral{5C3C5E7665633E}{}\isactrlvec c\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C7369676D613E}{\isasymsigma}}{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@26849
   265
  \end{matharray}
wenzelm@26849
   266
wenzelm@26849
   267
  \medskip We now reconsider the case of non-root records, which are
wenzelm@26849
   268
  derived of some parent.  In general, the latter may depend on
wenzelm@26849
   269
  another parent as well, resulting in a list of \emph{ancestor
wenzelm@26849
   270
  records}.  Appending the lists of fields of all ancestors results in
wenzelm@26849
   271
  a certain field prefix.  The record package automatically takes care
wenzelm@26849
   272
  of this by lifting operations over this context of ancestor fields.
wenzelm@40685
   273
  Assuming that \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C616C7068613E}{\isasymalpha}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C616C7068613E}{\isasymalpha}}\isaliteral{5C3C5E7375623E}{}\isactrlsub m{\isaliteral{29}{\isacharparenright}}\ t{\isaliteral{22}{\isachardoublequote}}} has ancestor
wenzelm@40685
   274
  fields \isa{{\isaliteral{22}{\isachardoublequote}}b\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C72686F3E}{\isasymrho}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{2C}{\isacharcomma}}\ b\isaliteral{5C3C5E7375623E}{}\isactrlsub k\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C72686F3E}{\isasymrho}}\isaliteral{5C3C5E7375623E}{}\isactrlsub k{\isaliteral{22}{\isachardoublequote}}},
wenzelm@26849
   275
  the above record operations will get the following types:
wenzelm@26849
   276
wenzelm@26852
   277
  \medskip
wenzelm@26852
   278
  \begin{tabular}{lll}
wenzelm@40685
   279
    \isa{{\isaliteral{22}{\isachardoublequote}}c\isaliteral{5C3C5E7375623E}{}\isactrlsub i{\isaliteral{22}{\isachardoublequote}}} & \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}{\isaliteral{22}{\isachardoublequote}}} & \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6C706172723E}{\isasymlparr}}\isaliteral{5C3C5E7665633E}{}\isactrlvec b\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C72686F3E}{\isasymrho}}{\isaliteral{2C}{\isacharcomma}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec c\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C7369676D613E}{\isasymsigma}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C7A6574613E}{\isasymzeta}}{\isaliteral{5C3C72706172723E}{\isasymrparr}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E7375623E}{}\isactrlsub i{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
   280
    \isa{{\isaliteral{22}{\isachardoublequote}}c\isaliteral{5C3C5E7375623E}{}\isactrlsub i{\isaliteral{5F}{\isacharunderscore}}update{\isaliteral{22}{\isachardoublequote}}} & \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}{\isaliteral{22}{\isachardoublequote}}} & \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E7375623E}{}\isactrlsub i\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{5C3C6C706172723E}{\isasymlparr}}\isaliteral{5C3C5E7665633E}{}\isactrlvec b\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C72686F3E}{\isasymrho}}{\isaliteral{2C}{\isacharcomma}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec c\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C7369676D613E}{\isasymsigma}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C7A6574613E}{\isasymzeta}}{\isaliteral{5C3C72706172723E}{\isasymrparr}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{5C3C6C706172723E}{\isasymlparr}}\isaliteral{5C3C5E7665633E}{}\isactrlvec b\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C72686F3E}{\isasymrho}}{\isaliteral{2C}{\isacharcomma}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec c\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C7369676D613E}{\isasymsigma}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C7A6574613E}{\isasymzeta}}{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
   281
    \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}make{\isaliteral{22}{\isachardoublequote}}} & \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}{\isaliteral{22}{\isachardoublequote}}} & \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C72686F3E}{\isasymrho}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{5C3C72686F3E}{\isasymrho}}\isaliteral{5C3C5E7375623E}{}\isactrlsub k\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E7375623E}{}\isactrlsub n\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{5C3C6C706172723E}{\isasymlparr}}\isaliteral{5C3C5E7665633E}{}\isactrlvec b\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C72686F3E}{\isasymrho}}{\isaliteral{2C}{\isacharcomma}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec c\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C7369676D613E}{\isasymsigma}}{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@26852
   282
  \end{tabular}
wenzelm@26852
   283
  \medskip
wenzelm@26849
   284
wenzelm@26852
   285
  \noindent Some further operations address the extension aspect of a
wenzelm@40685
   286
  derived record scheme specifically: \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}fields{\isaliteral{22}{\isachardoublequote}}} produces a
wenzelm@26849
   287
  record fragment consisting of exactly the new fields introduced here
wenzelm@40685
   288
  (the result may serve as a more part elsewhere); \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}extend{\isaliteral{22}{\isachardoublequote}}}
wenzelm@40685
   289
  takes a fixed record and adds a given more part; \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}truncate{\isaliteral{22}{\isachardoublequote}}} restricts a record scheme to a fixed record.
wenzelm@26849
   290
wenzelm@26852
   291
  \medskip
wenzelm@26852
   292
  \begin{tabular}{lll}
wenzelm@40685
   293
    \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}fields{\isaliteral{22}{\isachardoublequote}}} & \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}{\isaliteral{22}{\isachardoublequote}}} & \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E7375623E}{}\isactrlsub n\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{5C3C6C706172723E}{\isasymlparr}}\isaliteral{5C3C5E7665633E}{}\isactrlvec c\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C7369676D613E}{\isasymsigma}}{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
   294
    \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}extend{\isaliteral{22}{\isachardoublequote}}} & \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}{\isaliteral{22}{\isachardoublequote}}} & \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6C706172723E}{\isasymlparr}}\isaliteral{5C3C5E7665633E}{}\isactrlvec b\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C72686F3E}{\isasymrho}}{\isaliteral{2C}{\isacharcomma}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec c\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C7369676D613E}{\isasymsigma}}{\isaliteral{5C3C72706172723E}{\isasymrparr}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{5C3C7A6574613E}{\isasymzeta}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{5C3C6C706172723E}{\isasymlparr}}\isaliteral{5C3C5E7665633E}{}\isactrlvec b\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C72686F3E}{\isasymrho}}{\isaliteral{2C}{\isacharcomma}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec c\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C7369676D613E}{\isasymsigma}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C7A6574613E}{\isasymzeta}}{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
   295
    \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}truncate{\isaliteral{22}{\isachardoublequote}}} & \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}{\isaliteral{22}{\isachardoublequote}}} & \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6C706172723E}{\isasymlparr}}\isaliteral{5C3C5E7665633E}{}\isactrlvec b\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C72686F3E}{\isasymrho}}{\isaliteral{2C}{\isacharcomma}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec c\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C7369676D613E}{\isasymsigma}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C7A6574613E}{\isasymzeta}}{\isaliteral{5C3C72706172723E}{\isasymrparr}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{5C3C6C706172723E}{\isasymlparr}}\isaliteral{5C3C5E7665633E}{}\isactrlvec b\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C72686F3E}{\isasymrho}}{\isaliteral{2C}{\isacharcomma}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec c\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ \isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C7369676D613E}{\isasymsigma}}{\isaliteral{5C3C72706172723E}{\isasymrparr}}{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@26852
   296
  \end{tabular}
wenzelm@26852
   297
  \medskip
wenzelm@26849
   298
wenzelm@40685
   299
  \noindent Note that \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}make{\isaliteral{22}{\isachardoublequote}}} and \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}fields{\isaliteral{22}{\isachardoublequote}}} coincide
wenzelm@26849
   300
  for root records.%
wenzelm@26849
   301
\end{isamarkuptext}%
wenzelm@26849
   302
\isamarkuptrue%
wenzelm@26849
   303
%
wenzelm@26849
   304
\isamarkupsubsection{Derived rules and proof tools%
wenzelm@26849
   305
}
wenzelm@26849
   306
\isamarkuptrue%
wenzelm@26849
   307
%
wenzelm@26849
   308
\begin{isamarkuptext}%
wenzelm@26849
   309
The record package proves several results internally, declaring
wenzelm@26849
   310
  these facts to appropriate proof tools.  This enables users to
wenzelm@26849
   311
  reason about record structures quite conveniently.  Assume that
wenzelm@26849
   312
  \isa{t} is a record type as specified above.
wenzelm@26849
   313
wenzelm@26849
   314
  \begin{enumerate}
wenzelm@26849
   315
  
wenzelm@26849
   316
  \item Standard conversions for selectors or updates applied to
wenzelm@26849
   317
  record constructor terms are made part of the default Simplifier
wenzelm@26849
   318
  context; thus proofs by reduction of basic operations merely require
wenzelm@26902
   319
  the \hyperlink{method.simp}{\mbox{\isa{simp}}} method without further arguments.  These rules
wenzelm@40685
   320
  are available as \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}simps{\isaliteral{22}{\isachardoublequote}}}, too.
wenzelm@26849
   321
  
wenzelm@26849
   322
  \item Selectors applied to updated records are automatically reduced
wenzelm@26849
   323
  by an internal simplification procedure, which is also part of the
wenzelm@26849
   324
  standard Simplifier setup.
wenzelm@26849
   325
wenzelm@40685
   326
  \item Inject equations of a form analogous to \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}\ y{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}x{\isaliteral{27}{\isacharprime}}{\isaliteral{2C}{\isacharcomma}}\ y{\isaliteral{27}{\isacharprime}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C65717569763E}{\isasymequiv}}\ x\ {\isaliteral{3D}{\isacharequal}}\ x{\isaliteral{27}{\isacharprime}}\ {\isaliteral{5C3C616E643E}{\isasymand}}\ y\ {\isaliteral{3D}{\isacharequal}}\ y{\isaliteral{27}{\isacharprime}}{\isaliteral{22}{\isachardoublequote}}} are declared to the Simplifier and Classical
wenzelm@26902
   327
  Reasoner as \hyperlink{attribute.iff}{\mbox{\isa{iff}}} rules.  These rules are available as
wenzelm@40685
   328
  \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}iffs{\isaliteral{22}{\isachardoublequote}}}.
wenzelm@26849
   329
wenzelm@40685
   330
  \item The introduction rule for record equality analogous to \isa{{\isaliteral{22}{\isachardoublequote}}x\ r\ {\isaliteral{3D}{\isacharequal}}\ x\ r{\isaliteral{27}{\isacharprime}}\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ y\ r\ {\isaliteral{3D}{\isacharequal}}\ y\ r{\isaliteral{27}{\isacharprime}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ r\ {\isaliteral{3D}{\isacharequal}}\ r{\isaliteral{27}{\isacharprime}}{\isaliteral{22}{\isachardoublequote}}} is declared to the Simplifier,
wenzelm@40685
   331
  and as the basic rule context as ``\hyperlink{attribute.intro}{\mbox{\isa{intro}}}\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{3F}{\isacharquery}}{\isaliteral{22}{\isachardoublequote}}}''.
wenzelm@40685
   332
  The rule is called \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}equality{\isaliteral{22}{\isachardoublequote}}}.
wenzelm@26849
   333
wenzelm@26849
   334
  \item Representations of arbitrary record expressions as canonical
wenzelm@26902
   335
  constructor terms are provided both in \hyperlink{method.cases}{\mbox{\isa{cases}}} and \hyperlink{method.induct}{\mbox{\isa{induct}}} format (cf.\ the generic proof methods of the same name,
wenzelm@26849
   336
  \secref{sec:cases-induct}).  Several variations are available, for
wenzelm@26849
   337
  fixed records, record schemes, more parts etc.
wenzelm@26849
   338
  
wenzelm@26849
   339
  The generic proof methods are sufficiently smart to pick the most
wenzelm@26849
   340
  sensible rule according to the type of the indicated record
wenzelm@40685
   341
  expression: users just need to apply something like ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{28}{\isacharparenleft}}cases\ r{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequote}}}'' to a certain proof problem.
wenzelm@26849
   342
wenzelm@40685
   343
  \item The derived record operations \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}make{\isaliteral{22}{\isachardoublequote}}}, \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}fields{\isaliteral{22}{\isachardoublequote}}}, \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}extend{\isaliteral{22}{\isachardoublequote}}}, \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}truncate{\isaliteral{22}{\isachardoublequote}}} are \emph{not}
wenzelm@26849
   344
  treated automatically, but usually need to be expanded by hand,
wenzelm@40685
   345
  using the collective fact \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}defs{\isaliteral{22}{\isachardoublequote}}}.
wenzelm@26849
   346
wenzelm@26849
   347
  \end{enumerate}%
wenzelm@26849
   348
\end{isamarkuptext}%
wenzelm@26849
   349
\isamarkuptrue%
wenzelm@26849
   350
%
wenzelm@26849
   351
\isamarkupsection{Datatypes \label{sec:hol-datatype}%
wenzelm@26849
   352
}
wenzelm@26849
   353
\isamarkuptrue%
wenzelm@26849
   354
%
wenzelm@26849
   355
\begin{isamarkuptext}%
wenzelm@26849
   356
\begin{matharray}{rcl}
wenzelm@40685
   357
    \indexdef{HOL}{command}{datatype}\hypertarget{command.HOL.datatype}{\hyperlink{command.HOL.datatype}{\mbox{\isa{\isacommand{datatype}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\
haftmann@41644
   358
    \indexdef{HOL}{command}{rep\_datatype}\hypertarget{command.HOL.rep-datatype}{\hyperlink{command.HOL.rep-datatype}{\mbox{\isa{\isacommand{rep{\isaliteral{5F}{\isacharunderscore}}datatype}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ proof{\isaliteral{28}{\isacharparenleft}}prove{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@26849
   359
  \end{matharray}
wenzelm@26849
   360
wenzelm@26849
   361
  \begin{rail}
wenzelm@26849
   362
    'datatype' (dtspec + 'and')
wenzelm@26849
   363
    ;
wenzelm@40516
   364
    'rep_datatype' ('(' (name +) ')')? (term +)
wenzelm@26849
   365
    ;
wenzelm@26849
   366
wenzelm@35352
   367
    dtspec: parname? typespec mixfix? '=' (cons + '|')
wenzelm@26849
   368
    ;
haftmann@31907
   369
    cons: name ( type * ) mixfix?
wenzelm@26849
   370
  \end{rail}
wenzelm@26849
   371
wenzelm@28788
   372
  \begin{description}
wenzelm@26849
   373
wenzelm@28788
   374
  \item \hyperlink{command.HOL.datatype}{\mbox{\isa{\isacommand{datatype}}}} defines inductive datatypes in
wenzelm@26849
   375
  HOL.
wenzelm@26849
   376
wenzelm@40685
   377
  \item \hyperlink{command.HOL.rep-datatype}{\mbox{\isa{\isacommand{rep{\isaliteral{5F}{\isacharunderscore}}datatype}}}} represents existing types as
wenzelm@26849
   378
  inductive ones, generating the standard infrastructure of derived
wenzelm@26849
   379
  concepts (primitive recursion etc.).
wenzelm@26849
   380
wenzelm@28788
   381
  \end{description}
wenzelm@26849
   382
wenzelm@26849
   383
  The induction and exhaustion theorems generated provide case names
wenzelm@26849
   384
  according to the constructors involved, while parameters are named
wenzelm@26849
   385
  after the types (see also \secref{sec:cases-induct}).
wenzelm@26849
   386
wenzelm@26849
   387
  See \cite{isabelle-HOL} for more details on datatypes, but beware of
wenzelm@26849
   388
  the old-style theory syntax being used there!  Apart from proper
wenzelm@26849
   389
  proof methods for case-analysis and induction, there are also
wenzelm@40685
   390
  emulations of ML tactics \hyperlink{method.HOL.case-tac}{\mbox{\isa{case{\isaliteral{5F}{\isacharunderscore}}tac}}} and \hyperlink{method.HOL.induct-tac}{\mbox{\isa{induct{\isaliteral{5F}{\isacharunderscore}}tac}}} available, see \secref{sec:hol-induct-tac}; these admit
wenzelm@26849
   391
  to refer directly to the internal structure of subgoals (including
wenzelm@26849
   392
  internally bound parameters).%
wenzelm@26849
   393
\end{isamarkuptext}%
wenzelm@26849
   394
\isamarkuptrue%
wenzelm@26849
   395
%
haftmann@41644
   396
\isamarkupsection{Functorial structure of types%
haftmann@41644
   397
}
haftmann@41644
   398
\isamarkuptrue%
haftmann@41644
   399
%
haftmann@41644
   400
\begin{isamarkuptext}%
haftmann@41644
   401
\begin{matharray}{rcl}
haftmann@41753
   402
    \indexdef{HOL}{command}{enriched\_type}\hypertarget{command.HOL.enriched-type}{\hyperlink{command.HOL.enriched-type}{\mbox{\isa{\isacommand{enriched{\isaliteral{5F}{\isacharunderscore}}type}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}local{\isaliteral{5F}{\isacharunderscore}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ proof{\isaliteral{28}{\isacharparenleft}}prove{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequote}}}
haftmann@41644
   403
  \end{matharray}
haftmann@41644
   404
haftmann@41644
   405
  \begin{rail}
haftmann@41752
   406
    'enriched_type' (prefix ':')? term
haftmann@41644
   407
    ;
haftmann@41644
   408
  \end{rail}
haftmann@41644
   409
haftmann@41644
   410
  \begin{description}
haftmann@41644
   411
haftmann@41753
   412
  \item \hyperlink{command.HOL.enriched-type}{\mbox{\isa{\isacommand{enriched{\isaliteral{5F}{\isacharunderscore}}type}}}} allows to prove and register
haftmann@41753
   413
  properties about the functorial structure of type constructors;
haftmann@41753
   414
  these properties then can be used by other packages to
haftmann@41644
   415
  deal with those type constructors in certain type constructions.
haftmann@41644
   416
  Characteristic theorems are noted in the current local theory; by
haftmann@41753
   417
  default, they are prefixed with the base name of the type constructor,
haftmann@41644
   418
  an explicit prefix can be given alternatively.
haftmann@41644
   419
haftmann@41644
   420
  The given term \isa{{\isaliteral{22}{\isachardoublequote}}m{\isaliteral{22}{\isachardoublequote}}} is considered as \emph{mapper} for the
haftmann@41644
   421
  corresponding type constructor and must conform to the following
haftmann@41644
   422
  type pattern:
haftmann@41644
   423
haftmann@41644
   424
  \begin{matharray}{lll}
haftmann@41644
   425
    \isa{{\isaliteral{22}{\isachardoublequote}}m{\isaliteral{22}{\isachardoublequote}}} & \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}{\isaliteral{22}{\isachardoublequote}}} &
haftmann@41644
   426
      \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E697375623E}{}\isactrlisub {\isadigit{1}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E697375623E}{}\isactrlisub k\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{28}{\isacharparenleft}}\isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C616C7068613E}{\isasymalpha}}\isaliteral{5C3C5E697375623E}{}\isactrlisub n{\isaliteral{29}{\isacharparenright}}\ t\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{28}{\isacharparenleft}}\isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C626574613E}{\isasymbeta}}\isaliteral{5C3C5E697375623E}{}\isactrlisub n{\isaliteral{29}{\isacharparenright}}\ t{\isaliteral{22}{\isachardoublequote}}} \\
haftmann@41644
   427
  \end{matharray}
haftmann@41644
   428
haftmann@41644
   429
  \noindent where \isa{t} is the type constructor, \isa{{\isaliteral{22}{\isachardoublequote}}\isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C616C7068613E}{\isasymalpha}}\isaliteral{5C3C5E697375623E}{}\isactrlisub n{\isaliteral{22}{\isachardoublequote}}} and \isa{{\isaliteral{22}{\isachardoublequote}}\isaliteral{5C3C5E7665633E}{}\isactrlvec {\isaliteral{5C3C626574613E}{\isasymbeta}}\isaliteral{5C3C5E697375623E}{}\isactrlisub n{\isaliteral{22}{\isachardoublequote}}} are distinct
haftmann@41644
   430
  type variables free in the local theory and \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E697375623E}{}\isactrlisub {\isadigit{1}}{\isaliteral{22}{\isachardoublequote}}},
haftmann@41644
   431
  \ldots, \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E697375623E}{}\isactrlisub k{\isaliteral{22}{\isachardoublequote}}} is a subsequence of \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C616C7068613E}{\isasymalpha}}\isaliteral{5C3C5E697375623E}{}\isactrlisub {\isadigit{1}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{5C3C626574613E}{\isasymbeta}}\isaliteral{5C3C5E697375623E}{}\isactrlisub {\isadigit{1}}{\isaliteral{22}{\isachardoublequote}}}, \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C626574613E}{\isasymbeta}}\isaliteral{5C3C5E697375623E}{}\isactrlisub {\isadigit{1}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{5C3C616C7068613E}{\isasymalpha}}\isaliteral{5C3C5E697375623E}{}\isactrlisub {\isadigit{1}}{\isaliteral{22}{\isachardoublequote}}}, \ldots,
haftmann@41644
   432
  \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C616C7068613E}{\isasymalpha}}\isaliteral{5C3C5E697375623E}{}\isactrlisub n\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{5C3C626574613E}{\isasymbeta}}\isaliteral{5C3C5E697375623E}{}\isactrlisub n{\isaliteral{22}{\isachardoublequote}}}, \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C626574613E}{\isasymbeta}}\isaliteral{5C3C5E697375623E}{}\isactrlisub n\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{5C3C616C7068613E}{\isasymalpha}}\isaliteral{5C3C5E697375623E}{}\isactrlisub n{\isaliteral{22}{\isachardoublequote}}}.
haftmann@41644
   433
haftmann@41644
   434
  \end{description}%
haftmann@41644
   435
\end{isamarkuptext}%
haftmann@41644
   436
\isamarkuptrue%
haftmann@41644
   437
%
wenzelm@26849
   438
\isamarkupsection{Recursive functions \label{sec:recursion}%
wenzelm@26849
   439
}
wenzelm@26849
   440
\isamarkuptrue%
wenzelm@26849
   441
%
wenzelm@26849
   442
\begin{isamarkuptext}%
wenzelm@26849
   443
\begin{matharray}{rcl}
wenzelm@40685
   444
    \indexdef{HOL}{command}{primrec}\hypertarget{command.HOL.primrec}{\hyperlink{command.HOL.primrec}{\mbox{\isa{\isacommand{primrec}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}local{\isaliteral{5F}{\isacharunderscore}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ local{\isaliteral{5F}{\isacharunderscore}}theory{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
   445
    \indexdef{HOL}{command}{fun}\hypertarget{command.HOL.fun}{\hyperlink{command.HOL.fun}{\mbox{\isa{\isacommand{fun}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}local{\isaliteral{5F}{\isacharunderscore}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ local{\isaliteral{5F}{\isacharunderscore}}theory{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
   446
    \indexdef{HOL}{command}{function}\hypertarget{command.HOL.function}{\hyperlink{command.HOL.function}{\mbox{\isa{\isacommand{function}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}local{\isaliteral{5F}{\isacharunderscore}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ proof{\isaliteral{28}{\isacharparenleft}}prove{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
   447
    \indexdef{HOL}{command}{termination}\hypertarget{command.HOL.termination}{\hyperlink{command.HOL.termination}{\mbox{\isa{\isacommand{termination}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}local{\isaliteral{5F}{\isacharunderscore}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ proof{\isaliteral{28}{\isacharparenleft}}prove{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@26849
   448
  \end{matharray}
wenzelm@26849
   449
wenzelm@26849
   450
  \begin{rail}
wenzelm@26849
   451
    'primrec' target? fixes 'where' equations
wenzelm@26849
   452
    ;
krauss@40411
   453
    ('fun' | 'function') target? functionopts? fixes \\ 'where' equations
krauss@40411
   454
    ;
wenzelm@26849
   455
    equations: (thmdecl? prop + '|')
wenzelm@26849
   456
    ;
wenzelm@26987
   457
    functionopts: '(' (('sequential' | 'domintros' | 'tailrec' | 'default' term) + ',') ')'
wenzelm@26849
   458
    ;
wenzelm@26849
   459
    'termination' ( term )?
wenzelm@26849
   460
  \end{rail}
wenzelm@26849
   461
wenzelm@28788
   462
  \begin{description}
wenzelm@26849
   463
wenzelm@28788
   464
  \item \hyperlink{command.HOL.primrec}{\mbox{\isa{\isacommand{primrec}}}} defines primitive recursive
wenzelm@26849
   465
  functions over datatypes, see also \cite{isabelle-HOL}.
wenzelm@26849
   466
wenzelm@28788
   467
  \item \hyperlink{command.HOL.function}{\mbox{\isa{\isacommand{function}}}} defines functions by general
wenzelm@26849
   468
  wellfounded recursion. A detailed description with examples can be
wenzelm@26849
   469
  found in \cite{isabelle-function}. The function is specified by a
wenzelm@26849
   470
  set of (possibly conditional) recursive equations with arbitrary
wenzelm@26849
   471
  pattern matching. The command generates proof obligations for the
wenzelm@26849
   472
  completeness and the compatibility of patterns.
wenzelm@26849
   473
wenzelm@26849
   474
  The defined function is considered partial, and the resulting
wenzelm@40685
   475
  simplification rules (named \isa{{\isaliteral{22}{\isachardoublequote}}f{\isaliteral{2E}{\isachardot}}psimps{\isaliteral{22}{\isachardoublequote}}}) and induction rule
wenzelm@40685
   476
  (named \isa{{\isaliteral{22}{\isachardoublequote}}f{\isaliteral{2E}{\isachardot}}pinduct{\isaliteral{22}{\isachardoublequote}}}) are guarded by a generated domain
wenzelm@40685
   477
  predicate \isa{{\isaliteral{22}{\isachardoublequote}}f{\isaliteral{5F}{\isacharunderscore}}dom{\isaliteral{22}{\isachardoublequote}}}. The \hyperlink{command.HOL.termination}{\mbox{\isa{\isacommand{termination}}}}
wenzelm@26849
   478
  command can then be used to establish that the function is total.
wenzelm@26849
   479
wenzelm@40685
   480
  \item \hyperlink{command.HOL.fun}{\mbox{\isa{\isacommand{fun}}}} is a shorthand notation for ``\hyperlink{command.HOL.function}{\mbox{\isa{\isacommand{function}}}}~\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{28}{\isacharparenleft}}sequential{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequote}}}, followed by automated
wenzelm@28788
   481
  proof attempts regarding pattern matching and termination.  See
wenzelm@28788
   482
  \cite{isabelle-function} for further details.
wenzelm@26849
   483
wenzelm@28788
   484
  \item \hyperlink{command.HOL.termination}{\mbox{\isa{\isacommand{termination}}}}~\isa{f} commences a
wenzelm@26849
   485
  termination proof for the previously defined function \isa{f}.  If
wenzelm@26849
   486
  this is omitted, the command refers to the most recent function
wenzelm@26849
   487
  definition.  After the proof is closed, the recursive equations and
wenzelm@26849
   488
  the induction principle is established.
wenzelm@26849
   489
wenzelm@28788
   490
  \end{description}
wenzelm@26849
   491
haftmann@27452
   492
  Recursive definitions introduced by the \hyperlink{command.HOL.function}{\mbox{\isa{\isacommand{function}}}}
haftmann@27452
   493
  command accommodate
wenzelm@40685
   494
  reasoning by induction (cf.\ \secref{sec:cases-induct}): rule \isa{{\isaliteral{22}{\isachardoublequote}}c{\isaliteral{2E}{\isachardot}}induct{\isaliteral{22}{\isachardoublequote}}} (where \isa{c} is the name of the function definition)
wenzelm@26849
   495
  refers to a specific induction rule, with parameters named according
krauss@33857
   496
  to the user-specified equations. Cases are numbered (starting from 1).
krauss@33857
   497
krauss@33857
   498
  For \hyperlink{command.HOL.primrec}{\mbox{\isa{\isacommand{primrec}}}}, the induction principle coincides
haftmann@27452
   499
  with structural recursion on the datatype the recursion is carried
haftmann@27452
   500
  out.
wenzelm@26849
   501
wenzelm@26849
   502
  The equations provided by these packages may be referred later as
wenzelm@40685
   503
  theorem list \isa{{\isaliteral{22}{\isachardoublequote}}f{\isaliteral{2E}{\isachardot}}simps{\isaliteral{22}{\isachardoublequote}}}, where \isa{f} is the (collective)
wenzelm@26849
   504
  name of the functions defined.  Individual equations may be named
wenzelm@26849
   505
  explicitly as well.
wenzelm@26849
   506
wenzelm@26902
   507
  The \hyperlink{command.HOL.function}{\mbox{\isa{\isacommand{function}}}} command accepts the following
wenzelm@26849
   508
  options.
wenzelm@26849
   509
wenzelm@28788
   510
  \begin{description}
wenzelm@26849
   511
wenzelm@28788
   512
  \item \isa{sequential} enables a preprocessor which disambiguates
wenzelm@28788
   513
  overlapping patterns by making them mutually disjoint.  Earlier
wenzelm@28788
   514
  equations take precedence over later ones.  This allows to give the
wenzelm@28788
   515
  specification in a format very similar to functional programming.
wenzelm@28788
   516
  Note that the resulting simplification and induction rules
wenzelm@28788
   517
  correspond to the transformed specification, not the one given
wenzelm@26849
   518
  originally. This usually means that each equation given by the user
hoelzl@36137
   519
  may result in several theorems.  Also note that this automatic
wenzelm@26849
   520
  transformation only works for ML-style datatype patterns.
wenzelm@26849
   521
wenzelm@28788
   522
  \item \isa{domintros} enables the automated generation of
wenzelm@26849
   523
  introduction rules for the domain predicate. While mostly not
wenzelm@26849
   524
  needed, they can be helpful in some proofs about partial functions.
wenzelm@26849
   525
wenzelm@28788
   526
  \item \isa{tailrec} generates the unconstrained recursive
wenzelm@26849
   527
  equations even without a termination proof, provided that the
wenzelm@26849
   528
  function is tail-recursive. This currently only works
wenzelm@26849
   529
wenzelm@40685
   530
  \item \isa{{\isaliteral{22}{\isachardoublequote}}default\ d{\isaliteral{22}{\isachardoublequote}}} allows to specify a default value for a
wenzelm@40685
   531
  (partial) function, which will ensure that \isa{{\isaliteral{22}{\isachardoublequote}}f\ x\ {\isaliteral{3D}{\isacharequal}}\ d\ x{\isaliteral{22}{\isachardoublequote}}}
wenzelm@40685
   532
  whenever \isa{{\isaliteral{22}{\isachardoublequote}}x\ {\isaliteral{5C3C6E6F74696E3E}{\isasymnotin}}\ f{\isaliteral{5F}{\isacharunderscore}}dom{\isaliteral{22}{\isachardoublequote}}}.
wenzelm@26849
   533
wenzelm@28788
   534
  \end{description}%
wenzelm@26849
   535
\end{isamarkuptext}%
wenzelm@26849
   536
\isamarkuptrue%
wenzelm@26849
   537
%
wenzelm@26849
   538
\isamarkupsubsection{Proof methods related to recursive definitions%
wenzelm@26849
   539
}
wenzelm@26849
   540
\isamarkuptrue%
wenzelm@26849
   541
%
wenzelm@26849
   542
\begin{isamarkuptext}%
wenzelm@26849
   543
\begin{matharray}{rcl}
wenzelm@40685
   544
    \indexdef{HOL}{method}{pat\_completeness}\hypertarget{method.HOL.pat-completeness}{\hyperlink{method.HOL.pat-completeness}{\mbox{\isa{pat{\isaliteral{5F}{\isacharunderscore}}completeness}}}} & : & \isa{method} \\
wenzelm@28788
   545
    \indexdef{HOL}{method}{relation}\hypertarget{method.HOL.relation}{\hyperlink{method.HOL.relation}{\mbox{\isa{relation}}}} & : & \isa{method} \\
wenzelm@40685
   546
    \indexdef{HOL}{method}{lexicographic\_order}\hypertarget{method.HOL.lexicographic-order}{\hyperlink{method.HOL.lexicographic-order}{\mbox{\isa{lexicographic{\isaliteral{5F}{\isacharunderscore}}order}}}} & : & \isa{method} \\
wenzelm@40685
   547
    \indexdef{HOL}{method}{size\_change}\hypertarget{method.HOL.size-change}{\hyperlink{method.HOL.size-change}{\mbox{\isa{size{\isaliteral{5F}{\isacharunderscore}}change}}}} & : & \isa{method} \\
wenzelm@26849
   548
  \end{matharray}
wenzelm@26849
   549
wenzelm@26849
   550
  \begin{rail}
wenzelm@26849
   551
    'relation' term
wenzelm@26849
   552
    ;
wenzelm@40516
   553
    'lexicographic_order' ( clasimpmod * )
wenzelm@26849
   554
    ;
wenzelm@40516
   555
    'size_change' ( orders ( clasimpmod * ) )
krauss@33858
   556
    ;
krauss@33858
   557
    orders: ( 'max' | 'min' | 'ms' ) *
wenzelm@26849
   558
  \end{rail}
wenzelm@26849
   559
wenzelm@28788
   560
  \begin{description}
wenzelm@26849
   561
wenzelm@40685
   562
  \item \hyperlink{method.HOL.pat-completeness}{\mbox{\isa{pat{\isaliteral{5F}{\isacharunderscore}}completeness}}} is a specialized method to
wenzelm@26849
   563
  solve goals regarding the completeness of pattern matching, as
wenzelm@26902
   564
  required by the \hyperlink{command.HOL.function}{\mbox{\isa{\isacommand{function}}}} package (cf.\
wenzelm@26849
   565
  \cite{isabelle-function}).
wenzelm@26849
   566
wenzelm@28788
   567
  \item \hyperlink{method.HOL.relation}{\mbox{\isa{relation}}}~\isa{R} introduces a termination
wenzelm@26849
   568
  proof using the relation \isa{R}.  The resulting proof state will
wenzelm@26849
   569
  contain goals expressing that \isa{R} is wellfounded, and that the
wenzelm@26849
   570
  arguments of recursive calls decrease with respect to \isa{R}.
wenzelm@26849
   571
  Usually, this method is used as the initial proof step of manual
wenzelm@26849
   572
  termination proofs.
wenzelm@26849
   573
wenzelm@40685
   574
  \item \hyperlink{method.HOL.lexicographic-order}{\mbox{\isa{lexicographic{\isaliteral{5F}{\isacharunderscore}}order}}} attempts a fully
wenzelm@26849
   575
  automated termination proof by searching for a lexicographic
wenzelm@26849
   576
  combination of size measures on the arguments of the function. The
wenzelm@26902
   577
  method accepts the same arguments as the \hyperlink{method.auto}{\mbox{\isa{auto}}} method,
wenzelm@26849
   578
  which it uses internally to prove local descents.  The same context
wenzelm@26902
   579
  modifiers as for \hyperlink{method.auto}{\mbox{\isa{auto}}} are accepted, see
wenzelm@26849
   580
  \secref{sec:clasimp}.
wenzelm@26849
   581
wenzelm@26849
   582
  In case of failure, extensive information is printed, which can help
wenzelm@26849
   583
  to analyse the situation (cf.\ \cite{isabelle-function}).
wenzelm@26849
   584
wenzelm@40685
   585
  \item \hyperlink{method.HOL.size-change}{\mbox{\isa{size{\isaliteral{5F}{\isacharunderscore}}change}}} also works on termination goals,
krauss@33858
   586
  using a variation of the size-change principle, together with a
krauss@33858
   587
  graph decomposition technique (see \cite{krauss_phd} for details).
krauss@33858
   588
  Three kinds of orders are used internally: \isa{max}, \isa{min},
krauss@33858
   589
  and \isa{ms} (multiset), which is only available when the theory
krauss@33858
   590
  \isa{Multiset} is loaded. When no order kinds are given, they are
krauss@33858
   591
  tried in order. The search for a termination proof uses SAT solving
krauss@33858
   592
  internally.
krauss@33858
   593
krauss@33858
   594
 For local descent proofs, the same context modifiers as for \hyperlink{method.auto}{\mbox{\isa{auto}}} are accepted, see \secref{sec:clasimp}.
krauss@33858
   595
wenzelm@28788
   596
  \end{description}%
wenzelm@26849
   597
\end{isamarkuptext}%
wenzelm@26849
   598
\isamarkuptrue%
wenzelm@26849
   599
%
krauss@40412
   600
\isamarkupsubsection{Functions with explicit partiality%
krauss@40412
   601
}
krauss@40412
   602
\isamarkuptrue%
krauss@40412
   603
%
krauss@40412
   604
\begin{isamarkuptext}%
krauss@40412
   605
\begin{matharray}{rcl}
wenzelm@40685
   606
    \indexdef{HOL}{command}{partial\_function}\hypertarget{command.HOL.partial-function}{\hyperlink{command.HOL.partial-function}{\mbox{\isa{\isacommand{partial{\isaliteral{5F}{\isacharunderscore}}function}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}local{\isaliteral{5F}{\isacharunderscore}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ local{\isaliteral{5F}{\isacharunderscore}}theory{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
   607
    \indexdef{HOL}{attribute}{partial\_function\_mono}\hypertarget{attribute.HOL.partial-function-mono}{\hyperlink{attribute.HOL.partial-function-mono}{\mbox{\isa{partial{\isaliteral{5F}{\isacharunderscore}}function{\isaliteral{5F}{\isacharunderscore}}mono}}}} & : & \isa{attribute} \\
krauss@40412
   608
  \end{matharray}
krauss@40412
   609
krauss@40412
   610
  \begin{rail}
krauss@40412
   611
    'partial_function' target? '(' mode ')' fixes \\ 'where' thmdecl? prop
krauss@40412
   612
  \end{rail}
krauss@40412
   613
krauss@40412
   614
  \begin{description}
krauss@40412
   615
wenzelm@40685
   616
  \item \hyperlink{command.HOL.partial-function}{\mbox{\isa{\isacommand{partial{\isaliteral{5F}{\isacharunderscore}}function}}}} defines recursive
krauss@40412
   617
  functions based on fixpoints in complete partial orders. No
krauss@40412
   618
  termination proof is required from the user or constructed
krauss@40412
   619
  internally. Instead, the possibility of non-termination is modelled
krauss@40412
   620
  explicitly in the result type, which contains an explicit bottom
krauss@40412
   621
  element.
krauss@40412
   622
krauss@40412
   623
  Pattern matching and mutual recursion are currently not supported.
krauss@40412
   624
  Thus, the specification consists of a single function described by a
krauss@40412
   625
  single recursive equation.
krauss@40412
   626
krauss@40412
   627
  There are no fixed syntactic restrictions on the body of the
krauss@40412
   628
  function, but the induced functional must be provably monotonic
krauss@40412
   629
  wrt.\ the underlying order.  The monotonicitity proof is performed
krauss@40412
   630
  internally, and the definition is rejected when it fails. The proof
krauss@40412
   631
  can be influenced by declaring hints using the
wenzelm@40685
   632
  \hyperlink{attribute.HOL.partial-function-mono}{\mbox{\isa{partial{\isaliteral{5F}{\isacharunderscore}}function{\isaliteral{5F}{\isacharunderscore}}mono}}} attribute.
krauss@40412
   633
krauss@40412
   634
  The mandatory \isa{mode} argument specifies the mode of operation
krauss@40412
   635
  of the command, which directly corresponds to a complete partial
krauss@40412
   636
  order on the result type. By default, the following modes are
krauss@40412
   637
  defined: 
krauss@40412
   638
krauss@40412
   639
  \begin{description}
krauss@40412
   640
  \item \isa{option} defines functions that map into the \isa{option} type. Here, the value \isa{None} is used to model a
krauss@40412
   641
  non-terminating computation. Monotonicity requires that if \isa{None} is returned by a recursive call, then the overall result
krauss@40412
   642
  must also be \isa{None}. This is best achieved through the use of
wenzelm@40685
   643
  the monadic operator \isa{{\isaliteral{22}{\isachardoublequote}}Option{\isaliteral{2E}{\isachardot}}bind{\isaliteral{22}{\isachardoublequote}}}.
krauss@40412
   644
  
krauss@40412
   645
  \item \isa{tailrec} defines functions with an arbitrary result
wenzelm@40685
   646
  type and uses the slightly degenerated partial order where \isa{{\isaliteral{22}{\isachardoublequote}}undefined{\isaliteral{22}{\isachardoublequote}}} is the bottom element.  Now, monotonicity requires that
krauss@40412
   647
  if \isa{undefined} is returned by a recursive call, then the
krauss@40412
   648
  overall result must also be \isa{undefined}. In practice, this is
krauss@40412
   649
  only satisfied when each recursive call is a tail call, whose result
krauss@40412
   650
  is directly returned. Thus, this mode of operation allows the
krauss@40412
   651
  definition of arbitrary tail-recursive functions.
krauss@40412
   652
  \end{description}
krauss@40412
   653
krauss@40412
   654
  Experienced users may define new modes by instantiating the locale
wenzelm@40685
   655
  \isa{{\isaliteral{22}{\isachardoublequote}}partial{\isaliteral{5F}{\isacharunderscore}}function{\isaliteral{5F}{\isacharunderscore}}definitions{\isaliteral{22}{\isachardoublequote}}} appropriately.
krauss@40412
   656
wenzelm@40685
   657
  \item \hyperlink{attribute.HOL.partial-function-mono}{\mbox{\isa{partial{\isaliteral{5F}{\isacharunderscore}}function{\isaliteral{5F}{\isacharunderscore}}mono}}} declares rules for
krauss@40412
   658
  use in the internal monononicity proofs of partial function
krauss@40412
   659
  definitions.
krauss@40412
   660
krauss@40412
   661
  \end{description}%
krauss@40412
   662
\end{isamarkuptext}%
krauss@40412
   663
\isamarkuptrue%
krauss@40412
   664
%
wenzelm@26849
   665
\isamarkupsubsection{Old-style recursive function definitions (TFL)%
wenzelm@26849
   666
}
wenzelm@26849
   667
\isamarkuptrue%
wenzelm@26849
   668
%
wenzelm@26849
   669
\begin{isamarkuptext}%
wenzelm@40685
   670
The old TFL commands \hyperlink{command.HOL.recdef}{\mbox{\isa{\isacommand{recdef}}}} and \hyperlink{command.HOL.recdef-tc}{\mbox{\isa{\isacommand{recdef{\isaliteral{5F}{\isacharunderscore}}tc}}}} for defining recursive are mostly obsolete; \hyperlink{command.HOL.function}{\mbox{\isa{\isacommand{function}}}} or \hyperlink{command.HOL.fun}{\mbox{\isa{\isacommand{fun}}}} should be used instead.
wenzelm@26849
   671
wenzelm@26849
   672
  \begin{matharray}{rcl}
wenzelm@40685
   673
    \indexdef{HOL}{command}{recdef}\hypertarget{command.HOL.recdef}{\hyperlink{command.HOL.recdef}{\mbox{\isa{\isacommand{recdef}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
   674
    \indexdef{HOL}{command}{recdef\_tc}\hypertarget{command.HOL.recdef-tc}{\hyperlink{command.HOL.recdef-tc}{\mbox{\isa{\isacommand{recdef{\isaliteral{5F}{\isacharunderscore}}tc}}}}}\isa{{\isaliteral{22}{\isachardoublequote}}\isaliteral{5C3C5E7375703E}{}\isactrlsup {\isaliteral{2A}{\isacharasterisk}}{\isaliteral{22}{\isachardoublequote}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ proof{\isaliteral{28}{\isacharparenleft}}prove{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@26849
   675
  \end{matharray}
wenzelm@26849
   676
wenzelm@26849
   677
  \begin{rail}
wenzelm@26849
   678
    'recdef' ('(' 'permissive' ')')? \\ name term (prop +) hints?
wenzelm@26849
   679
    ;
wenzelm@26849
   680
    recdeftc thmdecl? tc
wenzelm@26849
   681
    ;
haftmann@31907
   682
    hints: '(' 'hints' ( recdefmod * ) ')'
wenzelm@26849
   683
    ;
wenzelm@40516
   684
    recdefmod: (('recdef_simp' | 'recdef_cong' | 'recdef_wf') (() | 'add' | 'del') ':' thmrefs) | clasimpmod
wenzelm@26849
   685
    ;
wenzelm@26849
   686
    tc: nameref ('(' nat ')')?
wenzelm@26849
   687
    ;
wenzelm@26849
   688
  \end{rail}
wenzelm@26849
   689
wenzelm@28788
   690
  \begin{description}
wenzelm@26849
   691
  
wenzelm@28788
   692
  \item \hyperlink{command.HOL.recdef}{\mbox{\isa{\isacommand{recdef}}}} defines general well-founded
wenzelm@26849
   693
  recursive functions (using the TFL package), see also
wenzelm@40685
   694
  \cite{isabelle-HOL}.  The ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{28}{\isacharparenleft}}permissive{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequote}}}'' option tells
wenzelm@26849
   695
  TFL to recover from failed proof attempts, returning unfinished
wenzelm@40685
   696
  results.  The \isa{recdef{\isaliteral{5F}{\isacharunderscore}}simp}, \isa{recdef{\isaliteral{5F}{\isacharunderscore}}cong}, and \isa{recdef{\isaliteral{5F}{\isacharunderscore}}wf} hints refer to auxiliary rules to be used in the internal
wenzelm@26902
   697
  automated proof process of TFL.  Additional \hyperlink{syntax.clasimpmod}{\mbox{\isa{clasimpmod}}}
wenzelm@26849
   698
  declarations (cf.\ \secref{sec:clasimp}) may be given to tune the
wenzelm@26849
   699
  context of the Simplifier (cf.\ \secref{sec:simplifier}) and
wenzelm@26849
   700
  Classical reasoner (cf.\ \secref{sec:classical}).
wenzelm@26849
   701
  
wenzelm@40685
   702
  \item \hyperlink{command.HOL.recdef-tc}{\mbox{\isa{\isacommand{recdef{\isaliteral{5F}{\isacharunderscore}}tc}}}}~\isa{{\isaliteral{22}{\isachardoublequote}}c\ {\isaliteral{28}{\isacharparenleft}}i{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequote}}} recommences the
wenzelm@26849
   703
  proof for leftover termination condition number \isa{i} (default
wenzelm@26902
   704
  1) as generated by a \hyperlink{command.HOL.recdef}{\mbox{\isa{\isacommand{recdef}}}} definition of
wenzelm@26849
   705
  constant \isa{c}.
wenzelm@26849
   706
  
wenzelm@26902
   707
  Note that in most cases, \hyperlink{command.HOL.recdef}{\mbox{\isa{\isacommand{recdef}}}} is able to finish
wenzelm@26849
   708
  its internal proofs without manual intervention.
wenzelm@26849
   709
wenzelm@28788
   710
  \end{description}
wenzelm@26849
   711
wenzelm@26902
   712
  \medskip Hints for \hyperlink{command.HOL.recdef}{\mbox{\isa{\isacommand{recdef}}}} may be also declared
wenzelm@26849
   713
  globally, using the following attributes.
wenzelm@26849
   714
wenzelm@26849
   715
  \begin{matharray}{rcl}
wenzelm@40685
   716
    \indexdef{HOL}{attribute}{recdef\_simp}\hypertarget{attribute.HOL.recdef-simp}{\hyperlink{attribute.HOL.recdef-simp}{\mbox{\isa{recdef{\isaliteral{5F}{\isacharunderscore}}simp}}}} & : & \isa{attribute} \\
wenzelm@40685
   717
    \indexdef{HOL}{attribute}{recdef\_cong}\hypertarget{attribute.HOL.recdef-cong}{\hyperlink{attribute.HOL.recdef-cong}{\mbox{\isa{recdef{\isaliteral{5F}{\isacharunderscore}}cong}}}} & : & \isa{attribute} \\
wenzelm@40685
   718
    \indexdef{HOL}{attribute}{recdef\_wf}\hypertarget{attribute.HOL.recdef-wf}{\hyperlink{attribute.HOL.recdef-wf}{\mbox{\isa{recdef{\isaliteral{5F}{\isacharunderscore}}wf}}}} & : & \isa{attribute} \\
wenzelm@26849
   719
  \end{matharray}
wenzelm@26849
   720
wenzelm@26849
   721
  \begin{rail}
wenzelm@40516
   722
    ('recdef_simp' | 'recdef_cong' | 'recdef_wf') (() | 'add' | 'del')
wenzelm@26849
   723
    ;
wenzelm@26849
   724
  \end{rail}%
wenzelm@26849
   725
\end{isamarkuptext}%
wenzelm@26849
   726
\isamarkuptrue%
wenzelm@26849
   727
%
wenzelm@26849
   728
\isamarkupsection{Inductive and coinductive definitions \label{sec:hol-inductive}%
wenzelm@26849
   729
}
wenzelm@26849
   730
\isamarkuptrue%
wenzelm@26849
   731
%
wenzelm@26849
   732
\begin{isamarkuptext}%
wenzelm@26849
   733
An \textbf{inductive definition} specifies the least predicate (or
wenzelm@26849
   734
  set) \isa{R} closed under given rules: applying a rule to elements
wenzelm@26849
   735
  of \isa{R} yields a result within \isa{R}.  For example, a
wenzelm@26849
   736
  structural operational semantics is an inductive definition of an
wenzelm@26849
   737
  evaluation relation.
wenzelm@26849
   738
wenzelm@26849
   739
  Dually, a \textbf{coinductive definition} specifies the greatest
wenzelm@26849
   740
  predicate~/ set \isa{R} that is consistent with given rules: every
wenzelm@26849
   741
  element of \isa{R} can be seen as arising by applying a rule to
wenzelm@26849
   742
  elements of \isa{R}.  An important example is using bisimulation
wenzelm@26849
   743
  relations to formalise equivalence of processes and infinite data
wenzelm@26849
   744
  structures.
wenzelm@26849
   745
wenzelm@26849
   746
  \medskip The HOL package is related to the ZF one, which is
wenzelm@26849
   747
  described in a separate paper,\footnote{It appeared in CADE
wenzelm@26849
   748
  \cite{paulson-CADE}; a longer version is distributed with Isabelle.}
wenzelm@26849
   749
  which you should refer to in case of difficulties.  The package is
wenzelm@26849
   750
  simpler than that of ZF thanks to implicit type-checking in HOL.
wenzelm@26849
   751
  The types of the (co)inductive predicates (or sets) determine the
wenzelm@26849
   752
  domain of the fixedpoint definition, and the package does not have
wenzelm@26849
   753
  to use inference rules for type-checking.
wenzelm@26849
   754
wenzelm@26849
   755
  \begin{matharray}{rcl}
wenzelm@40685
   756
    \indexdef{HOL}{command}{inductive}\hypertarget{command.HOL.inductive}{\hyperlink{command.HOL.inductive}{\mbox{\isa{\isacommand{inductive}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}local{\isaliteral{5F}{\isacharunderscore}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ local{\isaliteral{5F}{\isacharunderscore}}theory{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
   757
    \indexdef{HOL}{command}{inductive\_set}\hypertarget{command.HOL.inductive-set}{\hyperlink{command.HOL.inductive-set}{\mbox{\isa{\isacommand{inductive{\isaliteral{5F}{\isacharunderscore}}set}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}local{\isaliteral{5F}{\isacharunderscore}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ local{\isaliteral{5F}{\isacharunderscore}}theory{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
   758
    \indexdef{HOL}{command}{coinductive}\hypertarget{command.HOL.coinductive}{\hyperlink{command.HOL.coinductive}{\mbox{\isa{\isacommand{coinductive}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}local{\isaliteral{5F}{\isacharunderscore}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ local{\isaliteral{5F}{\isacharunderscore}}theory{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
   759
    \indexdef{HOL}{command}{coinductive\_set}\hypertarget{command.HOL.coinductive-set}{\hyperlink{command.HOL.coinductive-set}{\mbox{\isa{\isacommand{coinductive{\isaliteral{5F}{\isacharunderscore}}set}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}local{\isaliteral{5F}{\isacharunderscore}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ local{\isaliteral{5F}{\isacharunderscore}}theory{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@28788
   760
    \indexdef{HOL}{attribute}{mono}\hypertarget{attribute.HOL.mono}{\hyperlink{attribute.HOL.mono}{\mbox{\isa{mono}}}} & : & \isa{attribute} \\
wenzelm@26849
   761
  \end{matharray}
wenzelm@26849
   762
wenzelm@26849
   763
  \begin{rail}
wenzelm@40516
   764
    ('inductive' | 'inductive_set' | 'coinductive' | 'coinductive_set') target? fixes ('for' fixes)? \\
wenzelm@26849
   765
    ('where' clauses)? ('monos' thmrefs)?
wenzelm@26849
   766
    ;
wenzelm@26849
   767
    clauses: (thmdecl? prop + '|')
wenzelm@26849
   768
    ;
wenzelm@26849
   769
    'mono' (() | 'add' | 'del')
wenzelm@26849
   770
    ;
wenzelm@26849
   771
  \end{rail}
wenzelm@26849
   772
wenzelm@28788
   773
  \begin{description}
wenzelm@26849
   774
wenzelm@28788
   775
  \item \hyperlink{command.HOL.inductive}{\mbox{\isa{\isacommand{inductive}}}} and \hyperlink{command.HOL.coinductive}{\mbox{\isa{\isacommand{coinductive}}}} define (co)inductive predicates from the
wenzelm@26902
   776
  introduction rules given in the \hyperlink{keyword.where}{\mbox{\isa{\isakeyword{where}}}} part.  The
wenzelm@26902
   777
  optional \hyperlink{keyword.for}{\mbox{\isa{\isakeyword{for}}}} part contains a list of parameters of the
wenzelm@26849
   778
  (co)inductive predicates that remain fixed throughout the
wenzelm@26902
   779
  definition.  The optional \hyperlink{keyword.monos}{\mbox{\isa{\isakeyword{monos}}}} section contains
wenzelm@26849
   780
  \emph{monotonicity theorems}, which are required for each operator
wenzelm@26849
   781
  applied to a recursive set in the introduction rules.  There
wenzelm@40685
   782
  \emph{must} be a theorem of the form \isa{{\isaliteral{22}{\isachardoublequote}}A\ {\isaliteral{5C3C6C653E}{\isasymle}}\ B\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ M\ A\ {\isaliteral{5C3C6C653E}{\isasymle}}\ M\ B{\isaliteral{22}{\isachardoublequote}}},
wenzelm@40685
   783
  for each premise \isa{{\isaliteral{22}{\isachardoublequote}}M\ R\isaliteral{5C3C5E7375623E}{}\isactrlsub i\ t{\isaliteral{22}{\isachardoublequote}}} in an introduction rule!
wenzelm@26849
   784
wenzelm@40685
   785
  \item \hyperlink{command.HOL.inductive-set}{\mbox{\isa{\isacommand{inductive{\isaliteral{5F}{\isacharunderscore}}set}}}} and \hyperlink{command.HOL.coinductive-set}{\mbox{\isa{\isacommand{coinductive{\isaliteral{5F}{\isacharunderscore}}set}}}} are wrappers for to the previous commands,
wenzelm@26849
   786
  allowing the definition of (co)inductive sets.
wenzelm@26849
   787
wenzelm@28788
   788
  \item \hyperlink{attribute.HOL.mono}{\mbox{\isa{mono}}} declares monotonicity rules.  These
wenzelm@26902
   789
  rule are involved in the automated monotonicity proof of \hyperlink{command.HOL.inductive}{\mbox{\isa{\isacommand{inductive}}}}.
wenzelm@26849
   790
wenzelm@28788
   791
  \end{description}%
wenzelm@26849
   792
\end{isamarkuptext}%
wenzelm@26849
   793
\isamarkuptrue%
wenzelm@26849
   794
%
wenzelm@26849
   795
\isamarkupsubsection{Derived rules%
wenzelm@26849
   796
}
wenzelm@26849
   797
\isamarkuptrue%
wenzelm@26849
   798
%
wenzelm@26849
   799
\begin{isamarkuptext}%
wenzelm@26849
   800
Each (co)inductive definition \isa{R} adds definitions to the
wenzelm@26849
   801
  theory and also proves some theorems:
wenzelm@26849
   802
wenzelm@26849
   803
  \begin{description}
wenzelm@26849
   804
wenzelm@40685
   805
  \item \isa{R{\isaliteral{2E}{\isachardot}}intros} is the list of introduction rules as proven
wenzelm@26849
   806
  theorems, for the recursive predicates (or sets).  The rules are
wenzelm@26849
   807
  also available individually, using the names given them in the
wenzelm@26849
   808
  theory file;
wenzelm@26849
   809
wenzelm@40685
   810
  \item \isa{R{\isaliteral{2E}{\isachardot}}cases} is the case analysis (or elimination) rule;
wenzelm@26849
   811
wenzelm@40685
   812
  \item \isa{R{\isaliteral{2E}{\isachardot}}induct} or \isa{R{\isaliteral{2E}{\isachardot}}coinduct} is the (co)induction
wenzelm@26849
   813
  rule.
wenzelm@26849
   814
wenzelm@26849
   815
  \end{description}
wenzelm@26849
   816
wenzelm@40685
   817
  When several predicates \isa{{\isaliteral{22}{\isachardoublequote}}R\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{2C}{\isacharcomma}}\ R\isaliteral{5C3C5E7375623E}{}\isactrlsub n{\isaliteral{22}{\isachardoublequote}}} are
wenzelm@26849
   818
  defined simultaneously, the list of introduction rules is called
wenzelm@40685
   819
  \isa{{\isaliteral{22}{\isachardoublequote}}R\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{5F}{\isacharunderscore}}{\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{5F}{\isacharunderscore}}R\isaliteral{5C3C5E7375623E}{}\isactrlsub n{\isaliteral{2E}{\isachardot}}intros{\isaliteral{22}{\isachardoublequote}}}, the case analysis rules are
wenzelm@40685
   820
  called \isa{{\isaliteral{22}{\isachardoublequote}}R\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{2E}{\isachardot}}cases{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{2C}{\isacharcomma}}\ R\isaliteral{5C3C5E7375623E}{}\isactrlsub n{\isaliteral{2E}{\isachardot}}cases{\isaliteral{22}{\isachardoublequote}}}, and the list
wenzelm@40685
   821
  of mutual induction rules is called \isa{{\isaliteral{22}{\isachardoublequote}}R\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{5F}{\isacharunderscore}}{\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{5F}{\isacharunderscore}}R\isaliteral{5C3C5E7375623E}{}\isactrlsub n{\isaliteral{2E}{\isachardot}}inducts{\isaliteral{22}{\isachardoublequote}}}.%
wenzelm@26849
   822
\end{isamarkuptext}%
wenzelm@26849
   823
\isamarkuptrue%
wenzelm@26849
   824
%
wenzelm@26849
   825
\isamarkupsubsection{Monotonicity theorems%
wenzelm@26849
   826
}
wenzelm@26849
   827
\isamarkuptrue%
wenzelm@26849
   828
%
wenzelm@26849
   829
\begin{isamarkuptext}%
wenzelm@26849
   830
Each theory contains a default set of theorems that are used in
wenzelm@26849
   831
  monotonicity proofs.  New rules can be added to this set via the
wenzelm@26902
   832
  \hyperlink{attribute.HOL.mono}{\mbox{\isa{mono}}} attribute.  The HOL theory \isa{Inductive}
wenzelm@26849
   833
  shows how this is done.  In general, the following monotonicity
wenzelm@26849
   834
  theorems may be added:
wenzelm@26849
   835
wenzelm@26849
   836
  \begin{itemize}
wenzelm@26849
   837
wenzelm@40685
   838
  \item Theorems of the form \isa{{\isaliteral{22}{\isachardoublequote}}A\ {\isaliteral{5C3C6C653E}{\isasymle}}\ B\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ M\ A\ {\isaliteral{5C3C6C653E}{\isasymle}}\ M\ B{\isaliteral{22}{\isachardoublequote}}}, for proving
wenzelm@26849
   839
  monotonicity of inductive definitions whose introduction rules have
wenzelm@40685
   840
  premises involving terms such as \isa{{\isaliteral{22}{\isachardoublequote}}M\ R\isaliteral{5C3C5E7375623E}{}\isactrlsub i\ t{\isaliteral{22}{\isachardoublequote}}}.
wenzelm@26849
   841
wenzelm@26849
   842
  \item Monotonicity theorems for logical operators, which are of the
wenzelm@40685
   843
  general form \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{5C3C6C6F6E6772696768746172726F773E}{\isasymlongrightarrow}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{5C3C6C6F6E6772696768746172726F773E}{\isasymlongrightarrow}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{5C3C6C6F6E6772696768746172726F773E}{\isasymlongrightarrow}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{22}{\isachardoublequote}}}.  For example, in
wenzelm@40685
   844
  the case of the operator \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6F723E}{\isasymor}}{\isaliteral{22}{\isachardoublequote}}}, the corresponding theorem is
wenzelm@26849
   845
  \[
wenzelm@40685
   846
  \infer{\isa{{\isaliteral{22}{\isachardoublequote}}P\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{5C3C6F723E}{\isasymor}}\ P\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{2}}\ {\isaliteral{5C3C6C6F6E6772696768746172726F773E}{\isasymlongrightarrow}}\ Q\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{5C3C6F723E}{\isasymor}}\ Q\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{2}}{\isaliteral{22}{\isachardoublequote}}}}{\isa{{\isaliteral{22}{\isachardoublequote}}P\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{5C3C6C6F6E6772696768746172726F773E}{\isasymlongrightarrow}}\ Q\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{22}{\isachardoublequote}}} & \isa{{\isaliteral{22}{\isachardoublequote}}P\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{2}}\ {\isaliteral{5C3C6C6F6E6772696768746172726F773E}{\isasymlongrightarrow}}\ Q\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{2}}{\isaliteral{22}{\isachardoublequote}}}}
wenzelm@26849
   847
  \]
wenzelm@26849
   848
wenzelm@26849
   849
  \item De Morgan style equations for reasoning about the ``polarity''
wenzelm@26849
   850
  of expressions, e.g.
wenzelm@26849
   851
  \[
wenzelm@40685
   852
  \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6E6F743E}{\isasymnot}}\ {\isaliteral{5C3C6E6F743E}{\isasymnot}}\ P\ {\isaliteral{5C3C6C6F6E676C65667472696768746172726F773E}{\isasymlongleftrightarrow}}\ P{\isaliteral{22}{\isachardoublequote}}} \qquad\qquad
wenzelm@40685
   853
  \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6E6F743E}{\isasymnot}}\ {\isaliteral{28}{\isacharparenleft}}P\ {\isaliteral{5C3C616E643E}{\isasymand}}\ Q{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C6C6F6E676C65667472696768746172726F773E}{\isasymlongleftrightarrow}}\ {\isaliteral{5C3C6E6F743E}{\isasymnot}}\ P\ {\isaliteral{5C3C6F723E}{\isasymor}}\ {\isaliteral{5C3C6E6F743E}{\isasymnot}}\ Q{\isaliteral{22}{\isachardoublequote}}}
wenzelm@26849
   854
  \]
wenzelm@26849
   855
wenzelm@26849
   856
  \item Equations for reducing complex operators to more primitive
wenzelm@26849
   857
  ones whose monotonicity can easily be proved, e.g.
wenzelm@26849
   858
  \[
wenzelm@40685
   859
  \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{28}{\isacharparenleft}}P\ {\isaliteral{5C3C6C6F6E6772696768746172726F773E}{\isasymlongrightarrow}}\ Q{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C6C6F6E676C65667472696768746172726F773E}{\isasymlongleftrightarrow}}\ {\isaliteral{5C3C6E6F743E}{\isasymnot}}\ P\ {\isaliteral{5C3C6F723E}{\isasymor}}\ Q{\isaliteral{22}{\isachardoublequote}}} \qquad\qquad
wenzelm@40685
   860
  \isa{{\isaliteral{22}{\isachardoublequote}}Ball\ A\ P\ {\isaliteral{5C3C65717569763E}{\isasymequiv}}\ {\isaliteral{5C3C666F72616C6C3E}{\isasymforall}}x{\isaliteral{2E}{\isachardot}}\ x\ {\isaliteral{5C3C696E3E}{\isasymin}}\ A\ {\isaliteral{5C3C6C6F6E6772696768746172726F773E}{\isasymlongrightarrow}}\ P\ x{\isaliteral{22}{\isachardoublequote}}}
wenzelm@26849
   861
  \]
wenzelm@26849
   862
wenzelm@26849
   863
  \end{itemize}
wenzelm@26849
   864
wenzelm@26849
   865
  %FIXME: Example of an inductive definition%
wenzelm@26849
   866
\end{isamarkuptext}%
wenzelm@26849
   867
\isamarkuptrue%
wenzelm@26849
   868
%
wenzelm@26849
   869
\isamarkupsection{Arithmetic proof support%
wenzelm@26849
   870
}
wenzelm@26849
   871
\isamarkuptrue%
wenzelm@26849
   872
%
wenzelm@26849
   873
\begin{isamarkuptext}%
wenzelm@26849
   874
\begin{matharray}{rcl}
wenzelm@28788
   875
    \indexdef{HOL}{method}{arith}\hypertarget{method.HOL.arith}{\hyperlink{method.HOL.arith}{\mbox{\isa{arith}}}} & : & \isa{method} \\
nipkow@30863
   876
    \indexdef{HOL}{attribute}{arith}\hypertarget{attribute.HOL.arith}{\hyperlink{attribute.HOL.arith}{\mbox{\isa{arith}}}} & : & \isa{attribute} \\
wenzelm@40685
   877
    \indexdef{HOL}{attribute}{arith\_split}\hypertarget{attribute.HOL.arith-split}{\hyperlink{attribute.HOL.arith-split}{\mbox{\isa{arith{\isaliteral{5F}{\isacharunderscore}}split}}}} & : & \isa{attribute} \\
wenzelm@26849
   878
  \end{matharray}
wenzelm@26849
   879
wenzelm@26902
   880
  The \hyperlink{method.HOL.arith}{\mbox{\isa{arith}}} method decides linear arithmetic problems
wenzelm@26849
   881
  (on types \isa{nat}, \isa{int}, \isa{real}).  Any current
wenzelm@26849
   882
  facts are inserted into the goal before running the procedure.
wenzelm@26849
   883
nipkow@30863
   884
  The \hyperlink{attribute.HOL.arith}{\mbox{\isa{arith}}} attribute declares facts that are
nipkow@30863
   885
  always supplied to the arithmetic provers implicitly.
nipkow@30863
   886
wenzelm@40685
   887
  The \hyperlink{attribute.HOL.arith-split}{\mbox{\isa{arith{\isaliteral{5F}{\isacharunderscore}}split}}} attribute declares case split
wenzelm@30865
   888
  rules to be expanded before \hyperlink{method.HOL.arith}{\mbox{\isa{arith}}} is invoked.
wenzelm@26849
   889
nipkow@30863
   890
  Note that a simpler (but faster) arithmetic prover is
nipkow@30863
   891
  already invoked by the Simplifier.%
wenzelm@26849
   892
\end{isamarkuptext}%
wenzelm@26849
   893
\isamarkuptrue%
wenzelm@26849
   894
%
wenzelm@30172
   895
\isamarkupsection{Intuitionistic proof search%
wenzelm@30172
   896
}
wenzelm@30172
   897
\isamarkuptrue%
wenzelm@30172
   898
%
wenzelm@30172
   899
\begin{isamarkuptext}%
wenzelm@30172
   900
\begin{matharray}{rcl}
wenzelm@30172
   901
    \indexdef{HOL}{method}{iprover}\hypertarget{method.HOL.iprover}{\hyperlink{method.HOL.iprover}{\mbox{\isa{iprover}}}} & : & \isa{method} \\
wenzelm@30172
   902
  \end{matharray}
wenzelm@30172
   903
wenzelm@30172
   904
  \begin{rail}
wenzelm@35613
   905
    'iprover' ( rulemod * )
wenzelm@30172
   906
    ;
wenzelm@30172
   907
  \end{rail}
wenzelm@30172
   908
wenzelm@30172
   909
  The \hyperlink{method.HOL.iprover}{\mbox{\isa{iprover}}} method performs intuitionistic proof
wenzelm@30172
   910
  search, depending on specifically declared rules from the context,
wenzelm@30172
   911
  or given as explicit arguments.  Chained facts are inserted into the
wenzelm@35613
   912
  goal before commencing proof search.
wenzelm@35613
   913
wenzelm@30172
   914
  Rules need to be classified as \hyperlink{attribute.Pure.intro}{\mbox{\isa{intro}}},
wenzelm@30172
   915
  \hyperlink{attribute.Pure.elim}{\mbox{\isa{elim}}}, or \hyperlink{attribute.Pure.dest}{\mbox{\isa{dest}}}; here the
wenzelm@40685
   916
  ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{21}{\isacharbang}}{\isaliteral{22}{\isachardoublequote}}}'' indicator refers to ``safe'' rules, which may be
wenzelm@30172
   917
  applied aggressively (without considering back-tracking later).
wenzelm@40685
   918
  Rules declared with ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{3F}{\isacharquery}}{\isaliteral{22}{\isachardoublequote}}}'' are ignored in proof search (the
wenzelm@30172
   919
  single-step \hyperlink{method.rule}{\mbox{\isa{rule}}} method still observes these).  An
wenzelm@30172
   920
  explicit weight annotation may be given as well; otherwise the
wenzelm@30172
   921
  number of rule premises will be taken into account here.%
wenzelm@30172
   922
\end{isamarkuptext}%
wenzelm@30172
   923
\isamarkuptrue%
wenzelm@30172
   924
%
wenzelm@30172
   925
\isamarkupsection{Coherent Logic%
wenzelm@30172
   926
}
wenzelm@30172
   927
\isamarkuptrue%
wenzelm@30172
   928
%
wenzelm@30172
   929
\begin{isamarkuptext}%
wenzelm@30172
   930
\begin{matharray}{rcl}
wenzelm@30172
   931
    \indexdef{HOL}{method}{coherent}\hypertarget{method.HOL.coherent}{\hyperlink{method.HOL.coherent}{\mbox{\isa{coherent}}}} & : & \isa{method} \\
wenzelm@30172
   932
  \end{matharray}
wenzelm@30172
   933
wenzelm@30172
   934
  \begin{rail}
wenzelm@30172
   935
    'coherent' thmrefs?
wenzelm@30172
   936
    ;
wenzelm@30172
   937
  \end{rail}
wenzelm@30172
   938
wenzelm@30172
   939
  The \hyperlink{method.HOL.coherent}{\mbox{\isa{coherent}}} method solves problems of
wenzelm@30172
   940
  \emph{Coherent Logic} \cite{Bezem-Coquand:2005}, which covers
wenzelm@30172
   941
  applications in confluence theory, lattice theory and projective
wenzelm@41052
   942
  geometry.  See \verb|~~/src/HOL/ex/Coherent.thy| for some
wenzelm@30172
   943
  examples.%
wenzelm@30172
   944
\end{isamarkuptext}%
wenzelm@30172
   945
\isamarkuptrue%
wenzelm@30172
   946
%
haftmann@31907
   947
\isamarkupsection{Checking and refuting propositions%
haftmann@31907
   948
}
haftmann@31907
   949
\isamarkuptrue%
haftmann@31907
   950
%
haftmann@31907
   951
\begin{isamarkuptext}%
haftmann@31907
   952
Identifying incorrect propositions usually involves evaluation of
haftmann@31907
   953
  particular assignments and systematic counter example search.  This
haftmann@31907
   954
  is supported by the following commands.
haftmann@31907
   955
haftmann@31907
   956
  \begin{matharray}{rcl}
wenzelm@40685
   957
    \indexdef{HOL}{command}{value}\hypertarget{command.HOL.value}{\hyperlink{command.HOL.value}{\mbox{\isa{\isacommand{value}}}}}\isa{{\isaliteral{22}{\isachardoublequote}}\isaliteral{5C3C5E7375703E}{}\isactrlsup {\isaliteral{2A}{\isacharasterisk}}{\isaliteral{22}{\isachardoublequote}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}context\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
   958
    \indexdef{HOL}{command}{quickcheck}\hypertarget{command.HOL.quickcheck}{\hyperlink{command.HOL.quickcheck}{\mbox{\isa{\isacommand{quickcheck}}}}}\isa{{\isaliteral{22}{\isachardoublequote}}\isaliteral{5C3C5E7375703E}{}\isactrlsup {\isaliteral{2A}{\isacharasterisk}}{\isaliteral{22}{\isachardoublequote}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}proof\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
   959
    \indexdef{HOL}{command}{quickcheck\_params}\hypertarget{command.HOL.quickcheck-params}{\hyperlink{command.HOL.quickcheck-params}{\mbox{\isa{\isacommand{quickcheck{\isaliteral{5F}{\isacharunderscore}}params}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}}
haftmann@31907
   960
  \end{matharray}
haftmann@31907
   961
haftmann@31907
   962
  \begin{rail}
haftmann@31907
   963
    'value' ( ( '[' name ']' ) ? ) modes? term
haftmann@31907
   964
    ;
haftmann@31907
   965
haftmann@31907
   966
    'quickcheck' ( ( '[' args ']' ) ? ) nat?
haftmann@31907
   967
    ;
haftmann@31907
   968
haftmann@31907
   969
    'quickcheck_params' ( ( '[' args ']' ) ? )
haftmann@31907
   970
    ;
haftmann@31907
   971
haftmann@31907
   972
    modes: '(' (name + ) ')'
haftmann@31907
   973
    ;
haftmann@31907
   974
haftmann@31907
   975
    args: ( name '=' value + ',' )
haftmann@31907
   976
    ;
haftmann@31907
   977
  \end{rail}
haftmann@31907
   978
haftmann@31907
   979
  \begin{description}
haftmann@31907
   980
haftmann@31907
   981
  \item \hyperlink{command.HOL.value}{\mbox{\isa{\isacommand{value}}}}~\isa{t} evaluates and prints a
haftmann@31907
   982
    term; optionally \isa{modes} can be specified, which are
haftmann@31907
   983
    appended to the current print mode (see also \cite{isabelle-ref}).
haftmann@31907
   984
    Internally, the evaluation is performed by registered evaluators,
haftmann@31907
   985
    which are invoked sequentially until a result is returned.
haftmann@31907
   986
    Alternatively a specific evaluator can be selected using square
haftmann@37419
   987
    brackets; typical evaluators use the current set of code equations
haftmann@37419
   988
    to normalize and include \isa{simp} for fully symbolic evaluation
haftmann@37419
   989
    using the simplifier, \isa{nbe} for \emph{normalization by evaluation}
haftmann@37419
   990
    and \emph{code} for code generation in SML.
haftmann@31907
   991
haftmann@31907
   992
  \item \hyperlink{command.HOL.quickcheck}{\mbox{\isa{\isacommand{quickcheck}}}} tests the current goal for
wenzelm@41185
   993
    counter examples using a series of assignments for its
haftmann@31907
   994
    free variables; by default the first subgoal is tested, an other
haftmann@31907
   995
    can be selected explicitly using an optional goal index.
wenzelm@41185
   996
    Assignments can be chosen exhausting the search space upto a given
wenzelm@41185
   997
    size or using a fixed number of random assignments in the search space.
wenzelm@41185
   998
    By default, quickcheck uses exhaustive testing.
haftmann@31907
   999
    A number of configuration options are supported for
haftmann@31907
  1000
    \hyperlink{command.HOL.quickcheck}{\mbox{\isa{\isacommand{quickcheck}}}}, notably:
haftmann@31907
  1001
haftmann@31907
  1002
    \begin{description}
haftmann@31907
  1003
wenzelm@41185
  1004
    \item[\isa{tester}] specifies how to explore the search space
wenzelm@41185
  1005
      (e.g. exhaustive or random).
wenzelm@41185
  1006
      An unknown configuration option is treated as an argument to tester,
wenzelm@41185
  1007
      making \isa{{\isaliteral{22}{\isachardoublequote}}tester\ {\isaliteral{3D}{\isacharequal}}{\isaliteral{22}{\isachardoublequote}}} optional.
wenzelm@40515
  1008
    \item[\isa{size}] specifies the maximum size of the search space
wenzelm@40515
  1009
    for assignment values.
haftmann@31907
  1010
wenzelm@40515
  1011
    \item[\isa{iterations}] sets how many sets of assignments are
wenzelm@40515
  1012
    generated for each particular size.
haftmann@31907
  1013
wenzelm@40685
  1014
    \item[\isa{no{\isaliteral{5F}{\isacharunderscore}}assms}] specifies whether assumptions in
wenzelm@40515
  1015
    structured proofs should be ignored.
wenzelm@40515
  1016
wenzelm@40515
  1017
    \item[\isa{timeout}] sets the time limit in seconds.
wenzelm@40515
  1018
wenzelm@40685
  1019
    \item[\isa{default{\isaliteral{5F}{\isacharunderscore}}type}] sets the type(s) generally used to
wenzelm@40515
  1020
    instantiate type variables.
wenzelm@40515
  1021
wenzelm@40515
  1022
    \item[\isa{report}] if set quickcheck reports how many tests
wenzelm@40515
  1023
    fulfilled the preconditions.
wenzelm@40515
  1024
wenzelm@40515
  1025
    \item[\isa{quiet}] if not set quickcheck informs about the
wenzelm@40515
  1026
    current size for assignment values.
wenzelm@40515
  1027
wenzelm@40515
  1028
    \item[\isa{expect}] can be used to check if the user's
wenzelm@40685
  1029
    expectation was met (\isa{no{\isaliteral{5F}{\isacharunderscore}}expectation}, \isa{no{\isaliteral{5F}{\isacharunderscore}}counterexample}, or \isa{counterexample}).
wenzelm@35352
  1030
haftmann@31907
  1031
    \end{description}
haftmann@31907
  1032
haftmann@31907
  1033
    These option can be given within square brackets.
haftmann@31907
  1034
wenzelm@40685
  1035
  \item \hyperlink{command.HOL.quickcheck-params}{\mbox{\isa{\isacommand{quickcheck{\isaliteral{5F}{\isacharunderscore}}params}}}} changes quickcheck
haftmann@31907
  1036
    configuration options persitently.
haftmann@31907
  1037
haftmann@31907
  1038
  \end{description}%
haftmann@31907
  1039
\end{isamarkuptext}%
haftmann@31907
  1040
\isamarkuptrue%
haftmann@31907
  1041
%
wenzelm@28788
  1042
\isamarkupsection{Unstructured case analysis and induction \label{sec:hol-induct-tac}%
wenzelm@26849
  1043
}
wenzelm@26849
  1044
\isamarkuptrue%
wenzelm@26849
  1045
%
wenzelm@26849
  1046
\begin{isamarkuptext}%
wenzelm@27124
  1047
The following tools of Isabelle/HOL support cases analysis and
wenzelm@27124
  1048
  induction in unstructured tactic scripts; see also
wenzelm@27124
  1049
  \secref{sec:cases-induct} for proper Isar versions of similar ideas.
wenzelm@26849
  1050
wenzelm@26849
  1051
  \begin{matharray}{rcl}
wenzelm@40685
  1052
    \indexdef{HOL}{method}{case\_tac}\hypertarget{method.HOL.case-tac}{\hyperlink{method.HOL.case-tac}{\mbox{\isa{case{\isaliteral{5F}{\isacharunderscore}}tac}}}}\isa{{\isaliteral{22}{\isachardoublequote}}\isaliteral{5C3C5E7375703E}{}\isactrlsup {\isaliteral{2A}{\isacharasterisk}}{\isaliteral{22}{\isachardoublequote}}} & : & \isa{method} \\
wenzelm@40685
  1053
    \indexdef{HOL}{method}{induct\_tac}\hypertarget{method.HOL.induct-tac}{\hyperlink{method.HOL.induct-tac}{\mbox{\isa{induct{\isaliteral{5F}{\isacharunderscore}}tac}}}}\isa{{\isaliteral{22}{\isachardoublequote}}\isaliteral{5C3C5E7375703E}{}\isactrlsup {\isaliteral{2A}{\isacharasterisk}}{\isaliteral{22}{\isachardoublequote}}} & : & \isa{method} \\
wenzelm@40685
  1054
    \indexdef{HOL}{method}{ind\_cases}\hypertarget{method.HOL.ind-cases}{\hyperlink{method.HOL.ind-cases}{\mbox{\isa{ind{\isaliteral{5F}{\isacharunderscore}}cases}}}}\isa{{\isaliteral{22}{\isachardoublequote}}\isaliteral{5C3C5E7375703E}{}\isactrlsup {\isaliteral{2A}{\isacharasterisk}}{\isaliteral{22}{\isachardoublequote}}} & : & \isa{method} \\
wenzelm@40685
  1055
    \indexdef{HOL}{command}{inductive\_cases}\hypertarget{command.HOL.inductive-cases}{\hyperlink{command.HOL.inductive-cases}{\mbox{\isa{\isacommand{inductive{\isaliteral{5F}{\isacharunderscore}}cases}}}}}\isa{{\isaliteral{22}{\isachardoublequote}}\isaliteral{5C3C5E7375703E}{}\isactrlsup {\isaliteral{2A}{\isacharasterisk}}{\isaliteral{22}{\isachardoublequote}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}local{\isaliteral{5F}{\isacharunderscore}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ local{\isaliteral{5F}{\isacharunderscore}}theory{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@26849
  1056
  \end{matharray}
wenzelm@26849
  1057
wenzelm@26849
  1058
  \begin{rail}
wenzelm@40516
  1059
    'case_tac' goalspec? term rule?
wenzelm@26849
  1060
    ;
wenzelm@40516
  1061
    'induct_tac' goalspec? (insts * 'and') rule?
wenzelm@26849
  1062
    ;
wenzelm@40516
  1063
    'ind_cases' (prop +) ('for' (name +)) ?
wenzelm@26849
  1064
    ;
wenzelm@40516
  1065
    'inductive_cases' (thmdecl? (prop +) + 'and')
wenzelm@26849
  1066
    ;
wenzelm@26849
  1067
wenzelm@26849
  1068
    rule: ('rule' ':' thmref)
wenzelm@26849
  1069
    ;
wenzelm@26849
  1070
  \end{rail}
wenzelm@26849
  1071
wenzelm@28788
  1072
  \begin{description}
wenzelm@26849
  1073
wenzelm@40685
  1074
  \item \hyperlink{method.HOL.case-tac}{\mbox{\isa{case{\isaliteral{5F}{\isacharunderscore}}tac}}} and \hyperlink{method.HOL.induct-tac}{\mbox{\isa{induct{\isaliteral{5F}{\isacharunderscore}}tac}}} admit
wenzelm@28788
  1075
  to reason about inductive types.  Rules are selected according to
wenzelm@28788
  1076
  the declarations by the \hyperlink{attribute.cases}{\mbox{\isa{cases}}} and \hyperlink{attribute.induct}{\mbox{\isa{induct}}}
wenzelm@28788
  1077
  attributes, cf.\ \secref{sec:cases-induct}.  The \hyperlink{command.HOL.datatype}{\mbox{\isa{\isacommand{datatype}}}} package already takes care of this.
wenzelm@27124
  1078
wenzelm@27124
  1079
  These unstructured tactics feature both goal addressing and dynamic
wenzelm@26849
  1080
  instantiation.  Note that named rule cases are \emph{not} provided
wenzelm@27124
  1081
  as would be by the proper \hyperlink{method.cases}{\mbox{\isa{cases}}} and \hyperlink{method.induct}{\mbox{\isa{induct}}} proof
wenzelm@40685
  1082
  methods (see \secref{sec:cases-induct}).  Unlike the \hyperlink{method.induct}{\mbox{\isa{induct}}} method, \hyperlink{method.induct-tac}{\mbox{\isa{induct{\isaliteral{5F}{\isacharunderscore}}tac}}} does not handle structured rule
wenzelm@27124
  1083
  statements, only the compact object-logic conclusion of the subgoal
wenzelm@27124
  1084
  being addressed.
wenzelm@26849
  1085
  
wenzelm@40685
  1086
  \item \hyperlink{method.HOL.ind-cases}{\mbox{\isa{ind{\isaliteral{5F}{\isacharunderscore}}cases}}} and \hyperlink{command.HOL.inductive-cases}{\mbox{\isa{\isacommand{inductive{\isaliteral{5F}{\isacharunderscore}}cases}}}} provide an interface to the internal \verb|mk_cases| operation.  Rules are simplified in an unrestricted
wenzelm@26861
  1087
  forward manner.
wenzelm@26849
  1088
wenzelm@40685
  1089
  While \hyperlink{method.HOL.ind-cases}{\mbox{\isa{ind{\isaliteral{5F}{\isacharunderscore}}cases}}} is a proof method to apply the
wenzelm@40685
  1090
  result immediately as elimination rules, \hyperlink{command.HOL.inductive-cases}{\mbox{\isa{\isacommand{inductive{\isaliteral{5F}{\isacharunderscore}}cases}}}} provides case split theorems at the theory level
wenzelm@40685
  1091
  for later use.  The \hyperlink{keyword.for}{\mbox{\isa{\isakeyword{for}}}} argument of the \hyperlink{method.HOL.ind-cases}{\mbox{\isa{ind{\isaliteral{5F}{\isacharunderscore}}cases}}} method allows to specify a list of variables that should
wenzelm@26849
  1092
  be generalized before applying the resulting rule.
wenzelm@26849
  1093
wenzelm@28788
  1094
  \end{description}%
wenzelm@26849
  1095
\end{isamarkuptext}%
wenzelm@26849
  1096
\isamarkuptrue%
wenzelm@26849
  1097
%
wenzelm@26849
  1098
\isamarkupsection{Executable code%
wenzelm@26849
  1099
}
wenzelm@26849
  1100
\isamarkuptrue%
wenzelm@26849
  1101
%
wenzelm@26849
  1102
\begin{isamarkuptext}%
wenzelm@26849
  1103
Isabelle/Pure provides two generic frameworks to support code
wenzelm@26849
  1104
  generation from executable specifications.  Isabelle/HOL
wenzelm@26849
  1105
  instantiates these mechanisms in a way that is amenable to end-user
wenzelm@26849
  1106
  applications.
wenzelm@26849
  1107
haftmann@37397
  1108
  \medskip One framework generates code from functional programs
haftmann@37397
  1109
  (including overloading using type classes) to SML \cite{SML}, OCaml
haftmann@39048
  1110
  \cite{OCaml}, Haskell \cite{haskell-revised-report} and Scala
haftmann@39048
  1111
  \cite{scala-overview-tech-report}.
haftmann@37397
  1112
  Conceptually, code generation is split up in three steps:
haftmann@37397
  1113
  \emph{selection} of code theorems, \emph{translation} into an
haftmann@37397
  1114
  abstract executable view and \emph{serialization} to a specific
haftmann@37397
  1115
  \emph{target language}.  Inductive specifications can be executed
haftmann@37397
  1116
  using the predicate compiler which operates within HOL.
haftmann@37397
  1117
  See \cite{isabelle-codegen} for an introduction.
haftmann@37397
  1118
haftmann@37397
  1119
  \begin{matharray}{rcl}
wenzelm@40685
  1120
    \indexdef{HOL}{command}{export\_code}\hypertarget{command.HOL.export-code}{\hyperlink{command.HOL.export-code}{\mbox{\isa{\isacommand{export{\isaliteral{5F}{\isacharunderscore}}code}}}}}\isa{{\isaliteral{22}{\isachardoublequote}}\isaliteral{5C3C5E7375703E}{}\isactrlsup {\isaliteral{2A}{\isacharasterisk}}{\isaliteral{22}{\isachardoublequote}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}context\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}{\isaliteral{22}{\isachardoublequote}}} \\
haftmann@37397
  1121
    \indexdef{HOL}{attribute}{code}\hypertarget{attribute.HOL.code}{\hyperlink{attribute.HOL.code}{\mbox{\isa{code}}}} & : & \isa{attribute} \\
wenzelm@40685
  1122
    \indexdef{HOL}{command}{code\_abort}\hypertarget{command.HOL.code-abort}{\hyperlink{command.HOL.code-abort}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}abort}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
  1123
    \indexdef{HOL}{command}{code\_datatype}\hypertarget{command.HOL.code-datatype}{\hyperlink{command.HOL.code-datatype}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}datatype}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
  1124
    \indexdef{HOL}{command}{print\_codesetup}\hypertarget{command.HOL.print-codesetup}{\hyperlink{command.HOL.print-codesetup}{\mbox{\isa{\isacommand{print{\isaliteral{5F}{\isacharunderscore}}codesetup}}}}}\isa{{\isaliteral{22}{\isachardoublequote}}\isaliteral{5C3C5E7375703E}{}\isactrlsup {\isaliteral{2A}{\isacharasterisk}}{\isaliteral{22}{\isachardoublequote}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}context\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
  1125
    \indexdef{HOL}{attribute}{code\_inline}\hypertarget{attribute.HOL.code-inline}{\hyperlink{attribute.HOL.code-inline}{\mbox{\isa{code{\isaliteral{5F}{\isacharunderscore}}inline}}}} & : & \isa{attribute} \\
wenzelm@40685
  1126
    \indexdef{HOL}{attribute}{code\_post}\hypertarget{attribute.HOL.code-post}{\hyperlink{attribute.HOL.code-post}{\mbox{\isa{code{\isaliteral{5F}{\isacharunderscore}}post}}}} & : & \isa{attribute} \\
wenzelm@40685
  1127
    \indexdef{HOL}{command}{print\_codeproc}\hypertarget{command.HOL.print-codeproc}{\hyperlink{command.HOL.print-codeproc}{\mbox{\isa{\isacommand{print{\isaliteral{5F}{\isacharunderscore}}codeproc}}}}}\isa{{\isaliteral{22}{\isachardoublequote}}\isaliteral{5C3C5E7375703E}{}\isactrlsup {\isaliteral{2A}{\isacharasterisk}}{\isaliteral{22}{\isachardoublequote}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}context\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
  1128
    \indexdef{HOL}{command}{code\_thms}\hypertarget{command.HOL.code-thms}{\hyperlink{command.HOL.code-thms}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}thms}}}}}\isa{{\isaliteral{22}{\isachardoublequote}}\isaliteral{5C3C5E7375703E}{}\isactrlsup {\isaliteral{2A}{\isacharasterisk}}{\isaliteral{22}{\isachardoublequote}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}context\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
  1129
    \indexdef{HOL}{command}{code\_deps}\hypertarget{command.HOL.code-deps}{\hyperlink{command.HOL.code-deps}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}deps}}}}}\isa{{\isaliteral{22}{\isachardoublequote}}\isaliteral{5C3C5E7375703E}{}\isactrlsup {\isaliteral{2A}{\isacharasterisk}}{\isaliteral{22}{\isachardoublequote}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}context\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
  1130
    \indexdef{HOL}{command}{code\_const}\hypertarget{command.HOL.code-const}{\hyperlink{command.HOL.code-const}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}const}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
  1131
    \indexdef{HOL}{command}{code\_type}\hypertarget{command.HOL.code-type}{\hyperlink{command.HOL.code-type}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}type}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
  1132
    \indexdef{HOL}{command}{code\_class}\hypertarget{command.HOL.code-class}{\hyperlink{command.HOL.code-class}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}class}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
  1133
    \indexdef{HOL}{command}{code\_instance}\hypertarget{command.HOL.code-instance}{\hyperlink{command.HOL.code-instance}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}instance}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
  1134
    \indexdef{HOL}{command}{code\_reserved}\hypertarget{command.HOL.code-reserved}{\hyperlink{command.HOL.code-reserved}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}reserved}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
  1135
    \indexdef{HOL}{command}{code\_monad}\hypertarget{command.HOL.code-monad}{\hyperlink{command.HOL.code-monad}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}monad}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
  1136
    \indexdef{HOL}{command}{code\_include}\hypertarget{command.HOL.code-include}{\hyperlink{command.HOL.code-include}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}include}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
  1137
    \indexdef{HOL}{command}{code\_modulename}\hypertarget{command.HOL.code-modulename}{\hyperlink{command.HOL.code-modulename}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}modulename}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
  1138
    \indexdef{HOL}{command}{code\_reflect}\hypertarget{command.HOL.code-reflect}{\hyperlink{command.HOL.code-reflect}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}reflect}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}}
haftmann@37397
  1139
  \end{matharray}
haftmann@37397
  1140
haftmann@37397
  1141
  \begin{rail}
wenzelm@40516
  1142
     'export_code' ( constexpr + ) \\
wenzelm@40516
  1143
       ( ( 'in' target ( 'module_name' string ) ? \\
haftmann@37820
  1144
        ( 'file' ( string | '-' ) ) ? ( '(' args ')' ) ?) + ) ?
haftmann@37397
  1145
    ;
haftmann@37397
  1146
haftmann@37397
  1147
    const: term
haftmann@37397
  1148
    ;
haftmann@37397
  1149
haftmann@40959
  1150
    constexpr: ( const | 'name._' | '_' )
haftmann@37397
  1151
    ;
haftmann@37397
  1152
haftmann@37397
  1153
    typeconstructor: nameref
haftmann@37397
  1154
    ;
haftmann@37397
  1155
haftmann@37397
  1156
    class: nameref
haftmann@37397
  1157
    ;
haftmann@37397
  1158
haftmann@39048
  1159
    target: 'SML' | 'OCaml' | 'Haskell' | 'Scala'
haftmann@37397
  1160
    ;
haftmann@37397
  1161
haftmann@38706
  1162
    'code' ( 'del' | 'abstype' | 'abstract' ) ?
haftmann@37397
  1163
    ;
haftmann@37397
  1164
wenzelm@40516
  1165
    'code_abort' ( const + )
haftmann@37397
  1166
    ;
haftmann@37397
  1167
wenzelm@40516
  1168
    'code_datatype' ( const + )
haftmann@37397
  1169
    ;
haftmann@37397
  1170
haftmann@37397
  1171
    'code_inline' ( 'del' ) ?
haftmann@37397
  1172
    ;
haftmann@37397
  1173
haftmann@37397
  1174
    'code_post' ( 'del' ) ?
haftmann@37397
  1175
    ;
haftmann@37397
  1176
wenzelm@40516
  1177
    'code_thms' ( constexpr + ) ?
haftmann@37397
  1178
    ;
haftmann@37397
  1179
wenzelm@40516
  1180
    'code_deps' ( constexpr + ) ?
haftmann@37397
  1181
    ;
haftmann@37397
  1182
wenzelm@40516
  1183
    'code_const' (const + 'and') \\
haftmann@37397
  1184
      ( ( '(' target ( syntax ? + 'and' ) ')' ) + )
haftmann@37397
  1185
    ;
haftmann@37397
  1186
wenzelm@40516
  1187
    'code_type' (typeconstructor + 'and') \\
haftmann@37397
  1188
      ( ( '(' target ( syntax ? + 'and' ) ')' ) + )
haftmann@37397
  1189
    ;
haftmann@37397
  1190
wenzelm@40516
  1191
    'code_class' (class + 'and') \\
haftmann@37397
  1192
      ( ( '(' target \\ ( string ? + 'and' ) ')' ) + )
haftmann@37397
  1193
    ;
haftmann@37397
  1194
wenzelm@40516
  1195
    'code_instance' (( typeconstructor '::' class ) + 'and') \\
haftmann@37397
  1196
      ( ( '(' target ( '-' ? + 'and' ) ')' ) + )
haftmann@37397
  1197
    ;
haftmann@37397
  1198
wenzelm@40516
  1199
    'code_reserved' target ( string + )
haftmann@37397
  1200
    ;
haftmann@37397
  1201
wenzelm@40516
  1202
    'code_monad' const const target
haftmann@37397
  1203
    ;
haftmann@37397
  1204
wenzelm@40516
  1205
    'code_include' target ( string ( string | '-') )
haftmann@37397
  1206
    ;
haftmann@37397
  1207
wenzelm@40516
  1208
    'code_modulename' target ( ( string string ) + )
haftmann@37397
  1209
    ;
haftmann@37397
  1210
haftmann@40957
  1211
    'code_reflect' string \\
haftmann@40959
  1212
      ( 'datatypes' ( string '=' ( '_' | ( string + '|' ) + 'and' ) ) ) ? \\
haftmann@39832
  1213
      ( 'functions' ( string + ) ) ? ( 'file' string ) ?
haftmann@39832
  1214
    ;
haftmann@39832
  1215
haftmann@37397
  1216
    syntax: string | ( 'infix' | 'infixl' | 'infixr' ) nat string
haftmann@37397
  1217
    ;
haftmann@37397
  1218
haftmann@37397
  1219
  \end{rail}
haftmann@37397
  1220
haftmann@37397
  1221
  \begin{description}
haftmann@37397
  1222
wenzelm@40685
  1223
  \item \hyperlink{command.HOL.export-code}{\mbox{\isa{\isacommand{export{\isaliteral{5F}{\isacharunderscore}}code}}}} generates code for a given list
haftmann@39832
  1224
  of constants in the specified target language(s).  If no
haftmann@39832
  1225
  serialization instruction is given, only abstract code is generated
haftmann@39832
  1226
  internally.
haftmann@37397
  1227
haftmann@37397
  1228
  Constants may be specified by giving them literally, referring to
wenzelm@40685
  1229
  all executable contants within a certain theory by giving \isa{{\isaliteral{22}{\isachardoublequote}}name{\isaliteral{2E}{\isachardot}}{\isaliteral{2A}{\isacharasterisk}}{\isaliteral{22}{\isachardoublequote}}}, or referring to \emph{all} executable constants currently
wenzelm@40685
  1230
  available by giving \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{2A}{\isacharasterisk}}{\isaliteral{22}{\isachardoublequote}}}.
haftmann@37397
  1231
haftmann@37397
  1232
  By default, for each involved theory one corresponding name space
haftmann@37397
  1233
  module is generated.  Alternativly, a module name may be specified
wenzelm@40685
  1234
  after the \hyperlink{keyword.module-name}{\mbox{\isa{\isakeyword{module{\isaliteral{5F}{\isacharunderscore}}name}}}} keyword; then \emph{all} code is
haftmann@37397
  1235
  placed in this module.
haftmann@37397
  1236
haftmann@39832
  1237
  For \emph{SML}, \emph{OCaml} and \emph{Scala} the file specification
haftmann@39832
  1238
  refers to a single file; for \emph{Haskell}, it refers to a whole
haftmann@39832
  1239
  directory, where code is generated in multiple files reflecting the
haftmann@39832
  1240
  module hierarchy.  Omitting the file specification denotes standard
haftmann@37748
  1241
  output.
haftmann@37397
  1242
haftmann@37397
  1243
  Serializers take an optional list of arguments in parentheses.  For
wenzelm@40685
  1244
  \emph{SML} and \emph{OCaml}, ``\isa{no{\isaliteral{5F}{\isacharunderscore}}signatures}`` omits
haftmann@37397
  1245
  explicit module signatures.
haftmann@37397
  1246
  
haftmann@39832
  1247
  For \emph{Haskell} a module name prefix may be given using the
wenzelm@40685
  1248
  ``\isa{{\isaliteral{22}{\isachardoublequote}}root{\isaliteral{3A}{\isacharcolon}}{\isaliteral{22}{\isachardoublequote}}}'' argument; ``\isa{string{\isaliteral{5F}{\isacharunderscore}}classes}'' adds a
haftmann@39832
  1249
  ``\verb|deriving (Read, Show)|'' clause to each appropriate
haftmann@39832
  1250
  datatype declaration.
haftmann@37397
  1251
haftmann@37397
  1252
  \item \hyperlink{attribute.HOL.code}{\mbox{\isa{code}}} explicitly selects (or with option
wenzelm@40685
  1253
  ``\isa{{\isaliteral{22}{\isachardoublequote}}del{\isaliteral{22}{\isachardoublequote}}}'' deselects) a code equation for code generation.
haftmann@38706
  1254
  Usually packages introducing code equations provide a reasonable
wenzelm@40685
  1255
  default setup for selection.  Variants \isa{{\isaliteral{22}{\isachardoublequote}}code\ abstype{\isaliteral{22}{\isachardoublequote}}} and
wenzelm@40685
  1256
  \isa{{\isaliteral{22}{\isachardoublequote}}code\ abstract{\isaliteral{22}{\isachardoublequote}}} declare abstract datatype certificates or
haftmann@38706
  1257
  code equations on abstract datatype representations respectively.
haftmann@37397
  1258
wenzelm@40685
  1259
  \item \hyperlink{command.HOL.code-abort}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}abort}}}} declares constants which are not
haftmann@39832
  1260
  required to have a definition by means of code equations; if needed
haftmann@39832
  1261
  these are implemented by program abort instead.
haftmann@37397
  1262
wenzelm@40685
  1263
  \item \hyperlink{command.HOL.code-datatype}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}datatype}}}} specifies a constructor set
haftmann@37397
  1264
  for a logical type.
haftmann@37397
  1265
wenzelm@40685
  1266
  \item \hyperlink{command.HOL.print-codesetup}{\mbox{\isa{\isacommand{print{\isaliteral{5F}{\isacharunderscore}}codesetup}}}} gives an overview on
haftmann@37397
  1267
  selected code equations and code generator datatypes.
haftmann@37397
  1268
wenzelm@40685
  1269
  \item \hyperlink{attribute.HOL.code-inline}{\mbox{\isa{code{\isaliteral{5F}{\isacharunderscore}}inline}}} declares (or with option
wenzelm@40685
  1270
  ``\isa{{\isaliteral{22}{\isachardoublequote}}del{\isaliteral{22}{\isachardoublequote}}}'' removes) inlining theorems which are applied as
haftmann@39832
  1271
  rewrite rules to any code equation during preprocessing.
haftmann@37397
  1272
wenzelm@40685
  1273
  \item \hyperlink{attribute.HOL.code-post}{\mbox{\isa{code{\isaliteral{5F}{\isacharunderscore}}post}}} declares (or with option ``\isa{{\isaliteral{22}{\isachardoublequote}}del{\isaliteral{22}{\isachardoublequote}}}'' removes) theorems which are applied as rewrite rules to any
haftmann@39832
  1274
  result of an evaluation.
haftmann@37397
  1275
wenzelm@40685
  1276
  \item \hyperlink{command.HOL.print-codeproc}{\mbox{\isa{\isacommand{print{\isaliteral{5F}{\isacharunderscore}}codeproc}}}} prints the setup of the code
haftmann@39832
  1277
  generator preprocessor.
haftmann@37397
  1278
wenzelm@40685
  1279
  \item \hyperlink{command.HOL.code-thms}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}thms}}}} prints a list of theorems
haftmann@37397
  1280
  representing the corresponding program containing all given
haftmann@37397
  1281
  constants after preprocessing.
haftmann@37397
  1282
wenzelm@40685
  1283
  \item \hyperlink{command.HOL.code-deps}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}deps}}}} visualizes dependencies of
haftmann@37397
  1284
  theorems representing the corresponding program containing all given
haftmann@37397
  1285
  constants after preprocessing.
haftmann@37397
  1286
wenzelm@40685
  1287
  \item \hyperlink{command.HOL.code-const}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}const}}}} associates a list of constants
haftmann@37397
  1288
  with target-specific serializations; omitting a serialization
haftmann@37397
  1289
  deletes an existing serialization.
haftmann@37397
  1290
wenzelm@40685
  1291
  \item \hyperlink{command.HOL.code-type}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}type}}}} associates a list of type
haftmann@37397
  1292
  constructors with target-specific serializations; omitting a
haftmann@37397
  1293
  serialization deletes an existing serialization.
haftmann@37397
  1294
wenzelm@40685
  1295
  \item \hyperlink{command.HOL.code-class}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}class}}}} associates a list of classes
haftmann@37397
  1296
  with target-specific class names; omitting a serialization deletes
haftmann@37397
  1297
  an existing serialization.  This applies only to \emph{Haskell}.
haftmann@37397
  1298
wenzelm@40685
  1299
  \item \hyperlink{command.HOL.code-instance}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}instance}}}} declares a list of type
haftmann@37397
  1300
  constructor / class instance relations as ``already present'' for a
wenzelm@40685
  1301
  given target.  Omitting a ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{2D}{\isacharminus}}{\isaliteral{22}{\isachardoublequote}}}'' deletes an existing
haftmann@37397
  1302
  ``already present'' declaration.  This applies only to
haftmann@37397
  1303
  \emph{Haskell}.
haftmann@37397
  1304
wenzelm@40685
  1305
  \item \hyperlink{command.HOL.code-reserved}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}reserved}}}} declares a list of names as
haftmann@37397
  1306
  reserved for a given target, preventing it to be shadowed by any
haftmann@37397
  1307
  generated code.
haftmann@37397
  1308
wenzelm@40685
  1309
  \item \hyperlink{command.HOL.code-monad}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}monad}}}} provides an auxiliary mechanism
haftmann@37397
  1310
  to generate monadic code for Haskell.
haftmann@37397
  1311
wenzelm@40685
  1312
  \item \hyperlink{command.HOL.code-include}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}include}}}} adds arbitrary named content
wenzelm@40685
  1313
  (``include'') to generated code.  A ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{2D}{\isacharminus}}{\isaliteral{22}{\isachardoublequote}}}'' as last argument
haftmann@37397
  1314
  will remove an already added ``include''.
haftmann@37397
  1315
wenzelm@40685
  1316
  \item \hyperlink{command.HOL.code-modulename}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}modulename}}}} declares aliasings from one
haftmann@37397
  1317
  module name onto another.
haftmann@37397
  1318
wenzelm@40685
  1319
  \item \hyperlink{command.HOL.code-reflect}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}reflect}}}} without a ``\isa{{\isaliteral{22}{\isachardoublequote}}file{\isaliteral{22}{\isachardoublequote}}}''
haftmann@39832
  1320
  argument compiles code into the system runtime environment and
haftmann@39832
  1321
  modifies the code generator setup that future invocations of system
wenzelm@40685
  1322
  runtime code generation referring to one of the ``\isa{{\isaliteral{22}{\isachardoublequote}}datatypes{\isaliteral{22}{\isachardoublequote}}}'' or ``\isa{{\isaliteral{22}{\isachardoublequote}}functions{\isaliteral{22}{\isachardoublequote}}}'' entities use these precompiled
wenzelm@40685
  1323
  entities.  With a ``\isa{{\isaliteral{22}{\isachardoublequote}}file{\isaliteral{22}{\isachardoublequote}}}'' argument, the corresponding code
haftmann@39832
  1324
  is generated into that specified file without modifying the code
haftmann@39832
  1325
  generator setup.
haftmann@39832
  1326
haftmann@37397
  1327
  \end{description}
haftmann@37397
  1328
haftmann@39832
  1329
  The other framework generates code from both functional and
haftmann@39832
  1330
  relational programs to SML.  See \cite{isabelle-HOL} for further
haftmann@39832
  1331
  information (this actually covers the new-style theory format as
haftmann@39832
  1332
  well).
wenzelm@26849
  1333
wenzelm@26849
  1334
  \begin{matharray}{rcl}
wenzelm@40685
  1335
    \indexdef{HOL}{command}{code\_module}\hypertarget{command.HOL.code-module}{\hyperlink{command.HOL.code-module}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}module}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
  1336
    \indexdef{HOL}{command}{code\_library}\hypertarget{command.HOL.code-library}{\hyperlink{command.HOL.code-library}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}library}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
  1337
    \indexdef{HOL}{command}{consts\_code}\hypertarget{command.HOL.consts-code}{\hyperlink{command.HOL.consts-code}{\mbox{\isa{\isacommand{consts{\isaliteral{5F}{\isacharunderscore}}code}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
  1338
    \indexdef{HOL}{command}{types\_code}\hypertarget{command.HOL.types-code}{\hyperlink{command.HOL.types-code}{\mbox{\isa{\isacommand{types{\isaliteral{5F}{\isacharunderscore}}code}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\  
wenzelm@28788
  1339
    \indexdef{HOL}{attribute}{code}\hypertarget{attribute.HOL.code}{\hyperlink{attribute.HOL.code}{\mbox{\isa{code}}}} & : & \isa{attribute} \\
wenzelm@26849
  1340
  \end{matharray}
wenzelm@26849
  1341
wenzelm@26849
  1342
  \begin{rail}
wenzelm@40516
  1343
  ( 'code_module' | 'code_library' ) modespec ? name ? \\
wenzelm@26849
  1344
    ( 'file' name ) ? ( 'imports' ( name + ) ) ? \\
wenzelm@26849
  1345
    'contains' ( ( name '=' term ) + | term + )
wenzelm@26849
  1346
  ;
wenzelm@26849
  1347
wenzelm@26849
  1348
  modespec: '(' ( name * ) ')'
wenzelm@26849
  1349
  ;
wenzelm@26849
  1350
wenzelm@40516
  1351
  'consts_code' (codespec +)
wenzelm@26849
  1352
  ;
wenzelm@26849
  1353
wenzelm@26849
  1354
  codespec: const template attachment ?
wenzelm@26849
  1355
  ;
wenzelm@26849
  1356
wenzelm@40516
  1357
  'types_code' (tycodespec +)
wenzelm@26849
  1358
  ;
wenzelm@26849
  1359
wenzelm@26849
  1360
  tycodespec: name template attachment ?
wenzelm@26849
  1361
  ;
wenzelm@26849
  1362
wenzelm@26849
  1363
  const: term
wenzelm@26849
  1364
  ;
wenzelm@26849
  1365
wenzelm@26849
  1366
  template: '(' string ')'
wenzelm@26849
  1367
  ;
wenzelm@26849
  1368
wenzelm@26849
  1369
  attachment: 'attach' modespec ? verblbrace text verbrbrace
wenzelm@26849
  1370
  ;
wenzelm@26849
  1371
wenzelm@26849
  1372
  'code' (name)?
wenzelm@26849
  1373
  ;
haftmann@37397
  1374
  \end{rail}%
wenzelm@26849
  1375
\end{isamarkuptext}%
wenzelm@26849
  1376
\isamarkuptrue%
wenzelm@26849
  1377
%
wenzelm@27047
  1378
\isamarkupsection{Definition by specification \label{sec:hol-specification}%
wenzelm@27047
  1379
}
wenzelm@27047
  1380
\isamarkuptrue%
wenzelm@27047
  1381
%
wenzelm@27047
  1382
\begin{isamarkuptext}%
wenzelm@27047
  1383
\begin{matharray}{rcl}
wenzelm@40685
  1384
    \indexdef{HOL}{command}{specification}\hypertarget{command.HOL.specification}{\hyperlink{command.HOL.specification}{\mbox{\isa{\isacommand{specification}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ proof{\isaliteral{28}{\isacharparenleft}}prove{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@40685
  1385
    \indexdef{HOL}{command}{ax\_specification}\hypertarget{command.HOL.ax-specification}{\hyperlink{command.HOL.ax-specification}{\mbox{\isa{\isacommand{ax{\isaliteral{5F}{\isacharunderscore}}specification}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ proof{\isaliteral{28}{\isacharparenleft}}prove{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequote}}} \\
wenzelm@27047
  1386
  \end{matharray}
wenzelm@27047
  1387
wenzelm@27047
  1388
  \begin{rail}
wenzelm@40516
  1389
  ('specification' | 'ax_specification') '(' (decl +) ')' \\ (thmdecl? prop +)
wenzelm@27047
  1390
  ;
wenzelm@27047
  1391
  decl: ((name ':')? term '(' 'overloaded' ')'?)
wenzelm@27047
  1392
  \end{rail}
wenzelm@27047
  1393
wenzelm@28788
  1394
  \begin{description}
wenzelm@27047
  1395
wenzelm@40685
  1396
  \item \hyperlink{command.HOL.specification}{\mbox{\isa{\isacommand{specification}}}}~\isa{{\isaliteral{22}{\isachardoublequote}}decls\ {\isaliteral{5C3C7068693E}{\isasymphi}}{\isaliteral{22}{\isachardoublequote}}} sets up a
wenzelm@27047
  1397
  goal stating the existence of terms with the properties specified to
wenzelm@27047
  1398
  hold for the constants given in \isa{decls}.  After finishing the
wenzelm@27047
  1399
  proof, the theory will be augmented with definitions for the given
wenzelm@27047
  1400
  constants, as well as with theorems stating the properties for these
wenzelm@27047
  1401
  constants.
wenzelm@27047
  1402
wenzelm@40685
  1403
  \item \hyperlink{command.HOL.ax-specification}{\mbox{\isa{\isacommand{ax{\isaliteral{5F}{\isacharunderscore}}specification}}}}~\isa{{\isaliteral{22}{\isachardoublequote}}decls\ {\isaliteral{5C3C7068693E}{\isasymphi}}{\isaliteral{22}{\isachardoublequote}}} sets up
wenzelm@28788
  1404
  a goal stating the existence of terms with the properties specified
wenzelm@28788
  1405
  to hold for the constants given in \isa{decls}.  After finishing
wenzelm@28788
  1406
  the proof, the theory will be augmented with axioms expressing the
wenzelm@28788
  1407
  properties given in the first place.
wenzelm@27047
  1408
wenzelm@28788
  1409
  \item \isa{decl} declares a constant to be defined by the
wenzelm@27047
  1410
  specification given.  The definition for the constant \isa{c} is
wenzelm@40685
  1411
  bound to the name \isa{c{\isaliteral{5F}{\isacharunderscore}}def} unless a theorem name is given in
wenzelm@27047
  1412
  the declaration.  Overloaded constants should be declared as such.
wenzelm@27047
  1413
wenzelm@28788
  1414
  \end{description}
wenzelm@27047
  1415
wenzelm@40685
  1416
  Whether to use \hyperlink{command.HOL.specification}{\mbox{\isa{\isacommand{specification}}}} or \hyperlink{command.HOL.ax-specification}{\mbox{\isa{\isacommand{ax{\isaliteral{5F}{\isacharunderscore}}specification}}}} is to some extent a matter of style.  \hyperlink{command.HOL.specification}{\mbox{\isa{\isacommand{specification}}}} introduces no new axioms, and so by
wenzelm@40685
  1417
  construction cannot introduce inconsistencies, whereas \hyperlink{command.HOL.ax-specification}{\mbox{\isa{\isacommand{ax{\isaliteral{5F}{\isacharunderscore}}specification}}}} does introduce axioms, but only after the
wenzelm@27047
  1418
  user has explicitly proven it to be safe.  A practical issue must be
wenzelm@27047
  1419
  considered, though: After introducing two constants with the same
wenzelm@27047
  1420
  properties using \hyperlink{command.HOL.specification}{\mbox{\isa{\isacommand{specification}}}}, one can prove
wenzelm@27047
  1421
  that the two constants are, in fact, equal.  If this might be a
wenzelm@40685
  1422
  problem, one should use \hyperlink{command.HOL.ax-specification}{\mbox{\isa{\isacommand{ax{\isaliteral{5F}{\isacharunderscore}}specification}}}}.%
wenzelm@27047
  1423
\end{isamarkuptext}%
wenzelm@27047
  1424
\isamarkuptrue%
wenzelm@27047
  1425
%
wenzelm@26849
  1426
\isadelimtheory
wenzelm@26849
  1427
%
wenzelm@26849
  1428
\endisadelimtheory
wenzelm@26849
  1429
%
wenzelm@26849
  1430
\isatagtheory
wenzelm@26840
  1431
\isacommand{end}\isamarkupfalse%
wenzelm@26840
  1432
%
wenzelm@26840
  1433
\endisatagtheory
wenzelm@26840
  1434
{\isafoldtheory}%
wenzelm@26840
  1435
%
wenzelm@26840
  1436
\isadelimtheory
wenzelm@26840
  1437
%
wenzelm@26840
  1438
\endisadelimtheory
wenzelm@26849
  1439
\isanewline
wenzelm@26840
  1440
\end{isabellebody}%
wenzelm@26840
  1441
%%% Local Variables:
wenzelm@26840
  1442
%%% mode: latex
wenzelm@26840
  1443
%%% TeX-master: "root"
wenzelm@26840
  1444
%%% End: