l3lab/ntp-mathlib huggingface dataset:
/-- Construct an initial segment from an order embedding into a well order, by collapsing it
to fill the gaps. -/
noncomputable def collapse [IsWellOrder β s] (f : r ↪r s) : r ≼i s :=
  haveI := RelEmbedding.isWellOrder f
  ⟨RelEmbedding.ofMonotone (fun a => (collapseF f a).1) fun a b => collapseF.lt f, fun a b =>
    Acc.recOn (IsWellFounded.wf.apply b : Acc s b)
      (fun b _ _ a h => by
        

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝ : IsWellOrder β s
f : r ↪r s
this : IsWellOrder α r
a✝ : α
b✝ b : β
x✝¹ : ∀ (y : β), s y b → Acc s y
x✝ :
  ∀ (y : β),
    s y b →
      ∀ (x : α),
        s y
            ((ofMonotone (fun a => ↑(collapseF f a)) (_ : ∀ (a b : α), r a b → s ↑(collapseF f a) ↑(collapseF f b)))
              x) →
          ∃ a',
            (ofMonotone (fun a => ↑(collapseF f a)) (_ : ∀ (a b : α), r a b → s ↑(collapseF f a) ↑(collapseF f b))) a' =
              y
a : α
h : s b ((ofMonotone (fun a => ↑(collapseF f a)) (_ : ∀ (a b : α), r a b → s ↑(collapseF f a) ↑(collapseF f b))) a)
⊢ ∃ a', (ofMonotone (fun a => ↑(collapseF f a)) (_ : ∀ (a b : α), r a b → s ↑(collapseF f a) ↑(collapseF f b))) a' = b

Next tactic:
rcases (@IsWellFounded.wf _ r).has_min { a | ¬s (collapseF f a).1 b }
          ⟨_, asymm h⟩ with ⟨m, hm, hm'⟩
/-- Construct an initial segment from an order embedding into a well order, by collapsing it
to fill the gaps. -/
noncomputable def collapse [IsWellOrder β s] (f : r ↪r s) : r ≼i s :=
  haveI := RelEmbedding.isWellOrder f
  ⟨RelEmbedding.ofMonotone (fun a => (collapseF f a).1) fun a b => collapseF.lt f, fun a b =>
    Acc.recOn (IsWellFounded.wf.apply b : Acc s b)
      (fun b _ _ a h => by
        rcases (@IsWellFounded.wf _ r).has_min { a | ¬s (collapseF f a).1 b }
          ⟨_, asymm h⟩ with ⟨m, hm, hm'⟩
        

Proof state:
case intro.intro
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝ : IsWellOrder β s
f : r ↪r s
this : IsWellOrder α r
a✝ : α
b✝ b : β
x✝¹ : ∀ (y : β), s y b → Acc s y
x✝ :
  ∀ (y : β),
    s y b →
      ∀ (x : α),
        s y
            ((ofMonotone (fun a => ↑(collapseF f a)) (_ : ∀ (a b : α), r a b → s ↑(collapseF f a) ↑(collapseF f b)))
              x) →
          ∃ a',
            (ofMonotone (fun a => ↑(collapseF f a)) (_ : ∀ (a b : α), r a b → s ↑(collapseF f a) ↑(collapseF f b))) a' =
              y
a : α
h : s b ((ofMonotone (fun a => ↑(collapseF f a)) (_ : ∀ (a b : α), r a b → s ↑(collapseF f a) ↑(collapseF f b))) a)
m : α
hm : m ∈ {a | ¬s (↑(collapseF f a)) b}
hm' : ∀ x ∈ {a | ¬s (↑(collapseF f a)) b}, ¬r x m
⊢ ∃ a', (ofMonotone (fun a => ↑(collapseF f a)) (_ : ∀ (a b : α), r a b → s ↑(collapseF f a) ↑(collapseF f b))) a' = b

Next tactic:
refine' ⟨m, ((@trichotomous _ s _ _ _).resolve_left hm).resolve_right
          (collapseF.not_lt f _ fun a' h' => _)⟩
/-- Construct an initial segment from an order embedding into a well order, by collapsing it
to fill the gaps. -/
noncomputable def collapse [IsWellOrder β s] (f : r ↪r s) : r ≼i s :=
  haveI := RelEmbedding.isWellOrder f
  ⟨RelEmbedding.ofMonotone (fun a => (collapseF f a).1) fun a b => collapseF.lt f, fun a b =>
    Acc.recOn (IsWellFounded.wf.apply b : Acc s b)
      (fun b _ _ a h => by
        rcases (@IsWellFounded.wf _ r).has_min { a | ¬s (collapseF f a).1 b }
          ⟨_, asymm h⟩ with ⟨m, hm, hm'⟩
        refine' ⟨m, ((@trichotomous _ s _ _ _).resolve_left hm).resolve_right
          (collapseF.not_lt f _ fun a' h' => _)⟩
        

Proof state:
case intro.intro
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝ : IsWellOrder β s
f : r ↪r s
this : IsWellOrder α r
a✝ : α
b✝ b : β
x✝¹ : ∀ (y : β), s y b → Acc s y
x✝ :
  ∀ (y : β),
    s y b →
      ∀ (x : α),
        s y
            ((ofMonotone (fun a => ↑(collapseF f a)) (_ : ∀ (a b : α), r a b → s ↑(collapseF f a) ↑(collapseF f b)))
              x) →
          ∃ a',
            (ofMonotone (fun a => ↑(collapseF f a)) (_ : ∀ (a b : α), r a b → s ↑(collapseF f a) ↑(collapseF f b))) a' =
              y
a : α
h : s b ((ofMonotone (fun a => ↑(collapseF f a)) (_ : ∀ (a b : α), r a b → s ↑(collapseF f a) ↑(collapseF f b))) a)
m : α
hm : m ∈ {a | ¬s (↑(collapseF f a)) b}
hm' : ∀ x ∈ {a | ¬s (↑(collapseF f a)) b}, ¬r x m
a' : α
h' : r a' m
⊢ s (↑(collapseF f a')) b

Next tactic:
by_contra hn
/-- Construct an initial segment from an order embedding into a well order, by collapsing it
to fill the gaps. -/
noncomputable def collapse [IsWellOrder β s] (f : r ↪r s) : r ≼i s :=
  haveI := RelEmbedding.isWellOrder f
  ⟨RelEmbedding.ofMonotone (fun a => (collapseF f a).1) fun a b => collapseF.lt f, fun a b =>
    Acc.recOn (IsWellFounded.wf.apply b : Acc s b)
      (fun b _ _ a h => by
        rcases (@IsWellFounded.wf _ r).has_min { a | ¬s (collapseF f a).1 b }
          ⟨_, asymm h⟩ with ⟨m, hm, hm'⟩
        refine' ⟨m, ((@trichotomous _ s _ _ _).resolve_left hm).resolve_right
          (collapseF.not_lt f _ fun a' h' => _)⟩
        by_contra hn
        

Proof state:
case intro.intro
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝ : IsWellOrder β s
f : r ↪r s
this : IsWellOrder α r
a✝ : α
b✝ b : β
x✝¹ : ∀ (y : β), s y b → Acc s y
x✝ :
  ∀ (y : β),
    s y b →
      ∀ (x : α),
        s y
            ((ofMonotone (fun a => ↑(collapseF f a)) (_ : ∀ (a b : α), r a b → s ↑(collapseF f a) ↑(collapseF f b)))
              x) →
          ∃ a',
            (ofMonotone (fun a => ↑(collapseF f a)) (_ : ∀ (a b : α), r a b → s ↑(collapseF f a) ↑(collapseF f b))) a' =
              y
a : α
h : s b ((ofMonotone (fun a => ↑(collapseF f a)) (_ : ∀ (a b : α), r a b → s ↑(collapseF f a) ↑(collapseF f b))) a)
m : α
hm : m ∈ {a | ¬s (↑(collapseF f a)) b}
hm' : ∀ x ∈ {a | ¬s (↑(collapseF f a)) b}, ¬r x m
a' : α
h' : r a' m
hn : ¬s (↑(collapseF f a')) b
⊢ False

Next tactic:
exact hm' _ hn h'
/-- The `p`-adic integers as a subring of `ℚ_[p]`. -/
def subring : Subring ℚ_[p] where
  carrier := { x : ℚ_[p] | ‖x‖ ≤ 1 }
  zero_mem' := by norm_num
  one_mem' := by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
⊢ 1 ∈
    { carrier := {x | ‖x‖ ≤ 1},
        mul_mem' := (_ : ∀ {a b : ℚ_[p]}, a ∈ {x | ‖x‖ ≤ 1} → b ∈ {x | ‖x‖ ≤ 1} → ‖a * b‖ ≤ 1) }.carrier

Next tactic:
norm_num
/-- The `p`-adic integers as a subring of `ℚ_[p]`. -/
def subring : Subring ℚ_[p] where
  carrier := { x : ℚ_[p] | ‖x‖ ≤ 1 }
  zero_mem' := by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
⊢ 0 ∈
    {
          toSubsemigroup :=
            { carrier := {x | ‖x‖ ≤ 1},
              mul_mem' := (_ : ∀ {a b : ℚ_[p]}, a ∈ {x | ‖x‖ ≤ 1} → b ∈ {x | ‖x‖ ≤ 1} → ‖a * b‖ ≤ 1) },
          one_mem' := (_ : ‖1‖ ≤ 1) }.toSubsemigroup.carrier

Next tactic:
norm_num
/-- Addition on `ℤ_[p]` is inherited from `ℚ_[p]`. -/
instance : Add ℤ_[p] := (by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
⊢ Add ↥(subring p)

Next tactic:
infer_instance
/-- Multiplication on `ℤ_[p]` is inherited from `ℚ_[p]`. -/
instance : Mul ℤ_[p] := (by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
⊢ Mul ↥(subring p)

Next tactic:
infer_instance
/-- Negation on `ℤ_[p]` is inherited from `ℚ_[p]`. -/
instance : Neg ℤ_[p] := (by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
⊢ Neg ↥(subring p)

Next tactic:
infer_instance
/-- Subtraction on `ℤ_[p]` is inherited from `ℚ_[p]`. -/
instance : Sub ℤ_[p] := (by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
⊢ Sub ↥(subring p)

Next tactic:
infer_instance
/-- Zero on `ℤ_[p]` is inherited from `ℚ_[p]`. -/
instance : Zero ℤ_[p] := (by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
⊢ Zero ↥(subring p)

Next tactic:
infer_instance
/-- One on `ℤ_[p]` is inherited from `ℚ_[p]`. -/
instance : One ℤ_[p] := ⟨⟨1, by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
⊢ ‖1‖ ≤ 1

Next tactic:
norm_num
theorem coe_eq_zero (z : ℤ_[p]) : (z : ℚ_[p]) = 0 ↔ z = 0 := by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
z : ℤ_[p]
⊢ ↑z = 0 ↔ z = 0

Next tactic:
rw [← coe_zero, Subtype.coe_inj]
instance : AddCommGroup ℤ_[p] := (by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
⊢ AddCommGroup ↥(subring p)

Next tactic:
infer_instance
instance instCommRing : CommRing ℤ_[p] := (by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
⊢ CommRing ↥(subring p)

Next tactic:
infer_instance
/-- The inverse of a `p`-adic integer with norm equal to `1` is also a `p`-adic integer.
Otherwise, the inverse is defined to be `0`. -/
def inv : ℤ_[p] → ℤ_[p]
  | ⟨k, _⟩ => if h : ‖k‖ = 1 then ⟨k⁻¹, by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
k : ℚ_[p]
property✝ : ‖k‖ ≤ 1
h : ‖k‖ = 1
⊢ ‖k⁻¹‖ ≤ 1

Next tactic:
simp [h]
instance : CharZero ℤ_[p] where
  cast_injective m n h := Nat.cast_injective (by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
m n : ℕ
h : ↑m = ↑n
⊢ ↑m = ↑n

Next tactic:
rw [Subtype.ext_iff] at h
instance : CharZero ℤ_[p] where
  cast_injective m n h := Nat.cast_injective (by rw [Subtype.ext_iff] at h; 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
m n : ℕ
h✝ : ↑m = ↑n
h : ↑↑m = ↑↑n
⊢ ↑m = ↑n

Next tactic:
norm_cast at h
@[norm_cast] -- @[simp] -- Porting note: not in simpNF
theorem coe_int_eq (z1 z2 : ℤ) : (z1 : ℤ_[p]) = z2 ↔ z1 = z2 := by
  

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
z1 z2 : ℤ
⊢ ↑z1 = ↑z2 ↔ z1 = z2

Next tactic:
suffices (z1 : ℚ_[p]) = z2 ↔ z1 = z2 from Iff.trans (by norm_cast) this
@[norm_cast] -- @[simp] -- Porting note: not in simpNF
theorem coe_int_eq (z1 z2 : ℤ) : (z1 : ℤ_[p]) = z2 ↔ z1 = z2 := by
  suffices (z1 : ℚ_[p]) = z2 ↔ z1 = z2 from Iff.trans (by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
z1 z2 : ℤ
this : ↑z1 = ↑z2 ↔ z1 = z2
⊢ ↑z1 = ↑z2 ↔ ↑z1 = ↑z2

Next tactic:
norm_cast
@[norm_cast] -- @[simp] -- Porting note: not in simpNF
theorem coe_int_eq (z1 z2 : ℤ) : (z1 : ℤ_[p]) = z2 ↔ z1 = z2 := by
  suffices (z1 : ℚ_[p]) = z2 ↔ z1 = z2 from Iff.trans (by norm_cast) this
  

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
z1 z2 : ℤ
⊢ ↑z1 = ↑z2 ↔ z1 = z2

Next tactic:
norm_cast
/-- A sequence of integers that is Cauchy with respect to the `p`-adic norm converges to a `p`-adic
integer. -/
def ofIntSeq (seq : ℕ → ℤ) (h : IsCauSeq (padicNorm p) fun n => seq n) : ℤ_[p] :=
  ⟨⟦⟨_, h⟩⟧,
    show ↑(PadicSeq.norm _) ≤ (1 : ℝ) by
      

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
seq : ℕ → ℤ
h : IsCauSeq (padicNorm p) fun n => ↑(seq n)
⊢ ↑(PadicSeq.norm { val := fun n => ↑(seq n), property := h }) ≤ 1

Next tactic:
rw [PadicSeq.norm]
/-- A sequence of integers that is Cauchy with respect to the `p`-adic norm converges to a `p`-adic
integer. -/
def ofIntSeq (seq : ℕ → ℤ) (h : IsCauSeq (padicNorm p) fun n => seq n) : ℤ_[p] :=
  ⟨⟦⟨_, h⟩⟧,
    show ↑(PadicSeq.norm _) ≤ (1 : ℝ) by
      rw [PadicSeq.norm]
      

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
seq : ℕ → ℤ
h : IsCauSeq (padicNorm p) fun n => ↑(seq n)
⊢ ↑(if hf : { val := fun n => ↑(seq n), property := h } ≈ 0 then 0
      else padicNorm p (↑{ val := fun n => ↑(seq n), property := h } (PadicSeq.stationaryPoint hf))) ≤
    1

Next tactic:
split_ifs with hne
/-- A sequence of integers that is Cauchy with respect to the `p`-adic norm converges to a `p`-adic
integer. -/
def ofIntSeq (seq : ℕ → ℤ) (h : IsCauSeq (padicNorm p) fun n => seq n) : ℤ_[p] :=
  ⟨⟦⟨_, h⟩⟧,
    show ↑(PadicSeq.norm _) ≤ (1 : ℝ) by
      rw [PadicSeq.norm]
      split_ifs with hne <;> 

Proof state:
case pos
p : ℕ
inst✝ : Fact (Nat.Prime p)
seq : ℕ → ℤ
h : IsCauSeq (padicNorm p) fun n => ↑(seq n)
hne : { val := fun n => ↑(seq n), property := h } ≈ 0
⊢ ↑0 ≤ 1

Next tactic:
norm_cast
/-- A sequence of integers that is Cauchy with respect to the `p`-adic norm converges to a `p`-adic
integer. -/
def ofIntSeq (seq : ℕ → ℤ) (h : IsCauSeq (padicNorm p) fun n => seq n) : ℤ_[p] :=
  ⟨⟦⟨_, h⟩⟧,
    show ↑(PadicSeq.norm _) ≤ (1 : ℝ) by
      rw [PadicSeq.norm]
      split_ifs with hne <;> 

Proof state:
case neg
p : ℕ
inst✝ : Fact (Nat.Prime p)
seq : ℕ → ℤ
h : IsCauSeq (padicNorm p) fun n => ↑(seq n)
hne : ¬{ val := fun n => ↑(seq n), property := h } ≈ 0
⊢ ↑(padicNorm p (↑{ val := fun n => ↑(seq n), property := h } (PadicSeq.stationaryPoint hne))) ≤ 1

Next tactic:
norm_cast
/-- A sequence of integers that is Cauchy with respect to the `p`-adic norm converges to a `p`-adic
integer. -/
def ofIntSeq (seq : ℕ → ℤ) (h : IsCauSeq (padicNorm p) fun n => seq n) : ℤ_[p] :=
  ⟨⟦⟨_, h⟩⟧,
    show ↑(PadicSeq.norm _) ≤ (1 : ℝ) by
      rw [PadicSeq.norm]
      split_ifs with hne <;> norm_cast
      

Proof state:
case neg
p : ℕ
inst✝ : Fact (Nat.Prime p)
seq : ℕ → ℤ
h : IsCauSeq (padicNorm p) fun n => ↑(seq n)
hne : ¬{ val := fun n => ↑(seq n), property := h } ≈ 0
⊢ padicNorm p (↑{ val := fun n => ↑(seq n), property := h } (PadicSeq.stationaryPoint hne)) ≤ 1

Next tactic:
apply padicNorm.of_int
instance : NormedCommRing ℤ_[p] :=
  { PadicInt.instCommRing with
    dist_eq := fun ⟨_, _⟩ ⟨_, _⟩ => rfl
    norm_mul := by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
src✝ : CommRing ℤ_[p] := instCommRing
⊢ ∀ (a b : ℤ_[p]), ‖a * b‖ ≤ ‖a‖ * ‖b‖

Next tactic:
simp [norm_def]
instance isAbsoluteValue : IsAbsoluteValue fun z : ℤ_[p] => ‖z‖ where
  abv_nonneg' := norm_nonneg
  abv_eq_zero' := by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
⊢ ∀ {x : ℤ_[p]}, ‖x‖ = 0 ↔ x = 0

Next tactic:
simp [norm_eq_zero]
instance isAbsoluteValue : IsAbsoluteValue fun z : ℤ_[p] => ‖z‖ where
  abv_nonneg' := norm_nonneg
  abv_eq_zero' := by simp [norm_eq_zero]
  abv_add' := fun ⟨_, _⟩ ⟨_, _⟩ => norm_add_le _ _
  abv_mul' _ _ := by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
x✝¹ x✝ : ℤ_[p]
⊢ ‖x✝¹ * x✝‖ = ‖x✝¹‖ * ‖x✝‖

Next tactic:
simp only [norm_def, padicNormE.mul, PadicInt.coe_mul]
@[simp]
theorem norm_mul (z1 z2 : ℤ_[p]) : ‖z1 * z2‖ = ‖z1‖ * ‖z2‖ := by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
z1 z2 : ℤ_[p]
⊢ ‖z1 * z2‖ = ‖z1‖ * ‖z2‖

Next tactic:
simp [norm_def]
@[simp]
theorem norm_pow (z : ℤ_[p]) : ∀ n : ℕ, ‖z ^ n‖ = ‖z‖ ^ n
  | 0 => by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
z : ℤ_[p]
⊢ ‖z ^ 0‖ = ‖z‖ ^ 0

Next tactic:
simp
@[simp]
theorem norm_pow (z : ℤ_[p]) : ∀ n : ℕ, ‖z ^ n‖ = ‖z‖ ^ n
  | 0 => by simp
  | k + 1 => by
    

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
z : ℤ_[p]
k : ℕ
⊢ ‖z ^ (k + 1)‖ = ‖z‖ ^ (k + 1)

Next tactic:
rw [pow_succ, pow_succ, norm_mul]
@[simp]
theorem norm_pow (z : ℤ_[p]) : ∀ n : ℕ, ‖z ^ n‖ = ‖z‖ ^ n
  | 0 => by simp
  | k + 1 => by
    rw [pow_succ, pow_succ, norm_mul]
    

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
z : ℤ_[p]
k : ℕ
⊢ ‖z‖ * ‖z ^ k‖ = ‖z‖ * ‖z‖ ^ k

Next tactic:
congr
@[simp]
theorem norm_pow (z : ℤ_[p]) : ∀ n : ℕ, ‖z ^ n‖ = ‖z‖ ^ n
  | 0 => by simp
  | k + 1 => by
    rw [pow_succ, pow_succ, norm_mul]
    congr
    

Proof state:
case e_a
p : ℕ
inst✝ : Fact (Nat.Prime p)
z : ℤ_[p]
k : ℕ
⊢ ‖z ^ k‖ = ‖z‖ ^ k

Next tactic:
apply norm_pow
theorem norm_eq_of_norm_add_lt_right {z1 z2 : ℤ_[p]} (h : ‖z1 + z2‖ < ‖z2‖) : ‖z1‖ = ‖z2‖ :=
  by_contra fun hne =>
    not_lt_of_ge (by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
z1 z2 : ℤ_[p]
h : ‖z1 + z2‖ < ‖z2‖
hne : ¬‖z1‖ = ‖z2‖
⊢ ‖z1 + z2‖ ≥ ‖z2‖

Next tactic:
rw [norm_add_eq_max_of_ne hne]
theorem norm_eq_of_norm_add_lt_right {z1 z2 : ℤ_[p]} (h : ‖z1 + z2‖ < ‖z2‖) : ‖z1‖ = ‖z2‖ :=
  by_contra fun hne =>
    not_lt_of_ge (by rw [norm_add_eq_max_of_ne hne]; 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
z1 z2 : ℤ_[p]
h : ‖z1 + z2‖ < ‖z2‖
hne : ¬‖z1‖ = ‖z2‖
⊢ max ‖z1‖ ‖z2‖ ≥ ‖z2‖

Next tactic:
apply le_max_right
theorem norm_eq_of_norm_add_lt_left {z1 z2 : ℤ_[p]} (h : ‖z1 + z2‖ < ‖z1‖) : ‖z1‖ = ‖z2‖ :=
  by_contra fun hne =>
    not_lt_of_ge (by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
z1 z2 : ℤ_[p]
h : ‖z1 + z2‖ < ‖z1‖
hne : ¬‖z1‖ = ‖z2‖
⊢ ‖z1 + z2‖ ≥ ‖z1‖

Next tactic:
rw [norm_add_eq_max_of_ne hne]
theorem norm_eq_of_norm_add_lt_left {z1 z2 : ℤ_[p]} (h : ‖z1 + z2‖ < ‖z1‖) : ‖z1‖ = ‖z2‖ :=
  by_contra fun hne =>
    not_lt_of_ge (by rw [norm_add_eq_max_of_ne hne]; 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
z1 z2 : ℤ_[p]
h : ‖z1 + z2‖ < ‖z1‖
hne : ¬‖z1‖ = ‖z2‖
⊢ max ‖z1‖ ‖z2‖ ≥ ‖z1‖

Next tactic:
apply le_max_left
@[simp]
theorem padic_norm_e_of_padicInt (z : ℤ_[p]) : ‖(z : ℚ_[p])‖ = ‖z‖ := by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
z : ℤ_[p]
⊢ ‖↑z‖ = ‖z‖

Next tactic:
simp [norm_def]
theorem norm_int_cast_eq_padic_norm (z : ℤ) : ‖(z : ℤ_[p])‖ = ‖(z : ℚ_[p])‖ := by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
z : ℤ
⊢ ‖↑z‖ = ‖↑z‖

Next tactic:
simp [norm_def]
private def cauSeq_to_rat_cauSeq (f : CauSeq ℤ_[p] norm) : CauSeq ℚ_[p] fun a => ‖a‖ :=
  ⟨fun n => f n, fun _ hε => by 

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
f : CauSeq ℤ_[p] norm
x✝ : ℝ
hε : x✝ > 0
⊢ ∃ i, ∀ j ≥ i, (fun a => ‖a‖) ((fun n => ↑(↑f n)) j - (fun n => ↑(↑f n)) i) < x✝

Next tactic:
simpa [norm, norm_def] using f.cauchy hε
instance complete : CauSeq.IsComplete ℤ_[p] norm :=
  ⟨fun f =>
    have hqn : ‖CauSeq.lim (cauSeq_to_rat_cauSeq f)‖ ≤ 1 :=
      padicNormE_lim_le zero_lt_one fun _ => norm_le_one _
    ⟨⟨_, hqn⟩, fun ε => by
      

Proof state:
p : ℕ
inst✝ : Fact (Nat.Prime p)
f : CauSeq ℤ_[p] norm
hqn : ‖CauSeq.lim (PadicInt.cauSeq_to_rat_cauSeq f)‖ ≤ 1
ε : ℝ
⊢ ε > 0 →
    ∃ i,
      ∀ j ≥ i, ‖↑(f - CauSeq.const norm { val := CauSeq.lim (PadicInt.cauSeq_to_rat_cauSeq f), property := hqn }) j‖ < ε

Next tactic:
simpa [norm, norm_def] using CauSeq.equiv_lim (cauSeq_to_rat_cauSeq f) ε
theorem exists_pow_neg_lt {ε : ℝ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℝ) ^ (-(k : ℤ)) < ε := by
  

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
ε : ℝ
hε : 0 < ε
⊢ ∃ k, ↑p ^ (-↑k) < ε

Next tactic:
obtain ⟨k, hk⟩ := exists_nat_gt ε⁻¹
theorem exists_pow_neg_lt {ε : ℝ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℝ) ^ (-(k : ℤ)) < ε := by
  obtain ⟨k, hk⟩ := exists_nat_gt ε⁻¹
  

Proof state:
case intro
p : ℕ
hp : Fact (Nat.Prime p)
ε : ℝ
hε : 0 < ε
k : ℕ
hk : ε⁻¹ < ↑k
⊢ ∃ k, ↑p ^ (-↑k) < ε

Next tactic:
use k
theorem exists_pow_neg_lt {ε : ℝ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℝ) ^ (-(k : ℤ)) < ε := by
  obtain ⟨k, hk⟩ := exists_nat_gt ε⁻¹
  use k
  

Proof state:
case h
p : ℕ
hp : Fact (Nat.Prime p)
ε : ℝ
hε : 0 < ε
k : ℕ
hk : ε⁻¹ < ↑k
⊢ ↑p ^ (-↑k) < ε

Next tactic:
rw [← inv_lt_inv hε (_root_.zpow_pos_of_pos _ _)]
theorem exists_pow_neg_lt {ε : ℝ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℝ) ^ (-(k : ℤ)) < ε := by
  obtain ⟨k, hk⟩ := exists_nat_gt ε⁻¹
  use k
  rw [← inv_lt_inv hε (_root_.zpow_pos_of_pos _ _)]
  · 

Proof state:
case h
p : ℕ
hp : Fact (Nat.Prime p)
ε : ℝ
hε : 0 < ε
k : ℕ
hk : ε⁻¹ < ↑k
⊢ ε⁻¹ < (↑p ^ (-↑k))⁻¹

Next tactic:
rw [zpow_neg, inv_inv, zpow_ofNat]
theorem exists_pow_neg_lt {ε : ℝ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℝ) ^ (-(k : ℤ)) < ε := by
  obtain ⟨k, hk⟩ := exists_nat_gt ε⁻¹
  use k
  rw [← inv_lt_inv hε (_root_.zpow_pos_of_pos _ _)]
  · rw [zpow_neg, inv_inv, zpow_ofNat]
    

Proof state:
case h
p : ℕ
hp : Fact (Nat.Prime p)
ε : ℝ
hε : 0 < ε
k : ℕ
hk : ε⁻¹ < ↑k
⊢ ε⁻¹ < ↑p ^ k

Next tactic:
apply lt_of_lt_of_le hk
theorem exists_pow_neg_lt {ε : ℝ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℝ) ^ (-(k : ℤ)) < ε := by
  obtain ⟨k, hk⟩ := exists_nat_gt ε⁻¹
  use k
  rw [← inv_lt_inv hε (_root_.zpow_pos_of_pos _ _)]
  · rw [zpow_neg, inv_inv, zpow_ofNat]
    apply lt_of_lt_of_le hk
    

Proof state:
case h
p : ℕ
hp : Fact (Nat.Prime p)
ε : ℝ
hε : 0 < ε
k : ℕ
hk : ε⁻¹ < ↑k
⊢ ↑k ≤ ↑p ^ k

Next tactic:
norm_cast
theorem exists_pow_neg_lt {ε : ℝ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℝ) ^ (-(k : ℤ)) < ε := by
  obtain ⟨k, hk⟩ := exists_nat_gt ε⁻¹
  use k
  rw [← inv_lt_inv hε (_root_.zpow_pos_of_pos _ _)]
  · rw [zpow_neg, inv_inv, zpow_ofNat]
    apply lt_of_lt_of_le hk
    norm_cast
    

Proof state:
case h
p : ℕ
hp : Fact (Nat.Prime p)
ε : ℝ
hε : 0 < ε
k : ℕ
hk : ε⁻¹ < ↑k
⊢ k ≤ p ^ k

Next tactic:
apply le_of_lt
theorem exists_pow_neg_lt {ε : ℝ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℝ) ^ (-(k : ℤ)) < ε := by
  obtain ⟨k, hk⟩ := exists_nat_gt ε⁻¹
  use k
  rw [← inv_lt_inv hε (_root_.zpow_pos_of_pos _ _)]
  · rw [zpow_neg, inv_inv, zpow_ofNat]
    apply lt_of_lt_of_le hk
    norm_cast
    apply le_of_lt
    

Proof state:
case h.a
p : ℕ
hp : Fact (Nat.Prime p)
ε : ℝ
hε : 0 < ε
k : ℕ
hk : ε⁻¹ < ↑k
⊢ k < p ^ k

Next tactic:
convert Nat.lt_pow_self _ _ using 1
theorem exists_pow_neg_lt {ε : ℝ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℝ) ^ (-(k : ℤ)) < ε := by
  obtain ⟨k, hk⟩ := exists_nat_gt ε⁻¹
  use k
  rw [← inv_lt_inv hε (_root_.zpow_pos_of_pos _ _)]
  · rw [zpow_neg, inv_inv, zpow_ofNat]
    apply lt_of_lt_of_le hk
    norm_cast
    apply le_of_lt
    convert Nat.lt_pow_self _ _ using 1
    

Proof state:
case h.a.convert_2
p : ℕ
hp : Fact (Nat.Prime p)
ε : ℝ
hε : 0 < ε
k : ℕ
hk : ε⁻¹ < ↑k
⊢ 1 < p

Next tactic:
exact hp.1.one_lt
theorem exists_pow_neg_lt {ε : ℝ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℝ) ^ (-(k : ℤ)) < ε := by
  obtain ⟨k, hk⟩ := exists_nat_gt ε⁻¹
  use k
  rw [← inv_lt_inv hε (_root_.zpow_pos_of_pos _ _)]
  · rw [zpow_neg, inv_inv, zpow_ofNat]
    apply lt_of_lt_of_le hk
    norm_cast
    apply le_of_lt
    convert Nat.lt_pow_self _ _ using 1
    exact hp.1.one_lt
  · 

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
ε : ℝ
hε : 0 < ε
k : ℕ
hk : ε⁻¹ < ↑k
⊢ 0 < ↑p

Next tactic:
exact mod_cast hp.1.pos
theorem exists_pow_neg_lt_rat {ε : ℚ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℚ) ^ (-(k : ℤ)) < ε := by
  

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
ε : ℚ
hε : 0 < ε
⊢ ∃ k, ↑p ^ (-↑k) < ε

Next tactic:
obtain ⟨k, hk⟩ := @exists_pow_neg_lt p _ ε (mod_cast hε)
theorem exists_pow_neg_lt_rat {ε : ℚ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℚ) ^ (-(k : ℤ)) < ε := by
  obtain ⟨k, hk⟩ := @exists_pow_neg_lt p _ ε (mod_cast hε)
  

Proof state:
case intro
p : ℕ
hp : Fact (Nat.Prime p)
ε : ℚ
hε : 0 < ε
k : ℕ
hk : ↑p ^ (-↑k) < ↑ε
⊢ ∃ k, ↑p ^ (-↑k) < ε

Next tactic:
use k
theorem exists_pow_neg_lt_rat {ε : ℚ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℚ) ^ (-(k : ℤ)) < ε := by
  obtain ⟨k, hk⟩ := @exists_pow_neg_lt p _ ε (mod_cast hε)
  use k
  

Proof state:
case h
p : ℕ
hp : Fact (Nat.Prime p)
ε : ℚ
hε : 0 < ε
k : ℕ
hk : ↑p ^ (-↑k) < ↑ε
⊢ ↑p ^ (-↑k) < ε

Next tactic:
rw [show (p : ℝ) = (p : ℚ) by simp] at hk
theorem exists_pow_neg_lt_rat {ε : ℚ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℚ) ^ (-(k : ℤ)) < ε := by
  obtain ⟨k, hk⟩ := @exists_pow_neg_lt p _ ε (mod_cast hε)
  use k
  rw [show (p : ℝ) = (p : ℚ) by 

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
ε : ℚ
hε : 0 < ε
k : ℕ
hk : ↑p ^ (-↑k) < ↑ε
⊢ ↑p = ↑↑p

Next tactic:
simp
theorem exists_pow_neg_lt_rat {ε : ℚ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℚ) ^ (-(k : ℤ)) < ε := by
  obtain ⟨k, hk⟩ := @exists_pow_neg_lt p _ ε (mod_cast hε)
  use k
  rw [show (p : ℝ) = (p : ℚ) by simp] at hk
  

Proof state:
case h
p : ℕ
hp : Fact (Nat.Prime p)
ε : ℚ
hε : 0 < ε
k : ℕ
hk : ↑↑p ^ (-↑k) < ↑ε
⊢ ↑p ^ (-↑k) < ε

Next tactic:
exact mod_cast hk
theorem norm_int_lt_one_iff_dvd (k : ℤ) : ‖(k : ℤ_[p])‖ < 1 ↔ (p : ℤ) ∣ k :=
  suffices ‖(k : ℚ_[p])‖ < 1 ↔ ↑p ∣ k by 

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
k : ℤ
this : ‖↑k‖ < 1 ↔ ↑p ∣ k
⊢ ‖↑k‖ < 1 ↔ ↑p ∣ k

Next tactic:
rwa [norm_int_cast_eq_padic_norm]
theorem norm_int_le_pow_iff_dvd {k : ℤ} {n : ℕ} :
    ‖(k : ℤ_[p])‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ (p ^ n : ℤ) ∣ k :=
  suffices ‖(k : ℚ_[p])‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ (p ^ n : ℤ) ∣ k by
    

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
k : ℤ
n : ℕ
this : ‖↑k‖ ≤ ↑p ^ (-↑n) ↔ ↑p ^ n ∣ k
⊢ ‖↑k‖ ≤ ↑p ^ (-↑n) ↔ ↑p ^ n ∣ k

Next tactic:
simpa [norm_int_cast_eq_padic_norm]
theorem norm_eq_pow_val {x : ℤ_[p]} (hx : x ≠ 0) : ‖x‖ = (p : ℝ) ^ (-x.valuation) := by
  

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

Next tactic:
refine @Padic.norm_eq_pow_val p hp x ?_
theorem norm_eq_pow_val {x : ℤ_[p]} (hx : x ≠ 0) : ‖x‖ = (p : ℝ) ^ (-x.valuation) := by
  refine @Padic.norm_eq_pow_val p hp x ?_
  

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

Next tactic:
contrapose! hx
theorem norm_eq_pow_val {x : ℤ_[p]} (hx : x ≠ 0) : ‖x‖ = (p : ℝ) ^ (-x.valuation) := by
  refine @Padic.norm_eq_pow_val p hp x ?_
  contrapose! hx
  

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

Next tactic:
exact Subtype.val_injective hx
@[simp]
theorem valuation_p : valuation (p : ℤ_[p]) = 1 := by 

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
⊢ valuation ↑p = 1

Next tactic:
simp [valuation]
theorem valuation_nonneg (x : ℤ_[p]) : 0 ≤ x.valuation := by
  

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

Next tactic:
by_cases hx : x = 0
theorem valuation_nonneg (x : ℤ_[p]) : 0 ≤ x.valuation := by
  by_cases hx : x = 0
  · 

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

Next tactic:
simp [hx]