loop detection for infinite rule recursion