l3lab/ntp-mathlib huggingface dataset:
theorem isCoprime_of_irreducible_dvd {x y : R} (nonzero : ¬(x = 0 ∧ y = 0))
    (H : ∀ z : R, Irreducible z → z ∣ x → ¬z ∣ y) : IsCoprime x y := by
  apply isCoprime_of_dvd x y nonzero
  intro z znu znz zx zy
  obtain ⟨i, h1, h2⟩ := WfDvdMonoid.exists_irreducible_factor znu znz
  apply H i h1 <;>
    · 

Proof state:
case intro.intro.a
R : Type u
M : Type v
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : IsPrincipalIdealRing R
inst✝ : GCDMonoid R
x y : R
nonzero : ¬(x = 0 ∧ y = 0)
H : ∀ (z : R), Irreducible z → z ∣ x → ¬z ∣ y
z : R
znu : z ∈ nonunits R
znz : z ≠ 0
zx : z ∣ x
zy : z ∣ y
i : R
h1 : Irreducible i
h2 : i ∣ z
⊢ i ∣ y

Next tactic:
apply dvd_trans h2
theorem isCoprime_of_irreducible_dvd {x y : R} (nonzero : ¬(x = 0 ∧ y = 0))
    (H : ∀ z : R, Irreducible z → z ∣ x → ¬z ∣ y) : IsCoprime x y := by
  apply isCoprime_of_dvd x y nonzero
  intro z znu znz zx zy
  obtain ⟨i, h1, h2⟩ := WfDvdMonoid.exists_irreducible_factor znu znz
  apply H i h1 <;>
    · apply dvd_trans h2
      

Proof state:
case intro.intro.a
R : Type u
M : Type v
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : IsPrincipalIdealRing R
inst✝ : GCDMonoid R
x y : R
nonzero : ¬(x = 0 ∧ y = 0)
H : ∀ (z : R), Irreducible z → z ∣ x → ¬z ∣ y
z : R
znu : z ∈ nonunits R
znz : z ≠ 0
zx : z ∣ x
zy : z ∣ y
i : R
h1 : Irreducible i
h2 : i ∣ z
⊢ z ∣ y

Next tactic:
assumption
theorem Irreducible.coprime_iff_not_dvd {p n : R} (pp : Irreducible p) :
    IsCoprime p n ↔ ¬p ∣ n := by
  

Proof state:
R : Type u
M : Type v
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : IsPrincipalIdealRing R
inst✝ : GCDMonoid R
p n : R
pp : Irreducible p
⊢ IsCoprime p n ↔ ¬p ∣ n

Next tactic:
constructor
theorem Irreducible.coprime_iff_not_dvd {p n : R} (pp : Irreducible p) :
    IsCoprime p n ↔ ¬p ∣ n := by
  constructor
  · 

Proof state:
case mp
R : Type u
M : Type v
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : IsPrincipalIdealRing R
inst✝ : GCDMonoid R
p n : R
pp : Irreducible p
⊢ IsCoprime p n → ¬p ∣ n

Next tactic:
intro co H
theorem Irreducible.coprime_iff_not_dvd {p n : R} (pp : Irreducible p) :
    IsCoprime p n ↔ ¬p ∣ n := by
  constructor
  · intro co H
    

Proof state:
case mp
R : Type u
M : Type v
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : IsPrincipalIdealRing R
inst✝ : GCDMonoid R
p n : R
pp : Irreducible p
co : IsCoprime p n
H : p ∣ n
⊢ False

Next tactic:
apply pp.not_unit
theorem Irreducible.coprime_iff_not_dvd {p n : R} (pp : Irreducible p) :
    IsCoprime p n ↔ ¬p ∣ n := by
  constructor
  · intro co H
    apply pp.not_unit
    

Proof state:
case mp
R : Type u
M : Type v
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : IsPrincipalIdealRing R
inst✝ : GCDMonoid R
p n : R
pp : Irreducible p
co : IsCoprime p n
H : p ∣ n
⊢ IsUnit p

Next tactic:
rw [isUnit_iff_dvd_one]
theorem Irreducible.coprime_iff_not_dvd {p n : R} (pp : Irreducible p) :
    IsCoprime p n ↔ ¬p ∣ n := by
  constructor
  · intro co H
    apply pp.not_unit
    rw [isUnit_iff_dvd_one]
    

Proof state:
case mp
R : Type u
M : Type v
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : IsPrincipalIdealRing R
inst✝ : GCDMonoid R
p n : R
pp : Irreducible p
co : IsCoprime p n
H : p ∣ n
⊢ p ∣ 1

Next tactic:
apply IsCoprime.dvd_of_dvd_mul_left co
theorem Irreducible.coprime_iff_not_dvd {p n : R} (pp : Irreducible p) :
    IsCoprime p n ↔ ¬p ∣ n := by
  constructor
  · intro co H
    apply pp.not_unit
    rw [isUnit_iff_dvd_one]
    apply IsCoprime.dvd_of_dvd_mul_left co
    

Proof state:
case mp
R : Type u
M : Type v
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : IsPrincipalIdealRing R
inst✝ : GCDMonoid R
p n : R
pp : Irreducible p
co : IsCoprime p n
H : p ∣ n
⊢ p ∣ n * 1

Next tactic:
rw [mul_one n]
theorem Irreducible.coprime_iff_not_dvd {p n : R} (pp : Irreducible p) :
    IsCoprime p n ↔ ¬p ∣ n := by
  constructor
  · intro co H
    apply pp.not_unit
    rw [isUnit_iff_dvd_one]
    apply IsCoprime.dvd_of_dvd_mul_left co
    rw [mul_one n]
    

Proof state:
case mp
R : Type u
M : Type v
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : IsPrincipalIdealRing R
inst✝ : GCDMonoid R
p n : R
pp : Irreducible p
co : IsCoprime p n
H : p ∣ n
⊢ p ∣ n

Next tactic:
exact H
theorem Irreducible.coprime_iff_not_dvd {p n : R} (pp : Irreducible p) :
    IsCoprime p n ↔ ¬p ∣ n := by
  constructor
  · intro co H
    apply pp.not_unit
    rw [isUnit_iff_dvd_one]
    apply IsCoprime.dvd_of_dvd_mul_left co
    rw [mul_one n]
    exact H
  · 

Proof state:
case mpr
R : Type u
M : Type v
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : IsPrincipalIdealRing R
inst✝ : GCDMonoid R
p n : R
pp : Irreducible p
⊢ ¬p ∣ n → IsCoprime p n

Next tactic:
intro nd
theorem Irreducible.coprime_iff_not_dvd {p n : R} (pp : Irreducible p) :
    IsCoprime p n ↔ ¬p ∣ n := by
  constructor
  · intro co H
    apply pp.not_unit
    rw [isUnit_iff_dvd_one]
    apply IsCoprime.dvd_of_dvd_mul_left co
    rw [mul_one n]
    exact H
  · intro nd
    

Proof state:
case mpr
R : Type u
M : Type v
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : IsPrincipalIdealRing R
inst✝ : GCDMonoid R
p n : R
pp : Irreducible p
nd : ¬p ∣ n
⊢ IsCoprime p n

Next tactic:
apply isCoprime_of_irreducible_dvd
theorem Irreducible.coprime_iff_not_dvd {p n : R} (pp : Irreducible p) :
    IsCoprime p n ↔ ¬p ∣ n := by
  constructor
  · intro co H
    apply pp.not_unit
    rw [isUnit_iff_dvd_one]
    apply IsCoprime.dvd_of_dvd_mul_left co
    rw [mul_one n]
    exact H
  · intro nd
    apply isCoprime_of_irreducible_dvd
    · 

Proof state:
case mpr.nonzero
R : Type u
M : Type v
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : IsPrincipalIdealRing R
inst✝ : GCDMonoid R
p n : R
pp : Irreducible p
nd : ¬p ∣ n
⊢ ¬(p = 0 ∧ n = 0)

Next tactic:
rintro ⟨hp, -⟩
theorem Irreducible.coprime_iff_not_dvd {p n : R} (pp : Irreducible p) :
    IsCoprime p n ↔ ¬p ∣ n := by
  constructor
  · intro co H
    apply pp.not_unit
    rw [isUnit_iff_dvd_one]
    apply IsCoprime.dvd_of_dvd_mul_left co
    rw [mul_one n]
    exact H
  · intro nd
    apply isCoprime_of_irreducible_dvd
    · rintro ⟨hp, -⟩
      

Proof state:
case mpr.nonzero.intro
R : Type u
M : Type v
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : IsPrincipalIdealRing R
inst✝ : GCDMonoid R
p n : R
pp : Irreducible p
nd : ¬p ∣ n
hp : p = 0
⊢ False

Next tactic:
exact pp.ne_zero hp
theorem Irreducible.coprime_iff_not_dvd {p n : R} (pp : Irreducible p) :
    IsCoprime p n ↔ ¬p ∣ n := by
  constructor
  · intro co H
    apply pp.not_unit
    rw [isUnit_iff_dvd_one]
    apply IsCoprime.dvd_of_dvd_mul_left co
    rw [mul_one n]
    exact H
  · intro nd
    apply isCoprime_of_irreducible_dvd
    · rintro ⟨hp, -⟩
      exact pp.ne_zero hp
    

Proof state:
case mpr.H
R : Type u
M : Type v
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : IsPrincipalIdealRing R
inst✝ : GCDMonoid R
p n : R
pp : Irreducible p
nd : ¬p ∣ n
⊢ ∀ (z : R), Irreducible z → z ∣ p → ¬z ∣ n

Next tactic:
rintro z zi zp zn
theorem Irreducible.coprime_iff_not_dvd {p n : R} (pp : Irreducible p) :
    IsCoprime p n ↔ ¬p ∣ n := by
  constructor
  · intro co H
    apply pp.not_unit
    rw [isUnit_iff_dvd_one]
    apply IsCoprime.dvd_of_dvd_mul_left co
    rw [mul_one n]
    exact H
  · intro nd
    apply isCoprime_of_irreducible_dvd
    · rintro ⟨hp, -⟩
      exact pp.ne_zero hp
    rintro z zi zp zn
    

Proof state:
case mpr.H
R : Type u
M : Type v
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : IsPrincipalIdealRing R
inst✝ : GCDMonoid R
p n : R
pp : Irreducible p
nd : ¬p ∣ n
z : R
zi : Irreducible z
zp : z ∣ p
zn : z ∣ n
⊢ False

Next tactic:
exact nd ((zi.associated_of_dvd pp zp).symm.dvd.trans zn)
theorem nonPrincipals_eq_empty_iff : nonPrincipals R = ∅ ↔ IsPrincipalIdealRing R := by
  

Proof state:
R : Type u
M : Type v
inst✝ : CommRing R
⊢ nonPrincipals R = ∅ ↔ IsPrincipalIdealRing R

Next tactic:
simp [Set.eq_empty_iff_forall_not_mem, isPrincipalIdealRing_iff, nonPrincipals_def]
/-- Any chain in the set of non-principal ideals has an upper bound which is non-principal.
(Namely, the union of the chain is such an upper bound.)
-/
theorem nonPrincipals_zorn (c : Set (Ideal R)) (hs : c ⊆ nonPrincipals R)
    (hchain : IsChain (· ≤ ·) c) {K : Ideal R} (hKmem : K ∈ c) :
    ∃ I ∈ nonPrincipals R, ∀ J ∈ c, J ≤ I := by
  

Proof state:
R : Type u
M : Type v
inst✝ : CommRing R
c : Set (Ideal R)
hs : c ⊆ nonPrincipals R
hchain : IsChain (fun x x_1 => x ≤ x_1) c
K : Ideal R
hKmem : K ∈ c
⊢ ∃ I ∈ nonPrincipals R, ∀ J ∈ c, J ≤ I

Next tactic:
refine' ⟨sSup c, _, fun J hJ => le_sSup hJ⟩
/-- Any chain in the set of non-principal ideals has an upper bound which is non-principal.
(Namely, the union of the chain is such an upper bound.)
-/
theorem nonPrincipals_zorn (c : Set (Ideal R)) (hs : c ⊆ nonPrincipals R)
    (hchain : IsChain (· ≤ ·) c) {K : Ideal R} (hKmem : K ∈ c) :
    ∃ I ∈ nonPrincipals R, ∀ J ∈ c, J ≤ I := by
  refine' ⟨sSup c, _, fun J hJ => le_sSup hJ⟩
  

Proof state:
R : Type u
M : Type v
inst✝ : CommRing R
c : Set (Ideal R)
hs : c ⊆ nonPrincipals R
hchain : IsChain (fun x x_1 => x ≤ x_1) c
K : Ideal R
hKmem : K ∈ c
⊢ sSup c ∈ nonPrincipals R

Next tactic:
rintro ⟨x, hx⟩
/-- Any chain in the set of non-principal ideals has an upper bound which is non-principal.
(Namely, the union of the chain is such an upper bound.)
-/
theorem nonPrincipals_zorn (c : Set (Ideal R)) (hs : c ⊆ nonPrincipals R)
    (hchain : IsChain (· ≤ ·) c) {K : Ideal R} (hKmem : K ∈ c) :
    ∃ I ∈ nonPrincipals R, ∀ J ∈ c, J ≤ I := by
  refine' ⟨sSup c, _, fun J hJ => le_sSup hJ⟩
  rintro ⟨x, hx⟩
  

Proof state:
case mk.intro
R : Type u
M : Type v
inst✝ : CommRing R
c : Set (Ideal R)
hs : c ⊆ nonPrincipals R
hchain : IsChain (fun x x_1 => x ≤ x_1) c
K : Ideal R
hKmem : K ∈ c
x : R
hx : sSup c = Submodule.span R {x}
⊢ False

Next tactic:
have hxmem : x ∈ sSup c := hx.symm ▸ Submodule.mem_span_singleton_self x
/-- Any chain in the set of non-principal ideals has an upper bound which is non-principal.
(Namely, the union of the chain is such an upper bound.)
-/
theorem nonPrincipals_zorn (c : Set (Ideal R)) (hs : c ⊆ nonPrincipals R)
    (hchain : IsChain (· ≤ ·) c) {K : Ideal R} (hKmem : K ∈ c) :
    ∃ I ∈ nonPrincipals R, ∀ J ∈ c, J ≤ I := by
  refine' ⟨sSup c, _, fun J hJ => le_sSup hJ⟩
  rintro ⟨x, hx⟩
  have hxmem : x ∈ sSup c := hx.symm ▸ Submodule.mem_span_singleton_self x
  

Proof state:
case mk.intro
R : Type u
M : Type v
inst✝ : CommRing R
c : Set (Ideal R)
hs : c ⊆ nonPrincipals R
hchain : IsChain (fun x x_1 => x ≤ x_1) c
K : Ideal R
hKmem : K ∈ c
x : R
hx : sSup c = Submodule.span R {x}
hxmem : x ∈ sSup c
⊢ False

Next tactic:
obtain ⟨J, hJc, hxJ⟩ := (Submodule.mem_sSup_of_directed ⟨K, hKmem⟩ hchain.directedOn).1 hxmem
/-- Any chain in the set of non-principal ideals has an upper bound which is non-principal.
(Namely, the union of the chain is such an upper bound.)
-/
theorem nonPrincipals_zorn (c : Set (Ideal R)) (hs : c ⊆ nonPrincipals R)
    (hchain : IsChain (· ≤ ·) c) {K : Ideal R} (hKmem : K ∈ c) :
    ∃ I ∈ nonPrincipals R, ∀ J ∈ c, J ≤ I := by
  refine' ⟨sSup c, _, fun J hJ => le_sSup hJ⟩
  rintro ⟨x, hx⟩
  have hxmem : x ∈ sSup c := hx.symm ▸ Submodule.mem_span_singleton_self x
  obtain ⟨J, hJc, hxJ⟩ := (Submodule.mem_sSup_of_directed ⟨K, hKmem⟩ hchain.directedOn).1 hxmem
  

Proof state:
case mk.intro.intro.intro
R : Type u
M : Type v
inst✝ : CommRing R
c : Set (Ideal R)
hs : c ⊆ nonPrincipals R
hchain : IsChain (fun x x_1 => x ≤ x_1) c
K : Ideal R
hKmem : K ∈ c
x : R
hx : sSup c = Submodule.span R {x}
hxmem : x ∈ sSup c
J : Submodule R R
hJc : J ∈ c
hxJ : x ∈ J
⊢ False

Next tactic:
have hsSupJ : sSup c = J := le_antisymm (by simp [hx, Ideal.span_le, hxJ]) (le_sSup hJc)
/-- Any chain in the set of non-principal ideals has an upper bound which is non-principal.
(Namely, the union of the chain is such an upper bound.)
-/
theorem nonPrincipals_zorn (c : Set (Ideal R)) (hs : c ⊆ nonPrincipals R)
    (hchain : IsChain (· ≤ ·) c) {K : Ideal R} (hKmem : K ∈ c) :
    ∃ I ∈ nonPrincipals R, ∀ J ∈ c, J ≤ I := by
  refine' ⟨sSup c, _, fun J hJ => le_sSup hJ⟩
  rintro ⟨x, hx⟩
  have hxmem : x ∈ sSup c := hx.symm ▸ Submodule.mem_span_singleton_self x
  obtain ⟨J, hJc, hxJ⟩ := (Submodule.mem_sSup_of_directed ⟨K, hKmem⟩ hchain.directedOn).1 hxmem
  have hsSupJ : sSup c = J := le_antisymm (by 

Proof state:
R : Type u
M : Type v
inst✝ : CommRing R
c : Set (Ideal R)
hs : c ⊆ nonPrincipals R
hchain : IsChain (fun x x_1 => x ≤ x_1) c
K : Ideal R
hKmem : K ∈ c
x : R
hx : sSup c = Submodule.span R {x}
hxmem : x ∈ sSup c
J : Submodule R R
hJc : J ∈ c
hxJ : x ∈ J
⊢ sSup c ≤ J

Next tactic:
simp [hx, Ideal.span_le, hxJ]
/-- Any chain in the set of non-principal ideals has an upper bound which is non-principal.
(Namely, the union of the chain is such an upper bound.)
-/
theorem nonPrincipals_zorn (c : Set (Ideal R)) (hs : c ⊆ nonPrincipals R)
    (hchain : IsChain (· ≤ ·) c) {K : Ideal R} (hKmem : K ∈ c) :
    ∃ I ∈ nonPrincipals R, ∀ J ∈ c, J ≤ I := by
  refine' ⟨sSup c, _, fun J hJ => le_sSup hJ⟩
  rintro ⟨x, hx⟩
  have hxmem : x ∈ sSup c := hx.symm ▸ Submodule.mem_span_singleton_self x
  obtain ⟨J, hJc, hxJ⟩ := (Submodule.mem_sSup_of_directed ⟨K, hKmem⟩ hchain.directedOn).1 hxmem
  have hsSupJ : sSup c = J := le_antisymm (by simp [hx, Ideal.span_le, hxJ]) (le_sSup hJc)
  

Proof state:
case mk.intro.intro.intro
R : Type u
M : Type v
inst✝ : CommRing R
c : Set (Ideal R)
hs : c ⊆ nonPrincipals R
hchain : IsChain (fun x x_1 => x ≤ x_1) c
K : Ideal R
hKmem : K ∈ c
x : R
hx : sSup c = Submodule.span R {x}
hxmem : x ∈ sSup c
J : Submodule R R
hJc : J ∈ c
hxJ : x ∈ J
hsSupJ : sSup c = J
⊢ False

Next tactic:
specialize hs hJc
/-- Any chain in the set of non-principal ideals has an upper bound which is non-principal.
(Namely, the union of the chain is such an upper bound.)
-/
theorem nonPrincipals_zorn (c : Set (Ideal R)) (hs : c ⊆ nonPrincipals R)
    (hchain : IsChain (· ≤ ·) c) {K : Ideal R} (hKmem : K ∈ c) :
    ∃ I ∈ nonPrincipals R, ∀ J ∈ c, J ≤ I := by
  refine' ⟨sSup c, _, fun J hJ => le_sSup hJ⟩
  rintro ⟨x, hx⟩
  have hxmem : x ∈ sSup c := hx.symm ▸ Submodule.mem_span_singleton_self x
  obtain ⟨J, hJc, hxJ⟩ := (Submodule.mem_sSup_of_directed ⟨K, hKmem⟩ hchain.directedOn).1 hxmem
  have hsSupJ : sSup c = J := le_antisymm (by simp [hx, Ideal.span_le, hxJ]) (le_sSup hJc)
  specialize hs hJc
  

Proof state:
case mk.intro.intro.intro
R : Type u
M : Type v
inst✝ : CommRing R
c : Set (Ideal R)
hchain : IsChain (fun x x_1 => x ≤ x_1) c
K : Ideal R
hKmem : K ∈ c
x : R
hx : sSup c = Submodule.span R {x}
hxmem : x ∈ sSup c
J : Submodule R R
hJc : J ∈ c
hxJ : x ∈ J
hsSupJ : sSup c = J
hs : J ∈ nonPrincipals R
⊢ False

Next tactic:
rw [← hsSupJ, hx, nonPrincipals_def] at hs
/-- Any chain in the set of non-principal ideals has an upper bound which is non-principal.
(Namely, the union of the chain is such an upper bound.)
-/
theorem nonPrincipals_zorn (c : Set (Ideal R)) (hs : c ⊆ nonPrincipals R)
    (hchain : IsChain (· ≤ ·) c) {K : Ideal R} (hKmem : K ∈ c) :
    ∃ I ∈ nonPrincipals R, ∀ J ∈ c, J ≤ I := by
  refine' ⟨sSup c, _, fun J hJ => le_sSup hJ⟩
  rintro ⟨x, hx⟩
  have hxmem : x ∈ sSup c := hx.symm ▸ Submodule.mem_span_singleton_self x
  obtain ⟨J, hJc, hxJ⟩ := (Submodule.mem_sSup_of_directed ⟨K, hKmem⟩ hchain.directedOn).1 hxmem
  have hsSupJ : sSup c = J := le_antisymm (by simp [hx, Ideal.span_le, hxJ]) (le_sSup hJc)
  specialize hs hJc
  rw [← hsSupJ, hx, nonPrincipals_def] at hs
  

Proof state:
case mk.intro.intro.intro
R : Type u
M : Type v
inst✝ : CommRing R
c : Set (Ideal R)
hchain : IsChain (fun x x_1 => x ≤ x_1) c
K : Ideal R
hKmem : K ∈ c
x : R
hx : sSup c = Submodule.span R {x}
hxmem : x ∈ sSup c
J : Submodule R R
hJc : J ∈ c
hxJ : x ∈ J
hsSupJ : sSup c = J
hs : ¬IsPrincipal (Submodule.span R {x})
⊢ False

Next tactic:
exact hs ⟨⟨x, rfl⟩⟩
/-- If all prime ideals in a commutative ring are principal, so are all other ideals. -/
theorem IsPrincipalIdealRing.of_prime (H : ∀ P : Ideal R, P.IsPrime → P.IsPrincipal) :
    IsPrincipalIdealRing R := by
  -- Suppose the set of `nonPrincipals` is not empty.
  

Proof state:
R : Type u
M : Type v
inst✝ : CommRing R
H : ∀ (P : Ideal R), IsPrime P → IsPrincipal P
⊢ IsPrincipalIdealRing R

Next tactic:
rw [← nonPrincipals_eq_empty_iff, Set.eq_empty_iff_forall_not_mem]
/-- If all prime ideals in a commutative ring are principal, so are all other ideals. -/
theorem IsPrincipalIdealRing.of_prime (H : ∀ P : Ideal R, P.IsPrime → P.IsPrincipal) :
    IsPrincipalIdealRing R := by
  -- Suppose the set of `nonPrincipals` is not empty.
  rw [← nonPrincipals_eq_empty_iff, Set.eq_empty_iff_forall_not_mem]
  

Proof state:
R : Type u
M : Type v
inst✝ : CommRing R
H : ∀ (P : Ideal R), IsPrime P → IsPrincipal P
⊢ ∀ (x : Ideal R), x ∉ nonPrincipals R

Next tactic:
intro J hJ
/-- If all prime ideals in a commutative ring are principal, so are all other ideals. -/
theorem IsPrincipalIdealRing.of_prime (H : ∀ P : Ideal R, P.IsPrime → P.IsPrincipal) :
    IsPrincipalIdealRing R := by
  -- Suppose the set of `nonPrincipals` is not empty.
  rw [← nonPrincipals_eq_empty_iff, Set.eq_empty_iff_forall_not_mem]
  intro J hJ
  -- We will show a maximal element `I ∈ nonPrincipals R` (which exists by Zorn) is prime.
  

Proof state:
R : Type u
M : Type v
inst✝ : CommRing R
H : ∀ (P : Ideal R), IsPrime P → IsPrincipal P
J : Ideal R
hJ : J ∈ nonPrincipals R
⊢ False

Next tactic:
obtain ⟨I, Ibad, -, Imax⟩ := zorn_nonempty_partialOrder₀ (nonPrincipals R) nonPrincipals_zorn _ hJ
/-- If all prime ideals in a commutative ring are principal, so are all other ideals. -/
theorem IsPrincipalIdealRing.of_prime (H : ∀ P : Ideal R, P.IsPrime → P.IsPrincipal) :
    IsPrincipalIdealRing R := by
  -- Suppose the set of `nonPrincipals` is not empty.
  rw [← nonPrincipals_eq_empty_iff, Set.eq_empty_iff_forall_not_mem]
  intro J hJ
  -- We will show a maximal element `I ∈ nonPrincipals R` (which exists by Zorn) is prime.
  obtain ⟨I, Ibad, -, Imax⟩ := zorn_nonempty_partialOrder₀ (nonPrincipals R) nonPrincipals_zorn _ hJ
  

Proof state:
case intro.intro.intro
R : Type u
M : Type v
inst✝ : CommRing R
H : ∀ (P : Ideal R), IsPrime P → IsPrincipal P
J : Ideal R
hJ : J ∈ nonPrincipals R
I : Ideal R
Ibad : I ∈ nonPrincipals R
Imax : ∀ z ∈ nonPrincipals R, I ≤ z → z = I
⊢ False

Next tactic:
have Imax' : ∀ {J}, I < J → J.IsPrincipal := by
    intro J hJ
    by_contra He
    exact hJ.ne (Imax _ ((nonPrincipals_def R).2 He) hJ.le).symm
/-- If all prime ideals in a commutative ring are principal, so are all other ideals. -/
theorem IsPrincipalIdealRing.of_prime (H : ∀ P : Ideal R, P.IsPrime → P.IsPrincipal) :
    IsPrincipalIdealRing R := by
  -- Suppose the set of `nonPrincipals` is not empty.
  rw [← nonPrincipals_eq_empty_iff, Set.eq_empty_iff_forall_not_mem]
  intro J hJ
  -- We will show a maximal element `I ∈ nonPrincipals R` (which exists by Zorn) is prime.
  obtain ⟨I, Ibad, -, Imax⟩ := zorn_nonempty_partialOrder₀ (nonPrincipals R) nonPrincipals_zorn _ hJ
  have Imax' : ∀ {J}, I < J → J.IsPrincipal := by
    

Proof state:
R : Type u
M : Type v
inst✝ : CommRing R
H : ∀ (P : Ideal R), IsPrime P → IsPrincipal P
J : Ideal R
hJ : J ∈ nonPrincipals R
I : Ideal R
Ibad : I ∈ nonPrincipals R
Imax : ∀ z ∈ nonPrincipals R, I ≤ z → z = I
⊢ ∀ {J : Ideal R}, I < J → IsPrincipal J

Next tactic:
intro J hJ
/-- If all prime ideals in a commutative ring are principal, so are all other ideals. -/
theorem IsPrincipalIdealRing.of_prime (H : ∀ P : Ideal R, P.IsPrime → P.IsPrincipal) :
    IsPrincipalIdealRing R := by
  -- Suppose the set of `nonPrincipals` is not empty.
  rw [← nonPrincipals_eq_empty_iff, Set.eq_empty_iff_forall_not_mem]
  intro J hJ
  -- We will show a maximal element `I ∈ nonPrincipals R` (which exists by Zorn) is prime.
  obtain ⟨I, Ibad, -, Imax⟩ := zorn_nonempty_partialOrder₀ (nonPrincipals R) nonPrincipals_zorn _ hJ
  have Imax' : ∀ {J}, I < J → J.IsPrincipal := by
    intro J hJ
    

Proof state:
R : Type u
M : Type v
inst✝ : CommRing R
H : ∀ (P : Ideal R), IsPrime P → IsPrincipal P
J✝ : Ideal R
hJ✝ : J✝ ∈ nonPrincipals R
I : Ideal R
Ibad : I ∈ nonPrincipals R
Imax : ∀ z ∈ nonPrincipals R, I ≤ z → z = I
J : Ideal R
hJ : I < J
⊢ IsPrincipal J

Next tactic:
by_contra He
/-- If all prime ideals in a commutative ring are principal, so are all other ideals. -/
theorem IsPrincipalIdealRing.of_prime (H : ∀ P : Ideal R, P.IsPrime → P.IsPrincipal) :
    IsPrincipalIdealRing R := by
  -- Suppose the set of `nonPrincipals` is not empty.
  rw [← nonPrincipals_eq_empty_iff, Set.eq_empty_iff_forall_not_mem]
  intro J hJ
  -- We will show a maximal element `I ∈ nonPrincipals R` (which exists by Zorn) is prime.
  obtain ⟨I, Ibad, -, Imax⟩ := zorn_nonempty_partialOrder₀ (nonPrincipals R) nonPrincipals_zorn _ hJ
  have Imax' : ∀ {J}, I < J → J.IsPrincipal := by
    intro J hJ
    by_contra He
    

Proof state:
R : Type u
M : Type v
inst✝ : CommRing R
H : ∀ (P : Ideal R), IsPrime P → IsPrincipal P
J✝ : Ideal R
hJ✝ : J✝ ∈ nonPrincipals R
I : Ideal R
Ibad : I ∈ nonPrincipals R
Imax : ∀ z ∈ nonPrincipals R, I ≤ z → z = I
J : Ideal R
hJ : I < J
He : ¬IsPrincipal J
⊢ False

Next tactic:
exact hJ.ne (Imax _ ((nonPrincipals_def R).2 He) hJ.le).symm
/-- If all prime ideals in a commutative ring are principal, so are all other ideals. -/
theorem IsPrincipalIdealRing.of_prime (H : ∀ P : Ideal R, P.IsPrime → P.IsPrincipal) :
    IsPrincipalIdealRing R := by
  -- Suppose the set of `nonPrincipals` is not empty.
  rw [← nonPrincipals_eq_empty_iff, Set.eq_empty_iff_forall_not_mem]
  intro J hJ
  -- We will show a maximal element `I ∈ nonPrincipals R` (which exists by Zorn) is prime.
  obtain ⟨I, Ibad, -, Imax⟩ := zorn_nonempty_partialOrder₀ (nonPrincipals R) nonPrincipals_zorn _ hJ
  have Imax' : ∀ {J}, I < J → J.IsPrincipal := by
    intro J hJ
    by_contra He
    exact hJ.ne (Imax _ ((nonPrincipals_def R).2 He) hJ.le).symm
  

Proof state:
case intro.intro.intro
R : Type u
M : Type v
inst✝ : CommRing R
H : ∀ (P : Ideal R), IsPrime P → IsPrincipal P
J : Ideal R
hJ : J ∈ nonPrincipals R
I : Ideal R
Ibad : I ∈ nonPrincipals R
Imax : ∀ z ∈ nonPrincipals R, I ≤ z → z = I
Imax' : ∀ {J : Ideal R}, I < J → IsPrincipal J
⊢ False

Next tactic:
by_cases hI1 : I = ⊤
/-- If all prime ideals in a commutative ring are principal, so are all other ideals. -/
theorem IsPrincipalIdealRing.of_prime (H : ∀ P : Ideal R, P.IsPrime → P.IsPrincipal) :
    IsPrincipalIdealRing R := by
  -- Suppose the set of `nonPrincipals` is not empty.
  rw [← nonPrincipals_eq_empty_iff, Set.eq_empty_iff_forall_not_mem]
  intro J hJ
  -- We will show a maximal element `I ∈ nonPrincipals R` (which exists by Zorn) is prime.
  obtain ⟨I, Ibad, -, Imax⟩ := zorn_nonempty_partialOrder₀ (nonPrincipals R) nonPrincipals_zorn _ hJ
  have Imax' : ∀ {J}, I < J → J.IsPrincipal := by
    intro J hJ
    by_contra He
    exact hJ.ne (Imax _ ((nonPrincipals_def R).2 He) hJ.le).symm
  by_cases hI1 : I = ⊤
  · 

Proof state:
case pos
R : Type u
M : Type v
inst✝ : CommRing R
H : ∀ (P : Ideal R), IsPrime P → IsPrincipal P
J : Ideal R
hJ : J ∈ nonPrincipals R
I : Ideal R
Ibad : I ∈ nonPrincipals R
Imax : ∀ z ∈ nonPrincipals R, I ≤ z → z = I
Imax' : ∀ {J : Ideal R}, I < J → IsPrincipal J
hI1 : I = ⊤
⊢ False

Next tactic:
subst hI1
/-- If all prime ideals in a commutative ring are principal, so are all other ideals. -/
theorem IsPrincipalIdealRing.of_prime (H : ∀ P : Ideal R, P.IsPrime → P.IsPrincipal) :
    IsPrincipalIdealRing R := by
  -- Suppose the set of `nonPrincipals` is not empty.
  rw [← nonPrincipals_eq_empty_iff, Set.eq_empty_iff_forall_not_mem]
  intro J hJ
  -- We will show a maximal element `I ∈ nonPrincipals R` (which exists by Zorn) is prime.
  obtain ⟨I, Ibad, -, Imax⟩ := zorn_nonempty_partialOrder₀ (nonPrincipals R) nonPrincipals_zorn _ hJ
  have Imax' : ∀ {J}, I < J → J.IsPrincipal := by
    intro J hJ
    by_contra He
    exact hJ.ne (Imax _ ((nonPrincipals_def R).2 He) hJ.le).symm
  by_cases hI1 : I = ⊤
  · subst hI1
    

Proof state:
case pos
R : Type u
M : Type v
inst✝ : CommRing R
H : ∀ (P : Ideal R), IsPrime P → IsPrincipal P
J : Ideal R
hJ : J ∈ nonPrincipals R
Ibad : ⊤ ∈ nonPrincipals R
Imax : ∀ z ∈ nonPrincipals R, ⊤ ≤ z → z = ⊤
Imax' : ∀ {J : Ideal R}, ⊤ < J → IsPrincipal J
⊢ False

Next tactic:
exact Ibad top_isPrincipal