10

How can I implement following rules in prolog.

I write the “ No spiders are mammals” sentence as Existential and universal:

¬∃x(mammals(X) ∧ spider(X) ) //It is not the case that mammals are spider

∀X(mammals(X) ⇒ ¬spider(X)) //All mammals are non-spider.
false
  • 10,264
  • 13
  • 101
  • 209
user2064809
  • 403
  • 1
  • 4
  • 13

1 Answers1

7

Suppose you have a database with the following facts:

mammals(cat).
mammals(dog).
 ...

spider(blackwidow).
 ...

Now you can issue a rewrite your sentence into a prolog query quite straightforward:

¬∃x(mammals(X) ∧ spider(X) ) //It is not the case that mammals are spider

?- \+((mammals(X), spider(X))).
true.

and

∀X(mammals(X) ⇒ ¬spider(X)) //All mammals are non-spider.

?- forall(mammals(X), \+spider(X)).
true.
gusbro
  • 22,357
  • 35
  • 46
  • Is there a way to I implement these rules in 'x.pl' Environment ? I mean add the rules to the database? – user2064809 Jan 30 '15 at 06:11
  • 3
    You can add a procedure which succeeds when the condition holds, just add the query onto the body of a procedure. E.g.: `no_mammal_is_spider:- \+((mammals(X), spider(X))).` – gusbro Jan 30 '15 at 14:38
  • Thankyou for your answer. Could you please guide me how can I add following sentence in prolog as a rule? ∀X(q(X) OR b(X) ⇒ Mammal(X)) %All mammal are either ‘q’ OR ‘B’. I wrote it but I don’t know what’s the problem: `C(cat).` `Mammal (X) :- forall(q(X) V b(X))` Finally I should answer this question: Is ‘cat’ is a mammal? `?-mammal(cat)` – user2064809 Feb 13 '15 at 15:37
  • 2
    %All mammal are either ‘q’ OR ‘b’ would be written `forall(mammals(X), ( q(X) ; b(X) ) ).` – gusbro Feb 13 '15 at 15:43
  • `mammal(b).` `mammal(q).` `forall(mammal(X), ( q(X) ; b(X) ) ).` `q(cat).` `cat(pishi).` Then I write `?- mammal(pishi)` But I get `false`. Instead of `true`. – user2064809 Feb 13 '15 at 16:12
  • I think you are getting this wrong. `mammal(pishi)` gets `false` because your program states that there are only two mammals, b and q, with b and q being atoms. The forall(...) written in the program would be a fact, not what you intended. – gusbro Feb 13 '15 at 17:21