Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The non-tail recursive version shown in class The question needs to be done using OCaml in this format. 4. In lecture 11 quickly explained the
The non-tail recursive version shown in class
The question needs to be done using OCaml in this format.
4. In lecture 11 quickly explained the Russian peasant algorithm for fast exponentiation. In this exercise you have to implement a tail-recursive version of the algorithm. Everything is with integers in this question so please do not use floating point operations. Our tester will detect whether you used built-in functions, so please don't try to use them. # let even n = (n mod 2) = 0; ; # let odd n = (n mod 2) = 1;; # let rec rpe base power = if base = 0 then 0 else if power = 0 then i else if (odd power) then base * (rpe base (power - 1)) else let tmp = (rpe base (power/2)) in tmp * tmp; ; val rpe : int -> int -> int =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