-1

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

jwolf
  • 33
  • 3
  • 1
    The helper function should call itself, not the function it's "helping". (And please don't post pictures of code, post the code.) – molbdnilo Mar 24 '22 at 07:41
  • Please post text _as_ text where possible. (as opposed to an image of text) – Chris Mar 24 '22 at 17:36

1 Answers1

0

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)
molbdnilo
  • 64,751
  • 3
  • 43
  • 82