doc-src/Inductive/ind-defs.tex
author wenzelm
Fri, 23 May 1997 18:55:28 +0200
changeset 3322 bc4d107fb6dd
parent 3162 78fa85d44e68
child 4239 8c98484ef66f
permissions -rw-r--r--
tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3162
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
     1
\documentclass[12pt]{article}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
     2
\usepackage{a4,latexsym,proof}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
     3
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
     4
\makeatletter
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
     5
\input{../rail.sty}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
     6
\input{../iman.sty}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
     7
\input{../extra.sty}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
     8
\makeatother
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
     9
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    10
\newif\ifshort%''Short'' means a published version, not the documentation
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    11
\shortfalse%%%%%\shorttrue
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    12
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    13
\title{A Fixedpoint Approach to\\ 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    14
  (Co)Inductive and (Co)Datatype Definitions%
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    15
  \thanks{J. Grundy and S. Thompson made detailed comments.  Mads Tofte and
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    16
    the referees were also helpful.  The research was funded by the SERC
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    17
    grants GR/G53279, GR/H40570 and by the ESPRIT Project 6453 ``Types''.}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    18
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    19
\author{Lawrence C. Paulson\\{\tt lcp@cl.cam.ac.uk}\\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    20
        Computer Laboratory, University of Cambridge, England}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    21
\date{\today} 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    22
\setcounter{secnumdepth}{2} \setcounter{tocdepth}{2}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    23
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    24
\newcommand\sbs{\subseteq}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    25
\let\To=\Rightarrow
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    26
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    27
%\newcommand\emph[1]{{\em#1\/}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    28
\newcommand\defn[1]{{\bf#1}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    29
%\newcommand\textsc[1]{{\sc#1}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    30
%\newcommand\texttt[1]{{\tt#1}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    31
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    32
\newcommand\pow{{\cal P}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    33
%%%\let\pow=\wp
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    34
\newcommand\RepFun{\hbox{\tt RepFun}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    35
\newcommand\cons{\hbox{\tt cons}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    36
\def\succ{\hbox{\tt succ}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    37
\newcommand\split{\hbox{\tt split}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    38
\newcommand\fst{\hbox{\tt fst}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    39
\newcommand\snd{\hbox{\tt snd}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    40
\newcommand\converse{\hbox{\tt converse}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    41
\newcommand\domain{\hbox{\tt domain}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    42
\newcommand\range{\hbox{\tt range}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    43
\newcommand\field{\hbox{\tt field}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    44
\newcommand\lfp{\hbox{\tt lfp}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    45
\newcommand\gfp{\hbox{\tt gfp}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    46
\newcommand\id{\hbox{\tt id}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    47
\newcommand\trans{\hbox{\tt trans}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    48
\newcommand\wf{\hbox{\tt wf}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    49
\newcommand\nat{\hbox{\tt nat}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    50
\newcommand\rank{\hbox{\tt rank}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    51
\newcommand\univ{\hbox{\tt univ}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    52
\newcommand\Vrec{\hbox{\tt Vrec}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    53
\newcommand\Inl{\hbox{\tt Inl}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    54
\newcommand\Inr{\hbox{\tt Inr}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    55
\newcommand\case{\hbox{\tt case}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    56
\newcommand\lst{\hbox{\tt list}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    57
\newcommand\Nil{\hbox{\tt Nil}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    58
\newcommand\Cons{\hbox{\tt Cons}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    59
\newcommand\lstcase{\hbox{\tt list\_case}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    60
\newcommand\lstrec{\hbox{\tt list\_rec}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    61
\newcommand\length{\hbox{\tt length}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    62
\newcommand\listn{\hbox{\tt listn}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    63
\newcommand\acc{\hbox{\tt acc}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    64
\newcommand\primrec{\hbox{\tt primrec}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    65
\newcommand\SC{\hbox{\tt SC}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    66
\newcommand\CONST{\hbox{\tt CONST}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    67
\newcommand\PROJ{\hbox{\tt PROJ}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    68
\newcommand\COMP{\hbox{\tt COMP}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    69
\newcommand\PREC{\hbox{\tt PREC}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    70
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    71
\newcommand\quniv{\hbox{\tt quniv}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    72
\newcommand\llist{\hbox{\tt llist}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    73
\newcommand\LNil{\hbox{\tt LNil}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    74
\newcommand\LCons{\hbox{\tt LCons}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    75
\newcommand\lconst{\hbox{\tt lconst}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    76
\newcommand\lleq{\hbox{\tt lleq}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    77
\newcommand\map{\hbox{\tt map}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    78
\newcommand\term{\hbox{\tt term}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    79
\newcommand\Apply{\hbox{\tt Apply}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    80
\newcommand\termcase{\hbox{\tt term\_case}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    81
\newcommand\rev{\hbox{\tt rev}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    82
\newcommand\reflect{\hbox{\tt reflect}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    83
\newcommand\tree{\hbox{\tt tree}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    84
\newcommand\forest{\hbox{\tt forest}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    85
\newcommand\Part{\hbox{\tt Part}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    86
\newcommand\TF{\hbox{\tt tree\_forest}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    87
\newcommand\Tcons{\hbox{\tt Tcons}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    88
\newcommand\Fcons{\hbox{\tt Fcons}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    89
\newcommand\Fnil{\hbox{\tt Fnil}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    90
\newcommand\TFcase{\hbox{\tt TF\_case}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    91
\newcommand\Fin{\hbox{\tt Fin}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    92
\newcommand\QInl{\hbox{\tt QInl}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    93
\newcommand\QInr{\hbox{\tt QInr}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    94
\newcommand\qsplit{\hbox{\tt qsplit}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    95
\newcommand\qcase{\hbox{\tt qcase}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    96
\newcommand\Con{\hbox{\tt Con}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    97
\newcommand\data{\hbox{\tt data}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    98
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
    99
\binperiod     %%%treat . like a binary operator
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   100
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   101
\begin{document}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   102
\pagestyle{empty}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   103
\begin{titlepage}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   104
\maketitle 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   105
\begin{abstract}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   106
  This paper presents a fixedpoint approach to inductive definitions.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   107
  Instead of using a syntactic test such as ``strictly positive,'' the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   108
  approach lets definitions involve any operators that have been proved
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   109
  monotone.  It is conceptually simple, which has allowed the easy
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   110
  implementation of mutual recursion and iterated definitions.  It also
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   111
  handles coinductive definitions: simply replace the least fixedpoint by a
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   112
  greatest fixedpoint.  
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   113
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   114
  The method has been implemented in two of Isabelle's logics, \textsc{zf} set
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   115
  theory and higher-order logic.  It should be applicable to any logic in
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   116
  which the Knaster-Tarski theorem can be proved.  Examples include lists of
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   117
  $n$ elements, the accessible part of a relation and the set of primitive
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   118
  recursive functions.  One example of a coinductive definition is
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   119
  bisimulations for lazy lists.  Recursive datatypes are examined in detail,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   120
  as well as one example of a \defn{codatatype}: lazy lists.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   121
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   122
  The Isabelle package has been applied in several large case studies,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   123
  including two proofs of the Church-Rosser theorem and a coinductive proof of
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   124
  semantic consistency.  The package can be trusted because it proves theorems
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   125
  from definitions, instead of asserting desired properties as axioms.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   126
\end{abstract}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   127
%
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   128
\bigskip
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   129
\centerline{Copyright \copyright{} \number\year{} by Lawrence C. Paulson}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   130
\thispagestyle{empty} 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   131
\end{titlepage}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   132
\tableofcontents\cleardoublepage\pagestyle{plain}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   133
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   134
\setcounter{page}{1}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   135
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   136
\section{Introduction}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   137
Several theorem provers provide commands for formalizing recursive data
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   138
structures, like lists and trees.  Robin Milner implemented one of the first
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   139
of these, for Edinburgh \textsc{lcf}~\cite{milner-ind}.  Given a description
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   140
of the desired data structure, Milner's package formulated appropriate
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   141
definitions and proved the characteristic theorems.  Similar is Melham's
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   142
recursive type package for the Cambridge \textsc{hol} system~\cite{melham89}.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   143
Such data structures are called \defn{datatypes}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   144
below, by analogy with datatype declarations in Standard~\textsc{ml}\@.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   145
Some logics take datatypes as primitive; consider Boyer and Moore's shell
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   146
principle~\cite{bm79} and the Coq type theory~\cite{paulin-tlca}.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   147
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   148
A datatype is but one example of an \defn{inductive definition}.  Such a
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   149
definition~\cite{aczel77} specifies the least set~$R$ \defn{closed under}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   150
given rules: applying a rule to elements of~$R$ yields a result within~$R$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   151
Inductive definitions have many applications.  The collection of theorems in a
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   152
logic is inductively defined.  A structural operational
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   153
semantics~\cite{hennessy90} is an inductive definition of a reduction or
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   154
evaluation relation on programs.  A few theorem provers provide commands for
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   155
formalizing inductive definitions; these include Coq~\cite{paulin-tlca} and
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   156
again the \textsc{hol} system~\cite{camilleri92}.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   157
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   158
The dual notion is that of a \defn{coinductive definition}.  Such a definition
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   159
specifies the greatest set~$R$ \defn{consistent with} given rules: every
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   160
element of~$R$ can be seen as arising by applying a rule to elements of~$R$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   161
Important examples include using bisimulation relations to formalize
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   162
equivalence of processes~\cite{milner89} or lazy functional
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   163
programs~\cite{abramsky90}.  Other examples include lazy lists and other
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   164
infinite data structures; these are called \defn{codatatypes} below.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   165
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   166
Not all inductive definitions are meaningful.  \defn{Monotone} inductive
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   167
definitions are a large, well-behaved class.  Monotonicity can be enforced
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   168
by syntactic conditions such as ``strictly positive,'' but this could lead to
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   169
monotone definitions being rejected on the grounds of their syntactic form.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   170
More flexible is to formalize monotonicity within the logic and allow users
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   171
to prove it.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   172
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   173
This paper describes a package based on a fixedpoint approach.  Least
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   174
fixedpoints yield inductive definitions; greatest fixedpoints yield
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   175
coinductive definitions.  Most of the discussion below applies equally to
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   176
inductive and coinductive definitions, and most of the code is shared.  
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   177
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   178
The package supports mutual recursion and infinitely-branching datatypes and
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   179
codatatypes.  It allows use of any operators that have been proved monotone,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   180
thus accepting all provably monotone inductive definitions, including
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   181
iterated definitions.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   182
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   183
The package has been implemented in
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   184
Isabelle~\cite{paulson-markt,paulson-isa-book} using 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   185
\textsc{zf} set theory \cite{paulson-set-I,paulson-set-II}; part of it has
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   186
since been ported to Isabelle/\textsc{hol} (higher-order logic).  The
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   187
recursion equations are specified as introduction rules for the mutually
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   188
recursive sets.  The package transforms these rules into a mapping over sets,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   189
and attempts to prove that the mapping is monotonic and well-typed.  If
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   190
successful, the package makes fixedpoint definitions and proves the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   191
introduction, elimination and (co)induction rules.  Users invoke the package
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   192
by making simple declarations in Isabelle theory files.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   193
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   194
Most datatype packages equip the new datatype with some means of expressing
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   195
recursive functions.  This is the main omission from my package.  Its
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   196
fixedpoint operators define only recursive sets.  The Isabelle/\textsc{zf}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   197
theory provides well-founded recursion~\cite{paulson-set-II}, which is harder
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   198
to use than structural recursion but considerably more general.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   199
Slind~\cite{slind-tfl} has written a package to automate the definition of
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   200
well-founded recursive functions in Isabelle/\textsc{hol}.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   201
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   202
\paragraph*{Outline.} Section~2 introduces the least and greatest fixedpoint
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   203
operators.  Section~3 discusses the form of introduction rules, mutual
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   204
recursion and other points common to inductive and coinductive definitions.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   205
Section~4 discusses induction and coinduction rules separately.  Section~5
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   206
presents several examples, including a coinductive definition.  Section~6
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   207
describes datatype definitions.  Section~7 presents related work.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   208
Section~8 draws brief conclusions.  \ifshort\else The appendices are simple
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   209
user's manuals for this Isabelle package.\fi
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   210
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   211
Most of the definitions and theorems shown below have been generated by the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   212
package.  I have renamed some variables to improve readability.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   213
 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   214
\section{Fixedpoint operators}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   215
In set theory, the least and greatest fixedpoint operators are defined as
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   216
follows:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   217
\begin{eqnarray*}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   218
   \lfp(D,h)  & \equiv & \inter\{X\sbs D. h(X)\sbs X\} \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   219
   \gfp(D,h)  & \equiv & \union\{X\sbs D. X\sbs h(X)\}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   220
\end{eqnarray*}   
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   221
Let $D$ be a set.  Say that $h$ is \defn{bounded by}~$D$ if $h(D)\sbs D$, and
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   222
\defn{monotone below~$D$} if
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   223
$h(A)\sbs h(B)$ for all $A$ and $B$ such that $A\sbs B\sbs D$.  If $h$ is
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   224
bounded by~$D$ and monotone then both operators yield fixedpoints:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   225
\begin{eqnarray*}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   226
   \lfp(D,h)  & = & h(\lfp(D,h)) \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   227
   \gfp(D,h)  & = & h(\gfp(D,h)) 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   228
\end{eqnarray*}   
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   229
These equations are instances of the Knaster-Tarski theorem, which states
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   230
that every monotonic function over a complete lattice has a
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   231
fixedpoint~\cite{davey&priestley}.  It is obvious from their definitions
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   232
that $\lfp$ must be the least fixedpoint, and $\gfp$ the greatest.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   233
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   234
This fixedpoint theory is simple.  The Knaster-Tarski theorem is easy to
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   235
prove.  Showing monotonicity of~$h$ is trivial, in typical cases.  We must
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   236
also exhibit a bounding set~$D$ for~$h$.  Frequently this is trivial, as when
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   237
a set of theorems is (co)inductively defined over some previously existing set
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   238
of formul{\ae}.  Isabelle/\textsc{zf} provides suitable bounding sets for
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   239
infinitely-branching (co)datatype definitions; see~\S\ref{univ-sec}.  Bounding
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   240
sets are also called \defn{domains}.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   241
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   242
The powerset operator is monotone, but by Cantor's theorem there is no
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   243
set~$A$ such that $A=\pow(A)$.  We cannot put $A=\lfp(D,\pow)$ because
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   244
there is no suitable domain~$D$.  But \S\ref{acc-sec} demonstrates
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   245
that~$\pow$ is still useful in inductive definitions.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   246
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   247
\section{Elements of an inductive or coinductive definition}\label{basic-sec}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   248
Consider a (co)inductive definition of the sets $R_1$, \ldots,~$R_n$, in
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   249
mutual recursion.  They will be constructed from domains $D_1$,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   250
\ldots,~$D_n$, respectively.  The construction yields not $R_i\sbs D_i$ but
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   251
$R_i\sbs D_1+\cdots+D_n$, where $R_i$ is contained in the image of~$D_i$
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   252
under an injection.  Reasons for this are discussed
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   253
elsewhere~\cite[\S4.5]{paulson-set-II}.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   254
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   255
The definition may involve arbitrary parameters $\vec{p}=p_1$,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   256
\ldots,~$p_k$.  Each recursive set then has the form $R_i(\vec{p})$.  The
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   257
parameters must be identical every time they occur within a definition.  This
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   258
would appear to be a serious restriction compared with other systems such as
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   259
Coq~\cite{paulin-tlca}.  For instance, we cannot define the lists of
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   260
$n$ elements as the set $\listn(A,n)$ using rules where the parameter~$n$
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   261
varies.  Section~\ref{listn-sec} describes how to express this set using the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   262
inductive definition package.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   263
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   264
To avoid clutter below, the recursive sets are shown as simply $R_i$
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   265
instead of~$R_i(\vec{p})$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   266
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   267
\subsection{The form of the introduction rules}\label{intro-sec}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   268
The body of the definition consists of the desired introduction rules.  The
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   269
conclusion of each rule must have the form $t\in R_i$, where $t$ is any term.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   270
Premises typically have the same form, but they can have the more general form
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   271
$t\in M(R_i)$ or express arbitrary side-conditions.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   272
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   273
The premise $t\in M(R_i)$ is permitted if $M$ is a monotonic operator on
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   274
sets, satisfying the rule 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   275
\[ \infer{M(A)\sbs M(B)}{A\sbs B} \]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   276
The user must supply the package with monotonicity rules for all such premises.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   277
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   278
The ability to introduce new monotone operators makes the approach
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   279
flexible.  A suitable choice of~$M$ and~$t$ can express a lot.  The
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   280
powerset operator $\pow$ is monotone, and the premise $t\in\pow(R)$
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   281
expresses $t\sbs R$; see \S\ref{acc-sec} for an example.  The \emph{list of}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   282
operator is monotone, as is easily proved by induction.  The premise
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   283
$t\in\lst(R)$ avoids having to encode the effect of~$\lst(R)$ using mutual
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   284
recursion; see \S\ref{primrec-sec} and also my earlier
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   285
paper~\cite[\S4.4]{paulson-set-II}.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   286
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   287
Introduction rules may also contain \defn{side-conditions}.  These are
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   288
premises consisting of arbitrary formul{\ae} not mentioning the recursive
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   289
sets. Side-conditions typically involve type-checking.  One example is the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   290
premise $a\in A$ in the following rule from the definition of lists:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   291
\[ \infer{\Cons(a,l)\in\lst(A)}{a\in A & l\in\lst(A)} \]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   292
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   293
\subsection{The fixedpoint definitions}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   294
The package translates the list of desired introduction rules into a fixedpoint
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   295
definition.  Consider, as a running example, the finite powerset operator
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   296
$\Fin(A)$: the set of all finite subsets of~$A$.  It can be
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   297
defined as the least set closed under the rules
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   298
\[  \emptyset\in\Fin(A)  \qquad 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   299
    \infer{\{a\}\un b\in\Fin(A)}{a\in A & b\in\Fin(A)} 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   300
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   301
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   302
The domain in a (co)inductive definition must be some existing set closed
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   303
under the rules.  A suitable domain for $\Fin(A)$ is $\pow(A)$, the set of all
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   304
subsets of~$A$.  The package generates the definition
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   305
\[  \Fin(A) \equiv \lfp(\pow(A), \,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   306
  \begin{array}[t]{r@{\,}l}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   307
      \lambda X. \{z\in\pow(A). & z=\emptyset \disj{} \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   308
                  &(\exists a\,b. z=\{a\}\un b\conj a\in A\conj b\in X)\})
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   309
  \end{array}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   310
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   311
The contribution of each rule to the definition of $\Fin(A)$ should be
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   312
obvious.  A coinductive definition is similar but uses $\gfp$ instead
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   313
of~$\lfp$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   314
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   315
The package must prove that the fixedpoint operator is applied to a
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   316
monotonic function.  If the introduction rules have the form described
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   317
above, and if the package is supplied a monotonicity theorem for every
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   318
$t\in M(R_i)$ premise, then this proof is trivial.\footnote{Due to the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   319
  presence of logical connectives in the fixedpoint's body, the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   320
  monotonicity proof requires some unusual rules.  These state that the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   321
  connectives $\conj$, $\disj$ and $\exists$ preserve monotonicity with respect
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   322
  to the partial ordering on unary predicates given by $P\sqsubseteq Q$ if and
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   323
  only if $\forall x.P(x)\imp Q(x)$.}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   324
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   325
The package returns its result as an \textsc{ml} structure, which consists of named
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   326
components; we may regard it as a record.  The result structure contains
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   327
the definitions of the recursive sets as a theorem list called {\tt defs}.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   328
It also contains some theorems; {\tt dom\_subset} is an inclusion such as 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   329
$\Fin(A)\sbs\pow(A)$, while {\tt bnd\_mono} asserts that the fixedpoint
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   330
definition is monotonic.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   331
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   332
Internally the package uses the theorem {\tt unfold}, a fixedpoint equation
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   333
such as
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   334
\[
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   335
  \begin{array}[t]{r@{\,}l}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   336
     \Fin(A) = \{z\in\pow(A). & z=\emptyset \disj{} \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   337
             &(\exists a\,b. z=\{a\}\un b\conj a\in A\conj b\in \Fin(A))\}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   338
  \end{array}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   339
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   340
In order to save space, this theorem is not exported.  
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   341
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   342
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   343
\subsection{Mutual recursion} \label{mutual-sec}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   344
In a mutually recursive definition, the domain of the fixedpoint construction
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   345
is the disjoint sum of the domain~$D_i$ of each~$R_i$, for $i=1$,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   346
\ldots,~$n$.  The package uses the injections of the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   347
binary disjoint sum, typically $\Inl$ and~$\Inr$, to express injections
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   348
$h_{1n}$, \ldots, $h_{nn}$ for the $n$-ary disjoint sum $D_1+\cdots+D_n$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   349
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   350
As discussed elsewhere \cite[\S4.5]{paulson-set-II}, Isabelle/\textsc{zf} defines the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   351
operator $\Part$ to support mutual recursion.  The set $\Part(A,h)$
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   352
contains those elements of~$A$ having the form~$h(z)$:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   353
\[ \Part(A,h)  \equiv \{x\in A. \exists z. x=h(z)\}. \]   
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   354
For mutually recursive sets $R_1$, \ldots,~$R_n$ with
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   355
$n>1$, the package makes $n+1$ definitions.  The first defines a set $R$ using
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   356
a fixedpoint operator. The remaining $n$ definitions have the form
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   357
\[ R_i \equiv \Part(R,h_{in}), \qquad i=1,\ldots, n.  \] 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   358
It follows that $R=R_1\un\cdots\un R_n$, where the $R_i$ are pairwise disjoint.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   359
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   360
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   361
\subsection{Proving the introduction rules}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   362
The user supplies the package with the desired form of the introduction
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   363
rules.  Once it has derived the theorem {\tt unfold}, it attempts
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   364
to prove those rules.  From the user's point of view, this is the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   365
trickiest stage; the proofs often fail.  The task is to show that the domain 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   366
$D_1+\cdots+D_n$ of the combined set $R_1\un\cdots\un R_n$ is
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   367
closed under all the introduction rules.  This essentially involves replacing
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   368
each~$R_i$ by $D_1+\cdots+D_n$ in each of the introduction rules and
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   369
attempting to prove the result.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   370
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   371
Consider the $\Fin(A)$ example.  After substituting $\pow(A)$ for $\Fin(A)$
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   372
in the rules, the package must prove
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   373
\[  \emptyset\in\pow(A)  \qquad 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   374
    \infer{\{a\}\un b\in\pow(A)}{a\in A & b\in\pow(A)} 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   375
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   376
Such proofs can be regarded as type-checking the definition.\footnote{The
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   377
  Isabelle/\textsc{hol} version does not require these proofs, as \textsc{hol}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   378
  has implicit type-checking.} The user supplies the package with
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   379
type-checking rules to apply.  Usually these are general purpose rules from
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   380
the \textsc{zf} theory.  They could however be rules specifically proved for a
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   381
particular inductive definition; sometimes this is the easiest way to get the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   382
definition through!
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   383
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   384
The result structure contains the introduction rules as the theorem list {\tt
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   385
intrs}.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   386
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   387
\subsection{The case analysis rule}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   388
The elimination rule, called {\tt elim}, performs case analysis.  It is a
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   389
simple consequence of {\tt unfold}.  There is one case for each introduction
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   390
rule.  If $x\in\Fin(A)$ then either $x=\emptyset$ or else $x=\{a\}\un b$ for
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   391
some $a\in A$ and $b\in\Fin(A)$.  Formally, the elimination rule for $\Fin(A)$
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   392
is written
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   393
\[ \infer{Q}{x\in\Fin(A) & \infer*{Q}{[x=\emptyset]}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   394
                 & \infer*{Q}{[x=\{a\}\un b & a\in A &b\in\Fin(A)]_{a,b}} }
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   395
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   396
The subscripted variables $a$ and~$b$ above the third premise are
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   397
eigenvariables, subject to the usual ``not free in \ldots'' proviso.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   398
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   399
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   400
\section{Induction and coinduction rules}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   401
Here we must consider inductive and coinductive definitions separately.  For
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   402
an inductive definition, the package returns an induction rule derived
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   403
directly from the properties of least fixedpoints, as well as a modified rule
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   404
for mutual recursion.  For a coinductive definition, the package returns a
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   405
basic coinduction rule.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   406
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   407
\subsection{The basic induction rule}\label{basic-ind-sec}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   408
The basic rule, called {\tt induct}, is appropriate in most situations.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   409
For inductive definitions, it is strong rule induction~\cite{camilleri92}; for
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   410
datatype definitions (see below), it is just structural induction.  
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   411
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   412
The induction rule for an inductively defined set~$R$ has the form described
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   413
below.  For the time being, assume that $R$'s domain is not a Cartesian
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   414
product; inductively defined relations are treated slightly differently.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   415
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   416
The major premise is $x\in R$.  There is a minor premise for each
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   417
introduction rule:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   418
\begin{itemize}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   419
\item If the introduction rule concludes $t\in R_i$, then the minor premise
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   420
is~$P(t)$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   421
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   422
\item The minor premise's eigenvariables are precisely the introduction
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   423
rule's free variables that are not parameters of~$R$.  For instance, the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   424
eigenvariables in the $\Fin(A)$ rule below are $a$ and $b$, but not~$A$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   425
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   426
\item If the introduction rule has a premise $t\in R_i$, then the minor
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   427
premise discharges the assumption $t\in R_i$ and the induction
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   428
hypothesis~$P(t)$.  If the introduction rule has a premise $t\in M(R_i)$
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   429
then the minor premise discharges the single assumption
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   430
\[ t\in M(\{z\in R_i. P(z)\}). \] 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   431
Because $M$ is monotonic, this assumption implies $t\in M(R_i)$.  The
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   432
occurrence of $P$ gives the effect of an induction hypothesis, which may be
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   433
exploited by appealing to properties of~$M$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   434
\end{itemize}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   435
The induction rule for $\Fin(A)$ resembles the elimination rule shown above,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   436
but includes an induction hypothesis:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   437
\[ \infer{P(x)}{x\in\Fin(A) & P(\emptyset)
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   438
        & \infer*{P(\{a\}\un b)}{[a\in A & b\in\Fin(A) & P(b)]_{a,b}} }
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   439
\] 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   440
Stronger induction rules often suggest themselves.  We can derive a rule for
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   441
$\Fin(A)$ whose third premise discharges the extra assumption $a\not\in b$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   442
The package provides rules for mutual induction and inductive relations.  The
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   443
Isabelle/\textsc{zf} theory also supports well-founded induction and recursion
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   444
over datatypes, by reasoning about the \defn{rank} of a
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   445
set~\cite[\S3.4]{paulson-set-II}.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   446
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   447
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   448
\subsection{Modified induction rules}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   449
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   450
If the domain of $R$ is a Cartesian product $A_1\times\cdots\times A_m$
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   451
(however nested), then the corresponding predicate $P_i$ takes $m$ arguments.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   452
The major premise becomes $\pair{z_1,\ldots,z_m}\in R$ instead of $x\in R$;
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   453
the conclusion becomes $P(z_1,\ldots,z_m)$.  This simplifies reasoning about
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   454
inductively defined relations, eliminating the need to express properties of
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   455
$z_1$, \ldots,~$z_m$ as properties of the tuple $\pair{z_1,\ldots,z_m}$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   456
Occasionally it may require you to split up the induction variable
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   457
using {\tt SigmaE} and {\tt dom\_subset}, especially if the constant {\tt
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   458
  split} appears in the rule.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   459
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   460
The mutual induction rule is called {\tt
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   461
mutual\_induct}.  It differs from the basic rule in two respects:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   462
\begin{itemize}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   463
\item Instead of a single predicate~$P$, it uses $n$ predicates $P_1$,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   464
\ldots,~$P_n$: one for each recursive set.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   465
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   466
\item There is no major premise such as $x\in R_i$.  Instead, the conclusion
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   467
refers to all the recursive sets:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   468
\[ (\forall z.z\in R_1\imp P_1(z))\conj\cdots\conj
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   469
   (\forall z.z\in R_n\imp P_n(z))
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   470
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   471
Proving the premises establishes $P_i(z)$ for $z\in R_i$ and $i=1$,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   472
\ldots,~$n$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   473
\end{itemize}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   474
%
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   475
If the domain of some $R_i$ is a Cartesian product, then the mutual induction
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   476
rule is modified accordingly.  The predicates are made to take $m$ separate
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   477
arguments instead of a tuple, and the quantification in the conclusion is over
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   478
the separate variables $z_1$, \ldots, $z_m$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   479
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   480
\subsection{Coinduction}\label{coind-sec}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   481
A coinductive definition yields a primitive coinduction rule, with no
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   482
refinements such as those for the induction rules.  (Experience may suggest
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   483
refinements later.)  Consider the codatatype of lazy lists as an example.  For
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   484
suitable definitions of $\LNil$ and $\LCons$, lazy lists may be defined as the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   485
greatest set consistent with the rules
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   486
\[  \LNil\in\llist(A)  \qquad 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   487
    \infer[(-)]{\LCons(a,l)\in\llist(A)}{a\in A & l\in\llist(A)}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   488
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   489
The $(-)$ tag stresses that this is a coinductive definition.  A suitable
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   490
domain for $\llist(A)$ is $\quniv(A)$; this set is closed under the variant
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   491
forms of sum and product that are used to represent non-well-founded data
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   492
structures (see~\S\ref{univ-sec}).
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   493
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   494
The package derives an {\tt unfold} theorem similar to that for $\Fin(A)$. 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   495
Then it proves the theorem {\tt coinduct}, which expresses that $\llist(A)$
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   496
is the greatest solution to this equation contained in $\quniv(A)$:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   497
\[ \infer{x\in\llist(A)}{x\in X & X\sbs \quniv(A) &
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   498
    \infer*{
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   499
     \begin{array}[b]{r@{}l}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   500
       z=\LNil\disj 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   501
       \bigl(\exists a\,l.\, & z=\LCons(a,l) \conj a\in A \conj{}\\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   502
                             & l\in X\un\llist(A) \bigr)
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   503
     \end{array}  }{[z\in X]_z}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   504
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   505
This rule complements the introduction rules; it provides a means of showing
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   506
$x\in\llist(A)$ when $x$ is infinite.  For instance, if $x=\LCons(0,x)$ then
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   507
applying the rule with $X=\{x\}$ proves $x\in\llist(\nat)$.  (Here $\nat$
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   508
is the set of natural numbers.)
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   509
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   510
Having $X\un\llist(A)$ instead of simply $X$ in the third premise above
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   511
represents a slight strengthening of the greatest fixedpoint property.  I
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   512
discuss several forms of coinduction rules elsewhere~\cite{paulson-coind}.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   513
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   514
The clumsy form of the third premise makes the rule hard to use, especially in
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   515
large definitions.  Probably a constant should be declared to abbreviate the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   516
large disjunction, and rules derived to allow proving the separate disjuncts.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   517
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   518
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   519
\section{Examples of inductive and coinductive definitions}\label{ind-eg-sec}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   520
This section presents several examples from the literature: the finite
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   521
powerset operator, lists of $n$ elements, bisimulations on lazy lists, the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   522
well-founded part of a relation, and the primitive recursive functions.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   523
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   524
\subsection{The finite powerset operator}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   525
This operator has been discussed extensively above.  Here is the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   526
corresponding invocation in an Isabelle theory file.  Note that
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   527
$\cons(a,b)$ abbreviates $\{a\}\un b$ in Isabelle/\textsc{zf}.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   528
\begin{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   529
Finite = Arith + 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   530
consts      Fin :: i=>i
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   531
inductive
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   532
  domains   "Fin(A)" <= "Pow(A)"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   533
  intrs
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   534
    emptyI  "0 : Fin(A)"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   535
    consI   "[| a: A;  b: Fin(A) |] ==> cons(a,b) : Fin(A)"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   536
  type_intrs "[empty_subsetI, cons_subsetI, PowI]"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   537
  type_elims "[make_elim PowD]"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   538
end
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   539
\end{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   540
Theory {\tt Finite} extends the parent theory {\tt Arith} by declaring the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   541
unary function symbol~$\Fin$, which is defined inductively.  Its domain is
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   542
specified as $\pow(A)$, where $A$ is the parameter appearing in the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   543
introduction rules.  For type-checking, we supply two introduction
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   544
rules:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   545
\[ \emptyset\sbs A              \qquad
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   546
   \infer{\{a\}\un B\sbs C}{a\in C & B\sbs C}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   547
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   548
A further introduction rule and an elimination rule express both
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   549
directions of the equivalence $A\in\pow(B)\bimp A\sbs B$.  Type-checking
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   550
involves mostly introduction rules.  
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   551
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   552
Like all Isabelle theory files, this one yields a structure containing the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   553
new theory as an \textsc{ml} value.  Structure {\tt Finite} also has a
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   554
substructure, called~{\tt Fin}.  After declaring \hbox{\tt open Finite;} we
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   555
can refer to the $\Fin(A)$ introduction rules as the list {\tt Fin.intrs}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   556
or individually as {\tt Fin.emptyI} and {\tt Fin.consI}.  The induction
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   557
rule is {\tt Fin.induct}.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   558
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   559
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   560
\subsection{Lists of $n$ elements}\label{listn-sec}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   561
This has become a standard example of an inductive definition.  Following
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   562
Paulin-Mohring~\cite{paulin-tlca}, we could attempt to define a new datatype
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   563
$\listn(A,n)$, for lists of length~$n$, as an $n$-indexed family of sets.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   564
But her introduction rules
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   565
\[ \hbox{\tt Niln}\in\listn(A,0)  \qquad
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   566
   \infer{\hbox{\tt Consn}(n,a,l)\in\listn(A,\succ(n))}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   567
         {n\in\nat & a\in A & l\in\listn(A,n)}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   568
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   569
are not acceptable to the inductive definition package:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   570
$\listn$ occurs with three different parameter lists in the definition.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   571
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   572
The Isabelle version of this example suggests a general treatment of
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   573
varying parameters.  It uses the existing datatype definition of
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   574
$\lst(A)$, with constructors $\Nil$ and~$\Cons$, and incorporates the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   575
parameter~$n$ into the inductive set itself.  It defines $\listn(A)$ as a
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   576
relation consisting of pairs $\pair{n,l}$ such that $n\in\nat$
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   577
and~$l\in\lst(A)$ and $l$ has length~$n$.  In fact, $\listn(A)$ is the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   578
converse of the length function on~$\lst(A)$.  The Isabelle/\textsc{zf} introduction
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   579
rules are
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   580
\[ \pair{0,\Nil}\in\listn(A)  \qquad
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   581
   \infer{\pair{\succ(n),\Cons(a,l)}\in\listn(A)}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   582
         {a\in A & \pair{n,l}\in\listn(A)}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   583
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   584
The Isabelle theory file takes, as parent, the theory~{\tt List} of lists.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   585
We declare the constant~$\listn$ and supply an inductive definition,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   586
specifying the domain as $\nat\times\lst(A)$:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   587
\begin{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   588
ListN = List +
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   589
consts  listn :: i=>i
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   590
inductive
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   591
  domains   "listn(A)" <= "nat*list(A)"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   592
  intrs
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   593
    NilI  "<0,Nil>: listn(A)"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   594
    ConsI "[| a: A;  <n,l>: listn(A) |] ==> <succ(n), Cons(a,l)>: listn(A)"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   595
  type_intrs "nat_typechecks @ list.intrs"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   596
end
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   597
\end{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   598
The type-checking rules include those for 0, $\succ$, $\Nil$ and $\Cons$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   599
Because $\listn(A)$ is a set of pairs, type-checking requires the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   600
equivalence $\pair{a,b}\in A\times B \bimp a\in A \conj b\in B$.  The
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   601
package always includes the rules for ordered pairs.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   602
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   603
The package returns introduction, elimination and induction rules for
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   604
$\listn$.  The basic induction rule, {\tt listn.induct}, is
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   605
\[ \infer{P(z_1,z_2)}{\pair{z_1,z_2}\in\listn(A) & P(0,\Nil) &
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   606
             \infer*{P(\succ(n),\Cons(a,l))}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   607
                {[a\in A & \pair{n,l}\in\listn(A) & P(n,l)]_{a,l,n}}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   608
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   609
This rule lets the induction formula to be a 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   610
binary property of pairs, $P(n,l)$.  
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   611
It is now a simple matter to prove theorems about $\listn(A)$, such as
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   612
\[ \forall l\in\lst(A). \pair{\length(l),\, l}\in\listn(A) \]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   613
\[ \listn(A)``\{n\} = \{l\in\lst(A). \length(l)=n\} \]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   614
This latter result --- here $r``X$ denotes the image of $X$ under $r$
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   615
--- asserts that the inductive definition agrees with the obvious notion of
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   616
$n$-element list.  
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   617
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   618
A ``list of $n$ elements'' really is a list, namely an element of ~$\lst(A)$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   619
It is subject to list operators such as append (concatenation).  For example,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   620
a trivial induction on $\pair{m,l}\in\listn(A)$ yields
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   621
\[ \infer{\pair{m\mathbin{+} m',\, l@l'}\in\listn(A)}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   622
         {\pair{m,l}\in\listn(A) & \pair{m',l'}\in\listn(A)} 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   623
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   624
where $+$ denotes addition on the natural numbers and @ denotes append.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   625
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   626
\subsection{Rule inversion: the function {\tt mk\_cases}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   627
The elimination rule, {\tt listn.elim}, is cumbersome:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   628
\[ \infer{Q}{x\in\listn(A) & 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   629
          \infer*{Q}{[x = \pair{0,\Nil}]} &
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   630
          \infer*{Q}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   631
             {\left[\begin{array}{l}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   632
               x = \pair{\succ(n),\Cons(a,l)} \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   633
               a\in A \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   634
               \pair{n,l}\in\listn(A)
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   635
               \end{array} \right]_{a,l,n}}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   636
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   637
The \textsc{ml} function {\tt listn.mk\_cases} generates simplified instances of
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   638
this rule.  It works by freeness reasoning on the list constructors:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   639
$\Cons(a,l)$ is injective in its two arguments and differs from~$\Nil$.  If
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   640
$x$ is $\pair{i,\Nil}$ or $\pair{i,\Cons(a,l)}$ then {\tt listn.mk\_cases}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   641
deduces the corresponding form of~$i$;  this is called rule inversion.  
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   642
Here is a sample session: 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   643
\begin{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   644
listn.mk_cases list.con_defs "<i,Nil> : listn(A)";
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   645
{\out "[| <?i, []> : listn(?A); ?i = 0 ==> ?Q |] ==> ?Q" : thm}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   646
listn.mk_cases list.con_defs "<i,Cons(a,l)> : listn(A)";
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   647
{\out "[| <?i, Cons(?a, ?l)> : listn(?A);}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   648
{\out     !!n. [| ?a : ?A; <n, ?l> : listn(?A); ?i = succ(n) |] ==> ?Q }
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   649
{\out  |] ==> ?Q" : thm}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   650
\end{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   651
Each of these rules has only two premises.  In conventional notation, the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   652
second rule is
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   653
\[ \infer{Q}{\pair{i, \Cons(a,l)}\in\listn(A) & 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   654
          \infer*{Q}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   655
             {\left[\begin{array}{l}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   656
               a\in A \\ \pair{n,l}\in\listn(A) \\ i = \succ(n)
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   657
               \end{array} \right]_{n}}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   658
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   659
The package also has built-in rules for freeness reasoning about $0$
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   660
and~$\succ$.  So if $x$ is $\pair{0,l}$ or $\pair{\succ(i),l}$, then {\tt
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   661
listn.mk\_cases} can deduce the corresponding form of~$l$. 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   662
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   663
The function {\tt mk\_cases} is also useful with datatype definitions.  The
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   664
instance from the definition of lists, namely {\tt list.mk\_cases}, can
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   665
prove that $\Cons(a,l)\in\lst(A)$ implies $a\in A $ and $l\in\lst(A)$:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   666
\[ \infer{Q}{\Cons(a,l)\in\lst(A) & 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   667
                 & \infer*{Q}{[a\in A &l\in\lst(A)]} }
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   668
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   669
A typical use of {\tt mk\_cases} concerns inductive definitions of evaluation
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   670
relations.  Then rule inversion yields case analysis on possible evaluations.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   671
For example, Isabelle/\textsc{zf} includes a short proof of the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   672
diamond property for parallel contraction on combinators.  Ole Rasmussen used
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   673
{\tt mk\_cases} extensively in his development of the theory of
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   674
residuals~\cite{rasmussen95}.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   675
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   676
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   677
\subsection{A coinductive definition: bisimulations on lazy lists}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   678
This example anticipates the definition of the codatatype $\llist(A)$, which
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   679
consists of finite and infinite lists over~$A$.  Its constructors are $\LNil$
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   680
and~$\LCons$, satisfying the introduction rules shown in~\S\ref{coind-sec}.  
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   681
Because $\llist(A)$ is defined as a greatest fixedpoint and uses the variant
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   682
pairing and injection operators, it contains non-well-founded elements such as
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   683
solutions to $\LCons(a,l)=l$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   684
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   685
The next step in the development of lazy lists is to define a coinduction
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   686
principle for proving equalities.  This is done by showing that the equality
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   687
relation on lazy lists is the greatest fixedpoint of some monotonic
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   688
operation.  The usual approach~\cite{pitts94} is to define some notion of 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   689
bisimulation for lazy lists, define equivalence to be the greatest
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   690
bisimulation, and finally to prove that two lazy lists are equivalent if and
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   691
only if they are equal.  The coinduction rule for equivalence then yields a
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   692
coinduction principle for equalities.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   693
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   694
A binary relation $R$ on lazy lists is a \defn{bisimulation} provided $R\sbs
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   695
R^+$, where $R^+$ is the relation
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   696
\[ \{\pair{\LNil,\LNil}\} \un 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   697
   \{\pair{\LCons(a,l),\LCons(a,l')} . a\in A \conj \pair{l,l'}\in R\}.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   698
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   699
A pair of lazy lists are \defn{equivalent} if they belong to some
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   700
bisimulation.  Equivalence can be coinductively defined as the greatest
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   701
fixedpoint for the introduction rules
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   702
\[  \pair{\LNil,\LNil} \in\lleq(A)  \qquad 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   703
    \infer[(-)]{\pair{\LCons(a,l),\LCons(a,l')} \in\lleq(A)}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   704
          {a\in A & \pair{l,l'}\in \lleq(A)}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   705
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   706
To make this coinductive definition, the theory file includes (after the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   707
declaration of $\llist(A)$) the following lines:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   708
\begin{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   709
consts    lleq :: i=>i
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   710
coinductive
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   711
  domains "lleq(A)" <= "llist(A) * llist(A)"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   712
  intrs
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   713
    LNil  "<LNil,LNil> : lleq(A)"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   714
    LCons "[| a:A; <l,l'>: lleq(A) |] ==> <LCons(a,l),LCons(a,l')>: lleq(A)"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   715
  type_intrs  "llist.intrs"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   716
\end{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   717
The domain of $\lleq(A)$ is $\llist(A)\times\llist(A)$.  The type-checking
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   718
rules include the introduction rules for $\llist(A)$, whose 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   719
declaration is discussed below (\S\ref{lists-sec}).
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   720
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   721
The package returns the introduction rules and the elimination rule, as
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   722
usual.  But instead of induction rules, it returns a coinduction rule.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   723
The rule is too big to display in the usual notation; its conclusion is
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   724
$x\in\lleq(A)$ and its premises are $x\in X$, 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   725
${X\sbs\llist(A)\times\llist(A)}$ and
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   726
\[ \infer*{z=\pair{\LNil,\LNil}\disj \bigl(\exists a\,l\,l'.\,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   727
     \begin{array}[t]{@{}l}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   728
       z=\pair{\LCons(a,l),\LCons(a,l')} \conj a\in A \conj{}\\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   729
       \pair{l,l'}\in X\un\lleq(A) \bigr)
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   730
     \end{array}  
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   731
    }{[z\in X]_z}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   732
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   733
Thus if $x\in X$, where $X$ is a bisimulation contained in the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   734
domain of $\lleq(A)$, then $x\in\lleq(A)$.  It is easy to show that
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   735
$\lleq(A)$ is reflexive: the equality relation is a bisimulation.  And
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   736
$\lleq(A)$ is symmetric: its converse is a bisimulation.  But showing that
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   737
$\lleq(A)$ coincides with the equality relation takes some work.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   738
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   739
\subsection{The accessible part of a relation}\label{acc-sec}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   740
Let $\prec$ be a binary relation on~$D$; in short, $(\prec)\sbs D\times D$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   741
The \defn{accessible} or \defn{well-founded} part of~$\prec$, written
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   742
$\acc(\prec)$, is essentially that subset of~$D$ for which $\prec$ admits
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   743
no infinite decreasing chains~\cite{aczel77}.  Formally, $\acc(\prec)$ is
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   744
inductively defined to be the least set that contains $a$ if it contains
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   745
all $\prec$-predecessors of~$a$, for $a\in D$.  Thus we need an
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   746
introduction rule of the form 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   747
\[ \infer{a\in\acc(\prec)}{\forall y.y\prec a\imp y\in\acc(\prec)} \]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   748
Paulin-Mohring treats this example in Coq~\cite{paulin-tlca}, but it causes
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   749
difficulties for other systems.  Its premise is not acceptable to the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   750
inductive definition package of the Cambridge \textsc{hol}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   751
system~\cite{camilleri92}.  It is also unacceptable to the Isabelle package
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   752
(recall \S\ref{intro-sec}), but fortunately can be transformed into the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   753
acceptable form $t\in M(R)$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   754
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   755
The powerset operator is monotonic, and $t\in\pow(R)$ is equivalent to
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   756
$t\sbs R$.  This in turn is equivalent to $\forall y\in t. y\in R$.  To
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   757
express $\forall y.y\prec a\imp y\in\acc(\prec)$ we need only find a
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   758
term~$t$ such that $y\in t$ if and only if $y\prec a$.  A suitable $t$ is
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   759
the inverse image of~$\{a\}$ under~$\prec$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   760
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   761
The definition below follows this approach.  Here $r$ is~$\prec$ and
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   762
$\field(r)$ refers to~$D$, the domain of $\acc(r)$.  (The field of a
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   763
relation is the union of its domain and range.)  Finally $r^{-}``\{a\}$
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   764
denotes the inverse image of~$\{a\}$ under~$r$.  We supply the theorem {\tt
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   765
  Pow\_mono}, which asserts that $\pow$ is monotonic.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   766
\begin{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   767
consts    acc :: i=>i
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   768
inductive
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   769
  domains "acc(r)" <= "field(r)"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   770
  intrs
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   771
    vimage  "[| r-``\{a\}: Pow(acc(r)); a: field(r) |] ==> a: acc(r)"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   772
  monos     "[Pow_mono]"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   773
\end{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   774
The Isabelle theory proceeds to prove facts about $\acc(\prec)$.  For
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   775
instance, $\prec$ is well-founded if and only if its field is contained in
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   776
$\acc(\prec)$.  
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   777
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   778
As mentioned in~\S\ref{basic-ind-sec}, a premise of the form $t\in M(R)$
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   779
gives rise to an unusual induction hypothesis.  Let us examine the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   780
induction rule, {\tt acc.induct}:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   781
\[ \infer{P(x)}{x\in\acc(r) &
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   782
     \infer*{P(a)}{\left[
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   783
                   \begin{array}{r@{}l}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   784
                     r^{-}``\{a\} &\, \in\pow(\{z\in\acc(r).P(z)\}) \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   785
                                a &\, \in\field(r)
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   786
                   \end{array}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   787
                   \right]_a}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   788
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   789
The strange induction hypothesis is equivalent to
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   790
$\forall y. \pair{y,a}\in r\imp y\in\acc(r)\conj P(y)$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   791
Therefore the rule expresses well-founded induction on the accessible part
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   792
of~$\prec$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   793
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   794
The use of inverse image is not essential.  The Isabelle package can accept
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   795
introduction rules with arbitrary premises of the form $\forall
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   796
\vec{y}.P(\vec{y})\imp f(\vec{y})\in R$.  The premise can be expressed
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   797
equivalently as 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   798
\[ \{z\in D. P(\vec{y}) \conj z=f(\vec{y})\} \in \pow(R) \] 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   799
provided $f(\vec{y})\in D$ for all $\vec{y}$ such that~$P(\vec{y})$.  The
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   800
following section demonstrates another use of the premise $t\in M(R)$,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   801
where $M=\lst$. 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   802
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   803
\subsection{The primitive recursive functions}\label{primrec-sec}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   804
The primitive recursive functions are traditionally defined inductively, as
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   805
a subset of the functions over the natural numbers.  One difficulty is that
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   806
functions of all arities are taken together, but this is easily
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   807
circumvented by regarding them as functions on lists.  Another difficulty,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   808
the notion of composition, is less easily circumvented.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   809
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   810
Here is a more precise definition.  Letting $\vec{x}$ abbreviate
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   811
$x_0,\ldots,x_{n-1}$, we can write lists such as $[\vec{x}]$,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   812
$[y+1,\vec{x}]$, etc.  A function is \defn{primitive recursive} if it
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   813
belongs to the least set of functions in $\lst(\nat)\to\nat$ containing
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   814
\begin{itemize}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   815
\item The \defn{successor} function $\SC$, such that $\SC[y,\vec{x}]=y+1$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   816
\item All \defn{constant} functions $\CONST(k)$, such that
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   817
  $\CONST(k)[\vec{x}]=k$. 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   818
\item All \defn{projection} functions $\PROJ(i)$, such that
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   819
  $\PROJ(i)[\vec{x}]=x_i$ if $0\leq i<n$. 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   820
\item All \defn{compositions} $\COMP(g,[f_0,\ldots,f_{m-1}])$, 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   821
where $g$ and $f_0$, \ldots, $f_{m-1}$ are primitive recursive,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   822
such that
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   823
\[ \COMP(g,[f_0,\ldots,f_{m-1}])[\vec{x}] = 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   824
   g[f_0[\vec{x}],\ldots,f_{m-1}[\vec{x}]]. \] 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   825
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   826
\item All \defn{recursions} $\PREC(f,g)$, where $f$ and $g$ are primitive
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   827
  recursive, such that
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   828
\begin{eqnarray*}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   829
  \PREC(f,g)[0,\vec{x}] & = & f[\vec{x}] \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   830
  \PREC(f,g)[y+1,\vec{x}] & = & g[\PREC(f,g)[y,\vec{x}],\, y,\, \vec{x}].
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   831
\end{eqnarray*} 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   832
\end{itemize}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   833
Composition is awkward because it combines not two functions, as is usual,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   834
but $m+1$ functions.  In her proof that Ackermann's function is not
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   835
primitive recursive, Nora Szasz was unable to formalize this definition
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   836
directly~\cite{szasz93}.  So she generalized primitive recursion to
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   837
tuple-valued functions.  This modified the inductive definition such that
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   838
each operation on primitive recursive functions combined just two functions.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   839
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   840
\begin{figure}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   841
\begin{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   842
Primrec = List +
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   843
consts
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   844
  primrec :: i
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   845
  SC      :: i
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   846
  \(\vdots\)
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   847
defs
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   848
  SC_def    "SC == lam l:list(nat).list_case(0, \%x xs.succ(x), l)"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   849
  \(\vdots\)
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   850
inductive
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   851
  domains "primrec" <= "list(nat)->nat"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   852
  intrs
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   853
    SC       "SC : primrec"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   854
    CONST    "k: nat ==> CONST(k) : primrec"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   855
    PROJ     "i: nat ==> PROJ(i) : primrec"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   856
    COMP     "[| g: primrec; fs: list(primrec) |] ==> COMP(g,fs): primrec"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   857
    PREC     "[| f: primrec; g: primrec |] ==> PREC(f,g): primrec"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   858
  monos      "[list_mono]"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   859
  con_defs   "[SC_def,CONST_def,PROJ_def,COMP_def,PREC_def]"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   860
  type_intrs "nat_typechecks @ list.intrs @                      
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   861
              [lam_type, list_case_type, drop_type, map_type,    
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   862
               apply_type, rec_type]"
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   863
end
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   864
\end{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   865
\hrule
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   866
\caption{Inductive definition of the primitive recursive functions} 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   867
\label{primrec-fig}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   868
\end{figure}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   869
\def\fs{{\it fs}} 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   870
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   871
Szasz was using \textsc{alf}, but Coq and \textsc{hol} would also have
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   872
problems accepting this definition.  Isabelle's package accepts it easily
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   873
since $[f_0,\ldots,f_{m-1}]$ is a list of primitive recursive functions and
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   874
$\lst$ is monotonic.  There are five introduction rules, one for each of the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   875
five forms of primitive recursive function.  Let us examine the one for
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   876
$\COMP$:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   877
\[ \infer{\COMP(g,\fs)\in\primrec}{g\in\primrec & \fs\in\lst(\primrec)} \]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   878
The induction rule for $\primrec$ has one case for each introduction rule.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   879
Due to the use of $\lst$ as a monotone operator, the composition case has
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   880
an unusual induction hypothesis:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   881
 \[ \infer*{P(\COMP(g,\fs))}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   882
          {[g\in\primrec & \fs\in\lst(\{z\in\primrec.P(z)\})]_{\fs,g}} 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   883
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   884
The hypothesis states that $\fs$ is a list of primitive recursive functions,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   885
each satisfying the induction formula.  Proving the $\COMP$ case typically
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   886
requires structural induction on lists, yielding two subcases: either
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   887
$\fs=\Nil$ or else $\fs=\Cons(f,\fs')$, where $f\in\primrec$, $P(f)$, and
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   888
$\fs'$ is another list of primitive recursive functions satisfying~$P$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   889
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   890
Figure~\ref{primrec-fig} presents the theory file.  Theory {\tt Primrec}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   891
defines the constants $\SC$, $\CONST$, etc.  These are not constructors of
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   892
a new datatype, but functions over lists of numbers.  Their definitions,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   893
most of which are omitted, consist of routine list programming.  In
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   894
Isabelle/\textsc{zf}, the primitive recursive functions are defined as a subset of
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   895
the function set $\lst(\nat)\to\nat$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   896
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   897
The Isabelle theory goes on to formalize Ackermann's function and prove
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   898
that it is not primitive recursive, using the induction rule {\tt
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   899
  primrec.induct}.  The proof follows Szasz's excellent account.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   900
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   901
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   902
\section{Datatypes and codatatypes}\label{data-sec}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   903
A (co)datatype definition is a (co)inductive definition with automatically
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   904
defined constructors and a case analysis operator.  The package proves that
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   905
the case operator inverts the constructors and can prove freeness theorems
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   906
involving any pair of constructors.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   907
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   908
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   909
\subsection{Constructors and their domain}\label{univ-sec}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   910
A (co)inductive definition selects a subset of an existing set; a (co)datatype
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   911
definition creates a new set.  The package reduces the latter to the former.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   912
Isabelle/\textsc{zf} supplies sets having strong closure properties to serve
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   913
as domains for (co)inductive definitions.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   914
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   915
Isabelle/\textsc{zf} defines the Cartesian product $A\times
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   916
B$, containing ordered pairs $\pair{a,b}$; it also defines the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   917
disjoint sum $A+B$, containing injections $\Inl(a)\equiv\pair{0,a}$ and
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   918
$\Inr(b)\equiv\pair{1,b}$.  For use below, define the $m$-tuple
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   919
$\pair{x_1,\ldots,x_m}$ to be the empty set~$\emptyset$ if $m=0$, simply $x_1$
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   920
if $m=1$ and $\pair{x_1,\pair{x_2,\ldots,x_m}}$ if $m\geq2$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   921
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   922
A datatype constructor $\Con(x_1,\ldots,x_m)$ is defined to be
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   923
$h(\pair{x_1,\ldots,x_m})$, where $h$ is composed of $\Inl$ and~$\Inr$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   924
In a mutually recursive definition, all constructors for the set~$R_i$ have
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   925
the outer form~$h_{in}$, where $h_{in}$ is the injection described
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   926
in~\S\ref{mutual-sec}.  Further nested injections ensure that the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   927
constructors for~$R_i$ are pairwise distinct.  
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   928
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   929
Isabelle/\textsc{zf} defines the set $\univ(A)$, which contains~$A$ and
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   930
furthermore contains $\pair{a,b}$, $\Inl(a)$ and $\Inr(b)$ for $a$,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   931
$b\in\univ(A)$.  In a typical datatype definition with set parameters
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   932
$A_1$, \ldots, $A_k$, a suitable domain for all the recursive sets is
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   933
$\univ(A_1\un\cdots\un A_k)$.  This solves the problem for
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   934
datatypes~\cite[\S4.2]{paulson-set-II}.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   935
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   936
The standard pairs and injections can only yield well-founded
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   937
constructions.  This eases the (manual!) definition of recursive functions
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   938
over datatypes.  But they are unsuitable for codatatypes, which typically
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   939
contain non-well-founded objects.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   940
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   941
To support codatatypes, Isabelle/\textsc{zf} defines a variant notion of
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   942
ordered pair, written~$\pair{a;b}$.  It also defines the corresponding variant
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   943
notion of Cartesian product $A\otimes B$, variant injections $\QInl(a)$
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   944
and~$\QInr(b)$ and variant disjoint sum $A\oplus B$.  Finally it defines the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   945
set $\quniv(A)$, which contains~$A$ and furthermore contains $\pair{a;b}$,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   946
$\QInl(a)$ and $\QInr(b)$ for $a$, $b\in\quniv(A)$.  In a typical codatatype
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   947
definition with set parameters $A_1$, \ldots, $A_k$, a suitable domain is
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   948
$\quniv(A_1\un\cdots\un A_k)$.  Details are published
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   949
elsewhere~\cite{paulson-final}.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   950
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   951
\subsection{The case analysis operator}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   952
The (co)datatype package automatically defines a case analysis operator,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   953
called {\tt$R$\_case}.  A mutually recursive definition still has only one
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   954
operator, whose name combines those of the recursive sets: it is called
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   955
{\tt$R_1$\_\ldots\_$R_n$\_case}.  The case operator is analogous to those
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   956
for products and sums.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   957
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   958
Datatype definitions employ standard products and sums, whose operators are
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   959
$\split$ and $\case$ and satisfy the equations
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   960
\begin{eqnarray*}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   961
  \split(f,\pair{x,y})  & = &  f(x,y) \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   962
  \case(f,g,\Inl(x))    & = &  f(x)   \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   963
  \case(f,g,\Inr(y))    & = &  g(y)
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   964
\end{eqnarray*}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   965
Suppose the datatype has $k$ constructors $\Con_1$, \ldots,~$\Con_k$.  Then
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   966
its case operator takes $k+1$ arguments and satisfies an equation for each
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   967
constructor:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   968
\[ R\hbox{\_case}(f_1,\ldots,f_k, {\tt Con}_i(\vec{x})) = f_i(\vec{x}),
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   969
    \qquad i = 1, \ldots, k
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   970
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   971
The case operator's definition takes advantage of Isabelle's representation of
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   972
syntax in the typed $\lambda$-calculus; it could readily be adapted to a
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   973
theorem prover for higher-order logic.  If $f$ and~$g$ have meta-type $i\To i$
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   974
then so do $\split(f)$ and $\case(f,g)$.  This works because $\split$ and
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   975
$\case$ operate on their last argument.  They are easily combined to make
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   976
complex case analysis operators.  For example, $\case(f,\case(g,h))$ performs
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   977
case analysis for $A+(B+C)$; let us verify one of the three equations:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   978
\[ \case(f,\case(g,h), \Inr(\Inl(b))) = \case(g,h,\Inl(b)) = g(b) \]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   979
Codatatype definitions are treated in precisely the same way.  They express
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   980
case operators using those for the variant products and sums, namely
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   981
$\qsplit$ and~$\qcase$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   982
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   983
\medskip
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   984
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   985
To see how constructors and the case analysis operator are defined, let us
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   986
examine some examples.  Further details are available
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   987
elsewhere~\cite{paulson-set-II}.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   988
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   989
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   990
\subsection{Example: lists and lazy lists}\label{lists-sec}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   991
Here is a declaration of the datatype of lists, as it might appear in a theory
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   992
file:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   993
\begin{ttbox} 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   994
consts  list :: i=>i
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   995
datatype "list(A)" = Nil | Cons ("a:A", "l: list(A)")
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   996
\end{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   997
And here is a declaration of the codatatype of lazy lists:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   998
\begin{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
   999
consts  llist :: i=>i
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1000
codatatype "llist(A)" = LNil | LCons ("a: A", "l: llist(A)")
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1001
\end{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1002
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1003
Each form of list has two constructors, one for the empty list and one for
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1004
adding an element to a list.  Each takes a parameter, defining the set of
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1005
lists over a given set~$A$.  Each is automatically given the appropriate
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1006
domain: $\univ(A)$ for $\lst(A)$ and $\quniv(A)$ for $\llist(A)$.  The default
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1007
can be overridden.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1008
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1009
\ifshort
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1010
Now $\lst(A)$ is a datatype and enjoys the usual induction rule.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1011
\else
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1012
Since $\lst(A)$ is a datatype, it enjoys a structural induction rule, {\tt
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1013
  list.induct}:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1014
\[ \infer{P(x)}{x\in\lst(A) & P(\Nil)
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1015
        & \infer*{P(\Cons(a,l))}{[a\in A & l\in\lst(A) & P(l)]_{a,l}} }
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1016
\] 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1017
Induction and freeness yield the law $l\not=\Cons(a,l)$.  To strengthen this,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1018
Isabelle/\textsc{zf} defines the rank of a set and proves that the standard
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1019
pairs and injections have greater rank than their components.  An immediate
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1020
consequence, which justifies structural recursion on lists
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1021
\cite[\S4.3]{paulson-set-II}, is
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1022
\[ \rank(l) < \rank(\Cons(a,l)). \]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1023
\par
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1024
\fi
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1025
But $\llist(A)$ is a codatatype and has no induction rule.  Instead it has
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1026
the coinduction rule shown in \S\ref{coind-sec}.  Since variant pairs and
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1027
injections are monotonic and need not have greater rank than their
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1028
components, fixedpoint operators can create cyclic constructions.  For
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1029
example, the definition
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1030
\[ \lconst(a) \equiv \lfp(\univ(a), \lambda l. \LCons(a,l)) \]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1031
yields $\lconst(a) = \LCons(a,\lconst(a))$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1032
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1033
\ifshort
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1034
\typeout{****SHORT VERSION}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1035
\typeout{****Omitting discussion of constructors!}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1036
\else
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1037
\medskip
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1038
It may be instructive to examine the definitions of the constructors and
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1039
case operator for $\lst(A)$.  The definitions for $\llist(A)$ are similar.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1040
The list constructors are defined as follows:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1041
\begin{eqnarray*}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1042
  \Nil       & \equiv & \Inl(\emptyset) \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1043
  \Cons(a,l) & \equiv & \Inr(\pair{a,l})
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1044
\end{eqnarray*}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1045
The operator $\lstcase$ performs case analysis on these two alternatives:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1046
\[ \lstcase(c,h) \equiv \case(\lambda u.c, \split(h)) \]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1047
Let us verify the two equations:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1048
\begin{eqnarray*}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1049
    \lstcase(c, h, \Nil) & = & 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1050
       \case(\lambda u.c, \split(h), \Inl(\emptyset)) \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1051
     & = & (\lambda u.c)(\emptyset) \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1052
     & = & c\\[1ex]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1053
    \lstcase(c, h, \Cons(x,y)) & = & 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1054
       \case(\lambda u.c, \split(h), \Inr(\pair{x,y})) \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1055
     & = & \split(h, \pair{x,y}) \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1056
     & = & h(x,y)
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1057
\end{eqnarray*} 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1058
\fi
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1059
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1060
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1061
\ifshort
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1062
\typeout{****Omitting mutual recursion example!}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1063
\else
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1064
\subsection{Example: mutual recursion}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1065
In mutually recursive trees and forests~\cite[\S4.5]{paulson-set-II}, trees
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1066
have the one constructor $\Tcons$, while forests have the two constructors
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1067
$\Fnil$ and~$\Fcons$:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1068
\begin{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1069
consts  tree, forest, tree_forest    :: i=>i
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1070
datatype "tree(A)"   = Tcons ("a: A",  "f: forest(A)")
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1071
and      "forest(A)" = Fnil  |  Fcons ("t: tree(A)",  "f: forest(A)")
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1072
\end{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1073
The three introduction rules define the mutual recursion.  The
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1074
distinguishing feature of this example is its two induction rules.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1075
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1076
The basic induction rule is called {\tt tree\_forest.induct}:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1077
\[ \infer{P(x)}{x\in\TF(A) & 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1078
     \infer*{P(\Tcons(a,f))}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1079
        {\left[\begin{array}{l} a\in A \\ 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1080
                                f\in\forest(A) \\ P(f)
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1081
               \end{array}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1082
         \right]_{a,f}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1083
     & P(\Fnil)
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1084
     & \infer*{P(\Fcons(t,f))}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1085
        {\left[\begin{array}{l} t\in\tree(A)   \\ P(t) \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1086
                                f\in\forest(A) \\ P(f)
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1087
                \end{array}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1088
         \right]_{t,f}} }
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1089
\] 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1090
This rule establishes a single predicate for $\TF(A)$, the union of the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1091
recursive sets.  Although such reasoning is sometimes useful
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1092
\cite[\S4.5]{paulson-set-II}, a proper mutual induction rule should establish
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1093
separate predicates for $\tree(A)$ and $\forest(A)$.  The package calls this
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1094
rule {\tt tree\_forest.mutual\_induct}.  Observe the usage of $P$ and $Q$ in
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1095
the induction hypotheses:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1096
\[ \infer{(\forall z. z\in\tree(A)\imp P(z)) \conj
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1097
          (\forall z. z\in\forest(A)\imp Q(z))}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1098
     {\infer*{P(\Tcons(a,f))}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1099
        {\left[\begin{array}{l} a\in A \\ 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1100
                                f\in\forest(A) \\ Q(f)
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1101
               \end{array}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1102
         \right]_{a,f}}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1103
     & Q(\Fnil)
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1104
     & \infer*{Q(\Fcons(t,f))}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1105
        {\left[\begin{array}{l} t\in\tree(A)   \\ P(t) \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1106
                                f\in\forest(A) \\ Q(f)
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1107
                \end{array}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1108
         \right]_{t,f}} }
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1109
\] 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1110
Elsewhere I describe how to define mutually recursive functions over trees and
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1111
forests \cite[\S4.5]{paulson-set-II}.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1112
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1113
Both forest constructors have the form $\Inr(\cdots)$,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1114
while the tree constructor has the form $\Inl(\cdots)$.  This pattern would
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1115
hold regardless of how many tree or forest constructors there were.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1116
\begin{eqnarray*}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1117
  \Tcons(a,l)  & \equiv & \Inl(\pair{a,l}) \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1118
  \Fnil        & \equiv & \Inr(\Inl(\emptyset)) \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1119
  \Fcons(a,l)  & \equiv & \Inr(\Inr(\pair{a,l}))
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1120
\end{eqnarray*} 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1121
There is only one case operator; it works on the union of the trees and
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1122
forests:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1123
\[ {\tt tree\_forest\_case}(f,c,g) \equiv 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1124
    \case(\split(f),\, \case(\lambda u.c, \split(g))) 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1125
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1126
\fi
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1127
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1128
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1129
\subsection{Example: a four-constructor datatype}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1130
A bigger datatype will illustrate some efficiency 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1131
refinements.  It has four constructors $\Con_0$, \ldots, $\Con_3$, with the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1132
corresponding arities.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1133
\begin{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1134
consts    data :: [i,i] => i
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1135
datatype  "data(A,B)" = Con0
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1136
                      | Con1 ("a: A")
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1137
                      | Con2 ("a: A", "b: B")
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1138
                      | Con3 ("a: A", "b: B", "d: data(A,B)")
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1139
\end{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1140
Because this datatype has two set parameters, $A$ and~$B$, the package
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1141
automatically supplies $\univ(A\un B)$ as its domain.  The structural
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1142
induction rule has four minor premises, one per constructor, and only the last
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1143
has an induction hypothesis.  (Details are left to the reader.)
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1144
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1145
The constructors are defined by the equations
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1146
\begin{eqnarray*}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1147
  \Con_0         & \equiv & \Inl(\Inl(\emptyset)) \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1148
  \Con_1(a)      & \equiv & \Inl(\Inr(a)) \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1149
  \Con_2(a,b)    & \equiv & \Inr(\Inl(\pair{a,b})) \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1150
  \Con_3(a,b,c)  & \equiv & \Inr(\Inr(\pair{a,b,c})).
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1151
\end{eqnarray*} 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1152
The case analysis operator is
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1153
\[ {\tt data\_case}(f_0,f_1,f_2,f_3) \equiv 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1154
    \case(\begin{array}[t]{@{}l}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1155
          \case(\lambda u.f_0,\; f_1),\, \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1156
          \case(\split(f_2),\; \split(\lambda v.\split(f_3(v)))) )
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1157
   \end{array} 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1158
\]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1159
This may look cryptic, but the case equations are trivial to verify.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1160
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1161
In the constructor definitions, the injections are balanced.  A more naive
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1162
approach is to define $\Con_3(a,b,c)$ as $\Inr(\Inr(\Inr(\pair{a,b,c})))$;
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1163
instead, each constructor has two injections.  The difference here is small.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1164
But the \textsc{zf} examples include a 60-element enumeration type, where each
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1165
constructor has 5 or~6 injections.  The naive approach would require 1 to~59
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1166
injections; the definitions would be quadratic in size.  It is like the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1167
advantage of binary notation over unary.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1168
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1169
The result structure contains the case operator and constructor definitions as
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1170
the theorem list \verb|con_defs|. It contains the case equations, such as 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1171
\[ {\tt data\_case}(f_0,f_1,f_2,f_3,\Con_3(a,b,c)) = f_3(a,b,c), \]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1172
as the theorem list \verb|case_eqns|.  There is one equation per constructor.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1173
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1174
\subsection{Proving freeness theorems}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1175
There are two kinds of freeness theorems:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1176
\begin{itemize}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1177
\item \defn{injectiveness} theorems, such as
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1178
\[ \Con_2(a,b) = \Con_2(a',b') \bimp a=a' \conj b=b' \]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1179
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1180
\item \defn{distinctness} theorems, such as
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1181
\[ \Con_1(a) \not= \Con_2(a',b')  \]
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1182
\end{itemize}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1183
Since the number of such theorems is quadratic in the number of constructors,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1184
the package does not attempt to prove them all.  Instead it returns tools for
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1185
proving desired theorems --- either manually or during
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1186
simplification or classical reasoning.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1187
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1188
The theorem list \verb|free_iffs| enables the simplifier to perform freeness
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1189
reasoning.  This works by incremental unfolding of constructors that appear in
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1190
equations.  The theorem list contains logical equivalences such as
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1191
\begin{eqnarray*}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1192
  \Con_0=c      & \bimp &  c=\Inl(\Inl(\emptyset))     \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1193
  \Con_1(a)=c   & \bimp &  c=\Inl(\Inr(a))             \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1194
                & \vdots &                             \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1195
  \Inl(a)=\Inl(b)   & \bimp &  a=b                     \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1196
  \Inl(a)=\Inr(b)   & \bimp &  {\tt False}             \\
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1197
  \pair{a,b} = \pair{a',b'} & \bimp & a=a' \conj b=b'
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1198
\end{eqnarray*}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1199
For example, these rewrite $\Con_1(a)=\Con_1(b)$ to $a=b$ in four steps.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1200
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1201
The theorem list \verb|free_SEs| enables the classical
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1202
reasoner to perform similar replacements.  It consists of elimination rules
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1203
to replace $\Con_0=c$ by $c=\Inl(\Inl(\emptyset))$ and so forth, in the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1204
assumptions.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1205
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1206
Such incremental unfolding combines freeness reasoning with other proof
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1207
steps.  It has the unfortunate side-effect of unfolding definitions of
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1208
constructors in contexts such as $\exists x.\Con_1(a)=x$, where they should
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1209
be left alone.  Calling the Isabelle tactic {\tt fold\_tac con\_defs}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1210
restores the defined constants.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1211
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1212
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1213
\section{Related work}\label{related}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1214
The use of least fixedpoints to express inductive definitions seems
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1215
obvious.  Why, then, has this technique so seldom been implemented?
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1216
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1217
Most automated logics can only express inductive definitions by asserting
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1218
axioms.  Little would be left of Boyer and Moore's logic~\cite{bm79} if their
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1219
shell principle were removed.  With \textsc{alf} the situation is more
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1220
complex; earlier versions of Martin-L\"of's type theory could (using
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1221
wellordering types) express datatype definitions, but the version underlying
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1222
\textsc{alf} requires new rules for each definition~\cite{dybjer91}.  With Coq
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1223
the situation is subtler still; its underlying Calculus of Constructions can
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1224
express inductive definitions~\cite{huet88}, but cannot quite handle datatype
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1225
definitions~\cite{paulin-tlca}.  It seems that researchers tried hard to
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1226
circumvent these problems before finally extending the Calculus with rule
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1227
schemes for strictly positive operators.  Recently Gim{\'e}nez has extended
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1228
the Calculus of Constructions with inductive and coinductive
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1229
types~\cite{gimenez-codifying}, with mechanized support in Coq.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1230
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1231
Higher-order logic can express inductive definitions through quantification
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1232
over unary predicates.  The following formula expresses that~$i$ belongs to the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1233
least set containing~0 and closed under~$\succ$:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1234
\[ \forall P. P(0)\conj (\forall x.P(x)\imp P(\succ(x))) \imp P(i) \] 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1235
This technique can be used to prove the Knaster-Tarski theorem, which (in its
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1236
general form) is little used in the Cambridge \textsc{hol} system.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1237
Melham~\cite{melham89} describes the development.  The natural numbers are
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1238
defined as shown above, but lists are defined as functions over the natural
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1239
numbers.  Unlabelled trees are defined using G\"odel numbering; a labelled
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1240
tree consists of an unlabelled tree paired with a list of labels.  Melham's
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1241
datatype package expresses the user's datatypes in terms of labelled trees.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1242
It has been highly successful, but a fixedpoint approach might have yielded
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1243
greater power with less effort.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1244
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1245
Elsa Gunter~\cite{gunter-trees} reports an ongoing project to generalize the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1246
Cambridge \textsc{hol} system with mutual recursion and infinitely-branching
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1247
trees.  She retains many features of Melham's approach.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1248
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1249
Melham's inductive definition package~\cite{camilleri92} also uses
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1250
quantification over predicates.  But instead of formalizing the notion of
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1251
monotone function, it requires definitions to consist of finitary rules, a
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1252
syntactic form that excludes many monotone inductive definitions.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1253
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1254
\textsc{pvs}~\cite{pvs-language} is another proof assistant based on
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1255
higher-order logic.  It supports both inductive definitions and datatypes,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1256
apparently by asserting axioms.  Datatypes may not be iterated in general, but
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1257
may use recursion over the built-in $\lst$ type.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1258
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1259
The earliest use of least fixedpoints is probably Robin Milner's.  Brian
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1260
Monahan extended this package considerably~\cite{monahan84}, as did I in
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1261
unpublished work.\footnote{The datatype package described in my \textsc{lcf}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1262
  book~\cite{paulson87} does {\it not\/} make definitions, but merely asserts
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1263
  axioms.} \textsc{lcf} is a first-order logic of domain theory; the relevant
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1264
fixedpoint theorem is not Knaster-Tarski but concerns fixedpoints of
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1265
continuous functions over domains.  \textsc{lcf} is too weak to express
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1266
recursive predicates.  The Isabelle package might be the first to be based on
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1267
the Knaster-Tarski theorem.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1268
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1269
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1270
\section{Conclusions and future work}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1271
Higher-order logic and set theory are both powerful enough to express
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1272
inductive definitions.  A growing number of theorem provers implement one
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1273
of these~\cite{IMPS,saaltink-fme}.  The easiest sort of inductive
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1274
definition package to write is one that asserts new axioms, not one that
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1275
makes definitions and proves theorems about them.  But asserting axioms
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1276
could introduce unsoundness.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1277
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1278
The fixedpoint approach makes it fairly easy to implement a package for
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1279
(co)in\-duc\-tive definitions that does not assert axioms.  It is efficient:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1280
it processes most definitions in seconds and even a 60-constructor datatype
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1281
requires only a few minutes.  It is also simple: The first working version took
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1282
under a week to code, consisting of under 1100 lines (35K bytes) of Standard
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1283
\textsc{ml}.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1284
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1285
In set theory, care is needed to ensure that the inductive definition yields
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1286
a set (rather than a proper class).  This problem is inherent to set theory,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1287
whether or not the Knaster-Tarski theorem is employed.  We must exhibit a
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1288
bounding set (called a domain above).  For inductive definitions, this is
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1289
often trivial.  For datatype definitions, I have had to formalize much set
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1290
theory.  To justify infinitely-branching datatype definitions, I have had to
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1291
develop a theory of cardinal arithmetic~\cite{paulson-gr}, such as the theorem
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1292
that if $\kappa$ is an infinite cardinal and $|X(\alpha)| \le \kappa$ for all
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1293
$\alpha<\kappa$ then $|\union\sb{\alpha<\kappa} X(\alpha)| \le \kappa$.  
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1294
The need for such efforts is not a drawback of the fixedpoint approach, for
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1295
the alternative is to take such definitions on faith.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1296
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1297
Care is also needed to ensure that the greatest fixedpoint really yields a
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1298
coinductive definition.  In set theory, standard pairs admit only well-founded
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1299
constructions.  Aczel's anti-foundation axiom~\cite{aczel88} could be used to
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1300
get non-well-founded objects, but it does not seem easy to mechanize.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1301
Isabelle/\textsc{zf} instead uses a variant notion of ordered pairing, which
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1302
can be generalized to a variant notion of function.  Elsewhere I have
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1303
proved that this simple approach works (yielding final coalgebras) for a broad
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1304
class of definitions~\cite{paulson-final}.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1305
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1306
Several large studies make heavy use of inductive definitions.  L\"otzbeyer
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1307
and Sandner have formalized two chapters of a semantics book~\cite{winskel93},
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1308
proving the equivalence between the operational and denotational semantics of
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1309
a simple imperative language.  A single theory file contains three datatype
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1310
definitions (of arithmetic expressions, boolean expressions and commands) and
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1311
three inductive definitions (the corresponding operational rules).  Using
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1312
different techniques, Nipkow~\cite{nipkow-CR} and Rasmussen~\cite{rasmussen95}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1313
have both proved the Church-Rosser theorem; inductive definitions specify
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1314
several reduction relations on $\lambda$-terms.  Recently, I have applied
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1315
inductive definitions to the analysis of cryptographic
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1316
protocols~\cite{paulson-markt}. 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1317
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1318
To demonstrate coinductive definitions, Frost~\cite{frost95} has proved the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1319
consistency of the dynamic and static semantics for a small functional
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1320
language.  The example is due to Milner and Tofte~\cite{milner-coind}.  It
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1321
concerns an extended correspondence relation, which is defined coinductively.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1322
A codatatype definition specifies values and value environments in mutual
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1323
recursion.  Non-well-founded values represent recursive functions.  Value
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1324
environments are variant functions from variables into values.  This one key
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1325
definition uses most of the package's novel features.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1326
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1327
The approach is not restricted to set theory.  It should be suitable for any
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1328
logic that has some notion of set and the Knaster-Tarski theorem.  I have
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1329
ported the (co)inductive definition package from Isabelle/\textsc{zf} to
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1330
Isabelle/\textsc{hol} (higher-order logic).  V\"olker~\cite{voelker95}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1331
is investigating how to port the (co)datatype package.  \textsc{hol}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1332
represents sets by unary predicates; defining the corresponding types may
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1333
cause complications.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1334
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1335
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1336
\begin{footnotesize}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1337
\bibliographystyle{springer}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1338
\bibliography{string-abbrv,atp,theory,funprog,isabelle,crossref}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1339
\end{footnotesize}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1340
%%%%%\doendnotes
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1341
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1342
\ifshort\typeout{****Omitting appendices}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1343
\else
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1344
\newpage
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1345
\appendix
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1346
\section{Inductive and coinductive definitions: users guide}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1347
A theory file may contain any number of inductive and coinductive
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1348
definitions.  They may be intermixed with other declarations; in
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1349
particular, the (co)inductive sets \defn{must} be declared separately as
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1350
constants, and may have mixfix syntax or be subject to syntax translations.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1351
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1352
The syntax is rather complicated.  Please consult the examples above and the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1353
theory files on the \textsc{zf} source directory.  
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1354
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1355
Each (co)inductive definition adds definitions to the theory and also proves
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1356
some theorems.  Each definition creates an \textsc{ml} structure, which is a
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1357
substructure of the main theory structure.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1358
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1359
Inductive and datatype definitions can take up considerable storage.  The
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1360
introduction rules are replicated in slightly different forms as fixedpoint
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1361
definitions, elimination rules and induction rules.  L\"otzbeyer and Sandner's
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1362
six definitions occupy over 600K in total.  Defining the 60-constructor
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1363
datatype requires nearly 560K\@.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1364
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1365
\subsection{The result structure}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1366
Many of the result structure's components have been discussed
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1367
in~\S\ref{basic-sec}; others are self-explanatory.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1368
\begin{description}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1369
\item[\tt thy] is the new theory containing the recursive sets.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1370
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1371
\item[\tt defs] is the list of definitions of the recursive sets.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1372
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1373
\item[\tt bnd\_mono] is a monotonicity theorem for the fixedpoint operator.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1374
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1375
\item[\tt dom\_subset] is a theorem stating inclusion in the domain.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1376
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1377
\item[\tt intrs] is the list of introduction rules, now proved as theorems, for
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1378
the recursive sets.  The rules are also available individually, using the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1379
names given them in the theory file. 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1380
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1381
\item[\tt elim] is the elimination rule.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1382
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1383
\item[\tt mk\_cases] is a function to create simplified instances of {\tt
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1384
elim}, using freeness reasoning on some underlying datatype.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1385
\end{description}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1386
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1387
For an inductive definition, the result structure contains two induction
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1388
rules, {\tt induct} and \verb|mutual_induct|.  (To save storage, the latter
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1389
rule is just {\tt True} unless more than one set is being defined.)  For a
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1390
coinductive definition, it contains the rule \verb|coinduct|.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1391
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1392
Figure~\ref{def-result-fig} summarizes the two result signatures,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1393
specifying the types of all these components.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1394
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1395
\begin{figure}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1396
\begin{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1397
sig
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1398
val thy          : theory
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1399
val defs         : thm list
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1400
val bnd_mono     : thm
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1401
val dom_subset   : thm
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1402
val intrs        : thm list
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1403
val elim         : thm
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1404
val mk_cases     : thm list -> string -> thm
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1405
{\it(Inductive definitions only)} 
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1406
val induct       : thm
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1407
val mutual_induct: thm
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1408
{\it(Coinductive definitions only)}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1409
val coinduct    : thm
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1410
end
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1411
\end{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1412
\hrule
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1413
\caption{The result of a (co)inductive definition} \label{def-result-fig}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1414
\end{figure}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1415
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1416
\subsection{The syntax of a (co)inductive definition}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1417
An inductive definition has the form
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1418
\begin{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1419
inductive
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1420
  domains    {\it domain declarations}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1421
  intrs      {\it introduction rules}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1422
  monos      {\it monotonicity theorems}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1423
  con_defs   {\it constructor definitions}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1424
  type_intrs {\it introduction rules for type-checking}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1425
  type_elims {\it elimination rules for type-checking}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1426
\end{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1427
A coinductive definition is identical, but starts with the keyword
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1428
{\tt coinductive}.  
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1429
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1430
The {\tt monos}, {\tt con\_defs}, {\tt type\_intrs} and {\tt type\_elims}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1431
sections are optional.  If present, each is specified as a string, which
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1432
must be a valid \textsc{ml} expression of type {\tt thm list}.  It is simply
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1433
inserted into the {\tt .thy.ML} file; if it is ill-formed, it will trigger
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1434
\textsc{ml} error messages.  You can then inspect the file on your directory.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1435
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1436
\begin{description}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1437
\item[\it domain declarations] consist of one or more items of the form
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1438
  {\it string\/}~{\tt <=}~{\it string}, associating each recursive set with
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1439
  its domain.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1440
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1441
\item[\it introduction rules] specify one or more introduction rules in
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1442
  the form {\it ident\/}~{\it string}, where the identifier gives the name of
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1443
  the rule in the result structure.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1444
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1445
\item[\it monotonicity theorems] are required for each operator applied to
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1446
  a recursive set in the introduction rules.  There \defn{must} be a theorem
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1447
  of the form $A\sbs B\Imp M(A)\sbs M(B)$, for each premise $t\in M(R_i)$
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1448
  in an introduction rule!
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1449
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1450
\item[\it constructor definitions] contain definitions of constants
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1451
  appearing in the introduction rules.  The (co)datatype package supplies
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1452
  the constructors' definitions here.  Most (co)inductive definitions omit
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1453
  this section; one exception is the primitive recursive functions example
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1454
  (\S\ref{primrec-sec}).
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1455
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1456
\item[\it type\_intrs] consists of introduction rules for type-checking the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1457
  definition, as discussed in~\S\ref{basic-sec}.  They are applied using
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1458
  depth-first search; you can trace the proof by setting
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1459
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1460
  \verb|trace_DEPTH_FIRST := true|.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1461
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1462
\item[\it type\_elims] consists of elimination rules for type-checking the
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1463
  definition.  They are presumed to be safe and are applied as much as
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1464
  possible, prior to the {\tt type\_intrs} search.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1465
\end{description}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1466
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1467
The package has a few notable restrictions:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1468
\begin{itemize}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1469
\item The theory must separately declare the recursive sets as
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1470
  constants.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1471
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1472
\item The names of the recursive sets must be identifiers, not infix
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1473
operators.  
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1474
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1475
\item Side-conditions must not be conjunctions.  However, an introduction rule
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1476
may contain any number of side-conditions.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1477
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1478
\item Side-conditions of the form $x=t$, where the variable~$x$ does not
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1479
  occur in~$t$, will be substituted through the rule \verb|mutual_induct|.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1480
\end{itemize}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1481
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1482
Isabelle/\textsc{hol} uses a simplified syntax for inductive definitions,
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1483
thanks to type-checking.  There are no \texttt{domains}, \texttt{type\_intrs}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1484
or \texttt{type\_elims} parts.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1485
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1486
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1487
\section{Datatype and codatatype definitions: users guide}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1488
This section explains how to include (co)datatype declarations in a theory
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1489
file.  Please include {\tt Datatype} as a parent theory; this makes available
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1490
the definitions of $\univ$ and $\quniv$.
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1491
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1492
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1493
\subsection{The result structure}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1494
The result structure extends that of (co)inductive definitions
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1495
(Figure~\ref{def-result-fig}) with several additional items:
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1496
\begin{ttbox}
78fa85d44e68 moved here from ..
wenzelm
parents:
diff changeset
  1497
val con_defs  : thm list