4

I am trying to define in Coq different types of equalities. During an university course my professor gave us the rules of four different types, as follows (I provide just the links to the rules):

The difference among these four types relies on the type C.

I am trying to prove the isomorphism among them. Unfortunately I have some troubles in declaring as inductive types the first and the second, because I cannot find a way to specify the type C. I have a definition for the third and the fourth, and I already proved the isomorphism between them.

Thanks in advance.

madipi
  • 355
  • 2
  • 11

1 Answers1

3

You cannot quite use inductive types to obtain something that embodies exactly the first two principles without getting the other two. The reason for that is that Coq inductive data types automatically support strong dependent elimination, which means that the result type is allowed to refer to the element being eliminated. This is what you see in the last two sets of rules you gave: the type C is allowed to refer to a proof p that two points a and b are equal. Any reasonable inductively defined equality type will automatically support rules 3 and 4, and thus 1 and 2, which are weaker. For instance, here's how you get 1 and 2 with Coq's standard equality.

Section Gentzen.

Variables (A : Type) (C : A -> A -> Type).

Definition e_id_g {a b : A} (p : a = b) (c : C a a) : C a b :=
  match p with eq_refl => fun c => c end c.

Definition c_id_g (a : A) (c : C a a) : e_id_g (eq_refl a) c = c :=
  eq_refl.

End Gentzen.

Section Leibniz.

Variables (A : Type) (C : A -> A -> Type).

Definition e_id_l {a b : A} (p : a = b) (c : forall x, C x x) : C a b :=
  match p with eq_refl => c a end.

Definition c_id_l (a : A) (c : forall x, C x x) :
                  e_id_l (eq_refl a) c = c a :=
  eq_refl.

End Leibniz.

It is possible to give a different definition that supports just rules 1 and 2, but not 3 and 4, by using a Church encoding of equality:

Definition eq {A} (a b : A) : Prop :=
  forall P : A -> Prop, P a -> P b.

Definition refl {A} (a : A) : eq a a :=
  fun P x => x.

The idea here -- as in similar encodings for data types in the lambda calculus -- is to define a type as the type of its (non-dependent) eliminator, or fold. This definition is sometimes known as Leibniz equality, and indeed provides essentially the same proof rules as you got in 1 and 2, as the following script shows.

Section Gentzen.

Variables (A : Type) (C : A -> A -> Prop).

Definition e_id_g {a b : A} (p : eq a b) (c : C a a) : C a b :=
  p (C a) c.

Definition c_id_g (a : A) (c : C a a) : e_id_g (refl a) c = c :=
  eq_refl.

End Gentzen.

Section Leibniz.

Variables (A : Type) (C : A -> A -> Prop).

Definition e_id_l {a b : A} (p : eq a b) (c : forall x, C x x) : C a b :=
  p (C a) (c a).

Definition c_id_l (a : A) (c : forall x, C x x) :
                  e_id_l (refl a) c = c a :=
  eq_refl.

End Leibniz.

(These principles are actually a bit different: they are restricted to Prop, due to restrictions in Coq's basic theory related to something called impredicativity. But this is an orthogonal issue.)

Without asserting extra axioms, it is impossible to obtain principles 3 and 4 for this new encoding of equality. Proving this would require doing a case analysis on elements of the type forall P, P a -> P b, and arguing that all these elements are of the form refl applied to something. However, this is a type of functions, and there is no way in Coq's basic theory to perform case analysis on those. Note that this argument lays outside of Coq's theory: it is not contradictory to assert as an extra axiom that 3 and 4 are valid for this new type; it is just impossible to prove so without these axioms.

Arthur Azevedo De Amorim
  • 23,012
  • 3
  • 33
  • 39
  • Ok, thanks. So I have to define them by explicitly stating the axioms for proving something, right? Could you please tell me if this definition https://x80.org/collacoq/wudunacuho.coq is correct? – madipi Aug 04 '17 at 07:25
  • The rules you wrote are correct, but you don't need to use axioms: you can define types that support those principles using the encoding shown above – Arthur Azevedo De Amorim Aug 04 '17 at 12:39
  • I actually don't understand how I can prove isomorphism between Gentzen's eqaulity and Leibniz's one using your definitions (actually both of them). I cannot pattern-match on `refl` because it isn't a constructor, and I'm not sure how to proceed using the Proof environment. I think my problem is about the use of Coq's standard equality. – madipi Aug 05 '17 at 08:41
  • This is the problem with this equality principle: you cannot do so. Because the type C in the eliminator does not mention the equality proof itself (like 3 and 4 did), you can't argue that all such proofs come from refl. – Arthur Azevedo De Amorim Aug 05 '17 at 13:45
  • So you're saying these two types are not isomorphic because of the erefl's stuff right? I found a similar issue while proving the isomorphism between Martin Lot and Leibniz. I could do that only adding to the Leibniz's definition the UIC axiom, saying that all the proofs are equal to each other. I concluded basically that without that axiom I cannot prove what I was trying to prove. Here I think it's the same thing, but worst, because I don't know anything about any proof. – madipi Aug 05 '17 at 15:57