This Article 
 Bibliographic References 
 Add to: 
Efficient Reordering of Prolog Programs
December 1989 (vol. 1 no. 4)
pp. 470-482

Prolog programs are often inefficient: execution corresponds to a depth-first traversal of an AND/OR graph; traversing subgraphs in another order can be less expensive. It is shown how the reordering of clauses within Prolog predicates, and especially of goals within clauses, can prevent unnecessary search. The characterization and detection of restrictions on reordering is discussed. A system of calling modes for Prolog, geared to reordering, is proposed, and ways to infer them automatically are discussed. The information needed for safe reordering is summarized, and which types can be inferred automatically and which must be provided by the user are considered. An improved method for determining a good order for the goals of Prolog clauses is presented and used as the basis for a reordering system.

[1] A. Barr and E. A. Feigenbaum,The Handbook of Artificial Intelligence, vol. I, Los Altos, CA: William Kaufmann, 1981.
[2] M. Bruynoogheet al., "Abstract interpretation: Towards the global optimization of Prolog programs," inProc. 1987 Symp. Logic Programming, Sept. 1987, pp. 192-204.
[3] M. Bruynooghe and L. M. Pereira, "Deduction revision by intelligent backtracking," inImplementations of Prolog, J. A. Campbell, Ed. Chichester, England: Ellis Horwood, 1984, pp. 194-215.
[4] M. Bruynooghe and G. Janssens, "An instance of abstract interpretation integrating type and mode inferencing," inProc. 5th Int. Conf. Symp. Logic Programming, Aug. 1988, pp. 669-683.
[5] J.-H. Chang, A. M. Despain, and D. DeGroot, "AND-parallelism of logic programs based on a static data dependency analysis," inDigest of Papers of COMPCON Spring '85, Feb. 1985, pp. 218-225.
[6] W. F. Clocksin and C. S. Mellish,Programming in Prolog. New York: Springer-Verlag, 1984.
[7] H. Coelho, J. C. Cotta, and L. M. Pereira, "How to solve it in Prolog," Laboratorio Nacional de Engenhara Civil, Lisbon, Portugal, July 1982.
[8] S. K. Debray, "Optimizing almost-tail-recursive Prolog programs," Dep. Comput. Sci., State Univ. New York at Stony Brook, Stony Brook, New York, Tech. Rep. 84/089, Nov. 1984.
[9] S. D. Debray and D. S. Warren, "Automatic mode inference for Prolog programs," inProc. 1986 Symp. Logic Programming, Sept. 1986, pp. 78-88.
[10] S. D. Debray, "The SB-Prolog system, Version 2.3.2: A user manual," Dep. Comput. Sci., Univ. Arizona, Tucson, Tech. Rep. 87- 15, Mar. 1988.
[11] M. M. Gooley and B. W. Wah, "Efficient reordering of Prolog programs," inProc. 4th Int. Conf. Data Eng., Feb. 1988, pp. 110-117.
[12] J. G. Kemeny and J. L. Snell,Finite Markov Chains. New York: Van Nostrand, 1965.
[13] R. Kowalski,Logic for Problem Solving. New York: North-Holland, 1979.
[14] G.-J. Li and B. W. Wah, "How good are parallel and ordered depth-first searches?" inProc. Int. Conf. Parallel Processing, Aug. 1986, pp. 992-999.
[15] H. Mannila and E. Ukkonen, "Flow analysis of Prolog programs," inProc. 1987 Symp. Logic Programming, Sept. 1987, pp. 205-214.
[16] C. S. Mellish, "Some global optimizations for a Prolog compiler,"J. Logic Programming, vol. 1, pp. 43-66, 1985.
[17] C. S. Mellish, "Abstract interpretation of logic programs," inProc. 3rd Int. Conf. Logic Programming, July 1986, pp. 463-474.
[18] A. Mycroft and R. A. O'Keefe, "A polymorphic type system for Prolog,"Artificial Intell., vol. 23, pp. 295-307, 1985.
[19] F. Pereira, C-Prolog User's Manual, Version 1.5, Edinburgh Computer Aided Architectural Design, Edinburgh, Scotland, Aug. 1983.
[20] L. M. Pereira, F. C. N. Pereira, and D. H. D. Warren, User's Guide to DECsystem-10 Prolog, Sept. 1978.
[21] D. E. Smith and M. R. Genesereth, "Ordering conjunctive queries,"Artificial Intell., vol. 26, pp. 171-215, 1985.
[22] Z. Somogyi, "A system of precise modes for logic programs," inProc. 4th Int. Conf. Logic Programming, May 1987, pp. 769-787.
[23] L. Sterling and E. Y. Shapiro,The Art of Prolog. Cambridge, MA: M.I.T. Press, 1986.
[24] H. Tamaki and T. Sato, "Unfold/fold transformation of logic programs," inProc. 2nd Int. Conf. Logic Programming, 1984, pp. 127- 138.
[25] D. H. D. Warren, "Efficient processing of interactive relational database queries expressed in logic," presented at the 7th Conf. on Very Large Data Bases, 1981.
[26] D. H. D. Warren, "An abstract Prolog instruction set," SRI Int., Menlo Park, CA, Tech. Note 309, Oct. 1983.
[27] D. H. D. Warren, "Applied logic--Its use and implementation as a programming tool," SRI Int., Menlo Park, CA, Tech. Note 290, June 1983.
[28] R. Warren, M. Hermenegildo, and S. K. Debray, "On the practicality of global flow analysis of logic programs," inProc. 5th Int. Conf. Symp. Logic Programming, Aug. 1988, pp. 684-699.
[29] D. A. Wolfram, "Intractable unifiability problems and backtracking," inProc. 3rd Int. Conf. Logic Programming, July 1986, pp. 107-121.

Index Terms:
Prolog programs reordering; depth-first traversal; traversing subgraphs; predicates; clauses; logic programming; PROLOG
M.M. Gooley, B.W. Wah, "Efficient Reordering of Prolog Programs," IEEE Transactions on Knowledge and Data Engineering, vol. 1, no. 4, pp. 470-482, Dec. 1989, doi:10.1109/69.43422
Usage of this product signifies your acceptance of the Terms of Use.