Home > OS >  Recusive ML function of exponential with three variable helper function
Recusive ML function of exponential with three variable helper function

Time:04-04

I need help figuring out what I need to do for the helper function recursively, I am kinda lost of in what I need to do for the helper function.

Here is the question and the example input. The example input and output

Here is the example of what the helper function does

The helper function example

This is what I have written so far My attempt

CodePudding user response:

You only need to change the notation slightly to find the solution.

Instead of a*bn, write exp3(a, b, n).

Then the example says,

  exp(3,4)
= exp3(1, 3, 4)
= exp3(1*3, 3, 4-1)
= exp3(3*3, 3, 3-1)
= exp3(3*9, 3, 2-1)
= exp3(3*27, 3, 1-1)
= 81

And you have actually been given the solution – the text literally says "Lemma 4.15 provides a base case, Lemma 4.16 a recursive case".

Lemma 4.15:

exp3(a, b, 0) = a

Lemma 4.16:

exp3(a, b, n) = exp3(a * b, b, n - 1)

And the function that needs help should only have one case; the first "step" shown in the example:

fun exp(a, b) = exp3(1, a, b)
  • Related