Message Boards Message Boards

GROUPS:

Reason for difference between Nest and NestList

Posted 1 month ago
394 Views
|
7 Replies
|
6 Total Likes
|

Hi!

Is there a reason that Nest[] applies a function n times but NestList[] applies a function 0 to n times?

Thank you!

7 Replies

Hi Timo In my personal opinion, I think in Nest the user is only interested in the final answer and whether the step zero is included or not won't make a difference in the final result. However, in NestList, the user is interested to see all the steps of the operation so Wolfram staff thought that it would be useful to also include step zero in the list. Hope this makes sense to you.

Posted 1 month ago

Timo:

From what I can tell, the documentation is perhaps a bit misleading one compared side by side.

Next[f, x, 0]

returns

x

While

Next[f, x, 1]

returns

f[x]

So, I think Nest supports n = 0 and works as expected.

I hope that helps.

Have a great and safe rest of your weekend.

I was asking about the rational behind the decision to implement the parameter to both functions in different ways?!

There is no difference.

Can you show an example that demonstrates a difference?

Hey Mike,

thank you for your answer! I think i phrased my question wrong.

I was asking about the rational behind the decision to implement the parameter to both functions in different ways?!

All the best, Timo

Posted 1 month ago

Timo:

That is a great question. But how is the implementation different? It seems to me they just described the function differently in the documentation.

But, I am still very new to all of this. I would really like to understand as well.

THANK YOU for the great question.

Posted 1 month ago

Great thinking Ahmed. That does make sense to me.

Look at it: NestList gives a list of the intermediate results, which may be useful for a bunch of reasons.

Nest[f, x, 3]
NestList[f, x, 3]
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract