Lean / Reader
Lean reader

OptimalSwitches.lean

88 lines7 declarationsno sorryimports Thresholds Mathlib.Algebra.BigOperators.Associated

Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports Thresholds, which it does not have: you can read it there, but it will not check. Build the project itself to check it.

  1. import Thresholds
  2. import Mathlib.Algebra.BigOperators.Associated
  3. namespace FactorialSwitches
  4. open Finset
  5. def marked (H : Finset ℕ) (u : ℕ → ℕ) : Finset ℕ := H.image (fun p => p * u p)
  6. /-- The large marker is uniquely recoverable from a marked factor. -/
  7. theorem marked_inj (H : Finset ℕ) (B : ℕ) (u : ℕ → ℕ)
  8. (pr : ∀ p ∈ H, p.Prime) (large : ∀ p ∈ H, B < p)
  9. (size : ∀ p ∈ H, 0 < u p ∧ u p ≤ B) :
  10. Set.InjOn (fun p => p * u p) (↑H : Set ℕ) := by
  11. intro p hp l hl eq
  12. change p * u p = l * u l at eq
  13. have dv : p ∣ l*u l := by rw [← eq]; exact Nat.dvd_mul_right p (u p)
  14. rcases (pr p hp).dvd_mul.mp dv with h|h
  15. · exact ((Nat.dvd_prime (pr l hl)).mp h).resolve_left (pr p hp).ne_one
  16. · have := Nat.le_of_dvd (size l hl).1 h
  17. have := (size l hl).2
  18. have := large p hp
  19. omega
  20. theorem marked_prod (H : Finset ℕ) (B : ℕ) (u : ℕ → ℕ)
  21. (pr : ∀ p ∈ H, p.Prime) (large : ∀ p ∈ H, B < p)
  22. (size : ∀ p ∈ H, 0 < u p ∧ u p ≤ B) :
  23. (∏ x ∈ marked H u, x) = (∏ p ∈ H, p) * ∏ p ∈ H, u p := by
  24. unfold marked
  25. rw [prod_image (marked_inj H B u pr large size),prod_mul_distrib]
  26. theorem marked_disjoint (H K : Finset ℕ) (u : ℕ → ℕ)
  27. (free : ∀ a ∈ K, ∀ p ∈ H, ¬p ∣ a) : Disjoint K (marked H u) := by
  28. refine Finset.disjoint_left.mpr ?_
  29. intro x hx mark
  30. obtain ⟨p,hp,rfl⟩ := Finset.mem_image.mp mark
  31. exact free _ hx p hp (Nat.dvd_mul_right _ _)
  32. /-- A reassignment preserving the product of the cofactors retains the
  33. entire omitted product, even with an arbitrary untouched background. -/
  34. theorem switch_product (H K : Finset ℕ) (B : ℕ) (u v : ℕ → ℕ)
  35. (pr : ∀ p ∈ H, p.Prime) (large : ∀ p ∈ H, B < p)
  36. (old : ∀ p ∈ H, 0 < u p ∧ u p ≤ B) (new : ∀ p ∈ H, 0 < v p ∧ v p ≤ B)
  37. (free : ∀ a ∈ K, ∀ p ∈ H, ¬p ∣ a)
  38. (cofactors : ∏ p ∈ H, u p = ∏ p ∈ H, v p) :
  39. (∏ x ∈ K ∪ marked H u, x) = ∏ x ∈ K ∪ marked H v, x := by
  40. rw [prod_union (marked_disjoint H K u free),prod_union (marked_disjoint H K v free),
  41. marked_prod H B u pr large old,marked_prod H B v pr large new,cofactors]
  42. /-- The selected factors after switching give the same target in the same interval. -/
  43. theorem switch_selected (A H K : Finset ℕ) (B target : ℕ) (u v : ℕ → ℕ)
  44. (pr : ∀ p ∈ H, p.Prime) (large : ∀ p ∈ H, B < p)
  45. (old : ∀ p ∈ H, 0 < u p ∧ u p ≤ B) (new : ∀ p ∈ H, 0 < v p ∧ v p ≤ B)
  46. (free : ∀ a ∈ K, ∀ p ∈ H, ¬p ∣ a)
  47. (cofactors : ∏ p ∈ H, u p = ∏ p ∈ H, v p)
  48. (within : K ∪ marked H v ⊆ A) (pos : ∀ a ∈ A, 0 < a)
  49. (target_eq : target * (∏ x ∈ K ∪ marked H u, x) = ∏ x ∈ A, x) :
  50. ∏ x ∈ A \ (K ∪ marked H v), x = target := by
  51. have same := switch_product H K B u v pr large old new free cofactors
  52. rw [same] at target_eq
  53. have mul := (Finset.prod_sdiff (f := id) within).trans target_eq.symm
  54. exact Nat.eq_of_mul_eq_mul_right (Finset.prod_pos (fun i hi => pos i (within hi))) mul
  55. /-- The reassigned labels themselves can be recovered uniquely from the new omitted set. -/
  56. theorem recover_label (H K : Finset ℕ) (B : ℕ) (u v : ℕ → ℕ)
  57. (pr : ∀ p ∈ H, p.Prime) (large : ∀ p ∈ H, B < p)
  58. (new : ∀ p ∈ H, 0 < v p ∧ v p ≤ B) (free : ∀ a ∈ K, ∀ p ∈ H, ¬p ∣ a)
  59. (sets : K ∪ marked H u = K ∪ marked H v) (p : ℕ) (hp : p ∈ H) : u p = v p := by
  60. have mem : p*u p ∈ K ∪ marked H u := Finset.mem_union.mpr (Or.inr (Finset.mem_image_of_mem _ hp))
  61. rw [sets] at mem
  62. rcases Finset.mem_union.mp mem with h|h
  63. · exact False.elim (free _ h p hp (Nat.dvd_mul_right _ _))
  64. obtain ⟨l,hl,e⟩ := Finset.mem_image.mp h
  65. have dv : p ∣ l*v l := by rw [e]; exact Nat.dvd_mul_right _ _
  66. rcases (pr p hp).dvd_mul.mp dv with h|h
  67. · have eq := ((Nat.dvd_prime (pr l hl)).mp h).resolve_left (pr p hp).ne_one
  68. subst l
  69. exact Nat.eq_of_mul_eq_mul_left (pr p hp).pos e.symm
  70. · have := Nat.le_of_dvd (new l hl).1 h
  71. have := (new l hl).2
  72. have := large p hp
  73. omega
  74. #print axioms switch_selected
  75. #print axioms recover_label
  76. #print axioms marked_inj
  77. #print axioms switch_product
  78. end FactorialSwitches