next up previous contents index
Next: Other Directives Up: Compiler Directives Previous: Indexing Directives   Contents   Index


Unification Factoring

When the clause heads of a predicate have portions of arguments common to several clauses, indexing on the principal functor of one argument may not be sufficient. Indexing may be improved in such cases by the use of unification factoring. Unification Factoring is a program transformation that ``factors out'' common parts of clause heads, allowing differing parts to be used for indexing, as illustrated by the following example:
p(f(a),X) :- q(X).
p(f(b),X) :- r(X).
$\longrightarrow$
p(f(X),Y) :- _$p(X,Y).
_$p(a,X) :- q(X).
_$p(b,X) :- r(X).
The transformation thus effectively allows $p/2$ to be indexed on atoms $a/0$ and $b/0$. Unification Factoring is transparent to the user; predicates created by the transformation are internal to the system and do not appear during tracing.

The following compiler directives control the use of unification factoring:3.4.

:- ti(F/A).
Specifies that predicate $F/A$ should be compiled with unification factoring enabled.
:- ti_off(F/A).
Specifies that predicate $F/A$ should be compiled with unification factoring disabled.
:- ti_all.
Specifies that all predicates defined in the file should be compiled with unification factoring enabled.
:- ti_off_all.
Specifies that all predicates defined in the file should be compiled with unification factoring disabled.
By default, higher-order predicates (more precisely, predicates named apply with arity greater than 1) are compiled with unification factoring enabled. It can be disabled using the ti_off directive. For all other predicates, unification factoring must be enabled explicitly via the ti or ti_all directive. If both :- ti(F/A). ( :- ti_all.) and :- ti_off(F/A). ( :- ti_off_all.) are specified, :- ti_off(F/A). ( :- ti_off_all.) takes precedence. Note that unification factoring may have no effect when a predicate is well indexed to begin with. For example, unification factoring has no effect on the following program:
p(a,c,X) :- q(X).
p(b,c,X) :- r(X).
even though the two clauses have $c/0$ in common. The user may examine the results of the transformation by using the ti_dump compiler option (see Section 3.8.2).


next up previous contents index
Next: Other Directives Up: Compiler Directives Previous: Indexing Directives   Contents   Index
Baoqiu Cui
2000-04-23