• Aucun résultat trouvé

Static Sematics

Dans le document Symbolic model-checking with Set Rewriting (Page 66-70)

transition1()=Identity

transition2()= Try(Fail);transition3= Sequence(Identity,Fail)

5.2 Static Sematics

The syntax that we defined in Section5.1.1allows to describe some set rewrite systems that are not semantically correct. This is because the language to describe the syntax is not expressive enough to describe all the constraints we would like our system to respect. Thus we add some further constraints to guarantee that the described system can safely be translated.

Some examples of the constraints we add in this section are that the strategies must be used with the right number of parameters they were defined with. We would also like to impose some restrictions on the rewrite rules supported by our system, e.g., linearity. The static semantics helps us to describe these constraints.

To describe the static semantics we proceed as follows. First we define a set of auxiliary operations that work on the syntactic sets. Then we define the rules of the static semantics.

5.2.1 Auxiliary Operations

We define the functionFVthat returns the free variables in the strategies of our system as follows

FV :Strat → P(V)

:basicStrat 7→ ∅

:id() 7→ ∅

:id(strat,listStrat) 7→FV(strat)∪FV(id(listStrat))

This function inductively traverses the abstract syntax tree of our expression and collects the variables it encounters. Please note that this function is only applied to strategies of the setStrat, not to the set of declarations and transitions. In this con-text, all the variables collected arefree variables. An example is presented in Exam-ple5.2.1.

Example 5.2.1 We present an example of the application of the FV function.

FV(Choice(S,Identity))={S}

FV(IfThenElse(S,Q,Q))={S,Q}

48 Chapter 5. Set rewriting We also define the functionDV that returns the defined variables of a declaration as follows:

DV :Dec → P(V)

:id()= strat 7→ ∅

:id(S,vars)=strat 7→ {S} ∪DV(id(vars))

:d;d0 7→ DV(d)∪DV(d0)

:trans;trans0 7→ DV(trans)∪DV(trans0)

This function is applied to declarations and transitions alike and traverses specifi-cally the set definitions of the functions. Whereas the aforementioned function collects the variables used in a strategy, this function collects the variables in the definition.

We present an example of its application in Example5.2.2.

Example 5.2.2 We present an example of the application of the DV function.

DV(Try(S)=Choice(S,Identity))={S} DV(myStrat(S,Q,T)=IfThenElse(S,Q,R))={S,Q,T}

DV(myStrat1(S,Q)=IfThenElse(S,Q,R))={S,Q}

We define the following predicated `id(listVars)= stratas follows:

1. (id(listVars)= strat;d)`id(listVars)= strat 2. (id0(listVars0)=strat0;d)` id(listVars)=strat

d` id(listVar)= strat , ifid ,id0

The predicate takes declarations is used to get the definition of a strategy from the declarations. d ` id(listVars)= strat is true only if strategyid is defined ind. It is defined recursively. The first rule states that if a strategy declaration is at the first position of a sequence of strategy declarations, and the exact same declaration is on the right hand side of the turnstile (`) operator, then the predicate is true. The second rule states that if the first declaration of the sequence and the declaration on the right hand side of the turnstile are not exactly the same, then we try to determine the result of the predicate from the tail of the sequence of declarations. In the end, this predicate is true is the strategy declaration on the right hand side of the turnstile is declared in the sequence of declarations on the left side. The predicate can also be applied to transitions. We present an example of its application in Example5.2.3.

Example 5.2.3 We present some examples of the predicate.

Try(S)=Choice(S,Identity);· `Try(S)= Choice(S,Identity) =true Try(S)=Choice(S,Identity);· `MyTry(S)=Choice(S,Identity) =false

myStrat1(S)=Identity;

myStrat2(S)=Fail;· `myStrat2(S)=Fail =true

5.2. Static Sematics 49 In the same way that we defined the free variables for strategies we define them for terms. For terms we define a function that returns the multi-set (cf. Def. 3.1.4) of variables used in a term, theTV function. TheTV function is formally defined as follows:

TV :TΣ,X → M(X)

:constant 7→ ∅

:x 7→ 10x , ifx∈X

: f(t1, . . . ,tn) 7→ [

i∈{1,...,n}

TV(ti)

The TV function recursively traverses the terms and collects each appearance of the variable in a multi-set. We use a multi-set instead of a simple set because we want to know the cardinality of each variable. In Example5.2.4we show how theTV function works.

Example 5.2.4 We present some applications of the TV function:

TV(plus($x,$x))= 20$x

TV(times($x,plus($y,$z)))= $x++$y++$z

We also define the equivalence of two strategies. The formal definition is given in Def. 5.2.1. This notion is useful to compare a declared strategy with a strategy.

Intuitively, a strategy is equivalent to a declared strategy if the body of the declared strategy is equal to the strategy.

Definition 5.2.1 Given a sequence of declarations d. Two strategies strat and strat0 are equivalent, we note strat ≡ strat0, if and only if one of the following conditions is true

1. strat =strat0

2. If we have d ` id(listVars)=strat, and strat0 ≡ strat, then id(listVars)≡strat0 In Example5.2.5we propose some examples of equivalent strategies. Please note that the notion of equivalence is sensible to redirections, i.e., if a declared strategy

“points” to another, the equivalence takes this into account.

Example 5.2.5 We present some strategies that are equivalent. We assume that the strategy myId = Identity, and myId2 = myId is defined in the sequence of declara-tions.

Identity≡ myId Identity≡ myId2

myId≡ myId2

50 Chapter 5. Set rewriting

5.2.2 Rules

The following rules are constraints that all the expressions in our language need to respect. The rules state certain natural constraints of system that cannot be expressed in the syntax. For a system to be valid we require that all the equations of the static semantics are true.

A set rewriting system has to respect the following static rules:

Id∩V =∅ (5.1)

FV(strat)⊆DV(id(. . .)=strat) (5.2) d;d0 =⇒ ((d `id(listVars)= strat∧d0 `id0(listVars0)= strat0) =⇒ id,id0)

(5.3) t{t0 =⇒ ∀x∈X : (cardTV(t)(x)≤1∧cardTV(t0)(x)≤1) (5.4)

t{t0 =⇒ ∀x∈X : cardTV(t)(x)≥cardTV(t0)(x) (5.5)

Not(S) =⇒ S is equivalent to a Basic Strategy (5.6) Equation (5.1) states that variables and identifiers cannot share the same name.

This constraints helps to make the difference between the strategy variables and de-clared strategies that have no parameters. We present an example of its application in Example5.2.6.

Example 5.2.6 A system where we define the strategy M(S) = Choice(S,Identity may not define another strategy myStrat(M)= Union(M,Identity).

Equation (5.2) formalizes that the set of variables declared in a parametric strategy is the set used in the function, i.e.,one cannot use a variable that was not previously declared. However, one is not forced to use all variable that were declared. The idea of the operation is that the set of declared variables (in the parameters) is equals to the set of free variables in the strategy. We illustrate the application of the equation in Example5.2.7.

Example 5.2.7 We present some strategies and tell if the strategies respect Equa-tion(5.2).

Identity1=Union(S,Identity) (5.7)

Try2(S,Q)= Choice(S,Q) (5.8)

In Strategy Declaration5.7the rule is not valid. Indeed we have that{S}( ∅.

In Strategy Declaration5.8the rule is valid. Indeed we have{S} ⊆ {S,Q}.

Equation (5.3) specifies the constraint that one cannot define a strategy twice. It uses the predicate presented in the previous section. The idea is that given two se-quences of declarations, if the predicate is true the two sese-quences, then the strategies defined on both sequences must be different.

Their next static rules concern rewrite rules. The Rule (5.4) states a property of rewrite rules called non-linearity. The rule expresses that, a variable may not appear more than once in any side of the rule.

5.3. Dynamic Semantics 51

Dans le document Symbolic model-checking with Set Rewriting (Page 66-70)