\section{Linear combinations, span, and linear independence}

\begin{outcome}
  \begin{enumerate}
  \item Determine if a vector is within a given span.
  \item Determine if a set is spanning.
  \item Determine if a set is linearly independent.
  \end{enumerate}
\end{outcome}

In this section, we will again explore concepts introduced earlier in terms of $\R^n$ and extend them to apply to abstract vector spaces.

We can now revisit many of the concepts first introduced in
Chapter~\ref{cha:vectors-rn} in the context of general vector spaces.
We will look at linear combinations, span, and linear independence in
this section, and at subspaces, bases, and dimension in the next
section.

\begin{definition}{Linear combination}{linear-combination-vector-space}
  Let $V$ be a vector space over a field $K$. Let
  $\vect{u}_1,\ldots,\vect{u}_n\in V$. A vector
  $\vect{v}\in V$ is called a \textbf{linear combination}%
  \index{linear combination!in a vector space}%
  \index{linear combination!of vectors} of
  $\vect{u}_1,\ldots,\vect{u}_n$ if there exist scalars
  $a_1,\ldots,a_n\in K$ such that
  \begin{equation*}
    \vect{v} = a_1 \vect{u}_1 + \ldots + a_n \vect{u}_n.
  \end{equation*}
\end{definition}

\begin{example}{Linear combination of matrices}{linear-combination-matrix}
  Write the matrix $A=\begin{mymatrix}{rr} 1 & 3 \\ -1 & 2 \end{mymatrix}$
  as a linear combination%
  \index{linear combination!of matrices} of
  \begin{equation*}
    \begin{mymatrix}{rr} 1 & 0 \\ 0 & 1 \end{mymatrix},\quad
    \begin{mymatrix}{rr} 1 & 0 \\ 0 & -1 \end{mymatrix},\quad
    \begin{mymatrix}{rr} 0 & 1 \\ 1 & 0 \end{mymatrix},\quad\mbox{and}\quad
    \begin{mymatrix}{rr} 0 & -1 \\ 1 & 0 \end{mymatrix}.
  \end{equation*}
\end{example}

\begin{solution}
  We must find coefficients $a,b,c,d$ such that
  \begin{equation*}
    \begin{mymatrix}{rr} 1 & 3 \\ -1 & 2 \end{mymatrix}
    ~=~ a \begin{mymatrix}{rr} 1 & 0 \\ 0 & 1 \end{mymatrix}
    + b \begin{mymatrix}{rr} 1 & 0 \\ 0 & -1 \end{mymatrix}
    + c \begin{mymatrix}{rr} 0 & 1 \\ 1 & 0 \end{mymatrix}
    + d \begin{mymatrix}{rr} 0 & -1 \\ 1 & 0 \end{mymatrix},
  \end{equation*}
  or equivalently,
  \begin{equation*}
    \begin{mymatrix}{rr} 1 & 3 \\ -1 & 2 \end{mymatrix}
    ~=~ \begin{mymatrix}{cc} a+b & c-d \\ c+d & a-b \end{mymatrix}.
  \end{equation*}
  This yields a system of four equations in four variables:
  \begin{equation*}
    \begin{array}{r@{~~}c@{~}r}
      a+b &=& 1, \\
      c+d &=& -1, \\
      c-d &=& 3, \\
      a-b &=& 2.
    \end{array}
  \end{equation*}
  We can easily solve the system of equations to find the unique
  solution $a=\frac{3}{2}$, $b=-\frac{1}{2}$, $c=1$, $d=-2$.
  Therefore
  \begin{equation*}
    \begin{mymatrix}{rr} 1 & 3 \\ -1 & 2 \end{mymatrix}
    ~=~ \frac{3}{2} \begin{mymatrix}{rr} 1 & 0 \\ 0 & 1 \end{mymatrix}
    - \frac{1}{2} \begin{mymatrix}{rr} 1 & 0 \\ 0 & -1 \end{mymatrix}
    + 1 \begin{mymatrix}{rr} 0 & 1 \\ 1 & 0 \end{mymatrix}
    - 2 \begin{mymatrix}{rr} 0 & -1 \\ 1 & 0 \end{mymatrix}.
  \end{equation*}
\end{solution}

\begin{example}{Linear combination of polynomials}{linear-combination-polynomials}
  Write the polynomial $p(x) = 7x^2 + 4x - 3$ as a linear combination%
  \index{linear combination!of polynomials} of
  \begin{equation*}
    q_1(x) = x^2,\quad
    q_2(x) = (x+1)^2,\quad\mbox{and}\quad
    q_3(x) = (x+2)^2.
  \end{equation*}
\end{example}

\begin{solution}
  Note that $q_2(x) = (x+1)^2 = x^2 + 2x + 1$ and
  $q_3(x) = (x+2)^2 = x^2 + 4x + 4$. We must find coefficients $a,b,c$
  such that $p(x) = aq_1(x) + bq_2(x) + cq_3(x)$, or equivalently,
  \begin{equation*}
    7x^2 + 4x - 3 ~=~ ax^2 ~+~ b(x^2 + 2x + 1) ~+~ c(x^2 + 4x + 4).
  \end{equation*}
  Collecting equal powers of $x$, we can rewrite this as
  \begin{equation*}
    7x^2 + 4x - 3 ~=~ (a+b+c)x^2 ~+~ (2b+4c)x ~+~ (b+4c).
  \end{equation*}
  Since two polynomials are equal if and only if each corresponding
  coefficient is equal, this yields a system of three equations in
  three variables
  \begin{equation*}
    \begin{array}{r@{~~}c@{~}r}
      a+b+c &=& 7, \\
      2b+4c &=& 4, \\
      b+4c &=& -3.
    \end{array}
  \end{equation*}
  We can easily solve this system of equations and find that the
  unique solution is $a=\frac{5}{2}$, $b=7$,
  $c=-\frac{5}{2}$. Therefore
  \begin{equation*}
    p(x) ~=~ \frac{5}{2}\,q_1(x) ~+~ 7\,q_2(x) ~-~ \frac{5}{2}\,q_3(x).
  \end{equation*}
\end{solution}

As in Chapter~\ref{cha:vectors-rn}, the span of a set of vectors is
defined as the set of all of its linear combinations. We generalize
the concept of span to consider spans of arbitrary (possibly finite,
possibly infinite) sets of vectors.

\begin{definition}{Span of a set of vectors}{vector-space-span}
  Let $V$ be a vector space over some field $K$, and let $S$ be a set
  of vectors (i.e., a subset of $V$). The \textbf{span}%
  \index{span}%
  \index{vector!span}%
  \index{vector space!span} of $S$ is the set of all linear
  combinations of elements of $S$. In symbols, we have
  \begin{equation*}
    \sspan S
    ~=~ \set{a_1\vect{u}_1+\ldots+a_k\vect{u}_k \mid
      \mbox{
        $\vect{u}_1,\ldots,\vect{u}_k\in S$
        and
        $a_1,\ldots,a_k\in K$
      }}.
  \end{equation*}
\end{definition}

It is important not to misunderstand this definition.  Even when the
set $S$ is infinite, each {\em individual} element
$\vect{v}\in\sspan S$ is a linear combination of only {\em finitely
  many} elements $\vect{u}_1,\ldots,\vect{u}_k$ of $S$.
The definition does not talk about infinite linear combinations
\begin{equation*}
  a_1\vect{u}_1 + a_2\vect{u}_2 + a_3\vect{u}_3 + \ldots
\end{equation*}
Indeed, such infinite sums do not typically exist.  However, different
elements $\vect{v},\vect{w}\in\sspan S$ can be linear combinations of
a different (finite) number of vectors of $S$. For example, it is
possible that $\vect{v}$ is a linear combination of 10 elements of
$S$, and $\vect{w}$ is a linear combination of 100 elements of $S$.

\begin{example}{Spans of sequences}{spans-sequences}
  Consider the vector space $\Seq_K$ of infinite sequences. For every
  $k\in\N$, let $e^k$ be the sequence whose $k\th$ element is $1$ and
  that is $0$ everywhere else, i.e.,
  \begin{equation*}
    \begin{array}{l}
      e^0 = (1,0,0,0,0,\ldots), \\
      e^1 = (0,1,0,0,0,\ldots), \\
      e^2 = (0,0,1,0,0,\ldots), \\
    \end{array}
  \end{equation*}
  and so on.
  Let $S=\set{e^k \mid k\in\N}$. Which of the following sequences are in
  $\sspan S$?
  \begin{enumialphparenastyle}
    \begin{enumerate}
    \item $f = (1,1,1,0,0,0,0,0,\ldots)$ (followed by infinitely many zeros),
    \item $g = (1,2,0,5,0,0,0,0,\ldots)$ (followed by infinitely many zeros),
    \item $h = (1,1,1,1,1,1,1,1,\ldots)$ (followed by infinitely many ones),
    \item $k = (1,0,1,0,1,0,1,0,\ldots)$ (forever alternating between $1$ and $0$).
    \end{enumerate}
  \end{enumialphparenastyle}
\end{example}

\begin{solution}
  \begin{enumialphparenastyle}
    \begin{enumerate}
    \item We have $f\in\sspan S$, because $f = e^0 + e^1 + e^2$.
    \item We have $g\in\sspan S$, because $g = 1e^0 + 2e^1 + 5e^3$.
    \item The sequence $h$ is not in $\sspan S$, because each element
      of $\sspan S$ is, by definition, a linear combinations of {\em
        finitely many} elements of $S$. No linear combinations of
      finitely many $e^k$ can end in infinitely many ones. Note that
      we are not permitted to write an infinite sum such as
      $e^0+e^1+e^2+\ldots$. Such infinite sums are not defined in
      vector spaces.
    \item The sequence $k$ is not in $\sspan S$, for the same reason.
      We would need to add infinitely many sequences of the form $e^k$
      to get a sequence that contains infinitely many non-zero
      elements. However, this is not permitted by the definition of
      span.
    \end{enumerate}
  \end{enumialphparenastyle}
  \vspace{-4ex}
\end{solution}

\begin{example}{Span of polynomials}{span-of-polynomials}
  Let $p(x)=7x^2+4x-3$. Is $p(x)\in\sspan\set{x^2,~ (x+1)^2,~ (x+2)^2}$?
\end{example}

\begin{solution}
  The answer is yes, because we found in
  Example~\ref{exa:linear-combination-polynomials} that
  $p(x) = \frac{5}{2}\,x^2 ~+~ 7\,(x+1)^2 ~-~ \frac{5}{2}\,(x+2)^2$.
\end{solution}

We say that a set of vectors $S$ is a \textbf{spanning set}%
\index{spanning set}%
\index{vector space!spanning set} for $V$ if $V = \sspan S$.

\begin{example}{Spanning set}{spanning-set}
  Let $S = \set{x^2,~ (x+1)^2,~ (x+2)^2}$. Show that $S$ is a
  spanning set for $\Poly_2$, the vector space of all polynomials of
  degree at most $2$.
\end{example}

\begin{solution}
  This is analogous to Example~\ref{exa:linear-combination-polynomials}.
  Consider an arbitrary element $p(x) = p_2x^2 + p^1x + p_0$ of
  $\Poly_2$. We must show that $p(x)\in\sspan S$, i.e., that there
  exists $a,b,c\in K$ such that
  \begin{equation*}
    p(x) = ax^2 + b(x+1)^2 + c(x+2)^2.
  \end{equation*}
  We can equivalently rewrite this equation as
  \begin{equation*}
    p_2x^2 + p^1x + p_0 ~=~ (a+b+c)x^2 ~+~ (2b+4c)x ~+~ (b+4c),
  \end{equation*}
  which yields the system of equations
  \begin{equation*}
    \begin{array}{r@{~~}c@{~}r}
      a+b+c &=& p_2 \\
      2b+4c &=& p_1 \\
      b+4c &=& p_0
    \end{array}
    \quad\roweq\quad
    \begin{mymatrix}{ccc|c}
      1 & 1 & 1 & p_2 \\
      0 & 2 & 4 & p_1 \\
      0 & 1 & 4 & p_0 \\
    \end{mymatrix}
    \quad\roweq\quad
    \begin{mymatrix}{ccc|c}
      1 & 0 & 0 & p_2-\frac{3}{4}p_1+\frac{1}{2}p_0 \\
      0 & 1 & 0 & p_1-p_0 \\
      0 & 0 & 1 & \frac{1}{2}p_0-\frac{1}{4}p_1 \\
    \end{mymatrix}.
  \end{equation*}
  Since the system has rank 3, it has a solution. Therefore,
  $p(x)\in\sspan S$. Since $p(x)$ was an arbitrary element of
  $\Poly_2$, it follows that $S$ is a spanning set for $\Poly_2$.
\end{solution}

To define the concept of linear independence in a general vector
space, it will be convenient to base our definition on the
``alternative'' characterization of
Theorem~\ref{thm:characterization-linear-independence}. Here too, we
generalize the definition to an arbitrary (finite or infinite) set of
vectors.

\begin{definition}{Linear independence}{linear-independence-vector-space}
  Let $V$ be a vector space over some field $K$. A finite set of
  vectors $\set{\vect{u}_1,\ldots,\vect{u}_k}$ is called
  \textbf{linearly independent}%
  \index{linear independence!in a vector space}%
  \index{vector!linearly independent!in a vector space}%
  \index{vector space!linear independence}
  if the equation
  \begin{equation*}
    a_1\,\vect{u}_1 + \ldots + a_k\,\vect{u}_k = \vect{0}
  \end{equation*}
  has only the trivial solution $a_1,\ldots,a_k=0$. An infinite set
  $S$ of vectors is called linearly independent if every finite subset
  of $S$ is linearly independent. A set of vectors is called
  \textbf{linearly dependent}%
  \index{linear dependence}%
  \index{vector!linearly dependent}if it is not linearly independent.
\end{definition}

\begin{example}{Linearly independent polynomials}{linear-independence-polynomial}
  Determine whether the polynomials $x^2$, $x^2 + 2x - 1$, and
  $2x^2 - x + 3$ are linearly independent.
\end{example}

\begin{solution}
  According to the definition of linear independence, we must solve
  the equation
  \begin{equation*}
    ax^2 + b(x^2 + 2x - 1) + c(2x^2 - x + 3) ~=~ 0.
  \end{equation*}
  If there is a non-trivial solution, the polynomials are linearly
  dependent. If there is only the trivial solution, they are linearly
  independent. We first rearrange the left-hand side to collect equal
  powers of $x$:
  \begin{equation*}
    (a + b + 2c)x^2 + (2b - c)x + (3c - b) ~=~ 0.
  \end{equation*}
  This turns into a system of 3 equations in 3 variables:
  \begin{equation*}
    \begin{array}{rcl}
      a + b + 2c &=& 0 \\
      2b - c &=& 0 \\
      3c - b &=& 0
    \end{array}
    \quad\roweq\quad
    \begin{mymatrix}{rrr|r}
      1 &  1 &  2 & 0 \\
      0 &  2 & -1 & 0 \\
      0 & -1 &  3 & 0
    \end{mymatrix}
    \quad\roweq\quad
    \begin{mymatrix}{rrr|r}
      1 &  0 &  0 & 0 \\
      0 &  1 &  0 & 0 \\
      0 &  0 &  1 & 0
    \end{mymatrix}.
  \end{equation*}
  Since the system has rank 3, there are no free variables. The only
  solution is $a=b=c=0$, and the polynomials are linearly
  independent.
\end{solution}

\begin{example}{Linearly independent sequences}{linear-independence-sequences}
  Let $K$ be a field, and consider again the sequences from
  Example~\ref{exa:spans-sequences},
    \begin{equation*}
    \begin{array}{l}
      e^0 = (1,0,0,0,0,\ldots), \\
      e^1 = (0,1,0,0,0,\ldots), \\
      e^2 = (0,0,1,0,0,\ldots), \\
    \end{array}
  \end{equation*}
  and so on. Let $S=\set{e^0, e^1, e^2,\ldots}$. This is an infinite
  subset of $\Seq_K$. Show that $S$ is linearly independent.
\end{example}

\begin{solution}
  Since $S$ is an infinite set, we have to show that every finite
  subset of $S$ is linearly independent. So consider a finite subset
  \begin{equation*}
    \set{e^{k_1}, e^{k_2}, \ldots, e^{k_n}} \subseteq S
  \end{equation*}
  and assume that
  \begin{equation}\label{eqn:linear-independence-sequences}
    a_1e^{k_1} + a_2e^{k_2} + \ldots + a_ne^{k_n} = 0.
  \end{equation}
  We have to show that $a_1,\ldots,a_n=0$. Consider some index
  $i\in\set{1,\ldots,n}$. Then the $k_i\th$ element of
  $a_1e^{k_1} + \ldots + a_ne^{k_n}$ is equal to $a_i$ by the
  left-hand side of {\eqref{eqn:linear-independence-sequences}}, but
  it is also equal to $0$ by the right-hand side of
  {\eqref{eqn:linear-independence-sequences}}. It follows that $a_i=0$
  for all $i\in\set{1,\ldots,n}$, and therefore
  $\set{e^{k_1}, e^{k_2}, \ldots, e^{k_n}}$ is linearly
  independent. Since $\set{e^{k_1}, e^{k_2}, \ldots, e^{k_n}}$ was an
  arbitrary finite subset of $S$, it follows, by definition, that $S$
  is linearly independent.
\end{solution}

\begin{example}{Linearly dependent matrices}{linearly-dependent-matrices}
  Determine whether the following elements of $\Mat_{m,n}$ are
  linearly independent:
  \begin{equation*}
    M_1 = \begin{mymatrix}{rr} -1 & 0 \\ 1 & -1 \end{mymatrix},\quad
    M_2 = \begin{mymatrix}{rr}  1 & 1 \\ 1 &  2 \end{mymatrix},\quad
    M_3 = \begin{mymatrix}{rr}  1 & 3 \\ 5 &  4 \end{mymatrix}.
  \end{equation*}
\end{example}

\begin{solution}
  To determine whether $\set{M_1,M_2,M_3}$ is linearly independent, we
  look for solutions to
  \begin{equation*}
    aM_1 + bM_2 + cM_3 = 0.
  \end{equation*}
  Notice that this equation has non-trivial solutions, for example
  $a=2$, $b=3$ and $c=-1$. Therefore the matrices are linearly
  dependent.
\end{solution}

\begin{example}{Linearly independent functions}{linearly-independent-functions}
  In the vector space $\Func_{\R,\R}$ of real-valued functions on the
  real numbers, show that the functions $f(x)=\sin x$ and $g(x)=\cos
  x$ are linearly independent.
\end{example}

\begin{solution}
  Assume $A\sin x+B\cos x=0$. Note that this is an equality of
  functions, which means that it is true for all $x$. In particular,
  substituting $x=0$ into the equation, and using the fact that
  $\sin 0=0$ and $\cos 0=1$, we have
  \begin{equation*}
    0 = A\sin 0 + B\cos 0 = A\cdot 0 + B\cdot 1 = B,
  \end{equation*}
  and therefore $B=0$. On the other hand, substituting
  $x=\frac{\pi}{2}$ into the equation, and using the fact that
  $\sin\frac{\pi}{2} = 1$ and $\cos\frac{\pi}{2}=0$, we have
  \begin{equation*}
    0 = A\sin\frac{\pi}{2} + B\cos\frac{\pi}{2} = A\cdot 1 + B\cdot 0
    = A,
  \end{equation*}
  and therefore $A=0$. Therefore, the equation $A\sin x+B\cos x=0$
  only has the trivial solution $A=B=0$, and it follows that $\sin x$
  and $\cos x$ are linearly independent.
\end{solution}

The properties of linear independence that were discussed in
Chapter~\ref{cha:vectors-rn} remain true in the general setting of
vector spaces. For example, the first two parts of
Proposition~\ref{prop:properties-linear-independence} apply without change.
(The third part specifically mentions $\R^n$, but can be generalized
to any vector space of dimension $n$). We also have the usual
characterization of linear dependence in terms of redundant vectors:

\begin{proposition}{Linear dependence and redundant vectors}{linear-dependence-redundant}
  Let $V$ be a vector space, and let $\vect{u}_1,\vect{u}_2,\ldots$ be
  a (finite or infinite) sequence of vectors in $V$. If
  $\vect{u}_1,\vect{u}_2,\ldots$ are linearly dependent, then at least
  one of the vectors can be written as a linear combination of earlier
  vectors in the sequence:
  \begin{equation*}
    \vect{u}_j = a_1\,\vect{u}_1 + a_2\,\vect{u}_2 + \ldots + a_{j-1}\,\vect{u}_{j-1},
  \end{equation*}
  for some $j$.
\end{proposition}

\begin{proof}
  Suppose that the vectors are linearly dependent. Then the equation
  $b_1\vect{u}_1+\ldots+b_k\vect{u}_k=\vect{0}$ has a non-trivial solution
  for some $k$. In other words, there exist scalars $b_1,\ldots,b_k$,
  not all equal to zero, such that
  $b_1\vect{u}_1+\ldots+b_k\vect{u}_k=\vect{0}$. Let $j$ be the largest index
  such that $b_j\neq 0$. Then
  $b_1\vect{u}_1+\ldots+b_j\vect{u}_j=\vect{0}$. Dividing by $b_j$ and
  solving for $\vect{u}_j$, we have
  $\vect{u}_j = -\frac{b_1}{b_j}\vect{u}_1 - \ldots -
  \frac{b_{j-1}}{b_j}\vect{u}_{j-1}$, so $\vect{u}_j$ can be written
  as a linear combination of earlier vectors as claimed.
\end{proof}

\begin{example}{Polynomials of increasing degree}{polynomials-increasing-degree}
  Consider a sequence of non-zero polynomials $p_1(x), \ldots, p_k(x)$
  of increasing degree, i.e., such that the degree of each $p_i(x)$ is
  strictly larger than that of $p_{i-1}(x)$. Show that
  $p_1(x),\ldots,p_k(x)$ are linearly independent in the vector space
  $\Poly$.
\end{example}

\begin{solution}
  A polynomial of degree $n$ cannot be a linear combination of
  polynomials of degree less than $n$. Therefore, none of the
  polynomials $p_1(x), \ldots, p_k(x)$ can be written as a linear
  combination of earlier polynomials. By
  Proposition~\ref{prop:linear-dependence-redundant}, $p_1(x), \ldots,
  p_k(x)$ are linearly independent.
\end{solution}

Theorems~\ref{thm:unique-linear-combination} and
{\ref{thm:linearly-independent-subset}} also remain true in the
setting of general vector spaces. The original proofs can be used
without change. Thus, if $\vect{u}_1,\ldots,\vect{u}_k$ are linearly
independent, then every vector
$\vect{v}\in\sspan\set{\vect{u}_1,\ldots,\vect{u}_k}$ can be uniquely
written as a linear combination of
$\vect{u}_1,\ldots,\vect{u}_k$. Also, given any finite set of vectors,
we can find a subset of the vectors that is linearly independent and
has the same span.

We finish this section with a useful observation about linear
independence. Namely, given a linearly independent set of vectors and
one more vector that is not in their span, then we can add the vector
to the set and it will remain linearly independent.

\begin{proposition}{Adding to a linearly independent set}{adding-linearly-independent}
  Suppose $\set{\vect{u}_1,\ldots,\vect{u}_k}$ is linearly
  independent and
  $\vect{v}\notin \sspan\set{\vect{u}_1,\ldots,\vect{u}_k}$. Then
  the set
  \begin{equation*}
    \set{\vect{u}_1,\ldots,\vect{u}_k,\vect{v}}
  \end{equation*}
  is also linearly independent.
\end{proposition}

\begin{proof}
  Assume, on the contrary, that the set were linearly dependent. Then
  by Proposition~\ref{prop:linear-dependence-redundant}, one of the
  vectors can be written as a linear combination of earlier vectors.
  This vector cannot be one of the $\vect{u}_i$, because
  $\vect{u}_1,\ldots,\vect{u}_k$ are linearly independent.  It
  also cannot be $\vect{v}$, because
  $\vect{v}\notin
  \sspan\set{\vect{u}_1,\ldots,\vect{u}_k}$. Therefore, our
  assumption cannot be true, and the set is linearly independent.
\end{proof}


\section{Introduction}
\begin{theorem}
    Let $F,f:[a,b]\to\mathbb R$ are continuous and $F$ differentiable with $F^\prime=f$, we have
    $$\int_a^bf(t)\,\mathrm dt=F(b)-F(a)$$
\end{theorem}
There is a reason why this theorem takes so long to prove.
First of all obvious we need to actually define what we meant by all those terms in there and link them together.
More subtlely, this is a theorem about the real numbers.
Suppose $F^\prime=f=G^\prime$, then $F$ and $G$ can be differed by a constant.
So if we set
$$F(x)=\begin{cases}
    1\text{, if $x^2>2$}\\
    0\text{, otherwise}
\end{cases}$$
and $G\equiv 0$.
So $F$ is differentiable at every rational number and those derivatives are $0$, and so is $G$, but $F$ is not constant.
Hence the theorem is simply not true for rational numbers, so we must use properties of real numbers.\\
These are what real analysis (in a beginner's level) is going to be about.


\documentclass[inequalities.tex]{subfile}

\begin{document}
	\chapter{Practice Problems}\label{ch:practice}

	We will pose various types of problems here. The problems will not be sorted in any particular order. There will be no categorization and similar problems will not be put together. We did not provide practice problems per section or chapter because in real contest, you will have no way of knowing what technique or theorem to use. This is why we demonstrated some problems while discussing a particular concept but did not add any extra problems. Here, you are free to use any method necessary to solve the problems.
		\begin{problem}
			Let $a,b,c$ be positive real numbers. Prove that
				\begin{align*}
					(a^{3}+2)(b^{3}+2)(c^{3}+2)
						& \geq (a+b+c)^{3}
				\end{align*}

				\begin{solution}
					Rearrange the inequality as
						\begin{align*}
							(a^{3}+1^{3}+1^{3})^{\frac{1}{3}}(1^{3}+b^{3}+1^{3})^{\frac{1}{3}}(1^{3}+1^{3}+c^{3})^{\frac{1}{3}}
								& \geq \left(a^{3}1^{3}1^{3}\right)^{\frac{1}{3}}+\left(1^{3}b^{3}1^{3}\right)^{\frac{1}{3}}+\left(1^{3}1^{3}c^{3}\right)^{\frac{1}{3}}
						\end{align*}
					which is obviously true by \nameref{thm:holdergen}.
				\end{solution}
		\end{problem}

		\begin{problem}
			Let $a,b$ be positive real numbers such that $a+b=1$. Prove that
				\begin{align*}
					\dfrac{1}{a^{2}}+\dfrac{1}{b^{2}}
						& \geq 8
				\end{align*}

				\begin{solution}
					Using \nameref{thm:holdergen} on $(a+b),(a+b),\left(\frac{1}{a^{2}}+\frac{1}{b^{2}}\right)$,
						\begin{align*}
							(a+b)^{\frac{1}{3}}(a+b)^{\frac{1}{3}}\left(\dfrac{1}{a^{2}}+\dfrac{1}{b^{2}}\right)^{\frac{1}{3}}
								& \geq \left(a\cdot a\cdot\dfrac{1}{a^{2}}\right)^{\frac{1}{3}}+\left(b\cdot b\cdot\dfrac{1}{b^{2}}\right)^{\frac{1}{3}}
						\end{align*}
				\end{solution}
		\end{problem}

		\begin{problem}
			Let $a,b,c$ be positive real numbers such that $a+b+c=1$. Prove that
				\begin{align*}
					4a^{3}+9b^{3}+36c^{3}
						& \geq 1
				\end{align*}
			Notice that $4,9,36$ are square numbers while $a+b+c$ is also $1$. This along with the terms like $4a^{3}$ tells us to somehow cancel the factors $4,9,36$ so that we can use the fact that
				\begin{align*}
					\left(a^{3}\right)^{\frac{1}{3}}+\left(b^{3}\right)^{\frac{1}{3}}+\left(c^{3}\right)^{\frac{1}{3}}
						& = 1
				\end{align*}
			Fortunately, we also have $\frac{1}{2}+\frac{1}{3}+\frac{1}{6}=1$ so using \nameref{thm:holdergen},
				\begin{align*}
					\left(\dfrac{1}{2}+\dfrac{1}{3}+\dfrac{1}{6}\right)^{\frac{1}{3}}\left(\dfrac{1}{2}+\dfrac{1}{3}+\dfrac{1}{6}\right)^{\frac{1}{3}}\left(4a^{3}+9b^{3}+36c^{3}\right)^{\frac{1}{3}}
						& \geq\\ \left(\dfrac{1}{2}\cdot\dfrac{1}{2}\cdot4a^{3}\right)^{\frac{1}{3}}+\left(\dfrac{1}{3}\cdot\dfrac{1}{3}\cdot9b^{3}\right)^{\frac{1}{3}}+\left(\dfrac{1}{6}\cdot\dfrac{1}{6}\cdot36c^{3}\right)^{\frac{1}{3}}
				\end{align*}
			This proves the claim.
		\end{problem}
\end{document}


\appendix

\section{Baseline methods}
\subsection{Geweke test}
The Geweke test \citep{geweke_getting_2004} compares (estimates of) the expectations of hand-picked features (\emph{test functions}) under both the forward and backward joints.
Specifically, let $g: \mathcal{Y}\times \Theta\to \mathbb{R}$ denote a test function, and let  $S_f=\{(y_i, \theta_i)\}_{i=1}^n$ be samples from the forward joint and $S_b=\{(\tilde{y}_i, \tilde{\theta}_i)\}_{i=1}^n$ be ones from the backward joint.
Then, the z-score
% $\sqrt{n}(\hat{\bar{g}} - \hat{\tilde{g}})/\sqrt{\hat{\sigma^{2}}+\hat{\tilde{\sigma}}^{2}}$
\begin{equation}
    \frac{\bar{g}(S_f) - \bar{g}(S_b)}{\sqrt{ \frac{\hat{\sigma}^{2}}{N} + \frac{\hat{\tilde{\sigma}}^{2}}{N}}}
    % \xrightarrow[]{d} \mathcal{N}(0, 1)
    \label{eq:geweke}
\end{equation}
asymptotically follows the standard Gaussian if $\tilde{\pi}(\theta\given y)=\pi(\theta\given y)$, where $\bar{g}(S) = \frac{1}{n}\sum_{(y,\theta) \in S}g(y, \theta)$ and $\hat{\sigma}, \hat{\tilde{\sigma}}$ are estimated variances.
The width of the window estimator $\hat{\tilde{\sigma}}$ can be set to account for the serial dependence in the backward joint samples.

% \subsection{\cite{talts_validating_2018}}
% % \cite{talts_validating_2018} take a similar approach under the assumption that the posterior is absolutely continuous.
% The authors draw samples using the BC algorithm, then compute univariate rank statistics of a draw from the prior among the thinned, approximately independent posterior samples; if there is no error, the rank statistics should be discretely uniformly distributed.
% The authors suggest examining histograms of the rank statistics to better understand errors rather than conducting a formal test.

\subsection{Rank statistic approach of \cite{gandy_unit_2020}}
The rank test from \cite{gandy_unit_2020} requires reversibility of the MCMC sampler. It draws a sample $\theta_{l}$ from the prior, with the associated index $l$ drawn uniformly from $\{1,\ldots,\tilde{L}\}$. The sampler is then run forward and backward to generate samples $\theta_{1}, \ldots, \theta_{l-1}$ and $\theta_{l+1}, \ldots, \theta_{\tilde{L}} $. Under the null, the rank statistic of $\theta_{l}$ among the other samples should be uniformly distributed; after many repeated simulations, this is verified using a $\chi^{2}$ test.

\section{Experiment details}
\subsection{Experiment 1}
\subsubsection{Effect of sampler mixing speed}
\label{appendix:ex1a}
\begin{figure}[H]
    \centering
    \includegraphics[width=\textwidth]{figures/results_1a.png}
    \caption{Experiment 1 type-I/II error rates against $\sigma_{\epsilon}$, over 1000 trials with a sample size of 250. As $\sigma_{\epsilon}$ increases, autocorrelation in the Gibbs sampler decreases and mixing speed increases. We use the thinning size $t=5$ for the SC simulator, and take $L=500$ burn-in steps for both the SC and BC simulators. For the Rank test, each rank statistic is calculated using a chain of length $\tilde{L}=5$.}
    \label{fig:ex1a}
\end{figure}

\subsubsection{Effect of varying BC simulator burn-in}
\begin{figure}[H]
    \centering
    \includegraphics[width=\textwidth]{figures/results_1b.png}
    \caption{Experiment 1 type-I/II error rates over 1000 trials for different burn-in sizes $L$. The top panels use the likelihood- and prior-augmented test functions and the bottom panels use the baseline as discussed in the text. We set $\sigma_{\epsilon}^{2}=0.1$. Type-II error rates fall as $L$ increases.}
    \label{fig:ex2b}
\end{figure}

\subsection{Experiment 2: Reversible Jump Sampler Implementation}
\label{appendix:ex2}
The prior is defined by
\begin{equation}
  \pi(\theta|\lambda, \tau, a, b ) = p(\ell|\lambda) p(\mathbf{\gamma}|\ell) p(\sigma^{2} | a, b) \prod_{j} p(\beta_{j} | \tau, \gamma),
\end{equation}
where
\begin{equation}
  p(\ell|\lambda) = \frac{\exp{(-\lambda)} \lambda^{\ell}}{C\ell!}, \quad \ell \in \{1,\ldots, p\}
\end{equation}
\begin{equation}
  p(\mathbf{\gamma}|\ell) \propto {d\choose \ell}^{-1}
\end{equation}
\begin{equation}
  p(\beta_{j} | \tau, \gamma ) = \begin{cases} (2\tau)^{-1}\exp(-\frac{|\beta_{j}|}{\tau}) & j \in \mathbf{\gamma} \\ \delta(\beta_{j}) & \text{otherwise} \end{cases}
\end{equation}
\begin{equation}
    p(\sigma^{2} | a, b) = \frac{b^{a}}{\Gamma(a)} (\sigma^{2})^{-a-1} \exp{\left(-\frac{b}{\sigma^{2}}\right)}.
\end{equation}
$C$ is a normalization constant, $\delta$ is the Dirac delta function, and $\mathbf{\gamma}$ is a vector of the nonzero indices of $\beta$.
The likelihood is given by
\begin{equation}
  p(y | \sigma, \beta, X ) = (2\pi)^{-\frac{n}{2}} \sigma^{-n} \exp{\left(-\frac{\Vert y-X\beta\Vert^{2}_{2}}{2\sigma^{2}}\right)}.
\end{equation}
The joint probability is then
\begin{equation}
    \begin{aligned}
         p(y, \theta | X, \lambda, \tau, a, b ) \propto &\sigma^{-n} \exp{\left(-\frac{\Vert  y-X\beta\Vert^{2}_{2}}{2\sigma^{2}}\right)} \times \\
         & \frac{\exp{(-\lambda)} \lambda^{\ell}}{\ell!} {d\choose \ell}^{-1} \prod_{j\in \mathbf{\gamma}} (2\tau)^{-1}\exp\left(-\frac{|\beta_{j}|}{\tau}\right) \prod_{j' \notin \mathbf{\gamma}} \delta(\beta_{j'}) \frac{b^{a}}{\Gamma(a)} (\sigma^{2})^{-a-1} \exp{\left(-\frac{b}{\sigma^{2}}\right)}.
    \end{aligned}
    \label{eq:ex2_joint}
\end{equation}

Each iteration of the reversible-jump MCMC posterior sampler takes two steps in random order. A Gibbs step updates $\sigma^{2}$. By conjugacy,
\begin{equation}
    \sigma^{2} | y, X, \beta \sim \mathcal{IG}\left(a + \frac{n}{2}, b + \frac{\sum_{i=1}^{n}(y_{i}-x_{i}\beta)^{2} }{2}\right),
\end{equation}
where $x_{i}$ denotes row $i$ of $X$.

The other step is a reversible jump. We start by proposing $\ell' \in \{\ell-1, \ell, \ell+1\}$ uniformly at random, disallowing $\ell<1$ and $\ell>p$. Thus, when $\ell \in \{1,p\}$, there are only two valid proposals, not three. Then, depending on the $\ell'$ proposed, we complete the proposal $\tilde{\theta}$ via one of the following
\begin{itemize}
    \item Update: $\ell' = \ell$
    \begin{enumerate}
        \item Choose $j \in \{1, \ldots, \ell\}$ uniformly at random
        \item Propose $\mathbf{\gamma}' = \mathbf{\gamma}, \beta'_{j} = \beta_{j} + \mathcal{N}(0, \epsilon_{\text{update}}), \beta'_{i \neq j} = \beta_{i}$
        \item $P(\tilde{\theta} \rightarrow \theta) = P(\theta \rightarrow \tilde{\theta})=\mathcal{N}(\beta_{j}'; \beta_{j},\epsilon_{\text{update}})=\mathcal{N}(\beta_{j}; \beta_{j}',\epsilon_{\text{update}})$
    \end{enumerate}
\end{itemize}

\begin{itemize}
    \item Birth: $\ell' = \ell+1$
    \begin{enumerate}
        \item Choose $j \in \{\ell+1, \ldots, p\}$ uniformly at random
        \item Propose $\mathbf{\gamma}' = \mathbf{\gamma} \cup j$
        \item Propose $\beta'_{j} = \mathcal{N}(0, \epsilon_{\text{birth}}), \beta'_{i \neq j} = \beta_{i}$
        \item $p(\tilde{\theta} \rightarrow \theta) = \begin{cases}\frac{1}{2}\frac{1}{\ell'} & \ell'=p \\ \frac{1}{3} \frac{1}{\ell'} & 1<\ell<p \end{cases} $
        \item $p(\theta \rightarrow \tilde{\theta}) = \begin{cases}\frac{1}{2}\frac{1}{p-\ell} \mathcal{N}(\beta_{j}'; 0,\epsilon_{\text{birth}}) & \ell=1 \\ \frac{1}{3} \frac{1}{p-\ell} \mathcal{N}(\beta_{j}'; 0,\epsilon_{\text{birth}}) & 1<\ell<p \end{cases} $
    \end{enumerate}
\end{itemize}

\begin{itemize}
    \item Death: $\ell' = \ell-1$
    \begin{enumerate}
        \item Choose $j \in \{1, \ldots, \ell\}$ uniformly at random
        \item Propose $\mathbf{\gamma}' = \mathbf{\gamma} \setminus j$
        \item Propose $\beta'_{j} = 0, \beta'_{i \neq j} = \beta_{i}$
        \item $p(\tilde{\theta} \rightarrow \theta) = \begin{cases}\frac{1}{2}\frac{1}{p-\ell'} \mathcal{N}(\beta_{j}; 0,\epsilon_{\text{birth}}) & k'=1 \\ \frac{1}{3} \frac{1}{p-\ell'} \mathcal{N}(\beta_{j}; 0,\epsilon_{\text{birth}}) & 1<\ell'<p \end{cases} $
        \item $p(\theta \rightarrow \tilde{\theta}) = \begin{cases}\frac{1}{2}\frac{1}{\ell} & \ell=p \\ \frac{1}{3} \frac{1}{\ell} & 1<\ell<p \end{cases} $
    \end{enumerate}
\end{itemize}
for random walk sizes $\epsilon_{\text{update}}, \epsilon_{\text{birth}}$.

We accept the birth-death proposal $\tilde{\theta}$ with probability
\begin{equation}
    A(\tilde{\theta}|\theta) = \min{\left(\frac{p(y, \tilde{\theta} |  X,  \lambda, \tau, a, b  )}{p(y, \theta |  X, \lambda, \tau, a, b  )} \frac{p(\tilde{\theta} \rightarrow \theta)}{p(\theta \rightarrow \tilde{\theta})}, 1\right)}.
\end{equation}


\subsection{Nonsmooth derivatives}\label{subsec:nonsmooth_derivatives}

\begin{remark}\label{rem:nonsmooth_analysis}
  Nonsmooth analysis studies generalized differentiability for functions which are not necessarily differentible. The generalized derivatives (see \fullref{subsec:nonsmooth_derivatives}) are not linear, which motivates the study of subdifferentials (see \fullref{subsec:subdifferentials}).

  Both optimization in Euclidean spaces and infinite-dimensional optimization studies (not necessarily linear) real-valued functionals. Hence, we are only concerned with studying real-valued topological vector spaces.
\end{remark}

\begin{remark}\label{rem:nonsmooth_differentiability}
  Unlike in \fullref{def:differentiability}, we do not introduce terminology for differentiability because actual differentiability refers to linear approximations of \( f: U \to Y \) with some consistency properties. We will say that \enquote{\( f \) has a Clarke derivative at \( x_0 \) in the direction \( h \)} rather than \enquote{\( f \) is Clarke differentiable at \( x_0 \) in the direction \( h \)}.
\end{remark}

\begin{definition}\label{def:nonsmooth_derivatives}
  Let \( X \) be a real Hausdorff \hyperref[def:topological_vector_space]{topological vector spaces} and let \( U \subseteq X \) be an open set.

  We fix a point \( x_0 \in U \) and a direction \( h \in X \).

  \begin{thmenum}
    \thmitem{def:nonsmooth_derivatives/directional}\Fullref{def:differentiability} already introduced directional derivatives. Here we introduce a special notation for them:
    \begin{equation*}
      D_h^+ f(x_0) = f_+'(x_0)(h) \coloneqq \lim_{t \downarrow 0} \frac {f(x_0 + th) - f(x_0)} t.
    \end{equation*}

    \thmitem{def:nonsmooth_derivatives/dini}\cite[definition 11.18]{Clarke2013} The upper (resp. lower) \term{Dini derivative} is defined as
    \begin{balign*}
      \overline{D}_h f(x_0) = \overline{f'}(x_0)(h) & \coloneqq \limsup_{t \downarrow 0} \frac {f(x_0 + th) - f(x_0)} t
      \\
      \underline{D}_h f(x_0) = \underline{f'}(x_0)(h) & \coloneqq \liminf_{t \downarrow 0} \frac {f(x_0 + th) - f(x_0)} t
    \end{balign*}

    Dini derivatives are useful when the difference quotients are bounded, but do not have a limit.

    \thmitem{def:nonsmooth_derivatives/clarke}\cite[section 10.1]{Clarke2013} The \term{generalized Clarke derivative} is defined as
    \begin{equation*}
      D_h^\circ f(x_0)
      =
      f^\circ(x_0)(h)
      \coloneqq
      \limsup_{\substack{y \to x_0 \\ t \downarrow 0}} \frac {f(y + th) - f(y)} t.
    \end{equation*}

    Refer to \fullref{subsec:clarke_gradients} for their usefulness.
  \end{thmenum}
\end{definition}


% This is part of the TFTB Reference Manual.
% Copyright (C) 1996 CNRS (France) and Rice University (US).
% See the file refguide.tex for copying conditions.

\markright{tfrrmsc}
\section*{\hspace*{-1.6cm} tfrrmsc}

\vspace*{-.4cm}
\hspace*{-1.6cm}\rule[0in]{16.5cm}{.02cm}
\vspace*{.2cm}

{\bf \large \sf Purpose}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
Reassigned Morlet Scalogram time-frequency distribution.
\end{minipage}
\vspace*{.2cm}

{\bf \large \sf Synopsis}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
\begin{verbatim}
[tfr,rtfr,hat] = tfrrmsc(x)
[tfr,rtfr,hat] = tfrrmsc(x,t)
[tfr,rtfr,hat] = tfrrmsc(x,t,N)
[tfr,rtfr,hat] = tfrrmsc(x,t,N,f0t)
[tfr,rtfr,hat] = tfrrmsc(x,t,N,f0t,trace)
\end{verbatim}
\end{minipage}
\vspace*{.5cm}

{\bf \large \sf Description}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
	{\ty tfrrmsc} computes the Morlet scalogram and its reassigned
        version. The reassigned Morlet scalogram has the following
        expression, where $h(t)$ is a gaussian window :
\begin{eqnarray*}
\hspace*{-.2cm}SC_x^{(r)}(t',a';h)=\iint_{-\infty}^{+\infty} {a'}^2\
SC_x(t,a;h)\ \delta(t'-\hat{t}(x;t,a))\ \delta(a'-\hat{a}(x;t,a))\
\dfrac{dt\ da}{a^2},
\end{eqnarray*}
where
\begin{eqnarray*}
\hat{t}(x;t,a)=t-\Re\left\{a\ \dfrac{T_x(t,a;\ens{T}_h)\ T_x^*(t,a;h)}
{|T_x(t,a;h)|^2}\right\} \\
\hat{\nu}(x;t,a)=\dfrac{\nu_0}{\hat{a}(x;t,a)}=\dfrac{\nu_0}{a} +
\Im\left\{\dfrac{T_x(t,a;\ens{D}_h)\ T_x^*(t,a;h)}{2\pi a\
|T_x(t,a;h)|^2}\right\}
\end{eqnarray*}
with $\ens{T}_h(t)=t\ h(t)$ and $\ens{D}_h(t)=\frac{dh}{dt}(t)$. $SC_x(t,a;h)$ denotes
the scalogram and $T_x(t,a;h)$ the wavelet transform :
\[SC_x(t,a;h)=\left|T_x(t,a;h)\right|^2=\frac{1}{|a|}\ \left|\int_{-\infty}^{+\infty}
x(s)\ h^*\left(\dfrac{s-t}{a}\right)\ ds\right|^2.\]

\hspace*{-.5cm}\begin{tabular*}{14cm}{p{1.5cm} p{8cm} c}
Name & Description & Default value\\
\hline
        {\ty x}     & analyzed signal ({\ty Nx=length(x)})\\
        {\ty t}     & the time instant(s)           & {\ty (1:Nx)}\\
        {\ty N}     & number of frequency bins      & {\ty Nx}\\
        {\ty f0t}   & time-bandwidth product of the mother wavelet
                                              & {\ty 2.5}\\
        {\ty trace} & if nonzero, the progression of the algorithm is shown
                                              & {\ty 0}\\
\hline \end{tabular*} \end{minipage}

\newpage

\hspace*{1.5cm} \begin{minipage}[t]{13.5cm}
\hspace*{-.5cm}\begin{tabular*}{14cm}{p{1.5cm} p{8cm} c}
Name & Description & Default value\\ \hline
        {\ty tfr, rtfr}  & time-frequency representation and its reassigned
            version\\
        {\ty hat}   & complex matrix of the reassignment vectors\\

\hline
\end{tabular*}
\vspace*{.2cm}

When called without output arguments, {\ty tfrrmsc} runs {\ty tfrqview}.
\end{minipage}
\vspace*{.5cm}

{\bf \large \sf Example}
\begin{verbatim}
         sig=fmlin(64,0.1,0.4);
         tfrrmsc(sig,1:64,64,2.1,1);
\end{verbatim}
\vspace*{.5cm}

{\bf \large \sf See Also}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
all the {\ty tfr*} functions.
\end{minipage}
\vspace*{.5cm}

{\bf \large \sf Reference}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
[1] F. Auger, P. Flandrin ``Improving the Readability of Time-Frequency and
Time-Scale Representations by the Reassignment Method'' IEEE Transactions
on Signal Processing, Vol. 43, No. 5, pp. 1068-89, 1995.
\end{minipage}


\documentclass{article}
\usepackage{amsmath, amsfonts, graphicx, fullpage, leftidx}
\begin{document}
\section{Pole/end-effector sub system}
Consider a massless pole with a sphere attached to one end, with sphere mass being $m_s$. The other end of the pole (point $A$) is attached to the end-effector with mass $m_e$ at point $A$. The state of the system is the velocity of the end-effector point A $(\dot{x}_A, \dot{y}_A, \dot{z}_A)$, the delta position between the sphere and the end-effector in the horizontal plane $x_{AB} = x_B - x_A, y_{AB} = y_B-y_A$, together with its time derivative $\dot{x}_{AB}, \dot{y}_{AB}$.

\begin{figure}
	\centering
	\includegraphics[width=0.5\textwidth]{pole.pdf}
\end{figure}

The position of the mass is
\begin{align}
	\begin{bmatrix}
		x_A + x_{AB}\\
		y_A + y_{AB}\\
		z_A + \sqrt{l^2 - x_{AB}^2 - y_{AB}^2}
	\end{bmatrix}
\end{align}
The velocity of the mass is
\begin{align}
	\begin{bmatrix}
		\dot{x}_A + \dot{x}_{AB}\\
		\dot{y}_A + \dot{y}_{AB}\\
		\dot{z}_A - \frac{x_{AB}\dot{x}_{AB} + y_{AB}\dot{y}_{AB}}{\sqrt{l^2-x_{AB}^2 - y_{AB}^2}}
	\end{bmatrix}
\end{align}
The total kinetic energy of the system is
\begin{multline}
	T = 0.5 m_e (\dot{x}_A^2 + \dot{y}_A^2 +\dot{z}_A^2) + 0.5 m_s(\dot{x}_A^2 + \dot{y}_A^2 + \dot{z}_A^2 + \dot{x}_{AB}^2 + \dot{y}_{AB}^2 + \frac{(x_{AB}^2\dot{x}_{AB}^2 + y_{AB}^2\dot{y}_{AB}^2 + 2x_{AB}y_{AB}\dot{x}_{AB}\dot{y}_{AB})}{l^2-x_{AB}^2-y_{AB}^2}\\
	+ 2\dot{x}_A\dot{x}_{AB} + 2\dot{y}_A\dot{y}_{AB} - \frac{2\dot{z}_A(x_{AB}\dot{x}_{AB}+y_{AB}\dot{y}_{AB})}{\sqrt{l^2-x_{AB}^2-y_{AB}^2}})
\end{multline}
The total potential energy is
\begin{align}
	V = m_egz_A + m_sg(z_A + \sqrt{l^2-x_{AB}^2-y_{AB}^2})
\end{align}
Using Lagrangian $L = T-V$ and $\frac{d}{dt}\frac{\partial L}{\partial \dot{q}}-\frac{\partial L}{\partial q} = Bu$, we have
\begin{align}
	(m_e + m_s)\ddot{x}_A + m_s\ddot{x}_{AB} = f_x\\
	(m_e + m_s)\ddot{y}_A + m_s\ddot{y}_{AB} = f_y
\end{align}
\begin{multline}
	(m_e + m_s)(\ddot{z}_A+g) - m_s\left(\dot{x}_{AB}^2\frac{l^2 - y_{AB}^2}{z_{AB}^3} + \frac{x_{AB}}{z_{AB}}\ddot{x}_{AB} + \dot{y}_{AB}^2\frac{l^2-x_{AB}^2}{z_{AB}^3} + \frac{y_{AB}}{z_{AB}}\ddot{y}_{AB} - 2 \frac{x_{AB}y_{AB}\dot{x}_{AB}\dot{y}_{AB}}{z_{AB}^3}\right) = f_z
\end{multline}
\begin{multline}
	m_s(\ddot{x}_A + \ddot{x}_{AB}) - m_sx_{AB}(g+\ddot{z}_A)/z_{AB} + m_s(x_{AB}^2\ddot{x}_{AB}+x_{AB}\dot{x}_{AB}^2+x_{AB}y_{AB}\ddot{y}_{AB}+x_{AB}\dot{y}_{AB}^2)/z_{AB}^2\\
	+ m_s(x_{AB}^3\dot{x}_{AB}^2 + 2x_{AB}^2y_{AB}\dot{x}_{AB}\dot{y}_{AB} + x_{AB}y_{AB}^2\dot{y}_{AB}^2)/z_{AB}^4=0
\end{multline}
\begin{multline}
	m_s(\ddot{y}_A + \ddot{y}_{AB}) - m_sy_{AB}(g+\ddot{z}_A)/z_{AB} + m_s(y_{AB}^2\ddot{y}_{AB}+y_{AB}\dot{y}_{AB}^2+y_{AB}x_{AB}\ddot{x}_{AB}+y_{AB}\dot{x}_{AB}^2)/z_{AB}^2\\
	+ m_s(y_{AB}^3\dot{y}_{AB}^2 + 2y_{AB}^2x_{AB}\dot{y}_{AB}\dot{x}_{AB} + y_{AB}x_{AB}^2\dot{x}_{AB}^2)/z_{AB}^4=0
\end{multline}

In the matrix form, we have
\begin{align}
	M	\begin{bmatrix}\ddot{x}_A\\\ddot{y}_A\\\ddot{z}_A\\\ddot{x}_{AB}\\\ddot{y}_{AB}\end{bmatrix} + C = \begin{bmatrix}f_x\\f_y\\f_z\\0\\0\end{bmatrix}\label{eq:pole_ee_manipulator_eq}
\end{align}
where
\begin{align}
	M =
	\begin{bmatrix}
		m_e + m_s & 0 & 0 & m_s & 0\\
		0 & m_e + m_s & 0 & 0 & m_s\\
		0 & 0 & m_e + m_s & -m_s\frac{x_{AB}}{z_{AB}} & -m_s\frac{y_{AB}}{z_{AB}}\\
		m_s& 0 & -m_s\frac{x_{AB}}{z_{AB}} & m_s + m_s\frac{x_{AB}^2}{z_{AB}^2} & m_s\frac{x_{AB}y_{AB}}{z_{AB}^2}\\
		0 & m_s & -m_s\frac{y_{AB}}{z_{AB}} &m_s\frac{x_{AB}y_{AB}}{z_{AB}^2} & m_s + m_s\frac{y_{AB}^2}{z_{AB}^2}
	\end{bmatrix}\\
	C = \begin{bmatrix}
		0\\
		0\\
		(m_e + m_s)g - m_s\left(\dot{x}_{AB}^2\frac{l^2-y_{AB}^2}{z_{AB}^3} + \dot{y}_{AB}^2\frac{l^2-x_{AB}^2}{z_{AB}^3} - 2\frac{x_{AB}y_{AB}\dot{x}_{AB}\dot{y}_{AB}}{z_{AB}^3}\right)\\
		-m_sg\frac{x_{AB}}{z_{AB}}+m_sx_{AB}\left(\frac{\dot{x}_{AB}^2 + \dot{y}_{AB}^2}{z_{AB}^2}+\frac{(x_{AB}\dot{x}_{AB} + y_{AB}\dot{y}_{AB})^2}{z_{AB}^4}\right)\\
		-m_sg\frac{y_{AB}}{z_{AB}}+m_sy_{AB}\left(\frac{\dot{x}_{AB}^2 + \dot{y}_{AB}^2}{z_{AB}^2}+\frac{(x_{AB}\dot{x}_{AB} + y_{AB}\dot{y}_{AB})^2}{z_{AB}^4}\right)
	\end{bmatrix}
\end{align}

\section{Whole system}
Assuming that we construct a controller, that given the current state of the pole/end-effector system, this controller computes the force $f_x, f_y, f_z$ applied from the robot to the end-effector, now we want to compute the robot joint torque $\tau$ to apply that force.

We first apply the force $f_x, f_y, f_z$ computed from the controller as input to the pole/end-effector system, from the dynamics equation \eqref{eq:pole_ee_manipulator_eq} we can compute the acceleration of the end effector $\ddot{x}_A, \ddot{y}_A, \ddot{z}_A$, together with the acceleration of the pole $\ddot{x}_B, \ddot{y}_B, \ddot{z}_B$ (where we use both $\ddot{x}_A, \ddot{y}_A, \ddot{z}_A$ and $\ddot{x}_{AB}, \ddot{y}_{AB}, \ddot{z}_{AB}$). We know that for the pole to achieve this acceleration, the end-effector has to apply a force
\begin{align}
	f_B = m_s\begin{bmatrix}\ddot{x}_B \\ \ddot{y}_B \\ \ddot{z}_B + g\end{bmatrix}
\end{align}
onto the pole, applied at where the pole makes contact with the end effector. Based on Newton's third law, there is an equal and opposite force $-f_B$ applied on the end-effector at the contact point $P$ between the end-effector and the pole. Hence our goal is to compute the joint torque of the robot arm, such that the end-effector can achieve the desired acceleration $\ddot{x}_A, \ddot{y}_A, \ddot{z}_A$ under the external force $-f_B$.

We can write the manipulator equation for the IIWA arm (together with the end-effector welded to the wrist joint)
\begin{align}
	M_{iiwa}\ddot{q}_{iiwa} + C = g(q_{iiwa}) + \tau - \left(\leftidx{^W}{J}^P\right)^Tf_B\label{eq:iiwa_eom}
\end{align}
where $\leftidx{^W}{J}^P$ is the Jacobian of the contact point $P$ written in the world frame.
And we also have the constraints on the end-effector acceleration
\begin{align}
	\leftidx{^W}{J}^E\ddot{q}_{iiwa} + \leftidx{^W}{\dot{J}}^E\dot{q}_{iiwa} = \leftidx{^W}{a}^E_{des}\label{eq:iiwa_ee_acceleration}
\end{align}
where $\leftidx{^W}{J}^E$ is the Jacobian of the end-effector written in the world frame. $\leftidx{^W}{a}^E_{des}$ is the desired acceleration of the IIWA end-effector frame $E$ in the world frame $W$. This acceleration includes both the linear acceleraton $\ddot{x}_A, \ddot{y}_A, \ddot{z}_A$, together with the desired angular acceleration. The desired acceleration can be set in two ways
\begin{itemize}
	\item If our goal is to keep the end-effector to be horizontal, then we can compute the desired angular acceleration using a PD law depending on the orientation error.
	\item We can also set the desired end-effector angular acceleration to be zero. Note that this won't handle any orientation drift. Namely if currently the end-effector angular velocity is non-zero, then the orientation will continue to drift.
\end{itemize}

Combining the equations \eqref{eq:iiwa_eom} and \eqref{eq:iiwa_ee_acceleration} we have unknown variable $\tau\in\mathbb{R}^7$. The problem is under-constrained, we can also impose the cost as $\min \tau^T\tau$ to get a unique (and optimal) $\tau$. If we ignore the joint torque limit, then this ends up being an equality-constrained QP which can be solved very efficiently in the closed form.

\end{document}


% To be compiled by XeLaTeX, preferably under TeX Live.
% LaTeX source for ``Yanqi Lake Lectures on Algebra'' Part III.
% Copyright 2019  李文威 (Wen-Wei Li).
% Permission is granted to copy, distribute and/or modify this
% document under the terms of the Creative Commons
% Attribution-NonCommercial 4.0 International (CC BY-NC 4.0)
% https://creativecommons.org/licenses/by-nc/4.0/

% To be included
\chapter{Dimension of finitely generated algebras}

The main reference is \cite[\S 13]{Mat80}.

\section{Dimensions in fibers}
Consider a homomorphism $\varphi: A \to B$, which induces $\varphi^\sharp: \Spec(B) \to \Spec(A)$ on prime spectra. Given $\mathfrak{p} \in \Spec(A)$, we are interested in the fiber $(\varphi^\sharp)^{-1}(\mathfrak{p})$; the prime ideals $\mathfrak{q}$ therein are described by $\varphi^{-1}(\mathfrak{q}) = \mathfrak{p}$, or equivalently:
\[ \varphi^{-1}(\mathfrak{q}) \cap (A \smallsetminus \mathfrak{p}) = \emptyset, \quad \mathfrak{q} \supset \varphi(\mathfrak{p}). \]
Adopt the convention that a zero ring has $\Spec = \emptyset$. The first condition says that $\mathfrak{q}$ comes from $\Spec(B_{\mathfrak{p}})$, where $B_{\mathfrak{p}}$ is the localization with respect to $\varphi(A \smallsetminus \mathfrak{p})$ (possibly zero). The second condition then says that $\mathfrak{q}B_{\mathfrak{p}}$ lies over the image of $\mathfrak{p}A_{\mathfrak{p}}$. Set
\[ \kappa(\mathfrak{p}) := A_{\mathfrak{p}}/\mathfrak{p}A_{\mathfrak{p}}. \]
The fiber $(\varphi^\sharp)^{-1}(\mathfrak{p})$ is then identified with the spectrum of
\[ B \dotimes{A} \kappa(\mathfrak{p}) = \left( B \dotimes{A} A_{\mathfrak{p}} \right) \dotimes{A_{\mathfrak{p}}} \kappa(\mathfrak{p}) = B_{\mathfrak{p}} \dotimes{A_{\mathfrak{p}}} (A_{\mathfrak{p}}/\mathfrak{p}A_{\mathfrak{p}} ), \]
which is empty if and only if $B \dotimes{A} \kappa(\mathfrak{p})$ is zero. This also equips $(\varphi^\sharp)^{-1}(\mathfrak{p})$ with an extra structure: it is the spectrum of an explicit quotient ring of $B_{\mathfrak{p}}$.

Observe that for all $\mathfrak{q} \in (\varphi^\sharp)^{-1}(\mathfrak{p})$, the localization of $B_{\mathfrak{p}} \dotimes{A_{\mathfrak{p}}} \kappa(\mathfrak{p})$ at the image of $\mathfrak{q}$ is canonically isomorphic to $B_{\mathfrak{q}} \dotimes{A_{\mathfrak{p}}} \kappa(\mathfrak{p})$.

\begin{proposition}\label{prop:fiber-ineq}
	Assume $A, B$ to be Noetherian. Let $\mathfrak{q} \in \Spec(B)$ and $\mathfrak{p} := \varphi^\sharp(\mathfrak{q})$. We have
	\begin{enumerate}[(i)]
		\item $\dim(B_{\mathfrak{q}}) \leq \dim(A_{\mathfrak{p}}) + \dim B_{\mathfrak{q}} \dotimes{A_{\mathfrak{p}}} \kappa(\mathfrak{p})$ (note that the existence of $\mathfrak{q}$ ensures that $B_{\mathfrak{p}} \dotimes{A_{\mathfrak{p}}} \kappa(\mathfrak{p}) \neq \{0\}$, hence $B_{\mathfrak{q}} \dotimes{A_{\mathfrak{p}}} \kappa(\mathfrak{p}) \neq \{0\}$);
		\item equality holds if going-down holds for $\varphi$;
		\item if going-down holds and $\varphi^\sharp$ is surjective, then $\dim(B) \geq \dim(A)$, and for all ideal $\mathfrak{a} \subsetneq A$ we have $\varphi(\mathfrak{a}) B \neq B$ and $\mathrm{ht}(\mathfrak{a}) = \mathrm{ht}(\varphi(\mathfrak{a})B)$.
	\end{enumerate}
\end{proposition}

It is crucial to notice that $\dim B_{\mathfrak{q}} \dotimes{A_{\mathfrak{p}}} \kappa(\mathfrak{p}) = \text{ht}(\mathfrak{q}B_{\mathfrak{q}}/\varphi(\mathfrak{p}) B_{\mathfrak{q}}) = \text{ht}(\mathfrak{q}/\varphi(\mathfrak{p})B)$.

This bounds the source dimension of a morphism by the target dimension plus the fiber dimension, localized both at $\mathfrak{p}$ and $\mathfrak{q} \in (\varphi^\sharp)^{-1}(\mathfrak{p})$. In order to have an equality, a certain submersion-like condition on $\varphi^\sharp$ is evidently required; this explains the going-down condition. Cf. \cite[(6.H)]{Mat80}.

\begin{proof}
	We have an induced local homomorphism $A_{\mathfrak{p}} \to B_{\mathfrak{q}}$ since $\mathfrak{q} \mapsto \mathfrak{p}$. Since (i) and (ii) depend only on this induced homomorphism, we may assume from the outset that $A$, $B$ are local with maximal ideals $\mathfrak{p}, \mathfrak{q}$, and $\varphi$ is a local homomorphism. Let $d := \dim A$ and take a parameter ideal $I = (t_1, \ldots, t_d)$ of $A$, so that $\mathfrak{p}^k \subset I \subset \mathfrak{p}$ for some $k$. It follows that $\sqrt{\varphi(\mathfrak{p}) B} = \sqrt{\varphi(I)B}$, therefore $\dim(B \dotimes{A} \kappa(\mathfrak{p})) = \dim(B/\varphi(\mathfrak{p})B) = \dim (B/\varphi(I)B)$; denote this number as $e$. Take a $s_1, \ldots, s_e \in \mathfrak{q}$ whose images generate a parameter ideal for $B/\varphi(I)B$, and put $J := (\varphi(t_1), \ldots, \varphi(t_d), s_1, \ldots, s_e)$. Then $B/J$ is Artinian, therefore $\dim B \leq d+e$ establishes (i).

	As for (ii), we conserve the same hypotheses and take a prime chain $\mathfrak{q} = \mathfrak{q}_0 \supsetneq \cdots \supsetneq \mathfrak{q}_e$ with $\mathfrak{q}_e \supset \varphi(\mathfrak{p})B$ in $B$, as well as a prime chain $\mathfrak{p} = \mathfrak{p}_0 \supsetneq \cdots \supsetneq \mathfrak{p}_d$ in $A$. Note that $\varphi^{-1}(\mathfrak{q}_e) = \mathfrak{p}$ since $e = \dim B/\varphi(\mathfrak{p})B$. By applying going-down repeatedly to the chain $\mathfrak{p}_i$, we obtain a prime chain in $B$
	\[ \mathfrak{q}_e \supsetneq \cdots \supsetneq \mathfrak{q}_{e+d}, \quad \varphi^{-1}(\mathfrak{q}_{e+i}) = \mathfrak{p}_i. \]
	Concatenation with $\mathfrak{q}_0 \supsetneq \cdots$ gives $\dim(B) = d + e$. This shows (ii).

	The first assertion of (iii) results from (ii). To show the remaining one, let us show $\varphi(\mathfrak{a})B \neq B$: if $\varphi^\sharp(\mathfrak{q}) = \mathfrak{p} \supset \mathfrak{a}$, then $\mathfrak{q} \supset \varphi(\mathfrak{a}) B$. Next, take a minimal over-prime $\mathfrak{q} \supset \varphi(\mathfrak{a})B$ with $\text{ht}(\mathfrak{q}) = \text{ht}(\varphi(\mathfrak{a})B)$. With $\mathfrak{p} := \varphi^{-1}(\mathfrak{q}) \supset \mathfrak{a}$, we must have $\dim B_{\mathfrak{q}} \otimes \kappa(\mathfrak{p}) = \text{ht}(\mathfrak{q}/\varphi(\mathfrak{p})B) = 0$ by the minimality of $\mathfrak{q}$. An application of (ii) yields
	\begin{gather*}
		\text{ht}(\varphi(\mathfrak{a})B) = \text{ht}(\mathfrak{q}) = \text{ht}(\mathfrak{p}) \geq \text{ht}(\mathfrak{a}).
	\end{gather*}
	To obtain $\leq$, choose $\mathfrak{p} \supset \mathfrak{a}$ with $\text{ht}(\mathfrak{p}) = \text{ht}(\mathfrak{a})$ and take $\mathfrak{q} \in \Spec(B)$ with $\mathfrak{p} = \varphi^{-1}(\mathfrak{q})$; this implies $\mathfrak{q} \supset \varphi(\mathfrak{p})B \supset \varphi(\mathfrak{a})B$. Upon shrinking $\mathfrak{q}$, we may even assume $\mathfrak{q}$ is minimal over $\varphi(\mathfrak{p})B$, i.e. $\text{ht}(\mathfrak{q}/ \varphi(\mathfrak{p})B) = 0$. Using (ii), this entails $\text{ht}(\mathfrak{a}) = \text{ht}(\mathfrak{p}) = \text{ht}(\mathfrak{q}) \geq \text{ht}(\varphi(\mathfrak{a})B)$.
\end{proof}

\vspace{1em}
\begin{center}
	\begin{tikzpicture}
		\draw (-2,1) -- (2,1);
		\draw[line width=6pt, white] (0, 2) -- (0, -1.5);
		\draw[line width=2pt, black] (0,2) -- (0, 0.7);
		\draw[line width=1.5pt, dashed] (0, 0.65) -- (0, 0);
		\draw[line width=2pt, black] (0,0) -- (0, -1.2);
		\draw[line width=5pt, white] (-3,0) -- (3,0);
		\draw (-3,0) -- (3,0);
		\draw (-3,0) -- (-2,1);
		\draw (3,0) -- (2,1);
		\fill[opacity=0.2, shade, color=black!50!white] (-2,1) -- (2,1) -- (3,0) -- (-3,0) -- (-2,1);
		\node[anchor=west, text width=4cm, align=left] at (4.5, 0.7) {\small The minimal primes in a ring $B$ may have different heights when the scheme $\Spec(B)$ is not equi-dimensional.};
	\end{tikzpicture}
\end{center}
\vspace{1em}

Going-down holds for flat $\varphi$ by Theorem \ref{prop:going-down-flat}, therefore the dimension equality
\[ \dim(B_{\mathfrak{q}}) = \dim(A_{\mathfrak{p}}) + \dim B_{\mathfrak{q}} \dotimes{A_{\mathfrak{p}}} \kappa(\mathfrak{p}) \]
holds for flat ring homomorphisms.

\begin{remark}
	In general, if $B$ is a finitely generated algebra over Noetherian $A$ such that $\Spec(B) \to \Spec(A)$ is a closed map, the fiber dimension $\mathfrak{p} \mapsto \dim B/\mathfrak{p}B$ is an \emph{upper semi-continuous function} on the target space $\Spec(A)$. More concretely, the fiber dimension is non-decreasing under specialization of $\mathfrak{p}$. Cf. \cite[\S 14.3]{Eis95} or \cite[(13.E)]{Mat80}. Try to understand this phenomenon intuitively.
\end{remark}

\begin{proposition}\label{prop:dim-integral}
	Suppose $B$ is integral over a subring $A$.
	\begin{enumerate}[(i)]
		\item We have $\dim A = \dim B$.
		\item If we assume moreover that $A, B$ are both Noetherian, then $\mathrm{ht}(\mathfrak{q}) \leq \mathrm{ht}(\mathfrak{q} \cap A)$ for every $\mathfrak{q} \in \Spec(B)$.
		\item Furthermore, if going-down also holds for $A \hookrightarrow B$, we have $\mathrm{ht}(J) = \mathrm{ht}(J \cap A)$ for every ideal $J \subsetneq B$.
	\end{enumerate}
\end{proposition}
\begin{proof}
	Going-up holds and $\Spec(B) \twoheadrightarrow \Spec(A)$ in the situation of (i) by Theorem \ref{prop:Cohen-Seidenberg}, hence $\dim B \geq \dim A$ by lifting prime chains. To prove $\leq$, observe that $\mathfrak{q} \subsetneq \mathfrak{q}'$ implies $\mathfrak{q} \cap A \subsetneq \mathfrak{q}' \cap A$ since there are no inclusion relations in the fibers of $\Spec(B) \to \Spec(A)$.

	As for (ii), note that $\text{ht}(\mathfrak{q}) \leq \text{ht}(\mathfrak{p}) + \text{ht}(\mathfrak{q}/\mathfrak{p}B)$ where $\mathfrak{p} := \mathfrak{q} \cap A$; as the are no inclusion relations in fibers, the last term must be $0$.

	Now assume going-down and consider (iii). Take $\mathfrak{q} \in \Spec(B)$ with $\text{ht}(\mathfrak{q}) = \text{ht}(J)$. Put $\mathfrak{p} := \mathfrak{q} \cap A \supset J　\cap A$. Again, since there are no inclusions in the fiber over $\mathfrak{p}$ of $\Spec(B) \twoheadrightarrow \Spec(A)$, we have $\dim(B_{\mathfrak{q}}/ \mathfrak{p}B_{\mathfrak{q}}) = 0$. Proposition \ref{prop:fiber-ineq} (ii) implies $\text{ht}(\mathfrak{q})=\text{ht}(\mathfrak{p})$, therefore $\text{ht}(J) \geq \text{ht}(J \cap A)$.

	On the other hand, for any $\mathfrak{p} \supset J \cap A$ with $\text{ht}(\mathfrak{p}) = \text{ht}(J \cap A)$, since $A/J \cap A \hookrightarrow B/J$ is integral, there exists $\mathfrak{q} \supset J$ with $\mathfrak{q} \cap A = \mathfrak{p}$. Together with Proposition \ref{prop:fiber-ineq} (i) and $\mathrm{ht}(\mathfrak{q}/\mathfrak{p}B) = 0$, this implies $\text{ht}(J) \leq \text{ht}(\mathfrak{q}) \leq \text{ht}(\mathfrak{p}) = \text{ht}(J \cap A)$ by (ii).
\end{proof}

\section{Calculation for polynomial algebras}
Let us apply the results from the previous section to elucidate the Krull dimension of polynomial algebras.

\begin{theorem}\label{prop:dim-polynomial-alg}
	Let $A$ be a Noetherian ring, we have $\dim A[X_1, \ldots, X_n] = \dim A + n$ for any $n \geq 0$. In particular, $\dim A[X_1, \ldots, X_n] = n$ if $A$ is Artinian (eg.\ a field).
\end{theorem}
\begin{proof}
	Evidently we may assume $n=1$. We shall apply Proposition \ref{prop:fiber-ineq} to $A \hookrightarrow B = A[X]$. Take any $\mathfrak{p} \in \Spec(A)$ and let $\mathfrak{q}$ be a maximal element in $\{\mathfrak{q}' \in \Spec(B): \mathfrak{q} \cap A = \mathfrak{p} \}$. Put $\kappa := \kappa(\mathfrak{p})$. It suffices to show that $B_{\mathfrak{q}} \dotimes{A_{\mathfrak{p}}} \kappa$ has dimension one, since $B$ is free hence flat over $A$, and Proposition \ref{prop:fiber-ineq} will imply
	\[ \dim B_{\mathfrak{q}} = \dim A_{\mathfrak{p}} + 1 \]
	and taking supremum over $\mathfrak{p} \in \Spec(A)$ gives the result.

	Indeed, put $B_{\mathfrak{p}} := B[(A \smallsetminus \mathfrak{p})^{-1}] = A_{\mathfrak{p}}[X]$ and $\mathfrak{q}' := \mathfrak{q}[(A \smallsetminus \mathfrak{p})^{-1}] \in \Spec(B_{\mathfrak{p}})$. As $\mathfrak{q}' \supset \mathfrak{p}A_{\mathfrak{p}}$, we have $\overline{\mathfrak{q}'} := \mathfrak{q}' \supset \mathfrak{p}A_{\mathfrak{p}} \in \Spec(\kappa[X])$, and $\overline{\mathfrak{q}'}$ is maximal in the fiber over $\{0\}$ of $\Spec(\kappa[X]) \to \Spec(\kappa)$, i.e.\ in $\MaxSpec(\kappa[X])$. Localization in stages yields
	\[ B_{\mathfrak{q}} \dotimes{A_{\mathfrak{p}}} \kappa \simeq \frac{B_{\mathfrak{q}}}{\mathfrak{p} B_{\mathfrak{q}}} \simeq \left( \frac{B_{\mathfrak{p}}}{ \mathfrak{p} A_{\mathfrak{p}} B_{\mathfrak{p}}} \right)_{\mathfrak{q}' } \simeq \kappa[X]_{\overline{\mathfrak{q}'}}. \]
	As $\kappa[X]$ is a principal ideal domain which is not a field, every maximal ideal thereof has height one. Hence $\dim \kappa[X]_{\overline{\mathfrak{q'}}} = \mathrm{ht}(\mathfrak{q}') = 1$.
\end{proof}

\begin{corollary}\label{prop:poly-alg-ht}
	Let $\Bbbk$ be a field, then for every $0 \leq i \leq n$ we have $\mathrm{ht}(X_1, \ldots, X_i) = i$ in $\Bbbk[X_1, \ldots, X_n]$.
\end{corollary}
\begin{proof}
	The prime chain $\{0\} \subset (X_1) \subsetneq \cdots \subsetneq (X_1, \ldots, X_n)$ has length $n = \dim \Bbbk[X_1, \ldots, X_n]$. Thus for each $0 \leq i \leq n$, the chain $\{0\} \subset (X_1) \subsetneq \cdots \subsetneq (X_1, \ldots, X_i)$ has maximal length among all prime chains starting with $(X_1, \ldots, X_i)$.
\end{proof}

Combined with Theorem \ref{prop:dim-polynomial-alg}, we see that for $\Bbbk$ a field, $R := \Bbbk[X_1, \ldots, X_n]$ and $\mathfrak{p} := (X_1, \ldots, X_i)$, the equality
\[ \text{ht}(\mathfrak{p}) + \dim R/\mathfrak{p} = \dim R. \]
holds. This will be generalized to finitely generated domains over $\Bbbk$.

We record another simple consequence for later use.
\begin{corollary}\label{prop:fg-dimension-bound}
	Let $\Bbbk$ be a field. Any $\Bbbk$-algebra $A$ with $n$ generators has finite dimension $\leq n$.
\end{corollary}
\begin{proof}
	Writing $A = \Bbbk[X_1, \ldots, X_n]/I$ for some ideal $I$, we have $\dim A \leq \Bbbk[X_1, \ldots, X_n]$ since every prime chain in $A$ lifts to $\Bbbk[X_1, \ldots, X_n]$. Now apply Theorem \ref{prop:dim-polynomial-alg}.
\end{proof}

\section{Noether normalization and its consequences}
Fix a field $\Bbbk$. A few preparatory results are in order.

\begin{lemma}\label{prop:normalization-Nagata}
	Suppose $\Bbbk$ is a field and $t \in \Bbbk[X_1, \ldots X_e] \smallsetminus \Bbbk$. There exist $t_1, \ldots, t_{e-1} \in \Bbbk[X_1, \ldots, X_e]$ such that $\Bbbk[X_1, \ldots, X_e]$ is finitely generated as a module over the $\Bbbk$-subalgebra $S := \Bbbk[t_1, \ldots, t_{e-1}, t]$.
\end{lemma}
\begin{proof}
	We seek $t_i$ of the form $X_i - X_e^{k^i}$ where $k$ is a large integer. Then $t$ can be uniquely expressed as a polynomial of $t_1, \ldots, t_{e-1}, X_e$. We claim that upon modifying $t$ by $\Bbbk^\times$, which is clearly harmless, one can choose $k$ such that $t$ is monic as an element of $\Bbbk[t_1, \ldots, t_{e-1}][X_e]$, say of some degree $\delta$. If this is the case,
	\[ t = X_e^\delta + \sum_{0 \leq j < \delta} \left(\text{polynomial in } t_1, \ldots, t_{e-1}\right) X_e^j \]
	says that $X_e$ is integral over $S$, and then $\Bbbk[X_1, \ldots, X_e]$ is generated as an $S$-module by $1, X_e, \ldots, X_e^{\delta-1}$.

	To choose $k$, one stares at the expansion
	\[ X_1^{a_1} \cdots X_e^{a_e} = \left(t_1 + X_e^{k^1}\right)^{a_1} \cdots \left(t_{e-1} + X_e^{k^{e-1}}\right)^{a_{e-1}} \cdot X_e^{a_e} = X_e^{a_e + a_1 k^1 + \cdots + a_{e-1} k^{e-1}} + \text{mixed terms}. \]
	If $k > \max\{a_1, \ldots, a_e \}$, the exponent of $X_e$ is simply the base $k$ expression with digits $a_e, a_1, \ldots, a_{e-1}$. Now write $t$ as a linear combination of monomials $X_1^{a_1} \cdots X_e^{a_e}$ and expand them in terms of $t_1, \ldots, t_{e-1}, X_e$. From the observation above, different $(a_1, \ldots, a_e)$ contributes a different exponent of $X_e$ whenever $k \gg 0$. Adjusting $t$ by $\Bbbk^\times$, we get the asserted property.
\end{proof}

\begin{lemma}\label{prop:normalization-aux}
	Let $\mathfrak{a}$ be a nonzero ideal of a domain $R$, then $\dim(R/\mathfrak{a}) + 1 \leq \dim R$.
\end{lemma}
\begin{proof}
	Any prime chain $\mathfrak{p}_0 \supsetneq \cdots \supsetneq \mathfrak{p}_n$ in $R$ with $\mathfrak{p}_n \supset \mathfrak{a}$ can be extended to a prime chain length $n+1$, namely by adjoining $\mathfrak{p}_{n+1} := \{0\}$.
\end{proof}

\begin{theorem}[E.\ Noether, M.\ Nagata]\label{prop:Noether-normalization}\index{Noether normalization}
	Let $B$ be a finitely generated $\Bbbk$-algebra of dimension $n$. Consider a chain of proper ideals $I_1 \subsetneq \cdots \subsetneq I_m$, with $\dim(B/I_j) = d_j$ and $d_1 > \cdots > d_m \geq 0$. Then there exist a $\Bbbk$-subalgebra $A \subset B$ together with an isomorphism $A \simeq \Bbbk[X_1, \ldots, X_n]$, satisfying
	\begin{compactitem}
		\item $B$ is a finitely generated $A$-module, in particular $B$ is integral over $A$;
		\item $I_j \cap A \simeq (X_{d_j+1}, \ldots, X_n)$ under the isomorphism above, for each $1 \leq j \leq m$.
	\end{compactitem}
\end{theorem}

Note that the assumption $I_j \subsetneq I_{j+1}$ is merely for convenience. Allowing $I_j = I_{j+1}$ and $d_j = d_{j+1}$ for some $j$ is surely possible..

\begin{proof}
	Write $B = \Bbbk[Y_1, \ldots, Y_r]/J$, where $r \geq n$ (Corollary \ref{prop:fg-dimension-bound}), and denote the preimage of $I_j$ in $\Bbbk[Y_1, \ldots, Y_r]$ by $\tilde{I}_j$. The first step is to reduce to the case $J=\{0\}$. To see this, we adjoin $\tilde{I}_0 = \{0\}$ (with $d_0 = n$) into the ideal chain; it may happen that $\tilde{I}_0 = \tilde{I}_1$, but that's harmless. Suppose we can find $\tilde{A} \subset \Bbbk[Y_1, \ldots, Y_r]$, $\tilde{A} \simeq \Bbbk[X_1, \ldots, X_r]$ with the required properties relative to $\tilde{I}_\bullet$. Taking quotient by $J$, we obtain the corresponding properties for $I_\bullet$. Indeed, the passage from $\tilde{A}$ to $A := \tilde{A}/(\tilde{A} \cap J)$ truncates the variables $X_{n + 1}, \ldots, X_r$, whereas
	\[ I_j \cap A = \frac{\tilde{I}_j \cap (\tilde{A} + J)}{J} = \frac{(\tilde{I}_j \cap \tilde{A}) + J}{J}  \simeq \frac{\tilde{I}_j \cap \tilde{A}}{J \cap \tilde{A}}; \]
	try to convince yourself of the middle equality.

	Secondly, having reduced to the case $B = \Bbbk[Y_1, \ldots, Y_r]$ (thus $r = n$), it suffices to pick $x_1, \ldots, x_n \in B$ such that
	\begin{enumerate}[(a)]
		\item $B$ is finitely generated as a module over $A := \Bbbk[x_1, \ldots, x_n]$, and
		\item $I_j \cap A \supset (x_{d_j+1}, \ldots, x_n)$ for all $j$.
	\end{enumerate}
	Indeed, (a) implies $\mathrm{Frac}(A)$ and $\mathrm{Frac}(B)$ have the same transcendence degree $n$ over $\Bbbk$, therefore $x_1, \ldots, x_n$ must be algebraically independent over $\Bbbk$. On the other hand, $\dim(B/I_j) = \dim(A/I_j \cap A)$ by (a) and Proposition \ref{prop:dim-integral}; but if $I_j \cap A \supsetneq (x_{d_j+1}, \ldots, x_n)$ then $A/I_j \cap A$ is a proper quotient of the domain $\Bbbk[x_1, \ldots, x_{d_j}]$, therefore would have dimension $< d_j$ by Lemma \ref{prop:normalization-aux}.

	We shall construct $x_1, \ldots, x_n$ step by step. Suppose $0 \leq e \leq n$ and that we have produced elements $x'_1, \ldots, x'_e$ and $x_{e+1}, \ldots, x_n$ in $B$ satisfying
	\begin{enumerate}[(i)]
		\item $B$ is finitely generated as a module over $\Bbbk[x'_1, \ldots, x'_e, x_{e+1}, \ldots, x_n] =: S_e$;
		\item $I_j \cap S_e \supset (x_{e+1}, \ldots, x_n)$ when $d_j \leq e$;
		\item $I_j \cap S_e \supset (x_{d_j + 1}, \ldots, x_n)$ when $d_j \geq e$ (with $j = 1, \ldots, m$).
	\end{enumerate}

	For the initial case $e=n$, simply take $x'_i := Y_i$. Our aim is $e=0$. Let us explain the induction step from $e \geq 1$ to $e-1$. The prior argument based on transcendence degrees implies the algebraic independence among
	\[ x'_1, \ldots, x'_e, x_{e+1}, \ldots, x_n. \]
	If $e \leq d_j$ for all $j$, we are done. Otherwise set $j := \min\{j': e > d_{j'} \}$, we contend that
	\[ I_j \cap \Bbbk[x'_1, \ldots, x'_e] \neq \{0\}. \]
	If not, we would have $I_j \cap S_e = (x_{e+1}, \ldots, x_n)$ since $I_j \cap S_e \supset (x_{e+1}, \ldots, x_n)$ by (ii). We have $\dim(S_e/I_j \cap S_e) = \dim(B/I_j) = d_j$ by integrality, whilst $\dim(S_e/(x_{e+1}, \ldots, x_n)) = e$. Contradiction.

	Now take $x_e \in I_j \cap \Bbbk[x'_1, \ldots, x'_e] \smallsetminus \{0\}$. Note that $x_e \notin \Bbbk$ as $I_j \neq B$. By Lemma \ref{prop:normalization-Nagata}, we may choose $x''_1, \ldots, x''_{e-1} \in \Bbbk[x'_1, \ldots, x'_e]$ such that $\Bbbk[x'_1, \ldots, x'_e]$ is finitely generated over $\Bbbk[x''_1, \ldots, x''_{e-1}, x_e]$ as a module. It remains to verify that the new sequence
	\[ x''_1, \ldots, x''_{e-1}, x_e, \ldots, x_n \]
	satisfies (i)---(iii) above with $e-1$ replacing $e$.

	First, $S_e$ is a finitely generated module over its subalgebra $\Bbbk[x''_1, \ldots, x_n]$ by construction, hence so is $B$ and (i) follows. Next, let $1 \leq j' \leq m$. If $d_{j'} > e-1$, the procedure above does not affect $x_{d_j + 1}, \ldots, x_n$, so they belong to $I_{j'} \cap \Bbbk[x''_1, \ldots, x_n]$. If $d_{j'} < e$, setting $j := \min\{j'' : e > d_{j''} \}$ we have $j' \geq j$ and
	\[ I_{j'} \cap \Bbbk[x''_1, \ldots, x_n] \supset I_j \cap \Bbbk[x''_1, \ldots, x_n] \supset (x_{e+1}, \ldots, x_n) + (x_e). \]
	All in all, we obtain (ii) and (iii).
\end{proof}

\begin{corollary}[Dimension formula]\label{prop:fg-dim-formula}\index{dimension formula}
	Let $B$ be a finitely generated algebra over a field $\Bbbk$. Suppose $B$ is a domain, then for all $\mathfrak{q} \in \Spec(B)$ we have
	\[ \dim(B/\mathfrak{q}) + \mathrm{ht}(\mathfrak{q}) = \dim B. \]
\end{corollary}
\begin{proof}
	Choose a subalgebra $A$ of $B$ as in Theorem \ref{prop:Noether-normalization} and put $\mathfrak{p} = \mathfrak{q} \cap A$. Since $B$ is a domain and $A$ is normal, the Cohen--Seidenberg Theorem \ref{prop:Cohen-Seidenberg} asserts the going-down property for $A \hookrightarrow B$. Proposition \ref{prop:dim-integral} implies that $\dim A = \dim B$, $\dim A/\mathfrak{p} = \dim B/\mathfrak{q}$ and $\text{ht}(\mathfrak{p}) = \text{ht}(\mathfrak{q})$, so we are again reduced to the case $B = \Bbbk[X_1, \ldots, X_n]$ and $\mathfrak{q} = (X_{d+1}, \ldots, X_n)$. This is known by Corollary \ref{prop:poly-alg-ht}.
\end{proof}

The dimension formula allows us to compute $\dim B$ by choosing any prime $\mathfrak{q}$, a prime chain of longest length below $\mathfrak{q}$ (i.e. in $B_{\mathfrak{q}}$) and another one above $\mathfrak{q}$ (i.e. in $B/\mathfrak{q}$); their concatenation will then be a prime chain in $B$ with maximal length $\dim B$. By applying the dimension formula to $\mathfrak{q}, \mathfrak{q}' \subset B$ and to $\mathfrak{q}'/\mathfrak{q} \subset B/\mathfrak{q}$, it follows that $\text{ht}(\mathfrak{q}') = \text{ht}(\mathfrak{q}) + \text{ht}(\mathfrak{q}'/\mathfrak{q})$ for all $\mathfrak{q}' \supsetneq \mathfrak{q}$ in $B$.

For a general Noetherian domain $B$, we call a prime chain \emph{maximal} if it is not properly contained in any prime chain. A priori, a maximal prime chain does not necessarily have length equal to $\dim B$. If
\[ \forall \mathfrak{q}' \supset \mathfrak{q}: \text{primes}, \quad \text{ht}(\mathfrak{q}') = \text{ht}(\mathfrak{q}) + \text{ht}(\mathfrak{q}'/\mathfrak{q}), \]
we say $B$ is a \emph{catenary} domain\index{catenary}. This means that $\text{ht}(\mathfrak{q}'/\mathfrak{q}) = \dim B_{\mathfrak{q}'}/\mathfrak{q}B_{\mathfrak{q}'}$ is the common length of all maximal prime chains between $\mathfrak{q}'$ and $\mathfrak{q}$. In particular, maximal prime chains in $B_{\mathfrak{q}'}$ are automatically longest. As shown above, finitely generated domains over a field are catenary. For a finer analysis of catenary and universally catenary rings, we refer to \cite[\S 14]{Mat80}.

\begin{corollary}
	Suppose $B$ is a domain finitely generated over a field $\Bbbk$. Set $L := \mathrm{Frac}(B)$. Then $\dim B = \mathrm{tr.deg}_\Bbbk(L)$ and it is the common length of maximal prime chains.
\end{corollary}
\begin{proof}
	Choose a subalgebra $A$ of $B$ as in Theorem \ref{prop:Noether-normalization}. Since the field $\text{Frac}(B)$ is a finite extension of $\text{Frac}(A)$ and $\dim A = \dim B$ by Proposition \ref{prop:dim-integral}, the first assertion reduces immediately to the case $B = \Bbbk[X_1, \ldots, X_n]$, which is obvious. As to the second assertion, consider a maximal prime chain $\mathfrak{q}_0 \supsetneq \cdots \supsetneq \mathfrak{q}_n = \{0\}$ in $B$. Maximality implies $\text{ht}(\mathfrak{q}_i/\mathfrak{q}_{i+1}) = 1$ for all $i$ and $\dim B/\mathfrak{q}_0 = 0$. Applying Corollary \ref{prop:fg-dim-formula} repeatedly, we see
	\begin{multline*}
		\dim B = \dim B/\mathfrak{q}_n = \dim B/\mathfrak{q}_{n-1} + \text{ht}(\mathfrak{q}_{n-1}/\mathfrak{q}_n) = \\
		\dim B/\mathfrak{q}_{n-2} + \text{ht}(\mathfrak{q}_{n-1}/\mathfrak{q}_{n-2}) + \text{ht}(\mathfrak{q}_{n-1}/\mathfrak{q}_n) = \cdots = \dim B/\mathfrak{q}_0 + \sum_{i=0}^{n-1} \text{ht}(\mathfrak{q}_i/\mathfrak{q}_{i+1})
	\end{multline*}
	which equals $n$.
\end{proof}

\begin{remark}
	Recall that finitely generated domains over an algebraically closed field $\Bbbk$ are objects ``opposite'' to the irreducible affine $\Bbbk$-varieties. It is instructive to make a comparison with the analytic theory when $\Bbbk=\CC$. Let $\mathcal{X}$ be a compact connected complex manifold of (complex) dimension $n$. Denote by $\mathcal{M}(\mathcal{X})$ the field of meromorphic functions on $\mathcal{X}$. Siegel proved that $\text{tr.deg}_{\CC}(\mathcal{M}(\mathcal{X})) \leq n$. When $\mathcal{X}$ is a projective algebraic $\CC$-variety, equality holds and we have $\mathcal{M}(\mathcal{X}) = \text{Frac}(A)$ if $\Spec(A)$ is any open dense affine subscheme in $\mathcal{X}$. In general, the abundance of meromorphic functions on $\mathcal{X}$ is a subtle issue, cf. the case of Riemann surfaces ($n=1$). Compact connected complex manifolds with $\text{tr.deg}_{\CC}(\mathcal{M}(\mathcal{X})) = \dim_{\CC} \mathcal{X}$ are called \emph{Moishezon manifolds}.\index{Moishezon manifolds}

	Non-algebraic Moishezon manifolds do exist, and Moishezon proved that a Moishezon manifold is projective, hence algebraic, if and only if it is Kähler. Following M.\ Artin and D.\ Knutson, one can enlarge the category of $\CC$-schemes into that of \emph{algebraic spaces} over $\CC$, and there is an analytification functor $\mathcal{X} \mapsto \mathcal{X}_{\text{an}}$ that sends algebraic spaces of finite type over $\CC$ to complex analytic varieties. M. Artin \cite[\S 7]{Ar70} showed that the analytification establishes an equivalence between the category of smooth proper algebraic spaces of finite type over $\CC$ and that of Moishezon manifolds. Therefore, such manifolds still retain an algebraic flavor: they are quotients of certain $\CC$-schemes by étale equivalence relations.
\end{remark}