/-- 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 => _⟩
        obtain ⟨c, rfl⟩ := Submodule.mem_span_singleton.1 hz
        rw [IsOrtho, smul_left, add_right, smul_right, div_mul_cancel _ hx, add_neg_self,
          mul_zero])
  refine' ⟨b, _⟩
  · rw [Basis.coe_mkFinCons]
    intro j i
    refine' Fin.cases _ (fun i => _) i <;> refine' Fin.cases _ (fun j => _) j <;> intro hij <;>
      simp only [Function.onFun, Fin.cons_zero, Fin.cons_succ, Function.comp_apply]
    · exact (hij rfl).elim
    · rw [IsOrtho, hB₂]
      exact (v' j).prop _ (Submodule.mem_span_singleton_self x)
    · 

Proof state:
case succ.inr.intro.intro.refine'_2.refine'_1
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'
b : Basis (Fin (d + 1)) K V :=
  Basis.mkFinCons x v' (_ : ∀ (c : K), ∀ y ∈ orthogonal B (Submodule.span K {x}), c • x + y = 0 → c = 0)
    (_ : ∀ (y : V), ∃ c, y + c • x ∈ orthogonal B (Submodule.span K {x}))
j i✝ : Fin (Nat.succ d)
i : Fin d
hij : 0 ≠ Fin.succ i
⊢ IsOrtho B x ↑(v' i)

Next tactic:
exact (v' i).prop _ (Submodule.mem_span_singleton_self x)