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

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

View Full Document Right Arrow Icon
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 pbound args of G  :- sup ,1variables Group II Magic  0th supplementary. If head has predicate q: sup 0 variables :- m qbound args Group III i , 1st supplementary + G  ith supplementary. sup variables :- sup ,1variables & G n i i r:i r: i r:i r:i i Group IV Last supplementary + last subgoal  head. H :- sup ,1variables & G Group V Initialize. If query has predicate p we have the bodyless rule m pbound 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 On time what takes On2  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. nT1 ; T2 is a tree with left subtree T1 and right subtree T2 . Predicate subT1 ; T2  true when T1 is a subtree of T2 . Predicate eqT1 ; T2 true when T1 and T2 are identical trees. Rules: r1: eqleaf,leaf r2: eqnT1,T2,nT3,T4 :- eqT1,T3 & eqT2,T4 r3: subT1,T2 :- eqT1,T2 r4: subT1,nT2,T3 :- subT1,T2 r5: subT1,nT2,T3 :- subT1,T3 Query: subT,nnleaf,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 eqT3 :- sup2:0T3,T4 eqT4 :- sup2:1T1,T3,T4 eqT2 :- sup3:0T2 subT2 :- sup4:0T2,T3 subT3 :- sup5:0T2,T3 Group II sup2:0T3,T4 :- m eqnT3,T4 sup3:0T2 :- m subT2 sup4:0T2,T3 :- m subnT2,T3 sup5:0T2,T3 :- m subnT2,T3 Group III sup2:1T1,T3,T4 :sup2:0T3,T4 & eqT1,T3 Group IV eqleaf,leaf eqnT1,T2,nT3,T4 :sup2:1T1,T3,T4 & eqT2,T4 subT1,T2 :- sup3:0T2 & eqT1,T2 subT1,nT2,T3 :sup4:0T2,T3 & subT1,T2 subT1,nT2,T3 :sup5:0T2,T3 & subT1,T3 Group V m subnnleaf,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 + 1st 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 eqT3 :- m eqnT3,T4 eqT4 :- sup2:1T1,T3,T4 eqT2 :- m subT2 subT2 :- m subnT2,T3 subT3 :- m subnT2,T3 Group III sup2:1T1,T3,T4 :m eqnT3,T4 & eqT1,T3 Group IV eqleaf,leaf eqnT1,T2,nT3,T4 :sup2:1T1,T3,T4 & eqT2,T4 subT1,T2 :- m subT2 & eqT1,T2 subT1,nT2,T3 :m subnT2,T3 & subT1,T2 subT1,nT2,T3 :m subnT2,T3 & subT1,T3 Group V m subnnleaf,leaf,leaf 4 ...
View Full Document

Ask a homework question - tutors are online