Top-down evaluation works in the opposite direction from bottom-up: instead of saturating all derivable facts upfront, it starts from the query and works backwards through rules, generating only the subgoals needed to answer that specific query. AbcDatalog provides one top-down engine —Documentation Index
Fetch the complete documentation index at: https://mintlify.com/HarvardPL/AbcDatalog/llms.txt
Use this file to discover all available pages before exploring further.
IterativeQsqEngine — which implements the Query-Subquery (QSQ) algorithm.
The QSQ algorithm
QSQ is an adornment-based, demand-driven evaluation method. When a query such astc(a, Y)? is posed, QSQ adorns the predicate with a binding pattern (here: tc^{bf}, meaning the first argument is bound and the second is free). The engine then generates adorned versions of the rules that define tc, restricting rule evaluation to tuples consistent with the known bindings. Intermediate results are propagated through a set of supplementary relations that carry binding information sideways across the body of each rule. This process continues iteratively until no new answers can be generated.
The practical effect is that the engine may explore only a small portion of the full fixpoint, which is beneficial when a query has selective bound arguments and the complete derivation would be much larger than what the query actually needs.
IterativeQsqEngine
IterativeQsqEngine extends AbstractQsqEngine, which handles program initialization (separating EDB facts from IDB rules). IterativeQsqEngine provides the concrete query() implementation using the iterative QSQ loop.
There is no static factory method; instantiate it directly with new IterativeQsqEngine().
When to prefer top-down evaluation
Top-down evaluation is most advantageous when:- The query has one or more bound arguments that significantly restrict the search space (e.g.,
tc(a, Y)?rather thantc(X, Y)?). - The program has large EDB relations but only a small subset of facts is relevant to the query.
- You want to avoid the upfront cost of saturating the entire fixpoint.