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: "jonikelee AT gmail.com" <jonikelee AT gmail.com>
  • To: Robbert Krebbers <mailinglists AT robbertkrebbers.nl>, coq-club <coq-club AT inria.fr>
  • Subject: Re: [Coq-Club] How can I extract data from this exists Prop?
  • Date: Tue, 25 Aug 2020 16:31:10 -0400
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=jonikelee AT gmail.com; spf=Pass smtp.mailfrom=jonikelee AT gmail.com; spf=None smtp.helo=postmaster AT mail-qt1-f173.google.com
  • Ironport-phdr: 9a23:UR4ChhTqSWDapW4Gxfbhe1lR5dpsv+yvbD5Q0YIujvd0So/mwa67ZBaCt8tkgFKBZ4jH8fUM07OQ7/m+HzVaud3Y7SlKWacPfidNsd8RkQ0kDZzNImzAB9muURYHGt9fXkRu5XCxPBsdMs//Y1rPvi/6tmZKSV3wOgVvO+v6BJPZgdip2OCu4Z3TZBhDiCagbb9oIxi6sATcutMLjYd8Nqo9xQbFr3tVd+9L2W5mOFWfkgrm6Myt5pBj6SNQu/wg985ET6r3erkzQKJbAjo7LW07/dXnuhbfQwSB4HscSXgWnQFTAwfZ9hH6X4z+vTX8u+FgxSSVJ8z2TbQzWTS/86dmTQLjhSkbOzIl9mzcl8p9h79Zrh28vRxy24DaboGLOvRjfa3Sf90aS21OUclNWCJMGZ+8b5IVAuYdJ+tUs4vwql0TphW+HwmsA+bvxydGin/02q061eUhEQLY0wwkAd0Brm/ZrNrwNKgIUOC1yLPEwinEb/NT1zv29Y/FchImofGKXLJwctTeyU0xGAzblViQponlMCmU1uQJqWSU8+1gVee2hmMhtgp+rSShyN02hYnVmoIa1ErE9SNhzYg6JdO0VEp2bMKkHZZMtiyXKoR4T948T2x0tis31qMLtIKmcCQXyZkq2wLSZ+CIfYaG/B/vSeicLzd6iX95Zb6ygQu5/0anyu35TMa00VBKozJEktnKrHAN1gbc5tKJSvtn5kuh3C6P1wHK5uFfL0E0jrDXK5k7wr4/kJcYrEfNHjfulUnokKObcl8o9+uo5uj9f7nrp4OQO5Vphgz8PKkigtKzDOUkPgQTWmWX5OCx26Hm8ED2QbhGkuE6n6zEvJ/GJMkWo7W2DgxJ3Yk+7huwFDir0NoWnXQCIlJKZg+IgJXsNlzOLvD3Ee2wjlKxmzlx3f/GJKfuApDVI3jDjrjhebF95lZZyAUpzNBf44tYCqgdIP7uQ0PxusHUAx03PgCuzObnD9J91owaWW2RGKOWLKTSsVqQ6uIuJemDepMVtS7jJ/Q54/Pil3w0lF8HcaW03JYbdGq0EulkLkiXeXbsh80OEWYOvgowVuzqj1iCXCZRZ3a1WaI85zI7B5yiDYjdWI+gm7OB3CKhEZ1XYmBKEEyDEXDtd4mcQfcDdDqSItN9kjwDTbWuV4gh1Qi3uADmz7pnM/Hb9zYDtZPj0dh1//fcmQsz9TxyFcSd0nuCQ3t6nmMSFHcK2/VFpkZ3x02fmYtijvZSGMZIr6dMWwY+NJjTy+1hF8vaQAXLdNqTVFW8T9+sDCsqCNQ1lZtGaEFkXt6mkxqLiyGtGvoek6GBLJ0y6KPVmXbrcZVT0XHDgeMjiF8nQcZLOGCOiat29gyVDInM2Q3NlaGsdKcR2CPA3GiGxGuK+kpfVVgjAu3+QXkDax6O/pzC7UTYQur2UOV1Ak560ceHb5ByRJjshFRCSu3kPY2HMW20kma0Qx2Pw+HVNda4SyAmxCzYTXM8vUUL53/fbFoxAy6gpyTVCzk8TQuyMXOpyvF3rTaAdmFxzwyOaBc/hb+8+xpQnODFDv1KgelCtyAmpDF5Wl262oCOBg==

Oh - sorry, it wasn't intended to be off-list. Thanks for the detailed
explanation.

On Tue, 25 Aug 2020 20:58:12 +0200
Robbert Krebbers <mailinglists AT robbertkrebbers.nl> wrote:

> Not sure if this was intended to be off-list.
>
> It's like that, but more complicated for the general case. Since bool
> is finite, termination is trivial. For types are are countable, not
> non-finite, (take p : nat → bool) you need to find a suitable
> termination measure.
>
> On 8/25/20 8:54 PM, jonikelee AT gmail.com wrote:
> > On Tue, 25 Aug 2020 20:37:47 +0200
> > Robbert Krebbers <mailinglists AT robbertkrebbers.nl> wrote:
> >
> >> The mentioned proof makes use of the following theorem:
> >>
> >> (∃ x : A, P x) → { x : A | P x }
> >>
> >> under the assumption that 1.) A is countable, and 2.) the predicate
> >> is decidable.
> >
> > I see. I missed that there was a double "==" in isPrefixOf. Ok, so
> > this is just something like:
> >
> > Definition extract{P : bool -> bool}(e : exists b, P b = true) : {b
> > | P b = true}. Proof.
> > assert bool as b by constructor.
> > destruct (P b) eqn:E.
> > - exists b. exact E.
> > - destruct (P (negb b)) eqn:E2.
> > + exists (negb b). exact E2.
> > + exfalso. destruct e as (b' & F), b, b'.
> > all:cbn in *. all:congruence.
> > Defined.
> >
> > OK - not as magical as I thought. Thanks.
> >
> >>
> >> This theorem holds intuitively because you can write an algorithm
> >> that searches for the witness. Because A is countable, it can
> >> simply enumerate all elements. Then, because P is decidable, it
> >> can test for each element if P holds or not. Now, since (∃ x : A,
> >> P x) holds, this algorithm will terminate, i.e. finally find a
> >> witness.
> >>
> >> The Coq standard library also includes a version of this theorem,
> >> see
> >> https://coq.inria.fr/distrib/current/stdlib/Coq.Logic.ConstructiveEpsilon.html
> >>
> >> Also std++ includes a version of this theorem, see
> >> https://gitlab.mpi-sws.org/iris/stdpp/-/blob/master/theories/countable.v#L84
> >>
> >> choiceType in ssreflect (or the Countable type class in std++)
> >> expresses that a type is countable, and is used to automatically
> >> infer assumption (1) in the above theorem.
> >>
> >> Hope this helps!
> >>
> >> On 8/25/20 8:27 PM, jonikelee AT gmail.com wrote:
> >>> Can someone explain to a non-ssreflect/non-mathcomp user how
> >>> choiceType works? It looks like it must rely on an axiom. Are
> >>> there any types that fulfill it? For example, is there a
> >>> non-axiomatic way in which bool is a choiceType?
> >>>
> >>> Because, the ability to pull the necessary x out of "exists x, P
> >>> x" seems magical. How would a program using this extract?
> >>>
> >>> On Tue, 25 Aug 2020 19:15:14 +0200
> >>> Emilio Jesús Gallego Arias <e AT x80.org> wrote:
> >>>
> >>>> Hi Agnishom,
> >>>>
> >>>> Agnishom Chattopadhyay <agnishom AT cmi.ac.in> writes:
> >>>>
> >>>>> 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.
> >>>>
> >>>> If you can afford to work with a type A which has a notion of
> >>>> choice principle you can indeed write your witness function.
> >>>> Example:
> >>>>
> >>>> From mathcomp Require Import all_ssreflect.
> >>>>
> >>>> Set Implicit Arguments.
> >>>> Unset Strict Implicit.
> >>>> Unset Printing Implicit Defensive.
> >>>>
> >>>> Variable (A : choiceType).
> >>>>
> >>>> Definition isPrefixOf (x : list A) (y : list A) :=
> >>>> exists z, x ++ z == y.
> >>>>
> >>>> Definition extract x y (w : isPrefixOf x y) : list A := xchoose
> >>>> w.
> >>>>
> >>>> Kind regards,
> >>>> Emilio
> >>>
> >




Archive powered by MHonArc 2.6.19+.

Top of Page