This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: 1 COMP348: Principles of Programming Languages Fall 2010 Assignment 1 Due date: Monday, October 18, 2010 Exercise 1 (Prolog) Consider the following graph: a b c d e f g (a) Define the Prolog facts specifying this graph. (b) Write down a Prolog program pathk(X, Y, K) returning the paths of a specific size K. For example, if the program is executed as follows: ?- pathk(X, Y, 3), Prolog will return: X=a, Y=d ; X= b, Y=e ; X=a, Y=e ; X=c, Y=f ; X=d, Y=g ; false. (c) By asking Prolog the query: ?- pathk(X, Y, 6), demonstrate step-by-step (unification and resolution) how this query is executed. 2 Exercise 2 (Prolog) The Fibonacci sequence is given as 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, Build a Prolog program to compute the n th Fibonacci number. (Indication: starting from the third element, each element is the sum of the two previous elements) Exercise 3 (Prolog) (a) Write down a Prolog program (we call it fela ) having as input a list and returning true if the First element of the list is Equal to the Last element. The program should return false if the input is not a list. element of the list is Equal to the Last element....
View Full Document
- Spring '10