doc-src/IsarRef/Thy/document/HOL_Specific.tex
author blanchet
Fri, 27 May 2011 10:41:09 +0200
changeset 43881 665623e695ea
parent 43576 528a2ba8fa74
child 44141 bc72c1ccc89e
permissions -rw-r--r--
document new "try"
     1 %
     2 \begin{isabellebody}%
     3 \def\isabellecontext{HOL{\isaliteral{5F}{\isacharunderscore}}Specific}%
     4 %
     5 \isadelimtheory
     6 %
     7 \endisadelimtheory
     8 %
     9 \isatagtheory
    10 \isacommand{theory}\isamarkupfalse%
    11 \ HOL{\isaliteral{5F}{\isacharunderscore}}Specific\isanewline
    12 \isakeyword{imports}\ Base\ Main\isanewline
    13 \isakeyword{begin}%
    14 \endisatagtheory
    15 {\isafoldtheory}%
    16 %
    17 \isadelimtheory
    18 %
    19 \endisadelimtheory
    20 %
    21 \isamarkupchapter{Isabelle/HOL \label{ch:hol}%
    22 }
    23 \isamarkuptrue%
    24 %
    25 \isamarkupsection{Typedef axiomatization \label{sec:hol-typedef}%
    26 }
    27 \isamarkuptrue%
    28 %
    29 \begin{isamarkuptext}%
    30 \begin{matharray}{rcl}
    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}}} \\
    32   \end{matharray}
    33 
    34   \begin{railoutput}
    35 \rail@begin{2}{}
    36 \rail@term{\hyperlink{command.HOL.typedef}{\mbox{\isa{\isacommand{typedef}}}}}[]
    37 \rail@bar
    38 \rail@nextbar{1}
    39 \rail@nont{\isa{altname}}[]
    40 \rail@endbar
    41 \rail@nont{\isa{abstype}}[]
    42 \rail@term{\isa{{\isaliteral{3D}{\isacharequal}}}}[]
    43 \rail@nont{\isa{repset}}[]
    44 \rail@end
    45 \rail@begin{3}{\isa{altname}}
    46 \rail@term{\isa{{\isaliteral{28}{\isacharparenleft}}}}[]
    47 \rail@bar
    48 \rail@nont{\hyperlink{syntax.name}{\mbox{\isa{name}}}}[]
    49 \rail@nextbar{1}
    50 \rail@term{\isa{\isakeyword{open}}}[]
    51 \rail@nextbar{2}
    52 \rail@term{\isa{\isakeyword{open}}}[]
    53 \rail@nont{\hyperlink{syntax.name}{\mbox{\isa{name}}}}[]
    54 \rail@endbar
    55 \rail@term{\isa{{\isaliteral{29}{\isacharparenright}}}}[]
    56 \rail@end
    57 \rail@begin{2}{\isa{abstype}}
    58 \rail@nont{\hyperlink{syntax.typespec-sorts}{\mbox{\isa{typespec{\isaliteral{5F}{\isacharunderscore}}sorts}}}}[]
    59 \rail@bar
    60 \rail@nextbar{1}
    61 \rail@nont{\hyperlink{syntax.mixfix}{\mbox{\isa{mixfix}}}}[]
    62 \rail@endbar
    63 \rail@end
    64 \rail@begin{2}{\isa{repset}}
    65 \rail@nont{\hyperlink{syntax.term}{\mbox{\isa{term}}}}[]
    66 \rail@bar
    67 \rail@nextbar{1}
    68 \rail@term{\isa{\isakeyword{morphisms}}}[]
    69 \rail@nont{\hyperlink{syntax.name}{\mbox{\isa{name}}}}[]
    70 \rail@nont{\hyperlink{syntax.name}{\mbox{\isa{name}}}}[]
    71 \rail@endbar
    72 \rail@end
    73 \end{railoutput}
    74 
    75 
    76   \begin{description}
    77 
    78   \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}}}
    79   axiomatizes a Gordon/HOL-style type definition in the background
    80   theory of the current context, depending on a non-emptiness result
    81   of the set \isa{A} (which needs to be proven interactively).
    82 
    83   The raw type may not depend on parameters or assumptions of the
    84   context --- this is logically impossible in Isabelle/HOL --- but the
    85   non-emptiness property can be local, potentially resulting in
    86   multiple interpretations in target contexts.  Thus the established
    87   bijection between the representing set \isa{A} and the new type
    88   \isa{t} may semantically depend on local assumptions.
    89 
    90   By default, \hyperlink{command.HOL.typedef}{\mbox{\isa{\isacommand{typedef}}}} defines both a type \isa{t}
    91   and a set (term constant) of the same name, unless an alternative
    92   base name is given in parentheses, or the ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{28}{\isacharparenleft}}open{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequote}}}''
    93   declaration is used to suppress a separate constant definition
    94   altogether.  The injection from type to set is called \isa{Rep{\isaliteral{5F}{\isacharunderscore}}t},
    95   its inverse \isa{Abs{\isaliteral{5F}{\isacharunderscore}}t} --- this may be changed via an explicit
    96   \hyperlink{keyword.HOL.morphisms}{\mbox{\isa{\isakeyword{morphisms}}}} declaration.
    97 
    98   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
    99   corresponding injection/surjection pair (in both directions).  Rules
   100   \isa{Rep{\isaliteral{5F}{\isacharunderscore}}t{\isaliteral{5F}{\isacharunderscore}}inject} and \isa{Abs{\isaliteral{5F}{\isacharunderscore}}t{\isaliteral{5F}{\isacharunderscore}}inject} provide a slightly
   101   more convenient view on the injectivity part, suitable for automated
   102   proof tools (e.g.\ in \hyperlink{attribute.simp}{\mbox{\isa{simp}}} or \hyperlink{attribute.iff}{\mbox{\isa{iff}}}
   103   declarations).  Rules \isa{Rep{\isaliteral{5F}{\isacharunderscore}}t{\isaliteral{5F}{\isacharunderscore}}cases}/\isa{Rep{\isaliteral{5F}{\isacharunderscore}}t{\isaliteral{5F}{\isacharunderscore}}induct}, and
   104   \isa{Abs{\isaliteral{5F}{\isacharunderscore}}t{\isaliteral{5F}{\isacharunderscore}}cases}/\isa{Abs{\isaliteral{5F}{\isacharunderscore}}t{\isaliteral{5F}{\isacharunderscore}}induct} provide alternative views
   105   on surjectivity; these are already declared as set or type rules for
   106   the generic \hyperlink{method.cases}{\mbox{\isa{cases}}} and \hyperlink{method.induct}{\mbox{\isa{induct}}} methods.
   107 
   108   An alternative name for the set definition (and other derived
   109   entities) may be specified in parentheses; the default is to use
   110   \isa{t} as indicated before.
   111 
   112   \end{description}%
   113 \end{isamarkuptext}%
   114 \isamarkuptrue%
   115 %
   116 \isamarkupsection{Adhoc tuples%
   117 }
   118 \isamarkuptrue%
   119 %
   120 \begin{isamarkuptext}%
   121 \begin{matharray}{rcl}
   122     \indexdef{HOL}{attribute}{split\_format}\hypertarget{attribute.HOL.split-format}{\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} \\
   123   \end{matharray}
   124 
   125   \begin{railoutput}
   126 \rail@begin{2}{}
   127 \rail@term{\hyperlink{attribute.HOL.split-format}{\mbox{\isa{split{\isaliteral{5F}{\isacharunderscore}}format}}}}[]
   128 \rail@bar
   129 \rail@nextbar{1}
   130 \rail@term{\isa{{\isaliteral{28}{\isacharparenleft}}}}[]
   131 \rail@term{\isa{complete}}[]
   132 \rail@term{\isa{{\isaliteral{29}{\isacharparenright}}}}[]
   133 \rail@endbar
   134 \rail@end
   135 \end{railoutput}
   136 
   137 
   138   \begin{description}
   139 
   140   \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
   141   arguments in function applications to be represented canonically
   142   according to their tuple type structure.
   143 
   144   Note that this operation tends to invent funny names for new local
   145   parameters introduced.
   146 
   147   \end{description}%
   148 \end{isamarkuptext}%
   149 \isamarkuptrue%
   150 %
   151 \isamarkupsection{Records \label{sec:hol-record}%
   152 }
   153 \isamarkuptrue%
   154 %
   155 \begin{isamarkuptext}%
   156 In principle, records merely generalize the concept of tuples, where
   157   components may be addressed by labels instead of just position.  The
   158   logical infrastructure of records in Isabelle/HOL is slightly more
   159   advanced, though, supporting truly extensible record schemes.  This
   160   admits operations that are polymorphic with respect to record
   161   extension, yielding ``object-oriented'' effects like (single)
   162   inheritance.  See also \cite{NaraschewskiW-TPHOLs98} for more
   163   details on object-oriented verification and record subtyping in HOL.%
   164 \end{isamarkuptext}%
   165 \isamarkuptrue%
   166 %
   167 \isamarkupsubsection{Basic concepts%
   168 }
   169 \isamarkuptrue%
   170 %
   171 \begin{isamarkuptext}%
   172 Isabelle/HOL supports both \emph{fixed} and \emph{schematic} records
   173   at the level of terms and types.  The notation is as follows:
   174 
   175   \begin{center}
   176   \begin{tabular}{l|l|l}
   177     & record terms & record types \\ \hline
   178     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}}} \\
   179     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}}} &
   180       \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}}} \\
   181   \end{tabular}
   182   \end{center}
   183 
   184   \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}}}.
   185 
   186   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
   187   \isa{a} and field \isa{y} of value \isa{b}.  The corresponding
   188   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}}}
   189   and \isa{{\isaliteral{22}{\isachardoublequote}}b\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ B{\isaliteral{22}{\isachardoublequote}}}.
   190 
   191   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
   192   \isa{x} and \isa{y} as before, but also possibly further fields
   193   as indicated by the ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{22}{\isachardoublequote}}}'' notation (which is actually part
   194   of the syntax).  The improper field ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{22}{\isachardoublequote}}}'' of a record
   195   scheme is called the \emph{more part}.  Logically it is just a free
   196   variable, which is occasionally referred to as ``row variable'' in
   197   the literature.  The more part of a record scheme may be
   198   instantiated by zero or more further components.  For example, the
   199   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.
   200   Fixed records are special instances of record schemes, where
   201   ``\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}}}
   202   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
   203   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}}}.
   204 
   205   \medskip Two key observations make extensible records in a simply
   206   typed language like HOL work out:
   207 
   208   \begin{enumerate}
   209 
   210   \item the more part is internalized, as a free term or type
   211   variable,
   212 
   213   \item field names are externalized, they cannot be accessed within
   214   the logic as first-class values.
   215 
   216   \end{enumerate}
   217 
   218   \medskip In Isabelle/HOL record types have to be defined explicitly,
   219   fixing their field names and types, and their (optional) parent
   220   record.  Afterwards, records may be formed using above syntax, while
   221   obeying the canonical order of fields as given by their declaration.
   222   The record package provides several standard operations like
   223   selectors and updates.  The common setup for various generic proof
   224   tools enable succinct reasoning patterns.  See also the Isabelle/HOL
   225   tutorial \cite{isabelle-hol-book} for further instructions on using
   226   records in practice.%
   227 \end{isamarkuptext}%
   228 \isamarkuptrue%
   229 %
   230 \isamarkupsubsection{Record specifications%
   231 }
   232 \isamarkuptrue%
   233 %
   234 \begin{isamarkuptext}%
   235 \begin{matharray}{rcl}
   236     \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}}} \\
   237   \end{matharray}
   238 
   239   \begin{railoutput}
   240 \rail@begin{4}{}
   241 \rail@term{\hyperlink{command.HOL.record}{\mbox{\isa{\isacommand{record}}}}}[]
   242 \rail@nont{\hyperlink{syntax.typespec-sorts}{\mbox{\isa{typespec{\isaliteral{5F}{\isacharunderscore}}sorts}}}}[]
   243 \rail@term{\isa{{\isaliteral{3D}{\isacharequal}}}}[]
   244 \rail@cr{2}
   245 \rail@bar
   246 \rail@nextbar{3}
   247 \rail@nont{\hyperlink{syntax.type}{\mbox{\isa{type}}}}[]
   248 \rail@term{\isa{{\isaliteral{2B}{\isacharplus}}}}[]
   249 \rail@endbar
   250 \rail@plus
   251 \rail@nont{\hyperlink{syntax.constdecl}{\mbox{\isa{constdecl}}}}[]
   252 \rail@nextplus{3}
   253 \rail@endplus
   254 \rail@end
   255 \end{railoutput}
   256 
   257 
   258   \begin{description}
   259 
   260   \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}}},
   261   derived from the optional parent record \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C7461753E}{\isasymtau}}{\isaliteral{22}{\isachardoublequote}}} by adding new
   262   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.
   263 
   264   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
   265   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
   266   least one new field \isa{{\isaliteral{22}{\isachardoublequote}}c\isaliteral{5C3C5E7375623E}{}\isactrlsub i{\isaliteral{22}{\isachardoublequote}}} has to be specified.
   267   Basically, field names need to belong to a unique record.  This is
   268   not a real restriction in practice, since fields are qualified by
   269   the record name internally.
   270 
   271   The parent record specification \isa{{\isaliteral{5C3C7461753E}{\isasymtau}}} is optional; if omitted
   272   \isa{t} becomes a root record.  The hierarchy of all records
   273   declared within a theory context forms a forest structure, i.e.\ a
   274   set of trees starting with a root record each.  There is no way to
   275   merge multiple parent records!
   276 
   277   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
   278   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
   279   \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}}}.
   280 
   281   \end{description}%
   282 \end{isamarkuptext}%
   283 \isamarkuptrue%
   284 %
   285 \isamarkupsubsection{Record operations%
   286 }
   287 \isamarkuptrue%
   288 %
   289 \begin{isamarkuptext}%
   290 Any record definition of the form presented above produces certain
   291   standard operations.  Selectors and updates are provided for any
   292   field, including the improper one ``\isa{more}''.  There are also
   293   cumulative record constructor functions.  To simplify the
   294   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}}}.
   295 
   296   \medskip \textbf{Selectors} and \textbf{updates} are available for
   297   any field (including ``\isa{more}''):
   298 
   299   \begin{matharray}{lll}
   300     \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}}} \\
   301     \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}}} \\
   302   \end{matharray}
   303 
   304   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
   305   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
   306   because of postfix notation the order of fields shown here is
   307   reverse than in the actual term.  Since repeated updates are just
   308   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.
   309   Thus commutativity of independent updates can be proven within the
   310   logic for any two fields, but not as a general theorem.
   311 
   312   \medskip The \textbf{make} operation provides a cumulative record
   313   constructor function:
   314 
   315   \begin{matharray}{lll}
   316     \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}}} \\
   317   \end{matharray}
   318 
   319   \medskip We now reconsider the case of non-root records, which are
   320   derived of some parent.  In general, the latter may depend on
   321   another parent as well, resulting in a list of \emph{ancestor
   322   records}.  Appending the lists of fields of all ancestors results in
   323   a certain field prefix.  The record package automatically takes care
   324   of this by lifting operations over this context of ancestor fields.
   325   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
   326   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}}},
   327   the above record operations will get the following types:
   328 
   329   \medskip
   330   \begin{tabular}{lll}
   331     \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}}} \\
   332     \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}}} \\
   333     \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}}} \\
   334   \end{tabular}
   335   \medskip
   336 
   337   \noindent Some further operations address the extension aspect of a
   338   derived record scheme specifically: \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}fields{\isaliteral{22}{\isachardoublequote}}} produces a
   339   record fragment consisting of exactly the new fields introduced here
   340   (the result may serve as a more part elsewhere); \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}extend{\isaliteral{22}{\isachardoublequote}}}
   341   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.
   342 
   343   \medskip
   344   \begin{tabular}{lll}
   345     \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}}} \\
   346     \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}}} \\
   347     \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}}} \\
   348   \end{tabular}
   349   \medskip
   350 
   351   \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
   352   for root records.%
   353 \end{isamarkuptext}%
   354 \isamarkuptrue%
   355 %
   356 \isamarkupsubsection{Derived rules and proof tools%
   357 }
   358 \isamarkuptrue%
   359 %
   360 \begin{isamarkuptext}%
   361 The record package proves several results internally, declaring
   362   these facts to appropriate proof tools.  This enables users to
   363   reason about record structures quite conveniently.  Assume that
   364   \isa{t} is a record type as specified above.
   365 
   366   \begin{enumerate}
   367 
   368   \item Standard conversions for selectors or updates applied to
   369   record constructor terms are made part of the default Simplifier
   370   context; thus proofs by reduction of basic operations merely require
   371   the \hyperlink{method.simp}{\mbox{\isa{simp}}} method without further arguments.  These rules
   372   are available as \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}simps{\isaliteral{22}{\isachardoublequote}}}, too.
   373 
   374   \item Selectors applied to updated records are automatically reduced
   375   by an internal simplification procedure, which is also part of the
   376   standard Simplifier setup.
   377 
   378   \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
   379   Reasoner as \hyperlink{attribute.iff}{\mbox{\isa{iff}}} rules.  These rules are available as
   380   \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}iffs{\isaliteral{22}{\isachardoublequote}}}.
   381 
   382   \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,
   383   and as the basic rule context as ``\hyperlink{attribute.intro}{\mbox{\isa{intro}}}\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{3F}{\isacharquery}}{\isaliteral{22}{\isachardoublequote}}}''.
   384   The rule is called \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}equality{\isaliteral{22}{\isachardoublequote}}}.
   385 
   386   \item Representations of arbitrary record expressions as canonical
   387   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,
   388   \secref{sec:cases-induct}).  Several variations are available, for
   389   fixed records, record schemes, more parts etc.
   390 
   391   The generic proof methods are sufficiently smart to pick the most
   392   sensible rule according to the type of the indicated record
   393   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.
   394 
   395   \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}
   396   treated automatically, but usually need to be expanded by hand,
   397   using the collective fact \isa{{\isaliteral{22}{\isachardoublequote}}t{\isaliteral{2E}{\isachardot}}defs{\isaliteral{22}{\isachardoublequote}}}.
   398 
   399   \end{enumerate}%
   400 \end{isamarkuptext}%
   401 \isamarkuptrue%
   402 %
   403 \isamarkupsection{Datatypes \label{sec:hol-datatype}%
   404 }
   405 \isamarkuptrue%
   406 %
   407 \begin{isamarkuptext}%
   408 \begin{matharray}{rcl}
   409     \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}}} \\
   410     \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}}} \\
   411   \end{matharray}
   412 
   413   \begin{railoutput}
   414 \rail@begin{2}{}
   415 \rail@term{\hyperlink{command.HOL.datatype}{\mbox{\isa{\isacommand{datatype}}}}}[]
   416 \rail@plus
   417 \rail@nont{\isa{spec}}[]
   418 \rail@nextplus{1}
   419 \rail@cterm{\isa{\isakeyword{and}}}[]
   420 \rail@endplus
   421 \rail@end
   422 \rail@begin{3}{}
   423 \rail@term{\hyperlink{command.HOL.rep-datatype}{\mbox{\isa{\isacommand{rep{\isaliteral{5F}{\isacharunderscore}}datatype}}}}}[]
   424 \rail@bar
   425 \rail@nextbar{1}
   426 \rail@term{\isa{{\isaliteral{28}{\isacharparenleft}}}}[]
   427 \rail@plus
   428 \rail@nont{\hyperlink{syntax.name}{\mbox{\isa{name}}}}[]
   429 \rail@nextplus{2}
   430 \rail@endplus
   431 \rail@term{\isa{{\isaliteral{29}{\isacharparenright}}}}[]
   432 \rail@endbar
   433 \rail@plus
   434 \rail@nont{\hyperlink{syntax.term}{\mbox{\isa{term}}}}[]
   435 \rail@nextplus{1}
   436 \rail@endplus
   437 \rail@end
   438 \rail@begin{2}{\isa{spec}}
   439 \rail@bar
   440 \rail@nextbar{1}
   441 \rail@nont{\hyperlink{syntax.parname}{\mbox{\isa{parname}}}}[]
   442 \rail@endbar
   443 \rail@nont{\hyperlink{syntax.typespec}{\mbox{\isa{typespec}}}}[]
   444 \rail@bar
   445 \rail@nextbar{1}
   446 \rail@nont{\hyperlink{syntax.mixfix}{\mbox{\isa{mixfix}}}}[]
   447 \rail@endbar
   448 \rail@term{\isa{{\isaliteral{3D}{\isacharequal}}}}[]
   449 \rail@plus
   450 \rail@nont{\isa{cons}}[]
   451 \rail@nextplus{1}
   452 \rail@cterm{\isa{{\isaliteral{7C}{\isacharbar}}}}[]
   453 \rail@endplus
   454 \rail@end
   455 \rail@begin{2}{\isa{cons}}
   456 \rail@nont{\hyperlink{syntax.name}{\mbox{\isa{name}}}}[]
   457 \rail@plus
   458 \rail@nextplus{1}
   459 \rail@cnont{\hyperlink{syntax.type}{\mbox{\isa{type}}}}[]
   460 \rail@endplus
   461 \rail@bar
   462 \rail@nextbar{1}
   463 \rail@nont{\hyperlink{syntax.mixfix}{\mbox{\isa{mixfix}}}}[]
   464 \rail@endbar
   465 \rail@end
   466 \end{railoutput}
   467 
   468 
   469   \begin{description}
   470 
   471   \item \hyperlink{command.HOL.datatype}{\mbox{\isa{\isacommand{datatype}}}} defines inductive datatypes in
   472   HOL.
   473 
   474   \item \hyperlink{command.HOL.rep-datatype}{\mbox{\isa{\isacommand{rep{\isaliteral{5F}{\isacharunderscore}}datatype}}}} represents existing types as
   475   inductive ones, generating the standard infrastructure of derived
   476   concepts (primitive recursion etc.).
   477 
   478   \end{description}
   479 
   480   The induction and exhaustion theorems generated provide case names
   481   according to the constructors involved, while parameters are named
   482   after the types (see also \secref{sec:cases-induct}).
   483 
   484   See \cite{isabelle-HOL} for more details on datatypes, but beware of
   485   the old-style theory syntax being used there!  Apart from proper
   486   proof methods for case-analysis and induction, there are also
   487   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
   488   to refer directly to the internal structure of subgoals (including
   489   internally bound parameters).%
   490 \end{isamarkuptext}%
   491 \isamarkuptrue%
   492 %
   493 \isamarkupsection{Functorial structure of types%
   494 }
   495 \isamarkuptrue%
   496 %
   497 \begin{isamarkuptext}%
   498 \begin{matharray}{rcl}
   499     \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}}}
   500   \end{matharray}
   501 
   502   \begin{railoutput}
   503 \rail@begin{2}{}
   504 \rail@term{\hyperlink{command.HOL.enriched-type}{\mbox{\isa{\isacommand{enriched{\isaliteral{5F}{\isacharunderscore}}type}}}}}[]
   505 \rail@bar
   506 \rail@nextbar{1}
   507 \rail@nont{\hyperlink{syntax.name}{\mbox{\isa{name}}}}[]
   508 \rail@term{\isa{{\isaliteral{3A}{\isacharcolon}}}}[]
   509 \rail@endbar
   510 \rail@nont{\hyperlink{syntax.term}{\mbox{\isa{term}}}}[]
   511 \rail@end
   512 \end{railoutput}
   513 
   514 
   515   \begin{description}
   516 
   517   \item \hyperlink{command.HOL.enriched-type}{\mbox{\isa{\isacommand{enriched{\isaliteral{5F}{\isacharunderscore}}type}}}}~\isa{{\isaliteral{22}{\isachardoublequote}}prefix{\isaliteral{3A}{\isacharcolon}}\ m{\isaliteral{22}{\isachardoublequote}}} allows to
   518   prove and register properties about the functorial structure of type
   519   constructors.  These properties then can be used by other packages
   520   to deal with those type constructors in certain type constructions.
   521   Characteristic theorems are noted in the current local theory.  By
   522   default, they are prefixed with the base name of the type
   523   constructor, an explicit prefix can be given alternatively.
   524 
   525   The given term \isa{{\isaliteral{22}{\isachardoublequote}}m{\isaliteral{22}{\isachardoublequote}}} is considered as \emph{mapper} for the
   526   corresponding type constructor and must conform to the following
   527   type pattern:
   528 
   529   \begin{matharray}{lll}
   530     \isa{{\isaliteral{22}{\isachardoublequote}}m{\isaliteral{22}{\isachardoublequote}}} & \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}{\isaliteral{22}{\isachardoublequote}}} &
   531       \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}}} \\
   532   \end{matharray}
   533 
   534   \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
   535   type variables free in the local theory and \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C7369676D613E}{\isasymsigma}}\isaliteral{5C3C5E697375623E}{}\isactrlisub {\isadigit{1}}{\isaliteral{22}{\isachardoublequote}}},
   536   \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,
   537   \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}}}.
   538 
   539   \end{description}%
   540 \end{isamarkuptext}%
   541 \isamarkuptrue%
   542 %
   543 \isamarkupsection{Recursive functions \label{sec:recursion}%
   544 }
   545 \isamarkuptrue%
   546 %
   547 \begin{isamarkuptext}%
   548 \begin{matharray}{rcl}
   549     \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}}} \\
   550     \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}}} \\
   551     \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}}} \\
   552     \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}}} \\
   553   \end{matharray}
   554 
   555   \begin{railoutput}
   556 \rail@begin{2}{}
   557 \rail@term{\hyperlink{command.HOL.primrec}{\mbox{\isa{\isacommand{primrec}}}}}[]
   558 \rail@bar
   559 \rail@nextbar{1}
   560 \rail@nont{\hyperlink{syntax.target}{\mbox{\isa{target}}}}[]
   561 \rail@endbar
   562 \rail@nont{\hyperlink{syntax.fixes}{\mbox{\isa{fixes}}}}[]
   563 \rail@term{\isa{\isakeyword{where}}}[]
   564 \rail@nont{\isa{equations}}[]
   565 \rail@end
   566 \rail@begin{4}{}
   567 \rail@bar
   568 \rail@term{\hyperlink{command.HOL.fun}{\mbox{\isa{\isacommand{fun}}}}}[]
   569 \rail@nextbar{1}
   570 \rail@term{\hyperlink{command.HOL.function}{\mbox{\isa{\isacommand{function}}}}}[]
   571 \rail@endbar
   572 \rail@bar
   573 \rail@nextbar{1}
   574 \rail@nont{\hyperlink{syntax.target}{\mbox{\isa{target}}}}[]
   575 \rail@endbar
   576 \rail@bar
   577 \rail@nextbar{1}
   578 \rail@nont{\isa{functionopts}}[]
   579 \rail@endbar
   580 \rail@nont{\hyperlink{syntax.fixes}{\mbox{\isa{fixes}}}}[]
   581 \rail@cr{3}
   582 \rail@term{\isa{\isakeyword{where}}}[]
   583 \rail@nont{\isa{equations}}[]
   584 \rail@end
   585 \rail@begin{3}{\isa{equations}}
   586 \rail@plus
   587 \rail@bar
   588 \rail@nextbar{1}
   589 \rail@nont{\hyperlink{syntax.thmdecl}{\mbox{\isa{thmdecl}}}}[]
   590 \rail@endbar
   591 \rail@nont{\hyperlink{syntax.prop}{\mbox{\isa{prop}}}}[]
   592 \rail@nextplus{2}
   593 \rail@cterm{\isa{{\isaliteral{7C}{\isacharbar}}}}[]
   594 \rail@endplus
   595 \rail@end
   596 \rail@begin{3}{\isa{functionopts}}
   597 \rail@term{\isa{{\isaliteral{28}{\isacharparenleft}}}}[]
   598 \rail@plus
   599 \rail@bar
   600 \rail@term{\isa{sequential}}[]
   601 \rail@nextbar{1}
   602 \rail@term{\isa{domintros}}[]
   603 \rail@endbar
   604 \rail@nextplus{2}
   605 \rail@cterm{\isa{{\isaliteral{2C}{\isacharcomma}}}}[]
   606 \rail@endplus
   607 \rail@term{\isa{{\isaliteral{29}{\isacharparenright}}}}[]
   608 \rail@end
   609 \rail@begin{2}{}
   610 \rail@term{\hyperlink{command.HOL.termination}{\mbox{\isa{\isacommand{termination}}}}}[]
   611 \rail@bar
   612 \rail@nextbar{1}
   613 \rail@nont{\hyperlink{syntax.term}{\mbox{\isa{term}}}}[]
   614 \rail@endbar
   615 \rail@end
   616 \end{railoutput}
   617 
   618 
   619   \begin{description}
   620 
   621   \item \hyperlink{command.HOL.primrec}{\mbox{\isa{\isacommand{primrec}}}} defines primitive recursive
   622   functions over datatypes, see also \cite{isabelle-HOL}.
   623 
   624   \item \hyperlink{command.HOL.function}{\mbox{\isa{\isacommand{function}}}} defines functions by general
   625   wellfounded recursion. A detailed description with examples can be
   626   found in \cite{isabelle-function}. The function is specified by a
   627   set of (possibly conditional) recursive equations with arbitrary
   628   pattern matching. The command generates proof obligations for the
   629   completeness and the compatibility of patterns.
   630 
   631   The defined function is considered partial, and the resulting
   632   simplification rules (named \isa{{\isaliteral{22}{\isachardoublequote}}f{\isaliteral{2E}{\isachardot}}psimps{\isaliteral{22}{\isachardoublequote}}}) and induction rule
   633   (named \isa{{\isaliteral{22}{\isachardoublequote}}f{\isaliteral{2E}{\isachardot}}pinduct{\isaliteral{22}{\isachardoublequote}}}) are guarded by a generated domain
   634   predicate \isa{{\isaliteral{22}{\isachardoublequote}}f{\isaliteral{5F}{\isacharunderscore}}dom{\isaliteral{22}{\isachardoublequote}}}. The \hyperlink{command.HOL.termination}{\mbox{\isa{\isacommand{termination}}}}
   635   command can then be used to establish that the function is total.
   636 
   637   \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
   638   proof attempts regarding pattern matching and termination.  See
   639   \cite{isabelle-function} for further details.
   640 
   641   \item \hyperlink{command.HOL.termination}{\mbox{\isa{\isacommand{termination}}}}~\isa{f} commences a
   642   termination proof for the previously defined function \isa{f}.  If
   643   this is omitted, the command refers to the most recent function
   644   definition.  After the proof is closed, the recursive equations and
   645   the induction principle is established.
   646 
   647   \end{description}
   648 
   649   Recursive definitions introduced by the \hyperlink{command.HOL.function}{\mbox{\isa{\isacommand{function}}}}
   650   command accommodate
   651   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)
   652   refers to a specific induction rule, with parameters named according
   653   to the user-specified equations. Cases are numbered (starting from 1).
   654 
   655   For \hyperlink{command.HOL.primrec}{\mbox{\isa{\isacommand{primrec}}}}, the induction principle coincides
   656   with structural recursion on the datatype the recursion is carried
   657   out.
   658 
   659   The equations provided by these packages may be referred later as
   660   theorem list \isa{{\isaliteral{22}{\isachardoublequote}}f{\isaliteral{2E}{\isachardot}}simps{\isaliteral{22}{\isachardoublequote}}}, where \isa{f} is the (collective)
   661   name of the functions defined.  Individual equations may be named
   662   explicitly as well.
   663 
   664   The \hyperlink{command.HOL.function}{\mbox{\isa{\isacommand{function}}}} command accepts the following
   665   options.
   666 
   667   \begin{description}
   668 
   669   \item \isa{sequential} enables a preprocessor which disambiguates
   670   overlapping patterns by making them mutually disjoint.  Earlier
   671   equations take precedence over later ones.  This allows to give the
   672   specification in a format very similar to functional programming.
   673   Note that the resulting simplification and induction rules
   674   correspond to the transformed specification, not the one given
   675   originally. This usually means that each equation given by the user
   676   may result in several theorems.  Also note that this automatic
   677   transformation only works for ML-style datatype patterns.
   678 
   679   \item \isa{domintros} enables the automated generation of
   680   introduction rules for the domain predicate. While mostly not
   681   needed, they can be helpful in some proofs about partial functions.
   682 
   683   \end{description}%
   684 \end{isamarkuptext}%
   685 \isamarkuptrue%
   686 %
   687 \isamarkupsubsection{Proof methods related to recursive definitions%
   688 }
   689 \isamarkuptrue%
   690 %
   691 \begin{isamarkuptext}%
   692 \begin{matharray}{rcl}
   693     \indexdef{HOL}{method}{pat\_completeness}\hypertarget{method.HOL.pat-completeness}{\hyperlink{method.HOL.pat-completeness}{\mbox{\isa{pat{\isaliteral{5F}{\isacharunderscore}}completeness}}}} & : & \isa{method} \\
   694     \indexdef{HOL}{method}{relation}\hypertarget{method.HOL.relation}{\hyperlink{method.HOL.relation}{\mbox{\isa{relation}}}} & : & \isa{method} \\
   695     \indexdef{HOL}{method}{lexicographic\_order}\hypertarget{method.HOL.lexicographic-order}{\hyperlink{method.HOL.lexicographic-order}{\mbox{\isa{lexicographic{\isaliteral{5F}{\isacharunderscore}}order}}}} & : & \isa{method} \\
   696     \indexdef{HOL}{method}{size\_change}\hypertarget{method.HOL.size-change}{\hyperlink{method.HOL.size-change}{\mbox{\isa{size{\isaliteral{5F}{\isacharunderscore}}change}}}} & : & \isa{method} \\
   697   \end{matharray}
   698 
   699   \begin{railoutput}
   700 \rail@begin{1}{}
   701 \rail@term{\hyperlink{method.HOL.relation}{\mbox{\isa{relation}}}}[]
   702 \rail@nont{\hyperlink{syntax.term}{\mbox{\isa{term}}}}[]
   703 \rail@end
   704 \rail@begin{2}{}
   705 \rail@term{\hyperlink{method.HOL.lexicographic-order}{\mbox{\isa{lexicographic{\isaliteral{5F}{\isacharunderscore}}order}}}}[]
   706 \rail@plus
   707 \rail@nextplus{1}
   708 \rail@cnont{\hyperlink{syntax.clasimpmod}{\mbox{\isa{clasimpmod}}}}[]
   709 \rail@endplus
   710 \rail@end
   711 \rail@begin{2}{}
   712 \rail@term{\hyperlink{method.HOL.size-change}{\mbox{\isa{size{\isaliteral{5F}{\isacharunderscore}}change}}}}[]
   713 \rail@nont{\isa{orders}}[]
   714 \rail@plus
   715 \rail@nextplus{1}
   716 \rail@cnont{\hyperlink{syntax.clasimpmod}{\mbox{\isa{clasimpmod}}}}[]
   717 \rail@endplus
   718 \rail@end
   719 \rail@begin{4}{\isa{orders}}
   720 \rail@plus
   721 \rail@nextplus{1}
   722 \rail@bar
   723 \rail@term{\isa{max}}[]
   724 \rail@nextbar{2}
   725 \rail@term{\isa{min}}[]
   726 \rail@nextbar{3}
   727 \rail@term{\isa{ms}}[]
   728 \rail@endbar
   729 \rail@endplus
   730 \rail@end
   731 \end{railoutput}
   732 
   733 
   734   \begin{description}
   735 
   736   \item \hyperlink{method.HOL.pat-completeness}{\mbox{\isa{pat{\isaliteral{5F}{\isacharunderscore}}completeness}}} is a specialized method to
   737   solve goals regarding the completeness of pattern matching, as
   738   required by the \hyperlink{command.HOL.function}{\mbox{\isa{\isacommand{function}}}} package (cf.\
   739   \cite{isabelle-function}).
   740 
   741   \item \hyperlink{method.HOL.relation}{\mbox{\isa{relation}}}~\isa{R} introduces a termination
   742   proof using the relation \isa{R}.  The resulting proof state will
   743   contain goals expressing that \isa{R} is wellfounded, and that the
   744   arguments of recursive calls decrease with respect to \isa{R}.
   745   Usually, this method is used as the initial proof step of manual
   746   termination proofs.
   747 
   748   \item \hyperlink{method.HOL.lexicographic-order}{\mbox{\isa{lexicographic{\isaliteral{5F}{\isacharunderscore}}order}}} attempts a fully
   749   automated termination proof by searching for a lexicographic
   750   combination of size measures on the arguments of the function. The
   751   method accepts the same arguments as the \hyperlink{method.auto}{\mbox{\isa{auto}}} method,
   752   which it uses internally to prove local descents.  The same context
   753   modifiers as for \hyperlink{method.auto}{\mbox{\isa{auto}}} are accepted, see
   754   \secref{sec:clasimp}.
   755 
   756   In case of failure, extensive information is printed, which can help
   757   to analyse the situation (cf.\ \cite{isabelle-function}).
   758 
   759   \item \hyperlink{method.HOL.size-change}{\mbox{\isa{size{\isaliteral{5F}{\isacharunderscore}}change}}} also works on termination goals,
   760   using a variation of the size-change principle, together with a
   761   graph decomposition technique (see \cite{krauss_phd} for details).
   762   Three kinds of orders are used internally: \isa{max}, \isa{min},
   763   and \isa{ms} (multiset), which is only available when the theory
   764   \isa{Multiset} is loaded. When no order kinds are given, they are
   765   tried in order. The search for a termination proof uses SAT solving
   766   internally.
   767 
   768  For local descent proofs, the same context modifiers as for \hyperlink{method.auto}{\mbox{\isa{auto}}} are accepted, see \secref{sec:clasimp}.
   769 
   770   \end{description}%
   771 \end{isamarkuptext}%
   772 \isamarkuptrue%
   773 %
   774 \isamarkupsubsection{Functions with explicit partiality%
   775 }
   776 \isamarkuptrue%
   777 %
   778 \begin{isamarkuptext}%
   779 \begin{matharray}{rcl}
   780     \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}}} \\
   781     \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} \\
   782   \end{matharray}
   783 
   784   \begin{railoutput}
   785 \rail@begin{5}{}
   786 \rail@term{\hyperlink{command.HOL.partial-function}{\mbox{\isa{\isacommand{partial{\isaliteral{5F}{\isacharunderscore}}function}}}}}[]
   787 \rail@bar
   788 \rail@nextbar{1}
   789 \rail@nont{\hyperlink{syntax.target}{\mbox{\isa{target}}}}[]
   790 \rail@endbar
   791 \rail@term{\isa{{\isaliteral{28}{\isacharparenleft}}}}[]
   792 \rail@nont{\hyperlink{syntax.nameref}{\mbox{\isa{nameref}}}}[]
   793 \rail@term{\isa{{\isaliteral{29}{\isacharparenright}}}}[]
   794 \rail@nont{\hyperlink{syntax.fixes}{\mbox{\isa{fixes}}}}[]
   795 \rail@cr{3}
   796 \rail@term{\isa{\isakeyword{where}}}[]
   797 \rail@bar
   798 \rail@nextbar{4}
   799 \rail@nont{\hyperlink{syntax.thmdecl}{\mbox{\isa{thmdecl}}}}[]
   800 \rail@endbar
   801 \rail@nont{\hyperlink{syntax.prop}{\mbox{\isa{prop}}}}[]
   802 \rail@end
   803 \end{railoutput}
   804 
   805 
   806   \begin{description}
   807 
   808   \item \hyperlink{command.HOL.partial-function}{\mbox{\isa{\isacommand{partial{\isaliteral{5F}{\isacharunderscore}}function}}}}~\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{28}{\isacharparenleft}}mode{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequote}}} defines
   809   recursive functions based on fixpoints in complete partial
   810   orders. No termination proof is required from the user or
   811   constructed internally. Instead, the possibility of non-termination
   812   is modelled explicitly in the result type, which contains an
   813   explicit bottom element.
   814 
   815   Pattern matching and mutual recursion are currently not supported.
   816   Thus, the specification consists of a single function described by a
   817   single recursive equation.
   818 
   819   There are no fixed syntactic restrictions on the body of the
   820   function, but the induced functional must be provably monotonic
   821   wrt.\ the underlying order.  The monotonicitity proof is performed
   822   internally, and the definition is rejected when it fails. The proof
   823   can be influenced by declaring hints using the
   824   \hyperlink{attribute.HOL.partial-function-mono}{\mbox{\isa{partial{\isaliteral{5F}{\isacharunderscore}}function{\isaliteral{5F}{\isacharunderscore}}mono}}} attribute.
   825 
   826   The mandatory \isa{mode} argument specifies the mode of operation
   827   of the command, which directly corresponds to a complete partial
   828   order on the result type. By default, the following modes are
   829   defined:
   830 
   831   \begin{description}
   832   \item \isa{option} defines functions that map into the \isa{option} type. Here, the value \isa{None} is used to model a
   833   non-terminating computation. Monotonicity requires that if \isa{None} is returned by a recursive call, then the overall result
   834   must also be \isa{None}. This is best achieved through the use of
   835   the monadic operator \isa{{\isaliteral{22}{\isachardoublequote}}Option{\isaliteral{2E}{\isachardot}}bind{\isaliteral{22}{\isachardoublequote}}}.
   836 
   837   \item \isa{tailrec} defines functions with an arbitrary result
   838   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
   839   if \isa{undefined} is returned by a recursive call, then the
   840   overall result must also be \isa{undefined}. In practice, this is
   841   only satisfied when each recursive call is a tail call, whose result
   842   is directly returned. Thus, this mode of operation allows the
   843   definition of arbitrary tail-recursive functions.
   844   \end{description}
   845 
   846   Experienced users may define new modes by instantiating the locale
   847   \isa{{\isaliteral{22}{\isachardoublequote}}partial{\isaliteral{5F}{\isacharunderscore}}function{\isaliteral{5F}{\isacharunderscore}}definitions{\isaliteral{22}{\isachardoublequote}}} appropriately.
   848 
   849   \item \hyperlink{attribute.HOL.partial-function-mono}{\mbox{\isa{partial{\isaliteral{5F}{\isacharunderscore}}function{\isaliteral{5F}{\isacharunderscore}}mono}}} declares rules for
   850   use in the internal monononicity proofs of partial function
   851   definitions.
   852 
   853   \end{description}%
   854 \end{isamarkuptext}%
   855 \isamarkuptrue%
   856 %
   857 \isamarkupsubsection{Old-style recursive function definitions (TFL)%
   858 }
   859 \isamarkuptrue%
   860 %
   861 \begin{isamarkuptext}%
   862 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.
   863 
   864   \begin{matharray}{rcl}
   865     \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}}} \\
   866     \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}}} \\
   867   \end{matharray}
   868 
   869   \begin{railoutput}
   870 \rail@begin{5}{}
   871 \rail@term{\hyperlink{command.HOL.recdef}{\mbox{\isa{\isacommand{recdef}}}}}[]
   872 \rail@bar
   873 \rail@nextbar{1}
   874 \rail@term{\isa{{\isaliteral{28}{\isacharparenleft}}}}[]
   875 \rail@term{\isa{\isakeyword{permissive}}}[]
   876 \rail@term{\isa{{\isaliteral{29}{\isacharparenright}}}}[]
   877 \rail@endbar
   878 \rail@cr{3}
   879 \rail@nont{\hyperlink{syntax.name}{\mbox{\isa{name}}}}[]
   880 \rail@nont{\hyperlink{syntax.term}{\mbox{\isa{term}}}}[]
   881 \rail@plus
   882 \rail@nont{\hyperlink{syntax.prop}{\mbox{\isa{prop}}}}[]
   883 \rail@nextplus{4}
   884 \rail@endplus
   885 \rail@bar
   886 \rail@nextbar{4}
   887 \rail@nont{\isa{hints}}[]
   888 \rail@endbar
   889 \rail@end
   890 \rail@begin{2}{}
   891 \rail@nont{\isa{recdeftc}}[]
   892 \rail@bar
   893 \rail@nextbar{1}
   894 \rail@nont{\hyperlink{syntax.thmdecl}{\mbox{\isa{thmdecl}}}}[]
   895 \rail@endbar
   896 \rail@nont{\isa{tc}}[]
   897 \rail@end
   898 \rail@begin{2}{\isa{hints}}
   899 \rail@term{\isa{{\isaliteral{28}{\isacharparenleft}}}}[]
   900 \rail@term{\isa{\isakeyword{hints}}}[]
   901 \rail@plus
   902 \rail@nextplus{1}
   903 \rail@cnont{\isa{recdefmod}}[]
   904 \rail@endplus
   905 \rail@term{\isa{{\isaliteral{29}{\isacharparenright}}}}[]
   906 \rail@end
   907 \rail@begin{4}{\isa{recdefmod}}
   908 \rail@bar
   909 \rail@bar
   910 \rail@term{\isa{recdef{\isaliteral{5F}{\isacharunderscore}}simp}}[]
   911 \rail@nextbar{1}
   912 \rail@term{\isa{recdef{\isaliteral{5F}{\isacharunderscore}}cong}}[]
   913 \rail@nextbar{2}
   914 \rail@term{\isa{recdef{\isaliteral{5F}{\isacharunderscore}}wf}}[]
   915 \rail@endbar
   916 \rail@bar
   917 \rail@nextbar{1}
   918 \rail@term{\isa{add}}[]
   919 \rail@nextbar{2}
   920 \rail@term{\isa{del}}[]
   921 \rail@endbar
   922 \rail@term{\isa{{\isaliteral{3A}{\isacharcolon}}}}[]
   923 \rail@nont{\hyperlink{syntax.thmrefs}{\mbox{\isa{thmrefs}}}}[]
   924 \rail@nextbar{3}
   925 \rail@nont{\hyperlink{syntax.clasimpmod}{\mbox{\isa{clasimpmod}}}}[]
   926 \rail@endbar
   927 \rail@end
   928 \rail@begin{2}{\isa{tc}}
   929 \rail@nont{\hyperlink{syntax.nameref}{\mbox{\isa{nameref}}}}[]
   930 \rail@bar
   931 \rail@nextbar{1}
   932 \rail@term{\isa{{\isaliteral{28}{\isacharparenleft}}}}[]
   933 \rail@nont{\hyperlink{syntax.nat}{\mbox{\isa{nat}}}}[]
   934 \rail@term{\isa{{\isaliteral{29}{\isacharparenright}}}}[]
   935 \rail@endbar
   936 \rail@end
   937 \end{railoutput}
   938 
   939 
   940   \begin{description}
   941 
   942   \item \hyperlink{command.HOL.recdef}{\mbox{\isa{\isacommand{recdef}}}} defines general well-founded
   943   recursive functions (using the TFL package), see also
   944   \cite{isabelle-HOL}.  The ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{28}{\isacharparenleft}}permissive{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequote}}}'' option tells
   945   TFL to recover from failed proof attempts, returning unfinished
   946   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
   947   automated proof process of TFL.  Additional \hyperlink{syntax.clasimpmod}{\mbox{\isa{clasimpmod}}}
   948   declarations (cf.\ \secref{sec:clasimp}) may be given to tune the
   949   context of the Simplifier (cf.\ \secref{sec:simplifier}) and
   950   Classical reasoner (cf.\ \secref{sec:classical}).
   951 
   952   \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
   953   proof for leftover termination condition number \isa{i} (default
   954   1) as generated by a \hyperlink{command.HOL.recdef}{\mbox{\isa{\isacommand{recdef}}}} definition of
   955   constant \isa{c}.
   956 
   957   Note that in most cases, \hyperlink{command.HOL.recdef}{\mbox{\isa{\isacommand{recdef}}}} is able to finish
   958   its internal proofs without manual intervention.
   959 
   960   \end{description}
   961 
   962   \medskip Hints for \hyperlink{command.HOL.recdef}{\mbox{\isa{\isacommand{recdef}}}} may be also declared
   963   globally, using the following attributes.
   964 
   965   \begin{matharray}{rcl}
   966     \indexdef{HOL}{attribute}{recdef\_simp}\hypertarget{attribute.HOL.recdef-simp}{\hyperlink{attribute.HOL.recdef-simp}{\mbox{\isa{recdef{\isaliteral{5F}{\isacharunderscore}}simp}}}} & : & \isa{attribute} \\
   967     \indexdef{HOL}{attribute}{recdef\_cong}\hypertarget{attribute.HOL.recdef-cong}{\hyperlink{attribute.HOL.recdef-cong}{\mbox{\isa{recdef{\isaliteral{5F}{\isacharunderscore}}cong}}}} & : & \isa{attribute} \\
   968     \indexdef{HOL}{attribute}{recdef\_wf}\hypertarget{attribute.HOL.recdef-wf}{\hyperlink{attribute.HOL.recdef-wf}{\mbox{\isa{recdef{\isaliteral{5F}{\isacharunderscore}}wf}}}} & : & \isa{attribute} \\
   969   \end{matharray}
   970 
   971   \begin{railoutput}
   972 \rail@begin{3}{}
   973 \rail@bar
   974 \rail@term{\hyperlink{attribute.HOL.recdef-simp}{\mbox{\isa{recdef{\isaliteral{5F}{\isacharunderscore}}simp}}}}[]
   975 \rail@nextbar{1}
   976 \rail@term{\hyperlink{attribute.HOL.recdef-cong}{\mbox{\isa{recdef{\isaliteral{5F}{\isacharunderscore}}cong}}}}[]
   977 \rail@nextbar{2}
   978 \rail@term{\hyperlink{attribute.HOL.recdef-wf}{\mbox{\isa{recdef{\isaliteral{5F}{\isacharunderscore}}wf}}}}[]
   979 \rail@endbar
   980 \rail@bar
   981 \rail@nextbar{1}
   982 \rail@term{\isa{add}}[]
   983 \rail@nextbar{2}
   984 \rail@term{\isa{del}}[]
   985 \rail@endbar
   986 \rail@end
   987 \end{railoutput}%
   988 \end{isamarkuptext}%
   989 \isamarkuptrue%
   990 %
   991 \isamarkupsection{Inductive and coinductive definitions \label{sec:hol-inductive}%
   992 }
   993 \isamarkuptrue%
   994 %
   995 \begin{isamarkuptext}%
   996 An \textbf{inductive definition} specifies the least predicate (or
   997   set) \isa{R} closed under given rules: applying a rule to elements
   998   of \isa{R} yields a result within \isa{R}.  For example, a
   999   structural operational semantics is an inductive definition of an
  1000   evaluation relation.
  1001 
  1002   Dually, a \textbf{coinductive definition} specifies the greatest
  1003   predicate~/ set \isa{R} that is consistent with given rules: every
  1004   element of \isa{R} can be seen as arising by applying a rule to
  1005   elements of \isa{R}.  An important example is using bisimulation
  1006   relations to formalise equivalence of processes and infinite data
  1007   structures.
  1008 
  1009   \medskip The HOL package is related to the ZF one, which is
  1010   described in a separate paper,\footnote{It appeared in CADE
  1011   \cite{paulson-CADE}; a longer version is distributed with Isabelle.}
  1012   which you should refer to in case of difficulties.  The package is
  1013   simpler than that of ZF thanks to implicit type-checking in HOL.
  1014   The types of the (co)inductive predicates (or sets) determine the
  1015   domain of the fixedpoint definition, and the package does not have
  1016   to use inference rules for type-checking.
  1017 
  1018   \begin{matharray}{rcl}
  1019     \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}}} \\
  1020     \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}}} \\
  1021     \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}}} \\
  1022     \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}}} \\
  1023     \indexdef{HOL}{attribute}{mono}\hypertarget{attribute.HOL.mono}{\hyperlink{attribute.HOL.mono}{\mbox{\isa{mono}}}} & : & \isa{attribute} \\
  1024   \end{matharray}
  1025 
  1026   \begin{railoutput}
  1027 \rail@begin{7}{}
  1028 \rail@bar
  1029 \rail@term{\hyperlink{command.HOL.inductive}{\mbox{\isa{\isacommand{inductive}}}}}[]
  1030 \rail@nextbar{1}
  1031 \rail@term{\hyperlink{command.HOL.inductive-set}{\mbox{\isa{\isacommand{inductive{\isaliteral{5F}{\isacharunderscore}}set}}}}}[]
  1032 \rail@nextbar{2}
  1033 \rail@term{\hyperlink{command.HOL.coinductive}{\mbox{\isa{\isacommand{coinductive}}}}}[]
  1034 \rail@nextbar{3}
  1035 \rail@term{\hyperlink{command.HOL.coinductive-set}{\mbox{\isa{\isacommand{coinductive{\isaliteral{5F}{\isacharunderscore}}set}}}}}[]
  1036 \rail@endbar
  1037 \rail@bar
  1038 \rail@nextbar{1}
  1039 \rail@nont{\hyperlink{syntax.target}{\mbox{\isa{target}}}}[]
  1040 \rail@endbar
  1041 \rail@nont{\hyperlink{syntax.fixes}{\mbox{\isa{fixes}}}}[]
  1042 \rail@bar
  1043 \rail@nextbar{1}
  1044 \rail@term{\isa{\isakeyword{for}}}[]
  1045 \rail@nont{\hyperlink{syntax.fixes}{\mbox{\isa{fixes}}}}[]
  1046 \rail@endbar
  1047 \rail@cr{5}
  1048 \rail@bar
  1049 \rail@nextbar{6}
  1050 \rail@term{\isa{\isakeyword{where}}}[]
  1051 \rail@nont{\isa{clauses}}[]
  1052 \rail@endbar
  1053 \rail@bar
  1054 \rail@nextbar{6}
  1055 \rail@term{\isa{\isakeyword{monos}}}[]
  1056 \rail@nont{\hyperlink{syntax.thmrefs}{\mbox{\isa{thmrefs}}}}[]
  1057 \rail@endbar
  1058 \rail@end
  1059 \rail@begin{3}{\isa{clauses}}
  1060 \rail@plus
  1061 \rail@bar
  1062 \rail@nextbar{1}
  1063 \rail@nont{\hyperlink{syntax.thmdecl}{\mbox{\isa{thmdecl}}}}[]
  1064 \rail@endbar
  1065 \rail@nont{\hyperlink{syntax.prop}{\mbox{\isa{prop}}}}[]
  1066 \rail@nextplus{2}
  1067 \rail@cterm{\isa{{\isaliteral{7C}{\isacharbar}}}}[]
  1068 \rail@endplus
  1069 \rail@end
  1070 \rail@begin{3}{}
  1071 \rail@term{\hyperlink{attribute.HOL.mono}{\mbox{\isa{mono}}}}[]
  1072 \rail@bar
  1073 \rail@nextbar{1}
  1074 \rail@term{\isa{add}}[]
  1075 \rail@nextbar{2}
  1076 \rail@term{\isa{del}}[]
  1077 \rail@endbar
  1078 \rail@end
  1079 \end{railoutput}
  1080 
  1081 
  1082   \begin{description}
  1083 
  1084   \item \hyperlink{command.HOL.inductive}{\mbox{\isa{\isacommand{inductive}}}} and \hyperlink{command.HOL.coinductive}{\mbox{\isa{\isacommand{coinductive}}}} define (co)inductive predicates from the
  1085   introduction rules given in the \hyperlink{keyword.where}{\mbox{\isa{\isakeyword{where}}}} part.  The
  1086   optional \hyperlink{keyword.for}{\mbox{\isa{\isakeyword{for}}}} part contains a list of parameters of the
  1087   (co)inductive predicates that remain fixed throughout the
  1088   definition.  The optional \hyperlink{keyword.monos}{\mbox{\isa{\isakeyword{monos}}}} section contains
  1089   \emph{monotonicity theorems}, which are required for each operator
  1090   applied to a recursive set in the introduction rules.  There
  1091   \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}}},
  1092   for each premise \isa{{\isaliteral{22}{\isachardoublequote}}M\ R\isaliteral{5C3C5E7375623E}{}\isactrlsub i\ t{\isaliteral{22}{\isachardoublequote}}} in an introduction rule!
  1093 
  1094   \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,
  1095   allowing the definition of (co)inductive sets.
  1096 
  1097   \item \hyperlink{attribute.HOL.mono}{\mbox{\isa{mono}}} declares monotonicity rules.  These
  1098   rule are involved in the automated monotonicity proof of \hyperlink{command.HOL.inductive}{\mbox{\isa{\isacommand{inductive}}}}.
  1099 
  1100   \end{description}%
  1101 \end{isamarkuptext}%
  1102 \isamarkuptrue%
  1103 %
  1104 \isamarkupsubsection{Derived rules%
  1105 }
  1106 \isamarkuptrue%
  1107 %
  1108 \begin{isamarkuptext}%
  1109 Each (co)inductive definition \isa{R} adds definitions to the
  1110   theory and also proves some theorems:
  1111 
  1112   \begin{description}
  1113 
  1114   \item \isa{R{\isaliteral{2E}{\isachardot}}intros} is the list of introduction rules as proven
  1115   theorems, for the recursive predicates (or sets).  The rules are
  1116   also available individually, using the names given them in the
  1117   theory file;
  1118 
  1119   \item \isa{R{\isaliteral{2E}{\isachardot}}cases} is the case analysis (or elimination) rule;
  1120 
  1121   \item \isa{R{\isaliteral{2E}{\isachardot}}induct} or \isa{R{\isaliteral{2E}{\isachardot}}coinduct} is the (co)induction
  1122   rule.
  1123 
  1124   \end{description}
  1125 
  1126   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
  1127   defined simultaneously, the list of introduction rules is called
  1128   \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
  1129   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
  1130   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}}}.%
  1131 \end{isamarkuptext}%
  1132 \isamarkuptrue%
  1133 %
  1134 \isamarkupsubsection{Monotonicity theorems%
  1135 }
  1136 \isamarkuptrue%
  1137 %
  1138 \begin{isamarkuptext}%
  1139 Each theory contains a default set of theorems that are used in
  1140   monotonicity proofs.  New rules can be added to this set via the
  1141   \hyperlink{attribute.HOL.mono}{\mbox{\isa{mono}}} attribute.  The HOL theory \isa{Inductive}
  1142   shows how this is done.  In general, the following monotonicity
  1143   theorems may be added:
  1144 
  1145   \begin{itemize}
  1146 
  1147   \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
  1148   monotonicity of inductive definitions whose introduction rules have
  1149   premises involving terms such as \isa{{\isaliteral{22}{\isachardoublequote}}M\ R\isaliteral{5C3C5E7375623E}{}\isactrlsub i\ t{\isaliteral{22}{\isachardoublequote}}}.
  1150 
  1151   \item Monotonicity theorems for logical operators, which are of the
  1152   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
  1153   the case of the operator \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6F723E}{\isasymor}}{\isaliteral{22}{\isachardoublequote}}}, the corresponding theorem is
  1154   \[
  1155   \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}}}}
  1156   \]
  1157 
  1158   \item De Morgan style equations for reasoning about the ``polarity''
  1159   of expressions, e.g.
  1160   \[
  1161   \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6E6F743E}{\isasymnot}}\ {\isaliteral{5C3C6E6F743E}{\isasymnot}}\ P\ {\isaliteral{5C3C6C6F6E676C65667472696768746172726F773E}{\isasymlongleftrightarrow}}\ P{\isaliteral{22}{\isachardoublequote}}} \qquad\qquad
  1162   \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}}}
  1163   \]
  1164 
  1165   \item Equations for reducing complex operators to more primitive
  1166   ones whose monotonicity can easily be proved, e.g.
  1167   \[
  1168   \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
  1169   \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}}}
  1170   \]
  1171 
  1172   \end{itemize}
  1173 
  1174   %FIXME: Example of an inductive definition%
  1175 \end{isamarkuptext}%
  1176 \isamarkuptrue%
  1177 %
  1178 \isamarkupsection{Arithmetic proof support%
  1179 }
  1180 \isamarkuptrue%
  1181 %
  1182 \begin{isamarkuptext}%
  1183 \begin{matharray}{rcl}
  1184     \indexdef{HOL}{method}{arith}\hypertarget{method.HOL.arith}{\hyperlink{method.HOL.arith}{\mbox{\isa{arith}}}} & : & \isa{method} \\
  1185     \indexdef{HOL}{attribute}{arith}\hypertarget{attribute.HOL.arith}{\hyperlink{attribute.HOL.arith}{\mbox{\isa{arith}}}} & : & \isa{attribute} \\
  1186     \indexdef{HOL}{attribute}{arith\_split}\hypertarget{attribute.HOL.arith-split}{\hyperlink{attribute.HOL.arith-split}{\mbox{\isa{arith{\isaliteral{5F}{\isacharunderscore}}split}}}} & : & \isa{attribute} \\
  1187   \end{matharray}
  1188 
  1189   The \hyperlink{method.HOL.arith}{\mbox{\isa{arith}}} method decides linear arithmetic problems
  1190   (on types \isa{nat}, \isa{int}, \isa{real}).  Any current
  1191   facts are inserted into the goal before running the procedure.
  1192 
  1193   The \hyperlink{attribute.HOL.arith}{\mbox{\isa{arith}}} attribute declares facts that are
  1194   always supplied to the arithmetic provers implicitly.
  1195 
  1196   The \hyperlink{attribute.HOL.arith-split}{\mbox{\isa{arith{\isaliteral{5F}{\isacharunderscore}}split}}} attribute declares case split
  1197   rules to be expanded before \hyperlink{method.HOL.arith}{\mbox{\isa{arith}}} is invoked.
  1198 
  1199   Note that a simpler (but faster) arithmetic prover is
  1200   already invoked by the Simplifier.%
  1201 \end{isamarkuptext}%
  1202 \isamarkuptrue%
  1203 %
  1204 \isamarkupsection{Intuitionistic proof search%
  1205 }
  1206 \isamarkuptrue%
  1207 %
  1208 \begin{isamarkuptext}%
  1209 \begin{matharray}{rcl}
  1210     \indexdef{HOL}{method}{iprover}\hypertarget{method.HOL.iprover}{\hyperlink{method.HOL.iprover}{\mbox{\isa{iprover}}}} & : & \isa{method} \\
  1211   \end{matharray}
  1212 
  1213   \begin{railoutput}
  1214 \rail@begin{2}{}
  1215 \rail@term{\hyperlink{method.HOL.iprover}{\mbox{\isa{iprover}}}}[]
  1216 \rail@plus
  1217 \rail@nextplus{1}
  1218 \rail@cnont{\hyperlink{syntax.rulemod}{\mbox{\isa{rulemod}}}}[]
  1219 \rail@endplus
  1220 \rail@end
  1221 \end{railoutput}
  1222 
  1223 
  1224   The \hyperlink{method.HOL.iprover}{\mbox{\isa{iprover}}} method performs intuitionistic proof
  1225   search, depending on specifically declared rules from the context,
  1226   or given as explicit arguments.  Chained facts are inserted into the
  1227   goal before commencing proof search.
  1228 
  1229   Rules need to be classified as \hyperlink{attribute.Pure.intro}{\mbox{\isa{intro}}},
  1230   \hyperlink{attribute.Pure.elim}{\mbox{\isa{elim}}}, or \hyperlink{attribute.Pure.dest}{\mbox{\isa{dest}}}; here the
  1231   ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{21}{\isacharbang}}{\isaliteral{22}{\isachardoublequote}}}'' indicator refers to ``safe'' rules, which may be
  1232   applied aggressively (without considering back-tracking later).
  1233   Rules declared with ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{3F}{\isacharquery}}{\isaliteral{22}{\isachardoublequote}}}'' are ignored in proof search (the
  1234   single-step \hyperlink{method.Pure.rule}{\mbox{\isa{rule}}} method still observes these).  An
  1235   explicit weight annotation may be given as well; otherwise the
  1236   number of rule premises will be taken into account here.%
  1237 \end{isamarkuptext}%
  1238 \isamarkuptrue%
  1239 %
  1240 \isamarkupsection{Coherent Logic%
  1241 }
  1242 \isamarkuptrue%
  1243 %
  1244 \begin{isamarkuptext}%
  1245 \begin{matharray}{rcl}
  1246     \indexdef{HOL}{method}{coherent}\hypertarget{method.HOL.coherent}{\hyperlink{method.HOL.coherent}{\mbox{\isa{coherent}}}} & : & \isa{method} \\
  1247   \end{matharray}
  1248 
  1249   \begin{railoutput}
  1250 \rail@begin{2}{}
  1251 \rail@term{\hyperlink{method.HOL.coherent}{\mbox{\isa{coherent}}}}[]
  1252 \rail@bar
  1253 \rail@nextbar{1}
  1254 \rail@nont{\hyperlink{syntax.thmrefs}{\mbox{\isa{thmrefs}}}}[]
  1255 \rail@endbar
  1256 \rail@end
  1257 \end{railoutput}
  1258 
  1259 
  1260   The \hyperlink{method.HOL.coherent}{\mbox{\isa{coherent}}} method solves problems of
  1261   \emph{Coherent Logic} \cite{Bezem-Coquand:2005}, which covers
  1262   applications in confluence theory, lattice theory and projective
  1263   geometry.  See \verb|~~/src/HOL/ex/Coherent.thy| for some
  1264   examples.%
  1265 \end{isamarkuptext}%
  1266 \isamarkuptrue%
  1267 %
  1268 \isamarkupsection{Proving propositions%
  1269 }
  1270 \isamarkuptrue%
  1271 %
  1272 \begin{isamarkuptext}%
  1273 In addition to the standard proof methods, a number of diagnosis
  1274   tools search for proofs and provide an Isar proof snippet on success.
  1275   These tools are available via the following commands.
  1276 
  1277   \begin{matharray}{rcl}
  1278     \indexdef{HOL}{command}{solve\_direct}\hypertarget{command.HOL.solve-direct}{\hyperlink{command.HOL.solve-direct}{\mbox{\isa{\isacommand{solve{\isaliteral{5F}{\isacharunderscore}}direct}}}}}\isa{{\isaliteral{22}{\isachardoublequote}}\isaliteral{5C3C5E7375703E}{}\isactrlsup {\isaliteral{2A}{\isacharasterisk}}{\isaliteral{22}{\isachardoublequote}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}proof\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}{\isaliteral{22}{\isachardoublequote}}} \\
  1279     \indexdef{HOL}{command}{try}\hypertarget{command.HOL.try}{\hyperlink{command.HOL.try}{\mbox{\isa{\isacommand{try}}}}}\isa{{\isaliteral{22}{\isachardoublequote}}\isaliteral{5C3C5E7375703E}{}\isactrlsup {\isaliteral{2A}{\isacharasterisk}}{\isaliteral{22}{\isachardoublequote}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}proof\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}{\isaliteral{22}{\isachardoublequote}}} \\
  1280     \indexdef{HOL}{command}{try\_methods}\hypertarget{command.HOL.try-methods}{\hyperlink{command.HOL.try-methods}{\mbox{\isa{\isacommand{try{\isaliteral{5F}{\isacharunderscore}}methods}}}}}\isa{{\isaliteral{22}{\isachardoublequote}}\isaliteral{5C3C5E7375703E}{}\isactrlsup {\isaliteral{2A}{\isacharasterisk}}{\isaliteral{22}{\isachardoublequote}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}proof\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}{\isaliteral{22}{\isachardoublequote}}} \\
  1281     \indexdef{HOL}{command}{sledgehammer}\hypertarget{command.HOL.sledgehammer}{\hyperlink{command.HOL.sledgehammer}{\mbox{\isa{\isacommand{sledgehammer}}}}}\isa{{\isaliteral{22}{\isachardoublequote}}\isaliteral{5C3C5E7375703E}{}\isactrlsup {\isaliteral{2A}{\isacharasterisk}}{\isaliteral{22}{\isachardoublequote}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}proof\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}{\isaliteral{22}{\isachardoublequote}}} \\
  1282     \indexdef{HOL}{command}{sledgehammer\_params}\hypertarget{command.HOL.sledgehammer-params}{\hyperlink{command.HOL.sledgehammer-params}{\mbox{\isa{\isacommand{sledgehammer{\isaliteral{5F}{\isacharunderscore}}params}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}}
  1283   \end{matharray}
  1284 
  1285   \begin{railoutput}
  1286 \rail@begin{1}{}
  1287 \rail@term{\hyperlink{command.HOL.try}{\mbox{\isa{\isacommand{try}}}}}[]
  1288 \rail@end
  1289 \rail@begin{6}{}
  1290 \rail@term{\hyperlink{command.HOL.try-methods}{\mbox{\isa{\isacommand{try{\isaliteral{5F}{\isacharunderscore}}methods}}}}}[]
  1291 \rail@bar
  1292 \rail@nextbar{1}
  1293 \rail@plus
  1294 \rail@bar
  1295 \rail@term{\isa{simp}}[]
  1296 \rail@nextbar{2}
  1297 \rail@term{\isa{intro}}[]
  1298 \rail@nextbar{3}
  1299 \rail@term{\isa{elim}}[]
  1300 \rail@nextbar{4}
  1301 \rail@term{\isa{dest}}[]
  1302 \rail@endbar
  1303 \rail@term{\isa{{\isaliteral{3A}{\isacharcolon}}}}[]
  1304 \rail@nont{\hyperlink{syntax.thmrefs}{\mbox{\isa{thmrefs}}}}[]
  1305 \rail@nextplus{5}
  1306 \rail@endplus
  1307 \rail@endbar
  1308 \rail@bar
  1309 \rail@nextbar{1}
  1310 \rail@nont{\hyperlink{syntax.nat}{\mbox{\isa{nat}}}}[]
  1311 \rail@endbar
  1312 \rail@end
  1313 \rail@begin{2}{}
  1314 \rail@term{\hyperlink{command.HOL.sledgehammer}{\mbox{\isa{\isacommand{sledgehammer}}}}}[]
  1315 \rail@bar
  1316 \rail@nextbar{1}
  1317 \rail@term{\isa{{\isaliteral{5B}{\isacharbrackleft}}}}[]
  1318 \rail@nont{\isa{args}}[]
  1319 \rail@term{\isa{{\isaliteral{5D}{\isacharbrackright}}}}[]
  1320 \rail@endbar
  1321 \rail@bar
  1322 \rail@nextbar{1}
  1323 \rail@nont{\isa{facts}}[]
  1324 \rail@endbar
  1325 \rail@bar
  1326 \rail@nextbar{1}
  1327 \rail@nont{\hyperlink{syntax.nat}{\mbox{\isa{nat}}}}[]
  1328 \rail@endbar
  1329 \rail@end
  1330 \rail@begin{2}{}
  1331 \rail@term{\hyperlink{command.HOL.sledgehammer-params}{\mbox{\isa{\isacommand{sledgehammer{\isaliteral{5F}{\isacharunderscore}}params}}}}}[]
  1332 \rail@bar
  1333 \rail@nextbar{1}
  1334 \rail@term{\isa{{\isaliteral{5B}{\isacharbrackleft}}}}[]
  1335 \rail@nont{\isa{args}}[]
  1336 \rail@term{\isa{{\isaliteral{5D}{\isacharbrackright}}}}[]
  1337 \rail@endbar
  1338 \rail@end
  1339 \rail@begin{2}{\isa{args}}
  1340 \rail@plus
  1341 \rail@nont{\hyperlink{syntax.name}{\mbox{\isa{name}}}}[]
  1342 \rail@term{\isa{{\isaliteral{3D}{\isacharequal}}}}[]
  1343 \rail@nont{\isa{value}}[]
  1344 \rail@nextplus{1}
  1345 \rail@cterm{\isa{{\isaliteral{2C}{\isacharcomma}}}}[]
  1346 \rail@endplus
  1347 \rail@end
  1348 \rail@begin{5}{\isa{facts}}
  1349 \rail@term{\isa{{\isaliteral{28}{\isacharparenleft}}}}[]
  1350 \rail@bar
  1351 \rail@nextbar{1}
  1352 \rail@plus
  1353 \rail@bar
  1354 \rail@nextbar{2}
  1355 \rail@bar
  1356 \rail@term{\isa{add}}[]
  1357 \rail@nextbar{3}
  1358 \rail@term{\isa{del}}[]
  1359 \rail@endbar
  1360 \rail@term{\isa{{\isaliteral{3A}{\isacharcolon}}}}[]
  1361 \rail@endbar
  1362 \rail@nont{\hyperlink{syntax.thmrefs}{\mbox{\isa{thmrefs}}}}[]
  1363 \rail@nextplus{4}
  1364 \rail@endplus
  1365 \rail@endbar
  1366 \rail@term{\isa{{\isaliteral{29}{\isacharparenright}}}}[]
  1367 \rail@end
  1368 \end{railoutput}
  1369  % FIXME check args "value"
  1370 
  1371   \begin{description}
  1372 
  1373   \item \hyperlink{command.HOL.solve-direct}{\mbox{\isa{\isacommand{solve{\isaliteral{5F}{\isacharunderscore}}direct}}}} checks whether the current subgoals can
  1374     be solved directly by an existing theorem. Duplicate lemmas can be detected
  1375     in this way.
  1376 
  1377   \item \hyperlink{command.HOL.try-methods}{\mbox{\isa{\isacommand{try{\isaliteral{5F}{\isacharunderscore}}methods}}}} attempts to prove a subgoal using a combination
  1378     of standard proof methods (\isa{auto}, \isa{simp}, \isa{blast}, etc.).
  1379     Additional facts supplied via \isa{{\isaliteral{22}{\isachardoublequote}}simp{\isaliteral{3A}{\isacharcolon}}{\isaliteral{22}{\isachardoublequote}}}, \isa{{\isaliteral{22}{\isachardoublequote}}intro{\isaliteral{3A}{\isacharcolon}}{\isaliteral{22}{\isachardoublequote}}},
  1380     \isa{{\isaliteral{22}{\isachardoublequote}}elim{\isaliteral{3A}{\isacharcolon}}{\isaliteral{22}{\isachardoublequote}}}, and \isa{{\isaliteral{22}{\isachardoublequote}}dest{\isaliteral{3A}{\isacharcolon}}{\isaliteral{22}{\isachardoublequote}}} are passed to the appropriate proof
  1381     methods.
  1382 
  1383   \item \hyperlink{command.HOL.sledgehammer}{\mbox{\isa{\isacommand{sledgehammer}}}} attempts to prove a subgoal using external
  1384     automatic provers (resolution provers and SMT solvers). See the Sledgehammer
  1385     manual \cite{isabelle-sledgehammer} for details.
  1386 
  1387   \item \hyperlink{command.HOL.sledgehammer-params}{\mbox{\isa{\isacommand{sledgehammer{\isaliteral{5F}{\isacharunderscore}}params}}}} changes
  1388     \hyperlink{command.HOL.sledgehammer}{\mbox{\isa{\isacommand{sledgehammer}}}} configuration options persistently.
  1389 
  1390   \end{description}%
  1391 \end{isamarkuptext}%
  1392 \isamarkuptrue%
  1393 %
  1394 \isamarkupsection{Checking and refuting propositions%
  1395 }
  1396 \isamarkuptrue%
  1397 %
  1398 \begin{isamarkuptext}%
  1399 Identifying incorrect propositions usually involves evaluation of
  1400   particular assignments and systematic counterexample search.  This
  1401   is supported by the following commands.
  1402 
  1403   \begin{matharray}{rcl}
  1404     \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}}} \\
  1405     \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}}} \\
  1406     \indexdef{HOL}{command}{refute}\hypertarget{command.HOL.refute}{\hyperlink{command.HOL.refute}{\mbox{\isa{\isacommand{refute}}}}}\isa{{\isaliteral{22}{\isachardoublequote}}\isaliteral{5C3C5E7375703E}{}\isactrlsup {\isaliteral{2A}{\isacharasterisk}}{\isaliteral{22}{\isachardoublequote}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}proof\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}{\isaliteral{22}{\isachardoublequote}}} \\
  1407     \indexdef{HOL}{command}{nitpick}\hypertarget{command.HOL.nitpick}{\hyperlink{command.HOL.nitpick}{\mbox{\isa{\isacommand{nitpick}}}}}\isa{{\isaliteral{22}{\isachardoublequote}}\isaliteral{5C3C5E7375703E}{}\isactrlsup {\isaliteral{2A}{\isacharasterisk}}{\isaliteral{22}{\isachardoublequote}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}proof\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}{\isaliteral{22}{\isachardoublequote}}} \\
  1408     \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}}} \\
  1409     \indexdef{HOL}{command}{refute\_params}\hypertarget{command.HOL.refute-params}{\hyperlink{command.HOL.refute-params}{\mbox{\isa{\isacommand{refute{\isaliteral{5F}{\isacharunderscore}}params}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\
  1410     \indexdef{HOL}{command}{nitpick\_params}\hypertarget{command.HOL.nitpick-params}{\hyperlink{command.HOL.nitpick-params}{\mbox{\isa{\isacommand{nitpick{\isaliteral{5F}{\isacharunderscore}}params}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}}
  1411   \end{matharray}
  1412 
  1413   \begin{railoutput}
  1414 \rail@begin{2}{}
  1415 \rail@term{\hyperlink{command.HOL.value}{\mbox{\isa{\isacommand{value}}}}}[]
  1416 \rail@bar
  1417 \rail@nextbar{1}
  1418 \rail@term{\isa{{\isaliteral{5B}{\isacharbrackleft}}}}[]
  1419 \rail@nont{\isa{name}}[]
  1420 \rail@term{\isa{{\isaliteral{5D}{\isacharbrackright}}}}[]
  1421 \rail@endbar
  1422 \rail@bar
  1423 \rail@nextbar{1}
  1424 \rail@nont{\isa{modes}}[]
  1425 \rail@endbar
  1426 \rail@nont{\hyperlink{syntax.term}{\mbox{\isa{term}}}}[]
  1427 \rail@end
  1428 \rail@begin{3}{}
  1429 \rail@bar
  1430 \rail@term{\hyperlink{command.HOL.quickcheck}{\mbox{\isa{\isacommand{quickcheck}}}}}[]
  1431 \rail@nextbar{1}
  1432 \rail@term{\hyperlink{command.HOL.refute}{\mbox{\isa{\isacommand{refute}}}}}[]
  1433 \rail@nextbar{2}
  1434 \rail@term{\hyperlink{command.HOL.nitpick}{\mbox{\isa{\isacommand{nitpick}}}}}[]
  1435 \rail@endbar
  1436 \rail@bar
  1437 \rail@nextbar{1}
  1438 \rail@term{\isa{{\isaliteral{5B}{\isacharbrackleft}}}}[]
  1439 \rail@nont{\isa{args}}[]
  1440 \rail@term{\isa{{\isaliteral{5D}{\isacharbrackright}}}}[]
  1441 \rail@endbar
  1442 \rail@bar
  1443 \rail@nextbar{1}
  1444 \rail@nont{\hyperlink{syntax.nat}{\mbox{\isa{nat}}}}[]
  1445 \rail@endbar
  1446 \rail@end
  1447 \rail@begin{3}{}
  1448 \rail@bar
  1449 \rail@term{\hyperlink{command.HOL.quickcheck-params}{\mbox{\isa{\isacommand{quickcheck{\isaliteral{5F}{\isacharunderscore}}params}}}}}[]
  1450 \rail@nextbar{1}
  1451 \rail@term{\hyperlink{command.HOL.refute-params}{\mbox{\isa{\isacommand{refute{\isaliteral{5F}{\isacharunderscore}}params}}}}}[]
  1452 \rail@nextbar{2}
  1453 \rail@term{\hyperlink{command.HOL.nitpick-params}{\mbox{\isa{\isacommand{nitpick{\isaliteral{5F}{\isacharunderscore}}params}}}}}[]
  1454 \rail@endbar
  1455 \rail@bar
  1456 \rail@nextbar{1}
  1457 \rail@term{\isa{{\isaliteral{5B}{\isacharbrackleft}}}}[]
  1458 \rail@nont{\isa{args}}[]
  1459 \rail@term{\isa{{\isaliteral{5D}{\isacharbrackright}}}}[]
  1460 \rail@endbar
  1461 \rail@end
  1462 \rail@begin{2}{\isa{modes}}
  1463 \rail@term{\isa{{\isaliteral{28}{\isacharparenleft}}}}[]
  1464 \rail@plus
  1465 \rail@nont{\hyperlink{syntax.name}{\mbox{\isa{name}}}}[]
  1466 \rail@nextplus{1}
  1467 \rail@endplus
  1468 \rail@term{\isa{{\isaliteral{29}{\isacharparenright}}}}[]
  1469 \rail@end
  1470 \rail@begin{2}{\isa{args}}
  1471 \rail@plus
  1472 \rail@nont{\hyperlink{syntax.name}{\mbox{\isa{name}}}}[]
  1473 \rail@term{\isa{{\isaliteral{3D}{\isacharequal}}}}[]
  1474 \rail@nont{\isa{value}}[]
  1475 \rail@nextplus{1}
  1476 \rail@cterm{\isa{{\isaliteral{2C}{\isacharcomma}}}}[]
  1477 \rail@endplus
  1478 \rail@end
  1479 \end{railoutput}
  1480  % FIXME check "value"
  1481 
  1482   \begin{description}
  1483 
  1484   \item \hyperlink{command.HOL.value}{\mbox{\isa{\isacommand{value}}}}~\isa{t} evaluates and prints a
  1485     term; optionally \isa{modes} can be specified, which are
  1486     appended to the current print mode (see also \cite{isabelle-ref}).
  1487     Internally, the evaluation is performed by registered evaluators,
  1488     which are invoked sequentially until a result is returned.
  1489     Alternatively a specific evaluator can be selected using square
  1490     brackets; typical evaluators use the current set of code equations
  1491     to normalize and include \isa{simp} for fully symbolic evaluation
  1492     using the simplifier, \isa{nbe} for \emph{normalization by evaluation}
  1493     and \emph{code} for code generation in SML.
  1494 
  1495   \item \hyperlink{command.HOL.quickcheck}{\mbox{\isa{\isacommand{quickcheck}}}} tests the current goal for
  1496     counterexamples using a series of assignments for its
  1497     free variables; by default the first subgoal is tested, an other
  1498     can be selected explicitly using an optional goal index.
  1499     Assignments can be chosen exhausting the search space upto a given
  1500     size or using a fixed number of random assignments in the search space.
  1501     By default, quickcheck uses exhaustive testing.
  1502     A number of configuration options are supported for
  1503     \hyperlink{command.HOL.quickcheck}{\mbox{\isa{\isacommand{quickcheck}}}}, notably:
  1504 
  1505     \begin{description}
  1506 
  1507     \item[\isa{tester}] specifies how to explore the search space
  1508       (e.g. exhaustive or random).
  1509       An unknown configuration option is treated as an argument to tester,
  1510       making \isa{{\isaliteral{22}{\isachardoublequote}}tester\ {\isaliteral{3D}{\isacharequal}}{\isaliteral{22}{\isachardoublequote}}} optional.
  1511     \item[\isa{size}] specifies the maximum size of the search space
  1512     for assignment values.
  1513 
  1514     \item[\isa{eval}] takes a term or a list of terms and evaluates
  1515       these terms under the variable assignment found by quickcheck.
  1516 
  1517     \item[\isa{iterations}] sets how many sets of assignments are
  1518     generated for each particular size.
  1519 
  1520     \item[\isa{no{\isaliteral{5F}{\isacharunderscore}}assms}] specifies whether assumptions in
  1521     structured proofs should be ignored.
  1522 
  1523     \item[\isa{timeout}] sets the time limit in seconds.
  1524 
  1525     \item[\isa{default{\isaliteral{5F}{\isacharunderscore}}type}] sets the type(s) generally used to
  1526     instantiate type variables.
  1527 
  1528     \item[\isa{report}] if set quickcheck reports how many tests
  1529     fulfilled the preconditions.
  1530 
  1531     \item[\isa{quiet}] if not set quickcheck informs about the
  1532     current size for assignment values.
  1533 
  1534     \item[\isa{expect}] can be used to check if the user's
  1535     expectation was met (\isa{no{\isaliteral{5F}{\isacharunderscore}}expectation}, \isa{no{\isaliteral{5F}{\isacharunderscore}}counterexample}, or \isa{counterexample}).
  1536 
  1537     \end{description}
  1538 
  1539     These option can be given within square brackets.
  1540 
  1541   \item \hyperlink{command.HOL.quickcheck-params}{\mbox{\isa{\isacommand{quickcheck{\isaliteral{5F}{\isacharunderscore}}params}}}} changes
  1542     \hyperlink{command.HOL.quickcheck}{\mbox{\isa{\isacommand{quickcheck}}}} configuration options persistently.
  1543 
  1544   \item \hyperlink{command.HOL.refute}{\mbox{\isa{\isacommand{refute}}}} tests the current goal for
  1545     counterexamples using a reduction to SAT. The following configuration
  1546     options are supported:
  1547 
  1548     \begin{description}
  1549 
  1550     \item[\isa{minsize}] specifies the minimum size (cardinality) of the
  1551       models to search for.
  1552 
  1553     \item[\isa{maxsize}] specifies the maximum size (cardinality) of the
  1554       models to search for. Nonpositive values mean $\infty$.
  1555 
  1556     \item[\isa{maxvars}] specifies the maximum number of Boolean variables
  1557     to use when transforming the term into a propositional formula.
  1558     Nonpositive values mean $\infty$.
  1559 
  1560     \item[\isa{satsolver}] specifies the SAT solver to use.
  1561 
  1562     \item[\isa{no{\isaliteral{5F}{\isacharunderscore}}assms}] specifies whether assumptions in
  1563     structured proofs should be ignored.
  1564 
  1565     \item[\isa{maxtime}] sets the time limit in seconds.
  1566 
  1567     \item[\isa{expect}] can be used to check if the user's
  1568     expectation was met (\isa{genuine}, \isa{potential},
  1569     \isa{none}, or \isa{unknown}).
  1570 
  1571     \end{description}
  1572 
  1573     These option can be given within square brackets.
  1574 
  1575   \item \hyperlink{command.HOL.refute-params}{\mbox{\isa{\isacommand{refute{\isaliteral{5F}{\isacharunderscore}}params}}}} changes
  1576     \hyperlink{command.HOL.refute}{\mbox{\isa{\isacommand{refute}}}} configuration options persistently.
  1577 
  1578   \item \hyperlink{command.HOL.nitpick}{\mbox{\isa{\isacommand{nitpick}}}} tests the current goal for counterexamples
  1579     using a reduction to first-order relational logic. See the Nitpick manual
  1580     \cite{isabelle-nitpick} for details.
  1581 
  1582   \item \hyperlink{command.HOL.nitpick-params}{\mbox{\isa{\isacommand{nitpick{\isaliteral{5F}{\isacharunderscore}}params}}}} changes
  1583     \hyperlink{command.HOL.nitpick}{\mbox{\isa{\isacommand{nitpick}}}} configuration options persistently.
  1584 
  1585   \end{description}%
  1586 \end{isamarkuptext}%
  1587 \isamarkuptrue%
  1588 %
  1589 \isamarkupsection{Unstructured case analysis and induction \label{sec:hol-induct-tac}%
  1590 }
  1591 \isamarkuptrue%
  1592 %
  1593 \begin{isamarkuptext}%
  1594 The following tools of Isabelle/HOL support cases analysis and
  1595   induction in unstructured tactic scripts; see also
  1596   \secref{sec:cases-induct} for proper Isar versions of similar ideas.
  1597 
  1598   \begin{matharray}{rcl}
  1599     \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} \\
  1600     \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} \\
  1601     \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} \\
  1602     \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}}} \\
  1603   \end{matharray}
  1604 
  1605   \begin{railoutput}
  1606 \rail@begin{2}{}
  1607 \rail@term{\hyperlink{method.HOL.case-tac}{\mbox{\isa{case{\isaliteral{5F}{\isacharunderscore}}tac}}}}[]
  1608 \rail@bar
  1609 \rail@nextbar{1}
  1610 \rail@nont{\hyperlink{syntax.goal-spec}{\mbox{\isa{goal{\isaliteral{5F}{\isacharunderscore}}spec}}}}[]
  1611 \rail@endbar
  1612 \rail@nont{\hyperlink{syntax.term}{\mbox{\isa{term}}}}[]
  1613 \rail@bar
  1614 \rail@nextbar{1}
  1615 \rail@nont{\isa{rule}}[]
  1616 \rail@endbar
  1617 \rail@end
  1618 \rail@begin{3}{}
  1619 \rail@term{\hyperlink{method.HOL.induct-tac}{\mbox{\isa{induct{\isaliteral{5F}{\isacharunderscore}}tac}}}}[]
  1620 \rail@bar
  1621 \rail@nextbar{1}
  1622 \rail@nont{\hyperlink{syntax.goal-spec}{\mbox{\isa{goal{\isaliteral{5F}{\isacharunderscore}}spec}}}}[]
  1623 \rail@endbar
  1624 \rail@bar
  1625 \rail@nextbar{1}
  1626 \rail@plus
  1627 \rail@nont{\hyperlink{syntax.insts}{\mbox{\isa{insts}}}}[]
  1628 \rail@nextplus{2}
  1629 \rail@cterm{\isa{\isakeyword{and}}}[]
  1630 \rail@endplus
  1631 \rail@endbar
  1632 \rail@bar
  1633 \rail@nextbar{1}
  1634 \rail@nont{\isa{rule}}[]
  1635 \rail@endbar
  1636 \rail@end
  1637 \rail@begin{3}{}
  1638 \rail@term{\hyperlink{method.HOL.ind-cases}{\mbox{\isa{ind{\isaliteral{5F}{\isacharunderscore}}cases}}}}[]
  1639 \rail@plus
  1640 \rail@nont{\hyperlink{syntax.prop}{\mbox{\isa{prop}}}}[]
  1641 \rail@nextplus{1}
  1642 \rail@endplus
  1643 \rail@bar
  1644 \rail@nextbar{1}
  1645 \rail@term{\isa{\isakeyword{for}}}[]
  1646 \rail@plus
  1647 \rail@nont{\hyperlink{syntax.name}{\mbox{\isa{name}}}}[]
  1648 \rail@nextplus{2}
  1649 \rail@endplus
  1650 \rail@endbar
  1651 \rail@end
  1652 \rail@begin{3}{}
  1653 \rail@term{\hyperlink{command.HOL.inductive-cases}{\mbox{\isa{\isacommand{inductive{\isaliteral{5F}{\isacharunderscore}}cases}}}}}[]
  1654 \rail@plus
  1655 \rail@bar
  1656 \rail@nextbar{1}
  1657 \rail@nont{\hyperlink{syntax.thmdecl}{\mbox{\isa{thmdecl}}}}[]
  1658 \rail@endbar
  1659 \rail@plus
  1660 \rail@nont{\hyperlink{syntax.prop}{\mbox{\isa{prop}}}}[]
  1661 \rail@nextplus{1}
  1662 \rail@endplus
  1663 \rail@nextplus{2}
  1664 \rail@cterm{\isa{\isakeyword{and}}}[]
  1665 \rail@endplus
  1666 \rail@end
  1667 \rail@begin{1}{\isa{rule}}
  1668 \rail@term{\isa{rule}}[]
  1669 \rail@term{\isa{{\isaliteral{3A}{\isacharcolon}}}}[]
  1670 \rail@nont{\hyperlink{syntax.thmref}{\mbox{\isa{thmref}}}}[]
  1671 \rail@end
  1672 \end{railoutput}
  1673 
  1674 
  1675   \begin{description}
  1676 
  1677   \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
  1678   to reason about inductive types.  Rules are selected according to
  1679   the declarations by the \hyperlink{attribute.cases}{\mbox{\isa{cases}}} and \hyperlink{attribute.induct}{\mbox{\isa{induct}}}
  1680   attributes, cf.\ \secref{sec:cases-induct}.  The \hyperlink{command.HOL.datatype}{\mbox{\isa{\isacommand{datatype}}}} package already takes care of this.
  1681 
  1682   These unstructured tactics feature both goal addressing and dynamic
  1683   instantiation.  Note that named rule cases are \emph{not} provided
  1684   as would be by the proper \hyperlink{method.cases}{\mbox{\isa{cases}}} and \hyperlink{method.induct}{\mbox{\isa{induct}}} proof
  1685   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
  1686   statements, only the compact object-logic conclusion of the subgoal
  1687   being addressed.
  1688 
  1689   \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
  1690   forward manner.
  1691 
  1692   While \hyperlink{method.HOL.ind-cases}{\mbox{\isa{ind{\isaliteral{5F}{\isacharunderscore}}cases}}} is a proof method to apply the
  1693   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
  1694   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
  1695   be generalized before applying the resulting rule.
  1696 
  1697   \end{description}%
  1698 \end{isamarkuptext}%
  1699 \isamarkuptrue%
  1700 %
  1701 \isamarkupsection{Executable code%
  1702 }
  1703 \isamarkuptrue%
  1704 %
  1705 \begin{isamarkuptext}%
  1706 For validation purposes, it is often useful to \emph{execute}
  1707   specifications.  In principle, execution could be simulated by
  1708   Isabelle's inference kernel, i.e. by a combination of resolution and
  1709   simplification.  Unfortunately, this approach is rather inefficient.
  1710   A more efficient way of executing specifications is to translate
  1711   them into a functional programming language such as ML.
  1712 
  1713   Isabelle provides two generic frameworks to support code generation
  1714   from executable specifications.  Isabelle/HOL instantiates these
  1715   mechanisms in a way that is amenable to end-user applications.%
  1716 \end{isamarkuptext}%
  1717 \isamarkuptrue%
  1718 %
  1719 \isamarkupsubsection{The new code generator (F. Haftmann)%
  1720 }
  1721 \isamarkuptrue%
  1722 %
  1723 \begin{isamarkuptext}%
  1724 This framework generates code from functional programs
  1725   (including overloading using type classes) to SML \cite{SML}, OCaml
  1726   \cite{OCaml}, Haskell \cite{haskell-revised-report} and Scala
  1727   \cite{scala-overview-tech-report}.  Conceptually, code generation is
  1728   split up in three steps: \emph{selection} of code theorems,
  1729   \emph{translation} into an abstract executable view and
  1730   \emph{serialization} to a specific \emph{target language}.
  1731   Inductive specifications can be executed using the predicate
  1732   compiler which operates within HOL.  See \cite{isabelle-codegen} for
  1733   an introduction.
  1734 
  1735   \begin{matharray}{rcl}
  1736     \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}}} \\
  1737     \indexdef{HOL}{attribute}{code}\hypertarget{attribute.HOL.code}{\hyperlink{attribute.HOL.code}{\mbox{\isa{code}}}} & : & \isa{attribute} \\
  1738     \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}}} \\
  1739     \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}}} \\
  1740     \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}}} \\
  1741     \indexdef{HOL}{attribute}{code\_inline}\hypertarget{attribute.HOL.code-inline}{\hyperlink{attribute.HOL.code-inline}{\mbox{\isa{code{\isaliteral{5F}{\isacharunderscore}}inline}}}} & : & \isa{attribute} \\
  1742     \indexdef{HOL}{attribute}{code\_post}\hypertarget{attribute.HOL.code-post}{\hyperlink{attribute.HOL.code-post}{\mbox{\isa{code{\isaliteral{5F}{\isacharunderscore}}post}}}} & : & \isa{attribute} \\
  1743     \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}}} \\
  1744     \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}}} \\
  1745     \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}}} \\
  1746     \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}}} \\
  1747     \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}}} \\
  1748     \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}}} \\
  1749     \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}}} \\
  1750     \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}}} \\
  1751     \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}}} \\
  1752     \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}}} \\
  1753     \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}}} \\
  1754     \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}}}
  1755   \end{matharray}
  1756 
  1757   \begin{railoutput}
  1758 \rail@begin{11}{}
  1759 \rail@term{\hyperlink{command.HOL.export-code}{\mbox{\isa{\isacommand{export{\isaliteral{5F}{\isacharunderscore}}code}}}}}[]
  1760 \rail@plus
  1761 \rail@nont{\isa{constexpr}}[]
  1762 \rail@nextplus{1}
  1763 \rail@endplus
  1764 \rail@cr{3}
  1765 \rail@bar
  1766 \rail@nextbar{4}
  1767 \rail@plus
  1768 \rail@term{\isa{\isakeyword{in}}}[]
  1769 \rail@nont{\isa{target}}[]
  1770 \rail@bar
  1771 \rail@nextbar{5}
  1772 \rail@term{\isa{\isakeyword{module{\isaliteral{5F}{\isacharunderscore}}name}}}[]
  1773 \rail@nont{\hyperlink{syntax.string}{\mbox{\isa{string}}}}[]
  1774 \rail@endbar
  1775 \rail@cr{7}
  1776 \rail@bar
  1777 \rail@nextbar{8}
  1778 \rail@term{\isa{\isakeyword{file}}}[]
  1779 \rail@bar
  1780 \rail@nont{\hyperlink{syntax.string}{\mbox{\isa{string}}}}[]
  1781 \rail@nextbar{9}
  1782 \rail@term{\isa{{\isaliteral{2D}{\isacharminus}}}}[]
  1783 \rail@endbar
  1784 \rail@endbar
  1785 \rail@bar
  1786 \rail@nextbar{8}
  1787 \rail@term{\isa{{\isaliteral{28}{\isacharparenleft}}}}[]
  1788 \rail@nont{\isa{args}}[]
  1789 \rail@term{\isa{{\isaliteral{29}{\isacharparenright}}}}[]
  1790 \rail@endbar
  1791 \rail@nextplus{10}
  1792 \rail@endplus
  1793 \rail@endbar
  1794 \rail@end
  1795 \rail@begin{1}{\isa{const}}
  1796 \rail@nont{\hyperlink{syntax.term}{\mbox{\isa{term}}}}[]
  1797 \rail@end
  1798 \rail@begin{3}{\isa{constexpr}}
  1799 \rail@bar
  1800 \rail@nont{\isa{const}}[]
  1801 \rail@nextbar{1}
  1802 \rail@term{\isa{name{\isaliteral{2E}{\isachardot}}{\isaliteral{5F}{\isacharunderscore}}}}[]
  1803 \rail@nextbar{2}
  1804 \rail@term{\isa{{\isaliteral{5F}{\isacharunderscore}}}}[]
  1805 \rail@endbar
  1806 \rail@end
  1807 \rail@begin{1}{\isa{typeconstructor}}
  1808 \rail@nont{\hyperlink{syntax.nameref}{\mbox{\isa{nameref}}}}[]
  1809 \rail@end
  1810 \rail@begin{1}{\isa{class}}
  1811 \rail@nont{\hyperlink{syntax.nameref}{\mbox{\isa{nameref}}}}[]
  1812 \rail@end
  1813 \rail@begin{4}{\isa{target}}
  1814 \rail@bar
  1815 \rail@term{\isa{SML}}[]
  1816 \rail@nextbar{1}
  1817 \rail@term{\isa{OCaml}}[]
  1818 \rail@nextbar{2}
  1819 \rail@term{\isa{Haskell}}[]
  1820 \rail@nextbar{3}
  1821 \rail@term{\isa{Scala}}[]
  1822 \rail@endbar
  1823 \rail@end
  1824 \rail@begin{4}{}
  1825 \rail@term{\hyperlink{attribute.HOL.code}{\mbox{\isa{code}}}}[]
  1826 \rail@bar
  1827 \rail@nextbar{1}
  1828 \rail@bar
  1829 \rail@term{\isa{del}}[]
  1830 \rail@nextbar{2}
  1831 \rail@term{\isa{abstype}}[]
  1832 \rail@nextbar{3}
  1833 \rail@term{\isa{abstract}}[]
  1834 \rail@endbar
  1835 \rail@endbar
  1836 \rail@end
  1837 \rail@begin{2}{}
  1838 \rail@term{\hyperlink{command.HOL.code-abort}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}abort}}}}}[]
  1839 \rail@plus
  1840 \rail@nont{\isa{const}}[]
  1841 \rail@nextplus{1}
  1842 \rail@endplus
  1843 \rail@end
  1844 \rail@begin{2}{}
  1845 \rail@term{\hyperlink{command.HOL.code-datatype}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}datatype}}}}}[]
  1846 \rail@plus
  1847 \rail@nont{\isa{const}}[]
  1848 \rail@nextplus{1}
  1849 \rail@endplus
  1850 \rail@end
  1851 \rail@begin{2}{}
  1852 \rail@term{\hyperlink{attribute.HOL.code-inline}{\mbox{\isa{code{\isaliteral{5F}{\isacharunderscore}}inline}}}}[]
  1853 \rail@bar
  1854 \rail@nextbar{1}
  1855 \rail@term{\isa{del}}[]
  1856 \rail@endbar
  1857 \rail@end
  1858 \rail@begin{2}{}
  1859 \rail@term{\hyperlink{attribute.HOL.code-post}{\mbox{\isa{code{\isaliteral{5F}{\isacharunderscore}}post}}}}[]
  1860 \rail@bar
  1861 \rail@nextbar{1}
  1862 \rail@term{\isa{del}}[]
  1863 \rail@endbar
  1864 \rail@end
  1865 \rail@begin{3}{}
  1866 \rail@term{\hyperlink{command.HOL.code-thms}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}thms}}}}}[]
  1867 \rail@bar
  1868 \rail@nextbar{1}
  1869 \rail@plus
  1870 \rail@nont{\isa{constexpr}}[]
  1871 \rail@nextplus{2}
  1872 \rail@endplus
  1873 \rail@endbar
  1874 \rail@end
  1875 \rail@begin{3}{}
  1876 \rail@term{\hyperlink{command.HOL.code-deps}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}deps}}}}}[]
  1877 \rail@bar
  1878 \rail@nextbar{1}
  1879 \rail@plus
  1880 \rail@nont{\isa{constexpr}}[]
  1881 \rail@nextplus{2}
  1882 \rail@endplus
  1883 \rail@endbar
  1884 \rail@end
  1885 \rail@begin{7}{}
  1886 \rail@term{\hyperlink{command.HOL.code-const}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}const}}}}}[]
  1887 \rail@plus
  1888 \rail@nont{\isa{const}}[]
  1889 \rail@nextplus{1}
  1890 \rail@cterm{\isa{\isakeyword{and}}}[]
  1891 \rail@endplus
  1892 \rail@cr{3}
  1893 \rail@plus
  1894 \rail@term{\isa{{\isaliteral{28}{\isacharparenleft}}}}[]
  1895 \rail@nont{\isa{target}}[]
  1896 \rail@plus
  1897 \rail@bar
  1898 \rail@nextbar{4}
  1899 \rail@nont{\isa{syntax}}[]
  1900 \rail@endbar
  1901 \rail@nextplus{5}
  1902 \rail@cterm{\isa{\isakeyword{and}}}[]
  1903 \rail@endplus
  1904 \rail@term{\isa{{\isaliteral{29}{\isacharparenright}}}}[]
  1905 \rail@nextplus{6}
  1906 \rail@endplus
  1907 \rail@end
  1908 \rail@begin{7}{}
  1909 \rail@term{\hyperlink{command.HOL.code-type}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}type}}}}}[]
  1910 \rail@plus
  1911 \rail@nont{\isa{typeconstructor}}[]
  1912 \rail@nextplus{1}
  1913 \rail@cterm{\isa{\isakeyword{and}}}[]
  1914 \rail@endplus
  1915 \rail@cr{3}
  1916 \rail@plus
  1917 \rail@term{\isa{{\isaliteral{28}{\isacharparenleft}}}}[]
  1918 \rail@nont{\isa{target}}[]
  1919 \rail@plus
  1920 \rail@bar
  1921 \rail@nextbar{4}
  1922 \rail@nont{\isa{syntax}}[]
  1923 \rail@endbar
  1924 \rail@nextplus{5}
  1925 \rail@cterm{\isa{\isakeyword{and}}}[]
  1926 \rail@endplus
  1927 \rail@term{\isa{{\isaliteral{29}{\isacharparenright}}}}[]
  1928 \rail@nextplus{6}
  1929 \rail@endplus
  1930 \rail@end
  1931 \rail@begin{9}{}
  1932 \rail@term{\hyperlink{command.HOL.code-class}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}class}}}}}[]
  1933 \rail@plus
  1934 \rail@nont{\isa{class}}[]
  1935 \rail@nextplus{1}
  1936 \rail@cterm{\isa{\isakeyword{and}}}[]
  1937 \rail@endplus
  1938 \rail@cr{3}
  1939 \rail@plus
  1940 \rail@term{\isa{{\isaliteral{28}{\isacharparenleft}}}}[]
  1941 \rail@nont{\isa{target}}[]
  1942 \rail@cr{5}
  1943 \rail@plus
  1944 \rail@bar
  1945 \rail@nextbar{6}
  1946 \rail@nont{\hyperlink{syntax.string}{\mbox{\isa{string}}}}[]
  1947 \rail@endbar
  1948 \rail@nextplus{7}
  1949 \rail@cterm{\isa{\isakeyword{and}}}[]
  1950 \rail@endplus
  1951 \rail@term{\isa{{\isaliteral{29}{\isacharparenright}}}}[]
  1952 \rail@nextplus{8}
  1953 \rail@endplus
  1954 \rail@end
  1955 \rail@begin{7}{}
  1956 \rail@term{\hyperlink{command.HOL.code-instance}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}instance}}}}}[]
  1957 \rail@plus
  1958 \rail@nont{\isa{typeconstructor}}[]
  1959 \rail@term{\isa{{\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}}}[]
  1960 \rail@nont{\isa{class}}[]
  1961 \rail@nextplus{1}
  1962 \rail@cterm{\isa{\isakeyword{and}}}[]
  1963 \rail@endplus
  1964 \rail@cr{3}
  1965 \rail@plus
  1966 \rail@term{\isa{{\isaliteral{28}{\isacharparenleft}}}}[]
  1967 \rail@nont{\isa{target}}[]
  1968 \rail@plus
  1969 \rail@bar
  1970 \rail@nextbar{4}
  1971 \rail@term{\isa{{\isaliteral{2D}{\isacharminus}}}}[]
  1972 \rail@endbar
  1973 \rail@nextplus{5}
  1974 \rail@cterm{\isa{\isakeyword{and}}}[]
  1975 \rail@endplus
  1976 \rail@term{\isa{{\isaliteral{29}{\isacharparenright}}}}[]
  1977 \rail@nextplus{6}
  1978 \rail@endplus
  1979 \rail@end
  1980 \rail@begin{2}{}
  1981 \rail@term{\hyperlink{command.HOL.code-reserved}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}reserved}}}}}[]
  1982 \rail@nont{\isa{target}}[]
  1983 \rail@plus
  1984 \rail@nont{\hyperlink{syntax.string}{\mbox{\isa{string}}}}[]
  1985 \rail@nextplus{1}
  1986 \rail@endplus
  1987 \rail@end
  1988 \rail@begin{1}{}
  1989 \rail@term{\hyperlink{command.HOL.code-monad}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}monad}}}}}[]
  1990 \rail@nont{\isa{const}}[]
  1991 \rail@nont{\isa{const}}[]
  1992 \rail@nont{\isa{target}}[]
  1993 \rail@end
  1994 \rail@begin{2}{}
  1995 \rail@term{\hyperlink{command.HOL.code-include}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}include}}}}}[]
  1996 \rail@nont{\isa{target}}[]
  1997 \rail@nont{\hyperlink{syntax.string}{\mbox{\isa{string}}}}[]
  1998 \rail@bar
  1999 \rail@nont{\hyperlink{syntax.string}{\mbox{\isa{string}}}}[]
  2000 \rail@nextbar{1}
  2001 \rail@term{\isa{{\isaliteral{2D}{\isacharminus}}}}[]
  2002 \rail@endbar
  2003 \rail@end
  2004 \rail@begin{2}{}
  2005 \rail@term{\hyperlink{command.HOL.code-modulename}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}modulename}}}}}[]
  2006 \rail@nont{\isa{target}}[]
  2007 \rail@plus
  2008 \rail@nont{\hyperlink{syntax.string}{\mbox{\isa{string}}}}[]
  2009 \rail@nont{\hyperlink{syntax.string}{\mbox{\isa{string}}}}[]
  2010 \rail@nextplus{1}
  2011 \rail@endplus
  2012 \rail@end
  2013 \rail@begin{11}{}
  2014 \rail@term{\hyperlink{command.HOL.code-reflect}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}reflect}}}}}[]
  2015 \rail@nont{\hyperlink{syntax.string}{\mbox{\isa{string}}}}[]
  2016 \rail@cr{2}
  2017 \rail@bar
  2018 \rail@nextbar{3}
  2019 \rail@term{\isa{\isakeyword{datatypes}}}[]
  2020 \rail@nont{\hyperlink{syntax.string}{\mbox{\isa{string}}}}[]
  2021 \rail@term{\isa{{\isaliteral{3D}{\isacharequal}}}}[]
  2022 \rail@bar
  2023 \rail@term{\isa{{\isaliteral{5F}{\isacharunderscore}}}}[]
  2024 \rail@nextbar{4}
  2025 \rail@plus
  2026 \rail@plus
  2027 \rail@nont{\hyperlink{syntax.string}{\mbox{\isa{string}}}}[]
  2028 \rail@nextplus{5}
  2029 \rail@cterm{\isa{{\isaliteral{7C}{\isacharbar}}}}[]
  2030 \rail@endplus
  2031 \rail@nextplus{6}
  2032 \rail@cterm{\isa{\isakeyword{and}}}[]
  2033 \rail@endplus
  2034 \rail@endbar
  2035 \rail@endbar
  2036 \rail@cr{8}
  2037 \rail@bar
  2038 \rail@nextbar{9}
  2039 \rail@term{\isa{\isakeyword{functions}}}[]
  2040 \rail@plus
  2041 \rail@nont{\hyperlink{syntax.string}{\mbox{\isa{string}}}}[]
  2042 \rail@nextplus{10}
  2043 \rail@endplus
  2044 \rail@endbar
  2045 \rail@bar
  2046 \rail@nextbar{9}
  2047 \rail@term{\isa{\isakeyword{file}}}[]
  2048 \rail@nont{\hyperlink{syntax.string}{\mbox{\isa{string}}}}[]
  2049 \rail@endbar
  2050 \rail@end
  2051 \rail@begin{4}{\isa{syntax}}
  2052 \rail@bar
  2053 \rail@nont{\hyperlink{syntax.string}{\mbox{\isa{string}}}}[]
  2054 \rail@nextbar{1}
  2055 \rail@bar
  2056 \rail@term{\isa{\isakeyword{infix}}}[]
  2057 \rail@nextbar{2}
  2058 \rail@term{\isa{\isakeyword{infixl}}}[]
  2059 \rail@nextbar{3}
  2060 \rail@term{\isa{\isakeyword{infixr}}}[]
  2061 \rail@endbar
  2062 \rail@nont{\hyperlink{syntax.nat}{\mbox{\isa{nat}}}}[]
  2063 \rail@nont{\hyperlink{syntax.string}{\mbox{\isa{string}}}}[]
  2064 \rail@endbar
  2065 \rail@end
  2066 \end{railoutput}
  2067 
  2068 
  2069   \begin{description}
  2070 
  2071   \item \hyperlink{command.HOL.export-code}{\mbox{\isa{\isacommand{export{\isaliteral{5F}{\isacharunderscore}}code}}}} generates code for a given list
  2072   of constants in the specified target language(s).  If no
  2073   serialization instruction is given, only abstract code is generated
  2074   internally.
  2075 
  2076   Constants may be specified by giving them literally, referring to
  2077   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
  2078   available by giving \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{2A}{\isacharasterisk}}{\isaliteral{22}{\isachardoublequote}}}.
  2079 
  2080   By default, for each involved theory one corresponding name space
  2081   module is generated.  Alternativly, a module name may be specified
  2082   after the \hyperlink{keyword.module-name}{\mbox{\isa{\isakeyword{module{\isaliteral{5F}{\isacharunderscore}}name}}}} keyword; then \emph{all} code is
  2083   placed in this module.
  2084 
  2085   For \emph{SML}, \emph{OCaml} and \emph{Scala} the file specification
  2086   refers to a single file; for \emph{Haskell}, it refers to a whole
  2087   directory, where code is generated in multiple files reflecting the
  2088   module hierarchy.  Omitting the file specification denotes standard
  2089   output.
  2090 
  2091   Serializers take an optional list of arguments in parentheses.  For
  2092   \emph{SML} and \emph{OCaml}, ``\isa{no{\isaliteral{5F}{\isacharunderscore}}signatures}`` omits
  2093   explicit module signatures.
  2094 
  2095   For \emph{Haskell} a module name prefix may be given using the
  2096   ``\isa{{\isaliteral{22}{\isachardoublequote}}root{\isaliteral{3A}{\isacharcolon}}{\isaliteral{22}{\isachardoublequote}}}'' argument; ``\isa{string{\isaliteral{5F}{\isacharunderscore}}classes}'' adds a
  2097   ``\verb|deriving (Read, Show)|'' clause to each appropriate
  2098   datatype declaration.
  2099 
  2100   \item \hyperlink{attribute.HOL.code}{\mbox{\isa{code}}} explicitly selects (or with option
  2101   ``\isa{{\isaliteral{22}{\isachardoublequote}}del{\isaliteral{22}{\isachardoublequote}}}'' deselects) a code equation for code generation.
  2102   Usually packages introducing code equations provide a reasonable
  2103   default setup for selection.  Variants \isa{{\isaliteral{22}{\isachardoublequote}}code\ abstype{\isaliteral{22}{\isachardoublequote}}} and
  2104   \isa{{\isaliteral{22}{\isachardoublequote}}code\ abstract{\isaliteral{22}{\isachardoublequote}}} declare abstract datatype certificates or
  2105   code equations on abstract datatype representations respectively.
  2106 
  2107   \item \hyperlink{command.HOL.code-abort}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}abort}}}} declares constants which are not
  2108   required to have a definition by means of code equations; if needed
  2109   these are implemented by program abort instead.
  2110 
  2111   \item \hyperlink{command.HOL.code-datatype}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}datatype}}}} specifies a constructor set
  2112   for a logical type.
  2113 
  2114   \item \hyperlink{command.HOL.print-codesetup}{\mbox{\isa{\isacommand{print{\isaliteral{5F}{\isacharunderscore}}codesetup}}}} gives an overview on
  2115   selected code equations and code generator datatypes.
  2116 
  2117   \item \hyperlink{attribute.HOL.code-inline}{\mbox{\isa{code{\isaliteral{5F}{\isacharunderscore}}inline}}} declares (or with option
  2118   ``\isa{{\isaliteral{22}{\isachardoublequote}}del{\isaliteral{22}{\isachardoublequote}}}'' removes) inlining theorems which are applied as
  2119   rewrite rules to any code equation during preprocessing.
  2120 
  2121   \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
  2122   result of an evaluation.
  2123 
  2124   \item \hyperlink{command.HOL.print-codeproc}{\mbox{\isa{\isacommand{print{\isaliteral{5F}{\isacharunderscore}}codeproc}}}} prints the setup of the code
  2125   generator preprocessor.
  2126 
  2127   \item \hyperlink{command.HOL.code-thms}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}thms}}}} prints a list of theorems
  2128   representing the corresponding program containing all given
  2129   constants after preprocessing.
  2130 
  2131   \item \hyperlink{command.HOL.code-deps}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}deps}}}} visualizes dependencies of
  2132   theorems representing the corresponding program containing all given
  2133   constants after preprocessing.
  2134 
  2135   \item \hyperlink{command.HOL.code-const}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}const}}}} associates a list of constants
  2136   with target-specific serializations; omitting a serialization
  2137   deletes an existing serialization.
  2138 
  2139   \item \hyperlink{command.HOL.code-type}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}type}}}} associates a list of type
  2140   constructors with target-specific serializations; omitting a
  2141   serialization deletes an existing serialization.
  2142 
  2143   \item \hyperlink{command.HOL.code-class}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}class}}}} associates a list of classes
  2144   with target-specific class names; omitting a serialization deletes
  2145   an existing serialization.  This applies only to \emph{Haskell}.
  2146 
  2147   \item \hyperlink{command.HOL.code-instance}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}instance}}}} declares a list of type
  2148   constructor / class instance relations as ``already present'' for a
  2149   given target.  Omitting a ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{2D}{\isacharminus}}{\isaliteral{22}{\isachardoublequote}}}'' deletes an existing
  2150   ``already present'' declaration.  This applies only to
  2151   \emph{Haskell}.
  2152 
  2153   \item \hyperlink{command.HOL.code-reserved}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}reserved}}}} declares a list of names as
  2154   reserved for a given target, preventing it to be shadowed by any
  2155   generated code.
  2156 
  2157   \item \hyperlink{command.HOL.code-monad}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}monad}}}} provides an auxiliary mechanism
  2158   to generate monadic code for Haskell.
  2159 
  2160   \item \hyperlink{command.HOL.code-include}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}include}}}} adds arbitrary named content
  2161   (``include'') to generated code.  A ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{2D}{\isacharminus}}{\isaliteral{22}{\isachardoublequote}}}'' as last argument
  2162   will remove an already added ``include''.
  2163 
  2164   \item \hyperlink{command.HOL.code-modulename}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}modulename}}}} declares aliasings from one
  2165   module name onto another.
  2166 
  2167   \item \hyperlink{command.HOL.code-reflect}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}reflect}}}} without a ``\isa{{\isaliteral{22}{\isachardoublequote}}file{\isaliteral{22}{\isachardoublequote}}}''
  2168   argument compiles code into the system runtime environment and
  2169   modifies the code generator setup that future invocations of system
  2170   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
  2171   entities.  With a ``\isa{{\isaliteral{22}{\isachardoublequote}}file{\isaliteral{22}{\isachardoublequote}}}'' argument, the corresponding code
  2172   is generated into that specified file without modifying the code
  2173   generator setup.
  2174 
  2175   \end{description}%
  2176 \end{isamarkuptext}%
  2177 \isamarkuptrue%
  2178 %
  2179 \isamarkupsubsection{The old code generator (S. Berghofer)%
  2180 }
  2181 \isamarkuptrue%
  2182 %
  2183 \begin{isamarkuptext}%
  2184 This framework generates code from both functional and
  2185   relational programs to SML, as explained below.
  2186 
  2187   \begin{matharray}{rcl}
  2188     \indexdef{}{command}{code\_module}\hypertarget{command.code-module}{\hyperlink{command.code-module}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}module}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\
  2189     \indexdef{}{command}{code\_library}\hypertarget{command.code-library}{\hyperlink{command.code-library}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}library}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\
  2190     \indexdef{}{command}{consts\_code}\hypertarget{command.consts-code}{\hyperlink{command.consts-code}{\mbox{\isa{\isacommand{consts{\isaliteral{5F}{\isacharunderscore}}code}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\
  2191     \indexdef{}{command}{types\_code}\hypertarget{command.types-code}{\hyperlink{command.types-code}{\mbox{\isa{\isacommand{types{\isaliteral{5F}{\isacharunderscore}}code}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\
  2192     \indexdef{}{attribute}{code}\hypertarget{attribute.code}{\hyperlink{attribute.code}{\mbox{\isa{code}}}} & : & \isa{attribute} \\
  2193   \end{matharray}
  2194 
  2195   \begin{railoutput}
  2196 \rail@begin{11}{}
  2197 \rail@bar
  2198 \rail@term{\hyperlink{command.code-module}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}module}}}}}[]
  2199 \rail@nextbar{1}
  2200 \rail@term{\hyperlink{command.code-library}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}library}}}}}[]
  2201 \rail@endbar
  2202 \rail@bar
  2203 \rail@nextbar{1}
  2204 \rail@nont{\isa{modespec}}[]
  2205 \rail@endbar
  2206 \rail@bar
  2207 \rail@nextbar{1}
  2208 \rail@nont{\hyperlink{syntax.name}{\mbox{\isa{name}}}}[]
  2209 \rail@endbar
  2210 \rail@cr{3}
  2211 \rail@bar
  2212 \rail@nextbar{4}
  2213 \rail@term{\isa{\isakeyword{file}}}[]
  2214 \rail@nont{\isa{name}}[]
  2215 \rail@endbar
  2216 \rail@bar
  2217 \rail@nextbar{4}
  2218 \rail@term{\isa{\isakeyword{imports}}}[]
  2219 \rail@plus
  2220 \rail@nont{\hyperlink{syntax.name}{\mbox{\isa{name}}}}[]
  2221 \rail@nextplus{5}
  2222 \rail@endplus
  2223 \rail@endbar
  2224 \rail@cr{7}
  2225 \rail@term{\isa{\isakeyword{contains}}}[]
  2226 \rail@bar
  2227 \rail@plus
  2228 \rail@nont{\hyperlink{syntax.name}{\mbox{\isa{name}}}}[]
  2229 \rail@term{\isa{{\isaliteral{3D}{\isacharequal}}}}[]
  2230 \rail@nont{\hyperlink{syntax.term}{\mbox{\isa{term}}}}[]
  2231 \rail@nextplus{8}
  2232 \rail@endplus
  2233 \rail@nextbar{9}
  2234 \rail@plus
  2235 \rail@nont{\hyperlink{syntax.term}{\mbox{\isa{term}}}}[]
  2236 \rail@nextplus{10}
  2237 \rail@endplus
  2238 \rail@endbar
  2239 \rail@end
  2240 \rail@begin{2}{\isa{modespec}}
  2241 \rail@term{\isa{{\isaliteral{28}{\isacharparenleft}}}}[]
  2242 \rail@plus
  2243 \rail@nextplus{1}
  2244 \rail@cnont{\hyperlink{syntax.name}{\mbox{\isa{name}}}}[]
  2245 \rail@endplus
  2246 \rail@term{\isa{{\isaliteral{29}{\isacharparenright}}}}[]
  2247 \rail@end
  2248 \rail@begin{2}{}
  2249 \rail@term{\hyperlink{command.HOL.consts-code}{\mbox{\isa{\isacommand{consts{\isaliteral{5F}{\isacharunderscore}}code}}}}}[]
  2250 \rail@plus
  2251 \rail@nont{\isa{codespec}}[]
  2252 \rail@nextplus{1}
  2253 \rail@endplus
  2254 \rail@end
  2255 \rail@begin{2}{\isa{codespec}}
  2256 \rail@nont{\isa{const}}[]
  2257 \rail@nont{\isa{template}}[]
  2258 \rail@bar
  2259 \rail@nextbar{1}
  2260 \rail@nont{\isa{attachment}}[]
  2261 \rail@endbar
  2262 \rail@end
  2263 \rail@begin{2}{}
  2264 \rail@term{\hyperlink{command.HOL.types-code}{\mbox{\isa{\isacommand{types{\isaliteral{5F}{\isacharunderscore}}code}}}}}[]
  2265 \rail@plus
  2266 \rail@nont{\isa{tycodespec}}[]
  2267 \rail@nextplus{1}
  2268 \rail@endplus
  2269 \rail@end
  2270 \rail@begin{2}{\isa{tycodespec}}
  2271 \rail@nont{\hyperlink{syntax.name}{\mbox{\isa{name}}}}[]
  2272 \rail@nont{\isa{template}}[]
  2273 \rail@bar
  2274 \rail@nextbar{1}
  2275 \rail@nont{\isa{attachment}}[]
  2276 \rail@endbar
  2277 \rail@end
  2278 \rail@begin{1}{\isa{const}}
  2279 \rail@nont{\hyperlink{syntax.term}{\mbox{\isa{term}}}}[]
  2280 \rail@end
  2281 \rail@begin{1}{\isa{template}}
  2282 \rail@term{\isa{{\isaliteral{28}{\isacharparenleft}}}}[]
  2283 \rail@nont{\hyperlink{syntax.string}{\mbox{\isa{string}}}}[]
  2284 \rail@term{\isa{{\isaliteral{29}{\isacharparenright}}}}[]
  2285 \rail@end
  2286 \rail@begin{2}{\isa{attachment}}
  2287 \rail@term{\isa{attach}}[]
  2288 \rail@bar
  2289 \rail@nextbar{1}
  2290 \rail@nont{\isa{modespec}}[]
  2291 \rail@endbar
  2292 \rail@term{\isa{{\isaliteral{7B}{\isacharbraceleft}}}}[]
  2293 \rail@nont{\hyperlink{syntax.text}{\mbox{\isa{text}}}}[]
  2294 \rail@term{\isa{{\isaliteral{7D}{\isacharbraceright}}}}[]
  2295 \rail@end
  2296 \rail@begin{2}{}
  2297 \rail@term{\hyperlink{attribute.code}{\mbox{\isa{code}}}}[]
  2298 \rail@bar
  2299 \rail@nextbar{1}
  2300 \rail@nont{\isa{name}}[]
  2301 \rail@endbar
  2302 \rail@end
  2303 \end{railoutput}%
  2304 \end{isamarkuptext}%
  2305 \isamarkuptrue%
  2306 %
  2307 \isamarkupsubsubsection{Invoking the code generator%
  2308 }
  2309 \isamarkuptrue%
  2310 %
  2311 \begin{isamarkuptext}%
  2312 The code generator is invoked via the \hyperlink{command.code-module}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}module}}}}
  2313   and \hyperlink{command.code-library}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}library}}}} commands, which correspond to
  2314   \emph{incremental} and \emph{modular} code generation, respectively.
  2315 
  2316   \begin{description}
  2317 
  2318   \item [Modular] For each theory, an ML structure is generated,
  2319   containing the code generated from the constants defined in this
  2320   theory.
  2321 
  2322   \item [Incremental] All the generated code is emitted into the same
  2323   structure.  This structure may import code from previously generated
  2324   structures, which can be specified via \hyperlink{keyword.imports}{\mbox{\isa{\isakeyword{imports}}}}.
  2325   Moreover, the generated structure may also be referred to in later
  2326   invocations of the code generator.
  2327 
  2328   \end{description}
  2329 
  2330   After the \hyperlink{command.code-module}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}module}}}} and \hyperlink{command.code-library}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}library}}}}
  2331   keywords, the user may specify an optional list of ``modes'' in
  2332   parentheses. These can be used to instruct the code generator to
  2333   emit additional code for special purposes, e.g.\ functions for
  2334   converting elements of generated datatypes to Isabelle terms, or
  2335   test data generators. The list of modes is followed by a module
  2336   name.  The module name is optional for modular code generation, but
  2337   must be specified for incremental code generation.
  2338 
  2339   The code can either be written to a file, in which case a file name
  2340   has to be specified after the \hyperlink{keyword.file}{\mbox{\isa{\isakeyword{file}}}} keyword, or be loaded
  2341   directly into Isabelle's ML environment. In the latter case, the
  2342   \hyperlink{command.ML}{\mbox{\isa{\isacommand{ML}}}} theory command can be used to inspect the results
  2343   interactively, for example.
  2344 
  2345   The terms from which to generate code can be specified after the
  2346   \hyperlink{keyword.contains}{\mbox{\isa{\isakeyword{contains}}}} keyword, either as a list of bindings, or just
  2347   as a list of terms. In the latter case, the code generator just
  2348   produces code for all constants and types occuring in the term, but
  2349   does not bind the compiled terms to ML identifiers.
  2350 
  2351   Here is an example:%
  2352 \end{isamarkuptext}%
  2353 \isamarkuptrue%
  2354 \isacommand{code{\isaliteral{5F}{\isacharunderscore}}module}\isamarkupfalse%
  2355 \ Test\isanewline
  2356 \isakeyword{contains}\ test\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{22}{\isachardoublequoteopen}}foldl\ op\ {\isaliteral{2B}{\isacharplus}}\ {\isaliteral{28}{\isacharparenleft}}{\isadigit{0}}\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ int{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5B}{\isacharbrackleft}}{\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isadigit{2}}{\isaliteral{2C}{\isacharcomma}}\ {\isadigit{3}}{\isaliteral{2C}{\isacharcomma}}\ {\isadigit{4}}{\isaliteral{2C}{\isacharcomma}}\ {\isadigit{5}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{22}{\isachardoublequoteclose}}%
  2357 \begin{isamarkuptext}%
  2358 \noindent This binds the result of compiling the given term to
  2359   the ML identifier \verb|Test.test|.%
  2360 \end{isamarkuptext}%
  2361 \isamarkuptrue%
  2362 %
  2363 \isadelimML
  2364 %
  2365 \endisadelimML
  2366 %
  2367 \isatagML
  2368 \isacommand{ML}\isamarkupfalse%
  2369 \ {\isaliteral{7B2A}{\isacharverbatimopen}}\ %
  2370 \isaantiq
  2371 assert{}%
  2372 \endisaantiq
  2373 \ {\isaliteral{28}{\isacharparenleft}}Test{\isaliteral{2E}{\isachardot}}test\ {\isaliteral{3D}{\isacharequal}}\ {\isadigit{1}}{\isadigit{5}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{2A7D}{\isacharverbatimclose}}%
  2374 \endisatagML
  2375 {\isafoldML}%
  2376 %
  2377 \isadelimML
  2378 %
  2379 \endisadelimML
  2380 %
  2381 \isamarkupsubsubsection{Configuring the code generator%
  2382 }
  2383 \isamarkuptrue%
  2384 %
  2385 \begin{isamarkuptext}%
  2386 When generating code for a complex term, the code generator
  2387   recursively calls itself for all subterms.  When it arrives at a
  2388   constant, the default strategy of the code generator is to look up
  2389   its definition and try to generate code for it.  Constants which
  2390   have no definitions that are immediately executable, may be
  2391   associated with a piece of ML code manually using the \indexref{}{command}{consts\_code}\hyperlink{command.consts-code}{\mbox{\isa{\isacommand{consts{\isaliteral{5F}{\isacharunderscore}}code}}}} command.  It takes a list whose elements consist of a
  2392   constant (given in usual term syntax -- an explicit type constraint
  2393   accounts for overloading), and a mixfix template describing the ML
  2394   code. The latter is very much the same as the mixfix templates used
  2395   when declaring new constants.  The most notable difference is that
  2396   terms may be included in the ML template using antiquotation
  2397   brackets \verb|{|\verb|*|~\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{2E}{\isachardot}}{\isaliteral{2E}{\isachardot}}{\isaliteral{2E}{\isachardot}}{\isaliteral{22}{\isachardoublequote}}}~\verb|*|\verb|}|.
  2398 
  2399   A similar mechanism is available for types: \indexref{}{command}{types\_code}\hyperlink{command.types-code}{\mbox{\isa{\isacommand{types{\isaliteral{5F}{\isacharunderscore}}code}}}} associates type constructors with specific ML code.
  2400 
  2401   For example, the following declarations copied from \verb|~~/src/HOL/Product_Type.thy| describe how the product type of
  2402   Isabelle/HOL should be compiled to ML.%
  2403 \end{isamarkuptext}%
  2404 \isamarkuptrue%
  2405 \isacommand{typedecl}\isamarkupfalse%
  2406 \ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{27}{\isacharprime}}a{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{27}{\isacharprime}}b{\isaliteral{29}{\isacharparenright}}\ prod\isanewline
  2407 \isacommand{consts}\isamarkupfalse%
  2408 \ Pair\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{27}{\isacharprime}}a\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}b\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{27}{\isacharprime}}a{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{27}{\isacharprime}}b{\isaliteral{29}{\isacharparenright}}\ prod{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
  2409 \isanewline
  2410 \isacommand{types{\isaliteral{5F}{\isacharunderscore}}code}\isamarkupfalse%
  2411 \ prod\ \ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}{\isaliteral{5F}{\isacharunderscore}}\ {\isaliteral{2A}{\isacharasterisk}}{\isaliteral{2F}{\isacharslash}}\ {\isaliteral{5F}{\isacharunderscore}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}{\isaliteral{29}{\isacharparenright}}\isanewline
  2412 \isacommand{consts{\isaliteral{5F}{\isacharunderscore}}code}\isamarkupfalse%
  2413 \ Pair\ \ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}{\isaliteral{5F}{\isacharunderscore}}{\isaliteral{2C}{\isacharcomma}}{\isaliteral{2F}{\isacharslash}}\ {\isaliteral{5F}{\isacharunderscore}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}{\isaliteral{29}{\isacharparenright}}%
  2414 \begin{isamarkuptext}%
  2415 Sometimes, the code associated with a constant or type may
  2416   need to refer to auxiliary functions, which have to be emitted when
  2417   the constant is used. Code for such auxiliary functions can be
  2418   declared using \hyperlink{keyword.attach}{\mbox{\isa{\isakeyword{attach}}}}. For example, the \isa{wfrec}
  2419   function can be implemented as follows:%
  2420 \end{isamarkuptext}%
  2421 \isamarkuptrue%
  2422 \isacommand{consts{\isaliteral{5F}{\isacharunderscore}}code}\isamarkupfalse%
  2423 \ wfrec\ \ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{5C3C6D6F64756C653E}{\isasymmodule}}wfrec{\isaliteral{3F}{\isacharquery}}{\isaliteral{22}{\isachardoublequoteclose}}{\isaliteral{29}{\isacharparenright}}\ \ \isanewline
  2424 \isakeyword{attach}\ {\isaliteral{7B2A}{\isacharverbatimopen}}\ fun\ wfrec\ f\ x\ {\isaliteral{3D}{\isacharequal}}\ f\ {\isaliteral{28}{\isacharparenleft}}wfrec\ f{\isaliteral{29}{\isacharparenright}}\ x\ {\isaliteral{2A7D}{\isacharverbatimclose}}%
  2425 \begin{isamarkuptext}%
  2426 If the code containing a call to \isa{wfrec} resides in an
  2427   ML structure different from the one containing the function
  2428   definition attached to \isa{wfrec}, the name of the ML structure
  2429   (followed by a ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{2E}{\isachardot}}{\isaliteral{22}{\isachardoublequote}}}'')  is inserted in place of ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6D6F64756C653E}{\isasymmodule}}{\isaliteral{22}{\isachardoublequote}}}'' in the above template.  The ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{3F}{\isacharquery}}{\isaliteral{22}{\isachardoublequote}}}''  means that
  2430   the code generator should ignore the first argument of \isa{wfrec}, i.e.\ the termination relation, which is usually not
  2431   executable.
  2432 
  2433   \medskip Another possibility of configuring the code generator is to
  2434   register theorems to be used for code generation. Theorems can be
  2435   registered via the \hyperlink{attribute.code}{\mbox{\isa{code}}} attribute. It takes an optional
  2436   name as an argument, which indicates the format of the
  2437   theorem. Currently supported formats are equations (this is the
  2438   default when no name is specified) and horn clauses (this is
  2439   indicated by the name \texttt{ind}). The left-hand sides of
  2440   equations may only contain constructors and distinct variables,
  2441   whereas horn clauses must have the same format as introduction rules
  2442   of inductive definitions.
  2443 
  2444   The following example specifies three equations from which to
  2445   generate code for \isa{{\isaliteral{22}{\isachardoublequote}}op\ {\isaliteral{3C}{\isacharless}}{\isaliteral{22}{\isachardoublequote}}} on natural numbers (see also
  2446   \verb|~~/src/HOL/Nat.thy|).%
  2447 \end{isamarkuptext}%
  2448 \isamarkuptrue%
  2449 \isacommand{lemma}\isamarkupfalse%
  2450 \ {\isaliteral{5B}{\isacharbrackleft}}code{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}Suc\ m\ {\isaliteral{3C}{\isacharless}}\ Suc\ n{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}m\ {\isaliteral{3C}{\isacharless}}\ n{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
  2451 \ \ \isakeyword{and}\ {\isaliteral{5B}{\isacharbrackleft}}code{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}{\isaliteral{28}{\isacharparenleft}}n{\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}nat{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3C}{\isacharless}}\ {\isadigit{0}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ False{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
  2452 \ \ \isakeyword{and}\ {\isaliteral{5B}{\isacharbrackleft}}code{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}{\isadigit{0}}\ {\isaliteral{3C}{\isacharless}}\ Suc\ n{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ True{\isaliteral{22}{\isachardoublequoteclose}}%
  2453 \isadelimproof
  2454 \ %
  2455 \endisadelimproof
  2456 %
  2457 \isatagproof
  2458 \isacommand{by}\isamarkupfalse%
  2459 \ simp{\isaliteral{5F}{\isacharunderscore}}all%
  2460 \endisatagproof
  2461 {\isafoldproof}%
  2462 %
  2463 \isadelimproof
  2464 %
  2465 \endisadelimproof
  2466 %
  2467 \isamarkupsubsubsection{Specific HOL code generators%
  2468 }
  2469 \isamarkuptrue%
  2470 %
  2471 \begin{isamarkuptext}%
  2472 The basic code generator framework offered by Isabelle/Pure
  2473   has already been extended with additional code generators for
  2474   specific HOL constructs. These include datatypes, recursive
  2475   functions and inductive relations. The code generator for inductive
  2476   relations can handle expressions of the form \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{28}{\isacharparenleft}}t\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{2C}{\isacharcomma}}\ t\isaliteral{5C3C5E7375623E}{}\isactrlsub n{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C696E3E}{\isasymin}}\ r{\isaliteral{22}{\isachardoublequote}}}, where \isa{{\isaliteral{22}{\isachardoublequote}}r{\isaliteral{22}{\isachardoublequote}}} is an inductively defined relation. If at
  2477   least one of the \isa{{\isaliteral{22}{\isachardoublequote}}t\isaliteral{5C3C5E7375623E}{}\isactrlsub i{\isaliteral{22}{\isachardoublequote}}} is a dummy pattern ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5F}{\isacharunderscore}}{\isaliteral{22}{\isachardoublequote}}}'',
  2478   the above expression evaluates to a sequence of possible answers. If
  2479   all of the \isa{{\isaliteral{22}{\isachardoublequote}}t\isaliteral{5C3C5E7375623E}{}\isactrlsub i{\isaliteral{22}{\isachardoublequote}}} are proper terms, the expression evaluates
  2480   to a boolean value.
  2481 
  2482   The following example demonstrates this for beta-reduction on lambda
  2483   terms (see also \verb|~~/src/HOL/Proofs/Lambda/Lambda.thy|).%
  2484 \end{isamarkuptext}%
  2485 \isamarkuptrue%
  2486 \isacommand{datatype}\isamarkupfalse%
  2487 \ dB\ {\isaliteral{3D}{\isacharequal}}\isanewline
  2488 \ \ \ \ Var\ nat\isanewline
  2489 \ \ {\isaliteral{7C}{\isacharbar}}\ App\ dB\ dB\ \ {\isaliteral{28}{\isacharparenleft}}\isakeyword{infixl}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{5C3C6465677265653E}{\isasymdegree}}{\isaliteral{22}{\isachardoublequoteclose}}\ {\isadigit{2}}{\isadigit{0}}{\isadigit{0}}{\isaliteral{29}{\isacharparenright}}\isanewline
  2490 \ \ {\isaliteral{7C}{\isacharbar}}\ Abs\ dB\isanewline
  2491 \isanewline
  2492 \isacommand{primrec}\isamarkupfalse%
  2493 \ lift\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}dB\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ nat\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ dB{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
  2494 \isakeyword{where}\isanewline
  2495 \ \ \ \ {\isaliteral{22}{\isachardoublequoteopen}}lift\ {\isaliteral{28}{\isacharparenleft}}Var\ i{\isaliteral{29}{\isacharparenright}}\ k\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}if\ i\ {\isaliteral{3C}{\isacharless}}\ k\ then\ Var\ i\ else\ Var\ {\isaliteral{28}{\isacharparenleft}}i\ {\isaliteral{2B}{\isacharplus}}\ {\isadigit{1}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
  2496 \ \ {\isaliteral{7C}{\isacharbar}}\ {\isaliteral{22}{\isachardoublequoteopen}}lift\ {\isaliteral{28}{\isacharparenleft}}s\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ t{\isaliteral{29}{\isacharparenright}}\ k\ {\isaliteral{3D}{\isacharequal}}\ lift\ s\ k\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ lift\ t\ k{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
  2497 \ \ {\isaliteral{7C}{\isacharbar}}\ {\isaliteral{22}{\isachardoublequoteopen}}lift\ {\isaliteral{28}{\isacharparenleft}}Abs\ s{\isaliteral{29}{\isacharparenright}}\ k\ {\isaliteral{3D}{\isacharequal}}\ Abs\ {\isaliteral{28}{\isacharparenleft}}lift\ s\ {\isaliteral{28}{\isacharparenleft}}k\ {\isaliteral{2B}{\isacharplus}}\ {\isadigit{1}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
  2498 \isanewline
  2499 \isacommand{primrec}\isamarkupfalse%
  2500 \ subst\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}dB\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ dB\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ nat\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ dB{\isaliteral{22}{\isachardoublequoteclose}}\ \ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{5F}{\isacharunderscore}}{\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5F}{\isacharunderscore}}{\isaliteral{27}{\isacharprime}}{\isaliteral{2F}{\isacharslash}}{\isaliteral{5F}{\isacharunderscore}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{22}{\isachardoublequoteclose}}\ {\isaliteral{5B}{\isacharbrackleft}}{\isadigit{3}}{\isadigit{0}}{\isadigit{0}}{\isaliteral{2C}{\isacharcomma}}\ {\isadigit{0}}{\isaliteral{2C}{\isacharcomma}}\ {\isadigit{0}}{\isaliteral{5D}{\isacharbrackright}}\ {\isadigit{3}}{\isadigit{0}}{\isadigit{0}}{\isaliteral{29}{\isacharparenright}}\isanewline
  2501 \isakeyword{where}\isanewline
  2502 \ \ \ \ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}Var\ i{\isaliteral{29}{\isacharparenright}}{\isaliteral{5B}{\isacharbrackleft}}s{\isaliteral{2F}{\isacharslash}}k{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{3D}{\isacharequal}}\isanewline
  2503 \ \ \ \ \ \ {\isaliteral{28}{\isacharparenleft}}if\ k\ {\isaliteral{3C}{\isacharless}}\ i\ then\ Var\ {\isaliteral{28}{\isacharparenleft}}i\ {\isaliteral{2D}{\isacharminus}}\ {\isadigit{1}}{\isaliteral{29}{\isacharparenright}}\ else\ if\ i\ {\isaliteral{3D}{\isacharequal}}\ k\ then\ s\ else\ Var\ i{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
  2504 \ \ {\isaliteral{7C}{\isacharbar}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}t\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ u{\isaliteral{29}{\isacharparenright}}{\isaliteral{5B}{\isacharbrackleft}}s{\isaliteral{2F}{\isacharslash}}k{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{3D}{\isacharequal}}\ t{\isaliteral{5B}{\isacharbrackleft}}s{\isaliteral{2F}{\isacharslash}}k{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ u{\isaliteral{5B}{\isacharbrackleft}}s{\isaliteral{2F}{\isacharslash}}k{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
  2505 \ \ {\isaliteral{7C}{\isacharbar}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}Abs\ t{\isaliteral{29}{\isacharparenright}}{\isaliteral{5B}{\isacharbrackleft}}s{\isaliteral{2F}{\isacharslash}}k{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{3D}{\isacharequal}}\ Abs\ {\isaliteral{28}{\isacharparenleft}}t{\isaliteral{5B}{\isacharbrackleft}}lift\ s\ {\isadigit{0}}\ {\isaliteral{2F}{\isacharslash}}\ k{\isaliteral{2B}{\isacharplus}}{\isadigit{1}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
  2506 \isanewline
  2507 \isacommand{inductive}\isamarkupfalse%
  2508 \ beta\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}dB\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ dB\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ bool{\isaliteral{22}{\isachardoublequoteclose}}\ \ {\isaliteral{28}{\isacharparenleft}}\isakeyword{infixl}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isaliteral{5C3C626574613E}{\isasymbeta}}{\isaliteral{22}{\isachardoublequoteclose}}\ {\isadigit{5}}{\isadigit{0}}{\isaliteral{29}{\isacharparenright}}\isanewline
  2509 \isakeyword{where}\isanewline
  2510 \ \ \ \ beta{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}Abs\ s\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ t\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isaliteral{5C3C626574613E}{\isasymbeta}}\ s{\isaliteral{5B}{\isacharbrackleft}}t{\isaliteral{2F}{\isacharslash}}{\isadigit{0}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
  2511 \ \ {\isaliteral{7C}{\isacharbar}}\ appL{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}s\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isaliteral{5C3C626574613E}{\isasymbeta}}\ t\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ s\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ u\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isaliteral{5C3C626574613E}{\isasymbeta}}\ t\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ u{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
  2512 \ \ {\isaliteral{7C}{\isacharbar}}\ appR{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}s\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isaliteral{5C3C626574613E}{\isasymbeta}}\ t\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ u\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ s\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isaliteral{5C3C626574613E}{\isasymbeta}}\ u\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ t{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
  2513 \ \ {\isaliteral{7C}{\isacharbar}}\ abs{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}s\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isaliteral{5C3C626574613E}{\isasymbeta}}\ t\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ Abs\ s\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isaliteral{5C3C626574613E}{\isasymbeta}}\ Abs\ t{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
  2514 \isanewline
  2515 \isacommand{code{\isaliteral{5F}{\isacharunderscore}}module}\isamarkupfalse%
  2516 \ Test\isanewline
  2517 \isakeyword{contains}\isanewline
  2518 \ \ test{\isadigit{1}}\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{22}{\isachardoublequoteopen}}Abs\ {\isaliteral{28}{\isacharparenleft}}Var\ {\isadigit{0}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ Var\ {\isadigit{0}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isaliteral{5C3C626574613E}{\isasymbeta}}\ Var\ {\isadigit{0}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
  2519 \ \ test{\isadigit{2}}\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{22}{\isachardoublequoteopen}}Abs\ {\isaliteral{28}{\isacharparenleft}}Abs\ {\isaliteral{28}{\isacharparenleft}}Var\ {\isadigit{0}}\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ Var\ {\isadigit{0}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ {\isaliteral{28}{\isacharparenleft}}Abs\ {\isaliteral{28}{\isacharparenleft}}Var\ {\isadigit{0}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ Var\ {\isadigit{0}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isaliteral{5C3C626574613E}{\isasymbeta}}\ {\isaliteral{5F}{\isacharunderscore}}{\isaliteral{22}{\isachardoublequoteclose}}%
  2520 \begin{isamarkuptext}%
  2521 In the above example, \verb|Test.test1| evaluates to a boolean,
  2522   whereas \verb|Test.test2| is a lazy sequence whose elements can be
  2523   inspected separately.%
  2524 \end{isamarkuptext}%
  2525 \isamarkuptrue%
  2526 %
  2527 \isadelimML
  2528 %
  2529 \endisadelimML
  2530 %
  2531 \isatagML
  2532 \isacommand{ML}\isamarkupfalse%
  2533 \ {\isaliteral{7B2A}{\isacharverbatimopen}}\ %
  2534 \isaantiq
  2535 assert{}%
  2536 \endisaantiq
  2537 \ Test{\isaliteral{2E}{\isachardot}}test{\isadigit{1}}\ {\isaliteral{2A7D}{\isacharverbatimclose}}\isanewline
  2538 \isacommand{ML}\isamarkupfalse%
  2539 \ {\isaliteral{7B2A}{\isacharverbatimopen}}\ val\ results\ {\isaliteral{3D}{\isacharequal}}\ DSeq{\isaliteral{2E}{\isachardot}}list{\isaliteral{5F}{\isacharunderscore}}of\ Test{\isaliteral{2E}{\isachardot}}test{\isadigit{2}}\ {\isaliteral{2A7D}{\isacharverbatimclose}}\isanewline
  2540 \isacommand{ML}\isamarkupfalse%
  2541 \ {\isaliteral{7B2A}{\isacharverbatimopen}}\ %
  2542 \isaantiq
  2543 assert{}%
  2544 \endisaantiq
  2545 \ {\isaliteral{28}{\isacharparenleft}}length\ results\ {\isaliteral{3D}{\isacharequal}}\ {\isadigit{2}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{2A7D}{\isacharverbatimclose}}%
  2546 \endisatagML
  2547 {\isafoldML}%
  2548 %
  2549 \isadelimML
  2550 %
  2551 \endisadelimML
  2552 %
  2553 \begin{isamarkuptext}%
  2554 \medskip The theory underlying the HOL code generator is described
  2555   more detailed in \cite{Berghofer-Nipkow:2002}. More examples that
  2556   illustrate the usage of the code generator can be found e.g.\ in
  2557   \verb|~~/src/HOL/MicroJava/J/JListExample.thy| and \verb|~~/src/HOL/MicroJava/JVM/JVMListExample.thy|.%
  2558 \end{isamarkuptext}%
  2559 \isamarkuptrue%
  2560 %
  2561 \isamarkupsection{Definition by specification \label{sec:hol-specification}%
  2562 }
  2563 \isamarkuptrue%
  2564 %
  2565 \begin{isamarkuptext}%
  2566 \begin{matharray}{rcl}
  2567     \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}}} \\
  2568     \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}}} \\
  2569   \end{matharray}
  2570 
  2571   \begin{railoutput}
  2572 \rail@begin{6}{}
  2573 \rail@bar
  2574 \rail@term{\hyperlink{command.HOL.specification}{\mbox{\isa{\isacommand{specification}}}}}[]
  2575 \rail@nextbar{1}
  2576 \rail@term{\hyperlink{command.HOL.ax-specification}{\mbox{\isa{\isacommand{ax{\isaliteral{5F}{\isacharunderscore}}specification}}}}}[]
  2577 \rail@endbar
  2578 \rail@term{\isa{{\isaliteral{28}{\isacharparenleft}}}}[]
  2579 \rail@plus
  2580 \rail@nont{\isa{decl}}[]
  2581 \rail@nextplus{1}
  2582 \rail@endplus
  2583 \rail@term{\isa{{\isaliteral{29}{\isacharparenright}}}}[]
  2584 \rail@cr{3}
  2585 \rail@plus
  2586 \rail@bar
  2587 \rail@nextbar{4}
  2588 \rail@nont{\hyperlink{syntax.thmdecl}{\mbox{\isa{thmdecl}}}}[]
  2589 \rail@endbar
  2590 \rail@nont{\hyperlink{syntax.prop}{\mbox{\isa{prop}}}}[]
  2591 \rail@nextplus{5}
  2592 \rail@endplus
  2593 \rail@end
  2594 \rail@begin{2}{\isa{decl}}
  2595 \rail@bar
  2596 \rail@nextbar{1}
  2597 \rail@nont{\hyperlink{syntax.name}{\mbox{\isa{name}}}}[]
  2598 \rail@term{\isa{{\isaliteral{3A}{\isacharcolon}}}}[]
  2599 \rail@endbar
  2600 \rail@nont{\hyperlink{syntax.term}{\mbox{\isa{term}}}}[]
  2601 \rail@term{\isa{{\isaliteral{28}{\isacharparenleft}}}}[]
  2602 \rail@term{\isa{\isakeyword{overloaded}}}[]
  2603 \rail@bar
  2604 \rail@nextbar{1}
  2605 \rail@term{\isa{{\isaliteral{29}{\isacharparenright}}}}[]
  2606 \rail@endbar
  2607 \rail@end
  2608 \end{railoutput}
  2609 
  2610 
  2611   \begin{description}
  2612 
  2613   \item \hyperlink{command.HOL.specification}{\mbox{\isa{\isacommand{specification}}}}~\isa{{\isaliteral{22}{\isachardoublequote}}decls\ {\isaliteral{5C3C7068693E}{\isasymphi}}{\isaliteral{22}{\isachardoublequote}}} sets up a
  2614   goal stating the existence of terms with the properties specified to
  2615   hold for the constants given in \isa{decls}.  After finishing the
  2616   proof, the theory will be augmented with definitions for the given
  2617   constants, as well as with theorems stating the properties for these
  2618   constants.
  2619 
  2620   \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
  2621   a goal stating the existence of terms with the properties specified
  2622   to hold for the constants given in \isa{decls}.  After finishing
  2623   the proof, the theory will be augmented with axioms expressing the
  2624   properties given in the first place.
  2625 
  2626   \item \isa{decl} declares a constant to be defined by the
  2627   specification given.  The definition for the constant \isa{c} is
  2628   bound to the name \isa{c{\isaliteral{5F}{\isacharunderscore}}def} unless a theorem name is given in
  2629   the declaration.  Overloaded constants should be declared as such.
  2630 
  2631   \end{description}
  2632 
  2633   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
  2634   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
  2635   user has explicitly proven it to be safe.  A practical issue must be
  2636   considered, though: After introducing two constants with the same
  2637   properties using \hyperlink{command.HOL.specification}{\mbox{\isa{\isacommand{specification}}}}, one can prove
  2638   that the two constants are, in fact, equal.  If this might be a
  2639   problem, one should use \hyperlink{command.HOL.ax-specification}{\mbox{\isa{\isacommand{ax{\isaliteral{5F}{\isacharunderscore}}specification}}}}.%
  2640 \end{isamarkuptext}%
  2641 \isamarkuptrue%
  2642 %
  2643 \isadelimtheory
  2644 %
  2645 \endisadelimtheory
  2646 %
  2647 \isatagtheory
  2648 \isacommand{end}\isamarkupfalse%
  2649 %
  2650 \endisatagtheory
  2651 {\isafoldtheory}%
  2652 %
  2653 \isadelimtheory
  2654 %
  2655 \endisadelimtheory
  2656 \isanewline
  2657 \end{isabellebody}%
  2658 %%% Local Variables:
  2659 %%% mode: latex
  2660 %%% TeX-master: "root"
  2661 %%% End: