\newpage
\section{Second-order Differential Equations}

\subsection{General Theory of Homogeneous Linear Equations}
  The standard form for a general second order ordinary differential equation is

  \[
    x''(t)+p(t)x'(t)+q(t)x(t)=f(t).
  \]

  For us, $p(t)$ and $q(t)$ are typically going to be constants. Also, we know that if $f(t)=0$, the equation is homogeneous.

  \begin{lemma}
    GGiven an equation in the form

    \[
      x''(t)+p(t)x'(t)+q(t)x(t)=0,
    \]

    if $x_1(t)$ and $x_2(t)$ are solutions to equation (3.2), then
    \[\]

    \[
      x(t)=C_1x_1(t)+C_2x_2(t)
    \]

    is also a solution to equation (3.1) for all $C_1,C_2$'s. Equation (3.3) is the general solution to a homogeneous ODE
  \end{lemma}

  Let's take a look at an application of lemma (3.1.1).

  \begin{eg}
    Consider the equation

    \[
    t^2x'''+2tx''-6x'=0.
    \]

    This equation is a third order, linear and homogeneous, but not autonomous ordinary differential equation. Let's put this differential equation into standard form:

    \[
    x''+\frac{2}{t}x''+\frac{6}{t^2}x'=0
    \]

    As long as $t_0\neq0$, we have a unique solution if given 3 initial conditions. The domain of this ordinary differential equation is $t>0,t<0$. Earlier, in section 3.1, we showed that $1,t^3,\frac{1}{t^2}$ were all solutions. Because this ordinary differential equation is linear and homogeneous, we know that

    \[
    x(t)=C_11+C_2t^3+C_3\frac{1}{t^2},
    \]

    is also a solution for all $C_1,C_2,C_3$. Just note, equation (3.6) is a linear combination of $1,t^3,\frac{1}{t^2}$. So, this is a \underline{general solution} as long as the functions, $1,t^3,\frac{1}{t^2}$ are all “different” from each other.
  \end{eg}

  What is “different”? Different means no one function in a set can be written as a linear combination of other functions in the set. Different means that all the functions are linearly independent. More generally, if

  \[
    C_1f_1(t)+C_2f_2(t)+\dots+C_nf_n(t)=0
  \]

  \begin{theorem}
    We can instead test for linear independence by using the wronskian,

    \[
      w(f_1,f_2)(t)=det\begin{vmatrix}
        f_1(t)&&f_2(t)\\f'_1(t)&&f'_2(t)\\
      \end{vmatrix}
    \]

    \begin{itemize}
      \item If $w(t)=0$ for all $t$'s, then $\{f_1,f_2\}$ are linearly dependent.
      \item If $w(t)=0$ for all $t$'s, then $\{f_1,f_2\}$ are linearly independent.
    \end{itemize}
  \end{theorem}

  Now, if we try to use the wronskian on problem 16, we do it like so:

  \begin{align*}
    w(t)=
    \begin{vmatrix}
      1&&t^3&&\frac{1}{t^2}\\
      0&&3t^2&&-\frac{2}{t^2}\\
      0&&6t&&\frac{6}{t^4}\\
    \end{vmatrix}\\
    \to 1\times
    \begin{vmatrix}
      3t^2&&-\frac{2}{t^2}\\
      6t&&\frac{6}{t^4}\\
    \end{vmatrix}\\
    =\frac{18}{t^2}+\frac{12}{t^2}=\frac{30}{t^2}\neq0
  \end{align*}

  So we know that $\{1,t^3,\frac{1}{t^3}\}$ are linearly independent.

  Let's consider another problem where we need to show that the solutions are linearly dependent.

  \begin{eg}
    Let's consider the equation $y''(x)=-9y$, which has the solutions $\{\cos(3x),\sin(3x)\}$ and let's show that the two solutions are linearly independent:

  \[
    w(x)=\begin{bmatrix} \cos(3t)&\sin(3t)\\-3\sin(3t)&3\cos(3t) \end{bmatrix}
    =3\cos^2(3x)+3\sin^2(3x)=3\neq0
  \]

  Which means that both solutions are valid for this ordinary differential equation. We can turn our original equation into $y''(x)+9y=0$ which is a homogeneous ordinary differential equation. Our $p(x)=0$, and because we know that $w(x)=Ce^{-\int p(x)dx}$, we know that the solution to our equation is 0.
  \end{eg}

  \begin{theorem}
    What to we do when solving linear non-homogeneous ordinary differential equations?
    \begin{enumerate}
      \item Solve the associated homogeneous ODE $\to X_h(t)$, which will have many unknown constants
      \item Find one solution to non-homogeneous ODE $\to X_p(t)$
    \end{enumerate}

    The general solution to the original non-homogeneous ODE is

    \[
      x(t)=x_h(t)+x_p(t)
    \]
  \end{theorem}

  Let's try out this new theorem on an example problem.

  \begin{eg}
    Consider the differential equation $y''-5y'-6y=4x$. We claim that

    \[
      y(x)=c_1e^{-x}+c_2e^{6x}-\frac{2}{3}+\frac{5}{9}
    \]

    Are $\{e^{-x},e^{6x}\}$ linearly independent? Verify both solutions to equation (3.14).

    \begin{align*}
      w(x)&=\begin{bmatrix} e^{-x}&e^{6x}\\-e^{-x}&6e^{6x} \end{bmatrix} \\
          &=6e^{5x}+e^{5x}=7e^{5x}
    \end{align*}

    Now we need to verify that this is a solution:

    \begin{align*}
      y'(x)&=-C_1e^{-x}+6C_2e^{6x}-\frac{2}{3}\\
      y''(x)&=C_1e^{-x}+36C_2e^{6x}
    \end{align*}

     Let's see if the left-hand side is equal to $4x$ like it was above.

     \begin{align*}
       y''-5y'-6y=\left[C_1e^{-x}+36C_2e^{6x}\right]&-5\left[-C_1e^{-x}+6C_2e^{6x}-\frac{2}{3}\right]\\
                                                    &-6\left[C_1e^{-x}+C_2e^{6x}-\frac{2}{3}+\frac{5}{9}\right]
     \end{align*}
     \begin{align*}
       &=C_1[e^{-x}+te^{-x}-6e^{-x}]+C_2[36e^{6x}-30e^{6x}-6e^{6x}]+\left[\frac{10}{3}+4x-\frac{10}{3}\right]\\
       &=0+0+4x
     .\end{align*}

  \end{eg}

\subsection{Homogeneous Linear Equations with Constant Coefficients}

  Homogeneous ordinary differential equations are ones that come in the form
  \[
    ay''+by'+cy=0
  \]

  The first method of solving homogeneous linear equations with constant coefficients is the method of lucky guess. In this method, we let $y(x)=e^{rx}$. If we take the multiple derivatives of $e^{rx}$, we can find what $y'(x)$ and $y''(x)$ equal. Now we can plug in the $e^{rx}$ into our equation to get

  \begin{align*}
    ar^2e^{rx}+bre^{rx}+ce^{rx}=0\\
    e^{rx}[ar^2+br+c]=0
  .\end{align*}
  \[
    \boxed{ar^2+br+c=0}
  \]

  There are 3 distinct cases for the roots of this equation.
  \begin{enumerate}
    \item 2 real distinct roots.
    \item 1 repeated root.
    \item 2 complex conjugate roots ($A+Bi$).
  \end{enumerate}

  Let's take a look at an example of this method in action.

  \begin{eg}
    Consider the equation
    \[
    y''-5y'-6y=0
    .\]
    We are going to let $y(x)=e^{rx}$. We can skip adding $e^{rx}$ to the beginning of each term because we can just divide that over in our minds. After going through that we get
    \begin{align*}
      r^2-5r-6&=0\\
      (r-6)(r+1)&=0\\
      r&=6,-1
    .\end{align*}

    From this, we know that our two solutions are $y_1(x)=e^{6x},y_2(x)=e^{-x}$. Our general solution is
    \[
      \boxed{y(x)=C_1 e^{6x}+C_2e^{-x}}
    \]
    Now all we need to do is check the wronskian $W(x)$ to make sure that $\{e^{r_1x},e^{r_2x}\}$ are linearly independent.
  \end{eg}

  Let's explore a case of a real repeated root. Let's look at the equation
  \[
  y''-8y'+16=0
  .\]
  We can let $y(t)=e^{rt}$, to get
  \[
  r^2-8r+16=0
  .\]
  Our roots for $r$ are 4 and 4. One of our solutions should be $y_1(t)=e^{4t}$, but because we have a repeated root, I claim that $y_2(t)=te^{4t}$. We can verify that this is a repeated root by putting it in a wronskian:
    \begin{align*}
      w(t)&=\left|
      \begin{matrix}
        e^{4t}&te^{4t}\\
        4e^{4t}&e^{4t}+4te^{4t}
      \end{matrix}
      \right|\\
          &=e^{8t}+4te^{8t}-4te^{8t}\\
          &=e^{8t}\neq 0
    .\end{align*}
    Because the wronskian result was not equal to zero, we know that these are two linearly independent solutions. Our general solution in this case would be
    \[
      y(t)=C_1e^{4t}+C_2te^{4t}
    .\]
    If we were to solve a 4th order ordinary differential equation, our general solution would look something like this:
    \[
      y(t)=C_1e^{2t}+C_2e^{-3t}+C_3te^{-3t}+C_4t^2e^{-3t}
    .\]
    As you can see, the main difference between the second and third order ordinary differential equations is the amount of roots you need to take. Let's take a look at the third case, having 2 complex conjugate values for $r=\alpha\pm i\beta$.\newline\newline
    Consider the equation
    \[
    y''-2y'+5y=0
    .\]
    Let $y(t)=e^{rt}$. Our previous equation will turn into $r^2-2r+5=0$, and we will need to use the quadratic formula for this case.

    \begin{align*}
      r&=\frac{2\pm\sqrt{4-20} }{2}\\
       &=\frac{2\pm\sqrt{-16} }{2}\\
       &=1\pm 2i
    .\end{align*}

    Because of Euler's identity,
    \[
      e^{i\theta}=\cos(\theta)+i\sin(\theta)
    ,\]
    we can determine that the general solution of this ordinary differential equation is
    \[
    y(t)=C_1e^{1t}\cos(2t)+C_2e^{1t}\sin(2t)
    .\]
    \begin{eg}
      Solve the homogeneous linear ordinary differential equation,
      \[
      x'''+3x''-4x'-12x=0
      .\]
      Let $x(t)=e^{rt}$, this means that
      \begin{align*}
        x'&=re^{rt}\\
        x''&=r^2e^{rt}\\
        x'''=r^3e^{rt}
      .\end{align*}
    Our expanded out equation is
    \[
      e^{rt}[r^3+3r^2-4r-12]=0
    .\]
    From this, we can see that our roots are $r=2,-2,-3$, which means that our general solution is
    \[
      x(t)=C_1e^{2t}+C_2e^{-2t}+C_3e^{-3t}
    .\]
    \end{eg}

\subsection{The Spring-Mass Equation}

  The spring-mass equation is a variation of Hooke's law, which states
  \[
    F_{spring}=-kx(k>0)
  .\]
  This tries to bring mass back to equilibrium where $x(t)$ is the distance of the mass from its equilibrium position at time $t$. The differential version of the equation is
  \[
    mx''+bx'+kx=F(t)
  .\]
  Where $mx''$ is the acceleration, $bx'$ is the resistance friction, $kx$ is the spring force and $F(t)$ is any extra force acting on the system. Where is gravity within this equation? It drops out because the stretching of the string due to gravity puts the block attached to the string into equilibrium.\newline\newline
  When you first attach the mass and the mass stops moving,
  \[
    m(0)=-k(s)-b(0)-mg\to mg=ks\to k
  .\]
  \begin{eg}
    A mass weighing 10 pounds stretches a string $\frac{1}{4}ft$. Assuming no dampening, find the amplitude period of oscillations of the mass if it is released from a point $\frac{1}{10}ft$below it's equilibrium position with an initial upward velocity of $\frac{1}{20}\frac{ft}{s}$.\newline
    Because the mass weighs 10 pounds, $mg=10$, which means that $m=\frac{10}{32}=\frac{5}{16}\frac{lbs^2}{ft}$. The first thing we need to do is find K. This can be done by setting $mg=ks$ and solving for $k$.
    \begin{align*}
      10&=\frac{1}{4}k\\
      k=\frac{10}{\frac{1}{4}}=40\\
      [k]=\frac{10lb}{\frac{1}{ft}}=\left[\frac{lb}{ft}\right]
    .\end{align*}
    Our ordinary differential equation is going to be
    \[
    \frac{5}{16}x''+40x=0
    .\]
    We are given the initial values of $x'(0)=-\frac{1}{20}$ and $x(0)=-\frac{1}{10}$. We get the ordinary differential  equation
    \begin{align*}
      \to x''+128x=0\\
    .\end{align*}
    Furthermore, we are going to let $x(t)=e^{rt}$. This gives us
    \begin{align*}
      r^2+128&=0\\
      r^2&=-128\\
      r&=\pm\sqrt{-128}=\pm_8\sqrt{2i}
    .\end{align*}
    The general solution to our ordinary differential equation in this situation is
    \[
      x(t)=C_1\cos\left( 8\sqrt{2} t \right) +C_2\sin\left( 8\sqrt{2} t \right)
    .\]
    This gives us that the angular frequency of our system, $\beta=8\sqrt{2} \left[ \frac{1}{s} \right] $, and the period of our system, $T=\frac{\pi}{4\sqrt{2} }s$.\newline
    NOTE: In general, the natural frequency of a spring mass system is $\omega_0=8\sqrt{2} $.\newline
    Now we need to apply our initial conditions to find $C_1,C_2 $.
    \begin{align*}
      x'(t)&=-8\sqrt{2} C_1\sin\left( 8\sqrt{2} t \right) +8\sqrt{2} C_2\cos\left( 8\sqrt{2} t \right) \\
      x(0)&=C_1=-\frac{1}{10}\\
      x'(0)&=8\sqrt{2} C_2=\frac{1}{10}
    .\end{align*}
    This gives us that our equation of motion is
    \begin{align*}
      x(t)&=-\frac{1}{10}\cos\left( 8\sqrt{2} t \right) +\frac{1}{160\sqrt{2} }\sin\left( 8\sqrt{t}  \right) \\
          &=R\sin\left( \beta t+\phi \right) \\
      C_1&=R\sin\phi\\
      C_2&=R\cos\phi\\
      C_1^2+C_2^2&=R^2\\
      \sqrt{\left( -\frac{1}{10} \right) ^2+\left( \frac{1}{160\sqrt{2} } \right) ^2} &= R\\
      \sqrt{\frac{513}{51200}} &=R
    \end{align*}
    \[
      \boxed{R\approx0.100ft}
    .\]
    \begin{align*}
      \phi&=tan^{-1}\left( \frac{C_1}{C_2} \right)+\frac{1}{60}\sqrt{2} \sin(8\sqrt{2} t) \\
          &=tan^{-1}\left( -16\sqrt{2}  \right) \\
      \phi&=-1.4226rad\\
      x(t)&= -\frac{1}{10}\cos\left( 8\sqrt{2}t  \right)+\frac{1}{160\sqrt{2} }\sin\left( 8\sqrt{2}t  \right) \\
          &\approx 0.1001\sin\left( 8\sqrt{2} t-1.5266 \right)
    .\end{align*}
  \end{eg}

  $x(t)$ is the displacement of mass from equilibrium at time $t$. The following is the general formula for a mass-spring system.
  \[
    mx''+bx'+kx=0 \text{ where $mbk>0$}
  .\]
  Let's consider a dampening situation. If we let $x(t)=e^{rt}$, then
  \begin{align*}
  mr^2+br+k=0\\
  \to r=\frac{-b\pm\sqrt{b^2-4mk} }{2m}
  .\end{align*}
  \begin{itemize}
    \item Repeated $r$ values.
      For this case, we are going to get $b^2-4mk=0$, which is a critically dampened system. This would make $r=-\frac{b}{2m},-\frac{b}{2m}$, which would make our general solution
      \[
        x(t)=C_1e^{-\frac{b}{2m}t}+C_2te^{-\frac{b}{2m}t}
      .\]
      If we take the $\lim_{t \to \infty} x(t) $, we can see that this equation goes to zero.
    \item 2 real distinct roots.
      \[
        r_1=\frac{-b+\sqrt{b^2-4mk} }{2m}<b, r_2=\frac{-b-\sqrt{b^2-4mk} }{2m} <0
      .\]
      If $b^2-4mk > 0,$ we have an over dampened system. $r<r_1<0$. The solution to this equation would be
      \[
        x(t)=C_1e^{r_1t}+C_2e^{r_2t}
      .\]
      The limit as this ordinary differential equation goes to infinity is zero.
    \item 2 real complex conjugate roots. If
      \[
      r=-\frac{b}{2m}\pm i \frac{\sqrt{4mk-b^2} }{2m}
      .\]
      Our $\alpha = -\frac{b}{2m}$, and our $\beta=i \frac{\sqrt{4mk-b^2} }{2m}$. Our general solution in this scenario would be
      \[
        x(t)=C_1e^{-\frac{b}{2m}t}\cos\left( i \frac{\sqrt{4mk-b^2} }{2m}t \right) +C_2e^{-\frac{b}{2m}t}\sin\left( i \frac{\sqrt{4mk-b^2} }{2m}t \right)
      .\]
      \[
        \lim_{t \to \infty} x(t)=0
      .\]
  \end{itemize}
\subsection{Non-homogeneous Linear Equations}

\subsubsection{Method of Undetermined Coefficients}

When can we use the method of undetermined coefficients? This method can be used with
\begin{itemize}
  \item Most constant coefficient ordinary differential equations
  \item Non-homogeneous term must be of the form:
    \begin{itemize}
      \item Polynomials.
      \item $e^{cx}$
      \item $\sin(bx),\cos(bx)$
    \end{itemize}
\end{itemize}

\begin{theorem}
  After finding the homogeneous function $y_h(x):$
  \begin{enumerate}
    \item Make your first guess at the form of $y_p(x)$ with unknown constants based on $f(x)$.
    \item Plug $y_p(x)$ into ordinary differential equation. (Left-hand side equals right-hand side for all $x$'s).
    \item Solve linear system.
    \item Plug back into the guess $y_p(x)$.
    \item General solution is $y(x)=y_h(x)+y_p(x)$.
  \end{enumerate}
\end{theorem}

\begin{eg}
  Consider the following ordinary differential equation.
  \[
  x''-3x'-4x=-7t
  .\]
  In order to solve for $x_h(t)$, we set the right-hand side equal to zero and let $x(t)=re^{rt}$.
  \begin{align*}
    r^2-3r-4&=0\\
    (r-4)(r+1)&=0\\
    r&=4,1
  .\end{align*}
  This gives us that our general homogeneous solution is
  \[
    x_h(t)=C_1e^{4t}+C_2e^{-t}
  .\]
  \begin{enumerate}
    \item Now we make our initial guess of $x_p(t)=At+B$. Then we need to make sure that it does not match one of the homogeneous solutions from above.
    \item $x_p'(t)=A$, $x_p''(t)=0$

  Now we must plug our $x_p(t)$ and $x_p''(t)$ into our original ordinary differential equation. This gives us
  \[
    0-3A-4(At+B)=-7t
  .\]
  Now We need to separate all the terms that have a $t$ attached to them, and all the solutions that are constant as
  \begin{align*}
    t&:-4A=-7\\
    1&:-3A-4B=0
  .\end{align*}
  \item Now we must simply solve for both $A$ and $B$. After solving, we get that
  \[
    x_p(t)=\frac{7}{4}t-\frac{21}{16}
  .\]
  This gives us the general solution as
  \[
  C_1e^{4t}+C_2e^{-t}+\frac{7}{4}t-\frac{21}{16}
  .\]
  \end{enumerate}
  Just a caution, we need to make sure that we apply our initial and boundary conditions to our general solution only.
\end{eg}

\begin{eg}
  Consider the ordinary differential equation
  \[
  x''-3x'-4x=6e^{-4t}
  .\]
  We can see that $x_h(t)=C_1e^{4t}+C_2e^{-t} $. Our initial guess is going to be $x_p(t)=Ae^{-4t}$. Using our initial guess we can do the following
  \begin{align*}
    x_p''-3x_p-4x_p=6e^{-4t}\\
    16Ae^{-4t}+12Ae^{-4t}-4Ae^{-4t}=6e^{-4t}\\
    24A=6\therefore A=\frac{1}{4}
    x_p(t)=\frac{1}{4}e^{-4t}
  .\end{align*}
  Because our initial guess matched on of the solutions in the homogeneous equation we need to modify our equation or else we will be incorrect, but how do we know how to modify our guess? We need to add a $t$ and check again to make sure that our solution is not matching. Let's try again with $Ate^{-4t}$
  \begin{align*}
    x_p'&=4e^{4t}+4Ate^{4t}\\
    x_p''&=8Ae^{4t}+16Ae^{4t}
  .\end{align*}
  After plugging $x_p$ and $x_p''$ into our ordinary differential equation and solving the system at the end, we get the general result as
  \[
    x(t)=C_1e^{4t}+C_2e^{-t}+\frac{6}{5}te^{4t}
  .\]
\end{eg}

\subsubsection{Variation of Parameters}

  This method is more tedious and difficult than the method described in section (3.4.1), but it is more universal and will find a particular solution to any non-homogeneous linear ordinary differential equation.
  \begin{theorem}
    To solve something using variation of parameters,
    \begin{enumerate}
      \item Find $y_h(x)=C_1y_1(x)+C_2y_2(x)$.
      \item Let $y(x)=v_1(x)y_1(x)+v_2(x)y_2(x)$, where $y_1(x),y_2(x)$ are from the homogeneous solution. Our goal is to find $v_1,v_2$.
      \item Solve system for $v_1',v_2'$. In order to do this, we can use the following system
        \begin{align*}
          y_1'(x)v_1'(x)+y_2'(x)v_2'(x)=f(x)\\
          y_1(x)v_1'(x)+y_2(x)v_2'(x)=0
        .\end{align*}
        In order to do this, we need to use Cramer's rule. Cramer's rule tells us to find
        \begin{align*}
          w(x)&=\left| \begin{matrix} y_1(x)&y_2(x)\\y_1'(x)&y_2'(x) \end{matrix} \right|\\
          v_1'(x)&= \frac{\left| \begin{matrix} 0&y_2\\f(x)&y_2' \end{matrix} \right|}{w(x)} \\
          v_2'(x)&=\frac{\left| \begin{matrix} y_1&0\\y_1'&f(x) \end{matrix} \right| }{w(x)}
        .\end{align*}
      \item Integrate to find $v_1(x)$ and $v_2(x)$. $v_1(x)=\boxed{}+c,v_2(x)=\boxed{}+c$.
      \item Simplify.
    \end{enumerate}
  \end{theorem}

  \begin{eg}
    Solve the ordinary differential equation $x''-2x'+x=\frac{e^{t}}{t}$. First we need to find the homogeneous ordinary differential equation by letting $x_h(t)=e^{rt}$ and solving for $r$. When all is done we end up with $x_1(t)=e^{t},x_2(t)=te^{t}$.
    \begin{enumerate}
      \item Let $x(t)=v_1(t)e^{t}+v_2(t)te^{t}$
      \item Set up a system of equations.
        \begin{align*}
          e^{t}v_1'+te^{t}v_2'&=0\\
          e^{t}v_1'+\left( e^{t}+te^{t} \right)v_2'=\frac{e^{t}}{t}
        .\end{align*}
        Now we can solve this to get $v_1'=-1,v_2'=\frac{1}{t}$.
      \item Now we need to integrate both $v_1(t)$ and $v_2(t) $ like so
        \begin{align*}
          v_1(t)&=\int -1dt=-t+C_1\\
          v_2(t)&=\int \frac{1}{t}dt=\ln|t|+C_2
        .\end{align*}
      \item So,
        \begin{align*}
          x(t)&=(-t+C_1)e^{t}+\left( \ln|t|+C_2 \right) te^{t}\\
              &=-te^{t}+te^{t}\ln|t|+C_1e^{t}+C_2te^{t}
        .\end{align*}
    \end{enumerate}
    Another way we can solve this is using the wronskian,
    \begin{align*}
      w(t)&= \left| \begin{matrix} e^{t}&te^{t}\\e^{t}&te^{t}+e^{t} \end{matrix} \right| = \ldots=e^{2t}\\
      v_1'(t)&=\frac{\left| \begin{matrix} 0&te^{t}\\\frac{e^{t}}{t}&te^{t}+e^{t} \end{matrix} \right| }{w(t)}=\ldots=-1\\
      v_2'(t)&=\frac{\left| \begin{matrix} e^{t}&0\\e^{t}&\frac{e^{t}}{t} \end{matrix} \right| }{w(t)}=\ldots=\frac{1}{t}
    .\end{align*}
  \end{eg}
\subsection{The Forced Spring-Mass System}

The equations from a forced spring-mass system are in the form
\[
  mx''+bx'+kx=f(x)
.\]
In this section we are going to examine the effects of $f(t)$ on the system. There are three cases for the dampening of a system, under damped, over damped, and critically dampened. We are going to be looking at the under damped case first.
\begin{eg}
  Consider the equation
  \[
    x''+w_0^2x=A\cos(\omega t) \text{ where $\omega_0=\sqrt{\frac{k}{m}} $}
  .\]
  If we were to make our guess based off of this information, we should guess that $x_p(t)=B\cos(\omega t) + C\sin(\omega t)$. $x_h(t)=C_1\cos(\omega_0 t)+C_2\sin(\omega_0 t)$, which is the natural frequency of this equation. If $\omega\neq\omega_0$, then we don't have to modify. Otherwise, we will need to modify our equation to
  \[
    x_p(t)=Bt\cos(\omega_0 t)+Ct\sin(\omega_0 t)
  .\]
  Beats happen when $\omega$ is close, but not equal to $\omega_0$. Through a trigonometric identity,
  \begin{align*}
    x(t)&=\frac{-2A}{\omega_0^2-\omega^2}\sin\left( \frac{\omega+\omega_0}{2}\cdot t \right) \sin\left( \frac{\omega-\omega_0}{2}t \right)
  .\end{align*}
\end{eg}
\begin{eg}
  A mass of $5kg$ stretches a spring $10cm$ and is acted on by an external force of $10\sin\left( \frac{t}{2} \right) N$ and moves in a viscous medium that imparts a force of 2 N when the speed is $4 \frac{cm}{s}$. Find the initial value problem that models setting the mass in motion from its equilibrium position with an upward velocity of $3 \frac{cm}{s}$.\par
  Let $t$ be time since the mass in set in motion in seconds. Let $x$ be displacement (where up is positive) of the mass from equilibrium.
  \begin{align*}
    mg&=ks\\
    5.98&=k(0.1m)\\
    \to k&=490 \frac{kg}{s^2}
  .\end{align*}
  \begin{align*}
    5x''+bx'+490x&=10\sin\left( \frac{t}{2} \right) \\
    x(0)&=0\\
    x'(0)=0.03
  .\end{align*}
  They told us that $f_{damping}=-bx'$. We know that the force damping when at a velocity of $0.4 \frac{m}{s^2}$, so we can solve for $b$ and see that $b=50$. This makes our ordinary differential equation
  \[
  x''+10x'+98x=2\sin\left( \frac{t}{2} \right)
  .\]
  We should expect to see trigonometric functions because of the value of $f(x)$. Let's try the equation
  \[
    x_p(t)=A\cos\left( \frac{t}{2} \right) +B\sin\left( \frac{t}{2} \right)
  .\]
  We can use $b-4mk$ to determine the numbers required for our homogeneous solution.
\end{eg}

\begin{theorem}
  Here is the outline for solving these problems.
  \begin{enumerate}
    \item Find $x_h(t)=C_1e^{\alpha t}\cos\left( \beta t \right) +C_2e^{\alpha}\sin\left( \beta t \right) $
    \item Find $x_p(t)=A\cos\left( \beta t \right) +B\sin\left( \beta t \right) $
    \item State general solutions.
    \item Apply initial conditions to find $C_1,C_2$.
    \item Find the particular solution
  \end{enumerate}
\end{theorem}

\begin{note}
  The maximum amplitude occurs when
  \begin{align*}
    \omega=\sqrt{\omega_0^2-2\lambda}\\
    \omega_0=\sqrt{\frac{k}{m}}
  .\end{align*}
\end{note}
\subsection{Solving Cauchy Euler Ordinary Differential Equations}
\subsubsection{Method of Lucky Guess}

If an equation is not in the form
\[
ax^2y'' + bxy'+cy=0
,\] then we cannot use the method of lucky guess. This method is common in polar, cylindrical, and spherical coordinates. The first thing we need to do when using this method is put it in standard form,
\[
y''+\frac{b}{a}\frac{1}{x}y'+\frac{c}{ax^2}y=0
.\]
Now, we just need to let $y(x)=x^{r}$ to find our $r$-values.
\begin{eg}
  Solve the following ordinary differential equation.
  \[
  x^2y'''+2xy''-6y'=0
  .\]
  Let $y(x)=x^{r}$. Using this we can find that $y'=rx^{r}, y''=r(r-1)x^{r-2},y'''=r(r-1)(r-2)x^{r-3}$. Now let's plug our $y$'s into our ordinary differential equation and solve for $r$ like the following.
  \begin{align*}
    x^2r(r-1)(r-2)x^{r-3}+2xr(r-1)x^{r-2}-6rx^{r-1}&=0\\
    x^{r-1}\left[ \left( r^{3}-3r^2+2r \right) + \left( 2r^2-2r \right) -6r  \right]&=0\\
    r\left[ r^2-3r+2+2r-2-6 \right] &=0\\
    r\left[ r^2-r-6 \right]&=0\\
    r(r-3)(r+2)&=0\\
    \to r&=0,3,-2.
  .\end{align*}
  From here we can determine the following.
  \begin{align*}
    y_1(x)&=x^{0}=1\\
    y_2(x)&=x^{3}\\
    y_3(x)&=x^{2}
  .\end{align*}
  So the general solution of our ordinary differential equation is
  \[
    y(x)=C_1+C_2x^{3}+\frac{C_3}{x^2}
  .\]
\end{eg}
  If $r$ is repeated, then $y_1(x)=x^{r},y_2=x^{r}\ln x,y_{n}(\ln x)^n$. If $r=\alpha\pm i\beta$, then we need to set
  \begin{align*}
    y_1(x)&=x^{\alpha}\cos(\beta\ln x)\\
    y_2(x)&=x^{\alpha}\sin(\beta\ln x)
  .\end{align*}
  This gives us two equations,
  \begin{align*}
    ay''+by'+cy=0 && ax^2y''+bxy+cy=0
  .\end{align*}
  Let's take a look at an example for this.
\begin{eg}
  Consider the equation $4x^2y''+y=0$
  \begin{enumerate}
    \item Let $y(x)=e^{r}$, after taking the derivatives we can see that
      \begin{align*}
        x^{r}[4r(r-1)+1]&=0\text{ for all $x$'s}\\
        4r^2-4r+1&=0\\
        (2r-1)^2=0\to r=\frac{1}{2},\frac{1}{2}
      .\end{align*}
      This gives us that our general solution is
      \[
      C_1x^{\frac{1}{2}}+C_2x^{\frac{1}{2}}\ln x, x>0
      .\]
    \item Let's consider a different approach.
      \begin{align*}
        x^{r}[4r(r-1)+17]&=0\\
        4r^2-4r+17&=0\\
        (2r-1)^2&=1-17\\
        |2r-1|&=4i\\
        2r-1&=\pm_4i\\
        r=\frac{1}{2}\pm 2i
      .\end{align*}
      This tells us that the general solution is
      \[
        y(x)=C_1x^{\frac{1}{2}}\cos(2\ln x)+C_2x^{\frac{1}{2}}(2\ln x),x>0
      .\]
  \end{enumerate}
\end{eg}
The equation $ax^2 \frac{d^2y}{dt^2}+bx \frac{dy}{dt}+cy=0$ can be transformed via $x=e^{t},t=\ln x$ to
\[
  a \frac{d^2y}{dt^2}+(b-a) \frac{dy}{dt}+cy=0
.\]
Let's take a look at another example.
\begin{eg}
  Consider the following ordinary differential equation,
  \[
  \rho \frac{d^2u}{d\rho^2}+2 \frac{du}{d\rho}=0
  .\]
  Let $u(a)=A,u(b)=B$. We can see that $u(\rho)=\rho^{r}, u'=r\rho^{r-1}, u''=r(r-1)\rho^{r-2}$. Now in order to solve this ordinary differential equation, we need to determine the roots of $r$, and we need to solve for both $C_1,C_2$.
  \begin{align*}
    \rho^{r-1}[r(r-1)+2r]&=0\\
    r^2-r+2r&=0\\
    r^2+r&=0\\
    r(r+1)&=0\\
    r&=0,1
  .\end{align*}
  Now, we can determine that $u(\rho)=C_1+C_2\rho^{-1}$ as long as $\rho>0$. We can now use the following system to solve for $C_1,C_2$,
\begin{align*}
  \begin{cases}
    \rho(a)=C_1+\frac{C_2}{a}=A & C_2=\frac{A-B}{\frac{1}{a}-\frac{1}{b}}=\frac{ab(B-A)}{a-b}\\
    \rho(b)=C_1+\frac{C_2}{b}=B & C_1=\frac{aA-bB}{a-b}
  \end{cases}
\end{align*}
\end{eg}

Let's take a look at another example.
\begin{eg}
  Consider the ordinary differential equation
  \[
    x^2y''-2xy'+2y=-x\text{, where }x>0
  .\]
  From here, we need to put our equation into standard form, so it looks like
  \[
    y''-\frac{2}{x}y'+\frac{2}{x^2}y=-\frac{1}{x}\text{, where $-\frac{1}{x}=f(x)$}
  .\]
  The first thing we need to do now is solve for $y_h(x)$, which means we have to do the following
  \begin{align*}
    x^2y''-2xy'+2y&=0\\
    r&=2,1\\
    y_1(x)=x^2\\
    y_2(x)=x\\
    y_h(x)=C_1x^2+C_2x
  .\end{align*}
  Now we are going to use variation of parameters to solve for $C_1,C_2$. In order to do this, let $y(x)=v_1(x)x^2+v_2(x)x$. We can either use a linear system to solve this, or we can use the wronskian. Using the linear system, we end up with
  \begin{equation*}
    \begin{cases}
      x^2v_1'+xv_2'=0\\
      2xv_1'+1v_2'=-\frac{1}{x}
    \end{cases}
  \end{equation*}
  If we were to use the wronskian we would do the following
  \begin{align*}
    w(x)&=\left| \begin{matrix} x^2&x\\2x&1 \end{matrix} \right| =x^2-2x^2=-x^2\\
    v_1'&= \frac{\left| \begin{matrix} 0&x\\-\frac{1}{x}&1 \end{matrix} \right| }{-x^2}=-\frac{1}{x^2}\\
    v_2'&=\frac{\left| \begin{matrix} x^2&0\\2x&-\frac{1}{x} \end{matrix} \right| }{-x^2}=-\frac{x}{x^2}=\frac{1}{x}\\
    v_1=\int-\frac{1}{x^2}dx=\frac{1}{x}+C_1\\
    v_2=\int \frac{1}{x}dx=\ln|x|+C_2
  .\end{align*}
  So $y(x)=v_1x^2+v_2x$. After simplification, we end up with
  \[
    y(x)=C_1x^2+C_3x+x\ln|x|
  .\]
\end{eg}
\subsubsection{Taylor and Frobenius Series Solutions to Linear Ordinary Differential Equations}

This is a backup strategy if the method of lucky guess does not work. In this strategy, the main point is to let
\[
  y(x)=\sum_{n=0}^{\infty}C_n(x-x_0)^{n}
.\]
Our goal is to use our initial conditions to solve the ordinary differential equation and find $C_n$'s. Sometimes we need a more generalized series, and that is when we are going to use the frobenius series. Here is the general pathway through one of these problems.
\begin{align*}
  y(x)&=(x-x_0)^{r}\sum_{n=0}^{\infty} C_n(x-x_0)^{n}\\
  x_0&\to 0\\
  y(x)&=\sum_{n=0}^{\infty} C_nx^{n+r}
.\end{align*}
Given an ordinary differential equation with initial conditions, $y(0)=y_0,y'(0)=v_0$, let
\begin{align*}
  y(x)&=C_0+C_1x+C_2x^2+C_3x^3\\
  y'(x)&=C_1+2C_2x+3C_3x^2
.\end{align*}
Now we apply our initial conditions, which tell us the first two terms in the solution.
There are three main ordinary differential equations that we need to know that force us to use the Taylor or Frobenius series solutions,
\begin{itemize}
  \item Legendre's ODE
    \[
      (1-t^2)x''-2tx'+\lambda(\lambda+1)x=0
    .\]
  \item Bessel's ODE
    \[
      t^2x''+tx'+(t^2-v^2)x=0
    .\]
  \item Airy's ODE
    \[
    x''-tx=0
    .\]
\end{itemize}
\begin{theorem}
  Consider the equation
  \[
    x''+p(t)x'+q(t)x=0
  ,\] where $f(x)=0$. A singular point of the ordinary differential equation is a value of $t$ where $p,q,\text{ or }f$ is not analytic (cannot be written as Taylor series). If we attempt to solve a singular point ODE, we will end up dividing by 0. An ordinary point are non-singular points.
\end{theorem}
Consider Bessel's ordinary differential equation, $x''+\frac{1}{t}x'+\left( 1-\frac{2^2}{t^2} \right) = 0 $ This equation has a singular point of $t=0$. A point is regular if $tp$ (in this case $t-t_0$) and $t^2q$ ($\left( t-t_0 \right) ^2$) are analytic. Otherwise, they are irregular points. In the case of Bessel's ordinary differential equation, there is a regular singular point.
\begin{theorem}
  If you expect a Taylor series at $t=t_0$ (ordinary point) and the radius of convergence is at least as big as the distance to the nearest singular point (can be complex), then there exist 2 linearly independent series solutions. If $t=t_0$ is a singular point, you need to use a frobenius series.
\end{theorem}
\begin{eg}
  Consider Airy's ordinary differential equation, $x''-t=0$. The two linearized solutions are $A_i(t)$ and $B_i(t)$. We are given the initial conditions $x(0)=1,x'(0)=-2$. From here, let $x(t)=1-2t+C_2t^3+C_4t^{4}$, this gives us that
  \begin{align*}
    x'(t)&=-2+2C_2t+3C_3t^2+4C_4t^3\\
    x''&=C_2+6C_3t+12C_4t^2
  .\end{align*}
  If we plug the equations above into Airy's equation, we get
  \[
  \left[ 2C_2+6C_3t+12C_4t^2+\ldots \right]-t\left[ 1-2t+C_2t^2+C_3t^3+C_4t ^{4}+\ldots \right] =0
  .\]
  We can pull out specific values in order to solve for $C_2,C_3,C_4$, like the following
  \begin{align*}
    1&:2C_2=0 &&\to C_2=0\\
    t&:6C_3-1=0&&\to C_3=\frac{1}{6}\\
    t^2&:12C_4+2=0&&\to C_3=-\frac{1}{6}
  .\end{align*}
  From here, we can determine that our general solution is
  \begin{equation*}
    \boxed{x(t)=1-2t+\frac{1}{6}t^3-\frac{1}{6}t ^{4}+\ldots}
  \end{equation*}
  For general initial conditions ($x(0)=C_0, x'(0)=C_1$).
  \begin{align*}
    x''-tx\\
    [2C_2+6C_3t+12C_4t^2+\ldots]-t[C_0+C_1t+C_2t^2+\ldots]\\
  .\end{align*}
  \begin{align*}
    1&:2C_2=0&&\to C_2=0\\
    t&:6C_3-C_0=0&&\to C_3=\frac{1}{6}C_0\\
    t^2&:12C_4-C_1=0&&\to C_4=\frac{1}{12}C_1\\
  .\end{align*}
  This would make our particular solution
  \begin{align*}
    x(t)&=C_0+C_1t+\left( \frac{1}{6}C_0 \right) t^3+\left( \frac{1}{12}C_1 \right) t ^{4}\\
  .\end{align*}
\end{eg}

Another important skill that plays in with Taylor series ordinary differential equations is re-indexing. This is basically just an u-substitution for a series. Our goal is to rewrite
\[
  \sum_{n=2}^{\infty} n(n-1)a_nt ^{n-2}
.\]
In order to have $t ^{k}$, we need to let $k=n-2\to n=k+2$, which gives us a series that looks like
\[
  \sum_{k=0}^{\infty} (k+2)(k+1)a_{k+2}t ^{k}
.\]
Let's take a look at re indexing  when it comes to Airy's equation.
\[
x''-tx=0
.\]
\begin{eg}
  \begin{align*}
    x(t)&=\sum_{n=0}^{\infty} C_nt^n\\
    x'(t)&=\sum_{n=1}^{\infty} C_nnt ^{n-1}\\
    x''(t)&=\sum_{n=2}^{\infty} C_nn(n-1)t ^{n-2}=
  .\end{align*}
  We can rewrite Airy's ODE as
  \[
    \sum_{n=2}^{\infty} C_nn(n-1)t ^{n-2}-t \sum_{n=0}^{\infty} C_nt ^{n}=0
  .\]
  Because we have a difference of 3 in the exponents, let $n-2 = k + 1, n=k+3 \text{ or } k=n-3$. This makes our Taylor series
  \[
    \sum_{k=-1}^{\infty} C_{k+3}(k+3)(k+2)t ^{k+1}-\sum_{n=0}^{\infty} C_nt ^{n+1}=0
  .\]
  Now if we choose another variable $m$ and take both $k,n$ and put them in terms of $m$, we get
  \[
    C_2(2)(1)t ^{0}+\sum_{m=0}^{\infty} \left[ C_{m+3}(m+3)(m+2)-C_m \right] t ^{m+1}=0
  .\]
  From here, we can solve for $C_2$ using $2C_2=0$ for the 1's values. This leaves us with
  \[
    m\ge 0:C_{m+3}(m+3)(m+2)-C_m=0\\
  .\]
  Our general recursion relation is
  \[
    C_{m+3}=\frac{C_m}{(m+3)(m+2)}
  .\]
  If we follow our recursion relationship
  \begin{align*}
    m=0:&&C_3=\frac{C_0}{3\times2}=\frac{1}{6}C_0\\
    m=1:&&C_4=\frac{C_1}{4\times 3}=\frac{1}{12}C_1\\
    m=2&&C_5=\frac{C_2}{5\times 4}=0\\
    m=3:&&C_6=\frac{C_3}{6\times 3}=\frac{1}{18}C_3=\frac{1}{18}\times \frac{1}{6}C_0=\frac{1}{108}C_0
  .\end{align*}
  Every third coefficient is 0, all other coefficients can be expressed in terms of $C_1,C_2$.
  \begin{align*}
    x(t)&=C_0+C_1t+C_2t^2+\ldots\\
        &=C_0+C_1t+\frac{1}{6}C_0t^3+\frac{1}{16}c_1t ^{4}+\ldots\\
        &=C_0\left[ 1+\frac{1}{6}t^3+\frac{1}{108}t ^{6}+\ldots \right] + C_1\left[ t+\frac{1}{12}t ^{4}+\ldots \right]
  .\end{align*}
\end{eg}
Let's take a look at another example to solidify understanding.
\begin{eg}
  Consider the equation $(x+2)y''+3y'+4y=0$. Let $y(x)=\sum_{n=0}^{\infty} C_nx^{n}$. This makes our differential
  \[
    (x+2)\sum_{n=2}^{\infty} C_nn(n-1)x^{n-2}+3 \sum_{n=1}^{\infty} C_nnx^{n-1}+4 \sum_{n=0}^{\infty} C_nx^{n}=0
  .\]
  Let $n-2=k-1$, which would make $n=k+1,k=n-1$. Also let $n=j-1,j=n+1$ After changing our values, our ordinary differential equation, our equation is
  \[
    \sum_{n=2}^{\infty} C_nn(n-1)x^{n-1}+\sum_{k=1}^{\infty} 2C_{k+1}(k+1)kx^{k-1}+\sum_{n=1}^{\infty} 3c_nnx^{n-1}+\sum_{j=1}^{\infty} 4C_{j-1}x^{j-1}=0
  .\]
  Now rewrite $n,k,j\to m$. Let  $k,n,j=1$. This makes our differential
  \begin{align*}
    0=&2C_2\times 2\times 1\times x^{0}+3C_1\times 1\times x^{0}+4C_0\times x^{0}\\
    +&\sum_{m=2}^{\infty} \left[ C_m\left[ m(m-1)+3m \right] +2C_{m+1}(m+1)m+4C_m-1 \right]x^{m}
  .\end{align*}
  After simplification, we can pull out like terms to solve for $C_2$ and the recursion relation.
  \begin{align*}
    1&:4C_2+3C_1+4C_0=0&&\to C_2=\frac{-3C_1-4C_0}{4}\\
    x^{m-1}&:C_m(m^2+2m)+2C_{m+1}(m+1)m+4C_m-1 = 0
  .\end{align*}
  Our general recursion relation as long as $m\ge 2$ is
  \[
    C_{m+1}=\frac{-m(m+2)C_m-4C_m-1}{m(m+1)}
  .\]
  If we set $m=2$, we can solve and get results for $C_1, C_2$. One approach to finding two linearly independent solutions is to set $y(x)=C_0+C_1x+C_2x^2$, and then use the values calculated from $C_{m+1}$ to get
  \begin{align*}
    &=C_0+C_1x+\left( -\frac{3}{4}C_1-C_0 \right)x^2+(\text{from above})x^3\\
    &=C_0\left[ 1-x^2+\boxed{}x^3+\ldots \right] +C_1\left[ x-\frac{3}{4}x^2+1 \right] x^3
  .\end{align*}
\end{eg}

An alternative for finding two linearly independent solutions is solving with $C_0=1,C_1=0$. This makes our initial conditions $x(0)=1,x'(0)=0$. This makes our $C_2=-1,C_3=\frac{2}{3},C_4=-\frac{1}{4}$. We also need to solve with the initial conditions $x(0)=0,x'(0)=1$. This makes our solutions
\begin{align*}
  y_1(x)&=1+0x-1x^2+\frac{2}{3}x^3-\frac{1}{4}x^{4}\\
  y_2(x)&=0+1x-\frac{3}{4}x^2+\frac{1}{6}x^3+\frac{1}{48}x^{4}
.\end{align*}
The general solution is
\[
  y(x)=C_1y_1(x)+C_2y_2(x)
,\]
where $C_1=x(0),C_2=x'(0)$. A Frobenius series is when you expand around a singular point (a point that is hard for the equation). Consider Bessel's ordinary differential equation.
\begin{eg}
  \[
  x^2y''+xy'+\left( x^2-\frac{1}{4} \right) y=0\text{ with }\nu=\frac{1}{2}
  .\]
  Here we are going to let $y(x)=\sum_{n=0}^{\infty} C_nx^{n+r}$, and our goal is to find $n$ and $c_n$. We can easily find that
  \begin{align*}
    y'&=\sum_{n=0}^{\infty} C_n(n+r)x^{n+r-1}\\
    y''&=\sum_{n=0}^{\infty} C_n(n+r)(n+r-1)x^{n+r-2}
  .\end{align*}
  Our ordinary differential equation written out is
  \[
    \sum_{n=0}^{\infty} C_n(n+r)(n+r-1)x^{n+r}+\sum_{n=0}^{\infty} C_n(n+r)x^{n+r}+\sum_{n=0}^{\infty} C_nx^{n+r+2}-\sum_{n=0}^{\infty} \frac{1}{4}C_nx^{n}=0
  .\]
  Let $k+r=n+r+2$. This gives us that
  \[
    \sum_{n=0}^{\infty} C_n\left[ (n+r)(n+r-1)+(n+r)-\frac{1}{4} \right] x^{n+r}+\sum_{k=2}^{\infty} C_{k-2}x^{k+r}=0
  .\]
  If we transform the $k$  into an $n$ , we get that
  \begin{align*}
    &\sum_{n=2}^{\infty} \left( C_n\left[ (n+r)(n+r-1+1)-\frac{1}{4} \right] +C_n-2 \right) x^{n+r}+\\&C_0\left( r(r-1)+r-\frac{1}{4} \right) x^{r}+C_1\left[ (r+1)(r)+(r+1)-\frac{1}{4} \right] x^{r+1}
  .\end{align*}
  Now we can pull out like terms to create a system of equations to solve for $C$ values:
  \begin{align*}
    x^{r}&:&&r^2-\frac{1}{4}=0\text{ or }C_0=0\\
    x^{r+1}&:&&(r+1)^2-\frac{1}{4}=0\text{ or }C_1=0\\
    x^{r+h}&:&&C_n=\frac{-C_n-2}{(n+r)^2-\frac{1}{4}}
  .\end{align*}
  If $C_0\neq 0, r=\pm \frac{1}{2}$ or if $C_1\neq 0, r+1=\pm \frac{1}{2}$. There are two linearly dependent solutions
  \begin{itemize}
    \item $r=\frac{1}{2}$
    \item $r=-\frac{1}{2}$
  \end{itemize}
  If we take $r=\frac{1}{2}$ and simplify $C_n$, we can see that
  \[
    C_n=\frac{-C_n-2}{n(n+1)}, n\ge 2
  .\]
  Using this, we can solve for a certain number of terms to get that
  \[
    y_1(x)=x^{\frac{1}{2}}\left[ C_0-\frac{1}{3!}C_0x^2+\frac{1}{5!}x^{4}+\ldots \right]
  .\]
  This equation simplifies down to
  $\frac{C_0}{\sqrt{x} }\sin (x)$.
\end{eg}


\section{Adapt the \acrshort{nrpa} to stochastic problem}%
\label{sec:adapt_the_nrpa_to_stochastic_problem}

As explained in section \ref{sec:the_nrpa}, the \gls{nrpa} is an algorithm that obtains state of the art results on different optimization problem.
All these problems have in common to be non stochastic problem.
It means that if we apply action \(a\) on state \(s\) and we obtain the state \(s'\) then, when repeating the same process, we will always obtain \(s'\).
In a stochastic context, this assurance does not exist.
Meaning that, when applying \(a\) on \(s\) we may obtain \(s'\) but also \(s^{*}\) or \(s''\)  or any others, depending on the problem.

In this section, we are going to present how we tried to adapt the \gls{nrpa} to solve stochastic problem.
We will first discuss a bit more what a stochastic problem is by considering a small example in order to highlight the difficulty to solve one.
Then we will explain why the \gls{nrpa} is not well suited to solve this kind of problem by identifying the main issues.
Then, we will present how we attended to these issues by explaining our new algorithm the \gls{snrpa}.

\subimport{./subs/}{stochastic.tex}
\subimport{./subs/}{nrpa.tex}
\subimport{./subs/}{snrpa.tex}


\chapter{A Brief Note on Feature Engineering \label{chapter:feateng}}

All machine learning algorithms and statistical models depend on the concept of a \textbf{feature}. A feature is some aspect of a dataset that, the model designer believes, represents the data in a way that is relevant to the problem he/she is trying to solve.

Before any algorithm can be applied, therefore, it is necessary to decide how to represent the data: which features to include and how to extract them from the raw data. This task is called \textbf{feature engineering}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Study Design vs. Feature Engineering}

We have seen a large number of features in Chapters~\ref{chapter:overview}--\ref{chapter:logreg}, but we never stopped to consider them. That's because, in many datasets, the features are chosen at the \textbf{study design} stage. The analyst (statistician, data scientist, etc.) has no say in what the features look like or which features are included.

This paradigm is changing as data science increasingly focuses on large, observational datasets, like those from electronic medical records (EMRs). In these types of studies, the raw data were not collected for the study itself, but to fulfill some other purpose. The analyst must choose how to build features from the raw data and use them in models.
\vspace{4mm}

\begin{question}{}
The examples in Chapters~\ref{chapter:classification} and~\ref{chapter:regression} used the same two features. What were these features? How were they represented? What are some alternatives to this choice of features?
\end{question}

\begin{question}{}
In Chapter~\ref{chapter:decisiontrees}, we looked at the Wisconsin Breast Cancer Dataset, which includes $30$ different imaging features relevant to predicting whether a tumor is benign or malignant. How were these features represented? What are some alternatives to this choice?
\end{question}

\begin{question}{}
In Chapters~\ref{chapter:linreg} and~\ref{chapter:logreg}, we looked at two datasets that were collected for the purposes of answering particular questions. Do you agree with these study designers' choice of features? What other features could potentially have been relevant to answering each research question?
\end{question}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Turning Data into Numbers}

A model is just a tool for learning relationships among sets of numbers. The first step in any data science problem, therefore, is deciding how to represent what is often a large, complex, noisy dataset as a set of numbers.

\subsection{Numbers}

Sometimes you get lucky and the feature you need is already a number, such as a vital sign measurement, lab value, or other biomarker. In that case, more often than not, the feature enters into the model as its raw value.

In some cases, you may also choose to apply a \textbf{transformation} to the feature before it enters the model. A transformation is simply the application of a deterministic mathematical function that changes the shape of the distribution of the feature. Transformations are often used to improve the interpretability of a model and/or to ensure that the model fulfills the assumptions of the statistical inference method(s) being used (e.g., a hypothesis test).
\vspace{4mm}

\begin{question}{}
Here are $100$ random samples from a normal distribution with $\mu = 3.0$ and $\sigma = 0.5$ and five different transformations of those samples. What do you notice about the shape and position of the data under the different transformations?
\begin{center}
\includegraphics[width=0.4\textwidth]{img/normal-transform-0.png}
\includegraphics[width=0.4\textwidth]{img/normal-transform-1.png}
\includegraphics[width=0.4\textwidth]{img/normal-transform-2.png}
\includegraphics[width=0.4\textwidth]{img/normal-transform-3.png}
\includegraphics[width=0.4\textwidth]{img/normal-transform-4.png}
\includegraphics[width=0.4\textwidth]{img/normal-transform-5.png}
\end{center}
\end{question}

\begin{question}{}
Here are $100$ random samples from an exponential (see Section~\ref{sect:exponential}) distribution with $\lambda = 0.8$ and the same five transformations of those samples. What do you notice about the shape and position of the data under the different transformations?
\begin{center}
\includegraphics[width=0.4\textwidth]{img/exp-transform-0.png}
\includegraphics[width=0.4\textwidth]{img/exp-transform-1.png}
\includegraphics[width=0.4\textwidth]{img/exp-transform-2.png}
\includegraphics[width=0.4\textwidth]{img/exp-transform-3.png}
\includegraphics[width=0.4\textwidth]{img/exp-transform-4.png}
\includegraphics[width=0.4\textwidth]{img/exp-transform-5.png}
\end{center}
\end{question}

Economics, the social sciences, and related disciplines, which are heavily dependent on the use of regression models and hypothesis tests, rely extensively on transformations. In my experience, machine learning folks spend almost no time on them because their primary concern is predictive accuracy, not model interpretation. Machine learning practitioners, however, very frequently \textbf{scale and center} their predictors (see footnote in Section~\ref{section:sehyp}), which is another type of transformation. We will get into more detail on transformations as we continue to learn about regression models.

\subsection{Binary Variables}

For features which are yes/no (e.g., presence/absence of a disease, symptom, physical attribute, etc.) the most common coding scheme is to use ``1'' for ``yes'' and ``0'' for ``no''. This is useful for interpretation, particularly in regression models. In a linear regression model using this coding scheme, for example, the model coefficient will be the shift in the mean of the normal distribution representing the outcome, $y$, when the feature is present.

\subsection{Categories}

Categorical features with $k>2$ categories are generally represented using \textbf{indicator variables}. If a feature, $x$, has $k$ \textbf{levels}, we can use $k-1$ yes/no indicator variables to represent that feature. For example, assume $k = 3$ and the possible levels of our feature, $x$, are $A$, $B$, and $C$. We set:
\begin{align*}
x_1 &= \left\{ \begin{array}{cl} 1 & \text{ if }x = A \\
                                                0 & \text{ otherwise} \end{array} \right. \\[2mm]
x_2 &= \left\{ \begin{array}{cl} 1 & \text{ if }x = B \\
                                                0 & \text{ otherwise} \end{array} \right.
\end{align*}
If the value of $x$ is $A$, $x_1 = 1$ and $x_2 = 0$. If it's $B$, $x_1 = 0$ and $x_2 = 1$. The value $C$ is called our \textbf{reference category} and has $x_1 = 0$ and $x_2 = 0$. In this way, information about all three categories is captured using only two variables. Creating indicator variables is just another way of transforming the value of a feature.
\vspace{4mm}

\begin{question}{}
In Section~\ref{sect:lowbwt}, we saw an example of a model that predicts whether or not a mother will give birth to a low birthweight baby. One of the factors considered in that model is the mother's race, which was coded (crudely and probably inaccurately, I might add) as \texttt{1 = white, 2 = Black, 3 = other}. You can tell how the feature \texttt{RACE} was coded by examining the model output. How many indicator variables were used? Which level of the feature was used as the reference category?
\end{question}


\subsection{Checking}

\begin{frame}
  \frametitle{Checking (= Reachability)}

  To establish if a model satisfies a safety
  property amounts to check if some
  {\bf bad state is reachable} from the set
  of initial states
  \vfill
  This can be done automatically by {\bf visiting} the
  set of states that are {\bf reachable} from the initial
  state with the application of a transition
  \vfill
  \pause
  Let $S^{(0)}$ be the set of initial states.
  Algorithmically, it amounts to implement the following loop
  (iteration $i$)
  \vfill
  \begin{boxedminipage}{\textwidth}
  \begin{center}
  Forward-Reachability
  \begin{tabular}{rcl}
     \\
       {\bf Safety Check} & ~~ & If $S^{(i)}$ contains a bad state, return {\bf unsafe} \\
        {\bf Next States} & ~~ & Compute $S^{(i+1)} := S^{(i)} \cup T(S^{(i)})$ \\
    {\bf Fix-Point Check} & ~~ & If $S^{(i+1)} \equiv S^{(i)}$, return {\bf safe}
  \end{tabular}
  \end{center}
  \end{boxedminipage}
  \vfill
  $T(S^{(i)}) = $ states that can be reached from $S^{(i)}$ with a transition

\end{frame}

\begin{frame}
  \frametitle{Checking - Forward Reachability - Property Verified}
  \begin{boxedminipage}{\textwidth}
  \begin{center}
  Forward-Reachability
  \begin{tabular}{rcl}
     \\
       {\bf Safety Check} & ~~ & \colthrat{If $S^{(i)}$ contains a bad state, return {\bf unsafe}}{2,5,8,11|handout:0} \\
        {\bf Next States} & ~~ & \colthrat{Compute $S^{(i+1)} := S^{(i)} \cup T(S^{(i)})$}{3,6,9,12|handout:0} \\
    {\bf Fix-Point Check} & ~~ & \colthrat{If $S^{(i+1)} \equiv S^{(i)}$, return {\bf safe}}{4,7,10,13}
  \end{tabular}
  \end{center}
  \end{boxedminipage}
  \vfill
  \begin{overlayarea}{\textwidth}{4cm}
    \only<1,2|handout:0>{\scalebox{.6}{\input{forward_1.pdf_t}}}
    \only<3-5|handout:0>{\scalebox{.6}{\input{forward_2.pdf_t}}}
    \only<6-8|handout:0>{\scalebox{.6}{\input{forward_3.pdf_t}}}
    \only<9-11|handout:0>{\scalebox{.6}{\input{forward_4.pdf_t}}}
    \only<12,13>{\scalebox{.6}{\input{forward_5.pdf_t}}}
  \end{overlayarea}

\end{frame}

\begin{frame}
  \frametitle{Checking - Forward Reachability - Property Not Verified}
  \begin{boxedminipage}{\textwidth}
  \begin{center}
  Forward-Reachability
  \begin{tabular}{rcl}
     \\
       {\bf Safety Check} & ~~ & \colthrat{If $S^{(i)}$ contains a bad state, return {\bf unsafe}}{1} \\
        {\bf Next States} & ~~ & Compute $S^{(i+1)} := S^{(i)} \cup T(S^{(i)})$ \\
    {\bf Fix-Point Check} & ~~ & If $S^{(i+1)} \equiv S^{(i)}$, return {\bf safe}
  \end{tabular}
  \end{center}
  \end{boxedminipage}
  \vfill
  \begin{overlayarea}{\textwidth}{4cm}
    \only<1|handout:0>{\scalebox{.6}{\input{forward_6.pdf_t}}}
    \only<2>{\scalebox{.6}{\input{forward_7.pdf_t}}}
  \end{overlayarea}

\end{frame}

\begin{frame}
  \frametitle{Back to the washing machine}

Iteration: \only<1|handout:0>{0}\only<2|handout:0>{1}\only<3|handout:0>{2}\only<4|handout:0>{3}\only<5>{4 - Fix Point Reached - System is SAFE}
  \vfill
  \begin{center}
    \only<1|handout:0>{\input{model_4_1}}
    \only<2|handout:0>{\input{model_4_2}}
    \only<3|handout:0>{\input{model_4_3}}
    \only<4|handout:0>{\input{model_4_4}}
    \only<5>{\input{model_4_5}}
  \end{center}

\end{frame}

\begin{frame}
  \frametitle{Checking - Backward Reachability}
  \begin{boxedminipage}{\textwidth}
  \begin{center}
  Backward-Reachability ($S^{(0)} \equiv$ ``bad states'')
  \begin{tabular}{rcl}
     \\
       {\bf Safety Check} & ~~ & If $S^{(i)}$ contains an initial, return {\bf unsafe} \\
        {\bf Next States} & ~~ & Compute $S^{(i+1)} := S^{(i)} \cup T^{-1}(S^{(i)})$ \\
    {\bf Fix-Point Check} & ~~ & If $S^{(i+1)} \equiv S^{(i)}$, return {\bf safe}
  \end{tabular}
  \end{center}
  \end{boxedminipage}
  \vfill
  \begin{overlayarea}{\textwidth}{4cm}
    \only<1|handout:0>{\scalebox{.6}{\input{backward_1.pdf_t}}}
    \only<2>{\scalebox{.6}{\input{backward_2.pdf_t}}}
  \end{overlayarea}

\end{frame}


\documentclass[12pt, a4paper]{article}
\usepackage[margin=1.25in]{geometry}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{float}
\usepackage{listings}
\usepackage{caption}
\usepackage{physics}
\usepackage[shortlabels]{enumitem}

\setlength\parindent{0pt}
\newcommand{\code}{\lstinline[basicstyle=\small]}
\lstset{
    language=Python,
    basicstyle=\scriptsize
}

\title{EE2703: Applied Programming Lab \\ \Large Assignment 7: Circuit Analysis using Sympy}
\author{Soham Roy \\ \normalsize EE20B130}
\date{\today}
\begin{document}

\maketitle % Insert the title, author and date

\section{Introduction}
The goal of this assignment is to understand the symbolic algebra capabilities of python and to circuits using
the Laplace Transform. \\
The aim is also to understand the basics of the high pass and low pass filter circuits.

\section{Subquestions}
\subsection{Question 1}
To find the transfer function of the given circuit, and then find the unit step response.
Solving the circuit by using the basic KCL and KVL laws, we get the following solution in matrix form:
\[
    \begin{pmatrix}
        0                                    & 0             & 1 & -1/G \\
        \frac{-1}{1+sc_2R_2}                 & 1             & 0 & 0    \\
        0                                    & -G            & G & 1    \\
        -\frac{1}{R_1} -\frac{1}{R_2} - sC_1 & \frac{1}{R_2} & 0 & sC_1
    \end{pmatrix}
    \begin{pmatrix}
        V1 \\
        Vp \\
        Vm \\
        V0
    \end{pmatrix}
    =
    \begin{pmatrix}
        0 \\
        0 \\
        0 \\
        -\frac{Vi(s)}{R_1}
    \end{pmatrix}
\]

We then use the \code{sympy} library to implement this in python and also solve for the voltage vector.
We calculate the Voltage response for a unit input, which would thus give me the transfer function of this circuit.
We then plot the Frequency response of this circuit. The following is the code:

\begin{lstlisting}
    def lowpass(Vi, R1=10000, R2=10000, C1=1e-9, C2=1e-9, G=1.586):
        A = sym.Matrix(
            [
                [0, 0, 1, -1 / G],
                [-1 / (1 + s * R2 * C2), 1, 0, 0],
                [0, -G, G, 1],
                [-1 / R1 - 1 / R2 - s * C1, 1 / R2, 0, s * C1],
            ]
        )
        b = sym.Matrix([0, 0, 0, -Vi / R1])
        V = A.inv() * b

        return A, b, V

    title = "Lowpass Filter Magnitude Response"

    A, b, V = lowpass(1)
    V_o = V[3]
    print(V_o)
    ww = np.logspace(0, 8, 801)
    ss = 1j * ww
    H = sym.lambdify(s, V_o, "numpy")
    HH = H(ss)
    plot(title, "$\omega (rad/s)$", "$|H(j\omega)|$",
         ww, [abs(HH)], plotting_fn=plt.loglog)
\end{lstlisting}
The following plot is obtained.

\begin{figure}[H]
    \centering
    \includegraphics[scale=0.6]{0.png}
\end{figure}

Once we have obtained the system response in \code{sympy} symbolic form, we need to convert it to our standard
\code{scipy.signal.lti} form in order to work with it further, the following function does this job.

\begin{lstlisting}
    def to_num_den(expr):
        num, den = expr.as_numer_denom()
        num = [float(i) for i in sym.Poly(num, s).all_coeffs()]
        den = [float(i) for i in sym.Poly(den, s).all_coeffs()]
        return num, den
\end{lstlisting}

The unit step response of the circuit i.e the output for an input of $u(t)$ is calculated using the following code:

\begin{lstlisting}
    title = "Lowpass Filter Step Response"

    V_o = lowpass(1 / s)[2][3]
    H = sp.lti(*to_num_den(V_o))
    t = np.linspace(0, 5e-3, 10000)
    v = sp.impulse(H, T=t)[1]
    plot(title, "$t (s)$", "$V_o (V)$", t, [v])
\end{lstlisting}

The following plot is obtained:
\begin{figure}[H]
    \centering
    \includegraphics[scale=0.6]{1.png}
\end{figure}

\subsection{Question 2}
This time, we need to obtain the output for a mixed frequency input
\[V_i(t) = (\sin(2000\pi t)+\cos(2*10^6\pi t))u_0(t) Volts\]

This is done as follows:
\begin{lstlisting}
    title = "Lowpass Filter Input Response"

    V_o = lowpass(1)[2][3]
    H = sp.lti(*to_num_den(V_o))
    t = np.linspace(0, 5e-3, 100000)
    input = (np.sin(2000 * np.pi * t) + np.cos(2e6 * np.pi * t)) * (t > 0)
    v = sp.lsim(H, U=input, T=t)[1]
    plot(title, "$t (s)$", "$V (V)$", t, [input, v], ["Input", "Output"])
\end{lstlisting}

The following plots are obtained:
\begin{figure}[H]
    \centering
    \includegraphics[scale=0.6]{2.png}
\end{figure}

This can be explained easily, since we know that a low pass filter only allows those frequencies to pass which are less than the pole frequency, i.e in this case $10^5$, thus the $10^3$ frequency component passes, whereas the $10^6$ frequency component is filtered out. \\Due to the very high frequency of the $10^6$ frequency signal, it appears as if this signal oscillates about the $10^3$ frequncy signal with the latter as it's mean value, in the input.

\subsection{Question 3}
Now, we try to do the same analysis for a high pass filter. A high-pass filter is a filter that passes signals with a frequency higher than a certain cutoff frequency and attenuates signals with frequencies lower than the cutoff frequency.
The code for this part is as follows:
\begin{lstlisting}
    def highpass(Vi, R1=10000, R3=10000, C1=1e-9, C2=1e-9, G=1.586):
        A = sym.Matrix(
            [
                [0, -1, 0, 1 / G],
                [s * C2 * R3 / (s * C2 * R3 + 1), 0, -1, 0],
                [0, G, -G, 1],
                [-s * C2 - 1 / R1 - s * C1, 0, s * C2, 1 / R1],
            ]
        )
        b = sym.Matrix([0, 0, 0, -Vi * s * C1])
        V = A.inv() * b

        return A, b, V

    title = "Highpass Filter Magnitude Response"

    A, b, V = highpass(1)
    V_o = V[3]
    print(V_o)
    ww = np.logspace(0, 8, 801)
    ss = 1j * ww
    H = sym.lambdify(s, V_o, "numpy")
    HH = H(ss)
    plot(title, "$\omega (rad/s)$", "$|H(j\omega)|$",
         ww, [abs(HH)], plotting_fn=plt.loglog)
\end{lstlisting}

The following is the frequency response for the given high pass filter:

\begin{figure}[H]
    \centering
    \includegraphics[scale=0.6]{3.png}
\end{figure}

\subsection{Question 4}
Now, we try to obtain the response of this filter for a damped sinusoidal input as follows:
\[V_{i, hf}(t) = e^{-5 \cdot 10^4t} cos(2\pi \cdot 10^8 \cdot t) \]
\[V_{i, lf}(t) = e^{-5t} cos(2\pi \cdot 10 \cdot t)\]

The code for this is as follows:
\begin{lstlisting}
    title = "Highpass Damped Response for High Frequency"

    V_o = highpass(1)[2][3]
    H = sp.lti(*to_num_den(V_o))
    t = np.linspace(0, 1e-4, 1000)
    input = np.cos(2 * np.pi * 1e8 * t) * np.exp(-5e4 * t) * (t > 0)
    v = sp.lsim(H, U=input, T=t)[1]
    plot(title, "$t (s)$", "$V (V)$", t, [input, v], ["Input", "Output"])

    title = "Highpass Damped Response for Low Frequency"

    t = np.linspace(0, 1, 1000)
    input = np.cos(20 * np.pi * t) * np.exp(-5 * t) * (t > 0)
    v = sp.lsim(H, U=input, T=t)[1]
    plot(title, "$t (s)$", "$V (V)$", t, [input, v], ["Input", "Output"])
\end{lstlisting}

The following graphs are obtained for the high frequency and low frequency inputs respectively.

\begin{figure}[H]
    \centering
    \includegraphics[scale=0.6]{4a.png}
\end{figure}

\begin{figure}[H]
    \centering
    \includegraphics[scale=0.6]{4b.png}
\end{figure}

This can be explained quite easily, we know that a high pass filter will not allow the frequency components lower than pole freuqency to pass. Thus, effectively the low frequency component is filtered and thus it is not observed in the output.\\
Whereas, in the high frequency input case, we see that the output is pretty much same as the input, which indicates that our filter is working as required.

\subsection{Question 5}
We aim to find the unit step response of the high pass filter. For this, we pass $u(t)$ (in Laplace domain 1/s) in the \code{highpass} function, and then compute the inverse Laplace using the \code{scipy.signal.impulse} function.
The following code does this:

\begin{lstlisting}
    title = "Highpass Step Response"

    V_o = highpass(1 / s)[2][3]
    H = sp.lti(*to_num_den(V_o))
    t = np.linspace(0, 5e-3, 10000)
    v = sp.impulse(H, T=t)[1]
    plot(title, "$t (s)$", "$V_o (V)$", t, [v])
\end{lstlisting}

The following is the obtained response:
\begin{figure}[H]
    \centering
    \includegraphics[scale=0.6]{5.png}
\end{figure}

Let's understand this response. As soon as the voltage is applied, i.e at t $\rightarrow0^+$, the capacitors behave as short-circuited, and thus we see a positive voltage at the output node, whereas at t $\rightarrow\infty$ (for practical purposes, this time is not that large), the capacitors would behave as open-circuited for DC-value of voltage and thus we would see zero volts at the output node.

\section{Conclusion}
In this assignment, we have understood the use of \code{sympy} library to do symbolic algebra. We have also learnt how this can be integrated with out previous knowledge of \code{scipy.signal} library to help solve circuits. We have also looked at some basic circuits like the high pass and the low pass filter and their responses for various inputs.

\end{document}


\documentclass[a4paper]{article}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}

\usepackage{algorithm}
\usepackage[noend]{algpseudocode}

\usepackage{titlesec}
\newcommand{\sectionbreak}{\clearpage}

\begin{document}
\title{Solving constraint satisfaction problems using arc consistency and path consistency techniques}
\maketitle
\section{Local consistency algorithms}
\subsection{Arc consistency}
For the arc consistency we use AC1 algorithm.
\begin{algorithm}
    \caption{AC1 algorithm}
    \begin{algorithmic}[1]
        \Procedure{Revise}{$v_i,v_j$}\Comment{a network with two variables $v_i$,$v_j$, domains $D_i$ and $D_j$, and constraint $R_{ij}$ }
            \For {each $ a_i\in D_i$}
                \If {there is no $a_j \in D_j$ with $(a_i,a_j) \in R_{ij}$}
                    \State {remove $a_i$ from $D_i$}
                \EndIf
            \EndFor
        \EndProcedure
    \end{algorithmic}
    \begin{algorithmic}[2]
        \Procedure{AC1}{$N$}\Comment{a constraint network $N = <V,D,C>$}
            \Repeat
                \For {each arc $(v_i, v_j)$ with $R _{ij}\in C$}
                    \State{Revise$(v_i,v_j)$}
                    \State{Revise$(v_j,v_i)$}
                \EndFor
            \Until{no domain is changed}
        \EndProcedure
    \end{algorithmic}
\end{algorithm}

\subsection{Path consistency}
For the path consistency we use PC1 algorithm.
\begin{algorithm}
    \caption{PC1 algorithm}
    \begin{algorithmic}[1]
        \Procedure{Path\_Revise}{$\{v_i,v_j\},v_k$}\Comment{a binary network $<V,D,C>$ with variables $v_i$,$v_j$,$v_k$}
            \For {each pair $ (a_i,a_j)\in R_{ij}$}
                 \If {there is no $a_k \in D_k$ such that $(a_i,a_k) \in R_{ik}$ and $(a_j,a_k) \in R_{jk}$} \State {remove $(a_i,a_j)$ from $R_{ij}$}
                \EndIf
            \EndFor
        \EndProcedure
    \end{algorithmic}

    \begin{algorithmic}[2]
        \Procedure{PC1}{$N$}\Comment{a constraint network $N = <V,D,C>$}
            \Repeat
                \For {each (ordered) triple of variables $v_i, v_j, v_k$}
                    \State{Path\_Revise$({v_i,v_j},v_k)$}
                \EndFor
            \Until{no constraint is changed}
        \EndProcedure
    \end{algorithmic}
\end{algorithm}

\section{Python implementation}
For the implementation we use modified \textbf{python\_constraint} module.
\subsection{Installation}
\begin{itemize}
    \item Clone the repository \newline \texttt{git clone https://github.com/asergeenko/python-constraint.git}
    \item Build and setup the module \newline \texttt{python setup.py build}\newline \texttt{python setup.py install}
\end{itemize}
\subsection{Module overview}
Python implementations of the AC1 and PC1 algorithms are located in \texttt{consistency.py} file. There are four methods:\\\\
\textbf{arc\_revise}\textit{(var1,var2,problem,constraints\_for\_variable)}\\
\textit{\#Implements REVISE procedure from AC1 algorithm}\\

\textbf{Input:}

\textit{var1} and \textit{var2} - variables to revise,

\textit{problem} - \textbf{python\_constraint}'s \textit{Problem} instance,

\textit{constraints\_for\_variable} - dictionary with constraints for variable \textit{var1}

(returned by \textit{getArcs} function from \textbf{constraint} module).\\

\textbf{Output:}

Returns \textit{True} if arc \textit{(var1,var2)} is not arc-consistent

and some values are removed from the domain.\\\\
\textbf{ac1}\textit{(arcs, problem)}\\
\textit{\#Implements AC1 procedure}\\

\textbf{Input:}

\textit{arcs} - arcs (returned by \textit{getArcs} function from \textbf{constraint} module),

\textit{problem} - \textbf{python\_constraint}'s \textit{Problem} instance\\\\
\textbf{path\_revise}\textit{(var1, var2, var3,problem)}\\
\textit{\#Implements PATH\_REVISE procedure from PC1 algorithm}\\

\textbf{Input:}

\textit{var1},\textit{var2}.\textit{var3} - variables to revise,

\textit{problem} - \textbf{python\_constraint}'s \textit{Problem} instance\\

\textbf{Output:}

Returns \textit{True} if the pair \textit{(var1,var2)} is not path-consistent relative to \textit{var3}

and some values are removed.\\\\
\textbf{pc1}\textit{(problem)}\\
\textit{\#Implements PC1 procedure}\\

\textbf{Input:}

\textit{problem} - \textbf{python\_constraint}'s \textit{Problem} instance\\

\section{Problem solving examples}
\subsection{Examples overview}
These algorithms are suitable for CSP problems with binary constraints. So we have \textit{N-Queens problem} (can be found in \texttt{examples/queens/queens.py}) and \textit{Map coloring problem} (can be found in \texttt{examples/map\_coloring/map\_coloring.py}).
N-queens example is the part of the original \textbf{python\_constraint} module and has just one parameter:\\

\texttt{size = 8} \textit{\# size of the chessboard}\\\\
Map coloring example is new and has the following parameters:\\

\texttt{countries = ['A','B','C']} \textit{\# countries}

\texttt{num\_colors = 2} \textit{\# number of colors}

\texttt{neighbors = ['AB','BC','CA']} \textit{\# countries that border each other}
\subsection{Command-line parameters}

\texttt{python queens.py [-h] [-s]\footnote{This parameter is used only with \texttt{queens.py} example.} [-ac] [-pc]}\\
\texttt{python map\_coloring.py [-h] [-ac] [-pc]}\\\\
\texttt{-h} - show help message\\
\texttt{-s} - show solutions on the chessboard (doesn't show by default)\\
\texttt{-ac} - use arc consistency algorithm (not used by default)\\
\texttt{-pc} - use path consistency algorithm (not used by default)\\
\end{document}


\section{Topological division rings and fields}
\label{sec:topological-division-rings-fields}

\para Vector spaces with a compatible topology can not only defined for vector spaces over the ground fields
$\R$ and $\C$ but also over fields $\fldK$ carrying an absolute value
$|\cdot | : \fldK \to \R_{\geq 0}$. This endows the ground field with a topology which will be needed in the
definition of a topological vector space. We therefore give here a brief introduction to topological division
rings and fields first.

\begin{definition}
  Let $R$ be a division ring. By an \emph{absolute value} on $R$ one understands a map $ |\cdot | : R \to \R_{\geq 0}$
  such that the following axioms hold true.
  \begin{axiomlist}[VDR]
  \item
  \label{axiom:field-absolute-value-multiplicativity}
     The function $| \cdot |$ is multiplicative that is
     \[ |xy| = |x|  \, | y| \quad \text{for all } x,y \in R \ . \]
  \item
  \label{axiom:field-absolute-value-subadditivity}
    The triangle inequality is satisfied which means that
    \[ |x + y| \leq  |x| +  | y| \quad  \text{for all } x,y \in R \ . \]
  \item
  \label{axiom:field-absolute-value-nondegeneracy}
  For all $x \in R$ the relation $|x|=0$ holds true if and only if $x=0$.
  \end{axiomlist}
  A division ring or field endowed with an absolute value is called a \emph{valued division ring}
  respectively a \emph{valued field}.
  An absolute value $|\cdot|$ on a division ring $R$ and the corresponding valued
  division ring $(R,|\cdot|)$ are called \emph{non-archimedean} if
  the \emph{strong triangle inequality} is satisfied that is if
  \begin{axiomlist}[VDR]
  \setcounter{enumi}{3}
  \item\label{axiom:field-absolute-value-non-archimedean}
    $ |x + y| \leq  \max \{ |x| , | y| \} $ for all $x,y \in R$.
  \end{axiomlist}
  Otherwise $|\cdot|$ and $(R,|\cdot|)$ are called \emph{archimedean}.
\end{definition}

\begin{lemma}
  Let $(R,|\cdot|)$ be a valued division ring. Then
  \begin{romanlist}
  \item\label{ite:absolute-value-one}
     $|1|=1$,
   \item\label{ite:absolute-value-negative}
     $|-x| =|x|$ for all $x\in R$, and
  \item\label{ite:absolute-value-difference}
     $\big| |x| - |y| \big| \leq |x - y|   \leq  |x| + |y|$ for all $x,y\in R$.
  \end{romanlist}
\end{lemma}

\begin{proof}
  \ref{ite:absolute-value-one} holds true since $|1| = |1^2| = |1|^2$ and $|1| \neq 0$ by $1 \neq 0$.
  To verify \ref{ite:absolute-value-negative} it suffices to show that $|-1| =1$. But that holds true
  since $|-1|^2 = | (-1)^2| = 1$ and $|-1| \geq 0$.
  The last claim follows by
  \[
  - |x-y| = |x| - (|y-x| +|x|) \leq |x| - |y| \leq  |x-y| + |y | - |y| = |x-y|
  \]
  and
  \[
    |x - y|  = | x + (-y)|  \leq  |x| + |-y| = |x| + |y| \ .
  \]
\end{proof}

\begin{examples}
\begin{environmentlist}
\item
  Obviously, the \emph{standard absolute values}
  \[
    |\cdot |_\infty : \Q, \R\to \R_{\geq 0}, \: x \mapsto
    \begin{cases}
      x & \text{if } x\geq 0\\
      -x & \text{if } x< 0
    \end{cases}
  \quad\text{and}\quad
    |\cdot |_\infty : \C\to \R_{\geq 0}, \: z \mapsto \sqrt{z \overline{z}}
  \]
  are absolute values on the fields $\Q$, $\R$ and $\C$, respectively. These absolute values are all archimedean
  since $|1+ 1|_\infty = 2 > 1$. Unless mentioned differently, we always assume
  $\Q$, $\R$ and $\C$ to be equipped with the standard absolute values. If no confusion can arise we usually
  write $|\cdot|$ instead of $|\cdot |_\infty$.
\item
  The \emph{standard absolute value} on the quaternions
  \[
     |\cdot |_\infty : \H \to \R_{\geq 0} , \: q = a + b \quati + c\quatj + d \quatk \mapsto \sqrt{\overline{q}q} = \sqrt{a^2 +b^2+ c^2 + d^2} \ ,
  \]
  where $a,b,c,d$ are real, is an archimedean absolute value. Usually it is briefly denoted $|\cdot|$.
\item
  For every division ring $R$ the map
  \[ |\cdot| :R \to \R, \: x \mapsto
    \begin{cases}
    0 & \text{if } x=0 ,\\
    1 & \text{else}
  \end{cases}
  \]
  is a non-archimedean absolute value. It is called the \emph{trivial absolute value} on $R$.
\item
  An absolute value  $|\cdot|:\fldF \to\R_{\geq 0}$ defined on a finite field $\fldF$ has to be trivial.
  To see this observe that for each $x\in \fldK^\times$ there
  exists an $n\in \N$ such that $x^n =1$. This entails  $|x|^n=1$, hence $|x|=1$
  for all $x\in \fldK^\times$. So $|\cdot|$ is trivial.
\item
  The field of formal Laurent power series $\fldK ((X))$ over a field $\fldK$ can be equipped
  with an absolute value as follows. Choose $0<\varepsilon < 1$
  and define the absolute value $\left| \sum_{k\in \Z} a_k X^k\right| $ of an element
  $\sum_{n\in \Z} a_n X^n\in \fldK ((X)) $ as $\varepsilon^n$, where $n$ is the minimal integer such that $a_n\neq 0$.
\item
  Let $p$ be prime number. For every integer $m\neq 0$ let $\nu_p(m)$ be the exponent of $p$ in the prime factor decomposition of $m$
  that is $m = p^{\nu_p(n)}n$ where $n$ is relatively prime to $p$.
  For $m \in \Z$ and $n\in \gzN$ one defines the \emph{$p$-adic absolute value} of the rational number $x = \frac mn$ by
  \[
    \left| x \right|_p =
    \begin{cases}
      0 & \text{if } m=0 \ ,\\
      p^{-\nu_p(m) +\nu_p(n)} & \text{else}\ .
    \end{cases}
  \]
  Note that $ \left| x \right|_p$ does not depend on the particular representation of $x$ as the quotient of integers $m$ and $n$.
  By definition it is immediately clear that the $p$-adic absolute value is an absolute value on $\Q$ indeed.
  It is non-archimedean.
\end{environmentlist}
\end{examples}

\begin{proposition}
  A valued division ring $(R,|\cdot|)$ is non-archimedean if and only if the image of $\Z$ under
  the canonical map  $\Z\to R$ is bounded.
\end{proposition}

\begin{proof}
  Assume that $(R,|\cdot|)$ is a non-archimedean valued division ring.
  Then, $|0 \cdot 1| = |0|= 0 $ and, under the assumption that $|(n-1)\cdot 1|\leq 1$ for some $n\in \gzN$,
  $|n\cdot 1| = | (n-1)\cdot 1 + 1 | = \max \{ |(n-1)\cdot 1| , 1 \} = 1$.
  Hence by induction and since $|-1| =1$ one obtains that $|n\cdot 1|\leq 1$ for all $n\in \Z$,
  and the image of $\Z$ in $R$ is bounded.

  To show the converse assume that the image of $\Z$ in $R$ is bounded by some constant $C>0$. Then, for all $x,y\in R$
  and $n\in \gzN$ by the binomial formula and the triangle inequality
  \[
    |x+y|^n =\left|\sum_{k=0}^n {n \choose k} x^k y^{n-k} \right|
    \leq (n+1) \,C \max \{|x|,|y|\}^n \ .
  \]
  Taking the $n$-th root gives $|x+y|\leq \big( (n+1)C\big)^{1/n} \max \{|x|,|y|\}$ which after passing to the limit $n\to\infty$
  entails  $|x+y| \leq \max \{|x|,|y|\}$ since $\lim\limits_{n\to\infty} \big( (n+1)C\big)^{1/n} = 1$. Hence
  $(R,|\cdot|)$ is non-archimedean.
\end{proof}

\begin{proposition}
  Let $|\cdot|$ be an absolute value on the division ring $R$. Then for every $\tau>0$ with $\tau\leq 1$ the
  map $|\cdot|^\tau: R\to\R_{\geq 0}$ is an absolute value on $R$ as well.
  It is archimedean if and only if $|\cdot|$ is archimedean.
\end{proposition}

\begin{proof}
  To prove that $|\cdot|^\tau$ is an absolute value it suffices to show that $(a+b)^\tau \leq a^\tau + b^\tau$
  for all $a,b\geq 0$. Without loss of generality we may assume $a \geq b>0$. By dividing through $b^\tau$
  one sees that the claim is equivalent to $(t +1 )^\tau \leq t^\tau + 1$ for all $t\geq 1$.
  For $t=1$ this is certainly true. The derivative of the function
  $h :\rightopenint{1,\infty} \to\R$, $t\mapsto (t +1 )^\tau - t^\tau$ now is
  given by $h'(t) = \tau \big( (t +1 )^{\tau-1} - t^{\tau-1} \big)$ which is negative
  since $\tau-1\leq 0$ and $1+ t > t\geq 1$. Hence $h$ is monotone decreasing
  and $(t +1 )^\tau - t^\tau \leq  1$ for all $t\geq 1$.

  Since $\openint{0,\infty} \to \R$, $t\mapsto t^\tau$ is strictly increasing  and unbounded,
  the image of $\Z$ in $R$ is unbounded with respect to    $|\cdot|$  if and only if
  it is with respect to $|\cdot|^\tau$.
\end{proof}

\para An absolute value $ |\cdot | : R \to \R_{\geq 0}$ on a division ring $R$ induces the metric
$d : R \times R \to \R_{\geq 0}$, $(x,y) \mapsto |x-y|$ which then gives
rise to a topology on $R$. This topology has the following properties:
\begin{axiomlist}[TDR]
  \item\label{axiom:topological-division-ring-continuity-addition}
     Addition $+ : R \times R \to R$ is continuous.
  \item\label{axiom:topological-division-ring-continuity-multiplication}
     Multiplication $\cdot : R \times R \to R$ is
     continuous.
  \item\label{axiom:topological-division-ring-continuity-inversion}
    Inversion $(\:\cdot\:)^{-1}:R^\times \to R^\times $ is continuous, where $R^\times$ denotes the
    set of units in $R$ i.e.~$R^\times = R \setminus \{ 0\}$.
\end{axiomlist}

\begin{proof}
   Addition is continuous since  for all $a,b,x,y \in R$ by the triangle inequality
   \[ d ( x + y , a+ b ) = | x + y -( a+ b)| \leq | x-a| + | y-b| = d(x,a) + d(y,b)\ .\]
   Actually, this even shows  that addition is Lipschitz continuous.
   Now fix $a,b \in R$ and let $C = \max \{ |a|,|b| \} + 1$. Then for all $x,y \in R$
   with $d(y,b) <  1$
   \[ d ( x \cdot y , a \cdot b ) = | (x \cdot y - a \cdot y) + (a \cdot y - a \cdot b)|
   \leq | x-a| \, |y|  + |a| \, | y-b| \leq C \big(  d(x,a) + d(y,b) \big) \ .\]
   Hence multiplication is continuous.
   Finally, fix $a \in R^\times$ and let $x \in R^\times $ with $d(x,a) <  \frac{|a|}{2}$. Then
   $|x| \geq |a| - d(x,a) > \frac{|a|}{2} >0$ and
   \[ d \left( x^{-1} , a^{-1} \right) =  \left|  x^{-1} - a^{-1} \right| = \left|  x^{-1} \cdot a^{-1} \right|
   \, | x-a | = \frac{1}{|x| \, |a|} d( x,a ) <  \frac{2}{|a|^2} d( x,a )  \ .\]
   So inversion is also continuous.
\end{proof}

\begin{definition}
 A division ring or field $R$ which is equipped with a topology so that
 \ref{axiom:topological-division-ring-continuity-addition},
 \ref{axiom:topological-division-ring-continuity-multiplication} and
 \ref{axiom:topological-division-ring-continuity-inversion} are satisfied is called a
 \emph{topological division ring} or a \emph{topological field}, respectively.
\end{definition}

\begin{lemma}\label{thm:zero-neighborhood-topological-division-ring-infinite}
  If $|\cdot|$ is a non-trivial absolute value on the division ring $R$, then there exists an element
  $t\in R^\times$ such that the sequence $(t^n)_{n\in\N}$ converges to $0$. Furthermore in this case
  every $0$-neighborhood in $R$ contains infinitely many elements.
\end{lemma}
\begin{proof}
  By non-triviality of $|\cdot|$ there exists $t\in R^\times$ such that $|t|\neq 1$. By possibly
  passing to $t^{-1}$ we can assume $|t|<1$. Since then $\lim\limits_{n\to\infty} |t|^n =0$,
  the sequence $(t^n)_{n\in\N}$ converges to $0$.  This implies in particular that
  for every $\varepsilon >0$ the open ball $\ball (0,\varepsilon) =\{t \in R \mid |t| < \varepsilon \}$
  contains infinitely many elements. So the lemma is proved.
\end{proof}

\begin{definition}
  Two absolute values $|\cdot|$ and $|\cdot|^\prime$ on a division ring $R$ are called \emph{equivalent}
  if they induce the same topology on $R$.
\end{definition}

\begin{theorem}
  Let $|\cdot|$ and $|\cdot|^\prime$ be two absolute values on the division ring $R$.
  Then they are equivalent if and only if there exists $e>0$ such that $|\cdot|^\prime =|\cdot|^\tau$.
  In particular the trivial absolute value is the only one inducing the discrete topology on $R$.
\end{theorem}

\begin{proof}
  Let us first show the following proposition.
  \begin{enumerate}[label={\textup{({\sffamily A})}},align=left,leftmargin=*]
  \item\label{ite:absolute-values-preserving-unit-balls}
    If $|\cdot|$ and $|\cdot|^\prime$ are equivalent, then  the relation $|x|< 1$ holds true for $x \in R^\times$
    if and only if $|x|^\prime< 1$.
  \end{enumerate}
  Since $\left| x^{-1}\right| =\frac{1}{|x|}$ and $\left| x^{-1}\right|^\prime =\frac{1}{|x|^\prime}$
  for all $x \in R^\times$, \ref{ite:absolute-values-preserving-unit-balls}
  implies that $|x|> 1$ if and only if $|x|^\prime> 1$ and that  $|x|= 1$ if and only if $|x|^\prime = 1$.
  To verify claim \ref{ite:absolute-values-preserving-unit-balls} assume now that $0 < |x|< 1$.
  Then  $\lim\limits_{n\to\infty}|x^n|=0$, hence $(x^n)_{n\in\N}$ converges to $0$. By assumption,
  $\lim\limits_{n\to\infty}|x^n|^\prime=0$ then holds as well which implies that $|x|^\prime<1$.
  By switching  $|\cdot|$ and $|\cdot|^\prime$  the converse holds true, so
  \ref{ite:absolute-values-preserving-unit-balls} is proved.

  Next we show that $|\cdot|$ is trivial  if and only if the induced topology on $R$ is discrete.
  Namely, if  $|\cdot|$ is non-trivial, then there exists $x\in R^\times$ such  that  $|x| \neq 1$. After
  possibly passing to $\frac 1x$ we can achieve that  $|x| < 1$. So $\lim\limits_{n\to\infty}|x^n|=0$, which
  means that $(x^n)_{n\in\N}$ is a sequence of non-zero elements of $R$ converging to $0$. But this implies that
  the singleton $\{ 0\}$ is not  open in the topology induced by $|\cdot|$, hence this topology is non-discrete.
  Since obviously the trivial absolute value induces the discrete topology on $R$ the second claim of the theorem is
  proved.

  Now assume that $|\cdot|^\prime =|\cdot|^\tau$ for some $\tau>0$. Then a subset $B \subset R$ is a metric
  open ball with respect to $|\cdot|$ if and only if it is one with respect to $|\cdot|^\prime$
  since for $x \in R$ and $\varepsilon >0$
  \begin{equation*}
  \begin{split}
    &\big\{ y \in R \bigmid |y -x| < \varepsilon \big\}  = \big\{ y \in R \bigmid |y-x|^\prime < \varepsilon^\tau \big\}
    \text{ and } \\
    &\big\{ y \in R \bigmid |y- x|^\prime < \varepsilon \big\}  = \big\{ y \in R \bigmid |y-x| < \varepsilon^{1/\tau} \big\} \ .
  \end{split}
  \end{equation*}
  Hence the open sets with respect to the metric defined by $|\cdot|$ coincide with those defined by $|\cdot|^\prime$ and
  the two absolute values  are equivalent.

  Let us finally show the other direction and assume that $|\cdot|$ and $|\cdot|^\prime$ are equivalent.
  By the already proven second claim of the theorem we can restrict to the case where the induced topology is non-discrete
  which means to the case where both  $|\cdot|$ and $|\cdot|^\prime$ are non-trivial.
  We show that there exists $\tau >0$ such that $|x|^\prime =  |x|^\tau $ for all $x\in R^\times$ with $ |x|> 1$.
  This is sufficient, since if $ |x|= 1$, then $|x|^\prime =  1 = |x|^\sigma $ for any $\sigma >0$
  by \ref{ite:absolute-values-preserving-unit-balls}, and since if $x\in R^\times$ with $ |x|< 1$ then
  $ |x^{-1}| > 1$ and
  \[
     |x|^\prime = \frac{1}{\left|x^{-1}\right|^\prime} = \frac{1}{\left|x^{-1}\right|^\tau} = |x|^\tau \ .
  \]
  The existence of a $\tau >0$ with the claimed property is equivalent to the function
  \[
       R^\times \to \R,\: x \mapsto \frac{\ln |x|^\prime}{\ln |x|}
  \]
  being constant. Assume that that is not the case. Then there exist $x,y \in R^\times$
  with $|x|,|y|>1$ such that
  $\frac{\ln |x|^\prime}{\ln |x|} \neq \frac{\ln |y|^\prime}{\ln |y|}$. By possibly switching $x$ and $y$ we
  can assume  $\frac{\ln |x|^\prime}{\ln |x|} < \frac{\ln |y|^\prime}{\ln |y|}$.
  But that implies $\frac{\ln |x|^\prime}{\ln |y|^\prime} < \frac{\ln |x|}{\ln |y|}$ since the logarithms are positive
  by assumptions on $x$ and $y$ and \ref{ite:absolute-values-preserving-unit-balls}. Hence there exists a
  rational number $\frac pq$ with $p,q \in \gzN$ such that
  \[
   \frac{\ln |x|^\prime}{\ln |y|^\prime} < \frac pq < \frac{\ln |x|}{\ln |y|} \ .
  \]
  Then $|x^q|^\prime <  |y^p|^\prime$ and $|y^p| <  |x^q|$ which entails
  \[
    \left| \frac{x^q}{y^p} \right|^\prime < 1 \text{ and }
    \left| \frac{x^q}{y^p} \right| > 1 \ .
  \]
  This contradicts \ref{ite:absolute-values-preserving-unit-balls} and the theorem is proved.
\end{proof}

\begin{remarks}
  \begin{environmentlist}
  \item
    By  Ostrowski's theorem \cite[p.~276]{OstLF}, see also \cite[Thm.~3.1.3]{GouAN}, every non-trivial absolute value
    on the field $\Q$ of rational numbers is either equivalent to the standard absolute value $|\cdot|_\infty$ or to a
    $p$-adic absolute value $|\cdot|_p$  for some prime number $p$. Observe that for different primes $p$ and $q$ the
    absolute values $|\cdot|_p$ and $|\cdot|_q$ are not equivalent.
  \item
    Another theorem of Ostrowski \cite[p.~284]{OstLF}, sometimes called big Ostrowski's theorem, tells that for every archimedean
    valued field $(\fldK,|\cdot|)$ there exists an embedding $\iota :\fldK \hookrightarrow \C$ into the field of complex numbers
    with its standard absolute value and a positive real number $\tau\leq 1$ such that
    \[
         |x| =|\iota(x) |_\infty^\tau \quad \text{for all } x \in \fldK \ .
    \]
    In particular this means that every complete archimedean valued field is isomorphic to either $(\R,|\cdot|_\infty^\tau)$ or
    $(\C,|\cdot|_\infty^\tau)$ for some positive $\tau\leq 1$.
  \item
    The $p$-adic absolute values on $\Q$  have extensions to $\R$ by \cite[XII, \S4, Thm.~4.1]{LanA3rd}.
    This is a highly non-obvious result. To prove it one has to check first that $|\cdot|_p$ can be extended to an absolute
    value $|\cdot|$ on the field $\fldk$ of real numbers algebraic over $\Q$. This extended absolute value is,
    and that turns out to be crucial, again non-archimedean.
    Now one observes that $|\cdot|$ can be extended to the polynomial ring $\fldk [X]$ by the \emph{Gau{\ss} norm}
    $|p(X)| = \max_{0\leq i \leq n} \{a_i\}$ where $p(X)= a_n X^n + \ldots + a_1 X + a_0 \in\fldk [X]$.
    The Gau{\ss} norm obviously extends to an absolute value on the fraction field $\fldk(X)$.
    Again, this extension is non-archimedean.
    Now one recalls that $\R$ is a purely transcendental field extension of $\fldk$ and uses a transfinite induction type
    argument involving the just constructed  Gau{\ss} norm to extend $|\cdot|$ from $\fldK$ to $\R$.
    The thus obtained extension of the $p$-adic absolute value to $\R$ is not unique. In its construction, the
    axiom of choice is used, so one can not even give an explicit formula for such an extension.
  \end{environmentlist}
\end{remarks}