From 787d2daa8ad46ce4cf3e3575e132edb76071fc99 Mon Sep 17 00:00:00 2001 From: rslopes Date: Thu, 8 Sep 2005 22:53:33 +0000 Subject: [PATCH] updated with the queens example... git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1388 b08c6af1-5177-4d33-ba66-4b1c6b8b522a --- README.EAM.html | 52 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/README.EAM.html b/README.EAM.html index 3d73ca490..b710d1837 100644 --- a/README.EAM.html +++ b/README.EAM.html @@ -75,7 +75,7 @@ no ?- --------------------------------------------------------------------------- -A bigger example: +A first example: You can try out the next example, the well-known benchmark scanner.pl that behaves badly in standard Prolog systems. @@ -216,8 +216,58 @@ llength([A|R],N):- llength(R,M), N is M+1. +--------------------------------------------------------------------------- +Another example: +The famours queens... +Try to evaluate in normal Prolog que query: +?- queens([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],X). +Now quit YAP and enable eam before loading the queens program +Here is the code for you to try it: +demo1:- queens([1,2,3,4,5,6,7,8,9],L), write(L), nl, fail. +demo2:- queens([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],L), write(L), nl. + +queens(L,C):- + perm(L,P), + pair(L,P,C), + safe([],C). + +perm([],[]). +perm(Xs,[Z|Zs]):- + select(Z,Xs,Ys), + perm(Ys,Zs). + +select(X,[X|Xs],Xs). +select(X,[Y|Ys],[Y|Zs]):- + select(X,Ys,Zs). + +pair([],[],[]). +pair([X|Y],[U|V],[p(X,U)|W]):- + pair(Y,V,W). + +safe(X,[]). +safe(X,[Q|R]):- + test(X,Q), + safe([Q|X],R). + +test([],X). +test([p(C1,R1)|S],p(C2,R2)):- + test(S,p(C2,R2)), + nd(p(C1,R1),p(C2,R2)). + +nd(p(C1,R1),p(C2,R2)):- + wait_while_var([C1,C2,R1,R2]), + C is C1-C2, + R is R1-R2, + C=\=R, + NR is R2-R1, + C=\=NR. + +Note that on the nd predicate, we have used wait_while_var +to force the EAM to wait while C1, C2, R1, R2 are not bound, +because the operations in this predicate can't be done with +those variables unbound. --------------------------------------------------------------------------- 3. Some notes...