···55\p{These lecture notes are based on the material I used to teach the [[typesig-dt]] course at the [[uoe]] in 2024.}
66\transclude{dt-0005}
77\transclude{dt-001Z}
88-\subtree{
99-\taxon{Lecture}
1010-\title{Recursively Defined Domains}
1111-\p{todo}
1212-}
88+\transclude{dt-004Z}
139\subtree{
1410\taxon{Lecture}
1511\title{Scott Domains}
···4137\transclude{dt-004G}
4238\transclude{dt-004H}
4339\transclude{dt-004I}
4040+\transclude{dt-004O}
44414542\scope{
4643\put\transclude/toc{false}
+13
trees/dt/dt-004J.tree
···11+\import{dt-macros}
22+\title{Why we need recursively defined domains}
33+\author{liamoc}
44+\p{ We saw recursive domain equations with higher-order procedures in \ref{dt-0007}, but there are numerous other examples where they come up. }
55+\transclude{dt-004L}
66+\transclude{dt-004M}
77+\p{How can we find solutions to such recursive equations? How can we guarantee the existence of a (least) solution?
88+}
99+\p{We can start by generalising [the fixed point approach](dt-001I) we used for values (i.e. elements of [cpos](dt-001D)) to domains (i.e. [cpos](dt-001D) themselves).}
1010+\transclude{dt-004N}
1111+\p{
1212+To ensure that least fixed points exist, and to give us a means of finding them, we must now generalise all of the concepts we used for least fixed points on values ([information ordering](dt-000B), [least upper bounds](dt-0017), [continuity](dt-001J) etc.) to domains themselves.
1313+}
+9
trees/dt/dt-004K.tree
···11+\taxon{Definition}
22+\title{Untyped #{\lambda}-calculus}
33+\author{liamoc}
44+\p{
55+ Untyped #{\lambda}-calculus consists only of untyped (higher-order) functions:
66+ ##{
77+ e \; \Coloneqq \; x \mid \lambda x. e \mid e_1\ e_2
88+}
99+}
+11
trees/dt/dt-004L.tree
···11+\import{dt-macros}
22+\title{Recursive algebraic data types}
33+\author{liamoc}
44+\p{Suppose we have a language with recursive data types, such as this #{\mathit{List}} type in Haskell-style syntax:
55+##{
66+\textbf{data}\ \mathit{List} = \mathsf{Nil} \mid \mathsf{Cons}\ (\mathit{Int} \times \mathit{List}) }
77+As in [PCF](dt-003T), the denotation of a type #{\tau} is the domain which contains all the denotations of all closed expressions of type #{\tau}. What, then, is the domain that corresponds to #{\mathit{List}\ a}? We need a [cpo](dt-001D) #{L} that satisfies the below equation (where #{\mathbf{1}} is the [cpo](dt-001D) containing just one element #{\bot}):
88+##{
99+L \simeq \mathbf{1} + (\mathbb{Z}_\bot \times L)
1010+}
1111+}
+11
trees/dt/dt-004M.tree
···11+\import{dt-macros}
22+\author{liamoc}
33+\title{Untyped higher-order languages}
44+\p{
55+ If we take [PCF](dt-003T), \em{discard} the type system, #{\syn{fix}}, natural number primitives and any other superfluous features, and just boil our language down to a minimal, Turing-complete subset, we end up with the [untyped #{\lambda}-calculus](dt-004K) — a language consisting only of untyped functions.}
66+\transclude{dt-004K}
77+\p{Trying to give a semantics to the [untyped #{\lambda} calculus](dt-004K) poses an issue: we can no longer rely on the type of an expression to select an appropriate semantic domain. Instead, we we must pick a \em{single} domain #{D} which, since functions can be applied to themselves, must apparently include the set of functions #{D \contto D}:
88+##{
99+D \simeq D\contto D
1010+}
1111+}
+13
trees/dt/dt-004N.tree
···11+\import{dt-macros}
22+\taxon{Example}
33+\author{liamoc}
44+\title{Recursive domain equations as endofunctors}
55+\p{This recursive equation for lists:
66+##{
77+L \simeq \mathbf{1} + (\mathbb{Z}_\bot \times L)
88+}
99+Can be expressed as the least fixed point of this mapping (specifically an [endofunctor](dt-004T)) #{\mathcal{F}} on [cpos](dt-001D):
1010+##{
1111+\mathcal{F}(A) \triangleq \mathbf{1} + (\mathbb{Z}_\bot \times A)
1212+}
1313+}
+23
trees/dt/dt-004O.tree
···11+\import{dt-macros}
22+\author{liamoc}
33+\title{From a cpo to the [category #{\mathbf{Cpo}}](dt-002B)}
44+\problemblock{
55+ \p{The following definitions are \strong{insufficient} when using [function](dt-002L) constructions in our domain equations (#{\contto} and #{\strictto}), but it will suffice for our purposes for now.}
66+}
77+\p{Let us say (for now) that a [cpo](dt-001D) #{A} \em{approximates} a [cpo](dt-001D) #{B} (i.e. #{A \sqsubseteq B}) iff there is a [continuous function](dt-001J) #{f : A\contto B}. Then, there is a least element for this ordering: the one-element [cpo](dt-001D) #{\mathbf{1} = \Set{ \bot }}, as the [continuous function](dt-001J) #{(\lambda x. \bot) : \mathbf{1} \contto A} exists for any [cpo](dt-001D) #{A}.}
88+\scope{
99+\put\transclude/toc{false}
1010+\put\transclude/numbered{false}
1111+\subtree{
1212+\title{Initiality}
1313+\taxon{Categorical Aside}
1414+\p{The [category #{\mathbf{Cpo}}](dt-002B) has no initial object. The [cpo](dt-001D) #{\mathbf{1}} is terminal; but also serves as a "pseudo" initial object due to the above.}
1515+}
1616+}
1717+\transclude{dt-004P}
1818+\transclude{dt-004T}
1919+\transclude{dt-004U}
2020+\transclude{dt-004V}
2121+\transclude{dt-004W}
2222+\transclude{dt-004X}
2323+\transclude{dt-004Y}
+6
trees/dt/dt-004P.tree
···11+\import{dt-macros}
22+\author{liamoc}
33+\title{Colimits in the [category #{\mathbf{Cpo}}](dt-002B)}
44+\transclude{dt-004Q}
55+\transclude{dt-004R}
66+\transclude{dt-004S}
+11
trees/dt/dt-004Q.tree
···11+\import{dt-macros}
22+\author{liamoc}
33+\taxon{Definition}
44+\title{#{\omega}-chains of cpos in the category #{\mathbf{Cpo}}}
55+\p{An [#{\omega}-chain](dt-000W) of [cpos](dt-001D) in the [category #{\mathbf{Cpo}}](dt-002B) consists of a family of [cpos](dt-001D) #{\Set{A_i \mid i \in \mathbb{N} }}, together with a family of [continuous functions](dt-001J) #{\Set{ f_i : A_i\contto A_{i+1} \mid i \in \mathbb{N}}}, shown below:}
66+\figure{
77+\tex{\usepackage{tikz-cd}}{
88+\begin{tikzcd}
99+ A_0 \ar[r,thick,"f_0"'] & A_1 \ar[r,thick,"f_1"'] & A_2 \ar[r,thick,"f_2"'] & A_3 \ar[r,thick,-,dotted] & \quad
1010+\end{tikzcd}
1111+}}
+11
trees/dt/dt-004R.tree
···11+\import{dt-macros}
22+\taxon{Definition}
33+\title{Upper bounds in the category #{\mathbf{Cpo}}}
44+\p{A [cpo](dt-001D) #{A} is an [upper bound](dm-000C) of an [#{\omega}-chain of cpos](dt-004Q) in [the category #{\mathbf{Cpo}}](dt-002B) if there is a family of [continuous functions](dt-001J) #{\Set{g_i : A_i \contto A \mid i \in \mathbb{N}}} such that the following diagram commutes (i.e. #{g_i = g_{i+1} \circ f_i} for all #{i \in \mathbb{N}}):}
55+\figure{\tex{\usepackage{tikz-cd}}{
66+\begin{tikzcd}
77+& & & A & \\
88+& & & & \cdots\\
99+ A_0 \ar[r,thick,"f_0"'] \ar[uurrr,"g_0"near start] & A_1 \ar[r,thick,"f_1"']\ar[uurr,"g_1"near start] & A_2 \ar[r,thick,"f_2"'] \ar[uur,"g_2"near start] & A_3 \ar[uu,"g_3"near start] \ar[r,thick,-,dotted] & \quad
1010+\end{tikzcd}
1111+}}
+17
trees/dt/dt-004S.tree
···11+\import{dt-macros}
22+\author{liamoc}
33+\taxon{Definition}
44+\title{Least upper bounds in the category #{\mathbf{Cpo}}}
55+\p{A [cpo](dt-001D) #{A} is the [\em{least} upper bound](dt-0017) of an [#{\omega}-chain of cpos](dt-004Q) if is both an [upper bound](dt-004R) and if there exists a \em{unique} #{k} for any other [upper bound](dt-004R) #{B} such that the following diagram commutes (i.e. #{h_i = g_i \circ k} for all #{i \in \mathbb{N}}):}
66+\figure{
77+\tex{\usepackage{tikz-cd}}{
88+\begin{tikzcd}
99+& & & B & \\
1010+& & & & \cdots\\
1111+& & & A \ar[uu,thick,dashed,"k"] & \\
1212+& & & & \cdots\\
1313+ A_0 \ar[r,thick,"f_0"'] \ar[uuuurrr,"h_0", bend left] \ar[uurrr,"g_0"near start] & A_1 \ar[r,thick,"f_1"']\ar[uurr,"g_1"near start]\ar[uuuurr,"h_1", bend left] & A_2 \ar[r,thick,"f_2"'] \ar[uur,"g_2"near start] \ar[uuuur,"h_2", bend left] & A_3 \ar[uu,"g_3"near start] \ar[r,thick,-,dotted] \ar[uuuu,"h_3", bend left=3.5em] & \quad
1414+\end{tikzcd}
1515+}}
1616+\p{The least upper bound of such an #{\omega}-chain is also called its \em{colimit}.}
1717+\p{\strong{Note}: Uniqueness of lubs is up to isomorphism. That is, if #{A} and #{B} are both colimits of our #{\omega}-chain, then #{A \simeq B}.}
+10
trees/dt/dt-004T.tree
···11+\import{dt-macros}
22+\taxon{Definition}
33+\author{liamoc}
44+\title{Endofunctors on #{\textbf{Cpo}}}
55+\p{An \em{endofunctor} on [the category #{\textbf{Cpo}}](dt-002B) is a [functor](dm-000J) #{\textbf{Cpo} \rightarrow \textbf{Cpo}}, i.e. a mapping #{\mathcal{F}} on [cpos](dt-001D) together with a mapping #{\mathcal{F}} on [continuous functions](dt-001J), such that:}
66+\ol{
77+\li{If #{f : A \contto B} then #{\mathcal{F}(f) : \mathcal{F}(A)\contto \mathcal{F}(B)} }
88+\li{#{\mathcal{F}(\mathsf{id}_A : A\contto A) = \mathsf{id}_{\mathcal{F}(A)} : \mathcal{F}(A)\contto \mathcal{F}(A)}}
99+\li{#{\mathcal{F}(f \circ g) = \mathcal{F}(f) \circ \mathcal{F}(g)}}
1010+}
+6
trees/dt/dt-004U.tree
···11+\import{dt-macros}
22+\taxon{Remark}
33+\author{liamoc}
44+\p{
55+Observe that, given the [information ordering for cpos](dt-004O) where #{A \sqsubseteq B} if there exists a continuous function #{A \contto B}, the [functor](dm-000J) laws necessarily imply [monotonicity](dt-000J) for all [endofunctors](dt-004T) #{\mathcal{F}}.
66+}
+22
trees/dt/dt-004V.tree
···11+\import{dt-macros}
22+\title{Cocontinuous endofunctors}
33+\taxon{Definition}
44+\p{An [endofunctor](dt-004T) #{\mathcal{F}} is \em{cocontinuous} iff it preserves [colimits](dt-004S) of [#{\omega}-chains of cpos](dt-004Q). That is, given a [chain](dt-004Q) where #{A} is a [colimit](dt-004S):
55+\figure{
66+\tex{\usepackage{tikz-cd}}{
77+\begin{tikzcd}
88+& & & A & \\
99+& & & & \cdots\\
1010+ A_0 \ar[r,thick,"f_0"'] \ar[uurrr,"g_0"near start] & A_1 \ar[r,thick,"f_1"']\ar[uurr,"g_1"near start] & A_2 \ar[r,thick,"f_2"'] \ar[uur,"g_2"near start] & A_3 \ar[uu,"g_3"near start] \ar[r,thick,-,dotted] & \quad
1111+\end{tikzcd}
1212+}}
1313+Then #{\mathcal{F}(A)} is a [colimit](dt-004S) for the following [chain](dt-004Q):
1414+\figure{
1515+\tex{\usepackage{tikz-cd}}{
1616+\begin{tikzcd}[row sep=3.6em]
1717+& & & \mathcal{F}(A) & \\
1818+& & & & \cdots\\
1919+ \mathcal{F}(A_0) \ar[r,thick,"\mathcal{F}(f_0)"',->] \ar[uurrr,"\mathcal{F}(g_0)"near start] & \mathcal{F}(A_1) \ar[r,thick,"\mathcal{F}(f_1)"',->]\ar[uurr,"\mathcal{F}(g_1)"near start] & \mathcal{F}(A_2) \ar[r,thick,"\mathcal{F}(f_2)"',->] \ar[uur,"\mathcal{F}(g_2)"near start] & \mathcal{F}(A_3) \ar[uu,"\mathcal{F}(g_3)"near start] \ar[r,thick,-,dotted] & \quad
2020+\end{tikzcd}
2121+}}
2222+}
+11
trees/dt/dt-004W.tree
···11+\import{dt-macros}
22+\author{liamoc}
33+\taxon{Definition}
44+\title{Fixed points of [endofunctors on #{\mathbf{Cpo}}](dt-004T)}
55+\p{A [fixed point](dt-000S) of an [endofunctor on cpos](dt-004T) #{\mathcal{F}} is a [cpo](dt-001D) #{\mathcal{F}} such that #{\mathcal{F}(A) \simeq A}. }
66+\scope{
77+\put\transclude/toc{false}
88+\put\transclude/numbered{false}
99+\subtree{\taxon{Note}
1010+\p{In Scott's approach, which we follow here, our fixed points are up to [isomorphism](dt-002E) (suitable for languages with \em{isorecursive} types), but there are other approaches where they are equalities (suitable for languages with \em{equirecursive} types).
1111+}}}
+13
trees/dt/dt-004X.tree
···11+\import{dt-macros}
22+\author{liamoc}
33+\taxon{Theorem}
44+\title{Fixed point theorem for endofunctors on #{\mathbf{Cpo}}}
55+\p{ Every [cocontinuous endofunctor](dt-004V) #{\mathcal{F}} on [cpos](dt-001D) has a [least fixed point](dt-004W), given by the [colimit](dt-004S) of the [#{\omega}-chain](dt-004Q):}
66+\figure{
77+\tex{\usepackage{tikz-cd}}{\begin{tikzcd}[column sep=5.2em]
88+ \mathbf{1} \ar[r,"\lambda x.\bot"] &
99+ \mathcal{F}(\mathbf{1}) \ar[r,"\mathcal{F}(\lambda x.\bot)"] &
1010+ \mathcal{F}(\mathcal{F}(\mathbf{1})) \ar[r,"\mathcal{F}(\mathcal{F}(\lambda x.\bot))"] &
1111+ \mathcal{F}(\mathcal{F}(\mathcal{F}(\mathbf{1}))) \ar[r,thick,-,dotted] & \quad
1212+\end{tikzcd}
1313+}}
+74
trees/dt/dt-004Y.tree
···11+\taxon{Example}
22+\import{dt-macros}
33+\author{liamoc}
44+\title{Binary Numbers}
55+\p{
66+Consider the Haskell-style data type:
77+##{
88+\textbf{data}\ \mathit{Bin} = \mathsf{Zero}\ \mathit{Bin} \mid \mathsf{Empty} \mid \mathsf{One}\ \mathit{Bin}
99+}
1010+So, e.g. #{\mathsf{One}\ (\mathsf{Zero}\ (\mathsf{One}\ \mathsf{Empty})) : \mathit{Bin}}.}
1111+\p{ The recursive domain equation is, expressed as a fixed point:
1212+##{
1313+B \simeq \mathcal{F}(B)\quad\text{where}\ \mathcal{F}(X) = X + \mathbf{1} + X
1414+}
1515+We wish to show that #{\mathcal{F}} is a [cocontinuous endofunctor](dt-004V).}
1616+\p{We have a mapping #{\mathcal{F}} on [cpos](dt-001D) (objects of [the category #{\textbf{Cpo}}](dt-002B)), but for it to be a [functor](dm-000J) we additionally need a mapping #{\mathcal{F}} on [continuous functions](dt-001J) (morphisms of [the category #{\textbf{Cpo}}](dt-002B)). }
1717+1818+\p{Recalling [our sum construction](dt-0031), we may remember that sums are already a [bifunctor](dm-000M) #{\textbf{Cpo} \times \textbf{Cpo} \rightarrow \textbf{Cpo}} (\ref{dt-0038}). Thus, our mapping on [continuous functions](dt-001J) #{\mathcal{F}} can be \em{derived} from our mapping on [cpos](dt-001D) #{\mathcal{F}} by using the morphism mapping from the sum construction (\ref{dt-0037}). Given a continuous function #{f : A \contto B}, our morphism mapping is:}
1919+##{
2020+\begin{array}{l}
2121+\mathcal{F}(f) : \mathcal{F}(A)\contto \mathcal{F}(B)\\
2222+\mathcal{F}(f) \triangleq f + \mathsf{id}_\textbf{1} + f
2323+\end{array}
2424+}
2525+\p{Proof that this [endofunctor](dt-004T) is [cocontinuous](dt-004V) is left for the reader. Hence the semantics of the type #{\mathit{Bin}}, i.e. #{\llbracket \mathit{Bin} \rrbracket : \textbf{Cpo}} is the least fixed point of #{\mathcal{F}}, i.e. the [colimit](dt-004S) of the [#{\omega}-chain](dt-004Q):}
2626+\figure{
2727+\tex{\usepackage{tikz-cd}}{
2828+\begin{tikzcd}[column sep=5.2em]
2929+ \mathbf{1} \ar[r,"\lambda x.\bot"] &
3030+ \mathcal{F}(\mathbf{1}) \ar[r,"\mathcal{F}(\lambda x.\bot)"] &
3131+ \mathcal{F}(\mathcal{F}(\mathbf{1})) \ar[r,"\mathcal{F}(\mathcal{F}(\lambda x.\bot))"] &
3232+ \mathcal{F}(\mathcal{F}(\mathcal{F}(\mathbf{1}))) \ar[r,thick,-,dotted] & \quad
3333+\end{tikzcd}
3434+}}
3535+\p{Let us visualise this chain. Here the sum injections have been written as #{\textsf{Z, E, O}} rather than (combinations of) #{\textsf{inl}} and #{\textsf{inr}} to keep the connection with the Haskell data type clear. }
3636+\figure{
3737+\tex{\usepackage{tikz}}{
3838+\begin{tikzpicture}
3939+ \node[draw, fill=white, rounded corners] (b1) at (0,0) {$\bot$};
4040+ \draw[->,ultra thick,dotted] (6,1.5) -- (10.5,1.5);
4141+ \draw[fill=white!95!black, rounded corners=2em] (6,-1) -- (10,3.5) -- (2,3.5) -- cycle;
4242+ \draw[fill=white!97!black, rounded corners=2em,dashed] (6,-0.8) -- (8.1,1.5) -- (3.9,1.5) -- cycle;
4343+ \draw[->,ultra thick] (2,0.5) -- (4.8,0.5);
4444+ \draw[fill=white!97!black, rounded corners=2em] (2,-0.8) -- (3.8,1.5) -- (0.2,1.5) -- cycle;
4545+ \node[draw, fill=white, dashed, rounded corners] (b2) at (2,0) {$\bot$};
4646+ \draw[->,ultra thick] (b1) -- (b2);
4747+ \node (a1) at (1.2,1) {$\mathsf{Z}(\bot)$};
4848+ \node (a2) at (2,1.04) {$\mathsf{E}$};
4949+ \node (a3) at (2.8,1) {$\mathsf{O}(\bot)$};
5050+ \draw[-] (b2) -- (a2);
5151+ \draw[-] (b2) -- (a3);
5252+ \draw[-] (b2) -- (a1);
5353+ \node (b2) at (6,0) {$\bot$};
5454+ \node (a1) at (5,1) {$\mathsf{Z}(\bot)$};
5555+ \node (a2) at (6,1.04) {$\mathsf{E}$};
5656+ \node (a3) at (7,1) {$\mathsf{O}(\bot)$};
5757+ \draw[-] (b2) -- (a2);
5858+ \draw[-] (b2) -- (a3);
5959+ \draw[-] (b2) -- (a1);
6060+ \node (c1) at (3.3,3) {\footnotesize $\mathsf{Z}(\mathsf{Z}(\bot))$};
6161+ \node (c2) at (4.3,3) {\footnotesize $\mathsf{Z}(\mathsf{E})$};
6262+ \node (c3) at (5.3,3) {\footnotesize $\mathsf{Z}(\mathsf{O}(\bot))$};
6363+ \draw[-] (a1) -- (c2);
6464+ \draw[-] (a1) -- (c3);
6565+ \draw[-] (a1) -- (c1);
6666+ \node (c1) at (6.7,3) {\footnotesize $\mathsf{O}(\mathsf{Z}(\bot))$};
6767+ \node (c2) at (7.7,3) {\footnotesize $\mathsf{O}(\mathsf{E})$};
6868+ \node (c3) at (8.7,3) {\footnotesize $\mathsf{O}(\mathsf{O}(\bot))$}; \draw[-] (a3) -- (c2);
6969+ \draw[-] (a3) -- (c3);
7070+ \draw[-] (a3) -- (c1);
7171+\end{tikzpicture}
7272+}}
7373+\p{Thus, the #{n}th cpo in the chain contains binary numbers with at most #{n} defined digits. The [colimit](dt-004S) of the chain contains all binary numbers (finite, partial, and infinite!).
7474+}
+7
trees/dt/dt-004Z.tree
···11+\taxon{Lecture}
22+\author{liamoc}
33+\title{Recursively Defined Domains}
44+\p{This lecture is based on material from [[haskellhutt]], [[jlongley]],[[danascott]], [[jstoy]], [[cgunter]], and [[gwinskel]].}
55+\transclude{dt-004J}
66+\transclude{dt-004O}
77+\p{\strong{TODO: Retraction pairs stuff}}