PROLOG !

stuck with question in prolog

Page 1 of 1

1 Replies - 750 Views - Last Post: 03 June 2010 - 07:20 AM Rate Topic: -----

#1 Guest_Onchanok*


Reputation:

PROLOG !

Posted 03 June 2010 - 05:06 AM

Questions

1. Given the knowledge base

dog(ann).
dog(onn).
manita(orr).
manita(abb).

We know that all dogs are manitas and all manitas are dogs, so write a predicate prove such that

?- prove(dog(X)). ?- prove(manita(X)).
X = ann ; X = orr ;
X = onn ; X = abb ;
X = orr ; X = ann ;
X = abb ; X = onn.
false. false.

Improve your solution by writing a predicate test such that

?- test.
A dog is a manita and a manita is a dog:
ann
onn
orr
abb
false.

I do not expect a solution like dog(X) v manita(X).

2. Define a predicate & to represent logical AND (to have the same behaviour as comma). First, define its syntax: let & be an infix right-associative operator with slightly lower precedence than the comma, such that f(a & b, c) will mean f((a & B),c), not f(a & (b, c)). Next, tell Prolog how to solve a goal that contains ampersands: GoalA & GoalB should succeed if GoalA succeeds and then GoalB succeeds with the same instantiations. Finally, test it against this knowledge base

parent(mihai, ana).
parent(veta, ana).
parent(veta, anabel).
parent(iosif, mihai).
parent(maria, mihai).
parent(ion, veta).
parent(elena, veta).

1. by defining a predicate grandparent(X, Y) (X is a grandparent of Y) and by providing a query such that it will display

Child = ana,
Grandparents = [iosif, maria, ion, elena] ;
Child = anabel,
Grandparents = [ion, elena].

2. by defining a predicate only-child(P, C) (what parent P has only a child C) which can be incorporated in a predicate testa to produce

?- testa.
ana is an only child of mihai
mihai is an only child of iosif
mihai is an only child of maria
veta is an only child of ion
veta is an only child of elena
false.

Please help me with this....

Is This A Good Question/Topic? 0

Replies To: PROLOG !

#2 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: PROLOG !

Posted 03 June 2010 - 07:20 AM

[rules][/rules]
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1