1:- module(infomath,[]). 2% :- [pac(infomath)]. 3 4random_point(X, Y):- X is random_float, 5 Y is random_float. 6 7pi(N, Pi):- monte_carlo(N, 0, In), 8 Pi is 4.0* (In / N). 9 10monte_carlo(0, In, In). 11monte_carlo(N, In, In1):- N > 0, 12 N0 is N-1, 13 random_point(X,Y), 14 ( X^2 + Y^2 < 1 15 -> In0 is In+1 16 ; In0 = In 17 ), 18 monte_carlo(N0, In0, In1). 19 20% pi/4 : 1 = X : N. pi = 4*X/N 21 22% ?- infomath:pi(10000000, Pi). 23%@ Pi = 3.1415876 .