Question

Prolog predicates - Built on this, question did not have enough clarity so I am posting the question in context.

Here is the question and I will post what I have done so far and what I am struggling on.

Scenario (A quiet weird one)

James and Victoria are married, but Victoria is in love with Curt. Curt does not love her because he is still married to and cares about Kylie, though she is more interested in Henry. Arthur is romantically inclined towards Victoria but he is in competition with Henry, who also loves Victoria despite being married to Crystal, whom James is feeling romantic about.

1] Represent this information using Prolog predicates.Only use two predicate names.

This is my interpretation of this

is_Married([James,Victoria],[Curt,Kylie],[Henry,Crystal]).

is_inLove([Victoria,Curt],[Kylie,Henry],[Arthur,Victoria],[Henry,Victoria],[James,Victoria]).

For the second predicate, I'm also unsure if I should put [Curt,Kylie] as it said 'and still cares about' in the scenario.

2] A married is on the rocks if both participants are romantically inclined towards other people, and not each other. How could a Prolog rule represent this statement.

My answer

∀∃x: is_married(X,Y) ∧¬ is_inLove(X,Y) ∨ is_inLove(Y,X) → on_rocks (x)

I'm a bit confused on how to represent, marriage as apposed to the two participants.

3]A circle of love exists when a person X loves someone else, who in turn loves somebody else and so on until somebody in that chain loves person X. Assuming only one circle of love exists, write the prolog rules that will find this circle and produce a list of those involved.

My answer

write_list([X|A,B,C]:-

write(X)

writelist(X,Tail).

Was it helpful?

Solution

The Prolog way is to represent each pair as a separate fact; all the similar facts will form a relationship (predicate).

So you have three is_Married facts, and five loves facts. Or six, including that one about Curt:

is_Married(James,Victoria).
is_Married(Curt,Kylie).
is_Married(Henry,Crystal).

loves(Victoria,Curt).       % changed the name
loves(Kylie,Henry).       
loves(Arthur,Victoria).
loves(Henry,Victoria).
loves(James,Victoria).
loves(Curt,Kylie).

"A marri[age] is on the rocks if both participants are romantically inclined towards other people, and not each other." This is a straightforward translation from English to Prolog:

on_the_rocks(A,B):-     % a pair of people, whose marriage is on the rocks
   is_Married(A,B), 
   loves(A,C), C \= B,
   .....
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top