Logic Programming The Basics Temur Kutsia Research Institute for - - PowerPoint PPT Presentation

logic programming
SMART_READER_LITE
LIVE PREVIEW

Logic Programming The Basics Temur Kutsia Research Institute for - - PowerPoint PPT Presentation

Logic Programming The Basics Temur Kutsia Research Institute for Symbolic Computation Johannes Kepler University Linz, Austria kutsia@risc.jku.at Contents Basics of P ROLOG Facts Questions Variables Conjunction Rules P ROLOG Used to


slide-1
SLIDE 1

Logic Programming

The Basics Temur Kutsia

Research Institute for Symbolic Computation Johannes Kepler University Linz, Austria kutsia@risc.jku.at

slide-2
SLIDE 2

Contents

Basics of PROLOG Facts Questions Variables Conjunction Rules

slide-3
SLIDE 3

PROLOG

Used to solve problems involving

◮ objects, and ◮ relationships between objects.

slide-4
SLIDE 4

Relationships

Example

John owns the book

◮ The relationship: ownership ◮ The objects: book, John

Directional:

◮ John owns the book ◮ Not: The book owns John

slide-5
SLIDE 5

Questions

Example

Does John own the book? Asks a question about a relationship already established.

slide-6
SLIDE 6

Rules

Describe Relationships Using other Relationships.

Example

Two people are sisters if they are both female and have the same parents. Gives a definition of one relationship given other relationships.

◮ Both must be females. ◮ Both must have the same parents. ◮ If two people satisfy these rules, then they are sisters

(according to our simplified relationship)

slide-7
SLIDE 7

Programming in PROLOG

◮ Declaring Facts about objects and their relationships. ◮ Defining Rules about objects and their relationships. ◮ Asking Questions about objects and their relationships.

slide-8
SLIDE 8

PROLOG

◮ Program can be thought of as a storehouse of facts and

rules.

◮ Conversational Language: The user can ask questions

about the set of facts and rules in the PROLOG program.

slide-9
SLIDE 9

PROLOG

Sisters Example:

◮ A rule defining sisters and the facts about the people

involved.

◮ The user would ask:

Are these two people sisters?

◮ The system would answer

yes (true) or no (false)

slide-10
SLIDE 10

Parts of Fact

slide-11
SLIDE 11

Order of Objects

slide-12
SLIDE 12

Examples of Facts

Example

Gold is valuable. valuable(gold) Jane is a female. female(jane) John owns some gold.

  • wns(john, gold)

John is the father of Mary. father(john, mary)

slide-13
SLIDE 13

Examples of Facts

Example

Gold is valuable. valuable(gold) Jane is a female. female(jane) John owns some gold.

  • wns(john, gold)

John is the father of Mary. father(john, mary)

Are these expressions really facts? Is there anything missing?

slide-14
SLIDE 14

Interpretation of Names

The name refers to an object.

◮ Semantic Meaning: Given by the programmer. ◮ Syntactic Meaning: a set of characters, as PROLOG sees it.

slide-15
SLIDE 15

Interpretation of Names

Name refers to an object.

◮ Name gold can refer to:

◮ a particular lump of gold, or ◮ the chemical element Gold having atomic number 79.

◮ valuable(gold) can mean:

◮ that particular lump of gold, named gold, is valuable, or ◮ the chemical element Gold, named gold, is valuable.

The programmer decides (in her usage) the meaning.

slide-16
SLIDE 16

Fact Terminology

slide-17
SLIDE 17

Database

Definition

In PROLOG, database is a collection of facts.

◮ PROLOG draws its knowledge from these facts. ◮ The programmer is responsible for their accuracy.

slide-18
SLIDE 18

Questions

◮ The database contains the facts from which the questions

are answered.

◮ A question can look exactly like a fact:

  • wns(mary, book).

◮ The difference is in which mode one is in.

slide-19
SLIDE 19

Questions

In the interactive question mode (indicated by the question mark and dash ?-):

◮ Question: ?- owns(mary, book). ◮ Meaning:

◮ If mary is interpreted as a person called Mary, and book is

interpreted as some particular book, then

◮ ?- owns(mary, book). means: Does Mary own the

book?

slide-20
SLIDE 20

Database Search

Example

Facts in the database: likes(joe, fish). likes(joe, mary). likes(mary, book). likes(john, book). Questions: ?- likes(joe, money). no ?- likes(joe, mary). yes ?- king(john, france). no

slide-21
SLIDE 21

Knowledge

The questions are always answered with respect to the database.

Example

Facts in the database: human(socrates). human(aristotle). athenian(socrates). Question: Is Socrates Greek? ?- greek(socrates). The answer with respect to this database is No.

slide-22
SLIDE 22

Questions

Up until now questions just reflect exactly the database. Does Mary like the book? ?- likes(mary, book). More Interesting Question: What objects does Mary like? Variables.

slide-23
SLIDE 23

Variables

Tiresome to ask about every object: likes(john, this). likes(john, that). Better to ask: What does John like?

  • r

Does John like X? (i.e. use variables)

slide-24
SLIDE 24

Question With Variables

Does John like X? ?- likes(john, X).

  • r

?- likes(john, SomethingThatJohnLikes). X and SomethingThatJohnLikes are variables. Variable begins with a capital letter.

slide-25
SLIDE 25

PROLOG Answer

Database: likes(john, flowers). Question: ?- likes(john, X). PROLOG answers: X=flowers

slide-26
SLIDE 26

Many Answers

Database: likes(john, flowers). likes(john, mary). likes(paul, mary). Question: ?- likes(john, X). PROLOG answers: X=flowers and the user acknowledges X=mary and the user acknowledges no

slide-27
SLIDE 27

Placemarker

◮ The first match is found: X=flowers. ◮ The user acknowledges. ◮ From that place on the next match is found (the search

continues).

◮ From the place of the last instantiation no more match was

found.

◮ Thus answer: no.

slide-28
SLIDE 28

Conjunctions

More Complicated Relationships: Does Mary like John and does John like Mary? Both Conditions must be fulfilled.

slide-29
SLIDE 29

Conjunctions

Comma means Conjunction: ?- likes(john, mary), likes(mary, john). likes(mary, food). likes(mary, wine). likes(john, wine). likes(john, mary). Answer: no A match for likes(john, mary) but none for likes(mary, john)

slide-30
SLIDE 30

Conjunctions with Variables

Is there anything that both mary and john like? Find out what Mary likes and then see if John likes it. ?- likes(mary, X), likes(john, X).

slide-31
SLIDE 31

Backtracking

◮ Find match for the first goal. ◮ Then see if it matches the second. ◮ If not, find another match for the first. ◮ See if this matches the second. ◮ etc.

slide-32
SLIDE 32

Match First

slide-33
SLIDE 33

Match Second

slide-34
SLIDE 34

Backtrack

slide-35
SLIDE 35

Success

slide-36
SLIDE 36

Rules

◮ How to express that John likes all people?

slide-37
SLIDE 37

Rules

◮ How to express that John likes all people? ◮ Listing all people?

slide-38
SLIDE 38

Rules

◮ How to express that John likes all people? ◮ Listing all people?

◮ likes(john, alfred).

slide-39
SLIDE 39

Rules

◮ How to express that John likes all people? ◮ Listing all people?

◮ likes(john, alfred). ◮ likes(john, bertrand).

slide-40
SLIDE 40

Rules

◮ How to express that John likes all people? ◮ Listing all people?

◮ likes(john, alfred). ◮ likes(john, bertrand). ◮ likes(john, charles).

slide-41
SLIDE 41

Rules

◮ How to express that John likes all people? ◮ Listing all people?

◮ likes(john, alfred). ◮ likes(john, bertrand). ◮ likes(john, charles). ◮ likes(john, david). ◮ etc.

slide-42
SLIDE 42

Rules

◮ How to express that John likes all people? ◮ Listing all people?

◮ likes(john, alfred). ◮ likes(john, bertrand). ◮ likes(john, charles). ◮ likes(john, david). ◮ etc.

◮ Not feasible. More compact way: Using rules.

John likes any object provided it is a person.

slide-43
SLIDE 43

Rule Examples

◮ Rules state Dependence:

I use an umbrella if there is rain.

slide-44
SLIDE 44

Rule Examples

◮ Rules state Dependence:

I use an umbrella if there is rain.

◮ Rules Define:

X is a bird if X is an animal and X has feathers.

slide-45
SLIDE 45

Formulating Rules

◮ John likes anyone who likes wine.

slide-46
SLIDE 46

Formulating Rules

◮ John likes anyone who likes wine. ◮ John likes any something if it likes wine.

slide-47
SLIDE 47

Formulating Rules

◮ John likes anyone who likes wine. ◮ John likes any something if it likes wine. ◮ John likes X if X likes wine.

slide-48
SLIDE 48

Rule Syntax

likes(john, X)

  • :-

likes(X, wine).

  • head

rule delimiter body

slide-49
SLIDE 49

Variable Scope

The occurrences of X within a rule: likes(john, X) :-likes(X, wine), likes(X, food).

slide-50
SLIDE 50

Variable Scope

The occurrences of X within a rule: likes(john, X) :-likes(X, wine), likes(X, food). instantiates here

slide-51
SLIDE 51

Variable Scope

The occurrences of X within a rule: likes(john, X) :-likes(X, wine), likes(X, food). instantiates here checked here

slide-52
SLIDE 52

Variable Scope

The occurrences of X within a rule: likes(john, X) :-likes(X, wine), likes(X, food). returns here instantiates here checked here

slide-53
SLIDE 53

Royal Parents

Example

◮ The parents of X are Y and Z. ◮ Y is the mother. ◮ Z is the father.

Database: male(albert). male(edward). female(alice). female(victoria). parents(edward, victoria, albert). parents(alice, victoria, albert).

slide-54
SLIDE 54

Sisters

Example

X is a sister of Y if:

slide-55
SLIDE 55

Sisters

Example

X is a sister of Y if:

◮ X is female,

slide-56
SLIDE 56

Sisters

Example

X is a sister of Y if:

◮ X is female, ◮ X has parents M and F

,

slide-57
SLIDE 57

Sisters

Example

X is a sister of Y if:

◮ X is female, ◮ X has parents M and F

,

◮ Y has parents M and F

.

slide-58
SLIDE 58

Sisters

Example

X is a sister of Y if:

◮ X is female, ◮ X has parents M and F

,

◮ Y has parents M and F

. Rule: sister(X, Y) :- female(X), parents(X, M, F), parents(Y, M, F).

slide-59
SLIDE 59

Sisters Question

Rule: sister(X, Y) :- female(X), parents(X, M, F), parents(Y, M, F). Question: sister(alice, edward).

slide-60
SLIDE 60

Sisters Question

Rule: sister(X, Y) :- female(X), parents(X, M, F), parents(Y, M, F). Question: sister(alice, edward).

◮ The question (goal) matches the head of the rule, if one

replaces X with alice and Y with edward.

slide-61
SLIDE 61

Sisters Question

Rule: sister(X, Y) :- female(X), parents(X, M, F), parents(Y, M, F). Question: sister(alice, edward).

◮ The question (goal) matches the head of the rule, if one

replaces X with alice and Y with edward.

◮ The instance of the body becomes a new goal:

female(alice), parents(alice, M, F), parents(edward, M, F).

slide-62
SLIDE 62

Is Alice Edward’s Sister?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). sister(alice,edward)

slide-63
SLIDE 63

Is Alice Edward’s Sister?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). sister(alice,edward)

slide-64
SLIDE 64

Is Alice Edward’s Sister?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). sister(alice,edward)

slide-65
SLIDE 65

Is Alice Edward’s Sister?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X0, Y0):- female(X0), parents(X0, M0, F0), parents(Y0, M0, F0). sister(alice,edward)

slide-66
SLIDE 66

Is Alice Edward’s Sister?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X0, Y0):- female(X0), parents(X0, M0, F0), parents(Y0, M0, F0). sister(alice,edward) X0=alice, Y0=edward

slide-67
SLIDE 67

Is Alice Edward’s Sister?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X0, Y0):- female(X0), parents(X0, M0, F0), parents(Y0, M0, F0). X0=alice, Y0=edward 7 sister(alice,edward) female(alice), parents(alice,M0,F0), parents(edward,M0,F0).

slide-68
SLIDE 68

Is Alice Edward’s Sister?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). X0=alice, Y0=edward 7 sister(alice,edward) female(alice), parents(alice,M0,F0), parents(edward,M0,F0).

slide-69
SLIDE 69

Is Alice Edward’s Sister?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). X0=alice, Y0=edward 7 sister(alice,edward) female(alice), parents(alice,M0,F0), parents(edward,M0,F0).

slide-70
SLIDE 70

Is Alice Edward’s Sister?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). X0=alice, Y0=edward 7 sister(alice,edward) female(alice), parents(alice,M0,F0), parents(edward,M0,F0).

slide-71
SLIDE 71

Is Alice Edward’s Sister?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). X0=alice, Y0=edward 7 sister(alice,edward) 3 female(alice), parents(alice,M0,F0), parents(edward,M0,F0). parents(alice,M0,F0), parents(edward,M0,F0).

slide-72
SLIDE 72

Is Alice Edward’s Sister?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). X0=alice, Y0=edward 7 sister(alice,edward) 3 female(alice), parents(alice,M0,F0), parents(edward,M0,F0). parents(alice,M0,F0), parents(edward,M0,F0).

slide-73
SLIDE 73

Is Alice Edward’s Sister?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). X0=alice, Y0=edward 7 sister(alice,edward) 3 female(alice), parents(alice,M0,F0), parents(edward,M0,F0). parents(alice,M0,F0), parents(edward,M0,F0).

slide-74
SLIDE 74

Is Alice Edward’s Sister?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). X0=alice, Y0=edward 7 sister(alice,edward) 3 female(alice), parents(alice,M0,F0), parents(edward,M0,F0). parents(alice,M0,F0), parents(edward,M0,F0). M0=victoria, F0=albert

slide-75
SLIDE 75

Is Alice Edward’s Sister?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). X0=alice, Y0=edward 7 sister(alice,edward) 3 female(alice), parents(alice,M0,F0), parents(edward,M0,F0). 6 parents(alice,M0,F0), parents(edward,M0,F0). parents(edward,victoria,albert). M0=victoria, F0=albert

slide-76
SLIDE 76

Is Alice Edward’s Sister?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). X0=alice, Y0=edward 7 sister(alice,edward) 3 female(alice), parents(alice,M0,F0), parents(edward,M0,F0). 6 parents(alice,M0,F0), parents(edward,M0,F0). M0=victoria, F0=albert parents(edward,victoria,albert).

slide-77
SLIDE 77

Is Alice Edward’s Sister?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). X0=alice, Y0=edward 7 sister(alice,edward) 3 female(alice), parents(alice,M0,F0), parents(edward,M0,F0). 6 parents(alice,M0,F0), parents(edward,M0,F0). M0=victoria, F0=albert 5 parents(edward,victoria,albert).

slide-78
SLIDE 78

Is Alice Edward’s Sister?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). X0=alice, Y0=edward 7 sister(alice,edward) 3 female(alice), parents(alice,M0,F0), parents(edward,M0,F0). 6 parents(alice,M0,F0), parents(edward,M0,F0). M0=victoria, F0=albert 5 parents(edward,victoria,albert).

slide-79
SLIDE 79

Who’s Sister Is Alice?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). sister(alice,X)

slide-80
SLIDE 80

Who’s Sister Is Alice?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). sister(alice,X)

slide-81
SLIDE 81

Who’s Sister Is Alice?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). sister(alice,X)

slide-82
SLIDE 82

Who’s Sister Is Alice?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X0, Y0):- female(X0), parents(X0, M0, F0), parents(Y0, M0, F0). sister(alice,X)

slide-83
SLIDE 83

Who’s Sister Is Alice?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X0, Y0):- female(X0), parents(X0, M0, F0), parents(Y0, M0, F0). sister(alice,X) X0=alice, Y0=X

slide-84
SLIDE 84

Who’s Sister Is Alice?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X0, Y0):- female(X0), parents(X0, M0, F0), parents(Y0, M0, F0). X0=alice, Y0=X 7 sister(alice,X) female(alice), parents(alice,M0,F0), parents(X,M0,F0).

slide-85
SLIDE 85

Who’s Sister Is Alice?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). X0=alice, Y0=X 7 sister(alice,X) female(alice), parents(alice,M0,F0), parents(X,M0,F0).

slide-86
SLIDE 86

Who’s Sister Is Alice?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). X0=alice, Y0=X 7 sister(alice,X) female(alice), parents(alice,M0,F0), parents(X,M0,F0).

slide-87
SLIDE 87

Who’s Sister Is Alice?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). X0=alice, Y0=X 7 sister(alice,X) female(alice), parents(alice,M0,F0), parents(X,M0,F0).

slide-88
SLIDE 88

Who’s Sister Is Alice?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). X0=alice, Y0=X 7 sister(alice,X) 3 female(alice), parents(alice,M0,F0), parents(X,M0,F0). parents(alice,M0,F0), parents(X,M0,F0).

slide-89
SLIDE 89

Who’s Sister Is Alice?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). X0=alice, Y0=X 7 sister(alice,X) 3 female(alice), parents(alice,M0,F0), parents(X,M0,F0). parents(alice,M0,F0), parents(X,M0,F0).

slide-90
SLIDE 90

Who’s Sister Is Alice?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). X0=alice, Y0=X 7 sister(alice,X) 3 female(alice), parents(alice,M0,F0), parents(X,M0,F0). parents(alice,M0,F0), parents(X,M0,F0).

slide-91
SLIDE 91

Who’s Sister Is Alice?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). X0=alice, Y0=X 7 sister(alice,X) 3 female(alice), parents(alice,M0,F0), parents(X,M0,F0). parents(alice,M0,F0), parents(X,M0,F0). M0=victoria F0=albert

slide-92
SLIDE 92

Who’s Sister Is Alice?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). X0=alice, Y0=X 7 sister(alice,X) 3 female(alice), parents(alice,M0,F0), parents(X,M0,F0). 6 parents(alice,M0,F0), parents(X,M0,F0). parents(X,victoria,albert). M0=victoria F0=albert

slide-93
SLIDE 93

Who’s Sister Is Alice?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). X0=alice, Y0=X 7 sister(alice,X) 3 female(alice), parents(alice,M0,F0), parents(X,M0,F0). 6 parents(alice,M0,F0), parents(X,M0,F0). M0=victoria F0=albert parents(X,victoria,albert).

slide-94
SLIDE 94

Who’s Sister Is Alice?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). X0=alice, Y0=X 7 sister(alice,X) 3 female(alice), parents(alice,M0,F0), parents(X,M0,F0). 6 parents(alice,M0,F0), parents(X,M0,F0). M0=victoria F0=albert 5 parents(X,victoria,albert). X=edward

slide-95
SLIDE 95

Who’s Sister Is Alice?

(1) male(albert). (2) male(edward). (3) female(alice). (4) female(victoria). (5) parents(edward, victoria, albert). (6) parents(alice, victoria, albert). (7) sister(X, Y):- female(X), parents(X, M, F), parents(Y, M, F). X0=alice, Y0=X 7 sister(alice,X) 3 female(alice), parents(alice,M0,F0), parents(X,M0,F0). 6 parents(alice,M0,F0), parents(X,M0,F0). M0=victoria F0=albert 5 parents(X,victoria,albert). X=edward

  • Answer: X = edward.
slide-96
SLIDE 96

Complete Derivation Tree

7 sister(alice,X) X0=alice, Y0=X 3 female(alice), parents(alice,M0,F0), parents(X,M0,F0). 6 parents(alice,M0,F0), parents(X,M0,F0). M0=victoria, F0=albert 6 ✁

5 parents(X,victoria,albert). X=edward

  • Answer: X = edward.

X=alice

  • Answer: X = alice.