Question: Write an ML function sum which, given an integer n computes the sum of the first n naturals. Namely, it computes: sigma_i = 0^n i

 Write an ML function sum which, given an integer n computes

Write an ML function sum which, given an integer n computes the sum of the first n naturals. Namely, it computes: sigma_i = 0^n i fun sum n = ... Extent your sum function into a sumsq function. Given a natural n, sumsq computes the sum of the squares of the first n naturals: sigma_i = 0^n i^2 fun sumsq n = ... Write an ML function sumOdd which, given a natural n computes the sum of the first n odd naturals. For instance, sumOdd 4 = 1 + 3 + 5 + 7 (i.e., we have four terms). fun sumOdd n = ... Write an ML function fib that computes, from an integer input n, the n^th Fibonacci number (as always, fib(i) = fib(i - 1) + fib(i - 2), fib(0) = 0, fib(1) = 1). fun fib n = ... Write an ML function fibFast that computes, in linear time, from an integer input n, the n^th Fibonacci's number. fun fibFast n =

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!