Complexity of the CHR Rational Tree Equation Solver
Marc Meister, Thom Frühwirth · 2006
Constraint Handling Rules (CHR) is a concurrent, committed-choice, rule-based language. One of the first CHR programs is the classic constraint solver for syntactic equality of rational trees that performs unification [7, 4, 14]. The worst-case time (and space) complexity of this short and elegant solver so far was an open problem [8] and assumed to be polynomial. In this paper we show that under the standard operational semantics of CHR there exist particular computations with n occurrences of variables and function symbols that produce O(2 n) constraints, thus leading to exponential time and space complexity. We also show that the standard implementation of the solver in CHR libraries for Prolog may not terminate due to the Prolog built-in order used in comparing terms. Complexity can be improved to be quadratic for any term order under both standard and refined CHR semantics without changing the equation solver, when equations are transformed into flat normal form.