Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] help please with development in Coq

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] help please with development in Coq


Chronological Thread 
  • From: Gaëtan Gilbert <gaetan.gilbert AT skyskimmer.net>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] help please with development in Coq
  • Date: Tue, 5 Feb 2019 11:57:35 +0100
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=gaetan.gilbert AT skyskimmer.net; spf=Pass smtp.mailfrom=gaetan.gilbert AT skyskimmer.net; spf=None smtp.helo=postmaster AT relay4-d.mail.gandi.net
  • Ironport-phdr: 9a23:TwXnYBc2ZGpRjHtjHgShetcWlGMj4u6mDksu8pMizoh2WeGdxcS/Zh7h7PlgxGXEQZ/co6odzbaO4+a4ASQp2tWoiDg6aptCVhsI2409vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6nK94iQPFRrhKAF7Ovr6GpLIj8Swyuu+54Dfbx9HiTahYr5+Ngm6oRnMvcQKnIVuLbo8xAHUqXVSYeRWwm1oJVOXnxni48q74YBu/SdNtf8/7sBMSar1cbg2QrxeFzQmLns65Nb3uhnZTAuA/WUTX2MLmRdVGQfF7RX6XpDssivms+d2xSeXMdHqQb0yRD+v6bpgRh31hycdLzM37X/ZisJwgqxYrhyuqRNwzIzIb4+aL/d+YqDQcMkGSWZdUMtcVSpMCZ68YYsVCOoBOP5VoYjnqFwSsRuxHw+sC/vuxD9Jgn/5xrM10/49EQrb2wEgEMgBv2rIrNrvMqceS++1zKjMzTrYcfxWwyv95ZPTchAiofCMRrFwccvUyUkqCQzFlE+cqYr7MDOJz+kAtXWQ4eRnVeKqkWEnqgdxryCzxscxk4XGm5gVxU7f9Spk3ok1I8e0R1NlbtK8DJRQtyWaN4puQsw4R2Fnojw2yrsYtp6neiUB1ZcpxwbHZvCZboSF4AjvWeSNLTtimX5oe7yyiwyv/UWky+DwTte43EtEoyZfj9XBtm4B2wbO5sWGVPdx5EOs1DmJ2gvO8O9LO1o0mrDeK5M5wr4/iJ4TsUPbEy/shkr2iLWZd0Ur9+Sx9uvreLDmqYWdN49wkA3+Pb4hmsqiDuQ5KAQOWXaU+fik2L3i+032XqlKg+UonqXEsp3WP8YWqrKjDwNI0Ysu5QyzAyqi3dkZhXUHKUhKeBODj4jnIVHOJ/X4AO+wg1u2jjhr2+rJPrv7DpXCL3jDlKzucqhn605A0wcz1tNf5pJPCrECIfLzX0rxu8LCDhMjNQy73frnBM1n1owCQWKPHrOZMKTKvFCU4eIvOvCAa5MRuDbgMPco/OXujH88mV8FZ6alx5oXaHaiHvRnOUqVe3Tsgs1SWVsN6wE5VanhjECIeT9VfXe7GawmtR8hD4fzIo5AWomrt5OA2C22BIEeMm9PB0yFFzHndoGOVu0QQDmRM9RikzkBWKLnTYI9g0L9/DTmwqZqe7KHshYTsojugYAstr/j0Coq/DkxNPyzlmSETmV6hGQNHmFkx6Nuuk98z1KOy+5+juAKTIUPtcMMaR8zMNvn98I/E8r7A1yTZdSYU1WnR9CrG3c3Q85jm4ZTMXY4IM2ri1X45wTvA7IRkObWVoY59qvNgz39YcN0ynKA26Ang1hgRMZTZzWr

1: you shouldn't need the refine in the tail definition (tail of list of length 1 isn't special)

2: again in the definition of tail, if you swap "inversion e" and "exists x" the resulting proof term is much simpler as the first projection won't depend on the size proof. Then you won't need to destruct the identity later as it won't be blocking. Try Print-ing the lemma before and after the change to see what it affects.

If you know that S is injective you can also avoid using inversion while defining tail (inversion is known for producing ugly proof terms, this isn't a problem in regular proofs as you don't care about the terms but should be avoided when using Defined) and instead apply the injectivity proof (find it with Search (S _ = S _ -> _ = _)).

If for some reason you really have to prove something where an equality blocks you, you may want to look into working with relevant identities. For this learn to use HoTT (the parts which don't rely on the HoTT axioms can be used in any Coq development). This is nontrivial.

Gaëtan Gilbert

On 05/02/2019 10:59, Norman Rink wrote:
Dear Coq-club,

I am relatively new to Coq. While I feel comfortable with “pedestrian”-style
Coq developments – by which I mean specifying comparably simply-typed
functions in Gallina and proving theorems about these functions outside of
the definitions – I am now trying to use Coq/Gallina more effectively by
writing dependently-typed functions (hoping that this will save some
outside-of-definitions proof effort).

In this context, I would like to introduce my own tuples, i.e. lists of fixed
finite length. For these tuples, I then want to introduce “typical” list
functions like ‘append’, ‘tail’ etc. My tuple definition and ‘tail’ function
appear below.

Definition MyTuple (n:nat) := { l:list nat | length l = n }.

Definition tail {n:nat} : MyTuple (S n) -> MyTuple n.
Proof.
refine(match n with
| 0 => fun _ => exist _ [] eq_refl
| S n' => fun t => _
end).
destruct t.
destruct x.
inversion e.
inversion e. exists x. reflexivity.
Defined.

Since the definition of ‘tail’ is a little non-transparent (and the code for
the proof is quite cryptic – try printing it), I am compelled to verify that
my ‘tail’ function behaves as expected. This means I want my taking-the-tail
operation to commute with projecting the list out of ‘MyTuple’, i.e.:

Lemma tail_correct : forall (n:nat) (t:MyTuple (S n)),
proj1_sig (tail t) = tl (proj1_sig t).

When attempting to prove this lemma (by induction on n), I run into the
problem that I would like to “destruct” an equality proof ‘e’:

e : length (n0 :: x) = S (S n)

The only constructor for ‘e’ is of course ‘eq_refl’, but I cannot seem to
convince Coq of this since ‘eq_refl’ has type ‘x = x’ while my ‘e’ from above
is typed at ‘length (n0 :: x) = S (S n)’. I wonder if there is anything that
I am obviously doing wrong.

I am aware of the discussion of similar looking issues in Chapter 10 of the
CPDT book. http://adam.chlipala.net/cpdt/
However, the techniques from there (proof irrelevance, ’UIP’, ‘StreicherK’)
do not quite seem to work for me since all of them eventually talk about
proofs of ‘x = x’. (Heterogeneous equality ‘JMeq’ also does not seem to be a
good fit since it appears that ‘JMeq’ can be put to use most effectively if
it is indeed used at the same types eventually.)

In case anyone feels compelled to suggest I use finite-length vectors instead
of subtypes of lists: I ultimately run into similar problems with equality
between different types (not for the ‘tail’ function specifically but in
attempted proofs of lemmas similar to “tail_correct” above). It would be
great if I could somehow eliminate ‘eq_rec’/‘eq_rect’ from terms in my
proofs, but I understand that this is a bit of a rush (wishful) fix.

Any help or pointers would be greatly appreciated. Many thanks.

Best regards,

Norman Rink



Dr. Norman Rink
Postdoctoral Researcher

Technische Universität Dresden
Faculty of Computer Science
Chair for Compiler Construction
Helmholtzstrasse 18
Barkhausenbau, BAR III.59
01062 Dresden

phone: +49 (0)351 463 43711
email:
norman.rink AT tu-dresden.de
www: https://cfaed.tu-dresden.de/ccc-staff-rink








Archive powered by MHonArc 2.6.18.

Top of Page