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 ps.uni-saarland.de>
  • To: Coq Club <coq-club AT inria.fr>
  • Subject: Re: [Coq-Club] Dependent typing puzzle, constructor injectivity
  • Date: Sun, 14 Feb 2021 11:30:54 +0100
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=smolka AT ps.uni-saarland.de; spf=Pass smtp.mailfrom=smolka AT ps.uni-saarland.de; spf=None smtp.helo=postmaster AT theia.rz.uni-saarland.de
  • Ironport-phdr: 9a23:UsW8XRIY54+SHcZYINmcpTZWNBhigK39O0sv0rFitYgeI/nxwZ3uMQTl6Ol3ixeRBMOHsqMC1bad6vixEUU7or+5+EgYd5JNUxJXwe43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6arXK99yMdFQviPgRpOOv1BpTSj8Oq3Oyu5pHfeQpFiCe5bL9oLRi7ogrdutQKjYZmN6081gbHrnxUdupM2GhmP0iTnxHy5sex+J5s7SFdsO8/+sBDTKv3Yb02QaRXAzo6PW814tbrtQTYQguU+nQcSGQWnQFWDAXD8Rr3Q43+sir+tup6xSmaIcj7Rq06VDi+86tmTgLjhTwZPDAl7m7Yls1wjLpaoB2/oRx/35XUa5yROPZnY6/RYc8WSW9HU81MVSJOH5m8YpMPAeUdMuhXoJTzqVUArRWgBwaiB+ThxyRUhn/v2K02z+QhHR3E0QEmAtkAsG7UrNLwNKoKUO660rPIzSneZP1L3Df974zIchM7rvqRWr9was/RyU4rFwPGlFqdspTlPyiP2uQQtWib7vNsVfm1hGE9sQFxpiKgxsExhYXTm40a1EnJ+CNky4k6OdO2UlR0YcK4EJROrSGaMZN7Tt4iTWxsuCg31rMLtYOlcSUF1Zgq2RrSZviaf4WM/x7uWumcLClkiH57d7yzmQq+/VSgxODzS8S4zFZHoylYntTKq3sD1ATT59CaRvZz8UqtwzKC2gHJ5uxGO0w5m7fXJ4Ylz7M+jJYfrEDOEyzslEnojKKaaF8o9vWo5unjZLjtu4WSOJVuig7kN6Qjgsy/Dvo8MggJR2Wb5eS826Pi/ULjWrlKlPw3nrPEsJDcJMQXv7W5DBVP3YY57xawFTGm38kCkXYaMl1JYBOHj473NFHSOP30EPmyjlu2nDpvxv3KJL/sDo/DI3TeiLvheKxy609YyAo919Bf4JdUB6kaIPL2XU/xsN/YAQUiPgys2ObrEsh91oUfWW6WGa+WKrndsUWM5u01JemDeZUZtyvjJPQ9/f7hkWc5mUMBfamuxZYYdHe4Hu1/L0qFZXrsn8wOHHwRvgs+SezqkEeNXSRSZ3a0RaI85ys0BJioDYfZFciRh+mq2z7zNZlLbCgSAVeVVHzsao+sWvEWaSvULNU3wRIeUr30ZII7yVmVsQj+yLMvevHR/SkbvLr7z55o4eyWjhg77zh9Ccjb32zbHDI8pX8BWzJjhPM3mkd60FrWlPEg26UFR+wW3OtAV0IBDbCZz+F+DIqsCB7Bc9aADky0BMigAHQqR9srx9YIbwBxFof610yR72+RG7YQ0oezKtks6KuGhyrpPIBgzXeDz6AolV0vRMcJOWD03vcupTiWPJbAlgCir4jvcK0d2CDX82LZlTiWpwdFVg81SqzMR3QWYEeQodmrv04=

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