Sequential.v 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. (* Copyright © 2019 Ariadne Devos
  2. SPDX-License-Identifier: GPL-2.0 or GPL-3.0 *)
  3. Require Import S.Lucid.Arrow.
  4. Require Import Coq.Sets.Ensembles.
  5. Section definitions.
  6. Variable World : Type.
  7. Variable A B C : Type.
  8. (* The signature of the sequential composition of two arrows.
  9. (This only gives the properties of such a composition,
  10. the resulting pre-condition may be impossible.)
  11. TODO: whether this is correct, will be verified if
  12. some Arrow type is lowered to some concurrent Monad (or
  13. C, or ... assembly) and a bisimulation is proven to
  14. be maintained *)
  15. Definition seq_sig (stop : ArrowSig World A B) (start : ArrowSig World B C) : ArrowSig World A C
  16. := {| rely := fun p w => rely stop p w /\ forall q, post stop p q -> rely start q w;
  17. (* guaranteed-p? Both arrows must keep up with the promise.
  18. (Remember, the frame condition specifies instants in time)
  19. `guarantee stop p w`: first arrow.
  20. `forall q, post stop p q -> _`: like the first arrow,
  21. except that the intermediate value must be introduced.
  22. Since we are speaking of *guarantees*, it must hold for
  23. all *posssible* (hence post stop p q) intermediates. *)
  24. guarantee := fun (p : Situation A) w => guarantee stop p w
  25. /\ forall (q : Situation B), post stop p q -> guarantee start q w;
  26. (* In the original formulation,
  27. { P } S1 { Q }, { Q } S2 { R }
  28. |- { P } S1 S2 { R }.
  29. In ours,
  30. { P } S1 { Q }, { R } S2 { S }
  31. |- { P /\ Q -> R } S1 { S }
  32. (except for the qualifiers and binders)
  33. (Is this weakest precondition?) *)
  34. pre := fun (p : Situation A) => pre stop p /\ (forall (q : Situation B), post stop p q -> pre start q);
  35. (* The post-condition is given as a set of possibilities dependent on the input.
  36. Possible -> exists.
  37. This is an ordinary Hoare composition rule. *)
  38. post := fun (p : Situation A) (r : Situation C) =>
  39. exists (q : Situation B), post stop p q /\ post start q r;
  40. |}.
  41. End definitions.
  42. Arguments seq_sig { _ _ _ _ } _ _.