Compfiles/Usa1994P2.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 1994, Problem 2
The sequence a₁, a₂, ... , a₉₉ has a₁ = a₃ = a₅ = ... = a₉₇ = 1, a₂ = a₄ = a₆ = ... = a₉₈ = 2, and a₉₉ = 3. We interpret subscripts greater than 99 by subtracting 99, so that a₁₀₀ means a₁ etc. An allowed move is to change the value of any one of the aₙ to another member of {1, 2, 3} different from its two neighbors, aₙ₋₁ and aₙ₊₁. Is there a sequence of allowed moves which results in aₘ = aₘ₊₂ = ... = aₘ₊₉₆ = 1, aₘ₊₁ = aₘ₊₃ = ... = aₘ₊₉₅ = 2, aₘ₊₉₇ = 3, aₘ₊₉₈ = 2 for some m? [So if m = 1, we have just interchanged the values of a₉₈ and a₉₉.]
The answer is "no": the cyclic-weight sum below is an invariant of allowed moves, it equals 3 for the initial configuration and -3 for every target configuration.
Imported by 1 file
- abbrev
Usa1994P2.ValThe three values that may appear in the sequence line 39 sourceSource documentation
The three values that may appear in the sequence. We identify the values 1, 2, 3 of the problem statement with 0, 1, 2 in
ZMod 3; the cyclic successor mapx ↦ x + 1then sends 1 → 2 → 3 → 1.no axioms what this means
Proof uses:
ZMod,OfNat.ofNat,Nat1 instances, coercions and auxiliary constants left out.
abbrev Val := ZMod 3
- abbrev
Usa1994P2.ConfigA configuration of the sequence, indexed byZMod 99(indices are interpreted modulo 99, as in the problem statement) line 44 sourceSource documentation
A configuration of the sequence, indexed by
ZMod 99(indices are interpreted modulo 99, as in the problem statement). Indexicorresponds to the problem's aᵢ₊₁.no axioms what this means
Proof uses:
ZMod,OfNat.ofNat,Nat, Usa1994P2.Val1 instances, coercions and auxiliary constants left out.
abbrev Config := ZMod 99 → Val
Mentions: Usa1994P2.Val
- def
Usa1994P2.initialThe initial configuration: 1, 2, 1, 2, ..., 1, 2, 3 line 47 sourceSource documentation
The initial configuration: 1, 2, 1, 2, ..., 1, 2, 3.
standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses: Usa1994P2.Config
Proof uses:
ZMod,OfNat.ofNat,Nat,ite, Usa1994P2.Val,Eq,ZMod.val,HMod.hMod21 instances, coercions and auxiliary constants left out.
def initial : Config := fun i ↦ …
Mentions: Usa1994P2.Config
- def
Usa1994P2.targetPatDocumented declaration: targetPat line 54 sourceSource documentation
The alternating pattern underlying the target configurations:
targetPat kis the value at offsetk(with0 ≤ k ≤ 98) from the base index, namely 1 at even offsets≤ 96, 2 at odd offsets≤ 95, 3 at offset 97 and 2 at offset 98.standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
Nat, Usa1994P2.ValProof uses:
ite,Eq,OfNat.ofNat,HMod.hMod21 instances, coercions and auxiliary constants left out.
def targetPat (k : ℕ) : Val := …
Mentions: Usa1994P2.Val
- def
Usa1994P2.targetDocumented declaration: target line 60 sourceSource documentation
The target configuration with base index
m: the value at indexidepends only on the offseti - m, exactly as in the problem statement where indexm + kcarries thek-th value of the pattern.standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
ZMod,OfNat.ofNat,Nat, Usa1994P2.ConfigProof uses: Usa1994P2.targetPat,
ZMod.val,HSub.hSub9 instances, coercions and auxiliary constants left out.
def target (m : ZMod 99) : Config := fun i ↦ targetPat (i - m).val
Mentions: Usa1994P2.Config, Usa1994P2.targetPat
- def
Usa1994P2.MoveAn allowed move: change the value at some indexnto another valuevthat differs from both neighbors line 64 sourceSource documentation
An allowed move: change the value at some index
nto another valuevthat differs from both neighbors.standard axioms: Quot.sound, propext what this means
Statement uses: Usa1994P2.Config
Proof uses:
Exists,ZMod,OfNat.ofNat,Nat, Usa1994P2.Val,And,Ne,HSub.hSub,HAdd.hAdd,Eq,Function.update17 instances, coercions and auxiliary constants left out.
def Move (a b : Config) : Prop := …
Mentions: Usa1994P2.Config
- def
Usa1994P2.pairWeightDocumented declaration: pairWeight line 72 sourceSource documentation
The weight of a pair of consecutive values:
0if they are equal,+1if the second is the cyclic successor of the first (i.e. the pairs (1,2), (2,3), (3,1) of the problem statement), and-1otherwise.standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses: Usa1994P2.Val,
IntProof uses:
ite,Eq,OfNat.ofNat,Nat,HAdd.hAdd,Neg.neg18 instances, coercions and auxiliary constants left out.
def pairWeight (x y : Val) : ℤ := …
Mentions: Usa1994P2.Val
- def
Usa1994P2.totalWeightThe invariant: the total weight around the cycle line 76 sourceSource documentation
The invariant: the total weight around the cycle.
standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses: Usa1994P2.Config,
IntProof uses:
Finset.sum,ZMod,OfNat.ofNat,Nat,Finset.univ, Usa1994P2.pairWeight,HAdd.hAdd15 instances, coercions and auxiliary constants left out.
def totalWeight (a : Config) : ℤ := ∑ i : ZMod 99, pairWeight (a i) (a (i + 1))
Mentions: Usa1994P2.Config, Usa1994P2.pairWeight
- theorem
Usa1994P2.pairWeight_localA case analysis onZMod 3: the key local identity behind the invariance oftotalWeightline 83 sourceSource documentation
A case analysis on
ZMod 3: the key local identity behind the invariance oftotalWeight. Ifxdiffers from bothLandRandvdiffers from all ofx,LandR, then the two pairs throughxand throughvhave the same total weight. (This forcesL = R, and each side of the identity vanishes.)standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses: Usa1994P2.Val,
And,Ne,Eq,Int,HAdd.hAdd,HSub.hSub, Usa1994P2.pairWeight,OfNat.ofNatProof uses:
of_decide_eq_true,Nat,id,Bool,Decidable.decide,Bool.true,Eq.refl19 instances, coercions and auxiliary constants left out.
Tactic trace: 1 steps
Open to load the checked before-and-after goal states.
theorem pairWeight_local : ∀ L R x v : Val, (x ≠ L ∧ x ≠ R ∧ v ≠ x ∧ v ≠ L ∧ v ≠ R) → pairWeight L v - pairWeight L x + (pairWeight v R - pairWeight x R) = 0 := by …Mentions: Usa1994P2.Val, Usa1994P2.pairWeight
- theorem
Usa1994P2.succ_ne_selfInZMod 99, an index and its successor are distinct line 89 sourceSource documentation
In
ZMod 99, an index and its successor are distinct.standard axioms: Quot.sound, propext what this means
Statement uses:
ZMod,OfNat.ofNat,Nat,Ne,HAdd.hAddProof uses:
Eq,of_decide_eq_true,id,Bool,Decidable.decide,Bool.true,Eq.refl,HSub.hSub,congrArg,Eq.mp,sub_self,add_sub_cancel_left40 instances, coercions and auxiliary constants left out.
Tactic trace: 6 steps
Open to load the checked before-and-after goal states.
theorem succ_ne_self (n : ZMod 99) : n + 1 ≠ n := by …
- theorem
Usa1994P2.pred_ne_selfInZMod 99, an index and its predecessor are distinct line 97 sourceSource documentation
In
ZMod 99, an index and its predecessor are distinct.standard axioms: Quot.sound, propext what this means
Statement uses:
ZMod,OfNat.ofNat,Nat,Ne,HSub.hSubProof uses:
Eq,of_decide_eq_true,id,Bool,Decidable.decide,Bool.true,Eq.refl,congrArg,Iff.mp,Neg.neg,neg_eq_zero,Eq.mp,sub_self,sub_sub_cancel_left41 instances, coercions and auxiliary constants left out.
Tactic trace: 6 steps
Open to load the checked before-and-after goal states.
theorem pred_ne_self (n : ZMod 99) : n - 1 ≠ n := by …
- theorem
Usa1994P2.move_preserves_distinctA move preserves the property that every two consecutive values are distinct line 106 sourceSource documentation
A move preserves the property that every two consecutive values are distinct.
standard axioms: Quot.sound, propext what this means
Statement uses: Usa1994P2.Config, Usa1994P2.Move,
ZMod,OfNat.ofNat,Nat,Ne, Usa1994P2.Val,HAdd.hAddProof uses:
Exists,And,HSub.hSub,Eq,Function.update,dite,Eq.mpr,id,congrArg,Function.update_self,Function.update_of_ne, Usa1994P2.succ_ne_self,Not,eq_sub_of_add_eq,Ne.symm,Eq.symm32 instances, coercions and auxiliary constants left out.
Tactic trace: 16 steps
Open to load the checked before-and-after goal states.
theorem move_preserves_distinct {a b : Config} (hm : Move a b) (h : ∀ i, a i ≠ a (i + 1)) : ∀ i, b i ≠ b (i + 1) := by …Mentions: Usa1994P2.Config, Usa1994P2.Move, h
- theorem
Usa1994P2.totalWeight_moveThe total weight is invariant under allowed moves, provided the configuration has distinct consecutive values line 123 sourceSource documentation
The total weight is invariant under allowed moves, provided the configuration has distinct consecutive values.
standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses: Usa1994P2.Config, Usa1994P2.Move,
ZMod,OfNat.ofNat,Nat,Ne, Usa1994P2.Val,HAdd.hAdd,Eq,Int, Usa1994P2.totalWeightProof uses:
Exists,And,HSub.hSub,Function.update, Usa1994P2.pred_ne_self,Not,Membership.mem,Finset,Insert.insert,Singleton.singleton, Usa1994P2.pairWeight,And.left,Eq.mp,Eq.trans,Or,congrArg,eq_sub_of_add_eq,Eq.mpr,id,Function.update_of_neand 18 more61 instances, coercions and auxiliary constants left out.
Tactic trace: 18 steps
Open to load the checked before-and-after goal states.
theorem totalWeight_move {a b : Config} (hm : Move a b) (h : ∀ i, a i ≠ a (i + 1)) : totalWeight a = totalWeight b := by …Mentions: Usa1994P2.Config, Usa1994P2.Move, h, Usa1994P2.totalWeight
- theorem
Usa1994P2.initial_distinctIn the initial configuration, consecutive values are distinct line 153 sourceSource documentation
In the initial configuration, consecutive values are distinct.
standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
ZMod,OfNat.ofNat,Nat,Ne, Usa1994P2.Val, Usa1994P2.initial,HAdd.hAddProof uses:
of_decide_eq_true,Eq,id,Bool,Decidable.decide,Bool.true,Eq.refl29 instances, coercions and auxiliary constants left out.
Tactic trace: 1 steps
Open to load the checked before-and-after goal states.
theorem initial_distinct : ∀ i : ZMod 99, initial i ≠ initial (i + 1) := by …
Mentions: Usa1994P2.initial
- theorem
Usa1994P2.totalWeight_initialThe total weight of the initial configuration is3line 158 sourceSource documentation
The total weight of the initial configuration is
3.standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
Eq,Int, Usa1994P2.totalWeight, Usa1994P2.initial,OfNat.ofNatProof uses:
of_decide_eq_true,id,Bool,Decidable.decide,Bool.true,Eq.refl3 instances, coercions and auxiliary constants left out.
Tactic trace: 1 steps
Open to load the checked before-and-after goal states.
theorem totalWeight_initial : totalWeight initial = 3 := by …
Mentions: Usa1994P2.totalWeight, Usa1994P2.initial
- theorem
Usa1994P2.totalWeight_target_zeroThe total weight of the target configuration with base0is-3line 163 sourceSource documentation
The total weight of the target configuration with base
0is-3.standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
Eq,Int, Usa1994P2.totalWeight, Usa1994P2.target,OfNat.ofNat,ZMod,Nat,Neg.negProof uses:
of_decide_eq_true,id,Bool,Decidable.decide,Bool.true,Eq.refl19 instances, coercions and auxiliary constants left out.
Tactic trace: 1 steps
Open to load the checked before-and-after goal states.
theorem totalWeight_target_zero : totalWeight (target 0) = -3 := by …
Mentions: Usa1994P2.totalWeight, Usa1994P2.target
- theorem
Usa1994P2.totalWeight_target_eqShifting the base index of the target configuration does not change the total weight: the sum is over a full cycle line 168 sourceSource documentation
Shifting the base index of the target configuration does not change the total weight: the sum is over a full cycle.
standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
ZMod,OfNat.ofNat,Nat,Eq,Int, Usa1994P2.totalWeight, Usa1994P2.targetProof uses:
Function.Bijective,HSub.hSub,Iff.mpr,Exists,And,Function.LeftInverse,Function.RightInverse,Function.bijective_iff_has_inverse,Exists.intro,HAdd.hAdd,And.intro,sub_add_cancel,add_sub_cancel_right,Trans.trans,Finset.sum,Finset.univ, Usa1994P2.pairWeight, Usa1994P2.targetPat,ZMod.val,Finset.sum_congrand 38 more51 instances, coercions and auxiliary constants left out.
Tactic trace: 9 steps
Open to load the checked before-and-after goal states.
theorem totalWeight_target_eq (m : ZMod 99) : totalWeight (target m) = totalWeight (target 0) := by …Mentions: Usa1994P2.totalWeight, Usa1994P2.target
- theorem
Usa1994P2.reachable_invariantEvery reachable configuration has the same total weight as the initial configuration, and has distinct consecutive values line 189 sourceSource documentation
Every reachable configuration has the same total weight as the initial configuration, and has distinct consecutive values.
standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses: Usa1994P2.Config,
Relation.ReflTransGen, Usa1994P2.Move, Usa1994P2.initial,And,Eq,Int, Usa1994P2.totalWeight,ZMod,OfNat.ofNat,Nat,Ne, Usa1994P2.Val,HAdd.hAddProof uses:
Relation.ReflTransGen.rec,And.intro,rfl, Usa1994P2.initial_distinct,Eq.trans,Eq.symm, Usa1994P2.totalWeight_move,And.right,And.left, Usa1994P2.move_preserves_distinct24 instances, coercions and auxiliary constants left out.
Tactic trace: 3 steps
Open to load the checked before-and-after goal states.
theorem reachable_invariant {b : Config} (hr : Relation.ReflTransGen Move initial b) : totalWeight b = totalWeight initial ∧ ∀ i, b i ≠ b (i + 1) := by …Mentions: Usa1994P2.Config, Usa1994P2.Move, Usa1994P2.initial, Usa1994P2.totalWeight
- determine
Usa1994P2.does_existThe answer to the question "is there a sequence of allowed moves to a target configuration?" is no line 201 sourceSource documentation
The answer to the question "is there a sequence of allowed moves to a target configuration?" is no.
no axioms what this means
Statement uses:
BoolProof uses:
Bool.falsedetermine does_exist : Bool := false
- problem
Usa1994P2.usa1994_p2line 203 sourcestandard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
ite,Eq,Bool, Usa1994P2.does_exist,Bool.true,Exists,ZMod,OfNat.ofNat,Nat,Relation.ReflTransGen, Usa1994P2.Config, Usa1994P2.Move, Usa1994P2.initial, Usa1994P2.target,NotProof uses:
id,False,Int, Usa1994P2.totalWeight,Ne, Usa1994P2.Val,HAdd.hAdd,And, Usa1994P2.reachable_invariant,absurd,Neg.neg,Eq.mp,congrArg, Usa1994P2.totalWeight_initial, Usa1994P2.totalWeight_target_zero, Usa1994P2.totalWeight_target_eq,of_decide_eq_true,Decidable.decide,Eq.refl24 instances, coercions and auxiliary constants left out.
Tactic trace: 6 steps
Open to load the checked before-and-after goal states.