Beruflich Dokumente
Kultur Dokumente
EXlCSE/T /325/71/2008
)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))
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)
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
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
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
? - not(human(X».
? - not(not(human(X»).
5
b).Convert the following wffto clausal form (Clearly show the steps)
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.
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=/
(define (abc k x)
(cond ( ( null ? x) k)
( ( < ( car x ) k) (abc (Gar x )( cdr x)))
( else (abe k (cdr x») ))
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