├── lean-toolchain
├── html
├── _sources
│ ├── genindex.rst.txt
│ ├── C01_Introduction.rst.txt
│ ├── C10_Linear_Algebra.rst.txt
│ ├── C13_Integration_and_Measure_Theory.rst.txt
│ ├── index.rst.txt
│ ├── C02_Basics.rst.txt
│ ├── C05_Elementary_Number_Theory.rst.txt
│ ├── C03_Logic.rst.txt
│ ├── C12_Differential_Calculus.rst.txt
│ ├── C06_Discrete_Mathematics.rst.txt
│ ├── C07_Structures.rst.txt
│ ├── C09_Groups_and_Rings.rst.txt
│ ├── C08_Hierarchies.rst.txt
│ ├── C04_Sets_and_Functions.rst.txt
│ └── C11_Topology.rst.txt
├── objects.inv
├── _static
│ ├── file.png
│ ├── plus.png
│ ├── minus.png
│ ├── favicon.ico
│ ├── css
│ │ ├── fonts
│ │ │ ├── lato-bold.woff
│ │ │ ├── lato-bold.woff2
│ │ │ ├── lato-normal.woff
│ │ │ ├── lato-normal.woff2
│ │ │ ├── Roboto-Slab-Bold.woff
│ │ │ ├── Roboto-Slab-Bold.woff2
│ │ │ ├── fontawesome-webfont.eot
│ │ │ ├── fontawesome-webfont.ttf
│ │ │ ├── lato-bold-italic.woff
│ │ │ ├── lato-bold-italic.woff2
│ │ │ ├── lato-normal-italic.woff
│ │ │ ├── Roboto-Slab-Regular.woff
│ │ │ ├── Roboto-Slab-Regular.woff2
│ │ │ ├── fontawesome-webfont.woff
│ │ │ ├── fontawesome-webfont.woff2
│ │ │ └── lato-normal-italic.woff2
│ │ ├── custom.css
│ │ └── badge_only.css
│ ├── fonts
│ │ ├── Lato
│ │ │ ├── lato-bold.eot
│ │ │ ├── lato-bold.ttf
│ │ │ ├── lato-bold.woff
│ │ │ ├── lato-bold.woff2
│ │ │ ├── lato-italic.eot
│ │ │ ├── lato-italic.ttf
│ │ │ ├── lato-italic.woff
│ │ │ ├── lato-italic.woff2
│ │ │ ├── lato-regular.eot
│ │ │ ├── lato-regular.ttf
│ │ │ ├── lato-regular.woff
│ │ │ ├── lato-bolditalic.eot
│ │ │ ├── lato-bolditalic.ttf
│ │ │ ├── lato-regular.woff2
│ │ │ ├── lato-bolditalic.woff
│ │ │ └── lato-bolditalic.woff2
│ │ └── RobotoSlab
│ │ │ ├── roboto-slab-v7-bold.eot
│ │ │ ├── roboto-slab-v7-bold.ttf
│ │ │ ├── roboto-slab-v7-bold.woff
│ │ │ ├── roboto-slab-v7-bold.woff2
│ │ │ ├── roboto-slab-v7-regular.eot
│ │ │ ├── roboto-slab-v7-regular.ttf
│ │ │ ├── roboto-slab-v7-regular.woff
│ │ │ └── roboto-slab-v7-regular.woff2
│ ├── documentation_options.js
│ └── js
│ │ └── badge_only.js
├── _images
│ ├── schroeder_bernstein1.png
│ ├── schroeder_bernstein2.png
│ └── schroeder_bernstein3.png
└── .buildinfo
├── MIL
├── C01_Introduction
│ ├── solutions
│ │ ├── Solutions_S01_Getting_Started.lean
│ │ └── Solutions_S02_Overview.lean
│ ├── S01_Getting_Started.lean
│ └── S02_Overview.lean
├── Common.lean
├── C06_Discrete_Mathematics
│ ├── solutions
│ │ ├── Solutions_S01_Finsets_and_Fintypes.lean
│ │ ├── Solutions_S02_Counting_Arguments.lean
│ │ └── Solutions_S03_Inductive_Structures.lean
│ └── S01_Finsets_and_Fintypes.lean
├── C10_Linear_Algebra
│ ├── solutions
│ │ ├── Solutions_S01_Vector_Spaces.lean
│ │ ├── Solutions_S03_Endomorphisms.lean
│ │ ├── Solutions_S04_Bases.lean
│ │ └── Solutions_S02_Subspaces.lean
│ └── S03_Endomorphisms.lean
├── C13_Integration_and_Measure_Theory
│ ├── solutions
│ │ ├── Solutions_S01_Elementary_Integration.lean
│ │ ├── Solutions_S03_Integration.lean
│ │ └── Solutions_S02_Measure_Theory.lean
│ ├── S01_Elementary_Integration.lean
│ ├── S02_Measure_Theory.lean
│ └── S03_Integration.lean
├── C12_Differential_Calculus
│ ├── solutions
│ │ ├── Solutions_S01_Elementary_Differential_Calculus.lean
│ │ └── Solutions_S02_Differential_Calculus_in_Normed_Spaces.lean
│ └── S01_Elementary_Differential_Calculus.lean
├── C02_Basics
│ ├── solutions
│ │ ├── Solutions_S01_Calculating.lean
│ │ ├── Solutions_S03_Using_Theorems_and_Lemmas.lean
│ │ ├── Solutions_S02_Proving_Identities_in_Algebraic_Structures.lean
│ │ ├── Solutions_S04_More_on_Order_and_Divisibility.lean
│ │ └── Solutions_S05_Proving_Facts_about_Algebraic_Structures.lean
│ ├── S04_More_on_Order_and_Divisibility.lean
│ ├── S05_Proving_Facts_about_Algebraic_Structures.lean
│ ├── S02_Proving_Identities_in_Algebraic_Structures.lean
│ ├── S03_Using_Theorems_and_Lemmas.lean
│ └── S01_Calculating.lean
├── C05_Elementary_Number_Theory
│ ├── solutions
│ │ ├── Solutions_S04_More_Induction.lean
│ │ ├── Solutions_S02_Induction_and_Recursion.lean
│ │ └── Solutions_S01_Irrational_Roots.lean
│ ├── S01_Irrational_Roots.lean
│ ├── S02_Induction_and_Recursion.lean
│ └── S04_More_Induction.lean
├── C03_Logic
│ ├── solutions
│ │ ├── Solutions_S02_The_Existential_Quantifier.lean
│ │ ├── Solutions_S04_Conjunction_and_Iff.lean
│ │ ├── Solutions_S03_Negation.lean
│ │ ├── Solutions_S01_Implication_and_the_Universal_Quantifier.lean
│ │ ├── Solutions_S05_Disjunction.lean
│ │ └── Solutions_S06_Sequences_and_Convergence.lean
│ ├── S05_Disjunction.lean
│ ├── S03_Negation.lean
│ ├── S06_Sequences_and_Convergence.lean
│ ├── S04_Conjunction_and_Iff.lean
│ ├── S02_The_Existential_Quantifier.lean
│ └── S01_Implication_and_the_Universal_Quantifier.lean
├── C07_Structures
│ ├── solutions
│ │ ├── Solutions_S02_Algebraic_Structures.lean
│ │ └── Solutions_S01_Structures.lean
│ └── S02_Algebraic_Structures.lean
├── C04_Sets_and_Functions
│ ├── solutions
│ │ ├── Solutions_S03_The_Schroeder_Bernstein_Theorem.lean
│ │ └── Solutions_S01_Sets.lean
│ ├── S03_The_Schroeder_Bernstein_Theorem.lean
│ └── S02_Functions.lean
├── C11_Topology
│ ├── solutions
│ │ └── Solutions_S01_Filters.lean
│ └── S01_Filters.lean
├── C08_Hierarchies
│ ├── S03_Subobjects.lean
│ └── S02_Morphisms.lean
└── C09_Groups_and_Rings
│ └── solutions
│ └── Solutions_S02_Rings.lean
├── .gitignore
├── mathematics_in_lean.pdf
├── .gitpod.yml
├── .devcontainer
├── Dockerfile
└── devcontainer.json
├── lakefile.toml
├── .github
└── pull_request_template.md
├── .vscode
├── extensions.json
└── settings.json
├── .docker
└── gitpod
│ └── Dockerfile
├── MIL.lean
├── MIL_solutions.lean
└── lake-manifest.json
/lean-toolchain:
--------------------------------------------------------------------------------
1 | leanprover/lean4:v4.21.0
--------------------------------------------------------------------------------
/html/_sources/genindex.rst.txt:
--------------------------------------------------------------------------------
1 | Index
2 | =====
--------------------------------------------------------------------------------
/MIL/C01_Introduction/solutions/Solutions_S01_Getting_Started.lean:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/MIL/C01_Introduction/S01_Getting_Started.lean:
--------------------------------------------------------------------------------
1 | #eval "Hello, World!"
2 |
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /.vscode
2 | /build
3 | /lake-packages
4 | .lake
5 | /.cache
6 | .DS_Store
7 |
--------------------------------------------------------------------------------
/html/objects.inv:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/objects.inv
--------------------------------------------------------------------------------
/html/_static/file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/file.png
--------------------------------------------------------------------------------
/html/_static/plus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/plus.png
--------------------------------------------------------------------------------
/MIL/Common.lean:
--------------------------------------------------------------------------------
1 | import Mathlib.Tactic
2 | import Mathlib.Util.Delaborators
3 |
4 | set_option warningAsError false
5 |
--------------------------------------------------------------------------------
/html/_static/minus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/minus.png
--------------------------------------------------------------------------------
/mathematics_in_lean.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/mathematics_in_lean.pdf
--------------------------------------------------------------------------------
/html/_static/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/favicon.ico
--------------------------------------------------------------------------------
/MIL/C01_Introduction/solutions/Solutions_S02_Overview.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 |
3 | open Nat
4 |
5 | -- There are no exercises in this section.
6 |
--------------------------------------------------------------------------------
/html/_images/schroeder_bernstein1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_images/schroeder_bernstein1.png
--------------------------------------------------------------------------------
/html/_images/schroeder_bernstein2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_images/schroeder_bernstein2.png
--------------------------------------------------------------------------------
/html/_images/schroeder_bernstein3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_images/schroeder_bernstein3.png
--------------------------------------------------------------------------------
/html/_static/css/fonts/lato-bold.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/css/fonts/lato-bold.woff
--------------------------------------------------------------------------------
/html/_static/css/fonts/lato-bold.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/css/fonts/lato-bold.woff2
--------------------------------------------------------------------------------
/html/_static/fonts/Lato/lato-bold.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/Lato/lato-bold.eot
--------------------------------------------------------------------------------
/html/_static/fonts/Lato/lato-bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/Lato/lato-bold.ttf
--------------------------------------------------------------------------------
/html/_static/fonts/Lato/lato-bold.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/Lato/lato-bold.woff
--------------------------------------------------------------------------------
/html/_static/css/fonts/lato-normal.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/css/fonts/lato-normal.woff
--------------------------------------------------------------------------------
/html/_static/css/fonts/lato-normal.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/css/fonts/lato-normal.woff2
--------------------------------------------------------------------------------
/html/_static/fonts/Lato/lato-bold.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/Lato/lato-bold.woff2
--------------------------------------------------------------------------------
/html/_static/fonts/Lato/lato-italic.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/Lato/lato-italic.eot
--------------------------------------------------------------------------------
/html/_static/fonts/Lato/lato-italic.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/Lato/lato-italic.ttf
--------------------------------------------------------------------------------
/html/_static/fonts/Lato/lato-italic.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/Lato/lato-italic.woff
--------------------------------------------------------------------------------
/html/_static/fonts/Lato/lato-italic.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/Lato/lato-italic.woff2
--------------------------------------------------------------------------------
/html/_static/fonts/Lato/lato-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/Lato/lato-regular.eot
--------------------------------------------------------------------------------
/html/_static/fonts/Lato/lato-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/Lato/lato-regular.ttf
--------------------------------------------------------------------------------
/html/_static/fonts/Lato/lato-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/Lato/lato-regular.woff
--------------------------------------------------------------------------------
/html/_static/fonts/Lato/lato-bolditalic.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/Lato/lato-bolditalic.eot
--------------------------------------------------------------------------------
/html/_static/fonts/Lato/lato-bolditalic.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/Lato/lato-bolditalic.ttf
--------------------------------------------------------------------------------
/html/_static/fonts/Lato/lato-regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/Lato/lato-regular.woff2
--------------------------------------------------------------------------------
/html/_static/css/fonts/Roboto-Slab-Bold.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/css/fonts/Roboto-Slab-Bold.woff
--------------------------------------------------------------------------------
/html/_static/css/fonts/Roboto-Slab-Bold.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/css/fonts/Roboto-Slab-Bold.woff2
--------------------------------------------------------------------------------
/html/_static/css/fonts/fontawesome-webfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/css/fonts/fontawesome-webfont.eot
--------------------------------------------------------------------------------
/html/_static/css/fonts/fontawesome-webfont.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/css/fonts/fontawesome-webfont.ttf
--------------------------------------------------------------------------------
/html/_static/css/fonts/lato-bold-italic.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/css/fonts/lato-bold-italic.woff
--------------------------------------------------------------------------------
/html/_static/css/fonts/lato-bold-italic.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/css/fonts/lato-bold-italic.woff2
--------------------------------------------------------------------------------
/html/_static/css/fonts/lato-normal-italic.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/css/fonts/lato-normal-italic.woff
--------------------------------------------------------------------------------
/html/_static/fonts/Lato/lato-bolditalic.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/Lato/lato-bolditalic.woff
--------------------------------------------------------------------------------
/html/_static/fonts/Lato/lato-bolditalic.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/Lato/lato-bolditalic.woff2
--------------------------------------------------------------------------------
/html/_static/css/fonts/Roboto-Slab-Regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/css/fonts/Roboto-Slab-Regular.woff
--------------------------------------------------------------------------------
/html/_static/css/fonts/Roboto-Slab-Regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/css/fonts/Roboto-Slab-Regular.woff2
--------------------------------------------------------------------------------
/html/_static/css/fonts/fontawesome-webfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/css/fonts/fontawesome-webfont.woff
--------------------------------------------------------------------------------
/html/_static/css/fonts/fontawesome-webfont.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/css/fonts/fontawesome-webfont.woff2
--------------------------------------------------------------------------------
/html/_static/css/fonts/lato-normal-italic.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/css/fonts/lato-normal-italic.woff2
--------------------------------------------------------------------------------
/.gitpod.yml:
--------------------------------------------------------------------------------
1 | image:
2 | file: .docker/gitpod/Dockerfile
3 |
4 | vscode:
5 | extensions:
6 | - leanprover.lean4
7 |
8 | tasks:
9 | - init: lake exe cache get
10 |
--------------------------------------------------------------------------------
/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.eot
--------------------------------------------------------------------------------
/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.ttf
--------------------------------------------------------------------------------
/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.woff
--------------------------------------------------------------------------------
/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.woff2
--------------------------------------------------------------------------------
/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.eot
--------------------------------------------------------------------------------
/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.ttf
--------------------------------------------------------------------------------
/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.woff
--------------------------------------------------------------------------------
/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/mathematics_in_lean/HEAD/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.woff2
--------------------------------------------------------------------------------
/html/_sources/C01_Introduction.rst.txt:
--------------------------------------------------------------------------------
1 | .. _introduction:
2 |
3 | Introduction
4 | ============
5 |
6 | .. include:: C01_Introduction/S01_Getting_Started.inc
7 | .. include:: C01_Introduction/S02_Overview.inc
8 |
--------------------------------------------------------------------------------
/MIL/C06_Discrete_Mathematics/solutions/Solutions_S01_Finsets_and_Fintypes.lean:
--------------------------------------------------------------------------------
1 | import Mathlib.Data.Finset.Powerset
2 | import Mathlib.Data.Finset.Max
3 | import Mathlib.Data.Nat.Prime.Basic
4 | import Mathlib.Data.Fintype.BigOperators
5 |
6 |
--------------------------------------------------------------------------------
/MIL/C10_Linear_Algebra/solutions/Solutions_S01_Vector_Spaces.lean:
--------------------------------------------------------------------------------
1 | import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
2 | import Mathlib.LinearAlgebra.Eigenspace.Minpoly
3 | import Mathlib.LinearAlgebra.Charpoly.Basic
4 |
5 | import MIL.Common
6 |
7 |
--------------------------------------------------------------------------------
/html/.buildinfo:
--------------------------------------------------------------------------------
1 | # Sphinx build info version 1
2 | # This file records the configuration used when building these files. When it is not found, a full rebuild will be done.
3 | config: a340bf0c76a4f9e7976f0ee66f38630b
4 | tags: 645f666f9bcd5a90fca523b33c5a78b7
5 |
--------------------------------------------------------------------------------
/.devcontainer/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM mcr.microsoft.com/devcontainers/base:jammy
2 |
3 | USER vscode
4 | WORKDIR /home/vscode
5 |
6 | RUN curl https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh -sSf | sh -s -- -y --default-toolchain none
7 |
8 | ENV PATH="/home/vscode/.elan/bin:${PATH}"
9 |
--------------------------------------------------------------------------------
/MIL/C13_Integration_and_Measure_Theory/solutions/Solutions_S01_Elementary_Integration.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Analysis.SpecialFunctions.Integrals.Basic
3 | import Mathlib.Analysis.Convolution
4 |
5 | open Set Filter
6 |
7 | open Topology Filter
8 |
9 | noncomputable section
10 |
11 |
--------------------------------------------------------------------------------
/html/_sources/C10_Linear_Algebra.rst.txt:
--------------------------------------------------------------------------------
1 | .. _linear_algebra:
2 |
3 | Linear algebra
4 | ==============
5 |
6 |
7 | .. include:: C10_Linear_Algebra/S01_Vector_Spaces.inc
8 | .. include:: C10_Linear_Algebra/S02_Subspaces.inc
9 | .. include:: C10_Linear_Algebra/S03_Endomorphisms.inc
10 | .. include:: C10_Linear_Algebra/S04_Bases.inc
11 |
--------------------------------------------------------------------------------
/lakefile.toml:
--------------------------------------------------------------------------------
1 | name = "mil"
2 | defaultTargets = ["MIL"]
3 |
4 | [leanOptions]
5 | pp.unicode.fun = true # pretty-prints `fun a ↦ b`
6 | autoImplicit = false
7 | relaxedAutoImplicit = false
8 |
9 | [[require]]
10 | name = "mathlib"
11 | git = "https://github.com/leanprover-community/mathlib4"
12 | rev = "v4.21.0"
13 |
14 | [[lean_lib]]
15 | name = "MIL"
16 |
--------------------------------------------------------------------------------
/MIL/C12_Differential_Calculus/solutions/Solutions_S01_Elementary_Differential_Calculus.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv
3 | import Mathlib.Analysis.Calculus.Deriv.Pow
4 | import Mathlib.Analysis.Calculus.MeanValue
5 |
6 | open Set Filter
7 | open Topology Filter Classical Real
8 |
9 | noncomputable section
10 |
11 |
--------------------------------------------------------------------------------
/.github/pull_request_template.md:
--------------------------------------------------------------------------------
1 | WARNING: Please do not open a pull request in this repository.
2 |
3 | This is not the relevant repository to contribute to Mathematics in Lean. This repository is cloned by people who want to study the book. It is automatically created from the source repository which can be found at https://github.com/avigad/mathematics_in_lean_source and where you can open a pull-request.
4 |
--------------------------------------------------------------------------------
/html/_static/documentation_options.js:
--------------------------------------------------------------------------------
1 | const DOCUMENTATION_OPTIONS = {
2 | VERSION: 'v4.19.0',
3 | LANGUAGE: 'en',
4 | COLLAPSE_INDEX: false,
5 | BUILDER: 'html',
6 | FILE_SUFFIX: '.html',
7 | LINK_SUFFIX: '.html',
8 | HAS_SOURCE: true,
9 | SOURCELINK_SUFFIX: '.txt',
10 | NAVIGATION_WITH_KEYS: false,
11 | SHOW_SEARCH_SUMMARY: true,
12 | ENABLE_SEARCH_SHORTCUTS: true,
13 | };
--------------------------------------------------------------------------------
/html/_static/css/custom.css:
--------------------------------------------------------------------------------
1 | .rst-content .admonition .admonition-title:before {
2 | content: none;
3 | }
4 |
5 | .rst-content .admonition-theorem .admonition-title:before {
6 | content: none;
7 | }
8 |
9 | .rst-content .admonition-proof .admonition-title:before {
10 | content: none;
11 | }
12 |
13 | code.literal {
14 | color: #404040 !important;
15 | background-color: #fbfbfb !important;
16 | }
17 |
--------------------------------------------------------------------------------
/html/_sources/C13_Integration_and_Measure_Theory.rst.txt:
--------------------------------------------------------------------------------
1 | .. _integration_and_measure_theory:
2 |
3 | .. index:: integration
4 |
5 | Integration and Measure Theory
6 | ==============================
7 |
8 | .. include:: C13_Integration_and_Measure_Theory/S01_Elementary_Integration.inc
9 | .. include:: C13_Integration_and_Measure_Theory/S02_Measure_Theory.inc
10 | .. include:: C13_Integration_and_Measure_Theory/S03_Integration.inc
11 |
--------------------------------------------------------------------------------
/.devcontainer/devcontainer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "MIL dev container",
3 |
4 | "build": {
5 | "dockerfile": "Dockerfile"
6 | },
7 |
8 | "onCreateCommand": "echo \"Downloading the Lean 4 mathematical library...\" && lake exe cache get! && lake build +MIL.Common && echo \"Finished setup! Open a file using the Explorer in the top-left of your screen.\"",
9 |
10 | "customizations": {
11 | "vscode" : {
12 | "extensions" : [ "leanprover.lean4" ]
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/MIL/C13_Integration_and_Measure_Theory/solutions/Solutions_S03_Integration.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Analysis.Normed.Module.FiniteDimension
3 | import Mathlib.Analysis.Convolution
4 | import Mathlib.MeasureTheory.Function.Jacobian
5 | import Mathlib.MeasureTheory.Integral.Bochner.Basic
6 | import Mathlib.MeasureTheory.Measure.Lebesgue.Basic
7 |
8 | open Set Filter
9 |
10 | open Topology Filter ENNReal
11 |
12 | open MeasureTheory
13 |
14 | noncomputable section
15 | variable {α : Type*} [MeasurableSpace α]
16 | variable {μ : Measure α}
17 |
18 |
--------------------------------------------------------------------------------
/html/_sources/index.rst.txt:
--------------------------------------------------------------------------------
1 |
2 | Mathematics in Lean
3 | ===================
4 |
5 | .. toctree::
6 | :numbered:
7 | :maxdepth: 2
8 |
9 | C01_Introduction
10 | C02_Basics
11 | C03_Logic
12 | C04_Sets_and_Functions
13 | C05_Elementary_Number_Theory
14 | C06_Discrete_Mathematics
15 | C07_Structures
16 | C08_Hierarchies
17 | C09_Groups_and_Rings
18 | C10_Linear_Algebra
19 | C11_Topology
20 | C12_Differential_Calculus
21 | C13_Integration_and_Measure_Theory
22 |
23 | .. toctree::
24 | :hidden:
25 |
26 | genindex
27 |
--------------------------------------------------------------------------------
/MIL/C13_Integration_and_Measure_Theory/solutions/Solutions_S02_Measure_Theory.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Analysis.Normed.Module.FiniteDimension
3 | import Mathlib.Analysis.Convolution
4 | import Mathlib.MeasureTheory.Function.Jacobian
5 | import Mathlib.MeasureTheory.Integral.Bochner.Basic
6 | import Mathlib.MeasureTheory.Measure.Lebesgue.Basic
7 |
8 | open Set Filter
9 |
10 | noncomputable section
11 |
12 | variable {α : Type*} [MeasurableSpace α]
13 |
14 | variable {ι : Type*} [Encodable ι]
15 |
16 | open MeasureTheory Function
17 | variable {μ : Measure α}
18 |
19 |
--------------------------------------------------------------------------------
/html/_sources/C02_Basics.rst.txt:
--------------------------------------------------------------------------------
1 | .. _basics:
2 |
3 | Basics
4 | ======
5 |
6 | This chapter is designed to introduce you to the nuts and
7 | bolts of mathematical reasoning in Lean: calculating,
8 | applying lemmas and theorems,
9 | and reasoning about generic structures.
10 |
11 | .. include:: C02_Basics/S01_Calculating.inc
12 | .. include:: C02_Basics/S02_Proving_Identities_in_Algebraic_Structures.inc
13 | .. include:: C02_Basics/S03_Using_Theorems_and_Lemmas.inc
14 | .. include:: C02_Basics/S04_More_on_Order_and_Divisibility.inc
15 | .. include:: C02_Basics/S05_Proving_Facts_about_Algebraic_Structures.inc
16 |
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | // This file prevents VS Code from making unhelpful suggestions about extensions
2 | // during the initial setup of Mathematics In Lean.
3 | {
4 | // See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
5 | // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
6 |
7 | // List of extensions which should be recommended for users of this workspace.
8 | "recommendations": [
9 | "leanprover.lean4"
10 | ],
11 | // List of extensions recommended by VS Code that should not be recommended for users of this workspace.
12 | "unwantedRecommendations": [
13 | "ms-vscode-remote.remote-containers"
14 | ]
15 | }
16 |
--------------------------------------------------------------------------------
/html/_sources/C05_Elementary_Number_Theory.rst.txt:
--------------------------------------------------------------------------------
1 | .. _number_theory:
2 |
3 | Elementary Number Theory
4 | ========================
5 |
6 | In this chapter, we show you how to formalize some elementary
7 | results in number theory.
8 | As we deal with more substantive mathematical content,
9 | the proofs will get longer and more involved,
10 | building on the skills you have already mastered.
11 |
12 | .. include:: C05_Elementary_Number_Theory/S01_Irrational_Roots.inc
13 | .. include:: C05_Elementary_Number_Theory/S02_Induction_and_Recursion.inc
14 | .. include:: C05_Elementary_Number_Theory/S03_Infinitely_Many_Primes.inc
15 | .. include:: C05_Elementary_Number_Theory/S04_More_Induction.inc
16 |
--------------------------------------------------------------------------------
/html/_sources/C03_Logic.rst.txt:
--------------------------------------------------------------------------------
1 | .. _logic:
2 |
3 | Logic
4 | =====
5 |
6 | In the last chapter, we dealt with equations, inequalities,
7 | and basic mathematical statements like
8 | ":math:`x` divides :math:`y`."
9 | Complex mathematical statements are built up from
10 | simple ones like these
11 | using logical terms like "and," "or," "not," and
12 | "if ... then," "every," and "some."
13 | In this chapter, we show you how to work with statements
14 | that are built up in this way.
15 |
16 | .. include:: C03_Logic/S01_Implication_and_the_Universal_Quantifier.inc
17 | .. include:: C03_Logic/S02_The_Existential_Quantifier.inc
18 | .. include:: C03_Logic/S03_Negation.inc
19 | .. include:: C03_Logic/S04_Conjunction_and_Iff.inc
20 | .. include:: C03_Logic/S05_Disjunction.inc
21 | .. include:: C03_Logic/S06_Sequences_and_Convergence.inc
22 |
--------------------------------------------------------------------------------
/html/_sources/C12_Differential_Calculus.rst.txt:
--------------------------------------------------------------------------------
1 | .. _differential_calculus:
2 |
3 | .. index:: differential calculus
4 |
5 | Differential Calculus
6 | =====================
7 |
8 | We now consider the formalization of notions from *analysis*,
9 | starting with differentiation in this chapter
10 | and turning integration and measure theory in the next.
11 | In :numref:`elementary_differential_calculus`, we stick with the
12 | setting of functions from the real numbers to the real numbers,
13 | which is familiar from any introductory calculus class.
14 | In :numref:`normed_spaces`, we then consider the notion of a derivative in
15 | a much broader setting.
16 |
17 | .. include:: C12_Differential_Calculus/S01_Elementary_Differential_Calculus.inc
18 | .. include:: C12_Differential_Calculus/S02_Differential_Calculus_in_Normed_Spaces.inc
19 |
--------------------------------------------------------------------------------
/html/_sources/C06_Discrete_Mathematics.rst.txt:
--------------------------------------------------------------------------------
1 | .. _discrete_mathematics:
2 |
3 | Discrete Mathematics
4 | ====================
5 |
6 | *Discrete Mathematics* is the study of finite sets, objects, and structures.
7 | We can count the elements of a finite set, and we can compute finite sums or products over its
8 | elements, we can compute maximums and minimums, and so on.
9 | We can also study objects that are generated by finitely many applications of
10 | certain generating functions, we can define functions by structural recursion,
11 | and prove theorems by structural induction.
12 | This chapters describes parts of Mathlib that support these activities.
13 |
14 | .. include:: C06_Discrete_Mathematics/S01_Finsets_and_Fintypes.inc
15 | .. include:: C06_Discrete_Mathematics/S02_Counting_Arguments.inc
16 | .. include:: C06_Discrete_Mathematics/S03_Inductive_Structures.inc
17 |
--------------------------------------------------------------------------------
/html/_static/js/badge_only.js:
--------------------------------------------------------------------------------
1 | !function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=4)}({4:function(e,t,r){}});
--------------------------------------------------------------------------------
/MIL/C02_Basics/solutions/Solutions_S01_Calculating.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Data.Real.Basic
3 | example (a b c : ℝ) : c * b * a = b * (a * c) := by
4 | rw [mul_comm c b]
5 | rw [mul_assoc b c a]
6 | rw [mul_comm c a]
7 |
8 | example (a b c : ℝ) : a * (b * c) = b * (a * c) := by
9 | rw [← mul_assoc a b c]
10 | rw [mul_comm a b]
11 | rw [mul_assoc b a c]
12 |
13 | example (a b c : ℝ) : a * (b * c) = b * (c * a) := by
14 | rw [mul_comm]
15 | rw [mul_assoc]
16 |
17 | example (a b c : ℝ) : a * (b * c) = b * (a * c) := by
18 | rw [← mul_assoc]
19 | rw [mul_comm a]
20 | rw [mul_assoc]
21 |
22 | example (a b c d e f : ℝ) (h : b * c = e * f) : a * b * c * d = a * e * f * d := by
23 | rw [mul_assoc a]
24 | rw [h]
25 | rw [← mul_assoc]
26 |
27 | example (a b c d : ℝ) (hyp : c = b * a - d) (hyp' : d = a * b) : c = 0 := by
28 | rw [hyp]
29 | rw [hyp']
30 | rw [mul_comm]
31 | rw [sub_self]
32 |
33 |
--------------------------------------------------------------------------------
/MIL/C05_Elementary_Number_Theory/solutions/Solutions_S04_More_Induction.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Analysis.Calculus.Taylor
3 | import Mathlib.Data.Nat.GCD.Basic
4 |
5 | namespace more_induction
6 |
7 | @[simp] def fib : ℕ → ℕ
8 | | 0 => 0
9 | | 1 => 1
10 | | n + 2 => fib n + fib (n + 1)
11 |
12 | theorem fib_add_two (n : ℕ) : fib (n + 2) = fib n + fib (n + 1) := rfl
13 |
14 | theorem fib_add (m n : ℕ) : fib (m + n + 1) = fib m * fib n + fib (m + 1) * fib (n + 1) := by
15 | induction n generalizing m with
16 | | zero => simp
17 | | succ n ih =>
18 | specialize ih (m + 1)
19 | rw [add_assoc m 1 n, add_comm 1 n] at ih
20 | simp only [fib_add_two, Nat.succ_eq_add_one, ih]
21 | ring
22 |
23 | example (n : ℕ): (fib n) ^ 2 + (fib (n + 1)) ^ 2 = fib (2 * n + 1) := by
24 | rw [two_mul, fib_add, pow_two, pow_two]
25 | example (n : ℕ): (fib n) ^ 2 + (fib (n + 1)) ^ 2 = fib (2 * n + 1) := by
26 | rw [two_mul, fib_add, pow_two, pow_two]
27 |
28 |
--------------------------------------------------------------------------------
/MIL/C13_Integration_and_Measure_Theory/S01_Elementary_Integration.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Analysis.SpecialFunctions.Integrals.Basic
3 | import Mathlib.Analysis.Convolution
4 |
5 | open Set Filter
6 |
7 | open Topology Filter
8 |
9 | noncomputable section
10 |
11 | open MeasureTheory intervalIntegral
12 |
13 | open Interval
14 | -- this introduces the notation `[[a, b]]` for the segment from `min a b` to `max a b`
15 |
16 | example (a b : ℝ) : (∫ x in a..b, x) = (b ^ 2 - a ^ 2) / 2 :=
17 | integral_id
18 |
19 | example {a b : ℝ} (h : (0 : ℝ) ∉ [[a, b]]) : (∫ x in a..b, 1 / x) = Real.log (b / a) :=
20 | integral_one_div h
21 |
22 | example (f : ℝ → ℝ) (hf : Continuous f) (a b : ℝ) : deriv (fun u ↦ ∫ x : ℝ in a..u, f x) b = f b :=
23 | (integral_hasStrictDerivAt_right (hf.intervalIntegrable _ _) (hf.stronglyMeasurableAtFilter _ _)
24 | hf.continuousAt).hasDerivAt.deriv
25 |
26 | example {f : ℝ → ℝ} {a b : ℝ} {f' : ℝ → ℝ} (h : ∀ x ∈ [[a, b]], HasDerivAt f (f' x) x)
27 | (h' : IntervalIntegrable f' volume a b) : (∫ y in a..b, f' y) = f b - f a :=
28 | integral_eq_sub_of_hasDerivAt h h'
29 |
30 | open Convolution
31 |
32 | example (f : ℝ → ℝ) (g : ℝ → ℝ) : f ⋆ g = fun x ↦ ∫ t, f t * g (x - t) :=
33 | rfl
34 |
--------------------------------------------------------------------------------
/html/_sources/C07_Structures.rst.txt:
--------------------------------------------------------------------------------
1 | .. _structures:
2 |
3 | Structures
4 | ==========
5 |
6 | Modern mathematics makes essential use of algebraic
7 | structures,
8 | which encapsulate patterns that can be instantiated in
9 | multiple settings.
10 | The subject provides various ways of defining such structures and
11 | constructing particular instances.
12 |
13 | Lean therefore provides corresponding ways of
14 | defining structures formally and working with them.
15 | You have already seen examples of algebraic structures in Lean,
16 | such as rings and lattices, which were discussed in
17 | :numref:`Chapter %s `.
18 | This chapter will explain the mysterious square bracket annotations
19 | that you saw there,
20 | ``[Ring α]`` and ``[Lattice α]``.
21 | It will also show you how to define and use
22 | algebraic structures on your own.
23 |
24 | For more technical detail, you can consult `Theorem Proving in Lean `_,
25 | and a paper by Anne Baanen, `Use and abuse of instance parameters in the Lean mathematical library `_.
26 |
27 | .. include:: C07_Structures/S01_Structures.inc
28 | .. include:: C07_Structures/S02_Algebraic_Structures.inc
29 | .. include:: C07_Structures/S03_Building_the_Gaussian_Integers.inc
30 |
--------------------------------------------------------------------------------
/html/_sources/C09_Groups_and_Rings.rst.txt:
--------------------------------------------------------------------------------
1 | .. _groups_and_ring:
2 |
3 | Groups and Rings
4 | ================
5 |
6 | We saw in :numref:`proving_identities_in_algebraic_structures` how to reason about
7 | operations in groups and rings. Later, in :numref:`section_algebraic_structures`, we saw how
8 | to define abstract algebraic structures, such as group structures, as well as concrete instances
9 | such as the ring structure on the Gaussian integers. :numref:`Chapter %s ` explained how
10 | hierarchies of abstract structures are handled in Mathlib.
11 |
12 | In this chapter we work with groups and rings in more detail. We won't be able to
13 | cover every aspect of the treatment of these topics in Mathlib, especially since Mathlib is constantly growing.
14 | But we will provide entry points to the library and show how the essential concepts are used.
15 | There is some overlap with the discussion of
16 | :numref:`Chapter %s `, but here we will focus on how to use Mathlib instead of the design
17 | decisions behind the way the topics are treated.
18 | So making sense of some of the examples may require reviewing the background from
19 | :numref:`Chapter %s `.
20 |
21 | .. include:: C09_Groups_and_Rings/S01_Groups.inc
22 | .. include:: C09_Groups_and_Rings/S02_Rings.inc
23 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "files.exclude": {
3 | "**/.git": true,
4 | "**/.DS_Store": true,
5 | "**/*.olean": true,
6 | "**/.DS_yml": true,
7 | "**/.gitpod.yml": true,
8 | "**/.vscode": true,
9 | ".devcontainer.json": true,
10 | ".docker": true,
11 | "build": true,
12 | "html": true,
13 | "lake-packages": true,
14 | ".gitignore": true,
15 | "lake-manifest.json": true,
16 | "lakefile.lean": true,
17 | "lean-toolchain": true,
18 | "mathematics_in_lean.pdf": true,
19 | "MIL.lean": true,
20 | "README.md":true,
21 | ".lake": true,
22 | ".devcontainer": true,
23 | ".github": true
24 | },
25 | "editor.minimap.enabled": false,
26 | "editor.acceptSuggestionOnEnter": "off",
27 | "editor.quickSuggestions.comments": true,
28 | "scm.diffDecorationsGutterVisibility": "hover",
29 | "editor.semanticHighlighting.enabled": true,
30 | "editor.semanticTokenColorCustomizations": {
31 | "[Default Light+]": {"rules": {"variable": "#1a31da"}}
32 | },
33 | "editor.unicodeHighlight.nonBasicASCII": false,
34 | "editor.unicodeHighlight.ambiguousCharacters": false,
35 | "editor.fontLigatures": true,
36 | "files.trimTrailingWhitespace": true,
37 | "files.trimFinalNewlines": true,
38 | "lean4.infoview.emphasizeFirstGoal": true,
39 | "lean4.infoview.showExpectedType": false
40 | }
41 |
--------------------------------------------------------------------------------
/MIL/C01_Introduction/S02_Overview.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 |
3 | open Nat
4 |
5 | -- These are pieces of data.
6 | #check 2 + 2
7 |
8 | def f (x : ℕ) :=
9 | x + 3
10 |
11 | #check f
12 |
13 | -- These are propositions, of type `Prop`.
14 | #check 2 + 2 = 4
15 |
16 | def FermatLastTheorem :=
17 | ∀ x y z n : ℕ, n > 2 ∧ x * y * z ≠ 0 → x ^ n + y ^ n ≠ z ^ n
18 |
19 | #check FermatLastTheorem
20 |
21 | -- These are proofs of propositions.
22 | theorem easy : 2 + 2 = 4 :=
23 | rfl
24 |
25 | #check easy
26 |
27 | theorem hard : FermatLastTheorem :=
28 | sorry
29 |
30 | #check hard
31 |
32 | -- Here are some proofs.
33 | example : ∀ m n : Nat, Even n → Even (m * n) := fun m n ⟨k, (hk : n = k + k)⟩ ↦
34 | have hmn : m * n = m * k + m * k := by rw [hk, mul_add]
35 | show ∃ l, m * n = l + l from ⟨_, hmn⟩
36 |
37 | example : ∀ m n : Nat, Even n → Even (m * n) :=
38 | fun m n ⟨k, hk⟩ ↦ ⟨m * k, by rw [hk, mul_add]⟩
39 |
40 | example : ∀ m n : Nat, Even n → Even (m * n) := by
41 | -- Say `m` and `n` are natural numbers, and assume `n = 2 * k`.
42 | rintro m n ⟨k, hk⟩
43 | -- We need to prove `m * n` is twice a natural number. Let's show it's twice `m * k`.
44 | use m * k
45 | -- Substitute for `n`,
46 | rw [hk]
47 | -- and now it's obvious.
48 | ring
49 |
50 | example : ∀ m n : Nat, Even n → Even (m * n) := by
51 | rintro m n ⟨k, hk⟩; use m * k; rw [hk]; ring
52 |
53 | example : ∀ m n : Nat, Even n → Even (m * n) := by
54 | intros; simp [*, parity_simps]
55 |
56 |
--------------------------------------------------------------------------------
/html/_sources/C08_Hierarchies.rst.txt:
--------------------------------------------------------------------------------
1 | .. _hierarchies:
2 |
3 | Hierarchies
4 | ===========
5 |
6 | We have seen in :numref:`Chapter %s ` how to define the class
7 | of groups and build instances of this class, and then how to build an instance
8 | of the commutative ring class. But of course there is a hierarchy here: a
9 | commutative ring is in particular an additive group. In this chapter we
10 | will study how to build such hierarchies. They appear in all branches
11 | of mathematics but in this chapter the emphasis will be on algebraic examples.
12 |
13 | It may seem premature to discuss how to build hierarchies before more discussions
14 | about using existing hierarchies. But some understanding of the technology underlying
15 | hierarchies is required to use them. So you should probably still read this chapter,
16 | but without trying too hard to remember everything on your first read, then read
17 | the following chapters and come back here for a second reading.
18 |
19 | In this chapter, we will redefine (simpler versions of) many things that appear in Mathlib
20 | so we will used indices to distinguish our version. For instance we will have ``Ring₁``
21 | as our version of ``Ring``. Since we will gradually explain more powerful ways of formalizing
22 | structures, those indices will sometimes grow beyond one.
23 |
24 | .. include:: C08_Hierarchies/S01_Basics.inc
25 | .. include:: C08_Hierarchies/S02_Morphisms.inc
26 | .. include:: C08_Hierarchies/S03_Subobjects.inc
27 |
--------------------------------------------------------------------------------
/.docker/gitpod/Dockerfile:
--------------------------------------------------------------------------------
1 | # This is the Dockerfile for `leanprovercommunity/mathlib:gitpod`.
2 |
3 | # gitpod doesn't support multiple FROM statements, (or rather, you can't copy from one to another)
4 | # so we just install everything in one go
5 | FROM ubuntu:jammy
6 |
7 | USER root
8 |
9 | RUN apt-get update && apt-get install sudo git curl git bash-completion python3 -y && apt-get clean
10 |
11 | RUN useradd -l -u 33333 -G sudo -md /home/gitpod -s /bin/bash -p gitpod gitpod \
12 | # passwordless sudo for users in the 'sudo' group
13 | && sed -i.bkp -e 's/%sudo\s\+ALL=(ALL\(:ALL\)\?)\s\+ALL/%sudo ALL=NOPASSWD:ALL/g' /etc/sudoers
14 | USER gitpod
15 | WORKDIR /home/gitpod
16 |
17 | SHELL ["/bin/bash", "-c"]
18 |
19 | # gitpod bash prompt
20 | RUN { echo && echo "PS1='\[\033[01;32m\]\u\[\033[00m\] \[\033[01;34m\]\w\[\033[00m\]\$(__git_ps1 \" (%s)\") $ '" ; } >> .bashrc
21 |
22 | # install elan
23 | RUN curl https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh -sSf | sh -s -- -y --default-toolchain none
24 |
25 | # install whichever toolchain mathlib is currently using
26 | RUN . ~/.profile && elan toolchain install $(curl https://raw.githubusercontent.com/leanprover-community/mathlib4/master/lean-toolchain)
27 |
28 | ENV PATH="/home/gitpod/.local/bin:/home/gitpod/.elan/bin:${PATH}"
29 |
30 | # fix the infoview when the container is used on gitpod:
31 | ENV VSCODE_API_VERSION="1.50.0"
32 |
33 | # ssh to github once to bypass the unknown fingerprint warning
34 | RUN ssh -o StrictHostKeyChecking=no github.com || true
35 |
36 | # run sudo once to suppress usage info
37 | RUN sudo echo finished
--------------------------------------------------------------------------------
/MIL/C12_Differential_Calculus/S01_Elementary_Differential_Calculus.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv
3 | import Mathlib.Analysis.Calculus.Deriv.Pow
4 | import Mathlib.Analysis.Calculus.MeanValue
5 |
6 | open Set Filter
7 | open Topology Filter Classical Real
8 |
9 | noncomputable section
10 |
11 | open Real
12 |
13 | /-- The sin function has derivative 1 at 0. -/
14 | example : HasDerivAt sin 1 0 := by simpa using hasDerivAt_sin 0
15 |
16 | example (x : ℝ) : DifferentiableAt ℝ sin x :=
17 | (hasDerivAt_sin x).differentiableAt
18 |
19 | example {f : ℝ → ℝ} {x a : ℝ} (h : HasDerivAt f a x) : deriv f x = a :=
20 | h.deriv
21 |
22 | example {f : ℝ → ℝ} {x : ℝ} (h : ¬DifferentiableAt ℝ f x) : deriv f x = 0 :=
23 | deriv_zero_of_not_differentiableAt h
24 |
25 | example {f g : ℝ → ℝ} {x : ℝ} (hf : DifferentiableAt ℝ f x) (hg : DifferentiableAt ℝ g x) :
26 | deriv (f + g) x = deriv f x + deriv g x :=
27 | deriv_add hf hg
28 |
29 | example {f : ℝ → ℝ} {a : ℝ} (h : IsLocalMin f a) : deriv f a = 0 :=
30 | h.deriv_eq_zero
31 |
32 | open Set
33 |
34 | example {f : ℝ → ℝ} {a b : ℝ} (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hfI : f a = f b) :
35 | ∃ c ∈ Ioo a b, deriv f c = 0 :=
36 | exists_deriv_eq_zero hab hfc hfI
37 |
38 | example (f : ℝ → ℝ) {a b : ℝ} (hab : a < b) (hf : ContinuousOn f (Icc a b))
39 | (hf' : DifferentiableOn ℝ f (Ioo a b)) : ∃ c ∈ Ioo a b, deriv f c = (f b - f a) / (b - a) :=
40 | exists_deriv_eq_slope f hab hf hf'
41 |
42 | example : deriv (fun x : ℝ ↦ x ^ 5) 6 = 5 * 6 ^ 4 := by simp
43 |
44 | example : deriv sin π = -1 := by simp
45 |
--------------------------------------------------------------------------------
/MIL/C13_Integration_and_Measure_Theory/S02_Measure_Theory.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Analysis.Normed.Module.FiniteDimension
3 | import Mathlib.Analysis.Convolution
4 | import Mathlib.MeasureTheory.Function.Jacobian
5 | import Mathlib.MeasureTheory.Integral.Bochner.Basic
6 | import Mathlib.MeasureTheory.Measure.Lebesgue.Basic
7 |
8 | open Set Filter
9 |
10 | noncomputable section
11 |
12 | variable {α : Type*} [MeasurableSpace α]
13 |
14 | example : MeasurableSet (∅ : Set α) :=
15 | MeasurableSet.empty
16 |
17 | example : MeasurableSet (univ : Set α) :=
18 | MeasurableSet.univ
19 |
20 | example {s : Set α} (hs : MeasurableSet s) : MeasurableSet (sᶜ) :=
21 | hs.compl
22 |
23 | example : Encodable ℕ := by infer_instance
24 |
25 | example (n : ℕ) : Encodable (Fin n) := by infer_instance
26 |
27 | variable {ι : Type*} [Encodable ι]
28 |
29 | example {f : ι → Set α} (h : ∀ b, MeasurableSet (f b)) : MeasurableSet (⋃ b, f b) :=
30 | MeasurableSet.iUnion h
31 |
32 | example {f : ι → Set α} (h : ∀ b, MeasurableSet (f b)) : MeasurableSet (⋂ b, f b) :=
33 | MeasurableSet.iInter h
34 |
35 | open MeasureTheory Function
36 | variable {μ : Measure α}
37 |
38 | example (s : Set α) : μ s = ⨅ (t : Set α) (_ : s ⊆ t) (_ : MeasurableSet t), μ t :=
39 | measure_eq_iInf s
40 |
41 | example (s : ι → Set α) : μ (⋃ i, s i) ≤ ∑' i, μ (s i) :=
42 | measure_iUnion_le s
43 |
44 | example {f : ℕ → Set α} (hmeas : ∀ i, MeasurableSet (f i)) (hdis : Pairwise (Disjoint on f)) :
45 | μ (⋃ i, f i) = ∑' i, μ (f i) :=
46 | μ.m_iUnion hmeas hdis
47 |
48 | example {P : α → Prop} : (∀ᵐ x ∂μ, P x) ↔ ∀ᶠ x in ae μ, P x :=
49 | Iff.rfl
50 |
--------------------------------------------------------------------------------
/MIL/C02_Basics/solutions/Solutions_S03_Using_Theorems_and_Lemmas.lean:
--------------------------------------------------------------------------------
1 | import Mathlib.Analysis.SpecialFunctions.Log.Basic
2 | import MIL.Common
3 |
4 | variable (a b c d e : ℝ)
5 | open Real
6 |
7 | example (h₀ : a ≤ b) (h₁ : b < c) (h₂ : c ≤ d) (h₃ : d < e) : a < e := by
8 | apply lt_of_le_of_lt h₀
9 | apply lt_trans h₁
10 | exact lt_of_le_of_lt h₂ h₃
11 |
12 | example (h₀ : d ≤ e) : c + exp (a + d) ≤ c + exp (a + e) := by
13 | apply add_le_add_left
14 | rw [exp_le_exp]
15 | apply add_le_add_left h₀
16 |
17 | -- an alternative using `linarith`.
18 | example (h₀ : d ≤ e) : c + exp (a + d) ≤ c + exp (a + e) := by
19 | have : exp (a + d) ≤ exp (a + e) := by
20 | rw [exp_le_exp]
21 | linarith
22 | linarith [this]
23 |
24 | example (h : a ≤ b) : log (1 + exp a) ≤ log (1 + exp b) := by
25 | have h₀ : 0 < 1 + exp a := by linarith [exp_pos a]
26 | apply log_le_log h₀
27 | apply add_le_add_left (exp_le_exp.mpr h)
28 |
29 | -- SOLUTION.
30 | example (h : a ≤ b) : c - exp b ≤ c - exp a := by
31 | apply sub_le_sub_left
32 | exact exp_le_exp.mpr h
33 |
34 | -- alternatively:
35 | example (h : a ≤ b) : c - exp b ≤ c - exp a := by
36 | linarith [exp_le_exp.mpr h]
37 |
38 | theorem fact1 : a*b*2 ≤ a^2 + b^2 := by
39 | have h : 0 ≤ a^2 - 2*a*b + b^2
40 | calc
41 | a^2 - 2*a*b + b^2 = (a - b)^2 := by ring
42 | _ ≥ 0 := by apply pow_two_nonneg
43 | linarith
44 |
45 | theorem fact2 : -(a*b)*2 ≤ a^2 + b^2 := by
46 | have h : 0 ≤ a^2 + 2*a*b + b^2
47 | calc
48 | a^2 + 2*a*b + b^2 = (a + b)^2 := by ring
49 | _ ≥ 0 := by apply pow_two_nonneg
50 | linarith
51 |
52 | example : |a*b| ≤ (a^2 + b^2)/2 := by
53 | have h : (0 : ℝ) < 2 := by norm_num
54 | apply abs_le'.mpr
55 | constructor
56 | · rw [le_div_iff₀ h]
57 | apply fact1
58 | rw [le_div_iff₀ h]
59 | apply fact2
60 |
61 |
--------------------------------------------------------------------------------
/html/_sources/C04_Sets_and_Functions.rst.txt:
--------------------------------------------------------------------------------
1 | .. _sets_and_functions:
2 |
3 | Sets and Functions
4 | ==================
5 |
6 | The vocabulary of sets, relations, and functions provides a uniform
7 | language for carrying out constructions in all the branches of
8 | mathematics.
9 | Since functions and relations can be defined in terms of sets,
10 | axiomatic set theory can be used as a foundation for mathematics.
11 |
12 | Lean's foundation is based instead on the primitive notion of a *type*,
13 | and it includes ways of defining functions between types.
14 | Every expression in Lean has a type:
15 | there are natural numbers, real numbers, functions from reals to reals,
16 | groups, vector spaces, and so on.
17 | Some expressions *are* types,
18 | which is to say,
19 | their type is ``Type``.
20 | Lean and Mathlib provide ways of defining new types,
21 | and ways of defining objects of those types.
22 |
23 | Conceptually, you can think of a type as just a set of objects.
24 | Requiring every object to have a type has some advantages.
25 | For example, it makes it possible to overload notation like ``+``,
26 | and it sometimes makes input less verbose
27 | because Lean can infer a lot of information from
28 | an object's type.
29 | The type system also enables Lean to flag errors when you
30 | apply a function to the wrong number of arguments,
31 | or apply a function to arguments of the wrong type.
32 |
33 | Lean's library does define elementary set-theoretic notions.
34 | In contrast to set theory,
35 | in Lean a set is always a set of objects of some type,
36 | such as a set of natural numbers or a set of functions
37 | from real numbers to real numbers.
38 | The distinction between types and sets takes some getting used to,
39 | but this chapter will take you through the essentials.
40 |
41 | .. include:: C04_Sets_and_Functions/S01_Sets.inc
42 | .. include:: C04_Sets_and_Functions/S02_Functions.inc
43 | .. include:: C04_Sets_and_Functions/S03_The_Schroeder_Bernstein_Theorem.inc
44 |
--------------------------------------------------------------------------------
/MIL/C02_Basics/S04_More_on_Order_and_Divisibility.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Data.Real.Basic
3 |
4 | namespace C02S04
5 |
6 | section
7 | variable (a b c d : ℝ)
8 |
9 | #check (min_le_left a b : min a b ≤ a)
10 | #check (min_le_right a b : min a b ≤ b)
11 | #check (le_min : c ≤ a → c ≤ b → c ≤ min a b)
12 |
13 | example : min a b = min b a := by
14 | apply le_antisymm
15 | · show min a b ≤ min b a
16 | apply le_min
17 | · apply min_le_right
18 | apply min_le_left
19 | · show min b a ≤ min a b
20 | apply le_min
21 | · apply min_le_right
22 | apply min_le_left
23 |
24 | example : min a b = min b a := by
25 | have h : ∀ x y : ℝ, min x y ≤ min y x := by
26 | intro x y
27 | apply le_min
28 | apply min_le_right
29 | apply min_le_left
30 | apply le_antisymm
31 | apply h
32 | apply h
33 |
34 | example : min a b = min b a := by
35 | apply le_antisymm
36 | repeat
37 | apply le_min
38 | apply min_le_right
39 | apply min_le_left
40 |
41 | example : max a b = max b a := by
42 | sorry
43 | example : min (min a b) c = min a (min b c) := by
44 | sorry
45 | theorem aux : min a b + c ≤ min (a + c) (b + c) := by
46 | sorry
47 | example : min a b + c = min (a + c) (b + c) := by
48 | sorry
49 | #check (abs_add : ∀ a b : ℝ, |a + b| ≤ |a| + |b|)
50 |
51 | example : |a| - |b| ≤ |a - b| :=
52 | sorry
53 | end
54 |
55 | section
56 | variable (w x y z : ℕ)
57 |
58 | example (h₀ : x ∣ y) (h₁ : y ∣ z) : x ∣ z :=
59 | dvd_trans h₀ h₁
60 |
61 | example : x ∣ y * x * z := by
62 | apply dvd_mul_of_dvd_left
63 | apply dvd_mul_left
64 |
65 | example : x ∣ x ^ 2 := by
66 | apply dvd_mul_left
67 |
68 | example (h : x ∣ w) : x ∣ y * (x * z) + x ^ 2 + w ^ 2 := by
69 | sorry
70 | end
71 |
72 | section
73 | variable (m n : ℕ)
74 |
75 | #check (Nat.gcd_zero_right n : Nat.gcd n 0 = n)
76 | #check (Nat.gcd_zero_left n : Nat.gcd 0 n = n)
77 | #check (Nat.lcm_zero_right n : Nat.lcm n 0 = 0)
78 | #check (Nat.lcm_zero_left n : Nat.lcm 0 n = 0)
79 |
80 | example : Nat.gcd m n = Nat.gcd n m := by
81 | sorry
82 | end
83 |
84 |
85 |
--------------------------------------------------------------------------------
/MIL/C03_Logic/solutions/Solutions_S02_The_Existential_Quantifier.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Data.Real.Basic
3 |
4 | set_option autoImplicit true
5 |
6 | namespace C03S02
7 |
8 | def FnUb (f : ℝ → ℝ) (a : ℝ) : Prop :=
9 | ∀ x, f x ≤ a
10 |
11 | def FnLb (f : ℝ → ℝ) (a : ℝ) : Prop :=
12 | ∀ x, a ≤ f x
13 |
14 | def FnHasUb (f : ℝ → ℝ) :=
15 | ∃ a, FnUb f a
16 |
17 | def FnHasLb (f : ℝ → ℝ) :=
18 | ∃ a, FnLb f a
19 |
20 | theorem fnUb_add {f g : ℝ → ℝ} {a b : ℝ} (hfa : FnUb f a) (hgb : FnUb g b) :
21 | FnUb (fun x ↦ f x + g x) (a + b) :=
22 | fun x ↦ add_le_add (hfa x) (hgb x)
23 |
24 | section
25 |
26 | variable {f g : ℝ → ℝ}
27 |
28 | example (lbf : FnHasLb f) (lbg : FnHasLb g) : FnHasLb fun x ↦ f x + g x := by
29 | rcases lbf with ⟨a, lbfa⟩
30 | rcases lbg with ⟨b, lbgb⟩
31 | use a + b
32 | intro x
33 | exact add_le_add (lbfa x) (lbgb x)
34 |
35 | example {c : ℝ} (ubf : FnHasUb f) (h : c ≥ 0) : FnHasUb fun x ↦ c * f x := by
36 | rcases ubf with ⟨a, ubfa⟩
37 | use c * a
38 | intro x
39 | exact mul_le_mul_of_nonneg_left (ubfa x) h
40 |
41 | end
42 |
43 | section
44 | variable {a b c : ℕ}
45 |
46 | example (divab : a ∣ b) (divbc : b ∣ c) : a ∣ c := by
47 | rcases divab with ⟨d, rfl⟩
48 | rcases divbc with ⟨e, rfl⟩
49 | use d * e; ring
50 |
51 | example (divab : a ∣ b) (divac : a ∣ c) : a ∣ b + c := by
52 | rcases divab with ⟨d, rfl⟩
53 | rcases divac with ⟨e, rfl⟩
54 | use d + e; ring
55 |
56 | end
57 |
58 | section
59 |
60 | open Function
61 |
62 | example {c : ℝ} (h : c ≠ 0) : Surjective fun x ↦ c * x := by
63 | intro x
64 | use x / c
65 | dsimp; rw [mul_div_cancel₀ _ h]
66 |
67 | example {c : ℝ} (h : c ≠ 0) : Surjective fun x ↦ c * x := by
68 | intro x
69 | use x / c
70 | field_simp
71 |
72 | end
73 |
74 | section
75 | open Function
76 | variable {α : Type*} {β : Type*} {γ : Type*}
77 | variable {g : β → γ} {f : α → β}
78 |
79 | example (surjg : Surjective g) (surjf : Surjective f) : Surjective fun x ↦ g (f x) := by
80 | intro z
81 | rcases surjg z with ⟨y, rfl⟩
82 | rcases surjf y with ⟨x, rfl⟩
83 | use x
84 |
85 | end
86 |
--------------------------------------------------------------------------------
/MIL/C07_Structures/solutions/Solutions_S02_Algebraic_Structures.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Data.Real.Basic
3 |
4 | namespace C06S02
5 |
6 | structure AddGroup₁ (α : Type*) where
7 | add : α → α → α
8 | zero : α
9 | neg : α → α
10 | add_assoc : ∀ x y z : α, add (add x y) z = add x (add y z)
11 | add_zero : ∀ x : α, add x zero = x
12 | zero_add : ∀ x : α, add x zero = x
13 | neg_add_cancel : ∀ x : α, add (neg x) x = zero
14 |
15 | @[ext]
16 | structure Point where
17 | x : ℝ
18 | y : ℝ
19 | z : ℝ
20 |
21 | namespace Point
22 |
23 | def add (a b : Point) : Point :=
24 | ⟨a.x + b.x, a.y + b.y, a.z + b.z⟩
25 |
26 | def neg (a : Point) : Point :=
27 | ⟨-a.x, -a.y, -a.z⟩
28 |
29 | def zero : Point :=
30 | ⟨0, 0, 0⟩
31 |
32 | def addGroupPoint : AddGroup₁ Point where
33 | add := Point.add
34 | zero := Point.zero
35 | neg := Point.neg
36 | add_assoc := by simp [Point.add, add_assoc]
37 | add_zero := by simp [Point.add, Point.zero]
38 | zero_add := by simp [Point.add, Point.zero]
39 | neg_add_cancel := by simp [Point.add, Point.neg, Point.zero]
40 |
41 | end Point
42 |
43 | class AddGroup₂ (α : Type*) where
44 | add : α → α → α
45 | zero : α
46 | neg : α → α
47 | add_assoc : ∀ x y z : α, add (add x y) z = add x (add y z)
48 | add_zero : ∀ x : α, add x zero = x
49 | zero_add : ∀ x : α, add x zero = x
50 | neg_add_cancel : ∀ x : α, add (neg x) x = zero
51 |
52 | instance hasAddAddGroup₂ {α : Type*} [AddGroup₂ α] : Add α :=
53 | ⟨AddGroup₂.add⟩
54 |
55 | instance hasZeroAddGroup₂ {α : Type*} [AddGroup₂ α] : Zero α :=
56 | ⟨AddGroup₂.zero⟩
57 |
58 | instance hasNegAddGroup₂ {α : Type*} [AddGroup₂ α] : Neg α :=
59 | ⟨AddGroup₂.neg⟩
60 |
61 | instance : AddGroup₂ Point where
62 | add := Point.add
63 | zero := Point.zero
64 | neg := Point.neg
65 | add_assoc := by simp [Point.add, add_assoc]
66 | add_zero := by simp [Point.add, Point.zero]
67 | zero_add := by simp [Point.add, Point.zero]
68 | neg_add_cancel := by simp [Point.add, Point.neg, Point.zero]
69 |
70 | section
71 | variable (x y : Point)
72 |
73 | #check x + -y + 0
74 |
75 | end
76 |
77 |
--------------------------------------------------------------------------------
/MIL/C03_Logic/solutions/Solutions_S04_Conjunction_and_Iff.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Data.Real.Basic
3 | import Mathlib.Data.Nat.Prime.Basic
4 |
5 | namespace C03S04
6 |
7 | example {m n : ℕ} (h : m ∣ n ∧ m ≠ n) : m ∣ n ∧ ¬n ∣ m := by
8 | rcases h with ⟨h0, h1⟩
9 | constructor
10 | · exact h0
11 | intro h2
12 | apply h1
13 | apply Nat.dvd_antisymm h0 h2
14 |
15 | example {x y : ℝ} : x ≤ y ∧ ¬y ≤ x ↔ x ≤ y ∧ x ≠ y := by
16 | constructor
17 | · rintro ⟨h0, h1⟩
18 | constructor
19 | · exact h0
20 | intro h2
21 | apply h1
22 | rw [h2]
23 | rintro ⟨h0, h1⟩
24 | constructor
25 | · exact h0
26 | intro h2
27 | apply h1
28 | apply le_antisymm h0 h2
29 |
30 | theorem aux {x y : ℝ} (h : x ^ 2 + y ^ 2 = 0) : x = 0 :=
31 | have h' : x ^ 2 = 0 := by linarith [pow_two_nonneg x, pow_two_nonneg y]
32 | pow_eq_zero h'
33 |
34 | example (x y : ℝ) : x ^ 2 + y ^ 2 = 0 ↔ x = 0 ∧ y = 0 := by
35 | constructor
36 | · intro h
37 | constructor
38 | · exact aux h
39 | rw [add_comm] at h
40 | exact aux h
41 | rintro ⟨rfl, rfl⟩
42 | norm_num
43 |
44 | theorem not_monotone_iff {f : ℝ → ℝ} : ¬Monotone f ↔ ∃ x y, x ≤ y ∧ f x > f y := by
45 | rw [Monotone]
46 | push_neg
47 | rfl
48 |
49 | example : ¬Monotone fun x : ℝ ↦ -x := by
50 | rw [not_monotone_iff]
51 | use 0, 1
52 | norm_num
53 |
54 | section
55 | variable {α : Type*} [PartialOrder α]
56 | variable (a b : α)
57 |
58 | example : a < b ↔ a ≤ b ∧ a ≠ b := by
59 | rw [lt_iff_le_not_ge]
60 | constructor
61 | · rintro ⟨h0, h1⟩
62 | constructor
63 | · exact h0
64 | intro h2
65 | apply h1
66 | rw [h2]
67 | rintro ⟨h0, h1⟩
68 | constructor
69 | · exact h0
70 | intro h2
71 | apply h1
72 | apply le_antisymm h0 h2
73 |
74 | end
75 |
76 | section
77 | variable {α : Type*} [Preorder α]
78 | variable (a b c : α)
79 |
80 | example : ¬a < a := by
81 | rw [lt_iff_le_not_ge]
82 | rintro ⟨h0, h1⟩
83 | exact h1 h0
84 |
85 | example : a < b → b < c → a < c := by
86 | simp only [lt_iff_le_not_ge]
87 | rintro ⟨h0, h1⟩ ⟨h2, h3⟩
88 | constructor
89 | · apply le_trans h0 h2
90 | intro h4
91 | apply h1
92 | apply le_trans h2 h4
93 |
94 | end
95 |
--------------------------------------------------------------------------------
/MIL/C10_Linear_Algebra/solutions/Solutions_S03_Endomorphisms.lean:
--------------------------------------------------------------------------------
1 | import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
2 | import Mathlib.LinearAlgebra.Eigenspace.Minpoly
3 | import Mathlib.LinearAlgebra.Charpoly.Basic
4 |
5 | import MIL.Common
6 |
7 |
8 |
9 |
10 | variable {K : Type*} [Field K] {V : Type*} [AddCommGroup V] [Module K V]
11 |
12 | variable {W : Type*} [AddCommGroup W] [Module K W]
13 |
14 |
15 | open Polynomial Module LinearMap End
16 |
17 | example (φ ψ : End K V) : φ * ψ = φ ∘ₗ ψ :=
18 | End.mul_eq_comp φ ψ -- `rfl` would also work
19 |
20 | -- evaluating `P` on `φ`
21 | example (P : K[X]) (φ : End K V) : V →ₗ[K] V :=
22 | aeval φ P
23 |
24 | -- evaluating `X` on `φ` gives back `φ`
25 | example (φ : End K V) : aeval φ (X : K[X]) = φ :=
26 | aeval_X φ
27 |
28 |
29 |
30 | #check Submodule.eq_bot_iff
31 | #check Submodule.mem_inf
32 | #check LinearMap.mem_ker
33 |
34 | example (P Q : K[X]) (h : IsCoprime P Q) (φ : End K V) : ker (aeval φ P) ⊓ ker (aeval φ Q) = ⊥ := by
35 | rw [Submodule.eq_bot_iff]
36 | rintro x hx
37 | rw [Submodule.mem_inf, mem_ker, mem_ker] at hx
38 | rcases h with ⟨U, V, hUV⟩
39 | have := congr((aeval φ) $hUV.symm x)
40 | simpa [hx]
41 |
42 | #check Submodule.add_mem_sup
43 | #check map_mul
44 | #check End.mul_apply
45 | #check LinearMap.ker_le_ker_comp
46 |
47 | example (P Q : K[X]) (h : IsCoprime P Q) (φ : End K V) :
48 | ker (aeval φ P) ⊔ ker (aeval φ Q) = ker (aeval φ (P*Q)) := by
49 | apply le_antisymm
50 | · apply sup_le
51 | · rw [mul_comm, map_mul]
52 | apply ker_le_ker_comp -- or alternative below:
53 | -- intro x hx
54 | -- rw [mul_comm, mem_ker] at *
55 | -- simp [hx]
56 | · rw [map_mul]
57 | apply ker_le_ker_comp -- or alternative as above
58 | · intro x hx
59 | rcases h with ⟨U, V, hUV⟩
60 | have key : x = aeval φ (U*P) x + aeval φ (V*Q) x := by simpa using congr((aeval φ) $hUV.symm x)
61 | rw [key, add_comm]
62 | apply Submodule.add_mem_sup <;> rw [mem_ker] at *
63 | · rw [← mul_apply, ← map_mul, show P*(V*Q) = V*(P*Q) by ring, map_mul, mul_apply, hx,
64 | map_zero]
65 | · rw [← mul_apply, ← map_mul, show Q*(U*P) = U*(P*Q) by ring, map_mul, mul_apply, hx,
66 | map_zero]
67 |
68 |
--------------------------------------------------------------------------------
/MIL/C10_Linear_Algebra/S03_Endomorphisms.lean:
--------------------------------------------------------------------------------
1 | import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
2 | import Mathlib.LinearAlgebra.Eigenspace.Minpoly
3 | import Mathlib.LinearAlgebra.Charpoly.Basic
4 |
5 | import MIL.Common
6 |
7 |
8 |
9 |
10 | variable {K : Type*} [Field K] {V : Type*} [AddCommGroup V] [Module K V]
11 |
12 | variable {W : Type*} [AddCommGroup W] [Module K W]
13 |
14 |
15 | open Polynomial Module LinearMap End
16 |
17 | example (φ ψ : End K V) : φ * ψ = φ ∘ₗ ψ :=
18 | End.mul_eq_comp φ ψ -- `rfl` would also work
19 |
20 | -- evaluating `P` on `φ`
21 | example (P : K[X]) (φ : End K V) : V →ₗ[K] V :=
22 | aeval φ P
23 |
24 | -- evaluating `X` on `φ` gives back `φ`
25 | example (φ : End K V) : aeval φ (X : K[X]) = φ :=
26 | aeval_X φ
27 |
28 |
29 |
30 | #check Submodule.eq_bot_iff
31 | #check Submodule.mem_inf
32 | #check LinearMap.mem_ker
33 |
34 | example (P Q : K[X]) (h : IsCoprime P Q) (φ : End K V) : ker (aeval φ P) ⊓ ker (aeval φ Q) = ⊥ := by
35 | sorry
36 |
37 | #check Submodule.add_mem_sup
38 | #check map_mul
39 | #check End.mul_apply
40 | #check LinearMap.ker_le_ker_comp
41 |
42 | example (P Q : K[X]) (h : IsCoprime P Q) (φ : End K V) :
43 | ker (aeval φ P) ⊔ ker (aeval φ Q) = ker (aeval φ (P*Q)) := by
44 | sorry
45 | example (φ : End K V) (a : K) : φ.eigenspace a = LinearMap.ker (φ - a • 1) :=
46 | End.eigenspace_def
47 |
48 |
49 |
50 | example (φ : End K V) (a : K) : φ.HasEigenvalue a ↔ φ.eigenspace a ≠ ⊥ :=
51 | Iff.rfl
52 |
53 | example (φ : End K V) (a : K) : φ.HasEigenvalue a ↔ ∃ v, φ.HasEigenvector a v :=
54 | ⟨End.HasEigenvalue.exists_hasEigenvector, fun ⟨_, hv⟩ ↦ φ.hasEigenvalue_of_hasEigenvector hv⟩
55 |
56 | example (φ : End K V) : φ.Eigenvalues = {a // φ.HasEigenvalue a} :=
57 | rfl
58 |
59 | -- Eigenvalue are roots of the minimal polynomial
60 | example (φ : End K V) (a : K) : φ.HasEigenvalue a → (minpoly K φ).IsRoot a :=
61 | φ.isRoot_of_hasEigenvalue
62 |
63 | -- In finite dimension, the converse is also true (we will discuss dimension below)
64 | example [FiniteDimensional K V] (φ : End K V) (a : K) :
65 | φ.HasEigenvalue a ↔ (minpoly K φ).IsRoot a :=
66 | φ.hasEigenvalue_iff_isRoot
67 |
68 | -- Cayley-Hamilton
69 | example [FiniteDimensional K V] (φ : End K V) : aeval φ φ.charpoly = 0 :=
70 | φ.aeval_self_charpoly
71 |
72 |
--------------------------------------------------------------------------------
/MIL/C02_Basics/solutions/Solutions_S02_Proving_Identities_in_Algebraic_Structures.lean:
--------------------------------------------------------------------------------
1 | import Mathlib.Algebra.Ring.Defs
2 | import Mathlib.Data.Real.Basic
3 | import MIL.Common
4 |
5 | namespace MyRing
6 | variable {R : Type*} [Ring R]
7 |
8 | theorem add_neg_cancel_right (a b : R) : a + b + -b = a := by
9 | rw [add_assoc, add_neg_cancel, add_zero]
10 |
11 | theorem add_left_cancel {a b c : R} (h : a + b = a + c) : b = c := by
12 | rw [← neg_add_cancel_left a b, h, neg_add_cancel_left]
13 |
14 | theorem add_right_cancel {a b c : R} (h : a + b = c + b) : a = c := by
15 | rw [← add_neg_cancel_right a b, h, add_neg_cancel_right]
16 |
17 | theorem zero_mul (a : R) : 0 * a = 0 := by
18 | have h : 0 * a + 0 * a = 0 * a + 0 := by rw [← add_mul, add_zero, add_zero]
19 | rw [add_left_cancel h]
20 |
21 | theorem neg_eq_of_add_eq_zero {a b : R} (h : a + b = 0) : -a = b := by
22 | rw [← neg_add_cancel_left a b, h, add_zero]
23 |
24 | theorem eq_neg_of_add_eq_zero {a b : R} (h : a + b = 0) : a = -b := by
25 | symm
26 | apply neg_eq_of_add_eq_zero
27 | rw [add_comm, h]
28 |
29 | theorem neg_zero : (-0 : R) = 0 := by
30 | apply neg_eq_of_add_eq_zero
31 | rw [add_zero]
32 |
33 | theorem neg_neg (a : R) : - -a = a := by
34 | apply neg_eq_of_add_eq_zero
35 | rw [neg_add_cancel]
36 |
37 | end MyRing
38 |
39 | namespace MyRing
40 | variable {R : Type*} [Ring R]
41 |
42 | theorem self_sub (a : R) : a - a = 0 := by
43 | rw [sub_eq_add_neg, add_neg_cancel]
44 |
45 | theorem one_add_one_eq_two : 1 + 1 = (2 : R) := by
46 | norm_num
47 |
48 | theorem two_mul (a : R) : 2 * a = a + a := by
49 | rw [← one_add_one_eq_two, add_mul, one_mul]
50 |
51 | end MyRing
52 |
53 | section
54 | variable {G : Type*} [Group G]
55 |
56 | namespace MyGroup
57 |
58 | theorem mul_inv_cancel (a : G) : a * a⁻¹ = 1 := by
59 | have h : (a * a⁻¹)⁻¹ * (a * a⁻¹ * (a * a⁻¹)) = 1 := by
60 | rw [mul_assoc, ← mul_assoc a⁻¹ a, inv_mul_cancel, one_mul, inv_mul_cancel]
61 | rw [← h, ← mul_assoc, inv_mul_cancel, one_mul]
62 |
63 | theorem mul_one (a : G) : a * 1 = a := by
64 | rw [← inv_mul_cancel a, ← mul_assoc, mul_inv_cancel, one_mul]
65 |
66 | theorem mul_inv_rev (a b : G) : (a * b)⁻¹ = b⁻¹ * a⁻¹ := by
67 | rw [← one_mul (b⁻¹ * a⁻¹), ← inv_mul_cancel (a * b), mul_assoc, mul_assoc, ← mul_assoc b b⁻¹,
68 | mul_inv_cancel, one_mul, mul_inv_cancel, mul_one]
69 |
70 | end MyGroup
71 |
72 | end
73 |
74 |
--------------------------------------------------------------------------------
/MIL.lean:
--------------------------------------------------------------------------------
1 | import MIL.C01_Introduction.S01_Getting_Started
2 | import MIL.C01_Introduction.S02_Overview
3 | import MIL.C02_Basics.S01_Calculating
4 | import MIL.C02_Basics.S02_Proving_Identities_in_Algebraic_Structures
5 | import MIL.C02_Basics.S03_Using_Theorems_and_Lemmas
6 | import MIL.C02_Basics.S04_More_on_Order_and_Divisibility
7 | import MIL.C02_Basics.S05_Proving_Facts_about_Algebraic_Structures
8 | import MIL.C03_Logic.S01_Implication_and_the_Universal_Quantifier
9 | import MIL.C03_Logic.S02_The_Existential_Quantifier
10 | import MIL.C03_Logic.S03_Negation
11 | import MIL.C03_Logic.S04_Conjunction_and_Iff
12 | import MIL.C03_Logic.S05_Disjunction
13 | import MIL.C03_Logic.S06_Sequences_and_Convergence
14 | import MIL.C04_Sets_and_Functions.S01_Sets
15 | import MIL.C04_Sets_and_Functions.S02_Functions
16 | import MIL.C04_Sets_and_Functions.S03_The_Schroeder_Bernstein_Theorem
17 | import MIL.C05_Elementary_Number_Theory.S01_Irrational_Roots
18 | import MIL.C05_Elementary_Number_Theory.S02_Induction_and_Recursion
19 | import MIL.C05_Elementary_Number_Theory.S03_Infinitely_Many_Primes
20 | import MIL.C05_Elementary_Number_Theory.S04_More_Induction
21 | import MIL.C06_Discrete_Mathematics.S01_Finsets_and_Fintypes
22 | import MIL.C06_Discrete_Mathematics.S02_Counting_Arguments
23 | import MIL.C06_Discrete_Mathematics.S03_Inductive_Structures
24 | import MIL.C07_Structures.S01_Structures
25 | import MIL.C07_Structures.S02_Algebraic_Structures
26 | import MIL.C07_Structures.S03_Building_the_Gaussian_Integers
27 | import MIL.C08_Hierarchies.S01_Basics
28 | import MIL.C08_Hierarchies.S02_Morphisms
29 | import MIL.C08_Hierarchies.S03_Subobjects
30 | import MIL.C09_Groups_and_Rings.S01_Groups
31 | import MIL.C09_Groups_and_Rings.S02_Rings
32 | import MIL.C10_Linear_Algebra.S01_Vector_Spaces
33 | import MIL.C10_Linear_Algebra.S02_Subspaces
34 | import MIL.C10_Linear_Algebra.S03_Endomorphisms
35 | import MIL.C10_Linear_Algebra.S04_Bases
36 | import MIL.C11_Topology.S01_Filters
37 | import MIL.C11_Topology.S02_Metric_Spaces
38 | import MIL.C11_Topology.S03_Topological_Spaces
39 | import MIL.C12_Differential_Calculus.S01_Elementary_Differential_Calculus
40 | import MIL.C12_Differential_Calculus.S02_Differential_Calculus_in_Normed_Spaces
41 | import MIL.C13_Integration_and_Measure_Theory.S01_Elementary_Integration
42 | import MIL.C13_Integration_and_Measure_Theory.S02_Measure_Theory
43 | import MIL.C13_Integration_and_Measure_Theory.S03_Integration
44 | import MIL.Common
45 |
--------------------------------------------------------------------------------
/MIL/C03_Logic/solutions/Solutions_S03_Negation.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Data.Real.Basic
3 |
4 | namespace C03S03
5 |
6 | section
7 | variable (a b : ℝ)
8 |
9 | def FnUb (f : ℝ → ℝ) (a : ℝ) : Prop :=
10 | ∀ x, f x ≤ a
11 |
12 | def FnLb (f : ℝ → ℝ) (a : ℝ) : Prop :=
13 | ∀ x, a ≤ f x
14 |
15 | def FnHasUb (f : ℝ → ℝ) :=
16 | ∃ a, FnUb f a
17 |
18 | def FnHasLb (f : ℝ → ℝ) :=
19 | ∃ a, FnLb f a
20 |
21 | variable (f : ℝ → ℝ)
22 |
23 | example (h : ∀ a, ∃ x, f x < a) : ¬FnHasLb f := by
24 | rintro ⟨a, ha⟩
25 | rcases h a with ⟨x, hx⟩
26 | have := ha x
27 | linarith
28 |
29 | example : ¬FnHasUb fun x ↦ x := by
30 | rintro ⟨a, ha⟩
31 | have : a + 1 ≤ a := ha (a + 1)
32 | linarith
33 |
34 | example (h : Monotone f) (h' : f a < f b) : a < b := by
35 | apply lt_of_not_ge
36 | intro h''
37 | apply absurd h'
38 | apply not_lt_of_ge (h h'')
39 |
40 | example (h : a ≤ b) (h' : f b < f a) : ¬Monotone f := by
41 | intro h''
42 | apply absurd h'
43 | apply not_lt_of_ge
44 | apply h'' h
45 |
46 | example : ¬∀ {f : ℝ → ℝ}, Monotone f → ∀ {a b}, f a ≤ f b → a ≤ b := by
47 | intro h
48 | let f := fun x : ℝ ↦ (0 : ℝ)
49 | have monof : Monotone f := by
50 | intro a b leab
51 | rfl
52 | have h' : f 1 ≤ f 0 := le_refl _
53 | have : (1 : ℝ) ≤ 0 := h monof h'
54 | linarith
55 |
56 | example (x : ℝ) (h : ∀ ε > 0, x < ε) : x ≤ 0 := by
57 | apply le_of_not_gt
58 | intro h'
59 | linarith [h _ h']
60 |
61 | end
62 |
63 | section
64 | variable {α : Type*} (P : α → Prop) (Q : Prop)
65 |
66 | example (h : ¬∃ x, P x) : ∀ x, ¬P x := by
67 | intro x Px
68 | apply h
69 | use x
70 |
71 | example (h : ∀ x, ¬P x) : ¬∃ x, P x := by
72 | rintro ⟨x, Px⟩
73 | exact h x Px
74 |
75 | example (h : ∃ x, ¬P x) : ¬∀ x, P x := by
76 | intro h'
77 | rcases h with ⟨x, nPx⟩
78 | apply nPx
79 | apply h'
80 |
81 | example (h : ¬¬Q) : Q := by
82 | by_contra h'
83 | exact h h'
84 |
85 | example (h : Q) : ¬¬Q := by
86 | intro h'
87 | exact h' h
88 |
89 | end
90 |
91 | section
92 | variable (f : ℝ → ℝ)
93 |
94 | example (h : ¬FnHasUb f) : ∀ a, ∃ x, f x > a := by
95 | intro a
96 | by_contra h'
97 | apply h
98 | use a
99 | intro x
100 | apply le_of_not_gt
101 | intro h''
102 | apply h'
103 | use x
104 |
105 | example (h : ¬Monotone f) : ∃ x y, x ≤ y ∧ f y < f x := by
106 | rw [Monotone] at h
107 | push_neg at h
108 | exact h
109 |
110 | end
111 |
112 |
--------------------------------------------------------------------------------
/MIL/C05_Elementary_Number_Theory/solutions/Solutions_S02_Induction_and_Recursion.lean:
--------------------------------------------------------------------------------
1 | import Mathlib.Data.Nat.GCD.Basic
2 | import MIL.Common
3 |
4 | def fac : ℕ → ℕ
5 | | 0 => 1
6 | | n + 1 => (n + 1) * fac n
7 |
8 | theorem pow_two_le_fac (n : ℕ) : 2 ^ (n - 1) ≤ fac n := by
9 | rcases n with _ | n
10 | · simp [fac]
11 | induction' n with n ih
12 | · simp [fac]
13 | simp at *
14 | rw [pow_succ', fac]
15 | apply Nat.mul_le_mul _ ih
16 | repeat' apply Nat.succ_le_succ
17 | apply zero_le
18 |
19 | section
20 |
21 | variable {α : Type*} (s : Finset ℕ) (f : ℕ → ℕ) (n : ℕ)
22 |
23 | open BigOperators
24 | open Finset
25 |
26 | theorem sum_sqr (n : ℕ) : ∑ i ∈ range (n + 1), i ^ 2 = n * (n + 1) * (2 * n + 1) / 6 := by
27 | symm;
28 | apply Nat.div_eq_of_eq_mul_right (by norm_num : 0 < 6)
29 | induction' n with n ih
30 | · simp
31 | rw [Finset.sum_range_succ, mul_add 6, ← ih]
32 | ring
33 |
34 | end
35 |
36 | inductive MyNat where
37 | | zero : MyNat
38 | | succ : MyNat → MyNat
39 |
40 | namespace MyNat
41 |
42 | def add : MyNat → MyNat → MyNat
43 | | x, zero => x
44 | | x, succ y => succ (add x y)
45 |
46 | def mul : MyNat → MyNat → MyNat
47 | | x, zero => zero
48 | | x, succ y => add (mul x y) x
49 |
50 | theorem zero_add (n : MyNat) : add zero n = n := by
51 | induction' n with n ih
52 | · rfl
53 | rw [add, ih]
54 |
55 | theorem succ_add (m n : MyNat) : add (succ m) n = succ (add m n) := by
56 | induction' n with n ih
57 | · rfl
58 | rw [add, ih]
59 | rfl
60 |
61 | theorem add_comm (m n : MyNat) : add m n = add n m := by
62 | induction' n with n ih
63 | · rw [zero_add]
64 | rfl
65 | rw [add, succ_add, ih]
66 |
67 | theorem add_assoc (m n k : MyNat) : add (add m n) k = add m (add n k) := by
68 | induction' k with k ih
69 | · rfl
70 | rw [add, ih]
71 | rfl
72 |
73 | theorem mul_add (m n k : MyNat) : mul m (add n k) = add (mul m n) (mul m k) := by
74 | induction' k with k ih
75 | · rfl
76 | rw [add, mul, mul, ih, add_assoc]
77 |
78 | theorem zero_mul (n : MyNat) : mul zero n = zero := by
79 | induction' n with n ih
80 | · rfl
81 | rw [mul, ih]
82 | rfl
83 |
84 | theorem succ_mul (m n : MyNat) : mul (succ m) n = add (mul m n) n := by
85 | induction' n with n ih
86 | · rfl
87 | rw [mul, mul, ih, add_assoc, add_assoc, add_comm n, succ_add]
88 | rfl
89 |
90 | theorem mul_comm (m n : MyNat) : mul m n = mul n m := by
91 | induction' n with n ih
92 | · rw [zero_mul]
93 | rfl
94 | rw [mul, ih, succ_mul]
95 |
96 | end MyNat
97 |
--------------------------------------------------------------------------------
/MIL/C06_Discrete_Mathematics/solutions/Solutions_S02_Counting_Arguments.lean:
--------------------------------------------------------------------------------
1 | import Mathlib.Data.Fintype.BigOperators
2 | import Mathlib.Combinatorics.Pigeonhole
3 | import Mathlib.Tactic
4 |
5 | open Finset
6 |
7 | def triangle (n : ℕ) : Finset (ℕ × ℕ) := {p ∈ range (n+1) ×ˢ range (n+1) | p.1 < p.2}
8 |
9 | example (n : ℕ) : #(triangle n) = (n + 1) * n / 2 := by
10 | apply Nat.eq_div_of_mul_eq_right (by norm_num)
11 | let turn (p : ℕ × ℕ) : ℕ × ℕ := (n - 1 - p.1, n - p.2)
12 | calc 2 * #(triangle n)
13 | = #(triangle n) + #(triangle n) := by
14 | ring
15 | _ = #(triangle n) + #(triangle n |>.image turn) := by
16 | rw [Finset.card_image_of_injOn]
17 | rintro ⟨p1, p2⟩ hp ⟨q1, q2⟩ hq; simp [turn]
18 | simp_all [triangle]; omega
19 | _ = #(range n ×ˢ range (n + 1)) := by
20 | rw [←Finset.card_union_of_disjoint]; swap
21 | . rw [Finset.disjoint_iff_ne]
22 | rintro ⟨p1, p2⟩ hp ⟨q1, q2⟩ hq; simp [turn] at *
23 | simp_all [triangle]; omega
24 | congr; ext p; rcases p with ⟨p1, p2⟩
25 | simp [triangle, turn]
26 | constructor
27 | . rintro (h | h) <;> omega
28 | rcases Nat.lt_or_ge p1 p2 with h | h
29 | . omega
30 | . intro h'
31 | right
32 | use n - 1 - p1, n - p2
33 | omega
34 | _ = (n + 1) * n := by
35 | simp [mul_comm]
36 |
37 | def triangle' (n : ℕ) : Finset (ℕ × ℕ) := {p ∈ range n ×ˢ range n | p.1 ≤ p.2}
38 |
39 | example (n : ℕ) : #(triangle' n) = #(triangle n) := by
40 | let f (p : ℕ × ℕ) : ℕ × ℕ := (p.1, p.2 + 1)
41 | have : triangle n = (triangle' n |>.image f) := by
42 | ext p; rcases p with ⟨p1, p2⟩
43 | simp [triangle, triangle', f]
44 | constructor
45 | . intro h
46 | use p1, p2 - 1
47 | omega
48 | . simp; omega
49 | rw [this, card_image_of_injOn]
50 | rintro ⟨p1, p2⟩ hp ⟨q1, q2⟩ hq; simp [f] at *
51 |
52 | example {n : ℕ} (A : Finset ℕ)
53 | (hA : #(A) = n + 1)
54 | (hA' : A ⊆ range (2 * n)) :
55 | ∃ m ∈ A, ∃ k ∈ A, Nat.Coprime m k := by
56 | have : ∃ t ∈ range n, 1 < #({u ∈ A | u / 2 = t}) := by
57 | apply exists_lt_card_fiber_of_mul_lt_card_of_maps_to
58 | · intro u hu
59 | specialize hA' hu
60 | simp only [mem_range] at *
61 | exact Nat.div_lt_of_lt_mul hA'
62 | · simp [hA]
63 | rcases this with ⟨t, ht, ht'⟩
64 | simp only [one_lt_card, mem_filter] at ht'
65 | rcases ht' with ⟨m, ⟨hm, hm'⟩, k, ⟨hk, hk'⟩, hmk⟩
66 | have : m = k + 1 ∨ k = m + 1 := by omega
67 | rcases this with rfl | rfl
68 | . use k, hk, k+1, hm; simp
69 | . use m, hm, m+1, hk; simp
70 |
--------------------------------------------------------------------------------
/MIL/C04_Sets_and_Functions/solutions/Solutions_S03_The_Schroeder_Bernstein_Theorem.lean:
--------------------------------------------------------------------------------
1 | import Mathlib.Data.Set.Lattice
2 | import Mathlib.Data.Set.Function
3 | import MIL.Common
4 |
5 | open Set
6 | open Function
7 |
8 | noncomputable section
9 | open Classical
10 | variable {α β : Type*} [Nonempty β]
11 |
12 | section
13 | variable (f : α → β) (g : β → α)
14 |
15 | def sbAux : ℕ → Set α
16 | | 0 => univ \ g '' univ
17 | | n + 1 => g '' (f '' sbAux n)
18 |
19 | def sbSet :=
20 | ⋃ n, sbAux f g n
21 |
22 | def sbFun (x : α) : β :=
23 | if x ∈ sbSet f g then f x else invFun g x
24 |
25 | theorem sb_right_inv {x : α} (hx : x ∉ sbSet f g) : g (invFun g x) = x := by
26 | have : x ∈ g '' univ := by
27 | contrapose! hx
28 | rw [sbSet, mem_iUnion]
29 | use 0
30 | rw [sbAux, mem_diff]
31 | exact ⟨mem_univ _, hx⟩
32 | have : ∃ y, g y = x := by
33 | simp at this
34 | assumption
35 | exact invFun_eq this
36 |
37 | theorem sb_injective (hf : Injective f) : Injective (sbFun f g) := by
38 | set A := sbSet f g with A_def
39 | set h := sbFun f g with h_def
40 | intro x₁ x₂
41 | intro (hxeq : h x₁ = h x₂)
42 | show x₁ = x₂
43 | simp only [h_def, sbFun, ← A_def] at hxeq
44 | by_cases xA : x₁ ∈ A ∨ x₂ ∈ A
45 | · wlog x₁A : x₁ ∈ A generalizing x₁ x₂ hxeq xA
46 | · symm
47 | apply this hxeq.symm xA.symm (xA.resolve_left x₁A)
48 | have x₂A : x₂ ∈ A := by
49 | apply _root_.not_imp_self.mp
50 | intro (x₂nA : x₂ ∉ A)
51 | rw [if_pos x₁A, if_neg x₂nA] at hxeq
52 | rw [A_def, sbSet, mem_iUnion] at x₁A
53 | have x₂eq : x₂ = g (f x₁) := by
54 | rw [hxeq, sb_right_inv f g x₂nA]
55 | rcases x₁A with ⟨n, hn⟩
56 | rw [A_def, sbSet, mem_iUnion]
57 | use n + 1
58 | simp [sbAux]
59 | exact ⟨x₁, hn, x₂eq.symm⟩
60 | rw [if_pos x₁A, if_pos x₂A] at hxeq
61 | exact hf hxeq
62 | push_neg at xA
63 | rw [if_neg xA.1, if_neg xA.2] at hxeq
64 | rw [← sb_right_inv f g xA.1, hxeq, sb_right_inv f g xA.2]
65 |
66 | theorem sb_surjective (hg : Injective g) : Surjective (sbFun f g) := by
67 | set A := sbSet f g with A_def
68 | set h := sbFun f g with h_def
69 | intro y
70 | by_cases gyA : g y ∈ A
71 | · rw [A_def, sbSet, mem_iUnion] at gyA
72 | rcases gyA with ⟨n, hn⟩
73 | rcases n with _ | n
74 | · simp [sbAux] at hn
75 | simp [sbAux] at hn
76 | rcases hn with ⟨x, xmem, hx⟩
77 | use x
78 | have : x ∈ A := by
79 | rw [A_def, sbSet, mem_iUnion]
80 | exact ⟨n, xmem⟩
81 | rw [h_def, sbFun, if_pos this]
82 | apply hg hx
83 |
84 | use g y
85 | rw [h_def, sbFun, if_neg gyA]
86 | apply leftInverse_invFun hg
87 |
88 | end
89 |
90 |
--------------------------------------------------------------------------------
/MIL/C13_Integration_and_Measure_Theory/S03_Integration.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Analysis.Normed.Module.FiniteDimension
3 | import Mathlib.Analysis.Convolution
4 | import Mathlib.MeasureTheory.Function.Jacobian
5 | import Mathlib.MeasureTheory.Integral.Bochner.Basic
6 | import Mathlib.MeasureTheory.Measure.Lebesgue.Basic
7 |
8 | open Set Filter
9 |
10 | open Topology Filter ENNReal
11 |
12 | open MeasureTheory
13 |
14 | noncomputable section
15 | variable {α : Type*} [MeasurableSpace α]
16 | variable {μ : Measure α}
17 |
18 | section
19 | variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {f : α → E}
20 |
21 | example {f g : α → E} (hf : Integrable f μ) (hg : Integrable g μ) :
22 | ∫ a, f a + g a ∂μ = ∫ a, f a ∂μ + ∫ a, g a ∂μ :=
23 | integral_add hf hg
24 |
25 | example {s : Set α} (c : E) : ∫ x in s, c ∂μ = (μ s).toReal • c :=
26 | setIntegral_const c
27 |
28 | open Filter
29 |
30 | example {F : ℕ → α → E} {f : α → E} (bound : α → ℝ) (hmeas : ∀ n, AEStronglyMeasurable (F n) μ)
31 | (hint : Integrable bound μ) (hbound : ∀ n, ∀ᵐ a ∂μ, ‖F n a‖ ≤ bound a)
32 | (hlim : ∀ᵐ a ∂μ, Tendsto (fun n : ℕ ↦ F n a) atTop (𝓝 (f a))) :
33 | Tendsto (fun n ↦ ∫ a, F n a ∂μ) atTop (𝓝 (∫ a, f a ∂μ)) :=
34 | tendsto_integral_of_dominated_convergence bound hmeas hint hbound hlim
35 |
36 | example {α : Type*} [MeasurableSpace α] {μ : Measure α} [SigmaFinite μ] {β : Type*}
37 | [MeasurableSpace β] {ν : Measure β} [SigmaFinite ν] (f : α × β → E)
38 | (hf : Integrable f (μ.prod ν)) : ∫ z, f z ∂ μ.prod ν = ∫ x, ∫ y, f (x, y) ∂ν ∂μ :=
39 | integral_prod f hf
40 |
41 | end
42 |
43 | section
44 |
45 | open Convolution
46 |
47 | variable {𝕜 : Type*} {G : Type*} {E : Type*} {E' : Type*} {F : Type*} [NormedAddCommGroup E]
48 | [NormedAddCommGroup E'] [NormedAddCommGroup F] [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E]
49 | [NormedSpace 𝕜 E'] [NormedSpace 𝕜 F] [MeasurableSpace G] [NormedSpace ℝ F] [CompleteSpace F]
50 | [Sub G]
51 |
52 | example (f : G → E) (g : G → E') (L : E →L[𝕜] E' →L[𝕜] F) (μ : Measure G) :
53 | f ⋆[L, μ] g = fun x ↦ ∫ t, L (f t) (g (x - t)) ∂μ :=
54 | rfl
55 |
56 | end
57 |
58 | example {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E]
59 | [MeasurableSpace E] [BorelSpace E] (μ : Measure E) [μ.IsAddHaarMeasure] {F : Type*}
60 | [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] {s : Set E} {f : E → E}
61 | {f' : E → E →L[ℝ] E} (hs : MeasurableSet s)
62 | (hf : ∀ x : E, x ∈ s → HasFDerivWithinAt f (f' x) s x) (h_inj : InjOn f s) (g : E → F) :
63 | ∫ x in f '' s, g x ∂μ = ∫ x in s, |(f' x).det| • g (f x) ∂μ :=
64 | integral_image_eq_integral_abs_det_fderiv_smul μ hs hf h_inj g
65 |
--------------------------------------------------------------------------------
/MIL/C04_Sets_and_Functions/S03_The_Schroeder_Bernstein_Theorem.lean:
--------------------------------------------------------------------------------
1 | import Mathlib.Data.Set.Lattice
2 | import Mathlib.Data.Set.Function
3 | import MIL.Common
4 |
5 | open Set
6 | open Function
7 |
8 | noncomputable section
9 | open Classical
10 | variable {α β : Type*} [Nonempty β]
11 |
12 | section
13 | variable (f : α → β) (g : β → α)
14 |
15 | def sbAux : ℕ → Set α
16 | | 0 => univ \ g '' univ
17 | | n + 1 => g '' (f '' sbAux n)
18 |
19 | def sbSet :=
20 | ⋃ n, sbAux f g n
21 |
22 | def sbFun (x : α) : β :=
23 | if x ∈ sbSet f g then f x else invFun g x
24 |
25 | theorem sb_right_inv {x : α} (hx : x ∉ sbSet f g) : g (invFun g x) = x := by
26 | have : x ∈ g '' univ := by
27 | contrapose! hx
28 | rw [sbSet, mem_iUnion]
29 | use 0
30 | rw [sbAux, mem_diff]
31 | sorry
32 | have : ∃ y, g y = x := by
33 | sorry
34 | sorry
35 |
36 | theorem sb_injective (hf : Injective f) : Injective (sbFun f g) := by
37 | set A := sbSet f g with A_def
38 | set h := sbFun f g with h_def
39 | intro x₁ x₂
40 | intro (hxeq : h x₁ = h x₂)
41 | show x₁ = x₂
42 | simp only [h_def, sbFun, ← A_def] at hxeq
43 | by_cases xA : x₁ ∈ A ∨ x₂ ∈ A
44 | · wlog x₁A : x₁ ∈ A generalizing x₁ x₂ hxeq xA
45 | · symm
46 | apply this hxeq.symm xA.symm (xA.resolve_left x₁A)
47 | have x₂A : x₂ ∈ A := by
48 | apply _root_.not_imp_self.mp
49 | intro (x₂nA : x₂ ∉ A)
50 | rw [if_pos x₁A, if_neg x₂nA] at hxeq
51 | rw [A_def, sbSet, mem_iUnion] at x₁A
52 | have x₂eq : x₂ = g (f x₁) := by
53 | sorry
54 | rcases x₁A with ⟨n, hn⟩
55 | rw [A_def, sbSet, mem_iUnion]
56 | use n + 1
57 | simp [sbAux]
58 | exact ⟨x₁, hn, x₂eq.symm⟩
59 | sorry
60 | push_neg at xA
61 | sorry
62 |
63 | theorem sb_surjective (hg : Injective g) : Surjective (sbFun f g) := by
64 | set A := sbSet f g with A_def
65 | set h := sbFun f g with h_def
66 | intro y
67 | by_cases gyA : g y ∈ A
68 | · rw [A_def, sbSet, mem_iUnion] at gyA
69 | rcases gyA with ⟨n, hn⟩
70 | rcases n with _ | n
71 | · simp [sbAux] at hn
72 | simp [sbAux] at hn
73 | rcases hn with ⟨x, xmem, hx⟩
74 | use x
75 | have : x ∈ A := by
76 | rw [A_def, sbSet, mem_iUnion]
77 | exact ⟨n, xmem⟩
78 | rw [h_def, sbFun, if_pos this]
79 | apply hg hx
80 |
81 | sorry
82 |
83 | end
84 |
85 | theorem schroeder_bernstein {f : α → β} {g : β → α} (hf : Injective f) (hg : Injective g) :
86 | ∃ h : α → β, Bijective h :=
87 | ⟨sbFun f g, sb_injective f g hf, sb_surjective f g hg⟩
88 |
89 | -- Auxiliary information
90 | section
91 | variable (g : β → α) (x : α)
92 |
93 | #check (invFun g : α → β)
94 | #check (leftInverse_invFun : Injective g → LeftInverse (invFun g) g)
95 | #check (leftInverse_invFun : Injective g → ∀ y, invFun g (g y) = y)
96 | #check (invFun_eq : (∃ y, g y = x) → g (invFun g x) = x)
97 |
98 | end
99 |
--------------------------------------------------------------------------------
/MIL/C11_Topology/solutions/Solutions_S01_Filters.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Topology.Instances.Real.Lemmas
3 |
4 | open Set Filter Topology
5 |
6 | -- In the next example we could use `tauto` in each proof instead of knowing the lemmas
7 | example {α : Type*} (s : Set α) : Filter α :=
8 | { sets := { t | s ⊆ t }
9 | univ_sets := subset_univ s
10 | sets_of_superset := fun hU hUV ↦ Subset.trans hU hUV
11 | inter_sets := fun hU hV ↦ subset_inter hU hV }
12 |
13 | example : Filter ℕ :=
14 | { sets := { s | ∃ a, ∀ b, a ≤ b → b ∈ s }
15 | univ_sets := by
16 | use 42
17 | simp
18 | sets_of_superset := by
19 | rintro U V ⟨N, hN⟩ hUV
20 | use N
21 | tauto
22 | inter_sets := by
23 | rintro U V ⟨N, hN⟩ ⟨N', hN'⟩
24 | use max N N'
25 | intro b hb
26 | rw [max_le_iff] at hb
27 | constructor <;> tauto }
28 |
29 | def Tendsto₁ {X Y : Type*} (f : X → Y) (F : Filter X) (G : Filter Y) :=
30 | ∀ V ∈ G, f ⁻¹' V ∈ F
31 |
32 | example {X Y Z : Type*} {F : Filter X} {G : Filter Y} {H : Filter Z} {f : X → Y} {g : Y → Z}
33 | (hf : Tendsto₁ f F G) (hg : Tendsto₁ g G H) : Tendsto₁ (g ∘ f) F H :=
34 | calc
35 | map (g ∘ f) F = map g (map f F) := by rw [map_map]
36 | _ ≤ map g G := (map_mono hf)
37 | _ ≤ H := hg
38 |
39 |
40 | example {X Y Z : Type*} {F : Filter X} {G : Filter Y} {H : Filter Z} {f : X → Y} {g : Y → Z}
41 | (hf : Tendsto₁ f F G) (hg : Tendsto₁ g G H) : Tendsto₁ (g ∘ f) F H := by
42 | intro V hV
43 | rw [preimage_comp]
44 | apply hf
45 | apply hg
46 | exact hV
47 |
48 | example (f : ℕ → ℝ × ℝ) (x₀ y₀ : ℝ) :
49 | Tendsto f atTop (𝓝 (x₀, y₀)) ↔
50 | Tendsto (Prod.fst ∘ f) atTop (𝓝 x₀) ∧ Tendsto (Prod.snd ∘ f) atTop (𝓝 y₀) :=
51 | calc
52 | Tendsto f atTop (𝓝 (x₀, y₀)) ↔ map f atTop ≤ 𝓝 (x₀, y₀) := Iff.rfl
53 | _ ↔ map f atTop ≤ 𝓝 x₀ ×ˢ 𝓝 y₀ := by rw [nhds_prod_eq]
54 | _ ↔ map f atTop ≤ comap Prod.fst (𝓝 x₀) ⊓ comap Prod.snd (𝓝 y₀) := Iff.rfl
55 | _ ↔ map f atTop ≤ comap Prod.fst (𝓝 x₀) ∧ map f atTop ≤ comap Prod.snd (𝓝 y₀) := le_inf_iff
56 | _ ↔ map Prod.fst (map f atTop) ≤ 𝓝 x₀ ∧ map Prod.snd (map f atTop) ≤ 𝓝 y₀ := by
57 | rw [← map_le_iff_le_comap, ← map_le_iff_le_comap]
58 | _ ↔ map (Prod.fst ∘ f) atTop ≤ 𝓝 x₀ ∧ map (Prod.snd ∘ f) atTop ≤ 𝓝 y₀ := by
59 | rw [map_map, map_map]
60 |
61 |
62 | -- an alternative solution
63 | example (f : ℕ → ℝ × ℝ) (x₀ y₀ : ℝ) :
64 | Tendsto f atTop (𝓝 (x₀, y₀)) ↔
65 | Tendsto (Prod.fst ∘ f) atTop (𝓝 x₀) ∧ Tendsto (Prod.snd ∘ f) atTop (𝓝 y₀) := by
66 | rw [nhds_prod_eq]
67 | unfold Tendsto SProd.sprod Filter.instSProd
68 | rw [le_inf_iff, ← map_le_iff_le_comap, map_map, ← map_le_iff_le_comap, map_map]
69 |
70 | example (u : ℕ → ℝ) (M : Set ℝ) (x : ℝ) (hux : Tendsto u atTop (𝓝 x))
71 | (huM : ∀ᶠ n in atTop, u n ∈ M) : x ∈ closure M :=
72 | mem_closure_iff_clusterPt.mpr (neBot_of_le <| le_inf hux <| le_principal_iff.mpr huM)
73 |
--------------------------------------------------------------------------------
/MIL/C02_Basics/S05_Proving_Facts_about_Algebraic_Structures.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Topology.MetricSpace.Basic
3 |
4 | section
5 | variable {α : Type*} [PartialOrder α]
6 | variable (x y z : α)
7 |
8 | #check x ≤ y
9 | #check (le_refl x : x ≤ x)
10 | #check (le_trans : x ≤ y → y ≤ z → x ≤ z)
11 | #check (le_antisymm : x ≤ y → y ≤ x → x = y)
12 |
13 |
14 | #check x < y
15 | #check (lt_irrefl x : ¬ (x < x))
16 | #check (lt_trans : x < y → y < z → x < z)
17 | #check (lt_of_le_of_lt : x ≤ y → y < z → x < z)
18 | #check (lt_of_lt_of_le : x < y → y ≤ z → x < z)
19 |
20 | example : x < y ↔ x ≤ y ∧ x ≠ y :=
21 | lt_iff_le_and_ne
22 |
23 | end
24 |
25 | section
26 | variable {α : Type*} [Lattice α]
27 | variable (x y z : α)
28 |
29 | #check x ⊓ y
30 | #check (inf_le_left : x ⊓ y ≤ x)
31 | #check (inf_le_right : x ⊓ y ≤ y)
32 | #check (le_inf : z ≤ x → z ≤ y → z ≤ x ⊓ y)
33 | #check x ⊔ y
34 | #check (le_sup_left : x ≤ x ⊔ y)
35 | #check (le_sup_right : y ≤ x ⊔ y)
36 | #check (sup_le : x ≤ z → y ≤ z → x ⊔ y ≤ z)
37 |
38 | example : x ⊓ y = y ⊓ x := by
39 | sorry
40 |
41 | example : x ⊓ y ⊓ z = x ⊓ (y ⊓ z) := by
42 | sorry
43 |
44 | example : x ⊔ y = y ⊔ x := by
45 | sorry
46 |
47 | example : x ⊔ y ⊔ z = x ⊔ (y ⊔ z) := by
48 | sorry
49 |
50 | theorem absorb1 : x ⊓ (x ⊔ y) = x := by
51 | sorry
52 |
53 | theorem absorb2 : x ⊔ x ⊓ y = x := by
54 | sorry
55 |
56 | end
57 |
58 | section
59 | variable {α : Type*} [DistribLattice α]
60 | variable (x y z : α)
61 |
62 | #check (inf_sup_left x y z : x ⊓ (y ⊔ z) = x ⊓ y ⊔ x ⊓ z)
63 | #check (inf_sup_right x y z : (x ⊔ y) ⊓ z = x ⊓ z ⊔ y ⊓ z)
64 | #check (sup_inf_left x y z : x ⊔ y ⊓ z = (x ⊔ y) ⊓ (x ⊔ z))
65 | #check (sup_inf_right x y z : x ⊓ y ⊔ z = (x ⊔ z) ⊓ (y ⊔ z))
66 | end
67 |
68 | section
69 | variable {α : Type*} [Lattice α]
70 | variable (a b c : α)
71 |
72 | example (h : ∀ x y z : α, x ⊓ (y ⊔ z) = x ⊓ y ⊔ x ⊓ z) : a ⊔ b ⊓ c = (a ⊔ b) ⊓ (a ⊔ c) := by
73 | sorry
74 |
75 | example (h : ∀ x y z : α, x ⊔ y ⊓ z = (x ⊔ y) ⊓ (x ⊔ z)) : a ⊓ (b ⊔ c) = a ⊓ b ⊔ a ⊓ c := by
76 | sorry
77 |
78 | end
79 |
80 | section
81 | variable {R : Type*} [Ring R] [PartialOrder R] [IsStrictOrderedRing R]
82 | variable (a b c : R)
83 |
84 | #check (add_le_add_left : a ≤ b → ∀ c, c + a ≤ c + b)
85 | #check (mul_pos : 0 < a → 0 < b → 0 < a * b)
86 |
87 | #check (mul_nonneg : 0 ≤ a → 0 ≤ b → 0 ≤ a * b)
88 |
89 | example (h : a ≤ b) : 0 ≤ b - a := by
90 | sorry
91 |
92 | example (h: 0 ≤ b - a) : a ≤ b := by
93 | sorry
94 |
95 | example (h : a ≤ b) (h' : 0 ≤ c) : a * c ≤ b * c := by
96 | sorry
97 |
98 | end
99 |
100 | section
101 | variable {X : Type*} [MetricSpace X]
102 | variable (x y z : X)
103 |
104 | #check (dist_self x : dist x x = 0)
105 | #check (dist_comm x y : dist x y = dist y x)
106 | #check (dist_triangle x y z : dist x z ≤ dist x y + dist y z)
107 |
108 | example (x y : X) : 0 ≤ dist x y := by
109 | sorry
110 |
111 | end
112 |
113 |
--------------------------------------------------------------------------------
/MIL/C12_Differential_Calculus/solutions/Solutions_S02_Differential_Calculus_in_Normed_Spaces.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Analysis.Normed.Operator.BanachSteinhaus
3 | import Mathlib.Analysis.Normed.Module.FiniteDimension
4 | import Mathlib.Analysis.Calculus.InverseFunctionTheorem.FDeriv
5 | import Mathlib.Analysis.Calculus.ContDiff.RCLike
6 | import Mathlib.Analysis.Calculus.FDeriv.Prod
7 |
8 |
9 | open Set Filter
10 |
11 | open Topology Filter
12 |
13 | noncomputable section
14 |
15 | section
16 |
17 | variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E]
18 | [NormedSpace 𝕜 E] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
19 |
20 | open Metric
21 |
22 | example {ι : Type*} [CompleteSpace E] {g : ι → E →L[𝕜] F} (h : ∀ x, ∃ C, ∀ i, ‖g i x‖ ≤ C) :
23 | ∃ C', ∀ i, ‖g i‖ ≤ C' := by
24 | -- sequence of subsets consisting of those `x : E` with norms `‖g i x‖` bounded by `n`
25 | let e : ℕ → Set E := fun n ↦ ⋂ i : ι, { x : E | ‖g i x‖ ≤ n }
26 | -- each of these sets is closed
27 | have hc : ∀ n : ℕ, IsClosed (e n) := fun i ↦
28 | isClosed_iInter fun i ↦ isClosed_le (g i).cont.norm continuous_const
29 | -- the union is the entire space; this is where we use `h`
30 | have hU : (⋃ n : ℕ, e n) = univ := by
31 | refine eq_univ_of_forall fun x ↦ ?_
32 | rcases h x with ⟨C, hC⟩
33 | obtain ⟨m, hm⟩ := exists_nat_ge C
34 | exact ⟨e m, mem_range_self m, mem_iInter.mpr fun i ↦ le_trans (hC i) hm⟩
35 | /- apply the Baire category theorem to conclude that for some `m : ℕ`,
36 | `e m` contains some `x` -/
37 | obtain ⟨m : ℕ, x : E, hx : x ∈ interior (e m)⟩ := nonempty_interior_of_iUnion_of_closed hc hU
38 | obtain ⟨ε, ε_pos, hε : ball x ε ⊆ interior (e m)⟩ := isOpen_iff.mp isOpen_interior x hx
39 | obtain ⟨k : 𝕜, hk : 1 < ‖k‖⟩ := NormedField.exists_one_lt_norm 𝕜
40 | -- show all elements in the ball have norm bounded by `m` after applying any `g i`
41 | have real_norm_le : ∀ z ∈ ball x ε, ∀ (i : ι), ‖g i z‖ ≤ m := by
42 | intro z hz i
43 | replace hz := mem_iInter.mp (interior_iInter_subset _ (hε hz)) i
44 | apply interior_subset hz
45 | have εk_pos : 0 < ε / ‖k‖ := div_pos ε_pos (zero_lt_one.trans hk)
46 | refine ⟨(m + m : ℕ) / (ε / ‖k‖), fun i ↦ ContinuousLinearMap.opNorm_le_of_shell ε_pos ?_ hk ?_⟩
47 | · exact div_nonneg (Nat.cast_nonneg _) εk_pos.le
48 | intro y le_y y_lt
49 | calc
50 | ‖g i y‖ = ‖g i (y + x) - g i x‖ := by rw [(g i).map_add, add_sub_cancel_right]
51 | _ ≤ ‖g i (y + x)‖ + ‖g i x‖ := (norm_sub_le _ _)
52 | _ ≤ m + m :=
53 | (add_le_add (real_norm_le (y + x) (by rwa [add_comm, add_mem_ball_iff_norm]) i)
54 | (real_norm_le x (mem_ball_self ε_pos) i))
55 | _ = (m + m : ℕ) := by norm_cast
56 | _ ≤ (m + m : ℕ) * (‖y‖ / (ε / ‖k‖)) :=
57 | (le_mul_of_one_le_right (Nat.cast_nonneg _)
58 | ((one_le_div <| div_pos ε_pos (zero_lt_one.trans hk)).2 le_y))
59 | _ = (m + m : ℕ) / (ε / ‖k‖) * ‖y‖ := (mul_comm_div _ _ _).symm
60 |
61 |
62 | end
63 |
64 |
--------------------------------------------------------------------------------
/MIL/C08_Hierarchies/S03_Subobjects.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.GroupTheory.QuotientGroup.Basic
3 |
4 | set_option autoImplicit true
5 |
6 |
7 | @[ext]
8 | structure Submonoid₁ (M : Type) [Monoid M] where
9 | /-- The carrier of a submonoid. -/
10 | carrier : Set M
11 | /-- The product of two elements of a submonoid belongs to the submonoid. -/
12 | mul_mem {a b} : a ∈ carrier → b ∈ carrier → a * b ∈ carrier
13 | /-- The unit element belongs to the submonoid. -/
14 | one_mem : 1 ∈ carrier
15 |
16 | /-- Submonoids in `M` can be seen as sets in `M`. -/
17 | instance [Monoid M] : SetLike (Submonoid₁ M) M where
18 | coe := Submonoid₁.carrier
19 | coe_injective' _ _ := Submonoid₁.ext
20 |
21 |
22 |
23 | example [Monoid M] (N : Submonoid₁ M) : 1 ∈ N := N.one_mem
24 |
25 | example [Monoid M] (N : Submonoid₁ M) (α : Type) (f : M → α) := f '' N
26 |
27 |
28 | example [Monoid M] (N : Submonoid₁ M) (x : N) : (x : M) ∈ N := x.property
29 |
30 |
31 | instance SubMonoid₁Monoid [Monoid M] (N : Submonoid₁ M) : Monoid N where
32 | mul := fun x y ↦ ⟨x*y, N.mul_mem x.property y.property⟩
33 | mul_assoc := fun x y z ↦ SetCoe.ext (mul_assoc (x : M) y z)
34 | one := ⟨1, N.one_mem⟩
35 | one_mul := fun x ↦ SetCoe.ext (one_mul (x : M))
36 | mul_one := fun x ↦ SetCoe.ext (mul_one (x : M))
37 |
38 |
39 | example [Monoid M] (N : Submonoid₁ M) : Monoid N where
40 | mul := fun ⟨x, hx⟩ ⟨y, hy⟩ ↦ ⟨x*y, N.mul_mem hx hy⟩
41 | mul_assoc := fun ⟨x, _⟩ ⟨y, _⟩ ⟨z, _⟩ ↦ SetCoe.ext (mul_assoc x y z)
42 | one := ⟨1, N.one_mem⟩
43 | one_mul := fun ⟨x, _⟩ ↦ SetCoe.ext (one_mul x)
44 | mul_one := fun ⟨x, _⟩ ↦ SetCoe.ext (mul_one x)
45 |
46 |
47 | class SubmonoidClass₁ (S : Type) (M : Type) [Monoid M] [SetLike S M] : Prop where
48 | mul_mem : ∀ (s : S) {a b : M}, a ∈ s → b ∈ s → a * b ∈ s
49 | one_mem : ∀ s : S, 1 ∈ s
50 |
51 | instance [Monoid M] : SubmonoidClass₁ (Submonoid₁ M) M where
52 | mul_mem := Submonoid₁.mul_mem
53 | one_mem := Submonoid₁.one_mem
54 |
55 |
56 | instance [Monoid M] : Min (Submonoid₁ M) :=
57 | ⟨fun S₁ S₂ ↦
58 | { carrier := S₁ ∩ S₂
59 | one_mem := ⟨S₁.one_mem, S₂.one_mem⟩
60 | mul_mem := fun ⟨hx, hx'⟩ ⟨hy, hy'⟩ ↦ ⟨S₁.mul_mem hx hy, S₂.mul_mem hx' hy'⟩ }⟩
61 |
62 |
63 | example [Monoid M] (N P : Submonoid₁ M) : Submonoid₁ M := N ⊓ P
64 |
65 |
66 | def Submonoid.Setoid [CommMonoid M] (N : Submonoid M) : Setoid M where
67 | r := fun x y ↦ ∃ w ∈ N, ∃ z ∈ N, x*w = y*z
68 | iseqv := {
69 | refl := fun x ↦ ⟨1, N.one_mem, 1, N.one_mem, rfl⟩
70 | symm := fun ⟨w, hw, z, hz, h⟩ ↦ ⟨z, hz, w, hw, h.symm⟩
71 | trans := by
72 | sorry
73 | }
74 |
75 | instance [CommMonoid M] : HasQuotient M (Submonoid M) where
76 | quotient' := fun N ↦ Quotient N.Setoid
77 |
78 | def QuotientMonoid.mk [CommMonoid M] (N : Submonoid M) : M → M ⧸ N := Quotient.mk N.Setoid
79 |
80 | instance [CommMonoid M] (N : Submonoid M) : Monoid (M ⧸ N) where
81 | mul := Quotient.map₂ (· * ·) (by
82 | sorry
83 | )
84 | mul_assoc := by
85 | sorry
86 | one := QuotientMonoid.mk N 1
87 | one_mul := by
88 | sorry
89 | mul_one := by
90 | sorry
91 |
--------------------------------------------------------------------------------
/MIL/C02_Basics/solutions/Solutions_S04_More_on_Order_and_Divisibility.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Data.Real.Basic
3 |
4 | namespace C02S04
5 |
6 | section
7 | variable (a b c d : ℝ)
8 |
9 | #check (min_le_left a b : min a b ≤ a)
10 | #check (min_le_right a b : min a b ≤ b)
11 | #check (le_min : c ≤ a → c ≤ b → c ≤ min a b)
12 |
13 | example : max a b = max b a := by
14 | apply le_antisymm
15 | repeat
16 | apply max_le
17 | apply le_max_right
18 | apply le_max_left
19 |
20 | example : min (min a b) c = min a (min b c) := by
21 | apply le_antisymm
22 | · apply le_min
23 | · apply le_trans
24 | apply min_le_left
25 | apply min_le_left
26 | apply le_min
27 | · apply le_trans
28 | apply min_le_left
29 | apply min_le_right
30 | apply min_le_right
31 | apply le_min
32 | · apply le_min
33 | · apply min_le_left
34 | apply le_trans
35 | apply min_le_right
36 | apply min_le_left
37 | apply le_trans
38 | apply min_le_right
39 | apply min_le_right
40 |
41 | theorem aux : min a b + c ≤ min (a + c) (b + c) := by
42 | apply le_min
43 | · apply add_le_add_right
44 | apply min_le_left
45 | apply add_le_add_right
46 | apply min_le_right
47 |
48 | example : min a b + c = min (a + c) (b + c) := by
49 | apply le_antisymm
50 | · apply aux
51 | have h : min (a + c) (b + c) = min (a + c) (b + c) - c + c := by rw [sub_add_cancel]
52 | rw [h]
53 | apply add_le_add_right
54 | rw [sub_eq_add_neg]
55 | apply le_trans
56 | apply aux
57 | rw [add_neg_cancel_right, add_neg_cancel_right]
58 |
59 | example : |a| - |b| ≤ |a - b| :=
60 | calc
61 | |a| - |b| = |a - b + b| - |b| := by rw [sub_add_cancel]
62 | _ ≤ |a - b| + |b| - |b| := by
63 | apply sub_le_sub_right
64 | apply abs_add
65 | _ ≤ |a - b| := by rw [add_sub_cancel_right]
66 |
67 |
68 | -- alternatively
69 | example : |a| - |b| ≤ |a - b| := by
70 | have h := abs_add (a - b) b
71 | rw [sub_add_cancel] at h
72 | linarith
73 |
74 | end
75 |
76 | section
77 | variable (w x y z : ℕ)
78 |
79 | example (h₀ : x ∣ y) (h₁ : y ∣ z) : x ∣ z :=
80 | dvd_trans h₀ h₁
81 |
82 | example : x ∣ y * x * z := by
83 | apply dvd_mul_of_dvd_left
84 | apply dvd_mul_left
85 |
86 | example : x ∣ x ^ 2 := by
87 | apply dvd_mul_left
88 |
89 | example (h : x ∣ w) : x ∣ y * (x * z) + x ^ 2 + w ^ 2 := by
90 | apply dvd_add
91 | · apply dvd_add
92 | · apply dvd_mul_of_dvd_right
93 | apply dvd_mul_right
94 | apply dvd_mul_left
95 | rw [pow_two]
96 | apply dvd_mul_of_dvd_right
97 | exact h
98 |
99 | end
100 |
101 | section
102 | variable (m n : ℕ)
103 |
104 | #check (Nat.gcd_zero_right n : Nat.gcd n 0 = n)
105 | #check (Nat.gcd_zero_left n : Nat.gcd 0 n = n)
106 | #check (Nat.lcm_zero_right n : Nat.lcm n 0 = 0)
107 | #check (Nat.lcm_zero_left n : Nat.lcm 0 n = 0)
108 |
109 | example : Nat.gcd m n = Nat.gcd n m := by
110 | apply Nat.dvd_antisymm
111 | repeat
112 | apply Nat.dvd_gcd
113 | apply Nat.gcd_dvd_right
114 | apply Nat.gcd_dvd_left
115 |
116 | end
117 |
118 |
--------------------------------------------------------------------------------
/MIL/C07_Structures/solutions/Solutions_S01_Structures.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Algebra.BigOperators.Ring.List
3 | import Mathlib.Data.Real.Basic
4 |
5 | namespace C06S01
6 | noncomputable section
7 |
8 | @[ext]
9 | structure Point where
10 | x : ℝ
11 | y : ℝ
12 | z : ℝ
13 |
14 | namespace Point
15 |
16 | def add (a b : Point) : Point :=
17 | ⟨a.x + b.x, a.y + b.y, a.z + b.z⟩
18 |
19 | protected theorem add_assoc (a b c : Point) : (a.add b).add c = a.add (b.add c) := by
20 | simp [add, add_assoc]
21 |
22 | def smul (r : ℝ) (a : Point) : Point :=
23 | ⟨r * a.x, r * a.y, r * a.z⟩
24 |
25 | theorem smul_distrib (r : ℝ) (a b : Point) :
26 | (smul r a).add (smul r b) = smul r (a.add b) := by
27 | simp [add, smul, mul_add]
28 |
29 | end Point
30 |
31 | structure StandardTwoSimplex where
32 | x : ℝ
33 | y : ℝ
34 | z : ℝ
35 | x_nonneg : 0 ≤ x
36 | y_nonneg : 0 ≤ y
37 | z_nonneg : 0 ≤ z
38 | sum_eq : x + y + z = 1
39 |
40 | namespace StandardTwoSimplex
41 |
42 | noncomputable section
43 |
44 | def weightedAverage (lambda : Real) (lambda_nonneg : 0 ≤ lambda) (lambda_le : lambda ≤ 1)
45 | (a b : StandardTwoSimplex) : StandardTwoSimplex
46 | where
47 | x := lambda * a.x + (1 - lambda) * b.x
48 | y := lambda * a.y + (1 - lambda) * b.y
49 | z := lambda * a.z + (1 - lambda) * b.z
50 | x_nonneg := add_nonneg (mul_nonneg lambda_nonneg a.x_nonneg) (mul_nonneg (by linarith) b.x_nonneg)
51 | y_nonneg := add_nonneg (mul_nonneg lambda_nonneg a.y_nonneg) (mul_nonneg (by linarith) b.y_nonneg)
52 | z_nonneg := add_nonneg (mul_nonneg lambda_nonneg a.z_nonneg) (mul_nonneg (by linarith) b.z_nonneg)
53 | sum_eq := by
54 | trans (a.x + a.y + a.z) * lambda + (b.x + b.y + b.z) * (1 - lambda)
55 | · ring
56 | simp [a.sum_eq, b.sum_eq]
57 |
58 | end
59 |
60 | end StandardTwoSimplex
61 |
62 | open BigOperators
63 |
64 | structure StandardSimplex (n : ℕ) where
65 | V : Fin n → ℝ
66 | NonNeg : ∀ i : Fin n, 0 ≤ V i
67 | sum_eq_one : (∑ i, V i) = 1
68 |
69 | namespace StandardSimplex
70 |
71 | def midpoint (n : ℕ) (a b : StandardSimplex n) : StandardSimplex n
72 | where
73 | V i := (a.V i + b.V i) / 2
74 | NonNeg := by
75 | intro i
76 | apply div_nonneg
77 | · linarith [a.NonNeg i, b.NonNeg i]
78 | norm_num
79 | sum_eq_one := by
80 | simp [div_eq_mul_inv, ← Finset.sum_mul, Finset.sum_add_distrib,
81 | a.sum_eq_one, b.sum_eq_one]
82 | field_simp
83 |
84 | end StandardSimplex
85 |
86 | namespace StandardSimplex
87 |
88 | def weightedAverage {n : ℕ} (lambda : Real) (lambda_nonneg : 0 ≤ lambda) (lambda_le : lambda ≤ 1)
89 | (a b : StandardSimplex n) : StandardSimplex n
90 | where
91 | V i := lambda * a.V i + (1 - lambda) * b.V i
92 | NonNeg i :=
93 | add_nonneg (mul_nonneg lambda_nonneg (a.NonNeg i)) (mul_nonneg (by linarith) (b.NonNeg i))
94 | sum_eq_one := by
95 | trans (lambda * ∑ i, a.V i) + (1 - lambda) * ∑ i, b.V i
96 | · rw [Finset.sum_add_distrib, Finset.mul_sum, Finset.mul_sum]
97 | simp [a.sum_eq_one, b.sum_eq_one]
98 |
99 | end StandardSimplex
100 |
101 |
--------------------------------------------------------------------------------
/MIL/C03_Logic/S05_Disjunction.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Data.Real.Basic
3 |
4 | namespace C03S05
5 |
6 | section
7 |
8 | variable {x y : ℝ}
9 |
10 | example (h : y > x ^ 2) : y > 0 ∨ y < -1 := by
11 | left
12 | linarith [pow_two_nonneg x]
13 |
14 | example (h : -y > x ^ 2 + 1) : y > 0 ∨ y < -1 := by
15 | right
16 | linarith [pow_two_nonneg x]
17 |
18 | example (h : y > 0) : y > 0 ∨ y < -1 :=
19 | Or.inl h
20 |
21 | example (h : y < -1) : y > 0 ∨ y < -1 :=
22 | Or.inr h
23 |
24 | example : x < |y| → x < y ∨ x < -y := by
25 | rcases le_or_gt 0 y with h | h
26 | · rw [abs_of_nonneg h]
27 | intro h; left; exact h
28 | · rw [abs_of_neg h]
29 | intro h; right; exact h
30 |
31 | example : x < |y| → x < y ∨ x < -y := by
32 | cases le_or_gt 0 y
33 | case inl h =>
34 | rw [abs_of_nonneg h]
35 | intro h; left; exact h
36 | case inr h =>
37 | rw [abs_of_neg h]
38 | intro h; right; exact h
39 |
40 | example : x < |y| → x < y ∨ x < -y := by
41 | cases le_or_gt 0 y
42 | next h =>
43 | rw [abs_of_nonneg h]
44 | intro h; left; exact h
45 | next h =>
46 | rw [abs_of_neg h]
47 | intro h; right; exact h
48 |
49 | example : x < |y| → x < y ∨ x < -y := by
50 | match le_or_gt 0 y with
51 | | Or.inl h =>
52 | rw [abs_of_nonneg h]
53 | intro h; left; exact h
54 | | Or.inr h =>
55 | rw [abs_of_neg h]
56 | intro h; right; exact h
57 |
58 | namespace MyAbs
59 |
60 | theorem le_abs_self (x : ℝ) : x ≤ |x| := by
61 | sorry
62 |
63 | theorem neg_le_abs_self (x : ℝ) : -x ≤ |x| := by
64 | sorry
65 |
66 | theorem abs_add (x y : ℝ) : |x + y| ≤ |x| + |y| := by
67 | sorry
68 |
69 | theorem lt_abs : x < |y| ↔ x < y ∨ x < -y := by
70 | sorry
71 |
72 | theorem abs_lt : |x| < y ↔ -y < x ∧ x < y := by
73 | sorry
74 |
75 | end MyAbs
76 |
77 | end
78 |
79 | example {x : ℝ} (h : x ≠ 0) : x < 0 ∨ x > 0 := by
80 | rcases lt_trichotomy x 0 with xlt | xeq | xgt
81 | · left
82 | exact xlt
83 | · contradiction
84 | · right; exact xgt
85 |
86 | example {m n k : ℕ} (h : m ∣ n ∨ m ∣ k) : m ∣ n * k := by
87 | rcases h with ⟨a, rfl⟩ | ⟨b, rfl⟩
88 | · rw [mul_assoc]
89 | apply dvd_mul_right
90 | · rw [mul_comm, mul_assoc]
91 | apply dvd_mul_right
92 |
93 | example {z : ℝ} (h : ∃ x y, z = x ^ 2 + y ^ 2 ∨ z = x ^ 2 + y ^ 2 + 1) : z ≥ 0 := by
94 | sorry
95 |
96 | example {x : ℝ} (h : x ^ 2 = 1) : x = 1 ∨ x = -1 := by
97 | sorry
98 |
99 | example {x y : ℝ} (h : x ^ 2 = y ^ 2) : x = y ∨ x = -y := by
100 | sorry
101 |
102 | section
103 | variable {R : Type*} [CommRing R] [IsDomain R]
104 | variable (x y : R)
105 |
106 | example (h : x ^ 2 = 1) : x = 1 ∨ x = -1 := by
107 | sorry
108 |
109 | example (h : x ^ 2 = y ^ 2) : x = y ∨ x = -y := by
110 | sorry
111 |
112 | end
113 |
114 | example (P : Prop) : ¬¬P → P := by
115 | intro h
116 | cases em P
117 | · assumption
118 | · contradiction
119 |
120 | example (P : Prop) : ¬¬P → P := by
121 | intro h
122 | by_cases h' : P
123 | · assumption
124 | contradiction
125 |
126 | example (P Q : Prop) : P → Q ↔ ¬P ∨ Q := by
127 | sorry
128 |
129 |
--------------------------------------------------------------------------------
/MIL/C03_Logic/S03_Negation.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Data.Real.Basic
3 |
4 | namespace C03S03
5 |
6 | section
7 | variable (a b : ℝ)
8 |
9 | example (h : a < b) : ¬b < a := by
10 | intro h'
11 | have : a < a := lt_trans h h'
12 | apply lt_irrefl a this
13 |
14 | def FnUb (f : ℝ → ℝ) (a : ℝ) : Prop :=
15 | ∀ x, f x ≤ a
16 |
17 | def FnLb (f : ℝ → ℝ) (a : ℝ) : Prop :=
18 | ∀ x, a ≤ f x
19 |
20 | def FnHasUb (f : ℝ → ℝ) :=
21 | ∃ a, FnUb f a
22 |
23 | def FnHasLb (f : ℝ → ℝ) :=
24 | ∃ a, FnLb f a
25 |
26 | variable (f : ℝ → ℝ)
27 |
28 | example (h : ∀ a, ∃ x, f x > a) : ¬FnHasUb f := by
29 | intro fnub
30 | rcases fnub with ⟨a, fnuba⟩
31 | rcases h a with ⟨x, hx⟩
32 | have : f x ≤ a := fnuba x
33 | linarith
34 |
35 | example (h : ∀ a, ∃ x, f x < a) : ¬FnHasLb f :=
36 | sorry
37 |
38 | example : ¬FnHasUb fun x ↦ x :=
39 | sorry
40 |
41 | #check (not_le_of_gt : a > b → ¬a ≤ b)
42 | #check (not_lt_of_ge : a ≥ b → ¬a < b)
43 | #check (lt_of_not_ge : ¬a ≥ b → a < b)
44 | #check (le_of_not_gt : ¬a > b → a ≤ b)
45 |
46 | example (h : Monotone f) (h' : f a < f b) : a < b := by
47 | sorry
48 |
49 | example (h : a ≤ b) (h' : f b < f a) : ¬Monotone f := by
50 | sorry
51 |
52 | example : ¬∀ {f : ℝ → ℝ}, Monotone f → ∀ {a b}, f a ≤ f b → a ≤ b := by
53 | intro h
54 | let f := fun x : ℝ ↦ (0 : ℝ)
55 | have monof : Monotone f := by sorry
56 | have h' : f 1 ≤ f 0 := le_refl _
57 | sorry
58 |
59 | example (x : ℝ) (h : ∀ ε > 0, x < ε) : x ≤ 0 := by
60 | sorry
61 |
62 | end
63 |
64 | section
65 | variable {α : Type*} (P : α → Prop) (Q : Prop)
66 |
67 | example (h : ¬∃ x, P x) : ∀ x, ¬P x := by
68 | sorry
69 |
70 | example (h : ∀ x, ¬P x) : ¬∃ x, P x := by
71 | sorry
72 |
73 | example (h : ¬∀ x, P x) : ∃ x, ¬P x := by
74 | sorry
75 |
76 | example (h : ∃ x, ¬P x) : ¬∀ x, P x := by
77 | sorry
78 |
79 | example (h : ¬∀ x, P x) : ∃ x, ¬P x := by
80 | by_contra h'
81 | apply h
82 | intro x
83 | show P x
84 | by_contra h''
85 | exact h' ⟨x, h''⟩
86 |
87 | example (h : ¬¬Q) : Q := by
88 | sorry
89 |
90 | example (h : Q) : ¬¬Q := by
91 | sorry
92 |
93 | end
94 |
95 | section
96 | variable (f : ℝ → ℝ)
97 |
98 | example (h : ¬FnHasUb f) : ∀ a, ∃ x, f x > a := by
99 | sorry
100 |
101 | example (h : ¬∀ a, ∃ x, f x > a) : FnHasUb f := by
102 | push_neg at h
103 | exact h
104 |
105 | example (h : ¬FnHasUb f) : ∀ a, ∃ x, f x > a := by
106 | dsimp only [FnHasUb, FnUb] at h
107 | push_neg at h
108 | exact h
109 |
110 | example (h : ¬Monotone f) : ∃ x y, x ≤ y ∧ f y < f x := by
111 | sorry
112 |
113 | example (h : ¬FnHasUb f) : ∀ a, ∃ x, f x > a := by
114 | contrapose! h
115 | exact h
116 |
117 | example (x : ℝ) (h : ∀ ε > 0, x ≤ ε) : x ≤ 0 := by
118 | contrapose! h
119 | use x / 2
120 | constructor <;> linarith
121 |
122 | end
123 |
124 | section
125 | variable (a : ℕ)
126 |
127 | example (h : 0 < 0) : a > 37 := by
128 | exfalso
129 | apply lt_irrefl 0 h
130 |
131 | example (h : 0 < 0) : a > 37 :=
132 | absurd h (lt_irrefl 0)
133 |
134 | example (h : 0 < 0) : a > 37 := by
135 | have h' : ¬0 < 0 := lt_irrefl 0
136 | contradiction
137 |
138 | end
139 |
140 |
--------------------------------------------------------------------------------
/html/_static/css/badge_only.css:
--------------------------------------------------------------------------------
1 | .clearfix{*zoom:1}.clearfix:after,.clearfix:before{display:table;content:""}.clearfix:after{clear:both}@font-face{font-family:FontAwesome;font-style:normal;font-weight:400;src:url(fonts/fontawesome-webfont.eot?674f50d287a8c48dc19ba404d20fe713?#iefix) format("embedded-opentype"),url(fonts/fontawesome-webfont.woff2?af7ae505a9eed503f8b8e6982036873e) format("woff2"),url(fonts/fontawesome-webfont.woff?fee66e712a8a08eef5805a46892932ad) format("woff"),url(fonts/fontawesome-webfont.ttf?b06871f281fee6b241d60582ae9369b9) format("truetype"),url(fonts/fontawesome-webfont.svg?912ec66d7572ff821749319396470bde#FontAwesome) format("svg")}.fa:before{font-family:FontAwesome;font-style:normal;font-weight:400;line-height:1}.fa:before,a .fa{text-decoration:inherit}.fa:before,a .fa,li .fa{display:inline-block}li .fa-large:before{width:1.875em}ul.fas{list-style-type:none;margin-left:2em;text-indent:-.8em}ul.fas li .fa{width:.8em}ul.fas li .fa-large:before{vertical-align:baseline}.fa-book:before,.icon-book:before{content:"\f02d"}.fa-caret-down:before,.icon-caret-down:before{content:"\f0d7"}.fa-caret-up:before,.icon-caret-up:before{content:"\f0d8"}.fa-caret-left:before,.icon-caret-left:before{content:"\f0d9"}.fa-caret-right:before,.icon-caret-right:before{content:"\f0da"}.rst-versions{position:fixed;bottom:0;left:0;width:300px;color:#fcfcfc;background:#1f1d1d;font-family:Lato,proxima-nova,Helvetica Neue,Arial,sans-serif;z-index:400}.rst-versions a{color:#2980b9;text-decoration:none}.rst-versions .rst-badge-small{display:none}.rst-versions .rst-current-version{padding:12px;background-color:#272525;display:block;text-align:right;font-size:90%;cursor:pointer;color:#27ae60}.rst-versions .rst-current-version:after{clear:both;content:"";display:block}.rst-versions .rst-current-version .fa{color:#fcfcfc}.rst-versions .rst-current-version .fa-book,.rst-versions .rst-current-version .icon-book{float:left}.rst-versions .rst-current-version.rst-out-of-date{background-color:#e74c3c;color:#fff}.rst-versions .rst-current-version.rst-active-old-version{background-color:#f1c40f;color:#000}.rst-versions.shift-up{height:auto;max-height:100%;overflow-y:scroll}.rst-versions.shift-up .rst-other-versions{display:block}.rst-versions .rst-other-versions{font-size:90%;padding:12px;color:grey;display:none}.rst-versions .rst-other-versions hr{display:block;height:1px;border:0;margin:20px 0;padding:0;border-top:1px solid #413d3d}.rst-versions .rst-other-versions dd{display:inline-block;margin:0}.rst-versions .rst-other-versions dd a{display:inline-block;padding:6px;color:#fcfcfc}.rst-versions .rst-other-versions .rtd-current-item{font-weight:700}.rst-versions.rst-badge{width:auto;bottom:20px;right:20px;left:auto;border:none;max-width:300px;max-height:90%}.rst-versions.rst-badge .fa-book,.rst-versions.rst-badge .icon-book{float:none;line-height:30px}.rst-versions.rst-badge.shift-up .rst-current-version{text-align:right}.rst-versions.rst-badge.shift-up .rst-current-version .fa-book,.rst-versions.rst-badge.shift-up .rst-current-version .icon-book{float:left}.rst-versions.rst-badge>.rst-current-version{width:auto;height:30px;line-height:30px;padding:0 6px;display:block;text-align:center}@media screen and (max-width:768px){.rst-versions{width:85%;display:none}.rst-versions.shift{display:block}}#flyout-search-form{padding:6px}
--------------------------------------------------------------------------------
/MIL_solutions.lean:
--------------------------------------------------------------------------------
1 | import MIL.C01_Introduction.solutions.Solutions_S01_Getting_Started
2 | import MIL.C01_Introduction.solutions.Solutions_S02_Overview
3 | import MIL.C02_Basics.solutions.Solutions_S01_Calculating
4 | import MIL.C02_Basics.solutions.Solutions_S02_Proving_Identities_in_Algebraic_Structures
5 | import MIL.C02_Basics.solutions.Solutions_S03_Using_Theorems_and_Lemmas
6 | import MIL.C02_Basics.solutions.Solutions_S04_More_on_Order_and_Divisibility
7 | import MIL.C02_Basics.solutions.Solutions_S05_Proving_Facts_about_Algebraic_Structures
8 | import MIL.C03_Logic.solutions.Solutions_S01_Implication_and_the_Universal_Quantifier
9 | import MIL.C03_Logic.solutions.Solutions_S02_The_Existential_Quantifier
10 | import MIL.C03_Logic.solutions.Solutions_S03_Negation
11 | import MIL.C03_Logic.solutions.Solutions_S04_Conjunction_and_Iff
12 | import MIL.C03_Logic.solutions.Solutions_S05_Disjunction
13 | import MIL.C03_Logic.solutions.Solutions_S06_Sequences_and_Convergence
14 | import MIL.C04_Sets_and_Functions.solutions.Solutions_S01_Sets
15 | import MIL.C04_Sets_and_Functions.solutions.Solutions_S02_Functions
16 | import MIL.C04_Sets_and_Functions.solutions.Solutions_S03_The_Schroeder_Bernstein_Theorem
17 | import MIL.C05_Elementary_Number_Theory.solutions.Solutions_S01_Irrational_Roots
18 | import MIL.C05_Elementary_Number_Theory.solutions.Solutions_S02_Induction_and_Recursion
19 | import MIL.C05_Elementary_Number_Theory.solutions.Solutions_S03_Infinitely_Many_Primes
20 | import MIL.C05_Elementary_Number_Theory.solutions.Solutions_S04_More_Induction
21 | import MIL.C06_Discrete_Mathematics.solutions.Solutions_S01_Finsets_and_Fintypes
22 | import MIL.C06_Discrete_Mathematics.solutions.Solutions_S02_Counting_Arguments
23 | import MIL.C06_Discrete_Mathematics.solutions.Solutions_S03_Inductive_Structures
24 | import MIL.C07_Structures.solutions.Solutions_S01_Structures
25 | import MIL.C07_Structures.solutions.Solutions_S02_Algebraic_Structures
26 | import MIL.C07_Structures.solutions.Solutions_S03_Building_the_Gaussian_Integers
27 | import MIL.C08_Hierarchies.solutions.Solutions_S01_Basics
28 | import MIL.C08_Hierarchies.solutions.Solutions_S02_Morphisms
29 | import MIL.C08_Hierarchies.solutions.Solutions_S03_Subobjects
30 | import MIL.C09_Groups_and_Rings.solutions.Solutions_S01_Groups
31 | import MIL.C09_Groups_and_Rings.solutions.Solutions_S02_Rings
32 | import MIL.C10_Linear_Algebra.solutions.Solutions_S01_Vector_Spaces
33 | import MIL.C10_Linear_Algebra.solutions.Solutions_S02_Subspaces
34 | import MIL.C10_Linear_Algebra.solutions.Solutions_S03_Endomorphisms
35 | import MIL.C10_Linear_Algebra.solutions.Solutions_S04_Bases
36 | import MIL.C11_Topology.solutions.Solutions_S01_Filters
37 | import MIL.C11_Topology.solutions.Solutions_S02_Metric_Spaces
38 | import MIL.C11_Topology.solutions.Solutions_S03_Topological_Spaces
39 | import MIL.C12_Differential_Calculus.solutions.Solutions_S01_Elementary_Differential_Calculus
40 | import MIL.C12_Differential_Calculus.solutions.Solutions_S02_Differential_Calculus_in_Normed_Spaces
41 | import MIL.C13_Integration_and_Measure_Theory.solutions.Solutions_S01_Elementary_Integration
42 | import MIL.C13_Integration_and_Measure_Theory.solutions.Solutions_S02_Measure_Theory
43 | import MIL.C13_Integration_and_Measure_Theory.solutions.Solutions_S03_Integration
44 | import MIL.Common
45 |
--------------------------------------------------------------------------------
/MIL/C09_Groups_and_Rings/solutions/Solutions_S02_Rings.lean:
--------------------------------------------------------------------------------
1 | import Mathlib.RingTheory.Ideal.Quotient.Operations
2 | import Mathlib.RingTheory.Localization.Basic
3 | import Mathlib.RingTheory.DedekindDomain.Ideal
4 | import Mathlib.Analysis.Complex.Polynomial.Basic
5 | import Mathlib.Data.ZMod.QuotientRing
6 | import MIL.Common
7 |
8 | noncomputable section
9 |
10 | open BigOperators PiNotation
11 |
12 | section
13 | variable {ι R : Type*} [CommRing R]
14 | open Ideal Quotient Function
15 |
16 | #check Pi.ringHom
17 | #check ker_Pi_Quotient_mk
18 |
19 | /-- The homomorphism from ``R ⧸ ⨅ i, I i`` to ``Π i, R ⧸ I i`` featured in the Chinese
20 | Remainder Theorem. -/
21 | def chineseMap (I : ι → Ideal R) : (R ⧸ ⨅ i, I i) →+* Π i, R ⧸ I i :=
22 | Ideal.Quotient.lift (⨅ i, I i) (Pi.ringHom fun i : ι ↦ Ideal.Quotient.mk (I i))
23 | (by simp [← RingHom.mem_ker, ker_Pi_Quotient_mk])
24 |
25 | lemma chineseMap_mk (I : ι → Ideal R) (x : R) :
26 | chineseMap I (Quotient.mk _ x) = fun i : ι ↦ Ideal.Quotient.mk (I i) x :=
27 | rfl
28 |
29 | lemma chineseMap_mk' (I : ι → Ideal R) (x : R) (i : ι) :
30 | chineseMap I (mk _ x) i = mk (I i) x :=
31 | rfl
32 |
33 | lemma chineseMap_inj (I : ι → Ideal R) : Injective (chineseMap I) := by
34 | rw [chineseMap, injective_lift_iff, ker_Pi_Quotient_mk]
35 |
36 | theorem isCoprime_Inf {I : Ideal R} {J : ι → Ideal R} {s : Finset ι}
37 | (hf : ∀ j ∈ s, IsCoprime I (J j)) : IsCoprime I (⨅ j ∈ s, J j) := by
38 | classical
39 | simp_rw [isCoprime_iff_add] at *
40 | induction s using Finset.induction with
41 | | empty =>
42 | simp
43 | | @insert i s _ hs =>
44 | rw [Finset.iInf_insert, inf_comm, one_eq_top, eq_top_iff, ← one_eq_top]
45 | set K := ⨅ j ∈ s, J j
46 | calc
47 | 1 = I + K := (hs fun j hj ↦ hf j (Finset.mem_insert_of_mem hj)).symm
48 | _ = I + K * (I + J i) := by rw [hf i (Finset.mem_insert_self i s), mul_one]
49 | _ = (1 + K) * I + K * J i := by ring
50 | _ ≤ I + K ⊓ J i := by gcongr ; apply mul_le_left ; apply mul_le_inf
51 |
52 |
53 | lemma chineseMap_surj [Fintype ι] {I : ι → Ideal R}
54 | (hI : ∀ i j, i ≠ j → IsCoprime (I i) (I j)) : Surjective (chineseMap I) := by
55 | classical
56 | intro g
57 | choose f hf using fun i ↦ Ideal.Quotient.mk_surjective (g i)
58 | have key : ∀ i, ∃ e : R, mk (I i) e = 1 ∧ ∀ j, j ≠ i → mk (I j) e = 0 := by
59 | intro i
60 | have hI' : ∀ j ∈ ({i} : Finset ι)ᶜ, IsCoprime (I i) (I j) := by
61 | intros j hj
62 | exact hI _ _ (by simpa [ne_comm, isCoprime_iff_add] using hj)
63 | rcases isCoprime_iff_exists.mp (isCoprime_Inf hI') with ⟨u, hu, e, he, hue⟩
64 | replace he : ∀ j, j ≠ i → e ∈ I j := by simpa using he
65 | refine ⟨e, ?_, ?_⟩
66 | · simp [eq_sub_of_add_eq' hue, map_sub, eq_zero_iff_mem.mpr hu]
67 | · exact fun j hj ↦ eq_zero_iff_mem.mpr (he j hj)
68 | choose e he using key
69 | use mk _ (∑ i, f i * e i)
70 | ext i
71 | rw [chineseMap_mk', map_sum, Fintype.sum_eq_single i]
72 | · simp [(he i).1, hf]
73 | · intros j hj
74 | simp [(he j).2 i hj.symm]
75 |
76 | noncomputable def chineseIso [Fintype ι] (f : ι → Ideal R)
77 | (hf : ∀ i j, i ≠ j → IsCoprime (f i) (f j)) : (R ⧸ ⨅ i, f i) ≃+* Π i, R ⧸ f i :=
78 | { Equiv.ofBijective _ ⟨chineseMap_inj f, chineseMap_surj hf⟩,
79 | chineseMap f with }
80 |
81 | end
82 |
83 |
--------------------------------------------------------------------------------
/MIL/C03_Logic/S06_Sequences_and_Convergence.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Data.Real.Basic
3 |
4 | namespace C03S06
5 |
6 | def ConvergesTo (s : ℕ → ℝ) (a : ℝ) :=
7 | ∀ ε > 0, ∃ N, ∀ n ≥ N, |s n - a| < ε
8 |
9 | example : (fun x y : ℝ ↦ (x + y) ^ 2) = fun x y : ℝ ↦ x ^ 2 + 2 * x * y + y ^ 2 := by
10 | ext
11 | ring
12 |
13 | example (a b : ℝ) : |a| = |a - b + b| := by
14 | congr
15 | ring
16 |
17 | example {a : ℝ} (h : 1 < a) : a < a * a := by
18 | convert (mul_lt_mul_right _).2 h
19 | · rw [one_mul]
20 | exact lt_trans zero_lt_one h
21 |
22 | theorem convergesTo_const (a : ℝ) : ConvergesTo (fun x : ℕ ↦ a) a := by
23 | intro ε εpos
24 | use 0
25 | intro n nge
26 | rw [sub_self, abs_zero]
27 | apply εpos
28 |
29 | theorem convergesTo_add {s t : ℕ → ℝ} {a b : ℝ}
30 | (cs : ConvergesTo s a) (ct : ConvergesTo t b) :
31 | ConvergesTo (fun n ↦ s n + t n) (a + b) := by
32 | intro ε εpos
33 | dsimp -- this line is not needed but cleans up the goal a bit.
34 | have ε2pos : 0 < ε / 2 := by linarith
35 | rcases cs (ε / 2) ε2pos with ⟨Ns, hs⟩
36 | rcases ct (ε / 2) ε2pos with ⟨Nt, ht⟩
37 | use max Ns Nt
38 | sorry
39 |
40 | theorem convergesTo_mul_const {s : ℕ → ℝ} {a : ℝ} (c : ℝ) (cs : ConvergesTo s a) :
41 | ConvergesTo (fun n ↦ c * s n) (c * a) := by
42 | by_cases h : c = 0
43 | · convert convergesTo_const 0
44 | · rw [h]
45 | ring
46 | rw [h]
47 | ring
48 | have acpos : 0 < |c| := abs_pos.mpr h
49 | sorry
50 |
51 | theorem exists_abs_le_of_convergesTo {s : ℕ → ℝ} {a : ℝ} (cs : ConvergesTo s a) :
52 | ∃ N b, ∀ n, N ≤ n → |s n| < b := by
53 | rcases cs 1 zero_lt_one with ⟨N, h⟩
54 | use N, |a| + 1
55 | sorry
56 |
57 | theorem aux {s t : ℕ → ℝ} {a : ℝ} (cs : ConvergesTo s a) (ct : ConvergesTo t 0) :
58 | ConvergesTo (fun n ↦ s n * t n) 0 := by
59 | intro ε εpos
60 | dsimp
61 | rcases exists_abs_le_of_convergesTo cs with ⟨N₀, B, h₀⟩
62 | have Bpos : 0 < B := lt_of_le_of_lt (abs_nonneg _) (h₀ N₀ (le_refl _))
63 | have pos₀ : ε / B > 0 := div_pos εpos Bpos
64 | rcases ct _ pos₀ with ⟨N₁, h₁⟩
65 | sorry
66 |
67 | theorem convergesTo_mul {s t : ℕ → ℝ} {a b : ℝ}
68 | (cs : ConvergesTo s a) (ct : ConvergesTo t b) :
69 | ConvergesTo (fun n ↦ s n * t n) (a * b) := by
70 | have h₁ : ConvergesTo (fun n ↦ s n * (t n + -b)) 0 := by
71 | apply aux cs
72 | convert convergesTo_add ct (convergesTo_const (-b))
73 | ring
74 | have := convergesTo_add h₁ (convergesTo_mul_const b cs)
75 | convert convergesTo_add h₁ (convergesTo_mul_const b cs) using 1
76 | · ext; ring
77 | ring
78 |
79 | theorem convergesTo_unique {s : ℕ → ℝ} {a b : ℝ}
80 | (sa : ConvergesTo s a) (sb : ConvergesTo s b) :
81 | a = b := by
82 | by_contra abne
83 | have : |a - b| > 0 := by sorry
84 | let ε := |a - b| / 2
85 | have εpos : ε > 0 := by
86 | change |a - b| / 2 > 0
87 | linarith
88 | rcases sa ε εpos with ⟨Na, hNa⟩
89 | rcases sb ε εpos with ⟨Nb, hNb⟩
90 | let N := max Na Nb
91 | have absa : |s N - a| < ε := by sorry
92 | have absb : |s N - b| < ε := by sorry
93 | have : |a - b| < |a - b| := by sorry
94 | exact lt_irrefl _ this
95 |
96 | section
97 | variable {α : Type*} [LinearOrder α]
98 |
99 | def ConvergesTo' (s : α → ℝ) (a : ℝ) :=
100 | ∀ ε > 0, ∃ N, ∀ n ≥ N, |s n - a| < ε
101 |
102 | end
103 |
104 |
--------------------------------------------------------------------------------
/lake-manifest.json:
--------------------------------------------------------------------------------
1 | {"version": "1.1.0",
2 | "packagesDir": ".lake/packages",
3 | "packages":
4 | [{"url": "https://github.com/leanprover-community/mathlib4",
5 | "type": "git",
6 | "subDir": null,
7 | "scope": "",
8 | "rev": "308445d7985027f538e281e18df29ca16ede2ba3",
9 | "name": "mathlib",
10 | "manifestFile": "lake-manifest.json",
11 | "inputRev": "v4.21.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": "c4aa78186d388e50a436e8362b947bae125a2933",
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": "6c62474116f525d2814f0157bb468bf3a4f9f120",
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": "d07bd64f1910f1cc5e4cc87b6b9c590080e7a457",
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": "6980f6ca164de593cb77cd03d8eac549cc444156",
49 | "name": "proofwidgets",
50 | "manifestFile": "lake-manifest.json",
51 | "inputRev": "v0.0.62",
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": "8ff27701d003456fd59f13a9212431239d902aef",
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": "e9c65db4823976353cd0bb03199a172719efbeb7",
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": "8d2067bf518731a70a255d4a61b5c103922c772e",
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": "7c6aef5f75a43ebbba763b44d535175a1b04c9e0",
89 | "name": "Cli",
90 | "manifestFile": "lake-manifest.json",
91 | "inputRev": "main",
92 | "inherited": true,
93 | "configFile": "lakefile.toml"}],
94 | "name": "mil",
95 | "lakeDir": ".lake"}
96 |
--------------------------------------------------------------------------------
/MIL/C04_Sets_and_Functions/solutions/Solutions_S01_Sets.lean:
--------------------------------------------------------------------------------
1 | import Mathlib.Data.Set.Lattice
2 | import Mathlib.Data.Nat.Prime.Basic
3 | import MIL.Common
4 |
5 | section
6 | variable {α : Type*}
7 | variable (s t u : Set α)
8 | open Set
9 |
10 | example : s ∩ t ∪ s ∩ u ⊆ s ∩ (t ∪ u) := by
11 | rintro x (⟨xs, xt⟩ | ⟨xs, xu⟩)
12 | · use xs; left; exact xt
13 | · use xs; right; exact xu
14 |
15 | example : s \ (t ∪ u) ⊆ (s \ t) \ u := by
16 | rintro x ⟨xs, xntu⟩
17 | constructor
18 | use xs
19 | · intro xt
20 | exact xntu (Or.inl xt)
21 | intro xu
22 | apply xntu (Or.inr xu)
23 |
24 | example : s ∩ t = t ∩ s :=
25 | Subset.antisymm
26 | (fun x ⟨xs, xt⟩ ↦ ⟨xt, xs⟩) fun x ⟨xt, xs⟩ ↦ ⟨xs, xt⟩
27 |
28 | example : s ∩ (s ∪ t) = s := by
29 | ext x; constructor
30 | · rintro ⟨xs, _⟩
31 | exact xs
32 | · intro xs
33 | use xs; left; exact xs
34 |
35 | example : s ∪ s ∩ t = s := by
36 | ext x; constructor
37 | · rintro (xs | ⟨xs, xt⟩) <;> exact xs
38 | · intro xs; left; exact xs
39 |
40 | example : s \ t ∪ t = s ∪ t := by
41 | ext x; constructor
42 | · rintro (⟨xs, nxt⟩ | xt)
43 | · left
44 | exact xs
45 | · right
46 | exact xt
47 | by_cases h : x ∈ t
48 | · intro
49 | right
50 | exact h
51 | rintro (xs | xt)
52 | · left
53 | use xs
54 | right; exact xt
55 |
56 | example : s \ t ∪ t \ s = (s ∪ t) \ (s ∩ t) := by
57 | ext x; constructor
58 | · rintro (⟨xs, xnt⟩ | ⟨xt, xns⟩)
59 | · constructor
60 | left
61 | exact xs
62 | rintro ⟨_, xt⟩
63 | contradiction
64 | · constructor
65 | right
66 | exact xt
67 | rintro ⟨xs, _⟩
68 | contradiction
69 | rintro ⟨xs | xt, nxst⟩
70 | · left
71 | use xs
72 | intro xt
73 | apply nxst
74 | constructor <;> assumption
75 | · right; use xt; intro xs
76 | apply nxst
77 | constructor <;> assumption
78 |
79 | example : { n | Nat.Prime n } ∩ { n | n > 2 } ⊆ { n | ¬Even n } := by
80 | intro n
81 | simp
82 | intro nprime n_gt
83 | rcases Nat.Prime.eq_two_or_odd nprime with h | h
84 | · rw [h]
85 | linarith
86 | · rw [Nat.odd_iff, h]
87 |
88 | end
89 |
90 | section
91 |
92 | variable (s t : Set ℕ)
93 |
94 | section
95 | variable (ssubt : s ⊆ t)
96 |
97 | example (h₀ : ∀ x ∈ t, ¬Even x) (h₁ : ∀ x ∈ t, Prime x) : ∀ x ∈ s, ¬Even x ∧ Prime x := by
98 | intro x xs
99 | constructor
100 | · apply h₀ x (ssubt xs)
101 | apply h₁ x (ssubt xs)
102 |
103 | example (h : ∃ x ∈ s, ¬Even x ∧ Prime x) : ∃ x ∈ t, Prime x := by
104 | rcases h with ⟨x, xs, _, px⟩
105 | use x, ssubt xs
106 |
107 | end
108 |
109 | end
110 |
111 | section
112 | variable {α I : Type*}
113 | variable (A B : I → Set α)
114 | variable (s : Set α)
115 |
116 | open Set
117 |
118 | example : (s ∪ ⋂ i, A i) = ⋂ i, A i ∪ s := by
119 | ext x
120 | simp only [mem_union, mem_iInter]
121 | constructor
122 | · rintro (xs | xI)
123 | · intro i
124 | right
125 | exact xs
126 | intro i
127 | left
128 | exact xI i
129 | intro h
130 | by_cases xs : x ∈ s
131 | · left
132 | exact xs
133 | right
134 | intro i
135 | cases h i
136 | · assumption
137 | contradiction
138 |
139 | def primes : Set ℕ :=
140 | { x | Nat.Prime x }
141 |
142 | example : (⋃ p ∈ primes, { x | x ≤ p }) = univ := by
143 | apply eq_univ_of_forall
144 | intro x
145 | simp
146 | rcases Nat.exists_infinite_primes x with ⟨p, pge, primep⟩
147 | use p, primep
148 |
149 | end
150 |
151 |
--------------------------------------------------------------------------------
/MIL/C11_Topology/S01_Filters.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Topology.Instances.Real.Lemmas
3 |
4 | open Set Filter Topology
5 |
6 | def principal {α : Type*} (s : Set α) : Filter α
7 | where
8 | sets := { t | s ⊆ t }
9 | univ_sets := sorry
10 | sets_of_superset := sorry
11 | inter_sets := sorry
12 |
13 | example : Filter ℕ :=
14 | { sets := { s | ∃ a, ∀ b, a ≤ b → b ∈ s }
15 | univ_sets := sorry
16 | sets_of_superset := sorry
17 | inter_sets := sorry }
18 |
19 | def Tendsto₁ {X Y : Type*} (f : X → Y) (F : Filter X) (G : Filter Y) :=
20 | ∀ V ∈ G, f ⁻¹' V ∈ F
21 |
22 | def Tendsto₂ {X Y : Type*} (f : X → Y) (F : Filter X) (G : Filter Y) :=
23 | map f F ≤ G
24 |
25 | example {X Y : Type*} (f : X → Y) (F : Filter X) (G : Filter Y) :
26 | Tendsto₂ f F G ↔ Tendsto₁ f F G :=
27 | Iff.rfl
28 |
29 | #check (@Filter.map_mono : ∀ {α β} {m : α → β}, Monotone (map m))
30 |
31 | #check
32 | (@Filter.map_map :
33 | ∀ {α β γ} {f : Filter α} {m : α → β} {m' : β → γ}, map m' (map m f) = map (m' ∘ m) f)
34 |
35 | example {X Y Z : Type*} {F : Filter X} {G : Filter Y} {H : Filter Z} {f : X → Y} {g : Y → Z}
36 | (hf : Tendsto₁ f F G) (hg : Tendsto₁ g G H) : Tendsto₁ (g ∘ f) F H :=
37 | sorry
38 |
39 | variable (f : ℝ → ℝ) (x₀ y₀ : ℝ)
40 |
41 | #check comap ((↑) : ℚ → ℝ) (𝓝 x₀)
42 |
43 | #check Tendsto (f ∘ (↑)) (comap ((↑) : ℚ → ℝ) (𝓝 x₀)) (𝓝 y₀)
44 |
45 | section
46 | variable {α β γ : Type*} (F : Filter α) {m : γ → β} {n : β → α}
47 |
48 | #check (comap_comap : comap m (comap n F) = comap (n ∘ m) F)
49 |
50 | end
51 |
52 | example : 𝓝 (x₀, y₀) = 𝓝 x₀ ×ˢ 𝓝 y₀ :=
53 | nhds_prod_eq
54 |
55 | #check le_inf_iff
56 |
57 | example (f : ℕ → ℝ × ℝ) (x₀ y₀ : ℝ) :
58 | Tendsto f atTop (𝓝 (x₀, y₀)) ↔
59 | Tendsto (Prod.fst ∘ f) atTop (𝓝 x₀) ∧ Tendsto (Prod.snd ∘ f) atTop (𝓝 y₀) :=
60 | sorry
61 |
62 | example (x₀ : ℝ) : HasBasis (𝓝 x₀) (fun ε : ℝ ↦ 0 < ε) fun ε ↦ Ioo (x₀ - ε) (x₀ + ε) :=
63 | nhds_basis_Ioo_pos x₀
64 |
65 | example (u : ℕ → ℝ) (x₀ : ℝ) :
66 | Tendsto u atTop (𝓝 x₀) ↔ ∀ ε > 0, ∃ N, ∀ n ≥ N, u n ∈ Ioo (x₀ - ε) (x₀ + ε) := by
67 | have : atTop.HasBasis (fun _ : ℕ ↦ True) Ici := atTop_basis
68 | rw [this.tendsto_iff (nhds_basis_Ioo_pos x₀)]
69 | simp
70 |
71 | example (P Q : ℕ → Prop) (hP : ∀ᶠ n in atTop, P n) (hQ : ∀ᶠ n in atTop, Q n) :
72 | ∀ᶠ n in atTop, P n ∧ Q n :=
73 | hP.and hQ
74 |
75 | example (u v : ℕ → ℝ) (h : ∀ᶠ n in atTop, u n = v n) (x₀ : ℝ) :
76 | Tendsto u atTop (𝓝 x₀) ↔ Tendsto v atTop (𝓝 x₀) :=
77 | tendsto_congr' h
78 |
79 | example (u v : ℕ → ℝ) (h : u =ᶠ[atTop] v) (x₀ : ℝ) :
80 | Tendsto u atTop (𝓝 x₀) ↔ Tendsto v atTop (𝓝 x₀) :=
81 | tendsto_congr' h
82 |
83 | #check Eventually.of_forall
84 | #check Eventually.mono
85 | #check Eventually.and
86 |
87 | example (P Q R : ℕ → Prop) (hP : ∀ᶠ n in atTop, P n) (hQ : ∀ᶠ n in atTop, Q n)
88 | (hR : ∀ᶠ n in atTop, P n ∧ Q n → R n) : ∀ᶠ n in atTop, R n := by
89 | apply (hP.and (hQ.and hR)).mono
90 | rintro n ⟨h, h', h''⟩
91 | exact h'' ⟨h, h'⟩
92 |
93 | example (P Q R : ℕ → Prop) (hP : ∀ᶠ n in atTop, P n) (hQ : ∀ᶠ n in atTop, Q n)
94 | (hR : ∀ᶠ n in atTop, P n ∧ Q n → R n) : ∀ᶠ n in atTop, R n := by
95 | filter_upwards [hP, hQ, hR] with n h h' h''
96 | exact h'' ⟨h, h'⟩
97 |
98 | #check mem_closure_iff_clusterPt
99 | #check le_principal_iff
100 | #check neBot_of_le
101 |
102 | example (u : ℕ → ℝ) (M : Set ℝ) (x : ℝ) (hux : Tendsto u atTop (𝓝 x))
103 | (huM : ∀ᶠ n in atTop, u n ∈ M) : x ∈ closure M :=
104 | sorry
105 |
106 |
--------------------------------------------------------------------------------
/MIL/C10_Linear_Algebra/solutions/Solutions_S04_Bases.lean:
--------------------------------------------------------------------------------
1 | import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
2 | import Mathlib.LinearAlgebra.Eigenspace.Minpoly
3 | import Mathlib.LinearAlgebra.Charpoly.Basic
4 | import Mathlib.Data.Complex.FiniteDimensional
5 |
6 | import MIL.Common
7 |
8 | variable {K : Type*} [Field K] {V : Type*} [AddCommGroup V] [Module K V]
9 |
10 | section
11 |
12 | variable {ι : Type*} (B : Basis ι K V) (v : V) (i : ι)
13 |
14 | -- The basis vector with index ``i``
15 | #check (B i : V)
16 |
17 | -- the linear isomorphism with the model space given by ``B``
18 | #check (B.repr : V ≃ₗ[K] ι →₀ K)
19 |
20 | -- the component function of ``v``
21 | #check (B.repr v : ι →₀ K)
22 |
23 | -- the component of ``v`` with index ``i``
24 | #check (B.repr v i : K)
25 |
26 | variable [DecidableEq ι]
27 |
28 | section
29 |
30 | variable {W : Type*} [AddCommGroup W] [Module K W]
31 | (φ : V →ₗ[K] W) (u : ι → W)
32 |
33 | #check (B.constr K : (ι → W) ≃ₗ[K] (V →ₗ[K] W))
34 |
35 | #check (B.constr K u : V →ₗ[K] W)
36 |
37 | example (i : ι) : B.constr K u (B i) = u i :=
38 | B.constr_basis K u i
39 |
40 |
41 |
42 | variable {ι' : Type*} (B' : Basis ι' K W) [Fintype ι] [DecidableEq ι] [Fintype ι'] [DecidableEq ι']
43 |
44 | open LinearMap
45 |
46 | #check (toMatrix B B' : (V →ₗ[K] W) ≃ₗ[K] Matrix ι' ι K)
47 |
48 | open Matrix -- get access to the ``*ᵥ`` notation for multiplication between matrices and vectors.
49 |
50 | example (φ : V →ₗ[K] W) (v : V) : (toMatrix B B' φ) *ᵥ (B.repr v) = B'.repr (φ v) :=
51 | toMatrix_mulVec_repr B B' φ v
52 |
53 |
54 | variable {ι'' : Type*} (B'' : Basis ι'' K W) [Fintype ι''] [DecidableEq ι'']
55 |
56 | example (φ : V →ₗ[K] W) : (toMatrix B B'' φ) = (toMatrix B' B'' .id) * (toMatrix B B' φ) := by
57 | simp
58 |
59 | end
60 |
61 |
62 | open Module LinearMap Matrix
63 |
64 | -- Some lemmas coming from the fact that `LinearMap.toMatrix` is an algebra morphism.
65 | #check toMatrix_comp
66 | #check id_comp
67 | #check comp_id
68 | #check toMatrix_id
69 |
70 | -- Some lemmas coming from the fact that ``Matrix.det`` is a multiplicative monoid morphism.
71 | #check Matrix.det_mul
72 | #check Matrix.det_one
73 |
74 | example [Fintype ι] (B' : Basis ι K V) (φ : End K V) :
75 | (toMatrix B B φ).det = (toMatrix B' B' φ).det := by
76 | set M := toMatrix B B φ
77 | set M' := toMatrix B' B' φ
78 | set P := (toMatrix B B') LinearMap.id
79 | set P' := (toMatrix B' B) LinearMap.id
80 | have F : M = P' * M' * P := by
81 | rw [← toMatrix_comp, ← toMatrix_comp, id_comp, comp_id]
82 | have F' : P' * P = 1 := by
83 | rw [← toMatrix_comp, id_comp, toMatrix_id]
84 | rw [F, Matrix.det_mul, Matrix.det_mul,
85 | show P'.det * M'.det * P.det = P'.det * P.det * M'.det by ring, ← Matrix.det_mul, F',
86 | Matrix.det_one, one_mul]
87 | end
88 |
89 |
90 | section
91 | variable (E F : Submodule K V) [FiniteDimensional K V]
92 |
93 | open Module
94 |
95 | example : finrank K (E ⊔ F : Submodule K V) + finrank K (E ⊓ F : Submodule K V) =
96 | finrank K E + finrank K F :=
97 | Submodule.finrank_sup_add_finrank_inf_eq E F
98 |
99 | example : finrank K E ≤ finrank K V := Submodule.finrank_le E
100 | example (h : finrank K V < finrank K E + finrank K F) :
101 | Nontrivial (E ⊓ F : Submodule K V) := by
102 | rw [← finrank_pos_iff (R := K)]
103 | have := Submodule.finrank_sup_add_finrank_inf_eq E F
104 | have := Submodule.finrank_le E
105 | have := Submodule.finrank_le F
106 | have := Submodule.finrank_le (E ⊔ F)
107 | linarith
108 | end
109 |
110 |
--------------------------------------------------------------------------------
/MIL/C02_Basics/solutions/Solutions_S05_Proving_Facts_about_Algebraic_Structures.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Topology.MetricSpace.Basic
3 |
4 | section
5 | variable {α : Type*} [Lattice α]
6 | variable (x y z : α)
7 |
8 | example : x ⊓ y = y ⊓ x := by
9 | apply le_antisymm
10 | repeat
11 | apply le_inf
12 | · apply inf_le_right
13 | apply inf_le_left
14 |
15 | example : x ⊓ y ⊓ z = x ⊓ (y ⊓ z) := by
16 | apply le_antisymm
17 | · apply le_inf
18 | · trans x ⊓ y
19 | apply inf_le_left
20 | apply inf_le_left
21 | apply le_inf
22 | · trans x ⊓ y
23 | apply inf_le_left
24 | apply inf_le_right
25 | apply inf_le_right
26 | apply le_inf
27 | · apply le_inf
28 | · apply inf_le_left
29 | trans y ⊓ z
30 | apply inf_le_right
31 | apply inf_le_left
32 | trans y ⊓ z
33 | apply inf_le_right
34 | apply inf_le_right
35 |
36 | example : x ⊔ y = y ⊔ x := by
37 | apply le_antisymm
38 | repeat
39 | apply sup_le
40 | · apply le_sup_right
41 | apply le_sup_left
42 |
43 | example : x ⊔ y ⊔ z = x ⊔ (y ⊔ z) := by
44 | apply le_antisymm
45 | · apply sup_le
46 | · apply sup_le
47 | apply le_sup_left
48 | · trans y ⊔ z
49 | apply le_sup_left
50 | apply le_sup_right
51 | trans y ⊔ z
52 | apply le_sup_right
53 | apply le_sup_right
54 | apply sup_le
55 | · trans x ⊔ y
56 | apply le_sup_left
57 | apply le_sup_left
58 | apply sup_le
59 | · trans x ⊔ y
60 | apply le_sup_right
61 | apply le_sup_left
62 | apply le_sup_right
63 |
64 | theorem absorb1 : x ⊓ (x ⊔ y) = x := by
65 | apply le_antisymm
66 | · apply inf_le_left
67 | apply le_inf
68 | · apply le_refl
69 | apply le_sup_left
70 |
71 | theorem absorb2 : x ⊔ x ⊓ y = x := by
72 | apply le_antisymm
73 | · apply sup_le
74 | · apply le_refl
75 | apply inf_le_left
76 | apply le_sup_left
77 |
78 | end
79 |
80 | section
81 | variable {α : Type*} [DistribLattice α]
82 | variable (x y z : α)
83 |
84 | #check (inf_sup_left x y z : x ⊓ (y ⊔ z) = x ⊓ y ⊔ x ⊓ z)
85 | #check (inf_sup_right x y z : (x ⊔ y) ⊓ z = x ⊓ z ⊔ y ⊓ z)
86 | #check (sup_inf_left x y z : x ⊔ y ⊓ z = (x ⊔ y) ⊓ (x ⊔ z))
87 | #check (sup_inf_right x y z : x ⊓ y ⊔ z = (x ⊔ z) ⊓ (y ⊔ z))
88 | end
89 |
90 | section
91 | variable {α : Type*} [Lattice α]
92 | variable (a b c : α)
93 |
94 | example (h : ∀ x y z : α, x ⊓ (y ⊔ z) = x ⊓ y ⊔ x ⊓ z) : a ⊔ b ⊓ c = (a ⊔ b) ⊓ (a ⊔ c) := by
95 | rw [h, @inf_comm _ _ (a ⊔ b), absorb1, @inf_comm _ _ (a ⊔ b), h, ← sup_assoc, @inf_comm _ _ c a,
96 | absorb2, inf_comm]
97 |
98 | example (h : ∀ x y z : α, x ⊔ y ⊓ z = (x ⊔ y) ⊓ (x ⊔ z)) : a ⊓ (b ⊔ c) = a ⊓ b ⊔ a ⊓ c := by
99 | rw [h, @sup_comm _ _ (a ⊓ b), absorb2, @sup_comm _ _ (a ⊓ b), h, ← inf_assoc, @sup_comm _ _ c a,
100 | absorb1, sup_comm]
101 |
102 | end
103 |
104 | section
105 | variable {R : Type*} [Ring R] [PartialOrder R] [IsStrictOrderedRing R]
106 | variable (a b c : R)
107 |
108 | theorem aux1 (h : a ≤ b) : 0 ≤ b - a := by
109 | rw [← sub_self a, sub_eq_add_neg, sub_eq_add_neg, add_comm, add_comm b]
110 | apply add_le_add_left h
111 |
112 | theorem aux2 (h : 0 ≤ b - a) : a ≤ b := by
113 | rw [← add_zero a, ← sub_add_cancel b a, add_comm (b - a)]
114 | apply add_le_add_left h
115 |
116 | example (h : a ≤ b) (h' : 0 ≤ c) : a * c ≤ b * c := by
117 | have h1 : 0 ≤ (b - a) * c := mul_nonneg (aux1 _ _ h) h'
118 | rw [sub_mul] at h1
119 | exact aux2 _ _ h1
120 |
121 | end
122 |
123 | section
124 | variable {X : Type*} [MetricSpace X]
125 | variable (x y z : X)
126 |
127 | example (x y : X) : 0 ≤ dist x y :=by
128 | have : 0 ≤ dist x y + dist y x := by
129 | rw [← dist_self x]
130 | apply dist_triangle
131 | linarith [dist_comm x y]
132 |
133 | end
134 |
135 |
--------------------------------------------------------------------------------
/MIL/C03_Logic/solutions/Solutions_S01_Implication_and_the_Universal_Quantifier.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Data.Real.Basic
3 |
4 | namespace C03S01
5 |
6 | theorem my_lemma4 :
7 | ∀ {x y ε : ℝ}, 0 < ε → ε ≤ 1 → |x| < ε → |y| < ε → |x * y| < ε := by
8 | intro x y ε epos ele1 xlt ylt
9 | calc
10 | |x * y| = |x| * |y| := by apply abs_mul
11 | _ ≤ |x| * ε := by apply mul_le_mul; linarith; linarith; apply abs_nonneg; apply abs_nonneg;
12 | _ < 1 * ε := by rw [mul_lt_mul_right epos]; linarith
13 | _ = ε := by apply one_mul
14 |
15 | def FnUb (f : ℝ → ℝ) (a : ℝ) : Prop :=
16 | ∀ x, f x ≤ a
17 |
18 | def FnLb (f : ℝ → ℝ) (a : ℝ) : Prop :=
19 | ∀ x, a ≤ f x
20 |
21 | section
22 | variable (f g : ℝ → ℝ) (a b : ℝ)
23 |
24 | example (hfa : FnLb f a) (hgb : FnLb g b) : FnLb (fun x ↦ f x + g x) (a + b) := by
25 | intro x
26 | apply add_le_add
27 | apply hfa
28 | apply hgb
29 |
30 | example (nnf : FnLb f 0) (nng : FnLb g 0) : FnLb (fun x ↦ f x * g x) 0 := by
31 | intro x
32 | apply mul_nonneg
33 | apply nnf
34 | apply nng
35 |
36 | example (hfa : FnUb f a) (hgb : FnUb g b) (nng : FnLb g 0) (nna : 0 ≤ a) :
37 | FnUb (fun x ↦ f x * g x) (a * b) := by
38 | intro x
39 | apply mul_le_mul
40 | apply hfa
41 | apply hgb
42 | apply nng
43 | apply nna
44 |
45 | end
46 |
47 | section
48 | variable (f g : ℝ → ℝ)
49 |
50 | example {c : ℝ} (mf : Monotone f) (nnc : 0 ≤ c) : Monotone fun x ↦ c * f x := by
51 | intro a b aleb
52 | apply mul_le_mul_of_nonneg_left _ nnc
53 | apply mf aleb
54 |
55 | example {c : ℝ} (mf : Monotone f) (nnc : 0 ≤ c) : Monotone fun x ↦ c * f x :=
56 | fun a b aleb ↦ mul_le_mul_of_nonneg_left (mf aleb) nnc
57 |
58 | example (mf : Monotone f) (mg : Monotone g) : Monotone fun x ↦ f (g x) := by
59 | intro a b aleb
60 | apply mf
61 | apply mg
62 | apply aleb
63 |
64 | example (mf : Monotone f) (mg : Monotone g) : Monotone fun x ↦ f (g x) :=
65 | fun a b aleb ↦ mf (mg aleb)
66 |
67 | def FnEven (f : ℝ → ℝ) : Prop :=
68 | ∀ x, f x = f (-x)
69 |
70 | def FnOdd (f : ℝ → ℝ) : Prop :=
71 | ∀ x, f x = -f (-x)
72 |
73 | example (of : FnOdd f) (og : FnOdd g) : FnEven fun x ↦ f x * g x := by
74 | intro x
75 | calc
76 | (fun x ↦ f x * g x) x = f x * g x := rfl
77 | _ = f (-x) * g (-x) := by rw [of, og, neg_mul_neg]
78 |
79 |
80 | example (ef : FnEven f) (og : FnOdd g) : FnOdd fun x ↦ f x * g x := by
81 | intro x
82 | dsimp
83 | rw [ef, og, neg_mul_eq_mul_neg]
84 |
85 | example (ef : FnEven f) (og : FnOdd g) : FnEven fun x ↦ f (g x) := by
86 | intro x
87 | dsimp
88 | rw [og, ← ef]
89 |
90 | end
91 |
92 | section
93 |
94 | variable {α : Type*} (r s t : Set α)
95 |
96 | example : r ⊆ s → s ⊆ t → r ⊆ t := by
97 | intro rsubs ssubt x xr
98 | apply ssubt
99 | apply rsubs
100 | apply xr
101 |
102 | theorem Subset.trans : r ⊆ s → s ⊆ t → r ⊆ t :=
103 | fun rsubs ssubt x xr ↦ ssubt (rsubs xr)
104 |
105 | end
106 |
107 | section
108 | variable {α : Type*} [PartialOrder α]
109 | variable (s : Set α) (a b : α)
110 |
111 | def SetUb (s : Set α) (a : α) :=
112 | ∀ x, x ∈ s → x ≤ a
113 |
114 | example (h : SetUb s a) (h' : a ≤ b) : SetUb s b := by
115 | intro x xs
116 | apply le_trans (h x xs) h'
117 |
118 | example (h : SetUb s a) (h' : a ≤ b) : SetUb s b :=
119 | fun x xs ↦ le_trans (h x xs) h'
120 |
121 | end
122 |
123 | section
124 |
125 | open Function
126 |
127 | example {c : ℝ} (h : c ≠ 0) : Injective fun x ↦ c * x := by
128 | intro x₁ x₂ h'
129 | apply (mul_right_inj' h).mp h'
130 |
131 | variable {α : Type*} {β : Type*} {γ : Type*}
132 | variable {g : β → γ} {f : α → β}
133 |
134 | example (injg : Injective g) (injf : Injective f) : Injective fun x ↦ g (f x) := by
135 | intro x₁ x₂ h
136 | apply injf
137 | apply injg
138 | apply h
139 |
140 | end
141 |
--------------------------------------------------------------------------------
/MIL/C10_Linear_Algebra/solutions/Solutions_S02_Subspaces.lean:
--------------------------------------------------------------------------------
1 | import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
2 | import Mathlib.LinearAlgebra.Eigenspace.Minpoly
3 | import Mathlib.LinearAlgebra.Charpoly.Basic
4 |
5 | import MIL.Common
6 |
7 |
8 | variable {K : Type*} [Field K] {V : Type*} [AddCommGroup V] [Module K V]
9 |
10 | example (U : Submodule K V) {x y : V} (hx : x ∈ U) (hy : y ∈ U) :
11 | x + y ∈ U :=
12 | U.add_mem hx hy
13 |
14 | example (U : Submodule K V) {x : V} (hx : x ∈ U) (a : K) :
15 | a • x ∈ U :=
16 | U.smul_mem a hx
17 |
18 |
19 | def preimage {W : Type*} [AddCommGroup W] [Module K W] (φ : V →ₗ[K] W) (H : Submodule K W) :
20 | Submodule K V where
21 | carrier := φ ⁻¹' H
22 | zero_mem' := by
23 | rw [Set.mem_preimage, map_zero]
24 | exact H.zero_mem
25 | add_mem' := by
26 | rintro a b ha hb
27 | rw [Set.mem_preimage, map_add]
28 | apply H.add_mem <;> assumption
29 | smul_mem' := by
30 | rintro a v hv
31 | rw [Set.mem_preimage, map_smul]
32 | exact H.smul_mem a hv
33 |
34 |
35 | example {S T : Submodule K V} {x : V} (h : x ∈ S ⊔ T) :
36 | ∃ s ∈ S, ∃ t ∈ T, x = s + t := by
37 | rw [← S.span_eq, ← T.span_eq, ← Submodule.span_union] at h
38 | induction h using Submodule.span_induction with
39 | | mem x h =>
40 | rcases h with (hx|hx)
41 | · use x, hx, 0, T.zero_mem
42 | module
43 | · use 0, S.zero_mem, x, hx
44 | module
45 | | zero =>
46 | use 0, S.zero_mem, 0, T.zero_mem
47 | module
48 | | add x y hx hy hx' hy' =>
49 | rcases hx' with ⟨s, hs, t, ht, rfl⟩
50 | rcases hy' with ⟨s', hs', t', ht', rfl⟩
51 | use s + s', S.add_mem hs hs', t + t', T.add_mem ht ht'
52 | module
53 | | smul a x hx hx' =>
54 | rcases hx' with ⟨s, hs, t, ht, rfl⟩
55 | use a • s, S.smul_mem a hs, a • t, T.smul_mem a ht
56 | module
57 |
58 |
59 | section
60 |
61 | variable {W : Type*} [AddCommGroup W] [Module K W] (φ : V →ₗ[K] W)
62 |
63 | variable (E : Submodule K V) in
64 | #check (Submodule.map φ E : Submodule K W)
65 |
66 | variable (F : Submodule K W) in
67 | #check (Submodule.comap φ F : Submodule K V)
68 |
69 |
70 | open Function LinearMap
71 |
72 | example : Injective φ ↔ ker φ = ⊥ := ker_eq_bot.symm
73 |
74 | example : Surjective φ ↔ range φ = ⊤ := range_eq_top.symm
75 |
76 | #check Submodule.mem_map_of_mem
77 | #check Submodule.mem_map
78 | #check Submodule.mem_comap
79 |
80 | example (E : Submodule K V) (F : Submodule K W) :
81 | Submodule.map φ E ≤ F ↔ E ≤ Submodule.comap φ F := by
82 | constructor
83 | · intro h x hx
84 | exact h ⟨x, hx, rfl⟩
85 | · rintro h - ⟨x, hx, rfl⟩
86 | exact h hx
87 |
88 |
89 | variable (E : Submodule K V)
90 |
91 | example : Module K (V ⧸ E) := inferInstance
92 |
93 | example : V →ₗ[K] V ⧸ E := E.mkQ
94 |
95 | example : ker E.mkQ = E := E.ker_mkQ
96 |
97 | example : range E.mkQ = ⊤ := E.range_mkQ
98 |
99 | example (hφ : E ≤ ker φ) : V ⧸ E →ₗ[K] W := E.liftQ φ hφ
100 |
101 | example (F : Submodule K W) (hφ : E ≤ .comap φ F) : V ⧸ E →ₗ[K] W ⧸ F := E.mapQ F φ hφ
102 |
103 | noncomputable example : (V ⧸ LinearMap.ker φ) ≃ₗ[K] range φ := φ.quotKerEquivRange
104 |
105 |
106 | open Submodule
107 |
108 | #check Submodule.map_comap_eq
109 | #check Submodule.comap_map_eq
110 |
111 | example : Submodule K (V ⧸ E) ≃ { F : Submodule K V // E ≤ F } where
112 | toFun F := ⟨comap E.mkQ F, by
113 | conv_lhs => rw [← E.ker_mkQ, ← comap_bot]
114 | gcongr
115 | apply bot_le⟩
116 | invFun P := map E.mkQ P
117 | left_inv P := by
118 | dsimp
119 | rw [Submodule.map_comap_eq, E.range_mkQ]
120 | exact top_inf_eq P
121 | right_inv := by
122 | intro P
123 | ext x
124 | dsimp only
125 | rw [Submodule.comap_map_eq, E.ker_mkQ, sup_of_le_left]
126 | exact P.2
127 |
--------------------------------------------------------------------------------
/MIL/C02_Basics/S02_Proving_Identities_in_Algebraic_Structures.lean:
--------------------------------------------------------------------------------
1 | import Mathlib.Algebra.Ring.Defs
2 | import Mathlib.Data.Real.Basic
3 | import MIL.Common
4 |
5 | section
6 | variable (R : Type*) [Ring R]
7 |
8 | #check (add_assoc : ∀ a b c : R, a + b + c = a + (b + c))
9 | #check (add_comm : ∀ a b : R, a + b = b + a)
10 | #check (zero_add : ∀ a : R, 0 + a = a)
11 | #check (neg_add_cancel : ∀ a : R, -a + a = 0)
12 | #check (mul_assoc : ∀ a b c : R, a * b * c = a * (b * c))
13 | #check (mul_one : ∀ a : R, a * 1 = a)
14 | #check (one_mul : ∀ a : R, 1 * a = a)
15 | #check (mul_add : ∀ a b c : R, a * (b + c) = a * b + a * c)
16 | #check (add_mul : ∀ a b c : R, (a + b) * c = a * c + b * c)
17 |
18 | end
19 |
20 | section
21 | variable (R : Type*) [CommRing R]
22 | variable (a b c d : R)
23 |
24 | example : c * b * a = b * (a * c) := by ring
25 |
26 | example : (a + b) * (a + b) = a * a + 2 * (a * b) + b * b := by ring
27 |
28 | example : (a + b) * (a - b) = a ^ 2 - b ^ 2 := by ring
29 |
30 | example (hyp : c = d * a + b) (hyp' : b = a * d) : c = 2 * a * d := by
31 | rw [hyp, hyp']
32 | ring
33 |
34 | end
35 |
36 | namespace MyRing
37 | variable {R : Type*} [Ring R]
38 |
39 | theorem add_zero (a : R) : a + 0 = a := by rw [add_comm, zero_add]
40 |
41 | theorem add_neg_cancel (a : R) : a + -a = 0 := by rw [add_comm, neg_add_cancel]
42 |
43 | #check MyRing.add_zero
44 | #check add_zero
45 |
46 | end MyRing
47 |
48 | namespace MyRing
49 | variable {R : Type*} [Ring R]
50 |
51 | theorem neg_add_cancel_left (a b : R) : -a + (a + b) = b := by
52 | rw [← add_assoc, neg_add_cancel, zero_add]
53 |
54 | -- Prove these:
55 | theorem add_neg_cancel_right (a b : R) : a + b + -b = a := by
56 | sorry
57 |
58 | theorem add_left_cancel {a b c : R} (h : a + b = a + c) : b = c := by
59 | sorry
60 |
61 | theorem add_right_cancel {a b c : R} (h : a + b = c + b) : a = c := by
62 | sorry
63 |
64 | theorem mul_zero (a : R) : a * 0 = 0 := by
65 | have h : a * 0 + a * 0 = a * 0 + 0 := by
66 | rw [← mul_add, add_zero, add_zero]
67 | rw [add_left_cancel h]
68 |
69 | theorem zero_mul (a : R) : 0 * a = 0 := by
70 | sorry
71 |
72 | theorem neg_eq_of_add_eq_zero {a b : R} (h : a + b = 0) : -a = b := by
73 | sorry
74 |
75 | theorem eq_neg_of_add_eq_zero {a b : R} (h : a + b = 0) : a = -b := by
76 | sorry
77 |
78 | theorem neg_zero : (-0 : R) = 0 := by
79 | apply neg_eq_of_add_eq_zero
80 | rw [add_zero]
81 |
82 | theorem neg_neg (a : R) : - -a = a := by
83 | sorry
84 |
85 | end MyRing
86 |
87 | -- Examples.
88 | section
89 | variable {R : Type*} [Ring R]
90 |
91 | example (a b : R) : a - b = a + -b :=
92 | sub_eq_add_neg a b
93 |
94 | end
95 |
96 | example (a b : ℝ) : a - b = a + -b :=
97 | rfl
98 |
99 | example (a b : ℝ) : a - b = a + -b := by
100 | rfl
101 |
102 | namespace MyRing
103 | variable {R : Type*} [Ring R]
104 |
105 | theorem self_sub (a : R) : a - a = 0 := by
106 | sorry
107 |
108 | theorem one_add_one_eq_two : 1 + 1 = (2 : R) := by
109 | norm_num
110 |
111 | theorem two_mul (a : R) : 2 * a = a + a := by
112 | sorry
113 |
114 | end MyRing
115 |
116 | section
117 | variable (A : Type*) [AddGroup A]
118 |
119 | #check (add_assoc : ∀ a b c : A, a + b + c = a + (b + c))
120 | #check (zero_add : ∀ a : A, 0 + a = a)
121 | #check (neg_add_cancel : ∀ a : A, -a + a = 0)
122 |
123 | end
124 |
125 | section
126 | variable {G : Type*} [Group G]
127 |
128 | #check (mul_assoc : ∀ a b c : G, a * b * c = a * (b * c))
129 | #check (one_mul : ∀ a : G, 1 * a = a)
130 | #check (inv_mul_cancel : ∀ a : G, a⁻¹ * a = 1)
131 |
132 | namespace MyGroup
133 |
134 | theorem mul_inv_cancel (a : G) : a * a⁻¹ = 1 := by
135 | sorry
136 |
137 | theorem mul_one (a : G) : a * 1 = a := by
138 | sorry
139 |
140 | theorem mul_inv_rev (a b : G) : (a * b)⁻¹ = b⁻¹ * a⁻¹ := by
141 | sorry
142 |
143 | end MyGroup
144 |
145 | end
146 |
147 |
--------------------------------------------------------------------------------
/MIL/C03_Logic/solutions/Solutions_S05_Disjunction.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Data.Real.Basic
3 |
4 | namespace C03S05
5 |
6 | section
7 |
8 | variable {x y : ℝ}
9 |
10 | namespace MyAbs
11 |
12 | theorem le_abs_self (x : ℝ) : x ≤ |x| := by
13 | rcases le_or_gt 0 x with h | h
14 | · rw [abs_of_nonneg h]
15 | · rw [abs_of_neg h]
16 | linarith
17 |
18 | theorem neg_le_abs_self (x : ℝ) : -x ≤ |x| := by
19 | rcases le_or_gt 0 x with h | h
20 | · rw [abs_of_nonneg h]
21 | linarith
22 | · rw [abs_of_neg h]
23 |
24 | theorem abs_add (x y : ℝ) : |x + y| ≤ |x| + |y| := by
25 | rcases le_or_gt 0 (x + y) with h | h
26 | · rw [abs_of_nonneg h]
27 | linarith [le_abs_self x, le_abs_self y]
28 | · rw [abs_of_neg h]
29 | linarith [neg_le_abs_self x, neg_le_abs_self y]
30 |
31 | theorem lt_abs : x < |y| ↔ x < y ∨ x < -y := by
32 | rcases le_or_gt 0 y with h | h
33 | · rw [abs_of_nonneg h]
34 | constructor
35 | · intro h'
36 | left
37 | exact h'
38 | · intro h'
39 | rcases h' with h' | h'
40 | · exact h'
41 | · linarith
42 | rw [abs_of_neg h]
43 | constructor
44 | · intro h'
45 | right
46 | exact h'
47 | · intro h'
48 | rcases h' with h' | h'
49 | · linarith
50 | · exact h'
51 |
52 | theorem abs_lt : |x| < y ↔ -y < x ∧ x < y := by
53 | rcases le_or_gt 0 x with h | h
54 | · rw [abs_of_nonneg h]
55 | constructor
56 | · intro h'
57 | constructor
58 | · linarith
59 | exact h'
60 | · intro h'
61 | rcases h' with ⟨h1, h2⟩
62 | exact h2
63 | · rw [abs_of_neg h]
64 | constructor
65 | · intro h'
66 | constructor
67 | · linarith
68 | · linarith
69 | · intro h'
70 | linarith
71 |
72 | end MyAbs
73 |
74 | end
75 |
76 | example {z : ℝ} (h : ∃ x y, z = x ^ 2 + y ^ 2 ∨ z = x ^ 2 + y ^ 2 + 1) : z ≥ 0 := by
77 | rcases h with ⟨x, y, rfl | rfl⟩ <;> linarith [sq_nonneg x, sq_nonneg y]
78 |
79 | example {x : ℝ} (h : x ^ 2 = 1) : x = 1 ∨ x = -1 := by
80 | have h' : x ^ 2 - 1 = 0 := by rw [h, sub_self]
81 | have h'' : (x + 1) * (x - 1) = 0 := by
82 | rw [← h']
83 | ring
84 | rcases eq_zero_or_eq_zero_of_mul_eq_zero h'' with h1 | h1
85 | · right
86 | exact eq_neg_iff_add_eq_zero.mpr h1
87 | · left
88 | exact eq_of_sub_eq_zero h1
89 |
90 | example {x y : ℝ} (h : x ^ 2 = y ^ 2) : x = y ∨ x = -y := by
91 | have h' : x ^ 2 - y ^ 2 = 0 := by rw [h, sub_self]
92 | have h'' : (x + y) * (x - y) = 0 := by
93 | rw [← h']
94 | ring
95 | rcases eq_zero_or_eq_zero_of_mul_eq_zero h'' with h1 | h1
96 | · right
97 | exact eq_neg_iff_add_eq_zero.mpr h1
98 | · left
99 | exact eq_of_sub_eq_zero h1
100 |
101 | section
102 | variable {R : Type*} [CommRing R] [IsDomain R]
103 | variable (x y : R)
104 |
105 | example (h : x ^ 2 = 1) : x = 1 ∨ x = -1 := by
106 | have h' : x ^ 2 - 1 = 0 := by rw [h, sub_self]
107 | have h'' : (x + 1) * (x - 1) = 0 := by
108 | rw [← h']
109 | ring
110 | rcases eq_zero_or_eq_zero_of_mul_eq_zero h'' with h1 | h1
111 | · right
112 | exact eq_neg_iff_add_eq_zero.mpr h1
113 | · left
114 | exact eq_of_sub_eq_zero h1
115 |
116 | example (h : x ^ 2 = y ^ 2) : x = y ∨ x = -y := by
117 | have h' : x ^ 2 - y ^ 2 = 0 := by rw [h, sub_self]
118 | have h'' : (x + y) * (x - y) = 0 := by
119 | rw [← h']
120 | ring
121 | rcases eq_zero_or_eq_zero_of_mul_eq_zero h'' with h1 | h1
122 | · right
123 | exact eq_neg_iff_add_eq_zero.mpr h1
124 | · left
125 | exact eq_of_sub_eq_zero h1
126 |
127 | end
128 |
129 | example (P Q : Prop) : P → Q ↔ ¬P ∨ Q := by
130 | constructor
131 | · intro h
132 | by_cases h' : P
133 | · right
134 | exact h h'
135 | · left
136 | exact h'
137 | rintro (h | h)
138 | · intro h'
139 | exact absurd h' h
140 | · intro
141 | exact h
142 |
--------------------------------------------------------------------------------
/MIL/C05_Elementary_Number_Theory/solutions/Solutions_S01_Irrational_Roots.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Data.Nat.Factorization.Basic
3 | import Mathlib.Data.Nat.Prime.Basic
4 |
5 | theorem even_of_even_sqr {m : ℕ} (h : 2 ∣ m ^ 2) : 2 ∣ m := by
6 | rw [pow_two, Nat.prime_two.dvd_mul] at h
7 | cases h <;> assumption
8 |
9 | example {m n : ℕ} (coprime_mn : m.Coprime n) : m ^ 2 ≠ 2 * n ^ 2 := by
10 | intro sqr_eq
11 | have : 2 ∣ m := by
12 | apply even_of_even_sqr
13 | rw [sqr_eq]
14 | apply dvd_mul_right
15 | obtain ⟨k, meq⟩ := dvd_iff_exists_eq_mul_left.mp this
16 | have : 2 * (2 * k ^ 2) = 2 * n ^ 2 := by
17 | rw [← sqr_eq, meq]
18 | ring
19 | have : 2 * k ^ 2 = n ^ 2 :=
20 | (mul_right_inj' (by norm_num)).mp this
21 | have : 2 ∣ n := by
22 | apply even_of_even_sqr
23 | rw [← this]
24 | apply dvd_mul_right
25 | have : 2 ∣ m.gcd n := by
26 | apply Nat.dvd_gcd <;>
27 | assumption
28 | have : 2 ∣ 1 := by
29 | convert this
30 | symm
31 | exact coprime_mn
32 | norm_num at this
33 |
34 | example {m n p : ℕ} (coprime_mn : m.Coprime n) (prime_p : p.Prime) : m ^ 2 ≠ p * n ^ 2 := by
35 | intro sqr_eq
36 | have : p ∣ m := by
37 | apply prime_p.dvd_of_dvd_pow
38 | rw [sqr_eq]
39 | apply dvd_mul_right
40 | obtain ⟨k, meq⟩ := dvd_iff_exists_eq_mul_left.mp this
41 | have : p * (p * k ^ 2) = p * n ^ 2 := by
42 | rw [← sqr_eq, meq]
43 | ring
44 | have : p * k ^ 2 = n ^ 2 := by
45 | apply (mul_right_inj' _).mp this
46 | exact prime_p.ne_zero
47 | have : p ∣ n := by
48 | apply prime_p.dvd_of_dvd_pow
49 | rw [← this]
50 | apply dvd_mul_right
51 | have : p ∣ Nat.gcd m n := by apply Nat.dvd_gcd <;> assumption
52 | have : p ∣ 1 := by
53 | convert this
54 | symm
55 | exact coprime_mn
56 | have : 2 ≤ 1 := by
57 | apply prime_p.two_le.trans
58 | exact Nat.le_of_dvd zero_lt_one this
59 | norm_num at this
60 |
61 | theorem factorization_mul' {m n : ℕ} (mnez : m ≠ 0) (nnez : n ≠ 0) (p : ℕ) :
62 | (m * n).factorization p = m.factorization p + n.factorization p := by
63 | rw [Nat.factorization_mul mnez nnez]
64 | rfl
65 |
66 | theorem factorization_pow' (n k p : ℕ) :
67 | (n ^ k).factorization p = k * n.factorization p := by
68 | rw [Nat.factorization_pow]
69 | rfl
70 |
71 | theorem Nat.Prime.factorization' {p : ℕ} (prime_p : p.Prime) :
72 | p.factorization p = 1 := by
73 | rw [prime_p.factorization]
74 | simp
75 |
76 | example {m n p : ℕ} (nnz : n ≠ 0) (prime_p : p.Prime) : m ^ 2 ≠ p * n ^ 2 := by
77 | intro sqr_eq
78 | have nsqr_nez : n ^ 2 ≠ 0 := by simpa
79 | have eq1 : Nat.factorization (m ^ 2) p = 2 * m.factorization p := by
80 | rw [factorization_pow']
81 | have eq2 : (p * n ^ 2).factorization p = 2 * n.factorization p + 1 := by
82 | rw [factorization_mul' prime_p.ne_zero nsqr_nez, prime_p.factorization', factorization_pow',
83 | add_comm]
84 | have : 2 * m.factorization p % 2 = (2 * n.factorization p + 1) % 2 := by
85 | rw [← eq1, sqr_eq, eq2]
86 | rw [add_comm, Nat.add_mul_mod_self_left, Nat.mul_mod_right] at this
87 | norm_num at this
88 |
89 | example {m n k r : ℕ} (nnz : n ≠ 0) (pow_eq : m ^ k = r * n ^ k) {p : ℕ} :
90 | k ∣ r.factorization p := by
91 | rcases r with _ | r
92 | · simp
93 | have npow_nz : n ^ k ≠ 0 := fun npowz ↦ nnz (pow_eq_zero npowz)
94 | have eq1 : (m ^ k).factorization p = k * m.factorization p := by
95 | rw [factorization_pow']
96 | have eq2 : ((r + 1) * n ^ k).factorization p =
97 | k * n.factorization p + (r + 1).factorization p := by
98 | rw [factorization_mul' r.succ_ne_zero npow_nz, factorization_pow', add_comm]
99 | have : r.succ.factorization p = k * m.factorization p - k * n.factorization p := by
100 | rw [← eq1, pow_eq, eq2, add_comm, Nat.add_sub_cancel]
101 | rw [this]
102 | apply Nat.dvd_sub <;>
103 | apply Nat.dvd_mul_right
104 |
105 |
--------------------------------------------------------------------------------
/MIL/C02_Basics/S03_Using_Theorems_and_Lemmas.lean:
--------------------------------------------------------------------------------
1 | import Mathlib.Analysis.SpecialFunctions.Log.Basic
2 | import MIL.Common
3 |
4 | variable (a b c d e : ℝ)
5 | open Real
6 |
7 | #check (le_refl : ∀ a : ℝ, a ≤ a)
8 | #check (le_trans : a ≤ b → b ≤ c → a ≤ c)
9 |
10 | section
11 | variable (h : a ≤ b) (h' : b ≤ c)
12 |
13 | #check (le_refl : ∀ a : Real, a ≤ a)
14 | #check (le_refl a : a ≤ a)
15 | #check (le_trans : a ≤ b → b ≤ c → a ≤ c)
16 | #check (le_trans h : b ≤ c → a ≤ c)
17 | #check (le_trans h h' : a ≤ c)
18 |
19 | end
20 |
21 | example (x y z : ℝ) (h₀ : x ≤ y) (h₁ : y ≤ z) : x ≤ z := by
22 | apply le_trans
23 | · apply h₀
24 | · apply h₁
25 |
26 | example (x y z : ℝ) (h₀ : x ≤ y) (h₁ : y ≤ z) : x ≤ z := by
27 | apply le_trans h₀
28 | apply h₁
29 |
30 | example (x y z : ℝ) (h₀ : x ≤ y) (h₁ : y ≤ z) : x ≤ z :=
31 | le_trans h₀ h₁
32 |
33 | example (x : ℝ) : x ≤ x := by
34 | apply le_refl
35 |
36 | example (x : ℝ) : x ≤ x :=
37 | le_refl x
38 |
39 | #check (le_refl : ∀ a, a ≤ a)
40 | #check (le_trans : a ≤ b → b ≤ c → a ≤ c)
41 | #check (lt_of_le_of_lt : a ≤ b → b < c → a < c)
42 | #check (lt_of_lt_of_le : a < b → b ≤ c → a < c)
43 | #check (lt_trans : a < b → b < c → a < c)
44 |
45 | -- Try this.
46 | example (h₀ : a ≤ b) (h₁ : b < c) (h₂ : c ≤ d) (h₃ : d < e) : a < e := by
47 | sorry
48 |
49 | example (h₀ : a ≤ b) (h₁ : b < c) (h₂ : c ≤ d) (h₃ : d < e) : a < e := by
50 | linarith
51 |
52 | section
53 |
54 | example (h : 2 * a ≤ 3 * b) (h' : 1 ≤ a) (h'' : d = 2) : d + a ≤ 5 * b := by
55 | linarith
56 |
57 | end
58 |
59 | example (h : 1 ≤ a) (h' : b ≤ c) : 2 + a + exp b ≤ 3 * a + exp c := by
60 | linarith [exp_le_exp.mpr h']
61 |
62 | #check (exp_le_exp : exp a ≤ exp b ↔ a ≤ b)
63 | #check (exp_lt_exp : exp a < exp b ↔ a < b)
64 | #check (log_le_log : 0 < a → a ≤ b → log a ≤ log b)
65 | #check (log_lt_log : 0 < a → a < b → log a < log b)
66 | #check (add_le_add : a ≤ b → c ≤ d → a + c ≤ b + d)
67 | #check (add_le_add_left : a ≤ b → ∀ c, c + a ≤ c + b)
68 | #check (add_le_add_right : a ≤ b → ∀ c, a + c ≤ b + c)
69 | #check (add_lt_add_of_le_of_lt : a ≤ b → c < d → a + c < b + d)
70 | #check (add_lt_add_of_lt_of_le : a < b → c ≤ d → a + c < b + d)
71 | #check (add_lt_add_left : a < b → ∀ c, c + a < c + b)
72 | #check (add_lt_add_right : a < b → ∀ c, a + c < b + c)
73 | #check (add_nonneg : 0 ≤ a → 0 ≤ b → 0 ≤ a + b)
74 | #check (add_pos : 0 < a → 0 < b → 0 < a + b)
75 | #check (add_pos_of_pos_of_nonneg : 0 < a → 0 ≤ b → 0 < a + b)
76 | #check (exp_pos : ∀ a, 0 < exp a)
77 | #check add_le_add_left
78 |
79 | example (h : a ≤ b) : exp a ≤ exp b := by
80 | rw [exp_le_exp]
81 | exact h
82 |
83 | example (h₀ : a ≤ b) (h₁ : c < d) : a + exp c + e < b + exp d + e := by
84 | apply add_lt_add_of_lt_of_le
85 | · apply add_lt_add_of_le_of_lt h₀
86 | apply exp_lt_exp.mpr h₁
87 | apply le_refl
88 |
89 | example (h₀ : d ≤ e) : c + exp (a + d) ≤ c + exp (a + e) := by sorry
90 |
91 | example : (0 : ℝ) < 1 := by norm_num
92 |
93 | example (h : a ≤ b) : log (1 + exp a) ≤ log (1 + exp b) := by
94 | have h₀ : 0 < 1 + exp a := by sorry
95 | apply log_le_log h₀
96 | sorry
97 |
98 | example : 0 ≤ a ^ 2 := by
99 | -- apply?
100 | exact sq_nonneg a
101 |
102 | example (h : a ≤ b) : c - exp b ≤ c - exp a := by
103 | sorry
104 |
105 | example : 2*a*b ≤ a^2 + b^2 := by
106 | have h : 0 ≤ a^2 - 2*a*b + b^2
107 | calc
108 | a^2 - 2*a*b + b^2 = (a - b)^2 := by ring
109 | _ ≥ 0 := by apply pow_two_nonneg
110 |
111 | calc
112 | 2*a*b = 2*a*b + 0 := by ring
113 | _ ≤ 2*a*b + (a^2 - 2*a*b + b^2) := add_le_add (le_refl _) h
114 | _ = a^2 + b^2 := by ring
115 |
116 | example : 2*a*b ≤ a^2 + b^2 := by
117 | have h : 0 ≤ a^2 - 2*a*b + b^2
118 | calc
119 | a^2 - 2*a*b + b^2 = (a - b)^2 := by ring
120 | _ ≥ 0 := by apply pow_two_nonneg
121 | linarith
122 |
123 | example : |a*b| ≤ (a^2 + b^2)/2 := by
124 | sorry
125 |
126 | #check abs_le'.mpr
127 |
128 |
--------------------------------------------------------------------------------
/MIL/C02_Basics/S01_Calculating.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Data.Real.Basic
3 | -- An example.
4 | example (a b c : ℝ) : a * b * c = b * (a * c) := by
5 | rw [mul_comm a b]
6 | rw [mul_assoc b a c]
7 |
8 | -- Try these.
9 | example (a b c : ℝ) : c * b * a = b * (a * c) := by
10 | sorry
11 |
12 | example (a b c : ℝ) : a * (b * c) = b * (a * c) := by
13 | sorry
14 |
15 | -- An example.
16 | example (a b c : ℝ) : a * b * c = b * c * a := by
17 | rw [mul_assoc]
18 | rw [mul_comm]
19 |
20 | /- Try doing the first of these without providing any arguments at all,
21 | and the second with only one argument. -/
22 | example (a b c : ℝ) : a * (b * c) = b * (c * a) := by
23 | sorry
24 |
25 | example (a b c : ℝ) : a * (b * c) = b * (a * c) := by
26 | sorry
27 |
28 | -- Using facts from the local context.
29 | example (a b c d e f : ℝ) (h : a * b = c * d) (h' : e = f) : a * (b * e) = c * (d * f) := by
30 | rw [h']
31 | rw [← mul_assoc]
32 | rw [h]
33 | rw [mul_assoc]
34 |
35 | example (a b c d e f : ℝ) (h : b * c = e * f) : a * b * c * d = a * e * f * d := by
36 | sorry
37 |
38 | example (a b c d : ℝ) (hyp : c = b * a - d) (hyp' : d = a * b) : c = 0 := by
39 | sorry
40 |
41 | example (a b c d e f : ℝ) (h : a * b = c * d) (h' : e = f) : a * (b * e) = c * (d * f) := by
42 | rw [h', ← mul_assoc, h, mul_assoc]
43 |
44 | section
45 |
46 | variable (a b c d e f : ℝ)
47 |
48 | example (h : a * b = c * d) (h' : e = f) : a * (b * e) = c * (d * f) := by
49 | rw [h', ← mul_assoc, h, mul_assoc]
50 |
51 | end
52 |
53 | section
54 | variable (a b c : ℝ)
55 |
56 | #check a
57 | #check a + b
58 | #check (a : ℝ)
59 | #check mul_comm a b
60 | #check (mul_comm a b : a * b = b * a)
61 | #check mul_assoc c a b
62 | #check mul_comm a
63 | #check mul_comm
64 |
65 | end
66 |
67 | section
68 | variable (a b : ℝ)
69 |
70 | example : (a + b) * (a + b) = a * a + 2 * (a * b) + b * b := by
71 | rw [mul_add, add_mul, add_mul]
72 | rw [← add_assoc, add_assoc (a * a)]
73 | rw [mul_comm b a, ← two_mul]
74 |
75 | example : (a + b) * (a + b) = a * a + 2 * (a * b) + b * b :=
76 | calc
77 | (a + b) * (a + b) = a * a + b * a + (a * b + b * b) := by
78 | rw [mul_add, add_mul, add_mul]
79 | _ = a * a + (b * a + a * b) + b * b := by
80 | rw [← add_assoc, add_assoc (a * a)]
81 | _ = a * a + 2 * (a * b) + b * b := by
82 | rw [mul_comm b a, ← two_mul]
83 |
84 | example : (a + b) * (a + b) = a * a + 2 * (a * b) + b * b :=
85 | calc
86 | (a + b) * (a + b) = a * a + b * a + (a * b + b * b) := by
87 | sorry
88 | _ = a * a + (b * a + a * b) + b * b := by
89 | sorry
90 | _ = a * a + 2 * (a * b) + b * b := by
91 | sorry
92 |
93 | end
94 |
95 | -- Try these. For the second, use the theorems listed underneath.
96 | section
97 | variable (a b c d : ℝ)
98 |
99 | example : (a + b) * (c + d) = a * c + a * d + b * c + b * d := by
100 | sorry
101 |
102 | example (a b : ℝ) : (a + b) * (a - b) = a ^ 2 - b ^ 2 := by
103 | sorry
104 |
105 | #check pow_two a
106 | #check mul_sub a b c
107 | #check add_mul a b c
108 | #check add_sub a b c
109 | #check sub_sub a b c
110 | #check add_zero a
111 |
112 | end
113 |
114 | -- Examples.
115 |
116 | section
117 | variable (a b c d : ℝ)
118 |
119 | example (a b c d : ℝ) (hyp : c = d * a + b) (hyp' : b = a * d) : c = 2 * a * d := by
120 | rw [hyp'] at hyp
121 | rw [mul_comm d a] at hyp
122 | rw [← two_mul (a * d)] at hyp
123 | rw [← mul_assoc 2 a d] at hyp
124 | exact hyp
125 |
126 | example : c * b * a = b * (a * c) := by
127 | ring
128 |
129 | example : (a + b) * (a + b) = a * a + 2 * (a * b) + b * b := by
130 | ring
131 |
132 | example : (a + b) * (a - b) = a ^ 2 - b ^ 2 := by
133 | ring
134 |
135 | example (hyp : c = d * a + b) (hyp' : b = a * d) : c = 2 * a * d := by
136 | rw [hyp, hyp']
137 | ring
138 |
139 | end
140 |
141 | example (a b c : ℕ) (h : a + b = c) : (a + b) * (a + b) = a * c + b * c := by
142 | nth_rw 2 [h]
143 | rw [add_mul]
144 |
--------------------------------------------------------------------------------
/MIL/C05_Elementary_Number_Theory/S01_Irrational_Roots.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Data.Nat.Factorization.Basic
3 | import Mathlib.Data.Nat.Prime.Basic
4 |
5 | #print Nat.Coprime
6 |
7 | example (m n : Nat) (h : m.Coprime n) : m.gcd n = 1 :=
8 | h
9 |
10 | example (m n : Nat) (h : m.Coprime n) : m.gcd n = 1 := by
11 | rw [Nat.Coprime] at h
12 | exact h
13 |
14 | example : Nat.Coprime 12 7 := by norm_num
15 |
16 | example : Nat.gcd 12 8 = 4 := by norm_num
17 |
18 | #check Nat.prime_def_lt
19 |
20 | example (p : ℕ) (prime_p : Nat.Prime p) : 2 ≤ p ∧ ∀ m : ℕ, m < p → m ∣ p → m = 1 := by
21 | rwa [Nat.prime_def_lt] at prime_p
22 |
23 | #check Nat.Prime.eq_one_or_self_of_dvd
24 |
25 | example (p : ℕ) (prime_p : Nat.Prime p) : ∀ m : ℕ, m ∣ p → m = 1 ∨ m = p :=
26 | prime_p.eq_one_or_self_of_dvd
27 |
28 | example : Nat.Prime 17 := by norm_num
29 |
30 | -- commonly used
31 | example : Nat.Prime 2 :=
32 | Nat.prime_two
33 |
34 | example : Nat.Prime 3 :=
35 | Nat.prime_three
36 |
37 | #check Nat.Prime.dvd_mul
38 | #check Nat.Prime.dvd_mul Nat.prime_two
39 | #check Nat.prime_two.dvd_mul
40 |
41 | theorem even_of_even_sqr {m : ℕ} (h : 2 ∣ m ^ 2) : 2 ∣ m := by
42 | rw [pow_two, Nat.prime_two.dvd_mul] at h
43 | cases h <;> assumption
44 |
45 | example {m : ℕ} (h : 2 ∣ m ^ 2) : 2 ∣ m :=
46 | Nat.Prime.dvd_of_dvd_pow Nat.prime_two h
47 |
48 | example (a b c : Nat) (h : a * b = a * c) (h' : a ≠ 0) : b = c :=
49 | -- apply? suggests the following:
50 | (mul_right_inj' h').mp h
51 |
52 | example {m n : ℕ} (coprime_mn : m.Coprime n) : m ^ 2 ≠ 2 * n ^ 2 := by
53 | intro sqr_eq
54 | have : 2 ∣ m := by
55 | sorry
56 | obtain ⟨k, meq⟩ := dvd_iff_exists_eq_mul_left.mp this
57 | have : 2 * (2 * k ^ 2) = 2 * n ^ 2 := by
58 | rw [← sqr_eq, meq]
59 | ring
60 | have : 2 * k ^ 2 = n ^ 2 :=
61 | sorry
62 | have : 2 ∣ n := by
63 | sorry
64 | have : 2 ∣ m.gcd n := by
65 | sorry
66 | have : 2 ∣ 1 := by
67 | sorry
68 | norm_num at this
69 |
70 | example {m n p : ℕ} (coprime_mn : m.Coprime n) (prime_p : p.Prime) : m ^ 2 ≠ p * n ^ 2 := by
71 | sorry
72 | #check Nat.primeFactorsList
73 | #check Nat.prime_of_mem_primeFactorsList
74 | #check Nat.prod_primeFactorsList
75 | #check Nat.primeFactorsList_unique
76 |
77 | theorem factorization_mul' {m n : ℕ} (mnez : m ≠ 0) (nnez : n ≠ 0) (p : ℕ) :
78 | (m * n).factorization p = m.factorization p + n.factorization p := by
79 | rw [Nat.factorization_mul mnez nnez]
80 | rfl
81 |
82 | theorem factorization_pow' (n k p : ℕ) :
83 | (n ^ k).factorization p = k * n.factorization p := by
84 | rw [Nat.factorization_pow]
85 | rfl
86 |
87 | theorem Nat.Prime.factorization' {p : ℕ} (prime_p : p.Prime) :
88 | p.factorization p = 1 := by
89 | rw [prime_p.factorization]
90 | simp
91 |
92 | example {m n p : ℕ} (nnz : n ≠ 0) (prime_p : p.Prime) : m ^ 2 ≠ p * n ^ 2 := by
93 | intro sqr_eq
94 | have nsqr_nez : n ^ 2 ≠ 0 := by simpa
95 | have eq1 : Nat.factorization (m ^ 2) p = 2 * m.factorization p := by
96 | sorry
97 | have eq2 : (p * n ^ 2).factorization p = 2 * n.factorization p + 1 := by
98 | sorry
99 | have : 2 * m.factorization p % 2 = (2 * n.factorization p + 1) % 2 := by
100 | rw [← eq1, sqr_eq, eq2]
101 | rw [add_comm, Nat.add_mul_mod_self_left, Nat.mul_mod_right] at this
102 | norm_num at this
103 |
104 | example {m n k r : ℕ} (nnz : n ≠ 0) (pow_eq : m ^ k = r * n ^ k) {p : ℕ} :
105 | k ∣ r.factorization p := by
106 | rcases r with _ | r
107 | · simp
108 | have npow_nz : n ^ k ≠ 0 := fun npowz ↦ nnz (pow_eq_zero npowz)
109 | have eq1 : (m ^ k).factorization p = k * m.factorization p := by
110 | sorry
111 | have eq2 : ((r + 1) * n ^ k).factorization p =
112 | k * n.factorization p + (r + 1).factorization p := by
113 | sorry
114 | have : r.succ.factorization p = k * m.factorization p - k * n.factorization p := by
115 | rw [← eq1, pow_eq, eq2, add_comm, Nat.add_sub_cancel]
116 | rw [this]
117 | sorry
118 |
119 | #check multiplicity
120 |
121 |
--------------------------------------------------------------------------------
/MIL/C05_Elementary_Number_Theory/S02_Induction_and_Recursion.lean:
--------------------------------------------------------------------------------
1 | import Mathlib.Data.Nat.GCD.Basic
2 | import MIL.Common
3 |
4 | example (n : Nat) : n.succ ≠ Nat.zero :=
5 | Nat.succ_ne_zero n
6 |
7 | example (m n : Nat) (h : m.succ = n.succ) : m = n :=
8 | Nat.succ.inj h
9 |
10 | def fac : ℕ → ℕ
11 | | 0 => 1
12 | | n + 1 => (n + 1) * fac n
13 |
14 | example : fac 0 = 1 :=
15 | rfl
16 |
17 | example : fac 0 = 1 := by
18 | rw [fac]
19 |
20 | example : fac 0 = 1 := by
21 | simp [fac]
22 |
23 | example (n : ℕ) : fac (n + 1) = (n + 1) * fac n :=
24 | rfl
25 |
26 | example (n : ℕ) : fac (n + 1) = (n + 1) * fac n := by
27 | rw [fac]
28 |
29 | example (n : ℕ) : fac (n + 1) = (n + 1) * fac n := by
30 | simp [fac]
31 |
32 | theorem fac_pos (n : ℕ) : 0 < fac n := by
33 | induction' n with n ih
34 | · rw [fac]
35 | exact zero_lt_one
36 | rw [fac]
37 | exact mul_pos n.succ_pos ih
38 |
39 | theorem dvd_fac {i n : ℕ} (ipos : 0 < i) (ile : i ≤ n) : i ∣ fac n := by
40 | induction' n with n ih
41 | · exact absurd ipos (not_lt_of_ge ile)
42 | rw [fac]
43 | rcases Nat.of_le_succ ile with h | h
44 | · apply dvd_mul_of_dvd_right (ih h)
45 | rw [h]
46 | apply dvd_mul_right
47 |
48 | theorem pow_two_le_fac (n : ℕ) : 2 ^ (n - 1) ≤ fac n := by
49 | rcases n with _ | n
50 | · simp [fac]
51 | sorry
52 | section
53 |
54 | variable {α : Type*} (s : Finset ℕ) (f : ℕ → ℕ) (n : ℕ)
55 |
56 | #check Finset.sum s f
57 | #check Finset.prod s f
58 |
59 | open BigOperators
60 | open Finset
61 |
62 | example : s.sum f = ∑ x ∈ s, f x :=
63 | rfl
64 |
65 | example : s.prod f = ∏ x ∈ s, f x :=
66 | rfl
67 |
68 | example : (range n).sum f = ∑ x ∈ range n, f x :=
69 | rfl
70 |
71 | example : (range n).prod f = ∏ x ∈ range n, f x :=
72 | rfl
73 |
74 | example (f : ℕ → ℕ) : ∑ x ∈ range 0, f x = 0 :=
75 | Finset.sum_range_zero f
76 |
77 | example (f : ℕ → ℕ) (n : ℕ) : ∑ x ∈ range n.succ, f x = ∑ x ∈ range n, f x + f n :=
78 | Finset.sum_range_succ f n
79 |
80 | example (f : ℕ → ℕ) : ∏ x ∈ range 0, f x = 1 :=
81 | Finset.prod_range_zero f
82 |
83 | example (f : ℕ → ℕ) (n : ℕ) : ∏ x ∈ range n.succ, f x = (∏ x ∈ range n, f x) * f n :=
84 | Finset.prod_range_succ f n
85 |
86 | example (n : ℕ) : fac n = ∏ i ∈ range n, (i + 1) := by
87 | induction' n with n ih
88 | · simp [fac, prod_range_zero]
89 | simp [fac, ih, prod_range_succ, mul_comm]
90 |
91 | example (a b c d e f : ℕ) : a * (b * c * f * (d * e)) = d * (a * f * e) * (c * b) := by
92 | simp [mul_assoc, mul_comm, mul_left_comm]
93 |
94 | theorem sum_id (n : ℕ) : ∑ i ∈ range (n + 1), i = n * (n + 1) / 2 := by
95 | symm; apply Nat.div_eq_of_eq_mul_right (by norm_num : 0 < 2)
96 | induction' n with n ih
97 | · simp
98 | rw [Finset.sum_range_succ, mul_add 2, ← ih]
99 | ring
100 |
101 | theorem sum_sqr (n : ℕ) : ∑ i ∈ range (n + 1), i ^ 2 = n * (n + 1) * (2 * n + 1) / 6 := by
102 | sorry
103 | end
104 |
105 | inductive MyNat where
106 | | zero : MyNat
107 | | succ : MyNat → MyNat
108 |
109 | namespace MyNat
110 |
111 | def add : MyNat → MyNat → MyNat
112 | | x, zero => x
113 | | x, succ y => succ (add x y)
114 |
115 | def mul : MyNat → MyNat → MyNat
116 | | x, zero => zero
117 | | x, succ y => add (mul x y) x
118 |
119 | theorem zero_add (n : MyNat) : add zero n = n := by
120 | induction' n with n ih
121 | · rfl
122 | rw [add, ih]
123 |
124 | theorem succ_add (m n : MyNat) : add (succ m) n = succ (add m n) := by
125 | induction' n with n ih
126 | · rfl
127 | rw [add, ih]
128 | rfl
129 |
130 | theorem add_comm (m n : MyNat) : add m n = add n m := by
131 | induction' n with n ih
132 | · rw [zero_add]
133 | rfl
134 | rw [add, succ_add, ih]
135 |
136 | theorem add_assoc (m n k : MyNat) : add (add m n) k = add m (add n k) := by
137 | sorry
138 | theorem mul_add (m n k : MyNat) : mul m (add n k) = add (mul m n) (mul m k) := by
139 | sorry
140 | theorem zero_mul (n : MyNat) : mul zero n = zero := by
141 | sorry
142 | theorem succ_mul (m n : MyNat) : mul (succ m) n = add (mul m n) n := by
143 | sorry
144 | theorem mul_comm (m n : MyNat) : mul m n = mul n m := by
145 | sorry
146 | end MyNat
147 |
--------------------------------------------------------------------------------
/MIL/C03_Logic/S04_Conjunction_and_Iff.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Data.Real.Basic
3 | import Mathlib.Data.Nat.Prime.Basic
4 |
5 | namespace C03S04
6 |
7 | example {x y : ℝ} (h₀ : x ≤ y) (h₁ : ¬y ≤ x) : x ≤ y ∧ x ≠ y := by
8 | constructor
9 | · assumption
10 | intro h
11 | apply h₁
12 | rw [h]
13 |
14 | example {x y : ℝ} (h₀ : x ≤ y) (h₁ : ¬y ≤ x) : x ≤ y ∧ x ≠ y :=
15 | ⟨h₀, fun h ↦ h₁ (by rw [h])⟩
16 |
17 | example {x y : ℝ} (h₀ : x ≤ y) (h₁ : ¬y ≤ x) : x ≤ y ∧ x ≠ y :=
18 | have h : x ≠ y := by
19 | contrapose! h₁
20 | rw [h₁]
21 | ⟨h₀, h⟩
22 |
23 | example {x y : ℝ} (h : x ≤ y ∧ x ≠ y) : ¬y ≤ x := by
24 | rcases h with ⟨h₀, h₁⟩
25 | contrapose! h₁
26 | exact le_antisymm h₀ h₁
27 |
28 | example {x y : ℝ} : x ≤ y ∧ x ≠ y → ¬y ≤ x := by
29 | rintro ⟨h₀, h₁⟩ h'
30 | exact h₁ (le_antisymm h₀ h')
31 |
32 | example {x y : ℝ} : x ≤ y ∧ x ≠ y → ¬y ≤ x :=
33 | fun ⟨h₀, h₁⟩ h' ↦ h₁ (le_antisymm h₀ h')
34 |
35 | example {x y : ℝ} (h : x ≤ y ∧ x ≠ y) : ¬y ≤ x := by
36 | have ⟨h₀, h₁⟩ := h
37 | contrapose! h₁
38 | exact le_antisymm h₀ h₁
39 |
40 | example {x y : ℝ} (h : x ≤ y ∧ x ≠ y) : ¬y ≤ x := by
41 | cases h
42 | case intro h₀ h₁ =>
43 | contrapose! h₁
44 | exact le_antisymm h₀ h₁
45 |
46 | example {x y : ℝ} (h : x ≤ y ∧ x ≠ y) : ¬y ≤ x := by
47 | cases h
48 | next h₀ h₁ =>
49 | contrapose! h₁
50 | exact le_antisymm h₀ h₁
51 |
52 | example {x y : ℝ} (h : x ≤ y ∧ x ≠ y) : ¬y ≤ x := by
53 | match h with
54 | | ⟨h₀, h₁⟩ =>
55 | contrapose! h₁
56 | exact le_antisymm h₀ h₁
57 |
58 | example {x y : ℝ} (h : x ≤ y ∧ x ≠ y) : ¬y ≤ x := by
59 | intro h'
60 | apply h.right
61 | exact le_antisymm h.left h'
62 |
63 | example {x y : ℝ} (h : x ≤ y ∧ x ≠ y) : ¬y ≤ x :=
64 | fun h' ↦ h.right (le_antisymm h.left h')
65 |
66 | example {m n : ℕ} (h : m ∣ n ∧ m ≠ n) : m ∣ n ∧ ¬n ∣ m :=
67 | sorry
68 |
69 | example : ∃ x : ℝ, 2 < x ∧ x < 4 :=
70 | ⟨5 / 2, by norm_num, by norm_num⟩
71 |
72 | example (x y : ℝ) : (∃ z : ℝ, x < z ∧ z < y) → x < y := by
73 | rintro ⟨z, xltz, zlty⟩
74 | exact lt_trans xltz zlty
75 |
76 | example (x y : ℝ) : (∃ z : ℝ, x < z ∧ z < y) → x < y :=
77 | fun ⟨z, xltz, zlty⟩ ↦ lt_trans xltz zlty
78 |
79 | example : ∃ x : ℝ, 2 < x ∧ x < 4 := by
80 | use 5 / 2
81 | constructor <;> norm_num
82 |
83 | example : ∃ m n : ℕ, 4 < m ∧ m < n ∧ n < 10 ∧ Nat.Prime m ∧ Nat.Prime n := by
84 | use 5
85 | use 7
86 | norm_num
87 |
88 | example {x y : ℝ} : x ≤ y ∧ x ≠ y → x ≤ y ∧ ¬y ≤ x := by
89 | rintro ⟨h₀, h₁⟩
90 | use h₀
91 | exact fun h' ↦ h₁ (le_antisymm h₀ h')
92 |
93 | example {x y : ℝ} (h : x ≤ y) : ¬y ≤ x ↔ x ≠ y := by
94 | constructor
95 | · contrapose!
96 | rintro rfl
97 | rfl
98 | contrapose!
99 | exact le_antisymm h
100 |
101 | example {x y : ℝ} (h : x ≤ y) : ¬y ≤ x ↔ x ≠ y :=
102 | ⟨fun h₀ h₁ ↦ h₀ (by rw [h₁]), fun h₀ h₁ ↦ h₀ (le_antisymm h h₁)⟩
103 |
104 | example {x y : ℝ} : x ≤ y ∧ ¬y ≤ x ↔ x ≤ y ∧ x ≠ y :=
105 | sorry
106 |
107 | theorem aux {x y : ℝ} (h : x ^ 2 + y ^ 2 = 0) : x = 0 :=
108 | have h' : x ^ 2 = 0 := by sorry
109 | pow_eq_zero h'
110 |
111 | example (x y : ℝ) : x ^ 2 + y ^ 2 = 0 ↔ x = 0 ∧ y = 0 :=
112 | sorry
113 |
114 | section
115 |
116 | example (x : ℝ) : |x + 3| < 5 → -8 < x ∧ x < 2 := by
117 | rw [abs_lt]
118 | intro h
119 | constructor <;> linarith
120 |
121 | example : 3 ∣ Nat.gcd 6 15 := by
122 | rw [Nat.dvd_gcd_iff]
123 | constructor <;> norm_num
124 |
125 | end
126 |
127 | theorem not_monotone_iff {f : ℝ → ℝ} : ¬Monotone f ↔ ∃ x y, x ≤ y ∧ f x > f y := by
128 | rw [Monotone]
129 | push_neg
130 | rfl
131 |
132 | example : ¬Monotone fun x : ℝ ↦ -x := by
133 | sorry
134 |
135 | section
136 | variable {α : Type*} [PartialOrder α]
137 | variable (a b : α)
138 |
139 | example : a < b ↔ a ≤ b ∧ a ≠ b := by
140 | rw [lt_iff_le_not_ge]
141 | sorry
142 |
143 | end
144 |
145 | section
146 | variable {α : Type*} [Preorder α]
147 | variable (a b c : α)
148 |
149 | example : ¬a < a := by
150 | rw [lt_iff_le_not_ge]
151 | sorry
152 |
153 | example : a < b → b < c → a < c := by
154 | simp only [lt_iff_le_not_ge]
155 | sorry
156 |
157 | end
158 |
--------------------------------------------------------------------------------
/html/_sources/C11_Topology.rst.txt:
--------------------------------------------------------------------------------
1 | .. _topology:
2 |
3 | .. index:: topology
4 |
5 | Topology
6 | ========
7 |
8 | Calculus is based on the concept of a function, which is used to model
9 | quantities that depend on one another.
10 | For example, it is common to study quantities that change over time.
11 | The notion of a *limit* is also fundamental.
12 | We may say that the limit of a function :math:`f(x)` is a value :math:`b`
13 | as :math:`x` approaches a value :math:`a`,
14 | or that :math:`f(x)` *converges to* :math:`b` as :math:`x` approaches :math:`a`.
15 | Equivalently, we may say that :math:`f(x)` approaches :math:`b` as :math:`x`
16 | approaches a value :math:`a`, or that it *tends to* :math:`b`
17 | as :math:`x` tends to :math:`a`.
18 | We have already begun to consider such notions in :numref:`sequences_and_convergence`.
19 |
20 | *Topology* is the abstract study of limits and continuity.
21 | Having covered the essentials of formalization in Chapters :numref:`%s `
22 | to :numref:`%s `,
23 | in this chapter, we will explain how topological notions are formalized in Mathlib.
24 | Not only do topological abstractions apply in much greater generality,
25 | but they also, somewhat paradoxically, make it easier to reason about limits
26 | and continuity in concrete instances.
27 |
28 | Topological notions build on quite a few layers of mathematical structure.
29 | The first layer is naive set theory,
30 | as described in :numref:`Chapter %s `.
31 | The next layer is the theory of *filters*, which we will describe in :numref:`filters`.
32 | On top of that, we layer
33 | the theories of *topological spaces*, *metric spaces*, and a slightly more exotic
34 | intermediate notion called a *uniform space*.
35 |
36 | Whereas previous chapters relied on mathematical notions that were likely
37 | familiar to you,
38 | the notion of a filter is less well known,
39 | even to many working mathematicians.
40 | The notion is essential, however, for formalizing mathematics effectively.
41 | Let us explain why.
42 | Let ``f : ℝ → ℝ`` be any function. We can consider
43 | the limit of ``f x`` as ``x`` approaches some value ``x₀``,
44 | but we can also consider the limit of ``f x`` as ``x`` approaches infinity
45 | or negative infinity.
46 | We can moreover consider the limit of ``f x`` as ``x`` approaches ``x₀`` from
47 | the right, conventionally written ``x₀⁺``, or from the left,
48 | written ``x₀⁻``. There are variations where ``x`` approaches ``x₀`` or ``x₀⁺``
49 | or ``x₀⁻`` but
50 | is not allowed to take on the value ``x₀`` itself.
51 | This results in at least eight ways that ``x`` can approach something.
52 | We can also restrict to rational values of ``x``
53 | or place other constraints on the domain, but let's stick to those 8 cases.
54 |
55 | We have a similar variety of options on the codomain:
56 | we can specify that ``f x`` approaches a value from the left or right,
57 | or that it approaches positive or negative infinity, and so on.
58 | For example, we may wish to say that ``f x`` tends to ``+∞``
59 | when ``x`` tends to ``x₀`` from the right without
60 | being equal to ``x₀``.
61 | This results in 64 different kinds of limit statements,
62 | and we haven't even begun to deal with limits of sequences,
63 | as we did in :numref:`sequences_and_convergence`.
64 |
65 | The problem is compounded even further when it comes to the supporting lemmas.
66 | For instance, limits compose: if
67 | ``f x`` tends to ``y₀`` when ``x`` tends to ``x₀`` and
68 | ``g y`` tends to ``z₀`` when ``y`` tends to ``y₀`` then
69 | ``g ∘ f x`` tends to ``z₀`` when ``x`` tends to ``x₀``.
70 | There are three notions of "tends to" at play here,
71 | each of which can be instantiated in any of the eight ways described
72 | in the previous paragraph.
73 | This results in 512 lemmas, a lot to have to add to a library!
74 | Informally, mathematicians generally prove two or three of these
75 | and simply note that the rest can be proved "in the same way."
76 | Formalizing mathematics requires making the relevant notion of "sameness"
77 | fully explicit, and that is exactly what Bourbaki's theory of filters
78 | manages to do.
79 |
80 | .. include:: C11_Topology/S01_Filters.inc
81 | .. include:: C11_Topology/S02_Metric_Spaces.inc
82 | .. include:: C11_Topology/S03_Topological_Spaces.inc
83 |
--------------------------------------------------------------------------------
/MIL/C07_Structures/S02_Algebraic_Structures.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Data.Real.Basic
3 |
4 | namespace C06S02
5 |
6 | structure Group₁ (α : Type*) where
7 | mul : α → α → α
8 | one : α
9 | inv : α → α
10 | mul_assoc : ∀ x y z : α, mul (mul x y) z = mul x (mul y z)
11 | mul_one : ∀ x : α, mul x one = x
12 | one_mul : ∀ x : α, mul one x = x
13 | inv_mul_cancel : ∀ x : α, mul (inv x) x = one
14 |
15 | structure Grp₁ where
16 | α : Type*
17 | str : Group₁ α
18 |
19 | section
20 | variable (α β γ : Type*)
21 | variable (f : α ≃ β) (g : β ≃ γ)
22 |
23 | #check Equiv α β
24 | #check (f.toFun : α → β)
25 | #check (f.invFun : β → α)
26 | #check (f.right_inv : ∀ x : β, f (f.invFun x) = x)
27 | #check (f.left_inv : ∀ x : α, f.invFun (f x) = x)
28 | #check (Equiv.refl α : α ≃ α)
29 | #check (f.symm : β ≃ α)
30 | #check (f.trans g : α ≃ γ)
31 |
32 | example (x : α) : (f.trans g).toFun x = g.toFun (f.toFun x) :=
33 | rfl
34 |
35 | example (x : α) : (f.trans g) x = g (f x) :=
36 | rfl
37 |
38 | example : (f.trans g : α → γ) = g ∘ f :=
39 | rfl
40 |
41 | end
42 |
43 | example (α : Type*) : Equiv.Perm α = (α ≃ α) :=
44 | rfl
45 |
46 | def permGroup {α : Type*} : Group₁ (Equiv.Perm α)
47 | where
48 | mul f g := Equiv.trans g f
49 | one := Equiv.refl α
50 | inv := Equiv.symm
51 | mul_assoc f g h := (Equiv.trans_assoc _ _ _).symm
52 | one_mul := Equiv.trans_refl
53 | mul_one := Equiv.refl_trans
54 | inv_mul_cancel := Equiv.self_trans_symm
55 |
56 | structure AddGroup₁ (α : Type*) where
57 | (add : α → α → α)
58 | -- fill in the rest
59 | @[ext]
60 | structure Point where
61 | x : ℝ
62 | y : ℝ
63 | z : ℝ
64 |
65 | namespace Point
66 |
67 | def add (a b : Point) : Point :=
68 | ⟨a.x + b.x, a.y + b.y, a.z + b.z⟩
69 |
70 | def neg (a : Point) : Point := sorry
71 |
72 | def zero : Point := sorry
73 |
74 | def addGroupPoint : AddGroup₁ Point := sorry
75 |
76 | end Point
77 |
78 | section
79 | variable {α : Type*} (f g : Equiv.Perm α) (n : ℕ)
80 |
81 | #check f * g
82 | #check mul_assoc f g g⁻¹
83 |
84 | -- group power, defined for any group
85 | #check g ^ n
86 |
87 | example : f * g * g⁻¹ = f := by rw [mul_assoc, mul_inv_cancel, mul_one]
88 |
89 | example : f * g * g⁻¹ = f :=
90 | mul_inv_cancel_right f g
91 |
92 | example {α : Type*} (f g : Equiv.Perm α) : g.symm.trans (g.trans f) = f :=
93 | mul_inv_cancel_right f g
94 |
95 | end
96 |
97 | class Group₂ (α : Type*) where
98 | mul : α → α → α
99 | one : α
100 | inv : α → α
101 | mul_assoc : ∀ x y z : α, mul (mul x y) z = mul x (mul y z)
102 | mul_one : ∀ x : α, mul x one = x
103 | one_mul : ∀ x : α, mul one x = x
104 | inv_mul_cancel : ∀ x : α, mul (inv x) x = one
105 |
106 | instance {α : Type*} : Group₂ (Equiv.Perm α) where
107 | mul f g := Equiv.trans g f
108 | one := Equiv.refl α
109 | inv := Equiv.symm
110 | mul_assoc f g h := (Equiv.trans_assoc _ _ _).symm
111 | one_mul := Equiv.trans_refl
112 | mul_one := Equiv.refl_trans
113 | inv_mul_cancel := Equiv.self_trans_symm
114 |
115 | #check Group₂.mul
116 |
117 | def mySquare {α : Type*} [Group₂ α] (x : α) :=
118 | Group₂.mul x x
119 |
120 | #check mySquare
121 |
122 | section
123 | variable {β : Type*} (f g : Equiv.Perm β)
124 |
125 | example : Group₂.mul f g = g.trans f :=
126 | rfl
127 |
128 | example : mySquare f = f.trans f :=
129 | rfl
130 |
131 | end
132 |
133 | instance : Inhabited Point where default := ⟨0, 0, 0⟩
134 |
135 | #check (default : Point)
136 |
137 | example : ([] : List Point).headI = default :=
138 | rfl
139 |
140 | instance : Add Point where add := Point.add
141 |
142 | section
143 | variable (x y : Point)
144 |
145 | #check x + y
146 |
147 | example : x + y = Point.add x y :=
148 | rfl
149 |
150 | end
151 |
152 | instance {α : Type*} [Group₂ α] : Mul α :=
153 | ⟨Group₂.mul⟩
154 |
155 | instance {α : Type*} [Group₂ α] : One α :=
156 | ⟨Group₂.one⟩
157 |
158 | instance {α : Type*} [Group₂ α] : Inv α :=
159 | ⟨Group₂.inv⟩
160 |
161 | section
162 | variable {α : Type*} (f g : Equiv.Perm α)
163 |
164 | #check f * 1 * g⁻¹
165 |
166 | def foo : f * 1 * g⁻¹ = g.symm.trans ((Equiv.refl α).trans f) :=
167 | rfl
168 |
169 | end
170 |
171 | class AddGroup₂ (α : Type*) where
172 | add : α → α → α
173 | -- fill in the rest
174 |
--------------------------------------------------------------------------------
/MIL/C08_Hierarchies/S02_Morphisms.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Topology.Instances.Real.Lemmas
3 |
4 | set_option autoImplicit true
5 |
6 |
7 | def isMonoidHom₁ [Monoid G] [Monoid H] (f : G → H) : Prop :=
8 | f 1 = 1 ∧ ∀ g g', f (g * g') = f g * f g'
9 | structure isMonoidHom₂ [Monoid G] [Monoid H] (f : G → H) : Prop where
10 | map_one : f 1 = 1
11 | map_mul : ∀ g g', f (g * g') = f g * f g'
12 | example : Continuous (id : ℝ → ℝ) := continuous_id
13 | @[ext]
14 | structure MonoidHom₁ (G H : Type) [Monoid G] [Monoid H] where
15 | toFun : G → H
16 | map_one : toFun 1 = 1
17 | map_mul : ∀ g g', toFun (g * g') = toFun g * toFun g'
18 |
19 | instance [Monoid G] [Monoid H] : CoeFun (MonoidHom₁ G H) (fun _ ↦ G → H) where
20 | coe := MonoidHom₁.toFun
21 |
22 | attribute [coe] MonoidHom₁.toFun
23 |
24 |
25 | example [Monoid G] [Monoid H] (f : MonoidHom₁ G H) : f 1 = 1 := f.map_one
26 |
27 | @[ext]
28 | structure AddMonoidHom₁ (G H : Type) [AddMonoid G] [AddMonoid H] where
29 | toFun : G → H
30 | map_zero : toFun 0 = 0
31 | map_add : ∀ g g', toFun (g + g') = toFun g + toFun g'
32 |
33 | instance [AddMonoid G] [AddMonoid H] : CoeFun (AddMonoidHom₁ G H) (fun _ ↦ G → H) where
34 | coe := AddMonoidHom₁.toFun
35 |
36 | attribute [coe] AddMonoidHom₁.toFun
37 |
38 | @[ext]
39 | structure RingHom₁ (R S : Type) [Ring R] [Ring S] extends MonoidHom₁ R S, AddMonoidHom₁ R S
40 |
41 |
42 |
43 | class MonoidHomClass₁ (F : Type) (M N : Type) [Monoid M] [Monoid N] where
44 | toFun : F → M → N
45 | map_one : ∀ f : F, toFun f 1 = 1
46 | map_mul : ∀ f g g', toFun f (g * g') = toFun f g * toFun f g'
47 |
48 |
49 | def badInst [Monoid M] [Monoid N] [MonoidHomClass₁ F M N] : CoeFun F (fun _ ↦ M → N) where
50 | coe := MonoidHomClass₁.toFun
51 |
52 |
53 | class MonoidHomClass₂ (F : Type) (M N : outParam Type) [Monoid M] [Monoid N] where
54 | toFun : F → M → N
55 | map_one : ∀ f : F, toFun f 1 = 1
56 | map_mul : ∀ f g g', toFun f (g * g') = toFun f g * toFun f g'
57 |
58 | instance [Monoid M] [Monoid N] [MonoidHomClass₂ F M N] : CoeFun F (fun _ ↦ M → N) where
59 | coe := MonoidHomClass₂.toFun
60 |
61 | attribute [coe] MonoidHomClass₂.toFun
62 |
63 |
64 | instance (M N : Type) [Monoid M] [Monoid N] : MonoidHomClass₂ (MonoidHom₁ M N) M N where
65 | toFun := MonoidHom₁.toFun
66 | map_one := fun f ↦ f.map_one
67 | map_mul := fun f ↦ f.map_mul
68 |
69 | instance (R S : Type) [Ring R] [Ring S] : MonoidHomClass₂ (RingHom₁ R S) R S where
70 | toFun := fun f ↦ f.toMonoidHom₁.toFun
71 | map_one := fun f ↦ f.toMonoidHom₁.map_one
72 | map_mul := fun f ↦ f.toMonoidHom₁.map_mul
73 |
74 |
75 | lemma map_inv_of_inv [Monoid M] [Monoid N] [MonoidHomClass₂ F M N] (f : F) {m m' : M} (h : m*m' = 1) :
76 | f m * f m' = 1 := by
77 | rw [← MonoidHomClass₂.map_mul, h, MonoidHomClass₂.map_one]
78 |
79 | example [Monoid M] [Monoid N] (f : MonoidHom₁ M N) {m m' : M} (h : m*m' = 1) : f m * f m' = 1 :=
80 | map_inv_of_inv f h
81 |
82 | example [Ring R] [Ring S] (f : RingHom₁ R S) {r r' : R} (h : r*r' = 1) : f r * f r' = 1 :=
83 | map_inv_of_inv f h
84 |
85 |
86 |
87 | class MonoidHomClass₃ (F : Type) (M N : outParam Type) [Monoid M] [Monoid N] extends
88 | DFunLike F M (fun _ ↦ N) where
89 | map_one : ∀ f : F, f 1 = 1
90 | map_mul : ∀ (f : F) g g', f (g * g') = f g * f g'
91 |
92 | instance (M N : Type) [Monoid M] [Monoid N] : MonoidHomClass₃ (MonoidHom₁ M N) M N where
93 | coe := MonoidHom₁.toFun
94 | coe_injective' _ _ := MonoidHom₁.ext
95 | map_one := MonoidHom₁.map_one
96 | map_mul := MonoidHom₁.map_mul
97 |
98 |
99 | @[ext]
100 | structure OrderPresHom (α β : Type) [LE α] [LE β] where
101 | toFun : α → β
102 | le_of_le : ∀ a a', a ≤ a' → toFun a ≤ toFun a'
103 |
104 | @[ext]
105 | structure OrderPresMonoidHom (M N : Type) [Monoid M] [LE M] [Monoid N] [LE N] extends
106 | MonoidHom₁ M N, OrderPresHom M N
107 |
108 | class OrderPresHomClass (F : Type) (α β : outParam Type) [LE α] [LE β]
109 |
110 | instance (α β : Type) [LE α] [LE β] : OrderPresHomClass (OrderPresHom α β) α β where
111 |
112 | instance (α β : Type) [LE α] [Monoid α] [LE β] [Monoid β] :
113 | OrderPresHomClass (OrderPresMonoidHom α β) α β where
114 |
115 | instance (α β : Type) [LE α] [Monoid α] [LE β] [Monoid β] :
116 | MonoidHomClass₃ (OrderPresMonoidHom α β) α β
117 | := sorry
118 |
--------------------------------------------------------------------------------
/MIL/C06_Discrete_Mathematics/S01_Finsets_and_Fintypes.lean:
--------------------------------------------------------------------------------
1 | import Mathlib.Data.Finset.Powerset
2 | import Mathlib.Data.Finset.Max
3 | import Mathlib.Data.Nat.Prime.Basic
4 | import Mathlib.Data.Fintype.BigOperators
5 |
6 | section
7 | variable {α : Type*} [DecidableEq α] (a : α) (s t : Finset α)
8 |
9 | #check a ∈ s
10 | #check s ∩ t
11 |
12 | end
13 |
14 | open Finset
15 |
16 | variable (a b c : Finset ℕ)
17 | variable (n : ℕ)
18 |
19 | #check a ∩ b
20 | #check a ∪ b
21 | #check a \ b
22 | #check (∅ : Finset ℕ)
23 |
24 | example : a ∩ (b ∪ c) = (a ∩ b) ∪ (a ∩ c) := by
25 | ext x; simp only [mem_inter, mem_union]; tauto
26 |
27 | example : a ∩ (b ∪ c) = (a ∩ b) ∪ (a ∩ c) := by rw [inter_union_distrib_left]
28 |
29 | #check ({0, 2, 5} : Finset Nat)
30 |
31 | def example1 : Finset ℕ := {0, 1, 2}
32 |
33 | example : ({0, 1, 2} : Finset ℕ) = {1, 2, 0} := by decide
34 |
35 | example : ({0, 1, 2} : Finset ℕ) = {0, 1, 1, 2} := by decide
36 |
37 | example : ({0, 1} : Finset ℕ) = {1, 0} := by rw [Finset.pair_comm]
38 |
39 | example (x : Nat) : ({x, x} : Finset ℕ) = {x} := by simp
40 |
41 | example (x y z : Nat) : ({x, y, z, y, z, x} : Finset ℕ) = {x, y, z} := by
42 | ext i; simp [or_comm, or_assoc, or_left_comm]
43 |
44 | example (x y z : Nat) : ({x, y, z, y, z, x} : Finset ℕ) = {x, y, z} := by
45 | ext i; simp; tauto
46 |
47 | example (s : Finset ℕ) (a : ℕ) (h : a ∉ s) : (insert a s |>.erase a) = s :=
48 | Finset.erase_insert h
49 |
50 | example (s : Finset ℕ) (a : ℕ) (h : a ∈ s) : insert a (s.erase a) = s :=
51 | Finset.insert_erase h
52 |
53 | set_option pp.notation false in
54 | #check ({0, 1, 2} : Finset ℕ)
55 |
56 | example : {m ∈ range n | Even m} = (range n).filter Even := rfl
57 | example : {m ∈ range n | Even m ∧ m ≠ 3} = (range n).filter (fun m ↦ Even m ∧ m ≠ 3) := rfl
58 |
59 | example : {m ∈ range 10 | Even m} = {0, 2, 4, 6, 8} := by decide
60 |
61 | #check (range 5).image (fun x ↦ x * 2)
62 |
63 | example : (range 5).image (fun x ↦ x * 2) = {x ∈ range 10 | Even x} := by decide
64 |
65 | section
66 | variable (s t : Finset Nat)
67 | #check s ×ˢ t
68 | #check s.powerset
69 |
70 | end
71 |
72 | namespace finsets_and_fintypes
73 | #check Finset.fold
74 |
75 | def f (n : ℕ) : Int := (↑n)^2
76 |
77 | #check (range 5).fold (fun x y : Int ↦ x + y) 0 f
78 | #eval (range 5).fold (fun x y : Int ↦ x + y) 0 f
79 |
80 | #check ∑ i ∈ range 5, i^2
81 | #check ∏ i ∈ range 5, i + 1
82 |
83 | variable (g : Nat → Finset Int)
84 |
85 | #check (range 5).biUnion g
86 |
87 | end finsets_and_fintypes
88 |
89 | #check Finset.induction
90 |
91 | example {α : Type*} [DecidableEq α] (f : α → ℕ) (s : Finset α) (h : ∀ x ∈ s, f x ≠ 0) :
92 | ∏ x ∈ s, f x ≠ 0 := by
93 | induction s using Finset.induction_on with
94 | | empty => simp
95 | | @insert a s anins ih =>
96 | rw [prod_insert anins]
97 | apply mul_ne_zero
98 | · apply h; apply mem_insert_self
99 | apply ih
100 | intros x xs
101 | exact h x (mem_insert_of_mem xs)
102 |
103 | noncomputable example (s : Finset ℕ) (h : s.Nonempty) : ℕ := Classical.choose h
104 |
105 | example (s : Finset ℕ) (h : s.Nonempty) : Classical.choose h ∈ s := Classical.choose_spec h
106 |
107 | noncomputable example (s : Finset ℕ) : List ℕ := s.toList
108 |
109 | example (s : Finset ℕ) (a : ℕ) : a ∈ s.toList ↔ a ∈ s := mem_toList
110 |
111 | #check Finset.min
112 | #check Finset.min'
113 | #check Finset.max
114 | #check Finset.max'
115 | #check Finset.inf
116 | #check Finset.inf'
117 | #check Finset.sup
118 | #check Finset.sup'
119 |
120 | example : Finset.Nonempty {2, 6, 7} := ⟨6, by trivial⟩
121 | example : Finset.min' {2, 6, 7} ⟨6, by trivial⟩ = 2 := by trivial
122 |
123 | #check Finset.card
124 |
125 | #eval (range 5).card
126 |
127 | example (s : Finset ℕ) : s.card = #s := by rfl
128 |
129 | example (s : Finset ℕ) : s.card = ∑ i ∈ s, 1 := by rw [card_eq_sum_ones]
130 |
131 | example (s : Finset ℕ) : s.card = ∑ i ∈ s, 1 := by simp
132 |
133 | section
134 | variable {α : Type*} [Fintype α]
135 |
136 | example : ∀ x : α, x ∈ Finset.univ := by
137 | intro x; exact mem_univ x
138 |
139 | example : Fintype.card α = (Finset.univ : Finset α).card := rfl
140 | end
141 |
142 | example : Fintype.card (Fin 5) = 5 := by simp
143 | example : Fintype.card ((Fin 5) × (Fin 3)) = 15 := by simp
144 |
145 | section
146 | variable (s : Finset ℕ)
147 |
148 | example : (↑s : Type) = {x : ℕ // x ∈ s} := rfl
149 | example : Fintype.card ↑s = s.card := by simp
150 | end
151 |
152 |
--------------------------------------------------------------------------------
/MIL/C05_Elementary_Number_Theory/S04_More_Induction.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Analysis.Calculus.Taylor
3 | import Mathlib.Data.Nat.GCD.Basic
4 |
5 | namespace more_induction
6 |
7 | def fac : ℕ → ℕ
8 | | 0 => 1
9 | | n + 1 => (n + 1) * fac n
10 |
11 | theorem fac_pos (n : ℕ) : 0 < fac n := by
12 | induction' n with n ih
13 | · rw [fac]
14 | exact zero_lt_one
15 | rw [fac]
16 | exact mul_pos n.succ_pos ih
17 |
18 | example (n : ℕ) : 0 < fac n := by
19 | induction n
20 | case zero =>
21 | rw [fac]
22 | exact zero_lt_one
23 | case succ n ih =>
24 | rw [fac]
25 | exact mul_pos n.succ_pos ih
26 |
27 | example (n : ℕ) : 0 < fac n := by
28 | induction n with
29 | | zero =>
30 | rw [fac]
31 | exact zero_lt_one
32 | | succ n ih =>
33 | rw [fac]
34 | exact mul_pos n.succ_pos ih
35 |
36 | theorem fac_pos' : ∀ n, 0 < fac n
37 | | 0 => by
38 | rw [fac]
39 | exact zero_lt_one
40 | | n + 1 => by
41 | rw [fac]
42 | exact mul_pos n.succ_pos (fac_pos' n)
43 |
44 | @[simp] def fib : ℕ → ℕ
45 | | 0 => 0
46 | | 1 => 1
47 | | n + 2 => fib n + fib (n + 1)
48 |
49 | theorem fib_add_two (n : ℕ) : fib (n + 2) = fib n + fib (n + 1) := rfl
50 |
51 | example (n : ℕ) : fib (n + 2) = fib n + fib (n + 1) := by rw [fib]
52 |
53 | noncomputable section
54 |
55 | def phi : ℝ := (1 + √5) / 2
56 | def phi' : ℝ := (1 - √5) / 2
57 |
58 | theorem phi_sq : phi^2 = phi + 1 := by
59 | field_simp [phi, add_sq]; ring
60 |
61 | theorem phi'_sq : phi'^2 = phi' + 1 := by
62 | field_simp [phi', sub_sq]; ring
63 |
64 | theorem fib_eq : ∀ n, fib n = (phi^n - phi'^n) / √5
65 | | 0 => by simp
66 | | 1 => by field_simp [phi, phi']
67 | | n+2 => by field_simp [fib_eq, pow_add, phi_sq, phi'_sq]; ring
68 |
69 | end
70 |
71 | theorem fib_coprime_fib_succ (n : ℕ) : Nat.Coprime (fib n) (fib (n + 1)) := by
72 | induction n with
73 | | zero => simp
74 | | succ n ih =>
75 | simp only [fib, Nat.coprime_add_self_right]
76 | exact ih.symm
77 |
78 | #eval fib 6
79 | #eval List.range 20 |>.map fib
80 |
81 | def fib' (n : Nat) : Nat :=
82 | aux n 0 1
83 | where aux
84 | | 0, x, _ => x
85 | | n+1, x, y => aux n y (x + y)
86 |
87 | theorem fib'.aux_eq (m n : ℕ) : fib'.aux n (fib m) (fib (m + 1)) = fib (n + m) := by
88 | induction n generalizing m with
89 | | zero => simp [fib'.aux]
90 | | succ n ih => rw [fib'.aux, ←fib_add_two, ih, add_assoc, add_comm 1]
91 |
92 | theorem fib'_eq_fib : fib' = fib := by
93 | ext n
94 | erw [fib', fib'.aux_eq 0 n]; rfl
95 |
96 | #eval fib' 10000
97 |
98 | theorem fib_add (m n : ℕ) : fib (m + n + 1) = fib m * fib n + fib (m + 1) * fib (n + 1) := by
99 | induction n generalizing m with
100 | | zero => simp
101 | | succ n ih =>
102 | specialize ih (m + 1)
103 | rw [add_assoc m 1 n, add_comm 1 n] at ih
104 | simp only [fib_add_two, Nat.succ_eq_add_one, ih]
105 | ring
106 |
107 | theorem fib_add' : ∀ m n, fib (m + n + 1) = fib m * fib n + fib (m + 1) * fib (n + 1)
108 | | _, 0 => by simp
109 | | m, n + 1 => by
110 | have := fib_add' (m + 1) n
111 | rw [add_assoc m 1 n, add_comm 1 n] at this
112 | simp only [fib_add_two, Nat.succ_eq_add_one, this]
113 | ring
114 |
115 | example (n : ℕ): (fib n) ^ 2 + (fib (n + 1)) ^ 2 = fib (2 * n + 1) := by sorry
116 | example (n : ℕ): (fib n) ^ 2 + (fib (n + 1)) ^ 2 = fib (2 * n + 1) := by
117 | rw [two_mul, fib_add, pow_two, pow_two]
118 |
119 | #check (@Nat.not_prime_iff_exists_dvd_lt :
120 | ∀ {n : ℕ}, 2 ≤ n → (¬Nat.Prime n ↔ ∃ m, m ∣ n ∧ 2 ≤ m ∧ m < n))
121 |
122 | theorem ne_one_iff_exists_prime_dvd : ∀ {n}, n ≠ 1 ↔ ∃ p : ℕ, p.Prime ∧ p ∣ n
123 | | 0 => by simpa using Exists.intro 2 Nat.prime_two
124 | | 1 => by simp [Nat.not_prime_one]
125 | | n + 2 => by
126 | have hn : n+2 ≠ 1 := by omega
127 | simp only [Ne, not_false_iff, true_iff, hn]
128 | by_cases h : Nat.Prime (n + 2)
129 | · use n+2, h
130 | · have : 2 ≤ n + 2 := by omega
131 | rw [Nat.not_prime_iff_exists_dvd_lt this] at h
132 | rcases h with ⟨m, mdvdn, mge2, -⟩
133 | have : m ≠ 1 := by omega
134 | rw [ne_one_iff_exists_prime_dvd] at this
135 | rcases this with ⟨p, primep, pdvdm⟩
136 | use p, primep
137 | exact pdvdm.trans mdvdn
138 |
139 | theorem zero_lt_of_mul_eq_one (m n : ℕ) : n * m = 1 → 0 < n ∧ 0 < m := by
140 | cases n <;> cases m <;> simp
141 |
142 | example (m n : ℕ) : n*m = 1 → 0 < n ∧ 0 < m := by
143 | rcases m with (_ | m); simp
144 | rcases n with (_ | n) <;> simp
145 |
146 |
--------------------------------------------------------------------------------
/MIL/C03_Logic/solutions/Solutions_S06_Sequences_and_Convergence.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Data.Real.Basic
3 |
4 | namespace C03S06
5 |
6 | def ConvergesTo (s : ℕ → ℝ) (a : ℝ) :=
7 | ∀ ε > 0, ∃ N, ∀ n ≥ N, |s n - a| < ε
8 |
9 | theorem convergesTo_const (a : ℝ) : ConvergesTo (fun x : ℕ ↦ a) a := by
10 | intro ε εpos
11 | use 0
12 | intro n nge
13 | rw [sub_self, abs_zero]
14 | apply εpos
15 |
16 | theorem convergesTo_add {s t : ℕ → ℝ} {a b : ℝ}
17 | (cs : ConvergesTo s a) (ct : ConvergesTo t b) :
18 | ConvergesTo (fun n ↦ s n + t n) (a + b) := by
19 | intro ε εpos
20 | dsimp
21 | have ε2pos : 0 < ε / 2 := by linarith
22 | rcases cs (ε / 2) ε2pos with ⟨Ns, hs⟩
23 | rcases ct (ε / 2) ε2pos with ⟨Nt, ht⟩
24 | use max Ns Nt
25 | intro n hn
26 | have ngeNs : n ≥ Ns := le_of_max_le_left hn
27 | have ngeNt : n ≥ Nt := le_of_max_le_right hn
28 | calc
29 | |s n + t n - (a + b)| = |s n - a + (t n - b)| := by
30 | congr
31 | ring
32 | _ ≤ |s n - a| + |t n - b| := (abs_add _ _)
33 | _ < ε / 2 + ε / 2 := (add_lt_add (hs n ngeNs) (ht n ngeNt))
34 | _ = ε := by norm_num
35 |
36 | theorem convergesTo_mul_const {s : ℕ → ℝ} {a : ℝ} (c : ℝ) (cs : ConvergesTo s a) :
37 | ConvergesTo (fun n ↦ c * s n) (c * a) := by
38 | by_cases h : c = 0
39 | · convert convergesTo_const 0
40 | · rw [h]
41 | ring
42 | rw [h]
43 | ring
44 | have acpos : 0 < |c| := abs_pos.mpr h
45 | intro ε εpos
46 | dsimp
47 | have εcpos : 0 < ε / |c| := by apply div_pos εpos acpos
48 | rcases cs (ε / |c|) εcpos with ⟨Ns, hs⟩
49 | use Ns
50 | intro n ngt
51 | calc
52 | |c * s n - c * a| = |c| * |s n - a| := by rw [← abs_mul, mul_sub]
53 | _ < |c| * (ε / |c|) := (mul_lt_mul_of_pos_left (hs n ngt) acpos)
54 | _ = ε := mul_div_cancel₀ _ (ne_of_lt acpos).symm
55 |
56 | theorem exists_abs_le_of_convergesTo {s : ℕ → ℝ} {a : ℝ} (cs : ConvergesTo s a) :
57 | ∃ N b, ∀ n, N ≤ n → |s n| < b := by
58 | rcases cs 1 zero_lt_one with ⟨N, h⟩
59 | use N, |a| + 1
60 | intro n ngt
61 | calc
62 | |s n| = |s n - a + a| := by
63 | congr
64 | abel
65 | _ ≤ |s n - a| + |a| := (abs_add _ _)
66 | _ < |a| + 1 := by linarith [h n ngt]
67 |
68 | theorem aux {s t : ℕ → ℝ} {a : ℝ} (cs : ConvergesTo s a) (ct : ConvergesTo t 0) :
69 | ConvergesTo (fun n ↦ s n * t n) 0 := by
70 | intro ε εpos
71 | dsimp
72 | rcases exists_abs_le_of_convergesTo cs with ⟨N₀, B, h₀⟩
73 | have Bpos : 0 < B := lt_of_le_of_lt (abs_nonneg _) (h₀ N₀ (le_refl _))
74 | have pos₀ : ε / B > 0 := div_pos εpos Bpos
75 | rcases ct _ pos₀ with ⟨N₁, h₁⟩
76 | use max N₀ N₁
77 | intro n ngt
78 | have ngeN₀ : n ≥ N₀ := le_of_max_le_left ngt
79 | have ngeN₁ : n ≥ N₁ := le_of_max_le_right ngt
80 | calc
81 | |s n * t n - 0| = |s n| * |t n - 0| := by rw [sub_zero, abs_mul, sub_zero]
82 | _ < B * (ε / B) := (mul_lt_mul'' (h₀ n ngeN₀) (h₁ n ngeN₁) (abs_nonneg _) (abs_nonneg _))
83 | _ = ε := mul_div_cancel₀ _ (ne_of_lt Bpos).symm
84 |
85 | theorem convergesTo_mul {s t : ℕ → ℝ} {a b : ℝ}
86 | (cs : ConvergesTo s a) (ct : ConvergesTo t b) :
87 | ConvergesTo (fun n ↦ s n * t n) (a * b) := by
88 | have h₁ : ConvergesTo (fun n ↦ s n * (t n + -b)) 0 := by
89 | apply aux cs
90 | convert convergesTo_add ct (convergesTo_const (-b))
91 | ring
92 | have := convergesTo_add h₁ (convergesTo_mul_const b cs)
93 | convert convergesTo_add h₁ (convergesTo_mul_const b cs) using 1
94 | · ext; ring
95 | ring
96 |
97 | theorem convergesTo_unique {s : ℕ → ℝ} {a b : ℝ}
98 | (sa : ConvergesTo s a) (sb : ConvergesTo s b) :
99 | a = b := by
100 | by_contra abne
101 | have : |a - b| > 0 := by
102 | apply lt_of_le_of_ne
103 | · apply abs_nonneg
104 | intro h''
105 | apply abne
106 | apply eq_of_abs_sub_eq_zero h''.symm
107 | let ε := |a - b| / 2
108 | have εpos : ε > 0 := by
109 | change |a - b| / 2 > 0
110 | linarith
111 | rcases sa ε εpos with ⟨Na, hNa⟩
112 | rcases sb ε εpos with ⟨Nb, hNb⟩
113 | let N := max Na Nb
114 | have absa : |s N - a| < ε := by
115 | apply hNa
116 | apply le_max_left
117 | have absb : |s N - b| < ε := by
118 | apply hNb
119 | apply le_max_right
120 | have : |a - b| < |a - b|
121 | calc
122 | |a - b| = |(-(s N - a)) + (s N - b)| := by
123 | congr
124 | ring
125 | _ ≤ |(-(s N - a))| + |s N - b| := (abs_add _ _)
126 | _ = |s N - a| + |s N - b| := by rw [abs_neg]
127 | _ < ε + ε := (add_lt_add absa absb)
128 | _ = |a - b| := by norm_num [ε]
129 |
130 | exact lt_irrefl _ this
131 |
132 |
--------------------------------------------------------------------------------
/MIL/C04_Sets_and_Functions/S02_Functions.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Data.Set.Lattice
3 | import Mathlib.Data.Set.Function
4 | import Mathlib.Analysis.SpecialFunctions.Log.Basic
5 |
6 | section
7 |
8 | variable {α β : Type*}
9 | variable (f : α → β)
10 | variable (s t : Set α)
11 | variable (u v : Set β)
12 |
13 | open Function
14 | open Set
15 |
16 | example : f ⁻¹' (u ∩ v) = f ⁻¹' u ∩ f ⁻¹' v := by
17 | ext
18 | rfl
19 |
20 | example : f '' (s ∪ t) = f '' s ∪ f '' t := by
21 | ext y; constructor
22 | · rintro ⟨x, xs | xt, rfl⟩
23 | · left
24 | use x, xs
25 | right
26 | use x, xt
27 | rintro (⟨x, xs, rfl⟩ | ⟨x, xt, rfl⟩)
28 | · use x, Or.inl xs
29 | use x, Or.inr xt
30 |
31 | example : s ⊆ f ⁻¹' (f '' s) := by
32 | intro x xs
33 | show f x ∈ f '' s
34 | use x, xs
35 |
36 | example : f '' s ⊆ v ↔ s ⊆ f ⁻¹' v := by
37 | sorry
38 |
39 | example (h : Injective f) : f ⁻¹' (f '' s) ⊆ s := by
40 | sorry
41 |
42 | example : f '' (f ⁻¹' u) ⊆ u := by
43 | sorry
44 |
45 | example (h : Surjective f) : u ⊆ f '' (f ⁻¹' u) := by
46 | sorry
47 |
48 | example (h : s ⊆ t) : f '' s ⊆ f '' t := by
49 | sorry
50 |
51 | example (h : u ⊆ v) : f ⁻¹' u ⊆ f ⁻¹' v := by
52 | sorry
53 |
54 | example : f ⁻¹' (u ∪ v) = f ⁻¹' u ∪ f ⁻¹' v := by
55 | sorry
56 |
57 | example : f '' (s ∩ t) ⊆ f '' s ∩ f '' t := by
58 | sorry
59 |
60 | example (h : Injective f) : f '' s ∩ f '' t ⊆ f '' (s ∩ t) := by
61 | sorry
62 |
63 | example : f '' s \ f '' t ⊆ f '' (s \ t) := by
64 | sorry
65 |
66 | example : f ⁻¹' u \ f ⁻¹' v ⊆ f ⁻¹' (u \ v) := by
67 | sorry
68 |
69 | example : f '' s ∩ v = f '' (s ∩ f ⁻¹' v) := by
70 | sorry
71 |
72 | example : f '' (s ∩ f ⁻¹' u) ⊆ f '' s ∩ u := by
73 | sorry
74 |
75 | example : s ∩ f ⁻¹' u ⊆ f ⁻¹' (f '' s ∩ u) := by
76 | sorry
77 |
78 | example : s ∪ f ⁻¹' u ⊆ f ⁻¹' (f '' s ∪ u) := by
79 | sorry
80 |
81 | variable {I : Type*} (A : I → Set α) (B : I → Set β)
82 |
83 | example : (f '' ⋃ i, A i) = ⋃ i, f '' A i := by
84 | sorry
85 |
86 | example : (f '' ⋂ i, A i) ⊆ ⋂ i, f '' A i := by
87 | sorry
88 |
89 | example (i : I) (injf : Injective f) : (⋂ i, f '' A i) ⊆ f '' ⋂ i, A i := by
90 | sorry
91 |
92 | example : (f ⁻¹' ⋃ i, B i) = ⋃ i, f ⁻¹' B i := by
93 | sorry
94 |
95 | example : (f ⁻¹' ⋂ i, B i) = ⋂ i, f ⁻¹' B i := by
96 | sorry
97 |
98 | example : InjOn f s ↔ ∀ x₁ ∈ s, ∀ x₂ ∈ s, f x₁ = f x₂ → x₁ = x₂ :=
99 | Iff.refl _
100 |
101 | end
102 |
103 | section
104 |
105 | open Set Real
106 |
107 | example : InjOn log { x | x > 0 } := by
108 | intro x xpos y ypos
109 | intro e
110 | -- log x = log y
111 | calc
112 | x = exp (log x) := by rw [exp_log xpos]
113 | _ = exp (log y) := by rw [e]
114 | _ = y := by rw [exp_log ypos]
115 |
116 |
117 | example : range exp = { y | y > 0 } := by
118 | ext y; constructor
119 | · rintro ⟨x, rfl⟩
120 | apply exp_pos
121 | intro ypos
122 | use log y
123 | rw [exp_log ypos]
124 |
125 | example : InjOn sqrt { x | x ≥ 0 } := by
126 | sorry
127 |
128 | example : InjOn (fun x ↦ x ^ 2) { x : ℝ | x ≥ 0 } := by
129 | sorry
130 |
131 | example : sqrt '' { x | x ≥ 0 } = { y | y ≥ 0 } := by
132 | sorry
133 |
134 | example : (range fun x ↦ x ^ 2) = { y : ℝ | y ≥ 0 } := by
135 | sorry
136 |
137 | end
138 |
139 | section
140 | variable {α β : Type*} [Inhabited α]
141 |
142 | #check (default : α)
143 |
144 | variable (P : α → Prop) (h : ∃ x, P x)
145 |
146 | #check Classical.choose h
147 |
148 | example : P (Classical.choose h) :=
149 | Classical.choose_spec h
150 |
151 | noncomputable section
152 |
153 | open Classical
154 |
155 | def inverse (f : α → β) : β → α := fun y : β ↦
156 | if h : ∃ x, f x = y then Classical.choose h else default
157 |
158 | theorem inverse_spec {f : α → β} (y : β) (h : ∃ x, f x = y) : f (inverse f y) = y := by
159 | rw [inverse, dif_pos h]
160 | exact Classical.choose_spec h
161 |
162 | variable (f : α → β)
163 |
164 | open Function
165 |
166 | example : Injective f ↔ LeftInverse (inverse f) f :=
167 | sorry
168 |
169 | example : Surjective f ↔ RightInverse (inverse f) f :=
170 | sorry
171 |
172 | end
173 |
174 | section
175 | variable {α : Type*}
176 | open Function
177 |
178 | theorem Cantor : ∀ f : α → Set α, ¬Surjective f := by
179 | intro f surjf
180 | let S := { i | i ∉ f i }
181 | rcases surjf S with ⟨j, h⟩
182 | have h₁ : j ∉ f j := by
183 | intro h'
184 | have : j ∉ f j := by rwa [h] at h'
185 | contradiction
186 | have h₂ : j ∈ S
187 | sorry
188 | have h₃ : j ∉ S
189 | sorry
190 | contradiction
191 |
192 | -- COMMENTS: TODO: improve this
193 | end
194 |
--------------------------------------------------------------------------------
/MIL/C03_Logic/S02_The_Existential_Quantifier.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Data.Real.Basic
3 |
4 | set_option autoImplicit true
5 |
6 | namespace C03S02
7 |
8 | example : ∃ x : ℝ, 2 < x ∧ x < 3 := by
9 | use 5 / 2
10 | norm_num
11 |
12 | example : ∃ x : ℝ, 2 < x ∧ x < 3 := by
13 | have h1 : 2 < (5 : ℝ) / 2 := by norm_num
14 | have h2 : (5 : ℝ) / 2 < 3 := by norm_num
15 | use 5 / 2, h1, h2
16 |
17 | example : ∃ x : ℝ, 2 < x ∧ x < 3 := by
18 | have h : 2 < (5 : ℝ) / 2 ∧ (5 : ℝ) / 2 < 3 := by norm_num
19 | use 5 / 2
20 |
21 | example : ∃ x : ℝ, 2 < x ∧ x < 3 :=
22 | have h : 2 < (5 : ℝ) / 2 ∧ (5 : ℝ) / 2 < 3 := by norm_num
23 | ⟨5 / 2, h⟩
24 |
25 | example : ∃ x : ℝ, 2 < x ∧ x < 3 :=
26 | ⟨5 / 2, by norm_num⟩
27 |
28 | def FnUb (f : ℝ → ℝ) (a : ℝ) : Prop :=
29 | ∀ x, f x ≤ a
30 |
31 | def FnLb (f : ℝ → ℝ) (a : ℝ) : Prop :=
32 | ∀ x, a ≤ f x
33 |
34 | def FnHasUb (f : ℝ → ℝ) :=
35 | ∃ a, FnUb f a
36 |
37 | def FnHasLb (f : ℝ → ℝ) :=
38 | ∃ a, FnLb f a
39 |
40 | theorem fnUb_add {f g : ℝ → ℝ} {a b : ℝ} (hfa : FnUb f a) (hgb : FnUb g b) :
41 | FnUb (fun x ↦ f x + g x) (a + b) :=
42 | fun x ↦ add_le_add (hfa x) (hgb x)
43 |
44 | section
45 |
46 | variable {f g : ℝ → ℝ}
47 |
48 | example (ubf : FnHasUb f) (ubg : FnHasUb g) : FnHasUb fun x ↦ f x + g x := by
49 | rcases ubf with ⟨a, ubfa⟩
50 | rcases ubg with ⟨b, ubgb⟩
51 | use a + b
52 | apply fnUb_add ubfa ubgb
53 |
54 | example (lbf : FnHasLb f) (lbg : FnHasLb g) : FnHasLb fun x ↦ f x + g x := by
55 | sorry
56 |
57 | example {c : ℝ} (ubf : FnHasUb f) (h : c ≥ 0) : FnHasUb fun x ↦ c * f x := by
58 | sorry
59 |
60 | example : FnHasUb f → FnHasUb g → FnHasUb fun x ↦ f x + g x := by
61 | rintro ⟨a, ubfa⟩ ⟨b, ubgb⟩
62 | exact ⟨a + b, fnUb_add ubfa ubgb⟩
63 |
64 | example : FnHasUb f → FnHasUb g → FnHasUb fun x ↦ f x + g x :=
65 | fun ⟨a, ubfa⟩ ⟨b, ubgb⟩ ↦ ⟨a + b, fnUb_add ubfa ubgb⟩
66 |
67 | end
68 |
69 | example (ubf : FnHasUb f) (ubg : FnHasUb g) : FnHasUb fun x ↦ f x + g x := by
70 | obtain ⟨a, ubfa⟩ := ubf
71 | obtain ⟨b, ubgb⟩ := ubg
72 | exact ⟨a + b, fnUb_add ubfa ubgb⟩
73 |
74 | example (ubf : FnHasUb f) (ubg : FnHasUb g) : FnHasUb fun x ↦ f x + g x := by
75 | cases ubf
76 | case intro a ubfa =>
77 | cases ubg
78 | case intro b ubgb =>
79 | exact ⟨a + b, fnUb_add ubfa ubgb⟩
80 |
81 | example (ubf : FnHasUb f) (ubg : FnHasUb g) : FnHasUb fun x ↦ f x + g x := by
82 | cases ubf
83 | next a ubfa =>
84 | cases ubg
85 | next b ubgb =>
86 | exact ⟨a + b, fnUb_add ubfa ubgb⟩
87 |
88 | example (ubf : FnHasUb f) (ubg : FnHasUb g) : FnHasUb fun x ↦ f x + g x := by
89 | match ubf, ubg with
90 | | ⟨a, ubfa⟩, ⟨b, ubgb⟩ =>
91 | exact ⟨a + b, fnUb_add ubfa ubgb⟩
92 |
93 | example (ubf : FnHasUb f) (ubg : FnHasUb g) : FnHasUb fun x ↦ f x + g x :=
94 | match ubf, ubg with
95 | | ⟨a, ubfa⟩, ⟨b, ubgb⟩ =>
96 | ⟨a + b, fnUb_add ubfa ubgb⟩
97 |
98 | section
99 |
100 | variable {α : Type*} [CommRing α]
101 |
102 | def SumOfSquares (x : α) :=
103 | ∃ a b, x = a ^ 2 + b ^ 2
104 |
105 | theorem sumOfSquares_mul {x y : α} (sosx : SumOfSquares x) (sosy : SumOfSquares y) :
106 | SumOfSquares (x * y) := by
107 | rcases sosx with ⟨a, b, xeq⟩
108 | rcases sosy with ⟨c, d, yeq⟩
109 | rw [xeq, yeq]
110 | use a * c - b * d, a * d + b * c
111 | ring
112 |
113 | theorem sumOfSquares_mul' {x y : α} (sosx : SumOfSquares x) (sosy : SumOfSquares y) :
114 | SumOfSquares (x * y) := by
115 | rcases sosx with ⟨a, b, rfl⟩
116 | rcases sosy with ⟨c, d, rfl⟩
117 | use a * c - b * d, a * d + b * c
118 | ring
119 |
120 | end
121 |
122 | section
123 | variable {a b c : ℕ}
124 |
125 | example (divab : a ∣ b) (divbc : b ∣ c) : a ∣ c := by
126 | rcases divab with ⟨d, beq⟩
127 | rcases divbc with ⟨e, ceq⟩
128 | rw [ceq, beq]
129 | use d * e; ring
130 |
131 | example (divab : a ∣ b) (divac : a ∣ c) : a ∣ b + c := by
132 | sorry
133 |
134 | end
135 |
136 | section
137 |
138 | open Function
139 |
140 | example {c : ℝ} : Surjective fun x ↦ x + c := by
141 | intro x
142 | use x - c
143 | dsimp; ring
144 |
145 | example {c : ℝ} (h : c ≠ 0) : Surjective fun x ↦ c * x := by
146 | sorry
147 |
148 | example (x y : ℝ) (h : x - y ≠ 0) : (x ^ 2 - y ^ 2) / (x - y) = x + y := by
149 | field_simp [h]
150 | ring
151 |
152 | example {f : ℝ → ℝ} (h : Surjective f) : ∃ x, f x ^ 2 = 4 := by
153 | rcases h 2 with ⟨x, hx⟩
154 | use x
155 | rw [hx]
156 | norm_num
157 |
158 | end
159 |
160 | section
161 | open Function
162 | variable {α : Type*} {β : Type*} {γ : Type*}
163 | variable {g : β → γ} {f : α → β}
164 |
165 | example (surjg : Surjective g) (surjf : Surjective f) : Surjective fun x ↦ g (f x) := by
166 | sorry
167 |
168 | end
169 |
--------------------------------------------------------------------------------
/MIL/C06_Discrete_Mathematics/solutions/Solutions_S03_Inductive_Structures.lean:
--------------------------------------------------------------------------------
1 | import Mathlib.Tactic
2 |
3 | namespace MyListSpace3
4 |
5 | variable {α β γ : Type*}
6 | variable (as bs cs : List α)
7 | variable (a b c : α)
8 |
9 | open List
10 |
11 | def reverse : List α → List α
12 | | [] => []
13 | | a :: as => reverse as ++ [a]
14 |
15 | theorem reverse_append (as bs : List α) : reverse (as ++ bs) = reverse bs ++ reverse as := by
16 | induction' as with a as ih
17 | . rw [nil_append, reverse, append_nil]
18 | rw [cons_append, reverse, ih, reverse, append_assoc]
19 |
20 | theorem reverse_reverse (as : List α) : reverse (reverse as) = as := by
21 | induction' as with a as ih
22 | . rfl
23 | rw [reverse, reverse_append, ih, reverse, reverse, nil_append, cons_append, nil_append]
24 |
25 | end MyListSpace3
26 |
27 | inductive BinTree where
28 | | empty : BinTree
29 | | node : BinTree → BinTree → BinTree
30 |
31 | namespace BinTree
32 |
33 | def size : BinTree → ℕ
34 | | empty => 0
35 | | node l r => size l + size r + 1
36 |
37 | def depth : BinTree → ℕ
38 | | empty => 0
39 | | node l r => max (depth l) (depth r) + 1
40 |
41 | theorem depth_le_size : ∀ t : BinTree, depth t ≤ size t
42 | | BinTree.empty => Nat.zero_le _
43 | | BinTree.node l r => by
44 | simp only [depth, size, add_le_add_iff_right, max_le_iff]
45 | constructor
46 | . apply le_add_right
47 | apply depth_le_size
48 | . apply le_add_left
49 | apply depth_le_size
50 |
51 | def flip : BinTree → BinTree
52 | | empty => empty
53 | | node l r => node (flip r) (flip l)
54 |
55 | example: flip (node (node empty (node empty empty)) (node empty empty)) =
56 | node (node empty empty) (node (node empty empty) empty) := rfl
57 |
58 | theorem size_flip : ∀ t, size (flip t) = size t
59 | | empty => rfl
60 | | node l r => by
61 | dsimp [size, flip]
62 | rw [size_flip l, size_flip r]; omega
63 |
64 | end BinTree
65 |
66 | inductive PropForm : Type where
67 | | var (n : ℕ) : PropForm
68 | | fls : PropForm
69 | | conj (A B : PropForm) : PropForm
70 | | disj (A B : PropForm) : PropForm
71 | | impl (A B : PropForm) : PropForm
72 | namespace PropForm
73 |
74 | def eval : PropForm → (ℕ → Bool) → Bool
75 | | var n, v => v n
76 | | fls, _ => false
77 | | conj A B, v => A.eval v && B.eval v
78 | | disj A B, v => A.eval v || B.eval v
79 | | impl A B, v => ! A.eval v || B.eval v
80 |
81 | def vars : PropForm → Finset ℕ
82 | | var n => {n}
83 | | fls => ∅
84 | | conj A B => A.vars ∪ B.vars
85 | | disj A B => A.vars ∪ B.vars
86 | | impl A B => A.vars ∪ B.vars
87 |
88 | def subst : PropForm → ℕ → PropForm → PropForm
89 | | var n, m, C => if n = m then C else var n
90 | | fls, _, _ => fls
91 | | conj A B, m, C => conj (A.subst m C) (B.subst m C)
92 | | disj A B, m, C => disj (A.subst m C) (B.subst m C)
93 | | impl A B, m, C => impl (A.subst m C) (B.subst m C)
94 |
95 | theorem subst_eq_of_not_mem_vars :
96 | ∀ (A : PropForm) (n : ℕ) (C : PropForm), n ∉ A.vars → A.subst n C = A
97 | | var m, n, C, h => by simp_all [subst, vars]; tauto
98 | | fls, n, C, _ => by rw [subst]
99 | | conj A B, n, C, h => by
100 | simp_all [subst, vars, subst_eq_of_not_mem_vars A, subst_eq_of_not_mem_vars B]
101 | | disj A B, n, C, h => by
102 | simp_all [subst, vars, subst_eq_of_not_mem_vars A, subst_eq_of_not_mem_vars B]
103 | | impl A B, n, C, h => by
104 | simp_all [subst, vars, subst_eq_of_not_mem_vars A, subst_eq_of_not_mem_vars B]
105 |
106 | -- alternative proof:
107 | theorem subst_eq_of_not_mem_vars' (A : PropForm) (n : ℕ) (C : PropForm):
108 | n ∉ A.vars → A.subst n C = A := by
109 | cases A <;> simp_all [subst, vars, subst_eq_of_not_mem_vars']; tauto
110 |
111 | theorem subst_eval_eq : ∀ (A : PropForm) (n : ℕ) (C : PropForm) (v : ℕ → Bool),
112 | (A.subst n C).eval v = A.eval (fun m => if m = n then C.eval v else v m)
113 | | var m, n, C, v => by
114 | simp [subst, eval]
115 | split <;> simp [eval]
116 | | fls, n, C, v => by
117 | simp [subst, eval]
118 | | conj A B, n, C, v => by
119 | simp [subst, eval, subst_eval_eq A n C v, subst_eval_eq B n C v]
120 | | disj A B, n, C, v => by
121 | simp [subst, eval, subst_eval_eq A n C v, subst_eval_eq B n C v]
122 | | impl A B, n, C, v => by
123 | simp [subst, eval, subst_eval_eq A n C v, subst_eval_eq B n C v]
124 |
125 | -- alternative proof:
126 | theorem subst_eval_eq' (A : PropForm) (n : ℕ) (C : PropForm) (v : ℕ → Bool) :
127 | (A.subst n C).eval v = A.eval (fun m => if m = n then C.eval v else v m) := by
128 | cases A <;> simp [subst, eval, subst_eval_eq'];
129 | split <;> simp_all [eval]
130 |
131 | end PropForm
132 |
--------------------------------------------------------------------------------
/MIL/C03_Logic/S01_Implication_and_the_Universal_Quantifier.lean:
--------------------------------------------------------------------------------
1 | import MIL.Common
2 | import Mathlib.Data.Real.Basic
3 |
4 | namespace C03S01
5 |
6 | #check ∀ x : ℝ, 0 ≤ x → |x| = x
7 |
8 | #check ∀ x y ε : ℝ, 0 < ε → ε ≤ 1 → |x| < ε → |y| < ε → |x * y| < ε
9 |
10 | theorem my_lemma : ∀ x y ε : ℝ, 0 < ε → ε ≤ 1 → |x| < ε → |y| < ε → |x * y| < ε :=
11 | sorry
12 |
13 | section
14 | variable (a b δ : ℝ)
15 | variable (h₀ : 0 < δ) (h₁ : δ ≤ 1)
16 | variable (ha : |a| < δ) (hb : |b| < δ)
17 |
18 | #check my_lemma a b δ
19 | #check my_lemma a b δ h₀ h₁
20 | #check my_lemma a b δ h₀ h₁ ha hb
21 |
22 | end
23 |
24 | theorem my_lemma2 : ∀ {x y ε : ℝ}, 0 < ε → ε ≤ 1 → |x| < ε → |y| < ε → |x * y| < ε :=
25 | sorry
26 |
27 | section
28 | variable (a b δ : ℝ)
29 | variable (h₀ : 0 < δ) (h₁ : δ ≤ 1)
30 | variable (ha : |a| < δ) (hb : |b| < δ)
31 |
32 | #check my_lemma2 h₀ h₁ ha hb
33 |
34 | end
35 |
36 | theorem my_lemma3 :
37 | ∀ {x y ε : ℝ}, 0 < ε → ε ≤ 1 → |x| < ε → |y| < ε → |x * y| < ε := by
38 | intro x y ε epos ele1 xlt ylt
39 | sorry
40 |
41 | theorem my_lemma4 :
42 | ∀ {x y ε : ℝ}, 0 < ε → ε ≤ 1 → |x| < ε → |y| < ε → |x * y| < ε := by
43 | intro x y ε epos ele1 xlt ylt
44 | calc
45 | |x * y| = |x| * |y| := sorry
46 | _ ≤ |x| * ε := sorry
47 | _ < 1 * ε := sorry
48 | _ = ε := sorry
49 |
50 | def FnUb (f : ℝ → ℝ) (a : ℝ) : Prop :=
51 | ∀ x, f x ≤ a
52 |
53 | def FnLb (f : ℝ → ℝ) (a : ℝ) : Prop :=
54 | ∀ x, a ≤ f x
55 |
56 | section
57 | variable (f g : ℝ → ℝ) (a b : ℝ)
58 |
59 | example (hfa : FnUb f a) (hgb : FnUb g b) : FnUb (fun x ↦ f x + g x) (a + b) := by
60 | intro x
61 | dsimp
62 | apply add_le_add
63 | apply hfa
64 | apply hgb
65 |
66 | example (hfa : FnLb f a) (hgb : FnLb g b) : FnLb (fun x ↦ f x + g x) (a + b) :=
67 | sorry
68 |
69 | example (nnf : FnLb f 0) (nng : FnLb g 0) : FnLb (fun x ↦ f x * g x) 0 :=
70 | sorry
71 |
72 | example (hfa : FnUb f a) (hgb : FnUb g b) (nng : FnLb g 0) (nna : 0 ≤ a) :
73 | FnUb (fun x ↦ f x * g x) (a * b) :=
74 | sorry
75 |
76 | end
77 |
78 | section
79 | variable {α : Type*} {R : Type*} [AddCommMonoid R] [PartialOrder R] [IsOrderedCancelAddMonoid R]
80 |
81 | #check add_le_add
82 |
83 | def FnUb' (f : α → R) (a : R) : Prop :=
84 | ∀ x, f x ≤ a
85 |
86 | theorem fnUb_add {f g : α → R} {a b : R} (hfa : FnUb' f a) (hgb : FnUb' g b) :
87 | FnUb' (fun x ↦ f x + g x) (a + b) := fun x ↦ add_le_add (hfa x) (hgb x)
88 |
89 | end
90 |
91 | example (f : ℝ → ℝ) (h : Monotone f) : ∀ {a b}, a ≤ b → f a ≤ f b :=
92 | @h
93 |
94 | section
95 | variable (f g : ℝ → ℝ)
96 |
97 | example (mf : Monotone f) (mg : Monotone g) : Monotone fun x ↦ f x + g x := by
98 | intro a b aleb
99 | apply add_le_add
100 | apply mf aleb
101 | apply mg aleb
102 |
103 | example (mf : Monotone f) (mg : Monotone g) : Monotone fun x ↦ f x + g x :=
104 | fun a b aleb ↦ add_le_add (mf aleb) (mg aleb)
105 |
106 | example {c : ℝ} (mf : Monotone f) (nnc : 0 ≤ c) : Monotone fun x ↦ c * f x :=
107 | sorry
108 |
109 | example (mf : Monotone f) (mg : Monotone g) : Monotone fun x ↦ f (g x) :=
110 | sorry
111 |
112 | def FnEven (f : ℝ → ℝ) : Prop :=
113 | ∀ x, f x = f (-x)
114 |
115 | def FnOdd (f : ℝ → ℝ) : Prop :=
116 | ∀ x, f x = -f (-x)
117 |
118 | example (ef : FnEven f) (eg : FnEven g) : FnEven fun x ↦ f x + g x := by
119 | intro x
120 | calc
121 | (fun x ↦ f x + g x) x = f x + g x := rfl
122 | _ = f (-x) + g (-x) := by rw [ef, eg]
123 |
124 |
125 | example (of : FnOdd f) (og : FnOdd g) : FnEven fun x ↦ f x * g x := by
126 | sorry
127 |
128 | example (ef : FnEven f) (og : FnOdd g) : FnOdd fun x ↦ f x * g x := by
129 | sorry
130 |
131 | example (ef : FnEven f) (og : FnOdd g) : FnEven fun x ↦ f (g x) := by
132 | sorry
133 |
134 | end
135 |
136 | section
137 |
138 | variable {α : Type*} (r s t : Set α)
139 |
140 | example : s ⊆ s := by
141 | intro x xs
142 | exact xs
143 |
144 | theorem Subset.refl : s ⊆ s := fun x xs ↦ xs
145 |
146 | theorem Subset.trans : r ⊆ s → s ⊆ t → r ⊆ t := by
147 | sorry
148 |
149 | end
150 |
151 | section
152 | variable {α : Type*} [PartialOrder α]
153 | variable (s : Set α) (a b : α)
154 |
155 | def SetUb (s : Set α) (a : α) :=
156 | ∀ x, x ∈ s → x ≤ a
157 |
158 | example (h : SetUb s a) (h' : a ≤ b) : SetUb s b :=
159 | sorry
160 |
161 | end
162 |
163 | section
164 |
165 | open Function
166 |
167 | example (c : ℝ) : Injective fun x ↦ x + c := by
168 | intro x₁ x₂ h'
169 | exact (add_left_inj c).mp h'
170 |
171 | example {c : ℝ} (h : c ≠ 0) : Injective fun x ↦ c * x := by
172 | sorry
173 |
174 | variable {α : Type*} {β : Type*} {γ : Type*}
175 | variable {g : β → γ} {f : α → β}
176 |
177 | example (injg : Injective g) (injf : Injective f) : Injective fun x ↦ g (f x) := by
178 | sorry
179 |
180 | end
181 |
--------------------------------------------------------------------------------