packaging mathematical structuresgarillot/tphols-slides.pdf · packaging mathematical structures f....
TRANSCRIPT
Packaging Mathematical Structures
F. Garillot1, G. Gonthier2,A. Mahboubi3, L. Rideau4
1: Microsoft Research - INRIA Joint Centre2: Microsoft Research
3: INRIA Saclay-Île de France4: INRIA Sophia-Antipolis
1
Formalizing Finite Group Algebra
the Feit-Thompson proof
2007 2008 2009 2010 2011
local analysis character theory
problems
linear algebra,
infinite setting
combinatorics,
finite setting
This paper presents our so-
lutions using Coq’s de-
pendent records, coercions,
type inference.
2
Packaging Mathematical Structures
Two proof examples, in depth
Hierarchy details,
a nice alternative to Σ-types
Our algebraic hierarchy
Composable mathematical structures
This talk
Our paper
3
Our Algebraic Hierarchy
Type
Equality
Choice
Zmodule
Ring
Commutative Ring Unit Ring
Commutative Unit Ring
Integral Domain
Field Decidable field Closed Field
Countable
Finite
. . .
See A Modular Formaliza-
tion Of Finite Group Theory,
(TPHOLs 07)
Type
SubType
See the
paper,
§ 3.1.
4
Our Algebraic Hierarchy
Type
Equality
Choice
Zmodule
Ring
Commutative Ring Unit Ring
Commutative Unit Ring
Integral Domain
Field Decidable field Closed Field
Countable
Finite
. . .
See A Modular Formaliza-
tion Of Finite Group Theory,
(TPHOLs 07)
Type
SubType
See the
paper,
§ 3.1.
depth = 10
4-a
Our Algebraic Hierarchy
practical
purpose
(nothing here)
➘
Type
Equality
Choice
Zmodule
Ring
Commutative Ring Unit Ring
Commutative Unit Ring
Integral Domain
Field Decidable field Closed Field
Countable
Finite
. . .
See A Modular Formaliza-
tion Of Finite Group Theory,
(TPHOLs 07)
Type
SubType
See the
paper,
§ 3.1.
4-b
Our Algebraic Hierarchy
multiple
inheri-
tance
Type
Equality
Choice
Zmodule
Ring
Commutative Ring Unit Ring
Commutative Unit Ring
Integral Domain
Field Decidable field Closed Field
Countable
Finite
. . .
See A Modular Formaliza-
tion Of Finite Group Theory,
(TPHOLs 07)
Type
SubType
See the
paper,
§ 3.1.
4-c
Our Algebraic Hierarchy
Blue nodes collapse
on green in a clas-
sical/untyped setting.
infinite
quotients in
intentional
setting
Type
Equality
Choice
Zmodule
Ring
Commutative Ring Unit Ring
Commutative Unit Ring
Integral Domain
Field Decidable field Closed Field
Countable
Finite
. . .
See A Modular Formaliza-
tion Of Finite Group Theory,
(TPHOLs 07)
Type
SubType
See the
paper,
§ 3.1.
4-d
Our Algebraic Hierarchy
better
composi-
tionality
Type
Equality
Choice
Zmodule
Ring
Commutative Ring Unit Ring
Commutative Unit Ring
Integral Domain
Field Decidable field Closed Field
Countable
Finite
. . .
See A Modular Formaliza-
tion Of Finite Group Theory,
(TPHOLs 07)
Type
SubType
See the
paper,
§ 3.1.
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)[
Components, objects]
6=[
APIs, interfaces]
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)[
Components, objects]
6=[
APIs, interfaces]
(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
� a constant zero : M
� an operation : add : M-> M -> M
� axiom(s) verified by add on M
associative add;
� . . .
ZModule (M:Type)
C elements per structure,
n nested (parametric) struc-
tures in which the parame-
ter occurs at every element:
term size in Cn
� 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
T
MixinEq
opzmod
axiomszmod
MixinZmodopzmod
axiomszmod
eqType
zmodType
10
Telescopes : Canonical Structure inference
2+ 2
Zmodule.add α 2 2
Equality.sort(Zmodule.sortα) ≡βιδ int
Zmodule.sortα ≡βιδ inteqType
Equality.sort (Zmodule.sort (intzmodType))
Notation
type inference
lookup (Equality.sort,int) ; inteqType
lookup (Zmodule.sort,inteqType) ; intzmodType
11
Telescopes : Canonical Structure inference
2+ 2
Zmodule.add α 2 2
Equality.sort(Zmodule.sortα) ≡βιδ int
Zmodule.sortα ≡βιδ inteqType
Equality.sort (Zmodule.sort (intzmodType))
Notation
type inference
lookup (Equality.sort,int) ; inteqType
lookup (Zmodule.sort,inteqType) ; intzmodType
� Simple packaging, but
11-a
Telescopes : Canonical Structure inference
2+ 2
Zmodule.add α 2 2
Equality.sort(Zmodule.sortα) ≡βιδ int
Zmodule.sortα ≡βιδ inteqType
Equality.sort (Zmodule.sort (intzmodType))
Notation
type inference
lookup (Equality.sort,int) ; inteqType
lookup (Zmodule.sort,inteqType) ; intzmodType
� 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
Zmodule.add α 2 2
Equality.sort(Zmodule.sortα) ≡βιδ int
Zmodule.sortα ≡βιδ inteqType
Equality.sort (Zmodule.sort (intzmodType))
Notation
type inference
lookup (Equality.sort,int) ; inteqType
lookup (Zmodule.sort,inteqType) ; intzmodType
� 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
Zmodule.add α 2 2
Equality.sort(Zmodule.sortα) ≡βιδ int
Zmodule.sortα ≡βιδ inteqType
Equality.sort (Zmodule.sort (intzmodType))
Notation
type inference
lookup (Equality.sort,int) ; inteqType
lookup (Zmodule.sort,inteqType) ; intzmodType
� 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
T
ClassEq
opeq
axiomseq
MixinZmodopzmod
axiomszmod
Classzmod
zmodType
12
Packed Classes
T
ClassEq
opeq
axiomseq
MixinZmodopzmod
axiomszmod
Classzmod
zmodType
T Classeq
ϕϕ
eqType
x : T denotes
x : (Zmodule.sort T α),
which, thanks to ϕ, has a
canonical eqType structure.
12-a
Packed Classes
2+ 2 == 4
Equality.op γ(Zmodule.add α 2 2) 4
Zmodule.sort α ≡ int︸ ︷︷ ︸
Zmodule.sort intzmodType
Equality.sort γ ≡ Zmodule.sort intzmodType
Equality.op (Zmodule.eqType(intzmodType))(Zmodule.add ...) 4
Notation
lookup(Zmodule.sort,int)
; intzmodType
lookup(Equality.sort,Zmodule.sort intzmodType)
; Zmodule.eqType(intzmodType)
4 == 2+ 2
Equality.op γ (Zmodule.add α 2 2) 4
Equality.op inteqType (Zmodule.add α 2 2) 4
...
Notation
lookup(Equality.sort,int) ; inteqType
≡βιδ
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