Visualizing Program Semantics

The current book is a combination of number of great ideas, applications, case studies, and practical systems in the domain of Semantics. The book has been divided into two volumes. The current one is the second volume which highlights the state-of-the-art application areas in the domain of Semantics. This volume has been divided into four sections and ten chapters. The sections include: 1) Software Engineering, 2) Applications: Semantic Cache, E-Health, Sport Video Browsing, and Power Grids, 3) Visualization, and 4) Natural Language Disambiguation. Authors across the World have contributed to debate on state-of-the-art systems, theories, models, applications areas, case studies in the domain of Semantics. Furthermore, authors have proposed new approaches to solve real life problems ranging from e-Health to power grids, video browsing to program semantics, semantic cache systems to natural language disambiguation, and public debate to software engineering.


Introduction
Generally, any program is designed for computing one problem based on one special architecture computing machine. It is unavoidable that some machine constraint will be transferred to the program code. When the program is formalized for being verified or validated the machine constraints will be treated as properties of program .
Turing model,the theory model of program(mainstream ), has two special features: Only one storage tape that determines the changing status is sequent; Only one write-read head that determines the sequence of action operating is serialization; Accordingly, research on program semantics is focus on two areas: the first viewpoint thinks that a program is a set of status. the operating is a procedure of status changing. So, for that the formalization tools describe status. The other one viewpoint thinks that a program is a set of processes. A status is abstracted for understanding the process. So, for that the formalization tools describe the processes, and a status only is the composition of processes by timeline.
One target of formalizing a program is,not for a special machine, to get one general and one abstract specification Bjorner et al. (1987); Spivey (1998). So, one program specification must describe the following basic properties: • variables and theeir changing; • the consumptive or the nonconsumptive resources; • the semantics of operation; • the control flow in program, not one in computing machine.
For the problems, Petri nets is an ideal theory tool. By both extending and applying Petri nets theory, the semantics of program can be formalized visually Breuer & Lano (1999); Girault & Valk (2002); Jensen et al. (2007).

Model
Informally, a program is composed of data structure and algorithm Harel (1987); Khedker et al. (2009) ;Woodcock & Davies (1996). We know data structure is a discrete description of entity attributes based on one special computing machine. For example, the data structure of tree can be described as in figure 1(if the tree only has such attributes) understand that is a tree but not any others. So, the discrete description of attributes does not help to understand an entity .
And there is another characteristics in coding a program. For example, there is a segment of algorithm in figure 2, o 1 and o 2 are labeled as a statement on x and a statement on y respectively(ignore other unconcern processes).
Also, we can design another algorithm(figure 3) to fulfill the same function as in figure 2.
The reason to explain the case is in design phase designer only concerns the result produced by the algorithm, and thinks the algorithm is right if and only if the algorithm can produce an expected result. However, the same result the two algorithms can produce but not the same semantics the two algorithms have.
In a word, when designing an algorithm, the designer transforms some constraints into the algorithm unconsciously, for example, serialization(discussed above). Once the algorithm finished, the additional relations are fixed into the code. So, two aftereffects are forged: 1. Two independent operations will be serialized, a new relation is added; or 2. The two concurrent operations will be serialized and the relation of concurrence is lost.
For convenience, the relation between variables, variable and operation, or operations is called control.
Asynchronous control, A-control for short, is a kind of relation between operation and variable that has no directive or indirected causality. A-control has two types: concurrent control and noncorrelation control.
A concurrent control denotes there are one or more common direct or indirect causality sets among operations (variables), e.g., o in figure 4 is a common result of b 1 , b 2 and b 3 . Dashed line shows there are more than one node, the straight line show there is a directive relation.
A noncorrelation control denotes there is no any common direct or indirect causality among operations (variables) . A noncorrelation control is no necessary in program. However, in a large-scale software system, noncorrelation controls are usual. The noncorrelative variables or operations in a system may be associated for building a new system. For example, in figure  5(1), {a 1 , a 2 , ··· , a i } is non correlative with {b 1 , b 2 , ··· , b i } in a system, however, in figure   208 Semantics in Action -Applications and Scenarios www.intechopen.com (2), {a 1 , a 2 , ··· , a i } is associated with {b 1 , b 2 , ··· , b i } because of c i in a new system. c i is a common result among {a 1 , a 2 , ··· , a i } and {b 1 , b 2 , ··· , b i }. Obviously, the noncorrelation control between {a 1 , a 2 , ··· , a i } and (2)

Fig. 5. Asynchronous Control
Linear control, L-control for short, describes causality among variables and operations. L-control has two kinds of types: direct associated and indirect associated.
one variable is a direct composition of another one, e.g., X is composed of b as in figure 6(1); or one variable is a indirect sub-composition of another one, e.g., in figure 6(2), Y is directly composed of both a and b. Specially, c is an indirect sub-composition of Y. For operations, L-control denotes one operation is a run condition of another one , e.g., in figure 7(1), c i run only after a i finished (direct associated); or one operation is one of run conditions of another one (indirect associated), e.g., in figure 7(2), c i can not run immediately after a i finish if b i do not finish.

Fig. 7. Linear Operations
Loop control is a special L-control(figure 8). because of the recursive attributes not being permitted, A loop control can only describe relations among operations.
Parallel control , P-control for short, denotes variables or operations are parallel. On one hand, parallel operations have direct common pre-operations or post-operations as in figure  9(1). A is parallel to B because C is a direct common post-operation of A and B. On the other hand, parallel variables have direct common target variables. In figure 9(2), both right and le f t construct a tree, a parallel control exists between le f t and right. tree: left: tree; right:tree; Fig. 9. Parallel Control P-control is relative. In figure 10(1), a is parallel to b. But, if another P-control is inserted between a and b ( figure 10(2)), then the new a is the direct run condition of b. Obviously, the new a is not parallel to b and the P-control between a and b losts.

Fig. 10. Relative Parallel Control
Trigger Action Control is the logic relation that regulates how to run, delay and terminate operations. Any operation can only run after it gets (satisfied) a control handle of computing machine. In other words, computing machine determines how to run a program.
In figure 11, a control handle arrives at the statement doingsomething.
Here, controlo f program = true and controls of other statements can not be satisfied (controlo f o i = false), the statement doingsomething is running. and the other statements do not run. So, Control mechanism can help to describe the dynamic properties.

Regulate Order
Single control handle determines a program is sequent. If a program has more than one control handles, how about a program should be? For example, a program in figure  11 has one control handle, statements only run in turn. When the program has two control handles, the program can run by many ways, such as in figure 12.
Resource is physical and depend on a computing machine. Running a program needs resources, such as RAM, CPU, communication channel, and so on. Generally, resources are managed by an operation system. (3)

Fig. 12. Regulate Order
Resource can be either consumable or inconsumable . Consumable resource will be consumed out during a program run. Consumable resources are exclusive, such as RAM ,CPU. Inconsumable resource can be shared, such as system clock and any program can read the system clock any time.
We know, the mathematics model of program is Turing machine. Accordingly, a program is a set of variables and read-writes.
-Operation is to process variables, such as to update the current value of variable; -Variable records the result produced by operation(s). An operation can be described by the track of changing value of variable.

Token
As same as Petri net, token is expressed by symbol "•". Here, token has two functions: firstly, the flowing track of token denotes control flow; secondly, token in a variable place is expressed by the value instead of symbol "•", and the number of tokens in variable place is the current value of variable place, such as in figure 14.b. To hold consistency, the number of token in control place is mapped to a value of integer type. In figure 14.a, the data type denoted by the place is integer and the current value is 1. So, the number of token in place is 1. (a) represents the relation of control flow which denotes the firing of transition t 1 will consume resource s 1 ; (b) represents the read relation which denotes the firing of transition t 2 will read the current value of s 2 but not modify the current value of s 2 ;

212
Semantics in Action -Applications and Scenarios

www.intechopen.com
Visualizing Program Semantics 7 (c) represents the write relation which denotes the firing of transition t 3 will modify the current value of s 3 ; (d) represents the read-write relation which is the combination of a read relation and a write relation, i.e. the firing of transition t 4 not only read the current of s 4 , but also modifies the current value of s 4 .
The four kinds of relations are classified into two categories: flow relationship(a) and read-write relationship (b, c, d). Flow relationship is a kind of consumable relationship. Control place can only hold flow relationship(control arc)and tokens in a control place must flow. Read-write relationship is a kind of inconsumable relationship;Read-write do not consume any token and tokens in a variable place can not flow around. Variable place can only hold read-write relationship(read arc, write arc or both).

Transition
Extension of transition defines a new kind of transition called variable transition. Variable transition can not only connect with control place but also variable place. In other words, the firing of transition may either consume resources(e.g. need some tokens) or not. Contrast to variable transition, transition defined in Petri net is called control transition . The structure of control transition is represented as in figure 16.a. Guard is a mechanism to control the firing of control transition. Control guard holds false only if the firing condition is not satisfied, i.e., the transition can not fire; When the firing condition is satisfied, the control guard hold true and the transition fire. The structure of variable transition is composed of three parts (figure 16.b): E denotes a control guard which is same as control guard of control transition; B is called variable guard which denotes the condition satisfied by variables(places).

I operations script .
Because Petri nets is a self-explain system, places need not be declared explicitly. Variables are described by variable places. In figure 17, places are variable places. Assignment X := a + b + c can be described as a variable transition(figure 18), where a,b and c connect with the variable transition. Read operation is described by read arc between a variable transition and a variable place. Write operation is described by write arc between a variable transition and a variable place. Figure 20 describes assignment X := a + b + c, where Figure 19(1) is read operation. Figure 19 (2) is write operation.
When a variable is both read and write, readwrite relation can be applied. Figure 20 is a readwrite relation. Consumable resource is described by control place. The number of tokens  in a control place denotes the number of available resource described by the control place. The weight of arc denotes the number of resource consumed by a transition. For example, RAM consumption can be described as in figure ??. Place denotes the resource RAM; the number of tokens in place denotes the available number of RAM; o 1 denotes an operation; the weight of arc denotes that operation o 1 will consume two units of RAM during firing.

Formal definitions
For a convenience, the extension is called rwPN (readable and writable Petri Net ). The following discussion will refer some concepts of Petri Net or Coloured Petri Net.
where S c , S v , T are finite sets and R, W, F are relations respectively.
Let S be a function from a set of places to a set of colors, such as where S is a set of places,S v is a set of Variable places,S c is a set of control places,C is a set of colors. Here and afterward, sets are finite .
Because dom(F) ∪ cod(F) can contain places,transitions , or both. For a convinence and in a discussion context, dom(F) ∪ cod(F) can be viewed as a set of places,asetoftransitions or both on need.
F only connects between S c and T or T and S c , and is defined as where T is a set of transitions. F describes a situation in which tokens are flowable, i.e. tokens can flow out of this place and into another one along Control Flow F.
R only connects between S v and T, and is defined as W also only connects between T and S v , and is defined as is represented graphically by a line with circle ⊸ but which points to a variable place .
Semantically similar to Coloured Petri Net, a transition is also controlled by a GUARD that is a boolean value. Let G c denote this kind of GUARD , called control guard .
T is a set of transitions , and G c changes from TRUE to FALSE alternatively. When the preset of a transition has enough tokens , the control guard of transition is TRUE. Otherwise, the control guard of transition is FALSE.
Additionally, there has another GUARD to monitor the Variable placesinthepreset of transition . Such a GUARD called variable guard . Let G v be a variable guard and where the boolean expression specifies a variable-related condition to fire a transition . Any operand in BooleanExpression either holds a constant or just is a variable place .
Accordingly, the two GUARDS codetermine whether a transition can be fired.
The third part of a transition is statements which describes the expected action of a transition . Statements can be written by a program language, such as C, Java, etc. Let function L be the action script of a transition , then L : T → statement Summarily, a transition has three components: G c , G v and L . Let function H be when G v (t)=∅ and L (t)=∅, the transition is the same as that of Coloured Petri Net.
when G c (t)=∅, the transition can fire without any Control Flow .
when G v (t)=∅, the transition can fire when the preset of transition has enough tokens.
where T| S c is a set of transitions connecting with control places.
where T| S v is a set of transitions connecting with Variable places.
Theory 4.1. If N cv is cvNet and N dv is dvNet of rwPN N respectively, then where ∪ is the operator of graph union, based on definitions rwPN N, cvNet N cv and dvNet N dv , the conclusion holds obviously.
So, if a system is modeled by rwPN , the system features can be captured from two views. One view is from Control View Net which describes the control flow relationship of system. The other one is from Data View Net which describes the entity relationship of system.
Specially, if let color set C = C ∪ Integer ∪ DATATYPE ∪ BOOL ∪ BooleanExpression ∪ statement and cd = S ∪ H , rwPNs can be mapped to Coloured Petri NetN =< P, T, Pre, Post, C, cd > . The mapping from rwPNs to Coloured Petri Netwill further be discussed in the next section.
the Variable Guardsof transitions and the action script are concerned.
Theory 4.2. If N cs is cvNets and N ds is dvNets of rwPNs N respectively, then where ∪ is the operator of graph union, based on definitions rwPNs N, cvNets N cs and dvNets N ds , the conclusion also holds.
When the dynamic features of system are concerned, there are also two views to study the system, cvNets and dvNets . Specially, Because GUARD G c and GUARD G v in H will determine whether transitions can be fired, some properties of program, e.g.,the code coverage and key path in the program testing, can be computed automatically based on H .

Dynamic semantics
where, enabled(M c , t) denotes • t has enough number of tokens and leads to control guard where Val(H (t)) denotes the current value of s updated by t.
From above definition, a transition will be affected by three factors: tokens in control place, variable guard(B) and control guard(E).
Definition 5.6. t 1 , t 2 ∈ T and t 1 = t 2 , in marking M, t 1 is concurrent with t 2 , iff Definition 5.7. A directed net N =(B, E; F) is a general occurrence net, if N satisfies the condition: "•" is a symbol of relation composition.
A general occurrence net N =( B, E; F),ifx, y ∈ E or x, y ∈ B(x = y), and (x, y) ∈ F + , then there is a partial order relation between x and y, denoted as x ≺ y, or more strictly x ≺ N y .
Then (N ′ , ρ) is a process of system Σ . Where, 1. Process may have a special place ε which is not appeared in rwPNs . ε denotes the partial order of transitions. Transition labels in process are transition names in rwPNs . Place labels in process are place names in rwPNs or label ε . Accordingly, the process may have special arc(s) (complementary arc) ,associated with ε, which are also not appeared in rwPNs .
2. N will guarantee the less complexity through removing the redundant arcs.
3. Elements of S p mapped from • e • are similar to places of Petri nets. Elements of S v mapped from • e • can be : This condition is similar to general petri net theory except that the tail part of condition is 6. Not all processes need all initial resources described by the initial marking M 0 . This condition requires |{b}| ≤ M 0 (s) instead of |{b}| = M 0 (s). If the first operation upon an element of S v is read action, the element must have an initial value.
The process of Petri nets is an observational record of system . Based on the above definition of process, the mapping rules to process can be summarized by the graphic representation. In Figure 22, one variable place is only operated by one transition.
• Read relation is mapped to input arc(a out-arc with arrowhead); • write relation is mapped to output arc(a in-arc with arrowhead); • read-write relation is mapped to input-output arc(one read and one writečl'. Figure 23 lists the process mapping rules on read-write concurrent or conflict relations between two transitions. When one transition writes after the other transition has read, place ε is introduced to denote a sequential relation between the two transitions. When two transitions write the same place at the same time, place ε is introduced to denote the sequential order relation.
Based on above rules, more complex mapping specification can be work out.

Analysis
To verify the formal specification, all petri net theory can be applied. In this section, we will discuss some special features.
Theory 6.1. A program has only one place s, • s = ∅.

Proof:
The computing target is initialized by only one computing unit. The unit must provide all initial condition for the computing target. Meanwhile the unit will also ask for cooperation with other units because the unit can not fulfill the special computing. If the number of • s = ∅ and greater than 1, the computing target will be more than 1 and are initialized by different 221 Visualizing Program Semantics www.intechopen.com Proof: When a computing task reach a status in which all other status are no changed anymore, i.e. the program reach a fixed point.
The above two theorems show there exists the boundary in a program specification.
Let S is a step in marking M of system, then S's successive marking is M, ∀p ∈ P, P is a set of all status.
where, X(t) denotes the number of transition t appearing in step X. M ′ is the succession of M, written as M[X > M ′ , i.e. , after X firing, reaches from marking M to M ′ . I − denotes the number of consumed tokens or the value for one variable. I + denotes the number of produced tokens or the updated value for one variable.
So, system will step into a new status, and 1. In the same step, more than one action can be fired.
2. Based on the preset of transition, I − , I + and M , the marking M ′ can be determined.
Resources or control flow are described by tokens, the number of tokens in system must be conserved. The property of conservation of token number is called invariant. Invariable(including T invariant and S invariant) is limited within boundary, i.e. local invariant and system invariant. The invariant can be computed through reference matrix.

222
Semantics in Action -Applications and Scenarios

www.intechopen.com
From initializing computing to result returning, the task must be fulfilled in n steps. occurrence sequence: we can get two sequences: 1. sequence of status changing:M 0 M 1 M 2 ···M n M; 2. sequence of transition changing:S 1 S 2 ···S n . Theory 6.3. Any marking M i can reach at from the initial marking M 0 , i.e. there exists one sequence: If such a sequence is not exists, then there are two cases: • Net is not connective. So, there are at least two no connective subnet and the two subnet have no any intercourse. Because any subnet has its special computing target, the two computing targets are not interactive. That is inconsistency with the one and only of computing target. Therefore, the two computing targets are unsure.
• If net is connective, but there exists a marking M k can not reach. In M k , place p k has no token. p k is not isolated and has pre-transition t k . So, there is a function I + . Because p k has no token, therefore t k is not enable, i.e., t k can not fire. In other words, the program has an operation and the operation will never be executed. So, such a computing procedure is not optimization and even wrong.
From above, any marking M i is reachable from the initial marking M 0 .

Theory 6.4. elements in net are partial order and there exists least upper bound and greatest lower bound
Proof: In any system , every operation or status serves for the computing target. Therefore, all operations and status are correlation, i.e. all are useful for the computing target. So, there does not exist any independent subnet, and all elements are in the same partial order set. The initial set • s = ∅ is greatest lower bound. s • = ∅ is least upper bound.
In the following discussion, let C is a Coloured Petri Nets , R is a rwPNs . C is the Coloured Petri Netmapping of R. For any element x ∈ R, x ′ is the mapping element in C , and vice versa.
Theory 6.1. if t ′ ∈ C is firable, then t is also firable.
Proof: If t ′ ∈ C is firable , then three condition must be satisfied.
1. the preset of t ′ has enough tokens; 2. the postset of t ′ has enough capacity; 3. the arc expression • t ′ ×{t ′ } can be evaluated correctly.

223
Visualizing Program Semantics

www.intechopen.com
In R, whether t fires or not depends on preset of t. Let p be the preset of t. p may contain control place p p ,variable place p v or both. For a convenient, suppose p p and p v respectively contains only one single place. for control place , p p is same as the preset of t ′ . For variable place ,I f (p v , t) ∈ R, then there are two corresponding arcs, Because t ′ ∈ C is firable, p v has enough token and capacity.
If (t, p v ) ∈ W, then there are two corresponding arcs, Because t ′ ∈ C is firable, p v has enough token and capacity.
The arc expression • t ′ ×{t ′ } can be evaluated correctly, and the number of tokens in variable place remain unchanged. Meanwhile, the logical condition in arc expression • t ′ ×{t ′ } are removed and put into the variable guard of t, consequently, the three condition of t's firing 1. control guard holds; 2. variable guard holds; 3. the value of variable place can be evaluated correctly.
can be satisfied. Therefore, t also is firable.

Proof:
Because b ′ is reachable, therefore transitions in the preset of b ′ can fire. Let the preset of b ′ is T ′ and the preset of T ′ is P ′ . To prove b is reachable, the preset of b must be firable. Let the preset of b is T and the preset of T is P.
for ∀p ∈ P,ifp is a control place , obviously t is firable. If p is a variable place , the expression of arc (p ′ , t ′ ) in C contains variable guard of t as the logical conditions of arc expression. And the arc expression (p ′ , t ′ ) can be evaluated correctly , therefore p's variable guard can hold TRUE, i.e., in rwPNs t can fire, because b is the postset of t, accordingly b is reachable. Theory 6.3. Let M ′ 1 is a marking of C and M 1 is a marking of R.i fM ′ 1 is reachable, then M 1 is also reachable, and there is a occurrence sequence Proof: According to theorem 6.2, the theorem holds.
Theory 6.4. if C is live, then R is also live.
Proof: because C is live, therefore for any transition in C can fire and any marking of C can be reachable. Accordingly to 6.2 and 6.3, the theorem can be proved. Theory 6.5. Let M ′ is the marking of C . R is bounded iff there exists a natural number bound n so that for every reachable marking M ′ ≤ n.
Proof: 1. If M ′ ≤ n. ∀p ′ ∈ M ′ ,ifp ∈ R is a control place , obviously the number of tokens in p is same as the number of tokens in p ′ .i fp is a variable place , then based on the definition of variable place in rwPNs , the number of tokens in a variable place always is 1. ∀p ≤ n holds. Therefore R is bounded. 2. If R is bounded. ∀p ∈ R,ifp is a variable place , then the number in p is 1. If p is a control place , because R is bounded, therefore there exists a natural number bound n and p ≤ n holds. Because the mapping rules don't change the number of tokens in a place, therefore ∀p ′ ∈ C , the number in p ′ is same as the number in p. Accordingly, there exists a natural number bound n and p ′ ≤ n. Therefore M ′ ≤ n holds.

Example
In this section, we formalize several programs to illustrate rwPNs usage.

Min
A function, foo, computes the value of 5 * min(x, y) with parameters, x and y. Suppose the code is such as int foo(int x,int y) { int z; if x<y z: =x ; else z:=y; z:=5 * z; return z; } Obviously foo contains three variables, x,y and z. Let , variable x and variable y are read. Therefore, in L (t if ), variables z is written,and variable y is read. Consequently, transition t if concerns three variables , x(read),y(read) and z(written). The specification can be represented as that in Figure 24. Similarly, Transition t else can be described in figure 25.  Statements in if-else are mutual exclusive, i.e. statement 1 and statement 2 are mutual exclusive. To guarantee the mutual exclusion, one control place is applied. Let C i f else is the control place ( Figure 26). When C i f else has one token , there is only one is TRUEbetween After t if fires and the token is consumed, then C i f else loses the token . And then G c (t if ) changes to FALSE. Generally, G c (t if ) will be TRUEor FALSEalternatively on whether C i f else has enough tokens.
In statement z := 5 * z, z appears in both sides of the assignment that means z will be both read and written. Moreover, statement z = 5 * z only executes after statement if-else finishes, i.e. t min follows both t if and t else . Let control place C determine the consecutive order. Then the program specification can be represented as that in figure 27. t min will execute when C has one token , therefore the variable guard of t min is not necessary. Of course, any GUARD can be added if need.
In rwPNs , if all Variable places,Read Arcs and Write Arcs are omitted, the cvNets of program can abstracted as figure 28. In fact, that in figure 28 is a P/T nets and the analysis techniques of Petri nets can be applied . Obviously cvNets describes the Control Flow framework of program.  Informally, when an engineer starts to design a program, he can push Control Flow ( cvNets ) aside first, and only focus on data flow( dvNets ), i.e., entity relations. When a computing machine has be chosen to implement the program, the Control Flow ( cvNets ) can be integrated at later. Accordingly, the final model of program just is composed of cvNets and dvNets .
Control place set: S p = φ ; Variable control set: (Variable) Transition set: Control flow set: F = φ ; Read relation (R) and write relation (W): C is the type set of x i ; I, the specification of transition t i : for ∀t i T: , v i ; This statement denotes that v i exchanges the value with v i+1 ; The semantics of marking varying is: In figure 30, transitions firing may reduce the number of descending arrays of M(v i )(1 ≤ i ≤ n). When marking satisfies ∀v i S v ∧ i = n : M(v i ) ≤ M(v i+1 ), then ∀t i T : B(t i )= false∧ E(t i )=true, and the sort arrives at the fixpoint, the sort accomplishes the purpose.

Fig. 30. SORT Specification
In figure 30, there is no sequential relation among t 1 , t 2 , ··· , t n−1 , that is to say, transitions can fire concurrently. The semantics of sort in figure 30 is: Transition t i is to compare the current value of v i (M(v i )=x k ) and that of v i+1 (M(v i1 )=x j ). If the current value of v i is bigger than that of v i+1 , then v i exchanges the current value with v i+1 ; and then the guard of transition t i (E(t i ) and B(t i )) holds false. When every transition guard holds false, the sort arrives at the fixpoint and terminates.
The specification in figure 30 has not any resources restriction and n transitions can fire concurrently. If resources are restricted, e.g., only one control handle, the new specification is described as in figure 31. Where, additional sets, Control place set: S p = {s i |1 ≤ i < n}; Control transition set: Control flow set:

Fig. 31. Constraint SORT Specification
In figure 31, t i can fire only if s i , which is the preset of t i , has at least one token. After t i fires, the token in s i is consumed and a new token flows into s i+1 , which is the postset of t i . Because of the nondeterminacy, the firing possibility of g i is the same as that of t i . If there are not g i , when v i v i+1 , t i cant fire and the sort terminates though t j > t j+1 (j > i). While transitions is fired continually, the token flows along place s 1 , s 2 , ··· , s n−1 , and s 1 . In fact, the specification in figure 31 is bubble sort . Similarly, if other resources are restrained, many different sorts can be designed based on the specification in figure 30.

Dining philosophy
In this section, DPP(Dining philosophy problem) is treated as a program .  eating, the philosopher returns the borrowed fork and frees his own fork for being lent, and then he starts to think. We suppose it is fair to use forks and there isn't any priority. In addition, a premise is that a philosopher doesn't free his holding fork(s) until he finishes his eating. Obviously, forks are the shared resources. To guarantee each philosopher can eat, each dining philosopher must finish his eating in a while and free his holding forks. Therefore, no philosopher can eat or be hungry forever.
Let PHIL be the type philosophers belong to, P i ∈ PHIL denotes the ith philosopher. Variable place P i .state records the current state of philosopher, i.e. thinking, hungry or eating. Concisely, P i .state = thinking, P i .state = hungry and P i .state = eating are abbreviated as P i .thinking, P i .hungry and P i .eating respectively, here the data type of thinking, hungry and eating are Boolean. Let FORK be the type forks belong to, f i ∈ FORK denotes the fork owned by the ith philosopher. Variable transitions T i , H i and E i denote operations that make philosopher P i to think, be hungry and eat respectively (see Fig.33). T i , H i and E i all can modify the current value of P i .state. In figure 33, Control guard locates at top level and its initial value is false. Control guard is false denotes that the fire condition of transition can't be satisfied, so the transition can't fire. When the fire condition of transition is satisfied, control guard is true and the transition is enabled. Control guard is just the first control of transition's firing. Variable guard locates at the middle level and it represents the condition that the associated variables must satisfy. Similar to Control guard, when variable guard is true, the transition is enabled. Variable guard is the second control of transition's firing. The transition fires only when both control guard and variable guard are true. Variable guard is fixed once it is assigned, but control guard can alternate between true and false. Action description locates at bottom level and it is a collection of assignments. For example, the semantics of T i is: when control f low arrives at T i (control guard is true) and P i is eating (variable guard is true), P i changes its state (eating) and starts thinking. Meanwhile P i sets the current state to thinking. The semantics of E i and H i are similar to T i 's. In figure 34, the initial marking of P i is: M 0 ( f i )=1, M 0 (St i )=1 and P i .state = thinking, i.e. the initial state of P i is thinking and the next enable transition is H i . When H i fires, P i is in the state of hungriness and requests two forks to eat, i.e. the weight of arc (H i , Sa i ) is 2. When M( f i )=1 and M(Sa i ) ≥ 1, Lf i fires. Consequently, fork f i is held by P i . Similarly, When M( f i−1 )=1 and M(Sa i ) ≥ 1, Rf i fires. Consequently, fork f i−1 is held by P i .I fFf i has two tokens, i.e. M(Ff i )=2, E i fires and P i starts to eat with two forks. Marking M(Sf i )=1 denotes P i is eating. T i 's firing denotes P i finishes eating and start to think, at the same time, P i frees forks f i and f i−1 (P 1 uses f 1 and f 5 ), i.e. M( f i )=1 and M( f i−1 )=1. In Fig.34 and other figures, arc with arrow denotes control f low and arc without arrow denotes read/write relationship. Control place set: S p = {St i , Sh i , Sf i , f i , Sa i , Ff i |i = 1, 2, 3, 4, 5}.
In figure.35, non-neighboring philosophers hasn't the shared resource (fork), so they can be concurrent, such as P 1 and P 3 (P 4 ), P 2 and P 4 (P 5 ), P 3 and P 5 (P 1 ). These properties can be The hungry philosopher has opportunity to eat. The dining philosopher must finish his eating in a while and start to think.
These properties ensure each philosopher is in one of three states by turn, i.e. any philosopher can't be in one of states forever. Therefore, the individual philosopher could be live. Similarly, P i .hungriness ensures P i .eating and P i .eating ensures P i .thinking hold true.
The neighboring philosophers can't eat at the same time.
Proof: Similar to property 1, property 2 can be rewritten as Suppose P i is in the state of eating, the firing condition of E i is

M(Ff i )=2
At that time, tokens in Sf i and Sf j must respectively be consumed, i.e.

M(Sf i )=0 M(Sf j )=0
Similarly, P j is in state of eating, the firing condition of E j is M(Ff j )=2  Fig. 37. The process segment of P i 's eating Moreover, there also is occurrence sequence: Therefore, property 4 holds true.

Proof of liveness
T is a set of transitions, M is a set of system markings. Let r = {(m, m ′ )|m, m ′ ∈ M ∧ t ∈ T : m[t > m ′ }, then r * = r 0 ∪ r 1 ∪ r 2 ∪···= ∞ i=0 r i is called as reachable relation, expression mr * m ′ denotes that marking m can be changed to marking m ′ after finite transitions fire.
If m ∈ M, t ∈ T, m ′ ∈ M : mr * m ′ ∧ m ′ [t >, then the system is live.
If the system is live, and m, m ′ ∈ M : mr * m ′ , then the system is circular.
From the above definition, we can prove the liveness of the dining problem.

Proof:
The state of each philosopher changes in turn: thinking → hungry → eating → thinking ··· The state change of philosopher P i is controlled by a flow (directed circle): δ i = ···T i H i E i T i ···, The two neighbor philosophers must share one fork. P i requests the fork is controlled by (directed circle) The right fork: ε r i = f i E i Sf i T i f i The left fork: ε l i = f i+1 E i Sf i T i f i+1 The current book is a combination of number of great ideas, applications, case studies, and practical systems in the domain of Semantics. The book has been divided into two volumes. The current one is the second volume which highlights the state-of-the-art application areas in the domain of Semantics. This volume has been divided into four sections and ten chapters. The sections include: 1) Software Engineering, 2) Applications: Semantic Cache, E-Health, Sport Video Browsing, and Power Grids, 3) Visualization, and 4) Natural Language Disambiguation. Authors across the World have contributed to debate on state-of-the-art systems, theories, models, applications areas, case studies in the domain of Semantics. Furthermore, authors have proposed new approaches to solve real life problems ranging from e-Health to power grids, video browsing to program semantics, semantic cache systems to natural language disambiguation, and public debate to software engineering.