Let A be a subgroup of a commutative group (G, + ) and P be a commutative ring. We give the full description of functions $${g: G \rightarrow P}$$ satisfying $$g(x + y) + g(x - y) = 2g(x)g(y) \quad (x, y) \in A \times G. \quad\quad\quad\quad (A)$$ Thus we obtain a family of functions depicting evolutions of quite arbitrary functions $${g_0 : G \to P}$$ into cosine functions $${g: G \to P}$$ , i.e., solutions of the d’Alembert (cosine) functional equation $$g(x + y) + g(x - y) = 2g(x)g(y) \quad x, y \in G. \quad\quad\quad\quad (B)$$ We also show that every function $${g: G \rightarrow P}$$ , fulfilling (A), is a solution of (B) if and only if A = G.