l3lab/ntp-mathlib huggingface dataset:
theorem valuation_nonneg (x : ℤ_[p]) : 0 ≤ x.valuation := by
  by_cases hx : x = 0
  · simp [hx]
  

Proof state:
case neg
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : ¬x = 0
⊢ 0 ≤ valuation x

Next tactic:
have h : (1 : ℝ) < p := mod_cast hp.1.one_lt
theorem valuation_nonneg (x : ℤ_[p]) : 0 ≤ x.valuation := by
  by_cases hx : x = 0
  · simp [hx]
  have h : (1 : ℝ) < p := mod_cast hp.1.one_lt
  

Proof state:
case neg
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : ¬x = 0
h : 1 < ↑p
⊢ 0 ≤ valuation x

Next tactic:
rw [← neg_nonpos, ← (zpow_strictMono h).le_iff_le]
theorem valuation_nonneg (x : ℤ_[p]) : 0 ≤ x.valuation := by
  by_cases hx : x = 0
  · simp [hx]
  have h : (1 : ℝ) < p := mod_cast hp.1.one_lt
  rw [← neg_nonpos, ← (zpow_strictMono h).le_iff_le]
  

Proof state:
case neg
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : ¬x = 0
h : 1 < ↑p
⊢ ↑p ^ (-valuation x) ≤ ↑p ^ 0

Next tactic:
show (p : ℝ) ^ (-valuation x) ≤ (p : ℝ) ^ (0 : ℤ)
theorem valuation_nonneg (x : ℤ_[p]) : 0 ≤ x.valuation := by
  by_cases hx : x = 0
  · simp [hx]
  have h : (1 : ℝ) < p := mod_cast hp.1.one_lt
  rw [← neg_nonpos, ← (zpow_strictMono h).le_iff_le]
  show (p : ℝ) ^ (-valuation x) ≤ (p : ℝ) ^ (0 : ℤ)
  

Proof state:
case neg
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : ¬x = 0
h : 1 < ↑p
⊢ ↑p ^ (-valuation x) ≤ ↑p ^ 0

Next tactic:
rw [← norm_eq_pow_val hx]
theorem valuation_nonneg (x : ℤ_[p]) : 0 ≤ x.valuation := by
  by_cases hx : x = 0
  · simp [hx]
  have h : (1 : ℝ) < p := mod_cast hp.1.one_lt
  rw [← neg_nonpos, ← (zpow_strictMono h).le_iff_le]
  show (p : ℝ) ^ (-valuation x) ≤ (p : ℝ) ^ (0 : ℤ)
  rw [← norm_eq_pow_val hx]
  

Proof state:
case neg
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : ¬x = 0
h : 1 < ↑p
⊢ ‖x‖ ≤ ↑p ^ 0

Next tactic:
simpa using x.property
@[simp]
theorem valuation_p_pow_mul (n : ℕ) (c : ℤ_[p]) (hc : c ≠ 0) :
    ((p : ℤ_[p]) ^ n * c).valuation = n + c.valuation := by
  

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
c : ℤ_[p]
hc : c ≠ 0
⊢ valuation (↑p ^ n * c) = ↑n + valuation c

Next tactic:
have : ‖(p : ℤ_[p]) ^ n * c‖ = ‖(p : ℤ_[p]) ^ n‖ * ‖c‖ := norm_mul _ _
@[simp]
theorem valuation_p_pow_mul (n : ℕ) (c : ℤ_[p]) (hc : c ≠ 0) :
    ((p : ℤ_[p]) ^ n * c).valuation = n + c.valuation := by
  have : ‖(p : ℤ_[p]) ^ n * c‖ = ‖(p : ℤ_[p]) ^ n‖ * ‖c‖ := norm_mul _ _
  

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
c : ℤ_[p]
hc : c ≠ 0
this : ‖↑p ^ n * c‖ = ‖↑p ^ n‖ * ‖c‖
⊢ valuation (↑p ^ n * c) = ↑n + valuation c

Next tactic:
have aux : (p : ℤ_[p]) ^ n * c ≠ 0 := by
    contrapose! hc
    rw [mul_eq_zero] at hc
    cases' hc with hc hc
    · refine (hp.1.ne_zero ?_).elim
      exact_mod_cast pow_eq_zero hc
    · exact hc
@[simp]
theorem valuation_p_pow_mul (n : ℕ) (c : ℤ_[p]) (hc : c ≠ 0) :
    ((p : ℤ_[p]) ^ n * c).valuation = n + c.valuation := by
  have : ‖(p : ℤ_[p]) ^ n * c‖ = ‖(p : ℤ_[p]) ^ n‖ * ‖c‖ := norm_mul _ _
  have aux : (p : ℤ_[p]) ^ n * c ≠ 0 := by
    

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
c : ℤ_[p]
hc : c ≠ 0
this : ‖↑p ^ n * c‖ = ‖↑p ^ n‖ * ‖c‖
⊢ ↑p ^ n * c ≠ 0

Next tactic:
contrapose! hc
@[simp]
theorem valuation_p_pow_mul (n : ℕ) (c : ℤ_[p]) (hc : c ≠ 0) :
    ((p : ℤ_[p]) ^ n * c).valuation = n + c.valuation := by
  have : ‖(p : ℤ_[p]) ^ n * c‖ = ‖(p : ℤ_[p]) ^ n‖ * ‖c‖ := norm_mul _ _
  have aux : (p : ℤ_[p]) ^ n * c ≠ 0 := by
    contrapose! hc
    

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
c : ℤ_[p]
this : ‖↑p ^ n * c‖ = ‖↑p ^ n‖ * ‖c‖
hc : ↑p ^ n * c = 0
⊢ c = 0

Next tactic:
rw [mul_eq_zero] at hc
@[simp]
theorem valuation_p_pow_mul (n : ℕ) (c : ℤ_[p]) (hc : c ≠ 0) :
    ((p : ℤ_[p]) ^ n * c).valuation = n + c.valuation := by
  have : ‖(p : ℤ_[p]) ^ n * c‖ = ‖(p : ℤ_[p]) ^ n‖ * ‖c‖ := norm_mul _ _
  have aux : (p : ℤ_[p]) ^ n * c ≠ 0 := by
    contrapose! hc
    rw [mul_eq_zero] at hc
    

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
c : ℤ_[p]
this : ‖↑p ^ n * c‖ = ‖↑p ^ n‖ * ‖c‖
hc : ↑p ^ n = 0 ∨ c = 0
⊢ c = 0

Next tactic:
cases' hc with hc hc
@[simp]
theorem valuation_p_pow_mul (n : ℕ) (c : ℤ_[p]) (hc : c ≠ 0) :
    ((p : ℤ_[p]) ^ n * c).valuation = n + c.valuation := by
  have : ‖(p : ℤ_[p]) ^ n * c‖ = ‖(p : ℤ_[p]) ^ n‖ * ‖c‖ := norm_mul _ _
  have aux : (p : ℤ_[p]) ^ n * c ≠ 0 := by
    contrapose! hc
    rw [mul_eq_zero] at hc
    cases' hc with hc hc
    · 

Proof state:
case inl
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
c : ℤ_[p]
this : ‖↑p ^ n * c‖ = ‖↑p ^ n‖ * ‖c‖
hc : ↑p ^ n = 0
⊢ c = 0

Next tactic:
refine (hp.1.ne_zero ?_).elim
@[simp]
theorem valuation_p_pow_mul (n : ℕ) (c : ℤ_[p]) (hc : c ≠ 0) :
    ((p : ℤ_[p]) ^ n * c).valuation = n + c.valuation := by
  have : ‖(p : ℤ_[p]) ^ n * c‖ = ‖(p : ℤ_[p]) ^ n‖ * ‖c‖ := norm_mul _ _
  have aux : (p : ℤ_[p]) ^ n * c ≠ 0 := by
    contrapose! hc
    rw [mul_eq_zero] at hc
    cases' hc with hc hc
    · refine (hp.1.ne_zero ?_).elim
      

Proof state:
case inl
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
c : ℤ_[p]
this : ‖↑p ^ n * c‖ = ‖↑p ^ n‖ * ‖c‖
hc : ↑p ^ n = 0
⊢ p = 0

Next tactic:
exact_mod_cast pow_eq_zero hc
@[simp]
theorem valuation_p_pow_mul (n : ℕ) (c : ℤ_[p]) (hc : c ≠ 0) :
    ((p : ℤ_[p]) ^ n * c).valuation = n + c.valuation := by
  have : ‖(p : ℤ_[p]) ^ n * c‖ = ‖(p : ℤ_[p]) ^ n‖ * ‖c‖ := norm_mul _ _
  have aux : (p : ℤ_[p]) ^ n * c ≠ 0 := by
    contrapose! hc
    rw [mul_eq_zero] at hc
    cases' hc with hc hc
    · refine (hp.1.ne_zero ?_).elim
      exact_mod_cast pow_eq_zero hc
    · 

Proof state:
case inr
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
c : ℤ_[p]
this : ‖↑p ^ n * c‖ = ‖↑p ^ n‖ * ‖c‖
hc : c = 0
⊢ c = 0

Next tactic:
exact hc
@[simp]
theorem valuation_p_pow_mul (n : ℕ) (c : ℤ_[p]) (hc : c ≠ 0) :
    ((p : ℤ_[p]) ^ n * c).valuation = n + c.valuation := by
  have : ‖(p : ℤ_[p]) ^ n * c‖ = ‖(p : ℤ_[p]) ^ n‖ * ‖c‖ := norm_mul _ _
  have aux : (p : ℤ_[p]) ^ n * c ≠ 0 := by
    contrapose! hc
    rw [mul_eq_zero] at hc
    cases' hc with hc hc
    · refine (hp.1.ne_zero ?_).elim
      exact_mod_cast pow_eq_zero hc
    · exact hc
  

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
c : ℤ_[p]
hc : c ≠ 0
this : ‖↑p ^ n * c‖ = ‖↑p ^ n‖ * ‖c‖
aux : ↑p ^ n * c ≠ 0
⊢ valuation (↑p ^ n * c) = ↑n + valuation c

Next tactic:
rwa [norm_eq_pow_val aux, norm_p_pow, norm_eq_pow_val hc, ← zpow_add₀, ← neg_add,
    zpow_inj, neg_inj] at this
@[simp]
theorem valuation_p_pow_mul (n : ℕ) (c : ℤ_[p]) (hc : c ≠ 0) :
    ((p : ℤ_[p]) ^ n * c).valuation = n + c.valuation := by
  have : ‖(p : ℤ_[p]) ^ n * c‖ = ‖(p : ℤ_[p]) ^ n‖ * ‖c‖ := norm_mul _ _
  have aux : (p : ℤ_[p]) ^ n * c ≠ 0 := by
    contrapose! hc
    rw [mul_eq_zero] at hc
    cases' hc with hc hc
    · refine (hp.1.ne_zero ?_).elim
      exact_mod_cast pow_eq_zero hc
    · exact hc
  rwa [norm_eq_pow_val aux, norm_p_pow, norm_eq_pow_val hc, ← zpow_add₀, ← neg_add,
    zpow_inj, neg_inj] at this
  · 

Proof state:
case h₀
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
c : ℤ_[p]
hc : c ≠ 0
this : ↑p ^ (-valuation (↑p ^ n * c)) = ↑p ^ (-(↑n + valuation c))
aux : ↑p ^ n * c ≠ 0
⊢ 0 < ↑p

Next tactic:
exact mod_cast hp.1.pos
@[simp]
theorem valuation_p_pow_mul (n : ℕ) (c : ℤ_[p]) (hc : c ≠ 0) :
    ((p : ℤ_[p]) ^ n * c).valuation = n + c.valuation := by
  have : ‖(p : ℤ_[p]) ^ n * c‖ = ‖(p : ℤ_[p]) ^ n‖ * ‖c‖ := norm_mul _ _
  have aux : (p : ℤ_[p]) ^ n * c ≠ 0 := by
    contrapose! hc
    rw [mul_eq_zero] at hc
    cases' hc with hc hc
    · refine (hp.1.ne_zero ?_).elim
      exact_mod_cast pow_eq_zero hc
    · exact hc
  rwa [norm_eq_pow_val aux, norm_p_pow, norm_eq_pow_val hc, ← zpow_add₀, ← neg_add,
    zpow_inj, neg_inj] at this
  · exact mod_cast hp.1.pos
  · 

Proof state:
case h₁
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
c : ℤ_[p]
hc : c ≠ 0
this : ↑p ^ (-valuation (↑p ^ n * c)) = ↑p ^ (-(↑n + valuation c))
aux : ↑p ^ n * c ≠ 0
⊢ ↑p ≠ 1

Next tactic:
exact mod_cast hp.1.ne_one
@[simp]
theorem valuation_p_pow_mul (n : ℕ) (c : ℤ_[p]) (hc : c ≠ 0) :
    ((p : ℤ_[p]) ^ n * c).valuation = n + c.valuation := by
  have : ‖(p : ℤ_[p]) ^ n * c‖ = ‖(p : ℤ_[p]) ^ n‖ * ‖c‖ := norm_mul _ _
  have aux : (p : ℤ_[p]) ^ n * c ≠ 0 := by
    contrapose! hc
    rw [mul_eq_zero] at hc
    cases' hc with hc hc
    · refine (hp.1.ne_zero ?_).elim
      exact_mod_cast pow_eq_zero hc
    · exact hc
  rwa [norm_eq_pow_val aux, norm_p_pow, norm_eq_pow_val hc, ← zpow_add₀, ← neg_add,
    zpow_inj, neg_inj] at this
  · exact mod_cast hp.1.pos
  · exact mod_cast hp.1.ne_one
  · 

Proof state:
case ha
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
c : ℤ_[p]
hc : c ≠ 0
this : ↑p ^ (-valuation (↑p ^ n * c)) = ↑p ^ (-↑n) * ↑p ^ (-valuation c)
aux : ↑p ^ n * c ≠ 0
⊢ ↑p ≠ 0

Next tactic:
exact mod_cast hp.1.ne_zero
theorem mul_inv : ∀ {z : ℤ_[p]}, ‖z‖ = 1 → z * z.inv = 1
  | ⟨k, _⟩, h => by
    

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
k : ℚ_[p]
property✝ : ‖k‖ ≤ 1
h : ‖{ val := k, property := property✝ }‖ = 1
⊢ { val := k, property := property✝ } * inv { val := k, property := property✝ } = 1

Next tactic:
have hk : k ≠ 0 := fun h' => zero_ne_one' ℚ_[p] (by simp [h'] at h)
theorem mul_inv : ∀ {z : ℤ_[p]}, ‖z‖ = 1 → z * z.inv = 1
  | ⟨k, _⟩, h => by
    have hk : k ≠ 0 := fun h' => zero_ne_one' ℚ_[p] (by 

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
k : ℚ_[p]
property✝ : ‖k‖ ≤ 1
h : ‖{ val := k, property := property✝ }‖ = 1
h' : k = 0
⊢ 0 = 1

Next tactic:
simp [h'] at h
theorem mul_inv : ∀ {z : ℤ_[p]}, ‖z‖ = 1 → z * z.inv = 1
  | ⟨k, _⟩, h => by
    have hk : k ≠ 0 := fun h' => zero_ne_one' ℚ_[p] (by simp [h'] at h)
    

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
k : ℚ_[p]
property✝ : ‖k‖ ≤ 1
h : ‖{ val := k, property := property✝ }‖ = 1
hk : k ≠ 0
⊢ { val := k, property := property✝ } * inv { val := k, property := property✝ } = 1

Next tactic:
unfold PadicInt.inv
theorem mul_inv : ∀ {z : ℤ_[p]}, ‖z‖ = 1 → z * z.inv = 1
  | ⟨k, _⟩, h => by
    have hk : k ≠ 0 := fun h' => zero_ne_one' ℚ_[p] (by simp [h'] at h)
    unfold PadicInt.inv
    

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
k : ℚ_[p]
property✝ : ‖k‖ ≤ 1
h : ‖{ val := k, property := property✝ }‖ = 1
hk : k ≠ 0
⊢ ({ val := k, property := property✝ } *
      match { val := k, property := property✝ } with
      | { val := k, property := property } => if h : ‖k‖ = 1 then { val := k⁻¹, property := (_ : ‖k⁻¹‖ ≤ 1) } else 0) =
    1

Next tactic:
rw [norm_eq_padic_norm] at h
theorem mul_inv : ∀ {z : ℤ_[p]}, ‖z‖ = 1 → z * z.inv = 1
  | ⟨k, _⟩, h => by
    have hk : k ≠ 0 := fun h' => zero_ne_one' ℚ_[p] (by simp [h'] at h)
    unfold PadicInt.inv
    rw [norm_eq_padic_norm] at h
    

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
k : ℚ_[p]
property✝ : ‖k‖ ≤ 1
h : ‖k‖ = 1
hk : k ≠ 0
⊢ ({ val := k, property := property✝ } *
      match { val := k, property := property✝ } with
      | { val := k, property := property } => if h : ‖k‖ = 1 then { val := k⁻¹, property := (_ : ‖k⁻¹‖ ≤ 1) } else 0) =
    1

Next tactic:
dsimp only
theorem mul_inv : ∀ {z : ℤ_[p]}, ‖z‖ = 1 → z * z.inv = 1
  | ⟨k, _⟩, h => by
    have hk : k ≠ 0 := fun h' => zero_ne_one' ℚ_[p] (by simp [h'] at h)
    unfold PadicInt.inv
    rw [norm_eq_padic_norm] at h
    dsimp only
    

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
k : ℚ_[p]
property✝ : ‖k‖ ≤ 1
h : ‖k‖ = 1
hk : k ≠ 0
⊢ ({ val := k, property := property✝ } * if h : ‖k‖ = 1 then { val := k⁻¹, property := (_ : ‖k⁻¹‖ ≤ 1) } else 0) = 1

Next tactic:
rw [dif_pos h]
theorem mul_inv : ∀ {z : ℤ_[p]}, ‖z‖ = 1 → z * z.inv = 1
  | ⟨k, _⟩, h => by
    have hk : k ≠ 0 := fun h' => zero_ne_one' ℚ_[p] (by simp [h'] at h)
    unfold PadicInt.inv
    rw [norm_eq_padic_norm] at h
    dsimp only
    rw [dif_pos h]
    

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
k : ℚ_[p]
property✝ : ‖k‖ ≤ 1
h : ‖k‖ = 1
hk : k ≠ 0
⊢ { val := k, property := property✝ } * { val := k⁻¹, property := (_ : ‖k⁻¹‖ ≤ 1) } = 1

Next tactic:
apply Subtype.ext_iff_val.2
theorem mul_inv : ∀ {z : ℤ_[p]}, ‖z‖ = 1 → z * z.inv = 1
  | ⟨k, _⟩, h => by
    have hk : k ≠ 0 := fun h' => zero_ne_one' ℚ_[p] (by simp [h'] at h)
    unfold PadicInt.inv
    rw [norm_eq_padic_norm] at h
    dsimp only
    rw [dif_pos h]
    apply Subtype.ext_iff_val.2
    

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
k : ℚ_[p]
property✝ : ‖k‖ ≤ 1
h : ‖k‖ = 1
hk : k ≠ 0
⊢ ↑({ val := k, property := property✝ } * { val := k⁻¹, property := (_ : ‖k⁻¹‖ ≤ 1) }) = ↑1

Next tactic:
simp [mul_inv_cancel hk]
theorem inv_mul {z : ℤ_[p]} (hz : ‖z‖ = 1) : z.inv * z = 1 := by 

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
z : ℤ_[p]
hz : ‖z‖ = 1
⊢ inv z * z = 1

Next tactic:
rw [mul_comm, mul_inv hz]
theorem isUnit_iff {z : ℤ_[p]} : IsUnit z ↔ ‖z‖ = 1 :=
  ⟨fun h => by
    

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
z : ℤ_[p]
h : IsUnit z
⊢ ‖z‖ = 1

Next tactic:
rcases isUnit_iff_dvd_one.1 h with ⟨w, eq⟩
theorem isUnit_iff {z : ℤ_[p]} : IsUnit z ↔ ‖z‖ = 1 :=
  ⟨fun h => by
    rcases isUnit_iff_dvd_one.1 h with ⟨w, eq⟩
    

Proof state:
case intro
p : ℕ
hp : Fact (Nat.Prime p)
z : ℤ_[p]
h : IsUnit z
w : ℤ_[p]
eq : 1 = z * w
⊢ ‖z‖ = 1

Next tactic:
refine' le_antisymm (norm_le_one _) _
theorem isUnit_iff {z : ℤ_[p]} : IsUnit z ↔ ‖z‖ = 1 :=
  ⟨fun h => by
    rcases isUnit_iff_dvd_one.1 h with ⟨w, eq⟩
    refine' le_antisymm (norm_le_one _) _
    

Proof state:
case intro
p : ℕ
hp : Fact (Nat.Prime p)
z : ℤ_[p]
h : IsUnit z
w : ℤ_[p]
eq : 1 = z * w
⊢ 1 ≤ ‖z‖

Next tactic:
have := mul_le_mul_of_nonneg_left (norm_le_one w) (norm_nonneg z)
theorem isUnit_iff {z : ℤ_[p]} : IsUnit z ↔ ‖z‖ = 1 :=
  ⟨fun h => by
    rcases isUnit_iff_dvd_one.1 h with ⟨w, eq⟩
    refine' le_antisymm (norm_le_one _) _
    have := mul_le_mul_of_nonneg_left (norm_le_one w) (norm_nonneg z)
    

Proof state:
case intro
p : ℕ
hp : Fact (Nat.Prime p)
z : ℤ_[p]
h : IsUnit z
w : ℤ_[p]
eq : 1 = z * w
this : ‖z‖ * ‖w‖ ≤ ‖z‖ * 1
⊢ 1 ≤ ‖z‖

Next tactic:
rwa [mul_one, ← norm_mul, ← eq, norm_one] at this
theorem norm_lt_one_mul {z1 z2 : ℤ_[p]} (hz2 : ‖z2‖ < 1) : ‖z1 * z2‖ < 1 :=
  calc
    ‖z1 * z2‖ = ‖z1‖ * ‖z2‖ := by 

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
z1 z2 : ℤ_[p]
hz2 : ‖z2‖ < 1
⊢ ‖z1 * z2‖ = ‖z1‖ * ‖z2‖

Next tactic:
simp
theorem mem_nonunits {z : ℤ_[p]} : z ∈ nonunits ℤ_[p] ↔ ‖z‖ < 1 := by
  

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
z : ℤ_[p]
⊢ z ∈ nonunits ℤ_[p] ↔ ‖z‖ < 1

Next tactic:
rw [lt_iff_le_and_ne]
theorem mem_nonunits {z : ℤ_[p]} : z ∈ nonunits ℤ_[p] ↔ ‖z‖ < 1 := by
  rw [lt_iff_le_and_ne]; 

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
z : ℤ_[p]
⊢ z ∈ nonunits ℤ_[p] ↔ ‖z‖ ≤ 1 ∧ ‖z‖ ≠ 1

Next tactic:
simp [norm_le_one z, nonunits, isUnit_iff]
@[simp]
theorem norm_units (u : ℤ_[p]ˣ) : ‖(u : ℤ_[p])‖ = 1 := isUnit_iff.mp <| by 

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
u : ℤ_[p]ˣ
⊢ IsUnit ↑u

Next tactic:
simp
/-- `unitCoeff hx` is the unit `u` in the unique representation `x = u * p ^ n`.
See `unitCoeff_spec`. -/
def unitCoeff {x : ℤ_[p]} (hx : x ≠ 0) : ℤ_[p]ˣ :=
  let u : ℚ_[p] := x * (p : ℚ_[p]) ^ (-x.valuation)
  have hu : ‖u‖ = 1 := by
    

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : x ≠ 0
u : ℚ_[p] := ↑x * ↑p ^ (-valuation x)
⊢ ‖u‖ = 1

Next tactic:
simp [hx, Nat.zpow_ne_zero_of_pos (mod_cast hp.1.pos) x.valuation, norm_eq_pow_val,
      zpow_neg, inv_mul_cancel]
theorem unitCoeff_spec {x : ℤ_[p]} (hx : x ≠ 0) :
    x = (unitCoeff hx : ℤ_[p]) * (p : ℤ_[p]) ^ Int.natAbs (valuation x) := by
  

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : x ≠ 0
⊢ x = ↑(unitCoeff hx) * ↑p ^ Int.natAbs (valuation x)

Next tactic:
apply Subtype.coe_injective
theorem unitCoeff_spec {x : ℤ_[p]} (hx : x ≠ 0) :
    x = (unitCoeff hx : ℤ_[p]) * (p : ℤ_[p]) ^ Int.natAbs (valuation x) := by
  apply Subtype.coe_injective
  

Proof state:
case a
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : x ≠ 0
⊢ (fun a => ↑a) x = (fun a => ↑a) (↑(unitCoeff hx) * ↑p ^ Int.natAbs (valuation x))

Next tactic:
push_cast
theorem unitCoeff_spec {x : ℤ_[p]} (hx : x ≠ 0) :
    x = (unitCoeff hx : ℤ_[p]) * (p : ℤ_[p]) ^ Int.natAbs (valuation x) := by
  apply Subtype.coe_injective
  push_cast
  

Proof state:
case a
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : x ≠ 0
⊢ ↑x = ↑↑(unitCoeff hx) * ↑p ^ Int.natAbs (valuation x)

Next tactic:
have repr : (x : ℚ_[p]) = unitCoeff hx * (p : ℚ_[p]) ^ x.valuation := by
    rw [unitCoeff_coe, mul_assoc, ← zpow_add₀]
    · simp
    · exact mod_cast hp.1.ne_zero
theorem unitCoeff_spec {x : ℤ_[p]} (hx : x ≠ 0) :
    x = (unitCoeff hx : ℤ_[p]) * (p : ℤ_[p]) ^ Int.natAbs (valuation x) := by
  apply Subtype.coe_injective
  push_cast
  have repr : (x : ℚ_[p]) = unitCoeff hx * (p : ℚ_[p]) ^ x.valuation := by
    

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : x ≠ 0
⊢ ↑x = ↑↑(unitCoeff hx) * ↑p ^ valuation x

Next tactic:
rw [unitCoeff_coe, mul_assoc, ← zpow_add₀]
theorem unitCoeff_spec {x : ℤ_[p]} (hx : x ≠ 0) :
    x = (unitCoeff hx : ℤ_[p]) * (p : ℤ_[p]) ^ Int.natAbs (valuation x) := by
  apply Subtype.coe_injective
  push_cast
  have repr : (x : ℚ_[p]) = unitCoeff hx * (p : ℚ_[p]) ^ x.valuation := by
    rw [unitCoeff_coe, mul_assoc, ← zpow_add₀]
    · 

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : x ≠ 0
⊢ ↑x = ↑x * ↑p ^ (-valuation x + valuation x)

Next tactic:
simp
theorem unitCoeff_spec {x : ℤ_[p]} (hx : x ≠ 0) :
    x = (unitCoeff hx : ℤ_[p]) * (p : ℤ_[p]) ^ Int.natAbs (valuation x) := by
  apply Subtype.coe_injective
  push_cast
  have repr : (x : ℚ_[p]) = unitCoeff hx * (p : ℚ_[p]) ^ x.valuation := by
    rw [unitCoeff_coe, mul_assoc, ← zpow_add₀]
    · simp
    · 

Proof state:
case ha
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : x ≠ 0
⊢ ↑p ≠ 0

Next tactic:
exact mod_cast hp.1.ne_zero
theorem unitCoeff_spec {x : ℤ_[p]} (hx : x ≠ 0) :
    x = (unitCoeff hx : ℤ_[p]) * (p : ℤ_[p]) ^ Int.natAbs (valuation x) := by
  apply Subtype.coe_injective
  push_cast
  have repr : (x : ℚ_[p]) = unitCoeff hx * (p : ℚ_[p]) ^ x.valuation := by
    rw [unitCoeff_coe, mul_assoc, ← zpow_add₀]
    · simp
    · exact mod_cast hp.1.ne_zero
  

Proof state:
case a
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : x ≠ 0
repr : ↑x = ↑↑(unitCoeff hx) * ↑p ^ valuation x
⊢ ↑x = ↑↑(unitCoeff hx) * ↑p ^ Int.natAbs (valuation x)

Next tactic:
convert repr using 2
theorem unitCoeff_spec {x : ℤ_[p]} (hx : x ≠ 0) :
    x = (unitCoeff hx : ℤ_[p]) * (p : ℤ_[p]) ^ Int.natAbs (valuation x) := by
  apply Subtype.coe_injective
  push_cast
  have repr : (x : ℚ_[p]) = unitCoeff hx * (p : ℚ_[p]) ^ x.valuation := by
    rw [unitCoeff_coe, mul_assoc, ← zpow_add₀]
    · simp
    · exact mod_cast hp.1.ne_zero
  convert repr using 2
  

Proof state:
case h.e'_3.h.e'_6
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : x ≠ 0
repr : ↑x = ↑↑(unitCoeff hx) * ↑p ^ valuation x
⊢ ↑p ^ Int.natAbs (valuation x) = ↑p ^ valuation x

Next tactic:
rw [← zpow_ofNat, Int.natAbs_of_nonneg (valuation_nonneg x)]
theorem norm_le_pow_iff_le_valuation (x : ℤ_[p]) (hx : x ≠ 0) (n : ℕ) :
    ‖x‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ ↑n ≤ x.valuation := by
  

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : x ≠ 0
n : ℕ
⊢ ‖x‖ ≤ ↑p ^ (-↑n) ↔ ↑n ≤ valuation x

Next tactic:
rw [norm_eq_pow_val hx]
theorem norm_le_pow_iff_le_valuation (x : ℤ_[p]) (hx : x ≠ 0) (n : ℕ) :
    ‖x‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ ↑n ≤ x.valuation := by
  rw [norm_eq_pow_val hx]
  

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : x ≠ 0
n : ℕ
⊢ ↑p ^ (-valuation x) ≤ ↑p ^ (-↑n) ↔ ↑n ≤ valuation x

Next tactic:
lift x.valuation to ℕ using x.valuation_nonneg with k
theorem norm_le_pow_iff_le_valuation (x : ℤ_[p]) (hx : x ≠ 0) (n : ℕ) :
    ‖x‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ ↑n ≤ x.valuation := by
  rw [norm_eq_pow_val hx]
  lift x.valuation to ℕ using x.valuation_nonneg with k
  

Proof state:
case intro
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : x ≠ 0
n k : ℕ
⊢ ↑p ^ (-↑k) ≤ ↑p ^ (-↑n) ↔ ↑n ≤ ↑k

Next tactic:
simp only [Int.ofNat_le, zpow_neg, zpow_ofNat]
theorem norm_le_pow_iff_le_valuation (x : ℤ_[p]) (hx : x ≠ 0) (n : ℕ) :
    ‖x‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ ↑n ≤ x.valuation := by
  rw [norm_eq_pow_val hx]
  lift x.valuation to ℕ using x.valuation_nonneg with k
  simp only [Int.ofNat_le, zpow_neg, zpow_ofNat]
  

Proof state:
case intro
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : x ≠ 0
n k : ℕ
⊢ (↑p ^ k)⁻¹ ≤ (↑p ^ n)⁻¹ ↔ n ≤ k

Next tactic:
have aux : ∀ m : ℕ, 0 < (p : ℝ) ^ m := by
    intro m
    refine pow_pos ?_ m
    exact mod_cast hp.1.pos
theorem norm_le_pow_iff_le_valuation (x : ℤ_[p]) (hx : x ≠ 0) (n : ℕ) :
    ‖x‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ ↑n ≤ x.valuation := by
  rw [norm_eq_pow_val hx]
  lift x.valuation to ℕ using x.valuation_nonneg with k
  simp only [Int.ofNat_le, zpow_neg, zpow_ofNat]
  have aux : ∀ m : ℕ, 0 < (p : ℝ) ^ m := by
    

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : x ≠ 0
n k : ℕ
⊢ ∀ (m : ℕ), 0 < ↑p ^ m

Next tactic:
intro m
theorem norm_le_pow_iff_le_valuation (x : ℤ_[p]) (hx : x ≠ 0) (n : ℕ) :
    ‖x‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ ↑n ≤ x.valuation := by
  rw [norm_eq_pow_val hx]
  lift x.valuation to ℕ using x.valuation_nonneg with k
  simp only [Int.ofNat_le, zpow_neg, zpow_ofNat]
  have aux : ∀ m : ℕ, 0 < (p : ℝ) ^ m := by
    intro m
    

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : x ≠ 0
n k m : ℕ
⊢ 0 < ↑p ^ m

Next tactic:
refine pow_pos ?_ m
theorem norm_le_pow_iff_le_valuation (x : ℤ_[p]) (hx : x ≠ 0) (n : ℕ) :
    ‖x‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ ↑n ≤ x.valuation := by
  rw [norm_eq_pow_val hx]
  lift x.valuation to ℕ using x.valuation_nonneg with k
  simp only [Int.ofNat_le, zpow_neg, zpow_ofNat]
  have aux : ∀ m : ℕ, 0 < (p : ℝ) ^ m := by
    intro m
    refine pow_pos ?_ m
    

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : x ≠ 0
n k m : ℕ
⊢ 0 < ↑p

Next tactic:
exact mod_cast hp.1.pos
theorem norm_le_pow_iff_le_valuation (x : ℤ_[p]) (hx : x ≠ 0) (n : ℕ) :
    ‖x‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ ↑n ≤ x.valuation := by
  rw [norm_eq_pow_val hx]
  lift x.valuation to ℕ using x.valuation_nonneg with k
  simp only [Int.ofNat_le, zpow_neg, zpow_ofNat]
  have aux : ∀ m : ℕ, 0 < (p : ℝ) ^ m := by
    intro m
    refine pow_pos ?_ m
    exact mod_cast hp.1.pos
  

Proof state:
case intro
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : x ≠ 0
n k : ℕ
aux : ∀ (m : ℕ), 0 < ↑p ^ m
⊢ (↑p ^ k)⁻¹ ≤ (↑p ^ n)⁻¹ ↔ n ≤ k

Next tactic:
rw [inv_le_inv (aux _) (aux _)]
theorem norm_le_pow_iff_le_valuation (x : ℤ_[p]) (hx : x ≠ 0) (n : ℕ) :
    ‖x‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ ↑n ≤ x.valuation := by
  rw [norm_eq_pow_val hx]
  lift x.valuation to ℕ using x.valuation_nonneg with k
  simp only [Int.ofNat_le, zpow_neg, zpow_ofNat]
  have aux : ∀ m : ℕ, 0 < (p : ℝ) ^ m := by
    intro m
    refine pow_pos ?_ m
    exact mod_cast hp.1.pos
  rw [inv_le_inv (aux _) (aux _)]
  

Proof state:
case intro
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : x ≠ 0
n k : ℕ
aux : ∀ (m : ℕ), 0 < ↑p ^ m
⊢ ↑p ^ n ≤ ↑p ^ k ↔ n ≤ k

Next tactic:
have : p ^ n ≤ p ^ k ↔ n ≤ k := (pow_right_strictMono hp.1.one_lt).le_iff_le
theorem norm_le_pow_iff_le_valuation (x : ℤ_[p]) (hx : x ≠ 0) (n : ℕ) :
    ‖x‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ ↑n ≤ x.valuation := by
  rw [norm_eq_pow_val hx]
  lift x.valuation to ℕ using x.valuation_nonneg with k
  simp only [Int.ofNat_le, zpow_neg, zpow_ofNat]
  have aux : ∀ m : ℕ, 0 < (p : ℝ) ^ m := by
    intro m
    refine pow_pos ?_ m
    exact mod_cast hp.1.pos
  rw [inv_le_inv (aux _) (aux _)]
  have : p ^ n ≤ p ^ k ↔ n ≤ k := (pow_right_strictMono hp.1.one_lt).le_iff_le
  

Proof state:
case intro
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : x ≠ 0
n k : ℕ
aux : ∀ (m : ℕ), 0 < ↑p ^ m
this : p ^ n ≤ p ^ k ↔ n ≤ k
⊢ ↑p ^ n ≤ ↑p ^ k ↔ n ≤ k

Next tactic:
rw [← this]
theorem norm_le_pow_iff_le_valuation (x : ℤ_[p]) (hx : x ≠ 0) (n : ℕ) :
    ‖x‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ ↑n ≤ x.valuation := by
  rw [norm_eq_pow_val hx]
  lift x.valuation to ℕ using x.valuation_nonneg with k
  simp only [Int.ofNat_le, zpow_neg, zpow_ofNat]
  have aux : ∀ m : ℕ, 0 < (p : ℝ) ^ m := by
    intro m
    refine pow_pos ?_ m
    exact mod_cast hp.1.pos
  rw [inv_le_inv (aux _) (aux _)]
  have : p ^ n ≤ p ^ k ↔ n ≤ k := (pow_right_strictMono hp.1.one_lt).le_iff_le
  rw [← this]
  

Proof state:
case intro
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : x ≠ 0
n k : ℕ
aux : ∀ (m : ℕ), 0 < ↑p ^ m
this : p ^ n ≤ p ^ k ↔ n ≤ k
⊢ ↑p ^ n ≤ ↑p ^ k ↔ p ^ n ≤ p ^ k

Next tactic:
norm_cast
theorem mem_span_pow_iff_le_valuation (x : ℤ_[p]) (hx : x ≠ 0) (n : ℕ) :
    x ∈ (Ideal.span {(p : ℤ_[p]) ^ n} : Ideal ℤ_[p]) ↔ ↑n ≤ x.valuation := by
  

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
x : ℤ_[p]
hx : x ≠ 0
n : ℕ
⊢ x ∈ Ideal.span {↑p ^ n} ↔ ↑n ≤ valuation x

Next tactic:
rw [Ideal.mem_span_singleton]