Repository navigation
Expand file tree
/
Copy pathquorum.v
More file actions
57 lines (51 loc) · 2.05 KB
/
Copy pathquorum.v
File metadata and controls
57 lines (51 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
From Perennial.program_proof.tulip Require Import prelude.
From Goose.github_com.mit_pdos.tulip Require Import quorum.
(* Local Ltac Zify.zify_post_hook ::= Z.div_mod_to_equations. *)
Section cquorum.
Context `{!heapGS Σ}.
Theorem wp_ClassicQuorum (n : u64) :
{{{ True }}}
ClassicQuorum #n
{{{ (x : u64), RET #x; ⌜uint.Z x = (uint.Z n / 2 + 1)%Z⌝ }}}.
Proof.
(*@ func ClassicQuorum(n uint64) uint64 { @*)
(*@ // floor(n / 2) + 1 @*)
(*@ return n / 2 + 1 @*)
(*@ } @*)
iIntros (Φ) "_ HΦ".
wp_rec. wp_pures.
iApply "HΦ".
iPureIntro. word.
Qed.
(* The precondition enforces no overflow. *)
Theorem wp_FastQuorum (n : u64) :
uint.Z n < 2 ^ 62 ->
{{{ True }}}
FastQuorum #n
{{{ (x : u64), RET #x; ⌜uint.Z x = ((3 * uint.Z n + 3) / 4)%Z⌝ }}}.
Proof.
(*@ func FastQuorum(n uint64) uint64 { @*)
(*@ // ceiling(3n / 4) @*)
(*@ return (3 * n + 3) / 4 @*)
(*@ } @*)
iIntros (Hn Φ) "_ HΦ".
wp_rec. wp_pures.
iApply "HΦ".
iPureIntro. word.
Qed.
Theorem wp_Half (n : u64) :
uint.Z n < 2 ^ 64 - 1 ->
{{{ True }}}
Half #n
{{{ (x : u64), RET #x; ⌜uint.Z x = ((uint.Z n + 1) / 2)%Z⌝ }}}.
Proof.
(*@ func Half(n uint64) uint64 { @*)
(*@ // ceiling(n / 2) @*)
(*@ return (n + 1) / 2 @*)
(*@ } @*)
iIntros (Hn Φ) "_ HΦ".
wp_rec. wp_pures.
iApply "HΦ".
iPureIntro. word.
Qed.
End cquorum.