l3lab/ntp-mathlib huggingface dataset:
theorem map_subset_iff_subset_preimage {f : α ↪ β} {s : Finset α} {t : Finset β} :
    s.map f ⊆ t ↔ s ⊆ t.preimage f (f.injective.injOn _) := by
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
f : α ↪ β
s : Finset α
t : Finset β
⊢ map f s ⊆ t ↔ s ⊆ preimage t ⇑f (_ : InjOn (⇑f) (⇑f ⁻¹' ↑t))

Next tactic:
classical rw [map_eq_image, image_subset_iff_subset_preimage]
theorem map_subset_iff_subset_preimage {f : α ↪ β} {s : Finset α} {t : Finset β} :
    s.map f ⊆ t ↔ s ⊆ t.preimage f (f.injective.injOn _) := by
  classical 

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
f : α ↪ β
s : Finset α
t : Finset β
⊢ map f s ⊆ t ↔ s ⊆ preimage t ⇑f (_ : InjOn (⇑f) (⇑f ⁻¹' ↑t))

Next tactic:
rw [map_eq_image, image_subset_iff_subset_preimage]
theorem image_preimage [DecidableEq β] (f : α → β) (s : Finset β) [∀ x, Decidable (x ∈ Set.range f)]
    (hf : Set.InjOn f (f ⁻¹' ↑s)) : image f (preimage s f hf) = s.filter fun x => x ∈ Set.range f :=
  Finset.coe_inj.1 <| by
    

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
inst✝¹ : DecidableEq β
f : α → β
s : Finset β
inst✝ : (x : β) → Decidable (x ∈ Set.range f)
hf : InjOn f (f ⁻¹' ↑s)
⊢ ↑(image f (preimage s f hf)) = ↑(filter (fun x => x ∈ Set.range f) s)

Next tactic:
simp only [coe_image, coe_preimage, coe_filter, Set.image_preimage_eq_inter_range,
      ← Set.sep_mem_eq]
theorem image_preimage [DecidableEq β] (f : α → β) (s : Finset β) [∀ x, Decidable (x ∈ Set.range f)]
    (hf : Set.InjOn f (f ⁻¹' ↑s)) : image f (preimage s f hf) = s.filter fun x => x ∈ Set.range f :=
  Finset.coe_inj.1 <| by
    simp only [coe_image, coe_preimage, coe_filter, Set.image_preimage_eq_inter_range,
      ← Set.sep_mem_eq]; 

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
inst✝¹ : DecidableEq β
f : α → β
s : Finset β
inst✝ : (x : β) → Decidable (x ∈ Set.range f)
hf : InjOn f (f ⁻¹' ↑s)
⊢ {x | x ∈ ↑s ∧ x ∈ Set.range f} = {x | x ∈ s ∧ x ∈ Set.range f}

Next tactic:
rfl
theorem image_preimage_of_bij [DecidableEq β] (f : α → β) (s : Finset β)
    (hf : Set.BijOn f (f ⁻¹' ↑s) ↑s) : image f (preimage s f hf.injOn) = s :=
  Finset.coe_inj.1 <| by 

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
inst✝ : DecidableEq β
f : α → β
s : Finset β
hf : BijOn f (f ⁻¹' ↑s) ↑s
⊢ ↑(image f (preimage s f (_ : InjOn f (f ⁻¹' ↑s)))) = ↑s

Next tactic:
simpa using hf.image_eq
theorem subset_map_iff {f : α ↪ β} {s : Finset β} {t : Finset α} :
    s ⊆ t.map f ↔ ∃ u, u ⊆ t ∧ s = u.map f := by
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
f : α ↪ β
s : Finset β
t : Finset α
⊢ s ⊆ map f t ↔ ∃ u ⊆ t, s = map f u

Next tactic:
classical
  simp_rw [← coe_subset, coe_map, subset_image_iff, map_eq_image, eq_comm]
theorem subset_map_iff {f : α ↪ β} {s : Finset β} {t : Finset α} :
    s ⊆ t.map f ↔ ∃ u, u ⊆ t ∧ s = u.map f := by
  classical
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
f : α ↪ β
s : Finset β
t : Finset α
⊢ s ⊆ map f t ↔ ∃ u ⊆ t, s = map f u

Next tactic:
simp_rw [← coe_subset, coe_map, subset_image_iff, map_eq_image, eq_comm]
theorem sigma_preimage_mk {β : α → Type*} [DecidableEq α] (s : Finset (Σa, β a)) (t : Finset α) :
    (t.sigma fun a => s.preimage (Sigma.mk a) <| sigma_mk_injective.injOn _) =
      s.filter fun a => a.1 ∈ t := by
  

Proof state:
α : Type u
β✝ : Type v
ι : Sort w
γ : Type x
β : α → Type u_1
inst✝ : DecidableEq α
s : Finset ((a : α) × β a)
t : Finset α
⊢ (Finset.sigma t fun a => preimage s (Sigma.mk a) (_ : InjOn (Sigma.mk a) (Sigma.mk a ⁻¹' ↑s))) =
    filter (fun a => a.fst ∈ t) s

Next tactic:
ext x
theorem sigma_preimage_mk {β : α → Type*} [DecidableEq α] (s : Finset (Σa, β a)) (t : Finset α) :
    (t.sigma fun a => s.preimage (Sigma.mk a) <| sigma_mk_injective.injOn _) =
      s.filter fun a => a.1 ∈ t := by
  ext x
  

Proof state:
case a
α : Type u
β✝ : Type v
ι : Sort w
γ : Type x
β : α → Type u_1
inst✝ : DecidableEq α
s : Finset ((a : α) × β a)
t : Finset α
x : (i : α) × β i
⊢ (x ∈ Finset.sigma t fun a => preimage s (Sigma.mk a) (_ : InjOn (Sigma.mk a) (Sigma.mk a ⁻¹' ↑s))) ↔
    x ∈ filter (fun a => a.fst ∈ t) s

Next tactic:
simp [and_comm]
theorem sigma_preimage_mk_of_subset {β : α → Type*} [DecidableEq α] (s : Finset (Σa, β a))
    {t : Finset α} (ht : s.image Sigma.fst ⊆ t) :
    (t.sigma fun a => s.preimage (Sigma.mk a) <| sigma_mk_injective.injOn _) = s := by
  

Proof state:
α : Type u
β✝ : Type v
ι : Sort w
γ : Type x
β : α → Type u_1
inst✝ : DecidableEq α
s : Finset ((a : α) × β a)
t : Finset α
ht : image Sigma.fst s ⊆ t
⊢ (Finset.sigma t fun a => preimage s (Sigma.mk a) (_ : InjOn (Sigma.mk a) (Sigma.mk a ⁻¹' ↑s))) = s

Next tactic:
rw [sigma_preimage_mk, filter_true_of_mem <| image_subset_iff.1 ht]
@[to_additive]
theorem prod_preimage' [CommMonoid β] (f : α → γ) [DecidablePred fun x => x ∈ Set.range f]
    (s : Finset γ) (hf : Set.InjOn f (f ⁻¹' ↑s)) (g : γ → β) :
    (∏ x in s.preimage f hf, g (f x)) = ∏ x in s.filter fun x => x ∈ Set.range f, g x := by
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
inst✝¹ : CommMonoid β
f : α → γ
inst✝ : DecidablePred fun x => x ∈ Set.range f
s : Finset γ
hf : InjOn f (f ⁻¹' ↑s)
g : γ → β
⊢ ∏ x in preimage s f hf, g (f x) = ∏ x in filter (fun x => x ∈ Set.range f) s, g x

Next tactic:
haveI := Classical.decEq γ
@[to_additive]
theorem prod_preimage' [CommMonoid β] (f : α → γ) [DecidablePred fun x => x ∈ Set.range f]
    (s : Finset γ) (hf : Set.InjOn f (f ⁻¹' ↑s)) (g : γ → β) :
    (∏ x in s.preimage f hf, g (f x)) = ∏ x in s.filter fun x => x ∈ Set.range f, g x := by
  haveI := Classical.decEq γ
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
inst✝¹ : CommMonoid β
f : α → γ
inst✝ : DecidablePred fun x => x ∈ Set.range f
s : Finset γ
hf : InjOn f (f ⁻¹' ↑s)
g : γ → β
this : DecidableEq γ
⊢ ∏ x in preimage s f hf, g (f x) = ∏ x in filter (fun x => x ∈ Set.range f) s, g x

Next tactic:
calc
    (∏ x in preimage s f hf, g (f x)) = ∏ x in image f (preimage s f hf), g x :=
      Eq.symm <| prod_image <| by simpa only [mem_preimage, InjOn] using hf
    _ = ∏ x in s.filter fun x => x ∈ Set.range f, g x := by rw [image_preimage]
@[to_additive]
theorem prod_preimage' [CommMonoid β] (f : α → γ) [DecidablePred fun x => x ∈ Set.range f]
    (s : Finset γ) (hf : Set.InjOn f (f ⁻¹' ↑s)) (g : γ → β) :
    (∏ x in s.preimage f hf, g (f x)) = ∏ x in s.filter fun x => x ∈ Set.range f, g x := by
  haveI := Classical.decEq γ
  calc
    (∏ x in preimage s f hf, g (f x)) = ∏ x in image f (preimage s f hf), g x :=
      Eq.symm <| prod_image <| by 

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
inst✝¹ : CommMonoid β
f : α → γ
inst✝ : DecidablePred fun x => x ∈ Set.range f
s : Finset γ
hf : InjOn f (f ⁻¹' ↑s)
g : γ → β
this : DecidableEq γ
⊢ ∀ x ∈ preimage s f hf, ∀ y ∈ preimage s f hf, f x = f y → x = y

Next tactic:
simpa only [mem_preimage, InjOn] using hf
@[to_additive]
theorem prod_preimage' [CommMonoid β] (f : α → γ) [DecidablePred fun x => x ∈ Set.range f]
    (s : Finset γ) (hf : Set.InjOn f (f ⁻¹' ↑s)) (g : γ → β) :
    (∏ x in s.preimage f hf, g (f x)) = ∏ x in s.filter fun x => x ∈ Set.range f, g x := by
  haveI := Classical.decEq γ
  calc
    (∏ x in preimage s f hf, g (f x)) = ∏ x in image f (preimage s f hf), g x :=
      Eq.symm <| prod_image <| by simpa only [mem_preimage, InjOn] using hf
    _ = ∏ x in s.filter fun x => x ∈ Set.range f, g x := by 

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
inst✝¹ : CommMonoid β
f : α → γ
inst✝ : DecidablePred fun x => x ∈ Set.range f
s : Finset γ
hf : InjOn f (f ⁻¹' ↑s)
g : γ → β
this : DecidableEq γ
⊢ ∏ x in image f (preimage s f hf), g x = ∏ x in filter (fun x => x ∈ Set.range f) s, g x

Next tactic:
rw [image_preimage]
@[to_additive]
theorem prod_preimage [CommMonoid β] (f : α → γ) (s : Finset γ) (hf : Set.InjOn f (f ⁻¹' ↑s))
    (g : γ → β) (hg : ∀ x ∈ s, x ∉ Set.range f → g x = 1) :
    (∏ x in s.preimage f hf, g (f x)) = ∏ x in s, g x := by
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
inst✝ : CommMonoid β
f : α → γ
s : Finset γ
hf : InjOn f (f ⁻¹' ↑s)
g : γ → β
hg : ∀ x ∈ s, x ∉ Set.range f → g x = 1
⊢ ∏ x in preimage s f hf, g (f x) = ∏ x in s, g x

Next tactic:
classical
    rw [prod_preimage', prod_filter_of_ne]
    exact fun x hx => Not.imp_symm (hg x hx)
@[to_additive]
theorem prod_preimage [CommMonoid β] (f : α → γ) (s : Finset γ) (hf : Set.InjOn f (f ⁻¹' ↑s))
    (g : γ → β) (hg : ∀ x ∈ s, x ∉ Set.range f → g x = 1) :
    (∏ x in s.preimage f hf, g (f x)) = ∏ x in s, g x := by
  classical
    

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
inst✝ : CommMonoid β
f : α → γ
s : Finset γ
hf : InjOn f (f ⁻¹' ↑s)
g : γ → β
hg : ∀ x ∈ s, x ∉ Set.range f → g x = 1
⊢ ∏ x in preimage s f hf, g (f x) = ∏ x in s, g x

Next tactic:
rw [prod_preimage', prod_filter_of_ne]
@[to_additive]
theorem prod_preimage [CommMonoid β] (f : α → γ) (s : Finset γ) (hf : Set.InjOn f (f ⁻¹' ↑s))
    (g : γ → β) (hg : ∀ x ∈ s, x ∉ Set.range f → g x = 1) :
    (∏ x in s.preimage f hf, g (f x)) = ∏ x in s, g x := by
  classical
    rw [prod_preimage', prod_filter_of_ne]
    

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
inst✝ : CommMonoid β
f : α → γ
s : Finset γ
hf : InjOn f (f ⁻¹' ↑s)
g : γ → β
hg : ∀ x ∈ s, x ∉ Set.range f → g x = 1
⊢ ∀ x ∈ s, g x ≠ 1 → x ∈ Set.range f

Next tactic:
exact fun x hx => Not.imp_symm (hg x hx)
lemma toNat_lt' {a : ℤ} {b : ℕ} (hb : b ≠ 0) : a.toNat < b ↔ a < b := by
  

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
a : ℤ
b : ℕ
hb : b ≠ 0
⊢ toNat a < b ↔ a < ↑b

Next tactic:
rw [← toNat_lt_toNat, toNat_coe_nat]
lemma toNat_lt' {a : ℤ} {b : ℕ} (hb : b ≠ 0) : a.toNat < b ↔ a < b := by
  rw [← toNat_lt_toNat, toNat_coe_nat]; 

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
a : ℤ
b : ℕ
hb : b ≠ 0
⊢ 0 < ↑b

Next tactic:
exact coe_nat_pos.2 hb.bot_lt
theorem cast_commute [NonAssocRing α] : ∀ (m : ℤ) (x : α), Commute (↑m) x
  | (n : ℕ), x => by 

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : NonAssocRing α
n : ℕ
x : α
⊢ Commute (↑↑n) x

Next tactic:
simpa using n.cast_commute x
theorem cast_commute [NonAssocRing α] : ∀ (m : ℤ) (x : α), Commute (↑m) x
  | (n : ℕ), x => by simpa using n.cast_commute x
  | -[n+1], x => by
    

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : NonAssocRing α
n : ℕ
x : α
⊢ Commute (↑-[n+1]) x

Next tactic:
simpa only [cast_negSucc, Commute.neg_left_iff, Commute.neg_right_iff] using
      (n + 1).cast_commute (-x)
theorem cast_mono [OrderedRing α] : Monotone (fun x : ℤ => (x : α)) := by
  

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : OrderedRing α
⊢ Monotone fun x => ↑x

Next tactic:
intro m n h
theorem cast_mono [OrderedRing α] : Monotone (fun x : ℤ => (x : α)) := by
  intro m n h
  

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : OrderedRing α
m n : ℤ
h : m ≤ n
⊢ (fun x => ↑x) m ≤ (fun x => ↑x) n

Next tactic:
rw [← sub_nonneg] at h
theorem cast_mono [OrderedRing α] : Monotone (fun x : ℤ => (x : α)) := by
  intro m n h
  rw [← sub_nonneg] at h
  

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : OrderedRing α
m n : ℤ
h : 0 ≤ n - m
⊢ (fun x => ↑x) m ≤ (fun x => ↑x) n

Next tactic:
lift n - m to ℕ using h with k hk
theorem cast_mono [OrderedRing α] : Monotone (fun x : ℤ => (x : α)) := by
  intro m n h
  rw [← sub_nonneg] at h
  lift n - m to ℕ using h with k hk
  

Proof state:
case intro
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : OrderedRing α
m n : ℤ
k : ℕ
hk : ↑k = n - m
⊢ ↑m ≤ ↑n

Next tactic:
rw [← sub_nonneg, ← cast_sub, ← hk, cast_ofNat]
theorem cast_mono [OrderedRing α] : Monotone (fun x : ℤ => (x : α)) := by
  intro m n h
  rw [← sub_nonneg] at h
  lift n - m to ℕ using h with k hk
  rw [← sub_nonneg, ← cast_sub, ← hk, cast_ofNat]
  

Proof state:
case intro
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : OrderedRing α
m n : ℤ
k : ℕ
hk : ↑k = n - m
⊢ 0 ≤ ↑k

Next tactic:
exact k.cast_nonneg
@[simp]
theorem cast_nonneg [OrderedRing α] [Nontrivial α] : ∀ {n : ℤ}, (0 : α) ≤ n ↔ 0 ≤ n
  | (n : ℕ) => by 

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝¹ : OrderedRing α
inst✝ : Nontrivial α
n : ℕ
⊢ 0 ≤ ↑↑n ↔ 0 ≤ ↑n

Next tactic:
simp
@[simp]
theorem cast_nonneg [OrderedRing α] [Nontrivial α] : ∀ {n : ℤ}, (0 : α) ≤ n ↔ 0 ≤ n
  | (n : ℕ) => by simp
  | -[n+1] => by
    

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝¹ : OrderedRing α
inst✝ : Nontrivial α
n : ℕ
⊢ 0 ≤ ↑-[n+1] ↔ 0 ≤ -[n+1]

Next tactic:
have : -(n : α) < 1 := lt_of_le_of_lt (by simp) zero_lt_one
@[simp]
theorem cast_nonneg [OrderedRing α] [Nontrivial α] : ∀ {n : ℤ}, (0 : α) ≤ n ↔ 0 ≤ n
  | (n : ℕ) => by simp
  | -[n+1] => by
    have : -(n : α) < 1 := lt_of_le_of_lt (by 

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝¹ : OrderedRing α
inst✝ : Nontrivial α
n : ℕ
⊢ -↑n ≤ 0

Next tactic:
simp
@[simp]
theorem cast_nonneg [OrderedRing α] [Nontrivial α] : ∀ {n : ℤ}, (0 : α) ≤ n ↔ 0 ≤ n
  | (n : ℕ) => by simp
  | -[n+1] => by
    have : -(n : α) < 1 := lt_of_le_of_lt (by simp) zero_lt_one
    

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝¹ : OrderedRing α
inst✝ : Nontrivial α
n : ℕ
this : -↑n < 1
⊢ 0 ≤ ↑-[n+1] ↔ 0 ≤ -[n+1]

Next tactic:
simpa [(negSucc_lt_zero n).not_le, ← sub_eq_add_neg, le_neg] using this.not_le
@[simp, norm_cast]
theorem cast_le [OrderedRing α] [Nontrivial α] {m n : ℤ} : (m : α) ≤ n ↔ m ≤ n := by
  

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝¹ : OrderedRing α
inst✝ : Nontrivial α
m n : ℤ
⊢ ↑m ≤ ↑n ↔ m ≤ n

Next tactic:
rw [← sub_nonneg, ← cast_sub, cast_nonneg, sub_nonneg]
@[simp]
theorem cast_nonpos [OrderedRing α] [Nontrivial α] {n : ℤ} : (n : α) ≤ 0 ↔ n ≤ 0 := by
  

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝¹ : OrderedRing α
inst✝ : Nontrivial α
n : ℤ
⊢ ↑n ≤ 0 ↔ n ≤ 0

Next tactic:
rw [← cast_zero, cast_le]
@[simp]
theorem cast_pos [OrderedRing α] [Nontrivial α] {n : ℤ} : (0 : α) < n ↔ 0 < n := by
  

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝¹ : OrderedRing α
inst✝ : Nontrivial α
n : ℤ
⊢ 0 < ↑n ↔ 0 < n

Next tactic:
rw [← cast_zero, cast_lt]
@[simp]
theorem cast_lt_zero [OrderedRing α] [Nontrivial α] {n : ℤ} : (n : α) < 0 ↔ n < 0 := by
  

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝¹ : OrderedRing α
inst✝ : Nontrivial α
n : ℤ
⊢ ↑n < 0 ↔ n < 0

Next tactic:
rw [← cast_zero, cast_lt]
@[simp, norm_cast]
theorem cast_abs : ((|a| : ℤ) : α) = |(a : α)| := by 

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : LinearOrderedRing α
a b n : ℤ
⊢ ↑|a| = |↑a|

Next tactic:
simp [abs_eq_max_neg]
theorem cast_le_neg_one_of_neg (h : a < 0) : (a : α) ≤ -1 := by
  

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : LinearOrderedRing α
a b n : ℤ
h : a < 0
⊢ ↑a ≤ -1

Next tactic:
rw [← Int.cast_one, ← Int.cast_neg, cast_le]
theorem cast_le_neg_one_of_neg (h : a < 0) : (a : α) ≤ -1 := by
  rw [← Int.cast_one, ← Int.cast_neg, cast_le]
  

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : LinearOrderedRing α
a b n : ℤ
h : a < 0
⊢ a ≤ -1

Next tactic:
exact Int.le_sub_one_of_lt h
theorem nneg_mul_add_sq_of_abs_le_one {x : α} (hx : |x| ≤ 1) : (0 : α) ≤ n * x + n * n := by
  

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : LinearOrderedRing α
a b n : ℤ
x : α
hx : |x| ≤ 1
⊢ 0 ≤ ↑n * x + ↑n * ↑n

Next tactic:
have hnx : 0 < n → 0 ≤ x + n := fun hn => by
    have := _root_.add_le_add (neg_le_of_abs_le hx) (cast_one_le_of_pos hn)
    rwa [add_left_neg] at this
theorem nneg_mul_add_sq_of_abs_le_one {x : α} (hx : |x| ≤ 1) : (0 : α) ≤ n * x + n * n := by
  have hnx : 0 < n → 0 ≤ x + n := fun hn => by
    

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : LinearOrderedRing α
a b n : ℤ
x : α
hx : |x| ≤ 1
hn : 0 < n
⊢ 0 ≤ x + ↑n

Next tactic:
have := _root_.add_le_add (neg_le_of_abs_le hx) (cast_one_le_of_pos hn)
theorem nneg_mul_add_sq_of_abs_le_one {x : α} (hx : |x| ≤ 1) : (0 : α) ≤ n * x + n * n := by
  have hnx : 0 < n → 0 ≤ x + n := fun hn => by
    have := _root_.add_le_add (neg_le_of_abs_le hx) (cast_one_le_of_pos hn)
    

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : LinearOrderedRing α
a b n : ℤ
x : α
hx : |x| ≤ 1
hn : 0 < n
this : -1 + 1 ≤ x + ↑n
⊢ 0 ≤ x + ↑n

Next tactic:
rwa [add_left_neg] at this
theorem nneg_mul_add_sq_of_abs_le_one {x : α} (hx : |x| ≤ 1) : (0 : α) ≤ n * x + n * n := by
  have hnx : 0 < n → 0 ≤ x + n := fun hn => by
    have := _root_.add_le_add (neg_le_of_abs_le hx) (cast_one_le_of_pos hn)
    rwa [add_left_neg] at this
  

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : LinearOrderedRing α
a b n : ℤ
x : α
hx : |x| ≤ 1
hnx : 0 < n → 0 ≤ x + ↑n
⊢ 0 ≤ ↑n * x + ↑n * ↑n

Next tactic:
have hnx' : n < 0 → x + n ≤ 0 := fun hn => by
    have := _root_.add_le_add (le_of_abs_le hx) (cast_le_neg_one_of_neg hn)
    rwa [add_right_neg] at this
theorem nneg_mul_add_sq_of_abs_le_one {x : α} (hx : |x| ≤ 1) : (0 : α) ≤ n * x + n * n := by
  have hnx : 0 < n → 0 ≤ x + n := fun hn => by
    have := _root_.add_le_add (neg_le_of_abs_le hx) (cast_one_le_of_pos hn)
    rwa [add_left_neg] at this
  have hnx' : n < 0 → x + n ≤ 0 := fun hn => by
    

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : LinearOrderedRing α
a b n : ℤ
x : α
hx : |x| ≤ 1
hnx : 0 < n → 0 ≤ x + ↑n
hn : n < 0
⊢ x + ↑n ≤ 0

Next tactic:
have := _root_.add_le_add (le_of_abs_le hx) (cast_le_neg_one_of_neg hn)
theorem nneg_mul_add_sq_of_abs_le_one {x : α} (hx : |x| ≤ 1) : (0 : α) ≤ n * x + n * n := by
  have hnx : 0 < n → 0 ≤ x + n := fun hn => by
    have := _root_.add_le_add (neg_le_of_abs_le hx) (cast_one_le_of_pos hn)
    rwa [add_left_neg] at this
  have hnx' : n < 0 → x + n ≤ 0 := fun hn => by
    have := _root_.add_le_add (le_of_abs_le hx) (cast_le_neg_one_of_neg hn)
    

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : LinearOrderedRing α
a b n : ℤ
x : α
hx : |x| ≤ 1
hnx : 0 < n → 0 ≤ x + ↑n
hn : n < 0
this : x + ↑n ≤ 1 + -1
⊢ x + ↑n ≤ 0

Next tactic:
rwa [add_right_neg] at this
theorem nneg_mul_add_sq_of_abs_le_one {x : α} (hx : |x| ≤ 1) : (0 : α) ≤ n * x + n * n := by
  have hnx : 0 < n → 0 ≤ x + n := fun hn => by
    have := _root_.add_le_add (neg_le_of_abs_le hx) (cast_one_le_of_pos hn)
    rwa [add_left_neg] at this
  have hnx' : n < 0 → x + n ≤ 0 := fun hn => by
    have := _root_.add_le_add (le_of_abs_le hx) (cast_le_neg_one_of_neg hn)
    rwa [add_right_neg] at this
  

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : LinearOrderedRing α
a b n : ℤ
x : α
hx : |x| ≤ 1
hnx : 0 < n → 0 ≤ x + ↑n
hnx' : n < 0 → x + ↑n ≤ 0
⊢ 0 ≤ ↑n * x + ↑n * ↑n

Next tactic:
rw [← mul_add, mul_nonneg_iff]
theorem nneg_mul_add_sq_of_abs_le_one {x : α} (hx : |x| ≤ 1) : (0 : α) ≤ n * x + n * n := by
  have hnx : 0 < n → 0 ≤ x + n := fun hn => by
    have := _root_.add_le_add (neg_le_of_abs_le hx) (cast_one_le_of_pos hn)
    rwa [add_left_neg] at this
  have hnx' : n < 0 → x + n ≤ 0 := fun hn => by
    have := _root_.add_le_add (le_of_abs_le hx) (cast_le_neg_one_of_neg hn)
    rwa [add_right_neg] at this
  rw [← mul_add, mul_nonneg_iff]
  

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : LinearOrderedRing α
a b n : ℤ
x : α
hx : |x| ≤ 1
hnx : 0 < n → 0 ≤ x + ↑n
hnx' : n < 0 → x + ↑n ≤ 0
⊢ 0 ≤ ↑n ∧ 0 ≤ x + ↑n ∨ ↑n ≤ 0 ∧ x + ↑n ≤ 0

Next tactic:
rcases lt_trichotomy n 0 with (h | rfl | h)
theorem nneg_mul_add_sq_of_abs_le_one {x : α} (hx : |x| ≤ 1) : (0 : α) ≤ n * x + n * n := by
  have hnx : 0 < n → 0 ≤ x + n := fun hn => by
    have := _root_.add_le_add (neg_le_of_abs_le hx) (cast_one_le_of_pos hn)
    rwa [add_left_neg] at this
  have hnx' : n < 0 → x + n ≤ 0 := fun hn => by
    have := _root_.add_le_add (le_of_abs_le hx) (cast_le_neg_one_of_neg hn)
    rwa [add_right_neg] at this
  rw [← mul_add, mul_nonneg_iff]
  rcases lt_trichotomy n 0 with (h | rfl | h)
  · 

Proof state:
case inl
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : LinearOrderedRing α
a b n : ℤ
x : α
hx : |x| ≤ 1
hnx : 0 < n → 0 ≤ x + ↑n
hnx' : n < 0 → x + ↑n ≤ 0
h : n < 0
⊢ 0 ≤ ↑n ∧ 0 ≤ x + ↑n ∨ ↑n ≤ 0 ∧ x + ↑n ≤ 0

Next tactic:
exact Or.inr ⟨mod_cast h.le, hnx' h⟩
theorem nneg_mul_add_sq_of_abs_le_one {x : α} (hx : |x| ≤ 1) : (0 : α) ≤ n * x + n * n := by
  have hnx : 0 < n → 0 ≤ x + n := fun hn => by
    have := _root_.add_le_add (neg_le_of_abs_le hx) (cast_one_le_of_pos hn)
    rwa [add_left_neg] at this
  have hnx' : n < 0 → x + n ≤ 0 := fun hn => by
    have := _root_.add_le_add (le_of_abs_le hx) (cast_le_neg_one_of_neg hn)
    rwa [add_right_neg] at this
  rw [← mul_add, mul_nonneg_iff]
  rcases lt_trichotomy n 0 with (h | rfl | h)
  · exact Or.inr ⟨mod_cast h.le, hnx' h⟩
  · 

Proof state:
case inr.inl
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : LinearOrderedRing α
a b : ℤ
x : α
hx : |x| ≤ 1
hnx : 0 < 0 → 0 ≤ x + ↑0
hnx' : 0 < 0 → x + ↑0 ≤ 0
⊢ 0 ≤ ↑0 ∧ 0 ≤ x + ↑0 ∨ ↑0 ≤ 0 ∧ x + ↑0 ≤ 0

Next tactic:
simp [le_total 0 x]
theorem nneg_mul_add_sq_of_abs_le_one {x : α} (hx : |x| ≤ 1) : (0 : α) ≤ n * x + n * n := by
  have hnx : 0 < n → 0 ≤ x + n := fun hn => by
    have := _root_.add_le_add (neg_le_of_abs_le hx) (cast_one_le_of_pos hn)
    rwa [add_left_neg] at this
  have hnx' : n < 0 → x + n ≤ 0 := fun hn => by
    have := _root_.add_le_add (le_of_abs_le hx) (cast_le_neg_one_of_neg hn)
    rwa [add_right_neg] at this
  rw [← mul_add, mul_nonneg_iff]
  rcases lt_trichotomy n 0 with (h | rfl | h)
  · exact Or.inr ⟨mod_cast h.le, hnx' h⟩
  · simp [le_total 0 x]
  · 

Proof state:
case inr.inr
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : LinearOrderedRing α
a b n : ℤ
x : α
hx : |x| ≤ 1
hnx : 0 < n → 0 ≤ x + ↑n
hnx' : n < 0 → x + ↑n ≤ 0
h : 0 < n
⊢ 0 ≤ ↑n ∧ 0 ≤ x + ↑n ∨ ↑n ≤ 0 ∧ x + ↑n ≤ 0

Next tactic:
exact Or.inl ⟨mod_cast h.le, hnx h⟩
theorem cast_natAbs : (n.natAbs : α) = |n| := by
  

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : LinearOrderedRing α
a b n : ℤ
⊢ ↑(natAbs n) = ↑|n|

Next tactic:
cases n
theorem cast_natAbs : (n.natAbs : α) = |n| := by
  cases n
  · 

Proof state:
case ofNat
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : LinearOrderedRing α
a b : ℤ
a✝ : ℕ
⊢ ↑(natAbs (ofNat a✝)) = ↑|ofNat a✝|

Next tactic:
simp
theorem cast_natAbs : (n.natAbs : α) = |n| := by
  cases n
  · simp
  · 

Proof state:
case negSucc
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
inst✝ : LinearOrderedRing α
a b : ℤ
a✝ : ℕ
⊢ ↑(natAbs -[a✝+1]) = ↑|-[a✝+1]|

Next tactic:
rw [abs_eq_natAbs, natAbs_negSucc, cast_succ, cast_ofNat, cast_succ]
theorem eq_int_castAddHom (f : ℤ →+ A) (h1 : f 1 = 1) : f = Int.castAddHom A :=
  ext_int <| by 

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
A : Type u_5
inst✝ : AddGroupWithOne A
f : ℤ →+ A
h1 : f 1 = 1
⊢ f 1 = (castAddHom A) 1

Next tactic:
simp [h1]
/-- If two `MonoidHom`s agree on `-1` and the naturals then they are equal. -/
@[ext]
theorem ext_int {f g : ℤ →* M} (h_neg_one : f (-1) = g (-1))
    (h_nat : f.comp Int.ofNatHom.toMonoidHom = g.comp Int.ofNatHom.toMonoidHom) : f = g := by
  

Proof state:
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
M : Type u_5
inst✝ : Monoid M
f g : ℤ →* M
h_neg_one : f (-1) = g (-1)
h_nat : comp f ↑ofNatHom = comp g ↑ofNatHom
⊢ f = g

Next tactic:
ext (x | x)
/-- If two `MonoidHom`s agree on `-1` and the naturals then they are equal. -/
@[ext]
theorem ext_int {f g : ℤ →* M} (h_neg_one : f (-1) = g (-1))
    (h_nat : f.comp Int.ofNatHom.toMonoidHom = g.comp Int.ofNatHom.toMonoidHom) : f = g := by
  ext (x | x)
  · 

Proof state:
case h.ofNat
F : Type u_1
ι : Type u_2
α : Type u_3
β : Type u_4
M : Type u_5
inst✝ : Monoid M
f g : ℤ →* M
h_neg_one : f (-1) = g (-1)
h_nat : comp f ↑ofNatHom = comp g ↑ofNatHom
x : ℕ
⊢ f (ofNat x) = g (ofNat x)

Next tactic:
exact (FunLike.congr_fun h_nat x : _)