• No se han encontrado resultados

Casos 352328 Síndrome MEGDEL 20 Casos

5.2

Decidability for Hierarchical Programs

We now study the computational complexity of the following decision prob- lem: (πhie) given an hierarchical Datalog program P and Datalog goals F1, G1,

determine whether P ∪{F1} ZmaxP P ∪{G1}. In this respect, let P be a hierarchical

Datalog program.

Algorithm 3: function bisim1(F1,G1)

begin

if bothempty(F1, G1) or bothf ail(F1, G1) then

return true else SF ←− successor(F1) SG ←− successor(G1) if SF 6= ∅ and SG 6= ∅ then SF0 ←− SF while SF0 6= ∅ do F2←− get-element(SF0) f ound-bisim ←− f alse SG0 ←− SG

while SG06= ∅ and f ound-bisim = f alse do G2 ←− get-element(SG0)

f ound-bisim ←− bisim1(F2, G2)

if f ound-bisim = f alse then return f alse SG0 ←− SG while SG06= ∅ do G2 ←− get-element(SG0) f ound-bisim ←− f alse SF0 ←− SF

while SF06= ∅ and f ound-bisim = f alse do F2 ←− get-element(SF0)

f ound-bisim ←− bisim1(G2, F2)

if f ound-bisim = f alse then return f alse

return true else

return f alse

In Algorithm3, bothempty(F1,G1) is a Boolean function returning true iff

F1=  and G1 = , whereas bothfail(F1,G1) is a Boolean function returning

true iff F1 6= , successor(F1)=∅, G1 6=  and successor(G1)=∅. Moreover,

with a clause of P whereas get-element(.) is a function removing one element from the set of elements given as input and returning it.

Example 5.1 Running the algorithm bisim1 on an hierarchical logic program

Let P be the following hierarchical logic program: C1: q(a) ←;

C2: p(a, b) ←;

C3: p(b, c) ←;

C4: p(b, y) ← q(y);

and F1(a, b) =← p(a, b), G1(b, c) =← p(b, c) two goals. Its corresponding SLD-

trees is depicted next:

SLD-tree(P ∪ {F1(a, b)}) SLD-tree(P ∪ {G1(b, c)})

← p(a, b)



← p(b, c)

 ← q(c)

Note that in the SLD-tree of P ∪ {G1(b, c)}, the goal ← q(c) is a failure goal.

The following is the trace execution of the Algorithm3over the goals F1(a, b)

and G1(b, c).

bisim1(F1(a, b),G1(b, c))

bothempty(F1(a, b),G1(b, c)) is false

bothfail(F1(a, b),G1(b, c)) is false

SF ←− {} SG ←− {, q(c)} SF 6= ∅ and SG 6= ∅ SF0←− {} SF06= ∅ F2←−  , SF0←− ∅ f ound-bisim ←− f alse SG0←− {, q(c)}

SG06= ∅ and f ound-bisim = f alse G2←−  , SG0←− {q(c)}

f ound-bisim ←− bisim1(,) bothempty(,) is true return true

SG06= ∅ and f ound-bisim = true (quit the while loop) f ound-bisim = true (loop on the elements of SF0) SF0= ∅ (continue in the second part of the algorithm) SG0←− {, q(c)}

SG06= ∅

G2←−  , SG0←− {q(c)}

f ound-bisim ←− f alse SF0←− {}

SF06= ∅ and f ound-bisim = f alse F2←−  , SF0←− ∅

f ound-bisim ←− bisim1(,) bothempty(,) is true

5.2. DECIDABILITY FOR HIERARCHICAL PROGRAMS 109

return true

SF0= ∅ (continue and check the if statement) f ound-bisim = true (loop on the elements of SG0) SG06= ∅

G2←− q(c) , SG0←− ∅

f ound-bisim ←− f alse SF0←− {}

SF06= ∅ and f ound-bisim = f alse F2←−  , SF0←− ∅ f ound-bisim ←− bisim1(,q(c)) bothempty(,q(c)) is false bothfail(,q(c)) is false SF ←− ∅, SG ←− ∅ return f alse

SF0= ∅ and f ound-bisim = f alse (continue and check the if statement) f ound-bisim = f alse

return f alse

Thus the algorithm bisim1(F1(a, b),G1(b, c)) returns f alse.

In order to demonstrate the decidability of (πhie), we need to prove the fol-

lowing lemmas for all Datalog goals F1, G1:

Lemma 5.2.1 (Termination). bisim1(F1,G1) terminates.

Lemma 5.2.2 (Completeness). If P ∪{F1} ZmaxP P ∪{G1}, then bisim1(F1,G1)

returns true.

Lemma 5.2.3 (Soundness). If bisim1(F1,G1) returns true, then P ∪{F1} ZmaxP

P ∪ {G1}.

Let  be the binary relation on the set of all pairs of Datalog goals defined by: (F2, G2)  (F1, G1) iff

• the SLD-tree for F1 is deeper than the SLD-tree for F2,

• the SLD-tree for G1 is deeper than the SLD-tree for G2.

The depth of an SLD-tree is the depth of its longest branch. Remark that in this section, all SLD-trees are finite.

Obviously,  is a partial order on the set of all pairs of goals. Since P is hierar- chical, then  is well-founded.

Proof of Lemma 5.2.1. The proof is done by -induction on (F1, G1). Let (F1, G1)

be such that for all (F2, G2), if (F2, G2)  (F1, G1) then bisim1(F2,G2) termi-

nates. Since every recursive call to bisim1 that is performed along the execution of bisim1(F1,G1) is done with respect to a pair (F2, G2) of goals such that

Proof of Lemma 5.2.2. Let us consider the following property:

(P rop1(F1, G1)) if F1ZmaxP G1 then bisim1(F1,G1) returns true.

Again, we proceed by -induction. Suppose (F1, G1) is such that for all (F2, G2),

if (F2, G2)  (F1, G1) then P rop1(F2, G2). Let us show that P rop1(F1, G1).

Suppose P ∪ {F1} ZmaxP P ∪ {G1}. Hence, for all successors F2 of F1, there exists

a successor G2 of G1 such that P ∪ {F2} ZmaxP P ∪ {G2}, and conversely. Seeing

that the logic program is hierarchical, then (F2, G2)  (F1, G1). By induction

hypothesis, P rop1(F2, G2). Since P ∪ {F2} ZmaxP P ∪ {G2}, then bisim1(F2,G2)

returns true. As a result, one sees that bisim1(F1,G1) returns true.

Proof of Lemma 5.2.3. It suffices to demonstrate that the binary relation Z de- fined as follows between Datalog goals is a bisimulation: F1Z G1iff bisim1(F1,G1)

returns true. Let F1, G1be Datalog goals such that F1Z G1. Hence, bisim1(F1,G1)

returns true. Thus, obviously, F1 =  iff G1 = , and the first condition charac-

terizing bisimulations holds for Z. Now, suppose that F2 is a resolvent of F1 and

a clause in P . Since bisim1(F1,G1) returns true, then there exists a resolvent

G2 of G1 and a clause in P such that bisim1(F2,G2) returns true, i.e. F2 Z G2.

As a result, the second condition characterizing bisimulations holds for Z. The third condition characterizing bisimulations holds for Z too, as the reader can quickly check. Thus Z is a bisimulation.

As a consequence of lemmas5.2.1– 5.2.3, we have:

Theorem 5.2.1. Algorithm 3 is a sound and complete decision procedure for (πhie).

It follows that (πhie) is decidable. Moreover,

Theorem 5.2.2. (πhie) is in 2EXPTIME.

Proof. Let P be a hierarchical Datalog program and G be a goal. Let n be the maximal number of atoms in the clauses of P or in G, and t be the number of level mapping in P .

In fact, the maximal depth of a branch in an SLD-tree is equal to n × (the maximal depth of a branch at level t − 1) which is in turn equal to n × (1 + n × (1+ the maximal depth of a branch at level t − 2)). Thus, by iterating the same operation until level 1, we conclude that the maximal depth D of a branch in an SLD-tree cannot exceedPt

i=1ni. Remark that

Pt

i=1ni≤ t × nt.

Let s be the maximal number of clauses that defines a predicate. Hence, the branching degree of the SLD-tree for P ∪ {G} is bounded by s. Remark that our algorithm uses twice two nested loops. Each loop run through all the successors of a some goal. In the worst case, the number of successors of a goal will not exceed the branching degree s. In fact, for a maximal depth D, the time complexity

5.2. DECIDABILITY FOR HIERARCHICAL PROGRAMS 111

of the algorithm is approximately equal to 2 × s2× (the time complexity of the

algorithm for a depth D−1) which is in turn equal to 4×s4×(the time complexity of the algorithm for a depth D − 2). Thus, by iterating the same operation until depth 1, one can show that for a depth D, the time complexity of our algorithm is about 2D× s2×D≤ 2t×nt

× s2×t×nt

.

Note that for a hierarchical program P and a goal G, the number of nodes in the corresponding SLD-tree is about st×nt.

Concerning the exact complexity of (πhie), we do not know whether (πhie) is

Documento similar