Efficient recursion termination for function-free horn logic
- Author(s): Wong, Wang-chan
- Bic, Lubomir
- et al.
We present an efficient scheme to terminate infinite recursion in function-free Horn logic. In [BW84], Brough and Walker show that a preorder linear resolution with a goal termination strategy is incomplete, i.e. it must miss some answers. Their theory is true if left-recursion is allowed. The crucial assumption underlying Brough and Walker's theory is that the order of literals in a clause should not be altered. This assumption, however, is not necessary in programs that do not contain any extra-logical features such as the 'cut' symbol of Prolog. This is because the order of literals does not affect the correctness of such programs, only their efficiency. In this paper, we show that left-recursion can always be eliminated. The idea is to transform loops of the input set into safe loops, that are left-recursion free. Consequently, the goal termination strategy guarantees to always terminate properly with all possible answers; thus, it is complete in the domain of safe loops. We further show that all rules in a safe loop can be transformed into rules that begin with a base literal. This permits the implementation of a simple scheme to carry out the goal termination strategy more efficiently. The basic idea of this scheme is to distribute the history containing all executed goals over assertions, rather than maintaining it as a centralized data structure. This reduces the amount of work performed during execution.