Mathematical Foundation of Computer Sciences VIII

Theoretical Computer Sciences

Guoqiang Li

School of Software, Shanghai Jiao Tong University

1 Petri Nets

1 Petri Nets

Petri Nets

 Systems are specified as a directed bipartite graph. Systems are specified as a directed bipartite graph. The two The two kinds of nodes in the graph: kinds of nodes in the graph:

Embedded Systems Design Fö 5 2 of2 75 Petri Nets

Petri Nets

 Systems are specified as a directed bipartite graph. Systems are specified as a directed bipartite graph. The two The two kinds of nodes in the graph: kinds of nodes in the graph: 1. Places: they hold the distributed state of the • Places: they holdsystem the expressed distributed by state the presence/absence of the system expressed by theof tokens presence/absence in the places. of tokens in the places.

Embedded Systems Design Fö 5 3 of3 75 Petri Nets

Petri Nets

 Systems are specified as a directed bipartite graph. Systems are specified as a directed bipartite graph. The two The two kinds of nodes in the graph: kinds of nodes in the graph: 1. Places: they hold the distributed state of the • Places: they holdsystem the expressed distributed by state the presence/absence of the system expressed by theof tokens presence/absence in the places. of tokens in the places.

• Transitions:2. denote Transitions the activity: denote in the the activity system in the system

Embedded Systems Design Fö 5 4 of4 75 Petri Nets

Petri Nets

 Systems are specified as a directed bipartite graph. Systems are specified as a directed bipartite graph. The two The two kinds of nodes in the graph: kinds of nodes in the graph: 1. Places: they hold the distributed state of the • Places: they holdsystem the expressed distributed by state the presence/absence of the system expressed by theof tokens presence/absence in the places. of tokens in the places.

• Transitions:2. denote Transitions the activity: denote in the the activity system in the system The state of the system: captured by the marking of the places (number of tokens in each place)  The state of the system: captured by the marking of the places (number of tokens in each place)

Embedded Systems Design Fö 5 5 of 75 5 Petri Nets

Petri Nets The dynamic evolution of the system: determined by the firing process of transitions.  Systems are specified as a directed bipartite graph. • A transitionThe istwo enabled kinds of and nodes may in fire the whenever graph: its predecessor places are marked. 1. Places: they hold the distributed state of the system expressed by the presence/absence of tokens in the places. 2. Transitions: denote the activity in the system

 The state of the system: captured by the marking of the places (number of tokens in each place)

6

Embedded Systems Design Fö 5 5 of 75 Petri Nets

Petri Nets

The dynamicThe dynamic evolution evolution of the of system:the system: determined determined by theby the firing firing process process of of transitions.transitions.

• A transition A transition is enabled is andenabled may and fire whenevermay fire whenever all its predecessorall placesits predecessor are marked. places are marked.

• If a transition fires it removes a token from each  If a transition fires it removes a token from each predecessor place and adds a token to each successor place. predecessor place and adds a token to each successor place.

7 Embedded Systems Design Fö 5 7 of 75 Nondeterminism

Nondeterminism

 Both T1 and T2 are enabled and any of the two may fire.

T1 T2

8 Embedded Systems Design Fö 5 8 of 75 NondeterminismNondeterminism Nondeterminism  Both T1 and T2 are enabled and any of the two may fire.  Both T1 and T2 are enabled and any of the two may fire. T1 T2

T1 T2

T1 T2

Embedded Systems Design Fö 5 9 of 75

Embedded Systems Design Fö 5 8 of 75

9 Nondeterminism Nondeterminism Nondeterminism  Both T1 and T2 are enabled and any of the two may fire.  Both T1 and T2 are enabled and any of the two may fire. T1 T2

T1 T2

T1 T2

Embedded Systems Design Fö 5 10 of 75

Embedded Systems Design Fö 5 8 of 75

10 NondeterminismNondeterminismNondeterminism Nondeterminism

 Both T1 and T2Both are T1 enabled and T2 and are anyenabled and any of the two mayof fire.the two may fire.  Both T1 and T2 are enabled and any of the two may fire. T1 T1 T2 T2

T1 T2

T1 T2 T1 T2

Embedded Systems Design FöEmbedded 5 Systems Design Fö 5 9 of 75 10 of 75

Embedded Systems Design Fö 5 8 of 75

11 Example

A producer and a consumer process communicating through a buffer:

12 Example Petri Net Example A producer and a consumer process communicating through a buffer:

prod. rec. prod. rec. prod. rec. B B B

send cons. send cons. send cons.

prod. rec. prod. rec. prod. rec. B B B

send cons. send cons. send cons.

Embedded Systems Design Fö 5 17 of 75

13 Example Petri Net Example A producer and a consumer process communicating through a buffer:

prod. rec. prod. rec. prod. rec. B B B

send cons. send cons. send cons.

prod. rec. prod. rec. prod. rec. B B B

send cons. send cons. send cons.

Embedded Systems Design Fö 5 23 of 75

14 Notice that the buffer is considered to be infinite (tokens accumulate in B).

Example Petri Net Example A producer and a consumer process communicating through a buffer:

prod. rec. prod. rec. prod. rec. B B B

send cons. send cons. send cons.

Embedded Systems Design Fö 5 26 of 75

15 Example Petri Net Example A producer and a consumer process communicating through a buffer:

prod. rec. prod. rec. prod. rec. B B B

send cons. send cons. send cons.

Embedded Systems Design Fö 5 26 of 75 Notice that the buffer is considered to be infinite (tokens accumulate in B). 15 The buffer size is three (number of initial tokens in B’)

• Number of tokens in B’: how many free slots are available in the buffer;

• Number of tokens in B: how many messages (tokens) are in the buffer.

Total number of tokens in B and B’ is constant (= 3).

Example Petri Net Example

Here we have the same model as on the previous slides, but with limited buffer. We have the same model,The but buffer with limitedsize is three buffer. (number of initial tokens in B’)

prod. rec. B

B’ send cons.

 Nr. of tokens in B’: how many free slots are available in the buffer;

 Nr. of tokens in B: how many messages (tokens) are in the buffer. Total number of tokens in B and B’ is constant (= 3).

Embedded Systems Design Fö 5 28 of 75

16 Example Petri Net Example

Here we have the same model as on the previous slides, but with limited buffer. We have the same model,The but buffer with limitedsize is three buffer. (number of initial tokens in B’)

prod. rec. B

B’ send cons.

The buffer size is three (number of initial tokens in B’)  Nr. of tokens in B’: how many free slots are available in the buffer;

• Number of tokens in B’:Nr. how of manytokens free in B: slots how are many available messages in the (tokens) buffer; are in the buffer. • Number of tokens in B:Total how manynumber messages of tokens (tokens) in B and are B’ inis constant the buffer. (= 3).

Total number of tokens in B and B’ is constant (= 3). Embedded Systems Design Fö 5 28 of 75

16 Example Petri Net Example

Here we have the same model as on the previous slides, but with limited buffer. TheWe buffer have the size same is three model, (number but withof initial limited tokens buffer. in B’)

prod. rec. prod. rec. prod. rec. B B B

B’ B’ B’ send cons. send cons. send cons.

prod. rec. prod. rec. prod. rec. B B B

B’ B’ B’ send cons. send cons. send cons.

Embedded Systems Design Fö 5 33 of 75

17 Formal Definition

A Petri net is a four-tuple: PN = hP, T , I , Oi, where P ∩ T = ∅

• P: a finite set of places, {p1, p2,..., pn}

• T : a finite set of transitions, {t1, t2,..., ts }

• I : an input function, T × P → {0, 1}

• O: an output function, T × P → {0, 1}

M0: an initial marking, P → N

18 As an uninterpreted model, Petri Nets can be used for several, very different classes of problems.

Some Features and Applications of Petri Nets

Intuitive:

• Easy to express concurrency, synchronisation, nondeterminism.

• Nondeterminism is an important difference between Petri nets and sequential models.

19 Some Features and Applications of Petri Nets

Intuitive:

• Easy to express concurrency, synchronisation, nondeterminism.

• Nondeterminism is an important difference between Petri nets and sequential models.

As an uninterpreted model, Petri Nets can be used for several, very different classes of problems.

19 Some Features and Applications of Petri Nets

Industrial production systems,

Information systems,

Computer architectures,

Operating systems,

Concurrent programs,

Distributed systems,

Hardware systems

20 • You can check that available resources are not exceeded.

Liveness: A transition t is called live if for every possible marking there exists a chance for that transition to become enabled.

The whole net is live, if all its transitions are live.

• Important in order to check that the system is not deadlocked.

Reachability: given a current marking M and another marking M0, does there exist a sequence of transitions by which M0 can be obtained?

• You can check that a certain desired state (marking) is reached.

• You can check that a certain undesired state is never reached.

Properties and Analysis of Petri Nets

Boundedness: number of tokens in a place does not exceed a limit.

21 Liveness: A transition t is called live if for every possible marking there exists a chance for that transition to become enabled.

The whole net is live, if all its transitions are live.

• Important in order to check that the system is not deadlocked.

Reachability: given a current marking M and another marking M0, does there exist a sequence of transitions by which M0 can be obtained?

• You can check that a certain desired state (marking) is reached.

• You can check that a certain undesired state is never reached.

Properties and Analysis of Petri Nets

Boundedness: number of tokens in a place does not exceed a limit.

• You can check that available resources are not exceeded.

21 • Important in order to check that the system is not deadlocked.

Reachability: given a current marking M and another marking M0, does there exist a sequence of transitions by which M0 can be obtained?

• You can check that a certain desired state (marking) is reached.

• You can check that a certain undesired state is never reached.

Properties and Analysis of Petri Nets

Boundedness: number of tokens in a place does not exceed a limit.

• You can check that available resources are not exceeded.

Liveness: A transition t is called live if for every possible marking there exists a chance for that transition to become enabled.

The whole net is live, if all its transitions are live.

21 Reachability: given a current marking M and another marking M0, does there exist a sequence of transitions by which M0 can be obtained?

• You can check that a certain desired state (marking) is reached.

• You can check that a certain undesired state is never reached.

Properties and Analysis of Petri Nets

Boundedness: number of tokens in a place does not exceed a limit.

• You can check that available resources are not exceeded.

Liveness: A transition t is called live if for every possible marking there exists a chance for that transition to become enabled.

The whole net is live, if all its transitions are live.

• Important in order to check that the system is not deadlocked.

21 • You can check that a certain desired state (marking) is reached.

• You can check that a certain undesired state is never reached.

Properties and Analysis of Petri Nets

Boundedness: number of tokens in a place does not exceed a limit.

• You can check that available resources are not exceeded.

Liveness: A transition t is called live if for every possible marking there exists a chance for that transition to become enabled.

The whole net is live, if all its transitions are live.

• Important in order to check that the system is not deadlocked.

Reachability: given a current marking M and another marking M0, does there exist a sequence of transitions by which M0 can be obtained?

21 Properties and Analysis of Petri Nets

Boundedness: number of tokens in a place does not exceed a limit.

• You can check that available resources are not exceeded.

Liveness: A transition t is called live if for every possible marking there exists a chance for that transition to become enabled.

The whole net is live, if all its transitions are live.

• Important in order to check that the system is not deadlocked.

Reachability: given a current marking M and another marking M0, does there exist a sequence of transitions by which M0 can be obtained?

• You can check that a certain desired state (marking) is reached.

• You can check that a certain undesired state is never reached.

21 Vector Addition Systems

21 Petri Nets and Vector Systems

Petri Net Example

A producer and a consumer process communicating through a buffer: 1 1   prod. rec.   0 B   0 0 send cons.

22

Embedded Systems Design Fö 5 12 of 75 Petri Nets and Vector Systems Petri Net Example

A producer and a consumer process communicating through a buffer: −1    0    prod. rec.    1    B 1   0  0  1   1 Petri Net Example   0       0 −−−−−→ 1 send cons.     0 0 0 0 prod. rec. prod. rec. B B send cons. send cons.

23

Embedded Systems Design Fö 5 12 of 75

Embedded Systems Design Fö 5 13 of 75 Definition (Reachability problem) d w Input: d-VAS A, and u, v ∈ Z , u and v is reachable if ∃w, u −→ v or LA(u, v) 6= ∅.

Example

1-VAS A = {−2, 2}

LA(0, 5) = ∅ (unreachable), LA(0, 4) 6= ∅(reachable)

Formal Definition

Definition (d-VAS) d d a Assume d ≥ 1, A ⊆ Z . Given u, v ∈ Z , define one step as u −→ w v, if v − u = a ∈ A. The transitive closure is:−→. The VAS language ∗ w LA(u, v) = {w | w ∈ A , u −→ v}

24 Example

1-VAS A = {−2, 2}

LA(0, 5) = ∅ (unreachable), LA(0, 4) 6= ∅(reachable)

Formal Definition

Definition (d-VAS) d d a Assume d ≥ 1, A ⊆ Z . Given u, v ∈ Z , define one step as u −→ w v, if v − u = a ∈ A. The transitive closure is:−→. The VAS language ∗ w LA(u, v) = {w | w ∈ A , u −→ v}

Definition (Reachability problem) d w Input: d-VAS A, and u, v ∈ Z , u and v is reachable if ∃w, u −→ v or LA(u, v) 6= ∅.

24 Formal Definition

Definition (d-VAS) d d a Assume d ≥ 1, A ⊆ Z . Given u, v ∈ Z , define one step as u −→ w v, if v − u = a ∈ A. The transitive closure is:−→. The VAS language ∗ w LA(u, v) = {w | w ∈ A , u −→ v}

Definition (Reachability problem) d w Input: d-VAS A, and u, v ∈ Z , u and v is reachable if ∃w, u −→ v or LA(u, v) 6= ∅.

Example

1-VAS A = {−2, 2}

LA(0, 5) = ∅ (unreachable), LA(0, 4) 6= ∅(reachable)

24 Preliminaries

Three equivalent models: • Vector addition system(VAS), ideal for proof • Vector addition system with states(VASS), ideal for examples • Q a finite set of states • Transition rule Q A Q ✓ ⇥ ⇥ • n-VASS can be encoded in n+3 - VAS(Hopcroft & Pansiot 1979) • Petri nets, ideal for applications • Places, tokens, transitions

1-VASS Petri Net

n-VASS can be encoded in n+3-VAS(Hopcroft & Pansiot 1979).

VAS and VASS

Definition (Vector addition system with states(VASS)) d , A triple hQ, ∆, di, and A ⊆ Z • Q a finite set of states

• Transition rule ∆ ⊆ Q × A × Q

25 n-VASS can be encoded in n+3-VAS(Hopcroft & Pansiot 1979).

Preliminaries

VAS and VASS Three equivalent models: • Vector addition system(VAS), ideal for proof • Vector addition system with states(VASS), ideal for examples • Q a finite set of states Definition (Vector addition• systemTransition with states(VASS))rule Q A Q d ✓ ⇥ ⇥ , A triple hQ, ∆, di, and A ⊆•Zn-VASS can be encoded in n+3 - VAS(Hopcroft & Pansiot 1979) • Q a finite set of states• Petri nets, ideal for applications • Transition rule ∆ ⊆ Q ו APlaces,× Q tokens, transitions

1-VASS Petri Net

25 Preliminaries

VAS and VASS Three equivalent models: • Vector addition system(VAS), ideal for proof • Vector addition system with states(VASS), ideal for examples • Q a finite set of states Definition (Vector addition• systemTransition with states(VASS))rule Q A Q d ✓ ⇥ ⇥ , A triple hQ, ∆, di, and A ⊆•Zn-VASS can be encoded in n+3 - VAS(Hopcroft & Pansiot 1979) • Q a finite set of states• Petri nets, ideal for applications • Transition rule ∆ ⊆ Q ו APlaces,× Q tokens, transitions

1-VASS Petri Net

n-VASS can be encoded in n+3-VAS(Hopcroft & Pansiot 1979).

25 Three Equivalent Models

Vector addition system(VAS), ideal for proof

Vector addition system with states(VASS), ideal for examples

Petri nets, ideal for applications

26 VAS as Coordinate

from slides by Sylvain Schmitz

27 Theoretical Computer Sciences

27 BASICS

What is the core in computing science?

28 BASICS

Computation!

29 The First Question

Q1: Given a model, which problem can be solved by the model?

30 Theory of Computation

Theory of Computation.

31 Church-Turing Thesis

Everything algorithmically computable is computable by a Turing machine.

32 Church-Turing Thesis

33 Church-Turing Thesis

34 The Second Question

Q2: Given a solvable problem, can it be solved efficiently?

35 Theory of Complexity

Theory of Complexity.

36 Time: P ⊆ NP ⊆ EXP ⊆ NEXP

Space: ⊆ NL ⊆ PSPACE = NPSPACE

Hybrid: L ⊆ NL ⊆ P ⊆ NP ⊆ PSPACE⊆ EXP

Counting: NP ⊆ ]P ⊆ EXP

Probability: P ⊆ ZPP ⊆ RP ⊆ NP ⊆ PP ⊆ PSPACERP ⊆ BPP ⊆ PP

Quantum: P ⊆ BPP ⊆ BQP ⊆ PP ⊆ PSPACE

Complexity Classes

37 Space: L ⊆ NL ⊆ PSPACE = NPSPACE

Hybrid: L ⊆ NL ⊆ P ⊆ NP ⊆ PSPACE⊆ EXP

Counting: NP ⊆ ]P ⊆ EXP

Probability: P ⊆ ZPP ⊆ RP ⊆ NP ⊆ PP ⊆ PSPACERP ⊆ BPP ⊆ PP

Quantum: P ⊆ BPP ⊆ BQP ⊆ PP ⊆ PSPACE

Complexity Classes

Time: P ⊆ NP ⊆ EXP ⊆ NEXP

37 Hybrid: L ⊆ NL ⊆ P ⊆ NP ⊆ PSPACE⊆ EXP

Counting: NP ⊆ ]P ⊆ EXP

Probability: P ⊆ ZPP ⊆ RP ⊆ NP ⊆ PP ⊆ PSPACERP ⊆ BPP ⊆ PP

Quantum: P ⊆ BPP ⊆ BQP ⊆ PP ⊆ PSPACE

Complexity Classes

Time: P ⊆ NP ⊆ EXP ⊆ NEXP

Space: L ⊆ NL ⊆ PSPACE = NPSPACE

37 Counting: NP ⊆ ]P ⊆ EXP

Probability: P ⊆ ZPP ⊆ RP ⊆ NP ⊆ PP ⊆ PSPACERP ⊆ BPP ⊆ PP

Quantum: P ⊆ BPP ⊆ BQP ⊆ PP ⊆ PSPACE

Complexity Classes

Time: P ⊆ NP ⊆ EXP ⊆ NEXP

Space: L ⊆ NL ⊆ PSPACE = NPSPACE

Hybrid: L ⊆ NL ⊆ P ⊆ NP ⊆ PSPACE⊆ EXP

37 Quantum: P ⊆ BPP ⊆ BQP ⊆ PP ⊆ PSPACE

Complexity Classes

Time: P ⊆ NP ⊆ EXP ⊆ NEXP

Space: L ⊆ NL ⊆ PSPACE = NPSPACE

Hybrid: L ⊆ NL ⊆ P ⊆ NP ⊆ PSPACE⊆ EXP

Counting: NP ⊆ ]P ⊆ EXP

Probability: P ⊆ ZPP ⊆ RP ⊆ NP ⊆ PP ⊆ PSPACERP ⊆ BPP ⊆ PP

37 Complexity Classes

Time: P ⊆ NP ⊆ EXP ⊆ NEXP

Space: L ⊆ NL ⊆ PSPACE = NPSPACE

Hybrid: L ⊆ NL ⊆ P ⊆ NP ⊆ PSPACE⊆ EXP

Counting: NP ⊆ ]P ⊆ EXP

Probability: P ⊆ ZPP ⊆ RP ⊆ NP ⊆ PP ⊆ PSPACERP ⊆ BPP ⊆ PP

Quantum: P ⊆ BPP ⊆ BQP ⊆ PP ⊆ PSPACE

37 Complexity Zoo

https://complexityzoo.net/Complexity_Zoo

545 classes now!

38 The Third Question

Q2: Given an (efficient) problem, how to solve it?

39 Theory of Programming

Theory of Programming.

40 Theory of Programming

data structures

41 Process Rewriting Systems

PRS (G,G)

PAD (S,G) PAN (P,G)

Pushdown (S,S) Processes PA (1,G) Petri Nets (P,P)

BPA (1,S) BPP (1,P)

Finite-State Systems (1,1)

Figure The PRShierarchy

42