• Ingen resultater fundet

The type rules are given in Figure 5. The type system defines the following judgments:

i: [1, L]∈Γ Fig. 5.Type system for the generalized process calculus

– Γ `ι: [1, L], which means thatιhas type[1, L]in the type environmentΓ; – Γ `MG,Γ `PG, which mean thatMG,PG, respectively, are well-typed in

the type environmentΓ.

– i1: [1, L1], . . . , ih : [1, Lh]`patG Γ, which means that the patternpatG has free indicesi1, . . . , ih of types [1, L1], . . . ,[1, Lh] respectively, and binds the variables inΓ.

Most type rules are straightforward. For instance, the rule (Var) means that xi1,...,ih is well-typed when the types expected by x for its indices match the types of i1, . . . , ih. The rules (PatVar), (PatData), and (PatList) deal with the patterns xi1,...,ih, f(patG1, . . . ,patGn), and list(i ≤ L,patG), respectively. They build the type environment that gives types to the variables bound in the pattern.

B Proofs

We writeP ≡α Qwhen the process P is equal toQ up to renaming of bound names: in an instrumented process(νa:a0[x1, . . . , xn, s1, . . . , sn0])P, the namea can be renamed, but the function symbola0 remains unchanged. This is why we may end up with instrumented processes in which the name ais different from the function symbol a0.

B.1 Proof of Lemma 1

Lemma 1 is an immediate consequence of the following lemma.

Lemma 2. LetΓ `PG be a well-typed generalized process, such that the bound names of PG are pairwise distinct and distinct from free names of PG. Given an environment T forΓ `PG, and a list of indicesei≤L, we have:e

Tren(PG, T,ei≤L)e ≡αPGT. Furthermore, we have the following two properties:

P1. The bound names in Tren(PG, T,ei ≤L)e are pairwise distinct and distinct from free names, except that in processesP+Q, the bound names inP need not be distinct from those inQ.

P2. All bound names inTren(PG, T,ei≤L)e are of the formaLeT,...

eiT,... when they come from(νa)inPG and of the formaLT,eLT,...

v,eiT,... when they come from(for alli≤ L, νai)inPG.

Proof. The propertyTren(PG, T,ei≤L)e ≡αPGT is proved by an easy induction on the syntax ofPG.

Properties P1 and P2 are proved by simultaneous induction on the syntax of PG.

– CaseΠi≤LPG: for eachv≤LT, by induction hypothesis, the bound names in Tren(PG, T[i 7→ v],(ei, i) ≤(L, L))e are pairwise distinct (except that in processes P +Q, the bound names in P need not be distinct from those in Q) and distinct from free names. Furthermore, they are of the form aLeT,LT,...

eiT,v,... when they come from (νa) in PG and of the form aL0T,eLT,LT,...

v0,eiT,v,...

when they come from(for alli0 ≤L0, νai0)in PG, so P2 holds. Hence the names Tren(PG, T[i 7→ v],(ei, i) ≤ (eL, L)) are distinct from the names in Tren(PG, T[i7→v0],(ei, i)≤(eL, L))whenv6=v0, so P1 holds.

– Case (for alli ≤ L, νai)PG: by induction hypothesis, the bound names in Tren(PG, T,ei≤L)e are pairwise distinct (except that in processesP+Q, the bound names inPneed not be distinct from those inQ) and distinct from free names. Furthermore, they are of the forma0LeT,...

eiT,... when they come from(νa0) in PG and of the form a0LT,eLT,...

v,eiT,... when they come from(for alli ≤L, νa0i) inPG. The new bound namesaLT,eLT

v,eiT forv≤LT are of the required form, so P2 holds. They are distinct from the free names and from the bound names ofTren(PG, T,ei ≤L), since the bound names ine (for alli ≤L, νai)PG are pairwise distinct and distinct from free names, so they do not use the same symbola. So P1 holds.

– The case(νa)PG is similar to the previous one. All other cases follow easily using the induction hypothesis. We use the property that the bound names ofPG are pairwise distinct and distinct from free names ofPG. In the cases

“choose”, we also use that in processesP+Q, the bound names inP need not be distinct from those inQ, so the induction hypothesis already guarantees

that names are distinct when desired.

B.2 Proof of Theorem 3

Theorem 3 comes from the combination of two different results. The first result (Lemma 4) shows that the translation from generalized processes to processes commutes with the instrumentation (provided the translation is suitably re-named usingTren). The second result (Lemma 10) shows the soundness of the translation from instrumented processes to generalized Horn clauses.

Instrumentation Before proving the first result, we define the instrumentation of processes and generalized processes more formally by induction on the syntax of the processes, as follows.

Definition 5 Given a process P, a list of variables Vars =x1, . . . , xn, and a list of session identifiersSessId=s1, . . . , sn0, we define the instrumented process as follows:

– instr(in(M, x).P,Vars,SessId) =in(M, x).instr(P,(Vars, x),SessId);

– instr(!P,Vars,SessId) = !sinstr(P,Vars,(SessId, s));

– instr((νa)P,Vars,SessId) = (νa:a[Vars,SessId])instr(P,Vars,SessId);

– In all other cases, the same instrumentation is applied recursively on the sub-processes. For instance,instr(P |Q,Vars,SessId) = instr(P,Vars,SessId)| instr(Q,Vars,SessId).

We letinstr(P) = instr(P,∅,∅).

Definition 6 Given a generalized processPG, a list of variablesVars=x1, . . . , xn, a list of session identifiersSessId =s1, . . . , sn0, and a list of indicesei≤L,e we define the instrumented generalized process as follows:

– instrG(in(MG, x).PG,Vars,SessId,ei≤L) =e in(MG, x).instrG(PG,(Vars, x),SessId,ei≤L);e

– instrG(!PG,Vars,SessId,ei≤L) = !e sinstrG(PG,Vars,(SessId, s),ei≤L);e – instrGi≤LPG,Vars,SessId,ei≤L) =e

Πi≤LinstrG(PG,Vars,SessId,(ei, i≤L, L));e – instrG((for alli≤L, νai)PG,Vars,SessId,ei≤L) =e

(for alli≤L, νai:aL,eL

i,ei [Vars,SessId])instrG(P,Vars,SessId,ei≤L);e – instrG((νa)PG,Vars,SessId,ei≤L) =e

(νa:aLe

ei[Vars,SessId])instrG(PG,Vars,SessId,ei≤L);e

– In all other cases, the same instrumentation is applied recursively on the sub-processes. For instance,instrG(PG | QG,Vars,SessId,ei≤L) = instre G(PG, Vars,SessId,ei≤L)e |instrG(QG,Vars,SessId,ei≤L).e

We letinstrG(PG) = instrG(PG,∅,∅,∅ ≤ ∅).

The translationPGT on instrumented processes is defined similarly to the translation on non-instrumented processes; the cases that differ are as follows:

– (!sPG)T = !sPGT – ((νa : a0Le

ei[x1, . . . , xn, s1, . . . , sn0])PG)T = (νa : a0LeT

eiT [x1, . . . , xn, s1, . . . , sn0])PGT

– ((for alli ≤L, νai : a0L,eL

i,ei [x1, . . . , xn, s1, . . . , sn0])PG)T = (νa1 :a0LT,eLT

1,eiT [x1, . . . , xn, s1, . . . , sn0]). . .(νaLT :a0LT,eLT

LT,eiT [x1, . . . , xn, s1, . . . , sn0])PGT

Lemma 3. Given a well-typed generalized processΓ `PG, an environment T for Γ ` PG, a list of variables Vars = x1, . . . xn, a list of session identifiers SessId =s1, . . . , sn0, and a list of indicesei≤L, we have:e

(instrG(PG,Vars,SessId,ei≤L))e Tαinstr(Tren(PG, T,ei≤L),e Vars,SessId). Proof. This proof is done by structural induction on the processPG. We detail here the most interesting cases.

– Casein(MG, x).PG:

(instrG(in(MG, x).PG,Vars,SessId,ei≤L))e T

= (in(MG, x).instrG(PG,(Vars, x),SessId,ei≤L))e T

=in(MGT, x).(instrG(PG,(Vars, x),SessId,ei≤L))e T

αin(MGT, x).instr(Tren(PG, T,ei≤L),e (Vars, x),SessId) by induction hypothesis

αinstr(in(MGT, x).Tren(PG, T,ei≤L),e Vars,SessId)

αinstr(Tren(in(MG, x).PG, T,ei≤L),e Vars,SessId) – Case!PG:

(instrG(!PG,Vars,SessId,ei≤L))e T

= (!sinstrG(PG,Vars,(SessId, s),ei≤L))e T

= !s(instrG(PG,Vars,(SessId, s),ei≤L))e T

α!sinstr(Tren(PG, T,ei≤L),e Vars,(SessId, s))

by induction hypothesis

αinstr(!Tren(PG, T,ei≤L),e Vars,SessId)

αinstr(Tren(!PG, T,ei≤L),e Vars,SessId) – CaseΠi≤LPG:

(instrGi≤LPG,Vars,SessId,ei≤L))e T

i≤L(instrG(PG,Vars,SessId,(ei, i)≤(eL, L)))T

= (instrG(PG,Vars,SessId,(ei, i)≤(eL, L)))T[i7→1] | · · · | (instrG(PG,Vars,SessId,(ei, i)≤(eL, L)))T[i7→LT] For eachv≤LT, we have by induction hypothesis:

instrG(PG,Vars,SessId,(ei, i)≤(L, L))e T[i7→v]α

instr(Tren(PG, T[i7→v],(ei, i)≤(L, L)),e Vars,SessId).

Hence:

(instrGi≤LPG,Vars,SessId,ei≤L))e T

αinstr(Tren(PG, T[i7→1],(ei, i)≤(L, L)),e Vars,SessId)| · · · | instr(Tren(PG, T[i7→LT],(ei, i)≤(eL, L)),Vars,SessId)

αinstr(Tren(PG, T[i7→1],(ei, i)≤(L, L))e | · · · |

Tren(PG, T[i7→LT],(ei, i)≤(eL, L)),Vars,SessId)

αinstr(Tren(Πi≤LPG, T,ei≤L),e Vars,SessId)

– Case(for alli≤L, νai)PG:

(instrG((for alli≤L, νai)PG,Vars,SessId,ei≤L))e T

= ((for alli≤L, νai :aL,eL

i,ei [Vars,SessId]) instrG(PG,Vars,SessId,ei≤L))e T

= (νa1:aLT,eLT

1,eiT [Vars,SessId]). . .(νaLT :aLT,eLT

LT,eiT [Vars,SessId]) (instrG(PG,Vars,SessId,ei≤L))e T

Moreover, by induction hypothesis, (instrG(PG,Vars,SessId,ei ≤L))e Tα instr(Tren(PG, T,ei≤L),e Vars,SessId). Therefore,

(instrG((for alli≤L, νai)PG,Vars,SessId,ei≤L))e T

α(νa1:aLT,eLT

1,eiT [Vars,SessId]). . .(νaLT :aLT,eLT

LT,eiT [Vars,SessId]) instr(Tren(PG, T,ei≤L),e Vars,SessId)

α(νaLT,eLT

1,eiT :aLT,eLT

1,eiT [Vars,SessId]). . .(νaLT,eLT

LT,eiT :aLT,eLT

LT,eiT [Vars,SessId]) (instr(Tren(PG, T,ei≤L),e Vars,SessId){aLT,eLT

1,eiT /a1, . . . , aLT,eLT

1,eiT /aLT}) by renaming bound names

αinstr((νaLT,eLT

1,eiT ). . .(νaLT,eLT

LT,eiT )Tren(PG, T,ei≤L){ae LT,eLT

1,eiT /a1, . . . , aLT,eLT

1,eiT /aLT},Vars,SessId)

αinstr(Tren((for alli≤L, νai)PG, T,ei≤L),e Vars,SessId)

– The case (νa)PG can be handled similarly to the previous case. All other cases follow easily from the induction hypothesis.

Lemma 4. Given a well-typed generalized process Γ0`P0G, we have:

(instrG(P0G))T0αinstr(Tren(P0G, T0,∅ ≤ ∅)).

Proof. This result comes immediately from Lemma 3 applied to instrG(P0G) =

instrG(P0G,∅,∅,∅ ≤ ∅).

Translation from Instrumented Processes to Clauses We use the follow-ing standard result.

Lemma 5. LetE1,E2be two sets of equations over standard clause terms. Then mgu(E1∪ E2)is defined if and only ifmgu(mgu(E2)E1)mgu(E2)is defined, and mgu(E1∪ E2) =mgu(mgu(E2)E1)mgu(E2).

Lemma 6. Let P be an instrumented process, ρ a function that associates a clause term with each name and variable, and H a sequence of facts. Given a substitution σover the variables inρ, we have that:

[[P]](σρ)(σH)v[[P]]ρH .

Proof. The proof of this lemma is done by structural induction on the process P. We detail here the most interesting cases.

– CaseM(x).P:

[[M(x).P]](σρ)(σH)

= [[P]]((σρ)[x7→x])(σH∧message(σρ(M), x))

= [[P]](σ0(ρ[x7→x]))(σ0(H∧message(ρ(M), x)))

where we define the substitutionσ0=σ[x7→x]

v[[P]](ρ[x7→x])(H∧message(ρ(M), x)) by induction hypothesis v[[M(x).P]]ρH

– Caseletx=g(M1, . . . , Mn)inP elseQ:

[[letx=g(M1, . . . , Mn)inP elseQ]](σρ)(σH)

= [[Q]](σρ)(σH)∪[

{[[P]](σ1σρ[x7→σ10p0])(σ1σH)|g(p01, . . . , p0n)→p0 is in def(g)and (σ1, σ01)is a most general pair of substitutions such that σ1σρ(Mi) =σ10p0i,for eachi= 1, . . . n}

By induction hypothesis, we have [[Q]](σρ)(σH) v [[Q]]ρH. Let g(p01, . . . , p0n) → p0 be a rule in def(g), and (σ1, σ10) be a most general pair of sub-stitutions such that σ1σρ(Mi) = σ10p0i, for each i = 1, . . . n. Let σ2 = σ1σ and σ20 = σ10. For each i = 1, . . . , n, we have σ2ρ(Mi) = σ20p0i. Let (σ3, σ30) be a most general pair of substitutions such that for each i = 1, . . . , n:

σ3ρ(Mi) =σ03p0i. As (σ2, σ02) is such a pair (but maybe not a most general one), there exists a substitution σ4 such that σ2 = σ4σ3 and σ02 = σ4σ30. Hence we have that

[[P]](σ1σρ[x7→σ10p0])(σ1σH)

= [[P]](σ4σ3ρ[x7→σ4σ03p0])(σ4σ3σH)

= [[P]](σ43ρ[x7→σ30p0]))(σ43σH)) v[[P]](σ3ρ[x7→σ30p0])(σ3σH)

by induction hypothesis. Therefore,

[[letx=g(M1, . . . , Mn)in P elseQ]](σρ)(σH) v[[Q]]ρH∪[

{[[P]](σ3ρ[x7→σ30p0])(σ3σH)|g(p01, . . . , p0n)→p0 is indef(g)and(σ3, σ30)is a most general pair of substitutions such thatσ3ρ(Mi) =σ03p0i,for eachi= 1, . . . n}

v[[letx=g(M1, . . . , Mn)in P elseQ]]ρH.

– The other cases are straightforward using the induction hypothesis.

Lemma 7. We have

[[letE1 in . . . letEl in P elseQ . . . elseQ]]ρH

v[[Q]]ρH∪[[P]](mgu(E)(ρ[x17→p01, . . . , xl7→p0l]))(mgu(E)H) where

– for eachi≤l,Ei isxi=gi(Mi,1, . . . , Mi,ni);

– for eachi ≤l, xi does not occur in Q nor in Mk,j for all k= 1, . . . , l and j= 1, . . . , nk;

– for each i ≤ l, gi(p0i,1, . . . , p0i,n

i) → p00i is the rewriting rule of gi and pi,1, . . . , pi,ni, p0i are obtained by renamingp0i,1, . . . , p0i,ni, p00i with fresh vari-ables;

– E={ρ(Mk,j) =pk,j |k= 1, . . . , l andj= 1, . . . , nk}.

When the equations inEcannot be unified,mgu(E)is not defined, and the second component of the union is omitted.

Proof. The proof is done by induction onl.

– Base case:l= 1.

[[letE1in P elseQ]]ρH = [[Q]]ρH∪[[P]](σρ[x17→σp01])(σH)

whereσis a most general substitution such that σρ(M1,j) =σp1,j for each j = 1, . . . , n1, assuming that σ exists. (Finding such a σ is equivalent to finding a most general pair of substitutions (σ0, σ00) such thatσ0ρ(M1,j) = σ00p01,j: we can define σ by σx =σ00α−1x where α is the renaming of p0i,j intopi,jandxis a fresh variable introduced by this renaming, andσx=σ0x otherwise.) Henceσ=mgu(E) whereE ={ρ(M1,j) =p1,j |j = 1, . . . , n1} and we can conclude that

[[letE1 inP elseQ]]ρH= [[Q]]ρH∪[[P]](mgu(E)(ρ[x17→p01]))(mgu(E)H) Whenmgu(E)is not defined, that is,σdoes not exist, the second component of the union is omitted.

– Inductive step. We have

[[letE1 in letE2in . . . letElin P elseQ . . . elseQelseQ]]ρH

= [[Q]]ρH∪[[letE2 in . . . letEl inP elseQ . . . elseQ]]ρ1H1

whereρ1=mgu(E1)(ρ[x17→p01]),H1=mgu(E1)H, and E1={ρ(M1,j) =p1,j |j= 1, . . . , n1}, by the base case v[[Q]]ρH∪[[Q]]ρ1H1

[[P]](mgu(E2)(ρ1[x27→p02, . . . , xl7→p0l]))(mgu(E2)H1)

where E2 = {ρ1(Mk,j) = pk,j | k = 2, . . . , landj = 1, . . . , nk}, by induc-tion hypothesis, assuming thatmgu(E1)andmgu(E2)are defined. We have [[Q]]ρ1H1 = [[Q]](mgu(E1)ρ)(mgu(E1)H) since x1 does not occur in Q, so [[Q]]ρ1H1v[[Q]]ρH by Lemma 6.

LetE20 = {ρ(Mk,j) = pk,j | k = 2, . . . , landj = 1, . . . , nk}. The variables of pk,j (k ≥ 2) are fresh, so they are untouched by mgu(E1), so we have E2=mgu(E1)E20 andE =E1∪ E20, so

mgu(E2)mgu(E1) =mgu(mgu(E1)E20)mgu(E1) =mgu(E1∪ E20) =mgu(E) by Lemma 5. Moreover, the variables of p02, . . . , p0l are fresh, so they are untouched bymgu(E1). Hence

mgu(E2)(ρ1[x27→p02, . . . , xl7→p0l])

=mgu(E2)mgu(E1)(ρ[x17→p01, x27→p02, . . . , xl7→p0l])

=mgu(E)(ρ[x17→p01, . . . , xl7→p0l])

andmgu(E2)H1=mgu(E2)mgu(E1)H =mgu(E)H. Therefore, [[letE1 in letE2in . . . letElin P elseQ . . . elseQelseQ]]ρH

v[[Q]]ρH∪[[P]](mgu(E)(ρ[x17→p01, . . . , xl7→p0l]))(mgu(E)H) As before, when mgu(E) is not defined, that is, mgu(E2)mgu(E1) is not defined, the second component of the union is omitted.

From this lemma, we obtain the following result for the special case of the decomposition of data constructors.

Corollary 3. Let f be a data constructor of arity n and f1−1, . . . , fn−1 be its associated destructors.

[[letx1=f1−1(M)in . . . letxn=fn−1(M)inP elseQ . . . elseQ]]ρH v[[Q]]ρH∪[[P]](mgu(E)(ρ[x17→v1, . . . , xn7→vn]))(mgu(E)H)

wherex1, . . . , xn do not occur inQnor inM, andE={f(v1, . . . , vn) =ρ(M)}.

Whenmgu(E)is not defined, the second component of the union is omitted.

Proof. By Lemma 7, we obtain

[[letx1=f1−1(M)in . . . letxn =fn−1(M)inP elseQ . . . elseQ]]ρH v[[Q]]ρH∪[[P]](mgu(E0)(ρ[x17→v1,1, . . . , xn7→vn,n]))(mgu(E0)H) where E0 = {ρ(M) = f(vk,1, . . . , vk,n) | k = 1, . . . , n} and the variables vk,j

(k= 1, . . . , n,j= 1, . . . , n) are fresh. We have mgu(E0)vk,j =mgu(E0)vk0,j for allk, k0, j, so for allj= 1, . . . , n, we can rename the variablesvk,j for allk into the same variablevj. After this renaming, we obtain the announced result.

Lemma 8. Suppose that the variables ofpat1, . . . ,patn are pairwise distinct and fresh (that is, they do not occur inρ,H,M1, . . . ,Mn, andQ).

[[letpat1=M1 in . . . letpatn=Mn in P elseQ . . . elseQ]]ρH

v[[Q]]ρH∪[[P]](mgu(E)(ρ[x7→x|xoccurs inpat1, . . . ,patn]))(mgu(E)H) whereE ={pati=ρ(Mi)|i= 1, . . . , n}.

Proof. The proof is done by induction on the total size of the patternspat1, . . . , patn.

– Case 1: there is a single patternpat =x.

[[letx=M inP elseQ]]ρH

= [[letx=id(M)in P elseQ]]ρH

= [[Q]]ρH∪[[P]](mgu({ρ(M) =y})(ρ[x7→y]))(mgu({ρ(M) =y})H) wherey is a fresh variable and the rewrite rule for destructor id is renamed intoid(y)→y (see the base case of Lemma 7).

v[[Q]]ρH∪[[P]](mgu({ρ(M) =x})(ρ[x7→x]))(mgu({ρ(M) =x})H) by renamingxinto y sincexand y do not occur in ρ, ρ(M), andH.

– Case 2: there is a single patternpat =f(pat1, . . . ,patn).

[[letf(pat1, . . . ,patn) =M inP elseQ]]ρH

= [[letx1=f1−1(M)in . . . letxn =fn−1(M)in

letpat1=x1in . . . letpatn=xn in P elseQ . . . elseQ elseQ . . . elseQ]]ρH

wherex1, . . . , xn are fresh variables

v[[Q]]ρH∪[[letpat1=x1 in . . . letpatn=xn inP elseQ . . . elseQ]]

(mgu(E)(ρ[x17→v1, . . . , xn7→vn]))(mgu(E)H) whereE={f(v1, . . . , vn) =ρ(M)}, by Corollary 3 v[[Q]]ρH∪[[Q]]ρ0H0

[[P]](mgu(E0)(ρ0[x7→x|xoccurs inpat1, . . . ,patn]))(mgu(E0)H0) where ρ0 =mgu(E)(ρ[x1 7→v1, . . . , xn 7→vn]), H0 =mgu(E)H, andE0 = {pat10(x1), . . . ,patn0(xn)}, by induction hypothesis (since the total size ofpat1, . . . ,patn is less than the size off(pat1, . . . ,patn)).

Asx1, . . . , xn do not appear inQ,[[Q]]ρ0H0 = [[Q]](mgu(E)ρ)(mgu(E)H)v [[Q]]ρH, by Lemma 6.

We have E0 = {pati = mgu(E)vi | i = 1, . . . , n} = mgu(E){pati = vi | i = 1, . . . , n}, so by Lemma 5, mgu(E0)mgu(E) = mgu({f(v1, . . . , vn) = ρ(M)} ∪ {pati =vi | i= 1, . . . , n}) =mgu({f(pat1, . . . ,patn) =ρ(M)} ∪ {pati = vi | i = 1, . . . , n}). Let E00 = {f(pat1, . . . ,patn) = ρ(M)}. Then

we have mgu(E0)mgu(E) = (mgu(E00))[vi 7→mgu(E00)pati]. Therefore we obtain that:

[[letf(pat1, . . . ,patn) =M inP elseQ]]ρH v[[Q]]ρH

∪[[P]](mgu(E00)(ρ[x7→x|xoccurs inpat1, . . . ,patn]))(mgu(E00)H) since the variablesv1, . . . , vn do not occur inρandH, and the variablesx1, . . . , xn can be removed from the environment since they do not occur inP. – Case 3: there are several patterns.

[[letpat1=M1 in . . . letpatn=Mn inP elseQ . . . elseQ]]ρH

v[[Q]]ρH∪[[letpat2=M2 in . . . letpatn =Mn inP elseQ . . . elseQ]]

(mgu(E1)(ρ[x7→x|xoccurs inpat1]))(mgu(E1)H)

whereE1={pat1=ρ(M1)}, by induction hypothesis applied to pat1 v[[Q]]ρH∪[[Q]]ρ0H0

[[P]](mgu(E2)(ρ0[x7→x|xoccurs inpat2, . . . ,patn]))(mgu(E2)H0) where ρ0 = mgu(E1)(ρ[x 7→ x | xoccurs inpat1]), H0 = mgu(E1)H, and E2={pati0(Mi)|i= 2, . . . , n}, by induction hypothesis applied topat2, . . . ,patn.

Since the variables ofpat1do not occur in the processQ, we have[[Q]]ρ0H0= [[Q]](mgu(E1)ρ)(mgu(E1)H)v[[Q]]ρH by Lemma 6.

Let E20 = {pati = ρ(Mi) | i = 2, . . . , n} and E = {pati = ρ(Mi) | i = 1, . . . , n}. Since the variables ofpati for i≥2 do not occur inE1, we have mgu(E2)mgu(E1) =mgu(mgu(E1)E20)mgu(E1) =mgu(E1∪ E20) =mgu(E) by Lemma 5. So

mgu(E2)(ρ0[x7→x|xoccurs inpat2, . . . ,patn])

=mgu(E2)mgu(E1)(ρ[x7→x|xoccurs inpat1, . . . ,patn])

=mgu(E)(ρ[x7→x|xoccurs inpat1, . . . ,patn]) andmgu(E2)H0=mgu(E2)mgu(E1)H =mgu(E)H. Therefore,

[[letpat1=M1 in . . . letpatn=Mn inP elseQ . . . elseQ]]ρHv[[Q]]ρH

∪[[P]](mgu(E)(ρ[x7→x|xoccurs inpat1, . . . ,patn]))(mgu(E)H) Lemma 9. LetΓP `MG be a well-typed pattern, ρG a function that associates a clause term with each name and variable, possibly with indices, andΓ an envi-ronment for generalized Horn clauses such thatΓP, Γ `ρG. ThenΓ `ρG(MG) Proof. We detail here the three interesting cases.

– Case MG = x

eι. Since ΓP typesx

eι, we have two judgments x_ : Le ∈ ΓP

and ΓP ` eι : L. From the definition ofe ΓP, Γ ` ρG, if {x

ei 7→ pG} ∈ ρG, then Γ,ei : Le ` pG. Moreover, as ΓP ` eι : L, we havee Γ ` eι : L. Hencee ρG(MG) =pG{eι/ei}and Γ `ρG(MG).

– Case MG = a. From the definition of Γ ` ρG, if {a 7→ pG} ∈ ρG, then Γ `pGG(MG).

– CaseMG =aι. SinceΓP typesaι, we have two judgmentsa_ : [1, L]∈ΓP

andΓP `i: [1, L]. From the definition of ΓP, Γ ` ρG, if {ai 7→pG} ∈ρG, then Γ, i : [1, L] ` pG. Moreover, as ΓP ` i : [1, L], we have Γ `i : [1, L].

HenceρG(MG) =pG{ι/i} andΓ `ρG(MG).

We writeT0extT to mean thatT0is an extension of the environmentT. Given a type environment ΓP for processes and a type environmentΓ for generalized Horn clauses, we define{x

ei7→pG}T ={x

ve7→pGT[ei7→ev]|ev≤L}e whenx_ :Le∈ Γ,{a7→pG}T ={a7→pGT}, and{ai7→pG}T ={av7→pGT[i7→v] |v≤L}when a_: [1, L]∈ΓP. We extend this definition naturally toρGT.

Lemma 10. LetΓP `PGbe a well-typed instrumented generalized process,ρGa function that associates a clause term with each name and variable, possibly with indices,HG a sequence of facts,E a set of equations, and Γ is an environment for generalized Horn clauses such that:

– Γ `HG; – Γ ` E;

– ΓP, Γ `ρG. Then

[[PGT]](mgu(ETGT)(mgu(ET)HGT)v [

T0extT

([[PG]]ρGHGEΓ)T0

and the clauses in the right hand side are well-typed.

Proof. The proof is done by structural induction on the process PG. Let ρ = mgu(ETGT and H = mgu(ET)HGT, and let us show that [[PGT]]ρH v S

T0extT([[PG]]ρGHGEΓ)T0. – Caseout(MG, NG).PG:

[[(out(MG, NG).PG)T]]ρH

= [[out(MGT, NGT)i.PGT]]ρH

= [[PGT]]ρH∪ {(mgu(ET)HGT

⇒message(mgu(ETGT(MGT),mgu(ETGT(NGT))}

= [[PGT]]ρH∪({Γ `HG∧ E ⇒message(ρG(MG), ρG(NG))})T

v [

T0extT

([[PG]]ρGHGEΓ)T0∪ [

T0extT

({Γ `HG∧ E ⇒message(ρG(MG), ρG(NG))})T0 by induction hypothesis and using thatT is an extension of itself

v [

T0extT

([[out(MG, NG).PG]]ρGHGEΓ)T0

– Casein(MG, x).PG:

[[(in(MG, x).PG)T]]ρH= [[in(MGT, x).PGT]]ρH

= [[PGT]](ρ[x7→x])(H∧message(ρ(MGT), x)) The right-hand side of the theorem develops in

[

T0extT

([[in(MG, x).PG]]ρGHGEΓ)T0 = [

T0extT

([[PG]]ρG1H1G1)T0

whereρG1G[x7→x],H1G=HG∧message(ρG(MG), x), and Γ1=Γ, x_: [ ]. We show that ρ[x7→x] =mgu(ETGT1 :

mgu(ETGT1 =mgu(ETGT[x7→x] =ρ[x7→x]

andH∧message(ρ(MGT), x) =mgu(ET)H1GT:

mgu(ET)H1GT =mgu(ET)(HG∧message(ρG(MG), x))T

=mgu(ET)HGT ∧mgu(ET)(message(ρGT(MGT), x)

=H∧message(mgu(ETGT(MGT), x)

=H∧message(ρ(MGT), x)

LetΓP0 the environment that types PG, ΓP0P, x_ : [ ]. Before applying the induction hypothesis we need to show thatΓP0, Γ1 ` ρG1 and Γ1 ` H1G (clearly,Γ1 ` E). SinceΓP, Γ `ρG, we have ΓP0, Γ1G. For the new map [x7→x]∈ρG1 we have thatx_: [ ]∈ΓP0 andΓ1`x. HenceΓP0, Γ1G1. Since Γ ` HG, we have Γ1 ` HG. From Lemma 9 we have that Γ ` ρG(MG), as ΓP, Γ ` ρG and ΓP ` MG. Finally Γ1 ` x. Hence Γ1 ` message(ρG(MG), x), and thus Γ1 ` H1G. Therefore, we can apply the in-duction hypothesis and conclude.

– Case0:[[0T]]ρH=∅=S

T0extT([[0]]ρGHGEΓ)T0. – CasePG|QG:

[[(PG|QG)T]]ρH = [[PGT |QGT]]ρH= [[PGT]]ρH∪[[QGT]]ρH

v [

T0extT

([[PG]]ρGHGEΓ)T0∪ [

T0extT

([[QG]]ρGHGEΓ)T0

v [

T0extT

([[PG|QG]]ρGHGEΓ)T0

– Case!sPG:

[[(!sPG)T]]ρh= [[!sPGT]]ρH= [[PGT]](ρ[s7→s])H

v [

T0extT

([[PG]](ρG[s7→s])HGEΓ)T0

v [

T0extT

([[!sPG]]ρGHGEΓ)T0

– CaseΠi≤LP:

[[(Πi≤LP)T]]ρH = [[PGT[i7→1]|. . . |PGT[i7→LT]]]ρH

= [[PGT[i7→1]]]ρH∪ · · · ∪[[PGT[i7→LT]]]ρH

By induction hypothesis,[[PGT[i7→v]]]ρH vS

T0extT[i7→v]([[PG]]ρGHGE(Γ, i : [1, L]))T0 for each v∈ {1, . . . , LT}. Therefore

[[(Πi≤LP)T]]ρHv [

T0extT[i7→1]

([[PG]]ρGHGE(Γ, i: [1, L]))T0∪ · · · ∪

[

T0extT[i7→LT]

([[PG]]ρGHGE(Γ, i: [1, L]))T0

v [

T0extT

([[PG]]ρGHGE(Γ, i: [1, L]))T0

v [

T0extT

([[Πi≤LPG]]ρGHGEΓ)T0

sinceT[i7→v]is an extension ofT for each v∈ {1, . . . , LT}.

– Case(for alli≤L, νai :aL,eL

i,ei [x1, . . . , xn, s1, . . . , sn0])PG: [[((for alli≤L, νai:aL,eL

i,ei [x1, . . . , xn, s1, . . . , sn0])PG)T]]ρH

= [[(νa1:aLT,eLT

1,eiT [x1, . . . , xn, s1, . . . , sn0]). . . (νaLT :aLT,eLT

LT,eiT [x1, . . . , xn, s1, . . . , sn0])PGT]]ρH

= [[PGT]]ρ1H

where

ρ1=ρ[a17→aLT,eLT

1,eiT [ρ(x1), . . . , ρ(xn), ρ(s1), . . . , ρ(sn0)], . . . , aLT 7→aLT,eLT

LT,eiT [ρ(x1), . . . , ρ(xn), ρ(s1), . . . , ρ(sn0)]]. The right-hand side of the theorem develops in

[

T0extT

([[(for alli≤L, νai :aL,eL

i,ei [x1, . . . , xn, s1, . . . , sn0])PG]]ρGHGEΓ)T0

= [

T0extT

([[PG]]ρG1HGEΓ)T0

whereρG1G[ai7→aL,eL ρG1. We can then apply the induction hypothesis and conclude.

– Case(νa)PG: this case is similar to the previous one.

– Case let for allei ≤ L, xe

ei = g(M1G, . . . , MnG)in PG elseQG: let g(p1, . . . , pn)→p0be the rewrite rule for the destructorg. We suppose that the tuples of indicesev ≤LeT are indexed by1, . . . , l, that is, we define {ev1, . . . ,vel} = mgu(E1)does not exist, the second component of the union is omitted, and the rest of the proof can easily be adapted.) The right-hand side of the theorem develops in

rule with fresh variables with indicesei: y0 Let ΓP0 the environment that types PG: by the typing rules we have that ΓP0P, x_ :L. Before applying induction we need to show thate ΓP0, Γ0 `

This means that each equation inE0 is well typed in Γ0; moreover Γ0 ` E becauseΓ0 extends Γ andΓ ` E by hypothesis. ThusΓ0` E ∪ E0.

We can then apply the induction hypothesis, which yields [[PGT]](mgu(αE1)(ρ[x

ev1 7→αp01, . . . , x

vel 7→αp0l]))(mgu(αE1)H)

v [

T0extT

([[PG]](ρG[x

ei7→p0G])HG(E ∪ E00)T0 and[[QGT]]ρHvS

T0extT([[QG]]ρGHGEΓ)T0. Moreover,

[[PGT]](mgu(E1)(ρ[x

ev1 7→p01, . . . , x

evl7→p0l]))(mgu(E1)H) v[[PGT]](mgu(αE1)(ρ[x

ve1 7→αp01, . . . , x

evl7→αp0l]))(mgu(αE1)H) (These two sets of clauses are in fact equal up to renaming of variables, by construction.)

Hence we can conclude that:

[[(let for allei≤L, xe

ei=g(M1G, . . . , MnG)inPG elseQG)T]]ρH v [

T0extT

([[let for allei≤L, xe

ei=g(M1G, . . . , MnG)inPG elseQG]]ρGHGEΓ)T0

– Caselet for allei≤L,e patG =MG inPG elseQG: as in the previous case, we suppose that the tuples of indicesev≤LeT are indexed by1, . . . , l, that is, we define{ev1, . . . ,evl}={e1, . . . ,LeT}.

[[(let for allei≤L,e patG =MG in PG elseQG)T]]ρH

= [[letE1 in . . . letEl inPGT elseQGT . . . elseQGT]]ρH whereEi is the equationpatGT[ei7→evi]=MGT[ei7→evi]. v[[Q]]ρH∪[[P]]ρ0H0

by Lemma 8, where E1 = {patGT00 = ρ(MGT00) | T00 = T[ei 7→ ev],ve ≤ LeT}, ρ0 =mgu(E1)(ρ[x7→ x| xoccurs inpatGT[ei7→ev],ev ≤ LeT]), and H0 = mgu(E1)H, assuming thatmgu(E1)exists. (Whenmgu(E1)does not exist, the second component of the union is omitted, and the rest of the proof can easily be adapted.)

The right-hand side of the theorem develops in:

[

T0extT

([[let for allei≤L,e patG=MG in PG elseQG]]ρGHGEΓ)T0

= [

T0extT

([[Q]]ρGHGEΓ)T0

[[P]](ρG[x

ei0 7→x

ei0 |x

ei0 occurs inpatG])HG(E ∪ E00)T0

whereE0 =V

ei≤LepatG .

G(MG)andΓ0 isΓ extended for the variables oc-curring inpatG. More precisely, if the typing rule for the processlet for allei≤ L,e patG =MG inPG elseQG hasi1 : [1, L1], . . . , ih : [1, Lh] ` patG Γ00 Let ΓP0 the environment that types PG: by the typing rules we have that ΓP0P, ΓP00, whereei:Le `patG ΓP00. Before applying induction we need

– CasechooseL inPG: [[(chooseLin PG)T]]ρH

= [[PGT[L7→1]+· · ·+PGT[L7→n]+· · ·]]ρH

= [[PGT[L7→1]]]ρH∪ · · · ∪[[PGT[L7→n]]]ρH∪ · · ·

v [

T0extT[L7→1]

([[PG]]ρGHGEΓ)T0∪ · · · ∪ [

T0extT[L7→n]

([[PG]]ρGHGEΓ)T0∪ · · ·

v [

T0extT

([[chooseLinPG]]ρGHGT0)

– Casechoosek≤LinPG:

[[(choosek≤LinPG)T]]ρH

= [[PGT[k7→1]+· · ·+PGT[k7→LT]]]ρH

= [[PGT[k7→1]]]ρH∪ · · · ∪[[PGT[k7→LT]]]ρH

v [

T0extT[k7→1]

([[PG]]ρGHGE(Γ, k: [1, L]))T0∪ · · · ∪

[

T0extT[k7→LT]

([[PG]]ρGHGE(Γ, k: [1, L]))T0

v [

T0extT

([[choosek≤L inPG]]ρGHGT0)

– Casechooseφ :L1× · · · ×Lh →L0 in PG: this case is similar to previous

one.

Combining the results From the previous results, we easily obtain Theorem 3.

Proof (of Theorem 3). By Lemma 10, ([[P1G]]ρ0∅∅Γ0)T =S

T([[P1G]]ρ0∅∅Γ0)T w [[P1GT0]]ρ0∅, whereP1G = instrG(P0G). By Lemma 4,instr(P00) = instr(Tren(P0G, T0,∅ ≤ ∅)) ≡α instrG(P0G)T0 = P1GT0, so we have ([[instrG(P0G)]]ρ0∅∅Γ0)T w [[instr(P00)]]ρ0∅since the translation to Horn clauses [[·]]is invariant by renaming of bound names.

Moreover, for each clauseR in{att(a[ ])|a∈S} ∪ {(Rn), (Rf), (Rg), (Rl), (Rs)} except the clauses (Rf) and (Rg) for lists of fixed length, R is also a generalized Horn clause and we have {R}T = {R}. The clauses (Rf) for lists of fixed length are in {RG}T = {att(x1)∧ · · · ∧att(xn) ⇒ att(hx1, . . . , xni) | n∈ N}, where RG =(Rf-list). The clauses (Rg) for lists of fixed length are in {RG}T ={att(hx1, . . . , xni)⇒att(xv)|n∈N, v≤n} whereRG=(Rg-list).

So we obtainRGTPG

0,S w RP00,S.

RELATEREDE DOKUMENTER