Skip to content

Commit 0fbd8ec

Browse files
committed
2 parents c56056c + df603be commit 0fbd8ec

File tree

6 files changed

+111
-59
lines changed

6 files changed

+111
-59
lines changed

doc/hydra-chapter.tex

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ \subsection{The rules of the game}
112112
Thus, the replication process will be represented as a binary relation on a data type \texttt{Hydra},
113113
linking the state of the hydra \emph{before} and \emph{after} the transformation.
114114
A battle will thus be represented as a sequence of terms of type \texttt{Hydra}, respecting the rules of the game.
115-
115+
In other terms, we consider hydra battles as \emph{transition systems}.
116116

117117

118118

@@ -154,7 +154,7 @@ \subsection{Example}
154154
\end{figure}
155155

156156

157-
\begin{figure}[hp]
157+
\begin{figure}[h]
158158
\centering
159159
\begin{tikzpicture}[very thick, scale=0.5]
160160

@@ -179,7 +179,7 @@ \subsection{Example}
179179
\label{fig:Hy2}
180180
\end{figure}
181181

182-
\begin{figure}[hp]
182+
\begin{figure}[h]
183183
\centering
184184
\begin{tikzpicture}[very thick, scale=0.6]
185185

@@ -221,7 +221,7 @@ \subsection{Example}
221221

222222
Figs.~\ref{fig:Hy4} and~\vref{fig:Hy5} represent a possible third round of the battle, with a replication factor equal to $2$. Let us call \texttt{Hy'''} the state of the hydra after that third round.
223223

224-
\begin{figure}[hp]
224+
\begin{figure}[h]
225225
\centering
226226
\begin{tikzpicture}[very thick, scale=0.6]
227227

@@ -262,7 +262,7 @@ \subsection{Example}
262262
\caption{A third beheading (wounded part in red) \label{fig:Hy4}}
263263
\end{figure}
264264

265-
\begin{figure}[hp]
265+
\begin{figure}[h]
266266
\centering
267267
\begin{tikzpicture}[very thick, scale=0.4]
268268

@@ -415,9 +415,7 @@ \section{Hydras and their representation in \emph{Coq}}
415415
\input{movies/snippets/Hydra_Definitions/HydraAlt}
416416

417417
Using this representation, one can re-define all the constructions of this chapter, which is left as an exercise.
418-
You will probably have to use patterns described for instance in~\cite{BC04} or the archives of the \coq communication channels (please consult~\url{https://coq.inria.fr/community.html}).
419-
420-
418+
You will probably have to use patterns described for instance in~\cite{BC04, BC04ch14} or the archives of the \coq communication channels (please consult~\url{https://coq.inria.fr/community.html}).
421419
\end{remark}
422420

423421

@@ -552,8 +550,8 @@ \subsubsection{A failed attempt}
552550

553551
\input{movies/snippets/Hydra_Examples/BadInductiond}
554552

555-
We notice that this sub-goal does not contain any hypothesis
556-
on the height and size of the hydra \texttt{h}. So, it looks hard to prove the conclusion. Let's stop.
553+
We notice immediately that the context of this sub-goal does not allow to infer its conclusion.
554+
Let's stop.
557555

558556
\input{movies/snippets/Hydra_Examples/BadInductione}
559557

@@ -611,7 +609,7 @@ \section{Relational description of hydra battles}
611609

612610

613611
In this section, we represent the rules of hydra battles as a binary relation associated with
614-
a \emph{round}, i.e., an interaction composed of the two following actions:
612+
a \emph{round}\footnote{usually called a \emph{small step semantics}}, i.e., an interaction composed of the two following actions:
615613
\begin{enumerate}
616614
\item Hercules chops off one head of the hydra.
617615
\item Then, the hydra replicates the wounded part (if the head is at distance $\geq 2$ from the foot).
@@ -635,7 +633,7 @@ \section{Relational description of hydra battles}
635633

636634
\subsection{Chopping off a head at distance 1 from the foot (relation R1)}
637635

638-
If Hercules chops off a head close to the root, there is no replication at all. We use an auxiliary
636+
If Hercules chops off a head next to the root, there is no replication at all. We use an auxiliary
639637
predicate \texttt{S0}, associated with the removing of one head from a sequence of hydras.
640638

641639

@@ -648,7 +646,7 @@ \subsubsection{Example}
648646
\label{sec:orgheadline45}
649647

650648
Let us represent in \coq{} the transformation of the hydra of Fig.~\vref{fig:Hy} into
651-
the configuration represented in Fig.~\ref{fig:Hy-prime}.
649+
the configuration represented in Fig.~\vref{fig:Hy-prime}.
652650

653651
\vspace{4pt}
654652
\emph{From Module~\href{../theories/html/hydras.Hydra.Hydra_Examples.html}{Hydra.Hydra\_Examples}}
@@ -697,7 +695,7 @@ \subsubsection{Example}
697695

698696
\subsection{Binary relation associated with a round}
699697

700-
Let us merge \texttt{R1} and \texttt{R1} into a single relation.
698+
Let us merge \texttt{R1} and \texttt{R2} into a single relation.
701699
First, we define the relation \texttt{(round\_n n h h')} where \texttt{n} is the expected number of replications (irrelevant in the case of an \texttt{R1}-transformation).
702700
Then, we define a \emph{round} (small step) of a battle
703701
by abstraction over \texttt{n},
@@ -731,13 +729,6 @@ \subsection{Rounds and battles}
731729

732730
\input{movies/snippets/Hydra_Definitions/roundPlus}
733731

734-
\index{hydras}{Exercises}
735-
736-
\begin{exercise}
737-
Prove that if \texttt{$h$ -+-> $h'$}, then
738-
the height of $h'$ is less or equal than the height of $h$.
739-
740-
\end{exercise}
741732

742733
\begin{remark}
743734
\label{remark:transitive-closure}
@@ -763,6 +754,12 @@ \subsection{Rounds and battles}
763754
The same remark also holds for reflexive and transitive closures.
764755
\end{remark}
765756

757+
\index{hydras}{Exercises}
758+
\begin{exercise}
759+
Prove that if \texttt{$h$ -+-> $h'$}, then
760+
the height of $h'$ is less or equal than the height of $h$.
761+
762+
\end{exercise}
766763
\index{hydras}{Exercises}
767764

768765
\begin{exercise}
@@ -1007,9 +1004,9 @@ \subsection{Looking for regularities}
10071004

10081005
\subsection{Testing \dots}
10091006
\label{sect:testing}
1010-
In order to study \emph{experimentally} the different configurations of the battle, we will use a simple data type for representing the states as tuples composed of
1011-
the round number, and the respective number of daughters \texttt{h2}, \texttt{h1}, and heads
1012-
of the current hydra.
1007+
In order to make the study of this battle easier, we will use a simple data type for representing a configuration
1008+
$(\textit{round}, \texttt{hyd}\;n_2\;n_1\; n_h)$ as the $4$-tuple
1009+
10131010

10141011

10151012
\input{movies/snippets/BigBattle/stateDef}
@@ -1039,7 +1036,7 @@ \subsection{Testing \dots}
10391036
\input{movies/snippets/BigBattle/testDefTests}
10401037

10411038
The battle we are studying looks to be awfully long. Let us concentrate our
1042-
tests on some particular events : the states where $\texttt{nh}=0$.
1039+
tests on some particular events : the states where $n_h=0$.
10431040
From the value of \texttt{test 5}, it is obvious that at the 10-th round, the counter \texttt{nh} is equal to zero.
10441041

10451042

@@ -1068,7 +1065,8 @@ \subsection{Proving \dots}
10681065
We are now able to reason about the sequence of transitions defined by our hydra battle.
10691066

10701067
Let us define a binary relation associated with every round of the battle.
1071-
In the following definition \texttt{i} is associated with the round number (or date, if we consider a discrete time), and \texttt{a}, \texttt{b}, \texttt{c} respectively associated with the number of occurrences of \texttt{h2}, \texttt{h1} and heads connected to the hydra's foot. For convenience, we do not use the type \texttt{state} of the preceding section, but consider the round numbers and the number of hydras \texttt{h2}, \texttt{h1} and heads as separate arguments of the relation (which is no more ---formally--- ``binary'').
1068+
In the following definition \texttt{i} is associated with the round number (or date, if we consider a discrete time), and \texttt{a}, \texttt{b}, \texttt{c} respectively associated with the number of occurrences of \texttt{h2}, \texttt{h1} and heads connected to the hydra's foot. For convenience\footnote{In a few words, the type \texttt{state} was designed for performing \emph{computations}, and \texttt{steps} for writing \emph{interactive proofs}, inspired by the aforementionned computations.},
1069+
we do not use the type \texttt{state} of the preceding section, but consider the round numbers and the number of hydras \texttt{h2}, \texttt{h1} and heads as separate arguments of the relation (which is no more ---formally--- ``binary'').
10721070

10731071
\input{movies/snippets/BigBattle/oneStep}
10741072

@@ -1088,7 +1086,7 @@ \subsection{Proving \dots}
10881086

10891087

10901088

1091-
The following lemma establishes a relation between \texttt{steps} and the predicate \texttt{battle}.
1089+
The following lemma establishes a relation between \texttt{steps} and the predicate \texttt{rounds}.
10921090

10931091
\input{movies/snippets/BigBattle/stepsBattle}
10941092

@@ -1248,7 +1246,7 @@ \subsection{A minoration lemma}
12481246
\vspace{4pt}
12491247

12501248

1251-
The number $N$ is greater than or equal to $2^{2^{95}\times 95}.$ If we wrote $N$ in base $10$, $N$ would require at least $10^{30}$ digits!
1249+
The number $N$ is greater than or equal to $2^{2^{95}\times 95}.$ If we write $N$ in base $10$, $N$ would require at least $10^{30}$ digits!
12521250

12531251

12541252
\section{Generic properties}
@@ -1331,7 +1329,7 @@ \subsection{A small proof of impossibility}
13311329
one has to consider first a well-founded set $(A,<)$, then a strictly decreasing measure on this set. The following lemma shows that, if the order structure $(A,<)$ is too simple, it is useless to look for a convenient measure, which simply no exists. Such kind of result is useful, because it saves you time and effort.
13321330

13331331

1334-
The best known well-founded order is the natural order on the set $\mathbb{N}$ of natural numbers (the type \texttt{nat} of Standard library). It would be interesting to look for some measure $m:\texttt{nat}\arrow\texttt{nat}$ and prove it is a variant.
1332+
The best known well-founded order is the natural order on the set $\mathbb{N}$ of natural numbers (the type \texttt{nat} of Standard Library). It would be interesting to look for some measure $m:\texttt{nat}\arrow\texttt{nat}$ and prove it is a variant.
13351333

13361334
Unfortunately, we can prove that
13371335
\emph{no} instance of class (\texttt{WfVariant round Peano.lt $m$}) can be built, where

doc/hydras.tex

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ \section{Generalities}
207207
necessary. Since the development of a theory is represented as a bunch of computer files,
208208
everyone is able to read the proofs with an arbitrary level of detail, or to play with the theory by writing alternate proofs or definitions.
209209

210+
If a formal development is large (at least 10 KLOCs), we believe that a human-readable document containing explanations, diagrams, code snippets, examples, exercises, etc.) would be useful
211+
for a better understanding of both the mathematical contents
212+
and the formalization techniques used in the
213+
development~\cite{Chiplunkar23}.
214+
215+
This document has been generated with \alectr (see Sect.~\vref{sect:alectryon-intro}), which ensures the \texttt{pdf} is consistent with the last compiled version of the \coq project.
216+
210217

211218
Among all the theorems proved with the help of proof assistants like \coq{}~\cite{Coq,BC04}, \hol{}~\cite{HOL}, \isabelle{}~\cite{isabelle}, etc.,
212219
several statements and proofs share some interesting features:
@@ -331,6 +338,7 @@ \section{Generalities}
331338

332339

333340
\subsection{Documenting theories with \alectr}
341+
\label{sect:alectryon-intro}
334342

335343
Quotations of \coq source and answers are progressively replaced from copy-pasted \emph{verbatim} to automatically generated \emph{LaTeX} blocks, using Clément Pit-Claudel's \alectr tool~\cite{alectryonpaper, alectryongithub}.
336344
Many thanks to Jérémy Damour, Clément Pit-Claudel and Théo Zimmermann who designed tools for maintaining consistency between the always evolving \coq{} modules and documentation written in \emph{LaTeX}.
@@ -341,8 +349,8 @@ \subsection{Trust in our proofs}
341349
\label{sect:trust-in-proofs}
342350

343351
Unlike mathematical literature, where definitions and proofs are spread out over many articles and books,
344-
the whole proof is now inside your computer. It is composed from the \texttt{.v} files you downloaded and
345-
parts of \coq's standard library. Thus, there is no ambiguity in our definitions and the premises of the theorems. Furthermore, you will be able to navigate through the development, using your favorite text editor or IDE, and some commands like \texttt{Search}, \texttt{Locate}, etc.
352+
the whole proof is now inside your computer. It is composed from the \texttt{.v} files you downloaded,
353+
parts of \coq's standard library, and required \coq packages (see Fig.~\vref{fig:genealogy}). Thus, there is no ambiguity in our definitions and the premises of the theorems. Furthermore, you will be able to navigate through the development, using your favorite text editor or IDE, and some commands like \texttt{Search}, \texttt{Locate}, etc.
346354

347355

348356

@@ -356,7 +364,8 @@ \subsection{Assumed redundancy}
356364
several aborted proofs.
357365
Of course, do not hesitate to contribute nice proofs or alternative definitions!
358366

359-
It may also happen that some proof looks to be useless, because the proven theorem is a trivial consequence of another (also proven) result.
367+
It may also happen that some direct proof looks to be useless,
368+
because the proven theorem is a trivial consequence of another (also proven) result.
360369
For instance, let us consider the three following statements:
361370
\begin{enumerate}
362371
\item There is no measure into $\mathbb{N}$ for proving the termination of all hydra battles (Sect~\vref{omega-case}).
@@ -398,7 +407,6 @@ \subsection{Typographical Conventions}
398407

399408
\subsubsection{Using \alectr}
400409
Whenever possible, we use \alectr to display \coq code (definition, proof scripts) and answers.
401-
402410
Here are two examples from Chapters~\ref{chapter:primrec}
403411
and~\ref{chapter-powers}.
404412

@@ -410,18 +418,25 @@ \subsubsection{Using \alectr}
410418
\inputsnippets{Fib2/fibEuclDemo}
411419

412420
\subsubsection{Verbatim quotations}
421+
In some situations, we replace \alectr snippets with
422+
verbatim blocks.
413423

414-
Quotations of \coq{} source from others libraries (\coq's standard library, borrowed plug-ins) are displayed as follows.
415-
416-
\begin{Coqsrc}
424+
\begin{itemize}
425+
\item When the quoted source belongs to some library on which we do not have the write permission, we cannot include
426+
directives for generating snippets.
427+
For instance, the following code belongs to \coq's standard library.
428+
\begin{Coqsrc}
417429
Inductive CompareSpec (Peq Plt Pgt : Prop) :
418430
comparison -> Prop :=
419431
CompEq : Peq -> CompareSpec Peq Plt Pgt Eq
420432
| CompLt : Plt -> CompareSpec Peq Plt Pgt Lt
421433
| CompGt : Pgt -> CompareSpec Peq Plt Pgt Gt.
422434
\end{Coqsrc}
423435

424-
We use also verbatim code inclusions when the examples lead to very long computations.
436+
437+
\item
438+
We use also verbatim code inclusions when the examples would lead to too long computations during the compilation and the
439+
documentation generation.
425440

426441
\begin{Coqbad}
427442
Example C87_ok_slow : chain_correct 87 C87.
@@ -436,7 +451,7 @@ \subsubsection{Verbatim quotations}
436451
\begin{Coqbad}
437452
Qed.
438453
\end{Coqbad}
439-
454+
\end{itemize}
440455
\subsection{Remark}
441456

442457
In general, we do not include full proof scripts in this document. The only exceptions are very short proofs (\emph{e.g.}, proofs by computation, or by application of automatic tactics). Likewise, we may display only the important steps on a long interactive proof, for instance, in the following lemma (\vref{lemma:L-2_6-1}):
@@ -479,7 +494,7 @@ \subsection{Alternative or bad definitions}
479494

480495
\section{How to install the libraries}
481496
\label{sec:orgheadline4}
482-
The present distribution has been checked with version 8.14.1 of the Coq proof assistant, with a few plug-ins. \emph{Please refer to \href{https://github.com/coq-community/hydra-battle\#readme}{the README file of the project}.}
497+
The present distribution has been checked with versions up to 8.18 of the Coq proof assistant, with a few plug-ins. \emph{Please refer to \href{https://github.com/coq-community/hydra-battle\#readme}{the README file of the project}.}
483498

484499

485500
\section{Comments on exercises and projects}

doc/thebib.bib

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ @book{BC04
6969

7070

7171

72+
73+
7274
@InBook{BC04ch14,
7375
author = {Bertot, Yves and Cast\'eran, Pierre},
7476
title = {Interactive Theorem Proving and Program Development: {Coq'Art}: The Calculus of Inductive Constructions},
75-
chapter = {14},
77+
chapter = {Foundations of Inductive Types},
7678
publisher = {Springer},
7779
year = {2004},
7880
note = {\url{https://www-sop.inria.fr/members/Yves.Bertot/coqart-chapter14.pdf}},
@@ -1331,3 +1333,13 @@ @Misc{Dowek2023
13311333
note = {\url{https://arxiv.org/pdf/2303.18099.pdf}},
13321334
}
13331335

1336+
@InProceedings{Chiplunkar23,
1337+
author = {Shardul Chiplunkar and Clément Pit-Claudel },
1338+
title = {Diagrammatic notations for interactive theorem proving},
1339+
OPTcrossref = {},
1340+
booktitle = {4th International Workshop on Human Aspects of Types and Reasoning Assistants},
1341+
year = {2023},
1342+
address = {Cascais, Portugal},
1343+
note = {\url{https://infoscience.epfl.ch/record/305144}}
1344+
}
1345+

theories/ordinals/Hydra/BigBattle.v

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ Qed.
7373
(* end snippet L23L03 *)
7474

7575
(** From now on, we abstract the configurations of the battle
76-
as tuples (round number, n2, n1, nh) where n2 (resp. n1, nh) is the number of
77-
sub-hydras h2 [resp. h1, heads] *)
76+
as tuples (round number, n2, n1, nh) where n2 (resp. n1, nh) is the number of daughters of type h2 [resp. h1, heads] *)
7877

7978
(* begin snippet stateDef *)
8079

0 commit comments

Comments
 (0)