Question: Question 6 [ 1 5 ] Let L 1 , L 2 and L denote lists of terms. Write Prolog programs to realise the following:

Question 6[15]
Let L1, L2 and L denote lists of terms. Write Prolog programs to realise the following:
(Note that the lengths of lists L1 and L2 should be equal in all cases):
a) Interleave alternate elements of L1 and L2 into L.
For example, if L1=[a,b,c] and L2=[1,2,3],
then L =[a,1,b,2,c,3].
Are the input-output roles of variables in your program reversible?
b) Transpose L1 and L2 into L. That is, if L1=[a,b,c] and L2=[1,2,3], then
L =[(a,1),(b,2),(c,3)].
Are the input-output roles of your variables reversible?
c) Suppose that L1 and L2 are lists of numeric values. Write a procedure
inner_prod(L1,L2,X) that defines X to be the inner-product of the two vectors L1
and L2.
The inner-product X is calculated as follows:
If we have two vectors [a1, a2,..., an] and [b1, b2,..., bn] then
X = a1\times b1+ a2\times b2+...+ an\times bn.
Are the input-output roles of the variable in your program reversible?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!