- Notifications
You must be signed in to change notification settings - Fork23
High level commands to declare a hierarchy based on packed classes
License
math-comp/hierarchy-builder
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Hierarchy Builder (HB) provides high level commands to declare a hierarchy of algebraic structure(or interfaces if you prefer the glossary of computer science) for the Coq system.
Given a structure one can develop its theory, and that theory becomes automatically applicable toall the examples of the structure. One can also declare alternative interfaces, for convenienceor backward compatibility, and provide glue code linking these interfaces to the structures part ofthe hierarchy.
HB commands compile down to Coq modules, sections, records, coercions, canonical structure instancesand notations following thepacked classes discipline which is at the core of theMathematicalComponents library. All that complexity is hidden behinda few concepts and a few declarative Coq commands.
From HBRequireImport structures.From CoqRequireImport ssreflect ZArith.HB.mixinRecord IsAddComoid A := { zero : A; add : A -> A -> A; addrA : forall x y z, add x (add y z) = add (add x y) z; addrC : forall x y, add x y = add y x; add0r : forall x, add zero x = x;}.HB.structureDefinition AddComoid := { A of IsAddComoid A }.Notation "0" := zero.Infix "+" := add.Checkforall (M : AddComoid.type) (x : M), x + x = 0.
This is all we need to do in order to declare theAddComoid
structureand write statements in its signature.
We proceed by declaring how to obtain an Abelian group out of theadditive, commutative, monoid.
HB.mixinRecord IsAbelianGrp A of IsAddComoid A := { opp : A -> A; addNr : forall x, opp x + x = 0;}.HB.structureDefinition AbelianGrp := { A of IsAbelianGrp A & IsAddComoid A }.Notation "- x" := (opp x).
Abelian groups feature the operations and properties given by theIsAbelianGrp
mixin (and its dependencyIsAddComoid
).
Lemma example (G : AbelianGrp.type) (x : G) : x + (- x) = - 0.Proof. by rewrite addrC addNr -[LHS](addNr zero) addrC add0r.Qed.
We proceed by showing thatZ
is an example of both structures, and usethe lemma just proved on a statement aboutZ
.
HB.instanceDefinition Z_CoMoid := IsAddComoid.Build Z 0%Z Z.add Z.add_assoc Z.add_comm Z.add_0_l. HB.instanceDefinition Z_AbGrp := IsAbelianGrp.Build Z Z.opp Z.add_opp_diag_l.Lemma example2 (x : Z) : x + (- x) = - 0.Proof. by rewrite example.Qed.
Thispaper describes the languagein details, and the corresponding talkis available on youtube.Thewiki gathers sometricks and FAQs. If you want to work on the implementation of HB, thisrecorded hacking session may be relevant to you.
(click to expand)
- You can install HB via OPAM
opam repo add coq-released https://coq.inria.fr/opam/releasedopam install coq-hierarchy-builder
- You can use it in nix with the attribute
coqPackages_8_XX.hierarchy-builder
e.g.vianix-shell -p coq_8_13 -p coqPackages_8_13.hierarchy-builder
(click to expand)
amixin is a bare bone building block of the hierarchy, it packs operationsand axioms.
afactory is a package of operations and properties that is elaborated byHB to one or more mixin. A mixin is hence a trivial factory.
astructure is declared by attaching zero or more factories to a type.
abuilder is a user provided piece of code capable ofbuilding one or more mixins from a factory.
aninstance is an example of a structure: it provides all operation andfulfills all axioms.
(click to expand)
HB core commands:
HB.mixin
declares a mixin,HB.structure
declares a structure,HB.factory
declares a factory,HB.builders
andHB.end
declare a set of builders,HB.instance
declares a structure instance,HB.declare
declares a context with parameters, key and mixins.HB.saturate
reconsiders all mixin instances to see if some newly declaredstructure can be inhabited
HB core tactic-in-term:
HB.pack
to synthesize a structure instance in the middle of a term.
HB utility commands:
HB.export
exports a module and schedules it for re-exportHB.reexport
exports all modules, instances and constants scheduled forre-exportHB.lock
locks a definition behind an opaque symbol and an unfoldingequation using Coq module system
HB queries:
HB.about
is similar toAbout
but prints more info on HB structures, likethe known instances and where they are declaredHB.locate
is similar toLocate
, prints file name and line of any globalconstant synthesized by HBHB.graph
prints the structure hierarchy to a dot fileHB.howto
prints sequences of factories to equip a type with a given structure
HB debug commands:
HB.status
dumps the contents of the hierarchy (debug purposes)HB.check
is similar toCheck
(testing purposes)
The documentation of all commands can be found in the comments ofstructures.v, search forElpi Command
and you willfind them. All commands can be prefixed with the attribute#[verbose]
to get an idea of what they are doing.
For debugging and teaching purposes, passing the attributes#[log]
or#[log(raw)]
to a HB command prints Coq commands which arealmost equivalent to its effect. Hence, copy-pasting the displayed commands intoyour source file is not expected to work, and we strongly recommendagainst it.
(click to expand)
- demo1 anddemo3 declare and evolve a hierarchy up torings with various clients that are tested not to break when the hierarchyevolves
- demo2 describes the subtle triangular interaction between groups,topological space and uniform spaces. Indeed, 1. all uniform spaces induce atopology, which makes them topological spaces, but 2. all topological groups(groups that are topological spaces such that the addition and opposite arecontinuous) induce a uniformity, which makes them uniform spaces. We solvethis seamingly mutual dependency using HB.
About
High level commands to declare a hierarchy based on packed classes