···1414 \put\transclude/numbered{false}
1515\subtree{\taxon{Thesis}
1616\p{Computable functions are [continuous](dt-001J) functions on [cpos](dt-001D).}
1717-}}1717+}}
1818+\transclude{dt-001W}
1919+\transclude{dt-001P}
2020+\transclude{dt-001Q}
2121+\transclude{dt-001S}
+24
trees/dt-001P.tree
···11+\import{dt-macros}
22+\taxon{Theorem}
33+\title{The Kleene fixed point theorem}
44+\p{Let #{(S, \sqsubseteq)} be a [cpo](dt-001D) and #{f : S \rightarrow S} be a [continuous](dt-001J) function. Then the [lub](dt-0017) of the [Kleene chain](dt-000X) #{\bigsqcup_{n\in \mathbb{N}}f^{n}(\bot)} is the least [fixed point](dt-000S) of #{f}.}
55+\scope{
66+ \put\transclude/toc{false}
77+ \put\transclude/numbered{false}
88+\subtree{\taxon{Proof}
99+\p{We apply [continuity](dt-001J) to show that it is a [fixed point](dt-000S):
1010+1111+ ##{\begin{array}{lclr}
1212+ f(\bigsqcup_{n \in \mathbb{N}} f^n(\bot) ) & = &
1313+ \bigsqcup_{n \in \mathbb{N}} f(f^n(\bot)) &
1414+ \text{(continuity)} \acr{0.5em}
1515+ &=& \bigsqcup_{n \in \mathbb{N}} f^{n+1}(\bot)\acr{0.5em}
1616+ &=& \bigsqcup_{n=1,2\dots}f^{n}(\bot)
1717+ &\qquad\text{(reindexing)}\acr{0.5em}
1818+ &=& \bot \sqcup \bigsqcup_{n=1,2\dots}f^{n}(\bot)\acr{0.5em}
1919+ &=&\bigsqcup_{n\in \mathbb{N}}f^{n}(\bot)\acr{0.5em}
2020+ \end{array}
2121+ }
2222+ To see that it is the \em{least} [fixed point](dt-000S): Let #{y} be a [fixed point](dt-000S) of #{f}. We know that #{\bot \sqsubseteq y} by [definition of #{\bot}](dt-000A). Taking #{f} of both sides, we get #{f(\bot) \sqsubseteq y}. We can continue this inductively and thus we know that, for all #{n \in \mathbb{N}}, #{f^n(\bot) \sqsubseteq y}. Because #{y} is, therefore, an [upper bound](dm-000C) of the [ascending Kleene chain](dt-000X), it must also be at least as large as the [lub](dt-0017) of that [chain](dt-000V).
2323+}
2424+}}
+5
trees/dt-001Q.tree
···11+\import{dt-macros}
22+\taxon{Definition}
33+\author{liamoc}
44+\title{The \fixop operator}
55+\p{Let #{\fixop(f)} denote the least [fixed point](dt-000S) of the [continuous function](dt-001J) #{f}, that is #{\bigsqcup_{n\in \mathbb{N}}f^{n}(\bot)}, guaranteed to exist by \ref{dt-001P}.}
+6
trees/dt-001R.tree
···11+\import{dt-macros}
22+\author{liamoc}
33+\title{Semantics with fixed points}
44+\transclude{dt-001V}
55+\transclude{dt-001U}
66+\transclude{dt-001T}
+31
trees/dt-001S.tree
···11+\import{dt-macros}
22+\author{liamoc}
33+\taxon{Exercise}
44+\ol{
55+ \li{What is #{\fixop(\mathsf{id})} where #{\mathsf{id}} is the identity function on #{\mathbb{B}_\bot}?
66+ \scope{
77+ \put\transclude/toc{false}
88+ \put\transclude/numbered{false}
99+ \put\transclude/expanded{false}
1010+ \subtree{\taxon{Solution} ##{\bigsqcup \Set{ \bot, \mathsf{id}(\bot), \mathsf{id}(\mathsf{id}(\bot)), \dots } = \bot}}}
1111+ }
1212+ \li{What is #{\fixop(\kappa_\False)} where #{\kappa_\False} is the constant function that always returns #{\False}?
1313+ \scope{
1414+ \put\transclude/toc{false}
1515+ \put\transclude/numbered{false}
1616+ \put\transclude/expanded{false}
1717+ \subtree{\taxon{Solution} ##{\bigsqcup \{ \bot, \kappa_F(\bot), \kappa_F(\kappa_F(\bot)), \dots \} = \False}}}}
1818+ \li{What is #{\fixop(f)} where
1919+ ##{\begin{array}{l}
2020+ f : [\mathbb{N}_\bot] \rightarrow [\mathbb{N}_\bot]\\
2121+ f(x) = 1::x
2222+ \end{array}}
2323+ (where #{[\mathbb{N}_\bot]} denotes Haskell-style lazy lists of #{\mathbb{N}_\bot})?
2424+ \scope{
2525+ \put\transclude/toc{false}
2626+ \put\transclude/numbered{false}
2727+ \put\transclude/expanded{false}
2828+ \subtree{\taxon{Solution}
2929+\p{##{\bigsqcup \{ \bot, 1::\bot, 1::1::\bot, \dots \} = 1::1::1::\cdots}
3030+Here #{\fixop(f)} would be the semantics of the recursive definition #{\mathsf{ones} = 1 :: \mathsf{ones}}.}}}}
3131+}
+25
trees/dt-001T.tree
···11+\import{dt-macros}
22+\taxon{Exercise}
33+\author{liamoc}
44+\ol{
55+\li{Write down the first few approximations #{\Phi^m(\bot)} to #{\fixop(\Phi)}, where the higher order function #{\Phi : (\mathbb{Z}_\bot \rightarrow [\mathbb{Z}_\bot]) \rightarrow (\mathbb{Z}_\bot \rightarrow [\mathbb{Z}_\bot])} is given by:
66+##{\Phi(f) = \lambda n.\ n :: f (n+1)}
77+What is #{\Phi^m(\bot)}? What is #{\fixop(\Phi)}?}
88+ \scope{
99+ \put\transclude/toc{false}
1010+ \put\transclude/numbered{false}
1111+ \put\transclude/expanded{false}
1212+ \subtree{\taxon{Solution}
1313+ \p{The approximations are #{\Set{ \lambda n.\ \bot, \lambda n.\ n :: \bot, \lambda n.\ n :: (n + 1) :: \bot, \dots }}. The limit is a function that, given a natural number #{n}, produces the infinite list of natural numbers starting from #{n}.}
1414+ }}
1515+\li{Repeat the same process, but this time for a new higher order function #{\Phi : (\mathbb{Z}_\bot \rightarrow \mathbb{Z}_\bot) \rightarrow (\mathbb{Z}_\bot \rightarrow \mathbb{Z}_\bot)} given by:
1616+##{\Phi(f) = \lambda n.\ \text{if}\ n = 0\ \text{then}\ 0\ \text{else}\ f(n-2)}}
1717+ \scope{
1818+ \put\transclude/toc{false}
1919+ \put\transclude/numbered{false}
2020+ \put\transclude/expanded{false}
2121+ \subtree{\taxon{Solution}
2222+\p{The #{n}th approximation returns #{0} if the input number
2323+is non-negative, even and less than #{2n}, otherwise it diverges (returns #{\bot}). The limit returns #{0} for any non-negative even number, and diverges otherwise. }
2424+ }}
2525+}
+16
trees/dt-001U.tree
···11+\import{dt-macros}
22+\title{Semantics of recursive functions}
33+\author{liamoc}
44+\p{Consider the function #{\Phi \in (\mathbb{N}_\bot \rightarrow \mathbb{N}_\bot) \rightarrow (\mathbb{N}_\bot \rightarrow \mathbb{N}_\bot)}, given by:
55+##{\Phi(f) = \lambda n.\ \text{if}\ n = 0\ \text{then}\ 1\ \text{else}\ n\cdot f(n-1)}
66+Looking at the first few elements of our [Kleene chain](dt-000X), we get:
77+##{
88+\begin{array}{lcl}
99+ \Phi^0(\bot) & = & \lambda n.\ \bot \quad \text{(i.e. $\bot_{\mathbb{N}_\bot \rightarrow \mathbb{N}_\bot}$)}\\
1010+ \Phi^1(\bot) & = & \lambda n.\ \text{if}\ n = 0\ \text{then}\ 1\ \text{else}\ \bot\\
1111+ \Phi^2(\bot) & = & \lambda n.\ \text{if}\ n = 0\ \text{then}\ 1\ \text{else}\ n\cdot(\text{if}\ n - 1 = 0\ \text{then}\ 1\ \text{else}\ \bot)\\
1212+ \cdots
1313+\end{array}
1414+}
1515+Continuing on, we see that the #{m}th approximation #{\Phi^m(\bot)} to #{\fixop(\Phi)} is the function that gives #{x!} for all #{x} up to #{m}, and diverges (#{\bot}) for all other arguments. Hence the limit #{\fixop(\Phi)} is the \em{factorial} function on #{\mathbb{N}_\bot}!
1616+}
+13
trees/dt-001V.tree
···11+\import{dt-macros}
22+\title{Semantics of loops}
33+\author{liamoc}
44+\p{Armed with [the \fixop operator](dt-001Q), we can return to our semantics of #{\mathsf{while}} loops from \ref{dt-0006} and \ref{dt-000R}, and at last define their semantics without relying on dubious recursive definitions:
55+##{
66+\begin{array}{l}
77+\llbracket \mathsf{while}\ b\ \mathsf{do}\ c\ \mathsf{od} \rrbracket_\mathcal{C} = \fixop(f)\acr{0.5em}
88+\qquad \text{where}\; f(X)\ \sigma\; \triangleq \; \begin{cases} X\ (\llbracket c \rrbracket_\mathcal{C}\ \sigma) & \text{if}\ \llbracket b \rrbracket_\mathcal{B}\ \sigma = \True \\
99+ \sigma & \text{otherwise}
1010+ \end{cases}
1111+\end{array}
1212+}}
1313+\p{Proof that #{f} is [continuous](dt-001J) is technically required but is omitted here.}
+15
trees/dt-001W.tree
···11+\import{dt-macros}
22+\taxon{Exercise}
33+\author{liamoc}
44+\p{Show that if a function #{f : A \rightarrow B} on [cpos](dt-001D) #{A} and #{B} is [monotonic](dt-000J) and #{A} is finite, then #{f} is [continuous](dt-001J). }
55+\p{\em{Hint}: Finite [directed](dt-0010) sets contain their [lub](dt-0017)}
66+\scope{
77+ \put\transclude/toc{false}
88+ \put\transclude/numbered{false}
99+ \put\transclude/expanded{false}
1010+\subtree{\taxon{Solution}
1111+\p{Because of \ref{dt-001O}, it suffices to show the second condition of [continuity](dt-001J), as #{f} is [monotonic](dt-000J). }
1212+\p{Because #{A} is finite, any directed subset #{X \subseteq A} is also finite, and therefore #{\bigsqcup X \in X}. Because #{f} is [monotone](dt-000J), #{f(x) \sqsubseteq f (\bigsqcup X)} for all #{x \in X}. }
1313+\p{The solution to \ref{dt-001N} shows that #{\Set{f(x) \mid x \in X}} is [directed](dt-0010) and therefore contains its upper bound #{c}. Because #{f} is monotone, #{f(\bigsqcup X)} must be #{c} (else it would contradict the above).}
1414+\p{Therefore #{\bigsqcup \Set{f(x) \mid x \in X} = f (\bigsqcup X)}, as required. }
1515+}}
+40
trees/dt-001X.tree
···11+\import{dt-macros}
22+\taxon{Exercise}
33+\author{liamoc}
44+\ol{
55+\li{Show that if #{A} and #{B} are [posets](dm-0004) and #{X \subseteq A \times B} is [directed](dt-0010) (by the ordering in \ref{dt-000E}), then the subsets #{\pi_0(X) \subseteq A} and #{\pi_1(X) \subseteq B} (defined below) are also [directed](dt-0010).
66+ ##{ \begin{array}{lcl}
77+ \pi_0(X) & = & \{ a \in A \mid \exists b \in B.\ (a,b) \in X \}\\
88+ \pi_1(X) & = & \{ b \in B \mid \exists a \in A.\ (a,b) \in X \}\\
99+ \end{array}
1010+ }
1111+\scope{
1212+ \put\transclude/toc{false}
1313+ \put\transclude/numbered{false}
1414+ \put\transclude/expanded{false}
1515+ \subtree{\taxon{Solution}
1616+ \p{Given two elements #{x,y \in \pi_0(X)}, we know that there exists #{b_x, b_y \in B} such that #{(x,b_x) \in X} and #{(y,b_y) \in X}. Because #{X} is [directed](dt-0010), we can conclude that there exists an [upper bound](dm-000C) #{(z, b_z) \in X} where #{x \sqsubseteq z} and #{y \sqsubseteq z}. As #{z \in \pi_0(X)}, #{z} is an [upper bound](dm-000C) in #{\pi_0(X)} for both #{x} and #{y} and thus #{\pi_0(X)} is [directed](dt-0010). The proof for #{\pi_1} is analogous.
1717+ }
1818+ }}
1919+}
2020+\li{ Give an example of a set #{X \subseteq \{\top,\bot\}\times\{\top,\bot\}} such that #{\pi_0(X)} and #{\pi_1(X)} are [directed](dt-0010), but #{X} is not.
2121+\scope{
2222+ \put\transclude/toc{false}
2323+ \put\transclude/numbered{false}
2424+ \put\transclude/expanded{false}
2525+\subtree{\taxon{Solution}
2626+\p{#{X = \Set{(\top,\bot), (\bot,\top)}} is not directed as the two elements are not comparable, but #{\pi_0(X) = \pi_1(X) = \Set{\top,\bot}} which is directed as #{\bot \sqsubseteq \top}.}
2727+}}
2828+}
2929+\li{ Show that if #{A} and #{B} are [cpos](dt-001D) and #{X \subseteq A \times B} is [directed](dt-0010), then ##{\bigsqcup X = \left(\bigsqcup \pi_0(X), \bigsqcup\pi_1(X)\right)}
3030+\strong{Note}: Together with #{\bot_{A\times B} = (\bot_A, \bot_B)} this shows that the [Cartesian product](dm-0005) of two [cpos](dt-001D) is itself a [cpo](dt-001D).}
3131+\scope{
3232+ \put\transclude/toc{false}
3333+ \put\transclude/numbered{false}
3434+ \put\transclude/expanded{false}
3535+ \subtree{\taxon{Solution}
3636+ \p{
3737+ Let #{(x,y) = \left(\bigsqcup \pi_0(X), \bigsqcup\pi_1(X)\right)}. Because of the ordering in \ref{dt-000E}, #{(x,y)} is certainly \em{a} [upper bound](dm-000C) of the directed set #{X}. To show it is the \em{least} [upper bound](dm-000C), assume for the sake of contradiction that #{(x,y)} is \em{not} the [least upper bound](dt-0017) of #{X}. Then, there must be a #{(v,w)\sqsubset (x,y)} such that #{\forall x \in X.\ x \sqsubseteq (v,w)}. But then, #{v} would be a lesser [upper bound](dm-000C) for #{\pi_0(X)} than #{x}, which is supposed to be the [lub](dt-0017). Thus there is a contradiction, and #{(x,y)} must be the [lub](dt-0017) of #{X}.
3838+ }
3939+ }}
4040+}