I was wondering where the formula: $$\cos^n(x)=\sum_{k=0}^n\frac{n!}{k!(n-k)!}\cos(x(2k-n))$$ Was first originally published. I accidentally derived it a few days ago and was wondering where it was first established for historical context. I derived it in the following way:
Using Euler's formulas, we can write $\cos^n(x)$ out as: $$\cos^n(x)=\frac{1}{2^n}(e^{ix}+e^{-ix})^n$$ Which, when expanded using Newton's binomial formula yields: $$\cos^n(x)=\frac{1}{2^n}\sum_{k=0}^n\frac{n!}{k!(n-k)!}e^{ikx}\cdot e^{-ix(n-k)}$$ Which simplifies down to: $$\cos^n(x)=\frac{1}{2^n}\left(\sum_{k=0}^n(\frac{n!}{k!(n-k)!}\cos(x(2k-n)))+i\sum_{k=0}^n(\frac{n!}{k!(n-k)!}\sin(x(2k-n)))\right)$$ $$=\frac{1}{2^n}C_n+\frac{i}{2^n}S_n$$ Because $S_n\in\mathbb{R}$ we can write that $\Im(\cos^n(x))=S_n=0$ And consequently we yield: $$\cos^n(x)=\frac{1}{2^n}\sum_{k=0}^n\frac{n!}{k!(n-k)!}\cos(x(2k-n))$$ Where does this originally come from? I'm sure it's been done before but I've looked everywhere and can't find it at all. This is as usual purely recreational.

Note: This does not address the question of origin of these formulas. But, in the spirit of recreation, here are some other ways to rearrange the sum, which are easier to parse if we treat odd and even $n$ separately.
Because the cosine is an even function and the binomial coefficients are symmetric, we can get away with half as many terms and some other forms.
When $n$ is odd, we fold the sum in half: $$ \cos^n(x) = \frac{1}{2^{n-1}} \sum_{k=0}^{(n-1)/2} \binom{n}{k} \cos\bigl( (n-2k)x \bigr). $$ Equivalently, with $n = 2m+1$, $$ \cos^{2m+1}(x) = \frac{1}{2^{2m}} \sum_{k=0}^{m} \binom{2m+1}{k} \cos\bigl( (2m-2k+1)x \bigr), $$ or by reindexing with $j = m - k$, $$ \cos^{2m+1}(x) = \frac{1}{2^{2m}} \sum_{j=0}^{m} \binom{2m+1}{m-j} \cos\bigl( (2j+1)x \bigr). $$
For example, with $n = 7$, equivalently $m = 3$, $$ \cos^7(x) = \frac{1}{2^6} \biggl[ \binom{7}{3} \cos(1x) + \binom{7}{2} \cos(3x) + \binom{7}{1} \cos(5x) + \binom{7}{0} \cos(7x) \biggr]. $$
When $n$ is even, we peel off the middle term before folding in half: $$ \cos^n(x) = \frac{1}{2^n} \binom{n}{n/2} + \frac{1}{2^{n-1}} \sum_{k=0}^{n/2-1} \binom{n}{k} \cos\bigl( (n-2k)x \bigr). $$ Equivalently, with $n = 2m$, $$ \cos^{2m}(x) = \frac{1}{2^{2m}} \binom{2m}{m} + \frac{1}{2^{2m-1}} \sum_{k=0}^{m-1} \binom{2m}{k} \cos\bigl( (2m-2k)x \bigr), $$ or by reindexing with $j = m - k$, $$ \cos^{2m}(x) = \frac{1}{2^{2m}} \binom{2m}{m} + \frac{1}{2^{2m-1}} \sum_{j=1}^{m} \binom{2m}{m-j} \cos( 2jx ). $$
For example, with $n = 6$, equivalently $m = 3$, $$ \cos^6(x) = \frac{1}{2^6} \binom{6}{3} + \frac{1}{2^5} \biggl[ \binom{6}{2} \cos(2x) + \binom{6}{1} \cos(4x) + \binom{6}{0} \cos(6x) \biggr]. $$