fact
stringlengths
6
3.84k
type
stringclasses
11 values
library
stringclasses
32 values
imports
listlengths
1
14
filename
stringlengths
20
95
symbolic_name
stringlengths
1
90
docstring
stringlengths
7
20k
private tendsto_const_rpow_inv {C : ℝ} (hC : 0 < C) : Tendsto (fun k : ℕ ↦ C ^ (k : ℝ)⁻¹) atTop (𝓝 1) := ((continuous_iff_continuousAt.mpr fun _ ↦ continuousAt_const_rpow hC.ne').tendsto' 0 1 (rpow_zero C)).comp <| tendsto_inv_atTop_zero.comp tendsto_natCast_atTop_atTop
lemma
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
tendsto_const_rpow_inv
null
private tendsto_nat_rpow_inv : Tendsto (fun k : ℕ ↦ (k : ℝ) ^ (k : ℝ)⁻¹) atTop (𝓝 1) := by simp_rw [← one_div] exact Tendsto.comp tendsto_rpow_div tendsto_natCast_atTop_atTop
lemma
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
tendsto_nat_rpow_inv
null
private list_mul_sum {R : Type*} [Semiring R] {T : Type*} (l : List T) (y : R) (x : R) : (l.mapIdx fun i _ => x * y ^ i).sum = x * (l.mapIdx fun i _ => y ^ i).sum := by simp_rw [← smul_eq_mul, List.smul_sum, List.mapIdx_eq_zipIdx_map] congr 1 simp
lemma
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
list_mul_sum
null
private list_geom {T : Type*} {F : Type*} [DivisionRing F] (l : List T) {y : F} (hy : y ≠ 1) : (l.mapIdx fun i _ => y ^ i).sum = (y ^ l.length - 1) / (y - 1) := by rw [← geom_sum_eq hy l.length, List.mapIdx_eq_zipIdx_map, Finset.sum_range, ← Fin.sum_univ_fun_getElem] simp only let e : Fin l.zipIdx.length ...
lemma
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
list_geom
null
eq_on_nat_iff_eq : (∀ n : ℕ, f n = g n) ↔ f = g := by refine ⟨fun h ↦ ?_, fun h n ↦ congrFun (congrArg DFunLike.coe h) ↑n⟩ ext1 z rw [← Rat.num_div_den z, map_div₀, map_div₀, h, eq_on_nat_iff_eq_on_int.mp h]
lemma
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
eq_on_nat_iff_eq
Values of an absolute value on the rationals are determined by the values on the natural numbers.
exists_nat_rpow_iff_isEquiv : (∃ c : ℝ, 0 < c ∧ ∀ n : ℕ, f n ^ c = g n) ↔ f.IsEquiv g := by rw [isEquiv_iff_exists_rpow_eq] refine ⟨fun ⟨c, hc, h⟩ ↦ ⟨c, hc, ?_⟩, fun ⟨c, hc, h⟩ ↦ ⟨c, hc, (congrFun h ·)⟩⟩ ext1 x rw [← Rat.num_div_den x, map_div₀, map_div₀, div_rpow (by positivity) (by positivity), h x.den, ←...
lemma
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
exists_nat_rpow_iff_isEquiv
The equivalence class of an absolute value on the rationals is determined by its values on the natural numbers.
padic (p : ℕ) [Fact p.Prime] : AbsoluteValue ℚ ℝ where toFun x := (padicNorm p x : ℝ) map_mul' := by simp only [padicNorm.mul, Rat.cast_mul, forall_const] nonneg' x := cast_nonneg.mpr <| padicNorm.nonneg x eq_zero' x := ⟨fun H ↦ padicNorm.zero_of_padicNorm_eq_zero <| cast_eq_zero.mp H, fun H ↦ cast_eq...
def
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
padic
The real-valued `AbsoluteValue` corresponding to the p-adic norm on `ℚ`.
padic_le_one (p : ℕ) [Fact p.Prime] (n : ℤ) : padic p n ≤ 1 := by simp only [padic_eq_padicNorm] exact_mod_cast padicNorm.of_int n variable (hf_nontriv : f.IsNontrivial) (bdd : ∀ n : ℕ, f n ≤ 1) include hf_nontriv bdd in
lemma
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
padic_le_one
null
exists_minimal_nat_zero_lt_and_lt_one : ∃ p : ℕ, (0 < f p ∧ f p < 1) ∧ ∀ m : ℕ, 0 < f m ∧ f m < 1 → p ≤ m := by obtain ⟨n, hn1, hn2⟩ : ∃ n : ℕ, n ≠ 0 ∧ f n ≠ 1 := by contrapose! hf_nontriv refine (isNontrivial_iff_ne_trivial f).not_left.mpr <| eq_on_nat_iff_eq.mp fun n ↦ ?_ rcases eq_or_ne n 0 with rf...
lemma
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
exists_minimal_nat_zero_lt_and_lt_one
There exists a minimal positive integer with absolute value smaller than 1.
is_prime_of_minimal_nat_zero_lt_and_lt_one : p.Prime := by rw [← Nat.irreducible_iff_nat_prime] constructor -- Two goals: p is not a unit and any product giving p must contain a unit. · rw [Nat.isUnit_iff] rintro rfl simp only [Nat.cast_one, map_one, lt_self_iff_false] at hp1 · rintro a b rfl rw [Na...
lemma
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
is_prime_of_minimal_nat_zero_lt_and_lt_one
The minimal positive integer with absolute value smaller than 1 is a prime number.
eq_one_of_not_dvd {m : ℕ} (hpm : ¬ p ∣ m) : f m = 1 := by apply le_antisymm (bdd m) by_contra! hm set M := f p ⊔ f m with hM set k := Nat.ceil (M.logb (1 / 2)) + 1 with hk obtain ⟨a, b, bezout⟩ : IsCoprime (p ^ k : ℤ) (m ^ k) := is_prime_of_minimal_nat_zero_lt_and_lt_one hp0 hp1 hmin |>.coprime_iff_...
lemma
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
eq_one_of_not_dvd
A natural number not divisible by `p` has absolute value 1.
exists_pos_eq_pow_neg : ∃ t : ℝ, 0 < t ∧ f p = p ^ (-t) := by have pprime := is_prime_of_minimal_nat_zero_lt_and_lt_one hp0 hp1 hmin refine ⟨- logb p (f p), Left.neg_pos_iff.mpr <| logb_neg (mod_cast pprime.one_lt) hp0 hp1, ?_⟩ rw [neg_neg] exact (rpow_logb (mod_cast pprime.pos) (mod_cast pprime.ne_one) hp0).sy...
lemma
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
exists_pos_eq_pow_neg
The absolute value of `p` is `p ^ (-t)` for some positive real number `t`.
equiv_padic_of_bounded : ∃! p, ∃ (_ : Fact p.Prime), f.IsEquiv (padic p) := by obtain ⟨p, hfp, hmin⟩ := exists_minimal_nat_zero_lt_and_lt_one hf_nontriv bdd have hprime := is_prime_of_minimal_nat_zero_lt_and_lt_one hfp.1 hfp.2 hmin have hprime_fact : Fact p.Prime := ⟨hprime⟩ obtain ⟨t, h⟩ := exists_pos_eq_p...
theorem
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
equiv_padic_of_bounded
If `f` is bounded and not trivial, then it is equivalent to a p-adic absolute value.
real : AbsoluteValue ℚ ℝ where toFun x := |x| map_mul' x y := by simp nonneg' x := by simp eq_zero' x := by simp add_le' x y := by simpa using abs_add_le (x : ℝ) (y : ℝ) @[simp] lemma real_eq_abs (r : ℚ) : real r = |r| := (cast_abs r).symm
def
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
real
The standard absolute value on `ℚ`. We name it `real` because it corresponds to the unique real place of `ℚ`.
apply_le_sum_digits (n : ℕ) {m : ℕ} (hm : 1 < m) : f n ≤ ((Nat.digits m n).mapIdx fun i _ ↦ m * (f m) ^ i).sum := by set L := Nat.digits m n set L' : List ℚ := List.map Nat.cast (L.mapIdx fun i a ↦ (a * m ^ i)) with hL' have hcoef {c : ℕ} (hc : c ∈ Nat.digits m n) : f c < m := lt_of_le_of_lt (f.apply_nat_...
lemma
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
apply_le_sum_digits
Given any two integers `n`, `m` with `m > 1`, the absolute value of `n` is bounded by `m + m * f m + m * (f m) ^ 2 + ... + m * (f m) ^ d` where `d` is the number of digits of the expansion of `n` in base `m`.
one_lt_of_not_bounded (notbdd : ¬ ∀ n : ℕ, f n ≤ 1) {n₀ : ℕ} (hn₀ : 1 < n₀) : 1 < f n₀ := by contrapose! notbdd with h intro n have h_ineq1 {m : ℕ} (hm : 1 ≤ m) : f m ≤ n₀ * (logb n₀ m + 1) := by /- L is the string of digits of `n` in the base `n₀` -/ set L := Nat.digits n₀ m calc f m ≤ (L.mapIdx ...
lemma
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
one_lt_of_not_bounded
If `f n > 1` for some `n` then `f n > 1` for all `n ≥ 2`
private expr_pos : 0 < m * f m / (f m - 1) := by apply div_pos (mul_pos (mod_cast zero_lt_of_lt hm) (map_pos_of_ne_zero f (mod_cast ne_zero_of_lt hm))) linarith only [one_lt_of_not_bounded notbdd hm] include hn hm notbdd in
lemma
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
expr_pos
null
private param_upperbound {k : ℕ} (hk : k ≠ 0) : f n ≤ (m * f m / (f m - 1)) ^ (k : ℝ)⁻¹ * f m ^ logb m n := by have h_ineq1 {m n : ℕ} (hm : 1 < m) (hn : 1 < n) : f n ≤ (m * f m / (f m - 1)) * f m ^ logb m n := by let d := Nat.log m n calc f n ≤ ((Nat.digits m n).mapIdx fun i _ ↦ m * f m ^ i).sum...
lemma
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
param_upperbound
null
le_pow_log : f n ≤ f m ^ logb m n := by have : Tendsto (fun k : ℕ ↦ (m * f m / (f m - 1)) ^ (k : ℝ)⁻¹ * f m ^ logb m n) atTop (𝓝 (f m ^ logb m n)) := by nth_rw 2 [← one_mul (f ↑m ^ logb ↑m ↑n)] exact (tendsto_const_rpow_inv (expr_pos hm notbdd)).mul_const _ exact le_of_tendsto_of_tendsto (tendsto_con...
lemma
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
le_pow_log
Given two natural numbers `n, m` greater than 1 we have `f n ≤ f m ^ logb m n`.
private le_of_eq_pow {s t : ℝ} (hfm : f m = m ^ s) (hfn : f n = n ^ t) : t ≤ s := by rw [← rpow_le_rpow_left_iff (x := n) (mod_cast hn), ← hfn] apply le_trans <| le_pow_log hm hn notbdd rw [hfm, ← rpow_mul (Nat.cast_nonneg m), mul_comm, rpow_mul (Nat.cast_nonneg m), rpow_logb (mod_cast zero_lt_of_lt hm) (mod_...
lemma
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
le_of_eq_pow
Given `m, n ≥ 2` and `f m = m ^ s`, `f n = n ^ t` for `s, t > 0`, we have `t ≤ s`.
private eq_of_eq_pow {s t : ℝ} (hfm : f m = m ^ s) (hfn : f n = n ^ t) : s = t := le_antisymm (le_of_eq_pow hn hm notbdd hfn hfm) (le_of_eq_pow hm hn notbdd hfm hfn) include notbdd in
lemma
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
eq_of_eq_pow
null
equiv_real_of_unbounded : f.IsEquiv real := by obtain ⟨m, hm⟩ := Classical.exists_not_of_not_forall notbdd have oneltm : 1 < m := by contrapose! hm rcases le_one_iff_eq_zero_or_eq_one.mp hm with rfl | rfl <;> simp rw [← exists_nat_rpow_iff_isEquiv] set s := logb m (f m) with hs refine ⟨s⁻¹, inv_po...
theorem
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
equiv_real_of_unbounded
If `f` is not bounded and not trivial, then it is equivalent to the standard absolute value on `ℚ`.
equiv_real_or_padic (f : AbsoluteValue ℚ ℝ) (hf_nontriv : f.IsNontrivial) : f ≈ real ∨ ∃! p, ∃ (_ : Fact p.Prime), f ≈ (padic p) := by by_cases bdd : ∀ n : ℕ, f n ≤ 1 · exact .inr <| equiv_padic_of_bounded hf_nontriv bdd · exact .inl <| equiv_real_of_unbounded bdd
theorem
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
equiv_real_or_padic
**Ostrowski's Theorem**: every absolute value (with values in `ℝ`) on `ℚ` is equivalent to either the standard absolute value or a `p`-adic absolute value for a prime `p`.
not_real_isEquiv_padic (p : ℕ) [Fact p.Prime] : ¬ real.IsEquiv (padic p) := by rw [isEquiv_iff_exists_rpow_eq] rintro ⟨c, hc₀, hc⟩ apply_fun (· 2) at hc simp only [real_eq_abs, abs_ofNat, cast_ofNat] at hc exact ((padic_le_one p 2).trans_lt <| one_lt_rpow one_lt_two hc₀).ne' hc @[deprecated (since := "2025-09...
lemma
NumberTheory
[ "Mathlib.Analysis.AbsoluteValue.Equivalence", "Mathlib.Analysis.SpecialFunctions.Log.Base", "Mathlib.Analysis.SpecialFunctions.Pow.Continuity", "Mathlib.NumberTheory.Padics.PadicNorm" ]
Mathlib/NumberTheory/Ostrowski.lean
not_real_isEquiv_padic
The standard absolute value on `ℚ` is not equivalent to any `p`-adic absolute value.
is_pell_solution_iff_mem_unitary {d : ℤ} {a : ℤ√d} : a.re ^ 2 - d * a.im ^ 2 = 1 ↔ a ∈ unitary (ℤ√d) := by rw [← norm_eq_one_iff_mem_unitary, norm_def, sq, sq, ← mul_assoc]
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
is_pell_solution_iff_mem_unitary
An element of `ℤ√d` has norm one (i.e., `a.re^2 - d*a.im^2 = 1`) if and only if it is contained in the submonoid of unitary elements. TODO: merge this result with `Pell.isPell_iff_mem_unitary`.
Solution₁ (d : ℤ) : Type := ↥(unitary (ℤ√d))
def
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
Solution₁
`Pell.Solution₁ d` is the type of solutions to the Pell equation `x^2 - d*y^2 = 1`. We define this in terms of elements of `ℤ√d` of norm one.
instCommGroup : CommGroup (Solution₁ d) := inferInstanceAs (CommGroup (unitary (ℤ√d)))
instance
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
instCommGroup
null
instHasDistribNeg : HasDistribNeg (Solution₁ d) := inferInstanceAs (HasDistribNeg (unitary (ℤ√d)))
instance
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
instHasDistribNeg
null
instInhabited : Inhabited (Solution₁ d) := inferInstanceAs (Inhabited (unitary (ℤ√d)))
instance
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
instInhabited
null
protected x (a : Solution₁ d) : ℤ := (a : ℤ√d).re
def
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
x
The `x` component of a solution to the Pell equation `x^2 - d*y^2 = 1`
protected y (a : Solution₁ d) : ℤ := (a : ℤ√d).im
def
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
y
The `y` component of a solution to the Pell equation `x^2 - d*y^2 = 1`
prop (a : Solution₁ d) : a.x ^ 2 - d * a.y ^ 2 = 1 := is_pell_solution_iff_mem_unitary.mpr a.property
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
prop
The proof that `a` is a solution to the Pell equation `x^2 - d*y^2 = 1`
prop_x (a : Solution₁ d) : a.x ^ 2 = 1 + d * a.y ^ 2 := by rw [← a.prop]; ring
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
prop_x
An alternative form of the equation, suitable for rewriting `x^2`.
prop_y (a : Solution₁ d) : d * a.y ^ 2 = a.x ^ 2 - 1 := by rw [← a.prop]; ring
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
prop_y
An alternative form of the equation, suitable for rewriting `d * y^2`.
@[ext] ext {a b : Solution₁ d} (hx : a.x = b.x) (hy : a.y = b.y) : a = b := Subtype.ext <| Zsqrtd.ext hx hy
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
ext
Two solutions are equal if their `x` and `y` components are equal.
mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : Solution₁ d where val := ⟨x, y⟩ property := is_pell_solution_iff_mem_unitary.mp prop @[simp]
def
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
mk
Construct a solution from `x`, `y` and a proof that the equation is satisfied.
x_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (mk x y prop).x = x := rfl @[simp]
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
x_mk
null
y_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (mk x y prop).y = y := rfl @[simp]
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
y_mk
null
coe_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (↑(mk x y prop) : ℤ√d) = ⟨x, y⟩ := Zsqrtd.ext (x_mk x y prop) (y_mk x y prop) @[simp]
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
coe_mk
null
x_one : (1 : Solution₁ d).x = 1 := rfl @[simp]
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
x_one
null
y_one : (1 : Solution₁ d).y = 0 := rfl @[simp]
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
y_one
null
x_mul (a b : Solution₁ d) : (a * b).x = a.x * b.x + d * (a.y * b.y) := by rw [← mul_assoc] rfl @[simp]
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
x_mul
null
y_mul (a b : Solution₁ d) : (a * b).y = a.x * b.y + a.y * b.x := rfl @[simp]
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
y_mul
null
x_inv (a : Solution₁ d) : a⁻¹.x = a.x := rfl @[simp]
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
x_inv
null
y_inv (a : Solution₁ d) : a⁻¹.y = -a.y := rfl @[simp]
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
y_inv
null
x_neg (a : Solution₁ d) : (-a).x = -a.x := rfl @[simp]
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
x_neg
null
y_neg (a : Solution₁ d) : (-a).y = -a.y := rfl
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
y_neg
null
eq_zero_of_d_neg (h₀ : d < 0) (a : Solution₁ d) : a.x = 0 ∨ a.y = 0 := by have h := a.prop contrapose! h have h1 := sq_pos_of_ne_zero h.1 have h2 := sq_pos_of_ne_zero h.2 nlinarith
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
eq_zero_of_d_neg
When `d` is negative, then `x` or `y` must be zero in a solution.
x_ne_zero (h₀ : 0 ≤ d) (a : Solution₁ d) : a.x ≠ 0 := by intro hx have h : 0 ≤ d * a.y ^ 2 := mul_nonneg h₀ (sq_nonneg _) rw [a.prop_y, hx, sq, zero_mul, zero_sub] at h exact not_le.mpr (neg_one_lt_zero : (-1 : ℤ) < 0) h
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
x_ne_zero
A solution has `x ≠ 0`.
y_ne_zero_of_one_lt_x {a : Solution₁ d} (ha : 1 < a.x) : a.y ≠ 0 := by intro hy have prop := a.prop rw [hy, sq (0 : ℤ), zero_mul, mul_zero, sub_zero] at prop exact lt_irrefl _ (((one_lt_sq_iff₀ <| zero_le_one.trans ha.le).mpr ha).trans_eq prop)
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
y_ne_zero_of_one_lt_x
A solution with `x > 1` must have `y ≠ 0`.
d_pos_of_one_lt_x {a : Solution₁ d} (ha : 1 < a.x) : 0 < d := by refine pos_of_mul_pos_left ?_ (sq_nonneg a.y) rw [a.prop_y, sub_pos] exact one_lt_pow₀ ha two_ne_zero
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
d_pos_of_one_lt_x
If a solution has `x > 1`, then `d` is positive.
d_nonsquare_of_one_lt_x {a : Solution₁ d} (ha : 1 < a.x) : ¬IsSquare d := by have hp := a.prop rintro ⟨b, rfl⟩ simp_rw [← sq, ← mul_pow, sq_sub_sq, Int.mul_eq_one_iff_eq_one_or_neg_one] at hp cutsat
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
d_nonsquare_of_one_lt_x
If a solution has `x > 1`, then `d` is not a square.
eq_one_of_x_eq_one (h₀ : d ≠ 0) {a : Solution₁ d} (ha : a.x = 1) : a = 1 := by have prop := a.prop_y rw [ha, one_pow, sub_self, mul_eq_zero, or_iff_right h₀, sq_eq_zero_iff] at prop exact ext ha prop
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
eq_one_of_x_eq_one
A solution with `x = 1` is trivial.
eq_one_or_neg_one_iff_y_eq_zero {a : Solution₁ d} : a = 1 ∨ a = -1 ↔ a.y = 0 := by refine ⟨fun H => H.elim (fun h => by simp [h]) fun h => by simp [h], fun H => ?_⟩ have prop := a.prop rw [H, sq (0 : ℤ), mul_zero, mul_zero, sub_zero, sq_eq_one_iff] at prop exact prop.imp (fun h => ext h H) fun h => ext h H
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
eq_one_or_neg_one_iff_y_eq_zero
A solution is `1` or `-1` if and only if `y = 0`.
x_mul_pos {a b : Solution₁ d} (ha : 0 < a.x) (hb : 0 < b.x) : 0 < (a * b).x := by simp only [x_mul] refine neg_lt_iff_pos_add'.mp (abs_lt.mp ?_).1 rw [← abs_of_pos ha, ← abs_of_pos hb, ← abs_mul, ← sq_lt_sq, mul_pow a.x, a.prop_x, b.prop_x, ← sub_pos] ring_nf rcases le_or_gt 0 d with h | h · positivity ...
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
x_mul_pos
The set of solutions with `x > 0` is closed under multiplication.
y_mul_pos {a b : Solution₁ d} (hax : 0 < a.x) (hay : 0 < a.y) (hbx : 0 < b.x) (hby : 0 < b.y) : 0 < (a * b).y := by simp only [y_mul] positivity
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
y_mul_pos
The set of solutions with `x` and `y` positive is closed under multiplication.
x_pow_pos {a : Solution₁ d} (hax : 0 < a.x) (n : ℕ) : 0 < (a ^ n).x := by induction n with | zero => simp only [pow_zero, x_one, zero_lt_one] | succ n ih => rw [pow_succ]; exact x_mul_pos ih hax
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
x_pow_pos
If `(x, y)` is a solution with `x` positive, then all its powers with natural exponents have positive `x`.
y_pow_succ_pos {a : Solution₁ d} (hax : 0 < a.x) (hay : 0 < a.y) (n : ℕ) : 0 < (a ^ n.succ).y := by induction n with | zero => simp only [pow_one, hay] | succ n ih => rw [pow_succ']; exact y_mul_pos hax hay (x_pow_pos hax _) ih
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
y_pow_succ_pos
If `(x, y)` is a solution with `x` and `y` positive, then all its powers with positive natural exponents have positive `y`.
y_zpow_pos {a : Solution₁ d} (hax : 0 < a.x) (hay : 0 < a.y) {n : ℤ} (hn : 0 < n) : 0 < (a ^ n).y := by lift n to ℕ using hn.le norm_cast at hn ⊢ rw [← Nat.succ_pred_eq_of_pos hn] exact y_pow_succ_pos hax hay _
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
y_zpow_pos
If `(x, y)` is a solution with `x` and `y` positive, then all its powers with positive exponents have positive `y`.
x_zpow_pos {a : Solution₁ d} (hax : 0 < a.x) (n : ℤ) : 0 < (a ^ n).x := by cases n with | ofNat n => rw [Int.ofNat_eq_coe, zpow_natCast] exact x_pow_pos hax n | negSucc n => rw [zpow_negSucc] exact x_pow_pos hax (n + 1)
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
x_zpow_pos
If `(x, y)` is a solution with `x` positive, then all its powers have positive `x`.
sign_y_zpow_eq_sign_of_x_pos_of_y_pos {a : Solution₁ d} (hax : 0 < a.x) (hay : 0 < a.y) (n : ℤ) : (a ^ n).y.sign = n.sign := by rcases n with ((_ | n) | n) · rfl · rw [Int.ofNat_eq_coe, zpow_natCast] exact Int.sign_eq_one_of_pos (y_pow_succ_pos hax hay n) · rw [zpow_negSucc] exact Int.sign_eq_neg_on...
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
sign_y_zpow_eq_sign_of_x_pos_of_y_pos
If `(x, y)` is a solution with `x` and `y` positive, then the `y` component of any power has the same sign as the exponent.
exists_pos_variant (h₀ : 0 < d) (a : Solution₁ d) : ∃ b : Solution₁ d, 0 < b.x ∧ 0 ≤ b.y ∧ a ∈ ({b, b⁻¹, -b, -b⁻¹} : Set (Solution₁ d)) := by refine (lt_or_gt_of_ne (a.x_ne_zero h₀.le)).elim ((le_total 0 a.y).elim (fun hy hx => ⟨-a⁻¹, ?_, ?_, ?_⟩) fun hy hx => ⟨-a, ?_, ?_, ?_⟩) ((le_to...
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
exists_pos_variant
If `a` is any solution, then one of `a`, `a⁻¹`, `-a`, `-a⁻¹` has positive `x` and nonnegative `y`.
exists_of_not_isSquare (h₀ : 0 < d) (hd : ¬IsSquare d) : ∃ x y : ℤ, x ^ 2 - d * y ^ 2 = 1 ∧ y ≠ 0 := by let ξ : ℝ := √d have hξ : Irrational ξ := by refine irrational_nrt_of_notint_nrt 2 d (sq_sqrt <| Int.cast_nonneg.mpr h₀.le) ?_ two_pos rintro ⟨x, hx⟩ refine hd ⟨x, @Int.cast_injective ℝ _ _ d (x *...
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
exists_of_not_isSquare
If `d` is a positive integer that is not a square, then there is a nontrivial solution to the Pell equation `x^2 - d*y^2 = 1`.
exists_iff_not_isSquare (h₀ : 0 < d) : (∃ x y : ℤ, x ^ 2 - d * y ^ 2 = 1 ∧ y ≠ 0) ↔ ¬IsSquare d := by refine ⟨?_, exists_of_not_isSquare h₀⟩ rintro ⟨x, y, hxy, hy⟩ ⟨a, rfl⟩ rw [← sq, ← mul_pow, sq_sub_sq] at hxy simpa [hy, mul_self_pos.mp h₀, sub_eq_add_neg, eq_neg_self_iff] using Int.eq_of_mul_eq_one hxy
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
exists_iff_not_isSquare
If `d` is a positive integer, then there is a nontrivial solution to the Pell equation `x^2 - d*y^2 = 1` if and only if `d` is not a square.
exists_nontrivial_of_not_isSquare (h₀ : 0 < d) (hd : ¬IsSquare d) : ∃ a : Solution₁ d, a ≠ 1 ∧ a ≠ -1 := by obtain ⟨x, y, prop, hy⟩ := exists_of_not_isSquare h₀ hd refine ⟨mk x y prop, fun H => ?_, fun H => ?_⟩ <;> apply_fun Solution₁.y at H <;> simp [hy] at H
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
exists_nontrivial_of_not_isSquare
If `d` is a positive integer that is not a square, then there exists a nontrivial solution to the Pell equation `x^2 - d*y^2 = 1`.
exists_pos_of_not_isSquare (h₀ : 0 < d) (hd : ¬IsSquare d) : ∃ a : Solution₁ d, 1 < a.x ∧ 0 < a.y := by obtain ⟨x, y, h, hy⟩ := exists_of_not_isSquare h₀ hd refine ⟨mk |x| |y| (by rwa [sq_abs, sq_abs]), ?_, abs_pos.mpr hy⟩ rw [x_mk, ← one_lt_sq_iff_one_lt_abs, eq_add_of_sub_eq h, lt_add_iff_pos_right] exact...
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
exists_pos_of_not_isSquare
If `d` is a positive integer that is not a square, then there exists a solution to the Pell equation `x^2 - d*y^2 = 1` with `x > 1` and `y > 0`.
IsFundamental (a : Solution₁ d) : Prop := 1 < a.x ∧ 0 < a.y ∧ ∀ {b : Solution₁ d}, 1 < b.x → a.x ≤ b.x
def
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
IsFundamental
We define a solution to be *fundamental* if it has `x > 1` and `y > 0` and its `x` is the smallest possible among solutions with `x > 1`.
x_pos {a : Solution₁ d} (h : IsFundamental a) : 0 < a.x := zero_lt_one.trans h.1
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
x_pos
A fundamental solution has positive `x`.
d_pos {a : Solution₁ d} (h : IsFundamental a) : 0 < d := d_pos_of_one_lt_x h.1
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
d_pos
If a fundamental solution exists, then `d` must be positive.
d_nonsquare {a : Solution₁ d} (h : IsFundamental a) : ¬IsSquare d := d_nonsquare_of_one_lt_x h.1
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
d_nonsquare
If a fundamental solution exists, then `d` must be a non-square.
subsingleton {a b : Solution₁ d} (ha : IsFundamental a) (hb : IsFundamental b) : a = b := by have hx := le_antisymm (ha.2.2 hb.1) (hb.2.2 ha.1) refine Solution₁.ext hx ?_ have : d * a.y ^ 2 = d * b.y ^ 2 := by rw [a.prop_y, b.prop_y, hx] exact (sq_eq_sq₀ ha.2.1.le hb.2.1.le).mp (Int.eq_of_mul_eq_mul_left ha.d_p...
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
subsingleton
If there is a fundamental solution, it is unique.
exists_of_not_isSquare (h₀ : 0 < d) (hd : ¬IsSquare d) : ∃ a : Solution₁ d, IsFundamental a := by obtain ⟨a, ha₁, ha₂⟩ := exists_pos_of_not_isSquare h₀ hd have P : ∃ x' : ℕ, 1 < x' ∧ ∃ y' : ℤ, 0 < y' ∧ (x' : ℤ) ^ 2 - d * y' ^ 2 = 1 := by have hax := a.prop lift a.x to ℕ using by positivity with ax n...
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
exists_of_not_isSquare
If `d` is positive and not a square, then a fundamental solution exists.
y_strictMono {a : Solution₁ d} (h : IsFundamental a) : StrictMono fun n : ℤ => (a ^ n).y := by have H : ∀ n : ℤ, 0 ≤ n → (a ^ n).y < (a ^ (n + 1)).y := by intro n hn rw [← sub_pos, zpow_add, zpow_one, y_mul, add_sub_assoc] rw [show (a ^ n).y * a.x - (a ^ n).y = (a ^ n).y * (a.x - 1) by ring] refin...
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
y_strictMono
The map sending an integer `n` to the `y`-coordinate of `a^n` for a fundamental solution `a` is strictly increasing.
zpow_y_lt_iff_lt {a : Solution₁ d} (h : IsFundamental a) (m n : ℤ) : (a ^ m).y < (a ^ n).y ↔ m < n := by refine ⟨fun H => ?_, fun H => h.y_strictMono H⟩ contrapose! H exact h.y_strictMono.monotone H
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
zpow_y_lt_iff_lt
If `a` is a fundamental solution, then `(a^m).y < (a^n).y` if and only if `m < n`.
zpow_eq_one_iff {a : Solution₁ d} (h : IsFundamental a) (n : ℤ) : a ^ n = 1 ↔ n = 0 := by rw [← zpow_zero a] exact ⟨fun H => h.y_strictMono.injective (congr_arg Solution₁.y H), fun H => H ▸ rfl⟩
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
zpow_eq_one_iff
The `n`th power of a fundamental solution is trivial if and only if `n = 0`.
zpow_ne_neg_zpow {a : Solution₁ d} (h : IsFundamental a) {n n' : ℤ} : a ^ n ≠ -a ^ n' := by intro hf apply_fun Solution₁.x at hf have H := x_zpow_pos h.x_pos n rw [hf, x_neg, lt_neg, neg_zero] at H exact lt_irrefl _ ((x_zpow_pos h.x_pos n').trans H)
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
zpow_ne_neg_zpow
A power of a fundamental solution is never equal to the negative of a power of this fundamental solution.
x_le_x {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x) : a₁.x ≤ a.x := h.2.2 hax
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
x_le_x
The `x`-coordinate of a fundamental solution is a lower bound for the `x`-coordinate of any positive solution.
y_le_y {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x) (hay : 0 < a.y) : a₁.y ≤ a.y := by have H : d * (a₁.y ^ 2 - a.y ^ 2) = a₁.x ^ 2 - a.x ^ 2 := by rw [a.prop_x, a₁.prop_x]; ring rw [← abs_of_pos hay, ← abs_of_pos h.2.1, ← sq_le_sq, ← mul_le_mul_iff_right₀ h.d_pos, ← sub_nonpo...
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
y_le_y
The `y`-coordinate of a fundamental solution is a lower bound for the `y`-coordinate of any positive solution.
x_mul_y_le_y_mul_x {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x) (hay : 0 < a.y) : a.x * a₁.y ≤ a.y * a₁.x := by rw [← abs_of_pos <| zero_lt_one.trans hax, ← abs_of_pos hay, ← abs_of_pos h.x_pos, ← abs_of_pos h.2.1, ← abs_mul, ← abs_mul, ← sq_le_sq, mul_pow, mul_pow, a.prop_x, a₁...
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
x_mul_y_le_y_mul_x
null
mul_inv_y_nonneg {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x) (hay : 0 < a.y) : 0 ≤ (a * a₁⁻¹).y := by simpa only [y_inv, mul_neg, y_mul, le_neg_add_iff_add_le, add_zero] using h.x_mul_y_le_y_mul_x hax hay
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
mul_inv_y_nonneg
If we multiply a positive solution with the inverse of a fundamental solution, the `y`-coordinate remains nonnegative.
mul_inv_x_pos {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x) (hay : 0 < a.y) : 0 < (a * a₁⁻¹).x := by simp only [x_mul, x_inv, y_inv, mul_neg, lt_add_neg_iff_add_lt, zero_add] refine lt_of_mul_lt_mul_left ?_ <| zero_le_one.trans hax.le calc a.x * (d * (a.y * a₁.y)) _ = d * a.y...
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
mul_inv_x_pos
If we multiply a positive solution with the inverse of a fundamental solution, the `x`-coordinate stays positive.
mul_inv_x_lt_x {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x) (hay : 0 < a.y) : (a * a₁⁻¹).x < a.x := by simp only [x_mul, x_inv, y_inv, mul_neg, add_neg_lt_iff_le_add'] refine lt_of_mul_lt_mul_left ?_ h.2.1.le calc a₁.y * (a.x * a₁.x) _ = a.x * a₁.y * a₁.x := by ring _ ≤ ...
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
mul_inv_x_lt_x
If we multiply a positive solution with the inverse of a fundamental solution, the `x`-coordinate decreases.
eq_pow_of_nonneg {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 0 < a.x) (hay : 0 ≤ a.y) : ∃ n : ℕ, a = a₁ ^ n := by lift a.x to ℕ using hax.le with ax hax' induction ax using Nat.strong_induction_on generalizing a with | h x ih => rcases hay.eq_or_lt with hy | hy · -- case 1: `a = 1` ...
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
eq_pow_of_nonneg
Any nonnegative solution is a power with nonnegative exponent of a fundamental solution.
eq_zpow_or_neg_zpow {a₁ : Solution₁ d} (h : IsFundamental a₁) (a : Solution₁ d) : ∃ n : ℤ, a = a₁ ^ n ∨ a = -a₁ ^ n := by obtain ⟨b, hbx, hby, hb⟩ := exists_pos_variant h.d_pos a obtain ⟨n, hn⟩ := h.eq_pow_of_nonneg hbx hby rcases hb with (rfl | rfl | rfl | hb) · exact ⟨n, Or.inl (mod_cast hn)⟩ · exact ⟨-...
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
eq_zpow_or_neg_zpow
Every solution is, up to a sign, a power of a given fundamental solution.
existsUnique_pos_generator (h₀ : 0 < d) (hd : ¬IsSquare d) : ∃! a₁ : Solution₁ d, 1 < a₁.x ∧ 0 < a₁.y ∧ ∀ a : Solution₁ d, ∃ n : ℤ, a = a₁ ^ n ∨ a = -a₁ ^ n := by obtain ⟨a₁, ha₁⟩ := IsFundamental.exists_of_not_isSquare h₀ hd refine ⟨a₁, ⟨ha₁.1, ha₁.2.1, ha₁.eq_zpow_or_neg_zpow⟩, fun a (H : 1 < _ ∧ _) => ...
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
existsUnique_pos_generator
When `d` is positive and not a square, then the group of solutions to the Pell equation `x^2 - d*y^2 = 1` has a unique positive generator (up to sign).
pos_generator_iff_fundamental (a : Solution₁ d) : (1 < a.x ∧ 0 < a.y ∧ ∀ b : Solution₁ d, ∃ n : ℤ, b = a ^ n ∨ b = -a ^ n) ↔ IsFundamental a := by refine ⟨fun h => ?_, fun H => ⟨H.1, H.2.1, H.eq_zpow_or_neg_zpow⟩⟩ have h₀ := d_pos_of_one_lt_x h.1 have hd := d_nonsquare_of_one_lt_x h.1 obtain ⟨a₁, ha₁⟩ := Is...
theorem
NumberTheory
[ "Mathlib.Data.ZMod.Basic", "Mathlib.NumberTheory.DiophantineApproximation.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic", "Mathlib.Tactic.Qify" ]
Mathlib/NumberTheory/Pell.lean
pos_generator_iff_fundamental
A positive solution is a generator (up to sign) of the group of all solutions to the Pell equation `x^2 - d*y^2 = 1` if and only if it is a fundamental solution.
IsPell : ℤ√d → Prop | ⟨x, y⟩ => x * x - d * y * y = 1
def
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
IsPell
The property of being a solution to the Pell equation, expressed as a property of elements of `ℤ√d`.
isPell_norm : ∀ {b : ℤ√d}, IsPell b ↔ b * star b = 1 | ⟨x, y⟩ => by simp [Zsqrtd.ext_iff, IsPell, mul_comm]; ring_nf
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
isPell_norm
null
isPell_iff_mem_unitary : ∀ {b : ℤ√d}, IsPell b ↔ b ∈ unitary (ℤ√d) | ⟨x, y⟩ => by rw [unitary.mem_iff, isPell_norm, mul_comm (star _), and_self_iff]
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
isPell_iff_mem_unitary
null
isPell_mul {b c : ℤ√d} (hb : IsPell b) (hc : IsPell c) : IsPell (b * c) := isPell_norm.2 (by simp [mul_comm, mul_left_comm c, mul_assoc, star_mul, isPell_norm.1 hb, isPell_norm.1 hc])
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
isPell_mul
null
isPell_star : ∀ {b : ℤ√d}, IsPell b ↔ IsPell (star b) | ⟨x, y⟩ => by simp [IsPell]
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
isPell_star
null
private d (_a1 : 1 < a) := a * a - 1 @[simp]
def
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
d
null
d_pos : 0 < d a1 := tsub_pos_of_lt (mul_lt_mul a1 (le_of_lt a1) (by decide) (Nat.zero_le _) : 1 * 1 < a * a)
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
d_pos
null
xn (n : ℕ) : ℕ := (pell a1 n).1
def
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
xn
The Pell sequences, i.e. the sequence of integer solutions to `x ^ 2 - d * y ^ 2 = 1`, where `d = a ^ 2 - 1`, defined together in mutual recursion. -/ --@[nolint dup_namespace] def pell : ℕ → ℕ × ℕ | 0 => (1, 0) | n+1 => ((pell n).1 * a + d a1 * (pell n).2, (pell n).1 + (pell n).2 * a) /-- The Pell `x` sequence.
yn (n : ℕ) : ℕ := (pell a1 n).2 @[simp]
def
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
yn
The Pell `y` sequence.
pell_val (n : ℕ) : pell a1 n = (xn a1 n, yn a1 n) := show pell a1 n = ((pell a1 n).1, (pell a1 n).2) from match pell a1 n with | (_, _) => rfl @[simp]
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
pell_val
null
xn_zero : xn a1 0 = 1 := rfl @[simp]
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
xn_zero
null
yn_zero : yn a1 0 = 0 := rfl @[simp]
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
yn_zero
null
xn_succ (n : ℕ) : xn a1 (n + 1) = xn a1 n * a + d a1 * yn a1 n := rfl @[simp]
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
xn_succ
null
yn_succ (n : ℕ) : yn a1 (n + 1) = xn a1 n + yn a1 n * a := rfl
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
yn_succ
null