|
| 1 | + |
| 2 | +Require Import TraceModel. |
| 3 | +Require Import CommonST. |
| 4 | +Require Import XPrefix. |
| 5 | + |
| 6 | +Axiom src : language. |
| 7 | + |
| 8 | +(* Defining partial/trace semantics for programs and contexts in terms of the |
| 9 | + whole-program semantics; here we only look at finite prefixes as we currently |
| 10 | + do in our CCS'18 recomposition proof *) |
| 11 | +(* CH: An important assumption here is that the whole-program traces already |
| 12 | + include enough information to define a "proper" partial-program semantics |
| 13 | + CH: This might be related to our previous conjecture that adding the |
| 14 | + information needed to achieve "FATs" to the trace does not prevent any |
| 15 | + extra optimizations? |
| 16 | + CH: And anyway, composition / recomposition / FATs(?) should be strong |
| 17 | + enough conditions to enforce this assumption? So "proper" above could |
| 18 | + well mean satisfying composition / recomposition / FATs *) |
| 19 | +Definition xsemp (P:par src) (m : xpref) := exists C, xsem (C[P]) m. |
| 20 | +Definition xsemc (C:ctx src) (m : xpref) := exists P, xsem (C[P]) m. |
| 21 | + |
| 22 | +(* Trace equivalence defined over partial semantics and only for |
| 23 | + finite trace prefixes, as usually the case in the literature *) |
| 24 | +Definition trace_equiv P1 P2 := forall m, xsemp P1 m <-> xsemp P2 m. |
| 25 | + |
| 26 | +(* CH: This is exactly how we defined the premise and conclusion of RTEP, |
| 27 | + yet usually FATs is more related to FA than to RTEP -- are we still |
| 28 | + convinced that the two agree in a determinate setting? [TOOD: read] *) |
| 29 | +(* CH: After 2020-03-10 discussion, this definition has little to do with |
| 30 | + observational equivalence, which means that the thing below should not |
| 31 | + be called FATs either -- in particular this definition is not the right |
| 32 | + one for FATs in the presence of internal nondeterminism *) |
| 33 | +Definition beh_equiv P1 P2 := forall C t, sem src (C[P1]) t <-> sem src (C[P2]) t. |
| 34 | + |
| 35 | +Definition not_really_fats := forall P1 P2, trace_equiv P1 P2 <-> beh_equiv P1 P2. |
| 36 | + |
| 37 | +(* In this model not_really_fats_rtl and decomposition are trivial *) |
| 38 | +(* CH: Isn't the former already quite worrisome that one FATs direction holds no |
| 39 | + matter how informative or uninformative our traces are? Not if the above |
| 40 | + is not really FATs though ... *) |
| 41 | + |
| 42 | +Lemma beh_equiv_trace_equiv : forall P1 P2, beh_equiv P1 P2 -> trace_equiv P1 P2. |
| 43 | +Proof. |
| 44 | + unfold beh_equiv, trace_equiv, xsemp, xsem. intros P1 P2 Hbe m. |
| 45 | + split; intros [C [t [Hpref Hpsem]]]; exists C, t. |
| 46 | + - rewrite -> Hbe in Hpsem. tauto. |
| 47 | + - rewrite <- Hbe in Hpsem. tauto. |
| 48 | +Qed. |
| 49 | + |
| 50 | +Lemma decomposition : forall C P m, xsem (C[P]) m -> (xsemp P m /\ xsemc C m). |
| 51 | +Proof. |
| 52 | + unfold xsemp, xsemc, xsem. intros C P m [t [Hpref Hsem]]. split. |
| 53 | + - exists C, t. tauto. |
| 54 | + - exists P, t. tauto. |
| 55 | +Qed. |
| 56 | + |
| 57 | +(* Composition is not trivial though *) |
| 58 | + |
| 59 | +Definition composition := forall C P m, xsemp P m -> xsemc C m -> xsem (C[P]) m. |
| 60 | + |
| 61 | +Lemma composition_trivial : composition. |
| 62 | +Proof. |
| 63 | + unfold composition, xsemp, xsemc. |
| 64 | + intros C P m [C' H1] [P' H2]. |
| 65 | +Abort. (* what we are left with looks like recomposition *) |
| 66 | + |
| 67 | +(* Composition follows from recomposition *) |
| 68 | +(* This definition matches the CCS'18 one. This bakes in a few things: |
| 69 | + - we are only looking at prefixes (artifact of just looking at RSC) |
| 70 | + - whole-program semantics defined in terms of traces (prefixes) of events, |
| 71 | + which for us are pretty informative (this definition is agnostic to that) *) |
| 72 | +Definition recomposition := forall C1 P1 C2 P2 m, |
| 73 | + @xsem src (C1[P1]) m -> @xsem src (C2[P2]) m -> @xsem src (C1[P2]) m. |
| 74 | + |
| 75 | +Lemma recomposition_composition : recomposition -> composition. |
| 76 | +Proof. |
| 77 | + unfold recomposition, composition, xsemp, xsemc. |
| 78 | + intros Hrecomp C P m [C' H1] [P' H2]. eapply Hrecomp; eassumption. |
| 79 | +Qed. |
| 80 | + |
| 81 | +(* Recomposition also follows from composition *) |
| 82 | + |
| 83 | +Lemma composition_recomposition : composition -> recomposition. |
| 84 | +Proof. |
| 85 | + unfold recomposition, composition, xsemp, xsemc. |
| 86 | + intros Hcomp C1 P1 C2 P2 m H0 H1. |
| 87 | + apply Hcomp; eexists; eassumption. |
| 88 | +Qed. |
| 89 | + |
| 90 | +(* Our original conjecture: not_really_fats follows from recomposition *) |
| 91 | + |
| 92 | +Lemma recomposition_not_really_fats : recomposition -> not_really_fats. |
| 93 | +Proof. |
| 94 | + unfold recomposition, not_really_fats, trace_equiv, beh_equiv, xsemp, xsem. |
| 95 | + intros Hrecomp P1 P2. split; [| now apply beh_equiv_trace_equiv]. |
| 96 | + intros Htequiv C t. split; intro Hsem. |
| 97 | +Abort. |
| 98 | + |
| 99 | +(* This is easier if we restrict beh_equiv to finitely representable prefixes *) |
| 100 | + |
| 101 | +Lemma recomposition_trace_equiv_weak_beh_equiv : recomposition -> |
| 102 | + forall P1 P2, trace_equiv P1 P2 -> |
| 103 | + forall C m, xsem (C[P1]) m <-> xsem (C[P2]) m. (* <-- weaker beh_equiv *) |
| 104 | +Proof. |
| 105 | + unfold recomposition, trace_equiv, xsemp. |
| 106 | + intros Hrecomp P1 P2. intros H C m. |
| 107 | + split; intro Hsem. |
| 108 | + - assert (Hprem: exists C : ctx src, xsem (C [P1]) m) by eauto. |
| 109 | + rewrite -> H in Hprem. destruct Hprem as [C' Hdone]. |
| 110 | + eapply Hrecomp; eassumption. |
| 111 | + - assert (Hprem: exists C : ctx src, xsem (C [P2]) m) by eauto. |
| 112 | + rewrite <- H in Hprem. destruct Hprem as [C' Hdone]. |
| 113 | + eapply Hrecomp; eassumption. |
| 114 | +Qed. |
| 115 | + |
| 116 | +(* Now back to the more difficult proof (and broken), so let's go to classical logic *) |
| 117 | + |
| 118 | +Require Import ClassicalExtras. |
| 119 | + |
| 120 | +Module NewAssumption. |
| 121 | + (* Assumption made silently in Deepak's proof *) |
| 122 | + (* should follow from `semantics_safety_like src` ? *) |
| 123 | + Axiom not_sem : forall C P t, |
| 124 | + ~sem src (C [P]) t -> exists m, xprefix m t /\ ~xsem (C[P]) m. |
| 125 | + |
| 126 | + Lemma recomposition_not_really_fats : recomposition -> not_really_fats. |
| 127 | + Proof. |
| 128 | + (* unfold fats, trace_equiv, obs_equiv, psemp, psem. *) |
| 129 | + intros Hrecomp P1 P2. split; [| now apply beh_equiv_trace_equiv]. |
| 130 | + intros Htequiv. rewrite dne. intro Hc. |
| 131 | + do 2 setoid_rewrite not_forall_ex_not in Hc. |
| 132 | + destruct Hc as [C [t Hc]]. rewrite not_iff in Hc. |
| 133 | + destruct Hc as [[H1 H2] | [H2 H1]]. |
| 134 | + - apply not_sem in H2. destruct H2 as [m [Hpref H2]]. apply H2. clear H2. |
| 135 | + rewrite <- recomposition_trace_equiv_weak_beh_equiv; |
| 136 | + [ exists t; now eauto | assumption | assumption ]. |
| 137 | + - apply not_sem in H2. destruct H2 as [m [Hpref H2]]. apply H2. clear H2. |
| 138 | + rewrite -> recomposition_trace_equiv_weak_beh_equiv; |
| 139 | + [ exists t; now eauto | assumption | assumption ]. |
| 140 | + Qed. |
| 141 | + |
| 142 | +End NewAssumption. |
| 143 | + |
| 144 | +Module OldAssumption. |
| 145 | + (* should follow from `semantics_safety_like src` *) |
| 146 | + Axiom not_sem : forall C P t, |
| 147 | + ~sem src (C [P]) t -> ~diverges t -> exists m, prefix m t /\ ~psem (C[P]) m. |
| 148 | + |
| 149 | + Lemma recomposition_not_really_fats : recomposition -> not_really_fats. |
| 150 | + Proof. |
| 151 | + intros Hrecomp P1 P2. split; [| now apply beh_equiv_trace_equiv]. |
| 152 | + intros Htequiv. intros C t. |
| 153 | + destruct t as [ m es | m | s ]. |
| 154 | + - eapply (recomposition_trace_equiv_weak_beh_equiv Hrecomp) |
| 155 | + with (m := xstop m es) (C := C) in Htequiv. unfold xsem in Htequiv. |
| 156 | + (* the rest is just a lot of boilerplate to prove something obvious *) |
| 157 | + destruct Htequiv as [Htequiv1 Htequiv2]. split; intro H. |
| 158 | + + assert (H' : exists t, xprefix (xstop m es) t /\ sem src (C [P1]) t). |
| 159 | + { exists (tstop m es). simpl. tauto. } |
| 160 | + destruct (Htequiv1 H') as [t' [Hprefix Hsem]]. destruct t'; simpl in Hprefix. |
| 161 | + * destruct Hprefix as [H1 H2]. subst. assumption. |
| 162 | + * contradiction. |
| 163 | + * contradiction. |
| 164 | + + assert (H' : exists t, xprefix (xstop m es) t /\ sem src (C [P2]) t). |
| 165 | + { exists (tstop m es). simpl. tauto. } |
| 166 | + destruct (Htequiv2 H') as [t' [Hprefix Hsem]]. destruct t'; simpl in Hprefix. |
| 167 | + * destruct Hprefix as [H1 H2]. subst. assumption. |
| 168 | + * contradiction. |
| 169 | + * contradiction. |
| 170 | + - eapply (recomposition_trace_equiv_weak_beh_equiv Hrecomp) |
| 171 | + with (m := xsilent m) (C := C) in Htequiv. unfold xsem in Htequiv. |
| 172 | + destruct Htequiv as [Htequiv1 Htequiv2]. split; intro H. |
| 173 | + + assert (H' : exists t, xprefix (xsilent m) t /\ sem src (C [P1]) t). |
| 174 | + { exists (tsilent m). simpl. tauto. } |
| 175 | + destruct (Htequiv1 H') as [t' [Hprefix Hsem]]. destruct t'; simpl in Hprefix. |
| 176 | + * contradiction. |
| 177 | + * destruct Hprefix as [H1 H2]. subst. assumption. |
| 178 | + * contradiction. |
| 179 | + + assert (H' : exists t, xprefix (xsilent m) t /\ sem src (C [P2]) t). |
| 180 | + { exists (tsilent m). simpl. tauto. } |
| 181 | + destruct (Htequiv2 H') as [t' [Hprefix Hsem]]. destruct t'; simpl in Hprefix. |
| 182 | + * contradiction. |
| 183 | + * destruct Hprefix as [H1 H2]. subst. assumption. |
| 184 | + * contradiction. |
| 185 | + - rewrite dne. intro Hc. rewrite not_iff in Hc. |
| 186 | + destruct Hc as [[H1 H2] | [H2 H1]]. |
| 187 | + + apply not_sem in H2. simpl in H2. destruct H2 as [m [Hpref H2]]. apply H2. clear H2. |
| 188 | + rewrite <- recomposition_trace_equiv_weak_beh_equiv; |
| 189 | + [ exists (tstream s); now eauto | assumption | assumption ]. tauto. |
| 190 | + + apply not_sem in H2. destruct H2 as [m [Hpref H2]]. apply H2. clear H2. |
| 191 | + rewrite -> recomposition_trace_equiv_weak_beh_equiv; |
| 192 | + [ exists (tstream s); now eauto | assumption | assumption ]. tauto. |
| 193 | + Abort. |
| 194 | + |
| 195 | +End OldAssumption. |
0 commit comments