relations: Phase 3 path explanation + distance + mixed-kind reachability (explain.sx, reach_any) + 24 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 53s

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-07 12:06:04 +00:00
parent 7a1696490c
commit ffe3ec25ac
7 changed files with 331 additions and 10 deletions

View File

@@ -8,6 +8,9 @@
;; reach(K,X,Y) :- rel(X,Y,K). ; one hop
;; reach(K,X,Y) :- rel(X,Z,K), reach(K,Z,Y). ; transitive
;;
;; `reach_any` is the kind-agnostic closure (any edge, any kind) used for
;; mixed-kind reachability — distinct from single-kind `reach`.
;;
;; rnode collects the nodes touched by a kind; root/leaf are those with no
;; incoming / no outgoing edge (stratified negation over has_parent/has_child).
;; Cycles are ordinary data: `reach(K,X,X)` simply holds for nodes on a cycle —
@@ -18,6 +21,8 @@
(quote
((reach K X Y <- (rel X Y K))
(reach K X Y <- (rel X Z K) (reach K Z Y))
(reach_any X Y <- (rel X Y K))
(reach_any X Y <- (rel X Z K) (reach_any Z Y))
(rnode K X <- (rel X Y K))
(rnode K Y <- (rel X Y K))
(has_parent K Y <- (rel X Y K))
@@ -55,6 +60,22 @@
(db a b kind)
(> (len (dl-query db (list (quote reach) kind a b))) 0)))
;; Mixed-kind: descendants reachable from node over edges of ANY kind.
(define
relations-descendants-any
(fn
(db node)
(relations-pluck
(dl-query db (list (quote reach_any) node (quote Y)))
:Y)))
;; Mixed-kind: is b reachable from a over edges of ANY kind?
(define
relations-reachable-any?
(fn
(db a b)
(> (len (dl-query db (list (quote reach_any) a b))) 0)))
;; Roots: nodes touched by kind with no incoming edge.
(define
relations-roots