SlideShare a Scribd company logo
Formal Methods in
Software
Lecture 5. Pi-Calculus
Vlad Patryshev
SCU
2014 Prerequisites
λ-1, λ-2
This is Tier 2 of Modern Comp Sci
History: Hoare, CSP, 1978
The trouble is: it’s static in structure - no process creation allowed
What is π-calculus
• Describes processes developing in time
• Is conceptually similar to λ-calculus
• Is used to describe
o games
o security protocols (spi-calculus)
o biological and chemical processes
o business processes
• Is the base of modern concurrency libraries, like Scala Actors
Scala Actors, an implementation of π
class CustomerSupport extends Actor {
def act() {
while (true) {
receive {
case Stop =>
println("End of my sufferings")
exit()
case question:String => sender ! s"What do you mean, $question?!"
}
}
}
}
Elements of Pi
Notion Simplified Notation Milner Notation Meaning
variable x,y,... x,y,... Stores (points to) data; typeless
channel a,b,... a,b,... Used for communication
process (agent) P,Q,... P,Q,... Denotes a combination of elementary processes
write a!(x1,...xn) ā ⟨x1,...xn⟩ A process in which channel a outputs the values of
x (sends a message)
read a?(x1,...xn) a(x1,...xn) A process in which channel a reads a message with
values x1,...xn
new channel new(x1,...xn) ν(x1,...xn) Creates new names to be used within the scope
identifier A(x1,...)=P A(x1,...)=P given a process, give it a name
Operations on Processes
Operation Simplified Notation Milner Notation Meaning
sequence P.Q P.Q run process P, then process Q
parallel P|Q P|Q run processes P and Q in parallel
choice P+Q P+Q nondeterministically run either P or Q
match if x=y then P if x=y then P obvious (this op is optional)
mismatch if x≠y then P if x≠y then P obvious (this op is optional)
null process 0 0 does nothing, and ends
replication *(P)=P|*(P) !P unlimited replication of process P
reduction P → Q P → Q evaluation: P performs a step and becomes Q
Example
Printer = b?doc . Println(doc) . Printer
Server = a!b . Server
Client = a?p . p!doc
Life = Client | Server | Printer
Laws and Rules
First, a free variable is something that’s exposed to external world, while a
bound variable is hidden in a scope - so we are free to rename bound
variables, but we better not touch free variables.
Defining Free and Bound Names
• 0 has no bound or free names
• a?x - a is free, x is bound (it’s a new name to be used further down)
• new(x) - x is bound
• a!x - a and x are free
• A(x1,...xn)=P - x1,...xn are bound
• P.Q, P|Q, P+Q - free(P)∪free(Q), bound(P)∪bound(Q) (where’s the
rest?!)
Laws and Rules for Reduction
• fundamental rule (channels communication)
• alpha-conversion (like in lambda), and unfolding law
• monoid laws
• choice rule
• parallelization rule
• replication rule
• name binding rule
• scope extension laws
Laws and Rules for Reduction
• fundamental rule (channels communication, beta-reduction)
(x!z . P) | (x?y . Q) → P|(Q[y/z])
• alpha-conversion (like in lambda), and unfolding law
o P[x/y] ≡ P
o if A(x) = P, then A(y) = P[x/y]
• monoid laws
• choice rule
• parallelization rule
• replication rule
• name binding rule
• scope extension laws
Laws and Rules for Reduction
• fundamental rule (channels communication)
• alpha-conversion (like in lambda), and unfolding law
• monoid laws
| is a commutative monoid, 0 is a neutral element
+ is commutative and associative
• choice rule
o If P→Q, then (P+R) → (Q+R) (?)
• parallelism rule
o If P→Q, then (P|R) → (Q|R)
• replication rule
o If P→Q, then *(P) → Q|*(P) (this follows from definition)
• name binding rule
Laws and Rules for Reduction
• fundamental rule (channels communication)
• alpha-conversion (like in lambda), and unfolding law
• monoid laws
• choice rule
• parallelism rule
• replication rule
• name binding rule
If P→Q, then new(x).P → new(x).Q (new names don’t break it)
• scope extension laws
o new(x).0 = 0
o new(x).(P|Q)=P|(new(x).Q) if x∉fn(P)
o new(x).(P+Q)=P+(new(x).Q) if x∉fn(P)
o new(x).new(y).P = new(y).new(x).P
Can Model Lambda-Calculus
λ-expression π-agent on port p Meaning
M [M](p) Build an agent with a communication channel p
λx M p?x.p?q.[M](q) Given a channel p, obtain the value of x and the communication
channel q; call agent [M] on channel q
x x!p A variable, when used, just publishes its channel
M N new(a,b).(
([M](a))|
(a!b.a!f)|
*((b?c).[N](c))
Applying M to N means: create control channels a and b, and
launch in parallel:
● [M] on a (it will wait)
● pass b and f to M via channel a
● read channel b on y, start [N] which will work with channel c;
run it forever, we may need result more than once.
Modeling Lambda: Example
For M=λx x how will [M N] look? Can we reduce it to just [N]?
[(λx x) N](f) = new(a).new(b) . ([M](a) | (a!b.a!f) | *(b?c.[N](c)) ) =
new(a).new(b) . (a?x.a?y.x!y | (a!b.a!f) | *(b?c.[N](c)) ) →
new(a).new(b) . (a?y.b!y | (a!f) | *(b?c.[N](c)) ) →
new(a).new(b) . (b!f | 0 | *(b?c.[N](c)) ) →
new(a).new(b) . (b!f | *(b?c.[N](c)) ) →
new(a).new(b) . (b!f | b?c.[N](c)| *(b?c.[N](c)) ) →
new(a).new(b) . (0 | [N](f) | *(b?c.[N](c)) ) →
new(a).new(b) . ([N](f) | *(b?c.[N](c)) ) →
new(b) . ([N](f) | *(b?c.[N](c)) ) →
([N](f) | new(b). *(b@c.[N](c)) ) →
[N](f)
Modeling Lambda: Example
M=λa a, N=b // using (x!z).P | (x?y).Q ) → P|(Q[z/y])
[(λa a) b](p) = (new(q) . [M](q)) |
(new(y) . q!(y,p)) |
*((y?r) . [N](r)) =
(new(q) . q?(x,q’) . x!q’ |
(new(y) . q!(y,p)) |
*(y?r . z!r))) → /* reduces to */
(new(q) . (new(y) . y!p) |
*(y?r . z!r)) =
(new(q) . (new(y) . y!p) |
(y?r . z!r)) |
*(y?r . !z(r))) → /* reduces to */
(new(q) . (new(y) . z!p) |
*(?y(r) . z!r)) “=” /* nobody’s calling local channel y*/
(new(q) . (new(y) . z!p) “=” /* nobody uses q and y */
z!p =
[z](p)
References
http://scienceblogs.com/goodmath/2007/04/16/back-to-calculus-a-better-intr-1/
http://users.soe.ucsc.edu/~abadi/Papers/isss02.pdf
https://www.doc.ic.ac.uk/~pg/Concurrency/4pi.pdf
drona.csa.iisc.ernet.in/~deepakd/pav/crchandbook.ps
https://github.com/leithaus/SpecialK/blob/master/docs/presentations/Agents%20and%20agency%2
0in%20the%20Internet.pdf?raw=true
http://www.scala-lang.org/old/node/242
http://basics.sjtu.edu.cn/~yuxi/papers/lambda_in_pi.pdf
http://scala-programming-language.1934581.n4.nabble.com/scala-Actors-versus-processes-
td1993744.html - Greg Meredith discussing Pi and Scala Actors with Martin Odersky. Not much.
Wikipedia
Formal methods   5 - Pi calculus

More Related Content

PDF
Formal methods 4 - Z notation
PPTX
Formal methods 3 - languages and machines
PDF
Formal methods 8 - category theory (last one)
PPTX
Formal methods 2 - languages and machines
PPTX
#5 formal methods – hoare logic
PPT
Algorithum Analysis
PPTX
Lambda Calculus
PDF
Formal methods 4 - Z notation
Formal methods 3 - languages and machines
Formal methods 8 - category theory (last one)
Formal methods 2 - languages and machines
#5 formal methods – hoare logic
Algorithum Analysis
Lambda Calculus

What's hot (20)

PPT
Time complexity
PPTX
Algorithm big o
PPTX
Lambda calculus
PPTX
Introduction to Algorithms and Asymptotic Notation
PDF
Ch03
PDF
Lambda Calculus by Dustin Mulcahey
PPTX
asymptotic analysis and insertion sort analysis
PDF
Functional Programming by Examples using Haskell
PDF
[FLOLAC'14][scm] Functional Programming Using Haskell
PDF
Introduction to haskell
DOCX
Deterministic finite automata
PDF
Python data handling
PDF
Functional programming with haskell
DOC
Time and space complexity
PPTX
Complexity analysis - The Big O Notation
PPTX
asymptotic notation
PPT
Big oh Representation Used in Time complexities
ODP
Clojure basics
Time complexity
Algorithm big o
Lambda calculus
Introduction to Algorithms and Asymptotic Notation
Ch03
Lambda Calculus by Dustin Mulcahey
asymptotic analysis and insertion sort analysis
Functional Programming by Examples using Haskell
[FLOLAC'14][scm] Functional Programming Using Haskell
Introduction to haskell
Deterministic finite automata
Python data handling
Functional programming with haskell
Time and space complexity
Complexity analysis - The Big O Notation
asymptotic notation
Big oh Representation Used in Time complexities
Clojure basics
Ad

Similar to Formal methods 5 - Pi calculus (20)

PDF
Understanding distributed calculi in Haskell
PDF
RChain - Understanding Distributed Calculi
PDF
Applied machine learning for search engine relevance 3
PDF
Sep logic slide
PDF
Sparsenet
PPT
Q-Metrics in Theory And Practice
PPT
Q-Metrics in Theory and Practice
PDF
Process Algebras and Petri Nets are Discrete Dynamical Systems
PDF
Introduction to Max-SAT and Max-SAT Evaluation
PDF
Distributed systems vs compositionality
PDF
Advanced matlab codigos matematicos
PDF
Coordinate sampler: A non-reversible Gibbs-like sampler
PDF
Kolev skalna2018 article-exact_solutiontoa_parametricline
PDF
Convex optimization methods
PDF
Sequence and Traverse - Part 3
PDF
Proof techniques and quantifiers : lecture 3
PPTX
Lecture 8 about data mining and how to use it.pptx
PDF
Introduction to Matlab
PPT
Poggi analytics - star - 1a
PDF
Conceptual Introduction to Gaussian Processes
Understanding distributed calculi in Haskell
RChain - Understanding Distributed Calculi
Applied machine learning for search engine relevance 3
Sep logic slide
Sparsenet
Q-Metrics in Theory And Practice
Q-Metrics in Theory and Practice
Process Algebras and Petri Nets are Discrete Dynamical Systems
Introduction to Max-SAT and Max-SAT Evaluation
Distributed systems vs compositionality
Advanced matlab codigos matematicos
Coordinate sampler: A non-reversible Gibbs-like sampler
Kolev skalna2018 article-exact_solutiontoa_parametricline
Convex optimization methods
Sequence and Traverse - Part 3
Proof techniques and quantifiers : lecture 3
Lecture 8 about data mining and how to use it.pptx
Introduction to Matlab
Poggi analytics - star - 1a
Conceptual Introduction to Gaussian Processes
Ad

More from Vlad Patryshev (20)

PDF
Formal methods 6 - elements of algebra
PPTX
Formal methods 1 - introduction
PPTX
Formal methods 7 - category theory
PDF
Truth, deduction, computation lecture i (last one)
PDF
Truth, deduction, computation lecture h
PDF
Truth, deduction, computation lecture g
PDF
Truth, deduction, computation lecture f
PDF
Truth, deduction, computation lecture e
PDF
Truth, deduction, computation lecture d
PDF
Truth, deduction, computation lecture c
PDF
Truth, deduction, computation lecture b
PDF
Truth, deduction, computation lecture a
PDF
Truth, deduction, computation lecture 9
PDF
Truth, deduction, computation lecture 8
PDF
Truth, deduction, computation lecture 7
PDF
Truth, deduction, computation lecture 6
PDF
Truth, deduction, computation; lecture 5
PDF
Truth, deduction, computation; lecture 4
PDF
Truth, deduction, computation; lecture 3
PDF
Truth, deduction, computation; lecture 2
Formal methods 6 - elements of algebra
Formal methods 1 - introduction
Formal methods 7 - category theory
Truth, deduction, computation lecture i (last one)
Truth, deduction, computation lecture h
Truth, deduction, computation lecture g
Truth, deduction, computation lecture f
Truth, deduction, computation lecture e
Truth, deduction, computation lecture d
Truth, deduction, computation lecture c
Truth, deduction, computation lecture b
Truth, deduction, computation lecture a
Truth, deduction, computation lecture 9
Truth, deduction, computation lecture 8
Truth, deduction, computation lecture 7
Truth, deduction, computation lecture 6
Truth, deduction, computation; lecture 5
Truth, deduction, computation; lecture 4
Truth, deduction, computation; lecture 3
Truth, deduction, computation; lecture 2

Recently uploaded (20)

PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Classroom Observation Tools for Teachers
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
01-Introduction-to-Information-Management.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Cell Types and Its function , kingdom of life
PPTX
Lesson notes of climatology university.
PDF
Basic Mud Logging Guide for educational purpose
PDF
Pre independence Education in Inndia.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Pharma ospi slides which help in ospi learning
TR - Agricultural Crops Production NC III.pdf
Anesthesia in Laparoscopic Surgery in India
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPH.pptx obstetrics and gynecology in nursing
Classroom Observation Tools for Teachers
human mycosis Human fungal infections are called human mycosis..pptx
01-Introduction-to-Information-Management.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
2.FourierTransform-ShortQuestionswithAnswers.pdf
RMMM.pdf make it easy to upload and study
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Cell Types and Its function , kingdom of life
Lesson notes of climatology university.
Basic Mud Logging Guide for educational purpose
Pre independence Education in Inndia.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Pharma ospi slides which help in ospi learning

Formal methods 5 - Pi calculus

  • 1. Formal Methods in Software Lecture 5. Pi-Calculus Vlad Patryshev SCU 2014 Prerequisites λ-1, λ-2
  • 2. This is Tier 2 of Modern Comp Sci
  • 3. History: Hoare, CSP, 1978 The trouble is: it’s static in structure - no process creation allowed
  • 4. What is π-calculus • Describes processes developing in time • Is conceptually similar to λ-calculus • Is used to describe o games o security protocols (spi-calculus) o biological and chemical processes o business processes • Is the base of modern concurrency libraries, like Scala Actors
  • 5. Scala Actors, an implementation of π class CustomerSupport extends Actor { def act() { while (true) { receive { case Stop => println("End of my sufferings") exit() case question:String => sender ! s"What do you mean, $question?!" } } } }
  • 6. Elements of Pi Notion Simplified Notation Milner Notation Meaning variable x,y,... x,y,... Stores (points to) data; typeless channel a,b,... a,b,... Used for communication process (agent) P,Q,... P,Q,... Denotes a combination of elementary processes write a!(x1,...xn) ā ⟨x1,...xn⟩ A process in which channel a outputs the values of x (sends a message) read a?(x1,...xn) a(x1,...xn) A process in which channel a reads a message with values x1,...xn new channel new(x1,...xn) ν(x1,...xn) Creates new names to be used within the scope identifier A(x1,...)=P A(x1,...)=P given a process, give it a name
  • 7. Operations on Processes Operation Simplified Notation Milner Notation Meaning sequence P.Q P.Q run process P, then process Q parallel P|Q P|Q run processes P and Q in parallel choice P+Q P+Q nondeterministically run either P or Q match if x=y then P if x=y then P obvious (this op is optional) mismatch if x≠y then P if x≠y then P obvious (this op is optional) null process 0 0 does nothing, and ends replication *(P)=P|*(P) !P unlimited replication of process P reduction P → Q P → Q evaluation: P performs a step and becomes Q
  • 8. Example Printer = b?doc . Println(doc) . Printer Server = a!b . Server Client = a?p . p!doc Life = Client | Server | Printer
  • 9. Laws and Rules First, a free variable is something that’s exposed to external world, while a bound variable is hidden in a scope - so we are free to rename bound variables, but we better not touch free variables. Defining Free and Bound Names • 0 has no bound or free names • a?x - a is free, x is bound (it’s a new name to be used further down) • new(x) - x is bound • a!x - a and x are free • A(x1,...xn)=P - x1,...xn are bound • P.Q, P|Q, P+Q - free(P)∪free(Q), bound(P)∪bound(Q) (where’s the rest?!)
  • 10. Laws and Rules for Reduction • fundamental rule (channels communication) • alpha-conversion (like in lambda), and unfolding law • monoid laws • choice rule • parallelization rule • replication rule • name binding rule • scope extension laws
  • 11. Laws and Rules for Reduction • fundamental rule (channels communication, beta-reduction) (x!z . P) | (x?y . Q) → P|(Q[y/z]) • alpha-conversion (like in lambda), and unfolding law o P[x/y] ≡ P o if A(x) = P, then A(y) = P[x/y] • monoid laws • choice rule • parallelization rule • replication rule • name binding rule • scope extension laws
  • 12. Laws and Rules for Reduction • fundamental rule (channels communication) • alpha-conversion (like in lambda), and unfolding law • monoid laws | is a commutative monoid, 0 is a neutral element + is commutative and associative • choice rule o If P→Q, then (P+R) → (Q+R) (?) • parallelism rule o If P→Q, then (P|R) → (Q|R) • replication rule o If P→Q, then *(P) → Q|*(P) (this follows from definition) • name binding rule
  • 13. Laws and Rules for Reduction • fundamental rule (channels communication) • alpha-conversion (like in lambda), and unfolding law • monoid laws • choice rule • parallelism rule • replication rule • name binding rule If P→Q, then new(x).P → new(x).Q (new names don’t break it) • scope extension laws o new(x).0 = 0 o new(x).(P|Q)=P|(new(x).Q) if x∉fn(P) o new(x).(P+Q)=P+(new(x).Q) if x∉fn(P) o new(x).new(y).P = new(y).new(x).P
  • 14. Can Model Lambda-Calculus λ-expression π-agent on port p Meaning M [M](p) Build an agent with a communication channel p λx M p?x.p?q.[M](q) Given a channel p, obtain the value of x and the communication channel q; call agent [M] on channel q x x!p A variable, when used, just publishes its channel M N new(a,b).( ([M](a))| (a!b.a!f)| *((b?c).[N](c)) Applying M to N means: create control channels a and b, and launch in parallel: ● [M] on a (it will wait) ● pass b and f to M via channel a ● read channel b on y, start [N] which will work with channel c; run it forever, we may need result more than once.
  • 15. Modeling Lambda: Example For M=λx x how will [M N] look? Can we reduce it to just [N]? [(λx x) N](f) = new(a).new(b) . ([M](a) | (a!b.a!f) | *(b?c.[N](c)) ) = new(a).new(b) . (a?x.a?y.x!y | (a!b.a!f) | *(b?c.[N](c)) ) → new(a).new(b) . (a?y.b!y | (a!f) | *(b?c.[N](c)) ) → new(a).new(b) . (b!f | 0 | *(b?c.[N](c)) ) → new(a).new(b) . (b!f | *(b?c.[N](c)) ) → new(a).new(b) . (b!f | b?c.[N](c)| *(b?c.[N](c)) ) → new(a).new(b) . (0 | [N](f) | *(b?c.[N](c)) ) → new(a).new(b) . ([N](f) | *(b?c.[N](c)) ) → new(b) . ([N](f) | *(b?c.[N](c)) ) → ([N](f) | new(b). *(b@c.[N](c)) ) → [N](f)
  • 16. Modeling Lambda: Example M=λa a, N=b // using (x!z).P | (x?y).Q ) → P|(Q[z/y]) [(λa a) b](p) = (new(q) . [M](q)) | (new(y) . q!(y,p)) | *((y?r) . [N](r)) = (new(q) . q?(x,q’) . x!q’ | (new(y) . q!(y,p)) | *(y?r . z!r))) → /* reduces to */ (new(q) . (new(y) . y!p) | *(y?r . z!r)) = (new(q) . (new(y) . y!p) | (y?r . z!r)) | *(y?r . !z(r))) → /* reduces to */ (new(q) . (new(y) . z!p) | *(?y(r) . z!r)) “=” /* nobody’s calling local channel y*/ (new(q) . (new(y) . z!p) “=” /* nobody uses q and y */ z!p = [z](p)