@@ -174,7 +174,7 @@ lemma dlist_fu (d: 'a distr) (xs:'a list):
174174 xs \i n dlist d (size xs).
175175proof.
176176move=> fu; rewrite /support dlist1E 1:size_ge0 /=.
177- by apply Bigreal.prodr_gt0_seq => /= a Hin _;apply fu.
177+ by apply Bigreal.prodr_gt0_seq => /= a Hin _; apply fu.
178178qed.
179179
180180lemma dlist_uni (d:' a distr) n :
@@ -333,10 +333,9 @@ qed.
333333
334334abstract theory Program.
335335 type t.
336- op d: t distr.
337336
338337 module Sample = {
339- proc sample(n:int): t list = {
338+ proc sample(d: t distr, n:int): t list = {
340339 var r;
341340
342341 r <$ dlist d n;
@@ -345,7 +344,7 @@ abstract theory Program.
345344 }.
346345
347346 module SampleCons = {
348- proc sample(n:int): t list = {
347+ proc sample(d: t distr, n:int): t list = {
349348 var r, rs;
350349
351350 rs <$ dlist d (n - 1);
@@ -355,7 +354,7 @@ abstract theory Program.
355354 }.
356355
357356 module Loop = {
358- proc sample(n:int): t list = {
357+ proc sample(d: t distr, n:int): t list = {
359358 var i, r, l;
360359
361360 i <- 0;
@@ -370,7 +369,7 @@ abstract theory Program.
370369 }.
371370
372371 module LoopSnoc = {
373- proc sample(n:int): t list = {
372+ proc sample(d: t distr, n:int): t list = {
374373 var i, r, l;
375374
376375 i <- 0;
@@ -384,63 +383,65 @@ abstract theory Program.
384383 }
385384 }.
386385
387- lemma pr_Sample _n &m xs: Pr[Sample.sample(_n) @ &m: res = xs] = mu (dlist d _n) (pred1 xs).
388- proof. by byphoare (_: n = _n ==> res = xs)=> //=; proc; rnd. qed.
386+ lemma pr_Sample _d _n &m xs:
387+ Pr[Sample.sample(_d, _n) @ &m: res = xs] = mu (dlist _d _n) (pred1 xs).
388+ proof. by byphoare (: d = _d /\ n = _n ==> res = xs)=> //=; proc; rnd. qed.
389389
390- equiv Sample_SampleCons_eq: Sample.sample ~ SampleCons.sample: 0 < n{1} /\ ={n} ==> ={res}.
390+ equiv Sample_SampleCons_eq: Sample.sample ~ SampleCons.sample: 0 < n{1} /\ ={d, n} ==> ={res}.
391391 proof.
392- bypr (res{1}) (res{2})=> //= &1 &2 xs [lt0_n] <-.
393- rewrite (pr_Sample n{1} &1 xs); case (size xs = n{1})=> [< <-|].
394- case xs lt0_n => [|x xs lt0_n]; 1: smt().
392+ bypr (res{1}) (res{2})=> //= &1 &2 xs [lt0_n] [] <- <-.
393+ rewrite (pr_Sample d{1} n{1} &1 xs); move: lt0_n; case (size xs = n{1})=> [<-|].
394+ + case: xs=> [|x xs lt0_n]; 1: smt().
395395 rewrite dlistS1E.
396- byphoare (_: n = size xs + 1 ==> x::xs = res)=> //=; 2: by rewrite addrC.
397- proc; seq 1: (rs = xs) (mu (dlist d (size xs)) (pred1 xs)) (mu d (pred1 x)) _ 0%r => //.
398- by rnd (pred1 xs); skip; smt().
399- by rnd (pred1 x); skip; smt().
400- by hoare; auto; smt().
401- smt().
402- move=> len_xs; rewrite dlist1E 1:/# ifF 1:/#.
396+ byphoare (: d = d{1} /\ n = size xs + 1 ==> x::xs = res)=> //=; 2: by rewrite addrC.
397+ proc; seq 1: (rs = xs) (mu (dlist d{1} (size xs)) (pred1 xs)) (mu d{1} (pred1 x)) _ 0%r (d = d{1}) => //.
398+ + by auto.
399+ + by rnd (pred1 xs); skip; smt().
400+ + by rnd (pred1 x); skip; smt().
401+ + by hoare; auto; smt().
402+ + smt().
403+ move=> len_xs gt0_n; rewrite dlist1E 1:/# ifF 1:/#.
403404 byphoare (_: n = n{1} ==> xs = res)=> //=; hoare.
404405 proc; auto=> />; smt(supp_dlist_size).
405406 qed.
406407
407- equiv Sample_Loop_eq: Sample.sample ~ Loop.sample: ={n} ==> ={res}.
408+ equiv Sample_Loop_eq: Sample.sample ~ Loop.sample: ={d, n} ==> ={res}.
408409 proof.
409410 proc*; exists* n{1}; elim* => _n.
410411 move: (eq_refl _n); case (_n <= 0)=> //= h.
411- + inline *;rcondf{2} 4 ;auto;smt (supp_dlist0 weight_dlist0).
412+ + inline *;rcondf{2} 5 ;auto;smt (supp_dlist0 weight_dlist0).
412413 have {h} h: 0 <= _n by smt ().
413- call (_: _n = n{1} /\ ={n} ==> ={res})=> //=.
414+ call (_: _n = n{1} /\ ={d, n} ==> ={res})=> //=.
414415 elim _n h=> //= [|_n le0_n ih].
415- proc; rcondf{2} 3; auto=> />. smt(supp_dlist0 weight_dlist0).
416+ + by proc; rcondf{2} 3; auto=> />; smt(supp_dlist0 weight_dlist0).
416417 case (_n = 0)=> [-> | h].
417- proc; rcondt{2} 3; 1:(by auto); rcondf{2} 6; 1:by auto.
418+ + proc; rcondt{2} 3; 1:(by auto); rcondf{2} 6; 1:by auto.
418419 wp; rnd (fun x => head witness x) (fun x => [x]).
419- auto => />;split => [ rR ? | _ rL ].
420+ auto => /> &0 ;split => [ rR ? | _ rL ].
420421 + by rewrite dlist1E //= big_consT big_nil.
421- rewrite supp_dlist //;case rL => //=; smt (size_eq0).
422+ by rewrite supp_dlist //;case rL => //=; smt (size_eq0).
422423 transitivity SampleCons.sample
423- (={n} /\ 0 < n{1} ==> ={res})
424- (_n + 1 = n{1} /\ ={n} /\ 0 < n{1} ==> ={res})=> //=; 1:smt().
425- by conseq Sample_SampleCons_eq.
424+ (={d, n} /\ 0 < n{1} ==> ={res})
425+ (_n + 1 = n{1} /\ ={d, n} /\ 0 < n{1} ==> ={res})=> //=; 1:smt().
426+ + by conseq Sample_SampleCons_eq.
426427 proc; splitwhile{2} 3: (i < n - 1).
427428 rcondt{2} 4; 1:by auto; while (i < n); auto; smt().
428429 rcondf{2} 7; 1:by auto; while (i < n); auto; smt().
429430 wp; rnd.
430431 outline {1} 1 ~ Sample.sample.
431432 rewrite equiv[{1} 1 ih].
432433 inline.
433- by wp; while (={i} /\ ={l } /\ n0{1} = n{2} - 1); auto; smt().
434+ by wp; while (={i, l } /\ d0{1} = d{2 } /\ n0{1} = n{2} - 1); auto; smt().
434435 qed.
435436
436- equiv Sample_LoopSnoc_eq: Sample.sample ~ LoopSnoc.sample: ={n} ==> ={res}.
437+ equiv Sample_LoopSnoc_eq: Sample.sample ~ LoopSnoc.sample: ={d, n} ==> ={res}.
437438 proof.
438439 proc*.
439440 replace* {1} { x } by { x; r <- rev r; }.
440441 inline *; wp; rnd rev; auto.
441442 smt(revK dlist_rev).
442443 rewrite equiv[{1} 1 Sample_Loop_eq].
443- inline *; wp; while (={i, n0} /\ rev l{1} = l{2}); auto => />.
444+ inline *; wp; while (={i, n0, d0 } /\ rev l{1} = l{2}); auto => />.
444445 smt(rev_cons cats1).
445446 qed.
446447end Program.
0 commit comments