tiny-datalog 0.4.0__tar.gz → 0.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tiny_datalog-0.4.0/tiny_datalog.egg-info → tiny_datalog-0.6.0}/PKG-INFO +62 -29
- {tiny_datalog-0.4.0 → tiny_datalog-0.6.0}/README.md +61 -28
- {tiny_datalog-0.4.0 → tiny_datalog-0.6.0}/pyproject.toml +2 -1
- {tiny_datalog-0.4.0 → tiny_datalog-0.6.0}/tiny_datalog/__init__.py +3 -2
- tiny_datalog-0.6.0/tiny_datalog/chase.py +401 -0
- {tiny_datalog-0.4.0 → tiny_datalog-0.6.0}/tiny_datalog/containment.py +11 -1
- {tiny_datalog-0.4.0 → tiny_datalog-0.6.0}/tiny_datalog/core.py +290 -19
- {tiny_datalog-0.4.0 → tiny_datalog-0.6.0}/tiny_datalog/datalog.py +135 -21
- {tiny_datalog-0.4.0 → tiny_datalog-0.6.0}/tiny_datalog/engines.py +11 -5
- {tiny_datalog-0.4.0 → tiny_datalog-0.6.0}/tiny_datalog/incremental.py +18 -7
- {tiny_datalog-0.4.0 → tiny_datalog-0.6.0}/tiny_datalog/magic.py +19 -1
- {tiny_datalog-0.4.0 → tiny_datalog-0.6.0}/tiny_datalog/prolog.py +4 -1
- {tiny_datalog-0.4.0 → tiny_datalog-0.6.0}/tiny_datalog/semantics.py +6 -3
- {tiny_datalog-0.4.0 → tiny_datalog-0.6.0}/tiny_datalog/semiring.py +10 -3
- {tiny_datalog-0.4.0 → tiny_datalog-0.6.0}/tiny_datalog/tabling.py +9 -4
- {tiny_datalog-0.4.0 → tiny_datalog-0.6.0/tiny_datalog.egg-info}/PKG-INFO +62 -29
- {tiny_datalog-0.4.0 → tiny_datalog-0.6.0}/tiny_datalog.egg-info/SOURCES.txt +1 -0
- {tiny_datalog-0.4.0 → tiny_datalog-0.6.0}/tiny_datalog.egg-info/entry_points.txt +1 -0
- {tiny_datalog-0.4.0 → tiny_datalog-0.6.0}/LICENSE +0 -0
- {tiny_datalog-0.4.0 → tiny_datalog-0.6.0}/setup.cfg +0 -0
- {tiny_datalog-0.4.0 → tiny_datalog-0.6.0}/tiny_datalog/defeasible.py +0 -0
- {tiny_datalog-0.4.0 → tiny_datalog-0.6.0}/tiny_datalog/subsumption.py +0 -0
- {tiny_datalog-0.4.0 → tiny_datalog-0.6.0}/tiny_datalog.egg-info/dependency_links.txt +0 -0
- {tiny_datalog-0.4.0 → tiny_datalog-0.6.0}/tiny_datalog.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tiny-datalog
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: A Datalog engine whose core you can read in an afternoon, and a course built on it
|
|
5
5
|
Author: Andrew Goodchild
|
|
6
6
|
License-Expression: MIT
|
|
@@ -127,7 +127,7 @@ Nothing to install:
|
|
|
127
127
|
|
|
128
128
|
```sh
|
|
129
129
|
git clone https://github.com/andrewgoodchild/tiny-datalog && cd tiny-datalog
|
|
130
|
-
python3 tests.py #
|
|
130
|
+
python3 tests.py # 362 tests, ~20s
|
|
131
131
|
```
|
|
132
132
|
|
|
133
133
|
## Why the language choice decides what you can ask later
|
|
@@ -183,7 +183,9 @@ it:
|
|
|
183
183
|
|
|
184
184
|
Every feature in this repository is a check of that kind: stratification
|
|
185
185
|
catches circularity, `--models` catches contradiction and ambiguity,
|
|
186
|
-
`containment.py` catches redundancy,
|
|
186
|
+
`containment.py` catches redundancy, integrity constraints catch a rule
|
|
187
|
+
set that breaks the policy stated another way, warnings catch the typo
|
|
188
|
+
that silently empties a relation, and `--explain` produces the
|
|
187
189
|
derivation somebody has to sign off on.
|
|
188
190
|
|
|
189
191
|
Two limits. An engine checks coherence, not intent: a rule set can pass
|
|
@@ -194,7 +196,7 @@ the better tool, and that covers most problems.
|
|
|
194
196
|
|
|
195
197
|
## What else you can ask it
|
|
196
198
|
|
|
197
|
-
The worked example above is one row of a table. The full version —
|
|
199
|
+
The worked example above is one row of a table. The full version — 32
|
|
198
200
|
questions, each with the command that answers it and the lesson that
|
|
199
201
|
builds the machinery — is in
|
|
200
202
|
[getting started](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/getting-started.md), beside the reading
|
|
@@ -249,8 +251,14 @@ the current research threads. The field's own recent lecture notes
|
|
|
249
251
|
observe that the literature advises people building Datalog engines
|
|
250
252
|
better than people trying to *use* one; this course does both halves
|
|
251
253
|
on purpose — sixteen lessons where the engine is the explanation, then
|
|
252
|
-
a lesson on authoring rules that survive review,
|
|
253
|
-
built for rules with exceptions
|
|
254
|
+
a lesson on authoring rules that survive review, one on a logic
|
|
255
|
+
built for rules with exceptions, and five where the engine goes to
|
|
256
|
+
work: [authorization](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/20-authorization.md),
|
|
257
|
+
[program analysis](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/21-program-analysis.md),
|
|
258
|
+
[knowledge graphs and the chase](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/22-knowledge-graphs.md),
|
|
259
|
+
[time and history](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/23-time.md),
|
|
260
|
+
and [memory for a language-model agent](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/24-memory.md).
|
|
261
|
+
And it is built to be
|
|
254
262
|
inherited: `git clone`, no dependencies, no hosted anything, and every
|
|
255
263
|
quoted transcript re-verified by CI — the exercises cannot rot. (For where each
|
|
256
264
|
technique ships — CodeQL, RDFox, Feldera, SNOMED and the rest —
|
|
@@ -297,10 +305,9 @@ see [pyDatalog](https://pypi.org/project/pyDatalog/).
|
|
|
297
305
|
Deliberate omissions, because saying why teaches more than lacking them
|
|
298
306
|
quietly:
|
|
299
307
|
|
|
300
|
-
- **Arithmetic
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
become trees. [Lesson 14](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/14-arithmetic.md) is the whole
|
|
308
|
+
- **Arithmetic.** `Z = X + 1` makes values nobody stated, so it can make
|
|
309
|
+
a relation infinite, and the termination theorem goes with it.
|
|
310
|
+
[Lesson 14](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/14-arithmetic.md) is the whole
|
|
304
311
|
story, including what to do instead.
|
|
305
312
|
- **Indexes and join planning.** Every join is a nested loop so the
|
|
306
313
|
algorithms stay one-screen readable. It is also why the magic-sets
|
|
@@ -313,7 +320,10 @@ quietly:
|
|
|
313
320
|
|
|
314
321
|
Aggregation used to be on this list;
|
|
315
322
|
[lesson 13](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/13-aggregation.md) is what promoting an omission
|
|
316
|
-
into a feature looks like.
|
|
323
|
+
into a feature looks like. Comparisons (`<`, `<=`, `>`, `>=`, `=`,
|
|
324
|
+
`!=`) used to share arithmetic's entry. They check values and never
|
|
325
|
+
make them, so they can only filter, and lesson 14's own argument lets
|
|
326
|
+
them in; [lesson 23](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/23-time.md) puts them to work.
|
|
317
327
|
|
|
318
328
|
## Using it in your own project
|
|
319
329
|
|
|
@@ -350,6 +360,25 @@ engine = run_program(rules, facts={
|
|
|
350
360
|
engine.query("exposed(S, C)") # [{'S': 'app', 'C': 'cve_2026_0001'}]
|
|
351
361
|
```
|
|
352
362
|
|
|
363
|
+
A rule with no head is an integrity constraint, a situation that must
|
|
364
|
+
never arise. `engine.violations()` lists each broken one with its
|
|
365
|
+
counterexamples, and the command line prints them and exits with
|
|
366
|
+
status 3:
|
|
367
|
+
|
|
368
|
+
```python
|
|
369
|
+
checked = run_program(rules + ":- exposed(S, C).", facts={
|
|
370
|
+
"depends": [("app", "lib"), ("lib", "core")],
|
|
371
|
+
"service": ["app"],
|
|
372
|
+
"vulnerable": [("core", "cve_2026_0001")],
|
|
373
|
+
})
|
|
374
|
+
checked.violations() # [(constraint, [{'S': 'app', 'C': 'cve_2026_0001'}])]
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
For agents, `skills/tiny-datalog/SKILL.md` is an Agent Skill that
|
|
378
|
+
teaches a coding agent the language and the habits (explain before
|
|
379
|
+
trusting, state properties as constraints); copy it into your agent's
|
|
380
|
+
skills directory.
|
|
381
|
+
|
|
353
382
|
The command-line interface installs too, as `tiny-datalog` (and
|
|
354
383
|
`tiny-datalog-semiring`, `-tabling`, `-incremental`, `-subsumption`,
|
|
355
384
|
`-containment`, `-defeasible`, `-prolog` for the other engines and the
|
|
@@ -367,11 +396,12 @@ installed package; clone the repository for that.
|
|
|
367
396
|
```
|
|
368
397
|
tiny_datalog/ the code you read, in three tiers:
|
|
369
398
|
core.py the common core — the language every module shares:
|
|
370
|
-
AST, parser, safety checks,
|
|
371
|
-
formatting, query helpers
|
|
399
|
+
AST, parser, safety checks, comparisons, stratification,
|
|
400
|
+
matching, formatting, query helpers, warnings
|
|
372
401
|
engines — four strategies, one answer (engines.py lists them):
|
|
373
402
|
datalog.py the base engine: semi-naive and naive bottom-up
|
|
374
|
-
evaluation, aggregation,
|
|
403
|
+
evaluation, aggregation, integrity constraints,
|
|
404
|
+
--explain / why-not, --assume, the CLI
|
|
375
405
|
magic.py the magic-sets rewriting (a program-to-program pass)
|
|
376
406
|
tabling.py tabled top-down evaluation (iterative QSQR)
|
|
377
407
|
engines.py the registry and the interface the four share
|
|
@@ -384,18 +414,21 @@ tiny_datalog/ the code you read, in three tiers:
|
|
|
384
414
|
subsumption.py KL-ONE-style EL classifier, compiled to Datalog
|
|
385
415
|
containment.py query containment and minimisation by homomorphism
|
|
386
416
|
defeasible.py defeasible logic: exceptions, priorities, defeaters
|
|
417
|
+
chase.py existential rules: the chase, labelled nulls, weak
|
|
418
|
+
acyclicity
|
|
387
419
|
*.py three-line launchers, so `python3 datalog.py ...` works
|
|
388
420
|
straight from a checkout with nothing installed
|
|
389
|
-
programs/ teaching programs,
|
|
390
|
-
|
|
391
|
-
lessons/ getting started, glossary, and lessons 0–
|
|
421
|
+
programs/ teaching programs, named for what they model; each
|
|
422
|
+
lesson says which ones it runs
|
|
423
|
+
lessons/ getting started, glossary, and lessons 0–24
|
|
392
424
|
exercises/ worked answers, verified by the test suite
|
|
393
425
|
cases/ golden test cases — add one without writing Python
|
|
426
|
+
skills/ an Agent Skill that teaches coding agents to use the engine
|
|
394
427
|
conformance/ the external datalog-conformance corpus (Soufflé, Nemo,
|
|
395
428
|
Crepe, SPINdle), run against every evaluation strategy
|
|
396
429
|
benchmarks/ scaled input generators (chain/tree/clique/grid, an EL
|
|
397
430
|
ontology, and the N-queens puzzle)
|
|
398
|
-
tests.py
|
|
431
|
+
tests.py 362 tests: every shipped program and exercise answer is
|
|
399
432
|
executed, a conformance suite runs every query through
|
|
400
433
|
every engine that handles it, and a seeded fuzzer checks
|
|
401
434
|
the same property on random programs
|
|
@@ -412,7 +445,7 @@ This project started as an attempt at a tiny implementation of
|
|
|
412
445
|
Datalog, small enough to read in an afternoon. It grew with the
|
|
413
446
|
course. Each lesson that taught a new technique — magic sets, stable models,
|
|
414
447
|
semirings, incremental maintenance, tabling, subsumption, containment,
|
|
415
|
-
defeasible logic — brought a module to run it, and the repository is
|
|
448
|
+
defeasible logic, the chase — brought a module to run it, and the repository is
|
|
416
449
|
now several thousand lines. The core idea stayed small, and the code
|
|
417
450
|
is laid out so you can still read just that: the common core and the
|
|
418
451
|
base engine, below, are the original tiny Datalog. Everything else is
|
|
@@ -422,21 +455,21 @@ Measured in lines, comments, docstrings and blank lines included:
|
|
|
422
455
|
|
|
423
456
|
| Tier | Lines |
|
|
424
457
|
|---|---|
|
|
425
|
-
| the common core (`core.py`: the language, evaluating nothing) |
|
|
426
|
-
| the base engine's evaluator (`datalog.py` up to its CLI section: the module docstring, the import list that re-exports the core, `Program`, `Engine`, aggregation folding, `run_program`) |
|
|
427
|
-
| `--explain`, why-not, printing and the CLI (the rest of `datalog.py`) |
|
|
428
|
-
| the other pluggable engines: magic sets (`magic.py`) and tabling (`tabling.py`), plus the `engines.py` registry (naive evaluation is a flag on the base engine) |
|
|
429
|
-
| the
|
|
458
|
+
| the common core (`core.py`: the language, evaluating nothing; about 270 of these lines arrived with comparisons, constraints, value checks and the warnings) | 1,056 |
|
|
459
|
+
| the base engine's evaluator (`datalog.py` up to its CLI section: the module docstring, the import list that re-exports the core, `Program`, `Engine`, aggregation folding, `run_program`) | 423 |
|
|
460
|
+
| `--explain`, why-not, constraint reports, `--assume`, printing and the CLI (the rest of `datalog.py`) | 621 |
|
|
461
|
+
| the other pluggable engines: magic sets (`magic.py`) and tabling (`tabling.py`), plus the `engines.py` registry (naive evaluation is a flag on the base engine) | 578 |
|
|
462
|
+
| the eight extensions | 2,860 |
|
|
430
463
|
|
|
431
464
|
So the smallest complete Datalog system here — parse, check, stratify,
|
|
432
|
-
evaluate semi-naively — is the core plus the evaluator, about 1,
|
|
433
|
-
lines. All of it is
|
|
465
|
+
evaluate semi-naively — is the core plus the evaluator, about 1,500
|
|
466
|
+
lines. All of it is 5.5k lines of toolkit (every module but the
|
|
434
467
|
re-export list in `__init__.py`), roughly a quarter of it commentary,
|
|
435
|
-
and 3.
|
|
468
|
+
and 3.9k of tests.
|
|
436
469
|
|
|
437
470
|
"Tiny" is a claim about that core and evaluator, and about each module
|
|
438
|
-
built on them singly: none of the
|
|
439
|
-
`engines.py` and the
|
|
471
|
+
built on them singly: none of the eleven (`magic.py`, `tabling.py`,
|
|
472
|
+
`engines.py` and the eight extensions) exceeds 500 lines, which a test asserts. It is not a
|
|
440
473
|
claim about the repository, which is a dozen modules because it
|
|
441
474
|
teaches a dozen things.
|
|
442
475
|
|
|
@@ -94,7 +94,7 @@ Nothing to install:
|
|
|
94
94
|
|
|
95
95
|
```sh
|
|
96
96
|
git clone https://github.com/andrewgoodchild/tiny-datalog && cd tiny-datalog
|
|
97
|
-
python3 tests.py #
|
|
97
|
+
python3 tests.py # 362 tests, ~20s
|
|
98
98
|
```
|
|
99
99
|
|
|
100
100
|
## Why the language choice decides what you can ask later
|
|
@@ -150,7 +150,9 @@ it:
|
|
|
150
150
|
|
|
151
151
|
Every feature in this repository is a check of that kind: stratification
|
|
152
152
|
catches circularity, `--models` catches contradiction and ambiguity,
|
|
153
|
-
`containment.py` catches redundancy,
|
|
153
|
+
`containment.py` catches redundancy, integrity constraints catch a rule
|
|
154
|
+
set that breaks the policy stated another way, warnings catch the typo
|
|
155
|
+
that silently empties a relation, and `--explain` produces the
|
|
154
156
|
derivation somebody has to sign off on.
|
|
155
157
|
|
|
156
158
|
Two limits. An engine checks coherence, not intent: a rule set can pass
|
|
@@ -161,7 +163,7 @@ the better tool, and that covers most problems.
|
|
|
161
163
|
|
|
162
164
|
## What else you can ask it
|
|
163
165
|
|
|
164
|
-
The worked example above is one row of a table. The full version —
|
|
166
|
+
The worked example above is one row of a table. The full version — 32
|
|
165
167
|
questions, each with the command that answers it and the lesson that
|
|
166
168
|
builds the machinery — is in
|
|
167
169
|
[getting started](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/getting-started.md), beside the reading
|
|
@@ -216,8 +218,14 @@ the current research threads. The field's own recent lecture notes
|
|
|
216
218
|
observe that the literature advises people building Datalog engines
|
|
217
219
|
better than people trying to *use* one; this course does both halves
|
|
218
220
|
on purpose — sixteen lessons where the engine is the explanation, then
|
|
219
|
-
a lesson on authoring rules that survive review,
|
|
220
|
-
built for rules with exceptions
|
|
221
|
+
a lesson on authoring rules that survive review, one on a logic
|
|
222
|
+
built for rules with exceptions, and five where the engine goes to
|
|
223
|
+
work: [authorization](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/20-authorization.md),
|
|
224
|
+
[program analysis](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/21-program-analysis.md),
|
|
225
|
+
[knowledge graphs and the chase](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/22-knowledge-graphs.md),
|
|
226
|
+
[time and history](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/23-time.md),
|
|
227
|
+
and [memory for a language-model agent](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/24-memory.md).
|
|
228
|
+
And it is built to be
|
|
221
229
|
inherited: `git clone`, no dependencies, no hosted anything, and every
|
|
222
230
|
quoted transcript re-verified by CI — the exercises cannot rot. (For where each
|
|
223
231
|
technique ships — CodeQL, RDFox, Feldera, SNOMED and the rest —
|
|
@@ -264,10 +272,9 @@ see [pyDatalog](https://pypi.org/project/pyDatalog/).
|
|
|
264
272
|
Deliberate omissions, because saying why teaches more than lacking them
|
|
265
273
|
quietly:
|
|
266
274
|
|
|
267
|
-
- **Arithmetic
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
become trees. [Lesson 14](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/14-arithmetic.md) is the whole
|
|
275
|
+
- **Arithmetic.** `Z = X + 1` makes values nobody stated, so it can make
|
|
276
|
+
a relation infinite, and the termination theorem goes with it.
|
|
277
|
+
[Lesson 14](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/14-arithmetic.md) is the whole
|
|
271
278
|
story, including what to do instead.
|
|
272
279
|
- **Indexes and join planning.** Every join is a nested loop so the
|
|
273
280
|
algorithms stay one-screen readable. It is also why the magic-sets
|
|
@@ -280,7 +287,10 @@ quietly:
|
|
|
280
287
|
|
|
281
288
|
Aggregation used to be on this list;
|
|
282
289
|
[lesson 13](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/13-aggregation.md) is what promoting an omission
|
|
283
|
-
into a feature looks like.
|
|
290
|
+
into a feature looks like. Comparisons (`<`, `<=`, `>`, `>=`, `=`,
|
|
291
|
+
`!=`) used to share arithmetic's entry. They check values and never
|
|
292
|
+
make them, so they can only filter, and lesson 14's own argument lets
|
|
293
|
+
them in; [lesson 23](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/23-time.md) puts them to work.
|
|
284
294
|
|
|
285
295
|
## Using it in your own project
|
|
286
296
|
|
|
@@ -317,6 +327,25 @@ engine = run_program(rules, facts={
|
|
|
317
327
|
engine.query("exposed(S, C)") # [{'S': 'app', 'C': 'cve_2026_0001'}]
|
|
318
328
|
```
|
|
319
329
|
|
|
330
|
+
A rule with no head is an integrity constraint, a situation that must
|
|
331
|
+
never arise. `engine.violations()` lists each broken one with its
|
|
332
|
+
counterexamples, and the command line prints them and exits with
|
|
333
|
+
status 3:
|
|
334
|
+
|
|
335
|
+
```python
|
|
336
|
+
checked = run_program(rules + ":- exposed(S, C).", facts={
|
|
337
|
+
"depends": [("app", "lib"), ("lib", "core")],
|
|
338
|
+
"service": ["app"],
|
|
339
|
+
"vulnerable": [("core", "cve_2026_0001")],
|
|
340
|
+
})
|
|
341
|
+
checked.violations() # [(constraint, [{'S': 'app', 'C': 'cve_2026_0001'}])]
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
For agents, `skills/tiny-datalog/SKILL.md` is an Agent Skill that
|
|
345
|
+
teaches a coding agent the language and the habits (explain before
|
|
346
|
+
trusting, state properties as constraints); copy it into your agent's
|
|
347
|
+
skills directory.
|
|
348
|
+
|
|
320
349
|
The command-line interface installs too, as `tiny-datalog` (and
|
|
321
350
|
`tiny-datalog-semiring`, `-tabling`, `-incremental`, `-subsumption`,
|
|
322
351
|
`-containment`, `-defeasible`, `-prolog` for the other engines and the
|
|
@@ -334,11 +363,12 @@ installed package; clone the repository for that.
|
|
|
334
363
|
```
|
|
335
364
|
tiny_datalog/ the code you read, in three tiers:
|
|
336
365
|
core.py the common core — the language every module shares:
|
|
337
|
-
AST, parser, safety checks,
|
|
338
|
-
formatting, query helpers
|
|
366
|
+
AST, parser, safety checks, comparisons, stratification,
|
|
367
|
+
matching, formatting, query helpers, warnings
|
|
339
368
|
engines — four strategies, one answer (engines.py lists them):
|
|
340
369
|
datalog.py the base engine: semi-naive and naive bottom-up
|
|
341
|
-
evaluation, aggregation,
|
|
370
|
+
evaluation, aggregation, integrity constraints,
|
|
371
|
+
--explain / why-not, --assume, the CLI
|
|
342
372
|
magic.py the magic-sets rewriting (a program-to-program pass)
|
|
343
373
|
tabling.py tabled top-down evaluation (iterative QSQR)
|
|
344
374
|
engines.py the registry and the interface the four share
|
|
@@ -351,18 +381,21 @@ tiny_datalog/ the code you read, in three tiers:
|
|
|
351
381
|
subsumption.py KL-ONE-style EL classifier, compiled to Datalog
|
|
352
382
|
containment.py query containment and minimisation by homomorphism
|
|
353
383
|
defeasible.py defeasible logic: exceptions, priorities, defeaters
|
|
384
|
+
chase.py existential rules: the chase, labelled nulls, weak
|
|
385
|
+
acyclicity
|
|
354
386
|
*.py three-line launchers, so `python3 datalog.py ...` works
|
|
355
387
|
straight from a checkout with nothing installed
|
|
356
|
-
programs/ teaching programs,
|
|
357
|
-
|
|
358
|
-
lessons/ getting started, glossary, and lessons 0–
|
|
388
|
+
programs/ teaching programs, named for what they model; each
|
|
389
|
+
lesson says which ones it runs
|
|
390
|
+
lessons/ getting started, glossary, and lessons 0–24
|
|
359
391
|
exercises/ worked answers, verified by the test suite
|
|
360
392
|
cases/ golden test cases — add one without writing Python
|
|
393
|
+
skills/ an Agent Skill that teaches coding agents to use the engine
|
|
361
394
|
conformance/ the external datalog-conformance corpus (Soufflé, Nemo,
|
|
362
395
|
Crepe, SPINdle), run against every evaluation strategy
|
|
363
396
|
benchmarks/ scaled input generators (chain/tree/clique/grid, an EL
|
|
364
397
|
ontology, and the N-queens puzzle)
|
|
365
|
-
tests.py
|
|
398
|
+
tests.py 362 tests: every shipped program and exercise answer is
|
|
366
399
|
executed, a conformance suite runs every query through
|
|
367
400
|
every engine that handles it, and a seeded fuzzer checks
|
|
368
401
|
the same property on random programs
|
|
@@ -379,7 +412,7 @@ This project started as an attempt at a tiny implementation of
|
|
|
379
412
|
Datalog, small enough to read in an afternoon. It grew with the
|
|
380
413
|
course. Each lesson that taught a new technique — magic sets, stable models,
|
|
381
414
|
semirings, incremental maintenance, tabling, subsumption, containment,
|
|
382
|
-
defeasible logic — brought a module to run it, and the repository is
|
|
415
|
+
defeasible logic, the chase — brought a module to run it, and the repository is
|
|
383
416
|
now several thousand lines. The core idea stayed small, and the code
|
|
384
417
|
is laid out so you can still read just that: the common core and the
|
|
385
418
|
base engine, below, are the original tiny Datalog. Everything else is
|
|
@@ -389,21 +422,21 @@ Measured in lines, comments, docstrings and blank lines included:
|
|
|
389
422
|
|
|
390
423
|
| Tier | Lines |
|
|
391
424
|
|---|---|
|
|
392
|
-
| the common core (`core.py`: the language, evaluating nothing) |
|
|
393
|
-
| the base engine's evaluator (`datalog.py` up to its CLI section: the module docstring, the import list that re-exports the core, `Program`, `Engine`, aggregation folding, `run_program`) |
|
|
394
|
-
| `--explain`, why-not, printing and the CLI (the rest of `datalog.py`) |
|
|
395
|
-
| the other pluggable engines: magic sets (`magic.py`) and tabling (`tabling.py`), plus the `engines.py` registry (naive evaluation is a flag on the base engine) |
|
|
396
|
-
| the
|
|
425
|
+
| the common core (`core.py`: the language, evaluating nothing; about 270 of these lines arrived with comparisons, constraints, value checks and the warnings) | 1,056 |
|
|
426
|
+
| the base engine's evaluator (`datalog.py` up to its CLI section: the module docstring, the import list that re-exports the core, `Program`, `Engine`, aggregation folding, `run_program`) | 423 |
|
|
427
|
+
| `--explain`, why-not, constraint reports, `--assume`, printing and the CLI (the rest of `datalog.py`) | 621 |
|
|
428
|
+
| the other pluggable engines: magic sets (`magic.py`) and tabling (`tabling.py`), plus the `engines.py` registry (naive evaluation is a flag on the base engine) | 578 |
|
|
429
|
+
| the eight extensions | 2,860 |
|
|
397
430
|
|
|
398
431
|
So the smallest complete Datalog system here — parse, check, stratify,
|
|
399
|
-
evaluate semi-naively — is the core plus the evaluator, about 1,
|
|
400
|
-
lines. All of it is
|
|
432
|
+
evaluate semi-naively — is the core plus the evaluator, about 1,500
|
|
433
|
+
lines. All of it is 5.5k lines of toolkit (every module but the
|
|
401
434
|
re-export list in `__init__.py`), roughly a quarter of it commentary,
|
|
402
|
-
and 3.
|
|
435
|
+
and 3.9k of tests.
|
|
403
436
|
|
|
404
437
|
"Tiny" is a claim about that core and evaluator, and about each module
|
|
405
|
-
built on them singly: none of the
|
|
406
|
-
`engines.py` and the
|
|
438
|
+
built on them singly: none of the eleven (`magic.py`, `tabling.py`,
|
|
439
|
+
`engines.py` and the eight extensions) exceeds 500 lines, which a test asserts. It is not a
|
|
407
440
|
claim about the repository, which is a dozen modules because it
|
|
408
441
|
teaches a dozen things.
|
|
409
442
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "tiny-datalog"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.6.0"
|
|
8
8
|
description = "A Datalog engine whose core you can read in an afternoon, and a course built on it"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -52,6 +52,7 @@ tiny-datalog-incremental = "tiny_datalog.incremental:main"
|
|
|
52
52
|
tiny-datalog-subsumption = "tiny_datalog.subsumption:main"
|
|
53
53
|
tiny-datalog-containment = "tiny_datalog.containment:main"
|
|
54
54
|
tiny-datalog-defeasible = "tiny_datalog.defeasible:main"
|
|
55
|
+
tiny-datalog-chase = "tiny_datalog.chase:main"
|
|
55
56
|
|
|
56
57
|
[tool.setuptools.packages.find]
|
|
57
58
|
include = ["tiny_datalog*"]
|
|
@@ -16,7 +16,8 @@ question of a program: `semantics` (stable and well-founded models),
|
|
|
16
16
|
`semiring` (provenance-weighted evaluation), `incremental` (maintenance
|
|
17
17
|
under updates), `subsumption` (KL-ONE style classification),
|
|
18
18
|
`containment` (query containment), `defeasible` (rules with exceptions
|
|
19
|
-
and priorities),
|
|
19
|
+
and priorities), `chase` (existential rules and labelled nulls), and
|
|
20
|
+
`prolog` (a Prolog reader for the same syntax).
|
|
20
21
|
Import those by name: `from tiny_datalog import semiring`.
|
|
21
22
|
"""
|
|
22
23
|
|
|
@@ -35,7 +36,7 @@ from tiny_datalog.datalog import (
|
|
|
35
36
|
format_atom, format_fact,
|
|
36
37
|
)
|
|
37
38
|
|
|
38
|
-
__version__ = "0.
|
|
39
|
+
__version__ = "0.6.0"
|
|
39
40
|
|
|
40
41
|
__all__ = [
|
|
41
42
|
"Var", "Const", "Struct", "Atom", "Literal", "Rule",
|