Packaging Mathematical Structures
1
2
F. Garillot , G. Gonthier ,
A. Mahboubi3, L. Rideau4
1
: Microsoft Research - INRIA Joint Centre
2
: Microsoft Research
3
: INRIA Saclay-Île de France
4
: INRIA Sophia-Antipolis
1
Formalizing Finite Group Algebra
the Feit-Thompson proof
combinatorics,
local analysis
finite setting
character theory
linear algebra,
infinite setting
problems
2007
2008
2009
2010
2011
This paper presents our solutions using Coq’s dependent records, coercions,
type inference.
2
Packaging Mathematical Structures
Composable mathematical structures
This talk
Our algebraic hierarchy
Our paper
Hierarchy details,
a nice alternative to Σ-types
Two proof examples, in depth
3
Our Algebraic Hierarchy
Type
Type
See the
paper,
Equality
SubType
§ 3.1.
Choice
Zmodule
Countable
Ring
Finite
See A Modular Formalization Of Finite Group Theory,
Commutative Ring
Unit Ring
...
(TPHOLs 07)
Commutative Unit Ring
Integral Domain
Field
Decidable field
Closed Field
4
Our Algebraic Hierarchy
Type
Type
See the
paper,
Equality
SubType
§ 3.1.
Choice
Zmodule
Countable
Ring
Finite
See A Modular Formalization Of Finite Group Theory,
Commutative Ring
Unit Ring
...
(TPHOLs 07)
Commutative Unit Ring
Integral Domain
Field
Decidable field
Closed Field
depth = 10
4-a
Our Algebraic Hierarchy
Type
Type
See the
paper,
(nothing here)
Equality
SubType
§ 3.1.
➘
Choice
Zmodule
Countable
Ring
Finite
See A Modular Formalization Of Finite Group Theory,
Commutative Ring
Unit Ring
...
(TPHOLs 07)
Commutative Unit Ring
Integral Domain
practical
purpose
Field
Decidable field
Closed Field
4-b
Our Algebraic Hierarchy
Type
Type
See the
paper,
Equality
SubType
§ 3.1.
Choice
Zmodule
Countable
Ring
Finite
See A Modular Formalization Of Finite Group Theory,
Commutative Ring
Unit Ring
...
(TPHOLs 07)
Commutative Unit Ring
multiple
inheritance
Integral Domain
Field
Decidable field
Closed Field
4-c
Our Algebraic Hierarchy
Type
Blue nodes collapse
on green in a clas-
Equality
sical/untyped setting.
Choice
infinite
Type
quotients in
paper,
intentional
SubType
setting
Zmodule
Countable
Ring
Finite
See the
§ 3.1.
See A Modular Formalization Of Finite Group Theory,
Commutative Ring
Unit Ring
...
(TPHOLs 07)
Commutative Unit Ring
Integral Domain
Field
Decidable field
Closed Field
4-d
Our Algebraic Hierarchy
Type
Equality
Type
better
compositionality
See the
paper,
SubType
§ 3.1.
Choice
Zmodule
Countable
Ring
Finite
See A Modular Formalization Of Finite Group Theory,
Commutative Ring
Unit Ring
...
(TPHOLs 07)
Commutative Unit Ring
Integral Domain
Field
Decidable field
Closed Field
4-e
Our Algebraic Hierarchy
5
Our Algebraic Hierarchy
(1) This hierarchy is populated by ground types, e.g.: Z/nZ, Fp
5-a
Our Algebraic Hierarchy
(1) This hierarchy is populated by ground types, e.g.: Z/nZ, Fp
(2) . . . and parametric types, e.g.: matrix, polynomials.
5-b
Our Algebraic Hierarchy
(1) This hierarchy is populated by ground types, e.g.: Z/nZ, Fp
(2) . . . and parametric types, e.g.: matrix, polynomials.
(3) Very little computational content or theory in a Ring
5-c
Our Algebraic Hierarchy
(1) This hierarchy is populated by ground types, e.g.: Z/nZ, Fp
(2) . . . and parametric types, e.g.: matrix, polynomials.
(3) Very little computational content or theory in a Ring
(4) but it is a nice package that occurs several times in lemma statements.
5-d
Our Algebraic Hierarchy
(1) This hierarchy is populated by ground types, e.g.: Z/nZ, Fp
(2) . . . and parametric types, e.g.: matrix, polynomials.
(3) Very little computational content or theory in a Ring
(4) but it is a nice package that occurs several times in lemma statements.
(5)
h
Components, objects
i
6=
h
APIs, interfaces
i
5-e
Our Algebraic Hierarchy
(1) This hierarchy is populated by ground types, e.g.: Z/nZ, Fp
(2) . . . and parametric types, e.g.: matrix, polynomials.
(3) Very little computational content or theory in a Ring
(4) but it is a nice package that occurs several times in lemma statements.
(5)
h
Components, objects
i
6=
h
APIs, interfaces
i
(6) algebraic properties =
^ interface programming
5-f
Representing objects and structures
We want to manipulate objects:
6
Representing objects and structures
We want to manipulate objects:
(Cayley-Hamilton)
"
P (A) = 0
where P (X) = det(X • In − A)
#
6-a
Representing objects and structures
We want to manipulate objects:
(Cayley-Hamilton)
"
P (A) = 0
where P (X) = det(X • In − A)
#
But we do not want to specify the corresponding structure:
The Ring of polynomials over
the Ring of matrices
over a general Commutative Ring.
6-b
A Type class
ZModule (M:Type)
a constant zero :
an operation : add :
M
M-> M -> M
axiom(s) verified by add on M
associative add;
...
C elements per structure,
n nested (parametric) structures in which the parameter occurs at every element:
term size in C n
How do we pass structures when enunciating lemmas ?
Proofs introduce structures.
7
A Typical structure
We fill the blanks using Canonical Structures.
operation on the type
Module Equality.
Record mixin_of (T : Type) : Type :=
Mixin { op : rel T; _ : forall x y, reflect (x = y) (op x y) }.
Structure type : Type :=
Pack { sort :> Type; mixin : mixin_of sort}.
End Equality.
representation type
axiom(s) verified by the operation
projection
8
A Typical structure
We fill the blanks using Canonical Structures.
Module Equality.
Record mixin_of (T : Type) : Type :=
Mixin {
: _
; _ : _
}.
Structure type : Type :=
Pack {sort :> Type; mixin : mixin_of sort}.
End Equality.
This is generic: we use modules as namespaces only:
Notation eqType := Equality.type.
9
Canonical Structure Composition
Most widely used: Telescopes
zmodType
eqType
T
MixinEq
opzmod
MixinZmod
opzmod
axiomszmod
axiomszmod
10
Telescopes : Canonical Structure inference
2+2
Notation
Zmodule.add α 2 2
type inference
Equality.sort(Zmodule.sortα) ≡βιδ int
lookup
(Equality.sort,int)
;
inteqT ype
Zmodule.sortα ≡βιδ inteqT ype
lookup
(Zmodule.sort,int eqT ype ) ; intzmodT ype
Equality.sort (Zmodule.sort (intzmodT ype ))
11
Telescopes : Canonical Structure inference
2+2
Notation
Zmodule.add α 2 2
type inference
Equality.sort(Zmodule.sortα) ≡βιδ int
lookup
(Equality.sort,int)
;
inteqT ype
Zmodule.sortα ≡βιδ inteqT ype
lookup
(Zmodule.sort,int eqT ype ) ; intzmodT ype
Equality.sort (Zmodule.sort (intzmodT ype ))
Simple packaging, but
11-a
Telescopes : Canonical Structure inference
2+2
Notation
Zmodule.add α 2 2
type inference
Equality.sort(Zmodule.sortα) ≡βιδ int
lookup
(Equality.sort,int)
;
inteqT ype
Zmodule.sortα ≡βιδ inteqT ype
lookup
(Zmodule.sort,int eqT ype ) ; intzmodT ype
Equality.sort (Zmodule.sort (intzmodT ype ))
Simple packaging, but
head constant always the same x:T is interpreted as
x:Equality.sort(Zmodule.sort T)
11-b
Telescopes : Canonical Structure inference
2+2
Notation
Zmodule.add α 2 2
type inference
Equality.sort(Zmodule.sortα) ≡βιδ int
lookup
(Equality.sort,int)
;
inteqT ype
Zmodule.sortα ≡βιδ inteqT ype
lookup
(Zmodule.sort,int eqT ype ) ; intzmodT ype
Equality.sort (Zmodule.sort (intzmodT ype ))
Simple packaging, but
head constant always the same x:T is interpreted as
x:Equality.sort(Zmodule.sort T)
we’re defining coercions/canonical projections on Equality.sort !
11-c
Telescopes : Canonical Structure inference
2+2
Notation
Zmodule.add α 2 2
type inference
Equality.sort(Zmodule.sortα) ≡βιδ int
lookup
(Equality.sort,int)
;
inteqT ype
Zmodule.sortα ≡βιδ inteqT ype
lookup
(Zmodule.sort,int eqT ype ) ; intzmodT ype
Equality.sort (Zmodule.sort (intzmodT ype ))
Simple packaging, but
head constant always the same x:T is interpreted as
x:Equality.sort(Zmodule.sort T)
we’re defining coercions/canonical projections on Equality.sort !
as is, no multiple inheritance
11-d
Packed Classes
zmodType
Classzmod
T
ClassEq
opeq
MixinZmod
opzmod
axiomseq
axiomszmod
12
Packed Classes
zmodType
Classzmod
T
ϕ
T
eqType
ClassEq
opeq
MixinZmod
opzmod
axiomseq
axiomszmod
ϕ
Classeq
x : T
denotes
x : (Zmodule.sort T α),
which, thanks to ϕ, has a
canonical eqType structure.
12-a
Packed Classes
2 + 2 == 4
Notation
Equality.op γ(Zmodule.add α 2 2) 4
Zmodule.sort
|
{z α ≡ int}
lookup(Zmodule.sort,int)
; intzmodT ype
Zmodule.sort intzmodType
Equality.sort γ ≡ Zmodule.sort intzmodType
lookup(Equality.sort,Zmodule.sort
intzmodT ype )
; Zmodule.eqType(int zmodT ype )
Equality.op (Zmodule.eqType(int zmodT ype ))(Zmodule.add ...)
≡βιδ
4 == 2 + 2
4
Notation
Equality.op γ (Zmodule.add α 2 2) 4
lookup(Equality.sort,int) ; inteqT ype
Equality.op inteqT ype (Zmodule.add α 2 2) 4
...
13
Packed Classes
Coherent coercions,
x:T
interpreted as Zmodule.sort T.
Multiple inheritance:
Module ComUnitRing.
Record class_of (R : Type) : Type := Class {
base1 :> ComRing.class_of R;
ext :> UnitRing.mixin_of (Ring.Pack base1 R)}.
Coercion base2 R m := UnitRing.Class (@ext R m).
...
End ComUnitRing.
14
Conclusion
algebraic structure composition is interface programming
representing a large hierarchy implies packaging
know the work ahead,
and take the time to build the tools you will need
15
Cn
16
Cn
A + x
16-a
Cn
A + x
add (matrix T) (zeromx T) (addmx T)
16-b
Cn
A + x
add (matrix T) (zeromx T) (addmx T)
...
(addmx (poly T) (zeropx T) (addpx T) )
16-c
Cn
A + x
add (matrix T) (zeromx T) (addmx T)
...
(addmx (poly T) (zeropx T) (addpx T) )
and zeromx is itself (zeromx (poly T) (zeropx T) (addpx T) ) ...
16-d
© Copyright 2026 Paperzz