Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions