Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Dependent typing puzzle, constructor injectivity

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Dependent typing puzzle, constructor injectivity


Chronological Thread 
  • From: Gert Smolka <smolka AT cs.uni-saarland.de>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] Dependent typing puzzle, constructor injectivity
  • Date: Sun, 14 Feb 2021 11:25:58 +0100
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=smolka AT cs.uni-saarland.de; spf=Pass smtp.mailfrom=smolka AT cs.uni-saarland.de; spf=None smtp.helo=postmaster AT theia.rz.uni-saarland.de
  • Ironport-phdr: 9a23:+uyI3R9CnvIJJP9uRHKM819IXTAuvvDOBiVQ1KB31+kcTK2v8tzYMVDF4r011RmVBNSdta4P0rKH+4nbGkU4qa6bt34DdJEeHzQksu4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2aFLduGC94iAPERvjKwV1Ov71GonPhMiryuy+4ZLebxhMiTanYL5/Ixq6oRjNusQSnIBvNrs/xhzVr3VSZu9Y33loJVWdnxb94se/4ptu+DlOtvwi6sBNT7z0c7w3QrJEAjsmNXs15NDwuhnYUQSP/HocXX4InRdOHgPI8Qv1Xpb1siv9q+p9xCyXNtD4QLwoRTiv6bpgRRn1gykFKjE56nnahMxsg6xUrx2vuhJxw4DKbo6XN/RwebjQfc8DRWpEQspRVzBND4G6YoASD+QBJ+FYr4zlqlUPsxS+HxWsD/7yxD9NgX/22a463P48GgzBxwwgGtUOsHDXrNrvL6odTfu1wLPVzTXFbvNawCz955LSfRA7pfGDR7RwftfLxUYyCQzIl1OdopHqMD2JzOoCqXSb7/Z+WuK1jW4qsxx8riayysoshITEiI0bx1TK+yln3oo7JdK2RUFmbdK4DpZdtz+WOpZ2TM4gTWxmuCg0x7IHtJKnciUExpopygLZZveacIaI+gruWPufLDp3nn5ofLOyiwyw/ES6xODwS9G43VJEoyZfj9XBsnMA2wbN5sWHVPdx5Fqt1DaL2g3V9+pKO1o7lbDBJJ4k2rMwloQcsUDEHiLuhEX2jLGZdkQ+9eSy8eTmY6/qpoKaN491kw3+Kb4hldalAeQ8KAcOWXWU9f6h27L95UH5QbNKgeMqkqTBrZzXK8sWqrS9DgJUyIou6QyzAjm73NgAmHkINlNFeBaJj4jzPFHOJej1Dey6g1SrlDdrxOrJM6b9DZXWNHTDjbHhfbdk505H0gU818pf55ZOBbEHPf3/QFL+u8LAAh8jLwO02/rnCMl61o4GRW2PBbaZPLrOvl+M++IgOPKBZJQVuTb4M/gq/eTijX4/mV8HfKmmx4EbaH6iHqcuH0LMan31x9wFDG0ivwwkTeWshkfRfyRUYiOdUrggrgo+D4alBM+XXYWqhL+I9CygWIBQZyVdA1mWFX7ue8OIVqFfO2qpPsZ9n2lcBvCaQIg72ET27V6o+/9cNuPRvxYgm9fm3dlx6ffUkEtqpzdvSdmb0iSWRmhummoOS3k60fIm+BEv+hK4yaF9xsdgO5lT6vdOCFloKZ7RzuU8EcK0RwTAO8yAQUyiS9OqRz08HIpon40+Jn1lEtDntSjtmjKwCuVNxbeQQoEy8+fH1nHrI897xzDK2ft5gg==

Dear Dominique,
why not use the standard technique for non-indexed inductive types for
inr_inj?
See below.
Gert

Fact inr_inj X Y (y y': Y) :
inr X y = inr y' -> y = y'.
Proof.
intros H.
apply f_equal
with (f:= fun a: X + Y => match a with
| inl x => y
| inr y => y
end)
in H.
exact H.
Qed.


> On 14. Feb 2021, at 10:11, Dominique Larchey-Wendling
> <dominique.larchey-wendling AT loria.fr> wrote:
>
> Dear Gert,
>
> Btw, I was a bit lazy implementing injectivity of inr, which
> is also interesting when avoiding inversion, because inversion
> hides what is happening.
>
> The trick is to implement *partial* inversion (inr_inv below).
>
> Best,
>
> Dominique
>
> Section inr_inv.
>
> Variables (A B : Type).
>
> Implicit Type (s : A + B).
>
> Definition not_inl s :=
> match s with
> | inl _ => False
> | _ => True
> end.
>
> Definition inr_inv s : not_inl s -> B :=
> match s with
> | inl _ => fun H => match H with end
> | inr b => fun _ => b
> end.
>
> Lemma inr_inv_fun r s wr ws : r = s -> inr_inv r wr = inr_inv s ws.
> Proof.
> intros ->; destruct s; auto; destruct ws.
> Qed.
>
> Theorem inr_inj x y : @inr A B x = inr y -> x = y.
> Proof. exact (inr_inv_fun (inr _) (inr _) I I). Qed.
>
> End inr_inv.
>
>
>
> ----- Mail original -----
>> De: "Gert Smolka" <smolka AT ps.uni-saarland.de>
>> À: "coq-club" <coq-club AT inria.fr>
>> Envoyé: Dimanche 14 Février 2021 09:59:30
>> Objet: Re: [Coq-Club] Dependent typing puzzle, constructor injectivity
>
>> Dear Dominique,
>> beautiful! Working with a general inversion operator (K_invert)
>> and exploiting the injectivity of inr and existT yields an elegant
>> general scheme.
>> Thanks, Gert
>>
>>> On 13. Feb 2021, at 22:42, Dominique Larchey-Wendling
>>> <dominique.larchey-wendling AT loria.fr> wrote:
>>>
>>> Dear Gert,
>>>
>>> This is mainly what you did, which is implementing
>>> the inversion function by dependent pattern matching.
>>> Some short code below,
>>>
>>> Best regards,
>>>
>>> Dominique
>>>
>>> PS: I guess if you do not have nat but an unspecified type
>>> X with S : X -> X, then you cannot show injectivity of
>>> the constructors.
>>>
>>> -----------------------------
>>>
>>> Fact inr_inj {A B} (x y : B) : @inr A B x = inr y -> x = y.
>>> Proof. inversion 1; trivial. Qed. (* Lazy here *)
>>>
>>> Fact DPI_nat :
>>> forall (p: nat -> Type) n a b, existT p n a = existT p n b -> a = b.
>>> Proof.
>>> (* Follows with Coq.Logic.Eqdep_dec.UIP_refl_nat *)
>>> Admitted.
>>>
>>> Inductive K (x: nat) : nat -> Type :=
>>> | K1: K x (S x)
>>> | K2: forall y z, K x y -> K y z -> K x z.
>>>
>>> Definition K_invert x y (H : K x y) : (( y = S x ) + { z : nat & K x z *
>>> K z y
>>> })%type :=
>>> match H with
>>> | K1 _ => inl eq_refl
>>> | K2 _ y z H1 H2 => inr (existT _ y (H1,H2))
>>> end.
>>>
>>> Fact K2_injective x y z a b a' b':
>>> K2 x z y a b = K2 x z y a' b' -> (a,b) = (a',b').
>>> Proof.
>>> intros H.
>>> now apply f_equal with (f := K_invert _ _), inr_inj, DPI_nat in H.
>>> Qed.




Archive powered by MHonArc 2.6.19+.

Top of Page