Expectation for a function of a discrete random variable This is a bit on the elementary side, but I'm having trouble understanding if the following formula is a definition, or a derivation.
Given that $E[X] = \sum\limits_x xp(x)$, and $g(X)$ is some real-valued function, then $E[g(X)] = \sum\limits_xg(x)p(x)$.
From an intuitive standpoint, this makes perfect sense. Finding the expected value of a function of $X$ is fundamentally no different than finding the expectation for $X$ itself, as the expectation is just the theoretical average of all possible values of $g$.
But is this something that

*

*we define explicitly,

*follows directly from the definition of $E[X]$, or

*something that can be proven to follow from the formula for $E[X]$?

The reason I ask is that I understand $E[X]$ and $E[g(X)]$ in isolation, but I'm having trouble determining if the bridge between them is mathematically provable, or if the latter is just an "obvious" definition.
It also seems that most proofs for properties of expectation (such as linearity; $E[aX + b] = aE[X] +b$) begins with the knowledge that $E[g(X)] = \sum\limits_xg(x)p(x)$ so it's pretty fundamental.

This is not a definition; it is the discrete version of the law of the unconcious statistician.  To derive the law, suppose we start with some discrete random variable $X$ which ranges over the domain $\mathscr{X}$.  Now let $S = g(X)$ be our transformed discrete random variable and let $\mathscr{S} \equiv \{ g(x) | x \in \mathscr{X} \}$ be the domain of this latter random variable.
To facilitate our analysis, define the sets $\mathscr{X}(s) \equiv \{ x \in \mathscr{X} | g(x) = s \}$ for all $s \in \mathscr{S}$.  It is trivial to show that these sets form a partition of the space $\mathscr{X}$ and give:
$$\begin{align}
\mathbb{P}(S=s)
&= \sum_{x \in \mathscr{X}(s)} \mathbb{P}(X=x). \\[6pt]
\end{align}$$
We therefore have:
$$\begin{align}
\mathbb{E}(g(X)) 
&= \mathbb{E}(S) \\[6pt]
&= \sum_{s \in \mathscr{S}} s \cdot \mathbb{P}(S=s) \\[6pt]
&= \sum_{s \in \mathscr{S}} s \sum_{x \in \mathscr{X}(s)} \mathbb{P}(X=x) \\[6pt]
&= \sum_{s \in \mathscr{S}} \sum_{x \in \mathscr{X}(s)} s \cdot \mathbb{P}(X=x) \\[6pt]
&= \sum_{s \in \mathscr{S}} \sum_{x \in \mathscr{X}(s)} g(x) \cdot \mathbb{P}(X=x) \\[6pt]
&= \sum_{x \in \mathscr{X}} g(x) \cdot \mathbb{P}(X=x). \\[6pt]
\end{align}$$
