You're saying you want as outputs
$1,3,7,15,31,63$
Note they are respectively $2^1-1,2^2-1,2^3-1,2^4-1,2^5-1,2^6-1$ so what you really want is $f(n)=2^n-1$
Now this is a finite geometric sum, namely
$\sum_{i=0}^{n-1}2^i=2^n-1$
This follows from the geometric sum formula, that is
$\sum_{i=0}^{n-1} a^i=\frac{a^n-1}{a-1}$
The MO for this is the following. Let our sum be $S$
$1 + a + \cdots + {a^{n - 1}} = S$
Then
$a + {a^2} + \cdots + {a^n} = aS$
But
$a + {a^2} + \cdots + {a^n} = \left( {1 + a + \cdots + {a^{n - 1}}} \right) - 1 + {a^n} = S - 1 + {a^n}$
So that
$\eqalign{ & S - 1 + {a^n} = aS \cr & S - aS = 1 - {a^n} \cr & \left( {1 - a} \right)S = 1 - {a^n} \cr & S = \frac{{1 - {a^n}}}{{1 - a}} \cr} $
as desired.