l3lab/ntp-mathlib huggingface dataset:
theorem continuousOn_dslope (h : s ∈ 𝓝 a) :
    ContinuousOn (dslope f a) s ↔ ContinuousOn f s ∧ DifferentiableAt 𝕜 f a := by
  

Proof state:
𝕜 : Type u_1
E : Type u_2
inst✝² : NontriviallyNormedField 𝕜
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f : 𝕜 → E
a b : 𝕜
s : Set 𝕜
h : s ∈ 𝓝 a
⊢ ContinuousOn (dslope f a) s ↔ ContinuousOn f s ∧ DifferentiableAt 𝕜 f a

Next tactic:
refine' ⟨fun hc => ⟨hc.of_dslope, continuousAt_dslope_same.1 <| hc.continuousAt h⟩, _⟩
theorem continuousOn_dslope (h : s ∈ 𝓝 a) :
    ContinuousOn (dslope f a) s ↔ ContinuousOn f s ∧ DifferentiableAt 𝕜 f a := by
  refine' ⟨fun hc => ⟨hc.of_dslope, continuousAt_dslope_same.1 <| hc.continuousAt h⟩, _⟩
  

Proof state:
𝕜 : Type u_1
E : Type u_2
inst✝² : NontriviallyNormedField 𝕜
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f : 𝕜 → E
a b : 𝕜
s : Set 𝕜
h : s ∈ 𝓝 a
⊢ ContinuousOn f s ∧ DifferentiableAt 𝕜 f a → ContinuousOn (dslope f a) s

Next tactic:
rintro ⟨hc, hd⟩ x hx
theorem continuousOn_dslope (h : s ∈ 𝓝 a) :
    ContinuousOn (dslope f a) s ↔ ContinuousOn f s ∧ DifferentiableAt 𝕜 f a := by
  refine' ⟨fun hc => ⟨hc.of_dslope, continuousAt_dslope_same.1 <| hc.continuousAt h⟩, _⟩
  rintro ⟨hc, hd⟩ x hx
  

Proof state:
case intro
𝕜 : Type u_1
E : Type u_2
inst✝² : NontriviallyNormedField 𝕜
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f : 𝕜 → E
a b : 𝕜
s : Set 𝕜
h : s ∈ 𝓝 a
hc : ContinuousOn f s
hd : DifferentiableAt 𝕜 f a
x : 𝕜
hx : x ∈ s
⊢ ContinuousWithinAt (dslope f a) s x

Next tactic:
rcases eq_or_ne x a with (rfl | hne)
theorem continuousOn_dslope (h : s ∈ 𝓝 a) :
    ContinuousOn (dslope f a) s ↔ ContinuousOn f s ∧ DifferentiableAt 𝕜 f a := by
  refine' ⟨fun hc => ⟨hc.of_dslope, continuousAt_dslope_same.1 <| hc.continuousAt h⟩, _⟩
  rintro ⟨hc, hd⟩ x hx
  rcases eq_or_ne x a with (rfl | hne)
  

Proof state:
case intro.inl
𝕜 : Type u_1
E : Type u_2
inst✝² : NontriviallyNormedField 𝕜
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f : 𝕜 → E
b : 𝕜
s : Set 𝕜
hc : ContinuousOn f s
x : 𝕜
hx : x ∈ s
h : s ∈ 𝓝 x
hd : DifferentiableAt 𝕜 f x
⊢ ContinuousWithinAt (dslope f x) s x
case intro.inr
𝕜 : Type u_1
E : Type u_2
inst✝² : NontriviallyNormedField 𝕜
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f : 𝕜 → E
a b : 𝕜
s : Set 𝕜
h : s ∈ 𝓝 a
hc : ContinuousOn f s
hd : DifferentiableAt 𝕜 f a
x : 𝕜
hx : x ∈ s
hne : x ≠ a
⊢ ContinuousWithinAt (dslope f a) s x

Next tactic:
exacts [(continuousAt_dslope_same.2 hd).continuousWithinAt,
    (continuousWithinAt_dslope_of_ne hne).2 (hc x hx)]
theorem DifferentiableWithinAt.of_dslope (h : DifferentiableWithinAt 𝕜 (dslope f a) s b) :
    DifferentiableWithinAt 𝕜 f s b := by
  

Proof state:
𝕜 : Type u_1
E : Type u_2
inst✝² : NontriviallyNormedField 𝕜
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f : 𝕜 → E
a b : 𝕜
s : Set 𝕜
h : DifferentiableWithinAt 𝕜 (dslope f a) s b
⊢ DifferentiableWithinAt 𝕜 f s b

Next tactic:
simpa only [id, sub_smul_dslope f a, sub_add_cancel] using
    ((differentiableWithinAt_id.sub_const a).smul h).add_const (f a)
theorem differentiableWithinAt_dslope_of_ne (h : b ≠ a) :
    DifferentiableWithinAt 𝕜 (dslope f a) s b ↔ DifferentiableWithinAt 𝕜 f s b := by
  

Proof state:
𝕜 : Type u_1
E : Type u_2
inst✝² : NontriviallyNormedField 𝕜
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f : 𝕜 → E
a b : 𝕜
s : Set 𝕜
h : b ≠ a
⊢ DifferentiableWithinAt 𝕜 (dslope f a) s b ↔ DifferentiableWithinAt 𝕜 f s b

Next tactic:
refine' ⟨DifferentiableWithinAt.of_dslope, fun hd => _⟩
theorem differentiableWithinAt_dslope_of_ne (h : b ≠ a) :
    DifferentiableWithinAt 𝕜 (dslope f a) s b ↔ DifferentiableWithinAt 𝕜 f s b := by
  refine' ⟨DifferentiableWithinAt.of_dslope, fun hd => _⟩
  

Proof state:
𝕜 : Type u_1
E : Type u_2
inst✝² : NontriviallyNormedField 𝕜
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f : 𝕜 → E
a b : 𝕜
s : Set 𝕜
h : b ≠ a
hd : DifferentiableWithinAt 𝕜 f s b
⊢ DifferentiableWithinAt 𝕜 (dslope f a) s b

Next tactic:
refine' (((differentiableWithinAt_id.sub_const a).inv (sub_ne_zero.2 h)).smul
    (hd.sub_const (f a))).congr_of_eventuallyEq _ (dslope_of_ne _ h)
theorem differentiableWithinAt_dslope_of_ne (h : b ≠ a) :
    DifferentiableWithinAt 𝕜 (dslope f a) s b ↔ DifferentiableWithinAt 𝕜 f s b := by
  refine' ⟨DifferentiableWithinAt.of_dslope, fun hd => _⟩
  refine' (((differentiableWithinAt_id.sub_const a).inv (sub_ne_zero.2 h)).smul
    (hd.sub_const (f a))).congr_of_eventuallyEq _ (dslope_of_ne _ h)
  

Proof state:
𝕜 : Type u_1
E : Type u_2
inst✝² : NontriviallyNormedField 𝕜
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f : 𝕜 → E
a b : 𝕜
s : Set 𝕜
h : b ≠ a
hd : DifferentiableWithinAt 𝕜 f s b
⊢ dslope f a =ᶠ[𝓝[s] b] fun y => (id y - a)⁻¹ • (f y - f a)

Next tactic:
refine' (eqOn_dslope_slope _ _).eventuallyEq_of_mem _
theorem differentiableWithinAt_dslope_of_ne (h : b ≠ a) :
    DifferentiableWithinAt 𝕜 (dslope f a) s b ↔ DifferentiableWithinAt 𝕜 f s b := by
  refine' ⟨DifferentiableWithinAt.of_dslope, fun hd => _⟩
  refine' (((differentiableWithinAt_id.sub_const a).inv (sub_ne_zero.2 h)).smul
    (hd.sub_const (f a))).congr_of_eventuallyEq _ (dslope_of_ne _ h)
  refine' (eqOn_dslope_slope _ _).eventuallyEq_of_mem _
  

Proof state:
𝕜 : Type u_1
E : Type u_2
inst✝² : NontriviallyNormedField 𝕜
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f : 𝕜 → E
a b : 𝕜
s : Set 𝕜
h : b ≠ a
hd : DifferentiableWithinAt 𝕜 f s b
⊢ {a}ᶜ ∈ 𝓝[s] b

Next tactic:
exact mem_nhdsWithin_of_mem_nhds (isOpen_ne.mem_nhds h)
theorem differentiableAt_dslope_of_ne (h : b ≠ a) :
    DifferentiableAt 𝕜 (dslope f a) b ↔ DifferentiableAt 𝕜 f b := by
  

Proof state:
𝕜 : Type u_1
E : Type u_2
inst✝² : NontriviallyNormedField 𝕜
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f : 𝕜 → E
a b : 𝕜
s : Set 𝕜
h : b ≠ a
⊢ DifferentiableAt 𝕜 (dslope f a) b ↔ DifferentiableAt 𝕜 f b

Next tactic:
simp only [← differentiableWithinAt_univ, differentiableWithinAt_dslope_of_ne h]
instance : WfDvdMonoid ℕ :=
  ⟨by
    

Proof state:
⊢ WellFounded DvdNotUnit

Next tactic:
refine'
      RelHomClass.wellFounded
        (⟨fun x : ℕ => if x = 0 then (⊤ : ℕ∞) else x, _⟩ : DvdNotUnit →r (· < ·)) wellFounded_lt
instance : WfDvdMonoid ℕ :=
  ⟨by
    refine'
      RelHomClass.wellFounded
        (⟨fun x : ℕ => if x = 0 then (⊤ : ℕ∞) else x, _⟩ : DvdNotUnit →r (· < ·)) wellFounded_lt
    

Proof state:
⊢ ∀ {a b : ℕ}, DvdNotUnit a b → (fun x => if x = 0 then ⊤ else ↑x) a < (fun x => if x = 0 then ⊤ else ↑x) b

Next tactic:
intro a b h
instance : WfDvdMonoid ℕ :=
  ⟨by
    refine'
      RelHomClass.wellFounded
        (⟨fun x : ℕ => if x = 0 then (⊤ : ℕ∞) else x, _⟩ : DvdNotUnit →r (· < ·)) wellFounded_lt
    intro a b h
    

Proof state:
a b : ℕ
h : DvdNotUnit a b
⊢ (fun x => if x = 0 then ⊤ else ↑x) a < (fun x => if x = 0 then ⊤ else ↑x) b

Next tactic:
cases' a with a
instance : WfDvdMonoid ℕ :=
  ⟨by
    refine'
      RelHomClass.wellFounded
        (⟨fun x : ℕ => if x = 0 then (⊤ : ℕ∞) else x, _⟩ : DvdNotUnit →r (· < ·)) wellFounded_lt
    intro a b h
    cases' a with a
    · 

Proof state:
case zero
b : ℕ
h : DvdNotUnit zero b
⊢ (fun x => if x = 0 then ⊤ else ↑x) zero < (fun x => if x = 0 then ⊤ else ↑x) b

Next tactic:
exfalso
instance : WfDvdMonoid ℕ :=
  ⟨by
    refine'
      RelHomClass.wellFounded
        (⟨fun x : ℕ => if x = 0 then (⊤ : ℕ∞) else x, _⟩ : DvdNotUnit →r (· < ·)) wellFounded_lt
    intro a b h
    cases' a with a
    · exfalso
      

Proof state:
case zero.h
b : ℕ
h : DvdNotUnit zero b
⊢ False

Next tactic:
revert h
instance : WfDvdMonoid ℕ :=
  ⟨by
    refine'
      RelHomClass.wellFounded
        (⟨fun x : ℕ => if x = 0 then (⊤ : ℕ∞) else x, _⟩ : DvdNotUnit →r (· < ·)) wellFounded_lt
    intro a b h
    cases' a with a
    · exfalso
      revert h
      

Proof state:
case zero.h
b : ℕ
⊢ DvdNotUnit zero b → False

Next tactic:
simp [DvdNotUnit]
instance : WfDvdMonoid ℕ :=
  ⟨by
    refine'
      RelHomClass.wellFounded
        (⟨fun x : ℕ => if x = 0 then (⊤ : ℕ∞) else x, _⟩ : DvdNotUnit →r (· < ·)) wellFounded_lt
    intro a b h
    cases' a with a
    · exfalso
      revert h
      simp [DvdNotUnit]
    

Proof state:
case succ
b a : ℕ
h : DvdNotUnit (succ a) b
⊢ (fun x => if x = 0 then ⊤ else ↑x) (succ a) < (fun x => if x = 0 then ⊤ else ↑x) b

Next tactic:
cases b
instance : WfDvdMonoid ℕ :=
  ⟨by
    refine'
      RelHomClass.wellFounded
        (⟨fun x : ℕ => if x = 0 then (⊤ : ℕ∞) else x, _⟩ : DvdNotUnit →r (· < ·)) wellFounded_lt
    intro a b h
    cases' a with a
    · exfalso
      revert h
      simp [DvdNotUnit]
    cases b
    · 

Proof state:
case succ.zero
a : ℕ
h : DvdNotUnit (succ a) zero
⊢ (fun x => if x = 0 then ⊤ else ↑x) (succ a) < (fun x => if x = 0 then ⊤ else ↑x) zero

Next tactic:
simpa [succ_ne_zero] using WithTop.coe_lt_top (a + 1)
instance : WfDvdMonoid ℕ :=
  ⟨by
    refine'
      RelHomClass.wellFounded
        (⟨fun x : ℕ => if x = 0 then (⊤ : ℕ∞) else x, _⟩ : DvdNotUnit →r (· < ·)) wellFounded_lt
    intro a b h
    cases' a with a
    · exfalso
      revert h
      simp [DvdNotUnit]
    cases b
    · simpa [succ_ne_zero] using WithTop.coe_lt_top (a + 1)
    

Proof state:
case succ.succ
a n✝ : ℕ
h : DvdNotUnit (succ a) (succ n✝)
⊢ (fun x => if x = 0 then ⊤ else ↑x) (succ a) < (fun x => if x = 0 then ⊤ else ↑x) (succ n✝)

Next tactic:
cases' dvd_and_not_dvd_iff.2 h with h1 h2
instance : WfDvdMonoid ℕ :=
  ⟨by
    refine'
      RelHomClass.wellFounded
        (⟨fun x : ℕ => if x = 0 then (⊤ : ℕ∞) else x, _⟩ : DvdNotUnit →r (· < ·)) wellFounded_lt
    intro a b h
    cases' a with a
    · exfalso
      revert h
      simp [DvdNotUnit]
    cases b
    · simpa [succ_ne_zero] using WithTop.coe_lt_top (a + 1)
    cases' dvd_and_not_dvd_iff.2 h with h1 h2
    

Proof state:
case succ.succ.intro
a n✝ : ℕ
h : DvdNotUnit (succ a) (succ n✝)
h1 : succ a ∣ succ n✝
h2 : ¬succ n✝ ∣ succ a
⊢ (fun x => if x = 0 then ⊤ else ↑x) (succ a) < (fun x => if x = 0 then ⊤ else ↑x) (succ n✝)

Next tactic:
simp only [succ_ne_zero, cast_lt, if_false]
instance : WfDvdMonoid ℕ :=
  ⟨by
    refine'
      RelHomClass.wellFounded
        (⟨fun x : ℕ => if x = 0 then (⊤ : ℕ∞) else x, _⟩ : DvdNotUnit →r (· < ·)) wellFounded_lt
    intro a b h
    cases' a with a
    · exfalso
      revert h
      simp [DvdNotUnit]
    cases b
    · simpa [succ_ne_zero] using WithTop.coe_lt_top (a + 1)
    cases' dvd_and_not_dvd_iff.2 h with h1 h2
    simp only [succ_ne_zero, cast_lt, if_false]
    

Proof state:
case succ.succ.intro
a n✝ : ℕ
h : DvdNotUnit (succ a) (succ n✝)
h1 : succ a ∣ succ n✝
h2 : ¬succ n✝ ∣ succ a
⊢ succ a < succ n✝

Next tactic:
refine lt_of_le_of_ne (Nat.le_of_dvd (Nat.succ_pos _) h1) fun con => h2 ?_
instance : WfDvdMonoid ℕ :=
  ⟨by
    refine'
      RelHomClass.wellFounded
        (⟨fun x : ℕ => if x = 0 then (⊤ : ℕ∞) else x, _⟩ : DvdNotUnit →r (· < ·)) wellFounded_lt
    intro a b h
    cases' a with a
    · exfalso
      revert h
      simp [DvdNotUnit]
    cases b
    · simpa [succ_ne_zero] using WithTop.coe_lt_top (a + 1)
    cases' dvd_and_not_dvd_iff.2 h with h1 h2
    simp only [succ_ne_zero, cast_lt, if_false]
    refine lt_of_le_of_ne (Nat.le_of_dvd (Nat.succ_pos _) h1) fun con => h2 ?_
    

Proof state:
case succ.succ.intro
a n✝ : ℕ
h : DvdNotUnit (succ a) (succ n✝)
h1 : succ a ∣ succ n✝
h2 : ¬succ n✝ ∣ succ a
con : succ a = succ n✝
⊢ succ n✝ ∣ succ a

Next tactic:
rw [con]
/-- `ℕ` is a gcd_monoid. -/
instance : GCDMonoid ℕ where
  gcd := Nat.gcd
  lcm := Nat.lcm
  gcd_dvd_left := Nat.gcd_dvd_left
  gcd_dvd_right := Nat.gcd_dvd_right
  dvd_gcd := Nat.dvd_gcd
  gcd_mul_lcm a b := by 

Proof state:
a b : ℕ
⊢ Associated (Nat.gcd a b * Nat.lcm a b) (a * b)

Next tactic:
rw [Nat.gcd_mul_lcm]
/-- `ℕ` is a gcd_monoid. -/
instance : GCDMonoid ℕ where
  gcd := Nat.gcd
  lcm := Nat.lcm
  gcd_dvd_left := Nat.gcd_dvd_left
  gcd_dvd_right := Nat.gcd_dvd_right
  dvd_gcd := Nat.dvd_gcd
  gcd_mul_lcm a b := by rw [Nat.gcd_mul_lcm]; 

Proof state:
a b : ℕ
⊢ Associated (a * b) (a * b)

Next tactic:
rfl
instance normalizationMonoid : NormalizationMonoid ℤ where
  normUnit a := if 0 ≤ a then 1 else -1
  normUnit_zero := if_pos le_rfl
  normUnit_mul {a b} hna hnb := by
    

Proof state:
a b : ℤ
hna : a ≠ 0
hnb : b ≠ 0
⊢ (fun a => if 0 ≤ a then 1 else -1) (a * b) =
    (fun a => if 0 ≤ a then 1 else -1) a * (fun a => if 0 ≤ a then 1 else -1) b

Next tactic:
cases' hna.lt_or_lt with ha ha
instance normalizationMonoid : NormalizationMonoid ℤ where
  normUnit a := if 0 ≤ a then 1 else -1
  normUnit_zero := if_pos le_rfl
  normUnit_mul {a b} hna hnb := by
    cases' hna.lt_or_lt with ha ha <;> 

Proof state:
case inl
a b : ℤ
hna : a ≠ 0
hnb : b ≠ 0
ha : a < 0
⊢ (fun a => if 0 ≤ a then 1 else -1) (a * b) =
    (fun a => if 0 ≤ a then 1 else -1) a * (fun a => if 0 ≤ a then 1 else -1) b

Next tactic:
cases' hnb.lt_or_lt with hb hb
instance normalizationMonoid : NormalizationMonoid ℤ where
  normUnit a := if 0 ≤ a then 1 else -1
  normUnit_zero := if_pos le_rfl
  normUnit_mul {a b} hna hnb := by
    cases' hna.lt_or_lt with ha ha <;> 

Proof state:
case inr
a b : ℤ
hna : a ≠ 0
hnb : b ≠ 0
ha : 0 < a
⊢ (fun a => if 0 ≤ a then 1 else -1) (a * b) =
    (fun a => if 0 ≤ a then 1 else -1) a * (fun a => if 0 ≤ a then 1 else -1) b

Next tactic:
cases' hnb.lt_or_lt with hb hb
instance normalizationMonoid : NormalizationMonoid ℤ where
  normUnit a := if 0 ≤ a then 1 else -1
  normUnit_zero := if_pos le_rfl
  normUnit_mul {a b} hna hnb := by
    cases' hna.lt_or_lt with ha ha <;> cases' hnb.lt_or_lt with hb hb <;>
      

Proof state:
case inl.inl
a b : ℤ
hna : a ≠ 0
hnb : b ≠ 0
ha : a < 0
hb : b < 0
⊢ (fun a => if 0 ≤ a then 1 else -1) (a * b) =
    (fun a => if 0 ≤ a then 1 else -1) a * (fun a => if 0 ≤ a then 1 else -1) b

Next tactic:
simp [mul_nonneg_iff, ha.le, ha.not_le, hb.le, hb.not_le]
instance normalizationMonoid : NormalizationMonoid ℤ where
  normUnit a := if 0 ≤ a then 1 else -1
  normUnit_zero := if_pos le_rfl
  normUnit_mul {a b} hna hnb := by
    cases' hna.lt_or_lt with ha ha <;> cases' hnb.lt_or_lt with hb hb <;>
      

Proof state:
case inl.inr
a b : ℤ
hna : a ≠ 0
hnb : b ≠ 0
ha : a < 0
hb : 0 < b
⊢ (fun a => if 0 ≤ a then 1 else -1) (a * b) =
    (fun a => if 0 ≤ a then 1 else -1) a * (fun a => if 0 ≤ a then 1 else -1) b

Next tactic:
simp [mul_nonneg_iff, ha.le, ha.not_le, hb.le, hb.not_le]
instance normalizationMonoid : NormalizationMonoid ℤ where
  normUnit a := if 0 ≤ a then 1 else -1
  normUnit_zero := if_pos le_rfl
  normUnit_mul {a b} hna hnb := by
    cases' hna.lt_or_lt with ha ha <;> cases' hnb.lt_or_lt with hb hb <;>
      

Proof state:
case inr.inl
a b : ℤ
hna : a ≠ 0
hnb : b ≠ 0
ha : 0 < a
hb : b < 0
⊢ (fun a => if 0 ≤ a then 1 else -1) (a * b) =
    (fun a => if 0 ≤ a then 1 else -1) a * (fun a => if 0 ≤ a then 1 else -1) b

Next tactic:
simp [mul_nonneg_iff, ha.le, ha.not_le, hb.le, hb.not_le]
instance normalizationMonoid : NormalizationMonoid ℤ where
  normUnit a := if 0 ≤ a then 1 else -1
  normUnit_zero := if_pos le_rfl
  normUnit_mul {a b} hna hnb := by
    cases' hna.lt_or_lt with ha ha <;> cases' hnb.lt_or_lt with hb hb <;>
      

Proof state:
case inr.inr
a b : ℤ
hna : a ≠ 0
hnb : b ≠ 0
ha : 0 < a
hb : 0 < b
⊢ (fun a => if 0 ≤ a then 1 else -1) (a * b) =
    (fun a => if 0 ≤ a then 1 else -1) a * (fun a => if 0 ≤ a then 1 else -1) b

Next tactic:
simp [mul_nonneg_iff, ha.le, ha.not_le, hb.le, hb.not_le]
instance normalizationMonoid : NormalizationMonoid ℤ where
  normUnit a := if 0 ≤ a then 1 else -1
  normUnit_zero := if_pos le_rfl
  normUnit_mul {a b} hna hnb := by
    cases' hna.lt_or_lt with ha ha <;> cases' hnb.lt_or_lt with hb hb <;>
      simp [mul_nonneg_iff, ha.le, ha.not_le, hb.le, hb.not_le]
  normUnit_coe_units u :=
    (units_eq_one_or u).elim (fun eq => eq.symm ▸ if_pos zero_le_one) fun eq =>
      eq.symm ▸ if_neg (not_le_of_gt <| show (-1 : ℤ) < 0 by 

Proof state:
u : ℤˣ
eq : u = -1
⊢ -1 < 0

Next tactic:
decide
theorem normalize_of_nonneg {z : ℤ} (h : 0 ≤ z) : normalize z = z := by
  

Proof state:
z : ℤ
h : 0 ≤ z
⊢ normalize z = z

Next tactic:
rw [normalize_apply, normUnit_eq, if_pos h, Units.val_one, mul_one]
theorem normalize_of_nonpos {z : ℤ} (h : z ≤ 0) : normalize z = -z := by
  

Proof state:
z : ℤ
h : z ≤ 0
⊢ normalize z = -z

Next tactic:
obtain rfl | h := h.eq_or_lt
theorem normalize_of_nonpos {z : ℤ} (h : z ≤ 0) : normalize z = -z := by
  obtain rfl | h := h.eq_or_lt
  · 

Proof state:
case inl
h : 0 ≤ 0
⊢ normalize 0 = -0

Next tactic:
simp
theorem normalize_of_nonpos {z : ℤ} (h : z ≤ 0) : normalize z = -z := by
  obtain rfl | h := h.eq_or_lt
  · simp
  · 

Proof state:
case inr
z : ℤ
h✝ : z ≤ 0
h : z < 0
⊢ normalize z = -z

Next tactic:
rw [normalize_apply, normUnit_eq, if_neg (not_le_of_gt h), Units.val_neg, Units.val_one,
      mul_neg_one]
theorem abs_eq_normalize (z : ℤ) : |z| = normalize z := by
  

Proof state:
z : ℤ
⊢ |z| = normalize z

Next tactic:
cases le_total 0 z
theorem abs_eq_normalize (z : ℤ) : |z| = normalize z := by
  cases le_total 0 z <;> 

Proof state:
case inl
z : ℤ
h✝ : 0 ≤ z
⊢ |z| = normalize z

Next tactic:
simp [-normalize_apply, normalize_of_nonneg, normalize_of_nonpos, *]
theorem abs_eq_normalize (z : ℤ) : |z| = normalize z := by
  cases le_total 0 z <;> 

Proof state:
case inr
z : ℤ
h✝ : z ≤ 0
⊢ |z| = normalize z

Next tactic:
simp [-normalize_apply, normalize_of_nonneg, normalize_of_nonpos, *]
theorem nonneg_of_normalize_eq_self {z : ℤ} (hz : normalize z = z) : 0 ≤ z :=
  abs_eq_self.1 <| by 

Proof state:
z : ℤ
hz : normalize z = z
⊢ |z| = z

Next tactic:
rw [abs_eq_normalize, hz]
instance : GCDMonoid ℤ where
  gcd a b := Int.gcd a b
  lcm a b := Int.lcm a b
  gcd_dvd_left a b := Int.gcd_dvd_left _ _
  gcd_dvd_right a b := Int.gcd_dvd_right _ _
  dvd_gcd := dvd_gcd
  gcd_mul_lcm a b := by
    

Proof state:
a b : ℤ
⊢ Associated ((fun a b => ↑(gcd a b)) a b * (fun a b => ↑(lcm a b)) a b) (a * b)

Next tactic:
rw [← Int.ofNat_mul, gcd_mul_lcm, coe_natAbs, abs_eq_normalize]
instance : GCDMonoid ℤ where
  gcd a b := Int.gcd a b
  lcm a b := Int.lcm a b
  gcd_dvd_left a b := Int.gcd_dvd_left _ _
  gcd_dvd_right a b := Int.gcd_dvd_right _ _
  dvd_gcd := dvd_gcd
  gcd_mul_lcm a b := by
    rw [← Int.ofNat_mul, gcd_mul_lcm, coe_natAbs, abs_eq_normalize]
    

Proof state:
a b : ℤ
⊢ Associated (normalize (a * b)) (a * b)

Next tactic:
exact normalize_associated (a * b)
theorem exists_unit_of_abs (a : ℤ) : ∃ (u : ℤ) (_ : IsUnit u), (Int.natAbs a : ℤ) = u * a := by
  

Proof state:
a : ℤ
⊢ ∃ u, ∃ (_ : IsUnit u), ↑(natAbs a) = u * a

Next tactic:
cases' natAbs_eq a with h h
theorem exists_unit_of_abs (a : ℤ) : ∃ (u : ℤ) (_ : IsUnit u), (Int.natAbs a : ℤ) = u * a := by
  cases' natAbs_eq a with h h
  · 

Proof state:
case inl
a : ℤ
h : a = ↑(natAbs a)
⊢ ∃ u, ∃ (_ : IsUnit u), ↑(natAbs a) = u * a

Next tactic:
use 1, isUnit_one
theorem exists_unit_of_abs (a : ℤ) : ∃ (u : ℤ) (_ : IsUnit u), (Int.natAbs a : ℤ) = u * a := by
  cases' natAbs_eq a with h h
  · use 1, isUnit_one
    

Proof state:
case h
a : ℤ
h : a = ↑(natAbs a)
⊢ ↑(natAbs a) = 1 * a

Next tactic:
rw [← h, one_mul]
theorem exists_unit_of_abs (a : ℤ) : ∃ (u : ℤ) (_ : IsUnit u), (Int.natAbs a : ℤ) = u * a := by
  cases' natAbs_eq a with h h
  · use 1, isUnit_one
    rw [← h, one_mul]
  · 

Proof state:
case inr
a : ℤ
h : a = -↑(natAbs a)
⊢ ∃ u, ∃ (_ : IsUnit u), ↑(natAbs a) = u * a

Next tactic:
use -1, isUnit_one.neg
theorem exists_unit_of_abs (a : ℤ) : ∃ (u : ℤ) (_ : IsUnit u), (Int.natAbs a : ℤ) = u * a := by
  cases' natAbs_eq a with h h
  · use 1, isUnit_one
    rw [← h, one_mul]
  · use -1, isUnit_one.neg
    

Proof state:
case h
a : ℤ
h : a = -↑(natAbs a)
⊢ ↑(natAbs a) = -1 * a

Next tactic:
rw [← neg_eq_iff_eq_neg.mpr h]
theorem exists_unit_of_abs (a : ℤ) : ∃ (u : ℤ) (_ : IsUnit u), (Int.natAbs a : ℤ) = u * a := by
  cases' natAbs_eq a with h h
  · use 1, isUnit_one
    rw [← h, one_mul]
  · use -1, isUnit_one.neg
    rw [← neg_eq_iff_eq_neg.mpr h]
    

Proof state:
case h
a : ℤ
h : a = -↑(natAbs a)
⊢ -a = -1 * a

Next tactic:
simp only [neg_mul, one_mul]
theorem gcd_eq_one_iff_coprime {a b : ℤ} : Int.gcd a b = 1 ↔ IsCoprime a b := by
  

Proof state:
a b : ℤ
⊢ gcd a b = 1 ↔ IsCoprime a b

Next tactic:
constructor
theorem gcd_eq_one_iff_coprime {a b : ℤ} : Int.gcd a b = 1 ↔ IsCoprime a b := by
  constructor
  · 

Proof state:
case mp
a b : ℤ
⊢ gcd a b = 1 → IsCoprime a b

Next tactic:
intro hg
theorem gcd_eq_one_iff_coprime {a b : ℤ} : Int.gcd a b = 1 ↔ IsCoprime a b := by
  constructor
  · intro hg
    

Proof state:
case mp
a b : ℤ
hg : gcd a b = 1
⊢ IsCoprime a b

Next tactic:
obtain ⟨ua, -, ha⟩ := exists_unit_of_abs a
theorem gcd_eq_one_iff_coprime {a b : ℤ} : Int.gcd a b = 1 ↔ IsCoprime a b := by
  constructor
  · intro hg
    obtain ⟨ua, -, ha⟩ := exists_unit_of_abs a
    

Proof state:
case mp.intro.intro
a b : ℤ
hg : gcd a b = 1
ua : ℤ
ha : ↑(natAbs a) = ua * a
⊢ IsCoprime a b

Next tactic:
obtain ⟨ub, -, hb⟩ := exists_unit_of_abs b
theorem gcd_eq_one_iff_coprime {a b : ℤ} : Int.gcd a b = 1 ↔ IsCoprime a b := by
  constructor
  · intro hg
    obtain ⟨ua, -, ha⟩ := exists_unit_of_abs a
    obtain ⟨ub, -, hb⟩ := exists_unit_of_abs b
    

Proof state:
case mp.intro.intro.intro.intro
a b : ℤ
hg : gcd a b = 1
ua : ℤ
ha : ↑(natAbs a) = ua * a
ub : ℤ
hb : ↑(natAbs b) = ub * b
⊢ IsCoprime a b

Next tactic:
use Nat.gcdA (Int.natAbs a) (Int.natAbs b) * ua, Nat.gcdB (Int.natAbs a) (Int.natAbs b) * ub
theorem gcd_eq_one_iff_coprime {a b : ℤ} : Int.gcd a b = 1 ↔ IsCoprime a b := by
  constructor
  · intro hg
    obtain ⟨ua, -, ha⟩ := exists_unit_of_abs a
    obtain ⟨ub, -, hb⟩ := exists_unit_of_abs b
    use Nat.gcdA (Int.natAbs a) (Int.natAbs b) * ua, Nat.gcdB (Int.natAbs a) (Int.natAbs b) * ub
    

Proof state:
case h
a b : ℤ
hg : gcd a b = 1
ua : ℤ
ha : ↑(natAbs a) = ua * a
ub : ℤ
hb : ↑(natAbs b) = ub * b
⊢ Nat.gcdA (natAbs a) (natAbs b) * ua * a + Nat.gcdB (natAbs a) (natAbs b) * ub * b = 1

Next tactic:
rw [mul_assoc, ← ha, mul_assoc, ← hb, mul_comm, mul_comm _ (Int.natAbs b : ℤ), ←
      Nat.gcd_eq_gcd_ab, ← gcd_eq_natAbs, hg, Int.ofNat_one]
theorem gcd_eq_one_iff_coprime {a b : ℤ} : Int.gcd a b = 1 ↔ IsCoprime a b := by
  constructor
  · intro hg
    obtain ⟨ua, -, ha⟩ := exists_unit_of_abs a
    obtain ⟨ub, -, hb⟩ := exists_unit_of_abs b
    use Nat.gcdA (Int.natAbs a) (Int.natAbs b) * ua, Nat.gcdB (Int.natAbs a) (Int.natAbs b) * ub
    rw [mul_assoc, ← ha, mul_assoc, ← hb, mul_comm, mul_comm _ (Int.natAbs b : ℤ), ←
      Nat.gcd_eq_gcd_ab, ← gcd_eq_natAbs, hg, Int.ofNat_one]
  · 

Proof state:
case mpr
a b : ℤ
⊢ IsCoprime a b → gcd a b = 1

Next tactic:
rintro ⟨r, s, h⟩
theorem gcd_eq_one_iff_coprime {a b : ℤ} : Int.gcd a b = 1 ↔ IsCoprime a b := by
  constructor
  · intro hg
    obtain ⟨ua, -, ha⟩ := exists_unit_of_abs a
    obtain ⟨ub, -, hb⟩ := exists_unit_of_abs b
    use Nat.gcdA (Int.natAbs a) (Int.natAbs b) * ua, Nat.gcdB (Int.natAbs a) (Int.natAbs b) * ub
    rw [mul_assoc, ← ha, mul_assoc, ← hb, mul_comm, mul_comm _ (Int.natAbs b : ℤ), ←
      Nat.gcd_eq_gcd_ab, ← gcd_eq_natAbs, hg, Int.ofNat_one]
  · rintro ⟨r, s, h⟩
    

Proof state:
case mpr.intro.intro
a b r s : ℤ
h : r * a + s * b = 1
⊢ gcd a b = 1

Next tactic:
by_contra hg
theorem gcd_eq_one_iff_coprime {a b : ℤ} : Int.gcd a b = 1 ↔ IsCoprime a b := by
  constructor
  · intro hg
    obtain ⟨ua, -, ha⟩ := exists_unit_of_abs a
    obtain ⟨ub, -, hb⟩ := exists_unit_of_abs b
    use Nat.gcdA (Int.natAbs a) (Int.natAbs b) * ua, Nat.gcdB (Int.natAbs a) (Int.natAbs b) * ub
    rw [mul_assoc, ← ha, mul_assoc, ← hb, mul_comm, mul_comm _ (Int.natAbs b : ℤ), ←
      Nat.gcd_eq_gcd_ab, ← gcd_eq_natAbs, hg, Int.ofNat_one]
  · rintro ⟨r, s, h⟩
    by_contra hg
    

Proof state:
case mpr.intro.intro
a b r s : ℤ
h : r * a + s * b = 1
hg : ¬gcd a b = 1
⊢ False

Next tactic:
obtain ⟨p, ⟨hp, ha, hb⟩⟩ := Nat.Prime.not_coprime_iff_dvd.mp hg