What is the meaning of these prolog sentences? (substitution)

66 Views Asked by At

I'm just beginning to learn Prolog and I've come across this example for substitution:

We have the substitution S2 = {X= brother(maya), Y = friend(john)} We apply the substitution S2 to friend(X, Y) : friend(X, Y) * S2 We get: friend(brother(maya), friend(john))

There are multiple things in this example that I don't understand.

  1. What does brother(maya) stand for? "Someone is Maya's brother" should be expressed as brother(X, maya). Does brother(maya) mean "Maya is a brother", or maybe "Maya has a brother"?

  2. As far as I know, the value of a predicate is a Boolean (true or false). Does that mean that friend(brother(maya), friend(john)) is essentialy friend(true, true), and what would that even mean?

Thank you in advance for your help.

1

There are 1 best solutions below

0
TessellatingHeckler On

brother(maya) is like ripplekilo(earboat) - a Prolog term with name and atom. Is Maya only a female name or is it like Hilary in English? Is Brother Maya a monk? If there is more meaning for it than you can tell from reading the code, you need to ask the author or guess.

"Someone is Maya's brother" should be expressed as brother(X, maya).

With an unbound variable, the term is more of a question (query) than a statement. As you say, it's unhelpful when you can't read the meaning from the code, and your suggestion is still ambiguous - brother(X,Y) which one is the brother? Or do they both share a third brother? Or is X a counter, like brother(3, maya) saying Maya has three brothers? Or linking somehow to brother number 3 of Maya? Ideally the name describes the relation between the parameters, e.g. brother_sister/2 or siblings/2 might be clearer, and if not then that's what % comments are for.

As far as I know, the value of a predicate is a Boolean (true or false). Does that mean that friend(brother(maya), friend(john)) is essentialy friend(true, true)

true and false are not Booleans in Prolog they are also just atoms, and Prolog doesn't let you nest queries like other languages nest function calls, so no they are not equivalent.

As for what it means, it is worth musing on how 01110001 can be the number 113, or the letter q, or the hex pair 0x71, or four vote agreements and four disagreements, or BV in Morse Code... symbols don't contain meaning; computer programs move symbols around, the words are not meaningful to Prolog - the code would run if they were sadf(whoeu,qfmoe) if used consistently. brother(X, maya) might mean that Maya is the CEO of company X, for all we know. Worse named code has existed.