• 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!
78
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Wolf-Tilo Balke Philipp Wille

Institut für Informationssysteme

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

Knowledge-Based Systems

and Deductive Databases

(2)

•  Given is a set of formulae !

–  A model of ! is an interpretation "#such that all is an interpretation "#such that all formulas in !#evaluate to true with respect to "

•  If ! has a model, it is called satisfiable has a model, it is called satisfiable

–  If ! has no model, it is called unsatisfiable or has no model, it is called unsatisfiable or inconsistent

–  If two formulas always evaluate to the same truth value given any interpretation ", they are called

semantically equivalent

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

4.0 Last Lecture

(3)

•  If every possible interpretation is a model of !, , the formulas $#in !##are called tautologies

–  Sometimes also called valid –  Denoted by %$

–  Tautologies can be used to provide transformation rules for generating

semantically equivalent formulas

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

4.0 Last Lecture

(4)

•  All first-order logic expressions

– You might think of the negation as mirror operation along the red-dotted line

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

4.0 Last Lecture

SATISFIABLE, but not valid VALID

(tautologies)

UNSATIS- FIABLE

W

1

¬ W

1

W

2

¬ W

2

(5)

•  A formula $#is a semantic conclusion of !&

iff every model of !#is also a model of $'

– !%$###($##semantically follows from !) %$###($##semantically follows from !) )

– Test for !%$( show that #!#)#*+$, is unsatisfiable' %$( show that #!#)#*+$, is unsatisfiable' – Testing unsatisfiability is generally quite difficult due to the

unlimited number of possible interpretations

•  Idea: Herbrand Interpretations

– Herbrand interpretations interpret each constant and each closed formula on mirror of itself

– Purely symbolic interpretations, as such they represent some kind of a worst case scenario

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

4.0 Last Lecture

(6)

•  Clauses are special formulas containing only disjunctions of positive or negative literals

–  Horn clauses contain at most one positive literal

•  Lemma: Given a set of clauses !'

–  !#has a model, if and only if !#has a Herbrand model –  !#is unsatisfiable, if and only if !#has no Herbrand

model

•  Open Question: How can Herbrand

interpretations help evaluating queries in a deductive DB?

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

4.0 Last Lecture

(7)

•  How complex is it to decide if a formula is a tautology or is a satisfiable?

•  How can logics be used to develop computer programs?

–  Which complexity is OK for a computer language?

–  How does logic programming work?

–  What can it do?

–  Example: Datalog

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

4.0 Today‘s mission

(8)

4.1 Complexity of Logic 4.2 The Datalog Language 4.3 Datalog Programs

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

4. Logical Programming

(9)

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

4.1Complexity of Logic

•  The last lectures dealt with basics of first order logics

– We showed how to write syntactically correct logical statements

– We discussed interpretations and models

– We showed how to deduce and to prove statements – We heard some stuff about history of logics

•  So, we get closer to building a deductive DB

– Essentially, a deductive DB will later check if a given

statement can be followed given a set of facts and rules

•  !%$, i.e. !#)#*$,#satisfiable %$, i.e. !#)#*$,#satisfiable

(10)

•  Now, it’s time to have a look at the

computational complexity of logics

–  The check for validity and the check for satisfiability is especially important

–  A database is about performance

–  If it turns out that the anticipated complexity is prohibitive, we are in deep trouble

•  Will some restrictions save the day?

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

4.1Complexity of Logic

(11)

•  First, let‘s have a look on plain Boolean logic

–  i.e. no predicates, no quantifiers, universe is limited to

*-./0&#12340,'

•  e.g $

5

6#7#8#+#7&##$

9

6#:7#8#+;<#=#+7

–  Like first order logic Boolean statements can also be valid, satisfiable, or unsatisfiable

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

4.1Complexity of Logic

SATISFIABLE, but not valid VALID

(tautologies)

UNSATIS-

FIABLE

W

1

W

2

¬ W

2

¬ W

1

(12)

•  So, how do you test whether some Boolean statement $ is satisfiable, valid, or unsatisfiable

–  This is commonly known as the SAT problem –  Unsatisfiable:

•  Check if $ is satisfiable; if not, it is unsatisfiable

–  Valid:

•  Check if ¬$ is unsatisfiable; if not, it is valid

–  Satisfiable:

•  Generate a substitution for all variables in $'

•  Evaluate the substituted expression

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

4.1Complexity of Logic

(13)

•  Unfortunately, SAT is in NP-C

–  Deterministic decidable algorithm

•  Generate all 2

n

substitutions

•  Evaluate substituted expression for each substitution

–  In >:?

9

< each'

•  Overall, in >:?

9

9

?

<'

–  Non-Deterministic semi-decidable algorithm

•  Guess any substitution

•  Evaluate substituted expression in >:?

9

<

•  Continue until you find a working substitution

–  NP is a pretty bad property for an algorithm…

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

4.1Complexity of Logic

(14)

•  Example: Is $ satisfiable?

–  $ 5 @:7#8#+;<#=#+7##'

–  $ 9 @A

::7#8#;#8#B<#=#A

:7#8#+;<#=#:;#8#+B<#=#:B#8#+7<#=#A :+7#8#+;#8#+B<<#'

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

4.1Complexity of Logic

7' ;' $

5

'

C' C' D'

C' 5' D'

5' C' D'

5' 5' D'

7' ;' B' $

9

'

C' C' C' D'

C' C' 5' D'

C' 5' C' D'

C' 5' 5' D'

5' C' C' D'

5' C' 5' D'

5' 5' C' D'

5' 5' 5' D'

(15)

•  Example: Is $ satisfiable?

–  $ 5 @:7#8#+;<#=#+7##'

•  Yes, for 7@;@12340'

–  $ 9 @A

::7#8#;#8#B<#=#A

:7#8#+;<#=#:;#8#+B<#=#:B#8#+7<#=#A :+7#8#+;#8#+B<<#'

•  Nope, unsatisfiable'

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

4.1Complexity of Logic

7' ;' $

5

'

C' C' 5'

C' 5' C'

5' C' C'

5' 5' C'

7' ;' B' $

9

'

C' C' C' C'

C' C' 5' C'

C' 5' C' C'

C' 5' 5' C'

5' C' C' C'

5' C' 5' C'

5' 5' C' C'

5' 5' 5' C'

(16)

•  Example: Is $ satisfiable?

–  You could also try to construct the substitution which satisfies the expression (or show that there is none)

•  For general formulas, this is very difficult to be done automatically

–  $ 9 @A

::7#8#;#8#B<#=#A

:7#8#+;<#=#:;#8#+B<#=#:B#8#+7<#=#A :+7#8#+;#8#+B<<#'

•  One false, one true, all need to be the same? Not possible

→ unsatisfiable'

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

4.1Complexity of Logic

N"&-#:-0?&-6+C<+7%&,-?+,-0#-7&-0C3&-

O%%-0?C&&-"&&'-0#-?+6&-0?&-,+1&-6+%3&-

N"&-?+,-0#-7&-:+%,&-

(17)

•  The default algorithm for solving the SAT problem is the Davis-Putnam algorithm

–  Solves the problem of satisfiability for a Boolean formula in conjunctive normal form

–  Complexity is somewhere around >:5EF ? <G' –  Basic idea: Build a pruned tree of possible

substitutions'

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

4.1Complexity of Logic

P#-Q3""/-R#(<4<+"-S+0T-

(18)

•  There are several variants of the SAT problem:

–  3-SAT: This is the problem for Boolean satisfiability in conjunctive normal form, where each clause

contains at most 3 literals

•  3-SAT was the first problem that was ever shown to be NP-complete

•  Normal SAT reduces polynomially to 3-SAT

–  Horn-SAT: This restricts SAT to formulas in

conjunctive normal form, where each clause is a Horn clause '

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

4.1Complexity of Logic

(19)

•  Horn-SAT is very important as it is in P-complete

–  Example Horn-SAT problem:

•  !(@*:+7

9

#8+7

5

8#7

H

<&#:+7

5

8#+7

9

8#+7

H

#8#+7

I

<&#:7

5

<&#:7

9

<,'

•  This results in (implicative form):

–  Facts: #-./0J#7

5

&#-./0J#7

9

' –  Definites: (7

9

#=#7

5#

J#7

H

<

–  Goals: (7

5

=#7

9

#=#7

H

#=#7

I

#J#12340<'

•  Whole set is satisfiable, if conjunction of implications is true'

–  Idea: find all those variables which have to be -./0 and look for any contradiction!

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

4.1Complexity of Logic

(20)

•  Find all those variables K which have to be -./0!

–  Init K(@L#:i.e. all variables are 12340)

–  Pick any unsatisfied implication M N #(facts or definites)'

•  M

N#

6#:7

5

=#G#=#7

?

#<#J#;'

•  unsatisfied implication: all 7

N

are -./0, ; is 12340'

•  Add ; to K#(thus M

N##

is satisfied now)

•  Repeat until there are no unsatisfied implications

–  !#is satisfiable, iff K#satisfies all clauses

•  Furthermore, K#is the minimal set of variables which

satisfies#!, i.e. for each satisfying substitution KO#holds, KPKO# , i.e. for each satisfying substitution KO#holds, KPKO#

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

4.1Complexity of Logic

75' 79' 75J#79' :+%,&- :+%,&- !"#$- :+%,&- 0C3&- !"#$- 0C3&- :+%,&- :+%,&-

0C3&- 0C3&- !"#$%

(21)

•   Example Horn-SAT problem:

–  M

5#

6:-./0J#7

5

<&#M

9#

6:-./0J#7

9

<&#A

M

H#

6(7

5

=#7

9

#=#7

H

#=#7

I

#J#12340<&#M

I#

6:7

9

#=#7

5#

J#7

H

<'

•   Algorithm

–  :-./0J#7

5

<####' Q####K(@*7

5

,' –  :-./0J#7

9

<####' Q####K(@*7

5

&#7

9

,' –  7

9

#=#7

5#

J#7

H

###' Q####K(@*7

5

&#7

9

&#7

H

,' –  Does K satisfy all clauses?

•  It obviously satisfies M

5

&#M

9

& and M

I'

•  It also satisfies M

H'

•  K#satisfies !#R #R

''

–  If there was also an M

S#

6(7

9

=#7

H

#J#12340<&#!##would be unsatisfiable

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

4.1Complexity of Logic

(22)

•  So, lets switch to general first order logic. What changes with respect to complexity?

–  Universe of potentially unlimited size –  Quantifiers

•  A given sub-formula has to be true for all / some elements of the universe

•  How does this affect our complexity?

–  As an example, we will use the popular axiomatization of the number theory

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

4.1Complexity of Logic

(23)

•   Number theory

–  T

UK

#@#:V&#W&#X&#Y<#@:*C,&#*Z&#[&##\&##]#,&#*@&#^,&#*7&#;&#B,<' –  There is just the constant “0”

•  Interpretation of T

UK

#'

–  Universe contains all natural numbers

–  The Z function represents the successor function

•  i.e. Z:Z:Z:_C`<<<@H'

•  As using the successor function is very unhandy, we employ a shortcut notation for all natural numbers

–  We may, e.g. use 3451 instead of Z:Z:Z:Z:G#Z:C<#G<<<<'

–  This syntactically incorrect as we use the interpretation as a symbol'

–  The functions [&##\&##and ↑ represent addition, multiplication, and exponentiation

–  The predicates @&##and < represent equality and the less-than- predicate

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

4.1Complexity of Logic

(24)

•  So, how can we (naively) evaluate first order logic?

–  Generate all substitutions for quantified sub-formulas and evaluate the main formula

–  a7#:#7#b#S<'

•  7@C; Bang. Untrue.

–  c7#:#7#b#S<'

•  7@Cd#7@5d#7@9d#G#d#7@e; Ok. True.

–  a#7&#;#:Hb7##8#Hb;##8#:7#\#;#b#7#[#;<<'

•  7@C&#;@C#d#7@5&#;@Cd#7@C&#;@5d#7@5&#;@5d#7@9&#;@C&#G So, this seems to be true? Where do we stop?

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

4.1Complexity of Logic

(25)

•  Testing all substitutions for universes with unlimited size is kind of tricky

•  Alternative Idea:

– Use deductive systems to construct a proof from a set of valid axioms to the questionable statement

– Number theory has been axiomized several times on different styles

– Most popular: Peano arithmetic

•  Commonly 15 axiom types inducing countable unlimited number of axioms

•  Introduced by Italian mathematician Giuseppe Peano in 1889

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

4.1Complexity of Logic

(26)

•  But consider this:

–  +c?&#2&#f&#g#::2 ?# [#f ?# @#g ? <#=#?b9<' –  This is Fermats Last Theorem –  It took 357 years to show that this

statement is provable for the natural numbers

•  1637-1995

•  Proof did some

really nasty tricks…

–  So, we seem to be

in severe trouble here…

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

4.1Complexity of Logic

.03@<'%/-,1+%%-1+C(<"-

(27)

•  So, where is the problem?

– Remember Gödel’s Incompleteness Theorem

•  “Any effectively generated theory capable of expressing elementary arithmetic cannot be both consistent and complete. In

particular, for any consistent, effectively generated formal theory that proves certain basic arithmetic truths, there is an arithmetical

statement that is true, but not provable in the theory.”

– Thus, for any non-trivial deductive system NT, there are statements which cannot be proofed within that system

•  Unproofeable statements are called undecidable

•  UK#h#$#(#$#can be proven in the system UK

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

4.1Complexity of Logic

%#$ decidable %#+$

UK#h#$'

decidable UK#h#+$' +$-

$-

undecidable-

(28)

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

4.1Complexity of Logic

(29)

–  …the actual theorem is not important for us. But note that the theorem is indeed expressible and true within the Peano arithmetic

•  i.e. all Goodstein sequences are finite regardless of their start value.

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

4.1Complexity of Logic

(30)

– BUT: Paris-Kirby Theorem:

“The Goodstein Theorem is not decidable.”

•  i.e. there is no way to prove Goodstein within Paeno arithmetic

–  Actually, there is no way to proof it at all using first order logic

•  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 was shown within itself. This is not possible according to Gödel’s

incompleteness theorem.”

•  This is pretty bad. Obviously, we need some restrictions…

– …but first, we move to some algorithms

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

4.1Complexity of Logic

(31)

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

4.1 Herbrand Theorem

•  Jacques Herbrand

–  Born 1908 in Paris, finished his Doctorate degree 1929 at the Sorbonne in Paris

–  In early 1931, he got a fellowship at the university of Berlin, worked there with John von Neumann

–  Later moved to Göttingen to work with Emmy Noether

–  There, started his signature work “On the consistency of arithmetic”

•  Before finishing, died during a hiking trip in the Alps in July 1931 at age 23

Q3""/-R#(<4<+"-S+0-

(32)

•  The Herbrand theorem (1928)

– Informal: “i is a closed formula in universal prenex form. Then i is unsatisfiable if and only if there is a finite subset of its Herbrand expansion which is Boolean unsatisfiable”

•  Note that Herbrand himself messed the proof up, the flaw was discovered in 1960 by Dreben…

•  Today, proving is quite easy if the Compactness theorem is used

•  Universal prenex form:

i#6##a#;

5

&#G&#;

?##

j:;

5

&G&#;

?

< and j being quantifier-free.

– Very important: The problem of first order logics unsatisfiability is transformed to a Boolean

unsatisfiability problem

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

4.1 Herbrand Theorem

(33)

•  Herbrand Theorem (more formally)

– Let i#be in universal prenex form i#6##a#;

5

&#G&#;

?##

j:;

5

&G&#

;

?

< . Then i is unsatisfiable if and only if there is a finite set Ki of ground terms -

Nk

with 1lNlm##and 1lNl? such that Ki#(@*j:-

55

&#G&#-

5?

<&#G&#j:-

m5

&#G&-

m?

<,#is unsatisfiable

•  j:-

N5

&#G&#-

N?

< are called ground instances of i'

•  Set of possible ground instances is potentially of unlimited size (e.g. Herbrand base)

•  The set of all possible ground instances is called Herbrand expansion n:i<#

•  i.e. for a set of terms Ki#holds Ki#Pn:i<#and Ki#finite

– The Herbrand theorem can equivalently be stated for existentially quantified or mixed closed formulas '

•  Transformation rules for ∀ and ∃ (Herbrandization)!

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

4.1 Herbrand Theorem

(34)

•  Some considerations

– Ki can be checked for unsatisfiability in finite time

•  e.g. Davis-Putnam algorithm, etc

– However, it is not known which Ki will show the unsatisfiability

•  There is potentially an unlimited number of Ki#Pn:i<#'

– If you did not find an unsatisfiable Ki yet, this either means

a)  There are none and thus i is satisfiable b)  You have not looked long enough

•  You cannot know which of both are true (reduces to the Halting problem…)

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

4.1 Herbrand Theorem

(35)

•   This lead’s to a simple meta-algorithm for checking unsatisfiability (Gilmore algorithm, 1960)

•   Preparation:

–  Take any first-order-logic formula i'

–  Transform A into universal prenex form iO#(@#a#;

5

&#G&#;

?#

j:;

5

&G&#

;

?

< '

•  i.e. pull all quantifiers to the front and transform to universal quantifiers

–  Be able to generate a the Herbrand expansion n:iO<#@#*i

5

&#i

9

#&#

G,#

•   Gilmore Algorithm

–  m(@5

–  While =

mN@5

#i

N

is satisfiable (or: “while not unsatisfiable”)

•  m[['

–  Return `i#N4#/?42-N4oN2f30`

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

4.1 Herbrand Theorem

(36)

•  Thus, the Gilmore algorithm is semi- decidable

–  Answers only if i is unsatisfiable, else is caught in endless loop

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

4.1 Herbrand Theorem

(37)

•  Restriction 1: Allow only a decidable subset of first order formulas

–  One such subset of first order logics are the so-called Schönfinkel-Bernays expressions:

•  Given a language without functional symbols and without the equality predicate

•  Given expressions in prenex form

$#6#c#7

5

&#G&#7

?

#a#;

5

&#G&#;

?

##$

9

with $

9#

is quantifier free

•  Then it is decidable if $ has a model or not

–  SB-SAT problem

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

4.1Complexity of Logic

(38)

•  Easy proof:

–  Without functional symbols, the Herbrand base is finite

–  If the Herbrand base is finite, the Herbrand expansion is finite

–  If the Herbrand expansion is finite, you can generate all subsets of the expansion in finite time (and which are also finite)

–  Each check for unsatisfiability for a finite set of ground instances is in finite time

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

4.1Complexity of Logic

(39)

•  However, there is a catch: SB-SAT ∈ NEXP-C

– NEXP: The class of all non-deterministic exponential algorithms

– What does that mean:

•  You can only guess the solution AND then you need an

exponential amount of time to check if your guess was correct….

•  >:9

p:?<

< using a non-deterministic Turing machine and unlimited space.

•  Or, you could unfold the problem to an deterministic machine which takes even longer….

– This is obviously a very

very bad complexity class…

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

4.1Complexity of Logic

(40)

•  Additionally, Schönfinkel-Bernays severely restricts the expressiveness of logics

–  No functions!

•  This is even bad in the case where you actually can avoid functions as many predicates could be implemented more efficiently as functions

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

4.1Complexity of Logic

(41)

•   So… how do we solve all this?

–  We need a subset of first order logic which has guaranteed finite Herbrand expansions

–  We should try to find subset which is in a better complexity class than NEXP

–  We should find a subset which does not limit the expressiveness too much

•   Approach: Restrict to first order logics allowing only for Horn clauses and non-recursive typed functions

–  Ground instances are thus Horn clauses

–  Check for unsatisfiability of finite subsets of Herbrand expansion is in P

–  Herbrand expansions is finite as the Herbrand universe is finite

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

4.1Complexity of Logic

(42)

•  Relational databases distinguish between DDL and DML

–  DDL is for creating schemas or views –  DML is for maintaining data and queries

•  Evaluation follows the (tuple) relational calculus

•  In deductive databases both data and queries are specified by formulae

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

4.2 Logic as Data Model

&% '% (%

U- U- U- U-

(43)

•  Every predicate is written by Horn clauses of the form

–  ! #:q 5 ! " #q 9 ! " # "! " #q ? <&###q N ! # ! q T #'

–  With atomic formulae q N and at most one positive literal q k

•  Logic programming introduced a slightly

different notation of Horn clauses for simplicity

–  q k # $ #q 5 ! &# " &#q kr5 &#q k[5 &# "#! q ? E#'

–  That means ‘ $ ’ is understood as implication, ‘ , ’ as conjunction, and ‘ . ‘ denotes the end of a clause

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

4.2 Logic as Data Model

(44)

•  A deductive database consists of facts and rules

–  The set of facts is called extensional database (EDB)

•  If no functions are used in the facts, it can be stored as a simple relational database table

–  The set of rules is called intensional database (IDB)

•  The reflects the idea of views in relational databases, but allows for recursion

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

4.2 Datalog

(45)

•  Datalog is a query and rule language specifically defined for deductive databases

–  Syntactically similar to Prolog

–  Introduced around 1978 for academic database research by Hervé Gallaire and Jack Minker

–  Used as the main foundation for expert systems theory during the 1980ies

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

4.2 Datalog

(46)

•  A database clause (DB-clause) is defined as

–  i# $ #q 5 ! &# "#! q ? E##with an atomic formula i ! # ! i T #and literals q N ! # ! q T #'

•  i#is refered to as head and q

5

! &# "#! q

?

#as body (or body literals) of the DB-clause

•  often written as i#(r#q

5

! &# "#! q

?

–  DB-clauses with ?#b#C#are called rules

–  DB-clauses with ?#@#C#and an atomic ground formula i are called facts

–  A DB-clause with only atomic body literals is called definite

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

4.2 Datalog Syntax

(47)

•  Example facts

–  p2.0?-:stu?&#v2.;<E' –  p2.0?-:stu?&#Kutw24<E' –  p2.0?-:Kutw24&#x0t.y0<E' –  …

•  Example rules

–  y.2?zp2.0?-:{&|<# $ #p2.0?-:{&}<&#p2.0?-:}&|<E#' –  w2.;O4~3t0:{<# $ #p2.0?-:|&#v2.;<&#p2.0?-:|&{<E' –  …

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

4.2 Datalog Syntax

V&#C(&- .#"W+- >&0&C- !+C&"-

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

Y#?"-

(48)

•  The most important feature of Datalog is the possibility to use recursion

– 0zy0:H&9<EA 0zy0:9&e<EA 0zy0:9&S<EA 0zy0:S&H<E'

– p2-u:{&|<# $ #0zy0:{&|<EA

p2-u:{&|<# $ #0zy0:{&}<&#p2-u:}&|<E'

– Alternative ways for writing the last rule are:

p2-u:{&|<# $ #p2-u:{&}<&#0zy0:}&|<E##

or p2-u:{&|<# $ #p2-u:{&}<&#p2-u:}&|<E#'

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

4.2 Datalog Syntax

)%

*% +%

,%

(49)

•  The definition z01:p< of a predicate symbol p is the set of facts/rules in the Datalog program, where p

occurs in the head

– y.2?zwt-u0.:{&|<# $ #p2.0?-:{&}<&#p2.0?-:}&|<&#

' ' ' ' ' #####10w230:|<E#'

– p2-u:{&|<# $ #0zy0:{&|<EA

p2-u:{&|<# $ #0zy0:{&}<&#p2-u:}&|<E'

– If a definition does not at all depend on some variable in a body literal, it is often written as ‘_’ (don’t care)

•  p:{&#|< $ #.:{&#}<&#Ä:|&#}&#~<E

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

4.2 Datalog Syntax

(50)

•  Problem of variables in heads of rules

–  Consider a rule p:{< $ #.:|<E#

– What does it mean?

•  If there is a substitution for | making .:|< true, then p:{< is true for all possible substitutions for {?

•  … if .:|< is true for all possible substitutions of |, then p:{< is true??

•  … or only for |@{???

•  Restriction: In Datalog all variables used in a head predicate always have to occur in some body literal, too

– Similar problem arises, if a constant in the head would depend on varibles in body literals p:2< $ #.:{<E#

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

4.2 Datalog Syntax

(51)

•  A database query is defined as

–  D#q 5 ! &# "#! q ? E##with literals q N ! # ! q T #&#?bC'

•  Alternative notation $ #q

5

! &# "#! q

?

E#or #(r#q

5

! &# "#! q

?

E

–  A query with only atomic literals is called definite –  A definite query with ?@5 is called a Datalog query

•  Why is this a query?

–  A set of DB-clauses !#and a query Å#6#q 5 ! &# "#! q ? #are unsatisfiable, iff !%#+Å# with +Å#6# %#+Å# with +Å#6# % % #:+q #:+q 5 5 ! ! & & " " & & ! ! +q +q ? ? < <

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

4.2 Datalog Syntax

(52)

•  Example database

–  p2.0?-:ktu?&#w2.;<E#p2.0?-:ktu?&#-utw24<E#G' –  10w230:w2.;<E#10w230:4t?k2<E#G#

–  y.2?zwt-u0.:{&|<# $ #p2.0?-:{&}<&#p2.0?-:}&|<&#

' ' ' ' ' #####10w230:|<E#'

•  Example datalog query

–  $ut#N4#stu?O4#y.2?zwt-u0.D' –  #Dy.2?zwt-u0.:ktu?&{<E'

•  y.2?zwt-u0.:ktu?&#4t?k2<E#A y.2?zwt-u0.:ktu?&#m2.0?<E

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

4.2 Datalog Syntax

V&#C(&- .#"W+- >&0&C- !+C&"-

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

Y#?"-

(53)

•  For simplicity often some often used arithmetic predicates like {<, ' , ( , >, =, ) } are predefined for the use in body literals of rules

–  Example:

zNyN-:{< $ ?2-/.23?/wf0.:{<, {# ' #ÇEA

##########4w2330.:{&|<# $ ?/wf0.:{<, ?/wf0.#:|<,#{^#|E'

•  The same holds for simple arithmetic functions like {+, -, *, /}

–  4/w:{&|&#}<# $ #}@{[|'

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

4.2 Datalog Syntax

(54)

•  If predicate symbols defining facts never occur in the head of any rule, a set of DB-clauses is called a Datalog f,neg -program

–  This name follows the idea of logic programming –  There are different kinds of programs…

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

4.3 Datalog Programs

(55)

•  Depending on the use of functions and

negation several Datalog language classes can be distinguished

–  Datalog neg programs do not contain function symbols

–  Datalog f programs (or definite programs) do not contain negative literals

–  Datalog programs contain neither negative literals nor function symbols

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

4.3 Datalog Language Classes

(56)

•  Expressiveness

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

4.3 Datalog Language Classes

-'!'./0 12%3$0%

-'!'./0 1%

-'!'./0 3$0%

-'!'./0 %

(57)

•  Datalog programs can also be distinguished by their dependencies between predicates

– We have seen already that negation in literals may sometimes lead to strange results…

•  Remember: closed world assumption

•  For example

–  All numbers which are not even are odd –  All numbers which are not odd are even

– Idea: find out about the relation between different predicates by examining their respective definitions

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

4.3 Program Classes

(58)

•  The program connection graph (PCG) of some program É consists of

–  Nodes for each predicate symbol p in É'

–  Directed edges from node p to node Ä, if Ä is in the definition of p'

–  An edge is negative, if Ä occurs in a negated literal, otherwise the edge is positive

•  A recursive clique is a maximum subset of the predicates in É, such that between each two

predicate symbols there is a path in the PCG

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

4.3 Program Classes

(59)

•  A program is called hierarchic, if the PCG does not contain cycles

–  If there are cycles the program is called recursive

–  f2gu03t.:{< $ #w230:{<&#+#w2..N0z:{<E#is hierachic

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

4.3 Program Classes

4'.$% 4'""5$6%

('78$./"%

9% :%

(60)

–  p2-u:{&#}< $ #0zy0:{&#|<&#p2-u:|&#}<E###is recursive –  p:{&|< $ #Ä:|&#}<&#4:}<EA

Ä:{&|<# $ #.:|<&#4:{<EA

.:{<# $ #p:{&#{<E#################################is also recursive

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

4.3 Program Classes

$60$%

;'!8%

9%

9%

;% "%

<%

9% 9%

9%

=%

9%

9

(61)

•  A program is called stratified, if cycles in the PCG only consist of positive edges

–  yttzp2-u:{&#|< $ #p2-u:{&#|<&#+#-t33:{<EA

yttzp2-u:{&#}< $ #yttzp2-u:{&#|<&#yttzp2-u:|&#}<EA is a stratified and recursive program#

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

4.3 Program Classes

;'!8%

0//6;'!8%

9%

9%

!/..%

:%

(62)

–  00?:{< $ #?/wf0.:{<&#+#tzz:{<EA tzz:{< $ #?/wf0.:{<&#+#00?:{<EA

is a not stratified and recursive program#

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

4.3 Program Classes

/66%

9%

:%

$>$3%

:%

3#4($"%

9%

(63)

•  A stratification of some program É is a disjoint partitioning É#@#É 5 #Ñ#G#Ñ#É ? of É into program parts (strata) such that

–  The definition of each predicate symbol is a subset of some stratum

–  The definition of a predicate symbol in a positive

body literal of a DB-clause in É N #is part of a É k with klN' –  The definition of a predicate symbol in a negative

body literal of a DB-clause in É N #is part of a P j with k^N'

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

4.3 Stratification

(64)

•  Basic idea: layer the program such that definitions of negatively used predicates are always already given in previous layers

–  This effectively excludes the use of negation within recursion

•  It can be proved that a program is stratified, if and only if it has a stratification

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

4.3 Stratification

(65)

•  Stratification Algorithm

–  Takes a Datalog f,neg program as input and outputs either the stratification or ‘not stratified’

–  Thus, the problem of stratification is syntactically decidable

•  Initialization:

–  jt.#02gu#p.0zNg2-0#4;wft3#p#zt#4-.2-/wÖpÜ#(@#5#

w274-.2-/w#(@#5'

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

4.3 Stratification

(66)

•  Main loop:

–  á0p02-#A

##1t.#02gu#àârg32/40#äN-u#u02z#p.0zNg2-0#p#zt#A

#####1t.#02gu#?0y2-N0#ftz;#3N-0.23#äN-u#p.0zNg2-0#Ä#ztA

##########4-.2-/wÖpÜ#(@#w27:4-.2-/wÖpÜ&#4-.2-/wÖÄÜ[5<A

#####1t.#02gu#pt4N-N0#ftz;#3N-0.23#äN-u#p.0zNg2-0#Ä#zt#A

##########4-.2-/wÖpÜ#(@#w27:4-.2-/wÖpÜ&#4-.2-/wÖÄÜ<A

#####w274-.2-/w#(@#w27:*4-.2-/wÖpÜãp#N4#p.0zNg2-0,<A /?-N3#w274-.2-/w#b#å#p.0zNg2-04#A

#######t.#-u0#4-.2-/w#1/?g-Nt?#f0gtw04#4-2f30'

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

4.3 Stratification

(67)

•  Output:

–  "1#w274-.2-/w#b#å#p.0zNg2-04#A

#####-u0?#.0-/.?#ç?t-#4-.2-NoN0zOA

#####0340#1t.#N#(@#5#-t#w274-.2-/w#ztA

###############É N #(@###)######z01:p<###'

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

4.3 Stratification

p%#%5?!8%=!"'!#4%

(68)

•  Example

–  yttzp2-u:{&#|< $ #p2-u:{&#|<&#+#-t33:{<EA

yttzp2-u:{&#}< $ #yttzp2-u:{&#|<&#yttzp2-u:|&#}<E'

–  Initialization:

4-.2-/wÖyttzp2-uÜ#@#4-.2-/wÖp2-uÜ#@#4-.2-/w Ö-t33Ü#(@#5A

w274-.2-/w#(@#5A

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

4.3 Stratification

(69)

•  Example

–  yttzp2-u:{&#|< $ #p2-u:{&#|<&#+#-t33:{<EA

yttzp2-u:{&#}< $ #yttzp2-u:{&#|<&#yttzp2-u:|&#}<E'

–  First loop (maxstratum = 1):

first rule: 4-.2-/wÖyttzp2-uÜ#(@####A

####w27:4-.2-/wÖyttzp2-uÜ&#4-.2-/wÖp2-uÜ<#@#5A

###################4-.2-/wÖyttzp2-uÜ#(@####A

#####w27:4-.2-/wÖyttzp2-uÜ&#4-.2-/wÖ-t33Ü[5<#@#9A second rule: 4-.2-/wÖyttzp2-uÜ#(@####A

####w27:4-.2-/wÖyttzp2-uÜ&#4-.2-/wÖyttzp2-uÜ<#@#9A w274-.2-/w#(@#4-.2-/wÖyttzp2-uÜ#@#9

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

4.3 Stratification

(70)

•  Example

–  yttzp2-u:{&#|< $ #p2-u:{&#|<&#+#-t33:{<EA

yttzp2-u:{&#}< $ #yttzp2-u:{&#|<&#yttzp2-u:|&#}<E'

–  Second loop (maxstratum = 2):

results in no more changes to the strata and the algorithm terminates with w274-.2-/w#^#H'

–  #Hence the program is stratified and É5#(@#*z01:p2-u<&#z01:-t33<,A

########É9#(@#*z01:yttzp2-u<,'

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

4.3 Stratification

(71)

•  How about a not stratified program?

– 00?:{< $ #?/wf0.:{<&#+#tzz:{<EA tzz:{< $ #?/wf0.:{<&#+#00?:{<E

•  The loop will increase the strata of 00? and tzz until w274-.2-/w#b#å#p.0zNg2-04#:@H<'

– First loop:A

4-.2-/wÖ00?Ü#(@#A

###############w27:4-.2-/wÖ00?Ü&#4-.2-/wÖtzzÜ[5<#:@9<A 4-.2-/wÖtzzÜ#(@#A

################w27:4-.2-/wÖtzzÜ&#4-.2-/wÖ00?Ü[5<#:@H<' – Second loop:

#4-.2-/wÖ00?Ü#(@#A

###############w27:4-.2-/wÖ00?Ü&#4-.2-/wÖtzzÜ[5<#:@I<

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

4.3 Stratification

(72)

•  In this detour, we will show an example implementation of Datalog

–  DES: Datalog Educational System

•  http://des.sourceforge.net

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

4.3 DES

(73)

•  Write some Datalog program in a text file editor

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

4.3 DES

12-u0.:u0..Ngm&#k0??;<E' wt-u0.:zt.-u;&#k0??;<E' 12-u0.:f.2?-&#u0..Ngm<E' wt-u0.:2?y032&#u0..Ngm<E' 12-u0.:3t/N4&#zt.-u;<E' wt-u0.:k/z&#zt.-u;<E' 12-u0.:u/f0.-&#-u0m32<E' wt-u0.:k0??;&#-u0m32<E' p2.0?-:{&#|<#(r#12-u0.:{&#|<E' p2.0?-:{&#|<#(r#wt-u0.:{&#|<E'

2?g04-t.:{&#|&#à<#(r#p2.0?-:{&#|<&#à#N4#5E'

2?g04-t.:{&#|&#à<#(r#2?g04-t.:{&#}&#à5<&#2?g04-t.:}&#|&#à9<&#à#N4#à5#[#à9E'

(74)

•  Load (consult the program) the program

–  gt?4/3- command

–  Filename relative to DES installation directory

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

4.3 DES

(75)

•  Review the program

–  3N4-N?y command

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

4.3 DES

(76)

•  Run some queries

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

4.3 DES

R<,0-+%%-+"4&,0#C,-#:-Y&""/-$<0?-+-- '<,0+"4&-#:-D-Z(C+"'@+C&"0,[-

A,-;?&=%+-+"-+"4&,0#C-#:-Y&""/T-

(77)

•  Add some new rules from the shell

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

4.3 DES

P&$-C3%&-$<0?-2440.--4#11+"'-

9?#-<,-Y&""/\,--

(C+"'1#0?&CT-

(78)

•  Semantics of Datalog

•  Evaluation

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

Next Lecture

Referenzen

ÄHNLICHE DOKUMENTE

– Add to a theory T every fact that can be deduced by using any of the default rules in D, so-called extensions to the theory T. – Repeat until nothing new can

• 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

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

–  On the union of those rules and the previous ground instances, apply normal fixpoint iteration..

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

•  Non-monotonic reasoning considers that sometimes statements considered true, have to be revised in the light of new facts.. –  Tweety is