coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Castéran Pierre <pierre.casteran AT gmail.com>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] How can I extract data from this exists Prop?
- Date: Mon, 10 Aug 2020 11:00:45 +0200
- Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=pierre.casteran AT gmail.com; spf=Pass smtp.mailfrom=pierre.casteran AT gmail.com; spf=None smtp.helo=postmaster AT mail-wm1-f51.google.com
- Ironport-phdr: 9a23:WEmaKxVLWuWkhrmVj6cA5Lv8obfV8LGtZVwlr6E/grcLSJyIuqrYbRSFt8tkgFKBZ4jH8fUM07OQ7/m+HzxQqs/Z+Fk5M7V0HycfjssXmwFySOWkMmbcaMDQUiohAc5ZX0Vk9XzoeWJcGcL5ekGA6ibqtW1aFRrwLxd6KfroEYDOkcu3y/qy+5rOaAlUmTaxe7x/IAi3oAnLtcQbgoRuJrstxhDUvnZGZuNayH9yK1mOhRj8/MCw/JBi8yRUpf0s8tNLXLv5caolU7FWFSwqPG8p6sLlsxnDVhaP6WAHUmoKiBpIAhPK4w/8U5zsryb1rOt92C2dPc3rUbA5XCmp4ql3RBP0jioMKjg0+3zVhMNtlqJWuBKvqABwzIDJbo+VOuRwcaHec90dXmdORNpdVylbD4O8c4cCDewMNvtYoYnnoFsOqAOzCBe2C+P01j9PnGX20rc80+s5Cw/G3RIvH8gUsHvKsd74M78SUeGrw6nS1zXMcela1ivn54jTbhAuv+uMUqh2ccfKxkkvEhnKjlSUqYD/IzyV0eENvnGd4uF9Wu2hl3QppBttojiz2MgskI/Ji5oLxl3a9Ch03IQ4KNKkRUJnZdOpEZVduSGVOodoXM8uXnxktTg6xLAHupO2fCcExZopyRDQd/GKcJaE7xD+WOuNJzpzmXFreKqnihqs7UStzvfwW8q03VpQsyZJjNrBumoN2hDO8sSLVOFy8lu81TuKyw/c8fxILEQxmKfZMJEswrs9m5QNvkjfAiP7nVj5g7WLekgh9Oil6ufqbajjq5CGKYB4lwXzP6Egl8OkD+Q3Lg4DVHWB9+umzr3s50j5Ta1KjvIolqnZt4jXJcEBqa64Bw9Zy4gi6xOiAzu/3tQVnWQLIEhKeBKAiIjpNFXOL+7iAfijhFSslS9nx/HAPrL/HpXANmbPnKvlcLpn6ENRyBA/wc1B659XEL0MIO//Vlf0tNPCDx85NwK0w/zgCNV4zo4eQWOPDbGDMKPIr1CE/P4gLPOXZI8Jpjn9MeIq5/j1gH82nF8SZ6ip3Z8NZH+kGfRmJl2VYWDwjdcZDWcKog0+QfT2h12FSD5ffmq9X6Yh5j4gE4+mFofCRoW1gLObxiu7H5tWZnpHCl+WC3voeZ+ECL8wb3eZJdYkmTgZX5CgTZUg3FegrlzU0b1ie8Hd4TGZr5vl4+B06vfJmFlm7T15Fd6QlWqEVH15hGoObzAz1aF750d6zwHQguBDn/VEGIkLtLtyWQAgOMuElr0oO5XJQgvEO+yxZhOjS9SiDys2S4tokdALakd5Xd6li0Kahnf4M/ouj7WOQacM3Ofc0nz2fZsvzn/H0Ow+igBjTJYWc2KhgaF7+k7YAIubyxzFxZbvTrwV2Wv2zEnG1XCH5RgKXwt5UKGDVncaNBPb
Hello,
You can define isPrefixOf as an inductive predicate :
Inductive isPrefixOf {A:Type}: relation (list A) :=
pf1 : forall x, isPrefixOf nil x
| pf2 : forall a x y, isPrefixOf x y -> isPrefixOf (a::x) (a::y).
Then prove a small inversion lemma:
Lemma isPrefix_inv {A:Type} (x y: list A) (a b:A) :
isPrefixOf (a::x) (b::y) -> a = b /\ isPrefixOf x y.
Proof. inversion 1; auto. Qed.
Then you prove an equivalence between this definition and your sig definition (by induction on the lists, and applications of IsPrefix_inv).
Lemma isPrefixOf_ok {A} (x y:list A) : isPrefixOf x y -> {z | x ++ z = y}.
Lemma isPrefixOf_okR {A} (x y z:list A) : x ++ z = y -> isPrefixOf x y.
Best regards,
Pierre
Le 10 août 2020 à 05:55, Agnishom Chattopadhyay <agnishom AT cmi.ac.in> a écrit :I have a function that is something like this:Definition isPrefixOf (x : list A) (y : list A) :=
exists z, x ++ z = y.Now, I want to define a witness function. Informally, it can be described as follows: Given x and y such that (isPrefixOf x y), return z which satisfies the criteria exists z, x ++ z = y.I would try to define it this way, but that would not work (possibly because exists z, x ++ z = y is a Prop and we are asking for something in Type) :Definition witness (x y : list A) {H : isPrefixOf x y} : list A.
destruct H.Abort.Another option seems to be to defineDefinition isPrefixOf (x y : list A) :=
sig (fun z => x ++ z = y).But I do not like this because this does not let me define things like Instance isPrefixOf_PreOrder : PreOrder isPrefixOf.So, how can I have my cake and eat it too?
- [Coq-Club] How can I extract data from this exists Prop?, Agnishom Chattopadhyay, 08/10/2020
- Re: [Coq-Club] How can I extract data from this exists Prop?, Guillaume Melquiond, 08/10/2020
- Re: [Coq-Club] How can I extract data from this exists Prop?, Castéran Pierre, 08/10/2020
- Re: [Coq-Club] How can I extract data from this exists Prop?, Agnishom Chattopadhyay, 08/10/2020
- Re: [Coq-Club] How can I extract data from this exists Prop?, Emilio Jesús Gallego Arias, 08/25/2020
- Re: [Coq-Club] How can I extract data from this exists Prop?, Agnishom Chattopadhyay, 08/25/2020
- Re: [Coq-Club] How can I extract data from this exists Prop?, jonikelee AT gmail.com, 08/25/2020
- Re: [Coq-Club] How can I extract data from this exists Prop?, Robbert Krebbers, 08/25/2020
- Message not available
- Message not available
- Re: [Coq-Club] How can I extract data from this exists Prop?, jonikelee AT gmail.com, 08/25/2020
- Re: [Coq-Club] How can I extract data from this exists Prop?, jonikelee AT gmail.com, 08/26/2020
- Re: [Coq-Club] How can I extract data from this exists Prop?, Arthur Azevedo de Amorim, 08/26/2020
- Re: [Coq-Club] How can I extract data from this exists Prop?, Robbert Krebbers, 08/27/2020
- Re: [Coq-Club] How can I extract data from this exists Prop?, jonikelee AT gmail.com, 08/27/2020
- Re: [Coq-Club] How can I extract data from this exists Prop?, jonikelee AT gmail.com, 08/25/2020
- Message not available
- Message not available
- Re: [Coq-Club] How can I extract data from this exists Prop?, Robbert Krebbers, 08/25/2020
Archive powered by MHonArc 2.6.19+.