In this paper, we discuss a major optimization of P#. Our optimization is based on the exploitation of semi-deterministic predicates. A predicate is semi-deterministic if it always either fails or succeeds with exactly one solution. If a predicate is semi-deterministic then there may be backtracking from one clause of the predicate to the next, if an earlier clause fails at some point. A semi-deterministic predicate which only calls other semi-deterministic predicates has the property that an individual clause will not be executed more than once by backtracking. In such cases we can do away with the Prolog stacks, which govern backtracking, and simulate in C# the fairly simple flow of control which is permitted for such a predicate. A predicate is non-deterministic if it may produce more than one solution.
A more specific class of predicates than the semi-deterministic predicates is that of the deterministic predicates. A predicate is deterministic if it always succeeds exactly once. Deterministic predicates occur frequently in idiomatic Prolog. Often, they are the result of coding a function in Prolog. When one wishes to code a predicate which will be used as a function, one generally expresses this as a Prolog predicate, some of whose arguments are input arguments, with the other arguments being output arguments. Input arguments are arguments which are known to be instantiated on entry into the predicate, and output arguments are those which are not instantiated on entry into the predicate, but which will be instantiated on exit from the predicate. The property of an argument of being input or output is referred to as its mode.
Developer experience suggests that these functional predicates often perform some simple utility, that is, they frequently occur as leaf predicates. Such a predicate might, for example, concatenate two lists. Another feature of leaf predicates is that, often, they are called frequently. Thus, if we can reduce the time taken to execute such predicates, we may effect a significant optimization.
Download Optimizing P#: Translating Prolog to more Idiomatic pdf
Related Searches: input arguments, predicates, predicate, flow of control, instantiated
RSS feed for comments on this post · TrackBack URI
Leave a reply