l3lab/ntp-mathlib huggingface dataset:
/-- A finitely generated torsion module over a PID is an internal direct sum of its
`p i ^ e i`-torsion submodules for some primes `p i` and numbers `e i`.-/
theorem Submodule.isInternal_prime_power_torsion_of_pid [Module.Finite R M]
    (hM : Module.IsTorsion R M) :
    DirectSum.IsInternal fun p : (factors (⊤ : Submodule R M).annihilator).toFinset =>
      torsionBy R M
        (IsPrincipal.generator (p : Ideal R) ^
          (factors (⊤ : Submodule R M).annihilator).count ↑p) := by
  

Proof state:
R : Type u
inst✝⁷ : CommRing R
inst✝⁶ : IsDomain R
inst✝⁵ : IsPrincipalIdealRing R
M : Type v
inst✝⁴ : AddCommGroup M
inst✝³ : Module R M
N : Type (max u v)
inst✝² : AddCommGroup N
inst✝¹ : Module R N
inst✝ : Module.Finite R M
hM : Module.IsTorsion R M
⊢ DirectSum.IsInternal fun p => torsionBy R M (IsPrincipal.generator ↑p ^ Multiset.count (↑p) (factors (annihilator ⊤)))

Next tactic:
convert isInternal_prime_power_torsion hM
/-- A finitely generated torsion module over a PID is an internal direct sum of its
`p i ^ e i`-torsion submodules for some primes `p i` and numbers `e i`.-/
theorem Submodule.isInternal_prime_power_torsion_of_pid [Module.Finite R M]
    (hM : Module.IsTorsion R M) :
    DirectSum.IsInternal fun p : (factors (⊤ : Submodule R M).annihilator).toFinset =>
      torsionBy R M
        (IsPrincipal.generator (p : Ideal R) ^
          (factors (⊤ : Submodule R M).annihilator).count ↑p) := by
  convert isInternal_prime_power_torsion hM
  

Proof state:
case h.e'_8.h
R : Type u
inst✝⁷ : CommRing R
inst✝⁶ : IsDomain R
inst✝⁵ : IsPrincipalIdealRing R
M : Type v
inst✝⁴ : AddCommGroup M
inst✝³ : Module R M
N : Type (max u v)
inst✝² : AddCommGroup N
inst✝¹ : Module R N
inst✝ : Module.Finite R M
hM : Module.IsTorsion R M
x✝ : { x // x ∈ Multiset.toFinset (factors (annihilator ⊤)) }
⊢ torsionBy R M (IsPrincipal.generator ↑x✝ ^ Multiset.count (↑x✝) (factors (annihilator ⊤))) =
    torsionBySet R M ↑(↑x✝ ^ Multiset.count (↑x✝) (factors (annihilator ⊤)))

Next tactic:
ext p : 1
/-- A finitely generated torsion module over a PID is an internal direct sum of its
`p i ^ e i`-torsion submodules for some primes `p i` and numbers `e i`.-/
theorem Submodule.isInternal_prime_power_torsion_of_pid [Module.Finite R M]
    (hM : Module.IsTorsion R M) :
    DirectSum.IsInternal fun p : (factors (⊤ : Submodule R M).annihilator).toFinset =>
      torsionBy R M
        (IsPrincipal.generator (p : Ideal R) ^
          (factors (⊤ : Submodule R M).annihilator).count ↑p) := by
  convert isInternal_prime_power_torsion hM
  ext p : 1
  

Proof state:
case h.e'_8.h.h
R : Type u
inst✝⁷ : CommRing R
inst✝⁶ : IsDomain R
inst✝⁵ : IsPrincipalIdealRing R
M : Type v
inst✝⁴ : AddCommGroup M
inst✝³ : Module R M
N : Type (max u v)
inst✝² : AddCommGroup N
inst✝¹ : Module R N
inst✝ : Module.Finite R M
hM : Module.IsTorsion R M
x✝ : { x // x ∈ Multiset.toFinset (factors (annihilator ⊤)) }
p : M
⊢ p ∈ torsionBy R M (IsPrincipal.generator ↑x✝ ^ Multiset.count (↑x✝) (factors (annihilator ⊤))) ↔
    p ∈ torsionBySet R M ↑(↑x✝ ^ Multiset.count (↑x✝) (factors (annihilator ⊤)))

Next tactic:
rw [← torsionBySet_span_singleton_eq, Ideal.submodule_span_eq, ← Ideal.span_singleton_pow,
    Ideal.span_singleton_generator]
/-- A finitely generated torsion module over a PID is an internal direct sum of its
`p i ^ e i`-torsion submodules for some primes `p i` and numbers `e i`.-/
theorem Submodule.exists_isInternal_prime_power_torsion_of_pid [Module.Finite R M]
    (hM : Module.IsTorsion R M) :
    ∃ (ι : Type u) (_ : Fintype ι) (_ : DecidableEq ι) (p : ι → R) (_ : ∀ i, Irreducible <| p i)
        (e : ι → ℕ), DirectSum.IsInternal fun i => torsionBy R M <| p i ^ e i := by
  

Proof state:
R : Type u
inst✝⁷ : CommRing R
inst✝⁶ : IsDomain R
inst✝⁵ : IsPrincipalIdealRing R
M : Type v
inst✝⁴ : AddCommGroup M
inst✝³ : Module R M
N : Type (max u v)
inst✝² : AddCommGroup N
inst✝¹ : Module R N
inst✝ : Module.Finite R M
hM : Module.IsTorsion R M
⊢ ∃ ι x x p, ∃ (_ : ∀ (i : ι), Irreducible (p i)), ∃ e, DirectSum.IsInternal fun i => torsionBy R M (p i ^ e i)

Next tactic:
refine' ⟨_, _, _, _, _, _, Submodule.isInternal_prime_power_torsion_of_pid hM⟩
/-- A finitely generated torsion module over a PID is an internal direct sum of its
`p i ^ e i`-torsion submodules for some primes `p i` and numbers `e i`.-/
theorem Submodule.exists_isInternal_prime_power_torsion_of_pid [Module.Finite R M]
    (hM : Module.IsTorsion R M) :
    ∃ (ι : Type u) (_ : Fintype ι) (_ : DecidableEq ι) (p : ι → R) (_ : ∀ i, Irreducible <| p i)
        (e : ι → ℕ), DirectSum.IsInternal fun i => torsionBy R M <| p i ^ e i := by
  refine' ⟨_, _, _, _, _, _, Submodule.isInternal_prime_power_torsion_of_pid hM⟩
  

Proof state:
case refine'_1
R : Type u
inst✝⁷ : CommRing R
inst✝⁶ : IsDomain R
inst✝⁵ : IsPrincipalIdealRing R
M : Type v
inst✝⁴ : AddCommGroup M
inst✝³ : Module R M
N : Type (max u v)
inst✝² : AddCommGroup N
inst✝¹ : Module R N
inst✝ : Module.Finite R M
hM : Module.IsTorsion R M
⊢ Fintype { x // x ∈ Multiset.toFinset (factors (annihilator ⊤)) }
case refine'_2
R : Type u
inst✝⁷ : CommRing R
inst✝⁶ : IsDomain R
inst✝⁵ : IsPrincipalIdealRing R
M : Type v
inst✝⁴ : AddCommGroup M
inst✝³ : Module R M
N : Type (max u v)
inst✝² : AddCommGroup N
inst✝¹ : Module R N
inst✝ : Module.Finite R M
hM : Module.IsTorsion R M
⊢ ∀ (i : { x // x ∈ Multiset.toFinset (factors (annihilator ⊤)) }), Irreducible (IsPrincipal.generator ↑i)

Next tactic:
exact Finset.fintypeCoeSort _
/-- A finitely generated torsion module over a PID is an internal direct sum of its
`p i ^ e i`-torsion submodules for some primes `p i` and numbers `e i`.-/
theorem Submodule.exists_isInternal_prime_power_torsion_of_pid [Module.Finite R M]
    (hM : Module.IsTorsion R M) :
    ∃ (ι : Type u) (_ : Fintype ι) (_ : DecidableEq ι) (p : ι → R) (_ : ∀ i, Irreducible <| p i)
        (e : ι → ℕ), DirectSum.IsInternal fun i => torsionBy R M <| p i ^ e i := by
  refine' ⟨_, _, _, _, _, _, Submodule.isInternal_prime_power_torsion_of_pid hM⟩
  exact Finset.fintypeCoeSort _
  · 

Proof state:
case refine'_2
R : Type u
inst✝⁷ : CommRing R
inst✝⁶ : IsDomain R
inst✝⁵ : IsPrincipalIdealRing R
M : Type v
inst✝⁴ : AddCommGroup M
inst✝³ : Module R M
N : Type (max u v)
inst✝² : AddCommGroup N
inst✝¹ : Module R N
inst✝ : Module.Finite R M
hM : Module.IsTorsion R M
⊢ ∀ (i : { x // x ∈ Multiset.toFinset (factors (annihilator ⊤)) }), Irreducible (IsPrincipal.generator ↑i)

Next tactic:
rintro ⟨p, hp⟩
/-- A finitely generated torsion module over a PID is an internal direct sum of its
`p i ^ e i`-torsion submodules for some primes `p i` and numbers `e i`.-/
theorem Submodule.exists_isInternal_prime_power_torsion_of_pid [Module.Finite R M]
    (hM : Module.IsTorsion R M) :
    ∃ (ι : Type u) (_ : Fintype ι) (_ : DecidableEq ι) (p : ι → R) (_ : ∀ i, Irreducible <| p i)
        (e : ι → ℕ), DirectSum.IsInternal fun i => torsionBy R M <| p i ^ e i := by
  refine' ⟨_, _, _, _, _, _, Submodule.isInternal_prime_power_torsion_of_pid hM⟩
  exact Finset.fintypeCoeSort _
  · rintro ⟨p, hp⟩
    

Proof state:
case refine'_2.mk
R : Type u
inst✝⁷ : CommRing R
inst✝⁶ : IsDomain R
inst✝⁵ : IsPrincipalIdealRing R
M : Type v
inst✝⁴ : AddCommGroup M
inst✝³ : Module R M
N : Type (max u v)
inst✝² : AddCommGroup N
inst✝¹ : Module R N
inst✝ : Module.Finite R M
hM : Module.IsTorsion R M
p : Ideal R
hp : p ∈ Multiset.toFinset (factors (annihilator ⊤))
⊢ Irreducible (IsPrincipal.generator ↑{ val := p, property := hp })

Next tactic:
have hP := prime_of_factor p (Multiset.mem_toFinset.mp hp)
/-- A finitely generated torsion module over a PID is an internal direct sum of its
`p i ^ e i`-torsion submodules for some primes `p i` and numbers `e i`.-/
theorem Submodule.exists_isInternal_prime_power_torsion_of_pid [Module.Finite R M]
    (hM : Module.IsTorsion R M) :
    ∃ (ι : Type u) (_ : Fintype ι) (_ : DecidableEq ι) (p : ι → R) (_ : ∀ i, Irreducible <| p i)
        (e : ι → ℕ), DirectSum.IsInternal fun i => torsionBy R M <| p i ^ e i := by
  refine' ⟨_, _, _, _, _, _, Submodule.isInternal_prime_power_torsion_of_pid hM⟩
  exact Finset.fintypeCoeSort _
  · rintro ⟨p, hp⟩
    have hP := prime_of_factor p (Multiset.mem_toFinset.mp hp)
    

Proof state:
case refine'_2.mk
R : Type u
inst✝⁷ : CommRing R
inst✝⁶ : IsDomain R
inst✝⁵ : IsPrincipalIdealRing R
M : Type v
inst✝⁴ : AddCommGroup M
inst✝³ : Module R M
N : Type (max u v)
inst✝² : AddCommGroup N
inst✝¹ : Module R N
inst✝ : Module.Finite R M
hM : Module.IsTorsion R M
p : Ideal R
hp : p ∈ Multiset.toFinset (factors (annihilator ⊤))
hP : Prime p
⊢ Irreducible (IsPrincipal.generator ↑{ val := p, property := hp })

Next tactic:
haveI := Ideal.isPrime_of_prime hP
/-- A finitely generated torsion module over a PID is an internal direct sum of its
`p i ^ e i`-torsion submodules for some primes `p i` and numbers `e i`.-/
theorem Submodule.exists_isInternal_prime_power_torsion_of_pid [Module.Finite R M]
    (hM : Module.IsTorsion R M) :
    ∃ (ι : Type u) (_ : Fintype ι) (_ : DecidableEq ι) (p : ι → R) (_ : ∀ i, Irreducible <| p i)
        (e : ι → ℕ), DirectSum.IsInternal fun i => torsionBy R M <| p i ^ e i := by
  refine' ⟨_, _, _, _, _, _, Submodule.isInternal_prime_power_torsion_of_pid hM⟩
  exact Finset.fintypeCoeSort _
  · rintro ⟨p, hp⟩
    have hP := prime_of_factor p (Multiset.mem_toFinset.mp hp)
    haveI := Ideal.isPrime_of_prime hP
    

Proof state:
case refine'_2.mk
R : Type u
inst✝⁷ : CommRing R
inst✝⁶ : IsDomain R
inst✝⁵ : IsPrincipalIdealRing R
M : Type v
inst✝⁴ : AddCommGroup M
inst✝³ : Module R M
N : Type (max u v)
inst✝² : AddCommGroup N
inst✝¹ : Module R N
inst✝ : Module.Finite R M
hM : Module.IsTorsion R M
p : Ideal R
hp : p ∈ Multiset.toFinset (factors (annihilator ⊤))
hP : Prime p
this : Ideal.IsPrime p
⊢ Irreducible (IsPrincipal.generator ↑{ val := p, property := hp })

Next tactic:
exact (IsPrincipal.prime_generator_of_isPrime p hP.ne_zero).irreducible
theorem _root_.Ideal.torsionOf_eq_span_pow_pOrder (x : M) :
    torsionOf R M x = span {p ^ pOrder hM x} := by
  

Proof state:
R : Type u
inst✝⁶ : CommRing R
inst✝⁵ : IsDomain R
inst✝⁴ : IsPrincipalIdealRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type (max u v)
inst✝¹ : AddCommGroup N
inst✝ : Module R N
p : R
hp : Irreducible p
hM : IsTorsion' M ↥(Submonoid.powers p)
dec : (x : M) → Decidable (x = 0)
x : M
⊢ torsionOf R M x = Ideal.span {p ^ pOrder hM x}

Next tactic:
dsimp only [pOrder]
theorem _root_.Ideal.torsionOf_eq_span_pow_pOrder (x : M) :
    torsionOf R M x = span {p ^ pOrder hM x} := by
  dsimp only [pOrder]
  

Proof state:
R : Type u
inst✝⁶ : CommRing R
inst✝⁵ : IsDomain R
inst✝⁴ : IsPrincipalIdealRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type (max u v)
inst✝¹ : AddCommGroup N
inst✝ : Module R N
p : R
hp : Irreducible p
hM : IsTorsion' M ↥(Submonoid.powers p)
dec : (x : M) → Decidable (x = 0)
x : M
⊢ torsionOf R M x = Ideal.span {p ^ Nat.find (_ : ∃ n, p ^ n • x = 0)}

Next tactic:
rw [← (torsionOf R M x).span_singleton_generator, Ideal.span_singleton_eq_span_singleton, ←
    Associates.mk_eq_mk_iff_associated, Associates.mk_pow]
theorem _root_.Ideal.torsionOf_eq_span_pow_pOrder (x : M) :
    torsionOf R M x = span {p ^ pOrder hM x} := by
  dsimp only [pOrder]
  rw [← (torsionOf R M x).span_singleton_generator, Ideal.span_singleton_eq_span_singleton, ←
    Associates.mk_eq_mk_iff_associated, Associates.mk_pow]
  

Proof state:
R : Type u
inst✝⁶ : CommRing R
inst✝⁵ : IsDomain R
inst✝⁴ : IsPrincipalIdealRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type (max u v)
inst✝¹ : AddCommGroup N
inst✝ : Module R N
p : R
hp : Irreducible p
hM : IsTorsion' M ↥(Submonoid.powers p)
dec : (x : M) → Decidable (x = 0)
x : M
⊢ Associates.mk (generator (torsionOf R M x)) = Associates.mk p ^ Nat.find (_ : ∃ n, p ^ n • x = 0)

Next tactic:
have prop :
    (fun n : ℕ => p ^ n • x = 0) = fun n : ℕ =>
      (Associates.mk <| generator <| torsionOf R M x) ∣ Associates.mk p ^ n :=
    by ext n; rw [← Associates.mk_pow, Associates.mk_dvd_mk, ← mem_iff_generator_dvd]; rfl
theorem _root_.Ideal.torsionOf_eq_span_pow_pOrder (x : M) :
    torsionOf R M x = span {p ^ pOrder hM x} := by
  dsimp only [pOrder]
  rw [← (torsionOf R M x).span_singleton_generator, Ideal.span_singleton_eq_span_singleton, ←
    Associates.mk_eq_mk_iff_associated, Associates.mk_pow]
  have prop :
    (fun n : ℕ => p ^ n • x = 0) = fun n : ℕ =>
      (Associates.mk <| generator <| torsionOf R M x) ∣ Associates.mk p ^ n :=
    by 

Proof state:
R : Type u
inst✝⁶ : CommRing R
inst✝⁵ : IsDomain R
inst✝⁴ : IsPrincipalIdealRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type (max u v)
inst✝¹ : AddCommGroup N
inst✝ : Module R N
p : R
hp : Irreducible p
hM : IsTorsion' M ↥(Submonoid.powers p)
dec : (x : M) → Decidable (x = 0)
x : M
⊢ (fun n => p ^ n • x = 0) = fun n => Associates.mk (generator (torsionOf R M x)) ∣ Associates.mk p ^ n

Next tactic:
ext n
theorem _root_.Ideal.torsionOf_eq_span_pow_pOrder (x : M) :
    torsionOf R M x = span {p ^ pOrder hM x} := by
  dsimp only [pOrder]
  rw [← (torsionOf R M x).span_singleton_generator, Ideal.span_singleton_eq_span_singleton, ←
    Associates.mk_eq_mk_iff_associated, Associates.mk_pow]
  have prop :
    (fun n : ℕ => p ^ n • x = 0) = fun n : ℕ =>
      (Associates.mk <| generator <| torsionOf R M x) ∣ Associates.mk p ^ n :=
    by ext n; 

Proof state:
case h.a
R : Type u
inst✝⁶ : CommRing R
inst✝⁵ : IsDomain R
inst✝⁴ : IsPrincipalIdealRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type (max u v)
inst✝¹ : AddCommGroup N
inst✝ : Module R N
p : R
hp : Irreducible p
hM : IsTorsion' M ↥(Submonoid.powers p)
dec : (x : M) → Decidable (x = 0)
x : M
n : ℕ
⊢ p ^ n • x = 0 ↔ Associates.mk (generator (torsionOf R M x)) ∣ Associates.mk p ^ n

Next tactic:
rw [← Associates.mk_pow, Associates.mk_dvd_mk, ← mem_iff_generator_dvd]
theorem _root_.Ideal.torsionOf_eq_span_pow_pOrder (x : M) :
    torsionOf R M x = span {p ^ pOrder hM x} := by
  dsimp only [pOrder]
  rw [← (torsionOf R M x).span_singleton_generator, Ideal.span_singleton_eq_span_singleton, ←
    Associates.mk_eq_mk_iff_associated, Associates.mk_pow]
  have prop :
    (fun n : ℕ => p ^ n • x = 0) = fun n : ℕ =>
      (Associates.mk <| generator <| torsionOf R M x) ∣ Associates.mk p ^ n :=
    by ext n; rw [← Associates.mk_pow, Associates.mk_dvd_mk, ← mem_iff_generator_dvd]; 

Proof state:
case h.a
R : Type u
inst✝⁶ : CommRing R
inst✝⁵ : IsDomain R
inst✝⁴ : IsPrincipalIdealRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type (max u v)
inst✝¹ : AddCommGroup N
inst✝ : Module R N
p : R
hp : Irreducible p
hM : IsTorsion' M ↥(Submonoid.powers p)
dec : (x : M) → Decidable (x = 0)
x : M
n : ℕ
⊢ p ^ n • x = 0 ↔ p ^ n ∈ torsionOf R M x

Next tactic:
rfl
theorem _root_.Ideal.torsionOf_eq_span_pow_pOrder (x : M) :
    torsionOf R M x = span {p ^ pOrder hM x} := by
  dsimp only [pOrder]
  rw [← (torsionOf R M x).span_singleton_generator, Ideal.span_singleton_eq_span_singleton, ←
    Associates.mk_eq_mk_iff_associated, Associates.mk_pow]
  have prop :
    (fun n : ℕ => p ^ n • x = 0) = fun n : ℕ =>
      (Associates.mk <| generator <| torsionOf R M x) ∣ Associates.mk p ^ n :=
    by ext n; rw [← Associates.mk_pow, Associates.mk_dvd_mk, ← mem_iff_generator_dvd]; rfl
  

Proof state:
R : Type u
inst✝⁶ : CommRing R
inst✝⁵ : IsDomain R
inst✝⁴ : IsPrincipalIdealRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type (max u v)
inst✝¹ : AddCommGroup N
inst✝ : Module R N
p : R
hp : Irreducible p
hM : IsTorsion' M ↥(Submonoid.powers p)
dec : (x : M) → Decidable (x = 0)
x : M
prop : (fun n => p ^ n • x = 0) = fun n => Associates.mk (generator (torsionOf R M x)) ∣ Associates.mk p ^ n
⊢ Associates.mk (generator (torsionOf R M x)) = Associates.mk p ^ Nat.find (_ : ∃ n, p ^ n • x = 0)

Next tactic:
have := (isTorsion'_powers_iff p).mp hM x
theorem _root_.Ideal.torsionOf_eq_span_pow_pOrder (x : M) :
    torsionOf R M x = span {p ^ pOrder hM x} := by
  dsimp only [pOrder]
  rw [← (torsionOf R M x).span_singleton_generator, Ideal.span_singleton_eq_span_singleton, ←
    Associates.mk_eq_mk_iff_associated, Associates.mk_pow]
  have prop :
    (fun n : ℕ => p ^ n • x = 0) = fun n : ℕ =>
      (Associates.mk <| generator <| torsionOf R M x) ∣ Associates.mk p ^ n :=
    by ext n; rw [← Associates.mk_pow, Associates.mk_dvd_mk, ← mem_iff_generator_dvd]; rfl
  have := (isTorsion'_powers_iff p).mp hM x; 

Proof state:
R : Type u
inst✝⁶ : CommRing R
inst✝⁵ : IsDomain R
inst✝⁴ : IsPrincipalIdealRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type (max u v)
inst✝¹ : AddCommGroup N
inst✝ : Module R N
p : R
hp : Irreducible p
hM : IsTorsion' M ↥(Submonoid.powers p)
dec : (x : M) → Decidable (x = 0)
x : M
prop : (fun n => p ^ n • x = 0) = fun n => Associates.mk (generator (torsionOf R M x)) ∣ Associates.mk p ^ n
this : ∃ n, p ^ n • x = 0
⊢ Associates.mk (generator (torsionOf R M x)) = Associates.mk p ^ Nat.find (_ : ∃ n, p ^ n • x = 0)

Next tactic:
rw [prop] at this
theorem _root_.Ideal.torsionOf_eq_span_pow_pOrder (x : M) :
    torsionOf R M x = span {p ^ pOrder hM x} := by
  dsimp only [pOrder]
  rw [← (torsionOf R M x).span_singleton_generator, Ideal.span_singleton_eq_span_singleton, ←
    Associates.mk_eq_mk_iff_associated, Associates.mk_pow]
  have prop :
    (fun n : ℕ => p ^ n • x = 0) = fun n : ℕ =>
      (Associates.mk <| generator <| torsionOf R M x) ∣ Associates.mk p ^ n :=
    by ext n; rw [← Associates.mk_pow, Associates.mk_dvd_mk, ← mem_iff_generator_dvd]; rfl
  have := (isTorsion'_powers_iff p).mp hM x; rw [prop] at this
  

Proof state:
R : Type u
inst✝⁶ : CommRing R
inst✝⁵ : IsDomain R
inst✝⁴ : IsPrincipalIdealRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type (max u v)
inst✝¹ : AddCommGroup N
inst✝ : Module R N
p : R
hp : Irreducible p
hM : IsTorsion' M ↥(Submonoid.powers p)
dec : (x : M) → Decidable (x = 0)
x : M
prop : (fun n => p ^ n • x = 0) = fun n => Associates.mk (generator (torsionOf R M x)) ∣ Associates.mk p ^ n
this : ∃ n, Associates.mk (generator (torsionOf R M x)) ∣ Associates.mk p ^ n
⊢ Associates.mk (generator (torsionOf R M x)) = Associates.mk p ^ Nat.find (_ : ∃ n, p ^ n • x = 0)

Next tactic:
classical
  convert
    Associates.eq_pow_find_of_dvd_irreducible_pow ((Associates.irreducible_mk p).mpr hp)
      this.choose_spec
theorem _root_.Ideal.torsionOf_eq_span_pow_pOrder (x : M) :
    torsionOf R M x = span {p ^ pOrder hM x} := by
  dsimp only [pOrder]
  rw [← (torsionOf R M x).span_singleton_generator, Ideal.span_singleton_eq_span_singleton, ←
    Associates.mk_eq_mk_iff_associated, Associates.mk_pow]
  have prop :
    (fun n : ℕ => p ^ n • x = 0) = fun n : ℕ =>
      (Associates.mk <| generator <| torsionOf R M x) ∣ Associates.mk p ^ n :=
    by ext n; rw [← Associates.mk_pow, Associates.mk_dvd_mk, ← mem_iff_generator_dvd]; rfl
  have := (isTorsion'_powers_iff p).mp hM x; rw [prop] at this
  classical
  

Proof state:
R : Type u
inst✝⁶ : CommRing R
inst✝⁵ : IsDomain R
inst✝⁴ : IsPrincipalIdealRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type (max u v)
inst✝¹ : AddCommGroup N
inst✝ : Module R N
p : R
hp : Irreducible p
hM : IsTorsion' M ↥(Submonoid.powers p)
dec : (x : M) → Decidable (x = 0)
x : M
prop : (fun n => p ^ n • x = 0) = fun n => Associates.mk (generator (torsionOf R M x)) ∣ Associates.mk p ^ n
this : ∃ n, Associates.mk (generator (torsionOf R M x)) ∣ Associates.mk p ^ n
⊢ Associates.mk (generator (torsionOf R M x)) = Associates.mk p ^ Nat.find (_ : ∃ n, p ^ n • x = 0)

Next tactic:
convert
    Associates.eq_pow_find_of_dvd_irreducible_pow ((Associates.irreducible_mk p).mpr hp)
      this.choose_spec
theorem p_pow_smul_lift {x y : M} {k : ℕ} (hM' : Module.IsTorsionBy R M (p ^ pOrder hM y))
    (h : p ^ k • x ∈ R ∙ y) : ∃ a : R, p ^ k • x = p ^ k • a • y := by
  -- Porting note: needed to make `smul_smul` work below.
  

Proof state:
R : Type u
inst✝⁶ : CommRing R
inst✝⁵ : IsDomain R
inst✝⁴ : IsPrincipalIdealRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type (max u v)
inst✝¹ : AddCommGroup N
inst✝ : Module R N
p : R
hp : Irreducible p
hM : IsTorsion' M ↥(Submonoid.powers p)
dec : (x : M) → Decidable (x = 0)
x y : M
k : ℕ
hM' : IsTorsionBy R M (p ^ pOrder hM y)
h : p ^ k • x ∈ Submodule.span R {y}
⊢ ∃ a, p ^ k • x = p ^ k • a • y

Next tactic:
letI : MulAction R M := MulActionWithZero.toMulAction
theorem p_pow_smul_lift {x y : M} {k : ℕ} (hM' : Module.IsTorsionBy R M (p ^ pOrder hM y))
    (h : p ^ k • x ∈ R ∙ y) : ∃ a : R, p ^ k • x = p ^ k • a • y := by
  -- Porting note: needed to make `smul_smul` work below.
  letI : MulAction R M := MulActionWithZero.toMulAction
  

Proof state:
R : Type u
inst✝⁶ : CommRing R
inst✝⁵ : IsDomain R
inst✝⁴ : IsPrincipalIdealRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type (max u v)
inst✝¹ : AddCommGroup N
inst✝ : Module R N
p : R
hp : Irreducible p
hM : IsTorsion' M ↥(Submonoid.powers p)
dec : (x : M) → Decidable (x = 0)
x y : M
k : ℕ
hM' : IsTorsionBy R M (p ^ pOrder hM y)
h : p ^ k • x ∈ Submodule.span R {y}
this : MulAction R M := MulActionWithZero.toMulAction
⊢ ∃ a, p ^ k • x = p ^ k • a • y

Next tactic:
by_cases hk : k ≤ pOrder hM y
theorem p_pow_smul_lift {x y : M} {k : ℕ} (hM' : Module.IsTorsionBy R M (p ^ pOrder hM y))
    (h : p ^ k • x ∈ R ∙ y) : ∃ a : R, p ^ k • x = p ^ k • a • y := by
  -- Porting note: needed to make `smul_smul` work below.
  letI : MulAction R M := MulActionWithZero.toMulAction
  by_cases hk : k ≤ pOrder hM y
  · 

Proof state:
case pos
R : Type u
inst✝⁶ : CommRing R
inst✝⁵ : IsDomain R
inst✝⁴ : IsPrincipalIdealRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type (max u v)
inst✝¹ : AddCommGroup N
inst✝ : Module R N
p : R
hp : Irreducible p
hM : IsTorsion' M ↥(Submonoid.powers p)
dec : (x : M) → Decidable (x = 0)
x y : M
k : ℕ
hM' : IsTorsionBy R M (p ^ pOrder hM y)
h : p ^ k • x ∈ Submodule.span R {y}
this : MulAction R M := MulActionWithZero.toMulAction
hk : k ≤ pOrder hM y
⊢ ∃ a, p ^ k • x = p ^ k • a • y

Next tactic:
let f :=
      ((R ∙ p ^ (pOrder hM y - k) * p ^ k).quotEquivOfEq _ ?_).trans
        (quotTorsionOfEquivSpanSingleton R M y)
theorem p_pow_smul_lift {x y : M} {k : ℕ} (hM' : Module.IsTorsionBy R M (p ^ pOrder hM y))
    (h : p ^ k • x ∈ R ∙ y) : ∃ a : R, p ^ k • x = p ^ k • a • y := by
  -- Porting note: needed to make `smul_smul` work below.
  letI : MulAction R M := MulActionWithZero.toMulAction
  by_cases hk : k ≤ pOrder hM y
  · let f :=
      ((R ∙ p ^ (pOrder hM y - k) * p ^ k).quotEquivOfEq _ ?_).trans
        (quotTorsionOfEquivSpanSingleton R M y)
    

Proof state:
case pos.refine_2
R : Type u
inst✝⁶ : CommRing R
inst✝⁵ : IsDomain R
inst✝⁴ : IsPrincipalIdealRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type (max u v)
inst✝¹ : AddCommGroup N
inst✝ : Module R N
p : R
hp : Irreducible p
hM : IsTorsion' M ↥(Submonoid.powers p)
dec : (x : M) → Decidable (x = 0)
x y : M
k : ℕ
hM' : IsTorsionBy R M (p ^ pOrder hM y)
h : p ^ k • x ∈ Submodule.span R {y}
this : MulAction R M := MulActionWithZero.toMulAction
hk : k ≤ pOrder hM y
f : (R ⧸ Submodule.span R {p ^ (pOrder hM y - k) * p ^ k}) ≃ₗ[R] ↥(Submodule.span R {y}) :=
  Submodule.quotEquivOfEq (Submodule.span R {p ^ (pOrder hM y - k) * p ^ k}) (torsionOf R M y) ?pos.refine_1✝ ≪≫ₗ
    quotTorsionOfEquivSpanSingleton R M y
⊢ ∃ a, p ^ k • x = p ^ k • a • y
case pos.refine_1
R : Type u
inst✝⁶ : CommRing R
inst✝⁵ : IsDomain R
inst✝⁴ : IsPrincipalIdealRing R
M : Type v
inst✝³ : AddCommGroup M
inst✝² : Module R M
N : Type (max u v)
inst✝¹ : AddCommGroup N
inst✝ : Module R N
p : R
hp : Irreducible p
hM : IsTorsion' M ↥(Submonoid.powers p)
dec : (x : M) → Decidable (x = 0)
x y : M
k : ℕ
hM' : IsTorsionBy R M (p ^ pOrder hM y)
h : p ^ k • x ∈ Submodule.span R {y}
this : MulAction R M := MulActionWithZero.toMulAction
hk : k ≤ pOrder hM y
⊢ Submodule.span R {p ^ (pOrder hM y - k) * p ^ k} = torsionOf R M y

Next tactic:
have : f.symm ⟨p ^ k • x, h⟩ ∈
        R ∙ Ideal.Quotient.mk (R ∙ p ^ (pOrder hM y - k) * p ^ k) (p ^ k) := by
      rw [← Quotient.torsionBy_eq_span_singleton, mem_torsionBy_iff, ← f.symm.map_smul]
      convert f.symm.map_zero; ext
      rw [coe_smul_of_tower, coe_mk, coe_zero, smul_smul, ← pow_add, Nat.sub_add_cancel hk, @hM' x]
      · exact mem_nonZeroDivisors_of_ne_zero (pow_ne_zero _ hp.ne_zero)