l3lab/ntp-mathlib huggingface dataset:
theorem nondegenerate_iff_det_ne_zero {A : Type*} [DecidableEq n] [CommRing A] [IsDomain A]
    {M : Matrix n n A} : Nondegenerate M ↔ M.det ≠ 0 := by
  rw [ne_eq, ← exists_vecMul_eq_zero_iff]
  push_neg
  constructor
  · intro hM v hv hMv
    obtain ⟨w, hwMv⟩ := hM.exists_not_ortho_of_ne_zero hv
    simp [dotProduct_mulVec, hMv, zero_dotProduct, ne_eq, not_true] at hwMv
  · intro h v hv
    refine' not_imp_not.mp (h v) (funext fun i => _)
    

Proof state:
case mpr
n : Type u_1
inst✝⁶ : Fintype n
R : Type u_2
M✝ : Type u_3
inst✝⁵ : CommRing R
inst✝⁴ : AddCommGroup M✝
inst✝³ : Module R M✝
A : Type u_4
inst✝² : DecidableEq n
inst✝¹ : CommRing A
inst✝ : IsDomain A
M : Matrix n n A
h : ∀ (v : n → A), v ≠ 0 → vecMul v M ≠ 0
v : n → A
hv : ∀ (w : n → A), v ⬝ᵥ mulVec M w = 0
i : n
⊢ vecMul v M i = OfNat.ofNat 0 i

Next tactic:
simpa only [dotProduct_mulVec, dotProduct_single, mul_one] using hv (Pi.single i 1)
/-- A matrix whose nondiagonal entries are negative with the sum of the entries of each
column positive has nonzero determinant. -/
lemma det_ne_zero_of_sum_col_pos [DecidableEq n] {S : Type*} [LinearOrderedCommRing S]
    {A : Matrix n n S} (h1 : ∀ i j, i ≠ j → A i j < 0) (h2 : ∀ j, 0 < ∑ i, A i j) :
    A.det ≠ 0 := by
  

Proof state:
n : Type u_1
inst✝² : Fintype n
inst✝¹ : DecidableEq n
S : Type u_2
inst✝ : LinearOrderedCommRing S
A : Matrix n n S
h1 : ∀ (i j : n), i ≠ j → A i j < 0
h2 : ∀ (j : n), 0 < ∑ i : n, A i j
⊢ det A ≠ 0

Next tactic:
cases isEmpty_or_nonempty n
/-- A matrix whose nondiagonal entries are negative with the sum of the entries of each
column positive has nonzero determinant. -/
lemma det_ne_zero_of_sum_col_pos [DecidableEq n] {S : Type*} [LinearOrderedCommRing S]
    {A : Matrix n n S} (h1 : ∀ i j, i ≠ j → A i j < 0) (h2 : ∀ j, 0 < ∑ i, A i j) :
    A.det ≠ 0 := by
  cases isEmpty_or_nonempty n
  · 

Proof state:
case inl
n : Type u_1
inst✝² : Fintype n
inst✝¹ : DecidableEq n
S : Type u_2
inst✝ : LinearOrderedCommRing S
A : Matrix n n S
h1 : ∀ (i j : n), i ≠ j → A i j < 0
h2 : ∀ (j : n), 0 < ∑ i : n, A i j
h✝ : IsEmpty n
⊢ det A ≠ 0

Next tactic:
simp
/-- A matrix whose nondiagonal entries are negative with the sum of the entries of each
column positive has nonzero determinant. -/
lemma det_ne_zero_of_sum_col_pos [DecidableEq n] {S : Type*} [LinearOrderedCommRing S]
    {A : Matrix n n S} (h1 : ∀ i j, i ≠ j → A i j < 0) (h2 : ∀ j, 0 < ∑ i, A i j) :
    A.det ≠ 0 := by
  cases isEmpty_or_nonempty n
  · simp
  · 

Proof state:
case inr
n : Type u_1
inst✝² : Fintype n
inst✝¹ : DecidableEq n
S : Type u_2
inst✝ : LinearOrderedCommRing S
A : Matrix n n S
h1 : ∀ (i j : n), i ≠ j → A i j < 0
h2 : ∀ (j : n), 0 < ∑ i : n, A i j
h✝ : Nonempty n
⊢ det A ≠ 0

Next tactic:
contrapose! h2
/-- A matrix whose nondiagonal entries are negative with the sum of the entries of each
column positive has nonzero determinant. -/
lemma det_ne_zero_of_sum_col_pos [DecidableEq n] {S : Type*} [LinearOrderedCommRing S]
    {A : Matrix n n S} (h1 : ∀ i j, i ≠ j → A i j < 0) (h2 : ∀ j, 0 < ∑ i, A i j) :
    A.det ≠ 0 := by
  cases isEmpty_or_nonempty n
  · simp
  · contrapose! h2
    

Proof state:
case inr
n : Type u_1
inst✝² : Fintype n
inst✝¹ : DecidableEq n
S : Type u_2
inst✝ : LinearOrderedCommRing S
A : Matrix n n S
h1 : ∀ (i j : n), i ≠ j → A i j < 0
h✝ : Nonempty n
h2 : det A = 0
⊢ ∃ j, ∑ i : n, A i j ≤ 0

Next tactic:
obtain ⟨v, ⟨h_vnz, h_vA⟩⟩ := Matrix.exists_vecMul_eq_zero_iff.mpr h2
/-- A matrix whose nondiagonal entries are negative with the sum of the entries of each
column positive has nonzero determinant. -/
lemma det_ne_zero_of_sum_col_pos [DecidableEq n] {S : Type*} [LinearOrderedCommRing S]
    {A : Matrix n n S} (h1 : ∀ i j, i ≠ j → A i j < 0) (h2 : ∀ j, 0 < ∑ i, A i j) :
    A.det ≠ 0 := by
  cases isEmpty_or_nonempty n
  · simp
  · contrapose! h2
    obtain ⟨v, ⟨h_vnz, h_vA⟩⟩ := Matrix.exists_vecMul_eq_zero_iff.mpr h2
    

Proof state:
case inr.intro.intro
n : Type u_1
inst✝² : Fintype n
inst✝¹ : DecidableEq n
S : Type u_2
inst✝ : LinearOrderedCommRing S
A : Matrix n n S
h1 : ∀ (i j : n), i ≠ j → A i j < 0
h✝ : Nonempty n
h2 : det A = 0
v : n → S
h_vnz : v ≠ 0
h_vA : vecMul v A = 0
⊢ ∃ j, ∑ i : n, A i j ≤ 0

Next tactic:
wlog h_sup : 0 < Finset.sup' Finset.univ Finset.univ_nonempty v
/-- A matrix whose nondiagonal entries are negative with the sum of the entries of each
column positive has nonzero determinant. -/
lemma det_ne_zero_of_sum_col_pos [DecidableEq n] {S : Type*} [LinearOrderedCommRing S]
    {A : Matrix n n S} (h1 : ∀ i j, i ≠ j → A i j < 0) (h2 : ∀ j, 0 < ∑ i, A i j) :
    A.det ≠ 0 := by
  cases isEmpty_or_nonempty n
  · simp
  · contrapose! h2
    obtain ⟨v, ⟨h_vnz, h_vA⟩⟩ := Matrix.exists_vecMul_eq_zero_iff.mpr h2
    wlog h_sup : 0 < Finset.sup' Finset.univ Finset.univ_nonempty v
    · 

Proof state:
case inr.intro.intro.inr
n : Type u_1
inst✝² : Fintype n
inst✝¹ : DecidableEq n
S : Type u_2
inst✝ : LinearOrderedCommRing S
A : Matrix n n S
h1 : ∀ (i j : n), i ≠ j → A i j < 0
h✝ : Nonempty n
h2 : det A = 0
v : n → S
h_vnz : v ≠ 0
h_vA : vecMul v A = 0
this :
  ∀ {n : Type u_1} [inst : Fintype n] [inst_1 : DecidableEq n] {S : Type u_2} [inst_2 : LinearOrderedCommRing S]
    {A : Matrix n n S},
    (∀ (i j : n), i ≠ j → A i j < 0) →
      ∀ (h : Nonempty n),
        det A = 0 →
          ∀ (v : n → S),
            v ≠ 0 →
              vecMul v A = 0 → 0 < Finset.sup' Finset.univ (_ : Finset.Nonempty Finset.univ) v → ∃ j, ∑ i : n, A i j ≤ 0
h_sup : ¬0 < Finset.sup' Finset.univ (_ : Finset.Nonempty Finset.univ) v
⊢ ∃ j, ∑ i : n, A i j ≤ 0

Next tactic:
refine this h1 inferInstance h2 (-1 • v) ?_ ?_ ?_
/-- A matrix whose nondiagonal entries are negative with the sum of the entries of each
column positive has nonzero determinant. -/
lemma det_ne_zero_of_sum_col_pos [DecidableEq n] {S : Type*} [LinearOrderedCommRing S]
    {A : Matrix n n S} (h1 : ∀ i j, i ≠ j → A i j < 0) (h2 : ∀ j, 0 < ∑ i, A i j) :
    A.det ≠ 0 := by
  cases isEmpty_or_nonempty n
  · simp
  · contrapose! h2
    obtain ⟨v, ⟨h_vnz, h_vA⟩⟩ := Matrix.exists_vecMul_eq_zero_iff.mpr h2
    wlog h_sup : 0 < Finset.sup' Finset.univ Finset.univ_nonempty v
    · refine this h1 inferInstance h2 (-1 • v) ?_ ?_ ?_
      · 

Proof state:
case inr.intro.intro.inr.refine_1
n : Type u_1
inst✝² : Fintype n
inst✝¹ : DecidableEq n
S : Type u_2
inst✝ : LinearOrderedCommRing S
A : Matrix n n S
h1 : ∀ (i j : n), i ≠ j → A i j < 0
h✝ : Nonempty n
h2 : det A = 0
v : n → S
h_vnz : v ≠ 0
h_vA : vecMul v A = 0
this :
  ∀ {n : Type u_1} [inst : Fintype n] [inst_1 : DecidableEq n] {S : Type u_2} [inst_2 : LinearOrderedCommRing S]
    {A : Matrix n n S},
    (∀ (i j : n), i ≠ j → A i j < 0) →
      ∀ (h : Nonempty n),
        det A = 0 →
          ∀ (v : n → S),
            v ≠ 0 →
              vecMul v A = 0 → 0 < Finset.sup' Finset.univ (_ : Finset.Nonempty Finset.univ) v → ∃ j, ∑ i : n, A i j ≤ 0
h_sup : ¬0 < Finset.sup' Finset.univ (_ : Finset.Nonempty Finset.univ) v
⊢ -1 • v ≠ 0

Next tactic:
exact smul_ne_zero (by norm_num) h_vnz
/-- A matrix whose nondiagonal entries are negative with the sum of the entries of each
column positive has nonzero determinant. -/
lemma det_ne_zero_of_sum_col_pos [DecidableEq n] {S : Type*} [LinearOrderedCommRing S]
    {A : Matrix n n S} (h1 : ∀ i j, i ≠ j → A i j < 0) (h2 : ∀ j, 0 < ∑ i, A i j) :
    A.det ≠ 0 := by
  cases isEmpty_or_nonempty n
  · simp
  · contrapose! h2
    obtain ⟨v, ⟨h_vnz, h_vA⟩⟩ := Matrix.exists_vecMul_eq_zero_iff.mpr h2
    wlog h_sup : 0 < Finset.sup' Finset.univ Finset.univ_nonempty v
    · refine this h1 inferInstance h2 (-1 • v) ?_ ?_ ?_
      · exact smul_ne_zero (by 

Proof state:
n : Type u_1
inst✝² : Fintype n
inst✝¹ : DecidableEq n
S : Type u_2
inst✝ : LinearOrderedCommRing S
A : Matrix n n S
h1 : ∀ (i j : n), i ≠ j → A i j < 0
h✝ : Nonempty n
h2 : det A = 0
v : n → S
h_vnz : v ≠ 0
h_vA : vecMul v A = 0
this :
  ∀ {n : Type u_1} [inst : Fintype n] [inst_1 : DecidableEq n] {S : Type u_2} [inst_2 : LinearOrderedCommRing S]
    {A : Matrix n n S},
    (∀ (i j : n), i ≠ j → A i j < 0) →
      ∀ (h : Nonempty n),
        det A = 0 →
          ∀ (v : n → S),
            v ≠ 0 →
              vecMul v A = 0 → 0 < Finset.sup' Finset.univ (_ : Finset.Nonempty Finset.univ) v → ∃ j, ∑ i : n, A i j ≤ 0
h_sup : ¬0 < Finset.sup' Finset.univ (_ : Finset.Nonempty Finset.univ) v
⊢ -1 ≠ 0

Next tactic:
norm_num
/-- A matrix whose nondiagonal entries are negative with the sum of the entries of each
column positive has nonzero determinant. -/
lemma det_ne_zero_of_sum_col_pos [DecidableEq n] {S : Type*} [LinearOrderedCommRing S]
    {A : Matrix n n S} (h1 : ∀ i j, i ≠ j → A i j < 0) (h2 : ∀ j, 0 < ∑ i, A i j) :
    A.det ≠ 0 := by
  cases isEmpty_or_nonempty n
  · simp
  · contrapose! h2
    obtain ⟨v, ⟨h_vnz, h_vA⟩⟩ := Matrix.exists_vecMul_eq_zero_iff.mpr h2
    wlog h_sup : 0 < Finset.sup' Finset.univ Finset.univ_nonempty v
    · refine this h1 inferInstance h2 (-1 • v) ?_ ?_ ?_
      · exact smul_ne_zero (by norm_num) h_vnz
      · 

Proof state:
case inr.intro.intro.inr.refine_2
n : Type u_1
inst✝² : Fintype n
inst✝¹ : DecidableEq n
S : Type u_2
inst✝ : LinearOrderedCommRing S
A : Matrix n n S
h1 : ∀ (i j : n), i ≠ j → A i j < 0
h✝ : Nonempty n
h2 : det A = 0
v : n → S
h_vnz : v ≠ 0
h_vA : vecMul v A = 0
this :
  ∀ {n : Type u_1} [inst : Fintype n] [inst_1 : DecidableEq n] {S : Type u_2} [inst_2 : LinearOrderedCommRing S]
    {A : Matrix n n S},
    (∀ (i j : n), i ≠ j → A i j < 0) →
      ∀ (h : Nonempty n),
        det A = 0 →
          ∀ (v : n → S),
            v ≠ 0 →
              vecMul v A = 0 → 0 < Finset.sup' Finset.univ (_ : Finset.Nonempty Finset.univ) v → ∃ j, ∑ i : n, A i j ≤ 0
h_sup : ¬0 < Finset.sup' Finset.univ (_ : Finset.Nonempty Finset.univ) v
⊢ (vecMul (-1 • v) fun i j => A i j) = 0

Next tactic:
rw [Matrix.vecMul_smul, h_vA, smul_zero]
/-- A matrix whose nondiagonal entries are negative with the sum of the entries of each
column positive has nonzero determinant. -/
lemma det_ne_zero_of_sum_col_pos [DecidableEq n] {S : Type*} [LinearOrderedCommRing S]
    {A : Matrix n n S} (h1 : ∀ i j, i ≠ j → A i j < 0) (h2 : ∀ j, 0 < ∑ i, A i j) :
    A.det ≠ 0 := by
  cases isEmpty_or_nonempty n
  · simp
  · contrapose! h2
    obtain ⟨v, ⟨h_vnz, h_vA⟩⟩ := Matrix.exists_vecMul_eq_zero_iff.mpr h2
    wlog h_sup : 0 < Finset.sup' Finset.univ Finset.univ_nonempty v
    · refine this h1 inferInstance h2 (-1 • v) ?_ ?_ ?_
      · exact smul_ne_zero (by norm_num) h_vnz
      · rw [Matrix.vecMul_smul, h_vA, smul_zero]
      · 

Proof state:
case inr.intro.intro.inr.refine_3
n : Type u_1
inst✝² : Fintype n
inst✝¹ : DecidableEq n
S : Type u_2
inst✝ : LinearOrderedCommRing S
A : Matrix n n S
h1 : ∀ (i j : n), i ≠ j → A i j < 0
h✝ : Nonempty n
h2 : det A = 0
v : n → S
h_vnz : v ≠ 0
h_vA : vecMul v A = 0
this :
  ∀ {n : Type u_1} [inst : Fintype n] [inst_1 : DecidableEq n] {S : Type u_2} [inst_2 : LinearOrderedCommRing S]
    {A : Matrix n n S},
    (∀ (i j : n), i ≠ j → A i j < 0) →
      ∀ (h : Nonempty n),
        det A = 0 →
          ∀ (v : n → S),
            v ≠ 0 →
              vecMul v A = 0 → 0 < Finset.sup' Finset.univ (_ : Finset.Nonempty Finset.univ) v → ∃ j, ∑ i : n, A i j ≤ 0
h_sup : ¬0 < Finset.sup' Finset.univ (_ : Finset.Nonempty Finset.univ) v
⊢ 0 < Finset.sup' Finset.univ (_ : Finset.Nonempty Finset.univ) (-1 • v)

Next tactic:
obtain ⟨i, hi⟩ := Function.ne_iff.mp h_vnz
/-- A matrix whose nondiagonal entries are negative with the sum of the entries of each
column positive has nonzero determinant. -/
lemma det_ne_zero_of_sum_col_pos [DecidableEq n] {S : Type*} [LinearOrderedCommRing S]
    {A : Matrix n n S} (h1 : ∀ i j, i ≠ j → A i j < 0) (h2 : ∀ j, 0 < ∑ i, A i j) :
    A.det ≠ 0 := by
  cases isEmpty_or_nonempty n
  · simp
  · contrapose! h2
    obtain ⟨v, ⟨h_vnz, h_vA⟩⟩ := Matrix.exists_vecMul_eq_zero_iff.mpr h2
    wlog h_sup : 0 < Finset.sup' Finset.univ Finset.univ_nonempty v
    · refine this h1 inferInstance h2 (-1 • v) ?_ ?_ ?_
      · exact smul_ne_zero (by norm_num) h_vnz
      · rw [Matrix.vecMul_smul, h_vA, smul_zero]
      · obtain ⟨i, hi⟩ := Function.ne_iff.mp h_vnz
        

Proof state:
case inr.intro.intro.inr.refine_3.intro
n : Type u_1
inst✝² : Fintype n
inst✝¹ : DecidableEq n
S : Type u_2
inst✝ : LinearOrderedCommRing S
A : Matrix n n S
h1 : ∀ (i j : n), i ≠ j → A i j < 0
h✝ : Nonempty n
h2 : det A = 0
v : n → S
h_vnz : v ≠ 0
h_vA : vecMul v A = 0
this :
  ∀ {n : Type u_1} [inst : Fintype n] [inst_1 : DecidableEq n] {S : Type u_2} [inst_2 : LinearOrderedCommRing S]
    {A : Matrix n n S},
    (∀ (i j : n), i ≠ j → A i j < 0) →
      ∀ (h : Nonempty n),
        det A = 0 →
          ∀ (v : n → S),
            v ≠ 0 →
              vecMul v A = 0 → 0 < Finset.sup' Finset.univ (_ : Finset.Nonempty Finset.univ) v → ∃ j, ∑ i : n, A i j ≤ 0
h_sup : ¬0 < Finset.sup' Finset.univ (_ : Finset.Nonempty Finset.univ) v
i : n
hi : v i ≠ OfNat.ofNat 0 i
⊢ 0 < Finset.sup' Finset.univ (_ : Finset.Nonempty Finset.univ) (-1 • v)

Next tactic:
simp_rw [Finset.lt_sup'_iff, Finset.mem_univ, true_and] at h_sup ⊢
/-- A matrix whose nondiagonal entries are negative with the sum of the entries of each
column positive has nonzero determinant. -/
lemma det_ne_zero_of_sum_col_pos [DecidableEq n] {S : Type*} [LinearOrderedCommRing S]
    {A : Matrix n n S} (h1 : ∀ i j, i ≠ j → A i j < 0) (h2 : ∀ j, 0 < ∑ i, A i j) :
    A.det ≠ 0 := by
  cases isEmpty_or_nonempty n
  · simp
  · contrapose! h2
    obtain ⟨v, ⟨h_vnz, h_vA⟩⟩ := Matrix.exists_vecMul_eq_zero_iff.mpr h2
    wlog h_sup : 0 < Finset.sup' Finset.univ Finset.univ_nonempty v
    · refine this h1 inferInstance h2 (-1 • v) ?_ ?_ ?_
      · exact smul_ne_zero (by norm_num) h_vnz
      · rw [Matrix.vecMul_smul, h_vA, smul_zero]
      · obtain ⟨i, hi⟩ := Function.ne_iff.mp h_vnz
        simp_rw [Finset.lt_sup'_iff, Finset.mem_univ, true_and] at h_sup ⊢
        

Proof state:
case inr.intro.intro.inr.refine_3.intro
n : Type u_1
inst✝² : Fintype n
inst✝¹ : DecidableEq n
S : Type u_2
inst✝ : LinearOrderedCommRing S
A : Matrix n n S
h1 : ∀ (i j : n), i ≠ j → A i j < 0
h✝ : Nonempty n
h2 : det A = 0
v : n → S
h_vnz : v ≠ 0
h_vA : vecMul v A = 0
this :
  ∀ {n : Type u_1} [inst : Fintype n] [inst_1 : DecidableEq n] {S : Type u_2} [inst_2 : LinearOrderedCommRing S]
    {A : Matrix n n S},
    (∀ (i j : n), i ≠ j → A i j < 0) →
      ∀ (h : Nonempty n),
        det A = 0 →
          ∀ (v : n → S),
            v ≠ 0 →
              vecMul v A = 0 → 0 < Finset.sup' Finset.univ (_ : Finset.Nonempty Finset.univ) v → ∃ j, ∑ i : n, A i j ≤ 0
i : n
hi : v i ≠ OfNat.ofNat 0 i
h_sup : ¬∃ b, 0 < v b
⊢ ∃ b, 0 < (-1 • v) b

Next tactic:
simp_rw [not_exists, not_lt] at h_sup
/-- A matrix whose nondiagonal entries are negative with the sum of the entries of each
column positive has nonzero determinant. -/
lemma det_ne_zero_of_sum_col_pos [DecidableEq n] {S : Type*} [LinearOrderedCommRing S]
    {A : Matrix n n S} (h1 : ∀ i j, i ≠ j → A i j < 0) (h2 : ∀ j, 0 < ∑ i, A i j) :
    A.det ≠ 0 := by
  cases isEmpty_or_nonempty n
  · simp
  · contrapose! h2
    obtain ⟨v, ⟨h_vnz, h_vA⟩⟩ := Matrix.exists_vecMul_eq_zero_iff.mpr h2
    wlog h_sup : 0 < Finset.sup' Finset.univ Finset.univ_nonempty v
    · refine this h1 inferInstance h2 (-1 • v) ?_ ?_ ?_
      · exact smul_ne_zero (by norm_num) h_vnz
      · rw [Matrix.vecMul_smul, h_vA, smul_zero]
      · obtain ⟨i, hi⟩ := Function.ne_iff.mp h_vnz
        simp_rw [Finset.lt_sup'_iff, Finset.mem_univ, true_and] at h_sup ⊢
        simp_rw [not_exists, not_lt] at h_sup
        

Proof state:
case inr.intro.intro.inr.refine_3.intro
n : Type u_1
inst✝² : Fintype n
inst✝¹ : DecidableEq n
S : Type u_2
inst✝ : LinearOrderedCommRing S
A : Matrix n n S
h1 : ∀ (i j : n), i ≠ j → A i j < 0
h✝ : Nonempty n
h2 : det A = 0
v : n → S
h_vnz : v ≠ 0
h_vA : vecMul v A = 0
this :
  ∀ {n : Type u_1} [inst : Fintype n] [inst_1 : DecidableEq n] {S : Type u_2} [inst_2 : LinearOrderedCommRing S]
    {A : Matrix n n S},
    (∀ (i j : n), i ≠ j → A i j < 0) →
      ∀ (h : Nonempty n),
        det A = 0 →
          ∀ (v : n → S),
            v ≠ 0 →
              vecMul v A = 0 → 0 < Finset.sup' Finset.univ (_ : Finset.Nonempty Finset.univ) v → ∃ j, ∑ i : n, A i j ≤ 0
i : n
hi : v i ≠ OfNat.ofNat 0 i
h_sup : ∀ (x : n), v x ≤ 0
⊢ ∃ b, 0 < (-1 • v) b

Next tactic:
refine ⟨i, ?_⟩
/-- A matrix whose nondiagonal entries are negative with the sum of the entries of each
column positive has nonzero determinant. -/
lemma det_ne_zero_of_sum_col_pos [DecidableEq n] {S : Type*} [LinearOrderedCommRing S]
    {A : Matrix n n S} (h1 : ∀ i j, i ≠ j → A i j < 0) (h2 : ∀ j, 0 < ∑ i, A i j) :
    A.det ≠ 0 := by
  cases isEmpty_or_nonempty n
  · simp
  · contrapose! h2
    obtain ⟨v, ⟨h_vnz, h_vA⟩⟩ := Matrix.exists_vecMul_eq_zero_iff.mpr h2
    wlog h_sup : 0 < Finset.sup' Finset.univ Finset.univ_nonempty v
    · refine this h1 inferInstance h2 (-1 • v) ?_ ?_ ?_
      · exact smul_ne_zero (by norm_num) h_vnz
      · rw [Matrix.vecMul_smul, h_vA, smul_zero]
      · obtain ⟨i, hi⟩ := Function.ne_iff.mp h_vnz
        simp_rw [Finset.lt_sup'_iff, Finset.mem_univ, true_and] at h_sup ⊢
        simp_rw [not_exists, not_lt] at h_sup
        refine ⟨i, ?_⟩
        

Proof state:
case inr.intro.intro.inr.refine_3.intro
n : Type u_1
inst✝² : Fintype n
inst✝¹ : DecidableEq n
S : Type u_2
inst✝ : LinearOrderedCommRing S
A : Matrix n n S
h1 : ∀ (i j : n), i ≠ j → A i j < 0
h✝ : Nonempty n
h2 : det A = 0
v : n → S
h_vnz : v ≠ 0
h_vA : vecMul v A = 0
this :
  ∀ {n : Type u_1} [inst : Fintype n] [inst_1 : DecidableEq n] {S : Type u_2} [inst_2 : LinearOrderedCommRing S]
    {A : Matrix n n S},
    (∀ (i j : n), i ≠ j → A i j < 0) →
      ∀ (h : Nonempty n),
        det A = 0 →
          ∀ (v : n → S),
            v ≠ 0 →
              vecMul v A = 0 → 0 < Finset.sup' Finset.univ (_ : Finset.Nonempty Finset.univ) v → ∃ j, ∑ i : n, A i j ≤ 0
i : n
hi : v i ≠ OfNat.ofNat 0 i
h_sup : ∀ (x : n), v x ≤ 0
⊢ 0 < (-1 • v) i

Next tactic:
rw [Pi.smul_apply, neg_smul, one_smul, Left.neg_pos_iff]
/-- A matrix whose nondiagonal entries are negative with the sum of the entries of each
column positive has nonzero determinant. -/
lemma det_ne_zero_of_sum_col_pos [DecidableEq n] {S : Type*} [LinearOrderedCommRing S]
    {A : Matrix n n S} (h1 : ∀ i j, i ≠ j → A i j < 0) (h2 : ∀ j, 0 < ∑ i, A i j) :
    A.det ≠ 0 := by
  cases isEmpty_or_nonempty n
  · simp
  · contrapose! h2
    obtain ⟨v, ⟨h_vnz, h_vA⟩⟩ := Matrix.exists_vecMul_eq_zero_iff.mpr h2
    wlog h_sup : 0 < Finset.sup' Finset.univ Finset.univ_nonempty v
    · refine this h1 inferInstance h2 (-1 • v) ?_ ?_ ?_
      · exact smul_ne_zero (by norm_num) h_vnz
      · rw [Matrix.vecMul_smul, h_vA, smul_zero]
      · obtain ⟨i, hi⟩ := Function.ne_iff.mp h_vnz
        simp_rw [Finset.lt_sup'_iff, Finset.mem_univ, true_and] at h_sup ⊢
        simp_rw [not_exists, not_lt] at h_sup
        refine ⟨i, ?_⟩
        rw [Pi.smul_apply, neg_smul, one_smul, Left.neg_pos_iff]
        

Proof state:
case inr.intro.intro.inr.refine_3.intro
n : Type u_1
inst✝² : Fintype n
inst✝¹ : DecidableEq n
S : Type u_2
inst✝ : LinearOrderedCommRing S
A : Matrix n n S
h1 : ∀ (i j : n), i ≠ j → A i j < 0
h✝ : Nonempty n
h2 : det A = 0
v : n → S
h_vnz : v ≠ 0
h_vA : vecMul v A = 0
this :
  ∀ {n : Type u_1} [inst : Fintype n] [inst_1 : DecidableEq n] {S : Type u_2} [inst_2 : LinearOrderedCommRing S]
    {A : Matrix n n S},
    (∀ (i j : n), i ≠ j → A i j < 0) →
      ∀ (h : Nonempty n),
        det A = 0 →
          ∀ (v : n → S),
            v ≠ 0 →
              vecMul v A = 0 → 0 < Finset.sup' Finset.univ (_ : Finset.Nonempty Finset.univ) v → ∃ j, ∑ i : n, A i j ≤ 0
i : n
hi : v i ≠ OfNat.ofNat 0 i
h_sup : ∀ (x : n), v x ≤ 0
⊢ v i < 0

Next tactic:
refine Ne.lt_of_le hi (h_sup i)
/-- A matrix whose nondiagonal entries are negative with the sum of the entries of each
column positive has nonzero determinant. -/
lemma det_ne_zero_of_sum_col_pos [DecidableEq n] {S : Type*} [LinearOrderedCommRing S]
    {A : Matrix n n S} (h1 : ∀ i j, i ≠ j → A i j < 0) (h2 : ∀ j, 0 < ∑ i, A i j) :
    A.det ≠ 0 := by
  cases isEmpty_or_nonempty n
  · simp
  · contrapose! h2
    obtain ⟨v, ⟨h_vnz, h_vA⟩⟩ := Matrix.exists_vecMul_eq_zero_iff.mpr h2
    wlog h_sup : 0 < Finset.sup' Finset.univ Finset.univ_nonempty v
    · refine this h1 inferInstance h2 (-1 • v) ?_ ?_ ?_
      · exact smul_ne_zero (by norm_num) h_vnz
      · rw [Matrix.vecMul_smul, h_vA, smul_zero]
      · obtain ⟨i, hi⟩ := Function.ne_iff.mp h_vnz
        simp_rw [Finset.lt_sup'_iff, Finset.mem_univ, true_and] at h_sup ⊢
        simp_rw [not_exists, not_lt] at h_sup
        refine ⟨i, ?_⟩
        rw [Pi.smul_apply, neg_smul, one_smul, Left.neg_pos_iff]
        refine Ne.lt_of_le hi (h_sup i)
    · 

Proof state:
n✝ : Type u_1
inst✝³ : Fintype n✝
n : Type u_1
inst✝² : Fintype n
inst✝¹ : DecidableEq n
S : Type u_2
inst✝ : LinearOrderedCommRing S
A : Matrix n n S
h1 : ∀ (i j : n), i ≠ j → A i j < 0
h✝ : Nonempty n
h2 : det A = 0
v : n → S
h_vnz : v ≠ 0
h_vA : vecMul v A = 0
h_sup : 0 < Finset.sup' Finset.univ (_ : Finset.Nonempty Finset.univ) v
⊢ ∃ j, ∑ i : n, A i j ≤ 0

Next tactic:
obtain ⟨j₀, -, h_j₀⟩ := Finset.exists_mem_eq_sup' Finset.univ_nonempty v
/-- A matrix whose nondiagonal entries are negative with the sum of the entries of each
column positive has nonzero determinant. -/
lemma det_ne_zero_of_sum_col_pos [DecidableEq n] {S : Type*} [LinearOrderedCommRing S]
    {A : Matrix n n S} (h1 : ∀ i j, i ≠ j → A i j < 0) (h2 : ∀ j, 0 < ∑ i, A i j) :
    A.det ≠ 0 := by
  cases isEmpty_or_nonempty n
  · simp
  · contrapose! h2
    obtain ⟨v, ⟨h_vnz, h_vA⟩⟩ := Matrix.exists_vecMul_eq_zero_iff.mpr h2
    wlog h_sup : 0 < Finset.sup' Finset.univ Finset.univ_nonempty v
    · refine this h1 inferInstance h2 (-1 • v) ?_ ?_ ?_
      · exact smul_ne_zero (by norm_num) h_vnz
      · rw [Matrix.vecMul_smul, h_vA, smul_zero]
      · obtain ⟨i, hi⟩ := Function.ne_iff.mp h_vnz
        simp_rw [Finset.lt_sup'_iff, Finset.mem_univ, true_and] at h_sup ⊢
        simp_rw [not_exists, not_lt] at h_sup
        refine ⟨i, ?_⟩
        rw [Pi.smul_apply, neg_smul, one_smul, Left.neg_pos_iff]
        refine Ne.lt_of_le hi (h_sup i)
    · obtain ⟨j₀, -, h_j₀⟩ := Finset.exists_mem_eq_sup' Finset.univ_nonempty v
      

Proof state:
case intro.intro
n✝ : Type u_1
inst✝³ : Fintype n✝
n : Type u_1
inst✝² : Fintype n
inst✝¹ : DecidableEq n
S : Type u_2
inst✝ : LinearOrderedCommRing S
A : Matrix n n S
h1 : ∀ (i j : n), i ≠ j → A i j < 0
h✝ : Nonempty n
h2 : det A = 0
v : n → S
h_vnz : v ≠ 0
h_vA : vecMul v A = 0
h_sup : 0 < Finset.sup' Finset.univ (_ : Finset.Nonempty Finset.univ) v
j₀ : n
h_j₀ : Finset.sup' Finset.univ (_ : Finset.Nonempty Finset.univ) v = v j₀
⊢ ∃ j, ∑ i : n, A i j ≤ 0

Next tactic:
refine ⟨j₀, ?_⟩
/-- A matrix whose nondiagonal entries are negative with the sum of the entries of each
column positive has nonzero determinant. -/
lemma det_ne_zero_of_sum_col_pos [DecidableEq n] {S : Type*} [LinearOrderedCommRing S]
    {A : Matrix n n S} (h1 : ∀ i j, i ≠ j → A i j < 0) (h2 : ∀ j, 0 < ∑ i, A i j) :
    A.det ≠ 0 := by
  cases isEmpty_or_nonempty n
  · simp
  · contrapose! h2
    obtain ⟨v, ⟨h_vnz, h_vA⟩⟩ := Matrix.exists_vecMul_eq_zero_iff.mpr h2
    wlog h_sup : 0 < Finset.sup' Finset.univ Finset.univ_nonempty v
    · refine this h1 inferInstance h2 (-1 • v) ?_ ?_ ?_
      · exact smul_ne_zero (by norm_num) h_vnz
      · rw [Matrix.vecMul_smul, h_vA, smul_zero]
      · obtain ⟨i, hi⟩ := Function.ne_iff.mp h_vnz
        simp_rw [Finset.lt_sup'_iff, Finset.mem_univ, true_and] at h_sup ⊢
        simp_rw [not_exists, not_lt] at h_sup
        refine ⟨i, ?_⟩
        rw [Pi.smul_apply, neg_smul, one_smul, Left.neg_pos_iff]
        refine Ne.lt_of_le hi (h_sup i)
    · obtain ⟨j₀, -, h_j₀⟩ := Finset.exists_mem_eq_sup' Finset.univ_nonempty v
      refine ⟨j₀, ?_⟩
      

Proof state:
case intro.intro
n✝ : Type u_1
inst✝³ : Fintype n✝
n : Type u_1
inst✝² : Fintype n
inst✝¹ : DecidableEq n
S : Type u_2
inst✝ : LinearOrderedCommRing S
A : Matrix n n S
h1 : ∀ (i j : n), i ≠ j → A i j < 0
h✝ : Nonempty n
h2 : det A = 0
v : n → S
h_vnz : v ≠ 0
h_vA : vecMul v A = 0
h_sup : 0 < Finset.sup' Finset.univ (_ : Finset.Nonempty Finset.univ) v
j₀ : n
h_j₀ : Finset.sup' Finset.univ (_ : Finset.Nonempty Finset.univ) v = v j₀
⊢ ∑ i : n, A i j₀ ≤ 0

Next tactic:
rw [← mul_le_mul_left (h_j₀ ▸ h_sup), Finset.mul_sum, mul_zero]