├── lean-toolchain ├── website ├── .bundle │ └── config ├── assets │ ├── favicon.ico │ └── css │ │ └── style.scss ├── .gitignore ├── 404.html ├── Gemfile ├── upstreaming.md ├── _config.yml ├── _layouts │ └── default.html └── Gemfile.lock ├── blueprint ├── src │ ├── content.tex │ ├── plastex.cfg │ ├── print.tex │ ├── web.tex │ └── extra_styles.css ├── .gitignore └── tasks.py ├── .gitignore ├── LeanCamCombi ├── Mathlib │ ├── Combinatorics │ │ ├── SetFamily │ │ │ └── LYM.lean │ │ ├── SimpleGraph │ │ │ └── Density.lean │ │ └── Additive │ │ │ └── ApproximateSubgroup.lean │ └── Probability │ │ ├── HasLaw.lean │ │ ├── Distributions │ │ └── Bernoulli.lean │ │ └── Combinatorics │ │ └── BinomialRandomGraph │ │ └── Defs.lean ├── ExtrProbCombi │ ├── GiantComponent.lean │ ├── Connectivity.lean │ └── BollobasContainment.lean ├── Util.lean ├── StableCombi │ ├── AddSet.lean │ ├── Rel.lean │ └── Formula.lean ├── PlainCombi │ ├── ProbLYM.lean │ ├── OrderShatter.lean │ ├── LittlewoodOfford.lean │ └── VanDenBergKesten.lean ├── GrowthInGroups │ ├── Lecture4.lean │ ├── Lecture3.lean │ ├── Lecture2.lean │ └── Lecture1.lean └── GraphTheory │ ├── ExampleSheet2.lean │ └── ExampleSheet1.lean ├── .vscode ├── settings.json └── copyright.code-snippets ├── .github └── workflows │ ├── lean-release-tag.yml │ └── push.yml ├── .gitpod.yml ├── lakefile.toml ├── LeanCamCombi.lean ├── tasks.py ├── lake-manifest.json ├── scripts └── upstreaming_dashboard.py ├── README.md └── LICENSE /lean-toolchain: -------------------------------------------------------------------------------- 1 | leanprover/lean4:v4.26.0 -------------------------------------------------------------------------------- /website/.bundle/config: -------------------------------------------------------------------------------- 1 | --- 2 | BUNDLE_PATH: "vendor/bundle" 3 | -------------------------------------------------------------------------------- /blueprint/src/content.tex: -------------------------------------------------------------------------------- 1 | This is the LeanCamCombi blueprint. 2 | This file is content.tex. 3 | -------------------------------------------------------------------------------- /website/assets/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YaelDillies/LeanCamCombi/HEAD/website/assets/favicon.ico -------------------------------------------------------------------------------- /blueprint/.gitignore: -------------------------------------------------------------------------------- 1 | *.pdf 2 | *.paux 3 | *.aux 4 | *.log 5 | print 6 | web 7 | __pycache__ 8 | *.fdb_latexmk 9 | *.fls 10 | *.out 11 | *.synctex.gz 12 | *.xdv 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.olean 3 | /_target 4 | /.lake 5 | /doc-gen 6 | /build 7 | /lake-packages 8 | /leanpkg.path 9 | 10 | decls.pickle 11 | decls.yaml 12 | src/all.lean 13 | src/list_decls.lean 14 | src/.noisy_files 15 | -------------------------------------------------------------------------------- /LeanCamCombi/Mathlib/Combinatorics/SetFamily/LYM.lean: -------------------------------------------------------------------------------- 1 | import Mathlib.Combinatorics.SetFamily.LYM 2 | 3 | /-! 4 | # TODO 5 | 6 | * Use semantic naming convention instead of symbol-reading 7 | * Add the `∑ s ∈ 𝒜, ((card α).choose #s)⁻¹ ≤ 1` variant 8 | -/ 9 | -------------------------------------------------------------------------------- /website/.gitignore: -------------------------------------------------------------------------------- 1 | _site 2 | .sass-cache 3 | .jekyll-cache 4 | .jekyll-metadata 5 | vendor 6 | blueprint/ 7 | blueprint.pdf 8 | docs/ 9 | 10 | # Noisy files that are generated by CI. 11 | _includes/ready_to_upstream.md 12 | _includes/easy_to_unlock.md 13 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.insertSpaces": true, 3 | "editor.tabSize": 2, 4 | "editor.rulers" : [100], 5 | "files.encoding": "utf8", 6 | "files.eol": "\n", 7 | "files.insertFinalNewline": true, 8 | "files.trimFinalNewlines": true, 9 | "files.trimTrailingWhitespace": true, 10 | } 11 | -------------------------------------------------------------------------------- /blueprint/src/plastex.cfg: -------------------------------------------------------------------------------- 1 | [general] 2 | renderer=HTML5 3 | copy-theme-extras=yes 4 | plugins=leanblueprint 5 | 6 | [document] 7 | toc-depth=2 8 | toc-non-files=True 9 | 10 | [files] 11 | directory=../web/ 12 | split-level=0 13 | 14 | [html5] 15 | localtoc-level=0 16 | extra-css=extra_styles.css 17 | mathjax-dollars=True 18 | -------------------------------------------------------------------------------- /LeanCamCombi/ExtrProbCombi/GiantComponent.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Copyright (c) 2023 Yaël Dillies. All rights reserved. 3 | Released under Apache 2.0 license as described in the file LICENSE. 4 | Authors: Yaël Dillies 5 | -/ 6 | import LeanCamCombi.Mathlib.Probability.Combinatorics.BinomialRandomGraph.Defs 7 | 8 | /-! 9 | # The giant component 10 | -/ 11 | -------------------------------------------------------------------------------- /website/assets/css/style.scss: -------------------------------------------------------------------------------- 1 | --- 2 | --- 3 | 4 | @import "{{ site.theme }}"; 5 | 6 | .page-header { 7 | background-image: linear-gradient(120deg, #2d4fdc, #dc2ddc); 8 | } 9 | 10 | .main-content h1, 11 | .main-content h2, 12 | .main-content h3, 13 | .main-content h4, 14 | .main-content h5, 15 | .main-content h6 { 16 | color: #6f1599; 17 | } 18 | -------------------------------------------------------------------------------- /blueprint/src/print.tex: -------------------------------------------------------------------------------- 1 | \documentclass[a4paper]{report} 2 | 3 | \usepackage{amsmath,amsfonts,amsthm,amssymb} 4 | \usepackage[textwidth=14cm]{geometry} 5 | \usepackage[capitalize]{cleveref} 6 | 7 | \title{LeanCamCombi} 8 | \author{LeanCamCombi project contributors} 9 | 10 | \begin{document} 11 | \maketitle 12 | \input{content} 13 | \end{document} 14 | -------------------------------------------------------------------------------- /.vscode/copyright.code-snippets: -------------------------------------------------------------------------------- 1 | { 2 | "Copyright header for mathlib": { 3 | "scope": "lean4", 4 | "prefix": "copyright", 5 | "body": [ 6 | "/-", 7 | "Copyright (c) ${CURRENT_YEAR} $1. All rights reserved.", 8 | "Released under Apache 2.0 license as described in the file LICENSE.", 9 | "Authors: $1", 10 | "-/" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /LeanCamCombi/ExtrProbCombi/Connectivity.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Copyright (c) 2023 Yaël Dillies. All rights reserved. 3 | Released under Apache 2.0 license as described in the file LICENSE. 4 | Authors: Yaël Dillies 5 | -/ 6 | import LeanCamCombi.Mathlib.Probability.Combinatorics.BinomialRandomGraph.Defs 7 | 8 | /-! 9 | # Connectivity of the Erdős–Rényi model 10 | -/ 11 | -------------------------------------------------------------------------------- /.github/workflows/lean-release-tag.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - 'main' 5 | - 'master' 6 | paths: 7 | - 'lean-toolchain' 8 | 9 | jobs: 10 | lean-release-tag: 11 | name: Add Lean release tag 12 | runs-on: ubuntu-latest 13 | permissions: 14 | contents: write 15 | steps: 16 | - name: lean-release-tag action 17 | uses: leanprover-community/lean-release-tag@9ca7ed09e240259871327bfc3a3a8d8c4bcb41aa 18 | with: 19 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 20 | -------------------------------------------------------------------------------- /blueprint/src/web.tex: -------------------------------------------------------------------------------- 1 | \documentclass{report} 2 | 3 | \usepackage{amsmath,amsfonts,amsthm,amssymb} 4 | \usepackage{hyperref} 5 | \usepackage{graphicx} 6 | \DeclareGraphicsExtensions{.svg,.png,.jpg} 7 | \usepackage[capitalize]{cleveref} 8 | \usepackage[showmore, dep_graph, coverage, project=../../]{blueprint} 9 | 10 | \github{https://github.com/YaelDillies/LeanCamCombi/} 11 | 12 | \title{LeanCamCombi} 13 | \author{LeanCamCombi project contributors} 14 | 15 | \begin{document} 16 | \maketitle 17 | \input{content} 18 | \end{document} 19 | -------------------------------------------------------------------------------- /website/404.html: -------------------------------------------------------------------------------- 1 | --- 2 | permalink: /404.html 3 | layout: default 4 | --- 5 | 6 | 19 | 20 |
21 |

404

22 | 23 |

Page not found :(

24 |

The requested page could not be found.

25 |
26 | -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | # This is run when starting a Gitpod workspace on this repository 2 | 3 | image: leanprovercommunity/gitpod4 4 | 5 | vscode: 6 | extensions: 7 | - leanprover.lean4 # install the Lean 4 VS Code extension 8 | 9 | tasks: 10 | - init: | 11 | elan self update 12 | lake exe cache get 13 | lake build 14 | sudo apt-get update 15 | sudo apt install ruby ruby-dev -y 16 | sudo gem install bundler 17 | cp README.md website/index.md 18 | mkdir -p website/_includes 19 | python3 scripts/upstreaming_dashboard.py 20 | python3 scripts/import_graph.py 21 | cd website 22 | bundle install 23 | cd .. 24 | -------------------------------------------------------------------------------- /LeanCamCombi/Util.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Copyright (c) 2024 Yaël Dillies. All rights reserved. 3 | Released under Apache 2.0 license as described in the file LICENSE. 4 | Authors: Yaël Dillies 5 | -/ 6 | 7 | /-! 8 | # Utilities for course statements 9 | 10 | Sometimes a course states a result much earlier than it proves it, or states a theorem that won't be 11 | proved in the course. 12 | -/ 13 | 14 | /-- This theorem is proved later in this course. -/ 15 | axiom proved_later {P : Prop} : P 16 | 17 | /-- This theorem is not proved in this course but will be used. -/ 18 | axiom blackboxed {P : Prop} : P 19 | 20 | /-- This theorem is not proved in this course and won't be used. -/ 21 | axiom showcased {P : Prop} : P 22 | -------------------------------------------------------------------------------- /LeanCamCombi/Mathlib/Probability/HasLaw.lean: -------------------------------------------------------------------------------- 1 | import Mathlib.Probability.HasLaw 2 | 3 | open MeasureTheory 4 | 5 | namespace ProbabilityTheory 6 | variable {Ω 𝓧 : Type*} {mΩ : MeasurableSpace Ω} {m𝓧 : MeasurableSpace 𝓧} {X Y : Ω → 𝓧} 7 | {μ : Measure 𝓧} {P : Measure Ω} 8 | 9 | attribute [fun_prop] HasLaw HasLaw.aemeasurable 10 | 11 | lemma hasLaw_congr (hXY : X =ᵐ[P] Y) : HasLaw X μ P ↔ HasLaw Y μ P where 12 | mp h := h.congr hXY.symm 13 | mpr h := h.congr hXY 14 | 15 | protected lemma HasLaw.ae_iff (hX : HasLaw X μ P) {p : 𝓧 → Prop} (hp : Measurable p) : 16 | (∀ᵐ ω ∂P, p (X ω)) ↔ ∀ᵐ x ∂μ, p x := by 17 | rw [← hX.map_eq, ae_map_iff hX.aemeasurable (measurableSet_setOf.2 hp)] 18 | 19 | end ProbabilityTheory 20 | -------------------------------------------------------------------------------- /lakefile.toml: -------------------------------------------------------------------------------- 1 | name = "LeanCamCombi" 2 | keywords = ["math", "combinatorics", "additive-combinatorics", "probabilitistic-combinatorics", "extremal-combinatorics", "set-family", "graph-theory", "model-theory"] 3 | defaultTargets = ["LeanCamCombi"] 4 | 5 | [leanOptions] 6 | # Pretty-prints `fun a ↦ b` 7 | pp.unicode.fun = true 8 | # Don't assume a typo is a new variable 9 | autoImplicit = false 10 | relaxedAutoImplicit = false 11 | # Enable all mathlib linters: automatically matches what mathlib uses. 12 | weak.linter.mathlibStandardSet = true 13 | # Switch off warnings generated by `sorry` 14 | warn.sorry = false 15 | 16 | [[require]] 17 | name = "mathlib" 18 | git = "https://github.com/leanprover-community/mathlib4.git" 19 | rev = "v4.26.0" 20 | 21 | [[lean_lib]] 22 | name = "LeanCamCombi" 23 | -------------------------------------------------------------------------------- /LeanCamCombi/Mathlib/Combinatorics/SimpleGraph/Density.lean: -------------------------------------------------------------------------------- 1 | import Mathlib.Algebra.Field.Rat 2 | import Mathlib.Combinatorics.SimpleGraph.Subgraph 3 | 4 | /-! 5 | # TODO 6 | 7 | Rename `edgeDensity` to `edgeDensityBtw` 8 | -/ 9 | 10 | open Finset 11 | 12 | namespace SimpleGraph 13 | variable {α : Type*} [Fintype α] (G : SimpleGraph α) [Fintype G.edgeSet] 14 | 15 | /-- The edge density of a simple graph is its number of edges divided by its number of vertices. 16 | 17 | In other words, it is half of its average degree. -/ 18 | def edgeDensity' : ℚ≥0 := #G.edgeFinset / Fintype.card α 19 | 20 | open scoped Classical in 21 | /-- The maximum edge density of a subgraph of a graph. -/ 22 | noncomputable def maxEdgeSubdensity : ℚ≥0 := 23 | univ.sup' univ_nonempty fun G' : G.Subgraph ↦ G'.coe.edgeDensity' 24 | 25 | end SimpleGraph 26 | -------------------------------------------------------------------------------- /website/Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | # To upgrade, run `bundle update github-pages`. 4 | gem "github-pages", group: :jekyll_plugins 5 | # If you have any plugins, put them here! 6 | group :jekyll_plugins do 7 | #gem "jekyll-feed", "~> 0.12" 8 | end 9 | 10 | # Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem 11 | # and associated library. 12 | platforms :mingw, :x64_mingw, :mswin, :jruby do 13 | gem "tzinfo", "~> 1.2" 14 | gem "tzinfo-data" 15 | end 16 | 17 | # Performance-booster for watching directories on Windows. 18 | gem "wdm", "~> 0.1.1", :platforms => [:mingw, :x64_mingw, :mswin] 19 | 20 | # Lock `http_parser.rb` gem to `v0.6.x` on JRuby builds since newer versions of the gem 21 | # do not have a Java counterpart. 22 | gem "http_parser.rb", "~> 0.6.0", :platforms => [:jruby] 23 | 24 | # Used for locally serving the website. 25 | gem "webrick", "~> 1.7" 26 | -------------------------------------------------------------------------------- /website/upstreaming.md: -------------------------------------------------------------------------------- 1 | # Upstreaming dashboard 2 | 3 | The eventual goal of the LeanCamCombi project is to not contain any significant new formalisation, but instead to act as a shallow layer over [Mathlib](https://github.com/leanprover-community/mathlib4) showing concretely how to turn paper-combinatorics into Lean-combinatorics. 4 | 5 | As such, it is crucial to continuously upstream code from LeanCamCombi to Mathlib. The way we organise this is with the following two lists, showing files with no LeanCamCombi dependencies depending on whether they contain the keyword `sorry` or not. 6 | 7 | ## Files ready to upstream 8 | 9 | The following files are `sorry`-free and do not depend on any other LeanCamCombi, meaning they can be readily PRed to Mathlib. 10 | 11 | {% include ready_to_upstream.md %} 12 | 13 | ## Files easy to unlock 14 | 15 | The following files do not depend on any other LeanCamCombi file but still contain `sorry`, usually indicating that working on eliminating those sorries might unblock some part of the project. 16 | 17 | {% include easy_to_unlock.md %} 18 | -------------------------------------------------------------------------------- /LeanCamCombi.lean: -------------------------------------------------------------------------------- 1 | import LeanCamCombi.ExtrProbCombi.BollobasContainment 2 | import LeanCamCombi.ExtrProbCombi.Connectivity 3 | import LeanCamCombi.ExtrProbCombi.GiantComponent 4 | import LeanCamCombi.GraphTheory.ExampleSheet1 5 | import LeanCamCombi.GraphTheory.ExampleSheet2 6 | import LeanCamCombi.GrowthInGroups.Lecture1 7 | import LeanCamCombi.GrowthInGroups.Lecture2 8 | import LeanCamCombi.GrowthInGroups.Lecture3 9 | import LeanCamCombi.GrowthInGroups.Lecture4 10 | import LeanCamCombi.Mathlib.Combinatorics.Additive.ApproximateSubgroup 11 | import LeanCamCombi.Mathlib.Combinatorics.SetFamily.LYM 12 | import LeanCamCombi.Mathlib.Combinatorics.SimpleGraph.Density 13 | import LeanCamCombi.Mathlib.Probability.Combinatorics.BinomialRandomGraph.Defs 14 | import LeanCamCombi.Mathlib.Probability.Distributions.Bernoulli 15 | import LeanCamCombi.Mathlib.Probability.HasLaw 16 | import LeanCamCombi.PlainCombi.LittlewoodOfford 17 | import LeanCamCombi.PlainCombi.OrderShatter 18 | import LeanCamCombi.PlainCombi.ProbLYM 19 | import LeanCamCombi.PlainCombi.VanDenBergKesten 20 | import LeanCamCombi.StableCombi.AddSet 21 | import LeanCamCombi.StableCombi.Formula 22 | import LeanCamCombi.StableCombi.Rel 23 | import LeanCamCombi.Util 24 | -------------------------------------------------------------------------------- /blueprint/src/extra_styles.css: -------------------------------------------------------------------------------- 1 | div.theorem_thmcontent { 2 | border-left: .15rem solid black; 3 | } 4 | 5 | div.proposition_thmcontent { 6 | border-left: .15rem solid black; 7 | } 8 | 9 | div.lemma_thmcontent { 10 | border-left: .1rem solid black; 11 | } 12 | 13 | div.corollary_thmcontent { 14 | border-left: .1rem solid black; 15 | } 16 | 17 | div.proof_content { 18 | border-left: .08rem solid grey; 19 | } 20 | 21 | figure.subfloat span.subref { 22 | display: none; 23 | } 24 | 25 | nav.local_toc ul { 26 | font-size: 1.2rem; 27 | } 28 | 29 | @media (min-width:1024px) { 30 | nav.toc { 31 | width: 25vw; 32 | } 33 | } 34 | 35 | @media (min-width:1024px) { 36 | div.with-toc { 37 | margin-left:25vw; 38 | } 39 | } 40 | 41 | @font-face { 42 | font-family: 'Open Sans'; 43 | font-style: normal; 44 | font-weight: 400; 45 | font-stretch: 100%; 46 | font-display: swap; 47 | src: url(https://fonts.gstatic.com/s/opensans/v29/memSYaGs126MiZpBA-UvWbX2vVnXBbObj2OVZyOOSr4dVJWUgsjZ0B4gaVI.woff2) format('woff2'); 48 | unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; 49 | } 50 | 51 | body, h1, h2, h3, h4, h5, h6, p, text { 52 | font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif !important; 53 | } 54 | -------------------------------------------------------------------------------- /LeanCamCombi/StableCombi/AddSet.lean: -------------------------------------------------------------------------------- 1 | import Mathlib.Data.Set.Defs 2 | import LeanCamCombi.StableCombi.Rel 3 | 4 | variable {G : Type*} [Group G] {n : ℕ} {A : Set G} 5 | 6 | @[to_additive] def IsMulOrderPropWith (n : ℕ) (A : Set G) : Prop := IsOrderPropRelWith n (· * · ∈ A) 7 | 8 | @[to_additive] def IsMulOrderProp (A : Set G) : Prop := IsOrderPropRel (· * · ∈ A) 9 | 10 | @[to_additive] def IsMulStableWith (n : ℕ) (A : Set G) : Prop := IsStableRelWith n (· * · ∈ A) 11 | 12 | @[to_additive] def IsMulStable (A : Set G) : Prop := IsStableRel (· * · ∈ A) 13 | 14 | @[to_additive] 15 | def IsMulTreeBoundedWith (n : ℕ) (A : Set G) : Prop := IsTreeBoundedRelWith n (· * · ∈ A) 16 | 17 | @[to_additive (attr := simp)] 18 | lemma not_isMulStableWith : ¬ IsMulStableWith n A ↔ IsMulOrderPropWith n A := not_isStableRelWith 19 | 20 | @[to_additive (attr := simp)] 21 | lemma not_isMulOrderPropWith : ¬ IsMulOrderPropWith n A ↔ IsMulStableWith n A := 22 | not_isOrderPropRelWith 23 | 24 | @[to_additive (attr := simp)] 25 | lemma not_isMulStable : ¬ IsMulStable A ↔ IsMulOrderProp A := not_isStableRel 26 | 27 | @[to_additive (attr := simp)] 28 | lemma not_isMulOrderProp : ¬ IsMulOrderProp A ↔ IsMulStable A := not_isOrderPropRel 29 | 30 | @[to_additive] 31 | lemma IsMulStableWith.isMulTreeBoundedWith (hr : IsMulStableWith n A) : 32 | IsMulTreeBoundedWith (2 ^ n + 1) A := hr.isTreeBoundedRelWith 33 | 34 | @[to_additive] 35 | lemma IsMulTreeBoundedWith.isMulStableWith (hr : IsMulTreeBoundedWith n A) : 36 | IsMulStableWith (2 ^ n) A := hr.isStableRelWith 37 | -------------------------------------------------------------------------------- /LeanCamCombi/ExtrProbCombi/BollobasContainment.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Copyright (c) 2023 Yaël Dillies. All rights reserved. 3 | Released under Apache 2.0 license as described in the file LICENSE. 4 | Authors: Yaël Dillies 5 | -/ 6 | import LeanCamCombi.Mathlib.Combinatorics.SimpleGraph.Density 7 | import LeanCamCombi.Mathlib.Probability.Combinatorics.BinomialRandomGraph.Defs 8 | import Mathlib.Analysis.SpecialFunctions.Pow.Real 9 | import Mathlib.Combinatorics.SimpleGraph.Copy 10 | import Mathlib.MeasureTheory.Measure.Typeclasses.Probability 11 | 12 | /-! 13 | # Bollobás' graph containment lemma 14 | 15 | This file proves Bollobás' lemma on graph containment. 16 | -/ 17 | 18 | open Asymptotics Filter MeasureTheory 19 | open scoped MeasureTheory ENNReal NNReal SimpleGraph Topology unitInterval 20 | 21 | namespace SimpleGraph 22 | variable {V W Ω : Type*} [Fintype W] {G : ℕ → Ω → SimpleGraph V} (H : SimpleGraph W) 23 | [Fintype H.edgeSet] [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] {p : ℕ → I} 24 | (hG : ∀ n, IsBinomialRandom (G n) (p n) μ) 25 | 26 | /-- **Bollobás' Graph Containment Lemma**, zero statement -/ 27 | lemma zero_statement 28 | (hp : (fun n ↦ p n : ℕ → ℝ) =o[atTop] (fun n ↦ n ^ (-H.maxEdgeSubdensity⁻¹ : ℝ) : ℕ → ℝ)) : 29 | Tendsto (fun n ↦ μ {ω | H ⊑ G n ω}) atTop (𝓝 0) := 30 | sorry 31 | 32 | /-- **Bollobás' Graph Containment Lemma**, one statement -/ 33 | lemma one_statement 34 | (hp : (fun n ↦ n ^ (-H.maxEdgeSubdensity⁻¹ : ℝ) : ℕ → ℝ) =o[atTop] (fun n ↦ p n : ℕ → ℝ)) : 35 | Tendsto (fun n ↦ μ {ω | H ⊑ G n ω}) atTop (𝓝 1) := 36 | sorry 37 | 38 | end SimpleGraph 39 | -------------------------------------------------------------------------------- /LeanCamCombi/PlainCombi/ProbLYM.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Copyright (c) 2024 Ching-Tsun Chou, Chris Wong. All rights reserved. 3 | Released under Apache 2.0 license as described in the file LICENSE. 4 | Authors: Ching-Tsun Chou, Chris Wong 5 | -/ 6 | import Mathlib.Algebra.BigOperators.Field 7 | import Mathlib.Combinatorics.KatonaCircle 8 | 9 | /-! 10 | # The LYM inequality using probability theory 11 | 12 | This file proves the LYM inequality using (very elementary) probability theory. 13 | 14 | ## References 15 | 16 | This proof formalizes Section 1.2 of Prof. Yufei Zhao's lecture notes for MIT 18.226: 17 | 18 | 19 | 20 | A video of Prof. Zhao's lecture is available on YouTube: 21 | 22 | 23 | 24 | The proof of Theorem 1.10, Lecture 3 in the Cambridge lecture notes on combinatorics: 25 | 26 | 27 | 28 | is basically the same proof, except without using probability theory. 29 | -/ 30 | 31 | open Finset Fintype Numbering 32 | 33 | variable {α : Type*} [Fintype α] {𝒜 : Finset (Finset α)} 34 | 35 | /-- The **Lubell-Yamamoto-Meshalkin inequality**, proved using the Katona circle method. -/ 36 | theorem LYM_inequality (h𝒜 : IsAntichain (· ⊆ ·) (𝒜 : Set (Finset α))) : 37 | ∑ s ∈ 𝒜, ((card α).choose #s : ℚ≥0)⁻¹ ≤ 1 := by 38 | classical 39 | calc 40 | _ = ∑ s ∈ 𝒜, (prefixed s).dens := by simp 41 | _ = (𝒜.biUnion prefixed).dens := by 42 | rw [dens_biUnion] 43 | exact fun s hs t ht hst ↦ disjoint_prefixed_prefixed (h𝒜 hs ht hst) (h𝒜 ht hs hst.symm) 44 | _ ≤ 1 := dens_le_one 45 | -------------------------------------------------------------------------------- /LeanCamCombi/StableCombi/Rel.lean: -------------------------------------------------------------------------------- 1 | import Mathlib.Algebra.Group.Nat.Defs 2 | 3 | /-! 4 | # Stable binary relations 5 | -/ 6 | 7 | variable {α β : Type*} {n : ℕ} {r : α → β → Prop} 8 | 9 | def IsOrderPropRelWith (n : ℕ) (r : α → β → Prop) : Prop := 10 | ∃ (a : Fin n → α) (b : Fin n → β), ∀ i j, i ≤ j ↔ r (a i) (b j) 11 | 12 | def IsOrderPropRel (r : α → β → Prop) : Prop := 13 | ∃ (a : ℕ → α) (b : ℕ → β), ∀ i j, i ≤ j ↔ r (a i) (b j) 14 | 15 | def IsStableRelWith (n : ℕ) (r : α → β → Prop) : Prop := 16 | ∀ (a : Fin n → α) (b : Fin n → β), ∃ i j, ¬ (i ≤ j ↔ r (a i) (b j)) 17 | 18 | def IsStableRel (r : α → β → Prop) : Prop := 19 | ∀ (a : ℕ → α) (b : ℕ → β), ∃ i j, ¬ (i ≤ j ↔ r (a i) (b j)) 20 | 21 | def IsTreeBoundedRelWith (n : ℕ) (r : α → β → Prop) : Prop := 22 | ∀ (a : Vector Bool n → α) (b : ∀ m < n, Vector Bool m → β), 23 | ∃ (i : Vector Bool n) (m : ℕ) (hmn : m < n) (j : Vector Bool m), 24 | i.toList <+: j.toList ∧ ¬ (true :: i.toList <+: j.toList ↔ r (a i) (b m hmn j)) 25 | 26 | @[simp] lemma not_isStableRelWith : ¬ IsStableRelWith n r ↔ IsOrderPropRelWith n r := by 27 | simp [IsOrderPropRelWith, IsStableRelWith] 28 | 29 | @[simp] lemma not_isOrderPropRelWith : ¬ IsOrderPropRelWith n r ↔ IsStableRelWith n r := by 30 | simp [← not_isStableRelWith] 31 | 32 | @[simp] lemma not_isStableRel : ¬ IsStableRel r ↔ IsOrderPropRel r := by 33 | simp [IsOrderPropRel, IsStableRel] 34 | 35 | @[simp] lemma not_isOrderPropRel : ¬ IsOrderPropRel r ↔ IsStableRel r := by simp [← not_isStableRel] 36 | 37 | lemma IsStableRelWith.isTreeBoundedRelWith (hr : IsStableRelWith n r) : 38 | IsTreeBoundedRelWith (2 ^ n + 1) r := sorry 39 | 40 | lemma IsTreeBoundedRelWith.isStableRelWith (hr : IsTreeBoundedRelWith n r) : 41 | IsStableRelWith (2 ^ n) r := sorry 42 | -------------------------------------------------------------------------------- /LeanCamCombi/PlainCombi/OrderShatter.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Copyright (c) 2022 Yaël Dillies. All rights reserved. 3 | Released under Apache 2.0 license as described in the file LICENSE. 4 | Authors: Yaël Dillies 5 | -/ 6 | import Mathlib.Combinatorics.SetFamily.Compression.Down 7 | import Mathlib.Data.Finset.Powerset 8 | import Mathlib.Data.Finset.Sort 9 | 10 | /-! 11 | # Shattering families 12 | 13 | This file defines the shattering property and VC-dimension of set families. 14 | 15 | ## Main declarations 16 | 17 | * `Finset.StronglyShatters`: 18 | * `Finset.OrderShatters`: 19 | 20 | ## TODO 21 | 22 | * Order-shattering 23 | * Strong shattering 24 | -/ 25 | 26 | open scoped FinsetFamily 27 | 28 | namespace Finset 29 | variable {α : Type*} [DecidableEq α] {𝒜 ℬ : Finset (Finset α)} {s t : Finset α} {a : α} {n : ℕ} 30 | 31 | /-! ### Strong shattering -/ 32 | 33 | def StronglyShatters (𝒜 : Finset (Finset α)) (s : Finset α) : Prop := 34 | ∃ t, ∀ ⦃u⦄, u ⊆ s → ∃ v ∈ 𝒜, s ∩ v = u ∧ v \ s = t 35 | 36 | /-! ### Order shattering -/ 37 | 38 | section order 39 | variable [LinearOrder α] 40 | 41 | def OrderShatters : Finset (Finset α) → List α → Prop 42 | | 𝒜, [] => 𝒜.Nonempty 43 | | 𝒜, a :: l => (𝒜.nonMemberSubfamily a).OrderShatters l ∧ (𝒜.memberSubfamily a).OrderShatters l 44 | ∧ ∀ ⦃s : Finset α⦄, s ∈ 𝒜.nonMemberSubfamily a → ∀ ⦃t⦄, t ∈ 𝒜.memberSubfamily a → 45 | {x ∈ s | a < x} = {x ∈ t | a < x} 46 | 47 | instance instDecidableRel : DecidableRel (OrderShatters (α := α)) := fun 𝒜 l ↦ by 48 | induction l generalizing 𝒜 49 | · exact decidableNonempty 50 | · exact instDecidableAnd 51 | 52 | def orderShatterser (𝒜 : Finset (Finset α)) : Finset (Finset α) := 53 | {s ∈ 𝒜.biUnion powerset | 𝒜.OrderShatters <| s.sort (· ≤ ·)} 54 | 55 | end order 56 | 57 | end Finset 58 | -------------------------------------------------------------------------------- /blueprint/tasks.py: -------------------------------------------------------------------------------- 1 | import os 2 | import random 3 | from pathlib import Path 4 | import http.server 5 | import socketserver 6 | 7 | from invoke import run, task 8 | 9 | BP_DIR = Path(__file__).parent 10 | 11 | @task 12 | def print_bp(ctx): 13 | cwd = os.getcwd() 14 | os.chdir(BP_DIR) 15 | run('mkdir -p print && cd src && xelatex -output-directory=../print print.tex') 16 | os.chdir(cwd) 17 | 18 | @task 19 | def bp(ctx): 20 | cwd = os.getcwd() 21 | os.chdir(BP_DIR) 22 | run('mkdir -p print && cd src && xelatex -output-directory=../print print.tex') 23 | run('cd src && xelatex -output-directory=../print print.tex') 24 | os.chdir(cwd) 25 | 26 | @task 27 | def bptt(ctx): 28 | """ 29 | Build the blueprint PDF file with tectonic and prepare src/web.bbl for task `web` 30 | 31 | NOTE: install tectonic by running `curl --proto '=https' --tlsv1.2 -fsSL https://drop-sh.fullyjustified.net |sh` in 32 | `~/.local/bin/` 33 | """ 34 | 35 | cwd = os.getcwd() 36 | os.chdir(BP_DIR) 37 | run('mkdir -p print && cd src && tectonic -Z shell-escape-cwd=. --keep-intermediates --outdir ../print print.tex') 38 | # run('cp print/print.bbl src/web.bbl') 39 | os.chdir(cwd) 40 | 41 | @task 42 | def web(ctx): 43 | cwd = os.getcwd() 44 | os.chdir(BP_DIR/'src') 45 | run('plastex -c plastex.cfg web.tex') 46 | os.chdir(cwd) 47 | 48 | @task 49 | def serve(ctx, random_port=False): 50 | cwd = os.getcwd() 51 | os.chdir(BP_DIR/'web') 52 | Handler = http.server.SimpleHTTPRequestHandler 53 | if random_port: 54 | port = random.randint(8000, 8100) 55 | else: 56 | port = 8000 57 | 58 | httpd = socketserver.TCPServer(("", port), Handler) 59 | try: 60 | (ip, port) = httpd.server_address 61 | ip = ip or 'localhost' 62 | print(f'Serving http://{ip}:{port}/ ...') 63 | httpd.serve_forever() 64 | except KeyboardInterrupt: 65 | pass 66 | httpd.server_close() 67 | -------------------------------------------------------------------------------- /LeanCamCombi/GrowthInGroups/Lecture4.lean: -------------------------------------------------------------------------------- 1 | import Mathlib.Analysis.Matrix.Normed 2 | import Mathlib.GroupTheory.Nilpotent 3 | import Mathlib.LinearAlgebra.Matrix.GeneralLinearGroup.Defs 4 | import LeanCamCombi.Mathlib.Combinatorics.Additive.ApproximateSubgroup 5 | import LeanCamCombi.Util 6 | 7 | open Group 8 | open scoped Finset MatrixGroups Pointwise 9 | 10 | namespace GrowthInGroups.Lecture3 11 | variable {n : Type*} [Fintype n] [DecidableEq n] {K C₀ C : ℝ} 12 | 13 | attribute [instance] Matrix.linftyOpNormedRing 14 | 15 | lemma fact_4_1 (S T : GL n ℂ) : 16 | ‖(S * T * S⁻¹ * T⁻¹ - 1 : Matrix n n ℂ)‖ ≤ 17 | 2 * ‖(S⁻¹ : Matrix n n ℂ)‖ * ‖(T⁻¹ : Matrix n n ℂ)‖ * 18 | ‖(S - 1 : Matrix n n ℂ)‖ * ‖(T - 1 : Matrix n n ℂ)‖ := by 19 | simpa using norm_commutator_units_sub_one_le S T 20 | 21 | open scoped Classical in 22 | lemma lemma_4_2 (hC₀ : Fintype.card n < C₀) (K : ℝ) : 23 | ∃ δ : ℝ, 24 | ∀ A : Finset (GL n ℂ), IsApproximateSubgroup K (A : Set (GL n ℂ)) → (∀ a ∈ A, ‖a.val‖ ≤ C₀) → 25 | ∃ γ ∈ A ^ 2, δ * #A ≤ #{x ∈ A ^ 4 | Commute γ x} := sorry 26 | 27 | lemma corollary_4_3 (K C₀ : ℝ) : 28 | ∃ C > 0, ∀ (A : Set SL(2, ℂ)) (hA : IsApproximateSubgroup K A), 29 | ∃ (Z : Subgroup SL(2, ℂ)) (hH : ∀ x ∈ Z, ∀ y ∈ Z, Commute x y) (F : Finset SL(2, ℂ)), 30 | #F ≤ C ∧ A ⊆ F * Z := sorry 31 | 32 | /-- The **Breuillard-Green-Tao theorem**. -/ 33 | theorem theorem_4_4 : 34 | ∃ C > 0, ∀ {G} [Group G] [DecidableEq G] (A : Set G) (_hA : IsApproximateSubgroup K A), 35 | ∃ (H : Subgroup G) (N : Subgroup H) (_hD : N.Normal) (F : Finset G), 36 | upperCentralSeries (H ⧸ N) C = ⊤ ∧ ((↑) '' (N : Set H) : Set G) ⊆ (A / A) ^ 4 ∧ 37 | A ⊆ F * H := showcased 38 | 39 | lemma theorem_4_5 {G : Type*} [Group G] [DecidableEq G] {S : Finset G} (hSsymm : S⁻¹ = S) 40 | (hSgen : (Subgroup.closure (S : Set G) : Set G) = .univ) {d : ℕ} 41 | (hS : ∀ n : ℕ, #(S ^ n) ≤ C * n ^ d) : IsVirtuallyNilpotent G := sorry 42 | 43 | end GrowthInGroups.Lecture3 44 | -------------------------------------------------------------------------------- /LeanCamCombi/StableCombi/Formula.lean: -------------------------------------------------------------------------------- 1 | import Mathlib.ModelTheory.Semantics 2 | import LeanCamCombi.StableCombi.Rel 3 | 4 | namespace FirstOrder.Language 5 | variable {L : Language} 6 | 7 | namespace Formula 8 | variable (n : ℕ) (M : Type*) [L.Structure M] (φ : L.Formula (Fin 2)) 9 | 10 | def IsOrderPropWith : Prop := IsOrderPropRelWith n fun x y : M ↦ φ.Realize ![x, y] 11 | 12 | def IsOrderProp : Prop := IsOrderPropRel fun x y : M ↦ φ.Realize ![x, y] 13 | 14 | def IsStableWith : Prop := IsStableRelWith n fun x y : M ↦ φ.Realize ![x, y] 15 | 16 | def IsStable : Prop := IsStableRel fun x y : M ↦ φ.Realize ![x, y] 17 | 18 | def IsTreeBoundedWith : Prop := IsTreeBoundedRelWith n fun x y : M ↦ φ.Realize ![x, y] 19 | 20 | variable {n M φ} 21 | 22 | @[simp] lemma not_isStableWith : ¬ IsStableWith n M φ ↔ IsOrderPropWith n M φ := not_isStableRelWith 23 | 24 | @[simp] lemma not_isOrderPropWith : ¬ IsOrderPropWith n M φ ↔ IsStableWith n M φ := 25 | not_isOrderPropRelWith 26 | 27 | @[simp] lemma not_isStable : ¬ IsStable M φ ↔ IsOrderProp M φ := not_isStableRel 28 | 29 | @[simp] lemma not_isOrderProp : ¬ IsOrderProp M φ ↔ IsStable M φ := not_isOrderPropRel 30 | 31 | lemma IsStableWith.isTreeBoundedWith (hr : IsStableWith n M φ) : 32 | IsTreeBoundedWith (2 ^ n + 1) M φ := hr.isTreeBoundedRelWith 33 | 34 | lemma IsTreeBoundedWith.isStableWith (hr : IsTreeBoundedWith n M φ) : 35 | IsStableWith (2 ^ n) M φ := hr.isStableRelWith 36 | 37 | end Formula 38 | 39 | namespace Theory 40 | variable (T : L.Theory) 41 | 42 | -- TODO: What universe should we set `M` to here? 43 | def IsOrderProp : Prop := 44 | ∃ (M : Type*) (_ : L.Structure M), M ⊨ T ∧ ∃ φ : L.Formula (Fin 2), φ.IsOrderProp M 45 | 46 | def IsStable : Prop := ∀ ⦃M : Type*⦄ [L.Structure M], M ⊨ T → ∀ φ : L.Formula (Fin 2), φ.IsStable M 47 | 48 | variable {T} 49 | 50 | @[simp] lemma not_isStable : ¬ IsStable T ↔ IsOrderProp T := by simp [IsStable, IsOrderProp] 51 | 52 | @[simp] lemma not_isOrderProp : ¬ IsOrderProp T ↔ IsStable T := by simp [← not_isStable] 53 | 54 | end FirstOrder.Language.Theory 55 | -------------------------------------------------------------------------------- /LeanCamCombi/PlainCombi/LittlewoodOfford.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Copyright (c) 2022 Yaël Dillies. All rights reserved. 3 | Released under Apache 2.0 license as described in the file LICENSE. 4 | Authors: Yaël Dillies 5 | -/ 6 | import Mathlib.Analysis.Normed.Module.HahnBanach 7 | import Mathlib.Combinatorics.Enumerative.DoubleCounting 8 | import Mathlib.Order.Partition.Finpartition 9 | 10 | /-! 11 | # The Littlewood-Offord problem 12 | -/ 13 | 14 | open scoped BigOperators 15 | 16 | namespace Finset 17 | variable {ι E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {𝒜 : Finset (Finset ι)} 18 | {s : Finset ι} {f : ι → E} {r : ℝ} 19 | 20 | lemma exists_littlewood_offord_partition [DecidableEq ι] (hr : 0 < r) (hf : ∀ i ∈ s, r ≤ ‖f i‖) : 21 | ∃ P : Finpartition s.powerset, 22 | #P.parts = (#s).choose (#s / 2) ∧ (∀ 𝒜 ∈ P.parts, ∀ t ∈ 𝒜, t ⊆ s) ∧ ∀ 𝒜 ∈ P.parts, 23 | (𝒜 : Set (Finset ι)).Pairwise fun u v ↦ r ≤ dist (∑ i ∈ u, f i) (∑ i ∈ v, f i) := by 24 | classical 25 | induction s using Finset.induction with 26 | | empty => exact ⟨Finpartition.indiscrete <| singleton_ne_empty _, by simp⟩ 27 | | insert i s hi ih => 28 | obtain ⟨P, hP, hs, hPr⟩ := ih fun j hj ↦ hf _ <| mem_insert_of_mem hj 29 | clear ih 30 | obtain ⟨g, hg, hgf⟩ := 31 | exists_dual_vector ℝ (f i) (norm_pos_iff.1 <| hr.trans_le <| hf _ <| mem_insert_self _ _) 32 | choose! t ht using fun 𝒜 (h𝒜 : 𝒜 ∈ P.parts) ↦ 33 | Finset.exists_max_image _ (fun t ↦ g (∑ i ∈ t, f i)) (P.nonempty_of_mem_parts h𝒜) 34 | sorry 35 | 36 | /-- **Kleitman's lemma** -/ 37 | lemma card_le_of_forall_dist_sum_le (hr : 0 < r) (h𝒜 : ∀ t ∈ 𝒜, t ⊆ s) (hf : ∀ i ∈ s, r ≤ ‖f i‖) 38 | (h𝒜r : ∀ u, u ∈ 𝒜 → ∀ v, v ∈ 𝒜 → dist (∑ i ∈ u, f i) (∑ i ∈ v, f i) < r) : 39 | #𝒜 ≤ (#s).choose (#s / 2) := by 40 | classical 41 | obtain ⟨P, hP, _hs, hr⟩ := exists_littlewood_offord_partition hr hf 42 | rw [← hP] 43 | refine card_le_card_of_forall_subsingleton (· ∈ ·) (fun t ht ↦ ?_) fun ℬ hℬ t ht u hu ↦ 44 | (hr _ hℬ).eq ht.2 hu.2 (h𝒜r _ ht.1 _ hu.1).not_ge 45 | simpa only [exists_prop] using P.exists_mem (mem_powerset.2 <| h𝒜 _ ht) 46 | 47 | end Finset 48 | -------------------------------------------------------------------------------- /website/_config.yml: -------------------------------------------------------------------------------- 1 | # Welcome to Jekyll! 2 | # 3 | # This config file is meant for settings that affect your whole blog, values 4 | # which you are expected to set up once and rarely edit after that. If you find 5 | # yourself editing this file very often, consider using Jekyll's data files 6 | # feature for the data you need to update frequently. 7 | # 8 | # For technical reasons, this file is *NOT* reloaded automatically when you use 9 | # 'bundle exec jekyll serve'. If you change this file, please restart the server process. 10 | # 11 | # If you need help with YAML syntax, here are some quick references for you: 12 | # https://learn-the-web.algonquindesign.ca/topics/markdown-yaml-cheat-sheet/#yaml 13 | # https://learnxinyminutes.com/docs/yaml/ 14 | # 15 | # Site settings 16 | # These are used to personalize your new site. If you look in the HTML files, 17 | # you will see them accessed via {{ site.title }}, {{ site.email }}, and so on. 18 | # You can create any custom variable you would like, and they will be accessible 19 | # in the templates via {{ site.myvariable }}. 20 | 21 | title: Cambridge combinatorics in Lean 22 | #email: your-email@example.com 23 | description: Formalisation of the Cambridge combinatorics courses 24 | baseurl: "" # the subpath of your site, e.g. /blog 25 | url: "https://yaeldillies.github.io/LeanCamCombi/" # the base hostname & protocol for your site, e.g. http://example.com 26 | #twitter_username: jekyllrb 27 | github_username: YaelDillies 28 | repository: YaelDillies/LeanCamCombi 29 | 30 | # Build settings 31 | remote_theme: pages-themes/cayman@v0.2.0 32 | plugins: 33 | - jekyll-remote-theme 34 | # Exclude from processing. 35 | # The following items will not be processed, by default. 36 | # Any item listed under the `exclude:` key here will be automatically added to 37 | # the internal "default list". 38 | # 39 | # Excluded items can be processed by explicitly listing the directories or 40 | # their entries' file path in the `include:` list. 41 | # 42 | # exclude: 43 | # - .sass-cache/ 44 | # - .jekyll-cache/ 45 | # - gemfiles/ 46 | # - Gemfile 47 | # - Gemfile.lock 48 | # - node_modules/ 49 | # - vendor/bundle/ 50 | # - vendor/cache/ 51 | # - vendor/gems/ 52 | # - vendor/ruby/ 53 | -------------------------------------------------------------------------------- /.github/workflows/push.yml: -------------------------------------------------------------------------------- 1 | name: Build Lean project 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | workflow_dispatch: 9 | 10 | # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages 11 | permissions: 12 | contents: read 13 | pages: write 14 | id-token: write 15 | 16 | jobs: 17 | style_lint: 18 | name: Lint style 19 | runs-on: ubuntu-latest 20 | steps: 21 | - name: Checkout project 22 | uses: actions/checkout@v4 23 | with: 24 | fetch-depth: 0 25 | 26 | - name: Don't 'import Mathlib', use precise imports 27 | if: always() 28 | run: | 29 | ! (find LeanCamCombi -name "*.lean" -type f -print0 | xargs -0 grep -E -n '^import Mathlib$') 30 | 31 | - name: Files in LeanCamCombi.Mathlib can't import LeanCamCombi files outside LeanCamCombi.Mathlib 32 | run: | 33 | ! (find LeanCamCombi/Mathlib -name "*.lean" -type f -print0 | xargs -0 grep -E -n '^import LeanCamCombi.(?!Mathlib)') 34 | 35 | build: 36 | name: Build project 37 | runs-on: ubuntu-latest 38 | steps: 39 | - name: Checkout project 40 | uses: actions/checkout@v5 41 | with: 42 | fetch-depth: 0 # Fetch all history for all branches and tags 43 | 44 | - name: Build and lint the project 45 | id: build-lean 46 | uses: leanprover/lean-action@f807b338d95de7813c5c50d018f1c23c9b93b4ec # v1.2.0 47 | 48 | - name: Copy README.md to website/index.md 49 | if: github.ref == 'refs/heads/master' 50 | run: cp README.md website/index.md 51 | 52 | - name: Upstreaming dashboard 53 | if: github.ref == 'refs/heads/master' 54 | run: | 55 | mkdir -p website/_includes 56 | python3 scripts/upstreaming_dashboard.py 57 | 58 | - name: File dependencies 59 | if: github.ref == 'refs/heads/master' 60 | run: | 61 | sudo apt-get update 62 | sudo apt install graphviz -y 63 | ~/.elan/bin/lake exe graph website/file_deps.pdf 64 | 65 | - name: Build project documentation 66 | if: github.ref == 'refs/heads/master' 67 | id: build-docgen 68 | uses: leanprover-community/docgen-action@main 69 | with: 70 | blueprint: false 71 | homepage: "website" 72 | -------------------------------------------------------------------------------- /LeanCamCombi/GrowthInGroups/Lecture3.lean: -------------------------------------------------------------------------------- 1 | import Mathlib.Geometry.Group.Growth.QuotientInter 2 | import LeanCamCombi.Mathlib.Combinatorics.Additive.ApproximateSubgroup 3 | 4 | open Finset 5 | open scoped Pointwise 6 | 7 | namespace GrowthInGroups.Lecture3 8 | variable {G H : Type*} [Group G] [Group H] {A B : Set G} {K L : ℝ} {m n : ℕ} 9 | 10 | lemma lemma_3_1 [DecidableEq G] {A : Finset G} (hA₁ : 1 ∈ A) (hAsymm : A⁻¹ = A) 11 | (hA : #(A ^ 3) ≤ K * #A) : IsApproximateSubgroup (K ^ 3) (A ^ 2 : Set G) := 12 | .of_small_tripling hA₁ hAsymm hA 13 | 14 | lemma lemma_3_2 [DecidableEq G] {A B : Finset G} (hB : B.Nonempty) (hK : #(A * B) ≤ K * #B) : 15 | ∃ F ⊆ A, #F ≤ K ∧ A ⊆ F * (B / B) := ruzsa_covering_mul hB hK 16 | 17 | open scoped RightActions 18 | lemma proposition_3_3 [DecidableEq G] {A : Finset G} (hA₀ : A.Nonempty) (hA : #(A ^ 2) ≤ K * #A) : 19 | ∃ S ⊆ (A⁻¹ * A) ^ 2, IsApproximateSubgroup (2 ^ 12 * K ^ 36) (S : Set G) ∧ 20 | #S ≤ 16 * K ^ 12 * #A ∧ ∃ a ∈ A, #A / (2 * K) ≤ #(A ∩ S <• a) := 21 | exists_isApproximateSubgroup_of_small_doubling hA₀ hA 22 | 23 | lemma fact_3_5 {A : Set G} (hA : IsApproximateSubgroup K A) (π : G →* H) : 24 | IsApproximateSubgroup K (π '' A) := hA.image π 25 | 26 | lemma proposition_3_6_1 (hA : IsApproximateSubgroup K A) (hB : IsApproximateSubgroup L B) 27 | (hm : 2 ≤ m) (hn : 2 ≤ n) : 28 | ∃ F : Finset G, #F ≤ K ^ (m - 1) * L ^ (n - 1) ∧ A ^ m ∩ B ^ n ⊆ F * (A ^ 2 ∩ B ^ 2) := 29 | hA.pow_inter_pow_covBySMul_sq_inter_sq hB hm hn 30 | 31 | lemma proposition_3_6_2 (hA : IsApproximateSubgroup K A) (hB : IsApproximateSubgroup L B) 32 | (hm : 2 ≤ m) (hn : 2 ≤ n) : 33 | IsApproximateSubgroup (K ^ (2 * m - 1) * L ^ (2 * n - 1)) (A ^ m ∩ B ^ n) := 34 | hA.pow_inter_pow hB hm hn 35 | 36 | lemma lemma_3_7 (hA : A⁻¹ = A) (hB : B⁻¹ = B) (x y : G) : 37 | ∃ z : G, x • A ∩ y • B ⊆ z • (A ^ 2 ∩ B ^ 2) := by 38 | simpa [hA, hB, sq] using Set.exists_smul_inter_smul_subset_smul_inv_mul_inter_inv_mul A B x y 39 | 40 | open scoped Classical in 41 | lemma lemma_3_8_1 {H : Subgroup G} [H.Normal] {A : Finset G} : 42 | #((A ^ m).image <| QuotientGroup.mk' H) * #{x ∈ A ^ n | x ∈ H} ≤ #(A ^ (m + n)) := 43 | card_pow_quotient_mul_pow_inter_subgroup_le 44 | 45 | open scoped Classical in 46 | lemma lemma_3_8_2 {H : Subgroup G} [H.Normal] {A : Finset G} (hAsymm : A⁻¹ = A) : 47 | #A ≤ #(A.image <| QuotientGroup.mk' H) * #{x ∈ A ^ 2 | x ∈ H} := 48 | le_card_quotient_mul_sq_inter_subgroup hAsymm 49 | 50 | end GrowthInGroups.Lecture3 51 | -------------------------------------------------------------------------------- /LeanCamCombi/Mathlib/Combinatorics/Additive/ApproximateSubgroup.lean: -------------------------------------------------------------------------------- 1 | import Mathlib.Algebra.Order.BigOperators.Ring.Finset 2 | import Mathlib.Combinatorics.Additive.ApproximateSubgroup 3 | import Mathlib.Tactic.Bound 4 | 5 | open scoped Finset Pointwise 6 | 7 | variable {G : Type*} [Group G] {A B : Set G} {K L : ℝ} {m n : ℕ} 8 | 9 | namespace IsApproximateSubgroup 10 | 11 | @[to_additive] 12 | lemma pi {ι : Type*} {G : ι → Type*} [Fintype ι] [∀ i, Group (G i)] {A : ∀ i, Set (G i)} {K : ι → ℝ} 13 | (hA : ∀ i, IsApproximateSubgroup (K i) (A i)) : 14 | IsApproximateSubgroup (∏ i, K i) (Set.univ.pi A) where 15 | one_mem i _ := (hA i).one_mem 16 | inv_eq_self := by simp [(hA _).inv_eq_self] 17 | sq_covBySMul := by 18 | choose F hF hFS using fun i ↦ (hA i).sq_covBySMul 19 | classical 20 | refine ⟨Fintype.piFinset F, ?_, ?_⟩ 21 | · calc 22 | #(Fintype.piFinset F) = ∏ i, (#(F i) : ℝ) := by simp 23 | _ ≤ ∏ i, K i := by gcongr; exact hF _ 24 | · sorry 25 | 26 | end IsApproximateSubgroup 27 | 28 | set_option linter.flexible false in 29 | open Finset in 30 | open scoped RightActions in 31 | @[to_additive] 32 | lemma exists_isApproximateSubgroup_of_small_doubling [DecidableEq G] {A : Finset G} 33 | (hA₀ : A.Nonempty) (hA : #(A ^ 2) ≤ K * #A) : 34 | ∃ S ⊆ (A⁻¹ * A) ^ 2, IsApproximateSubgroup (2 ^ 12 * K ^ 36) (S : Set G) ∧ 35 | #S ≤ 16 * K ^ 12 * #A ∧ ∃ a ∈ A, #A / (2 * K) ≤ #(A ∩ S <• a) := by 36 | have hK : 1 ≤ K := one_le_of_le_mul_right₀ (by positivity) <| 37 | calc (#A : ℝ) ≤ #(A ^ 2) := mod_cast card_le_card_pow two_ne_zero 38 | _ ≤ K * #A := hA 39 | let S : Finset G := {g ∈ A⁻¹ * A | #A / (2 * K) ≤ #(A <• g ∩ A)} 40 | have hS₁ : 1 ∈ S := by simp [S, hA₀.ne_empty]; bound 41 | have hS₀ : S.Nonempty := ⟨1, hS₁⟩ 42 | have hSA : S ⊆ A⁻¹ * A := filter_subset .. 43 | have hSsymm : S⁻¹ = S := by ext; simp [S]; sorry 44 | have hScard := calc 45 | (#S : ℝ) ≤ #(A⁻¹ * A) := by gcongr 46 | _ ≤ K ^ 2 * #A := sorry 47 | obtain ⟨F, hFA, hFcard, hASF⟩ : ∃ F ⊆ A, #F ≤ 2 * K ∧ A ⊆ S * F := sorry 48 | refine ⟨S ^ 2, by gcongr, ?_, ?_, ?_⟩ 49 | · rw [show 2 ^ 12 * K ^ 36 = (2 ^ 4 * K ^ 12) ^ 3 by ring, coe_pow] 50 | refine .of_small_tripling hS₁ hSsymm ?_ 51 | calc 52 | (#(S ^ 3) : ℝ) 53 | _ ≤ #(A * S ^ 3) := mod_cast card_le_card_mul_left hA₀ 54 | _ ≤ #(A * S ^ 3 * A⁻¹) := mod_cast card_le_card_mul_right hA₀.inv 55 | _ ≤ 8 * K ^ 11 * #A := sorry 56 | _ ≤ 8 * K ^ 11 * #(S * F) := by gcongr 57 | _ ≤ 8 * K ^ 11 * (#S * #F) := by gcongr; exact mod_cast card_mul_le 58 | _ ≤ 8 * K ^ 11 * (#S * (2 * K)) := by gcongr 59 | _ = 2 ^ 4 * K ^ 12 * #S := by ring 60 | · sorry 61 | · sorry 62 | -------------------------------------------------------------------------------- /website/_layouts/default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | {% seo %} 8 | 9 | 11 | 12 | 13 | 14 | {% if jekyll.environment == "production" %} 15 | 17 | 19 | {% else %} 20 | 21 | 23 | {% endif %} 24 | {% include head-custom.html %} 25 | 26 | 27 | 28 | Skip to the content. 29 | 30 | 47 | 48 |
49 | {{ content }} 50 | 51 |
52 | {% if site.github.is_project_page %} 53 | {{ site.github.repository_name }} 54 | is maintained by Yaël Dillies, First year PhD student at Stockholm University. Visit the repository on GitHub for 55 | the full list of contributors. 56 | {% endif %} 57 |
58 |
59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /tasks.py: -------------------------------------------------------------------------------- 1 | import os 2 | import shutil 3 | import subprocess 4 | from pathlib import Path 5 | from invoke import run, task 6 | import json 7 | import re 8 | 9 | from blueprint.tasks import web, bp, print_bp, serve 10 | 11 | ROOT = Path(__file__).parent 12 | BP_DIR = ROOT/'blueprint' 13 | PROJ = 'LeanCamCombi' 14 | 15 | @task(bp, web) 16 | def all(ctx): 17 | shutil.rmtree(ROOT/'docs'/'blueprint', ignore_errors=True) 18 | shutil.copytree(ROOT/'blueprint'/'web', ROOT/'docs'/'blueprint') 19 | shutil.copy2(ROOT/'blueprint'/'print'/'print.pdf', ROOT/'docs'/'blueprint.pdf') 20 | 21 | @task(web) 22 | def html(ctx): 23 | shutil.rmtree(ROOT/'docs'/'blueprint', ignore_errors=True) 24 | shutil.copytree(ROOT/'blueprint'/'web', ROOT/'docs'/'blueprint') 25 | 26 | @task(all) 27 | def dev(ctx): 28 | """ 29 | Serve the blueprint website, rebuild PDF and the website on file changes 30 | """ 31 | 32 | from watchfiles import run_process, DefaultFilter 33 | 34 | def callback(changes): 35 | print('Changes detected:', changes) 36 | bp(ctx) 37 | web(ctx) 38 | 39 | run_process(BP_DIR/'src', target='inv serve', callback=callback, 40 | watch_filter=DefaultFilter( 41 | ignore_entity_patterns=( 42 | '.*\.aux$', 43 | '.*\.log$', 44 | '.*\.fls$', 45 | '.*\.fdb_latexmk$', 46 | '.*\.bbl$', 47 | '.*\.paux$', 48 | '.*\.pdf$', 49 | '.*\.out$', 50 | '.*\.blg$', 51 | '.*\.synctex.*$', 52 | ) 53 | )) 54 | 55 | @task 56 | def check(ctx): 57 | """ 58 | Check for broken references in blueprint to Lean declarations 59 | """ 60 | 61 | broken_decls = [] 62 | 63 | DECLS_FILE = ROOT/'.lake/build/doc/declarations/declaration-data.bmp' 64 | if not DECLS_FILE.exists(): 65 | print('[ERROR] Declarations file not found. Please run `lake -Kenv=dev build %s:docs` first.' % PROJ) 66 | exit(1) 67 | 68 | DEP_GRAPH_FILE = BP_DIR/'web/dep_graph_document.html' 69 | if not DEP_GRAPH_FILE.exists(): 70 | print('[ERROR] Dependency graph file not found. Please run `inv all` (or only `inv web`) first.') 71 | exit(1) 72 | 73 | with open(DECLS_FILE) as f: 74 | lean_decls = json.load(f)['declarations'] 75 | 76 | with open(DEP_GRAPH_FILE) as f: 77 | lean_decl_regex = re.compile(r'lean_decl.*href=".*/find/#doc/([^"]+)"') 78 | for line in f: 79 | match = lean_decl_regex.search(line) 80 | if match and match.lastindex == 1: 81 | blueprint_decl = match[1] 82 | if blueprint_decl not in lean_decls: 83 | broken_decls.append(blueprint_decl) 84 | 85 | if broken_decls: 86 | print('[WARN] The following Lean declarations are referenced in the blueprint but not in Lean:\n') 87 | for decl in broken_decls: 88 | print(decl) 89 | exit(1) 90 | else: 91 | print('[OK] All Lean declarations referenced in the blueprint exist.') 92 | -------------------------------------------------------------------------------- /LeanCamCombi/GrowthInGroups/Lecture2.lean: -------------------------------------------------------------------------------- 1 | import Mathlib.Algebra.Order.Group.Pointwise.Interval 2 | import LeanCamCombi.Mathlib.Combinatorics.Additive.ApproximateSubgroup 3 | 4 | open Fin Finset List 5 | open scoped Pointwise 6 | 7 | namespace GrowthInGroups.Lecture2 8 | variable {G : Type*} [DecidableEq G] [Group G] {A : Finset G} {k K : ℝ} {m : ℕ} 9 | 10 | lemma lemma_2_2 (U V W : Finset G) : #U * #(V⁻¹ * W) ≤ #(U * V) * #(U * W) := 11 | ruzsa_triangle_inequality_invMul_mul_mul .. 12 | 13 | lemma lemma_2_3_2 (hA : #(A ^ 2) ≤ K * #A) : #(A⁻¹ * A) ≤ K ^ 2 * #A := by 14 | obtain rfl | hA₀ := A.eq_empty_or_nonempty 15 | · simp 16 | have : 0 ≤ K := nonneg_of_mul_nonneg_left (hA.trans' <| by positivity) (by positivity) 17 | refine le_of_mul_le_mul_left ?_ (by positivity : (0 : ℝ) < #A) 18 | calc 19 | (#A * #(A⁻¹ * A) : ℝ) ≤ #(A * A) * #(A * A) := by norm_cast; exact lemma_2_2 .. 20 | _ ≤ (K * #A) * (K * #A) := by rw [← sq A]; gcongr 21 | _ = #A * (K ^ 2 * #A) := by ring 22 | 23 | lemma lemma_2_3_1 (hA : #(A ^ 2) ≤ K * #A) : #(A * A⁻¹) ≤ K ^ 2 * #A := by 24 | obtain rfl | hA₀ := A.eq_empty_or_nonempty 25 | · simp 26 | have : 0 ≤ K := nonneg_of_mul_nonneg_left (hA.trans' <| by positivity) (by positivity) 27 | refine le_of_mul_le_mul_left ?_ (by positivity : (0 : ℝ) < #A) 28 | calc 29 | (#A * #(A * A⁻¹) : ℝ) ≤ #(A * A) * #(A * A) := by 30 | norm_cast; simpa [← mul_inv_rev] using lemma_2_2 A⁻¹ A⁻¹ A⁻¹ 31 | _ ≤ (K * #A) * (K * #A) := by rw [← sq A]; gcongr 32 | _ = #A * (K ^ 2 * #A) := by ring 33 | 34 | lemma lemma_2_4_1 (hm : 3 ≤ m) (hA : #(A ^ 3) ≤ K * #A) (ε : Fin m → ℤ) (hε : ∀ i, |ε i| = 1) : 35 | #((finRange m).map fun i ↦ A ^ ε i).prod ≤ K ^ (3 * (m - 2)) * #A := 36 | small_alternating_pow_of_small_tripling hm hA ε hε 37 | 38 | lemma lemma_2_4_2 (hm : 3 ≤ m) (hA : #(A ^ 3) ≤ K * #A) (hAsymm : A⁻¹ = A) : 39 | #(A ^ m) ≤ K ^ (m - 2) * #A := small_pow_of_small_tripling hm hA hAsymm 40 | 41 | def def_2_5 (S : Set G) (K : ℝ) : Prop := IsApproximateSubgroup K S 42 | 43 | lemma remark_2_6_1 (k : ℕ) : IsApproximateAddSubgroup 2 (.Icc (-k) k : Set ℤ) where 44 | zero_mem := by simp 45 | neg_eq_self := by simp 46 | two_nsmul_covByVAdd := 47 | ⟨{(-k : ℤ), (k : ℤ)}, mod_cast card_le_two, by simp [two_nsmul, Set.Icc_add_Icc, Set.pair_add]⟩ 48 | 49 | lemma remark_2_6_2 {ι : Type*} [Fintype ι] (k : ι → ℕ) : 50 | IsApproximateAddSubgroup (2 ^ Fintype.card ι) 51 | (Set.univ.pi fun i ↦ .Icc (-k i) (k i) : Set (ι → ℤ)) := by 52 | simpa using IsApproximateAddSubgroup.pi fun i ↦ remark_2_6_1 (k i) 53 | 54 | lemma remark_2_6_3 : IsApproximateAddSubgroup 2 (.Icc (-1) 1 : Set ℝ) where 55 | zero_mem := by simp 56 | neg_eq_self := by simp 57 | two_nsmul_covByVAdd := 58 | ⟨{-1, 1}, mod_cast card_le_two, by simp [two_nsmul, Set.Icc_add_Icc, Set.pair_add]⟩ 59 | 60 | lemma lemma_2_7 {A : Finset G} (hA₁ : 1 ∈ A) (hsymm : A⁻¹ = A) (hA : #(A ^ 3) ≤ K * #A) : 61 | IsApproximateSubgroup (K ^ 3) (A ^ 2 : Set G) := .of_small_tripling hA₁ hsymm hA 62 | 63 | lemma lemma_2_8 {A B : Finset G} (hB : B.Nonempty) (hK : #(A * B) ≤ K * #B) : 64 | ∃ F ⊆ A, #F ≤ K ∧ A ⊆ F * (B / B) := ruzsa_covering_mul hB hK 65 | 66 | end GrowthInGroups.Lecture2 67 | -------------------------------------------------------------------------------- /lake-manifest.json: -------------------------------------------------------------------------------- 1 | {"version": "1.1.0", 2 | "packagesDir": ".lake/packages", 3 | "packages": 4 | [{"url": "https://github.com/leanprover-community/mathlib4.git", 5 | "type": "git", 6 | "subDir": null, 7 | "scope": "", 8 | "rev": "2df2f0150c275ad53cb3c90f7c98ec15a56a1a67", 9 | "name": "mathlib", 10 | "manifestFile": "lake-manifest.json", 11 | "inputRev": "v4.26.0", 12 | "inherited": false, 13 | "configFile": "lakefile.lean"}, 14 | {"url": "https://github.com/leanprover-community/plausible", 15 | "type": "git", 16 | "subDir": null, 17 | "scope": "leanprover-community", 18 | "rev": "160af9e8e7d4ae448f3c92edcc5b6a8522453f11", 19 | "name": "plausible", 20 | "manifestFile": "lake-manifest.json", 21 | "inputRev": "main", 22 | "inherited": true, 23 | "configFile": "lakefile.toml"}, 24 | {"url": "https://github.com/leanprover-community/LeanSearchClient", 25 | "type": "git", 26 | "subDir": null, 27 | "scope": "leanprover-community", 28 | "rev": "3591c3f664ac3719c4c86e4483e21e228707bfa2", 29 | "name": "LeanSearchClient", 30 | "manifestFile": "lake-manifest.json", 31 | "inputRev": "main", 32 | "inherited": true, 33 | "configFile": "lakefile.toml"}, 34 | {"url": "https://github.com/leanprover-community/import-graph", 35 | "type": "git", 36 | "subDir": null, 37 | "scope": "leanprover-community", 38 | "rev": "e9f31324f15ead11048b1443e62c5deaddd055d2", 39 | "name": "importGraph", 40 | "manifestFile": "lake-manifest.json", 41 | "inputRev": "main", 42 | "inherited": true, 43 | "configFile": "lakefile.toml"}, 44 | {"url": "https://github.com/leanprover-community/ProofWidgets4", 45 | "type": "git", 46 | "subDir": null, 47 | "scope": "leanprover-community", 48 | "rev": "b4fb2aa5290ebf61bc5f80a5375ba642f0a49192", 49 | "name": "proofwidgets", 50 | "manifestFile": "lake-manifest.json", 51 | "inputRev": "v0.0.83", 52 | "inherited": true, 53 | "configFile": "lakefile.lean"}, 54 | {"url": "https://github.com/leanprover-community/aesop", 55 | "type": "git", 56 | "subDir": null, 57 | "scope": "leanprover-community", 58 | "rev": "2f6d238744c4cb07fdc91240feaf5d4221a27931", 59 | "name": "aesop", 60 | "manifestFile": "lake-manifest.json", 61 | "inputRev": "master", 62 | "inherited": true, 63 | "configFile": "lakefile.toml"}, 64 | {"url": "https://github.com/leanprover-community/quote4", 65 | "type": "git", 66 | "subDir": null, 67 | "scope": "leanprover-community", 68 | "rev": "9312503909aa8e8bb392530145cc1677a6298574", 69 | "name": "Qq", 70 | "manifestFile": "lake-manifest.json", 71 | "inputRev": "master", 72 | "inherited": true, 73 | "configFile": "lakefile.toml"}, 74 | {"url": "https://github.com/leanprover-community/batteries", 75 | "type": "git", 76 | "subDir": null, 77 | "scope": "leanprover-community", 78 | "rev": "24241822ef9d3e7f6a3bcc53ad136e12663db8f3", 79 | "name": "batteries", 80 | "manifestFile": "lake-manifest.json", 81 | "inputRev": "main", 82 | "inherited": true, 83 | "configFile": "lakefile.toml"}, 84 | {"url": "https://github.com/leanprover/lean4-cli", 85 | "type": "git", 86 | "subDir": null, 87 | "scope": "leanprover", 88 | "rev": "933fce7e893f65969714c60cdb4bd8376786044e", 89 | "name": "Cli", 90 | "manifestFile": "lake-manifest.json", 91 | "inputRev": "v4.26.0", 92 | "inherited": true, 93 | "configFile": "lakefile.toml"}], 94 | "name": "LeanCamCombi", 95 | "lakeDir": ".lake"} 96 | -------------------------------------------------------------------------------- /scripts/upstreaming_dashboard.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """ 4 | This script parse the aggregate json file and filters all PRs which touch some given files. 5 | """ 6 | 7 | import json 8 | import os 9 | from typing import List 10 | import subprocess 11 | import json 12 | import pathlib 13 | 14 | def main(): 15 | pr_file = subprocess.run(["curl", "https://raw.githubusercontent.com/leanprover-community/queueboard/refs/heads/master/processed_data/open_pr_data.json"], 16 | capture_output = True, 17 | text = True) 18 | pr_json = json.loads(pr_file.stdout)["pr_statusses"] 19 | pr_dict = {pr["number"] : pr for pr in pr_json} 20 | 21 | file_touched_pr = {} 22 | for pr in pr_dict: 23 | for file in pr_dict[pr]["files"]: 24 | pr_data = { 25 | "number" : pr, 26 | "title" : pr_dict[pr]["title"], 27 | "num_files": len(pr_dict[pr]["files"]), 28 | "is_draft": pr_dict[pr]["is_draft"] 29 | } 30 | if file not in file_touched_pr: file_touched_pr[file] = [pr_data] 31 | else: file_touched_pr[file].append(pr_data) 32 | 33 | project_files = {} 34 | for entry in pathlib.Path("LeanCamCombi").rglob("*.lean"): 35 | code = None 36 | with open(entry, 'r') as reader: 37 | code = reader.read() 38 | entry = str(entry) 39 | file = "/".join(entry.split("/")[1:]) 40 | project_files[entry] = { 41 | "prs" : [] if file not in file_touched_pr else file_touched_pr[file], 42 | "num_sorries" : code.count("sorry"), 43 | "depends" : "import LeanCamCombi" in code 44 | } 45 | 46 | folder_path = "./website/_includes" 47 | if not os.path.exists(folder_path): 48 | os.makedirs(folder_path) 49 | 50 | with open(f"{folder_path}/ready_to_upstream.md", 'w+') as writer: 51 | text = "" 52 | for file_path in project_files: 53 | if project_files[file_path]["num_sorries"] > 0: continue 54 | if project_files[file_path]["depends"]: continue 55 | module_name = file_path.replace('/','.')[:-5] 56 | text += f"* [`{module_name}`](https://github.com/YaelDillies/LeanCamCombi/blob/master/{file_path}) \n" 57 | for pr in project_files[file_path]["prs"]: 58 | if pr["title"][:4] == "perf": continue 59 | if pr["is_draft"]: continue 60 | 61 | text += f" * " 62 | text += f" [" 63 | text += '' 64 | text += f" {pr['title']} #{pr['number']}](https://github.com/leanprover-community/mathlib4/pull/{pr['number']})" 65 | 66 | text +="\n" 67 | writer.write(text) 68 | 69 | with open(f"{folder_path}/easy_to_unlock.md", 'w+') as writer: 70 | text = "" 71 | for file_path in project_files: 72 | if project_files[file_path]["num_sorries"] == 0: continue 73 | if project_files[file_path]["depends"]: continue 74 | num_sorries = project_files[file_path]["num_sorries"] 75 | module_name = file_path.replace('/','.')[:-5] 76 | if num_sorries == 1: 77 | text += f"* [`{module_name}`](https://github.com/YaelDillies/LeanCamCombi/blob/master/{file_path}) {num_sorries} sorry\n" 78 | else: 79 | text += f"* [`{module_name}`](https://github.com/YaelDillies/LeanCamCombi/blob/master/{file_path}) {num_sorries} sorries\n" 80 | 81 | writer.write(text) 82 | 83 | main() 84 | -------------------------------------------------------------------------------- /LeanCamCombi/GraphTheory/ExampleSheet2.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Copyright (c) 2022 Yaël Dillies, Kexing Ying. All rights reserved. 3 | Released under Apache 2.0 license as described in the file LICENSE. 4 | Authors: Yaël Dillies, Kexing Ying 5 | -/ 6 | import Mathlib.Combinatorics.Hall.Basic 7 | import Mathlib.Combinatorics.SimpleGraph.Acyclic 8 | import Mathlib.Combinatorics.SimpleGraph.Clique 9 | import Mathlib.Data.Real.Sqrt 10 | import Mathlib.SetTheory.Cardinal.Basic 11 | 12 | /-! 13 | # Graph Theory, example sheet 2 14 | 15 | Here are the statements (and hopefully soon proofs!) of the questions from the second example sheet 16 | of the Cambridge Part II course Graph Theory. 17 | 18 | If you solve a question in Lean, feel free to open a Pull Request on Github! 19 | -/ 20 | 21 | 22 | /-! 23 | ### Question 1 24 | 25 | For a graph $$G$$, show that $$κ(G) ≤ fun(G) ≤ δ(G)$$. 26 | -/ 27 | 28 | 29 | /-! 30 | ### Question 2 31 | 32 | Let $$G be a graph. Show that $$e(G) > {χ(G) \choose 2}$$. 33 | -/ 34 | 35 | 36 | /-! 37 | ### Question 3 38 | 39 | Let $$G$$ be a $$k$$-connected graph and let $$y, x_1, \dots, x_k$$ be distinct vertices in $$G$$. 40 | Show that there exists paths $$P_1, \dots, P_k$$, where $$P_i$$ is a $$y − x_i$$ path and 41 | $$P_1, \dots, P_k$$ have no vertices in common, apart from the vertex $$y$$. 42 | -/ 43 | 44 | 45 | /-! 46 | ### Question 4 47 | 48 | An independent set in a graph $$G = (V, E)$$ is a subset $$I ⊆ V$$ so that $$x ≁ y$$ for all 49 | $$x, y ∈ I$$. Let $$G = (V, E)$$ be a connected graph with $$∆(G) ≤ 3$$ and $$|V| ≥ 10$$. Show that 50 | there exists an independent set $$I ⊆ V$$ so that every odd cycle in $$G$$ intersects $$I$$. 51 | -/ 52 | 53 | 54 | /-! 55 | ### Question 5 56 | 57 | Determine the chromatic polynomial of the $$n$$-cycle $$C_n$$. 58 | -/ 59 | 60 | 61 | /-! 62 | ### Question 6 63 | 64 | Let $$G$$ be a graph on $$n$$ vertices, show that the coefficients of the chromatic polynomial 65 | $$P_G$$ alternate in sign. That is, if $$P_G = P_ni=0 cit 66 | i 67 | , Then cn−j > 0 for even j and cn−j 6 0 for odd j. Also 68 | show that if G has m edges and k triangles then cn−2 = 69 | m 70 | 2 71 |  72 | − k. 73 | -/ 74 | 75 | 76 | /-! 77 | ### Question 7 78 | 79 | Determine $$χ(K_{n,n}$$). Determine $$χ(K_n)$$. 80 | -/ 81 | 82 | 83 | /-! 84 | ### Question 8 85 | 86 | Let $$G$$ be a graph that has an orientation where the longest directed path has length $$t$$ (that 87 | is, a sequence of oriented edges $$(v_1, v_2), \dots, (v_t, v_{t + 1})$$. Then $$χ(G) ≤ t + 1$$. 88 | -/ 89 | 90 | 91 | /-! 92 | ### Question 9 93 | 94 | Can $$K_{4, 4}$$ be drawn on the torus? What about $$K_{5, 5}$$? 95 | -/ 96 | 97 | 98 | /-! 99 | ### Question 10 100 | 101 | Let $$G$$ be a bipartite graph with maximum degree $$∆$$. Must we have $$χ(G) = ∆(G)$$? 102 | -/ 103 | 104 | 105 | /-! 106 | ### Question 11 107 | 108 | Let $$G = (V, E)$$ be a graph where $$V$$, $$E$$ are countably infinite. Show that $$χ(G) ≤ k$$ if 109 | and only if $$χ(H) ≤ k$$ for every finite subgraph $$H$$ of $$G$$. 110 | -/ 111 | 112 | 113 | /-! 114 | ### Question 12 115 | 116 | For $$k > 2$$, let $$G = (V, E)$$ be a $$k$$-connected graph and let $${x_1, \dots, x_k} ⊆ V$$. Show 117 | that there exists a cycle containing each of the vertices $$x_1, \dots, x_k$$. 118 | -/ 119 | 120 | 121 | /-! 122 | ### Question 13 123 | 124 | For each $$r > 2$$, construct a graph $$G$$ that does not contain a $$K_{r + 1}$$ and $$χ(G) > r$$. 125 | -/ 126 | 127 | 128 | /-! 129 | ### Question 14 130 | 131 | A graph is outer-planar if it can be drawn in the plane so that all of its vertices are on the 132 | infinite face. Articulate a conjecture of the form “Let $$G$$ be a graph with $$|G| > 5$$. $$G$$ is 133 | outer-planar if and only if ...”. Prove your conjecture. 134 | -/ 135 | 136 | 137 | /-! 138 | ### Question 15 139 | 140 | Show there is a triangle free graph with chromatic number $$2022$$. 141 | -/ 142 | 143 | 144 | /-! 145 | ### Question 16 146 | 147 | Let $$G$$ be a triangulation (a plane graph where every face is a triangle) and let $$G◦$$ be the 148 | planar dual of $$G$$: the vertices of $$G◦$$ are the faces of $$G$$ and edges in $$G◦$$ join faces 149 | that share a boundary edge (in $$G$$). Prove that $$χ(G) ≤ 4$$ if and only if $$χ(G◦) ≤ 3$$. 150 | -/ 151 | -------------------------------------------------------------------------------- /LeanCamCombi/PlainCombi/VanDenBergKesten.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Copyright (c) 2022 Yaël Dillies. All rights reserved. 3 | Released under Apache 2.0 license as described in the file LICENSE. 4 | Authors: Yaël Dillies 5 | -/ 6 | import Mathlib.Data.Finset.Sups 7 | import Mathlib.Data.Fintype.Basic 8 | import Mathlib.Order.UpperLower.Basic 9 | 10 | /-! 11 | # Set family certificates 12 | 13 | This file defines the certificator of two families of sets. If we consider set families `𝒜` and `ℬ` 14 | as probabilistic events, the size of the certificator `𝒜 □ ℬ` corresponds to the probability that 15 | `𝒜` and `ℬ` occur "disjointly". 16 | 17 | ## Main declarations 18 | 19 | * `finset.certificator`: Certificator of two elements of a Boolean algebra 20 | * `finset.card_certificator_le`: The Van den Berg-Kesten-Reimer inequality: The probability that `𝒜` 21 | and `ℬ` occur "disjointly" is less than the product of their probabilities. 22 | 23 | ## References 24 | 25 | * D. Reimer, *Proof of the Van den Berg–Kesten Conjecture* 26 | -/ 27 | 28 | open scoped FinsetFamily 29 | 30 | variable {α : Type*} 31 | 32 | namespace Finset 33 | section BooleanAlgebra 34 | variable [BooleanAlgebra α] (s t u : Finset α) {a : α} 35 | 36 | noncomputable def certificator : Finset α := 37 | open scoped Classical in 38 | {a ∈ s ∩ t | ∃ x y, IsCompl x y ∧ (∀ ⦃b⦄, a ⊓ x = b ⊓ x → b ∈ s) ∧ ∀ ⦃b⦄, a ⊓ y = b ⊓ y → b ∈ t} 39 | 40 | scoped[FinsetFamily] infixl:70 " □ " => Finset.certificator 41 | 42 | variable {s t u} 43 | 44 | @[simp] lemma mem_certificator : 45 | a ∈ s □ t ↔ 46 | ∃ x y, IsCompl x y ∧ (∀ ⦃b⦄, a ⊓ x = b ⊓ x → b ∈ s) ∧ ∀ ⦃b⦄, a ⊓ y = b ⊓ y → b ∈ t := by 47 | classical 48 | rw [certificator, mem_filter, and_iff_right_of_imp] 49 | rintro ⟨u, v, _, hu, hv⟩ 50 | exact mem_inter.2 ⟨hu rfl, hv rfl⟩ 51 | 52 | lemma certificator_subset_inter [DecidableEq α] : s □ t ⊆ s ∩ t := by 53 | unfold certificator; convert filter_subset .. 54 | 55 | open scoped Classical in 56 | lemma certificator_subset_disjSups : s □ t ⊆ s ○ t := by 57 | simp_rw [subset_iff, mem_certificator, mem_disjSups] 58 | rintro x ⟨u, v, huv, hu, hv⟩ 59 | refine ⟨x ⊓ u, hu (inf_right_idem _ _).symm, x ⊓ v, hv (inf_right_idem _ _).symm, 60 | huv.disjoint.mono inf_le_right inf_le_right, ?_⟩ 61 | rw [← inf_sup_left, huv.codisjoint.eq_top, inf_top_eq] 62 | 63 | variable (s t u) 64 | 65 | lemma certificator_comm : s □ t = t □ s := by 66 | ext s; rw [mem_certificator, exists_comm]; simp [isCompl_comm, and_comm] 67 | 68 | lemma IsUpperSet.certificator_eq_inter [DecidableEq α] (hs : IsUpperSet (s : Set α)) 69 | (ht : IsLowerSet (t : Set α)) : s □ t = s ∩ t := by 70 | refine 71 | certificator_subset_inter.antisymm fun a ha ↦ mem_certificator.2 ⟨a, aᶜ, isCompl_compl, ?_⟩ 72 | rw [mem_inter] at ha 73 | simp only [@eq_comm _ ⊥, ← sdiff_eq, inf_idem, right_eq_inf, _root_.sdiff_self, sdiff_eq_bot_iff] 74 | exact ⟨fun b hab ↦ hs hab ha.1, fun b hab ↦ ht hab ha.2⟩ 75 | 76 | lemma IsLowerSet.certificator_eq_inter [DecidableEq α] (hs : IsLowerSet (s : Set α)) 77 | (ht : IsUpperSet (t : Set α)) : s □ t = s ∩ t := by 78 | refine certificator_subset_inter.antisymm fun a ha ↦ 79 | mem_certificator.2 ⟨aᶜ, a, isCompl_compl.symm, ?_⟩ 80 | rw [mem_inter] at ha 81 | simp only [@eq_comm _ ⊥, ← sdiff_eq, inf_idem, right_eq_inf, _root_.sdiff_self, sdiff_eq_bot_iff] 82 | exact ⟨fun b hab ↦ hs hab ha.1, fun b hab ↦ ht hab ha.2⟩ 83 | 84 | open scoped Classical in 85 | lemma IsUpperSet.certificator_eq_disjSups (hs : IsUpperSet (s : Set α)) 86 | (ht : IsUpperSet (t : Set α)) : s □ t = s ○ t := by 87 | refine certificator_subset_disjSups.antisymm fun a ha ↦ mem_certificator.2 ?_ 88 | obtain ⟨x, hx, y, hy, hxy, rfl⟩ := mem_disjSups.1 ha 89 | refine ⟨x, xᶜ, isCompl_compl, ?_⟩ 90 | simp only [inf_of_le_right, le_sup_left, right_eq_inf, ← sdiff_eq, hxy.sup_sdiff_cancel_left] 91 | exact ⟨fun b hab ↦ hs hab hx, fun b hab ↦ ht (hab.trans_le sdiff_le) hy⟩ 92 | 93 | end BooleanAlgebra 94 | 95 | open scoped FinsetFamily 96 | 97 | variable [DecidableEq α] [Fintype α] {𝒜 ℬ 𝒞 : Finset (Finset α)} 98 | 99 | /-- The **Van den Berg-Kesten-Reimer Inequality**: The probability that `𝒜` and `ℬ` occur 100 | "disjointly" is less than the product of their probabilities. -/ 101 | lemma card_certificator_le : 2 ^ Fintype.card α * #(𝒜 □ ℬ) ≤ #𝒜 * #ℬ := sorry 102 | 103 | end Finset 104 | -------------------------------------------------------------------------------- /LeanCamCombi/GrowthInGroups/Lecture1.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Copyright (c) 2024 Yaël Dillies. All rights reserved. 3 | Released under Apache 2.0 license as described in the file LICENSE. 4 | Authors: Yaël Dillies 5 | -/ 6 | import Mathlib.Analysis.SpecialFunctions.Log.Basic 7 | import Mathlib.Combinatorics.Additive.DoublingConst 8 | import Mathlib.Combinatorics.Additive.VerySmallDoubling 9 | import Mathlib.Geometry.Group.Growth.LinearLowerBound 10 | import Mathlib.GroupTheory.Nilpotent 11 | import Mathlib.LinearAlgebra.Matrix.SpecialLinearGroup 12 | import LeanCamCombi.Util 13 | 14 | /-! 15 | # Growth in Groups - Lecture 1 16 | 17 | This file contains a Lean formalisation of the statements and proofs given in lecture 1 of the ETH 18 | course Growth in Groups lectured by Simon Machado in autumn/winter 2024. 19 | 20 | ## References 21 | 22 | [Lecture notes by Simon Machado](https://sites.google.com/view/simonmachado/teaching) 23 | -/ 24 | 25 | open Finset Fintype Group MulOpposite Real 26 | open scoped Combinatorics.Additive MatrixGroups Pointwise 27 | 28 | namespace GrowthInGroups.Lecture1 29 | variable {G : Type*} [Group G] [DecidableEq G] {A X : Finset G} {n : ℕ} {K : ℝ} 30 | 31 | /-- The growth of a set generating an infinite group is at least linear. -/ 32 | lemma fact_1_1_1 [Infinite G] (hX₁ : 1 ∈ X) (hXgen : Subgroup.closure (X : Set G) = ⊤) (n : ℕ) : 33 | n + 1 ≤ #(X ^ n) := add_one_le_card_pow hX₁ (by simp [hXgen, Set.infinite_univ]) _ 34 | 35 | /-- The growth of a set is at most exponential. -/ 36 | lemma fact_1_1_2 : #(X ^ n) ≤ #X ^ n := card_pow_le 37 | 38 | variable (G) in 39 | /-- A group **has polynomial growth** if any (equivalently, all) of its finite symmetric sets 40 | has polynomial growth. -/ 41 | def HasPolynomialGrowth : Prop := 42 | ∃ X : Finset G, X⁻¹ = X ∧ Subgroup.closure (X : Set G) = ⊤ ∧ ∃ d, ∀ n ≥ 2, #(X ^ n) ≤ n ^ d 43 | 44 | /-- **Gromov's theorem**. 45 | 46 | A group has polynomial growth iff it's virtually nilpotent. -/ 47 | @[nolint unusedArguments] 48 | lemma theorem_1_2 [Group.FG G] : HasPolynomialGrowth G ↔ IsVirtuallyNilpotent G := showcased 49 | 50 | lemma fact_1_3 [Fintype G] (hn : X ^ n = univ) : log (card G) / log #X ≤ n := by 51 | obtain rfl | hX := X.eq_empty_or_nonempty 52 | · simp 53 | refine div_le_of_le_mul₀ (log_nonneg <| by simpa) (by positivity) ?_ 54 | rw [← log_pow, ← Nat.cast_pow, ← card_univ, ← hn] 55 | gcongr 56 | exact card_pow_le 57 | 58 | /-- **Babai's conjecture**. 59 | 60 | For all finite sets `X` generating a simple group `G`, there exists a universal polynomial 61 | (in `log |G|`) upper bound to the number of steps `X` takes to generate `G`. -/ 62 | lemma conjecture_1_4 : 63 | ∃ Cᵤ ≥ 0, ∃ dᵤ ≥ 0, 64 | ∀ {G} [Group G] [IsSimpleGroup G] [Fintype G] [DecidableEq G] (X : Finset G) 65 | (_hX₁ : 1 ∈ X) (_hXsymm : X⁻¹ = X) (_hXclos : Subgroup.closure (X : Set G) = ⊤), 66 | ∃ m : ℕ, m ≤ Cᵤ * log (card G) ^ dᵤ ∧ X ^ m = univ := showcased 67 | 68 | -- Not even trying to state the collar lemma 69 | 70 | open scoped Classical in 71 | /-- An auxiliary lemma used in the proof of the collar theorem. -/ 72 | lemma proposition_1_7 : 73 | ∃ ε > 0, ∀ X : Finset SL(2, ℝ), #(X ^ 2) ≤ 1000 * #X → (∀ M ∈ X, ∀ i j, |M i j| ≤ ε) → 74 | ∃ A : Subgroup SL(2, ℝ), IsMulCommutative A ∧ 75 | ∃ a : Fin 10000000 → SL(2, ℝ), (X : Set SL(2, ℝ)) ⊆ ⋃ i, a i • A := showcased 76 | 77 | /-- The **Breuillard-Green-Tao theorem**. -/ 78 | lemma theorem_1_8 : 79 | ∃ C > 0, ∀ {G} [Group G] [DecidableEq G] (A : Finset G) (_hA : σₘ[A] ≤ K), 80 | ∃ (N : Subgroup G) (D : Subgroup N) (_hD : D.Normal), 81 | upperCentralSeries (N⧸ D) C = ⊤ ∧ ((↑) '' (D : Set N) : Set G) ⊆ (A / A) ^ 4 ∧ 82 | ∃ a : Fin C → G, (A : Set G) ⊆ ⋃ i, a i • N := showcased 83 | 84 | open scoped Classical in 85 | /-- The **product theorem**, due Breuillard-Green-Tao and Pyber-Szabo. 86 | 87 | A set in `SLₙ(k)` either has big tripling or is very big. In other words, there is no small 88 | tripling, except in trivial situations. -/ 89 | lemma theorem_1_9 : 90 | ∃ δ > 0, ∃ ε > 0, 91 | ∀ k [Field k] [Fintype k] [DecidableEq k] (A : Finset SL(n, k)) 92 | (_hAgen : Subgroup.closure (A : Set SL(n, k)) = ⊤), 93 | #A ^ (1 + δ) ≤ #(A ^ 3) ∨ card SL(n, k) ^ (1 - ε) ≤ #A := proved_later 94 | 95 | open MulAction in 96 | open scoped RightActions in 97 | /-- A non-empty set `A` with no doubling is the coset of a subgroup `H`. 98 | 99 | Precisely, `H` can be taken to be the stabiliser of `A` and `A` then is both a left and right coset 100 | of `H`. -/ 101 | lemma fact_1_10 (hA : #(A * A) ≤ #A) : 102 | ∃ H : Subgroup G, ∀ a ∈ A, a •> (H : Set G) = A ∧ (H : Set G) <• a = A := 103 | ⟨stabilizer G A, fun _a ha ↦ 104 | ⟨smul_stabilizer_of_no_doubling hA ha, op_smul_stabilizer_of_no_doubling hA ha⟩⟩ 105 | 106 | open scoped Classical RightActions in 107 | /-- A set `A` of tripling strictly less than three halves can be contained in a coset of a subgroup 108 | `H` of size strictly `|H| < 3/2 |A|`. 109 | 110 | One can furthermore arrange for `A` to lie in the centraliser of `H`. -/ 111 | lemma lemma_1_11 (hA : #(A * A) < (3 / 2 : ℚ) * #A) : 112 | ∃ (H : Subgroup G) (_ : Fintype H), 113 | (card H : ℚ≥0) < 3 / 2 * #A ∧ ∀ a ∈ A, (A : Set G) ⊆ a • H ∧ a • (H : Set G) = H <• a := 114 | doubling_lt_three_halves hA 115 | 116 | end GrowthInGroups.Lecture1 117 | -------------------------------------------------------------------------------- /LeanCamCombi/Mathlib/Probability/Distributions/Bernoulli.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Copyright (c) 2025 Yaël Dillies. All rights reserved. 3 | Released under Apache 2.0 license as described in the file LICENSE. 4 | Authors: Yaël Dillies 5 | -/ 6 | import LeanCamCombi.Mathlib.Probability.HasLaw 7 | import Mathlib.Probability.IdentDistrib 8 | import Mathlib.Probability.ProductMeasure 9 | 10 | /-! 11 | # Bernoulli random variables 12 | 13 | This file defines the binomial random distribution on a set. For a set `u : Set ι` and `p` between 14 | `0` and `1`, this is the measure on `Set ι` such that each `i ∈ u` belongs to the random set with 15 | probability `p`, and each `i ∉ u` doesn't belong to it. 16 | 17 | ## Notation 18 | 19 | `Ber(u, p)` is the product of `p`-Bernoulli distributions on `u`. 20 | 21 | ## TODO 22 | 23 | Add the characteristic predicate for a random variable to follow the Bernoulli distribution. 24 | -/ 25 | 26 | open MeasureTheory Measure unitInterval 27 | open scoped Finset 28 | 29 | namespace ProbabilityTheory 30 | variable {ι Ω : Type*} {m : MeasurableSpace Ω} {X Y : Ω → Set ι} {s u : Set ι} {i j : ι} {p q : I} 31 | {P : Measure Ω} 32 | 33 | variable (u p) in 34 | /-- The binomial distribution with parameter `p` on the set `u : Set V` is the measure on `Set V` 35 | such that each element of `u` is taken with probability `p`, and the elements outside of `u` are 36 | never taken. -/ 37 | noncomputable def bernoulliOn : Measure (Set ι) := 38 | .comap (fun s i ↦ i ∈ s) <| infinitePi fun i ↦ 39 | toNNReal p • dirac (i ∈ u) + toNNReal (σ p) • dirac False 40 | 41 | @[inherit_doc] scoped notation "Ber(" u ", " p ")" => bernoulliOn u p 42 | 43 | instance : IsProbabilityMeasure Ber(u, p) := 44 | MeasurableEquiv.setOf.symm.measurableEmbedding.isProbabilityMeasure_comap <| .of_forall fun P ↦ 45 | ⟨{a | P a}, rfl⟩ 46 | 47 | variable (u p) in 48 | lemma bernoulliOn_eq_map : 49 | Ber(u, p) = .map (fun p ↦ {i | p i}) 50 | (infinitePi fun i ↦ toNNReal p • dirac (i ∈ u) + toNNReal (σ p) • dirac False) := 51 | MeasurableEquiv.setOf.comap_symm 52 | 53 | lemma bernoulliOn_apply (S : Set (Set ι)) : 54 | Ber(u, p) S = (infinitePi fun a ↦ toNNReal p • dirac (a ∈ u) + toNNReal (σ p) • dirac False) 55 | ((fun t a ↦ a ∈ t) '' S) := by 56 | convert MeasurableEquiv.setOf.symm.measurableEmbedding.comap_apply .. 57 | 58 | lemma bernoulliOn_apply' (S : Set (Set ι)) : 59 | Ber(u, p) S = (infinitePi fun a ↦ toNNReal p • dirac (a ∈ u) + toNNReal (σ p) • dirac False) 60 | ((fun p ↦ {a | p a}) ⁻¹' S) := by 61 | convert MeasurableEquiv.setOf.symm.comap_apply .. 62 | 63 | variable (u) in 64 | @[simp] lemma bernoulliOn_zero : Ber(u, 0) = dirac ∅ := by simp [bernoulliOn_eq_map] 65 | 66 | variable (u) in 67 | @[simp] lemma bernoulliOn_one : Ber(u, 1) = dirac u := by simp [bernoulliOn_eq_map] 68 | 69 | section Countable 70 | variable [Countable ι] 71 | 72 | -- TODO: Does this hold if `ι` isn't countable? Note: the current proof only needs `u` cocountable, 73 | -- but we don't bother doing this minigeneralisation. 74 | lemma bernoulliOn_ae_subset : ∀ᵐ s ∂Ber(u, p), s ⊆ u := by 75 | classical 76 | change _ = _ 77 | simp only [Set.compl_setOf, Set.not_subset_iff_exists_mem_notMem, Set.setOf_exists, Set.setOf_and, 78 | measure_iUnion_null_iff] 79 | rintro a 80 | by_cases ha : a ∈ u 81 | · simp [*] 82 | calc 83 | Ber(u, p) ({s | a ∈ s} ∩ {s | a ∉ u}) 84 | _ = Ber(u, p) {s | a ∈ s} := by simp [ha] 85 | _ = infinitePi (fun a ↦ toNNReal p • dirac (a ∈ u) + toNNReal (σ p) • dirac False) 86 | (cylinder {a} {fun _ ↦ True}) := by 87 | rw [bernoulliOn_apply'] 88 | congr! 89 | ext 90 | simp [funext_iff] 91 | _ = 0 := by simp [infinitePi_cylinder _ (.singleton _), ha] 92 | 93 | end Countable 94 | 95 | variable (u p) in 96 | -- TODO: Generalise to countable `ι` and finite `u`. See the TODO on `infinitePi_pi`. 97 | @[simp] lemma bernoulliOn_singleton [Finite ι] (hsu : s ⊆ u) : 98 | Ber(u, p) {s} = toNNReal p ^ s.ncard * toNNReal (σ p) ^ (u \ s).ncard := by 99 | classical 100 | cases nonempty_fintype ι 101 | lift u to Finset ι using Set.toFinite _ 102 | calc 103 | Ber(u, p) {s} 104 | _ = ∏ i, ((if i ∈ u ↔ i ∈ s then (toNNReal p : ENNReal) else 0) + 105 | if i ∈ s then 0 else (toNNReal (σ p) : ENNReal)) := by 106 | simp [bernoulliOn_apply, Set.image_singleton, Set.indicator] 107 | simp [ENNReal.smul_def] 108 | _ = ∏ i ∈ u, (if i ∈ s then (toNNReal p : ENNReal) else (toNNReal (σ p) : ENNReal)) := by 109 | rw [← Finset.prod_subset u.subset_univ (by 110 | simpa +contextual [ite_add_ite, ← ENNReal.coe_add] using fun _ ↦ mt (@hsu _))] 111 | simp +contextual [ite_add_ite] 112 | _ = toNNReal p ^ s.ncard * toNNReal (σ p) ^ (↑u \ s).ncard := by 113 | simp [Finset.prod_ite, ← Set.ncard_coe_finset, Set.setOf_and, 114 | Set.inter_eq_right.2 hsu, ← Set.compl_setOf, Set.diff_eq_compl_inter, Set.inter_comm] 115 | 116 | /-! ### Bernoulli random variables -/ 117 | 118 | variable (X u p P) in 119 | /-- A random variable `X : Ω → Set ι` is `p`-bernoulli on a set `u : Set ι` if its distribution is 120 | the product over `u` of `p`-bernoulli random variables. -/ 121 | abbrev IsBernoulliOn : Prop := HasLaw X Ber(u, p) P 122 | 123 | lemma isBernoulliOn_congr (hXY : X =ᵐ[P] Y) : IsBernoulliOn X u p P ↔ IsBernoulliOn Y u p P := 124 | hasLaw_congr hXY 125 | 126 | lemma IsBernoulliOn.identDistrib_mem (hX : IsBernoulliOn X u p P) (hi : i ∈ u) (hj : j ∈ u) : 127 | IdentDistrib (fun ω ↦ i ∈ X ω) (fun ω ↦ j ∈ X ω) P P where 128 | aemeasurable_fst := by fun_prop 129 | aemeasurable_snd := by fun_prop 130 | map_eq := sorry 131 | 132 | lemma IsBernoulliOn.iIndepFun_mem (hX : IsBernoulliOn X u p P) : 133 | iIndepFun (fun i ω ↦ i ∈ X ω) P := sorry 134 | 135 | lemma IsBernoulliOn.sdiff (hX : IsBernoulliOn X u p P) : 136 | IsBernoulliOn (fun ω ↦ u \ X ω) u (σ p) P where 137 | map_eq := sorry 138 | aemeasurable := sorry 139 | 140 | lemma IsBernoulliOn.inter (hX : IsBernoulliOn X u p P) (hY : IsBernoulliOn Y u q P) : 141 | IsBernoulliOn (fun ω ↦ X ω ∩ Y ω) u (p * q) P where 142 | map_eq := sorry 143 | aemeasurable := sorry 144 | 145 | variable [Countable ι] 146 | 147 | lemma IsBernoulliOn.ae_subset (hX : IsBernoulliOn X u p P) : ∀ᵐ ω ∂P, X ω ⊆ u := 148 | (hX.ae_iff sorry).2 bernoulliOn_ae_subset 149 | 150 | lemma IsBernoulliOn.union (hX : IsBernoulliOn X u p P) (hY : IsBernoulliOn Y u q P) : 151 | IsBernoulliOn (fun ω ↦ X ω ∪ Y ω) u (σ <| σ p * σ q) P := by 152 | convert (hX.sdiff.inter hY.sdiff).sdiff using 0 153 | refine isBernoulliOn_congr ?_ 154 | filter_upwards [hX.ae_subset, hY.ae_subset] with ω hXω hYω 155 | rw [Set.diff_inter, Set.diff_diff_cancel_left hXω, Set.diff_diff_cancel_left hYω] 156 | 157 | end ProbabilityTheory 158 | -------------------------------------------------------------------------------- /LeanCamCombi/Mathlib/Probability/Combinatorics/BinomialRandomGraph/Defs.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Copyright (c) 2025 Yaël Dillies. All rights reserved. 3 | Released under Apache 2.0 license as described in the file LICENSE. 4 | Authors: Yaël Dillies 5 | -/ 6 | import LeanCamCombi.Mathlib.Probability.Distributions.Bernoulli 7 | import Mathlib.Combinatorics.SimpleGraph.Basic 8 | import Mathlib.Data.Sym.Card 9 | 10 | /-! 11 | # Binomial random graphs 12 | 13 | This file defines the distribution of binomial random graphs. 14 | -/ 15 | 16 | open MeasureTheory Measure ProbabilityTheory unitInterval Sym2 17 | open scoped Finset 18 | 19 | namespace SimpleGraph 20 | variable {V Ω : Type*} {m : MeasurableSpace Ω} {G H : Ω → SimpleGraph V} {e₁ e₂ : Sym2 V} {p q : I} 21 | {P : Measure Ω} 22 | 23 | /-! 24 | ### Sigma-algebra on simple graphs 25 | 26 | In this section, we pull back the sigma-algebra on `V → V → Prop` to a sigma-algebra on 27 | `SimpleGraph V` and prove that common operations are measurable. 28 | 29 | #### TODO 30 | 31 | This could move to an earlier file once/if we need this sigma-algebra in other contexts. 32 | 33 | ## Tags 34 | 35 | Erdős-Rényi graph, Erdős-Renyi graph, Erdös-Rényi graph, Erdös-Renyi graph, Erdos-Rényi graph, 36 | Erdos-Renyi graph 37 | -/ 38 | 39 | instance : MeasurableSpace (SimpleGraph V) := .comap Adj inferInstance 40 | 41 | /-- A simple graph-valued map is measurable iff all induced adjacency maps are measurable. -/ 42 | lemma measurable_iff_adj {Ω : Type*} {m : MeasurableSpace Ω} {G : Ω → SimpleGraph V} : 43 | Measurable G ↔ ∀ u v, Measurable fun ω ↦ (G ω).Adj u v := by 44 | simp [measurable_comap_iff, measurable_pi_iff] 45 | 46 | @[fun_prop] 47 | lemma measurable_adj : Measurable (Adj : SimpleGraph V → V → V → Prop) := comap_measurable _ 48 | 49 | @[fun_prop] 50 | lemma measurable_edgeSet : Measurable (edgeSet : SimpleGraph V → Set (Sym2 V)) := 51 | measurable_set_iff.2 <| by rintro ⟨u, v⟩; simp only [mem_edgeSet]; fun_prop 52 | 53 | set_option linter.flexible false in 54 | @[simp, fun_prop] 55 | lemma measurable_fromEdgeSet : Measurable (fromEdgeSet : Set (Sym2 V) → SimpleGraph V) := by 56 | simp [measurable_iff_adj]; fun_prop 57 | 58 | lemma measurableEmbedding_edgeSet [Countable V] : 59 | MeasurableEmbedding (edgeSet : SimpleGraph V → Set (Sym2 V)) where 60 | injective := edgeSet_injective 61 | measurable := measurable_edgeSet 62 | measurableSet_image' s hs := by 63 | simp only [← measurable_mem, Set.mem_image, edgeSet_eq_iff, ↓existsAndEq, true_and, 64 | Set.disjoint_right] 65 | refine .and (hs.mem.comp measurable_fromEdgeSet) <| .forall fun e ↦ .imp ?_ ?_ <;> fun_prop 66 | 67 | /-! 68 | ### Distribution of binomial random graphs 69 | 70 | In this section, we construct the binomial distribution with parameter `p` on simple graphs with 71 | vertices `V`. This is the law `G(V, p)` of binomial random graphs with probability `p`. 72 | -/ 73 | 74 | variable (V p) in 75 | /-- The binomial distribution with parameter `p` on simple graphs with vertices `V`. -/ 76 | @[expose] 77 | noncomputable def binomialRandom : Measure (SimpleGraph V) := Ber(diagSetᶜ, p).comap edgeSet 78 | 79 | @[inherit_doc] scoped notation "G(" V ", " p ")" => binomialRandom V p 80 | 81 | section Countable 82 | variable [Countable V] 83 | 84 | variable (V p) in 85 | lemma binomialRandom_eq_map : G(V, p) = map fromEdgeSet Ber(diagSetᶜ, p) := by 86 | refine (map_eq_comap measurable_fromEdgeSet measurableEmbedding_edgeSet ?_ 87 | fromEdgeSet_edgeSet).symm 88 | filter_upwards [bernoulliOn_ae_subset] with S hS 89 | refine ⟨fromEdgeSet S, ?_⟩ 90 | simpa [Sym2.diagSet_eq_setOf_isDiag, ← Set.compl_setOf, Set.subset_compl_iff_disjoint_right] 91 | using hS 92 | 93 | lemma isBernoulliOn_edgeSet_binomialRandom : IsBernoulliOn edgeSet diagSetᶜ p G(V, p) where 94 | map_eq := by 95 | rw [binomialRandom_eq_map, map_map (by fun_prop) (by fun_prop), Measure.map_congr, 96 | Measure.map_id] 97 | filter_upwards [bernoulliOn_ae_subset] with S hS 98 | simpa [Set.subset_compl_iff_disjoint_right] using hS 99 | 100 | variable (p) in 101 | lemma binomialRandom_apply' (S : Set (SimpleGraph V)) : 102 | G(V, p) S = Ber(diagSetᶜ, p) (edgeSet '' S) := by 103 | rw [binomialRandom, measurableEmbedding_edgeSet.comap_apply] 104 | 105 | variable (p) in 106 | lemma binomialRandom_apply (S : Set (SimpleGraph V)) : 107 | G(V, p) S = (infinitePi fun e : Sym2 V ↦ 108 | toNNReal p • .dirac (¬ e.IsDiag) + toNNReal (σ p) • .dirac False) 109 | ((fun G e ↦ e ∈ G.edgeSet) '' S) := by 110 | simp [binomialRandom_apply', bernoulliOn_apply, ← Set.image_comp] 111 | 112 | instance : IsProbabilityMeasure G(V, p) := by 113 | refine measurableEmbedding_edgeSet.isProbabilityMeasure_comap ?_ 114 | filter_upwards [bernoulliOn_ae_subset] with s hs 115 | refine ⟨.fromEdgeSet s, ?_⟩ 116 | simpa [Sym2.diagSet_eq_setOf_isDiag, ← Set.disjoint_compl_right_iff_subset, ← Set.compl_setOf] 117 | using hs 118 | 119 | variable (V) in 120 | @[simp] lemma binomialRandom_zero : G(V, 0) = dirac ⊥ := by simp [binomialRandom_eq_map] 121 | 122 | variable (V) in 123 | @[simp] lemma binomialRandom_one : G(V, 1) = dirac ⊤ := by simp [binomialRandom_eq_map] 124 | 125 | end Countable 126 | 127 | variable (p) in 128 | @[simp] lemma binomialRandom_singleton [Finite V] (G : SimpleGraph V) : 129 | G(V, p) {G} = toNNReal p ^ G.edgeSet.ncard * 130 | toNNReal (σ p) ^ ((Nat.card V).choose 2 - G.edgeSet.ncard) := by 131 | classical 132 | cases nonempty_fintype V 133 | simp only [binomialRandom, measurableEmbedding_edgeSet.comap_apply, Set.image_singleton, 134 | edgeSet_subset_setOf_not_isDiag, bernoulliOn_singleton] 135 | rw [Set.ncard_diff (edgeSet_subset_setOf_not_isDiag _)] 136 | congr! 137 | rw [Nat.card_eq_fintype_card, ← Sym2.card_subtype_not_diag, Fintype.card_eq_nat_card, 138 | ← Nat.card_coe_set_eq] 139 | simp [diagSet_compl_eq_setOf_not_isDiag] 140 | 141 | /-! ### Binomial random graphs -/ 142 | 143 | variable (G p P) in 144 | /-- A random variable `G : Ω → Set ι` is `p`-bernoulli on a set `u : Set ι` if its distribution is 145 | the product over `u` of `p`-bernoulli random variables. -/ 146 | abbrev IsBinomialRandom : Prop := HasLaw G G(V, p) P 147 | 148 | lemma isBinomialRandom_congr (hGH : G =ᵐ[P] H) : IsBinomialRandom G p P ↔ IsBinomialRandom H p P := 149 | hasLaw_congr hGH 150 | 151 | lemma IsBinomialRandom.identDistrib_mem_edgeSet (hG : IsBinomialRandom G p P) : 152 | IdentDistrib (fun ω ↦ e₁ ∈ (G ω).edgeSet) (fun ω ↦ e₂ ∈ (G ω).edgeSet) P P := sorry 153 | 154 | lemma IsBinomialRandom.iIndepFun_mem_edgeSet (hG : IsBinomialRandom G p P) : 155 | iIndepFun (fun e ω ↦ e ∈ (G ω).edgeSet) P := sorry 156 | 157 | lemma IsBinomialRandom.compl (hG : IsBinomialRandom G p P) : 158 | IsBinomialRandom (fun ω ↦ (G ω)ᶜ) (σ p) P where 159 | map_eq := sorry 160 | aemeasurable := sorry 161 | 162 | lemma IsBinomialRandom.inf (hG : IsBinomialRandom G p P) (hY : IsBinomialRandom H q P) : 163 | IsBinomialRandom (fun ω ↦ G ω ⊓ H ω) (p * q) P where 164 | map_eq := sorry 165 | aemeasurable := sorry 166 | 167 | variable [Countable V] 168 | 169 | lemma IsBinomialRandom.isBernoulliOn_edgeSet (hG : IsBinomialRandom G p P) : 170 | IsBernoulliOn (fun ω ↦ (G ω).edgeSet) diagSetᶜ p P := 171 | isBernoulliOn_edgeSet_binomialRandom.comp hG 172 | 173 | lemma IsBinomialRandom.sup (hG : IsBinomialRandom G p P) (hY : IsBinomialRandom H q P) : 174 | IsBinomialRandom (fun ω ↦ G ω ⊔ H ω) (σ <| σ p * σ q) P where 175 | map_eq := sorry 176 | aemeasurable := sorry 177 | 178 | end SimpleGraph 179 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cambridge combinatorics in Lean 2 | 3 | [![.github/workflows/push.yml](https://github.com/YaelDillies/LeanCamCombi/actions/workflows/push.yml/badge.svg)](https://github.com/YaelDillies/LeanCamCombi/actions/workflows/push.yml) 4 | [![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/YaelDillies/LeanCamCombi) 5 | 6 | This repository aims at formalising the mathematics courses relevant to combinatorics that are lectured in Cambridge, UK. 7 | 8 | ## What is formalisation? 9 | 10 | The purpose of this repository is to *digitise* some mathematical definitions, theorem statements and theorem proofs. Digitisation, or formalisation, is a process where the source material, typically a mathematical textbook or a PDF file is transformed into definitions in a target system consisting of a computer implementation of a logical theory (such as set theory or type theory). 11 | 12 | ### The source 13 | 14 | The definitions, theorems and proofs in this repository are (mostly) taken from six Cambridge courses, as well as a course from ETH Zürich: 15 | * Part IV Connections between Model Theory and Combinatorics, Lent 2019, lectured by Julia Wolf 16 | * Part II Graph Theory, Michaelmas 2022, lectured by Julian Sahasrabudhe 17 | * Part III Combinatorics, Michaelmas 2022 & [Michaelmas 2023](https://github.com/YaelDillies/maths-notes/blob/master/combinatorics.pdf), lectured by Béla Bollobás 18 | * Part III Extremal and Probabilistic Combinatorics, Michaelmas 2023, lectured by Julian Sahasrabudhe 19 | * Part III [Ramsey Theory on Graphs, Michaelmas 2024](https://github.com/YaelDillies/maths-notes/blob/master/ramsey_theory.pdf), lectured by Julian Sahasrabudhe 20 | * Part III [Additive Combinatorics, Lent 2024](https://github.com/YaelDillies/maths-notes/blob/master/additive_combinatorics.pdf), lectured by Julia Wolf 21 | * ETH Math-D [Growth in Groups, Winter 2024](https://sites.google.com/view/simonmachado/teaching), lectured by Simon Machado 22 | 23 | ### The target 24 | 25 | The formal system which we are using as a target is [Lean 4](https://lean-lang.org). Lean is a dependently typed theorem prover and programming language based on the Calculus of Inductive Constructions. It is being developed at the [Lean Focused Research Organization](https://lean-fro.org) by Leonardo de Moura and his team. 26 | 27 | Our project is backed by [mathlib](https://leanprover-community.github.io), the major classical maths library written in Lean 4. 28 | 29 | ## Content 30 | 31 | The Lean code is located within the `LeanCamCombi` folder. Within it, one can find: 32 | * One subfolder for each course, containing **formal lecture transcripts** in the files named `Lecture1`, `Lecture2`, etc... and **formal example sheet translations** in the files named `ExampleSheet1`, `ExampleSheet2`, etc... We follow the mathlib philosophy of aiming for the most general result within reach. This means that not all proofs follow the lecture notes, and might instead derive a result proved in the lectures from a general theorem. Those general theorems and prerequisite lemmas are proved in other folders. Read below. 33 | * A `Mathlib` subfolder for the **prerequisites** to be upstreamed to mathlib. Lemmas that belong in an existing mathlib file `Mathlib.X` will be located in `LeanCamCombi.Mathlib.X`. We aim to preserve the property that `LeanCamCombi.Mathlib.X` only imports `Mathlib.X` and files of the form `LeanCamCombi.Mathlib.Y` where `Mathlib.X` (transitively) imports `Mathlib.Y`. Prerequisites that do not belong in any existing mathlib file are placed in subtheory folders. See below. 34 | * One folder for each **theory development**. The formal lecture transcripts only contain what was stated in the lectures, but sometimes it makes sense for a theory to be developed as a whole before being incorporated by the prerequisites or imported in the formal lecture transcripts. 35 | * An `Archive` subfolder for **archived results**. It sometimes happens in mathlib that a long argument gets replaced by a shorter one, with a different proof. When the long argument was proved in a lecture, we salvage it to `LeanCamCombi` for conservation purposes. 36 | 37 | ### Content under development 38 | 39 | The following topics are under active development in LeanCamCombi. 40 | 41 | * The Erdős-Rényi model for random graphs, aka binomial random graph 42 | * The Littlewood-Offord problem 43 | * The van den Berg-Kesten-Reimer inequality 44 | * Approximate subgroups 45 | * Model theoretic stability and its relation to additive combinatorics 46 | 47 | See the [upstreaming dashboard](https://yaeldillies.github.io/LeanCamCombi/upstreaming) for more information. 48 | 49 | ### Current content 50 | 51 | The following topics are covered in LeanCamCombi and could be upstreamed to Mathlib. 52 | 53 | * Kneser's addition theorem 54 | * The Sylvester-Chvatal theorem 55 | * Containment of graphs 56 | 57 | See the [upstreaming dashboard](https://yaeldillies.github.io/LeanCamCombi/upstreaming) for more information. 58 | 59 | The following topics are archived because they are already covered by mathlib, but nevertheless display interesting proofs: 60 | * The Cauchy-Davenport theorem for `ℤ/pℤ` as a corollary of Kneser's theorem. 61 | 62 | ### Past content 63 | 64 | The following topics have been upstreamed to mathlib and no longer live in LeanCamCombi. 65 | 66 | * The Ahlswede-Zhang inequality 67 | * The four functions theorem and related discrete correlation inequalities: FKG inequality, Holley inequality, Daykin inequality, Marica-Schönheim inequality 68 | * The Marica-Schönheim proof of the squarefree special case of Graham's conjecture 69 | * The Cauchy-Davenport theorem for general groups, and also for linearly ordered cancellative semigroup 70 | * The Erdős-Ginzburg-Ziv theorem 71 | * Chevalley's theorem about constructible sets with and without a complexity bound 72 | 73 | ## Interacting with the project 74 | 75 | ### Getting the project 76 | 77 | To build the Lean files of this project, you need to have a working version of Lean. 78 | See [the installation instructions](https://leanprover-community.github.io/get_started.html) (under Regular install). 79 | Alternatively, click on the button below to open a Gitpod workspace containing the project. 80 | 81 | [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/YaelDillies/LeanAPAP) 82 | 83 | In either case, run `lake exe cache get` and then `lake build` to build the project. 84 | 85 | ### Browsing the project 86 | 87 | With the project opened in VScode, you are all set to start exploring the code. There are two pieces of functionality that help a lot when browsing through Lean code: 88 | 89 | * "Go to definition": If you right-click on a name of a definition or lemma (such as `IsBinomialRandomGraph`), then you can choose "Go to definition" from the menu, and you will be taken to the relevant location in the source files. This also works by `Ctrl`-clicking on the name. 90 | * "Goal view": in the event that you would like to read a *proof*, you can step through the proof line-by-line, and see the internals of Lean's "brain" in the Goal window. If the Goal window is not open, you can open it by clicking on the forall icon in the top right hand corner. 91 | 92 | ### Contributing 93 | 94 | **This project is open to contribution**. You are in fact encouraged to have a look at the example sheet translations and try your hand at one of the problems. If you manage to prove one of them, please open a PR! 95 | 96 | If you want to contribute a theorem or theory development, please open a PR! Note however that the standard of code is pretty high and that is not because you have formalised a concept/proved a theorem that it can be included into LeanCamCombi as is. Nonetheless I am willing to review your code and put it in shape for incorporation. 97 | -------------------------------------------------------------------------------- /website/Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | activesupport (6.0.5) 5 | concurrent-ruby (~> 1.0, >= 1.0.2) 6 | i18n (>= 0.7, < 2) 7 | minitest (~> 5.1) 8 | tzinfo (~> 1.1) 9 | zeitwerk (~> 2.2, >= 2.2.2) 10 | addressable (2.8.0) 11 | public_suffix (>= 2.0.2, < 5.0) 12 | coffee-script (2.4.1) 13 | coffee-script-source 14 | execjs 15 | coffee-script-source (1.11.1) 16 | colorator (1.1.0) 17 | commonmarker (0.23.4) 18 | concurrent-ruby (1.1.10) 19 | dnsruby (1.61.9) 20 | simpleidn (~> 0.1) 21 | em-websocket (0.5.3) 22 | eventmachine (>= 0.12.9) 23 | http_parser.rb (~> 0) 24 | ethon (0.15.0) 25 | ffi (>= 1.15.0) 26 | eventmachine (1.2.7) 27 | execjs (2.8.1) 28 | faraday (1.10.0) 29 | faraday-em_http (~> 1.0) 30 | faraday-em_synchrony (~> 1.0) 31 | faraday-excon (~> 1.1) 32 | faraday-httpclient (~> 1.0) 33 | faraday-multipart (~> 1.0) 34 | faraday-net_http (~> 1.0) 35 | faraday-net_http_persistent (~> 1.0) 36 | faraday-patron (~> 1.0) 37 | faraday-rack (~> 1.0) 38 | faraday-retry (~> 1.0) 39 | ruby2_keywords (>= 0.0.4) 40 | faraday-em_http (1.0.0) 41 | faraday-em_synchrony (1.0.0) 42 | faraday-excon (1.1.0) 43 | faraday-httpclient (1.0.1) 44 | faraday-multipart (1.0.3) 45 | multipart-post (>= 1.2, < 3) 46 | faraday-net_http (1.0.1) 47 | faraday-net_http_persistent (1.2.0) 48 | faraday-patron (1.0.0) 49 | faraday-rack (1.0.0) 50 | faraday-retry (1.0.3) 51 | ffi (1.15.5) 52 | forwardable-extended (2.6.0) 53 | gemoji (3.0.1) 54 | github-pages (226) 55 | github-pages-health-check (= 1.17.9) 56 | jekyll (= 3.9.2) 57 | jekyll-avatar (= 0.7.0) 58 | jekyll-coffeescript (= 1.1.1) 59 | jekyll-commonmark-ghpages (= 0.2.0) 60 | jekyll-default-layout (= 0.1.4) 61 | jekyll-feed (= 0.15.1) 62 | jekyll-gist (= 1.5.0) 63 | jekyll-github-metadata (= 2.13.0) 64 | jekyll-include-cache (= 0.2.1) 65 | jekyll-mentions (= 1.6.0) 66 | jekyll-optional-front-matter (= 0.3.2) 67 | jekyll-paginate (= 1.1.0) 68 | jekyll-readme-index (= 0.3.0) 69 | jekyll-redirect-from (= 0.16.0) 70 | jekyll-relative-links (= 0.6.1) 71 | jekyll-remote-theme (= 0.4.3) 72 | jekyll-sass-converter (= 1.5.2) 73 | jekyll-seo-tag (= 2.8.0) 74 | jekyll-sitemap (= 1.4.0) 75 | jekyll-swiss (= 1.0.0) 76 | jekyll-theme-architect (= 0.2.0) 77 | jekyll-theme-cayman (= 0.2.0) 78 | jekyll-theme-dinky (= 0.2.0) 79 | jekyll-theme-hacker (= 0.2.0) 80 | jekyll-theme-leap-day (= 0.2.0) 81 | jekyll-theme-merlot (= 0.2.0) 82 | jekyll-theme-midnight (= 0.2.0) 83 | jekyll-theme-minimal (= 0.2.0) 84 | jekyll-theme-modernist (= 0.2.0) 85 | jekyll-theme-primer (= 0.6.0) 86 | jekyll-theme-slate (= 0.2.0) 87 | jekyll-theme-tactile (= 0.2.0) 88 | jekyll-theme-time-machine (= 0.2.0) 89 | jekyll-titles-from-headings (= 0.5.3) 90 | jemoji (= 0.12.0) 91 | kramdown (= 2.3.2) 92 | kramdown-parser-gfm (= 1.1.0) 93 | liquid (= 4.0.3) 94 | mercenary (~> 0.3) 95 | minima (= 2.5.1) 96 | nokogiri (>= 1.13.4, < 2.0) 97 | rouge (= 3.26.0) 98 | terminal-table (~> 1.4) 99 | github-pages-health-check (1.17.9) 100 | addressable (~> 2.3) 101 | dnsruby (~> 1.60) 102 | octokit (~> 4.0) 103 | public_suffix (>= 3.0, < 5.0) 104 | typhoeus (~> 1.3) 105 | html-pipeline (2.14.1) 106 | activesupport (>= 2) 107 | nokogiri (>= 1.4) 108 | http_parser.rb (0.8.0) 109 | i18n (0.9.5) 110 | concurrent-ruby (~> 1.0) 111 | jekyll (3.9.2) 112 | addressable (~> 2.4) 113 | colorator (~> 1.0) 114 | em-websocket (~> 0.5) 115 | i18n (~> 0.7) 116 | jekyll-sass-converter (~> 1.0) 117 | jekyll-watch (~> 2.0) 118 | kramdown (>= 1.17, < 3) 119 | liquid (~> 4.0) 120 | mercenary (~> 0.3.3) 121 | pathutil (~> 0.9) 122 | rouge (>= 1.7, < 4) 123 | safe_yaml (~> 1.0) 124 | jekyll-avatar (0.7.0) 125 | jekyll (>= 3.0, < 5.0) 126 | jekyll-coffeescript (1.1.1) 127 | coffee-script (~> 2.2) 128 | coffee-script-source (~> 1.11.1) 129 | jekyll-commonmark (1.4.0) 130 | commonmarker (~> 0.22) 131 | jekyll-commonmark-ghpages (0.2.0) 132 | commonmarker (~> 0.23.4) 133 | jekyll (~> 3.9.0) 134 | jekyll-commonmark (~> 1.4.0) 135 | rouge (>= 2.0, < 4.0) 136 | jekyll-default-layout (0.1.4) 137 | jekyll (~> 3.0) 138 | jekyll-feed (0.15.1) 139 | jekyll (>= 3.7, < 5.0) 140 | jekyll-gist (1.5.0) 141 | octokit (~> 4.2) 142 | jekyll-github-metadata (2.13.0) 143 | jekyll (>= 3.4, < 5.0) 144 | octokit (~> 4.0, != 4.4.0) 145 | jekyll-include-cache (0.2.1) 146 | jekyll (>= 3.7, < 5.0) 147 | jekyll-mentions (1.6.0) 148 | html-pipeline (~> 2.3) 149 | jekyll (>= 3.7, < 5.0) 150 | jekyll-optional-front-matter (0.3.2) 151 | jekyll (>= 3.0, < 5.0) 152 | jekyll-paginate (1.1.0) 153 | jekyll-readme-index (0.3.0) 154 | jekyll (>= 3.0, < 5.0) 155 | jekyll-redirect-from (0.16.0) 156 | jekyll (>= 3.3, < 5.0) 157 | jekyll-relative-links (0.6.1) 158 | jekyll (>= 3.3, < 5.0) 159 | jekyll-remote-theme (0.4.3) 160 | addressable (~> 2.0) 161 | jekyll (>= 3.5, < 5.0) 162 | jekyll-sass-converter (>= 1.0, <= 3.0.0, != 2.0.0) 163 | rubyzip (>= 1.3.0, < 3.0) 164 | jekyll-sass-converter (1.5.2) 165 | sass (~> 3.4) 166 | jekyll-seo-tag (2.8.0) 167 | jekyll (>= 3.8, < 5.0) 168 | jekyll-sitemap (1.4.0) 169 | jekyll (>= 3.7, < 5.0) 170 | jekyll-swiss (1.0.0) 171 | jekyll-theme-architect (0.2.0) 172 | jekyll (> 3.5, < 5.0) 173 | jekyll-seo-tag (~> 2.0) 174 | jekyll-theme-cayman (0.2.0) 175 | jekyll (> 3.5, < 5.0) 176 | jekyll-seo-tag (~> 2.0) 177 | jekyll-theme-dinky (0.2.0) 178 | jekyll (> 3.5, < 5.0) 179 | jekyll-seo-tag (~> 2.0) 180 | jekyll-theme-hacker (0.2.0) 181 | jekyll (> 3.5, < 5.0) 182 | jekyll-seo-tag (~> 2.0) 183 | jekyll-theme-leap-day (0.2.0) 184 | jekyll (> 3.5, < 5.0) 185 | jekyll-seo-tag (~> 2.0) 186 | jekyll-theme-merlot (0.2.0) 187 | jekyll (> 3.5, < 5.0) 188 | jekyll-seo-tag (~> 2.0) 189 | jekyll-theme-midnight (0.2.0) 190 | jekyll (> 3.5, < 5.0) 191 | jekyll-seo-tag (~> 2.0) 192 | jekyll-theme-minimal (0.2.0) 193 | jekyll (> 3.5, < 5.0) 194 | jekyll-seo-tag (~> 2.0) 195 | jekyll-theme-modernist (0.2.0) 196 | jekyll (> 3.5, < 5.0) 197 | jekyll-seo-tag (~> 2.0) 198 | jekyll-theme-primer (0.6.0) 199 | jekyll (> 3.5, < 5.0) 200 | jekyll-github-metadata (~> 2.9) 201 | jekyll-seo-tag (~> 2.0) 202 | jekyll-theme-slate (0.2.0) 203 | jekyll (> 3.5, < 5.0) 204 | jekyll-seo-tag (~> 2.0) 205 | jekyll-theme-tactile (0.2.0) 206 | jekyll (> 3.5, < 5.0) 207 | jekyll-seo-tag (~> 2.0) 208 | jekyll-theme-time-machine (0.2.0) 209 | jekyll (> 3.5, < 5.0) 210 | jekyll-seo-tag (~> 2.0) 211 | jekyll-titles-from-headings (0.5.3) 212 | jekyll (>= 3.3, < 5.0) 213 | jekyll-watch (2.2.1) 214 | listen (~> 3.0) 215 | jemoji (0.12.0) 216 | gemoji (~> 3.0) 217 | html-pipeline (~> 2.2) 218 | jekyll (>= 3.0, < 5.0) 219 | kramdown (2.3.2) 220 | rexml 221 | kramdown-parser-gfm (1.1.0) 222 | kramdown (~> 2.0) 223 | liquid (4.0.3) 224 | listen (3.7.1) 225 | rb-fsevent (~> 0.10, >= 0.10.3) 226 | rb-inotify (~> 0.9, >= 0.9.10) 227 | mercenary (0.3.6) 228 | minima (2.5.1) 229 | jekyll (>= 3.5, < 5.0) 230 | jekyll-feed (~> 0.9) 231 | jekyll-seo-tag (~> 2.1) 232 | minitest (5.15.0) 233 | multipart-post (2.1.1) 234 | nokogiri (1.13.6-x86_64-linux) 235 | racc (~> 1.4) 236 | octokit (4.22.0) 237 | faraday (>= 0.9) 238 | sawyer (~> 0.8.0, >= 0.5.3) 239 | pathutil (0.16.2) 240 | forwardable-extended (~> 2.6) 241 | public_suffix (4.0.7) 242 | racc (1.6.0) 243 | rb-fsevent (0.11.1) 244 | rb-inotify (0.10.1) 245 | ffi (~> 1.0) 246 | rexml (3.2.5) 247 | rouge (3.26.0) 248 | ruby2_keywords (0.0.5) 249 | rubyzip (2.3.2) 250 | safe_yaml (1.0.5) 251 | sass (3.7.4) 252 | sass-listen (~> 4.0.0) 253 | sass-listen (4.0.0) 254 | rb-fsevent (~> 0.9, >= 0.9.4) 255 | rb-inotify (~> 0.9, >= 0.9.7) 256 | sawyer (0.8.2) 257 | addressable (>= 2.3.5) 258 | faraday (> 0.8, < 2.0) 259 | simpleidn (0.2.1) 260 | unf (~> 0.1.4) 261 | terminal-table (1.8.0) 262 | unicode-display_width (~> 1.1, >= 1.1.1) 263 | thread_safe (0.3.6) 264 | typhoeus (1.4.0) 265 | ethon (>= 0.9.0) 266 | tzinfo (1.2.9) 267 | thread_safe (~> 0.1) 268 | unf (0.1.4) 269 | unf_ext 270 | unf_ext (0.0.8.1) 271 | unicode-display_width (1.8.0) 272 | webrick (1.7.0) 273 | zeitwerk (2.5.4) 274 | 275 | PLATFORMS 276 | x86_64-linux 277 | 278 | DEPENDENCIES 279 | github-pages 280 | http_parser.rb (~> 0.6.0) 281 | tzinfo (~> 1.2) 282 | tzinfo-data 283 | wdm (~> 0.1.1) 284 | webrick (~> 1.7) 285 | 286 | BUNDLED WITH 287 | 2.3.14 288 | -------------------------------------------------------------------------------- /LeanCamCombi/GraphTheory/ExampleSheet1.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Copyright (c) 2022 Yaël Dillies, Kexing Ying. All rights reserved. 3 | Released under Apache 2.0 license as described in the file LICENSE. 4 | Authors: Yaël Dillies, Kexing Ying 5 | -/ 6 | import Mathlib.Combinatorics.Hall.Basic 7 | import Mathlib.Combinatorics.SimpleGraph.Acyclic 8 | import Mathlib.Combinatorics.SimpleGraph.Clique 9 | import Mathlib.Data.Real.Sqrt 10 | import Mathlib.SetTheory.Cardinal.Basic 11 | 12 | /-! 13 | # Graph Theory, example sheet 1 14 | 15 | Here are the statements (and hopefully soon proofs!) of the questions from the first example sheet 16 | of the Cambridge Part II course Graph Theory. 17 | 18 | If you solve a question in Lean, feel free to open a Pull Request on Github! 19 | -/ 20 | 21 | open Fintype (card) 22 | open Function SimpleGraph 23 | open scoped Cardinal SetRel 24 | 25 | namespace GraphTheory 26 | namespace ES1 27 | variable {ι α β γ : Type*} 28 | 29 | /-! 30 | ### Question 1 31 | 32 | Show that a graph $$G$$ which contains an odd circuit, contains an odd cycle. 33 | -/ 34 | 35 | 36 | lemma q1 (G : SimpleGraph α) (a : α) (w : G.Walk a a) (hw : Odd w.length) : 37 | ∃ (b : _) (p : G.Path b b), Odd (p : G.Walk b b).length := 38 | sorry 39 | 40 | /-! 41 | ### Question 2 42 | 43 | Show there are infinitely many planar graphs for which $$e(G) = 3(|G| − 2)$$. Can you give a nice 44 | description of all graphs that satisfy this equality? 45 | -/ 46 | 47 | 48 | /-! 49 | ### Question 3 50 | 51 | Show that every graph $$G$$, with $$|G| > 2$$, has two vertices of the same degree. 52 | -/ 53 | 54 | -- Planarity is hard 55 | lemma q3 [Fintype α] (G : SimpleGraph α) [DecidableRel G.Adj] : 56 | ∃ a b, a ≠ b ∧ G.degree a = G.degree b := 57 | sorry 58 | 59 | /-! 60 | ### Question 4 61 | 62 | Show that in every connected graph with $$|G| ≥ 2$$ there exists a vertex $$v$$ so that $$G − v$$ is 63 | connected. 64 | -/ 65 | 66 | -- This looks a bit painful as a translation. Probably better stated using connectivity on a set. 67 | lemma q4 [Finite α] [Nontrivial α] (G : SimpleGraph α) (hG : G.Connected) : 68 | ∃ a, ((⊤ : G.Subgraph).deleteVerts {a}).coe.Connected := by 69 | cases nonempty_fintype α 70 | sorry 71 | 72 | /-! 73 | ### Question 5 74 | 75 | Show that if $$G$$ is acyclic and $$|G| ≥ 1$$, then $$e(G) ≤ n − 1$$. 76 | -/ 77 | 78 | -- Note: The statement is true without `nonempty α` due to nat subtraction. 79 | lemma q5 [Fintype α] (G : SimpleGraph α) [DecidableRel G.Adj] (hG : G.IsAcyclic) : 80 | G.edgeFinset.card ≤ card α - 1 := by 81 | cases isEmpty_or_nonempty α 82 | · simp 83 | sorry 84 | 85 | /-! 86 | ### Question 6 87 | 88 | The degree sequence of a graph $$G = ({x_1, . . . , x_n}, E)$$ is the sequence 89 | $$d(x_1), . . . , d(x_n)$$. 90 | For $$n ≥ 2$$, let $$1 ≤ d_1 ≤ d_2 ≤ \dots ≤ d_n$$ be integers. Show that $$(d_i)_{i = 1}^n$$ is a 91 | degree sequence of a tree if and only if $$\sum_{i=1}^n d_i = 2n − 2$$. 92 | -/ 93 | 94 | /-- The finset of degrees of a finite graph. -/ 95 | def degreeSequence [Fintype α] (G : SimpleGraph α) [DecidableRel G.Adj] : Multiset ℕ := 96 | Finset.univ.val.map fun a ↦ G.degree a 97 | 98 | lemma q6 [Fintype α] (s : Multiset ℕ) (hs : Multiset.card s = card α) (h₀ : 0 ∉ s) : 99 | s.sum = 2 * card α - 2 ↔ 100 | ∃ (G : SimpleGraph α) (_ : DecidableRel G.Adj), degreeSequence G = s := 101 | sorry 102 | 103 | /-! 104 | ### Question 7 105 | 106 | Let $$T_1, \dots, T_k$$ be subtrees of a tree $$T$$. Show that if $$V(T_i) ∩ V(T_j) ≠ ∅$$ for all 107 | $$i, j ∈ [k]$$ then $$V(T_1) ∩ \dots ∩ V(T_k) ≠ ∅$$. 108 | -/ 109 | 110 | lemma q7 (G : SimpleGraph α) (hG : G.IsAcyclic) (s : Finset ι) (f : ι → G.Subgraph) 111 | (hf : ∀ i ∈ s, (f i).coe.IsAcyclic) (h : ∀ i ∈ s, ∀ j ∈ s, f i ⊓ f j ≠ ⊥) : 112 | s.inf f ≠ ⊥ := 113 | sorry 114 | 115 | /-! 116 | ### Question 8 117 | 118 | The average degree of a graph $$G = (V, E)$$ is $$n^{-1} \sum_{x ∈ V} d(x)$$. Show that if the 119 | average degree of $$G$$ is $$d$$ then $$G$$ contains a subgraph with minimum degree $≥ d/2$$. 120 | -/ 121 | 122 | /-- The average degree of a simple graph is the average of its degrees. -/ 123 | def averageDegree [Fintype α] (G : SimpleGraph α) [DecidableRel G.Adj] : ℚ := 124 | ∑ a, G.degree a / card α 125 | 126 | lemma q8 [Fintype α] (G : SimpleGraph α) [DecidableRel G.Adj] : 127 | ∃ (H : Subgraph G) (_ : DecidableRel H.Adj), ∀ a, averageDegree G / 2 ≤ H.degree a := 128 | sorry 129 | 130 | /-! 131 | ### Question 9 132 | 133 | Say that a graph $$G = (V, E)$$ can be decomposed into cycles if $$E$$ can be partitioned 134 | $$E = E_1 ∪ \dots ∪ E_k$$, where each $$E_i$$ is the edge set of a cycle. Show that $$G$$ can be 135 | decomposed into cycles if and only if all degrees of $$G$$ are even. 136 | -/ 137 | 138 | -- This looks painful as a translation. It will likely get better once we have Kyle's eulerian paths 139 | lemma q9 [Fintype α] (G : SimpleGraph α) [DecidableRel G.Adj] : 140 | (∃ 𝒜 : Finset (Σ a, G.Path a a), 141 | (∀ p q : Σ a, G.Path a a, 142 | (p.2 : G.Walk p.1 p.1).edges.Disjoint (q.2 : G.Walk q.1 q.1).edges) ∧ 143 | ∀ e, ∃ p : Σ a, G.Path a a, p ∈ 𝒜 ∧ e ∈ (p.2 : G.Walk p.1 p.1).edges) ↔ 144 | ∀ a, Even (G.degree a) := 145 | sorry 146 | 147 | /-! 148 | ### Question 10 149 | 150 | The clique number of a graph $$G$$ is the largest $$t$$ so that $$G$$ contains a complete graph on 151 | $$t$$ vertices. 152 | Show that the possible clique numbers for a regular graph on $$n$$ vertices are 153 | $$1, 2, \dots, n/2$$ and $$n$$. 154 | -/ 155 | 156 | lemma q10 [Fintype α] (n : ℕ) : 157 | (∃ (G : SimpleGraph α) (_ : DecidableRel G.Adj) (k : _), 158 | G.IsRegularOfDegree k ∧ cliqueNum G = n) ↔ 159 | n ≤ card α / 2 ∨ n = card α := 160 | sorry 161 | 162 | /-! 163 | ### Question 11 164 | 165 | Show that the Petersen graph is non-planar. 166 | -/ 167 | 168 | 169 | /-! 170 | ### Question 12 171 | 172 | Let $$G = (V, E)$$ be a graph. Show that there is a partition $$V = A ∪ B$$ so all the vertices in 173 | the graphs $$G[A]$$ and $$G[B]$$ are of even degree. 174 | -/ 175 | 176 | -- Note: This is a bit more general than the statement, because we allow partitioning any set of 177 | -- vertices 178 | lemma q12 [DecidableEq α] (G : SimpleGraph α) [DecidableRel G.Adj] (s : Finset α) : 179 | ∃ u v, Disjoint u v ∧ u ∪ v = s ∧ 180 | (∀ a ∈ u, Even #{b ∈ u | G.Adj a b}) ∧ ∀ a ∈ v, Even #{b ∈ v | G.Adj a b} := 181 | sorry 182 | 183 | /-! 184 | ### Question 13 185 | 186 | A $$m × n$$ Latin rectangle is a $$m × n$$ matrix, with each entry from $${1, . . . , n}$$, such 187 | that no two entries in the same row or column are the same. Prove that every $$m × n$$ Latin 188 | rectangle may be extended to a $$n × n$$ Latin square. 189 | -/ 190 | 191 | /-- A Latin rectangle is a binary function whose transversals are all injective. -/ 192 | def IsLatin (f : α → β → γ) : Prop := 193 | (∀ a, Injective (f a)) ∧ ∀ b, Injective fun a ↦ f a b 194 | 195 | lemma q13 [Finite α] (g : β ↪ α) (f : β → α → α) (hf : IsLatin f) : 196 | ∃ f', f' ∘ g = f ∧ IsLatin f := 197 | sorry 198 | 199 | /-! 200 | ### Question 14 201 | 202 | Let $$G = (X ∪ Y, E)$$ be a countably infinite bipartite graph with the property that 203 | $$|N(A)| ≥ |A|$$ for all $$A ⊆ X$$. Give an example to show that $$G$$ need not contain a matching 204 | from $$X$$ to $$Y$$ . On the other hand, show that if all of the degrees of $$G$$ are finite then 205 | $$G$$ does contain a matching from $$X$$ to $$Y$$. Does this remain true if $$G$$ is uncountable and 206 | all degrees of $$X$$ are finite (while degrees in $$Y$$ have no restriction)? 207 | -/ 208 | 209 | -- This translation looks slightly painful because of the `cardinal`. 210 | lemma q14_part1 : 211 | ∃ r : SetRel ℕ ℕ, 212 | (∀ A : Finset ℕ, (A.card : Cardinal) ≤ #(r.image A)) ∧ 213 | ∀ f : ℕ → ℕ, Injective f → ∃ n, ¬ n ~[r] f n := 214 | sorry 215 | 216 | lemma q14_part2 [DecidableEq β] [Countable α] [Countable β] (r : SetRel α β) 217 | [∀ a, Fintype (r.image {a})] (hr : ∀ A : Finset α, A.card ≤ card (r.image A)) : 218 | ∃ f : α → β, Injective f ∧ ∀ a, a ~[r] f a := 219 | sorry 220 | 221 | lemma q14_part3 [DecidableEq β] (r : SetRel α β) [∀ a, Fintype (r.image {a})] 222 | (hr : ∀ A : Finset α, A.card ≤ card (r.image A)) : 223 | ∃ f : α → β, Injective f ∧ ∀ a, a ~[r] f a := 224 | sorry 225 | 226 | /-! 227 | ### Question 15 228 | 229 | Let $$(X, d_X)$$ be a metric space. We say that a function $$f : X → ℝ^2$$ has distortion 230 | $$≤ D$$ if there exists an $$r > 0$$ so that 231 | $$rd_X(x, y) ≤ ‖f(x) − f(y)‖_2 ≤ Drd_X(x, y)$$. 232 | Show that there is some constant $$c > 0$$ such that for all $$n$$ there is a metric space 233 | $$M = ({x_1, \dots, x_n}, d_M)$$ on $$n$$ points so that every function $$f : M → ℝ^2$$ has 234 | distortion $$> cn^{1/2}$$. Does there exist some constant $$c > 0$$ such that for all $$n$$ there is 235 | a metric space $$M = ({x_1, \dots, x_n}, d_M)$$ on $$n$$ points so that every function 236 | $$f : M → ℝ^2$$ has distortion $$> cn$$? 237 | -/ 238 | 239 | /-- The distortion of a function `f` between metric spaces is the ratio between the maximum and 240 | minimum of `dist (f a) (f b) / dist a b`. -/ 241 | noncomputable def distortion [PseudoMetricSpace α] [PseudoMetricSpace β] (f : α → β) : ℝ := 242 | (⨆ (a) (b), dist (f a) (f b) / dist a b) / ⨅ (a) (b), dist (f a) (f b) / dist a b 243 | 244 | lemma q15_part1 : 245 | ∃ ε : ℝ, 0 < ε ∧ ∀ (α) [Fintype α], 246 | ∃ _ : MetricSpace α, ∀ f : α → ℝ × ℝ, ε * Real.sqrt (card α) ≤ distortion f := 247 | sorry 248 | 249 | lemma q15_part2 : 250 | ∃ ε : ℝ, 0 < ε ∧ ∀ (α) [Fintype α], 251 | ∃ _ : MetricSpace α, ∀ f : α → ℝ × ℝ, ε * card α ≤ distortion f := 252 | sorry 253 | 254 | end ES1 255 | end GraphTheory 256 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------