doc-src/IsarRef/Thy/document/HOL_Specific.tex
author wenzelm
Thu May 08 23:07:15 2008 +0200 (2008-05-08)
changeset 26861 e6fe036ec21d
parent 26854 9b4aec46ad78
child 26895 d066f9db833b
permissions -rw-r--r--
updated generated file;
     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{Isabelle/HOL \label{ch:hol}%
    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}{\isasymrparr}{\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
   184   the logic 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}\isactrlvec c\ {\isacharcolon}{\isacharcolon}\ \isactrlvec {\isasymsigma}{\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}\isactrlvec c\ {\isacharcolon}{\isacharcolon}\ \isactrlvec {\isasymsigma}{\isacharcomma}\ {\isasymdots}\ {\isacharcolon}{\isacharcolon}\ {\isasymzeta}{\isasymrparr}\ {\isasymRightarrow}\ {\isasymlparr}\isactrlvec c\ {\isacharcolon}{\isacharcolon}\ \isactrlvec {\isasymsigma}{\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}\isactrlvec c\ {\isacharcolon}{\isacharcolon}\ \isactrlvec {\isasymsigma}{\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   \medskip
   287   \begin{tabular}{lll}
   288     \isa{{\isachardoublequote}c\isactrlsub i{\isachardoublequote}} & \isa{{\isachardoublequote}{\isacharcolon}{\isacharcolon}{\isachardoublequote}} & \isa{{\isachardoublequote}{\isasymlparr}\isactrlvec b\ {\isacharcolon}{\isacharcolon}\ \isactrlvec {\isasymrho}{\isacharcomma}\ \isactrlvec c\ {\isacharcolon}{\isacharcolon}\ \isactrlvec {\isasymsigma}{\isacharcomma}\ {\isasymdots}\ {\isacharcolon}{\isacharcolon}\ {\isasymzeta}{\isasymrparr}\ {\isasymRightarrow}\ {\isasymsigma}\isactrlsub i{\isachardoublequote}} \\
   289     \isa{{\isachardoublequote}c\isactrlsub i{\isacharunderscore}update{\isachardoublequote}} & \isa{{\isachardoublequote}{\isacharcolon}{\isacharcolon}{\isachardoublequote}} & \isa{{\isachardoublequote}{\isasymsigma}\isactrlsub i\ {\isasymRightarrow}\ {\isasymlparr}\isactrlvec b\ {\isacharcolon}{\isacharcolon}\ \isactrlvec {\isasymrho}{\isacharcomma}\ \isactrlvec c\ {\isacharcolon}{\isacharcolon}\ \isactrlvec {\isasymsigma}{\isacharcomma}\ {\isasymdots}\ {\isacharcolon}{\isacharcolon}\ {\isasymzeta}{\isasymrparr}\ {\isasymRightarrow}\ {\isasymlparr}\isactrlvec b\ {\isacharcolon}{\isacharcolon}\ \isactrlvec {\isasymrho}{\isacharcomma}\ \isactrlvec c\ {\isacharcolon}{\isacharcolon}\ \isactrlvec {\isasymsigma}{\isacharcomma}\ {\isasymdots}\ {\isacharcolon}{\isacharcolon}\ {\isasymzeta}{\isasymrparr}{\isachardoublequote}} \\
   290     \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}\isactrlvec b\ {\isacharcolon}{\isacharcolon}\ \isactrlvec {\isasymrho}{\isacharcomma}\ \isactrlvec c\ {\isacharcolon}{\isacharcolon}\ \isactrlvec {\isasymsigma}{\isasymrparr}{\isachardoublequote}} \\
   291   \end{tabular}
   292   \medskip
   293 
   294   \noindent Some further operations address the extension aspect of a
   295   derived record scheme specifically: \isa{{\isachardoublequote}t{\isachardot}fields{\isachardoublequote}} produces a
   296   record fragment consisting of exactly the new fields introduced here
   297   (the result may serve as a more part elsewhere); \isa{{\isachardoublequote}t{\isachardot}extend{\isachardoublequote}}
   298   takes a fixed record and adds a given more part; \isa{{\isachardoublequote}t{\isachardot}truncate{\isachardoublequote}} restricts a record scheme to a fixed record.
   299 
   300   \medskip
   301   \begin{tabular}{lll}
   302     \isa{{\isachardoublequote}t{\isachardot}fields{\isachardoublequote}} & \isa{{\isachardoublequote}{\isacharcolon}{\isacharcolon}{\isachardoublequote}} & \isa{{\isachardoublequote}{\isasymsigma}\isactrlsub {\isadigit{1}}\ {\isasymRightarrow}\ {\isasymdots}\ {\isasymsigma}\isactrlsub n\ {\isasymRightarrow}\ {\isasymlparr}\isactrlvec c\ {\isacharcolon}{\isacharcolon}\ \isactrlvec {\isasymsigma}{\isasymrparr}{\isachardoublequote}} \\
   303     \isa{{\isachardoublequote}t{\isachardot}extend{\isachardoublequote}} & \isa{{\isachardoublequote}{\isacharcolon}{\isacharcolon}{\isachardoublequote}} & \isa{{\isachardoublequote}{\isasymlparr}\isactrlvec b\ {\isacharcolon}{\isacharcolon}\ \isactrlvec {\isasymrho}{\isacharcomma}\ \isactrlvec c\ {\isacharcolon}{\isacharcolon}\ \isactrlvec {\isasymsigma}{\isasymrparr}\ {\isasymRightarrow}\ {\isasymzeta}\ {\isasymRightarrow}\ {\isasymlparr}\isactrlvec b\ {\isacharcolon}{\isacharcolon}\ \isactrlvec {\isasymrho}{\isacharcomma}\ \isactrlvec c\ {\isacharcolon}{\isacharcolon}\ \isactrlvec {\isasymsigma}{\isacharcomma}\ {\isasymdots}\ {\isacharcolon}{\isacharcolon}\ {\isasymzeta}{\isasymrparr}{\isachardoublequote}} \\
   304     \isa{{\isachardoublequote}t{\isachardot}truncate{\isachardoublequote}} & \isa{{\isachardoublequote}{\isacharcolon}{\isacharcolon}{\isachardoublequote}} & \isa{{\isachardoublequote}{\isasymlparr}\isactrlvec b\ {\isacharcolon}{\isacharcolon}\ \isactrlvec {\isasymrho}{\isacharcomma}\ \isactrlvec c\ {\isacharcolon}{\isacharcolon}\ \isactrlvec {\isasymsigma}{\isacharcomma}\ {\isasymdots}\ {\isacharcolon}{\isacharcolon}\ {\isasymzeta}{\isasymrparr}\ {\isasymRightarrow}\ {\isasymlparr}\isactrlvec b\ {\isacharcolon}{\isacharcolon}\ \isactrlvec {\isasymrho}{\isacharcomma}\ \isactrlvec c\ {\isacharcolon}{\isacharcolon}\ \isactrlvec {\isasymsigma}{\isasymrparr}{\isachardoublequote}} \\
   305   \end{tabular}
   306   \medskip
   307 
   308   \noindent Note that \isa{{\isachardoublequote}t{\isachardot}make{\isachardoublequote}} and \isa{{\isachardoublequote}t{\isachardot}fields{\isachardoublequote}} coincide
   309   for root records.%
   310 \end{isamarkuptext}%
   311 \isamarkuptrue%
   312 %
   313 \isamarkupsubsection{Derived rules and proof tools%
   314 }
   315 \isamarkuptrue%
   316 %
   317 \begin{isamarkuptext}%
   318 The record package proves several results internally, declaring
   319   these facts to appropriate proof tools.  This enables users to
   320   reason about record structures quite conveniently.  Assume that
   321   \isa{t} is a record type as specified above.
   322 
   323   \begin{enumerate}
   324   
   325   \item Standard conversions for selectors or updates applied to
   326   record constructor terms are made part of the default Simplifier
   327   context; thus proofs by reduction of basic operations merely require
   328   the \mbox{\isa{simp}} method without further arguments.  These rules
   329   are available as \isa{{\isachardoublequote}t{\isachardot}simps{\isachardoublequote}}, too.
   330   
   331   \item Selectors applied to updated records are automatically reduced
   332   by an internal simplification procedure, which is also part of the
   333   standard Simplifier setup.
   334 
   335   \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
   336   Reasoner as \mbox{\isa{iff}} rules.  These rules are available as
   337   \isa{{\isachardoublequote}t{\isachardot}iffs{\isachardoublequote}}.
   338 
   339   \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,
   340   and as the basic rule context as ``\mbox{\isa{intro}}\isa{{\isachardoublequote}{\isacharquery}{\isachardoublequote}}''.
   341   The rule is called \isa{{\isachardoublequote}t{\isachardot}equality{\isachardoublequote}}.
   342 
   343   \item Representations of arbitrary record expressions as canonical
   344   constructor terms are provided both in \mbox{\isa{cases}} and \mbox{\isa{induct}} format (cf.\ the generic proof methods of the same name,
   345   \secref{sec:cases-induct}).  Several variations are available, for
   346   fixed records, record schemes, more parts etc.
   347   
   348   The generic proof methods are sufficiently smart to pick the most
   349   sensible rule according to the type of the indicated record
   350   expression: users just need to apply something like ``\isa{{\isachardoublequote}{\isacharparenleft}cases\ r{\isacharparenright}{\isachardoublequote}}'' to a certain proof problem.
   351 
   352   \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}
   353   treated automatically, but usually need to be expanded by hand,
   354   using the collective fact \isa{{\isachardoublequote}t{\isachardot}defs{\isachardoublequote}}.
   355 
   356   \end{enumerate}%
   357 \end{isamarkuptext}%
   358 \isamarkuptrue%
   359 %
   360 \isamarkupsection{Datatypes \label{sec:hol-datatype}%
   361 }
   362 \isamarkuptrue%
   363 %
   364 \begin{isamarkuptext}%
   365 \begin{matharray}{rcl}
   366     \indexdef{HOL}{command}{datatype}\mbox{\isa{\isacommand{datatype}}} & : & \isartrans{theory}{theory} \\
   367     \indexdef{HOL}{command}{rep\_datatype}\mbox{\isa{\isacommand{rep{\isacharunderscore}datatype}}} & : & \isartrans{theory}{theory} \\
   368   \end{matharray}
   369 
   370   \begin{rail}
   371     'datatype' (dtspec + 'and')
   372     ;
   373     'rep\_datatype' (name *) dtrules
   374     ;
   375 
   376     dtspec: parname? typespec infix? '=' (cons + '|')
   377     ;
   378     cons: name (type *) mixfix?
   379     ;
   380     dtrules: 'distinct' thmrefs 'inject' thmrefs 'induction' thmrefs
   381   \end{rail}
   382 
   383   \begin{descr}
   384 
   385   \item [\mbox{\isa{\isacommand{datatype}}}] defines inductive datatypes in
   386   HOL.
   387 
   388   \item [\mbox{\isa{\isacommand{rep{\isacharunderscore}datatype}}}] represents existing types as
   389   inductive ones, generating the standard infrastructure of derived
   390   concepts (primitive recursion etc.).
   391 
   392   \end{descr}
   393 
   394   The induction and exhaustion theorems generated provide case names
   395   according to the constructors involved, while parameters are named
   396   after the types (see also \secref{sec:cases-induct}).
   397 
   398   See \cite{isabelle-HOL} for more details on datatypes, but beware of
   399   the old-style theory syntax being used there!  Apart from proper
   400   proof methods for case-analysis and induction, there are also
   401   emulations of ML tactics \mbox{\isa{case{\isacharunderscore}tac}} and \mbox{\isa{induct{\isacharunderscore}tac}} available, see \secref{sec:hol-induct-tac}; these admit
   402   to refer directly to the internal structure of subgoals (including
   403   internally bound parameters).%
   404 \end{isamarkuptext}%
   405 \isamarkuptrue%
   406 %
   407 \isamarkupsection{Recursive functions \label{sec:recursion}%
   408 }
   409 \isamarkuptrue%
   410 %
   411 \begin{isamarkuptext}%
   412 \begin{matharray}{rcl}
   413     \indexdef{HOL}{command}{primrec}\mbox{\isa{\isacommand{primrec}}} & : & \isarkeep{local{\dsh}theory} \\
   414     \indexdef{HOL}{command}{fun}\mbox{\isa{\isacommand{fun}}} & : & \isarkeep{local{\dsh}theory} \\
   415     \indexdef{HOL}{command}{function}\mbox{\isa{\isacommand{function}}} & : & \isartrans{local{\dsh}theory}{proof(prove)} \\
   416     \indexdef{HOL}{command}{termination}\mbox{\isa{\isacommand{termination}}} & : & \isartrans{local{\dsh}theory}{proof(prove)} \\
   417   \end{matharray}
   418 
   419   \railalias{funopts}{function\_opts}  %FIXME ??
   420 
   421   \begin{rail}
   422     'primrec' target? fixes 'where' equations
   423     ;
   424     equations: (thmdecl? prop + '|')
   425     ;
   426     ('fun' | 'function') (funopts)? fixes 'where' clauses
   427     ;
   428     clauses: (thmdecl? prop ('(' 'otherwise' ')')? + '|')
   429     ;
   430     funopts: '(' (('sequential' | 'in' name | 'domintros' | 'tailrec' |
   431     'default' term) + ',') ')'
   432     ;
   433     'termination' ( term )?
   434   \end{rail}
   435 
   436   \begin{descr}
   437 
   438   \item [\mbox{\isa{\isacommand{primrec}}}] defines primitive recursive
   439   functions over datatypes, see also \cite{isabelle-HOL}.
   440 
   441   \item [\mbox{\isa{\isacommand{function}}}] defines functions by general
   442   wellfounded recursion. A detailed description with examples can be
   443   found in \cite{isabelle-function}. The function is specified by a
   444   set of (possibly conditional) recursive equations with arbitrary
   445   pattern matching. The command generates proof obligations for the
   446   completeness and the compatibility of patterns.
   447 
   448   The defined function is considered partial, and the resulting
   449   simplification rules (named \isa{{\isachardoublequote}f{\isachardot}psimps{\isachardoublequote}}) and induction rule
   450   (named \isa{{\isachardoublequote}f{\isachardot}pinduct{\isachardoublequote}}) are guarded by a generated domain
   451   predicate \isa{{\isachardoublequote}f{\isacharunderscore}dom{\isachardoublequote}}. The \mbox{\isa{\isacommand{termination}}}
   452   command can then be used to establish that the function is total.
   453 
   454   \item [\mbox{\isa{\isacommand{fun}}}] is a shorthand notation for
   455   ``\mbox{\isa{\isacommand{function}}}~\isa{{\isachardoublequote}{\isacharparenleft}sequential{\isacharparenright}{\isachardoublequote}}, followed by
   456   automated proof attempts regarding pattern matching and termination.
   457   See \cite{isabelle-function} for further details.
   458 
   459   \item [\mbox{\isa{\isacommand{termination}}}~\isa{f}] commences a
   460   termination proof for the previously defined function \isa{f}.  If
   461   this is omitted, the command refers to the most recent function
   462   definition.  After the proof is closed, the recursive equations and
   463   the induction principle is established.
   464 
   465   \end{descr}
   466 
   467   %FIXME check
   468 
   469   Recursive definitions introduced by both the \mbox{\isa{\isacommand{primrec}}} and the \mbox{\isa{\isacommand{function}}} command accommodate
   470   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)
   471   refers to a specific induction rule, with parameters named according
   472   to the user-specified equations.  Case names of \mbox{\isa{\isacommand{primrec}}} are that of the datatypes involved, while those of
   473   \mbox{\isa{\isacommand{function}}} are numbered (starting from 1).
   474 
   475   The equations provided by these packages may be referred later as
   476   theorem list \isa{{\isachardoublequote}f{\isachardot}simps{\isachardoublequote}}, where \isa{f} is the (collective)
   477   name of the functions defined.  Individual equations may be named
   478   explicitly as well.
   479 
   480   The \mbox{\isa{\isacommand{function}}} command accepts the following
   481   options.
   482 
   483   \begin{descr}
   484 
   485   \item [\isa{sequential}] enables a preprocessor which
   486   disambiguates overlapping patterns by making them mutually disjoint.
   487   Earlier equations take precedence over later ones.  This allows to
   488   give the specification in a format very similar to functional
   489   programming.  Note that the resulting simplification and induction
   490   rules correspond to the transformed specification, not the one given
   491   originally. This usually means that each equation given by the user
   492   may result in several theroems.  Also note that this automatic
   493   transformation only works for ML-style datatype patterns.
   494 
   495   \item [\isa{{\isachardoublequote}{\isasymIN}\ name{\isachardoublequote}}] gives the target for the definition.
   496   %FIXME ?!?
   497 
   498   \item [\isa{domintros}] enables the automated generation of
   499   introduction rules for the domain predicate. While mostly not
   500   needed, they can be helpful in some proofs about partial functions.
   501 
   502   \item [\isa{tailrec}] generates the unconstrained recursive
   503   equations even without a termination proof, provided that the
   504   function is tail-recursive. This currently only works
   505 
   506   \item [\isa{{\isachardoublequote}default\ d{\isachardoublequote}}] allows to specify a default value for a
   507   (partial) function, which will ensure that \isa{{\isachardoublequote}f\ x\ {\isacharequal}\ d\ x{\isachardoublequote}}
   508   whenever \isa{{\isachardoublequote}x\ {\isasymnotin}\ f{\isacharunderscore}dom{\isachardoublequote}}.
   509 
   510   \end{descr}%
   511 \end{isamarkuptext}%
   512 \isamarkuptrue%
   513 %
   514 \isamarkupsubsection{Proof methods related to recursive definitions%
   515 }
   516 \isamarkuptrue%
   517 %
   518 \begin{isamarkuptext}%
   519 \begin{matharray}{rcl}
   520     \indexdef{HOL}{method}{pat\_completeness}\mbox{\isa{pat{\isacharunderscore}completeness}} & : & \isarmeth \\
   521     \indexdef{HOL}{method}{relation}\mbox{\isa{relation}} & : & \isarmeth \\
   522     \indexdef{HOL}{method}{lexicographic\_order}\mbox{\isa{lexicographic{\isacharunderscore}order}} & : & \isarmeth \\
   523   \end{matharray}
   524 
   525   \begin{rail}
   526     'relation' term
   527     ;
   528     'lexicographic\_order' (clasimpmod *)
   529     ;
   530   \end{rail}
   531 
   532   \begin{descr}
   533 
   534   \item [\mbox{\isa{pat{\isacharunderscore}completeness}}] is a specialized method to
   535   solve goals regarding the completeness of pattern matching, as
   536   required by the \mbox{\isa{\isacommand{function}}} package (cf.\
   537   \cite{isabelle-function}).
   538 
   539   \item [\mbox{\isa{relation}}~\isa{R}] introduces a termination
   540   proof using the relation \isa{R}.  The resulting proof state will
   541   contain goals expressing that \isa{R} is wellfounded, and that the
   542   arguments of recursive calls decrease with respect to \isa{R}.
   543   Usually, this method is used as the initial proof step of manual
   544   termination proofs.
   545 
   546   \item [\mbox{\isa{lexicographic{\isacharunderscore}order}}] attempts a fully
   547   automated termination proof by searching for a lexicographic
   548   combination of size measures on the arguments of the function. The
   549   method accepts the same arguments as the \mbox{\isa{auto}} method,
   550   which it uses internally to prove local descents.  The same context
   551   modifiers as for \mbox{\isa{auto}} are accepted, see
   552   \secref{sec:clasimp}.
   553 
   554   In case of failure, extensive information is printed, which can help
   555   to analyse the situation (cf.\ \cite{isabelle-function}).
   556 
   557   \end{descr}%
   558 \end{isamarkuptext}%
   559 \isamarkuptrue%
   560 %
   561 \isamarkupsubsection{Old-style recursive function definitions (TFL)%
   562 }
   563 \isamarkuptrue%
   564 %
   565 \begin{isamarkuptext}%
   566 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.
   567 
   568   \begin{matharray}{rcl}
   569     \indexdef{HOL}{command}{recdef}\mbox{\isa{\isacommand{recdef}}} & : & \isartrans{theory}{theory} \\
   570     \indexdef{HOL}{command}{recdef\_tc}\mbox{\isa{\isacommand{recdef{\isacharunderscore}tc}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isartrans{theory}{proof(prove)} \\
   571   \end{matharray}
   572 
   573   \begin{rail}
   574     'recdef' ('(' 'permissive' ')')? \\ name term (prop +) hints?
   575     ;
   576     recdeftc thmdecl? tc
   577     ;
   578     hints: '(' 'hints' (recdefmod *) ')'
   579     ;
   580     recdefmod: (('recdef\_simp' | 'recdef\_cong' | 'recdef\_wf') (() | 'add' | 'del') ':' thmrefs) | clasimpmod
   581     ;
   582     tc: nameref ('(' nat ')')?
   583     ;
   584   \end{rail}
   585 
   586   \begin{descr}
   587   
   588   \item [\mbox{\isa{\isacommand{recdef}}}] defines general well-founded
   589   recursive functions (using the TFL package), see also
   590   \cite{isabelle-HOL}.  The ``\isa{{\isachardoublequote}{\isacharparenleft}permissive{\isacharparenright}{\isachardoublequote}}'' option tells
   591   TFL to recover from failed proof attempts, returning unfinished
   592   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
   593   automated proof process of TFL.  Additional \mbox{\isa{clasimpmod}}
   594   declarations (cf.\ \secref{sec:clasimp}) may be given to tune the
   595   context of the Simplifier (cf.\ \secref{sec:simplifier}) and
   596   Classical reasoner (cf.\ \secref{sec:classical}).
   597   
   598   \item [\mbox{\isa{\isacommand{recdef{\isacharunderscore}tc}}}~\isa{{\isachardoublequote}c\ {\isacharparenleft}i{\isacharparenright}{\isachardoublequote}}] recommences the
   599   proof for leftover termination condition number \isa{i} (default
   600   1) as generated by a \mbox{\isa{\isacommand{recdef}}} definition of
   601   constant \isa{c}.
   602   
   603   Note that in most cases, \mbox{\isa{\isacommand{recdef}}} is able to finish
   604   its internal proofs without manual intervention.
   605 
   606   \end{descr}
   607 
   608   \medskip Hints for \mbox{\isa{\isacommand{recdef}}} may be also declared
   609   globally, using the following attributes.
   610 
   611   \begin{matharray}{rcl}
   612     \indexdef{HOL}{attribute}{recdef\_simp}\mbox{\isa{recdef{\isacharunderscore}simp}} & : & \isaratt \\
   613     \indexdef{HOL}{attribute}{recdef\_cong}\mbox{\isa{recdef{\isacharunderscore}cong}} & : & \isaratt \\
   614     \indexdef{HOL}{attribute}{recdef\_wf}\mbox{\isa{recdef{\isacharunderscore}wf}} & : & \isaratt \\
   615   \end{matharray}
   616 
   617   \begin{rail}
   618     ('recdef\_simp' | 'recdef\_cong' | 'recdef\_wf') (() | 'add' | 'del')
   619     ;
   620   \end{rail}%
   621 \end{isamarkuptext}%
   622 \isamarkuptrue%
   623 %
   624 \isamarkupsection{Definition by specification \label{sec:hol-specification}%
   625 }
   626 \isamarkuptrue%
   627 %
   628 \begin{isamarkuptext}%
   629 \begin{matharray}{rcl}
   630     \indexdef{HOL}{command}{specification}\mbox{\isa{\isacommand{specification}}} & : & \isartrans{theory}{proof(prove)} \\
   631     \indexdef{HOL}{command}{ax\_specification}\mbox{\isa{\isacommand{ax{\isacharunderscore}specification}}} & : & \isartrans{theory}{proof(prove)} \\
   632   \end{matharray}
   633 
   634   \begin{rail}
   635   ('specification' | 'ax\_specification') '(' (decl +) ')' \\ (thmdecl? prop +)
   636   ;
   637   decl: ((name ':')? term '(' 'overloaded' ')'?)
   638   \end{rail}
   639 
   640   \begin{descr}
   641 
   642   \item [\mbox{\isa{\isacommand{specification}}}~\isa{{\isachardoublequote}decls\ {\isasymphi}{\isachardoublequote}}] sets up a
   643   goal stating the existence of terms with the properties specified to
   644   hold for the constants given in \isa{decls}.  After finishing the
   645   proof, the theory will be augmented with definitions for the given
   646   constants, as well as with theorems stating the properties for these
   647   constants.
   648 
   649   \item [\mbox{\isa{\isacommand{ax{\isacharunderscore}specification}}}~\isa{{\isachardoublequote}decls\ {\isasymphi}{\isachardoublequote}}] sets
   650   up a goal stating the existence of terms with the properties
   651   specified to hold for the constants given in \isa{decls}.  After
   652   finishing the proof, the theory will be augmented with axioms
   653   expressing the properties given in the first place.
   654 
   655   \item [\isa{decl}] declares a constant to be defined by the
   656   specification given.  The definition for the constant \isa{c} is
   657   bound to the name \isa{c{\isacharunderscore}def} unless a theorem name is given in
   658   the declaration.  Overloaded constants should be declared as such.
   659 
   660   \end{descr}
   661 
   662   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
   663   construction cannot introduce inconsistencies, whereas \mbox{\isa{\isacommand{ax{\isacharunderscore}specification}}} does introduce axioms, but only after the
   664   user has explicitly proven it to be safe.  A practical issue must be
   665   considered, though: After introducing two constants with the same
   666   properties using \mbox{\isa{\isacommand{specification}}}, one can prove
   667   that the two constants are, in fact, equal.  If this might be a
   668   problem, one should use \mbox{\isa{\isacommand{ax{\isacharunderscore}specification}}}.%
   669 \end{isamarkuptext}%
   670 \isamarkuptrue%
   671 %
   672 \isamarkupsection{Inductive and coinductive definitions \label{sec:hol-inductive}%
   673 }
   674 \isamarkuptrue%
   675 %
   676 \begin{isamarkuptext}%
   677 An \textbf{inductive definition} specifies the least predicate (or
   678   set) \isa{R} closed under given rules: applying a rule to elements
   679   of \isa{R} yields a result within \isa{R}.  For example, a
   680   structural operational semantics is an inductive definition of an
   681   evaluation relation.
   682 
   683   Dually, a \textbf{coinductive definition} specifies the greatest
   684   predicate~/ set \isa{R} that is consistent with given rules: every
   685   element of \isa{R} can be seen as arising by applying a rule to
   686   elements of \isa{R}.  An important example is using bisimulation
   687   relations to formalise equivalence of processes and infinite data
   688   structures.
   689 
   690   \medskip The HOL package is related to the ZF one, which is
   691   described in a separate paper,\footnote{It appeared in CADE
   692   \cite{paulson-CADE}; a longer version is distributed with Isabelle.}
   693   which you should refer to in case of difficulties.  The package is
   694   simpler than that of ZF thanks to implicit type-checking in HOL.
   695   The types of the (co)inductive predicates (or sets) determine the
   696   domain of the fixedpoint definition, and the package does not have
   697   to use inference rules for type-checking.
   698 
   699   \begin{matharray}{rcl}
   700     \indexdef{HOL}{command}{inductive}\mbox{\isa{\isacommand{inductive}}} & : & \isarkeep{local{\dsh}theory} \\
   701     \indexdef{HOL}{command}{inductive\_set}\mbox{\isa{\isacommand{inductive{\isacharunderscore}set}}} & : & \isarkeep{local{\dsh}theory} \\
   702     \indexdef{HOL}{command}{coinductive}\mbox{\isa{\isacommand{coinductive}}} & : & \isarkeep{local{\dsh}theory} \\
   703     \indexdef{HOL}{command}{coinductive\_set}\mbox{\isa{\isacommand{coinductive{\isacharunderscore}set}}} & : & \isarkeep{local{\dsh}theory} \\
   704     \indexdef{HOL}{attribute}{mono}\mbox{\isa{mono}} & : & \isaratt \\
   705   \end{matharray}
   706 
   707   \begin{rail}
   708     ('inductive' | 'inductive\_set' | 'coinductive' | 'coinductive\_set') target? fixes ('for' fixes)? \\
   709     ('where' clauses)? ('monos' thmrefs)?
   710     ;
   711     clauses: (thmdecl? prop + '|')
   712     ;
   713     'mono' (() | 'add' | 'del')
   714     ;
   715   \end{rail}
   716 
   717   \begin{descr}
   718 
   719   \item [\mbox{\isa{\isacommand{inductive}}} and \mbox{\isa{\isacommand{coinductive}}}] define (co)inductive predicates from the
   720   introduction rules given in the \mbox{\isa{\isakeyword{where}}} part.  The
   721   optional \mbox{\isa{\isakeyword{for}}} part contains a list of parameters of the
   722   (co)inductive predicates that remain fixed throughout the
   723   definition.  The optional \mbox{\isa{\isakeyword{monos}}} section contains
   724   \emph{monotonicity theorems}, which are required for each operator
   725   applied to a recursive set in the introduction rules.  There
   726   \emph{must} be a theorem of the form \isa{{\isachardoublequote}A\ {\isasymle}\ B\ {\isasymLongrightarrow}\ M\ A\ {\isasymle}\ M\ B{\isachardoublequote}},
   727   for each premise \isa{{\isachardoublequote}M\ R\isactrlsub i\ t{\isachardoublequote}} in an introduction rule!
   728 
   729   \item [\mbox{\isa{\isacommand{inductive{\isacharunderscore}set}}} and \mbox{\isa{\isacommand{coinductive{\isacharunderscore}set}}}] are wrappers for to the previous commands,
   730   allowing the definition of (co)inductive sets.
   731 
   732   \item [\mbox{\isa{mono}}] declares monotonicity rules.  These
   733   rule are involved in the automated monotonicity proof of \mbox{\isa{\isacommand{inductive}}}.
   734 
   735   \end{descr}%
   736 \end{isamarkuptext}%
   737 \isamarkuptrue%
   738 %
   739 \isamarkupsubsection{Derived rules%
   740 }
   741 \isamarkuptrue%
   742 %
   743 \begin{isamarkuptext}%
   744 Each (co)inductive definition \isa{R} adds definitions to the
   745   theory and also proves some theorems:
   746 
   747   \begin{description}
   748 
   749   \item [\isa{R{\isachardot}intros}] is the list of introduction rules as proven
   750   theorems, for the recursive predicates (or sets).  The rules are
   751   also available individually, using the names given them in the
   752   theory file;
   753 
   754   \item [\isa{R{\isachardot}cases}] is the case analysis (or elimination) rule;
   755 
   756   \item [\isa{R{\isachardot}induct} or \isa{R{\isachardot}coinduct}] is the (co)induction
   757   rule.
   758 
   759   \end{description}
   760 
   761   When several predicates \isa{{\isachardoublequote}R\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ R\isactrlsub n{\isachardoublequote}} are
   762   defined simultaneously, the list of introduction rules is called
   763   \isa{{\isachardoublequote}R\isactrlsub {\isadigit{1}}{\isacharunderscore}{\isasymdots}{\isacharunderscore}R\isactrlsub n{\isachardot}intros{\isachardoublequote}}, the case analysis rules are
   764   called \isa{{\isachardoublequote}R\isactrlsub {\isadigit{1}}{\isachardot}cases{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ R\isactrlsub n{\isachardot}cases{\isachardoublequote}}, and the list
   765   of mutual induction rules is called \isa{{\isachardoublequote}R\isactrlsub {\isadigit{1}}{\isacharunderscore}{\isasymdots}{\isacharunderscore}R\isactrlsub n{\isachardot}inducts{\isachardoublequote}}.%
   766 \end{isamarkuptext}%
   767 \isamarkuptrue%
   768 %
   769 \isamarkupsubsection{Monotonicity theorems%
   770 }
   771 \isamarkuptrue%
   772 %
   773 \begin{isamarkuptext}%
   774 Each theory contains a default set of theorems that are used in
   775   monotonicity proofs.  New rules can be added to this set via the
   776   \mbox{\isa{mono}} attribute.  The HOL theory \isa{Inductive}
   777   shows how this is done.  In general, the following monotonicity
   778   theorems may be added:
   779 
   780   \begin{itemize}
   781 
   782   \item Theorems of the form \isa{{\isachardoublequote}A\ {\isasymle}\ B\ {\isasymLongrightarrow}\ M\ A\ {\isasymle}\ M\ B{\isachardoublequote}}, for proving
   783   monotonicity of inductive definitions whose introduction rules have
   784   premises involving terms such as \isa{{\isachardoublequote}M\ R\isactrlsub i\ t{\isachardoublequote}}.
   785 
   786   \item Monotonicity theorems for logical operators, which are of the
   787   general form \isa{{\isachardoublequote}{\isacharparenleft}{\isasymdots}\ {\isasymlongrightarrow}\ {\isasymdots}{\isacharparenright}\ {\isasymLongrightarrow}\ {\isasymdots}\ {\isacharparenleft}{\isasymdots}\ {\isasymlongrightarrow}\ {\isasymdots}{\isacharparenright}\ {\isasymLongrightarrow}\ {\isasymdots}\ {\isasymlongrightarrow}\ {\isasymdots}{\isachardoublequote}}.  For example, in
   788   the case of the operator \isa{{\isachardoublequote}{\isasymor}{\isachardoublequote}}, the corresponding theorem is
   789   \[
   790   \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}}}
   791   \]
   792 
   793   \item De Morgan style equations for reasoning about the ``polarity''
   794   of expressions, e.g.
   795   \[
   796   \isa{{\isachardoublequote}{\isasymnot}\ {\isasymnot}\ P\ {\isasymlongleftrightarrow}\ P{\isachardoublequote}} \qquad\qquad
   797   \isa{{\isachardoublequote}{\isasymnot}\ {\isacharparenleft}P\ {\isasymand}\ Q{\isacharparenright}\ {\isasymlongleftrightarrow}\ {\isasymnot}\ P\ {\isasymor}\ {\isasymnot}\ Q{\isachardoublequote}}
   798   \]
   799 
   800   \item Equations for reducing complex operators to more primitive
   801   ones whose monotonicity can easily be proved, e.g.
   802   \[
   803   \isa{{\isachardoublequote}{\isacharparenleft}P\ {\isasymlongrightarrow}\ Q{\isacharparenright}\ {\isasymlongleftrightarrow}\ {\isasymnot}\ P\ {\isasymor}\ Q{\isachardoublequote}} \qquad\qquad
   804   \isa{{\isachardoublequote}Ball\ A\ P\ {\isasymequiv}\ {\isasymforall}x{\isachardot}\ x\ {\isasymin}\ A\ {\isasymlongrightarrow}\ P\ x{\isachardoublequote}}
   805   \]
   806 
   807   \end{itemize}
   808 
   809   %FIXME: Example of an inductive definition%
   810 \end{isamarkuptext}%
   811 \isamarkuptrue%
   812 %
   813 \isamarkupsection{Arithmetic proof support%
   814 }
   815 \isamarkuptrue%
   816 %
   817 \begin{isamarkuptext}%
   818 \begin{matharray}{rcl}
   819     \indexdef{HOL}{method}{arith}\mbox{\isa{arith}} & : & \isarmeth \\
   820     \indexdef{HOL}{method}{arith\_split}\mbox{\isa{arith{\isacharunderscore}split}} & : & \isaratt \\
   821   \end{matharray}
   822 
   823   The \mbox{\isa{arith}} method decides linear arithmetic problems
   824   (on types \isa{nat}, \isa{int}, \isa{real}).  Any current
   825   facts are inserted into the goal before running the procedure.
   826 
   827   The \mbox{\isa{arith{\isacharunderscore}split}} attribute declares case split rules
   828   to be expanded before the arithmetic procedure is invoked.
   829 
   830   Note that a simpler (but faster) version of arithmetic reasoning is
   831   already performed by the Simplifier.%
   832 \end{isamarkuptext}%
   833 \isamarkuptrue%
   834 %
   835 \isamarkupsection{Cases and induction: emulating tactic scripts \label{sec:hol-induct-tac}%
   836 }
   837 \isamarkuptrue%
   838 %
   839 \begin{isamarkuptext}%
   840 The following important tactical tools of Isabelle/HOL have been
   841   ported to Isar.  These should be never used in proper proof texts!
   842 
   843   \begin{matharray}{rcl}
   844     \indexdef{HOL}{method}{case\_tac}\mbox{\isa{case{\isacharunderscore}tac}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarmeth \\
   845     \indexdef{HOL}{method}{induct\_tac}\mbox{\isa{induct{\isacharunderscore}tac}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarmeth \\
   846     \indexdef{HOL}{method}{ind\_cases}\mbox{\isa{ind{\isacharunderscore}cases}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarmeth \\
   847     \indexdef{HOL}{command}{inductive\_cases}\mbox{\isa{\isacommand{inductive{\isacharunderscore}cases}}} & : & \isartrans{theory}{theory} \\
   848   \end{matharray}
   849 
   850   \begin{rail}
   851     'case\_tac' goalspec? term rule?
   852     ;
   853     'induct\_tac' goalspec? (insts * 'and') rule?
   854     ;
   855     'ind\_cases' (prop +) ('for' (name +)) ?
   856     ;
   857     'inductive\_cases' (thmdecl? (prop +) + 'and')
   858     ;
   859 
   860     rule: ('rule' ':' thmref)
   861     ;
   862   \end{rail}
   863 
   864   \begin{descr}
   865 
   866   \item [\mbox{\isa{case{\isacharunderscore}tac}} and \mbox{\isa{induct{\isacharunderscore}tac}}]
   867   admit to reason about inductive datatypes only (unless an
   868   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.
   869   These tactic emulations feature both goal addressing and dynamic
   870   instantiation.  Note that named rule cases are \emph{not} provided
   871   as would be by the proper \mbox{\isa{induct}} and \mbox{\isa{cases}} proof
   872   methods (see \secref{sec:cases-induct}).
   873   
   874   \item [\mbox{\isa{ind{\isacharunderscore}cases}} and \mbox{\isa{\isacommand{inductive{\isacharunderscore}cases}}}] provide an interface to the internal \verb|mk_cases| operation.  Rules are simplified in an unrestricted
   875   forward manner.
   876 
   877   While \mbox{\isa{ind{\isacharunderscore}cases}} is a proof method to apply the
   878   result immediately as elimination rules, \mbox{\isa{\isacommand{inductive{\isacharunderscore}cases}}} provides case split theorems at the theory level
   879   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
   880   be generalized before applying the resulting rule.
   881 
   882   \end{descr}%
   883 \end{isamarkuptext}%
   884 \isamarkuptrue%
   885 %
   886 \isamarkupsection{Executable code%
   887 }
   888 \isamarkuptrue%
   889 %
   890 \begin{isamarkuptext}%
   891 Isabelle/Pure provides two generic frameworks to support code
   892   generation from executable specifications.  Isabelle/HOL
   893   instantiates these mechanisms in a way that is amenable to end-user
   894   applications.
   895 
   896   One framework generates code from both functional and relational
   897   programs to SML.  See \cite{isabelle-HOL} for further information
   898   (this actually covers the new-style theory format as well).
   899 
   900   \begin{matharray}{rcl}
   901     \indexdef{HOL}{command}{value}\mbox{\isa{\isacommand{value}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarkeep{theory~|~proof} \\
   902     \indexdef{HOL}{command}{code\_module}\mbox{\isa{\isacommand{code{\isacharunderscore}module}}} & : & \isartrans{theory}{theory} \\
   903     \indexdef{HOL}{command}{code\_library}\mbox{\isa{\isacommand{code{\isacharunderscore}library}}} & : & \isartrans{theory}{theory} \\
   904     \indexdef{HOL}{command}{consts\_code}\mbox{\isa{\isacommand{consts{\isacharunderscore}code}}} & : & \isartrans{theory}{theory} \\
   905     \indexdef{HOL}{command}{types\_code}\mbox{\isa{\isacommand{types{\isacharunderscore}code}}} & : & \isartrans{theory}{theory} \\  
   906     \indexdef{HOL}{attribute}{code}\mbox{\isa{code}} & : & \isaratt \\
   907   \end{matharray}
   908 
   909   \begin{rail}
   910   'value' term
   911   ;
   912 
   913   ( 'code\_module' | 'code\_library' ) modespec ? name ? \\
   914     ( 'file' name ) ? ( 'imports' ( name + ) ) ? \\
   915     'contains' ( ( name '=' term ) + | term + )
   916   ;
   917 
   918   modespec: '(' ( name * ) ')'
   919   ;
   920 
   921   'consts\_code' (codespec +)
   922   ;
   923 
   924   codespec: const template attachment ?
   925   ;
   926 
   927   'types\_code' (tycodespec +)
   928   ;
   929 
   930   tycodespec: name template attachment ?
   931   ;
   932 
   933   const: term
   934   ;
   935 
   936   template: '(' string ')'
   937   ;
   938 
   939   attachment: 'attach' modespec ? verblbrace text verbrbrace
   940   ;
   941 
   942   'code' (name)?
   943   ;
   944   \end{rail}
   945 
   946   \begin{descr}
   947 
   948   \item [\mbox{\isa{\isacommand{value}}}~\isa{t}] evaluates and prints a
   949   term using the code generator.
   950 
   951   \end{descr}
   952 
   953   \medskip The other framework generates code from functional programs
   954   (including overloading using type classes) to SML \cite{SML}, OCaml
   955   \cite{OCaml} and Haskell \cite{haskell-revised-report}.
   956   Conceptually, code generation is split up in three steps:
   957   \emph{selection} of code theorems, \emph{translation} into an
   958   abstract executable view and \emph{serialization} to a specific
   959   \emph{target language}.  See \cite{isabelle-codegen} for an
   960   introduction on how to use it.
   961 
   962   \begin{matharray}{rcl}
   963     \indexdef{HOL}{command}{export\_code}\mbox{\isa{\isacommand{export{\isacharunderscore}code}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarkeep{theory~|~proof} \\
   964     \indexdef{HOL}{command}{code\_thms}\mbox{\isa{\isacommand{code{\isacharunderscore}thms}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarkeep{theory~|~proof} \\
   965     \indexdef{HOL}{command}{code\_deps}\mbox{\isa{\isacommand{code{\isacharunderscore}deps}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarkeep{theory~|~proof} \\
   966     \indexdef{HOL}{command}{code\_datatype}\mbox{\isa{\isacommand{code{\isacharunderscore}datatype}}} & : & \isartrans{theory}{theory} \\
   967     \indexdef{HOL}{command}{code\_const}\mbox{\isa{\isacommand{code{\isacharunderscore}const}}} & : & \isartrans{theory}{theory} \\
   968     \indexdef{HOL}{command}{code\_type}\mbox{\isa{\isacommand{code{\isacharunderscore}type}}} & : & \isartrans{theory}{theory} \\
   969     \indexdef{HOL}{command}{code\_class}\mbox{\isa{\isacommand{code{\isacharunderscore}class}}} & : & \isartrans{theory}{theory} \\
   970     \indexdef{HOL}{command}{code\_instance}\mbox{\isa{\isacommand{code{\isacharunderscore}instance}}} & : & \isartrans{theory}{theory} \\
   971     \indexdef{HOL}{command}{code\_monad}\mbox{\isa{\isacommand{code{\isacharunderscore}monad}}} & : & \isartrans{theory}{theory} \\
   972     \indexdef{HOL}{command}{code\_reserved}\mbox{\isa{\isacommand{code{\isacharunderscore}reserved}}} & : & \isartrans{theory}{theory} \\
   973     \indexdef{HOL}{command}{code\_include}\mbox{\isa{\isacommand{code{\isacharunderscore}include}}} & : & \isartrans{theory}{theory} \\
   974     \indexdef{HOL}{command}{code\_modulename}\mbox{\isa{\isacommand{code{\isacharunderscore}modulename}}} & : & \isartrans{theory}{theory} \\
   975     \indexdef{HOL}{command}{code\_exception}\mbox{\isa{\isacommand{code{\isacharunderscore}exception}}} & : & \isartrans{theory}{theory} \\
   976     \indexdef{HOL}{command}{print\_codesetup}\mbox{\isa{\isacommand{print{\isacharunderscore}codesetup}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isarkeep{theory~|~proof} \\
   977     \indexdef{HOL}{attribute}{code}\mbox{\isa{code}} & : & \isaratt \\
   978   \end{matharray}
   979 
   980   \begin{rail}
   981     'export\_code' ( constexpr + ) ? \\
   982       ( ( 'in' target ( 'module\_name' string ) ? \\
   983         ( 'file' ( string | '-' ) ) ? ( '(' args ')' ) ?) + ) ?
   984     ;
   985 
   986     'code\_thms' ( constexpr + ) ?
   987     ;
   988 
   989     'code\_deps' ( constexpr + ) ?
   990     ;
   991 
   992     const: term
   993     ;
   994 
   995     constexpr: ( const | 'name.*' | '*' )
   996     ;
   997 
   998     typeconstructor: nameref
   999     ;
  1000 
  1001     class: nameref
  1002     ;
  1003 
  1004     target: 'OCaml' | 'SML' | 'Haskell'
  1005     ;
  1006 
  1007     'code\_datatype' const +
  1008     ;
  1009 
  1010     'code\_const' (const + 'and') \\
  1011       ( ( '(' target ( syntax ? + 'and' ) ')' ) + )
  1012     ;
  1013 
  1014     'code\_type' (typeconstructor + 'and') \\
  1015       ( ( '(' target ( syntax ? + 'and' ) ')' ) + )
  1016     ;
  1017 
  1018     'code\_class' (class + 'and') \\
  1019       ( ( '(' target \\
  1020         ( ( string ('where' \\
  1021           ( const ( '==' | equiv ) string ) + ) ? ) ? + 'and' ) ')' ) + )
  1022     ;
  1023 
  1024     'code\_instance' (( typeconstructor '::' class ) + 'and') \\
  1025       ( ( '(' target ( '-' ? + 'and' ) ')' ) + )
  1026     ;
  1027 
  1028     'code\_monad' const const target
  1029     ;
  1030 
  1031     'code\_reserved' target ( string + )
  1032     ;
  1033 
  1034     'code\_include' target ( string ( string | '-') )
  1035     ;
  1036 
  1037     'code\_modulename' target ( ( string string ) + )
  1038     ;
  1039 
  1040     'code\_exception' ( const + )
  1041     ;
  1042 
  1043     syntax: string | ( 'infix' | 'infixl' | 'infixr' ) nat string
  1044     ;
  1045 
  1046     'code' ('func' | 'inline') ( 'del' )?
  1047     ;
  1048   \end{rail}
  1049 
  1050   \begin{descr}
  1051 
  1052   \item [\mbox{\isa{\isacommand{export{\isacharunderscore}code}}}] is the canonical interface
  1053   for generating and serializing code: for a given list of constants,
  1054   code is generated for the specified target languages.  Abstract code
  1055   is cached incrementally.  If no constant is given, the currently
  1056   cached code is serialized.  If no serialization instruction is
  1057   given, only abstract code is cached.
  1058 
  1059   Constants may be specified by giving them literally, referring to
  1060   all executable contants within a certain theory by giving \isa{{\isachardoublequote}name{\isachardot}{\isacharasterisk}{\isachardoublequote}}, or referring to \emph{all} executable constants currently
  1061   available by giving \isa{{\isachardoublequote}{\isacharasterisk}{\isachardoublequote}}.
  1062 
  1063   By default, for each involved theory one corresponding name space
  1064   module is generated.  Alternativly, a module name may be specified
  1065   after the \mbox{\isa{\isakeyword{module{\isacharunderscore}name}}} keyword; then \emph{all} code is
  1066   placed in this module.
  1067 
  1068   For \emph{SML} and \emph{OCaml}, the file specification refers to a
  1069   single file; for \emph{Haskell}, it refers to a whole directory,
  1070   where code is generated in multiple files reflecting the module
  1071   hierarchy.  The file specification ``\isa{{\isachardoublequote}{\isacharminus}{\isachardoublequote}}'' denotes standard
  1072   output.  For \emph{SML}, omitting the file specification compiles
  1073   code internally in the context of the current ML session.
  1074 
  1075   Serializers take an optional list of arguments in parentheses.  For
  1076   \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
  1077   declaration.
  1078 
  1079   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}thms}}}] prints a list of theorems
  1080   representing the corresponding program containing all given
  1081   constants; if no constants are given, the currently cached code
  1082   theorems are printed.
  1083 
  1084   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}deps}}}] visualizes dependencies of
  1085   theorems representing the corresponding program containing all given
  1086   constants; if no constants are given, the currently cached code
  1087   theorems are visualized.
  1088 
  1089   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}datatype}}}] specifies a constructor set
  1090   for a logical type.
  1091 
  1092   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}const}}}] associates a list of constants
  1093   with target-specific serializations; omitting a serialization
  1094   deletes an existing serialization.
  1095 
  1096   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}type}}}] associates a list of type
  1097   constructors with target-specific serializations; omitting a
  1098   serialization deletes an existing serialization.
  1099 
  1100   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}class}}}] associates a list of classes
  1101   with target-specific class names; in addition, constants associated
  1102   with this class may be given target-specific names used for instance
  1103   declarations; omitting a serialization deletes an existing
  1104   serialization.  This applies only to \emph{Haskell}.
  1105 
  1106   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}instance}}}] declares a list of type
  1107   constructor / class instance relations as ``already present'' for a
  1108   given target.  Omitting a ``\isa{{\isachardoublequote}{\isacharminus}{\isachardoublequote}}'' deletes an existing
  1109   ``already present'' declaration.  This applies only to
  1110   \emph{Haskell}.
  1111 
  1112   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}monad}}}] provides an auxiliary
  1113   mechanism to generate monadic code.
  1114 
  1115   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}reserved}}}] declares a list of names as
  1116   reserved for a given target, preventing it to be shadowed by any
  1117   generated code.
  1118 
  1119   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}include}}}] adds arbitrary named content
  1120   (``include'') to generated code.  A as last argument ``\isa{{\isachardoublequote}{\isacharminus}{\isachardoublequote}}''
  1121   will remove an already added ``include''.
  1122 
  1123   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}modulename}}}] declares aliasings from
  1124   one module name onto another.
  1125 
  1126   \item [\mbox{\isa{\isacommand{code{\isacharunderscore}exception}}}] declares constants which
  1127   are not required to have a definition by a defining equations; these
  1128   are mapped on exceptions instead.
  1129 
  1130   \item [\mbox{\isa{code}}~\isa{func}] explicitly selects (or
  1131   with option ``\isa{{\isachardoublequote}del{\isacharcolon}{\isachardoublequote}}'' deselects) a defining equation for
  1132   code generation.  Usually packages introducing defining equations
  1133   provide a resonable default setup for selection.
  1134 
  1135   \item [\mbox{\isa{code}}\isa{inline}] declares (or with
  1136   option ``\isa{{\isachardoublequote}del{\isacharcolon}{\isachardoublequote}}'' removes) inlining theorems which are
  1137   applied as rewrite rules to any defining equation during
  1138   preprocessing.
  1139 
  1140   \item [\mbox{\isa{\isacommand{print{\isacharunderscore}codesetup}}}] gives an overview on
  1141   selected defining equations, code generator datatypes and
  1142   preprocessor setup.
  1143 
  1144   \end{descr}%
  1145 \end{isamarkuptext}%
  1146 \isamarkuptrue%
  1147 %
  1148 \isadelimtheory
  1149 %
  1150 \endisadelimtheory
  1151 %
  1152 \isatagtheory
  1153 \isacommand{end}\isamarkupfalse%
  1154 %
  1155 \endisatagtheory
  1156 {\isafoldtheory}%
  1157 %
  1158 \isadelimtheory
  1159 %
  1160 \endisadelimtheory
  1161 \isanewline
  1162 \isanewline
  1163 \end{isabellebody}%
  1164 %%% Local Variables:
  1165 %%% mode: latex
  1166 %%% TeX-master: "root"
  1167 %%% End: