coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Klaus Ostermann <klaus.ostermann AT uni-tuebingen.de>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] Stuck with an induction proof using subset types
- Date: Fri, 19 May 2017 11:47:14 +0200
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=klaus.ostermann AT uni-tuebingen.de; spf=None smtp.mailfrom=klaus.ostermann AT uni-tuebingen.de; spf=None smtp.helo=postmaster AT mx04.uni-tuebingen.de
- Ironport-phdr: 9a23:urYx0hdI6korNa9DkQgrBNvvlGMj4u6mDksu8pMizoh2WeGdxcS5YB7h7PlgxGXEQZ/co6odzbGH7ea9BiRAuc/H6yFdNsQUFlcssoY/oU8JOI2/NQXDNvnkbig3ToxpdWRO2DWFC3VTA9v0fFbIo3e/vnY4ExT7MhdpdKyuQtaBx8u42Pqv9JLNfg5GmCSyYa9oLBWxsA7dqtQajZFsJ6s1yxbFuHtFduZLzm9sOV6fggzw68m08ZNh6Shcp+4t+8tdWqjmYqo0SqBVAzshP20p/sPnsgXNQxWS7XUGSGUWlRRIAwnB7B7kW5r6rzX3uOlg1iSEJMP6Vb87Vyis4KdtUx/olTwINyUl/2HNi8x/l7xUrRS8rBFi2YHUYYWVNP1jfqPBeN4RWGRMUtpNWyFHH4ixaZYEAegcMuZCt4TzukUArRW+CwevCu3gxDBHiX3q0qM1yOkhDQLL0RY8E94SvnnZrtP4P7oSX+Cvy6nIyC3OYfZS2Tjn9YjIaQ0qr+iXXbJsb8XR00wvGBnDjlWWtIfoODCV1uAXvGiG9OpsT+Wvi3U7qw5vuDivw90jio/Pho8O11DE8yR5zJ8pJd2lVkF0et+kEJ1fty6EMYt6WN4tTH9xtSs817YIuoa7cTAXxJkpyBPTceKLf5KI7x75SuqdPDh1iGprdb+9nRq+71SsxvDmWsS2ylpGsytIn9nKu3sQzRLc8NKHReF4/kq52TaAyQTT6uZcLEAxmqvXN5EszqQtlpoVsETPBzP2mFjog6CNd0Uk/Oeo5PrhYrn8u5CTKZd4igD4MqswhsyyGfk0PwYBUmSB5+iwzr3u8VfnTLlXgfA6iqzZv4rbJcQfqK65GQhV0oM75ha8CzepyskYnWIdIFJCYxKHk5bmO0vLIP/iC/e/hU+hkCptx/DHJ7HhHojNIWbYn7fge7Z95FBTyAwpwd9C+Z1YEqsBL+7rWk/tqNzYCQc0PBCzw+b+EdlyyoceWX+UDaKCK6PTsVqI5vo1LOWWZY8Vviz9K/k/6PL0g385gwxVQa781pwOLXu8A/5OIkODYHOqjM1SP30Nu18dSOX3kxWlSiJefXO7WaR0sjI/AZ+9S4DYWo23hbWH2g+mGJwTen1LAFGKHnruMYmJDaRfIBmOK9Nsx2RXHYOqTJUsgEmj
Hi Dominique,
thanks for your solution. That's quite instructive.
The puzzle piece I was missing is the "generalize (beq_nat_true keys n)"
part.
I'm still trying to understand why exactly it is necessary.
Klaus
Am 19/05/17 um 10:18 schrieb Dominique Larchey-Wendling:
> Hi Klaus,
>
> Well I do not really understand what got you stuck.
> Here is a possible proof.
>
> Best,
>
> Dominique
>
> ---------------
>
>
> Lemma lookup_correct : forall A (pairs : list (nat * A)) key s (m :
> member s pairs),
> lookup pairs key = Some (existT _ s m ) -> key = fst s.
> Proof.
> induction pairs as [ | (n,a) pairs IH ]; simpl; intros keys (i,b) m Hs.
> discriminate Hs.
> generalize (beq_nat_true keys n) (beq_nat_false keys n); intros H1 H2.
> destruct (beq_nat keys n).
> injection Hs; clear Hs; intros; subst i b.
> rewrite H1; auto.
> case_eq (lookup pairs keys).
> intros (p & m') Hp; rewrite Hp in Hs; apply IH in Hp.
> injection Hs; intros; subst; auto.
> intros H; rewrite H in Hs; discriminate.
> Qed.
>
>
> Le 19/05/2017 à 09:47, Klaus Ostermann a écrit :
>> Fixpoint lookup_simple {A} (pairs: list (nat * A)) (key :nat) : option
>> (nat * A) := match pairs with
>> | [] => None
>> | a :: ss => if (beq_nat key (fst a))
>> then Some a
>> else match (lookup_simple ss key) with
>> | None => None
>> | Some b => Some b
>> end
>> end.
>>
>> It's a simple induction proof to prove that they returned pair has the
>> correct key.
>>
>> Lemma lookup_simple_correct : forall A (pairs : list (nat * A)) key s ,
>> lookup_simple pairs key = Some s -> key = fst s.
>>
>> However, my lookup function should also return a proof that the returned
>> pair is
>> in the original list. For this I use a subset type:
>>
>> Inductive member (A : Type) (x : A) : list A -> Type :=
>> | here : forall l, member x (x :: l)
>> | there : forall y l, member x l -> member x (y :: l).
>>
>>
>> Fixpoint lookup {A} (pairs: list (nat * A)) (key :nat) : option { s:
>> (nat * A) & member s pairs} := match pairs with
>> | [] => None
>> | a :: ss => if (beq_nat key (fst a))
>> then Some (existT _ a (here a ss))
>> else match (lookup ss key) with
>> | None => None
>> | Some (existT s m) => Some (existT _ s (there a m))
>> end
>> end.
>>
>> The new version of the correctness lemma is easy to state:
>>
>> Lemma lookup_correct : forall A (pairs : list (nat * A)) key s (m :
>> member s pairs),
>> lookup pairs key = Some (existT _ s m ) -> key = fst s.
- [Coq-Club] Stuck with an induction proof using subset types, Klaus Ostermann, 05/19/2017
- Re: [Coq-Club] Stuck with an induction proof using subset types, Dominique Larchey-Wendling, 05/19/2017
- Re: [Coq-Club] Stuck with an induction proof using subset types, Klaus Ostermann, 05/19/2017
- Re: [Coq-Club] Stuck with an induction proof using subset types, François Thiré, 05/19/2017
- Re: [Coq-Club] Stuck with an induction proof using subset types, Dominique Larchey-Wendling, 05/19/2017
- Re: [Coq-Club] Stuck with an induction proof using subset types, Klaus Ostermann, 05/19/2017
- Re: [Coq-Club] Stuck with an induction proof using subset types, Dominique Larchey-Wendling, 05/19/2017
Archive powered by MHonArc 2.6.18.