l3lab/ntp-mathlib huggingface dataset:
lemma derivative_det_one_add_X_smul_aux {n} (M : Matrix (Fin n) (Fin n) R) :
    (derivative <| det (1 + (X : R[X]) • M.map C)).eval 0 = trace M := by
  induction n with
  | zero => simp
  | succ n IH =>
    rw [det_succ_row_zero, map_sum, eval_finset_sum]
    simp only [add_apply, smul_apply, map_apply, smul_eq_mul, X_mul_C, submatrix_add,
      submatrix_smul, Pi.add_apply, Pi.smul_apply, submatrix_map, derivative_mul, map_add,
      derivative_C, zero_mul, derivative_X, mul_one, zero_add, eval_add, eval_mul, eval_C, eval_X,
      mul_zero, add_zero, eval_det_add_X_smul, eval_pow, eval_neg, eval_one]
    rw [Finset.sum_eq_single 0]
    · simp only [Fin.val_zero, pow_zero, derivative_one, eval_zero, one_apply_eq, eval_one,
        mul_one, zero_add, one_mul, Fin.succAbove_zero, submatrix_one _ (Fin.succ_injective _),
        det_one, IH, trace_submatrix_succ]
    · intro i _ hi
      cases n with
      | zero => exact (hi (Subsingleton.elim i 0)).elim
      | succ n =>
        simp only [one_apply_ne' hi, eval_zero, mul_zero, zero_add, zero_mul, add_zero]
        

Proof state:
case succ.h₀.succ
R : Type u
inst✝³ : CommRing R
n✝ G : Type v
inst✝² : DecidableEq n✝
inst✝¹ : Fintype n✝
α β : Type v
inst✝ : DecidableEq α
M✝ : Matrix n✝ n✝ R
n : ℕ
IH : ∀ (M : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R), eval 0 (derivative (det (1 + X • map M ⇑C))) = trace M
M : Matrix (Fin (Nat.succ (Nat.succ n))) (Fin (Nat.succ (Nat.succ n))) R
i : Fin (Nat.succ (Nat.succ n))
a✝ : i ∈ univ
hi : i ≠ 0
⊢ (-1) ^ ↑i * (eval 0 (derivative 0) + M 0 i) * eval 0 (det (submatrix 1 Fin.succ (Fin.succAbove i))) = 0

Next tactic:
rw [det_eq_zero_of_column_eq_zero 0, eval_zero, mul_zero]
lemma derivative_det_one_add_X_smul_aux {n} (M : Matrix (Fin n) (Fin n) R) :
    (derivative <| det (1 + (X : R[X]) • M.map C)).eval 0 = trace M := by
  induction n with
  | zero => simp
  | succ n IH =>
    rw [det_succ_row_zero, map_sum, eval_finset_sum]
    simp only [add_apply, smul_apply, map_apply, smul_eq_mul, X_mul_C, submatrix_add,
      submatrix_smul, Pi.add_apply, Pi.smul_apply, submatrix_map, derivative_mul, map_add,
      derivative_C, zero_mul, derivative_X, mul_one, zero_add, eval_add, eval_mul, eval_C, eval_X,
      mul_zero, add_zero, eval_det_add_X_smul, eval_pow, eval_neg, eval_one]
    rw [Finset.sum_eq_single 0]
    · simp only [Fin.val_zero, pow_zero, derivative_one, eval_zero, one_apply_eq, eval_one,
        mul_one, zero_add, one_mul, Fin.succAbove_zero, submatrix_one _ (Fin.succ_injective _),
        det_one, IH, trace_submatrix_succ]
    · intro i _ hi
      cases n with
      | zero => exact (hi (Subsingleton.elim i 0)).elim
      | succ n =>
        simp only [one_apply_ne' hi, eval_zero, mul_zero, zero_add, zero_mul, add_zero]
        rw [det_eq_zero_of_column_eq_zero 0, eval_zero, mul_zero]
        

Proof state:
case succ.h₀.succ
R : Type u
inst✝³ : CommRing R
n✝ G : Type v
inst✝² : DecidableEq n✝
inst✝¹ : Fintype n✝
α β : Type v
inst✝ : DecidableEq α
M✝ : Matrix n✝ n✝ R
n : ℕ
IH : ∀ (M : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R), eval 0 (derivative (det (1 + X • map M ⇑C))) = trace M
M : Matrix (Fin (Nat.succ (Nat.succ n))) (Fin (Nat.succ (Nat.succ n))) R
i : Fin (Nat.succ (Nat.succ n))
a✝ : i ∈ univ
hi : i ≠ 0
⊢ ∀ (i_1 : Fin (Nat.succ n)), submatrix 1 Fin.succ (Fin.succAbove i) i_1 0 = 0

Next tactic:
intro j
lemma derivative_det_one_add_X_smul_aux {n} (M : Matrix (Fin n) (Fin n) R) :
    (derivative <| det (1 + (X : R[X]) • M.map C)).eval 0 = trace M := by
  induction n with
  | zero => simp
  | succ n IH =>
    rw [det_succ_row_zero, map_sum, eval_finset_sum]
    simp only [add_apply, smul_apply, map_apply, smul_eq_mul, X_mul_C, submatrix_add,
      submatrix_smul, Pi.add_apply, Pi.smul_apply, submatrix_map, derivative_mul, map_add,
      derivative_C, zero_mul, derivative_X, mul_one, zero_add, eval_add, eval_mul, eval_C, eval_X,
      mul_zero, add_zero, eval_det_add_X_smul, eval_pow, eval_neg, eval_one]
    rw [Finset.sum_eq_single 0]
    · simp only [Fin.val_zero, pow_zero, derivative_one, eval_zero, one_apply_eq, eval_one,
        mul_one, zero_add, one_mul, Fin.succAbove_zero, submatrix_one _ (Fin.succ_injective _),
        det_one, IH, trace_submatrix_succ]
    · intro i _ hi
      cases n with
      | zero => exact (hi (Subsingleton.elim i 0)).elim
      | succ n =>
        simp only [one_apply_ne' hi, eval_zero, mul_zero, zero_add, zero_mul, add_zero]
        rw [det_eq_zero_of_column_eq_zero 0, eval_zero, mul_zero]
        intro j
        

Proof state:
case succ.h₀.succ
R : Type u
inst✝³ : CommRing R
n✝ G : Type v
inst✝² : DecidableEq n✝
inst✝¹ : Fintype n✝
α β : Type v
inst✝ : DecidableEq α
M✝ : Matrix n✝ n✝ R
n : ℕ
IH : ∀ (M : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R), eval 0 (derivative (det (1 + X • map M ⇑C))) = trace M
M : Matrix (Fin (Nat.succ (Nat.succ n))) (Fin (Nat.succ (Nat.succ n))) R
i : Fin (Nat.succ (Nat.succ n))
a✝ : i ∈ univ
hi : i ≠ 0
j : Fin (Nat.succ n)
⊢ submatrix 1 Fin.succ (Fin.succAbove i) j 0 = 0

Next tactic:
rw [submatrix_apply, Fin.succAbove_below, one_apply_ne]
lemma derivative_det_one_add_X_smul_aux {n} (M : Matrix (Fin n) (Fin n) R) :
    (derivative <| det (1 + (X : R[X]) • M.map C)).eval 0 = trace M := by
  induction n with
  | zero => simp
  | succ n IH =>
    rw [det_succ_row_zero, map_sum, eval_finset_sum]
    simp only [add_apply, smul_apply, map_apply, smul_eq_mul, X_mul_C, submatrix_add,
      submatrix_smul, Pi.add_apply, Pi.smul_apply, submatrix_map, derivative_mul, map_add,
      derivative_C, zero_mul, derivative_X, mul_one, zero_add, eval_add, eval_mul, eval_C, eval_X,
      mul_zero, add_zero, eval_det_add_X_smul, eval_pow, eval_neg, eval_one]
    rw [Finset.sum_eq_single 0]
    · simp only [Fin.val_zero, pow_zero, derivative_one, eval_zero, one_apply_eq, eval_one,
        mul_one, zero_add, one_mul, Fin.succAbove_zero, submatrix_one _ (Fin.succ_injective _),
        det_one, IH, trace_submatrix_succ]
    · intro i _ hi
      cases n with
      | zero => exact (hi (Subsingleton.elim i 0)).elim
      | succ n =>
        simp only [one_apply_ne' hi, eval_zero, mul_zero, zero_add, zero_mul, add_zero]
        rw [det_eq_zero_of_column_eq_zero 0, eval_zero, mul_zero]
        intro j
        rw [submatrix_apply, Fin.succAbove_below, one_apply_ne]
        · 

Proof state:
case succ.h₀.succ
R : Type u
inst✝³ : CommRing R
n✝ G : Type v
inst✝² : DecidableEq n✝
inst✝¹ : Fintype n✝
α β : Type v
inst✝ : DecidableEq α
M✝ : Matrix n✝ n✝ R
n : ℕ
IH : ∀ (M : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R), eval 0 (derivative (det (1 + X • map M ⇑C))) = trace M
M : Matrix (Fin (Nat.succ (Nat.succ n))) (Fin (Nat.succ (Nat.succ n))) R
i : Fin (Nat.succ (Nat.succ n))
a✝ : i ∈ univ
hi : i ≠ 0
j : Fin (Nat.succ n)
⊢ Fin.succ j ≠ Fin.castSucc 0

Next tactic:
exact (bne_iff_ne (Fin.succ j) (Fin.castSucc 0)).mp rfl
lemma derivative_det_one_add_X_smul_aux {n} (M : Matrix (Fin n) (Fin n) R) :
    (derivative <| det (1 + (X : R[X]) • M.map C)).eval 0 = trace M := by
  induction n with
  | zero => simp
  | succ n IH =>
    rw [det_succ_row_zero, map_sum, eval_finset_sum]
    simp only [add_apply, smul_apply, map_apply, smul_eq_mul, X_mul_C, submatrix_add,
      submatrix_smul, Pi.add_apply, Pi.smul_apply, submatrix_map, derivative_mul, map_add,
      derivative_C, zero_mul, derivative_X, mul_one, zero_add, eval_add, eval_mul, eval_C, eval_X,
      mul_zero, add_zero, eval_det_add_X_smul, eval_pow, eval_neg, eval_one]
    rw [Finset.sum_eq_single 0]
    · simp only [Fin.val_zero, pow_zero, derivative_one, eval_zero, one_apply_eq, eval_one,
        mul_one, zero_add, one_mul, Fin.succAbove_zero, submatrix_one _ (Fin.succ_injective _),
        det_one, IH, trace_submatrix_succ]
    · intro i _ hi
      cases n with
      | zero => exact (hi (Subsingleton.elim i 0)).elim
      | succ n =>
        simp only [one_apply_ne' hi, eval_zero, mul_zero, zero_add, zero_mul, add_zero]
        rw [det_eq_zero_of_column_eq_zero 0, eval_zero, mul_zero]
        intro j
        rw [submatrix_apply, Fin.succAbove_below, one_apply_ne]
        · exact (bne_iff_ne (Fin.succ j) (Fin.castSucc 0)).mp rfl
        · 

Proof state:
case succ.h₀.succ.h
R : Type u
inst✝³ : CommRing R
n✝ G : Type v
inst✝² : DecidableEq n✝
inst✝¹ : Fintype n✝
α β : Type v
inst✝ : DecidableEq α
M✝ : Matrix n✝ n✝ R
n : ℕ
IH : ∀ (M : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R), eval 0 (derivative (det (1 + X • map M ⇑C))) = trace M
M : Matrix (Fin (Nat.succ (Nat.succ n))) (Fin (Nat.succ (Nat.succ n))) R
i : Fin (Nat.succ (Nat.succ n))
a✝ : i ∈ univ
hi : i ≠ 0
j : Fin (Nat.succ n)
⊢ Fin.castSucc 0 < i

Next tactic:
rw [Fin.castSucc_zero]
lemma derivative_det_one_add_X_smul_aux {n} (M : Matrix (Fin n) (Fin n) R) :
    (derivative <| det (1 + (X : R[X]) • M.map C)).eval 0 = trace M := by
  induction n with
  | zero => simp
  | succ n IH =>
    rw [det_succ_row_zero, map_sum, eval_finset_sum]
    simp only [add_apply, smul_apply, map_apply, smul_eq_mul, X_mul_C, submatrix_add,
      submatrix_smul, Pi.add_apply, Pi.smul_apply, submatrix_map, derivative_mul, map_add,
      derivative_C, zero_mul, derivative_X, mul_one, zero_add, eval_add, eval_mul, eval_C, eval_X,
      mul_zero, add_zero, eval_det_add_X_smul, eval_pow, eval_neg, eval_one]
    rw [Finset.sum_eq_single 0]
    · simp only [Fin.val_zero, pow_zero, derivative_one, eval_zero, one_apply_eq, eval_one,
        mul_one, zero_add, one_mul, Fin.succAbove_zero, submatrix_one _ (Fin.succ_injective _),
        det_one, IH, trace_submatrix_succ]
    · intro i _ hi
      cases n with
      | zero => exact (hi (Subsingleton.elim i 0)).elim
      | succ n =>
        simp only [one_apply_ne' hi, eval_zero, mul_zero, zero_add, zero_mul, add_zero]
        rw [det_eq_zero_of_column_eq_zero 0, eval_zero, mul_zero]
        intro j
        rw [submatrix_apply, Fin.succAbove_below, one_apply_ne]
        · exact (bne_iff_ne (Fin.succ j) (Fin.castSucc 0)).mp rfl
        · rw [Fin.castSucc_zero]; 

Proof state:
case succ.h₀.succ.h
R : Type u
inst✝³ : CommRing R
n✝ G : Type v
inst✝² : DecidableEq n✝
inst✝¹ : Fintype n✝
α β : Type v
inst✝ : DecidableEq α
M✝ : Matrix n✝ n✝ R
n : ℕ
IH : ∀ (M : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R), eval 0 (derivative (det (1 + X • map M ⇑C))) = trace M
M : Matrix (Fin (Nat.succ (Nat.succ n))) (Fin (Nat.succ (Nat.succ n))) R
i : Fin (Nat.succ (Nat.succ n))
a✝ : i ∈ univ
hi : i ≠ 0
j : Fin (Nat.succ n)
⊢ 0 < i

Next tactic:
exact lt_of_le_of_ne (Fin.zero_le _) hi.symm
lemma derivative_det_one_add_X_smul_aux {n} (M : Matrix (Fin n) (Fin n) R) :
    (derivative <| det (1 + (X : R[X]) • M.map C)).eval 0 = trace M := by
  induction n with
  | zero => simp
  | succ n IH =>
    rw [det_succ_row_zero, map_sum, eval_finset_sum]
    simp only [add_apply, smul_apply, map_apply, smul_eq_mul, X_mul_C, submatrix_add,
      submatrix_smul, Pi.add_apply, Pi.smul_apply, submatrix_map, derivative_mul, map_add,
      derivative_C, zero_mul, derivative_X, mul_one, zero_add, eval_add, eval_mul, eval_C, eval_X,
      mul_zero, add_zero, eval_det_add_X_smul, eval_pow, eval_neg, eval_one]
    rw [Finset.sum_eq_single 0]
    · simp only [Fin.val_zero, pow_zero, derivative_one, eval_zero, one_apply_eq, eval_one,
        mul_one, zero_add, one_mul, Fin.succAbove_zero, submatrix_one _ (Fin.succ_injective _),
        det_one, IH, trace_submatrix_succ]
    · intro i _ hi
      cases n with
      | zero => exact (hi (Subsingleton.elim i 0)).elim
      | succ n =>
        simp only [one_apply_ne' hi, eval_zero, mul_zero, zero_add, zero_mul, add_zero]
        rw [det_eq_zero_of_column_eq_zero 0, eval_zero, mul_zero]
        intro j
        rw [submatrix_apply, Fin.succAbove_below, one_apply_ne]
        · exact (bne_iff_ne (Fin.succ j) (Fin.castSucc 0)).mp rfl
        · rw [Fin.castSucc_zero]; exact lt_of_le_of_ne (Fin.zero_le _) hi.symm
    · 

Proof state:
case succ.h₁
R : Type u
inst✝³ : CommRing R
n✝ G : Type v
inst✝² : DecidableEq n✝
inst✝¹ : Fintype n✝
α β : Type v
inst✝ : DecidableEq α
M✝ : Matrix n✝ n✝ R
n : ℕ
IH : ∀ (M : Matrix (Fin n) (Fin n) R), eval 0 (derivative (det (1 + X • map M ⇑C))) = trace M
M : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R
⊢ 0 ∉ univ →
    (eval 0 (derivative ((-1) ^ ↑0)) * eval 0 (OfNat.ofNat 1 0 0) +
            (-1) ^ ↑0 * (eval 0 (derivative (OfNat.ofNat 1 0 0)) + M 0 0)) *
          eval 0 (det (submatrix 1 Fin.succ (Fin.succAbove 0))) +
        (-1) ^ ↑0 * eval 0 (OfNat.ofNat 1 0 0) *
          eval 0
            (derivative
              (det (submatrix 1 Fin.succ (Fin.succAbove 0) + X • map (submatrix M Fin.succ (Fin.succAbove 0)) ⇑C))) =
      0

Next tactic:
exact fun H ↦ (H <| Finset.mem_univ _).elim
/-- The derivative of `det (1 + M X)` at `0` is the trace of `M`. -/
lemma derivative_det_one_add_X_smul (M : Matrix n n R) :
    (derivative <| det (1 + (X : R[X]) • M.map C)).eval 0 = trace M := by
  

Proof state:
R : Type u
inst✝³ : CommRing R
n G : Type v
inst✝² : DecidableEq n
inst✝¹ : Fintype n
α β : Type v
inst✝ : DecidableEq α
M✝ M : Matrix n n R
⊢ eval 0 (derivative (det (1 + X • map M ⇑C))) = trace M

Next tactic:
let e := Matrix.reindexLinearEquiv R R (Fintype.equivFin n) (Fintype.equivFin n)
/-- The derivative of `det (1 + M X)` at `0` is the trace of `M`. -/
lemma derivative_det_one_add_X_smul (M : Matrix n n R) :
    (derivative <| det (1 + (X : R[X]) • M.map C)).eval 0 = trace M := by
  let e := Matrix.reindexLinearEquiv R R (Fintype.equivFin n) (Fintype.equivFin n)
  

Proof state:
R : Type u
inst✝³ : CommRing R
n G : Type v
inst✝² : DecidableEq n
inst✝¹ : Fintype n
α β : Type v
inst✝ : DecidableEq α
M✝ M : Matrix n n R
e : Matrix n n R ≃ₗ[R] Matrix (Fin (Fintype.card n)) (Fin (Fintype.card n)) R :=
  reindexLinearEquiv R R (Fintype.equivFin n) (Fintype.equivFin n)
⊢ eval 0 (derivative (det (1 + X • map M ⇑C))) = trace M

Next tactic:
rw [← Matrix.det_reindexLinearEquiv_self R[X] (Fintype.equivFin n)]
/-- The derivative of `det (1 + M X)` at `0` is the trace of `M`. -/
lemma derivative_det_one_add_X_smul (M : Matrix n n R) :
    (derivative <| det (1 + (X : R[X]) • M.map C)).eval 0 = trace M := by
  let e := Matrix.reindexLinearEquiv R R (Fintype.equivFin n) (Fintype.equivFin n)
  rw [← Matrix.det_reindexLinearEquiv_self R[X] (Fintype.equivFin n)]
  

Proof state:
R : Type u
inst✝³ : CommRing R
n G : Type v
inst✝² : DecidableEq n
inst✝¹ : Fintype n
α β : Type v
inst✝ : DecidableEq α
M✝ M : Matrix n n R
e : Matrix n n R ≃ₗ[R] Matrix (Fin (Fintype.card n)) (Fin (Fintype.card n)) R :=
  reindexLinearEquiv R R (Fintype.equivFin n) (Fintype.equivFin n)
⊢ eval 0
      (derivative (det ((reindexLinearEquiv R[X] R[X] (Fintype.equivFin n) (Fintype.equivFin n)) (1 + X • map M ⇑C)))) =
    trace M

Next tactic:
convert derivative_det_one_add_X_smul_aux (e M)
/-- The derivative of `det (1 + M X)` at `0` is the trace of `M`. -/
lemma derivative_det_one_add_X_smul (M : Matrix n n R) :
    (derivative <| det (1 + (X : R[X]) • M.map C)).eval 0 = trace M := by
  let e := Matrix.reindexLinearEquiv R R (Fintype.equivFin n) (Fintype.equivFin n)
  rw [← Matrix.det_reindexLinearEquiv_self R[X] (Fintype.equivFin n)]
  convert derivative_det_one_add_X_smul_aux (e M)
  · 

Proof state:
case h.e'_2.h.e'_4.h.e'_6.h.e'_6
R : Type u
inst✝³ : CommRing R
n G : Type v
inst✝² : DecidableEq n
inst✝¹ : Fintype n
α β : Type v
inst✝ : DecidableEq α
M✝ M : Matrix n n R
e : Matrix n n R ≃ₗ[R] Matrix (Fin (Fintype.card n)) (Fin (Fintype.card n)) R :=
  reindexLinearEquiv R R (Fintype.equivFin n) (Fintype.equivFin n)
⊢ (reindexLinearEquiv R[X] R[X] (Fintype.equivFin n) (Fintype.equivFin n)) (1 + X • map M ⇑C) = 1 + X • map (e M) ⇑C

Next tactic:
ext
/-- The derivative of `det (1 + M X)` at `0` is the trace of `M`. -/
lemma derivative_det_one_add_X_smul (M : Matrix n n R) :
    (derivative <| det (1 + (X : R[X]) • M.map C)).eval 0 = trace M := by
  let e := Matrix.reindexLinearEquiv R R (Fintype.equivFin n) (Fintype.equivFin n)
  rw [← Matrix.det_reindexLinearEquiv_self R[X] (Fintype.equivFin n)]
  convert derivative_det_one_add_X_smul_aux (e M)
  · ext; 

Proof state:
case h.e'_2.h.e'_4.h.e'_6.h.e'_6.a.h.a
R : Type u
inst✝³ : CommRing R
n G : Type v
inst✝² : DecidableEq n
inst✝¹ : Fintype n
α β : Type v
inst✝ : DecidableEq α
M✝ M : Matrix n n R
e : Matrix n n R ≃ₗ[R] Matrix (Fin (Fintype.card n)) (Fin (Fintype.card n)) R :=
  reindexLinearEquiv R R (Fintype.equivFin n) (Fintype.equivFin n)
i✝ x✝ : Fin (Fintype.card n)
n✝ : ℕ
⊢ coeff ((reindexLinearEquiv R[X] R[X] (Fintype.equivFin n) (Fintype.equivFin n)) (1 + X • map M ⇑C) i✝ x✝) n✝ =
    coeff ((1 + X • map (e M) ⇑C) i✝ x✝) n✝

Next tactic:
simp
/-- The derivative of `det (1 + M X)` at `0` is the trace of `M`. -/
lemma derivative_det_one_add_X_smul (M : Matrix n n R) :
    (derivative <| det (1 + (X : R[X]) • M.map C)).eval 0 = trace M := by
  let e := Matrix.reindexLinearEquiv R R (Fintype.equivFin n) (Fintype.equivFin n)
  rw [← Matrix.det_reindexLinearEquiv_self R[X] (Fintype.equivFin n)]
  convert derivative_det_one_add_X_smul_aux (e M)
  · ext; simp
  · 

Proof state:
case h.e'_3
R : Type u
inst✝³ : CommRing R
n G : Type v
inst✝² : DecidableEq n
inst✝¹ : Fintype n
α β : Type v
inst✝ : DecidableEq α
M✝ M : Matrix n n R
e : Matrix n n R ≃ₗ[R] Matrix (Fin (Fintype.card n)) (Fin (Fintype.card n)) R :=
  reindexLinearEquiv R R (Fintype.equivFin n) (Fintype.equivFin n)
⊢ trace M = trace (e M)

Next tactic:
delta trace
/-- The derivative of `det (1 + M X)` at `0` is the trace of `M`. -/
lemma derivative_det_one_add_X_smul (M : Matrix n n R) :
    (derivative <| det (1 + (X : R[X]) • M.map C)).eval 0 = trace M := by
  let e := Matrix.reindexLinearEquiv R R (Fintype.equivFin n) (Fintype.equivFin n)
  rw [← Matrix.det_reindexLinearEquiv_self R[X] (Fintype.equivFin n)]
  convert derivative_det_one_add_X_smul_aux (e M)
  · ext; simp
  · delta trace
    

Proof state:
case h.e'_3
R : Type u
inst✝³ : CommRing R
n G : Type v
inst✝² : DecidableEq n
inst✝¹ : Fintype n
α β : Type v
inst✝ : DecidableEq α
M✝ M : Matrix n n R
e : Matrix n n R ≃ₗ[R] Matrix (Fin (Fintype.card n)) (Fin (Fintype.card n)) R :=
  reindexLinearEquiv R R (Fintype.equivFin n) (Fintype.equivFin n)
⊢ ∑ i : n, diag M i = ∑ i : Fin (Fintype.card n), diag (e M) i

Next tactic:
rw [← (Fintype.equivFin n).symm.sum_comp]
/-- The derivative of `det (1 + M X)` at `0` is the trace of `M`. -/
lemma derivative_det_one_add_X_smul (M : Matrix n n R) :
    (derivative <| det (1 + (X : R[X]) • M.map C)).eval 0 = trace M := by
  let e := Matrix.reindexLinearEquiv R R (Fintype.equivFin n) (Fintype.equivFin n)
  rw [← Matrix.det_reindexLinearEquiv_self R[X] (Fintype.equivFin n)]
  convert derivative_det_one_add_X_smul_aux (e M)
  · ext; simp
  · delta trace
    rw [← (Fintype.equivFin n).symm.sum_comp]
    

Proof state:
case h.e'_3
R : Type u
inst✝³ : CommRing R
n G : Type v
inst✝² : DecidableEq n
inst✝¹ : Fintype n
α β : Type v
inst✝ : DecidableEq α
M✝ M : Matrix n n R
e : Matrix n n R ≃ₗ[R] Matrix (Fin (Fintype.card n)) (Fin (Fintype.card n)) R :=
  reindexLinearEquiv R R (Fintype.equivFin n) (Fintype.equivFin n)
⊢ ∑ i : Fin (Fintype.card n), diag M ((Fintype.equivFin n).symm i) = ∑ i : Fin (Fintype.card n), diag (e M) i

Next tactic:
rfl
lemma coeff_det_one_add_X_smul_one (M : Matrix n n R) :
    (det (1 + (X : R[X]) • M.map C)).coeff 1 = trace M := by
  

Proof state:
R : Type u
inst✝³ : CommRing R
n G : Type v
inst✝² : DecidableEq n
inst✝¹ : Fintype n
α β : Type v
inst✝ : DecidableEq α
M✝ M : Matrix n n R
⊢ coeff (det (1 + X • map M ⇑C)) 1 = trace M

Next tactic:
simp only [← derivative_det_one_add_X_smul, ← coeff_zero_eq_eval_zero,
    coeff_derivative, zero_add, Nat.cast_zero, mul_one]
lemma det_one_add_X_smul (M : Matrix n n R) :
    det (1 + (X : R[X]) • M.map C) =
      (1 : R[X]) + trace M • X + (det (1 + (X : R[X]) • M.map C)).divX.divX * X ^ 2 := by
  

Proof state:
R : Type u
inst✝³ : CommRing R
n G : Type v
inst✝² : DecidableEq n
inst✝¹ : Fintype n
α β : Type v
inst✝ : DecidableEq α
M✝ M : Matrix n n R
⊢ det (1 + X • map M ⇑C) = 1 + trace M • X + divX (divX (det (1 + X • map M ⇑C))) * X ^ 2

Next tactic:
rw [Algebra.smul_def (trace M), ← C_eq_algebraMap, pow_two, ← mul_assoc, add_assoc,
    ← add_mul, ← coeff_det_one_add_X_smul_one, ← coeff_divX, add_comm (C _), divX_mul_X_add,
    add_comm (1 : R[X]), ← C.map_one]
lemma det_one_add_X_smul (M : Matrix n n R) :
    det (1 + (X : R[X]) • M.map C) =
      (1 : R[X]) + trace M • X + (det (1 + (X : R[X]) • M.map C)).divX.divX * X ^ 2 := by
  rw [Algebra.smul_def (trace M), ← C_eq_algebraMap, pow_two, ← mul_assoc, add_assoc,
    ← add_mul, ← coeff_det_one_add_X_smul_one, ← coeff_divX, add_comm (C _), divX_mul_X_add,
    add_comm (1 : R[X]), ← C.map_one]
  

Proof state:
R : Type u
inst✝³ : CommRing R
n G : Type v
inst✝² : DecidableEq n
inst✝¹ : Fintype n
α β : Type v
inst✝ : DecidableEq α
M✝ M : Matrix n n R
⊢ det (1 + X • map M ⇑C) = divX (det (1 + X • map M ⇑C)) * X + C 1

Next tactic:
convert (divX_mul_X_add _).symm
lemma det_one_add_X_smul (M : Matrix n n R) :
    det (1 + (X : R[X]) • M.map C) =
      (1 : R[X]) + trace M • X + (det (1 + (X : R[X]) • M.map C)).divX.divX * X ^ 2 := by
  rw [Algebra.smul_def (trace M), ← C_eq_algebraMap, pow_two, ← mul_assoc, add_assoc,
    ← add_mul, ← coeff_det_one_add_X_smul_one, ← coeff_divX, add_comm (C _), divX_mul_X_add,
    add_comm (1 : R[X]), ← C.map_one]
  convert (divX_mul_X_add _).symm
  

Proof state:
case h.e'_3.h.e'_6.h.e'_6
R : Type u
inst✝³ : CommRing R
n G : Type v
inst✝² : DecidableEq n
inst✝¹ : Fintype n
α β : Type v
inst✝ : DecidableEq α
M✝ M : Matrix n n R
⊢ 1 = coeff (det (1 + X • map M ⇑C)) 0

Next tactic:
rw [coeff_zero_eq_eval_zero, eval_det_add_X_smul, det_one, eval_one]
/-- The first two terms of the taylor expansion of `det (1 + r • M)` at `r = 0`. -/
lemma det_one_add_smul (r : R) (M : Matrix n n R) :
    det (1 + r • M) =
      1 + trace M * r + (det (1 + (X : R[X]) • M.map C)).divX.divX.eval r * r ^ 2 := by
  

Proof state:
R : Type u
inst✝³ : CommRing R
n G : Type v
inst✝² : DecidableEq n
inst✝¹ : Fintype n
α β : Type v
inst✝ : DecidableEq α
M✝ : Matrix n n R
r : R
M : Matrix n n R
⊢ det (1 + r • M) = 1 + trace M * r + eval r (divX (divX (det (1 + X • map M ⇑C)))) * r ^ 2

Next tactic:
simpa [eval_det, ← smul_eq_mul_diagonal] using congr_arg (eval r) (Matrix.det_one_add_X_smul M)
theorem matPolyEquiv_eq_x_pow_sub_c {K : Type*} (k : ℕ) [Field K] (M : Matrix n n K) :
    matPolyEquiv ((expand K k : K[X] →+* K[X]).mapMatrix (charmatrix (M ^ k))) =
      X ^ k - C (M ^ k) := by
  -- porting note: `i` and `j` are used later on, but were not mentioned in mathlib3
  

Proof state:
R : Type u
inst✝⁵ : CommRing R
n G : Type v
inst✝⁴ : DecidableEq n
inst✝³ : Fintype n
α β : Type v
inst✝² : DecidableEq α
M✝ : Matrix n n R
p : ℕ
inst✝¹ : Fact (Nat.Prime p)
K : Type u_1
k : ℕ
inst✝ : Field K
M : Matrix n n K
⊢ matPolyEquiv ((RingHom.mapMatrix ↑(expand K k)) (charmatrix (M ^ k))) = X ^ k - C (M ^ k)

Next tactic:
ext m i j
theorem matPolyEquiv_eq_x_pow_sub_c {K : Type*} (k : ℕ) [Field K] (M : Matrix n n K) :
    matPolyEquiv ((expand K k : K[X] →+* K[X]).mapMatrix (charmatrix (M ^ k))) =
      X ^ k - C (M ^ k) := by
  -- porting note: `i` and `j` are used later on, but were not mentioned in mathlib3
  ext m i j
  

Proof state:
case a.a.h
R : Type u
inst✝⁵ : CommRing R
n G : Type v
inst✝⁴ : DecidableEq n
inst✝³ : Fintype n
α β : Type v
inst✝² : DecidableEq α
M✝ : Matrix n n R
p : ℕ
inst✝¹ : Fact (Nat.Prime p)
K : Type u_1
k : ℕ
inst✝ : Field K
M : Matrix n n K
m : ℕ
i j : n
⊢ coeff (matPolyEquiv ((RingHom.mapMatrix ↑(expand K k)) (charmatrix (M ^ k)))) m i j = coeff (X ^ k - C (M ^ k)) m i j

Next tactic:
rw [coeff_sub, coeff_C, matPolyEquiv_coeff_apply, RingHom.mapMatrix_apply, Matrix.map_apply,
    AlgHom.coe_toRingHom, DMatrix.sub_apply, coeff_X_pow]