l3lab/ntp-mathlib huggingface dataset:
theorem norm_of_mem_sphere {x : Fin n → ℕ} (hx : x ∈ sphere n d k) :
    ‖(WithLp.equiv 2 _).symm ((↑) ∘ x : Fin n → ℝ)‖ = Real.sqrt k := by
  

Proof state:
α : Type u_1
β : Type u_2
n d k N : ℕ
x✝ x : Fin n → ℕ
hx : x ∈ sphere n d k
⊢ ‖(WithLp.equiv 2 (Fin n → ℝ)).symm (Nat.cast ∘ x)‖ = Real.sqrt ↑k

Next tactic:
rw [EuclideanSpace.norm_eq]
theorem norm_of_mem_sphere {x : Fin n → ℕ} (hx : x ∈ sphere n d k) :
    ‖(WithLp.equiv 2 _).symm ((↑) ∘ x : Fin n → ℝ)‖ = Real.sqrt k := by
  rw [EuclideanSpace.norm_eq]
  

Proof state:
α : Type u_1
β : Type u_2
n d k N : ℕ
x✝ x : Fin n → ℕ
hx : x ∈ sphere n d k
⊢ Real.sqrt (∑ i : Fin n, ‖(WithLp.equiv 2 (Fin n → ℝ)).symm (Nat.cast ∘ x) i‖ ^ 2) = Real.sqrt ↑k

Next tactic:
dsimp
theorem norm_of_mem_sphere {x : Fin n → ℕ} (hx : x ∈ sphere n d k) :
    ‖(WithLp.equiv 2 _).symm ((↑) ∘ x : Fin n → ℝ)‖ = Real.sqrt k := by
  rw [EuclideanSpace.norm_eq]
  dsimp
  

Proof state:
α : Type u_1
β : Type u_2
n d k N : ℕ
x✝ x : Fin n → ℕ
hx : x ∈ sphere n d k
⊢ Real.sqrt (∑ i : Fin n, |↑(x i)| ^ 2) = Real.sqrt ↑k

Next tactic:
simp_rw [abs_cast, ← cast_pow, ← cast_sum, (mem_filter.1 hx).2]
theorem sphere_subset_preimage_metric_sphere : (sphere n d k : Set (Fin n → ℕ)) ⊆
    (fun x : Fin n → ℕ => (WithLp.equiv 2 _).symm ((↑) ∘ x : Fin n → ℝ)) ⁻¹'
      Metric.sphere (0 : PiLp 2 fun _ : Fin n => ℝ) (Real.sqrt k) :=
  fun x hx => by 

Proof state:
α : Type u_1
β : Type u_2
n d k N : ℕ
x✝ x : Fin n → ℕ
hx : x ∈ ↑(sphere n d k)
⊢ x ∈ (fun x => (WithLp.equiv 2 (Fin n → ℝ)).symm (Nat.cast ∘ x)) ⁻¹' Metric.sphere 0 (Real.sqrt ↑k)

Next tactic:
rw [Set.mem_preimage, mem_sphere_zero_iff_norm, norm_of_mem_sphere hx]
/-- The map that appears in Behrend's bound on Roth numbers. -/
@[simps]
def map (d : ℕ) : (Fin n → ℕ) →+ ℕ where
  toFun a := ∑ i, a i * d ^ (i : ℕ)
  map_zero' := by 

Proof state:
α : Type u_1
β : Type u_2
n d✝ k N : ℕ
x : Fin n → ℕ
d : ℕ
⊢ (fun a => ∑ i : Fin n, a i * d ^ ↑i) 0 = 0

Next tactic:
simp_rw [Pi.zero_apply, zero_mul, sum_const_zero]
/-- The map that appears in Behrend's bound on Roth numbers. -/
@[simps]
def map (d : ℕ) : (Fin n → ℕ) →+ ℕ where
  toFun a := ∑ i, a i * d ^ (i : ℕ)
  map_zero' := by simp_rw [Pi.zero_apply, zero_mul, sum_const_zero]
  map_add' a b := by 

Proof state:
α : Type u_1
β : Type u_2
n d✝ k N : ℕ
x : Fin n → ℕ
d : ℕ
a b : Fin n → ℕ
⊢ ZeroHom.toFun
      { toFun := fun a => ∑ i : Fin n, a i * d ^ ↑i, map_zero' := (_ : (fun a => ∑ i : Fin n, a i * d ^ ↑i) 0 = 0) }
      (a + b) =
    ZeroHom.toFun
        { toFun := fun a => ∑ i : Fin n, a i * d ^ ↑i, map_zero' := (_ : (fun a => ∑ i : Fin n, a i * d ^ ↑i) 0 = 0) }
        a +
      ZeroHom.toFun
        { toFun := fun a => ∑ i : Fin n, a i * d ^ ↑i, map_zero' := (_ : (fun a => ∑ i : Fin n, a i * d ^ ↑i) 0 = 0) } b

Next tactic:
simp_rw [Pi.add_apply, add_mul, sum_add_distrib]
theorem map_zero (d : ℕ) (a : Fin 0 → ℕ) : map d a = 0 := by 

Proof state:
α : Type u_1
β : Type u_2
n d✝ k N : ℕ
x : Fin n → ℕ
d : ℕ
a : Fin 0 → ℕ
⊢ (map d) a = 0

Next tactic:
simp [map]
theorem map_succ (a : Fin (n + 1) → ℕ) :
    map d a = a 0 + (∑ x : Fin n, a x.succ * d ^ (x : ℕ)) * d := by
  

Proof state:
α : Type u_1
β : Type u_2
n d k N : ℕ
x : Fin n → ℕ
a : Fin (n + 1) → ℕ
⊢ (map d) a = a 0 + (∑ x : Fin n, a (Fin.succ x) * d ^ ↑x) * d

Next tactic:
simp [map, Fin.sum_univ_succ, _root_.pow_succ', ← mul_assoc, ← sum_mul]
theorem map_monotone (d : ℕ) : Monotone (map d : (Fin n → ℕ) → ℕ) := fun x y h => by
  

Proof state:
α : Type u_1
β : Type u_2
n d✝ k N : ℕ
x✝ : Fin n → ℕ
d : ℕ
x y : Fin n → ℕ
h : x ≤ y
⊢ (map d) x ≤ (map d) y

Next tactic:
dsimp
theorem map_monotone (d : ℕ) : Monotone (map d : (Fin n → ℕ) → ℕ) := fun x y h => by
  dsimp; 

Proof state:
α : Type u_1
β : Type u_2
n d✝ k N : ℕ
x✝ : Fin n → ℕ
d : ℕ
x y : Fin n → ℕ
h : x ≤ y
⊢ ∑ i : Fin n, x i * d ^ ↑i ≤ ∑ i : Fin n, y i * d ^ ↑i

Next tactic:
exact sum_le_sum fun i _ => Nat.mul_le_mul_right _ <| h i
theorem map_mod (a : Fin n.succ → ℕ) : map d a % d = a 0 % d := by
  

Proof state:
α : Type u_1
β : Type u_2
n d k N : ℕ
x : Fin n → ℕ
a : Fin (succ n) → ℕ
⊢ (map d) a % d = a 0 % d

Next tactic:
rw [map_succ, Nat.add_mul_mod_self_right]
theorem map_eq_iff {x₁ x₂ : Fin n.succ → ℕ} (hx₁ : ∀ i, x₁ i < d) (hx₂ : ∀ i, x₂ i < d) :
    map d x₁ = map d x₂ ↔ x₁ 0 = x₂ 0 ∧ map d (x₁ ∘ Fin.succ) = map d (x₂ ∘ Fin.succ) := by
  

Proof state:
α : Type u_1
β : Type u_2
n d k N : ℕ
x : Fin n → ℕ
x₁ x₂ : Fin (succ n) → ℕ
hx₁ : ∀ (i : Fin (succ n)), x₁ i < d
hx₂ : ∀ (i : Fin (succ n)), x₂ i < d
⊢ (map d) x₁ = (map d) x₂ ↔ x₁ 0 = x₂ 0 ∧ (map d) (x₁ ∘ Fin.succ) = (map d) (x₂ ∘ Fin.succ)

Next tactic:
refine' ⟨fun h => _, fun h => by rw [map_succ', map_succ', h.1, h.2]⟩
theorem map_eq_iff {x₁ x₂ : Fin n.succ → ℕ} (hx₁ : ∀ i, x₁ i < d) (hx₂ : ∀ i, x₂ i < d) :
    map d x₁ = map d x₂ ↔ x₁ 0 = x₂ 0 ∧ map d (x₁ ∘ Fin.succ) = map d (x₂ ∘ Fin.succ) := by
  refine' ⟨fun h => _, fun h => by 

Proof state:
α : Type u_1
β : Type u_2
n d k N : ℕ
x : Fin n → ℕ
x₁ x₂ : Fin (succ n) → ℕ
hx₁ : ∀ (i : Fin (succ n)), x₁ i < d
hx₂ : ∀ (i : Fin (succ n)), x₂ i < d
h : x₁ 0 = x₂ 0 ∧ (map d) (x₁ ∘ Fin.succ) = (map d) (x₂ ∘ Fin.succ)
⊢ (map d) x₁ = (map d) x₂

Next tactic:
rw [map_succ', map_succ', h.1, h.2]
theorem map_eq_iff {x₁ x₂ : Fin n.succ → ℕ} (hx₁ : ∀ i, x₁ i < d) (hx₂ : ∀ i, x₂ i < d) :
    map d x₁ = map d x₂ ↔ x₁ 0 = x₂ 0 ∧ map d (x₁ ∘ Fin.succ) = map d (x₂ ∘ Fin.succ) := by
  refine' ⟨fun h => _, fun h => by rw [map_succ', map_succ', h.1, h.2]⟩
  

Proof state:
α : Type u_1
β : Type u_2
n d k N : ℕ
x : Fin n → ℕ
x₁ x₂ : Fin (succ n) → ℕ
hx₁ : ∀ (i : Fin (succ n)), x₁ i < d
hx₂ : ∀ (i : Fin (succ n)), x₂ i < d
h : (map d) x₁ = (map d) x₂
⊢ x₁ 0 = x₂ 0 ∧ (map d) (x₁ ∘ Fin.succ) = (map d) (x₂ ∘ Fin.succ)

Next tactic:
have : x₁ 0 = x₂ 0 := by
    rw [← mod_eq_of_lt (hx₁ _), ← map_mod, ← mod_eq_of_lt (hx₂ _), ← map_mod, h]
theorem map_eq_iff {x₁ x₂ : Fin n.succ → ℕ} (hx₁ : ∀ i, x₁ i < d) (hx₂ : ∀ i, x₂ i < d) :
    map d x₁ = map d x₂ ↔ x₁ 0 = x₂ 0 ∧ map d (x₁ ∘ Fin.succ) = map d (x₂ ∘ Fin.succ) := by
  refine' ⟨fun h => _, fun h => by rw [map_succ', map_succ', h.1, h.2]⟩
  have : x₁ 0 = x₂ 0 := by
    

Proof state:
α : Type u_1
β : Type u_2
n d k N : ℕ
x : Fin n → ℕ
x₁ x₂ : Fin (succ n) → ℕ
hx₁ : ∀ (i : Fin (succ n)), x₁ i < d
hx₂ : ∀ (i : Fin (succ n)), x₂ i < d
h : (map d) x₁ = (map d) x₂
⊢ x₁ 0 = x₂ 0

Next tactic:
rw [← mod_eq_of_lt (hx₁ _), ← map_mod, ← mod_eq_of_lt (hx₂ _), ← map_mod, h]
theorem map_eq_iff {x₁ x₂ : Fin n.succ → ℕ} (hx₁ : ∀ i, x₁ i < d) (hx₂ : ∀ i, x₂ i < d) :
    map d x₁ = map d x₂ ↔ x₁ 0 = x₂ 0 ∧ map d (x₁ ∘ Fin.succ) = map d (x₂ ∘ Fin.succ) := by
  refine' ⟨fun h => _, fun h => by rw [map_succ', map_succ', h.1, h.2]⟩
  have : x₁ 0 = x₂ 0 := by
    rw [← mod_eq_of_lt (hx₁ _), ← map_mod, ← mod_eq_of_lt (hx₂ _), ← map_mod, h]
  

Proof state:
α : Type u_1
β : Type u_2
n d k N : ℕ
x : Fin n → ℕ
x₁ x₂ : Fin (succ n) → ℕ
hx₁ : ∀ (i : Fin (succ n)), x₁ i < d
hx₂ : ∀ (i : Fin (succ n)), x₂ i < d
h : (map d) x₁ = (map d) x₂
this : x₁ 0 = x₂ 0
⊢ x₁ 0 = x₂ 0 ∧ (map d) (x₁ ∘ Fin.succ) = (map d) (x₂ ∘ Fin.succ)

Next tactic:
rw [map_succ, map_succ, this, add_right_inj, mul_eq_mul_right_iff] at h
theorem map_eq_iff {x₁ x₂ : Fin n.succ → ℕ} (hx₁ : ∀ i, x₁ i < d) (hx₂ : ∀ i, x₂ i < d) :
    map d x₁ = map d x₂ ↔ x₁ 0 = x₂ 0 ∧ map d (x₁ ∘ Fin.succ) = map d (x₂ ∘ Fin.succ) := by
  refine' ⟨fun h => _, fun h => by rw [map_succ', map_succ', h.1, h.2]⟩
  have : x₁ 0 = x₂ 0 := by
    rw [← mod_eq_of_lt (hx₁ _), ← map_mod, ← mod_eq_of_lt (hx₂ _), ← map_mod, h]
  rw [map_succ, map_succ, this, add_right_inj, mul_eq_mul_right_iff] at h
  

Proof state:
α : Type u_1
β : Type u_2
n d k N : ℕ
x : Fin n → ℕ
x₁ x₂ : Fin (succ n) → ℕ
hx₁ : ∀ (i : Fin (succ n)), x₁ i < d
hx₂ : ∀ (i : Fin (succ n)), x₂ i < d
h : ∑ x : Fin n, x₁ (Fin.succ x) * d ^ ↑x = ∑ x : Fin n, x₂ (Fin.succ x) * d ^ ↑x ∨ d = 0
this : x₁ 0 = x₂ 0
⊢ x₁ 0 = x₂ 0 ∧ (map d) (x₁ ∘ Fin.succ) = (map d) (x₂ ∘ Fin.succ)

Next tactic:
exact ⟨this, h.resolve_right (pos_of_gt (hx₁ 0)).ne'⟩
theorem map_injOn : {x : Fin n → ℕ | ∀ i, x i < d}.InjOn (map d) := by
  

Proof state:
α : Type u_1
β : Type u_2
n d k N : ℕ
x : Fin n → ℕ
⊢ Set.InjOn ⇑(map d) {x | ∀ (i : Fin n), x i < d}

Next tactic:
intro x₁ hx₁ x₂ hx₂ h
theorem map_injOn : {x : Fin n → ℕ | ∀ i, x i < d}.InjOn (map d) := by
  intro x₁ hx₁ x₂ hx₂ h
  

Proof state:
α : Type u_1
β : Type u_2
n d k N : ℕ
x x₁ : Fin n → ℕ
hx₁ : x₁ ∈ {x | ∀ (i : Fin n), x i < d}
x₂ : Fin n → ℕ
hx₂ : x₂ ∈ {x | ∀ (i : Fin n), x i < d}
h : (map d) x₁ = (map d) x₂
⊢ x₁ = x₂

Next tactic:
induction' n with n ih
theorem map_injOn : {x : Fin n → ℕ | ∀ i, x i < d}.InjOn (map d) := by
  intro x₁ hx₁ x₂ hx₂ h
  induction' n with n ih
  · 

Proof state:
case zero
α : Type u_1
β : Type u_2
n d k N : ℕ
x x₁ : Fin zero → ℕ
hx₁ : x₁ ∈ {x | ∀ (i : Fin zero), x i < d}
x₂ : Fin zero → ℕ
hx₂ : x₂ ∈ {x | ∀ (i : Fin zero), x i < d}
h : (map d) x₁ = (map d) x₂
⊢ x₁ = x₂

Next tactic:
simp [eq_iff_true_of_subsingleton]
theorem map_injOn : {x : Fin n → ℕ | ∀ i, x i < d}.InjOn (map d) := by
  intro x₁ hx₁ x₂ hx₂ h
  induction' n with n ih
  · simp [eq_iff_true_of_subsingleton]
  

Proof state:
case succ
α : Type u_1
β : Type u_2
n✝ d k N n : ℕ
ih :
  ∀ {x : Fin n → ℕ} ⦃x₁ : Fin n → ℕ⦄,
    x₁ ∈ {x | ∀ (i : Fin n), x i < d} →
      ∀ ⦃x₂ : Fin n → ℕ⦄, x₂ ∈ {x | ∀ (i : Fin n), x i < d} → (map d) x₁ = (map d) x₂ → x₁ = x₂
x x₁ : Fin (succ n) → ℕ
hx₁ : x₁ ∈ {x | ∀ (i : Fin (succ n)), x i < d}
x₂ : Fin (succ n) → ℕ
hx₂ : x₂ ∈ {x | ∀ (i : Fin (succ n)), x i < d}
h : (map d) x₁ = (map d) x₂
⊢ x₁ = x₂

Next tactic:
rw [forall_const] at ih
theorem map_injOn : {x : Fin n → ℕ | ∀ i, x i < d}.InjOn (map d) := by
  intro x₁ hx₁ x₂ hx₂ h
  induction' n with n ih
  · simp [eq_iff_true_of_subsingleton]
  rw [forall_const] at ih
  

Proof state:
case succ
α : Type u_1
β : Type u_2
n✝ d k N n : ℕ
ih :
  ∀ ⦃x₁ : Fin n → ℕ⦄,
    x₁ ∈ {x | ∀ (i : Fin n), x i < d} →
      ∀ ⦃x₂ : Fin n → ℕ⦄, x₂ ∈ {x | ∀ (i : Fin n), x i < d} → (map d) x₁ = (map d) x₂ → x₁ = x₂
x x₁ : Fin (succ n) → ℕ
hx₁ : x₁ ∈ {x | ∀ (i : Fin (succ n)), x i < d}
x₂ : Fin (succ n) → ℕ
hx₂ : x₂ ∈ {x | ∀ (i : Fin (succ n)), x i < d}
h : (map d) x₁ = (map d) x₂
⊢ x₁ = x₂

Next tactic:
ext i
theorem map_injOn : {x : Fin n → ℕ | ∀ i, x i < d}.InjOn (map d) := by
  intro x₁ hx₁ x₂ hx₂ h
  induction' n with n ih
  · simp [eq_iff_true_of_subsingleton]
  rw [forall_const] at ih
  ext i
  

Proof state:
case succ.h
α : Type u_1
β : Type u_2
n✝ d k N n : ℕ
ih :
  ∀ ⦃x₁ : Fin n → ℕ⦄,
    x₁ ∈ {x | ∀ (i : Fin n), x i < d} →
      ∀ ⦃x₂ : Fin n → ℕ⦄, x₂ ∈ {x | ∀ (i : Fin n), x i < d} → (map d) x₁ = (map d) x₂ → x₁ = x₂
x x₁ : Fin (succ n) → ℕ
hx₁ : x₁ ∈ {x | ∀ (i : Fin (succ n)), x i < d}
x₂ : Fin (succ n) → ℕ
hx₂ : x₂ ∈ {x | ∀ (i : Fin (succ n)), x i < d}
h : (map d) x₁ = (map d) x₂
i : Fin (succ n)
⊢ x₁ i = x₂ i

Next tactic:
have x := (map_eq_iff hx₁ hx₂).1 h
theorem map_injOn : {x : Fin n → ℕ | ∀ i, x i < d}.InjOn (map d) := by
  intro x₁ hx₁ x₂ hx₂ h
  induction' n with n ih
  · simp [eq_iff_true_of_subsingleton]
  rw [forall_const] at ih
  ext i
  have x := (map_eq_iff hx₁ hx₂).1 h
  

Proof state:
case succ.h
α : Type u_1
β : Type u_2
n✝ d k N n : ℕ
ih :
  ∀ ⦃x₁ : Fin n → ℕ⦄,
    x₁ ∈ {x | ∀ (i : Fin n), x i < d} →
      ∀ ⦃x₂ : Fin n → ℕ⦄, x₂ ∈ {x | ∀ (i : Fin n), x i < d} → (map d) x₁ = (map d) x₂ → x₁ = x₂
x✝ x₁ : Fin (succ n) → ℕ
hx₁ : x₁ ∈ {x | ∀ (i : Fin (succ n)), x i < d}
x₂ : Fin (succ n) → ℕ
hx₂ : x₂ ∈ {x | ∀ (i : Fin (succ n)), x i < d}
h : (map d) x₁ = (map d) x₂
i : Fin (succ n)
x : x₁ 0 = x₂ 0 ∧ (map d) ((fun i => x₁ i) ∘ Fin.succ) = (map d) ((fun i => x₂ i) ∘ Fin.succ)
⊢ x₁ i = x₂ i

Next tactic:
refine' Fin.cases x.1 (congr_fun <| ih (fun _ => _) (fun _ => _) x.2) i
theorem map_injOn : {x : Fin n → ℕ | ∀ i, x i < d}.InjOn (map d) := by
  intro x₁ hx₁ x₂ hx₂ h
  induction' n with n ih
  · simp [eq_iff_true_of_subsingleton]
  rw [forall_const] at ih
  ext i
  have x := (map_eq_iff hx₁ hx₂).1 h
  refine' Fin.cases x.1 (congr_fun <| ih (fun _ => _) (fun _ => _) x.2) i
  · 

Proof state:
case succ.h.refine'_1
α : Type u_1
β : Type u_2
n✝ d k N n : ℕ
ih :
  ∀ ⦃x₁ : Fin n → ℕ⦄,
    x₁ ∈ {x | ∀ (i : Fin n), x i < d} →
      ∀ ⦃x₂ : Fin n → ℕ⦄, x₂ ∈ {x | ∀ (i : Fin n), x i < d} → (map d) x₁ = (map d) x₂ → x₁ = x₂
x✝¹ x₁ : Fin (succ n) → ℕ
hx₁ : x₁ ∈ {x | ∀ (i : Fin (succ n)), x i < d}
x₂ : Fin (succ n) → ℕ
hx₂ : x₂ ∈ {x | ∀ (i : Fin (succ n)), x i < d}
h : (map d) x₁ = (map d) x₂
i : Fin (succ n)
x : x₁ 0 = x₂ 0 ∧ (map d) ((fun i => x₁ i) ∘ Fin.succ) = (map d) ((fun i => x₂ i) ∘ Fin.succ)
x✝ : Fin n
⊢ x₁ (Fin.succ x✝) < d

Next tactic:
exact hx₁ _
theorem map_injOn : {x : Fin n → ℕ | ∀ i, x i < d}.InjOn (map d) := by
  intro x₁ hx₁ x₂ hx₂ h
  induction' n with n ih
  · simp [eq_iff_true_of_subsingleton]
  rw [forall_const] at ih
  ext i
  have x := (map_eq_iff hx₁ hx₂).1 h
  refine' Fin.cases x.1 (congr_fun <| ih (fun _ => _) (fun _ => _) x.2) i
  · exact hx₁ _
  · 

Proof state:
case succ.h.refine'_2
α : Type u_1
β : Type u_2
n✝ d k N n : ℕ
ih :
  ∀ ⦃x₁ : Fin n → ℕ⦄,
    x₁ ∈ {x | ∀ (i : Fin n), x i < d} →
      ∀ ⦃x₂ : Fin n → ℕ⦄, x₂ ∈ {x | ∀ (i : Fin n), x i < d} → (map d) x₁ = (map d) x₂ → x₁ = x₂
x✝¹ x₁ : Fin (succ n) → ℕ
hx₁ : x₁ ∈ {x | ∀ (i : Fin (succ n)), x i < d}
x₂ : Fin (succ n) → ℕ
hx₂ : x₂ ∈ {x | ∀ (i : Fin (succ n)), x i < d}
h : (map d) x₁ = (map d) x₂
i : Fin (succ n)
x : x₁ 0 = x₂ 0 ∧ (map d) ((fun i => x₁ i) ∘ Fin.succ) = (map d) ((fun i => x₂ i) ∘ Fin.succ)
x✝ : Fin n
⊢ x₂ (Fin.succ x✝) < d

Next tactic:
exact hx₂ _
nonrec theorem addSalemSpencer_sphere : AddSalemSpencer (sphere n d k : Set (Fin n → ℕ)) := by
  

Proof state:
α : Type u_1
β : Type u_2
n d k N : ℕ
x : Fin n → ℕ
⊢ AddSalemSpencer ↑(sphere n d k)

Next tactic:
set f : (Fin n → ℕ) →+ EuclideanSpace ℝ (Fin n) :=
    { toFun := fun f => ((↑) : ℕ → ℝ) ∘ f
      map_zero' := funext fun _ => cast_zero
      map_add' := fun _ _ => funext fun _ => cast_add _ _ }
nonrec theorem addSalemSpencer_sphere : AddSalemSpencer (sphere n d k : Set (Fin n → ℕ)) := by
  set f : (Fin n → ℕ) →+ EuclideanSpace ℝ (Fin n) :=
    { toFun := fun f => ((↑) : ℕ → ℝ) ∘ f
      map_zero' := funext fun _ => cast_zero
      map_add' := fun _ _ => funext fun _ => cast_add _ _ }
  

Proof state:
α : Type u_1
β : Type u_2
n d k N : ℕ
x : Fin n → ℕ
f : (Fin n → ℕ) →+ EuclideanSpace ℝ (Fin n) :=
  { toZeroHom := { toFun := fun f => Nat.cast ∘ f, map_zero' := (_ : (fun f => Nat.cast ∘ f) 0 = 0) },
    map_add' :=
      (_ :
        ∀ (x x_1 : Fin n → ℕ),
          ZeroHom.toFun { toFun := fun f => Nat.cast ∘ f, map_zero' := (_ : (fun f => Nat.cast ∘ f) 0 = 0) } (x + x_1) =
            ZeroHom.toFun { toFun := fun f => Nat.cast ∘ f, map_zero' := (_ : (fun f => Nat.cast ∘ f) 0 = 0) } x +
              ZeroHom.toFun { toFun := fun f => Nat.cast ∘ f, map_zero' := (_ : (fun f => Nat.cast ∘ f) 0 = 0) } x_1) }
⊢ AddSalemSpencer ↑(sphere n d k)

Next tactic:
refine' AddSalemSpencer.of_image (f.toAddFreimanHom (sphere n d k : Set (Fin n → ℕ)) 2) _ _
nonrec theorem addSalemSpencer_sphere : AddSalemSpencer (sphere n d k : Set (Fin n → ℕ)) := by
  set f : (Fin n → ℕ) →+ EuclideanSpace ℝ (Fin n) :=
    { toFun := fun f => ((↑) : ℕ → ℝ) ∘ f
      map_zero' := funext fun _ => cast_zero
      map_add' := fun _ _ => funext fun _ => cast_add _ _ }
  refine' AddSalemSpencer.of_image (f.toAddFreimanHom (sphere n d k : Set (Fin n → ℕ)) 2) _ _
  · 

Proof state:
case refine'_1
α : Type u_1
β : Type u_2
n d k N : ℕ
x : Fin n → ℕ
f : (Fin n → ℕ) →+ EuclideanSpace ℝ (Fin n) :=
  { toZeroHom := { toFun := fun f => Nat.cast ∘ f, map_zero' := (_ : (fun f => Nat.cast ∘ f) 0 = 0) },
    map_add' :=
      (_ :
        ∀ (x x_1 : Fin n → ℕ),
          ZeroHom.toFun { toFun := fun f => Nat.cast ∘ f, map_zero' := (_ : (fun f => Nat.cast ∘ f) 0 = 0) } (x + x_1) =
            ZeroHom.toFun { toFun := fun f => Nat.cast ∘ f, map_zero' := (_ : (fun f => Nat.cast ∘ f) 0 = 0) } x +
              ZeroHom.toFun { toFun := fun f => Nat.cast ∘ f, map_zero' := (_ : (fun f => Nat.cast ∘ f) 0 = 0) } x_1) }
⊢ Set.InjOn ⇑(AddMonoidHom.toAddFreimanHom (↑(sphere n d k)) 2 f) ↑(sphere n d k)

Next tactic:
exact cast_injective.comp_left.injOn _
nonrec theorem addSalemSpencer_sphere : AddSalemSpencer (sphere n d k : Set (Fin n → ℕ)) := by
  set f : (Fin n → ℕ) →+ EuclideanSpace ℝ (Fin n) :=
    { toFun := fun f => ((↑) : ℕ → ℝ) ∘ f
      map_zero' := funext fun _ => cast_zero
      map_add' := fun _ _ => funext fun _ => cast_add _ _ }
  refine' AddSalemSpencer.of_image (f.toAddFreimanHom (sphere n d k : Set (Fin n → ℕ)) 2) _ _
  · exact cast_injective.comp_left.injOn _
  

Proof state:
case refine'_2
α : Type u_1
β : Type u_2
n d k N : ℕ
x : Fin n → ℕ
f : (Fin n → ℕ) →+ EuclideanSpace ℝ (Fin n) :=
  { toZeroHom := { toFun := fun f => Nat.cast ∘ f, map_zero' := (_ : (fun f => Nat.cast ∘ f) 0 = 0) },
    map_add' :=
      (_ :
        ∀ (x x_1 : Fin n → ℕ),
          ZeroHom.toFun { toFun := fun f => Nat.cast ∘ f, map_zero' := (_ : (fun f => Nat.cast ∘ f) 0 = 0) } (x + x_1) =
            ZeroHom.toFun { toFun := fun f => Nat.cast ∘ f, map_zero' := (_ : (fun f => Nat.cast ∘ f) 0 = 0) } x +
              ZeroHom.toFun { toFun := fun f => Nat.cast ∘ f, map_zero' := (_ : (fun f => Nat.cast ∘ f) 0 = 0) } x_1) }
⊢ AddSalemSpencer (⇑(AddMonoidHom.toAddFreimanHom (↑(sphere n d k)) 2 f) '' ↑(sphere n d k))

Next tactic:
refine' (addSalemSpencer_sphere 0 <| Real.sqrt k).mono (Set.image_subset_iff.2 fun x => _)
nonrec theorem addSalemSpencer_sphere : AddSalemSpencer (sphere n d k : Set (Fin n → ℕ)) := by
  set f : (Fin n → ℕ) →+ EuclideanSpace ℝ (Fin n) :=
    { toFun := fun f => ((↑) : ℕ → ℝ) ∘ f
      map_zero' := funext fun _ => cast_zero
      map_add' := fun _ _ => funext fun _ => cast_add _ _ }
  refine' AddSalemSpencer.of_image (f.toAddFreimanHom (sphere n d k : Set (Fin n → ℕ)) 2) _ _
  · exact cast_injective.comp_left.injOn _
  refine' (addSalemSpencer_sphere 0 <| Real.sqrt k).mono (Set.image_subset_iff.2 fun x => _)
  

Proof state:
case refine'_2
α : Type u_1
β : Type u_2
n d k N : ℕ
x✝ : Fin n → ℕ
f : (Fin n → ℕ) →+ EuclideanSpace ℝ (Fin n) :=
  { toZeroHom := { toFun := fun f => Nat.cast ∘ f, map_zero' := (_ : (fun f => Nat.cast ∘ f) 0 = 0) },
    map_add' :=
      (_ :
        ∀ (x x_1 : Fin n → ℕ),
          ZeroHom.toFun { toFun := fun f => Nat.cast ∘ f, map_zero' := (_ : (fun f => Nat.cast ∘ f) 0 = 0) } (x + x_1) =
            ZeroHom.toFun { toFun := fun f => Nat.cast ∘ f, map_zero' := (_ : (fun f => Nat.cast ∘ f) 0 = 0) } x +
              ZeroHom.toFun { toFun := fun f => Nat.cast ∘ f, map_zero' := (_ : (fun f => Nat.cast ∘ f) 0 = 0) } x_1) }
x : Fin n → ℕ
⊢ x ∈ ↑(sphere n d k) → x ∈ ⇑(AddMonoidHom.toAddFreimanHom (↑(sphere n d k)) 2 f) ⁻¹' Metric.sphere 0 (Real.sqrt ↑k)

Next tactic:
rw [Set.mem_preimage, mem_sphere_zero_iff_norm]
nonrec theorem addSalemSpencer_sphere : AddSalemSpencer (sphere n d k : Set (Fin n → ℕ)) := by
  set f : (Fin n → ℕ) →+ EuclideanSpace ℝ (Fin n) :=
    { toFun := fun f => ((↑) : ℕ → ℝ) ∘ f
      map_zero' := funext fun _ => cast_zero
      map_add' := fun _ _ => funext fun _ => cast_add _ _ }
  refine' AddSalemSpencer.of_image (f.toAddFreimanHom (sphere n d k : Set (Fin n → ℕ)) 2) _ _
  · exact cast_injective.comp_left.injOn _
  refine' (addSalemSpencer_sphere 0 <| Real.sqrt k).mono (Set.image_subset_iff.2 fun x => _)
  rw [Set.mem_preimage, mem_sphere_zero_iff_norm]
  

Proof state:
case refine'_2
α : Type u_1
β : Type u_2
n d k N : ℕ
x✝ : Fin n → ℕ
f : (Fin n → ℕ) →+ EuclideanSpace ℝ (Fin n) :=
  { toZeroHom := { toFun := fun f => Nat.cast ∘ f, map_zero' := (_ : (fun f => Nat.cast ∘ f) 0 = 0) },
    map_add' :=
      (_ :
        ∀ (x x_1 : Fin n → ℕ),
          ZeroHom.toFun { toFun := fun f => Nat.cast ∘ f, map_zero' := (_ : (fun f => Nat.cast ∘ f) 0 = 0) } (x + x_1) =
            ZeroHom.toFun { toFun := fun f => Nat.cast ∘ f, map_zero' := (_ : (fun f => Nat.cast ∘ f) 0 = 0) } x +
              ZeroHom.toFun { toFun := fun f => Nat.cast ∘ f, map_zero' := (_ : (fun f => Nat.cast ∘ f) 0 = 0) } x_1) }
x : Fin n → ℕ
⊢ x ∈ ↑(sphere n d k) → ‖(AddMonoidHom.toAddFreimanHom (↑(sphere n d k)) 2 f) x‖ = Real.sqrt ↑k

Next tactic:
exact norm_of_mem_sphere
theorem addSalemSpencer_image_sphere :
    AddSalemSpencer ((sphere n d k).image (map (2 * d - 1)) : Set ℕ) := by
  

Proof state:
α : Type u_1
β : Type u_2
n d k N : ℕ
x : Fin n → ℕ
⊢ AddSalemSpencer ↑(image (⇑(map (2 * d - 1))) (sphere n d k))

Next tactic:
rw [coe_image]
theorem addSalemSpencer_image_sphere :
    AddSalemSpencer ((sphere n d k).image (map (2 * d - 1)) : Set ℕ) := by
  rw [coe_image]
  

Proof state:
α : Type u_1
β : Type u_2
n d k N : ℕ
x : Fin n → ℕ
⊢ AddSalemSpencer (⇑(map (2 * d - 1)) '' ↑(sphere n d k))

Next tactic:
refine' @AddSalemSpencer.image _ (Fin n → ℕ) ℕ _ _ (sphere n d k) _ (map (2 * d - 1))
    (map_injOn.mono _) addSalemSpencer_sphere
theorem addSalemSpencer_image_sphere :
    AddSalemSpencer ((sphere n d k).image (map (2 * d - 1)) : Set ℕ) := by
  rw [coe_image]
  refine' @AddSalemSpencer.image _ (Fin n → ℕ) ℕ _ _ (sphere n d k) _ (map (2 * d - 1))
    (map_injOn.mono _) addSalemSpencer_sphere
  · 

Proof state:
case refine'_1
α : Type u_1
β : Type u_2
n d k N : ℕ
x : Fin n → ℕ
⊢ Fin n → ℕ

Next tactic:
exact x
theorem addSalemSpencer_image_sphere :
    AddSalemSpencer ((sphere n d k).image (map (2 * d - 1)) : Set ℕ) := by
  rw [coe_image]
  refine' @AddSalemSpencer.image _ (Fin n → ℕ) ℕ _ _ (sphere n d k) _ (map (2 * d - 1))
    (map_injOn.mono _) addSalemSpencer_sphere
  · exact x
  

Proof state:
case refine'_2
α : Type u_1
β : Type u_2
n d k N : ℕ
x : Fin n → ℕ
⊢ ↑(sphere n d k) + ↑(sphere n d k) ⊆ {x | ∀ (i : Fin n), x i < 2 * d - 1}

Next tactic:
rw [Set.add_subset_iff]
theorem addSalemSpencer_image_sphere :
    AddSalemSpencer ((sphere n d k).image (map (2 * d - 1)) : Set ℕ) := by
  rw [coe_image]
  refine' @AddSalemSpencer.image _ (Fin n → ℕ) ℕ _ _ (sphere n d k) _ (map (2 * d - 1))
    (map_injOn.mono _) addSalemSpencer_sphere
  · exact x
  rw [Set.add_subset_iff]
  

Proof state:
case refine'_2
α : Type u_1
β : Type u_2
n d k N : ℕ
x : Fin n → ℕ
⊢ ∀ x ∈ ↑(sphere n d k), ∀ y ∈ ↑(sphere n d k), x + y ∈ {x | ∀ (i : Fin n), x i < 2 * d - 1}

Next tactic:
rintro a ha b hb i
theorem addSalemSpencer_image_sphere :
    AddSalemSpencer ((sphere n d k).image (map (2 * d - 1)) : Set ℕ) := by
  rw [coe_image]
  refine' @AddSalemSpencer.image _ (Fin n → ℕ) ℕ _ _ (sphere n d k) _ (map (2 * d - 1))
    (map_injOn.mono _) addSalemSpencer_sphere
  · exact x
  rw [Set.add_subset_iff]
  rintro a ha b hb i
  

Proof state:
case refine'_2
α : Type u_1
β : Type u_2
n d k N : ℕ
x a : Fin n → ℕ
ha : a ∈ ↑(sphere n d k)
b : Fin n → ℕ
hb : b ∈ ↑(sphere n d k)
i : Fin n
⊢ (a + b) i < 2 * d - 1

Next tactic:
have hai := mem_box.1 (sphere_subset_box ha) i
theorem addSalemSpencer_image_sphere :
    AddSalemSpencer ((sphere n d k).image (map (2 * d - 1)) : Set ℕ) := by
  rw [coe_image]
  refine' @AddSalemSpencer.image _ (Fin n → ℕ) ℕ _ _ (sphere n d k) _ (map (2 * d - 1))
    (map_injOn.mono _) addSalemSpencer_sphere
  · exact x
  rw [Set.add_subset_iff]
  rintro a ha b hb i
  have hai := mem_box.1 (sphere_subset_box ha) i
  

Proof state:
case refine'_2
α : Type u_1
β : Type u_2
n d k N : ℕ
x a : Fin n → ℕ
ha : a ∈ ↑(sphere n d k)
b : Fin n → ℕ
hb : b ∈ ↑(sphere n d k)
i : Fin n
hai : a i < d
⊢ (a + b) i < 2 * d - 1

Next tactic:
have hbi := mem_box.1 (sphere_subset_box hb) i
theorem addSalemSpencer_image_sphere :
    AddSalemSpencer ((sphere n d k).image (map (2 * d - 1)) : Set ℕ) := by
  rw [coe_image]
  refine' @AddSalemSpencer.image _ (Fin n → ℕ) ℕ _ _ (sphere n d k) _ (map (2 * d - 1))
    (map_injOn.mono _) addSalemSpencer_sphere
  · exact x
  rw [Set.add_subset_iff]
  rintro a ha b hb i
  have hai := mem_box.1 (sphere_subset_box ha) i
  have hbi := mem_box.1 (sphere_subset_box hb) i
  

Proof state:
case refine'_2
α : Type u_1
β : Type u_2
n d k N : ℕ
x a : Fin n → ℕ
ha : a ∈ ↑(sphere n d k)
b : Fin n → ℕ
hb : b ∈ ↑(sphere n d k)
i : Fin n
hai : a i < d
hbi : b i < d
⊢ (a + b) i < 2 * d - 1

Next tactic:
rw [lt_tsub_iff_right, ← succ_le_iff, two_mul]