Built with Alectryon, running Coq+SerAPI. Bubbles () indicate interactive fragments: hover for details, tap to reveal contents. Use Ctrl+↑ Ctrl+↓ to navigate, Ctrl+🖱️ to focus. On Mac, use instead of Ctrl.

Literate programming with Alectryon (reST input)

Alectryon supports literate programs and documents (combinations of code and prose) written in Coq and reStructuredText. Here is an example, written in reST. It can be converted to Coq, HTML, or LaTeX using the following commands:

alectryon literate_reST.rst
    # reST+Coq → HTML;  produces ‘literate_reST.html’
$ DOCUTILSCONFIG=literate.docutils.conf alectryon \
  literate_reST.rst --backend latex
    # reST+Coq → LaTeX; produces ‘literate_reST.tex’
alectryon literate_reST.rst --backend coq
    # reST+Coq → Coq;   produces ‘literate_reST.v’

$ cd ..; python -m alectryon.literate \
    recipes/literate_reST.rst > recipes/literate_reST.min.v
  # Minimal reST → Coq; produces ‘literate_reST.min.v’
$ cd ..; python -m alectryon.literate --rst2coq - \
    < recipes/literate_reST.rst > recipes/literate_reST.min.stdin.v
  # Minimal reST → Coq; produces ‘literate_reST.min.stdin.v’

Coq fragments are introduced with .. coq:::


forall y x : nat, S x <= y -> x <= y
y: nat
IHy: forall x : nat, S x <= y -> x <= y
H: S y <= S y

y <= S y
y: nat
IHy: forall x : nat, S x <= y -> x <= y
x: nat
H: S x <= S y
H1: S x <= y
x <= S y
(* info eauto: *)
simple apply le_S.
simple apply le_n.
(* info eauto: *)
simple apply le_S.
simple apply IHy.
exact H1.
Qed.

forall x y z : nat, x <= y <= z -> x <= z

They can be nested nested into other reST directives, such as tables:

Coq commands
Coq command Description
  
x, y: nat

forall z : nat, x <= y <= z -> x <= z
Move the variables x and y into the context.
  

forall x z : nat, x <= 0 <= z -> x <= z
y: nat
IHy: forall x z : nat, x <= y <= z -> x <= z
forall x z : nat, x <= S y <= z -> x <= z
Perform induction on y, generalizing x.
  
x, z: nat
Hl: x <= 0
Hr: 0 <= z

x <= z
y: nat
IHy: forall x z : nat, x <= y <= z -> x <= z
x, z: nat
Hl: x <= S y
Hr: S y <= z
x <= z
Move conjunction into the context, splitting it into Hl and Hr.
  
x, z: nat
Hl: x <= 0
Hr: 0 <= z

x <= z
inversion Hl; assumption.
Solve base case; inversion changes x <= 0 into x = 0.
  
y: nat
IHy: forall x z : nat, x <= y <= z -> x <= z
x, z: nat
Hl: x <= S y
Hr: S y <= z

x <= z
y: nat
IHy: forall x z : nat, x <= y <= z -> x <= z
x, z: nat
Hl: x <= S y
Hr: S y <= z
H0: x <= y

x <= z
(* info eauto: *)
exact H0.
(* info eauto: *)
simple apply le_l.
exact Hr.
Solve inductive case using the le_l lemma.