l3lab/ntp-mathlib huggingface dataset:
theorem lt_rank_of_lt_finrank {n : ℕ} (h : n < finrank K V) : ↑n < Module.rank K V := by
  rwa [← Cardinal.toNat_lt_iff_lt_of_lt_aleph0, toNat_cast]
  · exact nat_lt_aleph0 n
  · contrapose! h
    

Proof state:
case hd
K : Type u
V : Type v
inst✝⁴ : Ring K
inst✝³ : AddCommGroup V
inst✝² : Module K V
V₂ : Type v'
inst✝¹ : AddCommGroup V₂
inst✝ : Module K V₂
n : ℕ
h : ℵ₀ ≤ Module.rank K V
⊢ finrank K V ≤ n

Next tactic:
rw [finrank, Cardinal.toNat_apply_of_aleph0_le h]
theorem lt_rank_of_lt_finrank {n : ℕ} (h : n < finrank K V) : ↑n < Module.rank K V := by
  rwa [← Cardinal.toNat_lt_iff_lt_of_lt_aleph0, toNat_cast]
  · exact nat_lt_aleph0 n
  · contrapose! h
    rw [finrank, Cardinal.toNat_apply_of_aleph0_le h]
    

Proof state:
case hd
K : Type u
V : Type v
inst✝⁴ : Ring K
inst✝³ : AddCommGroup V
inst✝² : Module K V
V₂ : Type v'
inst✝¹ : AddCommGroup V₂
inst✝ : Module K V₂
n : ℕ
h : ℵ₀ ≤ Module.rank K V
⊢ 0 ≤ n

Next tactic:
exact n.zero_le
theorem one_lt_rank_of_one_lt_finrank (h : 1 < finrank K V) : 1 < Module.rank K V := by
  

Proof state:
K : Type u
V : Type v
inst✝⁴ : Ring K
inst✝³ : AddCommGroup V
inst✝² : Module K V
V₂ : Type v'
inst✝¹ : AddCommGroup V₂
inst✝ : Module K V₂
h : 1 < finrank K V
⊢ 1 < Module.rank K V

Next tactic:
simpa using lt_rank_of_lt_finrank h
theorem finrank_le_finrank_of_rank_le_rank
    (h : lift.{v'} (Module.rank K V) ≤ Cardinal.lift.{v} (Module.rank K V₂))
    (h' : Module.rank K V₂ < ℵ₀) : finrank K V ≤ finrank K V₂ := by
  

Proof state:
K : Type u
V : Type v
inst✝⁴ : Ring K
inst✝³ : AddCommGroup V
inst✝² : Module K V
V₂ : Type v'
inst✝¹ : AddCommGroup V₂
inst✝ : Module K V₂
h : lift.{v', v} (Module.rank K V) ≤ lift.{v, v'} (Module.rank K V₂)
h' : Module.rank K V₂ < ℵ₀
⊢ finrank K V ≤ finrank K V₂

Next tactic:
simpa only [toNat_lift] using toNat_le_of_le_of_lt_aleph0 (lift_lt_aleph0.mpr h') h
/-- A finite dimensional space is nontrivial if it has `finrank` equal to the successor of a
natural number. -/
theorem nontrivial_of_finrank_eq_succ {n : ℕ} (hn : finrank K V = n.succ) : Nontrivial V :=
  nontrivial_of_finrank_pos (by 

Proof state:
K : Type u
V : Type v
inst✝⁶ : Ring K
inst✝⁵ : AddCommGroup V
inst✝⁴ : Module K V
V₂ : Type v'
inst✝³ : AddCommGroup V₂
inst✝² : Module K V₂
inst✝¹ : Nontrivial K
inst✝ : NoZeroSMulDivisors K V
n : ℕ
hn : finrank K V = Nat.succ n
⊢ 0 < finrank (?m.110345 hn) V

Next tactic:
rw [hn]
/-- A finite dimensional space is nontrivial if it has `finrank` equal to the successor of a
natural number. -/
theorem nontrivial_of_finrank_eq_succ {n : ℕ} (hn : finrank K V = n.succ) : Nontrivial V :=
  nontrivial_of_finrank_pos (by rw [hn]; 

Proof state:
K : Type u
V : Type v
inst✝⁶ : Ring K
inst✝⁵ : AddCommGroup V
inst✝⁴ : Module K V
V₂ : Type v'
inst✝³ : AddCommGroup V₂
inst✝² : Module K V₂
inst✝¹ : Nontrivial K
inst✝ : NoZeroSMulDivisors K V
n : ℕ
hn : finrank K V = Nat.succ n
⊢ 0 < Nat.succ n

Next tactic:
exact n.succ_pos
/-- A (finite dimensional) space that is a subsingleton has zero `finrank`. -/
@[nontriviality]
theorem finrank_zero_of_subsingleton [h : Subsingleton V] : finrank K V = 0 := by
  

Proof state:
K : Type u
V : Type v
inst✝⁶ : Ring K
inst✝⁵ : AddCommGroup V
inst✝⁴ : Module K V
V₂ : Type v'
inst✝³ : AddCommGroup V₂
inst✝² : Module K V₂
inst✝¹ : Nontrivial K
inst✝ : NoZeroSMulDivisors K V
h : Subsingleton V
⊢ finrank K V = 0

Next tactic:
by_contra h0
/-- A (finite dimensional) space that is a subsingleton has zero `finrank`. -/
@[nontriviality]
theorem finrank_zero_of_subsingleton [h : Subsingleton V] : finrank K V = 0 := by
  by_contra h0
  

Proof state:
K : Type u
V : Type v
inst✝⁶ : Ring K
inst✝⁵ : AddCommGroup V
inst✝⁴ : Module K V
V₂ : Type v'
inst✝³ : AddCommGroup V₂
inst✝² : Module K V₂
inst✝¹ : Nontrivial K
inst✝ : NoZeroSMulDivisors K V
h : Subsingleton V
h0 : ¬finrank K V = 0
⊢ False

Next tactic:
obtain ⟨x, y, hxy⟩ := nontrivial_of_finrank_pos (Nat.pos_of_ne_zero h0)
/-- A (finite dimensional) space that is a subsingleton has zero `finrank`. -/
@[nontriviality]
theorem finrank_zero_of_subsingleton [h : Subsingleton V] : finrank K V = 0 := by
  by_contra h0
  obtain ⟨x, y, hxy⟩ := nontrivial_of_finrank_pos (Nat.pos_of_ne_zero h0)
  

Proof state:
case mk.intro.intro
K : Type u
V : Type v
inst✝⁶ : Ring K
inst✝⁵ : AddCommGroup V
inst✝⁴ : Module K V
V₂ : Type v'
inst✝³ : AddCommGroup V₂
inst✝² : Module K V₂
inst✝¹ : Nontrivial K
inst✝ : NoZeroSMulDivisors K V
h : Subsingleton V
h0 : ¬finrank K V = 0
x y : V
hxy : x ≠ y
⊢ False

Next tactic:
exact hxy (Subsingleton.elim _ _)
/-- If a vector space (or module) has a finite basis, then its dimension (or rank) is equal to the
cardinality of the basis. This lemma uses a `Finset` instead of indexed types. -/
theorem finrank_eq_card_finset_basis {ι : Type w} {b : Finset ι} (h : Basis b K V) :
    finrank K V = Finset.card b := by 

Proof state:
K : Type u
V : Type v
inst✝⁵ : Ring K
inst✝⁴ : AddCommGroup V
inst✝³ : Module K V
V₂ : Type v'
inst✝² : AddCommGroup V₂
inst✝¹ : Module K V₂
inst✝ : StrongRankCondition K
ι : Type w
b : Finset ι
h : Basis { x // x ∈ b } K V
⊢ finrank K V = Finset.card b

Next tactic:
rw [finrank_eq_card_basis h, Fintype.card_coe]
/-- A ring satisfying `StrongRankCondition` (such as a `DivisionRing`) is one-dimensional as a
module over itself. -/
@[simp]
theorem finrank_self : finrank K K = 1 :=
  finrank_eq_of_rank_eq (by 

Proof state:
K : Type u
V : Type v
inst✝⁵ : Ring K
inst✝⁴ : AddCommGroup V
inst✝³ : Module K V
V₂ : Type v'
inst✝² : AddCommGroup V₂
inst✝¹ : Module K V₂
inst✝ : StrongRankCondition K
⊢ Module.rank K K = ↑1

Next tactic:
simp
/-- The vector space of functions on `Fin n` has finrank equal to `n`. -/
-- @[simp] -- Porting note: simp already proves this
theorem finrank_fin_fun {n : ℕ} : finrank K (Fin n → K) = n := by 

Proof state:
K : Type u
V : Type v
inst✝⁵ : Ring K
inst✝⁴ : AddCommGroup V
inst✝³ : Module K V
V₂ : Type v'
inst✝² : AddCommGroup V₂
inst✝¹ : Module K V₂
inst✝ : StrongRankCondition K
n : ℕ
⊢ finrank K (Fin n → K) = n

Next tactic:
simp
theorem finrank_eq_zero_of_basis_imp_not_finite
    (h : ∀ s : Set V, Basis.{v} (s : Set V) K V → ¬s.Finite) : finrank K V = 0 := by
  

Proof state:
K : Type u
V : Type v
inst✝⁴ : Ring K
inst✝³ : StrongRankCondition K
inst✝² : AddCommGroup V
inst✝¹ : Module K V
inst✝ : Free K V
h : ∀ (s : Set V), Basis (↑s) K V → ¬Set.Finite s
⊢ finrank K V = 0

Next tactic:
obtain ⟨_, ⟨b⟩⟩ := (Module.free_iff_set K V).mp ‹_›
theorem finrank_eq_zero_of_basis_imp_not_finite
    (h : ∀ s : Set V, Basis.{v} (s : Set V) K V → ¬s.Finite) : finrank K V = 0 := by
  obtain ⟨_, ⟨b⟩⟩ := (Module.free_iff_set K V).mp ‹_›
  

Proof state:
case intro.intro
K : Type u
V : Type v
inst✝⁴ : Ring K
inst✝³ : StrongRankCondition K
inst✝² : AddCommGroup V
inst✝¹ : Module K V
inst✝ : Free K V
h : ∀ (s : Set V), Basis (↑s) K V → ¬Set.Finite s
w✝ : Set V
b : Basis (↑w✝) K V
⊢ finrank K V = 0

Next tactic:
exact dif_neg fun rank_lt => h _ b (b.finite_index_of_rank_lt_aleph0 rank_lt)
theorem finrank_eq_zero_of_basis_imp_false (h : ∀ s : Finset V, Basis.{v} (s : Set V) K V → False) :
    finrank K V = 0 :=
  finrank_eq_zero_of_basis_imp_not_finite fun s b hs =>
    h hs.toFinset
      (by
        

Proof state:
K : Type u
V : Type v
inst✝⁴ : Ring K
inst✝³ : StrongRankCondition K
inst✝² : AddCommGroup V
inst✝¹ : Module K V
inst✝ : Free K V
h : ∀ (s : Finset V), Basis (↑↑s) K V → False
s : Set V
b : Basis (↑s) K V
hs : Set.Finite s
⊢ Basis (↑↑(Set.Finite.toFinset hs)) K V

Next tactic:
convert b
theorem finrank_eq_zero_of_basis_imp_false (h : ∀ s : Finset V, Basis.{v} (s : Set V) K V → False) :
    finrank K V = 0 :=
  finrank_eq_zero_of_basis_imp_not_finite fun s b hs =>
    h hs.toFinset
      (by
        convert b
        

Proof state:
case h.e'_1.h.e'_2
K : Type u
V : Type v
inst✝⁴ : Ring K
inst✝³ : StrongRankCondition K
inst✝² : AddCommGroup V
inst✝¹ : Module K V
inst✝ : Free K V
h : ∀ (s : Finset V), Basis (↑↑s) K V → False
s : Set V
b : Basis (↑s) K V
hs : Set.Finite s
⊢ ↑(Set.Finite.toFinset hs) = s

Next tactic:
simp
/-- The dimension of a finite dimensional space is preserved under linear equivalence. -/
theorem finrank_eq (f : M ≃ₗ[R] M₂) : finrank R M = finrank R M₂ := by
  

Proof state:
K : Type u
V : Type v
inst✝⁹ : Ring K
inst✝⁸ : AddCommGroup V
inst✝⁷ : Module K V
V₂ : Type v'
inst✝⁶ : AddCommGroup V₂
inst✝⁵ : Module K V₂
R : Type u_1
M : Type u_2
M₂ : Type u_3
inst✝⁴ : Ring R
inst✝³ : AddCommGroup M
inst✝² : AddCommGroup M₂
inst✝¹ : Module R M
inst✝ : Module R M₂
f : M ≃ₗ[R] M₂
⊢ finrank R M = finrank R M₂

Next tactic:
unfold finrank
/-- The dimension of a finite dimensional space is preserved under linear equivalence. -/
theorem finrank_eq (f : M ≃ₗ[R] M₂) : finrank R M = finrank R M₂ := by
  unfold finrank
  

Proof state:
K : Type u
V : Type v
inst✝⁹ : Ring K
inst✝⁸ : AddCommGroup V
inst✝⁷ : Module K V
V₂ : Type v'
inst✝⁶ : AddCommGroup V₂
inst✝⁵ : Module K V₂
R : Type u_1
M : Type u_2
M₂ : Type u_3
inst✝⁴ : Ring R
inst✝³ : AddCommGroup M
inst✝² : AddCommGroup M₂
inst✝¹ : Module R M
inst✝ : Module R M₂
f : M ≃ₗ[R] M₂
⊢ toNat (Module.rank R M) = toNat (Module.rank R M₂)

Next tactic:
rw [← Cardinal.toNat_lift, f.lift_rank_eq, Cardinal.toNat_lift]
/-- The dimensions of the domain and range of an injective linear map are equal. -/
theorem finrank_range_of_inj {f : V →ₗ[K] V₂} (hf : Function.Injective f) :
    finrank K (LinearMap.range f) = finrank K V := by 

Proof state:
K : Type u
V : Type v
inst✝⁴ : Ring K
inst✝³ : AddCommGroup V
inst✝² : Module K V
V₂ : Type v'
inst✝¹ : AddCommGroup V₂
inst✝ : Module K V₂
f : V →ₗ[K] V₂
hf : Injective ⇑f
⊢ finrank K ↥(range f) = finrank K V

Next tactic:
rw [(LinearEquiv.ofInjective f hf).finrank_eq]
@[simp]
theorem finrank_top : finrank K (⊤ : Submodule K V) = finrank K V := by
  

Proof state:
K : Type u
V : Type v
inst✝² : Ring K
inst✝¹ : AddCommGroup V
inst✝ : Module K V
⊢ finrank K ↥⊤ = finrank K V

Next tactic:
unfold finrank
@[simp]
theorem finrank_top : finrank K (⊤ : Submodule K V) = finrank K V := by
  unfold finrank
  

Proof state:
K : Type u
V : Type v
inst✝² : Ring K
inst✝¹ : AddCommGroup V
inst✝ : Module K V
⊢ toNat (Module.rank K ↥⊤) = toNat (Module.rank K V)

Next tactic:
simp [rank_top]
theorem lt_of_le_of_finrank_lt_finrank {s t : Submodule K V} (le : s ≤ t)
    (lt : finrank K s < finrank K t) : s < t :=
  lt_of_le_of_ne le fun h => ne_of_lt lt (by 

Proof state:
K : Type u
V : Type v
inst✝⁴ : Ring K
inst✝³ : AddCommGroup V
inst✝² : Module K V
V₂ : Type v'
inst✝¹ : AddCommGroup V₂
inst✝ : Module K V₂
s t : Submodule K V
le : s ≤ t
lt : finrank K ↥s < finrank K ↥t
h : s = t
⊢ finrank K ↥s = finrank K ↥t

Next tactic:
rw [h]
theorem lt_top_of_finrank_lt_finrank {s : Submodule K V} (lt : finrank K s < finrank K V) :
    s < ⊤ := by
  

Proof state:
K : Type u
V : Type v
inst✝⁴ : Ring K
inst✝³ : AddCommGroup V
inst✝² : Module K V
V₂ : Type v'
inst✝¹ : AddCommGroup V₂
inst✝ : Module K V₂
s : Submodule K V
lt : finrank K ↥s < finrank K V
⊢ s < ⊤

Next tactic:
rw [← finrank_top K V] at lt
theorem lt_top_of_finrank_lt_finrank {s : Submodule K V} (lt : finrank K s < finrank K V) :
    s < ⊤ := by
  rw [← finrank_top K V] at lt
  

Proof state:
K : Type u
V : Type v
inst✝⁴ : Ring K
inst✝³ : AddCommGroup V
inst✝² : Module K V
V₂ : Type v'
inst✝¹ : AddCommGroup V₂
inst✝ : Module K V₂
s : Submodule K V
lt : finrank K ↥s < finrank K ↥⊤
⊢ s < ⊤

Next tactic:
exact lt_of_le_of_finrank_lt_finrank le_top lt
theorem finrank_span_le_card (s : Set V) [Fintype s] : finrank K (span K s) ≤ s.toFinset.card :=
  finrank_le_of_rank_le (by 

Proof state:
K : Type u
V : Type v
inst✝³ : DivisionRing K
inst✝² : AddCommGroup V
inst✝¹ : Module K V
s : Set V
inst✝ : Fintype ↑s
⊢ Module.rank K ↥(span K s) ≤ ↑(Finset.card (Set.toFinset s))

Next tactic:
simpa using rank_span_le (K := K) s
theorem finrank_span_finset_le_card (s : Finset V) : (s : Set V).finrank K ≤ s.card :=
  calc
    (s : Set V).finrank K ≤ (s : Set V).toFinset.card := finrank_span_le_card (V := V) s
    _ = s.card := by 

Proof state:
K : Type u
V : Type v
inst✝² : DivisionRing K
inst✝¹ : AddCommGroup V
inst✝ : Module K V
s : Finset V
⊢ Finset.card (Set.toFinset ↑s) = Finset.card s

Next tactic:
simp
theorem finrank_range_le_card {ι : Type*} [Fintype ι] {b : ι → V} :
    (Set.range b).finrank K ≤ Fintype.card ι := by
  

Proof state:
K : Type u
V : Type v
inst✝³ : DivisionRing K
inst✝² : AddCommGroup V
inst✝¹ : Module K V
ι : Type u_1
inst✝ : Fintype ι
b : ι → V
⊢ Set.finrank K (Set.range b) ≤ Fintype.card ι

Next tactic:
classical
  refine (finrank_span_le_card _).trans ?_
  rw [Set.toFinset_range]
  exact Finset.card_image_le
theorem finrank_range_le_card {ι : Type*} [Fintype ι] {b : ι → V} :
    (Set.range b).finrank K ≤ Fintype.card ι := by
  classical
  

Proof state:
K : Type u
V : Type v
inst✝³ : DivisionRing K
inst✝² : AddCommGroup V
inst✝¹ : Module K V
ι : Type u_1
inst✝ : Fintype ι
b : ι → V
⊢ Set.finrank K (Set.range b) ≤ Fintype.card ι

Next tactic:
refine (finrank_span_le_card _).trans ?_
theorem finrank_range_le_card {ι : Type*} [Fintype ι] {b : ι → V} :
    (Set.range b).finrank K ≤ Fintype.card ι := by
  classical
  refine (finrank_span_le_card _).trans ?_
  

Proof state:
K : Type u
V : Type v
inst✝³ : DivisionRing K
inst✝² : AddCommGroup V
inst✝¹ : Module K V
ι : Type u_1
inst✝ : Fintype ι
b : ι → V
⊢ Finset.card (Set.toFinset (Set.range b)) ≤ Fintype.card ι

Next tactic:
rw [Set.toFinset_range]
theorem finrank_range_le_card {ι : Type*} [Fintype ι] {b : ι → V} :
    (Set.range b).finrank K ≤ Fintype.card ι := by
  classical
  refine (finrank_span_le_card _).trans ?_
  rw [Set.toFinset_range]
  

Proof state:
K : Type u
V : Type v
inst✝³ : DivisionRing K
inst✝² : AddCommGroup V
inst✝¹ : Module K V
ι : Type u_1
inst✝ : Fintype ι
b : ι → V
⊢ Finset.card (Finset.image b Finset.univ) ≤ Fintype.card ι

Next tactic:
exact Finset.card_image_le
theorem finrank_span_eq_card {ι : Type*} [Fintype ι] {b : ι → V} (hb : LinearIndependent K b) :
    finrank K (span K (Set.range b)) = Fintype.card ι :=
  finrank_eq_of_rank_eq
    (by
      

Proof state:
K : Type u
V : Type v
inst✝³ : DivisionRing K
inst✝² : AddCommGroup V
inst✝¹ : Module K V
ι : Type u_1
inst✝ : Fintype ι
b : ι → V
hb : LinearIndependent K b
⊢ Module.rank K ↥(span K (Set.range b)) = ↑(Fintype.card ι)

Next tactic:
have : Module.rank K (span K (Set.range b)) = #(Set.range b) := rank_span hb
theorem finrank_span_eq_card {ι : Type*} [Fintype ι] {b : ι → V} (hb : LinearIndependent K b) :
    finrank K (span K (Set.range b)) = Fintype.card ι :=
  finrank_eq_of_rank_eq
    (by
      have : Module.rank K (span K (Set.range b)) = #(Set.range b) := rank_span hb
      

Proof state:
K : Type u
V : Type v
inst✝³ : DivisionRing K
inst✝² : AddCommGroup V
inst✝¹ : Module K V
ι : Type u_1
inst✝ : Fintype ι
b : ι → V
hb : LinearIndependent K b
this : Module.rank K ↥(span K (Set.range b)) = #↑(Set.range b)
⊢ Module.rank K ↥(span K (Set.range b)) = ↑(Fintype.card ι)

Next tactic:
rwa [← lift_inj, mk_range_eq_of_injective hb.injective, Cardinal.mk_fintype, lift_natCast,
        lift_eq_nat_iff] at this
theorem finrank_span_set_eq_card (s : Set V) [Fintype s] (hs : LinearIndependent K ((↑) : s → V)) :
    finrank K (span K s) = s.toFinset.card :=
  finrank_eq_of_rank_eq
    (by
      

Proof state:
K : Type u
V : Type v
inst✝³ : DivisionRing K
inst✝² : AddCommGroup V
inst✝¹ : Module K V
s : Set V
inst✝ : Fintype ↑s
hs : LinearIndependent (ι := { x // x ∈ s }) K Subtype.val
⊢ Module.rank K ↥(span K s) = ↑(Finset.card (Set.toFinset s))

Next tactic:
have : Module.rank K (span K s) = #s := rank_span_set hs
theorem finrank_span_set_eq_card (s : Set V) [Fintype s] (hs : LinearIndependent K ((↑) : s → V)) :
    finrank K (span K s) = s.toFinset.card :=
  finrank_eq_of_rank_eq
    (by
      have : Module.rank K (span K s) = #s := rank_span_set hs
      

Proof state:
K : Type u
V : Type v
inst✝³ : DivisionRing K
inst✝² : AddCommGroup V
inst✝¹ : Module K V
s : Set V
inst✝ : Fintype ↑s
hs : LinearIndependent (ι := { x // x ∈ s }) K Subtype.val
this : Module.rank K ↥(span K s) = #↑s
⊢ Module.rank K ↥(span K s) = ↑(Finset.card (Set.toFinset s))

Next tactic:
rwa [Cardinal.mk_fintype, ← Set.toFinset_card] at this
theorem finrank_span_finset_eq_card (s : Finset V) (hs : LinearIndependent K ((↑) : s → V)) :
    finrank K (span K (s : Set V)) = s.card := by
  

Proof state:
K : Type u
V : Type v
inst✝² : DivisionRing K
inst✝¹ : AddCommGroup V
inst✝ : Module K V
s : Finset V
hs : LinearIndependent K Subtype.val
⊢ finrank K ↥(span K ↑s) = Finset.card s

Next tactic:
convert finrank_span_set_eq_card (s : Set V) hs
theorem finrank_span_finset_eq_card (s : Finset V) (hs : LinearIndependent K ((↑) : s → V)) :
    finrank K (span K (s : Set V)) = s.card := by
  convert finrank_span_set_eq_card (s : Set V) hs
  

Proof state:
case h.e'_3.h.e'_2
K : Type u
V : Type v
inst✝² : DivisionRing K
inst✝¹ : AddCommGroup V
inst✝ : Module K V
s : Finset V
hs : LinearIndependent K Subtype.val
⊢ s = Set.toFinset ↑s

Next tactic:
ext
theorem finrank_span_finset_eq_card (s : Finset V) (hs : LinearIndependent K ((↑) : s → V)) :
    finrank K (span K (s : Set V)) = s.card := by
  convert finrank_span_set_eq_card (s : Set V) hs
  ext
  

Proof state:
case h.e'_3.h.e'_2.a
K : Type u
V : Type v
inst✝² : DivisionRing K
inst✝¹ : AddCommGroup V
inst✝ : Module K V
s : Finset V
hs : LinearIndependent K Subtype.val
a✝ : V
⊢ a✝ ∈ s ↔ a✝ ∈ Set.toFinset ↑s

Next tactic:
simp
theorem linearIndependent_of_top_le_span_of_card_eq_finrank {ι : Type*} [Fintype ι] {b : ι → V}
    (spans : ⊤ ≤ span K (Set.range b)) (card_eq : Fintype.card ι = finrank K V) :
    LinearIndependent K b :=
  linearIndependent_iff'.mpr fun s g dependent i i_mem_s => by
    

Proof state:
K : Type u
V : Type v
inst✝³ : DivisionRing K
inst✝² : AddCommGroup V
inst✝¹ : Module K V
ι : Type u_1
inst✝ : Fintype ι
b : ι → V
spans : ⊤ ≤ span K (Set.range b)
card_eq : Fintype.card ι = finrank K V
s : Finset ι
g : ι → K
dependent : (Finset.sum s fun i => g i • b i) = 0
i : ι
i_mem_s : i ∈ s
⊢ g i = 0

Next tactic:
classical
    by_contra gx_ne_zero
    -- We'll derive a contradiction by showing `b '' (univ \ {i})` of cardinality `n - 1`
    -- spans a vector space of dimension `n`.
    refine' not_le_of_gt (span_lt_top_of_card_lt_finrank
      (show (b '' (Set.univ \ {i})).toFinset.card < finrank K V from _)) _
    · calc
        (b '' (Set.univ \ {i})).toFinset.card = ((Set.univ \ {i}).toFinset.image b).card := by
          rw [Set.toFinset_card, Fintype.card_ofFinset]
        _ ≤ (Set.univ \ {i}).toFinset.card := Finset.card_image_le
        _ = (Finset.univ.erase i).card := (congr_arg Finset.card (Finset.ext (by simp [and_comm])))
        _ < Finset.univ.card := (Finset.card_erase_lt_of_mem (Finset.mem_univ i))
        _ = finrank K V := card_eq
    -- We already have that `b '' univ` spans the whole space,
    -- so we only need to show that the span of `b '' (univ \ {i})` contains each `b j`.
    refine' spans.trans (span_le.mpr _)
    rintro _ ⟨j, rfl, rfl⟩
    -- The case that `j ≠ i` is easy because `b j ∈ b '' (univ \ {i})`.
    by_cases j_eq : j = i
    swap
    · refine' subset_span ⟨j, (Set.mem_diff _).mpr ⟨Set.mem_univ _, _⟩, rfl⟩
      exact mt Set.mem_singleton_iff.mp j_eq
    -- To show `b i ∈ span (b '' (univ \ {i}))`, we use that it's a weighted sum
    -- of the other `b j`s.
    rw [j_eq, SetLike.mem_coe, show b i = -((g i)⁻¹ • (s.erase i).sum fun j => g j • b j) from _]
    · refine' neg_mem (smul_mem _ _ (sum_mem fun k hk => _))
      obtain ⟨k_ne_i, _⟩ := Finset.mem_erase.mp hk
      refine' smul_mem _ _ (subset_span ⟨k, _, rfl⟩)
      simp_all only [Set.mem_univ, Set.mem_diff, Set.mem_singleton_iff, and_self, not_false_eq_true]
    -- To show `b i` is a weighted sum of the other `b j`s, we'll rewrite this sum
    -- to have the form of the assumption `dependent`.
    apply eq_neg_of_add_eq_zero_left
    calc
      (b i + (g i)⁻¹ • (s.erase i).sum fun j => g j • b j) =
          (g i)⁻¹ • (g i • b i + (s.erase i).sum fun j => g j • b j) :=
        by rw [smul_add, ← mul_smul, inv_mul_cancel gx_ne_zero, one_smul]
      _ = (g i)⁻¹ • (0 : V) := (congr_arg _ ?_)
      _ = 0 := smul_zero _
    -- And then it's just a bit of manipulation with finite sums.
    rwa [← Finset.insert_erase i_mem_s, Finset.sum_insert (Finset.not_mem_erase _ _)] at dependent
theorem linearIndependent_of_top_le_span_of_card_eq_finrank {ι : Type*} [Fintype ι] {b : ι → V}
    (spans : ⊤ ≤ span K (Set.range b)) (card_eq : Fintype.card ι = finrank K V) :
    LinearIndependent K b :=
  linearIndependent_iff'.mpr fun s g dependent i i_mem_s => by
    classical
    

Proof state:
K : Type u
V : Type v
inst✝³ : DivisionRing K
inst✝² : AddCommGroup V
inst✝¹ : Module K V
ι : Type u_1
inst✝ : Fintype ι
b : ι → V
spans : ⊤ ≤ span K (Set.range b)
card_eq : Fintype.card ι = finrank K V
s : Finset ι
g : ι → K
dependent : (Finset.sum s fun i => g i • b i) = 0
i : ι
i_mem_s : i ∈ s
⊢ g i = 0

Next tactic:
by_contra gx_ne_zero
theorem linearIndependent_of_top_le_span_of_card_eq_finrank {ι : Type*} [Fintype ι] {b : ι → V}
    (spans : ⊤ ≤ span K (Set.range b)) (card_eq : Fintype.card ι = finrank K V) :
    LinearIndependent K b :=
  linearIndependent_iff'.mpr fun s g dependent i i_mem_s => by
    classical
    by_contra gx_ne_zero
    -- We'll derive a contradiction by showing `b '' (univ \ {i})` of cardinality `n - 1`
    -- spans a vector space of dimension `n`.
    

Proof state:
K : Type u
V : Type v
inst✝³ : DivisionRing K
inst✝² : AddCommGroup V
inst✝¹ : Module K V
ι : Type u_1
inst✝ : Fintype ι
b : ι → V
spans : ⊤ ≤ span K (Set.range b)
card_eq : Fintype.card ι = finrank K V
s : Finset ι
g : ι → K
dependent : (Finset.sum s fun i => g i • b i) = 0
i : ι
i_mem_s : i ∈ s
gx_ne_zero : ¬g i = 0
⊢ False

Next tactic:
refine' not_le_of_gt (span_lt_top_of_card_lt_finrank
      (show (b '' (Set.univ \ {i})).toFinset.card < finrank K V from _)) _
theorem linearIndependent_of_top_le_span_of_card_eq_finrank {ι : Type*} [Fintype ι] {b : ι → V}
    (spans : ⊤ ≤ span K (Set.range b)) (card_eq : Fintype.card ι = finrank K V) :
    LinearIndependent K b :=
  linearIndependent_iff'.mpr fun s g dependent i i_mem_s => by
    classical
    by_contra gx_ne_zero
    -- We'll derive a contradiction by showing `b '' (univ \ {i})` of cardinality `n - 1`
    -- spans a vector space of dimension `n`.
    refine' not_le_of_gt (span_lt_top_of_card_lt_finrank
      (show (b '' (Set.univ \ {i})).toFinset.card < finrank K V from _)) _
    · 

Proof state:
case refine'_1
K : Type u
V : Type v
inst✝³ : DivisionRing K
inst✝² : AddCommGroup V
inst✝¹ : Module K V
ι : Type u_1
inst✝ : Fintype ι
b : ι → V
spans : ⊤ ≤ span K (Set.range b)
card_eq : Fintype.card ι = finrank K V
s : Finset ι
g : ι → K
dependent : (Finset.sum s fun i => g i • b i) = 0
i : ι
i_mem_s : i ∈ s
gx_ne_zero : ¬g i = 0
⊢ Finset.card (Set.toFinset (b '' (Set.univ \ {i}))) < finrank K V

Next tactic:
calc
        (b '' (Set.univ \ {i})).toFinset.card = ((Set.univ \ {i}).toFinset.image b).card := by
          rw [Set.toFinset_card, Fintype.card_ofFinset]
        _ ≤ (Set.univ \ {i}).toFinset.card := Finset.card_image_le
        _ = (Finset.univ.erase i).card := (congr_arg Finset.card (Finset.ext (by simp [and_comm])))
        _ < Finset.univ.card := (Finset.card_erase_lt_of_mem (Finset.mem_univ i))
        _ = finrank K V := card_eq