Prolog Reciprocal Rule -
I'm sure it's basically basic, though I did not find it by searching here.
I am learning to learn and found an example with the rules: (representation of adjacency)
adj (1, 2) adj (2, 1) adj (1 , 3) Adj (3, 1) Adj (3, 4) Adj (4, 3) Now, it hit me as a bit useless, because we know that the nearest one There is mutual relation, it should be enough to define only one of each pair, and then define:
adj (x, y): - adj (y, x) ! I understand why this simple effort does not work; It falls into an infinite loop if X and Y are not adjacent. But, I do not know exactly how to work it in all cases.
You should enter an alternate name and use your logic to use it. For example
adj (1, 2). Adj (1, 3) Adj (3, 4) Is_adj (x, y): - adj (x, y); Adj (y, x).
Comments
Post a Comment