I would like the function $f(n,M)$, where $n$ and $M$ are integers and $n\le M$, so that $f$ satisfies the following two conditions:
(1) $\sum_{n=0}^M (-1)^n f(n,M) = \tfrac{1}{2}$
(2) $f(n,M) \approx 1$ whenever $n\ll M$
The function is needed as a summation mollifier to ensure a piecewise function is continuous (each region of the piecewise function is a series expansion). The function $f(n,M) = e^{-\frac{k n^2}{M^2}}$ is close for large $k$, but the summation is not exactly $\frac{1}{2}$ and thus the piecewise function has a discontinuity.
I should also mention that $f(n,M) = 1$ for $n<M$ and $f(n,M) = 1/2$ for $n=M$ works, but I would prefer a smoother function.