1

I defined a Boole inductive type based on the disjoint sum's definition:

Inductive Boole :=
  | inlb (a: unit)
  | inrb (b: unit).

Given two types A and B I'm trying to prove the ismorphism between

sigT (fun x: Boole => prod ((eq x (inrb tt)) -> A) (eq x (inlb tt) -> B))

and

A + B

I managed to prove one side of the isomorphism

Definition sum_to_sigT {A} {B} (z: A + B) :
  sigT (fun x: Boole => prod ((eq x (inrb tt)) -> A) (eq x (inlb tt) -> B)).
Proof.
case z.
  move=> a.
  exists (inrb tt).
  rewrite //=.
move=> b.
  exists (inlb tt).
  rewrite //=.
Defined.

Lemma eq_inla_inltt (a: unit) : eq (inlb a) (inlb tt).
Proof.
by case a.
Qed.

Lemma eq_inra_inrtt (a: unit) : eq (inrb a) (inrb tt).
Proof.
by case a.
Qed.

Definition sigT_to_sum {A} {B} 
  (w: sigT (fun x: Boole => prod ((eq x (inrb tt)) -> A) (eq x (inlb tt) -> B))) :
  A + B.
Proof.
destruct w.
destruct p.
destruct x.
apply (inr (b (eq_inla_inltt a0))).
apply (inl (a (eq_inra_inrtt b0))).
Defined.

Definition eq_sum_sigT {A} {B} (x: A + B): 
  eq x (sigT_to_sum (sum_to_sigT x)).
Proof.
by case x.
Defined.

But I'm in trouble in proving the other side, basically because I don't manage to establish equality between the different x and p involved in the following proof:

Definition eq_sigT_sum {A} {B} 
  (y: sigT (fun x: Boole => prod ((eq x (inrb tt)) -> A) (eq x (inlb tt) -> B))) : eq y (sum_to_sigT (sigT_to_sum y)).
Proof.
case: (sum_to_sigT (sigT_to_sum y)).
  move=> x p.
  destruct y.
  destruct x.
  destruct p.
Defined.

Does anyone know how I can prove the latter lemma?

Thanks for the help.

burionk
  • 43
  • 5

1 Answers1

1

As bizarre as this sounds, you cannot prove this result in Coq's theory.

Let's call the type sigT (fun x => prod (eq x (inrb tt) -> A) (eq x (inlb tt) -> B)) simply T. Any element of T has the form existT x (pair f g), where x : Boole, f : eq x (inrb tt) -> A, and g : eq x (inlb tt) -> B. To show your result, you need to argue that two expressions of type T are equal, which will require at some point proving that two terms f1 and f2 of type eq x (inrb tt) -> A are equal.

The problem is that elements of eq x (inrb tt) -> A are functions: they take as input a proof that x and inrb tt are equal, and produce a term of type A as a result. And sadly, the notion of equality for functions in Coq is too weak to be useful in most cases. Normally in math, we would argue that two functions are equal by showing that they produce the same results, that is:

forall f g : A -> B,
  (forall x : A, f x = g x) -> f = g.

This principle, usually known as functional extensionality, is not available in Coq by default. Fortunately, the theory allows us to safely add it as an axiom without compromising the soundness of the theory. It is even available to us in the standard library. I've included here a proof of a slightly modified version of your result. (I've taken the liberty of using the ssreflect library, since I saw you were using it too.)

From mathcomp Require Import ssreflect ssrfun ssrbool eqtype.

Require Import Coq.Logic.FunctionalExtensionality.

Section Iso.

Variables A B : Type.

Inductive sum' :=
| Sum' x of x = true -> A & x = false -> B.

Definition sum'_of_sum (x : A + B) :=
  match x with
  | inl a =>
    Sum' true
         (fun _ => a)
         (fun e : true = false =>
            match e in _ = c return if c then A else B with
            | erefl => a
            end)
  | inr b =>
    Sum' false
         (fun e =>
            match e in _ = c return if c then A else B with
            | erefl => b
            end)
         (fun _ => b)
  end.

Definition sum_of_sum' (x : sum') : A + B :=
  let: Sum' b f g := x in
  match b return (b = true -> A) -> (b = false -> B) -> A + B with
  | true => fun f _ => inl (f erefl)
  | false => fun _ g => inr (g erefl)
  end f g.

Lemma sum_of_sum'K : cancel sum_of_sum' sum'_of_sum.
Proof.
case=> [[]] /= f g; congr Sum'; apply: functional_extensionality => x //;
by rewrite (eq_axiomK x).
Qed.

End Iso.
Arthur Azevedo De Amorim
  • 23,012
  • 3
  • 33
  • 39
  • Thank you very much. So there's no way to prove that result, even adapting your `Sum'`'s definition? That's so sad! Thanks for the proof, I'm still new to Coq, I'll try to go through it! – burionk Aug 07 '17 at 17:59
  • 1
    Correct; the only way is to assume functional extensionality, or a similar axiom. – Arthur Azevedo De Amorim Aug 07 '17 at 18:16