[step:Construct a greedy independent set attaining the rank upper bound]
Define a sequence of sets $G_0,G_1,\dots,G_m$ as follows. Set $G_0:=\varnothing$. For $1\leq i\leq m$, if $G_{i-1}\cup\{e_i\}\in\mathcal I$, define
\begin{align*}
G_i:=G_{i-1}\cup\{e_i\}.
\end{align*}
If $G_{i-1}\cup\{e_i\}\notin\mathcal I$, define
\begin{align*}
G_i:=G_{i-1}.
\end{align*}
Let $G:=G_m$. By construction and heredity, each $G_i$ is independent, and $G_i\subset S_i$.
We prove by induction on $i$ that
\begin{align*}
|G_i|=r(S_i)
\end{align*}
for every $0\leq i\leq m$. For $i=0$, both sides are $0$. Assume $1\leq i\leq m$ and $|G_{i-1}|=r(S_{i-1})$. Since $S_i=S_{i-1}\cup\{e_i\}$, every independent subset of $S_i$ either avoids $e_i$ and has size at most $r(S_{i-1})$, or contains $e_i$ and becomes an independent subset of $S_{i-1}$ after removing $e_i$, hence has size at most $r(S_{i-1})+1$. Also $S_{i-1}\subset S_i$, so $r(S_i)\geq r(S_{i-1})$. Therefore
\begin{align*}
r(S_i)\in\{r(S_{i-1}),r(S_{i-1})+1\}.
\end{align*}
If $G_{i-1}\cup\{e_i\}\in\mathcal I$, then $G_i=G_{i-1}\cup\{e_i\}$, so
\begin{align*}
|G_i|=|G_{i-1}|+1=r(S_{i-1})+1.
\end{align*}
The independent set $G_i\subset S_i$ has size $r(S_{i-1})+1$, so $r(S_i)\geq r(S_{i-1})+1$, and hence $r(S_i)=r(S_{i-1})+1=|G_i|$.
If $G_{i-1}\cup\{e_i\}\notin\mathcal I$, then $G_i=G_{i-1}$. Suppose, for contradiction, that $r(S_i)=r(S_{i-1})+1$. Then $S_i$ contains an independent subset $B\subset S_i$ with
\begin{align*}
|B|=r(S_{i-1})+1.
\end{align*}
Since $S_i=S_{i-1}\cup\{e_i\}$ and every independent subset of $S_{i-1}$ has size at most $r(S_{i-1})$, the set $B$ must contain $e_i$. By the induction hypothesis, $G_{i-1}$ is independent and has size $r(S_{i-1})$, while $B$ is independent and has size $r(S_{i-1})+1$. The augmentation axiom in the definition of a [matroid](/page/Matroid) applies to the independent sets $G_{i-1}$ and $B$: since $|G_{i-1}|<|B|$, there exists an element
\begin{align*}
b\in B\setminus G_{i-1}
\end{align*}
such that $G_{i-1}\cup\{b\}\in\mathcal I$. If $b\in S_{i-1}$, then $G_{i-1}\cup\{b\}$ would be an independent subset of $S_{i-1}$ of size $r(S_{i-1})+1$, contradicting the definition of $r(S_{i-1})$ as the maximum size of an independent subset of $S_{i-1}$. Therefore $b\notin S_{i-1}$. Since $B\subset S_i=S_{i-1}\cup\{e_i\}$, this forces $b=e_i$. Hence $G_{i-1}\cup\{e_i\}\in\mathcal I$, contradicting the definition of this case. Therefore $r(S_i)=r(S_{i-1})$, and
\begin{align*}
|G_i|=|G_{i-1}|=r(S_{i-1})=r(S_i).
\end{align*}
The induction is complete.
For the final greedy set $G=G_m$, the equality $|G_i|=r(S_i)$ and the inclusion $G_i=G\cap S_i$ imply
\begin{align*}
\sum_{e\in S_i}(\mathbb 1_G)_e=r(S_i)
\end{align*}
for every $1\leq i\leq m$. Substituting $x=\mathbb 1_G$ into the summation-by-parts identity gives
\begin{align*}
\sum_{e\in G}w_e
=
\sum_{i=1}^{m}(w_{e_i}-w_{e_{i+1}})r(S_i).
\end{align*}
Thus the upper bound from the previous step is attained by the independent set $G$.
[/step]