\documentclass{article}

\usepackage{amssymb}
\usepackage{amsthm}
\usepackage[UKenglish]{babel}
\usepackage{enumitem}
\usepackage{fancyhdr}
\usepackage[margin=1in]{geometry}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\usepackage{mathtools}
\usepackage{tikz-cd}
\usepackage{csquotes}

\newcommand{\F}{\mathbb{F}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\A}{\mathbb{A}}
\renewcommand{\P}{\mathbb{P}}

\newcommand{\val}[1]{\left. #1 \right\rvert}
\newcommand{\rb}[1]{\left( #1 \right)}
\renewcommand{\sb}[1]{\left[ #1 \right]}
\newcommand{\cb}[1]{\left\{ #1 \right\}}
\newcommand{\ab}[1]{\left\langle #1 \right\rangle}
\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}
\newcommand{\two}[2]{\begin{pmatrix} #1 \\ #2 \end{pmatrix}}
\newcommand{\three}[3]{\begin{pmatrix} #1 & #2 & #3 \end{pmatrix}}

\newcommand{\notb}[1]{\rb{\neg #1}}
\newcommand{\orb}[2]{\rb{#1 \lor #2}}
\newcommand{\andb}[2]{\rb{#1 \land #2}}
\newcommand{\impb}[2]{\rb{#1 \rightarrow #2}}
\newcommand{\iffb}[2]{\rb{#1 \leftrightarrow #2}}
\newcommand{\fab}[1]{\rb{\forall #1}}
\newcommand{\teb}[1]{\rb{\exists #1}}

\theoremstyle{definition}\newtheorem{definition}{Definition}[subsection]
\theoremstyle{definition}\newtheorem{remark}[definition]{Remark}
\theoremstyle{definition}\newtheorem*{example}{Example}
\theoremstyle{definition}\newtheorem*{note}{Note}
\newtheorem{proposition}[definition]{Proposition}
\newtheorem{lemma}[definition]{Lemma}
\newtheorem{theorem}[definition]{Theorem}
\newtheorem{corollary}[definition]{Corollary}

\pagestyle{fancy}
\lhead{M3P65 Mathematical Logic}
\rhead{Autumn 2018}

\title{M3P65 Mathematical Logic}
\author{Lectured by Prof David Evans \\ Typeset by David Kurniadi Angdinata}
\date{Autumn 2018}

\setcounter{section}{-1}

\begin{document}

\maketitle

\vfill

\tableofcontents

\pagebreak

\marginpar{Lecture 1 \\ Thursday \\ 04/10/18}

\section{Introduction}

The module is concerned with some of the foundational issues of mathematics, namely propositional logic, predicate logic, and set theory. These topics have applications to other areas of mathematics. Formal logic has applications via model theory and ZFC provides an essential toolkit for handling infinite objects.

In propositional logic, we look at the way simple propositions can be built into more complicated ones using connectives and make precise how the truth or falsity of the component statements influences the truth or falsity of the compound statement. This is done using truth tables and can be useful for testing the validity of various forms of reasoning. It provides a way of analysing deductions of the form 'If the following statements are true, ..., then so is ...'. A completely symbolic process of deduction and describe the formal deduction system for propositional calculus. The propositional formulas are regarded as strings of symbols and we give rules for deducing a new formula from a given collection of formulas. We want these deduction rules to have the property that anything that could be deduced using truth tables (so by considering truth or falsity of the various statements), can be deduced in this formal way, and vice versa. This is the soundness and completeness of our formal system.

In predicate logic, we analyse mathematics using quantifiers. We introduce the notion of a first-order structure, which is general enough to include many of the algebraic objects you come across in mathematics, such as groups, rings, and vector spaces. We then have to be precise about the formulas which make statements about these structures, and give a precise definition of what it means for a particular formula to be true in a structure. This is quite intricate, and the clever part is in getting the definitions right, but it corresponds to ordinary mathematical usage. Once this is done, we set up a formal deduction system for predicate logic. This parallels what we did for propositional logic, but is much harder. Nevertheless, the end result is the same. The formulas which are produced by our formal deduction system are precisely the formulas which are true in all first-order structures. This is Gödel's completeness theorem.

Set theory provides the basic foundations and the language in which most of modern mathematics can be expressed, as well as the means for discussing the various notions of sizes of infinity. For example, although the set of natural numbers, the set of integers and the set of real numbers are all infinite, there is a very natural sense in which the first two have the same size, whereas the third is strictly bigger. This is expressed properly in the notion of cardinality. To avoid paradoxes and inconsistencies, we have to be careful about what collections of objects we allow to be called sets. This is done by the Zermelo-Fraenkel axioms, which essentially tell us how we are allowed to create new sets out of old ones. Of course, having laid down these quite rigid rules, we have to show that they are sufficiently flexible to allow us to talk about everyday objects of mathematics. There are also situations in mathematics where an extra axiom is needed, the Axiom of Choice. For example without this axiom, we cannot show that every vector space has a basis. But it also has some slightly counterintuitive consequences, and we shall also look at some of these.

The lecture notes should be fairly self-contained, but the following books might also be of use. You might find that the notation which they use differs form that used in the lectures. You will be able to find various lecture notes on the internet. Some will be good, others not so good.

\begin{enumerate}
\item P Johnstone, Notes on logic and set theory, 1987
\item P J Cameron, Sets, logic and categories, 1999
\item A G Hamilton, Logic for mathematicians, 1988
\item R Cori and D Lascar, Mathematical logic: a course with exercises parts I and II, 2001
\item K Hrbaček and T Jech, Introduction to set theory 3rd edition, 1999
\end{enumerate}

$ 1 $ is very concise, but covers a surprising amount. $ 2 $ is friendlier, but skips some of the harder material. $ 4 $ is quite comprehensive and also available in the original French. $ 3 $ is useful for the logic part and $ 5 $ is a very nice introduction to set theory.

\section{Propositional logic}

Let $ p $ be 'Mr Jones is happy' and $ q $ be 'Mrs Jones is unhappy'. Then 'If Mr Jones is happy, then Mrs Jones is unhappy and if Mrs Jones is unhappy then Mr Jones is unhappy, so Mr Jones is unhappy' is
$$ \impb{\andb{\impb{p}{q}}{\impb{q}{\notb{p}}}}{\notb{p}}. $$

\subsection{Propositional formulas}

The following are \textbf{truth table rules}.

\begin{definition}
\label{def:1.1.1}
A \textbf{proposition} is a statement that is either \textbf{True} $ \rb{T} $ or \textbf{False} $ \rb{F} $, which can be represented symbolically as \textbf{propositional variables}
$$ p, \quad q, \quad \dots \qquad p_1, \quad p_2, \quad \dots. $$
We combine basic propositions into others using \textbf{connectives}, which are one of
\begin{itemize}
\item \textbf{negation 'not'} $ \rb{\neg p} $, which has value $ F $ if $ p $ has value $ T $ and has value $ T $ if $ p $ has value $ F $,
\item \textbf{conjunction 'and'} $ \rb{p \land q} $, which has value $ T $ iff $ p $ and $ q $ both have value $ T $,
\item \textbf{disjunction 'or'} $ \rb{p \lor q} $, which has value $ T $ iff at least one of $ p $ and $ q $ has value $ T $,
\item \textbf{implication 'implies'} $ \rb{p \rightarrow q} $, which has value $ F $ iff $ p $ has value $ T $ and $ q $ has value $ F $, and
\item \textbf{biconditional 'iff'} $ \rb{p \leftrightarrow q} $, which has value $ T $ iff $ p $ and $ q $ has the same value.
\end{itemize}
This can be represented in the following \textbf{truth table}.
\begin{center}
\begin{tabular}{|c|c|c|c|c|c|}
\hline
$ p $ & $ q $ & $ \rb{p \land q} $ & $ \rb{p \lor q} $ & $ \rb{p \rightarrow q} $ & $ \rb{p \leftrightarrow q} $ \\
\hline
$ T $ & $ T $ & $ T $ & $ T $ & $ T $ & $ T $ \\
\hline
$ T $ & $ F $ & $ F $ & $ T $ & $ F $ & $ F $ \\
\hline
$ F $ & $ T $ & $ F $ & $ T $ & $ T $ & $ F $ \\
\hline
$ F $ & $ F $ & $ F $ & $ F $ & $ T $ & $ T $ \\
\hline
\end{tabular}
\end{center}
\end{definition}

\begin{definition}
\label{def:1.1.2}
A \textbf{propositional formula} is obtained in the following way.
\begin{enumerate}
\item Any propositional variable is a formula.
\item If $ \phi $ and $ \psi $ are formulas, then so are
$$ \notb{\phi}, \qquad \andb{\phi}{\psi}, \qquad \orb{\phi}{\psi}, \qquad \impb{\phi}{\psi}, \qquad \iffb{\phi}{\psi}. $$
\item Any formula arises in this way.
\end{enumerate}
\end{definition}

\begin{example}
Some formulas are
$$ p_1, \qquad p_2, \qquad \notb{p_1}, \qquad \impb{p_1}{\notb{p_2}}, \qquad \impb{\impb{p_1}{\notb{p_2}}}{p_2}. $$
Some not formulas are
$$ p_1 \land p_2 \quad \rb{\text{missing brackets}}, \qquad )( \neg p_1 \quad \rb{\text{not well-formed}}. $$
\end{example}

Because of the brackets, every formula is either a propositional variable or is built from shorter formulas in a unique way. Arguments are often proved by induction on length of the formula, or the number of connectives in the formula.

\begin{definition}
\hfill
\begin{enumerate}
\item Let $ n \in \N $. A \textbf{truth function} of $ n $ variables is a function $ f : \cb{T, F}^n \to \cb{T, F} $, where $ \cb{T, F}^n = \cb{\rb{x_1, \dots, x_n} \mid x_i \in \cb{T, F}} $.
\item Suppose $ \phi $ is a formula whose variables are amongst $ p_1, \dots, p_n $. We obtain a truth function $ F_\phi : \cb{T, F}^n \to \cb{T, F} $ whose value at $ \rb{x_1, \dots, x_n} $ is the truth value of $ \phi $ when $ p_i $ has value $ x_i $ for $ i = 1, \dots, n $, computed using the rules in \ref{def:1.1.1}. $ F_\phi $ is the \textbf{truth function of $ \phi$}.
\end{enumerate}
\end{definition}

\begin{example}
$ \phi : \impb{\impb{p}{\notb{q}}}{p} $ has the following truth table.
\begin{center}
\begin{tabular}{|c|c|c|c|c|}
\hline
$ p $ & $ q $ & $ \notb{q} $ & $ \impb{p}{\notb{q}} $ & $ \phi $ \\
\hline
$ T $ & $ T $ & $ F $ & $ F $ & $ T $ \\
\hline
$ T $ & $ F $ & $ T $ & $ T $ & $ T $ \\
\hline
$ F $ & $ T $ & $ F $ & $ T $ & $ F $ \\
\hline
$ F $ & $ F $ & $ T $ & $ T $ & $ F $ \\
\hline
\end{tabular}
\end{center}
So for example $ F_\phi\rb{T, F} = T $. This can also be written in a \textbf{condensed form} as follows.
\begin{center}
\begin{tabular}{cccccccccccc}
$ ( $ & $ ( $ & $ p $ & $ \rightarrow $ & $ ( $ & $ \neg $ & $ q $ & $ ) $ & $ ) $ & $ \rightarrow $ & $ p $ & $ ) $ \\
& & $ T $ & $ F $ & & $ F $ & $ T $ & & & $ T $ & $ T $ & \\
& & $ T $ & $ T $ & & $ T $ & $ F $ & & & $ T $ & $ T $ & \\
& & $ F $ & $ T $ & & $ F $ & $ T $ & & & $ F $ & $ F $ & \\
& & $ F $ & $ T $ & & $ T $ & $ F $ & & & $ F $ & $ F $ & \\
\end{tabular}
\end{center}
\end{example}

\marginpar{Lecture 2 \\ Friday \\ 05/10/18}

\begin{example}
The truth function of $ \impb{\andb{\impb{p}{q}}{\impb{q}{\notb{p}}}}{\notb{p}} $ is always $ T $.
\end{example}

\begin{definition}
\hfill
\begin{enumerate}
\item A propositional formula is a \textbf{tautology} if its truth function $ F_\phi $ always has value $ T $.
\item Say that formulas $ \phi, \psi $ are \textbf{logically equivalent} (LE) if they have the same truth function, that is $ F_\phi = F_\psi $.
\end{enumerate}
\end{definition}

\begin{remark}
\hfill
\label{rem:1.1.5}
\begin{enumerate}
\item $ \phi, \psi $ are LE iff $ \iffb{\phi}{\psi} $ is a tautology.
\item Suppose $ \phi $ is a formula with variables $ p_1, \dots, p_n $ and $ \phi_1, \dots, \phi_n $ are formulas with variables $ q_1, \dots q_r $. For each $ i \le n $ substitute $ \phi_i $ in place of $ p_i $ in $ \phi $. Then the result is a formula $ \theta $, and if $ \phi $ is a tautology, then so is $ \theta $.
\end{enumerate}
\end{remark}

\begin{example}
Check $ \impb{\impb{\notb{p_2}}{\notb{p_1}}}{\impb{p_1}{p_2}} $ is a tautology. So by \ref{rem:1.1.5}(2), if $ \phi_1 $ and $ \phi_2 $ are any formulas, then $ \impb{\impb{\notb{\phi_2}}{\notb{\phi_1}}}{\impb{\phi_1}{\phi_2}} $ is a tautology.
\end{example}

\begin{proof}[Proof of \ref{rem:1.1.5}]
\hfill
\begin{enumerate}
\item Easy.
\item Prove $ F_\phi\rb{p_1, \dots, p_r} = F_\phi\rb{F_{\phi_1}\rb{q_1, \dots, q_r}, \dots, F_{\phi_n}\rb{q_1, \dots, q_r}} $ by induction on the number of connectives in $ \phi $.
\end{enumerate}
\end{proof}

\begin{example}
The following are LE formulas.
\begin{enumerate}
\item $ \andb{p_1}{\andb{p_2}{p_3}} $ is LE to $ \andb{\andb{p_1}{p_2}}{p_3} $.
\item $ \orb{p_1}{\orb{p_2}{p_3}} $ is LE to $ \orb{\orb{p_1}{p_2}}{p_3} $.
\item $ \orb{p_1}{\andb{p_2}{p_3}} $ is LE to $ \andb{\orb{p_1}{p_2}}{\orb{p_1}{p_3}} $.
\item $ \andb{p_1}{\orb{p_2}{p_3}} $ is LE to $ \orb{\andb{p_1}{p_2}}{\andb{p_1}{p_3}} $.
\item $ \notb{\notb{p_1}} $ is LE to $ p_1 $.
\item $ \notb{\andb{p_1}{p_2}} $ is LE to $ \orb{\notb{p_1}}{\notb{p_2}} $.
\item $ \notb{\orb{p_1}{p_2}} $ is LE to $ \andb{\notb{p_1}}{\notb{p_2}} $.
\end{enumerate}
By the first two examples, we usually omit brackets as $ \rb{p_1 \land p_2 \land p_3} $ and $ \rb{p_1 \lor p_2 \lor p_3} $ without ambiguity.
\end{example}

\begin{note}
By \ref{rem:1.1.5} we obtain, for formulas $ \phi, \psi, \chi $, $ \andb{\phi}{\andb{\psi}{\chi}} $ is LE to $ \andb{\andb{\phi}{\psi}}{\chi} $, etc.
\end{note}

\begin{lemma}
There are $ 2^{2^n} $ truth functions of $ n $ variables.
\end{lemma}

\begin{proof}
A truth function is a function $ F : \cb{T, F}^n \to \cb{T, F} $. $ \abs{\cb{T, F}^n} = 2^n $ and for each $ \bar{x} \in \cb{T, F}^n $, $ F\rb{\bar{x}} \in \cb{T, F} $. Hence the result.
\end{proof}

\begin{definition}
A set of connectives is \textbf{adequate} if for every $ n \ge 1 $, every truth function of $ n $ variables is the truth function of some formula which involves only connectives from the set, and variables $ p_1, \dots, p_n $.
\end{definition}

\begin{theorem}
\label{thm:1.1.9}
The set $ \cb{\neg, \land, \lor} $ is adequate.
\end{theorem}

\begin{proof}
Let $ G : \cb{T, F}^n \to \cb{T, F} $.
\begin{enumerate}
\item If $ G\rb{\bar{v}} = F $ for all $ \bar{v} \in \cb{T, F}^n $, let $ \phi = \andb{p_1}{\notb{p_1}} $. Then $ F_\phi = G $.
\item Otherwise list the $ \bar{v} \in \cb{T, F}^n $ with $ G\rb{\bar{v}} = T $ as $ \bar{v_1}, \dots, \bar{v_r} $. Write $ \bar{v_i} = \rb{v_{i1}, \dots, v_{in}} $, where each $ v_{ij} \in \cb{T, F} $. Define
$$ q_{ij} = \begin{cases} p_j & v_{ij} = T \\ \notb{p_j} & v_{ij} = F \end{cases}, \qquad \psi_i = \rb{q_{i1} \land \dots \land q_{in}}, \qquad \theta = \rb{\psi_1 \lor \dots \lor \psi_r}. $$
Hence
\begin{align*}
F_\theta\rb{\bar{v}} = T
& \iff \exists i \le r, \ F_{\psi_i}\rb{\bar{v}} = T \\
& \iff \exists i \le r, \ \forall j \le n, \ q_{ij} = T \\
& \iff \exists i \le r, \ \forall j \le n, \ p_j = v_{ij} \\
& \iff \exists i \le r, \ \bar{v} = \bar{v_i} \\
& \iff G\rb{\bar{v}} = T.
\end{align*}
Thus $ F_\theta = G $.
\end{enumerate}
As $ \phi $ and $ \theta $ were constructed using only $ \neg, \land, \lor $, \ref{thm:1.1.9} follows.
\end{proof}

A formula $ \theta $ as in case 2 is said to be in \textbf{disjunctive normal form} (DNF).

\begin{corollary}
Suppose $ \chi $ is a formula whose truth function is not always $ F $. Then $ \chi $ is LE to a formula in DNF.
\end{corollary}

\begin{proof}
Take $ G = F_\chi $ and apply case 2 of \ref{thm:1.1.9}.
\end{proof}

\begin{example}
Let $ \chi $ be $ \impb{\impb{p_1}{p_2}}{\notb{p_2}} $. Then $ F_\chi\rb{\bar{v}} = T $ iff $ \bar{v} = \rb{T, F}, \rb{F, F} $. Thus its DNF is
$$ \orb{\andb{p_1}{\notb{p_2}}}{\andb{\notb{p_1}}{\notb{p_2}}}. $$
\end{example}

\begin{corollary}
The following sets of connectives are adequate.
\begin{enumerate}
\item $ \cb{\neg, \lor} $.
\item $ \cb{\neg, \land} $.
\item $ \cb{\neg, \rightarrow} $.
\end{enumerate}
\end{corollary}

\begin{proof}
\hfill
\begin{enumerate}
\item By \ref{thm:1.1.9} it is sufficient to show that we can express $ \land $ using $ \neg, \lor $, which holds since $ \andb{p_1}{p_2} $ is LE to $ \notb{\orb{\notb{p_1}}{\notb{p_2}}} $.
\item By \ref{thm:1.1.9} it is sufficient to show that we can express $ \lor $ using $ \neg, \land $, which holds since $ \orb{p_1}{p_2} $ is LE to $ \notb{\andb{\notb{p_1}}{\notb{p_2}}} $.
\item By \ref{thm:1.1.9} it is sufficient to show that we can express $ \lor $ using $ \neg, \rightarrow $, which holds since $ \orb{p_1}{p_2} $ is LE to $ \impb{\notb{p}}{q} $.
\end{enumerate}
\end{proof}

\marginpar{Lecture 3 \\ Monday \\ 08/10/18}

\begin{example}
The following are not adequate.
\begin{enumerate}
\item $ \cb{\land, \lor} $. If $ \phi $ is built using $ \land, \lor $, then $ F_\phi\rb{T, \dots, T} = T $. Proof by induction on number of connectives.
\item $ \cb{\neg, \leftrightarrow} $. (TODO Exercise: proof)
\end{enumerate}
\end{example}

\begin{example}
The NOR connective $ \downarrow $ has the following truth table.
\begin{center}
\begin{tabular}{|c|c|c|}
\hline
$ p $ & $ q $ & $ \rb{p \downarrow q} $ \\
\hline
$ T $ & $ T $ & $ F $ \\
\hline
$ T $ & $ F $ & $ F $ \\
\hline
$ F $ & $ T $ & $ F $ \\
\hline
$ F $ & $ F $ & $ T $ \\
\hline
\end{tabular}
\end{center}
$ \rb{p \downarrow q} $ is LE to $ \andb{\notb{p}}{\notb{q}} $. $ \cb{\downarrow} $ is adequate. $ \rb{p \downarrow p} $ is LE to $ \notb{p} $ and $ \rb{\rb{p \downarrow p} \downarrow \rb{q \downarrow q}} $ is LE to $ \andb{p}{q} $. So as $ \cb{\neg, \lor} $ is adequate, so is $ \cb{\downarrow} $.
\end{example}

\subsection{A formal system for propositional logic}

Idea is to try to generate all tautologies from basic assumptions, or axioms, using appropriate deduction rules. A very general definition is the following.

\begin{definition}
\hfill
\begin{enumerate}
\item A \textbf{formal deduction system} $ \Sigma $ has the following ingredients.
\begin{enumerate}
\item a non-zero \textbf{alphabet} $ A $ of symbols,
\item a non-empty subset $ \mathcal{F} $ of the set of all finite sequences, or \textbf{strings}, of elements of $ A $, the \textbf{formulas} of $ \Sigma $,
\item a subset $ \mathcal{A} \subseteq \mathcal{F} $ called the \textbf{axioms} of $ \Sigma $, and
\item a collection of \textbf{deduction rules}.
\end{enumerate}
\item A \textbf{proof} in $ \Sigma $ is a finite sequence of formulas in $ \mathcal{F} $ $ \phi_1, \dots, \phi_n $ such that each $ \phi_i $ is either an axiom in $ \mathcal{A} $ or is obtained from $ \phi_1, \dots, \phi_{i - 1} $ using one of the deduction rules. The last, or any, formula in a proof is a \textbf{theorem} of $ \Sigma $.
\end{enumerate}
Write $ \vdash_\Sigma \phi $ for '$ \phi $ is a theorem of $ \Sigma $'.
\end{definition}

\begin{remark}
\hfill
\begin{enumerate}
\item If $ \phi \in \mathcal{A} $, then $ \vdash_\Sigma \phi $.
\item We should have an algorithm to test whether a string is a formula and whether it is an axiom. Then a computer can systematically generate all possible proofs in $ \Sigma $, and check whether something is a proof. Say $ \Sigma $ is \textbf{recursive} in this case.
\end{enumerate}
\end{remark}

The main example is the following.

\begin{definition}
\label{def:1.2.3}
The formal system \textbf{$ L $} for propositional logic has the following.
\begin{enumerate}
\item Alphabet. Alphabets are
\begin{enumerate}
\item variables $ p_1, p_2, \dots $,
\item connectives $ \neg, \rightarrow $, and
\item punctuation $ ( $, $ ) $.
\end{enumerate}
\item Formulas. \textbf{$ L $-formulas} are defined in \ref{def:1.1.2} for $ \neg, \rightarrow $ by
\begin{enumerate}
\item any variable $ p_i $ is a formula,
\item if $ \phi, \psi $ are formulas so are $ \notb{\phi}, \impb{\phi}{\psi} $, and
\item any formula arises in this way.
\end{enumerate}
\item Axioms. Suppose $ \phi, \psi, \chi $ are $ L $-formulas, then the axioms of $ L $ are
\begin{enumerate}[label=(A\arabic*)]
\item $ \impb{\phi}{\impb{\psi}{\phi}} $,
\item $ \impb{\impb{\phi}{\impb{\psi}{\chi}}}{\impb{\impb{\phi}{\psi}}{\impb{\phi}{\chi}}} $, and
\item $ \impb{\impb{\notb{\psi}}{\notb{\phi}}}{\impb{\phi}{\psi}} $.
\end{enumerate}
\item Deduction rules. \textbf{Modus Ponens} (MP), from formulas $ \phi, \impb{\phi}{\psi} $, deduce $ \psi $.
\end{enumerate}
\end{definition}

\begin{example}
Suppose $ \phi $ is an $ L $-formula. Then $ \vdash_L \impb{\phi}{\phi} $. Here is a proof in $ L $.
\begin{align*}
1 \qquad & \impb{\phi}{\impb{\impb{\phi}{\phi}}{\phi}} & \rb{\text{A1}} \\
2 \qquad & \impb{\impb{\phi}{\impb{\impb{\phi}{\phi}}{\phi}}}{\impb{\impb{\phi}{\impb{\phi}{\phi}}}{\impb{\phi}{\phi}}} & \rb{\text{A2}} \\
3 \qquad & \impb{\impb{\phi}{\impb{\phi}{\phi}}}{\impb{\phi}{\phi}} & \rb{1, 2, \text{MP}} \\
4 \qquad & \impb{\phi}{\impb{\phi}{\phi}} & \rb{\text{A1}} \\
5 \qquad & \impb{\phi}{\phi} & \rb{3, 4, \text{MP}}
\end{align*}
\end{example}

\marginpar{Lecture 4 \\ Thursday \\ 11/10/18}

\begin{definition}
Suppose $ \Gamma $ is a set of $ L $-formulas. A \textbf{deduction from $ \Gamma $} is a finite sequence of $ L $-formulas $ \phi_1, \dots, \phi_n $ such that each $ \phi_i $ is either an axiom, a formula in $ \Gamma $, or is obtained from previous formulas $ \phi_1, \dots, \phi_{i - 1} $ using the deduction rule MP. Write $ \Gamma \vdash_L \phi $ if there is a deduction from $ \Gamma $ ending in $ \phi $. Say $ \phi $ is a \textbf{consequence} of $ \Gamma $. So $ \emptyset \vdash_L \phi $ is the same as $ \vdash_L \phi $.
\end{definition}

\begin{theorem}[Deduction theorem]
\label{thm:1.2.5}
Suppose $ \Gamma $ is a set of $ L $-formulas and $ \phi, \psi $ are $ L $-formulas. Suppose $ \Gamma \cup \cb{\phi} \vdash_L \psi $. Then $ \Gamma \vdash_L \impb{\phi}{\psi} $.
\end{theorem}

\begin{corollary}[Hypothetical syllogism]
Suppose $ \phi, \psi, \chi $ are $ L $-formulas and $ \vdash_L \impb{\phi}{\psi} $ and $ \vdash_L \impb{\psi}{\chi} $. Then $ \vdash_L \impb{\phi}{\chi} $.
\end{corollary}

\begin{proof}
Use deduction theorem with $ \Gamma = \emptyset $. Show $ \cb{\phi} \vdash_L \chi $. Here is a deduction of $ \chi $ from $ \phi $.
\begin{align*}
1 \qquad & \impb{\phi}{\psi} & \rb{\text{theorem of } L} \\
2 \qquad & \impb{\psi}{\chi} & \rb{\text{theorem of } L} \\
3 \qquad & \phi & \rb{\text{assumption}} \\
4 \qquad & \psi & \rb{1, 3, \text{MP}} \\
5 \qquad & \chi & \rb{2, 4, \text{MP}}
\end{align*}
Thus $ \cb{\phi} \vdash_L \chi $. By deduction theorem, $ \emptyset \vdash_L \impb{\phi}{\chi} $, that is $ \vdash_L \impb{\phi}{\chi} $.
\end{proof}

\begin{proposition}
\label{prop:1.2.7}
Suppose $ \phi, \psi $ are $ L $-formulas. Then
\begin{enumerate}
\item $ \vdash_L \impb{\notb{\psi}}{\impb{\psi}{\phi}} $,
\item $ \cb{\notb{\psi}, \psi} \vdash_L \phi $, and
\item $ \vdash_L \impb{\impb{\notb{\phi}}{\phi}}{\phi} $.
\end{enumerate}
\end{proposition}

\begin{proof}
\hfill
\begin{enumerate}
\item Problem sheet 1.
\item By 1 and MP twice.
\item Suppose $ \chi $ is any formula. Then $ \cb{\notb{\phi}, \impb{\notb{\phi}}{\phi}} \vdash_L \chi $ by 2 and MP. Let $ \alpha $ be any axiom and let $ \chi $ be $ \notb{\alpha} $. Apply deduction theorem to get $ \cb{\impb{\notb{\phi}}{\phi}} \vdash_L \impb{\notb{\phi}}{\notb{\alpha}} $. Using A3 and MP we get $ \cb{\impb{\notb{\phi}}{\phi}} \vdash_L \impb{\alpha}{\phi} $. As $ \alpha $ is an axiom we get from MP $ \cb{\impb{\notb{\phi}}{\phi}} \vdash_L \phi $. Now use deduction theorem to obtain $ \vdash_L \impb{\impb{\notb{\phi}}{\phi}}{\phi} $.
\end{enumerate}
\end{proof}

\begin{proof}[Proof of \ref{thm:1.2.5}]
Suppose $ \Gamma \cup \cb{\phi} \vdash_L \psi $ using a deduction of length $ n $. Show by induction on $ n $ that $ \Gamma \vdash_L \impb{\phi}{\psi} $.
\begin{enumerate}
\item Base step is $ n = 1 $. In this case $ \psi $ is either an axiom or in $ \Gamma $ or is $ \phi $. In the first two cases $ \Gamma \vdash_L \psi $ is a one line deduction. Using the A1 axiom $ \impb{\psi}{\impb{\phi}{\psi}} $ and MP we obtain $ \Gamma \vdash_L \impb{\phi}{\psi} $. If $ \phi $ is $ \psi $ we have $ \Gamma \vdash_L \impb{\phi}{\phi} $ by \ref{def:1.2.3}. This finishes the base case.
\item Inductive step. In our deduction of $ \psi $ from $ \Gamma \cup \cb{\phi} $ either $ \psi $ is an axiom, or in $ \Gamma $, or is $ \phi $, or $ \psi $ is obtained from earlier steps using MP. In the first three cases we argue as in the base case to get $ \Gamma \vdash_L \impb{\phi}{\psi} $. In the last case there are formulas $ \chi $, $ \impb{\chi}{\psi} $ earlier in the deduction. We use the inductive hypothesis to get $ \Gamma \vdash_L \impb{\phi}{\chi} $ and $ \Gamma \vdash_L \impb{\phi}{\impb{\chi}{\psi}} $. We have the A2 axiom $ \impb{\impb{\phi}{\impb{\psi}{\chi}}}{\impb{\impb{\phi}{\psi}}{\impb{\phi}{\chi}}} $. This A2 axiom and MP twice we obtain $ \Gamma \vdash_L \impb{\phi}{\chi} $ as required, completing the inductive step.
\end{enumerate}
\end{proof}

\marginpar{Lecture 5 \\ Friday \\ 12/10/18}

\subsection{Soundness and completeness of $ L $}

\begin{theorem}[Soundness theorem of $ L $]
\label{thm:1.3.1}
Suppose $ \phi $ is a theorem of $ L $. Then $ \phi $ is a tautology.
\end{theorem}

\begin{definition}
A \textbf{propositional valuation} $ v $ is an assignment of truth values to the propositional variables $ p_1, p_2, \dots $. So $ v\rb{p_i} \in \cb{T, F} $ for $ i \in \N $.
\end{definition}

\begin{note}
Using the truth table rules, this assigns a truth value $ v\rb{\phi} \in \cb{T, F} $ to every $ L $-formula $ \phi $ satisfying $ v\rb{\notb{\phi}} \ne v\rb{\phi} $, etc. See problem sheet 2, question 3(b).
\end{note}

By induction on the length of a proof of $ \phi $ it is enough to show
\begin{enumerate}
\item every axiom is a tautology, and
\item MP preserves tautologies, that is if $ \psi, \impb{\psi}{\chi} $ are tautologies, so is $ \chi $.
\end{enumerate}

\begin{proof}[Proof of \ref{thm:1.3.1}]
\hfill
\begin{enumerate}
\item Use truth tables, or argue as follows. For A2, suppose for a contradiction there is a valuation $ v $ with $ v\rb{\impb{\impb{\phi}{\impb{\psi}{\chi}}}{\impb{\impb{\phi}{\psi}}{\impb{\phi}{\chi}}}} = F $. Then
\begin{equation}
\label{eq:1}
v\rb{\impb{\phi}{\impb{\psi}{\chi}}} = T,
\end{equation}
and
\begin{equation}
\label{eq:2}
v\rb{\impb{\impb{\phi}{\psi}}{\impb{\phi}{\chi}}} = F.
\end{equation}
By $ \rb{\ref{eq:2}} $, $ v\rb{\impb{\phi}{\psi}} = T $ and $ v\rb{\impb{\phi}{\chi}} = F $. So by the latter, $ v\rb{\phi} = T $ and $ v\rb{\chi} = F $. By the former, $ v\rb{\psi} = T $. This contradicts $ \rb{\ref{eq:1}} $. (TODO Exercise: for A1 and A3)
\item If $ v $ is a valuation and $ v\rb{\psi} = T $ and $ v\rb{\impb{\psi}{\chi}} = T $ then $ v\rb{\chi} = T $.
\end{enumerate}
\end{proof}

\begin{theorem}[Generalisation of Soundness theorem of $ L $]
Suppose $ \Gamma $ is a set of formulas and $ \phi $ a formula with $ \Gamma \vdash_L \phi $. Suppose $ v $ is a valuation with $ v\rb{\psi} = T $ for all $ \psi \in \Gamma $. Then $ v\rb{\phi} = T $.
\end{theorem}

\begin{proof}
Same proof. (TODO Exercise)
\end{proof}

\begin{theorem}[Completeness theorem of $ L $]
\label{thm:1.3.4}
Suppose $ \phi $ is a tautology, that is $ v\rb{\phi} = T $ for every valuation $ v $. Then $ \vdash_L \phi $.
\end{theorem}

The following are steps in the proof.
\begin{enumerate}
\item If $ v\rb{\phi} = T $ for all valuations $ v $, want to show $ \vdash_L \phi $.
\item Try to prove a generalisation. Suppose that for every $ v $ with $ v\rb{\Gamma} = T $, that is $ v\rb{\psi} = T $ for all $ \psi \in \Gamma $, we have $ v\rb{\phi} = T $. Then $ \Gamma \vdash_L \phi $.
\item Equivalently, if $ \Gamma \not\vdash_L \phi $, show there is a valuation $ v $ with $ v\rb{\Gamma} = T $ and $ v\rb{\phi} = F $.
\end{enumerate}

\begin{definition}
A set $ \Gamma $ of $ L $-formulas is \textbf{consistent} if there is no $ L $-formula $ \phi $ such that $ \Gamma \vdash_L \phi $ and $ \Gamma \vdash_L \notb{\phi} $.
\end{definition}

\begin{proposition}
\label{prop:1.3.7}
Suppose $ \Gamma $ is a consistent set of $ L $-formulas and $ \Gamma \not\vdash_L \phi $. Then $ \Gamma \cup \cb{\notb{\phi}} $ is consistent.
\end{proposition}

\begin{proof}
Suppose not. So there is some formula $ \psi $ with
\begin{equation}
\label{eq:3}
\Gamma \cup \cb{\notb{\phi}} \vdash_L \psi,
\end{equation}
and
\begin{equation}
\label{eq:4}
\Gamma \cup \cb{\notb{\phi}} \vdash_L \notb{\psi}.
\end{equation}
Apply deduction theorem to $ \rb{\ref{eq:4}} $, $ \Gamma \vdash_L \impb{\notb{\phi}}{\notb{\psi}} $. By A3 and MP we obtain $ \Gamma \vdash_L \impb{\psi}{\phi} $. By this, $ \rb{\ref{eq:3}} $, and MP, $ \Gamma \cup \cb{\notb{\phi}} \vdash_L \phi $. By deduction theorem, $ \Gamma \vdash_L \impb{\notb{\phi}}{\phi} $. By \ref{prop:1.2.7}(3), $ \vdash_L \impb{\impb{\notb{\phi}}{\phi}}{\phi} $. So by these and MP, $ \Gamma \vdash_L \phi $. This contradicts $ \Gamma \not\vdash_L \phi $.
\end{proof}

\begin{proposition}[Lindenbaum's lemma]
\label{prop:1.3.8}
Suppose $ \Gamma $ is a consistent set of $ L $-formulas. Then there is a consistent set of formulas $ \Gamma^* \supseteq \Gamma $ such that for every $ \phi $ either $ \Gamma^* \vdash_L \phi $ or $ \Gamma^* \vdash_L \notb{\phi} $.
\end{proposition}

Sometimes say $ \Gamma^* $ is \textbf{complete}.

\begin{proof}
The set of $ L $-formulas is countable, so we can list the $ L $-formulas as $ \phi_0, \phi_1, \dots $. It is countable because the alphabet $ \neg, \rightarrow, ), (, p_1, p_2, \dots $ is countable, and the formulas are finite sequences from this alphabet. Define inductively sets of formulas $ \Gamma_0 \subseteq \Gamma_1 \subseteq \dots $ where $ \Gamma_0 = \Gamma $ and $ \Gamma^* = \cup_{i \in \N} \Gamma_i $. Suppose $ \Gamma_n $ has been defined. If $ \Gamma_n \vdash_L \phi_n $ then let $ \Gamma_{n + 1} = \Gamma_n $. If $ \Gamma_n \not\vdash_L \phi_n $ then let $ \Gamma_{n + 1} = \Gamma_n \cup \cb{\notb{\phi_n}} $. An easy induction using \ref{prop:1.3.7} shows that each $ \Gamma_i $ is consistent. Claim that $ \Gamma^* $ is consistent. If $ \Gamma^* \vdash_L \phi $ and $ \Gamma^* \vdash_L \notb{\phi} $ then as deductions are finite sequence of formulas, $ \Gamma_n \vdash_L \phi $ and $ \Gamma_n \vdash_L \notb{\phi} $ for some $ n \in \N $, a contradiction. Let $ \phi $ be any formula. So $ \phi = \phi_n $ for some $ n $. If $ \Gamma^* \not\vdash_L \phi $ then $ \Gamma_n \not\vdash_L \phi $. So by construction $ \Gamma_{n + 1} \vdash_L \notb{\phi} $ as $ \notb{\phi} = \notb{\phi_n} \in \Gamma_{n + 1} $. Thus $ \Gamma^* \vdash_L \notb{\phi} $.
\end{proof}

\marginpar{Lecture 6 \\ Monday \\ 15/10/18}

\begin{lemma}
\label{lem:1.3.9}
Let $ \Gamma^* $ be as above. Then there is a valuation $ v $ such that for every $ L $-formula $ \phi $, $ v\rb{\phi} = T $ iff $ \Gamma^* \vdash_L \phi $.
\end{lemma}

\begin{corollary}
\label{cor:1.3.10}
Suppose $ \Delta $ is a set of $ L $-formulas which is consistent and $ \Delta \not\vdash_L \phi $. Then there is a valuation $ v $ with $ v\rb{\Delta} = T $ and $ v\rb{\phi} = F $.
\end{corollary}

\begin{proof}
Let $ \Gamma = \Delta \cup \cb{\notb{\phi}} $. By \ref{prop:1.3.7}, $ \Gamma $ is consistent. By \ref{prop:1.3.8} there is $ \Gamma^* \supseteq \Gamma $ which is still consistent and such that for every $ \chi $ either $ \Gamma^* \vdash_L \chi $ or $ \Gamma^* \vdash_L \notb{\chi} $. By \ref{lem:1.3.9} there is a valuation $ v $ with $ v\rb{\Gamma^*} = T $. In particular $ v\rb{\Delta} = T $ and $ v\rb{\notb{\phi}} = T $. So $ v\rb{\phi} = F $.
\end{proof}

\begin{proof}[Proof of \ref{thm:1.3.4}]
Suppose $ \not\vdash_L \phi $. Apply \ref{cor:1.3.10} with $ \Delta = \emptyset $. This is consistent due to the Soundness theorem. There is a valuation $ v $ with $ v\rb{\phi} = F $.
\end{proof}

\begin{proof}[Proof of \ref{lem:1.3.9}]
Let $ \Gamma^* $ be a consistent set of $ L $-formulas such that for every $ L $-formula $ \phi $ either $ \Gamma^* \vdash_L \phi $ or $ \Gamma^* \vdash_L \notb{\phi} $. Want a valuation $ v $ with $ v\rb{\phi} = T $ for all $ \phi \in \Gamma^* $, that is $ v\rb{\phi} = T $ iff $ \Gamma^* \vdash_L \phi $. Note that for each variable $ p_i $ either $ \Gamma^* \vdash_L p_i $ or $ \Gamma^* \vdash_L \notb{p_i} $. So let $ v $ be the valuation with $ v\rb{p_i} = T $ iff $ \Gamma^* \vdash_L p_i $. Prove by induction on the length of $ \phi $ that $ v\rb{\phi} = T $ iff $ \Gamma^* \vdash_L \phi $. Base case for $ \phi $ is just a propositional variable. This case is by definition of $ v $. Inductive step is the following.
\begin{enumerate}
\item Assume that $ \phi $ is $ \notb{\psi} $.
\begin{itemize}
\item[$ \implies $] $ v\rb{\phi} = T $ gives $ v\rb{\psi} = F $ since $ v $ is a valuation. By inductive hypothesis, $ \Gamma^* \not\vdash_L \psi $. Then Lindenbaum property gives $ \Gamma^* \vdash_L \notb{\psi} $, that is $ \Gamma^* \vdash_L \phi $.
\item[$ \impliedby $] Conversely suppose $ \Gamma^* \vdash_L \phi $. By consistency $ \Gamma^* \not\vdash_L \psi $. By inductive hypothesis, $ v\rb{\psi} = F $. As $ v $ is a valuation we obtain $ v\rb{\notb{\psi}} = T $, that is $ v\rb{\phi} = T $.
\end{itemize}
\item Assume that $ \phi $ is $ \impb{\psi}{\chi} $.
\begin{itemize}
\item[$ \impliedby $] Suppose $ v\rb{\phi} = F $. Show $ \Gamma^* \not\vdash_L \phi $. Then $ v\rb{\psi} = T $ and $ v\rb{\chi} = F $. By inductive hypothesis, $ \Gamma^* \vdash_L \psi $ and $ \Gamma^* \not\vdash_L \chi $. If $ \Gamma^* \vdash_L \phi $ then using $ \Gamma^* \vdash_L \psi $ and MP we get $ \Gamma^* \vdash_L \chi $, which is a contradiction. So $ \Gamma^* \not\vdash_L \phi $.
\item[$ \implies $] Suppose $ \Gamma^* \not\vdash_L \phi $, that is $ \Gamma^* \not\vdash_L \impb{\psi}{\chi} $. Then $ \Gamma^* \not\vdash_L \chi $ as $ \vdash_L \impb{\chi}{\impb{\psi}{\chi}} $. Also $ \Gamma^* \not\vdash_L \notb{\psi} $ as $ \vdash_L \impb{\notb{\psi}}{\impb{\psi}{\chi}} $ by \ref{prop:1.2.7}(1). By inductive hypothesis, $ v\rb{\chi} = F $ and $ v\rb{\notb{\psi}} = F $ so $ v\rb{\psi} = T $. Thus $ v\rb{\phi} = F $, which does the inductive step.
\end{itemize}
\end{enumerate}
\end{proof}

\begin{corollary}
\label{cor:1.3.12}
Suppose $ \Delta $ is a set of $ L $-formulas and $ \phi $ is an $ L $-formula. Then
\begin{enumerate}
\item $ \Delta $ is consistent iff there is a valuation $ v $ with $ v\rb{\Delta} = T $, and
\item $ \Delta \vdash_L \phi $ iff for every valuation $ v $ with $ v\rb{\Delta} = T $ we have $ v\rb{\phi} = T $.
\end{enumerate}
\end{corollary}

\begin{proof}
TODO Exercise: deduce these from the preliminaries to Completeness theorem - warning that in 2 do not assume that $ \Delta $ is consistent.
\end{proof}

\begin{theorem}[Compactness theorem for $ L $]
Suppose $ \Delta $ is a set of $ L $-formulas. The following are equivalent.
\begin{enumerate}
\item There is a valuation $ v $ with $ v\rb{\Delta} = T $.
\item For every finite subset $ \Delta_0 \subseteq \Delta $ there is a valuation $ w $ with $ w\rb{\Delta_0} = T $.
\end{enumerate}
\end{theorem}

\begin{proof}
By \ref{cor:1.3.12} 1 holds iff $ \Delta $ is consistent. Similarly 2 holds iff every finite subset of $ \Delta $ is consistent. But if $ \Delta \vdash_L \psi $ and $ \Delta \vdash_L \notb{\psi} $ then as deductions are finite and therefore only involve finitely many formulas in $ \Delta $, for some finite $ \Delta_0 \subseteq \Delta $, $ \Delta_0 \vdash_L \psi $ and $ \Delta_0 \vdash_L \notb{\psi} $.
\end{proof}

Let $ P $ be the set of sequences of $ \cb{T, F} $, that is the set of functions $ f : \N \to \cb{T, F} $. Topologise with basic open sets. For $ a_1, \dots, a_n \in \cb{T, F} $ consider $ O\rb{a_1, \dots, a_n} $, all sequences starting $ a_1, \dots, a_n $. (TODO Exercise: use Compactness theorem to prove $ P $ is compact)

\marginpar{Lecture 7 \\ Thursday \\ 18/10/18}

Lecture 7 is a problem class.

\marginpar{Lecture 8 \\ Friday \\ 19/10/18}

\section{Predicate logic}

Predicate logic is first-order logic. Plan is the following.
\begin{enumerate}
\item Introduce the mathematical objects, first-order structures.
\item Introduce the formulas, first-order languages.
\item Describe a formal system.
\item Show that its theorems are precisely the formulas true in all structures. This is Gödel's completeness theorem.
\end{enumerate}
$ 1 $ and $ 2 $ are semantics while $ 3 $ and $ 4 $ are syntax.

\subsection{Structures}

\begin{definition}
Suppose $ A $ is a set and $ n \ge 1 $ and $ n \in \N $. An \textbf{$ n $-ary relation} on $ A $ is a subset $ \bar{R} \subseteq A^n = \cb{\rb{a_1, \dots, a_n} \mid a_i \in A} $ of $ n $-tuples. An \textbf{$ n $-ary function} on $ A $ is a function $ \bar{f} : A^n \to A $.
\end{definition}

\begin{example}
\hfill
\begin{enumerate}
\item Ordering $ \le $ on $ \R $ is a binary relation on $ \R $.
\item $ + $ on $ \C $ is a binary function on $ \C $.
\item Even integers as a subset of $ \Z $ is a unary relation on $ \Z $.
\end{enumerate}
\end{example}

If $ \bar{R} \subseteq A^n $ is an $ n $-ary relation and $ a_1, \dots, a_n \in A $, write $ \bar{R}\rb{a_1, \dots, a_n} $ to mean $ \rb{a_1, \dots, a_n} \in \bar{R} $.

\begin{definition}
A \textbf{first-order structure} $ \mathcal{A} $ consists of
\begin{enumerate}
\item a non-empty set $ A $, the \textbf{domain} of $ \mathcal{A} $,
\item a set $ \cb{\bar{R_i} \mid i \in I} $ of relations on $ A $ for $ \bar{R_i} \subseteq A^{n_i} $,
\item a set $ \cb{\bar{f_j} \mid j \in J} $ of functions on $ A $ for $ \bar{f_j} : A^{m_j} \to A $, and
\item a set $ \cb{\bar{c_k} \mid k \in K} $ of \textbf{constants}, just elements of $ A $.
\end{enumerate}
The sets $ I, J, K $ are indexing sets and can be empty. Usually subsets of $ \N $. The information $ \rb{n_i \mid i \in I} $, $ \rb{m_j \mid j \in J} $, and the set $ K $ is called the \textbf{signature} of $ \mathcal{A} $. Might denote the structure by
$$ \mathcal{A} = \ab{A; \rb{\bar{R_i} \mid i \in I}, \rb{\bar{f_j} \mid j \in J}, \rb{\bar{c_k} \mid k \in K}}. $$
\end{definition}

\begin{example}
\hfill
\begin{enumerate}
\item Orderings on $ A = \N, \Z, \Q, \R $ where
$$ I = \cb{1}, \qquad J = \emptyset, \qquad K = \emptyset, \qquad \bar{R_1}\rb{a_1, a_2} \iff a_1 < a_2. $$
\item Groups.
\begin{enumerate}
\item $ \bar{R} $, the binary relation for equality,
\item $ \bar{m} $, the binary function for multiplication,
\item $ \bar{i} $, the unary function for inversion, and
\item $ \bar{e} $, the constant for identity element.
\end{enumerate}
\item Rings.
\begin{enumerate}
\item $ \bar{R} $, the binary relation for equality,
\item $ \bar{m} $, the binary function for multiplication,
\item $ \bar{a} $, the binary function for addition,
\item $ \bar{n} $, the binary function for negation,
\item $ \bar{0} $, the constant for zero, and
\item $ \bar{1} $, the constant for one.
\end{enumerate}
\item Graphs.
\begin{enumerate}
\item $ \bar{R} $, the binary relation for equality, and
\item $ \bar{E} $, the binary relation for adjacency.
\end{enumerate}
\end{enumerate}
\end{example}

\subsection{First-order languages}

\begin{definition}
\label{def:2.2.1}
A \textbf{first-order language} $ \mathcal{L} $ has an alphabet of symbols of the following types.
\begin{enumerate}
\item Variables $ x_0, x_1, \dots $.
\item Punctuation $ ( $, $ ) $, $ , $.
\item Connectives $ \neg $, $ \rightarrow $.
\item \textbf{Quantifier} $ \forall $.
\item Relation symbols $ R_i $ for $ i \in I $.
\item Function symbols $ f_j $ for $ j \in J $.
\item Constant symbols $ c_k $ for $ k \in K $.
\end{enumerate}
Here $ I, J, K $ are indexing sets and could have $ J, K = \emptyset $. Each $ R_i $ comes equipped with an \textbf{arity} $ n_i $. Each $ f_j $ comes equipped with an arity $ m_j $. The information $ \rb{n_i \mid i \in I} $, $ \rb{m_j \mid j \in J} $, $ K $ is called the signature of $ \mathcal{L} $. A first-order structure $ \mathcal{A} $ with the same signature as $ \mathcal{L} $ is referred to as an $ \mathcal{L} $-structure.
\end{definition}

\begin{definition}
A \textbf{term} of $ \mathcal{L} $ is defined as follows.
\begin{enumerate}
\item Any variable is a term.
\item Any constant symbol is a term.
\item If $ f $ is an $ m $-ary function symbol of $ \mathcal{L} $ and $ t_1, \dots, t_m $ are terms, then $ f\rb{t_1, \dots, t_m} $ is also a term.
\item Any term arises in this way.
\end{enumerate}
\end{definition}

\begin{example}
Suppose $ \mathcal{L} $ has a binary function symbol $ f $ and constant symbols $ c_1, c_2 $. Some terms are
$$ c_1, \qquad c_2, \qquad x_1, \qquad f\rb{c_1, x_1}, \qquad f\rb{f\rb{c_1, x_2}, c_2}, \qquad f\rb{x_1, f\rb{f\rb{c_1, x_2}, c_2}}. $$
Some not terms are
$$ ffx_1 \quad \rb{\text{not well-formed}}. $$
\end{example}

\marginpar{Lecture 9 \\ Monday \\ 22/10/18}

\begin{definition}
\hfill
\begin{enumerate}
\item An \textbf{atomic formula} of $ \mathcal{L} $ is of the form $ R\rb{t_1, \dots, t_n} $ where $ R $ is an $ n $-ary relation symbol of $ \mathcal{L} $ and $ t_1, \dots, t_n $ are terms.
\item The \textbf{formulas} of $ \mathcal{L} $ are defined as follows.
\begin{enumerate}
\item Any atomic formula is a formula.
\item If $ \phi, \psi $ are $ \mathcal{L} $-formulas then $ \notb{\phi} $, $ \impb{\phi}{\psi} $, $ \fab{x}\phi $ are $ \mathcal{L} $-formulas, where $ x $ is any variable.
\item Every $ \mathcal{L} $-formula arises in this way.
\end{enumerate}
\end{enumerate}
\end{definition}

\begin{example}
Suppose $ \mathcal{L} $ has a binary function symbol $ f $, a unary relation symbol $ P $, a binary relation symbol $ R $, and constant symbols $ c_1, c_2 $. Some terms are
$$ x_1, \qquad c_1, \qquad f\rb{x_1, c_1}, \qquad f\rb{f\rb{x_1, c_1}, x_2}. $$
Some atomic formulas are
$$ P\rb{x_1}, \qquad R\rb{f\rb{x_1, c_1}, x_2}. $$
Some formulas are
$$ \fab{x_1}\impb{R\rb{f\rb{x_1, c_1}, x_2}}{P\rb{x_1}}. $$
\end{example}

\begin{definition}
Suppose $ \phi, \psi $ are $ \mathcal{L} $-formulas. $ \teb{x}\phi $ means $ \notb{\fab{x}\notb{\phi}} $. $ \orb{\phi}{\psi} $ means $ \impb{\notb{\phi}}{\psi} $, etc as in propositional logic.
\end{definition}

\begin{definition}
Suppose $ \mathcal{L} $ is a first-order language with relation symbols $ R_i $ of arity $ n_i $ for $ i \in I $, function symbols $ f_j $ of arity $ m_j $ for $ j \in J $, and constant symbols $ c_k $ for $ k \in K $. An \textbf{$ \mathcal{L} $-structure} is a structure
$$ \mathcal{A} = \ab{A; \rb{\bar{R_i} \mid i \in I}, \rb{\bar{f_j} \mid j \in J}, \rb{\bar{c_k} \mid k \in K}} $$
of the same signature as $ \mathcal{L} $.
\end{definition}

There is a correspondence between the relation, function, and constant symbols of $ \mathcal{L} $ and the actual relations, functions, and constants in $ \mathcal{A} $, and the arities match up. This correspondence, or $ \mathcal{A} $, is called an \textbf{interpretation} of $ \mathcal{L} $.

\begin{definition}
With the same notation, suppose $ \mathcal{A} $ is an $ \mathcal{L} $-structure. A \textbf{valuation} in $ \mathcal{A} $ is a function $ v $ from the set of terms of $ \mathcal{L} $ to $ A $ satisfying
\begin{enumerate}
\item $ v\rb{c_k} = \bar{c_k} $, and
\item if $ t_1, \dots, t_m $ are terms of $ \mathcal{L} $ and $ f $ is an $ m $-ary function symbol then
$$ v\rb{f\rb{t_1, \dots, t_m}} = \bar{f}\rb{v\rb{t_1}, \dots, v\rb{t_m}}, $$
where $ \bar{f} $ is the interpretation of $ f $ in $ \mathcal{A} $.
\end{enumerate}
\end{definition}

\begin{lemma}
Suppose $ \mathcal{A} $ is an $ \mathcal{L} $-structure and $ a_0, a_1, \dots \in A $. Then there is a unique valuation $ v $ in $ \mathcal{A} $ with $ v\rb{x_l} = a_l $ for all $ l \in \N $, where the variables of $ \mathcal{L} $ are $ x_0, x_1, \dots $.
\end{lemma}

\begin{proof}
By induction on the length of terms. Show that if we let
\begin{enumerate}
\item $ v\rb{x_l} = a_l $ for all $ l \in \N $,
\item $ v\rb{c_k} = \bar{c_k} $ for all $ k \in K $, and
\item $ v\rb{f\rb{t_1, \dots, t_m}} = \bar{f}\rb{v\rb{t_1}, \dots, v\rb{t_m}} $,
\end{enumerate}
then $ v $ is a well-defined valuation.
\end{proof}

\begin{example}
Groups with signature of
\begin{enumerate}
\item binary relation symbol $ R $ for equality,
\item binary function symbol $ m $ for multiplication,
\item unary function symbol $ i $ for inversion, and
\item constant $ e $ for identity element.
\end{enumerate}
Let $ G $ be a group and $ g, h \in G $. Let $ v $ be a valuation with $ v\rb{x_0} = g $ and $ v\rb{x_1} = h $. Then
$$ v\rb{m\rb{m\rb{x_0, x_1}, i\rb{x_0}}} = \bar{m}\rb{v\rb{m\rb{x_0, x_1}}, v\rb{i\rb{x_0}}} = \bar{m}\rb{v\rb{x_0}, v\rb{x_1}}\bar{i}\rb{v\rb{x_0}} = ghg^{-1}. $$
\end{example}

\begin{definition}
Suppose $ \mathcal{A} $ is an $ \mathcal{L} $-structure and $ x_l $ is any variable. Suppose $ v, w $ are valuations in $ \mathcal{A} $. We say $ v, w $ are $ x_l $-equivalent if $ v\rb{x_m} = w\rb{x_m} $ whenever $ m \ne l $.
\end{definition}

\begin{definition}
\label{def:2.2.9}
Suppose $ \mathcal{A} $ is an $ \mathcal{L} $-structure and $ v $ is a valuation in $ \mathcal{A} $. Define, for an $ \mathcal{L} $-formula $ \phi $, what is meant by $ v $ \textbf{satisfies} $ \phi $ in $ \mathcal{A} $ by the following.
\begin{enumerate}
\item Suppose $ R $ is an $ n $-ary relation symbol and $ t_1, \dots, t_n $ are terms of $ \mathcal{L} $. Then $ v $ satisfies the atomic formula $ R\rb{t_1, \dots, t_n} $ iff $ \bar{R}\rb{v\rb{t_1}, \dots, v\rb{t_n}} $ holds in $ \mathcal{A} $.
\item Suppose $ \phi, \psi $ are $ \mathcal{L} $-formulas and we already know about valuations satisfying $ \phi, \psi $.
\begin{enumerate}
\item $ v $ satisfies $ \notb{\phi} $ in $ \mathcal{A} $ iff $ v $ does not satisfy $ \phi $ in $ \mathcal{A} $.
\item $ v $ satisfies $ \impb{\phi}{\psi} $ in $ \mathcal{A} $ iff it is not the case that $ v $ satisfies $ \phi $ in $ \mathcal{A} $ and $ v $ does not satisfy $ \psi $ in $ \mathcal{A} $.
\item $ v $ satisfies $ \fab{x_l}\phi $ in $ \mathcal{A} $ iff whenever $ w $ is a valuation in $ \mathcal{A} $ which is $ x_l $-equivalent to $ v $, then $ w $ satisfies $ \phi $ in $ \mathcal{A} $.
\end{enumerate}
\end{enumerate}
\end{definition}

\marginpar{Lecture 10 \\ Thursday \\ 25/10/18}

\begin{remark}
\ref{def:2.2.9} does not work if we allow empty structure.
\end{remark}

If $ v $ satisfies $ \phi $, write $ v\sb{\phi} = T $. If $ v $ does not satisfy $ \phi $, write $ v\sb{\phi} = F $. If every valuation in $ \mathcal{A} $ satisfies $ \phi $, say that $ \phi $ is \textbf{true} in $ \mathcal{A} $ or $ \mathcal{A} $ is a \textbf{model} of $ \phi $ and write $ \mathcal{A} \vDash \phi $. If $ \mathcal{A} \vDash \phi $ for every $ \mathcal{L} $-structure $ \mathcal{A} $, we say that $ \phi $ is \textbf{logically valid} and write $ \vDash \phi $. These are the analogues of tautologies in the propositional logic. Difference is in propositional logic there is an algorithm to decide whether a given formula is a tautology. There is no such algorithm to decide whether a given $ \mathcal{L} $-formula is logically valid or not, a consequence of Gödel's incompleteness theorem.

\begin{example}
\hfill
\begin{enumerate}
\item Suppose $ \mathcal{L} $ has a binary relation symbol $ R $. The $ \mathcal{L} $-formula $ \impb{R\rb{x_1, x_2}}{\impb{R\rb{x_2, x_3}}{R\rb{x_1, x_3}}} $ is true in $ \mathcal{A} = \ab{\N; <} $, where $ R $ is interpreted as $ < $. If not, there is a valuation $ v $ in $ \mathcal{A} $ such that $ v $ satisfies $ R\rb{x_1, x_2} $ or $ v $ does not satisfy $ \impb{R\rb{x_2, x_3}}{R\rb{x_1, x_3}} $. So $ v\sb{R\rb{x_2, x_3}} = T $ and $ v\sb{R\rb{x_1, x_3}} = F $. Let $ v\rb{x_i} = a_i \in \N $. So $ a_1 < a_2 $, $ a_2 < a_3 $, and $ a_1 \not< a_3 $. As $ < $ is transitive on $ \N $, this is a contradiction.
\item The same formula is not true in the structure $ \mathcal{B} $ with domain $ \N $ where we interpret $ R\rb{x_i, x_j} $ as $ x_i \ne x_j $. Take a valuation in $ \mathcal{B} $ with $ v\rb{x_1} = 1 = v\rb{x_3} $ and $ v\rb{x_2} = 2 $. $ v $ does not satisfy the formula in $ \mathcal{B} $.
\item Recall that $ \teb{x_1}\phi $ is an abbreviation for $ \notb{\fab{x_1}\notb{\phi}} $. Suppose $ \mathcal{A} $ is an $ \mathcal{L} $-structure and $ \phi $ an $ \mathcal{L} $-formula. Let $ v $ be a valuation in $ \mathcal{A} $. Then $ v $ satisfies $ \teb{x_1}\phi $ in $ \mathcal{A} $ iff there is a valuation $ w $ which is $ x_1 $-equivalent to $ v $ such that $ w $ satisfies $ \phi $. Suppose $ v $ satisfies $ \notb{\fab{x_1}\notb{\phi}} $. Using \ref{def:2.2.9} $ v $ does not satisfy $ \fab{x_1}\notb{\phi} $. So there is valuation $ w $ $ x_1 $-equivalent to $ v $ such that $ w $ does not satisfy $ \notb{\phi} $. Such a $ w $ satisfies $ \phi $. (TODO Exercise: converse)
\end{enumerate}
\end{example}

\begin{example}
$ \fab{x_1}\teb{x_2}R\rb{x_1, x_2} $ is true in $ \ab{\Z; <} $ and $ \ab{\N; <} $ but not in $ \ab{\N; >} $.
\end{example}

TODO Exercise: Suppose $ \phi $ is any $ \mathcal{L} $-formula. Then
\begin{enumerate}
\item $ \impb{\teb{x_1}\fab{x_2}\phi}{\fab{x_2}\teb{x_1}\phi} $ is logically valid, and
\item $ \impb{\fab{x_2}\teb{x_1}\phi}{\teb{x_1}\fab{x_2}\phi} $ is not necessarily logically valid.
\end{enumerate}

Consider the propositional formula $ \chi $ by $ \impb{p_1}{\impb{p_2}{p_1}} $. Suppose $ \mathcal{L} $ is a first-order language and $ \phi_1, \phi_2 $ are $ \mathcal{L} $-formulas. Substitute $ \phi_1 $ in place of $ p_1 $ and $ \phi_2 $ in place of $ p_2 $ in $ \chi $. We obtain an $ \mathcal{L} $-formula $ \theta $ by $ \impb{\phi_1}{\impb{\phi_2}{\phi_1}} $. Check that as $ \chi $ is a tautology $ \theta $ is logically valid. (TODO Exercise)

\begin{definition}
Suppose $ \chi $ is an $ \mathcal{L} $-formula involving propositional variables $ p_1, \dots, p_n $. Suppose $ \mathcal{L} $ is a first-order language and $ \phi_1, \dots, \phi_n $ are $ \mathcal{L} $-formulas. A \textbf{substitution instance} of $ \chi $ is obtained by replacing each $ p_i $ in $ \chi $ by $ \phi_i $ for $ i = 1, \dots, n $. Call the result $ \theta $.
\end{definition}

\begin{theorem}
\hfill
\begin{enumerate}
\item $ \theta $ is an $ \mathcal{L} $-formula, and
\item if $ \chi $ is a tautology then $ \theta $ is logically valid.
\end{enumerate}
\end{theorem}

\marginpar{Lecture 11 \\ Friday \\ 26/10/18}

\begin{proof}
Take an $ \mathcal{L} $-structure $ \mathcal{A} $ and a valuation $ v $ in $ \mathcal{A} $. Use this to define a propositional valuation $ w $ with $ w\rb{p_i} = v\sb{\phi_i} $ for $ i \le n $. Then prove by induction on the number of connectives in $ \chi $ that $ w\rb{\chi} = v\sb{\theta} $. In particular if $ \chi $ is a tautology, then $ v\sb{\theta} = T $. In the inductive step, consider $ \chi $ is $ \impb{\alpha}{\beta} $. So $ \theta $ is $ \impb{\theta_1}{\theta_2} $ where $ \theta_1 $ is obtained from $ \alpha $ and $ \theta_2 $ is obtained from $ \beta $. By inductive hypothesis $ w\rb{\alpha} = v\sb{\theta_1} $ and $ w\rb{\beta} = v\sb{\theta_2} $. So $ w\impb{\alpha}{\beta} = v\sb{\impb{\theta_1}{\theta_2}} $, etc. (TODO Exercise)
\end{proof}

\begin{note}
Not all logically valid formulas arise in this way.
\end{note}

\begin{example}
$ \impb{\teb{x_2}\fab{x_1}\phi}{\fab{x_1}\teb{x_2}\phi} $.
\end{example}

\subsection{Bound and free variables in formulas}

\begin{definition}
Suppose $ \phi, \psi $ are $ \mathcal{L} $-formulas and $ \fab{x_i}\phi $ occurs as a subformula of $ \psi $, that is $ \psi $ is $ \dots \fab{x_i}\phi \dots $. We say that $ \phi $ is the \textbf{scope} of that quantifier $ \fab{x_i} $ here in $ \psi $. An occurrence of a variable $ x_j $ in $ \psi $ is \textbf{bound} if it is in the scope of a quantifier $ \fab{x_j} $ in $ \psi $, or it is the $ x_j $ here. Otherwise it is a free occurrence of $ x_j $. Variables having a free occurrence in $ \psi $ are called \textbf{free} variables of $ \psi $. A formula with no free variables is called a \textbf{closed} formula or a \textbf{sentence} of $ \mathcal{L} $.
\end{definition}

\begin{example}
\hfill
\begin{enumerate}
\item Let $ \psi_1 $ be $ \impb{R_1\rb{x_1, x_2}}{\fab{x_3}R_2\rb{x_1, x_3}} $. Then $ x_1 $ and $ x_2 $ are free, and $ x_3 $ is bound with scope $ R_2\rb{x_1, x_3} $.
\item Let $ \psi_2 $ be $ \impb{\fab{x_1}R_1\rb{x_1, x_2}}{R_2\rb{x_1, x_2}} $. Then the first $ x_1 $ is bound with scope $ R_1\rb{x_1, x_2} $, and the second $ x_1 $ and $ x_2 $ are free. Compare with $ \fab{x_1}\impb{R_1\rb{x_1, x_2}}{R_2\rb{x_1, x_2}} $. Then $ x_1 $ is bound with scope $ \impb{R_1\rb{x_1, x_2}}{R_2\rb{x_1, x_2}} $, and $ x_2 $ is free.
\item Let $ \psi_3 $ be $ \impb{\teb{x_1}R_1\rb{x_1, x_2}}{\fab{x_2}R_2\rb{x_2, x_3}} $. Then $ x_1 $ and the second $ x_2 $ are bound with scope $ R_1\rb{x_1, x_2} $, and the first $ x_2 $ and $ x_3 $ are free.
\end{enumerate}
\end{example}

\begin{definition}
If $ \psi $ is an $ \mathcal{L} $-formula with free variables amongst $ x_1, \dots, x_n $, we might write $ \psi\rb{x_1, \dots, x_n} $ instead of $ \psi $. If $ t_1, \dots, t_n $ are terms, by $ \psi\rb{t_1, \dots, t_n} $ we mean the $ \mathcal{L} $-formula obtained by replacing each free occurrence of $ x_i $ in $ \psi $ by $ t_i $.
\end{definition}

\begin{example}
Let $ \psi\rb{x_1, x_2} $ be $ \impb{\fab{x_1}R\rb{x_1, x_2}}{\fab{x_3}R\rb{x_1, x_2, x_3}} $, $ t_1 $ be $ f_1\rb{x_1} $, and $ t_2 $ be $ f_2\rb{x_1, x_2} $. Then $ x_2 $ and the second $ x_1 $ are free. So $ \psi\rb{t_1, t_2} $ is
$$ \impb{\fab{x_1}R_1\rb{x_1, f_2\rb{x_1, x_2}}}{\fab{x_3}R_2\rb{f_1\rb{x_1}, f_2\rb{x_1, x_2}, x_3}}. $$
\end{example}

\begin{theorem}
\label{thm:2.3.3}
Suppose $ \phi $ is a closed $ \mathcal{L} $-formula and $ \mathcal{A} $ is an $ \mathcal{L} $-structure. Then either $ \mathcal{A} \vDash \phi $ or $ \mathcal{A} \vDash \notb{\phi} $. More generally, if $ \phi $ has free variables amongst $ x_1, \dots, x_n $ and $ v, w $ are valuations in $ \mathcal{A} $ with $ v\rb{x_i} = w\rb{x_i} $ for $ i = 1, \dots, n $, then $ v\sb{\phi} = T $ iff $ w\sb{\phi} = T $. Allow $ n = 0 $ here for no free variables.
\end{theorem}

\begin{proof}
Note that the first statement follows from the generalisation. If $ \phi $ has no free variables, then for any valuations $ v, w $ in $ \mathcal{A} $, they agree on the free variables of $ \phi $ so $ v\sb{\phi} = w\sb{\phi} $. Prove the generalisation by induction on the number of connectives and quantifiers in $ \phi $.
\begin{enumerate}
\item Base case. $ \phi $ is atomic, so $ \phi $ is $ R\rb{t_1, \dots, t_m} $ for $ t_j $ terms. The $ t_j $ only involve variables amongst $ x_1, \dots, x_n $. As $ v $ and $ w $ agree on these variables $ v\rb{t_j} = w\rb{t_j} $. So
$$ v\sb{R\rb{t_1, \dots, t_m}} = T \qquad \iff \qquad \bar{R}\rb{v\rb{t_1}, \dots, v\rb{t_m}} \qquad \iff \qquad w\sb{R\rb{t_1, \dots, t_m}} = T. $$
\item Inductive step. $ \phi $ is $ \notb{\psi} $, $ \impb{\psi}{\chi} $, or $ \fab{x_i}\psi $. (TODO Exercise: first two cases) Suppose $ \phi $ is $ \fab{x_i}\psi $. Suppose $ v\sb{\phi} = F $. By \ref{def:2.2.9} there is a valuation $ v' $ $ x_i $-equivalent to $ v $ with $ v'\sb{\psi} = F $. The free variables of $ \psi $ are amongst $ x_1, \dots, x_n, x_i $. Let $ w' $ be the valuation $ x_i $-equivalent to $ w $ with $ w'\rb{x_i} = v'\rb{x_i} $. Then $ v', w' $ agree on the free variables of $ \psi $. By inductive hypothesis $ v'\sb{\psi} = w'\sb{\psi} $ so $ w'\sb{\psi} = F $. As $ w' $ is $ x_i $-equivalent to $ w $ we obtain $ w\sb{\fab{x_i}\psi} = F $.
\end{enumerate}
\end{proof}

\marginpar{Lecture 12 \\ Monday \\ 29/10/18}

\begin{remark}
If $ \mathcal{A} $ is an $ \mathcal{L} $-structure and $ \psi\rb{x_1, \dots, x_n} $ an $ \mathcal{L} $-formula, whose free variables are amongst $ x_1, \dots, x_n $, and $ a_1, \dots, a_n \in A $ for domain $ A $ then we write $ \mathcal{A} \vDash \psi\rb{a_1, \dots, a_n} $ to mean $ v\sb{\psi} = T $ for every valuation $ v $ in $ \mathcal{A} $ with $ v\rb{x_i} = a_i $ for $ i = 1, \dots, n $.
\end{remark}

\begin{note}
By the proof of \ref{thm:2.3.3} this holds if $ v\sb{\psi} = T $ for some such valuation.
\end{note}

\begin{example}
An example where $ \mathcal{A} \vDash \fab{x_1}\phi\rb{x_1} $ but we have term $ t $, and a valuation $ v $ in $ \mathcal{A} $ with $ v\sb{\phi\rb{t}} = F $. Let $ \phi\rb{x_1} $ be $ \impb{\fab{x_2}R\rb{x_2, x_2}}{S\rb{x_1}} $. Scope of $ x_2 $ is $ R\rb{x_1, x_2} $. Let $ t_1 $ be $ x_2 $, then $ \phi\rb{t_1} $ is $ \impb{\fab{x_2}R\rb{x_2, x_2}}{S\rb{x_2}} $. Suppose $ \mathcal{A} = \ab{\N; \le, = 0} $. Domain is $ \N = \cb{0, 1, \dots} $, $ R\rb{x_1, x_2} $ interpreted as $ x_1 \le x_2 $, and $ S\rb{x_1} $ interpreted as $ x_1 = 0 $. So $ \mathcal{A} \vDash \fab{x_1}\phi\rb{x_1} $ but we choose a valuation $ v\rb{x_2} = 1 $ then $ v\sb{\phi\rb{t_1}} = F $ in $ \mathcal{A} $.
\end{example}

\begin{definition}
Let $ \phi $ be an $ \mathcal{L} $-formula, $ x_i $ a variable, $ t $ an $ \mathcal{L} $-term. We say $ t $ is free for $ x_i $ in $ \phi $ if there is no variable $ x_j $ in $ t $ such that $ x_i $ has a free occurrence within the scope of a quantifier $ \fab{x_j} $ in $ \phi $.
\end{definition}

TODO Exercise: Let $ t = f\rb{x_3, x_2, x_5} $, $ \phi_1 $ be $ \impb{\impb{\fab{x_2}R\rb{x_1, x_4}}{K\rb{x_1}}}{\fab{x_1}R\rb{x_1, x_1}} $, and $ \phi_2 $ be $ \impb{\fab{x_2}\impb{R\rb{x_2, x_4}}{\fab{x_1}K\rb{x_1}}}{\fab{x_2}R\rb{x_1, x_1}} $. For which $ t $ is $ t $ free for $ x_1 $?

\begin{theorem}
\label{thm:2.3.6}
Suppose $ \phi\rb{x_1} $ is an $ \mathcal{L} $-formula, possibly with other free variables. Let $ t $ be a term free for $ x_1 $ in $ \phi $, then $ \vDash \impb{\fab{x_1}\phi\rb{x_1}}{\phi\rb{t}} $. In particular, if $ \mathcal{A} $ is an $ \mathcal{L} $-structure with $ \mathcal{A} \vDash \fab{x_1}\phi\rb{x_1} $ then $ A \vDash \phi\rb{t} $.
\end{theorem}

\begin{lemma}
\label{lem:2.3.7}
With this notation, suppose $ v $ is a valuation in $ \mathcal{A} $. Let $ v' $ be the valuation in $ \mathcal{A} $ which is $ x_1 $-equivalent to $ v $, with $ v'\rb{x_1} = v\rb{t} $. Then $ v'\sb{\phi\rb{x_1}} = T $ iff $ v\sb{\phi\rb{t}} = T $.
\end{lemma}

\begin{proof}
This is by induction on the number of connectives and quantifiers in $ \phi $.
\begin{enumerate}
\item Base case. $ \phi $ is an atomic formula $ R\rb{u_1, \dots, u_m} $ where $ R $ is an $ m $-ary relation symbol and $ u_1, \dots, u_m $ are terms. Let $ u^*_i $ be the result of substituting $ t $ for $ x_1 $ in $ u_i $. Then, by induction on the length of the terms, each $ u_i^* $ is a term and $ v'\rb{u_i} = v\rb{u_i^*} $. Moreover, $ \phi\rb{t} $ is $ R\rb{u_1^*, \dots, u_m^*} $. Then
\begin{align*}
v'\sb{\phi\rb{x_1}} = T \qquad
& \iff \qquad \mathcal{A} \vDash R\rb{v'\rb{u_1}, \dots, v'\rb{u_m}} \\
& \iff \qquad \mathcal{A} \vDash R\rb{v\rb{u_1^*}, \dots, v\rb{u_m^*}} \\
& \iff \qquad v\sb{\phi\rb{t}} = T.
\end{align*}
\item Inductive step. There are three cases,
\begin{enumerate}
\item $ \phi $ is $ \notb{\psi} $,
\item $ \phi $ is $ \impb{\psi}{\chi} $, and
\item $ \phi $ is $ \fab{x_i}\psi $.
\end{enumerate}
We leave the first two cases as exercises and do the third. We can assume that $ i \ne 1 $. Otherwise $ x_1 $ is not free in $ \phi $ and $ \phi\rb{t} $ is just $ \phi $. The lemma then follows from \ref{thm:2.3.3}. Note also that as $ t $ is free for $ x_1 $ in $ \fab{x_i}\psi $, it follows that $ t $ is free for $ x_1 $ in $ \psi $ and $ x_i $ is not a variable in $ t $. Suppose first that $ v'\sb{\phi\rb{x_1}} = F $. We show that $ v\sb{\phi\rb{t}} = F $. By \ref{def:2.2.9}, there is a valuation $ w' $ which is $ x_i $-equivalent to $ v' $ with $ w'\sb{\psi\rb{x_1}} = F $. Note that as $ i \ne 1 $,
\begin{equation}
\label{eq:5}
w'\rb{x_1} = v'\rb{x_1} = v\rb{t}.
\end{equation}
Define a valuation $ w $ by
$$ w\rb{x_j} = \begin{cases} v\rb{x_j} & j \ne 1, i \\ w'\rb{x_i} & j = i \\ v\rb{x_1} & j = 1 \end{cases}. $$
So $ w $ is $ x_1 $-equivalent to $ w' $ and $ x_i $-equivalent to $ v $, noting that $ v, v' $ are $ x_i $-equivalent and $ w, v' $ are $ x_i $-equivalent. As $ x_i $ does not occur in $ t $ we have, by \ref{thm:2.3.3} and $ \rb{\ref{eq:5}} $,
$$ w\rb{t} = v\rb{t} = w'\rb{x_1}. $$
We can now apply the induction hypothesis to $ w $, $ w' $, and $ \psi $. We obtain that $ w\sb{\psi\rb{t}} = w'\sb{\psi\rb{x_1}} = F $. As $ w, v $ are $ x_i $-equivalent, it follows that
$$ v\sb{\fab{x_i}\psi\rb{t}} = F. $$
So $ v\sb{\phi\rb{t}} = F $, as required. We now prove the converse direction. We cannot argue by symmetry here. So suppose $ v\sb{\phi\rb{t}} = F $. There is a valuation $ w $ which is $ x_i $-equivalent to $ v $ with $ w\sb{\psi\rb{t}} = F $. Let $ w' $ be the valuation $ x_1 $-equivalent to $ w $ with
$$ w'\rb{x_1} = w\rb{t} = v\rb{t} = v'\rb{x_1}. $$
The fact that $ w\rb{t} = v\rb{t} $ is as before. By the inductive hypothesis, $ w'\sb{\psi\rb{x_1}} = w\rb{\psi\rb{t}} = F $. As $ w' $ is $ x_i $-equivalent to $ v' $ we have
$$ v'\sb{\fab{x_i}\psi\rb{x_1}} = F. $$
So $ v'\sb{\phi\rb{x_1}} = F $. This completes the inductive step.
\end{enumerate}
\end{proof}

\begin{proof}[Proof of \ref{thm:2.3.6}]
Suppose $ v $ is a valuation with $ v\sb{\phi\rb{t}} = F $. Show $ v\sb{\fab{x_1}\phi\rb{x_1}} = F $. Then
$$ v\sb{\impb{\fab{x_1}\phi\rb{x_1}}{\phi\rb{t}}} = T. $$
Take $ v' $ $ x_1 $-equivalent to $ v $ and $ v'\rb{x_1} = v\rb{t} $. Then by \ref{lem:2.3.7}, $ v'\sb{\phi\rb{x_1}} = F $, so $ v\sb{\fab{x_1}\phi\rb{x_1}} = F $.
\end{proof}

\subsection{The formal system $ K_\mathcal{L} $}

\begin{definition}
Suppose $ \mathcal{L} $ is a first-order language. The formal system \textbf{$ K_\mathcal{L} $} has as formulas $ \mathcal{L} $-formulas, and the following.
\begin{enumerate}
\item Axioms. For $ \phi, \chi, \psi $ $ \mathcal{L} $-formulas,
\begin{enumerate}[label=(A\arabic*)]
\item $ \impb{\phi}{\impb{\psi}{\phi}} $,
\item $ \impb{\impb{\phi}{\impb{\psi}{\chi}}}{\impb{\impb{\phi}{\psi}}{\impb{\phi}{\chi}}} $,
\item $ \impb{\impb{\notb{\phi}}{\notb{\psi}}}{\impb{\psi}{\phi}} $,
\item[(K1)] $ \impb{\fab{x_i}\phi\rb{x_i}}{\phi\rb{t}} $, where $ t $ is a term free for $ x_i $ in $ \phi $ and $ \phi $ can have other free variables, and
\item[(K2)] $ \impb{\fab{x_i}\impb{\phi}{\psi}}{\impb{\phi}{\fab{x_i}\psi}} $, if $ x_i $ is not free in $ \phi $.
\end{enumerate}
\item Deduction rules.
\begin{enumerate}
\item Modus Ponens (MP), from formulas $ \phi $ and $ \impb{\phi}{\psi} $ deduce $ \psi $, and
\item \textbf{Generalisation} (Gen), from formula $ \phi $ deduce $ \fab{x_i}\phi $.
\end{enumerate}
\end{enumerate}
A proof in $ K_\mathcal{L} $ is a finite sequence of $ \mathcal{L} $-formulas each of which is an axiom, or deduced from previous formulas in the proof using a rule of deduction. A theorem of $ K_\mathcal{L} $ is the last formula in some proof. Write $ \vdash_{K_\mathcal{L}} \phi $ for $ \phi $ is a theorem in $ K_\mathcal{L} $.
\end{definition}

\begin{note}
Books do not always use $ K_\mathcal{L} $, that is they write $ \vdash \phi $.
\end{note}

\begin{definition}
Suppose $ \Sigma $ is a set of $ \mathcal{L} $-formulas and $ \psi $ an $ \mathcal{L} $-formula. A deduction of $ \psi $ from $ \Sigma $ is a finite sequence of formulas, ending with $ \psi $, each of which is one of
\begin{enumerate}
\item an axiom,
\item a formula in $ \Sigma $, or
\item obtained from earlier formulas in the deduction using MP or Gen, with the restriction that when Gen is applied it does not involve a variable occurring freely in a formula in $ \Sigma $.
\end{enumerate}
Write $ \Sigma \vdash_{K_\mathcal{L}} \psi $ if there is a deduction from $ \Sigma $ to $ \psi $.
\end{definition}

\marginpar{Lecture 13 \\ Thursday \\ 01/11/18}

Lecture 13 is a problem class.

\marginpar{Lecture 14 \\ Friday \\ 02/11/18}

\begin{remark}
\hfill
\begin{enumerate}
\item If $ \Sigma $ consists of closed formulas, do not need to worry about the restriction on Gen.
\item $ \phi \vdash \fab{x_1}\phi $.
\end{enumerate}
\end{remark}

\begin{theorem}
\label{thm:2.4.4}
Suppose $ \phi $ is an $ \mathcal{L} $-formula which is a substitution instance of a tautology in propositional logic. Then $ \vdash_{K_\mathcal{L}} \phi $.
\end{theorem}

\begin{example}
$ \impb{\notb{\notb{\phi}}}{\phi} $ for an $ \mathcal{L} $-formula $ \phi $, as this is a substitution instance of $ \impb{\notb{\notb{p_1}}}{p_1} $. There is a tautology $ \chi $ with propositional variables $ p_1, \dots, p_n $ and $ \mathcal{L} $-formulas $ \psi_1, \dots, \psi_n $ such that $ \phi $ is obtained from $ \chi $ by substituting $ \psi_i $ for $ p_i $ for $ i = 1, \dots, n $. By Completeness of propositional logic in \ref{thm:1.3.4} there is a proof in $ L $ of $ \chi $ by $ \chi_1, \dots, \chi_r $, where each $ \chi_i $ is a propositional formula, that is in $ L $, and $ \chi_r = \chi $. If we substitute $ \psi_1, \dots, \psi_n $ for $ p_1, \dots, p_n $ in all $ \chi_j $ we obtain a sequence of $ \mathcal{L} $-formulas $ \phi_1, \dots, \phi_r $ which is a proof of $ \phi = \phi_r $ in $ K_\mathcal{L} $.
\end{example}

\begin{theorem}[Soundness theorem of $ K_\mathcal{L} $]
\label{thm:2.4.5}
If $ \vdash_{K_\mathcal{L}} \phi $ then $ \vDash \phi $, that is it is logically valid.
\end{theorem}

\begin{proof}
Like in the proof for $ L $, we need to show
\begin{enumerate}
\item axioms are logically valid, and
\item deduction rules preserve logical validity.
\end{enumerate}
For axioms, A1, A2, A3 are substitution instances of propositional tautologies in \ref{def:2.2.1} so are logically valid by \ref{thm:2.4.4}. K1 is logically valid by \ref{thm:2.3.6}. K2 is $ \impb{\fab{x_i}\impb{\phi}{\psi}}{\impb{\phi}{\fab{x_i}\psi}} $ if $ x_i $ is not free in $ \phi $. Suppose we have valuation $ v $ such that $ v\sb{\impb{\phi}{\fab{x_i}\psi}} = F $. So $ v\sb{\phi} = T $ and $ v\sb{\fab{x_i}\psi} = F $. So there is a valuation $ v' $ $ x_i $-equivalent to $ v $ with $ v'\sb{\psi} = F $. $ v $ and $ v' $ agree on all variables free in $ \phi $. So by \ref{thm:2.3.3} $ v\sb{\phi} = v'\sb{\phi} = T $, so $ v'\sb{\impb{\phi}{\psi}} = F $. So $ v\sb{\fab{x_i}\impb{\phi}{\psi}} = F $. So $ v\sb{K_2} = T $. For deduction rules, MP is if $ \vDash \phi $ and $ \vDash \impb{\phi}{\psi} $ then $ \vDash \psi $, and Gen is if $ \vDash \phi $ then $ \vDash \fab{x_i}\phi $. (TODO Exercise)
\end{proof}

TODO Exercise: Suppose $ \Sigma \vdash \psi $ then for every valuation $ v $ with $ v\sb{\sigma} = T $ for all $ \sigma \in \Sigma $ we have $ v\sb{\psi} = T $.

\begin{corollary}
There is no $ \mathcal{L} $-formula $ \phi $ with $ \vdash_{K_\mathcal{L}} \phi $ and $ \vdash_{K_\mathcal{L}} \notb{\phi} $.
\end{corollary}

\begin{theorem}[Deduction theorem]
Suppose $ \mathcal{L} $ is a first-order language, $ \Sigma $ is a set of $ \mathcal{L} $-formulas, and $ \phi, \psi $ are $ \mathcal{L} $-formulas. Then if $ \Sigma \cup \cb{\phi} \vdash \psi $ then $ \Sigma \vdash \impb{\phi}{\psi} $.
\end{theorem}

\begin{proof}
Follows proof of deduction theorem for $ L $ in \ref{thm:1.2.5} by induction on the length of the deduction.
\begin{enumerate}
\item Base case is one line deduction. Argue exactly as in \ref{thm:1.2.5}. Note that $ \vdash_{K_\mathcal{L}} \impb{\phi}{\phi} $ by \ref{thm:2.4.4}.
\item Inductive step. Suppose $ \psi $ follows from earlier formulas in the deduction using MP or Gen. MP is exactly as in \ref{thm:1.2.5}. For Gen, suppose $ \psi $ is obtained using Gen then $ \psi $ is $ \fab{x_i}\theta $ and $ \Sigma \cup \cb{\phi} \vdash \theta $ and $ x_i $ is not free in any formula in $ \Sigma \cup \cb{\phi} $. By induction we have $ \Sigma \vdash \impb{\phi}{\theta} $. By K2 $ \Sigma \vdash \impb{\fab{x_i}\impb{\phi}{\theta}}{\impb{\phi}{\fab{x_i}\theta}} $. By Gen $ \Sigma \vdash \fab{x_i}\impb{\phi}{\theta} $ for $ x_i $ not free in any formula in $ \Sigma $. So by MP we get $ \Sigma \vdash \impb{\phi}{\fab{x_i}\theta} $ which is $ \Sigma \vdash \impb{\phi}{\psi} $.
\end{enumerate}
\end{proof}

\marginpar{Lecture 15 \\ Monday \\ 05/11/18}

\subsection{Gödel's completeness theorem}

\begin{definition}
A set $ \Sigma $ of $ \mathcal{L} $-formulas is consistent if there is no formula $ \phi $ with $ \Sigma \vdash_{K_\mathcal{L}} \phi $ and $ \Sigma \vdash_{K_\mathcal{L}} \notb{\phi} $.
\end{definition}

By Soundness theorem \ref{thm:2.4.5} $ \emptyset $ is consistent, so $ K_\mathcal{L} $ is consistent.

\begin{remark}
If $ \Sigma $ is inconsistent then $ \Sigma \vdash \chi $ for any $ \mathcal{L} $-formula $ \chi $.
\end{remark}

Recall that a closed $ \mathcal{L} $-formula is one without free variables, sometimes called a sentence of $ \mathcal{L} $. Show that if $ \Sigma $ is a set of closed $ \mathcal{L} $-formulas which is consistent then there is an $ \mathcal{L} $-structure $ \mathcal{A} $ with $ \mathcal{A} \vDash \sigma $ for all $ \sigma \in \Sigma $. For a simplification, suppose that $ \mathcal{L} $ is countable, that is the variables are $ x_0, x_1, \dots $ and there are countably many relation, function, and constant symbols. So we can enumerate the $ \mathcal{L} $-formulas, or any subset thereof, as a list indexed by $ \N $. Enumerate the closed $ \mathcal{L} $-formulas as $ \psi_0, \psi_1, \dots $.

\begin{proposition}
\label{prop:2.5.2}
Suppose $ \Sigma $ is a consistent set of closed $ \mathcal{L} $-formulas and $ \phi $ is a closed $ \mathcal{L} $-formula.
\begin{enumerate}
\item (Compare \ref{prop:1.3.7}) If $ \Sigma \not\vdash_{K_\mathcal{L}} \phi $ then $ \Sigma \cup \cb{\notb{\phi}} $ is consistent.
\item (Compare Lindenbaum's lemma \ref{prop:1.3.8}) There is a consistent set $ \Sigma^* \supseteq \Sigma $ of closed $ \mathcal{L} $-formulas such that, for every closed $ \mathcal{L} $-formula $ \psi $ either $ \Sigma^* \vdash \psi $ or $ \Sigma^* \vdash \notb{\psi} $.
\end{enumerate}
\end{proposition}

\begin{proof}
\hfill
\begin{enumerate}
\item As in \ref{prop:1.3.7}, used deduction theorem and $ \vdash_{K_\mathcal{L}} \impb{\impb{\notb{\phi}}{\phi}}{\phi} $.
\item Uses $ 1 $ and the enumeration $ \psi_0, \psi_1, \dots $ of the closed $ \mathcal{L} $-formulas.
\end{enumerate}
\end{proof}

\begin{theorem}
\label{thm:2.5.3}
Suppose $ \Sigma $ is a consistent set of closed $ \mathcal{L} $-formulas. Then there is a countable $ \mathcal{L} $-structure $ \mathcal{A} $ with $ \mathcal{A} \vDash \Sigma $, that is $ \mathcal{A} \vDash \sigma $ for all $ \sigma \in \Sigma $.
\end{theorem}

\begin{theorem}
\label{thm:2.5.4}
Let $ \Sigma $ be a set of closed $ \mathcal{L} $-formulas and $ \phi $ a closed $ \mathcal{L} $-formula. If every model of $ \Sigma $ is a model of $ \phi $, that is if $ \mathcal{A} \vDash \Sigma $ or $ \mathcal{A} \vDash \sigma $ for all $ \sigma \in \Sigma $ then $ \mathcal{A} \vDash \phi $, then $ \Sigma \vdash_{K_\mathcal{L}} \phi $.
\end{theorem}

Notation is $ \Sigma \vDash \phi $. Then $ \Sigma \vDash \phi $ gives $ \Sigma \vdash \phi $. The converse is Soundness theorem.

\begin{proof}
May assume $ \Sigma $ is consistent, otherwise, everything is a consequence of $ \Sigma $. By assumption there is no model of $ \Sigma \cup \cb{\notb{\phi}} $. So by \ref{thm:2.5.3}, $ \Sigma \cup \cb{\notb{\phi}} $ is inconsistent. So by \ref{prop:2.5.2}(1), $ \Sigma \vdash \phi $.
\end{proof}

\begin{theorem}[Gödel's completeness theorem for $ K_\mathcal{L} $, 1929]
If $ \phi $ is an $ \mathcal{L} $-formula with $ \vDash \phi $, then $ \phi $ is a theorem of $ K_\mathcal{L} $, that is $ \vdash_{K_\mathcal{L}} \phi $.
\end{theorem}

\begin{proof}
If $ \phi $ is closed this follows from \ref{thm:2.5.4} with $ \Sigma = \emptyset $. Suppose $ \phi $ has free variables amongst $ x_1, \dots, x_n $ and consider the closed formula $ \psi $, $ \fab{x_1} \dots \fab{x_n}\phi $. As $ \vDash \phi $ we obtain $ \vDash \psi $. So by the closed case $ \vdash \psi $, that is
\begin{equation}
\label{eq:6}
\vdash \fab{x_1} \dots \fab{x_n}\phi.
\end{equation}
If $ \theta $ is any formula then $ \vdash \impb{\fab{x_i}\theta}{\theta} $ by the K1 axiom. So from $ \rb{\ref{eq:6}} $ and this fact and MP applied $ n $ times we obtain $ \vdash_{K_\mathcal{L}} \phi $.
\end{proof}

\begin{corollary}[Compactness theorem for $ K_\mathcal{L} $]
\label{cor:2.5.6}
Suppose $ \Sigma $ is a set of closed $ \mathcal{L} $-formulas and every finite subset of $ \Sigma $ has a model. Then $ \Sigma $ has a model.
\end{corollary}

\begin{proof}
Suppose $ \Sigma $ has no model. By \ref{thm:2.5.3} $ \Sigma $ is inconsistent so there is a formula $ \phi $ with $ \Sigma \vdash \phi $ and $ \Sigma \vdash \notb{\phi} $. Deductions only involve finitely many formulas in $ \Sigma $. So there is a finite $ \Sigma_0 \subseteq \Sigma $ with $ \Sigma_0 \vdash \phi $ and $ \Sigma_0 \vdash \notb{\phi} $. But then $ \Sigma_0 $ is inconsistent so has no model, a contradiction.
\end{proof}

\marginpar{Lecture 16 \\ Thursday \\ 08/11/18}

\begin{proof}[Sketch of proof of \ref{thm:2.5.3}]
Proof is in a series of steps. Notation is cumulative.
\begin{enumerate}
\item Let $ b_0, b_1, \dots $ be new constant symbols. Form $ \mathcal{L}^+ $ by adding these to the symbols of $ \mathcal{L} $. Regard $ \Sigma $ as a set of $ \mathcal{L}^+ $-formulas. Check $ \Sigma $ is still consistent in the formal system $ K_{\mathcal{L}^+} $. Note that $ \mathcal{L}^+ $ is still a countable language.
\item Adding witnesses. Use a lemma that there is a consistent set of closed $ \mathcal{L}^+ $-formulas $ \Sigma_\infty \supseteq \Sigma $ such that for every $ \mathcal{L}^+ $-formula $ \theta\rb{x_i} $ with one free variable there is some $ b_j $ with
$$ \Sigma_\infty \vdash_{K_{\mathcal{L}^+}} \impb{\notb{\fab{x_i}\theta\rb{x_i}}}{\notb{\theta\rb{b_j}}}. $$
Think of $ \theta\rb{x_i} $ as $ \notb{\chi\rb{x_i}} $. Then this formula is essentially $ \impb{\teb{x_i}\chi\rb{x_i}}{\chi\rb{b_j}} $, so $ b_j $ witnesses the existence of $ x_i $ satisfying $ x_i $.
\item By Lindenbaum's lemma \ref{prop:2.5.2} there is a consistent set $ \Sigma^* \supseteq \Sigma_\infty $ of closed $ \mathcal{L}^+ $-formulas such that for every closed $ \phi $ either $ \Sigma^* \vdash_{K_{\mathcal{L}^+}} \phi $ or $ \Sigma^* \vdash_{K_{\mathcal{L}^+}} \notb{\phi} $.
\item Building a structure. Let $ A = \cb{\bar{t}} $ where $ t $ is a closed term of $ \mathcal{L}^+ $. Note that
\begin{enumerate}
\item a term is closed if it only involves constant symbols and function symbols, and no variables,
\item use the $ \bar{\cdot} $ to distinguish when we are thinking of a term as an element of $ A $, and
\item as $ \mathcal{L}^+ $ is countable, $ A $ is countable.
\end{enumerate}
Make $ A $ into an $ \mathcal{L}^+ $ structure.
\begin{enumerate}
\item Each constant symbol $ c $ of $ \mathcal{L}^+ $ is interpreted as $ \bar{c} \in A $.
\item Suppose $ R $ is an $ n $-ary relation symbol. Define the relation $ \bar{R} \subseteq A^n $ by $ \rb{\bar{t_1}, \dots, \bar{t_n}} \in \bar{R} $ iff $ \Sigma^* \vdash R\rb{t_1, \dots, t_n} $, a closed atomic $ \mathcal{L}^+ $-formula, where $ t_1, \dots, t_n $ are closed $ \mathcal{L}^+ $-terms.
\item Suppose $ f $ is an $ m $-ary function symbol. Define a function $ \bar{f} : A^m \to A $ by $ \bar{f}\rb{\bar{t_1}, \dots, \bar{t_m}} = \bar{f\rb{t_1, \dots, t_m}} $ for closed terms $ t_1, \dots, t_m $.
\end{enumerate}
Call this structure $ \mathcal{A} $. Note that if $ v $ is a valuation in $ \mathcal{A} $ and $ t $ is a closed term, then $ v\rb{t} = \bar{t} $ by (a) and (c) here.
\item Use the main lemma that for every closed $ \mathcal{L}^+ $-formula $ \phi $
\begin{equation}
\label{eq:7}
\Sigma^* \vdash_{K_{\mathcal{L}^+}} \phi \qquad \iff \qquad \mathcal{A} \vDash \phi.
\end{equation}
Proof by induction on number of connectives and quantifiers in $ \phi $.
\begin{enumerate}
\item Base case. $ \phi $ is atomic, that is $ \phi $ is $ R\rb{t_1, \dots, t_n} $ for some closed terms $ t_i $, and relation symbol $ R $. $ \rb{\ref{eq:7}} $ holds by $ (b) $ in definition of $ \mathcal{A} $.
\item Inductive step. Assume $ \rb{\ref{eq:7}} $ holds for closed formulas involving fewer connectives and quantifiers.
\begin{enumerate}
\item $ \phi $ is $ \notb{\psi} $.
\item $ \phi $ is $ \impb{\psi}{\chi} $.
\item $ \phi $ is $ \fab{x_i}\psi $.
\end{enumerate}
In cases i and ii $ \psi, \chi $ are closed. So $ \rb{\ref{eq:7}} $ holds for these.
\begin{enumerate}
\item $ \phi $ is $ \notb{\psi} $, so $ \mathcal{A} \vDash \phi $ iff $ \mathcal{A} \not\vDash \psi $ by \ref{thm:2.3.3}, iff $ \Sigma^* \not\vdash \psi $ by $ \rb{\ref{eq:7}} $, iff $ \Sigma^* \vdash \notb{\psi} $ by step $ 3 $.
\item TODO Exercise.
\item $ \phi $ is $ \fab{x_i}\psi $.
\begin{enumerate}
\item $ x_i $ is not free in $ \psi $. So $ \psi $ is closed and we can use inductive hypothesis.
\item $ x_i $ is free in $ \psi $. So $ \psi\rb{x_i} $ has a single free variable.
\end{enumerate}
\end{enumerate}
\end{enumerate}
Suppose for a contradiction that $ \mathcal{A} \vDash \phi $ and $ \Sigma^* \not\vdash \phi $. Then by step $ 3 $ $ \Sigma^* \vdash \notb{\phi} $. By step $ 2 $, $ \Sigma^* \vdash \impb{\notb{\fab{x_i}\psi\rb{x_i}}}{\notb{\psi\rb{b_j}}} $ for some constant symbol $ b_j $, that is $ \Sigma^* \vdash \impb{\notb{\phi}}{\notb{\psi\rb{b_j}}} $. So $ \Sigma^* \vdash \notb{\psi\rb{b_j}} $. $ \notb{\psi\rb{b_j}} $ is closed and by case $ i $, $ \rb{\ref{eq:7}} $ applies. We obtain
\begin{equation}
\label{eq:8}
\mathcal{A} \vDash \notb{\psi\rb{b_j}}.
\end{equation}
This contradicts $ \mathcal{A} \vDash \fab{x_i}\psi $. Take a valuation $ v $ is $ \mathcal{A} $ with $ v\rb{x_i} = \bar{b_j} $, then $ v $ does not satisfy $ \psi $, by $ \rb{\ref{eq:8}} $.
\end{enumerate}
\end{proof}

TODO Exercise: think about this where $ \Sigma $ consists of the group axioms. What is $ \mathcal{A} $? Is it a group?

\marginpar{Lecture 17 \\ Friday \\ 09/11/18}

\subsection{Equality}

\begin{example}
In the language of groups, have a binary relation symbol $ E\rb{x_1, x_2} $ for equality $ x_1 = x_2 $.
\end{example}

\begin{definition}
Suppose $ \mathcal{L}^E $ is a first-order language with a distinguished binary relation symbol $ E $.
\begin{enumerate}
\item An $ \mathcal{L}^E $-structure in which $ E $ is interpreted as equality $ = $ is a \textbf{normal} $ \mathcal{L}^E $-structure.
\item The following are the axioms of equality, $ \Sigma_E $.
\begin{enumerate}
\item $ \fab{x_1}E\rb{x_1, x_2} $.
\item $ \fab{x_1}\fab{x_2}\impb{E\rb{x_1, x_2}}{E\rb{x_2, x_1}} $.
\item $ \fab{x_1}\fab{x_2}\fab{x_3}\impb{E\rb{x_1, x_2}}{\impb{E\rb{x_2, x_3}}{E\rb{x_1, x_3}}} $.
\end{enumerate}
\item For each $ n $-ary relation symbol $ R $ of $ \mathcal{L}^E $,
$$ \fab{x_1}\dots\fab{x_n}\fab{y_1}\dots\fab{y_n}\impb{\rb{R\rb{x_1, \dots, x_n} \land E\rb{x_1, y_1} \land \dots \land E\rb{x_n, y_n}}}{R\rb{y_1, \dots, y_n}}. $$
\item For each $ m $-ary function symbol $ f $ of $ \mathcal{L}^E $,
$$ \fab{x_1}\dots\fab{x_m}\fab{y_1}\dots\fab{y_m}\impb{\rb{E\rb{x_1, y_1} \land \dots \land E\rb{x_m, y_m}}}{E\rb{f\rb{x_1, \dots, x_m}, f\rb{y_1, \dots, y_m}}}. $$
\end{enumerate}
\end{definition}

\begin{definition}
\hfill
\begin{enumerate}
\item If $ \mathcal{A} $ is a normal $ \mathcal{L}^E $-structure then $ \mathcal{A} \vDash \Sigma_E $.
\item Suppose $ \mathcal{A} = \ab{A; \bar{E}, \dots} $ is an $ \mathcal{L}^E $-structure and $ \mathcal{A} \vDash \Sigma_E $. Then $ \bar{E} $ is an equivalence relation on $ A $. Denote, for $ a \in A $ $ \widehat{a} = \cb{b \in A \mid \bar{E}\rb{a, b}} $, the equivalence class of $ a $. Let $ \widehat{A} = \cb{\widehat{a} \mid a \in A} $. Make $ \widehat{A} $ into an $ \mathcal{L}^E $-structure $ \widehat{\mathcal{A}} $.
\begin{enumerate}
\item If $ R $ is an $ n $-ary relation symbol and $ \widehat{a_1}, \dots, \widehat{a_n} \in \widehat{A} $ then say $ \bar{R}\rb{\widehat{a_1}, \dots, \widehat{a_n}} $ holds in $ \widehat{\mathcal{A}} $ iff $ \bar{R}\rb{a_1, \dots, a_n} $ holds in $ \mathcal{A} $. This is well-defined by $ \Sigma_E $.
\item Similarly if $ f $ is an $ m $-ary function symbol and $ \widehat{a_1}, \dots, \widehat{a_m} \in \widehat{A} $ let $ \bar{f}\rb{\widehat{a_1}, \dots, \widehat{a_m}} = \widehat{\bar{f}\rb{a_1, \dots, a_m}} $. This is also well-defined by $ \Sigma_E $.
\item If $ c $ is a constant symbol, then interpret $ c $ as $ \widehat{\bar{c}} $ in $ \widehat{A} $, where $ \bar{c} $ is the interpretation in $ \mathcal{A} $.
\end{enumerate}
Note that in $ \widehat{\mathcal{A}} $ $ \bar{E}\rb{\widehat{a_1}, \widehat{a_2}} $ iff $ \bar{E}\rb{a_1, a_2} $ in $ \mathcal{A} $, iff $ \widehat{a_1} = \widehat{a_2} $. So $ \widehat{\mathcal{A}} $ is a normal $ \mathcal{L}^E $-structure.
\end{enumerate}
\end{definition}

\begin{lemma}
\label{lem:2.6.3}
Suppose $ \mathcal{A} $ is an $ \mathcal{L}^E $-structure with $ \mathcal{A} \vDash \Sigma_E $. Let $ v $ be a valuation in $ \mathcal{A} $. Let $ \widehat{\mathcal{A}} $ be as given above. Let $ \widehat{v} $ be the valuation in $ \widehat{\mathcal{A}} $ with $ \widehat{v}\rb{x_i} = \widehat{v\rb{x_i}} $. Then for every $ \mathcal{L}^E $-formula $ \phi $ $ \widehat{v} $ satisfies $ \phi $ in $ \widehat{\mathcal{A}} $ iff $ v $ satisfies $ \phi $ in $ \mathcal{A} $. In particular, if $ \phi $ is closed then $ \mathcal{A} \vDash \phi $ iff $ \widehat{\mathcal{A}} \vDash \phi $.
\end{lemma}

\begin{note}
If $ t $ is any term then $ \widehat{v}\rb{t} = \widehat{v\rb{t}} $ by definition of $ \bar{f} $ on the structure $ \widehat{\mathcal{A}} $.
\end{note}

\begin{proof}
The result \ref{lem:2.6.3} is proved by induction on the number of connectives and quantifiers in $ \phi $.
\begin{enumerate}
\item Base step. $ \phi $ is an atomic formula $ R\rb{t_1, \dots, t_n} $, where $ R $ is an $ n $-ary relation symbol and $ t_1, \dots, t_n $ are terms. Then $ v\sb{\phi} = T $ iff $ \bar{R}\rb{v\rb{t_1}, \dots, v\rb{t_n}} $ holds in $ \mathcal{A} $, iff $ \bar{R}\rb{\widehat{v\rb{t_1}}, \dots, \widehat{v\rb{t_n}}} $ holds in $ \mathcal{A} $ by definition of $ \bar{R} $ in $ \widehat{\mathcal{A}} $, iff $ \bar{R}\rb{\widehat{v}\rb{t_1}, \dots, \widehat{v}\rb{t_n}} $ in $ \mathcal{A} $, iff $ \widehat{v}\sb{\phi} = T $, as required.
\item Inductive step.
\begin{enumerate}
\item $ \phi $ is $ \notb{\psi} $. (TODO Exercise)
\item $ \phi $ is $ \impb{\theta}{\chi} $ (TODO Exercise)
\item $ \phi $ is $ \fab{x_i}\psi $.
\begin{itemize}
\item[$ \implies $] If $ v\sb{\fab{x_i}\psi} = F $ there is a $ v' $ $ x_i $-equivalent to $ v $ with $ v'\sb{\psi} = F $. Then $ \widehat{v'} $ is $ x_i $-equivalent to $ \widehat{v} $ and by the induction hypothesis $ \widehat{v'}\sb{\psi} = F $. So $ \widehat{v}\sb{\fab{x_i}\psi} = F $.
\item[$ \impliedby $] Suppose $ \widehat{v}\sb{\fab{x_i}\psi} = F $. So there is a valuation $ w $ in $ \widehat{\mathcal{A}} $ which is $ x_i $-equivalent to $ \widehat{v} $ and $ w\sb{\psi} = F $. There is a valuation $ v' $ in $ \mathcal{A} $ $ x_i $-equivalent to $ v $ with $ \widehat{v'} = w $. We just change $ v\rb{x_i} $ so $ \widehat{v'\rb{x_i}} = w\rb{x_i} $. Then $ v'\sb{\psi} = F $ by inductive hypothesis. So $ v\sb{\fab{x_i}\psi} = F $.
\end{itemize}
\end{enumerate}
\end{enumerate}
\end{proof}

\begin{lemma}
\label{lem:2.6.4}
Suppose $ \Delta $ is a set of closed $ \mathcal{L}^E $-formulas. Then $ \Delta $ has a normal model, that is a normal $ \mathcal{L}^E $-structure $ \mathcal{B} $ with $ \mathcal{B} \vDash \sigma $ for all $ \sigma \in \Delta $, iff $ \Delta \cup \Sigma_E $ has a model.
\end{lemma}

\begin{proof}
\hfill
\begin{itemize}
\item[$ \implies $] Trivial as $ \Sigma_E $ holds in a normal $ \mathcal{L}^E $-structure.
\item[$ \impliedby $] If $ \mathcal{A} \vDash \Delta \cup \Sigma_E $ then by \ref{lem:2.6.3} $ \widehat{\mathcal{A}} \vDash \Delta $ and $ \widehat{\mathcal{A}} $ is a normal $ \mathcal{L}^E $-structure.
\end{itemize}
\end{proof}

\begin{theorem}[Compactness theorem for normal models]
Suppose $ \mathcal{L}^E $ is a countable language with equality and $ \Delta $ is a set of closed $ \mathcal{L}^E $-formulas such that every finite subset of $ \Delta $ has a normal model. Then $ \Delta $ has a normal model.
\end{theorem}

\begin{proof}
Every normal $ \mathcal{L}^E $-structure is a model of $ \Sigma_E $, so every finite subset of $ \Delta \cup \Sigma_E $ has a model. By \ref{cor:2.5.6} $ \Delta \cup \Sigma_E $ has a model $ \mathcal{A} $. Then by \ref{lem:2.6.3} or \ref{lem:2.6.4} $ \widehat{\mathcal{A}} $ is a normal model of $ \Delta $.
\end{proof}

From now on, write $ \mathcal{L}^= $ instead of $ \mathcal{L}^E $ and $ x_1 = x_2 $ instead of $ E\rb{x_1, x_2} $ etc.

\marginpar{Lecture 18 \\ Monday \\ 12/11/18}

\begin{theorem}[Countable downward Löwenheim-Skolem theorem]
Suppose $ \mathcal{L}^= $ is a countable first-order language with equality, and $ \mathcal{B} $ a normal $ \mathcal{L}^= $ structure. Then there is a countable normal $ \mathcal{L}^= $-structure $ \mathcal{A} $ such that for every closed $ \mathcal{L}^= $-formula $ \phi $ $ \mathcal{B} \vDash \phi $ iff $ \mathcal{A} \vDash \phi $.
\end{theorem}

\begin{example}
$ \mathcal{B} = \ab{\R; +, \cdot, 0, 1, \le, \exp} $ has $ \mathcal{A} = ? $.
\end{example}

\begin{proof}
Let $ \Sigma $ be the closed $ \phi $ such that $ \mathcal{B} \vDash \phi $, called the \textbf{theory} of $ \mathcal{B} $. Then $ \Sigma \supseteq \Sigma_E $ with the axioms of equality, and $ \Sigma $ is consistent. By \ref{thm:2.5.3} $ \Sigma $ has a countable model $ \mathcal{C} $. Then $ \widehat{\mathcal{C}} $ is a countable normal model of $ \Sigma $ by \ref{lem:2.6.3}. So if $ \phi $ is closed and $ \mathcal{B} \vDash \phi $ then $ \widehat{\mathcal{C}} \vDash \phi $. Conversely if $ \phi $ is closed and $ \mathcal{B} \not\vDash \phi $ then $ \mathcal{B} \vDash \notb{\phi} $ by \ref{thm:2.3.3}, so $ \widehat{\mathcal{C}} \vDash \notb{\phi} $ so $ \widehat{\mathcal{C}} \not\vDash \phi $. Take $ \mathcal{A} = \widehat{\mathcal{C}} $.
\end{proof}

\subsection{Examples and applications}

Linear orders. Let $ \mathcal{L}^= $ be a first-order language with equality and a binary relation symbol $ \le $.

\begin{definition}
A linear order $ \mathcal{A} = \ab{A; \le_A} $ is a normal model if
\begin{enumerate}
\item $ \phi_1 $, $ \fab{x_1}\fab{x_2}\iffb{\andb{\rb{x_1 \le x_2}}{\rb{x_2 \le x_1}}}{\rb{x_1 = x_2}} $,
\item $ \phi_2 $, $ \fab{x_1}\fab{x_2}\fab{x_3}\impb{\andb{\rb{x_1 \le x_2}}{\rb{x_2 \le x_3}}}{\rb{x_1 \le x_3}} $, and
\item $ \phi_3 $, $ \fab{x_1}\fab{x_2}\orb{\rb{x_1 \le x_2}}{\rb{x_2 \le x_1}} $.
\end{enumerate}
It is \textbf{dense} if also
\begin{enumerate}
\setcounter{enumi}{3}
\item $ \phi_4 $, $ \fab{x_1}\fab{x_2}\teb{x_3}\impb{\rb{x_1 < x_2}}{\andb{\rb{x_1 < x_3}}{\rb{x_3 < x_2}}} $,
\end{enumerate}
where $ \rb{x_1 < x_2} $ is an abbreviation for $ \andb{\rb{x_1 \le x_2}}{\rb{x_1 \ne x_2}} $. It is \textbf{without endpoints} if
\begin{enumerate}
\setcounter{enumi}{4}
\item $ \phi_5 $, $ \fab{x_1}\teb{x_2}\rb{x_1 < x_2} $, and
\item $ \phi_6 $, $ \fab{x_1}\teb{x_2}\rb{x_2 < x_1} $.
\end{enumerate}
Let $ \Delta = \cb{\phi_1, \dots, \phi_6} $. $ \mathcal{Q} = \ab{\Q; \le} $ is a normal model of $ \Delta $. $ \mathcal{R} = \ab{\R; \le} $ is also a model of $ \Delta $.
\end{definition}

Will prove the following.

\begin{theorem}
\label{thm:2.7.2}
\hfill
\begin{enumerate}
\item For every closed $ \mathcal{L}^= $-formula $ \phi $ $ \mathcal{Q} \vDash \phi $ iff $ \mathcal{R} \vDash \phi $.
\item There is an algorithm to decide, given a closed $ \mathcal{L}^= $-formula $ \phi $, whether $ \mathcal{Q} \vDash \phi $ or $ \mathcal{Q} \vDash \notb{\phi} $.
\end{enumerate}
\end{theorem}

\begin{definition}
\label{def:2.7.3}
\hfill
\begin{enumerate}
\item Linear orders $ \mathcal{A} = \ab{A; \le_A} $ and $ \mathcal{B} = \ab{B; \le_B} $ are isomorphic if there is a bijection $ \alpha : A \to B $ such that for all $ a, a' \in A $ $ a \le_A a' $ iff $ \alpha\rb{a} \le_B \alpha\rb{a'} $.
\item If $ \mathcal{A}, \mathcal{B} $ are isomorphic and $ \phi $ is closed then $ \mathcal{A} \vDash \phi $ iff $ \mathcal{B} \vDash \phi $.
\end{enumerate}
\end{definition}

\begin{theorem}[Cantor]
\label{thm:2.7.4}
If $ \mathcal{A}, \mathcal{B} $ are countable dense linear orders without endpoints, then $ \mathcal{A}, \mathcal{B} $ are isomorphic.
\end{theorem}

\begin{lemma}[Łos-Vaught test]
\label{lem:2.7.5}
Let $ \Sigma = \Sigma_E \cup \Delta $. Then for every closed $ \mathcal{L}^= $-formula $ \phi $, we have either $ \Sigma \vdash \phi $ or $ \Sigma \vdash \notb{\phi} $. Say $ \Sigma $ is complete.
\end{lemma}

\begin{proof}
Suppose not. Then as $ \Sigma $ is consistent, it has a model, we can use \ref{prop:2.5.2} to get $ \Sigma_1 = \Sigma \cup \cb{\notb{\phi}} $ and $ \Sigma_2 = \Sigma \cup \cb{\notb{\notb{\phi}}} $ are consistent. So $ \Sigma \cup \cb{\phi} $ is consistent. By \ref{thm:2.5.3}, \ref{lem:2.6.4} it follows that $ \Sigma_1, \Sigma_2 $ have countable normal models $ \mathcal{A}_1, \mathcal{A}_2 $. So $ \mathcal{A}_1, \mathcal{A}_2 $ are countable dense linear orders without endpoints and $ \mathcal{A}_1 \vDash \notb{\phi} $ and $ \mathcal{A}_2 \vDash \phi $. This contradicts \ref{thm:2.7.4} and \ref{def:2.7.3}(2).
\end{proof}

\begin{proof}[Proof of \ref{thm:2.7.2}(1)]
Show $ \mathcal{Q} \vDash \phi $ iff $ \Sigma \vdash \phi $.
\begin{itemize}
\item[$ \impliedby $] As $ \mathcal{Q} \vDash \Sigma $ this is \ref{thm:2.4.5}.
\item[$ \implies $] If $ \Sigma \not\vdash \phi $ then by \ref{lem:2.7.5} $ \Sigma \vdash \notb{\phi} $. So $ \mathcal{Q} \vDash \notb{\phi} $, so $ \mathcal{Q} \not\vDash \phi $.
\end{itemize}
Similarly $ \mathcal{R} \vDash \phi $ iff $ \Sigma \vdash \phi $. So $ \mathcal{R} \vDash \phi $ iff $ \Sigma \vdash \phi $, iff $ \mathcal{Q} \vDash \phi $.
\end{proof}

\marginpar{Lecture 19 \\ Thursday \\ 15/11/18}

Lecture 19 is a problem class.

\end{document}