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

Twp #11

Merged
merged 43 commits into from
Jan 26, 2024
Merged

Twp #11

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
0694eb9
starting to write total weakest pre
hei411 Jan 9, 2024
6b53586
First file for twp completed
hei411 Jan 10, 2024
68e9aa4
start working on adequacy
hei411 Jan 10, 2024
605f0c0
some progress
hei411 Jan 10, 2024
71e3be4
state lemma of another induction hypothesis for twp, it is admitted f…
hei411 Jan 10, 2024
d2b2b80
Added real_le_limit lemma
hei411 Jan 10, 2024
230143e
Added limit rules
hei411 Jan 10, 2024
a1c39e5
added strong fixpoint rule
hei411 Jan 11, 2024
45e2230
Complete stronger induction lemma
hei411 Jan 11, 2024
7886b53
small add
hei411 Jan 11, 2024
fc60504
Small fix
hei411 Jan 11, 2024
efdcc0e
make more progress on another induction lemma
hei411 Jan 11, 2024
5d04db1
Solved ind'
hei411 Jan 11, 2024
be10159
simplify some hypothesis
hei411 Jan 12, 2024
ac69142
translate adequacy to just pure lemmas
hei411 Jan 12, 2024
3bced86
small change
hei411 Jan 12, 2024
ac3d35d
Completed val case
hei411 Jan 12, 2024
89af689
Now remaining two ugly lemmas
hei411 Jan 22, 2024
1931b32
COMPLETED
hei411 Jan 22, 2024
88ba1b3
ported continuity laws and prove the ones for ub_logic wp and app cou…
hei411 Jan 23, 2024
c048e6d
Implement limit adequacy theorem for ub twp
hei411 Jan 23, 2024
15d2530
Merge pull request #10 from hei411/twp
hei411 Jan 23, 2024
871899c
Finish total_ub_lift lemmas
hei411 Jan 23, 2024
8ea885b
Merge branch 'logsem:twp' into twp
hei411 Jan 23, 2024
e544408
Merge pull request #12 from hei411/twp
hei411 Jan 23, 2024
2347013
Add lemma on total_ub_lift and termination ineq
hei411 Jan 23, 2024
34f7954
strengthened adequacy!
hei411 Jan 24, 2024
02acbd0
Merge pull request #13 from hei411/twp
hei411 Jan 24, 2024
866d89a
added total lifting
hei411 Jan 24, 2024
1194fab
Added total ectx lifting lemmas
hei411 Jan 24, 2024
4d4ac7c
added stronger total_ub_lift implies ub_lift_strong
hei411 Jan 24, 2024
f52a190
total_primitive_laws
hei411 Jan 25, 2024
ee86b90
TODO: proofmode
hei411 Jan 25, 2024
af5267e
started proofmode
hei411 Jan 25, 2024
e4666ed
Adding total proof_mode
hei411 Jan 25, 2024
6223b70
Merge pull request #4 from hei411/main
hei411 Jan 25, 2024
4feb23c
working on ub_rules
hei411 Jan 25, 2024
12ec67e
added merge of the rand adv lemma
hei411 Jan 25, 2024
17c8098
twp lemmas in ub_rules except those in approximate lifting
hei411 Jan 25, 2024
c7f2e72
Changed ub_rules completely
hei411 Jan 25, 2024
e5638af
Merge pull request #16 from hei411/twp
hei411 Jan 26, 2024
5a30f5c
Merge branch 'main' into twp
hei411 Jan 26, 2024
b6601e3
Fix build to include Markus' stuff
hei411 Jan 26, 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
19 changes: 19 additions & 0 deletions theories/app_rel_logic/adequacy.v
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,22 @@ Proof.
apply upper_bound_ge_sup.
intro; simpl. auto.
Qed.

Theorem wp_ARcoupl_epsilon_lim Σ `{app_clutchGpreS Σ} (e e' : expr) (σ σ' : state) (ε : nonnegreal) φ :
(∀ `{app_clutchGS Σ} (ε' : nonnegreal), ε<ε' -> ⊢ spec_ctx -∗ ⤇ e' -∗ € ε' -∗ WP e {{ v, ∃ v', ⤇ Val v' ∗ ⌜φ v v'⌝ }} ) →
ARcoupl (lim_exec (e, σ)) (lim_exec (e', σ')) φ ε.
Proof.
intros H'.
apply ARcoupl_limit.
intros ε' Hineq.
assert (0<=ε') as Hε'.
{ trans ε; try lra. by destruct ε. }
pose (mknonnegreal ε' Hε') as NNRε'.
assert (ε' = (NNRbar_to_real (NNRbar.Finite NNRε'))) as Heq.
{ by simpl. }
rewrite Heq.
eapply wp_aRcoupl_lim; first done.
intros. iIntros "Hctx".
iApply (H' with "[$Hctx]").
lra.
Qed.
76 changes: 76 additions & 0 deletions theories/bi/weakestpre.v
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ Global Arguments wp {_ _ _ _ _} _ _ _%E _%I.
Global Instance: Params (@wp) 9 := {}.
Global Arguments wp_default : simpl never.

Class Twp (PROP EXPR VAL A : Type) := {
twp : A → coPset → EXPR → (VAL → PROP) → PROP;
twp_default : A
}.
Global Arguments twp {_ _ _ _ _} _ _ _%E _%I.
Global Instance: Params (@twp) 9 := {}.
Global Arguments twp_default : simpl never.


(** Notations for partial weakest preconditions *)
(** Notations without binder -- only parsing because they overlap with the
notations with binder. *)
Expand Down Expand Up @@ -176,3 +185,70 @@ Notation "'⟨⟨⟨' P ⟩ ⟩ ⟩ e @ E ⟨⟨⟨ 'RET' pat ; Q ⟩ ⟩ ⟩" :
(∀ Φ, P -∗ (Q -∗ Φ pat%V) -∗ WP e @ E {{ Φ }}) : stdpp_scope.
Notation "'⟨⟨⟨' P ⟩ ⟩ ⟩ e ⟨⟨⟨ 'RET' pat ; Q ⟩ ⟩ ⟩" :=
(∀ Φ, P -∗ (Q -∗ Φ pat%V) -∗ WP e {{ Φ }}) : stdpp_scope.



(** Notations for total weakest preconditions *)
(** Notations without binder -- only parsing because they overlap with the
notations with binder. *)
Notation "'WP' e @ s ; E [{ Φ } ]" := (twp s E e%E Φ)
(at level 20, e, Φ at level 200, only parsing) : bi_scope.
Notation "'WP' e @ E [{ Φ } ]" := (twp twp_default E e%E Φ)
(at level 20, e, Φ at level 200, only parsing) : bi_scope.
Notation "'WP' e [{ Φ } ]" := (twp twp_default ⊤ e%E Φ)
(at level 20, e, Φ at level 200, only parsing) : bi_scope.

(** Notations with binder. *)
Notation "'WP' e @ s ; E [{ v , Q } ]" := (twp s E e%E (λ v, Q))
(at level 20, e, Q at level 200,
format "'[hv' 'WP' e '/' @ '[' s ; '/' E ']' '/' [{ '[' v , '/' Q ']' } ] ']'") : bi_scope.
Notation "'WP' e @ E [{ v , Q } ]" := (twp twp_default E e%E (λ v, Q))
(at level 20, e, Q at level 200,
format "'[hv' 'WP' e '/' @ E '/' [{ '[' v , '/' Q ']' } ] ']'") : bi_scope.
Notation "'WP' e [{ v , Q } ]" := (twp twp_default ⊤ e%E (λ v, Q))
(at level 20, e, Q at level 200,
format "'[hv' 'WP' e '/' [{ '[' v , '/' Q ']' } ] ']'") : bi_scope.

(* Texan triples *)
Notation "'[[{' P } ] ] e @ s ; E [[{ x .. y , 'RET' pat ; Q } ] ]" :=
(□ ∀ Φ,
P -∗ (∀ x, .. (∀ y, Q -∗ Φ pat%V) .. ) -∗ WP e @ s; E [{ Φ }])%I
(at level 20, x closed binder, y closed binder,
format "'[hv' [[{ '[' P ']' } ] ] '/ ' e '/' @ '[' s ; '/' E ']' '/' [[{ '[hv' x .. y , RET pat ; '/' Q ']' } ] ] ']'") : bi_scope.
Notation "'[[{' P } ] ] e @ E [[{ x .. y , 'RET' pat ; Q } ] ]" :=
(□ ∀ Φ,
P -∗ (∀ x, .. (∀ y, Q -∗ Φ pat%V) .. ) -∗ WP e @ E [{ Φ }])%I
(at level 20, x closed binder, y closed binder,
format "'[hv' [[{ '[' P ']' } ] ] '/ ' e '/' @ E '/' [[{ '[hv' x .. y , RET pat ; '/' Q ']' } ] ] ']'") : bi_scope.
Notation "'[[{' P } ] ] e [[{ x .. y , 'RET' pat ; Q } ] ]" :=
(□ ∀ Φ,
P -∗ (∀ x, .. (∀ y, Q -∗ Φ pat%V) .. ) -∗ WP e [{ Φ }])%I
(at level 20, x closed binder, y closed binder,
format "'[hv' [[{ '[' P ']' } ] ] '/ ' e '/' [[{ '[hv' x .. y , RET pat ; '/' Q ']' } ] ] ']'") : bi_scope.

Notation "'[[{' P } ] ] e @ s ; E [[{ 'RET' pat ; Q } ] ]" :=
(□ ∀ Φ, P -∗ (Q -∗ Φ pat%V) -∗ WP e @ s; E [{ Φ }])%I
(at level 20,
format "'[hv' [[{ '[' P ']' } ] ] '/ ' e '/' @ '[' s ; '/' E ']' '/' [[{ '[hv' RET pat ; '/' Q ']' } ] ] ']'") : bi_scope.
Notation "'[[{' P } ] ] e @ E [[{ 'RET' pat ; Q } ] ]" :=
(□ ∀ Φ, P -∗ (Q -∗ Φ pat%V) -∗ WP e @ E [{ Φ }])%I
(at level 20,
format "'[hv' [[{ '[' P ']' } ] ] '/ ' e '/' @ E '/' [[{ '[hv' RET pat ; '/' Q ']' } ] ] ']'") : bi_scope.
Notation "'[[{' P } ] ] e [[{ 'RET' pat ; Q } ] ]" :=
(□ ∀ Φ, P -∗ (Q -∗ Φ pat%V) -∗ WP e [{ Φ }])%I
(at level 20,
format "'[hv' [[{ '[' P ']' } ] ] '/ ' e '/' [[{ '[hv' RET pat ; '/' Q ']' } ] ] ']'") : bi_scope.

(** Aliases for stdpp scope -- they inherit the levels and format from above. *)
Notation "'[[{' P } ] ] e @ s ; E [[{ x .. y , 'RET' pat ; Q } ] ]" :=
(∀ Φ, P -∗ (∀ x, .. (∀ y, Q -∗ Φ pat%V) .. ) -∗ WP e @ s; E [{ Φ }]) : stdpp_scope.
Notation "'[[{' P } ] ] e @ E [[{ x .. y , 'RET' pat ; Q } ] ]" :=
(∀ Φ, P -∗ (∀ x, .. (∀ y, Q -∗ Φ pat%V) .. ) -∗ WP e @ E [{ Φ }]) : stdpp_scope.
Notation "'[[{' P } ] ] e [[{ x .. y , 'RET' pat ; Q } ] ]" :=
(∀ Φ, P -∗ (∀ x, .. (∀ y, Q -∗ Φ pat%V) .. ) -∗ WP e [{ Φ }]) : stdpp_scope.
Notation "'[[{' P } ] ] e @ s ; E [[{ 'RET' pat ; Q } ] ]" :=
(∀ Φ, P -∗ (Q -∗ Φ pat%V) -∗ WP e @ s; E [{ Φ }]) : stdpp_scope.
Notation "'[[{' P } ] ] e @ E [[{ 'RET' pat ; Q } ] ]" :=
(∀ Φ, P -∗ (Q -∗ Φ pat%V) -∗ WP e @ E [{ Φ }]) : stdpp_scope.
Notation "'[[{' P } ] ] e [[{ 'RET' pat ; Q } ] ]" :=
(∀ Φ, P -∗ (Q -∗ Φ pat%V) -∗ WP e [{ Φ }]) : stdpp_scope.
91 changes: 91 additions & 0 deletions theories/prelude/Series_ext.v
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,97 @@ Proof.
* apply series_pos_partial_le; auto.
Qed.

Lemma real_le_limit (x y:R) :
(∀ ε, ε > 0 -> x - ε <= y) -> x<=y.
Proof.
intros H.
assert (forall seq,(∃ b, ∀ n, 0 <= - seq n <= b) -> (∀ n, (x+seq n) <= y)-> x+ Sup_seq (seq) <= y) as H_limit.
{ intros ? H0 H1.
rewrite Rplus_comm.
rewrite -Rcomplements.Rle_minus_r.
rewrite <- rbar_le_rle.
rewrite rbar_finite_real_eq.
+ apply upper_bound_ge_sup.
intros.
pose proof (H1 n). rewrite rbar_le_rle. lra.
+ destruct H0 as [b H0].
apply (is_finite_bounded (-b) 0).
-- eapply (Sup_seq_minor_le _ _ 0). destruct (H0 0%nat). apply Ropp_le_contravar in H3.
rewrite Ropp_involutive in H3. apply H3.
-- apply upper_bound_ge_sup. intros n. destruct (H0 n). apply Ropp_le_contravar in H2.
rewrite Ropp_involutive in H2. rewrite Ropp_0 in H2. done.
}
replace x with (x + Sup_seq (λ m,(λ n,-1%R/INR (S n)) m)).
- apply H_limit.
{ exists 1.
intros; split.
-- rewrite Ropp_div. rewrite Ropp_involutive.
apply Rcomplements.Rdiv_le_0_compat; try lra.
rewrite S_INR. pose proof (pos_INR n).
lra.
-- rewrite Ropp_div. rewrite Ropp_involutive.
rewrite Rcomplements.Rle_div_l; [|apply Rlt_gt].
++ assert (1<=INR(S n)); try lra.
rewrite S_INR.
pose proof (pos_INR n).
lra.
++ rewrite S_INR.
pose proof (pos_INR n).
lra.
}
intros. rewrite Ropp_div. apply H.
apply Rlt_gt.
apply Rdiv_lt_0_compat; first lra.
rewrite S_INR. pose proof (pos_INR n); lra.
- assert (Sup_seq (λ x : nat, - (1)%R / INR (S x))=0) as Hswap; last first.
+ rewrite Hswap. erewrite<- eq_rbar_finite; [|done]. lra.
+ apply is_sup_seq_unique. rewrite /is_sup_seq.
intros err.
split.
-- intros n.
eapply (Rbar_le_lt_trans _ (Rbar.Finite 0)); last first.
++ rewrite Rplus_0_l. apply (cond_pos err).
++ apply Rge_le. rewrite Ropp_div. apply Ropp_0_le_ge_contravar.
apply Rcomplements.Rdiv_le_0_compat; try lra.
rewrite S_INR. pose proof (pos_INR n); lra.
-- pose (r := 1/err -1).
assert (exists n, r<INR n) as [n Hr]; last first.
++ eexists n.
erewrite Ropp_div. replace (_-_) with (- (pos err)) by lra.
apply Ropp_lt_contravar.
rewrite Rcomplements.Rlt_div_l.
2:{ rewrite S_INR. pose proof pos_INR. apply Rlt_gt.
eapply Rle_lt_trans; [eapply H0|].
apply Rlt_n_Sn.
}
rewrite S_INR.
rewrite Rmult_comm.
rewrite <-Rcomplements.Rlt_div_l.
2:{ pose proof (cond_pos err); lra. }
rewrite <- Rcomplements.Rlt_minus_l.
rewrite -/r. done.
++ pose proof (Rgt_or_ge 0 r).
destruct H0.
--- exists 0%nat. eapply Rlt_le_trans; last apply pos_INR.
lra.
--- exists (Z.to_nat (up r)).
pose proof (archimed r) as [? ?].
rewrite INR_IZR_INZ.
rewrite ZifyInst.of_nat_to_nat_eq.
rewrite /Z.max.
case_match.
{ rewrite Z.compare_eq_iff in H3.
exfalso. rewrite -H3 in H1. lra.
}
2: { rewrite Z.compare_gt_iff in H3. exfalso.
assert (IZR (up r) >= 0) by lra.
apply IZR_lt in H3. lra.
}
lra.
Qed.



(** Monotone convergence theorem *)
Lemma mon_sup_succ (h : nat → R) :
(∀ n, h n <= h (S n)) →
Expand Down
12 changes: 12 additions & 0 deletions theories/prob/couplings_app.v
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,18 @@ Qed.
intros ; by eapply ARcoupl_refRcoupl, Rcoupl_refRcoupl.
Qed.

Lemma ARcoupl_limit `{Countable A, Countable B} μ1 μ2 ε (ψ : A -> B -> Prop):
(forall ε', ε' > ε -> ARcoupl μ1 μ2 ψ ε') -> ARcoupl μ1 μ2 ψ ε.
Proof.
rewrite /ARcoupl.
intros Hlimit. intros.
apply real_le_limit.
intros. rewrite Rle_minus_l.
rewrite Rplus_assoc.
apply Hlimit; try done.
lra.
Qed.

(* Lemma Rcoupl_fair_conv_comb `{Countable A, Countable B} *)
(* f `{Inj bool bool (=) (=) f, Surj bool bool (=) f} *)
(* (S : A → B → Prop) (μ1 μ2 : distr A) (μ1' μ2' : distr B) : *)
Expand Down
Loading
Loading