• Keine Ergebnisse gefunden

Knowledge-Based Systems and Deductive Databases

N/A
N/A
Protected

Academic year: 2021

Aktie "Knowledge-Based Systems and Deductive Databases"

Copied!
70
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Wolf-Tilo Balke Christoph Lofi Philipp Wille

Institut für Informationssysteme

Technische Universität Braunschweig http://www.ifis.cs.tu-bs.de

Knowledge-Based Systems

and Deductive Databases

(2)

•  Datalog can be converted to Relational Algebra and vice versa

–  This allows to merge Datalog-style reasoning techniques with relational databases

•  e.g. Datalog on RDBs, Recursive SQL, etc.

–  The elementary production rule (and thus the fixpoint iteration) has been implemented with

relational algebra in the last lecture

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- D-

7.0 Datalog to RelAlg

(3)

•  In addition to bottom-up approaches (like fix- point iteration), there are also top-down

evaluation schemes for Datalog

–  Idea: Start with query and try to construct a proof tree down to the facts

–  Simple Bottom Up approach: Construct all possible search trees by their depth

•  Search tree: Parameterized proof tree

– Search tree can be transformed to a proof tree by providing a valid substitution

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- E-

7.0 Datalog to RelAlg

(4)

–  Search trees are constructed by backwards- chaining of rules

–  Problem: When to stop?

•  A naïve solution: Compute the theoretical maximal chain length and use as limit

–  Outlook for today: Optimization techniques

•  Evaluation optimization

•  Query rewriting

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- F-

7.0 Datalog to RelAlg

(5)

•  More implementation and optimization techniques

–  Design Space –  Delta Iteration –  Logical Rewriting –  Magic Sets

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- G-

7 Datalog Optimization

(6)

•  The computation algorithms introduced in the previous weeks were all far from optimal

–  Usually, a lot of unnecessary deductions were performed

–  Wasted work

–  Termination problems, etc…

•  Thus, this week we will focus on optimization methods

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- H-

7.1 Query Optimization

(7)

•  Optimization and evaluation methods can be classified along several criterions

–  Search technique –  Formalism

–  Objective

–  Traversal Order –  Approach

–  Structure

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- I-

7.1 Query Optimization

(8)

•  Search Technique:

– Bottom-Up

•  Start with extensional database and use forward- chaining of rules to generate new facts

•  Result is subset of all generated facts

•  Set oriented-approach !"Very well-suited for databases

– Top-Down

•  Start with queries and either construct a proof tree or a refutation proof by backward-chaining of rules

•  Result is generated tuple-by-tuple !"More suited for complex languages, but less desirable for use within a database

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- J-

7.1 Query Optimization

(9)

•  Furthermore, there are two possible (non-exclusive) formalisms for query optimization

– Logical: A Datalog program is treated as logical rules

•  The predicates in the rules are connected to the query predicate

•  Some of the variables may already be bound by the query

– Algebraic: The rules in a Datalog program can be translated into algebraic expressions

•  Thus, the IDB corresponds to a system of algebraic equations

•  Transformations like in normal database query optimization may apply

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- K-

7.1 Query Optimization

(10)

•  Optimizations can address different objectives

–  Program Rewriting:

•  Given a specific evaluation algorithm, the Datalog program

# is rewritten into a semantically equivalent program #’

•  However, the new program # can be executed much faster than # using the same evaluation method

–  Evaluation Optimization:

•  Improve the process of evaluation itself, i.e. program stays as it is but the evaluation algorithm is improved

•  Can be combined with program rewriting for even increased effect

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- LM-

7.1 Query Optimization

(11)

•  Optimizations can focus on different traversal-orders

– Depth-First

•  Order of the literals in the body of a rule may affect performance

– e.g. consider top-down evaluation with search trees for

$%&'()*+$%&',)'"-%,'()""vs. $%&'()"*+"-%,'()'"$%&',)".

– In more general cases (e.g. Prolog), may even affect decidability

•  It may be possible to quickly produce the first answer

– Breadth-First

•  Whole right hand-side of rules is evaluated at the same time

•  Search trees grow more balanced

•  Due to the restrictions in Datalog, this becomes a set-oriented operation and is thus very suitable for DB’s

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- LL-

7.1 Query Optimization

(12)

•  When optimizing, two approaches are possible

–  Syntactic: just focus on the syntax of rules

•  Easier and thus more popular than semantics

•  e.g. restrict variables based on the goal structure or use special evaluation if all rules are linear, etc.

–  Semantic: utilize external knowledge during evaluation

•  E.g., integrity constraints

•  External constraints: “Lufthansa flights arrive at Terminal 1”

Query: “Where does the flight LH1243 arrive?”

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- LD-

7.1 Query Optimization

(13)

•  Summary of optimization classification with their (not necessarily exclusive) alternatives

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- LE-

7.1 Query Optimization

!"#$%"#&'( )*$%"'+,-%.(

/%+"01($%01'#23%( 7#N#1)3@- 0#@)'#$"-

4&"5+*#.5( %#(<4- C&%+5#"+%-+%(&7C+-

678%0,-%( C&$C<5"(- @3C&-&6+%3+5#"- 9"+-%".+*(&":%"( '&@0?)OC,0- 7C&+'0?)OC,0-

);;"&+01( ,/"0+454- ,&1+"54-

/$"30$3"%( C3%&-,0C3403C&- (#+%-,0C3403C&-

(14)

•  Not all combinations are feasible or sensible

–  We will focus on following combinations

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- LF-

7.1 Query Optimization

<6996=>?@( 96@>A6BC(

D-+*3+,&'(=%$1&:.( P+Q6&-RE+0&7#S-F+3..>/%#:%*T- .&1<)"+Q6&-RA%*$+(G$%"+,&'T- U&",4?&")P+V6<--

P+Q6&-;#@)2#$"-$<0?- .&+C4?-0C&&,-

W3&C/).37V3&C/-

H&I#0( )*I%7"+#0(

J%K"#,'I(=%$1&:.( =+I#0(/%$.- X#3"5"(-

.0+54-Y<%0&C<"(-

Z+C<+7%&-C&'345#"- X#",0+"0-C&'345#"-

(15)

•  Optimization techniques may be combined

–  Thus, mixed execution of rewriting and evaluation techniques based on logical and algebraic optimization is possible

•  Start with logic program L#

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- LG-

7.1 Query Optimization

[#--

[#\--

]&,3%0-

[#(<4+%-- ]&$C<5"(-

[#(<4+%--

^6+%3+5#"-

[#--

_#--

]&,3%0-

_%(&7C+<4--

;C+",:#C1+5#"-

_%(&7C+<4-

^6+%3+5#"-

_#\--

_%(&7C+<4- ]&$C<5"(-

[#--

_#\--

]&,3%0-

_%(&7C+<4-

^6+%3+5#"-

_#\\--

_%(&7C+<4- ]&$C<5"(-

[#\--

[#(<4+%-- ]&$C<5"(-

_%(&7C+<4--

;C+",:#C1+5#"-

(16)

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- LH-

7.1 Query Optimization

2+0+%#(--

@C#(C+1- -#--

2+0+%#(--

@C#(C+1- -#\-

H&I#0+*--

V3&C/-&6+%3+5#"-1&0?#',- )*I%7"+#0--

V3&C/-&6+%3+5#"-1&0?#',-

L3%"M("%.3*$(

--H&I#0+*((

"%K"#,'I(

]&%+5#"+%-- +%(&7C+-

&V3+5#",-

]&%+5#"+%- +%(&7C+-

&V3+5#",-

)*I%7"+#0((

"%K"#,'I(

9"+'.N&"5+,&'(#'$&((

(J%*+,&'+*()*I%7"+(

(17)

•  Evaluation methods actually compute the result of an (optimized or un-optimized) program #

–  Better evaluation methods skip unnecessary evaluation steps and/or terminate earlier

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- LI-

7.2 Evaluation Methods

<6996=>?@( 96@>A6BC(

D-+*3+,&'(=%$1&:( P+Q6&-RE+0&7#S-F+3..>/%#:%*T- .&1<)"+Q6&-RA%*$+(G$%"+,&'T- U&",4?&")P+V6<--

P+Q6&-;#@)2#$"-$<0?- .&+C4?-0C&&,-

W3&C/).37V3&C/-

(18)

•  Datalog programs can easily be evaluated in a

bottom-up fashion, but this should also be efficient

– The naïve algorithm derives everything that is possible from the facts

– But naïvely answering queries wastes valuable work…

– For dealing with recursion we have to evaluate fixpoints

•  For stratified Datalog

f,neg

programs we apply the fixpoint algorithms to every stratum

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- LJ-

7.2 Bottom-Up Evaluation

(19)

•  Bottom-up evaluation techniques are usually based on the fixpoint iteration

•  Remember: Fixpoint iteration itself is a general concept within all fields of mathematics

–  Start with an empty initial solution &

/.

–  Compute a new &

012

from a given &

0

by using a production rule

•  &

012

"*3"4%&

0

)

–  As soon as &

012

3&

0

, the algorithm stops

•  Fixpoint reached

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- LK-

7.2 Bottom-Up Evaluation

(20)

•  Up to now we have stated the elementary production rule declaratively.

– 4

#

"*"5 "*"5

""

6"78"9"8 6"78"9"8

: : t there exists a ground instance t there exists a ground instance 8"*+";

2

'";

<

'"='";

0"

of a program clause such

that 7;

2

'";

<

'"='";

0

>"?"5>.

•  However, we need an operative implementation

– The set 5

@12"

is computed from 5

@

as follows:

•  Enumerate all ground instances A5.

– Each ground instance is given by some substitution (out of a finite set)

•  Iterate over the ground instances, i.e. try all different substitutions

– For each 8"*+";2'";<'"='";0"9"A5, if 7;2'";<'"='";0>"?"5@, add 8 to 5@12

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- DM-

7.2 Bottom-Up Evaluation

(21)

a)  Full Enumeration: Consecutively generate and test all instances by enumeration

•  Loop over all rules

–  Apply each possible substitution on each rule

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- DL-

7.2 Bottom-Up Evaluation

Constant symbols*"72'<'B>.

Rules*"7C%&'()"*+"D%&'()E"""C%&'()"*+"D%&',)'"C%,'()E>.

Enumeration of instances*.

Rule 1:

C%2'2)"*+"D%2'2)E". C%2'<)"*+"D%2'<)E". C%2'B)"*+"D%2'B)E"F C%<'2)"*+"D%<'2)E". C%<'<)"*+"D%<'<)E". C%<'<)"*+"D%<'<)E.

C%B'2)"*+"D%B'2)E". C%B'<)"*+"D%B'<)E". C%B'<)"*+"D%B'<)E.

Rule 2:

C%2'2)"*+"D%2'2)'"C%2'2)E. C%2'2)"*+"D%2'<)'"C%<'2)E""=F C%2'<)"*+"D%2'2)'"C%2'<)E. C%2'<)"*+"D%2'<)'"C%<'<)E""=.

=.

(22)

b)  Restricted enumeration

•  Loop over all rules

–  For each rule, generate all instances possible when trying to unify the rules right hand side with the facts in !"

–  Only instances which will trigger a rule in the current iteration will be generated

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- DD-

7.2 Bottom-Up Evaluation

Constant symbols*"72'<'B>.

Rules*"7C%&'()"*+"D%&'()E"""C%&'()"*+"D%&',)'"C%,'()E>.

5*"7D%2'<)'"D%<'B)>.

Enumeration of instances*.

Rule 1:

C%2'<)"*+"D%2'<)E". C%<'B)"*+"D%<'B)E"F

Rule 2: Nothing. #$%&'("can not be unified with any fact in !.

(23)

•  The most naïve fixpoint algorithm class are the so-called Jacobi-Iterations

–  Developed by Carl Gustav Jacob Jacobi for solving

linear equitation systems ;G3H, early 18

th

century –  Characteristics:

•  Each intermediate result &

012

is wholly computed by utilizing all data in &

0.

•  No reuse between both results

•  Thus, the memory complexity for a given iteration step is roughly :&

012

:I:&

0

:.

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- DE-

7.2 Jacobi Iteration

(24)

•  Both fixpoint iterations introduced previously in the lecture are Jacobi iterations

–  i.e. fixpoint iteration and iterated fixpoint iteration

–  i.e. 5

012"

*3"4

#"

%5

0

).

•  “Apply production rule to all elements in 5

0"

and write results to 5

012

. Repeat”

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- DF-

7.2 Jacobi Iteration

(25)

•  Please note

–  Within each iteration, all already deduced facts of previous iteration are deduced again

•  Yes, they were… We just used the union notation for convenience

– 52"*3"5/"J"7D%2'<)'"D%2'B)>"F

5<"*3"52"J"7C%2'<)'"C%2'B)> was actually not reflecting this correctly.

– 52"*3"7D%2'<)'"D%2'B)>F

5<"*3"7D%2'<)'"D%2'B)'"C%2'<)'"C%2'B)> matches algorithm better…

–  Furthermore, both sets 5

012""

and 5

0"

involved in the iteration are treated strictly separately

•  Elementary production checks which rules are true within 5

@

and puts result into 5

@12

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- DG-

7.2 Jacobi Iteration

(26)

•  Idea:

– The convergence speed of the Jacobi iteration can be improved by also

respecting intermediate results of current iteration

•  This leads to the class of Gauss-Seidel-Iterations

– Historically, an improvement of the Jacobi equitation solver algorithm

•  Devised by Carl Friedrich Gauss and Philipp Ludwig von Seidel

– Base property:

•  If new information is produced by current iteration, it should also be possible to use it in the moment it is created (and not starting next iteration)

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- DH-

7.2 Gauss-Seidel Iteration

(27)

•  A Gauss-Seidel fixpoint iteration is obtained by modifying the elementary production

–  4

#

"*"5 "*"5

""

6"78"9"8 6"78"9"8

: : there exists a ground instance there exists a ground instance which has not been tested before in this iteration 8"*+";

2

'";

<

'"='";

0"

of a program clause such

that 7;

2

'";

<

'"='";

0

>"?"75"J"0DKL8MN>>.

–  0DKL8MN refers to all heads of the ground instances

of rules considered in the current iteration which had their body literals in 5.

•  Some of these are already in 5, but others are new and would usually only be available starting next iteration !"

improved convergence speed

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- DI-

7.2 Gauss-Seidel Iteration

(28)

•  Example program #

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- DJ-

7.2 Gauss-Seidel Iteration

L- D-

E- F- G-

DOPD%2'"<)E.

DOPD%2'"B)E.

DOPD%<'"Q)E.

DOPD%B'"Q)E.

DOPD%Q'"R)E.

CSTU%&'"()"*+"DOPD%&'"()E"".

CSTU%&'"()"*+"DOPD%&'",)'"CSTU%,'"()E"".

5/"3"7>F

52"3"7DOPD%2'"<)E"DOPD%2'"B)E"DOPD%<'"Q)E"DOPD%B'"Q)E"DOPD%Q'"R)E""F

""""""""""CSTU%2'"<)E"CSTU%2'"B)E"CSTU%<'"Q)E"CSTU%B'"Q)E"CSTU%Q'"R)E"F

""""""""""CSTU%2'"Q)E"CSTU%<'"R)E"CSTU%B'"R)">.

5<"3"7CSTU%2'"R)>-

(29)

•  Please note:

– The effectiveness of Gauss-Seidel iteration for

increasing convergence speed varies highly with respect to the chosen order of instance enumeration

•  e.g. “Instance V tested - generates the new fact 8

2

from 5”,

“Instance W tested – generates the new fact 8

<

from 5"J"8

2

– Good luck – improvement vs. Jacobi

•  vs. “Instance W tested – does not fire because it needs fact 8

2

”,

“Instance V tested – generates the new fact 8

2

from 5”

– Bad luck – no improvement

– Each single iteration which can be saved improves

performance dramatically as each iteration recomputes all known facts!

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- DK-

7.2 Gauss-Seidel Iteration

(30)

•  For both Gauss-Seidel and Jacobi, a lot of wasted work is performed

–  Everything is recomputed times and times again

•  But it can be shown that the elementary production rule is strictly monotonic

–  Thus, each result is a subset of the next result

•  i.e. 5

@

"?"5

@12

•  This leads to the semi-naïve evaluation for linear Datalog

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- EM-

7.2 Semi-Naïve Evaluation

(31)

•  The main operator for the fixpoint iteration is the elementary production 4

#

–  Naïve Fixpoint Iteration

•  5

012"

*3"4

#"

%5

0

).

–  Is there a better algorithm?

.

•  Idea: avoid re-computing known facts, but make sure that at least one of the facts in the body of a rule is new, if a new fact is computed!

•  Really new facts, always involve new facts of the last iteration step, otherwise they could already have been computed before…

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- EL-

7.2 Semi-Naïve Evaluation

(32)

•  Semi-naïve linear evaluation algorithms for

Datalog are generally known as Delta-Iteration

–  In each iteration step, compute just the difference between successive results X5

@"

*3"5

@

"Y"5

@+2.

–  i.e. X5

2"""""

*3"5

2

"Y"5

/"""""""""

3"4

#"

%Z)F

""""""""X5

@12"

*3"5

@12

"Y"5

@"

""3"4

#"

%5

@

)"Y"5

@

""F . """""""""""""""""3"4

#"

%5

@+2"

[""X5

@

)"Y"5

@.

•  Expecially*"X5

@"

["5

@+2

"*3"5

@

.

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- ED-

7.2 Semi-Naïve Evaluation

(33)

•  It is important to efficiently calculate X5

@12"

*3"4

#"

%5

@+2"

[""X5

@

)"Y"5

@.

–  Especially the 4

#

operator is often inefficient, because operator is often inefficient, because it simply applies all rules in the EDB

–  More efficient is the use of auxiliary functions

•  Define an auxiliary function of 4

#

aux aux

"#""#"

: 2 : 2

88##

! ! ! "2 "2 "2

888###

!2 !2 !2 !2

8888####

such that 4

#"

%5

@+2"

[""X5

@

)"Y"5

@

= S\G

"#

%5 %5

@+2@+2

'"X5 '"X5

@@

)"Y"5 )"Y"5

@.@.

•  Auxiliary functions can be chosen intelligently by just taking recursive parts of rules into account

•  A classic method of deriving auxiliary functions is symbolic differentiation

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- EE-

7.2 Semi-Naïve Evaluation

(34)

•  The symbolic differentiation operator O]"can be used on the respective relational algebra expressions

^ for Datalog programs.

Definition O]%^)*.

– O]%^)"*3"X_"'"if ^ is an IDB relation _.

– O]%^)"*3"`"'"if ^ is an EDB relation _.

– O]%a

b

%^))"3"a

b

%O]%^)) and – O]%c

b

%^))"3"c

b

%O]%^)).

– O]%^

2

" 䏗 "^

<

)"3"O]%^

2

)" 䏗 O]%^

<

)

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- EF-

7.2 Semi-Naïve Evaluation

P#0-+`&40&'-7/-,&%&45#",S-

@C#a&45#",S-+"'-3"<#",-

(35)

•  O]%^

2

" ! "^

<

)"3"""^

2

" ! "O]%^

<

) 䏗 O]%^

2

)" ! "^

<

䏗 O]%^

2

)" ! "O]%^

<

)

•  O]%^

2

"d

b

"^

<

)"3"""^

2

"d

b

"O]%^

<

) 䏗 O]%^

2

)"d

b

"^

<

䏗 O]%^

2

)"d

b

"O]%^

<

)

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- EG-

7.2 Semi-Naïve Evaluation

Y#C-X+C0&,<+"-@C#'340,-+"'- a#<",-1<b&'-0&C1,-"&&'-0#-7&- 4#",<'&C&'-

(36)

•  Consider the program

•  S0eDNTfg%&'()"*+"CSgD0T%&'()EF

S0eDNTfg%&'()"*+"CSgD0T%&',)'"S0eDNTfg%,'()E.

•  The respective expression in relational algebra for S0eDNTfg is CSgD0T"J"c

h2'"h<

%CSgD0T"d

h<3h2

S0eDNTfg).

–  Symbolic differentiation

O]%CSgD0T"J"c

h2'"h<

%CSgD0T"d

h<3h2

S0eDNTfg))"F

3"O]%CSgD0T)"J"c

h2'"h<

%O]%CSgD0T"d

h<3h2

S0eDNTfg))F 3"`"J"c

h2'"h<

%O]%CSgD0T)"d

h<3h2

S0eDNTfg"J"CSgD0T""F

"""d

h<3h2

O]%S0eDNTfg)"J"O]%CSgD0T)"d

h<3h2

O]%S0eDNTfg))F 3"c

h2'"h<

%`"J"CSgD0T"d

h<3h2

O]%S0eDNTfg)"J"`)F

3"c

h2'"h<

%CSgD0T"d

h<3h2

"XS0eDNTfg).

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- EH-

7.2 Semi-Naïve Evaluation

(37)

•  Having found a suitable auxiliary function the delta iteration works as follows

–  Initialization

•  5

/"

"*3"Z.

•  X5

2"""""

*3""4

#"

%Z)

–  Iteration until X5

@12"

3"Z".

•  5

@"

*3"5

@+2

"[""X5

@

•  X5

@12"

*3"S\G

#

%5 %5

@+2@+2

'"X5 '"X5

@@

)"Y"5 )"Y"5

@.@.

–  Again, for stratified Datalog

f,neg

programs the iteration has to be applied to every stratum.

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- EI-

7.2 Semi-Naïve Evaluation

(38)

•  Let’s consider our ancestor program again

–  CSgD0T%4UfiSN'"jfU0)E"F

CSgD0T%kSgl'"jfU0)EF

CSgD0T%ADfgPD'"4UfiSN)EF CSgD0T%mf0nS'"4UfiSN)EF CSgD0T%$DTDg'"kSgl)EF

CSgD0T%VSgD0'"kSgl)E.

–  S0eDNTfg%&'()"*+"CSgD0T%&'()EF

S0eDNTfg%&'()"*+"CSgD0T%&',)'"S0eDNTfg%,'()E.

–  S\G

S0eDNTfg

%S0eDNTfg'"XS0eDNTfg)"F

"*3"c

h2'"h<

%CSgD0T"d

h<3h2

"XS0eDNTfg).

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- EJ-

7.2 Semi-Naïve Evaluation

c&#C(&- .#"a+- >&0&C- !+C&"-

;?#1+,- d+C/-

e#?"-

(39)

–  S0eDNTfg

/

"*3"Z.

–  XS0eDNTfg

2

"""""*3""4

#

"%Z)"F "%Z)"F

3"7%4'"j)'"%k'"j)'"%A'"4)'"%m'"4)'"F

""""""%$'"k)'"%V'"k)>.

–  S0eDNTfg

2

"""""*3"S0eDNTfg

/"

["XS0eDNTfg

2

F

"""""""""""""""""""""""""3"X"S0eDNTfg

2.

–  XS0eDNTfg

<

""*3"S\G

S0eDNTfg

%S0eDNTfg

/

'"XS0eDNTfg

2

)"Y"F

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""S0eDNTfg

2F

""""""""""""""""""""""""*3"c

h2'"h<

%CSgD0T"d

h<3h2

"XS0eDNTfg

2

)"Y"F

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""S0eDNTfg

2F

"""""""""""""""""""""""""3"7%A'"j)'"%m'"j)'"%$'"j)'"%V'"j)>

.

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- EK-

7.2 Semi-Naïve Evaluation

c&#C(&- .#"a+- >&0&C- !+C&"-

;?#1+,- d+C/-

e#?"-

(40)

–  S0eDNTfg

<

"*3"S0eDNTfg

2"

["XS0eDNTfg

<

""F

"""""""""""""""""""""3"7%4'"j)'"%k'"j)'"%A'"4)'"%m'"4)'"%$'"k)'"F

""""""""""""""""""""""""""%V'"k)'"%A'"j)'"%m'"j)'"%$'"j)'"%V'"j)>

.

–  XS0eDNTfg

B

""*3"S\G

S0eDNTfg

%S0eDNTfg

2

'"XS0eDNTfg

<

)"Y"F

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""S0eDNTfg

<F

"""""""""""""""""""""""*3"c

h2'"h<

%CSgD0T"d

h<3h2

"XS0eDNTfg

<

)"Y"F

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""S0eDNTfg

<F

"""""""""""""""""""""""""3"`.

–  Thus, the least fixpoint isF

"S0eDNTfg

<

"J"CSgD0T.

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- FM-

7.2 Semi-Naïve Evaluation

c&#C(&-.#"a+->&0&C- !+C&"-

;?#1+,- d+C/-

e#?"-

(41)

•  Transforming a Datalog program into relational algebra also offers other optimizations

–  Typical relational algebra equivalences can be used for heuristically constructing better query plans

•  Usually an operator tree is built and transformed

–  Example: push selection

•  If a query involves a join or Cartesian product, pushing all selections down to the input relations avoids large

intermediate results

–  But now we have a new operator in our query plan:

the least fixpoint iteration (denoted as W]$)

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- FL-

7.2 Push Selection

(42)

•  Consider an example

–  DOPD%2'"<)E"F

DOPD%Q'"<)EF DOPD%<'"B)EF DOPD%B'"R)EF DOPD%R'"o)E.

–  CSTU%&'()"*+"DOPD%&'()E""""""""""""""""""""""""_2F CSTU%&'()"*+"DOPD%&',)'"CSTU%,'()E"""_<.

–  Relational algebra: DOPD"J"c

h2'"h<

%DOPD"d

h<3h2

CSTU).

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- FD-

7.2 Push Selection

L- D- F-

E- G- H-

(43)

•  Now consider the query pCSTU%&'"B).

–  c

h2"

a"

h<3B

%W]$"%DOPD"J"c

h2'"h<

%DOPD"F

"""""""""""""""""""""""""""""""""""""""""""""""d

h<3h2

CSTU))).

•  From which nodes there is a path to node 3?

–  The above query binds the second argument of CSTU.

•  CSTU%&'()"*+"DOPD%&'()EF

CSTU%&'()"*+"DOPD%&',)'"CSTU%,'()E.

–  Thus the selection could be pushed down to the DOPD and CSTU relations

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- FE-

7.2 Push Selection

W]$

.

J -

d

h<3h2

.

DOPD.

!

h2Eh<.

DOPD. CSTU.

!

h2.

"

h<3B.

Query

(44)

•  To answer the query we now only have to consider the facts and rules having the correct second argument

–  DOPD%<'"B)E"".

–  CSTU%<'B)E.

–  CSTU%2'B)E.

–  CSTU%Q'B)E.

–  Result:"7<'"2'"Q>

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- FF-

7.2 Push Selection

W]$

.

J -

d

h<3h2

. DOPD.

!

h2Eh<.

DOPD.

CSTU.

!

h2.

"

h<3B.

"

h<3B.

L- D- F-

E- G- H- :+40-

]L- ]D-

(45)

•  Now let’s try a different query pCSTU%B'()

–  c

h2"

a"

h23B

%W]$"%DOPD"J"c

h2'"h<

%DOPD"F

"""""""""""""""""""""""""""""""""""""""""""""""d

h<3h2

CSTU))).

•  To which nodes there is a path from node 3?

–  The above query binds the first argument of CSTU.

•  CSTU%&'()"*+"DOPD%&'()EF

CSTU%&'()"*+"DOPD%&',)'"CSTU%,'()E.

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- FG-

7.2 Push Selection

W]$

.

J -

d

h<3h2

. DOPD.

!

h2Eh<.

DOPD.

CSTU.

!

h2.

"

h23B.

"

h23B.

(46)

•  To answer the query we now only have to consider the facts and rules having the correct first argument

–  DOPD%B'R)E"".

–  CSTU%B'R)E.

–  `.

–  Result:"7R>.

–  Obviously this is wrong

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- FH-

7.2 Push Selection

L- D- F-

E- G- H- :+40-

]L- ]D-

W]$

.

J -

d

h<3h2

. DOPD.

!

h2Eh<.

DOPD.

CSTU.

!

h2.

"

h23B.

"

h23B.

(47)

•  More general: when can the least fixpoint iteration and selections be re-ordered?

–  Let C be a predicate in a linear recursive Datalog program and assume a query p"C%='"e'"=), binding some variable &

at the @-th position to constant e

–  The selection a

h@3e

and the least fixpoint iteration W]$ can be safely exchanged, if

& occurs in all literals with predicate C exactly in the @-th position .

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- FI-

7.2 Push Selection

W]$

.

^.

"

.

W]$

.

^.

"

.

(48)

•  In the following, we deal with rewriting methods

•  Basic Idea:

–  Transform program # to a semantically equivalent program #’ which can be evaluated faster using the same evaluation technique

•  e.g. same result, but faster when applying Jacobi iteration

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- FJ-

7.3. Logical Rewriting

H&I#0( )*I%7"+#0(

J%K"#,'I(=%$1&:( =+I#0(/%$.- X#3"5"(-

.0+54-Y<%0&C<"(-

Z+C<+7%&-C&'345#"- X#",0+"0-C&'345#"-

(49)

•  Clever rewriting could work like this:

–  All valid proof trees for result tuples need a

substitution for rule 1 and rule 2 such that & is substituted by #$%&

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- FK-

7.3. Logical Rewriting

#*F

S0eDNTfg%&'"()"*+"CSgD0T%&'"()E"".

S0eDNTfg%&'"()"*+"S0eDNTfg%&'",)'"CSgD0T%,'"()E.

S0eDNTfg% #$%& '"()"p".

(50)

•  Thus, an equivalent program #’ for the query looks like this

– This simple transformation will skip the deduction of many (or in this case all) useless facts

– Actually, this transformation was straight forward and simple, but there are also unintuitive but effective

translations…

•  Magic sets!

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- GM-

7.3. Logical Rewriting

#M*F

S0eDNTfg% #$%& '"()"*+"CSgD0T% #$%& '"()E"".

S0eDNTfg% #$%& '"()"*+"S0eDNTfg% #$%& '",)'"CSgD0T%,'"()E.

S0eDNTfg% #$%& '"()"p".

(51)

•  Magic Sets

–  Magic sets are a rewriting method exploiting the syntactic form of the query

–  The base idea is to capture some of the binding patterns of top-down evaluation approaches into rewriting

•  If there is a subgoal with a bound argument, solving this subgoal may lead to new instantiations of other arguments in the original rule

•  Only potentially useful deductions should be performed

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- GL-

7.3. Magic Sets

(52)

•  Who are the ancestors of #$%& ?

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- GD-

7.3. Magic Sets

c&#C(&- .#"a+- >&0&C- !+C&"-

#$%&- d+C/-

e#?"-

>+3%- .+C+?-

;<`/-

2&O"<0&%/-3"<1@#C0+"0-

>C#7+7%/-3"<1@#C0+"0- ]+@?+&%- d+C<+-

(53)

•  A typical top-down search tree for the goal S0eDNTfg% #$%& '"&)"looks like this

–  Possible substitutions already restricted

–  How can such a restriction be incorporated into rewriting methods?

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- GE-

7.3. Magic Sets

q"r"S0eDNTfg%#$%&'"&)--

S0eE%#$%&'"&)"*+"S0eE%#$%&'",)'"CSgE%,'"&)E- S0eE%#$%&'",)-- CSgE%,'"&)-- CSgE%#$%&'",)--

S0eE%#$%&'"&)"*+"CSgE%#$%&'",)E-

(54)

•  For rewriting, propagating binding is more difficult than using top-down approaches

•  Magic Set strategy is based on augmenting rules with additional constraints (collected in the

magic predicate)

–  This is facilitated by “adorning” predicates

–  Sideways information passing (SIP) is used to propagate binding information

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- GF-

7.3. Magic Sets

(55)

•  Before being able to perform the magic set transformation, we need some auxiliary definitions and considerations

–  Every query (goal) can also be seen as a rule and thus be added to the program

•  e.g. S0eDNTfg% #$%& '"&)p"""s"""t%&)"*+"S0eDNTfg% #$%& '"&).

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- GG-

7.3. Magic Sets

(56)

•  Arguments of predicates can be distinguished

–  Distinguished arguments have their range restricted by either constants within the same predicate or variables which are already restricted themselves

–  i.e.: The argument is distinguished if

•  it is a constant

•  OR it is bound by an adornment

•  OR it appears in an EDB fact that has a distinguished argument

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- GH-

7.3. Logical Rewriting

(57)

•  Predicates occurrences are distinguished if all its arguments are distinguished

–  In case of EDB facts, either all or none of the arguments are distinguished

•  Predicate occurrences are then adorned (i.e.

annotated) to express which arguments are distinguished

–  Adornments are added to the predicate, e.g."C

uH

%&'"()"vs."C

HH

%&'"()

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- GI-

7.3. Logical Rewriting

(58)

–  For each argument, there are two possible adornments

• 

H

for bound, i.e. distinguished variables

• 

v

for free, i.e. non-distinguished variables

–  Thus, for a predicate with n arguments, there are 2

n

possible adorned occurrences

•  e.g.,"""C

HH

%&'"()"'"C

uH

%&'"()'"C

Hv

%&'"()'"C

vv

%&'"().

•  Those adorned occurrences are treated as if they were different predicates, each being defined by its own set of rules

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- GJ-

7.3. Magic Sets

(59)

•  Example output of magic set algorithm

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- GK-

7.3. Magic Sets

#*F

S0eDNTfg% #$%& '"()"p.

S0eDNTfg%&'"()"*+"CSgD0T%&'"()E"".

S0eDNTfg%&'"()"*+"S0eDNTfg%&'",)'"CSgD0T%,'"()E.

#M*.

iSP@e% #$%& )EF

iSP@e%()"*+"iSP@e%,)'"CSgD0T%,'"()E.

t

v

%()"*+"S0eDNTfg

Hv

% #$%& '"()EF

S0eDNTfg

Hv"

%&'"()"*+"iSP@e%&)'"CSgD0T%&'"()E"".

S0eDNTfg

Hv"

%&'"()"*+"iSP@e%&)'"S0eDNTfg

Hv"

%&'",)'"CSgD0T%,'"()E.

^"4#'&'-V3&C/- d+(<4-,&0-

_'#C"1&"0-

]3%&-]&,0C<45#"- d+(<4-C3%&-

(60)

•  The idea of the magic set method is that the magic set contains all possibly interesting constant values

–  The magic set is recursively computed by the magic rules

•  Each adorned predicate occurrence has its own defining rules

–  In those rules, the attributes are restricted according to the adornment pattern to the magic set

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- HM-

7.3. Magic Sets

(61)

•  Now, following problems remain

–  How is the magic""set computed?

–  How are the rules for adorned predicate occurrences actually defined?

•  Before solving these problems, we have to find out which adorned occurrences are needed

•  Thus, the reachable adorned system has to be found

–  i.e. incorporate the query as rule and

replace all predicate by it’s respective adornments

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- HL-

7.3. Magic Sets

(62)

•  Incorporate goal query

•  Adorn predicate occurrences

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- HD-

7.3. Magic Sets

S0eDNTfg%&'

'#$%&

)p.

S0eDNTfg%&'"()"*+"CSgD0T%&'"()E"".

S0eDNTfg%&'"()"*+"S0eDNTfg%&'",)'"CSgD0T%,'"()E.

t%&)"*+"S0eDNTfg%&'"

#$%&

).

S0eDNTfg%&'"()"*+"CSgD0T%&'"()E"".

S0eDNTfg%&'"()"*+"S0eDNTfg%&'",)'"CSgD0T%,'"()E.

t

v

%&)"*+"S0eDNTfg

uH

%&'"

#$%&

)E".

S0eDNTfg

uH

%&'"()"*+"CSgD0T%&'"()E"".

S0eDNTfg

uH

%&'"()"*+"S0eDNTfg

uH"

%&'",)'"CSgD0T%,'"()E.

C&+4?+7%&-+'#C"&'-,/,0&1-- CM-

CL-CD-

(63)

•  For defining the magic set, we create magic rules

– For each adorned predicate occurrence in a rule of an intensional DB predicate, a magic rule corresponding to the right hand side of that rule is created

•  Predicate occurrences are replaced by magic predicates, bound arguments are used in rule head, free ones are dropped

•  Magic predicates in the head are annotated with its origin (rule

& predicate), those on the right hand side just with the predicate

– tv%&)"*+"S0eDNTfguH%&'"#$%&)E"F s"iSP@eLg/LS0eDNTfguH%#$%&)E

– S0eDNTfguH%&'"()"*+"S0eDNTfguH%&'",)'"CSgD0T%,'"()EF

s"iSP@eLg<LS0eDNTfguH%,)*+"iSP@eLS0eDNTfguH%,)'"CSgD0T"%,'"()E.

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- HE-

7.3. Magic Sets

(64)

•  Thus, we obtain multiple magic predicates for a single adorned predicate occurrence

–  Depending on the creating rule

•  e.g. iSP@eLg/LS0eDNTfg

uH

'"iSP@eLg<LS0eDNTfg

uH

both using

iSP@eLS0eDNTfg

uH

–  Now we need complementary rules connecting the magic predicates

•  Adorned magic predicate follows from special rule magic predicate with same adornment

•  iSP@eLS0eDNTfg

uH

"%&)*+"iSP@eLg/LS0eDNTfg

uH

%&)EF iSP@eLS0eDNTfg

uH

"%&)*+"iSP@eLg<LS0eDNTfg

uH

%&)E

!"#$%&'(&)*+,&'-./,0&1,-+"'-2&'3456&-2+0+7+,&,-8-9#%:);<%#-*+%=&-8->?<%<@@-9<%%&-8-A:A.-8-;B-*C+3",4?$&<(- HF-

7.3. Magic Sets

Referenzen

ÄHNLICHE DOKUMENTE

• The basic building blocks of description logics are concepts, roles and individuals.. – Like with frame systems, think of concepts like OO classes

13.1 Generating ontologies 13.2 Collective Intelligence 13.3 Folksonomies.. 13

topic of question is Godzilla, text contains named entity Godzilla. • Sentence proximity between passage

– Transform

–  Base building blocks are formulas, i.e.. •  When using a variable term in a statement in natural language, you may assign some value. –  ‘something

– Thus, Herbrand interpretation can be defined by listing all atoms from the base which evaluate to true. •  A Herbrand interpretation can identified with a subset of the

•  Proof Sketch: “Show that the consistency of Peano arithmetic directly follows from the Goodstein theorem. If Goodstein was provable within Peano, the consistency of Peano

•  For more expressive logic languages (like Prolog), deductive systems are used to find the truth values for the elements of the Herbrand universe.