Abstract
The execution of a Prolog program can be viewed as a sequence of unifications and backtracks over unifications. We study the time requirement of executing a sequence of such operations (the unify-deunify problem). It is shown that the well-known set union problem is reducible to this problem, even in the case when no function symbols are allowed (the Datalog unify-deunify problem). As the set union problem requires nonlinear time on a large class of algorithms, the same holds for the unify-deunify problem. Thus the linearity of single unifications does not give a complete picture of the time complexity of Prolog primitives. We discuss the methods for executing sequences of Datalog unifications used in Prolog interpreters and show that some of them require even quadratic time in the worst case. Complementing these results, we show that if the number of variables occurring in one clause is bounded by a constant, then the Datalog unify-deunify problem can be solved in linear time.
Similar content being viewed by others
References
A. V. Aho, J. E. Hopcroft and J. D. Ullman:The Design and Analysis of Computer Algorithms. Addison-Wesley, 1974.
J. R. Driscoll, N. Sarnak, D. D. Sleator and R. E. Tarjan:Making data structures persistent. Journal of Computer and System Sciences 38, 1 (February 1989), 86–124.
M. L. Fredman and M. E. Saks:The cell probe complexity of dynamic data structures. In: Proceedings of the 21st ACM Symposium on Theory of Computing, 1989, p. 345–354.
H. N. Gabow and R. E. Tarjan:A linear-time algorithm for a special case of disjoint set union. Journal of Computer and System Sciences 30 (1985), 205–221.
C. J. Hogger:Introduction to Logic Programming. Academic Press, 1984.
H. Mannila and E. Ukkonen:The set union problem with backtracking. In:Automata, Languages, and Programming, Thirteenth International Colloquium, Rennes, France, July 1986, Lecture Notes in Computer Science 226, Springer-Verlag 1986, p. 236–243.
K. Mehlhorn, S. Näher and H. Alt:A lower bound for the complexity of the union/split/find problem. In:Automata, Languages, and Programming, Fourteenth International Colloquium, Karlsruhe, FRG, July 1987, Lecture Notes in Computer Science 267, Springer-Verlag 1987, p. 479–488.
M. S. Paterson and M. N. Wegman:Linear unification. Journal of Computer and System Sciences 16 (1978), 158–167.
R. E. Tarjan:Efficiency of a good but not linear disjoint set union algorithm, J. ACM 22, 2 (April 1975), 215–225.
R. E. Tarjan:A class of algorithms which require nonlinear time to maintain disjoint sets. J. Computer and System Sciences 18 (1979), 110–127.
R. E. Tarjan and J. van Leeuwen:Worst-case analysis of set union algorithms. J. ACM 31, 2 (April 1984), 245–281.
J. van Leeuwen and T. van der Weide:Alternative path compression techniques. Technical Report RUU-CS-77-3, Rijksuniversiteit Utrecht, Utrecht, The Netherlands.
J. S. Vitter and R. A. Simons:New classes for parallel complexity: a study of unification and other complete problems for P. IEEE Transactions on Computers C-35, 5 (May 1986), 403–418.
D. H. D. Warren:Implementing Prolog — Compiling predicate logic programs. Research Reports 39 and 40, Department of Artificial Intelligence, University of Edinburgh, 1977.
J. Westbrook and R. E. Tarjan:Amortized analysis for set union with backtracking. SIAM Journal of Computing 18, 1 (February 1989), 1–11.
Author information
Authors and Affiliations
Additional information
A preliminary version of this paper appeared in the Third International Conference on Logic Programming, London, July 1986. This work was supported by the Academy of Finland and by TEKES.