Proc.agda 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. module Proc where
  2. open import Basics
  3. module ProcDef (U : Set)(T : U -> Set)(Name : U -> Set) where
  4. LT : U -> Set
  5. LT a = Lift (T a)
  6. record Tran (a b : U) : Set where
  7. field
  8. upV : T b -> LT a
  9. downV : T a -> LT b
  10. mapLT : {a b : U} -> (T a -> LT b) -> List (T a) -> List (T b)
  11. mapLT f [] = []
  12. mapLT f (x :: xs) with f x
  13. ... | bot = mapLT f xs
  14. ... | lift y = y :: mapLT f xs
  15. infixr 40 _!_ _!_+_
  16. infix 40 >_
  17. infixr 30 _||_ _/|_
  18. data Proc (a : U) : Set where
  19. o : Proc a
  20. >_ : (T a -> Proc a) -> Proc a
  21. _!_ : LT a -> Proc a -> Proc a
  22. _!_+_ : LT a -> Proc a -> (T a -> Proc a) -> Proc a
  23. _||_ : Proc a -> Proc a -> Proc a
  24. _/|_ : {b : U} -> Tran a b -> Proc b -> Proc a
  25. def : Name a -> Proc a
  26. Env : Set
  27. Env = (a : U) -> Name a -> Proc a
  28. record Param : Set1 where
  29. field
  30. U : Set
  31. T : U -> Set
  32. Name : U -> Set
  33. env : ProcDef.Env U T Name
  34. module Process (param : Param) where
  35. private open module Par = Param param public
  36. private open module Pro = ProcDef U T Name public
  37. infixr 40 _!g_ _!_+g_
  38. infix 40 >g_
  39. infixr 30 _||g_ _/|g_
  40. data Guard {a : U} : Proc a -> Set where
  41. og : Guard o
  42. >g_ : (f : T a -> Proc a) -> Guard (> f)
  43. _!g_ : (w : LT a)(p : Proc a) -> Guard (w ! p)
  44. _!_+g_ : (w : LT a)(p : Proc a)(f : T a -> Proc a) -> Guard (w ! p + f)
  45. _||g_ : {p1 p2 : Proc a} -> Guard p1 -> Guard p2 -> Guard (p1 || p2)
  46. _/|g_ : {b : U}(φ : Tran a b){p : Proc b} -> Guard p -> Guard (φ /| p)
  47. defg : (x : Name a) -> Guard (env a x) -> Guard (def x)
  48. infix 20 _-[_]->_ _-!_!->_
  49. open Tran
  50. data _-[_]->_ {a : U} : Proc a -> LT a -> Proc a -> Set where
  51. qtau : {p : Proc a} -> p -[ bot ]-> p
  52. rx-o : {v : T a} -> o -[ lift v ]-> o
  53. rx-! : {v : T a}{w : LT a}{p : Proc a} -> w ! p -[ lift v ]-> w ! p
  54. rx-> : {v : T a}{f : T a -> Proc a} -> > f -[ lift v ]-> f v
  55. rx-+ : {v : T a}{w : LT a}{p : Proc a}{f : T a -> Proc a} ->
  56. w ! p + f -[ lift v ]-> f v
  57. rx-|| : {v : T a}{p1 p2 p1' p2' : Proc a} ->
  58. p1 -[ lift v ]-> p1' ->
  59. p2 -[ lift v ]-> p2' ->
  60. p1 || p2 -[ lift v ]-> p1' || p2'
  61. rx-/| : {v : T a}{b : U}{φ : Tran a b}{q q' : Proc b} ->
  62. q -[ downV φ v ]-> q' ->
  63. φ /| q -[ lift v ]-> φ /| q'
  64. rx-def : {v : T a}{p : Proc a}{x : Name a} ->
  65. env a x -[ lift v ]-> p ->
  66. def x -[ lift v ]-> p
  67. data _-!_!->_ {a : U} : Proc a -> LT a -> Proc a -> Set where
  68. tx-! : {w : LT a}{p : Proc a} -> w ! p -! w !-> p
  69. tx-+ : {w : LT a}{p : Proc a}{f : T a -> Proc a} ->
  70. w ! p + f -! w !-> p
  71. tx-!| : {w : LT a}{p p' q q' : Proc a} ->
  72. p -! w !-> p' -> q -[ w ]-> q' ->
  73. p || q -! w !-> p' || q'
  74. tx-|! : {w : LT a}{p p' q q' : Proc a} ->
  75. p -[ w ]-> p' -> q -! w !-> q' ->
  76. p || q -! w !-> p' || q'
  77. tx-/| : {b : U}{w : LT b}{φ : Tran a b}{q q' : Proc b} ->
  78. q -! w !-> q' ->
  79. φ /| q -! upV φ =<< w !-> φ /| q'
  80. tx-def : {w : LT a}{p : Proc a}{x : Name a} ->
  81. env a x -! w !-> p ->
  82. def x -! w !-> p
  83. data Silent {a : U} : Proc a -> Set where
  84. silent-o : Silent o
  85. silent-> : {f : T a -> Proc a} -> Silent (> f)
  86. silent-|| : {p1 p2 : Proc a} ->
  87. Silent p1 -> Silent p2 -> Silent (p1 || p2)
  88. silent-def : {x : Name a} ->
  89. Silent (env _ x) -> Silent (def x)
  90. silent-/| : {b : U}{φ : Tran a b}{p : Proc b} ->
  91. Silent p -> Silent (φ /| p)
  92. infixr 40 _>!>_ _>*>_
  93. data _-[_]->*_ {a : U} : Proc a -> List (T a) -> Proc a -> Set where
  94. rnop : {p : Proc a} -> p -[ [] ]->* p
  95. _>?>_ : {p q r : Proc a}{x : T a}{xs : List (T a)} ->
  96. p -[ lift x ]-> q ->
  97. q -[ xs ]->* r ->
  98. p -[ x :: xs ]->* r
  99. rx-||* : forall {a xs}{p1 p2 q1 q2 : Proc a} ->
  100. p1 -[ xs ]->* p2 ->
  101. q1 -[ xs ]->* q2 ->
  102. p1 || q1 -[ xs ]->* p2 || q2
  103. rx-||* rnop rnop = rnop
  104. rx-||* (s1 >?> t1) (s2 >?> t2) = rx-|| s1 s2 >?> rx-||* t1 t2
  105. rx-/|* : forall {a b xs}{φ : Tran a b}{p q : Proc b} ->
  106. p -[ mapLT (downV φ) xs ]->* q ->
  107. φ /| p -[ xs ]->* φ /| q
  108. rx-/|* {xs = []} rnop = rnop
  109. rx-/|* {xs = x :: xs}{φ = φ} t with it (downV φ x) refl
  110. rx-/|* {xs = x :: xs}{φ}{p}{q} t | it bot eq =
  111. rx-/| (lem₁ eq) >?> rx-/|* (lem₂ eq t)
  112. where
  113. lem₁ : forall {w} -> w == bot -> p -[ w ]-> p
  114. lem₁ refl = qtau
  115. lem₂ : downV φ x == bot ->
  116. p -[ mapLT (downV φ) (x :: xs) ]->* q ->
  117. p -[ mapLT (downV φ) xs ]->* q
  118. lem₂ eq h with downV φ x
  119. lem₂ refl h | .bot = h
  120. rx-/|* {a}{b}{x :: xs}{φ}{p}{q} t | it (lift y) eq =
  121. rx-/| (lem₁ eq t) >?> rx-/|* (lem₂ eq t)
  122. where
  123. Eqn = downV φ x == lift y
  124. Asm = p -[ mapLT (downV φ) (x :: xs) ]->* q
  125. r : Eqn -> Asm -> Proc b
  126. r eq t with downV φ x
  127. r refl (_>?>_ {q = q} _ _) | ._ = q
  128. lem₁ : (eq : Eqn)(h : Asm) -> p -[ downV φ x ]-> r eq h
  129. lem₁ eq t with downV φ x
  130. lem₁ refl (s >?> _) | ._ = s
  131. lem₂ : (eq : Eqn)(h : Asm) -> r eq h -[ mapLT (downV φ) xs ]->* q
  132. lem₂ eq t with downV φ x
  133. lem₂ refl (_ >?> t) | ._ = t
  134. data _-!_!->*_ {a : U} : Proc a -> List (T a) -> Proc a -> Set where
  135. tnop : {p : Proc a} -> p -! [] !->* p
  136. _>!>_ : {p q r : Proc a}{x : T a}{xs : List (T a)} ->
  137. p -! lift x !-> q ->
  138. q -! xs !->* r ->
  139. p -! x :: xs !->* r
  140. _>*>_ : {p q r : Proc a}{xs : List (T a)} ->
  141. p -! bot !-> q ->
  142. q -! xs !->* r ->
  143. p -! xs !->* r