Skip to Content.
Sympa Menu

coq-club - [Coq-Club] Certified insertion

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

[Coq-Club] Certified insertion


Chronological Thread 
  • From: Klaus Ostermann <klaus.ostermann AT uni-tuebingen.de>
  • To: coq-club AT inria.fr
  • Subject: [Coq-Club] Certified insertion
  • Date: Sat, 8 Dec 2018 15:22:10 +0100
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=klaus.ostermann AT uni-tuebingen.de; spf=Pass smtp.mailfrom=klaus.ostermann AT uni-tuebingen.de; spf=None smtp.helo=postmaster AT mx03.uni-tuebingen.de
  • Ironport-phdr: 9a23:08EbThOwutyehLFdQq0l6mtUPXoX/o7sNwtQ0KIMzox0Lfv9rarrMEGX3/hxlliBBdydt6oUzbKO+4nbGkU4qa6bt34DdJEeHzQksu4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2aFLduGC94iAPERvjKwV1Ov71GonPhMiryuy+4ZLebxlLiTanfb9+MAi9oBnMuMURnYZsMLs6xAHTontPdeRWxGdoKkyWkh3h+Mq+/4Nt/jpJtf45+MFOTav1f6IjTbxFFzsmKHw65NfqtRbYUwSC4GYXX3gMnRpJBwjF6wz6Xov0vyDnuOdxxDWWMMvrRr0yRD+s7bpkSAXwhSkZNzA37WLZhMJ+g61UvB2vqAdyw5LXbYyPKPZyYq3QcNEcSGFcXshRTStBAoakYoUKC+oOJ/tYr5LgrFUXthu+GRejBPnqyjBSgH/227Ax3uMiEQHCxgMgAskOvG7TrNXuKKcdT/q1zKzSwjXFafNbwir96I7Jchw4vfGMQKx/ftHQyUkpGAPKkFOQpZb4MDyLz+kAtXWQ4el4Ve+3lmIqpQ58riKxyss2ioTFnJwZxk3K+Clhz4s4JMe0RU5hbdK6EJZdtzuWO5V4T84iRWxjpTw0xaccuZGheSgH0JQnyADba/yAa4WI5x3iWPqfLDtimXJlfrO/iw+u8Ui91OLzTci00FBFriVblNnArG0C2ALL5siGTPty4Fuh1C6S2w3d5exIO144mbDbJpI73LI8i5QevVzGHiDsmUX2iKGWdl8j+uit8+nnYbHmqYWBN49vkA3+Nb8umtChDuQiNwgBRW6b+eKn2b3++035QaxGjuErkqbHq5/aJMIbpqGnDA9TyIos9giwAy+80NsEhXkHME5FeBWfgof1PFHOOen0Auu7g1Sxizhm3OvGP73kApXVNHfPirbhfbBn605d0gU/195f54gHQo0Gdfn0Qwr6sMHSJh4/KQ29hej9W/tn0YZLemaGH7TRF7jOvEWN7+Qpa72PYIYIo3D6MOQo/fvni3kRhFkcOLW00JEWbn+1GLJqLhPKMjLXnt4dHDJS7UIFR+vwhQjaCG8BVzOJR6s5owoDJsejBIbHSJqqheXRjjq9H9hKe21MC1aDHHGue4jWAq5QOhLXGddol3k/bZbkU5UojEH8qQn7jqZ6I+DV/CIVs9Tv2YotvrCBpVQJ7TVxSv+l/SSNQmVzxDhaQi9uh+Zip0041kqO26l+jPFeU9BetatE
  • Openpgp: preference=signencrypt

I'm making a few experiments with using subset types for "certified
programming".

I'm stuck with a certified variants of the "insert" function as used in
insertion sort, that is,
it's type should say that the input list and output list are sorted and
that the output list
contains both the input list and the element to be inserted.

Could somebody tell me how to do this idiomatically in Coq, preferably
without using
"dependent destruction" and other tactics that require additional
axioms? I'm stuck on
how to make the case distinction on whether the element to be inserted
is less than or eqal
to the first element. Presumably this requires a fancy "return" annotation?

Inductive Sorted : list nat -> Prop :=
    | Sorted_nil : Sorted []
    | Sorted_cons1 a : Sorted [a]
    | Sorted_consn a b l :
        Sorted (b :: l) -> a <= b -> Sorted (a :: b :: l).

Definition sortedOf(l: list nat)(q: list nat) := Sorted q /\ forall m,
In m l <-> In m q.

Fixpoint insert(n: nat)(l: { q: list nat | Sorted q}) : { q: list nat |
sortedOf (cons n (proj1_sig l)) q}.   
refine(  match l return { q: list nat | sortedOf (cons n (proj1_sig l))
q} with
  | exist [] st =>  _
  | exist (cons x xs) st => _
  end).
- refine (exist _ [n] _). split.  constructor. intros. split; intros. 
simpl in H ; destruct H ; subst; constructor; auto. inversion H.
  constructor. inversion H ; subst; auto. inversion H0.
-  (* stuck here; how to make the case distinction on whether n <= x ? )


Klaus




Archive powered by MHonArc 2.6.18.

Top of Page