l3lab/ntp-mathlib huggingface dataset:
/-- Given a symmetric bilinear form `B` on some vector space `V` over a field `K`
in which `2` is invertible, there exists an orthogonal basis with respect to `B`. -/
theorem exists_orthogonal_basis [hK : Invertible (2 : K)] {B : BilinForm K V} (hB₂ : B.IsSymm) :
    ∃ v : Basis (Fin (finrank K V)) K V, B.iIsOrtho v := by
  induction' hd : finrank K V with d ih generalizing V
  · simp_rw [Nat.zero_eq]
    exact ⟨basisOfFinrankZero hd, fun _ _ _ => zero_left _⟩
  haveI := finrank_pos_iff.1 (hd.symm ▸ Nat.succ_pos d : 0 < finrank K V)
  -- either the bilinear form is trivial or we can pick a non-null `x`
  obtain rfl | hB₁ := eq_or_ne B 0
  · let b := FiniteDimensional.finBasis K V
    rw [hd] at b
    refine' ⟨b, fun i j _ => rfl⟩
  obtain ⟨x, hx⟩ := exists_bilinForm_self_ne_zero hB₁ hB₂
  rw [← Submodule.finrank_add_eq_of_isCompl (isCompl_span_singleton_orthogonal hx).symm,
    finrank_span_singleton (ne_zero_of_not_isOrtho_self x hx)] at hd
  let B' := B.restrict (B.orthogonal <| K ∙ x)
  obtain ⟨v', hv₁⟩ := ih (hB₂.restrict _ : B'.IsSymm) (Nat.succ.inj hd)
  -- concatenate `x` with the basis obtained by induction
  let b :=
    Basis.mkFinCons x v'
      (by
        rintro c y hy hc
        

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁶ : CommRing R
inst✝⁵ : AddCommGroup M
inst✝⁴ : Module R M
K : Type v
inst✝³ : Field K
hK : Invertible 2
d : ℕ
ih :
  ∀ {V : Type u} [inst : AddCommGroup V] [inst_1 : Module K V] [inst_2 : FiniteDimensional K V] {B : BilinForm K V},
    IsSymm B → finrank K V = d → ∃ v, iIsOrtho B ⇑v
V : Type u
inst✝² : AddCommGroup V
inst✝¹ : Module K V
inst✝ : FiniteDimensional K V
B : BilinForm K V
hB₂ : IsSymm B
this : Nontrivial V
hB₁ : B ≠ 0
x : V
hd : finrank K ↥(orthogonal B (Submodule.span K {x})) + 1 = Nat.succ d
hx : ¬IsOrtho B x x
B' : BilinForm K ↥(orthogonal B (Submodule.span K {x})) := restrict B (orthogonal B (Submodule.span K {x}))
v' : Basis (Fin d) K ↥(orthogonal B (Submodule.span K {x}))
hv₁ : iIsOrtho (restrict B (orthogonal B (Submodule.span K {x}))) ⇑v'
c : K
y : V
hy : y ∈ orthogonal B (Submodule.span K {x})
hc : c • x + y = 0
⊢ c = 0

Next tactic:
rw [add_eq_zero_iff_neg_eq] at hc
/-- Given a symmetric bilinear form `B` on some vector space `V` over a field `K`
in which `2` is invertible, there exists an orthogonal basis with respect to `B`. -/
theorem exists_orthogonal_basis [hK : Invertible (2 : K)] {B : BilinForm K V} (hB₂ : B.IsSymm) :
    ∃ v : Basis (Fin (finrank K V)) K V, B.iIsOrtho v := by
  induction' hd : finrank K V with d ih generalizing V
  · simp_rw [Nat.zero_eq]
    exact ⟨basisOfFinrankZero hd, fun _ _ _ => zero_left _⟩
  haveI := finrank_pos_iff.1 (hd.symm ▸ Nat.succ_pos d : 0 < finrank K V)
  -- either the bilinear form is trivial or we can pick a non-null `x`
  obtain rfl | hB₁ := eq_or_ne B 0
  · let b := FiniteDimensional.finBasis K V
    rw [hd] at b
    refine' ⟨b, fun i j _ => rfl⟩
  obtain ⟨x, hx⟩ := exists_bilinForm_self_ne_zero hB₁ hB₂
  rw [← Submodule.finrank_add_eq_of_isCompl (isCompl_span_singleton_orthogonal hx).symm,
    finrank_span_singleton (ne_zero_of_not_isOrtho_self x hx)] at hd
  let B' := B.restrict (B.orthogonal <| K ∙ x)
  obtain ⟨v', hv₁⟩ := ih (hB₂.restrict _ : B'.IsSymm) (Nat.succ.inj hd)
  -- concatenate `x` with the basis obtained by induction
  let b :=
    Basis.mkFinCons x v'
      (by
        rintro c y hy hc
        rw [add_eq_zero_iff_neg_eq] at hc
        

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁶ : CommRing R
inst✝⁵ : AddCommGroup M
inst✝⁴ : Module R M
K : Type v
inst✝³ : Field K
hK : Invertible 2
d : ℕ
ih :
  ∀ {V : Type u} [inst : AddCommGroup V] [inst_1 : Module K V] [inst_2 : FiniteDimensional K V] {B : BilinForm K V},
    IsSymm B → finrank K V = d → ∃ v, iIsOrtho B ⇑v
V : Type u
inst✝² : AddCommGroup V
inst✝¹ : Module K V
inst✝ : FiniteDimensional K V
B : BilinForm K V
hB₂ : IsSymm B
this : Nontrivial V
hB₁ : B ≠ 0
x : V
hd : finrank K ↥(orthogonal B (Submodule.span K {x})) + 1 = Nat.succ d
hx : ¬IsOrtho B x x
B' : BilinForm K ↥(orthogonal B (Submodule.span K {x})) := restrict B (orthogonal B (Submodule.span K {x}))
v' : Basis (Fin d) K ↥(orthogonal B (Submodule.span K {x}))
hv₁ : iIsOrtho (restrict B (orthogonal B (Submodule.span K {x}))) ⇑v'
c : K
y : V
hy : y ∈ orthogonal B (Submodule.span K {x})
hc : -(c • x) = y
⊢ c = 0

Next tactic:
rw [← hc, Submodule.neg_mem_iff] at hy
/-- Given a symmetric bilinear form `B` on some vector space `V` over a field `K`
in which `2` is invertible, there exists an orthogonal basis with respect to `B`. -/
theorem exists_orthogonal_basis [hK : Invertible (2 : K)] {B : BilinForm K V} (hB₂ : B.IsSymm) :
    ∃ v : Basis (Fin (finrank K V)) K V, B.iIsOrtho v := by
  induction' hd : finrank K V with d ih generalizing V
  · simp_rw [Nat.zero_eq]
    exact ⟨basisOfFinrankZero hd, fun _ _ _ => zero_left _⟩
  haveI := finrank_pos_iff.1 (hd.symm ▸ Nat.succ_pos d : 0 < finrank K V)
  -- either the bilinear form is trivial or we can pick a non-null `x`
  obtain rfl | hB₁ := eq_or_ne B 0
  · let b := FiniteDimensional.finBasis K V
    rw [hd] at b
    refine' ⟨b, fun i j _ => rfl⟩
  obtain ⟨x, hx⟩ := exists_bilinForm_self_ne_zero hB₁ hB₂
  rw [← Submodule.finrank_add_eq_of_isCompl (isCompl_span_singleton_orthogonal hx).symm,
    finrank_span_singleton (ne_zero_of_not_isOrtho_self x hx)] at hd
  let B' := B.restrict (B.orthogonal <| K ∙ x)
  obtain ⟨v', hv₁⟩ := ih (hB₂.restrict _ : B'.IsSymm) (Nat.succ.inj hd)
  -- concatenate `x` with the basis obtained by induction
  let b :=
    Basis.mkFinCons x v'
      (by
        rintro c y hy hc
        rw [add_eq_zero_iff_neg_eq] at hc
        rw [← hc, Submodule.neg_mem_iff] at hy
        

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁶ : CommRing R
inst✝⁵ : AddCommGroup M
inst✝⁴ : Module R M
K : Type v
inst✝³ : Field K
hK : Invertible 2
d : ℕ
ih :
  ∀ {V : Type u} [inst : AddCommGroup V] [inst_1 : Module K V] [inst_2 : FiniteDimensional K V] {B : BilinForm K V},
    IsSymm B → finrank K V = d → ∃ v, iIsOrtho B ⇑v
V : Type u
inst✝² : AddCommGroup V
inst✝¹ : Module K V
inst✝ : FiniteDimensional K V
B : BilinForm K V
hB₂ : IsSymm B
this : Nontrivial V
hB₁ : B ≠ 0
x : V
hd : finrank K ↥(orthogonal B (Submodule.span K {x})) + 1 = Nat.succ d
hx : ¬IsOrtho B x x
B' : BilinForm K ↥(orthogonal B (Submodule.span K {x})) := restrict B (orthogonal B (Submodule.span K {x}))
v' : Basis (Fin d) K ↥(orthogonal B (Submodule.span K {x}))
hv₁ : iIsOrtho (restrict B (orthogonal B (Submodule.span K {x}))) ⇑v'
c : K
y : V
hy : c • x ∈ orthogonal B (Submodule.span K {x})
hc : -(c • x) = y
⊢ c = 0

Next tactic:
have := (isCompl_span_singleton_orthogonal hx).disjoint
/-- Given a symmetric bilinear form `B` on some vector space `V` over a field `K`
in which `2` is invertible, there exists an orthogonal basis with respect to `B`. -/
theorem exists_orthogonal_basis [hK : Invertible (2 : K)] {B : BilinForm K V} (hB₂ : B.IsSymm) :
    ∃ v : Basis (Fin (finrank K V)) K V, B.iIsOrtho v := by
  induction' hd : finrank K V with d ih generalizing V
  · simp_rw [Nat.zero_eq]
    exact ⟨basisOfFinrankZero hd, fun _ _ _ => zero_left _⟩
  haveI := finrank_pos_iff.1 (hd.symm ▸ Nat.succ_pos d : 0 < finrank K V)
  -- either the bilinear form is trivial or we can pick a non-null `x`
  obtain rfl | hB₁ := eq_or_ne B 0
  · let b := FiniteDimensional.finBasis K V
    rw [hd] at b
    refine' ⟨b, fun i j _ => rfl⟩
  obtain ⟨x, hx⟩ := exists_bilinForm_self_ne_zero hB₁ hB₂
  rw [← Submodule.finrank_add_eq_of_isCompl (isCompl_span_singleton_orthogonal hx).symm,
    finrank_span_singleton (ne_zero_of_not_isOrtho_self x hx)] at hd
  let B' := B.restrict (B.orthogonal <| K ∙ x)
  obtain ⟨v', hv₁⟩ := ih (hB₂.restrict _ : B'.IsSymm) (Nat.succ.inj hd)
  -- concatenate `x` with the basis obtained by induction
  let b :=
    Basis.mkFinCons x v'
      (by
        rintro c y hy hc
        rw [add_eq_zero_iff_neg_eq] at hc
        rw [← hc, Submodule.neg_mem_iff] at hy
        have := (isCompl_span_singleton_orthogonal hx).disjoint
        

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁶ : CommRing R
inst✝⁵ : AddCommGroup M
inst✝⁴ : Module R M
K : Type v
inst✝³ : Field K
hK : Invertible 2
d : ℕ
ih :
  ∀ {V : Type u} [inst : AddCommGroup V] [inst_1 : Module K V] [inst_2 : FiniteDimensional K V] {B : BilinForm K V},
    IsSymm B → finrank K V = d → ∃ v, iIsOrtho B ⇑v
V : Type u
inst✝² : AddCommGroup V
inst✝¹ : Module K V
inst✝ : FiniteDimensional K V
B : BilinForm K V
hB₂ : IsSymm B
this✝ : Nontrivial V
hB₁ : B ≠ 0
x : V
hd : finrank K ↥(orthogonal B (Submodule.span K {x})) + 1 = Nat.succ d
hx : ¬IsOrtho B x x
B' : BilinForm K ↥(orthogonal B (Submodule.span K {x})) := restrict B (orthogonal B (Submodule.span K {x}))
v' : Basis (Fin d) K ↥(orthogonal B (Submodule.span K {x}))
hv₁ : iIsOrtho (restrict B (orthogonal B (Submodule.span K {x}))) ⇑v'
c : K
y : V
hy : c • x ∈ orthogonal B (Submodule.span K {x})
hc : -(c • x) = y
this : Disjoint (Submodule.span K {x}) (orthogonal B (Submodule.span K {x}))
⊢ c = 0

Next tactic:
rw [Submodule.disjoint_def] at this
/-- Given a symmetric bilinear form `B` on some vector space `V` over a field `K`
in which `2` is invertible, there exists an orthogonal basis with respect to `B`. -/
theorem exists_orthogonal_basis [hK : Invertible (2 : K)] {B : BilinForm K V} (hB₂ : B.IsSymm) :
    ∃ v : Basis (Fin (finrank K V)) K V, B.iIsOrtho v := by
  induction' hd : finrank K V with d ih generalizing V
  · simp_rw [Nat.zero_eq]
    exact ⟨basisOfFinrankZero hd, fun _ _ _ => zero_left _⟩
  haveI := finrank_pos_iff.1 (hd.symm ▸ Nat.succ_pos d : 0 < finrank K V)
  -- either the bilinear form is trivial or we can pick a non-null `x`
  obtain rfl | hB₁ := eq_or_ne B 0
  · let b := FiniteDimensional.finBasis K V
    rw [hd] at b
    refine' ⟨b, fun i j _ => rfl⟩
  obtain ⟨x, hx⟩ := exists_bilinForm_self_ne_zero hB₁ hB₂
  rw [← Submodule.finrank_add_eq_of_isCompl (isCompl_span_singleton_orthogonal hx).symm,
    finrank_span_singleton (ne_zero_of_not_isOrtho_self x hx)] at hd
  let B' := B.restrict (B.orthogonal <| K ∙ x)
  obtain ⟨v', hv₁⟩ := ih (hB₂.restrict _ : B'.IsSymm) (Nat.succ.inj hd)
  -- concatenate `x` with the basis obtained by induction
  let b :=
    Basis.mkFinCons x v'
      (by
        rintro c y hy hc
        rw [add_eq_zero_iff_neg_eq] at hc
        rw [← hc, Submodule.neg_mem_iff] at hy
        have := (isCompl_span_singleton_orthogonal hx).disjoint
        rw [Submodule.disjoint_def] at this
        

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁶ : CommRing R
inst✝⁵ : AddCommGroup M
inst✝⁴ : Module R M
K : Type v
inst✝³ : Field K
hK : Invertible 2
d : ℕ
ih :
  ∀ {V : Type u} [inst : AddCommGroup V] [inst_1 : Module K V] [inst_2 : FiniteDimensional K V] {B : BilinForm K V},
    IsSymm B → finrank K V = d → ∃ v, iIsOrtho B ⇑v
V : Type u
inst✝² : AddCommGroup V
inst✝¹ : Module K V
inst✝ : FiniteDimensional K V
B : BilinForm K V
hB₂ : IsSymm B
this✝ : Nontrivial V
hB₁ : B ≠ 0
x : V
hd : finrank K ↥(orthogonal B (Submodule.span K {x})) + 1 = Nat.succ d
hx : ¬IsOrtho B x x
B' : BilinForm K ↥(orthogonal B (Submodule.span K {x})) := restrict B (orthogonal B (Submodule.span K {x}))
v' : Basis (Fin d) K ↥(orthogonal B (Submodule.span K {x}))
hv₁ : iIsOrtho (restrict B (orthogonal B (Submodule.span K {x}))) ⇑v'
c : K
y : V
hy : c • x ∈ orthogonal B (Submodule.span K {x})
hc : -(c • x) = y
this : ∀ x_1 ∈ Submodule.span K {x}, x_1 ∈ orthogonal B (Submodule.span K {x}) → x_1 = 0
⊢ c = 0

Next tactic:
have := this (c • x) (Submodule.smul_mem _ _ <| Submodule.mem_span_singleton_self _) hy
/-- Given a symmetric bilinear form `B` on some vector space `V` over a field `K`
in which `2` is invertible, there exists an orthogonal basis with respect to `B`. -/
theorem exists_orthogonal_basis [hK : Invertible (2 : K)] {B : BilinForm K V} (hB₂ : B.IsSymm) :
    ∃ v : Basis (Fin (finrank K V)) K V, B.iIsOrtho v := by
  induction' hd : finrank K V with d ih generalizing V
  · simp_rw [Nat.zero_eq]
    exact ⟨basisOfFinrankZero hd, fun _ _ _ => zero_left _⟩
  haveI := finrank_pos_iff.1 (hd.symm ▸ Nat.succ_pos d : 0 < finrank K V)
  -- either the bilinear form is trivial or we can pick a non-null `x`
  obtain rfl | hB₁ := eq_or_ne B 0
  · let b := FiniteDimensional.finBasis K V
    rw [hd] at b
    refine' ⟨b, fun i j _ => rfl⟩
  obtain ⟨x, hx⟩ := exists_bilinForm_self_ne_zero hB₁ hB₂
  rw [← Submodule.finrank_add_eq_of_isCompl (isCompl_span_singleton_orthogonal hx).symm,
    finrank_span_singleton (ne_zero_of_not_isOrtho_self x hx)] at hd
  let B' := B.restrict (B.orthogonal <| K ∙ x)
  obtain ⟨v', hv₁⟩ := ih (hB₂.restrict _ : B'.IsSymm) (Nat.succ.inj hd)
  -- concatenate `x` with the basis obtained by induction
  let b :=
    Basis.mkFinCons x v'
      (by
        rintro c y hy hc
        rw [add_eq_zero_iff_neg_eq] at hc
        rw [← hc, Submodule.neg_mem_iff] at hy
        have := (isCompl_span_singleton_orthogonal hx).disjoint
        rw [Submodule.disjoint_def] at this
        have := this (c • x) (Submodule.smul_mem _ _ <| Submodule.mem_span_singleton_self _) hy
        

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁶ : CommRing R
inst✝⁵ : AddCommGroup M
inst✝⁴ : Module R M
K : Type v
inst✝³ : Field K
hK : Invertible 2
d : ℕ
ih :
  ∀ {V : Type u} [inst : AddCommGroup V] [inst_1 : Module K V] [inst_2 : FiniteDimensional K V] {B : BilinForm K V},
    IsSymm B → finrank K V = d → ∃ v, iIsOrtho B ⇑v
V : Type u
inst✝² : AddCommGroup V
inst✝¹ : Module K V
inst✝ : FiniteDimensional K V
B : BilinForm K V
hB₂ : IsSymm B
this✝¹ : Nontrivial V
hB₁ : B ≠ 0
x : V
hd : finrank K ↥(orthogonal B (Submodule.span K {x})) + 1 = Nat.succ d
hx : ¬IsOrtho B x x
B' : BilinForm K ↥(orthogonal B (Submodule.span K {x})) := restrict B (orthogonal B (Submodule.span K {x}))
v' : Basis (Fin d) K ↥(orthogonal B (Submodule.span K {x}))
hv₁ : iIsOrtho (restrict B (orthogonal B (Submodule.span K {x}))) ⇑v'
c : K
y : V
hy : c • x ∈ orthogonal B (Submodule.span K {x})
hc : -(c • x) = y
this✝ : ∀ x_1 ∈ Submodule.span K {x}, x_1 ∈ orthogonal B (Submodule.span K {x}) → x_1 = 0
this : c • x = 0
⊢ c = 0

Next tactic:
exact (smul_eq_zero.1 this).resolve_right fun h => hx <| h.symm ▸ zero_left _
/-- Given a symmetric bilinear form `B` on some vector space `V` over a field `K`
in which `2` is invertible, there exists an orthogonal basis with respect to `B`. -/
theorem exists_orthogonal_basis [hK : Invertible (2 : K)] {B : BilinForm K V} (hB₂ : B.IsSymm) :
    ∃ v : Basis (Fin (finrank K V)) K V, B.iIsOrtho v := by
  induction' hd : finrank K V with d ih generalizing V
  · simp_rw [Nat.zero_eq]
    exact ⟨basisOfFinrankZero hd, fun _ _ _ => zero_left _⟩
  haveI := finrank_pos_iff.1 (hd.symm ▸ Nat.succ_pos d : 0 < finrank K V)
  -- either the bilinear form is trivial or we can pick a non-null `x`
  obtain rfl | hB₁ := eq_or_ne B 0
  · let b := FiniteDimensional.finBasis K V
    rw [hd] at b
    refine' ⟨b, fun i j _ => rfl⟩
  obtain ⟨x, hx⟩ := exists_bilinForm_self_ne_zero hB₁ hB₂
  rw [← Submodule.finrank_add_eq_of_isCompl (isCompl_span_singleton_orthogonal hx).symm,
    finrank_span_singleton (ne_zero_of_not_isOrtho_self x hx)] at hd
  let B' := B.restrict (B.orthogonal <| K ∙ x)
  obtain ⟨v', hv₁⟩ := ih (hB₂.restrict _ : B'.IsSymm) (Nat.succ.inj hd)
  -- concatenate `x` with the basis obtained by induction
  let b :=
    Basis.mkFinCons x v'
      (by
        rintro c y hy hc
        rw [add_eq_zero_iff_neg_eq] at hc
        rw [← hc, Submodule.neg_mem_iff] at hy
        have := (isCompl_span_singleton_orthogonal hx).disjoint
        rw [Submodule.disjoint_def] at this
        have := this (c • x) (Submodule.smul_mem _ _ <| Submodule.mem_span_singleton_self _) hy
        exact (smul_eq_zero.1 this).resolve_right fun h => hx <| h.symm ▸ zero_left _)
      (by
        

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁶ : CommRing R
inst✝⁵ : AddCommGroup M
inst✝⁴ : Module R M
K : Type v
inst✝³ : Field K
hK : Invertible 2
d : ℕ
ih :
  ∀ {V : Type u} [inst : AddCommGroup V] [inst_1 : Module K V] [inst_2 : FiniteDimensional K V] {B : BilinForm K V},
    IsSymm B → finrank K V = d → ∃ v, iIsOrtho B ⇑v
V : Type u
inst✝² : AddCommGroup V
inst✝¹ : Module K V
inst✝ : FiniteDimensional K V
B : BilinForm K V
hB₂ : IsSymm B
this : Nontrivial V
hB₁ : B ≠ 0
x : V
hd : finrank K ↥(orthogonal B (Submodule.span K {x})) + 1 = Nat.succ d
hx : ¬IsOrtho B x x
B' : BilinForm K ↥(orthogonal B (Submodule.span K {x})) := restrict B (orthogonal B (Submodule.span K {x}))
v' : Basis (Fin d) K ↥(orthogonal B (Submodule.span K {x}))
hv₁ : iIsOrtho (restrict B (orthogonal B (Submodule.span K {x}))) ⇑v'
⊢ ∀ (z : V), ∃ c, z + c • x ∈ orthogonal B (Submodule.span K {x})

Next tactic:
intro y
/-- Given a symmetric bilinear form `B` on some vector space `V` over a field `K`
in which `2` is invertible, there exists an orthogonal basis with respect to `B`. -/
theorem exists_orthogonal_basis [hK : Invertible (2 : K)] {B : BilinForm K V} (hB₂ : B.IsSymm) :
    ∃ v : Basis (Fin (finrank K V)) K V, B.iIsOrtho v := by
  induction' hd : finrank K V with d ih generalizing V
  · simp_rw [Nat.zero_eq]
    exact ⟨basisOfFinrankZero hd, fun _ _ _ => zero_left _⟩
  haveI := finrank_pos_iff.1 (hd.symm ▸ Nat.succ_pos d : 0 < finrank K V)
  -- either the bilinear form is trivial or we can pick a non-null `x`
  obtain rfl | hB₁ := eq_or_ne B 0
  · let b := FiniteDimensional.finBasis K V
    rw [hd] at b
    refine' ⟨b, fun i j _ => rfl⟩
  obtain ⟨x, hx⟩ := exists_bilinForm_self_ne_zero hB₁ hB₂
  rw [← Submodule.finrank_add_eq_of_isCompl (isCompl_span_singleton_orthogonal hx).symm,
    finrank_span_singleton (ne_zero_of_not_isOrtho_self x hx)] at hd
  let B' := B.restrict (B.orthogonal <| K ∙ x)
  obtain ⟨v', hv₁⟩ := ih (hB₂.restrict _ : B'.IsSymm) (Nat.succ.inj hd)
  -- concatenate `x` with the basis obtained by induction
  let b :=
    Basis.mkFinCons x v'
      (by
        rintro c y hy hc
        rw [add_eq_zero_iff_neg_eq] at hc
        rw [← hc, Submodule.neg_mem_iff] at hy
        have := (isCompl_span_singleton_orthogonal hx).disjoint
        rw [Submodule.disjoint_def] at this
        have := this (c • x) (Submodule.smul_mem _ _ <| Submodule.mem_span_singleton_self _) hy
        exact (smul_eq_zero.1 this).resolve_right fun h => hx <| h.symm ▸ zero_left _)
      (by
        intro y
        

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁶ : CommRing R
inst✝⁵ : AddCommGroup M
inst✝⁴ : Module R M
K : Type v
inst✝³ : Field K
hK : Invertible 2
d : ℕ
ih :
  ∀ {V : Type u} [inst : AddCommGroup V] [inst_1 : Module K V] [inst_2 : FiniteDimensional K V] {B : BilinForm K V},
    IsSymm B → finrank K V = d → ∃ v, iIsOrtho B ⇑v
V : Type u
inst✝² : AddCommGroup V
inst✝¹ : Module K V
inst✝ : FiniteDimensional K V
B : BilinForm K V
hB₂ : IsSymm B
this : Nontrivial V
hB₁ : B ≠ 0
x : V
hd : finrank K ↥(orthogonal B (Submodule.span K {x})) + 1 = Nat.succ d
hx : ¬IsOrtho B x x
B' : BilinForm K ↥(orthogonal B (Submodule.span K {x})) := restrict B (orthogonal B (Submodule.span K {x}))
v' : Basis (Fin d) K ↥(orthogonal B (Submodule.span K {x}))
hv₁ : iIsOrtho (restrict B (orthogonal B (Submodule.span K {x}))) ⇑v'
y : V
⊢ ∃ c, y + c • x ∈ orthogonal B (Submodule.span K {x})

Next tactic:
refine' ⟨-B x y / B x x, fun z hz => _⟩
/-- Given a symmetric bilinear form `B` on some vector space `V` over a field `K`
in which `2` is invertible, there exists an orthogonal basis with respect to `B`. -/
theorem exists_orthogonal_basis [hK : Invertible (2 : K)] {B : BilinForm K V} (hB₂ : B.IsSymm) :
    ∃ v : Basis (Fin (finrank K V)) K V, B.iIsOrtho v := by
  induction' hd : finrank K V with d ih generalizing V
  · simp_rw [Nat.zero_eq]
    exact ⟨basisOfFinrankZero hd, fun _ _ _ => zero_left _⟩
  haveI := finrank_pos_iff.1 (hd.symm ▸ Nat.succ_pos d : 0 < finrank K V)
  -- either the bilinear form is trivial or we can pick a non-null `x`
  obtain rfl | hB₁ := eq_or_ne B 0
  · let b := FiniteDimensional.finBasis K V
    rw [hd] at b
    refine' ⟨b, fun i j _ => rfl⟩
  obtain ⟨x, hx⟩ := exists_bilinForm_self_ne_zero hB₁ hB₂
  rw [← Submodule.finrank_add_eq_of_isCompl (isCompl_span_singleton_orthogonal hx).symm,
    finrank_span_singleton (ne_zero_of_not_isOrtho_self x hx)] at hd
  let B' := B.restrict (B.orthogonal <| K ∙ x)
  obtain ⟨v', hv₁⟩ := ih (hB₂.restrict _ : B'.IsSymm) (Nat.succ.inj hd)
  -- concatenate `x` with the basis obtained by induction
  let b :=
    Basis.mkFinCons x v'
      (by
        rintro c y hy hc
        rw [add_eq_zero_iff_neg_eq] at hc
        rw [← hc, Submodule.neg_mem_iff] at hy
        have := (isCompl_span_singleton_orthogonal hx).disjoint
        rw [Submodule.disjoint_def] at this
        have := this (c • x) (Submodule.smul_mem _ _ <| Submodule.mem_span_singleton_self _) hy
        exact (smul_eq_zero.1 this).resolve_right fun h => hx <| h.symm ▸ zero_left _)
      (by
        intro y
        refine' ⟨-B x y / B x x, fun z hz => _⟩
        

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁶ : CommRing R
inst✝⁵ : AddCommGroup M
inst✝⁴ : Module R M
K : Type v
inst✝³ : Field K
hK : Invertible 2
d : ℕ
ih :
  ∀ {V : Type u} [inst : AddCommGroup V] [inst_1 : Module K V] [inst_2 : FiniteDimensional K V] {B : BilinForm K V},
    IsSymm B → finrank K V = d → ∃ v, iIsOrtho B ⇑v
V : Type u
inst✝² : AddCommGroup V
inst✝¹ : Module K V
inst✝ : FiniteDimensional K V
B : BilinForm K V
hB₂ : IsSymm B
this : Nontrivial V
hB₁ : B ≠ 0
x : V
hd : finrank K ↥(orthogonal B (Submodule.span K {x})) + 1 = Nat.succ d
hx : ¬IsOrtho B x x
B' : BilinForm K ↥(orthogonal B (Submodule.span K {x})) := restrict B (orthogonal B (Submodule.span K {x}))
v' : Basis (Fin d) K ↥(orthogonal B (Submodule.span K {x}))
hv₁ : iIsOrtho (restrict B (orthogonal B (Submodule.span K {x}))) ⇑v'
y z : V
hz : z ∈ Submodule.span K {x}
⊢ IsOrtho B z (y + (-bilin B x y / bilin B x x) • x)

Next tactic:
obtain ⟨c, rfl⟩ := Submodule.mem_span_singleton.1 hz