0

I have this facts or database in prolog to see if the educations is the same or less than. for example highschool <= highschool is true and highschool <= phd is true too, but masters <= highschool is false.

edu_less(high_school, bachelor).
edu_less(bachelor, masters).
edu_less(masters, phd).

edu_lessOrEqual(X,X).
edu_lessOrEqual(X, Y):- edu_less(X,Y).
edu_lessOrEqual(X, Y):- edu_less(X,Z),
                        edu_lessOrEqual(Z,Y).

but this outputs

edu_lessOrEqual(masters, phd).
true;
true;
false.

when i want only one true to be printed in the output.

true;
false.
4

1 回答 1

2

基本上,这是因为在 的第三个子句中edu_lessOrEqual/2,您递归地调用edu_lessOrEqual/2,所以您最终会遇到 Z 和 Y 都被实例化为的情况phdphd实际上等于,phd因此它满足了您所阐明的逻辑)。您可以通过在第三个子句的末尾添加 a 来纠正它Z \= Y,但在这种情况下,我很想使用条件语句来确保我不会以无用的选择点结束。

于 2017-11-18T04:32:28.113 回答