lesson_3
From mathcomp Require Import all_ssreflect all_algebra.
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Definition sorry {T} : T. Admitted.
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Definition sorry {T} : T. Admitted.
Advanced Topics
- deep specification
- user interfaces, notations, interactive books
- collaborative development / ecosystem / impact
- proof automation / Machine Learning
- higher mathematical structures / HoTT (Homotophy Type Theory)
- proof by refinement
- advanced program logics
- models, axioms, proof relevance
The Mathematical Components Library
- https://math-comp.github.io/
- Developed first for the 4 color theorem, then for the Feit-Thompsom proof.
- High-quality, large set of advanced techniques and theorems
- Large development effort, co-development with Coq, refactoring very costly
- Powerful but lacking documentation thus it feels hard to use
- Indeed, it is not a straightforward step for a mathematician.
Lean's mathlib
- https://leanprover-community.github.io/mathlib_docs/
- Lean is a recent re-implementation of Coq's type theory by Leo de Moura and collaborators
- Type theories almost compatible, front-ends follow the same spirit, but significant differences.
- Built on many ideas from math-comp
- Made very popular for mathematicians thanks to great communication and community.
- Math marketing effort mainly led by Kevin Buzzard
- New version (Lean 4) vs mathlib (Lean 3)
- It is also not a straightforward step for a mathematician.
- https://xenaproject.wordpress.com/2021/06/05/half-a-year-of-the-liquid-tensor-experiment-amazing-developments/
Challenges of doing mathematics in type theory
- general usability: search, tactics, documentation, notations
- organization of mathematical structures: base type theory is not well-suited for encoding complex mathematical
Plan + an example:
Lemma prime_above m : {p | m < p & prime p}.
have /pdivP[p pr_p p_dv_m1]: 1 < m`! + 1 by rewrite addn1 ltnS fact_gt0.
∃ p ⇒ //; rewrite ltnNge; apply: contraL p_dv_m1 ⇒ p_le_m.
by rewrite dvdn_addr ?dvdn_fact ?prime_gt0 // gtnNdvd ?prime_gt1.
Qed.
have /pdivP[p pr_p p_dv_m1]: 1 < m`! + 1 by rewrite addn1 ltnS fact_gt0.
∃ p ⇒ //; rewrite ltnNge; apply: contraL p_dv_m1 ⇒ p_le_m.
by rewrite dvdn_addr ?dvdn_fact ?prime_gt0 // gtnNdvd ?prime_gt1.
Qed.
Base useful libraries
- eqType, choiceType: types with choice and decidable equality
- nat: mathcomp's Peano numbers + their large theory, including modular arithmetic, prime numbers, etc...
- seq A: mathcomp's lists (or sequences) + their large theory
- finType: finite types
- orderType: types with different orders
- subType P A: subTypes of A convertibles to A. For example the set of all even natural numbers: { x : nat | even x }.
- ordinals 'I_n, in particular 'I_n := { x : nat | x < n }
- tuples n-tuple A, lists of size n, or tuples
- {ffun T → U} finitely supported functions (a tuple of cardinality #|T| .
Axiom funext : ∀ T U (f g : T → U), (∀ x, f x = g x) → f = g.
However, a lot of reasoning in mathematics depends on this being true.
mathcomp is pretty careful as to use datatypes that validate this principle,
for example finitely supported functions are implemented in a way such
that we can prove extensionality
Section ExtIntro.
Variable (T : finType) (U : Type).
Lemma ffun_ext_show (f g : {ffun T → U}) : f = g.
Proof. apply/ffunP. move⇒ x. Abort.
Variable (T : finType) (U : Type).
Lemma ffun_ext_show (f g : {ffun T → U}) : f = g.
Proof. apply/ffunP. move⇒ x. Abort.
Finite sets do validate this principle too
Lemma fset_ext_show (A B : {set T}) : A = B.
Proof. apply/setP. move⇒ x. Abort.
End ExtIntro.
Proof. apply/setP. move⇒ x. Abort.
End ExtIntro.
Mathematical Structures
Canonical Structures
Coercions
Status in Coq
Algebra
Open Scope ring_scope.
Import GRing.Theory.
Section AEx.
Variable (A : zmodType).
Import GRing.Theory.
Section AEx.
Variable (A : zmodType).
zmodType is the type of Abelian groups over choiceTypes:
Record mixin_of (V : Type) : Type := Mixin {
zero : V;
opp : V → V;
add : V → V → V;
_ : associative add;
_ : commutative add;
_ : left_id zero add;
_ : left_inverse zero opp add
}.
- The operators exported are [0] [x + y] [- x] , a few derived ones are defined too, like [x *+ n].
- Suffix for theory is [r], so [addr0], [addrA], etc...
Record mixin_of (V : Type) : Type := Mixin {
zero : V;
opp : V → V;
add : V → V → V;
_ : associative add;
_ : commutative add;
_ : left_id zero add;
_ : left_inverse zero opp add
}.
- The operators exported are [0] [x + y] [- x] , a few derived ones are defined too, like [x *+ n].
- Suffix for theory is [r], so [addr0], [addrA], etc...
Lemma demo_A (x y : A) : x + y + 0 = y + 0 + x.
Proof. Admitted.
Variable (R : ringType).
ringType: (non-commutative) rings over a commutative abelian group
Lemma demo_R (x y : R) : x + y + 0 = y + 0 + x.
Proof. Admitted.
Variable (C : comRingType).
Lemma demo_C (x y : C) : x + y + 0 = y + 0 + x.
Proof. Admitted.
Variable (L : lmodType R).
Lemma demo_l (a : R) (x y : L) : a *: (x + y) = a *: x + a *:y.
Proof. Admitted.
End AEx.
Big Operators
Lemma big_swap_(A : zmodType) (x y : A → A) i l : \sum_(i <- l) x i + y i = \sum_(i <- l) y i + x i.
Proof. Admitted.
Proof. Admitted.
Matrices
Lemma matrix_1 :
let A : 'M[nat]_(2,2) := \matrix_(i < 2, j < 2) (i + j)%nat in
let B : 'M[nat]_(2,2) := \matrix_(i < 2, j < 2) (i + j)%nat in
A = B.
Proof. Admitted.
Lemma matrix_struct_1 (T : zmodType) n m (A B : 'M[T]_(n,m)) : A + B = B + A.
Proof. Admitted.
Lemma matrix_struct_1' (T : zmodType) n m (A B : 'M[T]_(n,m)) : A + B = B + A.
Proof. Admitted.
Lemma matrix_struct_2 (T : ringType) n (A B C : 'M[T]_(n.+1,n.+1)) : A × B × C = A × (B × C).
Proof. Admitted.
Lemma tr_tr (T : zmodType) m n (A : 'M[T]_(n,m)) : A = A^T^T.
Proof. Admitted.
Polynomials
- 'X^i is the variable
- p.i is evaluation (Horner scheme)
- polynomials have the corresponding ring structure
Lemma poly_1 (A : ringType) (x y z : A) :
(Poly [:: x; y; z])`_1 = y.
Proof. by rewrite coef_Poly. Admitted.
Lemma poly_2 (A : ringType) (p q : {poly A}) : p + q = q + p.
Proof. Admitted.
(Poly [:: x; y; z])`_1 = y.
Proof. by rewrite coef_Poly. Admitted.
Lemma poly_2 (A : ringType) (p q : {poly A}) : p + q = q + p.
Proof. Admitted.