Guest User

Untitled

a guest
Jul 16th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. #lang racket
  2.  
  3. (require redex/reduction-semantics
  4. redex/gui
  5. racket/syntax)
  6.  
  7. (define-language CCS
  8. ;; channels
  9. [a b c d e ::=
  10. (variable-prefix a) (variable-prefix b) (variable-prefix c) (variable-prefix d)
  11. (variable-prefix e) (variable-prefix f) (variable-prefix g) (variable-prefix s)
  12. (variable-prefix t) (variable-prefix q) (variable-prefix r)]
  13. ;; variables
  14. [x y z w ::=
  15. (variable-prefix x) (variable-prefix y) (variable-prefix z) (variable-prefix w)]
  16. [u v ::= a x]
  17. ;; processes
  18. [P Q ::=
  19. nil
  20. (‖ P ...)
  21. ((ν a) P)
  22. (! P)
  23. (u ⇐ v) ;; maybe use (▔ u ⟨ v ⟩) instead?
  24. (u (x) · P)]
  25. #:binding-forms
  26. ((ν a) P #:refers-to a)
  27. (u (x) · P #:refers-to x)
  28. )
  29.  
  30. (define-extended-language CCS+eval CCS
  31. [abstract-function
  32. (variable-prefix A) (variable-prefix B) (variable-prefix C) (variable-prefix D)
  33. (variable-prefix E) (variable-prefix F) (variable-prefix G) (variable-prefix H)
  34. (variable-prefix I) (variable-prefix J) (variable-prefix K) (variable-prefix L)
  35. (variable-prefix M) (variable-prefix N) (variable-prefix O) (variable-prefix P)
  36. (variable-prefix Q) (variable-prefix R) (variable-prefix S) (variable-prefix T)
  37. (variable-prefix U) (variable-prefix V) (variable-prefix W) (variable-prefix X)
  38. (variable-prefix Y) (variable-prefix Z)]
  39. [P ::= .... (abstract-function u v ...)]
  40. [E ::=
  41. hole
  42. (‖ P ... E Q ...)
  43. ((ν a) E)])
  44.  
  45. (define R
  46. (reduction-relation
  47. CCS+eval
  48. #:domain P
  49.  
  50. ;; unfolding
  51. (--> (in-hole E (! P))
  52. (in-hole E (‖ P (! P)))
  53. "Rep")
  54.  
  55. ;; congruence (2)
  56. (--> (in-hole E (par))
  57. (in-hole E nil)
  58. "Par Nil")
  59. (--> (in-hole E (‖ P ... 0 Q ...))
  60. (in-hole E (‖ P ... Q ...))
  61. "Zero")
  62. (--> (in-hole E (‖ P_1 ... (‖ Q ...) P_2 ...))
  63. (in-hole E (‖ P_1 ... Q ... P_2 ...))
  64. "Assoc")
  65.  
  66. ;; congruence (3)
  67. (--> (in-hole E ((ν a) nil))
  68. (in-hole E nil)
  69. "Res Nil")
  70. #;
  71. (--> (in-hole E ((ν a) ((ν b) P)))
  72. (in-hole E ((ν b) ((ν a) P)))
  73. "Res Res")
  74. (--> (in-hole E (‖ P_1 ... ((ν a) Q) P_2 ...))
  75. (in-hole E ((ν a) (‖ P_1 ... Q P_2 ...)))
  76. "Res Par")
  77.  
  78. ;; communication!
  79. (--> (in-hole E (‖ P_1 ... (a ⇐ v) P_2 ... (a (x) · P) P_3 ...))
  80. (in-hole E (‖ P_1 ... P_2 ... (substitute P x v) P_3 ...))
  81. "Comm1")
  82. (--> (in-hole E (‖ P_1 ... (a (x) · P) P_2 ... (a ⇐ v) P_3 ...))
  83. (in-hole E (‖ P_1 ... P_2 ... (substitute P x v) P_3 ...))
  84. "Comm2")
  85. ))
  86.  
  87. ;; Some examples
  88. (define communication-example
  89. (term (‖ (a (x) · (x ⇐ c))
  90. (a ⇐ b))))
  91.  
  92. (define scope-extrusion-example
  93. (term (‖ ((ν b) (a ⇐ b))
  94. (a (x) ·
  95. (c ⇐ x)))))
  96.  
  97. ;; Small agents
  98. (define-metafunction CCS
  99. FW : a b -> P
  100. [(FW a b) (a (z) · (b ⇐ z))])
  101.  
  102. (define-metafunction CCS
  103. D : a b c -> P
  104. [(D a b c) (a (z) ·
  105. (‖ (b ⇐ z)
  106. (c ⇐ z)))])
  107.  
  108. (define-metafunction CCS
  109. K : a -> P
  110. [(K a) (a (z) · nil)])
  111.  
  112. (define-metafunction CCS
  113. NN : a -> P
  114. [(NN a) (! (a (x) ·
  115. ((ν b) (x ⇐ b))))])
  116.  
  117. ;; Hacking!
  118. (define-metafunction CCS
  119. [(SClient- integer)
  120. ((ν c) (‖ (a ⇐ c)
  121. (c (x) · (PClient c x))))
  122. (where abstract-function ,(format-symbol "PClient~a" (term integer)))])
  123.  
  124. (define-term SServer-a
  125. (! (a (y) ·
  126. ((ν s)
  127. (‖ (y ⇐ s)
  128. (PServer y s))))))
  129.  
  130. (define secure-client-server-example
  131. (term (‖ (SClient- 1) (SClient- 2) SServer-a)))
  132.  
  133. (define (lex-order rule-name)
  134. (cond [(equal? rule-name "Rep") 0]
  135. [(equal? rule-name "Res Par") -1]
  136. [else -2]))
  137.  
  138. (define (run-many! unfold-fuel t)
  139. (parameterize ([pretty-print-columns 50])
  140. (pretty-write t))
  141. (define next-steps
  142. (sort (apply-reduction-relation/tag-with-names R t)
  143. (λ (name1 name2)
  144. (define l1 (lex-order name1))
  145. (define l2 (lex-order name2))
  146. (or (< l1 l2)
  147. (and (= l1 l2) (string<? name1 name2))))
  148. #:key car))
  149. (cond
  150. [(< unfold-fuel 0)
  151. (printf "\nRun out of fuel.\n")
  152. t]
  153. [(null? next-steps) t]
  154. [else
  155. (match-define (cons (list rule-name t-next) _) next-steps)
  156. (printf "\n============ ~s ============\n" rule-name)
  157. (run-many! (cond [(member rule-name '("Rep" "Res Res")) (- unfold-fuel 1)]
  158. [else unfold-fuel])
  159. t-next)]))
Add Comment
Please, Sign In to add comment