Message Boards Message Boards

1
|
3479 Views
|
4 Replies
|
8 Total Likes
View groups...
Share
Share this post:

Is there a way to implement

Posted 11 years ago
Hey everyone,

im trying to implement a function which looks like this:
c[n_]:=Piecewise[{{c[n/3]+c[Abs[(n-2)/3-2]],Mod[n,6]==0&&n!=0},{c[(n - 2)/3] + c[Abs[(n - 2)/3 - 2]]),Mod[n,6]==2},...etc}]
Which uniquely defines its value at each n, since c[0] is defined to be 1. But Mathematica wont calculate the values and also the use of RecurrenceTable is restricted to arguments of type c[n+int].

A helpful idea would give me a happy day emoticon

Thanks for reading,

Lufu
4 Replies
Great ! Thats exactly what i was looking for emoticon

Thanks a lot !
This looks quite nice but doesnt work out with my function either. I think the problem is, that it defines the values somewhat implicit. Like f[2]=-f[0]-f[2], so mathematica got to solve a equation to get the value for f[2]. I attached the function to this post. Its even worse for the odd numbers because it refers to elements ahead, but overall everything is well defined.
Attachments:
I see.  You get e.g., f[1]=f[2]+f[3] which makes f[1] look undefined but you also get f[2] == -f[0] - f[2], f[3] = f[0] + f[6], f[4] = -f[2] - f[4], f[6] = f[0] + f[2] + f[4] i.e. exactly enough to solve uniquely.  The same problem happens with the enumerating generalized recursive functions.  Some are nice, some undefined, some underdefined, but also some whose definition status is unclear and probably formally undecidable.  These were studied by several people at the first NKS summer school (now the scope of the school is expanded with the new name Wolfram Science Summer School).

Here is one way to approach this, by generating the equations and using Reduce. 
Clear[equ, f]; equ[0] = (f[0] == 1);
equ[n_] :=
f[n] == Which[Mod[n, 6] ==  0 && n != 0,
   f[n/3] + f[Abs[n/3 - 2]] + f[Abs[n/3 + 2]],
   Mod[n, 6] == 2, -(f[(n - 2)/3] + f[Abs[(n - 2)/3 - 2]]) ,
   Mod[n, 6] == 4, -(f[(n + 2)/3] + f[Abs[(n + 2)/3 + 2]]) ,
   Mod[n, 2] == 1, f[Abs[n - 3]] + f[n + 3] ]
equs20 = Array[equ, 20, 0]

Array[f, 20] /. ToRules[Reduce[equs20]]
POSTED BY: Todd Rowland
You can do this sort of thing
f[1] = 7;
f[n_] := 3 f[Floor[n/3] + 1];
Array[f, 20]

although it is usually more efficient to store incrementally
f[1] = 7;
f[n_] := f[n]=3 f[Floor[n/3] + 1];
Array[f, 20]

Note the generalized recursive functions from the New Kind of Science book and this note at the end
http://www.wolframscience.com/nksonline/page-907b-text
POSTED BY: Todd Rowland
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