l3lab/ntp-mathlib huggingface dataset:
/-- If `F` is an exact additive functor, then `F` commutes with `Hᵢ` (up to natural isomorphism). -/
noncomputable def homology'FunctorIso (i : ι) :
    homology'Functor A c i ⋙ F ≅ F.mapHomologicalComplex c ⋙ homology'Functor B c i :=
  NatIso.ofComponents (fun X => homology'Iso F X i) (by
      intro X Y f
      dsimp
      rw [← Iso.inv_comp_eq, ← Category.assoc, ← Iso.eq_comp_inv]
      refine' coequalizer.hom_ext _
      dsimp [homology'Iso]
      simp only [PreservesCokernel.iso_inv]
      dsimp [homology'.map]
      simp only [← Category.assoc, cokernel.π_desc]
      simp only [Category.assoc, cokernelComparison_map_desc, cokernel.π_desc]
      simp only [π_comp_cokernelComparison, ← F.map_comp]
      erw [← kernelSubobjectIso_comp_kernel_map_assoc]
      simp only [HomologicalComplex.Hom.sqFrom_right, HomologicalComplex.Hom.sqFrom_left,
        F.mapHomologicalComplex_map_f, F.map_comp]
      dsimp [HomologicalComplex.dFrom, HomologicalComplex.Hom.next]
      rw [kernel_map_comp_preserves_kernel_iso_inv_assoc]
      conv_lhs => 

Proof state:
A : Type u
inst✝⁶ : Category.{v, u} A
inst✝⁵ : Abelian A
X✝ Y✝ Z : A
f✝ : X✝ ⟶ Y✝
g : Y✝ ⟶ Z
w : f✝ ≫ g = 0
ι : Type u_1
c : ComplexShape ι
B : Type u_2
inst✝⁴ : Category.{?u.309013, u_2} B
inst✝³ : Abelian B
F : A ⥤ B
inst✝² : Additive F
inst✝¹ : PreservesFiniteLimits F
inst✝ : PreservesFiniteColimits F
i : ι
X Y : HomologicalComplex A c
f : X ⟶ Y
| (kernelSubobjectIso (F.map (HomologicalComplex.d X i (ComplexShape.next c i)))).hom ≫
    (PreservesKernel.iso F (HomologicalComplex.d X i (ComplexShape.next c i))).inv ≫
      F.map (kernelSubobjectIso (HomologicalComplex.d X i (ComplexShape.next c i))).inv ≫
        F.map (kernelSubobjectMap (HomologicalComplex.Hom.sqFrom f i)) ≫
          F.map
            (cokernel.π
              (imageToKernel (HomologicalComplex.dTo Y i) (HomologicalComplex.d Y i (ComplexShape.next c i))
                (_ : HomologicalComplex.dTo Y i ≫ HomologicalComplex.dFrom Y i = 0)))

Next tactic:
erw [← F.map_comp_assoc]
/-- If `F` is an exact additive functor, then `F` commutes with `Hᵢ` (up to natural isomorphism). -/
noncomputable def homology'FunctorIso (i : ι) :
    homology'Functor A c i ⋙ F ≅ F.mapHomologicalComplex c ⋙ homology'Functor B c i :=
  NatIso.ofComponents (fun X => homology'Iso F X i) (by
      intro X Y f
      dsimp
      rw [← Iso.inv_comp_eq, ← Category.assoc, ← Iso.eq_comp_inv]
      refine' coequalizer.hom_ext _
      dsimp [homology'Iso]
      simp only [PreservesCokernel.iso_inv]
      dsimp [homology'.map]
      simp only [← Category.assoc, cokernel.π_desc]
      simp only [Category.assoc, cokernelComparison_map_desc, cokernel.π_desc]
      simp only [π_comp_cokernelComparison, ← F.map_comp]
      erw [← kernelSubobjectIso_comp_kernel_map_assoc]
      simp only [HomologicalComplex.Hom.sqFrom_right, HomologicalComplex.Hom.sqFrom_left,
        F.mapHomologicalComplex_map_f, F.map_comp]
      dsimp [HomologicalComplex.dFrom, HomologicalComplex.Hom.next]
      rw [kernel_map_comp_preserves_kernel_iso_inv_assoc]
      conv_lhs => erw [← F.map_comp_assoc]
      rotate_right; simp
      

Proof state:
A : Type u
inst✝⁶ : Category.{v, u} A
inst✝⁵ : Abelian A
X✝ Y✝ Z : A
f✝ : X✝ ⟶ Y✝
g : Y✝ ⟶ Z
w : f✝ ≫ g = 0
ι : Type u_1
c : ComplexShape ι
B : Type u_2
inst✝⁴ : Category.{?u.309013, u_2} B
inst✝³ : Abelian B
F : A ⥤ B
inst✝² : Additive F
inst✝¹ : PreservesFiniteLimits F
inst✝ : PreservesFiniteColimits F
i : ι
X Y : HomologicalComplex A c
f : X ⟶ Y
⊢ (kernelSubobjectIso (F.map (HomologicalComplex.d X i (ComplexShape.next c i)))).hom ≫
      (PreservesKernel.iso F (HomologicalComplex.d X i (ComplexShape.next c i))).inv ≫
        F.map
            ((kernelSubobjectIso (HomologicalComplex.d X i (ComplexShape.next c i))).inv ≫
              kernelSubobjectMap (HomologicalComplex.Hom.sqFrom f i)) ≫
          F.map
            (cokernel.π
              (imageToKernel (HomologicalComplex.dTo Y i) (HomologicalComplex.d Y i (ComplexShape.next c i))
                (_ : HomologicalComplex.dTo Y i ≫ HomologicalComplex.dFrom Y i = 0))) =
    (kernelSubobjectIso (F.map (HomologicalComplex.d X i (ComplexShape.next c i)))).hom ≫
      (PreservesKernel.iso F (HomologicalComplex.d X i (ComplexShape.next c i))).inv ≫
        F.map
            (kernel.map (HomologicalComplex.d X i (ComplexShape.next c i))
              (HomologicalComplex.d Y i (ComplexShape.next c i)) (HomologicalComplex.Hom.f f i)
              (HomologicalComplex.Hom.f f (ComplexShape.next c i))
              (_ :
                HomologicalComplex.d X i (ComplexShape.next c i) ≫ HomologicalComplex.Hom.f f (ComplexShape.next c i) =
                  HomologicalComplex.Hom.f f i ≫ HomologicalComplex.d Y i (ComplexShape.next c i))) ≫
          F.map (kernelSubobjectIso (HomologicalComplex.d Y i (ComplexShape.next c i))).inv ≫
            F.map
              (cokernel.π
                (imageToKernel (HomologicalComplex.dTo Y i) (HomologicalComplex.d Y i (ComplexShape.next c i))
                  (_ : HomologicalComplex.dTo Y i ≫ HomologicalComplex.dFrom Y i = 0)))

Next tactic:
rw [← kernel_map_comp_kernelSubobjectIso_inv]
/-- The (topological-space) closure of a subfield of a topological field is
itself a subfield. -/
def Subfield.topologicalClosure (K : Subfield α) : Subfield α :=
  { K.toSubring.topologicalClosure with
    carrier := _root_.closure (K : Set α)
    inv_mem' := fun x hx => by
      

Proof state:
K✝ : Type u_1
inst✝⁴ : DivisionRing K✝
inst✝³ : TopologicalSpace K✝
α : Type u_2
inst✝² : Field α
inst✝¹ : TopologicalSpace α
inst✝ : TopologicalDivisionRing α
K : Subfield α
src✝ : Subring α := Subring.topologicalClosure K.toSubring
x : α
hx :
  x ∈
    {
              toSubsemiring :=
                {
                  toSubmonoid :=
                    {
                      toSubsemigroup :=
                        { carrier := _root_.closure ↑K,
                          mul_mem' := (_ : ∀ {a b : α}, a ∈ src✝.carrier → b ∈ src✝.carrier → a * b ∈ src✝.carrier) },
                      one_mem' := (_ : 1 ∈ src✝.carrier) },
                  add_mem' := (_ : ∀ {a b : α}, a ∈ src✝.carrier → b ∈ src✝.carrier → a + b ∈ src✝.carrier),
                  zero_mem' := (_ : 0 ∈ src✝.carrier) },
              neg_mem' :=
                (_ : ∀ {x : α}, x ∈ src✝.carrier → -x ∈ src✝.carrier) }.toSubsemiring.toSubmonoid.toSubsemigroup.carrier
⊢ x⁻¹ ∈
    {
              toSubsemiring :=
                {
                  toSubmonoid :=
                    {
                      toSubsemigroup :=
                        { carrier := _root_.closure ↑K,
                          mul_mem' := (_ : ∀ {a b : α}, a ∈ src✝.carrier → b ∈ src✝.carrier → a * b ∈ src✝.carrier) },
                      one_mem' := (_ : 1 ∈ src✝.carrier) },
                  add_mem' := (_ : ∀ {a b : α}, a ∈ src✝.carrier → b ∈ src✝.carrier → a + b ∈ src✝.carrier),
                  zero_mem' := (_ : 0 ∈ src✝.carrier) },
              neg_mem' :=
                (_ : ∀ {x : α}, x ∈ src✝.carrier → -x ∈ src✝.carrier) }.toSubsemiring.toSubmonoid.toSubsemigroup.carrier

Next tactic:
dsimp only at hx ⊢
/-- The (topological-space) closure of a subfield of a topological field is
itself a subfield. -/
def Subfield.topologicalClosure (K : Subfield α) : Subfield α :=
  { K.toSubring.topologicalClosure with
    carrier := _root_.closure (K : Set α)
    inv_mem' := fun x hx => by
      dsimp only at hx ⊢
      

Proof state:
K✝ : Type u_1
inst✝⁴ : DivisionRing K✝
inst✝³ : TopologicalSpace K✝
α : Type u_2
inst✝² : Field α
inst✝¹ : TopologicalSpace α
inst✝ : TopologicalDivisionRing α
K : Subfield α
src✝ : Subring α := Subring.topologicalClosure K.toSubring
x : α
hx : x ∈ _root_.closure ↑K
⊢ x⁻¹ ∈ _root_.closure ↑K

Next tactic:
rcases eq_or_ne x 0 with (rfl | h)
/-- The (topological-space) closure of a subfield of a topological field is
itself a subfield. -/
def Subfield.topologicalClosure (K : Subfield α) : Subfield α :=
  { K.toSubring.topologicalClosure with
    carrier := _root_.closure (K : Set α)
    inv_mem' := fun x hx => by
      dsimp only at hx ⊢
      rcases eq_or_ne x 0 with (rfl | h)
      · 

Proof state:
case inl
K✝ : Type u_1
inst✝⁴ : DivisionRing K✝
inst✝³ : TopologicalSpace K✝
α : Type u_2
inst✝² : Field α
inst✝¹ : TopologicalSpace α
inst✝ : TopologicalDivisionRing α
K : Subfield α
src✝ : Subring α := Subring.topologicalClosure K.toSubring
hx : 0 ∈ _root_.closure ↑K
⊢ 0⁻¹ ∈ _root_.closure ↑K

Next tactic:
rwa [inv_zero]
/-- The (topological-space) closure of a subfield of a topological field is
itself a subfield. -/
def Subfield.topologicalClosure (K : Subfield α) : Subfield α :=
  { K.toSubring.topologicalClosure with
    carrier := _root_.closure (K : Set α)
    inv_mem' := fun x hx => by
      dsimp only at hx ⊢
      rcases eq_or_ne x 0 with (rfl | h)
      · rwa [inv_zero]
      · -- porting note: todo: Lean fails to find InvMemClass instance
        

Proof state:
case inr
K✝ : Type u_1
inst✝⁴ : DivisionRing K✝
inst✝³ : TopologicalSpace K✝
α : Type u_2
inst✝² : Field α
inst✝¹ : TopologicalSpace α
inst✝ : TopologicalDivisionRing α
K : Subfield α
src✝ : Subring α := Subring.topologicalClosure K.toSubring
x : α
hx : x ∈ _root_.closure ↑K
h : x ≠ 0
⊢ x⁻¹ ∈ _root_.closure ↑K

Next tactic:
rw [← @inv_coe_set α (Subfield α) _ _ SubfieldClass.toInvMemClass K, ← Set.image_inv]
/-- The (topological-space) closure of a subfield of a topological field is
itself a subfield. -/
def Subfield.topologicalClosure (K : Subfield α) : Subfield α :=
  { K.toSubring.topologicalClosure with
    carrier := _root_.closure (K : Set α)
    inv_mem' := fun x hx => by
      dsimp only at hx ⊢
      rcases eq_or_ne x 0 with (rfl | h)
      · rwa [inv_zero]
      · -- porting note: todo: Lean fails to find InvMemClass instance
        rw [← @inv_coe_set α (Subfield α) _ _ SubfieldClass.toInvMemClass K, ← Set.image_inv]
        

Proof state:
case inr
K✝ : Type u_1
inst✝⁴ : DivisionRing K✝
inst✝³ : TopologicalSpace K✝
α : Type u_2
inst✝² : Field α
inst✝¹ : TopologicalSpace α
inst✝ : TopologicalDivisionRing α
K : Subfield α
src✝ : Subring α := Subring.topologicalClosure K.toSubring
x : α
hx : x ∈ _root_.closure ↑K
h : x ≠ 0
⊢ x⁻¹ ∈ _root_.closure (Inv.inv '' ↑K)

Next tactic:
exact mem_closure_image (continuousAt_inv₀ h) hx
/--
The map `fun x => a * x + b`, as a homeomorphism from `𝕜` (a topological field) to itself,
when `a ≠ 0`.
-/
@[simps]
def affineHomeomorph (a b : 𝕜) (h : a ≠ 0) : 𝕜 ≃ₜ 𝕜 where
  toFun x := a * x + b
  invFun y := (y - b) / a
  left_inv x := by
    

Proof state:
K : Type u_1
inst✝⁴ : DivisionRing K
inst✝³ : TopologicalSpace K
𝕜 : Type u_2
inst✝² : Field 𝕜
inst✝¹ : TopologicalSpace 𝕜
inst✝ : TopologicalRing 𝕜
a b : 𝕜
h : a ≠ 0
x : 𝕜
⊢ (fun y => (y - b) / a) ((fun x => a * x + b) x) = x

Next tactic:
simp only [add_sub_cancel]
/--
The map `fun x => a * x + b`, as a homeomorphism from `𝕜` (a topological field) to itself,
when `a ≠ 0`.
-/
@[simps]
def affineHomeomorph (a b : 𝕜) (h : a ≠ 0) : 𝕜 ≃ₜ 𝕜 where
  toFun x := a * x + b
  invFun y := (y - b) / a
  left_inv x := by
    simp only [add_sub_cancel]
    

Proof state:
K : Type u_1
inst✝⁴ : DivisionRing K
inst✝³ : TopologicalSpace K
𝕜 : Type u_2
inst✝² : Field 𝕜
inst✝¹ : TopologicalSpace 𝕜
inst✝ : TopologicalRing 𝕜
a b : 𝕜
h : a ≠ 0
x : 𝕜
⊢ a * x / a = x

Next tactic:
exact mul_div_cancel_left x h
/--
The map `fun x => a * x + b`, as a homeomorphism from `𝕜` (a topological field) to itself,
when `a ≠ 0`.
-/
@[simps]
def affineHomeomorph (a b : 𝕜) (h : a ≠ 0) : 𝕜 ≃ₜ 𝕜 where
  toFun x := a * x + b
  invFun y := (y - b) / a
  left_inv x := by
    simp only [add_sub_cancel]
    exact mul_div_cancel_left x h
  right_inv y := by 

Proof state:
K : Type u_1
inst✝⁴ : DivisionRing K
inst✝³ : TopologicalSpace K
𝕜 : Type u_2
inst✝² : Field 𝕜
inst✝¹ : TopologicalSpace 𝕜
inst✝ : TopologicalRing 𝕜
a b : 𝕜
h : a ≠ 0
y : 𝕜
⊢ (fun x => a * x + b) ((fun y => (y - b) / a) y) = y

Next tactic:
simp [mul_div_cancel' _ h]
theorem IsLocalMin.inv {f : α → β} {a : α} (h1 : IsLocalMin f a) (h2 : ∀ᶠ z in 𝓝 a, 0 < f z) :
    IsLocalMax f⁻¹ a := by
  

Proof state:
K : Type u_1
inst✝³ : DivisionRing K
inst✝² : TopologicalSpace K
α : Type u_2
β : Type u_3
inst✝¹ : TopologicalSpace α
inst✝ : LinearOrderedSemifield β
a✝ : α
f : α → β
a : α
h1 : IsLocalMin f a
h2 : ∀ᶠ (z : α) in 𝓝 a, 0 < f z
⊢ IsLocalMax f⁻¹ a

Next tactic:
filter_upwards [h1, h2] with z h3 h4 using(inv_le_inv h4 h2.self_of_nhds).mpr h3
/-- If `f` is a function `α → 𝕜` which is continuous on a preconnected set `S`, and
`f ^ 2 = 1` on `S`, then either `f = 1` on `S`, or `f = -1` on `S`. -/
theorem IsPreconnected.eq_one_or_eq_neg_one_of_sq_eq [Ring 𝕜] [NoZeroDivisors 𝕜]
    (hS : IsPreconnected S) (hf : ContinuousOn f S) (hsq : EqOn (f ^ 2) 1 S) :
    EqOn f 1 S ∨ EqOn f (-1) S := by
  

Proof state:
K : Type u_1
inst✝⁶ : DivisionRing K
inst✝⁵ : TopologicalSpace K
α : Type u_2
𝕜 : Type u_3
f g : α → 𝕜
S : Set α
inst✝⁴ : TopologicalSpace α
inst✝³ : TopologicalSpace 𝕜
inst✝² : T1Space 𝕜
inst✝¹ : Ring 𝕜
inst✝ : NoZeroDivisors 𝕜
hS : IsPreconnected S
hf : ContinuousOn f S
hsq : EqOn (f ^ 2) 1 S
⊢ EqOn f 1 S ∨ EqOn f (-1) S

Next tactic:
have : DiscreteTopology ({1, -1} : Set 𝕜) := discrete_of_t1_of_finite
/-- If `f` is a function `α → 𝕜` which is continuous on a preconnected set `S`, and
`f ^ 2 = 1` on `S`, then either `f = 1` on `S`, or `f = -1` on `S`. -/
theorem IsPreconnected.eq_one_or_eq_neg_one_of_sq_eq [Ring 𝕜] [NoZeroDivisors 𝕜]
    (hS : IsPreconnected S) (hf : ContinuousOn f S) (hsq : EqOn (f ^ 2) 1 S) :
    EqOn f 1 S ∨ EqOn f (-1) S := by
  have : DiscreteTopology ({1, -1} : Set 𝕜) := discrete_of_t1_of_finite
  

Proof state:
K : Type u_1
inst✝⁶ : DivisionRing K
inst✝⁵ : TopologicalSpace K
α : Type u_2
𝕜 : Type u_3
f g : α → 𝕜
S : Set α
inst✝⁴ : TopologicalSpace α
inst✝³ : TopologicalSpace 𝕜
inst✝² : T1Space 𝕜
inst✝¹ : Ring 𝕜
inst✝ : NoZeroDivisors 𝕜
hS : IsPreconnected S
hf : ContinuousOn f S
hsq : EqOn (f ^ 2) 1 S
this : DiscreteTopology ↑{1, -1}
⊢ EqOn f 1 S ∨ EqOn f (-1) S

Next tactic:
have hmaps : MapsTo f S {1, -1}
/-- If `f` is a function `α → 𝕜` which is continuous on a preconnected set `S`, and
`f ^ 2 = 1` on `S`, then either `f = 1` on `S`, or `f = -1` on `S`. -/
theorem IsPreconnected.eq_one_or_eq_neg_one_of_sq_eq [Ring 𝕜] [NoZeroDivisors 𝕜]
    (hS : IsPreconnected S) (hf : ContinuousOn f S) (hsq : EqOn (f ^ 2) 1 S) :
    EqOn f 1 S ∨ EqOn f (-1) S := by
  have : DiscreteTopology ({1, -1} : Set 𝕜) := discrete_of_t1_of_finite
  have hmaps : MapsTo f S {1, -1}
  · 

Proof state:
case hmaps
K : Type u_1
inst✝⁶ : DivisionRing K
inst✝⁵ : TopologicalSpace K
α : Type u_2
𝕜 : Type u_3
f g : α → 𝕜
S : Set α
inst✝⁴ : TopologicalSpace α
inst✝³ : TopologicalSpace 𝕜
inst✝² : T1Space 𝕜
inst✝¹ : Ring 𝕜
inst✝ : NoZeroDivisors 𝕜
hS : IsPreconnected S
hf : ContinuousOn f S
hsq : EqOn (f ^ 2) 1 S
this : DiscreteTopology ↑{1, -1}
⊢ MapsTo f S {1, -1}

Next tactic:
simpa only [EqOn, Pi.one_apply, Pi.pow_apply, sq_eq_one_iff] using hsq
/-- If `f` is a function `α → 𝕜` which is continuous on a preconnected set `S`, and
`f ^ 2 = 1` on `S`, then either `f = 1` on `S`, or `f = -1` on `S`. -/
theorem IsPreconnected.eq_one_or_eq_neg_one_of_sq_eq [Ring 𝕜] [NoZeroDivisors 𝕜]
    (hS : IsPreconnected S) (hf : ContinuousOn f S) (hsq : EqOn (f ^ 2) 1 S) :
    EqOn f 1 S ∨ EqOn f (-1) S := by
  have : DiscreteTopology ({1, -1} : Set 𝕜) := discrete_of_t1_of_finite
  have hmaps : MapsTo f S {1, -1}
  · simpa only [EqOn, Pi.one_apply, Pi.pow_apply, sq_eq_one_iff] using hsq
  

Proof state:
K : Type u_1
inst✝⁶ : DivisionRing K
inst✝⁵ : TopologicalSpace K
α : Type u_2
𝕜 : Type u_3
f g : α → 𝕜
S : Set α
inst✝⁴ : TopologicalSpace α
inst✝³ : TopologicalSpace 𝕜
inst✝² : T1Space 𝕜
inst✝¹ : Ring 𝕜
inst✝ : NoZeroDivisors 𝕜
hS : IsPreconnected S
hf : ContinuousOn f S
hsq : EqOn (f ^ 2) 1 S
this : DiscreteTopology ↑{1, -1}
hmaps : MapsTo f S {1, -1}
⊢ EqOn f 1 S ∨ EqOn f (-1) S

Next tactic:
simpa using hS.eqOn_const_of_mapsTo hf hmaps
/-- If `f, g` are functions `α → 𝕜`, both continuous on a preconnected set `S`, with
`f ^ 2 = g ^ 2` on `S`, and `g z ≠ 0` all `z ∈ S`, then either `f = g` or `f = -g` on
`S`. -/
theorem IsPreconnected.eq_or_eq_neg_of_sq_eq [Field 𝕜] [HasContinuousInv₀ 𝕜] [ContinuousMul 𝕜]
    (hS : IsPreconnected S) (hf : ContinuousOn f S) (hg : ContinuousOn g S)
    (hsq : EqOn (f ^ 2) (g ^ 2) S) (hg_ne : ∀ {x : α}, x ∈ S → g x ≠ 0) :
    EqOn f g S ∨ EqOn f (-g) S := by
  

Proof state:
K : Type u_1
inst✝⁷ : DivisionRing K
inst✝⁶ : TopologicalSpace K
α : Type u_2
𝕜 : Type u_3
f g : α → 𝕜
S : Set α
inst✝⁵ : TopologicalSpace α
inst✝⁴ : TopologicalSpace 𝕜
inst✝³ : T1Space 𝕜
inst✝² : Field 𝕜
inst✝¹ : HasContinuousInv₀ 𝕜
inst✝ : ContinuousMul 𝕜
hS : IsPreconnected S
hf : ContinuousOn f S
hg : ContinuousOn g S
hsq : EqOn (f ^ 2) (g ^ 2) S
hg_ne : ∀ {x : α}, x ∈ S → g x ≠ 0
⊢ EqOn f g S ∨ EqOn f (-g) S

Next tactic:
have hsq : EqOn ((f / g) ^ 2) 1 S := fun x hx => by
    simpa [div_eq_one_iff_eq (pow_ne_zero _ (hg_ne hx))] using hsq hx
/-- If `f, g` are functions `α → 𝕜`, both continuous on a preconnected set `S`, with
`f ^ 2 = g ^ 2` on `S`, and `g z ≠ 0` all `z ∈ S`, then either `f = g` or `f = -g` on
`S`. -/
theorem IsPreconnected.eq_or_eq_neg_of_sq_eq [Field 𝕜] [HasContinuousInv₀ 𝕜] [ContinuousMul 𝕜]
    (hS : IsPreconnected S) (hf : ContinuousOn f S) (hg : ContinuousOn g S)
    (hsq : EqOn (f ^ 2) (g ^ 2) S) (hg_ne : ∀ {x : α}, x ∈ S → g x ≠ 0) :
    EqOn f g S ∨ EqOn f (-g) S := by
  have hsq : EqOn ((f / g) ^ 2) 1 S := fun x hx => by
    

Proof state:
K : Type u_1
inst✝⁷ : DivisionRing K
inst✝⁶ : TopologicalSpace K
α : Type u_2
𝕜 : Type u_3
f g : α → 𝕜
S : Set α
inst✝⁵ : TopologicalSpace α
inst✝⁴ : TopologicalSpace 𝕜
inst✝³ : T1Space 𝕜
inst✝² : Field 𝕜
inst✝¹ : HasContinuousInv₀ 𝕜
inst✝ : ContinuousMul 𝕜
hS : IsPreconnected S
hf : ContinuousOn f S
hg : ContinuousOn g S
hsq : EqOn (f ^ 2) (g ^ 2) S
hg_ne : ∀ {x : α}, x ∈ S → g x ≠ 0
x : α
hx : x ∈ S
⊢ ((f / g) ^ 2) x = OfNat.ofNat 1 x

Next tactic:
simpa [div_eq_one_iff_eq (pow_ne_zero _ (hg_ne hx))] using hsq hx
/-- If `f, g` are functions `α → 𝕜`, both continuous on a preconnected set `S`, with
`f ^ 2 = g ^ 2` on `S`, and `g z ≠ 0` all `z ∈ S`, then either `f = g` or `f = -g` on
`S`. -/
theorem IsPreconnected.eq_or_eq_neg_of_sq_eq [Field 𝕜] [HasContinuousInv₀ 𝕜] [ContinuousMul 𝕜]
    (hS : IsPreconnected S) (hf : ContinuousOn f S) (hg : ContinuousOn g S)
    (hsq : EqOn (f ^ 2) (g ^ 2) S) (hg_ne : ∀ {x : α}, x ∈ S → g x ≠ 0) :
    EqOn f g S ∨ EqOn f (-g) S := by
  have hsq : EqOn ((f / g) ^ 2) 1 S := fun x hx => by
    simpa [div_eq_one_iff_eq (pow_ne_zero _ (hg_ne hx))] using hsq hx
  

Proof state:
K : Type u_1
inst✝⁷ : DivisionRing K
inst✝⁶ : TopologicalSpace K
α : Type u_2
𝕜 : Type u_3
f g : α → 𝕜
S : Set α
inst✝⁵ : TopologicalSpace α
inst✝⁴ : TopologicalSpace 𝕜
inst✝³ : T1Space 𝕜
inst✝² : Field 𝕜
inst✝¹ : HasContinuousInv₀ 𝕜
inst✝ : ContinuousMul 𝕜
hS : IsPreconnected S
hf : ContinuousOn f S
hg : ContinuousOn g S
hsq✝ : EqOn (f ^ 2) (g ^ 2) S
hg_ne : ∀ {x : α}, x ∈ S → g x ≠ 0
hsq : EqOn ((f / g) ^ 2) 1 S
⊢ EqOn f g S ∨ EqOn f (-g) S

Next tactic:
simpa (config := { contextual := true }) [EqOn, div_eq_iff (hg_ne _)]
    using hS.eq_one_or_eq_neg_one_of_sq_eq (hf.div hg fun z => hg_ne) hsq
/-- If `f, g` are functions `α → 𝕜`, both continuous on a preconnected set `S`, with
`f ^ 2 = g ^ 2` on `S`, and `g z ≠ 0` all `z ∈ S`, then as soon as `f = g` holds at
one point of `S` it holds for all points. -/
theorem IsPreconnected.eq_of_sq_eq [Field 𝕜] [HasContinuousInv₀ 𝕜] [ContinuousMul 𝕜]
    (hS : IsPreconnected S) (hf : ContinuousOn f S) (hg : ContinuousOn g S)
    (hsq : EqOn (f ^ 2) (g ^ 2) S) (hg_ne : ∀ {x : α}, x ∈ S → g x ≠ 0) {y : α} (hy : y ∈ S)
    (hy' : f y = g y) : EqOn f g S := fun x hx => by
  

Proof state:
K : Type u_1
inst✝⁷ : DivisionRing K
inst✝⁶ : TopologicalSpace K
α : Type u_2
𝕜 : Type u_3
f g : α → 𝕜
S : Set α
inst✝⁵ : TopologicalSpace α
inst✝⁴ : TopologicalSpace 𝕜
inst✝³ : T1Space 𝕜
inst✝² : Field 𝕜
inst✝¹ : HasContinuousInv₀ 𝕜
inst✝ : ContinuousMul 𝕜
hS : IsPreconnected S
hf : ContinuousOn f S
hg : ContinuousOn g S
hsq : EqOn (f ^ 2) (g ^ 2) S
hg_ne : ∀ {x : α}, x ∈ S → g x ≠ 0
y : α
hy : y ∈ S
hy' : f y = g y
x : α
hx : x ∈ S
⊢ f x = g x

Next tactic:
rcases hS.eq_or_eq_neg_of_sq_eq hf hg @hsq @hg_ne with (h | h)
/-- If `f, g` are functions `α → 𝕜`, both continuous on a preconnected set `S`, with
`f ^ 2 = g ^ 2` on `S`, and `g z ≠ 0` all `z ∈ S`, then as soon as `f = g` holds at
one point of `S` it holds for all points. -/
theorem IsPreconnected.eq_of_sq_eq [Field 𝕜] [HasContinuousInv₀ 𝕜] [ContinuousMul 𝕜]
    (hS : IsPreconnected S) (hf : ContinuousOn f S) (hg : ContinuousOn g S)
    (hsq : EqOn (f ^ 2) (g ^ 2) S) (hg_ne : ∀ {x : α}, x ∈ S → g x ≠ 0) {y : α} (hy : y ∈ S)
    (hy' : f y = g y) : EqOn f g S := fun x hx => by
  rcases hS.eq_or_eq_neg_of_sq_eq hf hg @hsq @hg_ne with (h | h)
  · 

Proof state:
case inl
K : Type u_1
inst✝⁷ : DivisionRing K
inst✝⁶ : TopologicalSpace K
α : Type u_2
𝕜 : Type u_3
f g : α → 𝕜
S : Set α
inst✝⁵ : TopologicalSpace α
inst✝⁴ : TopologicalSpace 𝕜
inst✝³ : T1Space 𝕜
inst✝² : Field 𝕜
inst✝¹ : HasContinuousInv₀ 𝕜
inst✝ : ContinuousMul 𝕜
hS : IsPreconnected S
hf : ContinuousOn f S
hg : ContinuousOn g S
hsq : EqOn (f ^ 2) (g ^ 2) S
hg_ne : ∀ {x : α}, x ∈ S → g x ≠ 0
y : α
hy : y ∈ S
hy' : f y = g y
x : α
hx : x ∈ S
h : EqOn f g S
⊢ f x = g x

Next tactic:
exact h hx
/-- If `f, g` are functions `α → 𝕜`, both continuous on a preconnected set `S`, with
`f ^ 2 = g ^ 2` on `S`, and `g z ≠ 0` all `z ∈ S`, then as soon as `f = g` holds at
one point of `S` it holds for all points. -/
theorem IsPreconnected.eq_of_sq_eq [Field 𝕜] [HasContinuousInv₀ 𝕜] [ContinuousMul 𝕜]
    (hS : IsPreconnected S) (hf : ContinuousOn f S) (hg : ContinuousOn g S)
    (hsq : EqOn (f ^ 2) (g ^ 2) S) (hg_ne : ∀ {x : α}, x ∈ S → g x ≠ 0) {y : α} (hy : y ∈ S)
    (hy' : f y = g y) : EqOn f g S := fun x hx => by
  rcases hS.eq_or_eq_neg_of_sq_eq hf hg @hsq @hg_ne with (h | h)
  · exact h hx
  · 

Proof state:
case inr
K : Type u_1
inst✝⁷ : DivisionRing K
inst✝⁶ : TopologicalSpace K
α : Type u_2
𝕜 : Type u_3
f g : α → 𝕜
S : Set α
inst✝⁵ : TopologicalSpace α
inst✝⁴ : TopologicalSpace 𝕜
inst✝³ : T1Space 𝕜
inst✝² : Field 𝕜
inst✝¹ : HasContinuousInv₀ 𝕜
inst✝ : ContinuousMul 𝕜
hS : IsPreconnected S
hf : ContinuousOn f S
hg : ContinuousOn g S
hsq : EqOn (f ^ 2) (g ^ 2) S
hg_ne : ∀ {x : α}, x ∈ S → g x ≠ 0
y : α
hy : y ∈ S
hy' : f y = g y
x : α
hx : x ∈ S
h : EqOn f (-g) S
⊢ f x = g x

Next tactic:
rw [h _, Pi.neg_apply, neg_eq_iff_add_eq_zero, ← two_mul, mul_eq_zero,
      iff_false_iff.2 (hg_ne _)] at hy' ⊢
/-- If `f, g` are functions `α → 𝕜`, both continuous on a preconnected set `S`, with
`f ^ 2 = g ^ 2` on `S`, and `g z ≠ 0` all `z ∈ S`, then as soon as `f = g` holds at
one point of `S` it holds for all points. -/
theorem IsPreconnected.eq_of_sq_eq [Field 𝕜] [HasContinuousInv₀ 𝕜] [ContinuousMul 𝕜]
    (hS : IsPreconnected S) (hf : ContinuousOn f S) (hg : ContinuousOn g S)
    (hsq : EqOn (f ^ 2) (g ^ 2) S) (hg_ne : ∀ {x : α}, x ∈ S → g x ≠ 0) {y : α} (hy : y ∈ S)
    (hy' : f y = g y) : EqOn f g S := fun x hx => by
  rcases hS.eq_or_eq_neg_of_sq_eq hf hg @hsq @hg_ne with (h | h)
  · exact h hx
  · rw [h _, Pi.neg_apply, neg_eq_iff_add_eq_zero, ← two_mul, mul_eq_zero,
      iff_false_iff.2 (hg_ne _)] at hy' ⊢ <;> 

Proof state:
case inr
K : Type u_1
inst✝⁷ : DivisionRing K
inst✝⁶ : TopologicalSpace K
α : Type u_2
𝕜 : Type u_3
f g : α → 𝕜
S : Set α
inst✝⁵ : TopologicalSpace α
inst✝⁴ : TopologicalSpace 𝕜
inst✝³ : T1Space 𝕜
inst✝² : Field 𝕜
inst✝¹ : HasContinuousInv₀ 𝕜
inst✝ : ContinuousMul 𝕜
hS : IsPreconnected S
hf : ContinuousOn f S
hg : ContinuousOn g S
hsq : EqOn (f ^ 2) (g ^ 2) S
hg_ne : ∀ {x : α}, x ∈ S → g x ≠ 0
y : α
hy : y ∈ S
hy' : 2 = 0 ∨ False
x : α
hx : x ∈ S
h : EqOn f (-g) S
⊢ 2 = 0 ∨ False

Next tactic:
assumption