SCIENCE · NEUROSYMBOLIC AI

Scallop and scallopy in 2026: Datalog for neurosymbolic programming

AUTHOR · XERJ documentation team · REVIEWED BY · XERJ engineering team · PUBLISHED · 2026-12-06 · UPDATED · 2026-12-06
SHORT ANSWER · UPDATED 2026-12-06

What is Scallop? Scallop is a language based on Datalog for neurosymbolic programming: rules reason over facts, and each fact can carry a tag such as a probability, so the same program does discrete, probabilistic or differentiable reasoning. scallopy is its Python binding, and it plugs Scallop rules into PyTorch models so a network can be trained through the logic.

Key number: Scallop programs can be tagged: with the topkproofs provenance, alarm() = earthquake() or burglary() with tags 0.03 and 0.20 gives 0.224, which is 1 minus 0.97 times 0.8. (source: Scallop docs, Tags and Provenance)

Last checked: 2026-12-06. Repository facts from the GitHub REST API on that date; code and commands from the Scallop README; paper linked in Evidence.

TL;DR Scallop gives you Datalog rules that work with uncertain facts. Tag a fact with a probability, choose a provenance, and Scallop carries the tags through every proof. With scallopy you call it from Python, and with a differentiable provenance it becomes a PyTorch layer that a neural network can learn through. Try a program below, then read how the pieces fit.

Try it: run a Scallop program

Write facts and rules, pick a provenance, read every proof

Examples

ResultProbabilityProofs (base facts)
Runs in your browser and sends nothing. This is a small JavaScript re-implementation of a Scallop subset for learning (tagged facts, rules with and, or and recursion, query), not the Scallop engine; aggregation such as count is left out. Facts are independent. The alarm example reproduces the 0.224 that the Scallop docs report for topkproofs, and a typo shows the line-numbered error a solver hands back to an LLM so it can fix its program.
PASTE THIS TO YOUR AI AGENT. IT DOES THE REST Act as an AI engineer. Read https://xerj.org/science/scallop and https://xerj.org/compare/neurosymbolic-ai-frameworks-2026. Find one place in my project where a model outputs probabilities and a rule could reason over them, write that rule as a Scallop program with a provenance, and sketch the scallopy code that connects it. Index my repo with https://xerj.org first and cite file paths.

How Scallop works

A Scallop program has relations, facts and rules. rel is_a("tiger", "mammal") is a fact. rel name(a, b) :- name(a, c), is_a(c, b) is a rule: lowercase names such as a are variables, and the rule keeps applying until nothing new follows. Rules can be recursive, so a two line program computes every path in a graph.

The neurosymbolic part is the tag. In the README example an image model is unsure whether object 1 is a giraffe (0.3) or a tiger (0.7). Scallop keeps those numbers on the facts, and the rules carry them forward, so the program can say how likely it is that object 1 is an animal. Run the Animals example above to see it.

Provenance: one program, several kinds of reasoning

Scallop is built on the provenance semiring framework. A provenance decides how tags combine when facts are joined with and or merged with or. The Scallop README and docs name these, among others:

ProvenanceWhat a tag meansUse it for
unitNo tag: a fact holds or it does notPlain Datalog, the default in scli and scallopy
minmaxprobA probability; a proof is as strong as its weakest factSimple probabilistic reasoning, named in the README
topkproofsThe k most likely proofs of each factProbabilities that account for several proofs, as in the docs alarm example
difftopkproofsTop k proofs with gradientsTraining a PyTorch network through the rules, as in the README MNIST sum

On the command line you pick one with scli program.scl -p minmaxprob. In scallopy you pass provenance= when you create the context.

scallopy: Scallop from Python

This is the graph path example from the Scallop README. It adds two edges, two rules and prints every path.

import scallopy

ctx = scallopy.ScallopContext()
ctx.add_relation("edge", (int, int))
ctx.add_facts("edge", [(0, 1), (1, 2)])
ctx.add_rule("path(a, c) = edge(a, c)")
ctx.add_rule("path(a, c) = edge(a, b), path(b, c)")
ctx.run()
print(list(ctx.relation("path")))  # [(0, 1), (0, 2), (1, 2)]

For training, the README builds a two digit sum model. A digit network outputs ten probabilities per image, Scallop applies one rule, and the result is a 19 way output that a normal loss can train:

self.scl_ctx = scallopy.ScallopContext(provenance="difftopkproofs", k=k)
self.scl_ctx.add_relation("digit_1", int, input_mapping=list(range(10)))
self.scl_ctx.add_relation("digit_2", int, input_mapping=list(range(10)))
self.scl_ctx.add_rule("sum_2(a + b) = digit_1(a), digit_2(b)")
self.sum_2 = self.scl_ctx.forward_function("sum_2", list(range(19)))

This is the same MNIST addition task that DeepProbLog made famous, and you can try its logic step by step on neurosymbolic programming.

Install Scallop and scallopy

The README builds from source with nightly Rust. These are its commands:

rustup default nightly
git clone https://github.com/scallop-lang/scallop.git && cd scallop
make install-scli        # interpreter
pip install maturin
make install-scallopy    # Python binding

The repository also has make install-sclc for the compiler and sclrepl, a REPL for trying rules one line at a time, plus a VSCode extension. The README links an online playground at scallop.build.

Scallop and LLMs

The same split works with a language model as the neural part. The model reads a question and writes facts or rules, and a solver runs them. Logic-LM showed that when the solver reports an error, sending the error message back lets the model fix its own program. Type a mistake into the demo above to see that kind of message. For the measured gains, see neurosymbolic AI vs LLM, and for a rule engine over facts a model proposed, see neurosymbolic reasoning.

When to choose Scallop

Choose Scallop when your rules are relational, such as graphs, hierarchies or scene facts, and you want probabilities or training through them. Choose DeepProbLog for ProbLog and Prolog style programs, Logic Tensor Networks for fuzzy first-order logic in the loss, and Z3 or clingo when an LLM hands constraints to a solver. The full table is in neurosymbolic AI frameworks 2026.

How XERJ uses it

XERJ is a new way for AI to search for data, with a neurosymbolic model inside. XERJ Query-1 compiles a prompt to a search program you can read, and the engine checks results against stored facts, the same propose then check split that Scallop gives you for learning. See neurosymbolic AI and neurosymbolic models.

Read next

FAQ

What is Scallop?

Scallop is a language based on Datalog that supports differentiable logical and relational reasoning. It runs on its own as a Datalog solver, from Python through scallopy, and inside PyTorch models. It is open source under the MIT licence and written mainly in Rust.

What is scallopy?

scallopy is the Python binding for Scallop. You create a ScallopContext, add relations, facts and rules, call run() and read the results. It also builds PyTorch modules, so a network's output probabilities feed a Scallop rule and gradients flow back through it.

How do you install scallopy?

The Scallop README builds it from source: install Rust with the nightly channel as default, clone the repository, pip install maturin and run make install-scallopy. The same repository builds the scli interpreter, the sclc compiler and the sclrepl REPL.

What is a provenance in Scallop?

A provenance is the rule set for how tags on facts combine as the program runs. Scallop is built on the provenance semiring framework, so the same program can run with plain true or false facts, with probabilities, or with gradients for training. You pick one with -p on the command line or the provenance argument in scallopy.

What is the difference between minmaxprob and topkproofs?

minmaxprob scores a proof by its weakest fact and an answer by its best proof. topkproofs keeps the k most likely proofs of each fact and computes the probability that at least one holds. On the Scallop docs alarm example, topkproofs gives 0.224 for alarm, and the demo on this page reproduces that number.

Is Scallop the same as DeepProbLog?

No. Both train neural networks through logic, but DeepProbLog extends ProbLog, a Prolog dialect, while Scallop extends Datalog and lets you swap the provenance. See neurosymbolic programming for both side by side.

Evidence

Related