mathlib lean s mathematical library
play

mathlib : Leans mathematical library Johannes Hlzl VU Amsterdam - PowerPoint PPT Presentation

mathlib : Leans mathematical library Johannes Hlzl VU Amsterdam Lean Together 2019 Amsterdam Introduction what is mathlib (classical) mathematical library for Lean classical linear algebra, number theory, analysis, ... classical


  1. mathlib : Lean’s mathematical library Johannes Hölzl VU Amsterdam Lean Together 2019 Amsterdam

  2. Introduction — what is mathlib (classical) mathematical library for Lean classical – linear algebra, number theory, analysis, ... classical – using choice and LEM Formerly distributed with Lean itself Leo wanted more flexibility Some (current) topics: (Linear) Algebra, Analysis, Set Theory, Number Theory, ... Goal: be comparable to Coq’s mathematical components, Isabelle’s HOL-Analysis 1 23

  3. Development 120 , 000 100 , 000 Lines of lean Code 80 , 000 60 , 000 40 , 000 20 , 000 0 n b r r y n l g p t v c n a p u c a o e a u u e a e J O M A M D J F A S N J J Month in 2018 Repository starts July 2017 with 22.000 LoC 2 23

  4. Organization Constructions Tactics Theories 3 23

  5. Organization

  6. B asic parts tactic mathlib ’s tactics logic Lemmas about logical connectices; classical function inverse; Schröder-Bernstein; ... order Lemmas about orders; further order and lattice type classes algebra Lemmas about algebraic structures; more algebraic and order type classes, upto modules category Type category (Haskell style): Functor, Applicative, Monads, Traversable data Generic (mostly computable) types 4 23

  7. T heories set_theory Ordinals, Cardinals, a model of ZFC category_theory Category theory: functors, natural trans., limits, ... linear_algebra Modules, Vector spaces, Tensor products, Dimensions, ... analysis Analysis, Topology, Measure theory, ... group_theory Free (abelian) groups, Order of an element, ... ring_theory Principal ideal domains, ... field_theory Finite fields, perfect closure, ... computability Turing machines etc. number_theory Diophantine equations, Pell’s equation (?) 5 23

  8. data – Generic (mostly computable) types � n nat N , gcd , mod , prime , , ... � p int Z (as datatype, not quotient) rat Q (as datatype, not quotient) real R (as quotient over Cauchy sequences) equiv Isomorphism between Type fin fin n = { 0 ,..., n − 1 } set set α := α → Prop list list α multiset multiset α := list α / perm finset finset α := { m : multiset α | nodup m } ... 6 23

  9. C onstructions

  10. C onstructions – Ordered groups and rings nonneg _ comm _ group , nonneg _ ring and linear _ nonneg _ ring Helper type classes to construct ordered _ group and ordered _ ring Specify nonneg : α → Prop and (optionally) pos : α → Prop Constructs the order on the group / ring Proves the relation btw order and algebraic operations 7 23

  11. C onstructions – Adjoin ⊤ , ⊥ or 0 with _ top , with _ bot and with _ zero := option Ext. nonnneg. reals: R ≥ 0 ⊎ ∞ , extended nats N = N ⊎ ∞ Multisets with infinity (e.g. sets of factors, ∞ to represent 0) Example instances: ◮ partial _ order α → partial _ order ( with _ top α ) ◮ add _ monoid α → add _ monoid ( with _ top α ) ◮ canonically _ ordered _ comm _ semiring α → canonically _ ordered _ comm _ semiring ( with _ top α ) 8 23

  12. S tructures as Functors and Complete Lattices There are many set like structures: filter , topology , uniformity , submodule , measurable Form complete lattices, e.g. topological _ space α (Co)functors, e.g. map : ( α → β ) → ( filter α → filter β ) Exception: uniformity only cofunctor Order + comap is usually the morphism definition Used as light-weight category theory (simpler to setup, base constructions require less setup) 9 23

  13. Example: Topologies structure topo ( α : Type) := (is_open : set α → Prop) ... -- univ, ∩ , � cont : ( α → β ) → topo α → topo β → Prop cont f T 1 T 2 : ↔ ∀ s, is_open T 2 s → is_open T 1 (f − 1 ’s) ( ≤ ) : topo α → topo α → Prop T 1 ≤ T 2 : ↔ ∀ s, is_open T 1 s → is_open T 2 s map : ( α → β ) → (topo α → topo β ) − 1 ’ s) is_open (map T f) s : ↔ is_open T (f cont f T 1 T 2 : ↔ T 2 ≤ T 1 .map f 10 23

  14. Example: Generating Topologies generate : set (set α ) → topo α ∀ s ∈ g, is_open (generate g) s ∀ T, ( ∀ s ∈ g, is_open T s) → generate g ≤ T map : ( α → β ) → (topo α → topo β ) − 1 ’ s) is_open (map T f) s : ↔ is_open T (f comap : ( α → β ) → (topo β → topo α ) is_open (comap T f) s : ↔ ∃ t, is_open T t ∧ s = f − 1 ’t 11 23

  15. Example: Product of Topologies What do we want : _ × _ : topo α → topo β → topo ( α × β ) cont π 1 (T 1 × T 2 ) T 1 cont π 2 (T 1 × T 2 ) T 2 cont ( π 1 ◦ f) T T 1 → cont ( π 2 ◦ f) T T 2 → cont f T (T 1 × T 2 ) Traditional definition : T 1 × T 2 = generate {s × t | is_open T 1 s ∧ is_open T 2 t} Generic definition (set, filter, topology, σ -algebra): T 1 × T 2 = comap π 1 T 1 ⊔ comap π 2 T 2 12 23

  16. Example: Lattice Structure on Topologies Supremum as generating by the union: T 1 ⊔ T 2 = generate {s | is_open T 1 s ∨ is_open T 2 t} P roblem : Proof that it is a supremum. Define directly complete lattice over topologies: � � � s � is _ open T s � � T = � T ∈ T Problem : we might want different def eq for ⊤ , ⊓ , and � . Solution : Use Galois insertion (extending a Galois connection) to get the complete lattice structure 13 23

  17. C onstructions N T N := ⊤ Indiscrete ⊥ Sum T α ⊕ T β := map ι 1 T α ⊓ map ι 2 T β def = { s | open ( ι − 1 1 [ s ]) ∧ open ( ι − 1 2 [ s ]) } Product T α × T β := comap π 1 T α ⊔ comap π 2 T β Pi ∏ i T α i := � i comap ( λω , ω i ) T α i Sigma Σ i T α i := � i map ( λ a , ( i , a )) T α i List (not done yet) list T α := lfp ( λ T , T () ⊕ T α × T ) list T α := gfp ( λ T , T () ⊕ T α × T ) 14 23

  18. T actics and Commands

  19. T heories

  20. mathlib Basic (computable) data Type class hierarchies: Orders orders, lattices Algebraic (commutative) groups, rings, fields Spaces measurable, topological, uniform, metric Cardinals & ordinals Analysis: topology, measure theory, ... Linear algebra Group / ring / field theory Number theory 15 23

  21. Cardinals and Ordinals Definition (Equivalence, Cardinals and Ordinals) structure α ≃ β := ( f : α → β ) ( g : β → α ) ( f _ g : f ◦ g = id ) ( g _ f : g ◦ f = id ) cardinal u Type u + 1 Type u / ≃ : := ordinal u Type u + 1 Well _ order u / ≃ ord : := Well-ordered, semiring, etc... Semiring structure of cardinal from ≃ constructions κ + κ = κ = κ ∗ κ (for κ ≥ ω ) Existence of inaccessible cardinals (i.e. in the next universe) Application: Dimension of subspaces 16 23

  22. Number Theory p - adic numbers Q p by Rob Y. Lewis Cauchy construction of Q "in the other direction" Interesting result: Hensel’s lemma (see Rob’s talk) Quadratic Reciprocity by Chris Hughes ( ∼ 1300 lines patch) theorem quadratic_reciprocity (hp : prime p) (hq : prime q) (hpq : p � = q) (hp1 : p % 2 = 1) (hq1 : q % 2 = 1) : legendre p q hq * legendre q p hp = (-1) ^ (p/2 * q/2) 17 23

  23. Analysis F ilter generalizes limits (derived from Isabelle/HOL) Topology nhds filter, open & closed & compact sets, interior, closure Uniformity complete, totally bounded, completion compact ↔ complete & totally bounded Metric instance of uniformities Norm only rudimentary (no deriviatives yet...) Measure Lebesgue measure etc... 18 23

  24. Analysis: Constructing Reals Construct R using completion of Q For foundational reasons metric completion is not possible (alt: α → α → Q → Prop , c.f. Krebbers & Spitters) Formalize uniform spaces (using the filter library!) Use completion on the uniform space Q Is it worth it? Mario went back to Cauchy sequences... Anyway: R as order & topologically complete field 19 23

  25. Measure Theory (Outer) Measures structure outer_measure ( α : Type*) := ( µ : set α → ennreal) ... structure measure ( α ) [measurable_space α ] extends outer_measure α := ... Outer measures provide natural totalization of measures Carathéodory’s extension theorem Lebesgue Measure Completion measurable space 20 23

  26. P robability Theory def pmf ( α ) := { f : α → nnreal // is_sum f 1 } def pure (a : α ) : pmf α := � λ a’, if a’ = a then 1 else 0, is_sum_ite _ _ � def bind (p : pmf α ) (f : α → pmf β ) : pmf β := � λ b, ( ∑ a, p a * f a b), ... � prove rules of the Giry monad generality of ∑ helps! 21 23

  27. Analysis: Infinite Sum Definition (Infinite sum) f i f i ∑ s → at _ top ∑ = lim i : ι i ∈ s Assuming: f : ι → α , [ topological _ add _ monoid α ] at _ top : filter ( finset ι ) finite sets approaching univ : set ι R , normed vector spaces, ennreal , Q , N , Z , ... ∑ b ∑ c f ( b , c ) = ∑ ( b , c ) f ( b , c ) — α regular ∑ n : N f n = lim i → ∞ ∑ i n = 0 f n 22 23

  28. Linear Algebra Definition (Module) class module ( α : out_param (Type u)) ( β : Type v) [out_param (ring α )] [add_comm_group β ] extends semimodule α β C onstr.: Subspace, Linear maps, Quotient, Product, Tensor Product Dim.: dim ( β ) [vector_space α β ] : cardinal Laws: dom ( f ) s ∩ t ≃ ℓ s ⊕ t s ker ( f ) ≃ ℓ im ( f ) t R ⊕ M ≃ ℓ M M ⊕ N ≃ ℓ N ⊕ M M ⊕ ( N ⊕ L ) ≃ ℓ ( M ⊕ N ) ⊕ L 23 / 23

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend