l3lab/ntp-mathlib huggingface dataset:
/-- If a finset has cardinality larger than `finrank + 1`,
then there is a nontrivial linear relation amongst its elements,
such that the coefficients of the relation sum to zero.
-/
-- TODO: golf this
theorem Module.exists_nontrivial_relation_sum_zero_of_finrank_succ_lt_card [Module.Finite R V]
    {t : Finset V} (h : finrank R V + 1 < t.card) :
    ∃ f : V → R, ∑ e in t, f e • e = 0 ∧ ∑ e in t, f e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by
  classical
  -- Pick an element x₀ ∈ t,
  have card_pos : 0 < t.card := lt_trans (Nat.succ_pos _) h
  obtain ⟨x₀, m⟩ := (Finset.card_pos.1 card_pos).bex
  -- and apply the previous lemma to the {xᵢ - x₀}
  let shift : V ↪ V := ⟨fun x => x - x₀, sub_left_injective⟩
  let t' := (t.erase x₀).map shift
  have h' : finrank R V < t'.card := by
    simp only [card_map, Finset.card_erase_of_mem m]
    exact Nat.lt_pred_iff.mpr h
  -- to obtain a function `g`.
  obtain ⟨g, gsum, x₁, x₁_mem, nz⟩ := exists_nontrivial_relation_of_finrank_lt_card h'
  -- Then obtain `f` by translating back by `x₀`,
  -- and setting the value of `f` at `x₀` to ensure `∑ e in t, f e = 0`.
  let f : V → R := fun z => if z = x₀ then -∑ z in t.erase x₀, g (z - x₀) else g (z - x₀)
  refine' ⟨f, _, _, _⟩
  -- After this, it's a matter of verifying the properties,
  -- based on the corresponding properties for `g`.
  · show (∑ e : V in t, f e • e) = 0
    -- We prove this by splitting off the `x₀` term of the sum,
    -- which is itself a sum over `t.erase x₀`,
    -- combining the two sums, and
    -- observing that after reindexing we have exactly
    -- ∑ (x : V) in t', g x • x = 0.
    simp only
    conv_lhs =>
      apply_congr
      rfl
      rw [ite_smul]
    rw [Finset.sum_ite]
    conv =>
      congr
      congr
      apply_congr
      -- Porting note: the next two steps used to work by `simp [filter_eq', m]`
      erw [filter_eq']
      simp [m]
    conv =>
      congr
      congr
      rfl
      apply_congr
      simp [filter_ne']
    

Proof state:
case intro.intro.intro.intro.intro.refine'_1
R : Type u
M : Type v
N : Type w
V : Type v
inst✝⁶ : AddCommGroup V
V₂ : Type v'
inst✝⁵ : AddCommGroup V₂
inst✝⁴ : Ring R
inst✝³ : StrongRankCondition R
inst✝² : Module R V
inst✝¹ : Free R V
K : ?m.334640
inst✝ : Finite R V
t : Finset V
h : finrank R V + 1 < Finset.card t
card_pos : 0 < Finset.card t
x₀ : V
m : x₀ ∈ t
shift : V ↪ V := { toFun := fun x => x - x₀, inj' := (_ : Injective fun a => a - x₀) }
t' : Finset V := Finset.map shift (erase t x₀)
h' : finrank R V < Finset.card t'
g : V → R
gsum : ∑ e in t', g e • e = 0
x₁ : V
x₁_mem : x₁ ∈ t'
nz : g x₁ ≠ 0
f : V → R := fun z => if z = x₀ then -∑ z in erase t x₀, g (z - x₀) else g (z - x₀)
⊢ ∑ x in {x₀}, (-∑ z in erase t x₀, g (z - x₀)) • x + ∑ x in erase t x₀, g (x - x₀) • x = 0

Next tactic:
rw [sum_singleton, neg_smul, add_comm, ← sub_eq_add_neg, sum_smul, ← sum_sub_distrib]
/-- If a finset has cardinality larger than `finrank + 1`,
then there is a nontrivial linear relation amongst its elements,
such that the coefficients of the relation sum to zero.
-/
-- TODO: golf this
theorem Module.exists_nontrivial_relation_sum_zero_of_finrank_succ_lt_card [Module.Finite R V]
    {t : Finset V} (h : finrank R V + 1 < t.card) :
    ∃ f : V → R, ∑ e in t, f e • e = 0 ∧ ∑ e in t, f e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by
  classical
  -- Pick an element x₀ ∈ t,
  have card_pos : 0 < t.card := lt_trans (Nat.succ_pos _) h
  obtain ⟨x₀, m⟩ := (Finset.card_pos.1 card_pos).bex
  -- and apply the previous lemma to the {xᵢ - x₀}
  let shift : V ↪ V := ⟨fun x => x - x₀, sub_left_injective⟩
  let t' := (t.erase x₀).map shift
  have h' : finrank R V < t'.card := by
    simp only [card_map, Finset.card_erase_of_mem m]
    exact Nat.lt_pred_iff.mpr h
  -- to obtain a function `g`.
  obtain ⟨g, gsum, x₁, x₁_mem, nz⟩ := exists_nontrivial_relation_of_finrank_lt_card h'
  -- Then obtain `f` by translating back by `x₀`,
  -- and setting the value of `f` at `x₀` to ensure `∑ e in t, f e = 0`.
  let f : V → R := fun z => if z = x₀ then -∑ z in t.erase x₀, g (z - x₀) else g (z - x₀)
  refine' ⟨f, _, _, _⟩
  -- After this, it's a matter of verifying the properties,
  -- based on the corresponding properties for `g`.
  · show (∑ e : V in t, f e • e) = 0
    -- We prove this by splitting off the `x₀` term of the sum,
    -- which is itself a sum over `t.erase x₀`,
    -- combining the two sums, and
    -- observing that after reindexing we have exactly
    -- ∑ (x : V) in t', g x • x = 0.
    simp only
    conv_lhs =>
      apply_congr
      rfl
      rw [ite_smul]
    rw [Finset.sum_ite]
    conv =>
      congr
      congr
      apply_congr
      -- Porting note: the next two steps used to work by `simp [filter_eq', m]`
      erw [filter_eq']
      simp [m]
    conv =>
      congr
      congr
      rfl
      apply_congr
      simp [filter_ne']
    rw [sum_singleton, neg_smul, add_comm, ← sub_eq_add_neg, sum_smul, ← sum_sub_distrib]
    

Proof state:
case intro.intro.intro.intro.intro.refine'_1
R : Type u
M : Type v
N : Type w
V : Type v
inst✝⁶ : AddCommGroup V
V₂ : Type v'
inst✝⁵ : AddCommGroup V₂
inst✝⁴ : Ring R
inst✝³ : StrongRankCondition R
inst✝² : Module R V
inst✝¹ : Free R V
K : ?m.334640
inst✝ : Finite R V
t : Finset V
h : finrank R V + 1 < Finset.card t
card_pos : 0 < Finset.card t
x₀ : V
m : x₀ ∈ t
shift : V ↪ V := { toFun := fun x => x - x₀, inj' := (_ : Injective fun a => a - x₀) }
t' : Finset V := Finset.map shift (erase t x₀)
h' : finrank R V < Finset.card t'
g : V → R
gsum : ∑ e in t', g e • e = 0
x₁ : V
x₁_mem : x₁ ∈ t'
nz : g x₁ ≠ 0
f : V → R := fun z => if z = x₀ then -∑ z in erase t x₀, g (z - x₀) else g (z - x₀)
⊢ ∑ x in erase t x₀, (g (x - x₀) • x - g (x - x₀) • x₀) = 0

Next tactic:
simp only [← smul_sub]
/-- If a finset has cardinality larger than `finrank + 1`,
then there is a nontrivial linear relation amongst its elements,
such that the coefficients of the relation sum to zero.
-/
-- TODO: golf this
theorem Module.exists_nontrivial_relation_sum_zero_of_finrank_succ_lt_card [Module.Finite R V]
    {t : Finset V} (h : finrank R V + 1 < t.card) :
    ∃ f : V → R, ∑ e in t, f e • e = 0 ∧ ∑ e in t, f e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by
  classical
  -- Pick an element x₀ ∈ t,
  have card_pos : 0 < t.card := lt_trans (Nat.succ_pos _) h
  obtain ⟨x₀, m⟩ := (Finset.card_pos.1 card_pos).bex
  -- and apply the previous lemma to the {xᵢ - x₀}
  let shift : V ↪ V := ⟨fun x => x - x₀, sub_left_injective⟩
  let t' := (t.erase x₀).map shift
  have h' : finrank R V < t'.card := by
    simp only [card_map, Finset.card_erase_of_mem m]
    exact Nat.lt_pred_iff.mpr h
  -- to obtain a function `g`.
  obtain ⟨g, gsum, x₁, x₁_mem, nz⟩ := exists_nontrivial_relation_of_finrank_lt_card h'
  -- Then obtain `f` by translating back by `x₀`,
  -- and setting the value of `f` at `x₀` to ensure `∑ e in t, f e = 0`.
  let f : V → R := fun z => if z = x₀ then -∑ z in t.erase x₀, g (z - x₀) else g (z - x₀)
  refine' ⟨f, _, _, _⟩
  -- After this, it's a matter of verifying the properties,
  -- based on the corresponding properties for `g`.
  · show (∑ e : V in t, f e • e) = 0
    -- We prove this by splitting off the `x₀` term of the sum,
    -- which is itself a sum over `t.erase x₀`,
    -- combining the two sums, and
    -- observing that after reindexing we have exactly
    -- ∑ (x : V) in t', g x • x = 0.
    simp only
    conv_lhs =>
      apply_congr
      rfl
      rw [ite_smul]
    rw [Finset.sum_ite]
    conv =>
      congr
      congr
      apply_congr
      -- Porting note: the next two steps used to work by `simp [filter_eq', m]`
      erw [filter_eq']
      simp [m]
    conv =>
      congr
      congr
      rfl
      apply_congr
      simp [filter_ne']
    rw [sum_singleton, neg_smul, add_comm, ← sub_eq_add_neg, sum_smul, ← sum_sub_distrib]
    simp only [← smul_sub]
    -- At the end we have to reindex the sum, so we use `change` to
    -- express the summand using `shift`.
    

Proof state:
case intro.intro.intro.intro.intro.refine'_1
R : Type u
M : Type v
N : Type w
V : Type v
inst✝⁶ : AddCommGroup V
V₂ : Type v'
inst✝⁵ : AddCommGroup V₂
inst✝⁴ : Ring R
inst✝³ : StrongRankCondition R
inst✝² : Module R V
inst✝¹ : Free R V
K : ?m.334640
inst✝ : Finite R V
t : Finset V
h : finrank R V + 1 < Finset.card t
card_pos : 0 < Finset.card t
x₀ : V
m : x₀ ∈ t
shift : V ↪ V := { toFun := fun x => x - x₀, inj' := (_ : Injective fun a => a - x₀) }
t' : Finset V := Finset.map shift (erase t x₀)
h' : finrank R V < Finset.card t'
g : V → R
gsum : ∑ e in t', g e • e = 0
x₁ : V
x₁_mem : x₁ ∈ t'
nz : g x₁ ≠ 0
f : V → R := fun z => if z = x₀ then -∑ z in erase t x₀, g (z - x₀) else g (z - x₀)
⊢ ∑ x in erase t x₀, g (x - x₀) • (x - x₀) = 0

Next tactic:
change (∑ x : V in t.erase x₀, (fun e => g e • e) (shift x)) = 0
/-- If a finset has cardinality larger than `finrank + 1`,
then there is a nontrivial linear relation amongst its elements,
such that the coefficients of the relation sum to zero.
-/
-- TODO: golf this
theorem Module.exists_nontrivial_relation_sum_zero_of_finrank_succ_lt_card [Module.Finite R V]
    {t : Finset V} (h : finrank R V + 1 < t.card) :
    ∃ f : V → R, ∑ e in t, f e • e = 0 ∧ ∑ e in t, f e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by
  classical
  -- Pick an element x₀ ∈ t,
  have card_pos : 0 < t.card := lt_trans (Nat.succ_pos _) h
  obtain ⟨x₀, m⟩ := (Finset.card_pos.1 card_pos).bex
  -- and apply the previous lemma to the {xᵢ - x₀}
  let shift : V ↪ V := ⟨fun x => x - x₀, sub_left_injective⟩
  let t' := (t.erase x₀).map shift
  have h' : finrank R V < t'.card := by
    simp only [card_map, Finset.card_erase_of_mem m]
    exact Nat.lt_pred_iff.mpr h
  -- to obtain a function `g`.
  obtain ⟨g, gsum, x₁, x₁_mem, nz⟩ := exists_nontrivial_relation_of_finrank_lt_card h'
  -- Then obtain `f` by translating back by `x₀`,
  -- and setting the value of `f` at `x₀` to ensure `∑ e in t, f e = 0`.
  let f : V → R := fun z => if z = x₀ then -∑ z in t.erase x₀, g (z - x₀) else g (z - x₀)
  refine' ⟨f, _, _, _⟩
  -- After this, it's a matter of verifying the properties,
  -- based on the corresponding properties for `g`.
  · show (∑ e : V in t, f e • e) = 0
    -- We prove this by splitting off the `x₀` term of the sum,
    -- which is itself a sum over `t.erase x₀`,
    -- combining the two sums, and
    -- observing that after reindexing we have exactly
    -- ∑ (x : V) in t', g x • x = 0.
    simp only
    conv_lhs =>
      apply_congr
      rfl
      rw [ite_smul]
    rw [Finset.sum_ite]
    conv =>
      congr
      congr
      apply_congr
      -- Porting note: the next two steps used to work by `simp [filter_eq', m]`
      erw [filter_eq']
      simp [m]
    conv =>
      congr
      congr
      rfl
      apply_congr
      simp [filter_ne']
    rw [sum_singleton, neg_smul, add_comm, ← sub_eq_add_neg, sum_smul, ← sum_sub_distrib]
    simp only [← smul_sub]
    -- At the end we have to reindex the sum, so we use `change` to
    -- express the summand using `shift`.
    change (∑ x : V in t.erase x₀, (fun e => g e • e) (shift x)) = 0
    -- porting note: last argument can't be inferred
    

Proof state:
case intro.intro.intro.intro.intro.refine'_1
R : Type u
M : Type v
N : Type w
V : Type v
inst✝⁶ : AddCommGroup V
V₂ : Type v'
inst✝⁵ : AddCommGroup V₂
inst✝⁴ : Ring R
inst✝³ : StrongRankCondition R
inst✝² : Module R V
inst✝¹ : Free R V
K : ?m.334640
inst✝ : Finite R V
t : Finset V
h : finrank R V + 1 < Finset.card t
card_pos : 0 < Finset.card t
x₀ : V
m : x₀ ∈ t
shift : V ↪ V := { toFun := fun x => x - x₀, inj' := (_ : Injective fun a => a - x₀) }
t' : Finset V := Finset.map shift (erase t x₀)
h' : finrank R V < Finset.card t'
g : V → R
gsum : ∑ e in t', g e • e = 0
x₁ : V
x₁_mem : x₁ ∈ t'
nz : g x₁ ≠ 0
f : V → R := fun z => if z = x₀ then -∑ z in erase t x₀, g (z - x₀) else g (z - x₀)
⊢ ∑ x in erase t x₀, (fun e => g e • e) (shift x) = 0

Next tactic:
rw [← sum_map _ shift (fun e => g e • e)]
/-- If a finset has cardinality larger than `finrank + 1`,
then there is a nontrivial linear relation amongst its elements,
such that the coefficients of the relation sum to zero.
-/
-- TODO: golf this
theorem Module.exists_nontrivial_relation_sum_zero_of_finrank_succ_lt_card [Module.Finite R V]
    {t : Finset V} (h : finrank R V + 1 < t.card) :
    ∃ f : V → R, ∑ e in t, f e • e = 0 ∧ ∑ e in t, f e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by
  classical
  -- Pick an element x₀ ∈ t,
  have card_pos : 0 < t.card := lt_trans (Nat.succ_pos _) h
  obtain ⟨x₀, m⟩ := (Finset.card_pos.1 card_pos).bex
  -- and apply the previous lemma to the {xᵢ - x₀}
  let shift : V ↪ V := ⟨fun x => x - x₀, sub_left_injective⟩
  let t' := (t.erase x₀).map shift
  have h' : finrank R V < t'.card := by
    simp only [card_map, Finset.card_erase_of_mem m]
    exact Nat.lt_pred_iff.mpr h
  -- to obtain a function `g`.
  obtain ⟨g, gsum, x₁, x₁_mem, nz⟩ := exists_nontrivial_relation_of_finrank_lt_card h'
  -- Then obtain `f` by translating back by `x₀`,
  -- and setting the value of `f` at `x₀` to ensure `∑ e in t, f e = 0`.
  let f : V → R := fun z => if z = x₀ then -∑ z in t.erase x₀, g (z - x₀) else g (z - x₀)
  refine' ⟨f, _, _, _⟩
  -- After this, it's a matter of verifying the properties,
  -- based on the corresponding properties for `g`.
  · show (∑ e : V in t, f e • e) = 0
    -- We prove this by splitting off the `x₀` term of the sum,
    -- which is itself a sum over `t.erase x₀`,
    -- combining the two sums, and
    -- observing that after reindexing we have exactly
    -- ∑ (x : V) in t', g x • x = 0.
    simp only
    conv_lhs =>
      apply_congr
      rfl
      rw [ite_smul]
    rw [Finset.sum_ite]
    conv =>
      congr
      congr
      apply_congr
      -- Porting note: the next two steps used to work by `simp [filter_eq', m]`
      erw [filter_eq']
      simp [m]
    conv =>
      congr
      congr
      rfl
      apply_congr
      simp [filter_ne']
    rw [sum_singleton, neg_smul, add_comm, ← sub_eq_add_neg, sum_smul, ← sum_sub_distrib]
    simp only [← smul_sub]
    -- At the end we have to reindex the sum, so we use `change` to
    -- express the summand using `shift`.
    change (∑ x : V in t.erase x₀, (fun e => g e • e) (shift x)) = 0
    -- porting note: last argument can't be inferred
    rw [← sum_map _ shift (fun e => g e • e)]
    

Proof state:
case intro.intro.intro.intro.intro.refine'_1
R : Type u
M : Type v
N : Type w
V : Type v
inst✝⁶ : AddCommGroup V
V₂ : Type v'
inst✝⁵ : AddCommGroup V₂
inst✝⁴ : Ring R
inst✝³ : StrongRankCondition R
inst✝² : Module R V
inst✝¹ : Free R V
K : ?m.334640
inst✝ : Finite R V
t : Finset V
h : finrank R V + 1 < Finset.card t
card_pos : 0 < Finset.card t
x₀ : V
m : x₀ ∈ t
shift : V ↪ V := { toFun := fun x => x - x₀, inj' := (_ : Injective fun a => a - x₀) }
t' : Finset V := Finset.map shift (erase t x₀)
h' : finrank R V < Finset.card t'
g : V → R
gsum : ∑ e in t', g e • e = 0
x₁ : V
x₁_mem : x₁ ∈ t'
nz : g x₁ ≠ 0
f : V → R := fun z => if z = x₀ then -∑ z in erase t x₀, g (z - x₀) else g (z - x₀)
⊢ ∑ x in Finset.map shift (erase t x₀), g x • x = 0

Next tactic:
exact gsum
/-- If a finset has cardinality larger than `finrank + 1`,
then there is a nontrivial linear relation amongst its elements,
such that the coefficients of the relation sum to zero.
-/
-- TODO: golf this
theorem Module.exists_nontrivial_relation_sum_zero_of_finrank_succ_lt_card [Module.Finite R V]
    {t : Finset V} (h : finrank R V + 1 < t.card) :
    ∃ f : V → R, ∑ e in t, f e • e = 0 ∧ ∑ e in t, f e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by
  classical
  -- Pick an element x₀ ∈ t,
  have card_pos : 0 < t.card := lt_trans (Nat.succ_pos _) h
  obtain ⟨x₀, m⟩ := (Finset.card_pos.1 card_pos).bex
  -- and apply the previous lemma to the {xᵢ - x₀}
  let shift : V ↪ V := ⟨fun x => x - x₀, sub_left_injective⟩
  let t' := (t.erase x₀).map shift
  have h' : finrank R V < t'.card := by
    simp only [card_map, Finset.card_erase_of_mem m]
    exact Nat.lt_pred_iff.mpr h
  -- to obtain a function `g`.
  obtain ⟨g, gsum, x₁, x₁_mem, nz⟩ := exists_nontrivial_relation_of_finrank_lt_card h'
  -- Then obtain `f` by translating back by `x₀`,
  -- and setting the value of `f` at `x₀` to ensure `∑ e in t, f e = 0`.
  let f : V → R := fun z => if z = x₀ then -∑ z in t.erase x₀, g (z - x₀) else g (z - x₀)
  refine' ⟨f, _, _, _⟩
  -- After this, it's a matter of verifying the properties,
  -- based on the corresponding properties for `g`.
  · show (∑ e : V in t, f e • e) = 0
    -- We prove this by splitting off the `x₀` term of the sum,
    -- which is itself a sum over `t.erase x₀`,
    -- combining the two sums, and
    -- observing that after reindexing we have exactly
    -- ∑ (x : V) in t', g x • x = 0.
    simp only
    conv_lhs =>
      apply_congr
      rfl
      rw [ite_smul]
    rw [Finset.sum_ite]
    conv =>
      congr
      congr
      apply_congr
      -- Porting note: the next two steps used to work by `simp [filter_eq', m]`
      erw [filter_eq']
      simp [m]
    conv =>
      congr
      congr
      rfl
      apply_congr
      simp [filter_ne']
    rw [sum_singleton, neg_smul, add_comm, ← sub_eq_add_neg, sum_smul, ← sum_sub_distrib]
    simp only [← smul_sub]
    -- At the end we have to reindex the sum, so we use `change` to
    -- express the summand using `shift`.
    change (∑ x : V in t.erase x₀, (fun e => g e • e) (shift x)) = 0
    -- porting note: last argument can't be inferred
    rw [← sum_map _ shift (fun e => g e • e)]
    exact gsum
  · 

Proof state:
case intro.intro.intro.intro.intro.refine'_2
R : Type u
M : Type v
N : Type w
V : Type v
inst✝⁶ : AddCommGroup V
V₂ : Type v'
inst✝⁵ : AddCommGroup V₂
inst✝⁴ : Ring R
inst✝³ : StrongRankCondition R
inst✝² : Module R V
inst✝¹ : Free R V
K : ?m.334640
inst✝ : Finite R V
t : Finset V
h : finrank R V + 1 < Finset.card t
card_pos : 0 < Finset.card t
x₀ : V
m : x₀ ∈ t
shift : V ↪ V := { toFun := fun x => x - x₀, inj' := (_ : Injective fun a => a - x₀) }
t' : Finset V := Finset.map shift (erase t x₀)
h' : finrank R V < Finset.card t'
g : V → R
gsum : ∑ e in t', g e • e = 0
x₁ : V
x₁_mem : x₁ ∈ t'
nz : g x₁ ≠ 0
f : V → R := fun z => if z = x₀ then -∑ z in erase t x₀, g (z - x₀) else g (z - x₀)
⊢ ∑ e in t, f e = 0

Next tactic:
show (∑ e : V in t, f e) = 0
theorem Module.finite_of_rank_eq_nat [Module.Free R V] {n : ℕ} (h : Module.rank R V = n) :
    Module.Finite R V := by
  

Proof state:
R : Type u
M : Type v
N : Type w
V : Type v
inst✝³ : Ring R
inst✝² : AddCommGroup V
inst✝¹ : Module R V
inst✝ : Free R V
n : ℕ
h : Module.rank R V = ↑n
⊢ Finite R V

Next tactic:
nontriviality R
theorem Module.finite_of_rank_eq_nat [Module.Free R V] {n : ℕ} (h : Module.rank R V = n) :
    Module.Finite R V := by
  nontriviality R
  

Proof state:
R : Type u
M : Type v
N : Type w
V : Type v
inst✝³ : Ring R
inst✝² : AddCommGroup V
inst✝¹ : Module R V
inst✝ : Free R V
n : ℕ
h : Module.rank R V = ↑n
✝ : Nontrivial R
⊢ Finite R V

Next tactic:
obtain ⟨⟨ι, b⟩⟩ := Module.Free.exists_basis (R := R) (M := V)
theorem Module.finite_of_rank_eq_nat [Module.Free R V] {n : ℕ} (h : Module.rank R V = n) :
    Module.Finite R V := by
  nontriviality R
  obtain ⟨⟨ι, b⟩⟩ := Module.Free.exists_basis (R := R) (M := V)
  

Proof state:
case intro.mk
R : Type u
M : Type v
N : Type w
V : Type v
inst✝³ : Ring R
inst✝² : AddCommGroup V
inst✝¹ : Module R V
inst✝ : Free R V
n : ℕ
h : Module.rank R V = ↑n
✝ : Nontrivial R
ι : Type v
b : Basis ι R V
⊢ Finite R V

Next tactic:
have := mk_lt_aleph0_iff.mp <| cardinal_le_rank_of_linearIndependent
    b.linearIndependent |>.trans_eq h |>.trans_lt <| nat_lt_aleph0 n
theorem Module.finite_of_rank_eq_nat [Module.Free R V] {n : ℕ} (h : Module.rank R V = n) :
    Module.Finite R V := by
  nontriviality R
  obtain ⟨⟨ι, b⟩⟩ := Module.Free.exists_basis (R := R) (M := V)
  have := mk_lt_aleph0_iff.mp <| cardinal_le_rank_of_linearIndependent
    b.linearIndependent |>.trans_eq h |>.trans_lt <| nat_lt_aleph0 n
  

Proof state:
case intro.mk
R : Type u
M : Type v
N : Type w
V : Type v
inst✝³ : Ring R
inst✝² : AddCommGroup V
inst✝¹ : Module R V
inst✝ : Free R V
n : ℕ
h : Module.rank R V = ↑n
✝ : Nontrivial R
ι : Type v
b : Basis ι R V
this : _root_.Finite ι
⊢ Finite R V

Next tactic:
exact Module.Finite.of_basis b
theorem Module.finite_of_rank_eq_zero [NoZeroSMulDivisors R V]
    (h : Module.rank R V = 0) :
    Module.Finite R V := by
  

Proof state:
R : Type u
M : Type v
N : Type w
V : Type v
inst✝³ : Ring R
inst✝² : AddCommGroup V
inst✝¹ : Module R V
inst✝ : NoZeroSMulDivisors R V
h : Module.rank R V = 0
⊢ Finite R V

Next tactic:
nontriviality R
theorem Module.finite_of_rank_eq_zero [NoZeroSMulDivisors R V]
    (h : Module.rank R V = 0) :
    Module.Finite R V := by
  nontriviality R
  

Proof state:
R : Type u
M : Type v
N : Type w
V : Type v
inst✝³ : Ring R
inst✝² : AddCommGroup V
inst✝¹ : Module R V
inst✝ : NoZeroSMulDivisors R V
h : Module.rank R V = 0
✝ : Nontrivial R
⊢ Finite R V

Next tactic:
rw [rank_zero_iff] at h
theorem Module.finite_of_rank_eq_zero [NoZeroSMulDivisors R V]
    (h : Module.rank R V = 0) :
    Module.Finite R V := by
  nontriviality R
  rw [rank_zero_iff] at h
  

Proof state:
R : Type u
M : Type v
N : Type w
V : Type v
inst✝³ : Ring R
inst✝² : AddCommGroup V
inst✝¹ : Module R V
inst✝ : NoZeroSMulDivisors R V
h : Subsingleton V
✝ : Nontrivial R
⊢ Finite R V

Next tactic:
infer_instance
theorem FiniteDimensional.finrank_eq_zero_of_rank_eq_zero (h : Module.rank R V = 0) :
    finrank R V = 0 := by
  

Proof state:
R : Type u
M : Type v
N : Type w
V : Type v
inst✝² : Ring R
inst✝¹ : AddCommGroup V
inst✝ : Module R V
h : Module.rank R V = 0
⊢ finrank R V = 0

Next tactic:
delta finrank
theorem FiniteDimensional.finrank_eq_zero_of_rank_eq_zero (h : Module.rank R V = 0) :
    finrank R V = 0 := by
  delta finrank
  

Proof state:
R : Type u
M : Type v
N : Type w
V : Type v
inst✝² : Ring R
inst✝¹ : AddCommGroup V
inst✝ : Module R V
h : Module.rank R V = 0
⊢ toNat (Module.rank R V) = 0

Next tactic:
rw [h, zero_toNat]
theorem Submodule.bot_eq_top_of_rank_eq_zero [NoZeroSMulDivisors R V] (h : Module.rank R V = 0) :
    (⊥ : Submodule R V) = ⊤ := by
  

Proof state:
R : Type u
M : Type v
N : Type w
V : Type v
inst✝³ : Ring R
inst✝² : AddCommGroup V
inst✝¹ : Module R V
inst✝ : NoZeroSMulDivisors R V
h : Module.rank R V = 0
⊢ ⊥ = ⊤

Next tactic:
nontriviality R
theorem Submodule.bot_eq_top_of_rank_eq_zero [NoZeroSMulDivisors R V] (h : Module.rank R V = 0) :
    (⊥ : Submodule R V) = ⊤ := by
  nontriviality R
  

Proof state:
R : Type u
M : Type v
N : Type w
V : Type v
inst✝³ : Ring R
inst✝² : AddCommGroup V
inst✝¹ : Module R V
inst✝ : NoZeroSMulDivisors R V
h : Module.rank R V = 0
✝ : Nontrivial R
⊢ ⊥ = ⊤

Next tactic:
rw [rank_zero_iff] at h
theorem Submodule.bot_eq_top_of_rank_eq_zero [NoZeroSMulDivisors R V] (h : Module.rank R V = 0) :
    (⊥ : Submodule R V) = ⊤ := by
  nontriviality R
  rw [rank_zero_iff] at h
  

Proof state:
R : Type u
M : Type v
N : Type w
V : Type v
inst✝³ : Ring R
inst✝² : AddCommGroup V
inst✝¹ : Module R V
inst✝ : NoZeroSMulDivisors R V
h : Subsingleton V
✝ : Nontrivial R
⊢ ⊥ = ⊤

Next tactic:
exact Subsingleton.elim _ _
/-- See `rank_subsingleton` for the reason that `Nontrivial R` is needed. -/
@[simp]
theorem Submodule.rank_eq_zero [Nontrivial R] [NoZeroSMulDivisors R V] {S : Submodule R V} :
    Module.rank R S = 0 ↔ S = ⊥ :=
  ⟨fun h =>
    (Submodule.eq_bot_iff _).2 fun x hx =>
      congr_arg Subtype.val <|
        ((Submodule.eq_bot_iff _).1 <| Eq.symm <| Submodule.bot_eq_top_of_rank_eq_zero h) ⟨x, hx⟩
          Submodule.mem_top,
    fun h => by 

Proof state:
R : Type u
M : Type v
N : Type w
V : Type v
inst✝⁴ : Ring R
inst✝³ : AddCommGroup V
inst✝² : Module R V
inst✝¹ : Nontrivial R
inst✝ : NoZeroSMulDivisors R V
S : Submodule R V
h : S = ⊥
⊢ Module.rank R ↥S = 0

Next tactic:
rw [h, rank_bot]
@[simp]
theorem Submodule.finrank_eq_zero [StrongRankCondition R] [NoZeroSMulDivisors R V]
    {S : Submodule R V} [Module.Finite R S] :
    finrank R S = 0 ↔ S = ⊥ := by
  

Proof state:
R : Type u
M : Type v
N : Type w
V : Type v
inst✝⁵ : Ring R
inst✝⁴ : AddCommGroup V
inst✝³ : Module R V
inst✝² : StrongRankCondition R
inst✝¹ : NoZeroSMulDivisors R V
S : Submodule R V
inst✝ : Module.Finite R ↥S
⊢ finrank R ↥S = 0 ↔ S = ⊥

Next tactic:
rw [← Submodule.rank_eq_zero, ← finrank_eq_rank, ← @Nat.cast_zero Cardinal, Cardinal.natCast_inj]