---
title: "Scallop and scallopy 2026: neurosymbolic Datalog, live demo"
canonical: "https://xerj.org/science/scallop"
updated: "2026-12-06"
---

# Scallop and scallopy in 2026: Datalog for neurosymbolic programming

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](https://github.com/scallop-lang/scallop/blob/master/doc/src/probabilistic/provenance.md))
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.

## Agent prompt

```text
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:

| Provenance | What a tag means | Use it for |

| `unit` | No tag: a fact holds or it does not | Plain Datalog, the default in `scli` and scallopy |
| `minmaxprob` | A probability; a proof is as strong as its weakest fact | Simple probabilistic reasoning, named in the README |
| `topkproofs` | The k most likely proofs of each fact | Probabilities that account for several proofs, as in the docs alarm example |
| `difftopkproofs` | Top k proofs with gradients | Training 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](https://xerj.org/science/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](https://xerj.org/science/neurosymbolic-ai-vs-llm), and for a rule engine over facts a model proposed, see [neurosymbolic reasoning](https://xerj.org/science/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](https://xerj.org/compare/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](https://xerj.org/science/neurosymbolic-ai) and [neurosymbolic models](https://xerj.org/science/neurosymbolic-models).

## Read next

- [Neurosymbolic programming 2026: what it is, tools, live demo](https://xerj.org/science/neurosymbolic-programming)
- [Neurosymbolic AI frameworks 2026](https://xerj.org/compare/neurosymbolic-ai-frameworks-2026)
- [Neurosymbolic AI 2026: what it is, how it works, examples](https://xerj.org/science/neurosymbolic-ai)

## 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](https://xerj.org/science/neurosymbolic-programming) for both side by side.

## Evidence

- Scallop description, provenance semiring framework, the animals example, `scli -p minmaxprob`, the scallopy edge and path example, the MNIST sum module with `difftopkproofs`, and the install commands. Source: [https://github.com/scallop-lang/scallop](https://github.com/scallop-lang/scallop) (README)
- Tags and provenance, and the alarm example that gives 0.224 with `topkproofs`. Source: [https://github.com/scallop-lang/scallop/blob/master/doc/src/probabilistic/provenance.md](https://github.com/scallop-lang/scallop/blob/master/doc/src/probabilistic/provenance.md)
- Scallop: A Language for Neurosymbolic Programming, PLDI 2023. Source: [https://arxiv.org/abs/2304.04812](https://arxiv.org/abs/2304.04812)
- Logic-LM: self-refinement that uses the symbolic solver's error messages to revise the logical form, Findings of EMNLP 2023. Source: [https://aclanthology.org/2023.findings-emnlp.248/](https://aclanthology.org/2023.findings-emnlp.248/)
- Repository facts on 2026-12-06 from the GitHub REST API: scallop-lang/scallop, 530 stars, MIT licence, main language Rust, last push 2026-06-26.

## Related

- [Symbolic AI](https://xerj.org/science/symbolic-ai)
- [Neurosymbolic AI examples](https://xerj.org/science/neurosymbolic-ai-examples)
- [Grounded answers](https://xerj.org/science/grounded-answers)
