Recursive Functions in Maple

1k Views Asked by At

I'm trying to input the following recursive function into Maple but am not sure how? The recursive equations are as follows: \begin{align} h(2n)&=h(n),\\ h(4n+1)&= h(2n+1)+h(n), \\ h(4n+3)&=2\cdot h(2n+1)-h(n). \end{align}

Any help would be much appreciated!

1

There are 1 best solutions below

2
On BEST ANSWER

You need initial conditions at $n=1$ and $n=3$. Below, I just set them to the symbols $h1$ and $h3$.

restart:

h:= proc(n::posint)
option remember;
local q,r;
     q:= iquo(n,4,r);       
     `if`(r::even, thisproc(2*q+r/2), `if`(r=1, <1,1>, <2,-1>).thisproc~(<2*q+1, q>))
end proc:

#Set initial conditions:
(h(1), h(3)):= (h1, h3):  

#Usage: 
h(1021);