1 / 7

Prolog Programming Exercises on Fibonacci, GCD, and First-Order Logic

This document outlines a series of intelligent systems programming exercises using Prolog, focusing on foundational concepts. The exercises include a program to calculate Fibonacci numbers using a recursive function, finding the greatest common divisor (GCD) through subtraction-based recursion, and various queries involving list manipulations. Additionally, the document presents first-order logic (FOL) statements that express relationships regarding students' love for AI, including rules for quantifiers such as "all," "some," "at least two," "exactly two," and "at most two."

terra
Download Presentation

Prolog Programming Exercises on Fibonacci, GCD, and First-Order Logic

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) is op(1). ERROR: Arithmetic: ‘op/1’ is not a function ?- 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]

  6. FOL question Express the following sentences in first-order logic: (a) All students love AI (b) Some students love AI (c) At least two students love AI (d) Exactly two students love AI (e) At most two students love AI

  7. FOL question • All students love AI • ∀ x Student(x) => Loves(x, AI) • Some students love AI • Ǝ x Student(x)  Loves(x, AI) • At least two students love AI  • Ǝ x,y (x≠y)  Student(x)  Loves(x,AI)  Student(y)  Loves(y,AI) • Exactly two students love AI • Ǝ x,y ∀ z x≠yx≠zy≠z Student(x)  Loves(x,AI)  Student(y)  Loves(y,AI)  Student(z)  ┐Loves(z,AI) • Or • Ǝ x,y (x≠y Student(x)  Loves(x,AI)  Student(y)  Loves(y,AI)  ∀ z (Student(z)  Loves(z,AI) < --> (x=z V y=z)) ) • At most two students love AI ∀ x,y ,z Student(x)  Loves(x,AI)  Student(y)  Loves(y,AI)  Student(z)  Loves(z,AI)  (x=y Vx=z V y=z)

More Related