diff src/Coinductive.v @ 351:bb1a470c1757

Well-founded recursion
author Adam Chlipala <adam@chlipala.net>
date Wed, 26 Oct 2011 15:12:21 -0400
parents de7db21a016c
children dc99dffdf20a
line wrap: on
line diff
--- a/src/Coinductive.v	Wed Oct 26 11:19:52 2011 -0400
+++ b/src/Coinductive.v	Wed Oct 26 15:12:21 2011 -0400
@@ -41,9 +41,9 @@
 (** Let us begin with the most basic type of infinite data, %\textit{%#<i>#streams#</i>#%}%, or lazy lists.%\index{Vernacular commands!CoInductive}% *)
 
 Section stream.
-  Variable A : Set.
+  Variable A : Type.
 
-  CoInductive stream : Set :=
+  CoInductive stream : Type :=
   | Cons : A -> stream -> stream.
 End stream.
 
@@ -119,7 +119,7 @@
 Some familiar functions are easy to write in co-recursive fashion. *)
 
 Section map.
-  Variables A B : Set.
+  Variables A B : Type.
   Variable f : A -> B.
 
   CoFixpoint map (s : stream A) : stream B :=
@@ -133,7 +133,7 @@
    The implications of the condition can be subtle.  To illustrate how, we start off with another co-recursive function definition that %\textit{%#<i>#is#</i>#%}% legal.  The function [interleave] takes two streams and produces a new stream that alternates between their elements. *)
 
 Section interleave.
-  Variable A : Set.
+  Variable A : Type.
 
   CoFixpoint interleave (s1 s2 : stream A) : stream A :=
     match s1, s2 with
@@ -144,7 +144,7 @@
 (** Now say we want to write a weird stuttering version of [map] that repeats elements in a particular way, based on interleaving. *)
 
 Section map'.
-  Variables A B : Set.
+  Variables A B : Type.
   Variable f : A -> B.
 (* begin thide *)
   (** [[
@@ -210,7 +210,7 @@
 We are ready for our first %\index{co-inductive predicates}%co-inductive predicate. *)
 
 Section stream_eq.
-  Variable A : Set.
+  Variable A : Type.
 
   CoInductive stream_eq : stream A -> stream A -> Prop :=
   | Stream_eq : forall h t1 t2,
@@ -376,7 +376,7 @@
 (** Now we enter a section for the co-induction principle, based on %\index{Park's principle}%Park's principle as introduced in a tutorial by Gim%\'%enez%~\cite{IT}%. *)
 
 Section stream_eq_coind.
-  Variable A : Set.
+  Variable A : Type.
   Variable R : stream A -> stream A -> Prop.
   (** This relation generalizes the theorem we want to prove, characterizinge exactly which two arguments to [stream_eq] we want to consider. *)
 
@@ -408,7 +408,7 @@
    Compared to the inductive proofs that we are used to, it still seems unsatisfactory that we had to write out a choice of [R] in the last proof.  An alternate is to capture a common pattern of co-recursion in a more specialized co-induction principle.  For the current example, that pattern is: prove [stream_eq s1 s2] where [s1] and [s2] are defined as their own tails. *)
 
 Section stream_eq_loop.
-  Variable A : Set.
+  Variable A : Type.
   Variables s1 s2 : stream A.
 
   Hypothesis Cons_case_hd : hd s1 = hd s2.
@@ -492,7 +492,7 @@
 (** As in the case of [ones_eq'], we may be unsatisfied that we needed to write down a choice of [R] that seems to duplicate information already present in a lemma statement.  We can facilitate a simpler proof by defining a co-induction principle specialized to goals that begin with single universal quantifiers, and the strategy can be extended in a straightforward way to principles for other counts of quantifiers.  (Our [stream_eq_loop] principle is effectively the instantiation of this technique to zero quantifiers.) *)
 
 Section stream_eq_onequant.
-  Variables A B : Set.
+  Variables A B : Type.
   (** We have the types [A], the domain of the one quantifier; and [B], the type of data found in the streams. *)
 
   Variables f g : A -> stream B.