Logic Programming PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 272
At a glance
Powered by AI
The document provides an introduction to logic programming and its applications including representing structured knowledge, search, language processing, reasoning with incomplete information, default reasoning, abduction, and inductive logic programming.

The London Underground map is represented using logical facts of the form connected(station1, station2, line) to describe the connections between stations on different lines.

Rules are used to derive new information from the logical facts. For example, the rule near(X,Y) :- connected(X,Z,L), connected(Z,Y,L). allows deriving that two stations are near each other if they are connected on the same line with only one station between them.

(Introduction to) Logic Programming

D. Vermeir

September 23, 2009

1 / 259

Preliminaries

Outline
1 2 3 4

Preliminaries Introduction Clausal logic

Language processing Reasoning with Incomplete Information Default Reasoning The Semantics of Negation Abduction Inductive Logic Programming

10

Logic programming
11

Representing structured knowledge Searching graphs Informed search

12 13

6 7

2 / 259

Preliminaries

Organization

Evaluation: 50% project, 50% (closed book) theory exam. Exercise sessions: rst one on Wed. Sep. 30 2009, 15:00-17:00, IG. Book. Copies of transparencies. See website for further information.

3 / 259

Preliminaries

Contents

1 2 3 4 5 6 7 8

Introduction. Clausal logic. Logic programming in Prolog (incl. meta-programming). Representing structured knowledge. Search. Language processing using denite clause grammars. Reasoning using incomplete information (incl. abduction). Inductive logic programming (concept learning).

4 / 259

Introduction

Outline
1 2 3 4

Preliminaries Introduction Clausal logic

Language processing Reasoning with Incomplete Information Default Reasoning The Semantics of Negation Abduction Inductive Logic Programming

10

Logic programming
11

Representing structured knowledge Searching graphs Informed search

12 13

6 7

5 / 259

Introduction

introduction

Peter Flach, Simply Logical: Intelligent Reasoning by Example, Wiley, 1994.


6 / 259

Introduction

logical representation of map


described by a series of logical facts:
connected(bond_street,oxford_circus,central) connected(oxford_circus,tottenham_court_road,central) connected(bond_street,green_park,jubilee) connected(green_park,charing_cross,jubilee) connected(green_park,piccadilly_circus,piccadilly) connected(piccadilly_circus,leicester_square,piccadilly) connected(green_park,oxford_circus,victoria) connected(oxford_circus,piccadilly_circus,bakerloo) connected(piccadilly_circus,charing_cross,bakerloo) connected(tottenham_court_road,leicester_square,northern) connected(leicester_square,charing_cross,northern)

7 / 259

Introduction

derived information
Two stations are near if they are on the same line, with at most one station in between
near(bond_street,oxford_circus) near(oxford_circus,tottenham_court_road) near(bond_street,tottenham_court_road) near(bond_street,green_park) near(green_park,charing_cross) near(bond_street,charing_cross) % etc. (16 formulas)

The same effect can be obtained using 2 rules:


near(X,Y) :- connected(X,Y,L). near(X,Y) :- connected(X,Z,L), connected(Z,Y,L).

8 / 259

Introduction

the meaning of rules

The second rule


near(X,Y) :- connected(X,Z,L), connected(Z,Y,L)

reads: For any values of X , Y , Z and L, X is near Y if X is connected to Z via L, and Z is connected to Y via L. or X , Y , Z , L connected(X , Z , L) connected(Z , Y , L) near (X , Y )

9 / 259

Introduction

queries
?- connected(W,tottenham_court_road,L)

the answer can be found by matching it with facts:


{ W = oxford_circus , L = central} ?- near(tottenham_court_road,W)

match it with the conclusion of near(X,Y) :- connected(X,Y,L) yielding the substitution { X = tottenham_court_road, Y = W } and try to nd an answer to the premises
?- connected(tottenham_court_road,W,L)

giving { W = leicester_square, L = northern } The nal result is


{ X = tottenham_court_road, Y = W = leicester_square, L = northern }

10 / 259

Introduction

solving a query = constructing a proof (tree)


? near(tottenham_court_road,W) near(X,Y) : connected(X,Y,L) { X = tottenham_court_road Y=W } ? connected(tottenham_court_road,W,L) connected(tottenham_court_road, leicester_square,northern

{ W = leicester_square L = northern }

To solve a query ? Q1 , . . . , Qn nd a rule A : B1 , . . . , Bm where A matches Q1 and solve ? B1 , . . . , Bm , Q2 , . . . , Qn Resolution gives a procedural interpretation to logic.

11 / 259

Introduction

proof by refutation
Note: the procedural interpretation = the declarative semantics (e.g. because of looping). The proof technique used is reductio ad absurdum or proof by refutation: assume that the formula (query) is false and deduce a contradiction:
?- near(tottenham_court_road,W)

stands for W near (tottenham_court_road, W ) false or there are no stations near tottenham_court_road

12 / 259

Introduction

recursive rules
reachable(X,Y) :- connected(X,Y,L). reachable(X,Y) :- connected(X,Z,L), reachable(Z,Y). ?- reachable(bond_street,W)
: reachable(bond_street,W) reachable(X,Y) : connected(X,Z,L), reachable(Z,Y) { X = bond_street, Y=W} : connected(bond_stree,Z,L), reachable(Z,W) connected(bond_street,oxford_circus, central) { Z = oxford_circus, L = central } : reachable(oxford_circus,W) reachable(X,Y) : connected(X,Z,L), reachable(Z,Y). { X = oxford_circus, Y = W} : connected(oxford_circus,Z,L), reachable(Z,W) connected(oxford_circus, tottenham_court_road, central) { Z = tottenham_court_road,L=central} : reachable(tottenham_court_road,W) reachable(X,Y) : connected(X,Y,L) { X = tottenham_court_road, Y = W } : connected(tottenham_court_road,W,L) connected(tottenham_court_road, leicester_square,norhtern) { W = leicester_square, L = northern }

13 / 259

Introduction

prolog proof strategy

Prolog uses depth-rst search when nding a proof, backtracking when it fails, until a solution is found or there are no more possibilities. It tries rules and facts in the given order, always trying to resolve the rst subgoal.

14 / 259

Introduction

functors

can be used to represent complex data structures; the term


route(tottenham_court_road, route(leicester_square, noroute) )

represents
route

tottenham_court_road

route

leicester_square

noroute

15 / 259

Introduction

using functors
reachable(X,Y,noroute) :- connected(X,Y,L). reachable(X,Y,route(Z,R)) :connected(X,Z,L), reachable(Z,Y,R). ?- reachable(oxford_circus,charing_cross,R) { R = route(tottenham_court_road, route(leicester_square,noroute))} { R = route(piccadilly_circus,noroute)} { R = route(piccadilly_circus, route(leicester_square,noroute))} route(oxford_circus, route(leicester_square,noroute))

represents a route via .. Note: functors are not evaluated in normal LP.

16 / 259

Introduction

lists
Lists are also represented by a functor . (compare cons). E.g. the list [a,b,c] is represented as .
a .

[]

which can also be written as .(a,.(b,.(c,[]))) We also use [Head | Tail ] where Tail is a list, as a shorthand for
.(Head,Tail)

We can also write e.g. [ First, Second, Third | Rest ]

17 / 259

Introduction

using lists
A route can be represented by a list:
reachable(X,Y,[]) :- connected(X,Y,L). reachable(X,Y,[Z|R]) :connected(X,Z,L), reachable(Z,Y,R). ?- reachable(oxford_circus,charing_cross,R) {R=[tottenham_court_road,leicester_square]} {R=[piccadilly_circus]} {R=[piccadilly_circus,leicester_square]}

To ask from which station we can reach charing_cross via 4 intermediate stations:
?- reachable(X,charing_cross,[A,B,C,D])

18 / 259

Clausal logic

Outline
1 2 3 4

Preliminaries Introduction Clausal logic

Language processing Reasoning with Incomplete Information Default Reasoning The Semantics of Negation Abduction Inductive Logic Programming

10

Logic programming
11

Representing structured knowledge Searching graphs Informed search

12 13

6 7

19 / 259

Clausal logic

clausal logic

Any logic system has a: syntax: which sentences are legal. semantics: the meaning of sentences, i.e. what is the truth value of a sentence. proof theory: how to derive new sentences (theorems) from assumed ones (axioms) by means of inference rules. A logic system is called sound if anything you can prove is true complete if anything that is true can be proven

20 / 259

Clausal logic

propositional clausal logic syntax


Connectives :- if ; or , and clause : head[: body ] head body : [proposition[; proposition] ] : proposition[, proposition]

proposition : atom atom : single word starting with lower case example:
married ; bachelor :- man, adult

Someone is married or a bachelor if he is a man and an adult


21 / 259

Clausal logic

logic program
a program is a nite set of clauses, each terminated by a period; the clauses are to be read conjunctively
woman;man :- human. human :- man. human :- woman.

in traditional logic notation: (human (woman man)) (man human) (woman human) Using A B A B we get (human woman man) (man human) (woman human)
22 / 259

Clausal logic

clause
In general a clause H1 ; . . . ; Hn : B1 , . . . , Bm is equivalent with H1 . . . Hn B1 . . . Bm A clause can also be dened as L1 L2 . . . Ln where each Li is a literal, i.e. Li = Ai or Li = Ai , with Ai a proposition.

23 / 259

Clausal logic

special clauses

An empty head stands for false, an empty body stands for true:
man :- . :- impossible. % usually written as man.

is the same as (true man) (impossible false) i.e. man impossible

24 / 259

Clausal logic

semantics
The Herbrand base BP of a program P is the set of all atoms occurring in P. A Herbrand interpretation of P is a mapping i : BP {true, false} We will represent i by I = i 1 (true), the set of true propositions. An interpretation is a model for a clause if the clause is true under the interpretation, i.e. if either the head is true or the body is false. An interpretation is a model for a program if it is a model for each clause in the program.

25 / 259

Clausal logic

example
Consider P:
woman;man :- human. human :- man. human :- woman.

Then: BP = {woman, man, human} and a possible interpretation is i = {(woman, true), (man, false), (human, true)} or I = {woman, human} All clauses in P are true under I so it is a model of P. The interpretation J = {woman} is not a model of P.
26 / 259

Clausal logic

logical consequence
A clause C is a logical consequence of a program P, denoted P |= C if every model of P is also a model of C. E.g. for P:
woman. woman;man :- human. human :- man. human :- woman.

we have that P |= human. Note that P has two models: M1 = {woman, human} M2 = {woman, man, human} Intuitively, M1 is preferred since it only accepts what must be true.
27 / 259

Clausal logic

minimal models
Thus we could dene the best model to be the minimal one. However, consider P :
woman;man :- human. human.

P has 3 models M1 = {woman, human} M2 = {man, human} M3 = {woman, man, human} and M1 and M2 are both minimal! If we restrict (as in Prolog) to denite clauses, which have at most one atom in the head, then:

Theorem
A denite logic program has a unique minimal model.
28 / 259

Clausal logic

proof theory
How to compute logical consequences without checking all the models?

Use resolution as an inference rule.


married;bachelor :- man,adult. has_wife :- man,married.
has_wife:man,married married;bachelor:man,adult

has_wife;bachelor:man,adult

Using resolution, we get


has_wife;bachelor :- man,adult.

which is a logical consequence of the program.

29 / 259

Clausal logic

resolution: intuition
married;bachelor :- man,adult. has_wife :- man,married.

man adult married bachelor man married has_wife

either married and then man has_wife or married and then man adult bachelor thus man adult bachelor man has_wife
has_wife;bachelor :- man,adult.

30 / 259

Clausal logic

resolution in traditional notation

E1 E2 E2 E3 E1 E3

31 / 259

Clausal logic

special case: modus ponens

A AB B In clause notation: A A B B

32 / 259

Clausal logic

special case: modus tollens

B AB A In clause notation B A B A

33 / 259

Clausal logic

resolution with denite clauses


square :- rectangle, equal_sides. rectangle :- parallelogram, right_angles.
square:rectangle,equal_sides rectangle:parallelogram,right_angles square:equal_sides,parallelogram,right_angles resolvent

The resolvent can be used in further resolution steps...

Denition
A proof or derivation of a clause C from a program P is a sequence of clauses C0 , . . . , Cn = C such that i = 0 . . . n : either Ci P or Ci is the resolvent of Ci1 and Ci2 (i1 < i, i2 < i). We write P C if there is a proof of C from P.
34 / 259

Clausal logic

soundness, completeness
Theorem
Resolution is sound for propositional clausal logic, i.e. if P P |= C. About completeness: P |= C iff each model of P is a model of C iff no model of P is a model of C If C L1 L2 . . . Ln then C then

(1)

C L1 L2 . . . Ln {L1 , L2 , . . . , Ln } i.e. C is a set of clauses and so (1) P C has no model iff P C is inconsistent (by denition)
35 / 259

Clausal logic

completeness
Theorem
If Q is inconsistent then Q where . is the empty clause (true false) which has no model.

Theorem
Resolution is complete for propositional clausal logic, i.e. if P |= C then P C I.e. C is a logical consequence of P iff one can derive, using resolution, the empty clause ( ) from P C.
36 / 259

Clausal logic

Example: consider P2
happy :- has_friends. friendly :- happy.

We show that P2 |= C where C is


friendly :- has_ friends

P2 C is
happy :- has_friends. friendly :- happy. has_friends. :- friendly. (1) (2) (3) (4)

The proof:
(2+4) :- happy (1+5) :- has_friends (3+6) <empty-clause> (5) (6)

37 / 259

Clausal logic

relational clausal logic


Add individual constants and variables; the syntax has the same connectives as in the propositional case. constant : single word starting with lower case

variable : single word starting with upper case term : constant | variable predicate : single word starting with lower case atom : predicate[(term[, term] )] clause : head[: body ] head body : [atom[; atom] ] : atom[, atom]

likes(peter,S) :- student_of(S,peter)

for any S: if S is a student of peter then peter likes S


38 / 259

Clausal logic

arity, ground term, semantics


A predicate has an arity to denote the number of arguments. E.g. likes/2. In Prolog, p/2 is different from p/3. A term (atom) is ground if it does not contain any variables. semantics: The Herbrand universe of a program P is the set of all ground terms occurring in it. The Herbrand base BP of P is the set of all ground atoms that can be constructed using predicates in P and arguments in the Herbrand universe of P. A Herbrand interpretation is a subset I BP of ground atoms that are true.

39 / 259

Clausal logic

Consider P3
likes(peter,S) :- student_of(S,peter). % C1 student_of(maria,peter).

BP3 =
{ likes(peter,peter), likes(peter,maria), likes(maria,peter), likes(maria,maria), student_of(peter,peter), student_of(peter,maria), student_of(maria,peter), student_of(maria,maria) }

An interpretation I3 ={likes(peter,maria), student_of(maria,peter)}

Denition
A substitution is a mapping : Var Trm. For a clause C, the result of on C, denoted C is obtained by replacing all occurrences of X Var in C by (X ). C is an instance of C. If = {S/maria} then C1 is
likes(peter,maria) :- student_of(maria,peter).
40 / 259

Clausal logic

semantics
Denition
A ground instance of a clause C is the result C of some substitution such that C contains but ground atoms. Ground clauses are like propositional clauses.

Denition
An interpretation I is a model of a clause C iff it is a model of every ground instance of C. An interpretation is a model of a program P iff it is a model of each clause C P. All ground instances of clauses in P3 :
likes(peter,peter) :- student_of(peter,peter). likes(peter,maria) :- student_of(maria,peter). student_of(maria,peter).

Thus M3 = {likes(peter,maria), student_of(maria,peter)} is a model of P3 .


41 / 259

Clausal logic

proof theory
Naive version: do (propositional) resolution with all ground instances of clauses in P.

Denition
A substitution is a unier of two atoms a1 and a2 iff a1 = a2 . A substitution 1 is more general than 2 if 2 = 1 for some substitution . A unier of a1 and a2 is a most general unier (mgu) of a1 and a2 iff it is more general than any other unier of a1 and a2 .

Theorem
If two atoms are uniable then they their mgu is unique up to renaming.

42 / 259

Clausal logic

proof theory using mgu: example

likes(peter,S):student_of(S,peter) student_of(X,T):follows(X,C), teaches(T,C) {S/maria,T/peter,X/maria} likes(peter,maria):follows(maria,C),teaches(peter,C)

43 / 259

Clausal logic

proof theory using mgu


Do resolution on many clause-instances at once. If C1 = L1 . . . L11 n 1 C2 = L2 . . . L22 n 1 L1 = L2 i j for some 1 i n1 , 1 j n2

where = mgu(L1 , L2 ), then i j L1 . . . L1 L1 . . . L11 L2 . . . L2 L2 . . . L22 n n 1 i1 i+1 1 j1 j+1

44 / 259

Clausal logic

proof theory example


Consider P4 :
likes(peter,S) :- student_of(S,peter). student_of(S,T) :- follows(S,C), teaches(T,C). teaches(peter,logicpr). follows(maria,logicpr).

is there anyone whom peter likes (query) add peter likes nobody ( :- likes(peter,N))
:likes(peter,N) likes(peter,S):student_of(S,peter) {S/N} :student_of(N,peter) {S/N,T/peter} student_of(S,T):follows(S,C), teaches(T,C)

:follows(N,C),teaches(peter,C) follows(maria,logicpr) {N/maria,C/logicpr} :teaches(peter,logicpr) teaches(peter,logicpr)

Thus (:- likes(peter,N)){N/maria} P4 P4 |= likes(peter,maria)

and thus

45 / 259

Clausal logic

soundness, completeness
Theorem
Relational clausal logic is sound and (refutation) complete: P C P |= C

P {C} inconsistent P {C} New formulation is because: (X p(X )) X p(X ) but p(X). X p(X ) while :- p(X). X p(X )

46 / 259

Clausal logic

decidability relational clausal logic

Theorem
The question P |= C is decidable for relational clausal logic Because the Herbrand base is nite.

47 / 259

Clausal logic

full clausal logic


Add function symbols (functors), with an arity; constants are 0-ary functors. functor : single word starting with lower case variable : single word starting with upper case term : variable | functor [(term[, term] )] predicate : single word starting with lower case atom : predicate[(term[, term] )] clause : head[: body ] head body : [atom[; atom] ] : atom[, atom]

plus(0,X,X). plus(s(X),Y,s(Z)) :- plus(X,Y,Z). % read s(X) as successor of X


48 / 259

Clausal logic

semantics

As for relational case; models may be (necessarily) innite as in P5 :


plus(0,X,X). plus(s(X),Y,s(Z)) :- plus(X,Y,Z).

M5 =
{ plus(0,0,0), plus(s(0),0,s(0), plus(s(s(0)),0,s(s(0)), ... plus(0,s(0),s(0)), plus(s(0),s(0),s(s(0))), ... ... }

49 / 259

Clausal logic

computing the mgu


Denition
A set of equations {si = ti | i = 1 . . . n} between terms is in solved form if 1 i n si Var 1 i n ti does not contain any variable from {si | 1 i n} A set of equations {Xi = ti } represents a substitution {Xi /ti }.

Theorem
if solve({t1 = t2 }) succeeds, it returns mgu(t1 , t2 ).

50 / 259

Clausal logic

proc solve(var E

: set of equations)

repeat select s = t E case s = t of f (s1 , . . . , sn ) = f (t1 , . . . , tn ) (n 0) : replace s = t by {s1 = t1 , . . . , sn = tn } f (s1 , . . . , sm ) = g(t1 , . . . , tn ) (f /m = g/n) : fail X =X : remove X = X from E t = X (t Var) : replace t = X by X = t X = t (X Var X = t X occurs more than once in E) : if X occurs in t then fail else replace all occurrences of X in E (except in X = t) by t esac until no change
51 / 259

Clausal logic

examples
{f (X , g(Y )) = f (g(Z ), Z )} {X = g(Z ), g(Y ) = Z } {X = g(Z ), Z = g(Y )} {X = g(g(Y )), Z = g(Y )} {X /g(g(Y )), Z /g(Y )} {f (X , g(X ), b) = f (a, g(Z ), Z )} {X = a, g(X ) = g(Z ), b = Z } {X = a, X = Z , b = Z } {X = a, a = Z , b = Z } {X = a, Z = a, b = Z } {X = a, Z = a, b = a}

fail

52 / 259

Clausal logic

occur check

{l(Y , Y ) = l(X , f (X ))} {Y = X , Y = f (X )} {Y = X , X = f (X )} fail The last example illustrates the need for the occur check (which is not done in most Prolog implementations)

53 / 259

Clausal logic

soundness, completeness
Theorem
Full clausal logic is sound and (refutation) complete: P C P |= C

P {C} inconsistent P {C} However the question P |= C is only semi-decidable, i.e. there is no algorithm that will always answer the question (with yes or no) in nite time; but there is an algorithm that, if P |= C, will answer yes in nite time but this algorithm may loop if P |= C. This means that prolog may loop on certain queries.

54 / 259

Clausal logic

denite clause logic


married(X);bachelor(X) :- man(X), adult(X). man(peter). adult(peter). :- married(maria). :- bachelor(maria). man(paul). :- bachelor(paul).
married(X);bachelor(X):man(X),adult(X) {X/peter} married(peter);bachelor(peter):adult(peter) married(peter);bachelor(peter) right .. left :married(maria) married(X);bachelor(X):man(X),adult(X) {X/maria} bachelor(maria):man(maria),adult(maria) :man(maria),adult(maria) :bachelor(maria) man(peter) adult(peter)

left..right

married(X);bachelor(X):man(X),adult(X) {X/paul} married(paul);bachelor(paul):adult(paul) married(paul):adult(paul) both

man(paul) :bachelor(paul)

55 / 259

Clausal logic

For efciency reasons: restriction to denite clauses where the head contains at most 1 atom. A : B1 , . . . , Bn prove A by proving each of B1 , . . . , Bn . This is the procedural interpretation of denite clauses. It makes the search for a refutation much more efcient. Problem: how to represent
married(X);bachelor(X) :- man(X), adult(X).

To prove married(X): show man(X), adult(X) and not bachelor(X) .

56 / 259

Clausal logic

general clauses
A (pseudo-denite) general clause may contain negations in the body:
married(X) :- man(X), adult(X), not(bachelor(X)).

With man(jim). adult(jim). this will have


{ married(jim), adult(jim), man(jim) }

as a minimal model. Alternatively:


bachelor(X) :- man(X), adult(X), not(married(X)).

has, with man(jim). adult(jim). ,


{ bachelor(jim), adult(jim), man(jim) }

as a minimal model.

57 / 259

Clausal logic

clausal logic vs. predicate logic


Every set of clauses can be rewritten as an equivalent sentence in rst order (predicate) logic. Example:
married;bachelor :- man,adult. haswife :- married

becomes (man adult married bachelor ) (married haswife) or, using A B A B and (A B) A B: (man adult married bachelor ) (married haswife) which is in conjunctive normal form (a conjunction of disjunctions of literals).
58 / 259

Clausal logic

Variables in clauses are universally quantied:


reachable(X,Y,route(Z,R)):- connected(X,Z,L), reachable(Z,Y,R).

becomes X Y Z RL : connected(X , Z , L) reachable(Z , Y , R) reachable(X , Y , route(Z , R)) Note that nonempty(X) :- contains(X,Y). becomes X Y : nonempty (X ) contains(X , Y ) X : (Y : nonempty (X ) contains(X , Y )) X : (nonempty (X ) (Y : contains(X , Y ))) X : nonempty (X ) (Y : contains(X , Y )) X : (Y : contains(X , Y )) nonempty (X )

For each rst order sentence, there exists an almost equivalent set of clauses.
59 / 259

Clausal logic

algorithm
X [brick (X ) (Y [on(X , Y ) pyramid(Y )] Y [on(X , Y ) on(Y , X )] Y [brick (Y ) equal(X , Y )])] Step 1: eliminate using A B A B. X [brick (X ) (Y [on(X , Y ) pyramid(Y )] Y [on(X , Y ) on(Y , X )] Y [(brick (Y )) equal(X , Y )])] Step 2: move inside using (A B) A B (A B) A B (A) A X [p(X )] X [p(X )] (X [p(X )] X [p(X )]
60 / 259

Clausal logic

X [brick (X ) (Y [on(X , Y ) pyramid(Y )] Y [on(X , Y ) on(Y , X )] Y [brick (Y ) equal(X , Y )])] Step 3: replace using skolem functors E.g. X Y : likes(X , Y ) becomes X : likes(X , f (X )) where f is a new Skolem functor. All universally quantied variables in whose scope occurs become arguments of the Skolem term. E.g. X : likes(peter , X ) becomes likes(peter , g). In clausal logic, one is forced to use abstract names (using functors) for existentially quantied individuals.

61 / 259

Clausal logic

In example: X [brick (X ) (Y [on(X , Y ) pyramid(Y )] Y [on(X , Y ) on(Y , X )] Y [brick (Y ) equal(X , Y )])] becomes X [brick (X ) ([on(X , sup(X )) pyramid(sup(X ))] Y [on(X , Y ) on(Y , X )] Y [brick (Y ) equal(X , Y )])] Step 4: rename variables (make unique) X [brick (X ) ([on(X , sup(X )) pyramid(sup(X ))] Y [on(X , Y ) on(Y , X )] Z [brick (Z ) equal(X , Z )])]
62 / 259

Clausal logic

X [brick (X ) ([on(X , sup(X )) pyramid(sup(X ))] Y [on(X , Y ) on(Y , X )] Z [brick (Z ) equal(X , Z )])] Step 5: bring to front X Y Z [brick (X ) ([on(X , sup(X )) pyramid(sup(X ))] [on(X , Y ) on(Y , X )] [brick (Z ) equal(X , Z )])]

63 / 259

Clausal logic

Step 6
: bring inside using A (B C) (A B) (A C) X Y Z [brick (X )([on(X , sup(X )) pyramid(sup(X ))] [on(X , Y ) on(Y , X )][brick (Z ) equal(X , Z )])] becomes X Y Z [brick (X ) ([on(X , sup(X ))pyramid(sup(X ))] [brick (X ) on(X , Y ) on(Y , X )] [brick (X ) brick (Z ) equal(X , Z )])] X Y Z [brick (X ) on(X , sup(X ))] [brick (X ) pyramid(sup(X ))] [brick (X ) on(X , Y ) on(Y , X )] [brick (X ) brick (Z ) equal(X , Z )])]
64 / 259

Clausal logic

Step 7
: eliminate by splitting X [brick (X ) on(X , sup(X ))] X [brick (X ) pyramid(sup(X ))] X Y [brick (X ) on(X , Y ) on(Y , X )] X Z [brick (X ) brick (Z ) equal(X , Z )])] Step 8: rename variables (make unique) X [brick (X ) on(X , sup(X ))] W [brick (W ) pyramid(sup(W ))] UY [brick (U) on(U, Y ) on(Y , U)] V Z [brick (V ) brick (Z ) equal(V , Z )])] Step 9: make clauses
on(X,sup(X)) :- brick(X). :- brick(W), pyramid(sup(W)). :- brick(U), on(U,Y), on(Y,U). brick(Z) :- brick(V), equal(V,Z).
65 / 259

Clausal logic

denite clause programs are universal


Denite clause programs are as powerful as any other programming language:

Theorem
Let f be an n-ary partial recursive function. There exists a denite clause program Pf and an n + 1-ary predicate symbol pf such that the query : pf (sk1 (0), . . . , skn (0), X ) returns {X /sk (0)} iff f (k1 , . . . , kn ) = k

66 / 259

Logic programming

Outline
1 2 3 4

Preliminaries Introduction Clausal logic

Language processing Reasoning with Incomplete Information Default Reasoning The Semantics of Negation Abduction Inductive Logic Programming

10

Logic programming
11

Representing structured knowledge Searching graphs Informed search

12 13

6 7

67 / 259

Logic programming

logic programming

sentences in clausal logic: have a declarative meaning (e.g. order of atoms in the body is irrelevant) have a procedural meaning Thus clausal logic can be used as a programming language:
1

write down knowledge in a (declarative) program that species what the problem is rather than how it should be solved apply inference rules to nd solution algorithm = logic + control

68 / 259

Logic programming

algorithm = logic + control

where logic is declarative knowledge and control is procedural knowledge Prolog is not a purely declarative language since e.g. the order of the rules matters. Prologs proof procedure is based on resolution refutation in denite clause logic where a resolution strategy is xed: which literal to resolve upon which clause to resolve with

69 / 259

Logic programming

sld refutation
grandfather(X,Z) :- father(X,Y), parent(Y,Z). parent(X,Y) :- father(X,Y). parent(X,Y) :- mother(X,Y). father(a,b). mother(b,c).
:grandfather(a,X) goal (query) grandfather(C,D):father(C,E),parent(E,D). {C/a,D/X} :father(a,E),parent(E,X). derived goal father(a,b). {E/b} :parent(b,X). parent(U,V):mother(U,V). {U/b,V/X} :mother(b,X). mother(b,c). computed substitution {X/c} {X/c,C/a,D/c,E/b,U/b,V/c} computed answer substitution

70 / 259

Logic programming

SLD

Always resolve with (derived) goal: Linear proof trees. Use Selection rule to determine literal in goal to resolve with. Programs with Denite clauses only. Prologs selection rule: Consider goal literals left to right. (Try clauses in order of occurrence in program) SLD tree: shows (only) alternative resolvents

71 / 259

Logic programming

SLD trees
:grandfather(a,X) :father(a,E),parent(E,X) :parent(b,X) :father(b,X) blocked :mother(b,X)

Every leaf corresponds to a successful refutation ( a success branch). A blocked leaf corresponds to a failed branch. Prolog does a depth-rst traversal of an SLD tree. What if an SLD tree has innite branches?

72 / 259

Logic programming

innite sld trees


sibling(X,Y) :- sibling(Y,X). sibling(b,a).
:sibling(a,X) :sibling(X,a) :sibling(a,X) :sibling(X,a) ...

sibling(a,b). sibling(b,c). sibling(X,Y) :- sibling(X,Z), sibling(Z,Y).


:sibling(a,X) :sibling(a,Z),sibling(Z,Y) :sibling(b,Y) :sibling(a,U),sibling(U,Z), sibling(Z,Y) ... :sibling(a,Z),sibling(Z,Y) ...
73 / 259

Logic programming

problems with SLD resolution

Get trapped in innite subtree: thus Prolog is incomplete. We could do e.g. breadth-rst search but Prolog sacrices completeness for efciency (also in memory usage). Any innite SLD tree may cause the interpreter to loop if no (more) answers are to be found: this is because clausal logic is only semi-decidable. Thus one should be aware of the Prolog strategy (procedural knowledge), e.g. recursive clauses after non-recursive ones be careful with symmetric predicates: p(X,Y) :- p(Y,X)

74 / 259

Logic programming

pruning with cut


parent(X,Y) :- father(X,Y), !. parent(X,Y) :- mother(X,Y). father(a,b). mother(b,c).
:parent(a,X) :father(a,X),! :! :mother(a,X)

The meaning of cut (!): dont try alternatives for the literals to the left of the cut the clause in which the cut is found (A cut is always true.)
75 / 259

Logic programming

red & green cuts


parent(X,Y) :- father(X,Y), !. parent(X,Y) :- mother(X,Y). father(a,b). father(a,c). mother(m,b). mother(m,c).
:parent(a,X) :father(a,X),! :! :! :mother(a,X)

A green cut does not cut away any success branches. A red cut does, making the procedural meaning of the program different from the declarative meaning.
76 / 259

Logic programming

the dangers of !

max(M,N,M) :- M>=N. max(M,N,N) :- M=<N.

More efcient using a red cut:


max(M,N,M) :- M>=N,!. max(M,N,N).

77 / 259

Logic programming

the dangers of !

max(M,N,M) :- M>=N. max(M,N,N) :- M=<N.

More efcient using a red cut:


max(M,N,M) :- M>=N,!. max(M,N,N).

This is not equivalent! (try max(5,3,3) ). The program would be correct if only queries of the form
max(a,b,X)

were asked.

78 / 259

Logic programming

negation as failure
Cut can be used to ensure that the bodies of clauses are mutually exclusive.
p :- q,!,r. p :- s. % only if q fails

is equivalent to
p :- q, r. p :- not_q,s. not_q :- q,!,fail. not_q.

where fail is always false. More general: meta-predicate not/1 implementing negation by failure.
not(Goal) :- Goal,!,fail. not(Goal).

79 / 259

Logic programming

naf examples
p :- q, r. p :- not(q), s. s. % not(q) :- q,!,fail. % not(q).

:p :q,r :not(q),s.

:q,!,fail,s

:s

80 / 259

Logic programming

naf examples
p :- q,!,r. p :- s. s. % more efficient but less clear

:p :q,!,r :s

81 / 259

Logic programming

naf examples
p :- not(q), r. p :- q. q. r. % not(q) :- q,!,fail. % not(q).
:p :not(q),r :q

:q,!,fail,r

:r

:!,fail,r

:fail,r
82 / 259

Logic programming

oundering
occurs when the argument of not/1 is not grounded.
bachelor(X) :- not(married(X)), man(X). man(fred). man(peter). married(peter).
:bachelor(X)

:not(married(X)),man(X)

:married(X),!,fail,man(X)

man(X)

:!,fail,man(peter)

:fail,man(peter)

X is not a bachelor if anyone is married,..


83 / 259

Logic programming

sldnf resolution
SLDNF resolution says that not(Goal) fails only if Goal has a refutation with an empty answer substitution (in the example: if married(X).). Prolog does not check this; hence Prolog is not sound w.r.t. negation by failure. If Goal is ground, only empty answer substitutions are possible... The example can be xed by changing the order of the body of the rule:
bachelor(X) :- man(X), not(married(X)).

You can also read the original as X (Y : married(Y )) man(X ) bachelor (X )

84 / 259

Logic programming

if .. then .. else ..
p:- q,r,s,!,t. p:- q,r,u. q. r. u. q

, r are evaluated twice.

p :- q,r,if_then_else(s,t,u). if_then_else(S,T,U):- S,!,T. if_then_else(S,T,U):- U.

In most prologs:
diagnosis(P,C):- % C: condition, P: patient temperature(P,T), (T=<37 -> blood_pressure(P,C) ;T>37,T<38 -> Condition = ok ;otherwise -> fever(P,C) ).
85 / 259

Logic programming

tail recursion and !

play(Board,Player):lost(Board,Player). play(Board,Player):find_move(Board,Player,Move), make_move(Board,Move,NewBoard), next_player(Player,Next),!, play(NewBoard,Next).

Cut ensures that no previous moves are reconsidered and optimizes tail recursion to iteration.

86 / 259

Logic programming

arithmetic in prolog
nat(0). nat(s(X)):- nat(X). add(0,X,X). add(s(X),Y,s(Z)):- add(X,Y,Z). mul(0,X,0). mul(s(X),Y,Z):mul(X,Y,Z1), add(Y,Z1,Z).

Not efcient!
is(Result,expression) is true iff expression can be evaluated as an expression and its resulting value unied with Result ?- X X ?- X X is 5+7-3 = 9 is 5*3+7/2 = 18.5

87 / 259

Logic programming

is/2 is different from =/2 ; the latter succeeds if its arguments can be unied. ?- X = 5+7-3 X = 5+7-3 ?- 9 = 5+7-3 no ?- X = Y+3 X = _947+3 Y = _947 ?- X = f(X) X = f(f(f(f(f(f(f(f(f(f(f(f(f(f(f( .. error: term being written is too deep

The last example illustrates that Prolog does not implement the occur check. Prolog also has other built-in arithmetic predicates: <,>,=<,>=. \=/2 succeeds if its arguments are not uniable.

88 / 259

Logic programming

accumulators
Tail-recursive clauses are more efcient.
length([],0). length([H|T],N) :length(T,N1), N is N1+1.

The program is not tail-recursive. It can be made tail-recursive by introducing an accumulator: Read length_acc(L,M,N) as N = M + length(L).
length(L,N) :- length_acc(L,0,N). length_acc([],N,N). length_acc([H|T],N0,N) :% N0 is "length so far" N1 is N0+1, length_acc(T,N1,N).

89 / 259

Logic programming

reverse/2

naive_reverse([],[]). naive_reverse([H|T],R) :naive_reverse(T,R1), append(R1,[H],R). append([],Y,Y). append([H|T],Y,[H|Z]) :append(T,Y,Z).

90 / 259

Logic programming

efcient reverse using accumulator


Dene reverse(X , Y , Z ) Z = reverse(X ) + Y Then: reverse(X , [], Z ) Z = reverse(X ) reverse([H|T ], Y , Z ) Z = reverse([H|T ]) + Y Z = reverse(T ) + [H] + Y Z = reverse(T ) + [H|Y ] reverse(T , [H|Y ], Z )
reverse(X,Z) :- reverse(X,[],Z). reverse([],Z,Z). reverse([H|T],Y,Z) :% Y is "reversed so far" reverse(T,[H|Y],Z).
91 / 259

Logic programming

difference lists

X XY
Represent a list by a term L1-L2. [a,b,c,d]-[d] [a,b,c] [a,b,c,1,2]-[1,2] [a,b,c] [a,b,c|X]-X [a,b,c]

92 / 259

Logic programming

difference lists
reverse(X , Y , Z ) Z = reverse(X ) + Y reverse(X ) = Z Y and reverse([H|T ], Y , Z ) Z = reverse([H|T ]) + Y Z = reverse(T ) + [H|Y ] reverse(T ) = Z [H|Y ]

reverse(X,Z) :- reverse_dl(X,Z-[]). reverse_dl([],Z-Z). reverse_dl([H|T],Z-Y) :reverse_dl(T,Z-[H|Y]).


93 / 259

Logic programming

appending difference lists


Difference lists can be appended in constant time:

X Z + XZ ZY = XY Y

append(XZ , ZY, XY)

94 / 259

Logic programming

difference lists example

append_dl(X-Z, Z-Y, X-Y). :- append_dl([abc|A] - A, [de|B] - B, D) % unify with append_dl(X-Z, Z-Y, X-Y) X = [abc|A] Z = A = [de|B] Y = B D = X - Y = [abc|A] - B = [abcde|B] - B

95 / 259

Logic programming

example: atten/2
atomic/1

succeeds if its argument is a simple constant.

flatten([X|Xs],Y) :flatten(X,Y1), flatten(Xs,Y2), append(Y1,Y2,Y). flatten(X,[X]) :- atomic(X), X\=[]. flatten([],[]).

with difference lists:


flatten(X,Y) :- flatten_dl(X,Y-[]). flatten_dl([X|Xs],Y-Z) :- % append flat(X), flat(Xs) flatten_dl(X,Y-Y1), flatten_dl(Xs,Y1-Z). flatten_dl(X,[X|Xs]-Xs) :atomic(X), X\=[]. flatten_dl([],U-U).

96 / 259

Logic programming

other incomplete data structures

lookup(Key,[(Key,Value)|Dict],Value). lookup(Key,[(Key1,Value1)|Dict],Value) :Key \= Key1, lookup(Key,Dict,Value).

Example: suppose D = [(a,b),(c,d)|X]


?- lookup(a,D,V) V = b ?- lookup(c,D,e) no ?- lookup(e,D,f) yes % D = [(a,b),(c,d),(e,f)|X]

97 / 259

Logic programming

second order predicates


map(R,[],[]). map(R,[X|Xs],[Y|Ys]):R(X,Y), map(R,Xs,Ys). ?-map(parent,[a,b,c],X)

Most systems do not allow R(X,Y) in the body. Term=..List is true iff
Term Term

is a constant and List is the list [Term]

is a compound term f(A1,..,An) and List is a list with head f and whose tail unies with [A1,..,An]
map(R,[],[]). map(R,[X|Xs],[Y|Ys]):Goal =.. [R,X,Y], call(Goal), map(R,Xs,Ys).

98 / 259

Logic programming

ndall/3
is true iff Bag unies with the list of values to which a variable X not occurring in Term or Goal would be bound by successive resatisfactions of (call(Goal), X=Term) after systematic replacement of all variables in X by new variables.
findall(Term,Goal,Bag) parent(a,b). parent(a,c). parent(a,d). parent(e,f). parent(e,g). children(Parent,Children):findall(C,parent(Parent,C),Children). ?-children(a,Children) Children = [b,c,d]

99 / 259

Logic programming

bagof/3, setof/3
parent(a,b). parent(a,c). parent(e,f). parent(e,g). ?-bagof(C,parent(P,C),L) C = _951 P = a L = [b,c,d] ; C = _951 P = e L = [f,g] ?-bagof(C,P^parent(P,C),L) C = _957 P = _958 L = [b,c,d,f,g] (P ^ parent(P,C)) setof/3 parent(a,d).

reads like P : parent(P, C) is like bagof/3 with duplicates removed.


100 / 259

Logic programming

assert/1, retract/1
Variables in Prolog are local to the clause. Global variables can be simulated using:
asserta(Clause)

adds Clause at the beginning of the Prolog adds Clause at the end of the Prolog database.

database.
assertz(Clause) retract(Clause)

removes rst clause that unies with Clause from the Prolog database.

Note that backtracking does not undo the modications.


% retract all clauses whose head unifies with Term retractall(Term):retract(Term), fail. retractall(Term):retract((Term:- Body)), fail. retractall(Term).

101 / 259

Logic programming

operators
In Prolog, functors and predicates are called operators. Operators can be declared using
:op(Priority,Type,Name)

where Priority is a number between 0 and 1200 (lower priority binds stronger) Type is fx or fy (prex), xfx,xfy or yfx (inx), and xf or yf (postx) The x and y determine associativity:
associative X op Y op Z no xfx no right xfy op(X,op(Y,Z)) left yfx op(op(X,Y),Z)

102 / 259

Logic programming

meta-programs
Clauses are represented as terms :- (Head,Body) where :- can be treated as a functor (meta-level) or as a predicate (object-level).
% if A and B then C = if(then(and(A,B),C)) :- op(900,fx,if). :- op(800,xfx,then). :- op(700,yfx,and). % object-level rules if has_feathers and lays_eggs then is_bird. if has_gills and lays_eggs then is_fish. if tweety then has_feathers. if tweety then lays_eggs.

it should be possible to show that


if tweety then is_bird

follows from the object-level rules.

103 / 259

Logic programming

meta-program

derive(if Assumptions then Goal):if Body then Goal, derive(if Assumptions then Body). derive(if Assumptions then G1 and G2):derive(if Assumptions then G1), derive(if Assumptions then G2). derive(if Assumptions then Goal):assumed(Goal,Assumptions). % Goal is one of the assumptions assumed(A,A). assumed(A,A and As). assumed(A,B and As):assumed(A,As).

104 / 259

Logic programming

prolog meta-interpreter
prove(Goal):clause(Goal,Body), prove(Body). prove((Goal1,Goal2)):prove(Goal1), prove(Goal2). prove(true).

or, more conventionally, and adding negation as failure:


prove(true):- !. prove((A,B)):- !, prove(A), prove(B). prove(not(Goal)):- !, not(prove(Goal)). prove(A):% not (A=true; A=(X,Y); A=not(G)) clause(A,B), prove(B).

105 / 259

Logic programming

quicksort
% partition(l,n,Smalls,Bigs): % Smalls contains numbers in l % smaller than n, Bigs the rest. partition([],N,[],[]). partition([H|T],N,[H|Small],Big):H<N,partition(T,N,Small,Big). partition([H|T],N,Small,[H|Big]):H>=N,partition(T,N,Small,Big). quicksort([],[]). quicksort([X|Xs],Sorted):partition(Xs,X,Small,Big), quicksort(Small,S_Small), quicksort(Big,S_Big), append(S_Small,[X|S_Big],Sorted).

106 / 259

Logic programming

towers of hanoi
:- op(900,xfx,to). % hanoi(N,A,B,C,Moves): Moves is the list of moves to % move N disks from peg A to peg C, using peg B as % an intermediary. hanoi(0,A,B,C,[]). hanoi(N,A,B,C,Moves):N1 is N-1, % assume solved for N-1 disks hanoi(N1,A,C,B,Moves1), hanoi(N1,B,A,C,Moves2), append(Moves1,[A to C|Moves2],Moves). ?- hanoi(3,left,middle,right,M) M = [ left to right, left to middle, right to middle, left to right, middle to left, middle to right, left to right ]

107 / 259

Representing structured knowledge

Outline
1 2 3 4

Preliminaries Introduction Clausal logic

Language processing Reasoning with Incomplete Information Default Reasoning The Semantics of Negation Abduction Inductive Logic Programming

10

Logic programming
11

Representing structured knowledge Searching graphs Informed search

12 13

6 7

108 / 259

Representing structured knowledge

Representing structured knowledge

Knowledge is structured if its components have certain logical relationships. Explicit relationships are represented directly (as facts). Implicit relationships are found by reasoning. Reasoning is often done by searching, e.g. in a graph, a term etc.

109 / 259

Representing structured knowledge

tree as terms adt


% term_tree(Tree,R,S): term Tree represents % a tree with root R, list of subtrees S term_tree(Tree, Root, Subtrees):Tree =.. [Root|Subtrees]. % term_root(Tree, Root): R is root of T term_root(Tree, Root):term_tree(Tree, Root, Subtrees). % term_subtree(Tree, Subtree): Subtree is a subtree term_subtree(Tree, Subtree):term_tree(Tree, Root, Subtrees), element(Subtree, Subtrees). % element(X,Ys): X is element in list element(X,[X|Ys]). element(X,[Y|Ys]):element(X,Ys).

110 / 259

Representing structured knowledge

% term_arc(Tree, Arc): A is arc in Tree term_arc(Tree, [Root, SubRoot]):- % from root term_root(Tree, Root), term_subtree(Tree, SubTree), term_root(Subtree, SubRoot). term_arc(Tree, Arc):- % in subtree term_subtree(Tree, Subtree), term_arc(Subtree, Arc). % term_path(Tree, Path): Path is path in Tree term_path(Tree, Path):- % an arc is a path term_arc(Tree, Path). term_path(Tree, [Node1,Node2|Nodes]):term_arc(Tree,[Node1,Node2]), term_path(Tree,[Node2|Nodes]).

111 / 259

Representing structured knowledge

writing terms as trees


term_write(Tree):term_write(0,Tree), nl. term_write(Indent,Tree):term_tree(Tree, Root, Subtrees), term_write_node(Indent, NewIndent, Root), term_write_subtrees(NewIndent, Subtrees). term_write_subtrees(Indent,[]). term_write_subtrees(Indent,[Tree]):- !, term_write(Indent,Tree). term_write_subtrees(Indent,[Tree|Subtrees]):term_write(Indent,Tree), nl,tabs(Indent), term_write_subtrees(Indent, Subtrees). term_write_node(Begin,End,Node):name(Node,L), length(L,N), End is Begin+10, N1 is End-Begin-N, write_line(N1), write(Node).

112 / 259

Representing structured knowledge

write_line(0). write_line(N):N>0, N1 is N-1, write(-), write_line(N1).

:-

term_write(f1(f2(f4,f5(f7),f6),f3(f8,f9(f10))))

--------f1--------f2--------f4 --------f5--------f7 --------f6 --------f3--------f8 --------f9-------f10

113 / 259

Representing structured knowledge

graphs generated by a predicate


% path(P): P is a list of nodes representing a path % in graph defined by arc/2. path([N1, N2]):arc(N1, N2). path([N1, N2|Nodes]):arc(N1, N2), path([N2|Nodes]). % path_leaf(N, Path): Path is a path starting at N, ending % in a leaf in graph generated by arc/2. path_leaf(Leaf, [Leaf]):leaf(Leaf). path_leaf(N1, [N1|Nodes]):arc(N1, N2), path_leaf(N2, Nodes). % leaf(Leaf):- % no outgoing arcs not(arc(Leaf, SomeNode)).

114 / 259

Representing structured knowledge

sld trees
% resolve(goal, clause, newGoal): % newGoal is resolvent of goal using clause resolve([Literal|Literals], (Head:- Body), NewGoal):Literal = Head, % unify with head append(Body, Literals, NewGoal). % an arc in an SLD tree arc(Goal1, Goal2):clause(Head, Body), resolve(Goal1, (Head:- Body), Goal2). prove(Goal):path(Goal, []). % where path(N1, N2) :arc(N1, N2). path(N1, N3) :arc(N1, N2), path(N2, N3).

115 / 259

Representing structured knowledge

inheritance hierarchies
Instrument Wind String Percussion

Woodwind flute oboe saxophone

Brass trumpet trombone

Plucked guitar lute harp

Bowed violin cello

Keyboard harpsichord piano

Tuned triangle kettledrum

Untuned cymbal snaredrum

A class is represented by a unary predicate, an object by a constant.


instrument(X) :- wind(X). instrument(X) :- string(X). instrument(X) :- percussion(X). wind(X) :- woodwind(X). wind(X) :- brass(X). string(X) :- plucked(X). string(X) :- bowed(X). string(X) :- keyboard(X). percussion(X) :- tuned(X). percussion(X) :- untuned(X).
116 / 259

Representing structured knowledge

woodwind(flute). plucked(guitar). keyboard(piano). untuned(cymbal).

brass(trumpet). bowed(violin). tuned(triangle).

Properties:
material(flute, metal). % string instruments are made of wood material(X, wood) :- woodwind(X). material(X, wood) :- string(X). material(X, metal) :- brass(X). material(X, metal) :- percussion(X). ?- material(piano, X) X = wood ?- material(flute, X) X = metal; X = wood

Putting most specic clauses rst ensures that the rst answer is correct.
117 / 259

Representing structured knowledge

function(X, musical) :- instrument(X). action(oboe, reed(double)). action(saxophone, reed(single)). action(piano, hammered). action(X, hammered) :- percussion(X).

What are the properties of an object I?


attributes([material,action,function]). properties(I, Props):- attributes(Attrs), properties(Attrs, I, Props). properties([], Instance, []). properties([Attribute|Attributes], Instance, [Attribute=Val|Props]):get_value(Attribute, Instance, Val) ,!, % first only properties(Attributes, Instance, Props). get_value(Attribute, Instance, Value):Goal =.. [Attribute, Instance, Value], call(Goal).

118 / 259

Representing structured knowledge

?- properties(saxophone,P) P = [ material = metal, action=reed(single), function = musical]

Questions about classes are not easy to answer since one must resort to second-order programming. Design alternative representation where both classes and instances are represented by terms.

119 / 259

Representing structured knowledge

semantic networks
Represent hierarchy as set of facts.
isa(wind,instrument). isa(woodwind,wind). isa(brass,wind). % etc. inst(oboe,woodwind). inst(flute,woodwind). inst(trumpet,brass). % etc. % class properties: prop(instrument,function,musical). prop(woodwind,material,wood). prop(brass,material,metal). prop(brass,action,reed(lip)). % instance properties prop(flute,material,metal). prop(oboe,action,reed(double)). % ..
120 / 259

Representing structured knowledge

properties in semantic networks


properties(Instance, Properties):direct_properties(Instance, InstanceProperties), inst(Instance, Class), % inherit rest inherit(Class, InstanceProps, Properties). direct_properties(Instance, InstanceProperties):findall(Attribute=Value, prop(Instance,Attribute,Value), InstanceProperties). % isa(instrument,top). inherit(top, Properties, Properties), inherit(Class, Properties, AllProperties):direct_properties(Class, ClassProperties), override(Properties, ClassProperties, ExtendedProperties), isa(Class, SuperClass), inherit(SuperClass, ExtendedProperties, AllProperties).

121 / 259

Representing structured knowledge

% override(SpecificProps,ClassProps,Ps): Ps contains all % SpecificProps and those ClassProps that are not % overridden by SpecificProps. override(Properties, [], Properties). override(Properties, [Attr=AnyValue|ClassProperties], ExtendedProperties):element(Attr=Value, Properties), override(Properties, ClassProperties, ExtendedProperties). override(Properties, [Attr=Value|ClassProperties], [Attr=Value|ExtendedProperties]):not(element(Attr=AnyValue, Properties)), override(Properties, ClassProperties, ExtendedProperties).

122 / 259

Representing structured knowledge

frame-based inheritance

Add property list to each arc in the network.


isa(instrument, top, [function=musical]). isa(wind, instrument, []). isa(woodwind, wind, [material=wood]). isa(brass, wind, [material=metal,action=reed(lip)]). % instance(flute, woodwind, [material=metal]). instance(oboe, woodwind, [action=reed(double]). instance(trumpet, brass, []).

123 / 259

Representing structured knowledge

frame-based inheritance 2

properties(Instance, Properties):instance(Instance, Class, InstanceProperties), inherit(Class, InstanceProperties, Properties). inherit(top, Properties, Properties). inherit(Class, Properties, AllProperties):class(Class, SuperClass, ClassProperties), override(Properties, ClassProperties, ExtendedProperties), inherit(SuperClass, ExtendedProperties, AllProperties).

124 / 259

Searching graphs

Outline
1 2 3 4

Preliminaries Introduction Clausal logic

Language processing Reasoning with Incomplete Information Default Reasoning The Semantics of Negation Abduction Inductive Logic Programming

10

Logic programming
11

Representing structured knowledge Searching graphs Informed search

12 13

6 7

125 / 259

Searching graphs

searching graphs

A search space is a graph with one or more starting nodes and one or more goal nodes. A solution is a path from a start node to a goal node. A cost function assigns a cost to each arc. An optimal solution is a solution with minimal cost. Search algorithms differ w.r.t. completeness: is a solution always found? optimality: will shorter paths be found before longer ones? efciency of the algorithm.

126 / 259

Searching graphs

A general framework
% search(agenda,Goal): agenda contains reached but % untried nodes. % succeeds if a node Goal, for which goal(Goal), can % be reached from a node in Agenda. search(Agenda, Goal):% select/3 selects a node from the Agenda select(Agenda, Goal, RestOfAgenda), goal(Goal). search(Agenda, Goal):select(Agenda, CurrentNode, RestOfAgenda), children(CurrentNode, Children), add(Children, RestOfAgenda, NewAgenda), search(NewAgenda, Goal).

Different algorithms result from different implementations of select/3 and add/3 .

127 / 259

Searching graphs

depth-rst search
Agenda is a list (stack).
select/3 add/3

selects the rst node of the list

puts children in front of the new agenda

search_df([Goal|RestOfAgenda], Goal):goal(Goal). search_df([CurrentNode|RestOfAgenda], Goal):children(CurrentNode, Children), append(Children, RestOfAgenda, NewAgenda), search_df(NewAgenda, Goal). children(Node, Children):findall(Child, arc(Node,Child), Children).

128 / 259

Searching graphs

depth-rst search with paths

Return path to goal: keep paths instead of nodes in agenda.


children([Node|RestOfPath], Children):findall([Child,Node|RestOfPath], arc(Node,Child), Children). ?- search_df([[initial_node]], PathToGoal).

129 / 259

Searching graphs

depth-rst search with loop detection


Loop detection: keep list of visited nodes.
search_df([Goal|RestOfAgenda], VisitedNodes, Goal):goal(Goal). search_df([Node|RestOfAgenda], VisitedNodes, Goal):children(Node ,Children), add_df(Children, RestOfAgenda, [Node|VisitedNodes], NewAgenda), search_df(NewAgenda, [Node|VisitedNodes], Goal). % add_df(Nodes, Agenda, VisitedNodes, NewAgenda) add_df([], Agenda, VisitedNodes, Agenda). add_df([Node|Nodes], Agenda, VisitedNodes, [Node|NewAgenda]):not(element(Node, Agenda)), not(element(Node, VisitedNodes), add_df(Nodes, Agenda, VisitedNodes, NewAgenda). add_df([Node|Nodes], Agenda, VisitedNodes, NewAgenda):element(Node, Agenda), add_df(Nodes, Agenda, VisitedNodes, NewAgenda). add_df([Node|Nodes], Agenda, VisitedNodes, NewAgenda):element(Node, VisitedNodes), add_df(Nodes, Agenda, VisitedNodes, NewAgenda).
130 / 259

Searching graphs

depth-rst search with agenda on prolog stack

Using Prologs goal stack to keep agenda, but without loop detection:
search_df(Goal,Goal):goal(Goal). search_df(CurrentNode, Goal):arc(CurrentNode, Child), search_df(Child, Goal).

131 / 259

Searching graphs

depth-rst search with depth bound

An incomplete version with a depth bound:


search_bd(Depth, Goal, Goal):goal(Goal). search_bd(Depth, CurrentNode, Goal):Depth>0, NewDepth is Depth-1, arc(CurrentNode, Child), search_bd(NewDepth, Child, Goal). ?- search_df(10,initial_node,Goal).

132 / 259

Searching graphs

depth-rst search with iterative deepening

Iterative deepening (e.g. in chess):


search_id(CurrentNode, Goal):search_id(1, CurrentNode, Goal). search_id(Depth, CurrentNode, Goal):search_bd(Depth, CurrentNode, Goal). search_id(Depth, CurrentNode, Goal):NewDepth is Depth+1, search_id(NewDepth, CurrentNode, Goal).

133 / 259

Searching graphs

breadth-rst search
Agenda is a list (queue).
select/3 add/3

selects the rst node of the list

puts children at the back of the new agenda

search_bf([Goal|RestOfAgenda], Goal):goal(Goal). search_bf([CurrentNode|RestOfAgenda], Goal):children(CurrentNode, Children), append(RestOfAgenda ,Children, NewAgenda), search_bf(NewAgenda, Goal). children(Node, Children):findall(Child, arc(Node,Child), Children).

134 / 259

Searching graphs

a full clause refutation engine


Use breadth-rst search. Clause representation:
clause(([bach(X),married(X)] :- [man(X),adult(X)])). clause(([] :- [has_wife(paul)])). % empty head clause(([] :- [])). % empty clause

Because findall(X,G,L) creates new variables for the unbound variables in X before putting it in L, we keep a copy of the original goal in order to be able to retrieve the computed substitution. The agenda is a list of pairs
agenda_item(SubGoalClause, OriginalGoal)

135 / 259

Searching graphs

refute(GoalClause):refute([agenda_item(GoalClause,GoalClause)], GoalClause). % The following clause unifies two versions of the % original clause where the first version contains % the answer substitution. refute([ agenda_item(([]:- []), GoalClause) | _ ], GoalClause). refute([agenda_item(InputClause,GoalClause)|RestOfAgenda], OriginalGoalClause):findall( agenda_item(Resolvent, GoalClause), ( clause(Resolver), resolve(InputClause, Resolver, Resolvent) ), Children), append(RestOfAgenda, Children, NewAgenda), % breadth-first refute(NewAgenda, OriginalGoalClause).

136 / 259

Searching graphs

% resolve(Clause1,Clause2,R) iff R is a resolvent % of Clause1 and Clause2. resolve((H1:-B1), (H2:-B2), (ResHead:-ResBody)):% remove common literals from H1, B2, yielding R1, R2 remove_common_element(H1, B2, R1, R2), append(R1, H2, ResHead), append(B1, R2, ResBody). resolve((H1:- B1), (H2:-B2), (ResHead:-ResBody)):remove_common_element(H2, B1, R2, R1), append(H1, R2, ResHead), append(R1, B2, ResBody).

137 / 259

Searching graphs

% remove_common_element(+L1, +L2, -R1, -R2) % iff (roughly) exists X such that els(Li) = els(Ri) + {X} % (note that, necessarily, els(Li) not empty remove_common_element([A|B], C, B, E) :remove_element(A, C, E). remove_common_element([A|B], C, [A|D], E) :remove_common_element(B, C, D, E). % remove_element(+A,+L,-R) % iff (roughly) els(L) = els(R) + {A} remove_element(A, [A|B], B). remove_element(A, [C|B], [C|D]) :A\=C, remove_element(A, B, D).

138 / 259

Searching graphs

clause(([bachelor(X),married(X)]:- [man(X),adult(X)])). clause(([has_wife(X)]:- [man(X),married(X)])). clause(([]:- [has_wife(paul)])). clause(([man(paul)]:- [])). clause(([adult(paul)]:- [])). ?- refute(([] :- [bach(X)])) X = paul

The resolution strategy (input resolution: every resolvent has at least one program clause as its parent) used is incomplete for general clauses (but complete for denite ones).

139 / 259

Searching graphs

forward chaining
% model(-M) iff M is a model of the clauses defined by cl/1 model(M):model([], M). % model(+M0,-M) iff M0 can be extended to a model M % of the cl/1 clauses. model(M0, M):clause((H:- B)), % find violated clause instance is_violated((H:- B), M0),!, element(L, H), % select ground literal from the head model([L|M0], M). % and add it to the model model(M, M). % no violated clauses % is_violated((H:- B),+M) iff instance of H:-B % is violated by M is_violated((H:- B), M):satisfied_body(B, M), % this will ground the variables not(satisfied_head(H, M)).
140 / 259

Searching graphs

% satisfied_body(L,+M) iff M |= A for all A in L, % may bind vars in L satisfied_body([], M). satisfied_body([A|B], M) :element(A, M), satisfied_body(B, M). % satisfied_head(+L,+M) iff exists A in els(L) % with M |= A satisfied_head(L,M):element(A, L), element(A, M). element(A, [A|_]). element(A, [_|B]) :element(A, B).

141 / 259

Searching graphs

clause(([bach(X),married(X)]:- [man(X),adult(X)])). clause(([has_wife(X)]:- [man(X),married(X)])). clause(([man(paul)]:- [])). clause(([adult(paul)]:- [])). ?- model(M) M = [has_wife(paul), married(paul), adult(paul), man(paul)]; M = [bach(paul), adult(paul), man(paul)]

The program works correctly only for clauses for which grounding the body also grounds the head.
clause(([man(X),woman(X)]:- [])). clause(([]:- [man(jane)])). % jane is not a man clause(([]:- [woman(peter)])). % peter is not a woman

142 / 259

Searching graphs

range-restricted clauses

This can be xed:


clause(([man(X),woman(X)]:- [person(X)])). clause(([person(jane)]:- [])). clause(([person(peter)]:- [])). clause(([]:- [man(jane)])). clause(([]:- [woman(peter)])).

Range-restricted clauses: where all variables in the head also occur in the body. Any program can be transformed into an equivalent one using only range-restricted clauses.

143 / 259

Informed search

Outline
1 2 3 4

Preliminaries Introduction Clausal logic

Language processing Reasoning with Incomplete Information Default Reasoning The Semantics of Negation Abduction Inductive Logic Programming

10

Logic programming
11

Representing structured knowledge Searching graphs Informed search

12 13

6 7

144 / 259

Informed search

best-rst search
Informed search uses an heuristic estimate of the distance from a node to a goal.
% eval(Node,Value) estimates distance from node to goal search_best([Goal|RestAgenda], Goal):goal(Goal). search_best([CurrentNode|RestAgenda], Goal):children(CurrentNode, Children), add_best(Children, RestAgenda, NewAgenda), search_best(NewAgenda, Goal). % add_best(A,B,C): C contains % els from A,B sorted according to eval/2 add_best([], Agenda, Agenda). add_best([Node|Nodes], Agenda, NewAgenda):insert(Node, Agenda, TmpAgenda), add_best(Nodes, TmpAgenda, NewAgenda).

145 / 259

Informed search

insert(Node, Agenda, NewAgenda):eval(Node, Value), insert(Value, Node, Agenda, NewAgenda). insert(Value, Node, [], [Node]). insert(Value, Node, [FirstNode|RestOfAgenda], [Node, FirstNode|RestOfAgenda]):eval(FirstNode, FirstNodeValue), Value < FirstNodeValue. insert(Value, Node, [FirstNode|RestOfAgenda], [FirstNode|NewRestOfAgenda]):eval(FirstNode, FirstNodeValue), Value >= FirstNodeValue, insert(Value, Node, RestOfAgenda, NewRestOfAgenda).

Best-rst search is not complete since, with certain estimate functions, it may get lost in an innite subgraph.

146 / 259

Informed search

example puzzle

A tile may be moved to the empty spot if there are at most 2 tiles between it and the empty spot. Find a series of moves that bring all the black tiles to the right of all the white tiles.

147 / 259

Informed search

representing and manipulating the board


A position of the board is represented using a list, e.g.
[b,b,b,e,w,w,w] % get_tile(position,n,Tile): position[n]=Tile get_tile(Position, N, Tile) :get_tile(Position, 1, N, Tile). get_tile([Tile|Tiles], N, N, Tile). get_tile([Tile|Tiles], N0, N, FoundTile) :N1 is N0+1, get_tile(Tiles, N1, N, FoundTile). % replace(position,n,t,B): B is position with board[n]=t replace([Tile|Tiles], 1, ReplacementTile, [ReplacementTile|Tiles]). replace([Tile|Tiles], N, ReplacementTile, [Tile|RestOfTiles]):N>1, N1 is N-1, replace(Tiles, N1, ReplacementTile, RestOfTiles).

148 / 259

Informed search

representing the agenda

A move is represented by a term


move(FromPosition, ToPosition, Cost).

The start move:


start_move( move(noparent, [b,b,b,e,w,w,w], 0) ).

showing a move (in a sequence)


show_move( move(OldPosition, NewPosition, Cost), Value):write(NewPosition-Value), nl.

An agenda is list of terms move_value(Move, Value) where Value is the heuristic evaluation of the position reached by Move.

149 / 259

Informed search

tiles/2
tiles(ListOfPositions, TotalCost):start_move(StartMove), % Value is heuristic of distance to goal eval(StartMove, Value), % best-first search accumulating moves tiles([move_value(StartMove, Value)], FinalMove, [], VisitedMoves), % accumulator % find (and print) a backward path and its cost in % VisitedMoves from the final move to the start move order_moves(FinalMove, VisitedMoves, [], ListOfPositions, % accumulator 0, TotalCost). % accumulator

150 / 259

Informed search

tiles/4
% tiles(Agenda, LastMove, V0, V): goal can be % reached from a move in Agenda where LastMove % is the last move leading to the goal, % and V is V0 + the set of moves tried. tiles([move_value(LastMove,Value)|RestAgenda], LastMove, VisitedMoves, VisitedMoves):goal(LastMove). % eval(LastMove, 0), i.e. goal reached tiles([move_value(Move,Value)|RestAgenda], Goal, VisitedMoves, FinalVisitedMoves):show_move(Move, Value), % show move closest to goal % find and evaluate possible next moves from M setof0( move_value(NextMove, NextValue), ( next_move(Move, NextMove), eval(NextMove, NextValue) ), Children), merge(Children, RestAgenda, NewAgenda), tiles(NewAgenda, Goal, [Move|VisitedMoves], FinalVisitedMoves).
151 / 259

Informed search

next_move/2
next_move( move(Position, LastPosition, LastCost), move(LastPosition, NewPosition, Cost) ) :% consecutive moves: NewPosition can be reached from % LastPosition in 1 move at cost Cost % Ne = index of empty spot get_tile(LastPosition, Ne, e), % Nbw = index of nonempty spot get_tile(LastPosition, Nbw, BW), not(BW=e), Diff is abs(Ne-Nbw), Diff<4, % not too far from Ne replace(LastPosition, Ne, BW, IntermediatePosition), replace(IntermediatePosition, Nbw, e, NewPosition), ( Diff=1 -> Cost=1 ; otherwise -> Cost is Diff-1 ).

152 / 259

Informed search

% order_moves(FinalMove, VisitedMoves, % Positions, FinalPositions, % TotalCost,FinalTotalCost): % FinalPositions = Positions + connecting sequence of % target positions from VisitedMoves ending in % FinalMoves target position. % FinalTotalCost = TotalCost + total cost of moves % added to Positions to obtain FinalPositions. order_moves(move(noparent,StartPosition,0), VisitedMoves, Positions, [StartPosition|Positions], TotalCost, TotalCost). order_moves(move(FromPosition, ToPosition, Cost), VisitedMoves, Positions, FinalPositions, TotalCost, FinalTotalCost):element( PreviousMove, VisitedMoves), PreviousMove = move(PreviousPosition, FromPosition, CostOfPreviousMove), NewTotalCost is TotalCost + Cost, order_moves(PreviousMove, VisitedMoves, [ToPosition|Positions], FinalPositions, NewTotalCost, FinalTotalCost).
153 / 259

Informed search

utilities
% setof0/3: variant of setof/3 % which succeeds with empty list if no solutions are found setof0(X, G, L):setof(X, G, L), !. setof0(X, G, []). merge([], Agenda, Agenda). % avoid succeeding twice on merge([],[],L). merge([C|Cs],[],[C|Cs]). merge([C|Cs],[N|Ag],[C|NewAg]):eval(C,CVal), eval(N,NVal), CVal<NVal, merge(Cs,[N|Ag],NewAg]). merge([C|Cs],[N|Ag],[N|NewAg]):eval(C,CVal), eval(N,NVal), CVal>=NVal, merge([C|Cs],Ag,NewAg]).
154 / 259

Informed search

eval/1
goal(Move):eval(Move,0). eval(move(OldPosition,Position,C),Value):bLeftOfw(Position,Value). % Val is the sum of the number of black tiles % to the left of each white tile bLeftOfw(Pos,Val):findall((Nb,Nw), ( get_tile(Pos,Nb,b), get_tile(Pos,Nw,w), Nb<Nw), L), length(L,Val).

155 / 259

Informed search

example run
?- tiles(M,C). [b,b,b,e,w,w,w]-9 [b,b,b,w,e,w,w]-9 [b,b,e,w,b,w,w]-8 [b,b,w,w,b,e,w]-7 [b,b,w,w,b,w,e]-7 [b,b,w,w,e,w,b]-6 [b,e,w,w,b,w,b]-4 [b,w,e,w,b,w,b]-4 [e,w,b,w,b,w,b]-3 [w,w,b,e,b,w,b]-2 [w,w,b,w,b,e,b]-1 M = [[b,b,b,e,w,w,w],[b,b,b,w,e,w,w], [b,b,e,w,b,w,w],[b,b,w,w,b,e,w], [b,b,w,w,b,w,e],[b,b,w,w,e,w,b], [b,e,w,w,b,w,b],[b,w,e,w,b,w,b], [e,w,b,w,b,w,b],[w,w,b,e,b,w,b], [w,w,b,w,b,e,b],[w,w,e,w,b,b,b]] C = 15
156 / 259

Informed search

optimal best-rst search


Best-rst search can be made complete by using f (n) = g(n) + h(n) where g(n) is actual cost so far and h(n) is estimate on further cost to reach goal. Such an algorithm is called an A-algorithm. g(n) will prevent getting lost in an innite subgraph: adds a breadth-rst avor. If h(n) is optimistic, i.e. it underestimates the cost, then the algorithm always nds an optimal path. Such an algorithm is called an A -algorithm. In an extreme case, if h(n) = 0, the algorithm degenerates to breadth-rst (the heuristic in the previous example is optimistic).

157 / 259

Language processing

Outline
1 2 3 4

Preliminaries Introduction Clausal logic

Language processing Reasoning with Incomplete Information Default Reasoning The Semantics of Negation Abduction Inductive Logic Programming

10

Logic programming
11

Representing structured knowledge Searching graphs Informed search

12 13

6 7

158 / 259

Language processing

language processing

Syntax: denite clause grammars Semantics: terms instead of nonterminals Language generation An example interpreter

159 / 259

Language processing

denite clause grammars (dcg)

Context-free grammars in prolog. A sentence is a list of terminals:


[socrates, is, human]

Non-terminals are dened by rules


sentence --> noun_phrase, verb_phrase verb_phrase --> [is], property noun_phrase -->proper_noun proper_noun --> [socrates] property --> [mortal] property --> [human]

160 / 259

Language processing

rules and prolog


A rule
sentence --> noun_phrase, verb_phrase

can be read as:


sentence(S) :noun_phrase(NP), verb_phrase(VP), append(NP,VP,S).

A rule
property --> [mortal]

can be read as:


property([mortal]).

thus: sentence([socrates, is , mortal]) parses the sentence


161 / 259

Language processing

without append/3
A rule
sentence --> noun_phrase, verb_phrase

corresponds to
sentence(L,L0) :noun_phrase(L,L1), verb_phrase(L1,L0).

reading sentence(L,L0) as L consists of a sentence followed by L0 . The conversion of rules to clauses is often built into prolog, as is the meta-predicate phrase/2 where phrase(sentence,L) sentence(L,[])

162 / 259

Language processing

DCGs vs. context-free grammars

non-terminals can have arguments goals can be put into the rules no need for deterministic (LL(k), LR(k)) grammars! a single formalism for specifying syntax, semantics

163 / 259

Language processing

example: adding plurality constraints


sentence --> noun_phrase(N), verb_phrase(N) noun_phrase(N) --> article(N), noun(N) verb_phrase(N) --> intransitive_verb(N) article(singular) --> [a] article(singular) --> [the] article(plural) --> [the] noun(singular) --> [student] noun(plural) --> [students] intransitive_verb(singular) --> [sleeps] intransitive_verb(plural) --> [sleep] phrase(sentence,[a,student,sleeps]). % yes phrase(sentence,[the,students,sleep]). % yes phrase(sentence,[the,students,sleeps]). % no

164 / 259

Language processing

example: explicit parse trees


A parse tree is represented by a term.
sentence(s(NP,VP)) --> noun_phrase(NP), verb_phrase(VP) noun_phrase(np(Art,Adj,N)) --> article(Art), adjective(Adj), noun(N) noun_phrase(np(Art,N)) --> article(Art), noun(N) verb_phrase(vp(IV)) --> intransitive_verb(IV) article(art(the)) --> [the] adjective(adj(lazy)) --> [lazy] noun(n(student)) --> [student] intransitive_verb(iv(sleeps)) --> [sleeps]

165 / 259

Language processing

example: explicit parse trees


?- phrase(sentence(T), [the,lazy,student,sleeps]) T = s(np(art(the), adj(lazy), n(student)), vp(iv(sleeps))) ?- phrase(sentence(T), [the,lazy,student,sleeps]), term_write(T)

---s---np---art------the ---adj-----lazy -----n--student ---vp----iv---sleeps

166 / 259

Language processing

example: number parsing


nX_Y(N) if N is a number in [X..Y]. The grammar:
num(N) --> n1_999(N). num(N) --> n1_9(N1),[thousand],n1_999(N2), {N is N1*1000+N2}. n1_999(N) --> n1_99(N). n1_999(N) --> n1_9(N1),[hundred],n1_99(N2), {N is N1*100+N2}. n1_99(N) --> n0_9(N). n1_99(N) --> n10_19(N). n1_99(N) --> tens(N). n1_99(N) --> tens(N1),n1_9(N2),{N is N1+N2}. n0_9(0) --> []. n0_9(N) --> n1_9(N). n1_9(1) --> [one]. % two, .. , nine n10_19(10) --> [ten]. % eleven,.., nineteen tens(20) --> [twenty]. % thirty,.., ninety

167 / 259

Language processing

The rule
n1_99(N) --> tens(N1), n1_9(N2), {N is N1+N2}.

corresponds to the clause


n1_99(N,L,L0) :tens(N1,L,L1), n1_9(N2,L1,L0), N is N1 + N2.

168 / 259

Language processing

number parsing example

?- phrase(num(N), [two,thousand,two,hunderd,eleven]) N = 2211

169 / 259

Language processing

interpretation of natural language


Syntax:
sentence --> determiner, noun, verb_phrase sentence --> proper_noun, verb_phrase verb_phrase --> [is], property property --> [a], noun property --> [mortal] determiner --> every proper_noun --> [socrates] noun --> [human]

Semantics: convert sentences to clauses, e.g. every human is mortal becomes


mortal(X):human(X)

170 / 259

Language processing

A proper noun is interpreted as a constant.


proper_noun(socrates) --> [socrates]

A verb phrase is interpreted as a mapping from terms to literals X=>L:


verb_phrase(M) --> [is], property(M). property(X=>mortal(X)) --> [mortal]. sentence((L:- true)) --> proper_noun(X), verb_phrase(X=>L). ?-phrase(sentence(C),[socrates,is,mortal]). C = (mortal(socrates):- true) sentence(C) --> determiner(M1,M2,C), noun(M1), verb_phrase(M2). determiner(X=>B, X=>H, (H:- B)) --> [every]. noun(X=>human(X)) --> [human]. ?-phrase(sentence(C), [every human is mortal]) C = (mortal(X):- human(X))
171 / 259

Language processing

grammar
:- op(600,xfy,=>). sentence(C) --> determiner(N,M1,M2,C), noun(N,M1), verb_phrase(N,M2). sentence([(L:- true)]) --> proper_noun(N,X), verb_phrase(N,X=>L). verb_phrase(s,M) --> [is], property(s,M). verb_phrase(p,M) --> [are], property(p,M). property(N,X=>mortal(X)) --> [mortal]. property(s,M) --> noun(s,M). property(p,M) --> noun(p,M). determiner(s, X=>B , X=>H, [(H:- B)]) --> [every]. determiner(p, sk=>H1, sk=>H2, [(H1 :- true),(H2 :- true)]) -->[some]. proper_noun(s,socrates) --> [socrates]. noun(s,X=>human(X)) --> [human]. noun(p,X=>human(X)) --> [humans]. noun(s,X=>living_being(X)) --> [living],[being]. noun(p,X=>living_being(X)) --> [living],[beings].

172 / 259

Language processing

questions

question(Q) --> [who], [is], property(s,X=>Q) question(Q) --> [is], proper_noun(N,X), property(N,X=>Q) question((Q1,Q2)) --> [are], [some], noun(p,sk=>Q1), property(p,sk=>Q2)

173 / 259

Language processing

the interpreter: handle_input/2


% RB = rule base nl_shell(RB) :get_input(Input), handle_input(Input,RB). handle_input(stop,RB) :- !. handle_input(show,RB) :- !, show_rules(RB), nl_shell(RB). handle_input(Sentence,RB) :phrase(sentence(Rule),Sentence), nl_shell([Rule|RB]). handle_input(Question,RB) :phrase(question(Query),Question), prove(Query,RB), transform(Query,Clauses), phrase(sentence(Clauses),Answer), show_answer(Answer), nl_shell(RB). handle_input(Error,RB) :show_answer(no), nl_shell(RB).

174 / 259

Language processing

auxiliary clauses

show_rules([]). show_rules([R|Rs]) :phrase(sentence(R),Sentence), show_answer(Sentence), show_rules(Rs). get_input(Input) :write(? ),read(Input). show_answer(Answer) :write(! ),write(Answer), nl.

175 / 259

Language processing

answering questions
prove(true,RB) :- !. prove((A,B),RB) :- !, prove(A,RB),prove(B,RB). prove(A,RB) :find_clause((A:- B),RB), prove(B,RB). % find_clause(C,[R|Rs]) :% dont instantiate rule copy_element(C,R). find_clause(C,[R|Rs]) :find_clause(C,Rs). copy_element(X,Ys) :element(X1,Ys), % copy with fresh variables copy_term(X1,X). transform((A,B),[(A:- true)|Rest]) :transform(B,Rest). transform(A,(A:- true)).
176 / 259

Language processing

example session

? ? ? ! ? ? !

[every,human,is,mortal] [socrates,is,a,human] [who,is,mortal] [socrates,is,mortal] [some,living,beings,are,humans] [are,some,living,beings,mortal] [some,living,beings,are,mortal]

177 / 259

Reasoning with Incomplete Information

Outline
1 2 3 4

Preliminaries Introduction Clausal logic

Language processing Reasoning with Incomplete Information Default Reasoning The Semantics of Negation Abduction Inductive Logic Programming

10

Logic programming
11

Representing structured knowledge Searching graphs Informed search

12 13

6 7

178 / 259

Reasoning with Incomplete Information

reasoning with incomplete information

Forms of reasoning where conclusions are plausible but not guaranteed to be true: default reasoning: when a normal state of affairs is assumed (birds y).

179 / 259

Reasoning with Incomplete Information

reasoning with incomplete information

Forms of reasoning where conclusions are plausible but not guaranteed to be true: default reasoning: when a normal state of affairs is assumed (birds y). abductive resoning when there is a choice between several explanations that explain observations, e.g. in a diagnosis

179 / 259

Reasoning with Incomplete Information

reasoning with incomplete information

Forms of reasoning where conclusions are plausible but not guaranteed to be true: default reasoning: when a normal state of affairs is assumed (birds y). abductive resoning when there is a choice between several explanations that explain observations, e.g. in a diagnosis inductive reasoning when a general rule is learned from examples.

179 / 259

Reasoning with Incomplete Information

reasoning with incomplete information

Forms of reasoning where conclusions are plausible but not guaranteed to be true: default reasoning: when a normal state of affairs is assumed (birds y). abductive resoning when there is a choice between several explanations that explain observations, e.g. in a diagnosis inductive reasoning when a general rule is learned from examples. Such reasoning is unsound. Sound reasoning is called deduction. Deduction only makes implicit information explicit.

179 / 259

Default Reasoning

Outline
1 2 3 4

Preliminaries Introduction Clausal logic

Language processing Reasoning with Incomplete Information Default Reasoning The Semantics of Negation Abduction Inductive Logic Programming

10

Logic programming
11

Representing structured knowledge Searching graphs Informed search

12 13

6 7

180 / 259

Default Reasoning

default reasoning

Tweety is a bird. Normally, birds y. Therefore, Tweety ies.


bird(tweety). flies(X) :- bird(X), normal(X).

has 3 models:
{bird(tweety)} {bird(tweety), flies(tweety)} {bird(tweety), flies(tweety), normal(tweety)}

181 / 259

Default Reasoning

In default reasoning, it is more natural to use abnormal/1 instead of


normal/1: flies(X) ; abnormal(X) :bird(X).

can be transformed to a general denite clause:


flies(X) :bird(X) , not(abnormal(X)).

Using negation as failure, we can now prove that Tweety ies.


bird(X) :- ostrich(X). ostrich(tweety). abnormal(X) :- ostrich(X).

Here the default rule


flies(X) :bird(X), not(abnormal(X)).

is cancelled by the more specic rule about ostriches.

182 / 259

Default Reasoning

non-monotonic reasoning
In the example, new information invalidates previous conclusions. This is not the case for deductive reasoning where Th p Th {q} p p} we get that

for any q or, dening Closure(Th) = {p | Th

deduction is monotonic
Th1 Th2 Closure(Th1 ) Closure(Th2 )

183 / 259

Default Reasoning

non-monotonic reasoning
In the example, new information invalidates previous conclusions. This is not the case for deductive reasoning where Th p Th {q} p p} we get that

for any q or, dening Closure(Th) = {p | Th

deduction is monotonic
Th1 Th2 Closure(Th1 ) Closure(Th2 ) Default reasoning using not/1 is problematic because not/1 has no declarative semantics (but see later).

183 / 259

Default Reasoning

non-monotonic reasoning
In the example, new information invalidates previous conclusions. This is not the case for deductive reasoning where Th p Th {q} p p} we get that

for any q or, dening Closure(Th) = {p | Th

deduction is monotonic
Th1 Th2 Closure(Th1 ) Closure(Th2 ) Default reasoning using not/1 is problematic because not/1 has no declarative semantics (but see later). Alternatively we can distinguish between rules with exceptions (default rules) and rules without exceptions. Rules are applied whenever possible, but default rules are only applied when they do not lead to an inconsistency.
183 / 259

Default Reasoning

an interpreter for default reasoning

Example
default((flies(X) :- bird(X))). rule((not(flies(X)) :- penguin(X))). rule((bird(X) :- penguin(X))). rule((penguin(tweety) :- true)). rule((bird(opus) :- true)).

184 / 259

Default Reasoning

the interpreter 1/2

% E explains F from rules, defaults explain(F,E):explain(F,[],E). explain(true,E,E) :- !. explain((A,B),E0,E) :- !, explain(A,E0,E1), explain(B,E1,E). explain(A,E0,E):prove(A,E0,E). explain(A,E0,[default((A:-B))|E]):default((A:-B)), explain(B,E0,E), not(contradiction(A,E)).

185 / 259

Default Reasoning

the interpreter 2/2

% prove using non-defaults prove(true,E,E) :- !. prove((A,B),E0,E) :- !, prove(A,E0,E1), prove(B,E1,E). prove(A,E0,[rule((A:-B))|E]):rule((A:-B)), prove(B,E0,E). contradiction(not(A),E) :- !, prove(A,E,E1). contradiction(A,E):prove(not(A),E,E1).

186 / 259

Default Reasoning

Example
?- explain(flies(X),E) X=opus E=[default((flies(opus) :- bird(opus))), rule((bird(opus) :- true))] ?- explain(not(flies(X)),E) X=tweety E=[rule((not(flies(tweety)) :- penguin(tweety))), rule((penguin(tweety) :- true))]

187 / 259

Default Reasoning

Example
default((not(flies(X)) :- mammal(X))). default((flies(X) :- bat(X))). default((not(flies(X)) :- dead(X))). rule((mammal(X) :- bat(X))). rule((bat(a) :- true)). rule((dead(a) :- true)). ?-explain(flies(a),E) E=[default((flies(a) :- bat(a))), rule((bat(a) :- true))] ?-explain(not(flies(a)),E) E=[default((not(flies(a)) :- mammal(a))) rule((mammal(a) :- bat(a))), rule((bat(a) :- true))] E=[default((not(flies(a)) :- dead(a))) rule((dead(a) :- true))]

Only the third explanation seems acceptable.


188 / 259

Default Reasoning

We can rene by naming defaults and allow rules to cancel a specic default by name.

Example
default(mammals_dont_fly(X), (not(flies(X)):- mammal(X))). default(bats_fly(X),(flies(X):- bat(X))). default(dead_things_dont_fly(X), (not(flies(X)):- dead(X))). rule((mammal(X):- bat(X))). rule((bat(a):- true)). rule((dead(a):- true)). rule((not(mammals_dont_fly(X)):- bat(X))). % cancels mammals_dont_fly rule((not(bats_fly(X)):- dead(X))). % cancels bats_fly

189 / 259

Default Reasoning

Change the interpreter:


explain(A,E0,[default(Name)|E]):default(Name,(A:- B)), explain(B,E0,E), % default not cancelled not(contradiction(Name,E)), not(contradiction(A,E)).

190 / 259

Default Reasoning

Example
?-explain(flies(a),E) no ?-explain(not(flies(a)),E) E=[default(dead_things_dont_fly(a)), rule((dead(a):- true))]

191 / 259

The Semantics of Negation

Outline
1 2 3 4

Preliminaries Introduction Clausal logic

Language processing Reasoning with Incomplete Information Default Reasoning The Semantics of Negation Abduction Inductive Logic Programming

10

Logic programming
11

Representing structured knowledge Searching graphs Informed search

12 13

6 7

192 / 259

The Semantics of Negation

semantics of negation

A program P is complete if for every (ground) fact f , we have that P |= f or P |= f We consider two methods to complete programs: The closed world assumption works for denite clauses.

193 / 259

The Semantics of Negation

semantics of negation

A program P is complete if for every (ground) fact f , we have that P |= f or P |= f We consider two methods to complete programs: The closed world assumption works for denite clauses. Predicate completion works for general clauses (with negation in the body) but leads to inconsistencies for some programs.

193 / 259

The Semantics of Negation

semantics of negation

A program P is complete if for every (ground) fact f , we have that P |= f or P |= f We consider two methods to complete programs: The closed world assumption works for denite clauses. Predicate completion works for general clauses (with negation in the body) but leads to inconsistencies for some programs. Alternatively, the stable model semantics introduces nondeterminism.

193 / 259

The Semantics of Negation

the closed world assumption

CWA: everything that is not known to be true must be false (e.g. databases). CWA(P) = P {:A | A BP P |= A} CWA(P) is the intended program of P, according to the CWA.

194 / 259

The Semantics of Negation

Example
likes(peter,S) :- student_of(S,peter). student_of(paul,peter).

CWA(P):
likes(peter,S) :- student_of(S,peter). student_of(paul,peter). :- student(paul,paul). :- student(peter,paul). :- student(peter,peter). :- likes(paul,paul). :- likes(paul,peter). :- likes(peter,peter).

CWA(P) has only one model:


{student_of(paul,peter), likes(peter,paul)}

This intended model is the intersection of all (Herbrand) models.

195 / 259

The Semantics of Negation

Example
bird(tweety). flies(X);abnormal(X) :bird(X).

CWA(P):
bird(tweety). flies(X);abnormal(X) ::- flies(tweety). :- abnormal(tweety). bird(X).

which is inconsistent: CWA is unable to handle indenite (or general, pseudo-denite) clauses.

196 / 259

The Semantics of Negation

predicate completion

Regard a clause as part of the denition of a predicate. E.g. if


likes(peter,S) :student(S,peter).

is the only clause with head likes/2, its completion is X S likes(X , S) X = peter student(S, peter ) which can be translated back to clausal form:
likes(peter,S) :- student(S,peter). X=peter :- likes(X,S). student(S,peter) :- likes(X,S)

197 / 259

The Semantics of Negation

the completion algorithm 1/3

likes(peter,S) :- student(S,peter). likes(X,Y) :- friend(X,Y).

1. Ensure that each argument of the head of each clause is a distinct variable by adding literals of the form Var = Term to the body.
likes(X,S) :likes(X,Y) :X=peter, student(S,peter). friend(X,Y).

198 / 259

The Semantics of Negation

the completion algorithm 2/3

likes(X,S) :likes(X,Y) :-

X=peter, student(S,peter). friend(X,Y).

2. If there are several clauses for the same predicate (in the head), combine them into a single formula with a disjunctive body. X Y likes(X , Y ) (X = peter student(Y , peter )) friend(X , Y )

199 / 259

The Semantics of Negation

the completion algorithm 3/3

3. Replace the implication by an equivalence. X Y likes(X , Y ) (X = peter student(Y , peter )) friend(X , Y ) Note: predicates that have no clauses, e.g. p/1 becomes X p(X )

Clarke completion semantics


The intended model of P is the classical model of the predicate completion of Comp(P).

200 / 259

The Semantics of Negation

Be careful with variables that do not occur in the head:


ancestor(X,Y) :parent(X,Z), ancestor(Z,Y).

is equivalent to X Y Z ancestor (X , Y ) parent(X , Z ) ancestor (Z , Y ) but also with X Y ancestor (X , Y ) (Z parent(X , Z ) ancestor (Z , Y ))

201 / 259

The Semantics of Negation

Example
ancestor(X,Y) :ancestor(X,Y) :parent(X,Y). parent(X,Z), ancestor(Z,Y).

becomes X Y ancestor (X , Y ) parent(X , Y ) (Z parent(X , Z ) ancestor (Z , Y )) in step 2, and X Y ancestor (X , Y ) parent(X , Y ) (Z parent(X , Z ) ancestor (Z , Y )) in step 3.
202 / 259

The Semantics of Negation

Example
bird(tweety). flies(X) :- bird(X), not(abnormal(X)).

Comp(P) becomes: X bird(X ) X = tweety X ies(X ) (bird(X ) abnormal(X )) X abnormal(X ) which has a single model
{ bird(tweety), flies(tweety) }

203 / 259

The Semantics of Negation

Predicate completion gives inconsistent results in some cases:

Example
wise(X) :- not(teacher(X)). teacher(peter) :- wise(peter).

becomes X wise(X ) teacher (X ) X teacher (X ) X = peter wise(peter ) which is inconsistent.

204 / 259

The Semantics of Negation

stratied programs
Denition
A program P is stratied if its predicate symbols can be partitioned into disjoint sets S0 , . . . , Sn such that for each clause p(. . .) L1 , . . . , Lj where p Sk , any literal Lj is such that if Lj = q(. . .) then q S0 . . . Sk

205 / 259

The Semantics of Negation

stratied programs
Denition
A program P is stratied if its predicate symbols can be partitioned into disjoint sets S0 , . . . , Sn such that for each clause p(. . .) L1 , . . . , Lj where p Sk , any literal Lj is such that if Lj = q(. . .) then q S0 . . . Sk if Lj = q(. . .) then q S0 . . . Sk 1

205 / 259

The Semantics of Negation

stratied programs
Denition
A program P is stratied if its predicate symbols can be partitioned into disjoint sets S0 , . . . , Sn such that for each clause p(. . .) L1 , . . . , Lj where p Sk , any literal Lj is such that if Lj = q(. . .) then q S0 . . . Sk if Lj = q(. . .) then q S0 . . . Sk 1

Theorem
If P is stratied then Comp(P) is consistent.

205 / 259

The Semantics of Negation

Theorem
If P is stratied then Comp(P) is consistent. The condition is sufcient but not necessary:

Example
win(X ) loose(X ). loose(X ) win(X ). is not stratied but its completion is consistent.

206 / 259

The Semantics of Negation

the stable model semantics

Intuition: Guess a model and verify that it can be reconstructed from the program (stability).

Example
win:- not(loose). loose :- not(win).

Guess M = {win}: rst rule becomes


win.

while the second rule is not applicable (since its body is false).

207 / 259

The Semantics of Negation

the Gelfond-Lifschitz transformation


For a program P and an interpretation I, the GL transform PI is dened by
1

Removing all (true) negations not(b), where b I from the bodies of the rules. Remove all (blocked) rules that still contain negations after the previous step.

The result is a positive program.

Example
win:- not(loose). loose :- not(win).

P{win} contains just the clause


win.

208 / 259

The Semantics of Negation

stable model denition

Denition
M is a stable model of P iff M is the (unique) minimal model of PM .

Example
win:- not(loose). loose :- not(win).

Has two stable models: {win} and {loose}.

209 / 259

The Semantics of Negation

graph colorability with stable models


% graph defined by node/1, arc/2 % % a node must have a color color(N,red) :- node(N), not(color(N,green)), not(color(N,blue)). color(N,green) :- node(N), not(color(N,blue)), not(color(N,red)). color(N,blue) :- node(N), not(color(N,red)), not(color(N,green)). % % no two adjacent nodes have the same color :- arc(X,Y), color(X,C), color(Y,C).

Any stable model of the above program represents a solution to this NP-complete problem.

210 / 259

The Semantics of Negation

answer set programming


Extension of logic programming based on the stable model semantics for datalog programs (nite universe).

211 / 259

The Semantics of Negation

answer set programming


Extension of logic programming based on the stable model semantics for datalog programs (nite universe). Without disjunction in the head, NP problems (e.g. satisability of a propositional formula) can be represented.

211 / 259

The Semantics of Negation

answer set programming


Extension of logic programming based on the stable model semantics for datalog programs (nite universe). Without disjunction in the head, NP problems (e.g. satisability of a propositional formula) can be represented. The stable model semantics can be extended to disjunctive (datalog) programs, which increases the expressiveness to 2 P (NP using an NP (1 P) oracle, e.g. deciding whether x y (x, y ) is valid).

211 / 259

The Semantics of Negation

answer set programming


Extension of logic programming based on the stable model semantics for datalog programs (nite universe). Without disjunction in the head, NP problems (e.g. satisability of a propositional formula) can be represented. The stable model semantics can be extended to disjunctive (datalog) programs, which increases the expressiveness to 2 P (NP using an NP (1 P) oracle, e.g. deciding whether x y (x, y ) is valid). Efcient (sic) implementations are available: e.g. the smodels or the dlv systems.

211 / 259

The Semantics of Negation

answer set programming


Extension of logic programming based on the stable model semantics for datalog programs (nite universe). Without disjunction in the head, NP problems (e.g. satisability of a propositional formula) can be represented. The stable model semantics can be extended to disjunctive (datalog) programs, which increases the expressiveness to 2 P (NP using an NP (1 P) oracle, e.g. deciding whether x y (x, y ) is valid). Efcient (sic) implementations are available: e.g. the smodels or the dlv systems. Applications in conguration (space shuttle), planning, diagnostics, . . . .

211 / 259

The Semantics of Negation

sudoku using answer set programming


(author: Kim Bauters)
size(0..8). % like type declaration 1{p(X, Y, Value) : size(Value)}1 :- size(X), size(Y). % A value may not appear more than once in any row. :- p(X, Y1, Value), p(X, Y2, Value), size(X;Y1;Y2;Value), Y1!=Y2. % A value may not appear more than once in any column. :- p(X1, Y, Value), p(X2, Y, Value), size(X1;X2;Y;Value), X1!=X2. % A value may not appear more than once in any subgrid. :- p(X1, Y1, Value), p(X2, Y2, Value), size(X1;X2;Y1;Y2;Value), (X1 != X2 | Y1 != Y2), X1 / 3 == X2 / 3, Y1 / 3 == Y2 / 3. hide size(_).

Note: smodels extension (syntax sugar):


2{p,q,r}3

is true in M iff it contains between 2 and 3 elements of is shorthand for the set {p(a, X ) | q(X )}.
212 / 259

{p, q, r }.
{p(a,X) : q(X)}

Abduction

Outline
1 2 3 4

Preliminaries Introduction Clausal logic

Language processing Reasoning with Incomplete Information Default Reasoning The Semantics of Negation Abduction Inductive Logic Programming

10

Logic programming
11

Representing structured knowledge Searching graphs Informed search

12 13

6 7

213 / 259

Abduction

abduction
Given a theory T and an observation O, nd an explanation E such that T E O E.g. given the theory
likes(peter,S) :- student_of(S,peter). likes(X,Y) :- friend(X,Y).

and the observation likes(peter,paul), possible explanations are {student_of(paul,peter)} or {friend(peter,paul)} Another possible explanation is {(likes(X,Y) :- friendly(Y)), friendly(paul)} but abductive explanations are usually restricted to ground literals with predicates that are undened in the theory (abducibles).

214 / 259

Abduction

an abduction algorithm
Try to prove observation from theory; when an abducible literal is encountered that cannot be resolved, add it to the explanation.
abduce(O,E):- % P+E |- O abduce(O,[],E). abduce(true,E,E) :- !. abduce((A,B),E0,E) :- !, abduce(A,E0,E1), abduce(B,E1,E). abduce(A,E0,E):clause(A,B), abduce(B,E0,E). abduce(A,E,E):- element(A,E). abduce(A,E,[A|E]):- not(element(A,E)), abducible(A). abducible(A):- not(clause(A,B)). % clauses are assumed to be definitions

215 / 259

Abduction

Example
likes(peter,S) :- student_of(S,peter). likes(X,Y) :- friend(X,Y). ?-abduce(likes(peter,paul),E) E = [student_of(paul,peter)]; E = [friend(paul,peter)]

216 / 259

Abduction

Problems with general clauses:

Example
flies(X) :- bird(X), not(abnormal(X)). abnormal(X) :- penguin(X). bird(X) :- penguin(X). bird(X) :- sparrow(X). ?-abduce(flies(tweety),E) E = [not(abnormal(tweety)),penguin(tweety)]; E = [not(abnormal(tweety)),sparrow(tweety)];

217 / 259

Abduction

adding negation as failure


% E explains not(A) if E does not explain A abduce(not(A),E,E):not(abduce(A,E,E)). .. abducible(A):A \= not(X), not(clause(A,B)). ?-abduce(flies(tweety),E) E = [sparrow(tweety)]

Still problems because abduce(not(A),E,E) assumes E is complete. E.g.


abduce(not(abnormal(X)),[],[])

succeeds and thus, if flies(X):- not(abnormal(X)),bird(X) any explanation of bird(X) will explain flies(X). Thus we need a special abduce_not/3 that provides evidence for accepting not(..).
218 / 259

Abduction

new interpreter 1/2


abduce(true,E,E) :- !. abduce((A,B),E0,E) :- !, abduce(A,E0,E1), abduce(B,E1,E). abduce(A,E0,E):clause(A,B), abduce(B,E0,E). abduce(A,E,E):element(A,E). abduce(A,E,[A|E]):not(element(A,E)), abducible(A), not(abduce_not(A,E,E)). % only if E does not explain not(A) abduce(not(A),E0,E):not(element(A,E0)), abduce_not(A,E0,E). abducible(A):A \= not(X), not(clause(A,B)).
219 / 259

Abduction

new interpreter 2/2


abduce_not((A,B),E0,E):- % disjunction! abduce_not(A,E0,E) ; abduce_not(B,E0,E). abduce_not(A,E0,E):setof(B,clause(A,B),L), % abduce_not(B) for each body B abduce_not_list(L,E0,E). abduce_not(A,E,E):element(not(A),E). % not(A) already assumed abduce_not(A,E,[not(A)|E]):- % assume not(A) if not(element(not(A),E)), % not already there, and abducible(A), % it is abducible, and not(abduce(A,E,E)). % E does not explain A abduce_not(not(A),E0,E):not(element(not(A),E0)), abduce(A,E0,E). abduce_not_list([],E,E). abduce_not_list([B|Bs],E0,E):abduce_not(B,E0,E1), % body cannot be used abduce_not_list(Bs,E1,E).
220 / 259

Abduction

Example
flies(X) :- bird(X),not(abnormal(X)). flies1(X) :- not(abnormal(X)),bird(X). abnormal(X) :- penguin(X). abnormal(X) :- dead(X). bird(X) :- penguin(X). bird(X) :- sparrow(X). ?- abduce(flies(tweety),E). E = [not(penguin(tweety)),not(dead(tweety)), sparrow(tweety)] ?- abduce(flies1(tweety),E). E = [sparrow(tweety), not(penguin(tweety)),not(dead(tweety))]

221 / 259

Abduction

diagnosis using abduction


X Y Sum Z and1 C1 and2 or1 Carry C2 xor1 S xor2

adder(X,Y,Z,Sum,Carry) :xor(X,Y,S),xor(Z,S,Sum), and(X,Y,C1),and(Z,S,C2), or(C1,C2,Carry). xor(0,0,0). xor(0,1,1). xor(1,0,1). xor(1,1,0). and(0,0,0). and(0,1,0). and(1,0,0). and(1,1,1). or(0,0,0). or(0,1,1). or(1,0,1). or(1,1,1).

describes normal operation


222 / 259

Abduction

The fault model of a system describes the behavior of each component when in a faulty state. We distinguish 2 such states: s0 (stuck at 0) and s1 (stuck at 1). A faulty component is described by a literal fault(NameComponent=State) Names of components can be nested as in
nameSubSystem-nameComponent adder(N,X,Y,Z,Sum,Carry):xorg(N-xor1,X,Y,S), xorg(N-xor2,Z,S,Sum), andg(N-and1,X,Y,C1), andg(N-and2,X,S,C2), org(N-or1,C1,C2,Carry). xorg(N,X,Y,Z) xorg(N,0,0,1) xorg(N,0,1,0) xorg(N,1,0,0) xorg(N,1,1,1) :::::xor(X,Y,Z). fault(N=s1). fault(N=s0). fault(N=s0). fault(N=s1).

223 / 259

Abduction

xandg(N,X,Y,Z):- and(X,Y,Z). xandg(N,0,0,1):- fault(N=s1). xandg(N,1,0,1):- fault(N=s1). org(N,X,Y,Z):- or(X,Y,Z). org(N,0,0,1):- fault(N=s1). org(N,1,0,0):- fault(N=s0).

xandg(N,0,1,1) :- fault(N=s1). xandg(N,1,1,0) :- fault(N=s0).

org(N,0,1,0) :- fault(N=s0). org(N,1,1,0) :- fault(N=s0).

diagnosis(Observation,Diagnosis):abduce(Observation,Diagnosis). ?-diagnosis(adder(a,0,0,1,0,1),D). D = [fault(a-or1=s1),fault(a-xor2=s0)]; D = [fault(a-and2=s1),fault(a-xor2=s0)]; D = [fault(a-and1=s1),fault(a-xor2=s0)]; D = [fault(a-and2=s1),fault(a-and1=s1), fault(a-xor2=s0)]; D = [fault(a-xor1=s1)];

224 / 259

Abduction

D = [fault(a-or1=s1),fault(a-and2=s0), fault(a-xor1=s1)]; D = [fault(a-and1=s1),fault(a-xor1=s1)]; D = [fault(a-and2=s0),fault(a-and1=s1), fault(a-xor1=s1)];

Minimal diagnoses are more plausible:


min_diagnosis(O,D) :diagnosis(O,D), not(diagnosis(O,D1),proper_subset(D1,D)). ?-min_diagnosis(adder(a,0,0,1,0,1),D). D = [fault(a-or1=s1),fault(a-xor2=s0)]; D = [fault(a-and2=s1),fault(a-xor2=s0)]; D = [fault(a-and1=s1),fault(a-xor2=s0)]; D = [fault(a-xor1=s1)];

225 / 259

Inductive Logic Programming

Outline
1 2 3 4

Preliminaries Introduction Clausal logic

Language processing Reasoning with Incomplete Information Default Reasoning The Semantics of Negation Abduction Inductive Logic Programming

10

Logic programming
11

Representing structured knowledge Searching graphs Informed search

12 13

6 7

226 / 259

Inductive Logic Programming

Introduction

Inductive logic programming (ILP)


Problem: Given B background knowledge (theory, i.e. LP ) E + positive examples (set of facts), E negative examples (set of facts), Find a theory H (hypothesis) such that p E + B H |= p n E B H |= n Of course, we assume that e E + E B |= e Difference with abduction: H is a theory instead of a set of facts.

227 / 259

Inductive Logic Programming

Introduction

Relationship with learning


Concept learning tries to nd a suitable concept in a description space where descriptions are related via generalization/specialization relationships. Examples are at the bottom of the generalization hierarchy. A concept is suitable if it covers (generalizes) all positive and none of the negative examples. Learning capabilities depend on the characteristics of the description space: too rough makes learning impossible, too ne leads to trivial concepts (e.g. when the description space supports disjunction). A well-known algorithm is Mitchells candidate elimination algorithm where upper and lower bounds of possible solutions are updated according to input examples.

228 / 259

Inductive Logic Programming

Introduction

ILP as concept learning

ILP as discussed here can be seen as concept learning where the description space consists of LPs. The generalization relationship may be based on subsumption between clauses.

229 / 259

Inductive Logic Programming

Introduction

Example: learning append/3

?- induce_rlgg([ +append([1,2],[3,4],[1,2,3,4]), +append([a],[],[a]), +append([],[],[]), +append([],[1,2,3],[1,2,3]), +append([2],[3,4],[2,3,4]), +append([],[3,4],[3,4]), -append([a],[b],[b]), -append([c],[b],[c,a]), -append([1,2],[],[1,3]) ], Clauses).

230 / 259

Inductive Logic Programming

Introduction

Example: learning append/3


RLGG of append([1,2],[3,4],[1,2,3,4]) and append([a],[],[a]) is append([X|Y],Z,[X|U]) :- [append(Y,Z,U)] Covered example: append([1,2],[3,4],[1,2,3,4]) Covered example: append([a],[],[a]) Covered example: append([2],[3,4],[2,3,4]) RLGG of append([],[],[]) and append([],[1,2,3],[1,2,3]) is append([],X,X) :- [] Covered example: append([],[],[]) Covered example: append([],[1,2,3],[1,2,3]) Covered example: append([],[3,4],[3,4]) Clauses = [(append([],X,X) :- []), (append([X|Y],Z,[X|U]) :-

[append(Y,Z,U)])]

231 / 259

Inductive Logic Programming

Generalizing clauses

generalizing clauses: -subsumption

Denition
A clause c1 -subsumes a clause c2 iff there exists a substitution such that c1 c2 (c1 is more general or more widely applicable thant c2 ). Here clauses are seen as sets of (positive and negative) literals (disjunctions).

232 / 259

Inductive Logic Programming

Generalizing clauses

-subsumption examples
The clause
element(X,V) :element(X,Z)

-subsumes, using = {V [Y|Z]},


element(X,[Y|Z]) :element(X,Z)

(i.e. specializes element(X,V) :- element(X,Z)). The clause


a(X) :b(X).

-subsumes (with identity)


a(X) :b(X), c(X).

233 / 259

Inductive Logic Programming

Generalizing clauses

-subsumption implementation

% (H1:- B1) subsumes (H2 :- B2) theta_subsumes((H1:- B1),(H2 :- B2)):verify((grounded((H2:- B2)), H1=H2,subset(B1,B2))). % H1=H2 creates substitution, note that H2 has no vars grounded(Term):% instantiate vars in Term to terms of the form % $VAR(i) where i is different for each distinct % var, first i=0, last = N-1 numbervars(Term,0,N). verify(Goal) :% prove without binding not(not(call(Goal))).

234 / 259

Inductive Logic Programming

Generalizing clauses

-subsumption implementation

Example
?theta_subsumes( (element(X,V):- []), (element(X,V):- [element(X,Z)])).

yes. ?- theta_subsumes((element(X,a):- []), (element(X,V):- [])). no.

235 / 259

Inductive Logic Programming

Generalizing clauses

-subsumption vs. logical consequence


Theorem
If c1 -subsumes c2 then c1 |= c2 The reverse is not true:
a(X) :p(X) :b(X). % c1 p(X). % c2, tautology.

Here c1 |= c2 but there is no substitution such that c1 c2

Theorem
The set of (reduced) clauses form a lattice, i.e. a unique least general generalization lgg(c1 , c2 ) exists for any two clauses c1 and c2 . (a clause is reduced if it is minimal in the collection of equivalent clauses)
236 / 259

Inductive Logic Programming

Generalizing clauses

generalizing 2 terms

Consider the terms


element(1,[1]). %a1 element(z,[z,y,x]). %a2 element(X,[X|Y]). % a3

a3 subsumes a1 using {X/1, Y/[]} and a3 subsumes a2 using {X/z, Y/[y,x]} Moreover, a3 is the least generalization, i.e. every other term that -subsumes a1 and a2 also -subsumes a3 .

237 / 259

Inductive Logic Programming

Generalizing clauses

anti_unify
:- op(600,xfx,<-). % to record (inverse) substitutions anti_unify(Term1,Term2,Term):% use accumulators S1, S2 anti_unify(Term1,Term2,Term,[],S1,[],S2). anti_unify(Term1,Term2,Term1,S1,S1,S2,S2):Term1 == Term2,!. anti_unify(Term1,Term2,V,S1,S1,S2,S2):subs_lookup(S1,S2,Term1,Term2,V), !. % already substituted anti_unify(Term1,Term2,Term,S10,S1,S20,S2):nonvar(Term1), nonvar(Term2), functor(Term1,F,N), functor(Term2,F,N),!, functor(Term,F,N), % create F(X1,..,Xn) anti_unify_args(N,Term1,Term2,Term,S10,S1,S20,S2). % Create new variable V and substitutions V->Term1, V->Term2 anti_unify(Term1,Term2, V, S10,[Term1<-V|S10], S20,[Term2<-V|S20]).

238 / 259

Inductive Logic Programming

Generalizing clauses

% anti_unify_args(N,T1,T2,T,..): % anti-unify first N arguments of T1, T2 anti_unify_args(0,Term1,Term2,Term,S1,S1,S2,S2). anti_unify_args(N,Term1,Term2,Term,S10,S1,S20,S2):N>0,N1 is N-1, arg(N,Term1,Arg1), arg(N,Term2,Arg2), arg(N,Term,ArgN), anti_unify(Arg1,Arg2,ArgN,S10,S11,S20,S21), anti_unify_args(N1,Term1,Term2,Term,S11,S1,S21,S2). % subs_lookup(+subst1,+subst2,+term1,+term2,-var) % subst1(V) = term1, subst2(V) = term2 subs_lookup([T1<-V|Subs1],[T2<-V|Subs2],Term1,Term2,V):T1 == Term1, T2 == Term2,!. subs_lookup([S1|Subs1],[S2|Subs2],Term1,Term2,V):subs_lookup(Subs1,Subs2,Term1,Term2,V).

Example
?- anti_unify(2*2=2+2,2*3=3+3,T,[],S1,[],S2). T = 2 * _G191 = _G191 + _G191 S1 = [2 <- _G191] S2 = [3 <- _G191]
239 / 259

Inductive Logic Programming

Generalizing clauses

generalizing 2 clauses (1/2)

theta_lgg((H1:-B1),(H2:-B2),(H:-B)):anti_unify(H1,H2,H,[],S10,[],S20), theta_lgg_bodies(B1,B2, [],B, S10,S1, S20,S2). % theta_lgg_bodies considers each pair of literals % from both bodies theta_lgg_bodies([],B2,B,B,S1,S1,S2,S2). theta_lgg_bodies([Lit|B1],B2, B0,B, S10,S1, S20,S2):theta_lgg_literal(Lit,B2, B0,B00, S10,S11, S20,S21), theta_lgg_bodies(B1,B2, B00,B, S11,S1, S21,S2).

240 / 259

Inductive Logic Programming

Generalizing clauses

generalizing 2 clauses (2/2)

% theta_lgg_literal anti-unifies Lit1 with each % literal in 2nd arg theta_lgg_literal(Lit1,[], B,B, S1,S1, S2,S2). theta_lgg_literal(Lit1,[Lit2|B2], B0,B, S10,S1, S20,S2):same_predicate(Lit1,Lit2), anti_unify(Lit1,Lit2,Lit,S10,S11,S20,S21), theta_lgg_literal(Lit1,B2,[Lit|B0],B,S11,S1,S21,S2). theta_lgg_literal(Lit1,[Lit2|B2],B0,B,S10,S1,S20,S2):not(same_predicate(Lit1,Lit2)), theta_lgg_literal(Lit1,B2,B0,B,S10,S1,S20,S2). same_predicate(Lit1,Lit2) :functor(Lit1,P,N), functor(Lit2,P,N).

241 / 259

Inductive Logic Programming

Generalizing clauses

theta_lgg example

Example
?- theta_lgg( (element(c,[b,c]):- [ element(c,[c]) ]), (element(d,[b,c,d]):- [ element(d,[c,d]), element(d,[d]) ]), C). C = element(X, [b, c|Y]):- [element(X,[X]), element(X,[c|Y])]

242 / 259

Inductive Logic Programming

Generalizing clauses

theta_lgg example

Example
?- theta_lgg( (reverse([2,1],[3],[1,2,3]):- [ reverse([1],[2,3],[1,2,3]) ]), (reverse([a],[],[a]) :- [ reverse([],[a],[a]) ]), C). C = reverse([X|Y], Z, [U|V]) :- [reverse(Y, [X|Z], [U|V])]

243 / 259

Inductive Logic Programming

A bottom-up induction algorithm

a bottom-up induction algorithm

Denition
The relative least general generalization rlgg(e1 , e2 , M) of two positive examples relative to a (partial) model M is dened by rlgg(e1 , e2 , M) = lgg((e1 : M ), (e2 : M ))

244 / 259

Inductive Logic Programming

A bottom-up induction algorithm

a bottom-up induction algorithm: example


append([1,2],[3,4],[1,2,3,4]). append([],[],[]). append([a],[],[a]). append([2],[3,4],[2,3,4]).

the rlgg on the rst 2 examples is determined using


?- theta_lgg( (append([1,2],[3,4],[1,2,3,4]) :- [ append([1,2],[3,4],[1,2,3,4]), append([a],[],[a]), append([],[],[]), append([2],[3,4],[2,3,4]) ]), (append([a],[],[a]):- [ append([1,2],[3,4],[1,2,3,4]), append([a],[],[a]), append([],[],[]), append([2],[3,4],[2,3,4]) ]), C), write_ln(C).
245 / 259

Inductive Logic Programming

A bottom-up induction algorithm

example: result
append([X|Y], Z, [X|U]) :- [ append([2], [3, 4], [2, 3, 4]), append(Y, Z, U), append([V], Z, [V|Z]), append([K|L], [3, 4], [K, M, N|O]), append(L, P, Q), append([], [], []), append(R, [], R), append(S, P, T), append([A], P, [A|P]), append(B, [], B), append([a], [], [a]), append([C|L], P, [C|Q]), append([D|Y], [3, 4], [D, E, F|G]), append(H, Z, I), append([X|Y], Z, [X|U]), append([1, 2], [3, 4], [1, 2, 3, 4]) ]

too complex!
246 / 259

Inductive Logic Programming

A bottom-up induction algorithm

constrained clauses
We remove: ground facts (examples) are redundant literals involving variables not occurring in the head: i.e. we restrict to constrained clauses. The example result then becomes:
append([X|Y], Z, [X|U]) :append(Y, Z, U), append([X|Y], Z, [X|U]).

The head is part of the body: it can also be removed if we restrict to strictly constrained clauses where the variables in the body are a strict subset of the variables in the head.

247 / 259

Inductive Logic Programming

A bottom-up induction algorithm

computing the rlgg


% rlgg(E1,E2,M,C): C is RLGG of E1 and E2 relative to M rlgg(E1,E2,M,(H:- B)):anti_unify(E1,E2,H,[],S10,[],S20), varsin(H,V), % determine variables in head of clause rlgg_bodies(M,M,[],B,S10,S1,S20,S2,V). % rlgg_bodies(B0,B1,BR0,BR,S10,S1,S20,S2,V): rlgg all % literals in B0 with all literals in B1, yielding BR % containing only vars in V rlgg_bodies([],B2,B,B,S1,S1,S2,S2,V). rlgg_bodies([L|B1],B2,B0,B,S10,S1,S20,S2,V):rlgg_literal(L,B2,B0,B00,S10,S11,S20,S21,V), rlgg_bodies(B1,B2,B00,B,S11,S1,S21,S2,V).

248 / 259

Inductive Logic Programming

A bottom-up induction algorithm

rlgg_literal(L1,[],B,B,S1,S1,S2,S2,V). rlgg_literal(L1,[L2|B2],B0,B,S10,S1,S20,S2,V):same_predicate(L1,L2), anti_unify(L1,L2,L,S10,S11,S20,S21), varsin(L,Vars), var_proper_subset(Vars,V), % no new variables in literal !, rlgg_literal(L1,B2,[L|B0],B,S11,S1,S21,S2,V). rlgg_literal(L1,[L2|B2],B0,B,S10,S1,S20,S2,V):rlgg_literal(L1,B2,B0,B,S10,S1,S20,S2,V).

249 / 259

Inductive Logic Programming

A bottom-up induction algorithm

varsin/2
% varsin(+term,-list) list is list of % variables occurring in term varsin(Term,Vars):varsin(Term,[],V), sort(V,Vars). varsin(V,Vars,[V|Vars]):var(V). varsin(Term,V0,V):functor(Term,F,N), varsin_args(N,Term,V0,V). % varsin_args(N,T,V0,V) add vars in first % N args of T to V0, yielding V varsin_args(0,Term,Vars,Vars). varsin_args(N,Term,V0,V):N>0, N1 is N-1, arg(N,Term,ArgN), varsin(ArgN,V0,V1), varsin_args(N1,Term,V1,V).

250 / 259

Inductive Logic Programming

A bottom-up induction algorithm

var_remove_one/3, var_proper_subset/2

var_remove_one(X,[Y|Ys],Ys) :X == Y. var_remove_one(X,[Y|Ys],[Y|Zs) :var_remove_one(X,Ys,Zs). var_proper_subset([],Ys) :Ys \= []. var_proper_subset([X|Xs],Ys) :var_remove_one(X,Ys,Zs), var_proper_subset(Xs,Zs).

251 / 259

Inductive Logic Programming

A bottom-up induction algorithm

rlgg
Example
?rlgg( append([1,2],[3,4],[1,2,3,4]), append([a],[],[a]), [ append([1,2],[3,4],[1,2,3,4]), append([a],[],[a]), append([],[],[]), append([2],[3,4],[2,3,4]) ], (H:- B)). append([X|Y], Z, [X|U]) :- [ append([2], [3, 4], [2, 3, 4]), append(Y, Z, U), append([], [], []), append([a], [], [a]), append([1, 2], [3, 4], [1, 2, 3, 4]) ]
252 / 259

Inductive Logic Programming

A bottom-up induction algorithm

main algorithm

construct rlgg of two examples remove positive examples that are covered by the resulting clause remove further literals (generalizing the clause) as long as the clause does not cover any negative examples based on GOLEM system (Muggleton & Feng, 1990)

253 / 259

Inductive Logic Programming

A bottom-up induction algorithm

induce_rlgg implementation
induce_rlgg(Exs,Clauses):pos_neg(Exs,Poss,Negs), bg_model(BG), append(Poss,BG,Model), induce_rlgg(Poss,Negs,Model,Clauses). % induce_rlgg(+pos_exs,+neg_exs,+model,-clauses) induce_rlgg(Poss,Negs,Model,Clauses):covering(Poss,Negs,Model,[],Clauses). % pos_neg(+exs,-poss,-negs) split % positive and negative examples pos_neg([],[],[]). pos_neg([+E|Exs],[E|Poss],Negs):pos_neg(Exs,Poss,Negs). pos_neg([-E|Exs],Poss,[E|Negs]):pos_neg(Exs,Poss,Negs).

254 / 259

Inductive Logic Programming

A bottom-up induction algorithm

% covering(+pos_exs, +neg_exs, +model,+old_hypothesis, % -new_hypothesis): construct new_hypothesis % covering all of pos_exs and none of the neg_exs covering(Poss,Negs,Model,Hyp0,NewHyp) :construct_hypothesis(Poss,Negs,Model,Hyp), !, remove_pos(Poss,Model,Hyp,NewPoss), % cover remaining posexs covering(NewPoss,Negs,Model,[Hyp|Hyp0],NewHyp). covering(P,N,M,H0,H) :append(H0,P,H). % add uncovered exs to hypothesis % remove_pos(+old_pos_exs,+model,+clause,-new_pos_ex) % remove posexs that are covered by clause + model, % yielding new_pos_ex remove_pos([],M,H,[]). remove_pos([P|Ps],Model,Hyp,NewP) :covers_ex(Hyp,P,Model), !, write(Covered example: ), write_ln(P), remove_pos(Ps,Model,Hyp,NewP). remove_pos([P|Ps],Model,Hyp,[P|NewP]):remove_pos(Ps,Model,Hyp,NewP).

255 / 259

Inductive Logic Programming

A bottom-up induction algorithm

% covers_ex(+clause,+example,+model): % example is covered by clause covers_ex((Head:- Body),Example,Model):verify( (Head=Example, forall(element(L,Body),element(L,Model)) )). % construct_hypothesis(+pos_exs,+neg_exs,+model,-clause) construct_hypothesis([E1,E2|Es],Negs,Model,Clause):write(RLGG of ), write(E1), write( and ), write(E2), write( is), rlgg(E1,E2,Model,Cl), reduce(Cl,Negs,Model,Clause), !, nl,tab(5), write_ln(Clause). construct_hypothesis([E1,E2|Es],Negs,Model,Clause):write_ln( too general), construct_hypothesis([E2|Es],Negs,Model,Clause).

256 / 259

Inductive Logic Programming

A bottom-up induction algorithm

% reduce(+old_clause,+neg_exs,+model,-new_clause) % remove redundant literals from body and ensure % that no negexs are covered reduce((H:- B0),Negs,M,(H:-B)):% remove literals of M from B0, giving B1 setof0(L, (element(L,B0), not(var_element(L,M))), B1), % body B consists of literals from B1 that are necessary % not to cover negative examples reduce_negs(H,B1,[],B,Negs,M). % covers_neg(+clause,+negs,+model,-n) % n negative example from negs covered by clause + model covers_neg(Clause,Negs,Model,N):- element(N,Negs), covers_ex(Clause,N,Model).

257 / 259

Inductive Logic Programming

A bottom-up induction algorithm

% reduce_negs(+H,+In,+B0,-B,+Negs,+Model) % B is B0 + subsequence of In such that (H:- B) + Model % does not cover elements of Negs reduce_negs(H,[L|Rest],B0,B,Negs,Model):% try removing L append(B0,Rest,Body), not(covers_neg((H:- Body),Negs,Model,N)), !, reduce_negs(H,Rest,B0,B,Negs,Model). reduce_negs(H,[L|Rest],B0,B,Negs,Model):% L cannot be removed reduce_negs(H,Rest,[L|B0],B,Negs,Model). reduce_negs(H,[],Body,Body,Negs,Model):not(covers_neg((H:- Body),Negs,Model,N)). var_element(X,[Y|Ys]):X == Y. % syntactic identity var_element(X,[Y|Ys]):var_element(X,Ys).

258 / 259

Inductive Logic Programming

A bottom-up induction algorithm

further developments

Top-down (specializing) induction: cfr. book, section 9.3 Application examples:


scientic discovery: e.g. predicting 3-dimensional shape of proteins from their amino acid sequence data mining; this may use a probabilistic semantics

259 / 259

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy