;; lib/minikanren/tests/pythag.sx — Pythagorean triple search. ;; ;; Uses ino + intarith goals to find triples (a, b, c) with ;; a, b, c ∈ [1..N], a ≤ b, a² + b² = c². With intarith escapes ;; the search runs at host-arithmetic speed. (define digits-1-10 (list 1 2 3 4 5 6 7 8 9 10)) (mk-test "pythag-triples-1-to-10" (let ((triples (run* q (fresh (a b c a-sq b-sq sum c-sq) (ino a digits-1-10) (ino b digits-1-10) (ino c digits-1-10) (lteo-i a b) (*o-i a a a-sq) (*o-i b b b-sq) (*o-i c c c-sq) (pluso-i a-sq b-sq sum) (== sum c-sq) (== q (list a b c)))))) (and (= (len triples) 2) (and (some (fn (t) (= t (list 3 4 5))) triples) (some (fn (t) (= t (list 6 8 10))) triples)))) true) (mk-tests-run!)