/* Logic programs with Equality in Picat. From Nilsson & Matuszynski: "Logic, Programming and Prolog" Page 227ff (Chapter 13: Logic Programs with Equality") Trying to use Picat's function. This kind of works in some cases. This model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import v3_utils. main => go. go ?=> % This outputs: s(s(s(s(0)))) * factorial2(s(s(s(0)))) println(factorial2($s(s(s(s(0)))))), odd2(factorial2(0)), % ok println(ok), println(factorial2($s(0))), % this don't work odd2(factorial2($s(0))), println(ok2), fail, nl. go => true. % % this don't work! % go2 ?=> proud(robert), println(ok), proud(X), println(X), println(apply(X)), % testing fail, nl. go2 => true. % page 227 factorial2(0) = $s(0). factorial2(s(X)) = $s(X) * factorial2(X). odd2(s(0)). odd2(s(s(X))) :- odd2(X). % % This don't work! % % page 235 proud(father(X)) :- newborn(X). % proud(F) :- F=$father(X),newborn(X). % proud(F) :- newborn(X),F=apply($father(X)). % A little better but wrong! % Using Picat instead % proud(F) ?=> F = $father(X),newborn(X),println([f=F,x=X]). % Using Picat's conditional head, works _little_ better, but not the whole way... % proud(F), newborn(X) ?=> F = apply($father(X)),println([f=F,x=X]). newborn(sally). newborn(bruce). father(sally) = robert. father(bruce) = adam. father(simon) = robert.