1 / 5

Prolog And FOL Exercises

King Saud University College of Computer and Information Sciences Information Technology Department IT327 - Intelligent systems. Prolog And FOL Exercises. Question 1. Write a Prolog Program to find Fibonnaci Number defined as follows:

zahi
Download Presentation

Prolog And FOL Exercises

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. King Saud University College of Computer and Information Sciences Information Technology Department IT327 - Intelligent systems Prolog And FOL Exercises

  2. Question 1 • Write a Prolog Program to find Fibonnaci Number defined as follows: f(1) = 1, f(2) = 1, ∀ n > 2 : f(n) = f(n − 1) + f(n − 2) fibonacci(1,1). fibonacci(2,1). fibonacci(N,F) :- N>2, N1 is N-1, fibonacci(N1,F1), N2 is N-2, fibonacci(N2,F2), F is F1+F2.

  3. Question 2 • Write a Prolog program to find the greatest common divisor using the following algorithm gcd(a,b) = a if a=b gcd(a,b) = gcd(a-b,b) if a>b gcd(a,b) = gcd(a,b-a) if b>a gcd(A,A,A). gcd(A,B,Result) :- (A>B -> (Temp is A-B, gcd(Temp,B,Result)); B>A -> (Temp is B-A, gcd(A,Temp,Result))).

  4. Question 3 Solve the following Prolog queries ?- op(X) = op(1). X = 1 ?- op(op(Z),Y) = op(X, op(1)). Y = op(1) Z = _G157 X = op(_G157) ?- op(X,Y) = op(op(Y),op(X)). X = op(op(op(op(op(op(op(op(op(op(...)))))))))) Y = op(op(op(op(op(op(op(op(op(op(...))))))))))

  5. Question 4 Solve the following Prolog queries using lists ?-[1,2,3] = [1|X]. X = [2,3] ?- [1,2,3] = [1,2|X]. X = [3] ?- [1 | [2,3]] = [1,2,X]. X = 3 ?- [1 | [2,3,4]] = [1,2,X]. No ?- [1 | [2,3,4]] = [1,2|X]. X = [3,4]

More Related