Skip to content
Snippets Groups Projects
Commit 595edcf5 authored by Robbert Krebbers's avatar Robbert Krebbers
Browse files

Tweak.

parent 513d2cd7
No related branches found
No related tags found
No related merge requests found
...@@ -4,45 +4,42 @@ From iris.heap_lang Require Import proofmode notation. ...@@ -4,45 +4,42 @@ From iris.heap_lang Require Import proofmode notation.
From osiris.utils Require Import list. From osiris.utils Require Import list.
From osiris.examples Require Import list_sort. From osiris.examples Require Import list_sort.
Definition cmpZ : val :=
λ: "x" "y", "x" "y".
Section list_sort_instances. Section list_sort_instances.
Context `{!heapG Σ, !proto_chanG Σ} (N : namespace). Context `{!heapG Σ, !proto_chanG Σ} (N : namespace).
(* Example: Sort of integers *) (* Example: Sort of integers *)
Definition IZ (x : Z) (v : val) : iProp Σ := Definition IZ (x : Z) (v : val) : iProp Σ := v = #x⌝%I.
⌜∃ w, v = LitV $ LitInt w x = w⌝%I.
Definition compareZ : val :=
λ: "x" "y", "x" "y".
Lemma compareZ_spec : cmp_spec IZ () compareZ. Lemma cmpZ_spec : cmp_spec IZ () cmpZ.
Proof. Proof.
iIntros (x x' v v' Φ) "!>". rewrite /IZ. iIntros (x x' v v' Φ [-> ->]) "!> HΦ".
iIntros ([[w [-> ->]] [w' [-> ->]]]) "HΦ". wp_lam. wp_pures. by iApply "HΦ".
wp_lam. wp_pures. iApply "HΦ". eauto 10 with iFrame.
Qed. Qed.
Local Arguments val_encode _ _ !_ /. Local Arguments val_encode _ _ !_ /.
Lemma list_sort_client_le_spec l (xs : list Z) : Lemma list_sort_client_le_spec l (xs : list Z) :
{{{ l val_encode xs }}} {{{ l val_encode xs }}}
list_sort_client compareZ #l list_sort_client cmpZ #l
{{{ ys, RET #(); Sorted () ys ys xs l val_encode ys }}}. {{{ ys, RET #(); Sorted () ys ys xs l val_encode ys }}}.
Proof. Proof.
assert ( zs : list Z, val_encode zs = val_encode (LitV LitInt <$> zs)) as Henc. assert ( zs : list Z, val_encode zs = val_encode (LitV LitInt <$> zs)) as Henc.
{ intros zs. induction zs; f_equal/=; auto with f_equal. } { intros zs. induction zs; f_equal/=; auto with f_equal. }
iIntros (Φ) "Hl HΦ". iIntros (Φ) "Hl HΦ".
iApply (list_sort_client_spec N IZ () _ _ (LitV LitInt <$> xs) xs with "[] [Hl] [HΦ]"). iApply (list_sort_client_spec N IZ () _ _ (LitV LitInt <$> xs) xs with "[] [Hl] [HΦ]").
{ iApply compareZ_spec. } { iApply cmpZ_spec. }
{ rewrite -Henc. iFrame "Hl". { rewrite -Henc. iFrame "Hl".
iInduction xs as [|x xs] "IH"; csimpl; first by iFrame. iInduction xs as [|x xs] "IH"; csimpl; first by iFrame.
iFrame "IH". by iExists x. } by iFrame "IH". }
iIntros "!>" (ys ws) "(?&?&?&HI)". iIntros "!>" (ys ws) "(?&?&?&HI)".
iAssert ws = (LitV LitInt) <$> ys ⌝%I with "[HI]" as %->. iAssert ws = (LitV LitInt) <$> ys ⌝%I with "[HI]" as %->.
{ iInduction ys as [|y ys] "IH" forall (ws); { iInduction ys as [|y ys] "IH" forall (ws);
destruct ws as [|w ws]; csimpl; try done. destruct ws as [|w ws]; csimpl; try done.
iDestruct "HI" as "[HI1 HI2]"; iDestruct "HI1" as %(?&->&->). iDestruct "HI" as "[-> HI2]".
by iDestruct ("IH" with "HI2") as %->. } by iDestruct ("IH" with "HI2") as %->. }
rewrite -Henc. iApply ("HΦ" $! ys with "[$]"). rewrite -Henc. iApply ("HΦ" $! ys with "[$]").
Qed. Qed.
End list_sort_instances. End list_sort_instances.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment