-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

2
  • 1
    The helper function should call itself, not the function it's "helping". (And please don't post pictures of code, post the code.) Commented Mar 24, 2022 at 7:41
  • Please post text as text where possible. (as opposed to an image of text) Commented Mar 24, 2022 at 17:36

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the clarification and the advice.
Do you understand that it's not just "clarification" and "advice", but a solution? You just need to put the pieces together.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.