Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coneris flip #45

Merged
merged 69 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
351d7e8
Progres with flip_spec
hei411 Sep 17, 2024
4396686
Progress with flip_spec
hei411 Sep 17, 2024
b13e398
hocap flip spec
hei411 Sep 17, 2024
eb5024b
Basic template for impl2 with flip
hei411 Sep 17, 2024
f2d886e
new_counter_spec2
hei411 Sep 17, 2024
ee83b1b
Progress on impl 2, getting stuck a bit
hei411 Sep 17, 2024
bf4565a
another try?
hei411 Sep 17, 2024
0a5480f
first rough sketch of proof of impl2
hei411 Sep 19, 2024
4f74c4f
allocate_tape_spec2
hei411 Sep 19, 2024
2248da2
read_counter_spec2
hei411 Sep 19, 2024
a227713
NIT
hei411 Sep 19, 2024
e1027da
strengthen flip_tape_spec_some
hei411 Sep 19, 2024
c618b3b
Progress with incr counter tape spec some 2
hei411 Sep 19, 2024
0236bcc
progress with incr counter tape spec some 2
hei411 Sep 19, 2024
b602e83
impl2 refaactor
hei411 Sep 20, 2024
45b4474
flip presample spec simple
hei411 Sep 20, 2024
c0be184
Progress with flip presample spec
hei411 Sep 20, 2024
4dc3f50
Progress with changing hocap RA to authR, TODO: fix rand counter inte…
hei411 Sep 20, 2024
fe3ce88
BIG refactor, a lot of code commented out
hei411 Sep 20, 2024
14b179e
first attempt with hocap rand
hei411 Sep 23, 2024
758b6d5
progress with hocap rand
hei411 Sep 23, 2024
c6361a9
NIT
hei411 Sep 23, 2024
3058483
hocap rand progress
hei411 Sep 24, 2024
8ab40cc
finish hocap rand
hei411 Sep 24, 2024
e611498
hocap rand
hei411 Sep 24, 2024
fc7ad54
Slight improvement on spec
hei411 Sep 25, 2024
1e707a7
fix build
hei411 Sep 25, 2024
acfcf79
NIT
hei411 Sep 25, 2024
48ada79
Nicer
hei411 Sep 25, 2024
66f966a
hocap rand with simons suggestion
hei411 Sep 25, 2024
dfceb3f
remove file
hei411 Sep 25, 2024
d2d6f4f
FLIP
hei411 Sep 25, 2024
ef8d71f
NIT
hei411 Sep 25, 2024
4dbc843
interface spec of random counter
hei411 Sep 26, 2024
cbdb969
Better spec
hei411 Sep 26, 2024
690707a
Simplify spec by removing P
hei411 Sep 26, 2024
fb3f8f7
NIT
hei411 Sep 26, 2024
9200128
NIT
hei411 Sep 26, 2024
95f38e6
NIT
hei411 Sep 26, 2024
357f87c
lemma incr_counter_tape_spec_none
hei411 Sep 27, 2024
d0d1865
sequential spec incr_counter_tape_spec_none'
hei411 Sep 27, 2024
a75cb86
Progress with impl1
hei411 Sep 27, 2024
22b341b
fix spec of incr_counter_tape_spec_some
hei411 Sep 27, 2024
a3a2151
incr_counter_tape_spec_some1
hei411 Sep 27, 2024
140171c
counter_presample_spec1
hei411 Sep 27, 2024
7d7d463
complete impl1
hei411 Sep 27, 2024
5dc07b5
NIT
hei411 Sep 27, 2024
28ec2c8
CHECKPOINT. START OF REDOING SPECS TO MAKE TAPES LOCAL
hei411 Sep 27, 2024
ef09370
Updated hocap rand and hocap flip. TODO: rand counter and its impleme…
hei411 Sep 27, 2024
b285783
random counter spec fix
hei411 Sep 30, 2024
ea85077
impl1
hei411 Sep 30, 2024
33577e0
NIT
hei411 Sep 30, 2024
9367f48
Progress in impl2
hei411 Sep 30, 2024
2a2a3b8
progress with impl2
hei411 Sep 30, 2024
aa2d2f4
Progress with impl2
hei411 Sep 30, 2024
9a1e514
impl2 completed
hei411 Oct 1, 2024
e196ae1
Progress with impl3
hei411 Oct 1, 2024
746032e
impl3 create spec, allocate tape, and read from counter
hei411 Oct 1, 2024
73f3868
incr_counter_tape_spec_some3
hei411 Oct 1, 2024
a0101d2
NIT
hei411 Oct 1, 2024
644c7bf
add linear spec for hocap flip
hei411 Oct 1, 2024
ab1e100
NIT
hei411 Oct 2, 2024
531d4ef
NIT
hei411 Oct 2, 2024
3710d49
hocap_error_coupl
hei411 Oct 3, 2024
e68656c
NIT
hei411 Oct 3, 2024
9e2e5d1
break build but useful state_update def
hei411 Oct 4, 2024
9ae3eea
rand counter +impl1 +impl2 fix build
hei411 Oct 7, 2024
c12d733
Finish impl3
hei411 Oct 7, 2024
ea33c4c
Improve copset rewrites
hei411 Oct 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 61 additions & 21 deletions theories/coneris/error_rules.v
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ Lemma pgl_iterM_state N p σ α ns:
pgl (iterM p (λ σ, state_step σ α) σ)
(λ σ',
∃ ns' : list (fin (S N)),
ns' ∈ enum_uniform_list N p ∧ σ' = state_upd_tapes <[α:=(N; ns ++ ns')]> σ) 0.
ns' ∈ enum_uniform_fin_list N p ∧ σ' = state_upd_tapes <[α:=(N; ns ++ ns')]> σ) 0.
Proof.
intros H.
rewrite /pgl.
Expand All @@ -855,7 +855,7 @@ Proof.
rewrite -dunifv_pos in H1.
apply H0.
exists x.
split; [by apply elem_of_enum_uniform_list|done].
split; [by apply elem_of_enum_uniform_fin_list|done].
Qed.

Lemma state_step_coupl_iterM_state_adv_comp_con_prob_lang (p:nat) α σ1 Z (ε ε_rem: nonnegreal) N ns:
Expand All @@ -871,11 +871,11 @@ Proof.
by apply elem_of_list_In, elem_of_list_In, elem_of_elements, elem_of_dom. }
assert (0<=1 / S N ^ p)%R as Hineq.
{ apply Rcomplements.Rdiv_le_0_compat; first lra. apply pow_lt. apply pos_INR_S. }
(* R: predicate should hold iff tapes σ' at α is ns ++ [nx] where ns is in enum_uniform_list N p *)
(* R: predicate should hold iff tapes σ' at α is ns ++ [nx] where ns is in enum_uniform_fin_list N p *)
unshelve iExists
(fun σ' : state => exists ns', ns' ∈ enum_uniform_list N p /\ σ' = (state_upd_tapes <[α:=(_; ns ++ ns') : tape]> σ1)), nnreal_zero,
(fun σ' : state => exists ns', ns' ∈ enum_uniform_fin_list N p /\ σ' = (state_upd_tapes <[α:=(_; ns ++ ns') : tape]> σ1)), nnreal_zero,
(fun ρ => (ε_rem +
match ClassicalEpsilon.excluded_middle_informative (exists ns', ns' ∈ enum_uniform_list N p /\ ρ = (state_upd_tapes <[α:=(_; ns ++ ns') : tape]> σ1)) with
match ClassicalEpsilon.excluded_middle_informative (exists ns', ns' ∈ enum_uniform_fin_list N p /\ ρ = (state_upd_tapes <[α:=(_; ns ++ ns') : tape]> σ1)) with
| left p => mknonnegreal (ε2 (epsilon p)) _
| _ => nnreal_zero
end))%NNR.
Expand All @@ -893,14 +893,14 @@ Proof.
- apply Rlt_gt. apply pow_lt. pose proof pos_INR N; lra.
- rewrite -S_INR; simpl in *; lra.
}
rewrite elem_of_enum_uniform_list in H1.
rewrite elem_of_enum_uniform_fin_list in H1.
etrans; last exact.
etrans; last apply (SeriesC_ge_elem _ (epsilon e)).
+ rewrite S_INR. rewrite H1. by rewrite Nat.eqb_refl.
+ intros; case_match; last lra.
apply Rmult_le_pos; try done. by simpl.
+ apply (ex_seriesC_ext (λ n, if bool_decide (n∈enum_uniform_list N p) then (1 / S N ^ p * ε2 n)%R else 0%R)); last apply ex_seriesC_list.
intros. case_bool_decide as H'; rewrite elem_of_enum_uniform_list in H'.
+ apply (ex_seriesC_ext (λ n, if bool_decide (n∈enum_uniform_fin_list N p) then (1 / S N ^ p * ε2 n)%R else 0%R)); last apply ex_seriesC_list.
intros. case_bool_decide as H'; rewrite elem_of_enum_uniform_fin_list in H'.
* subst. by rewrite Nat.eqb_refl.
* rewrite -Nat.eqb_neq in H'. by rewrite H'.
- iPureIntro.
Expand All @@ -912,13 +912,13 @@ Proof.
by rewrite dmap_unfold_pmf -SeriesC_scal_r.
}
rewrite fubini_pos_seriesC'; last first.
+ eapply (ex_seriesC_ext (λ a, if bool_decide (a ∈ enum_uniform_list N p) then _ else 0%R)); last apply ex_seriesC_list.
+ eapply (ex_seriesC_ext (λ a, if bool_decide (a ∈ enum_uniform_fin_list N p) then _ else 0%R)); last apply ex_seriesC_list.
intros n.
case_bool_decide as H; first done.
rewrite SeriesC_0; first done.
intros x.
rewrite dunifv_pmf bool_decide_eq_false_2; first lra.
by rewrite -elem_of_enum_uniform_list.
by rewrite -elem_of_enum_uniform_fin_list.
+ intros a.
rewrite dunifv_pmf.
eapply (ex_seriesC_ext (λ b, if bool_decide (b=state_upd_tapes <[α:=(N; ns ++ a)]> σ1) then _ else 0%R)); last apply ex_seriesC_singleton_dependent.
Expand All @@ -927,11 +927,11 @@ Proof.
+ intros.
repeat apply Rmult_le_pos; repeat case_match; simpl; try lra; try done.
all: apply Rplus_le_le_0_compat; by try lra.
+ erewrite (SeriesC_ext _ (λ n, (if bool_decide (n∈enum_uniform_list N p) then 1 / S N ^ p * ε2 n else 0) + (if bool_decide (n∈enum_uniform_list N p) then 1 / S N ^ p * ε_rem else 0)))%R.
+ erewrite (SeriesC_ext _ (λ n, (if bool_decide (n∈enum_uniform_fin_list N p) then 1 / S N ^ p * ε2 n else 0) + (if bool_decide (n∈enum_uniform_fin_list N p) then 1 / S N ^ p * ε_rem else 0)))%R.
* rewrite SeriesC_plus; [|apply ex_seriesC_list..].
rewrite SeriesC_list_2; last apply NoDup_enum_uniform_list.
rewrite enum_uniform_list_length.
setoid_rewrite elem_of_enum_uniform_list'.
rewrite SeriesC_list_2; last apply NoDup_enum_uniform_fin_list.
rewrite enum_uniform_fin_list_length.
setoid_rewrite elem_of_enum_uniform_fin_list'.
rewrite Rplus_0_l.
rewrite Rplus_comm. apply Rplus_le_compat; last done.
rewrite -pow_INR. simpl.
Expand All @@ -951,7 +951,7 @@ Proof.
case_match; last first.
{ exfalso. apply n. naive_solver. }
rewrite dunifv_pmf.
rewrite bool_decide_eq_true_2; last by apply elem_of_enum_uniform_list.
rewrite bool_decide_eq_true_2; last by apply elem_of_enum_uniform_fin_list.
rewrite -pow_INR. simpl.
pose proof epsilon_correct _ e as H'. simpl in H'.
replace (epsilon e) with l; try lra.
Expand All @@ -962,15 +962,15 @@ Proof.
intros.
rewrite dunifv_pmf.
rewrite bool_decide_eq_false_2; first lra.
by rewrite -elem_of_enum_uniform_list.
by rewrite -elem_of_enum_uniform_fin_list.
- simpl.
iPureIntro.
eapply pgl_mon_pred; last first.
+ apply pgl_iterM_state. apply Hin.
+ done.
- iIntros (σ2 [ns' [Helem ->]]).
pose proof Helem as Helem'.
rewrite elem_of_enum_uniform_list in Helem. rewrite <- Helem.
rewrite elem_of_enum_uniform_fin_list in Helem. rewrite <- Helem.
iMod ("H" with "[]") as "H"; first done.
case_match; last first.
+ (* contradiction *)
Expand Down Expand Up @@ -1001,16 +1001,16 @@ Proof.
* intros. split; repeat case_match; try rewrite S_INR; simpl; try rewrite Rmult_1_r; try lra.
all: apply Rmult_le_pos; last done.
all: rewrite -S_INR; apply Rdiv_INR_ge_0.
* eapply (ex_seriesC_ext (λ x, if (bool_decide (x∈enum_uniform_list N 1%nat)) then
* eapply (ex_seriesC_ext (λ x, if (bool_decide (x∈enum_uniform_fin_list N 1%nat)) then
match x with |[x'] => (1 / S N * ε2 x')%R | _ => 0 end else 0));
last apply ex_seriesC_list.
intros [|n[|]].
-- rewrite bool_decide_eq_false_2; first done.
by rewrite elem_of_enum_uniform_list.
by rewrite elem_of_enum_uniform_fin_list.
-- rewrite bool_decide_eq_true_2; first done.
by rewrite elem_of_enum_uniform_list.
by rewrite elem_of_enum_uniform_fin_list.
-- rewrite bool_decide_eq_false_2; first done.
by rewrite elem_of_enum_uniform_list.
by rewrite elem_of_enum_uniform_fin_list.
+ intros; apply Rmult_le_pos; last by simpl.
apply Rdiv_INR_ge_0.
+ intros. repeat case_match; by simplify_eq.
Expand Down Expand Up @@ -1151,6 +1151,46 @@ Qed.
iFrame.
Qed.

Lemma state_update_presample_exp E α N ns (ε1 : R) (ε2 : fin (S N) → R) :
(∀ n, 0<=ε2 n)%R ->
(SeriesC (λ n, 1 / (S N) * ε2 n)%R <= ε1)%R →
α ↪N (N; ns) -∗ ↯ ε1 -∗ state_update E (∃ n, α ↪N (N; ns ++ [fin_to_nat n]) ∗ ↯ (ε2 n)).
Proof.
rewrite state_update_unseal/state_update_def.
iIntros (Hpos Hsum) "Hα Hε".
iIntros (σ1 ε_now) "[(Hheap&Htapes) Hε_supply]".
iDestruct "Hα" as (ns') "(%Hmap & Hα)".
iDestruct (ghost_map_lookup with "Htapes Hα") as "%Hlookup".
iDestruct (ec_supply_bound with "Hε_supply Hε") as %Hε1_ub.
iMod (ec_supply_decrease with "Hε_supply Hε") as (ε1' ε_rem -> Hε1') "Hε_supply".
iApply fupd_mask_intro; [set_solver|].
iIntros "Hclose".
subst.
iApply (state_step_coupl_state_adv_comp_con_prob_lang); first done.
iExists (λ x, mknonnegreal (ε2 x) _).
iSplit; first done.
iIntros (sample).
destruct (Rlt_decision (ε_rem + (ε2 sample))%R 1%R) as [Hdec|Hdec]; last first.
{ apply Rnot_lt_ge, Rge_le in Hdec.
iApply state_step_coupl_ret_err_ge_1.
simpl. simpl in *. lra.
}
unshelve iMod (ec_supply_increase _ (mknonnegreal (ε2 sample) _) with "Hε_supply") as "[Hε_supply Hε]"; first done.
{ simplify_eq. simpl. done. }
iMod (ghost_map_update ((N; ns' ++ [sample]) : tape) with "Htapes Hα") as "[Htapes Hα]".
(* iSpecialize ("Hwp" $! sample). *)
(* rewrite pgl_wp_unfold /pgl_wp_pre. *)
(* simpl. *)
remember {| heap := heap (σ1); tapes := (<[α:=(N; ns' ++ [sample])]> (tapes σ1)) |} as σ2.
rewrite /=.
iModIntro.
iApply state_step_coupl_ret.
iMod "Hclose".
iFrame.
iPureIntro. rewrite fmap_app; by f_equal.
Qed.


Lemma wp_couple_empty_tape_adv_comp E α N (ε1 : R) (ε2 : nat → R) :
(∀ (n:nat), 0<= ε2 n)%R ->
(SeriesC (λ n, if (bool_decide (n≤N)) then 1 / (S N) * ε2 n else 0%R)%R <= ε1)%R →
Expand Down
Loading
Loading