Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

8. What will be the output from ML system in ??? from following example code? -

ID: 3711745 • Letter: 8

Question

8. What will be the output from ML system in ??? from following example code?
- fun Sigma (f, x, y) = = if x <= y then f(x) + Sigma (f, x+1, y) = else 0; val Sigma = fn : (int -> int) * int * int -> int
- Sigma (sq, 1, 4); val it = ???

8. What will be the output from ML system in ??? from following example code?
- fun Sigma (f, x, y) = = if x <= y then f(x) + Sigma (f, x+1, y) = else 0; val Sigma = fn : (int -> int) * int * int -> int
- Sigma (sq, 1, 4); val it = ???


- fun Sigma (f, x, y) = = if x <= y then f(x) + Sigma (f, x+1, y) = else 0; val Sigma = fn : (int -> int) * int * int -> int
- Sigma (sq, 1, 4); val it = ???

Explanation / Answer

sigma(sq,1,4): 1<=4: call sq(1)+sigma(sq,2,4)

sigma(sq,2,4): 2<=4: call sq(2)+sigma(sq,3,4)

sigma(sq,3,4): 3<=4: call sq(3)+sigma(sq,4,4)

sigma(sq,4,4): 4<=4: call sq(4)+sigma(sq,5,4)

sigma(sq,5,4): sigma = 5*5*5

Ans: 5*5 + sq(4) +sq(3)+sq(2)+sq(1) = 25 + 16 + 9 + 4 + 1 = 29

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote