├── .gitignore ├── lean-toolchain ├── HarmonicLean ├── Imports.lean ├── Attrs.lean ├── StatementOnly_IMO2025P3.lean ├── StatementOnly_IMO2025P4.lean ├── StatementOnly_IMO2025P6.lean ├── StatementOnly_IMO2025P1.lean ├── StatementOnly_IMO2025P5.lean ├── IMO2025P3.lean ├── IMO2025P5.lean └── IMO2025P4_solve2.lean ├── README.md ├── HarmonicLean.lean ├── lakefile.toml ├── .github └── workflows │ ├── create-release.yml │ ├── lean_action_ci.yml │ └── update.yml └── lake-manifest.json /.gitignore: -------------------------------------------------------------------------------- 1 | /.lake 2 | -------------------------------------------------------------------------------- /lean-toolchain: -------------------------------------------------------------------------------- 1 | leanprover/lean4:v4.20.0-rc5 2 | -------------------------------------------------------------------------------- /HarmonicLean/Imports.lean: -------------------------------------------------------------------------------- 1 | import HarmonicLean.Attrs 2 | -------------------------------------------------------------------------------- /HarmonicLean/Attrs.lean: -------------------------------------------------------------------------------- 1 | import Mathlib 2 | 3 | attribute [simp] Nat.ModEq.refl -- `Int.ModEq.refl` is already `simp` in Mathlib 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Harmonic's IMO 2025 Results 2 | 3 | Harmonic's model Aristotle achieved gold medal performance, solving 5 problems. This repository contains the lean statement files and proofs for Problems 1-5. 4 | -------------------------------------------------------------------------------- /HarmonicLean.lean: -------------------------------------------------------------------------------- 1 | import HarmonicLean.StatementOnly_IMO2025P1 2 | import HarmonicLean.StatementOnly_IMO2025P3 3 | import HarmonicLean.StatementOnly_IMO2025P4 4 | import HarmonicLean.StatementOnly_IMO2025P5 5 | import HarmonicLean.StatementOnly_IMO2025P6 6 | import HarmonicLean.IMO2025P1 7 | import HarmonicLean.IMO2025P3 8 | import HarmonicLean.IMO2025P4 9 | import HarmonicLean.IMO2025P4_Solve2 10 | import HarmonicLean.IMO2025P5 11 | -------------------------------------------------------------------------------- /lakefile.toml: -------------------------------------------------------------------------------- 1 | name = "harmonic-imo-2025" 2 | version = "0.1.0" 3 | keywords = ["aristotle"] 4 | defaultTargets = ["HarmonicLean"] 5 | 6 | [leanOptions] 7 | pp.unicode.fun = true # pretty-prints `fun a ↦ b` 8 | autoImplicit = false 9 | relaxedAutoImplicit = false 10 | weak.linter.mathlibStandardSet = true 11 | maxSynthPendingDepth = 3 12 | 13 | [[require]] 14 | name = "mathlib" 15 | scope = "leanprover-community" 16 | rev = "v4.20.0-rc5" 17 | 18 | [[lean_lib]] 19 | name = "HarmonicLean" 20 | -------------------------------------------------------------------------------- /.github/workflows/create-release.yml: -------------------------------------------------------------------------------- 1 | name: Create Release 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'main' 7 | - 'master' 8 | paths: 9 | - 'lean-toolchain' 10 | 11 | jobs: 12 | lean-release-tag: 13 | name: Add Lean release tag 14 | runs-on: ubuntu-latest 15 | permissions: 16 | contents: write 17 | steps: 18 | - name: lean-release-tag action 19 | uses: leanprover-community/lean-release-tag@v1 20 | with: 21 | do-release: true 22 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 23 | -------------------------------------------------------------------------------- /.github/workflows/lean_action_ci.yml: -------------------------------------------------------------------------------- 1 | name: Lean Action CI 2 | 3 | on: 4 | push: 5 | pull_request: 6 | workflow_dispatch: 7 | 8 | # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages 9 | permissions: 10 | contents: read # Read access to repository contents 11 | pages: write # Write access to GitHub Pages 12 | id-token: write # Write access to ID tokens 13 | 14 | jobs: 15 | build: 16 | runs-on: ubuntu-latest 17 | 18 | steps: 19 | - uses: actions/checkout@v4 20 | - uses: leanprover/lean-action@v1 21 | - uses: leanprover-community/docgen-action@v1 22 | -------------------------------------------------------------------------------- /HarmonicLean/StatementOnly_IMO2025P3.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Let $\mathbb{N}$ denote the set of positive integers. 3 | A function $f\colon\mathbb{N} \to \mathbb{N}$ is said to be \emph{bonza} if 4 | $$ f(a) \ \ \text{divides} \ \ b^a - f(b)^{f(a)} $$ 5 | for all positive integers $a$ and $b$. 6 | Determine the smallest real constant $c$ such that 7 | $f(n)\leqslant cn$ for all bonza functions $f$ and all positive integers $n$. 8 | Answer: 4 9 | -/ 10 | 11 | import HarmonicLean.Imports 12 | 13 | open scoped BigOperators 14 | open scoped Real 15 | open scoped Nat 16 | open scoped Classical 17 | open scoped Pointwise 18 | 19 | set_option maxHeartbeats 0 20 | set_option maxRecDepth 4000 21 | set_option synthInstance.maxHeartbeats 20000 22 | set_option synthInstance.maxSize 128 23 | 24 | set_option pp.fullNames true 25 | set_option pp.structureInstances true 26 | 27 | set_option relaxedAutoImplicit false 28 | set_option autoImplicit false 29 | 30 | set_option pp.coercions.types true 31 | set_option pp.funBinderTypes true 32 | set_option pp.letVarTypes true 33 | set_option pp.piBinderTypes true 34 | 35 | set_option linter.all false 36 | 37 | noncomputable section 38 | 39 | namespace IMO2025P3Statement 40 | 41 | theorem main_theorem (IsBonza : (ℕ+ → ℕ+) → Prop) 42 | (hisBonza : ∀ f, IsBonza f ↔ ∀ a b : ℕ+, (b : ℕ) ^ (a : ℕ) ≡ (f b : ℕ) ^ (f a : ℕ) [MOD f a]) : 43 | IsLeast {c : ℝ | ∀ f, IsBonza f → ∀ n : ℕ+, (f n : ℝ) ≤ c * (n : ℝ)} 4 := by 44 | sorry 45 | -------------------------------------------------------------------------------- /HarmonicLean/StatementOnly_IMO2025P4.lean: -------------------------------------------------------------------------------- 1 | /- 2 | A proper divisor of a positive integer $N$ is a positive divisor of $N$ other than $N$ itself. 3 | The infinite sequence $a_1,a_2,\dots$ consists of positive integers, each of which has at least three proper divisors. 4 | For each $n\geqslant 1$, the integer $a_{n+1}$ is the sum of the three largest proper divisors of $a_n$. 5 | Determine all possible values of $a_1$. 6 | Answer: All integers of the form $6 \cdot 12^a \cdot m$, for $a \geq 0$ and $m$ is coprime to 10. 7 | -/ 8 | 9 | import HarmonicLean.Imports 10 | 11 | open scoped BigOperators 12 | open scoped Real 13 | open scoped Nat 14 | open scoped Classical 15 | open scoped Pointwise 16 | 17 | set_option maxHeartbeats 0 18 | set_option maxRecDepth 4000 19 | set_option synthInstance.maxHeartbeats 20000 20 | set_option synthInstance.maxSize 128 21 | 22 | set_option pp.fullNames true 23 | set_option pp.structureInstances true 24 | 25 | set_option relaxedAutoImplicit false 26 | set_option autoImplicit false 27 | 28 | set_option pp.coercions.types true 29 | set_option pp.funBinderTypes true 30 | set_option pp.letVarTypes true 31 | set_option pp.piBinderTypes true 32 | 33 | set_option linter.all false 34 | 35 | noncomputable section 36 | 37 | namespace IMO2025P4Statement 38 | 39 | theorem main_theorem : 40 | { a₁ | ∃ a : ℕ → ℕ, 41 | (∀ n, 0 < a n) ∧ 42 | (∀ n, 3 ≤ (a n).properDivisors.card) ∧ 43 | (∀ n, a (n+1) = 44 | ((a n).properDivisors.sort (· ≥ ·))[0]! + 45 | ((a n).properDivisors.sort (· ≥ ·))[1]! + 46 | ((a n).properDivisors.sort (· ≥ ·))[2]!) ∧ 47 | a₁ = a 0 48 | } = { n | ∃ a m, m.Coprime 10 ∧ n = 6 * 12 ^ a * m } := by 49 | sorry 50 | -------------------------------------------------------------------------------- /HarmonicLean/StatementOnly_IMO2025P6.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Consider a 2025×2025 grid of unit squares. Matilda wishes to place on the grid some rectangular 3 | tiles, possibly of different sizes, such that each side of every tile lies on a grid line and 4 | every unit square is covered by at most one tile. 5 | 6 | Determine the minimum number of tiles Matilda needs to place so that each row and each column 7 | of the grid has exactly one unit square that is not covered by any tile. 8 | -/ 9 | 10 | import HarmonicLean.Imports 11 | 12 | open scoped BigOperators 13 | open scoped Real 14 | open scoped Nat 15 | open scoped Classical 16 | open scoped Pointwise 17 | 18 | set_option maxHeartbeats 0 19 | set_option maxRecDepth 4000 20 | set_option synthInstance.maxHeartbeats 20000 21 | set_option synthInstance.maxSize 128 22 | 23 | set_option pp.fullNames true 24 | set_option pp.structureInstances true 25 | 26 | set_option relaxedAutoImplicit false 27 | set_option autoImplicit false 28 | 29 | set_option pp.coercions.types true 30 | set_option pp.funBinderTypes true 31 | set_option pp.letVarTypes true 32 | set_option pp.piBinderTypes true 33 | 34 | set_option linter.all false 35 | 36 | noncomputable section 37 | 38 | namespace IMO2025P6Statement 39 | 40 | noncomputable def _ANSWER_ : ℕ := sorry 41 | 42 | theorem problem_IMO_2025_P6 43 | (GoodCover : Set (Finset (NonemptyInterval (Fin 2025 × Fin 2025)))) 44 | (hGoodCover : ∀ S, S ∈ GoodCover ↔ 45 | Set.PairwiseDisjoint S.toSet SetLike.coe ∧ 46 | (∀ i, ∃! j, (i, j) ∉ ⋃ t ∈ S, (t : Set (Fin 2025 × Fin 2025))) ∧ 47 | (∀ j, ∃! i, (i, j) ∉ ⋃ t ∈ S, (t : Set (Fin 2025 × Fin 2025)))) : 48 | IsLeast (Finset.card '' GoodCover) _ANSWER_ := by 49 | sorry 50 | -------------------------------------------------------------------------------- /HarmonicLean/StatementOnly_IMO2025P1.lean: -------------------------------------------------------------------------------- 1 | /- 2 | A line in the plane is called sunny if it is not parallel to any of the $x$-axis, the $y$-axis, and the line $x+y=0$. 3 | Let $n \geqslant 3$ be a given integer. Determine all nonnegative integers $k$ such that there exist $n$ distinct lines in the plane satisfying both of the following: 4 | - for all positive integers $a$ and $b$ with $a+b \leqslant n+1$, the point $(a, b)$ is on at least one of the lines; and 5 | - exactly $k$ of the $n$ lines are sunny. 6 | 7 | Answer: 0, 1, 3 8 | -/ 9 | 10 | import HarmonicLean.Imports 11 | 12 | open scoped BigOperators 13 | open scoped Real 14 | open scoped Nat 15 | open scoped Classical 16 | open scoped Pointwise 17 | 18 | set_option maxHeartbeats 0 19 | set_option maxRecDepth 4000 20 | set_option synthInstance.maxHeartbeats 20000 21 | set_option synthInstance.maxSize 128 22 | 23 | set_option pp.fullNames true 24 | set_option pp.structureInstances true 25 | 26 | set_option relaxedAutoImplicit false 27 | set_option autoImplicit false 28 | 29 | set_option pp.coercions.types true 30 | set_option pp.funBinderTypes true 31 | set_option pp.letVarTypes true 32 | set_option pp.piBinderTypes true 33 | 34 | set_option linter.all false 35 | 36 | noncomputable section 37 | 38 | namespace IMO2025P1Statement 39 | 40 | theorem main_theorem 41 | (n : ℕ) 42 | (hn : n ≥ 3) : 43 | {0, 1, 3} = { k | ∃ lines : Finset (Set (ℝ × ℝ)), 44 | (∀ line ∈ lines, ∃ a b c, ¬ (a = 0 ∧ b = 0) ∧ line = { v : ℝ × ℝ | a * v.1 + b * v.2 + c = 0 }) ∧ 45 | lines.card = n ∧ 46 | (∀ a b : ℕ, 0 < a ∧ 0 < b ∧ a + b ≤ n + 1 → ∃ (l : Set (ℝ × ℝ)), l ∈ lines ∧ ((a : ℝ), (b : ℝ)) ∈ l) ∧ 47 | ((lines.filter (fun l => ∃ a b c, l = { v : ℝ × ℝ | a * v.1 + b * v.2 + c = 0 } ∧ a ≠ 0 ∧ b ≠ 0 ∧ a ≠ b)).card = k) } := by 48 | sorry 49 | -------------------------------------------------------------------------------- /.github/workflows/update.yml: -------------------------------------------------------------------------------- 1 | name: Update Dependencies 2 | 3 | on: 4 | # schedule: # Sets a schedule to trigger the workflow 5 | # - cron: "0 8 * * *" # Every day at 08:00 AM UTC (see https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#schedule) 6 | workflow_dispatch: # Allows the workflow to be triggered manually via the GitHub interface 7 | 8 | jobs: 9 | check-for-updates: # Determines which updates to apply. 10 | runs-on: ubuntu-latest 11 | outputs: 12 | is-update-available: ${{ steps.check-for-updates.outputs.is-update-available }} 13 | new-tags: ${{ steps.check-for-updates.outputs.new-tags }} 14 | steps: 15 | - name: Run the action 16 | id: check-for-updates 17 | uses: leanprover-community/mathlib-update-action@v1 18 | # START CONFIGURATION BLOCK 1 19 | # END CONFIGURATION BLOCK 1 20 | do-update: # Runs the upgrade, tests it, and makes a PR/issue/commit. 21 | runs-on: ubuntu-latest 22 | permissions: 23 | contents: write # Grants permission to push changes to the repository 24 | issues: write # Grants permission to create or update issues 25 | pull-requests: write # Grants permission to create or update pull requests 26 | needs: check-for-updates 27 | if: ${{ needs.check-for-updates.outputs.is-update-available }} 28 | strategy: # Runs for each update discovered by the `check-for-updates` job. 29 | max-parallel: 1 # Ensures that the PRs/issues are created in order. 30 | matrix: 31 | tag: ${{ fromJSON(needs.check-for-updates.outputs.new-tags) }} 32 | steps: 33 | - name: Run the action 34 | id: update-the-repo 35 | uses: leanprover-community/mathlib-update-action/do-update@v1 36 | with: 37 | tag: ${{ matrix.tag }} 38 | # START CONFIGURATION BLOCK 2 39 | on_update_succeeds: pr # Create a pull request if the update succeeds 40 | on_update_fails: issue # Create an issue if the update fails 41 | # END CONFIGURATION BLOCK 2 42 | -------------------------------------------------------------------------------- /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": "leanprover-community", 8 | "rev": "4e685d14db58b1ab29024bb0761902a3615f3f14", 9 | "name": "mathlib", 10 | "manifestFile": "lake-manifest.json", 11 | "inputRev": "v4.20.0-rc5", 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": "304c5e2f490d546134c06bf8919e13b175272084", 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": "25078369972d295301f5a1e53c3e5850cf6d9d4c", 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": "f5e58ef1f58fc0cbd92296d18951f45216309e48", 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": "632ca63a94f47dbd5694cac3fd991354b82b8f7a", 49 | "name": "proofwidgets", 50 | "manifestFile": "lake-manifest.json", 51 | "inputRev": "v0.0.59", 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": "9264d548cf1ccf0ba454b82f931f44c37c299fc1", 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": "36ce5e17d6ab3c881e0cb1bb727982507e708130", 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": "78e1181c4752c7e10874d2ed5a6a15063f4a35b6", 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": "4f22c09e7ded721e6ecd3cf59221c4647ca49664", 89 | "name": "Cli", 90 | "manifestFile": "lake-manifest.json", 91 | "inputRev": "main", 92 | "inherited": true, 93 | "configFile": "lakefile.toml"}], 94 | "name": "«harmonic-imo-2025»", 95 | "lakeDir": ".lake"} 96 | -------------------------------------------------------------------------------- /HarmonicLean/StatementOnly_IMO2025P5.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Alice and Bazza are playing the \emph{inekoalaty game}, a two-player game whose rules depend on a positive real number $\lambda$ which is known to both players. On the $n^\text{th}$ turn of the game (starting with $n=1$) the following happens: 3 | \begin{itemize} 4 | \item If $n$ is odd, Alice chooses a nonnegative real number $x_n$ such that 5 | \[ x_1 + x_2 + \dots + x_n \leqslant \lambda n.\] 6 | \item If $n$ is even, Bazza chooses a nonnegative real number $x_n$ such that 7 | \[ x_1^2 + x_2^2 + \dots + x_n^2 \leqslant n.\] 8 | \end{itemize} 9 | If a player cannot choose a suitable number $x_n$, the game ends and the other player wins. If the game goes on forever, neither player wins. All chosen numbers are known to both players. 10 | 11 | Determine all values of $\lambda$ for which Alice has a winning strategy and all those for which Bazza has a winning strategy. 12 | 13 | Answer: Alice wins if $\lambda > 1 / \sqrt{2}$. Bazza wins if $0 < \lambda < 1 / \sqrt{2}$. 14 | -/ 15 | 16 | import HarmonicLean.Imports 17 | 18 | open scoped BigOperators 19 | open scoped Real 20 | open scoped Nat 21 | open scoped Classical 22 | open scoped Pointwise 23 | 24 | set_option maxHeartbeats 0 25 | set_option maxRecDepth 4000 26 | set_option synthInstance.maxHeartbeats 20000 27 | set_option synthInstance.maxSize 128 28 | 29 | set_option pp.fullNames true 30 | set_option pp.structureInstances true 31 | 32 | set_option relaxedAutoImplicit false 33 | set_option autoImplicit false 34 | 35 | set_option pp.coercions.types true 36 | set_option pp.funBinderTypes true 37 | set_option pp.letVarTypes true 38 | set_option pp.piBinderTypes true 39 | 40 | set_option linter.all false 41 | 42 | noncomputable section 43 | 44 | namespace IMO2025P5Statement 45 | 46 | /- Alice's strategy: given a tuple of nonnegative reals of even length, 47 | yields the next number. -/ 48 | abbrev AliceStrategy : Type := ∀ n, (Fin (2 * n) → NNReal) → NNReal 49 | /- Bazza's strategy: given a tuple of nonnegative reals of odd length, 50 | yields the next number. -/ 51 | abbrev BazzaStrategy : Type := ∀ n, (Fin (2 * n + 1) → NNReal) → NNReal 52 | 53 | /- The sequence of numbers produced by a couple of strategies. -/ 54 | def play (alice : AliceStrategy) (bazza : BazzaStrategy) : ℕ → NNReal 55 | | n => 56 | if n % 2 = 0 then alice (n / 2) fun k ↦ play alice bazza k 57 | else bazza (n / 2) fun k ↦ play alice bazza k 58 | 59 | /- 60 | The predicate saying that `n` move in the sequence `xs 0, xs 1, ...` is valid. 61 | For even values of `n`, it checks that `∑ k ≤ n, xs k ≤ lam * (n + 1)`. 62 | For odd values of `n`, it checks that `∑ k ≤ n, (xs k) ^ 2 ≤ n + 1`. 63 | -/ 64 | def ValidMove (lam : ℝ) (xs : ℕ → NNReal) (n : ℕ) : Prop := 65 | if Even n then ∑ k ≤ n, xs k ≤ lam * (n + 1) 66 | else ∑ k ≤ n, (xs k) ^ 2 ≤ n + 1 67 | 68 | /-- The predicate saying that a given Alice's strategy is a winning one. -/ 69 | def AliceStrategy.Wins (lam : ℝ) (alice : AliceStrategy) : Prop := 70 | ∀ bazza, ∃ n, IsLeast {m | ¬ValidMove lam (play alice bazza) m} n ∧ Odd n 71 | 72 | /-- The predicate saying that a given Bazza's strategy is a winning one. -/ 73 | def BazzaStrategy.Wins (lam : ℝ) (bazza : BazzaStrategy) : Prop := 74 | ∀ alice, ∃ n, IsLeast {m | ¬ValidMove lam (play alice bazza) m} n ∧ Even n 75 | 76 | theorem main_theorem : 77 | {lam : ℝ | 0 < lam ∧ ∃ alice : AliceStrategy, alice.Wins lam} = {lam : ℝ | 1 / Real.sqrt 2 < lam} ∧ 78 | {lam : ℝ | 0 < lam ∧ ∃ bazza : BazzaStrategy, bazza.Wins lam} = {lam : ℝ | 0 < lam ∧ lam < 1 / Real.sqrt 2} := by 79 | sorry 80 | -------------------------------------------------------------------------------- /HarmonicLean/IMO2025P3.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Let $\mathbb{N}$ denote the set of positive integers. 3 | A function $f\colon\mathbb{N} \to \mathbb{N}$ is said to be \emph{bonza} if 4 | $$ f(a) \ \ \text{divides} \ \ b^a - f(b)^{f(a)} $$ 5 | for all positive integers $a$ and $b$. 6 | Determine the smallest real constant $c$ such that 7 | $f(n)\leqslant cn$ for all bonza functions $f$ and all positive integers $n$. 8 | Answer: 4 9 | -/ 10 | 11 | import HarmonicLean.Imports 12 | 13 | open scoped BigOperators 14 | open scoped Real 15 | open scoped Nat 16 | open scoped Classical 17 | open scoped Pointwise 18 | 19 | set_option maxHeartbeats 0 20 | set_option maxRecDepth 4000 21 | set_option synthInstance.maxHeartbeats 20000 22 | set_option synthInstance.maxSize 128 23 | 24 | set_option pp.fullNames true 25 | set_option pp.structureInstances true 26 | 27 | set_option relaxedAutoImplicit false 28 | set_option autoImplicit false 29 | 30 | set_option pp.coercions.types true 31 | set_option pp.funBinderTypes true 32 | set_option pp.letVarTypes true 33 | set_option pp.piBinderTypes true 34 | 35 | set_option linter.all false 36 | 37 | noncomputable section 38 | 39 | namespace IMO2025P3 40 | 41 | /- 42 | A function $f\colon\mathbb{N} \to \mathbb{N}$ is said to be \emph{bonza} if 43 | $$f(a) \text{ divides } b^a - f(b)^{f(a)}$$ 44 | for all positive integers $a$ and $b$. 45 | -/ 46 | def isBonza (f : ℕ+ → ℕ+) : Prop := 47 | ∀ a b : ℕ+, (b : ℕ) ^ (a : ℕ) ≡ (f b : ℕ) ^ (f a : ℕ) [MOD f a] 48 | 49 | /- 50 | For a bonza function $f$, let $S$ be the set of prime numbers $p$ for which $f(p) > 1$. 51 | -/ 52 | def S (f : ℕ+ → ℕ+) : Set ℕ+ := 53 | {p | Nat.Prime (p : ℕ) ∧ f p > 1} 54 | 55 | /- 56 | The function $f: \mathbb{N} \to \mathbb{N}$ defined by 57 | $$f(n) = \begin{cases} 58 | 1 & \text{if } n \text{ is odd} \\ 59 | 4 & \text{if } n \equiv 2 \pmod{4} \\ 60 | 16 & \text{if } n \equiv 0 \pmod{4} 61 | \end{cases}$$ 62 | is a bonza function. 63 | -/ 64 | def f_construction : ℕ+ → ℕ+ := fun n ↦ 65 | if Odd (n : ℕ) then 66 | 1 67 | else if (n : ℕ) % 4 = 2 then 68 | 4 69 | else 70 | 16 71 | 72 | /- 73 | If $f$ is a bonza function, then $f(n) \mid n^n$ for all $n \in \mathbb{N}$. 74 | -/ 75 | lemma f_n_divides_n_n (f : ℕ+ → ℕ+) (h : isBonza f) (n : ℕ+) : (f n : ℕ) ∣ (n : ℕ) ^ (n : ℕ) := by 76 | have := h n n; 77 | exact Nat.dvd_of_mod_eq_zero ( this.symm ▸ Nat.modEq_zero_iff_dvd.mpr ( dvd_pow_self _ ( PNat.ne_zero _ ) ) ) 78 | 79 | /- 80 | If $f$ is a bonza function and $p$ is a prime number, then $f(p)$ must be a power of $p$. 81 | -/ 82 | lemma prime_power_form (f : ℕ+ → ℕ+) (h : isBonza f) (p : ℕ+) (hp : Nat.Prime (p : ℕ)) : 83 | ∃ k : ℕ, (f p : ℕ) = (p : ℕ) ^ k := by 84 | have := h p p; 85 | -- From Lemma 2, we know that f(p) divides p^p. 86 | have h_div : (f p : ℕ) ∣ (p : ℕ) ^ (p : ℕ) := by 87 | exact Nat.dvd_of_mod_eq_zero ( this.symm ▸ Nat.modEq_zero_iff_dvd.mpr ( dvd_pow_self _ ( PNat.ne_zero _ ) ) ); 88 | rw [ Nat.dvd_prime_pow ] at h_div <;> aesop 89 | 90 | lemma construction_bonza : isBonza f_construction := by 91 | -- By definition of $f_construction$, we know that for any $a$, $f(a)$ is either $1$, $4$, or $16$. 92 | have h_cases : ∀ a : ℕ+, f_construction a = 1 ∨ f_construction a = 4 ∨ f_construction a = 16 := by 93 | aesop; 94 | unfold f_construction; 95 | split_ifs <;> simp ( config := { decide := Bool.true } ); 96 | -- Now consider the three cases for $f(a)$ and show that $f(a) \mid b^a - f(b)^{f(a)}$ for all $a$ and $b$. 97 | intros a b 98 | rcases h_cases a with ha | ha | ha; 99 | · -- Since $f_construction a = 1$, the congruence $b^a \equiv f_construction b \pmod{1}$ holds trivially because any integer is congruent to any other integer modulo 1. 100 | simp [ha, Nat.ModEq]; 101 | rw [ Nat.mod_one, Nat.mod_one ]; 102 | · rcases h_cases b with ( hb | hb | hb ) <;> simp_all ( config := { decide := Bool.true } ); 103 | · unfold f_construction at * ; aesop; 104 | · rw [ Nat.odd_iff ] at hb; omega; 105 | · -- Since $b$ is odd, we can write $b = 2k + 1$ for some integer $k$. 106 | obtain ⟨k, hk⟩ : ∃ k : ℕ, b = 2 * k + 1 := hb; 107 | norm_num [ Nat.ModEq, Nat.add_mod, Nat.mul_mod, Nat.pow_mod, hk ]; 108 | rw [ ← Nat.mod_add_div a 4, h_2 ] ; norm_num [ Nat.pow_add, Nat.pow_mul, Nat.mul_mod, Nat.pow_mod ] ; have := Nat.mod_lt k zero_lt_four ; interval_cases k % 4 <;> norm_num; 109 | · rcases Nat.even_or_odd' ( b : ℕ ) with ⟨ c, d | d ⟩ <;> norm_num [ Nat.ModEq, Nat.pow_mod, Nat.mul_mod, d ]; 110 | · rcases a with ( _ | _ | a ) <;> norm_num [ Nat.pow_succ', ← mul_assoc, Nat.mul_mod ] at *; 111 | · contradiction; 112 | · cases ha; 113 | · have := Nat.mod_lt c zero_lt_four; interval_cases c % 4 <;> norm_num [ Nat.pow_mod ] ; 114 | · unfold f_construction at hb; aesop; 115 | · -- Since $f(b) = 16$, we know that $b$ is divisible by $4$. Therefore, $b^{a}$ is divisible by $4^2 = 16$, making $b^{a} \equiv 0 \pmod{4}$. 116 | have hb_div : 4 ∣ (b : ℕ) := by 117 | unfold f_construction at hb; aesop; 118 | exact Nat.dvd_of_mod_eq_zero ( by rw [ Nat.even_iff ] at h; omega ); 119 | norm_num [ Nat.ModEq, Nat.pow_mod, Nat.mod_eq_zero_of_dvd hb_div ]; 120 | · -- Since $a$ is a multiple of 4, we can write $a = 4k$ for some $k \in \mathbb{N}$. 121 | obtain ⟨k, rfl⟩ : ∃ k : ℕ+, a = 4 * k := by 122 | -- Since $a$ is even and $f_construction a = 16$, it follows that $a$ must be a multiple of 4. 123 | have ha_mod : (a : ℕ) % 4 = 0 := by 124 | unfold f_construction at ha ; aesop; 125 | rw [ Nat.even_iff ] at h; omega; 126 | exact PNat.dvd_iff.mpr ( Nat.dvd_of_mod_eq_zero ha_mod ); 127 | cases h_cases b <;> aesop; 128 | · -- Since $b$ is odd, we can write $b = 2m + 1$ for some $m \in \mathbb{N}$. 129 | obtain ⟨m, hm⟩ : ∃ m : ℕ, b = 2 * m + 1 := by 130 | unfold f_construction at h; aesop; 131 | norm_num [ Nat.ModEq, Nat.pow_mul, Nat.pow_mod, hm ]; 132 | norm_num [ Nat.add_mod, Nat.mul_mod, Nat.pow_mod ] ; have := Nat.mod_lt m ( by decide : 0 < 16 ) ; interval_cases m % 16 <;> norm_num; 133 | · unfold f_construction at * ; aesop; 134 | norm_num [ Nat.ModEq, Nat.pow_mul, Nat.pow_mod, h_2 ]; 135 | rw [ ← Nat.mod_mod_of_dvd _ ( by decide : 4 ∣ 16 ) ] at h_2; have := Nat.mod_lt ( b : ℕ ) ( by decide : 0 < 16 ) ; interval_cases ( b : ℕ ) % 16 <;> norm_num at h_2 ⊢; 136 | · -- Since $b$ is a multiple of 4, we can write $b = 4m$ for some $m \in \mathbb{N}$. 137 | obtain ⟨m, rfl⟩ : ∃ m : ℕ+, b = 4 * m := by 138 | unfold f_construction at h_2; 139 | aesop; 140 | exact PNat.dvd_iff.mpr ( show 4 ∣ ( b : ℕ ) from Nat.dvd_of_mod_eq_zero ( by obtain ⟨ m, hm ⟩ := h; omega ) ); 141 | norm_num [ Nat.ModEq, Nat.pow_mul, Nat.mul_mod, Nat.pow_mod ]; 142 | have := Nat.mod_lt ( m : ℕ ) ( by decide : 0 < 16 ) ; interval_cases ( m : ℕ ) % 16 <;> norm_num [ Nat.pow_mod ] ; 143 | 144 | /- 145 | If $f$ is a bonza function for which $S=\{2\}$, then for any odd integer $n>1$, $f(n)=1$. 146 | -/ 147 | lemma odd_n_gives_f_n_one (f : ℕ+ → ℕ+) (h : isBonza f) (hS : S f = {(2 : ℕ+)}) (n : ℕ+) 148 | (hn_odd : Odd (n : ℕ)) (hn_gt_one : n > 1) : 149 | f n = 1 := by 150 | -- Since $n$ is odd and greater than 1, all its prime factors are odd primes. For any odd prime $p$, we have $f(p) = 1$ because $S(f) = \{2\}$. 151 | have h_prime_factors : ∀ p : ℕ+, Nat.Prime p → p ∣ n → f p = 1 := by 152 | rw [ Set.eq_singleton_iff_unique_mem ] at hS; 153 | -- Since $p$ is a prime divisor of $n$ and $n$ is odd, $p$ cannot be $2$. Therefore, $p$ is not in $S(f)$, which implies $f(p) \leq 1$. 154 | intros p hp_prime hp_div 155 | have hp_not_in_S : p ∉ S f := by 156 | intros H; specialize hS; have := hS.2 p H; simp_all ( config := { decide := Bool.true } ) [ PNat.dvd_iff, Nat.prime_dvd_prime_iff_eq ] ; 157 | -- Since $n$ is odd, $2$ cannot divide $n$, leading to a contradiction. 158 | exact absurd hp_div (by simpa [ ← even_iff_two_dvd ] using hn_odd); 159 | unfold S at *; aesop; 160 | -- Since $f(n)$ divides $p^n - 1$ for any prime factor $p$ of $n$, and $p$ divides $n$, it follows that $f(n)$ is coprime with $p$. 161 | have h_coprime : ∀ p : ℕ+, Nat.Prime p → p ∣ n → Nat.gcd (f n) p = 1 := by 162 | intros p hp_prime hp_div 163 | have h_div : (f n : ℕ) ∣ (p : ℕ) ^ (n : ℕ) - 1 := by 164 | have := h n p; 165 | rw [ ← Nat.modEq_zero_iff_dvd ] ; have := this.symm.dvd; simp_all ( config := { decide := Bool.true } ) [ ← ZMod.eq_iff_modEq_nat ] ; 166 | refine' Nat.Coprime.coprime_dvd_left h_div _; 167 | refine' Nat.Coprime.symm ( hp_prime.coprime_iff_not_dvd.mpr _ ); 168 | haveI := Fact.mk hp_prime; simp_all ( config := { decide := Bool.true } ) [ ← ZMod.natCast_zmod_eq_zero_iff_dvd, Nat.cast_sub ( Nat.one_le_pow _ _ hp_prime.pos ) ] ; 169 | -- Since $f(n)$ is coprime with all prime factors of $n$, it must be coprime with $n$ itself. 170 | have h_coprime_n : Nat.gcd (f n) n = 1 := by 171 | refine' Nat.Coprime.symm <| Nat.coprime_of_dvd <| _; 172 | exact fun k hk hk' hk'' => hk.not_dvd_one <| h_coprime ⟨ k, hk.pos ⟩ hk ( PNat.dvd_iff.mpr hk' ) ▸ Nat.dvd_gcd hk'' ( dvd_refl _ ); 173 | -- Since $f(n)$ divides $n^n$ and $f(n)$ is coprime with $n$, it follows that $f(n)$ must divide $1$. 174 | have h_div_one : (f n : ℕ) ∣ (n : ℕ) ^ (n : ℕ) ∧ Nat.gcd (f n) n = 1 → (f n : ℕ) ∣ 1 := by 175 | exact fun h => by have := Nat.dvd_gcd ( dvd_refl _ ) h.1; simp_all ( config := { decide := Bool.true } ) [ Nat.Coprime, Nat.Coprime.pow_right ] ; 176 | exact PNat.eq ( Nat.eq_one_of_dvd_one <| h_div_one ⟨ f_n_divides_n_n f h n, h_coprime_n ⟩ ) 177 | 178 | /- 179 | If $f$ is a bonza function and $p \in S$ (per Definition~\ref{def:S}), then $f(b) \equiv b \pmod{p}$ for all $b \in \mathbb{N}$. 180 | -/ 181 | lemma fermat_congruence (f : ℕ+ → ℕ+) (h : isBonza f) (p : ℕ+) (hp : p ∈ S f) (b : ℕ+) : 182 | (f b : ℕ) ≡ (b : ℕ) [MOD p] := by 183 | -- Since $p$ is a prime and $f(p) > 1$, we know that $f(p)$ is a power of $p$. Let $f(p) = p^k$ for some $k \geq 1$. 184 | obtain ⟨k, hk⟩ : ∃ k : ℕ, (f p : ℕ) = (p : ℕ) ^ k := by 185 | -- Apply the lemma that states $f(p)$ must be a power of $p$ for a bonza function $f$ and a prime $p$. 186 | apply prime_power_form f h p hp.left; 187 | -- Applying the definition of $P(a,b)$ with $a=p$, we get $b^p \equiv f(b)^{f(p)} \pmod{p}$. 188 | have hb_mod_p : (b : ℕ) ^ (p : ℕ) ≡ (f b : ℕ) ^ (f p : ℕ) [MOD p] := by 189 | have hb_mod_p : (b : ℕ) ^ (p : ℕ) ≡ (f b : ℕ) ^ (f p : ℕ) [MOD f p] := by 190 | exact?; 191 | -- Since $p$ divides $f(p)$, the congruence modulo $f(p)$ implies the congruence modulo $p$. 192 | have h_div : (p : ℕ) ∣ (f p : ℕ) := by 193 | rcases k with ( _ | k ) <;> simp_all ( config := { decide := Bool.true } ) [ pow_succ' ]; 194 | have := hp.2; aesop; 195 | exact hb_mod_p.of_dvd h_div; 196 | haveI := Fact.mk hp.left; simp_all ( config := { decide := Bool.true } ) [ ← ZMod.eq_iff_modEq_nat ] ; 197 | 198 | /- 199 | If $f$ is a bonza function for which $S=\{2\}$, and $n$ is an even integer, then $f(n)$ is a power of 2. 200 | -/ 201 | lemma even_n_power_of_two (f : ℕ+ → ℕ+) (h : isBonza f) (hS : S f = {(2 : ℕ+)}) (n : ℕ+) 202 | (hn_even : Even (n : ℕ)) : 203 | ∃ k : ℕ, (f n : ℕ) = 2 ^ k := by 204 | have h_prime_factors : ∀ p : ℕ+, Nat.Prime p → p ≠ 2 → ¬ (p ∣ f n) := by 205 | -- If $p$ divides $f(n)$, then by the definition of $S(f)$, $p$ must be in $S(f)$. 206 | have h_prime_in_S : ∀ p : ℕ+, Nat.Prime p → p ∣ f n → p ∈ S f := by 207 | -- If $p$ divides $f(n)$, then by the definition of $S(f)$, $p$ must be in $S(f)$ because $f(p)$ must be greater than 1. 208 | intros p hp hpn 209 | have h_fp_gt_one : f p > 1 := by 210 | have := h n p; 211 | replace := this.of_dvd ( PNat.dvd_iff.mp hpn ); 212 | rw [ Nat.ModEq, Nat.pow_mod ] at this; rcases p with ( _ | _ | p ) <;> rcases n with ( _ | _ | n ) <;> norm_num at *; 213 | · contradiction; 214 | · exact lt_of_le_of_ne ( PNat.one_le _ ) ( Ne.symm <| by intro t; simp ( config := { decide := Bool.true } ) [ t ] at this ); 215 | -- Since $p$ is a prime and $f(p) > 1$, we can conclude that $p \in S(f)$ by definition. 216 | exact ⟨hp, h_fp_gt_one⟩; 217 | exact fun p pp p2 hpn => p2 <| hS.subset ( h_prime_in_S p pp hpn ); 218 | -- Since $f(n)$ has no prime factors other than 2, it must be a power of 2. 219 | have h_prime_factors_two : ∀ p : ℕ, Nat.Prime p → p ∣ (f n : ℕ) → p = 2 := by 220 | exact fun p pp dp => Classical.not_not.1 fun hp => h_prime_factors ⟨ p, pp.pos ⟩ pp ( ne_of_apply_ne PNat.val hp ) ( PNat.dvd_iff.2 dp ); 221 | rw [ ← Nat.prod_primeFactorsList ( PNat.ne_zero ( f n ) ) ]; 222 | rw [ List.prod_eq_pow_single 2 ] <;> aesop; 223 | exact? 224 | 225 | /- 226 | For a bonza function $f$, any prime $q \notin S$ must satisfy $q \equiv 1 \pmod{p}$ for all $p \in S$. 227 | -/ 228 | lemma S_definition (f : ℕ+ → ℕ+) (h : isBonza f) (q : ℕ+) (hq_prime : Nat.Prime (q : ℕ)) 229 | (hq_not_in_S : q ∉ S f) (p : ℕ+) (hp_in_S : p ∈ S f) : 230 | (q : ℕ) ≡ 1 [MOD p] := by 231 | -- Let's substitute $b = q$ into Lemma fermat_congruence. 232 | have h_subst : (f q : ℕ) ≡ q [MOD p] := by 233 | exact?; 234 | -- From Lemma odd_n_gives_f_n_one, we know that $f(q) = 1$. 235 | have h_fq_one : f q = 1 := by 236 | unfold S at *; aesop; 237 | exact h_subst.symm.trans ( by simp? ( config := { decide := Bool.true } ) [ h_fq_one ] ) 238 | 239 | /- 240 | If $f$ is a bonza function and the set $S$ is finite and non-empty, then $S=\{2\}$. 241 | -/ 242 | lemma finite_S_constraint (f : ℕ+ → ℕ+) (h : isBonza f) (hS_fin : (S f).Finite) 243 | (hS_nonempty : (S f).Nonempty) : 244 | S f = {(2 : ℕ+)} := by 245 | -- Suppose $S$ is non-empty and finite. If $S \neq \{2\}$, it must contain an odd prime, and therefore also 2. 246 | by_cases h_odd_prime : ∃ p ∈ S f, p ≠ 2; 247 | · -- Let $M = \prod_{p \in S} p$. Any prime $q \notin S$ must satisfy $q \equiv 1 \pmod M$. 248 | obtain ⟨p, hp_in_S, hp_odd⟩ : ∃ p ∈ S f, p ≠ 2 := h_odd_prime 249 | have hM : ∀ q : ℕ+, Nat.Prime (q : ℕ) → q ∉ S f → (q : ℕ) ≡ 1 [MOD ∏ p in hS_fin.toFinset, (p : ℕ)] := by 250 | intros q hq_prime hq_not_in_S 251 | have hq_cong : ∀ p ∈ S f, (q : ℕ) ≡ 1 [MOD p] := by 252 | exact?; 253 | simp_all ( config := { decide := Bool.true } ) [ Nat.modEq_iff_dvd ]; 254 | convert Finset.prod_dvd_of_coprime _ _ <;> aesop; 255 | intros p hp q hq hpq; specialize hq_cong p hp; specialize hq_cong ; aesop; 256 | refine' Int.gcd_eq_one_iff_coprime.mp _; 257 | have := Nat.coprime_primes ( show Nat.Prime ( p : ℕ ) from by cases hp; aesop ) ( show Nat.Prime ( q : ℕ ) from by cases hq; aesop ) ; aesop; 258 | -- Let $M = \prod_{p \in S} p$. If $M > 2$, then $M-1 > 1$ and must have a prime divisor $q$. 259 | set M := ∏ p in hS_fin.toFinset, (p : ℕ) 260 | have hM_gt_two : M > 2 → False := by 261 | intro hM_gt_two 262 | obtain ⟨q, hq_prime, hq_div⟩ : ∃ q : ℕ+, Nat.Prime (q : ℕ) ∧ (q : ℕ) ∣ (M - 1) := by 263 | exact ⟨ ⟨ Nat.minFac ( M - 1 ), Nat.minFac_pos _ ⟩, Nat.minFac_prime ( Nat.ne_of_gt <| lt_tsub_iff_left.mpr <| by linarith ), Nat.minFac_dvd _ ⟩; 264 | -- Since $q \mid M - 1$, we have $q \equiv 1 \pmod M$. 265 | have hq_mod : (q : ℕ) ≡ 1 [MOD M] := by 266 | apply hM q hq_prime; 267 | intro hq_in_S; 268 | have := Nat.dvd_sub' ( show ( q : ℕ ) ∣ M from Finset.dvd_prod_of_mem _ <| hS_fin.mem_toFinset.mpr hq_in_S ) hq_div; 269 | rw [ Nat.sub_sub_self ( by linarith ) ] at this ; aesop; 270 | have := Nat.modEq_iff_dvd.mp hq_mod.symm; 271 | exact absurd ( Int.le_of_dvd ( by simpa using hq_prime.one_lt ) this ) ( by norm_num; linarith [ Nat.sub_add_cancel ( by linarith : 1 ≤ M ), Nat.le_of_dvd ( Nat.sub_pos_of_lt ( by linarith : 1 < M ) ) hq_div ] ); 272 | contrapose! hM_gt_two; aesop; 273 | -- Since $p \in S$ and $p \neq 2$, we have $p \geq 3$. 274 | have hp_ge_three : 3 ≤ (p : ℕ) := by 275 | exact lt_of_le_of_ne ( Nat.succ_le_of_lt ( show ( p : ℕ ) > 1 from Nat.Prime.one_lt hp_in_S.1 ) ) ( Ne.symm <| by simpa only [ Ne, ← PNat.coe_inj ] using hp_odd ); 276 | exact lt_of_lt_of_le hp_ge_three <| Nat.le_of_dvd ( Finset.prod_pos fun x hx => Nat.cast_pos.mpr <| PNat.pos x ) <| Finset.dvd_prod_of_mem _ <| hS_fin.mem_toFinset.mpr hp_in_S; 277 | · exact Set.eq_singleton_iff_nonempty_unique_mem.mpr ⟨ hS_nonempty, fun p hp => Classical.not_not.1 fun hp' => h_odd_prime ⟨ p, hp, hp' ⟩ ⟩ 278 | 279 | /- 280 | If $f$ is a bonza function for which $S=\{2\}$, and $n=2^k m$ with $m$ odd and $k \ge 1$, then $v_2(f(n)) \le k+2$, where $v_2(x)$ denotes the exponent of the highest power of 2 dividing $x$. 281 | -/ 282 | lemma v2_bound_formula (f : ℕ+ → ℕ+) (h : isBonza f) (hS : S f = {(2 : ℕ+)}) (n : ℕ+) 283 | (k m : ℕ) (hk : k ≥ 1) (hm_odd : Odd m) (hn_def : (n : ℕ) = 2 ^ k * m) : 284 | padicValNat 2 (f n : ℕ) ≤ k + 2 := by 285 | -- By Lemma~\ref{lem:even_n_power_of_two}, $f(n)$ must be a power of 2. Let's write $f(n)=2^\ell$. 286 | have h_fn_power_of_two : ∃ ℓ : ℕ, (f n : ℕ) = 2 ^ ℓ := by 287 | -- By Lemma~\ref{lem:even_n_power_of_two}, $f(n)$ must be a power of 2. Let's write $f(n)=2^{\ell}$. 288 | have := even_n_power_of_two f h hS n (show Even (n : ℕ) from by 289 | exact hn_def ▸ even_iff_two_dvd.mpr ( dvd_mul_of_dvd_left ( pow_dvd_pow _ hk ) _ )); 290 | aesop; 291 | -- However, we can also apply the divisibility condition with $n$ and any odd prime $p$. For an odd prime $p$, $P(n,p)$ implies $f(n) \mid p^n - 1$. 292 | have h_divides_odd_prime : ∀ p : ℕ+, Nat.Prime (p : ℕ) → p ≠ 2 → (f n : ℕ) ∣ (p : ℕ) ^ (n : ℕ) - 1 := by 293 | intros p hp_prime hp_ne_two 294 | have h_divides_p : (f n : ℕ) ∣ (p : ℕ) ^ (n : ℕ) - (f p : ℕ) ^ (f n : ℕ) := by 295 | have := h n p; 296 | rw [ ← Nat.modEq_zero_iff_dvd ]; 297 | cases le_total ( ( p : ℕ ) ^ ( n : ℕ ) ) ( ( f p : ℕ ) ^ ( f n : ℕ ) ) <;> simp_all ( config := { decide := Bool.true } ) [ ← ZMod.eq_iff_modEq_nat ]; 298 | -- Since $p$ is an odd prime, we have $f(p) = 1$ by definition of $S$. 299 | have h_fp_one : f p = 1 := by 300 | simp_all ( config := { decide := Bool.true } ) [ Set.eq_singleton_iff_unique_mem ]; 301 | exact le_antisymm ( not_lt.mp fun contra => hp_ne_two <| hS.2 p ⟨ hp_prime, contra ⟩ ) bot_le; 302 | aesop; 303 | -- Applying this with $p=3$, we have $f(n) \mid 3^n - 1 = 3^{2^km} - 1$. 304 | have h_divides_three : (f n : ℕ) ∣ 3 ^ (2 ^ k * m) - 1 := by 305 | simpa [ hn_def ] using h_divides_odd_prime 3 Nat.prime_three ( by decide ); 306 | -- Using the lemma on the 2-adic valuation of $3^{2^t}-1$, we have $v_2(3^{2^k m}-1) = v_2(3^{2^k}-1) + v_2(m)$. 307 | have h_val_three : (padicValNat 2 (3 ^ (2 ^ k * m) - 1)) = (padicValNat 2 (3 ^ (2 ^ k) - 1)) + (padicValNat 2 m) := by 308 | -- Applying the lemma on the 2-adic valuation of $3^{2^t}-1$, we can simplify the expression. 309 | have h_val_simplified : padicValNat 2 (3 ^ (2 ^ k * m) - 1) = padicValNat 2 ((3 ^ (2 ^ k) - 1) * (∑ i in Finset.range m, (3 ^ (2 ^ k)) ^ i)) := by 310 | zify; 311 | norm_num [ mul_geom_sum, pow_mul ]; 312 | rw [ h_val_simplified, padicValNat.mul ] <;> norm_num; 313 | · rw [ padicValNat.eq_zero_of_not_dvd, padicValNat.eq_zero_of_not_dvd ] <;> norm_num [ Nat.dvd_iff_mod_eq_zero, Nat.add_mod, Nat.pow_mod, Finset.sum_nat_mod ]; 314 | · exact Nat.odd_iff.mp hm_odd; 315 | · exact Nat.odd_iff.mp hm_odd; 316 | · exact ne_of_gt ( Nat.sub_pos_of_lt ( one_lt_pow₀ ( by decide ) ( by positivity ) ) ); 317 | · exact ⟨ 0, hm_odd.pos ⟩; 318 | -- Using the lemma on the 2-adic valuation of $3^{2^t}-1$, we have $v_2(3^{2^k}-1) = k+2$. 319 | have h_val_three_k : (padicValNat 2 (3 ^ (2 ^ k) - 1)) = k + 2 := by 320 | refine' Nat.le_induction _ _ k hk; 321 | · native_decide; 322 | · intro n hn ih; rw [ show ( 3 : ℕ ) ^ 2 ^ ( n + 1 ) - 1 = ( 3 ^ 2 ^ n - 1 ) * ( 3 ^ 2 ^ n + 1 ) by convert Nat.sq_sub_sq ( 3 ^ 2 ^ n ) 1 using 1 <;> ring ] ; rw [ padicValNat.mul ( Nat.sub_ne_zero_of_lt ( one_lt_pow₀ ( by decide ) ( by positivity ) ) ) ( by positivity ) ] ; simp +arith +decide [ ih ] ; 323 | rw [ padicValNat ]; 324 | norm_num [ Nat.find_eq_iff ]; 325 | exact ⟨ by rw [ Nat.dvd_iff_mod_eq_zero ] ; rcases n with ( _ | _ | n ) <;> norm_num [ Nat.add_mod, Nat.pow_succ', Nat.pow_mul, Nat.mul_mod, Nat.pow_mod ] at *, by rw [ ← even_iff_two_dvd ] ; simp ( config := { decide := Bool.true } ) [ parity_simps ] ⟩; 326 | have := Nat.factorization_le_iff_dvd ( by aesop ) ( Nat.sub_ne_zero_of_lt ( one_lt_pow₀ ( by decide : 1 < 3 ) ( by aesop ) ) ) |>.2 h_divides_three ; aesop; 327 | simp_all ( config := { decide := Bool.true } ) [ Nat.factorization ]; 328 | replace := this 2 ; simp_all ( config := { decide := Bool.true } ); 329 | erw [ padicValNat.eq_zero_of_not_dvd ( by simpa [ ← even_iff_two_dvd, Nat.one_le_iff_ne_zero, parity_simps ] using hm_odd ) ] at this ; linarith 330 | 331 | /- 332 | If $f$ is a bonza function, then $f(n) \le 4n$ for all $n \in \mathbb{N}$. 333 | -/ 334 | lemma upper_bound_four (f : ℕ+ → ℕ+) (h : isBonza f) (n : ℕ+) : 335 | (f n : ℕ) ≤ 4 * (n : ℕ) := by 336 | -- Consider two cases: $S$ is finite or infinite. 337 | by_cases hS_finite : (S f).Finite; 338 | · -- If $S$ is non-empty and finite, then $S=\{2\}$. 339 | by_cases hS_nonempty : (S f).Nonempty; 340 | · -- Since $S = \{2\}$, we can use the results from the lemmas. For any $n$, if $n$ is odd, then $f(n) = 1$, which is trivially $\leq 4n$. If $n$ is even, then $f(n)$ is a power of 2. 341 | have h_even : ∀ n : ℕ+, Even (n : ℕ) → (f n : ℕ) ≤ 4 * (n : ℕ) := by 342 | -- Since $S = \{2\}$, we can use the results from the lemmas. For any $n$, if $n$ is even, then $f(n)$ is a power of 2. 343 | intros n hn_even 344 | obtain ⟨k, hk⟩ : ∃ k : ℕ, (f n : ℕ) = 2 ^ k := by 345 | have := even_n_power_of_two f h ( by 346 | apply finite_S_constraint; 347 | · assumption; 348 | · assumption; 349 | · assumption ) n hn_even; 350 | exact this; 351 | -- Since $n$ is even, we can write $n = 2^m \cdot l$ where $l$ is odd and $m \geq 1$. 352 | obtain ⟨m, l, hm, hl⟩ : ∃ m l : ℕ, m ≥ 1 ∧ Odd l ∧ (n : ℕ) = 2 ^ m * l := by 353 | use Nat.factorization n 2, n / 2 ^ Nat.factorization n 2; 354 | -- Since $n$ is even, its factorization must include at least one 2, so $m \geq 1$. 355 | have hm_ge_one : 1 ≤ Nat.factorization n 2 := by 356 | exact Nat.pos_of_ne_zero fun h => by simp_all ( config := { decide := Bool.true } ) [ even_iff_two_dvd, Nat.factorization_eq_zero_iff ] ; 357 | exact ⟨ hm_ge_one, by rw [ Nat.odd_iff ] ; exact Nat.mod_two_ne_zero.mp fun contra => absurd ( Nat.dvd_of_mod_eq_zero contra ) ( Nat.not_dvd_ord_compl ( by norm_num ) <| by aesop ), Eq.symm <| Nat.mul_div_cancel' <| Nat.ord_proj_dvd _ _ ⟩; 358 | -- By Lemma~\ref{lem:v2_bound_formula}, we have $v_2(f(n)) \le m + 2$. 359 | have h_v2_bound : k ≤ m + 2 := by 360 | have h_v2_bound : padicValNat 2 (f n : ℕ) ≤ m + 2 := by 361 | -- Applying Lemma~\ref{lem:v2_bound_formula} with $n = 2^m \cdot l$, we get $v_2(f(n)) \le m + 2$. 362 | apply v2_bound_formula; 363 | any_goals tauto; 364 | exact?; 365 | simp_all ( config := { decide := Bool.true } ) [ padicValNat.pow ]; 366 | aesop; 367 | exact le_trans ( pow_le_pow_right₀ ( by decide ) h_v2_bound ) ( by ring_nf; norm_num; nlinarith [ pow_pos ( by decide : 0 < ( 2 : ℕ ) ) m, left.pos ] ); 368 | -- For any odd integer $n$, if $n > 1$, then $f(n) = 1$ by the lemma odd_n_gives_f_n_one. If $n = 1$, then $f(1) = 1$ by the lemma f_one_equals_one. 369 | have h_odd : ∀ n : ℕ+, Odd (n : ℕ) → (f n : ℕ) ≤ 4 * (n : ℕ) := by 370 | intros n hn_odd 371 | by_cases hn_gt_one : n > 1; 372 | · have := odd_n_gives_f_n_one f h ( show S f = { ( 2 : ℕ+ ) } from ?_ ) n hn_odd hn_gt_one; 373 | · aesop; 374 | linarith [ PNat.pos n ]; 375 | · exact?; 376 | · have := h 1 1 ; simp_all ( config := { decide := Bool.true } ) [ Nat.ModEq, Nat.pow_mod ]; 377 | exact if hn : Even ( n : ℕ ) then h_even n hn else h_odd n ( by simpa using hn ); 378 | · -- If $S$ is empty, then $f(p)=1$ for all prime numbers $p$. The condition $P(n,p)$ implies $f(n) \mid p^n - f(p)^{f(n)} = p^n - 1$. Since this holds for all primes $p$, we must have $f(n)=1$. 379 | have h_empty_S : ∀ p : ℕ+, Nat.Prime (p : ℕ) → f p = 1 := by 380 | aesop; 381 | exact le_antisymm ( not_lt.mp fun contra => hS_nonempty ⟨ p, a, contra ⟩ ) bot_le; 382 | -- The condition $P(n,p)$ implies $f(n) \mid p^n - f(p)^{f(n)} = p^n - 1$. Since this holds for all primes $p$, we must have $f(n)=1$. 383 | have h_divides_one : ∀ p : ℕ+, Nat.Prime (p : ℕ) → (f n : ℕ) ∣ (p : ℕ) ^ (n : ℕ) - 1 := by 384 | intro p hp; specialize h n p; aesop; 385 | simpa [ ← Int.natCast_dvd_natCast, Nat.cast_sub ( Nat.one_le_pow _ _ hp.pos ) ] using h.symm.dvd; 386 | -- Since this holds for all primes $p$, we must have $f(n)=1$. 387 | have h_fn_one : f n = 1 := by 388 | -- Assume for contradiction that $f(n) > 1$. Then there exists a prime $q$ such that $q \mid f(n)$. 389 | by_contra h_contra 390 | obtain ⟨q, hq_prime, hq_div⟩ : ∃ q : ℕ, Nat.Prime q ∧ q ∣ (f n : ℕ) := by 391 | exact Nat.exists_prime_and_dvd ( by simpa using h_contra ); 392 | have := Nat.dvd_trans hq_div ( h_divides_one ⟨ q, hq_prime.pos ⟩ hq_prime ); 393 | haveI := Fact.mk hq_prime; simp_all ( config := { decide := Bool.true } ) [ ← ZMod.natCast_zmod_eq_zero_iff_dvd, Nat.cast_sub ( Nat.one_le_pow _ _ hq_prime.pos ) ] ; 394 | simp ( config := { decide := Bool.true } ) [ h_fn_one ]; 395 | linarith [ PNat.pos n ]; 396 | · -- If $f$ is a bonza function for which $S$ is infinite, then $f(n) \le n$ for all $n \in \mathbb{N}$. 397 | have infinite_S_constraint (f : ℕ+ → ℕ+) (h : isBonza f) (hS_inf : (S f).Infinite) : 398 | ∀ n : ℕ+, (f n : ℕ) ≤ n := by 399 | -- Take any $n$. Since $S$ is infinite, there exists a prime $p \in S$ such that $p > f(n)$. 400 | intro n 401 | obtain ⟨p, hpS, hp_gt⟩ : ∃ p ∈ S f, (p : ℕ) > (f n : ℕ) := by 402 | exact Exists.elim ( hS_inf.exists_gt ( f n ) ) fun p hp => ⟨ p, hp.1, hp.2 ⟩; 403 | -- By Lemma~\ref{lem:fermat_congruence}, $f(n) \equiv n \pmod{p}$. 404 | have h_congr : (f n : ℕ) ≡ (n : ℕ) [MOD p] := by 405 | exact?; 406 | rw [ Nat.ModEq ] at h_congr; 407 | contrapose! h_congr; 408 | rw [ Nat.mod_eq_of_lt, Nat.mod_eq_of_lt ] <;> linarith; 409 | exact le_trans ( infinite_S_constraint f h hS_finite n ) ( le_mul_of_one_le_left' ( by decide ) ) 410 | 411 | /- 412 | Let $\mathbb{N}$ denote the set of positive integers. A function $f\colon\mathbb{N} \to \mathbb{N}$ is said to be \emph{bonza} if 413 | $$f(a) \text{ divides } b^a - f(b)^{f(a)}$$ 414 | for all positive integers $a$ and $b$. 415 | The smallest real constant $c$ such that $f(n) \leq cn$ for all bonza functions $f$ and all positive integers $n$ is $4$. 416 | -/ 417 | theorem main_theorem (IsBonza : (ℕ+ → ℕ+) → Prop) 418 | (hisBonza : ∀ f, IsBonza f ↔ ∀ a b : ℕ+, (b : ℕ) ^ (a : ℕ) ≡ (f b : ℕ) ^ (f a : ℕ) [MOD f a]) : 419 | IsLeast {c : ℝ | ∀ f, IsBonza f → ∀ n : ℕ+, (f n : ℝ) ≤ c * (n : ℝ)} 4 := by 420 | -- To prove that 4 is the least such constant, we need to show that for any $c < 4$, there exists a bonza function $f$ and an $n$ such that $f(n) > cn$. 421 | have h_least : ∀ c : ℝ, c < 4 → ∃ f : ℕ+ → ℕ+, IsBonza f ∧ ∃ n : ℕ+, (f n : ℝ) > c * (n : ℝ) := by 422 | -- For any $c < 4$, we can choose the bonza function $f$ defined by $f(n) = 1$ if $n$ is odd, $f(n) = 4$ if $n \equiv 2 \pmod{4}$, and $f(n) = 16$ if $n \equiv 0 \pmod{4}$, and $n = 4$. 423 | intros c hc 424 | use f_construction; 425 | constructor; 426 | · exact hisBonza _ |>.2 construction_bonza; 427 | · exact ⟨ 4, show c * 4 < 16 by linarith ⟩; 428 | constructor; 429 | · aesop; 430 | exact_mod_cast upper_bound_four f ( by aesop ) n; 431 | · exact fun c hc => by contrapose! h_least; tauto; 432 | 433 | #print axioms main_theorem 434 | -------------------------------------------------------------------------------- /HarmonicLean/IMO2025P5.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Alice and Bazza are playing the \emph{inekoalaty game}, a two-player game whose rules depend on a positive real number $\lambda$ which is known to both players. On the $n^\text{th}$ turn of the game (starting with $n=1$) the following happens: 3 | \begin{itemize} 4 | \item If $n$ is odd, Alice chooses a nonnegative real number $x_n$ such that 5 | \[ x_1 + x_2 + \dots + x_n \leqslant \lambda n.\] 6 | \item If $n$ is even, Bazza chooses a nonnegative real number $x_n$ such that 7 | \[ x_1^2 + x_2^2 + \dots + x_n^2 \leqslant n.\] 8 | \end{itemize} 9 | If a player cannot choose a suitable number $x_n$, the game ends and the other player wins. If the game goes on forever, neither player wins. All chosen numbers are known to both players. 10 | 11 | Determine all values of $\lambda$ for which Alice has a winning strategy and all those for which Bazza has a winning strategy. 12 | 13 | Answer: Alice wins if $\lambda > 1 / \sqrt{2}$. Bazza wins if $0 < \lambda < 1 / \sqrt{2}$. 14 | -/ 15 | 16 | import HarmonicLean.Imports 17 | 18 | open scoped BigOperators 19 | open scoped Real 20 | open scoped Nat 21 | open scoped Classical 22 | open scoped Pointwise 23 | 24 | set_option maxHeartbeats 0 25 | set_option maxRecDepth 4000 26 | set_option synthInstance.maxHeartbeats 20000 27 | set_option synthInstance.maxSize 128 28 | 29 | set_option pp.fullNames true 30 | set_option pp.structureInstances true 31 | 32 | set_option relaxedAutoImplicit false 33 | set_option autoImplicit false 34 | 35 | set_option pp.coercions.types true 36 | set_option pp.funBinderTypes true 37 | set_option pp.letVarTypes true 38 | set_option pp.piBinderTypes true 39 | 40 | set_option linter.all false 41 | 42 | noncomputable section 43 | 44 | namespace IMO2025P5 45 | 46 | /- Alice's strategy: given a tuple of nonnegative reals of even length, 47 | yields the next number. -/ 48 | abbrev AliceStrategy : Type := ∀ n, (Fin (2 * n) → NNReal) → NNReal 49 | /- Bazza's strategy: given a tuple of nonnegative reals of odd length, 50 | yields the next number. -/ 51 | abbrev BazzaStrategy : Type := ∀ n, (Fin (2 * n + 1) → NNReal) → NNReal 52 | 53 | /- The sequence of numbers produced by a couple of strategies. -/ 54 | def play (alice : AliceStrategy) (bazza : BazzaStrategy) : ℕ → NNReal 55 | | n => 56 | if n % 2 = 0 then alice (n / 2) fun k ↦ play alice bazza k 57 | else bazza (n / 2) fun k ↦ play alice bazza k 58 | 59 | /- 60 | The predicate saying that `n` move in the sequence `xs 0, xs 1, ...` is valid. 61 | For even values of `n`, it checks that `∑ k ≤ n, xs k ≤ lam * (n + 1)`. 62 | For odd values of `n`, it checks that `∑ k ≤ n, (xs k) ^ 2 ≤ n + 1`. 63 | -/ 64 | def ValidMove (lam : ℝ) (xs : ℕ → NNReal) (n : ℕ) : Prop := 65 | if Even n then ∑ k ≤ n, xs k ≤ lam * (n + 1) 66 | else ∑ k ≤ n, (xs k) ^ 2 ≤ n + 1 67 | 68 | /-- The predicate saying that a given Alice's strategy is a winning one. -/ 69 | def AliceStrategy.Wins (lam : ℝ) (alice : AliceStrategy) : Prop := 70 | ∀ bazza, ∃ n, IsLeast {m | ¬ValidMove lam (play alice bazza) m} n ∧ Odd n 71 | 72 | /-- The predicate saying that a given Bazza's strategy is a winning one. -/ 73 | def BazzaStrategy.Wins (lam : ℝ) (bazza : BazzaStrategy) : Prop := 74 | ∀ alice, ∃ n, IsLeast {m | ¬ValidMove lam (play alice bazza) m} n ∧ Even n 75 | 76 | /- 77 | For a sequence of moves $x_1, x_2, \dots$ in the inekoalaty game, we define the partial sum of values $S_n = \sum_{i=1}^n x_i$ and the partial sum of squares $Q_n = \sum_{i=1}^n x_i^2$. We adopt the convention that $S_0=0$ and $Q_0=0$. 78 | -/ 79 | def s (xs : ℕ → NNReal) (n : ℕ) : ℝ := ∑ i in Finset.range n, (xs i : ℝ) 80 | def q (xs : ℕ → NNReal) (n : ℕ) : ℝ := ∑ i in Finset.range n, (xs i : ℝ) ^ 2 81 | 82 | /- 83 | Bazza's reference strategy is as follows: on his turn $2k$, if he has not already lost (i.e., if $Q_{2k-1} \le 2k$), he chooses $x_{2k} = \sqrt{2k - Q_{2k-1}}$. 84 | -/ 85 | def bazzaReferenceStrategy : BazzaStrategy := fun n hist ↦ 86 | let Q_2n_plus_1 := ∑ i, (hist i : ℝ) ^ 2 87 | let val_sq := (2 * (n + 1) : ℝ) - Q_2n_plus_1 88 | if h : 0 ≤ val_sq then 89 | NNReal.sqrt ⟨val_sq, h⟩ 90 | else 91 | 0 92 | 93 | /- 94 | Let $f(k) = \frac{k\sqrt{2}}{2k-1}$ for $k \ge 1$. 95 | -/ 96 | def f (k : ℕ) : ℝ := (k : ℝ) * Real.sqrt 2 / (2 * (k : ℝ) - 1) 97 | 98 | /- 99 | For a given $\lambda > 1/\sqrt{2}$, Alice's reference strategy is as follows: first, choose an integer $K$ according to Lemma~\ref{lem:existence_of_K_for_alice} such that $\lambda > \frac{K\sqrt{2}}{2K-1}$. 100 | Then, for all turns $2k-1$ with $k < K$, Alice chooses $x_{2k-1}=0$. At turn $2K-1$, Alice chooses $x_{2K-1} = \lambda(2K-1) - S_{2K-2}$. 101 | -/ 102 | def aliceReferenceStrategy (lam : ℝ) (K : ℕ) : AliceStrategy := fun n hist ↦ 103 | if n + 1 < K then 104 | 0 105 | else if n + 1 = K then 106 | let S_2n := ∑ i, (hist i : ℝ) 107 | let move := lam * (2 * (n + 1) - 1) - S_2n 108 | if h_nonneg : 0 ≤ move then 109 | ⟨move, h_nonneg⟩ 110 | else 111 | 0 112 | else 113 | 0 114 | 115 | /- 116 | If Bazza uses his reference strategy (Definition~\ref{def:bazza_strategy}) and can make a move at turn $2k$, then $Q_{2k}=2k$. 117 | -/ 118 | lemma lemBazzaStrategyQValue (n : ℕ) (h : Fin (2 * n + 1) → NNReal) 119 | (h_can_move : (∑ i, (h i : ℝ) ^ 2) ≤ (2 * (n + 1) : ℝ)) : 120 | let x_2np1 := bazzaReferenceStrategy n h 121 | (∑ i, (h i : ℝ) ^ 2) + (x_2np1 : ℝ) ^ 2 = (2 * (n + 1) : ℝ) := by 122 | unfold bazzaReferenceStrategy; 123 | aesop 124 | 125 | /- 126 | If Bazza uses his reference strategy and neither player has won by turn $2k-1$, then $Q_{2k-2} = 2(k-1)$ for $k \ge 2$. For $k=1$, $Q_0=0$ by Definition~\ref{def:sums}. 127 | -/ 128 | lemma lemQ_2k_minus_2_under_bazza_ref (lam : ℝ) (alice : AliceStrategy) (k : ℕ) (hk : 1 ≤ k) 129 | (h_not_won : ∀ m < 2 * k - 2, ValidMove lam (play alice bazzaReferenceStrategy) m) : 130 | q (play alice bazzaReferenceStrategy) (2 * (k - 1)) = (2 * (k - 1) : ℝ) := by 131 | -- For the case when $k = 1$, we have $2 * (k - 1) = 0$, and the sum of squares up to 0 is 0, which matches $2 * (1 - 1) = 0$. 132 | by_cases hk1 : k = 1; 133 | · aesop; 134 | · rcases k with ( _ | _ | k ) <;> simp_all ( config := { decide := Bool.true } ) [ Nat.mul_succ ]; 135 | have h_q_2k : (∑ i in Finset.range (2 * k + 1), (play alice bazzaReferenceStrategy i : ℝ) ^ 2) ≤ (2 * (k + 1) : ℝ) := by 136 | specialize h_not_won ( 2 * k + 1 ) ; unfold ValidMove at h_not_won ; aesop; 137 | norm_cast; 138 | refine le_trans ?_ ( h_not_won.trans ?_ ); 139 | · exact Finset.sum_le_sum_of_subset ( fun x hx => Finset.mem_Iic.mpr ( Finset.mem_range_le hx |> le_trans <| Nat.le_refl _ ) ); 140 | · norm_cast; 141 | -- By definition of $q$, we can write 142 | have h_q_def : q (play alice bazzaReferenceStrategy) (2 * k + 2) = (∑ i in Finset.range (2 * k + 1), (play alice bazzaReferenceStrategy i : ℝ) ^ 2) + (bazzaReferenceStrategy k (fun i => play alice bazzaReferenceStrategy i) : ℝ) ^ 2 := by 143 | unfold q; 144 | rw [Finset.sum_range_succ]; 145 | unfold play; 146 | norm_num +zetaDelta at *; 147 | rw [ show ( 2 * k + 1 ) / 2 = k by omega ]; 148 | congr! 2; 149 | exact?; 150 | convert lemBazzaStrategyQValue k _ _ using 1; 151 | convert h_q_def; 152 | · rw [ Finset.sum_range ]; 153 | · simpa only [ Finset.sum_range ] using h_q_2k 154 | 155 | /- 156 | If Alice does not win at turn $2j-1$ against Bazza's reference strategy, then the sum of that turn's moves is $x_{2j-1}+x_{2j} \ge \sqrt{2}$. 157 | -/ 158 | lemma lemPairSumLowerBound (xs : ℕ → NNReal) (j : ℕ) (hj : 1 ≤ j) 159 | (h_q_prev : q xs (2 * (j - 1)) = (2 * (j - 1) : ℝ)) 160 | (h_bazza_move : xs (2 * j - 1) = bazzaReferenceStrategy (j - 1) fun i ↦ xs i.val) 161 | (h_not_win : ¬ (q xs (2 * j - 1) > (2 * j : ℝ))) : 162 | (xs (2 * j - 2) : ℝ) + (xs (2 * j - 1) : ℝ) ≥ Real.sqrt 2 := by 163 | -- By definition of $bazzaReferenceStrategy$, we know that $x_{2j} = \sqrt{2 - x_{2j-1}^2}$. 164 | have h_bazza_move_value : (xs (2 * j - 1) : ℝ) = Real.sqrt (2 - (xs (2 * j - 2) : ℝ) ^ 2) := by 165 | rcases j with ⟨ _ | j ⟩ <;> simp_all ( config := { decide := Bool.true } ) [ Nat.mul_succ, Finset.sum_range_succ ]; 166 | unfold bazzaReferenceStrategy; 167 | simp_all ( config := { decide := Bool.true } ) [ Fin.sum_univ_castSucc, q ]; 168 | split_ifs <;> simp_all ( config := { decide := Bool.true } ) [ Finset.sum_range ]; 169 | · ring; 170 | · rw [ Real.sqrt_eq_zero_of_nonpos ] ; linarith; 171 | by_cases h_case : (xs (2 * j - 2) : ℝ) ≤ Real.sqrt 2; 172 | · field_simp; 173 | rw [ h_bazza_move_value, Real.sqrt_le_left ]; 174 | · nlinarith only [ Real.sqrt_nonneg ( 2 - ( xs ( 2 * j - 2 ) : ℝ ) ^ 2 ), Real.mul_self_sqrt ( show 0 ≤ 2 - ( xs ( 2 * j - 2 ) : ℝ ) ^ 2 by nlinarith only [ Real.mul_self_sqrt ( show 0 ≤ 2 by norm_num ), h_case, show ( xs ( 2 * j - 2 ) : ℝ ) ≥ 0 by positivity ] ), show ( xs ( 2 * j - 2 ) : ℝ ) ≥ 0 by positivity ]; 175 | · positivity; 176 | · exact le_add_of_le_of_nonneg ( le_of_not_le h_case ) ( NNReal.coe_nonneg _ ) 177 | 178 | /- 179 | If Bazza uses his reference strategy and Alice has not won by turn $2k-1$, then $S_{2k-2} \ge (k-1)\sqrt{2}$ for $k \ge 1$. 180 | -/ 181 | lemma lemSLowerBound (lam : ℝ) (alice : AliceStrategy) (k : ℕ) (hk : 1 ≤ k) 182 | (h_not_won : ∀ m < 2 * k - 2, ValidMove lam (play alice bazzaReferenceStrategy) m) : 183 | s (play alice bazzaReferenceStrategy) (2 * (k - 1)) ≥ ((k - 1) : ℝ) * Real.sqrt 2 := by 184 | -- By Lemma~\ref{lem:pair_sum_lower_bound}, for each $j$ from $1$ to $k-1$, we have $x_{2j-1} + x_{2j} \ge \sqrt{2}$. 185 | have h_pair_sum_lower_bound : ∀ j ∈ Finset.Ico 1 k, (play alice bazzaReferenceStrategy (2 * j - 2) : ℝ) + (play alice bazzaReferenceStrategy (2 * j - 1) : ℝ) ≥ Real.sqrt 2 := by 186 | intro j hj; 187 | apply_rules [ lemPairSumLowerBound ]; 188 | · -- Since $j$ is in the Finset.Ico 1 k, we have $1 \leq j$. 189 | aesop; 190 | · -- Apply the lemma that states if Bazza uses his reference strategy and neither player has won by turn $2k-1$, then $Q_{2k-2} = 2(k-1)$. 191 | apply lemQ_2k_minus_2_under_bazza_ref; 192 | exacts [ Finset.mem_Ico.mp hj |>.1, fun m hm => h_not_won m ( by linarith [ Finset.mem_Ico.mp hj |>.2, Nat.sub_add_cancel ( by linarith [ Finset.mem_Ico.mp hj |>.1, Finset.mem_Ico.mp hj |>.2 ] : 2 ≤ 2 * k ), Nat.sub_add_cancel ( by linarith [ Finset.mem_Ico.mp hj |>.1, Finset.mem_Ico.mp hj |>.2 ] : 2 ≤ 2 * j ) ] ) ]; 193 | · unfold play; 194 | -- Since $2j-1$ is odd, $(2j-1) \% 2 = 1$, so the if condition is false. 195 | have h_odd : (2 * j - 1) % 2 = 1 := by 196 | cases j <;> norm_num [ Nat.add_mod, Nat.mul_succ ] at *; 197 | rw [ if_neg ]; 198 | · rw [ show ( 2 * j - 1 ) / 2 = j - 1 by omega ]; 199 | congr!; 200 | exact?; 201 | · -- Since $h_odd$ states that $(2 * j - 1) \% 2 = 1$, we can directly conclude that $(2 * j - 1) \% 2 \neq 0$. 202 | aesop; 203 | · rcases j with ( _ | j ) <;> simp_all ( config := { decide := Bool.true } ) [ Nat.mul_succ ]; 204 | have := h_not_won ( 2 * j + 1 ) ( by omega ); 205 | unfold ValidMove at this; aesop; 206 | exact le_trans ( Finset.sum_le_sum_of_subset_of_nonneg ( fun i hi => Finset.mem_Iic.mpr ( by linarith [ Finset.mem_range.mp hi ] ) ) fun _ _ _ => sq_nonneg _ ) ( mod_cast this ); 207 | -- By summing the inequalities from h_pair_sum_lower_bound over all j from 1 to k-1, we get the desired result. 208 | have h_sum_pairs : ∑ j in Finset.Ico 1 k, ((play alice bazzaReferenceStrategy (2 * j - 2) : ℝ) + (play alice bazzaReferenceStrategy (2 * j - 1) : ℝ)) ≥ (k - 1) * Real.sqrt 2 := by 209 | exact le_trans ( by norm_num [ hk ] ) ( Finset.sum_le_sum h_pair_sum_lower_bound ); 210 | convert h_sum_pairs using 1; 211 | unfold s; 212 | exact Nat.recOn k ( by norm_num ) fun n ih => by cases n <;> norm_num [ Nat.mul_succ, Finset.sum_range_succ, Finset.sum_Ico_succ_top ] at * ; linarith; 213 | 214 | /- 215 | The limit of $f(k)$ from Definition~\ref{def:f_function} as $k \to \infty$ is $1/\sqrt{2}$. 216 | -/ 217 | lemma lemFLimit : Filter.Tendsto f Filter.atTop (nhds (1 / Real.sqrt 2)) := by 218 | unfold f; 219 | -- We can divide the numerator and the denominator by $k$ and then take the limit as $k$ approaches infinity. 220 | have h_div : Filter.Tendsto (fun k : ℕ => (Real.sqrt 2) / (2 - 1 / (k : ℝ))) Filter.atTop (nhds (Real.sqrt 2 / 2)) := by 221 | exact le_trans ( tendsto_const_nhds.div ( tendsto_const_nhds.sub <| tendsto_one_div_atTop_nhds_zero_nat ) <| by norm_num ) <| by norm_num; 222 | refine Filter.Tendsto.congr' ?_ ( h_div.trans ?_ ); 223 | · filter_upwards [ Filter.eventually_gt_atTop 0 ] with k hk using by simpa [ -one_div, field_simps, hk.ne' ] using by ring; 224 | · norm_num [ Real.sqrt_div_self ] 225 | 226 | /- 227 | If $0 < \lambda < 1/\sqrt{2}$, Bazza has a winning strategy. 228 | -/ 229 | lemma lemBazzaWinsSmallLambda (lam : ℝ) (hlam : 0 < lam ∧ lam < 1 / Real.sqrt 2) : 230 | ∃ bazza, BazzaStrategy.Wins lam bazza := by 231 | -- By Lemma~\ref{lem:alice_cannot_win_small_lambda}, if $\lambda \le 1/\sqrt{2}$, Alice cannot have a winning strategy. Therefore, Bazza's reference strategy must be a winning strategy. 232 | have h_bazza_wins : ∀ alice : AliceStrategy, ∃ n, IsLeast {m | ¬ValidMove lam (play alice bazzaReferenceStrategy) m} n ∧ Even n := by 233 | bound; 234 | by_contra h_contra; 235 | -- If Alice cannot win, then for all $n$, the game continues. 236 | have h_game_continues : ∀ n, ValidMove lam (play alice bazzaReferenceStrategy) n := by 237 | intro n; 238 | induction' n using Nat.strong_induction_on with n ih; 239 | rcases Nat.even_or_odd' n with ⟨ k, rfl | rfl ⟩; 240 | · unfold ValidMove; 241 | contrapose! h_contra; 242 | use 2 * k; 243 | unfold ValidMove; 244 | unfold IsLeast; 245 | aesop; 246 | intro m hm; 247 | contrapose! hm; 248 | unfold ValidMove at ih; aesop; 249 | · have h_q_prev : q (play alice bazzaReferenceStrategy) (2 * k) = (2 * k : ℝ) := by 250 | convert lemQ_2k_minus_2_under_bazza_ref lam alice ( k + 1 ) ( by linarith ) _ using 1; 251 | · norm_num; 252 | · grind; 253 | unfold ValidMove; 254 | have h_not_win : ¬ (q (play alice bazzaReferenceStrategy) (2 * k + 1) > (2 * (k + 1) : ℝ)) := by 255 | have h_not_win : (play alice bazzaReferenceStrategy) (2 * k) ≤ Real.sqrt 2 := by 256 | have h_not_win : (play alice bazzaReferenceStrategy) (2 * k) ≤ lam * (2 * k + 1) - s (play alice bazzaReferenceStrategy) (2 * k) := by 257 | have := ih ( 2 * k ) ( by linarith ) ; unfold ValidMove at this ; aesop; 258 | unfold s; 259 | erw [ Finset.sum_Ico_eq_sub _ _ ] at this <;> norm_num at *; 260 | rw [ Finset.sum_range_succ ] at this ; linarith; 261 | have h_s_lower_bound : s (play alice bazzaReferenceStrategy) (2 * k) ≥ (k : ℝ) * Real.sqrt 2 := by 262 | convert lemSLowerBound lam alice ( k + 1 ) ( by linarith ) _ using 1; 263 | · norm_num; 264 | · exact fun m hm => ih m ( by omega ); 265 | rw [ lt_div_iff₀ ] at * <;> nlinarith [ Real.sqrt_nonneg 2, Real.sq_sqrt zero_le_two ]; 266 | unfold q at *; 267 | norm_num [ Finset.sum_range_succ ]; 268 | nlinarith [ Real.mul_self_sqrt ( show 0 ≤ 2 by norm_num ), show ( play alice bazzaReferenceStrategy ( 2 * k ) : ℝ ) ≥ 0 by positivity ]; 269 | aesop; 270 | unfold q at *; 271 | erw [ Finset.sum_Ico_succ_top ] <;> norm_num; 272 | rw [ show play alice bazzaReferenceStrategy ( 2 * k + 1 ) = bazzaReferenceStrategy k fun i => play alice bazzaReferenceStrategy i from ?_ ]; 273 | · rw [ ← NNReal.coe_le_coe ] ; aesop; 274 | unfold bazzaReferenceStrategy; 275 | norm_num [ Finset.sum_range ] at *; 276 | split_ifs; 277 | · norm_num [ ← NNReal.coe_le_coe ]; 278 | rw [ Real.sq_sqrt ] <;> linarith; 279 | · convert h_not_win using 1; 280 | · unfold bazzaReferenceStrategy; 281 | norm_num; 282 | · ring; 283 | · unfold play; 284 | norm_num [ Nat.add_mod ]; 285 | rw [ show ( 2 * k + 1 ) / 2 = k by omega ]; 286 | congr!; 287 | exact?; 288 | -- By Lemma~\ref{lem:s_lower_bound}, $S_{2k-2} \ge (k-1)\sqrt{2}$ for all $k \ge 1$. 289 | have h_s_lower_bound : ∀ k : ℕ, 1 ≤ k → s (play alice bazzaReferenceStrategy) (2 * (k - 1)) ≥ ((k - 1) : ℝ) * Real.sqrt 2 := by 290 | intro k hk; 291 | convert lemSLowerBound lam alice k hk _; 292 | exact fun m hm => h_game_continues m; 293 | -- Choose $k$ such that $(k-1)\sqrt{2} > \lambda(2k-1)$. 294 | obtain ⟨k, hk⟩ : ∃ k : ℕ, 1 ≤ k ∧ ((k - 1) : ℝ) * Real.sqrt 2 > lam * ((2 * k - 1) : ℝ) := by 295 | rw [ lt_div_iff₀ ] at * <;> norm_num; 296 | exact ⟨ ⌊ ( 1 - lam * Real.sqrt 2 ) ⁻¹ * 2⌋₊ + 2, by linarith, by push_cast; nlinarith [ Nat.lt_floor_add_one ( ( 1 - lam * Real.sqrt 2 ) ⁻¹ * 2 ), Real.sqrt_nonneg 2, Real.sq_sqrt zero_le_two, mul_inv_cancel₀ ( by nlinarith [ Real.sqrt_nonneg 2, Real.sq_sqrt zero_le_two ] : ( 1 - lam * Real.sqrt 2 ) ≠ 0 ) ] ⟩; 297 | specialize h_s_lower_bound k hk.1; 298 | specialize h_game_continues ( 2 * ( k - 1 ) ) ; unfold ValidMove at h_game_continues ; aesop; 299 | erw [ Finset.sum_Ico_eq_sub _ _ ] at h_game_continues <;> norm_num at *; 300 | unfold s at h_s_lower_bound; 301 | rw [ Finset.sum_range_succ ] at h_game_continues; 302 | linarith [ show ( play alice bazzaReferenceStrategy ( 2 * ( k - 1 ) ) : ℝ ) ≥ 0 by positivity ]; 303 | exact ⟨ bazzaReferenceStrategy, h_bazza_wins ⟩ 304 | 305 | /- 306 | If $\lambda > 1/\sqrt{2}$, there exists a positive integer $K$ such that $\lambda > \frac{K\sqrt{2}}{2K-1}$. 307 | -/ 308 | lemma lemExistenceOfKForAlice (lam : ℝ) (hlam : lam > 1 / Real.sqrt 2) : 309 | ∃ K : ℕ, 1 ≤ K ∧ lam > f K := by 310 | have := @lemFLimit; 311 | exact Filter.eventually_atTop.mp ( this.eventually ( gt_mem_nhds hlam ) ) |> fun ⟨ K, hK ⟩ ↦ ⟨ K + 1, by linarith, hK _ <| by linarith ⟩ 312 | 313 | /- 314 | For Alice's strategy from Definition~\ref{def:alice_strategy}, the sum $S_{2K-2}$ is bounded by $(S_{2K-2})^2 \le (K-1)Q_{2K-2}$. 315 | -/ 316 | lemma lemSBoundByQ (lam : ℝ) (K : ℕ) (hK : 1 ≤ K) (bazza : BazzaStrategy) : 317 | let xs := play (aliceReferenceStrategy lam K) bazza 318 | (s xs (2 * (K - 1))) ^ 2 ≤ ((K - 1) : ℝ) * q xs (2 * (K - 1)) := by 319 | -- By definition of $s$ and $q$, we can split the sum into two parts: one over even indices and one over odd indices. 320 | have h_split_sum : s (play (aliceReferenceStrategy lam K) bazza) (2 * (K - 1)) = ∑ i in Finset.range (K - 1), (play (aliceReferenceStrategy lam K) bazza (2 * i + 1) : ℝ) ∧ q (play (aliceReferenceStrategy lam K) bazza) (2 * (K - 1)) = ∑ i in Finset.range (K - 1), (play (aliceReferenceStrategy lam K) bazza (2 * i + 1) : ℝ) ^ 2 := by 321 | -- By definition of $s$ and $q$, we can split the sum into two parts: one over even indices and one over odd indices. Since Alice's strategy for the first $K-1$ turns is to choose $0$, the sum of the play values at even indices up to $2*(K-1)$ is zero. Therefore, the total sum is just the sum of the play values at the odd indices. 322 | have h_split_sum : ∑ i in Finset.range (2 * (K - 1)), (play (aliceReferenceStrategy lam K) bazza i : ℝ) = ∑ i in Finset.range (K - 1), (play (aliceReferenceStrategy lam K) bazza (2 * i + 1) : ℝ) ∧ ∑ i in Finset.range (2 * (K - 1)), (play (aliceReferenceStrategy lam K) bazza i : ℝ) ^ 2 = ∑ i in Finset.range (K - 1), (play (aliceReferenceStrategy lam K) bazza (2 * i + 1) : ℝ) ^ 2 := by 323 | -- By definition of $play$, we know that for even indices, the value is zero, and for odd indices, it's determined by Bazza's strategy. 324 | have h_play_even_zero : ∀ i < K - 1, play (aliceReferenceStrategy lam K) bazza (2 * i) = 0 := by 325 | -- By definition of play, for even indices, the value is determined by Alice's strategy. Since Alice's strategy returns zero for indices less than K-1, we have: 326 | intros i hi 327 | have h_alice_move : aliceReferenceStrategy lam K i (fun j => play (aliceReferenceStrategy lam K) bazza j) = 0 := by 328 | unfold aliceReferenceStrategy; 329 | grind; 330 | unfold play; 331 | -- Since $2i$ is even, the play value is determined by Alice's strategy, which returns zero for indices less than $K-1$. 332 | simp [h_alice_move]; 333 | rwa [ Nat.mul_div_cancel_left _ ( by decide ) ]; 334 | -- By definition of $play$, we know that for even indices, the value is zero, and for odd indices, it's determined by Bazza's strategy. Therefore, we can split the sum into two parts: one over even indices and one over odd indices. 335 | have h_split_sum : ∑ i in Finset.range (2 * (K - 1)), (play (aliceReferenceStrategy lam K) bazza i : ℝ) = ∑ i in Finset.range (K - 1), (play (aliceReferenceStrategy lam K) bazza (2 * i) : ℝ) + ∑ i in Finset.range (K - 1), (play (aliceReferenceStrategy lam K) bazza (2 * i + 1) : ℝ) ∧ ∑ i in Finset.range (2 * (K - 1)), (play (aliceReferenceStrategy lam K) bazza i : ℝ) ^ 2 = ∑ i in Finset.range (K - 1), (play (aliceReferenceStrategy lam K) bazza (2 * i) : ℝ) ^ 2 + ∑ i in Finset.range (K - 1), (play (aliceReferenceStrategy lam K) bazza (2 * i + 1) : ℝ) ^ 2 := by 336 | induction' K - 1 with k hk; 337 | · norm_num; 338 | · simp_all ( config := { decide := Bool.true } ) [ Nat.mul_succ, Finset.sum_range_succ ]; 339 | constructor <;> ring; 340 | exact ⟨ by rw [ h_split_sum.1, Finset.sum_eq_zero fun i hi => by rw [ h_play_even_zero i ( Finset.mem_range.mp hi ) ] ; norm_num ] ; ring, by rw [ h_split_sum.2, Finset.sum_eq_zero fun i hi => by rw [ h_play_even_zero i ( Finset.mem_range.mp hi ) ] ; norm_num ] ; ring ⟩; 341 | exact h_split_sum; 342 | -- Applying the Cauchy-Schwarz inequality to the sums, we get: 343 | have h_cauchy_schwarz : (∑ i in Finset.range (K - 1), (play (aliceReferenceStrategy lam K) bazza (2 * i + 1) : ℝ))^2 ≤ (Finset.card (Finset.range (K - 1))) * (∑ i in Finset.range (K - 1), (play (aliceReferenceStrategy lam K) bazza (2 * i + 1) : ℝ)^2) := by 344 | exact?; 345 | cases K <;> aesop 346 | 347 | /- 348 | If Alice follows her reference strategy, any sequence of valid moves by Bazza up to turn $2K-2$ must satisfy $S_{2K-2} \le \sqrt{2}(K-1)$. 349 | -/ 350 | lemma lemBazzaDefenseSBound (lam : ℝ) (K : ℕ) (hK : 1 ≤ K) (bazza : BazzaStrategy) 351 | (h_valid : ∀ m < 2 * K - 2, ValidMove lam (play (aliceReferenceStrategy lam K) bazza) m) : 352 | s (play (aliceReferenceStrategy lam K) bazza) (2 * (K - 1)) ≤ Real.sqrt 2 * ((K - 1) : ℝ) := by 353 | -- By the properties of the play sequence and the ValidMove condition, we can derive that the sum of the first 2*(K-1) terms is bounded by sqrt(2)*(K-1). 354 | have h_sum_bound : (s (play (aliceReferenceStrategy lam K) bazza) (2 * (K - 1))) ^ 2 ≤ (K - 1) * q (play (aliceReferenceStrategy lam K) bazza) (2 * (K - 1)) := by 355 | exact?; 356 | -- Substitute the bound on $q$ into the inequality for $s$. 357 | have h_subst : (s (play (aliceReferenceStrategy lam K) bazza) (2 * (K - 1))) ^ 2 ≤ (K - 1) * (2 * (K - 1)) := by 358 | specialize h_valid ( 2 * K - 3 ) ; rcases K with ( _ | _ | K ) <;> simp_all ( config := { decide := Bool.true } ) [ Nat.mul_succ, parity_simps ]; 359 | refine le_trans h_sum_bound ?_; 360 | unfold q at *; 361 | rw [ Finset.sum_range_succ ]; 362 | unfold ValidMove at h_valid ; aesop; 363 | erw [ Finset.sum_Ico_succ_top ] at h_valid <;> norm_num at *; 364 | exact mul_le_mul_of_nonneg_left ( mod_cast h_valid ) ( by positivity ); 365 | nlinarith only [ show 0 ≤ Real.sqrt 2 * ( K - 1 ) by exact mul_nonneg ( Real.sqrt_nonneg _ ) ( sub_nonneg.mpr ( Nat.one_le_cast.mpr hK ) ), h_subst, Real.mul_self_sqrt ( show 0 ≤ 2 by norm_num ) ] 366 | 367 | /- 368 | Alice's move $x_{2K-1}$ in her reference strategy is a valid move. 369 | -/ 370 | lemma lemAliceMoveValid (lam : ℝ) (hlam : lam > 1 / Real.sqrt 2) (K : ℕ) (hK : 1 ≤ K ∧ lam > f K) 371 | (bazza : BazzaStrategy) 372 | (h_valid_hist : ∀ m < 2 * K - 2, ValidMove lam (play (aliceReferenceStrategy lam K) bazza) m) : 373 | ValidMove lam (play (aliceReferenceStrategy lam K) bazza) (2 * K - 2) := by 374 | unfold ValidMove; aesop; 375 | · -- By definition of $S$, we can write 376 | have hS : ∑ i in Finset.Iic (2 * K - 2), (play (aliceReferenceStrategy lam K) bazza i : ℝ) = s (play (aliceReferenceStrategy lam K) bazza) (2 * K - 1) := by 377 | erw [ Finset.sum_Ico_eq_sub _ _ ] <;> norm_num; 378 | rcases K with ( _ | _ | K ) <;> trivial; 379 | rcases K with ( _ | _ | K ) <;> simp_all ( config := { decide := Bool.true } ) [ Nat.mul_succ ]; 380 | · unfold s; 381 | unfold play; norm_num; 382 | unfold aliceReferenceStrategy; 383 | norm_num; 384 | split_ifs <;> norm_num ; linarith [ inv_nonneg.2 ( Real.sqrt_nonneg 2 ) ]; 385 | · unfold f at right; 386 | rw [ div_lt_iff₀ ] at right <;> norm_num at *; 387 | · have := lemBazzaDefenseSBound lam ( K + 1 + 1 ) ( by linarith ) bazza; 388 | unfold s at *; 389 | rw [ Finset.sum_range_succ ]; 390 | rw [ show play ( aliceReferenceStrategy lam ( K + 1 + 1 ) ) bazza ( 2 * K + 2 ) = aliceReferenceStrategy lam ( K + 1 + 1 ) ( K + 1 ) ( fun i => play ( aliceReferenceStrategy lam ( K + 1 + 1 ) ) bazza i ) from ?_ ]; 391 | · unfold aliceReferenceStrategy at *; 392 | norm_num [ Finset.sum_range, Nat.mul_succ ] at *; 393 | split_ifs <;> norm_num; 394 | · linarith!; 395 | · exact le_trans ( this fun m mn => h_valid_hist m mn ) ( by nlinarith [ Real.sqrt_nonneg 2, Real.sq_sqrt zero_le_two ] ); 396 | · unfold play; 397 | norm_num [ Nat.add_mod ]; 398 | rw [ show ( 2 * K + 2 ) / 2 = K + 1 by norm_num [ Nat.add_div ] ]; 399 | congr!; 400 | exact?; 401 | · linarith; 402 | · exact absurd h ( by rw [ Nat.odd_iff ] ; omega ) 403 | 404 | /- 405 | Following her reference strategy, Alice wins at turn $2K$ if and only if $\lambda(2K-1) > S_{2K-2} + \sqrt{2K - Q_{2K-2}}$. 406 | -/ 407 | lemma lemAliceWinConditionFinalForm (lam : ℝ) (hlam : lam > 1 / Real.sqrt 2) (K : ℕ) (hK : 1 ≤ K ∧ lam > f K) (bazza : BazzaStrategy) 408 | (h_valid : ∀ m < 2 * K - 2, ValidMove lam (play (aliceReferenceStrategy lam K) bazza) m) : 409 | let xs := play (aliceReferenceStrategy lam K) bazza 410 | (q xs (2 * K - 1) > (2 * K : ℝ)) ↔ 411 | lam * ((2 * K - 1) : ℝ) > s xs (2 * (K - 1)) + Real.sqrt ((2 * K : ℝ) - q xs (2 * (K - 1))) := by 412 | bound; 413 | · -- Since $a > 2K$, we have $q xs (2K-1) > 2K$, which implies $q xs (2(K-1)) + (xs (2K-2))^2 > 2K$. 414 | have h_q_split : q xs (2 * (K - 1)) + (xs (2 * K - 2) : ℝ) ^ 2 > 2 * K := by 415 | convert a using 1; 416 | unfold q; 417 | rcases K with ( _ | _ | K ) <;> simp_all ( config := { decide := Bool.true } ) [ Nat.mul_succ, Finset.sum_range_succ ]; 418 | -- Substitute $x_{2K-1} = \lambda(2K-1) - S_{2K-2}$ into the inequality. 419 | have h_subst : (xs (2 * K - 2) : ℝ) = lam * (2 * K - 1) - s xs (2 * (K - 1)) := by 420 | have h_subst : xs (2 * K - 2) = aliceReferenceStrategy lam K (K - 1) (fun i => xs i) := by 421 | have h_subst : ∀ n, xs n = if n % 2 = 0 then aliceReferenceStrategy lam K (n / 2) (fun i => xs i) else bazza (n / 2) (fun i => xs i) := by 422 | exact?; 423 | rw [ h_subst ]; 424 | rw [ if_pos ( by omega ), show ( 2 * K - 2 ) / 2 = K - 1 by omega ]; 425 | unfold aliceReferenceStrategy at h_subst; 426 | rcases K with ( _ | _ | K ) <;> simp_all ( config := { decide := Bool.true } ) [ Nat.mul_succ ]; 427 | · unfold s; norm_num; 428 | split_ifs <;> norm_num ; linarith [ inv_nonneg.2 ( Real.sqrt_nonneg 2 ) ]; 429 | · unfold s; 430 | split_ifs <;> simp_all ( config := { decide := Bool.true } ) [ Finset.sum_range ]; 431 | have := h_valid ( 2 * K + 1 ) ( by linarith ) ; unfold ValidMove at this ; aesop; 432 | contrapose! h_q_split; 433 | unfold q; 434 | norm_cast; 435 | exact le_trans ( by rw [ Finset.range_eq_Ico ] ; rfl ) ( this.trans ( by ring_nf; norm_num ) ); 436 | aesop; 437 | -- Taking the square root of both sides of the inequality from h_q_split, we get Real.sqrt (2 * K - q xs (2 * (K - 1))) < lam * (2 * K - 1) - s xs (2 * (K - 1)). 438 | have h_sqrt : Real.sqrt (2 * K - q xs (2 * (K - 1))) < lam * (2 * K - 1) - s xs (2 * (K - 1)) := by 439 | rw [ Real.sqrt_lt ]; 440 | · linarith; 441 | · rcases K with ( _ | _ | K ) <;> norm_num [ Nat.mul_succ ] at *; 442 | · exact show ( ∑ i in Finset.range 0, ( xs i : ℝ ) ^ 2 ) ≤ 2 by norm_num; 443 | · specialize h_valid ( 2 * K + 1 ) ; unfold ValidMove at h_valid ; aesop; 444 | unfold q; 445 | norm_cast; 446 | exact le_trans ( by rw [ Finset.range_eq_Ico ] ; rfl ) ( h_valid.trans ( by ring_nf; norm_num ) ); 447 | · exact h_subst ▸ NNReal.coe_nonneg _; 448 | linarith; 449 | · -- Substitute the expression for $xs (2K - 2)$ from Alice's reference strategy. 450 | have h_subst : xs (2 * K - 2) = lam * (2 * K - 1) - s xs (2 * K - 2) := by 451 | rcases K with ( _ | K ) <;> simp_all ( config := { decide := Bool.true } ) [ Nat.mul_succ ]; 452 | -- By definition of `aliceReferenceStrategy`, when `n + 1 = K`, Alice sets `xs (2 * K)` to `lam * (2 * (K + 1) - 1) - s xs (2 * K)`. 453 | have h_alice_move : xs (2 * K) = aliceReferenceStrategy lam (K + 1) K (fun i => xs i) := by 454 | have h_alice_move : ∀ n, xs n = if n % 2 = 0 then aliceReferenceStrategy lam (K + 1) (n / 2) (fun i => xs i) else bazza (n / 2) (fun i => xs i) := by 455 | exact?; 456 | rw [ h_alice_move ] ; norm_num; 457 | rw [ Nat.mul_div_cancel_left _ ( by decide ) ]; 458 | unfold aliceReferenceStrategy at *; 459 | unfold s at *; 460 | simp +zetaDelta at *; 461 | rw [ h_alice_move, Finset.sum_range ]; 462 | split_ifs <;> norm_num; 463 | exact False.elim <| ‹¬_› <| by simpa [ Finset.sum_range ] using a.le.trans' <| add_le_add_left ( Real.sqrt_nonneg _ ) _; 464 | -- Substitute the expression for $q xs (2 * K - 1)$ using the definition of $q$. 465 | have h_q : q xs (2 * K - 1) = q xs (2 * K - 2) + (xs (2 * K - 2) : ℝ) ^ 2 := by 466 | unfold q; 467 | cases K <;> norm_num [ Nat.mul_succ, Finset.sum_range_succ ] at *; 468 | rcases K with ( _ | K ) <;> simp_all ( config := { decide := Bool.true } ) [ Nat.mul_succ ]; 469 | contrapose! a; 470 | nlinarith [ Real.sqrt_nonneg ( 2 * ( K + 1 ) - q xs ( 2 * K ) ), Real.mul_self_sqrt ( show 0 ≤ 2 * ( K + 1 ) - q xs ( 2 * K ) by nlinarith ) ] 471 | 472 | /- 473 | For any sequence of valid moves by Bazza against Alice's reference strategy, $S_{2K-2} + \sqrt{2K - Q_{2K-2}} \le K\sqrt{2}$. 474 | -/ 475 | lemma lemBazzaObjectiveUpperBound (lam : ℝ) (K : ℕ) (hK : 2 ≤ K) (bazza : BazzaStrategy) 476 | (h_valid : ∀ m < 2 * K - 2, ValidMove lam (play (aliceReferenceStrategy lam K) bazza) m) : 477 | let xs := play (aliceReferenceStrategy lam K) bazza 478 | s xs (2 * (K - 1)) + Real.sqrt ((2 * K : ℝ) - q xs (2 * (K-1))) ≤ (K : ℝ) * Real.sqrt 2 := by 479 | -- By Lemma~\ref{lem:q_bound}, we know that $Q_{2K-2} \leq 2(K-1)$. 480 | have h_q_bound : q (play (aliceReferenceStrategy lam K) bazza) (2 * (K - 1)) ≤ 2 * (K - 1) := by 481 | -- Apply the hypothesis `h_valid` with `m = 2 * (K - 1) - 1`. 482 | specialize h_valid (2 * (K - 1) - 1); 483 | rcases K with ( _ | _ | K ) <;> simp_all ( config := { decide := Bool.true } ) [ Nat.mul_succ ]; 484 | unfold ValidMove at h_valid ; aesop; 485 | convert h_valid using 1; 486 | unfold q; norm_cast; 487 | erw [ Finset.range_eq_Ico ] ; rfl; 488 | -- By Lemma~\ref{lem:s_lower_bound}, we know that $S_{2K-2} \leq \sqrt{(K-1)Q_{2K-2}}$. 489 | have h_s_lower_bound : s (play (aliceReferenceStrategy lam K) bazza) (2 * (K - 1)) ≤ Real.sqrt ((K - 1) * q (play (aliceReferenceStrategy lam K) bazza) (2 * (K - 1))) := by 490 | refine Real.le_sqrt_of_sq_le ?_; 491 | unfold s q; 492 | -- By definition of play, we know that play (aliceReferenceStrategy lam K) bazza (2 * i) = 0 for all i < K - 1. 493 | have h_play_zero : ∀ i < K - 1, play (aliceReferenceStrategy lam K) bazza (2 * i) = 0 := by 494 | unfold play; 495 | unfold aliceReferenceStrategy; 496 | grind; 497 | -- Since $play (aliceReferenceStrategy lam K) bazza (2 * i) = 0$ for all $i < K - 1$, we can split the sum into two parts: one over even indices and one over odd indices. 498 | have h_split_sum : ∑ i in Finset.range (2 * (K - 1)), (play (aliceReferenceStrategy lam K) bazza i : ℝ) = ∑ i in Finset.range (K - 1), (play (aliceReferenceStrategy lam K) bazza (2 * i + 1) : ℝ) := by 499 | have h_split_sum : Finset.range (2 * (K - 1)) = Finset.image (fun i => 2 * i) (Finset.range (K - 1)) ∪ Finset.image (fun i => 2 * i + 1) (Finset.range (K - 1)) := by 500 | ext ; aesop; 501 | · rcases Nat.even_or_odd' a with ⟨ b, rfl | rfl ⟩ <;> [ left; right ] <;> exact ⟨ b, by linarith, rfl ⟩; 502 | · linarith; 503 | rw [ h_split_sum, Finset.sum_union ]; 504 | · norm_num; 505 | exact Finset.sum_eq_zero fun i hi => by rw [ h_play_zero i ( Finset.mem_range.mp hi ) ] ; norm_num; 506 | · norm_num [ Finset.disjoint_right ]; 507 | grind; 508 | -- Applying the Cauchy-Schwarz inequality to the sum of the terms over odd indices. 509 | have h_cauchy_schwarz_odd : (∑ i in Finset.range (K - 1), (play (aliceReferenceStrategy lam K) bazza (2 * i + 1) : ℝ))^2 ≤ (K - 1) * (∑ i in Finset.range (K - 1), (play (aliceReferenceStrategy lam K) bazza (2 * i + 1) : ℝ)^2) := by 510 | have h_cauchy_schwarz_odd : ∀ (u v : Fin (K - 1) → ℝ), (∑ i, u i * v i)^2 ≤ (∑ i, u i^2) * (∑ i, v i^2) := by 511 | exact?; 512 | simpa [ Finset.sum_range, Nat.cast_sub ( show 1 ≤ K by linarith ) ] using h_cauchy_schwarz_odd ( fun _ => 1 ) ( fun i => ( play ( aliceReferenceStrategy lam K ) bazza ( 2 * i + 1 ) : ℝ ) ); 513 | -- Since the play values at even indices are zero, the sum of the squares up to 2*(K-1) is just the sum of the squares of the odd terms up to K-1. 514 | have h_split_sum_sq : ∑ i in Finset.range (2 * (K - 1)), (play (aliceReferenceStrategy lam K) bazza i : ℝ)^2 = ∑ i in Finset.range (K - 1), (play (aliceReferenceStrategy lam K) bazza (2 * i + 1) : ℝ)^2 := by 515 | have h_split_sum_sq : Finset.range (2 * (K - 1)) = Finset.image (fun i => 2 * i) (Finset.range (K - 1)) ∪ Finset.image (fun i => 2 * i + 1) (Finset.range (K - 1)) := by 516 | ext ; aesop; 517 | · rcases Nat.even_or_odd' a with ⟨ b, rfl | rfl ⟩ <;> [ left; right ] <;> exact ⟨ b, by linarith, rfl ⟩; 518 | · grind; 519 | rw [ h_split_sum_sq, Finset.sum_union ]; 520 | · norm_num; 521 | exact Finset.sum_eq_zero fun i hi => by rw [ h_play_zero i ( Finset.mem_range.mp hi ) ] ; norm_num; 522 | · norm_num [ Finset.disjoint_right ]; 523 | intros; omega; 524 | aesop; 525 | refine le_trans ( add_le_add h_s_lower_bound le_rfl ) ?_; 526 | -- Applying the Cauchy-Schwarz inequality, we get: 527 | have h_cauchy_schwarz : (Real.sqrt ((K - 1) * q (play (aliceReferenceStrategy lam K) bazza) (2 * (K - 1))) + Real.sqrt (2 * K - q (play (aliceReferenceStrategy lam K) bazza) (2 * (K - 1)))) ^ 2 ≤ (K - 1 + 1) * ((q (play (aliceReferenceStrategy lam K) bazza) (2 * (K - 1))) + (2 * K - q (play (aliceReferenceStrategy lam K) bazza) (2 * (K - 1)))) := by 528 | rw [ Real.sqrt_mul ( by norm_num; linarith ) ]; 529 | nlinarith only [ sq_nonneg ( Real.sqrt ( K - 1 ) * Real.sqrt ( 2 * K - q ( play ( aliceReferenceStrategy lam K ) bazza ) ( 2 * ( K - 1 ) ) ) - Real.sqrt ( q ( play ( aliceReferenceStrategy lam K ) bazza ) ( 2 * ( K - 1 ) ) ) ), Real.mul_self_sqrt ( show ( K : ℝ ) - 1 ≥ 0 by norm_num; linarith ), Real.mul_self_sqrt ( show ( q ( play ( aliceReferenceStrategy lam K ) bazza ) ( 2 * ( K - 1 ) ) : ℝ ) ≥ 0 by exact Finset.sum_nonneg fun _ _ => sq_nonneg _ ), Real.mul_self_sqrt ( show ( 2 * K - q ( play ( aliceReferenceStrategy lam K ) bazza ) ( 2 * ( K - 1 ) ) : ℝ ) ≥ 0 by linarith ) ]; 530 | exact le_trans ( Real.le_sqrt_of_sq_le h_cauchy_schwarz ) ( Real.sqrt_le_iff.mpr ⟨ by positivity, by nlinarith [ Real.mul_self_sqrt ( show 0 ≤ 2 by norm_num ) ] ⟩ ) 531 | 532 | /- 533 | If $\lambda > 1/\sqrt{2}$, Alice has a winning strategy. 534 | -/ 535 | lemma lemAliceWinsLargeLambda (lam : ℝ) (hlam : lam > 1 / Real.sqrt 2) : 536 | ∃ alice, AliceStrategy.Wins lam alice := by 537 | -- obtain such a K using lemExistenceOfKForAlice 538 | obtain ⟨K, hK⟩ : ∃ K : ℕ, 1 ≤ K ∧ lam > f K := by 539 | exact?; 540 | use aliceReferenceStrategy lam K; 541 | intro bazza; 542 | by_contra h_contra; 543 | -- If Alice never wins, then Bazza must win by turn $2K-1$. 544 | have h_bazza_wins : ∀ m < 2 * K - 2, ValidMove lam (play (aliceReferenceStrategy lam K) bazza) m := by 545 | intro m hm; 546 | induction' m using Nat.strong_induction_on with m ih; 547 | by_cases h_even : Even m; 548 | · unfold ValidMove; 549 | -- Since $m$ is even, we can write $m = 2k$ for some $k$. 550 | obtain ⟨k, rfl⟩ : ∃ k, m = 2 * k := even_iff_two_dvd.mp h_even; 551 | -- By definition of play, we can write out the sum. 552 | have h_sum : ∑ i in Finset.Iic (2 * k), (play (aliceReferenceStrategy lam K) bazza i : ℝ) = ∑ i in Finset.range k, (play (aliceReferenceStrategy lam K) bazza (2 * i + 1) : ℝ) := by 553 | erw [ Finset.sum_Ico_eq_sub _ _ ] <;> norm_num [ Finset.sum_range_succ, Nat.mul_succ ]; 554 | rw [ show ( Finset.range ( 2 * k ) : Finset ℕ ) = Finset.image ( fun i => 2 * i ) ( Finset.range k ) ∪ Finset.image ( fun i => 2 * i + 1 ) ( Finset.range k ) from ?_, Finset.sum_union ] <;> norm_num; 555 | · unfold play; 556 | unfold aliceReferenceStrategy; 557 | norm_num; 558 | rw [ Finset.sum_congr rfl fun i hi => by rw [ if_pos ( by linarith [ Finset.mem_range.mp hi, Nat.sub_add_cancel ( show 2 ≤ 2 * K from by linarith ) ] ) ] ] ; norm_num; 559 | intros; omega; 560 | · norm_num [ Finset.disjoint_right ]; 561 | intros; omega; 562 | · ext ; aesop; 563 | · rcases Nat.even_or_odd' a with ⟨ b, rfl | rfl ⟩ <;> [ left; right ] <;> exact ⟨ b, by linarith, rfl ⟩; 564 | · linarith; 565 | -- By definition of play, we can write out the sum of squares. 566 | have h_sum_squares : ∑ i in Finset.range k, (play (aliceReferenceStrategy lam K) bazza (2 * i + 1) : ℝ) ^ 2 ≤ 2 * k := by 567 | have := ih ( 2 * k - 1 ) ; rcases k with ( _ | k ) <;> simp_all ( config := { decide := Bool.true } ) [ Nat.mul_succ, parity_simps ]; 568 | have := ih ( 2 * k + 1 ) ( by linarith ) ( by omega ) ; unfold ValidMove at this; aesop; 569 | norm_cast; 570 | refine le_trans ?_ ( this.trans ?_ ); 571 | · have h_sum_squares : Finset.image (fun i => 2 * i + 1) (Finset.range (k + 1)) ⊆ Finset.Iic (2 * k + 1) := by 572 | exact Finset.image_subset_iff.mpr fun i hi => Finset.mem_Iic.mpr ( by linarith [ Finset.mem_range.mp hi ] ); 573 | exact le_trans ( by rw [ Finset.sum_image ( by norm_num ) ] ) ( Finset.sum_le_sum_of_subset h_sum_squares ); 574 | · norm_cast; 575 | have := Finset.sum_le_sum fun i ( hi : i ∈ Finset.range k ) => pow_two_nonneg ( ( play ( aliceReferenceStrategy lam K ) bazza ( 2 * i + 1 ) : ℝ ) - Real.sqrt 2 ); 576 | norm_num [ sub_sq, Finset.sum_add_distrib, Finset.mul_sum _ _ _ ] at this; 577 | norm_num [ ← Finset.mul_sum _ _ _, ← Finset.sum_mul ] at *; 578 | rw [ inv_eq_one_div, div_lt_iff₀ ] at hlam <;> nlinarith [ Real.sqrt_nonneg 2, Real.sq_sqrt zero_le_two ]; 579 | · contrapose! h_contra; 580 | use m; 581 | exact ⟨ ⟨ h_contra, fun n hn => not_lt.1 fun contra => hn <| ih n contra <| by omega ⟩, Nat.odd_iff.mpr <| Nat.not_even_iff.mp h_even ⟩; 582 | have h_alice_wins : q (play (aliceReferenceStrategy lam K) bazza) (2 * K - 1) > (2 * K : ℝ) := by 583 | have h_alice_wins : lam * ((2 * K - 1) : ℝ) > s (play (aliceReferenceStrategy lam K) bazza) (2 * (K - 1)) + Real.sqrt ((2 * K : ℝ) - q (play (aliceReferenceStrategy lam K) bazza) (2 * (K - 1))) := by 584 | have := lemBazzaObjectiveUpperBound lam K; 585 | rcases K with ( _ | _ | K ) <;> aesop; 586 | · unfold s q; norm_num; 587 | unfold f at hK ; aesop; 588 | norm_num at hK ; linarith; 589 | · refine' lt_of_le_of_lt ( this bazza h_bazza_wins ) _; 590 | unfold f at hK; 591 | rw [ div_lt_iff₀ ] at hK <;> norm_num at * <;> nlinarith; 592 | exact?; 593 | refine' h_contra ⟨ 2 * K - 1, _, _ ⟩; 594 | · -- Since $ValidMove$ holds for all $m < 2K-2$, the next $m$ where $ValidMove$ fails must be $2K-1$. 595 | have h_least : ∀ m, m < 2 * K - 1 → ValidMove lam (play (aliceReferenceStrategy lam K) bazza) m := by 596 | -- Since $m < 2K-1$, we have either $m < 2K-2$ or $m = 2K-2$. In both cases, $ValidMove$ holds by $h_bazza_wins$. 597 | intros m hm 598 | by_cases hm' : m < 2 * K - 2; 599 | · exact h_bazza_wins m hm'; 600 | · convert lemAliceMoveValid lam hlam K hK bazza _; 601 | · omega; 602 | · exact h_bazza_wins; 603 | refine' ⟨ _, fun m hm => _ ⟩ <;> aesop; 604 | · unfold ValidMove at a; 605 | rcases K with ( _ | K ) <;> simp_all ( config := { decide := Bool.true } ) [ Nat.mul_succ, parity_simps ]; 606 | unfold q at h_alice_wins; 607 | erw [ Finset.sum_Ico_succ_top ] at a <;> norm_num at *; 608 | exact h_alice_wins.not_le ( by norm_num [ ← NNReal.coe_le_coe ] at *; nlinarith ); 609 | · exact not_lt.1 fun contra => hm <| h_least m <| by omega; 610 | · exact ⟨ K - 1, by omega ⟩ 611 | 612 | /- 613 | Alice wins if $\lambda > 1 / \sqrt{2}$. Bazza wins if $0 < \lambda < 1 / \sqrt{2}$. 614 | -/ 615 | theorem main_theorem : 616 | {lam : ℝ | 0 < lam ∧ ∃ alice : AliceStrategy, alice.Wins lam} = {lam : ℝ | 1 / Real.sqrt 2 < lam} ∧ 617 | {lam : ℝ | 0 < lam ∧ ∃ bazza : BazzaStrategy, bazza.Wins lam} = {lam : ℝ | 0 < lam ∧ lam < 1 / Real.sqrt 2} := by 618 | constructor; 619 | · apply Set.ext; 620 | bound; 621 | · cases a ; aesop; 622 | -- By definition of Alice's winning strategy, if Alice has a winning strategy, then x must be greater than 1/sqrt(2). 623 | have h_x_gt : x > 1 / Real.sqrt 2 := by 624 | have := h bazzaReferenceStrategy; 625 | -- By definition of Alice's winning strategy, if Alice has a winning strategy, then there exists some $n$ where the move is invalid and $n$ is odd. 626 | obtain ⟨n, hn₁, hn₂⟩ := this; 627 | -- By definition of ValidMove, if the move is invalid, then for odd n, the sum of squares exceeds n+1. 628 | have h_sum_squares : ∑ i in Finset.range n, (play w bazzaReferenceStrategy i : ℝ) ^ 2 > n + 1 := by 629 | have := hn₁.1; 630 | unfold ValidMove at this; 631 | aesop; 632 | · exact absurd h_1 ( by simpa using hn₂ ); 633 | · contrapose! this; 634 | erw [ Finset.sum_Ico_succ_top ] <;> norm_num; 635 | rw [ ← NNReal.coe_le_coe ] ; aesop; 636 | rw [ show play w bazzaReferenceStrategy n = bazzaReferenceStrategy ( n / 2 ) ( fun i => play w bazzaReferenceStrategy i ) from ?_ ]; 637 | · unfold bazzaReferenceStrategy; 638 | norm_num [ ← NNReal.coe_le_coe ]; 639 | split_ifs; 640 | · norm_num [ ← NNReal.coe_le_coe, Finset.sum_range ]; 641 | rw [ Real.sq_sqrt ]; 642 | · rw [ show n = 2 * ( n / 2 ) + 1 by linarith [ Nat.odd_iff.mp hn₂, Nat.div_add_mod n 2 ] ]; 643 | norm_num [ Nat.add_div ]; 644 | rw [ show ( 2 * ( n / 2 ) + 1 ) / 2 = n / 2 by omega ] ; linarith; 645 | · linarith; 646 | · convert this using 1; 647 | unfold bazzaReferenceStrategy; 648 | norm_num; 649 | · unfold play; 650 | norm_num [ Nat.odd_iff.mp hn₂ ]; 651 | congr!; 652 | exact?; 653 | -- Since $n$ is odd, we can write $n = 2k + 1$ for some $k$. 654 | obtain ⟨k, rfl⟩ : ∃ k, n = 2 * k + 1 := hn₂; 655 | -- By definition of play, we can write out the sum of squares for the first 2k+1 turns. 656 | have h_play_sum_squares : ∑ i in Finset.range (2 * k + 1), (play w bazzaReferenceStrategy i : ℝ) ^ 2 ≤ 2 * k + (play w bazzaReferenceStrategy (2 * k) : ℝ) ^ 2 := by 657 | -- By definition of ValidMove, the sum of squares up to 2k is ≤ 2k. 658 | have h_sum_squares_2k : ∑ i in Finset.range (2 * k), (play w bazzaReferenceStrategy i : ℝ) ^ 2 ≤ 2 * k := by 659 | have := hn₁.2; 660 | have := @this ( 2 * k ) ; unfold ValidMove at this ; aesop; 661 | have := @this_1 ( 2 * k ) ; unfold ValidMove at this ; aesop; 662 | have := @this_1 ( 2 * k - 1 ) ; rcases k with ( _ | k ) <;> simp_all ( config := { decide := Bool.true } ) [ Nat.mul_succ, parity_simps ]; 663 | unfold ValidMove at this ; aesop; 664 | convert NNReal.coe_le_coe.mpr this using 1; 665 | · erw [ Finset.sum_Ico_eq_sum_range ] ; norm_num; 666 | · norm_cast; 667 | rw [ Finset.sum_range_succ ] ; linarith; 668 | have h_play_sum_squares : play w bazzaReferenceStrategy (2 * k) ≤ x * (2 * k + 1) - ∑ i in Finset.range (2 * k), (play w bazzaReferenceStrategy i : ℝ) := by 669 | have := hn₁.2; 670 | have := @this ( 2 * k ) ; unfold ValidMove at this ; aesop; 671 | erw [ Finset.sum_Ico_succ_top ] at this <;> norm_num at *; 672 | linarith; 673 | have h_play_sum_squares : ∑ i in Finset.range (2 * k), (play w bazzaReferenceStrategy i : ℝ) ≥ k * Real.sqrt 2 := by 674 | have := @lemSLowerBound x w ( k + 1 ) ( by linarith ) ?_; 675 | · aesop; 676 | · intro m hm; 677 | have := hn₁.2; 678 | exact Classical.not_not.1 fun hnm => not_lt_of_ge ( this hnm ) ( by omega ); 679 | simp +zetaDelta at *; 680 | -- By combining the terms, we can factor out $\sqrt{2}$ and simplify the expression. 681 | have h_simplified : Real.sqrt 2 < x * (2 * k + 1) - k * Real.sqrt 2 := by 682 | nlinarith [ Real.sqrt_nonneg 2, Real.sq_sqrt zero_le_two, show ( play w bazzaReferenceStrategy ( 2 * k ) : ℝ ) ≥ 0 by positivity ]; 683 | rw [ inv_eq_one_div, div_lt_iff₀ ] <;> nlinarith [ Real.sqrt_nonneg 2, Real.sq_sqrt zero_le_two ]; 684 | simpa using h_x_gt; 685 | · exact ⟨ lt_trans ( by positivity ) a, lemAliceWinsLargeLambda x a ⟩; 686 | · -- To prove the equality, we show mutual inclusion. 687 | apply Set.ext 688 | intro lam; 689 | constructor; 690 | · -- If there exists a bazza strategy that wins, then by the problem's statement, lam must be less than 1/sqrt(2). 691 | intro h 692 | obtain ⟨bazza, hbazza⟩ := h.right 693 | have hlam : 0 < lam ∧ lam < 1 / Real.sqrt 2 := by 694 | specialize hbazza ( fun n x => 0 ); 695 | aesop; 696 | unfold ValidMove at *; 697 | have := left_1.1 ; aesop; 698 | contrapose! this; 699 | -- Since $w$ is even, we can write $w = 2k$ for some $k$. 700 | obtain ⟨k, rfl⟩ : ∃ k, w = 2 * k := even_iff_two_dvd.mp right; 701 | -- By definition of play, we can write out the sum. 702 | have h_sum : ∑ i in Finset.Iic (2 * k), (play (fun n x => 0) bazza i : ℝ) = ∑ i in Finset.range k, (play (fun n x => 0) bazza (2 * i + 1) : ℝ) := by 703 | erw [ Finset.sum_Ico_eq_sub _ _ ] <;> norm_num [ Finset.sum_range_succ, Nat.mul_succ ]; 704 | rw [ show ( Finset.range ( 2 * k ) : Finset ℕ ) = Finset.image ( fun i => 2 * i ) ( Finset.range k ) ∪ Finset.image ( fun i => 2 * i + 1 ) ( Finset.range k ) from ?_, Finset.sum_union ] <;> norm_num; 705 | · unfold play; 706 | norm_num; 707 | · norm_num [ Finset.disjoint_right ]; 708 | intros; omega; 709 | · ext ; aesop; 710 | · rcases Nat.even_or_odd' a with ⟨ b, rfl | rfl ⟩ <;> [ left; right ] <;> exact ⟨ b, by linarith, rfl ⟩; 711 | · linarith; 712 | -- By definition of play, we can write out the sum of squares. 713 | have h_sum_squares : ∑ i in Finset.range k, (play (fun n x => 0) bazza (2 * i + 1) : ℝ) ^ 2 ≤ 2 * k := by 714 | have := left_1.2; 715 | have := @this ( 2 * k - 1 ) ; rcases k with ( _ | k ) <;> simp_all ( config := { decide := Bool.true } ) [ Nat.mul_succ, parity_simps ]; 716 | convert NNReal.coe_le_coe.mpr this using 1; 717 | · erw [ Finset.sum_Ico_eq_sum_range ] ; norm_num [ Finset.sum_range_succ, Nat.mul_succ ]; 718 | unfold play; 719 | exact Nat.recOn k ( by norm_num ) fun n ihn => by norm_num [ Nat.mul_succ, Finset.sum_range_succ, Nat.add_mod, Nat.mul_mod ] at * ; linarith; 720 | · norm_cast; 721 | have := Finset.sum_le_sum fun i ( hi : i ∈ Finset.range k ) => pow_two_nonneg ( ( play ( fun n x => 0 ) bazza ( 2 * i + 1 ) : ℝ ) - Real.sqrt 2 ); 722 | norm_num [ sub_sq, Finset.sum_add_distrib, Finset.mul_sum _ _ _ ] at this; 723 | norm_num [ ← Finset.mul_sum _ _ _, ← Finset.sum_mul ] at *; 724 | rw [ inv_eq_one_div, div_le_iff₀ ] at * <;> nlinarith [ Real.sqrt_nonneg 2, Real.sq_sqrt zero_le_two ] 725 | exact hlam; 726 | · exact fun h => ⟨ h.1, lemBazzaWinsSmallLambda lam h ⟩ 727 | 728 | #print axioms main_theorem 729 | -------------------------------------------------------------------------------- /HarmonicLean/IMO2025P4_solve2.lean: -------------------------------------------------------------------------------- 1 | /- 2 | A proper divisor of a positive integer $N$ is a positive divisor of $N$ other than $N$ itself. 3 | The infinite sequence $a_1,a_2,\dots$ consists of positive integers, each of which has at least three proper divisors. 4 | For each $n\geqslant 1$, the integer $a_{n+1}$ is the sum of the three largest proper divisors of $a_n$. 5 | Determine all possible values of $a_1$. 6 | Answer: All integers of the form $6 \cdot 12^a \cdot m$, for $a \geq 0$ and $m$ is coprime to 10. 7 | -/ 8 | 9 | import HarmonicLean.Imports 10 | 11 | open scoped BigOperators 12 | open scoped Real 13 | open scoped Nat 14 | open scoped Classical 15 | open scoped Pointwise 16 | 17 | set_option maxHeartbeats 0 18 | set_option maxRecDepth 4000 19 | set_option synthInstance.maxHeartbeats 20000 20 | set_option synthInstance.maxSize 128 21 | 22 | set_option pp.fullNames true 23 | set_option pp.structureInstances true 24 | 25 | set_option relaxedAutoImplicit false 26 | set_option autoImplicit false 27 | 28 | set_option pp.coercions.types true 29 | set_option pp.funBinderTypes true 30 | set_option pp.letVarTypes true 31 | set_option pp.piBinderTypes true 32 | 33 | set_option linter.all false 34 | 35 | noncomputable section 36 | 37 | namespace IMO2025P4Solve2 38 | 39 | /- 40 | The following definition is not explicitly present in the provided text, but is referred to as "Definition def:s_N". We formalize it here for use in the lemmas. 41 | For a positive integer $N$ with at least three proper divisors, $s(N)$ is the sum of the three largest proper divisors of $N$. 42 | -/ 43 | def s (N : ℕ) : ℕ := 44 | if h : 3 ≤ N.properDivisors.card then 45 | ((N.properDivisors.sort (· ≥ ·))[0]! + 46 | (N.properDivisors.sort (· ≥ ·))[1]! + 47 | (N.properDivisors.sort (· ≥ ·))[2]!) 48 | else 0 49 | 50 | /- 51 | If an integer $N$ is not divisible by 2 or 3, then $s(N) < N$. 52 | -/ 53 | lemma lem_s_N_bound_no_2_3 (N : ℕ) (hpos : 0 < N) (h_card : 3 ≤ N.properDivisors.card) 54 | (h2 : ¬ (2 ∣ N)) (h3 : ¬ (3 ∣ N)) : s N < N := by 55 | unfold s; 56 | -- Since $N$ is not divisible by 2 or 3, its smallest prime factor $p$ must be at least 5. Therefore, the three largest proper divisors are $N/p$, $N/q$, and $N/r$, where $p$, $q$, and $r$ are the smallest primes dividing $N$. 57 | have h_smallest_prime : ∀ {d : ℕ}, d ∈ N.properDivisors → d ≤ N / 5 := by 58 | aesop; 59 | rw [ Nat.le_div_iff_mul_le ] <;> obtain ⟨ k, hk ⟩ := left <;> aesop; 60 | contrapose! h3; interval_cases k <;> simp_all ( config := { decide := Bool.true } ) ; 61 | norm_num [ Nat.mul_mod ] at h2; 62 | rcases x : Finset.sort ( fun x1 x2 => x1 ≥ x2 ) N.properDivisors with ( _ | ⟨ a, _ | ⟨ b, _ | ⟨ c, _ | k ⟩ ⟩ ⟩ ) <;> simp_all +arith +decide; 63 | · replace x := congr_arg List.length x; aesop; 64 | · replace x := congr_arg List.length x; aesop; 65 | · replace x := congr_arg List.toFinset x; rw [ Finset.ext_iff ] at x; have := x a; have := x b; have := x c; aesop; 66 | have := x a; have := x b; have := x c; norm_num at *; 67 | grind; 68 | · replace x := congr_arg List.toFinset x; rw [ Finset.ext_iff ] at x; have ha := x a; have hb := x b; have hc := x c; have hk := x k; norm_num at *; 69 | grind 70 | 71 | /- 72 | Let $N$ be an integer satisfying the condition in Definition~\ref{def:s_N}. If $1 < d_1 < d_2 < d_3 < \dots$ are the positive divisors of $N$ greater than 1 in increasing order, then the three largest proper divisors of $N$ are $N/d_1$, $N/d_2$, and $N/d_3$. 73 | -/ 74 | lemma lem_s_N_smallest_divisors (N : ℕ) (h_card : 3 ≤ N.properDivisors.card) : 75 | let d₁ := ((N.divisors.erase 1).sort (· ≤ ·))[0]! 76 | let d₂ := ((N.divisors.erase 1).sort (· ≤ ·))[1]! 77 | let d₃ := ((N.divisors.erase 1).sort (· ≤ ·))[2]! 78 | s N = N / d₁ + N / d₂ + N / d₃ := by 79 | -- The three largest proper divisors of $N$ are $N/d_1$, $N/d_2$, and $N/d_3$, where $d_1$, $d_2$, and $d_3$ are the three smallest divisors of $N$ greater than 1. 80 | have h_largest : (N.properDivisors.sort (· ≥ ·))[0]! = N / ((N.divisors.erase 1).sort (· ≤ ·))[0]! ∧ 81 | (N.properDivisors.sort (· ≥ ·))[1]! = N / ((N.divisors.erase 1).sort (· ≤ ·))[1]! ∧ 82 | (N.properDivisors.sort (· ≥ ·))[2]! = N / ((N.divisors.erase 1).sort (· ≤ ·))[2]! := by 83 | have h_largest : (N.properDivisors.sort (· ≥ ·)) = List.map (fun d => N / d) ((N.divisors.erase 1).sort (· ≤ ·)) := by 84 | have h_largest : List.Sorted (· ≥ ·) (List.map (fun d => N / d) ((N.divisors.erase 1).sort (· ≤ ·))) ∧ List.Nodup (List.map (fun d => N / d) ((N.divisors.erase 1).sort (· ≤ ·))) := by 85 | aesop; 86 | · -- Since the original list of divisors is sorted in ascending order, applying N/d to each element will reverse the order, resulting in a list sorted in descending order. 87 | have h_sorted : ∀ {l : List ℕ}, (∀ d ∈ l, d ∣ N) → List.Sorted (· ≤ ·) l → List.Sorted (· ≥ ·) (List.map (fun d => N / d) l) := by 88 | intros l hl_div hl_sorted; induction hl_sorted <;> aesop; 89 | exact Nat.div_le_div_left ( a_1 _ a_4 ) ( Nat.pos_of_dvd_of_pos left ( Nat.pos_of_ne_zero ( by aesop_cat ) ) ); 90 | exact h_sorted ( fun d hd => Nat.dvd_of_mem_divisors <| Finset.mem_of_mem_erase <| Finset.mem_sort ( α := ℕ ) ( · ≤ · ) |>.1 hd ) <| Finset.sort_sorted _ _; 91 | · rw [ List.nodup_map_iff_inj_on ]; 92 | · aesop; 93 | exact?; 94 | · exact Finset.sort_nodup _ _; 95 | -- To prove the equality of the two lists, we can show that they are permutations of each other and that they are both sorted in the required order. 96 | have h_perm : List.Perm (List.map (fun d => N / d) ((N.divisors.erase 1).sort (· ≤ ·))) (Finset.sort (· ≥ ·) N.properDivisors) := by 97 | -- Since every proper divisor of $N$ can be written as $N/d$ for some divisor $d$ of $N$, the list of $N/d$ for each $d$ in the sorted list of divisors (excluding 1) is exactly the list of proper divisors. 98 | have h_perm : List.toFinset (List.map (fun d => N / d) ((N.divisors.erase 1).sort (· ≤ ·))) = N.properDivisors := by 99 | ext; aesop; 100 | · -- Since $w \mid N$, we have $N / w \mid N$ by definition of division. 101 | apply Nat.div_dvd_of_dvd left_2; 102 | · exact Nat.div_lt_self ( Nat.pos_of_ne_zero right_2 ) ( lt_of_le_of_ne ( Nat.pos_of_dvd_of_pos left_2 ( Nat.pos_of_ne_zero right_2 ) ) ( Ne.symm left_1 ) ); 103 | · exact ⟨ N / a, ⟨ by nlinarith [ Nat.div_mul_cancel left_1 ], Nat.div_dvd_of_dvd left_1, by linarith ⟩, by rw [ Nat.div_div_self ] <;> aesop ⟩; 104 | rw [ List.perm_iff_count ]; 105 | intro a; replace h_perm := Finset.ext_iff.mp h_perm a; aesop; 106 | by_cases ha : a ∈ List.map ( fun d => N / d ) ( Finset.sort ( fun x1 x2 => x1 ≤ x2 ) ( N.divisors.erase 1 ) ) <;> aesop; 107 | rw [ List.count_eq_zero_of_not_mem, List.count_eq_zero_of_not_mem ] <;> aesop; 108 | rw [ List.eq_of_perm_of_sorted h_perm h_largest.1 ( Finset.sort_sorted _ _ ) ]; 109 | rcases n : Finset.sort ( · ≤ · ) ( Nat.divisors N |> Finset.erase <| 1 ) with _ | ⟨ a, _ | ⟨ b, _ | ⟨ c, _ | n ⟩ ⟩ ⟩ <;> aesop; 110 | unfold s; aesop; 111 | 112 | /- 113 | If an integer $N$ is divisible by 2 but not by 3, then $s(N) < N$. 114 | -/ 115 | lemma lem_s_N_bound_yes_2_no_3 (N : ℕ) (hpos : 0 < N) (h_card : 3 ≤ N.properDivisors.card) 116 | (h2 : 2 ∣ N) (h3 : ¬ (3 ∣ N)) : s N < N := by 117 | -- Let's denote the three largest proper divisors of $N$ as $d_1$, $d_2$, and $d_3$. 118 | obtain ⟨d1, d2, d3, hd1, hd2, hd3, hd_distinct⟩ : ∃ d1 d2 d3, d1 ∈ N.properDivisors ∧ d2 ∈ N.properDivisors ∧ d3 ∈ N.properDivisors ∧ d1 > d2 ∧ d2 > d3 ∧ d1 + d2 + d3 = s N := by 119 | -- Since $N$ has at least three proper divisors, we can select the three largest ones from the sorted list of proper divisors. 120 | obtain ⟨d1, d2, d3, hd1, hd2, hd3, hd_sorted⟩ : ∃ d1 d2 d3, d1 ∈ N.properDivisors ∧ d2 ∈ N.properDivisors ∧ d3 ∈ N.properDivisors ∧ d1 > d2 ∧ d2 > d3 ∧ d1 ∈ (N.properDivisors.sort (· ≥ ·)) ∧ d2 ∈ (N.properDivisors.sort (· ≥ ·)) ∧ d3 ∈ (N.properDivisors.sort (· ≥ ·)) ∧ (N.properDivisors.sort (· ≥ ·)).take 3 = [d1, d2, d3] := by 121 | rcases n : Finset.sort ( fun x1 x2 ↦ x1 ≥ x2 ) N.properDivisors with _ | ⟨ d1, _ | ⟨ d2, _ | ⟨ d3, _ | n ⟩ ⟩ ⟩ ; aesop; 122 | · have := congr_arg List.length n; norm_num at this; 123 | interval_cases N ; contradiction; 124 | · replace n := congr_arg List.length n; aesop; 125 | · -- Since the cardinality of the proper divisors is at least 3, the sorted list cannot have only two elements. This leads to a contradiction. 126 | have h_contra : (Finset.sort (fun x1 x2 => x1 ≥ x2) N.properDivisors).length ≥ 3 := by 127 | simpa using h_card; 128 | aesop; 129 | · -- Since the list is sorted in descending order, we have $d1 > d2 > d3$. 130 | have h_sorted : d1 > d2 ∧ d2 > d3 := by 131 | have := n ▸ Finset.sort_sorted_gt N.properDivisors; aesop; 132 | exact ⟨ d1, d2, d3, by replace n := congr_arg List.toFinset n; rw [ Finset.ext_iff ] at n; specialize n d1; aesop, by replace n := congr_arg List.toFinset n; rw [ Finset.ext_iff ] at n; specialize n d2; aesop, by replace n := congr_arg List.toFinset n; rw [ Finset.ext_iff ] at n; specialize n d3; aesop, h_sorted.1, h_sorted.2, by aesop ⟩; 133 | · have := Finset.sort_sorted_gt N.properDivisors; aesop; 134 | all_goals replace n := congr_arg List.toFinset n; rw [ Finset.ext_iff ] at n; have := n d1; have := n d2; have := n d3; have := n n_1; aesop; 135 | grind; 136 | · specialize n d1; aesop; 137 | · specialize n d2; aesop; 138 | · specialize n d2; aesop; 139 | · specialize n d3; aesop; 140 | · exact ( n d3 ) |>.2 ( Or.inr <| Or.inr <| Or.inl rfl ) |>.2; 141 | -- Since the list take 3 of the sorted proper divisors is [d1, d2, d3], these are the three largest elements. Hence, their sum is s(N). 142 | use d1, d2, d3; 143 | unfold s; 144 | rcases n : Finset.sort ( fun x1 x2 => x1 ≥ x2 ) N.properDivisors with _ | ⟨ a, _ | ⟨ b, _ | ⟨ c, _ | n ⟩ ⟩ ⟩ <;> aesop; 145 | -- Since $2|N$, we have $d_1 = N/2$. 146 | have hd1_eq : d1 ≤ N / 2 := by 147 | -- Since $d1$ divides $N$ and $d1 < N$, we can write $N = d1 * k$ for some integer $k \geq 2$. 148 | obtain ⟨k, hk⟩ : ∃ k, N = d1 * k ∧ 2 ≤ k := by 149 | aesop; 150 | exact Exists.elim left fun k hk => ⟨ k, hk, by nlinarith only [ hk, right, left_3, left_4 ] ⟩; 151 | rw [ Nat.le_div_iff_mul_le ] <;> nlinarith only [ hk ]; 152 | -- Since $3 \nmid N$, we have $d_2 \leq N/4$. 153 | have hd2_eq : d2 ≤ N / 4 := by 154 | rw [ Nat.le_div_iff_mul_le ] <;> aesop; 155 | rcases left_1 with ⟨ k, hk ⟩; 156 | rcases k with ( _ | _ | _ | _ | k ) <;> simp_all ( config := { decide := Bool.true } ); 157 | grind; 158 | grind 159 | 160 | /- 161 | For an integer $N$ with smallest divisors greater than 1 being $d_1 < d_2 < d_3$, the function $s(N)$ from Definition~\ref{def:s_N} is given by $s(N) = N(\frac{1}{d_1} + \frac{1}{d_2} + \frac{1}{d_3})$. 162 | -/ 163 | lemma lem_s_N_formula (N : ℕ) (h_card : 3 ≤ N.properDivisors.card) : 164 | let d₁ := ((N.divisors.erase 1).sort (· ≤ ·))[0]! 165 | let d₂ := ((N.divisors.erase 1).sort (· ≤ ·))[1]! 166 | let d₃ := ((N.divisors.erase 1).sort (· ≤ ·))[2]! 167 | (s N : ℚ) = (N : ℚ) * (1 / (d₁ : ℚ) + 1 / (d₂ : ℚ) + 1 / (d₃ : ℚ)) := by 168 | -- Apply the lemma lem_s_N_smallest_divisors to express s(N) in terms of the reciprocals of the smallest divisors. 169 | have h_s_N : s N = N / ((N.divisors.erase 1).sort (· ≤ ·))[0]! + N / ((N.divisors.erase 1).sort (· ≤ ·))[1]! + N / ((N.divisors.erase 1).sort (· ≤ ·))[2]! := by 170 | -- Apply the lemma lem_s_N_smallest_divisors to conclude the proof. 171 | apply lem_s_N_smallest_divisors; 172 | assumption; 173 | rcases n : ( Finset.sort ( fun x1 x2 => x1 ≤ x2 ) ( N.divisors.erase 1 ) ) with _ | ⟨ a, _ | ⟨ b, _ | ⟨ c, _ | n ⟩ ⟩ ⟩ <;> aesop; 174 | · replace n := congr_arg List.toFinset n; rw [ Finset.ext_iff ] at n; specialize n a; aesop; 175 | · rw [ Nat.cast_div ( Nat.dvd_of_mem_divisors <| Finset.mem_of_mem_erase <| Finset.mem_sort ( α := ℕ ) ( · ≤ · ) |>.1 <| by rw [ n ] ; simp ( config := { decide := Bool.true } ) ), Nat.cast_div ( Nat.dvd_of_mem_divisors <| Finset.mem_of_mem_erase <| Finset.mem_sort ( α := ℕ ) ( · ≤ · ) |>.1 <| by rw [ n ] ; simp ( config := { decide := Bool.true } ) ) ]; 176 | · ring; 177 | · replace n := congr_arg List.toFinset n; rw [ Finset.ext_iff ] at n; specialize n b; aesop; 178 | · replace n := congr_arg List.toFinset n; rw [ Finset.ext_iff ] at n; specialize n 0; aesop; 179 | · have hn : a ∣ N ∧ b ∣ N ∧ c ∣ N := by 180 | replace n := congr_arg List.toFinset n; rw [ Finset.ext_iff ] at n; aesop; 181 | · specialize n a; aesop; 182 | · grind; 183 | · specialize n c; aesop; 184 | rw [ Nat.cast_div ( by tauto ), Nat.cast_div ( by tauto ), Nat.cast_div ( by tauto ) ] <;> ring <;> aesop; 185 | · -- By definition of $d₁$, $d₂$, and $d₃$, we know that $d₁$, $d₂$, and $d₃$ are the three smallest divisors of $N$ greater than 1. 186 | have h_divisors : d₁ ∣ N ∧ d₂ ∣ N ∧ d₃ ∣ N := by 187 | replace n := congr_arg List.toFinset n; rw [ Finset.ext_iff ] at n; aesop; 188 | · specialize n a; aesop; 189 | · -- By definition of $n$, we know that $b$ divides $N$. 190 | specialize n b; aesop; 191 | · specialize n c; aesop; 192 | rw [ Nat.cast_div, Nat.cast_div, Nat.cast_div ] <;> aesop; 193 | ring 194 | 195 | /- 196 | If an integer $N$ is divisible by 3 but not by 2, then $s(N) < N$. 197 | -/ 198 | lemma lem_s_N_bound_yes_3_no_2 (N : ℕ) (hpos : 0 < N) (h_card : 3 ≤ N.properDivisors.card) 199 | (h3 : 3 ∣ N) (h2 : ¬ (2 ∣ N)) : s N < N := by 200 | -- Use the provided lemma lem_s_N_smallest_divisors to relate s(N) to the smallest divisors of N. 201 | have h_smallest : let d₁ := ((N.divisors.erase 1).sort (· ≤ ·))[0]! 202 | let d₂ := ((N.divisors.erase 1).sort (· ≤ ·))[1]! 203 | let d₃ := ((N.divisors.erase 1).sort (· ≤ ·))[2]! 204 | s N = N / d₁ + N / d₂ + N / d₃ := by 205 | exact?; 206 | -- Since $N$ is divisible by 3 but not by 2, the smallest three divisors of $N$ greater than 1 are at least 3, 5, and 7. 207 | have hd₁ : ((N.divisors.erase 1).sort (· ≤ ·))[0]! ≥ 3 := by 208 | have h_min_divisor1 : ∀ d ∈ N.divisors.erase 1, 3 ≤ d := by 209 | aesop; 210 | contrapose! left; interval_cases d <;> simp_all ( config := { decide := Bool.true } ) [ Nat.dvd_iff_mod_eq_zero ] ; 211 | rcases n : Finset.sort ( fun x1 x2 => x1 ≤ x2 ) ( Nat.divisors N |> Finset.erase <| 1 ) with ( _ | ⟨ d₁, _ | ⟨ d₂, _ | ⟨ d₃, _ | k ⟩ ⟩ ⟩ ) <;> aesop; 212 | · replace n := congr_arg List.length n; aesop; 213 | rw [ Finset.erase_eq_iff_eq_insert ] at n <;> aesop; 214 | rw [ Finset.eq_singleton_iff_unique_mem ] at n ; aesop; 215 | · replace n := congr_arg List.toFinset n; rw [ Finset.ext_iff ] at n; specialize n d₁; aesop; 216 | · replace n := congr_arg List.length n; aesop; 217 | rw [ ← Nat.cons_self_properDivisors ] at * <;> aesop; 218 | rcases N with ( _ | _ | N ) <;> simp_all +arith +decide; 219 | · replace n := congr_arg List.toFinset n; rw [ Finset.ext_iff ] at n; specialize n d₁; aesop; 220 | · replace n := congr_arg List.toFinset n; rw [ Finset.ext_iff ] at n; specialize n d₁; aesop; 221 | have hd₂ : ((N.divisors.erase 1).sort (· ≤ ·))[1]! ≥ 5 := by 222 | rcases n : ( Finset.sort ( fun x1 x2 => x1 ≤ x2 ) ( N.divisors.erase 1 ) ) with _ | ⟨ a, _ | ⟨ b, l ⟩ ⟩ ; aesop; 223 | · replace n := congr_arg List.length n; aesop; 224 | rw [ Finset.card_erase_of_mem ] at n <;> aesop; 225 | rw [ ← Nat.cons_self_properDivisors ] at n <;> aesop; 226 | · have := Finset.sort_sorted ( · ≤ · ) ( N.divisors.erase 1 ) ; aesop; 227 | have hb_ne_a : b ≠ a := by 228 | intro h; have := List.nodup_cons.mp ( n.symm ▸ Finset.sort_nodup _ _ ) ; aesop; 229 | have hb_odd : b % 2 = 1 := by 230 | replace n := congr_arg List.toFinset n; rw [ Finset.ext_iff ] at n; specialize n b; aesop; 231 | exact Nat.mod_two_ne_zero.mp fun con => by have := Nat.mod_eq_zero_of_dvd ( dvd_trans ( Nat.dvd_of_mod_eq_zero con ) left_3 ) ; aesop; 232 | contrapose! hb_ne_a; interval_cases b <;> interval_cases a ; trivial; 233 | · contradiction; 234 | · trivial 235 | have hd₃ : ((N.divisors.erase 1).sort (· ≤ ·))[2]! ≥ 7 := by 236 | have hd₃ : ((N.divisors.erase 1).sort (· ≤ ·))[2]! > ((N.divisors.erase 1).sort (· ≤ ·))[1]! := by 237 | rcases n : Finset.sort ( fun x1 x2 => x1 ≤ x2 ) ( N.divisors.erase 1 ) with ( _ | ⟨ a, _ | ⟨ b, _ | ⟨ c, _ | n ⟩ ⟩ ⟩ ) <;> aesop; 238 | · replace n := congr_arg List.length n ; simp_all +arith +decide; 239 | rw [ ← Nat.cons_self_properDivisors ] at * <;> aesop; 240 | rcases N with ( _ | _ | N ) <;> simp_all +arith +decide; 241 | · have := Finset.sort_sorted ( · ≤ · ) ( N.divisors.erase 1 ) ; aesop; 242 | have := n ▸ Finset.sort_nodup ( · ≤ · ) ( N.divisors.erase 1 ) ; aesop; 243 | exact lt_of_le_of_ne right right_2; 244 | · have := Finset.sort_sorted ( · ≤ · ) ( N.divisors.erase 1 ) ; aesop; 245 | have := Finset.sort_nodup ( fun x1 x2 => x1 ≤ x2 ) ( N.divisors.erase 1 ) ; aesop; 246 | exact lt_of_le_of_ne left_1 left_8; 247 | by_contra hd₃_lt_7; 248 | interval_cases _ : ( Finset.sort ( fun x1 x2 => x1 ≤ x2 ) ( N.divisors.erase 1 ) )[2]!; 249 | all_goals interval_cases _ : ( Finset.sort ( fun x1 x2 => x1 ≤ x2 ) ( N.divisors.erase 1 ) )[1]!; 250 | -- Since $6$ is a divisor of $N$, it must be that $2 \mid N$, contradicting $h2$. 251 | have h_contra : 6 ∣ N := by 252 | rcases x : Finset.sort ( fun x1 x2 => x1 ≤ x2 ) ( N.divisors.erase 1 ) with _ | ⟨ a, _ | ⟨ b, _ | ⟨ c, _ | k ⟩ ⟩ ⟩ <;> aesop; 253 | · replace x := congr_arg List.toFinset x; rw [ Finset.ext_iff ] at x; specialize x 6; aesop; 254 | · replace x := congr_arg List.toFinset x; rw [ Finset.ext_iff ] at x; specialize x 6; aesop; 255 | exact h2 ( dvd_trans ( by decide ) h_contra ); 256 | -- Substitute the bounds for the smallest divisors into the expression for $s(N)$. 257 | have h_bound : s N ≤ N / 3 + N / 5 + N / 7 := by 258 | exact h_smallest ▸ add_le_add_three ( Nat.div_le_div_left hd₁ ( by decide ) ) ( Nat.div_le_div_left hd₂ ( by decide ) ) ( Nat.div_le_div_left hd₃ ( by decide ) ); 259 | grind 260 | 261 | /- 262 | If an integer $N$ is not divisible by 6, then $s(N) < N$. 263 | -/ 264 | lemma lem_s_N_less_than_N_if_not_div_by_6 (N : ℕ) (hpos : 0 < N) 265 | (h_card : 3 ≤ N.properDivisors.card) (h6 : ¬ (6 ∣ N)) : s N < N := by 266 | -- Since $N$ is not divisible by 6, it must be either not divisible by 2, not divisible by 3, or both. 267 | by_cases h2 : 2 ∣ N; 268 | · -- Since $N$ is divisible by 2 but not by 3, we can apply the lemma lem_s_N_bound_yes_2_no_3. 269 | apply lem_s_N_bound_yes_2_no_3 N hpos h_card h2 (by 270 | exact fun h3 => h6 ( Nat.lcm_dvd h2 h3 )); 271 | · by_cases h3 : 3 ∣ N; 272 | · exact?; 273 | · exact? 274 | 275 | /- 276 | If $6|N$ and $v_2(N) \ge 2$, then $s(N) = \frac{13}{12}N$. 277 | -/ 278 | lemma lem_s_N_val_div_by_6_v2_ge_2 (N : ℕ) (h_card : 3 ≤ N.properDivisors.card) 279 | (h6 : 6 ∣ N) (h_v2 : 2 ≤ padicValNat 2 N) : 12 * s N = 13 * N := by 280 | -- Since $6 \mid N$ and $v_2(N) \ge 2$, the three smallest divisors of $N$ greater than 1 are $2$, $3$, and $4$. 281 | have h_smallest_divisors : let d₁ := ((N.divisors.erase 1).sort (· ≤ ·))[0]! 282 | let d₂ := ((N.divisors.erase 1).sort (· ≤ ·))[1]! 283 | let d₃ := ((N.divisors.erase 1).sort (· ≤ ·))[2]! 284 | d₁ = 2 ∧ d₂ = 3 ∧ d₃ = 4 := by 285 | have h_smallest_divisors : ((Nat.divisors N).erase 1).sort (· ≤ ·) = (insert 2 (insert 3 (insert 4 (((Nat.divisors N).erase 1).filter (fun d => d > 4))))).sort (· ≤ ·) := by 286 | congr with x ; aesop; 287 | · rcases x with ( _ | _ | _ | _ | _ | x ) <;> simp_all +arith +decide; 288 | · exact dvd_trans ( by norm_num ) h6; 289 | · exact dvd_trans ( by norm_num ) h6; 290 | · exact dvd_trans ( pow_dvd_pow 2 h_v2 ) ( Nat.ordProj_dvd _ _ ); 291 | rw [ h_smallest_divisors ]; 292 | rw [ Finset.sort_insert, Finset.sort_insert, Finset.sort_insert ] ; aesop; 293 | all_goals norm_num; 294 | · grind; 295 | · intros; linarith; 296 | · intros; linarith; 297 | -- Substitute the values of $d₁$, $d₂$, and $d₃$ into the formula for $s(N)$. 298 | have h_s_formula : s N = N * (1 / 2 + 1 / 3 + 1 / 4 : ℚ) := by 299 | -- Apply the formula for $s(N)$ with the known values of the divisors. 300 | rw [lem_s_N_formula N h_card] 301 | simp [h_smallest_divisors]; 302 | exact_mod_cast ( by linarith : ( 12 : ℚ ) * s N = 13 * N ) 303 | 304 | /- 305 | If $v_2(N)=1$, $3|N$, and $5 \nmid N$, then $s(N) = N$. 306 | -/ 307 | lemma lem_s_N_val_div_by_6_v2_eq_1_no_5 (N : ℕ) (h_card : 3 ≤ N.properDivisors.card) 308 | (h_v2 : padicValNat 2 N = 1) (h3 : 3 ∣ N) (h5 : ¬ (5 ∣ N)) : s N = N := by 309 | -- Since $N$ is divisible by 3 and not by 5, the three largest proper divisors are $N/2$, $N/3$, and $N/6$. 310 | have h_divisors : (N.divisors.erase 1).sort (· ≤ ·) = [2, 3, 6] ++ ((N.divisors.erase 1).erase 2 |>.erase 3 |>.erase 6 |>.sort (· ≤ ·)) := by 311 | -- Since $2$, $3$, and $6$ are the smallest divisors of $N$ greater than $1$, they must appear first in the sorted list of divisors. 312 | have h_smallest_divisors : 2 ∈ N.divisors.erase 1 ∧ 3 ∈ N.divisors.erase 1 ∧ 6 ∈ N.divisors.erase 1 ∧ ∀ d ∈ N.divisors.erase 1, d < 2 → False ∧ ∀ d ∈ N.divisors.erase 1, d < 3 → False ∧ ∀ d ∈ N.divisors.erase 1, d < 6 → False := by 313 | aesop; 314 | · -- Since the 2-adic valuation of N is 1, it means that 2 divides N. 315 | have h_two_div : 2 ^ 1 ∣ N := by 316 | exact h_v2 ▸ Nat.ordProj_dvd _ _; 317 | exact h_two_div; 318 | · exact Nat.lcm_dvd h3 ( show 2 ∣ N from ( by contrapose! h_v2; simp_all ( config := { decide := Bool.true } ) [ padicValNat.eq_zero_of_not_dvd ] ) ); 319 | · exact Nat.lt_of_le_of_ne ( Nat.pos_of_dvd_of_pos a_1 ( Nat.pos_of_ne_zero a_2 ) ) ( Ne.symm a ); 320 | have h_sorted_divisors : Finset.sort (· ≤ ·) (insert 2 (insert 3 (insert 6 ((N.divisors.erase 1).erase 2 |>.erase 3 |>.erase 6)))) = [2, 3, 6] ++ Finset.sort (· ≤ ·) ((N.divisors.erase 1).erase 2 |>.erase 3 |>.erase 6) := by 321 | rw [ Finset.sort_insert, Finset.sort_insert, Finset.sort_insert ]; 322 | all_goals simp_all ( config := { decide := Bool.true } ); 323 | · intro b hb hb' hb'' hb''' hb''''; contrapose! hb; interval_cases b <;> simp_all ( config := { decide := Bool.true } ) ; 324 | obtain ⟨ k, hk ⟩ := hb''''; simp_all ( config := { decide := Bool.true } ) [ padicValNat.mul ] ; 325 | exact absurd h_v2 ( by { exact ne_of_gt ( lt_add_of_lt_of_nonneg ( by native_decide ) ( Nat.zero_le _ ) ) } ); 326 | · grind; 327 | convert h_sorted_divisors using 2; 328 | ext d; by_cases hd2 : d = 2 <;> by_cases hd3 : d = 3 <;> by_cases hd6 : d = 6 <;> aesop; 329 | -- Substitute the values of $d₁$, $d₂$, and $d₃$ into the formula for $s(N)$. 330 | have h_s_formula : s N = N * (1 / 2 + 1 / 3 + 1 / 6 : ℚ) := by 331 | rw [ lem_s_N_formula ]; 332 | · -- Since the list is [2, 3, 6], the first three elements are indeed 2, 3, and 6. Therefore, the sum of their reciprocals is 1/2 + 1/3 + 1/6. 333 | simp [h_divisors]; 334 | · assumption; 335 | exact_mod_cast ( by linarith : ( s N : ℚ ) = N ) 336 | 337 | /- 338 | If $v_2(N)=1$, $3|N$, and $5|N$, then $s(N) = \frac{31}{30}N$. 339 | -/ 340 | lemma lem_s_N_val_div_by_6_v2_eq_1_yes_5 (N : ℕ) (h_card : 3 ≤ N.properDivisors.card) 341 | (h_v2 : padicValNat 2 N = 1) (h3 : 3 ∣ N) (h5 : 5 ∣ N) : 30 * s N = 31 * N := by 342 | -- By Lemma~\ref{lem:s_N_formula}, $s(N) = N(\frac{1}{2}+\frac{1}{3}+\frac{1}{5})$. 343 | have h_s_formula : s N = N * (1 / 2 + 1 / 3 + 1 / 5 : ℚ) := by 344 | -- Since $N$ is divisible by 2, 3, and 5, and $v_2(N) = 1$, the three smallest divisors greater than 1 are 2, 3, and 5. 345 | have h_divisors : ((N.divisors.erase 1).sort (· ≤ ·))[0]! = 2 ∧ ((N.divisors.erase 1).sort (· ≤ ·))[1]! = 3 ∧ ((N.divisors.erase 1).sort (· ≤ ·))[2]! = 5 := by 346 | -- Since $N$ is divisible by $2$, $3$, and $5$, these are the smallest divisors greater than $1$. 347 | have h_smallest_divisors : (Nat.divisors N).erase 1 = insert 2 (insert 3 (insert 5 ((Nat.divisors N).erase 1 \ {2, 3, 5}))) := by 348 | ext; aesop; 349 | · tauto; 350 | · -- Since the p-adic valuation of 2 in N is 1, it means that 2 divides N. 351 | have h2 : 2 ^ 1 ∣ N := by 352 | exact h_v2 ▸ Nat.ordProj_dvd _ _; 353 | exact h2; 354 | -- Since the list is sorted, the first three elements are the smallest elements in the set. 355 | have h_sorted : (Finset.sort (· ≤ ·) (Insert.insert 2 (Insert.insert 3 (Insert.insert 5 ((Nat.divisors N).erase 1 \ {2, 3, 5}))))).take 3 = [2, 3, 5] := by 356 | rw [ Finset.sort_insert, Finset.sort_insert, Finset.sort_insert ]; 357 | all_goals norm_num [ Finset.mem_insert, Finset.mem_singleton ]; 358 | · intro b hb h2 h3 h4 h5 h6; contrapose! hb; interval_cases b <;> simp_all ( config := { decide := Bool.true } ) ; 359 | obtain ⟨ k, hk ⟩ := h2; simp_all ( config := { decide := Bool.true } ) [ padicValNat.mul ] ; 360 | exact absurd h_v2 ( by { exact ne_of_gt ( lt_add_of_lt_of_nonneg ( by native_decide ) ( Nat.zero_le _ ) ) } ); 361 | · intro a ha₁ ha₂ ha₃ ha₄ ha₅ ha₆; contrapose! ha₁; interval_cases a <;> simp_all ( config := { decide := Bool.true } ) ; 362 | · exact fun a ha₁ ha₂ ha₃ ha₄ ha₅ ha₆ => Nat.lt_of_le_of_ne ( Nat.pos_of_dvd_of_pos ha₂ ( Nat.pos_of_ne_zero ha₃ ) ) ( Ne.symm ha₁ ); 363 | rcases n : Finset.sort ( fun x1 x2 => x1 ≤ x2 ) ( Insert.insert 2 ( Insert.insert 3 ( Insert.insert 5 ( N.divisors.erase 1 \ { 2, 3, 5 } ) ) ) ) with _ | ⟨ a, _ | ⟨ b, _ | ⟨ c, _ | n ⟩ ⟩ ⟩ <;> simp ( config := { decide := Bool.true } ) [ n ] at h_sorted ⊢; 364 | · grind; 365 | · -- Substitute the values from h_sorted into the list n to conclude the proof. 366 | simp [h_sorted] at *; 367 | rw [ h_smallest_divisors ] ; simp ( config := { decide := Bool.true } ) [ n ] ; 368 | rw [ lem_s_N_formula N h_card ]; 369 | aesop; 370 | exact_mod_cast ( by linarith : ( 30 : ℚ ) * s N = 31 * N ) 371 | 372 | /- 373 | If $N$ is an odd integer, then $s(N)$ is odd and therefore not divisible by 6. 374 | -/ 375 | lemma lem_preservation_of_not_div_6_odd (N : ℕ) (h_card : 3 ≤ N.properDivisors.card) 376 | (h_odd : Odd N) : Odd (s N) := by 377 | -- Since $N$ is odd, all its divisors are odd. Therefore, each of the three largest proper divisors is odd. 378 | have h_divisors_odd : ∀ d ∈ N.properDivisors, Odd d := by 379 | exact fun d hd => h_odd.of_dvd_nat <| Nat.mem_properDivisors.mp hd |>.1; 380 | -- Since the three largest proper divisors of $N$ are all odd, their sum $s(N)$ is also odd. 381 | have h_sum_odd : ∀ {l : List ℕ}, (∀ d ∈ l, Odd d) → List.length l ≥ 3 → Odd (l.get! 0 + l.get! 1 + l.get! 2) := by 382 | intros l hl hl'; rcases l with ( _ | ⟨ a, _ | ⟨ b, _ | ⟨ c, _ | l ⟩ ⟩ ⟩ ) <;> simp_all +arith +decide [ parity_simps ] ; 383 | · aesop; 384 | · exact absurd a_1 ( by simpa using left_1 ); 385 | · exact absurd a_1 ( by simpa using right ); 386 | · aesop; 387 | · -- Since $b$ is both odd and even, this is a contradiction. 388 | exfalso; exact absurd a_1 (by simpa using left_1); 389 | · exact absurd a_1 ( by simpa using left_2 ); 390 | unfold s; aesop; 391 | 392 | /- 393 | If an integer $N$ satisfies the conditions of Lemma~\ref{lem:necessary_conditions_summary}, then $N$ is of the form $6 \cdot 12^a \cdot m$ for some integer $a \ge 0$ and a positive integer $m$ with $\gcd(m,10)=1$. 394 | -/ 395 | lemma lem_conditions_imply_form (N a : ℕ) (hN : 0 < N) (h_v2 : padicValNat 2 N = 2 * a + 1) 396 | (h_v3 : a + 1 ≤ padicValNat 3 N) (h_v5 : padicValNat 5 N = 0) : 397 | ∃ m, 0 < m ∧ Nat.Coprime m 10 ∧ N = 6 * 12^a * m := by 398 | -- We can write $N = 2^{2a+1} \cdot 3^{a+1} \cdot M$, where $M$ is not divisible by 2, 3, or 5. 399 | obtain ⟨M, hM⟩ : ∃ M, N = 2^(2*a+1) * 3^(a+1) * M := by 400 | -- Since $2^{2a+1}$ and $3^{a+1}$ are coprime and both divide $N$, their product $2^{2a+1} \cdot 3^{a+1}$ must also divide $N$. 401 | have h_coprime : Nat.gcd (2^(2*a+1)) (3^(a+1)) = 1 := by 402 | norm_num; 403 | apply_mod_cast Nat.Coprime.mul_dvd_of_dvd_of_dvd <;> aesop; 404 | · exact h_v2 ▸ Nat.ordProj_dvd _ _; 405 | · exact dvd_trans ( pow_dvd_pow _ h_v3 ) ( Nat.ordProj_dvd _ _ ); 406 | refine' ⟨ M, _, _, _ ⟩; 407 | · -- Since $N$ is positive and $N = 2^{2a+1} \cdot 3^{a+1} \cdot M$, if $M$ were zero or negative, then $N$ would be zero or negative, which contradicts $hN$. Therefore, $M$ must be positive. 408 | aesop; 409 | · rw [ show 10 = 2 * 5 by norm_num, Nat.coprime_mul_iff_right ] ; aesop; 410 | · contrapose! h_1; 411 | rw [ padicValNat.mul, padicValNat.mul ] at * <;> aesop; 412 | simp_all ( config := { decide := Bool.true } ) [ padicValNat.eq_zero_of_not_dvd, ← even_iff_two_dvd, parity_simps ]; 413 | · exact Nat.Coprime.symm ( Nat.Prime.coprime_iff_not_dvd ( by norm_num ) |>.2 fun h => h_1 <| dvd_mul_of_dvd_right h _ ); 414 | · rw [ hM ] ; ring; 415 | norm_num [ pow_mul', mul_assoc, ← mul_pow ] 416 | 417 | /- 418 | If $a_1$ has the form $6 \cdot 12^a \cdot m$ for $a \ge 0$ and $\gcd(m,10)=1$, it generates an infinite sequence. 419 | -/ 420 | lemma lem_sufficiency_stabilization (a m : ℕ) (hm : 0 < m) (h_coprime : Nat.Coprime m 10) : 421 | ∃ a_seq : ℕ → ℕ, a_seq 0 = 6 * 12^a * m ∧ 422 | (∀ n, 0 < a_seq n) ∧ 423 | (∀ n, 3 ≤ (a_seq n).properDivisors.card) ∧ 424 | (∀ n, a_seq (n + 1) = s (a_seq n)) := by 425 | -- Now consider the sequence starting at $a_1 = 6 \cdot 12^a \cdot m$. We need to show that this generates an infinite sequence. 426 | use fun n => if n ≤ a then (6 * 12^(a - n) * m) * 13^n else (6 * m) * 13^a; 427 | refine' ⟨ _, _, _, _ ⟩; 428 | · aesop; 429 | · aesop; 430 | · aesop; 431 | · -- Since $6 * 12^(a-n) * m * 13^n$ is divisible by $6$, it has at least the proper divisors $1$, $2$, and $3$. 432 | have h_divisors : {1, 2, 3} ⊆ (6 * 12^(a-n) * m * 13^n).properDivisors := by 433 | norm_num [ Finset.insert_subset_iff ]; 434 | exact ⟨ by nlinarith [ pow_pos ( by decide : 0 < 12 ) ( a - n ), pow_pos ( by decide : 0 < 13 ) n, mul_pos hm ( pow_pos ( by decide : 0 < 12 ) ( a - n ) ) ], ⟨ Nat.dvd_of_mod_eq_zero ( by norm_num [ Nat.mul_mod, Nat.pow_mod ] ), by nlinarith [ pow_pos ( by decide : 0 < 12 ) ( a - n ), pow_pos ( by decide : 0 < 13 ) n, mul_pos hm ( pow_pos ( by decide : 0 < 12 ) ( a - n ) ) ] ⟩, Nat.dvd_of_mod_eq_zero ( by norm_num [ Nat.mul_mod, Nat.pow_mod ] ), by nlinarith [ pow_pos ( by decide : 0 < 12 ) ( a - n ), pow_pos ( by decide : 0 < 13 ) n, mul_pos hm ( pow_pos ( by decide : 0 < 12 ) ( a - n ) ) ] ⟩; 435 | exact Finset.card_mono h_divisors; 436 | · -- Let's choose any $n$ such that $a < n$. We need to show that $6 * m * 13^a$ has at least three proper divisors. 437 | have h_divisors : (6 * m * 13^a).properDivisors ⊇ {1, 2, 3} := by 438 | norm_num [ Finset.insert_subset_iff ]; 439 | exact ⟨ by nlinarith [ pow_pos ( by decide : 0 < 13 ) a ], ⟨ dvd_mul_of_dvd_left ( dvd_mul_of_dvd_left ( by decide ) _ ) _, by nlinarith [ pow_pos ( by decide : 0 < 13 ) a ] ⟩, dvd_mul_of_dvd_left ( dvd_mul_of_dvd_left ( by decide ) _ ) _, by nlinarith [ pow_pos ( by decide : 0 < 13 ) a ] ⟩; 440 | exact Finset.card_mono h_divisors; 441 | · aesop; 442 | · -- By definition of $s$, we know that $s(N) = \frac{13}{12}N$ for $N = 6 \cdot 12^a \cdot m$. 443 | have h_s : ∀ a m : ℕ, 0 < m → Nat.Coprime m 10 → a ≥ 1 → s (6 * 12 ^ a * m) = 6 * 12 ^ (a - 1) * m * 13 := by 444 | intros a m hm h_coprime ha; 445 | have h_s : 12 * s (6 * 12 ^ a * m) = 13 * (6 * 12 ^ a * m) := by 446 | apply lem_s_N_val_div_by_6_v2_ge_2; 447 | · refine' Finset.two_lt_card.mpr _; 448 | norm_num; 449 | exact ⟨ 1, ⟨ one_dvd _, by nlinarith [ pow_pos ( by decide : 0 < 12 ) a ] ⟩, 2, ⟨ dvd_mul_of_dvd_left ( dvd_mul_of_dvd_left ( by decide ) _ ) _, by nlinarith [ pow_pos ( by decide : 0 < 12 ) a ] ⟩, 3, ⟨ dvd_mul_of_dvd_left ( dvd_mul_of_dvd_left ( by decide ) _ ) _, by nlinarith [ pow_pos ( by decide : 0 < 12 ) a ] ⟩, by decide, by decide, by decide ⟩; 450 | · exact dvd_mul_of_dvd_left ( dvd_mul_right _ _ ) _; 451 | · rw [ padicValNat.mul, padicValNat.mul ] <;> aesop; 452 | simp +arith +decide [ padicValNat.pow ]; 453 | exact le_add_of_nonneg_of_le ( Nat.zero_le _ ) ( by nlinarith [ show padicValNat 2 12 ≥ 2 by native_decide ] ); 454 | cases a <;> norm_num [ pow_succ' ] at * ; linarith; 455 | rw [ show a - n = a - ( n + 1 ) + 1 by omega ] ; simp ( config := { decide := Bool.true } ) [ *, pow_succ, mul_assoc ]; 456 | convert h_s ( a - ( n + 1 ) + 1 ) ( m * 13 ^ n ) ( by positivity ) ( by exact Nat.Coprime.mul h_coprime ( by cases n <;> norm_num ) ) ( by linarith [ Nat.sub_add_cancel h ] ) |> Eq.symm using 1 ; ring; 457 | · norm_num; 458 | · ring; 459 | · linarith; 460 | · cases eq_or_lt_of_le h_1 <;> first | linarith | aesop; 461 | -- By definition of $s$, we know that $s(6 * m * 13^n) = 6 * m * 13^n$. 462 | apply Eq.symm; 463 | apply lem_s_N_val_div_by_6_v2_eq_1_no_5; 464 | · -- Since $6 * m * 13^n$ is divisible by $6$, it has at least the proper divisors $1$, $2$, and $3$. 465 | have h_divisors : {1, 2, 3} ⊆ (6 * m * 13 ^ n).properDivisors := by 466 | norm_num [ Finset.insert_subset_iff ]; 467 | exact ⟨ by nlinarith [ pow_pos ( by decide : 0 < 13 ) n ], ⟨ dvd_mul_of_dvd_left ( dvd_mul_of_dvd_left ( by decide ) _ ) _, by nlinarith [ pow_pos ( by decide : 0 < 13 ) n ] ⟩, dvd_mul_of_dvd_left ( dvd_mul_of_dvd_left ( by decide ) _ ) _, by nlinarith [ pow_pos ( by decide : 0 < 13 ) n ] ⟩; 468 | exact Finset.card_mono h_divisors; 469 | · norm_num [ padicValNat.mul, hm.ne', show m ≠ 0 by linarith ]; 470 | rw [ show ( 6 : ℕ ) = 2 * 3 by norm_num, padicValNat.mul ] <;> norm_num; 471 | norm_num [ padicValNat.eq_zero_of_not_dvd, Nat.Prime.dvd_iff_one_le_factorization ]; 472 | exact Or.inr ( Nat.mod_two_ne_zero.mp fun contra => by have := Nat.dvd_gcd ( Nat.dvd_of_mod_eq_zero contra ) ( by decide : 2 ∣ 10 ) ; simp_all ( config := { decide := Bool.true } ) ); 473 | · exact dvd_mul_of_dvd_left ( dvd_mul_of_dvd_left ( by decide ) _ ) _; 474 | · norm_num [ Nat.Prime.dvd_mul, Nat.Prime.dvd_iff_one_le_factorization ]; 475 | exact fun h => by have := Nat.dvd_gcd h ( by decide : 5 ∣ 10 ) ; simp_all ( config := { decide := Bool.true } ) ; 476 | · -- By definition of $s$, we know that $s(6 * m * 13^a) = 6 * m * 13^a$. 477 | have h_s : s (6 * m * 13 ^ a) = 6 * m * 13 ^ a := by 478 | apply lem_s_N_val_div_by_6_v2_eq_1_no_5; 479 | · -- Since $6 * m * 13^a$ is divisible by $6$, it has at least the proper divisors $1$, $2$, and $3$. 480 | have h_divisors : Nat.properDivisors (6 * m * 13 ^ a) ⊇ {1, 2, 3} := by 481 | norm_num [ Finset.insert_subset_iff ]; 482 | exact ⟨ by nlinarith [ pow_pos ( by decide : 0 < 13 ) a ], ⟨ dvd_mul_of_dvd_left ( dvd_mul_of_dvd_left ( by decide ) _ ) _, by nlinarith [ pow_pos ( by decide : 0 < 13 ) a ] ⟩, dvd_mul_of_dvd_left ( dvd_mul_of_dvd_left ( by decide ) _ ) _, by nlinarith [ pow_pos ( by decide : 0 < 13 ) a ] ⟩; 483 | exact Finset.card_mono h_divisors; 484 | · rw [ padicValNat.mul, padicValNat.mul ] <;> norm_num; 485 | · rw [ show ( 6 : ℕ ) = 2 * 3 by norm_num, padicValNat.mul ] <;> norm_num; 486 | norm_num [ padicValNat.eq_zero_of_not_dvd, Nat.Prime.dvd_iff_one_le_factorization ]; 487 | exact Or.inr ( Nat.mod_two_ne_zero.mp fun contra => by have := Nat.dvd_gcd ( Nat.dvd_of_mod_eq_zero contra ) ( by decide : 2 ∣ 10 ) ; simp_all ( config := { decide := Bool.true } ) ); 488 | · linarith; 489 | · linarith; 490 | · exact dvd_mul_of_dvd_left ( dvd_mul_of_dvd_left ( by decide ) _ ) _; 491 | · norm_num [ Nat.Prime.dvd_mul, Nat.Prime.dvd_iff_one_le_factorization ]; 492 | exact fun h => by have := Nat.dvd_gcd h ( by decide : 5 ∣ 10 ) ; simp_all ( config := { decide := Bool.true } ) ; 493 | exact h_s.symm 494 | 495 | /- 496 | If an integer $N$ is even and not divisible by 3, then $s(N)$ is not divisible by 6. 497 | -/ 498 | lemma lem_preservation_of_not_div_6_no_3_even (N : ℕ) (h_card : 3 ≤ N.properDivisors.card) 499 | (h_even : Even N) (h3 : ¬ (3 ∣ N)) : ¬ (6 ∣ s N) := by 500 | -- If $N$ is even, then $d_1 = 2$. 501 | obtain ⟨d₁, hd₁⟩ : ∃ d₁, ((N.divisors.erase 1).sort (· ≤ ·))[0]! = 2 ∧ d₁ ∈ N.divisors.erase 1 := by 502 | -- Since $N$ is even, $2$ is a divisor of $N$. Also, since $N$ is not divisible by $3$, $3$ is not a divisor. The smallest divisor greater than $1$ for an even number is $2$. So, $2$ must be in the set of divisors of $N$ excluding $1$. 503 | have h_two_div : 2 ∈ N.divisors.erase 1 := by 504 | aesop; 505 | exact even_iff_two_dvd.mp h_even; 506 | rcases n : Finset.sort ( fun x1 x2 => x1 ≤ x2 ) ( N.divisors.erase 1 ) with _ | ⟨ x, _ | ⟨ y, l ⟩ ⟩ ; aesop; 507 | · replace n := congr_arg List.length n ; aesop; 508 | exact absurd n ( Nat.sub_ne_zero_of_lt ( lt_of_lt_of_le ( by decide ) ( Finset.one_lt_card.2 ⟨ 1, by aesop_cat, by aesop_cat ⟩ ) ) ); 509 | · replace n := congr_arg List.length n; aesop; 510 | · rw [ ← Nat.cons_self_properDivisors ] at n <;> aesop; 511 | · exact ⟨ 2, by decide, left ⟩; 512 | · have := Finset.sort_sorted ( fun x1 x2 => x1 ≤ x2 ) ( N.divisors.erase 1 ) ; aesop; 513 | · have := n ▸ Finset.mem_sort ( α := ℕ ) ( · ≤ · ) |>.2 ( show 2 ∈ N.divisors.erase 1 from by aesop ) ; aesop; 514 | · interval_cases x <;> simp_all ( config := { decide := Bool.true } ); 515 | · replace n := congr_arg List.toFinset n; rw [ Finset.ext_iff ] at n; specialize n 0; aesop; 516 | · replace n := congr_arg List.toFinset n; rw [ Finset.ext_iff ] at n; specialize n 1; aesop; 517 | · have := right_2 2 h_2; have := left_2 2 h_2; interval_cases x <;> interval_cases y <;> simp_all ( config := { decide := Bool.true } ) ; 518 | · replace n := congr_arg List.toFinset n; rw [ Finset.ext_iff ] at n; specialize n 0; aesop; 519 | · replace n := congr_arg List.toFinset n; rw [ Finset.ext_iff ] at n; specialize n 0; aesop; 520 | · replace n := congr_arg List.toFinset n; rw [ Finset.ext_iff ] at n; specialize n 0; aesop; 521 | · replace n := congr_arg List.toFinset n; rw [ Finset.ext_iff ] at n; specialize n 1; aesop; 522 | · replace n := congr_arg List.toFinset n; rw [ Finset.ext_iff ] at n; specialize n 1; aesop; 523 | · exact ⟨ 2, by decide, left ⟩; 524 | -- Let $d_2$ and $d_3$ be the second and third smallest divisors of $N$ greater than 1. 525 | obtain ⟨d₂, hd₂⟩ : ∃ d₂, ((N.divisors.erase 1).sort (· ≤ ·))[1]! = d₂ ∧ d₂ ∈ N.divisors.erase 1 ∧ d₂ > 2 := by 526 | rcases x : Finset.sort ( fun x1 x2 => x1 ≤ x2 ) ( Nat.divisors N |> Finset.erase <| 1 ) with ( _ | ⟨ a, _ | ⟨ b, l ⟩ ⟩ ) <;> aesop; 527 | · replace x := congr_arg List.length x ; aesop; 528 | rw [ ← Nat.cons_self_properDivisors right ] at x ; aesop; 529 | · have := x ▸ Finset.sort_sorted ( · ≤ · ) ( N.divisors.erase 1 ) ; aesop; 530 | · replace x := congr_arg List.toFinset x; rw [ Finset.ext_iff ] at x; specialize x b; aesop; 531 | · have := Finset.sort_sorted ( · ≤ · ) ( N.divisors.erase 1 ) ; aesop; 532 | refine' lt_of_le_of_ne left ( Ne.symm _ ); 533 | have := x ▸ Finset.sort_nodup ( · ≤ · ) ( N.divisors.erase 1 ) ; aesop; 534 | -- Let $d_3$ be the third smallest divisor of $N$ greater than 1. 535 | obtain ⟨d₃, hd₃⟩ : ∃ d₃, ((N.divisors.erase 1).sort (· ≤ ·))[2]! = d₃ ∧ d₃ ∈ N.divisors.erase 1 ∧ d₃ > d₂ := by 536 | rcases n : Finset.sort ( fun x1 x2 => x1 ≤ x2 ) ( N.divisors.erase 1 ) with _ | ⟨ a, _ | ⟨ b, _ | ⟨ c, _ | n ⟩ ⟩ ⟩ <;> aesop; 537 | all_goals have := Finset.sort_sorted ( · ≤ · ) ( N.divisors.erase 1 ) ; simp_all ( config := { decide := Bool.true } ); 538 | · replace n := congr_arg List.length n ; simp_all ( config := { decide := Bool.true } ); 539 | rw [ ← Nat.cons_self_properDivisors ] at n <;> aesop; 540 | · replace n := congr_arg List.toFinset n; rw [ Finset.ext_iff ] at n; specialize n c; aesop; 541 | · -- Since the divisors are distinct, b cannot be equal to c, so we must have b < c. 542 | have h_distinct : b ≠ c := by 543 | have := Finset.sort_nodup ( · ≤ · ) ( N.divisors.erase 1 ) ; aesop; 544 | exact lt_of_le_of_ne this.2 h_distinct; 545 | · replace n := congr_arg List.toFinset n; rw [ Finset.ext_iff ] at n; specialize n c; aesop; 546 | · have := n ▸ Finset.sort_nodup ( · ≤ · ) ( N.divisors.erase 1 ) ; aesop; 547 | exact lt_of_le_of_ne left_5 left_6; 548 | -- If $v_2(N) \ge 2$, then $d_2 = 4$. Since $3 \nmid N$, we have $3 \nmid d_3$. Then $s(N) = N(\frac{1}{2}+\frac{1}{4}+\frac{1}{d_3}) = N\frac{3d_3+4}{4d_3}$. Since $s(N)$ is an integer, and $v_3(N)=0, v_3(d_3)=0$, we must have $v_3(s(N)) = v_3(3d_3+4)$. As $d_3 \not\equiv 0 \pmod 3$, $3d_3+4 \equiv 1 \pmod 3$, so $v_3(3d_3+4)=0$. Thus, $v_3(s(N))=0$, so $s(N)$ is not divisible by 3, and therefore not by 6. 549 | by_cases h_v2 : d₂ = 4; 550 | · have h_s_formula : (s N : ℚ) = (N : ℚ) * (1 / 2 + 1 / 4 + 1 / d₃) := by 551 | have := lem_s_N_formula N h_card; aesop; 552 | -- Since $s(N)$ is an integer, and $v_3(N)=0, v_3(d_3)=0$, we must have $v_3(s(N)) = v_3(3d_3+4)$. As $d_3 \not\equiv 0 \pmod 3$, $3d_3+4 \equiv 1 \pmod 3$, so $v_3(3d_3+4)=0$. Thus, $v_3(s(N))=0$, so $s(N)$ is not divisible by 3, and therefore not by 6. 553 | have h_not_div_3 : ¬(3 ∣ s N) := by 554 | -- Since $s(N)$ is an integer, and $v_3(N)=0, v_3(d_3)=0$, we must have $v_3(s(N)) = v_3(3d_3+4)$. As $d_3 \not\equiv 0 \pmod 3$, $3d_3+4 \equiv 1 \pmod 3$, so $v_3(3d_3+4)=0$. Thus, $v_3(s(N))=0$, so $s(N)$ is not divisible by 3. 555 | have h_not_div_3 : ¬(3 ∣ (N * (3 * d₃ + 4))) := by 556 | norm_num [ Nat.dvd_iff_mod_eq_zero, Nat.add_mod, Nat.mul_mod ] at * ; aesop; 557 | contrapose! h_not_div_3; 558 | convert h_not_div_3.mul_right ( 4 * d₃ ) using 1; 559 | rw [ ← @Nat.cast_inj ℚ ] ; push_cast ; rw [ h_s_formula ] ; ring; 560 | simpa [ show d₃ ≠ 0 by linarith ] using by ring; 561 | exact fun h => h_not_div_3 ( dvd_trans ( by decide ) h ); 562 | · -- If $v_2(N) = 1$, then $d_2$ is an odd prime $p$. Since $3 \nmid N$, $p \ge 5$. The third smallest divisor $d_3$ is the minimum of $\{p^2, q, 2p\}$, where $q$ is the next smallest prime factor of $N$. 563 | by_cases h_odd_p : d₂ % 2 = 1; 564 | · -- If $d_3$ is odd, then $N/2$ is odd, while $N/d_2$ and $N/d_3$ are even. Their sum $s(N)$ is odd. An odd number is not divisible by 6. 565 | by_cases h_odd_d3 : d₃ % 2 = 1; 566 | · -- Since $N/2$ is odd and $N/d₂$ and $N/d₃$ are even, their sum $s(N)$ is odd. 567 | have h_odd_sN : Odd (s N) := by 568 | have h_odd_sN : Odd (N / 2 + N / d₂ + N / d₃) := by 569 | have h_odd_sN : Odd (N / 2) ∧ Even (N / d₂) ∧ Even (N / d₃) := by 570 | aesop; 571 | · -- Since the second smallest divisor is an odd prime, N cannot be divisible by 4, which implies that N/2 is odd. 572 | have h_not_div_4 : ¬(4 ∣ N) := by 573 | contrapose! h_v2; 574 | rcases x : Finset.sort ( fun x1 x2 => x1 ≤ x2 ) ( N.divisors.erase 1 ) with _ | ⟨ a, _ | ⟨ b, _ | ⟨ c, _ | k ⟩ ⟩ ⟩ <;> aesop; 575 | · replace x := congr_arg List.toFinset x; rw [ Finset.ext_iff ] at x; specialize x 4; aesop; 576 | · have y := @x ▸ Finset.sort_sorted ( · ≤ · ) ( N.divisors.erase 1 ) ; aesop; 577 | replace x := congr_arg List.toFinset x; rw [ Finset.ext_iff ] at x; specialize x 4; aesop; 578 | · interval_cases b <;> interval_cases c <;> trivial; 579 | · grind; 580 | exact Nat.odd_iff.mpr ( by obtain ⟨ k, hk ⟩ := even_iff_two_dvd.mp h_even; omega ); 581 | · rw [ Nat.even_iff ]; 582 | rw [ ← Nat.dvd_iff_mod_eq_zero ]; 583 | exact Nat.Coprime.dvd_of_dvd_mul_left ( show Nat.Coprime 2 ( ( Finset.sort ( fun x1 x2 => x1 ≤ x2 ) ( N.divisors.erase 1 ) )[1]?.getD 0 ) from Nat.prime_two.coprime_iff_not_dvd.mpr <| by omega ) <| Nat.dvd_trans ( even_iff_two_dvd.mp h_even ) <| by simpa [ Nat.mul_div_cancel' right_3 ] ; 584 | · rw [ even_iff_two_dvd ]; 585 | rw [ Nat.dvd_div_iff_mul_dvd ]; 586 | · exact Nat.Coprime.mul_dvd_of_dvd_of_dvd ( by rw [ ← Nat.mod_add_div ( ( Finset.sort ( fun x1 x2 => x1 ≤ x2 ) ( N.divisors.erase 1 ) )[2]?.getD 0 ) 2 ] ; aesop ) right_4 ( even_iff_two_dvd.mp h_even ); 587 | · aesop; 588 | simp_all ( config := { decide := Bool.true } ) [ parity_simps ]; 589 | convert h_odd_sN using 1; 590 | convert lem_s_N_smallest_divisors N h_card using 1; 591 | rw [ hd₁.1, hd₂.1, hd₃.1 ]; 592 | exact fun h => absurd ( h_odd_sN.of_dvd_nat h ) ( by decide ); 593 | · -- If $d_3$ is even, then $d_3 = 2p$. This is the smallest even divisor greater than 2. This case applies if $2p$ is smaller than any odd divisor of $N$ greater than $p$. Then $s(N) = N(\frac{1}{2}+\frac{1}{p}+\frac{1}{2p}) = N\frac{p+3}{2p}$. Since $p \ge 5$, $p$ is not divisible by 3. $p+3$ is divisible by 3 only if $p$ is, so $v_3(p+3)=0$. As $v_3(N)=0$ and $v_3(p)=0$, we have $v_3(s(N))=v_3(N)+v_3(p+3)-v_3(2p)=0$. So $3 \nmid s(N)$, which means $6 \nmid s(N)$. 594 | have h_even_d3 : d₃ = 2 * d₂ := by 595 | have h_even_d3 : d₃ ≤ 2 * d₂ := by 596 | have h_even_d3 : 2 * d₂ ∈ N.divisors.erase 1 := by 597 | aesop; 598 | exact Nat.Coprime.mul_dvd_of_dvd_of_dvd ( Nat.prime_two.coprime_iff_not_dvd.mpr <| by omega ) ( even_iff_two_dvd.mp h_even ) right_3; 599 | have h_even_d3 : 2 * d₂ ∈ Finset.sort (· ≤ ·) (N.divisors.erase 1) := by 600 | exact Finset.mem_sort ( α := ℕ ) ( · ≤ · ) |>.2 h_even_d3; 601 | rcases n : Finset.sort ( fun x1 x2 => x1 ≤ x2 ) ( N.divisors.erase 1 ) with _ | ⟨ a, _ | ⟨ b, _ | ⟨ c, _ | n ⟩ ⟩ ⟩ <;> aesop; 602 | · linarith; 603 | · linarith; 604 | · have := Finset.sort_sorted ( · ≤ · ) ( N.divisors.erase 1 ) ; aesop; 605 | · have := Finset.sort_sorted ( · ≤ · ) ( N.divisors.erase 1 ) ; aesop; 606 | have h_even_d3 : d₃ ≥ 2 * d₂ := by 607 | have h_even_d3 : d₃ % 2 = 0 := by 608 | exact Nat.mod_two_ne_one.mp h_odd_d3; 609 | have h_even_d3 : d₃ / 2 ≥ d₂ := by 610 | have h_even_d3 : d₃ / 2 ∈ N.divisors.erase 1 := by 611 | aesop; 612 | · grind; 613 | · exact Nat.dvd_trans ( Nat.div_dvd_of_dvd <| Nat.dvd_of_mod_eq_zero h_even_d3 ) right_4; 614 | have h_even_d3 : d₃ / 2 ∈ Finset.sort (· ≤ ·) (N.divisors.erase 1) := by 615 | exact Finset.mem_sort ( α := ℕ ) ( · ≤ · ) |>.2 h_even_d3; 616 | rcases n : Finset.sort ( fun x1 x2 => x1 ≤ x2 ) ( N.divisors.erase 1 ) with _ | ⟨ a, _ | ⟨ b, _ | ⟨ c, _ | n ⟩ ⟩ ⟩ <;> aesop; 617 | any_goals omega; 618 | · have := Nat.div_mul_cancel ( Nat.dvd_of_mod_eq_zero h_even_d3_2 ) ; aesop; 619 | interval_cases b ; trivial; 620 | · have := Nat.div_mul_cancel ( Nat.dvd_of_mod_eq_zero h_even_d3_2 ) ; aesop; 621 | interval_cases b ; trivial; 622 | · have := n ▸ Finset.sort_sorted ( · ≤ · ) ( N.divisors.erase 1 ) ; aesop; 623 | · have := Finset.sort_sorted ( · ≤ · ) ( N.divisors.erase 1 ) ; aesop; 624 | linarith [ Nat.mod_add_div d₃ 2 ]; 625 | linarith; 626 | have h_simplified : s N = (N : ℚ) * (1 / 2 + 1 / d₂ + 1 / (2 * d₂)) := by 627 | have := lem_s_N_formula N h_card; aesop; 628 | -- Since $p \ge 5$, $p$ is not divisible by 3. $p+3$ is divisible by 3 only if $p$ is, so $v_3(p+3)=0$. As $v_3(N)=0$ and $v_3(p)=0$, we have $v_3(s(N))=v_3(N)+v_3(p+3)-v_3(2p)=0$. So $3 \nmid s(N)$, which means $6 \nmid s(N)$. 629 | have h_not_div_3 : ¬(3 ∣ s N) := by 630 | have h_not_div_3 : ¬(3 ∣ (N * (d₂ + 3))) := by 631 | simp_all ( config := { decide := Bool.true } ) [ Nat.Prime.dvd_mul ]; 632 | exact fun h => h3 <| dvd_trans h hd₂.2.1.2; 633 | -- Since $3 \nmid N * (d₂ + 3)$ and $2 * d₂$ is not divisible by 3, the division by $2 * d₂$ doesn't introduce any factors of 3. Therefore, $s N$ can't be divisible by 3. 634 | have h_div : s N = (N * (d₂ + 3)) / (2 * d₂) := by 635 | rw [ Nat.div_eq_of_eq_mul_left ]; 636 | · linarith; 637 | · rw [ ← @Nat.cast_inj ℚ ] ; push_cast ; rw [ h_simplified ] ; ring; 638 | simpa [ show d₂ ≠ 0 by linarith ] using by ring; 639 | exact fun h => h_not_div_3 <| dvd_trans h <| h_div.symm ▸ Nat.div_dvd_of_dvd <| show 2 * d₂ ∣ N * ( d₂ + 3 ) from Nat.Coprime.mul_dvd_of_dvd_of_dvd ( show Nat.Coprime ( 2 ) ( d₂ ) from Nat.prime_two.coprime_iff_not_dvd.mpr <| by omega ) ( show 2 ∣ N * ( d₂ + 3 ) from dvd_mul_of_dvd_left ( even_iff_two_dvd.mp h_even ) _ ) ( show d₂ ∣ N * ( d₂ + 3 ) from dvd_mul_of_dvd_left ( Nat.dvd_of_mem_divisors <| Finset.mem_of_mem_erase hd₂.2.1 ) _ ); 640 | exact fun h => h_not_div_3 ( dvd_trans ( by decide ) h ); 641 | · contrapose! h_v2; 642 | aesop; 643 | rcases n : ( Finset.sort ( fun x1 x2 => x1 ≤ x2 ) ( N.divisors.erase 1 ) ) with _ | ⟨ a, _ | ⟨ b, l ⟩ ⟩ ; aesop; 644 | · aesop; 645 | · -- Since the second element is even and greater than 2, the smallest possible value is 4. 646 | have h_second : (Finset.sort (fun x1 x2 => x1 ≤ x2) (N.divisors.erase 1))[1]?.getD 0 = 4 := by 647 | have h_even : (Finset.sort (fun x1 x2 => x1 ≤ x2) (N.divisors.erase 1))[1]?.getD 0 % 2 = 0 := h_odd_p 648 | have h_gt_two : 2 < (Finset.sort (fun x1 x2 => x1 ≤ x2) (N.divisors.erase 1))[1]?.getD 0 := right_1 649 | aesop; 650 | have := Nat.dvd_of_mod_eq_zero h_odd_p; obtain ⟨ k, hk ⟩ := this; aesop; 651 | have := Finset.sort_sorted ( · ≤ · ) ( N.divisors.erase 1 ) ; aesop; 652 | replace n := congr_arg List.toFinset n; rw [ Finset.ext_iff ] at n; specialize n ( k ) ; aesop; 653 | rcases k with ( _ | _ | k ) <;> simp_all +arith +decide; 654 | exact n.mp ( dvd_of_mul_left_dvd right_3 ) |> Or.resolve_right <| fun h => by linarith [ left_1 _ h ] ; 655 | aesop 656 | 657 | /- 658 | If an integer $N$ is not divisible by 6, then $s(N)$ is not divisible by 6. 659 | -/ 660 | lemma lem_preservation_of_not_div_6 (N : ℕ) (h_card : 3 ≤ N.properDivisors.card) 661 | (h6 : ¬ (6 ∣ N)) : ¬ (6 ∣ s N) := by 662 | by_cases h_even : Even N; 663 | · -- Since $N$ is even and not divisible by 3, we can apply Lemma~\ref{lem:preservation_of_not_div_6_no_3_even}. 664 | have h_not_div_3 : ¬ (3 ∣ N) := by 665 | exact fun h => h6 ( Nat.lcm_dvd h_even.two_dvd h ); 666 | exact?; 667 | · replace := lem_preservation_of_not_div_6_odd N h_card; aesop; 668 | exact absurd ( this.of_dvd_nat a ) ( by decide ) 669 | 670 | /- 671 | If a sequence $(a_n)$ contains a term $a_k$ not divisible by 6, the sequence must terminate. 672 | -/ 673 | lemma lem_non_div_6_terminates (a : ℕ → ℕ) (h_pos : ∀ n, 0 < a n) 674 | (h_succ : ∀ n, a (n + 1) = s (a n)) (h_inf : ∀ n, 3 ≤ (a n).properDivisors.card) : 675 | ∀ k, 6 ∣ a k := by 676 | -- If $a_k$ is not divisible by 6, then $s(a_k) < a_k$ and $6 \nmid s(a_k)$. 677 | have h_not_div_6_implies_lt_and_not_div (k : ℕ) (h_not_div : ¬(6 ∣ a k)) : s (a k) < a k ∧ ¬(6 ∣ s (a k)) := by 678 | -- Apply the lemma that states if $a_k$ is not divisible by 6, then $s(a_k) < a_k$. 679 | have h_lt : s (a k) < a k := by 680 | -- Apply the lemma that states if $a_k$ is not divisible by 6, then $s(a_k) < a_k$ using the given hypotheses. 681 | apply lem_s_N_less_than_N_if_not_div_by_6; exact h_pos k; exact h_inf k; exact h_not_div; 682 | -- Apply the lemma that states if $N$ is not divisible by 6, then $s(N)$ is not divisible by 6. 683 | apply And.intro h_lt; 684 | exact?; 685 | -- Suppose a term $a_k$ is not divisible by 6. By Lemma~\ref{lem:s_N_less_than_N_if_not_div_by_6}, we have $s(a_k) < a_k$. For the sequence to continue, $a_{k+1}=s(a_k)$ must be defined, which requires $\tau(a_k) \ge 4$. If this condition is met, we have $a_{k+1} < a_k$. By Lemma~\ref{lem:preservation_of_not_div_6}, since $6 \nmid a_k$, it follows that $6 \nmid a_{k+1}$. This argument can be applied inductively: for all $m \ge k$, if $a_m$ is defined, then $6 \nmid a_m$, so $s(a_m) < a_m$. This implies $a_{m+1} < a_m$. Thus, the sequence $(a_m)_{m \ge k}$ is a strictly decreasing sequence of positive integers. 686 | have h_strict_decreasing_if_not_div_6 (k : ℕ) (h_not_div : ¬(6 ∣ a k)) : ∀ m ≥ k, a (m + 1) < a m := by 687 | -- By induction, if $a_k$ is not divisible by 6, then all $a_m$ for $m \geq k$ are also not divisible by 6. 688 | have h_not_div_6_for_all_m_ge_k (k : ℕ) (h_not_div : ¬(6 ∣ a k)) : ∀ m ≥ k, ¬(6 ∣ a m) := by 689 | intro m hm; 690 | induction hm <;> aesop; 691 | exact fun m hm => h_succ m ▸ h_not_div_6_implies_lt_and_not_div m ( h_not_div_6_for_all_m_ge_k k h_not_div m hm ) |>.1; 692 | -- Such a sequence must eventually either terminate because a term has fewer than three proper divisors, or reach the value 1. In either case, the sequence terminates. 693 | have h_finite_if_not_div_6 (k : ℕ) (h_not_div : ¬(6 ∣ a k)) : Set.Finite (Set.range (fun m => a (k + m))) := by 694 | exact Set.finite_iff_bddAbove.mpr ⟨ a k, by rintro x ⟨ m, rfl ⟩ ; exact Nat.recOn m ( by norm_num ) fun n ihn => by linarith! [ h_strict_decreasing_if_not_div_6 k h_not_div ( k + n ) ( by linarith ) ] ⟩; 695 | -- Assume there exists some $k$ such that $6 \nmid a_k$. Then the sequence starting at $k$ is strictly decreasing and finite, contradicting the assumption that the sequence is infinite. 696 | by_contra h_contra 697 | obtain ⟨k, hk⟩ : ∃ k, ¬(6 ∣ a k) := by 698 | exact not_forall.mp h_contra; 699 | exact absurd ( h_finite_if_not_div_6 k hk ) ( Set.infinite_range_of_injective ( StrictAnti.injective ( strictAnti_nat_of_succ_lt fun m => h_strict_decreasing_if_not_div_6 k hk _ ( Nat.le_add_right _ _ ) ) ) ) 700 | 701 | /- 702 | If $v_2(a_1)$ is an even integer, the sequence terminates. 703 | -/ 704 | lemma lem_v2_even_terminates (a : ℕ → ℕ) (h_pos : ∀ n, 0 < a n) 705 | (h_succ : ∀ n, a (n + 1) = s (a n)) (h_inf : ∀ n, 3 ≤ (a n).properDivisors.card) : 706 | Odd (padicValNat 2 (a 0)) := by 707 | -- By Lemma lem_non_div_6_terminates, all terms must be divisible by 6. 708 | have h_all_div_6 : ∀ n, 6 ∣ a n := by 709 | exact?; 710 | -- By Lemma lem_v2_decreasing, if $v_2(a_k)$ is even, then $v_2(a_{k+1})$ is also even and smaller. 711 | have h_v2_decreasing : ∀ n, padicValNat 2 (a n) ≥ 2 → Even (padicValNat 2 (a n)) → padicValNat 2 (a (n + 1)) = padicValNat 2 (a n) - 2 := by 712 | intros n hn_ge_2 hn_even; 713 | -- By Lemma lem_s_N_val_div_by_6_v2_ge_2, $s(a_n) = \frac{13}{12}a_n$. 714 | have h_s_val : 12 * s (a n) = 13 * a n := by 715 | exact?; 716 | rw [ h_succ, show s ( a n ) = a n * 13 / 12 by rw [ Nat.div_eq_of_eq_mul_left ] <;> linarith ]; 717 | rw [ padicValNat.div_of_dvd ]; 718 | · rw [ padicValNat.mul ] <;> norm_num; 719 | · rw [ show padicValNat 2 12 = 2 by native_decide, show padicValNat 2 13 = 0 by native_decide ] ; norm_num; 720 | · linarith [ h_pos n ]; 721 | · exact ⟨ s ( a n ), by linarith ⟩; 722 | -- By contradiction, assume $v_2(a_0)$ is even. 723 | by_contra h_even; 724 | -- Since $v_2(a_0)$ is even, by induction, $v_2(a_n)$ is also even and smaller for all $n$. 725 | have h_v2_even_all : ∀ n, Even (padicValNat 2 (a n)) := by 726 | -- By induction on $n$, we can show that $v_2(a_n)$ is even for all $n$. 727 | intro n 728 | induction' n with n ih; 729 | · simpa using h_even; 730 | · by_cases h₂ : padicValNat 2 (a n) ≥ 2; 731 | · rw [ h_v2_decreasing n h₂ ih ]; 732 | exact even_iff_two_dvd.mpr ( Nat.dvd_sub' ( even_iff_two_dvd.mp ih ) ( dvd_refl 2 ) ); 733 | · interval_cases _ : padicValNat 2 ( a n ) <;> simp_all ( config := { decide := Bool.true } ); 734 | exact absurd ( ‹a n = 0 ∨ a n % 2 = 1›.resolve_left ( ne_of_gt ( h_pos n ) ) ) ( by obtain ⟨ k, hk ⟩ := h_all_div_6 n; norm_num [ Nat.add_mod, Nat.mul_mod, hk ] ); 735 | -- Since $v_2(a_n)$ is even and smaller for all $n$, it must eventually become negative. 736 | have h_v2_neg : ∃ n, padicValNat 2 (a n) < 2 := by 737 | -- Since $v_2(a_n)$ is even and smaller for all $n$, it must eventually become negative. We can use induction to show this. 738 | have h_v2_decreasing_induction : ∀ n, padicValNat 2 (a n) ≥ 2 → padicValNat 2 (a (n + 1)) < padicValNat 2 (a n) := by 739 | exact fun n hn => h_v2_decreasing n hn ( h_v2_even_all n ) ▸ Nat.sub_lt ( by linarith ) ( by linarith ); 740 | by_cases h₂ : ∀ n, padicValNat 2 (a n) ≥ 2; 741 | · -- Since $v_2(a_n)$ is strictly decreasing and bounded below by 2, it must eventually reach 0. 742 | have h_v2_finite : Set.Finite (Set.range (fun n => padicValNat 2 (a n))) := by 743 | exact Set.finite_iff_bddAbove.mpr ⟨ padicValNat 2 ( a 0 ), by rintro x ⟨ n, rfl ⟩ ; exact Nat.recOn n ( by norm_num ) fun n ihn => by linarith [ h_v2_decreasing_induction n ( h₂ n ) ] ⟩; 744 | exact False.elim <| h_v2_finite.not_infinite <| Set.infinite_range_of_injective ( StrictAnti.injective <| strictAnti_nat_of_succ_lt fun n => h_v2_decreasing_induction n <| h₂ n ); 745 | · aesop; 746 | obtain ⟨ n, hn ⟩ := h_v2_neg; 747 | interval_cases _ : padicValNat 2 ( a n ) <;> simp_all ( config := { decide := Bool.true } ); 748 | · exact absurd ( ‹a n = 0 ∨ a n % 2 = 1›.resolve_left ( ne_of_gt ( h_pos n ) ) ) ( by obtain ⟨ k, hk ⟩ := h_all_div_6 n; norm_num [ Nat.add_mod, Nat.mul_mod, hk ] ); 749 | · exact absurd ( h_v2_even_all n ) ( by norm_num [ * ] ) 750 | 751 | /- 752 | For an infinite sequence, if $v_2(a_1) = 2k+1$ for some integer $k \ge 0$, it is necessary that $v_3(a_1) \ge k+1$. 753 | -/ 754 | lemma lem_v3_condition_for_v2_odd (a : ℕ → ℕ) (h_pos : ∀ n, 0 < a n) 755 | (h_succ : ∀ n, a (n + 1) = s (a n)) (h_inf : ∀ n, 3 ≤ (a n).properDivisors.card) (k : ℕ) 756 | (h_v2 : padicValNat 2 (a 0) = 2 * k + 1) : k + 1 ≤ padicValNat 3 (a 0) := by 757 | -- By Lemma~\ref{lem:all_terms_must_be_div_by_6_not_5}, all terms in the sequence are divisible by 6. 758 | have h_div_6 : ∀ n, 6 ∣ a n := by 759 | -- Apply the lemma that states if a sequence contains a term not divisible by 6, it must terminate. 760 | intros n 761 | apply lem_non_div_6_terminates a h_pos h_succ h_inf n; 762 | -- If $v_2(a_1) = 2k+1$, then by Lemma~\ref{lem:exponent_evolution}, $v_3(a_{k+1}) = v_3(a_1) - k$. 763 | have h_v3_k1 : padicValNat 3 (a (k)) = padicValNat 3 (a 0) - k := by 764 | have h_evolution : ∀ n ≤ k, padicValNat 2 (a n) = 2 * k + 1 - 2 * n ∧ padicValNat 3 (a n) = padicValNat 3 (a 0) - n := by 765 | -- We proceed by induction on $n$. 766 | intro n hn 767 | induction' n with n ih; 768 | · aesop; 769 | · -- By Lemma~\ref{lem:exponent_evolution}, $a_{n+1} = \frac{13}{12}a_n$. 770 | have h_an1 : a (n + 1) = (13 * a n) / 12 := by 771 | have h_an1 : 12 * s (a n) = 13 * a n := by 772 | apply lem_s_N_val_div_by_6_v2_ge_2; 773 | · exact h_inf n; 774 | · exact h_div_6 n; 775 | · exact ih ( Nat.le_of_succ_le hn ) |>.1 ▸ Nat.le_sub_of_add_le ( by linarith ); 776 | rw [ h_succ, ← h_an1, Nat.mul_div_cancel_left _ ( by decide ) ]; 777 | -- Using the properties of $p$-adic valuations, we can simplify the expressions for $v_2(a_{n+1})$ and $v_3(a_{n+1})$. 778 | have h_valuations : padicValNat 2 (13 * a n / 12) = padicValNat 2 (13 * a n) - padicValNat 2 12 ∧ padicValNat 3 (13 * a n / 12) = padicValNat 3 (13 * a n) - padicValNat 3 12 := by 779 | constructor <;> rw [ padicValNat.div_of_dvd ]; 780 | · have h_div_4 : 4 ∣ a n := by 781 | have h_div_4 : 2 ^ (2 * k + 1 - 2 * n) ∣ a n := by 782 | exact ih ( Nat.le_of_succ_le hn ) |>.1 ▸ Nat.ordProj_dvd _ _; 783 | exact dvd_trans ( pow_dvd_pow _ ( show 2 ≤ 2 * k + 1 - 2 * n from le_tsub_of_add_le_left ( by linarith ) ) ) h_div_4; 784 | exact dvd_mul_of_dvd_right ( Nat.lcm_dvd h_div_4 ( h_div_6 n ) ) _; 785 | · have h_div_4 : 4 ∣ a n := by 786 | have h_div_4 : 2 ^ (2 * k + 1 - 2 * n) ∣ a n := by 787 | exact ih ( Nat.le_of_succ_le hn ) |>.1 ▸ Nat.ordProj_dvd _ _; 788 | exact dvd_trans ( pow_dvd_pow _ ( show 2 ≤ 2 * k + 1 - 2 * n from le_tsub_of_add_le_left ( by linarith ) ) ) h_div_4; 789 | exact dvd_mul_of_dvd_right ( Nat.lcm_dvd h_div_4 ( h_div_6 n ) ) _; 790 | rw [ padicValNat.mul, padicValNat.mul ] at h_valuations <;> simp_all ( config := { decide := Bool.true } ); 791 | · norm_num [ show padicValNat 2 12 = 2 by native_decide, show padicValNat 3 12 = 1 by native_decide, show padicValNat 2 13 = 0 by native_decide, show padicValNat 3 13 = 0 by native_decide ] at * ; omega; 792 | · linarith [ h_pos n ]; 793 | · exact?; 794 | exact h_evolution k le_rfl |>.2; 795 | -- Since $a_k$ is divisible by 6, its 3-adic valuation must be at least 1. 796 | have h_v3_ak_ge_1 : 1 ≤ padicValNat 3 (a k) := by 797 | -- Since $a_k$ is divisible by 6, it is also divisible by 3. 798 | have h_div_3 : 3 ∣ a k := by 799 | exact dvd_trans ( by decide ) ( h_div_6 k ); 800 | rw [ padicValNat ] ; aesop; 801 | omega 802 | 803 | /- 804 | For the sequence $(a_n)$ to be infinite, $a_1$ must satisfy: for some integer $a \ge 0$, $v_2(a_1)=2a+1$, $v_3(a_1) \ge a+1$, and $v_5(a_1)=0$. 805 | -/ 806 | lemma lem_necessary_conditions_summary (a : ℕ → ℕ) (h_pos : ∀ n, 0 < a n) 807 | (h_succ : ∀ n, a (n + 1) = s (a n)) (h_inf : ∀ n, 3 ≤ (a n).properDivisors.card) : 808 | ∃ val_a, padicValNat 2 (a 0) = 2 * val_a + 1 ∧ 809 | val_a + 1 ≤ padicValNat 3 (a 0) ∧ padicValNat 5 (a 0) = 0 := by 810 | have h_v2_odd : Odd ( padicValNat 2 ( a 0 ) ) := by 811 | exact?; 812 | have h_v3_ge_v2_div_2_plus_1 : (padicValNat 3 (a 0)) ≥ (padicValNat 2 (a 0) + 1) / 2 := by 813 | cases h_v2_odd ; aesop; 814 | convert lem_v3_condition_for_v2_odd a h_pos h_succ h_inf w h using 1; 815 | norm_num [ Nat.add_div ]; 816 | have h_v5_zero : ¬(5 ∣ a 0) := by 817 | -- Suppose $5 \mid a_0$. Then $a_0$ is divisible by 6 and 5, so by 30. 818 | by_contra h_v5_div 819 | have h_div_30 : 30 ∣ a 0 := by 820 | have h_div_6 : 6 ∣ a 0 := by 821 | exact?; 822 | exact Nat.lcm_dvd h_v5_div h_div_6; 823 | -- Let $v_2(a_0) = 2k+1$ for some integer $k \ge 0$. 824 | obtain ⟨k, hk⟩ : ∃ k, padicValNat 2 (a 0) = 2 * k + 1 := by 825 | exact h_v2_odd; 826 | -- Then $a_1 = \frac{13}{12}a_0$ if $k \ge 1$, or $a_1 = \frac{31}{30}a_0$ if $k = 0$. 827 | have h_a1 : ∀ n ≤ k, a n = (13 / 12 : ℚ) ^ n * a 0 := by 828 | intro n hn; 829 | induction n <;> aesop; 830 | have h_a1_step : 12 * s (a n) = 13 * a n := by 831 | apply lem_s_N_val_div_by_6_v2_ge_2; 832 | · exact h_inf n; 833 | · exact?; 834 | · have := a_1 ( Nat.le_of_succ_le hn ); 835 | rw [ show a n = ( 13 ^ n * a 0 ) / 12 ^ n from ?_ ]; 836 | · rw [ padicValNat.div_of_dvd ]; 837 | · rw [ padicValNat.mul ] <;> norm_num; 838 | · rw [ show ( 12 ^ n : ℕ ) = 2 ^ ( 2 * n ) * 3 ^ n by rw [ pow_mul ] ; rw [ ← mul_pow ] ; norm_num, padicValNat.mul, padicValNat.pow, padicValNat.pow ] <;> norm_num; 839 | rw [ show padicValNat 2 ( 3 ^ n ) = 0 by exact padicValNat.eq_zero_of_not_dvd <| by norm_num [ Nat.Prime.dvd_iff_one_le_factorization ] ] ; omega; 840 | · linarith [ h_pos 0 ]; 841 | · field_simp at this; 842 | norm_cast at this; exact this ▸ dvd_mul_left _ _; 843 | · -- By multiplying both sides of the equation $(a n : ℚ) = (13 / 12) ^ n * (a 0 : ℚ)$ by $12^n$, we obtain $12^n * a n = 13^n * a 0$. 844 | have h_mul : 12^n * a n = 13^n * a 0 := by 845 | rw [ ← @Nat.cast_inj ℚ ] ; push_cast ; rw [ this ] ; ring; 846 | norm_num [ mul_assoc, div_pow ]; 847 | rw [ ← h_mul, Nat.mul_div_cancel_left _ ( pow_pos ( by decide ) _ ) ]; 848 | rw [ pow_succ' ] ; rw [ ← @Nat.cast_inj ℚ ] at *; push_cast at *; linarith [ a_1 <| Nat.le_of_succ_le hn ] ; 849 | -- Applying the lemma lem_s_N_val_div_by_6_v2_eq_1_yes_5 to aₖ, we get that s(aₖ) = (31/30)aₖ. 850 | have h_s_ak : s (a k) = (31 / 30 : ℚ) * a k := by 851 | have h_s_ak : padicValNat 2 (a k) = 1 ∧ 3 ∣ a k ∧ 5 ∣ a k := by 852 | bound; 853 | · have h_ak_div_30_not_4 : padicValNat 2 (a k) = padicValNat 2 (a 0) - 2 * k := by 854 | -- Using the properties of $p$-adic valuations, we can simplify the expression for $padicValNat 2 (a k)$. 855 | have h_padic_val : padicValNat 2 (a k) = padicValNat 2 ((13 ^ k * a 0) / 12 ^ k) := by 856 | rw [ Nat.div_eq_of_eq_mul_left ]; 857 | · positivity; 858 | · rw [ ← @Nat.cast_inj ℚ ] ; push_cast ; rw [ h_a1 k le_rfl ] ; ring; 859 | field_simp; 860 | rw [ h_padic_val, padicValNat.div_of_dvd ]; 861 | · rw [ padicValNat.mul ] <;> norm_num; 862 | · rw [ show ( 12 ^ k : ℕ ) = 2 ^ ( 2 * k ) * 3 ^ k by rw [ pow_mul ] ; rw [ ← mul_pow ] ; norm_num, padicValNat.mul, padicValNat.pow, padicValNat.pow ] <;> norm_num; 863 | rw [ show padicValNat 2 ( 3 ^ k ) = 0 by exact padicValNat.eq_zero_of_not_dvd <| by norm_num [ Nat.Prime.dvd_iff_one_le_factorization ] ] ; norm_num; 864 | norm_num [ padicValNat.eq_zero_of_not_dvd ]; 865 | · linarith [ h_pos 0 ]; 866 | · have h_div : 2 ^ (2 * k) ∣ a 0 := by 867 | -- Since $padicValNat 2 (a₀) = 2*k + 1$, we have $2^{2*k} \mid a₀$ by definition of $padicValNat$. 868 | have h_div : 2 ^ (padicValNat 2 (a 0)) ∣ a 0 := by 869 | exact Nat.ordProj_dvd _ _; 870 | exact dvd_trans ( pow_dvd_pow _ ( by linarith ) ) h_div; 871 | -- Since $2^{2k}$ divides $a0$ and $13^k$ is odd, $2^{2k}$ divides $13^k * a0$. Also, since $3^k$ divides $a0$ (because $30$ divides $a0$), $3^k$ divides $13^k * a0$. Therefore, $12^k = 2^{2k} * 3^k$ divides $13^k * a0$. 872 | have h_div_12k : 2 ^ (2 * k) ∣ 13 ^ k * a 0 ∧ 3 ^ k ∣ 13 ^ k * a 0 := by 873 | exact ⟨ dvd_mul_of_dvd_right h_div _, dvd_mul_of_dvd_right ( dvd_trans ( pow_dvd_pow _ <| show k ≤ padicValNat 3 ( a 0 ) from by omega ) <| Nat.ordProj_dvd _ _ ) _ ⟩; 874 | convert Nat.lcm_dvd h_div_12k.1 h_div_12k.2 using 1; 875 | norm_num [ pow_mul, Nat.lcm ]; 876 | norm_num [ ← mul_pow, Nat.gcd_comm ]; 877 | norm_num [ Nat.gcd_comm, Nat.Coprime, Nat.Coprime.pow ]; 878 | aesop; 879 | · specialize h_a1 k le_rfl; 880 | field_simp at h_a1; 881 | norm_cast at h_a1; 882 | replace h_a1 := congr_arg ( ·.factorization 3 ) h_a1 ; simp_all ( config := { decide := Bool.true } ) [ Nat.factorization_mul, ne_of_gt ( h_pos _ ) ]; 883 | rw [ show ( 12 : ℕ ) = 2 ^ 2 * 3 by norm_num, Nat.factorization_mul, Nat.factorization_pow ] at h_a1 <;> norm_num at *; 884 | simp_all ( config := { decide := Bool.true } ) [ Nat.factorization ]; 885 | exact Nat.dvd_of_mod_eq_zero ( Nat.mod_eq_zero_of_dvd <| by contrapose! h_a1; simp_all ( config := { decide := Bool.true } ) [ padicValNat.eq_zero_of_not_dvd ] ; omega ); 886 | · specialize h_a1 k le_rfl; 887 | -- Since $a_0$ is divisible by 5, we can write $a_0 = 5m$ for some integer $m$. 888 | obtain ⟨m, hm⟩ : ∃ m, a 0 = 5 * m := h_v5_div; 889 | field_simp at h_a1; 890 | norm_cast at h_a1; replace h_a1 := congr_arg ( · % 5 ) h_a1; norm_num [ Nat.add_mod, Nat.mul_mod, Nat.pow_mod, hm ] at h_a1; 891 | rw [ Nat.dvd_iff_mod_eq_zero ] ; rw [ ← Nat.mod_add_div k 4 ] at *; norm_num [ Nat.pow_add, Nat.pow_mul, Nat.mul_mod, Nat.pow_mod ] at *; have := Nat.mod_lt k four_pos; interval_cases k % 4 <;> simp_all ( config := { decide := Bool.true } ) ; 892 | · rw [ Nat.mul_mod ] at h_a1; have := Nat.mod_lt ( a ( 1 + 4 * ( k / 4 ) ) ) ( by decide : 5 > 0 ) ; interval_cases a ( 1 + 4 * ( k / 4 ) ) % 5 <;> trivial; 893 | · rw [ Nat.mul_mod ] at h_a1; have := Nat.mod_lt ( a ( 2 + 4 * ( k / 4 ) ) ) ( by decide : 5 > 0 ) ; interval_cases a ( 2 + 4 * ( k / 4 ) ) % 5 <;> trivial; 894 | · rw [ Nat.mul_mod ] at h_a1; have := Nat.mod_lt ( a ( 3 + 4 * ( k / 4 ) ) ) ( by decide : 5 > 0 ) ; interval_cases a ( 3 + 4 * ( k / 4 ) ) % 5 <;> trivial; 895 | have := lem_s_N_val_div_by_6_v2_eq_1_yes_5 ( a k ) ( h_inf k ) h_s_ak.1 h_s_ak.2.1 h_s_ak.2.2; 896 | rw [ div_mul_eq_mul_div, eq_div_iff ] <;> norm_cast ; linarith; 897 | -- This implies $v_2(a_{k+1}) = v_2(a_k) - 1 = 1 - 1 = 0$, so $a_{k+1}$ is not divisible by 2. 898 | have h_ak1_not_div_2 : ¬(2 ∣ a (k + 1)) := by 899 | have h_ak1_not_div_2 : padicValNat 2 (a (k + 1)) = 0 := by 900 | have h_ak1_not_div_2 : padicValNat 2 (a (k + 1)) = padicValNat 2 (31 * a k) - padicValNat 2 30 := by 901 | have h_ak1_not_div_2 : a (k + 1) * 30 = 31 * a k := by 902 | rw [ h_succ, ← @Nat.cast_inj ℚ ] ; push_cast ; linarith; 903 | rw [ ← h_ak1_not_div_2, padicValNat.mul ] <;> norm_num; 904 | linarith [ h_pos ( k + 1 ) ]; 905 | rw [ h_ak1_not_div_2, padicValNat.mul ] <;> norm_num; 906 | · rw [ show padicValNat 2 ( a k ) = padicValNat 2 ( a 0 ) - 2 * k by 907 | have h_ak1_not_div_2 : ∀ n ≤ k, padicValNat 2 (a n) = padicValNat 2 (a 0) - 2 * n := by 908 | intro n hn; 909 | have := h_a1 n hn; 910 | field_simp at this; 911 | norm_cast at this; 912 | have := congr_arg ( fun x => x.factorization 2 ) this ; norm_num [ Nat.factorization_mul, ne_of_gt ( h_pos _ ) ] at this; 913 | exact eq_tsub_of_add_eq ( by erw [ show ( Nat.factorization 12 ) 2 = 2 by native_decide ] at this; norm_num [ ← Nat.factorization_def ] at *; linarith ); 914 | exact h_ak1_not_div_2 k le_rfl ] ; simp +arith +decide [ hk ]; 915 | native_decide; 916 | · linarith [ h_pos k ]; 917 | -- If the 2-adic valuation of $a_{k+1}$ is zero, then $2$ does not divide $a_{k+1}$. 918 | simp [padicValNat] at h_ak1_not_div_2; 919 | exact?; 920 | -- This contradicts the assumption that the sequence is infinite, as $a_{k+1}$ would not be divisible by 6. 921 | have h_contradiction : ¬(6 ∣ a (k + 1)) := by 922 | exact fun h => h_ak1_not_div_2 ( dvd_trans ( by decide ) h ); 923 | exact h_contradiction ( lem_non_div_6_terminates a h_pos h_succ h_inf ( k + 1 ) ); 924 | cases h_v2_odd ; aesop; 925 | omega 926 | 927 | /- 928 | Let $\bigl(a_n\bigr)_{n\ge 1}$ be a sequence of positive integers such that each $a_n$ has at least three proper divisors, meaning $\tau(a_n) \ge 4$. For each $n\ge 1$, let $a_{n+1}$ be the sum of the three largest proper divisors of $a_n$. Such a sequence can be continued indefinitely if and only if $a_1$ is an integer of the form 929 | \[ 930 | a_1\;=\;6\cdot12^{\,a}\,m 931 | \] 932 | for some integer $a \ge 0$ and a positive integer $m$ with $\gcd(m,10)=1$. 933 | -/ 934 | theorem main_theorem : 935 | { a₁ | ∃ a : ℕ → ℕ, 936 | (∀ n, 0 < a n) ∧ 937 | (∀ n, 3 ≤ (a n).properDivisors.card) ∧ 938 | (∀ n, a (n+1) = 939 | ((a n).properDivisors.sort (· ≥ ·))[0]! + 940 | ((a n).properDivisors.sort (· ≥ ·))[1]! + 941 | ((a n).properDivisors.sort (· ≥ ·))[2]!) ∧ 942 | a₁ = a 0 943 | } = { n | ∃ a m, Nat.Coprime m 10 ∧ n = 6 * 12 ^ a * m } := by 944 | -- To prove equality of sets, we show each set is a subset of the other. 945 | apply Set.eq_of_subset_of_subset; 946 | · intro a₁ ha₁; 947 | -- Let's obtain the sequence $a$ and its properties from $ha₁$. 948 | obtain ⟨a, ha_pos, ha_card, ha_succ, rfl⟩ := ha₁; 949 | -- By Lemma~\ref{lem:necessary_conditions_summary}, $a_1$ must satisfy: for some integer $a \ge 0$, $v_2(a_1)=2a+1$, $v_3(a_1) \ge a+1$, and $v_5(a_1)=0$. 950 | obtain ⟨val_a, h2, h3, h5⟩ : ∃ val_a, padicValNat 2 (a 0) = 2 * val_a + 1 ∧ val_a + 1 ≤ padicValNat 3 (a 0) ∧ padicValNat 5 (a 0) = 0 := by 951 | apply lem_necessary_conditions_summary; 952 | · assumption; 953 | · unfold s; aesop; 954 | · assumption; 955 | have := lem_conditions_imply_form ( a 0 ) val_a ( ha_pos 0 ) h2 h3 h5; 956 | aesop; 957 | · -- By Lemma~\ref{lem:sufficiency_stabilization}, if $a_1$ is of the form $6 \cdot 12^a \cdot m$ with $m$ coprime to 10, then there exists a sequence $a_seq$ such that $a_seq 0 = a_1$ and each term is the sum of the three largest proper divisors of the previous term. 958 | intro n hn 959 | obtain ⟨a, m, hm_coprime, rfl⟩ := hn 960 | obtain ⟨a_seq, ha_seq⟩ := lem_sufficiency_stabilization a m (by 961 | exact Nat.pos_of_ne_zero ( by rintro rfl; norm_num at hm_coprime )) hm_coprime; 962 | unfold s at *; aesop; 963 | 964 | #print axioms main_theorem 965 | --------------------------------------------------------------------------------