tiny-datalog 0.5.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.
Files changed (24) hide show
  1. {tiny_datalog-0.5.0/tiny_datalog.egg-info → tiny_datalog-0.6.0}/PKG-INFO +53 -26
  2. {tiny_datalog-0.5.0 → tiny_datalog-0.6.0}/README.md +52 -25
  3. {tiny_datalog-0.5.0 → tiny_datalog-0.6.0}/pyproject.toml +1 -1
  4. {tiny_datalog-0.5.0 → tiny_datalog-0.6.0}/tiny_datalog/__init__.py +1 -1
  5. {tiny_datalog-0.5.0 → tiny_datalog-0.6.0}/tiny_datalog/chase.py +5 -1
  6. {tiny_datalog-0.5.0 → tiny_datalog-0.6.0}/tiny_datalog/containment.py +11 -1
  7. {tiny_datalog-0.5.0 → tiny_datalog-0.6.0}/tiny_datalog/core.py +288 -18
  8. {tiny_datalog-0.5.0 → tiny_datalog-0.6.0}/tiny_datalog/datalog.py +131 -20
  9. {tiny_datalog-0.5.0 → tiny_datalog-0.6.0}/tiny_datalog/engines.py +7 -2
  10. {tiny_datalog-0.5.0 → tiny_datalog-0.6.0}/tiny_datalog/incremental.py +18 -7
  11. {tiny_datalog-0.5.0 → tiny_datalog-0.6.0}/tiny_datalog/magic.py +19 -1
  12. {tiny_datalog-0.5.0 → tiny_datalog-0.6.0}/tiny_datalog/prolog.py +4 -1
  13. {tiny_datalog-0.5.0 → tiny_datalog-0.6.0}/tiny_datalog/semantics.py +6 -3
  14. {tiny_datalog-0.5.0 → tiny_datalog-0.6.0}/tiny_datalog/semiring.py +10 -3
  15. {tiny_datalog-0.5.0 → tiny_datalog-0.6.0}/tiny_datalog/tabling.py +9 -4
  16. {tiny_datalog-0.5.0 → tiny_datalog-0.6.0/tiny_datalog.egg-info}/PKG-INFO +53 -26
  17. {tiny_datalog-0.5.0 → tiny_datalog-0.6.0}/LICENSE +0 -0
  18. {tiny_datalog-0.5.0 → tiny_datalog-0.6.0}/setup.cfg +0 -0
  19. {tiny_datalog-0.5.0 → tiny_datalog-0.6.0}/tiny_datalog/defeasible.py +0 -0
  20. {tiny_datalog-0.5.0 → tiny_datalog-0.6.0}/tiny_datalog/subsumption.py +0 -0
  21. {tiny_datalog-0.5.0 → tiny_datalog-0.6.0}/tiny_datalog.egg-info/SOURCES.txt +0 -0
  22. {tiny_datalog-0.5.0 → tiny_datalog-0.6.0}/tiny_datalog.egg-info/dependency_links.txt +0 -0
  23. {tiny_datalog-0.5.0 → tiny_datalog-0.6.0}/tiny_datalog.egg-info/entry_points.txt +0 -0
  24. {tiny_datalog-0.5.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.5.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 # 326 tests, ~12s
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, and `--explain` produces the
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 — 23
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
@@ -250,10 +252,12 @@ 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
254
  a lesson on authoring rules that survive review, one on a logic
253
- built for rules with exceptions, and three where the engine goes to
255
+ built for rules with exceptions, and five where the engine goes to
254
256
  work: [authorization](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/20-authorization.md),
255
257
  [program analysis](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/21-program-analysis.md),
256
- and [knowledge graphs and the chase](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/22-knowledge-graphs.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).
257
261
  And it is built to be
258
262
  inherited: `git clone`, no dependencies, no hosted anything, and every
259
263
  quoted transcript re-verified by CI — the exercises cannot rot. (For where each
@@ -301,10 +305,9 @@ see [pyDatalog](https://pypi.org/project/pyDatalog/).
301
305
  Deliberate omissions, because saying why teaches more than lacking them
302
306
  quietly:
303
307
 
304
- - **Arithmetic and comparisons.** A built-in isn't a relation you can
305
- enumerate, so it must be *evaluated* the moment its operands bind —
306
- which entangles correctness with join order and forces terms to
307
- 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
308
311
  story, including what to do instead.
309
312
  - **Indexes and join planning.** Every join is a nested loop so the
310
313
  algorithms stay one-screen readable. It is also why the magic-sets
@@ -317,7 +320,10 @@ quietly:
317
320
 
318
321
  Aggregation used to be on this list;
319
322
  [lesson 13](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/13-aggregation.md) is what promoting an omission
320
- 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.
321
327
 
322
328
  ## Using it in your own project
323
329
 
@@ -354,6 +360,25 @@ engine = run_program(rules, facts={
354
360
  engine.query("exposed(S, C)") # [{'S': 'app', 'C': 'cve_2026_0001'}]
355
361
  ```
356
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
+
357
382
  The command-line interface installs too, as `tiny-datalog` (and
358
383
  `tiny-datalog-semiring`, `-tabling`, `-incremental`, `-subsumption`,
359
384
  `-containment`, `-defeasible`, `-prolog` for the other engines and the
@@ -371,11 +396,12 @@ installed package; clone the repository for that.
371
396
  ```
372
397
  tiny_datalog/ the code you read, in three tiers:
373
398
  core.py the common core — the language every module shares:
374
- AST, parser, safety checks, stratification, matching,
375
- formatting, query helpers
399
+ AST, parser, safety checks, comparisons, stratification,
400
+ matching, formatting, query helpers, warnings
376
401
  engines — four strategies, one answer (engines.py lists them):
377
402
  datalog.py the base engine: semi-naive and naive bottom-up
378
- evaluation, aggregation, --explain / why-not, the CLI
403
+ evaluation, aggregation, integrity constraints,
404
+ --explain / why-not, --assume, the CLI
379
405
  magic.py the magic-sets rewriting (a program-to-program pass)
380
406
  tabling.py tabled top-down evaluation (iterative QSQR)
381
407
  engines.py the registry and the interface the four share
@@ -392,16 +418,17 @@ tiny_datalog/ the code you read, in three tiers:
392
418
  acyclicity
393
419
  *.py three-line launchers, so `python3 datalog.py ...` works
394
420
  straight from a checkout with nothing installed
395
- programs/ teaching programs, numbered by the lesson that uses
396
- them (00-* are the README's examples)
397
- lessons/ getting started, glossary, and lessons 0–22
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
398
424
  exercises/ worked answers, verified by the test suite
399
425
  cases/ golden test cases — add one without writing Python
426
+ skills/ an Agent Skill that teaches coding agents to use the engine
400
427
  conformance/ the external datalog-conformance corpus (Soufflé, Nemo,
401
428
  Crepe, SPINdle), run against every evaluation strategy
402
429
  benchmarks/ scaled input generators (chain/tree/clique/grid, an EL
403
430
  ontology, and the N-queens puzzle)
404
- tests.py 326 tests: every shipped program and exercise answer is
431
+ tests.py 362 tests: every shipped program and exercise answer is
405
432
  executed, a conformance suite runs every query through
406
433
  every engine that handles it, and a seeded fuzzer checks
407
434
  the same property on random programs
@@ -428,17 +455,17 @@ Measured in lines, comments, docstrings and blank lines included:
428
455
 
429
456
  | Tier | Lines |
430
457
  |---|---|
431
- | the common core (`core.py`: the language, evaluating nothing) | 785 |
432
- | 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`) | 395 |
433
- | `--explain`, why-not, printing and the CLI (the rest of `datalog.py`) | 538 |
434
- | 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) | 549 |
435
- | the eight extensions | 2,822 |
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 |
436
463
 
437
464
  So the smallest complete Datalog system here — parse, check, stratify,
438
- evaluate semi-naively — is the core plus the evaluator, about 1,200
439
- lines. All of it is 5.1k lines of toolkit (every module but the
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
440
467
  re-export list in `__init__.py`), roughly a quarter of it commentary,
441
- and 3.6k of tests.
468
+ and 3.9k of tests.
442
469
 
443
470
  "Tiny" is a claim about that core and evaluator, and about each module
444
471
  built on them singly: none of the eleven (`magic.py`, `tabling.py`,
@@ -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 # 326 tests, ~12s
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, and `--explain` produces the
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 — 23
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
@@ -217,10 +219,12 @@ 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
221
  a lesson on authoring rules that survive review, one on a logic
220
- built for rules with exceptions, and three where the engine goes to
222
+ built for rules with exceptions, and five where the engine goes to
221
223
  work: [authorization](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/20-authorization.md),
222
224
  [program analysis](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/21-program-analysis.md),
223
- and [knowledge graphs and the chase](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/22-knowledge-graphs.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).
224
228
  And it is built to be
225
229
  inherited: `git clone`, no dependencies, no hosted anything, and every
226
230
  quoted transcript re-verified by CI — the exercises cannot rot. (For where each
@@ -268,10 +272,9 @@ see [pyDatalog](https://pypi.org/project/pyDatalog/).
268
272
  Deliberate omissions, because saying why teaches more than lacking them
269
273
  quietly:
270
274
 
271
- - **Arithmetic and comparisons.** A built-in isn't a relation you can
272
- enumerate, so it must be *evaluated* the moment its operands bind —
273
- which entangles correctness with join order and forces terms to
274
- 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
275
278
  story, including what to do instead.
276
279
  - **Indexes and join planning.** Every join is a nested loop so the
277
280
  algorithms stay one-screen readable. It is also why the magic-sets
@@ -284,7 +287,10 @@ quietly:
284
287
 
285
288
  Aggregation used to be on this list;
286
289
  [lesson 13](https://github.com/andrewgoodchild/tiny-datalog/blob/main/lessons/13-aggregation.md) is what promoting an omission
287
- 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.
288
294
 
289
295
  ## Using it in your own project
290
296
 
@@ -321,6 +327,25 @@ engine = run_program(rules, facts={
321
327
  engine.query("exposed(S, C)") # [{'S': 'app', 'C': 'cve_2026_0001'}]
322
328
  ```
323
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
+
324
349
  The command-line interface installs too, as `tiny-datalog` (and
325
350
  `tiny-datalog-semiring`, `-tabling`, `-incremental`, `-subsumption`,
326
351
  `-containment`, `-defeasible`, `-prolog` for the other engines and the
@@ -338,11 +363,12 @@ installed package; clone the repository for that.
338
363
  ```
339
364
  tiny_datalog/ the code you read, in three tiers:
340
365
  core.py the common core — the language every module shares:
341
- AST, parser, safety checks, stratification, matching,
342
- formatting, query helpers
366
+ AST, parser, safety checks, comparisons, stratification,
367
+ matching, formatting, query helpers, warnings
343
368
  engines — four strategies, one answer (engines.py lists them):
344
369
  datalog.py the base engine: semi-naive and naive bottom-up
345
- evaluation, aggregation, --explain / why-not, the CLI
370
+ evaluation, aggregation, integrity constraints,
371
+ --explain / why-not, --assume, the CLI
346
372
  magic.py the magic-sets rewriting (a program-to-program pass)
347
373
  tabling.py tabled top-down evaluation (iterative QSQR)
348
374
  engines.py the registry and the interface the four share
@@ -359,16 +385,17 @@ tiny_datalog/ the code you read, in three tiers:
359
385
  acyclicity
360
386
  *.py three-line launchers, so `python3 datalog.py ...` works
361
387
  straight from a checkout with nothing installed
362
- programs/ teaching programs, numbered by the lesson that uses
363
- them (00-* are the README's examples)
364
- lessons/ getting started, glossary, and lessons 0–22
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
365
391
  exercises/ worked answers, verified by the test suite
366
392
  cases/ golden test cases — add one without writing Python
393
+ skills/ an Agent Skill that teaches coding agents to use the engine
367
394
  conformance/ the external datalog-conformance corpus (Soufflé, Nemo,
368
395
  Crepe, SPINdle), run against every evaluation strategy
369
396
  benchmarks/ scaled input generators (chain/tree/clique/grid, an EL
370
397
  ontology, and the N-queens puzzle)
371
- tests.py 326 tests: every shipped program and exercise answer is
398
+ tests.py 362 tests: every shipped program and exercise answer is
372
399
  executed, a conformance suite runs every query through
373
400
  every engine that handles it, and a seeded fuzzer checks
374
401
  the same property on random programs
@@ -395,17 +422,17 @@ Measured in lines, comments, docstrings and blank lines included:
395
422
 
396
423
  | Tier | Lines |
397
424
  |---|---|
398
- | the common core (`core.py`: the language, evaluating nothing) | 785 |
399
- | 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`) | 395 |
400
- | `--explain`, why-not, printing and the CLI (the rest of `datalog.py`) | 538 |
401
- | 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) | 549 |
402
- | the eight extensions | 2,822 |
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 |
403
430
 
404
431
  So the smallest complete Datalog system here — parse, check, stratify,
405
- evaluate semi-naively — is the core plus the evaluator, about 1,200
406
- lines. All of it is 5.1k lines of toolkit (every module but the
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
407
434
  re-export list in `__init__.py`), roughly a quarter of it commentary,
408
- and 3.6k of tests.
435
+ and 3.9k of tests.
409
436
 
410
437
  "Tiny" is a claim about that core and evaluator, and about each module
411
438
  built on them singly: none of the eleven (`magic.py`, `tabling.py`,
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "tiny-datalog"
7
- version = "0.5.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"
@@ -36,7 +36,7 @@ from tiny_datalog.datalog import (
36
36
  format_atom, format_fact,
37
37
  )
38
38
 
39
- __version__ = "0.5.0"
39
+ __version__ = "0.6.0"
40
40
 
41
41
  __all__ = [
42
42
  "Var", "Const", "Struct", "Atom", "Literal", "Rule",
@@ -73,7 +73,8 @@ from dataclasses import dataclass
73
73
 
74
74
  from tiny_datalog.core import (
75
75
  _format_value, aggregate_of, Atom, cli, Const, DatalogError, Literal,
76
- match, parse, parse_query_atom, read_program, Rule, Var, validate)
76
+ match, parse, parse_query_atom, read_program, refuse_extras, Rule, Var,
77
+ validate)
77
78
  from tiny_datalog.datalog import Engine, Program
78
79
 
79
80
 
@@ -133,6 +134,9 @@ def check(clauses):
133
134
  The core's checks apply to a *skeleton* of each rule in which the
134
135
  existential variables are replaced by a placeholder constant: that
135
136
  is exactly "safe, except for the variables we mean to invent"."""
137
+ # an invented value has no order to compare, and denial
138
+ # constraints over nulls are a theory of their own
139
+ refuse_extras(clauses, "the chase")
136
140
  for c in clauses:
137
141
  if c.retract:
138
142
  raise DatalogError("a retraction is an update, not a statement:"
@@ -42,7 +42,7 @@ import sys
42
42
 
43
43
  from tiny_datalog.core import (
44
44
  aggregate_of, cli, Const, DatalogError, parse, read_program, validate,
45
- Var)
45
+ Var, is_comparison)
46
46
 
47
47
 
48
48
  def _extend(mapping, source_args, target_args):
@@ -93,6 +93,12 @@ def _bodies(rule):
93
93
  raise DatalogError(
94
94
  "containment by homomorphism is a conjunctive-query "
95
95
  "result; negation needs different theory: %s" % rule)
96
+ if is_comparison(lit):
97
+ # Klug (1988): with comparisons one homomorphism no longer
98
+ # suffices -- every ordering of the variables must be checked
99
+ raise DatalogError(
100
+ "containment by homomorphism is a conjunctive-query "
101
+ "result; comparisons need different theory: %s" % rule)
96
102
  if aggregate_of(rule.head):
97
103
  # sum/count see duplicates; Chandra–Merlin is about sets.
98
104
  raise DatalogError(
@@ -198,6 +204,10 @@ def main(argv=None):
198
204
  print("%s\n (skipped: negation is outside the theory)"
199
205
  % rule)
200
206
  continue
207
+ if any(is_comparison(lit) for lit in rule.body):
208
+ print("%s\n (skipped: comparisons are outside the theory)"
209
+ % rule)
210
+ continue
201
211
  if aggregate_of(rule.head):
202
212
  print("%s\n (skipped: aggregation is outside the theory)"
203
213
  % rule)