···11+\import{dt-macros}
22+\title{Extending cpo Mappings to endofunctors on #{\textbf{Cpo}^\mathbf{R}}}
33+\author{liamoc}
44+\p{If #{\mathcal{F}} is a mapping on [cpos](dt-001D) built up from basic cpos using the constructions #{\times}, #{\otimes}, #{+}, #{\oplus}, #{(\cdot)_\bot}, \em{as well as} #{\contto} and #{\strictto}, then #{\mathcal{F}} extends to a (\em{covariant}!) [cocontinuous functor](dt-005E) on #{\textbf{Cpo}^\mathbf{R}}.
55+We shall detail the construction for products and functions here, but the other constructions are all similar.}
66+\transclude{dt-005J}
77+\transclude{dt-005K}
+10
trees/dt/dt-005J.tree
···11+\import{dt-macros}
22+\taxon{Definition}
33+\author{liamoc}
44+\title{#{\times} operation for retraction pairs}
55+\p{
66+Given two [retraction pairs](dt-0054) #{(f,g)} and #{(h,i)}, our [retraction pair](dt-0054) for their [product](dt-0021) is just the product of their \em{embedding} and \em{projection}, i.e. #{(f \times h, g \times i)}, using our [product operation on continuous functions](dt-0026):
77+##{
88+\inferrule{A \rpair{f}{g} B\quad C \rpair{h}{i} D}{A\times C \rpair{f \times h}{g \times i} B \times D}
99+}
1010+}
+13
trees/dt/dt-005K.tree
···11+\import{dt-macros}
22+\taxon{Definition}
33+\author{liamoc}
44+\title{#{\contto} operation for retraction pairs}
55+\p{
66+We are given two [retraction pairs](dt-0054) #{A \rpair{f}{g} B} and
77+ #{C \rpair{h}{i} D}. To define a suitable \em{covariant} [functor](dt-005E), we define our morphism mapping in terms of our #{\contto} [operation on continuous functions](dt-002X): ##{ (f,g) \contto (h,i) \; \triangleq \; (g\contto h, f \contto i)}
88+Note that the positions of #{f} and #{g} are swapped in the above definition.
99+##{
1010+\inferrule{A \rpair{f}{g} B \quad C \rpair{h}{i} D}{A \contto C \rpair{g \contto h}{f \contto i} B \contto D}
1111+}
1212+Unlike [with the category #{\textbf{Cpo}}](dt-0053), this functor is not [contravariant](dm-000S) but \em{covariant}: Note the positions of #{A} and #{B} are not swapped!
1313+}
+57
trees/dt/dt-005L.tree
···11+\import{dt-macros}
22+\title{Semantics of untyped #{\lambda}-calculus}
33+\author{liamoc}
44+\p{
55+Recall the untyped #{\lambda} calculus:
66+\transclude{dt-004K}
77+We mentioned before that the semantic domain of this language must be a cpo #{D} such that ##{D \simeq D\contto D} In other words, solutions to this equation are fixed points of #{\mathcal{F}(X) = X\contto X}. The least such fixed point can expressed, by \ref{dt-005B}, as the [colimit](dt-005H) of the [#{\omega}-chain](dt-005C):
88+\figure{
99+\tex{\usepackage{tikz-cd}}{
1010+\begin{tikzcd}
1111+ \mathbf{1} \ar[r,"f_0",->,yshift=0.2em]\ar[r,"g_0"', <-,yshift=-0.2em] &
1212+ \mathcal{F}(\mathbf{1}) \ar[r,"f_1",->,yshift=0.2em]\ar[r,"g_1"', <-,yshift=-0.2em] &
1313+ \mathcal{F}(\mathcal{F}(\mathbf{1})) \ar[r,"f_2",->,yshift=0.2em]\ar[r,"g_2"', <-,yshift=-0.2em] &
1414+ \mathcal{F}(\mathcal{F}(\mathcal{F}(\mathbf{1}))) \ar[r,-,dashed,yshift=0.2em]\ar[r,dashed,-,yshift=-0.2em] &
1515+ \cdots
1616+\end{tikzcd}
1717+}}
1818+But, the least solution to this equation is \em{trivial}: #{D_\infty \simeq \mathbf{1}}, because #{\mathbf{1} \simeq \mathbf{1}\contto \mathbf{1}}. A non-trivial solution is obtained by starting the chain at #{\mathbf{2}}, the [cpo](dt-001D) containing just #{\Set{\top,\bot}}, rather than #{\mathbf{1}}.
1919+\figure{\tex{\usepackage{tikz-cd}}{
2020+\begin{tikzcd}
2121+ \mathbf{2} \ar[r,"f_0",->,yshift=0.2em]\ar[r,"g_0"', <-,yshift=-0.2em] &
2222+ \mathcal{F}(\mathbf{2}) \ar[r,"f_1",->,yshift=0.2em]\ar[r,"g_1"', <-,yshift=-0.2em] &
2323+ \mathcal{F}(\mathcal{F}(\mathbf{2})) \ar[r,"f_2",->,yshift=0.2em]\ar[r,"g_2"', <-,yshift=-0.2em] &
2424+ \mathcal{F}(\mathcal{F}(\mathcal{F}(\mathbf{2}))) \ar[r,-,dashed,yshift=0.2em]\ar[r,dashed,-,yshift=-0.2em] &
2525+ \cdots
2626+\end{tikzcd}
2727+}}}
2828+\p{
2929+We will now sketch a proof of the [retraction pair](dt-0054) between #{D_\infty} and #{D_\infty \contto D_\infty}, by providing two functions, #{\textbf{\textsf{up}} : D_\infty \rightarrow (D_\infty\contto D_\infty)} and its inverse #{\textbf{\textsf{down}} : (D_\infty\contto D_\infty) \rightarrow D_\infty}. }
3030+\p{
3131+Observe that each element of #{D_i} (for #{i > 0}) is a \em{function} #{D_{i-1} \contto D_{i-1}}. Therefore, an element of [the colimit #{D_\infty}](dt-005H) is an #{\omega}-tuple of such functions. To define #{\textbf{\textsf{up}}(d)(x)}, we must essentially "apply" each function in the element #{d \in D_\infty} (viewed as an #{\omega}-tuple of functions) to the element #{x \in D_\infty} (viewed as an #{\omega}-tuple of values). More specifically, we say that #{\textbf{\textsf{up}}(d)(x)} is an #{\omega}-tuple #{(y_m \mid y \in \mathbb{N})}, as follows:
3232+##{
3333+y_m = \bigsqcup_{k \in \mathbb{N}} \theta_{m+k,m}(d_{m+k+1}(x_{m+k}))
3434+}
3535+To define #{\textbf{\textsf{down}}(f)}, we are given a ([continuous](dt-001J)) function #{f : D_\infty\contto D_\infty} and must construct the #{\omega}-tuple of approximations at every #{D_n}. We do this by projecting the action of #{f} down to #{D_n}. We say that #{\textbf{\textsf{down}}(f)} is an #{\omega}-tuple #{(v_n \mid n \in \mathbb{N})} where:
3636+##{
3737+\begin{array}{lcl}
3838+ v_0 & \triangleq & \theta_{\infty,0}(f(\theta_{0,\infty}(\bot_{D_0})))\\
3939+ v_{n+1} & \triangleq & \theta_{\infty,n} \circ f \circ \theta_{n,\infty}
4040+\end{array}
4141+}}
4242+\subtree{
4343+\taxon{Definition}
4444+\title{Denotations for untyped #{\lambda}-calculus}
4545+\p{
4646+Using the new functions #{\textbf{\textsf{up}}} and #{\textbf{\textsf{down}}}, it is now straightforward to define a semantics for untyped #{\lambda}-calculus, where #{\sigma} is an environment #{\mathsf{Var} \rightarrow D_\infty}:
4747+##{\llbracket \cdot \rrbracket : (\mathsf{Var} \rightarrow D_\infty)\contto D_\infty}
4848+##{
4949+\begin{array}{lcl}
5050+\llbracket x \rrbracket \sigma & = & \sigma (x) \\
5151+\llbracket e_0\ e_1 \rrbracket \sigma & = & \textbf{\textsf{up}}(\llbracket e_0 \rrbracket \sigma) (\llbracket e_1 \rrbracket \sigma)\\
5252+\llbracket \lambda x.\ e \rrbracket \sigma & = & \textbf{\textsf{down}}(\boldsymbol{\lambda} v \in D_{\infty}.\ \llbracket e \rrbracket\ \sigma(x \mapsto v) )
5353+\end{array}
5454+}
5555+This semantics does not distinguish non-terminating computations from terminating ones. To model call-by-value more faithfully, we could use the equation #{D \simeq D\contto D_\bot} instead, and for call-by-name we could use #{D \simeq D_\bot\contto D_\bot}. The constructions are very similar.
5656+}
5757+}
+26
trees/dt/dt-005M.tree
···11+\import{dt-macros}
22+\taxon{Exercise}
33+\author{liamoc}
44+\p{
55+Show that #{\mathcal{F}(X) \triangleq \mathbf{1} + X} and #{\mathcal{F}(f) \triangleq \mathsf{id}_\mathbf{1} + f} (using our [#{+} operator for functions](dt-0037)) define an [endofunctor](dt-004T) #{\mathbf{Cpo} \rightarrow \mathbf{Cpo}}, i.e. that they satisfy the functor laws.}
66+\solnblock{
77+\ol{
88+ \li{
99+ We must show #{\mathcal{F}(\mathsf{id}_A : A \contto A) = \mathsf{id}_{\mathcal{F}(A)} : \mathcal{F}(A) \contto \mathcal{F}(A)}.
1010+ ##{\begin{array}{lcl}
1111+ \mathcal{F}(\mathsf{id}_A)& =& \mathsf{id}_\mathbf{1} + \mathsf{id}_A\\
1212+ &=& \mathsf{id}_{\mathbf{1} + A}\\
1313+ &=& \mathsf{id}_{\mathcal{F}(A)}
1414+ \end{array}}
1515+1616+ }
1717+ \li{
1818+ We must show #{\mathcal{F}(f \circ g) = \mathcal{F}(f) \circ \mathcal{F}(g)}.
1919+ ##{\begin{array}{lcl}
2020+ \mathcal{F}(f \circ g) &=& \mathsf{id}_\mathbf{1} + (f \circ g) \\
2121+ &=& (\mathsf{id}_\mathbf{1} + f) \circ (\mathsf{id}_\mathbf{1} + g) \\
2222+ & = & \mathcal{F}(f) \circ \mathcal{F}(g)
2323+ \end{array}}
2424+ }
2525+}
2626+}
···11+\import{dt-macros}
22+\taxon{Exercise}
33+\author{liamoc}
44+\p{
55+Show that, in contrast to #{\mathcal{F}(X) = X\contto \mathbb{Z}_\bot} from \ref{dt-0053}, the mapping #{\mathcal{G}(X) = \mathbb{Z}_\bot\contto X} \em{can} be extended to [continuous](dt-001J) functions giving a \em{covariant} [endofunctor](dt-004T) on #{\textbf{Cpo}}.
66+\solnblock{
77+\p{Given a continuous function #{f : A \contto B}, we must produce a continuous function #{\mathcal{F}(f) : (\mathbb{Z}_\bot \contto A) \contto (\mathbb{Z}_\bot \contto B)}, defined as follows:
88+##{\mathcal{F}(f)(g)(x) = f \circ g(x)}
99+Composition of continuous functions preserves continuity. The [functor laws](dt-004T) can be shown straightforwardly.
1010+}
1111+}}