Many papers do note that an equational unification problem such as below, might run in exponential time, when occurs_check=true
. There is no stipulation that this is a top-level query or a clause body, its just the equational unification problem:
X1 = f(X0, X0),
X2 = f(X1, X1),
..
Xn-1 = f(Xn-2, Xn-2),
Xn = f(Xn-1, Xn-1).
If true this could be a worst case for occurs check, since normal variable sharing unification is linear. Does every Prolog system necessarely feature this equational unification problem as a worst case?
If the Prolog system does not have an occurs_check=true
flag, one could try unify_with_occurs_check/2
in place of (=)/2
.