Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] How can I extract data from this exists Prop?

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] How can I extract data from this exists Prop?


Chronological Thread 
  • From: Agnishom Chattopadhyay <agnishom AT cmi.ac.in>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] How can I extract data from this exists Prop?
  • Date: Mon, 10 Aug 2020 12:26:40 -0500
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=agnishom AT cmi.ac.in; spf=Pass smtp.mailfrom=agnishom AT cmi.ac.in; spf=None smtp.helo=postmaster AT mail.cmi.ac.in
  • Ironport-phdr: 9a23:m1JDfxc1d+0cMG7DfIMEwr3ulGMj4u6mDksu8pMizoh2WeGdxcS4bR7h7PlgxGXEQZ/co6odzbaP7eawCSdZuM3JmUtBWaQEbwUCh8QSkl5oK+++Imq/EsTXaTcnFt9JTl5v8iLzG0FUHMHjew+a+SXqvnYdFRrlKAV6OPn+FJLMgMSrzeCy/IDYbxlViDanbr5+MRS7oR/Su8QVjoduN7s9xxXUqXZUZupawn9lK0iOlBjm/Mew+5Bj8yVUu/0/8sNLTLv3caclQ7FGFToqK2866tHluhnFVguP+2ATUn4KnRpSAgjK9w/1U5HsuSbnrOV92S2aPcrrTbAoXDmp8qlmRAP0hCoBKjU09nzchM5tg6JBuB+uqBJ/zIzUbo+bN/RwY73Tcs8BSGVbQspcTTZMDp+gY4YNCecKIOZWr5P6p1sLtRazGQasBOXuyj9Thn/22qg62Pk/HAHGxgMgA84OsHPMrNrvKagSUeC0w7PIzD7eaP5Zwzj96I7JchA6ofGMWrdwfNHNxkkqFgPJlE+fppD/MzOU0OQAqm6W5PdvWuyzkWAosR1xoiSxycc2jInEnoIbx03Y+Sllz4s4IcC0RU50bNO4FJZcqSGXOYRrTs0sTWxlvCY3x6MGtJC7fCUEyIoqygDBZvCacoWF4xzuWeWXLDxlh3xlYKqyiwus/UWu0OHxV8e53ExUoiZZnNTArG4B2wHN5sSfVPdx4kOs1SyM2g3T8O1IPEE5mKvBJ5I8wbM8ipweulnZECDsgkX5lqqWe10k+ue27+TnZa3rppqGOI91jgHyKLghmsm+AegiKAcBQ3KX+eW61LH7/E35RqtFjuEun6XErpzXK94Xq6+3DgNPzIov9xiyAy243NgFg3ULNFdFdwiGj4jtNVHOOvf4DfKnjlu2nzdrwfHGPqbhApXKK3jOi6vufbN860JG0gU80cpT55NSCr0ZOvL8RlfxtMDEDh8+KwG73+HnCMxk2owCXWKPH7SWPbjJsV6I4+IvO/ODaJUUuDb7Mfgl5uThgWU3mV8HLuGV2s4cb2n9FfB7KW2YZ2Dti5EPCzQkpA07GcXljlyZUTlWL12yVr4g4SkyBIK3BJaLEomihr2a3CC+NpZTZyZPARaNFyG7JM2/R/4QZXfKcYdamTseWO35EtJz5VSVrAb/joFfAK/U9ykf7Myx0dF046vYkBB0/DcyDsLPizjRHVExpXsBQnoN5I46uVZ0kw7R2q15xfVTU91VtasQA1UKcKXExuk/MOjcHwfIf9OHUlGjG4z0CjQwCNs6hd4IMR9w

Thank You. These are both great ideas. However, what I presented was a simplification of what I actually wanted. I am trying to define prefixes in the context of trace monoids (i.e, lists in which certain shufflings are allowed), in which case Definition witness (x y : list A) := skipn (length x) y. does not hold.

Probably the best I can do is to work with the type
sig (fun z => x ++ z = y).

This has the downside that I can't use definitions like PartialOrder from the standard library.


On Mon, Aug 10, 2020 at 4:01 AM Castéran Pierre <pierre.casteran AT gmail.com> wrote:
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 define

Definition 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?




Archive powered by MHonArc 2.6.19+.

Top of Page