Parallel.v 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. Require Import Coq.Program.Basics.
  6. (* Parallel composition of Arrows
  7. On <https://www.haskell.org/arrows/index.html>,
  8. only arr, seqA and firstA is described,
  9. so from these primitives, parallel composition
  10. is in fact sequential.
  11. This defines an actual parallel composition
  12. primitive, with interleaving, interference, and
  13. parallelism (as in, multi-threading!). *)
  14. Section definitions.
  15. Variable World : Type.
  16. Definition left_situation A B (X : Situation (A * B)) : Situation (World := World) A
  17. := match X with (w, (x, y)) => (w, x) end.
  18. Definition right_situation A B (X : Situation (A * B)) : Situation (World := World) B
  19. := match X with (w, (x, y)) => (w, y) end.
  20. Arguments left_situation { _ _ } _.
  21. Arguments right_situation { _ _ } _.
  22. Variable Arrow : forall A B, ArrowSig World A B -> Type.
  23. Variable A B C D : Type.
  24. Definition parA_sig (this : ArrowSig World A B) (that : ArrowSig World C D)
  25. : ArrowSig World (A * C) (B * D)
  26. := {| rely := fun p w => rely this (left_situation p) w
  27. /\ rely that (right_situation p) w;
  28. (* conjunction, not disjunction -- it is only guaranteed
  29. if both guarantee it*)
  30. guarantee := fun p w => guarantee this (left_situation p) w
  31. /\ guarantee that (right_situation p) w;
  32. (* Combine ordinary Hoare preconditions,
  33. and require that this/that fulfill each other rely/guarantee *)
  34. pre := fun p =>
  35. (pre this (left_situation p) /\ pre that (right_situation p))
  36. /\ (forall w, guarantee this (left_situation p) w -> rely that (right_situation p) w)
  37. /\ (forall w, guarantee that (right_situation p) w -> rely this (left_situation p) w);
  38. (* (The postconditions assume that 'rely' and 'pre' were respected)
  39. XXX still, this looks very suspicious!
  40. Better find a paper that says this is good or bad, or find an answer
  41. myself! *)
  42. post := fun p q => post this (left_situation p) (left_situation q)
  43. /\ post that (right_situation p) (right_situation q); |}.
  44. End definitions.
  45. Arguments parA_sig { _ _ _ _ _ } _ _.