• Nem Talált Eredményt

5.3 An Algorithm for Analyzing Implications

5.3.5 The Algorithm IntroduceNewAtoms

In the algorithmCheckImplication, we reference the functionIntroduceNewAtoms that is invoked by passing the list of atoms of the current truth table and the original formulae ϕand ϕ0. Its return value is a new list of atoms that are stored again inAtoms. If the return value is an empty list, then CheckImplicationterminates.

In the informal overview before, we have already presented how the new atoms can be introduced by applying inference rules. The algorithm checks if certain atoms can be substituted into the pa-rameters contained by the premises of an inference rule. If so, it checks if there are atoms in the conclusions that are not yet present in the current list of atoms. For eachaof such found atoms, the logical function ωPhϕ, ϕ0i(a) is called. If this function returns true for each atom, these new atoms will be returned by the algorithm. If for any of these atoms the function above returnsfalse, then the algorithm searches for a new inference rule to introduce atoms.ωPhϕ, ϕ0iis called a limit function, its role will be discussed later. At this point, we only need to know that if new atoms are returned, these atoms must satisfy some limit conditions. The inference rules that are used in this algorithm to introduce new atoms areProposition 5.32andProposition 5.34. It can be seen that we do not use all inference rules to introduce new atoms, this will be discussed in more details later. The pseudocode of the algorithmIntroduceNewAtomsis presented in Algorithm 4.

5. Formalizing Functional Properties of Model Transformations

Algorithm 3CheckImplication(ϕ, ϕ0)

1: Atomsall atoms inϕandϕ0

2: IgnoredRowsempty collection of indices 3: loop

4: T ruthT ablebuild a truth table forAtoms 5: HasP roof F oundfalse

6: HasRef utationF oundfalse 7: forRowIndexinT ruthT able.Rowsdo 8: if RowIndexIgnoredRowsthen 9: continuefor loop with next row 10: // checking inference rules:

11: if any of the implications derived by applying inference rules on atoms ofAtomsis violatedthen 12: addRowIndextoIgnoredRows

13: continuefor loop with next row

14: V aluecompute truth value ofϕin the current row 15: if V alue=falsethen

16: addRowIndextoIgnoredRows

17: continuefor loop (line 7) with next row

18: V alue0compute truth value ofϕ0 in the current row 19: if V alueandV alue0 then

20: HasP roof F oundtrue 21: if V alueandnotV alue0then 22: HasRef utationF oundtrue

23: if HasRef utationF oundandHasP roof F oundthen 24: breakfor loop

25: if HasP roof F oundand notHasRef utationF oundthen 26: return true

27: if HasRef utationF oundand notHasP roof F oundthen 28: return false

29: // introducing new atoms:

30: N ewAtomsIntroduceNewAtoms(Atoms) 31: if N ewAtomshas membersthen

32: addN ewAtomstoAtoms

33: adaptIgnoredRowsto new truth table 34: continueloop

35: else

36: return unknown

To guarantee that the algorithm CheckImplication terminates, we need to show that when the functionIntroduceNewAtomsis invoked again and again, after a while, it will return an empty list of atoms. How can we ensure this property? We introduce the definition oflimit functions. Informally, a limit function is a logical function such that there are only finite number of non-equivalent relation pattern conditions for which the return value istrue. We defineIntroduceNewAtomsin a way that it

Algorithm 4IntroduceNewAtoms(CurrentAtoms, ϕ, ϕ0)

OriginalAtomsall atoms inϕandϕ0

for allinference ruleRin the set of ’inference rules for introducing new atoms’do for allpossible substitution of the premises ofRby elements ofCurrentAtomsdo

Conclusionsatoms in the conclusion ofR N ewAtoms← ∅

for allaConclusionsdo

if @a0CurrentAtoms:Equiv(a, a0) =trueand@a00N ewAtoms:Equiv(a, a00) =truethen addatoN ewAtoms

if ∀aN ewAtoms:ωPhϕ, ϕ0i(a)then return N ewAtoms

return empty list

only returns atoms that satisfy an initially fixed limit function. Therefore, only finite numbers of new atoms can be introduced. The limit function is defined in a general way in order to make it possible to extend out method later with new types of TPDL conditions, because these new conditions may require a new type of limit function.

Definition 5.37 (limit function). The logical function ω :F → {true,false} is a called a limit function, if there are only finite number of non-equivalent formulaeψ such thatω(ψ) =true. 2 Definition 5.38. Let P denote the set of all possible patterns of a metamodel interface in context.

size:P →N is a function that returns the number of entities of a pattern, which is calculated as follows:∀P ∈ P:size(P) = (the number of nodes inP) + (the number of edges inP) + (the number of constraints inP), i.e. size(P) =|N(P)|+|E(P)|+|C(P)|. 2 We will use the function size to provide a valid limit function ωP. Given the fixed formulae ϕ1 and ϕ2, we take all the patterns that appear in them and compute the sum of their sizes. If ψ is a formula to be checked, we require the size of the pattern to be at most the previously computed size for any patterns in ψ. This is a limit to the size of the patterns, which means that the graph of the patterns can have only finite number of forms. Moreover, the pattern can have finite number of constraints. However, there may be many types of constraints defined in the patterns. In order to ensure that only finite number of patterns could be constructed, we require that each constraint of the patterns ofψ must be present in any of the patterns of ϕ1 orϕ2. Therefore, ψ can contain only finite number of types of patterns.

Definition 5.39 (limit function for patterns). Thelimit function for patternsis denoted by ωP

and is defined as follows. Letψ,ϕ1, andϕ2 be three TPDL formulae. LetPdenote the patterns that appear inψ andQ denote the patterns that appear inϕ1 andϕ2.ωP1, ϕ2i(ψ) =true iff∀P ∈P: size(P)≤PQ∈Qsize(Q) and ∀c∈ C(P) :∃Q∈Q such that ∃p:PQ where p is a partial pattern morphism,p(c) exists andp(c)∈ C(Q). We useωP1, ϕ2ito denote the limit function that is initialized byϕ1 and ϕ2. Note that Qand Pare the collection of all patterns of the appropriate formulae; they are not necessarily sets, i.e. these patterns are not required to be unique up to isomorphism. 2 Proposition 5.40 (validity of the limit function for patterns). Given any two TPDL formulae ϕ1 and ϕ2, the function ωP1, ϕ2i is a valid limit function, i.e. there are only finite number of non equivalent TPDL formula that satisfy the conditionωP1, ϕ2i.

Proof of Proposition 5.40. Given ϕ1 and ϕ2, let ψ be a formula with patterns P such that ωP1, ϕ2i(ψ) =true. If P is a pattern of ψ, then size(P)≤n where n=PQ∈Qsize(Q) and Q is the collection of patterns of ϕ1 and ϕ2. This means that P contains at most n number of graph elements. SinceP must conform to a metamodelMwhose graph is finite, this means that the graph ofP can have only finite number of different forms. For any constraintc that is part of P, we know that∃pc:PQi such that QiQ and pc(c)∈Qi. Since the number of constraints in the patterns ofQ is finite, P can have only finite number of constraints.

We have proved that ifP is a pattern ofψ, thenP must be an element of a finite set of patterns.

From a finite set of patterns, we can compose only finite number of non-equivalent relation pattern conditions. Given a finite set of atoms, by means of the logical connectives, we can compose only

finite number of non-equivalent formulae.

The presented limit function is used in the algorithmIntroduceNewAtomsto guarantee that there is only finite number of atoms that can be returned by the algorithm.

5. Formalizing Functional Properties of Model Transformations