Skip to content

Commit df28c85

Browse files
various improvements, per feedback
1 parent e2f9f50 commit df28c85

1 file changed

Lines changed: 27 additions & 66 deletions

File tree

theories/modules/TotalProb.ec

Lines changed: 27 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -86,40 +86,39 @@ seq 1 :
8686
(1%r - mu1 dt x')
8787
0%r
8888
(i = i' /\ (glob M) = (glob M){m}) => //.
89-
auto.
90-
rnd (pred1 x'); auto.
91-
call (_ : i = i' /\ x = x' /\ glob M = (glob M){m} ==> res).
92-
bypr => &hr [#] -> -> glob_eq.
93-
byequiv (_ : ={i, x, glob M} ==> ={res}) => //; sim.
94-
auto.
89+
+ auto.
90+
+ rnd (pred1 x'); auto.
91+
+ call (_ : i = i' /\ x = x' /\ glob M = (glob M){m} ==> res).
92+
+ bypr => &hr [#] -> -> glob_eq.
93+
byequiv (_ : ={i, x, glob M} ==> ={res}) => //; sim.
94+
+ auto.
9595
hoare; call (_ : true); auto; smt().
9696
qed.
9797
9898
lemma total_prob' (dt' : t distr) (supp : t list) (i' : input) &m :
99-
is_lossless dt' => is_finite_for (support dt') supp =>
99+
is_finite_for (support dt') supp =>
100100
Pr[Rand(M).f(dt', i') @ &m : res] =
101101
big predT
102102
(fun x' => mu1 dt' x' * Pr[M.main(i', x') @ &m : res])
103103
supp.
104104
proof.
105-
move => dt'_ll [uniq_supp supp_iff].
105+
move => [uniq_supp supp_iff].
106106
have -> :
107107
Pr[Rand(M).f(dt', i') @ &m : res] = Pr[RandAux.f(dt', i') @ &m : res].
108-
byequiv (_ : ={dt, i, glob M} ==> ={res}) => //; proc; sim.
108+
+ byequiv (_ : ={dt, i, glob M} ==> ={res}) => //; proc; sim.
109109
rewrite (EPL.list_partitioning RandAux (dt', i') E phi supp &m) //.
110110
have -> /= :
111111
Pr[RandAux.f(dt', i') @ &m: res /\ ! (x_of_glob_RA (glob RandAux) \in supp)] =
112112
0%r.
113-
byphoare (_ : dt = dt' /\ i = i' ==> _) => //; proc.
114-
seq 1 :
115-
(RandAux.x \in supp)
116-
1%r
117-
0%r
118-
0%r
119-
1%r => //.
120-
auto.
121-
hoare; call (_ : true); auto; smt().
122-
rnd pred0; auto; smt(mu0).
113+
+ byphoare (_ : dt = dt' /\ i = i' ==> _) => //; proc.
114+
seq 1 :
115+
(RandAux.x \in supp)
116+
1%r
117+
0%r
118+
0%r
119+
1%r => //.
120+
+ hoare; call (_ : true); auto; smt().
121+
rnd pred0; auto; smt(mu0).
123122
congr; apply fun_ext => x'; by rewrite RandAux_partition_eq.
124123
qed.
125124
@@ -128,15 +127,12 @@ end section.
128127
(*& total probability lemma for distributions with finite support &*)
129128
130129
lemma total_prob (M <: T) (dt : t distr) (supp : t list) (i : input) &m :
131-
is_lossless dt => is_finite_for (support dt) supp =>
130+
is_finite_for (support dt) supp =>
132131
Pr[Rand(M).f(dt, i) @ &m : res] =
133132
big predT
134133
(fun (x : t) => mu1 dt x * Pr[M.main(i, x) @ &m : res])
135134
supp.
136-
proof.
137-
move => dt_ll iff_supp_dt_supp.
138-
by apply (total_prob' M).
139-
qed.
135+
proof. move => iff_supp_dt_supp; by apply (total_prob' M). qed.
140136

141137
end TotalGeneral.
142138

@@ -156,8 +152,7 @@ lemma total_prob_bool (M <: T) (i : input) &m :
156152
Pr[M.main(i, false) @ &m : res] / 2%r.
157153
proof.
158154
rewrite (total_prob M DBool.dbool [true; false]) //.
159-
rewrite dbool_ll.
160-
smt(supp_dbool).
155+
+ smt(supp_dbool).
161156
by rewrite 2!big_cons big_nil /= /predT /predF /= 2!dbool1E.
162157
qed.
163158

@@ -171,22 +166,6 @@ clone include TotalGeneral with
171166
type t <- int
172167
proof *.
173168

174-
lemma big_weight_simp (M <: T) (m n : int, i : input, ys : int list) &m :
175-
(forall y, y \in ys => m <= y < n) =>
176-
big predT
177-
(fun (x : int) => mu1 (drange m n) x * Pr[M.main(i, x) @ &m : res])
178-
ys =
179-
big predT
180-
(fun (x : int) => Pr[M.main(i, x) @ &m : res] / (n - m)%r)
181-
ys.
182-
proof.
183-
elim ys => [// | y ys IH mem_impl].
184-
rewrite 2!big_cons (_ : predT y) //=.
185-
rewrite drange1E (_ : m <= y < n) 1:mem_impl //=.
186-
rewrite IH => [z z_in_ys | //].
187-
by rewrite mem_impl /= z_in_ys.
188-
qed.
189-
190169
(*& total probability lemma for `drange` &*)
191170

192171
lemma total_prob_drange (M <: T) (m n : int, i : input) &m :
@@ -198,10 +177,9 @@ lemma total_prob_drange (M <: T) (m n : int, i : input) &m :
198177
proof.
199178
move => lt_m_n.
200179
rewrite (total_prob M (drange m n) (range m n)).
201-
by rewrite drange_ll.
202-
rewrite /is_finite_for.
203-
smt(range_uniq mem_range supp_drange).
204-
rewrite (big_weight_simp M) //; by move => j /mem_range.
180+
+ rewrite /is_finite_for; smt(range_uniq mem_range supp_drange).
181+
apply eq_big_seq => x x_in_range_m_n /=.
182+
by rewrite drange1E (_ : m <= x < n) 1:-mem_range.
205183
qed.
206184

207185
end TotalRange.
@@ -218,23 +196,6 @@ clone include TotalGeneral with
218196
type t <- t
219197
proof *.
220198

221-
lemma big_weight_simp (M <: T) (xs : t list, i : input, ys : t list) &m :
222-
uniq xs =>
223-
(forall y, y \in ys => y \in xs) =>
224-
big predT
225-
(fun (x : t) => mu1 (duniform xs) x * Pr[M.main(i, x) @ &m : res])
226-
ys =
227-
big predT
228-
(fun (x : t) => Pr[M.main(i, x) @ &m : res] / (size xs)%r)
229-
ys.
230-
proof.
231-
move => uniq_xs.
232-
elim ys => [// | y ys IH mem_impl].
233-
rewrite 2!big_cons (_ : predT true) //=.
234-
rewrite duniform1E_uniq // (_ : y \in xs) 1:mem_impl //=.
235-
rewrite IH => [z z_in_ys | //]; by rewrite mem_impl /= z_in_ys.
236-
qed.
237-
238199
(*& total probability lemma for `duniform` &*)
239200

240201
lemma total_prob_uniform (M <: T) (xs : t list, i : input) &m :
@@ -246,9 +207,9 @@ lemma total_prob_uniform (M <: T) (xs : t list, i : input) &m :
246207
proof.
247208
move => uniq_xs xs_ne_nil.
248209
rewrite (total_prob M (duniform xs) xs).
249-
by rewrite duniform_ll.
250-
smt(supp_duniform).
251-
by rewrite (big_weight_simp M).
210+
+ smt(supp_duniform).
211+
apply eq_big_seq => y y_in_xs /=.
212+
by rewrite duniform1E_uniq // (_ : y \in xs).
252213
qed.
253214

254215
end TotalUniform.

0 commit comments

Comments
 (0)