Skip to main content

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.

DatalogEngine is the primary interface for evaluating Datalog programs in AbcDatalog. You initialize an engine with a set of Clause objects representing both EDB facts (body-less clauses) and IDB rules, after which the engine derives all consequences and answers point queries or conjunctive queries against the fully-computed result.

Methods

init

void init(Set<Clause> program) throws DatalogValidationException
Initializes the engine with a Datalog program. The set must include both the initial EDB facts (encoded as clauses with empty bodies) and the IDB rules used to derive new facts. The engine validates the program before evaluation begins.
program
Set<Clause>
required
The full program: a mix of body-less fact clauses and rules. Passed directly to the engine’s internal validator.
Calling init a second time on the same engine instance throws IllegalStateException. Create a new engine instance if you need to evaluate a different program.

query (single atom)

Set<PositiveAtom> query(PositiveAtom q)
Returns all ground facts derivable from the program that unify with the query atom q. Variables in q act as wildcards.
q
PositiveAtom
required
The query pattern. May contain variables, which are treated as existential wildcards during unification.
result
Set<PositiveAtom>
The set of all ground facts derivable from the program that unify with q. Returns an empty set if none match.

query (conjunctive)

default Set<ConstOnlySubstitution> query(List<PositiveAtom> query)
Returns the set of all minimal substitutions that simultaneously ground every atom in query and make the conjunction true with respect to the program. This is a default method implemented via ConjunctiveQueryHelper.
query
List<PositiveAtom>
required
A conjunctive query: a list of positive atoms sharing variables across elements.
result
Set<ConstOnlySubstitution>
Each ConstOnlySubstitution in the result maps the variables in query to constants. Apply a substitution to the query list using SubstitutionUtils.applyToPositiveAtoms to obtain a concrete solution.

Code example

import edu.harvard.seas.pl.abcdatalog.ast.Clause;
import edu.harvard.seas.pl.abcdatalog.ast.PositiveAtom;
import edu.harvard.seas.pl.abcdatalog.engine.DatalogEngine;
import edu.harvard.seas.pl.abcdatalog.engine.bottomup.sequential.SemiNaiveEngine;
import edu.harvard.seas.pl.abcdatalog.parser.DatalogParser;
import edu.harvard.seas.pl.abcdatalog.parser.DatalogTokenizer;
import java.io.StringReader;
import java.util.Set;

String src =
    "edge(a,b). edge(b,c). edge(c,d)."
    + "tc(X,Y) :- edge(X,Y)."
    + "tc(X,Y) :- tc(X,Z), tc(Z,Y).";

DatalogTokenizer t = new DatalogTokenizer(new StringReader(src));
Set<Clause> prog = DatalogParser.parseProgram(t);

DatalogEngine engine = SemiNaiveEngine.newEngine();
engine.init(prog);

// Single-atom query: find all pairs reachable from a
DatalogTokenizer qt = new DatalogTokenizer(new StringReader("tc(a, Y)?"));
PositiveAtom q = DatalogParser.parseQuery(qt);
Set<PositiveAtom> results = engine.query(q);
results.forEach(System.out::println);

Concrete implementations

SemiNaiveEngine

Classic semi-naive bottom-up evaluation. Supports explicit unification and stratified negation. Also implements DatalogEngineWithProvenance.

ConcurrentBottomUpEngine

Multi-threaded bottom-up evaluation using a work-stealing thread pool.

ConcurrentChunkedBottomUpEngine

Concurrent bottom-up engine that processes derived facts in chunks for improved cache locality.

ConcurrentStratifiedNegationBottomUpEngine

Concurrent engine with support for stratified negation.

IterativeQsqEngine

Top-down query-sub-query (QSQ) evaluation using an iterative fixpoint loop.

Build docs developers (and LLMs) love