Validating Mathematical Structures
Kazuhiko Sakaguchi
University of Tsukuba
Validating Mathematical Structures Kazuhiko Sakaguchi University of - - PowerPoint PPT Presentation
Validating Mathematical Structures Kazuhiko Sakaguchi University of Tsukuba The Coq Workshop 2019 @ Portland Packed classes Packaging Mathematical Structures [Garillot et al. 2009] Packed classes are generic design patterns to define and
University of Tsukuba
Packaging Mathematical Structures [Garillot et al. 2009]
◮ multiple inheritance, ◮ maximal sharing of notations and theories, and ◮ automated structure inference.
2 / 16
Packaging Mathematical Structures [Garillot et al. 2009]
◮ multiple inheritance, ◮ maximal sharing of notations and theories, and ◮ automated structure inference:
◮ requires a lot of unification hints in the form of canonical
◮ E.g., MathComp 1.9.0:
2 / 16
Packaging Mathematical Structures [Garillot et al. 2009]
Choice Countable GRing.Zmodule CountRing.Zmodule Finite GRing.Lmodule GRing.Ring CountRing.ComRing CountRing.ComUnitRing FinRing.ComRing CountRing.IntegralDomain FinRing.ComUnitRing CountRing.Field FinRing.IntegralDomain CountRing.DecidableField CountRing.ClosedField FinRing.Field CountRing.Ring CountRing.UnitRing FinRing.Ring FinRing.UnitRing FinRing.Lalgebra FinRing.UnitAlgebra FinRing.Zmodule FinRing.Lmodule FinGroup Equality Falgebra FieldExt SplittingField FinRing.Algebra GRing.Algebra GRing.UnitAlgebra GRing.ClosedField Num.ClosedField GRing.ComRing GRing.ComUnitRing GRing.IntegralDomain GRing.Field Num.NumDomain GRing.DecidableField Num.NumField Num.RealField Num.RealDomain GRing.Lalgebra Vector GRing.UnitRing Num.ArchimedeanField Num.RealClosedField
2 / 16
3 / 16
3 / 16
4 / 16
4 / 16
4 / 16
zero : ∀ A : Monoid.type, A add : ∀ A : Monoid.type, A → A → A
mul : ∀ A : Semiring.type, A → A → A
Monoid.sort Semiring.sort Group.sort Ring.sort
Ring.semiringType Ring.groupType Ring.monoidType Semiring.monoidType Group.monoidType
5 / 16
zero : ∀ A : Monoid.type, A add : ∀ A : Monoid.type, A → A → A
mul : ∀ A : Semiring.type, A → A → A
Monoid.sort Semiring.sort Group.sort Ring.sort
Ring.semiringType Ring.groupType Ring.monoidType Semiring.monoidType Group.monoidType
5 / 16
zero : ∀ A : Monoid.type, A add : ∀ A : Monoid.type, A → A → A
mul : ∀ A : Semiring.type, A → A → A
Monoid.sort Semiring.sort Group.sort Ring.sort
Ring.semiringType Ring.groupType Ring.monoidType Semiring.monoidType Group.monoidType
5 / 16
zero : ∀ A : Monoid.type, A add : ∀ A : Monoid.type, A → A → A
mul : ∀ A : Semiring.type, A → A → A
Monoid.sort Semiring.sort Group.sort Ring.sort
Ring.semiringType Ring.groupType Ring.monoidType Semiring.monoidType Group.monoidType
5 / 16
zero : ∀ A : Monoid.type, A add : ∀ A : Monoid.type, A → A → A
mul : ∀ A : Semiring.type, A → A → A
Monoid.sort Semiring.sort Group.sort Ring.sort
Semiring.sort (Ring.semiringType T)
Ring.semiringType Ring.groupType Ring.monoidType Semiring.monoidType Group.monoidType
5 / 16
zero : ∀ A : Monoid.type, A add : ∀ A : Monoid.type, A → A → A
mul : ∀ A : Semiring.type, A → A → A
Monoid.sort Semiring.sort Group.sort Ring.sort
Semiring.sort (Ring.semiringType T)
Ring.semiringType Ring.groupType Ring.monoidType Semiring.monoidType Group.monoidType
5 / 16
◮ If a structure B (transitively) inherits a structure A, we should
◮ Transitive ones can be automatically computed by Coq, but we declare
6 / 16
◮ If a structure B (transitively) inherits a structure A, we should
◮ Transitive ones can be automatically computed by Coq, but we declare
◮ There are ambiguous paths for multiple inheritances, e.g.,
◮ If we use packed classes correctly, these ambiguous paths will be
6 / 16
◮ We had no systematic way to detect inconvertible ambiguous
◮ We have relaxed the condition of ambiguous paths by
◮ This ambiguity checking is nontrivial in general, but we found that it’s
7 / 16
8 / 16
Monoid.sort ?1 → Monoid.sort ?1
8 / 16
Monoid.sort ?1 → Monoid.sort ?1
Monoid.sort ?1 = Semiring.sort ?2
8 / 16
Monoid.sort ?1 → Monoid.sort ?1
Monoid.sort ?1 = Semiring.sort ?2
8 / 16
8 / 16
Group.sort ?3 → Group.sort ?3
8 / 16
Group.sort ?3 → Group.sort ?3
Group.sort ?3 = Semiring.sort ?4
8 / 16
Group.sort ?3 → Group.sort ?3
Group.sort ?3 = Semiring.sort ?4
8 / 16
◮ To solve a unification problem A.sort _ = B.sort _, we need to
◮ C must be a maximal common subclass of A and B. ◮ C is A if A inherits B, and is B if B inherits A. ◮ C is undefined if A and B have no common subclass.
◮ For any two structures, their join must be unique.
◮ For a given inheritance diagram, we can validate this property and
◮ Generated assertions can be checked by Ltac script. 9 / 16
◮ The structures A and B have two maximal
◮ Which structure should be inferred from
◮ If C is inferred as their join, it can never be D, and
10 / 16
◮ The structures A and B have two maximal
◮ Which structure should be inferred from
◮ If C is inferred as their join, it can never be D, and
◮ We must disambiguate it by declaring an
10 / 16
11 / 16
◮ Line 4 asserts that “the join of groups and semirings are rings.”
11 / 16
◮ Line 4 asserts that “the join of groups and semirings are rings.” ◮ Lines 2 and 5 are symmetric ones.
11 / 16
/* T is the set of all the common subclasses of t1 and t2. */
*/
*/
*/
12 / 16
◮ We found and fixed many inheritance bugs in MathComp.
◮ finalg structures didn’t inherit countalg structures. It made many joins
◮ The finType instance of extremal_group wrongly overwrites the join of
13 / 16
◮ Automating structure/inheritance declarations by
14 / 16
François Garillot, Georges Gonthier, Assia Mahboubi, and Laurence Rideau. “Packaging Mathematical Structures”. In: TPHOLs ’09. Vol. 5674. LNCS. Springer, 2009,
Assia Mahboubi and Enrico Tassi. “Canonical Structures for the Working Coq User”. In: ITP ’13. Vol. 7998. LNCS. Springer, 2013, pp. 19–34.
15 / 16
16 / 16
16 / 16