Posts

Showing posts from May, 2009

Adventures in Prolog - General Reading (1)

Today's post is merely the advertisement of a dissertation thesis that might be an interesting read: Can Logic Programming Execute as Fast as Imperative Programming? Peter Lodewijk Van Roy ABSTRACT The purpose of this dissertation is to provide constructive proof that the logic programming language Prolog can be implemented an order of magnitude more efficiently than the best previous systems, so that its speed approaches imperative languages such as C for a significant class of problems. The driving force in the design is to encode each occurrence of a general feature of Prolog as simply as possible. The resulting system, Aquarius Prolog, is about five times faster than Quintus Prolog, a high performance commercial system, on a set of representative programs. The design is based on the following ideas: Reduce instruction granularity. Use an execution model, the Berkeley Abstract Machine (BAM), that retains the good features of the Warren Abstract Machine (WAM), a standard executi...

Adventures in Prolog - Simplify Sum (4)

Last post was concerned with implementing the simplification of an additive (compound) term. The proposed solution consists of three elementary steps (sorting, simplifying and reducing). Although the proposed solution is quite flexible, i.e. works on any atom not specifically a single character, the sorting of characters decreases performance somewhat. For this, this post is concerned with a more targeted approach to the introduced problem. Given an additive (compound) term containing numbers and (unitary) variable symbols (e.g., a, b, x, y, z), we wish to obtain a reduced form of this term, which simplifies the same variables and sums multiple numbers to one single number. The following solution makes use of: The (German and English) alphabet contains only 26 elementary characters (variable symbols) Character symbols can be ordered according to their occurence within the alphabet. Instead of operating on additive compound term, the proposed solution operates on a character array , i.e...

Adventures in Prolog - Simplify Sum (3)

In an earlier installment the simplify_sum predicate was discussed. However it was not really a feature complete solution to the initially motivated problem. For this, this post is concerned with providing a newer version, which actually solves the following problem. Given some additive formulae, such as: 1 a 1 + a a + a 1 + a + 9 + b + a + b + c we wish to obtain the following results: 1 1*a (or a) 1*a + 1 (or a + 1) 2*a 2*a + 2*b + 1*c + 10 (or 2*a + 2*b + c + 10) The proposed solution will consist of three parts: 1. order all parts of an additive equation according to letters and numbers. place letters in order of the alphabet and summarize numbers, such that at most one number is present. 2. summarize all variables. this leads to the transformation of x into 1*x 3. reduce all variables from 1*x to x. Translating the above sequence of steps into a Prolog program, leads to the following definition of the simplify_sum predicate: simplify_sum(In, Final) :- sort_sum(In, SortedOut), ...