The compiler generates two groupings of subroutines for each relation in the given rule set - two general subroutines and a collection of specialized subroutines. Each grouping includes both singular and plural subroutines (in analogy with compfindx and compfinds). Each singular subroutine returns a single factoid that satisfies the query supplied as argument; each plural subroutine return lists of all factoids that satisfy the query.
The two general subroutines work for arbitrary combinations of arguments - symbols, distinct or repeated variables, ground compound expressions, and compound expressions containing distinct or repeated variables.
The specialized subroutines work only for specific combinations of arguments, e.g. all ground expressions, two ground expressions, one ground expression and one variable, one variable and one ground expression, two unrelated variables, and so forth. (The compiler uses this information to produce code that is significantly faster than would be otherwise possible.) Specialized subroutines for all bound arguments return booleans. Specialized subroutines for cases with just one free argument return values of that argument. Specialized subroutines with more than one free argument return ground factoids.
The subroutines for each relation are named by the addition of varying numbers of $ characters to the name of the relation, together with combinations of the letters b and f to denote bound and free arguments.
The singular general subroutine for relation r is named $r$, and the plural general subroutine is named $$r$$.
The singular subroutine for a binary relation r with both arguments bound $r$bb$, and there is no plural version (as there can be at most one answer). The singular subroutine for a binary relation r with first argument bound and second argument free $r$bf$, and the plural version is named $$r$bf$$. The singular subroutine for a binary relation r with first argument free and second argument bound $r$fb$, and the plural version is named $$r$fb$$. The singular subroutine for a binary relation r with both arguments free is $r$ff$, and the plural version is named $$r$ff$$.
As an example, consider the rule shown below. The relation goal is defined in terms of the unary relation p and binary relation q.
The general subroutines produced for this ruleset are shown below. Note that there is one singular and one plural subroutine.
See below for the special subroutines produced for our ruleset. There are four singular subroutines and three plural subroutines (for all but the case of ground inputs).
The compiler also generates analogous subroutines for efficiently accessing subroutines for base relations. See below for the subroutines generated in this case.
At present, the compiler generates specialized subroutines for all combinations of arguments for 0-ary, unary, and binary relations (except that it does not generate a plural subroutine for the case when all arguments are bound). For all other relations, it generates only general subroutines.