l3lab/ntp-mathlib huggingface dataset:
theorem map_zero : Q 0 = 0 := by
  

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝² : CommSemiring R
inst✝¹ : AddCommMonoid M
inst✝ : Module R M
Q : QuadraticForm R M
⊢ Q 0 = 0

Next tactic:
rw [← @zero_smul R _ _ _ _ (0 : M), map_smul, zero_mul, zero_mul]
theorem map_smul_of_tower [CommSemiring S] [Algebra S R] [Module S M] [IsScalarTower S R M] (a : S)
    (x : M) : Q (a • x) = (a * a) • Q x := by
  

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁶ : CommSemiring R
inst✝⁵ : AddCommMonoid M
inst✝⁴ : Module R M
Q : QuadraticForm R M
inst✝³ : CommSemiring S
inst✝² : Algebra S R
inst✝¹ : Module S M
inst✝ : IsScalarTower S R M
a : S
x : M
⊢ Q (a • x) = (a * a) • Q x

Next tactic:
rw [← IsScalarTower.algebraMap_smul R a x, map_smul, ← RingHom.map_mul, Algebra.smul_def]
@[simp]
theorem map_neg (x : M) : Q (-x) = Q x := 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
Q : QuadraticForm R M
x : M
⊢ Q (-x) = Q x

Next tactic:
rw [← @neg_one_smul R _ _ _ _ x, map_smul, neg_one_mul, neg_neg, one_mul]
theorem map_sub (x y : M) : Q (x - y) = Q (y - x) := 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
Q : QuadraticForm R M
x y : M
⊢ Q (x - y) = Q (y - x)

Next tactic:
rw [← neg_sub, map_neg]
@[simp]
theorem polar_zero_left (y : M) : polar Q 0 y = 0 := 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
Q : QuadraticForm R M
y : M
⊢ polar (⇑Q) 0 y = 0

Next tactic:
simp only [polar, zero_add, QuadraticForm.map_zero, sub_zero, sub_self]
@[simp]
theorem polar_smul_left (a : R) (x y : M) : polar Q (a • x) y = a * polar Q x y := 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
Q : QuadraticForm R M
a : R
x y : M
⊢ polar (⇑Q) (a • x) y = a * polar (⇑Q) x y

Next tactic:
obtain ⟨B, h⟩ := Q.exists_companion
@[simp]
theorem polar_smul_left (a : R) (x y : M) : polar Q (a • x) y = a * polar Q x y := by
  obtain ⟨B, h⟩ := Q.exists_companion
  

Proof state:
case intro
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
Q : QuadraticForm R M
a : R
x y : M
B : BilinForm R M
h : ∀ (x y : M), Q (x + y) = Q x + Q y + BilinForm.bilin B x y
⊢ polar (⇑Q) (a • x) y = a * polar (⇑Q) x y

Next tactic:
simp_rw [polar, h, Q.map_smul, BilinForm.smul_left, sub_sub, add_sub_cancel']
@[simp]
theorem polar_neg_left (x y : M) : polar Q (-x) y = -polar Q x y := 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
Q : QuadraticForm R M
x y : M
⊢ polar (⇑Q) (-x) y = -polar (⇑Q) x y

Next tactic:
rw [← neg_one_smul R x, polar_smul_left, neg_one_mul]
@[simp]
theorem polar_sub_left (x x' y : M) : polar Q (x - x') y = polar Q x y - polar Q x' y := 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
Q : QuadraticForm R M
x x' y : M
⊢ polar (⇑Q) (x - x') y = polar (⇑Q) x y - polar (⇑Q) x' y

Next tactic:
rw [sub_eq_add_neg, sub_eq_add_neg, polar_add_left, polar_neg_left]
@[simp]
theorem polar_zero_right (y : M) : polar Q y 0 = 0 := 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
Q : QuadraticForm R M
y : M
⊢ polar (⇑Q) y 0 = 0

Next tactic:
simp only [add_zero, polar, QuadraticForm.map_zero, sub_self]
@[simp]
theorem polar_add_right (x y y' : M) : polar Q x (y + y') = polar Q x y + polar Q x y' := 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
Q : QuadraticForm R M
x y y' : M
⊢ polar (⇑Q) x (y + y') = polar (⇑Q) x y + polar (⇑Q) x y'

Next tactic:
rw [polar_comm Q x, polar_comm Q x, polar_comm Q x, polar_add_left]
@[simp]
theorem polar_smul_right (a : R) (x y : M) : polar Q x (a • y) = a * polar Q x y := 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
Q : QuadraticForm R M
a : R
x y : M
⊢ polar (⇑Q) x (a • y) = a * polar (⇑Q) x y

Next tactic:
rw [polar_comm Q x, polar_comm Q x, polar_smul_left]
@[simp]
theorem polar_neg_right (x y : M) : polar Q x (-y) = -polar Q x y := 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
Q : QuadraticForm R M
x y : M
⊢ polar (⇑Q) x (-y) = -polar (⇑Q) x y

Next tactic:
rw [← neg_one_smul R y, polar_smul_right, neg_one_mul]
@[simp]
theorem polar_sub_right (x y y' : M) : polar Q x (y - y') = polar Q x y - polar Q x y' := 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
Q : QuadraticForm R M
x y y' : M
⊢ polar (⇑Q) x (y - y') = polar (⇑Q) x y - polar (⇑Q) x y'

Next tactic:
rw [sub_eq_add_neg, sub_eq_add_neg, polar_add_right, polar_neg_right]
@[simp]
theorem polar_self (x : M) : polar Q x x = 2 * Q x := 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
Q : QuadraticForm R M
x : M
⊢ polar (⇑Q) x x = 2 * Q x

Next tactic:
rw [polar, map_add_self, sub_sub, sub_eq_iff_eq_add, ← two_mul, ← two_mul, ← mul_assoc]
@[simp]
theorem polar_self (x : M) : polar Q x x = 2 * Q x := by
  rw [polar, map_add_self, sub_sub, sub_eq_iff_eq_add, ← two_mul, ← two_mul, ← mul_assoc]
  

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
Q : QuadraticForm R M
x : M
⊢ 4 * Q x = 2 * 2 * Q x

Next tactic:
norm_num
/-- `QuadraticForm.polar` as a bilinear form -/
@[simps]
def polarBilin : BilinForm R M where
  bilin := polar Q
  bilin_add_left := polar_add_left Q
  bilin_smul_left := polar_smul_left Q
  bilin_add_right x y z := 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
Q : QuadraticForm R M
x y z : M
⊢ polar (⇑Q) x (y + z) = polar (⇑Q) x y + polar (⇑Q) x z

Next tactic:
simp_rw [polar_comm _ x, polar_add_left Q]
/-- `QuadraticForm.polar` as a bilinear form -/
@[simps]
def polarBilin : BilinForm R M where
  bilin := polar Q
  bilin_add_left := polar_add_left Q
  bilin_smul_left := polar_smul_left Q
  bilin_add_right x y z := by simp_rw [polar_comm _ x, polar_add_left Q]
  bilin_smul_right r x y := 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
Q : QuadraticForm R M
r : R
x y : M
⊢ polar (⇑Q) x (r • y) = r * polar (⇑Q) x y

Next tactic:
simp_rw [polar_comm _ x, polar_smul_left Q]
@[simp]
theorem polar_smul_left_of_tower (a : S) (x y : M) : polar Q (a • x) y = a • polar Q x y := 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
Q : QuadraticForm R M
inst✝³ : CommSemiring S
inst✝² : Algebra S R
inst✝¹ : Module S M
inst✝ : IsScalarTower S R M
a : S
x y : M
⊢ polar (⇑Q) (a • x) y = a • polar (⇑Q) x y

Next tactic:
rw [← IsScalarTower.algebraMap_smul R a x, polar_smul_left, Algebra.smul_def]
@[simp]
theorem polar_smul_right_of_tower (a : S) (x y : M) : polar Q x (a • y) = a • polar Q x y := 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
Q : QuadraticForm R M
inst✝³ : CommSemiring S
inst✝² : Algebra S R
inst✝¹ : Module S M
inst✝ : IsScalarTower S R M
a : S
x y : M
⊢ polar (⇑Q) x (a • y) = a • polar (⇑Q) x y

Next tactic:
rw [← IsScalarTower.algebraMap_smul R a y, polar_smul_right, Algebra.smul_def]
/-- An alternative constructor to `QuadraticForm.mk`, for rings where `polar` can be used. -/
@[simps]
def ofPolar (toFun : M → R) (toFun_smul : ∀ (a : R) (x : M), toFun (a • x) = a * a * toFun x)
    (polar_add_left : ∀ x x' y : M, polar toFun (x + x') y = polar toFun x y + polar toFun x' y)
    (polar_smul_left : ∀ (a : R) (x y : M), polar toFun (a • x) y = a • polar toFun x y) :
    QuadraticForm R M :=
  { toFun
    toFun_smul
    exists_companion' :=
      ⟨{  bilin := polar toFun
          bilin_add_left := polar_add_left
          bilin_smul_left := polar_smul_left
          bilin_add_right := fun x y z => 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
Q : QuadraticForm R M
inst✝³ : CommSemiring S
inst✝² : Algebra S R
inst✝¹ : Module S M
inst✝ : IsScalarTower S R M
toFun : M → R
toFun_smul : ∀ (a : R) (x : M), toFun (a • x) = a * a * toFun x
polar_add_left : ∀ (x x' y : M), polar toFun (x + x') y = polar toFun x y + polar toFun x' y
polar_smul_left : ∀ (a : R) (x y : M), polar toFun (a • x) y = a • polar toFun x y
x y z : M
⊢ polar toFun x (y + z) = polar toFun x y + polar toFun x z

Next tactic:
simp_rw [polar_comm _ x, polar_add_left]
/-- An alternative constructor to `QuadraticForm.mk`, for rings where `polar` can be used. -/
@[simps]
def ofPolar (toFun : M → R) (toFun_smul : ∀ (a : R) (x : M), toFun (a • x) = a * a * toFun x)
    (polar_add_left : ∀ x x' y : M, polar toFun (x + x') y = polar toFun x y + polar toFun x' y)
    (polar_smul_left : ∀ (a : R) (x y : M), polar toFun (a • x) y = a • polar toFun x y) :
    QuadraticForm R M :=
  { toFun
    toFun_smul
    exists_companion' :=
      ⟨{  bilin := polar toFun
          bilin_add_left := polar_add_left
          bilin_smul_left := polar_smul_left
          bilin_add_right := fun x y z => by simp_rw [polar_comm _ x, polar_add_left]
          bilin_smul_right := fun r x y => 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
Q : QuadraticForm R M
inst✝³ : CommSemiring S
inst✝² : Algebra S R
inst✝¹ : Module S M
inst✝ : IsScalarTower S R M
toFun : M → R
toFun_smul : ∀ (a : R) (x : M), toFun (a • x) = a * a * toFun x
polar_add_left : ∀ (x x' y : M), polar toFun (x + x') y = polar toFun x y + polar toFun x' y
polar_smul_left : ∀ (a : R) (x y : M), polar toFun (a • x) y = a • polar toFun x y
r : R
x y : M
⊢ polar toFun x (r • y) = r * polar toFun x y

Next tactic:
simp_rw [polar_comm _ x, polar_smul_left, smul_eq_mul]
/-- An alternative constructor to `QuadraticForm.mk`, for rings where `polar` can be used. -/
@[simps]
def ofPolar (toFun : M → R) (toFun_smul : ∀ (a : R) (x : M), toFun (a • x) = a * a * toFun x)
    (polar_add_left : ∀ x x' y : M, polar toFun (x + x') y = polar toFun x y + polar toFun x' y)
    (polar_smul_left : ∀ (a : R) (x y : M), polar toFun (a • x) y = a • polar toFun x y) :
    QuadraticForm R M :=
  { toFun
    toFun_smul
    exists_companion' :=
      ⟨{  bilin := polar toFun
          bilin_add_left := polar_add_left
          bilin_smul_left := polar_smul_left
          bilin_add_right := fun x y z => by simp_rw [polar_comm _ x, polar_add_left]
          bilin_smul_right := fun r x y => by
            simp_rw [polar_comm _ x, polar_smul_left, smul_eq_mul] },
        fun x y => 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
Q : QuadraticForm R M
inst✝³ : CommSemiring S
inst✝² : Algebra S R
inst✝¹ : Module S M
inst✝ : IsScalarTower S R M
toFun : M → R
toFun_smul : ∀ (a : R) (x : M), toFun (a • x) = a * a * toFun x
polar_add_left : ∀ (x x' y : M), polar toFun (x + x') y = polar toFun x y + polar toFun x' y
polar_smul_left : ∀ (a : R) (x y : M), polar toFun (a • x) y = a • polar toFun x y
x y : M
⊢ toFun (x + y) =
    toFun x + toFun y +
      BilinForm.bilin
        { bilin := polar toFun, bilin_add_left := polar_add_left, bilin_smul_left := polar_smul_left,
          bilin_add_right := (_ : ∀ (x y z : M), polar toFun x (y + z) = polar toFun x y + polar toFun x z),
          bilin_smul_right := (_ : ∀ (r : R) (x y : M), polar toFun x (r • y) = r * polar toFun x y) }
        x y

Next tactic:
rw [BilinForm.coeFn_mk, polar, sub_sub, add_sub_cancel'_right]
/-- In a ring the companion bilinear form is unique and equal to `QuadraticForm.polar`. -/
theorem choose_exists_companion : Q.exists_companion.choose = polarBilin Q :=
  BilinForm.ext fun x y => 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
Q : QuadraticForm R M
inst✝³ : CommSemiring S
inst✝² : Algebra S R
inst✝¹ : Module S M
inst✝ : IsScalarTower S R M
x y : M
⊢ BilinForm.bilin (Exists.choose (_ : ∃ B, ∀ (x y : M), Q (x + y) = Q x + Q y + BilinForm.bilin B x y)) x y =
    BilinForm.bilin (polarBilin Q) x y

Next tactic:
rw [polarBilin_apply, polar, Q.exists_companion.choose_spec, sub_sub, add_sub_cancel']
/-- `QuadraticForm R M` inherits the scalar action from any algebra over `R`.

This provides an `R`-action via `Algebra.id`. -/
instance : SMul S (QuadraticForm R M) :=
  ⟨fun a Q =>
    { toFun := a • ⇑Q
      toFun_smul := fun b x => by 

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁸ : CommSemiring R
inst✝⁷ : AddCommMonoid M
inst✝⁶ : Module R M
inst✝⁵ : Monoid S
inst✝⁴ : Monoid T
inst✝³ : DistribMulAction S R
inst✝² : DistribMulAction T R
inst✝¹ : SMulCommClass S R R
inst✝ : SMulCommClass T R R
a : S
Q : QuadraticForm R M
b : R
x : M
⊢ (a • ⇑Q) (b • x) = b * b * (a • ⇑Q) x

Next tactic:
rw [Pi.smul_apply, map_smul, Pi.smul_apply, mul_smul_comm]
/-- `QuadraticForm R M` inherits the scalar action from any algebra over `R`.

This provides an `R`-action via `Algebra.id`. -/
instance : SMul S (QuadraticForm R M) :=
  ⟨fun a Q =>
    { toFun := a • ⇑Q
      toFun_smul := fun b x => by rw [Pi.smul_apply, map_smul, Pi.smul_apply, mul_smul_comm]
      exists_companion' :=
        let ⟨B, h⟩ := Q.exists_companion
        ⟨a • B, by 

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁸ : CommSemiring R
inst✝⁷ : AddCommMonoid M
inst✝⁶ : Module R M
inst✝⁵ : Monoid S
inst✝⁴ : Monoid T
inst✝³ : DistribMulAction S R
inst✝² : DistribMulAction T R
inst✝¹ : SMulCommClass S R R
inst✝ : SMulCommClass T R R
a : S
Q : QuadraticForm R M
B : BilinForm R M
h : ∀ (x y : M), Q (x + y) = Q x + Q y + BilinForm.bilin B x y
⊢ ∀ (x y : M), (a • ⇑Q) (x + y) = (a • ⇑Q) x + (a • ⇑Q) y + BilinForm.bilin (a • B) x y

Next tactic:
simp [h]
instance : Zero (QuadraticForm R M) :=
  ⟨{  toFun := fun _ => 0
      toFun_smul := fun a _ => by 

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝² : CommSemiring R
inst✝¹ : AddCommMonoid M
inst✝ : Module R M
a : R
x✝ : M
⊢ (fun x => 0) (a • x✝) = a * a * (fun x => 0) x✝

Next tactic:
simp only [mul_zero]
instance : Zero (QuadraticForm R M) :=
  ⟨{  toFun := fun _ => 0
      toFun_smul := fun a _ => by simp only [mul_zero]
      exists_companion' := ⟨0, fun _ _ => by 

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝² : CommSemiring R
inst✝¹ : AddCommMonoid M
inst✝ : Module R M
x✝¹ x✝ : M
⊢ (fun x => 0) (x✝¹ + x✝) = (fun x => 0) x✝¹ + (fun x => 0) x✝ + BilinForm.bilin 0 x✝¹ x✝

Next tactic:
simp only [add_zero, BilinForm.zero_apply]
instance : Add (QuadraticForm R M) :=
  ⟨fun Q Q' =>
    { toFun := Q + Q'
      toFun_smul := fun a x => by 

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝² : CommSemiring R
inst✝¹ : AddCommMonoid M
inst✝ : Module R M
Q Q' : QuadraticForm R M
a : R
x : M
⊢ (⇑Q + ⇑Q') (a • x) = a * a * (⇑Q + ⇑Q') x

Next tactic:
simp only [Pi.add_apply, map_smul, mul_add]
instance : Add (QuadraticForm R M) :=
  ⟨fun Q Q' =>
    { toFun := Q + Q'
      toFun_smul := fun a x => by simp only [Pi.add_apply, map_smul, mul_add]
      exists_companion' :=
        let ⟨B, h⟩ := Q.exists_companion
        let ⟨B', h'⟩ := Q'.exists_companion
        ⟨B + B', fun x y => by
          

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝² : CommSemiring R
inst✝¹ : AddCommMonoid M
inst✝ : Module R M
Q Q' : QuadraticForm R M
B : BilinForm R M
h : ∀ (x y : M), Q (x + y) = Q x + Q y + BilinForm.bilin B x y
B' : BilinForm R M
h' : ∀ (x y : M), Q' (x + y) = Q' x + Q' y + BilinForm.bilin B' x y
x y : M
⊢ (⇑Q + ⇑Q') (x + y) = (⇑Q + ⇑Q') x + (⇑Q + ⇑Q') y + BilinForm.bilin (B + B') x y

Next tactic:
simp_rw [Pi.add_apply, h, h', BilinForm.add_apply, add_add_add_comm]
instance [Monoid S] [DistribMulAction S R] [SMulCommClass S R R] :
    DistribMulAction S (QuadraticForm R M) where
  mul_smul a b Q := ext fun x => by simp only [smul_apply, mul_smul]
  one_smul Q := ext fun x => by 

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁵ : CommSemiring R
inst✝⁴ : AddCommMonoid M
inst✝³ : Module R M
inst✝² : Monoid S
inst✝¹ : DistribMulAction S R
inst✝ : SMulCommClass S R R
Q : QuadraticForm R M
x : M
⊢ (1 • Q) x = Q x

Next tactic:
simp only [QuadraticForm.smul_apply, one_smul]
instance [Monoid S] [DistribMulAction S R] [SMulCommClass S R R] :
    DistribMulAction S (QuadraticForm R M) where
  mul_smul a b Q := ext fun x => by 

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁵ : CommSemiring R
inst✝⁴ : AddCommMonoid M
inst✝³ : Module R M
inst✝² : Monoid S
inst✝¹ : DistribMulAction S R
inst✝ : SMulCommClass S R R
a b : S
Q : QuadraticForm R M
x : M
⊢ ((a * b) • Q) x = (a • b • Q) x

Next tactic:
simp only [smul_apply, mul_smul]
instance [Monoid S] [DistribMulAction S R] [SMulCommClass S R R] :
    DistribMulAction S (QuadraticForm R M) where
  mul_smul a b Q := ext fun x => by simp only [smul_apply, mul_smul]
  one_smul Q := ext fun x => by simp only [QuadraticForm.smul_apply, one_smul]
  smul_add a Q Q' := by
    ext
    simp only [add_apply, smul_apply, smul_add]
  smul_zero a := by
    

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁵ : CommSemiring R
inst✝⁴ : AddCommMonoid M
inst✝³ : Module R M
inst✝² : Monoid S
inst✝¹ : DistribMulAction S R
inst✝ : SMulCommClass S R R
a : S
⊢ a • 0 = 0

Next tactic:
ext
instance [Monoid S] [DistribMulAction S R] [SMulCommClass S R R] :
    DistribMulAction S (QuadraticForm R M) where
  mul_smul a b Q := ext fun x => by simp only [smul_apply, mul_smul]
  one_smul Q := ext fun x => by simp only [QuadraticForm.smul_apply, one_smul]
  smul_add a Q Q' := by
    ext
    simp only [add_apply, smul_apply, smul_add]
  smul_zero a := by
    ext
    

Proof state:
case H
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁵ : CommSemiring R
inst✝⁴ : AddCommMonoid M
inst✝³ : Module R M
inst✝² : Monoid S
inst✝¹ : DistribMulAction S R
inst✝ : SMulCommClass S R R
a : S
x✝ : M
⊢ (a • 0) x✝ = 0 x✝

Next tactic:
simp only [zero_apply, smul_apply, smul_zero]
instance [Monoid S] [DistribMulAction S R] [SMulCommClass S R R] :
    DistribMulAction S (QuadraticForm R M) where
  mul_smul a b Q := ext fun x => by simp only [smul_apply, mul_smul]
  one_smul Q := ext fun x => by simp only [QuadraticForm.smul_apply, one_smul]
  smul_add a Q Q' := by
    

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁵ : CommSemiring R
inst✝⁴ : AddCommMonoid M
inst✝³ : Module R M
inst✝² : Monoid S
inst✝¹ : DistribMulAction S R
inst✝ : SMulCommClass S R R
a : S
Q Q' : QuadraticForm R M
⊢ a • (Q + Q') = a • Q + a • Q'

Next tactic:
ext
instance [Monoid S] [DistribMulAction S R] [SMulCommClass S R R] :
    DistribMulAction S (QuadraticForm R M) where
  mul_smul a b Q := ext fun x => by simp only [smul_apply, mul_smul]
  one_smul Q := ext fun x => by simp only [QuadraticForm.smul_apply, one_smul]
  smul_add a Q Q' := by
    ext
    

Proof state:
case H
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁵ : CommSemiring R
inst✝⁴ : AddCommMonoid M
inst✝³ : Module R M
inst✝² : Monoid S
inst✝¹ : DistribMulAction S R
inst✝ : SMulCommClass S R R
a : S
Q Q' : QuadraticForm R M
x✝ : M
⊢ (a • (Q + Q')) x✝ = (a • Q + a • Q') x✝

Next tactic:
simp only [add_apply, smul_apply, smul_add]
instance [Semiring S] [Module S R] [SMulCommClass S R R] : Module S (QuadraticForm R M) where
  zero_smul Q := by
    ext
    simp only [zero_apply, smul_apply, zero_smul]
  add_smul a b Q := by
    

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁵ : CommSemiring R
inst✝⁴ : AddCommMonoid M
inst✝³ : Module R M
inst✝² : Semiring S
inst✝¹ : Module S R
inst✝ : SMulCommClass S R R
a b : S
Q : QuadraticForm R M
⊢ (a + b) • Q = a • Q + b • Q

Next tactic:
ext
instance [Semiring S] [Module S R] [SMulCommClass S R R] : Module S (QuadraticForm R M) where
  zero_smul Q := by
    ext
    simp only [zero_apply, smul_apply, zero_smul]
  add_smul a b Q := by
    ext
    

Proof state:
case H
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁵ : CommSemiring R
inst✝⁴ : AddCommMonoid M
inst✝³ : Module R M
inst✝² : Semiring S
inst✝¹ : Module S R
inst✝ : SMulCommClass S R R
a b : S
Q : QuadraticForm R M
x✝ : M
⊢ ((a + b) • Q) x✝ = (a • Q + b • Q) x✝

Next tactic:
simp only [add_apply, smul_apply, add_smul]
instance [Semiring S] [Module S R] [SMulCommClass S R R] : Module S (QuadraticForm R M) where
  zero_smul Q := by
    

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁵ : CommSemiring R
inst✝⁴ : AddCommMonoid M
inst✝³ : Module R M
inst✝² : Semiring S
inst✝¹ : Module S R
inst✝ : SMulCommClass S R R
Q : QuadraticForm R M
⊢ 0 • Q = 0

Next tactic:
ext
instance [Semiring S] [Module S R] [SMulCommClass S R R] : Module S (QuadraticForm R M) where
  zero_smul Q := by
    ext
    

Proof state:
case H
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁵ : CommSemiring R
inst✝⁴ : AddCommMonoid M
inst✝³ : Module R M
inst✝² : Semiring S
inst✝¹ : Module S R
inst✝ : SMulCommClass S R R
Q : QuadraticForm R M
x✝ : M
⊢ (0 • Q) x✝ = 0 x✝

Next tactic:
simp only [zero_apply, smul_apply, zero_smul]
instance : Neg (QuadraticForm R M) :=
  ⟨fun Q =>
    { toFun := -Q
      toFun_smul := fun a x => 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
Q : QuadraticForm R M
a : R
x : M
⊢ (-⇑Q) (a • x) = a * a * (-⇑Q) x

Next tactic:
simp only [Pi.neg_apply, map_smul, mul_neg]
instance : Neg (QuadraticForm R M) :=
  ⟨fun Q =>
    { toFun := -Q
      toFun_smul := fun a x => by simp only [Pi.neg_apply, map_smul, mul_neg]
      exists_companion' :=
        let ⟨B, h⟩ := Q.exists_companion
        ⟨-B, fun x y => 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
Q : QuadraticForm R M
B : BilinForm R M
h : ∀ (x y : M), Q (x + y) = Q x + Q y + BilinForm.bilin B x y
x y : M
⊢ (-⇑Q) (x + y) = (-⇑Q) x + (-⇑Q) y + BilinForm.bilin (-B) x y

Next tactic:
simp_rw [Pi.neg_apply, h, BilinForm.neg_apply, neg_add]
/-- Compose the quadratic form with a linear function. -/
def comp (Q : QuadraticForm R N) (f : M →ₗ[R] N) : QuadraticForm R M where
  toFun x := Q (f x)
  toFun_smul a x := by 

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁴ : CommSemiring R
inst✝³ : AddCommMonoid M
inst✝² : Module R M
N : Type v
inst✝¹ : AddCommMonoid N
inst✝ : Module R N
Q : QuadraticForm R N
f : M →ₗ[R] N
a : R
x : M
⊢ (fun x => Q (f x)) (a • x) = a * a * (fun x => Q (f x)) x

Next tactic:
simp only [map_smul, f.map_smul]
/-- Compose the quadratic form with a linear function. -/
def comp (Q : QuadraticForm R N) (f : M →ₗ[R] N) : QuadraticForm R M where
  toFun x := Q (f x)
  toFun_smul a x := by simp only [map_smul, f.map_smul]
  exists_companion' :=
    let ⟨B, h⟩ := Q.exists_companion
    ⟨B.comp f f, fun x y => by 

Proof state:
S : Type u_1
T : Type u_2
R : Type u_3
M : Type u_4
inst✝⁴ : CommSemiring R
inst✝³ : AddCommMonoid M
inst✝² : Module R M
N : Type v
inst✝¹ : AddCommMonoid N
inst✝ : Module R N
Q : QuadraticForm R N
f : M →ₗ[R] N
B : BilinForm R N
h : ∀ (x y : N), Q (x + y) = Q x + Q y + BilinForm.bilin B x y
x y : M
⊢ (fun x => Q (f x)) (x + y) = (fun x => Q (f x)) x + (fun x => Q (f x)) y + BilinForm.bilin (BilinForm.comp B f f) x y

Next tactic:
simp_rw [f.map_add, h, BilinForm.comp_apply]