datalog: aggregation count/sum/min/max (Phase 8, 134/134)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 50s

New lib/datalog/aggregates.sx: (count R V Goal), (sum R V Goal),
(min R V Goal), (max R V Goal). dl-eval-aggregate runs
dl-find-bindings on the goal under the outer subst, collects
distinct values of V, applies the operator, binds R. Empty input:
count/sum return 0; min/max produce no binding (rule fails).

Group-by emerges naturally from outer-subst substitution into the
goal — `popular(P) :- post(P), count(N, U, liked(U, P)), >=(N, 3).`
counts per-post.

Stratifier extended: dl-aggregate-dep-edge contributes a
negation-like edge so the aggregate's goal relation is fully
derived before the aggregate fires (non-monotonicity respected).
Safety relaxed for aggregates: goal-internal vars are existentials,
only the result var becomes bound.
This commit is contained in:
2026-05-08 08:28:45 +00:00
parent caec05eb27
commit 6d04cf7bf2
9 changed files with 447 additions and 27 deletions

View File

@@ -1,8 +1,8 @@
{
"lang": "datalog",
"total_passed": 124,
"total_passed": 134,
"total_failed": 0,
"total": 124,
"total": 134,
"suites": [
{"name":"tokenize","passed":26,"failed":0,"total":26},
{"name":"parse","passed":18,"failed":0,"total":18},
@@ -10,7 +10,8 @@
{"name":"eval","passed":15,"failed":0,"total":15},
{"name":"builtins","passed":19,"failed":0,"total":19},
{"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":10,"failed":0,"total":10}
],
"generated": "2026-05-08T08:20:41+00:00"
"generated": "2026-05-08T08:28:29+00:00"
}