Theorem: PadicInt.exists_mem_range
File: Mathlib/NumberTheory/Padics/RingHoms.lean

tactic: simp only [maximalIdeal_eq_span_p, Ideal.mem_span_singleton, ← norm_lt_one_iff_dvd]
state_before: p : ℕ
hp_prime : Fact (Nat.Prime p)
r : ℚ
x : ℤ_[p]
⊢ ∃ n, n < p ∧ x - ↑n ∈ maximalIdeal ℤ_[p]

tactic: obtain ⟨r, hr⟩ := rat_dense p (x : ℚ_[p]) zero_lt_one
state_before: p : ℕ
hp_prime : Fact (Nat.Prime p)
r : ℚ
x : ℤ_[p]
⊢ ∃ n, n < p ∧ ‖x - ↑n‖ < 1

tactic: have H : ‖(r : ℚ_[p])‖ ≤ 1 := by
  rw [norm_sub_rev] at hr
  calc
    _ = ‖(r : ℚ_[p]) - x + x‖ := by ring_nf
    _ ≤ _ := padicNormE.nonarchimedean _ _
    _ ≤ _ := max_le (le_of_lt hr) x.2
state_before: case intro
p : ℕ
hp_prime : Fact (Nat.Prime p)
r✝ : ℚ
x : ℤ_[p]
r : ℚ
hr : ‖↑x - ↑r‖ < 1
⊢ ∃ n, n < p ∧ ‖x - ↑n‖ < 1

tactic: obtain ⟨n, hzn, hnp, hn⟩ := exists_mem_range_of_norm_rat_le_one r H
state_before: case intro
p : ℕ
hp_prime : Fact (Nat.Prime p)
r✝ : ℚ
x : ℤ_[p]
r : ℚ
hr : ‖↑x - ↑r‖ < 1
H : ‖↑r‖ ≤ 1
⊢ ∃ n, n < p ∧ ‖x - ↑n‖ < 1

tactic: lift n to ℕ using hzn
state_before: case intro.intro.intro.intro
p : ℕ
hp_prime : Fact (Nat.Prime p)
r✝ : ℚ
x : ℤ_[p]
r : ℚ
hr : ‖↑x - ↑r‖ < 1
H : ‖↑r‖ ≤ 1
n : ℤ
hzn : 0 ≤ n
hnp : n < ↑p
hn : ‖{ val := ↑r, property := H } - ↑n‖ < 1
⊢ ∃ n, n < p ∧ ‖x - ↑n‖ < 1

tactic: use n
state_before: case intro.intro.intro.intro.intro
p : ℕ
hp_prime : Fact (Nat.Prime p)
r✝ : ℚ
x : ℤ_[p]
r : ℚ
hr : ‖↑x - ↑r‖ < 1
H : ‖↑r‖ ≤ 1
n : ℕ
hnp : ↑n < ↑p
hn : ‖{ val := ↑r, property := H } - ↑↑n‖ < 1
⊢ ∃ n, n < p ∧ ‖x - ↑n‖ < 1

tactic: constructor
state_before: case intro.intro.intro.intro.intro
p : ℕ
hp_prime : Fact (Nat.Prime p)
r✝ : ℚ
x : ℤ_[p]
r : ℚ
hr : ‖↑x - ↑r‖ < 1
H : ‖↑r‖ ≤ 1
n : ℕ
hnp : ↑n < ↑p
hn : ‖{ val := ↑r, property := H } - ↑↑n‖ < 1
⊢ n < p ∧ ‖x - ↑n‖ < 1

tactic: simp only [norm_def, coe_sub, Subtype.coe_mk, coe_nat_cast] at hn⊢
state_before: case intro.intro.intro.intro.intro.right
p : ℕ
hp_prime : Fact (Nat.Prime p)
r✝ : ℚ
x : ℤ_[p]
r : ℚ
hr : ‖↑x - ↑r‖ < 1
H : ‖↑r‖ ≤ 1
n : ℕ
hnp : ↑n < ↑p
hn : ‖{ val := ↑r, property := H } - ↑↑n‖ < 1
⊢ ‖x - ↑n‖ < 1

tactic: rw [show (x - n : ℚ_[p]) = x - r + (r - n) by ring]
state_before: case intro.intro.intro.intro.intro.right
p : ℕ
hp_prime : Fact (Nat.Prime p)
r✝ : ℚ
x : ℤ_[p]
r : ℚ
hr : ‖↑x - ↑r‖ < 1
H : ‖↑r‖ ≤ 1
n : ℕ
hnp : ↑n < ↑p
hn : ‖↑r - ↑↑↑n‖ < 1
⊢ ‖↑x - ↑n‖ < 1

tactic: apply lt_of_le_of_lt (padicNormE.nonarchimedean _ _)
state_before: case intro.intro.intro.intro.intro.right
p : ℕ
hp_prime : Fact (Nat.Prime p)
r✝ : ℚ
x : ℤ_[p]
r : ℚ
hr : ‖↑x - ↑r‖ < 1
H : ‖↑r‖ ≤ 1
n : ℕ
hnp : ↑n < ↑p
hn : ‖↑r - ↑↑↑n‖ < 1
⊢ ‖↑x - ↑r + (↑r - ↑n)‖ < 1

tactic: apply max_lt hr
state_before: case intro.intro.intro.intro.intro.right
p : ℕ
hp_prime : Fact (Nat.Prime p)
r✝ : ℚ
x : ℤ_[p]
r : ℚ
hr : ‖↑x - ↑r‖ < 1
H : ‖↑r‖ ≤ 1
n : ℕ
hnp : ↑n < ↑p
hn : ‖↑r - ↑↑↑n‖ < 1
⊢ max ‖↑x - ↑r‖ ‖↑r - ↑n‖ < 1

tactic: simpa using hn
state_before: case intro.intro.intro.intro.intro.right
p : ℕ
hp_prime : Fact (Nat.Prime p)
r✝ : ℚ
x : ℤ_[p]
r : ℚ
hr : ‖↑x - ↑r‖ < 1
H : ‖↑r‖ ≤ 1
n : ℕ
hnp : ↑n < ↑p
hn : ‖↑r - ↑↑↑n‖ < 1
⊢ ‖↑r - ↑n‖ < 1

tactic: rw [norm_sub_rev] at hr
state_before: p : ℕ
hp_prime : Fact (Nat.Prime p)
r✝ : ℚ
x : ℤ_[p]
r : ℚ
hr : ‖↑x - ↑r‖ < 1
⊢ ‖↑r‖ ≤ 1

tactic: calc
  _ = ‖(r : ℚ_[p]) - x + x‖ := by ring_nf
  _ ≤ _ := padicNormE.nonarchimedean _ _
  _ ≤ _ := max_le (le_of_lt hr) x.2
state_before: p : ℕ
hp_prime : Fact (Nat.Prime p)
r✝ : ℚ
x : ℤ_[p]
r : ℚ
hr : ‖↑r - ↑x‖ < 1
⊢ ‖↑r‖ ≤ 1

tactic: ring_nf
state_before: p : ℕ
hp_prime : Fact (Nat.Prime p)
r✝ : ℚ
x : ℤ_[p]
r : ℚ
hr : ‖↑r - ↑x‖ < 1
⊢ ‖↑r‖ = ‖↑r - ↑x + ↑x‖

tactic: exact_mod_cast hnp
state_before: case intro.intro.intro.intro.intro.left
p : ℕ
hp_prime : Fact (Nat.Prime p)
r✝ : ℚ
x : ℤ_[p]
r : ℚ
hr : ‖↑x - ↑r‖ < 1
H : ‖↑r‖ ≤ 1
n : ℕ
hnp : ↑n < ↑p
hn : ‖{ val := ↑r, property := H } - ↑↑n‖ < 1
⊢ n < p

tactic: ring
state_before: p : ℕ
hp_prime : Fact (Nat.Prime p)
r✝ : ℚ
x : ℤ_[p]
r : ℚ
hr : ‖↑x - ↑r‖ < 1
H : ‖↑r‖ ≤ 1
n : ℕ
hnp : ↑n < ↑p
hn : ‖↑r - ↑↑↑n‖ < 1
⊢ ↑x - ↑n = ↑x - ↑r + (↑r - ↑n)