Could you help me to understand what my error is in the code? It is very necessary to understand ..

Task:
Describe a knowledge base on Prolog containing the following information:
Data:

  1. Alexey is the son of Yuri
  2. Yuri is the son of Ivan,
  3. Sergey is the son of Ivan
  4. Alexander is the son of Ivan
  5. Pavel is the son of Sergey.

Rules:

  1. X is the father of Y, if Y is the son of X
  2. X is a brother of Y if they are two different people, but both are sons of the same person.
  3. X is the uncle of Y, if the father of Y is Z, and X and Z are brothers
  4. X is the grandfather of Y, if X is the father of Z, and Z is the father of Y

Formulate goals and answer the following questions:

  1. Display the list of brothers Sergey
  2. What is the name of Paul's grandfather?
  3. Who is Sergei Aleksey?
predicates nondeterm son(string,string) /*who, whose*/ nondeterm father(string,string) /*who, whose*/ nondeterm brother(string,string) /*who, whose*/ nondeterm uncle(string,string) /*(who, whose*/ nondeterm grandfather(string,string) /*who, whose*/ clauses %Facts son(aleksej,yurij). son(yurij,ivan). son(sergej,ivan). son(alexandr,ivan). son(pavel,sergej). %Rules father(X,Y):-son(Y,X). brother(X,Y):-X<>Y,father(Z,X),father(Z,Y). uncle(X,Y):-father(Z,Y), brother(X,Z),brother(Z,X). grandfather(X,Y):-father(X,Z),father(Z,Y). goal brother(X,sergej). grandfather(X,pavel). X(sergej,aleksej). 

It seems that everything is logical, it should compile and produce a result, but for some reason it gives errors ..
I do not understand what is wrong ..

  • at least you need to add to the question the errors that you get - Grundy
  • X (sergej, aleksej) - you have no predicate X - Grundy
  • and another incomprehensible construction: brother(X,Z),brother(Z,X) - you have no difference in what order the arguments are passed to - Grundy
  • Error: E; Test_Goal, pos: 589, 450 Syntax error, section keyword expected - Gadget
  • one
    from where written by me - Gadget

1 answer 1

Immediately it is worth noting that there will not be tasks for you. Now essentially. Obviously, you do not have a predicate X (Y, Z) that would match each word's relationship to match who Y is for Z.

An example of such a predicate:

  Who(Y,Z,X):-brother(Y,Z), X="brother", Who(Y,Z,X):-father(Y,Z), X="father", ... 

And so to describe all possible situations for this predicate, not to forget about nephews and grandchildren. Of course, the code may not be working, since for Prolog there are a lot of different variations of language interpreters.

But the general idea is given.

PS In that interpreter with which I worked I had to be only one goal, not sure about yours.

  • I understand that no one will. - Gadget
  • I understood everything, what was the mistake, it turned out, thanks. - Gadget