%! TEX root = LST.tex
% vim: tw=50
% 17/02/2024 09AM

\begin{flashcard}[proof-first-order-defn]
\begin{definition*}[Proof (in first-order logic)]
  \glssymboldefn{ssynentails}{$\vdash$}{$\vdash$}
  \glsnoundefn{fproof}{proof}{proofs}
  \cloze{Let $S$ be a set of \glspl{form}, and $p$ a
  \gls{form}. A \emph{proof of $p$ from $S$} is a
  finite sequence $t_1, \ldots, t_n$ of
  \glspl{form} such that $t_n = p$ and for every
  $i$, we have one of:
  \begin{itemize}
    \item $t_i \in S$ or $t_i$ is an axiom.
    \item $\exists j, k < i$ with $t_k = (t_j
      \pimpl t_i)$.
    \item $\exists j < i$ with $t_i = (\pforall x)
      t_j$, $x \in \FV(t_j)$ and for all $k < j$ if
      $t_k \in S$ then $x$ does not occur \gls{free}
      in $t_k$.
  \end{itemize}
  In this case we say \emph{$S$ proves $p$} and
  write $S \vdash p$.

  (If $S$ is a \gls{theory} and $p$ is a
  \gls{sent} then we say \emph{$p$ is a theorem of
  $S$}).}
\end{definition*}
\end{flashcard}

\begin{remark*}
  Suppose we allow $\emptyset$ as a structure.
  Note that $(\pforall x)\pnot (x = x)$ is
  satisfied in $\emptyset$, whereas $\false$ is
  not. So $\{(\pforall x)\pnot (x = x)\} \not
  \ssementails \false$. However, $\{(\pforall
  x)\pnot(x =x)\} \ssynentails$:
  \begin{align*}
    &(\pforall x)\pnot (x = x)
    &&\text{(premise)} \\
    &((\pforall x)\pnot(x =x)) \pimpl (\pnot(x = x))
    &&\text{(A6)} \\
    &\pnot (x = x)
    &&\text{(\gls{MP})} \\
    &(\pforall x)(x = x)
    &&\text{(A4)} \\
    &(x = x)
    &&\text{(A6 + \gls{MP})} \\
    &\false
    &&\text{(\gls{MP})}
  \end{align*}
\end{remark*}

\begin{example*}
  $\{x = y\} \ssynentails (y = x)$.
  \begin{align*}
    &(\pforall x)(\pforall y)((x = y) \pimpl ((x =
    z) \pimpl (y = z))
    &&\text{(A5)} \\
    &(x = y) \pimpl ((x = z) \pimpl (y = z))
    &&\text{((A6 + \gls{MP}) twice)} \\
    &x = y
    &&\text{(premise)} \\
    &(x = z) \pimpl (y = z)
    &&\text{(\gls{MP})} \\
    &(\pforall z)((x = z) \pimpl (y = z))
    &&\text{(Gen)} \\
    &((\pforall z)((x = z) \pimpl (y = z))) \pimpl
    ((x = x) \pimpl (y = z))
    &&\text{(A6)} \\
    &(x = x) \pimpl (y = x)
    &&\text{(\gls{MP})} \\
    &(\pforall x)(x = x)
    &&\text{(A4)} \\
    &(x = x)
    &&\text{(A6 + \gls{MP})} \\
    &(y = x)
    &&\text{(\gls{MP})}
  \end{align*}
\end{example*}

\begin{flashcard}[first-order-deduction-thm]
\prompt{(In first order logic)}
\begin{proposition}[Deduction Theorem]
  \label{fo_ded_thm}
  \cloze{Let $S$ be a set of \glspl{form} and $p, q$ be
  \glspl{form}. Then $S \ssynentails (p \pimpl q)$
  if and only if $S \cup \{p\} \ssynentails q$.}
\end{proposition}

\begin{proof}
  \phantom{}
  \cloze{\begin{enumerate}[$\Rightarrow$]
    \item[$\Rightarrow$] Write down a \gls{fproof} of $p
      \pimpl q$ from $S$ and add the lines:
      \begin{align*}
        &p
        &&\text{(premise)} \\
        &q
        &&\text{(\gls{MP})}
      \end{align*}
      to get a \gls{fproof} of $q$ from $S \cup \{p\}$.
    \item[$\Leftarrow$] Let $t_1, \ldots, t_n = q$
      be a proof of $q$ from $S \cup \{p\}$. We
      proe $S \ssynentails (p \pimpl t_i)$ by
      induction on $i$.

      Our induction hypothesis at step $i$ will
      be: for $j < i$, $S \ssynentails (p \pimpl
      t_j)$ such that if the \gls{fproof} of $t_j$ from
      $S \cup \{p\}$ did not use any premise in
      which a \gls{var} $x$ occurs \gls{free}, then the
      \gls{fproof} of $(p \pimpl t_j)$ from $S$
      does not use any premise in which a
      \gls{var} $x$ occurs \gls{free}.

      To see $S \ssynentails (p \pimpl t_i)$, we
      consider cases:
      \begin{itemize}
        \item If $t_i \in S$ or $t_i$ an axiom,
          write
          \begin{align*}
            &t_i
            &&\text{(premise or axiom)} \\
            &t_i \pimpl (p \pimpl t_i)
            &&\text{(A1)} \\
            &p \pimpl t_i
            &&\text{(\gls{MP})}
          \end{align*}
          is a \gls{fproof} of $(p \pimpl t_i)$
          from $S$.
        \item If $t_i = p$, then write down a
          proof of $p \pimpl p$ from $\emptyset$.
        \item If $\exists j, k < i$ with $t_k =
          (t_j \pimpl t_i)$ then write
          \begin{align*}
            &(p \pimpl (t_j \pimpl t_i)) \pimpl
            ((p \pimpl t_j) \pimpl (p \pimpl t_i))
            &&\text{(A2)} \\
            &p \pimpl (t_j \pimpl t_i)
            &&\text{(by induction hypothesis)} \\
            &(p \pimpl t_j) \pimpl (p \pimpl t_i)
            &&\text{(\gls{MP})} \\
            &p \pimpl t_j
            &&\text{(by induction hypothesis)} \\
            &p \pimpl t_i
            &&\text{(\gls{MP})}
          \end{align*}
        \item Finally, if $\exists j < i$ such
          that $x \in \FV(t_j)$ and $t_i =
          (\pforall x) t_j$, then the \gls{fproof}
          of $t_j$ from $S \cup \{p\}$ did not use
          any premise in which $x$ occurs
          \gls{free}.

          If $x$ occurs \gls{free} in
          $p$, then $p$ did not occur in proof of
          $t_j$ from $S \cup \{p\}$, i.e. it is a
          proof of $t_j$ from $S$. By (Gen), $S
          \ssynentails (\pforall x) t_j$, i.e. $S
          \ssynentails (\pforall x) t_j$, i.e. $S
          \ssynentails t_i$. Add the lines
          \begin{align*}
            &t_i \pimpl (p \pimpl t_i)
            &&\text{(A1)} \\
            &p \pimpl t_i
            &&\text{(\gls{MP})}
          \end{align*}
          If $x$ does not occur \gls{free} in $p$,
          then we have a \gls{fproof} of $p \pimpl
          t_j$ from $S$ by induction hypothesis,
          which does not use any premise in which
          $x$ occurs \gls{free}. So we can add:
          \begin{align*}
            &(\pforall x)(p \pimpl t_j)
            &&\text{(Gen)} \\
            &((\pforall x)(p \pimpl t_j)) \pimpl
            (p \pimpl (\pforall x) t_j)
            &&\text{(A7)} \\
            &\ub{p \pimpl (\pforall x) t_j}_{= p
            \pimpl t_i}
            &&\text{(\gls{MP})}
          \end{align*}
      \end{itemize}
      In all cases the condition about
      \gls{free} \glspl{var} remains true.
      \qedhere
  \end{enumerate}}
\end{proof}
\end{flashcard}

\textbf{Aim:} $S \ssynentails p$ if and only if $S
\ssementails p$.

\begin{flashcard}[soundness-first-order-thm]
\prompt{(In first-order logic)}
\begin{proposition}[Soundness Theorem]
  \label{fo_soundness}
  \cloze{Let $S$ be a set of \glspl{form} and $p$ be a
  \gls{form}. If $S \ssynentails p$ then $S
  \fsementails p$.}
\end{proposition}

\begin{proof}[Proof (non-examinable)]
  \cloze{Write down a proof $t_1, \ldots, t_n$ of $p$
  from $S$. Verify thet $S \fsementails t_i$ by an
  easy induction.}
\end{proof}
\end{flashcard}

\begin{flashcard}[model-existence-first-order-thm]
\begin{theorem}[Model Existence Lemma]
  \label{fo_model_existence}
  \cloze{Let $S$ be a \gls{cons} \gls{theory} in the
  \gls{folang} $L = L(\pOmega, \pPi, \arity)$
  (i.e. $S \not\ssynentails \false$). Then $S$ has
  a \gls{fmodel}.}
\end{theorem}
\end{flashcard}

Assuming this, we have:

\begin{flashcard}[adequacy-first-order-thm]
\begin{corollary}[Adequacy Theorem]
  \cloze{Let $S$ be a set of \glspl{form} and $p$ be a
  \gls{form}. If $S \fsementails p$, ten $S
  \fsementails p$.}
\end{corollary}

\begin{proof}[Proof (non-examinable)]
  \cloze{Without loss of generality $S$ is a \gls{theory}
  and $p$ is a \gls{sent} (by using the definition
  of $\fsementails$ in the case where we have
  \glspl{form} rather than \glspl{sent}). Since $S
  \ssementails p$, $S \cup \{\pnot p\}
  \ssementails \false$. So by
  \cref{fo_model_existence}, $S \cup \{\pnot p\}
  \ssynentails \false$. So $S \ssynentails \pnot
  \pnot p$ (by \cref{fo_ded_thm}), so $S
  \ssynentails p$ by (A3) and (\gls{MP}).}
\end{proof}
\end{flashcard}

\begin{flashcard}[godel-completeness-first-order-thm]
\begin{theorem}[G\"odel's Completeness Theorem for
  first-order logic]
  \cloze{If $S$ is a set of \glspl{form} and $p$ is a
  \gls{form}, then $S \ssynentails p$ if and only
  if $S \fsementails p$.}
\end{theorem}
\end{flashcard}

\glsadjdefn{closed}{closed}{\gls{term}}
\textbf{Idea of proof of
\cref{fo_model_existence}:} We build a
\gls{fmodel} from $L = L(\pOmega, \pPi)$. Let $A$
be the set of \emph{closed} \glspl{term} in $L$, i.e.
\glspl{term} with no \glspl{var}. For example $S =
\text{\gls{theory} of fields}$ (in \gls{folang} of
commutative rings with $1$). $A$ consists of
\[ 1 + 1, (((1 + 0) + 0) + 1), 1 \cdot 1, 1 \cdot 0,
\ldots, 1 + (-1), \ldots \]
We will define the \gls{interpf} of $+$ (and other
symbols similarly) using:
\[ (1 + 1) +_A (1 + 0) = (1 + 1) + (1 + 0) \]
