Skip to content

Commit

Permalink
fix the open problem solved by Hew Wolff (#108)
Browse files Browse the repository at this point in the history
* fix the open problem solved by Hew Wolff

* wip

* clean everything with clean.sh

* add files with embedded fonts

* fix font size for back cover

* fix back cover size

* fix barcode position
  • Loading branch information
winitzki authored Sep 4, 2024
1 parent 07efb66 commit b120b8a
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 124 deletions.
5 changes: 3 additions & 2 deletions sofp-src/cover/sofp-back-cover-no-bg.tex.src
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
\onecolumn
\thispagestyle{empty}
\newgeometry{top=2cm, left=2.5cm, right=3.9cm,bottom=1cm}
\newgeometry{top=2.5cm, left=2.5cm, right=3.9cm, bottom=1cm}

\begin{wrapfigure}{l}{0.4\columnwidth}
\includegraphics[width=0.4\columnwidth]{monads_evil_face}
Expand Down Expand Up @@ -53,4 +53,5 @@ matrices or simplifying the expressions:

The author received a Ph.D. in theoretical physics. After a career in academic research, he works as a software engineer.

%\vspace{0.2cm}\hspace*{\fill}\includegraphics[scale=1.0]{barcode}

%\vspace{3.0cm}\hspace*{\fill}\colorbox{white}{\includegraphics[scale=1.0,width=50.8mm,height=30.5mm]{barcode}}
1 change: 1 addition & 0 deletions sofp-src/cover/sofp-back-cover.tex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
\usepackage{graphicx}
\usepackage{pagecolor}
\usepackage{changepage}
\usepackage{relsize}

\geometry{
paperwidth=\CoverWidth in,%
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
12 changes: 1 addition & 11 deletions sofp-src/lyx/sofp-applicative.lyx
Original file line number Diff line number Diff line change
Expand Up @@ -28713,21 +28713,11 @@ status open

\begin_layout Plain Layout
It is unknown how to characterize or enumerate all polynomial functors that
are monads (see Problems
are monads (see Problem
\begin_inset space ~
\end_inset


\begin_inset CommandInset ref
LatexCommand ref
reference "par:Problem-monads-1"
plural "false"
caps "false"
noprefix "false"

\end_inset

\begin_inset CommandInset ref
LatexCommand ref
reference "par:Problem-monads"
Expand Down
157 changes: 73 additions & 84 deletions sofp-src/lyx/sofp-summary.lyx
Original file line number Diff line number Diff line change
Expand Up @@ -3045,7 +3045,7 @@ do not store

.
\begin_inset Note Note
status open
status collapsed

\begin_layout Plain Layout
By Yoneda we have
Expand Down Expand Up @@ -3181,14 +3181,56 @@ If
Exercise
\begin_inset CommandInset label
LatexCommand label
name "par:Exercise-additional-13"
name "par:Problem-monads-1"

\end_inset


\begin_inset CommandInset ref
LatexCommand ref
reference "par:Exercise-additional-13"
reference "par:Problem-monads-1"
plural "false"
caps "false"
noprefix "false"

\end_inset


\end_layout

\begin_layout Standard
\begin_inset Foot
status open

\begin_layout Plain Layout
This was an open problem but it was solved by Hew Wolff.
\end_layout

\end_inset

Prove that
\begin_inset Formula $L^{A}\triangleq\bbnum 1+\underbrace{A\times A\times...\times A}_{n\text{ times}}$
\end_inset

cannot be made into a monad if
\begin_inset Formula $n\ge2$
\end_inset

.
\end_layout

\begin_layout Subsubsection
Exercise
\begin_inset CommandInset label
LatexCommand label
name "par:Exercise-additional-13-1"

\end_inset


\begin_inset CommandInset ref
LatexCommand ref
reference "par:Exercise-additional-13-1"
plural "false"
caps "false"
noprefix "false"
Expand Down Expand Up @@ -4541,87 +4583,7 @@ open problems
\begin_layout Standard
The author of this book does not know how to answer the following questions
and also could not find any answers in existing books or papers.
\end_layout

\begin_layout Subsubsection
Problem
\begin_inset CommandInset label
LatexCommand label
name "par:Problem-monads-1"

\end_inset


\begin_inset CommandInset ref
LatexCommand ref
reference "par:Problem-monads-1"
plural "false"
caps "false"
noprefix "false"

\end_inset


\end_layout

\begin_layout Standard
Do all polynomial functors of the form
\begin_inset Formula $P_{n}^{A}\triangleq\bbnum 1+\overbrace{A\times A\times...\times A}^{n\text{ times, }n\ge2}$
\end_inset

fail to be monads? An example is the functor
\begin_inset Formula $P_{2}^{A}\triangleq\bbnum 1+A\times A$
\end_inset

, which is not a monad because all possible implementations of
\begin_inset listings
inline true
status open

\begin_layout Plain Layout

pure
\end_layout

\end_inset

and
\begin_inset listings
inline true
status open

\begin_layout Plain Layout

flatMap
\end_layout

\end_inset

methods for
\begin_inset Formula $P_{2}$
\end_inset

fail the monad laws.
\begin_inset Foot
status open

\begin_layout Plain Layout
See discussion here:
\family typewriter

\begin_inset CommandInset href
LatexCommand href
target "https://stackoverflow.com/questions/49742377"
literal "false"

\end_inset


\end_layout

\end_inset



\end_layout

\begin_layout Subsubsection
Expand Down Expand Up @@ -4737,6 +4699,33 @@ not
obtained by a chain of these constructions?
\end_layout

\begin_layout Standard
For example, functors of the form
\begin_inset Formula $L^{A}\triangleq\bbnum 1+A\times A$
\end_inset

,
\begin_inset Formula $L^{A}\triangleq\bbnum 1+A\times A\times A$
\end_inset

, etc., cannot be obtained via these constructions.
All those functors are not monads (see Exercise
\begin_inset space ~
\end_inset


\begin_inset CommandInset ref
LatexCommand ref
reference "par:Problem-monads-1"
plural "false"
caps "false"
noprefix "false"

\end_inset

).
\end_layout

\begin_layout Subsubsection
Problem
\begin_inset CommandInset label
Expand Down
2 changes: 1 addition & 1 deletion sofp-src/scripts/clean.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rm -rf build vol1 vol2 vol3 pdf* mdoc sofp-*.pdf
rm -rf build tex vol1 vol2 vol3 pdf* mdoc sofp-*.pdf sofp.pdf
8 changes: 4 additions & 4 deletions sofp-src/scripts/prepare_volume.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ function pdfPages {
}

vol1_ISBN="ISBN (vol.~1): 978-1-4710-4004-7"
vol1_ISBN_barcode="vol1_isbn_barcode.pdf"
vol1_ISBN_barcode="vol1_isbn_barcode_embedded_fonts.pdf"
vol1_url="https://www.lulu.com/shop/sergei-winitzki/the-science-of-functional-programming-part-i/paperback/product-dyyq2zm.html"

vol2_ISBN="ISBN (vol.~2): 978-1-4461-9146-0"
vol2_ISBN_barcode="vol2_isbn_barcode.pdf"
vol2_ISBN_barcode="vol2_isbn_barcode_embedded_fonts.pdf"
vol2_url="https://www.lulu.com/shop/sergei-winitzki/the-science-of-functional-programming-part-ii/paperback/product-655e7wm.html"

vol3_ISBN="ISBN (vol.~3): 978-1-4461-9136-1"
vol3_ISBN_barcode="vol3_isbn_barcode.pdf"
vol3_ISBN_barcode="vol3_isbn_barcode_embedded_fonts.pdf"
vol3_url="https://www.lulu.com/shop/sergei-winitzki/the-science-of-functional-programming-part-ii/paperback/product-p668z4q.html"

v=$1
Expand Down Expand Up @@ -124,7 +124,7 @@ esac
echo "Using volume $v ISBN '$isbn'"
sed -i.bak -e 's|\({\\footnotesize{}\)ISBN: [^}]*\(}\\\\\)|\1'"$isbn"'\2|;' $dir/$name.tex
# Add barcode to back cover.
sed -i.bak -e 's|%\(.*\){barcode}.*|\1{'"$barcode"'}|' $dir/sofp-back-cover-no-bg.tex
sed -i.bak -e 's|%\(.*\){barcode}\(.*\)$|\1{'"$barcode"'}\2|' $dir/sofp-back-cover-no-bg.tex

mv $dir/$name.tex $dir/sofp.tex

Expand Down
Binary file modified sofp-src/tex/chapter3-picture.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion sofp-src/tex/sofp-applicative.tex
Original file line number Diff line number Diff line change
Expand Up @@ -4711,7 +4711,7 @@ \subsection{Relationship between monads and applicative functors}
functors with monoidal fixed types. (All our examples of non-applicative
functors involve non-polynomial functors.) But we have seen that not
all polynomial functors are monads.\footnote{It is unknown how to characterize or enumerate all polynomial functors
that are monads (see Problems~\ref{par:Problem-monads-1}\textendash \ref{par:Problem-monads}).} Example~\ref{subsec:Example-applicative-not-monad} shows a simple
that are monads (see Problem~\ref{par:Problem-monads}).} Example~\ref{subsec:Example-applicative-not-monad} shows a simple
applicative functor\index{applicative functor!not a monad} ($L^{A}\triangleq\bbnum 1+A\times A$)
that does \emph{not} have a lawful monad implementation (Exercise~\ref{subsec:Exercise-1-monads-7-not-a-monad}).

Expand Down
7 changes: 4 additions & 3 deletions sofp-src/tex/sofp-back-cover-no-bg.tex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
\onecolumn
\thispagestyle{empty}
\newgeometry{top=2cm, left=2.5cm, right=3.9cm,bottom=1cm}
\newgeometry{top=2.5cm, left=2.5cm, right=3.9cm, bottom=1cm}

\begin{wrapfigure}{l}{0.4\columnwidth}
\includegraphics[width=0.4\columnwidth]{monads_evil_face}
Expand Down Expand Up @@ -28,7 +28,7 @@
developed in excruciating detail through 1906
Scala code snippets, 192 statements with step-by-step
derivations, 104 diagrams, 223 examples
with tested Scala code, and 309 exercises. Discussions
with tested Scala code, and 310 exercises. Discussions
build upon each chapter\textsf{'}s material further.

Beginners in FP will find tutorials about the \texttt{map}/\texttt{reduce}
Expand All @@ -53,4 +53,5 @@

The author received a Ph.D. in theoretical physics. After a career in academic research, he works as a software engineer.

%\vspace{0.2cm}\hspace*{\fill}\includegraphics[scale=1.0]{barcode}

%\vspace{3.0cm}\hspace*{\fill}\colorbox{white}{\includegraphics[scale=1.0,width=50.8mm,height=30.5mm]{barcode}}
6 changes: 3 additions & 3 deletions sofp-src/tex/sofp-filterable.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3628,7 +3628,7 @@ \subsubsection{Statement \label{subsec:Statement-recursive-filterable-contrafunc
}
\end{lstlisting}
\[
\xymatrix{S^{B,F^{B}}\ar[r]\sp(0.525){\text{liftOpt}_{S}(f^{:A\rightarrow\bbnum 1+B})}\ar[rd]\sb(0.45){\text{liftOpt}_{F}(f)\triangleq~~~} & S^{A,F^{B}}\ar[d]\sp(0.45){\big(\overline{\text{liftOpt}_{F}}(f)\big)^{\uparrow S^{A,\bullet}}}\\
\xymatrix{S^{B,F^{B}}\ar[r]\sp(0.525){\text{liftOpt}_{S}(f^{:A\rightarrow\bbnum 1+B})}\ar[rd]\sb(0.45){\text{liftOpt}_{F}(f)\triangleq~~~} & S^{A,F^{B}}\ar[d]\sp(0.4){\big(\overline{\text{liftOpt}_{F}}(f)\big)^{\uparrow S^{A,\bullet}}}\\
\xyScaleY{1.8pc}\xyScaleX{6pc} & S^{A,F^{A}}
}
\]
Expand Down Expand Up @@ -3674,7 +3674,7 @@ \subsubsection{Statement \label{subsec:Statement-recursive-filterable-contrafunc
with respect to lifting in the type parameter $A$ of $S^{A,R}$.
That law is:
\[
\xymatrix{S^{B,R}\ar[r]\sp(0.5){\text{liftOpt}_{S}(f^{:A\rightarrow\bbnum 1+B})}\ar[d]\sb(0.55){(h^{:R\rightarrow R^{\prime}})^{\uparrow S^{B,\bullet}}} & S^{A,R}\ar[d]\sp(0.55){h^{\uparrow S^{A,\bullet}}}\\
\xymatrix{S^{B,R}\ar[r]\sp(0.5){\text{liftOpt}_{S}(f^{:A\rightarrow\bbnum 1+B})}\ar[d]\sb(0.5){(h^{:R\rightarrow R^{\prime}})^{\uparrow S^{B,\bullet}}} & S^{A,R}\ar[d]\sp(0.4){h^{\uparrow S^{A,\bullet}}}\\
\xyScaleY{1.8pc}\xyScaleX{6.0pc}S^{B,R^{\prime}}\ar[r]\sp(0.45){\text{liftOpt}_{S}(f)} & S^{A,R^{\prime}}
}
\]
Expand Down Expand Up @@ -4332,7 +4332,7 @@ \subsection{Naturality laws and natural transformations\label{subsec:Naturality-
that requirement as an equation called the \textbf{naturality law}\index{naturality law!of headOption@of \texttt{headOption}}
of \lstinline!headOption!:
\[
\xymatrix{\text{List}^{A}\ar[r]\sp(0.55){\text{headOpt}^{A}}\ar[d]\sb(0.5){(f^{:A\rightarrow B})^{\uparrow\text{List}}} & \text{Opt}^{A}\ar[d]\sb(0.4){f^{\uparrow\text{Opt}}}\\
\xymatrix{\text{List}^{A}\ar[r]\sp(0.55){\text{headOpt}^{A}}\ar[d]\sb(0.5){(f^{:A\rightarrow B})^{\uparrow\text{List}}} & \text{Opt}^{A}\ar[d]\sp(0.45){f^{\uparrow\text{Opt}}}\\
\xyScaleY{1.6pc}\xyScaleX{4.5pc}\text{List}^{B}\ar[r]\sp(0.55){\text{headOpt}^{B}} & \text{Opt}^{B}
}
\]
Expand Down
21 changes: 12 additions & 9 deletions sofp-src/tex/sofp-summary.tex
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,13 @@ \subsubsection{Exercise \label{par:Exercise-additional-12}\ref{par:Exercise-addi
If $M$ is a commutative monad then $M\circ M$ is also a lawful commutative
monad.
\subsubsection{Exercise \label{par:Exercise-additional-13}\ref{par:Exercise-additional-13}}
\subsubsection{Exercise \label{par:Problem-monads-1}\ref{par:Problem-monads-1}}
\footnote{This was an open problem but it was solved by Hew Wolff.}
Prove that $L^{A}\triangleq\bbnum 1+\underbrace{A\times A\times...\times A}_{n\text{ times}}$
cannot be made into a monad if $n\ge2$.
\subsubsection{Exercise \label{par:Exercise-additional-13-1}\ref{par:Exercise-additional-13-1}}
If $M$ is a commutative monad and $W$ is a commutative monoid then
the monoid $M^{W}$ is commutative.
Expand Down Expand Up @@ -632,14 +638,7 @@ \subsection{Open problems\index{open problems}}
The author of this book does not know how to answer the following
questions and also could not find any answers in existing books or
papers.
\subsubsection{Problem \label{par:Problem-monads-1}\ref{par:Problem-monads-1}}
Do all polynomial functors of the form $P_{n}^{A}\triangleq\bbnum 1+\overbrace{A\times A\times...\times A}^{n\text{ times, }n\ge2}$
fail to be monads? An example is the functor $P_{2}^{A}\triangleq\bbnum 1+A\times A$,
which is not a monad because all possible implementations of \lstinline!pure!
and \lstinline!flatMap! methods for $P_{2}$ fail the monad laws.\footnote{See discussion here: \texttt{\href{https://stackoverflow.com/questions/49742377}{https://stackoverflow.com/questions/49742377}}}
papers.
\subsubsection{Problem \label{par:Problem-monads}\ref{par:Problem-monads}}
Expand All @@ -660,6 +659,10 @@ \subsubsection{Problem \label{par:Problem-monads}\ref{par:Problem-monads}}
there any polynomial monads \emph{not} obtained by a chain of these
constructions?
For example, functors of the form $L^{A}\triangleq\bbnum 1+A\times A$,
$L^{A}\triangleq\bbnum 1+A\times A\times A$, etc., cannot be obtained
via these constructions. All those functors are not monads (see Exercise~\ref{par:Problem-monads-1}).
\subsubsection{Problem \label{subsec:Problem-co-pointed-applicative}\ref{subsec:Problem-co-pointed-applicative}}
By Statement~\ref{subsec:Statement-co-pointed-applicative-example},
Expand Down
2 changes: 1 addition & 1 deletion sofp-src/tex/sofp-typeclasses.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2889,7 +2889,7 @@ \subsection{Pointed functors: motivation and laws\label{subsec:Pointed-functors-
Since both sides of the law are functions applied to an arbitrary
value $x^{:A}$, we can omit $x$ and rewrite the law as:
\begin{equation}
\text{for any }f^{:A\rightarrow B}:\quad\quad\text{pu}_{F}\bef f^{\uparrow F}=f\bef\text{pu}_{F}\quad.\label{eq:naturality-law-of-pure}
\text{for any }f^{:A\rightarrow B}:\quad\text{pu}_{F}\bef f^{\uparrow F}=f\bef\text{pu}_{F}\quad.\label{eq:naturality-law-of-pure}
\end{equation}
\[
\xymatrix{\xyScaleY{2.0pc}\xyScaleX{4.0pc}A\ar[r]\sp(0.5){\text{pu}_{F}}\ar[d]\sb(0.45){f} & F^{A}\ar[d]\sp(0.45){f^{\uparrow F}}\\
Expand Down
Loading

0 comments on commit b120b8a

Please sign in to comment.