Question: DONE IN PROLOG 2. In this assignment you can use all Prolog functions. (a) L1 and L2 are arbitrary numeric lists/trees. Make Prolog program addlst(L1,

DONE IN PROLOG
DONE IN PROLOG 2. In this assignment you can use all Prolog

2. In this assignment you can use all Prolog functions. (a) L1 and L2 are arbitrary numeric lists/trees. Make Prolog program addlst(L1, L2, Sum) where Sum is the sum of all components in L1 and L2. For example, the statement addlst ([[1],2],[3/4]], [[1]],s] should return s = 11. (b) List X contains n numbers x1, x2,...,xn. List Y contains k numbers yl, y2,...,yk. Write a Prolog program that that in the case n=k returns the value xl*yl+x2*y2+...xn*yn; in all other cases the program should return the error message Length error, as in the following examples: ?- sp([1,2,3] [3, 2, 1), S] S = 10. ?- sp ([1,2,3,4), (3,2,1), s). S = 'Length error'. 1 2. In this assignment you can use all Prolog functions. (a) L1 and L2 are arbitrary numeric lists/trees. Make Prolog program addlst(L1, L2, Sum) where Sum is the sum of all components in L1 and L2. For example, the statement addlst ([[1],2],[3/4]], [[1]],s] should return s = 11. (b) List X contains n numbers x1, x2,...,xn. List Y contains k numbers yl, y2,...,yk. Write a Prolog program that that in the case n=k returns the value xl*yl+x2*y2+...xn*yn; in all other cases the program should return the error message Length error, as in the following examples: ?- sp([1,2,3] [3, 2, 1), S] S = 10. ?- sp ([1,2,3,4), (3,2,1), s). S = 'Length error'. 1

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!