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.

The term and atom classes in edu.harvard.seas.pl.abcdatalog.ast are the building blocks for constructing Datalog programs in Java without going through the text parser. All concrete types use static factory methods and — for Variable, Constant, and PredicateSym — intern instances in a thread-safe memo table so that the same logical entity is always the same Java object.

PredicateSym

A PredicateSym represents a predicate name together with its arity. The same (name, arity) pair always returns the same instance.
public static PredicateSym create(String sym, int arity)
sym
String
required
The predicate name. Must be a non-empty string. By convention, predicate names in Datalog text start with a lowercase letter.
arity
int
required
The number of arguments. Must be non-negative. Throws IllegalArgumentException if negative.
result
PredicateSym
The interned PredicateSym for (sym, arity). getSym() returns the name; getArity() returns the arity.

Variable

A Variable is a logic variable identified by a string name. Variables whose names start with an uppercase letter or _ parse as variables in Datalog text.
public static Variable create(String name)
name
String
required
The variable name. Instances are interned: Variable.create("X") == Variable.create("X").
result
Variable
The interned Variable for the given name. getName() returns the name.
A fresh anonymous variable (equivalent to _ in Datalog text) can be obtained with:
Variable anon = Variable.createFreshVariable();

Constant

A Constant represents a ground value (a zero-ary function symbol). Constants whose names start with a lowercase letter parse as constants in Datalog text.
public static Constant create(String name)
name
String
required
The constant name. Instances are interned: Constant.create("a") == Constant.create("a").
result
Constant
The interned Constant for the given name. getName() returns the name.

PositiveAtom

A PositiveAtom pairs a PredicateSym with a Term[] argument array. It implements both Head and Premise.
public static PositiveAtom create(PredicateSym pred, Term[] args)
pred
PredicateSym
required
The predicate symbol. Its arity must equal args.length; otherwise IllegalArgumentException is thrown.
args
Term[]
required
The argument array. The array is owned by the created atom and must not be modified after being passed in.
result
PositiveAtom
The new atom. getPred() returns the predicate symbol; getArgs() returns the argument array; isGround() returns true if all arguments are Constant instances.

NegatedAtom

NegatedAtom wraps a PositiveAtom with negation. It implements Premise and holds in evaluation when its inner atom is not derivable.
// Wrap an existing atom
public NegatedAtom(PositiveAtom atom)

// Construct directly from predicate and args
public NegatedAtom(PredicateSym pred, Term[] args)
getPred(), getArgs(), and isGround() delegate to the wrapped atom. asPositiveAtom() returns the inner PositiveAtom.

BinaryUnifier

BinaryUnifier represents a left = right premise in a rule body. It implements Premise.
public BinaryUnifier(Term left, Term right)
left
Term
required
A variable or constant on the left side of =.
right
Term
required
A variable or constant on the right side of =.
getLeft() and getRight() return the two terms. Must be enabled via DatalogValidator.withBinaryUnificationInRuleBody().

BinaryDisunifier

BinaryDisunifier represents a left != right premise. It holds when the two terms cannot be unified.
public BinaryDisunifier(Term left, Term right)
left
Term
required
A variable or constant on the left side of !=.
right
Term
required
A variable or constant on the right side of !=.
getLeft() and getRight() return the two terms. Must be enabled via DatalogValidator.withBinaryDisunificationInRuleBody().

Code example: building an AST programmatically

The following is adapted from EngineExample.makeQuery:
import edu.harvard.seas.pl.abcdatalog.ast.*;
import java.util.Arrays;
import java.util.Collections;

// Predicates
PredicateSym edgePred = PredicateSym.create("edge", 2);
PredicateSym tcPred   = PredicateSym.create("tc",   2);

// Terms
Term a = Constant.create("a");
Term b = Constant.create("b");
Term x = Variable.create("X");
Term y = Variable.create("Y");
Term z = Variable.create("Z");

// EDB facts: edge(a,b). edge(b,c).
Clause fact1 = new Clause(
    PositiveAtom.create(edgePred, new Term[]{a, b}),
    Collections.emptyList());
Clause fact2 = new Clause(
    PositiveAtom.create(edgePred, new Term[]{b, Constant.create("c")}),
    Collections.emptyList());

// Rule: tc(X,Y) :- edge(X,Y).
Clause rule = new Clause(
    PositiveAtom.create(tcPred, new Term[]{x, y}),
    Arrays.asList(PositiveAtom.create(edgePred, new Term[]{x, y})));

// Query atom: tc(X,Y)
PositiveAtom query = PositiveAtom.create(tcPred, new Term[]{x, y});

Build docs developers (and LLMs) love