···11+\title{Idempotence (of binary operators)}
22+\author{liamoc}
33+\taxon{Definition}
44+\p{ A binary operator #{\bullet} is \em{idempotent} iff, for all #{x}, #{x \bullet x = x}.}
+4
trees/dm-000E.tree
···11+\title{Commutativity}
22+\author{liamoc}
33+\taxon{Definition}
44+\p{ A binary operator #{\bullet} is \em{commutative} iff, for all #{x} and #{y}, #{x \bullet y = y \bullet x}.}
+4
trees/dm-000F.tree
···11+\title{Associativity}
22+\author{liamoc}
33+\taxon{Definition}
44+\p{ A binary operator #{\bullet} is \em{associative} iff, for all #{x}, #{y} and #{z}, #{x \bullet (y \bullet z) = (x \bullet y) \bullet z}. That is, the grouping with parentheses doesn't matter.}
···11\import{dt-macros}
22-\title{First Steps into Domains}
22+\title{Semantics and recursion}
33\taxon{Lecture}
44\author{liamoc}
55\p{This lecture is based on material from [[haskellhutt]], [[danascott]], [[jstoy]], [[cgunter]], and [[gwinskel]].}
+1-1
trees/dt-0006.tree
···88}
99The intuitive way to assign a semantics would be to use a \em{recursive function}:
1010##{
1111-\llbracket \mathsf{while}\ b\ \mathsf{do}\ c\ \mathsf{od} \rrbracket_\mathcal{C}\ \sigma\; = \; \begin{cases} \llbracket \mathsf{while}\ b\ \mathsf{do}\ c\ \mathsf{od} \rrbracket_\mathcal{C}\ (\llbracket c \rrbracket_\mathcal{C}\ \sigma) & \text{if}\ \llbracket b \rrbracket_\mathcal{B}\ \sigma = T \\
1111+\llbracket \mathsf{while}\ b\ \mathsf{do}\ c\ \mathsf{od} \rrbracket_\mathcal{C}\ \sigma\; = \; \begin{cases} \llbracket \mathsf{while}\ b\ \mathsf{do}\ c\ \mathsf{od} \rrbracket_\mathcal{C}\ (\llbracket c \rrbracket_\mathcal{C}\ \sigma) & \text{if}\ \llbracket b \rrbracket_\mathcal{B}\ \sigma = \True \\
1212 \sigma & \text{otherwise}
1313 \end{cases}
1414}
+2-2
trees/dt-000H.tree
···11\import{dt-macros}
22-\title{Monotonic Functions}
22+\title{Monotonic functions}
33\author{liamoc}
44\p{If we model our semantic domains for values with [pointed poset](dt-000G)s, then programs are modelled by functions between such [poset](dm-0004)s. But, not all functions are suitable:}
55\transclude{dt-000I}
66\p{It stands to reason that the amount of information we get out of our functions should grow as we increase the amount of information we put into them.
77-Such functions are called \em{monotonic} with respect to our information ordering.}
77+Such functions are called \em{monotonic} with respect to our [information ordering](dt-000B).}
88\transclude{dt-000J}
99\transclude{dt-000K}
1010\scope{
+8
trees/dt-000N.tree
···22\taxon{Exercise}
33\author{liamoc}
44\p{Consider the functions #{\mathbb{B}_\bot \rightarrow \mathbb{B}_\bot}. Which ones are [monotonic](dt-000J)? There are a total of 27 such functions but only three significant classes.}
55+\scope{
66+\put\transclude/toc{false}
77+\put\transclude/numbered{false}
88+\put\transclude/expanded{false}
99+\subtree{
1010+ \taxon{Solution}
1111+ \p{The three classes are the nine [strict](dt-000K) functions (which map #{\bot} to #{\bot}), which are all [monotonic](dt-000J), the two non-strict constant functions (which ignore their input and return #{\True} and #{\False} respectively), which are also monotonic, and the 16 non-monotonic functions.}
1212+}}
+19
trees/dt-000O.tree
···4545}
4646\ol{
4747 \li{ Write down the monotonic functions #{\mathbf{K}_3 \rightarrow \mathbf{K}_3}.}
4848+ \scope{
4949+ \put\transclude/toc{false}
5050+ \put\transclude/numbered{false}
5151+ \put\transclude/expanded{false}
5252+ \subtree{
5353+ \taxon{Solution}
5454+ \p{When drawn as a diagram like the above, the monotonic functions are all those whose lines do not cross.}
5555+ }}
4856 \li{ Write a simple recursive program to calculate the number of monotonic functions #{\mathbf{K}_n \rightarrow \mathbf{K}_m}.}
5757+ \scope{
5858+ \put\transclude/toc{false}
5959+ \put\transclude/numbered{false}
6060+ \put\transclude/expanded{false}
6161+ \subtree{
6262+ \taxon{Solution}
6363+\p{In Haskell:}
6464+ \pre{monotonics :: Int -> Int -> Int
6565+monotonics n 1 = 1
6666+monotonics n m = sum [monotonics (n-x) (m-1) | x <- [0..n]]}
6767+}}
4968}
···22\taxon{Exercise}
33\author{liamoc}
44\ol{
55-\li{Give an example of a [poset](dm-0004) #{A} and a [monotonic](dt-000J) function #{f : A \rightarrow A} such that #{f} \em{doesn't} have a [fixed point](dt-000S).}
55+\li{Give an example of a [poset](dm-0004) #{A} and a [monotonic](dt-000J) function #{f : A \rightarrow A} such that #{f} \em{doesn't} have a [fixed point](dt-000S).
66+\scope{
77+\put\transclude/toc{false}
88+\put\transclude/numbered{false}
99+\put\transclude/expanded{false}
1010+\subtree{
1111+ \taxon{Solution}
1212+ \p{In the poset #{(\mathbb{N},\leq)}, the function #{f(x) = x + 1} has no fixed points.}
1313+}}
1414+}
615\li{Give an example of a [poset](dm-0004) #{A} and a [monotonic](dt-000J) function #{f : A \rightarrow A} such that #{f} has \em{multiple} [fixed point](dt-000S)s.}
1616+\scope{
1717+\put\transclude/toc{false}
1818+\put\transclude/numbered{false}
1919+\put\transclude/expanded{false}
2020+\subtree{
2121+ \taxon{Solution}
2222+ \p{In the poset #{(\mathbb{N},\leq)}, the function #{f(x) = x} has infinitely many fixed points.}
2323+}}
724}
···11\taxon{Definition}
22-\title{Consistent subsets}
22+\title{Consistent subset}
33\p{
44 A subset #{Y \subseteq X} of a [poset](dm-0004) #{X} is \em{consistent} iff
55 ##{\exists x \in X.\ \forall y \in Y.\ y \sqsubseteq x}
+3
trees/dt-0015.tree
···11+\taxon{Corollary}
22+\author{liamoc}
33+\p{From \ref{dt-0014} we can see that a \em{finite} set #{S} is [directed](dt-0010) iff it has a \em{top} element #{\top}, i.e. #{\forall x \in S.\ x \sqsubseteq \top}.}
···11+\import{dt-macros}
22+\taxon{Definition}
33+\title{Least upper bound}
44+\author{liamoc}
55+\p{Let #{X \subseteq Y} be a subset of a [poset](dm-0004) #{Y}. An element #{y \in Y} is a \em{least upper bound} (or \em{lub}) for #{X} iff:
66+\ol{
77+ \li{ It is an [upper bound](dm-000C): #{\forall x \in X.\ x \sqsubseteq y}}
88+ \li{ It is less than any other [upper bound](dm-000C): #{\forall y' \in Y.\ (\forall x \in X. x \sqsubseteq y') \Rightarrow y \sqsubseteq y'}}
99+}
1010+It follows that lubs are unique if they exist. We write the lub of a set #{X} as #{\bigsqcup X}, and usually write #{x \sqcup y} as a shorthand for #{\bigsqcup \Set{x,y}}.
1111+}
+7
trees/dt-0018.tree
···11+\import{dt-macros}
22+\taxon{Corollary}
33+\title{Properties of #{\sqcup}}
44+\author{liamoc}
55+\p{
66+ When [lubs](dt-0017) exist, the binary #{\sqcup} operator is [idempotent](dm-000D), [commutative](dm-000E), and [associative](dm-000F). Also, we have that #{x \sqsubseteq y} iff #{x \sqcup y = y}.
77+}
+6
trees/dt-0019.tree
···11+\taxon{Theorem}
22+\title{Pointedness via lubs}
33+\author{liamoc}
44+\p{
55+ A [poset](dm-0004) #{Y} is [pointed](dt-000G) iff #{\bigsqcup \emptyset} exists, as the [lub](dt-0017) of an empty set is just the [bottom element](dt-000A) in the [poset](dm-0004), i.e. #{\bigsqcup \emptyset = \bot}.
66+}
+2
trees/dt-001A.tree
···11+\title{Information intuition}
22+\p{When the [poset](dm-0004) #{Y} from \ref{dt-0017} is ordered by our [information ordering](dt-000B), the intuition of the [lub](dt-0017) #{\bigsqcup X} is that it combines all of the information content of all the elements of #{X} but it does \em{not} add any additional information (hence \em{least}).}
···11+\import{dt-macros}
22+\taxon{Exercise}
33+\p{ What is the [lub](dt-0017) operator on subsets #{X \subseteq \nat} of the [poset](dm-0004) #{(\nat,\leq)}?}
44+\scope{
55+\put\transclude/toc{false}
66+\put\transclude/numbered{false}
77+\put\transclude/expanded{false}
88+\subtree{
99+ \taxon{Solution}
1010+ \p{The [lub](dt-0017) operator is \em{maximum}.}
1111+}}
+9
trees/dt-001D.tree
···11+\taxon{Definition}
22+\author{liamoc}
33+\title{Complete partial order}
44+\p{A \em{complete partial order} or \em{cpo} (more specifically a \em{directed complete partial order} or \em{dcpo}) is a [poset](dm-0004) where [lubs](dt-0017) exist for the empty set and for all [directed](dt-0010) subsets. That is, a \em{cpo} is a [poset](dm-0004) #{A} such that:
55+\ol{
66+ \li{#{A} has a [bottom element](dt-000A) #{\bot \in A}, that is the [lub of the empty set](dt-0019), and}
77+ \li{#{\bigsqcup X} exists for all [directed](dt-0010) #{X \subseteq A}.}
88+}
99+}
···11+\taxon{Aside}
22+\title{Other kinds of completeness}
33+\author{liamoc}
44+\p{In \ref{dt-001D} we defined cpos in terms of \em{directed completeness}. We may consider \em{chain completeness} instead, where, rather than require [lubs](dt-0017) for every [directed](dt-0010) subset of our [poset](dm-0004) #{A}, we require [lubs](dt-0017) for every [chain](dt-000V) #{X \subseteq A}. We know from \ref{dt-0012} that all [chains](dt-000V) are [directed](dt-0010), so every directed complete cpo is also chain complete. It is also known that every chain complete cpo is also directed complete, so the notions are \strong{equivalent}, although the proof is apparently non-trivial and buried in the literature.}
55+\p{If we weaken our completeness requirement to require [lubs](dt-0017) only for the countable [#{\omega}-chains](dt-000W) and not necessarily all chains, we get what is called an \em{#{\omega}-cpo}. All [#{\omega}-chains](dt-000W) are [chains](dt-000V) and are therefore [directed](dt-0010), but not all [chains](dt-000V) are [#{\omega}-chains](dt-000W).}
66+\p{Working with just #{\omega}-cpos is common in [denotational semantics](dt-0001) practice, but working with [directed](dt-0010) completeness simplifies some of the properties we will discuss later.}
+30
trees/dt-001G.tree
···11+\import{dt-macros}
22+\taxon{Exercise}
33+\author{liamoc}
44+\p{For each of the following [posets](dm-0004), determine if it is a [cpo](dt-001D) or not. If it is, describe the [lubs](dt-0017). If it is not, give a [directed](dt-0010) set which has no [lub](dt-0017).}
55+ \ol{
66+ \li{ A finite [pointed poset](dt-000G) }
77+ \li{ #{(\cal{P}(S), \subseteq)} for some set #{S}}
88+ \li{ #{(\nat,\leq)}}
99+ \li{ #{(\nat \cup \Set{\infty}, \leq)}}
1010+ \li{ #{ ([0,1] \subseteq \mathbb{R}, \leq)}}
1111+ \li{ #{ (\mathbb{Q}, \leq)}}
1212+ \li{ A [flat domain](dt-0008) #{S_\bot} for some set #{S}.}
1313+}
1414+\scope{
1515+ \put\transclude/toc{false}
1616+ \put\transclude/numbered{false}
1717+ \put\transclude/expanded{false}
1818+ \subtree{
1919+\taxon{Solution}
2020+\ol{
2121+ \li{ A finite [pointed poset](dt-000G) is a [cpo](dt-001D), as all [directed](dt-0010) subsets will be finite and therefore have a [lub](dt-0017). }
2222+\li{ #{(\cal{P}(S), \subseteq)} is a [cpo](dt-001D) as the [lub](dt-0017) is just the union. }
2323+\li{ #{(\nat,\leq)} is \em{not} a [cpo](dt-001D), as the [#{\omega}-chain](dt-000W) #{1 \leq 2 \leq 3 \leq \cdots} has no [lub](dt-0017).}
2424+\li{ #{(\nat \cup \Set{\infty}, \leq)} is a [cpo](dt-001D), as #{\infty} is the [lub](dt-0017) of any non-repeating [chain](dt-000V). }
2525+\li{ #{ ([0,1] \subseteq \mathbb{R}, \leq)} is a [cpo](dt-001D) with maximum as the [lub](dt-0017), but the open range (excluding 1) is not.}
2626+\li{ #{ (\mathbb{Q}, \leq)} is \em{not} a [cpo](dt-001D), and not just because it lacks a [lub](dt-0017) for #{\mathbb{Q}} itself, but also it doesn't contain #{\sqrt{2}}, which can be expressed as the [lub](dt-0017) of an infinite sequence of rational approximations. }
2727+\li{ A [flat domain](dt-0008) #{S_\bot} for some set #{S} is a [cpo](dt-001D), as the largest [chains](dt-000V) have two elements, and we always pick the non-#{\bot} one as the [lub](dt-0017). }
2828+ }
2929+}
3030+}