You are on page 1of 4

Page 1 of 4

EXlCSE/T /325/71/2008

B.C.S.E Part-1 Examination, 2008


(2nd Semester)
Subject: Mathematical Logic and Functional Programming

Time: Three hours Full Marks: 100

Answer Question No. 1 and any FOUR from the rest

1. a) With the help of example, explain "Occur-Check problem" in prolog.

)f. Evaluate the following A-expressions using applicative order evaluation (or
< pass by value) and normal order evaluation (or pass by name). If, in any case,
evaluation is not possible, write the reasons.

i. ( (Ax. * x x) ( + 2 3))

ii. ( (AY. 5) ((Ax. x x) (Ax. x x)) )

c. Explain (briefly) main characteristics of functional programming language and


functional program.

d. Consider the list (2 5 8) in Scheme. What will be the response of the Scheme
Interpreter for the following cases? Why?

1. > (2 5 8)

11. > '(2 5 8)

e. Suppose that we represent" Sam is Bill's father" by FATHER (BILL, SAM) and
" Harry is one of Bill's ancestors" by ANCESTOR (BILL, HARRY). Represent the
following in predicate logic.

" Every ancestor of Bill is either his father, his mother, or one of their ancestors."
4 x 5 =20

.. ..•., -
Page 2 of 4

2. Consider PERM (L, M) is a predicate which is true if and only if L is a


permutation of M and SORTED (L) is also a predicate which is true if and only if
list L is sorted in ascending order.

a) Write prolog clauses that define PERM (L, M) and SORTED (L). Then, define
SORT (L, M) (M is a sorted version of L) using PERM and SORTED. What is
the time complexity of this program?
b) Write a faster algorithm (such as QUICKSORT) in prolog? Draw aprolog search
tree to show how this algorithm works on the list L= (2 1 3) to produce the sorted
list. 10+ 10

3. a The following C function computes the power ab , where a is floating point


number and b is a (non-negative) integer: 5

double power( double a, int b)


{ int i;
double temp = 1.0;
for (i = 1; i < = b; i++ ) temp *= a ;
return temp;
}

Rewrite this function using an accumulating parameter to make it tail recursive.

I). Show the output of the following program (written in C syntax) using "pass by
value" and "pass by name" parameter passing methods and explain how it is
computed. 5
int i;
int a[2];
void p( int x, int y)
{ x++;
i++;
y++;
}
mainO
{ a[O]=l;
a[l ]=1;
i=O;
p(a[i], ariD;
printf("%d\n", a[O]);
printf(" %d\n", a[ 1]);
return 0;
}
Page 3 of4

c) With the help of a suitable example, discuss how lambda calculus can model recursion
using the function Y called fixed-point combinator. 10

A: a) Given only the following prolog clause:


human (bob).

How will Prolog respond for the following goals? Why?


?-human(X).

? - not(human(X».

? - not(not(human(X»).
5

b).Convert the following wffto clausal form (Clearly show the steps)

~(\ix){ P(x) ~ { (\iy) [P(y) ~ P(f(x,y»] 1\ ~ (\iy) [ Q(x,y) ~ P(y) ] } }


10

c) Define 1 (one) and 2 (two) by Lambda abstraction. Given the definition of the
successor function as: successoFAn. Af. Ax.(f((n f)x)), show that
(successor one )=two 5

5. a) C()nsider the following knowledge base (KB) and convert it to clauses using
predicate logic. Using Resolution refutation tree prove that West is a criminal.

An American who sells weapons to hostile nations, will be treated as criminal.


Nono owns some missiles.
IfNono owns some missiles, West sells it to Nono.
Missiles are weapons.
An enemy of America is treated as hostile nation
West is an American.
Nono is an enemy of America. 10

b) The following prolog code defines predicate P:


P( X, [XIYJ ).
P( X, [YIZ] ):-P( X, Z).

Show prolog search trees and solutions for the queries peA, [1,2,3])
and P(3, [1,2,3]). What standard list operation doesP represent?
(4+4)+2
Page 4 of4

6. a) Consider that a factorial program has been written in a CLP '(Constraint Logic
Programming) language as follows:
fact(O,l).
fact(N, N * R1):- N>O, fact(N-1,R1).

Explain how this CLP version of factorial program differs from the traditional
Prolog version. Write the traditional prolog version of this program.

Show how CLP version of the factorial program (written above) would produce
the solution for the goal fact (X; 6) (clearly show the resolution steps).
5+10

b) What areexample
suitable the uses for
of CUT predicate and FAIL predicate in prolog. Give
each predicate. (1.5'"
:
'-f=/

7. a) Consider the function abc defined as follows:

(define (abc k x)
(cond ( ( null ? x) k)
( ( < ( car x ) k) (abc (Gar x )( cdr x)))
( else (abe k (cdr x») ))

1. What is the purpose of this function?

In each of the following cases, give the value of the expression and explain
how it is computed.

ii (abc 5 '())
iii. (abc 5 '(5 4 3))
iv. (abc 5 '( 4 5 6) )
v. (abc 5 '( 7 3 6 2)) 2 x 5=10

b) Write a program in Scheme (a dialect of LISP) to find the sum of a list of


integers. 5

c) What is called higher order function? Give a suitable example in Scheme to


illustrate higher order function. 5

You might also like