Compfiles/Usa1997P3.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

17 declarations, 0 contain sorry, 0 declared as axioms

USA Mathematical Olympiad 1997, Problem 3

Prove that for any integer n, there exists a unique polynomial Q with coefficients in {0, 1, ..., 9} such that Q(-2) = Q(-5) = n.

Imports (8)
Imported by 1 file
  1. def Usa1997P3.digit The unique digit in {0, …, 9} congruent to u modulo 2 and to v modulo 5 (which exist and are unique by the Chinese remainder theorem) line 47 source

    Source documentation

    The unique digit in {0, …, 9} congruent to u modulo 2 and to v modulo 5 (which exist and are unique by the Chinese remainder theorem).

    no axioms what this means

    Statement uses: Int

    Proof uses: HMod.hMod, HSub.hSub, HMul.hMul, OfNat.ofNat

    7 instances, coercions and auxiliary constants left out.

    def digit (u v : ℤ) : ℤ := (6 * v - 5 * u) % 10
  2. lemma Usa1997P3.digit_props line 49 source

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

    Statement uses: Int, And, LE.le, OfNat.ofNat, Usa1997P3.digit, Eq, HMod.hMod

    Proof uses: id, And.intro, HSub.hSub, HMul.hMul

    16 instances, coercions and auxiliary constants left out.

    Tactic trace: 6 steps

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

  3. lemma Usa1997P3.step_props Documented declaration: step_props line 58 source

    Source documentation

    One step of the extraction: the successor pair ((digit u v - u)/2, (digit u v - v)/5) keeps the invariant u ≡ v (mod 3), and its components are strictly smaller than those of (u, v) as soon as |v| > 2 (for the second component) or |u| > 9 (for the first one).

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

    Statement uses: Int, Eq, HMod.hMod, HSub.hSub, OfNat.ofNat, And, LE.le, Usa1997P3.digit, HMul.hMul, HDiv.hDiv, LT.lt, Nat, Int.natAbs

    Proof uses: Usa1997P3.digit_props, Dvd.dvd, Int.mul_ediv_cancel', And.intro

    34 instances, coercions and auxiliary constants left out.

    Tactic trace: 12 steps

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

    lemma step_props (u v : ℤ) (h3 : (u - v) % 3 = 0) :
        0 ≤ digit u v ∧ digit u v ≤ 9 ∧
        2 * ((digit u v - u) / 2) = digit u v - u ∧
        5 * ((digit u v - v) / 5) = digit u v - v ∧
        ((digit u v - u) / 2 - (digit u v - v) / 5) % 3 = 0 ∧
        (2 < v.natAbs → ((digit u v - v) / 5).natAbs < v.natAbs) ∧
        (v.natAbs ≤ 2 → 9 < u.natAbs → ((digit u v - u) / 2).natAbs < u.natAbs) ∧
        (v.natAbs ≤ 2 → ((digit u v - v) / 5).natAbs ≤ 2) := by
    …

    Mentions: Usa1997P3.digit

  4. def Usa1997P3.polyOfDigits The polynomial whose coefficients are the given list of digits, in little-endian order line 75 source

    Source documentation

    The polynomial whose coefficients are the given list of digits, in little-endian order.

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

    Statement uses: List, Int, Polynomial

    4 instances, coercions and auxiliary constants left out.

    noncomputable def polyOfDigits : List ℤ → ℤ[X]
      | [] => 0
      | d :: ds => C d + X * polyOfDigits ds
  5. lemma Usa1997P3.eval_polyOfDigits_cons line 79 source

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

    Statement uses: Int, List, Eq, Polynomial.eval, Usa1997P3.polyOfDigits, List.cons, HAdd.hAdd, HMul.hMul

    Proof uses: of_eq_true, Eq.trans, True, congrFun', congrArg, Polynomial, Polynomial.X, RingHom, Polynomial.C, eq_intCast, Polynomial.eval_add, congr, Polynomial.eval_intCast, Polynomial.eval_mul, Polynomial.eval_X, eq_self

    31 instances, coercions and auxiliary constants left out.

    Tactic trace: 1 steps

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

  6. lemma Usa1997P3.coeff_polyOfDigits_cons line 83 source

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

    Statement uses: Int, List, Nat, Eq, Finsupp, Polynomial.coeff, Usa1997P3.polyOfDigits, List.cons, ite, OfNat.ofNat, HSub.hSub

    Proof uses: Nat.casesAuxOn, Eq.mpr, id, congrArg, ite_eq_left, rfl, of_eq_true, Eq.trans, True, congrFun', HAdd.hAdd, Polynomial, RingHom, Polynomial.C, HMul.hMul, Polynomial.X, Polynomial.coeff_add, congr, Polynomial.coeff_C_zero, Polynomial.mul_coeff_zero and 12 more

    34 instances, coercions and auxiliary constants left out.

    Tactic trace: 7 steps

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

  7. lemma Usa1997P3.coeff_polyOfDigits line 95 source

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

    Statement uses: List, Int, Membership.mem, And, LE.le, OfNat.ofNat, Nat, Finsupp, Polynomial.coeff, Usa1997P3.polyOfDigits

    Proof uses: List.rec, List.nil, of_eq_true, Eq.trans, True, congr, congrArg, and_self, List.cons, Or, Eq, congrFun', eq_self, true_or, List.mem_cons_of_mem, Eq.mpr, ite, HSub.hSub, id, Usa1997P3.coeff_polyOfDigits_cons and 9 more

    55 instances, coercions and auxiliary constants left out.

    Tactic trace: 9 steps

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

  8. def Usa1997P3.build Runs the extraction algorithm for at most fuel steps, returning the list of extracted digits if the pair (0, 0) is reached in time line 109 source

    Source documentation

    Runs the extraction algorithm for at most fuel steps, returning the list of extracted digits if the pair (0, 0) is reached in time.

    no axioms what this means

    Statement uses: Nat, Int, Option, List

    2 instances, coercions and auxiliary constants left out.

    def build : ℕ → ℤ → ℤ → Option (List ℤ)
      | 0, u, v => if u = 0 ∧ v = 0 then some [] else none
      | fuel + 1, u, v =>
        if u = 0 ∧ v = 0 then some []
        else
          match build fuel ((digit u v - u) / 2) ((digit u v - v) / 5) with
          | some ds => some (digit u v :: ds)
          | none => none
    
    /-- Any digit list produced by `build` from a pair `(u, v)` with
    `u ≡ v (mod 3)` indeed represents `(u, v)`. -/

    Mentions: Usa1997P3.digit

  9. lemma Usa1997P3.build_correct Any digit list produced by build from a pair (u, v) with u ≡ v (mod 3) indeed represents (u, v) line 120 source

    Source documentation

    Any digit list produced by build from a pair (u, v) with u ≡ v (mod 3) indeed represents (u, v).

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

    Statement uses: Nat, Int, List, Eq, Option, Usa1997P3.build, Option.some, HMod.hMod, HSub.hSub, OfNat.ofNat, And, Polynomial.eval, Neg.neg, Usa1997P3.polyOfDigits, Membership.mem, LE.le

    Proof uses: Nat.recAux, dite, List.nil, And.intro, of_eq_true, Eq.trans, True, congrFun', congrArg, Polynomial.eval_zero, eq_self, False.elim, Eq.mp, False, Option.some.inj, ite, Option.none, ite_eq_left, Eq.symm, Not and 21 more

    40 instances, coercions and auxiliary constants left out.

    Tactic trace: 46 steps

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

    lemma build_correct (fuel : ℕ) (u v : ℤ) (ds : List ℤ) (h : build fuel u v = some ds)
        (h3 : (u - v) % 3 = 0) :
        (polyOfDigits ds).eval (-2) = u ∧ (polyOfDigits ds).eval (-5) = v ∧
          ∀ d ∈ ds, 0 ≤ d ∧ d ≤ 9 := by
    …

    Mentions: h, Usa1997P3.build, Usa1997P3.polyOfDigits

  10. lemma Usa1997P3.build_region_all On the finite region |u| ≤ 9, |v| ≤ 2 the algorithm always terminates in at most 8 steps (checked here by exhaustive computation over the 95 pairs with u ≡ v (mod 3)) line 159 source

    Source documentation

    On the finite region |u| ≤ 9, |v| ≤ 2 the algorithm always terminates in at most 8 steps (checked here by exhaustive computation over the 95 pairs with u ≡ v (mod 3)).

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

    Statement uses: Nat, Membership.mem, Finset, Finset.range, OfNat.ofNat, Eq, Int, HMod.hMod, HSub.hSub, Bool, Option.isSome, List, Usa1997P3.build, Bool.true

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

    24 instances, coercions and auxiliary constants left out.

    Tactic trace: 1 steps

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

    lemma build_region_all :
        ∀ a ∈ Finset.range 19, ∀ b ∈ Finset.range 5,
          ((a : ℤ) - 9 - ((b : ℤ) - 2)) % 3 = 0 →
          (build 8 ((a : ℤ) - 9) ((b : ℤ) - 2)).isSome := by
    …

    Mentions: Usa1997P3.build

  11. lemma Usa1997P3.build_region_some line 165 source

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

    Statement uses: Int, And, LE.le, Neg.neg, OfNat.ofNat, Eq, HMod.hMod, HSub.hSub, Exists, List, Option, Usa1997P3.build, Nat, Option.some

    Proof uses: Membership.mem, Finset, Finset.range, Exists.intro, Int.toNat, HAdd.hAdd, And.intro, Iff.mpr, LT.lt, Finset.mem_range, Eq.mpr, id, congrArg, Eq.symm, Iff.mp, Bool, Option.isSome, Bool.true, Option.isSome_iff_exists, Usa1997P3.build_region_all and 1 more

    29 instances, coercions and auxiliary constants left out.

    Tactic trace: 12 steps

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

  12. def Usa1997P3.Good The specification of the problem: Q has coefficients in {0, …, 9} and takes the values u at -2 and v at -5 line 180 source

    Source documentation

    The specification of the problem: Q has coefficients in {0, …, 9} and takes the values u at -2 and v at -5.

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

    Statement uses: Int, Polynomial

    Proof uses: And, Nat, LE.le, OfNat.ofNat, Finsupp, Polynomial.coeff, Eq, Polynomial.eval, Neg.neg

    9 instances, coercions and auxiliary constants left out.

    def Good (u v : ℤ) (Q : ℤ[X]) : Prop :=
    …
  13. lemma Usa1997P3.good_of_good_step If the successor pair of (u, v) is representable, so is (u, v): prepend the extracted digit as the new constant coefficient line 185 source

    Source documentation

    If the successor pair of (u, v) is representable, so is (u, v): prepend the extracted digit as the new constant coefficient.

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

    Statement uses: Int, Eq, HMod.hMod, HSub.hSub, OfNat.ofNat, Exists, Polynomial, Usa1997P3.Good, HDiv.hDiv, Usa1997P3.digit

    Proof uses: LE.le, And, HMul.hMul, LT.lt, Nat, Int.natAbs, Usa1997P3.step_props, Finsupp, Polynomial.coeff, Polynomial.eval, Neg.neg, Exists.intro, HAdd.hAdd, RingHom, Polynomial.C, Polynomial.X, And.intro, Nat.casesAuxOn, of_eq_true, Eq.trans and 24 more

    65 instances, coercions and auxiliary constants left out.

    Tactic trace: 19 steps

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

    lemma good_of_good_step (u v : ℤ) (h3 : (u - v) % 3 = 0)
        (h : ∃ Q, Good ((digit u v - u) / 2) ((digit u v - v) / 5) Q) :
        ∃ Q, Good u v Q := by
    …

    Mentions: h, Usa1997P3.Good, Usa1997P3.digit

  14. theorem Usa1997P3.exists_good_region Documented declaration: exists_good_region line 209 source

    Source documentation

    Existence for all pairs in the region |v| ≤ 2, by strong descent on |u|: either |u| ≤ 9 and we are in the finite region checked by build_region_all, or one extraction step strictly decreases |u|.

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

    Statement uses: Int, LE.le, Nat, Int.natAbs, OfNat.ofNat, Eq, HMod.hMod, HSub.hSub, Exists, Polynomial, Usa1997P3.Good

    Proof uses: Nat.strong_induction_on, LT.lt, dite, List, Option, Usa1997P3.build, Option.some, Usa1997P3.build_region_some, Polynomial.eval, Neg.neg, Usa1997P3.polyOfDigits, And, Membership.mem, Usa1997P3.build_correct, Exists.intro, And.intro, Finsupp, Polynomial.coeff, Usa1997P3.coeff_polyOfDigits, Not and 7 more

    35 instances, coercions and auxiliary constants left out.

    Tactic trace: 15 steps

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

    theorem exists_good_region (u v : ℤ) (hv2 : v.natAbs ≤ 2) (h3 : (u - v) % 3 = 0) :
        ∃ Q, Good u v Q := by
    …

    Mentions: Usa1997P3.Good

  15. theorem Usa1997P3.exists_good Documented declaration: exists_good line 224 source

    Source documentation

    Existence for all pairs (u, v) with u ≡ v (mod 3), by strong descent on |v|: either |v| ≤ 2 and exists_good_region applies, or one extraction step strictly decreases |v|.

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

    Statement uses: Int, Eq, HMod.hMod, HSub.hSub, OfNat.ofNat, Exists, Polynomial, Usa1997P3.Good

    Proof uses: Nat.strong_induction_on, Nat, Int.natAbs, LT.lt, dite, LE.le, Usa1997P3.exists_good_region, Not, Usa1997P3.digit, And, HMul.hMul, HDiv.hDiv, Usa1997P3.step_props, rfl, Usa1997P3.good_of_good_step, Exists.intro, Eq.refl

    25 instances, coercions and auxiliary constants left out.

    Tactic trace: 11 steps

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

    theorem exists_good (u v : ℤ) (h3 : (u - v) % 3 = 0) : ∃ Q, Good u v Q := by
    …

    Mentions: Usa1997P3.Good

  16. theorem Usa1997P3.good_unique Uniqueness: the difference D of two good polynomials has coefficients in {-9, …, 9} and vanishes at -2 and -5 line 237 source

    Source documentation

    Uniqueness: the difference D of two good polynomials has coefficients in {-9, …, 9} and vanishes at -2 and -5. Its trailing coefficient is then divisible by both 2 and 5, hence by 10, hence it is zero — a contradiction unless D = 0.

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

    Statement uses: Polynomial, Int, Usa1997P3.Good, Eq

    Proof uses: Decidable.byContradiction, Not, Nat, And, LE.le, OfNat.ofNat, Finsupp, Polynomial.coeff, Polynomial.eval, Neg.neg, False, HSub.hSub, rfl, Ne, Iff.mpr, sub_ne_zero, of_eq_true, Eq.trans, True, congrFun' and 45 more

    90 instances, coercions and auxiliary constants left out.

    Tactic trace: 56 steps

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

    theorem good_unique (Q₁ Q₂ : ℤ[X]) (n : ℤ) (h₁ : Good n n Q₁) (h₂ : Good n n Q₂) :
        Q₁ = Q₂ := by
    …

    Mentions: Usa1997P3.Good

  17. problem Usa1997P3.usa1997_p3 line 289 source

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

    Statement uses: Int, ExistsUnique, Polynomial, And, Nat, LE.le, OfNat.ofNat, Finsupp, Polynomial.coeff, Eq, Polynomial.eval, Neg.neg

    Proof uses: Usa1997P3.Good, Exists, Usa1997P3.exists_good, of_eq_true, HMod.hMod, HSub.hSub, Eq.trans, True, congrFun', congrArg, sub_self, EuclideanDomain.zero_mod, eq_self, Exists.intro, And.intro, Usa1997P3.good_unique

    32 instances, coercions and auxiliary constants left out.

    Tactic trace: 3 steps

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