Merge loops/minikanren into architecture: full miniKanren-on-SX library
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 57s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 57s
Squash merge of 76 commits from loops/minikanren. Adds lib/minikanren/ — a complete miniKanren-on-SX implementation built on top of lib/guest/match.sx, validating the lib-guest unify-and-match kit as intended. Modules (20 .sx files, ~1700 LOC): unify, stream, goals, fresh, conde, condu, conda, run, relations, peano, intarith, project, nafc, matche, fd, queens, defrel, clpfd, tabling Phases 1–5 fully done (core miniKanren API, all classic relations, matche, conda, project, nafc). Phase 6 — native CLP(FD): domain primitives, fd-in / fd-eq / fd-neq / fd-lt / fd-lte / fd-plus / fd-times / fd-distinct / fd-label, with constraint reactivation iterating to fixed point. N-queens via FD: 4-queens 2 solutions, 5-queens 10 solutions (vs naive timeout past N=4). Phase 7 — naive ground-arg tabling: table-1 / table-2 / table-3. Fibonacci canary: tab-fib(25) = 75025 in seconds, naive fib(25) times out at 60s. Ackermann via table-3: A(3,3) = 61. 71 test files, 644+ tests passing across the suite. Producer/consumer SLG (cyclic patho, mutual recursion) deferred — research-grade work. The lib-guest validation experiment is conclusive: lib/minikanren/ unify.sx adds ~50 lines of local logic (custom cfg, deep walk*, fresh counter) over lib/guest/match.sx's ~100-line kit. The kit earns its keep ~3× by line count.
This commit is contained in:
40
lib/minikanren/tests/path-cycle-free.sx
Normal file
40
lib/minikanren/tests/path-cycle-free.sx
Normal file
@@ -0,0 +1,40 @@
|
||||
;; lib/minikanren/tests/path-cycle-free.sx — cycle-free reachability search.
|
||||
;;
|
||||
;; Threads a "visited" accumulator through the recursion, using nafc +
|
||||
;; membero to prevent revisiting nodes. Demonstrates how to make the
|
||||
;; cyclic-graph divergence problem (see tests/cyclic-graph.sx) tractable
|
||||
;; for graphs with cycles, without invoking Phase-7 tabling.
|
||||
|
||||
(define
|
||||
cf-edges
|
||||
(list (list :a :b) (list :b :a) (list :b :c) (list :c :d) (list :d :a))) ; another cycle
|
||||
|
||||
(define cf-edgeo (fn (from to) (membero (list from to) cf-edges)))
|
||||
|
||||
(define
|
||||
patho-no-cycles
|
||||
(fn
|
||||
(x y visited path)
|
||||
(conde
|
||||
((cf-edgeo x y) (nafc (membero y visited)) (== path (list x y)))
|
||||
((fresh (z mid v-prime) (cf-edgeo x z) (nafc (membero z visited)) (conso z visited v-prime) (patho-no-cycles z y v-prime mid) (conso x mid path))))))
|
||||
|
||||
(define cf-patho (fn (x y path) (patho-no-cycles x y (list x) path)))
|
||||
|
||||
(mk-test
|
||||
"cycle-free-finds-finitely"
|
||||
(let
|
||||
((paths (run* q (cf-patho :a :d q))))
|
||||
(and
|
||||
(>= (len paths) 1)
|
||||
(every? (fn (p) (and (= (first p) :a) (= (last p) :d))) paths)))
|
||||
true)
|
||||
|
||||
(mk-test
|
||||
"cycle-free-direct-edge"
|
||||
(run* q (cf-patho :a :b q))
|
||||
(list (list :a :b)))
|
||||
|
||||
(mk-test "cycle-free-no-self-loop" (run* q (cf-patho :a :a q)) (list))
|
||||
|
||||
(mk-tests-run!)
|
||||
Reference in New Issue
Block a user