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