Compfiles/Usa1994P2.lean

GitHub source file

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.

Imports (3)
Imported by 1 file
  1. abbrev Usa1994P2.Val The three values that may appear in the sequence line 39 source

    Source 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 map x ↦ x + 1 then sends 1 → 2 → 3 → 1.

    no axioms what this means

    Proof uses: ZMod, OfNat.ofNat, Nat

    1 instances, coercions and auxiliary constants left out.

    abbrev Val := ZMod 3
  2. abbrev Usa1994P2.Config A configuration of the sequence, indexed by ZMod 99 (indices are interpreted modulo 99, as in the problem statement) line 44 source

    Source documentation

    A configuration of the sequence, indexed by ZMod 99 (indices are interpreted modulo 99, as in the problem statement). Index i corresponds to the problem's aᵢ₊₁.

    no axioms what this means

    Proof uses: ZMod, OfNat.ofNat, Nat, Usa1994P2.Val

    1 instances, coercions and auxiliary constants left out.

    abbrev Config := ZMod 99 → Val

    Mentions: Usa1994P2.Val

  3. def Usa1994P2.initial The initial configuration: 1, 2, 1, 2, ..., 1, 2, 3 line 47 source

    Source 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.hMod

    21 instances, coercions and auxiliary constants left out.

    def initial : Config := fun i ↦
    …

    Mentions: Usa1994P2.Config

  4. def Usa1994P2.targetPat Documented declaration: targetPat line 54 source

    Source documentation

    The alternating pattern underlying the target configurations: targetPat k is the value at offset k (with 0 ≤ 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.Val

    Proof uses: ite, Eq, OfNat.ofNat, HMod.hMod

    21 instances, coercions and auxiliary constants left out.

    def targetPat (k : ℕ) : Val :=
    …

    Mentions: Usa1994P2.Val

  5. def Usa1994P2.target Documented declaration: target line 60 source

    Source documentation

    The target configuration with base index m: the value at index i depends only on the offset i - m, exactly as in the problem statement where index m + k carries the k-th value of the pattern.

    standard axioms: Classical.choice, Quot.sound, propext what this means

    Statement uses: ZMod, OfNat.ofNat, Nat, Usa1994P2.Config

    Proof uses: Usa1994P2.targetPat, ZMod.val, HSub.hSub

    9 instances, coercions and auxiliary constants left out.

    def target (m : ZMod 99) : Config := fun i ↦ targetPat (i - m).val

    Mentions: Usa1994P2.Config, Usa1994P2.targetPat

  6. def Usa1994P2.Move An allowed move: change the value at some index n to another value v that differs from both neighbors line 64 source

    Source documentation

    An allowed move: change the value at some index n to another value v that 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.update

    17 instances, coercions and auxiliary constants left out.

    def Move (a b : Config) : Prop :=
    …

    Mentions: Usa1994P2.Config

  7. def Usa1994P2.pairWeight Documented declaration: pairWeight line 72 source

    Source documentation

    The weight of a pair of consecutive values: 0 if they are equal, +1 if the second is the cyclic successor of the first (i.e. the pairs (1,2), (2,3), (3,1) of the problem statement), and -1 otherwise.

    standard axioms: Classical.choice, Quot.sound, propext what this means

    Statement uses: Usa1994P2.Val, Int

    Proof uses: ite, Eq, OfNat.ofNat, Nat, HAdd.hAdd, Neg.neg

    18 instances, coercions and auxiliary constants left out.

    def pairWeight (x y : Val) : ℤ :=
    …

    Mentions: Usa1994P2.Val

  8. def Usa1994P2.totalWeight The invariant: the total weight around the cycle line 76 source

    Source documentation

    The invariant: the total weight around the cycle.

    standard axioms: Classical.choice, Quot.sound, propext what this means

    Statement uses: Usa1994P2.Config, Int

    Proof uses: Finset.sum, ZMod, OfNat.ofNat, Nat, Finset.univ, Usa1994P2.pairWeight, HAdd.hAdd

    15 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

  9. theorem Usa1994P2.pairWeight_local A case analysis on ZMod 3: the key local identity behind the invariance of totalWeight line 83 source

    Source documentation

    A case analysis on ZMod 3: the key local identity behind the invariance of totalWeight. If x differs from both L and R and v differs from all of x, L and R, then the two pairs through x and through v have the same total weight. (This forces L = 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.ofNat

    Proof uses: of_decide_eq_true, Nat, id, Bool, Decidable.decide, Bool.true, Eq.refl

    19 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

  10. theorem Usa1994P2.succ_ne_self In ZMod 99, an index and its successor are distinct line 89 source

    Source 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.hAdd

    Proof uses: Eq, of_decide_eq_true, id, Bool, Decidable.decide, Bool.true, Eq.refl, HSub.hSub, congrArg, Eq.mp, sub_self, add_sub_cancel_left

    40 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
    …
  11. theorem Usa1994P2.pred_ne_self In ZMod 99, an index and its predecessor are distinct line 97 source

    Source 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.hSub

    Proof 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_left

    41 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
    …
  12. theorem Usa1994P2.move_preserves_distinct A move preserves the property that every two consecutive values are distinct line 106 source

    Source 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.hAdd

    Proof 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.symm

    32 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

  13. theorem Usa1994P2.totalWeight_move The total weight is invariant under allowed moves, provided the configuration has distinct consecutive values line 123 source

    Source 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.totalWeight

    Proof 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_ne and 18 more

    61 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

  14. theorem Usa1994P2.initial_distinct In the initial configuration, consecutive values are distinct line 153 source

    Source 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.hAdd

    Proof uses: of_decide_eq_true, Eq, id, Bool, Decidable.decide, Bool.true, Eq.refl

    29 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

  15. theorem Usa1994P2.totalWeight_initial The total weight of the initial configuration is 3 line 158 source

    Source 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.ofNat

    Proof uses: of_decide_eq_true, id, Bool, Decidable.decide, Bool.true, Eq.refl

    3 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

  16. theorem Usa1994P2.totalWeight_target_zero The total weight of the target configuration with base 0 is -3 line 163 source

    Source documentation

    The total weight of the target configuration with base 0 is -3.

    standard axioms: Classical.choice, Quot.sound, propext what this means

    Statement uses: Eq, Int, Usa1994P2.totalWeight, Usa1994P2.target, OfNat.ofNat, ZMod, Nat, Neg.neg

    Proof uses: of_decide_eq_true, id, Bool, Decidable.decide, Bool.true, Eq.refl

    19 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

  17. theorem Usa1994P2.totalWeight_target_eq Shifting the base index of the target configuration does not change the total weight: the sum is over a full cycle line 168 source

    Source 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.target

    Proof 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_congr and 38 more

    51 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

  18. theorem Usa1994P2.reachable_invariant Every reachable configuration has the same total weight as the initial configuration, and has distinct consecutive values line 189 source

    Source 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.hAdd

    Proof uses: Relation.ReflTransGen.rec, And.intro, rfl, Usa1994P2.initial_distinct, Eq.trans, Eq.symm, Usa1994P2.totalWeight_move, And.right, And.left, Usa1994P2.move_preserves_distinct

    24 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

  19. determine Usa1994P2.does_exist The answer to the question "is there a sequence of allowed moves to a target configuration?" is no line 201 source

    Source 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: Bool

    Proof uses: Bool.false

    determine does_exist : Bool := false
  20. problem Usa1994P2.usa1994_p2 line 203 source

    standard 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, Not

    Proof 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.refl

    24 instances, coercions and auxiliary constants left out.

    Tactic trace: 6 steps

    Open to load the checked before-and-after goal states.