Group Abstract Group Abstract

Message Boards Message Boards

0
|
5.5K Views
|
5 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Recursive function with no apparent recursive relationship

Posted 11 years ago
POSTED BY: B B
5 Replies

Alternatively one could make the statement:

Attributes[f] = Listable;

This works in the case that the lists contain more than two elements.

Henrik

POSTED BY: Henrik Schachner
Posted 11 years ago

Perfectly clear. Thank you

POSTED BY: B B
Posted 11 years ago
POSTED BY: Kuba Podkalicki
Posted 11 years ago

Yes, i almost understand. Thank you for your clear explanation.

I only need to apply it on a simple example

When i evaluate f[2, 3], the result is {f[2], f[3]}. Logically, the recursive function stops because each function has only one argument.

But I evaluate f[{2, 3}, {3, 3}], the result is {f[{2, 3}], f[{3, 3}]}. I would like to Mathematica continue the indentation. I believe that it becomes i didn't use the syntax of the list well.

May you help me to correct my syntax so that I can test this kind of recursive function on a example ?

Thanks a lot for your help.

POSTED BY: B B
Posted 11 years ago

The function you've provided is not refering to itself basing on values of arguments that were provided but basing on the pattern that those arguments match*.

p.s. you probably wanted to write:

f[x_, y_]:= {f[x], f[y]}

So f refers to itself only when you provide two arguments. Then it is returning itself scanned over those arguments. And since for f acting on one argument are no associated values the recursion stops.

Is that clear?

POSTED BY: Kuba Podkalicki
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard