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: [Coq-Club] Stuck with an induction proof using subset types
- Date: Fri, 19 May 2017 09:47:58 +0200
- Authentication-results: mail3-smtp-sop.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:MBbHHxzQMrrM2nXXCy+O+j09IxM/srCxBDY+r6Qd2+weIJqq85mqBkHD//Il1AaPBtSFra8bw6qO6ua7CDNGuc7A+Fk5M7VyFDY9yv8q1zQ6B8CEDUCpZNXLVAcdWPp4aVl+4nugOlJUEsutL3fbo3m18CJAUk6nbVk9Kev6AJPdgNqq3O6u5ZLTfx9IhD2gar9uMRm6twvcu80XjId4Kqs8yAbCrn9Ud+hL329lK1aekhTm6sus4JJv9jlbtu48+cJHTaj1cKM0QKBCAjghL247+tDguwPZTQuI6HscU2EWnQRNDgPY8hz0XYr/vzXjuOZl1yaUIcP5TbYvWTS/9KhrUwPniD0GNzEi7m7ajNF7gb9BrxKgoxx/xJPUYJ2QOfFjcK7RYc8WSGxcVctXSidPAJ6zb5EXAuQfPehWsorzqVUAohSxGQaiC/jiyiNRhnLswaE2z+osHAPA0Qc9H9wOqnPUrNDtOakXVeC61rTIzS7eZP1Pwjf99JbHcgokof6WW7Jwd9faxE4sFwPBlFqQtJflMymS1uQWr2iU8fBgVee1hG4hrQF8uSWvxsEtioXQmoIV107L+j54wIYzKt23Vkh7bcS5H5ROriyXMZZ9TM0lQ2Ftoik6y7sGtIa0fCgL1JQnxwPfZOedf4eU5RLjUeCcKip7inJ9YL+zmhi//Ee6xuHiTMW50ExGojRYntTDrnwA2R7e5tKZRvdh40utwzSC2xrO5uxFIU05k7fQJYQ7zb4qjJUTtFzOHi/ol0Xyi6+bbkAk++e05+noeLnmu5mcN45thgHiL6QhhNewAeU+MggBQWeb//6w26D98kHhQbVKiOM5krXBvZzHK8kWqbS1DxFP3osj8RqzESqq3dsAkXkCNl1FeRaHj4bzO1HJJfD1FfS/g1C2nzd23PDKJLrhAo7RLnfdirfheKxy60hayAco0NBf4ZNUBqgdIPLuRED+r93YDhk2MwOqxebrEshy2Z0GVWKVHqCZKL/SsUOP5u83P+aMY5YVtC/hJPgh+v7hlmQ0mUQdfKmsxZsYcmq0HvVgI0WDYHrjmM0NEWkQvll2cOu/g1qbFDVXenyaXqQm5zh9Bpj1I53EQ9WOhLWcx2+cBYFbfGVPDFbERXTsfpifHfAXdC+IJ8ZnlBQZU7nkV5Is3xCouwL8jbZqeLmHshYEvI7ugYAmr9bYkgs/oGR5
Hello everyone,
I'm stuck for hours with what I thought would be a very simple induction
proof.
The full code of the example and the proof is here:
https://gist.github.com/klauso/fd3787841a44e594715cdd2e758c53b1
I've defined a simple function to look up a key in a list of key value
pairs.
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.
But I'm totally stuck on the proof. I don't know how to get the right
"member" for using the induction
hypothesis. My proof attempt is also in the gist linked above.
Any ideas?
Thanks,
Klaus
- [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.