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: Jason -Zhong Sheng- Hu <fdhzs2010 AT hotmail.com>
  • To: "coq-club AT inria.fr" <coq-club AT inria.fr>
  • Subject: Re: [Coq-Club] help please with development in Coq
  • Date: Tue, 5 Feb 2019 12:29:44 +0000
  • Accept-language: en-CA, en-US
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=fdhzs2010 AT hotmail.com; spf=Pass smtp.mailfrom=fdhzs2010 AT hotmail.com; spf=Pass smtp.helo=postmaster AT NAM05-DM3-obe.outbound.protection.outlook.com
  • Ironport-phdr: 9a23:xVHKQRTpWgVNJ2USJK7oufAU8dpsv+yvbD5Q0YIujvd0So/mwa6zZBKN2/xhgRfzUJnB7Loc0qyK6/CmATRIyK3CmUhKSIZLWR4BhJdetC0bK+nBN3fGKuX3ZTcxBsVIWQwt1Xi6NU9IBJS2PAWK8TW94jEIBxrwKxd+KPjrFY7OlcS30P2594HObwlSizexfbB/IA+qoQnNq8IbnZZsJqEtxxXTv3BGYf5WxWRmJVKSmxbz+MK994N9/ipTpvws6ddOXb31cKokQ7NYCi8mM30u683wqRbDVwqP6WACXWgQjxFFHhLK7BD+Xpf2ryv6qu9w0zSUMMHqUbw5Xymp4qF2QxHqlSgHLSY0/mHJhMJtkKJVrhGvqABwzIPPeo6ZKOZyc7nBcd8GR2dMWNtaWSxbAoO7aosCF+4PMvxDr4n6oVsFsAKyCgqsBOPozD9IiWL907A60+s/FwHG0xUsFM8MvnTJsd74M6kSXv21zKjJ1jXPce9a1Srh5IXTchAhpu2MXbdqfsrQzUkjDR/KjlKVqYH8OT6ey+oDs2+e7+V6VOKvjXYqqx1sojS228gskJfGhpkIxV/a8yV12ps6KsOgREFnYd6kFJpQtzmAOItyWMwuWWdotzgmyrAApJW1fzAKxYwoyhLDcfCKd5aE7gj+WOueOzt1inBodKqxhxms8kWs1ujxW8yq31tFtCVJjNzBu3IC2hHd5MiKT/V980i91juM0g3f9/xLLE81mKfdNpUv2KQ/loAJvkTGBiL2mFv5jKuRdkg84ual9+Ppbqnmq5OFOYF6jQ/zPr0pmsOkH+s0KA8OX3WH+eun073j4Ev5T6hQgv0uiKnZt4zaKtoHqa6lAg9V1YAj5wy4Dze7zNQYmX4HLFVGeB6dk4fpPFTOLOj5Dfe5nVusjC9myv/aMrH7BpjBMGLPnKrucLpn5UNRyhI/zdVF6JJVDrEBLujzWkj0tNHAAB82Lgy0wuf8CNljyo8SRH6DD7SZMKPVrV+I4/ggI+iIZIMPpDn9LP0l6+b0jXAlgV8dYbWp3ZwPZX+kGfRmOlyVbmbogtccCmgHpRE+TezviF2aSzFffXeyX6Qm5jE6Eo2qF4nDRpr+yICGiW2wGYQTbWRbAHiNF23pfsOKQb1EPCmVO4pqliEOfbmnUY4okx+04lzU0b1ie8jd4Soe/dfR1N9z6KXolRw0+nk8L9nVh2+BT3NvxDtRHxc227x6qE15jFyE1P4r0LRjCdVP6qYRAU8BPpnGwrkiUoGgakf6Zt6MDW2ebJCjCDA1QMg2xoZVMUZ6B9CrjxSF1C2vUeZMy+67Qacs+6eZ5EDfYt5nwi+dhqkmk1wvQ88JPmqj1PYmqlrjQrXRmkDcrJ6EMKQR2CmRqzWl5E/W4QR0dVU1Vq/IG3cCekHRsNL1oFvYSKOjAqgmNQ0HztOeLqxNaZviilAUHfo=

 Hi Norman,

The general problem here is you do want to have full control over your proof term if proofs are relevant. In particular, when you invoke tactics, you will lose such control. At the very least, you want to finish the existential part first, then use proof mode to handle prop.

In my opinion, to define this function and lemma, there is no need to invoke K or anything. I suppose that if you can define tail by unpacking the subset type first, and then do recursion on the list directly, your lemma should be easier to prove, as the usage of the size information becomes quite limited and should not stand in your way when you establish the lemma.

Thanks,
Jason Hu

On Feb 5, 2019 04:59, Norman Rink <norman.rink AT tu-dresden.de> 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