l3lab/ntp-mathlib huggingface dataset:
/-- Let `V` be a vector space over `K = Frac(R)`, `S / R` a ring extension
and `V'` a module over `S`. If `b`, in the intersection `V''` of `V` and `V'`,
is linear independent over `S` in `V'`, then it is linear independent over `R` in `V`.

The statement we prove is actually slightly more general:
 * it suffices that the inclusion `algebraMap R S : R → S` is nontrivial
 * the function `f' : V'' → V'` doesn't need to be injective
-/
theorem FinrankQuotientMap.linearIndependent_of_nontrivial [IsDomain R] [IsDedekindDomain R]
    (hRS : RingHom.ker (algebraMap R S) ≠ ⊤) (f : V'' →ₗ[R] V) (hf : Function.Injective f)
    (f' : V'' →ₗ[R] V') {ι : Type*} {b : ι → V''} (hb' : LinearIndependent S (f' ∘ b)) :
    LinearIndependent K (f ∘ b) := by
  contrapose! hb' with hb
  -- Informally, if we have a nontrivial linear dependence with coefficients `g` in `K`,
  -- then we can find a linear dependence with coefficients `I.Quotient.mk g'` in `R/I`,
  -- where `I = ker (algebraMap R S)`.
  -- We make use of the same principle but stay in `R` everywhere.
  simp only [linearIndependent_iff', not_forall] at hb ⊢
  

Proof state:
R : Type u
inst✝¹⁹ : CommRing R
S : Type v
inst✝¹⁸ : CommRing S
f✝ : R →+* S
p : Ideal R
P : Ideal S
inst✝¹⁷ : Algebra R S
K : Type u_1
inst✝¹⁶ : Field K
inst✝¹⁵ : Algebra R K
hRK : IsFractionRing R K
L : Type u_2
inst✝¹⁴ : Field L
inst✝¹³ : Algebra S L
inst✝¹² : IsFractionRing S L
V : Type u_3
V' : Type u_4
V'' : Type u_5
inst✝¹¹ : AddCommGroup V
inst✝¹⁰ : Module R V
inst✝⁹ : Module K V
inst✝⁸ : IsScalarTower R K V
inst✝⁷ : AddCommGroup V'
inst✝⁶ : Module R V'
inst✝⁵ : Module S V'
inst✝⁴ : IsScalarTower R S V'
inst✝³ : AddCommGroup V''
inst✝² : Module R V''
inst✝¹ : IsDomain R
inst✝ : IsDedekindDomain R
hRS : RingHom.ker (algebraMap R S) ≠ ⊤
f : V'' →ₗ[R] V
hf : Function.Injective ⇑f
f' : V'' →ₗ[R] V'
ι : Type u_6
b : ι → V''
hb : ∃ x x_1, ∃ (_ : ∑ i in x, x_1 i • (⇑f ∘ b) i = 0), ∃ x_2, ∃ (_ : x_2 ∈ x), ¬x_1 x_2 = 0
⊢ ∃ x x_1, ∃ (_ : ∑ i in x, x_1 i • (⇑f' ∘ b) i = 0), ∃ x_2, ∃ (_ : x_2 ∈ x), ¬x_1 x_2 = 0

Next tactic:
obtain ⟨s, g, eq, j', hj's, hj'g⟩ := hb
/-- Let `V` be a vector space over `K = Frac(R)`, `S / R` a ring extension
and `V'` a module over `S`. If `b`, in the intersection `V''` of `V` and `V'`,
is linear independent over `S` in `V'`, then it is linear independent over `R` in `V`.

The statement we prove is actually slightly more general:
 * it suffices that the inclusion `algebraMap R S : R → S` is nontrivial
 * the function `f' : V'' → V'` doesn't need to be injective
-/
theorem FinrankQuotientMap.linearIndependent_of_nontrivial [IsDomain R] [IsDedekindDomain R]
    (hRS : RingHom.ker (algebraMap R S) ≠ ⊤) (f : V'' →ₗ[R] V) (hf : Function.Injective f)
    (f' : V'' →ₗ[R] V') {ι : Type*} {b : ι → V''} (hb' : LinearIndependent S (f' ∘ b)) :
    LinearIndependent K (f ∘ b) := by
  contrapose! hb' with hb
  -- Informally, if we have a nontrivial linear dependence with coefficients `g` in `K`,
  -- then we can find a linear dependence with coefficients `I.Quotient.mk g'` in `R/I`,
  -- where `I = ker (algebraMap R S)`.
  -- We make use of the same principle but stay in `R` everywhere.
  simp only [linearIndependent_iff', not_forall] at hb ⊢
  obtain ⟨s, g, eq, j', hj's, hj'g⟩ := hb
  

Proof state:
case intro.intro.intro.intro.intro
R : Type u
inst✝¹⁹ : CommRing R
S : Type v
inst✝¹⁸ : CommRing S
f✝ : R →+* S
p : Ideal R
P : Ideal S
inst✝¹⁷ : Algebra R S
K : Type u_1
inst✝¹⁶ : Field K
inst✝¹⁵ : Algebra R K
hRK : IsFractionRing R K
L : Type u_2
inst✝¹⁴ : Field L
inst✝¹³ : Algebra S L
inst✝¹² : IsFractionRing S L
V : Type u_3
V' : Type u_4
V'' : Type u_5
inst✝¹¹ : AddCommGroup V
inst✝¹⁰ : Module R V
inst✝⁹ : Module K V
inst✝⁸ : IsScalarTower R K V
inst✝⁷ : AddCommGroup V'
inst✝⁶ : Module R V'
inst✝⁵ : Module S V'
inst✝⁴ : IsScalarTower R S V'
inst✝³ : AddCommGroup V''
inst✝² : Module R V''
inst✝¹ : IsDomain R
inst✝ : IsDedekindDomain R
hRS : RingHom.ker (algebraMap R S) ≠ ⊤
f : V'' →ₗ[R] V
hf : Function.Injective ⇑f
f' : V'' →ₗ[R] V'
ι : Type u_6
b : ι → V''
s : Finset ι
g : ι → K
eq : ∑ i in s, g i • (⇑f ∘ b) i = 0
j' : ι
hj's : j' ∈ s
hj'g : ¬g j' = 0
⊢ ∃ x x_1, ∃ (_ : ∑ i in x, x_1 i • (⇑f' ∘ b) i = 0), ∃ x_2, ∃ (_ : x_2 ∈ x), ¬x_1 x_2 = 0

Next tactic:
use s
/-- Let `V` be a vector space over `K = Frac(R)`, `S / R` a ring extension
and `V'` a module over `S`. If `b`, in the intersection `V''` of `V` and `V'`,
is linear independent over `S` in `V'`, then it is linear independent over `R` in `V`.

The statement we prove is actually slightly more general:
 * it suffices that the inclusion `algebraMap R S : R → S` is nontrivial
 * the function `f' : V'' → V'` doesn't need to be injective
-/
theorem FinrankQuotientMap.linearIndependent_of_nontrivial [IsDomain R] [IsDedekindDomain R]
    (hRS : RingHom.ker (algebraMap R S) ≠ ⊤) (f : V'' →ₗ[R] V) (hf : Function.Injective f)
    (f' : V'' →ₗ[R] V') {ι : Type*} {b : ι → V''} (hb' : LinearIndependent S (f' ∘ b)) :
    LinearIndependent K (f ∘ b) := by
  contrapose! hb' with hb
  -- Informally, if we have a nontrivial linear dependence with coefficients `g` in `K`,
  -- then we can find a linear dependence with coefficients `I.Quotient.mk g'` in `R/I`,
  -- where `I = ker (algebraMap R S)`.
  -- We make use of the same principle but stay in `R` everywhere.
  simp only [linearIndependent_iff', not_forall] at hb ⊢
  obtain ⟨s, g, eq, j', hj's, hj'g⟩ := hb
  use s
  

Proof state:
case h
R : Type u
inst✝¹⁹ : CommRing R
S : Type v
inst✝¹⁸ : CommRing S
f✝ : R →+* S
p : Ideal R
P : Ideal S
inst✝¹⁷ : Algebra R S
K : Type u_1
inst✝¹⁶ : Field K
inst✝¹⁵ : Algebra R K
hRK : IsFractionRing R K
L : Type u_2
inst✝¹⁴ : Field L
inst✝¹³ : Algebra S L
inst✝¹² : IsFractionRing S L
V : Type u_3
V' : Type u_4
V'' : Type u_5
inst✝¹¹ : AddCommGroup V
inst✝¹⁰ : Module R V
inst✝⁹ : Module K V
inst✝⁸ : IsScalarTower R K V
inst✝⁷ : AddCommGroup V'
inst✝⁶ : Module R V'
inst✝⁵ : Module S V'
inst✝⁴ : IsScalarTower R S V'
inst✝³ : AddCommGroup V''
inst✝² : Module R V''
inst✝¹ : IsDomain R
inst✝ : IsDedekindDomain R
hRS : RingHom.ker (algebraMap R S) ≠ ⊤
f : V'' →ₗ[R] V
hf : Function.Injective ⇑f
f' : V'' →ₗ[R] V'
ι : Type u_6
b : ι → V''
s : Finset ι
g : ι → K
eq : ∑ i in s, g i • (⇑f ∘ b) i = 0
j' : ι
hj's : j' ∈ s
hj'g : ¬g j' = 0
⊢ ∃ x, ∃ (_ : ∑ i in s, x i • (⇑f' ∘ b) i = 0), ∃ x_1, ∃ (_ : x_1 ∈ s), ¬x x_1 = 0

Next tactic:
obtain ⟨a, hag, j, hjs, hgI⟩ := Ideal.exist_integer_multiples_not_mem hRS s g hj's hj'g
/-- Let `V` be a vector space over `K = Frac(R)`, `S / R` a ring extension
and `V'` a module over `S`. If `b`, in the intersection `V''` of `V` and `V'`,
is linear independent over `S` in `V'`, then it is linear independent over `R` in `V`.

The statement we prove is actually slightly more general:
 * it suffices that the inclusion `algebraMap R S : R → S` is nontrivial
 * the function `f' : V'' → V'` doesn't need to be injective
-/
theorem FinrankQuotientMap.linearIndependent_of_nontrivial [IsDomain R] [IsDedekindDomain R]
    (hRS : RingHom.ker (algebraMap R S) ≠ ⊤) (f : V'' →ₗ[R] V) (hf : Function.Injective f)
    (f' : V'' →ₗ[R] V') {ι : Type*} {b : ι → V''} (hb' : LinearIndependent S (f' ∘ b)) :
    LinearIndependent K (f ∘ b) := by
  contrapose! hb' with hb
  -- Informally, if we have a nontrivial linear dependence with coefficients `g` in `K`,
  -- then we can find a linear dependence with coefficients `I.Quotient.mk g'` in `R/I`,
  -- where `I = ker (algebraMap R S)`.
  -- We make use of the same principle but stay in `R` everywhere.
  simp only [linearIndependent_iff', not_forall] at hb ⊢
  obtain ⟨s, g, eq, j', hj's, hj'g⟩ := hb
  use s
  obtain ⟨a, hag, j, hjs, hgI⟩ := Ideal.exist_integer_multiples_not_mem hRS s g hj's hj'g
  

Proof state:
case h.intro.intro.intro.intro
R : Type u
inst✝¹⁹ : CommRing R
S : Type v
inst✝¹⁸ : CommRing S
f✝ : R →+* S
p : Ideal R
P : Ideal S
inst✝¹⁷ : Algebra R S
K : Type u_1
inst✝¹⁶ : Field K
inst✝¹⁵ : Algebra R K
hRK : IsFractionRing R K
L : Type u_2
inst✝¹⁴ : Field L
inst✝¹³ : Algebra S L
inst✝¹² : IsFractionRing S L
V : Type u_3
V' : Type u_4
V'' : Type u_5
inst✝¹¹ : AddCommGroup V
inst✝¹⁰ : Module R V
inst✝⁹ : Module K V
inst✝⁸ : IsScalarTower R K V
inst✝⁷ : AddCommGroup V'
inst✝⁶ : Module R V'
inst✝⁵ : Module S V'
inst✝⁴ : IsScalarTower R S V'
inst✝³ : AddCommGroup V''
inst✝² : Module R V''
inst✝¹ : IsDomain R
inst✝ : IsDedekindDomain R
hRS : RingHom.ker (algebraMap R S) ≠ ⊤
f : V'' →ₗ[R] V
hf : Function.Injective ⇑f
f' : V'' →ₗ[R] V'
ι : Type u_6
b : ι → V''
s : Finset ι
g : ι → K
eq : ∑ i in s, g i • (⇑f ∘ b) i = 0
j' : ι
hj's : j' ∈ s
hj'g : ¬g j' = 0
a : K
hag : ∀ i ∈ s, IsLocalization.IsInteger R (a * g i)
j : ι
hjs : j ∈ s
hgI : a * g j ∉ ↑(RingHom.ker (algebraMap R S))
⊢ ∃ x, ∃ (_ : ∑ i in s, x i • (⇑f' ∘ b) i = 0), ∃ x_1, ∃ (_ : x_1 ∈ s), ¬x x_1 = 0

Next tactic:
choose g'' hg'' using hag
/-- Let `V` be a vector space over `K = Frac(R)`, `S / R` a ring extension
and `V'` a module over `S`. If `b`, in the intersection `V''` of `V` and `V'`,
is linear independent over `S` in `V'`, then it is linear independent over `R` in `V`.

The statement we prove is actually slightly more general:
 * it suffices that the inclusion `algebraMap R S : R → S` is nontrivial
 * the function `f' : V'' → V'` doesn't need to be injective
-/
theorem FinrankQuotientMap.linearIndependent_of_nontrivial [IsDomain R] [IsDedekindDomain R]
    (hRS : RingHom.ker (algebraMap R S) ≠ ⊤) (f : V'' →ₗ[R] V) (hf : Function.Injective f)
    (f' : V'' →ₗ[R] V') {ι : Type*} {b : ι → V''} (hb' : LinearIndependent S (f' ∘ b)) :
    LinearIndependent K (f ∘ b) := by
  contrapose! hb' with hb
  -- Informally, if we have a nontrivial linear dependence with coefficients `g` in `K`,
  -- then we can find a linear dependence with coefficients `I.Quotient.mk g'` in `R/I`,
  -- where `I = ker (algebraMap R S)`.
  -- We make use of the same principle but stay in `R` everywhere.
  simp only [linearIndependent_iff', not_forall] at hb ⊢
  obtain ⟨s, g, eq, j', hj's, hj'g⟩ := hb
  use s
  obtain ⟨a, hag, j, hjs, hgI⟩ := Ideal.exist_integer_multiples_not_mem hRS s g hj's hj'g
  choose g'' hg'' using hag
  

Proof state:
case h.intro.intro.intro.intro
R : Type u
inst✝¹⁹ : CommRing R
S : Type v
inst✝¹⁸ : CommRing S
f✝ : R →+* S
p : Ideal R
P : Ideal S
inst✝¹⁷ : Algebra R S
K : Type u_1
inst✝¹⁶ : Field K
inst✝¹⁵ : Algebra R K
hRK : IsFractionRing R K
L : Type u_2
inst✝¹⁴ : Field L
inst✝¹³ : Algebra S L
inst✝¹² : IsFractionRing S L
V : Type u_3
V' : Type u_4
V'' : Type u_5
inst✝¹¹ : AddCommGroup V
inst✝¹⁰ : Module R V
inst✝⁹ : Module K V
inst✝⁸ : IsScalarTower R K V
inst✝⁷ : AddCommGroup V'
inst✝⁶ : Module R V'
inst✝⁵ : Module S V'
inst✝⁴ : IsScalarTower R S V'
inst✝³ : AddCommGroup V''
inst✝² : Module R V''
inst✝¹ : IsDomain R
inst✝ : IsDedekindDomain R
hRS : RingHom.ker (algebraMap R S) ≠ ⊤
f : V'' →ₗ[R] V
hf : Function.Injective ⇑f
f' : V'' →ₗ[R] V'
ι : Type u_6
b : ι → V''
s : Finset ι
g : ι → K
eq : ∑ i in s, g i • (⇑f ∘ b) i = 0
j' : ι
hj's : j' ∈ s
hj'g : ¬g j' = 0
a : K
j : ι
hjs : j ∈ s
hgI : a * g j ∉ ↑(RingHom.ker (algebraMap R S))
g'' : (i : ι) → i ∈ s → R
hg'' : ∀ (i : ι) (a_1 : i ∈ s), (algebraMap R K) (g'' i a_1) = a * g i
⊢ ∃ x, ∃ (_ : ∑ i in s, x i • (⇑f' ∘ b) i = 0), ∃ x_1, ∃ (_ : x_1 ∈ s), ¬x x_1 = 0

Next tactic:
letI := Classical.propDecidable
/-- Let `V` be a vector space over `K = Frac(R)`, `S / R` a ring extension
and `V'` a module over `S`. If `b`, in the intersection `V''` of `V` and `V'`,
is linear independent over `S` in `V'`, then it is linear independent over `R` in `V`.

The statement we prove is actually slightly more general:
 * it suffices that the inclusion `algebraMap R S : R → S` is nontrivial
 * the function `f' : V'' → V'` doesn't need to be injective
-/
theorem FinrankQuotientMap.linearIndependent_of_nontrivial [IsDomain R] [IsDedekindDomain R]
    (hRS : RingHom.ker (algebraMap R S) ≠ ⊤) (f : V'' →ₗ[R] V) (hf : Function.Injective f)
    (f' : V'' →ₗ[R] V') {ι : Type*} {b : ι → V''} (hb' : LinearIndependent S (f' ∘ b)) :
    LinearIndependent K (f ∘ b) := by
  contrapose! hb' with hb
  -- Informally, if we have a nontrivial linear dependence with coefficients `g` in `K`,
  -- then we can find a linear dependence with coefficients `I.Quotient.mk g'` in `R/I`,
  -- where `I = ker (algebraMap R S)`.
  -- We make use of the same principle but stay in `R` everywhere.
  simp only [linearIndependent_iff', not_forall] at hb ⊢
  obtain ⟨s, g, eq, j', hj's, hj'g⟩ := hb
  use s
  obtain ⟨a, hag, j, hjs, hgI⟩ := Ideal.exist_integer_multiples_not_mem hRS s g hj's hj'g
  choose g'' hg'' using hag
  letI := Classical.propDecidable
  

Proof state:
case h.intro.intro.intro.intro
R : Type u
inst✝¹⁹ : CommRing R
S : Type v
inst✝¹⁸ : CommRing S
f✝ : R →+* S
p : Ideal R
P : Ideal S
inst✝¹⁷ : Algebra R S
K : Type u_1
inst✝¹⁶ : Field K
inst✝¹⁵ : Algebra R K
hRK : IsFractionRing R K
L : Type u_2
inst✝¹⁴ : Field L
inst✝¹³ : Algebra S L
inst✝¹² : IsFractionRing S L
V : Type u_3
V' : Type u_4
V'' : Type u_5
inst✝¹¹ : AddCommGroup V
inst✝¹⁰ : Module R V
inst✝⁹ : Module K V
inst✝⁸ : IsScalarTower R K V
inst✝⁷ : AddCommGroup V'
inst✝⁶ : Module R V'
inst✝⁵ : Module S V'
inst✝⁴ : IsScalarTower R S V'
inst✝³ : AddCommGroup V''
inst✝² : Module R V''
inst✝¹ : IsDomain R
inst✝ : IsDedekindDomain R
hRS : RingHom.ker (algebraMap R S) ≠ ⊤
f : V'' →ₗ[R] V
hf : Function.Injective ⇑f
f' : V'' →ₗ[R] V'
ι : Type u_6
b : ι → V''
s : Finset ι
g : ι → K
eq : ∑ i in s, g i • (⇑f ∘ b) i = 0
j' : ι
hj's : j' ∈ s
hj'g : ¬g j' = 0
a : K
j : ι
hjs : j ∈ s
hgI : a * g j ∉ ↑(RingHom.ker (algebraMap R S))
g'' : (i : ι) → i ∈ s → R
hg'' : ∀ (i : ι) (a_1 : i ∈ s), (algebraMap R K) (g'' i a_1) = a * g i
this : (a : Prop) → Decidable a := Classical.propDecidable
⊢ ∃ x, ∃ (_ : ∑ i in s, x i • (⇑f' ∘ b) i = 0), ∃ x_1, ∃ (_ : x_1 ∈ s), ¬x x_1 = 0

Next tactic:
let g' i := if h : i ∈ s then g'' i h else 0
/-- Let `V` be a vector space over `K = Frac(R)`, `S / R` a ring extension
and `V'` a module over `S`. If `b`, in the intersection `V''` of `V` and `V'`,
is linear independent over `S` in `V'`, then it is linear independent over `R` in `V`.

The statement we prove is actually slightly more general:
 * it suffices that the inclusion `algebraMap R S : R → S` is nontrivial
 * the function `f' : V'' → V'` doesn't need to be injective
-/
theorem FinrankQuotientMap.linearIndependent_of_nontrivial [IsDomain R] [IsDedekindDomain R]
    (hRS : RingHom.ker (algebraMap R S) ≠ ⊤) (f : V'' →ₗ[R] V) (hf : Function.Injective f)
    (f' : V'' →ₗ[R] V') {ι : Type*} {b : ι → V''} (hb' : LinearIndependent S (f' ∘ b)) :
    LinearIndependent K (f ∘ b) := by
  contrapose! hb' with hb
  -- Informally, if we have a nontrivial linear dependence with coefficients `g` in `K`,
  -- then we can find a linear dependence with coefficients `I.Quotient.mk g'` in `R/I`,
  -- where `I = ker (algebraMap R S)`.
  -- We make use of the same principle but stay in `R` everywhere.
  simp only [linearIndependent_iff', not_forall] at hb ⊢
  obtain ⟨s, g, eq, j', hj's, hj'g⟩ := hb
  use s
  obtain ⟨a, hag, j, hjs, hgI⟩ := Ideal.exist_integer_multiples_not_mem hRS s g hj's hj'g
  choose g'' hg'' using hag
  letI := Classical.propDecidable
  let g' i := if h : i ∈ s then g'' i h else 0
  

Proof state:
case h.intro.intro.intro.intro
R : Type u
inst✝¹⁹ : CommRing R
S : Type v
inst✝¹⁸ : CommRing S
f✝ : R →+* S
p : Ideal R
P : Ideal S
inst✝¹⁷ : Algebra R S
K : Type u_1
inst✝¹⁶ : Field K
inst✝¹⁵ : Algebra R K
hRK : IsFractionRing R K
L : Type u_2
inst✝¹⁴ : Field L
inst✝¹³ : Algebra S L
inst✝¹² : IsFractionRing S L
V : Type u_3
V' : Type u_4
V'' : Type u_5
inst✝¹¹ : AddCommGroup V
inst✝¹⁰ : Module R V
inst✝⁹ : Module K V
inst✝⁸ : IsScalarTower R K V
inst✝⁷ : AddCommGroup V'
inst✝⁶ : Module R V'
inst✝⁵ : Module S V'
inst✝⁴ : IsScalarTower R S V'
inst✝³ : AddCommGroup V''
inst✝² : Module R V''
inst✝¹ : IsDomain R
inst✝ : IsDedekindDomain R
hRS : RingHom.ker (algebraMap R S) ≠ ⊤
f : V'' →ₗ[R] V
hf : Function.Injective ⇑f
f' : V'' →ₗ[R] V'
ι : Type u_6
b : ι → V''
s : Finset ι
g : ι → K
eq : ∑ i in s, g i • (⇑f ∘ b) i = 0
j' : ι
hj's : j' ∈ s
hj'g : ¬g j' = 0
a : K
j : ι
hjs : j ∈ s
hgI : a * g j ∉ ↑(RingHom.ker (algebraMap R S))
g'' : (i : ι) → i ∈ s → R
hg'' : ∀ (i : ι) (a_1 : i ∈ s), (algebraMap R K) (g'' i a_1) = a * g i
this : (a : Prop) → Decidable a := Classical.propDecidable
g' : ι → R := fun i => if h : i ∈ s then g'' i h else 0
⊢ ∃ x, ∃ (_ : ∑ i in s, x i • (⇑f' ∘ b) i = 0), ∃ x_1, ∃ (_ : x_1 ∈ s), ¬x x_1 = 0

Next tactic:
have hg' : ∀ i ∈ s, algebraMap _ _ (g' i) = a * g i := by
    intro i hi; exact (congr_arg _ (dif_pos hi)).trans (hg'' i hi)
/-- Let `V` be a vector space over `K = Frac(R)`, `S / R` a ring extension
and `V'` a module over `S`. If `b`, in the intersection `V''` of `V` and `V'`,
is linear independent over `S` in `V'`, then it is linear independent over `R` in `V`.

The statement we prove is actually slightly more general:
 * it suffices that the inclusion `algebraMap R S : R → S` is nontrivial
 * the function `f' : V'' → V'` doesn't need to be injective
-/
theorem FinrankQuotientMap.linearIndependent_of_nontrivial [IsDomain R] [IsDedekindDomain R]
    (hRS : RingHom.ker (algebraMap R S) ≠ ⊤) (f : V'' →ₗ[R] V) (hf : Function.Injective f)
    (f' : V'' →ₗ[R] V') {ι : Type*} {b : ι → V''} (hb' : LinearIndependent S (f' ∘ b)) :
    LinearIndependent K (f ∘ b) := by
  contrapose! hb' with hb
  -- Informally, if we have a nontrivial linear dependence with coefficients `g` in `K`,
  -- then we can find a linear dependence with coefficients `I.Quotient.mk g'` in `R/I`,
  -- where `I = ker (algebraMap R S)`.
  -- We make use of the same principle but stay in `R` everywhere.
  simp only [linearIndependent_iff', not_forall] at hb ⊢
  obtain ⟨s, g, eq, j', hj's, hj'g⟩ := hb
  use s
  obtain ⟨a, hag, j, hjs, hgI⟩ := Ideal.exist_integer_multiples_not_mem hRS s g hj's hj'g
  choose g'' hg'' using hag
  letI := Classical.propDecidable
  let g' i := if h : i ∈ s then g'' i h else 0
  have hg' : ∀ i ∈ s, algebraMap _ _ (g' i) = a * g i := by
    

Proof state:
R : Type u
inst✝¹⁹ : CommRing R
S : Type v
inst✝¹⁸ : CommRing S
f✝ : R →+* S
p : Ideal R
P : Ideal S
inst✝¹⁷ : Algebra R S
K : Type u_1
inst✝¹⁶ : Field K
inst✝¹⁵ : Algebra R K
hRK : IsFractionRing R K
L : Type u_2
inst✝¹⁴ : Field L
inst✝¹³ : Algebra S L
inst✝¹² : IsFractionRing S L
V : Type u_3
V' : Type u_4
V'' : Type u_5
inst✝¹¹ : AddCommGroup V
inst✝¹⁰ : Module R V
inst✝⁹ : Module K V
inst✝⁸ : IsScalarTower R K V
inst✝⁷ : AddCommGroup V'
inst✝⁶ : Module R V'
inst✝⁵ : Module S V'
inst✝⁴ : IsScalarTower R S V'
inst✝³ : AddCommGroup V''
inst✝² : Module R V''
inst✝¹ : IsDomain R
inst✝ : IsDedekindDomain R
hRS : RingHom.ker (algebraMap R S) ≠ ⊤
f : V'' →ₗ[R] V
hf : Function.Injective ⇑f
f' : V'' →ₗ[R] V'
ι : Type u_6
b : ι → V''
s : Finset ι
g : ι → K
eq : ∑ i in s, g i • (⇑f ∘ b) i = 0
j' : ι
hj's : j' ∈ s
hj'g : ¬g j' = 0
a : K
j : ι
hjs : j ∈ s
hgI : a * g j ∉ ↑(RingHom.ker (algebraMap R S))
g'' : (i : ι) → i ∈ s → R
hg'' : ∀ (i : ι) (a_1 : i ∈ s), (algebraMap R K) (g'' i a_1) = a * g i
this : (a : Prop) → Decidable a := Classical.propDecidable
g' : ι → R := fun i => if h : i ∈ s then g'' i h else 0
⊢ ∀ i ∈ s, (algebraMap R K) (g' i) = a * g i

Next tactic:
intro i hi
/-- Let `V` be a vector space over `K = Frac(R)`, `S / R` a ring extension
and `V'` a module over `S`. If `b`, in the intersection `V''` of `V` and `V'`,
is linear independent over `S` in `V'`, then it is linear independent over `R` in `V`.

The statement we prove is actually slightly more general:
 * it suffices that the inclusion `algebraMap R S : R → S` is nontrivial
 * the function `f' : V'' → V'` doesn't need to be injective
-/
theorem FinrankQuotientMap.linearIndependent_of_nontrivial [IsDomain R] [IsDedekindDomain R]
    (hRS : RingHom.ker (algebraMap R S) ≠ ⊤) (f : V'' →ₗ[R] V) (hf : Function.Injective f)
    (f' : V'' →ₗ[R] V') {ι : Type*} {b : ι → V''} (hb' : LinearIndependent S (f' ∘ b)) :
    LinearIndependent K (f ∘ b) := by
  contrapose! hb' with hb
  -- Informally, if we have a nontrivial linear dependence with coefficients `g` in `K`,
  -- then we can find a linear dependence with coefficients `I.Quotient.mk g'` in `R/I`,
  -- where `I = ker (algebraMap R S)`.
  -- We make use of the same principle but stay in `R` everywhere.
  simp only [linearIndependent_iff', not_forall] at hb ⊢
  obtain ⟨s, g, eq, j', hj's, hj'g⟩ := hb
  use s
  obtain ⟨a, hag, j, hjs, hgI⟩ := Ideal.exist_integer_multiples_not_mem hRS s g hj's hj'g
  choose g'' hg'' using hag
  letI := Classical.propDecidable
  let g' i := if h : i ∈ s then g'' i h else 0
  have hg' : ∀ i ∈ s, algebraMap _ _ (g' i) = a * g i := by
    intro i hi; 

Proof state:
R : Type u
inst✝¹⁹ : CommRing R
S : Type v
inst✝¹⁸ : CommRing S
f✝ : R →+* S
p : Ideal R
P : Ideal S
inst✝¹⁷ : Algebra R S
K : Type u_1
inst✝¹⁶ : Field K
inst✝¹⁵ : Algebra R K
hRK : IsFractionRing R K
L : Type u_2
inst✝¹⁴ : Field L
inst✝¹³ : Algebra S L
inst✝¹² : IsFractionRing S L
V : Type u_3
V' : Type u_4
V'' : Type u_5
inst✝¹¹ : AddCommGroup V
inst✝¹⁰ : Module R V
inst✝⁹ : Module K V
inst✝⁸ : IsScalarTower R K V
inst✝⁷ : AddCommGroup V'
inst✝⁶ : Module R V'
inst✝⁵ : Module S V'
inst✝⁴ : IsScalarTower R S V'
inst✝³ : AddCommGroup V''
inst✝² : Module R V''
inst✝¹ : IsDomain R
inst✝ : IsDedekindDomain R
hRS : RingHom.ker (algebraMap R S) ≠ ⊤
f : V'' →ₗ[R] V
hf : Function.Injective ⇑f
f' : V'' →ₗ[R] V'
ι : Type u_6
b : ι → V''
s : Finset ι
g : ι → K
eq : ∑ i in s, g i • (⇑f ∘ b) i = 0
j' : ι
hj's : j' ∈ s
hj'g : ¬g j' = 0
a : K
j : ι
hjs : j ∈ s
hgI : a * g j ∉ ↑(RingHom.ker (algebraMap R S))
g'' : (i : ι) → i ∈ s → R
hg'' : ∀ (i : ι) (a_1 : i ∈ s), (algebraMap R K) (g'' i a_1) = a * g i
this : (a : Prop) → Decidable a := Classical.propDecidable
g' : ι → R := fun i => if h : i ∈ s then g'' i h else 0
i : ι
hi : i ∈ s
⊢ (algebraMap R K) (g' i) = a * g i

Next tactic:
exact (congr_arg _ (dif_pos hi)).trans (hg'' i hi)