1

This is my prolog file.

male(bob).
male(john).

female(betty).
female(dana).

father(bob, john).
father(bob, dana).
mother(betty, john).
mother(betty, dana).

daughter(X, Y) :- female(X), mother(Y, X).

I want to query something like this daughter(X, mother(Y, john)). Is it possible?

I'm trying to get daughter of john's mother.

I got this idea from here under 'Asking Questions with Structures'

repeat
  • 18,496
  • 4
  • 54
  • 166
Pranav
  • 447
  • 5
  • 18

2 Answers2

1

try

mothers_daughter(X, Y) :- mother(Z,X), daughter(Y,Z).

query -> mothers_daughter(john, Y).

EDIT: daughter(X, mother(Y, Z)):- female(X),mother(Y, X).

Oğuz Tanrıkulu
  • 239
  • 2
  • 12
  • Like I mentioned I want it to call like this `daughter(X, mother(Y, john)).` Is it possible to do something like that without defining a separate relation? I'm trying to replicate [this](http://www.wolframalpha.com/input/?i=mother%27s+daughter) – Pranav Sep 24 '15 at 15:59
  • I got idea from [here](http://www.cse.unsw.edu.au/~billw/cs9414/notes/prolog/intro.html). Under section 'Asking Questions with Structures'. `owns(john, book(Title, author(leguin, GivenName))).` – Pranav Sep 24 '15 at 16:03
  • 1
    like ? daughter(X, mother(Y, Z)):- female(X),mother(Y, X). – Oğuz Tanrıkulu Sep 24 '15 at 16:17
  • Hey, thanks for answer I really appreciate it. But it isn't what I want. I don't want to create a new rule. I'm gonna wait for few more hours. If nothing, will accept yours. – Pranav Sep 24 '15 at 20:12
0

Something like that ?

daughter(X, Y), mother(Y, john).

This will match Y as the mother of john and then X as the daughter of Y. So X will be the daughter of john mother.

Emrys Myrooin
  • 2,179
  • 14
  • 39
  • Yeah, that would do. Thanks! Can you take a look at [this](http://stackoverflow.com/questions/32770849/given-values-x-and-y-return-rule-name-if-it-is-true) – Pranav Sep 24 '15 at 21:25