datalog: arith / by zero raises instead of returning inf
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 47s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 47s
`is(R, /(X, 0))` was silently producing IEEE infinity:
(dl-eval "p(10). q(R) :- p(X), is(R, /(X, 0))." "?- q(R).")
=> ({:R inf})
That value then flowed through comparisons (anything < inf, anything
> inf) and aggregations (sum of inf, max of inf) producing nonsense
results downstream. `dl-eval-arith` now checks the divisor before
the host `/` and raises "division by zero in <expr>" — surfacing
the bug at its source rather than letting infinity propagate.
1 new test; conformance 264/264.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -72,7 +72,13 @@
|
|||||||
((= rel "+") (+ a b))
|
((= rel "+") (+ a b))
|
||||||
((= rel "-") (- a b))
|
((= rel "-") (- a b))
|
||||||
((= rel "*") (* a b))
|
((= rel "*") (* a b))
|
||||||
((= rel "/") (/ a b))
|
((= rel "/")
|
||||||
|
(cond
|
||||||
|
((= b 0)
|
||||||
|
(error
|
||||||
|
(str "datalog arith: division by zero in "
|
||||||
|
w)))
|
||||||
|
(else (/ a b))))
|
||||||
(else (error (str "datalog arith: unknown op " rel)))))))))
|
(else (error (str "datalog arith: unknown op " rel)))))))))
|
||||||
(else (error (str "datalog arith: not a number — " w)))))))
|
(else (error (str "datalog arith: not a number — " w)))))))
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
{
|
{
|
||||||
"lang": "datalog",
|
"lang": "datalog",
|
||||||
"total_passed": 263,
|
"total_passed": 264,
|
||||||
"total_failed": 0,
|
"total_failed": 0,
|
||||||
"total": 263,
|
"total": 264,
|
||||||
"suites": [
|
"suites": [
|
||||||
{"name":"tokenize","passed":30,"failed":0,"total":30},
|
{"name":"tokenize","passed":30,"failed":0,"total":30},
|
||||||
{"name":"parse","passed":22,"failed":0,"total":22},
|
{"name":"parse","passed":22,"failed":0,"total":22},
|
||||||
{"name":"unify","passed":29,"failed":0,"total":29},
|
{"name":"unify","passed":29,"failed":0,"total":29},
|
||||||
{"name":"eval","passed":39,"failed":0,"total":39},
|
{"name":"eval","passed":39,"failed":0,"total":39},
|
||||||
{"name":"builtins","passed":23,"failed":0,"total":23},
|
{"name":"builtins","passed":24,"failed":0,"total":24},
|
||||||
{"name":"semi_naive","passed":8,"failed":0,"total":8},
|
{"name":"semi_naive","passed":8,"failed":0,"total":8},
|
||||||
{"name":"negation","passed":10,"failed":0,"total":10},
|
{"name":"negation","passed":10,"failed":0,"total":10},
|
||||||
{"name":"aggregates","passed":23,"failed":0,"total":23},
|
{"name":"aggregates","passed":23,"failed":0,"total":23},
|
||||||
@@ -16,5 +16,5 @@
|
|||||||
{"name":"magic","passed":36,"failed":0,"total":36},
|
{"name":"magic","passed":36,"failed":0,"total":36},
|
||||||
{"name":"demo","passed":21,"failed":0,"total":21}
|
{"name":"demo","passed":21,"failed":0,"total":21}
|
||||||
],
|
],
|
||||||
"generated": "2026-05-11T07:56:45+00:00"
|
"generated": "2026-05-11T07:59:10+00:00"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# datalog scoreboard
|
# datalog scoreboard
|
||||||
|
|
||||||
**263 / 263 passing** (0 failure(s)).
|
**264 / 264 passing** (0 failure(s)).
|
||||||
|
|
||||||
| Suite | Passed | Total | Status |
|
| Suite | Passed | Total | Status |
|
||||||
|-------|--------|-------|--------|
|
|-------|--------|-------|--------|
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
| parse | 22 | 22 | ok |
|
| parse | 22 | 22 | ok |
|
||||||
| unify | 29 | 29 | ok |
|
| unify | 29 | 29 | ok |
|
||||||
| eval | 39 | 39 | ok |
|
| eval | 39 | 39 | ok |
|
||||||
| builtins | 23 | 23 | ok |
|
| builtins | 24 | 24 | ok |
|
||||||
| semi_naive | 8 | 8 | ok |
|
| semi_naive | 8 | 8 | ok |
|
||||||
| negation | 10 | 10 | ok |
|
| negation | 10 | 10 | ok |
|
||||||
| aggregates | 23 | 23 | ok |
|
| aggregates | 23 | 23 | ok |
|
||||||
|
|||||||
@@ -239,7 +239,17 @@
|
|||||||
"safe — = binds head var"
|
"safe — = binds head var"
|
||||||
(dl-bt-throws?
|
(dl-bt-throws?
|
||||||
(fn () (dl-program "p(a). p(b). x(Y) :- p(X), =(Y, X).")))
|
(fn () (dl-program "p(a). p(b). x(Y) :- p(X), =(Y, X).")))
|
||||||
false))))
|
false)
|
||||||
|
|
||||||
|
;; Division by zero raises with a clear error. Without this guard
|
||||||
|
;; SX's `/` returned IEEE infinity, which then silently flowed
|
||||||
|
;; through comparisons and aggregations.
|
||||||
|
(dl-bt-test!
|
||||||
|
"is — division by zero raises"
|
||||||
|
(dl-bt-throws?
|
||||||
|
(fn ()
|
||||||
|
(dl-eval "p(10). q(R) :- p(X), is(R, /(X, 0))." "?- q(R).")))
|
||||||
|
true))))
|
||||||
|
|
||||||
(define
|
(define
|
||||||
dl-builtins-tests-run!
|
dl-builtins-tests-run!
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ for rose-ash data (e.g. federation graph, content relationships).
|
|||||||
|
|
||||||
## Status (rolling)
|
## Status (rolling)
|
||||||
|
|
||||||
`bash lib/datalog/conformance.sh` → **263/263 across 11 suites**
|
`bash lib/datalog/conformance.sh` → **264/264 across 11 suites**
|
||||||
(tokenize, parse, unify, eval, builtins, semi_naive, negation, aggregates,
|
(tokenize, parse, unify, eval, builtins, semi_naive, negation, aggregates,
|
||||||
api, magic, demo). Source is ~3100 LOC, tests ~2900 LOC, public API
|
api, magic, demo). Source is ~3100 LOC, tests ~2900 LOC, public API
|
||||||
documented in `lib/datalog/datalog.sx`.
|
documented in `lib/datalog/datalog.sx`.
|
||||||
@@ -320,6 +320,12 @@ large graphs.
|
|||||||
|
|
||||||
_Newest first._
|
_Newest first._
|
||||||
|
|
||||||
|
- 2026-05-11 — Division by zero in `is` silently produced IEEE
|
||||||
|
infinity instead of raising. `is(R, /(X, 0))` returned `R = inf`,
|
||||||
|
which then flowed through comparisons and aggregations to produce
|
||||||
|
nonsense results. `dl-eval-arith` now raises with a clear
|
||||||
|
"division by zero in <expr>" message. 1 new test; 264/264.
|
||||||
|
|
||||||
- 2026-05-11 — Aggregate variable validation: `count(N, Y, p(X))`
|
- 2026-05-11 — Aggregate variable validation: `count(N, Y, p(X))`
|
||||||
silently returned `N = 1` because `Y` was never bound in `p(X)` —
|
silently returned `N = 1` because `Y` was never bound in `p(X)` —
|
||||||
every match contributed the same unbound symbol, which dl-val-member?
|
every match contributed the same unbound symbol, which dl-val-member?
|
||||||
|
|||||||
Reference in New Issue
Block a user