# Defining a recursive sequence

I want to define a recursive sequence and then ask Mathematica to print a specific value: Am I doing something wrong?

First, you need to use "delayed substitution" so that Mathematica knows it needs to wait with evaluating expression until you type G. Secondly, you can't have arithmetic expression on the left-hand side. so the second line should be:
G[y_]:=2G[y-1].

• Also it's not strictly true that you can't have an arithmetic expression on the left hand side; it just gives completely different semantics from the one intended: The original definition would have been used when calling as G[y+1] (assuming y has no value assigned at the point of call). Indeed, when using a pattern, it can even make sense to have arithmetic arguments, e.g.: G:=1;G[i_Integer/;i>0]:=2*G[i-1];G[y_+n_Integer/;n>0]:=2*G[y+n-1] Then you could write G[a+4] and get the result 16*G[a]. May 21, 2012 at 8:17
• @celtschk Hi, could you explain if there is a difference between those two functions : H := Function[If[# <= 0, 0, H[# - 1] + #]] and G = Function[If[# <= 0, 0, r := G[# - 1] + #; r ]] ? Sep 24, 2016 at 14:20