Answered step by step
Verified Expert Solution
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started