I've come cross the following:
Let G be a compact Lie group with Lie algebra $\mathfrak{g}$. For every $f \in C^\infty (\mathfrak{g})$, we denote by $f^G$ the G-invariant function on $\mathfrak{g}$ defined by the equation $$f^G(X):= \int_G f(Ad(g)X)dg, X \in \mathfrak{g},$$ Where dg is the normalized Haar measure on G ($\int_G dg =1$).
I'm wondering why is the function $f^G$ G-invariant ? If the action of the group commutes with the integral then it would be clear that $f^G$ is G-invariant, but why does the group action commutes with the integral ?
This is a very common idea, which is maybe made more obvious if we work with a finite group.
If we have a function $f : \mathbb{R} \to \mathbb{R}$, how can we make it invariant under $G = \langle \sigma \mid \sigma^2 = 1 \rangle$ (which acts on $\mathbb{R}$ by $\sigma x = -x$)?
We might consider the new function
$$ f^G = f(1 \cdot x) + f(\sigma \cdot x) = f(x) + f(-x) $$
and ask if it is $G$-invariant.
Of course, it is. Why? Because
$$ f^G(\sigma x) = f(1 \cdot \sigma \cdot x) + f(\sigma \cdot \sigma \cdot x) = f(\sigma x) + f(1 x) = f^G(x) $$
Notice what happened here: Because we're summing up over the whole orbit of $x$, when we hit the input with some group element we just permute the sum. This is basically because $g \cdot - : G \to G$ is a bijection of our group.
This turns out to work in general. If we want to make a function $G$-invariant (even for large groups $G$) we can sum up over the entire orbit. Then when we wiggle the input by some group element, we just permute the things we're summing.
Now a sum and an integral are more or less the same thing, and so the same argument works if our group admits a finite Haar measure. For instance, when $G$ is compact.
So if we define $f^G(x) = \int_{g \in G} f(gx)$, then we see (taking $h \in G$ too):
$$ f^G(hx) = \int_{g \in G} f(ghx) \overset{(1)}{=} \int_{gh \in G} f(ghx) \overset{(2)}{=} \int_{g' \in G} f(g'x) = f^G(x) $$
In step $(1)$ we've reindexed our integral to use $gh$, which is OK since $-\cdot h$ is a bijection and our measure is right invariant. In step $(2)$ we've just renamed $gh = g'$ to make it more clear that we have something equivalent to $f^G$.
This idea of "averaging" over a group action is an extremely flexible tool, and is worth keeping in mind for future theorems, either for homeworks in a class or indeed in any research you do!
I hope this helps ^_^