33
44# Hierarchy Builder
55
6- High level commands to declare and evolve a hierarchy based on packed classes.
6+ Hierarchy Builder (HB) provides high level commands to declare a hierarchy of algebraic structure
7+ (or interfaces if you prefer the glossary of computer science) for the Coq system.
78
8- [ Presented at FSCD2020, talk available on youtube.] ( https://www.youtube.com/watch?v=F6iRaTlQrlo )
9+ Given a structure one can develop its theory, and that theory becomes automatically applicable to
10+ all the examples of the structure. One can also declare alternative interfaces, for convenience
11+ or backward compatibility, and provide glue code linking these interfaces to the structures part of
12+ the hierarchy.
13+
14+ HB commands compile down to Coq modules, sections, records, coercions, canonical structure instances
15+ and notations following the * packed classes* discipline which is at the core of the [ Mathematical
16+ Components] ( https://github.com/math-comp/math-comp ) library. All that complexity is hidden behind
17+ a few concepts and a few declarative Coq commands.
918
1019## Example
1120
1221``` coq
1322From HB Require Import structures.
1423From Coq Require Import ssreflect ZArith.
1524
16- HB.mixin Record AddComoid_of_Type A := {
25+ HB.mixin Record IsAddComoid A := {
1726 zero : A;
1827 add : A -> A -> A;
1928 addrA : forall x y z, add x (add y z) = add (add x y) z;
2029 addrC : forall x y, add x y = add y x;
2130 add0r : forall x, add zero x = x;
2231}.
23- HB.structure Definition AddComoid := { A of AddComoid_of_Type A }.
32+
33+ HB.structure Definition AddComoid := { A of IsAddComoid A }.
2434
2535Notation "0" := zero.
2636Infix "+" := add.
@@ -35,17 +45,18 @@ We proceed by declaring how to obtain an Abelian group out of the
3545additive, commutative, monoid.
3646
3747``` coq
38- HB.mixin Record AbelianGrp_of_AddComoid A of AddComoid A := {
48+ HB.mixin Record AddComoid_IsAbelianGrp A of IsAddComoid A := {
3949 opp : A -> A;
4050 addNr : forall x, opp x + x = 0;
4151}.
42- HB.structure Definition AbelianGrp := { A of AbelianGrp_of_AddComoid A & }.
52+
53+ HB.structure Definition AbelianGrp := { A of AddComoid_IsAbelianGrp A & IsAddComoid A }.
4354
4455Notation "- x" := (opp x).
4556```
4657
4758Abelian groups feature the operations and properties given by the
48- ` AbelianGrp_of_AddComoid ` mixin (and its dependency ` AddComoid ` ).
59+ ` IsAbelianGrp ` mixin (and its dependency ` IsAddComoid ` ).
4960
5061``` coq
5162Lemma example (G : AbelianGrp.type) (x : G) : x + (- x) = - 0.
@@ -57,22 +68,19 @@ the lemma just proved on a statement about `Z`.
5768
5869``` coq
5970HB.instance Definition Z_CoMoid :=
60- AddComoid_of_Type.Build Z 0%Z Z.add Z.add_assoc Z.add_comm Z.add_0_l.
71+ IsAddComoid.Build Z 0%Z Z.add Z.add_assoc Z.add_comm Z.add_0_l.
72+
6173HB.instance Definition Z_AbGrp :=
62- AbelianGrp_of_AddComoid .Build Z Z.opp Z.add_opp_diag_l.
74+ IsAbelianGrp .Build Z Z.opp Z.add_opp_diag_l.
6375
6476Lemma example2 (x : Z) : x + (- x) = - 0.
6577Proof. by rewrite example. Qed.
6678```
6779
6880## Documentation
6981
70- ### Status
71-
72- The software is beta-quality, it works but error messages should be improved.
73-
74- This [ draft paper] ( https://hal.inria.fr/hal-02478907 ) describes the language
75- in full detail.
82+ This [ paper] ( https://hal.inria.fr/hal-02478907 ) describes the language
83+ in details, and the corresponding talk [ is available on youtube.] ( https://www.youtube.com/watch?v=F6iRaTlQrlo )
7684
7785### Installation & availability
7886
@@ -87,7 +95,8 @@ opam repo add coq-released https://coq.inria.fr/opam/released
8795opam install coq-hierarchy-builder
8896```
8997
90- - You can use it in nix with the attribute ` coqPackages_8_11.hierarchy-builder ` e.g. via ` nix-shell -p coq_8_11 -p coqPackages_8_11.hierarchy-builder `
98+ - You can use it in nix with the attribute ` coqPackages_8_11.hierarchy-builder ` e.g.
99+ via ` nix-shell -p coq_8_11 -p coqPackages_8_11.hierarchy-builder `
91100
92101</p ></details >
93102
@@ -115,19 +124,25 @@ opam install coq-hierarchy-builder
115124
116125<details ><summary >(click to expand)</summary ><p >
117126
118- - ` HB.mixin ` declares a mixin
119- - ` HB.structure ` declares a structure
120- - ` HB.factory ` declares a factory
121- - ` HB.builders ` and ` HB.end ` declare a set of builders
122- - ` HB.instance ` declares a structure instance
123- - ` HB.export ` exports a module and schedules it for re-export
124- - ` HB.reexport ` exports all modules scheduled for re-export
125- - ` HB.graph ` prints the structure hierarchy to a dot file
126- - ` HB.status ` dumps the contents of the hierarchy (debug purposes)
127-
128- Their documentation can be found in the comments of [ structures.v] ( structures.v ) ,
129- search for ` Elpi Command ` and you will find them. All commands can be
130- prefixed with the attribute ` #[verbose] ` to get an idea of what they are doing.
127+ - HB core commands:
128+ - ` HB.mixin ` declares a mixin
129+ - ` HB.structure ` declares a structure
130+ - ` HB.factory ` declares a factory
131+ - ` HB.builders ` and ` HB.end ` declare a set of builders
132+ - ` HB.instance ` declares a structure instance
133+
134+ - HB support commands:
135+ - ` HB.export ` exports a module and schedules it for re-export
136+ - ` HB.reexport ` exports all modules and instances scheduled for re-export
137+ - ` HB.graph ` prints the structure hierarchy to a dot file
138+ - ` HB.status ` dumps the contents of the hierarchy (debug purposes)
139+ - ` HB.check ` is similar to ` Check ` (test purposes)
140+
141+ The documentation of all commands can be found in the comments of
142+ [ structures.v] ( structures.v ) , search for ` Elpi Command ` and you will
143+ find them. All commands can be prefixed with the attribute ` #[verbose] `
144+ to get an idea of what they are doing.
145+
131146See also the ` #[log] ` attribute in the "Plan B" section below.
132147
133148</p ></details >
0 commit comments