···11+\import{dt-macros}
12\taxon{Lecture Notes}
23\title{Domain theory}
34\author{liamoc}
···1415\title{Scott Domains}
1516\transclude{dt-0040}
1617\subtree{
1717-\title{Algebraicity and Ideals}
1818+\title{Algebraicity and ideals}
1919+\transclude{dt-0041}
2020+\transclude{dt-0042}
2121+\transclude{dt-0043}
2222+\transclude{dt-0045}
2323+\transclude{dt-0044}
2424+\transclude{dt-0047}
2525+\transclude{dt-0048}
2626+\transclude{dt-0046}
2727+\transclude{dt-0049}
1828}
1929\subtree{
2020-\title{Getting Closure}
3030+\title{Getting closure}
3131+\transclude{dt-004A}
3232+\transclude{dt-004B}
3333+\transclude{dt-004C}
3434+\problemblock{
3535+#{\omega}-[algebraic](dt-0041) [cpos](dt-001D) are closed under all of our constructions ([products](dt-0021) and [sums](dt-0031), including [strict versions of these](dt-003E)) \strong{except} functions #{\contto} and strict functions #{\strictto}!
3636+}
3737+3838+\transclude{dt-004D}
3939+\transclude{dt-004E}
4040+\transclude{dt-004F}
4141+\transclude{dt-004G}
4242+\transclude{dt-004H}
4343+\transclude{dt-004I}
4444+4545+\scope{
4646+\put\transclude/toc{false}
4747+\put\transclude/numbered{false}
4848+\subtree{\taxon{Thesis}
4949+\p{Our semantic domains are [Scott domains](dt-004G).}
5050+}}
5151+5252+2153}
2254}
2355\subtree{
+1-1
trees/dt/dt-003Z.tree
···22\author{liamoc}
33\title{Both infinite and compact}
44\taxon{Exercise}
55-\p{Find a set in the [cpo of submonoids](dt-003Y) of #{(\mathbb{N},0,+)} that is \em{both} infinite and [compact](dt-003U)}
55+\p{Find a set in the [cpo of submonoids](dt-003Y) of #{(\mathbb{N},0,+)} that is \em{both} infinite and [compact](dt-003U).}
6677\solnblock{
88\p{Take #{E \triangleq \Set{ n \in \mathbb{N} \mid n\ \text{is even}}}. Let #{Y \subseteq \pow{\mathbb{N}}} be directed and #{E \subseteq \bigcup Y}. Since #{2 \in E} there must exist #{y \in Y} such that #{2 \in Y}. Since #{(y,0,+)} is a [monoid](dm-000O), every positive multiple of #{2} is also in #{y}, thus #{E \subseteq y} and therefore #{E} is [compact](dt-003U).}
+1
trees/dt/dt-0040.tree
···3030\p{In the example cpo #{X} above, all the elements except #{\infty} and #{x} would be [compact](dt-003U). Thus, compactness better captures our notion of an element representing a finite amount of information. This understanding of [compact](dt-003U) elements is a generalisation of the notion of a finite element from the theory of algebraic lattices.}
3131\transclude{dt-003V}
3232\transclude{dt-003X}
3333+\transclude{dt-003Y}
3334\transclude{dt-003Z}
+12
trees/dt/dt-0041.tree
···11+\import{dt-macros}
22+\author{liamoc}
33+\taxon{Definition}
44+\title{Algebraicity}
55+\p{A [cpo](dt-001D) is \em{algebraic} iff every element is the [lub](dt-0017) of its [compact](dt-003U) approximations. That is, a [cpo](dt-001D) #{D} is \em{algebraic} iff for all #{x \in D},
66+\ol{
77+\li{#{\downset{x} = \Set{ y \in \compact{D} \mid y \sqsubseteq x }} is [directed](dt-0010);}
88+\li{#{x = \bigsqcup\downset{x}}}
99+}
1010+\strong{Note}: It's common in semantics to consider only algebraic [cpos](dt-001D) with a \em{countable} set of [compact](dt-003U) elements. Such [cpos](dt-001D) are called \em{#{\omega}-algebraic}.}
1111+1212+\p{ \strong{Aside}: Plotkin provides an equivalent definition of #{\omega}-algebraic [cpos](dt-001D) in which [directed sets](dt-0010) are replaced with [#{\omega}-chains](dt-000W) throughout. [Hutton](haskellhutt) claims this is less appealing, as the definition speaks of \em{an} [#{\omega}-chain](dt-000W) of [compact](dt-003U) approximations, rather than \em{the} [directed set](dt-0010) of such.}
+7
trees/dt/dt-0042.tree
···11+\import{dt-macros}
22+\taxon{Example}
33+\title{#{\omega}-algebraic cpos}
44+\author{liamoc}
55+\p{
66+Many standard examples of [cpos](dt-001D) are #{\omega}-[algebraic](dt-0041) [cpos](dt-001D): finite cpos, subsets #{\pow{X}} of a set #{X}, partial functions #{\mathbb{N} \nrightarrow \mathbb{N}} and [submonoids of a monoid](dt-003Y). In general, any [cpo](dt-001D) of subalgebras (e.g. subgroups of a group, subrings of a ring etc.) is #{\omega}-[algebraic](dt-0041). This is the origin of the terminology.
77+}
+20
trees/dt/dt-0043.tree
···11+\import{dt-macros}
22+\import{table-macros}
33+\taxon{Counterexample}
44+\author{liamoc}
55+\title{Non-algebraic cpo}
66+\<html:div>[class]{sidefigure}{
77+\tex{\usepackage{tikz-cd}\usetikzlibrary{decorations.pathreplacing}\usepackage{amsmath}}{
88+ \begin{tikzcd}
99+ \infty\\
1010+ 1\ar[u,thick,-,dotted] & & x\ar[ull,thick,-]\\
1111+ 0\ar[u,thick,-] \\
1212+ & \bot \ar[ul,thick,-]\ar[uur,thick,-]
1313+ \end{tikzcd}
1414+}
1515+}
1616+\p{In the [cpo](dt-001D) on the right (seen also in \ref{dt-0040}), the element #{x} is not the [lub](dt-0017) of its [compact](dt-003U) approximations. The only [compact](dt-003U) element that approximates #{x} is #{\bot}, and the [least upper bound](dt-0017) of the set #{\Set{\bot}} is just #{\bot}, not #{x}. That is:
1717+##{\downset{x} = \Set{\bot}}
1818+but:
1919+##{x \neq \bigsqcup\Set{\bot}}
2020+}
+22
trees/dt/dt-0044.tree
···11+\import{dt-macros}
22+\author{liamoc}
33+\taxon{Exercise}
44+\p{Let #{f : D \contto E} be a [continuous](dt-001J) function between [algebraic](dt-0041) [cpos](dt-001D). Define:
55+##{G_f = \Set{ (a,b) \in \compact{D} \times \compact{E} \mid b \sqsubseteq f(a) }}
66+Then for all #{x \in D}, prove that:
77+##{
88+f(x) = \bigsqcup\ \Set{ b \mid (a,b) \in G_f \land a \sqsubseteq x }
99+}
1010+}
1111+\solnblock{
1212+##{
1313+\begin{array}{lclr}
1414+f(x) & = & f(\bigsqcup \downset{x}) & \text{($D$ is {algebraic})}\\
1515+&=&\bigsqcup\ \{ f(a) \mid a \in \downset{x} \} & \text{($f$ is continuous)}\\
1616+&=&\bigsqcup\ \left\{ \bigsqcup \downset{f(a)} \mid a \in \downset{x} \right\} & \text{($E$ is {algebraic})}\\
1717+&=&\bigsqcup\ \Set{ b \in \compact{E} \mid b \sqsubseteq f(a) \land a \in \downset{x}} & \text{(lubs and defn of $\downarrow$)}\\
1818+&=&\bigsqcup\ \Set{ b \mid (a,b) \in G_f \land a \sqsubseteq x }&\text{(defn of $G_f$)}
1919+\end{array}
2020+}
2121+}
2222+\p{This is powerful. For example, the [continuous](dt-001J) function #{f : \pow{\mathbb{N}} \contto \pow{\mathbb{N}}} on an \em{uncountable} [cpo](dt-001D) #{\pow{\mathbb{N}}} is completely determined by the \em{countable} relation #{G_f}.}
+32
trees/dt/dt-0045.tree
···11+\import{dt-macros}
22+\author{liamoc}
33+\taxon{Theorem}
44+\title{Nothing suddenly invented at infinity}
55+\p{Let #{D} and #{E} be [algebraic](dt-0041) [cpos](dt-001D). Then a function #{f : D \rightarrow E} is [continuous](dt-001J) iff, for all #{x \in D}: ##{f(x) = \bigsqcup\ \Set{ f(a) \mid a \in \downset{x} }}
66+In other words, in an [algebraic](dt-0041) [cpo](dt-001D), [continuous functions](dt-001J) are completely defined by their behaviour for [compact](dt-003U) arguments.}
77+\p{This makes precise our earlier slogan in \ref{dt-001J}, that [continuous functions](dt-001J) don't suddenly behave differently for infinite (i.e. non-[compact](dt-003U)) elements.}
88+\proofblock{
99+First, assuming #{f} is [continuous](dt-001J), we show that #{f(x) = \bigsqcup\ \Set{ f(a) \mid a \in \downset{x} }}:
1010+##{
1111+\begin{array}{lclr}
1212+f(x) & = & f(\bigsqcup \downset{x}) & \text{($D$ is {algebraic})}\\
1313+&=&\bigsqcup\ \{ f(a) \mid a \in \downset{x} \} & \text{($f$ is continuous)}\\
1414+\end{array}
1515+}
1616+It remains to show that if #{f(x) = \bigsqcup\ \Set{ f(a) \mid a \in \downset{x} }}, then #{f} is [continuous](dt-001J). Using the [alternative definition](dt-001O), we shall first show that #{f} is [monotone](dt-000J). Let #{a \sqsubseteq b} for #{a,b \in D}. Then #{\downset{a} \subseteq \downset{b}} and thus #{\Set{f(x) \mid x \in \downset{a}} \subseteq \Set{f(x) \mid x \in \downset{b}}}, therefore:
1717+##{
1818+\begin{array}{lclr}
1919+f(a) &=&\bigsqcup\ \Set{ f(x) \mid x \in \downset{a} } & \text{(assumption)}\\
2020+ & \sqsubseteq &\bigsqcup\ \Set{ f(x) \mid x \in \downset{b} } & \text{(from above)}\\
2121+ & = & f(b) & \text{(assumption)}\\
2222+\end{array}
2323+}
2424+Next, let #{X \subseteq D} be [directed](dt-0010).
2525+##{\begin{array}{lclr}
2626+f(\bigsqcup X) &=&\bigsqcup\ \Set{ f(x) \mid x \in \downset{\bigsqcup X} } & \text{(assumption)}\\
2727+&=&\bigsqcup\ \Set{ f(x) \mid x \in \compact{X} \land x \sqsubseteq \bigsqcup X } & \text{(defn.~of $\downarrow$)}\\
2828+&=&\bigsqcup\ \Set{ f(x) \mid \exists y \in X.\ x \in \compact{X} \land x \sqsubseteq y } & \text{(compactness)}\\
2929+&=&\bigsqcup\ \Set{ f(x) \mid \exists y \in X.\ x \in \downset{y}} & \text{(defn.~of $\downarrow$)}\\
3030+&=&\bigsqcup\ \Set{ f(x) \mid x \in X} & \text{(algebraicity)}\\
3131+\end{array}}
3232+}
+9
trees/dt/dt-0046.tree
···11+\import{dt-macros}
22+\taxon{Definition}
33+\title{Ideal completion}
44+\author{liamoc}
55+ \p{The \em{ideal completion} of a set #{A}, written sometimes as #{\mathsf{Id}(A)}, is the set of all [ideal](dt-0048) subsets of #{A}, i.e.:
66+##{
77+\mathsf{Id}(A) = \Set{ X \subseteq A \mid X\ \text{is ideal}}
88+}
99+}
+4
trees/dt/dt-0047.tree
···11+\taxon{Definition}
22+\author{liamoc}
33+\title{Down-closure}
44+\p{ Given a [poset](dm-0004) #{Y}, a set #{X \subseteq Y} is \em{down-closed} iff, for all #{x \in X}, any #{y \sqsubseteq x} is in #{X}.}
+4
trees/dt/dt-0048.tree
···11+\taxon{Definition}
22+\author{liamoc}
33+\title{Ideal}
44+\p{ A set is \em{ideal} iff it is both [down-closed](dt-0047) and [directed](dt-0010).}
+7
trees/dt/dt-0049.tree
···11+\import{dt-macros}
22+\author{liamoc}
33+\taxon{Theorem}
44+\title{Representation theorem for [algebraic](dt-0041) [cpos](dt-001D)}
55+\p{ Every [algebraic](dt-0041) [cpo](dt-001D) #{D} is [isomorphic](dt-002E) to the [ideal completion](dt-0046) of its [compact](dt-003U) elements, ordered by subset inclusion. That is, #{\mathsf{Id}(K(D))} is an [algebraic](dt-0041) [cpo](dt-001D) such that #{D \simeq \mathsf{Id}(K(D))
66+}.
77+}
+6
trees/dt/dt-004A.tree
···11+\import{dt-macros}
22+\taxon{Definition}
33+\author{liamoc}
44+\title{Basis}
55+\p{A set of [compact](dt-003U) elements #{X \subseteq \compact{A}} is a \em{basis} for a [cpo](dt-001D) #{A} iff for all #{x\in A}, #{x= \bigsqcup\Set{a \in X \mid a \sqsubseteq x}}.
66+}
+9
trees/dt/dt-004B.tree
···11+\import{dt-macros}
22+\author{liamoc}
33+\taxon{Theorem}
44+\title{Compact basis for algebraic cpos}
55+\p{ If #{X} is a [basis](dt-004A) for #{A}, then #{A} is [algebraic](dt-0041) and #{\compact{A} = X}.
66+}
77+\proofblock{
88+\p{If #{a \in \compact{A}}, then #{\bigsqcup M = a} where #{M = \Set{ x \in X \mid x \sqsubseteq a }}, as #{X} is a [basis](dt-004A). Since #{a} is [compact](dt-003U), #{a \sqsubseteq b} for some #{b \in M}. But since #{a} is the [lub](dt-0017) of #{M}, #{b \sqsubseteq a} as well. By [antisymmetry](dm-0003) #{a = b}, hence #{a \in X}. Thus #{\compact{A} \subseteq X}, so #{\compact{A} = X} and #{A} is [algebraic](dt-0041).
99+}}
+37
trees/dt/dt-004C.tree
···11+\import{dt-macros}
22+\import{table-macros}
33+\author{liamoc}
44+\taxon{Theorem}
55+\title{Closure of algebraic cpos under product}
66+\p{If #{D} and #{E} are [algebraic](dt-0041) [cpos](dt-001D), then so is their product construction #{D \times E}.}
77+\proofblock{
88+\p{In the following proof, we show that #{\compact{D} \times \compact{E}} is a [basis](dt-004A) for the [product](dt-0021) #{D \times E} and thereby show via \ref{dt-004B} that #{D \times E} is [algebraic](dt-0041) if #{D} and #{E} are.}
99+\ol{
1010+\li{
1111+ #{\compact{D} \times \compact{E} \subseteq \compact{D \times E}}: Let #{(x,y) \in \compact{D} \times \compact{E}}. To show that #{(x,y)} is [compact](dt-003U), let us assume that #{(x,y) \in \bigsqcup X} where #{X \subseteq D \times E} is [directed](dt-0010). We must show that there exists some element #{e} of #{X} such that our #{(x,y) \sqsubseteq e}. As #{(x,y) \in \bigsqcup X}, by the definition of [lub](dt-0017) on [products](dt-0021) we can conclude that:
1212+ ##{\begin{array}{lcl}
1313+ x & \sqsubseteq & \bigsqcup \pi_0\lsquare X\rsquare \\
1414+ y & \sqsubseteq & \bigsqcup \pi_1[X]
1515+ \end{array}}
1616+ Here we use the notation #{f[X]} to indicate the image of a function on a set, i.e. #{\Set{ f(v) \mid v \in X }}.\br
1717+1818+ Since #{x} and #{y} are both [compact](dt-003U), there must exist #{x' \in \pi_0\lsquare X\rsquare} and #{y' \in \pi_1\lsquare X\rsquare} such that #{x \sqsubseteq x'} and #{y \sqsubseteq y'}. While it does not follow that #{(x', y') \in X}, we know that there must exist a pair #{(a,b) \in X} such that #{x' \sqsubseteq a} and #{y' \sqsubseteq b} as #{X} is [directed](dt-0010). Hence #{(a,b)} can be our element #{e \in X} that is approximated by #{(x,y)}, i.e. #{(x,y) \sqsubseteq (a,b)}.
1919+}
2020+\li{
2121+ #{\downset{x,y}} is directed for all #{(x,y) \in D \times E}:
2222+##{\begin{array}{lcl}
2323+ \downset{x,y} &= & \Set{ (a,b) \in \compact{D} \times \compact{E} \mid (a,b) \sqsubseteq (x,y) } \\
2424+ & = & \{ a \in \compact{D} \mid a \sqsubseteq x \} \times \Set{ b \in \compact{E} \mid b \sqsubseteq y }\\
2525+ & = & \downset{x} \times \downset{y}
2626+ \end{array}}
2727+ Because #{D} and #{E} are [algebraic](dt-0041), #{\downset{x}} and #{\downset{y}} are [directed](dt-0010). As directedness is closed under [product](dt-002K), #{\downset{x,y}} is [directed](dt-0010) too.
2828+}
2929+\li{#{(x,y) = \bigsqcup\downset{x,y}}
3030+Starting from the right hand side:
3131+##{\begin{array}{lclr}
3232+\bigsqcup \downset{x,y} & = & \bigsqcup(\downset{x} \times \downset{y}) & \text{(part 2)}\\
3333+ & = & (\bigsqcup(\downset{x}, \bigsqcup\downset{y})) & \text{(lub on products)}\\
3434+ & = & (x,y) & \text{($D$, $E$ are {algebraic})}
3535+\end{array}}}
3636+}
3737+}
+18
trees/dt/dt-004D.tree
···11+\import{dt-macros}
22+\taxon{Aside}
33+\author{liamoc}
44+\title{Scott's original solution: using complete lattices}
55+\p{The lack of closure of [algebraicity](dt-0041) under the ([continuous](dt-001J)) function arrow, [strict](dt-000K) or non-[strict](dt-000K), is not satisfying as it means that our semantic domains are not guaranteed to be [algebraic](dt-0041) even if they are composed from [algebraic](dt-0041) [cpos](dt-001D). Instead, we must replace [algebraic](dt-0041) [cpos](dt-001D) with something stronger still.}
66+\p{Scott's original solution to this lack of closure was to use a \em{complete lattice} instead of [cpos](dt-001D), i.e. requiring [lubs](dt-0017) for all subsets, not just [directed](dt-0010) ones. This solves the problem with #{\contto} but introduces new problems:
77+\ol{
88+\li{ Complete lattices need a \em{top} element #{\top}, but adding a fictitious top (representing inconsistent information) to [cpos](dt-001D) like #{\mathbb{B}_\bot} is strange.}
99+\li{ Extending the functions that capture our primitive semantic operationsto complete lattices can spoil nice algebraic properties. Consider these two possible implementations of #{\mathsf{ite}}, the function for the semantics of an #{\syn{if}} expression:
1010+##{
1111+\mathsf{ite}(\top,x,y) = x \sqcup y\quad\quad\quad \quad\quad \mathsf{ite}(\top,x,y) = \top
1212+}
1313+Either of these solutions results in the failure of useful and expected laws for #{\mathsf{if}} expressions. For example, the left definition above results in the failure of the common equation to eliminate unreachable cases: ##{\mathsf{ite}(b, \mathsf{ite}(b,x,y),z) = \mathsf{ite}(b,x,z) }
1414+And the second definition above results in the failure of this equation that removes redundant checks:
1515+##{\mathsf{ite}(b,x,x) = x}
1616+}
1717+\li{ The power domain construction (TODO) does not generalise to complete lattices, so semantics for non-deterministic programs are difficult in this setting. }
1818+}}
+5
trees/dt/dt-004E.tree
···11+\import{dt-macros}
22+\taxon{Definition}
33+\author{liamoc}
44+\title{Consistent completeness}
55+\p{A [poset](dm-0004) #{A} is \em{consistent complete} (or \em{bounded complete}) iff #{\bigsqcup X} exists for all [consistent](dt-0013) #{X \subseteq A}. That is, any set with \em{an} [upper bound](dm-000C) (a [consistent](dt-0013) set) has a [\em{least} upper bound](dt-0017).}
···11+\import{dt-macros}
22+\import{table-macros}
33+\taxon{Definition}
44+\title{Scott domain}
55+\author{liamoc}
66+77+\<html:img>[class]{sidefigure}[src]{\route-asset{assets/c3po.png}}
88+99+\p{A [cpo](dt-001D) #{D} is a \em{Scott domain} iff:
1010+\ol{
1111+ \li{ #{D} is [#{\omega}-algebraic](dt-0041), }
1212+ \li{ #{D} is [consistent complete](dt-004E), }
1313+}
1414+ In other words, \em{Scott domains} can be summed up by the acronym:
1515+}
1616+\<html:div>[class]{constrainfigure}{
1717+\tex{\usepackage{tikz}\usepackage{amsmath}}{
1818+\begin{tikzpicture}
1919+\node (a) at (5,3) {\Large $\text{ac}^3\text{po}$};
2020+\node (b1) at (0,-1) {\Large $\omega$-\textbf{\textcolor{orange}{a}}lgebraic };
2121+\node (b2) at (4,-1) {\Large \textbf{\textcolor{orange}{c}}onsistent-\textbf{\textcolor{orange}{c}}omplete };
2222+\node (b3) at (9.2,-1) {\Large \textbf{\textcolor{orange}{c}}omplete \textbf{\textcolor{orange}{p}}artial \textbf{\textcolor{orange}{o}}rder };
2323+\draw[thick,-] (b1) -- (a) (b2) -- (a) (b3) -- (a);
2424+\end{tikzpicture}
2525+}
2626+}
+3
trees/dt/dt-004H.tree
···11+\taxon{Remark}
22+\author{liamoc}
33+\p{The second requirement in \ref{dt-004G} can, in light of the first, be expressed equivalently as: #{x \sqcup y} exists for all [consistent](dt-0013) #{x,y \in D}. This is useful when needing to show that a given [cpo](dt-001D) is a [Scott domain](dt-004G).}
+5
trees/dt/dt-004I.tree
···11+\import{dt-macros}
22+\taxon{Theorem}
33+\author{liamoc}
44+\p{[Scott domains](dt-004G) are closed under all our [cpo](dt-001D) constructions, including [sums](dt-0031) #{+}, [products](dt-0021) #{\times}, [continuous functions](dt-002L) #{\contto}, [smash sums](dt-003H) #{\oplus}, [smash products](dt-003G) #{\otimes} and [strict functions](dt-003F) #{\strictto}.
55+}