2026-03-23 13:46:17 +01:00
# Geolog And Datalog
2026-03-23 13:53:18 +01:00
*A simple explanation of how Geolog is similar to Datalog, and how it is different.*
2026-03-23 13:46:17 +01:00
---
2026-03-23 13:53:18 +01:00
## What This Note Is About
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
Sometimes Geolog looks a lot like Datalog.
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
That is not an accident.
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
Both systems let you:
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
- describe facts,
- describe rules,
- and repeatedly apply those rules until no new facts appear.
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
But Geolog is not just Datalog with different syntax.
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
Geolog also has features that go beyond basic Datalog, especially:
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
- built-in types, called **sorts** ,
- built-in **functions** ,
- rules that can say “something exists”,
- and stronger support for equality.
This note explains the overlap in simple terms.
---
## First: What Is Datalog?
Datalog is a rule language.
It is often written with facts like this:
```prolog
edge(a, b).
edge(b, c).
```
And rules like this:
```prolog
reachable(X, Y) :- edge(X, Y).
reachable(X, Z) :- reachable(X, Y), reachable(Y, Z).
```
You can read those rules as:
- if `edge(X, Y)` is true, then `reachable(X, Y)` is true,
- if `reachable(X, Y)` and `reachable(Y, Z)` are true, then `reachable(X, Z)` is true.
Then the system keeps applying rules until it cannot derive anything new.
---
## Very Short Summary
The best simple summary is:
> Geolog contains a part that behaves a lot like typed Datalog, but full Geolog can do more.
Another good summary is:
> If you ignore some of the more advanced features, you can often read Geolog as “Datalog with types and functions”.
2026-03-23 13:46:17 +01:00
---
## Side-By-Side Mapping
2026-03-23 13:53:18 +01:00
| Idea | In Geolog | In Datalog |
|------|-----------|------------|
| Type of thing | `V : Sort;` | often left implicit, or written as a one-argument fact like `V(x)` |
2026-03-23 13:46:17 +01:00
| Relation | `edge : [from: V, to: V] -> Prop;` | `edge(X, Y)` |
2026-03-23 13:53:18 +01:00
| Function | `src : E -> V;` | usually encoded as a relation like `src(E, V)` |
2026-03-23 13:46:17 +01:00
| Fact | `[from: a, to: b] edge;` | `edge(a, b).` |
2026-03-23 13:53:18 +01:00
| Function value | `e1 src = a;` | `src(e1, a).` |
| Rule | `A, B |- C` | `C :- A, B.` |
| Starting data | an instance | a set of starting facts |
| Repeated rule application | chase | repeated rule evaluation until no new facts appear |
2026-03-23 13:46:17 +01:00
---
2026-03-23 13:53:18 +01:00
## 1. Sorts In Geolog Are Like Types
Geolog has **sorts** .
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
A sort is just a kind of thing.
Example:
2026-03-23 13:46:17 +01:00
```geolog
theory Graph {
V : Sort;
}
```
2026-03-23 13:53:18 +01:00
This says that `V` is a sort. You can think of it as the type “vertex”.
Basic Datalog usually does not have this built in.
If someone wants types in Datalog, they often simulate them with ordinary facts such as:
2026-03-23 13:46:17 +01:00
```prolog
V(a).
V(b).
V(c).
```
2026-03-23 13:53:18 +01:00
So the rough translation is:
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
- **Geolog sort** = **type** ,
- and in Datalog that type is often represented using an ordinary relation.
2026-03-23 13:46:17 +01:00
---
2026-03-23 13:53:18 +01:00
## 2. Relations Match Very Well
This part is simple.
2026-03-23 13:46:17 +01:00
Geolog relation declaration:
```geolog
edge : [from: V, to: V] -> Prop;
```
2026-03-23 13:53:18 +01:00
Geolog fact:
2026-03-23 13:46:17 +01:00
```geolog
[from: a, to: b] edge;
```
2026-03-23 13:53:18 +01:00
Datalog version:
2026-03-23 13:46:17 +01:00
```prolog
edge(a, b).
```
2026-03-23 13:53:18 +01:00
So:
- a Geolog relation is very much like a Datalog predicate,
- and a Geolog relation fact is very much like a Datalog fact.
2026-03-23 13:46:17 +01:00
---
2026-03-23 13:53:18 +01:00
## 3. Functions Need More Care
Geolog has real functions.
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
Example:
2026-03-23 13:46:17 +01:00
```geolog
E : Sort;
V : Sort;
src : E -> V;
e1 : E;
a : V;
e1 src = a;
```
2026-03-23 13:53:18 +01:00
This means:
- `src` takes an edge and gives back one vertex,
- `e1` has source `a` .
In Datalog, people usually write the same information like this:
2026-03-23 13:46:17 +01:00
```prolog
src(e1, a).
```
2026-03-23 13:53:18 +01:00
But there is a difference.
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
In Geolog, `src` is a true function, so each edge should have one source.
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
In plain Datalog, `src(e1, a)` is just a normal fact in a normal relation. Datalog does not automatically know that `src` is supposed to behave like a function.
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
So the simple rule is:
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
- **Geolog function** becomes **a relation in Datalog** ,
- but some meaning is lost unless you also add extra rules or constraints.
2026-03-23 13:46:17 +01:00
---
2026-03-23 13:53:18 +01:00
## 4. Axioms In Geolog Look Like Rules In Datalog
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
Geolog rule:
2026-03-23 13:46:17 +01:00
```geolog
ax/base : forall x,y : V.
[from: x, to: y] edge |- [from: x, to: y] reachable;
```
2026-03-23 13:53:18 +01:00
Datalog rule:
2026-03-23 13:46:17 +01:00
```prolog
reachable(X, Y) :- edge(X, Y).
```
2026-03-23 13:53:18 +01:00
Geolog rule:
2026-03-23 13:46:17 +01:00
```geolog
ax/trans : forall x,y,z : V.
[from: x, to: y] reachable, [from: y, to: z] reachable
|- [from: x, to: z] reachable;
```
2026-03-23 13:53:18 +01:00
Datalog rule:
2026-03-23 13:46:17 +01:00
```prolog
reachable(X, Z) :- reachable(X, Y), reachable(Y, Z).
```
2026-03-23 13:53:18 +01:00
So in the simplest cases:
- **Geolog axiom** behaves like a **Datalog rule** .
2026-03-23 13:46:17 +01:00
---
2026-03-23 13:53:18 +01:00
## 5. A Full Example
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
Here is a Geolog theory and instance:
2026-03-23 13:46:17 +01:00
```geolog
theory Graph {
V : Sort;
edge : [from: V, to: V] -> Prop;
reachable : [from: V, to: V] -> Prop;
ax/base : forall x,y : V.
[from: x, to: y] edge |- [from: x, to: y] reachable;
ax/trans : forall x,y,z : V.
[from: x, to: y] reachable, [from: y, to: z] reachable
|- [from: x, to: z] reachable;
}
instance G : Graph = {
a, b, c : V;
[from: a, to: b] edge;
[from: b, to: c] edge;
}
```
2026-03-23 13:53:18 +01:00
Here is the matching Datalog program:
2026-03-23 13:46:17 +01:00
```prolog
edge(a, b).
edge(b, c).
reachable(X, Y) :- edge(X, Y).
reachable(X, Z) :- reachable(X, Y), reachable(Y, Z).
```
2026-03-23 13:53:18 +01:00
After rule application, both systems derive:
2026-03-23 13:46:17 +01:00
```prolog
reachable(a, b).
reachable(b, c).
reachable(a, c).
```
2026-03-23 13:53:18 +01:00
This is the part of Geolog that feels the most like Datalog.
2026-03-23 13:46:17 +01:00
---
2026-03-23 13:53:18 +01:00
## 6. An Instance Is Just The Starting Data
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
In Geolog, a theory gives:
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
- the names of sorts,
- the names of functions,
- the names of relations,
- and the axioms.
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
Then an instance gives:
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
- the actual elements,
- function values,
- and relation facts.
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
So a Geolog instance is just the starting data for rule application.
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
That is exactly the role that a set of starting facts plays in Datalog.
2026-03-23 13:46:17 +01:00
---
2026-03-23 13:53:18 +01:00
## 7. Chase In Geolog Is Like Repeated Rule Evaluation In Datalog
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
In Geolog, the **chase** means:
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
1. look at the current facts,
2. find an axiom that applies,
3. add the fact that the axiom says must follow,
4. repeat until nothing new appears.
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
In Datalog, the standard evaluation idea is very similar:
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
1. look at the current facts,
2. find a rule whose body is true,
3. add the fact in the head of the rule,
4. repeat until nothing new appears.
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
So for simple rule systems:
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
- **Geolog chase** and **Datalog rule evaluation** are very close.
2026-03-23 13:46:17 +01:00
---
2026-03-23 13:53:18 +01:00
## 8. Where The Analogy Stops Working: “There Exists ...”
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
Geolog can write rules like this:
2026-03-23 13:46:17 +01:00
```geolog
forall p : Person.
|- exists c : Person. [parent: p, kid: c] child;
```
2026-03-23 13:53:18 +01:00
In plain language, this says:
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
- every person has some child.
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
If the system does not already know such a child, Geolog may create a fresh witness during chase.
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
Basic Datalog does not do that.
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
Basic Datalog works with facts and constants that already exist. It does not normally invent brand new objects just because a rule says something must exist.
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
So this is one major way in which Geolog is more expressive than ordinary Datalog.
2026-03-23 13:46:17 +01:00
---
2026-03-23 13:53:18 +01:00
## 9. Where The Analogy Stops Working: Equality
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
Geolog can also reason about equality in richer ways than plain Datalog normally does.
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
That means Geolog can sometimes merge or identify things based on logical consequences, while ordinary Datalog is usually just adding new facts.
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
So equality is another place where Geolog is doing more than basic Datalog.
2026-03-23 13:46:17 +01:00
---
2026-03-23 13:53:18 +01:00
## 10. A Safe Mental Model
If you want a simple way to think about the connection, use this:
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
- a **sort** in Geolog is like a type,
- a **relation** in Geolog is like a predicate in Datalog,
- a **fact** in a Geolog instance is like a Datalog fact,
- an **axiom** in Geolog is often like a Datalog rule,
- and **chase** is like repeatedly applying rules until no new facts appear.
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
That mental model is very useful.
Just remember that full Geolog is richer than plain Datalog.
2026-03-23 13:46:17 +01:00
---
2026-03-23 13:53:18 +01:00
## Final Summary
Here is the simplest correct conclusion:
> A large part of Geolog can be understood as Datalog-like rule evaluation over typed data.
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
But also:
2026-03-23 13:46:17 +01:00
2026-03-23 13:53:18 +01:00
> Full Geolog goes beyond basic Datalog because it has real functions, richer equality reasoning, and rules that can say that new things must exist.
2026-03-23 13:46:17 +01:00