I would like to have this suite computed :
h(-2)=0
h(-1)=1
h(i)=a(i)*h(i-1)+h(i-2), for i>=0
(a is given; for my tests I use a=(1,1,2), it has only 3 terms)
I think the best way is to use streams, so I wrote:
val h:Stream[Int]=0#::1#::(h.zipWithIndex.zip(h.tail).zip(h.tail.tail)).map{case(((a,i),b),c)=>{
liste_a(i-2)*b+a
}}
def h2(i:Int)=h(i+2)
but I have a ...stack overflow error, and I don't know where it comes from.