Search code examples
prologartificial-intelligencefirst-order-logic

Elephants in first order logic


I have as facts these (el stands for elephant):

el(Sam)    el(Clyde)    el(Oscar)
pink(Sam)
gray(Clyde)  likes(Clyde, Oscar)
pink(Oscar)Vgray(Oscar)    likes(Oscar, Sam)

Now, I want to prove(?) that: Some gray elephant likes some pink elephant, which translates to: (exists x)(el(x) /\ gray(x) /\ (exists y) (el(y) /\ pink(y) /\ likes(x, y)). So, we need to take its negation and resolve(?) it into the basis, in order to reach void(?).

The negation is (will use ~ to show negation):

~el(x) V ~gray(x) V ~el(y) V ~pink(y) V ~likes(x, y)

The way I see it, I shall assign x and y values (Sam, Clyde or Oscar) and insert the later statement in the base, to "kill" the facts that lie there already.

My attempt:

I set x = Clyde, y = Oscar, which gave me:

~el(Clyde) V ~gray(Clyde) V ~el(Oscar) V ~pink(Oscar) V ~likes(Clyde, Oscar)

which if I put into the base, "kill" their "pairs" and the base becomes:

el(Sam)
pink(Sam)
gray(Oscar)    likes(Oscar, Sam)

and now what? We run out of elephants!

Ideally, I would like to have x' = Oscar, y' = Sam, so that I would get:

~el(Oscar) V ~gray(Oscar) V ~el(Sam) V ~pink(Sam) V ~likes(Oscar, Sam)

which would go into the base and kill everything, but ~el(Oscar) would still be alive! How should I proceed?


Follow-up question:

Base:

a
b
c V d

and then I put into the bases ~a/\~b/\~c/\~d. Everything in the base will be vanished in the same way? I mean wouldn't the V operator affect things?


Solution

  • You could have something like this:

     el(sam).
     el(clyde).
     el(oscar).
     pink(sam).
     grey(clyde).
     likes(clyde,oscar).
     likes(oscar,sam).
     canbe(oscar,grey).
     canbe(oscar,pink).
    
     gelephant_likes_pelephant(GE,PE):-
       grey(GE),el(GE),
       pink(PE),el(PE),
       likes(GE,PE).
    
    
     gelephant_likes_pelephant(GE,PE):-
       canbe(GE,grey),el(GE),
       pink(PE),el(PE),
       likes(GE,PE).
    
    gelephant_likes_pelephant(GE,PE):-
      grey(GE),el(GE),
      canbe(PE,pink),el(PE),
      likes(GE,PE).
    

    Qs:

    ?- gelephant_likes_pelephant(GE,PE).
    GE = oscar,
    PE = sam ;
    GE = clyde,
    PE = oscar.
    

    You have to be careful how you use a predicate like canbe/2. As it is saying oscar can be grey or pink. Then my query is saying which grey elephants like which pink elephants, the answer can be interpreted as: IF oscar is a grey elephant THEN oscar likes sam OR IF clyde likes oscar THEN oscar is a pink elephant.