Chapter 4 Calculus of Inductive Constructions
The underlying formal language of Coq is a Calculus of
Constructions with Inductive Definitions. It is presented in
this chapter.
For Coq version V7, this Calculus was known as the
Calculus of (Co)Inductive Constructions (Cic in short).
The underlying calculus of Coq version V8.0 and up is a weaker
calculus where the sort Set satisfies predicative rules.
We call this calculus the
Predicative Calculus of (Co)Inductive
Constructions (pCic in short).
In section 4.7 we give the extrarules for Cic. A
compiling option of Coq allows to typecheck theories in this
extended system.
In pCic all objects have a type. There are types for functions (or
programs), there are atomic types (especially datatypes)... but also
types for proofs and types for the types themselves.
Especially, any object handled in the formalism must belong to a
type. For instance, the statement ``for all x, P'' is not
allowed in type theory; you must say instead: ``for all x
belonging to T, P''. The expression ``x belonging to T'' is
written ``x:T''. One also says: ``x has type T''.
The terms of pCic are detailed in section 4.1.
In pCic there is an internal reduction mechanism. In particular, it
allows to decide if two programs are intentionally equal (one
says convertible). Convertibility is presented in section
4.3.
The remaining sections are concerned with the typechecking of terms.
The beginner can skip them.
The reader seeking a background on the Calculus of Inductive
Constructions may read several papers. Giménez [61] provides
an introduction to inductive and coinductive definitions in Coq. In
their book [13], Bertot and Castéran give a precise
description of the pCic based on numerous practical examples.
Barras [9], Werner [117] and
PaulinMohring [104] are the most recent theses dealing with
Inductive Definitions. CoquandHuet [27, 28, 29]
introduces the Calculus of Constructions. CoquandPaulin [30]
extended this calculus to inductive definitions. The pCic is a
formulation of type theory including the possibility of inductive
constructions, Barendregt [6] studies the modern form of type
theory.
4.1 The terms
In most type theories, one usually makes a syntactic distinction
between types and terms. This is not the case for pCic which defines
both types and terms in the same syntactical structure. This is
because the typetheory itself forces terms and types to be defined in
a mutual recursive way and also because similar constructions can be
applied to both terms and types and consequently can share the same
syntactic structure.
Consider for instance the > constructor and assume nat is the
type of natural numbers. Then > is used both to denote
nat>nat which is the type of functions from nat to nat, and
to denote nat > Prop which is the type of unary predicates over
the natural numbers. Consider abstraction which builds functions. It
serves to build ``ordinary'' functions as fun x:nat => (mult x x) (assuming mult is already defined) but may build also
predicates over the natural numbers. For instance fun x:nat =>
(x=x) will
represent a predicate P, informally written in mathematics
P(x)same as x=x. If P has type nat > Prop, (P x) is a
proposition, furthermore forall x:nat,(P x) will represent the type of
functions which associate to each natural number n an object of
type (P n) and consequently represent proofs of the formula
``for all x.P(x)''.
Types are seen as terms of the language and then should belong to
another type. The type of a type is always a constant of the language
called a sort.
The two basic sorts in the language of pCic are Set and Prop.
The sort Prop intends to be the type of logical propositions. If
M is a logical proposition then it denotes a class, namely the class
of terms representing proofs of M. An object m belonging to M
witnesses the fact that M is true. An object of type Prop is
called a proposition.
The sort Set intends to be the type of specifications. This includes
programs and the usual sets such as booleans, naturals, lists
etc.
These sorts themselves can be manipulated as ordinary terms.
Consequently sorts also should be given a type. Because assuming
simply that Set has type Set leads to an inconsistent theory, we
have infinitely many sorts in the language of pCic. These are, in
addition to Set and Prop a hierarchy of universes Type(i)
for any integer i. We call S the set of sorts
which is defined by:
S same as {Prop,Set,Type(i) i in N}
The sorts enjoy the following properties: Prop:Type(0), Set:Type(0) and
Type(i):Type(i+1).
The user will never mention explicitly the index i when referring to
the universe Type(i). One only writes Type. The
system itself generates for each instance of Type a new
index for the universe and checks that the constraints between these
indexes can be solved. From the user point of view we consequently
have Type :Type.
We shall make precise in the typing rules the constraints between the
indexes.
Besides the sorts, the language also contains constants denoting
objects in the environment. These constants may denote previously
defined objects but also objects related to inductive definitions
(either the type itself or one of its constructors or destructors).
Remark. In other presentations of pCic,
the inductive objects are not seen as
external declarations but as firstclass terms. Usually the
definitions are also completely ignored. This is a nice theoretical
point of view but not so practical. An inductive definition is
specified by a possibly huge set of declarations, clearly we want to
share this specification among the various inductive objects and not
to duplicate it. So the specification should exist somewhere and the
various objects should refer to it. We choose one more level of
indirection where the objects are just represented as constants and
the environment gives the information on the kind of object the
constant refers to.
Our inductive objects will be manipulated as constants declared in the
environment. This roughly corresponds to the way they are actually
implemented in the Coq system. It is simple to map this presentation
in a theory where inductive objects are represented by terms.
Terms are built from variables, global names, constructors,
abstraction, application, local declarations bindings (``letin''
expressions) and product.
From a syntactic point of view, types cannot be distingued from terms,
except that they cannot start by an abstraction, and that if a term is
a sort or a product, it should be a type.
More precisely the language of the Calculus of Inductive
Constructions is built from the following rules:

the sorts Set, Prop, Type are terms.
 names for global constants of the environment are terms.
 variables are terms.
 if x is a variable and T, U are terms then for all x:T,U
(forall x:T,U in Coq concrete syntax) is a term. If x
occurs in U, for all x:T,U reads as ``for all x of type T,
U''. As U depends on x, one says that for all x:T,U is a
dependent product. If x doesn't occurs in U then
for all x:T,U reads as ``if T then U''. A non dependent
product can be written: T > U.
 if x is a variable and T, U are terms then lambda x:T , U
(fun x:T=> U in Coq concrete syntax) is a term. This is a
notation for the lambdaabstraction of
lambdacalculus
[8]. The term lambda x:T , U is a function which maps
elements of T to U.
 if T and U are terms then (T U) is a term
(T U in Coq concrete syntax). The term (T
U) reads as ``T applied to U''.
 if x is a variable, and T, U are terms then
let x:=T in U is a
term which denotes the term U where the variable x is locally
bound to T. This stands for the common ``letin'' construction of
functional programs such as ML or Scheme.
Notations.
Application associates to the left such that
(t t_{1}... t_{n}) represents (... (t t_{1})... t_{n}). The
products and arrows associate to the right such that for all x:A,B> C>
D represents for all x:A,(B> (C> D)). One uses sometimes
for all x y:A,B or
lambda x y:A, B to denote the abstraction or product of several variables
of the same type. The equivalent formulation is for all x:A, for all y:A,B or
lambda x:A , lambda y:A , B
Free variables.
The notion of free variables is defined as usual. In the expressions
lambda x:T, U and for all x:T, U the occurrences of x in U
are bound. They are represented by de Bruijn indexes in the internal
structure of terms.
Substitution.
The notion of substituting a term t to free occurrences of a
variable x in a term u is defined as usual. The resulting term
is written u{x/t}.
4.2 Typed terms
As objects of type theory, terms are subjected to type
discipline. The well typing of a term depends on an environment which
consists in a global environment (see below) and a local context.
Local context.
A local context (or shortly context) is an ordered list of
declarations of variables. The declaration of some variable x is
either an assumption, written x:T (T is a type) or a definition,
written x:=t:T. We use brackets to write contexts. A
typical example is [x:T;y:=u:U;z:V]. Notice that the variables
declared in a context must be distinct. If Gamma declares some x,
we write x inGamma. By writing (x:T)inGamma we mean that
either x:T is an assumption in Gamma or that there exists some t such
that x:=t:T is a definition in Gamma. If Gamma defines some
x:=t:T, we also write (x:=t:T)inGamma. Contexts must be
themselves well formed. For the rest of the chapter, the
notation Gamma::(y:T) (resp Gamma::(y:=t:T)) denotes the context
Gamma enriched with the declaration y:T (resp y:=t:T). The
notation [] denotes the empty context.
We define the inclusion of two contexts Gamma and Delta (written
as Gamma included in Delta) as the property, for all variable x,
type T and term t, if (x:T) in Gamma then (x:T)in Delta
and if (x:=t:T) in Gamma then (x:=t:T)in Delta.
A variable x is said to be free in Gamma if Gamma contains a
declaration y:T such that x is free in T.
Environment.
Because we are manipulating global declarations (constants and global
assumptions), we also need to consider a global environment E.
An environment is an ordered list of declarations of global
names. Declarations are either assumptions or ``standard''
definitions, that is abbreviations for wellformed terms
but also definitions of inductive objects. In the latter
case, an object in the environment will define one or more constants
(that is types and constructors, see section 4.5).
An assumption will be represented in the environment as
Assum(Gamma)(c:T) which means that c is assumed of some type T
welldefined in some context Gamma. An (ordinary) definition will
be represented in the environment as Def(Gamma)(c:=t:T) which means
that c is a constant which is valid in some context Gamma whose
value is t and type is T.
The rules for inductive definitions (see section
4.5) have to be considered as assumption
rules to which the following definitions apply: if the name c is
declared in E, we write c in E and if c:T or c:=t:T is
declared in E, we write (c : T) in E.
Typing rules.
In the following, we assume E is a valid environment wrt to
inductive definitions. We define simultaneously two
judgments. The first one E[Gamma]  t : T means the term t is welltyped
and has type T in the environment E and context Gamma. The
second judgment WF(E)[Gamma] means that the environment E is
wellformed and the context Gamma is a valid context in this
environment. It also means a third property which makes sure that any
constant in E was defined in an environment which is included in
Gamma
^{1}.
A term t is well typed in an environment E iff there exists a
context Gamma and a term T such that the judgment E[Gamma]  t : T can
be derived from the following rules.

WE

WF([])[[]]
 WS

E[Gamma]  T : s sin S x not in Gamma 

WF(E)[Gamma::(x:T)] 


E[Gamma]  t : T x not in Gamma 

WF(E)[Gamma::(x:=t:T)] 

 Def

E[Gamma]  t : T c not in Eunion Gamma 

WF(E;Def(Gamma)(c:=t:T))[Gamma] 
 Ax

WF(E)[Gamma] 

E[Gamma]  Prop : Type(p) 


WF(E)[Gamma] 

E[Gamma]  Set : Type(q) 

WF(E)[Gamma] i<j 

E[Gamma]  Type(i) : Type(j) 
 Var

WF(E)[Gamma] (x:T)inGamma or (x:=t:T)inGamma for some t 

E[Gamma]  x : T 
 Const

WF(E)[Gamma] (c:T) in E 

E[Gamma]  c : T 
 Prod

E[Gamma]  T : s s in S
E[Gamma::(x:T)]  U : Prop 

E[Gamma]  for all x:T,U : Prop 
E[Gamma]  T : s sin{Prop, Set}
E[Gamma::(x:T)]  U : Set 

E[Gamma]  for all x:T,U : Set 
E[Gamma]  T : Type(i) i<= k
E[Gamma::(x:T)]  U : Type(j) j <= k 

E[Gamma]  for all x:T,U : Type(k) 
 Lam

E[Gamma]  for all x:T,U : s E[Gamma::(x:T)]  t : U 

E[Gamma]  lambda x:T, t : for all x:T, U 
 App

E[Gamma]  t : for all x:U,T E[Gamma]  u : U 

E[Gamma]  (t u) : T{x/u} 
 Let

E[Gamma]  t : T E[Gamma::(x:=t:T)]  u : U 

E[Gamma]  let x:=t in u : U{x/t} 
Remark: We may have let x:=t in u
welltyped without having ((lambda x:T, u) t) welltyped (where
T is a type of t). This is because the value t associated to x
may be used in a conversion rule (see section 4.3).
4.3 Conversion rules
betareduction.
We want to be able to identify some terms as we can identify the
application of a function to a given argument with its result. For
instance the identity function over a given type T can be written
lambda x:T, x. In any environment E and context Gamma, we want to identify any object a (of type T) with the
application ((lambda x:T, x) a). We define for this a reduction (or a
conversion) rule we call beta:
E[Gamma]  ((lambda x:T,
t) u) >_{beta} t{x/u}
We say that t{x/u} is the betacontraction of
((lambda x:T, t) u) and, conversely, that ((lambda x:T, t) u)
is the betaexpansion of t{x/u}.
According to betareduction, terms of the Calculus of
Inductive Constructions enjoy some fundamental properties such as
confluence, strong normalization, subject reduction. These results are
theoretically of great importance but we will not detail them here and
refer the interested reader to [21].
iotareduction.
A specific conversion rule is associated to the inductive objects in
the environment. We shall give later on (section 4.5.4) the
precise rules but it just says that a destructor applied to an object
built from a constructor behaves as expected. This reduction is
called iotareduction and is more precisely studied in
[103, 117].
deltareduction.
We may have defined variables in contexts or constants in the global
environment. It is legal to identify such a reference with its value,
that is to expand (or unfold) it into its value. This
reduction is called deltareduction and shows as follows.
E[Gamma]  x >_{delta} t if (x:=t:T)inGamma E[Gamma]  c >_{delta} t if (c:=t:T)in E
zetareduction.
Coq allows also to remove local definitions occurring in terms by
replacing the defined variable by its value. The declaration being
destroyed, this reduction differs from deltareduction. It is
called zetareduction and shows as follows.
E[Gamma]  let x:=u in t >_{zeta} t{x/u}
Convertibility.
Let us write E[Gamma]  t > u for the contextual closure of the relation t reduces to u in the environment E and context Gamma with one of the previous reduction beta, iota, delta or zeta.
We say that two terms t_{1} and t_{2} are convertible (or equivalent) in the environment E and context Gamma iff there exists a term u such that E[Gamma]  t_{1} > ... > u
and E[Gamma]  t_{2} > ... > u.
We then write E[Gamma]  t_{1} =_{betadeltaiotazeta} t_{2}.
The convertibility relation allows to introduce a new typing rule
which says that two convertible wellformed types have the same
inhabitants.
At the moment, we did not take into account one rule between universes
which says that any term in a universe of index i is also a term in
the universe of index i+1. This property is included into the
conversion rule by extending the equivalence relation of
convertibility into an order inductively defined by:

if E[Gamma]  t =_{betadeltaiotazeta} u then E[Gamma]  t <=_{betadeltaiotazeta} u,
 if i <= j then E[Gamma]  Type(i) <=_{betadeltaiotazeta} Type(j),
 for any i, E[Gamma]  Prop <=_{betadeltaiotazeta} Type(i),
 for any i, E[Gamma]  Set <=_{betadeltaiotazeta} Type(i),
 if E[Gamma]  T =_{betadeltaiotazeta} U and E[Gamma::(x:T)]  T' <=_{betadeltaiotazeta} U' then E[Gamma]  for all x:T,T' <=_{betadeltaiotazeta} for all x:U,U'.
The conversion rule is now exactly:

Conv


E[Gamma]  U : s E[Gamma]  t : T E[Gamma]  T <=_{betadeltaiotazeta} U 

E[Gamma]  t : U 

etaconversion.
An other important rule is the etaconversion. It is to identify
terms over a dummy abstraction of a variable followed by an
application of this variable. Let T be a type, t be a term in
which the variable x doesn't occurs free. We have
E[Gamma]  lambda x:T, (t x) > t
Indeed, as x doesn't occur free in t, for any u one
applies to lambda x:T, (t x), it betareduces to (t u). So
lambda x:T, (t x) and t can be identified.
Remark: The etareduction is not taken into account in the
convertibility rule of Coq.
Normal form.
A term which cannot be any more reduced is said to be in normal
form. There are several ways (or strategies) to apply the reduction
rule. Among them, we have to mention the head reduction which
will play an important role (see chapter 8). Any term can
be written as lambda x_{1}:T_{1}, ... lambda x_{k}:T_{k} ,
(t_{0} t_{1}... t_{n}) where
t_{0} is not an application. We say then that t_{0} is the head
of t. If we assume that t_{0} is lambda x:T, u_{0} then one step of
betahead reduction of t is:
lambda x_{1}:T_{1}, ... lambda x_{k}:T_{k}, (lambda x:T, u_{0} t_{1}... t_{n})
> lambda (x_{1}:T_{1})...(x_{k}:T_{k}),
(u_{0}{x/t_{1}} t_{2} ... t_{n})
Iterating the process of head reduction until the head of the reduced
term is no more an abstraction leads to the betahead normal
form of t:
t > ... >
lambda x_{1}:T_{1}, ...lambda x_{k}:T_{k}, (v u_{1}
... u_{m})
where v is not an abstraction (nor an application). Note that the
head normal form must not be confused with the normal form since some
u_{i} can be reducible.
Similar notions of headnormal forms involving delta, iota and zeta
reductions or any combination of those can also be defined.
4.4 Derived rules for environments
From the original rules of the type system, one can derive new rules
which change the context of definition of objects in the environment.
Because these rules correspond to elementary operations in the Coq
engine used in the discharge mechanism at the end of a section, we
state them explicitly.
Mechanism of substitution.
One rule which can be proved valid, is to replace a term c by its
value in the environment. As we defined the substitution of a term for
a variable in a term, one can define the substitution of a term for a
constant. One easily extends this substitution to contexts and
environments.
Substitution Property:
WF(E;Def(Gamma)(c:=t:T); F)[Delta] 

WF(E; F{c/t})[Delta{c/t}] 
Abstraction.
One can modify the context of definition of a constant c by
abstracting a constant with respect to the last variable x of its
defining context. For doing that, we need to check that the constants
appearing in the body of the declaration do not depend on x, we need
also to modify the reference to the constant c in the environment
and context by explicitly applying this constant to the variable x.
Because of the rules for building environments and terms we know the
variable x is available at each stage where c is mentioned.
Abstracting property:
WF(E; Def(Gamma::(x:U))(c:=t:T);
F)[Delta] WF(E)[Gamma] 

WF(E;Def(Gamma)(c:=lambda x:U, t:for all x:U,T);
F{c/(c x)})[Delta{c/(c x)}] 
Pruning the context.
We said the judgment WF(E)[Gamma] means that the defining contexts of
constants in E are included in Gamma. If one abstracts or
substitutes the constants with the above rules then it may happen
that the context Gamma is now bigger than the one needed for
defining the constants in E. Because defining contexts are growing
in E, the minimum context needed for defining the constants in E
is the same as the one for the last constant. One can consequently
derive the following property.
Pruning property:
WF(E; Def(Delta)(c:=t:T))[Gamma] 

WF(E;Def(Delta)(c:=t:T))[Delta] 
4.5 Inductive Definitions
A (possibly mutual) inductive definition is specified by giving the
names and the type of the inductive sets or families to be
defined and the names and types of the constructors of the inductive
predicates. An inductive declaration in the environment can
consequently be represented with two contexts (one for inductive
definitions, one for constructors).
Stating the rules for inductive definitions in their general form
needs quite tedious definitions. We shall try to give a concrete
understanding of the rules by precising them on running examples. We
take as examples the type of natural numbers, the type of
parameterized lists over a type A, the relation which states that
a list has some given length and the mutual inductive definition of trees and
forests.
4.5.1 Representing an inductive definition
Inductive definitions without parameters
As for constants, inductive definitions can be defined in a nonempty
context.
We write Ind(Gamma)(Gamma_{I}:=Gamma_{C} ) an inductive
definition valid in a context Gamma, a
context of definitions Gamma_{I} and a context of constructors
Gamma_{C}.
Examples.
The inductive declaration for the type of natural numbers will be:
Ind()(nat:Set:=O:nat,S:nat>nat )
In a context with a variable A:Set, the lists of elements in A is
represented by:
Ind(A:Set)(List:Set:=nil:List,cons : A > List >
List )
Assuming
Gamma_{I} is [I_{1}:A_{1};...;I_{k}:A_{k}], and Gamma_{C} is
[c_{1}:C_{1};...;c_{n}:C_{n}], the general typing rules are:
Ind(Gamma)(Gamma_{I}:=Gamma_{C} ) in E
j=1... k 

(I_{j}:A_{j}) in E 
Ind(Gamma)(Gamma_{I}:=Gamma_{C} ) in E
i=1.. n 

(c_{i}:C_{i})in E 
Inductive definitions with parameters
We have to slightly complicate the representation above in order to handle
the delicate problem of parameters.
Let us explain that on the example of List. As they were defined
above, the type List can only be used in an environment where we
have a variable A:Set. Generally one want to consider lists of
elements in different types. For constants this is easily done by abstracting
the value over the parameter. In the case of inductive definitions we
have to handle the abstraction over several objects.
One possible way to do that would be to define the type List
inductively as being an inductive family of type Set>Set:
Ind()(List:Set>Set:=nil:(A:Set)(List A),cons : (A:Set)A
> (List A) > (List A) )
There are drawbacks to this point of view. The
information which says that (List nat) is an inductively defined
Set has been lost.
In the system, we keep track in the syntax of the context of
parameters. The idea of these parameters is that they can be
instantiated and still we have an inductive definition for which we
know the specification.
Formally the representation of an inductive declaration
will be
Ind(Gamma)[Gamma_{P}](Gamma_{I}:=Gamma_{C} ) for an inductive
definition valid in a context Gamma with parameters Gamma_{P}, a
context of definitions Gamma_{I} and a context of constructors
Gamma_{C}.
The occurrences of the variables of Gamma_{P} in the contexts
Gamma_{I} and Gamma_{C} are bound.
The definition Ind(Gamma)[Gamma_{P}](Gamma_{I}:=Gamma_{C} ) will be
wellformed exactly when Ind(Gamma,Gamma_{P})(Gamma_{I}:=Gamma_{C} ) is.
If Gamma_{P} is [p_{1}:P_{1};...;p_{r}:P_{r}], an object in
Ind(Gamma)[Gamma_{P}](Gamma_{I}:=Gamma_{C} ) applied to q_{1},...,q_{r}
will behave as the corresponding object of
Ind(Gamma)(Gamma_{I}{(p_{i}/q_{i})_{i=1..r}}:=Gamma_{C}{(p_{i}/q_{i})_{i=1..r}} ).
Examples
The declaration for parameterized lists is:
Ind()[A:Set](List:Set:=nil:List,cons : A > List >
List )
The declaration for the length of lists is:
Ind()[A:Set](Length:(List A)> nat>Prop:=Lnil:(Length (nil A) O),
Lcons :for all a:A, for all l:(List A),for all n:nat, (Length l n)> (Length (cons A a l) (S n)) )
The declaration for a mutual inductive definition of forests and trees is:
Ind()(tree:Set,forest:Set:=
node:forest > tree,
emptyf:forest,consf:tree > forest > forest )
These representations are the ones obtained as the result of the Coq
declaration:
Coq < Inductive nat : Set :=
Coq <  O : nat
Coq <  S : nat > nat.
Coq < Inductive list (A:Set) : Set :=
Coq <  nil : list A
Coq <  cons : A > list A > list A.
Coq < Inductive Length (A:Set) : list A > nat > Prop :=
Coq <  Lnil : Length A (nil A) O
Coq <  Lcons :
Coq < forall (a:A) (l:list A) (n:nat),
Coq < Length A l n > Length A (cons A a l) (S n).
Coq < Inductive tree : Set :=
Coq < node : forest > tree
Coq < with forest : Set :=
Coq <  emptyf : forest
Coq <  consf : tree > forest > forest.
The inductive declaration in Coq is slightly different from the one
we described theoretically. The difference is that in the type of
constructors the inductive definition is explicitly applied to the
parameters variables. The Coq typechecker verifies that all
parameters are applied in the correct manner in each recursive call.
In particular, the following definition will not be accepted because
there is an occurrence of List which is not applied to the parameter
variable:
Coq < Inductive list' (A:Set) : Set :=
Coq <  nil' : list' A
Coq <  cons' : A > list' (A > A) > list' A.
Coq < Coq < Error: The 1st argument of "list'" must be "A" in
A > list' (A > A) > list' A
4.5.2 Types of inductive objects
We have to give the type of constants in an environment E which
contains an inductive declaration.

IndConst
 Assuming Gamma_{P} is [p_{1}:P_{1};...;p_{r}:P_{r}],
Gamma_{I} is [I_{1}:A_{1};...;I_{k}:A_{k}], and Gamma_{C} is
[c_{1}:C_{1};...;c_{n}:C_{n}],
Ind(Gamma)[Gamma_{P}](Gamma_{I}:=Gamma_{C} ) in E
j=1... k 

(I_{j}:for all p_{1}:P_{1},...for all p_{r}:P_{r},A_{j}) in E 
Ind(Gamma)[Gamma_{P}](Gamma_{I}:=Gamma_{C} ) in E
i=1.. n 

(c_{i}:for all p_{1}:P_{1},... for all p_{r}:P_{r},C_{i}{I_{j}/(I_{j} p_{1}...
p_{r})}_{j=1... k})in E 
Example.
We have (List:Set > Set), (cons:for all A:Set,A>(List A)>
(List A)),
(Length:for all A:Set, (List A)>nat>Prop), tree:Set and forest:Set.
From now on, we write List_A instead of (List A) and Length_A
for (Length A).
4.5.3 Wellformed inductive definitions
We cannot accept any inductive declaration because some of them lead
to inconsistent systems. We restrict ourselves to definitions which
satisfy a syntactic criterion of positivity. Before giving the formal
rules, we need a few definitions:
Definitions
A type T is an arity of sort s if it converts
to the sort s or to a product for all x:T,U with U an arity
of sort s. (For instance A> Set or for all A:Prop,A>
Prop are arities of sort respectively Set and Prop). A type
of constructor of I is either a term
(I t_{1}... t_{n}) or for all x:T,C with C a type of constructor
of I.
The type of constructor T will be said to satisfy the positivity
condition for a constant X in the following cases:

T=(X t_{1}... t_{n}) and X does not occur free in
any t_{i}
 T=for all x:U,V and X occurs only strictly positively in U and
the type V satisfies the positivity condition for X
The constant X occurs strictly positively in T in the
following cases:

X does not occur in T
 T converts to (X t_{1} ... t_{n}) and X does not occur in
any of t_{i}
 T converts to for all x:U,V and X does not occur in
type U but occurs strictly positively in type V
 T converts to (I a_{1} ... a_{m} t_{1} ... t_{p}) where
I is the name of an inductive declaration of the form
Ind(Gamma)[p_{1}:P_{1};...;p_{m}:P_{m}](I:A:=c_{1}:C_{1};...;c_{n}:C_{n} )
(in particular, it is not mutually defined and it has m
parameters) and X does not occur in any of the t_{i}, and the
types of constructor C_{i}{p_{j}/a_{j}}_{j=1... m} of I satisfy
the imbricated positivity condition for X
The type of constructor T of I satisfies the imbricated
positivity condition for a constant X in the following
cases:

T=(I t_{1}... t_{n}) and X does not occur in
any t_{i}
 T=for all x:U,V and X occurs only strictly positively in U and
the type V satisfies the imbricated positivity condition for X
Example
X occurs strictly positively in A> X or X*A or (list
X) but not in X > A or (X > A)> A nor (neg A)
assuming the notion of product and lists were already defined and neg is an inductive definition with declaration Ind()[A:Set](neg:Set:=neg:(A>False) > neg ). Assuming
X has arity nat > Prop and ex is the inductively
defined existential quantifier, the occurrence of X in (ex
nat lambda n:nat, (X n)) is also strictly positive.
Correctness rules.
We shall now describe the rules allowing the introduction of a new
inductive definition.

WInd
 Let E be an environment and
Gamma,Gamma_{P},Gamma_{I},Gamma_{C} are contexts such that
Gamma_{I} is [I_{1}:A_{1};...;I_{k}:A_{k}] and Gamma_{C} is
[c_{1}:C_{1};...;c_{n}:C_{n}].

(E[Gamma;Gamma_{P}]  A_{j} : s'_{j})_{j=1... k}
(E[Gamma;Gamma_{P};Gamma_{I}]  C_{i} : s_{pi})_{i=1... n}


WF(E;Ind(Gamma)[Gamma_{P}](Gamma_{I}:=Gamma_{C} ))[Gamma] 

providing the following side conditions hold:

k>0, I_{j}, c_{i} are different names for j=1... k and i=1... n,
 for j=1... k we have A_{j} is an arity of sort s_{j} and I_{j}
not in Gamma union E,
 for i=1... n we have C_{i} is a type of constructor of
I_{pi} which satisfies the positivity condition for I_{1} ... I_{k}
and c_{i} not in Gamma union E.
One can remark that there is a constraint between the sort of the
arity of the inductive type and the sort of the type of its
constructors which will always be satisfied for the impredicative sort
(Prop) but may fail to define inductive definition
on sort Set and generate constraints between universes for
inductive definitions in types.
Examples
It is well known that existential quantifier can be encoded as an
inductive definition.
The following declaration introduces the secondorder existential
quantifier there exists X.P(X).
Coq < Inductive exProp (P:Prop>Prop) : Prop
Coq < := exP_intro : forall X:Prop, P X > exProp P.
The same definition on Set is not allowed and fails :
Coq < Inductive exSet (P:Set>Prop) : Set
Coq < := exS_intro : forall X:Set, P X > exSet P.
Coq < Coq < User error: Large nonpropositional inductive types must be in Type
It is possible to declare the same inductive definition in the
universe Type.
The exType inductive definition has type (Type_{i} >Prop)>
Type_{j} with the constraint i<j.
Coq < Inductive exType (P:Type>Prop) : Type
Coq < := exT_intro : forall X:Type, P X > exType P.
4.5.4 Destructors
The specification of inductive definitions with arities and
constructors is quite natural. But we still have to say how to use an
object in an inductive type.
This problem is rather delicate. There are actually several different
ways to do that. Some of them are logically equivalent but not always
equivalent from the computational point of view or from the user point
of view.
From the computational point of view, we want to be able to define a
function whose domain is an inductively defined type by using a
combination of case analysis over the possible constructors of the
object and recursion.
Because we need to keep a consistent theory and also we prefer to keep
a strongly normalising reduction, we cannot accept any sort of
recursion (even terminating). So the basic idea is to restrict
ourselves to primitive recursive functions and functionals.
For instance, assuming a parameter A:Set exists in the context, we
want to build a function length of type List_A> nat which
computes the length of the list, so such that (length nil) = O
and (length (cons A a l)) = (S (length l)). We want these
equalities to be recognized implicitly and taken into account in the
conversion rule.
From the logical point of view, we have built a type family by giving
a set of constructors. We want to capture the fact that we do not
have any other way to build an object in this type. So when trying to
prove a property (P m) for m in an inductive definition it is
enough to enumerate all the cases where m starts with a different
constructor.
In case the inductive definition is effectively a recursive one, we
want to capture the extra property that we have built the smallest
fixed point of this recursive equation. This says that we are only
manipulating finite objects. This analysis provides induction
principles.
For instance, in order to prove for all l:List_A,(Length_A l (length l))
it is enough to prove:
(Length_A nil (length nil)) and
for all a:A, for all l:List_A, (Length_A l (length l)) >
(Length_A (cons A a l) (length (cons A a l))).
which given the conversion equalities satisfied by length is the
same as proving:
(Length_A nil O) and for all a:A, for all l:List_A,
(Length_A l (length l)) >
(Length_A (cons A a l) (S (length l))).
One conceptually simple way to do that, following the basic scheme
proposed by MartinLöf in his Intuitionistic Type Theory, is to
introduce for each inductive definition an elimination operator. At
the logical level it is a proof of the usual induction principle and
at the computational level it implements a generic operator for doing
primitive recursion over the structure.
But this operator is rather tedious to implement and use. We choose in
this version of Coq to factorize the operator for primitive recursion
into two more primitive operations as was first suggested by Th. Coquand
in [25]. One is the definition by patternmatching. The second one is a definition by guarded fixpoints.
The match...with ...end construction.
The basic idea of this destructor operation is that we have an object
m in an inductive type I and we want to prove a property (P m)
which in general depends on m. For this, it is enough to prove the
property for m = (c_{i} u_{1}... u_{pi}) for each constructor of I.
The Coq term for this proof will be written :
match m with (c_{1} x_{11} ... x_{1p1}) => f_{1}  ... 
(c_{n} x_{n1}...x_{npn}) => f_{n} end
In this expression, if
m is a term built from a constructor (c_{i} u_{1}... u_{pi}) then
the expression will behave as it is specified with ith branch and
will reduce to f_{i} where the x_{i1}...x_{ipi} are replaced
by the u_{1}... u_{p} according to the iotareduction.
Actually, for typechecking a match...with...end
expression we also need to know the predicate P to be proved by case
analysis. Coq can sometimes infer this predicate but sometimes
not. The concrete syntax for describing this predicate uses the
as...return construction.
The predicate will be explicited using the syntax :
match m as x return (P x) with (c_{1} x_{11} ... x_{1p1}) => f_{1}  ... 
(c_{n} x_{n1}...x_{npn}) => f_{n} end
For the purpose of presenting the inference rules, we use a more
compact notation :
case(m,(lambda x , P), lambda x_{11} ... x_{1p1} , f_{1}  ... 
lambda x_{n1}...x_{npn} , f_{n})
This is the basic idea which is generalized to the case where I is
an inductively defined nary relation (in which case the property
P to be proved will be a n+1ary relation).
Nondependent elimination.
When defining a function by case analysis, we build an object of type I
> C and the minimality principle on an inductively defined logical
predicate of type A > Prop is often used to prove a property
for all x:A,(I x)> (C x). This is a particular case of the dependent
principle that we stated before with a predicate which does not depend
explicitly on the object in the inductive definition.
For instance, a function testing whether a list is empty
can be
defined as:
lambda l:List_A ,case(l,bool,nil => true  (cons a m) => false)
Allowed elimination sorts.
An important question for building the typing rule for match is
what can be the type of P with respect to the type of the inductive
definitions.
We define now a relation [I:AB] between an inductive
definition I of type A, an arity B which says that an object in
the inductive definition I can be eliminated for proving a property
P of type B.
The case of inductive definitions in sorts Set or Type is simple.
There is no restriction on the sort of the predicate to be
eliminated.
Notations.
The [I:AB] is defined as the smallest relation satisfying the
following rules:
We write [IB] for [I:AB] where A is the type of
I.

Prod

[(I x):A'B'] 

[I:(x:A)A'(x:A)B'] 
 Set& Type

s_{1} in {Set,Type(j)},
s_{2} in S 

[I:s_{1}I> s_{2}] 
The case of Inductive Definitions of sort Prop is a bit more
complicated, because of our interpretation of this sort. The only
harmless allowed elimination, is the one when predicate P is also of
sort Prop.

Prop

[I:PropI>Prop]
Prop is the type of logical propositions, the proofs of properties
P in Prop could not be used for computation and are consequentely
ignored by the extraction mechanism.
Assume A and B are two propositions, and the logical disjunction
A\/ B is defined inductively by :
Coq < Inductive or (A B:Prop) : Prop :=
Coq < lintro : A > or A B  rintro : B > or A B.
The following definition which computes a boolean value by case over
the proof of or A B is not accepted :
Coq < Definition choice (A B: Prop) (x:or A B) :=
Coq < match x with lintro a => true  rintro b => false end.
Coq < Coq < Error: Incorrect elimination of "x" in the inductive type
or
The elimination predicate "fun _ : or A B => bool" has type
"or A B > Set"
It should be one of :
"Prop"
Elimination of an inductive object of sort : "Prop"
is not allowed on a predicate in sort : "Set"
because noninformative objects may not construct informative ones.
From the computational point of view, the structure of the proof of
(or A B) in this term is needed for computing the boolean
value.
In general, if I has type Prop then P cannot have type I>
Set, because it will mean to build an informative proof of type
(P m) doing a case analysis over a noncomputational object that
will disappear in the extracted program. But the other way is safe
with respect to our interpretation we can have I a computational
object and P a noncomputational one, it just corresponds to proving
a logical property of a computational object.
In the same spirit, elimination on P of type I>
Type cannot be allowed because it trivially implies the elimination
on P of type I> Set by cumulativity. It also implies that there
is two proofs of the same property which are provably different,
contradicting the proofirrelevance property which is sometimes a
useful axiom :
Coq < Axiom proof_irrelevance : forall (P : Prop) (x y : P), x=y.
proof_irrelevance is assumed
The elimination of an inductive definition of type Prop on a
predicate P of type I> Type leads to a paradox when applied to
impredicative inductive definition like the secondorder existential
quantifier exProp defined above, because it give access to
the two projections on this type.
Empty and singleton elimination
There are special inductive definitions in Prop for which more
eliminations are allowed.

Propextended


I is an empty or singleton
definition sin S 

[I:PropI> s] 

A singleton
definition has only one constructor and all the arguments of this
constructor have type Prop. In that case, there is a canonical
way to interpret the informative extraction on an object in that type,
such that the elimination on any sort s is legal. Typical examples are
the conjunction of noninformative propositions and the equality.
If there is an hypothesis h:a=b in the context, it can be used for
rewriting not only in logical propositions but also in any type.
Coq < Print eq_rec.
eq_rec =
fun (A : Type) (x : A) (P : A > Set) => eq_rect x P
: forall (A : Type) (x : A) (P : A > Set),
P x > forall y : A, x = y > P y
Argument A is implicit
Argument scopes are [type_scope _ _ _ _ _]
Coq < Extraction eq_rec.
(** val eq_rec : 'a1 > 'a2 > 'a1 > 'a2 **)
let eq_rec x f y =
f
An empty definition has no constructors, in that case also,
elimination on any sort is allowed.
Type of branches.
Let c be a term of type C, we assume C is a type of constructor
for an inductive definition I. Let P be a term that represents the
property to be proved.
We assume r is the number of parameters.
We define a new type {c:C}^{P} which represents the type of the
branch corresponding to the c:C constructor.

{c:(I_{i} p_{1}... p_{r} t_{1} ... t_{p})}^{P} 
same as (P t_{1}... t_{p} c) 
{c:for all x:T,C}^{P} 
same as for all x:T,{(c x):C}^{P} 

We write {c}^{P} for {c:C}^{P} with C the type of c.
Examples.
For List_A the type of P will be List_A> s for s in S.
{(cons A)}^{P} same as
for all a:A, for all l:List_A,(P (cons A a l)).
For Length_A, the type of P will be
for all l:List_A,for all n:nat, (Length_A l n)> Prop and the expression
{(Lcons A)}^{P} is defined as:
for all a:A, for all l:List_A, for all n:nat, for all
h:(Length_A l n), (P (cons A a l) (S n) (Lcons A a l n l)).
If P does not depend on its third argument, we find the more natural
expression:
for all a:A, for all l:List_A, for all n:nat,
(Length_A l n)>(P (cons A a l) (S n)).
Typing rule.
Our very general destructor for inductive definition enjoys the
following typing rule

match


E[Gamma]  c : (I q_{1}... q_{r} t_{1}... t_{s})
E[Gamma]  P : B [(I q_{1}... q_{r})B]
(E[Gamma]  f_{i} : {(c_{pi} q_{1}... q_{r})}^{P})_{i=1... l} 

E[Gamma]  case(c,P,f_{1}... f_{l}) : (P t_{1}... t_{s} c) 

provided I is an inductive type in a declaration
Ind(Delta)[Gamma_{P}](Gamma_{I}:=Gamma_{C} ) with Gamma_{P} = r,
Gamma_{C} = [c_{1}:C_{1};...;c_{n}:C_{n}] and c_{p1}... c_{pl} are the
only constructors of I.
Example.
For List and Length the typing rules for the match expression
are (writing just t:M instead of E[Gamma]  t : M, the environment and
context being the same in all the judgments).
l:List_A P:List_A> s f_{1}:(P (nil A))
f_{2}:for all a:A, for all l:List_A, (P (cons A a l)) 

case(l,P,f_{1} f_{2}):(P l) 

H:(Length_A L N) 
P:for all l:List_A, for all n:nat, (Length_A l n)>
Prop 
f_{1}:(P (nil A) O Lnil) 
f_{2}:for all a:A, for all l:List_A, for all n:nat, for all
h:(Length_A l n), (P (cons A a n) (S n) (Lcons A a l n h)) 



case(H,P,f_{1} f_{2}):(P L N H) 
Definition of iotareduction.
We still have to define the iotareduction in the general case.
A iotaredex is a term of the following form:
case((c_{pi} q_{1}... q_{r} a_{1}... a_{m}),P,f_{1}...
f_{l})
with c_{pi} the ith constructor of the inductive type I with r
parameters.
The iotacontraction of this term is (f_{i} a_{1}... a_{m}) leading
to the general reduction rule:
case((c_{pi} q_{1}... q_{r} a_{1}... a_{m}),P,f_{1}...
f_{n}) >_{iota} (f_{i} a_{1}... a_{m})
4.5.5 Fixpoint definitions
The second operator for elimination is fixpoint definition.
This fixpoint may involve several mutually recursive definitions.
The basic concrete syntax for a recursive set of mutually recursive
declarations is (with Gamma_{i} contexts) :
fix f_{1} (Gamma_{1}) :A_{1}:=t_{1} with ... with f_{n}
(Gamma_{n}) :A_{n}:=t_{n}
The terms are obtained by projections from this set of declarations
and are written
fix f_{1} (Gamma_{1}) :A_{1}:=t_{1} with ... with f_{n}
(Gamma_{n}) :A_{n}:=t_{n} for f_{i}
In the inference rules, we represent such a
term by
Fix f_{i}{f_{1}:A_{1}':=t_{1}' ... f_{n}:A_{n}':=t_{n}'}
with t_{i}' (resp. A_{i}') representing the term t_{i} abstracted
(resp. generalised) with
respect to the bindings in the context Gamma_{i}, namely
t_{i}'=lambda Gamma_{i} , t_{i} and A_{i}'=for all Gamma_{i}, A_{i}.
Typing rule
The typing rule is the expected one for a fixpoint.

Fix

(E[Gamma]  A_{i} : s_{i})_{i=1... n}
(E[Gamma,f_{1}:A_{1},...,f_{n}:A_{n}]  t_{i} : A_{i})_{i=1... n} 

E[Gamma]  Fix f_{i}{f_{1}:A_{1}:=t_{1} ... f_{n}:A_{n}:=t_{n}} : A_{i} 
Any fixpoint definition cannot be accepted because nonnormalizing terms
will lead to proofs of absurdity.
The basic scheme of recursion that should be allowed is the one needed for
defining primitive
recursive functionals. In that case the fixpoint enjoys a special
syntactic restriction, namely one of the arguments belongs to an
inductive type, the function starts with a case analysis and recursive
calls are done on variables coming from patterns and representing subterms.
For instance in the case of natural numbers, a proof of the induction
principle of type
for all P:nat>Prop, (P O)>((n:nat)(P n)>(P (S n)))>
for all n:nat, (P n)
can be represented by the term:
lambda P:nat>Prop,lambda f:(P O), lambda g:(for all n:nat,
(P n)>(P (S n))) , 
Fix h{h:for all n:nat, (P n):=lambda n:nat, case(n,P,f lambda
p:nat, (g p (h p)))} 
Before accepting a fixpoint definition as being correctly typed, we
check that the definition is ``guarded''. A precise analysis of this
notion can be found in [59].
The first stage is to precise on which argument the fixpoint will be
decreasing. The type of this argument should be an inductive
definition.
For doing this the syntax of fixpoints is extended and becomes
Fix f_{i}{f_{1}/k_{1}:A_{1}:=t_{1} ... f_{n}/k_{n}:A_{n}:=t_{n}}
where k_{i} are positive integers.
Each A_{i} should be a type (reducible to a term) starting with at least
k_{i} products for all y_{1}:B_{1},... for all y_{ki}:B_{ki}, A'_{i}
and B_{ki}
being an instance of an inductive definition.
Now in the definition t_{i}, if f_{j} occurs then it should be applied
to at least k_{j} arguments and the k_{j}th argument should be
syntactically recognized as structurally smaller than y_{ki}
The definition of being structurally smaller is a bit technical.
One needs first to define the notion of
recursive arguments of a constructor.
For an inductive definition Ind(Gamma)[Gamma_{P}](Gamma_{I}:=Gamma_{C} ),
the type of a constructor c have the form
for all p_{1}:P_{1},... for all p_{r}:P_{r},
for all x_{1}:T_{1}, ... for all x_{r}:T_{r}, (I_{j} p_{1}...
p_{r} t_{1}... t_{s}) the recursive arguments will correspond to T_{i} in
which one of the I_{l} occurs.
The main rules for being structurally smaller are the following:
Given a variable y of type an inductive
definition in a declaration
Ind(Gamma)[Gamma_{P}](Gamma_{I}:=Gamma_{C} )
where Gamma_{I} is [I_{1}:A_{1};...;I_{k}:A_{k}], and Gamma_{C} is
[c_{1}:C_{1};...;c_{n}:C_{n}].
The terms structurally smaller than y are:

(t u), lambda x:u , t when t is structurally smaller than y .
 case(c,P,f_{1}... f_{n}) when each f_{i} is structurally
smaller than y.
If c is y or is structurally smaller than y, its type is an inductive
definition I_{p} part of the inductive
declaration corresponding to y.
Each f_{i} corresponds to a type of constructor C_{q} same as
for all y_{1}:B_{1}, ... for all y_{k}:B_{k}, (I a_{1}... a_{k})
and can consequently be
written lambda y_{1}:B'_{1}, ... lambda y_{k}:B'_{k}, g_{i}.
(B'_{i} is obtained from B_{i} by substituting parameters variables)
the variables y_{j} occurring
in g_{i} corresponding to recursive arguments B_{i} (the ones in
which one of the I_{l} occurs) are structurally smaller than y.
The following definitions are correct, we enter them using the
Fixpoint command as described in section 1.3.4 and show
the internal representation.
Coq < Fixpoint plus (n m:nat) {struct n} : nat :=
Coq < match n with
Coq <  O => m
Coq <  S p => S (plus p m)
Coq < end.
plus is recursively defined
Coq < Print plus.
plus =
(fix plus (n m : nat) {struct n} : nat :=
match n with
 O => m
 S p => S (plus p m)
end)
: nat > nat > nat
Coq < Fixpoint lgth (A:Set) (l:list A) {struct l} : nat :=
Coq < match l with
Coq <  nil => O
Coq <  cons a l' => S (lgth A l')
Coq < end.
lgth is recursively defined
Coq < Print lgth.
lgth =
(fix lgth (A : Set) (l : list A) {struct l} : nat :=
match l with
 nil => O
 cons _ l' => S (lgth A l')
end)
: forall A : Set, list A > nat
Argument scopes are [type_scope _]
Coq < Fixpoint sizet (t:tree) : nat := let (f) := t in S (sizef f)
Coq < with sizef (f:forest) : nat :=
Coq < match f with
Coq <  emptyf => O
Coq <  consf t f => plus (sizet t) (sizef f)
Coq < end.
sizet, sizef are recursively defined
Coq < Print sizet.
sizet =
fix sizet (t : tree) : nat :=
let (f) := t in S (sizef f)
with sizef (f : forest) : nat :=
match f with
 emptyf => O
 consf t f0 => plus (sizet t) (sizef f0)
end
for sizet
: tree > nat
Reduction rule
Let F be the set of declarations: f_{1}/k_{1}:A_{1}:=t_{1} ...
f_{n}/k_{n}:A_{n}:=t_{n}.
The reduction for fixpoints is:
(Fix f_{i}{F} a_{1}...
a_{ki}) >_{iota} t_{i}{(f_{k}/Fix f_{k}{F})_{k=1... n}}
when a_{ki} starts with a constructor.
This last restriction is needed in order to keep strong normalization
and corresponds to the reduction for primitive recursive operators.
We can illustrate this behavior on examples.
Coq < Goal forall n m:nat, plus (S n) m = S (plus n m).
1 subgoal
============================
forall n m : nat, plus (S n) m = S (plus n m)
Coq < reflexivity.
Proof completed.
Coq < Abort.
Current goal aborted
Coq < Goal forall f:forest, sizet (node f) = S (sizef f).
1 subgoal
============================
forall f : forest, sizet (node f) = S (sizef f)
Coq < reflexivity.
Proof completed.
Coq < Abort.
Current goal aborted
But assuming the definition of a son function from tree to forest:
Coq < Definition sont (t:tree) : forest
Coq < := let (f) := t in f.
sont is defined
The following is not a conversion but can be proved after a case analysis.
Coq < Goal forall t:tree, sizet t = S (sizef (sont t)).
Coq < Coq < 1 subgoal
============================
forall t : tree, sizet t = S (sizef (sont t))
Coq < reflexivity. (** this one fails **)
Toplevel input, characters 011
> reflexivity.
> ^^^^^^^^^^^
Error: Impossible to unify "S (sizef (sont t))" with "sizet t"
Coq < destruct t.
1 subgoal
f : forest
============================
sizet (node f) = S (sizef (sont (node f)))
Coq < reflexivity.
Proof completed.
Mutual induction
The principles of mutual induction can be automatically generated
using the Scheme command described in section 8.13.
4.6 Coinductive types
The implementation contains also coinductive definitions, which are
types inhabited by infinite objects.
More information on coinductive definitions can be found
in [60, 61].
4.7 Cic: the Calculus of Inductive Construction with
impredicative Set
Coq can be used as a typechecker for Cic, the original
Calculus of Inductive Constructions with an impredicative sort Set
by using the compiler option impredicativeset.
For example, using the ordinary coqtop command, the following
is rejected.
Coq < Definition id: Set := forall X:Set,X>X.
Coq < Coq < Coq < Coq < Toplevel input, characters 192202
> Definition id: Set := forall X:Set,X>X.
> ^^^^^^^^^^
Error: The term "forall X : Set, X > X" has type "Type"
while it is expected to have type "Set"
while it will typecheck, if one use instead the coqtop
impredicativeset command.
The major change in the theory concerns the rule for product formation
in the sort Set, which is extended to a domain in any sort :

Prod

E[Gamma]  T : s sin S
E[Gamma::(x:T)]  U : Set 

E[Gamma]  for all x:T,U : Set 
This extension has consequences on the inductive definitions which are
allowed.
In the impredicative system, one can build socalled large inductive
definitions like the example of secondorder existential
quantifier (exSet).
There should be restrictions on the eliminations which can be
performed on such definitions. The eliminations rules in the
impredicative system for sort Set become :

Set

s in
{Prop, Set} 

[I:SetI> s] 


I is a small inductive definition s in
{Type(i)} 

[I:SetI> s] 

 1
 This requirement could be relaxed if we instead introduced
an explicit mechanism for instantiating constants. At the external
level, the Coq engine works accordingly to this view that all the
definitions in the environment were built in a subcontext of the
current context.