5

I noticed that Coq synthesizes different induction principles on equality for Prop and Type. Does anybody have an explanation for that?

Equality is defined as

Inductive eq (A : Type) (x : A) : A -> Prop :=  eq_refl : x = x

And the associated induction principle has the following type:

eq_ind
 : forall (A : Type) (x : A) (P : A -> Prop),
   P x -> forall y : A, x = y -> P y

Now let's define a Type pendant of eq:

Inductive eqT {A:Type}(x:A):A->Type:= eqT_refl: eqT x x.

The automatically generated induction principle is

eqT_ind
 : forall (A : Type) (x : A) (P : forall a : A, eqT x a -> Prop),
   P x (eqT_refl x) -> forall (y : A) (e : eqT x y), P y e
Cryptostasis
  • 1,166
  • 6
  • 15
  • Fun fact: if you do `Print eqT.`, then Coq prints back `Inductive eqT (A : Type) (x : A) : A -> Prop := eqT_refl : eqT x x`. It is `A -> Prop` not `A -> Type`! – Anton Trunov Sep 25 '16 at 13:16

1 Answers1

5

Note: I'm going to use _rect principles everywhere instead of _ind, since _ind principles are usually implemented via the _rect ones.

Type of eqT_rect

Let's take a look at the predicate P. When dealing with inductive families, the number of arguments of P is equal to the number of non-parametric arguments (indices) + 1.

Let me give some examples (they can be easily skipped).

  • Natural numbers don't have parameters at all:

    Inductive nat : Set :=  O : nat | S : nat -> nat.
    

    So, the predicate P will be of type nat -> Type.

  • Lists have one parametric argument (A):

    Inductive list (A : Type) : Type :=
      nil : list A | cons : A -> list A -> list A.
    

    Again, P has only one argument: P : list A -> Type.

  • Vectors are a different:

    Inductive vec (A : Type) : nat -> Type :=
      nil : vec A 0
    | cons : A -> forall n : nat, vec A n -> vec A (S n).
    

    P has 2 arguments, because n in vec A n is a non-parameteric argument:

    P : forall n : nat, vec A n -> Type
    

The above explains eqT_rect (and, of course, eqT_ind as a consequence), since the argument after (x : A) is non-parametric, P has 2 arguments:

P : forall a : A, eqT x a -> Type

which justifies the overall type for eqT_rect:

eqT_rect
     : forall (A : Type) (x : A) (P : forall a : A, eqT x a -> Type),
       P x (eqT_refl x) -> forall (y : A) (e : eqT x y), P y e

The induction principle obtained in this way is called a maximal induction principle.

Type of eq_rect

The generated induction principles for inductive predicates (such as eq) are simplified to express proof irrelevance (the term for this is simplified induction principle).

When defining a predicate P, Coq simply drops the last argument of the predicate (which is the type being defined, and it lives in Prop). That's why the predicate used in eq_rect is unary. This fact shapes the type of eq_rect:

eq_rect : 
  forall (A : Type) (x : A) (P : A -> Type),
         P x -> forall y : A, x = y -> P y

How to generate maximal induction principle

We can also make Coq generate non-simplified induction principle for eq:

Scheme eq_rect_max := Induction for eq Sort Type.

The resulting type is

eq_rect_max :
  forall (A : Type) (x : A) (P : forall a : A, x = a -> Type),
         P x eq_refl -> forall (y : A) (e : x = y), P y e

and it has the same structure as eqT_rect.

References

For more detailed explanation see sect. 14.1.3 ... 14.1.6 of the book "Interactive Theorem Proving and Program Development (Coq'Art: The Calculus of Inductive Constructions)" by Bertot and Castéran (2004).

Anton Trunov
  • 15,074
  • 2
  • 23
  • 43
  • 1
    Remark to references: it's chapter 15 on the most recent French version. – Cryptostasis Sep 25 '16 at 16:19
  • 1
    I didn't know the authors put the whole [book](http://www.labri.fr/perso/casteran/CoqArt/coqartF.pdf) on the Internet for free! Moreover they seem to update it! And it seems to me I understand like 1/3 - 1/2 of the text with almost zero French knowledge :) – Anton Trunov Sep 25 '16 at 16:29
  • 2
    Note: although proof irrelevance is generally (implicitly) assumed and explains this simplified induction principle, Coq's logic does not imply it. – Zimm i48 Sep 25 '16 at 18:36
  • Correct! Proof Irrelevance as an axiom is stated [here](https://coq.inria.fr/library/Coq.Logic.ProofIrrelevance.html). Many thanks to all the commenters! – Anton Trunov Sep 25 '16 at 18:40
  • 2
    I'll add that you can also ask Coq to generate the simplified version with `Scheme my_eqT_ind := Minimality for eqT Sort Prop`. See https://coq.inria.fr/refman/Reference-Manual015.html#sec570. – eponier Sep 26 '16 at 08:56
  • 2
    Updated link: https://coq.inria.fr/refman/user-extensions/proof-schemes.html#generation-of-induction-principles-with-scheme. – eponier Jun 22 '18 at 10:21