Skip to content

Commit 8288b26

Browse files
committed
Mapreduce paper simple examples
1 parent 141589d commit 8288b26

3 files changed

Lines changed: 116 additions & 16 deletions

File tree

examples/mapreduce_paper.ec

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
require import AllCore Bool IntDiv CoreMap List Distr QFABV.
2+
from Jasmin require import JModel JArray.
3+
4+
5+
bind bitstring W8.w2bits W8.bits2w W8.to_uint W8.to_sint W8.of_int W8.t 8.
6+
realize size_tolist by auto.
7+
realize tolistP by auto.
8+
realize oflistP by admit.
9+
realize ofintP by admit.
10+
realize touintP by admit.
11+
realize tosintP by admit.
12+
13+
bind op W8.t W8.(+^) "xor".
14+
realize bvxorP by admit.
15+
16+
op bool2bits (b : bool) : bool list = [b].
17+
op bits2bool (b: bool list) : bool = List.nth false b 0.
18+
19+
op i2b (i : int) = (i %% 2 <> 0).
20+
op b2si (b: bool) = 0.
21+
22+
bind bitstring bool2bits bits2bool b2i b2si i2b bool 1.
23+
realize size_tolist by auto.
24+
realize tolistP by auto.
25+
realize oflistP by admit.
26+
realize ofintP by admit.
27+
realize touintP by admit.
28+
realize tosintP by auto.
29+
30+
bind op bool (^^) "add".
31+
realize bvaddP by admit.
32+
33+
op predT_bool : bool -> bool = fun _ => true.
34+
op xor1_bool (b: bool) = b ^^ true.
35+
36+
op xor_left (w1 : W8.t) =
37+
(w1 +^ (W8.of_int 42)) +^ (W8.of_int 213).
38+
39+
op xor_right (w1 : W8.t) =
40+
w1 +^ ((W8.of_int 42)) +^ (W8.of_int 213).
41+
42+
op xor_left_spec : W8.t -> W8.t.
43+
44+
bind circuit xor_left_spec "XOR_LEFT8".
45+
46+
op predT_W8 : W8.t -> bool = fun _ => true.
47+
48+
module M = {
49+
proc xor_left_proc (w1: W8.t) = {
50+
w1 <- w1 +^ (W8.of_int 42);
51+
w1 <- w1 +^ (W8.of_int 213);
52+
return w1;
53+
}
54+
55+
proc xor_right_proc (w1: W8.t) = {
56+
var w2 : W8.t;
57+
w2 <- (W8.of_int 42);
58+
w2 <- w2 +^ (W8.of_int 213);
59+
w1 <-w1 +^ w2;
60+
return w1;
61+
}
62+
}.
63+
64+
lemma xor_left_corr (w: W8.t) :
65+
hoare [ M.xor_left_proc : w = w1 ==> res = xor_left w].
66+
proof.
67+
proc.
68+
bdep 8 8 [w] [w1] [w1] xor_left predT_W8.
69+
admit.
70+
admit.
71+
qed.
72+
73+
lemma xor_left_equiv_xor_right_proc (w: W8.t) :
74+
equiv [ M.xor_left_proc ~ M.xor_right_proc : w = arg{1} /\ arg{1} = arg{2} ==> res{1} = res{2} ].
75+
proof.
76+
proc.
77+
bdepeq 8 [w1] [w1] {8 : [w1 ~ w1]} predT_W8.
78+
admit.
79+
auto.
80+
qed.
81+
82+
lemma xor_left_equiv_xor_right_proc_lanes (w: W8.t) :
83+
equiv [ M.xor_left_proc ~ M.xor_right_proc : w = arg{1} /\ arg{1} = arg{2} ==> res{1} = res{2} ].
84+
proof.
85+
proc.
86+
bdepeq 1 [w1] [w1] {1 : [w1 ~ w1]} predT_bool.
87+
admit.
88+
auto.
89+
qed.
90+
91+
92+
lemma xor_left_corr_lanes (w: W8.t) :
93+
hoare [ M.xor_left_proc : w = w1 ==> res = xor_left w].
94+
proof.
95+
proc.
96+
bdep 1 1 [w] [w1] [w1] xor1_bool predT_bool.
97+
admit.
98+
admit.
99+
qed.
100+
101+
lemma xor_left_corr_spec (w: W8.t) :
102+
hoare [ M.xor_left_proc : w = w1 ==> res = xor_left w].
103+
proof.
104+
proc.
105+
bdep 8 8 [w] [w1] [w1] xor_left_spec predT_W8.
106+
admit.
107+
admit.
108+
qed.

flake.nix

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
nixpkgs.url = "github:nixos/nixpkgs/24.05";
88
stable.url = "github:nixos/nixpkgs/24.05";
99
nixpkgs.follows = "opam-nix/nixpkgs";
10-
emacs-overlay.url = "github:nix-community/emacs-overlay";
1110

1211
prover_cvc4_1_8 = {
1312
url = "github:CVC4/CVC4-archived/1.8";
@@ -20,7 +19,7 @@
2019
};
2120

2221
prover_z3_4_12_6 = {
23-
url = "github:z3prover/z3/z3-4.13.3";
22+
url = "github:z3prover/z3/z3-4.12.6";
2423
flake = false;
2524
};
2625
};
@@ -110,19 +109,5 @@
110109
++ [ pkgs.git scope'.why3 packages.provers ]
111110
++ (with pkgs.python3Packages; [ pyyaml ]);
112111
};
113-
114-
devShells.withDevTools = pkgs.mkShell rec {
115-
inputsFrom = [ scope'.easycrypt ];
116-
buildInputs =
117-
devPackages
118-
++ devTools
119-
++ [ scope'.why3 packages.provers ]
120-
++ (with pkgs.python3Packages; [ pyyaml ]);
121-
SHELL = ''${pkgs.bashInteractive + "/bin/bash"}'';
122-
shellHook = builtins.replaceStrings ["\n"] [" "] ''
123-
export SHELL=${SHELL} &&
124-
export PATH=$PATH:`realpath .`
125-
'';
126-
};
127112
});
128113
}

libs/lospecs/specs/avx2.spec

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,3 +431,10 @@ VPSHUFB_128(w@128, widx@128) -> @128 =
431431
fun idx@8 . idx[7] ? 0 : w[@8|idx[@4|0]],
432432
widx
433433
)
434+
435+
# MAPREDUCE EXAMPLE
436+
XOR_LEFT8(w@8) -> @8 =
437+
xor<8>(xor<8>(w, 42@8), 213@8)
438+
439+
XOR_RIGHT8(w@8) -> @8 =
440+
xor<8>(w, xor<8>(42@8, 213@8))

0 commit comments

Comments
 (0)