···11+\import{dt-macros}
22+\author{liamoc}
33+\title{Dual category}
44+\taxon{Definition}
55+\p{The \em{dual} of a [category](dm-000G) #{\mathbf{C}}, written #{\mathbf{C}^\mathsf{op}}, is a [category](dm-000G) with the same objects as #{\mathbf{C}} but the arrows are reversed, that is, for each morphism #{A \xrightarrow{m} B} in #{\mathbf{C}}, there is a morphism #{B \xrightarrow{m} A} in #{\mathbf{C}^\mathsf{op}}.}
+1-1
trees/dt-001O.tree
···11\import{dt-macros}
22\taxon{Theorem}
33\author{liamoc}
44-\title{Alternative definition of continuity}
44+\title{Alternative characterisation of continuity}
55\p{A function #{f : A \rightarrow B} on [cpos](dt-001D) #{A} and #{B} is [continuous](dt-001J) iff:
66\ol{
77 \li{#{f} is [monotonic](dt-000J), and}
+1
trees/dt-001U.tree
···11\import{dt-macros}
22\title{Semantics of recursive functions}
33+\taxon{Example}
34\author{liamoc}
45\p{Consider the function #{\Phi \in (\mathbb{N}_\bot \rightarrow \mathbb{N}_\bot) \rightarrow (\mathbb{N}_\bot \rightarrow \mathbb{N}_\bot)}, given by:
56##{\Phi(f) = \lambda n.\ \text{if}\ n = 0\ \text{then}\ 1\ \text{else}\ n\cdot f(n-1)}
+1-3
trees/dt-001Z.tree
···55\author{liamoc}
66\p{This lecture is based on material from [[haskellhutt]], [[danascott]], [[jstoy]], [[cgunter]], and [[gwinskel]].}
77\transclude{dt-002K}
88-\subtree{
99-\title{Functions}
1010-}
88+\transclude{dt-002Z}
119\subtree{
1210\title{Sums}
1311}
+1-1
trees/dt-0024.tree
···44\title{Continuity of split}
55\author{liamoc}
66 \p{For [continuous functions](dt-001J) #{f} and #{g}, the [split function](dt-0023) #{\langle f, g \rangle} is [continuous](dt-001J).}
77- \proofblock{
77+ \proofblock{\p{Using the [alternative characterisation of continuity](dt-001O):}
88 \ul{
99 \li{ \em{#{\langle f, g \rangle} is [monotonic](dt-000J)}. Let #{x \sqsubseteq y \in A}. Then: ##{\begin{array}{lclr}
1010 \langle f , g \rangle\ x & = & (f(x), g(x)) & \text{(def)}\\
+33
trees/dt-002L.tree
···11+\import{dt-macros}
22+\taxon{Construction}
33+\title{The cpo of functions}
44+\author{liamoc}
55+66+77+\p{If #{A} and #{B} are [cpos](dt-001D), the set of [continuous functions](dt-002F) #{A \contto B} is a [cpo](dt-001D) under the \em{pointwise} ordering:
88+##{
99+f \sqsubseteq g\;\; \text{iff}\;\; \forall a \in A.\ f(a) \sqsubseteq g(a)
1010+}
1111+The intuition of this ordering in terms of information is that we increase the information content of a function overall by increasing the information content of any (or many) argument values. To prove this, we must show:
1212+\ol{
1313+ \li{ \em{#{A \contto B} has a [least element](dt-000A).} #{\bot_{A \contto B}} is the constant function that returns #{\bot_B}, i.e. #{\lambda a.\ \bot_B}.}
1414+ \li{ \em{#{\bigsqcup X} exists for all [directed](dt-0010) #{X \subseteq A \contto B}}. Our [lub](dt-0017) of a set of continuous functions #{\bigsqcup X} is the function #{\Phi} where: ##{\Phi(a) = \bigsqcup \Set{ f(a) \mid f \in X}}
1515+ We must show a number of properties of this [lub](dt-0017) #{\Phi}. Specifically:
1616+ \ol{
1717+ \li{ \em{#{\bigsqcup \Set{ f(a) \mid f \in X}} exists in #{B}}. \proofblock{We want to show that the set #{\Set{ f(a) \mid f \in X}} is [directed](dt-0010). Take two values #{g(a), h(a) \in \Set{ f(a) \mid f \in X}}. Since #{X} is [directed](dt-0010), there exists a function #{k \in X} such that #{g \sqsubseteq k} and #{h \sqsubseteq k}. By applying the definition of #{\sqsubseteq} for functions above, we have #{g(a) \sqsubseteq k(a)} and #{h(a) \sqsubseteq k(a)}. Thus #{k(a)} is an [upper bound](dm-000C) of these two values #{g(a), h(a)}, and thus #{\Set{ f(a) \mid f \in X}} is [directed](dt-0010), and thus its [lub](dt-0017) exists since #{B} is a [cpo](dt-001D).}}
1818+ \li{ \em{#{ \Phi(a) = \bigsqcup \Set{ f(a) \mid f \in X } } is continuous}. \proofblock{\p{Using the [alternative characterisation of continuity](dt-001O)}
1919+##{
2020+\begin{array}{lclr}
2121+ \Phi(\bigsqcup Y) &=& \bigsqcup\{ f(\bigsqcup Y) \mid f \in X \} & \text{(defn. $\Phi$)}\\
2222+ & = & \bigsqcup \{\bigsqcup \{ f(y) \mid y \in Y \} \mid f \in X \} & \text{($f$ is continuous)}\\
2323+ & = & \bigsqcup \{\bigsqcup \{ f(y) \mid f \in X \} \mid y \in Y \} & \text{(swap lubs)}\\
2424+ & = & \bigsqcup \{ \Phi(y) \mid y \in Y \} & \text{(defn. $\Phi$)}\\
2525+\end{array}
2626+}
2727+Monotonicity is similar to prove.}}
2828+\li{ \em{#{\Phi} is an [upper bound](dm-000C) for #{X \subseteq A \contto B}}. \proofblock{
2929+ Let #{g \in X}. Then for any #{a \in A} we have #{g(a) \in \Set{ f(a) \mid f \in X}}. Now, by 2a and lubs, we have #{g(a) \sqsubseteq \bigsqcup \Set{ f(a) \mid f \in X }}, which by the definition of #{\Phi} gives #{g(a) \sqsubseteq \Phi(a)}. Hence, by the definition of #{\sqsubseteq} on functions, we can conclude #{g \sqsubseteq \Phi}.}}
3030+ \li{ \em{#{\Phi} is the [least upper bound](dt-0017) for #{X}}. \proofblock{ Let #{g \in A \contto B} be an [upper bound](dm-000C) for #{X \subseteq A \contto B}. Then (using #{\sqsubseteq} on functions) #{g(a)} is an [upper bound](dm-000C) for #{\Set{f(a) \mid f \in X}} for all #{a \in A}. Now, by 2a and lubs, we have #{\bigsqcup\Set{f(a) \mid f \in X} \sqsubseteq g(a)}, i.e. #{\Phi(a) \sqsubseteq g(a)}, which, by the definition of #{\sqsubseteq} on functions, allows us to conclude #{\Phi \sqsubseteq g}.}}
3131+}
3232+}
3333+}}
···11+\import{dt-macros}
22+\taxon{Definition}
33+\author{liamoc}
44+\title{The #{\mathit{apply}} function}
55+\p{The #{\mathit{apply}} function simply applies a given function to a given argument:
66+##{
77+\begin{array}{l}
88+\mathit{apply} : ((A \contto B) \times A) \contto B\\
99+\mathit{apply} (f, a) = f(a)
1010+\end{array}
1111+}}
+12
trees/dt-002O.tree
···11+\import{dt-macros}
22+\taxon{Definition}
33+\author{liamoc}
44+\title{The #{\mathit{curry}} function}
55+\p{The function #{\mathit{curry}} transforms a function that takes two arguments all at once (as a [product](dm-0005)) into a function that takes the arguments one at a time. That is, if #{f : A \times B \contto C} then:
66+##{
77+\begin{array}{l}
88+\mathit{curry}(f) : A \contto (B \contto C)\\
99+\mathit{curry}(f)(a)(b) = f(a, b)
1010+\end{array}
1111+}
1212+}
···11+\import{dt-macros}
22+\taxon{Exercise}
33+\author{liamoc}
44+\p{Show that #{\mathit{apply}} is [continuous](dt-001J).}
55+\p{\em{Hint:} A function #{f : A \times B \rightarrow C} is [continuous](dt-001J) iff it is [continuous](dt-001J) in each argument separately, i.e., iff #{\forall a \in A.\ f(a,\cdot) : B \rightarrow C} is continuous, and #{\forall b \in B.\ f(\cdot,b) : A \rightarrow C} is continuous.}
66+\solnblock{
77+\p{
88+First showing #{\mathit{apply}(f,\cdot)} is continuous for some continuous #{f : A \contto B}, using the [alternative characterisation](dt-001O)
99+\ol{
1010+\li{ \em{#{\mathit{apply}(f,\cdot)} is monotonic}: Given #{a, b \in A} where #{a \sqsubseteq b}, we can see that #{\mathit{apply}(f,a) = f(a) \sqsubseteq f(b) = \mathit{apply}(f,b)} by the [monotonicity](dt-000J) of #{f}.
1111+}
1212+\li{ \em{#{\mathit{apply}(f,\cdot)} preserves lubs}: Given a [directed](dt-0010) #{X \subseteq A}, we can see that #{\mathit{apply}(f,\bigsqcup X) = f(\bigsqcup X) = \bigsqcup \Set{f(x) \mid x \in X} = \bigsqcup \Set{\mathit{apply}(f,x) \mid x \in X}} follows from the continuity of #{f}.
1313+}
1414+}
1515+Next, showing #{\mathit{apply}(\cdot,a)} is continuous for some fixed #{a \in A}:
1616+\ol{
1717+\li{ \em{#{\mathit{apply}(\cdot,a)} is monotonic}: Given #{f, g \in A \contto B} where #{f \sqsubseteq g}, we can see that #{\mathit{apply}(f,a) = f(a) \sqsubseteq g(a) = \mathit{apply}(g,a)} by the [pointwise ordering of functions](dt-002L).
1818+}
1919+\li{ \em{#{\mathit{apply}(\cdot,a)} preserves lubs}: Given a [directed](dt-0010) #{X \subseteq A \contto B}, we can see that #{\mathit{apply}(\bigsqcup X, a) = \left(\bigsqcup X\right)(a) = \bigsqcup \Set{f(a) \mid f \in X} = \bigsqcup \Set{\mathit{apply}(f,a) \mid f \in X}} follows from the [lub definition for functions](dt-002L).
2020+}
2121+}
2222+}}
+7
trees/dt-002R.tree
···11+\import{dt-macros}
22+\author{liamoc}
33+\taxon{Exercise}
44+\p{
55+ What is the common (functional programming) name for #{\mathit{apply} \circ (f \times \mathsf{id})}?
66+ \solnblock{\p{#{\mathit{uncurry}}}}
77+}
+9
trees/dt-002S.tree
···11+\import{dt-macros}
22+\author{liamoc}
33+\taxon{Theorem}
44+\title{Continuity of #{\mathit{curry}}}
55+\ol{
66+\li{#{\mathit{curry}} is [continuous](dt-001J) on #{A \times B \contto C}.}
77+\li{#{\mathit{curry}(f)}, given [continuous](dt-001J) #{f : A \times B \contto C}, is [continuous](dt-001J) on #{A}.}
88+\li{#{\mathit{curry}(f)(a)}, given [continuous](dt-001J) #{f : A \times B \contto C} and #{a \in A}, is [continuous](dt-001J) on #{B}.}
99+}
+15
trees/dt-002T.tree
···11+\import{dt-macros}
22+\author{liamoc}
33+\taxon{Definition}
44+\title{Universal property for functions}
55+\figure{
66+\tex{\usepackage{tikz-cd}\usepackage{amssymb}}{
77+\begin{tikzcd}[row sep=4em]
88+A \times B \ar[d,dashed,labels=description,"\mathit{curry}(f)\times \mathsf{id}_B"] \ar[r,"f"] & C \\
99+(B \contto C) \times B \ar[ur, labels=below right,"\mathit{apply}"]
1010+\end{tikzcd}
1111+}
1212+}
1313+##{
1414+ \mathit{apply} \circ h = f\; \text{iff}\; h = \mathit{curry}(f)\times\mathsf{id}_B
1515+}
+10
trees/dt-002U.tree
···11+\import{dt-macros}
22+\author{liamoc}
33+\taxon{Theorem}
44+\title{The currying isomorphism}
55+##{
66+(A \times B)\contto C \;\;\simeq \;\; A\contto (B\contto C)
77+}
88+\proofblock{
99+\p{Follows from the [universal property for functions](dt-002T) when set up with the [isomorphism](dt-002E) from [curry](dt-002O) and its inverse, the function in \ref{dt-002R}.}
1010+}
+14
trees/dt-002V.tree
···11+\import{dt-macros}
22+\author{liamoc}
33+\taxon{Remark}
44+\title{Why the function arrow is not a covariant [bifunctor](dm-000M)}
55+\p{
66+ For the #{\contto} operator on [cpos](dt-001D) (\ref{dt-002F}) to be the object mapping for a [bifunctor](dm-000M) #{\textbf{Cpo} \times \textbf{Cpo} \rightarrow \textbf{Cpo}} like #{\times} is (see \ref{dt-002C}), we would need to define a morphism mapping #{f \contto g} that, given two functions #{f : A \contto B} and #{g : C \contto D}, gives a function #{(A \contto C) \contto (B \contto D)}. But such a function is \em{not implementable}:
77+ ##{
88+\begin{array}{l}
99+ f \contto g : (A \contto C) \contto (B \contto D) \\
1010+ (f \contto g)(h)(b) =\ \textcolor{red}{???}\\
1111+ \end{array}
1212+ }
1313+ In the above hole #{\textcolor{red}{???}}, #{h : A \contto C} and #{b \in B}. Given the value #{b \in B}, none of our functions #{f, g} or #{h} take elements of #{B}, so there would be no way to produce the #{D} value required. This is because our function #{f : A \contto B} goes \em{the wrong way}. If #{f} were a function #{B \contto A}, things would be a lot easier.
1414+}
+14
trees/dt-002W.tree
···11+\import{dt-macros}
22+\title{The function arrow is a bifunctor}
33+\author{liamoc}
44+\p{The operator #{\contto} introduced in \ref{dt-002F} is is the object mapping for a [binary functor](dm-000M): ##{(\contto) : \mathbf{Cpo}^\mathsf{op} \times \mathbf{Cpo} \rightarrow \mathbf{Cpo}} The [category](dm-000G) #{\mathbf{Cpo}^\mathsf{op}} is the [dual category](dm-000Q) to #{\mathbf{Cpo}}.}
55+\p{
66+Thus, a morphism #{A \xrightarrow{m} B} in the [category](dm-000G) #{\mathbf{Cpo}^\mathsf{op}} is a [continuous](dt-001J) function #{m : B \contto A}. Thus, the morphism mapping for our [functor](dm-000J) must take two functions #{f : B \contto A} (the morphism from #{\mathbf{Cpo}^\mathsf{op}}) and #{g : C \contto D} (the morphism from #{\mathbf{Cpo}}), and produce #{(A \contto C) \contto (B \contto D)}. As with [products](dt-0026), we will overload the #{\contto} notation for this mapping as well. }
77+\transclude{dt-002X}
88+\transclude{dt-002Y}
99+\scope{
1010+\put\transclude/toc{false}
1111+\put\transclude/numbered{false}
1212+\subtree{\taxon{Upshot}
1313+\p{Our [category #{\textbf{Cpo}}](dt-002B) has \em{exponentials}.}
1414+}}
+14
trees/dt-002X.tree
···11+\import{dt-macros}
22+\taxon{Definition}
33+\author{liamoc}
44+\title{Morphism mapping for #{\contto}}
55+\p{
66+Given #{f : B \contto A} and #{g : C \contto D}, we have:
77+##{
88+\begin{array}{l}
99+f \contto g : (A \contto C) \contto (B \contto D)\\
1010+f \contto g = \mathit{curry}\ (g \circ \mathit{apply} \circ (\mathsf{id} \times f))\\[2em]
1111+\text{(or, operationally:)}\\
1212+(f \contto g)(h) = g \circ h \circ f\\
1313+\end{array}}
1414+}
+10
trees/dt-002Y.tree
···11+\import{dt-macros}
22+\author{liamoc}
33+\taxon{Theorem}
44+\p{
55+The two [functor](dm-000J) laws follow as a consequence of the [universal property](dt-002T) for functions:
66+\ol{
77+\li{ #{\mathsf{id}_A \contto \mathsf{id}_B = \mathsf{id}_{A \contto B}}}
88+\li{ #{(f \circ g) \contto (h \circ i) = (g \contto h) \circ (f \contto i)}}
99+}
1010+}
+12
trees/dt-002Z.tree
···11+\import{dt-macros}
22+\title{Functions}
33+\author{liamoc}
44+\p{Previously, such as in \ref{dt-001U}, we already implicitly assumed that the set of [continuous functions](dt-002F) on [cpos](dt-001D) #{A \contto B} is itself a [cpo](dt-001D). In this section, we will formalise this construction.}
55+\transclude{dt-002L}
66+\transclude{dt-002M}
77+\transclude{dt-002P}
88+\transclude{dt-002T}
99+\transclude{dt-002U}
1010+\transclude{dt-002V}
1111+\transclude{dm-000Q}
1212+\transclude{dt-002W}