Exchanging definite integral and infinite sum in context of Fourier series I am writing a mathematics paper on the convergence of the Fourier series for periodic functions, and in the first section (where I define the Fourier series), I also derive the standard coefficients $a_n, b_n$. The standard way of doing this is to multiply both sides of the function by $\cos{kx}$ or $\sin{kx}$ depending on which coefficient you are calculating, and integrating from $-\pi$ to $\pi$, as follows:
$$\int_{-\pi}^\pi f(x)\cos(kx) \, dx = \int_{-\pi}^\pi a_0 \cos{kx} \, dx + \int_{-\pi}^\pi \left(\sum_{n=1}^\infty a_n\cos{nx}\cos{kx} + b_n\cos{nx}\sin{kx} \right)\,dx.$$
However, from this point, the standard derivation of the coefficients involves interchanging the integral and the sum, but to me this is not inherently obvious. For example, if $a_n = 1$ for all $n$, the summation does not converge and we would be integrating something infinite, which doesn't make sense. I've looked at a few posts that talk about interchanging the order of the sum and integral, and most of them don't really seem to apply.
Monotone convergence and Vitali convergence don't seem to apply since we can't make statements about pointwise convergence of $a_n\cos{kx}$ or $b_n\sin{kx}$ without being circular. Fubini's theorem tells us that if $\int\sum_n |f_n(x)| \,dx $ is finite, then we can interchange the summation and integral. However, we can't guarantee that such an integral is finite unless $\int_{-\pi}^\pi f(x) \cos(x)\, dx$ is finite--which led me to assume that the finiteness of the sum is a sufficient condition for interchanging the integral and sum, but my professor said this was insufficient.
Another thing I am thinking about is that pointwise convergence does not preserve integrability, but uniform convergence does. Does this mean that we can only derive the coefficients $a_n, b_n$ when $f$ is uniformly convergent? In that case, why would anyone care about pointwise convergence with the Dirichlet kernel proof?
I guess put simply, my question is, what can we stipulate about $f$ so that the interchange above is valid?
 A: When we talk about infinite series, one always has to specify what type of convergence is intended, for example: pointwise convergence/ a.e pointwise convergence/ uniform convergence/ convergence in $L^2$ norm etc. Once you specify this then we can start discussing further. Now, the way I've usually seen things, pointwise convergence of Fourier series is a very subtle topic, and depending on how much regularity you assume on your function $f$, you get all sorts of (weird and crazy but cool) results.
I don't really feel like working with $\sin$ and $\cos$; so let $\phi_n(x)= e^{inx}$ (perhaps with appropriate normalization factors, which I can never remember, and don't feel like calculating now). Given $n\in \Bbb{N}$, let
\begin{align}
s_{n,f}= \sum_{l=-n}^n \hat{f}(l)\phi_l = \sum_{l=-n}^n \left(\int_{-\pi}^{\pi} f(t)\overline{\phi_l(t)}\, dt\right) \phi_l
\end{align}
This is the $n^{th}$ partial sum. Now, here's a couple of results:

*

*If $f$ is of class $C^p$, where $p\geq 1$ is an integer, then $\lVert s_{n,f}-f \rVert_{\infty} = O\left(n^{\frac{1}{2}-p}\right)$ as $n\to \infty$. In particular, this means $s_{n,f}\to f$ uniformly on $[-\pi,\pi]$. As a result of this, you can always interchange the series with the integral $\int_{-\pi}^{\pi}$.


*Usually, you may not want to assume such strong results. Another common thing we do is to suppose $f\in L^2([-\pi,\pi])$. In this case, $s_{n,f}$ need not converge to $f$ pointwise. However, what is true is that $s_{n,f}\to f$ in the $L^2$ norm; i.e $\lVert s_{n,f} - f \rVert_{L^2([-\pi,\pi])} \to 0$ as $n\to \infty$. So, in this case, if we write something like $f=\sum_{n=-\infty}^{\infty}\hat{f}(n)\phi_n$, then the limit which defines the series must be interpreted as an $L^2$ limit. In this case, for any $g\in L^2([-\pi,\pi])$, we can calculate the integral $\int_{-\pi}^{\pi}fg$ by bringing the series out. You can justify this as follows:
\begin{align}
\int_{-\pi}^{\pi}fg &= \left\langle f, \overline{g} \right\rangle =\left\langle \lim_{n\to \infty}s_{n,f}, \overline{g} \right\rangle = \lim_{n\to \infty}\left\langle s_{n,f}, \overline{g} \right\rangle = \sum_{n=-\infty}^{\infty}\hat{f}(n)\int_{\pi}^{\pi}\phi_n(t)g(t)\, dt,
\end{align}
where I used the fact that the inner product $\langle \cdot, \cdot\rangle$ on $L^2$ is a bilinear bounded function (because of Cauchy Schwarz inequality), or equivalently, it is continuous, so we can pull the limit outside.
Btw, note that if you take the sequence of coefficients to be all $1$, then you do not have convergence in $L^2$ even so that's just a very bad situation. Again, you may want to impose other types of regularity assumptions, in which case you get corresponding results. I obviously haven't written an exhaustive list, but hopefully this points you in the right direction.
A: How about the dominated convergence theorem? If you know the coefficients $a_n$ and $b_n$ decay rapidly enough so that the partial sums $|\sum_{n}^{N} a_n\cos(kx)+b_n\sin(kx)|$ are dominated by an integrable function, then the interchange is legal by dominated convergence. How fast the coefficients decay depends on the smoothness of $f$. For example if $f$ is twice continuously differentiable you can show using integration by parts that the coefficients grow like $\frac{1}{n^2}$. In this case the partial sums are indeed dominated by an $L^1[-\pi,\pi]$ function, namely a constant function.
