Yes, you are right: in logic, the variable x, of course, is not syntactically unified with the term f (x) on the grounds that the variable itself appears as a strict subterm f (x).
For this reason, the so-called check appears , which leads to a failure of the union.
As correctly noted in this article, Prolog implementations usually omit the availability check for performance reasons, which can lead to unfounded conclusions.
However, you can always perform unification with verification in Prolog using the ISO predicate unify_with_occurs_check/2 . Exactly as expected, the union you are asking about does not work in this case:
? - unify_with_occurs_check (X, f (X)).
false
Please note that on some Prolog systems you can set a flag to enable checking for all unifications.
For example, in SWI-Prolog:
? - set_prolog_flag (occurs_check, true).
true
? - X = f (X).
false
I recommend that you enable this flag to get sound results.
Unifications requiring verification often indicate programming errors. For this reason, you can set a flag to throw errors instead of failing.
See also the related question related to @false in the comments above, and the link provided.
source share