l3lab/ntp-mathlib huggingface dataset:
theorem CompleteLattice.Independent.subtype_ne_bot_le_finrank_aux [Module.Finite R V]
    [NoZeroSMulDivisors R V]
    {ι : Type w} {p : ι → Submodule R V} (hp : CompleteLattice.Independent p) :
    #{ i // p i ≠ ⊥ } ≤ (finrank R V : Cardinal.{w}) := by
  suffices Cardinal.lift.{v} #{ i // p i ≠ ⊥ } ≤ Cardinal.lift.{v} (finrank R V : Cardinal.{w}) by
    rwa [Cardinal.lift_le] at this
  

Proof state:
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.297683
inst✝¹ : Module.Finite R V
inst✝ : NoZeroSMulDivisors R V
ι : Type w
p : ι → Submodule R V
hp : Independent p
⊢ Cardinal.lift.{v, w} #{ i // p i ≠ ⊥ } ≤ Cardinal.lift.{v, w} ↑(finrank R V)

Next tactic:
calc
    Cardinal.lift.{v} #{ i // p i ≠ ⊥ } ≤ Cardinal.lift.{w} (Module.rank R V) :=
      hp.subtype_ne_bot_le_rank
    _ = Cardinal.lift.{w} (finrank R V : Cardinal.{v}) := by rw [finrank_eq_rank]
    _ = Cardinal.lift.{v} (finrank R V : Cardinal.{w}) := by simp
theorem CompleteLattice.Independent.subtype_ne_bot_le_finrank_aux [Module.Finite R V]
    [NoZeroSMulDivisors R V]
    {ι : Type w} {p : ι → Submodule R V} (hp : CompleteLattice.Independent p) :
    #{ i // p i ≠ ⊥ } ≤ (finrank R V : Cardinal.{w}) := by
  suffices Cardinal.lift.{v} #{ i // p i ≠ ⊥ } ≤ Cardinal.lift.{v} (finrank R V : Cardinal.{w}) by
    rwa [Cardinal.lift_le] at this
  calc
    Cardinal.lift.{v} #{ i // p i ≠ ⊥ } ≤ Cardinal.lift.{w} (Module.rank R V) :=
      hp.subtype_ne_bot_le_rank
    _ = Cardinal.lift.{w} (finrank R V : Cardinal.{v}) := by 

Proof state:
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.297683
inst✝¹ : Module.Finite R V
inst✝ : NoZeroSMulDivisors R V
ι : Type w
p : ι → Submodule R V
hp : Independent p
⊢ Cardinal.lift.{w, v} (Module.rank R V) = Cardinal.lift.{w, v} ↑(finrank R V)

Next tactic:
rw [finrank_eq_rank]
theorem CompleteLattice.Independent.subtype_ne_bot_le_finrank_aux [Module.Finite R V]
    [NoZeroSMulDivisors R V]
    {ι : Type w} {p : ι → Submodule R V} (hp : CompleteLattice.Independent p) :
    #{ i // p i ≠ ⊥ } ≤ (finrank R V : Cardinal.{w}) := by
  suffices Cardinal.lift.{v} #{ i // p i ≠ ⊥ } ≤ Cardinal.lift.{v} (finrank R V : Cardinal.{w}) by
    rwa [Cardinal.lift_le] at this
  calc
    Cardinal.lift.{v} #{ i // p i ≠ ⊥ } ≤ Cardinal.lift.{w} (Module.rank R V) :=
      hp.subtype_ne_bot_le_rank
    _ = Cardinal.lift.{w} (finrank R V : Cardinal.{v}) := by rw [finrank_eq_rank]
    _ = Cardinal.lift.{v} (finrank R V : Cardinal.{w}) := by 

Proof state:
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.297683
inst✝¹ : Module.Finite R V
inst✝ : NoZeroSMulDivisors R V
ι : Type w
p : ι → Submodule R V
hp : Independent p
⊢ Cardinal.lift.{w, v} ↑(finrank R V) = Cardinal.lift.{v, w} ↑(finrank R V)

Next tactic:
simp
/-- If `p` is an independent family of submodules of a `R`-finite module `V`, then the
number of nontrivial subspaces in the family `p` is finite. -/
noncomputable def CompleteLattice.Independent.fintypeNeBotOfFiniteDimensional
    [Module.Finite R V] [NoZeroSMulDivisors R V] {ι : Type w} {p : ι → Submodule R V}
    (hp : CompleteLattice.Independent p) : Fintype { i : ι // p i ≠ ⊥ } := by
  

Proof state:
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.304690
inst✝¹ : Module.Finite R V
inst✝ : NoZeroSMulDivisors R V
ι : Type w
p : ι → Submodule R V
hp : Independent p
⊢ Fintype { i // p i ≠ ⊥ }

Next tactic:
suffices #{ i // p i ≠ ⊥ } < (ℵ₀ : Cardinal.{w}) by
    rw [Cardinal.lt_aleph0_iff_fintype] at this
    exact this.some
/-- If `p` is an independent family of submodules of a `R`-finite module `V`, then the
number of nontrivial subspaces in the family `p` is finite. -/
noncomputable def CompleteLattice.Independent.fintypeNeBotOfFiniteDimensional
    [Module.Finite R V] [NoZeroSMulDivisors R V] {ι : Type w} {p : ι → Submodule R V}
    (hp : CompleteLattice.Independent p) : Fintype { i : ι // p i ≠ ⊥ } := by
  suffices #{ i // p i ≠ ⊥ } < (ℵ₀ : Cardinal.{w}) by
    

Proof state:
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.304690
inst✝¹ : Module.Finite R V
inst✝ : NoZeroSMulDivisors R V
ι : Type w
p : ι → Submodule R V
hp : Independent p
this : #{ i // p i ≠ ⊥ } < ℵ₀
⊢ Fintype { i // p i ≠ ⊥ }

Next tactic:
rw [Cardinal.lt_aleph0_iff_fintype] at this
/-- If `p` is an independent family of submodules of a `R`-finite module `V`, then the
number of nontrivial subspaces in the family `p` is finite. -/
noncomputable def CompleteLattice.Independent.fintypeNeBotOfFiniteDimensional
    [Module.Finite R V] [NoZeroSMulDivisors R V] {ι : Type w} {p : ι → Submodule R V}
    (hp : CompleteLattice.Independent p) : Fintype { i : ι // p i ≠ ⊥ } := by
  suffices #{ i // p i ≠ ⊥ } < (ℵ₀ : Cardinal.{w}) by
    rw [Cardinal.lt_aleph0_iff_fintype] at this
    

Proof state:
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.304690
inst✝¹ : Module.Finite R V
inst✝ : NoZeroSMulDivisors R V
ι : Type w
p : ι → Submodule R V
hp : Independent p
this : Nonempty (Fintype { i // p i ≠ ⊥ })
⊢ Fintype { i // p i ≠ ⊥ }

Next tactic:
exact this.some
/-- If `p` is an independent family of submodules of a `R`-finite module `V`, then the
number of nontrivial subspaces in the family `p` is finite. -/
noncomputable def CompleteLattice.Independent.fintypeNeBotOfFiniteDimensional
    [Module.Finite R V] [NoZeroSMulDivisors R V] {ι : Type w} {p : ι → Submodule R V}
    (hp : CompleteLattice.Independent p) : Fintype { i : ι // p i ≠ ⊥ } := by
  suffices #{ i // p i ≠ ⊥ } < (ℵ₀ : Cardinal.{w}) by
    rw [Cardinal.lt_aleph0_iff_fintype] at this
    exact this.some
  

Proof state:
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.304690
inst✝¹ : Module.Finite R V
inst✝ : NoZeroSMulDivisors R V
ι : Type w
p : ι → Submodule R V
hp : Independent p
⊢ #{ i // p i ≠ ⊥ } < ℵ₀

Next tactic:
refine' lt_of_le_of_lt hp.subtype_ne_bot_le_finrank_aux _
/-- If `p` is an independent family of submodules of a `R`-finite module `V`, then the
number of nontrivial subspaces in the family `p` is finite. -/
noncomputable def CompleteLattice.Independent.fintypeNeBotOfFiniteDimensional
    [Module.Finite R V] [NoZeroSMulDivisors R V] {ι : Type w} {p : ι → Submodule R V}
    (hp : CompleteLattice.Independent p) : Fintype { i : ι // p i ≠ ⊥ } := by
  suffices #{ i // p i ≠ ⊥ } < (ℵ₀ : Cardinal.{w}) by
    rw [Cardinal.lt_aleph0_iff_fintype] at this
    exact this.some
  refine' lt_of_le_of_lt hp.subtype_ne_bot_le_finrank_aux _
  

Proof state:
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.304690
inst✝¹ : Module.Finite R V
inst✝ : NoZeroSMulDivisors R V
ι : Type w
p : ι → Submodule R V
hp : Independent p
⊢ ↑(finrank R V) < ℵ₀

Next tactic:
simp [Cardinal.nat_lt_aleph0]
/-- If `p` is an independent family of submodules of a `R`-finite module `V`, then the
number of nontrivial subspaces in the family `p` is bounded above by the dimension of `V`.

Note that the `Fintype` hypothesis required here can be provided by
`CompleteLattice.Independent.fintypeNeBotOfFiniteDimensional`. -/
theorem CompleteLattice.Independent.subtype_ne_bot_le_finrank
    [Module.Finite R V] [NoZeroSMulDivisors R V]
    {ι : Type w} {p : ι → Submodule R V} (hp : CompleteLattice.Independent p)
    [Fintype { i // p i ≠ ⊥ }] :
    Fintype.card { i // p i ≠ ⊥ } ≤ finrank R V := by 

Proof state:
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.309824
inst✝² : Module.Finite R V
inst✝¹ : NoZeroSMulDivisors R V
ι : Type w
p : ι → Submodule R V
hp : Independent p
inst✝ : Fintype { i // p i ≠ ⊥ }
⊢ card { i // p i ≠ ⊥ } ≤ finrank R V

Next tactic:
simpa using hp.subtype_ne_bot_le_finrank_aux
/-- If a finset has cardinality larger than the rank of a module,
then there is a nontrivial linear relation amongst its elements.
-/
-- TODO: golf this
theorem Module.exists_nontrivial_relation_of_finrank_lt_card
    [Module.Finite R V] {t : Finset V}
    (h : finrank R V < t.card) : ∃ f : V → R, ∑ e in t, f e • e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by
  

Proof state:
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.320903
inst✝ : Finite R V
t : Finset V
h : finrank R V < Finset.card t
⊢ ∃ f, ∑ e in t, f e • e = 0 ∧ ∃ x ∈ t, f x ≠ 0

Next tactic:
classical
  have := mt FiniteDimensional.finset_card_le_finrank_of_linearIndependent (by simpa using h)
  rw [_root_.not_linearIndependent_iff] at this
  obtain ⟨s, g, sum, z, zm, nonzero⟩ := this
  -- Now we have to extend `g` to all of `t`, then to all of `V`.
  let f : V → R := fun x => if h : x ∈ t then if (⟨x, h⟩ : t) ∈ s then g ⟨x, h⟩ else 0 else 0
  -- and finally clean up the mess caused by the extension.
  refine' ⟨f, _, _⟩
  · dsimp
    rw [← (sum)] -- porting note: need parens to disambiguate
    fapply sum_bij_ne_zero fun v hvt _ => (⟨v, hvt⟩ : { v // v ∈ t })
    · intro v hvt H
      dsimp
      rw [dif_pos hvt] at H
      contrapose! H
      rw [if_neg H, zero_smul]
    · intro _ _ _ _ _ _
      exact Subtype.mk.inj
    · intro b hbs hb
      use b
      simpa only [hbs, exists_prop, dif_pos, Finset.mk_coe, and_true_iff, if_true, Finset.coe_mem,
        eq_self_iff_true, exists_prop_of_true, Ne.def] using hb
    · intro a h₁
      dsimp
      rw [dif_pos h₁]
      intro h₂
      rw [if_pos]
      contrapose! h₂
      rw [if_neg h₂, zero_smul]
  · refine' ⟨z, z.2, _⟩
    dsimp only
    erw [dif_pos z.2, if_pos] <;> rwa [Subtype.coe_eta]
/-- If a finset has cardinality larger than the rank of a module,
then there is a nontrivial linear relation amongst its elements.
-/
-- TODO: golf this
theorem Module.exists_nontrivial_relation_of_finrank_lt_card
    [Module.Finite R V] {t : Finset V}
    (h : finrank R V < t.card) : ∃ f : V → R, ∑ e in t, f e • e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by
  classical
  

Proof state:
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.320903
inst✝ : Finite R V
t : Finset V
h : finrank R V < Finset.card t
⊢ ∃ f, ∑ e in t, f e • e = 0 ∧ ∃ x ∈ t, f x ≠ 0

Next tactic:
have := mt FiniteDimensional.finset_card_le_finrank_of_linearIndependent (by simpa using h)
/-- If a finset has cardinality larger than the rank of a module,
then there is a nontrivial linear relation amongst its elements.
-/
-- TODO: golf this
theorem Module.exists_nontrivial_relation_of_finrank_lt_card
    [Module.Finite R V] {t : Finset V}
    (h : finrank R V < t.card) : ∃ f : V → R, ∑ e in t, f e • e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by
  classical
  have := mt FiniteDimensional.finset_card_le_finrank_of_linearIndependent (by 

Proof state:
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.320903
inst✝ : Finite R V
t : Finset V
h : finrank R V < Finset.card t
⊢ ¬Finset.card ?m.323544 ≤ finrank ?m.323537 ?m.323538

Next tactic:
simpa using h
/-- If a finset has cardinality larger than the rank of a module,
then there is a nontrivial linear relation amongst its elements.
-/
-- TODO: golf this
theorem Module.exists_nontrivial_relation_of_finrank_lt_card
    [Module.Finite R V] {t : Finset V}
    (h : finrank R V < t.card) : ∃ f : V → R, ∑ e in t, f e • e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by
  classical
  have := mt FiniteDimensional.finset_card_le_finrank_of_linearIndependent (by simpa using h)
  

Proof state:
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.320903
inst✝ : Finite R V
t : Finset V
h : finrank R V < Finset.card t
this : ¬LinearIndependent R fun x => ↑x
⊢ ∃ f, ∑ e in t, f e • e = 0 ∧ ∃ x ∈ t, f x ≠ 0

Next tactic:
rw [_root_.not_linearIndependent_iff] at this
/-- If a finset has cardinality larger than the rank of a module,
then there is a nontrivial linear relation amongst its elements.
-/
-- TODO: golf this
theorem Module.exists_nontrivial_relation_of_finrank_lt_card
    [Module.Finite R V] {t : Finset V}
    (h : finrank R V < t.card) : ∃ f : V → R, ∑ e in t, f e • e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by
  classical
  have := mt FiniteDimensional.finset_card_le_finrank_of_linearIndependent (by simpa using h)
  rw [_root_.not_linearIndependent_iff] at this
  

Proof state:
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.320903
inst✝ : Finite R V
t : Finset V
h : finrank R V < Finset.card t
this : ∃ s g, ∑ i in s, g i • ↑i = 0 ∧ ∃ i ∈ s, g i ≠ 0
⊢ ∃ f, ∑ e in t, f e • e = 0 ∧ ∃ x ∈ t, f x ≠ 0

Next tactic:
obtain ⟨s, g, sum, z, zm, nonzero⟩ := this
/-- If a finset has cardinality larger than the rank of a module,
then there is a nontrivial linear relation amongst its elements.
-/
-- TODO: golf this
theorem Module.exists_nontrivial_relation_of_finrank_lt_card
    [Module.Finite R V] {t : Finset V}
    (h : finrank R V < t.card) : ∃ f : V → R, ∑ e in t, f e • e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by
  classical
  have := mt FiniteDimensional.finset_card_le_finrank_of_linearIndependent (by simpa using h)
  rw [_root_.not_linearIndependent_iff] at this
  obtain ⟨s, g, sum, z, zm, nonzero⟩ := this
  -- Now we have to extend `g` to all of `t`, then to all of `V`.
  

Proof state:
case intro.intro.intro.intro.intro
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.320903
inst✝ : Finite R V
t : Finset V
h : finrank R V < Finset.card t
s : Finset { x // x ∈ t }
g : { x // x ∈ t } → R
sum : ∑ i in s, g i • ↑i = 0
z : { x // x ∈ t }
zm : z ∈ s
nonzero : g z ≠ 0
⊢ ∃ f, ∑ e in t, f e • e = 0 ∧ ∃ x ∈ t, f x ≠ 0

Next tactic:
let f : V → R := fun x => if h : x ∈ t then if (⟨x, h⟩ : t) ∈ s then g ⟨x, h⟩ else 0 else 0
/-- If a finset has cardinality larger than the rank of a module,
then there is a nontrivial linear relation amongst its elements.
-/
-- TODO: golf this
theorem Module.exists_nontrivial_relation_of_finrank_lt_card
    [Module.Finite R V] {t : Finset V}
    (h : finrank R V < t.card) : ∃ f : V → R, ∑ e in t, f e • e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by
  classical
  have := mt FiniteDimensional.finset_card_le_finrank_of_linearIndependent (by simpa using h)
  rw [_root_.not_linearIndependent_iff] at this
  obtain ⟨s, g, sum, z, zm, nonzero⟩ := this
  -- Now we have to extend `g` to all of `t`, then to all of `V`.
  let f : V → R := fun x => if h : x ∈ t then if (⟨x, h⟩ : t) ∈ s then g ⟨x, h⟩ else 0 else 0
  -- and finally clean up the mess caused by the extension.
  

Proof state:
case intro.intro.intro.intro.intro
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.320903
inst✝ : Finite R V
t : Finset V
h : finrank R V < Finset.card t
s : Finset { x // x ∈ t }
g : { x // x ∈ t } → R
sum : ∑ i in s, g i • ↑i = 0
z : { x // x ∈ t }
zm : z ∈ s
nonzero : g z ≠ 0
f : V → R :=
  fun x => if h : x ∈ t then if { val := x, property := h } ∈ s then g { val := x, property := h } else 0 else 0
⊢ ∃ f, ∑ e in t, f e • e = 0 ∧ ∃ x ∈ t, f x ≠ 0

Next tactic:
refine' ⟨f, _, _⟩
/-- If a finset has cardinality larger than the rank of a module,
then there is a nontrivial linear relation amongst its elements.
-/
-- TODO: golf this
theorem Module.exists_nontrivial_relation_of_finrank_lt_card
    [Module.Finite R V] {t : Finset V}
    (h : finrank R V < t.card) : ∃ f : V → R, ∑ e in t, f e • e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by
  classical
  have := mt FiniteDimensional.finset_card_le_finrank_of_linearIndependent (by simpa using h)
  rw [_root_.not_linearIndependent_iff] at this
  obtain ⟨s, g, sum, z, zm, nonzero⟩ := this
  -- Now we have to extend `g` to all of `t`, then to all of `V`.
  let f : V → R := fun x => if h : x ∈ t then if (⟨x, h⟩ : t) ∈ s then g ⟨x, h⟩ else 0 else 0
  -- and finally clean up the mess caused by the extension.
  refine' ⟨f, _, _⟩
  · 

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.320903
inst✝ : Finite R V
t : Finset V
h : finrank R V < Finset.card t
s : Finset { x // x ∈ t }
g : { x // x ∈ t } → R
sum : ∑ i in s, g i • ↑i = 0
z : { x // x ∈ t }
zm : z ∈ s
nonzero : g z ≠ 0
f : V → R :=
  fun x => if h : x ∈ t then if { val := x, property := h } ∈ s then g { val := x, property := h } else 0 else 0
⊢ ∑ e in t, f e • e = 0

Next tactic:
dsimp
/-- If a finset has cardinality larger than the rank of a module,
then there is a nontrivial linear relation amongst its elements.
-/
-- TODO: golf this
theorem Module.exists_nontrivial_relation_of_finrank_lt_card
    [Module.Finite R V] {t : Finset V}
    (h : finrank R V < t.card) : ∃ f : V → R, ∑ e in t, f e • e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by
  classical
  have := mt FiniteDimensional.finset_card_le_finrank_of_linearIndependent (by simpa using h)
  rw [_root_.not_linearIndependent_iff] at this
  obtain ⟨s, g, sum, z, zm, nonzero⟩ := this
  -- Now we have to extend `g` to all of `t`, then to all of `V`.
  let f : V → R := fun x => if h : x ∈ t then if (⟨x, h⟩ : t) ∈ s then g ⟨x, h⟩ else 0 else 0
  -- and finally clean up the mess caused by the extension.
  refine' ⟨f, _, _⟩
  · dsimp
    

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.320903
inst✝ : Finite R V
t : Finset V
h : finrank R V < Finset.card t
s : Finset { x // x ∈ t }
g : { x // x ∈ t } → R
sum : ∑ i in s, g i • ↑i = 0
z : { x // x ∈ t }
zm : z ∈ s
nonzero : g z ≠ 0
f : V → R :=
  fun x => if h : x ∈ t then if { val := x, property := h } ∈ s then g { val := x, property := h } else 0 else 0
⊢ ∑ e in t,
      (if h : e ∈ t then if { val := e, property := h } ∈ s then g { val := e, property := h } else 0 else 0) • e =
    0

Next tactic:
rw [← (sum)]
/-- If a finset has cardinality larger than the rank of a module,
then there is a nontrivial linear relation amongst its elements.
-/
-- TODO: golf this
theorem Module.exists_nontrivial_relation_of_finrank_lt_card
    [Module.Finite R V] {t : Finset V}
    (h : finrank R V < t.card) : ∃ f : V → R, ∑ e in t, f e • e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by
  classical
  have := mt FiniteDimensional.finset_card_le_finrank_of_linearIndependent (by simpa using h)
  rw [_root_.not_linearIndependent_iff] at this
  obtain ⟨s, g, sum, z, zm, nonzero⟩ := this
  -- Now we have to extend `g` to all of `t`, then to all of `V`.
  let f : V → R := fun x => if h : x ∈ t then if (⟨x, h⟩ : t) ∈ s then g ⟨x, h⟩ else 0 else 0
  -- and finally clean up the mess caused by the extension.
  refine' ⟨f, _, _⟩
  · dsimp
    rw [← (sum)] -- porting note: need parens to disambiguate
    

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.320903
inst✝ : Finite R V
t : Finset V
h : finrank R V < Finset.card t
s : Finset { x // x ∈ t }
g : { x // x ∈ t } → R
sum : ∑ i in s, g i • ↑i = 0
z : { x // x ∈ t }
zm : z ∈ s
nonzero : g z ≠ 0
f : V → R :=
  fun x => if h : x ∈ t then if { val := x, property := h } ∈ s then g { val := x, property := h } else 0 else 0
⊢ ∑ e in t,
      (if h : e ∈ t then if { val := e, property := h } ∈ s then g { val := e, property := h } else 0 else 0) • e =
    ∑ i in s, g i • ↑i

Next tactic:
fapply sum_bij_ne_zero fun v hvt _ => (⟨v, hvt⟩ : { v // v ∈ t })
/-- If a finset has cardinality larger than the rank of a module,
then there is a nontrivial linear relation amongst its elements.
-/
-- TODO: golf this
theorem Module.exists_nontrivial_relation_of_finrank_lt_card
    [Module.Finite R V] {t : Finset V}
    (h : finrank R V < t.card) : ∃ f : V → R, ∑ e in t, f e • e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by
  classical
  have := mt FiniteDimensional.finset_card_le_finrank_of_linearIndependent (by simpa using h)
  rw [_root_.not_linearIndependent_iff] at this
  obtain ⟨s, g, sum, z, zm, nonzero⟩ := this
  -- Now we have to extend `g` to all of `t`, then to all of `V`.
  let f : V → R := fun x => if h : x ∈ t then if (⟨x, h⟩ : t) ∈ s then g ⟨x, h⟩ else 0 else 0
  -- and finally clean up the mess caused by the extension.
  refine' ⟨f, _, _⟩
  · dsimp
    rw [← (sum)] -- porting note: need parens to disambiguate
    fapply sum_bij_ne_zero fun v hvt _ => (⟨v, hvt⟩ : { v // v ∈ t })
    · 

Proof state:
case intro.intro.intro.intro.intro.refine'_1.hi
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.320903
inst✝ : Finite R V
t : Finset V
h : finrank R V < Finset.card t
s : Finset { x // x ∈ t }
g : { x // x ∈ t } → R
sum : ∑ i in s, g i • ↑i = 0
z : { x // x ∈ t }
zm : z ∈ s
nonzero : g z ≠ 0
f : V → R :=
  fun x => if h : x ∈ t then if { val := x, property := h } ∈ s then g { val := x, property := h } else 0 else 0
⊢ ∀ (a : V) (h₁ : a ∈ t),
    (if h : a ∈ t then if { val := a, property := h } ∈ s then g { val := a, property := h } else 0 else 0) • a ≠ 0 →
      { val := a, property := h₁ } ∈ s

Next tactic:
intro v hvt H