\documentclass{article}
\input{packages}
\input{def}

\newcommand{\C}{\mathbb{C}}
\newcommand{\app}{\mathop{\cdot}}
\newcommand{\xequals}[1]{\stackrel{#1}{\approx}}

\lecture{The Effective Topos}

\begin{document}
\maketitle

Let $\C$ be the set of closed irreducible terms of the untyped lambda calculus extended to multiple-arity $\lambda$s and applications, where the term $(\lambda \langle x_1, \dots, x_n \rangle. c)~\langle c_1, \dots, c_n \rangle$ reduces (in one step) to $c[x_1 \mapsto c_1, \dots, x_n \mapsto c_n]$.
Define $c \app \langle c_1, \dots, c_n \rangle$ to be the partial operation outputing the (unique) normalization of $c~\langle c_1, \dots, c_n \rangle$ if one exists.
We use $\pi^2_1$ and $\pi^2_2$ as abbreviations for $\lambda \langle x_1, x_2 \rangle. x_1$ and $\lambda \langle x_1, x_2 \rangle.\; x_2$ respectively.
Recall that $\lambda \langle p \rangle.\;p~\langle c_1, c_2 \rangle$ represents the pair of $c_1$ and $c_2$.

\begin{remark}
The intuition is that $\C$ represents a codification of computation; we use the untyped lambda calculus simply as a concise example.
$\C$ could also be codifications of partial recursive functions or codifications of Turing machines.
\end{remark}

\begin{notation}
A proposition containing partial operations does not hold if those operations do not produce an output.
\end{notation}

\begin{definition}[$\cat{Eff}$]
The category with the following structure:
\begin{description}
\item[Object (Effective Set)] A set $X$ and a ternary relation $x_1 \xequals{c} x_2$, where $x_1, x_2 : X$ and $c : \C$, such that the following properties hold:
$$\exists c : \C.\; \forall x_1, x_2 : X.\; \forall c' : \C.\; x_1 \xequals{c'} x_2 \implies x_2 \xequals{c \app \langle c' \rangle} x_1$$
$$\exists c : \C.\; \forall x_1, x_2, x_3 : X.\; \forall c_\ell, c_r : \C.\; x_1 \xequals{c_\ell} x_2 \;\;\wedge\;\; x_2 \xequals{c_r} x_3 \implies x_1 \xequals{c \app \langle c_\ell, c_r \rangle} x_3$$
The intuition is that $x_1 \xequals{c} x_2$ means that $c$ is defined to serve as evidence that $x_1$ is equal to $x_2$.
The two required properties indicate that symmetry and transitivity are \emph{realizable}: the process of transforming evidence of equality into evidence of the symmetric equality is computable, and the process of transforming evidences of two connected equalities into evidence of the transitive equality is computable.
Note that all elements of $X$ are necessarily equal to themselves according to this ternary relation, which represents being undefined in the ``effective'' set.
\item[Morphism from $\langle X, \approx \rangle$ to $\langle Y, \approx \rangle$ (Realizable Function)] An equivalence class of ternary relations $x \xto{c} y$, where $x : X$, $y : Y$, and $c : \C$, satisfying the following four properties:
$$\exists c : \C.\; \forall x_1, x_2 : X.\; \forall y_1, y_2 : Y.\; \forall c_x, c_y, c' : \C.\; x_1 \xequals{c_x} x_2 \;\;\wedge\;\; y_1 \xequals{c_y} y_2 \;\;\wedge\;\; x_1 \xto{c'} y_1 \implies x_2 \xto{c \app \langle c_x, c_y, c' \rangle} y_2$$
$$\exists c : \C.\; \forall x : X.\; \forall y : Y.\; \forall c' : \C.\; x \xto{c'} y \implies x \xequals{c \app \langle \pi_1^2, c' \rangle} x \;\;\wedge\;\; y \xequals{c \app \langle \pi_2^2, c' \rangle} y$$
$$\exists c : \C.\; \forall x : X.\; \forall y_1, y_2 : Y.\; \forall c_1, c_2 : \C.\; x \xto{c_1} y_1 \;\;\wedge\;\; x \xto{c_2} y_2 \implies y_1 \xequals{c \app \langle c_1, c_2 \rangle} y_2$$
$$\exists c : \C.\; \forall x : X.\; \forall c_x : \C.\; x \xequals{c_x} x \implies \exists y : Y.\; x \xto{c \app \langle c_x \rangle} y$$
The intuition is that $x \xto{c} y$ means that $c$ is defined to serve as evidence that $x$ maps to $y$.
The four required properties indicate that extensionality (the maps-to relation is preserved by equivalence), strictness (only well-defined elements are related), left determinedness (the right half of the maps-to relation is determined up to equivalence by the left half), and left totality (every well-defined left element is related to some right element) are realizable.

Two such ternary relations $\mto$ and $\mto_*$ are considered to be in the same equivalence class if the following hold:
$$\exists c : \C.\; \forall x : X.\; \forall y : Y.\; \forall c' : \C.\; x \xto{c'} y \implies x \xto{c \app \langle c' \rangle}_* y$$
$$\exists c : \C.\; \forall x : X.\; \forall y : Y.\; \forall c' : \C.\; x \xto{c'}_* y \implies x \xto{c \app \langle c' \rangle} y$$
In other words, they are equivalent if there are computations for converting between their evidence for any given mapping.
\item[Identity] The identity on $\langle X, \approx \rangle$ is the weakest relation such that $\forall x, x' : X.\; \forall c : \C.\; x \xequals{c} x' \implies x \xto{c} x'$.
\item[Composition] The weakest relation such that $\forall x : X.\; \forall y : Y.\; \forall z : Z.\; \forall c, c' : \C.\; x \xto{c} y \wedge y \xto{c'} z \implies x \xto{\lambda \langle p \rangle.\; p~\langle c, c' \rangle} z$.
\end{description}
\end{definition}

\begin{notation}
We can denote the equality and maps-to relations with functions $X \times X \to \Set \C$ and $X \times Y \to \Set \C$ respectively.
\end{notation}

\begin{theorem}
$\langle \mathbb{1}, (1,1 \mapsto \C) \rangle$ and $\langle \mathbb{1}, (1,1 \mapsto \{\lambda x.\; x\}) \rangle$ (or any other nonempty set) are terminal objects of $\cat{Eff}$.
\end{theorem}

\begin{theorem}
Given $\langle X, R \rangle$ and $\langle Y, S \rangle$, their product in $\cat{Eff}$ is $\langle X \times Y, (\langle x, y \rangle, \langle x', y' \rangle \mapsto \{(\lambda \langle p \rangle.\; p~\langle c_x, c_y \rangle) \mid c_x \in R(x, x') \wedge c_y \in S(y, y') \}) \rangle$.
\end{theorem}

\begin{theorem}
Given $F$ and $G$ from $\langle X, R \rangle$ to $\langle Y, S \rangle$, their equalizer in $\cat{Eff}$ is $\langle X, (x, x' \mapsto \{ (\lambda \langle p \rangle.\; p~\langle c_x, c_f, c_y \rangle) \mid c_x \in R(x, x') \wedge \exists y : Y.\; c_f \in F(x, y) \wedge c_g \in G(x', y) \}) \rangle$.
\end{theorem}

\begin{theorem}
$\top \oplus \top$ (i.e.~$\B$) is $\langle \B, (b_1, b_2 \mapsto \{(\mathbf{if~}b_1\mathbf{~then~}\pi_1^2\mathbf{~ else~}\pi_2^2) \mid b_1 = b_2\}) \rangle$.
\end{theorem}

\begin{theorem}
$\cat{Eff}$ is Boolean only if the halting problem is decidable.
\end{theorem}
\begin{proof}
Let $\mathbb{H}$ be $\{ c : \C \mid \exists c' : \C.\; c \app \langle \rangle = c' \}$.
There is a monomorphism~$\mo{h}$ from $\langle \mathbb{H}, (c \mapsto \{c\}) \rangle$ to $\langle \C, (c \mapsto \{c\}) \rangle$ given by $(h, c \mapsto \{h \mid h = c\})$ (i.e.~the obvious inclusion).
If $\B$ were a subobject classifier, then there would be a morphism $\chi_\mo{h} : \langle \C, (c \mapsto \{c\}) \rangle \mto \B$ such that $\chi_\mo{h}(c, b)$ is nonempty if and only if $b$ indicates whether $c \app \langle \rangle$ produces an output (i.e.~if and only if $c$ halts on the empty input).
Let $c_t$ be a code evidencing that $\chi_\mo{h}$ is left total, and let $c_s$ be a code evidencing that $\chi_\mo{h}$ is strict.
Then $\lambda x.\; c_s~\langle \pi_2^2, c_t~\langle x \rangle \rangle$ must be a code that takes a code~$c$ and outputs either $\pi_1^2$ if $c \app \langle \rangle$ produces an output or $\pi_2^2$ if $c \app \langle \rangle$ does not produce an output, thereby deciding the halting problem.
\end{proof}

\begin{definition}[Strict Predicate for an Effective Set $\langle X, R \rangle$]
A function $K : X \to \Set \C$ satisfying the following two properties:
$$\exists c : \C.\; \forall x : X.\; \forall c_k \in K(x).\; c \app \langle c_k \rangle \in R(x, x)$$
$$\exists c : \C.\; \forall x, x' : X.\; \forall c_k \in K(x).\; \forall c_x \in R(x, x').\; c \app \langle c_k, c_x \rangle \in K(x')$$
\end{definition}

\begin{theorem}
Given a subobject $M : \langle Y, S \rangle \mono \langle X, R \rangle$ in $\cat{Eff}$, there exists a strict predicate~$K$ for $\langle X, R \rangle$ such that $M$ is isomorphic (as a subobject) to $\langle X, R_K \rangle$ with the obvious inclusion, where $R_K$ is defined as $(x, x' \mapsto \{ (\lambda p.\; p~\langle c_x, c_k, c_k' \rangle \mid c_x \in R(x, x') \wedge c_k \in K(x) \wedge c_k' \in K(x') \})$.
\end{theorem}

\begin{theorem}
$\Omega = \langle \Set \C, (C, C' \mapsto \{ (\lambda p.\; p~\langle f, f' \rangle) \mid (\forall c \in C.\; f \app \langle c \rangle \in C') \wedge (\forall c' \in C'.\; f' \app \langle c' \rangle \in C) \rangle \}) \rangle$ along with the morphism $\mathbf{true} = (1, C \mapsto C) : \langle \mathbb{1}, (1 \mapsto \C) \rangle \mto \Omega$ is a subobject classifier in $\cat{Eff}$.

Given a subobject $M$ of $\langle X, R \rangle$, let $K$ be a corresponding strict predicate.
Then the characterizing morphism $\chi_M : \langle X, R \rangle \mto \Omega$ is $(x, C \mapsto \{ (\lambda p.\; p~\langle c_x, f, f' \rangle) \mid c_x \in R(x, x) \wedge (\forall c : C.\; f \app \langle c \rangle \in K(x)) \wedge (\forall k : K(x).\; f' \app \langle k \rangle \in C) \})$.
\end{theorem}

\begin{theorem}
$\cat{Eff}$ is two-valued.
\end{theorem}
\begin{proof}
Every morphism from $\top$ to $\Omega$ corresponds to an isomorphic class of subobjects of $\top$, which corresponds to an isomorphic class of strict predicates on $\top$.
There are only two such isomorphic classes: the strict predicate mapping the unique element of $\top$ to the empty set, and the strict predicates mapping the unique element of $\top$ to a nonmepty set.
\end{proof}

\begin{theorem}
Given $\langle X, R \rangle$ and $\langle Y, S \rangle$, their exponential (with respect to products) is the subobject of $\langle X \times Y \to \Set \C, (F, G \mapsto \{ (\lambda \langle p \rangle.\; p~\langle f, f' \rangle) \mid \forall x : X.\; \forall y : Y.\; (\forall c \in F(x, y).\; f \app c \in G(x, y)) \wedge (\forall c' \in G(x, y).\; f' \app c \in F(x, y)) \}) \rangle$ given by the strict predicate mapping $F$ to the set of quadruples of codes exhibiting the four properties required for morphisms.
\end{theorem}

\begin{theorem}
The natural-numbers object is $\langle \N, \text{(map each number to its Church encoding)} \rangle$.
\end{theorem}

\begin{remark}
I am uncertain which of the following require a classical metalogic to prove.
\end{remark}

\begin{theorem}[Church's Thesis]
There is a bijection between the set of endomorphisms on the natural-numbers object of $\cat{Eff}$ and the set of computable functions from the natural numbers to the natural numbers.
\end{theorem}

\begin{theorem}[Markov's Principle]
The following proposition, interpreted as an element of $\Omega$ in $\cat{Eff}$, equals $\mathbf{true}$:
$$\forall \phi : \ob{N} \expto \Omega.\; \neg \neg (\exists n : \ob{N}.\; \phi(n)) \imply \exists n : \ob{N}.\; \phi(n)$$
\end{theorem}

\begin{theorem}[Brouwer's Principle]
The following proposition, interpreted as an element of $\Omega$ in $\cat{Eff}$, equals $\mathbf{true}$:
$$\forall f : (\ob{N} \expto \ob{N}) \expto \ob{N}.\; \forall g : \ob{N} \expto \ob{N}.\; \exists n : \ob{N}.\; \forall g' : \ob{N} \expto \ob{N}.\; \forall i : \ob{N}.\; i \leq n \wedge g(i) = g'(i) \imply f(g) = f(g')$$
\end{theorem}

\end{document}
