IMO26 / problem1 /problem1_formalization.lean
RowanXu06's picture
Upload problem1_formalization.lean
fd7a44d verified
Raw
History Blame Contribute Delete
4.42 kB
import Mathlib
/-!
# Problem 1: Blackboard gcd/lcm process
Lean 4 + Mathlib formalization scaffold.
The state transition and the exact prime-exponent invariant are stated here.
The two substantial proofs still marked `sorry` are:
1. construction of the lexicographic termination measure from `Nat.factorization`;
2. preservation of the gcd of every prime-exponent vector along `Step`.
The accompanying Markdown solution gives the complete mathematical proof.
-/
set_option autoImplicit false
namespace Problem1
abbrev Blackboard := Multiset β„•
/-- One legal blackboard move. -/
inductive Step : Blackboard β†’ Blackboard β†’ Prop
| move (rest : Blackboard) (m n : β„•)
(hm : 1 < m) (hn : 1 < n) :
Step
(m ::β‚˜ n ::β‚˜ rest)
(Nat.gcd m n ::β‚˜ (Nat.lcm m n / Nat.gcd m n) ::β‚˜ rest)
/-- Number of entries that are strictly greater than `1`. -/
def nontrivialCount (s : Blackboard) : β„• :=
(s.filter fun x => 1 < x).card
/-- A state is terminal exactly when no pair of nontrivial entries remains. -/
def Terminal (s : Blackboard) : Prop :=
nontrivialCount s ≀ 1
/-- Initial blackboard represented as a multiset. -/
def initialState (A : Fin 2026 β†’ β„•) : Blackboard :=
Multiset.ofList (List.ofFn A)
/-- The exponent of `p` in the prime factorisation of `n`. -/
noncomputable def vp (p n : β„•) : β„• :=
(Nat.factorization n) p
/-- Gcd of all exponents in a blackboard state. -/
noncomputable def exponentGCD (p : β„•) (s : Blackboard) : β„• :=
s.toFinset.gcd (fun n => vp p n)
/-- Gcd of all initial `p`-adic exponents. -/
noncomputable def initialExponentGCD
(A : Fin 2026 β†’ β„•) (p : β„•) : β„• :=
Finset.univ.gcd (fun i => vp p (A i))
/-- Reachability by finitely many legal moves. -/
abbrev Reachable := Relation.ReflTransGen Step
/--
The forward transition relation is well founded after reversing its arguments.
The proof uses the lexicographic measure
`(sum of Ξ© over all entries, number of entries > 1)`.
-/
theorem step_wellFounded :
WellFounded (fun next current : Blackboard => Step current next) := by
sorry
/-- Every legal play starting from the initial board terminates. -/
theorem every_play_terminates
(A : Fin 2026 β†’ β„•)
(hA : βˆ€ i, 1 < A i) :
βˆƒ s, Reachable (initialState A) s ∧ Terminal s := by
sorry
/-- At least one nontrivial entry survives every reachable state. -/
theorem at_least_one_nontrivial_survives
(A : Fin 2026 β†’ β„•)
(hA : βˆ€ i, 1 < A i)
{s : Blackboard}
(hs : Reachable (initialState A) s) :
1 ≀ nontrivialCount s := by
sorry
/-- A terminal reachable state has exactly one entry greater than `1`. -/
theorem terminal_has_exactly_one
(A : Fin 2026 β†’ β„•)
(hA : βˆ€ i, 1 < A i)
{s : Blackboard}
(hs : Reachable (initialState A) s)
(ht : Terminal s) :
nontrivialCount s = 1 := by
have hlo := at_least_one_nontrivial_survives A hA hs
exact Nat.le_antisymm ht hlo
/--
For every prime `p`, the gcd of the complete vector of `p`-adic exponents is
preserved by one move. On the selected coordinates this is the identity
`gcd (min a b) (max a b - min a b) = gcd a b`.
-/
theorem exponent_gcd_invariant_one_step
{s t : Blackboard}
(hst : Step s t)
(p : β„•) (hp : Nat.Prime p) :
exponentGCD p s = exponentGCD p t := by
sorry
/-- The exponent of every prime in the terminal value is uniquely fixed. -/
theorem terminal_value_exponents
(A : Fin 2026 β†’ β„•)
(hA : βˆ€ i, 1 < A i)
{s : Blackboard} {M : β„•}
(hs : Reachable (initialState A) s)
(hterminal : Terminal s)
(hM : M ∈ s)
(hMgt : 1 < M)
(hunique : βˆ€ x ∈ s, 1 < x β†’ x = M) :
βˆ€ p, Nat.Prime p β†’ vp p M = initialExponentGCD A p := by
sorry
/--
Mathematical closed form:
`M = ∏ p, p ^ gcd_i(v_p(A i))`, with the product restricted to primes
appearing in the initial data.
-/
theorem terminal_value_independent_of_choices
(A : Fin 2026 β†’ β„•)
(hA : βˆ€ i, 1 < A i)
{s₁ sβ‚‚ : Blackboard} {M₁ Mβ‚‚ : β„•}
(hs₁ : Reachable (initialState A) s₁)
(hsβ‚‚ : Reachable (initialState A) sβ‚‚)
(ht₁ : Terminal s₁) (htβ‚‚ : Terminal sβ‚‚)
(hM₁ : M₁ ∈ s₁) (hMβ‚‚ : Mβ‚‚ ∈ sβ‚‚)
(hM₁gt : 1 < M₁) (hMβ‚‚gt : 1 < Mβ‚‚)
(hu₁ : βˆ€ x ∈ s₁, 1 < x β†’ x = M₁)
(huβ‚‚ : βˆ€ x ∈ sβ‚‚, 1 < x β†’ x = Mβ‚‚) :
M₁ = Mβ‚‚ := by
sorry
end Problem1