具有三变量辅助函数的指数递归 ML 函数

发布于 2025-01-16 16:38:24 字数 283 浏览 2 评论 0原文

我需要帮助弄清楚我需要递归地为辅助函数做什么,我有点迷失了我需要为辅助函数做什么。

这是问题和示例输入。 示例输入和输出

以下是辅助函数的示例

辅助函数示例

这是我到目前为止所写的内容 我的尝试

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素染倾城色 2025-01-23 16:38:24

您只需稍微更改一下符号即可找到解决方案。

不要写 a*bn,而是写 exp3(a, b, n)

然后这个例子说,

  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

你实际上已经得到了解决方案——文本字面意思是“引理 4.15 提供了一个基本情况,引理 4.16 提供了一个递归情况”。

引理 4.15:

exp3(a, b, 0) = a

引理 4.16:

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

并且需要帮助的函数应该只有一种情况;示例中显示的第一个“步骤”:

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

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文