doc-src/IsarRef/Thy/document/HOL_Specific.tex
author wenzelm
Thu May 08 12:29:18 2008 +0200 (2008-05-08)
changeset 26849 df50bc1249d7
parent 26840 ec46381f149d
child 26852 a31203f58b20
permissions -rw-r--r--
converted HOL specific elements;
     1 %
     2 \begin{isabellebody}%
     3 \def\isabellecontext{HOL{\isacharunderscore}Specific}%
     4 %
     5 \isadelimtheory
     6 \isanewline
     7 \isanewline
     8 %
     9 \endisadelimtheory
    10 %
    11 \isatagtheory
    12 \isacommand{theory}\isamarkupfalse%
    13 \ HOL{\isacharunderscore}Specific\isanewline
    14 \isakeyword{imports}\ Main\isanewline
    15 \isakeyword{begin}%
    16 \endisatagtheory
    17 {\isafoldtheory}%
    18 %
    19 \isadelimtheory
    20 %
    21 \endisadelimtheory
    22 %
    23 \isamarkupchapter{HOL specific elements \label{ch:logics}%
    24 }
    25 \isamarkuptrue%
    26 %
    27 \isamarkupsection{Primitive types \label{sec:hol-typedef}%
    28 }
    29 \isamarkuptrue%
    30 %
    31 \begin{isamarkuptext}%
    32 \begin{matharray}{rcl}
    33     \indexdef{HOL}{command}{typedecl}\mbox{\isa{\isacommand{typedecl}}} & : & \isartrans{theory}{theory} \\
    34     \indexdef{HOL}{command}{typedef}\mbox{\isa{\isacommand{typedef}}} & : & \isartrans{theory}{proof(prove)} \\
    35   \end{matharray}
    36 
    37   \begin{rail}
    38     'typedecl' typespec infix?
    39     ;
    40     'typedef' altname? abstype '=' repset
    41     ;
    42 
    43     altname: '(' (name | 'open' | 'open' name) ')'
    44     ;
    45     abstype: typespec infix?
    46     ;
    47     repset: term ('morphisms' name name)?
    48     ;
    49   \end{rail}
    50 
    51   \begin{descr}
    52   
    53   \item [\mbox{\isa{\isacommand{typedecl}}}~\isa{{\isachardoublequote}{\isacharparenleft}{\isasymalpha}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymalpha}\isactrlsub n{\isacharparenright}\ t{\isachardoublequote}}] is similar to the original \mbox{\isa{\isacommand{typedecl}}} of
    54   Isabelle/Pure (see \secref{sec:types-pure}), but also declares type
    55   arity \isa{{\isachardoublequote}t\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}type{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ type{\isacharparenright}\ type{\isachardoublequote}}, making \isa{t} an
    56   actual HOL type constructor.   %FIXME check, update
    57   
    58   \item [\mbox{\isa{\isacommand{typedef}}}~\isa{{\isachardoublequote}{\isacharparenleft}{\isasymalpha}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymalpha}\isactrlsub n{\isacharparenright}\ t\ {\isacharequal}\ A{\isachardoublequote}}] sets up a goal stating non-emptiness of the set \isa{A}.
    59   After finishing the proof, the theory will be augmented by a
    60   Gordon/HOL-style type definition, which establishes a bijection
    61   between the representing set \isa{A} and the new type \isa{t}.
    62   
    63   Technically, \mbox{\isa{\isacommand{typedef}}} defines both a type \isa{t} and a set (term constant) of the same name (an alternative base
    64   name may be given in parentheses).  The injection from type to set
    65   is called \isa{Rep{\isacharunderscore}t}, its inverse \isa{Abs{\isacharunderscore}t} (this may be
    66   changed via an explicit \mbox{\isa{\isakeyword{morphisms}}} declaration).
    67   
    68   Theorems \isa{Rep{\isacharunderscore}t}, \isa{Rep{\isacharunderscore}t{\isacharunderscore}inverse}, and \isa{Abs{\isacharunderscore}t{\isacharunderscore}inverse} provide the most basic characterization as a
    69   corresponding injection/surjection pair (in both directions).  Rules
    70   \isa{Rep{\isacharunderscore}t{\isacharunderscore}inject} and \isa{Abs{\isacharunderscore}t{\isacharunderscore}inject} provide a slightly
    71   more convenient view on the injectivity part, suitable for automated
    72   proof tools (e.g.\ in \mbox{\isa{simp}} or \mbox{\isa{iff}} declarations).
    73   Rules \isa{Rep{\isacharunderscore}t{\isacharunderscore}cases}/\isa{Rep{\isacharunderscore}t{\isacharunderscore}induct}, and \isa{Abs{\isacharunderscore}t{\isacharunderscore}cases}/\isa{Abs{\isacharunderscore}t{\isacharunderscore}induct} provide alternative views on
    74   surjectivity; these are already declared as set or type rules for
    75   the generic \mbox{\isa{cases}} and \mbox{\isa{induct}} methods.
    76   
    77   An alternative name may be specified in parentheses; the default is
    78   to use \isa{t} as indicated before.  The ``\isa{{\isachardoublequote}{\isacharparenleft}open{\isacharparenright}{\isachardoublequote}}''
    79   declaration suppresses a separate constant definition for the
    80   representing set.
    81 
    82   \end{descr}
    83 
    84   Note that raw type declarations are rarely used in practice; the
    85   main application is with experimental (or even axiomatic!) theory
    86   fragments.  Instead of primitive HOL type definitions, user-level
    87   theories usually refer to higher-level packages such as \mbox{\isa{\isacommand{record}}} (see \secref{sec:hol-record}) or \mbox{\isa{\isacommand{datatype}}} (see \secref{sec:hol-datatype}).%
    88 \end{isamarkuptext}%
    89 \isamarkuptrue%
    90 %
    91 \isamarkupsection{Adhoc tuples%
    92 }
    93 \isamarkuptrue%
    94 %
    95 \begin{isamarkuptext}%
    96 \begin{matharray}{rcl}
    97     \mbox{\isa{split{\isacharunderscore}format}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isaratt \\
    98   \end{matharray}
    99 
   100   \begin{rail}
   101     'split\_format' (((name *) + 'and') | ('(' 'complete' ')'))
   102     ;
   103   \end{rail}
   104 
   105   \begin{descr}
   106   
   107   \item [\mbox{\isa{split{\isacharunderscore}format}}~\isa{{\isachardoublequote}p\isactrlsub {\isadigit{1}}\ {\isasymdots}\ p\isactrlsub m\ {\isasymAND}\ {\isasymdots}\ {\isasymAND}\ q\isactrlsub {\isadigit{1}}\ {\isasymdots}\ q\isactrlsub n{\isachardoublequote}}] puts expressions of
   108   low-level tuple types into canonical form as specified by the
   109   arguments given; the \isa{i}-th collection of arguments refers to
   110   occurrences in premise \isa{i} of the rule.  The ``\isa{{\isachardoublequote}{\isacharparenleft}complete{\isacharparenright}{\isachardoublequote}}'' option causes \emph{all} arguments in function
   111   applications to be represented canonically according to their tuple
   112   type structure.
   113 
   114   Note that these operations tend to invent funny names for new local
   115   parameters to be introduced.
   116 
   117   \end{descr}%
   118 \end{isamarkuptext}%
   119 \isamarkuptrue%
   120 %
   121 \isamarkupsection{Records \label{sec:hol-record}%
   122 }
   123 \isamarkuptrue%
   124 %
   125 \begin{isamarkuptext}%
   126 In principle, records merely generalize the concept of tuples, where
   127   components may be addressed by labels instead of just position.  The
   128   logical infrastructure of records in Isabelle/HOL is slightly more
   129   advanced, though, supporting truly extensible record schemes.  This
   130   admits operations that are polymorphic with respect to record
   131   extension, yielding ``object-oriented'' effects like (single)
   132   inheritance.  See also \cite{NaraschewskiW-TPHOLs98} for more
   133   details on object-oriented verification and record subtyping in HOL.%
   134 \end{isamarkuptext}%
   135 \isamarkuptrue%
   136 %
   137 \isamarkupsubsection{Basic concepts%
   138 }
   139 \isamarkuptrue%
   140 %
   141 \begin{isamarkuptext}%
   142 Isabelle/HOL supports both \emph{fixed} and \emph{schematic} records
   143   at the level of terms and types.  The notation is as follows:
   144 
   145   \begin{center}
   146   \begin{tabular}{l|l|l}
   147     & record terms & record types \\ \hline
   148     fixed & \isa{{\isachardoublequote}{\isasymlparr}x\ {\isacharequal}\ a{\isacharcomma}\ y\ {\isacharequal}\ b{\isasymrparr}{\isachardoublequote}} & \isa{{\isachardoublequote}{\isasymlparr}x\ {\isacharcolon}{\isacharcolon}\ A{\isacharcomma}\ y\ {\isacharcolon}{\isacharcolon}\ B{\isasymrparr}{\isachardoublequote}} \\
   149     schematic & \isa{{\isachardoublequote}{\isasymlparr}x\ {\isacharequal}\ a{\isacharcomma}\ y\ {\isacharequal}\ b{\isacharcomma}\ {\isasymdots}\ {\isacharequal}\ m{\isasymrparr}{\isachardoublequote}} &
   150       \isa{{\isachardoublequote}{\isasymlparr}x\ {\isacharcolon}{\isacharcolon}\ A{\isacharcomma}\ y\ {\isacharcolon}{\isacharcolon}\ B{\isacharcomma}\ {\isasymdots}\ {\isacharcolon}{\isacharcolon}\ M{\isasymrparr}{\isachardoublequote}} \\
   151   \end{tabular}
   152   \end{center}
   153 
   154   \noindent The ASCII representation of \isa{{\isachardoublequote}{\isasymlparr}x\ {\isacharequal}\ a{\isasymrparr}{\isachardoublequote}} is \isa{{\isachardoublequote}{\isacharparenleft}{\isacharbar}\ x\ {\isacharequal}\ a\ {\isacharbar}{\isacharparenright}{\isachardoublequote}}.
   155 
   156   A fixed record \isa{{\isachardoublequote}{\isasymlparr}x\ {\isacharequal}\ a{\isacharcomma}\ y\ {\isacharequal}\ b{\isasymrparr}{\isachardoublequote}} has field \isa{x} of value
   157   \isa{a} and field \isa{y} of value \isa{b}.  The corresponding
   158   type is \isa{{\isachardoublequote}{\isasymlparr}x\ {\isacharcolon}{\isacharcolon}\ A{\isacharcomma}\ y\ {\isacharcolon}{\isacharcolon}\ B{\isasymrparr}{\isachardoublequote}}, assuming that \isa{{\isachardoublequote}a\ {\isacharcolon}{\isacharcolon}\ A{\isachardoublequote}}
   159   and \isa{{\isachardoublequote}b\ {\isacharcolon}{\isacharcolon}\ B{\isachardoublequote}}.
   160 
   161   A record scheme like \isa{{\isachardoublequote}{\isasymlparr}x\ {\isacharequal}\ a{\isacharcomma}\ y\ {\isacharequal}\ b{\isacharcomma}\ {\isasymdots}\ {\isacharequal}\ m{\isasymrparr}{\isachardoublequote}} contains fields
   162   \isa{x} and \isa{y} as before, but also possibly further fields
   163   as indicated by the ``\isa{{\isachardoublequote}{\isasymdots}{\isachardoublequote}}'' notation (which is actually part
   164   of the syntax).  The improper field ``\isa{{\isachardoublequote}{\isasymdots}{\isachardoublequote}}'' of a record
   165   scheme is called the \emph{more part}.  Logically it is just a free
   166   variable, which is occasionally referred to as ``row variable'' in
   167   the literature.  The more part of a record scheme may be
   168   instantiated by zero or more further components.  For example, the
   169   previous scheme may get instantiated to \isa{{\isachardoublequote}{\isasymlparr}x\ {\isacharequal}\ a{\isacharcomma}\ y\ {\isacharequal}\ b{\isacharcomma}\ z\ {\isacharequal}\ c{\isacharcomma}\ {\isasymdots}\ {\isacharequal}\ m{\isacharprime}{\isachardoublequote}}, where \isa{m{\isacharprime}} refers to a different more part.
   170   Fixed records are special instances of record schemes, where
   171   ``\isa{{\isachardoublequote}{\isasymdots}{\isachardoublequote}}'' is properly terminated by the \isa{{\isachardoublequote}{\isacharparenleft}{\isacharparenright}\ {\isacharcolon}{\isacharcolon}\ unit{\isachardoublequote}}
   172   element.  In fact, \isa{{\isachardoublequote}{\isasymlparr}x\ {\isacharequal}\ a{\isacharcomma}\ y\ {\isacharequal}\ b{\isasymrparr}{\isachardoublequote}} is just an abbreviation
   173   for \isa{{\isachardoublequote}{\isasymlparr}x\ {\isacharequal}\ a{\isacharcomma}\ y\ {\isacharequal}\ b{\isacharcomma}\ {\isasymdots}\ {\isacharequal}\ {\isacharparenleft}{\isacharparenright}{\isasymrparr}{\isachardoublequote}}.
   174   
   175   \medskip Two key observations make extensible records in a simply
   176   typed language like HOL work out:
   177 
   178   \begin{enumerate}
   179 
   180   \item the more part is internalized, as a free term or type
   181   variable,
   182 
   183   \item field names are externalized, they cannot be accessed within the logic
   184   as first-class values.
   185 
   186   \end{enumerate}
   187 
   188   \medskip In Isabelle/HOL record types have to be defined explicitly,
   189   fixing their field names and types, and their (optional) parent
   190   record.  Afterwards, records may be formed using above syntax, while
   191   obeying the canonical order of fields as given by their declaration.
   192   The record package provides several standard operations like
   193   selectors and updates.  The common setup for various generic proof
   194   tools enable succinct reasoning patterns.  See also the Isabelle/HOL
   195   tutorial \cite{isabelle-hol-book} for further instructions on using
   196   records in practice.%
   197 \end{isamarkuptext}%
   198 \isamarkuptrue%
   199 %
   200 \isamarkupsubsection{Record specifications%
   201 }
   202 \isamarkuptrue%
   203 %
   204 \begin{isamarkuptext}%
   205 \begin{matharray}{rcl}
   206     \indexdef{HOL}{command}{record}\mbox{\isa{\isacommand{record}}} & : & \isartrans{theory}{theory} \\
   207   \end{matharray}
   208 
   209   \begin{rail}
   210     'record' typespec '=' (type '+')? (constdecl +)
   211     ;
   212   \end{rail}
   213 
   214   \begin{descr}
   215 
   216   \item [\mbox{\isa{\isacommand{record}}}~\isa{{\isachardoublequote}{\isacharparenleft}{\isasymalpha}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymalpha}\isactrlsub m{\isacharparenright}\ t\ {\isacharequal}\ {\isasymtau}\ {\isacharplus}\ c\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub {\isadigit{1}}\ {\isasymdots}\ c\isactrlsub n\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub n{\isachardoublequote}}] defines
   217   extensible record type \isa{{\isachardoublequote}{\isacharparenleft}{\isasymalpha}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymalpha}\isactrlsub m{\isacharparenright}\ t{\isachardoublequote}},
   218   derived from the optional parent record \isa{{\isachardoublequote}{\isasymtau}{\isachardoublequote}} by adding new
   219   field components \isa{{\isachardoublequote}c\isactrlsub i\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub i{\isachardoublequote}} etc.
   220 
   221   The type variables of \isa{{\isachardoublequote}{\isasymtau}{\isachardoublequote}} and \isa{{\isachardoublequote}{\isasymsigma}\isactrlsub i{\isachardoublequote}} need to be
   222   covered by the (distinct) parameters \isa{{\isachardoublequote}{\isasymalpha}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymalpha}\isactrlsub m{\isachardoublequote}}.  Type constructor \isa{t} has to be new, while \isa{{\isasymtau}} needs to specify an instance of an existing record type.  At
   223   least one new field \isa{{\isachardoublequote}c\isactrlsub i{\isachardoublequote}} has to be specified.
   224   Basically, field names need to belong to a unique record.  This is
   225   not a real restriction in practice, since fields are qualified by
   226   the record name internally.
   227 
   228   The parent record specification \isa{{\isasymtau}} is optional; if omitted
   229   \isa{t} becomes a root record.  The hierarchy of all records
   230   declared within a theory context forms a forest structure, i.e.\ a
   231   set of trees starting with a root record each.  There is no way to
   232   merge multiple parent records!
   233 
   234   For convenience, \isa{{\isachardoublequote}{\isacharparenleft}{\isasymalpha}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymalpha}\isactrlsub m{\isacharparenright}\ t{\isachardoublequote}} is made a
   235   type abbreviation for the fixed record type \isa{{\isachardoublequote}{\isasymlparr}c\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlsub n\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub n{\isasymrparr}{\isachardoublequote}}, likewise is \isa{{\isachardoublequote}{\isacharparenleft}{\isasymalpha}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymalpha}\isactrlsub m{\isacharcomma}\ {\isasymzeta}{\isacharparenright}\ t{\isacharunderscore}scheme{\isachardoublequote}} made an abbreviation for
   236   \isa{{\isachardoublequote}{\isasymlparr}c\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlsub n\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub n{\isacharcomma}\ {\isasymdots}\ {\isacharcolon}{\isacharcolon}\ {\isasymzeta}{\isasymrparr}{\isachardoublequote}}.
   237 
   238   \end{descr}%
   239 \end{isamarkuptext}%
   240 \isamarkuptrue%
   241 %
   242 \isamarkupsubsection{Record operations%
   243 }
   244 \isamarkuptrue%
   245 %
   246 \begin{isamarkuptext}%
   247 Any record definition of the form presented above produces certain
   248   standard operations.  Selectors and updates are provided for any
   249   field, including the improper one ``\isa{more}''.  There are also
   250   cumulative record constructor functions.  To simplify the
   251   presentation below, we assume for now that \isa{{\isachardoublequote}{\isacharparenleft}{\isasymalpha}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymalpha}\isactrlsub m{\isacharparenright}\ t{\isachardoublequote}} is a root record with fields \isa{{\isachardoublequote}c\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlsub n\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub n{\isachardoublequote}}.
   252 
   253   \medskip \textbf{Selectors} and \textbf{updates} are available for
   254   any field (including ``\isa{more}''):
   255 
   256   \begin{matharray}{lll}
   257     \isa{{\isachardoublequote}c\isactrlsub i{\isachardoublequote}} & \isa{{\isachardoublequote}{\isacharcolon}{\isacharcolon}{\isachardoublequote}} & \isa{{\isachardoublequote}{\isasymlparr}c\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlsub n\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub n{\isacharcomma}\ {\isasymdots}\ {\isacharcolon}{\isacharcolon}\ {\isasymzeta}{\isasymrparr}\ {\isasymRightarrow}\ {\isasymsigma}\isactrlsub i{\isachardoublequote}} \\
   258     \isa{{\isachardoublequote}c\isactrlsub i{\isacharunderscore}update{\isachardoublequote}} & \isa{{\isachardoublequote}{\isacharcolon}{\isacharcolon}{\isachardoublequote}} & \isa{{\isachardoublequote}{\isasymsigma}\isactrlsub i\ {\isasymRightarrow}\ {\isasymlparr}c\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlsub n\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub n{\isacharcomma}\ {\isasymdots}\ {\isacharcolon}{\isacharcolon}\ {\isasymzeta}{\isasymrparr}\ {\isasymRightarrow}\ {\isasymlparr}c\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlsub n\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub n{\isacharcomma}\ {\isasymdots}\ {\isacharcolon}{\isacharcolon}\ {\isasymzeta}{\isasymrparr}{\isachardoublequote}} \\
   259   \end{matharray}
   260 
   261   There is special syntax for application of updates: \isa{{\isachardoublequote}r{\isasymlparr}x\ {\isacharcolon}{\isacharequal}\ a{\isasymrparr}{\isachardoublequote}} abbreviates term \isa{{\isachardoublequote}x{\isacharunderscore}update\ a\ r{\isachardoublequote}}.  Further notation for
   262   repeated updates is also available: \isa{{\isachardoublequote}r{\isasymlparr}x\ {\isacharcolon}{\isacharequal}\ a{\isasymrparr}{\isasymlparr}y\ {\isacharcolon}{\isacharequal}\ b{\isasymrparr}{\isasymlparr}z\ {\isacharcolon}{\isacharequal}\ c{\isasymrparr}{\isachardoublequote}} may be written \isa{{\isachardoublequote}r{\isasymlparr}x\ {\isacharcolon}{\isacharequal}\ a{\isacharcomma}\ y\ {\isacharcolon}{\isacharequal}\ b{\isacharcomma}\ z\ {\isacharcolon}{\isacharequal}\ c{\isasymrparr}{\isachardoublequote}}.  Note that
   263   because of postfix notation the order of fields shown here is
   264   reverse than in the actual term.  Since repeated updates are just
   265   function applications, fields may be freely permuted in \isa{{\isachardoublequote}{\isasymlparr}x\ {\isacharcolon}{\isacharequal}\ a{\isacharcomma}\ y\ {\isacharcolon}{\isacharequal}\ b{\isacharcomma}\ z\ {\isacharcolon}{\isacharequal}\ c{\isasymrparr}{\isachardoublequote}}, as far as logical equality is concerned.
   266   Thus commutativity of independent updates can be proven within the
   267   logic for any two fields, but not as a general theorem.
   268 
   269   \medskip The \textbf{make} operation provides a cumulative record
   270   constructor function:
   271 
   272   \begin{matharray}{lll}
   273     \isa{{\isachardoublequote}t{\isachardot}make{\isachardoublequote}} & \isa{{\isachardoublequote}{\isacharcolon}{\isacharcolon}{\isachardoublequote}} & \isa{{\isachardoublequote}{\isasymsigma}\isactrlsub {\isadigit{1}}\ {\isasymRightarrow}\ {\isasymdots}\ {\isasymsigma}\isactrlsub n\ {\isasymRightarrow}\ {\isasymlparr}c\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlsub n\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub n{\isasymrparr}{\isachardoublequote}} \\
   274   \end{matharray}
   275 
   276   \medskip We now reconsider the case of non-root records, which are
   277   derived of some parent.  In general, the latter may depend on
   278   another parent as well, resulting in a list of \emph{ancestor
   279   records}.  Appending the lists of fields of all ancestors results in
   280   a certain field prefix.  The record package automatically takes care
   281   of this by lifting operations over this context of ancestor fields.
   282   Assuming that \isa{{\isachardoublequote}{\isacharparenleft}{\isasymalpha}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymalpha}\isactrlsub m{\isacharparenright}\ t{\isachardoublequote}} has ancestor
   283   fields \isa{{\isachardoublequote}b\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymrho}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ b\isactrlsub k\ {\isacharcolon}{\isacharcolon}\ {\isasymrho}\isactrlsub k{\isachardoublequote}},
   284   the above record operations will get the following types:
   285 
   286   \begin{matharray}{lll}
   287     \isa{{\isachardoublequote}c\isactrlsub i{\isachardoublequote}} & \isa{{\isachardoublequote}{\isacharcolon}{\isacharcolon}{\isachardoublequote}} & \isa{{\isachardoublequote}{\isasymlparr}b\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymrho}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ b\isactrlsub k\ {\isacharcolon}{\isacharcolon}\ {\isasymrho}\isactrlsub k{\isacharcomma}\ c\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlsub n\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub n{\isacharcomma}\ {\isasymdots}\ {\isacharcolon}{\isacharcolon}\ {\isasymzeta}{\isasymrparr}\ {\isasymRightarrow}\ {\isasymsigma}\isactrlsub i{\isachardoublequote}} \\
   288     \isa{{\isachardoublequote}c\isactrlsub i{\isacharunderscore}update{\isachardoublequote}} & \isa{{\isachardoublequote}{\isacharcolon}{\isacharcolon}{\isachardoublequote}} & \isa{{\isachardoublequote}{\isasymsigma}\isactrlsub i\ {\isasymRightarrow}\ {\isasymlparr}b\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymrho}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ b\isactrlsub k\ {\isacharcolon}{\isacharcolon}\ {\isasymrho}\isactrlsub k{\isacharcomma}\ c\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlsub n\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub n{\isacharcomma}\ {\isasymdots}\ {\isacharcolon}{\isacharcolon}\ {\isasymzeta}{\isasymrparr}\ {\isasymRightarrow}\ {\isasymlparr}b\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymrho}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ b\isactrlsub k\ {\isacharcolon}{\isacharcolon}\ {\isasymrho}\isactrlsub k{\isacharcomma}\ c\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlsub n\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub n{\isacharcomma}\ {\isasymdots}\ {\isacharcolon}{\isacharcolon}\ {\isasymzeta}{\isasymrparr}{\isachardoublequote}} \\
   289     \isa{{\isachardoublequote}t{\isachardot}make{\isachardoublequote}} & \isa{{\isachardoublequote}{\isacharcolon}{\isacharcolon}{\isachardoublequote}} & \isa{{\isachardoublequote}{\isasymrho}\isactrlsub {\isadigit{1}}\ {\isasymRightarrow}\ {\isasymdots}\ {\isasymrho}\isactrlsub k\ {\isasymRightarrow}\ {\isasymsigma}\isactrlsub {\isadigit{1}}\ {\isasymRightarrow}\ {\isasymdots}\ {\isasymsigma}\isactrlsub n\ {\isasymRightarrow}\ {\isasymlparr}b\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymrho}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ b\isactrlsub k\ {\isacharcolon}{\isacharcolon}\ {\isasymrho}\isactrlsub k{\isacharcomma}\ c\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlsub n\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub n{\isachardoublequote}} \\
   290   \end{matharray}
   291   \noindent
   292 
   293   \medskip Some further operations address the extension aspect of a
   294   derived record scheme specifically: \isa{{\isachardoublequote}t{\isachardot}fields{\isachardoublequote}} produces a
   295   record fragment consisting of exactly the new fields introduced here
   296   (the result may serve as a more part elsewhere); \isa{{\isachardoublequote}t{\isachardot}extend{\isachardoublequote}}
   297   takes a fixed record and adds a given more part; \isa{{\isachardoublequote}t{\isachardot}truncate{\isachardoublequote}} restricts a record scheme to a fixed record.
   298 
   299   \begin{matharray}{lll}
   300     \isa{{\isachardoublequote}t{\isachardot}fields{\isachardoublequote}} & \isa{{\isachardoublequote}{\isacharcolon}{\isacharcolon}{\isachardoublequote}} & \isa{{\isachardoublequote}{\isasymsigma}\isactrlsub {\isadigit{1}}\ {\isasymRightarrow}\ {\isasymdots}\ {\isasymsigma}\isactrlsub n\ {\isasymRightarrow}\ {\isasymlparr}c\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlsub n\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub n{\isachardoublequote}} \\
   301     \isa{{\isachardoublequote}t{\isachardot}extend{\isachardoublequote}} & \isa{{\isachardoublequote}{\isacharcolon}{\isacharcolon}{\isachardoublequote}} & \isa{{\isachardoublequote}{\isasymlparr}b\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymrho}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ b\isactrlsub k\ {\isacharcolon}{\isacharcolon}\ {\isasymrho}\isactrlsub k{\isacharcomma}\ c\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlsub n\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub n{\isasymrparr}\ {\isasymRightarrow}\ {\isasymzeta}\ {\isasymRightarrow}\ {\isasymlparr}b\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymrho}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ b\isactrlsub k\ {\isacharcolon}{\isacharcolon}\ {\isasymrho}\isactrlsub k{\isacharcomma}\ c\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlsub n\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub n{\isacharcomma}\ {\isasymdots}\ {\isacharcolon}{\isacharcolon}\ {\isasymzeta}{\isasymrparr}{\isachardoublequote}} \\
   302     \isa{{\isachardoublequote}t{\isachardot}truncate{\isachardoublequote}} & \isa{{\isachardoublequote}{\isacharcolon}{\isacharcolon}{\isachardoublequote}} & \isa{{\isachardoublequote}{\isasymlparr}b\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymrho}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ b\isactrlsub k\ {\isacharcolon}{\isacharcolon}\ {\isasymrho}\isactrlsub k{\isacharcomma}\ c\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlsub n\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub n{\isacharcomma}\ {\isasymdots}\ {\isacharcolon}{\isacharcolon}\ {\isasymzeta}{\isasymrparr}\ {\isasymRightarrow}\ {\isasymlparr}b\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymrho}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ b\isactrlsub k\ {\isacharcolon}{\isacharcolon}\ {\isasymrho}\isactrlsub k{\isacharcomma}\ c\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlsub n\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}\isactrlsub n{\isasymrparr}{\isachardoublequote}} \\
   303   \end{matharray}
   304 
   305   \noindent Note that \isa{{\isachardoublequote}t{\isachardot}make{\isachardoublequote}} and \isa{{\isachardoublequote}t{\isachardot}fields{\isachardoublequote}} coincide
   306   for root records.%
   307 \end{isamarkuptext}%
   308 \isamarkuptrue%
   309 %
   310 \isamarkupsubsection{Derived rules and proof tools%
   311 }
   312 \isamarkuptrue%
   313 %
   314 \begin{isamarkuptext}%
   315 The record package proves several results internally, declaring
   316   these facts to appropriate proof tools.  This enables users to
   317   reason about record structures quite conveniently.  Assume that
   318   \isa{t} is a record type as specified above.
   319 
   320   \begin{enumerate}
   321   
   322   \item Standard conversions for selectors or updates applied to
   323   record constructor terms are made part of the default Simplifier
   324   context; thus proofs by reduction of basic operations merely require
   325   the \mbox{\isa{simp}} method without further arguments.  These rules
   326   are available as \isa{{\isachardoublequote}t{\isachardot}simps{\isachardoublequote}}, too.
   327   
   328   \item Selectors applied to updated records are automatically reduced
   329   by an internal simplification procedure, which is also part of the
   330   standard Simplifier setup.
   331 
   332   \item Inject equations of a form analogous to \isa{{\isachardoublequote}{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}x{\isacharprime}{\isacharcomma}\ y{\isacharprime}{\isacharparenright}\ {\isasymequiv}\ x\ {\isacharequal}\ x{\isacharprime}\ {\isasymand}\ y\ {\isacharequal}\ y{\isacharprime}{\isachardoublequote}} are declared to the Simplifier and Classical
   333   Reasoner as \mbox{\isa{iff}} rules.  These rules are available as
   334   \isa{{\isachardoublequote}t{\isachardot}iffs{\isachardoublequote}}.
   335 
   336   \item The introduction rule for record equality analogous to \isa{{\isachardoublequote}x\ r\ {\isacharequal}\ x\ r{\isacharprime}\ {\isasymLongrightarrow}\ y\ r\ {\isacharequal}\ y\ r{\isacharprime}\ {\isasymdots}\ {\isasymLongrightarrow}\ r\ {\isacharequal}\ r{\isacharprime}{\isachardoublequote}} is declared to the Simplifier,
   337   and as the basic rule context as ``\mbox{\isa{intro}}\isa{{\isachardoublequote}{\isacharquery}{\isachardoublequote}}''.
   338   The rule is called \isa{{\isachardoublequote}t{\isachardot}equality{\isachardoublequote}}.
   339 
   340   \item Representations of arbitrary record expressions as canonical
   341   constructor terms are provided both in \mbox{\isa{cases}} and \mbox{\isa{induct}} format (cf.\ the generic proof methods of the same name,
   342   \secref{sec:cases-induct}).  Several variations are available, for
   343   fixed records, record schemes, more parts etc.
   344   
   345   The generic proof methods are sufficiently smart to pick the most
   346   sensible rule according to the type of the indicated record
   347   expression: users just need to apply something like ``\isa{{\isachardoublequote}{\isacharparenleft}cases\ r{\isacharparenright}{\isachardoublequote}}'' to a certain proof problem.
   348 
   349   \item The derived record operations \isa{{\isachardoublequote}t{\isachardot}make{\isachardoublequote}}, \isa{{\isachardoublequote}t{\isachardot}fields{\isachardoublequote}}, \isa{{\isachardoublequote}t{\isachardot}extend{\isachardoublequote}}, \isa{{\isachardoublequote}t{\isachardot}truncate{\isachardoublequote}} are \emph{not}
   350   treated automatically, but usually need to be expanded by hand,
   351   using the collective fact \isa{{\isachardoublequote}t{\isachardot}defs{\isachardoublequote}}.
   352 
   353   \end{enumerate}%
   354 \end{isamarkuptext}%
   355 \isamarkuptrue%
   356 %
   357 \isamarkupsection{Datatypes \label{sec:hol-datatype}%
   358 }
   359 \isamarkuptrue%
   360 %
   361 \begin{isamarkuptext}%
   362 \begin{matharray}{rcl}
   363     \indexdef{HOL}{command}{datatype}\mbox{\isa{\isacommand{datatype}}} & : & \isartrans{theory}{theory} \\
   364     \indexdef{HOL}{command}{rep-datatype}\mbox{\isa{\isacommand{rep{\isacharunderscore}datatype}}} & : & \isartrans{theory}{theory} \\
   365   \end{matharray}
   366 
   367   \begin{rail}
   368     'datatype' (dtspec + 'and')
   369     ;
   370     'rep\_datatype' (name *) dtrules
   371     ;
   372 
   373     dtspec: parname? typespec infix? '=' (cons + '|')
   374     ;
   375     cons: name (type *) mixfix?
   376     ;
   377     dtrules: 'distinct' thmrefs 'inject' thmrefs 'induction' thmrefs
   378   \end{rail}
   379 
   380   \begin{descr}
   381 
   382   \item [\mbox{\isa{\isacommand{datatype}}}] defines inductive datatypes in
   383   HOL.
   384 
   385   \item [\mbox{\isa{\isacommand{rep{\isacharunderscore}datatype}}}] represents existing types as
   386   inductive ones, generating the standard infrastructure of derived
   387   concepts (primitive recursion etc.).
   388 
   389   \end{descr}
   390 
   391   The induction and exhaustion theorems generated provide case names
   392   according to the constructors involved, while parameters are named
   393   after the types (see also \secref{sec:cases-induct}).
   394 
   395   See \cite{isabelle-HOL} for more details on datatypes, but beware of
   396   the old-style theory syntax being used there!  Apart from proper
   397   proof methods for case-analysis and induction, there are also
   398   emulations of ML tactics \mbox{\isa{case{\isacharunderscore}tac}} and \mbox{\isa{induct{\isacharunderscore}tac}} available, see \secref{sec:hol-induct-tac}; these admit
   399   to refer directly to the internal structure of subgoals (including
   400   internally bound parameters).%
   401 \end{isamarkuptext}%
   402 \isamarkuptrue%
   403 %
   404 \isamarkupsection{Recursive functions \label{sec:recursion}%
   405 }
   406 \isamarkuptrue%
   407 %
   408 \begin{isamarkuptext}%
   409 \begin{matharray}{rcl}
   410     \indexdef{HOL}{command}{primrec}\mbox{\isa{\isacommand{primrec}}} & : & \isarkeep{local{\dsh}theory} \\
   411     \indexdef{HOL}{command}{fun}\mbox{\isa{\isacommand{fun}}} & : & \isarkeep{local{\dsh}theory} \\
   412     \indexdef{HOL}{command}{function}\mbox{\isa{\isacommand{function}}} & : & \isartrans{local{\dsh}theory}{proof(prove)} \\
   413     \indexdef{HOL}{command}{termination}\mbox{\isa{\isacommand{termination}}} & : & \isartrans{local{\dsh}theory}{proof(prove)} \\
   414   \end{matharray}
   415 
   416   \railalias{funopts}{function\_opts}  %FIXME ??
   417 
   418   \begin{rail}
   419     'primrec' target? fixes 'where' equations
   420     ;
   421     equations: (thmdecl? prop + '|')
   422     ;
   423     ('fun' | 'function') (funopts)? fixes 'where' clauses
   424     ;
   425     clauses: (thmdecl? prop ('(' 'otherwise' ')')? + '|')
   426     ;
   427     funopts: '(' (('sequential' | 'in' name | 'domintros' | 'tailrec' |
   428     'default' term) + ',') ')'
   429     ;
   430     'termination' ( term )?
   431   \end{rail}
   432 
   433   \begin{descr}
   434 
   435   \item [\mbox{\isa{\isacommand{primrec}}}] defines primitive recursive
   436   functions over datatypes, see also \cite{isabelle-HOL}.
   437 
   438   \item [\mbox{\isa{\isacommand{function}}}] defines functions by general
   439   wellfounded recursion. A detailed description with examples can be
   440   found in \cite{isabelle-function}. The function is specified by a
   441   set of (possibly conditional) recursive equations with arbitrary
   442   pattern matching. The command generates proof obligations for the
   443   completeness and the compatibility of patterns.
   444 
   445   The defined function is considered partial, and the resulting
   446   simplification rules (named \isa{{\isachardoublequote}f{\isachardot}psimps{\isachardoublequote}}) and induction rule
   447   (named \isa{{\isachardoublequote}f{\isachardot}pinduct{\isachardoublequote}}) are guarded by a generated domain
   448   predicate \isa{{\isachardoublequote}f{\isacharunderscore}dom{\isachardoublequote}}. The \mbox{\isa{\isacommand{termination}}}
   449   command can then be used to establish that the function is total.
   450 
   451   \item [\mbox{\isa{\isacommand{fun}}}] is a shorthand notation for
   452   ``\mbox{\isa{\isacommand{function}}}~\isa{{\isachardoublequote}{\isacharparenleft}sequential{\isacharparenright}{\isachardoublequote}}, followed by
   453   automated proof attempts regarding pattern matching and termination.
   454   See \cite{isabelle-function} for further details.
   455 
   456   \item [\mbox{\isa{\isacommand{termination}}}~\isa{f}] commences a
   457   termination proof for the previously defined function \isa{f}.  If
   458   this is omitted, the command refers to the most recent function
   459   definition.  After the proof is closed, the recursive equations and
   460   the induction principle is established.
   461 
   462   \end{descr}
   463 
   464   %FIXME check
   465 
   466   Recursive definitions introduced by both the \mbox{\isa{\isacommand{primrec}}} and the \mbox{\isa{\isacommand{function}}} command accommodate
   467   reasoning by induction (cf.\ \secref{sec:cases-induct}): rule \isa{{\isachardoublequote}c{\isachardot}induct{\isachardoublequote}} (where \isa{c} is the name of the function definition)
   468   refers to a specific induction rule, with parameters named according
   469   to the user-specified equations.  Case names of \mbox{\isa{\isacommand{primrec}}} are that of the datatypes involved, while those of
   470   \mbox{\isa{\isacommand{function}}} are numbered (starting from 1).
   471 
   472   The equations provided by these packages may be referred later as
   473   theorem list \isa{{\isachardoublequote}f{\isachardot}simps{\isachardoublequote}}, where \isa{f} is the (collective)
   474   name of the functions defined.  Individual equations may be named
   475   explicitly as well.
   476 
   477   The \mbox{\isa{\isacommand{function}}} command accepts the following
   478   options.
   479 
   480   \begin{descr}
   481 
   482   \item [\isa{sequential}] enables a preprocessor which
   483   disambiguates overlapping patterns by making them mutually disjoint.
   484   Earlier equations take precedence over later ones.  This allows to
   485   give the specification in a format very similar to functional
   486   programming.  Note that the resulting simplification and induction
   487   rules correspond to the transformed specification, not the one given
   488   originally. This usually means that each equation given by the user
   489   may result in several theroems.  Also note that this automatic
   490   transformation only works for ML-style datatype patterns.
   491 
   492   \item [\isa{{\isachardoublequote}{\isasymIN}\ name{\isachardoublequote}}] gives the target for the definition.
   493   %FIXME ?!?
   494 
   495   \item [\isa{domintros}] enables the automated generation of
   496   introduction rules for the domain predicate. While mostly not
   497   needed, they can be helpful in some proofs about partial functions.
   498 
   499   \item [\isa{tailrec}] generates the unconstrained recursive
   500   equations even without a termination proof, provided that the
   501   function is tail-recursive. This currently only works
   502 
   503   \item [\isa{{\isachardoublequote}default\ d{\isachardoublequote}}] allows to specify a default value for a
   504   (partial) function, which will ensure that \isa{{\isachardoublequote}f\ x\ {\isacharequal}\ d\ x{\isachardoublequote}}
   505   whenever \isa{{\isachardoublequote}x\ {\isasymnotin}\ f{\isacharunderscore}dom{\isachardoublequote}}.
   506 
   507   \end{descr}%
   508 \end{isamarkuptext}%
   509 \isamarkuptrue%
   510 %
   511 \isamarkupsubsection{Proof methods related to recursive definitions%
   512 }
   513 \isamarkuptrue%
   514 %
   515 \begin{isamarkuptext}%
   516 \begin{matharray}{rcl}
   517     \indexdef{HOL}{method}{pat-completeness}\mbox{\isa{pat{\isacharunderscore}completeness}} & : & \isarmeth \\
   518     \indexdef{HOL}{method}{relation}\mbox{\isa{relation}} & : & \isarmeth \\
   519     \indexdef{HOL}{method}{lexicographic-order}\mbox{\isa{lexicographic{\isacharunderscore}order}} & : & \isarmeth \\
   520   \end{matharray}
   521 
   522   \begin{rail}
   523     'relation' term
   524     ;
   525     'lexicographic\_order' (clasimpmod *)
   526     ;
   527   \end{rail}
   528 
   529   \begin{descr}
   530 
   531   \item [\mbox{\isa{pat{\isacharunderscore}completeness}}] is a specialized method to
   532   solve goals regarding the completeness of pattern matching, as
   533   required by the \mbox{\isa{\isacommand{function}}} package (cf.\
   534   \cite{isabelle-function}).
   535 
   536   \item [\mbox{\isa{relation}}~\isa{R}] introduces a termination
   537   proof using the relation \isa{R}.  The resulting proof state will
   538   contain goals expressing that \isa{R} is wellfounded, and that the
   539   arguments of recursive calls decrease with respect to \isa{R}.
   540   Usually, this method is used as the initial proof step of manual
   541   termination proofs.
   542 
   543   \item [\mbox{\isa{lexicographic{\isacharunderscore}order}}] attempts a fully
   544   automated termination proof by searching for a lexicographic
   545   combination of size measures on the arguments of the function. The
   546   method accepts the same arguments as the \mbox{\isa{auto}} method,
   547   which it uses internally to prove local descents.  The same context
   548   modifiers as for \mbox{\isa{auto}} are accepted, see
   549   \secref{sec:clasimp}.
   550 
   551   In case of failure, extensive information is printed, which can help
   552   to analyse the situation (cf.\ \cite{isabelle-function}).
   553 
   554   \end{descr}%
   555 \end{isamarkuptext}%
   556 \isamarkuptrue%
   557 %
   558 \isamarkupsubsection{Old-style recursive function definitions (TFL)%
   559 }
   560 \isamarkuptrue%
   561 %
   562 \begin{isamarkuptext}%
   563 The old TFL commands \mbox{\isa{\isacommand{recdef}}} and \mbox{\isa{\isacommand{recdef{\isacharunderscore}tc}}} for defining recursive are mostly obsolete; \mbox{\isa{\isacommand{function}}} or \mbox{\isa{\isacommand{fun}}} should be used instead.
   564 
   565   \begin{matharray}{rcl}
   566     \indexdef{HOL}{command}{recdef}\mbox{\isa{\isacommand{recdef}}} & : & \isartrans{theory}{theory} \\
   567     \indexdef{HOL}{command}{recdef-tc}\mbox{\isa{\isacommand{recdef{\isacharunderscore}tc}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isartrans{theory}{proof(prove)} \\
   568   \end{matharray}
   569 
   570   \begin{rail}
   571     'recdef' ('(' 'permissive' ')')? \\ name term (prop +) hints?
   572     ;
   573     recdeftc thmdecl? tc
   574     ;
   575     hints: '(' 'hints' (recdefmod *) ')'
   576     ;
   577     recdefmod: (('recdef\_simp' | 'recdef\_cong' | 'recdef\_wf') (() | 'add' | 'del') ':' thmrefs) | clasimpmod
   578     ;
   579     tc: nameref ('(' nat ')')?
   580     ;
   581   \end{rail}
   582 
   583   \begin{descr}
   584   
   585   \item [\mbox{\isa{\isacommand{recdef}}}] defines general well-founded
   586   recursive functions (using the TFL package), see also
   587   \cite{isabelle-HOL}.  The ``\isa{{\isachardoublequote}{\isacharparenleft}permissive{\isacharparenright}{\isachardoublequote}}'' option tells
   588   TFL to recover from failed proof attempts, returning unfinished
   589   results.  The \isa{recdef{\isacharunderscore}simp}, \isa{recdef{\isacharunderscore}cong}, and \isa{recdef{\isacharunderscore}wf} hints refer to auxiliary rules to be used in the internal
   590   automated proof process of TFL.  Additional \mbox{\isa{clasimpmod}}
   591   declarations (cf.\ \secref{sec:clasimp}) may be given to tune the
   592   context of the Simplifier (cf.\ \secref{sec:simplifier}) and
   593   Classical reasoner (cf.\ \secref{sec:classical}).
   594   
   595   \item [\mbox{\isa{\isacommand{recdef{\isacharunderscore}tc}}}~\isa{{\isachardoublequote}c\ {\isacharparenleft}i{\isacharparenright}{\isachardoublequote}}] recommences the
   596   proof for leftover termination condition number \isa{i} (default
   597   1) as generated by a \mbox{\isa{\isacommand{recdef}}} definition of
   598   constant \isa{c}.
   599   
   600   Note that in most cases, \mbox{\isa{\isacommand{recdef}}} is able to finish
   601   its internal proofs without manual intervention.
   602 
   603   \end{descr}
   604 
   605   \medskip Hints for \mbox{\isa{\isacommand{recdef}}} may be also declared
   606   globally, using the following attributes.
   607 
   608   \begin{matharray}{rcl}
   609     \indexdef{HOL}{attribute}{recdef-simp}\mbox{\isa{recdef{\isacharunderscore}simp}} & : & \isaratt \\
   610     \indexdef{HOL}{attribute}{recdef-cong}\mbox{\isa{recdef{\isacharunderscore}cong}} & : & \isaratt \\
   611     \indexdef{HOL}{attribute}{recdef-wf}\mbox{\isa{recdef{\isacharunderscore}wf}} & : & \isaratt \\
   612   \end{matharray}
   613 
   614   \begin{rail}
   615     ('recdef\_simp' | 'recdef\_cong' | 'recdef\_wf') (() | 'add' | 'del')
   616     ;
   617   \end{rail}%
   618 \end{isamarkuptext}%
   619 \isamarkuptrue%
   620 %
   621 \isamarkupsection{Definition by specification \label{sec:hol-specification}%
   622 }
   623 \isamarkuptrue%
   624 %
   625 \begin{isamarkuptext}%
   626 \begin{matharray}{rcl}
   627     \indexdef{HOL}{command}{specification}\mbox{\isa{\isacommand{specification}}} & : & \isartrans{theory}{proof(prove)} \\
   628     \indexdef{HOL}{command}{ax-specification}\mbox{\isa{\isacommand{ax{\isacharunderscore}specification}}} & : & \isartrans{theory}{proof(prove)} \\
   629   \end{matharray}
   630 
   631   \begin{rail}
   632   ('specification' | 'ax\_specification') '(' (decl +) ')' \\ (thmdecl? prop +)
   633   ;
   634   decl: ((name ':')? term '(' 'overloaded' ')'?)
   635   \end{rail}
   636 
   637   \begin{descr}
   638 
   639   \item [\mbox{\isa{\isacommand{specification}}}~\isa{{\isachardoublequote}decls\ {\isasymphi}{\isachardoublequote}}] sets up a
   640   goal stating the existence of terms with the properties specified to
   641   hold for the constants given in \isa{decls}.  After finishing the
   642   proof, the theory will be augmented with definitions for the given
   643   constants, as well as with theorems stating the properties for these
   644   constants.
   645 
   646   \item [\mbox{\isa{\isacommand{ax{\isacharunderscore}specification}}}~\isa{{\isachardoublequote}decls\ {\isasymphi}{\isachardoublequote}}] sets
   647   up a goal stating the existence of terms with the properties
   648   specified to hold for the constants given in \isa{decls}.  After
   649   finishing the proof, the theory will be augmented with axioms
   650   expressing the properties given in the first place.
   651 
   652   \item [\isa{decl}] declares a constant to be defined by the
   653   specification given.  The definition for the constant \isa{c} is
   654   bound to the name \isa{c{\isacharunderscore}def} unless a theorem name is given in
   655   the declaration.  Overloaded constants should be declared as such.
   656 
   657   \end{descr}
   658 
   659   Whether to use \mbox{\isa{\isacommand{specification}}} or \mbox{\isa{\isacommand{ax{\isacharunderscore}specification}}} is to some extent a matter of style.  \mbox{\isa{\isacommand{specification}}} introduces no new axioms, and so by
   660   construction cannot introduce inconsistencies, whereas \mbox{\isa{\isacommand{ax{\isacharunderscore}specification}}} does introduce axioms, but only after the
   661   user has explicitly proven it to be safe.  A practical issue must be
   662   considered, though: After introducing two constants with the same
   663   properties using \mbox{\isa{\isacommand{specification}}}, one can prove
   664   that the two constants are, in fact, equal.  If this might be a
   665   problem, one should use \mbox{\isa{\isacommand{ax{\isacharunderscore}specification}}}.%
   666 \end{isamarkuptext}%
   667 \isamarkuptrue%
   668 %
   669 \isamarkupsection{Inductive and coinductive definitions \label{sec:hol-inductive}%
   670 }
   671 \isamarkuptrue%
   672 %
   673 \begin{isamarkuptext}%
   674 An \textbf{inductive definition} specifies the least predicate (or
   675   set) \isa{R} closed under given rules: applying a rule to elements
   676   of \isa{R} yields a result within \isa{R}.  For example, a
   677   structural operational semantics is an inductive definition of an
   678   evaluation relation.
   679 
   680   Dually, a \textbf{coinductive definition} specifies the greatest
   681   predicate~/ set \isa{R} that is consistent with given rules: every
   682   element of \isa{R} can be seen as arising by applying a rule to
   683   elements of \isa{R}.  An important example is using bisimulation
   684   relations to formalise equivalence of processes and infinite data
   685   structures.
   686 
   687   \medskip The HOL package is related to the ZF one, which is
   688   described in a separate paper,\footnote{It appeared in CADE
   689   \cite{paulson-CADE}; a longer version is distributed with Isabelle.}
   690   which you should refer to in case of difficulties.  The package is
   691   simpler than that of ZF thanks to implicit type-checking in HOL.
   692   The types of the (co)inductive predicates (or sets) determine the
   693   domain of the fixedpoint definition, and the package does not have
   694   to use inference rules for type-checking.
   695 
   696   \begin{matharray}{rcl}
   697     \indexdef{HOL}{command}{inductive}\mbox{\isa{\isacommand{inductive}}} & : & \isarkeep{local{\dsh}theory} \\
   698     \indexdef{HOL}{command}{inductive-set}\mbox{\isa{\isacommand{inductive{\isacharunderscore}set}}} & : & \isarkeep{local{\dsh}theory} \\
   699     \indexdef{HOL}{command}{coinductive}\mbox{\isa{\isacommand{coinductive}}} & : & \isarkeep{local{\dsh}theory} \\
   700     \indexdef{HOL}{command}{coinductive-set}\mbox{\isa{\isacommand{coinductive{\isacharunderscore}set}}} & : & \isarkeep{local{\dsh}theory} \\
   701     \indexdef{HOL}{attribute}{mono}\mbox{\isa{mono}} & : & \isaratt \\
   702   \end{matharray}
   703 
   704   \begin{rail}
   705     ('inductive' | 'inductive\_set' | 'coinductive' | 'coinductive\_set') target? fixes ('for' fixes)? \\
   706     ('where' clauses)? ('monos' thmrefs)?
   707     ;
   708     clauses: (thmdecl? prop + '|')
   709     ;
   710     'mono' (() | 'add' | 'del')
   711     ;
   712   \end{rail}
   713 
   714   \begin{descr}
   715 
   716   \item [\mbox{\isa{\isacommand{inductive}}} and \mbox{\isa{\isacommand{coinductive}}}] define (co)inductive predicates from the
   717   introduction rules given in the \mbox{\isa{\isakeyword{where}}} part.  The
   718   optional \mbox{\isa{\isakeyword{for}}} part contains a list of parameters of the
   719   (co)inductive predicates that remain fixed throughout the
   720   definition.  The optional \mbox{\isa{\isakeyword{monos}}} section contains
   721   \emph{monotonicity theorems}, which are required for each operator
   722   applied to a recursive set in the introduction rules.  There
   723   \emph{must} be a theorem of the form \isa{{\isachardoublequote}A\ {\isasymle}\ B\ {\isasymLongrightarrow}\ M\ A\ {\isasymle}\ M\ B{\isachardoublequote}},
   724   for each premise \isa{{\isachardoublequote}M\ R\isactrlsub i\ t{\isachardoublequote}} in an introduction rule!
   725 
   726   \item [\mbox{\isa{\isacommand{inductive{\isacharunderscore}set}}} and \mbox{\isa{\isacommand{coinductive{\isacharunderscore}set}}}] are wrappers for to the previous commands,
   727   allowing the definition of (co)inductive sets.
   728 
   729   \item [\mbox{\isa{mono}}] declares monotonicity rules.  These
   730   rule are involved in the automated monotonicity proof of \mbox{\isa{\isacommand{inductive}}}.
   731 
   732   \end{descr}%
   733 \end{isamarkuptext}%
   734 \isamarkuptrue%
   735 %
   736 \isamarkupsubsection{Derived rules%
   737 }
   738 \isamarkuptrue%
   739 %
   740 \begin{isamarkuptext}%
   741 Each (co)inductive definition \isa{R} adds definitions to the
   742   theory and also proves some theorems:
   743 
   744   \begin{description}
   745 
   746   \item [\isa{R{\isachardot}intros}] is the list of introduction rules as proven
   747   theorems, for the recursive predicates (or sets).  The rules are
   748   also available individually, using the names given them in the
   749   theory file;
   750 
   751   \item [\isa{R{\isachardot}cases}] is the case analysis (or elimination) rule;
   752 
   753   \item [\isa{R{\isachardot}induct} or \isa{R{\isachardot}coinduct}] is the (co)induction
   754   rule.
   755 
   756   \end{description}
   757 
   758   When several predicates \isa{{\isachardoublequote}R\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ R\isactrlsub n{\isachardoublequote}} are
   759   defined simultaneously, the list of introduction rules is called
   760   \isa{{\isachardoublequote}R\isactrlsub {\isadigit{1}}{\isacharunderscore}{\isasymdots}{\isacharunderscore}R\isactrlsub n{\isachardot}intros{\isachardoublequote}}, the case analysis rules are
   761   called \isa{{\isachardoublequote}R\isactrlsub {\isadigit{1}}{\isachardot}cases{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ R\isactrlsub n{\isachardot}cases{\isachardoublequote}}, and the list
   762   of mutual induction rules is called \isa{{\isachardoublequote}R\isactrlsub {\isadigit{1}}{\isacharunderscore}{\isasymdots}{\isacharunderscore}R\isactrlsub n{\isachardot}inducts{\isachardoublequote}}.%
   763 \end{isamarkuptext}%
   764 \isamarkuptrue%
   765 %
   766 \isamarkupsubsection{Monotonicity theorems%
   767 }
   768 \isamarkuptrue%
   769 %
   770 \begin{isamarkuptext}%
   771 Each theory contains a default set of theorems that are used in
   772   monotonicity proofs.  New rules can be added to this set via the
   773   \mbox{\isa{mono}} attribute.  The HOL theory \isa{Inductive}
   774   shows how this is done.  In general, the following monotonicity
   775   theorems may be added:
   776 
   777   \begin{itemize}
   778 
   779   \item Theorems of the form \isa{{\isachardoublequote}A\ {\isasymle}\ B\ {\isasymLongrightarrow}\ M\ A\ {\isasymle}\ M\ B{\isachardoublequote}}, for proving
   780   monotonicity of inductive definitions whose introduction rules have
   781   premises involving terms such as \isa{{\isachardoublequote}M\ R\isactrlsub i\ t{\isachardoublequote}}.
   782 
   783   \item Monotonicity theorems for logical operators, which are of the
   784   general form \isa{{\isachardoublequote}{\isacharparenleft}{\isasymdots}\ {\isasymlongrightarrow}\ {\isasymdots}{\isacharparenright}\ {\isasymLongrightarrow}\ {\isasymdots}\ {\isacharparenleft}{\isasymdots}\ {\isasymlongrightarrow}\ {\isasymdots}{\isacharparenright}\ {\isasymLongrightarrow}\ {\isasymdots}\ {\isasymlongrightarrow}\ {\isasymdots}{\isachardoublequote}}.  For example, in
   785   the case of the operator \isa{{\isachardoublequote}{\isasymor}{\isachardoublequote}}, the corresponding theorem is
   786   \[
   787   \infer{\isa{{\isachardoublequote}P\isactrlsub {\isadigit{1}}\ {\isasymor}\ P\isactrlsub {\isadigit{2}}\ {\isasymlongrightarrow}\ Q\isactrlsub {\isadigit{1}}\ {\isasymor}\ Q\isactrlsub {\isadigit{2}}{\isachardoublequote}}}{\isa{{\isachardoublequote}P\isactrlsub {\isadigit{1}}\ {\isasymlongrightarrow}\ Q\isactrlsub {\isadigit{1}}{\isachardoublequote}} & \isa{{\isachardoublequote}P\isactrlsub {\isadigit{2}}\ {\isasymlongrightarrow}\ Q\isactrlsub {\isadigit{2}}{\isachardoublequote}}}
   788   \]
   789 
   790   \item De Morgan style equations for reasoning about the ``polarity''
   791   of expressions, e.g.
   792   \[
   793   \isa{{\isachardoublequote}{\isasymnot}\ {\isasymnot}\ P\ {\isasymlongleftrightarrow}\ P{\isachardoublequote}} \qquad\qquad
   794   \isa{{\isachardoublequote}{\isasymnot}\ {\isacharparenleft}P\ {\isasymand}\ Q{\isacharparenright}\ {\isasymlongleftrightarrow}\ {\isasymnot}\ P\ {\isasymor}\ {\isasymnot}\ Q{\isachardoublequote}}
   795   \]
   796 
   797   \item Equations for reducing complex operators to more primitive
   798   ones whose monotonicity can easily be proved, e.g.
   799   \[
   800   \isa{{\isachardoublequote}{\isacharparenleft}P\ {\isasymlongrightarrow}\ Q{\isacharparenright}\ {\isasymlongleftrightarrow}\ {\isasymnot}\ P\ {\isasymor}\ Q{\isachardoublequote}} \qquad\qquad
   801   \isa{{\isachardoublequote}Ball\ A\ P\ {\isasymequiv}\ {\isasymforall}x{\isachardot}\ x\ {\isasymin}\ A\ {\isasymlongrightarrow}\ P\ x{\isachardoublequote}}
   802   \]
   803 
   804   \end{itemize}
   805 
   806   %FIXME: Example of an inductive definition%
   807 \end{isamarkuptext}%
   808 \isamarkuptrue%
   809 %
   810 \isamarkupsection{Arithmetic proof support%
   811 }
   812 \isamarkuptrue%
   813 %
   814 \begin{isamarkuptext}%
   815 \begin{matharray}{rcl}
   816     \indexdef{HOL}{method}{arith}\mbox{\isa{arith}} & : & \isarmeth \\
   817     \indexdef{HOL}{method}{arith-split}\mbox{\isa{arith{\isacharunderscore}split}} & : & \isaratt \\
   818   \end{matharray}
   819 
   820   The \mbox{\isa{arith}} method decides linear arithmetic problems
   821   (on types \isa{nat}, \isa{int}, \isa{real}).  Any current
   822   facts are inserted into the goal before running the procedure.
   823 
   824   The \mbox{\isa{arith{\isacharunderscore}split}} attribute declares case split rules
   825   to be expanded before the arithmetic procedure is invoked.
   826 
   827   Note that a simpler (but faster) version of arithmetic reasoning is
   828   already performed by the Simplifier.%
   829 \end{isamarkuptext}%
   830 \isamarkuptrue%
   831 %
   832 \isamarkupsection{Cases and induction: emulating tactic scripts \label{sec:hol-induct-tac}%
   833 }
   834 \isamarkuptrue%
   835 %
   836 \begin{isamarkuptext}%
   837 The following important tactical tools of Isabelle/HOL have been
   838   ported to Isar.  These should be never used in proper proof texts!
   839 
   840   \begin{matharray}{rcl}
   841     \indexdef{HOL}{method}{case-tac}\mbox{\isa{case{\isacharunderscore}tac}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarmeth \\
   842     \indexdef{HOL}{method}{induct-tac}\mbox{\isa{induct{\isacharunderscore}tac}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarmeth \\
   843     \indexdef{HOL}{method}{ind-cases}\mbox{\isa{ind{\isacharunderscore}cases}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarmeth \\
   844     \indexdef{HOL}{command}{inductive-cases}\mbox{\isa{\isacommand{inductive{\isacharunderscore}cases}}} & : & \isartrans{theory}{theory} \\
   845   \end{matharray}
   846 
   847   \begin{rail}
   848     'case\_tac' goalspec? term rule?
   849     ;
   850     'induct\_tac' goalspec? (insts * 'and') rule?
   851     ;
   852     'ind\_cases' (prop +) ('for' (name +)) ?
   853     ;
   854     'inductive\_cases' (thmdecl? (prop +) + 'and')
   855     ;
   856 
   857     rule: ('rule' ':' thmref)
   858     ;
   859   \end{rail}
   860 
   861   \begin{descr}
   862 
   863   \item [\mbox{\isa{case{\isacharunderscore}tac}} and \mbox{\isa{induct{\isacharunderscore}tac}}]
   864   admit to reason about inductive datatypes only (unless an
   865   alternative rule is given explicitly).  Furthermore, \mbox{\isa{case{\isacharunderscore}tac}} does a classical case split on booleans; \mbox{\isa{induct{\isacharunderscore}tac}} allows only variables to be given as instantiation.
   866   These tactic emulations feature both goal addressing and dynamic
   867   instantiation.  Note that named rule cases are \emph{not} provided
   868   as would be by the proper \mbox{\isa{induct}} and \mbox{\isa{cases}} proof
   869   methods (see \secref{sec:cases-induct}).
   870   
   871   \item [\mbox{\isa{ind{\isacharunderscore}cases}} and \mbox{\isa{\isacommand{inductive{\isacharunderscore}cases}}}] provide an interface to the internal
   872   \texttt{mk_cases} operation.  Rules are simplified in an
   873   unrestricted forward manner.
   874 
   875   While \mbox{\isa{ind{\isacharunderscore}cases}} is a proof method to apply the
   876   result immediately as elimination rules, \mbox{\isa{\isacommand{inductive{\isacharunderscore}cases}}} provides case split theorems at the theory level
   877   for later use.  The \mbox{\isa{\isakeyword{for}}} argument of the \mbox{\isa{ind{\isacharunderscore}cases}} method allows to specify a list of variables that should
   878   be generalized before applying the resulting rule.
   879 
   880   \end{descr}%
   881 \end{isamarkuptext}%
   882 \isamarkuptrue%
   883 %
   884 \isamarkupsection{Executable code%
   885 }
   886 \isamarkuptrue%
   887 %
   888 \begin{isamarkuptext}%
   889 Isabelle/Pure provides two generic frameworks to support code
   890   generation from executable specifications.  Isabelle/HOL
   891   instantiates these mechanisms in a way that is amenable to end-user
   892   applications.
   893 
   894   One framework generates code from both functional and relational
   895   programs to SML.  See \cite{isabelle-HOL} for further information
   896   (this actually covers the new-style theory format as well).
   897 
   898   \begin{matharray}{rcl}
   899     \indexdef{HOL}{command}{value}\mbox{\isa{\isacommand{value}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarkeep{theory~|~proof} \\
   900     \indexdef{HOL}{command}{code-module}\mbox{\isa{\isacommand{code{\isacharunderscore}module}}} & : & \isartrans{theory}{theory} \\
   901     \indexdef{HOL}{command}{code-library}\mbox{\isa{\isacommand{code{\isacharunderscore}library}}} & : & \isartrans{theory}{theory} \\
   902     \indexdef{HOL}{command}{consts-code}\mbox{\isa{\isacommand{consts{\isacharunderscore}code}}} & : & \isartrans{theory}{theory} \\
   903     \indexdef{HOL}{command}{types-code}\mbox{\isa{\isacommand{types{\isacharunderscore}code}}} & : & \isartrans{theory}{theory} \\  
   904     \indexdef{HOL}{attribute}{code}\mbox{\isa{code}} & : & \isaratt \\
   905   \end{matharray}
   906 
   907   \begin{rail}
   908   'value' term
   909   ;
   910 
   911   ( 'code\_module' | 'code\_library' ) modespec ? name ? \\
   912     ( 'file' name ) ? ( 'imports' ( name + ) ) ? \\
   913     'contains' ( ( name '=' term ) + | term + )
   914   ;
   915 
   916   modespec: '(' ( name * ) ')'
   917   ;
   918 
   919   'consts\_code' (codespec +)
   920   ;
   921 
   922   codespec: const template attachment ?
   923   ;
   924 
   925   'types\_code' (tycodespec +)
   926   ;
   927 
   928   tycodespec: name template attachment ?
   929   ;
   930 
   931   const: term
   932   ;
   933 
   934   template: '(' string ')'
   935   ;
   936 
   937   attachment: 'attach' modespec ? verblbrace text verbrbrace
   938   ;
   939 
   940   'code' (name)?
   941   ;
   942   \end{rail}
   943 
   944   \begin{descr}
   945 
   946   \item [\mbox{\isa{\isacommand{value}}}~\isa{t}] evaluates and prints a
   947   term using the code generator.
   948 
   949   \end{descr}
   950 
   951   \medskip The other framework generates code from functional programs
   952   (including overloading using type classes) to SML \cite{SML}, OCaml
   953   \cite{OCaml} and Haskell \cite{haskell-revised-report}.
   954   Conceptually, code generation is split up in three steps:
   955   \emph{selection} of code theorems, \emph{translation} into an
   956   abstract executable view and \emph{serialization} to a specific
   957   \emph{target language}.  See \cite{isabelle-codegen} for an
   958   introduction on how to use it.
   959 
   960   \begin{matharray}{rcl}
   961     \indexdef{HOL}{command}{export-code}\mbox{\isa{\isacommand{export{\isacharunderscore}code}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarkeep{theory~|~proof} \\
   962     \indexdef{HOL}{command}{code-thms}\mbox{\isa{\isacommand{code{\isacharunderscore}thms}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarkeep{theory~|~proof} \\
   963     \indexdef{HOL}{command}{code-deps}\mbox{\isa{\isacommand{code{\isacharunderscore}deps}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarkeep{theory~|~proof} \\
   964     \indexdef{HOL}{command}{code-datatype}\mbox{\isa{\isacommand{code{\isacharunderscore}datatype}}} & : & \isartrans{theory}{theory} \\
   965     \indexdef{HOL}{command}{code-const}\mbox{\isa{\isacommand{code{\isacharunderscore}const}}} & : & \isartrans{theory}{theory} \\
   966     \indexdef{HOL}{command}{code-type}\mbox{\isa{\isacommand{code{\isacharunderscore}type}}} & : & \isartrans{theory}{theory} \\
   967     \indexdef{HOL}{command}{code-class}\mbox{\isa{\isacommand{code{\isacharunderscore}class}}} & : & \isartrans{theory}{theory} \\
   968     \indexdef{HOL}{command}{code-instance}\mbox{\isa{\isacommand{code{\isacharunderscore}instance}}} & : & \isartrans{theory}{theory} \\
   969     \indexdef{HOL}{command}{code-monad}\mbox{\isa{\isacommand{code{\isacharunderscore}monad}}} & : & \isartrans{theory}{theory} \\
   970     \indexdef{HOL}{command}{code-reserved}\mbox{\isa{\isacommand{code{\isacharunderscore}reserved}}} & : & \isartrans{theory}{theory} \\
   971     \indexdef{HOL}{command}{code-include}\mbox{\isa{\isacommand{code{\isacharunderscore}include}}} & : & \isartrans{theory}{theory} \\
   972     \indexdef{HOL}{command}{code-modulename}\mbox{\isa{\isacommand{code{\isacharunderscore}modulename}}} & : & \isartrans{theory}{theory} \\
   973     \indexdef{HOL}{command}{code-exception}\mbox{\isa{\isacommand{code{\isacharunderscore}exception}}} & : & \isartrans{theory}{theory} \\
   974     \indexdef{HOL}{command}{print-codesetup}\mbox{\isa{\isacommand{print{\isacharunderscore}codesetup}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarkeep{theory~|~proof} \\
   975     \indexdef{HOL}{attribute}{code}\mbox{\isa{code}} & : & \isaratt \\
   976   \end{matharray}
   977 
   978   \begin{rail}
   979     'export\_code' ( constexpr + ) ? \\
   980       ( ( 'in' target ( 'module\_name' string ) ? \\
   981         ( 'file' ( string | '-' ) ) ? ( '(' args ')' ) ?) + ) ?
   982     ;
   983 
   984     'code\_thms' ( constexpr + ) ?
   985     ;
   986 
   987     'code\_deps' ( constexpr + ) ?
   988     ;
   989 
   990     const: term
   991     ;
   992 
   993     constexpr: ( const | 'name.*' | '*' )
   994     ;
   995 
   996     typeconstructor: nameref
   997     ;
   998 
   999     class: nameref
  1000     ;
  1001 
  1002     target: 'OCaml' | 'SML' | 'Haskell'
  1003     ;
  1004 
  1005     'code\_datatype' const +
  1006     ;
  1007 
  1008     'code\_const' (const + 'and') \\
  1009       ( ( '(' target ( syntax ? + 'and' ) ')' ) + )
  1010     ;
  1011 
  1012     'code\_type' (typeconstructor + 'and') \\
  1013       ( ( '(' target ( syntax ? + 'and' ) ')' ) + )
  1014     ;
  1015 
  1016     'code\_class' (class + 'and') \\
  1017       ( ( '(' target \\
  1018         ( ( string ('where' \\
  1019           ( const ( '==' | equiv ) string ) + ) ? ) ? + 'and' ) ')' ) + )
  1020     ;
  1021 
  1022     'code\_instance' (( typeconstructor '::' class ) + 'and') \\
  1023       ( ( '(' target ( '-' ? + 'and' ) ')' ) + )
  1024     ;
  1025 
  1026     'code\_monad' const const target
  1027     ;
  1028 
  1029     'code\_reserved' target ( string + )
  1030     ;
  1031 
  1032     'code\_include' target ( string ( string | '-') )
  1033     ;
  1034 
  1035     'code\_modulename' target ( ( string string ) + )
  1036     ;
  1037 
  1038     'code\_exception' ( const + )
  1039     ;
  1040 
  1041     syntax: string | ( 'infix' | 'infixl' | 'infixr' ) nat string
  1042     ;
  1043 
  1044     'code' ('func' | 'inline') ( 'del' )?
  1045     ;
  1046   \end{rail}
  1047 
  1048   \begin{descr}
  1049 
  1050   \item [\mbox{\isa{\isacommand{export{\isacharunderscore}code}}}] is the canonical interface
  1051   for generating and serializing code: for a given list of constants,
  1052   code is generated for the specified target languages.  Abstract code
  1053   is cached incrementally.  If no constant is given, the currently
  1054   cached code is serialized.  If no serialization instruction is
  1055   given, only abstract code is cached.
  1056 
  1057   Constants may be specified by giving them literally, referring to
  1058   all executable contants within a certain theory by giving \isa{{\isachardoublequote}name{\isachardot}{\isacharasterisk}{\isachardoublequote}}, or referring to \emph{all} executable constants currently
  1059   available by giving \isa{{\isachardoublequote}{\isacharasterisk}{\isachardoublequote}}.
  1060 
  1061   By default, for each involved theory one corresponding name space
  1062   module is generated.  Alternativly, a module name may be specified
  1063   after the \mbox{\isa{\isakeyword{module{\isacharunderscore}name}}} keyword; then \emph{all} code is
  1064   placed in this module.
  1065 
  1066   For \emph{SML} and \emph{OCaml}, the file specification refers to a
  1067   single file; for \emph{Haskell}, it refers to a whole directory,
  1068   where code is generated in multiple files reflecting the module
  1069   hierarchy.  The file specification ``\isa{{\isachardoublequote}{\isacharminus}{\isachardoublequote}}'' denotes standard
  1070   output.  For \emph{SML}, omitting the file specification compiles
  1071   code internally in the context of the current ML session.
  1072 
  1073   Serializers take an optional list of arguments in parentheses.  For
  1074   \emph{Haskell} a module name prefix may be given using the ``\isa{{\isachardoublequote}root{\isacharcolon}{\isachardoublequote}}'' argument; ``\isa{string{\isacharunderscore}classes}'' adds a ``\verb|deriving (Read, Show)|'' clause to each appropriate datatype
  1075   declaration.
  1076 
  1077   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}thms}}}] prints a list of theorems
  1078   representing the corresponding program containing all given
  1079   constants; if no constants are given, the currently cached code
  1080   theorems are printed.
  1081 
  1082   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}deps}}}] visualizes dependencies of
  1083   theorems representing the corresponding program containing all given
  1084   constants; if no constants are given, the currently cached code
  1085   theorems are visualized.
  1086 
  1087   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}datatype}}}] specifies a constructor set
  1088   for a logical type.
  1089 
  1090   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}const}}}] associates a list of constants
  1091   with target-specific serializations; omitting a serialization
  1092   deletes an existing serialization.
  1093 
  1094   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}type}}}] associates a list of type
  1095   constructors with target-specific serializations; omitting a
  1096   serialization deletes an existing serialization.
  1097 
  1098   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}class}}}] associates a list of classes
  1099   with target-specific class names; in addition, constants associated
  1100   with this class may be given target-specific names used for instance
  1101   declarations; omitting a serialization deletes an existing
  1102   serialization.  This applies only to \emph{Haskell}.
  1103 
  1104   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}instance}}}] declares a list of type
  1105   constructor / class instance relations as ``already present'' for a
  1106   given target.  Omitting a ``\isa{{\isachardoublequote}{\isacharminus}{\isachardoublequote}}'' deletes an existing
  1107   ``already present'' declaration.  This applies only to
  1108   \emph{Haskell}.
  1109 
  1110   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}monad}}}] provides an auxiliary
  1111   mechanism to generate monadic code.
  1112 
  1113   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}reserved}}}] declares a list of names as
  1114   reserved for a given target, preventing it to be shadowed by any
  1115   generated code.
  1116 
  1117   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}include}}}] adds arbitrary named content
  1118   (``include'') to generated code.  A as last argument ``\isa{{\isachardoublequote}{\isacharminus}{\isachardoublequote}}''
  1119   will remove an already added ``include''.
  1120 
  1121   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}modulename}}}] declares aliasings from
  1122   one module name onto another.
  1123 
  1124   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}exception}}}] declares constants which
  1125   are not required to have a definition by a defining equations; these
  1126   are mapped on exceptions instead.
  1127 
  1128   \item [\mbox{\isa{code}}~\isa{func}] explicitly selects (or
  1129   with option ``\isa{{\isachardoublequote}del{\isacharcolon}{\isachardoublequote}}'' deselects) a defining equation for
  1130   code generation.  Usually packages introducing defining equations
  1131   provide a resonable default setup for selection.
  1132 
  1133   \item [\mbox{\isa{code}}\isa{inline}] declares (or with
  1134   option ``\isa{{\isachardoublequote}del{\isacharcolon}{\isachardoublequote}}'' removes) inlining theorems which are
  1135   applied as rewrite rules to any defining equation during
  1136   preprocessing.
  1137 
  1138   \item [\mbox{\isa{\isacommand{print{\isacharunderscore}codesetup}}}] gives an overview on
  1139   selected defining equations, code generator datatypes and
  1140   preprocessor setup.
  1141 
  1142   \end{descr}%
  1143 \end{isamarkuptext}%
  1144 \isamarkuptrue%
  1145 %
  1146 \isadelimtheory
  1147 %
  1148 \endisadelimtheory
  1149 %
  1150 \isatagtheory
  1151 \isacommand{end}\isamarkupfalse%
  1152 %
  1153 \endisatagtheory
  1154 {\isafoldtheory}%
  1155 %
  1156 \isadelimtheory
  1157 %
  1158 \endisadelimtheory
  1159 \isanewline
  1160 \isanewline
  1161 \end{isabellebody}%
  1162 %%% Local Variables:
  1163 %%% mode: latex
  1164 %%% TeX-master: "root"
  1165 %%% End: