### Sync with unshared/manuscripts/2020.exteqaxiom before submission.

parent 797174ed
 ... @@ -106,7 +106,7 @@ The proof uses pattern matching, which is straightforward here because ... @@ -106,7 +106,7 @@ The proof uses pattern matching, which is straightforward here because %endif %endif % % In a similar way, one can prove that |(=)| is an equivalence relation: In a similar way, one can prove that |(=)| is an equivalence relation: Reflexivity is directly implemented by |Refl|, while symmetry and reflexivity is directly implemented by |Refl|, while symmetry and transitivity can be proven by pattern matching. transitivity can be proven by pattern matching. ... @@ -160,9 +160,10 @@ but not the converse, normally referred to as \emph{function extensionality}: ... @@ -160,9 +160,10 @@ but not the converse, normally referred to as \emph{function extensionality}: When working with functions, extensional equality is often the notion of When working with functions, extensional equality is often the notion of interest and libraries of formalized mathematics typically provide interest and libraries of formalized mathematics typically provide definitions like |<=>| and basic results like |IEqImplEE|, see for definitions like |<=>| and basic results like |IEqImplEE|. example |homot| and |eqtohomot| in Part A of the UniMath library \citep{UniMath} % or |eqfun| in Coq \citep{CoqProofAssistant}. See for example |homot| and |eqtohomot| in Part A of the UniMath library \citep{UniMath} or |eqfun| in Coq \citep{CoqProofAssistant}. In reasoning about generic programs in the style of the Algebra of In reasoning about generic programs in the style of the Algebra of Programming \citep{DBLP:books/daglib/0096998,mu2009algebra} and, more Programming \citep{DBLP:books/daglib/0096998,mu2009algebra} and, more ... @@ -200,7 +201,7 @@ two-argument version of extensional equality preservation: ... @@ -200,7 +201,7 @@ two-argument version of extensional equality preservation: > compPresEE : {A, B, C : Type} -> {g, g' : B -> C} -> {f, f' : A -> B} -> > compPresEE : {A, B, C : Type} -> {g, g' : B -> C} -> {f, f' : A -> B} -> > g <=> g' -> f <=> f' -> g . f <=> g' . f' > g <=> g' -> f <=> f' -> g . f <=> g' . f' > compPresEE {g} {g'} {f} {f'} gExtEq fExtEq x = > compPresEE {g} {g'} {f} {f'} gExtEq {-"\ "-} fExtEq {-"\ "-} x = > ( (g . f) x ) ={ Refl }= > ( (g . f) x ) ={ Refl }= > ( g (f x) ) ={ cong (fExtEq x) }= > ( g (f x) ) ={ cong (fExtEq x) }= > ( g (f' x) ) ={ gExtEq (f' x) }= > ( g (f' x) ) ={ gExtEq (f' x) }= ... @@ -209,8 +210,8 @@ two-argument version of extensional equality preservation: ... @@ -209,8 +210,8 @@ two-argument version of extensional equality preservation: The right hand side is a chain of equal expressions connected by the The right hand side is a chain of equal expressions connected by the |={| proofs |}=| of the individual steps within special braces and |={| proofs |}=| of the individual steps within special braces and ending in |QED|, see Preorder reasoning'' in ending in |QED|, see Preorder reasoning'' in the documentation by \citep{idrisdocs}. \citet{idrisdocs}. % % The steps with |Refl| are just for human readability, they could be The steps with |Refl| are just for human readability, they could be omitted as far as Idris is concerned. omitted as far as Idris is concerned. ... @@ -243,10 +244,10 @@ This paper is also about ADTs and generic programming. ... @@ -243,10 +244,10 @@ This paper is also about ADTs and generic programming. % % More specifically, we show how to exploit the notion of extensional More specifically, we show how to exploit the notion of extensional equality preservation to inform the design of ADTs for generic equality preservation to inform the design of ADTs for generic programming and embedded domain-specific languages (DSL). programming and embedded domain-specific languages (DSLs). % % This is exemplified in sections \ref{section:functors} and This is exemplified in sections \ref{section:functors} and \ref{section:monads} for ADTs for functors and monads but we conjecture \ref{section:monads} with ADTs for functors and monads but we conjecture that other abstract data types, e.g. for applicatives and arrows, could that other abstract data types, e.g. for applicatives and arrows, could also profit from a design informed by the notion of preservation of also profit from a design informed by the notion of preservation of extensional equality. extensional equality. ... @@ -285,8 +286,8 @@ of important research for the last thirty years. ... @@ -285,8 +286,8 @@ of important research for the last thirty years. Since Hofmann's seminal work \citep{hofmann1995extensional}, setoids Since Hofmann's seminal work \citep{hofmann1995extensional}, setoids have been the established, but also often dreaded (who coined the have been the established, but also often dreaded (who coined the expression \emph{setoid hell''}?) means to deal with extensional expression \emph{setoid hell''}?) means to deal with extensional concepts in intensional type theory, see also section concepts in intensional type theory (see also section \ref{section:relatedwork}. \ref{section:relatedwork}). % % Eventually, the study of Martin-Löf's equality type has lead to the Eventually, the study of Martin-Löf's equality type has lead to the development of Homotopy Type Theory and Voevodsky's Univalent development of Homotopy Type Theory and Voevodsky's Univalent ... @@ -326,11 +327,11 @@ These can be type-checked with Idris 1.3.2 and are available at ... @@ -326,11 +327,11 @@ These can be type-checked with Idris 1.3.2 and are available at %, see \texttt{README.md} in the paper's folder. %, see \texttt{README.md} in the paper's folder. % % In the next section we present a motivating example from monadic % In the next section we present a motivating example from monadic dynamical systems, in section~\ref{section:functors} we explore % dynamical systems, in section~\ref{section:functors} we explore extensional equality preservation for functors and in section % extensional equality preservation for functors and in section \ref{section:monads} for monads. % \ref{section:monads} for monads. % % % We continue with dynamical systems applications in section~\ref{section:applications} % We continue with dynamical systems applications in section~\ref{section:applications} and finish with related work (section~\ref{section:relatedwork}) and % and finish with related work (section~\ref{section:relatedwork}) and conclusions (section~\ref{section:conclusions}). % conclusions (section~\ref{section:conclusions}).
 ... @@ -141,6 +141,7 @@ As for |flowLemma2|, proving the representation lemma is straightforward ... @@ -141,6 +141,7 @@ As for |flowLemma2|, proving the representation lemma is straightforward but crucially relies on associativity of Kleisli composition and thus, as but crucially relies on associativity of Kleisli composition and thus, as seen in section \ref{section:monads}, on preservation of extensional seen in section \ref{section:monads}, on preservation of extensional equality: equality: \pagebreak % > reprLemma f Z mx = % > reprLemma f Z mx = % > ( (repr (flow f Z)) mx ) ={ Refl }= % > ( (repr (flow f Z)) mx ) ={ Refl }= ... @@ -150,7 +151,7 @@ equality: ... @@ -150,7 +151,7 @@ equality: % > ( flowDet (repr f) Z mx ) QED % > ( flowDet (repr f) Z mx ) QED > reprLemma f Z mx = Fat.pureRightIdKleisli id mx > reprLemma f Z mx = Fat.pureRightIdKleisli id mx > > reprLemma f (S m) mx = > reprLemma f (S m) mx = > ( repr (flow f (S m)) mx ) ={ Refl }= > ( repr (flow f (S m)) mx ) ={ Refl }= > ( (id >=> flow f (S m)) mx ) ={ Refl }= > ( (id >=> flow f (S m)) mx ) ={ Refl }= ... @@ -166,11 +167,11 @@ Notice also the application of |kleisliLeapfrog| to deduce |(id >=> ... @@ -166,11 +167,11 @@ Notice also the application of |kleisliLeapfrog| to deduce |(id >=> flow f m) ((id >=> f) mx)| from |((id >=> f) >=> flow f m) mx|. flow f m) ((id >=> f) mx)| from |((id >=> f) >=> flow f m) mx|. % % If we had formulated the theory in terms of bind instead of Kleisli If we had formulated the theory in terms of bind instead of Kleisli composition, the two expressions would be intensionally equal. composition, the two expressions would have been intensionally equal. \paragraph*{Flows and trajectories.} \paragraph*{Flows and trajectories.} % % The last application of preservation of extensional Our last application of preservation of extensional equality in the context of dynamical systems theory is a result about equality in the context of dynamical systems theory is a result about flows and trajectories. flows and trajectories. % % ... @@ -188,7 +189,7 @@ is an |M|-structure containing just |[x]|. ... @@ -188,7 +189,7 @@ is an |M|-structure containing just |[x]|. To compute the trajectories for |S n| steps, we first bind the outcome To compute the trajectories for |S n| steps, we first bind the outcome of a single step |f x : M X| into |trj f n|. of a single step |f x : M X| into |trj f n|. % % This results in an |M|-structure of vectors of length |S n|. This results in an |M|-structure of vectors of length |n|. % % Finally, we prepend these possible trajectories with the initial state Finally, we prepend these possible trajectories with the initial state |x|. |x|. ... @@ -284,4 +285,4 @@ induction. ... @@ -284,4 +285,4 @@ induction. % % As in the |flowTrjLemma| discussed above, |map| preserving extensional As in the |flowTrjLemma| discussed above, |map| preserving extensional equality turns out to be pivotal in applying the induction hypothesis, equality turns out to be pivotal in applying the induction hypothesis, see \citep{brede2020} for details. see \citet{brede2020} for details.
 ... @@ -12,7 +12,7 @@ ... @@ -12,7 +12,7 @@ \label{section:conclusions} \label{section:conclusions} In dependently typed programming in the context of Martin-Löf type In dependently typed programming in the context of Martin-Löf type theories \citep{nordstrom1990programming, martinlof1984}, the problem of theories \citep{martinlof1984, nordstrom1990programming}, the problem of how to specify abstract data types for verified generic programming is how to specify abstract data types for verified generic programming is still not well understood. still not well understood. % % ... ...
 ... @@ -32,7 +32,7 @@ $\mathcal{D}$ (often both denoted by |F|) such that for each arrow |f ... @@ -32,7 +32,7 @@ $\mathcal{D}$ (often both denoted by |F|) such that for each arrow |f : A -> B| in $\mathcal{C}$ there is an arrow |F f : F A -> F B| in : A -> B| in $\mathcal{C}$ there is an arrow |F f : F A -> F B| in $\mathcal{D}$. $\mathcal{D}$. % % For an introduction to category theory, see \citep{pierce_basic_1991}. For an introduction to category theory, see \citet{pierce_basic_1991}. % % The arrow map preserves identity arrows and arrow composition. The arrow map preserves identity arrows and arrow composition. % % ... @@ -172,26 +172,24 @@ proof looks as follows: ... @@ -172,26 +172,24 @@ proof looks as follows: % {-" below=\the\belowdisplayskip"-} % {-" below=\the\belowdisplayskip"-} > mapListPresEE : {A, B : Type} -> (f, g : A -> B) -> f <=> g -> mapList f <=> mapList g > mapListPresEE : {A, B : Type} -> (f, g : A -> B) -> f <=> g -> mapList f <=> mapList g > mapListPresEE f g fEEg [] = Refl > mapListPresEE f g fEEg [] = Refl > mapListPresEE f g fEEg (a :: as) = > mapListPresEE f g fEEg (a :: as) = {-"\,"-} > ( mapList f (a :: as) ) ={ Refl }= > ( mapList f (a :: as) ) ={ Refl }= > ( f a :: mapList f as ) ={ cong {f = (::{-"~"-} mapList f as)} (fEEg a) }= > ( f a :: mapList f as ) ={ cong {f = (::{-"~"-} mapList f as)} (fEEg a) }= > ( g a :: mapList f as ) ={ cong (mapListPresEE f g fEEg as) }= > ( g a :: mapList f as ) ={ cong (mapListPresEE f g fEEg as) }= > ( g a :: mapList g as ) ={ Refl }= > ( g a :: mapList g as ) ={ Refl }= > ( mapList g (a :: as) ) QED > ( mapList g (a :: as) ) QED In general the proofs have a very simple structure: they use the |f In general the proofs have a very simple structure: they use the |f <=> g| arguments to transform the arguments of type |A| expected by <=> g| arguments at the leaves'', and otherwise only use the the constructors into arguments of type |B|, and otherwise only use induction hypotheses. the induction hypotheses. % % They can also be written as dependent folds, but this results in less %They can also be written as dependent folds, but this results in less readable proofs. %readable proofs. % % (With a suitable universe of codes for types, or a library for With a suitable universe of codes for types, or a library for parametricity proofs, these proofs can be automated using parametricity proofs, these proofs can be automated using datatype-generic programming.) datatype-generic programming. % %if False %if False We can write |mapListPresEE| in a more condensed form using Idris' We can write |mapListPresEE| in a more condensed form using Idris' ... @@ -240,13 +238,13 @@ This is a common pattern for proofs of |mapPresEE|. ... @@ -240,13 +238,13 @@ This is a common pattern for proofs of |mapPresEE|. %endif %endif Let's now turn to a type constructor that is not an instance of Let's now turn to a type constructor that is not an instance of |VeriFunctor|, namely |Reader E| for some environment |E : Type|. our |VeriFunctor|, namely |Reader E| for some environment |E : Type|. > Reader : Type -> Type -> Type > Reader : Type -> Type -> Type > Reader E A = E -> A > Reader E A = E -> A > > > mapReader : {A, B, E : Type} -> (A -> B) -> Reader E A -> Reader E B > mapR : {A, B, E : Type} -> (A -> B) -> (Reader E A -> Reader E B) > mapReader f r = f . r > mapR f r = f . r If we try to implement preservation of extensional equality we end up with If we try to implement preservation of extensional equality we end up with ... @@ -258,18 +256,17 @@ If we try to implement preservation of extensional equality we end up with ... @@ -258,18 +256,17 @@ If we try to implement preservation of extensional equality we end up with %endif %endif > mapReaderPresEE : {A, B : Type} -> (f, g : A -> B) -> > mapRPresEE : {A, B : Type} -> (f, g : A -> B) -> f <=> g -> mapR f <=> mapR g > f <=> g -> mapReader f <=> mapReader g > mapRPresEE f g fEEg r = > mapReaderPresEE f g fEEg r = > ( mapR f r) ={ Refl }= > ( mapReader f r) ={ Refl }= > ( f . r ) ={ whatnow1 r }= -- here we need |f = g| to proceed > ( f . r ) ={ whatnow1 r }= -- here we need |f = g| to proceed > ( g . r ) ={ Refl }= > ( g . r ) ={ Refl }= > ( mapReader g r) QED > ( mapR g r) QED Notice the question mark in front of |whatnow1r|. This introduces an Notice the question mark in front of |whatnow1r|. This introduces an unresolved proof step and allows us to ask Idris to help us implementing unresolved proof step and allows us to ask Idris to help us implementing this step, see Elaborator Reflection -- Holes'' in \citep{idrisdocs}. this step, see Elaborator Reflection -- Holes'' in \citep{idrisdocs}. Among others, we can ask about the Among other things, we can ask about the type of |whatnow1r|. Perhaps not surprisingly, this turns out to be |f type of |whatnow1r|. Perhaps not surprisingly, this turns out to be |f . r = g . r|. . r = g . r|. ... @@ -278,9 +275,6 @@ all |e : E|, we cannot deduce |f . r = g . r| without extensionality. ... @@ -278,9 +275,6 @@ all |e : E|, we cannot deduce |f . r = g . r| without extensionality. % % Thus |Reader E| does not implement the |VeriFunctor| interface, but it Thus |Reader E| does not implement the |VeriFunctor| interface, but it is very close''. is very close''. % \footnote{By a similar argument, |mapPresEE| does not hold for the continuation monad.} %if False %if False > (<==>) : {A, B, C : Type} -> (f, g : A -> B -> C) -> Type > (<==>) : {A, B, C : Type} -> (f, g : A -> B -> C) -> Type ... @@ -290,13 +284,16 @@ is very close''. ... @@ -290,13 +284,16 @@ is very close''.