Compfiles/Usa2024P4.lean
Explanation legend Lean4 Domain Explanation Language (L4DEL)
L4DEL explanations are a separate layer. They do not change the Lean source. Intuition is explanatory prose; numbered items are a reading path; sources link the wording back to evidence.
- L4DEL
- Lean4 Domain Explanation Language
Credit: The upstream authors and contributors retain credit for the project and mathematics. lean4-explainer only renders their pinned source and adds the separately disclosed explanation layer.
Project sources: Pinned compfiles documentation, Pinned compfiles corpus index
20 declarations, 0 contain sorry, 0 declared as axioms
USA Mathematical Olympiad 2024, Problem 4
Let m and n be positive integers. A circular necklace contains mn beads, each either red or blue. It turned out that no matter how the necklace was cut into m blocks of n consecutive beads, each block had a distinct number of red beads. Determine, with proof, all possible values of the ordered pair (m, n).
Imports (5)
Imported by 1 file
- abbrev
Usa2024P4.NecklaceA circular necklace withm * nbeads, each red (true) or blue (false) line 32 sourceSource documentation
A circular necklace with
m * nbeads, each red (true) or blue (false). The beads are indexed by their position on the circle, i.e. byZMod (m * n).no axioms what this means
Statement uses:
NatProof uses:
ZMod,HMul.hMul,Bool2 instances, coercions and auxiliary constants left out.
abbrev Necklace (m n : ℕ) := ZMod (m * n) → Bool
- def
Usa2024P4.blockCountThe number of red beads in the block ofnconsecutive beads starting at positions + i * n(positions are taken modulom * n) line 36 sourceSource documentation
The number of red beads in the block of
nconsecutive beads starting at positions + i * n(positions are taken modulom * n).standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
Nat, Usa2024P4.Necklace,ZMod,HMul.hMulProof uses:
Finset.sum,Finset.range,ite,Eq,Bool,HAdd.hAdd,Bool.true,OfNat.ofNat19 instances, coercions and auxiliary constants left out.
def blockCount {m n : ℕ} (c : Necklace m n) (s : ZMod (m * n)) (i : ℕ) : ℕ := …Mentions: Usa2024P4.Necklace
- def
Usa2024P4.AllCutsDistinctDocumented declaration: AllCutsDistinct line 43 sourceSource documentation
The property from the problem statement: no matter how the necklace is cut into
mblocks ofnconsecutive beads (the cut is determined by the starting positionsof the first block), the numbers of red beads in themblocks are pairwise distinct.standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
Nat, Usa2024P4.NecklaceProof uses:
ZMod,HMul.hMul,Function.Injective,Fin, Usa2024P4.blockCount3 instances, coercions and auxiliary constants left out.
def AllCutsDistinct {m n : ℕ} (c : Necklace m n) : Prop := …Mentions: Usa2024P4.Necklace
- lemma
Usa2024P4.blockCount_leEach block containsnbeads, so its red bead count is at mostnline 49 sourceSource documentation
Each block contains
nbeads, so its red bead count is at mostn.standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
Nat, Usa2024P4.Necklace,ZMod,HMul.hMul,LE.le, Usa2024P4.blockCountProof uses:
id,Trans.trans,Eq,Finset.sum,Finset.range,ite,Bool,HAdd.hAdd,Bool.true,OfNat.ofNat,Finset.sum_le_sum,Membership.mem,Finset,Decidable,Not,Eq.mpr,congrFun',congrArg,ite_eq_right,of_eq_trueand 9 more42 instances, coercions and auxiliary constants left out.
Tactic trace: 7 steps
Open to load the checked before-and-after goal states.
lemma blockCount_le {m n : ℕ} (c : Necklace m n) (s : ZMod (m * n)) (i : ℕ) : blockCount c s i ≤ n := by …Mentions: Usa2024P4.Necklace, Usa2024P4.blockCount
- lemma
Usa2024P4.le_of_allCutsDistinctNecessity: themdistinct block counts all lie in{0, 1, ..., n}, which has onlyn + 1elements line 61 sourceSource documentation
Necessity: the
mdistinct block counts all lie in{0, 1, ..., n}, which has onlyn + 1elements.standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
Nat, Usa2024P4.Necklace, Usa2024P4.AllCutsDistinct,LE.le,HAdd.hAdd,OfNat.ofNatProof uses:
Function.Injective,Fin, Usa2024P4.blockCount,ZMod,HMul.hMul,Finset,Finset.image,Finset.univ,Finset.range,Membership.mem,And,Eq,Exists,Eq.mp,congrArg,propext,Finset.mem_image,Eq.mpr,LT.lt,idand 10 more28 instances, coercions and auxiliary constants left out.
Tactic trace: 10 steps
Open to load the checked before-and-after goal states.
lemma le_of_allCutsDistinct {m n : ℕ} {c : Necklace m n} (hc : AllCutsDistinct c) : m ≤ n + 1 := by …Mentions: Usa2024P4.Necklace, Usa2024P4.AllCutsDistinct
- def
Usa2024P4.rowRedDocumented declaration: rowRed line 79 sourceSource documentation
The red indicator of the unfolded construction: writing
p = q * n + jwithj < n(soqis the row andjthe column of beadp), the bead is red iffn + 1 - m ≤ j < n - q.no axioms what this means
Statement uses:
NatProof uses:
ite,And,LE.le,HSub.hSub,HAdd.hAdd,OfNat.ofNat,HMod.hMod,LT.lt,HDiv.hDiv14 instances, coercions and auxiliary constants left out.
def rowRed (m n : ℕ) (p : ℕ) : ℕ := …
- lemma
Usa2024P4.rowRed_eqEvaluatingrowRedon the beadt * n + ain rowt, columnaline 83 sourceSource documentation
Evaluating
rowRedon the beadt * n + ain rowt, columna.standard axioms: propext what this means
Statement uses:
Nat,LT.lt,OfNat.ofNat,Eq, Usa2024P4.rowRed,HAdd.hAdd,HMul.hMul,ite,And,LE.le,HSub.hSubProof uses:
id,HMod.hMod,Nat.mul_add_mod_of_lt,HDiv.hDiv,Eq.mpr,congrArg,Mathlib.Tactic.Ring.of_eq,HPow.hPow,Nat.rawCast,Mathlib.Tactic.Ring.Common.add_congr,Mathlib.Tactic.Ring.Common.mul_congr,Mathlib.Tactic.Ring.Common.atom_pf,rfl,Eq.symm,Eq.refl,Mathlib.Tactic.Ring.Common.add_mul,Mathlib.Tactic.Ring.Common.mul_add,Mathlib.Tactic.Ring.Common.mul_pf_left,Mathlib.Tactic.Ring.Common.mul_pf_right,Mathlib.Meta.NormNum.IsNat.to_raw_eqand 11 more43 instances, coercions and auxiliary constants left out.
Tactic trace: 6 steps
Open to load the checked before-and-after goal states.
lemma rowRed_eq {m n : ℕ} (hn : 0 < n) (t a : ℕ) (ha : a < n) : rowRed m n (t * n + a) = if n + 1 - m ≤ a ∧ a + t < n then 1 else 0 := by …Mentions: Usa2024P4.rowRed
- lemma
Usa2024P4.rowRed_selfEvaluatingrowRedon a bead in row0line 93 sourceSource documentation
Evaluating
rowRedon a bead in row0.standard axioms: propext what this means
Statement uses:
Nat,LT.lt,Eq, Usa2024P4.rowRed,ite,LE.le,HSub.hSub,HAdd.hAdd,OfNat.ofNatProof uses:
id,Eq.mpr,And,HMod.hMod,HDiv.hDiv,congrArg,Nat.mod_eq_of_lt,Nat.div_eq_of_lt,of_eq_true,Eq.trans,True,congrFun',ite_congr,eq_true,and_true,Eq.refl,Not,eq_self22 instances, coercions and auxiliary constants left out.
Tactic trace: 3 steps
Open to load the checked before-and-after goal states.
lemma rowRed_self {m n j : ℕ} (hj : j < n) : rowRed m n j = if n + 1 - m ≤ j then 1 else 0 := by …Mentions: Usa2024P4.rowRed
- def
Usa2024P4.constrThe necklace constructed for them ≤ n + 1direction: writingp = q * n + jwithj < n, beadpis red iffn + 1 - m ≤ j < n - qline 101 sourceSource documentation
The necklace constructed for the
m ≤ n + 1direction: writingp = q * n + jwithj < n, beadpis red iffn + 1 - m ≤ j < n - q.no axioms what this means
Statement uses:
Nat, Usa2024P4.NecklaceProof uses:
ZMod,HMul.hMul,Decidable.decide,And,LE.le,HSub.hSub,HAdd.hAdd,OfNat.ofNat,HMod.hMod,ZMod.val,LT.lt,HDiv.hDiv16 instances, coercions and auxiliary constants left out.
def constr (m n : ℕ) : Necklace m n := …
Mentions: Usa2024P4.Necklace
- lemma
Usa2024P4.blockCount_constr_eqDocumented declaration: blockCount_constr_eq line 107 sourceSource documentation
Bridging lemma: the block count of the constructed necklace can be computed with natural number arithmetic; the modulo
m * non the indices keeps track of the wrap-around of the circle.standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
Nat,Eq, Usa2024P4.blockCount, Usa2024P4.constr,ZMod,HMul.hMul,Finset.sum,Finset.range, Usa2024P4.rowRed,HMod.hMod,HAdd.hAddProof uses:
id,Finset.sum_congr,ite,Bool,Bool.true,OfNat.ofNat,rfl,Finset,Membership.mem,Eq.mpr,congrArg,congr,Eq.trans,Nat.cast_add,congrFun',Nat.cast_mul,Mathlib.Tactic.Ring.of_eq,HPow.hPow,Nat.rawCast,Mathlib.Tactic.Ring.Common.add_congrand 31 more60 instances, coercions and auxiliary constants left out.
Tactic trace: 7 steps
Open to load the checked before-and-after goal states.
lemma blockCount_constr_eq {m n : ℕ} (s' t : ℕ) : blockCount (constr m n) ((s' : ℕ) : ZMod (m * n)) t = ∑ j ∈ Finset.range n, rowRed m n ((s' + t * n + j) % (m * n)) := by …Mentions: Usa2024P4.blockCount, Usa2024P4.constr, Usa2024P4.rowRed
- lemma
Usa2024P4.sum_rowRedDocumented declaration: sum_rowRed line 120 sourceSource documentation
The key counting lemma: for a cut starting at
s' < n, the number of red beads in blockt(interpreted without wrap-around) ism - 1 - tifs' + t < nandm - 2 - totherwise.standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
Nat,LT.lt,OfNat.ofNat,LE.le,HAdd.hAdd,Eq,Finset.sum,Finset.range, Usa2024P4.rowRed,HMul.hMul,ite,HSub.hSubProof uses:
Finset.sum_range_add,Eq.mpr,id,congrArg,Eq.mp,Nat.sub_add_cancel,Nat.le_of_lt,Max.max,And,Finset.sum_congr,rfl,Finset,Membership.mem,Mathlib.Tactic.Ring.of_eq,HPow.hPow,Nat.rawCast,Mathlib.Tactic.Ring.Common.add_congr,Mathlib.Tactic.Ring.Common.atom_pf,Eq.symm,Eq.refland 35 more68 instances, coercions and auxiliary constants left out.
Tactic trace: 37 steps
Open to load the checked before-and-after goal states.
lemma sum_rowRed {m n : ℕ} (hn : 0 < n) (hmn : m ≤ n + 1) {s' t : ℕ} (hs : s' < n) : (∑ j ∈ Finset.range n, rowRed m n (s' + t * n + j)) = if s' + t < n then m - 1 - t else m - 2 - t := by …Mentions: Usa2024P4.rowRed
- lemma
Usa2024P4.sum_rowRed_lastDocumented declaration: sum_rowRed_last line 172 sourceSource documentation
The last block (which wraps around the end of the necklace) contains exactly
s' - (n + 1 - m)red beads: its firstn - s'beads lie in rowm - 1(which is entirely blue) and its lasts'beads lie in row0.standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
Nat,LT.lt,OfNat.ofNat,LE.le,HAdd.hAdd,Eq,Finset.sum,Finset.range, Usa2024P4.rowRed,HMod.hMod,HMul.hMul,HSub.hSubProof uses:
Exists,Exists.intro,Eq.mpr,id,congrArg,Nat.add_sub_cancel,Nat.succ,Nat.succ_mul,Eq.refl,Eq.symm,Finset.sum_range_add,Eq.mp,Nat.sub_add_cancel,Nat.le_of_lt,Finset.sum_eq_zero,Membership.mem,Finset,propext,Finset.mem_range,add_lt_add_leftand 42 more86 instances, coercions and auxiliary constants left out.
Tactic trace: 40 steps
Open to load the checked before-and-after goal states.
lemma sum_rowRed_last {m n : ℕ} (hm : 0 < m) (hn : 0 < n) (hmn : m ≤ n + 1) {s' : ℕ} (hs : s' < n) : (∑ j ∈ Finset.range n, rowRed m n ((s' + (m - 1) * n + j) % (m * n))) = s' - (n + 1 - m) := by …Mentions: Usa2024P4.rowRed
- lemma
Usa2024P4.blockCount_constrThe complete formula for the block counts of the constructed necklace when the cut starts ats' < nline 223 sourceSource documentation
The complete formula for the block counts of the constructed necklace when the cut starts at
s' < n.standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
Nat,LT.lt,OfNat.ofNat,LE.le,HAdd.hAdd,Eq, Usa2024P4.blockCount, Usa2024P4.constr,ZMod,HMul.hMul,ite,HSub.hSubProof uses:
Eq.mpr,Finset.sum,Finset.range, Usa2024P4.rowRed,HMod.hMod,id,congrArg, Usa2024P4.blockCount_constr_eq,dite,ite_eq_left,rfl, Usa2024P4.sum_rowRed_last,Eq.symm,Not,ite_eq_right,Membership.mem,Finset,mul_le_mul_of_nonneg_right,Nat.zero_le,Trans.transand 8 more56 instances, coercions and auxiliary constants left out.
Tactic trace: 24 steps
Open to load the checked before-and-after goal states.
lemma blockCount_constr {m n : ℕ} (hm : 0 < m) (hn : 0 < n) (hmn : m ≤ n + 1) {s' t : ℕ} (hs : s' < n) (ht : t < m) : blockCount (constr m n) ((s' : ℕ) : ZMod (m * n)) t = if t = m - 1 then s' - (n + 1 - m) else if s' + t < n then m - 1 - t else m - 2 - t := by …Mentions: Usa2024P4.blockCount, Usa2024P4.constr
- lemma
Usa2024P4.blockCount_add_periodThe block count is periodic in the block index with periodmline 252 sourceSource documentation
The block count is periodic in the block index with period
m.standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
Nat, Usa2024P4.Necklace,ZMod,HMul.hMul,Eq, Usa2024P4.blockCount,HAdd.hAddProof uses:
id,Finset.sum_congr,Finset.range,ite,Bool,Bool.true,OfNat.ofNat,rfl,Finset,Membership.mem,Mathlib.Tactic.Ring.of_eq,HPow.hPow,Nat.rawCast,Mathlib.Tactic.Ring.Common.add_congr,Mathlib.Tactic.Ring.Common.mul_congr,Mathlib.Tactic.Ring.Common.atom_pf,Eq.mpr,congrArg,Eq.symm,Eq.refland 16 more42 instances, coercions and auxiliary constants left out.
Tactic trace: 8 steps
Open to load the checked before-and-after goal states.
lemma blockCount_add_period {m n : ℕ} (c : Necklace m n) (s : ZMod (m * n)) (i : ℕ) : blockCount c s (i + m) = blockCount c s i := by …Mentions: Usa2024P4.Necklace, Usa2024P4.blockCount
- lemma
Usa2024P4.blockCount_add_mulIterated version ofblockCount_add_periodline 263 sourceSource documentation
Iterated version of
blockCount_add_period.standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
Nat, Usa2024P4.Necklace,ZMod,HMul.hMul,Eq, Usa2024P4.blockCount,HAdd.hAddProof uses:
Nat.recAux,of_eq_true,OfNat.ofNat,Eq.trans,True,congrFun',congrArg,MulZeroClass.mul_zero,add_zero,eq_self,Mathlib.Tactic.Ring.of_eq,HPow.hPow,Nat.rawCast,Mathlib.Tactic.Ring.Common.add_congr,Mathlib.Tactic.Ring.Common.atom_pf,rfl,Eq.mpr,id,Eq.symm,Eq.refland 17 more28 instances, coercions and auxiliary constants left out.
Tactic trace: 5 steps
Open to load the checked before-and-after goal states.
lemma blockCount_add_mul {m n : ℕ} (c : Necklace m n) (s : ZMod (m * n)) (i q : ℕ) : blockCount c s (i + m * q) = blockCount c s i := by …Mentions: Usa2024P4.Necklace, Usa2024P4.blockCount
- lemma
Usa2024P4.blockCount_modThe block count only depends on the block index modulomline 272 sourceSource documentation
The block count only depends on the block index modulo
m.standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
Nat, Usa2024P4.Necklace,ZMod,HMul.hMul,Eq, Usa2024P4.blockCount,HMod.hModProof uses:
Eq.mpr,HAdd.hAdd,HDiv.hDiv,id,Eq.rec,Eq.refl,Eq.trans,congrArg,Eq.symm,Nat.mod_add_div, Usa2024P4.blockCount_add_mul12 instances, coercions and auxiliary constants left out.
Tactic trace: 2 steps
Open to load the checked before-and-after goal states.
lemma blockCount_mod {m n : ℕ} (c : Necklace m n) (s : ZMod (m * n)) (x : ℕ) : blockCount c s x = blockCount c s (x % m) := by …Mentions: Usa2024P4.Necklace, Usa2024P4.blockCount
- lemma
Usa2024P4.blockCount_shiftShifting the starting position of the cut bynbeads shifts the blocks by one line 279 sourceSource documentation
Shifting the starting position of the cut by
nbeads shifts the blocks by one. This reduces a general cutsto a cut starting ats.val % n < n.standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
Nat,NeZero,HMul.hMul, Usa2024P4.Necklace,ZMod,Eq, Usa2024P4.blockCount,HMod.hMod,ZMod.val,HAdd.hAdd,HDiv.hDivProof uses:
id,Finset.sum_congr,Finset.range,ite,Bool,Bool.true,OfNat.ofNat,rfl,Finset,Membership.mem,Eq.mpr,Eq.rec,Eq.refl,Eq.trans,congrArg,Eq.symm,ZMod.natCast_zmod_val,Nat.cast_add,NatCast,Nat.mod_add_divand 18 more55 instances, coercions and auxiliary constants left out.
Tactic trace: 10 steps
Open to load the checked before-and-after goal states.
lemma blockCount_shift {m n : ℕ} [NeZero (m * n)] (c : Necklace m n) (s : ZMod (m * n)) (i : ℕ) : blockCount c s i = blockCount c ((s.val % n : ℕ) : ZMod (m * n)) (s.val / n + i) := by …Mentions: Usa2024P4.Necklace, Usa2024P4.blockCount
- lemma
Usa2024P4.allCutsDistinct_constrThe constructed necklace satisfies the property of the problem line 296 sourceSource documentation
The constructed necklace satisfies the property of the problem.
standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
Nat,LT.lt,OfNat.ofNat,LE.le,HAdd.hAdd, Usa2024P4.AllCutsDistinct, Usa2024P4.constrProof uses:
NeZero,HMul.hMul,NeZero.mk,LT.lt.ne',Nat.mul_pos,ZMod,Fin,Eq, Usa2024P4.blockCount,HMod.hMod,ZMod.val,Nat.mod_lt,HDiv.hDiv,dite,HSub.hSub,Decidable.byContradiction,Not,Eq.mp,ite,congrArgand 16 more47 instances, coercions and auxiliary constants left out.
Tactic trace: 18 steps
Open to load the checked before-and-after goal states.
lemma allCutsDistinct_constr {m n : ℕ} (hm : 0 < m) (hn : 0 < n) (hmn : m ≤ n + 1) : AllCutsDistinct (constr m n) := by …Mentions: Usa2024P4.AllCutsDistinct, Usa2024P4.constr
- determine
Usa2024P4.solutionThe answer: the required necklaces exist exactly for the pairs(m, n)withm ≤ n + 1line 325 sourceSource documentation
The answer: the required necklaces exist exactly for the pairs
(m, n)withm ≤ n + 1.no axioms what this means
Statement uses:
NatProof uses:
LE.le,HAdd.hAdd,OfNat.ofNat4 instances, coercions and auxiliary constants left out.
determine solution : ℕ → ℕ → Prop := fun m n ↦ m ≤ n + 1
- problem
Usa2024P4.usa2024_p4line 327 sourcestandard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
Nat,LT.lt,OfNat.ofNat,Iff,Exists, Usa2024P4.Necklace, Usa2024P4.AllCutsDistinct, Usa2024P4.solutionProof uses:
Iff.intro, Usa2024P4.le_of_allCutsDistinct,Exists.intro, Usa2024P4.constr, Usa2024P4.allCutsDistinct_constr5 instances, coercions and auxiliary constants left out.
Tactic trace: 7 steps
Open to load the checked before-and-after goal states.