Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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
image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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