我可以要求物理类比或隐喻递归吗? [英] Could I ask for physical analogies or metaphors for recursion?

查看:115
本文介绍了我可以要求物理类比或隐喻递归吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我突然在一个递归语言类(sml)中,递归对我来说还不是很理智。我正在想方形瓷砖的地板有时是整数倍增的模型或隐喻,或者Cuisenaire棒是加法和减法的模型或类比。有没有人有这样的模型可以分享?

解决方案

想象一下,你是一个真正的魔术师,你自己。你创造了一个更接近目标的步伐,并给予他(或她)与你所得到的相同的命令

你的双倍对他的副本也一样。他是魔术师,你看。



当最终版本发现自己创建了目标时,它无处可去,所以它向其创建者报告。这是相同的。



最后,你可以回答– 没有移动过一英寸 –现在可以轻松地从中创建最终结果。你假装不知道所有那些为你做实际的辛苦工作的双打。 嗯,你对自己说,如果我离目标更近了一步, 已经知道 结果?难道 很容易 找到最终答案 然后 *



当然,如果 you 是双重的,您必须将您的发现报告给 创建者。



更多此处。 (也是,我认为我看到这个双打创作连锁事件这里,虽然我不完全确定)。






*这就是问题解决递归方法的本质。

我怎么知道我的程序是正确的?如果我的简单的小组合步骤产生了一个有效的解决方案,在假设它为小案例产生了正确的解决方案的情况下,我所需要的只是确保它适用于最小的情况 - ndash;基础案例 - ndash;然后通过 验证有效性。

另一种可能性是分而治之,我们将问题分为两部分,所以将基本案例分解得更快。只要组合步骤简单(并且保留当然解决方案的有效性),它就可以工作。在我们的魔术师比喻中,我得到了自己的两个副本,并在他们完成时将他们的两个答案合并为一个。他们每个人都创建了两个自己的副本,所以这会创建一个魔术师的分支树,而不是像以前那样简单的线。






一个很好的例子是 Sierpinski三角形,它是一个由<通过将它们堆叠在角落,简单地将它们放在三个四分之一的Sierpinski三角形上。



三个组件三角形的每一个都是根据相同的配方构建的。

虽然它没有基本情况,所以递归是无限的(无底的;无限的),S.T的任何有限的表示。将大概画一个点代替S.T.这是太小(作为基本情况下,停止递归)。

在链接的维基百科文章中有一个很好的图片。



递归绘制ST没有大小限制将永远不会在屏幕上绘制任何东西!对于数学家来说,递归可能很好,但工程师应该对此更加谨慎。 :)



切换到 corecursion ⁄迭代(请参阅相关答案),我们首先绘制轮廓,然后再绘制内部;所以即使没有尺寸限制,图片也会很快出现。该程序然后会很忙,没有任何明显的影响,但这比空白屏幕好。


I am suddenly in a recursive language class (sml) and recursion is not yet physically sensible for me. I'm thinking about the way a floor of square tiles is sometimes a model or metaphor for integer multiplication, or Cuisenaire Rods are a model or analogue for addition and subtraction. Does anyone have any such models you could share?

解决方案

Imagine you're a real life magician, and can make a copy of yourself. You create your double a step closer to the goal and give him (or her) the same orders as you were given.

Your double does the same to his copy. He's a magician too, you see.

When the final copy finds itself created at the goal, it has nowhere more to go, so it reports back to its creator. Which does the same.

Eventually, you get your answer back – without having moved an inch – and can now create the final result from it, easily. You get to pretend not knowing about all those doubles doing the actual hard work for you. "Hmm," you're saying to yourself, "what if I were one step closer to the goal and already knew the result? Wouldn't it be easy to find the final answer then ?" *

Of course, if you were a double, you'd have to report your findings to your creator.

More here.

(also, I think I saw this "doubles" creation chain event here, though I'm not entirely sure).


* and that is the essence of the recursion method of problem solving.

How do I know my procedure is right? If my simple little combination step produces a valid solution, under assumption it produced the correct solution for the smaller case, all I need is to make sure it works for the smallest case – the base case – and then by induction the validity is proven!

Another possibility is divide-and-conquer, where we split our problem in two halves, so will get to the base case much much faster. As long as the combination step is simple (and preserves validity of solution of course), it works. In our magician metaphor, I get to create two copies of myself, and combine their two answers into one when they are finished. Each of them creates two copies of themselves as well, so this creates a branching tree of magicians, instead of a simple line as before.


A good example is the Sierpinski triangle which is a figure that is built from three quarter-sized Sierpinski triangles simply, by stacking them up at their corners.

Each of the three component triangles is built according to the same recipe.

Although it doesn't have the base case, and so the recursion is unbounded (bottomless; infinite), any finite representation of S.T. will presumably draw just a dot in place of the S.T. which is too small (serving as the base case, stopping the recursion).

There's a nice picture of it in the linked Wikipedia article.

Recursively drawing an S.T. without the size limit will never draw anything on screen! For mathematicians recursion may be great, engineers though should be more cautious about it. :)

Switching to corecursion ⁄ iteration (see the linked answer for that), we would first draw the outlines, and the interiors after that; so even without the size limit the picture would appear pretty quickly. The program would then be busy without any noticeable effect, but that's better than the empty screen.

这篇关于我可以要求物理类比或隐喻递归吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆