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