% From the book % PROLOG PROGRAMMING IN DEPTH % by Michael A. Covington, Donald Nute, and Andre Vellino % (Prentice Hall, 1997). % Copyright 1997 Prentice-Hall, Inc. % For educational use only % File REALSQR1.PL % From Chapter 2 % close_enough/2 and early version of real_square_root/2 close_enough(X,X) :- !. close_enough(X,Y) :- X < Y, Diff is Y-X, Diff < 0.0001. close_enough(X,Y) :- Y < X, close_enough(Y,X). real_square_root(X,nonexistent) :- X < 0.0. % Clause 1 real_square_root(X,Y) :- X >= 0.0, % Clause 2 R is sqrt(X), close_enough(R,Y). real_square_root(X,Y) :- X > 0.0, % Clause 3 R is -sqrt(X), close_enough(R,Y).