l3lab/ntp-mathlib huggingface dataset:
/-- An `R`-module `M` is flat iff for all ideals `I` of `R`, the tensor product of the
inclusion `I → R` and the identity `M → M` is injective. See `iff_rTensor_injective` to
restrict to finitely generated ideals `I`. --/
theorem iff_rTensor_injective' :
    Flat R M ↔ ∀ I : Ideal R, Injective (rTensor M I.subtype) := by
  rewrite [Flat.iff_rTensor_injective]
  refine ⟨fun h I => ?_, fun h I _ => h I⟩
  

Proof state:
R : Type u
inst✝² : CommRing R
M : Type v
inst✝¹ : AddCommGroup M
inst✝ : Module R M
h : ∀ ⦃I : Ideal R⦄, Ideal.FG I → Injective ⇑(rTensor M (Submodule.subtype I))
I : Ideal R
⊢ Injective ⇑(rTensor M (Submodule.subtype I))

Next tactic:
letI : AddCommGroup (I ⊗[R] M) := inferInstance
/-- An `R`-module `M` is flat iff for all ideals `I` of `R`, the tensor product of the
inclusion `I → R` and the identity `M → M` is injective. See `iff_rTensor_injective` to
restrict to finitely generated ideals `I`. --/
theorem iff_rTensor_injective' :
    Flat R M ↔ ∀ I : Ideal R, Injective (rTensor M I.subtype) := by
  rewrite [Flat.iff_rTensor_injective]
  refine ⟨fun h I => ?_, fun h I _ => h I⟩
  letI : AddCommGroup (I ⊗[R] M) := inferInstance -- Type class reminder
  

Proof state:
R : Type u
inst✝² : CommRing R
M : Type v
inst✝¹ : AddCommGroup M
inst✝ : Module R M
h : ∀ ⦃I : Ideal R⦄, Ideal.FG I → Injective ⇑(rTensor M (Submodule.subtype I))
I : Ideal R
this : AddCommGroup (↥I ⊗[R] M) := inferInstance
⊢ Injective ⇑(rTensor M (Submodule.subtype I))

Next tactic:
rewrite [injective_iff_map_eq_zero]
/-- An `R`-module `M` is flat iff for all ideals `I` of `R`, the tensor product of the
inclusion `I → R` and the identity `M → M` is injective. See `iff_rTensor_injective` to
restrict to finitely generated ideals `I`. --/
theorem iff_rTensor_injective' :
    Flat R M ↔ ∀ I : Ideal R, Injective (rTensor M I.subtype) := by
  rewrite [Flat.iff_rTensor_injective]
  refine ⟨fun h I => ?_, fun h I _ => h I⟩
  letI : AddCommGroup (I ⊗[R] M) := inferInstance -- Type class reminder
  rewrite [injective_iff_map_eq_zero]
  

Proof state:
R : Type u
inst✝² : CommRing R
M : Type v
inst✝¹ : AddCommGroup M
inst✝ : Module R M
h : ∀ ⦃I : Ideal R⦄, Ideal.FG I → Injective ⇑(rTensor M (Submodule.subtype I))
I : Ideal R
this : AddCommGroup (↥I ⊗[R] M) := inferInstance
⊢ ∀ (a : ↥I ⊗[R] M), (rTensor M (Submodule.subtype I)) a = 0 → a = 0

Next tactic:
intro x hx₀
/-- An `R`-module `M` is flat iff for all ideals `I` of `R`, the tensor product of the
inclusion `I → R` and the identity `M → M` is injective. See `iff_rTensor_injective` to
restrict to finitely generated ideals `I`. --/
theorem iff_rTensor_injective' :
    Flat R M ↔ ∀ I : Ideal R, Injective (rTensor M I.subtype) := by
  rewrite [Flat.iff_rTensor_injective]
  refine ⟨fun h I => ?_, fun h I _ => h I⟩
  letI : AddCommGroup (I ⊗[R] M) := inferInstance -- Type class reminder
  rewrite [injective_iff_map_eq_zero]
  intro x hx₀
  

Proof state:
R : Type u
inst✝² : CommRing R
M : Type v
inst✝¹ : AddCommGroup M
inst✝ : Module R M
h : ∀ ⦃I : Ideal R⦄, Ideal.FG I → Injective ⇑(rTensor M (Submodule.subtype I))
I : Ideal R
this : AddCommGroup (↥I ⊗[R] M) := inferInstance
x : ↥I ⊗[R] M
hx₀ : (rTensor M (Submodule.subtype I)) x = 0
⊢ x = 0

Next tactic:
obtain ⟨J, hfg, hle, y, rfl⟩ := exists_fg_le_eq_rTensor_inclusion x
/-- An `R`-module `M` is flat iff for all ideals `I` of `R`, the tensor product of the
inclusion `I → R` and the identity `M → M` is injective. See `iff_rTensor_injective` to
restrict to finitely generated ideals `I`. --/
theorem iff_rTensor_injective' :
    Flat R M ↔ ∀ I : Ideal R, Injective (rTensor M I.subtype) := by
  rewrite [Flat.iff_rTensor_injective]
  refine ⟨fun h I => ?_, fun h I _ => h I⟩
  letI : AddCommGroup (I ⊗[R] M) := inferInstance -- Type class reminder
  rewrite [injective_iff_map_eq_zero]
  intro x hx₀
  obtain ⟨J, hfg, hle, y, rfl⟩ := exists_fg_le_eq_rTensor_inclusion x
  

Proof state:
case intro.intro.intro.intro
R : Type u
inst✝² : CommRing R
M : Type v
inst✝¹ : AddCommGroup M
inst✝ : Module R M
h : ∀ ⦃I : Ideal R⦄, Ideal.FG I → Injective ⇑(rTensor M (Submodule.subtype I))
I : Ideal R
this : AddCommGroup (↥I ⊗[R] M) := inferInstance
J : Submodule R R
hfg : FG J
hle : J ≤ I
y : ↥J ⊗[R] M
hx₀ : (rTensor M (Submodule.subtype I)) ((rTensor M (inclusion hle)) y) = 0
⊢ (rTensor M (inclusion hle)) y = 0

Next tactic:
rewrite [← rTensor_comp_apply] at hx₀
/-- An `R`-module `M` is flat iff for all ideals `I` of `R`, the tensor product of the
inclusion `I → R` and the identity `M → M` is injective. See `iff_rTensor_injective` to
restrict to finitely generated ideals `I`. --/
theorem iff_rTensor_injective' :
    Flat R M ↔ ∀ I : Ideal R, Injective (rTensor M I.subtype) := by
  rewrite [Flat.iff_rTensor_injective]
  refine ⟨fun h I => ?_, fun h I _ => h I⟩
  letI : AddCommGroup (I ⊗[R] M) := inferInstance -- Type class reminder
  rewrite [injective_iff_map_eq_zero]
  intro x hx₀
  obtain ⟨J, hfg, hle, y, rfl⟩ := exists_fg_le_eq_rTensor_inclusion x
  rewrite [← rTensor_comp_apply] at hx₀
  

Proof state:
case intro.intro.intro.intro
R : Type u
inst✝² : CommRing R
M : Type v
inst✝¹ : AddCommGroup M
inst✝ : Module R M
h : ∀ ⦃I : Ideal R⦄, Ideal.FG I → Injective ⇑(rTensor M (Submodule.subtype I))
I : Ideal R
this : AddCommGroup (↥I ⊗[R] M) := inferInstance
J : Submodule R R
hfg : FG J
hle : J ≤ I
y : ↥J ⊗[R] M
hx₀ : (rTensor M (Submodule.subtype I ∘ₗ inclusion hle)) y = 0
⊢ (rTensor M (inclusion hle)) y = 0

Next tactic:
letI : AddCommGroup (J ⊗[R] M) := inferInstance
/-- An `R`-module `M` is flat iff for all ideals `I` of `R`, the tensor product of the
inclusion `I → R` and the identity `M → M` is injective. See `iff_rTensor_injective` to
restrict to finitely generated ideals `I`. --/
theorem iff_rTensor_injective' :
    Flat R M ↔ ∀ I : Ideal R, Injective (rTensor M I.subtype) := by
  rewrite [Flat.iff_rTensor_injective]
  refine ⟨fun h I => ?_, fun h I _ => h I⟩
  letI : AddCommGroup (I ⊗[R] M) := inferInstance -- Type class reminder
  rewrite [injective_iff_map_eq_zero]
  intro x hx₀
  obtain ⟨J, hfg, hle, y, rfl⟩ := exists_fg_le_eq_rTensor_inclusion x
  rewrite [← rTensor_comp_apply] at hx₀
  letI : AddCommGroup (J ⊗[R] M) := inferInstance -- Type class reminder
  

Proof state:
case intro.intro.intro.intro
R : Type u
inst✝² : CommRing R
M : Type v
inst✝¹ : AddCommGroup M
inst✝ : Module R M
h : ∀ ⦃I : Ideal R⦄, Ideal.FG I → Injective ⇑(rTensor M (Submodule.subtype I))
I : Ideal R
this✝ : AddCommGroup (↥I ⊗[R] M) := inferInstance
J : Submodule R R
hfg : FG J
hle : J ≤ I
y : ↥J ⊗[R] M
hx₀ : (rTensor M (Submodule.subtype I ∘ₗ inclusion hle)) y = 0
this : AddCommGroup (↥J ⊗[R] M) := inferInstance
⊢ (rTensor M (inclusion hle)) y = 0

Next tactic:
rw [(injective_iff_map_eq_zero _).mp (h hfg) y hx₀, _root_.map_zero]
/-- A retract of a flat `R`-module is flat. -/
lemma of_retract [f : Flat R M] (i : N →ₗ[R] M) (r : M →ₗ[R] N) (h : r.comp i = LinearMap.id) :
    Flat R N := by
  

Proof state:
R : Type u
inst✝⁴ : CommRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type w
inst✝¹ : AddCommGroup N
inst✝ : Module R N
f : Flat R M
i : N →ₗ[R] M
r : M →ₗ[R] N
h : r ∘ₗ i = LinearMap.id
⊢ Flat R N

Next tactic:
rw [iff_rTensor_injective] at *
/-- A retract of a flat `R`-module is flat. -/
lemma of_retract [f : Flat R M] (i : N →ₗ[R] M) (r : M →ₗ[R] N) (h : r.comp i = LinearMap.id) :
    Flat R N := by
  rw [iff_rTensor_injective] at *
  

Proof state:
R : Type u
inst✝⁴ : CommRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type w
inst✝¹ : AddCommGroup N
inst✝ : Module R N
f : ∀ ⦃I : Ideal R⦄, Ideal.FG I → Injective ⇑(rTensor M (Submodule.subtype I))
i : N →ₗ[R] M
r : M →ₗ[R] N
h : r ∘ₗ i = LinearMap.id
⊢ ∀ ⦃I : Ideal R⦄, Ideal.FG I → Injective ⇑(rTensor N (Submodule.subtype I))

Next tactic:
intro I hI
/-- A retract of a flat `R`-module is flat. -/
lemma of_retract [f : Flat R M] (i : N →ₗ[R] M) (r : M →ₗ[R] N) (h : r.comp i = LinearMap.id) :
    Flat R N := by
  rw [iff_rTensor_injective] at *
  intro I hI
  

Proof state:
R : Type u
inst✝⁴ : CommRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type w
inst✝¹ : AddCommGroup N
inst✝ : Module R N
f : ∀ ⦃I : Ideal R⦄, Ideal.FG I → Injective ⇑(rTensor M (Submodule.subtype I))
i : N →ₗ[R] M
r : M →ₗ[R] N
h : r ∘ₗ i = LinearMap.id
I : Ideal R
hI : Ideal.FG I
⊢ Injective ⇑(rTensor N (Submodule.subtype I))

Next tactic:
have h₁ : Function.Injective (lTensor R i)
/-- A retract of a flat `R`-module is flat. -/
lemma of_retract [f : Flat R M] (i : N →ₗ[R] M) (r : M →ₗ[R] N) (h : r.comp i = LinearMap.id) :
    Flat R N := by
  rw [iff_rTensor_injective] at *
  intro I hI
  have h₁ : Function.Injective (lTensor R i)
  · 

Proof state:
case h₁
R : Type u
inst✝⁴ : CommRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type w
inst✝¹ : AddCommGroup N
inst✝ : Module R N
f : ∀ ⦃I : Ideal R⦄, Ideal.FG I → Injective ⇑(rTensor M (Submodule.subtype I))
i : N →ₗ[R] M
r : M →ₗ[R] N
h : r ∘ₗ i = LinearMap.id
I : Ideal R
hI : Ideal.FG I
⊢ Injective ⇑(lTensor R i)

Next tactic:
apply Function.RightInverse.injective (g := (lTensor R r))
/-- A retract of a flat `R`-module is flat. -/
lemma of_retract [f : Flat R M] (i : N →ₗ[R] M) (r : M →ₗ[R] N) (h : r.comp i = LinearMap.id) :
    Flat R N := by
  rw [iff_rTensor_injective] at *
  intro I hI
  have h₁ : Function.Injective (lTensor R i)
  · apply Function.RightInverse.injective (g := (lTensor R r))
    

Proof state:
case h₁
R : Type u
inst✝⁴ : CommRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type w
inst✝¹ : AddCommGroup N
inst✝ : Module R N
f : ∀ ⦃I : Ideal R⦄, Ideal.FG I → Injective ⇑(rTensor M (Submodule.subtype I))
i : N →ₗ[R] M
r : M →ₗ[R] N
h : r ∘ₗ i = LinearMap.id
I : Ideal R
hI : Ideal.FG I
⊢ Function.RightInverse ⇑(lTensor R i) ⇑(lTensor R r)

Next tactic:
intro x
/-- A retract of a flat `R`-module is flat. -/
lemma of_retract [f : Flat R M] (i : N →ₗ[R] M) (r : M →ₗ[R] N) (h : r.comp i = LinearMap.id) :
    Flat R N := by
  rw [iff_rTensor_injective] at *
  intro I hI
  have h₁ : Function.Injective (lTensor R i)
  · apply Function.RightInverse.injective (g := (lTensor R r))
    intro x
    

Proof state:
case h₁
R : Type u
inst✝⁴ : CommRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type w
inst✝¹ : AddCommGroup N
inst✝ : Module R N
f : ∀ ⦃I : Ideal R⦄, Ideal.FG I → Injective ⇑(rTensor M (Submodule.subtype I))
i : N →ₗ[R] M
r : M →ₗ[R] N
h : r ∘ₗ i = LinearMap.id
I : Ideal R
hI : Ideal.FG I
x : R ⊗[R] N
⊢ (lTensor R r) ((lTensor R i) x) = x

Next tactic:
rw [← LinearMap.comp_apply, ← lTensor_comp, h]
/-- A retract of a flat `R`-module is flat. -/
lemma of_retract [f : Flat R M] (i : N →ₗ[R] M) (r : M →ₗ[R] N) (h : r.comp i = LinearMap.id) :
    Flat R N := by
  rw [iff_rTensor_injective] at *
  intro I hI
  have h₁ : Function.Injective (lTensor R i)
  · apply Function.RightInverse.injective (g := (lTensor R r))
    intro x
    rw [← LinearMap.comp_apply, ← lTensor_comp, h]
    

Proof state:
case h₁
R : Type u
inst✝⁴ : CommRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type w
inst✝¹ : AddCommGroup N
inst✝ : Module R N
f : ∀ ⦃I : Ideal R⦄, Ideal.FG I → Injective ⇑(rTensor M (Submodule.subtype I))
i : N →ₗ[R] M
r : M →ₗ[R] N
h : r ∘ₗ i = LinearMap.id
I : Ideal R
hI : Ideal.FG I
x : R ⊗[R] N
⊢ (lTensor R LinearMap.id) x = x

Next tactic:
simp
/-- A retract of a flat `R`-module is flat. -/
lemma of_retract [f : Flat R M] (i : N →ₗ[R] M) (r : M →ₗ[R] N) (h : r.comp i = LinearMap.id) :
    Flat R N := by
  rw [iff_rTensor_injective] at *
  intro I hI
  have h₁ : Function.Injective (lTensor R i)
  · apply Function.RightInverse.injective (g := (lTensor R r))
    intro x
    rw [← LinearMap.comp_apply, ← lTensor_comp, h]
    simp
  

Proof state:
R : Type u
inst✝⁴ : CommRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type w
inst✝¹ : AddCommGroup N
inst✝ : Module R N
f : ∀ ⦃I : Ideal R⦄, Ideal.FG I → Injective ⇑(rTensor M (Submodule.subtype I))
i : N →ₗ[R] M
r : M →ₗ[R] N
h : r ∘ₗ i = LinearMap.id
I : Ideal R
hI : Ideal.FG I
h₁ : Injective ⇑(lTensor R i)
⊢ Injective ⇑(rTensor N (Submodule.subtype I))

Next tactic:
rw [← Function.Injective.of_comp_iff h₁ (rTensor N I.subtype), ← LinearMap.coe_comp]
/-- A retract of a flat `R`-module is flat. -/
lemma of_retract [f : Flat R M] (i : N →ₗ[R] M) (r : M →ₗ[R] N) (h : r.comp i = LinearMap.id) :
    Flat R N := by
  rw [iff_rTensor_injective] at *
  intro I hI
  have h₁ : Function.Injective (lTensor R i)
  · apply Function.RightInverse.injective (g := (lTensor R r))
    intro x
    rw [← LinearMap.comp_apply, ← lTensor_comp, h]
    simp
  rw [← Function.Injective.of_comp_iff h₁ (rTensor N I.subtype), ← LinearMap.coe_comp]
  

Proof state:
R : Type u
inst✝⁴ : CommRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type w
inst✝¹ : AddCommGroup N
inst✝ : Module R N
f : ∀ ⦃I : Ideal R⦄, Ideal.FG I → Injective ⇑(rTensor M (Submodule.subtype I))
i : N →ₗ[R] M
r : M →ₗ[R] N
h : r ∘ₗ i = LinearMap.id
I : Ideal R
hI : Ideal.FG I
h₁ : Injective ⇑(lTensor R i)
⊢ Injective ⇑(lTensor R i ∘ₗ rTensor N (Submodule.subtype I))

Next tactic:
rw [LinearMap.lTensor_comp_rTensor, ← LinearMap.rTensor_comp_lTensor]
/-- A retract of a flat `R`-module is flat. -/
lemma of_retract [f : Flat R M] (i : N →ₗ[R] M) (r : M →ₗ[R] N) (h : r.comp i = LinearMap.id) :
    Flat R N := by
  rw [iff_rTensor_injective] at *
  intro I hI
  have h₁ : Function.Injective (lTensor R i)
  · apply Function.RightInverse.injective (g := (lTensor R r))
    intro x
    rw [← LinearMap.comp_apply, ← lTensor_comp, h]
    simp
  rw [← Function.Injective.of_comp_iff h₁ (rTensor N I.subtype), ← LinearMap.coe_comp]
  rw [LinearMap.lTensor_comp_rTensor, ← LinearMap.rTensor_comp_lTensor]
  

Proof state:
R : Type u
inst✝⁴ : CommRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type w
inst✝¹ : AddCommGroup N
inst✝ : Module R N
f : ∀ ⦃I : Ideal R⦄, Ideal.FG I → Injective ⇑(rTensor M (Submodule.subtype I))
i : N →ₗ[R] M
r : M →ₗ[R] N
h : r ∘ₗ i = LinearMap.id
I : Ideal R
hI : Ideal.FG I
h₁ : Injective ⇑(lTensor R i)
⊢ Injective ⇑(rTensor M (Submodule.subtype I) ∘ₗ lTensor (↥I) i)

Next tactic:
rw [LinearMap.coe_comp, Function.Injective.of_comp_iff (f hI)]
/-- A retract of a flat `R`-module is flat. -/
lemma of_retract [f : Flat R M] (i : N →ₗ[R] M) (r : M →ₗ[R] N) (h : r.comp i = LinearMap.id) :
    Flat R N := by
  rw [iff_rTensor_injective] at *
  intro I hI
  have h₁ : Function.Injective (lTensor R i)
  · apply Function.RightInverse.injective (g := (lTensor R r))
    intro x
    rw [← LinearMap.comp_apply, ← lTensor_comp, h]
    simp
  rw [← Function.Injective.of_comp_iff h₁ (rTensor N I.subtype), ← LinearMap.coe_comp]
  rw [LinearMap.lTensor_comp_rTensor, ← LinearMap.rTensor_comp_lTensor]
  rw [LinearMap.coe_comp, Function.Injective.of_comp_iff (f hI)]
  

Proof state:
R : Type u
inst✝⁴ : CommRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type w
inst✝¹ : AddCommGroup N
inst✝ : Module R N
f : ∀ ⦃I : Ideal R⦄, Ideal.FG I → Injective ⇑(rTensor M (Submodule.subtype I))
i : N →ₗ[R] M
r : M →ₗ[R] N
h : r ∘ₗ i = LinearMap.id
I : Ideal R
hI : Ideal.FG I
h₁ : Injective ⇑(lTensor R i)
⊢ Injective ⇑(lTensor (↥I) i)

Next tactic:
apply Function.RightInverse.injective (g := lTensor _ r)
/-- A retract of a flat `R`-module is flat. -/
lemma of_retract [f : Flat R M] (i : N →ₗ[R] M) (r : M →ₗ[R] N) (h : r.comp i = LinearMap.id) :
    Flat R N := by
  rw [iff_rTensor_injective] at *
  intro I hI
  have h₁ : Function.Injective (lTensor R i)
  · apply Function.RightInverse.injective (g := (lTensor R r))
    intro x
    rw [← LinearMap.comp_apply, ← lTensor_comp, h]
    simp
  rw [← Function.Injective.of_comp_iff h₁ (rTensor N I.subtype), ← LinearMap.coe_comp]
  rw [LinearMap.lTensor_comp_rTensor, ← LinearMap.rTensor_comp_lTensor]
  rw [LinearMap.coe_comp, Function.Injective.of_comp_iff (f hI)]
  apply Function.RightInverse.injective (g := lTensor _ r)
  

Proof state:
R : Type u
inst✝⁴ : CommRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type w
inst✝¹ : AddCommGroup N
inst✝ : Module R N
f : ∀ ⦃I : Ideal R⦄, Ideal.FG I → Injective ⇑(rTensor M (Submodule.subtype I))
i : N →ₗ[R] M
r : M →ₗ[R] N
h : r ∘ₗ i = LinearMap.id
I : Ideal R
hI : Ideal.FG I
h₁ : Injective ⇑(lTensor R i)
⊢ Function.RightInverse ⇑(lTensor (↥I) i) ⇑(lTensor (↥I) r)

Next tactic:
intro x
/-- A retract of a flat `R`-module is flat. -/
lemma of_retract [f : Flat R M] (i : N →ₗ[R] M) (r : M →ₗ[R] N) (h : r.comp i = LinearMap.id) :
    Flat R N := by
  rw [iff_rTensor_injective] at *
  intro I hI
  have h₁ : Function.Injective (lTensor R i)
  · apply Function.RightInverse.injective (g := (lTensor R r))
    intro x
    rw [← LinearMap.comp_apply, ← lTensor_comp, h]
    simp
  rw [← Function.Injective.of_comp_iff h₁ (rTensor N I.subtype), ← LinearMap.coe_comp]
  rw [LinearMap.lTensor_comp_rTensor, ← LinearMap.rTensor_comp_lTensor]
  rw [LinearMap.coe_comp, Function.Injective.of_comp_iff (f hI)]
  apply Function.RightInverse.injective (g := lTensor _ r)
  intro x
  

Proof state:
R : Type u
inst✝⁴ : CommRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type w
inst✝¹ : AddCommGroup N
inst✝ : Module R N
f : ∀ ⦃I : Ideal R⦄, Ideal.FG I → Injective ⇑(rTensor M (Submodule.subtype I))
i : N →ₗ[R] M
r : M →ₗ[R] N
h : r ∘ₗ i = LinearMap.id
I : Ideal R
hI : Ideal.FG I
h₁ : Injective ⇑(lTensor R i)
x : ↥I ⊗[R] N
⊢ (lTensor (↥I) r) ((lTensor (↥I) i) x) = x

Next tactic:
rw [← LinearMap.comp_apply, ← lTensor_comp, h]
/-- A retract of a flat `R`-module is flat. -/
lemma of_retract [f : Flat R M] (i : N →ₗ[R] M) (r : M →ₗ[R] N) (h : r.comp i = LinearMap.id) :
    Flat R N := by
  rw [iff_rTensor_injective] at *
  intro I hI
  have h₁ : Function.Injective (lTensor R i)
  · apply Function.RightInverse.injective (g := (lTensor R r))
    intro x
    rw [← LinearMap.comp_apply, ← lTensor_comp, h]
    simp
  rw [← Function.Injective.of_comp_iff h₁ (rTensor N I.subtype), ← LinearMap.coe_comp]
  rw [LinearMap.lTensor_comp_rTensor, ← LinearMap.rTensor_comp_lTensor]
  rw [LinearMap.coe_comp, Function.Injective.of_comp_iff (f hI)]
  apply Function.RightInverse.injective (g := lTensor _ r)
  intro x
  rw [← LinearMap.comp_apply, ← lTensor_comp, h]
  

Proof state:
R : Type u
inst✝⁴ : CommRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type w
inst✝¹ : AddCommGroup N
inst✝ : Module R N
f : ∀ ⦃I : Ideal R⦄, Ideal.FG I → Injective ⇑(rTensor M (Submodule.subtype I))
i : N →ₗ[R] M
r : M →ₗ[R] N
h : r ∘ₗ i = LinearMap.id
I : Ideal R
hI : Ideal.FG I
h₁ : Injective ⇑(lTensor R i)
x : ↥I ⊗[R] N
⊢ (lTensor (↥I) LinearMap.id) x = x

Next tactic:
simp
/-- A `R`-module linearly equivalent to a flat `R`-module is flat. -/
lemma of_linearEquiv [f : Flat R M] (e : N ≃ₗ[R] M) : Flat R N := by
  

Proof state:
R : Type u
inst✝⁴ : CommRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type w
inst✝¹ : AddCommGroup N
inst✝ : Module R N
f : Flat R M
e : N ≃ₗ[R] M
⊢ Flat R N

Next tactic:
have h : e.symm.toLinearMap.comp e.toLinearMap = LinearMap.id := by simp
/-- A `R`-module linearly equivalent to a flat `R`-module is flat. -/
lemma of_linearEquiv [f : Flat R M] (e : N ≃ₗ[R] M) : Flat R N := by
  have h : e.symm.toLinearMap.comp e.toLinearMap = LinearMap.id := by 

Proof state:
R : Type u
inst✝⁴ : CommRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type w
inst✝¹ : AddCommGroup N
inst✝ : Module R N
f : Flat R M
e : N ≃ₗ[R] M
⊢ ↑(LinearEquiv.symm e) ∘ₗ ↑e = LinearMap.id

Next tactic:
simp
/-- A `R`-module linearly equivalent to a flat `R`-module is flat. -/
lemma of_linearEquiv [f : Flat R M] (e : N ≃ₗ[R] M) : Flat R N := by
  have h : e.symm.toLinearMap.comp e.toLinearMap = LinearMap.id := by simp
  

Proof state:
R : Type u
inst✝⁴ : CommRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type w
inst✝¹ : AddCommGroup N
inst✝ : Module R N
f : Flat R M
e : N ≃ₗ[R] M
h : ↑(LinearEquiv.symm e) ∘ₗ ↑e = LinearMap.id
⊢ Flat R N

Next tactic:
exact of_retract _ _ _ e.toLinearMap e.symm.toLinearMap h
/-- A direct sum of flat `R`-modules is flat. -/
instance directSum (ι : Type v) (M : ι → Type w) [(i : ι) → AddCommGroup (M i)]
    [(i : ι) → Module R (M i)] [F : (i : ι) → (Flat R (M i))] : Flat R (⨁ i, M i) := by
  

Proof state:
R : Type u
inst✝² : CommRing R
ι : Type v
M : ι → Type w
inst✝¹ : (i : ι) → AddCommGroup (M i)
inst✝ : (i : ι) → Module R (M i)
F : ∀ (i : ι), Flat R (M i)
⊢ Flat R (⨁ (i : ι), M i)

Next tactic:
classical
  rw [iff_rTensor_injective]
  intro I hI
  rw [← Equiv.comp_injective _ (TensorProduct.lid R (⨁ i, M i)).toEquiv]
  set η₁ := TensorProduct.lid R (⨁ i, M i)
  set η := (fun i ↦ TensorProduct.lid R (M i))
  set φ := (fun i ↦ rTensor (M i) I.subtype)
  set π := (fun i ↦ component R ι (fun j ↦ M j) i)
  set ψ := (TensorProduct.directSumRight R {x // x ∈ I} (fun i ↦ M i)).symm.toLinearMap with psi_def
  set ρ := rTensor (⨁ i, M i) I.subtype
  set τ := (fun i ↦ component R ι (fun j ↦ ({x // x ∈ I} ⊗[R] (M j))) i)
  rw [← Equiv.injective_comp (TensorProduct.directSumRight _ _ _).symm.toEquiv]
  rw [LinearEquiv.coe_toEquiv, ← LinearEquiv.coe_coe, ← LinearMap.coe_comp]
  rw [LinearEquiv.coe_toEquiv, ← LinearEquiv.coe_coe, ← LinearMap.coe_comp]
  rw [← psi_def, injective_iff_map_eq_zero ((η₁.comp ρ).comp ψ)]
  have h₁ : ∀ (i : ι), (π i).comp ((η₁.comp ρ).comp ψ) = (η i).comp ((φ i).comp (τ i))
  · intro i
    apply DirectSum.linearMap_ext
    intro j
    apply TensorProduct.ext'
    intro a m
    simp only [coe_comp, LinearEquiv.coe_coe, Function.comp_apply, directSumRight_symm_lof_tmul,
      rTensor_tmul, coeSubtype, lid_tmul, map_smul]
    rw [DirectSum.component.of, DirectSum.component.of]
    by_cases h₂ : j = i
    · subst j; simp
    · simp [h₂]
  intro a ha; rw [DirectSum.ext_iff R]; intro i
  have f := LinearMap.congr_arg (f := (π i)) ha
  erw [LinearMap.congr_fun (h₁ i) a] at f
  rw [(map_zero (π i) : (π i) 0 = (0 : M i))] at f
  have h₂ := (F i)
  rw [iff_rTensor_injective] at h₂
  have h₃ := h₂ hI
  simp only [coe_comp, LinearEquiv.coe_coe, Function.comp_apply, AddEquivClass.map_eq_zero_iff,
    h₃, LinearMap.map_eq_zero_iff] at f
  simp [f]
/-- A direct sum of flat `R`-modules is flat. -/
instance directSum (ι : Type v) (M : ι → Type w) [(i : ι) → AddCommGroup (M i)]
    [(i : ι) → Module R (M i)] [F : (i : ι) → (Flat R (M i))] : Flat R (⨁ i, M i) := by
  classical
  

Proof state:
R : Type u
inst✝² : CommRing R
ι : Type v
M : ι → Type w
inst✝¹ : (i : ι) → AddCommGroup (M i)
inst✝ : (i : ι) → Module R (M i)
F : ∀ (i : ι), Flat R (M i)
⊢ Flat R (⨁ (i : ι), M i)

Next tactic:
rw [iff_rTensor_injective]
/-- A direct sum of flat `R`-modules is flat. -/
instance directSum (ι : Type v) (M : ι → Type w) [(i : ι) → AddCommGroup (M i)]
    [(i : ι) → Module R (M i)] [F : (i : ι) → (Flat R (M i))] : Flat R (⨁ i, M i) := by
  classical
  rw [iff_rTensor_injective]
  

Proof state:
R : Type u
inst✝² : CommRing R
ι : Type v
M : ι → Type w
inst✝¹ : (i : ι) → AddCommGroup (M i)
inst✝ : (i : ι) → Module R (M i)
F : ∀ (i : ι), Flat R (M i)
⊢ ∀ ⦃I : Ideal R⦄, Ideal.FG I → Injective ⇑(rTensor (⨁ (i : ι), M i) (Submodule.subtype I))

Next tactic:
intro I hI
/-- A direct sum of flat `R`-modules is flat. -/
instance directSum (ι : Type v) (M : ι → Type w) [(i : ι) → AddCommGroup (M i)]
    [(i : ι) → Module R (M i)] [F : (i : ι) → (Flat R (M i))] : Flat R (⨁ i, M i) := by
  classical
  rw [iff_rTensor_injective]
  intro I hI
  

Proof state:
R : Type u
inst✝² : CommRing R
ι : Type v
M : ι → Type w
inst✝¹ : (i : ι) → AddCommGroup (M i)
inst✝ : (i : ι) → Module R (M i)
F : ∀ (i : ι), Flat R (M i)
I : Ideal R
hI : Ideal.FG I
⊢ Injective ⇑(rTensor (⨁ (i : ι), M i) (Submodule.subtype I))

Next tactic:
rw [← Equiv.comp_injective _ (TensorProduct.lid R (⨁ i, M i)).toEquiv]