%by Maarten Burger, Alexander Apers, and Jos Zuiderwijk
\chapter{Chapter 11. Soundness and Completeness}

\section*{11.7.1 Part A --- Doing}

In the following, I give both full, detailed answers to the questions
and an indication of the expectations I have for a good answer. Note
that my way of answering is very detailed and there might be many
different, equally valid ways of writing up the same result. Note that
the correctness of the answer is always a factor but by far not the
only one. If, as in 11.7.3, the correctness of the answer is one out
of 4 elements of a correct answer, just writing down the correct
answer can give at most 1/4th of the points.

Keep in mind that since this is your first formal course, I give you a
lot of leeway when it comes to precise, mathematical formulations, but
the elements of a good answer should always be there to get decent
points.

\begin{itemize}

\item[11.7.1.1] \emph{Long answer}: In order to determine all variable and
  quantifier occurrences, we first construct the stripped parsing
  tree for the formula:
  \begin{center}
    \Tree [.{$\forall x$}
             [.{$\exists y$}
                [.{$\to$}
                 [.{$R$}
                   [.{$x$} ]
                   [.{$y$} ]
                 ]
                 [.{$\forall x$}
                    [.{$\land$}
                         [.{$P$} [.$x$ ] ]
                         [.{$\exists y$} [.{$R$} [.$x$ ] [.$y$ ] ] ]
                    ]
                 ]
                ]
             ]
             ]
  \end{center}
  The following table contains the information which variable
  occurrence is bound by which quantifier occurrence:
    \begin{longtable}{c | c}
      Variable occurrence      & Quantifier occurrence that binds it\\\hline
      $((r,1,1,1,1), x)$       & $(r, \forall x)$\\
      $((r,1,1,1,2), y)$       & $((r,1), \exists y)$\\
      $((r,1,1,2,1,1,1), x)$   & $((r,1,1,2), \forall x)$\\
      $((r,1,1,2,1,2,1,1), x)$ & $((r,1,1,2), \forall x)$\\
      $((r,1,1,2,1,2,1,2), y)$ & $((r,1,1,2,1,2), \exists y)$
    \end{longtable}

    \emph{Elements of a good answer}:

    \begin{itemize}
    \item Proper naming of the occurrences.
    \item Clear statement which variable occurrence is bound by which
      quantifier occurrence.
    \item Correct answer.
    \item Fully formulated sentences.
    \end{itemize}

  \item[11.7.1.2] \emph{Full answer}:
    \begin{enumerate}
    \item $\forall x(V(x)\to L(x))$
    \item $\neg \forall x(L(x)\to \forall y(\neg L(y)\to I(x,y)))$
    \item $L(x)\land \neg V(x)\land \neg D(x)$
    \item $\exists x(\neg L(x)\land \neg D(x))$
    \end{enumerate}

    \emph{Elements of a good answer}:

    \begin{itemize}
    \item Formalizations are indeed formulas.
    \item Adequate formalizations.
    \item Recognizes $V(x)\to L(x)$ as the best formalization of ``only
      if''
    \item Recognizes ``he'' as an indefinite pronoun, i.e. free
      variable.
      \item Recognizes the subordinate clause indicated by the commas
        in (iv) to indicate an existential quantifier.
    \end{itemize}

   \item[11.7.1.3] \emph{Long answer}: We are asked to determine the value of $\llbracket
     (0+x)\cdot S(0)\rrbracket^\mathcal{M}_\alpha$ for the given model
     and assignment. Applying the recursive definition of the
     denotation of a term in a model under an assignment, we get the
     following calculation:
     \begin{align*}
       \llbracket (0+x)\cdot
       S(0)\rrbracket^\mathcal{M}_\alpha&=\llbracket
                                          0+x\rrbracket^\mathcal{M}_\alpha\cdot^\mathcal{M}
                                          \llbracket
                                          S(0)\rrbracket^\mathcal{M}_\alpha
       \\
       &=(\llbracket
         0\rrbracket^\mathcal{M}_\alpha+^\mathcal{M}\llbracket
         x\rrbracket^\mathcal{M}_\alpha)\cdot^\mathcal{M}
         S^\mathcal{M}(\llbracket 0\rrbracket^\mathcal{M}_\alpha)\\
                                        &=(0^\mathcal{M}+^\mathcal{M}\alpha(x))\cdot^\mathcal{M}S^\mathcal{M}(0^\mathcal{M})\\
                                        &=(1 +^\mathcal{M}3)\cdot ^\mathcal{M}S^\mathcal{M}(1)\\
                                        &= 5\cdot 3\\
                                        &=15
     \end{align*}

     \emph{Elements of a good answer}:

     \begin{itemize}
     \item Explains what's being done.
     \item Applies the recursive clauses in sufficient detail.
     \item Applies the functions from the model correctly.
     \item Gets the correct result.
     \end{itemize}

  \item[11.7.1.4] \emph{(Very) Long Answer}: We claim that
    $\mathcal{M},\alpha\vDash \forall x\forall y(R(x,y)\to R(f(y), f(x)))$.
    In order to determine what we need to show is, we observe the following
    \begin{itemize}
      \item[] $\mathcal{M},\alpha\vDash \forall
        x\forall y(R(x,y)\to R(f(y), f(x)))$
      \item[\emph{iff}] for all $d\in D^\mathcal{M}$,
        $\mathcal{M},\alpha[x\mapsto d]\vDash \forall y(R(x,y)\to
        R(f(y), f(x)))$
      \item[\emph{iff}] for all $d,d'\in D^\mathcal{M}$,
        $\mathcal{M},\alpha[x\mapsto d, y\mapsto d']\vDash R(x,y)\to
        R(f(y), f(x))$
    \end{itemize}
    Since there are only 2 elements in $D^\mathcal{M}=\{1,2\}$,
    there are 4 possible choices for $d$ and $d'$ to consider:
    \begin{itemize}
      \item $d=1, d'=1$
      \item $d=1, d'=2$
      \item $d=2, d'=1$
      \item $d=2, d'=2$
    \end{itemize}
    Since for all choices of $d$ and $d'$ other than $d=1, d'=2$, we
    have that $\mathcal{M},\alpha[x\mapsto d, y\mapsto d']\nvDash
    R(x,y)$, so we don't have to check anything else to see that $\mathcal{M},\alpha[x\mapsto d, y\mapsto d']\vDash R(x,y)\to
    R(f(y), f(x))$.

    For $d=1, d'=2$, we observe that:\[\llbracket
    f(x)\rrbracket^\mathcal{M}_{\alpha[x\mapsto d, y\mapsto
    d']}=f^\mathcal{M}(1)=2\]\[\llbracket
    f(y)\rrbracket^\mathcal{M}_{\alpha[x\mapsto d, y\mapsto
    d']}=f^\mathcal{M}(2)=1.\]
    But then, we have
    $\mathcal{M}, \alpha[x\mapsto d, y\mapsto d']\vDash R(f(y), f(x))$
    and so
    $\mathcal{M},\alpha[x\mapsto d, y\mapsto d']\vDash R(x,y)\to R(f(y), f(x))$.

      So, for each choice of $d,d'\in D^\mathcal{M}$, we have \[\mathcal{M},\alpha[x\mapsto d, y\mapsto d']\vDash R(x,y)\to
      R(f(y), f(x))\] and so \[\mathcal{M},\alpha\vDash \forall
      x\forall y(R(x,y)\to R(f(y), f(x)),\] as desired.

    \emph{Elements of a good answer}:

    \begin{itemize}
    \item Applies the clause for the universal quantifier.
    \item Considers all the values for the variables.
    \item Notices that the only interesting case is when the value of
      $x$ is 1 and the value of $y$ 2.
    \item Gives the correct answer.
    \item Explains reasoning.
    \item Is written in full, comprehensible sentences.
    \end{itemize}

  \item[11.7.1.5]

    \begin{enumerate}

      \item%
        By definition,
        $\exists x(P(x)\land x=c),\forall x(P(x)\to Q(x))\vdash  Q(c)$
        iff the tableau for
        $\{ \exists x(P(x)\land x=c),\forall x(P(x)\to Q(x)),\neg Q(c)\}$
        is closed.
        Here is the tableau:

        \begin{center}
          \begin{prooftree}
            {%
              line numbering=false,
              for tree={s sep'=10mm},
              single branches=true,
              close with=\xmark
            }
            [{\exists x(P(x)\land x=c)}, grouped
                [{\forall x(P(x)\to Q(x))}, grouped
                    [{\neg Q(c)}, grouped
                        [{P(p)\land p=c}
                            [{P(p)}
                                [{p=c}
                                    [{P(p)\to Q(p)}
                                        [{\neg P(p)}, close ]
                                        [{Q(p)}
                                            [{\neg Q(p)}, close]
                                        ]
                                    ]
                                ]
                            ]
                        ]
                    ]
                ]
            ]
          \end{prooftree}
        \end{center}
        Since the tableau is closed,
        we can infer the conclusion from the premises as claimed.

        \emph{Elements of a good answer}:
        \begin{itemize}
          \item%
            Explains why the tableau is done.
          \item%
            Makes a tableau for
            $\Gamma\cup\{\neg\phi\}$
            not for $\Gamma\cup\{\phi\}$.
          \item%
            Applies all rules correctly.
          \item%
            Recognizes the correct application of the identity rule to close the second branch.
          \item%
            Gets the correct answer.
        \end{itemize}

\item By definition, $P(c)\lor (P(c)\land Q(c)), \forall x(Q(x)\to
  \neg P(c))\vdash \neg P(c)$ iff the tableau for $\{P(c)\lor (P(c)\land Q(c)), \forall x(Q(x)\to
  \neg P(c)), \neg\neg P(c)\}$ is closed. Here is the tableau:

  \begin{center}
  \begin{prooftree}
{
line numbering=false,
for tree={s sep'=10mm},
single branches=true,
close with=\xmark
}
[{P(c)\lor (P(c)\land Q(c))}, grouped
     [{\forall x(Q(x)\to \neg
  P(x)}, grouped
          [{\neg\neg P(c)}, grouped
                 [{P(c)}
                     [{P(c)}
                          [{Q(c)\to \neg P(c)}
                               [{\neg Q(c)}]
                               [{\neg P(c)}, close]
                          ]
                     ]
                     [{P(c)\land Q(c)}
                          [{P(c)}
                              [{Q(c)}
                                   [{Q(c)\to \neg P(c)}
                                     [{\neg Q(c)}, close]
                                     [{\neg P(c)}, close]
                                   ]
                              ]
                         ]
                     ]
                 ]
          ]
     ]
]
\end{prooftree}
\end{center}
Since the tableau is open, we cannot infer the conclusion from the
premises, as claimed. The associated model of the only open branch is
given by the following specification:
\begin{itemize}
   \item $D^\mathcal{M}=\{c\}$
   \item $c^\mathcal{M}=c$
   \item $P^\mathcal{M}=\{c\}$
   \item $Q^\mathcal{M}=\emptyset$
   \end{itemize}

   \emph{Elements of a good answer}:

   \begin{itemize}
   \item  Explains why the tableau is done.
  \item Makes a tableau for $\Gamma\cup\{\neg\phi\}$ not for
    $\Gamma\cup\{\phi\}$.
  \item Applies all rules correctly.
    \item Makes a complete tableau (i.e. applies \emph{all} possible
      rules).
  \item Gets the correct tableau.
   \item Specifies the associated model completely (including the
     interpretation of $c$ and $Q$).
    \item Gets the correct model.
   \end{itemize}

    \end{enumerate}

    \item[11.7.1.6] \emph{Long answer}: We're asked to determine whether
      the following
      inference is valid:
      \begin{itemize}
      \item The ball is round, and everything round comes from
        Mars. So, the ball comes from Mars.
      \end{itemize}
      In order to determine the validity of the argument, we first
      formalize it. We make use of the following translation key:
      \begin{center}
        \begin{tabular}[!h]{c c c}
          $b$   & : & the ball\\
          $R^1$ & : & \dots is round\\
          $M^1$ & : & \dots comes from Mars
        \end{tabular}
      \end{center}
      We obtain \[R(b), \forall x(R(x)\to M(x))\therefore M(b)\]

      I claim that this inference is valid, i.e. \[R(b), \forall
        x(R(x)\to M(x))\vDash M(b)\]

      In order to show that I'm making use of the tableau method. We
      know that $R(b), \forall
        x(R(x)\to M(x))\vdash M(b)$ iff the tableau for $\{R(b), \forall
        x(R(x)\to M(x)),\neg  M(b)\}$ is closed. Here is that tableau:

        \begin{center}
  \begin{prooftree}
{
line numbering=false,
for tree={s sep'=10mm},
single branches=true,
close with=\xmark
}
[{R(b)}, grouped
[{\forall x(R(x)\to M(x))}, grouped
[\neg M(b), grouped
[{R(b)\to M(b)}
    [{\neg R(b)}, close]
    [{M(b)}, close]
]
]
]
]
\end{prooftree}
\end{center}
Since the tableau is closed, we can infer that \[R(b), \forall
        x(R(x)\to M(x))\vdash M(b).\] By the soundness theorem, our
        claim that \[R(b), \forall
        x(R(x)\to M(x))\vDash M(b)\] follows from this.

        We have now shown that the formal inference \[R(b), \forall
        x(R(x)\to M(x))\therefore M(b)\] is valid. Since this formal
        inference is a formalization of the natural language inference
        we started with, we can infer that the natural language
        inference is valid, too.

        \emph{Elements of a good answer}:

        \begin{itemize}
        \item Explains what is done.
        \item Formalizes the inference.
        \item Gets a decent formalization.
        \item Checks whether the inferences entail the conclusion with
          a suitable method (tableau or semantics).
        \item Applies that method correctly.
        \item Transfers the results back to the natural language
          inference.
        \item Gets the correct result.
        \end{itemize}

\end{itemize}

\section*{11.7.2 Part B --- Proving}

      Below, I provide a proof for each of the claimed
      theorems. Please keep in mind that, as I said in the last
      lecture, if a mathematical claim is provable, then there is
      always more than one proof of it. This means, the proofs I
      provide are not the only possible proofs. The merit of the answers I formulate below is that they might give you a better
      idea of what I expect a good answer to look like. Also keep in
      mind that my answer are always as explicit as possible, and I
      don't necessarily expect the same level of attention to detail
      from you.

      The
      \emph{elements of a good answer} are the same in every case:
      \begin{itemize}
      \item Recognizes correctly what needs to be shown.
      \item Explains each reasoning step, doesn't have gaps in the
        argumentation.
      \item Uses correct reasoning, doesn't commit fallacies.
      \item Applies the definitions correctly.
      \item Is written in full, grammatical English/Dutch sentences.
      \item Obtains the correct result.
      \end{itemize}

      Here is a (non-exhaustive) list of marking categories that we
      use:
      \begin{longtable}{c | l}
		Abbreviation & Mistake \\
		\hline
		\lightning & Error/mistake (generic)\\
		Df. & Incorrect or imprecise definition \\
		Q\textbf{?} & Question not read correctly\\
		$\not\Rightarrow$ & Non-sequitur, reasoning mistake\\
		$\neq$ & Calculation mistake \\
		$\qedsymbol$? & QED missing, reasoning incomplete\\
		\textbf{x}? & Undeclared variables\\
		$\Rightarrow$\textbf{?} & Right-to-left direction missing \\
		$\Leftarrow$\textbf{?} & Left-to-right direction missing \\
		$\underline{\lor}$ & Distinction by cases not exhaustive\\
		$abc$ & Write complete sentences.\\
		{[squiggles]} & No (unexplained)  paintings!
		\end{longtable}

        \begin{itemize}
                \item[11.7.2.1] We're asked to show that if $\phi$ is an
                  open formula with $y$ as its only free variable,
                  then $\forall x\phi$ is also an open formula
                  (i.e. not a sentence). We
                  show this claim by showing that for every free
                  occurrence of $y$ in $\phi$ there will be a
                  corresponding free occurrence of $y$ in $\forall
                  x\phi$. Since there are free occurrences of $y$ in
                  $\phi$, from this the claim follows.

                  So, consider a free occurrence of $y$ in
                  $\phi$. Clearly, there is a corresponding occurrence
                  of $y$ in $\forall x\phi$. What remains
                  to be shown is that the occurrence is free. Suppose,
                  for indirect proof, that it's not. This would mean
                  that there's a quantifier occurrence of the form
                  $Qy$ in $\forall x\phi$, which binds the occurrence
                  of $y$. That quantifier occurrence cannot have a
                  corresponding occurrence in $\phi$, because then the
                  occurrence of $y$ in $\phi$ would be bound, contrary
                  to our assumption. But the only quantifier
                  occurrence that's in $\forall x\phi$ without a
                  corresponding occurrence in $\phi$ is $(r,\forall
                  x)$. But this occurrence cannot bind any occurrence
                  of $y$ since $x\neq y$. Hence, $y$ needs to be free
                  in $\forall y\phi$, as desired.%$

                  \emph{Alternative strategy (way more complicated)}:
                  Using induction on formulas.

                  \item[11.7.2.2] We're asked to show that for all $\Gamma$, we
                    have $\Gamma\vdash P(c)\lor \neg P(c)$. We know,
                    by definition, that this is the case iff the
                    tableau for $\Gamma\cup\{\neg (P(c)\lor \neg
                    P(c))\}$ is closed. But we can infer that this
                    tableau is closed even without knowing what the
                    members of $\Gamma$ are. To see this, note that
                    the initial list consists in $\Gamma\cup\{\neg (P(c)\lor \neg
                    P(c))\}$, so we can always close the tableau as follows:
                    \begin{center}
  \begin{prooftree}
{
line numbering=false,
for tree={s sep'=10mm},
single branches=true,
close with=\xmark
}
[{\Gamma}, grouped
[{\neg (P(c)\lor\neg P(c)}, grouped
[{\neg P(c)}
[{\neg\neg P(c)}
[{P(c)}, close
]
]
]
]
]
\end{prooftree}
\end{center}
Hence the tableau is always closed, which is what we needed to show.

            \emph{Alternative strategy}: Semantically show that
                $\Gamma\vDash P(c)\lor\neg P(c)$ and then use
                completeness to infer the result.

          \item[11.7.2.3] We aim to show that
            $\forall x(\phi\to\psi)\vDash\neg \exists x(\phi\land
            \neg\psi)$.
            By definition, we know that
            $\forall x(\phi\to\psi)\vDash\neg \exists x(\phi\land \neg\psi)$
            iff for all models $\mathcal{M}$,
            we have that if
            $\mathcal{M},\alpha\vDash \forall x(\phi\to\psi)$, then
            $\mathcal{M},\alpha\vDash\neg \exists x(\phi\land\neg\psi)$
            (for some arbitrary assignment $\alpha$).
            So, let $\mathcal{M}$ be an
            arbitrary model and suppose that
            $\mathcal{M},\alpha\vDash\forall x(\phi\to\psi)$.
            This means, by definition, that for all
            $d\in D^\mathcal{M}$ we have
            $\mathcal{M},\alpha[x\mapsto d]\vDash
            \phi\to\psi$.
            From this, we need to derive that
            $\mathcal{M},\alpha\vDash\neg \exists x
            (\phi\land\neg\psi)$.
            We do this indirectly.
            Suppose
            that $\mathcal{M},\alpha\nvDash\neg \exists x
            (\phi\land\neg\psi)$.
            It follows that  $\mathcal{M},\alpha\vDash \exists x
            (\phi\land\neg\psi)$.
            This means, by definition,
            that there must be a $d\in D^\mathcal{M}$ such that
            $\mathcal{M},\alpha[x\mapsto d]\vDash
            \phi\land\neg\psi$.
            From this it would follow
            that $\mathcal{M},\alpha[x\mapsto d]\vDash
            \phi$ and $\mathcal{M},\alpha[x\mapsto
            d]\nvDash\psi$, and so $\mathcal{M},\alpha[x\mapsto d]\nvDash
            \phi\to\psi$.
            But this would contradict our
            assumption that  $\mathcal{M},\alpha[x\mapsto d]\vDash
            \phi\to\psi$ for all $d\in D^\mathcal{M}$.
            So, by
            indirect proof, we can infer that  $\mathcal{M},\alpha\vDash\neg
            \exists x(\phi\land\neg\psi)$, as desired.

                  \item[11.7.2.4] We want to find a model
                    $\mathcal{M}^+$ that makes
                    $\forall x\exists yR(x,y)$ true and a model
                    $\mathcal{M}^-$ that makes the formula
                    false. There are different ways in which
                    we can achieve this, for example via tableau. You
                    know how that works, so I provide an answer that
                    I found by thinking about what needs to be the
                    case for the formula to be true/false

                    First, consider the model $\mathcal{M}^+$ given by:
                    \begin{itemize}
                    \item $D^{\mathcal{M}^+}=\{\ast\}$
                    \item $R^{\mathcal{M}^+}=\{(\ast,\ast)\}$
                    \end{itemize}
                    I claim that we have $\mathcal{M}^+,\alpha\vDash
                    \forall x\exists yR(x,y)$. To see this, remember
                    that $\mathcal{M}^+,\alpha\vDash
                    \forall x\exists yR(x,y)$ iff for all
                    $d\in D^{\mathcal{M}^+}$, we have
                    $\mathcal{M}^+,\alpha[x\mapsto d]\vDash
                    \exists yR(x,y)$. And we have $\mathcal{M}^+,\alpha[x\mapsto d]\vDash
                    \exists yR(x,y)$ iff for some $d'\in
                    D^{\mathcal{M}^+}$, we have
                    $\mathcal{M}^+,\alpha[x\mapsto d, y\mapsto d']\vDash
                    R(x,y)$. So, we have that $\mathcal{M}^+,\alpha\vDash
                    \forall x\exists yR(x,y)$ iff for all $d\in
                    D^{\mathcal{M}^+}$ there exists a $d'\in
                    D^{\mathcal{M}^+}$ such that  $\mathcal{M}^+,\alpha[x\mapsto d, y\mapsto d']\vDash
                    R(x,y)$. But there is only one element in
                    $D^{\mathcal{M}^+}$, namely $\ast$. And for
                    $d=\ast$, we can easily find a $d'$ such that $\mathcal{M}^+,\alpha[x\mapsto d, y\mapsto d']\vDash
                    R(x,y)$, namely $d'=\ast$. To see this, just note
                    that $\mathcal{M}^+,\alpha[x\mapsto \ast, y\mapsto \ast]\vDash
                    R(x,y)$ since
                    $(\ast, \ast)\in R^\mathcal{M}$. So, $\mathcal{M}^+,\alpha\vDash
                    \forall x\exists yR(x,y)$, as desired.

                    Now, consider the model $\mathcal{M}^-$ given by:
                    \begin{itemize}
                    \item $D^{\mathcal{M}^+}=\{\ast\}$
                    \item $R^{\mathcal{M}^+}=\emptyset$
                    \end{itemize}
                   As in the case of $\mathcal{M}^+$, we can infer
                   that $\mathcal{M}^-,\alpha\vDash
                    \forall x\exists yR(x,y)$ iff for all $d\in
                    D^{\mathcal{M}^-}$ there exists a $d'\in
                    D^{\mathcal{M}^-}$ such that  $\mathcal{M}^-,\alpha[x\mapsto d, y\mapsto d']\vDash
                    R(x,y)$. Again, there is only one element in
                    $D^{\mathcal{M}^-}$, namely $\ast$. But for
                    $d=\ast$, there exists no $d'$ such that $\mathcal{M}^-,\alpha[x\mapsto d, y\mapsto d']\vDash
                    R(x,y)$. For the only possible $d'$ would $\ast$
                    itself and we have $\mathcal{M}^-,\alpha[x\mapsto \ast, y\mapsto \ast]\nvDash
                    R(x,y)$ since $R^{\mathcal{M}-}=\emptyset$. So  $\mathcal{M}^-,\alpha\nvDash
                    \forall x\exists yR(x,y)$, as desired.

                    \item[11.7.2.5]We need to show that if $\Gamma\vDash
                      c\neq c$, then $\Gamma$ is unsatisfiable. By
                      definition $\Gamma$ is satisfiable iff there is
                      a model $\mathcal{M}$ and assignment $\alpha$
                      such that $\mathcal{M},\alpha\vDash \phi$ for
                      all $\phi\in\Gamma$. So, assume that $\Gamma\vDash
                      c\neq c$. We derive that $\Gamma$ is
                      unsatisfiable using indirect proof. So suppose
                      that $\Gamma$ is satisfiable, that is there is
                      a model $\mathcal{M}$ and assignment $\alpha$
                      such that $\mathcal{M},\alpha\vDash \phi$ for
                      all $\phi\in\Gamma$. Since $\mathcal{M},\alpha\vDash \phi$ for
                      all $\phi\in\Gamma$ and $\Gamma\vDash c\neq c$,
                      it follows that $\mathcal{M},\alpha\vDash c\neq
                      c$. But that would entail that
                      $c^\mathcal{M}\neq c^\mathcal{M}$, which is
                      impossible. So, there is no such $\mathcal{M}$
                      and $\alpha$ and $\Gamma$ is therefore unsatisfiable.

                  \item[11.7.2.6] We're asked to prove that for all
                    terms $s$ and $t$ we have, in the given model
                    $\mathcal{M}$ and under the given assignment
                    $\alpha$, that $\llbracket
                    s\rrbracket^\mathcal{M}_\alpha=\llbracket
                    t\rrbracket^\mathcal{M}_\alpha$. In order to prove
                    this fact, we show that for all $t$ we have $\llbracket
                    t\rrbracket^\mathcal{M}_\alpha=a^\mathcal{M}$. From
                    this, the claim follows immediately since then we
                    have: \[\llbracket
                    s\rrbracket^\mathcal{M}_\alpha=a^\mathcal{M}=\llbracket
                    t\rrbracket^\mathcal{M}_\alpha\]

                    So, we want to prove by induction that for all $t$ we have $\llbracket
                    t\rrbracket^\mathcal{M}_\alpha=a^\mathcal{M}$. We
                    have two base cases: (i) either $t$ is a constant
                    or (ii) $t$ a variable. If (i) $t$ is a constant, then
                    $t=a$, since $a$ is the only constant of
                    $\mathcal{S}$. And trivially, if $t=a$,  we have
                    $\llbracket t\rrbracket^\mathcal{M}=\llbracket
                    a\rrbracket^\mathcal{M}=a^\mathcal{M}$. If (ii)
                    $t$ is a variable $x\in \mathcal{V}$, then
                    $\llbracket t\rrbracket^\mathcal{M}=\llbracket
                    x\rrbracket^\mathcal{M}=\alpha(x)=a^\mathcal{M}$,
                    as desired.

                    For the induction step, assume the induction
                    hypothesis that $\llbracket
                    t\rrbracket^\mathcal{M}_\alpha=a^\mathcal{M}$. We
                    need to derive from this that $\llbracket
                    f(t)\rrbracket^\mathcal{M}_\alpha=a^\mathcal{M}$,
                    as well. To see this, we can reason as follows:
                    \[\llbracket
                    f(t)\rrbracket^\mathcal{M}_\alpha=f^\mathcal{M}(\llbracket
                    t\rrbracket^\mathcal{M}_\alpha)=f^\mathcal{M}(a^\mathcal{M})=a^\mathcal{M}\]

                  So, using the principle of induction on terms, we
                  have seen that  $\llbracket
                    t\rrbracket^\mathcal{M}_\alpha=a^\mathcal{M}$ for
                    all terms $t$, from which our main claim follows
                    as explained before.

                  \item[11.7.2.7] We're asked to prove by induction that
                    if $\phi$ is an open formula with $x$ as its only
                    free variable, then $(\phi)[x:=c]$ where $c$ is a
                    constant is a closed formula, i.e. a sentence.

                    For the base case, we need to consider two
                    situations: (i) $\phi$ is of the form $R(t_1,
                    \mathellipsis, x, \mathellipsis, t_n)$ where the
                    $t_i$ are ground terms or (ii)
                    $\phi$ is of the form $t=x$ or $x=t$ where $t$ is
                    a ground term. In case (i),
                    we simply observe that since each $t_i$ is a
                    ground term and thus doesn't contain $x$, we have $(R(t_1,
                    \mathellipsis, x, \mathellipsis,
                    t_n))[x:=c]=R(t_1, \mathellipsis, c,\mathellipsis,
                    t_n)$. Since all of the $t_i$'s are ground-terms
                    and $c$ is a constant, there is no free variable
                    in this formula and the claim holds. In case (ii),
                    we only consider the situation where $\phi$ is of
                    the form $t=x$ since $x=t$ is completely
                    analogous. We simply note that  since $t$ is a
                    ground term and thus doesn't contain $x$, we have
                    $(t=x)[x:=c]=t=c$. And since, again, $t$ is a
                    ground term and $c$ a constant, $t=c$ contains no
                    variables at all and is thus closed.

                    We go through the induction steps one by one:

                    \begin{itemize}
                    \item Assume the induction hypothesis that if
                      $\phi$ has only $x$ free, then $(\phi)[x:=c]$ is a
                    sentence. We need to derive that then also if
                    $\neg\phi$ contains only $x$ free, then
                    $(\neg\phi)[x:=c]$ is a sentence. But suppose that
                    $\neg\phi$ contains only $x$ free. We have by
                    definition that $(\neg\phi)[x:=c]=\neg
                    (\phi)[x:=c]$. And since if $\neg \phi$ contains
                    only $x$ free, then also $\phi$ can only contain
                    $x$ free. Hence $(\phi)[x:=c]$ is a sentence by
                    the induction hypothesis and so $\neg(\phi)[x:=c]$
                    is also sentence.

                    \item Assume the induction hypotheses that (a) if
                      $\phi$ has only $x$ free, then $(\phi)[x:=c]$ is a
                    sentence and that (b) if
                      $\psi$ has only $x$ free, then $(\psi)[x:=c]$ is a
                    sentence. Now consider $\phi\circ\psi$ with only
                    $x$ free for
                    $\circ=\land,\lor,\to,\leftrightarrow$. We know that
                    $(\phi\circ\psi)[x:=c]=(\phi)[x:=c]\circ
                    (\psi)[x:=c]$ by definition. Now if
                    $\phi\circ\psi$ has only $x$ free, each of $\phi$
                    and $\psi$ can only have $x$ free. So, by the
                    induction hypotheses (a) and (b), we have that
                    $(\phi)[x:=c]$ and $(\psi)[x:=c]$ are both
                    sentences. But if $(\phi)[x:=c]$ and
                    $(\psi)[x:=c]$, then
                    $(\phi)[x:=c]\circ(\psi)[x:=c]$ is a sentence,
                    too, as desired.

                    \item Assume the induction hypothesis that if
                      $\phi$ has only $x$ free, then $(\phi)[x:=c]$ is a
                    sentence. Consider $Qy\phi$ with only $x$ free for
                    $Q=\forall,\exists$. Note that if $Qy\phi$
                    contains $x$ free, then we need to have that
                    $y\neq x$. For in $Qx\phi$, every occurrence of
                    $x$ would be bound by $(r,Qx)$. But if $y\neq x$,
                    then we know that
                    $(Qy\phi)[x:=c]=Qy(\phi)[x:=c]$. And since
                    $(\phi)[x:=c]$ is a sentence by the induction
                    hypothesis, so is $Qy(\phi)[x:=c]$.
                    \end{itemize}
                    This completes our proof, we can now infer by the
                    principle of induction over formulas that for all
                    $\phi$ with only $x$ free, $(\phi)[x:=c]$ is a
                    sentence.

          \item[11.7.2.8] We're essentially asked to show that for all
            models $\mathcal{M}$ and assignments $\alpha$,
            we have
            $\mathcal{M},\alpha\vDash \forall xR(x,x)$ iff
            $(d,d)\in R^\mathcal{M}$ for all $d\in
            D^\mathcal{M}$. That is, we need to show two
            things:

            \begin{enumerate}[(a)]
              \item If  $\mathcal{M},\alpha\vDash \forall
                xR(x,x)$, then
                $(d,d)\in R^\mathcal{M}$ for all $d\in
                D^\mathcal{M}$
              \item If
                $(d,d)\in R^\mathcal{M}$ for all $d\in
                D^\mathcal{M}$, then  $\mathcal{M},\alpha\vDash \forall
                xR(x,x)$.
            \end{enumerate}

            To see that (a) holds, assume that
            $\mathcal{M},\alpha\vDash \forall
            xR(x,x)$. This means, by definition, that
            $\mathcal{M},\alpha[x\mapsto d]\vDash
            R(x,x)$. We derive that  $(d,d)\in R^\mathcal{M}$ for all $d\in
            D^\mathcal{M}$ by contradiction. Suppose that
            there exists a $d\in D^\mathcal{M}$ such that
            $(d,d)\notin R^\mathcal{M}$. But then, we'd have
            that $\mathcal{M},\alpha[x\mapsto d]\nvDash
            R(x,x)$, contrary to our assumption that for
            \emph{all} $d\in
            D^\mathcal{M}$, we have $\mathcal{M},\alpha[x\mapsto d]\vDash
            R(x,x)$. Hence $(d,d)\in R^\mathcal{M}$ for all $d\in
            D^\mathcal{M}$, as desired.

            To see that (b) holds assume that $(d,d)\in R^\mathcal{M}$ for all $d\in
            D^\mathcal{M}$. We need to derive that  $\mathcal{M},\alpha\vDash \forall
            xR(x,x)$, i.e. for all $d\in D^\mathcal{M}$ we have
            $\mathcal{M},\alpha[x\mapsto d]\vDash
            R(x,x)$. But this follows immediately since  $\mathcal{M},\alpha[x\mapsto d]\vDash
            R(x,x)$ iff $(\llbracket
            x\rrbracket^\mathcal{M}_{\alpha[x\mapsto
            d]},\llbracket
            x\rrbracket^\mathcal{M}_{\alpha[x\mapsto
            d]})=(d,d)\in R^\mathcal{M}$.

                        \item[11.7.2.9]We're asked to show that in the
                          given model $\mathcal{M}$ we have
                          \[\mathcal{M},\alpha\vDash \exists xP(x)\to
                          P(a)\lor P(b)\lor P(c)\] for each
                          $\alpha$. We know that, by definition, $\mathcal{M},\alpha\vDash \exists xP(x)\to
                          P(a)\lor P(b)\lor P(c)$ iff either (i)
                          $\mathcal{M},\alpha\nvDash \exists xP(x)$ or (ii)
                          $\mathcal{M},\alpha\vDash
                          P(a)\lor P(b)\lor P(c)$. Now clearly, we
                          either have (a) $\mathcal{M},\alpha\vDash
                          \exists xP(x)$ or (b)
                          $\mathcal{M},\alpha\nvDash \exists xP(x)$ by
                          bivalence. In case (b), we can immediately
                          infer that $\mathcal{M},\alpha\vDash \exists xP(x)\to
                          P(a)\lor P(b)\lor P(c)$, so we focus on case
                          (a). Suppose that $\mathcal{M},\alpha\vDash
                          \exists xP(x)$. This means, by definition,
                          that there exists a $d\in D^\mathcal{M}$
                          such that $\mathcal{M},\alpha[x\mapsto d]\vDash
                           P(x)$. Now, since
                           $D^\mathcal{M}=\{1,2,3\}$, we can only have
                           $d=1,2,3$. If $d=1$, then, since
                           $a^\mathcal{M}=1$, we have that
                           $\mathcal{M},\alpha[x\mapsto \llbracket
                           a\rrbracket^\mathcal{M}_\alpha]\vDash
                           P(x)$. By the denotation lemma, this gives
                           us $\mathcal{M},\alpha\vDash
                           (P(x))[x:=a]$, i.e. $\mathcal{M},\alpha\vDash
                           P(a)$. But if $\mathcal{M},\alpha\vDash
                           P(a)$, then $\mathcal{M},\alpha\vDash
                           P(a)\lor P(b)\lor P(c)$ and so $\mathcal{M},\alpha\vDash \exists xP(x)\to
                          P(a)\lor P(b)\lor P(c)$ by (ii), as
                          desired. If $d=2,3$, we can give the same,
                          analogous argument using the denotation
                          lemma. So, either way,  $\mathcal{M},\alpha\vDash \exists xP(x)\to
                          P(a)\lor P(b)\lor P(c)$, as desired.

                          \item[11.7.2.10] We're asked to prove that if
                            $\phi\vdash\psi$ and $\psi\vdash\phi$,
                            then $\phi\vdash\psi$. There are many
                            different ways we could do this, but I'll
                            use soundness and completeness. First,
                            I'll show my (Lemma) that  if
                            $\phi\vDash\psi$ and $\psi\vDash\phi$,
                            then $\phi\vDash\psi$.\footnote{We
                              actually proved this in class, so you
                              could, in principle just use this
                              without proof.} For suppose that
                            $\phi\vDash\psi$ and
                            $\psi\vDash\phi$. By definition, this
                            means that in every
                            model $\mathcal{M}$, (a) if $\mathcal{M}\vDash
                            \phi$, then $\mathcal{M}\vDash \psi$ and (b)
                            if $\mathcal{M}\vDash \psi$, then
                            $\mathcal{M}\vDash\theta$. I want to
                            derive $\phi\vDash\psi$, i.e. for every
                            model $\mathcal{M}$,
                            such that $\mathcal{M}\vDash\phi$, we also
                            have $\mathcal{M}\vDash\psi$. But if
                            $\mathcal{M}\vDash\phi$, then by (a)
                            $\mathcal{M}\vDash\psi$, and then by (b)
                            $\mathcal{M}\vDash\psi$, as desired. Now,
                            to prove our initial claim, suppose that
                            $\phi\vdash\psi$ and $\psi\vdash\phi$. By
                            soundness, I have that  $\phi\vDash\psi$
                            and $\psi\vDash\phi$. So, by my (Lemma), we
                            have $\phi\vDash\theta$. But then, by
                            completeness, we have $\phi\vdash\theta$,
                            as desired.

                            \item[11.7.2.11] We want to show that if
                              $\Gamma\vDash c\neq c$, then for all
                              formulas $\phi$, either $\Gamma\vDash\phi$ or
                              $\Gamma\vDash\neg\phi$ (the either
                              \dots or was meant
                              inclusively, otherwise the claim doesn't
                              hold). We actually show the stronger
                              claim that if $\Gamma\vDash c\neq c$,
                              then $\Gamma\vdash\phi$ for all $\phi$,
                              so certainly also for $\phi$ and
                              $\neg\phi$.

                              Above, we proved that if $\Gamma\vDash
                              c\neq c$, then $\Gamma$ is
                              unsatisfiable. We're going to use this
                              result. Since $\Gamma$ is unsatisfiable,
                              so is $\Gamma\cup\{\neg\phi\}$ for every
                              $\phi$ (we proved this in 6.2.5.(c) for
                              propositional logic, but the proof
                              clearly goes through for first-order
                              logic, too). But we know by the ``I
                              Can't Get No Satisfaction'' Theorem,
                              that $\Gamma\cup\{\neg\phi\}$ iff
                              $\Gamma\vDash\phi$. So, we can conclude
                              that if $\Gamma\vDash
                              c\neq c$, then $\Gamma\vDash\phi$, as
                              desired.

                              \item[11.7.2.12] In order to define the
                                desired function, we first define the
                                auxiliary function
                                $c:\mathcal{T}\to\mathbb{N}$ given by
                                the following recursion:
                                \begin{itemize}
                                \item $c(x)=1$ and $c(c)=1$
                                \item $c(f(t_1, \mathellipsis, t_n))=c(t_1)+\mathellipsis+c(t_n)+1$
                                \end{itemize}
                               We then define the desired function as
                               follows:
                               \begin{itemize}
                               \item $c(R(t_1, \mathellipsis,
                                 t_n))=c(t_1)+\mathellipsis+c(t_n)+1$

                               \item $c(s=t)=c(s)+c(t)+1$

                               \item $c(\neg \phi)=c(\phi)+1$
                               \item
                                 $c(\phi\circ\psi)=c(\phi)+c(\psi)+1$
                               \item $c(\forall x\phi)=c(\phi)+1$
                               \end{itemize}

                               We now need to prove that the number of
                               nodes in $T(\phi)$, $\#T(\phi)$, is
                               $c(\phi)$ for all
                               $\phi$. We do this by induction. Well,
                               first we prove the lemma that
                               for all $\#T(t)=c(t)$.

                               For the induction base, note that the
                               parsing tree for both $x\in\mathcal{V}$
                               and $c\in\mathcal{C}$ contains
                               precisely one node. So the claim
                               holds that $\#T(x)=\#T(c)=c(x)=c(c)=1$.

                               So, assume the induction hypothesis
                               that  $\#T(t_i)=c(t_i)$ for $1\leq
                               i\leq n$ and consider the number of
                               nodes in $T(f(t_1, \mathellipsis,
                               t_n))$. Since $T(f(t_1, \mathellipsis,
                               t_n))=$

                               \begin{center}
                               \Tree[.{$f(t_1, \mathellipsis,
                                 t_n)$} [.{$T(t_1)$} ] [
                               .{\dots} ]
                             [.{$T(t_n)$} ] ]
                           \end{center}
                           We have that $\#T(f(t_1, \mathellipsis,
                               t_n))=\#T(t_1)+\mathellipsis+\#T(t_n)+1$,
                               which, by the induction hypothesis is
                               identical to
                               $c(t_1)+\mathellipsis+c(t_n)+1=c(f(t_1,
                               \mathellipsis, t_n)$, as
                               desired.

                               Now, for our main claim, we prove by
                               induction that $\#T(\phi)=c(\phi)$.

                               For the first base case, we note that
                               $T(R(t_1, \mathellipsis, t_n)=$
                               \begin{center}
                               \Tree[.{$R(t_1, \mathellipsis,
                                 t_n)$} [.{$T(t_1)$} ] [
                               .{\dots} ]
                             [.{$T(t_n)$} ] ]
                           \end{center}
                           And so $\#T(R(t_1, \mathellipsis,
                           t_n)=c(t_1)+\mathellipsis+c(t_n)+1=c(R(t_1,
                           \mathellipsis, t_n)$, as
                           desired. For the second base case, we note
                           that $T(s=t)=$
                           \begin{center}
                               \Tree[.{$s=t$} [.{$T(s)$} ]
                             [.{$T(t)$} ] ]
                           \end{center}
                           And so
                           $\#T(s=t)=\#T(s)+\#T(t)+1=c(s)+c(t)+1=c(s=t)$, as
                           desired.

                           For the induction steps,
                           \begin{itemize}
                           \item Assume that  $\#T(\phi)=c(\phi)$ and
                             consider $T(\neg \phi)=$
                             \begin{center}
                               \Tree[.{$\neg \phi$} [.{$T(\phi)$} ] ]
                             \end{center}
                             and so
                             $\#T(\neg\phi)=\#T(\phi)+1=c(\phi)+1$ by
                             the induction hypothesis, as desired.

                             \item Assume that  $\#T(\phi)=c(\phi)$
                               and that  $\#T(\psi)=c(\psi)$ and
                               consider $T(\phi\circ\psi)=$
                                \begin{center}
                               \Tree[.{$\phi\circ\psi$} [.{$T(\phi)$} ]  [.{$T(\psi)$} ]]
                             \end{center}
                             So,
                             $\#T(\phi\circ\psi)=\#T(\phi)+\#T(\psi)+1=c(\phi)+c(\psi)+1$
                             by the induction hypothesis, as desired.

                              \item Assume that  $\#T(\phi)=c(\phi)$ and
                             consider $T(Qx \phi)=$
                             \begin{center}
                               \Tree[.{$Qx \phi$} [.{$T(\phi)$} ] ]
                             \end{center}
                             and so
                             $\#T(Qx\phi)=\#T(\phi)+1=c(\phi)+1$ by
                             the induction hypothesis, as desired.
                           \end{itemize}

                           So, by induction, we indeed have
                           $\#T(\phi)=c(\phi)$, as desired.

                         \item[11.7.2.13]

                           We show that Betrand is correct using
                           logic. First, we formalize the stranger's
                           claim using the following translation key:

                           \begin{center}
                             \begin{tabular}[!h]{c c c}
                               $K^1$ & \dots is a barber\\
                               $S^2$ & \dots shaves \underline{\phantom{\dots}}
                             \end{tabular}
                           \end{center}

                           The stranger's claim becomes:

                           \[ \exists x(K(x)\land \forall y(\neg
                             S(y,y)\leftrightarrow S(x,y)))\]

                           We now prove that Bertrand is correct, since
                           the stranger's claim is a logical
                           falsehood. We show this using
                           tableaux. More specifically, we show that
                           $\vdash \neg \exists x(K(x)\land \forall y(\neg
                             S(y,y)\leftrightarrow S(x,y)))$. By
                             definition, what we need to show is that
                             the tableau for $\{\neg\neg\exists x(K(x)\land \forall y(\neg
                             S(y,y)\leftrightarrow S(x,y)))\}$
                             closes. This can be seen as follows:

            \begin{center}
              \begin{prooftree}
                {%
                  line numbering=false,
                  for tree={s sep'=10mm},
                  single branches=true,
                  close with=\xmark
                }
                [{\neg \neg \exists x(K(x)\land \forall y(\neg S(y,y)\leftrightarrow S(x,y)))}
                    [{\exists x(K(x)\land \forall y(\neg S(y,y)\leftrightarrow S(x,y)))}
                        [{(K(p)\land \forall y(\neg S(y,y)\leftrightarrow S(p,y)))}
                            [{K(p)}
                                [{\forall y(\neg S(y,y)\leftrightarrow S(p,y))}
                                    [{\neg S(p,p)\leftrightarrow S(p,p)}
                                        [{\neg S(p,p)}
                                            [{S(p,p)}, close ]
                                        ]
                                    [{S(p,p)}
                                        [{\neg S(p,p)}, close ]
                                        ]
                                    ]
                                ]
                            ]
                        ]
                    ]
                ]
              \end{prooftree}
            \end{center}

            Now, since
            $\vdash \neg \exists x(K(x)\land \forall y(\neg S(y,y)\leftrightarrow S(x,y)))$,
            by soundness, we have
            $\vDash \neg \exists x(K(x)\land \forall y(\neg S(y,y)\leftrightarrow S(x,y)))$.
            That is the stranger's claim cannot be true in any model, so also not in the actual world.
            Bertrand is right.

                \end{itemize}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "../../logic.tex"
%%% End:


\subsection{Computation: $f(I_t)$}

\begin{frame}{Computation: $f(I_t)$}
    \begin{equation*}
        B: \alert{f(I_t)} \rightarrow O_t
    \end{equation*}
    \begin{columns}[t]
        \begin{column}{0.5\textwidth}
            Extractor function
            \begin{itemize}
                \item \textit{Unbiasing algorithms}
                \item Extracts uniformly distributed sequences
                \item SHA family
                \item Requires known seed
            \end{itemize}
        \end{column}
        \begin{column}{0.5\textwidth}
            Delay function
            \begin{itemize}
                \item Lower bound run time
                \item Inherently sequential
                \item Adjustable to advances in computation
                \item Asymmetrically hard --- slow computation, fast verification
            \end{itemize}
        \end{column}
    \end{columns}
\end{frame}
\note{
    Delay functions are often extractors
}


% $Id: PropagatorOverview.tex,v 1.1 2008/10/09 16:16:11 dconway Exp $
\chapter{\label{chapter:PropagatorOverview}Propagation in GMAT}
\chapauthor{Darrel J. Conway}{Thinking Systems, Inc.}

\section{Propagator Overview}

GMAT's model contains a subsystem that is used to move a user defined mission through time,
following the sequence of events defined in the Mission Control Sequence.  That subsystem is
referred to as the propagation subsystem.  In its most generic form, GMAT's propagation subsystem
can be thought of as taking a mission state $\textbf{X}_i$ at some time $t_i$ and moving that state
by some amount $\delta t$ to some new time $t_f$, resulting in a new state $\textbf{X}_f$.  The
components that are used to perform this change of state are the elements of the propagation
subsystem.  In other words, GMAT's propagation subsystem performs the actions needed to calculate
the new state by performing the operation

\begin{equation}\label{eq:abstractProp}
\textbf{X}_f(t_f) = F(\textbf{X}_i(t_i), \delta t)
\end{equation}

\noindent This chapter provides an overview of the definition of the quantities in this equation:
the definition of the mission state vector and all of its components, the evolution operator $F$
that moves the state vector, and an overview of the construction and decomposition of these
quantities in GMAT.

GMAT's propagation subsystem is used to perform all analytic propagation and numerical integration
needed by the system.  That includes modeling the time lines for spacecraft and formations, mass
depletion modeling during finite duration maneuvers, evolution of the state transition matrix,
attitude propagation, evolution of physical properties and their variances as needed for orbit and
attitude determination problems, and evolution of costate variables needed for optimal control
problems.  The diversity of propagation issues encountered in the coverage provided by the
propagation subsystem makes it a potentially quite complicated collection of components.  For that
reason, the subsystem is broken into a collection of different elements each tailored to specific
aspects of the propagation problem regime.  The propagation problem requires a consistent, complete
description of the evolution operators and the propagation vector, which are discussed briefly below
and in detail in Chapters~\ref{chapter:Propagators} and~\ref{chapter:PropagatorStates},
respectively.  This chapter concludes with a description of the scripting elements used to drive
propagation in GMAT, using the Propagate command as an example of this scripting.

\section{Propagator Overview}

The function $F$ in equation~\ref{eq:abstractProp} defines the process that takes a vector of
numbers defining system properties at one time and finds the values of those same properties at a
different time.  This process of moving the properties through time is performed using one
or more evolution operators.  The objects in GMAT that perform this evolution are the propagators.
GMAT's propagators are designed to support evolution either forwards or backwards in time.  The
propagators can be set to run in a synchronized manner or independently of one another.  The
selection of the category and type of propagator that is used is selected by the user based on the
types of parameters that need to be propagated.

GMAT Supports three different categories of propagators, defined by the type of data available for
the propagation.  The categories are

\begin{description}
\item[Analytic] GMAT's analytic propagators take a known, closed form solution to the evolution
problem and apply that solution to the propagation vector specified at some initial time to find its
values at some other time.  GMAT's analytic propagators use embedded evolution equations to
calculate the values of parameters at the desired times.
\item[Numerical] The numerical propagators find a solution of the differential equations of motion
for the parameters using a precision numerical integrator and derivative models.  Propagators in
this category consist of a pair of objects: a numerical integrator derived from the Integrator class
and a derivative model derived from the PhysicalModel class.
\item[Precalculated]  Precalculated parameter values are retrieved -- and, if needed, interpolated
-- from files containing the time history of the parameter values.
 \end{description}

Each category of propagator supplies implementations of core methods designed to standardize
the propagation interface.  The core propagation interfaces are defined in the Propagator base
class.  Every GMAT propagator uses these interfaces to perform the following actions:

\begin{itemize}
\item Map the propagation vector to known evolution operators
\item Initialize all data structures and object references needed to propagate
\item Load the initialized data structure immediately before propagating
\item Propagate the propagation vector
\item Reset the propagator to use its initial settings
\end{itemize}

\noindent The Propagator class defines these interfaces to perform the actions listed above:

\begin{description}
\item[GetPropagatorOrder]  GMAT includes both first and second order numerical integrators.  This
interface is used to determine which is needed for a particular integrator.  The non-numerical
integrators all report order 0.
\item[SetPhysicalModel]  The SetPhysicalModel method sets the derivative model used for numerical
integration, and -- for all propagators -- performs pre-initialization tasks required before
initialization can proceed.  This method ensures that all of the elements needed for evolution have
been set for the propagator.
\item[Initialize]  All of the reference object pointers and other interconnections necessary for
propagation are set in the Initialize method.  Propagators that do not allow for dynamic resizing of
the propagation vector also use this method to initialize the propagation vector mapping needed for
the evolution.  Those that may require dynamic resizing perform a preliminary mapping during
initialization.
\item[Update]  The Update method is used to reset the propagator when the underlying physical model
changes.  This method is used to refresh the propagation vector mapping if the propagation vector
has changed -- for instance, when a transient derivative is applied or removed to model mass flow
during a finite maneuver.  It also resets some of the propagator's properties if needed, like the
initial step size for variable step propagators.
\item[ResetInitialData]  The ResetInitialData method sets a flag telling the propagator that at the
next call to propagate the propagation vector, the propagator's initial data needs to be updated
prior to propagation.
\item[Step]  State evolution is driven through calls to the Step method.  Different categories and
subcategories of propagators implement different versions of this method based on the needs and
capabilities of the propagators.
\end{description}

\noindent These methods define the minimum level of interface required for every GMAT propagator.
The Propagator subclasses extend this set based on the needs of the category of the propagator
defined in the subclass.

The design details for the propagators are provided in Chapter~\ref{chapter:Propagators}.

\section{Propagation Vector Overview}

The propagators evolve a vector of data from one epoch to another.  The data that evolves is
contained in a column vector sized to match the evolving data.  This vector is assembled and
populated prior to propagation based on specifications scripted by the user.  The propagation
vector provides methods that support the following actions:

\begin{itemize}
\item Supply epoch information
\item Supply propagation vector information, including all of the following:
\begin{itemize}
\item Size of the vector
\item Element by element types for mapping the vector onto the propagator
\end{itemize}
\item Supply the propagation vector
\end{itemize}

\noindent GMAT uses a class, PropVector, to model the propagation vector.  The PropVector objects
supply the information used to assemble the derivative vector needed for numerical integration, the
epoch and state data needed for analytic propagation, or the epoch and time step information used
for precalculated propagation.

The PropVector class defines these interfaces to perform the actions listed above:

\begin{description}
\item[GetEpoch and SetEpoch]  A PropVector contains data calculated at a single epoch.  These
GetEpoch and SetEpoch methods provide access to the epoch data in the PropVector.
\item[GetDimension]  Retrieves the current size of the PropVector -- that is, the number of
elements that evolve over time.  The dimension is used to initialize the propagator, and, in
conjuction with the vector map, to ensure that the correct operator is used to evolve each element
of the vector.
\item[GetVectorMap]  Retrieves the mapping of the PropVector, element by element, so that the
evolution components can be set correctly.
\item[GetVector]  Retireves a pointer to the Real array of data for the vector.  The retrieved
vector has the size given by the dimension of the PropVector, mapped as specified in the vector
map.  Components that use the PropVector for propagation can both read and write to this retrieved
vector.  This violation of encapsulation is intentional, in order to make the propagation process
as fast as possible in GMAT.
\end{description}

\noindent These interfaces define the minimal interfaces necessary for PropVector objects.  They
are defined as overridable interfaces so that classes can be derived form PropVector in the future
as needed.

The PropVector class is managed through a mapping class, the MissionState.  The MissionState class
is a container class -- it contains references to the objects providing state data that evolves
using GMAT's evolution operators, as defined in its Propagator classes.  The MissionState class
provides methods accessed by the propagators to construct, retrieve, and update the PropVector.  It
manages the data flow between these objects and the propagation vectors manipulated by the
Propagators.  The MissionState builds the PropVectors used by the propagators, setting up the data
vector and associated component mappings used by the propagator to assemble the elements needed for
propagation.

The MissionState class defines a set of interfaces used to manage the data soureces used to assemble
the PropVector.  The interfaces supplied by the MissionState for these tasks are:

\begin{description}
\item[AddObject]  Adds an object that supplied data to one or more PropVectors.
\item[Initialize]  Constructs the PropVector or PropVectors used by a propagator.
\item[PrepareToPropagate] Completes PropVector initialization needed prior to propagation.
\item[GetPropVector]  Retrieves an assembled PropVector designed for propagation.
\end{description}

\noindent Each one of GMAT's propagators uses a MissionState object to manage the data that is
propagated.

The PropVector and MissionState classes are described in detail in
Chapter~\ref{chapter:PropagatorStates}.

\section{Scripting Propagation}

As is described above, GMAT provides three approaches to propagation.  The system can model the
evolution of the state data by numerically integrating the equations of motion, providing a high
precision model of the evolution, by reading the data from a pre-calculated file of data points
(e.g. a SPICE file), or by using an analytical propagator that provides a fast, lower fidelity
vector of propagated data.  The propagation subsystem can perform these tasks for all of the
parameters represented in the propagation vector: for the spacecraft orbit and attitude data, mass
properties, for the state transition matrix and covariance matrices, and for any other parameters
placed in the propagation vector, as long as the underlying propagation model supporting the
parameter exists.  For the numerical integrators, that means that the  set of ordinary differential
equations describing the evolution have been coded into the system.  Similarly, analytic
propagators require encoding of the analytic equations of motion.  The precalculated data
propagators require an ephemeris or similar time based file of the evolution of the paramteres that
they propagate.  GMAT is designed to support mixed mode propagation as well; elements propagated in
a Mission Control Sequence command need not all be propagated using the same approach.  Some can be
propagated analytically or using a file while others are numerically integrated.  The design
implementing this mode is described in Chapter~\ref{chapter:Propagators} and in the descriptions of
the commands that support propagation.

Commands that drive propagation follow the process shown in
Figure~\ref{figure:CommandPropagationOverview}.  The command is initialized in the Sandbox along
with the rest of the Mission Control Sequence.  During this initialization, specific pieces
required to initialize each propagator driven by that command are performed.  There are portions of
the propagation process that cannot be initialized at this point in the mission run because they
depend on data that may be changed when commands that precede the one invoking propagation fire.
This final piece of initialization is performed in a method named PrepareToPropagate(), which is
called when the command's Execute() method is called, immediately before the actual propagation.
Finally, the propagation is performed in the body of the Execute() method associated with the
command.

\begin{figure}[htb]
\begin{center}
\includegraphics[scale=0.5]{Images/PropagationintheMCS.eps}
\caption[Command and Propagation Processes]{\label{figure:CommandPropagationOverview}Command and
Propagation Processes}
\end{center}
\end{figure}

\subsection{Example: The Propagate Command}

Propagation is scripted in GMAT through the creation of propagator objects and the incorporation of
these objects into the Mission Control Sequence through propagator enabled commands.  The
prototypical propagator enabled command is the Propagate command (described more fully in
Section~\ref{section:Propagate}), scripted in its simplest form like this:

\begin{quote}
\begin{verbatim}
Propagate prop(sat)
\end{verbatim}
\end{quote}

\noindent The command shown here consists of three elements: the Propagate keyword, the name of the
propagator that is used (``prop'' in this case), and the object that is propagated, ``sat'' in
this example.  In order for this command to run, the objects used in teh propagation must exist, so
there must be matching creation commands.  Assuming that the command exists in the main script
rather than a function, that means these lines must occur before the Propagate command line:

\begin{quote}
\begin{verbatim}
Create Spacecraft sat;
Create Propagator prop;
\end{verbatim}
\end{quote}

\noindent The propagated object can, of course, be any object that supplies a propagation vector for
propagation.

The type of propagator is specified by setting the ``Type'' property on the propagator object, like
this:
\begin{quote}
\begin{verbatim}
prop.Type = PrinceDormand78;  % Use a Prince-Dormand RK integrator
\end{verbatim}
\end{quote}

\noindent The Type setting for the propagator must be made before setting any other propagator
properties because the properties for the propagator depend on the type of Propagator object that is
being used.  Every GMAT propagator has default values for each of its properties.  Users override
these settings to tailor the behavior of the propagator.

The following sections describe the scripting for each category of Propagator.

\subsubsection{Scripting Numerical Integrators}

The numerical integrators require an additional object defining the forces and other differential
equations that are used to model the propagation.  These pieces are gathered in a container class,
the ODEModel class derived from PhysicalModel.  The ODEModel class plays several roles in the
propagation subsystem:

\begin{itemize}
\item It works with a MissionState object to create the propagation vector
\item It coordinates the data mapping between the objects that are propagated and the propagation
vector
\item It handles the superposition tasks when the differential equations defining propagation
consist of multiple components
\end{itemize}

\noindent The ODEModel class is described more fully in Section~\ref{section:TheODEModel}.
Scripting for ODEModel objects depends on context.  For orbit propagation, the ODEModel is scripted
as a ForceModel component, using this syntax:

\begin{quote}
\begin{verbatim}
Create ForceModel forces;
forces.CentralBody = Earth;
forces.PrimaryBodies = {Earth};
forces.Drag = MSISE90;
forces.SRP = On;
forces.ErrorControl = RSSStep;
forces.GravityField.Earth.Degree = 4;
forces.GravityField.Earth.Order = 4;
forces.GravityField.Earth.PotentialFile = 'JGM2.cof';
forces.PointMasses = {Sun, Luna, Mercury, Venus, Mars};

Create Propagator prop;
prop.Type = PrinceDormand78;
prop.FM = forces;
\end{verbatim}
\end{quote}

\noindent The forces that are included in the differential equations of motion are defined by
specifying the desired elements and, when needed, properties of those elements.  The resulting
ODEModel is assigned to the integrator by assigning its name to the FM property of the Propagator.

\subsubsection{Scripting Analytic Propagators}

This section is TBD, based on requirements and design for analytic propagators when they are added
to GMAT.

\subsubsection{Scripting Precalculated Propagators}

\textit{Detailed information for this section is TBD, based on requirements and design for the SPICE
file component and discussions of other ephemeris based propagators planned for GMAT.  However, the
scripting discussion is underway, and included here, subject to extensive revision.}

Propagation based on precalculated data is used in GMAT to propagate data for spacecraft, celestial
bodies not modeled elsewhere, and other elements that are described using file-based time-indexed
data.

Scripting for the precalculated propagators is similar to that for the numerical integrators.  The
precalculated propagators identify the propagator type as one of the supported file based propagator
types, and identify a file -- the file containing the ephemeris data -- rather than a force model.
An example of the setup for a SPICE file based precalculated propagator for the Clementine mission
is given here:

\begin{quote}
\begin{verbatim}
Create Spacecraft Clementine
Clementine.EphemID = -40      % Clementine's NAIF ID

Create Asteroid Geographos    % Asteroid support is a future enhancement;
                              % use a Spacecraft with the current code base
Geographos.EphemID = 2006513  % No clue about the real NAIF ID for Geographos...

Create Propagator prop
prop.type = SPICE
prop.StepSize = 300    % seconds
prop.Ephemeris = DSPSE.SPK        % Ephem containing Clementine and Geographos
prop.Ephemeris = SolarBodies.SPK  % Second ephem used to add vectors together
\end{verbatim}
\end{quote}

\noindent Propagation with a SPICE file propagator is handled identically to that performed using
other propagators.  For the asteroid encounter phase of the mission above, a user could script the
propagaton like this:

\begin{quote}
\begin{verbatim}
Create Variable i
For i = 0 : 2000
   Propagate prop(Clementine, Geographos)
EndFor
\end{verbatim}
\end{quote}

\noindent One constraint imposed in GMAT is that for a single ephemeris based propagator, each
object that is propagated must be contained in the same ephemeris file.  That means that in the
example above, the ephemeris for both the Clementine spacecraft and the asteroid Geographos must
exist in the SPICE file DSPSE.SPK.  For this case, the same result could be achieved with separate
ephemerides for the spacecraft and asteroid with this scripting:

\begin{quote}
\begin{verbatim}
Create Spacecraft Clementine
Clementine.EphemID = -40   % Clementine's NAIF ID

Create Asteroid Geographos    % Asteroid support is a future enhancement;
                              % use a Spacecraft with the current code base
Geographos.EphemID = 2006513  % No clue about the real NAIF ID for Geographos...

Create Propagator prop
prop.type = SPICE
prop.StepSize = 300    % seconds
prop.Ephemeris = Clementine.SPK   % Ephem containing Clementine
prop.Ephemeris = SolarBodies.SPK  % Second ephem used to add vectors together

Create Propagator geogProp
geogProp.type = SPICE
geogProp.StepSize = 300    % seconds
geogProp.Ephemeris = Asteroids.SPK    % Ephem containing Geographos
geogProp.Ephemeris = SolarBodies.SPK  % Second ephem used to add vectors together

Create Variable i
For i = 0 : 2000
   Propagate Synchronized prop(Clementine) geogProp(Geographos)
EndFor
\end{verbatim}
\end{quote}

\noindent Finally, you may have noted that a second ephemeris source is identified for the SPICE
propagator.  This option is scripted in these examples to allow conversion of the epheris data for
propagated objects to other bodies in the model.  For example, the ephemeris for Geographos is
likely to be calculated with respect to the Sun.  GMAT may need Earth-centered states, so the SPICE
propagator needs to load the SPICE kernel that describes the Earth's location with respect to the
Sun in order to add the position vectors together to build the state vector.

The following chapters provide details of the propagation subsystem components.
Chapter~\ref{chapter:PropagatorStates} describes the PropVector and MissionState classes, and
includes descriptions of the data mapping for vector elements and diagrams describing hte layout of
the PropVector data for single and multiple objects.  Chapter~\ref{chapter:Propagators} describes
the design of the propagator classes.  The commands that control the propagation subsystem are
described in Chapters~\ref{chapter:Commands} and~\ref{chapter:SpecificCommands}.

% \subsection{The Equations of Motion}
%
% \subsection{Division of Labor: Integrators and Forces}
%
% \section{Integrators}
%
% \section{\label{section:ForceModelOverview}The GMAT Force Model}
%
% \subsection{The PhysicalModel Class}
%
% \subsection{The ForceModel Class}
%
% \subsubsection{Adding and Removing Forces}
%
% \subsection{Applying Forces to Spacecraft}
%
% \section{The State Vector}
%
% \section{The PropSetup Container}


\subsection{Applying Models to New York City}

So what about applying the same models to climate data of a different city? We consider to use the weather data from New York City in 2017 as test data with the models trained by Seattle data. The same data preprocessing approach is followed as what we did on Seattle data. After that, we only apply SVM and random forest here as they have better performance than $k$-NN. The confusion matrices are shown respectively in Table \ref{ny1} and Table \ref{ny2}.

For random forest, the Type \uppercase\expandafter{\romannumeral1} error is significantly higher. Although the Type \uppercase\expandafter{\romannumeral2} error is lower, it is actually due to the model classified to many days into rain days mistakenly. The model predicted 289 days that rain in 2017 and the average raining day in New York based on historical record is 122. Overall, this model trained with Seattle data is not suitable to predict precipitation in New York. Again, we apply SVM with whole Seattle data as training set and test on New York. As shown in Table \ref{ny2}, the Type \uppercase\expandafter{\romannumeral1} error is significantly higher as well as the Type \uppercase\expandafter{\romannumeral2} error. Overall those two model performed badly in the New York data.

\begin{table}[h]
\setlength{\belowcaptionskip}{5pt}
\caption{Confusion Matrix for New York, Random Forest}
\label{ny1}
\centering
\renewcommand\arraystretch{1.5}
\begin{tabular}{rrrrr}
\hline
\hline
 & & \multicolumn{2}{c}{True Condition} & \\
\hline
 & & Non-Precipitation & Precipitation & \\
\cline{1-4}
\multirow{2}{*}{Prediction} & {Non-Precipitation} & 62 & 13 & \\
\cline{2-4}
&Precipitation&176&113&\\
\hline
&Error Rate & 0.7394 & 0.1031 & 0.5192\\
\cline{2-5}
& & Type \uppercase\expandafter{\romannumeral1} & Type \uppercase\expandafter{\romannumeral2} & Overall\\
\hline
\end{tabular}
\end{table}

\begin{table}[h]
\setlength{\belowcaptionskip}{5pt}
\caption{Confusion Matrix for New York, SVM}
\label{ny2}
\centering
\renewcommand\arraystretch{1.5}
\begin{tabular}{rrrrr}
\hline
\hline
 & & \multicolumn{2}{c}{True Condition} & \\
\hline
 & & Non-Precipitation & Precipitation & \\
\cline{1-4}
\multirow{2}{*}{Prediction} & {Non-Precipitation} & 96 & 45 & \\
\cline{2-4}
&Precipitation&142&81&\\
\hline
&Error Rate & 0.596 & 0.357 & 0.5137\\
\cline{2-5}
& & Type \uppercase\expandafter{\romannumeral1} & Type \uppercase\expandafter{\romannumeral2} & Overall\\
\hline
\end{tabular}
\end{table}

There are several possible explanations for this. First, New York located on the east coast may have totally different meteorological environment compares to Seattle. So the variables and the threshold of those variables that matter in prediction may change. Second, New York has a rather imbalanced situation which has more days without precipitation (in fact, 126 days with precipitation, and 238 days without).


\section{Substitute Vectors}
\label{sec:lm}

In this study, we predict the part of speech of a word in a given
context based on its substitute vector.  The dimensions of the
substitute vector represent words in the vocabulary, and the entries
in the substitute vector represent the probability of those words
being used in the given context.  Note that the substitute vector is a
function of the context only and is indifferent to the target word.
This section details the choice of the data set, the vocabulary and
the estimation of substitute vector probabilities.

% what is the test data
The Wall Street Journal Section of the Penn Treebank \cite{treebank3}
was used as the test corpus (1,173,766 tokens, 49,206 types).
% what is the tag set
The treebank uses 45 part-of-speech tags which is the set we used as
the gold standard for comparison in our experiments.
% what is the LM training data
%Train => 5181717 126019973 690121813
To compute substitute probabilities we trained a language model using
approximately 126 million tokens of Wall Street Journal data
(1987-1994) extracted from CSR-III Text \cite{csr3text} (we excluded
the test corpus).
% how is the language model trained
We used SRILM \cite{Stolcke2002} to build a 4-gram language model with
Kneser-Ney discounting.
% what is the vocabulary
Words that were observed less than 20 times in the language model
training data were replaced by \textsc{unk} tags, which gave us a
vocabulary size of 78,498.
% perplexity
The perplexity of the 4-gram language model on the test corpus is 96.

% how are the substitutes computed
It is best to use both left and right context when estimating the
probabilities for potential lexical substitutes.  For example, in
\emph{``He lived in San Francisco suburbs.''}, the token \emph{San}
would be difficult to guess from the left context but it is almost
certain looking at the right context.  We define $c_w$ as the $2n-1$
word window centered around the target word position: $w_{-n+1} \ldots
w_0 \ldots w_{n-1}$ ($n=4$ is the n-gram order).  The probability of a
substitute word $w$ in a given context $c_w$ can be estimated as:
\begin{eqnarray}
  \label{eq:lm1}P(w_0 = w | c_w) & \propto & P(w_{-n+1}\ldots w_0\ldots w_{n-1})\\
  \label{eq:lm2}& = & P(w_{-n+1})P(w_{-n+2}|w_{-n+1})\nonumber\\
  &&\ldots P(w_{n-1}|w_{-n+1}^{n-2})\\
  \label{eq:lm3}& \approx & P(w_0| w_{-n+1}^{-1})P(w_{1}|w_{-n+2}^0)\nonumber\\
  &&\ldots P(w_{n-1}|w_0^{n-2})
\end{eqnarray}
where $w_i^j$ represents the sequence of words $w_i w_{i+1} \ldots
w_{j}$.  In Equation \ref{eq:lm1}, $P(w|c_w)$ is proportional to
$P(w_{-n+1}\ldots w_0 \ldots w_{n+1})$ because the words of the
context are fixed.  Terms without $w_0$ are identical for each
substitute in Equation \ref{eq:lm2} therefore they have been dropped
in Equation \ref{eq:lm3}.  Finally, because of the Markov property of
n-gram language model, only the closest $n-1$ words are used in the
experiments.

Near the sentence boundaries the appropriate terms were truncated in
Equation \ref{eq:lm3}.  Specifically, at the beginning of the sentence
shorter n-gram contexts were used and at the end of the sentence terms
beyond the end-of-sentence token were dropped.

For computational efficiency only the top 100 substitutes and their
unnormalized probabilities were computed for each of the 1,173,766
positions in the test set\footnote{The substitutes with unnormalized
  log probabilities can be downloaded from \mbox{\url{http://goo.gl/jzKH0}}.
  For a description of the {\sc fastsubs} algorithm used to generate
  the substitutes please see \mbox{\url{http://arxiv.org/abs/1205.5407v1}}.
  {\sc fastsubs} accomplishes this task in about 5 hours, a naive
  algorithm that looks at the whole vocabulary would take more than 6
  days on a typical 2012 workstation.}.  The probability vectors for
each position were normalized to add up to 1.0 giving us the final
substitute vectors used in the rest of this study.


% -*- latex -*-

% This file can be used for troubleshooting problems.

% Adjust this file to your liking and then build using:
%    make mathics-test.pdf
\chapter{Test Chapter}
\chapterstart
\chaptersections
\section*{TestSection}
\sectionstart

Here is what we want to test:

\begin{asy}
if(!settings.multipleView) settings.batchView=false;
settings.tex="xelatex";
defaultfilename="mathics-test-1";   % Note that filename line has been altered!
if(settings.render < 0) settings.render=4;
settings.outformat="";
settings.inlineimage=true;
settings.embed=true;
settings.toolbar=false;
viewportmargin=(2,2);

% Copy stuff here from mathics-xxx.asy
% The below is from the "Darker" section around mathics-114.asy

import three;
import solids;
size(6.6667cm, 6.6667cm);
currentprojection=perspective(2.6,-4.8,4.0);
currentlight=light(rgb(0.5,0.5,1), specular=red, (2,0,2), (2,2,2), (0,2,2));
// Sphere3DBox
draw(surface(sphere((0, 0, 0), 1)), rgb(0.0,0.6666666666666667,0.0));
draw(((-1,-1,-1)--(1,-1,-1)), rgb(0.4, 0.4, 0.4)+linewidth(1));
draw(((-1,1,-1)--(1,1,-1)), rgb(0.4, 0.4, 0.4)+linewidth(1));
draw(((-1,-1,1)--(1,-1,1)), rgb(0.4, 0.4, 0.4)+linewidth(1));
draw(((-1,1,1)--(1,1,1)), rgb(0.4, 0.4, 0.4)+linewidth(1));
draw(((-1,-1,-1)--(-1,1,-1)), rgb(0.4, 0.4, 0.4)+linewidth(1));
draw(((1,-1,-1)--(1,1,-1)), rgb(0.4, 0.4, 0.4)+linewidth(1));
draw(((-1,-1,1)--(-1,1,1)), rgb(0.4, 0.4, 0.4)+linewidth(1));
draw(((1,-1,1)--(1,1,1)), rgb(0.4, 0.4, 0.4)+linewidth(1));
draw(((-1,-1,-1)--(-1,-1,1)), rgb(0.4, 0.4, 0.4)+linewidth(1));
draw(((1,-1,-1)--(1,-1,1)), rgb(0.4, 0.4, 0.4)+linewidth(1));
draw(((-1,1,-1)--(-1,1,1)), rgb(0.4, 0.4, 0.4)+linewidth(1));
draw(((1,1,-1)--(1,1,1)), rgb(0.4, 0.4, 0.4)+linewidth(1));
\end{asy}
\sectionend
\chapterend


\chapter{Limits \& Continuity}

Limits are a way of describing what happens to a function $f(x)$ as $x$ gets arbitrarily close to a value from some direction (positive or negative).
This allows us not only to deal with "holes" in some functions but describe some of the building blocks of calculus, namely the derivative.

\input{./limits_continuity/limit_definition.tex}
\input{./limits_continuity/limit_properties.tex}
\input{./limits_continuity/left_right_hand_limits.tex}
\input{./limits_continuity/sandwich_theorem.tex}
\input{./limits_continuity/infinite_limits.tex}
\input{./limits_continuity/continuity_definition.tex}
\input{./limits_continuity/discontinuity_types.tex}
\input{./limits_continuity/continuity_properties.tex}
\input{./limits_continuity/intermediate_value_theorem.tex}


\documentclass[11pt,a4paper]{report}
\usepackage{amsmath,amsfonts,amssymb,amsthm,epsfig,epstopdf,titling,url,array}
\usepackage{enumitem}
\usepackage{changepage}
\usepackage{graphicx}
\usepackage{caption}
\theoremstyle{plain}
\newtheorem{thm}{Theorem}[section]
\newtheorem{lem}[thm]{Lemma}
\newtheorem{prop}[thm]{Proposition}
\newtheorem*{cor}{Corollary}
\theoremstyle{definition}
\newtheorem{defn}{Definition}[section]
\newtheorem{conj}{Conjecture}[section]
\newtheorem{exmp}{Example}[section]
\newtheorem{exercise}{Exercise}[section]
\theoremstyle{remark}
\newtheorem*{rem}{Remark}
\newtheorem*{note}{Note}
\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]}
\let\endchangemargin=\endlist
\begin{document}

\section*{Problem}
The function graphed below is a polynomial with only real roots. What is the function?
\begin{figure}[h!]
  \includegraphics[width=4in]{poly.png}
  {\caption*{}}
  \label{}
\end{figure}
\section*{Bonus}
Find all roots of the polynomial $x^3-x^2+x-1$.  Explain why this example illustrates how the ``only real roots'' assumption simplifies the answer to the first part.

\newpage
\section*{Solution}
From the graph, you can see that the polynomial has roots at $x=-1$, $x=0$, and $x=1$.  Since the polynomial has only real roots, its equation must be $p(x) = (x - - 1)(x - 0)(x - 1) = x^3 - x$.

\section*{Bonus Solution}
$x^3 - x^2 + x - 1 = (x^2 + 1)(x - 1) = (x - i)(x -- i)(x - 1)$
This polynomial has roots at $\pm i$ in the complex plane and at the real number 1.  Its graph shows only the real root at $x = 1$.  So in general, just multiplying together $(x - r_i)$ where the $r_i$ are the real roots (what you can see in its graph) will not always give you the equation of the polynomial.  If you have all of the complex roots, it will always work (up to a constant). A beautiful fact about the Complex numbers is that they make up what is called an \textit{algebraically closed field} with the consequence that every polynomial of degree $n$ with real or complex coefficients can be factored into a product like the above, giving $n$ roots.  Some may be ``repeated'' as in $p(x) = x^2 = (x - 0)(x - 0)$.

\section*{Bonus Bonus Solution}
There is actually an error in the solution above. The graph is in fact the graph of the given function, but that can't actually be established from the information given.  If $p(x)$ is a polynomial and $c$ is a non-zero constant, the $r(x) = c \mathord{\cdot} p(x)$ is another polynomial with the same roots.  So for example, $2x^3 - 2x$ would also have the same roots as the polynomial above.

\end{document}


\documentclass[a4paper]{report}

\usepackage[margin=3.0cm]{geometry}
\usepackage{amsmath}
\usepackage[pdftex]{graphicx}
%\usepackage{graphics}
\usepackage{subfig}
\setlength\parindent{0pt}
%\usepackage{natbib}           % required for bibliography

\title{HPIPM reference guide}
\author{Gianluca Frison}

\begin{document}

\maketitle
\tableofcontents

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Introduction}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

HPIPM, which stands for High-Performance Interior Point Method, is a library providing a collection of quadratic programs (QP) and routines to manage them.
Aim of the library is to provide both stand-alone IPM solvers for the QPs and the building blocks for more complex optimization algorithms.

At the moment, three QPs types are provided: dense QPs, optimal control problem (OCP) QPs, and tree-structured OCP QPs.
These QPs are defined using C structures.
HPIPM provides routines to manage the QPs, and to convert between them.

HPIPM is written entirely in C, and it builds on top of BLASFEO~\cite{Frison2018}, that provides high-performance implementations of basic linear algebra (LA) routines, optimized for matrices of moderate size (as common in embedded optimization).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Dense QP}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

The dense QP is a QP in the form
\begin{align*}
\min_{v,s} & \quad \frac 1 2 \begin{bmatrix} v \\ 1 \end{bmatrix}^T \begin{bmatrix} H & g \\ g^T & 0 \end{bmatrix} \begin{bmatrix} v \\ 1 \end{bmatrix} + \frac 1 2 \begin{bmatrix} s^l \\ s^u \\ 1 \end{bmatrix}^T \begin{bmatrix} Z^l & 0 & z^l \\ 0 & Z^u & z^u \\ (z^l)^T & (z^u)^T & 0 \end{bmatrix} \begin{bmatrix} s^l \\ s^u \\ 1 \end{bmatrix} \\
\text{s.t.} & \quad A v = b, \\
& \quad \begin{bmatrix} \underline v \\ \underline d \end{bmatrix} \leq \begin{bmatrix} J_{b,v} \\ C \end{bmatrix} v + \begin{bmatrix} J_{s,v} \\ J_{s,g} \end{bmatrix} s^l, \\
& \quad \begin{bmatrix} J_{b,v} \\ C \end{bmatrix} v - \begin{bmatrix} J_{s,v} \\ J_{s,g} \end{bmatrix} s^u \leq \begin{bmatrix} \overline v \\ \overline d \end{bmatrix}, \\
& \quad s^l\geq \underline s^l, \\
& \quad s^u\geq \underline s^u,
\end{align*}
where $v$ are the primal variables, $s^l$ ($s^u$) are the slack variables of the soft lower (upper) constraints.
The matrices $J_{\dots}$ are made of rows from identity matrices.
Furthermore, note that the constraint matrix with respect to $v$ is the same for the upper and the lower constraints.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{OCP QP}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

The OCP QP is a QP in the form
\begin{align*}
\min_{x,u,s} & \quad \sum_{n=0}^N \frac 1 2 \begin{bmatrix} u_n \\ x_n \\ 1 \end{bmatrix}^T \begin{bmatrix} R_n & S_n & r_n \\ S_n^T & Q_n & q_n \\ r_n^T & q_n^T & 0 \end{bmatrix} \begin{bmatrix} u_n \\ x_n \\ 1 \end{bmatrix} + \frac 1 2 \begin{bmatrix} s^l_n \\ s^u_n \\ 1 \end{bmatrix}^T \begin{bmatrix} Z^l_n & 0 & z^l_n \\ 0 & Z^u_n & z^u_n \\ (z^l_n)^T & (z^u_n)^T & 0 \end{bmatrix} \begin{bmatrix} s^l_n \\ s^u_n \\ 1 \end{bmatrix} \\
\text{s.t}  & & \\
     & \quad x_{n+1} = A_n x_n + B_n u_n + b_n, \qquad \qquad \qquad \qquad \qquad \qquad n=0,\dots,N-1, &\\
     & \quad \begin{bmatrix} \underline u_n \\ \underline x_n \\ \underline d_n \end{bmatrix} \leq \begin{bmatrix} J_{b,u,n} & 0 \\ 0 & J_{b,x,n} \\ D_n & C_n \end{bmatrix} \begin{bmatrix} u_n \\ x_n \end{bmatrix} + \begin{bmatrix} J_{s,u,n} \\ J_{s,x,n} \\ J_{s,g,n} \end{bmatrix} s^l_n, \quad \qquad \quad \,n=0,\dots,N, &\\
& \quad \begin{bmatrix} J_{b,u,n} & 0 \\ 0 & J_{b,x,n} \\ D_n & C_n \end{bmatrix} \begin{bmatrix} u_n \\ x_n \end{bmatrix} - \begin{bmatrix} J_{s,u,n} \\ J_{s,x,n} \\ J_{s,g,n} \end{bmatrix} s^u_n \leq \begin{bmatrix} \overline u_n \\ \overline x_n \\ \overline d_n \end{bmatrix} , \qquad \qquad n=0,\dots,N, & & \\
& \quad s^l_n\geq \underline{s}^l_n, \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \,\,\,  n=0,\dots,N, & &\\
& \quad s^u_n\geq \underline{s}^u_n, \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \,\,\,  n=0,\dots,N, & &\\
\end{align*}
where $u_n$ are the control inputs, $x_n$ are the states, $s^l_n$ ($s^u_n$) are the slack variables of the soft lower (upper) constraints
and $\underline{s}^l_n$ and $\underline{s}^u_n$ are the lower bounds on lower and upper slacks, respectively.
The matrices $J_{\dots,n}$ are made of rows from identity matrices.
Note that all quantities can vary stage-wise.
Furthermore, note that the constraint matrix with respect to $u$ and $x$ is the same for the upper and the lower constraints.

%%%%%%%%%%%%%%%%
\section{QP dimensions structure}
%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%
\subsection{Create structure}
%%%%%%%%%%%%%%%%

\begin{verbatim}
int d_ocp_qp_dim_memsize(int N);
\end{verbatim}

\begin{verbatim}
void d_ocp_qp_dim_create(int N, struct d_ocp_qp *qp, void *memory);
\end{verbatim}

%%%%%%%%%%%%%%%%
\subsection{Populate structure}
%%%%%%%%%%%%%%%%

Once created, an OCP QP dimmensions structure can be populated using the global setter routine
\begin{verbatim}
void d_ocp_qp_dim_set_all(int *nx, int *nu,
    int *nbx, int *nbu, int *ng,
    int *nsbx, int *nsbu, int *nsg,
    struct d_ocp_qp_dim *dim);
\end{verbatim}
which is useful when all structure fields have to be populated at onece.

Alternatively, it is possible to set the individual structure fields with the setter routine
\begin{verbatim}
void d_ocp_qp_dim_set(char *field, int *stage, int value,
    struct d_ocp_qp_dim *dim);
\end{verbatim}
where {\tt field} can be one of {\tt nx, nu, nbx, nbu, ng, nsbx, nsbu, nsg}.

%%%%%%%%%%%%%%%%
\section{QP structure}
%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%
\subsection{Create structure}
%%%%%%%%%%%%%%%%

\begin{verbatim}
int d_ocp_qp_memsize(struct d_ocp_qp_dim *dim);
\end{verbatim}

\begin{verbatim}
void d_ocp_qp_create(struct d_ocp_qp_dim *dim, struct d_ocp_qp *qp, void *memory);
\end{verbatim}

%%%%%%%%%%%%%%%%
\subsection{Populate structure}
%%%%%%%%%%%%%%%%

Once created, an OCP QP structure can be populated using the global conversion routine
\begin{verbatim}
void d_ocp_qp_set_all(double **A, double **B, double **b,
    double **Q, double **S, double **R, double **q, double **r,
    int **idxbx, double **lbx, double **ubx,
    int **idxbu, double **lbu, double **ubu,
    double **C, double **D, double **lg, double **ug,
    double **Zl, double **Zu, double **zl, double **zu,
    int **idxs, double **lls, double **lus,
    struct d_ocp_qp *qp);
\end{verbatim}
which is useful when all the structure fileds have to be populated at once.

Alternatively, it is possible to set the individual structure fields with the setter routine
\begin{verbatim}
void d_ocp_qp_set(char *field, int *stage, void *value,
    struct d_ocp_qp *qp);
\end{verbatim}
where {\tt filed} can be one of {\tt A, B, b, Q, S, R, q, r, idxb, lb, ub, Jbx, idxbx, lbx, ubx, Jbu, idxbu, lbu, ubu, C, D, lg, ug, Zl, Zu, zl, zu, idxs, lls, lus}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \chapter{Tree OCP QP}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\bibliographystyle{plain}
%\bibliography{biblio}             % bib file to produce the bibliography

\begin{thebibliography}{1}

\bibitem{Frison2018}
G.~Frison, D.~Kouzoupis, T.~Sartor, A.~Zanelli, and M.~Diehl.
\newblock {BLASFEO}: Basic linear algebra subroutines for embedded
  optimization.
\newblock {\em ACM Transactions on Mathematical Software (TOMS)}, 2018.
\newblock (accepted).

\end{thebibliography}

\end{document}


\section{Efficiency Analysis}

Here we try to analyze the speedup of Parareal analytically, and then through
scalability studies conducted on the supercomputer Prince, here at NYU.

\subsection{Theoretical Results}

We try to directly estimate the speedup of the Naive OpenMP implementation. We
denote our speedup $S$ by: (\cite{fieldstalk} slide 17)
\begin{equation*}
  S = \frac{\text{Time taken by fine solver}}{\text{Parareal time}}
\end{equation*}
Let the time taken by the fine and coarse solvers respectively be denoted by
$T_f$ and $T_g$. Furthermore, suppose we have the optimal amount of processors
$P$, such that $\Delta t = T/P$, where $T$ is the time to integrate up to.

Considering this, each step parareal makes a predictor and corrector
computation. The predictor is just a run of the coarse solver, costing $PT_g$.
The corrector has two parts, the fine and coarse portion. The fine portion is
parallelized optimally, and therefore costs just $T_f$, instead of $PT_f$.  In
addition, the coarse portion of the corrector takes advantage of the
\textit{first same as last} property, and doesn't have to be counted sepreately.
Recall, also, before the parareal iteration, we make an initial guess using one
coarse solve, $PT_g$. Therefore, for a parareal with $k$ iterations it would
have speedup:
\[
  S = \frac{PT_f}{PT_g + k(PT_g + T_f)}
  = \frac{1}{\frac{T_g}{T_f} + k(\frac{T_g}{T_f} + \frac{1}{P})}
  = \frac{1}{\frac{T_g}{T_f}(1+k) + \frac{k}{P}}
\]
Notice, under the limit:
\[
  \lim_{P \to \infty} S = \frac{1}{\frac{T_g}{T_f}(1+k)} = \frac{T_f}{T_g(1+k)}
\]
Supposing we have the idealized case of $k = 1$, then we would find that this
would result in speedup $\frac{T_f}{2T_g}$, which, given that $T_g << T_f$,
could be significant. However, in practice, $k$ has to be taken to be large
enough so that $S$ isn't too great. This is one of the first indicators we have
of why $T_g << T_f$ must be true.

\subsection{Scalability}

Since this algorithm is designed to take our numerical ODE techniques to a high
performance computing context, we would like to perform the standard scalability
tests using this algorithm, measuring how it scales to massively parallel
hardware.

All tests are performed on a single Prince node, having requested 28 processors.
We would be worried about other processes running on this node if this problem
was memory bound, however since the fine computation is performed in place and
the coarse operator has few points, the computation is compute bound.

\subsubsection{Strong Scaling Study}

A strong scaling study consists of fixing a total problem size, and increasing
the number of processors necessary. See figure \ref{fig:strong_scaling} for our
performed analysis.
\begin{figure}[!htb]
  \centering
  \includegraphics[width=.8\textwidth]{./resources/strong_scaling}
  \caption{This is a strong scaling study performed on the ODE $u' = u, u(0) =
  1$ integrating on time scale $[0, 4]$. Here we divided our time scale into
  pieces of size $4/P$, and then ran Parareal restricting the number of
  processors. Notice how the time taken doesn't improve from $14 \to
  28$.}\label{fig:strong_scaling}
\end{figure}
Note that figure \ref{fig:strong_scaling} presents a very interesting, and
dismal, phenomena. Notice how from processors $14 \to 27$ the speedup recieved
is negligable from the previous. Why does this occur? Recall that the optimal
number of processors for parareal iteration is the number of coarse steps, so
that we can process all of the $\fine$ integrators in one step. However,
supposing we have one less than optimal, the entire compute time is bounded by
that one thread that has to process two $\fine$ integrators. This is
troublesome.
In fact, suppose we desire to cut our time domain $[0, T]$ into $2N$ pieces.
Then any computation with number of processors $P$ taking value $N \to 2N-1$
will have the same computation time, theoretically.

Notice, however, that the general speedup does follow the theoretical linear
speedup we hope to see with $P$ processors, which is great.

\subsubsection{Weak Scaling Study}

The weak scaling study examines how the runtime increases as we increase the
amount of processors, working on a similar sized problem. See figure
\ref{fig:weak_scaling} for the results.
\begin{figure}[!htb]
  \centering
  \includegraphics[width=.8\textwidth]{./resources/weak_scaling}
  \caption{}\label{fig:weak_scaling}
\end{figure}
We see that the Weak Scaling of parareal is alright, seeming to stay roughly
constant, or atleast sublinear as we increase the number of processors doing
equal amounts of work. Note, this can only be true if $T_g << T_f$, otherwise we
will be bounded by Amadahl's law. When we increase the amount of processors
working, what happens is that the fine portion is computed in the same amount of
time, but the amount of points in general increase. This implies that the serial
portion of the computation will increase linearly in the number of points, so if
the course computation is not very cheap with respect to the fine computation,
we will lose the weak scaling performance.