%% -*- coding:utf-8 -*-
\chapter{Structure of finite K-algebras continued}

We apply the discussion from the last lecture to the case of field
extensions. We show that the separable extensions remain reduced after
a base change: the inseparability is responsible for eventual
nilpotents. As our next subject, we introduce normal and Galois
extensions and prove Artin's theorem on invariants.

\section{Structure of finite K-algebras, examples (cont'd)}

Last time we have seen that a finite $K$-algebra $A$
($\left[A:K\right] < \infty$) has only finitely many maximal ideals
$m_1, \dots, m_r$ and the following equation holds (see theorem
\ref{thm:structurefinitekalgebra}):
\[
A \cong A/m_1^{k_1} \times \dots \times A/m_r^{k_r}
\]
This is a general form of \mynameref{thm:chineseremainder}.

\begin{example}
  Let
  \[
  A = K\left[X\right]/\left(F\right)
  \]
  And the polynomial $F$ is not necessary
  irreducible so let's decompose into a product of irreducible
  factors:  $F= P_1^{k_1} \dots P_r^{k_r}$.
  Then by the  \mynameref{thm:chineseremainder}
  \footnote{
    See also remark \ref{rem:lec5_4} and theorem
    \ref{thm:structurefinitekalgebra}
  }
  one can get
  \[
  A \cong
  K\left[X\right]/\left(P_1\right)^{k_1} \times \dots
  \times K\left[X\right]/\left(P_r\right)^{k_r},
  \]
  where $K\left[X\right]/\left(P_i\right)^{k_i} = A/m_i^{k_i}$ and
  $m_i = \left( P_i \mod F \right)$
  \footnote{
    Using definition \ref{def:quotientring} one can get that
    $P_i \in K\left[X\right]$ corresponds to
    $P_i \mod F$ in $A = K\left[X\right]/\left(F\right)$ therefore
    we have $\left(P_i\right)$ is a \mynameref{def:maxideal} for
    $K\left[X\right]$ and
    \[
    A/\left(P_i\right)^{k_i} =
    K\left[X\right]/\left(P_i \mod F \right)^{k_i}.
    \]
    but $P_i \mod F  = P_i$ and as result
    \[
    K\left[X\right]/\left(F\right) \cong
    K\left[X\right]/\left(P_1\right)^{k_1} \times \dots
    \times K\left[X\right]/\left(P_r\right)^{k_r}.
    \]
  }
  - an ideal.
  \label{ex:lec5_1}
\end{example}

\begin{definition}[Nilpotent element]
  Let $A$ is a \mynameref{def:ring} than $x \in A$ is nilpotent if $x \ne 0$ but
  $\exists k: x^k = 0$.
  \footnote{
    Alternative definition from \cite{wiki:nilpotent}: An element,
    $x$, of a ring, $R$, is called nilpotent if there exists
    some positive integer, $n$, such that $x^n = 0$.
  }
  \label{def:nilpotent}
\end{definition}

\begin{definition}[reduced]
  $K$-algebra $A$ is reduced if it has no \mynameref{def:nilpotent}s.
  Or in other words
  \footnote{
    Let we have an $i$-th element of the product $\prod A/m_i^{k_i}$
    with $k_i > 1$ and $m_i  = (p)$ when
    $p \in A/m_i^{k_i}$ and $p \ne 0 = p^{k_i}$ i.e. $p$ is a
    nilpotent.
  }
  if in the decomposition
  \[
  A \cong A/m_1^{k_1} \times \dots \times A/m_r^{k_r}
  \]
  $\forall i: k_i = 1$.
  Or
  \footnote{
    $A/m_i$ is a field as soon as $m_i$ is a \mynameref{def:maxideal}
  }
  if $A$ is a product of fields.
  \label{def:reduced}
\end{definition}

\begin{definition}[local]
  \mynameref{def:ring} $A$ is called local if it has only one
  \mynameref{def:maxideal} i.e. $A \cong A/m^k$.
  \label{def:local}
\end{definition}

If $A$ is local then all elements of $A$ are nilpotents
i.e. any element of $A$ is a identity,zero or nilpotent
\footnote{
  As it was mentioned in \cite{wiki:localring}, a nonzero ring in
  which every element is either a unit or nilpotent is a local
  ring, but not reverse, as it was pointed on the lectures. There is
  also an example $A \cong A/\{0\}$ where $A$ is a \mynameref{def:field}
  and $\{0\}$ is the only maximal ideal for the fields (see example
  \ref{ex:maxideal}). In this case there are many non nilpotents
  different from identity and zero but the ring ($K$-algebra) is local.
}
\footnote{
  Comment from Staff on the issue: It looks confusing because Katya
  immediately applies this definition to the case of finite algebras
  without explicitly mentioning.

  You are right that it is not true in general. For example, discrete
  valuation rings are local and have no zero divisors at all. (Also your
  counterexample is not quite correct, because a field is exactly the
  case when every element is either invertible or nilpotent).

  But if a finite algebra has only one maximal ideal, then by the
  structural theorem it consists of nilpotents.
}
.

Most of our last examples were examples of reduced $K$-algebras such
as
\[
\mathbb{C} \otimes_{\mathbb{R}} \mathbb{C} =
\mathbb{C} \times \mathbb{C}
\]
or
\[
\mathbb{Q}\left(\sqrt{2}\right) \otimes_{\mathbb{Q}}
\mathbb{Q}\left(i\right) =
\mathbb{Q}\left(i, \sqrt{2}\right)
\]
that is a field and if we start producing similar examples then mostly
they are reduced. Well, why? Because in fact the presence of
nilpotents has to do with inseparability. The presence of nilpotents
reflects inseparability.

So let me give you one more example: tensor product of
extensions which is not reduced. Let $K$ be a field of characteristic
$p$, for instance $\mathbb{F}_p$. Consider a field of rational
functions over $K$
\footnote{
  As it was shown in example \ref{ex:lec3_1} (part
  \ref{ex:lec3_notperfect}) it's not a  \mynameref{def:perfectfield} and
  as result of theorem \ref{thm:lec3_4} is not separable.
}
: $K\left(X\right)$. We will consider
$K\left(X\right)$ as an extension of $K\left(X^p\right)$ (or with new
variable $Y = X^p$ - $K\left(Y\right)$. We will be interested in
\(
K\left(X\right)
\otimes_{K\left(Y\right)}
K\left(X\right)
\) where $X$ is a $p$th root of $Y$ so
\footnote{
  as soon as
  $K\left(X\right) = K\left[T\right]/\left(T^p - Y\right)$
}
\begin{eqnarray}
K\left(X\right)
\otimes_{K\left(Y\right)}
K\left(X\right)
\cong
\nonumber \\
\cong
K\left(X\right)
\otimes_{K\left(Y\right)}
K\left[T\right]/\left(T^p - Y\right)
\cong
\nonumber \\
\cong
K\left(X\right)\left[T\right]/\left(T^p - Y\right) =
\nonumber \\
=
K\left(X\right)\left[T\right]/\left(T^p - X^p\right) =
K\left(X\right)\left[T\right]/\left(T - X\right)^p
\nonumber
\end{eqnarray}
where $T$ is another variable. As result we have got a ring with
nilpotents for example $T - X$ and of course the reason is that our
extension $K\left(X\right)$ is pure inseparable extension (see
definition \ref{def:inseparabledegree}) of $K\left(Y\right)$.

\section{Separability and base change}
What is the reason for such a mysterious connection between
presence of nilpotents and separability? If $L$ is separable over $K$
then the number of \mynameref{def:homomorphism}s
$\left|Hom_K\left(L, \bar{K}\right)\right|$ is maximal and equal to
degree $\left[L : K\right]$ but in general it is less or equal to the
degree.  This is of course clear, because  if we have a polynomial
with distinct roots, then it's stem field for instance  has exactly
this number of  homomorphisms into the-algebraic closure and this
number is equal to the number of roots. So if some roots coincide,
then the number of homomorphisms diminishes.

Lets also recall \mynameref{thm:basechange}. If $L$ and $E$ are
extensions of $K$ and $L$ is finite over $K$ then
\[
Hom_K\left(L, E\right) \cong
Hom_E\left(
L \otimes_K E, E
\right).
\]
In the formula, $L \otimes_K E$ is a finite $E$-algebra denoted as $A$
below.
\begin{myremark}
  We have that $A = L \otimes_K E \cong E \otimes_K L$ is a free $E$
  module as soon as $L$ is a free $K$ module and with proposition
  \ref{prop:lec4_Addon} we have that $\left[A : E\right] < \infty$
  (as soon as $\left[L : K\right] < \infty$)
  and
  as result with theorem \ref{thm:structurefinitekalgebra} one can get
  that there are finitely many maximal ideals $m_i$ and
  \[
  A \cong A/m_1^{k_1} \times \dots \times A/m_r^{k_r}
  \]
  \label{rem:lec5_own1}
\end{myremark}

\begin{definition}
  With \mynameref{thm:chineseremainder} we have
  \[
  A \cong A/m_1^{k_1} \times \dots \times A/m_r^{k_r}
  \]
  Reduced algebra $A_{red}$ is defined by the following equation
  \[
  A_{red} = A/m_1 \times \dots \times A/m_r
  \]
  \label{def:reducedalgebra}
\end{definition}

We have that
\footnote{
  i.e. nilpotents become zeros in the $A_{red}$.
}
\[
A_{red} = A /\eta\left(A\right)
\]
where $\eta\left(A\right)$ is an \mynameref{def:ideal} of
nilpotents in $A$.

It is clear that
\[
Hom_E\left(A, E\right) =
Hom_E\left(A_{red}, E\right)
\]
because all homomorphism into a field must be zero on all nilpotents
\footnote{
  It requires some clarification. Consider a homomorphism
  $\phi \in Hom_E\left(A, E\right)$. $\forall x,y \in A, \phi(xy) =
  \phi(x)\phi(y)$. Let $x \in \eta\left(A\right)$ i.e. $x$ is a
  nilpotent then $x \ne 0_A, x^k = 0_A$. We have
  \[
  0_E = \phi(x^k) = \phi(x)^k
  \]
  i.e. $\phi(x) =  0_E$. Therefore all nilpotents go to zero and,
  instead of $A$ (as the set the $\phi$ acts on), we can consider
  $A_{red}$. As result, we will get that $\phi(0_{A_{red}}) = 0_E$ and all
  other properties of homomorphism are also hold, for instance
  $\forall \bar{x},\bar{y} \in A_{red}: \phi(\bar{x}+\bar{y}) =
  \phi(\bar{x}) + \phi(\bar{y})$. Really
  $\bar{x} = x + \eta(A), \bar{x} = x + \eta(A)$ and
  \[
  \phi(\bar{x}+\bar{y}) =
  \phi(x+y) = \phi(x) + \phi(y) =
  \phi(\bar{x}) + \phi(\bar{y})
  \]
  as soon as $\phi(\eta(A)) = 0_E$.
}.

So again, we see that if there are nilpotents in the tensor product,
then there is somehow fewer space for homomorphisms. Because if A is
not reduced, then the dimension
\[
\left[A_{red} : E\right] < \left[A : E\right].
\]
So the maximal number of homomorphisms, so let's say the slogan
``Maximal number of homomorphisms'' is attained when $A$ is reduced
and all quotients
\begin{equation}
  A/m_i \cong E
  \label{eq:lec5_1}
\end{equation}
because those quotients are of
course extensions of $E$.
\footnote{
  as it was mentioned above $A = L \otimes_K E$ is a finite
  $E$-algebra i.e. $A$ is a $E$-extension. The $A/m$ is also
  $E$-algebra (see remark
  \ref{rem:lec5_quotientkalgebra}) i.e. also $E$-extension.

  From other hand we consider $Hom\left(A/m_i, E\right)$ i.e. there is
  a homomorphism (injection) from $A/m_i \to E$ and as result
  $A/m_i \cong E$. These arguments are also used in the text below for
  the fact explanation.
}
In general,
those quotients are extensions of $E$ (see remark
  \ref{rem:lec5_quotientkalgebra}). We also have
\[
A \cong A/m_1 \times \dots \times A/m_r
\]
but $Hom\left(A/m_i, E\right) = \{0\}$ if $\left[A/m_i: E\right] > 1$.
This is because a field homomorphism is always injective. A field
homomorphism a homomorphism of fields which are extensions of $E$  an
$E$-homomorphism is injective. So you cannot map an $E$-vector space of
dimension greater than 1 into an $E$-vector space of dimension 1.

Lets take $E = \bar{K}$ then automatically we will get
$A/m_i \cong E$ because an algebraically closed field does not have a
non trivial finite extension.

So what have we had (see also example \ref{ex:lec5_conrad})?
\[
A = L \otimes_K \bar{K},
\]
\begin{equation}
  A_{red} = \prod_{i=1}^r \bar{K}.
  \label{eq:lec5_AredIsProd}
\end{equation}
The following one $A = A_{red}$ is the same to $r$ is maximal and
equal to $\left[L:K\right] = \left[A: \bar{K}\right]$.
\footnote{
  It is because there are $\left[L:K\right] = r$ roots of a
  polynomial and all the roots are in $\bar{K}$. Each root $\alpha_i$
  forms a polynomial $X - \alpha_i$ which creates an ideal $m_i =
  \left(X - \alpha_i\right)$. We also have
  $L = K\left(\alpha_1, \dots, \alpha_r\right)$ and
  \[
  A = L \otimes_K \bar{K} \cong \bar{K} \otimes_K L =
  \bar{K} \otimes_K K\left(\alpha_1, \dots, \alpha_r\right).
  \]
  It expands to (see example \ref{ex:lec4_1})
  \begin{eqnarray}
    A \cong \bar{K} \otimes_K \frac{K\left[X\right]}{(X-\alpha_1)
      \dots (X-\alpha_r)} \cong
    \nonumber \\
    \cong
    \frac{\bar{K}\left[X\right]}{\left(X - \alpha_1\right)}
    \times
    \dots
    \times
    \frac{\bar{K}\left[X\right]}{\left(X - \alpha_r\right)}
    \cong \bar{K} \times \dots \times \bar{K}.
    \nonumber
  \end{eqnarray}
}
In the case
\[
r = \left|Hom_{\bar{K}}\left(A, \bar{K}\right)\right| =
\left|Hom_K\left(L, \bar{K}\right)\right|
\]
So this explains why seperability is the same thing as the absence of
nilpotents. So let me formulate it as a theorem.

\begin{theorem}
  Let $L$ is a finite extension over $K$ then
  \begin{enumerate}
  \item $L$ is separable if and only if $L \otimes_K \bar{K}$
    is \mynameref{def:reduced}.
    $L$ is pure inseparable if and only if $L \otimes_K \bar{K}$
    is \mynameref{def:local}
  \item $L$ is separable if and only if for all algebraic extension
    $\Omega$, $L \otimes_K \Omega$ is reduced.
    $L$ is pure inseparable if and only if for all algebraic extension
    $\Omega$, $L \otimes_K \Omega$ is local.
  \item If $L$ is separable then the map
    \[
    \phi: L \otimes_K \bar{K} \to \bar{K}^n
    \]
    which sends
    \[
    \phi\left(l \otimes k\right) =
    \left(
    k \phi_1\left(l\right),
    \dots,
    k \phi_n\left(l\right)
    \right)
    \]
    where $\phi_i$ are distinct homomorphisms from $L$ to $\bar{K}$,
    is an isomorphism.
  \end{enumerate}
  \label{thm:lec5_1}
  \begin{proof}
    \begin{enumerate}
    \item $L$ separable is the same thing that the algebra
      $A = L\otimes_K \bar{K}$ has $\left[L:K\right]$ factors
      \footnote{
        If we have $L = K\left(\alpha\right)$
        (see theorem \ref{thm:lec3_3}) then
        there exists a minimal polynomial $P_{min}\left(\alpha,
        K\right)$ of degree $r = \left[L:K\right]$. The polynomial
        splits and has $r$ roots: $\alpha_1, \dots, \alpha_r$. Thus we
        have $r$ maximal ideals
        \(
        m_1 = \left(X - \alpha_1\right), \dots,
        m_r = \left(X - \alpha_r\right)
        \).
        For each maximal ideal we have $A/m_i \cong A$ (see claim
        \ref{claim:lec1_fieldquotionisomorphism}) thus with theorem
        \ref{thm:structurefinitekalgebra} and (\ref{eq:lec5_1}) we have
        \[
        A \cong \prod_{i=1}^r \bar{K}
        \]
      }
      $\bar{K}$ which is the same as $A$ is \mynameref{def:reduced}
      since $\dim_{\bar{K}} A = \left[L:K\right]$.
      \footnote{
        From (\ref{eq:lec5_AredIsProd}), if $A = A_{red}$, one can get
        $\dim_{\bar{K}} A = \dim_{\bar{K}} A_{red} = \dim_{\bar{K}}
        \prod_{i = 1}^r \bar{K} = r = \left[L:K\right]$.
      }

      $L$ is pure inseparable: this means that exists only one
      homomorphism of $L$ into $\bar{K}$ i.e. $A$ has only one
      $\bar{K}$-homomorphism into $\bar{K}$ thus only one factor and
      as result $A$ is \mynameref{def:local}.
    \item If $\Omega$ is an algebraic extension then
      \footnote {
        i.e. we can setup an \mynameref{def:injection} and structure
        preserving map $f: L \otimes_K \Omega \to L \otimes_K
        \bar{\Omega}$ (see definition \ref{def:embedding})
      }
      \[
      L \otimes_K \Omega \hookrightarrow L \otimes_K \bar{\Omega} =
      L \otimes_K \bar{K}.
      \]
      There is a sub-ring and so one easily checks, that a sub-ring of
      a reduced algebra is reduced and same for local.
    \item Leave as an excises
      \footnote{
        Accordingly \cite{mathstackexchange:tensorproduct} we have the
        following proof.
        Let $l_1, l_2, \dots, l_n$ is a $K$ basis in $L$.
        Then we can
        get the following elements of $\bar{K}^n$:
        $v_i = \left(\phi_1(l_i), \phi_2(l_i), \dots,
        \phi_n(l_i)\right)$. We can construct the following matrix if
        we put the $v_i$ vectors as columns:
        \[
        \begin{bmatrix}
          \phi_1(l_1) & \phi_1(l_2) & \cdots & \phi_1(l_n) \\
          \phi_2(l_1) & \phi_2(l_2) & \cdots & \phi_2(l_n) \\
          \vdots & \vdots & \ddots & \vdots \\
          \phi_n(l_1) & \phi_n(l_2) & \cdots & \phi_n(l_n) \\
        \end{bmatrix}
        \]
        Linear dependence relation between rows looks like
        \begin{eqnarray}
          \sum_{k=1} c_k \phi_k(l_i) = 0.
          \label{eq:lec5_note_isom}
        \end{eqnarray}
        Thus $\forall l \in L^\ast, \exists \{k_i\} \subset K: l =
        \sum_{i=1}^nk_i l_i$ (as soon as $\{l_i\}$ is the $K$ basis of
        $L$). Thus after multiplication (\ref{eq:lec5_note_isom}) by
        $k_i$ and summation we have
        \begin{eqnarray}
         \sum_{i=1} k_i \sum_{k=1} c_k \phi_k(l_i) =
        \sum_{k=1} c_k \phi_k(l) = 0
        \nonumber
        \end{eqnarray}
        that should hold for any $k_i$ and as result for any $l$. By
        theorem \ref{thm:dedekind} we can conclude that $\forall k:
        c_k = 0$. As result we have the set $\{v_i\}$ as linear
        independent. The size of the set is $n = \dim \bar{K}^n$
        i.e. $\{v_i\}$ is the $\bar{K}$ basis of $\bar{K}^n$.
      }
    \end{enumerate}
  \end{proof}
\end{theorem}
\begin{remark}
In general for modules $M$, $N$ and $P$ over a ring $R$ \textbf{not true} that
if $M \hookrightarrow N$ ($M$ is a sub module of $N$) then
$M \otimes_R P \hookrightarrow N \otimes_R P$. But this become the
truth if $R$ is a field and as result $M,N,P$ are
\mynameref{def:vectorspace}s. So, for my field extensions, I can say
that if I have an extension and then I take a base change, then it
remains an extension, but  you should not think that the same thing is
true for arbitrary modules over a ring.
\end{remark}

\begin{myexample}
  The example was taken from \cite{bib:KeithConradSeparability2}.
  Consider extension $\mathbb{Q}\left(\sqrt{2}\right)$ over
  $\mathbb{Q}$. Since
  \[
  \mathbb{Q}\left(\sqrt{2}\right) \cong
  \mathbb{Q}\left[X\right]/\left(X^2 - 2\right)
  \]
  tensoring with $\mathbb{Q}$ gives
  \begin{eqnarray}
    \mathbb{Q}\left(\sqrt{2}\right) \otimes_{\mathbb{Q}}
    \bar{\mathbb{Q}} \cong
    \bar{\mathbb{Q}} \otimes_{\mathbb{Q}}
    \mathbb{Q}\left(\sqrt{2}\right)
    \cong
    \nonumber \\
    \cong
    \bar{\mathbb{Q}} \otimes_{\mathbb{Q}}
    \mathbb{Q}\left[X\right]/\left(X^2 - 2\right)
    \cong
    \nonumber \\
    \cong
    \bar{\mathbb{Q}}\left[X\right]/
    \left(
    \left(X - \sqrt{2}\right)
    \left(X + \sqrt{2}\right)
    \right)
    \cong
    \nonumber \\
    \cong
    \bar{\mathbb{Q}}\left[X\right]/\left(X - \sqrt{2}\right)
    \times
    \bar{\mathbb{Q}}\left[X\right]/\left(X - \sqrt{2}\right)
    \cong
    \bar{\mathbb{Q}} \times \bar{\mathbb{Q}}
    \nonumber
  \end{eqnarray}
  We used the following fact (see claim
  \ref{claim:lec1_fieldquotionisomorphism})
  \[
  \bar{\mathbb{Q}}\left[X\right]/\left(X \pm \sqrt{2}\right)
  \cong
  \bar{\mathbb{Q}}
  \]
  \label{ex:lec5_conrad}
\end{myexample}

\section{Primitive element theorem}

\begin{definition}[Idempotent]
  The element $x$ is called idempotent if $x \cdot x = x$
  \label{def:idempotent}
\end{definition}

\begin{theorem}[Primitive element]
  Let $L$ is a finite \mynameref{def:separableextension} of $K$ then it
  has only finitely many sub extensions i.e. $E$ such that $K \subset
  E \subset L$.
  \begin{proof}
    So, let's base change to $\bar{K}$
    \footnote {
      see proof of theorem \ref{thm:lec5_1} (second part of it).
    }
    :
    \(
    E \otimes_{K} \bar{K} \hookrightarrow
    L \otimes_{K} \bar{K}
    \)
    \footnote{
      See also proof of theorem \ref{thm:lec5_1}.
    }.
    We also have (see also equation (\ref{eq:lec5_AredIsProd}))
    \[
    E \otimes_{K} \bar{K} \cong \bar{K}^m
    \]
    and
    \[
    L \otimes_{K} \bar{K} \cong \bar{K}^n
    \]
    are reduced $\bar{K}$ sub-algebras generated by
    \mynameref{def:idempotent}s namely by
    \[
    e_i = \left(0,0, \dots, 1, \dots, 0\right),
    \]
    where $1$ is in $i$-th place
    \footnote{
      this is because the typical element $k \in \bar{K}^n$ has the
      following form
      \[
      k = \left(k_1, k_2, \dots, k_n\right) = \sum_{i=1}^n k_i e_i,
      \]
      where $k_i \in \bar{K}$.
    }.

    On the other hand $L \otimes_K \bar{K} \cong \bar{K}^n$ has only
    finitely many \mynameref{def:idempotent}s because
    $\left(a_1, \dots, a_i, \dots, a_n\right)$ is an idempotent if and
    only if all $a_i$ are 0 or 1 and therefore there
    are only finitely many ways to choose $m$ idempotents out of them,
    \footnote{
      we have the following equation
      \[
      \bar{K}^m \hookrightarrow \bar{K}^n
      \]
    }
    so there is only finitely many ways to generate a subalgebra.
  \end{proof}
  \label{thm:primitiveelement}
\end{theorem}

\begin{corollary}[Primitive element theorem]
  $\exists \alpha \in L$ such that $L = K\left( \alpha \right)$
  whenever $L$ is finite and separable.
  \begin{proof}
    And this is easy to see, of course, because
    if $L$ and $K$ are infinite, then
    $L$ cannot be a union, a finite union of proper subextension.
    A vector space over an infinite field is not a finite union of
    proper subspaces.   For instance a plane is not a finite union of
    lines.
    \footnote{
      It will require some additional explanations. Took
      $\alpha \in L$ such that $P_{min}\left(\alpha, K\right)$ has
      maximal degree. If $K\left(\alpha\right) = L$ we complete and
      found the primitive element. If not then let
      $\beta \in L \setminus K\left(\alpha\right)$. Consider the
      following element $\gamma_a = \alpha + a \beta$ where $a \in
      K$. For any $a \in K$ exists $K\left(\gamma_a\right)$ such that
      $K \subset K\left(\gamma_a\right) \subset L$. We have
      $\left|K\right| = \infty$ but the
      number of sub-extensions is limited by theorem
      \ref{thm:primitiveelement} therefore $\exists a, b \in K$ such that
      $a \ne b$ and $K\left(\gamma_a\right) =
      K\left(\gamma_b\right) = K\left(\gamma\right)$ where $\gamma =
      \gamma_a$.

      We have $\gamma_a - \gamma_b = (a-b) \beta \in K\left(\gamma\right)$, i.e.
      $\beta \in K\left(\gamma\right)$. Therefore
      $\alpha = \gamma_a -a \beta = \gamma -a \beta \in
      K\left(\gamma\right)$. We also
      have (as soon as $\beta \notin
      K\left(\alpha\right)$) $K \subset K\left(\alpha\right)
      \subsetneq K\left(\gamma\right)
      \subset L$. Thus $\left[K\left(\gamma\right):K\right] >
      \left[K\left(\alpha\right):K\right]$. Therefore
      (see proposition \ref{prop:dimextension})
      \[
      \deg\left(P_{min}\left(\gamma, K\right)\right) >
      \deg\left(P_{min}\left(\alpha, K\right)\right)
      \]
      that is in contradiction with $\alpha$ choose.

      Note that \cite{bib:KenBrownPrimitiveElementTheorem} has another,
      more known, proof for the fact and prove that if
      $L = K\left(\alpha, \beta\right)$ then $\exists \lambda \in K$
      such that $\gamma = \alpha + \lambda \beta$ is the primitive
      element i.e. $L = K\left(\gamma\right) = K\left(\alpha,
      \beta\right)$.
    }

    If $L$ and $K$ are \mynameref{def:finitefield}s, then we have
    already described this situation completely. We have described all
    finite extensions and have seen that they are generated by one element.
    \footnote{
      As it was mentioned in the proof of corollary \ref{cor:lec3_1}
      we can take $\alpha = \mbox{ generator of } K^\times$. For more info
      see corollary \ref{cor:lec3_1}.
    }
  \end{proof}
  \label{col:primitiveelement}
\end{corollary}

\section{Examples. Normal extensions}

\subsection{Examples}

\begin{example}[Primitive element]
  \[
  \mathbb{Q}\left(\sqrt{2}, \sqrt{3}\right) =
  \mathbb{Q}\left(\sqrt{2} + \sqrt{3}\right).
  \]
  We have
  $\left[\mathbb{Q}\left(\sqrt{2}, \sqrt{3}\right) :
    \mathbb{Q}\right] = 4$ so all sub-extensions are quadratic.
  \footnote{
    As soon as extension has degree $4 = 2 \cdot 2$ then a
    sub-extension should have
    degree 2 and the minimal polynomial should be quadratic.
  }
  As no
  quadratic polynomial has $\alpha = \sqrt{2} + \sqrt{3}$ for a root
  \footnote{
    Quadratic polynomials have very simple formula for roots with
    only one square (discriminant) and it is not possible to get 2
    squares with it
  },
  $\alpha$ generates $\mathbb{Q}\left(\sqrt{2}, \sqrt{3}\right)$.

  This must be a primitive element, generates our field.
  It is not contained in any proper subextension.

  There is another proof (not part of the lectures) that shows that
  $\beta = \sqrt{2} + \sqrt{3}$ is a primitive element i.e.
  $\sqrt{2}, \sqrt{3}$ are generated by $\beta$. Really
  $\beta^2 = 5 + 2 \sqrt{2}\sqrt{3}$ i.e.
  \[
  \sqrt{2}\sqrt{3} = \frac{\beta^2 - 5}{2}.
  \]
  From other side
  \[
  \sqrt{2} \beta = \sqrt{2}\left(\sqrt{2} + \sqrt{3}\right) =
  2 + \sqrt{2}\sqrt{3} = \frac{\beta^2 - 1}{2}.
  \]
  Therefore
  \[
  \sqrt{2} = \frac{\beta^2 - 1}{2 \beta}
  \]
  and
  \[
  \sqrt{3} = \beta - \frac{\beta^2 - 1}{2 \beta}.
  \]
  \label{ex:lec5_primitiveelement}
\end{example}

\begin{example}[Extension which cannot be generated by a single element]
  So, take $K$ equal to $\mathbb{F}_p$ and consider
  $K\left(x,y\right)$ as an
  extension of $K\left(x^p,y^p\right)$. It has degree $p^2$
  \footnote {
    $K \subset K\left(x^p\right) \subset K\left(x^p,y^p\right)$ and
    $\left[K\left(x^p\right): K\right] = p$ as well as
    $\left[K\left(x^p, y^p\right): K\left(x^p\right)\right]$ thus with
    theorem \ref{thm:mulformuladegrees}
    \[
    \left[K\left(x^p, y^p\right): K\right] = p^2.
    \]
  }
  i.e.
  \[
  \left[
    K\left(x,y\right) : K\left(x^p,y^p\right)
    \right] = p^2.
  \]
  We have $\forall \alpha \in K\left(x,y\right) \setminus
  K\left(x^p,y^p\right)$ is of degree $p$ over
  $K\left(x^p,y^p\right)$. This is because
  $\alpha^p \in K\left(x^p,y^p\right)$
  \footnote{
    $\alpha = k_1 x + k_2 y$, where $k_1, k_2 \in K =
    \mathbb{F}_p$. Using remark \ref{rem:frobeniushomomorphism} we can
    get
    \[
    \alpha^p = k_1^p x^p + k_2^p y^p \in K\left(x^p, y^p\right).
    \]
  }
  . So, no element like these can
  generate our extension.
\end{example}

\subsection{Normal extensions}

\begin{definition}[Normal extension]
  A normal extension of $K$ is a \mynameref{def:splittingfield} of a
  family of polynomials
  \footnote {
    There is a set of polynomials (can be only one polynomial in the
    set) and the polynomials not necessary to be irreducible. Example
    $\mathbb{Q}/\mathbb{Q}$ - is a normal
    extension because there is a set of polynomials split in it :
    $\left\{X-1, X^2-1\right\}$. Note that any irreducible polynomial
    (another definition below) that has a root in it also splits, for
    instance $X - a$, where $a \in \mathbb{Q}$ is an irreducible, has
    a root $a \in \mathbb{Q}$ and splits in it. From other side an
    arbitrary polynomial ( for example $X^3-1$ ) can have a root in
    $\mathbb{Q}$ but does not necessary split in it.
  }
  in $K\left[X\right]$.
  \footnote{
    Another good definition of a normal extension
    \cite{wiki:normalextrus} can also be used. Normal extension $E/K$ is
    such algebraic extension in which every irreducible polynomial
    $P(X) \in K\left[X\right]$ that has a single root in $E$ splits in
    $E$.
  }
  \label{def:normalextension}
\end{definition}

\begin{remark}[Normal extension]
  So, take a bunch of polynomials in $K$ and we adjoin all their roots
  to $K$, and this is what is called a normal extension.
  For instance, a \mynameref{def:splittingfield} of one polynomial is
  also a normal extension.
\end{remark}

\begin{theorem}
  The following conditions are equivalent for an extension $L$ of $K$:
  \begin{enumerate}
  \item $\forall x \in L$ $P_{min}\left(x, K\right)$ splits in $L$.
  \item $L$ is \mynameref{def:normalextension}
  \item All \mynameref{def:homomorphism}s from $L$ to $\bar{K}$ have the
    same image.
    \footnote{
      And the image is $L$ as soon as $id$ is also a
      \mynameref{def:homomorphism}

      There are 2 staff's comments about the claim:
      \begin{itemize}
      \item You can't naturally identify $L$ with a particular
        subfield of $\overline{K}$ (unless $L$ is given as a
        subfield of $\overline{K}$ a priori). But from the lecture
        2.5 (see theorem \mynameref{thm:lec2_3}) we know, that there
        exists an embedding $L
        \hookrightarrow \overline{K}$ since $L$ is algebraic
        over $K$. And the theorem says that images of all such
        embeddings are equal if $L$ is normal over $K$.
      \item My previous answer was a little bit misleading. I meant,
        if you have an arbitrary algebraic extension of $K$, there
        is no canonical embedding into $\overline{K}$.

        % Was removed by the staff
        %% Consider, for
        %% example, a field $\mathbb{Q}/(x^3-2)$. It has several
        %% embeddings into $\overline{\mathbb{Q}}$,
        %% namely, $\mathbb{Q}(\sqrt[3]{2})$, $\mathbb{Q}(e^{2\pi
        %%   i/3}\sqrt[3]{2})$ and $\mathbb{Q}(e^{2\pi
        %%   i/3}\sqrt[3]{2})$. But if we consider the splitting field
        %% of $x^3-2$, then it's image in $\overline{\mathbb{Q}}$
        %% is $\mathbb{Q}(\sqrt[3]{2}, e^{2\pi i/3})$. So, yes,

        If we
        identify roots of polynomials which define $L$ with some
        elements of $\overline{K}$ (up to a permutation for each
        polynomial), then the image is $L$ itself.
      \end{itemize}

      As conclusion
      \cite{bib:baker} (p. 54),
      we can say that if $L$ is a splitting field of a
      polynomial $P$ (just another definition of normal extension
      \cite{bib:baker})
      with roots $\alpha_1, \alpha_2, \dots, \alpha_n$,  then
      $L=K\left(\alpha_1, \alpha_2, \dots, \alpha_n\right)$ and as
      soon as the homomorphism $\phi$ permutes the roots of $P$
      (if $L \subset \bar{K}$ or if we
      identify roots of polynomials which define $L$ with some
      elements of $\overline{K}$)
      :
      \begin{eqnarray}
      \phi\left(L\right) =
      \phi\left(K\left(\alpha_1, \alpha_2, \dots,
      \alpha_n\right)\right) =
      \nonumber \\
      K \left(\phi\left(\alpha_1\right),
      \phi\left(\alpha_2\right),
      \dots
      \phi\left(\alpha_n\right)
      \right) =
      K\left(\alpha_1, \alpha_2, \dots, \alpha_n\right) = L
      \nonumber
      \end{eqnarray}
    }
  \item The \mynameref{def:group} of \mynameref{def:automorphism}s
    $Aut\left(L/K\right)$ acts transitively (see definition
    \ref{def:transitive}) on this set of
    homomorphisms $Hom_K\left(L, \bar{K}\right)$.
  \end{enumerate}
  \label{thm:lec5_3}
  \begin{proof}
    1 implies 2: Take
    $\left(P_i\right)_{i \in I} = \left\{P_{min}\left(x, K\right) \mid
    x \in L\right\}$ - the set of polynomials
    (i.e. the family of polynomials).
    $L$ will be a splitting field of the set $\left(P_i\right)_{i \in
      I}$ and therefore (by definition \ref{def:normalextension}) $L$ is normal.

    2 implies 3: Let
    $S = \left\{\mbox{roots of } P_i, i \in I \mbox{ in } L\right\}$
    and
    $S' = \left\{\mbox{roots of } P_i, i \in I \mbox{ in }
    \bar{K}\right\}$
    \footnote{
      $S$ and $S'$ are 2 sets of roots
    }
    then any homomorphism
    $\phi: L \to \bar{K}$ sends $S$ to $S'$, but $S$ generates $L$
    over $K$, so $\phi\left(S\right)$ determines $\phi\left(L\right)$
    \footnote{
      As soon as $\phi(S) = S'$ then we have one set of roots and as
      result one image (that is generated by the set) for
      homomorphisms. Or more concrete, let $l \in L, S = \{s_i\}, S' =
      \{s'_i\}$. We have $l = \sum l_{ik}s_i^k$ where $l_{ik} \in K$.
      For the homomorphism $\phi$ we have
      $\phi(l) = \sum l_{ik}{s'}_i^k$ i.e. the image $\phi(L)$ consists
      of elements of the following form: $\sum l_{ik}{s'}_i^k$. For any
      homomorphism we will have the same form for the image or in
      other words - any homomorphism has the same image.
    }
    .

    3 implies 4: Let $j, j' \in Hom_K\left(L, \bar{K}\right)$
    (i.e. we took 2 homomorphisms)
    then
    they send $L$ isomorphically to its image $L'$. So, these are
    isomorphisms from $L$ to $L'$. So

    \begin{tikzpicture}[descr/.style={fill=white,inner sep=2.5pt}]
      \matrix (m) [matrix of math nodes, row sep=3em,
        column sep=3em]
              { & L' & \\
                L & & L\\ };
              \path[->,font=\scriptsize]
              (m-2-1) edge node[descr] {$ j' $} (m-1-2)
              (m-1-2) edge node[descr] {$ j^{-1} $} (m-2-3)
              (m-2-1) edge node[descr] {$ j^{-1}j' $} (m-2-3);
    \end{tikzpicture}

    take $j^{-1} \cdot j' \in Aut \left(L/K\right)$ and it sends $j$
    to $j'$
    \footnote{
      We have got that $\forall j, j' \in Hom_K\left(L,
      \bar{K}\right), \exists g \in Aut\left(L/K\right)$
      such that $g(j) = j'$, for instance $g = j^{-1}j'$ and
      \begin{equation}
        g(j) \equiv j g = j j^{-1} j' = j'.
        \label{eq:lec5_groupaction}
      \end{equation}
        Therefore group
      automorphisms acts transitively by the definition
      \ref{def:transitive}
    }.

    4 implies 1:  I have this \mynameref{def:transitive} and I have to prove
    that any minimal polynomial splits. Consider
    $P_{min}\left(x, K\right)$. $\alpha_1, \dots, \alpha_n$ - roots in
    $\bar{K}$. Then I have map $K\left(x\right) \to
    K\left(\alpha_i\right)$ that extends to
    $j_i: L \xrightarrow[x \to \alpha_i]{} \bar{K}$. This is by
    \mynameref{thm:lec2_3}.
    $\exists \theta_i \in Aut\left(L/K\right)$ such that
    $j_1 \theta_i = j_i$
    \footnote{
      as it was mentioned at the equation (\ref{eq:lec5_groupaction})
    }
    thus
    $\alpha_i \in j_1\left(L\right)$
    \footnote{
      $\theta_i: L \to L$ thus $j_1 \theta_i: L \to j_1(L)$
    }
    or all roots are in
    $j_1\left(L\right)$ and the polynomial
    $P_{min}\left(x, \bar{K}\right)$ splits over $j_1\left(L\right)$
    but this means that it splits over $L$
    \footnote{
      If $x = \alpha_1$ then $j_1 = id$ and $j_1(L) = L$
    }
  \end{proof}
\end{theorem}

\section{Galois extensions}

Now we are ready to give a definition for central object of Galois
theory

\begin{definition}[Galois extension]
  A Galois extension is a \mynameref{def:normalextension} and
  \mynameref{def:separableextension}.
  \label{def:galoisextension}
\end{definition}

\begin{theorem}
  Let $L$ be a finite over $K$ then the number of automorphisms
  $Aut\left(L/K\right)$ is less or equal to degree
  $\left[L:K\right]$:
  \[
  \left|Aut\left(L/K\right)\right| \le \left[L:K\right].
  \]
  The equality holds if and only if $L$ is
  \mynameref{def:galoisextension}.
  \label{thm:lec5_4}
  \begin{proof}
    We know that the group of automorphisms $Aut\left(L/K\right)$ acts
    freely (see definition \ref{def:freeaction}) on the set
    $Hom_K\left(L, \bar{K}\right)$,
    \footnote{
      Note that the number of distinct roots is equal to the number of
      distinct homomorphisms (see proposition \ref{prop:lec3_2}). Thus
      we can set an association between
      roots and homomorphisms. Proposition \ref{prop:stemfield}
      says that the stem
      field isomorphism (that translated to the considered
      automorphism) is unique determined by it's value on the roots that
      it exchanges. I.e. the the action of $Aut\left(L/K\right)$ on
      the set of roots (and as result on the set $Hom_K\left(L,
      \bar{K}\right)$) is exactly that one defined for
      \mynameref{def:freeaction}.

      See also first and second remarks at \ref{rem:lec5_onnormalext}.
    }
    so the number of
    automorphisms $\left|Aut\left(L/K\right)\right|$ is equal to the
    number of \mynameref{def:orbit} of this action which is less or
    equal
    \footnote{
      in ideal case each element has an unique orbit and the number of
      elements and the number of orbits are equal.
    }
    to the cardinality of the set it self:
    $\left|Hom_K\left(L, \bar{K}\right)\right|$. The equality holds
    whenever (if and only if) \mynameref{def:action} is
    \mynameref{def:transitive}.
    \footnote{
      This follows directly from the definition of
      \mynameref{def:transitive} i.e. $\forall h_1, h_2 \in
      Hom_K\left(L, \bar{K}\right)$ $\exists a \in
      Aut\left(L/K\right)$  such that $a(h_1) = h_2$.
    }
    We just seen in
    theorem \ref{thm:lec5_3} that this means that $L$ is normal over
    $K$. So we have
    \[
    \left|Aut\left(L/K\right)\right| \le
    \left|Hom_K\left(L, \bar{K}\right)\right| \le
    \left[L:K\right].
    \]
    The first inequality become equality if $L$ is normal and the
    second one if $L$ is separable
    \footnote{
      see definitions \ref{def:separabledegree} and
      \ref{def:separableextension}.
    }, thus
    \[
    \left|Aut\left(L/K\right)\right| \le \left[L:K\right]
    \]
    and equality holds if $L$ is both normal and separable i.e. if
    it's \mynameref{def:galoisextension}.
  \end{proof}
\end{theorem}

\begin{definition}[Set of invariants]
  If group $G$ acts on a set $X$ then $X^G = \left\{x
  \in X \mbox{ such that } gx = x, \forall g \in G\right\}$ - the
  set of invariants.
  \label{def:setinvariants}
\end{definition}

\begin{remark}[on normal extensions]
  \label{rem:lec5_onnormalext}
  If $L$ is normal over $K$ then
  \begin{enumerate}
  \item If we have an \mynameref{def:isomorphism} of sub-extensions
    ($K \subset L_1, L_2 \subset L$)
    $\phi: L_1 \cong L_2$ then it extends to an
    \mynameref{def:automorphism} of $L$.  To see this, we embed $L$ into
    an algebraic closure $\bar{K}$. And remark that $\phi$ extends to a
    map from $L_1$ to $\bar{K}$,
    \footnote{
      Ekaterina really said that but may be more better to say that
      $\phi$ extends to a map from $L$ to $\bar{K}$ ???
    }
    but all those maps have the same
    image (see theorem \ref{thm:lec5_3}), namely $L$
    \footnote{
      Consider $L_1 \subset L_2 \subset L \subset \bar{K}$ we have a
      homomorphism $\phi_1: L_1 \to L_2$ (our isomorphism) that
      accordingly theorem \ref{thm:lec2_3}, can be extended to
      homomorphism $L_1 \to \bar{K}$ and the last one can be extended
      to $\tilde{\phi_1}: L \to \bar{K}$. We can also consider
      $L_2 \subset L_1 \subset L \subset \bar{K}$ and homomorphism
      $\phi_2: L_2 \to L_1$ that can extended (using the same
      approach) to  $\tilde{\phi_2}: L \to \bar{K}$. Both
      $\tilde{\phi_{1,2}}$ has the same image $L$ as soon as $L$ -
      normal extension (see theorem \ref{thm:lec5_3}). Thus we have an
      \mynameref{def:automorphism}.
    }.
  \item \label{rem:item:lec5_onnormalext_2} The group of automorphisms $Aut\left(L/K\right)$ acts
    transitively on the roots of any irreducible polynomial $P \in
    K\left[X\right]$. Again, an isomorphism of stem fields extends to
    an automorphism of $L$
    \footnote{
      In the case we have \mynameref{def:transitive} i.e. for any roots
      $x,y$ we have an isomorphism of stem fields $\phi$ such that
      $\phi(x) = y$ (see proposition \ref{prop:stemfield}). This
      isomorphism extends to an automorphism accordingly the
      prev. remark.
    }.
  \item If the group $Aut\left(L/K\right)$ fixes (see definition
    \label{rem:item:lec5_onnormalext_3}
    \ref{def:fixedpoint}) some element $x \notin K$ then $x$ is pure
    inseparable (see definitions
    \ref {def:deginseppol} and \ref{def:degsepelem}) i.e.
    $P_{min}\left(x, K\right)$ has a
    single root $x$. Thus if $L$ is
    \mynameref{def:galoisextension} (i.e. is separable) then
    the set of elements which are fixed  by the automorphisms  of $L$
    over K is just K itself:
    $L^{Aut\left(L/K\right)} = K$
    (see definition \ref{def:setinvariants}).
    \footnote{
      Another explanation is the following. Let $x \in L \setminus K$
      then $g \in Aut\left(L/K\right)$ such that $g \ne id$ permutes
      roots of irreducible $P_{min}\left(x, K\right)$ and $g(x) = x'
      \ne x$. The only thing that works for
      $\forall g \in Aut\left(L/K\right)$ is $K$ i.e.
      $\forall k \in K$ and $\forall g \in Aut\left(L/K\right)$ we
      have $g(k) = k$. This is because $P_{min}\left(x, K\right) = X
      - k$ i.e. only one root possible.
    }
  \end{enumerate}
\end{remark}

\begin{definition}[Galois group]
  If $L$ is \mynameref{def:galoisextension} then Galois group $G =
  Gal\left(L/K\right)$ is the group of automorphisms $Aut\left(L/K\right)$.
  \label{def:galoisgroup}
\end{definition}

Thus we can write
\begin{equation}
  L^{Gal\left(L/K\right)} = K.
  \label{eq:lec5_2}
\end{equation}

\section{Artin's theorem}

Motivated by (\ref{eq:lec5_2}) let formulate and proof the important
theorem
\begin{theorem}[Artin]
  \label{thm:artin}
  $L$ is a field and $G \subset Aut\left(L\right)$
  \begin{enumerate}
  \item If $G$ acts with finite orbits,  so, I mean all orbits of G
    are finite (i.e. $\forall x \in L: \left|Orb(x)\right| < \infty$),
    then $L$ is a \mynameref{def:galoisextension} of $L^G$.
  \item If $\left|G\right| = n < \infty$ then
    $\left[L : L^G\right] = n$ and $G$ is a \mynameref{def:galoisgroup}
  \end{enumerate}

  \begin{remark}
    Well notice, that acting with finite orbits  and being finite is not
    the same thing. So, a short remark before giving a proof: notice
    that finite orbits does not mean finiteness because it's typical for
    Galois groups to act with finite orbits.  If we have some G, which
    is Galois of $L$ over $K$: $G = Gal\left(L/K\right)$, and
    $x \in L$, then $x$ is a root of a
    polynomial of some finite degree  and it's splitting field is
    finite over $K$, so, the orbit of $x$ is also finite
    because it's always sent to another root of the
    same polynomial and so consists of roots of  the
    $P_{min}\left(x, K\right)$. But of course the Galois group itself
    $Gal\left(L/K\right)$ can be infinite when $L$ is not finite over $K$. For
    instance, if  $K  = \mathbb{F}_p$ and $L = \overline{\mathbb{F}_p}$. It is
    very easy to compute all the Galois groups, and in fact we shall see
    shortly what is exactly this Galois group of $L$ over $K$ is infinite.
    \footnote{
      Section \ref{sec:lec6_finitefield} shows that
      $Gal\left(\bar{\mathbb{F}}_p/\mathbb{F}_p\right)$ is not cyclic,
      but theorem \ref{thm:lec3_2} says that if $G$ is finite than it
      should be cyclic. Thus we can conclude that
      $Gal\left(\bar{\mathbb{F}}_p/\mathbb{F}_p\right)$ is not finite
    }
  \end{remark}
  \begin{proof}
    \begin{enumerate}
    \item  Let me take $x$, well say, $x_1 \in L$ which is not
      $G$-invariant: $x_1 \in L \setminus L^G$ and
      $G$-\mynameref{def:orbit} of $x$
      $Orb(x) = \{x_1, x_2, \dots, x_k\}$. The
      polynomial $P\left(X\right) = \prod_{i=1}^k\left(X - x_i\right)$
      is $G$-invariant
      \footnote{
        I.e. $\forall g \in G: g\left(P\left(X\right)\right) =
        P\left(X\right)$
      }
      . $G$ just permutes  the $x_i$, it permutes the factors of these
      polynomial,
      so the polynomial is $G$-invariant. Therefore its coefficients are
      $G$-invariant and as result $P \in L^G\left[X\right]$ by
      definition \ref{def:setinvariants}. $L^G$ is a field of $G$
      invariants, and it is
      separable. $P$ is separable,
      because all $x_i$ are distinct ( there are distinct elements of the
      orbit ). And $L$ is splitting field of $P$, therefore $L$ is a
      \mynameref{def:galoisextension} over $L^G$ by the
      \mynameref{def:galoisextension} definition.
    \item We have $\left|G\right| = n$ then
      $\forall y \in L: \left|Orb\left(y\right)\right| \le n$. Take
      $x$ as above ($x \in L \setminus L^G$)
      $\left[L^G\left(x\right): L^G\right] \le n$.
      \footnote{
        $x$ is a root of the following polynomial $P\left(X\right) =
        \prod_{i=1}^k\left(X - x_i\right)$, where $x_i \in
        Orb(x)$. The polynomial has degree $\deg P =
        \left|Orb(x)\right| \le n$ and
        $\deg P_{min}\left(x, L^G\right) \le \deg P \le n$ therefore
        $\left[L^G\left(x\right): L^G\right] \le n$.
      }
      Claim that this
      implies $\left[L:L^G\right] \le n$. If I knew already, that $L$ is
      finite over $L^G$, this would be very easy, this would be just a
      direct consequence of \mynameref{thm:primitiveelement}. I
      would say that $L$ is generated by one element. I take this one element as
      my $x$ and I see that $L$ is of degree at most $n$ over $L^G$. But I
      don't know yet that $L$ is finite so I have to do some trick. So,
      proof of the claim:  take $x$ such that
      $\left[L^G\left(x\right):L^G\right]$ is maximal then take $y \in
      L$. $L^G\left(x,y\right)$ is finite over $L$
      \footnote{
        because $x,y$ are algebraic elements and using theorem
        \ref{thm:lec1_2} and proposition \ref{prop:lec1_1} we can
        conclude that $L^G\left(x,y\right)$ is finite over $L$.
      }
      and I can apply
      \mynameref{thm:primitiveelement}. Therefore
      $L^G\left(x,y\right) = L^G\left(z\right)$. But
      \[
      \left[L^G\left(x\right):L^G\right] \ge
      \left[L^G\left(z\right):L^G\right]
      \]
      thus $L^G\left(x\right) = L^G\left(z\right)$ so
      $y \in L^G\left(x\right)$ and since I can do this for any $y$, I
      eventually conclude that $L = L^G\left(x\right)$, and in
      particular, $\left[L: L^G\right] \le n$. Well, now if this is
      strictly less than $n$, then $L$ cannot have $n$ automorphisms
      over $L^G$ but $G \subset Aut\left(L/L^G\right)$ so this is a
      contradiction. Therefore $\left[L: L^G\right] = n$ and
      $G = Aut\left(L/L^G\right)$ (see theorem \ref{thm:lec5_4}).
    \end{enumerate}
  \end{proof}
\end{theorem}


\documentclass{article}
\usepackage[utf8]{inputenc}

\title{\large{\textsc{Dynamic Programming 01}}}
\date{}

\usepackage{natbib}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage[a4paper, portrait, margin=0.8in]{geometry}

\usepackage{listings}

\newcommand\perm[2][n]{\prescript{#1\mkern-2.5mu}{}P_{#2}}
\newcommand\comb[2][n]{\prescript{#1\mkern-0.5mu}{}C_{#2}}
\newcommand*{\field}[1]{\mathbb{#1}}

\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}

\newcommand{\Mod}[1]{\ (\text{mod}\ #1)}

\begin{document}

\maketitle

\subsection*{}

For the problems below, identify the subproblem, recurrence relation, and time complexity using dynamic programming. If you finish, both problems are on your homework, so you can begin coding them up.

%%%%% PROBLEMS %%%%

\begin{enumerate}

%%%%% PROBLEM 1 %%%%%
\item There are many cases in which it can be helpful to determine how different one string is from another.  Spellcheck programs use this concept to determine the most likely word attempted, biologists use it to determine how well one strand of DNA matches another, and machine translation programs use it to predict the accuracy of a generated sentence.

Given two strings $a$ and $b$, return the minimum number of operations required to convert string $a$ to string $b$. You can apply three different operations to the first string:

\begin{itemize}
    \item Insert a new character
    \item Delete and existing character
    \item Replace one character with another
\end{itemize}

For example:

\begin{lstlisting}
a = "sunday"
b = "saturday"

editDistance = 3

Steps: replace n with r, insert t, insert a
\end{lstlisting}

%%%%% PROBLEM 2 %%%%%
\item Monsters have captured Professor Nick, `N`, and imprisoned him in the bottom-right corner of the Academic Center.  The monsters also went ahead with the old remodelling plan, so the AC now consists of M x N rooms laid out in a 2D grid.  The rest of our valiant teaching team, `T`, will need to fight through the rooms of monsters in order to save Nick.

The teaching team has a health level indicated by the integer `h`.  If h drops to `0` or below at any point, everyone died, and Nick is stuck with the monsters.

Each room has either a monster or a health power up (e.g. coffee, monster fighting weapons, etc.) and will increase or decrease the health of the teaching team by the integer amount given for that room.

Given the 2D array of integers representing the health values of each room in the AC, assuming the teaching team starts in the top-left corner and Nick in the bottom-right corner, and assuming that the teaching team only moves right or down, return the **minimum initial health** required to save Professor Nick.  We need to know how much coffee to drink before attempting the rescue.

Example:

\begin{lstlisting}
-------------------------
| -2 (T) |  -3	|   3   |
-------------------------
|   -5   | -10  |   1   |
-------------------------
|   10   |  30  | -5 (S)|
-------------------------

map = {{-2, -3, 3}, {-5, -10, 1}, {10, 30, -5}}

minInitialHealth = 7, following the optimal path R -> R -> D -> D
\end{lstlisting}

%%%%% PROBLEM 3 %%%%%
\item Jingyi has a stack of coins and would like to split them up as evenly as possible with David. She is given a set of $N$ coins. Each of these coins has a given value. She must place each of these coins in one of two piles. Output the smallest possible difference between the total values of these two piles.

You are given

coins, an array of all the coins Jingyi must split
You will be filling out the function public int splitCoins(int[] coins) in $Coins.java$ and run tests in $CoinsTest.java$

For example, if she had the coins \{3,1,1,2,5,7\}, she can try to split them up into \{3,5\} and \{1,1,2,7\} and the difference between these two piles would be 3. The more optimal splitting is \{3, 2, 5\} and \{1, 1, 7\}, for a difference of 1.

\end{enumerate}

\newpage

\begin{center}
Solutions
\end{center}

%%%%% SOLUTIONS %%%%%
\begin{enumerate}

%%%%% Solution 1 %%%%%
\item
\begin{lstlisting}

Subproblem: String suffixes, cut off front letters (could also do back, but the
            suffixes concept provides a comparison to the text justification example
            from lecture)

Recurrence Relation: dp[i][j] = 1 + min(dp[i][j-1], dp[i-1][j], dp[i-1][j-1]);
                        min gets min DP of insert, remove, or replace

Runtime: O(MN), where m and n are the lengths of a and b

\end{lstlisting}

%%%%% Solution 2 %%%%%
\item
\begin{lstlisting}

Subproblem: min hp needed at position working back from target

Recurrence Relation: int down = Math.max(health[i + 1][j] - map[i][j], 1);
                     int right = Math.max(health[i][j + 1] - map[i][j], 1);
                     health[i][j] = Math.min(right, down);

Runtime: O(MN) where m and n are the dimensions of the dungeon

\end{lstlisting}

%%%%% Solution 3 %%%%%
\item
\begin{lstlisting}

Subproblem: Subproblem is DP\[i, j\], where i is the number of coins already placed
and j is the amount in the left pile

Guess: Do you put the coin in the left pile or not?

Recurrence Relation: DP\[i, j\] = whichever of (DP\[i+1, j\],
                                                DP\[i+1, j+coins\[i\]\])
                                is closer to sum(coins)/2

Runtime: O(ns) where n the number of coins and s is the sum of the coins

\end{lstlisting}

\end{enumerate}

\end{document}


\section{Feedback (informally)}
\subsection{}

\begin{frame}\mccz
\frametitleTC{Feedback and its magic}
\myPause
 \begin{columns}
  \column[T]{0.45\textwidth}
   \only<2->{\centering\includegraphics[height=6cm]{./Unit-02/img/Feedback-TheMagic_cc0.jpg}}\myPause%
  \column[T]{0.55\textwidth}
   \begin{itemize}[<+-| alert@+>]
   \item If PROPERLY used, feedback can
         \begin{itemize}[<+-| alert@+>]
         \item \vspace{2mm}counteract model errors\\
                and uncertainties,
         \item \vspace{2mm}reject a disturbance\\
                without the need\\
                for its measurement,
         \item \vspace{2mm}stabilise an unstable\\
               or ``runaway'' system.
         \end{itemize}
   \item \vspace{4mm}Let us see.
   \end{itemize}
 \end{columns}
\end{frame}

\begin{frame}
\frametitleTC{Feedback to counteract model errors/uncertainty and disturbances}
\framesubtitleTC{(to introduce this idea we do not use dynamic systems for simplicity)}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item \vspace{-8mm}Consider a controlled system such that the outcome $O$ depends on the control action $A$ and
       the disturbance $D$ as \textcolor{magenta}{$O=0.5(A+D)$.}
 \item If we want to use open-loop control and to make $O$ equal a reference $R$, we must solve for $A$ the equation
       $0.5(A+D)=R$, whence the control law \DG{$A=2R-D$.}
 \item Let us verify with some numbers:
 \item[] \begin{center}
          \includegraphics[width=0.60\columnwidth]{./Unit-02/img/Taxonomy-OpenLoop-Example-FullKnowledge.pdf}
          \hspace{6mm}\includegraphics[height=1.5cm]{./Unit-02/img/smile.png}
         \end{center}
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Feedback to counteract model errors/uncertainty and disturbances}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item But what if we assume \textcolor{magenta}{$O=0.5(A+D)$} while the true system is
       \textcolor{magenta}{ $O=\mathbf{0.6}(A+D)$}?
 \item If we use the nominal control law \DG{$A=2D-R$} on the true system, we get the following:
 \item[] \begin{center}
          \includegraphics[width=0.65\columnwidth]{./Unit-02/img/Taxonomy-OpenLoop-Example-PartialKnowledge.pdf}
          \hspace{6mm}\includegraphics[height=1.5cm]{./Unit-02/img/frown.png}
         \end{center}
 \item \vfill H\'{e}las, 20\% error on a model parameter (0.6 instead of 0.5)\\
       $\Rightarrow$ 20\% error of $O$ wrt $R$.
 \item Open-loop control cannot counteract model errors.
 \item Let us try with feedback.
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Feedback to counteract model errors/uncertainty and disturbances}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item \underline{EXAMPLE} feedback scheme with \TC{proportional} control (action $A$ proportional\\
       to the \TC{error} $R-O$); note that we do not compensate the disturbance:
 \item[] \begin{center}
          \includegraphics[width=0.60\columnwidth]{./Unit-02/img/Taxonomy-ClosedLoop-Example.pdf}
         \end{center}
 \item Joining the system and controller equations, for $O$ we get
       \begin{displaymath}
        \begin{array}{rcl}
         \left\{\begin{array}{rl}
          A &= K(R-O) \\
          O &= 0.6(A+D)
         \end{array}\right. &
         \Rightarrow &
          O = \frac{3K}{3K+5}R+\frac{3}{3K+5}D
         \end{array}
        \end{displaymath}
 \item Apparently, as $K \rightarrow \infty$, $O \rightarrow R$ $\forall D$.
 \item \vfill Yes, feedback can counteract model errors and disturbances;
 \item possible drawbacks on stability (improper use of feedback) later on.
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Studying the stability of a system}
\framesubtitleTC{adopting here a \underline{very} informal attitude, where ``stable'' means ``left alone, does not
                 run amok''}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item Let us take our system, initialise $y(0)$ to $y_0$, let $u(k)=0$ $\forall k$ so that
       \begin{displaymath}
        y(k) = ay(k-1),
       \end{displaymath}
       and see what happens.
 \item \vfill Case 1: $|a|<1$, for example 0.5 or -0.5.\\
 \item[] For $k=0,1,2,\ldots$, we have respectively the $y$ sequences
       \begin{displaymath}
        \begin{matrix*}[r]
          y_0, &  0.5y_0, & 0.25y_0, &  0.125y_0, \ldots \\
          y_0, & -0.5y_0, & 0.25y_0, & -0.125y_0, \ldots
        \end{matrix*}
       \end{displaymath}
 \item[] For $k\rightarrow\infty$ the system's \TC{free motion} (no input) converges to zero\\
         $\Rightarrow$ we say the system is \TC{asymptotically stable.}
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Studying the stability of a system}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item Case 2: $|a|=1$, i.e., $a=\pm 1$.\\
 \item[] For $k=0,1,2,\ldots$, we have respectively the $y$ sequences
       \begin{displaymath}
        \begin{matrix*}[r]
          y_0, &  y_0, & y_0, &  y_0, \ldots \\
          y_0, & -y_0, & y_0, & -y_0, \ldots
        \end{matrix*}
       \end{displaymath}
 \item[] For $k\rightarrow\infty$ the free motion neither converges to zero nor diverges\\
         $\Rightarrow$ we say the system is \TC{stable}, but not asymptotically.
 \item \vfill Case 3: $|a|>1$, for example 2 or -2.\\
 \item[] For $k=0,1,2,\ldots$, we have respectively the $y$ sequences
       \begin{displaymath}
        \begin{matrix*}[r]
          y_0, &  2y_0, & 4y_0, &  8y_0, \ldots \\
          y_0, & -2y_0, & 4y_0, & -8y_0, \ldots
        \end{matrix*}
       \end{displaymath}
 \item[] For $k\rightarrow\infty$ the free motion diverges (except for the one case $y_0=0$)\\
         $\Rightarrow$ we say the system is \TC{unstable.}
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Stabilising a system by means of feedback}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item Take an unstable system:
       \begin{displaymath}
        y(k) = ay(k-1)+u(k-1), \qquad a=2.
       \end{displaymath}
 \item Feed $y$ back to $u$ proportionally, i.e., set $u(k) = Qy(k)$.
 \item Doing so we have the closed-loop system
       \begin{displaymath}
        y(k) = 2y(k-1)+Qy(k-1) = (2+Q)y(k-1)
       \end{displaymath}
       and if we chose $Q$ so that $|2+Q|<1$, this is asymptotically stable.
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Stabilising a system by means of feedback}
\framesubtitleTC{and once again, tolerating model errors/uncertainties}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item Note that feedback control is also naturally \TC{robust} (for the moment,\\
       think of this as ``resilient to model errors'').
 \item For example, take $Q=-1.5$ so that $2+Q=0.5$.
 \item In this case the closed loop is asymptotically stable not only for $a=2$,\\
       but $\forall a$ s.t. $|a+Q|=|a-1.5|<1$, i.e., for $0.5<a<2.5$.
 \item \vspace{4mm} Summing up, with feedback we can impose stability even if we do not know\\
       the system (here, parameter $a$) precisely...
 \item[]\vspace{-1mm} ...but for the very same reasons, we might also \emph{destroy} stability.
 \item Feedback is a powerful weapon, use with care.
 \item \vfill And now, let us re-address feedback and dynamic systems\\
       with a formal attitude (soon focusing on the DT LTI case).
 \end{itemize}
\end{frame}


\input{../header_overview}

%---------- start document ---------- %
\section{Introduction}
 NZMATH\cite{NZMATH} is a number theory oriented calculation system
mainly developed by the Nakamula laboratory at Tokyo Metropolitan University.
 NZMATH system provides you mathematical, especially number-theoretic computational power.
 It is freely available and distributed under the BSD license.
The most distinctive feature of NZMATH is that it is written entirely
using a scripting language called Python.

If you want to learn how to start using NZMATH,
see Installation (section \ref{installation}) and
Tutorial (section \ref{tutorial}).
%
 \subsection{Philosophy -- Advantages over Other Systems}
 In this section, we discuss philosophy of NZMATH, that is, the advantages of
NZMATH compared to other similar systems.
%
\subsubsection{Open Source Software}
%
Many computational algebra systems, such as Maple\cite{Maple},
Mathematica\cite{Mathematica}, and Magma\cite{Magma} are fare-paying systems.
These non-free systems are not distributed with source codes.
Then, users cannot modify such systems easily.
It narrows these system's potentials
for users not to take part in developing them.
NZMATH, on the other hand, is an open-source software
and the source codes are openly available.
Furthermore, NZMATH is distributed under the BSD license.
BSD license claims as-is and redistribution or commercial use are permitted
provided that these packages retain the copyright notice.
NZMATH users can develop it just as they like.
%
\subsubsection{Speed of Development}
%
We took over developing of SIMATH\cite{SIMATH},
which was developed under the leadership of Prof.Zimmer
at Saarlandes University in Germany.
However, it costs a lot of time and efforts to develop these system.
Almost all systems including SIMATH are
implemented in C or C++ for execution speed,
but we have to take the time to work memory management,
construction of an interactive interpreter,
preparation for multiple precision package and so on.
In this regard, we chose Python which is a modern programming language.
Python provides automatic memory management, a sophisticated interpreter
and many useful packages.
We can concentrate on development of mathematical matters by using Python.
%
\subsubsection{Bridging the Gap between Users And Developers}
%
KANT/KASH\cite{KANT} and PARI/GP\cite{PARI} are similar systems to NZMATH.
But programming languages for modifying these systems are
different between users and developers.
We think the gap makes evolution speed of these systems slow.
On the other hand, NZMATH has been developed with Python for bridging this gap.
Python grammar is easy to understand
and users can read easily codes written by Python.
And NZMATH, which is one of Python libraries, works on very wide platform
including UNIX/Linux, Macintosh, Windows, and so forth.
Users can modify the programs and feedback to developers with a light heart.
So developers can absorb their thinking.
Then NZMATH will progress to more flexible user-friendly system.
%
\subsubsection{Link with Other Softwares}
%
NZMATH distributed as a Python library
enables us to link other Python packages with it.
For example, NZMATH can be used with IPython\cite{IPython},
which is a comfortable interactive interpreter.
And it can be linked with matplotlib\cite{matplotlib},
which is a powerful graphic software.
Also mpmath\cite{mpmath}, which is a module for floating-point operation,
can improve efficiency of NZMATH.
In fact, the module ecpp\linkingzero{ecpp} improves performance with mpmath.
There are many softwares implemented in Python.
Many of these packages are freely available.
Users can use NZMATH with these packages
and create an unthinkable powerful system.
%
\subsection{Information}
  NZMATH has more than 25 modules.
These modules cover a lot of territory including
elementary number theoretic methods, combinatorial theoretic methods,
solving equations, primality, factorization,
multiplicative number theoretic functions,
matrix, vector, polynomial, rational field, finite field,
elliptic curve, and so on.
NZMATH manual for users is at:
\begin{verbatim}
http://tnt.math.se.tmu.ac.jp/nzmath/manual/
\end{verbatim}
If you are interested in NZMATH, please visit the official website
below to obtain more information about it.
\begin{verbatim}
http://tnt.math.se.tmu.ac.jp/nzmath/
\end{verbatim}
Note that NZMATH can be used even if users do not have any experience of
writing programs in Python.
%
\subsection{Installation}\label{installation}
In this section, we explain how to install NZMATH.
If you use Windows (Windows XP, Windows Vista, Windows 7 etc.)
as an operating system (OS),
then see \ref{windows install} ``Install for Windows Users''.
%
\subsubsection{Basic Installation}
There are three steps for installation of NZMATH.

%First, make preparation of computer with the Python installed.
First, check whether Python is installed in the computer.
Python 2.5 or a higher version is needed for NZMATH.
If you do not have a copy of Python, please install it first.
Python is available from \verb+http://www.python.org/+.

Second, download a NZMATH package and expand it.
It is distributed at official web site:
\begin{verbatim}
http://tnt.math.se.tmu.ac.jp/nzmath/download
\end{verbatim}
or at sourceforge.net:
\begin{verbatim}
http://sourceforge.net/project/showfiles.php?group_id=171032
\end{verbatim}
The package can be easily extracted, depending on the operating system.
For systems with recent GNU tar, type a single command below:
\begin{verbatim}
    % tar xf NZMATH-*.*.*.tar.gz
\end{verbatim}
where, \verb|%| is a command line prompt.
With standard tar, type
\begin{verbatim}
    % gzip -cd NZMATH-*.*.*.tar.gz | tar xf -
\end{verbatim}.
Please read *.*.* as the version number of which you downloaded the package.
For example, if the latest version is 1.0.0, then type the following command.
\begin{verbatim}
    % tar xf NZMATH-1.0.0.tar.gz
\end{verbatim}
Then, a subdirectory named NZMATH-*.*.* is created.

Finally, install NZMATH to the standard python path.
Usually, this can be translated into writing files somewhere
under \verb+/usr/lib+ or \verb+/usr/local/lib+.
So the appropriate write permission may be required at this step.
Typically, type commands below:
\begin{verbatim}
    % cd NZMATH-*.*.*
    % su
    # python setup.py install
\end{verbatim}

\subsubsection{Installation for Windows Users}\label{windows install}
We also distribute installation packages for specific platforms.
Especially, we started distributing the installer for Windows in 2007.

Please download the installer (NZMATH-*.*.*.win32Install.exe) from
\begin{verbatim}
http://tnt.math.se.tmu.ac.jp/nzmath/download
\end{verbatim}
or at sourceforge.net:
\begin{verbatim}
http://sourceforge.net/project/showfiles.php?group_id=171032
\end{verbatim}

Here, we explain a way of installing NZMATH with the installer.
First please open the installer.
If you use Windows Vista or higher version,
UAC (User Account Control) may ask if you run the program. click "Allow".
Then the setup window will open.
Following the steps in the setup wizard,
you can install NZMATH with only three clicks.
%
\subsection{Tutorial}\label{tutorial}
  In this section, we describe how to use NZMATH.
\subsubsection{Sample Session}
  Start your Python interpreter.
  That is, open your command interpreter such as Terminal for MacOS or bash/csh for linux, type the strings ``python'' and press the key Enter.
\begin{ex}
% python
Python 2.6.1 (r261:67515, Jan 14 2009, 10:59:13)
[GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
\end{ex}
  For windows users, it normally means opening IDLE (Python GUI), which is a Python software.
\begin{ex}
Python 2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.

    ****************************************************************
    Personal firewall software may warn about the connection IDLE
    makes to its subprocess using this computer's internal loopback
    interface.  This connection is not visible on any external
    interface and no data is sent to or received from the Internet.
    ****************************************************************

IDLE 2.6.1
>>>
\end{ex}
Here, '\verb+>>>+' is a Python prompt, which means that the system waits you to input commands.

Then, type:
\begin{ex}
>>> from nzmath import *
>>>
\end{ex}
This command enables you to use all NZMATH features.
If you use only a specific module (the term ``module'' is explained later), for example, prime, type as the following:
\begin{ex}
>>> from nzmath import prime
>>>
\end{ex}
You are ready to use NZMATH.
For example, type the string ``prime.nextPrime(1000)'',
then you obtain `1009''
as the smallest prime among numbers greater than $1000$.
\begin{ex}
>>> prime.nextPrime(1000)
1009
>>>
\end{ex}
``prime'' is a name of a module, which is a NZMATH file including Python codes.
``nextPrime'' is a name of a function, which outputs values after the system executes some processes for inputs.
NZMATH has various functions for mathematical or algorithmic computations.
See \ref{function} Functions.

Also, we can create some mathematical objects.
For example, you may use the module ``matrix''.
If you want to define the matrix
\begin{equation*}
\left(
\begin{array}{rl}
1 & 2\\
5 & 6\\
\end{array}
\right)
\end{equation*}
and compute the square, then type as the following:
\begin{ex}
>>> A = matrix.Matrix(2, 2, [1, 2]+[5, 6])
>>> print A
1 2
5 6
>>> print A ** 2
11 14
35 46
>>>
\end{ex}
``Matrix'' is a name of a class, which is a template of mathematical objects.
See \ref{class} Classes for using NZMATH classes.

The command ``print'' enables us to represent outputs with good-looking forms.
The data structure such as ``[a, b, c, $\cdots$]'' is called list.
Also, we use various Python data structures like
tuple ``(a, b, c, $\cdots$)'',
dictionary ``$\{x_1:y_1, x_2:y_2, x_3:y_3, \cdots\}$'' etc.
%These follow syntax of Python programming language.
Note that we do not explain Python's syntax in detail
because it is not absolutely necessary to use NZMATH.
However, we recommend that you learn Python for developing your potential.
Python grammar are easy to study.
For information on how to use Python,
see \verb+http://docs.python.org+ or many other documents about Python.

 % \subsection{Python $\&$ NZMATH}
 %  \subsubsection{Save to a file}
 \subsection{Note on the Document}
   \paragraph{$\dagger$}
   Some beginnings of lines or blocks such as sections or sentences
    may be marked $\dagger$.
   This means these lines or blocks is for advanced users.
   For example, the class \textit{FiniteFieldElement} %
   (See \linkingone{finitefield}{FinitePrimeFieldElement}) is %
   one of abstract classes in NZMATH, %
   which can be inherited to new classes similar to the finite field.
   \paragraph{[$\cdots$]}
   For example, we may sometimes write as \textit{function(a,b[,c,d])}.
   It means the argument ``c, d'' or only ``d'' can be discarded.
   Such functions use ``default argument values'',
   which is one of the feature of Python.\\
   (See
   \verb+http://docs.python.org/tutorial/controlflow.html#default-argument-values+)

   \textbf{Warning}:\ Python also have the feature ``keyword arguments''.
   We have tried to keep the feature in NZMATH too.
   However, some functions cannot be used with this feature
   because these functions are written
   expecting that arguments are given in order.

%---------- end document ---------- %

\input{../footer}


% Document Type: LaTeX
\input ../6001mac

\def\fbox#1{%
 \vtop{\vbox{\hrule%
    \hbox{\vrule\kern3pt%
\vtop{\vbox{\kern3pt#1}\kern3pt}%
\kern3pt\vrule}}%
\hrule}}

\begin{document}

\psetheader{SAMPLE}{Simple Problem Set}

\medskip

\begin{flushleft}
Reading:
\begin{itemize}

\item Text (SICP 2nd Edition by Abelson \& Sussman): section 1.1

\end{itemize}
\end{flushleft}

\smallskip
The purpose of the exercises below is to familiarize you with the
basics of Scheme language and interpreter.  Spending a little time on
simple mechanics now will save you a great deal of time over the rest
of the semester.

\section{1. Before Turning on your Computer}

Read the course notes through section 1.1.  Then, predict what the
interpreter will print in response to evaluation of each of the following
expressions.  Assume that the sequence is evaluated in the order in which
it is presented here.

\beginlisp
(- 8 9)
\null
(> 3.7 4.4)
\null
(- (if (> 3 4) 7 10) (/ 16 10))
\null
(define b 13)
\null
13
\null
b
\null
>
\null
(define square (lambda (x) (* x x)))
\null
square
\null
(square 13)
\null
(square b)
\null
(square (square (/ b 1.3)))
\null
(define multiply-by-itself square)
\null
(multiply-by-itself b)
\null
(define a b)
\null
(= a b)
\null
(if (= (* b a) (square 13))
    (< a b)
    (- a b))
\null
(cond ((>= a 2) b)
      ((< (square b) (multiply-by-itself a)) (/ 1 0))
      (else (abs (- (square a) b))))
\endlisp

\section{2. Getting started with the Scheme Interpreter}

In the Scheme interpreter, you will use a text-editing system called Edwin,
which is an editor closely resembling the widely used editor Emacs.  Even
if you are already familiar with Emacs, you should take some time {\it now}
to run the Emacs/Edwin tutorial.  This can be invoked by typing {\tt C-h}
followed by {\tt t}.  You will probably get bored before you finish the
tutorial. (It's too long, anyway.)  But at least skim all the topics so
you know what's there.  You'll need to gain reasonable facility with the
editor in order to complete the exercises below.

\subsection{Evaluating expressions}

After you have learned something about Edwin, go to the Scheme buffer
(i.e., the buffer named {\tt *scheme*}).\footnote{If you don't know
how to do this, go back and learn more about Edwin.}  As with any
buffer, you can type Scheme expressions, or any other text into this
buffer.  What distinguishes the Scheme buffer from other buffers is
the fact that underlying this buffer is a Scheme evaluator, which you
can ask to evaluate expressions, as explained in the section of the
tutorial entitled ``Evaluating Scheme expressions.''

Type in and evaluate (one by one) the expressions from section 1 of
this assignment to see how well you predicted what the system would
print.  If the system gives a response that you do not understand, ask
for help from a lab tutor or from the person sitting next to you.

Observe that some of the examples printed above in section 1 are
indented and displayed over several lines for readability.  An
expression may be typed on a single line or on several lines; the
Scheme interpreter ignores redundant spaces and carriage returns.  It
is to your advantage to format your work so that you (and others) can
read it easily. It is also helpful in detecting errors introduced by
incorrectly placed parentheses.  For example the two expressions

\beginlisp
(* 5 (- 2 (/ 4 2) (/ 8 3)))
\null
(* 5 (- 2 (/ 4 2)) (/ 8 3))
\endlisp

\noindent
look deceptively similar but have different values. Properly indented,
however, the difference is obvious.

\beginlisp
(* 5
   (- 2
      (/ 4 2)
      (/ 8 3)))
\null
(* 5
   (- 2
      (/ 4 2))
   (/ 8 3))
\endlisp

Edwin provides several commands that ``pretty-print'' your code, e.g.,
indents lines to reflect the inherent structure of the Scheme
expressions.\footnote{Make a
habit of typing {\tt ctrl-j} at the end of a line, instead of {\tt
enter}, when you enter Scheme expressions, so that the cursor will
automatically indent to the right place.}

\subsection{Creating a file}

Since the Scheme buffer will chronologically list all the expressions
you evaluate, and since you will generally have to try more than one
version of the same procedure as part of the coding and debugging
process, it is usually better to keep your procedure definitions in a
separate buffer, rather than to work only in the Scheme buffer.  You
can save this other buffer in a file on your disk so you can split
your lab work over more than one session.

The basic idea is to create another buffer, into which you can type your
code, and later save that buffer in a disk file.  You do this by
typing {\tt C-x C-f} {\it filename}.  If you already have a buffer
open for that file Edwin simply switches you into this buffer.
Otherwise, Edwin will create a new buffer for the file.  If you give
the system a name that has not yet been used, with an extension of
{\tt .scm}, Edwin will automatically create a new buffer with that
file name, in {\tt scheme} mode.  In a Scheme-mode buffer some editing
commands treat text as code, for example, typing {\tt C-j} at the end
of a line will move you to the next line with appropriate indentation.

Once you are ready to transfer your procedures to Scheme, you can use any
of several commands: {\tt M-z} to evaluate the current definition, {\tt
ctrl-x ctrl-e} to evaluate the expression preceding the cursor, {\tt M-o}
to evaluate the entire buffer, or using {\tt M-x eval-region} to evaluate
a ``marked'' region in the buffer.  Each of these commands will cause the
Scheme evaluator to evaluate the appropriate set of expressions (usually
definitions).  By returning to the {\tt *scheme*} buffer, you can now use
these expressions.

To practice these ideas, create a new buffer, called {\tt
ps1-ans.scm}.  In this buffer, create a definition for a simple
procedure, by typing in the following (verbatim):

\beginlisp
(define square (lambda (x) (*x x)))
\endlisp

\noindent
Now evaluate this definition by using either {\tt M-z} or {\tt M-o}.
Go back to the Scheme buffer, and try evaluating {\tt (square 4)}.

If you actually typed in the definition {\em exactly} as printed above,
you should have hit an error at this point.  The system will now be
offering you a chance to enter the debugger.  For now, type {\tt Q} to
quit the evaluation (we'll see how to use the debugger below).  Go back to
the {\tt ps1-ans.scm} buffer and edit the definition to insert a space
between {\tt *} and {\tt x}.  Re-evaluate the definition, and return to
Scheme and try evaluating {\tt (square 4)} again.

As a second method of evaluating expressions, try the following.  Go
to the {\tt *scheme*} buffer, and again type in:

\beginlisp
(define square (lambda (x) (*x x)))
\endlisp

Place the cursor at the end of the line, and type {\tt C-x C-e} to
evaluate this expression.  Again try {\tt (square 4)}.  When it fails,
again use {\tt Q} to quit out of the debugger.  This time, you should
type {\tt M-p} several times, until the definition of {\tt square}
that you typed in appears on the screen.  Edit this definition to
insert a space between {\tt *} and {\tt x}, evaluate the new
expression, and use {\tt M-p} to get back the expression {\tt (square
4)}.  Make a habit of using {\tt M-p}, rather than going back and
editing previous expressions in the Scheme buffer in place.  That
way, the buffer will contain an intact record of your work.

\section{3. The Scheme Debugger}

While you work, you will often need to debug programs.  This
section contains an exercise to acquaint you with some of the features
of Scheme to aid in debugging.  Learning to use the debugging features
will save you much grief on later problem sets.  Additional
information about the debugger can be found by typing {\tt ?} in the debugger.

Load the code for this problem set using the Edwin {\tt C-x C-f}
command. Evaluate the code using {\tt M-x eval-buffer}.  This will
load definitions of the following three procedures {\tt p1}, {\tt p2}
and {\tt p3}:

\beginlisp
(define p1
  (lambda (x y)
    (+ (p2 x y)
       (p3 x y))))
\null
(define p2
  (lambda (z w)
    (* z w)))
\null
(define p3
  (lambda (a b)
    (+ (p2 a)
       (p2 b))))
\endlisp

In the Scheme buffer, evaluate the expression {\tt (p1 1 2)}.  This
should signal an error, with the message:

{\small
\begin{verbatim}
;The procedure #[compound-procedure P2] has been called with 1 argument
;it requires exactly 2 arguments.
;Type D to debug error, Q to quit back to REP loop:
\end{verbatim}
}

Don't panic.  Beginners have a tendency, when they hit an error, to
quickly type {\tt Q}, often without even reading the error message.
Then they stare at their code in the editor trying to see what the bug
is.  Indeed, the example here is simple enough so that you probably
can find the bug by just reading the code.  Instead, however, let's
see how Scheme can be coaxed into producing some helpful information
about the error.

First of all, there is the error message itself.  It tells you that
the error was caused by a procedure being called with one argument,
which is the wrong number of arguments for that procedure.
Unfortunately, the error message alone doesn't say where in the code
the error occurred.  In order to find out more, you need to use the
debugger.  To do this type {\tt D} to start the debugger.

\subsection{Using the debugger}

The debugger allows you to grovel around examining pieces of the
execution in progress, in order to learn more about what may have
caused the error.  When you start the debugger, it will create a new
window showing two buffers.  The top buffer should look like this.

{\small
\begin{verbatim}
     COMMANDS:   ? - Help   q - Quit Debugger   e - Environment browser
This is a debugger buffer:
Lines identify stack frames, most recent first.
   Sx means frame is in subproblem number x
   Ry means frame is reduction number y
The buffer below describes the current subproblem or reduction.
-----------
The *ERROR* that started the debugger is:
  The procedure #[compound-procedure 119 p2] has been called with 1 argument;
  it requires exactly 2 arguments.

>S0  (#[compound-procedure 119 p2] 2)
    R0  (p2 b)
 S1  (+ (p2 a) #(p2 b)#)
    R0  (+ (p2 a) (p2 b))
    R1  (p3 x y)
 S2  (+ (p2 x y) #(p3 x y)#)
    R0  (+ (p2 x y) (p3 x y))
    R1  (p1 1 2)
 --more--
\end{verbatim}
}

You can select a ``frame'' by clicking on its line with the mouse or by
using the ordinary cursor line-motion commands to move from line to line.
Notice that the bottom, information, buffer changes as the selected line
changes.

The frames in the list in the top buffer represent the steps in the
evaluation of the expression.  There are two kinds of steps---subproblems
and reductions.  For now, you should think of a reduction step as
transforming an expression into ``more elementary'' form, and think of a
subproblem as picking out a piece of a compound expression to work on.

So, starting at the bottom of the list and working upwards, we see
{\tt (p1 1 2)}, which is the expression we tried to evaluate.  The
next line up indicates that {\tt (p1 1 2)} reduces to {\tt (+
(p2 x y) (p3 x y))}.  Above that, we see that in order to evaluate
this expression the interpreter chose to work on the subproblem {\tt
(p3 x y)}, and so on, moving upwards until we reach the error: the
call to {\tt (p2 b)} from within the procedure {\tt p3} has only one
argument, and {\tt p2} requires two arguments.\footnote{Notice that
the call that produced the error was {\tt (p2 b)}, and that {\tt (p2
a)} would have also given an error.  This indicates that in this case
Scheme was evaluating the arguments to {\tt +} in right-to-left order,
which is something you may not have expected.  You should never write
code that depends for its correct execution on the order of evaluation
of the arguments in a combination.  The Scheme system does not
guarantee that any particular order will be followed, nor even
that this order will be the same each time a combination is
evaluated.}

Take a moment to examine the other debugger information (which will
come in handy as your programs become more complex).  Specifically, in
the top buffer, select the line
{\small
\begin{verbatim}
>S2  (+ (p2 x y) #(p3 x y)#)
\end{verbatim}
}

The bottom buffer should now look like this:
{\small
\begin{verbatim}
                         SUBPROBLEM LEVEL: 2
Expression (from stack):
 Subproblem being executed highlighted.
    (+ (p2 x y) (p3 x y))
---------------------------------------------------------------------
ENVIRONMENT named: (user)
    p1 = #[compound-procedure 31 p1]
    p3 = #[compound-procedure 32 p3]
    p2 = #[compound-procedure 27 p2]
==> ENVIRONMENT created by the procedure: P1
      x = 1
      y = 2
---------------------------------------------------------------------
;EVALUATION may occur below in the environment of the selected frame.
\end{verbatim}
}

The information here is in three parts.  The first shows the
expression again, with the subproblem being worked on.  The next major
part of the display shows information about the {\it environments}.
We'll have a lot more to say about environments later in the course,
but, for now, notice the line
{\small
\begin{verbatim}
==> ENVIRONMENT created by the procedure: P1
\end{verbatim}
}
This indicates that the evaluation of the current expression is within
procedure {\tt p1}.  Also we find the environment has two {\it bindings}
that specify the particular values of {\tt x} and {\tt y} referred
to in the expression, namely {\tt x = 1} and {\tt y = 2}.  At the bottom
of the description buffer is an area where you can evaluate
expressions in this environment (which is often useful in debugging).

Before quitting the debugger try one final experiment (you may have
already done this).  Continue to scroll down through the stack past
the line: {\tt R1 (p1 1 2)} (you can also click the mouse on the line
{\tt --more--} to show the next subproblem).  You will then see
additional frames that various complicated expressions.  What you
are looking at is some of the guts of the Scheme system---the part
shown here is a piece of the interpreter's read-eval-print program.
In general, backing up from any error will eventually land you in the
guts of the system. (Yes: almost all of the system is itself a Scheme
program.)

You can type {\tt q} to return to the Scheme top level interpreter.

\section{4. Exploring the system}

The following exercises are meant to help you practice editing and
debugging, and using on-line documentation.

\paragraph{Exercise 1:  More debugging}

The code you loaded for problem set 1 also defined three other procedures,
called {\tt fold}, {\tt spindle}, and {\tt mutilate}.  One of these
procedures contains an error.  Evaluate the expression {\tt (fold 1 2)}.
What is the error?  How should the procedure be defined?  (Notice that you
can examine the code for a procedure by using the {\tt pp} (``pretty
print'') command.  For example, evaluating the expression {\tt (pp fold)}
will print the definition of {\tt fold}.

\paragraph{Exercise 2: Still more debugging}

The code you loaded also contains a buggy definition of a procedure meant
to compute the factorials of positive integers:
$n!=n\cdot(n-1)\cdot(n-2)\cdots3\cdot2\cdot1$.  Evaluate the expression
{\tt (fact 5)} (which is supposed to return 120).  Use the debugger to
find the bug and correct the definition.  Compute the factorial of 243.
Copy the corrected definition and the value of {\tt (fact 243)} into your
{\tt ps1-ans.scm} buffer.

\paragraph{Exercise 3: Defining a simple procedure}

The number of combinations of $n$ things taken $k$ at a time is given
by $n!/k!(n-k)!$.  Define a procedure {\tt (comb n k)} that computes
the number of combinations, and find the number of combinations of 243
things taken 90 at a time.  Include your procedure definition and your
answer in {\tt ps1-ans.scm}.

\paragraph{Exercise 4: Practice with the editor}

Find the Free Software Foundation copyright notice at the end of the Edwin
tutorial.  Copy it into {\tt ps1-ans.scm}.

\paragraph{Exercise 5: Learning to use {\tt Info}}

Start up the {\tt info} program with the Edwin command {\tt M-x info}.
{\tt Info} is a directory of useful information.  You select a topic
from the menu, by typing {\tt m} followed by the name of the topic.
(You can type a few characters that begin the topic name, and then type
a space, and Edwin will complete the name.  One of the {\tt info}
options (type {\tt h}) gives you a brief tutorial in how to use the
program.  Use {\tt info} to find the cost of a 12-inch cheese pizza
from Pizza Ring, and copy this to the answer buffer.

\paragraph{Exercise 6: Hacker Jargon}

The info {\tt Jargon} entry is a collection of hacker terms that was
eventually published in 1983 as the book {\it The Hacker's
Dictionary}.  The {\tt New Jargon} info entry is an expanded version
that was published in 1991 by MIT Press as {\it The New Hacker's
Dictionary}.  The old Jargon file is structured as an {\tt info}
file, with submenus; the new version is a single text file, which you
can search.  Find the definition of ``Unix conspiracy'' from the new
jargon file, and find the definition of ``Phase of the Moon'' from
either jargon file.  Include these in the answer buffer.

\paragraph{Exercise 7: Scheme documentation}

The {\tt Scheme} info entry is an on-line copy of the Scheme
reference manual that was distributed with the notes.  Find the
description of ``identifiers'' in the documentation.  What is the
longest identifier in the list of example identifiers?

\paragraph{Exercise 8: More documentation}

There is an Edwin command that you can use to automatically re-indent
expressions.  For example, if you have a procedure typed as

\beginlisp
(define test-procedure
(lambda (a b)
(cond ((>= a 2) b)
   ((< (square b)
 (multiply-by-itself a))
         (/ 1 0))
(else (abs (- (square a) b))))))
\endlisp

\noindent
you can move the cursor to the beginning of the line with the {\tt
define}, type this Edwin command, and the expression will
automatically be re-indented as

\beginlisp
(define test-procedure
  (lambda (a b)
    (cond ((>= a 2) b)
          ((< (square b)
              (multiply-by-itself a))
           (/ 1 0))
          (else (abs (- (square a) b))))))
\endlisp

\noindent
Find the description of this command.  What is the command?  Where did
you find it?

\paragraph{Exercise 9: Running Shell Commands}

If you run the Scheme interpreter within a *nix environment, the Edwin command
{\tt M-x shell} will create a shell buffer, which you can use to run
various *nix programs.  Some of the more interesting ones are {\tt ls}, {\tt
date}, and {\tt echo}.
For example, typing

\beginlisp
date
\endlisp

\noindent
will show you the current date and time (e.g. {\tt Tue Jul  2 15:39:45 EDT
1996}). See if you can figure out what the other commands do, and copy your
results into your answer buffer.

\paragraph{Exercise 10: Getting information from around the world}

You can also use the finger program to query computers on the
Internet, all over the world.  You can finger a particular name at
some location, or just finger the location (e.g., {\tt finger
@mit.edu}) to get general information.  Try fingering some of the
following places:

\begin{itemize}
\item {\tt cs.berkeley.edu}---a computer run by the computer science
department at UC Berkeley

\item {\tt idt.unit.no}---a computer at the Norwegian Institute of
Technology, a part of the The University of Trondheim, Norway.

\item {\tt whitehouse.gov}---the White House
\end{itemize}

See what else you can find.  Include some piece of this in your answer
file.

\paragraph{Exercise 11:}
An {\em application} of an expression $E$ is an expression of the form
$(E\, E_1 \ldots E_n)$.  This includes the case $n = 0$, corresponding to
an expression $(E)$.  A {\em Curried application} of $E$ is either an
application of $E$ or an application of a Curried application of E.  For
each of the procedures defined below, give a Curried application of the
procedure which evaluates to 3.

\beginlisp
(define foo1
  (lambda (x)
    (* x x)))
\endlisp

\beginlisp
(define foo2
  (lambda (x y)
      (/ x y)))
\endlisp

\beginlisp
(define foo3
  (lambda (x)
    (lambda (y)
      (/ x y))))
\endlisp

\beginlisp
(define foo4
  (lambda (x)
    (x 3)))
\endlisp

\beginlisp
(define foo5
  (lambda (x)
    (cond ((= x 2)
           (lambda () x))
          (else
           (lambda () (* x 3))))))
\endlisp

\beginlisp
(define foo6
  (lambda (x)
    (x (lambda (y) (y y)))))
\endlisp

Type in these definitions, and include a demonstration of your answers
in the answer buffer.

\end{document}