The syntax Goal infers most can also be varied to invoke different levels of Generalised Propagation. Other alternatives are Goal infers fd, Goal infers range, Goal infers unique, and Goal infers consistent. The strongest constraint is generated by Goal infers most, but it can be expensive to compute. The other alternatives may be evaluated more efficiently, and may yield a better overall performance on different applications. We call them ``approximations'', since the information they produce during propagation is a (weaker) approximation of the information produced by the strongest constraint.
We illustrate the different approximations supported by the current version of Propia on a single small example. The results for Goal infers most reflect the problem that structured terms cannot appear in finite domains.
[eclipse]: [user]. p(1,a). p(2,f(Z)). p(3,3). user compiled
[eclipse]: p(X,Y) infers most. X = X{[1..3]} Y = Y Delayed goals: p(X{[1..3]}, Y) infers most yes. [eclipse]: X::[1, 3], p(X, Y) infers most. X = X{[1, 3]} Y = Y{[3, a]} Delayed goals: p(X{[1, 3]}, Y{[3, a]}) infers most yes. [eclipse]: p(2,Y) infers most. Y = f(Z) yes.The first approximation we will introduce in this section is one that searches for the unique answer to the query. It is written Goal infers unique. This is cheap because as soon as two different answers to the query have been found, the constraint evaluation terminates and the constraint is delayed again until new information becomes available. Here are two examples of this approximation. In the first example notice that no domain is produced for X.
[eclipse]: p(X,Y) infers unique. X = X Y = Y Delayed goals: p(X, Y) infers unique yes.In the second example, by contrast,
infers unique
yields the same
result as infers most
: [eclipse]: p(X,X) infers unique. X = 3 yes.
The next example shows that unique can even capture nonground answers:
[eclipse]: p(2,X) infers unique. X = X Delayed goals: p(2, X) infers unique yes.
The next approximation we shall describe is even weaker: it tests if there is an answer and if not it fails. If there is an answer it checks to see if the constraint is already true.
[eclipse]: p(1,Y) infers consistent. Y = Y Delayed goals: p(1, Y) infers consistent yes. [eclipse]: p(1,a) infers consistent. yes. [eclipse]: p(1,X) infers consistent, X=b. no (more) solution.
The strongest language infers most
extracts any information
possible from the loaded constraint solvers. The solvers currently
handled by Propia are unification (which is the built-in solver
of Prolog), finite domains and range.
The finite domain library is loaded by lib(fd)
and the range
library by lib(range)
. These libraries are described
elsewhere.
If both libraries are loaded, then infers most
extracts
information from unification, finite domains and ranges. For example:
[eclipse]: [user]. p(f(X),a) :- X *>=0, X *=< 10. p(f(X),b) :- X=12. yes. [eclipse 14]: p(X,Y) infers most. X = f(X{0.0..12.0}) Y = Y{[a, b]} Delayed goals: p(f(X{0.0 .. 12.0}), Y{[a, b]}) infers most yes.
The approximations infers fd
and infers range
are
similar to infers most
. However, while infers most
extracts information based on whatever constraint solvers are loaded,
the others only infers information derived from the specified constraint
solver.
Here's the same example using infers fd
:
[eclipse 14]: p(X,Y) infers fd. X = f(X) Y = Y{[a, b]} Delayed goals: p(f(X), Y{[a, b]}) infers fd yes.
Here's the same example using infers range
:
[eclipse 14]: p(X,Y) infers range. X = f(X{0.0..12.0}) Y = Y Delayed goals: p(f(X{0.0 .. 12.0}), Y) infers range yes.
One rather special approximation langue is infers ac
, where
ac
stands for arc-consistency.
This has similar semantics to infers fd
, but is implemented
very efficiently using the built-in element
constraint of the
finite domain solver.
The limitation is that Goal infers ac
is implemented by
executing the goal repeatedly to find all the solutions, and then
manipulating the complete set of solutions.
It will only work in case there are finitely many solutions and they
are all ground.
Finally it is possible to invoke Propia in such a way as to influence
its waking conditions. To do this, use the standard
suspend
syntax. For example ``forward checking'' can be
implemented as follows:
propagate(Goal,fc) :- !, suspend(Goal,4,Goal->inst) infers most.In this case the Propia constraint wakes up each time a variable in the goal is instantiated.
The default priority for Propia constraints is 3. However, in the above example, the priority of the Propia constraint has been set to 4.