slides01-16

# slides01-16 - Five Groups of Rules for Magic Construction...

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Five Groups of Rules for Magic Construction Let r be a typical rule H :- G1 & G2 &    & G Group I Supplementary  magic for next subgoal. If G has IDB predicate p: m pbound args of G  :- sup ,1variables Group II Magic  0th supplementary. If head has predicate q: sup 0 variables :- m qbound args Group III i , 1st supplementary + G  ith supplementary. sup variables :- sup ,1variables & G n i i r:i r: i r:i r:i i Group IV Last supplementary + last subgoal  head. H :- sup ,1variables & G Group V Initialize. If query has predicate p we have the bodyless rule m pbound args from query r:n n Group V is the only rule that depends on the actual query. Others depend only on the binding pattern. Magic-Sets Beats Top-Down Claim: the magic" rules implemented by seminaive evaluation only infers facts that any top-down implementation would infer. 3 I.e., magic-sets + seminaive has the advantages of both top-down and bottomup. 3 Well not exactly. Prolog uses a tailrecursion elimination" technique that sometimes does in On time what takes On2  by magic-sets. 3 The same trick has been used in deductive systems like LDL, Coral; it is described in Ch. 15 of PDKS-II. 1 Example Binary trees constructed as terms. Leaves constructed by constant leaf . Interior nodes constructed by function symbol n. nT1 ; T2 is a tree with left subtree T1 and right subtree T2 . Predicate subT1 ; T2  true when T1 is a subtree of T2 . Predicate eqT1 ; T2 true when T1 and T2 are identical trees. Rules: r1: eqleaf,leaf r2: eqnT1,T2,nT3,T4 :- eqT1,T3 & eqT2,T4 r3: subT1,T2 :- eqT1,T2 r4: subT1,nT2,T3 :- subT1,T2 r5: subT1,nT2,T3 :- subT1,T3 Query: subT,nnleaf,leaf,leaf, i.e., nd the subtrees of a speci c tree. Adorned goal: sub . fb The Rule Goal Graph sub fb r3 02j 1 T T : eq r4 02 3j 1 T ;T r5 02 3j 1 T T : ;T : fb r1j 0 r2 03 4j 1 2 T : ;T T ;T : r2 11 3 4j 2 T ;T ;T : Interesting fact: r4 and r5 are not safe. however, for the sub binding pattern, all variables of the head either appear in the fb 2 T T body or are present in a bound argument of the head. This notion of safety with respect to a binding pattern is appropriate when magic-sets is used. The Magic Rules Group I m m m m m eqT3 :- sup2:0T3,T4 eqT4 :- sup2:1T1,T3,T4 eqT2 :- sup3:0T2 subT2 :- sup4:0T2,T3 subT3 :- sup5:0T2,T3 Group II sup2:0T3,T4 :- m eqnT3,T4 sup3:0T2 :- m subT2 sup4:0T2,T3 :- m subnT2,T3 sup5:0T2,T3 :- m subnT2,T3 Group III sup2:1T1,T3,T4 :sup2:0T3,T4 & eqT1,T3 Group IV eqleaf,leaf eqnT1,T2,nT3,T4 :sup2:1T1,T3,T4 & eqT2,T4 subT1,T2 :- sup3:0T2 & eqT1,T2 subT1,nT2,T3 :sup4:0T2,T3 & subT1,T2 subT1,nT2,T3 :sup5:0T2,T3 & subT1,T3 Group V m subnnleaf,leaf,leaf Simplifying Magic Rules Use Group II rules to replace sup 0 's by magic predicates. If a supplementary predicate comes before an EDB subgoal, it is used only once and may be eliminated. However, if it is before an IDB subgoal, it is used twice, once in Group I and once in Group III or IV. r: 3 Thus, we can omit sup if i + 1st subgoal is EDB and i 0. We use in place of Group III rules new rules of the form: sup    :sup ,1   & G &    & G ,1 provided all of G +1; : : :; G ,1 are EDB. Also, G is IDB, and either G is IDB or i = 1. r:i r:j r:i i i j j j i Similarly, Group IV rules are replaced by H :- sup ,1   & G &    & G provided all of G +1; : : :; G are EDB. Also, G is IDB or i = 1. In the two rules above, use the appropriate magic predicate if i = 1. r:i i i n n i Example For the tree rules, we get: Group I m m m m m eqT3 :- m eqnT3,T4 eqT4 :- sup2:1T1,T3,T4 eqT2 :- m subT2 subT2 :- m subnT2,T3 subT3 :- m subnT2,T3 Group III sup2:1T1,T3,T4 :m eqnT3,T4 & eqT1,T3 Group IV eqleaf,leaf eqnT1,T2,nT3,T4 :sup2:1T1,T3,T4 & eqT2,T4 subT1,T2 :- m subT2 & eqT1,T2 subT1,nT2,T3 :m subnT2,T3 & subT1,T2 subT1,nT2,T3 :m subnT2,T3 & subT1,T3 Group V m subnnleaf,leaf,leaf 4 ...
View Full Document

## This document was uploaded on 01/06/2012.

Ask a homework question - tutors are online