Compfiles/Usa1997P3.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
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
- def
Usa1997P3.digitThe unique digit in{0, …, 9}congruent toumodulo 2 and tovmodulo 5 (which exist and are unique by the Chinese remainder theorem) line 47 sourceSource documentation
The unique digit in
{0, …, 9}congruent toumodulo 2 and tovmodulo 5 (which exist and are unique by the Chinese remainder theorem).no axioms what this means
Statement uses:
IntProof uses:
HMod.hMod,HSub.hSub,HMul.hMul,OfNat.ofNat7 instances, coercions and auxiliary constants left out.
def digit (u v : ℤ) : ℤ := (6 * v - 5 * u) % 10
- lemma
Usa1997P3.digit_propsline 49 sourcestandard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
Int,And,LE.le,OfNat.ofNat, Usa1997P3.digit,Eq,HMod.hModProof uses:
id,And.intro,HSub.hSub,HMul.hMul16 instances, coercions and auxiliary constants left out.
Tactic trace: 6 steps
Open to load the checked before-and-after goal states.
- lemma
Usa1997P3.step_propsDocumented declaration: step_props line 58 sourceSource documentation
One step of the extraction: the successor pair
((digit u v - u)/2, (digit u v - v)/5)keeps the invariantu ≡ 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.natAbsProof uses: Usa1997P3.digit_props,
Dvd.dvd,Int.mul_ediv_cancel',And.intro34 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
- def
Usa1997P3.polyOfDigitsThe polynomial whose coefficients are the given list of digits, in little-endian order line 75 sourceSource 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,Polynomial4 instances, coercions and auxiliary constants left out.
noncomputable def polyOfDigits : List ℤ → ℤ[X] | [] => 0 | d :: ds => C d + X * polyOfDigits ds
- lemma
Usa1997P3.eval_polyOfDigits_consline 79 sourcestandard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
Int,List,Eq,Polynomial.eval, Usa1997P3.polyOfDigits,List.cons,HAdd.hAdd,HMul.hMulProof 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_self31 instances, coercions and auxiliary constants left out.
Tactic trace: 1 steps
Open to load the checked before-and-after goal states.
- lemma
Usa1997P3.coeff_polyOfDigits_consline 83 sourcestandard 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.hSubProof 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_zeroand 12 more34 instances, coercions and auxiliary constants left out.
Tactic trace: 7 steps
Open to load the checked before-and-after goal states.
- lemma
Usa1997P3.coeff_polyOfDigitsline 95 sourcestandard 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.polyOfDigitsProof 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 more55 instances, coercions and auxiliary constants left out.
Tactic trace: 9 steps
Open to load the checked before-and-after goal states.
- def
Usa1997P3.buildRuns the extraction algorithm for at mostfuelsteps, returning the list of extracted digits if the pair(0, 0)is reached in time line 109 sourceSource documentation
Runs the extraction algorithm for at most
fuelsteps, 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,List2 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
- lemma
Usa1997P3.build_correctAny digit list produced bybuildfrom a pair(u, v)withu ≡ v (mod 3)indeed represents(u, v)line 120 sourceSource documentation
Any digit list produced by
buildfrom a pair(u, v)withu ≡ 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.leProof 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,Notand 21 more40 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
- lemma
Usa1997P3.build_region_allOn the finite region|u| ≤ 9,|v| ≤ 2the algorithm always terminates in at most 8 steps (checked here by exhaustive computation over the 95 pairs withu ≡ v (mod 3)) line 159 sourceSource documentation
On the finite region
|u| ≤ 9,|v| ≤ 2the algorithm always terminates in at most 8 steps (checked here by exhaustive computation over the 95 pairs withu ≡ 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.trueProof uses:
of_decide_eq_true,id,Decidable.decide,Eq.refl24 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
- lemma
Usa1997P3.build_region_someline 165 sourcestandard 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.someProof 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 more29 instances, coercions and auxiliary constants left out.
Tactic trace: 12 steps
Open to load the checked before-and-after goal states.
- def
Usa1997P3.GoodThe specification of the problem:Qhas coefficients in{0, …, 9}and takes the valuesuat-2andvat-5line 180 sourceSource documentation
The specification of the problem:
Qhas coefficients in{0, …, 9}and takes the valuesuat-2andvat-5.standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
Int,PolynomialProof uses:
And,Nat,LE.le,OfNat.ofNat,Finsupp,Polynomial.coeff,Eq,Polynomial.eval,Neg.neg9 instances, coercions and auxiliary constants left out.
def Good (u v : ℤ) (Q : ℤ[X]) : Prop := …
- lemma
Usa1997P3.good_of_good_stepIf the successor pair of(u, v)is representable, so is(u, v): prepend the extracted digit as the new constant coefficient line 185 sourceSource 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.digitProof 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.transand 24 more65 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
- theorem
Usa1997P3.exists_good_regionDocumented declaration: exists_good_region line 209 sourceSource documentation
Existence for all pairs in the region
|v| ≤ 2, by strong descent on|u|: either|u| ≤ 9and we are in the finite region checked bybuild_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.GoodProof 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,Notand 7 more35 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
- theorem
Usa1997P3.exists_goodDocumented declaration: exists_good line 224 sourceSource documentation
Existence for all pairs
(u, v)withu ≡ v (mod 3), by strong descent on|v|: either|v| ≤ 2andexists_good_regionapplies, 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.GoodProof 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.refl25 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
- theorem
Usa1997P3.good_uniqueUniqueness: the differenceDof two good polynomials has coefficients in{-9, …, 9}and vanishes at-2and-5line 237 sourceSource documentation
Uniqueness: the difference
Dof two good polynomials has coefficients in{-9, …, 9}and vanishes at-2and-5. Its trailing coefficient is then divisible by both 2 and 5, hence by 10, hence it is zero — a contradiction unlessD = 0.standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
Polynomial,Int, Usa1997P3.Good,EqProof 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 more90 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
- problem
Usa1997P3.usa1997_p3line 289 sourcestandard 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.negProof 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_unique32 instances, coercions and auxiliary constants left out.
Tactic trace: 3 steps
Open to load the checked before-and-after goal states.