Functional Evaluation in iProlog

iProlog implements a simple form of eager functional evaluation through an extension of the is built-in predicate. Programmers are allowed to define their own is clauses. For example: f is defined as a function on X which returns the value X^2+3. Not that the iProlog interpreter knows the difference between a function and a predicate, so to evaluate a function it is only necessary to type the functional expression and the resulting value is printed on the terminal.

To invoke a function from within a function is easy:

To evaluate a function within a clause, use the is predicate: Functions are really just a notational convenience, internally, the are implemented as if they were clauses whose last argument is always the output. Here is another example:

Semantics

In general, function definitions have the form: The order of execution is:
  1. The function call is unified with Fin the first clause.
  2. The Conditions are then processed as the body of a normal Prolog clause. That is, the conditions should consist of a comma separated list of Prolog literals. They are not function calls.
  3. Each clause is implicitly terminated by a cut. Thus, if either the unification with F fails or one of the conditions in the body of the clause fails, processing will move to the next clause. However, once one clause succeeds, iProlog will not backtrack to any remaining clause.

A More Complex Example

The following example is a simple implementation of Prospector's probabilistic reasoning. First, we define some rules: The rule states that the presence of rcib support the hypothesis that smir is present with sufficiency 20 and necessity 1. We need to define some prior probabilities:

The posterior probabilities are essentially the inputs:

The program for evaluating the probabilities is:

The program is called as follows: Click here to get the code.