Fix all warnings, add conclusion

This commit is contained in:
Leon Vatthauer 2024-03-17 15:13:11 +01:00
parent 6d254586e1
commit 8000bf9884
Signed by: leonv
SSH key fingerprint: SHA256:G4+ddwoZmhLPRB1agvXzZMXIzkVJ36dUYZXf5NxT+u8
9 changed files with 123 additions and 96 deletions

View file

@ -77,3 +77,6 @@ Goncharov
denotational
Plotkin
monadic
Vatthauer
minimality
coequalizer

View file

@ -49,3 +49,11 @@
{"rule":"IF_IS","sentence":"^\\QConsider \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q defined by \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q if \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q if \\E(?:Dummy|Ina|Jimmy-)[0-9]+$"}
{"rule":"IF_IS","sentence":"^\\QFurthermore, consider the setoid function \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q defined by \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q if \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q if \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q Now, by coinduction we can easily follow that \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q for any \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q \\E(?:Dummy|Ina|Jimmy-)[0-9]+$"}
{"rule":"WHITESPACE_RULE","sentence":"^\\QFriedrich-Alexander-Universität Erlangen-Nürnberg [] Chair for Computer Science 8 Theoretical Computer Science Bachelor Thesis in Computer Science [0.5] Advisor: Sergey Goncharov Erlangen,\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_US","sentence":"^\\Q[agda] linenos=true, breaklines=true, encoding=utf8, fontsize=, frame=lines, autogobble\\E$"}
{"rule":"WHITESPACE_RULE","sentence":"^\\Q[4][]##4\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_US","sentence":"^\\Q[cases] mycase Case .\\E$"}
{"rule":"COMMA_PARENTHESIS_WHITESPACE","sentence":"^\\Q[cases] mycase Case .\\E$"}
{"rule":"IF_IS","sentence":"^\\QLet \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q be a setoid and \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q be a setoid morphism, we define \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q point wise: \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q if \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q if \\E(?:Dummy|Ina|Jimmy-)[0-9]+$"}
{"rule":"IF_IS","sentence":"^\\QFurthermore, consider the setoid morphism \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q defined by \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q if \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q if \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q Now, by coinduction we can easily follow that \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q for any \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q \\E(?:Dummy|Ina|Jimmy-)[0-9]+$"}
{"rule":"IF_IS","sentence":"^\\QConsider, \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q if \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q if \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q if \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q and \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q if \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q if \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q where \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q is a setoid morphism that maps every \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q to \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q.\\E$"}
{"rule":"IF_IS","sentence":"^\\QConsider another setoid morphism \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q, defined by \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q if \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q if \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q if \\E(?:Dummy|Ina|Jimmy-)[0-9]+$"}

View file

@ -1,23 +1,15 @@
\documentclass[a4paper,11pt,numbers=noenddot]{scrbook}
\usepackage[top=2cm,lmargin=1in,rmargin=1in,bottom=3cm,hmarginratio=1:1]{geometry}
\usepackage[ngerman, main=british]{babel}
\usepackage[ngerman, english]{babel}
\babeltags{german=ngerman}
\usepackage{minted}
\setminted[agda]{
linenos=true,
breaklines=true,
encoding=utf8,
fontsize=\small,
frame=lines,
autogobble
}
% \usepackage{mathabx}
% \usepackage{amssymb}
\usepackage[dvipsnames]{xcolor} % Coloured text etc.
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{fancyvrb}
\usepackage{anyfontsize}
% \usepackage{mathtools}
% \usepackage{amsmath}
\usepackage{mathpartir}
@ -56,6 +48,16 @@
%\usepackage[justific=raggedright,totoc]{idxlayout}
\usepackage[type=CC, modifier=by-sa,version=4.0]{doclicense}
% Listings package supporting unicode and agda highlighting
\usepackage{minted}
\setminted[agda]{
linenos=true,
breaklines=true,
encoding=utf8,
fontsize=\small,
frame=lines,
autogobble
}
% autoref for minted listings
\providecommand*{\listingautorefname}{Listing}
@ -89,7 +91,9 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt}
% \setlength\parskip{\baselineskip}
\setlength{\marginparsep}{0cm}
\AtBeginEnvironment{minted}{\setlength{\parskip}{0pt}}
\title{Implementing Categorical Notions of Partiality and Delay in Agda}
@ -106,7 +110,7 @@
\makeatother
\usepackage[scale=.8]{noto-mono}
\usepackage[scale=.85]{noto-mono}
\usepackage{mathrsfs}
\usepackage{xargs}
@ -191,14 +195,14 @@
\pagestyle{plain}
\input{src/titlepage}%
\chapter*{Disclaimer}
\begin{german}
Ich versichere, dass ich die Arbeit ohne fremde Hilfe und ohne Benutzung anderer als der angegebenen Quellen angefertigt habe und dass die Arbeit in gleicher oder ähnlicher Form noch keiner anderen Prüfungsbehörde vorgelegen hat und von dieser als Teil einer Prüfungsleistung angenommen wurde.
Alle Ausführungen, die wörtlich oder sinngemäß übernommen wurden, sind als solche gekennzeichnet.
{\begin{german}
Ich versichere, dass ich die Arbeit ohne fremde Hilfe und ohne Benutzung anderer als der angegebenen Quellen angefertigt habe und dass die Arbeit in gleicher oder ähnlicher Form noch keiner anderen Prüfungsbehörde vorgelegen hat und von dieser als Teil einer Prüfungsleistung angenommen wurde.
Alle Ausführungen, die wörtlich oder sinngemäß übernommen wurden, sind als solche gekennzeichnet.
\vspace{5em}
Erlangen, \today{} \rule{7cm}{1pt}\\
\phantom{Erlangen, \today{}} \theauthor{}
\end{german}
\vspace{5em}
Erlangen, \today{} \rule{7cm}{1pt}\\
\phantom{Erlangen, \today{}} \theauthor{}
\end{german}}
% \chapter*{Licensing}
% \doclicenseThis{}
@ -207,7 +211,7 @@
\tableofcontents
\listoftodos\
% \listoftodos\
\newcommandx{\unsure}[2][1=]{\todo[inline,linecolor=red,backgroundcolor=red!25,bordercolor=red,#1]{#2}}
\newcommandx{\change}[2][1=]{\todo[linecolor=blue,backgroundcolor=blue!25,bordercolor=blue,#1]{#2}}
@ -231,8 +235,6 @@
\include{src/06_setoids}
\include{src/07_conclusion}
\todo[inline]{Add fullstop behind every proof}
\appendix
\medskip

View file

@ -9,12 +9,13 @@ reverse l = revAcc l []
revAcc [] a = a
revAcc (x:xs) a = revAcc xs (x:a)
\end{minted}
and regard the following definition of an infinite list:
and regard the following definition of an infinite list
\begin{minted}{haskell}
ones :: [Int]
ones = 1 : ones
\end{minted}
Of course the call \texttt{reverse ones} will never terminate, hence \texttt{reverse} is a partial function.
Of course evaluation of the term \texttt{reverse ones} will never terminate, hence it is clear that \texttt{reverse} is a partial function.
Thus, in order to reason about Haskell programs, or generally programs of any programming language offering general recursion, one needs to be able to model partiality as a side effect.
Generally for modelling programming languages there are three prevailing methods. First is the operational approach introduced by Plotkin~\cite{plotkin1975call}, where partial functions are used that map programs to their resulting values, secondly there is the denotational approach by Scott~\cite{scott1993type}, where programming languages are interpreted mathematically, by functions capturing the ``meaning'' of programs.
@ -22,5 +23,11 @@ For this thesis we will consider the third, categorical approach that has been i
In the categorical approach programs are interpreted in categories, where objects represent types and monads are used to model side effects.
The goal for this thesis is thus to study monads which are suitable for modeling partiality.
We use the dependent programming language Agda~\cite{agda} as a safe and type-checked environment for reasoning in category theory, therefore in \autoref{chp:agda-cat} we start out by quickly introducing the Agda programming language as well as the category theory library that we will be working with. In \autoref{chp:partiality} we will then consider various properties that partiality monads should have and examine Capretta's delay monad~\cite{delay}, which has been introduced in type theory as a coinductive data type and then studied as a monad in the category of setoids. We will examine the delay monad in a general categorical setting, where however the delay monad will prove to be insufficient as a monad for modeling only partiality due to the too intensional notion of equality that this monad comes with. It is believed to be impossible to remedy this problem in a way that preserves the monadic structure without use of additional axioms, thus in \autoref{chp:iteration} we will draw on the inherent connection between iteration and recursion to define a suitable partiality monad in a general setting without extra axioms, by relating to previous research on iteration theories. This monad has first been introduced and studied in~\cite{uniformelgot} under weaker assumptions than we use, concretely by weakening the notion of Elgot algebra to the notion of uniform iteration algebra, which uses fewer axioms. During mechanization of the results concerning this monad it turned out that under the weaker assumptions, desirable properties like commutativity seem not to be provable, resulting in the adaptation of this monad.
Lastly, in \autoref{chp:setoids} we will study this partiality monad in the category of setoids, where it will turn out to be equivalent to a certain quotient of the delay monad.
We use the dependently typed programming language Agda~\cite{agda} as a safe and type-checked environment for reasoning in category theory, therefore in \autoref{chp:agda-cat} we start out by quickly showcasing the Agda programming language as well as the category theory library that we will be working with.
In \autoref{chp:partiality} we will then consider various properties that partiality monads should satisfy and inspect Capretta's delay monad~\cite{delay}, which has been introduced in type theory as a coinductive data type and then studied as a monad in the category of setoids.
We will examine the delay monad in a general categorical setting, where we prove strength and commutativity of this monad. However, it is not a minimal partiality monad, i.e.\ one that captures no other side effect besides some form of non-termination, since the monad comes with a too intensional notion of equality. In order to achieve minimality one can consider the quotient of the delay monad where a less intensional notion of equality is used. However, it is believed to be impossible to show that the monadic structure is preserved under such a quotient, but the axiom of countable choice has been identified as a sufficient assumption under which the monad structure is preserved in~\cite{quotienting}.
In order to define a partiality monad using no such assumptions, we will draw on the inherent connection between iteration and recursion in \autoref{chp:iteration} to define a suitable partiality monad, by relating to previous research on iteration theories.
This monad has first been introduced and studied in~\cite{uniformelgot} under weaker assumptions than we use, concretely by weakening the notion of Elgot algebra to the notion of uniform iteration algebra, which uses fewer axioms.
During mechanization of the results concerning this monad it turned out that under the weaker assumptions, desirable properties like commutativity seem not to be provable, resulting in the adaptation of this monad.
Lastly, in \autoref{chp:setoids} we will study this partiality monad in the category of setoids, where notably the axiom of countable choice holds.
In this category, the partiality monad will turn out to be equivalent to a certain quotient of the delay monad.

View file

@ -8,27 +8,24 @@ We will also sometimes omit indices of the identity and of natural transformatio
\section{Distributive and Cartesian Closed Categories}
Let us first introduce notation for binary (co)products by giving their usual diagrams: % chktex 36
\begin{figure}[ht]
% https://q.uiver.app/#q=WzAsOCxbMiwwLCJBIFxcdGltZXMgQiJdLFswLDAsIkEiXSxbNCwwLCJCIl0sWzIsMiwiQyJdLFs4LDAsIkEgKyBCIl0sWzYsMCwiQSJdLFsxMCwwLCJCIl0sWzgsMiwiQyJdLFswLDEsIlxccGlfMSIsMl0sWzAsMiwiXFxwaV8yIl0sWzMsMiwiZyIsMl0sWzMsMSwiZiJdLFszLDAsIlxcZXhpc3RzISBcXGxhbmdsZSBmICwgZyBcXHJhbmdsZSIsMix7InN0eWxlIjp7ImJvZHkiOnsibmFtZSI6ImRhc2hlZCJ9fX1dLFs1LDQsImlfMSJdLFs2LDQsImlfMiIsMl0sWzUsNywiZiIsMl0sWzYsNywiZyJdLFs0LDcsIlxcZXhpc3RzICEgW2YgLCBnXSIsMV1d
\[
\begin{tikzcd}
A && {A \times B} && B && A && {A + B} && B \\
\\
&& C &&&&&& C
\arrow["{\pi_1}"', from=1-3, to=1-1]
\arrow["{\pi_2}", from=1-3, to=1-5]
\arrow["g"', from=3-3, to=1-5]
\arrow["f", from=3-3, to=1-1]
\arrow["{\exists! \langle f , g \rangle}"', dashed, from=3-3, to=1-3]
\arrow["{i_1}", from=1-7, to=1-9]
\arrow["{i_2}"', from=1-11, to=1-9]
\arrow["f"', from=1-7, to=3-9]
\arrow["g", from=1-11, to=3-9]
\arrow["{\exists ! [f , g]}", dashed, from=1-9, to=3-9]
\end{tikzcd}
\]
\caption{The defining diagrams of products and coproducts}
\end{figure}
% https://q.uiver.app/#q=WzAsOCxbMiwwLCJBIFxcdGltZXMgQiJdLFswLDAsIkEiXSxbNCwwLCJCIl0sWzIsMiwiQyJdLFs4LDAsIkEgKyBCIl0sWzYsMCwiQSJdLFsxMCwwLCJCIl0sWzgsMiwiQyJdLFswLDEsIlxccGlfMSIsMl0sWzAsMiwiXFxwaV8yIl0sWzMsMiwiZyIsMl0sWzMsMSwiZiJdLFszLDAsIlxcZXhpc3RzISBcXGxhbmdsZSBmICwgZyBcXHJhbmdsZSIsMix7InN0eWxlIjp7ImJvZHkiOnsibmFtZSI6ImRhc2hlZCJ9fX1dLFs1LDQsImlfMSJdLFs2LDQsImlfMiIsMl0sWzUsNywiZiIsMl0sWzYsNywiZyJdLFs0LDcsIlxcZXhpc3RzICEgW2YgLCBnXSIsMV1d
\[
\begin{tikzcd}
A && {A \times B} && B && A && {A + B} && B \\
\\
&& C &&&&&& C
\arrow["{\pi_1}"', from=1-3, to=1-1]
\arrow["{\pi_2}", from=1-3, to=1-5]
\arrow["g"', from=3-3, to=1-5]
\arrow["f", from=3-3, to=1-1]
\arrow["{\exists! \langle f , g \rangle}"', dashed, from=3-3, to=1-3]
\arrow["{i_1}", from=1-7, to=1-9]
\arrow["{i_2}"', from=1-11, to=1-9]
\arrow["f"', from=1-7, to=3-9]
\arrow["g", from=1-11, to=3-9]
\arrow["{\exists ! [f , g]}", dashed, from=1-9, to=3-9]
\end{tikzcd}
\]
We will furthermore overload this notation and write \(f \times g := \langle f \circ \pi_1 , g \circ \pi_2 \rangle \) and \(f + g := \lbrack i_1 \circ f , i_2 \circ g \rbrack \) on morphisms. To avoid parentheses we will use the convention that products bind stronger than coproducts.

View file

@ -47,13 +47,13 @@ Streams are always infinite and thus this representation of coinductive types as
\end{minted}
That is, the coinductive type \(coList\) is defined by the constructors \(nil\) and \(\). Agda does implement a second kind of coinductive types that allows exactly such definitions, however the use of these sometimes called \emph{positive coinductive types} is discouraged, since it is known to break subject reduction~\cite{agda-man}\cite{coq-man}. Instead, sticking to coinductive records, we can define \(coList\) as two mutual types, one inductive and the other coinductive:
\begin{minted}{agda}
mutual
data coList (A : Set) : Set where
nil : coList A
__ : A → coList A → coList A
record coList (A : Set) : Set where
coinductive
field force : coList A
mutual
data coList (A : Set) : Set where
nil : coList A
__ : A → coList A → coList A
record coList (A : Set) : Set where
coinductive
field force : coList A
\end{minted}
Unfortunately, this does add the overhead of having to define functions on \(coList\) as mutual recursive functions, e.g.\ the \(repeat\) function from before can be defined as
\begin{minted}{agda}

View file

@ -317,14 +317,14 @@ Products and exponentials of Elgot algebras can be formed in a canonical way, wh
& {((eval + id) \circ dstr \circ (f \times id))}^{\sharp_a}
\\=\;&{((eval + id) \circ dstr \circ (g \times id))}^{\sharp_a} \circ (h \times id)\tag{\ref{law:uniformity}}
\\=\;&eval \circ ({((eval + id) \circ dstr \circ (g \times id))}^{\sharp_a} \times id) \circ (h \times id)
\\=\;&eval \circ ({((eval + id) \circ dstr \circ (g \times id))}^{\sharp_a} \circ h \times id)
\\=\;&eval \circ ({((eval + id) \circ dstr \circ (g \times id))}^{\sharp_a} \circ h \times id).
\end{alignat*}
Note that the application of \ref{law:uniformity} requires: % chktex 2
\begin{alignat*}{1}
& (id + (h \times id)) \circ (eval + id) \circ dstr \circ (f \times id)
\\=\;&(eval + id) \circ (id + (h \times id)) \circ dstr \circ (f \times id)
\\=\;&(eval + id) \circ dstr \circ (id \times h) \circ (id \times id) \circ (f \times id)
\\=\;&(eval + id) \circ dstr \circ (g \times id) \circ (h \times id)
\\=\;&(eval + id) \circ dstr \circ (g \times id) \circ (h \times id).
\end{alignat*}
\item \textbf{Folding}: Let \(f : Y \rightarrow X^A + Y, h : Y \rightarrow Z\). We need to show that
\begin{alignat*}{1}
@ -333,7 +333,7 @@ Products and exponentials of Elgot algebras can be formed in a canonical way, wh
\\=\;&curry({((eval + id) \circ dstr \circ ([ (id + i_1) \circ f , i_2 \circ h ] \times id))}^{\sharp_a})
\\=\;&{[ (id + i_1) \circ f , i_2 \circ h ]}^\sharp.
\end{alignat*}
Indeed, we are done by:
Indeed, we are done by
\begin{alignat*}{1}
& {((eval + id) \circ dstr \circ ((curry({((eval + id) \circ dstr \circ (f \times id))}^{\sharp_a}) + h) \times id))}^{\sharp_a}
\\=\;&{((eval + id) \circ ((curry({((eval + id) \circ dstr \circ (f \times id))}^{\sharp_a}) \times id) + (h \times id)) \circ dstr)}^{\sharp_a}
@ -341,22 +341,24 @@ Products and exponentials of Elgot algebras can be formed in a canonical way, wh
\\=\;&{(({((eval + id) \circ dstr \circ (f \times id))}^{\sharp_a} + (h \times id)) \circ dstr)}^{\sharp_a}
\\=\;&{(({((eval + id) \circ dstr \circ (f \times id))}^{\sharp_a} + dstr \circ (h \times id)))}^{\sharp_a} \circ dstr\tag{\ref{law:uniformity}}
\\=\;&[ (id + i_1) \circ (eval + id) \circ dstr \circ (f \times id) , i_2 \circ dstr \circ (h \times id) ] \circ dstr\tag{\ref{law:folding}}
\\=\;&{((eval + id) \circ dstr \circ ([ (id + i_1) \circ f , i_2 \circ h ] \times id))}^{\sharp_a}.\tag{\ref{law:uniformity}}
\end{alignat*}
Note that the second application of~\ref{law:uniformity} is non-trivial, using epicness of \(dstr^{-1}\):
\begin{alignat*}{1}
& (id + dstr) \circ (eval + id) \circ dstr \circ ([ (id + i_1) \circ f , i_2 \circ h ] \times id) \circ dstr^{-1}
\\=\;&[ (id + dstr) \circ (eval + id) \circ dstr \circ ([ (id + i_1) \circ f , i_2 \circ h ] \times id) \circ (i_1 \times id)
\\&, (id + dstr) \circ (eval + id) \circ dstr \circ ([ (id + i_1) \circ f , i_2 \circ h ] \times id) \circ (i_2 \times id) ]
\\=\;&[ (id + dstr) \circ (eval + id) \circ dstr \circ (((id + i_1) \circ f) \times id)
\\&, (id + dstr) \circ (eval + id) \circ dstr \circ ((i_2 \circ h) \times id) ]
\\=\;&[ (id + dstr) \circ (eval + id) \circ dstr \circ ((id + i_1) \times id) \circ (f \times id)
\\&, (id + dstr) \circ (eval + id) \circ dstr \circ (i_2 \times id) \circ (h \times id) ]
\\=\;&[ (id + dstr) \circ (eval + id) \circ (id + (i_1 \times id)) \circ dstr \circ (f \times id)
\\&, (id + dstr) \circ (eval + id) \circ i_2 \circ (h \times id) ]
\\=\;&[ (eval + i_1) \circ dstr \circ (f \times id) , i_2 \circ dstr \circ (h \times id) ]
\\=\;&[ (id + i_1) \circ (eval + id) \circ dstr \circ (f \times id) , i_2 \circ dstr \circ (h \times id) ] \circ dstr \circ dstr^{-1}.\tag*{\qedhere}
\\=\;&{((eval + id) \circ dstr \circ ([ (id + i_1) \circ f , i_2 \circ h ] \times id))}^{\sharp_a},\tag{\ref{law:uniformity}}
\end{alignat*}
where the identity that is required for the second application of~\ref{law:uniformity} follows by epicness of \(dstr^{-1}\).
\qedhere
% \begin{alignat*}{1}
% & (id + dstr) \circ (eval + id) \circ dstr \circ ([ (id + i_1) \circ f , i_2 \circ h ] \times id) \circ dstr^{-1}
% \\=\;&[ (id + dstr) \circ (eval + id) \circ dstr \circ ([ (id + i_1) \circ f , i_2 \circ h ] \times id) \circ (i_1 \times id)
% \\&, (id + dstr) \circ (eval + id) \circ dstr \circ ([ (id + i_1) \circ f , i_2 \circ h ] \times id) \circ (i_2 \times id) ]
% \\=\;&[ (id + dstr) \circ (eval + id) \circ dstr \circ (((id + i_1) \circ f) \times id)
% \\&, (id + dstr) \circ (eval + id) \circ dstr \circ ((i_2 \circ h) \times id) ]
% \\=\;&[ (id + dstr) \circ (eval + id) \circ dstr \circ ((id + i_1) \times id) \circ (f \times id)
% \\&, (id + dstr) \circ (eval + id) \circ dstr \circ (i_2 \times id) \circ (h \times id) ]
% \\=\;&[ (id + dstr) \circ (eval + id) \circ (id + (i_1 \times id)) \circ dstr \circ (f \times id)
% \\&, (id + dstr) \circ (eval + id) \circ i_2 \circ (h \times id) ]
% \\=\;&[ (eval + i_1) \circ dstr \circ (f \times id) , i_2 \circ dstr \circ (h \times id) ]
% \\=\;&[ (id + i_1) \circ (eval + id) \circ dstr \circ (f \times id) , i_2 \circ dstr \circ (h \times id) ] \circ dstr \circ dstr^{-1}.\tag*{\qedhere}
% \end{alignat*}
\end{itemize}
\end{proof}

View file

@ -11,15 +11,15 @@ We will now introduce the category that the rest of the chapter will take place
For brevity, we will not use the tuple notation most of the time, instead we will just say `Let \(A\) be a setoid' and implicitly call the equivalence relation \(\overset{A}{=}\).
\begin{definition}[Setoid Function]
A function on setoids \(A\) and \(B\) is a function \(f : A \rightarrow B\) between the carriers, such that \(f\) respects the equivalences, i.e.\ for any \(x,y : A\), \(x \overset{A}{=} y\) implies \(f\;x \overset{B}{=} f\;y\). We will denote setoid functions as \(A ⇝ B\).
\begin{definition}[Setoid Morphism]
A morphism between setoids \(A\) and \(B\) is a function \(f : A \rightarrow B\) between the carriers, such that \(f\) respects the equivalences, i.e.\ for any \(x,y : A\), \(x \overset{A}{=} y\) implies \(f\;x \overset{B}{=} f\;y\). We will denote setoid morphisms as \(A ⇝ B\).
\end{definition}
Let us now consider the function space setoid, which is of special interest, since it defines a notion of equality between functions.
Let us now consider the function space setoid, which is of special interest, since it carries a notion of equality between functions.
\begin{definition}[Function Space Setoid]
Given two setoids \(A\) and \(B\). The function space setoid on these setoids is defined as \((A ⇝ B, \doteq)\) or just \(A ⇝ B\), where \(\doteq\) is point wise equality on setoid functions.
Given two setoids \(A\) and \(B\), the function space setoid on these setoids is defined as \((A ⇝ B, \doteq)\) or just \(A ⇝ B\), where \(\doteq\) is the point wise equality on setoid morphisms.
\end{definition}
Setoids together with setoid functions form a category that we will call \(\setoids\). Properties of \(\setoids\) have already been examined in~\cite{setoids}, however we will reiterate some of these properties now to introduce notation that will be used for the rest of the chapter.
Setoids together with setoid morphisms form a category that we will call \(\setoids\). Properties of \(\setoids\) have already been examined in~\cite{setoids}, however we will reiterate some of these properties now to introduce notation that will be used for the rest of the chapter.
\begin{proposition}
\(\setoids\) is a distributive category.
@ -87,7 +87,7 @@ Setoids together with setoid functions form a category that we will call \(\seto
distributeˡ (x , i₁ y) = i₁ (x , y)
distributeˡ (x , i₂ y) = i₂ (x , y)
\end{minted}
Note that these functions are inverse by definition, and it follows quickly that they are setoid functions.
Note that these functions are inverse by definition, and it follows quickly that they are setoid morphism.
\end{proof}
\begin{proposition}\label{prop:setoids-ccc}
@ -127,7 +127,7 @@ Let \(A\) be a setoid. Lifting the equivalence \(\overset{A}{=}\) to \(D\;A\) yi
\((D\;A, \sim)\) is a setoid and admits a monad structure.
\end{proposition}
Computations in \((D\;A, \sim)\) are only identified if they evaluate to the same result in the same amount of steps. In many contexts this behavior is too intensional. Instead, we will now consider the quotient of this setoid, where all computations that evaluate to the same result are identified. Let us first define a relation that states that two computations evaluate to the same result
Computations in \((D\;A, \sim)\) are only identified if they evaluate to the same result in the same number of steps. In many contexts this behavior is too intensional. Instead, we will now consider the quotient of this setoid, where all computations that evaluate to the same result are identified. Let us first define a relation that states that two computations evaluate to the same result
\[
\inferrule*{x \overset{A}{=} y}{now\;x \downarrow y} \qquad
@ -166,9 +166,9 @@ For the rest of this chapter we will abbreviate \(\tilde{D}\;A = (D_A , \sim)\)
Every \(\dbtilde{D}\;A\) can be equipped with an Elgot algebra structure.
\end{lemma}
\begin{proof}
We need to show that for every setoid \(A\) the resulting setoid \(\dbtilde{D}\;A\) can be extended to an Elgot algebra.
We need to show that for every setoid \(A\) the resulting setoid \(\dbtilde{D}\;A\) extends to an Elgot algebra.
Let \(X\) be a setoid and \(f : X ⇝ \dbtilde{D}\;A + X\) be a setoid function, we define \(f^\sharp : X ⇝ \dbtilde{D}\;A\) point wise:
Let \(X\) be a setoid and \(f : X ⇝ \dbtilde{D}\;A + X\) be a setoid morphism, we define \(f^\sharp : X ⇝ \dbtilde{D}\;A\) point wise:
\[
f^\sharp\;x :=
\begin{cases}
@ -177,7 +177,7 @@ For the rest of this chapter we will abbreviate \(\tilde{D}\;A = (D_A , \sim)\)
\end{cases}
\]
Let us first verify that \(f^\sharp\) is indeed a setoid function, i.e.\ given \(x, y : X\) with \(x \overset{X}{=} y\), we need to show that \(f^\sharp\;x \approx f^\sharp\;y\). Since \(f\) is a setoid function we know that \(f\;x \overset{+}{=} f\;y\), which already implies that \(f^\sharp\;x \approx f^\sharp\;y\) by the definition of \(f^\sharp\). Note that by the same argument we can define an iteration operator that respects strong bisimilarity, let us call it \(f^{\tilde{\sharp}}\) as we will later need to distinguish between \(f^\sharp\) and \(f^{\tilde{\sharp}}\).
Let us first verify that \(f^\sharp\) is indeed a setoid morphism, i.e.\ given \(x, y : X\) with \(x \overset{X}{=} y\), we need to show that \(f^\sharp\;x \approx f^\sharp\;y\). Since \(f\) is a setoid morphism we know that \(f\;x \overset{+}{=} f\;y\), which already implies that \(f^\sharp\;x \approx f^\sharp\;y\) by the definition of \(f^\sharp\). Note that by the same argument we can define an iteration operator that respects strong bisimilarity, let us call it \(f^{\tilde{\sharp}}\) as we will later need to distinguish between \(f^\sharp\) and \(f^{\tilde{\sharp}}\).
Next, we check the iteration laws:
@ -189,7 +189,7 @@ For the rest of this chapter we will abbreviate \(\tilde{D}\;A = (D_A , \sim)\)
\case{} \(f\;x = i_2\;a\)
\[ f^\sharp\;x \approx later (f^{\sharp}\;a) \approx f^\sharp\;a \approx [ id , f^\sharp ] (i_2 \;a) \approx [ id , f^\sharp ] (f\;x)\]
\end{mycase}
\item \ref{law:uniformity}: Let \(Y\) be a setoid and \(g : Y ⇝ \dbtilde{D}\;A + Y, h : X ⇝ Y\) be setoid functions, such that \((id + h) \circ f \doteq g \circ h\). We need to show that \(f^\sharp\;x \approx g^\sharp(h\;x)\), for any \(x : X\). Let us proceed by case distinction over \(f\;x\) and \(g (h\;x)\), note that by the requisite equation \((id + h) \circ f \doteq g \circ h\), we only need to consider two cases: % chktex 2
\item \ref{law:uniformity}: Let \(Y\) be a setoid and \(g : Y ⇝ \dbtilde{D}\;A + Y, h : X ⇝ Y\) be setoid morphisms, such that \((id + h) \circ f \doteq g \circ h\). We need to show that \(f^\sharp\;x \approx g^\sharp(h\;x)\), for any \(x : X\). Let us proceed by case distinction over \(f\;x\) and \(g (h\;x)\), note that by the requisite equation \((id + h) \circ f \doteq g \circ h\), we only need to consider two cases: % chktex 2
\begin{mycase}
\case{} \(f\;x = i_1\;a\) and \(g (h\;x) = i_1\;b\)\\
Consider that \((id + h) \circ f \doteq g \circ h\) on \(x\) yields \(i_1 \; a \overset{+}{=} i_1 \; b\) and thus \(a \approx b\). Then indeed,
@ -199,7 +199,7 @@ For the rest of this chapter we will abbreviate \(\tilde{D}\;A = (D_A , \sim)\)
We are done by coinduction, which yields
\[f^\sharp\;x \approx later(f^\sharp\;a) \approx later(g^\sharp(h\;a)) \approx later(g^\sharp\;b) \approx g^\sharp (h\;x).\]
\end{mycase}
\item \ref{law:folding}: Let \(Y\) be a setoid and \(h : Y ⇝ X + Y\) a setoid function, we need to show that \({(f^\sharp + h)}^\sharp\;z \approx {[ (id + i_1) \circ f , i_2 \circ h ]}^\sharp\;z\) for any \(z : X + Y\). % chktex 2
\item \ref{law:folding}: Let \(Y\) be a setoid and \(h : Y ⇝ X + Y\) a setoid morphism, we need to show that \({(f^\sharp + h)}^\sharp\;z \approx {[ (id + i_1) \circ f , i_2 \circ h ]}^\sharp\;z\) for any \(z : X + Y\). % chktex 2
Let us first establish the following fact
\[f^\sharp\;c \approx {[(id + i_1) \circ f , i_2 \circ h ]}^\sharp(i_1\;c) \qquad \text{for any } c : X, \tag{*}\label{folding-helper}\]
which follows by case distinction on \(f\;c\) and coinduction:
@ -243,16 +243,16 @@ For the rest of this chapter we will abbreviate \(\tilde{D}\;A = (D_A , \sim)\)
\end{alignat*}
\end{mycase}
\end{itemize}
This concludes the proof that every \(\dbtilde{D}\;A\) can be extended to an Elgot algebra.
This concludes the proof that every \(\dbtilde{D}\;A\) extends to an Elgot algebra.
\end{proof}
In the next proof a notion of \emph{discretized} setoid is needed, i.e.\ given a setoid \(Z\), we can discretize \(Z\) by replacing the equivalence relation with propositional equality, yielding \(\disc{Z} := (Z, \equiv)\). Now, the following corollary describes how to transform an iteration on \(\dbtilde{D}\;A\) into an iteration on \(\tilde{D}\;A\).
\begin{corollary}\label{cor:discretize}
Given a setoid function \(g : X ⇝ \dbtilde{D}\;A + X\). There exists a setoid function \(\bar{g} : \disc{X}\tilde{D}\;A + \disc{X}\) such that \(g^\sharp\;x \sim \bar{g}^{\tilde{\sharp}}\;x\) for any \(x : X\).
Given a setoid morphism \(g : X ⇝ \dbtilde{D}\;A + X\), there exists a setoid morphism \(\bar{g} : \disc{X}\tilde{D}\;A + \disc{X}\) such that \(g^\sharp\;x \sim \bar{g}^{\tilde{\sharp}}\;x\) for any \(x : X\).
\end{corollary}
\begin{proof}
It is clear that propositional equality implies strong bisimilarity and thus \(\bar{g}\) is a setoid function that behaves as \(g\) does but with a different type profile.
It is clear that propositional equality implies strong bisimilarity and thus \(\bar{g}\) is a setoid morphism that behaves as \(g\) does but with a different type profile.
The requisite property follows by case distinction on \(g\;x\).
\begin{mycase}
\case{} \(g\;x = i_1\;a\)\\
@ -267,8 +267,8 @@ In the next proof a notion of \emph{discretized} setoid is needed, i.e.\ given a
Every \(\dbtilde{D}\;A\) can be equipped with a free Elgot algebra structure.
\end{theorem}
\begin{proof}
We build on \autoref{lem:Delgot}, it thus suffices to show that for any setoid \(A\), the Elgot algebra \((\dbtilde{D}\;A, {(-)}^\sharp)\) together with the setoid function \(now : A ⇝ \dbtilde{D}\;A\) is a free such algebra.
Given an Elgot algebra \((B, {(-)}^{\sharp_b})\) and a setoid function \(f : A ⇝ B\). We need to define an Elgot algebra function \(\free{f} : \dbtilde{D}\;A ⇝ B\). Consider \(g : \tilde{D}\;A ⇝ B + \tilde{D}\;A\) defined by
We build on \autoref{lem:Delgot}, it thus suffices to show that for any setoid \(A\), the Elgot algebra \((\dbtilde{D}\;A, {(-)}^\sharp)\) together with the setoid morphism \(now : A ⇝ \dbtilde{D}\;A\) is a free such algebra.
Given an Elgot algebra \((B, {(-)}^{\sharp_b})\) and a setoid morphism \(f : A ⇝ B\). We need to define an Elgot algebra function \(\free{f} : \dbtilde{D}\;A ⇝ B\). Consider \(g : \tilde{D}\;A ⇝ B + \tilde{D}\;A\) defined by
\[g\;x =
\begin{cases}
i_1(f\;a) & \text{if } x = now\;a \\
@ -277,10 +277,10 @@ In the next proof a notion of \emph{discretized} setoid is needed, i.e.\ given a
\(g\) trivially respects strong bisimilarity, thus consider \(g^{\sharp_b} : \tilde{D}\;A ⇝ B\). We need to show that \(g^{\sharp_b}\) also respects weak bisimilarity, thus yielding the requisite function \(\free{f} = g^{\sharp_b} : \dbtilde{D}\;A ⇝ B\). However, the proof turns out to be rather complex, let us postpone it to~\autoref{cor:respects}.
Instead, we will continue with the proof. Let us now show that \(g^{\sharp_b}\) is iteration preserving. Given a setoid function \(h : X ⇝ \dbtilde{D}\;A + X\), we need to show that \(g^{\sharp_b} (h^\sharp\;x) \overset{B}{=} {((g^{\sharp_b} + id) \circ h)}^{\sharp_b}\;x\) for any \(x : X\). Using \autoref{cor:discretize} we will proceed to show
Instead, we will continue with the proof. Let us now show that \(g^{\sharp_b}\) is iteration preserving. Given a setoid morphism \(h : X ⇝ \dbtilde{D}\;A + X\), we need to show that \(g^{\sharp_b} (h^\sharp\;x) \overset{B}{=} {((g^{\sharp_b} + id) \circ h)}^{\sharp_b}\;x\) for any \(x : X\). Using \autoref{cor:discretize} we will proceed to show
\[g^{\sharp_b} (h^\sharp\;x) \overset{B}{=} {((g^{\sharp_b} + id) \circ \bar{h})}^{\sharp_b}\;x \overset{B}{=} {((g^{\sharp_b} + id) \circ h)}^{\sharp_b}\;x.\]
The second step instantly follows by \ref{law:uniformity}, considering that the identity function easily extends to a setoid function \(id : \disc{X} ⇝ X\), and thus the second step can be reduced to \({((g^{\sharp_b} + id) \circ \bar{h})}^{\sharp_b}\;x \overset{B}{=} {((g^{\sharp_b} + id) \circ h)}^{\sharp_b}(id\;x)\). % chktex 2
The second step instantly follows by \ref{law:uniformity}, considering that the identity function easily extends to a setoid morphism \(id : \disc{X} ⇝ X\), and thus the second step can be reduced to \({((g^{\sharp_b} + id) \circ \bar{h})}^{\sharp_b}\;x \overset{B}{=} {((g^{\sharp_b} + id) \circ h)}^{\sharp_b}(id\;x)\). % chktex 2
For the first step consider
\begin{alignat*}{1}
& g^{\sharp_b} (h^\sharp\;x)
@ -293,7 +293,7 @@ In the next proof a notion of \emph{discretized} setoid is needed, i.e.\ given a
Thus, \(g^{\sharp_b}\) is an Elgot algebra function. We are left to check that \(g^{\sharp_b}\) satisfies the requisite properties of free objects. First, note that \(g^{\sharp_b} \circ now \doteq [ id , g^\sharp_b ] \circ g \circ now \doteq f\) by \ref{law:fixpoint} and the definition of \(g\). % chktex 2
Next, we need to check uniqueness of \(g^{\sharp_b}\). It suffices to show that any two Elgot algebra functions \(e, h : \dbtilde{D}\;A ⇝ B\) satisfying \(e \circ now \doteq f\) and \(h \circ now \doteq f\) are equal.
First, note that the identity function can be extended to the following conversion setoid function \(conv : \tilde{D}\;A ⇝ \dbtilde{D}\;A\), since strong bisimilarity implies weak bisimilarity. Furthermore, consider the setoid function \(o : \tilde{D}\;A ⇝ \tilde{D}\;A + \tilde{D}\;A\) defined by
First, note that the identity function extends to the following conversion setoid morphism \(conv : \tilde{D}\;A ⇝ \dbtilde{D}\;A\), since strong bisimilarity implies weak bisimilarity. Furthermore, consider the setoid morphism \(o : \tilde{D}\;A ⇝ \tilde{D}\;A + \tilde{D}\;A\) defined by
\[o\;x := \begin{cases}
i_1(now\;z) & \text{if } x = now\;z \\
i_2\;z & \text{if } x = later\;z
@ -380,7 +380,7 @@ Lastly, consider the function \(\iota : A \times \mathbb{N} \rightarrow D\;A\),
later(\iota\;(a, m)) & \text{if } n = m + 1
\end{cases}\]
Trivially, \(\iota\) can be extended to a setoid function \(\iota : A \times \mathbb{N}\tilde{D}\;A\), where the equivalence on \(\mathbb{N}\) is propositional equality.
Trivially, \(\iota\) extends to a setoid morphism \(\iota : A \times \mathbb{N}\tilde{D}\;A\), where the equivalence on \(\mathbb{N}\) is propositional equality.
Let us state two facts about \(\Delta\), the proofs can again be found in the formalization.
\begin{corollary}\label{cor:delta}
\(\Delta\) satisfies the following properties:
@ -393,7 +393,7 @@ Let us state two facts about \(\Delta\), the proofs can again be found in the fo
Let us now return to the missing Corollary of \autoref{thm:Dfreeelgot}.
\begin{corollary}\label{cor:respects}
The setoid function \(g^{\sharp_b} : \tilde{D}\;A ⇝ B\) defined in \autoref{thm:Dfreeelgot} respects weak bisimilarity, thus yielding \(\free{f} = g^{\sharp_b} : \dbtilde{D}\;A ⇝ B\).
The setoid morphism \(g^{\sharp_b} : \tilde{D}\;A ⇝ B\) defined in \autoref{thm:Dfreeelgot} respects weak bisimilarity, thus yielding \(\free{f} = g^{\sharp_b} : \dbtilde{D}\;A ⇝ B\).
\end{corollary}
\begin{proof}
Let \(x, y : D\;A\) such that \(x \approx y\). Recall that by \autoref{cor:race} \(x \approx y\) implies \(p: race\;x\;y \lesssim y\) and symmetrically \(q: race\;y\;x \lesssim x\), now, using Corollaries~\ref{cor:race} and~\ref{cor:delta}:
@ -430,10 +430,10 @@ Let us now return to the missing Corollary of \autoref{thm:Dfreeelgot}.
i_1(f\;x) & \text{if } p = now\;(x , n) \\
i_2\;q & \text{if } p = later\;q
\end{cases}\]
where \(o : A ⇝ A \times \mathbb{N}\) is a setoid function that maps every \(z : A\) to \((z , 0) : A \times \mathbb{N}\). The applications of \ref{law:uniformity} are then justified by the definitions of \(g_1\) and \(g_2\) as well as the fact that \(\iota \circ o \doteq now\). % chktex 2
where \(o : A ⇝ A \times \mathbb{N}\) is a setoid morphism that maps every \(z : A\) to \((z , 0) : A \times \mathbb{N}\). The applications of \ref{law:uniformity} are then justified by the definitions of \(g_1\) and \(g_2\) as well as the fact that \(\iota \circ o \doteq now\). % chktex 2
We are thus done after showing that \(g_1^{\sharp_b}\;z \overset{B}{=} g_2^{\sharp_b}\;z\).
Consider another setoid function
Consider another setoid morphism
\[g_3 : \tilde{D}(A \times \mathbb{N}) ⇝ B + \tilde{D}(A \times \mathbb{N}) + \tilde{D}(A \times \mathbb{N}),\]
defined by
\[g_3\;p := \begin{cases}

View file

@ -1 +1,9 @@
\chapter{Conclusion}
\chapter{Conclusion}
We have considered a novel approach to defining a monad suitable for modelling partiality from first principles, which has first been introduced in~\cite{uniformelgot}.
Using the dependently typed programming language Agda, we were able to formally verify important properties of this monad:
it is an equational lifting monad, i.e.\ a monad that offers no other side effect besides some form of non-termination and furthermore it turns out to be the initial pre-Elgot monad.
Moreover, we have considered a concrete description of this monad in the category of setoids, where it turns out to be a quotient of the delay monad.
With this thesis we have thus created a small Agda library that contains categorical concepts concerning partiality and iteration theories.
Future work might improve on this library by formalizing important results concerning partiality monads, such as the fact that every equational lifting monad has a restriction category as its Kleisli category.
Furthermore, one can continue studying the delay monad in a categorical setting, by modeling the quotient by weak bisimilarity of the delay monad through a certain coequalizer, as has been done in~\cite{uniformelgot}, and then identifying assumptions under which this constitutes a suitable monad for modeling partiality.