l3lab/ntp-mathlib huggingface dataset:
theorem exists_reduced_fraction' {b : B} (hb : b ≠ 0) (hx : Irreducible x) :
    ∃ (a : R) (n : ℤ), ¬x ∣ a ∧ selfZPow x B n * algebraMap R B a = b := by
  obtain ⟨⟨a₀, y⟩, H⟩ := surj (Submonoid.powers x) b
  obtain ⟨d, hy⟩ := (Submonoid.mem_powers_iff y.1 x).mp y.2
  have ha₀ : a₀ ≠ 0 := by
    haveI :=
      @isDomain_of_le_nonZeroDivisors B _ R _ _ _ (Submonoid.powers x) _
        (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
    simp only [map_zero, ← hy, map_pow] at H
    apply ((injective_iff_map_eq_zero' (algebraMap R B)).mp _ a₀).mpr.mt
    

Proof state:
R : Type u_1
inst✝⁶ : CommRing R
x : R
B : Type u_2
inst✝⁵ : CommRing B
inst✝⁴ : Algebra R B
inst✝³ : IsLocalization.Away x B
inst✝² : IsDomain R
inst✝¹ : NormalizationMonoid R
inst✝ : UniqueFactorizationMonoid R
b : B
hb : b ≠ 0
hx : Irreducible x
a₀ : R
y : ↥(Submonoid.powers x)
d : ℕ
hy : x ^ d = ↑y
this : IsDomain B
H : b * (algebraMap R B) x ^ d = (algebraMap R B) a₀
⊢ ¬(algebraMap R B) a₀ = 0
R : Type u_1
inst✝⁶ : CommRing R
x : R
B : Type u_2
inst✝⁵ : CommRing B
inst✝⁴ : Algebra R B
inst✝³ : IsLocalization.Away x B
inst✝² : IsDomain R
inst✝¹ : NormalizationMonoid R
inst✝ : UniqueFactorizationMonoid R
b : B
hb : b ≠ 0
hx : Irreducible x
a₀ : R
y : ↥(Submonoid.powers x)
d : ℕ
hy : x ^ d = ↑y
this : IsDomain B
H : b * (algebraMap R B) x ^ d = (algebraMap R B) a₀
⊢ Function.Injective ⇑(algebraMap R B)

Next tactic:
rw [← H]
theorem exists_reduced_fraction' {b : B} (hb : b ≠ 0) (hx : Irreducible x) :
    ∃ (a : R) (n : ℤ), ¬x ∣ a ∧ selfZPow x B n * algebraMap R B a = b := by
  obtain ⟨⟨a₀, y⟩, H⟩ := surj (Submonoid.powers x) b
  obtain ⟨d, hy⟩ := (Submonoid.mem_powers_iff y.1 x).mp y.2
  have ha₀ : a₀ ≠ 0 := by
    haveI :=
      @isDomain_of_le_nonZeroDivisors B _ R _ _ _ (Submonoid.powers x) _
        (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
    simp only [map_zero, ← hy, map_pow] at H
    apply ((injective_iff_map_eq_zero' (algebraMap R B)).mp _ a₀).mpr.mt
    rw [← H]
    

Proof state:
R : Type u_1
inst✝⁶ : CommRing R
x : R
B : Type u_2
inst✝⁵ : CommRing B
inst✝⁴ : Algebra R B
inst✝³ : IsLocalization.Away x B
inst✝² : IsDomain R
inst✝¹ : NormalizationMonoid R
inst✝ : UniqueFactorizationMonoid R
b : B
hb : b ≠ 0
hx : Irreducible x
a₀ : R
y : ↥(Submonoid.powers x)
d : ℕ
hy : x ^ d = ↑y
this : IsDomain B
H : b * (algebraMap R B) x ^ d = (algebraMap R B) a₀
⊢ ¬b * (algebraMap R B) x ^ d = 0
R : Type u_1
inst✝⁶ : CommRing R
x : R
B : Type u_2
inst✝⁵ : CommRing B
inst✝⁴ : Algebra R B
inst✝³ : IsLocalization.Away x B
inst✝² : IsDomain R
inst✝¹ : NormalizationMonoid R
inst✝ : UniqueFactorizationMonoid R
b : B
hb : b ≠ 0
hx : Irreducible x
a₀ : R
y : ↥(Submonoid.powers x)
d : ℕ
hy : x ^ d = ↑y
this : IsDomain B
H : b * (algebraMap R B) x ^ d = (algebraMap R B) a₀
⊢ Function.Injective ⇑(algebraMap R B)

Next tactic:
apply mul_ne_zero hb (pow_ne_zero _ _)
theorem exists_reduced_fraction' {b : B} (hb : b ≠ 0) (hx : Irreducible x) :
    ∃ (a : R) (n : ℤ), ¬x ∣ a ∧ selfZPow x B n * algebraMap R B a = b := by
  obtain ⟨⟨a₀, y⟩, H⟩ := surj (Submonoid.powers x) b
  obtain ⟨d, hy⟩ := (Submonoid.mem_powers_iff y.1 x).mp y.2
  have ha₀ : a₀ ≠ 0 := by
    haveI :=
      @isDomain_of_le_nonZeroDivisors B _ R _ _ _ (Submonoid.powers x) _
        (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
    simp only [map_zero, ← hy, map_pow] at H
    apply ((injective_iff_map_eq_zero' (algebraMap R B)).mp _ a₀).mpr.mt
    rw [← H]
    apply mul_ne_zero hb (pow_ne_zero _ _)
    

Proof state:
R : Type u_1
inst✝⁶ : CommRing R
x : R
B : Type u_2
inst✝⁵ : CommRing B
inst✝⁴ : Algebra R B
inst✝³ : IsLocalization.Away x B
inst✝² : IsDomain R
inst✝¹ : NormalizationMonoid R
inst✝ : UniqueFactorizationMonoid R
b : B
hb : b ≠ 0
hx : Irreducible x
a₀ : R
y : ↥(Submonoid.powers x)
d : ℕ
hy : x ^ d = ↑y
this : IsDomain B
H : b * (algebraMap R B) x ^ d = (algebraMap R B) a₀
⊢ (algebraMap R B) x ≠ 0
R : Type u_1
inst✝⁶ : CommRing R
x : R
B : Type u_2
inst✝⁵ : CommRing B
inst✝⁴ : Algebra R B
inst✝³ : IsLocalization.Away x B
inst✝² : IsDomain R
inst✝¹ : NormalizationMonoid R
inst✝ : UniqueFactorizationMonoid R
b : B
hb : b ≠ 0
hx : Irreducible x
a₀ : R
y : ↥(Submonoid.powers x)
d : ℕ
hy : x ^ d = ↑y
this : IsDomain B
H : b * (algebraMap R B) x ^ d = (algebraMap R B) a₀
⊢ Function.Injective ⇑(algebraMap R B)

Next tactic:
exact
      IsLocalization.to_map_ne_zero_of_mem_nonZeroDivisors B
        (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
        (mem_nonZeroDivisors_iff_ne_zero.mpr hx.ne_zero)
theorem exists_reduced_fraction' {b : B} (hb : b ≠ 0) (hx : Irreducible x) :
    ∃ (a : R) (n : ℤ), ¬x ∣ a ∧ selfZPow x B n * algebraMap R B a = b := by
  obtain ⟨⟨a₀, y⟩, H⟩ := surj (Submonoid.powers x) b
  obtain ⟨d, hy⟩ := (Submonoid.mem_powers_iff y.1 x).mp y.2
  have ha₀ : a₀ ≠ 0 := by
    haveI :=
      @isDomain_of_le_nonZeroDivisors B _ R _ _ _ (Submonoid.powers x) _
        (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
    simp only [map_zero, ← hy, map_pow] at H
    apply ((injective_iff_map_eq_zero' (algebraMap R B)).mp _ a₀).mpr.mt
    rw [← H]
    apply mul_ne_zero hb (pow_ne_zero _ _)
    exact
      IsLocalization.to_map_ne_zero_of_mem_nonZeroDivisors B
        (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
        (mem_nonZeroDivisors_iff_ne_zero.mpr hx.ne_zero)
    

Proof state:
R : Type u_1
inst✝⁶ : CommRing R
x : R
B : Type u_2
inst✝⁵ : CommRing B
inst✝⁴ : Algebra R B
inst✝³ : IsLocalization.Away x B
inst✝² : IsDomain R
inst✝¹ : NormalizationMonoid R
inst✝ : UniqueFactorizationMonoid R
b : B
hb : b ≠ 0
hx : Irreducible x
a₀ : R
y : ↥(Submonoid.powers x)
d : ℕ
hy : x ^ d = ↑y
this : IsDomain B
H : b * (algebraMap R B) x ^ d = (algebraMap R B) a₀
⊢ Function.Injective ⇑(algebraMap R B)

Next tactic:
exact IsLocalization.injective B (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
theorem exists_reduced_fraction' {b : B} (hb : b ≠ 0) (hx : Irreducible x) :
    ∃ (a : R) (n : ℤ), ¬x ∣ a ∧ selfZPow x B n * algebraMap R B a = b := by
  obtain ⟨⟨a₀, y⟩, H⟩ := surj (Submonoid.powers x) b
  obtain ⟨d, hy⟩ := (Submonoid.mem_powers_iff y.1 x).mp y.2
  have ha₀ : a₀ ≠ 0 := by
    haveI :=
      @isDomain_of_le_nonZeroDivisors B _ R _ _ _ (Submonoid.powers x) _
        (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
    simp only [map_zero, ← hy, map_pow] at H
    apply ((injective_iff_map_eq_zero' (algebraMap R B)).mp _ a₀).mpr.mt
    rw [← H]
    apply mul_ne_zero hb (pow_ne_zero _ _)
    exact
      IsLocalization.to_map_ne_zero_of_mem_nonZeroDivisors B
        (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
        (mem_nonZeroDivisors_iff_ne_zero.mpr hx.ne_zero)
    exact IsLocalization.injective B (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
  

Proof state:
case intro.mk.intro
R : Type u_1
inst✝⁶ : CommRing R
x : R
B : Type u_2
inst✝⁵ : CommRing B
inst✝⁴ : Algebra R B
inst✝³ : IsLocalization.Away x B
inst✝² : IsDomain R
inst✝¹ : NormalizationMonoid R
inst✝ : UniqueFactorizationMonoid R
b : B
hb : b ≠ 0
hx : Irreducible x
a₀ : R
y : ↥(Submonoid.powers x)
H : b * (algebraMap R B) ↑(a₀, y).2 = (algebraMap R B) (a₀, y).1
d : ℕ
hy : x ^ d = ↑y
ha₀ : a₀ ≠ 0
⊢ ∃ a n, ¬x ∣ a ∧ selfZPow x B n * (algebraMap R B) a = b

Next tactic:
simp only [← hy] at H
theorem exists_reduced_fraction' {b : B} (hb : b ≠ 0) (hx : Irreducible x) :
    ∃ (a : R) (n : ℤ), ¬x ∣ a ∧ selfZPow x B n * algebraMap R B a = b := by
  obtain ⟨⟨a₀, y⟩, H⟩ := surj (Submonoid.powers x) b
  obtain ⟨d, hy⟩ := (Submonoid.mem_powers_iff y.1 x).mp y.2
  have ha₀ : a₀ ≠ 0 := by
    haveI :=
      @isDomain_of_le_nonZeroDivisors B _ R _ _ _ (Submonoid.powers x) _
        (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
    simp only [map_zero, ← hy, map_pow] at H
    apply ((injective_iff_map_eq_zero' (algebraMap R B)).mp _ a₀).mpr.mt
    rw [← H]
    apply mul_ne_zero hb (pow_ne_zero _ _)
    exact
      IsLocalization.to_map_ne_zero_of_mem_nonZeroDivisors B
        (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
        (mem_nonZeroDivisors_iff_ne_zero.mpr hx.ne_zero)
    exact IsLocalization.injective B (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
  simp only [← hy] at H
  

Proof state:
case intro.mk.intro
R : Type u_1
inst✝⁶ : CommRing R
x : R
B : Type u_2
inst✝⁵ : CommRing B
inst✝⁴ : Algebra R B
inst✝³ : IsLocalization.Away x B
inst✝² : IsDomain R
inst✝¹ : NormalizationMonoid R
inst✝ : UniqueFactorizationMonoid R
b : B
hb : b ≠ 0
hx : Irreducible x
a₀ : R
y : ↥(Submonoid.powers x)
d : ℕ
hy : x ^ d = ↑y
ha₀ : a₀ ≠ 0
H : b * (algebraMap R B) (x ^ d) = (algebraMap R B) a₀
⊢ ∃ a n, ¬x ∣ a ∧ selfZPow x B n * (algebraMap R B) a = b

Next tactic:
classical
  obtain ⟨m, a, hyp1, hyp2⟩ := max_power_factor ha₀ hx
  refine' ⟨a, m - d, _⟩
  rw [← mk'_one (M := Submonoid.powers x) B, selfZPow_pow_sub, selfZPow_coe_nat, selfZPow_coe_nat,
    ← map_pow _ _ d, mul_comm _ b, H, hyp2, map_mul, map_pow _ _ m]
  exact ⟨hyp1, congr_arg _ (IsLocalization.mk'_one _ _)⟩
theorem exists_reduced_fraction' {b : B} (hb : b ≠ 0) (hx : Irreducible x) :
    ∃ (a : R) (n : ℤ), ¬x ∣ a ∧ selfZPow x B n * algebraMap R B a = b := by
  obtain ⟨⟨a₀, y⟩, H⟩ := surj (Submonoid.powers x) b
  obtain ⟨d, hy⟩ := (Submonoid.mem_powers_iff y.1 x).mp y.2
  have ha₀ : a₀ ≠ 0 := by
    haveI :=
      @isDomain_of_le_nonZeroDivisors B _ R _ _ _ (Submonoid.powers x) _
        (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
    simp only [map_zero, ← hy, map_pow] at H
    apply ((injective_iff_map_eq_zero' (algebraMap R B)).mp _ a₀).mpr.mt
    rw [← H]
    apply mul_ne_zero hb (pow_ne_zero _ _)
    exact
      IsLocalization.to_map_ne_zero_of_mem_nonZeroDivisors B
        (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
        (mem_nonZeroDivisors_iff_ne_zero.mpr hx.ne_zero)
    exact IsLocalization.injective B (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
  simp only [← hy] at H
  classical
  

Proof state:
case intro.mk.intro
R : Type u_1
inst✝⁶ : CommRing R
x : R
B : Type u_2
inst✝⁵ : CommRing B
inst✝⁴ : Algebra R B
inst✝³ : IsLocalization.Away x B
inst✝² : IsDomain R
inst✝¹ : NormalizationMonoid R
inst✝ : UniqueFactorizationMonoid R
b : B
hb : b ≠ 0
hx : Irreducible x
a₀ : R
y : ↥(Submonoid.powers x)
d : ℕ
hy : x ^ d = ↑y
ha₀ : a₀ ≠ 0
H : b * (algebraMap R B) (x ^ d) = (algebraMap R B) a₀
⊢ ∃ a n, ¬x ∣ a ∧ selfZPow x B n * (algebraMap R B) a = b

Next tactic:
obtain ⟨m, a, hyp1, hyp2⟩ := max_power_factor ha₀ hx
theorem exists_reduced_fraction' {b : B} (hb : b ≠ 0) (hx : Irreducible x) :
    ∃ (a : R) (n : ℤ), ¬x ∣ a ∧ selfZPow x B n * algebraMap R B a = b := by
  obtain ⟨⟨a₀, y⟩, H⟩ := surj (Submonoid.powers x) b
  obtain ⟨d, hy⟩ := (Submonoid.mem_powers_iff y.1 x).mp y.2
  have ha₀ : a₀ ≠ 0 := by
    haveI :=
      @isDomain_of_le_nonZeroDivisors B _ R _ _ _ (Submonoid.powers x) _
        (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
    simp only [map_zero, ← hy, map_pow] at H
    apply ((injective_iff_map_eq_zero' (algebraMap R B)).mp _ a₀).mpr.mt
    rw [← H]
    apply mul_ne_zero hb (pow_ne_zero _ _)
    exact
      IsLocalization.to_map_ne_zero_of_mem_nonZeroDivisors B
        (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
        (mem_nonZeroDivisors_iff_ne_zero.mpr hx.ne_zero)
    exact IsLocalization.injective B (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
  simp only [← hy] at H
  classical
  obtain ⟨m, a, hyp1, hyp2⟩ := max_power_factor ha₀ hx
  

Proof state:
case intro.mk.intro.intro.intro.intro
R : Type u_1
inst✝⁶ : CommRing R
x : R
B : Type u_2
inst✝⁵ : CommRing B
inst✝⁴ : Algebra R B
inst✝³ : IsLocalization.Away x B
inst✝² : IsDomain R
inst✝¹ : NormalizationMonoid R
inst✝ : UniqueFactorizationMonoid R
b : B
hb : b ≠ 0
hx : Irreducible x
a₀ : R
y : ↥(Submonoid.powers x)
d : ℕ
hy : x ^ d = ↑y
ha₀ : a₀ ≠ 0
H : b * (algebraMap R B) (x ^ d) = (algebraMap R B) a₀
m : ℕ
a : R
hyp1 : ¬x ∣ a
hyp2 : a₀ = x ^ m * a
⊢ ∃ a n, ¬x ∣ a ∧ selfZPow x B n * (algebraMap R B) a = b

Next tactic:
refine' ⟨a, m - d, _⟩
theorem exists_reduced_fraction' {b : B} (hb : b ≠ 0) (hx : Irreducible x) :
    ∃ (a : R) (n : ℤ), ¬x ∣ a ∧ selfZPow x B n * algebraMap R B a = b := by
  obtain ⟨⟨a₀, y⟩, H⟩ := surj (Submonoid.powers x) b
  obtain ⟨d, hy⟩ := (Submonoid.mem_powers_iff y.1 x).mp y.2
  have ha₀ : a₀ ≠ 0 := by
    haveI :=
      @isDomain_of_le_nonZeroDivisors B _ R _ _ _ (Submonoid.powers x) _
        (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
    simp only [map_zero, ← hy, map_pow] at H
    apply ((injective_iff_map_eq_zero' (algebraMap R B)).mp _ a₀).mpr.mt
    rw [← H]
    apply mul_ne_zero hb (pow_ne_zero _ _)
    exact
      IsLocalization.to_map_ne_zero_of_mem_nonZeroDivisors B
        (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
        (mem_nonZeroDivisors_iff_ne_zero.mpr hx.ne_zero)
    exact IsLocalization.injective B (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
  simp only [← hy] at H
  classical
  obtain ⟨m, a, hyp1, hyp2⟩ := max_power_factor ha₀ hx
  refine' ⟨a, m - d, _⟩
  

Proof state:
case intro.mk.intro.intro.intro.intro
R : Type u_1
inst✝⁶ : CommRing R
x : R
B : Type u_2
inst✝⁵ : CommRing B
inst✝⁴ : Algebra R B
inst✝³ : IsLocalization.Away x B
inst✝² : IsDomain R
inst✝¹ : NormalizationMonoid R
inst✝ : UniqueFactorizationMonoid R
b : B
hb : b ≠ 0
hx : Irreducible x
a₀ : R
y : ↥(Submonoid.powers x)
d : ℕ
hy : x ^ d = ↑y
ha₀ : a₀ ≠ 0
H : b * (algebraMap R B) (x ^ d) = (algebraMap R B) a₀
m : ℕ
a : R
hyp1 : ¬x ∣ a
hyp2 : a₀ = x ^ m * a
⊢ ¬x ∣ a ∧ selfZPow x B (↑m - ↑d) * (algebraMap R B) a = b

Next tactic:
rw [← mk'_one (M := Submonoid.powers x) B, selfZPow_pow_sub, selfZPow_coe_nat, selfZPow_coe_nat,
    ← map_pow _ _ d, mul_comm _ b, H, hyp2, map_mul, map_pow _ _ m]
theorem exists_reduced_fraction' {b : B} (hb : b ≠ 0) (hx : Irreducible x) :
    ∃ (a : R) (n : ℤ), ¬x ∣ a ∧ selfZPow x B n * algebraMap R B a = b := by
  obtain ⟨⟨a₀, y⟩, H⟩ := surj (Submonoid.powers x) b
  obtain ⟨d, hy⟩ := (Submonoid.mem_powers_iff y.1 x).mp y.2
  have ha₀ : a₀ ≠ 0 := by
    haveI :=
      @isDomain_of_le_nonZeroDivisors B _ R _ _ _ (Submonoid.powers x) _
        (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
    simp only [map_zero, ← hy, map_pow] at H
    apply ((injective_iff_map_eq_zero' (algebraMap R B)).mp _ a₀).mpr.mt
    rw [← H]
    apply mul_ne_zero hb (pow_ne_zero _ _)
    exact
      IsLocalization.to_map_ne_zero_of_mem_nonZeroDivisors B
        (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
        (mem_nonZeroDivisors_iff_ne_zero.mpr hx.ne_zero)
    exact IsLocalization.injective B (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero)
  simp only [← hy] at H
  classical
  obtain ⟨m, a, hyp1, hyp2⟩ := max_power_factor ha₀ hx
  refine' ⟨a, m - d, _⟩
  rw [← mk'_one (M := Submonoid.powers x) B, selfZPow_pow_sub, selfZPow_coe_nat, selfZPow_coe_nat,
    ← map_pow _ _ d, mul_comm _ b, H, hyp2, map_mul, map_pow _ _ m]
  

Proof state:
case intro.mk.intro.intro.intro.intro
R : Type u_1
inst✝⁶ : CommRing R
x : R
B : Type u_2
inst✝⁵ : CommRing B
inst✝⁴ : Algebra R B
inst✝³ : IsLocalization.Away x B
inst✝² : IsDomain R
inst✝¹ : NormalizationMonoid R
inst✝ : UniqueFactorizationMonoid R
b : B
hb : b ≠ 0
hx : Irreducible x
a₀ : R
y : ↥(Submonoid.powers x)
d : ℕ
hy : x ^ d = ↑y
ha₀ : a₀ ≠ 0
H : b * (algebraMap R B) (x ^ d) = (algebraMap R B) a₀
m : ℕ
a : R
hyp1 : ¬x ∣ a
hyp2 : a₀ = x ^ m * a
⊢ ¬x ∣ a ∧ (algebraMap R B) x ^ m * mk' B a 1 = (algebraMap R B) x ^ m * (algebraMap R B) a

Next tactic:
exact ⟨hyp1, congr_arg _ (IsLocalization.mk'_one _ _)⟩
theorem Rat.RingOfIntegers.isUnit_iff {x : 𝓞 ℚ} : IsUnit x ↔ (x : ℚ) = 1 ∨ (x : ℚ) = -1 := by
  

Proof state:
x : ↥(𝓞 ℚ)
⊢ IsUnit x ↔ ↑x = 1 ∨ ↑x = -1

Next tactic:
simp_rw [(isUnit_map_iff (Rat.ringOfIntegersEquiv : 𝓞 ℚ →+* ℤ) x).symm, Int.isUnit_iff,
    RingEquiv.coe_toRingHom, RingEquiv.map_eq_one_iff, RingEquiv.map_eq_neg_one_iff, ←
    Subtype.coe_injective.eq_iff]
theorem Rat.RingOfIntegers.isUnit_iff {x : 𝓞 ℚ} : IsUnit x ↔ (x : ℚ) = 1 ∨ (x : ℚ) = -1 := by
  simp_rw [(isUnit_map_iff (Rat.ringOfIntegersEquiv : 𝓞 ℚ →+* ℤ) x).symm, Int.isUnit_iff,
    RingEquiv.coe_toRingHom, RingEquiv.map_eq_one_iff, RingEquiv.map_eq_neg_one_iff, ←
    Subtype.coe_injective.eq_iff]; 

Proof state:
x : ↥(𝓞 ℚ)
⊢ ↑x = ↑1 ∨ ↑x = ↑(-1) ↔ ↑x = 1 ∨ ↑x = -1

Next tactic:
rfl
theorem NumberField.isUnit_iff_norm [NumberField K] {x : 𝓞 K} :
    IsUnit x ↔ |(RingOfIntegers.norm ℚ x : ℚ)| = 1 := by
  

Proof state:
K : Type u_1
inst✝¹ : Field K
inst✝ : NumberField K
x : ↥(𝓞 K)
⊢ IsUnit x ↔ |↑((RingOfIntegers.norm ℚ) x)| = 1

Next tactic:
convert (RingOfIntegers.isUnit_norm ℚ (F := K)).symm
theorem NumberField.isUnit_iff_norm [NumberField K] {x : 𝓞 K} :
    IsUnit x ↔ |(RingOfIntegers.norm ℚ x : ℚ)| = 1 := by
  convert (RingOfIntegers.isUnit_norm ℚ (F := K)).symm
  

Proof state:
case h.e'_2.a
K : Type u_1
inst✝¹ : Field K
inst✝ : NumberField K
x : ↥(𝓞 K)
⊢ |↑((RingOfIntegers.norm ℚ) x)| = 1 ↔ IsUnit ((RingOfIntegers.norm ℚ) x)

Next tactic:
rw [← abs_one, abs_eq_abs, ← Rat.RingOfIntegers.isUnit_iff]
theorem coe_injective : Function.Injective ((↑) : (𝓞 K)ˣ → K) :=
  fun _ _ h => by 

Proof state:
K : Type u_1
inst✝ : Field K
x✝¹ x✝ : (↥(𝓞 K))ˣ
h : (fun x => ↑↑x) x✝¹ = (fun x => ↑↑x) x✝
⊢ x✝¹ = x✝

Next tactic:
rwa [SetLike.coe_eq_coe, Units.eq_iff] at h
theorem coe_pow (x : (𝓞 K)ˣ) (n : ℕ) : (↑(x ^ n) : K) = (x : K) ^ n := by
  

Proof state:
K : Type u_1
inst✝ : Field K
x : (↥(𝓞 K))ˣ
n : ℕ
⊢ ↑↑(x ^ n) = ↑↑x ^ n

Next tactic:
rw [← SubmonoidClass.coe_pow, ← val_pow_eq_pow_val]
theorem coe_zpow (x : (𝓞 K)ˣ) (n : ℤ) : (↑(x ^ n) : K) = (x : K) ^ n := by
  

Proof state:
K : Type u_1
inst✝ : Field K
x : (↥(𝓞 K))ˣ
n : ℤ
⊢ ↑↑(x ^ n) = ↑↑x ^ n

Next tactic:
change ((Units.coeHom K).comp (map (algebraMap (𝓞 K) K))) (x ^ n) = _
theorem coe_zpow (x : (𝓞 K)ˣ) (n : ℤ) : (↑(x ^ n) : K) = (x : K) ^ n := by
  change ((Units.coeHom K).comp (map (algebraMap (𝓞 K) K))) (x ^ n) = _
  

Proof state:
K : Type u_1
inst✝ : Field K
x : (↥(𝓞 K))ˣ
n : ℤ
⊢ (MonoidHom.comp (coeHom K) (map ↑(algebraMap (↥(𝓞 K)) K))) (x ^ n) = ↑↑x ^ n

Next tactic:
exact map_zpow _ x n
theorem mem_torsion {x : (𝓞 K)ˣ} [NumberField K] :
    x ∈ torsion K ↔ ∀ w : InfinitePlace K, w x = 1 := by
  

Proof state:
K : Type u_1
inst✝¹ : Field K
x : (↥(𝓞 K))ˣ
inst✝ : NumberField K
⊢ x ∈ torsion K ↔ ∀ (w : InfinitePlace K), w ↑↑x = 1

Next tactic:
rw [eq_iff_eq (x : K) 1, torsion, CommGroup.mem_torsion, isOfFinOrder_iff_pow_eq_one]
theorem mem_torsion {x : (𝓞 K)ˣ} [NumberField K] :
    x ∈ torsion K ↔ ∀ w : InfinitePlace K, w x = 1 := by
  rw [eq_iff_eq (x : K) 1, torsion, CommGroup.mem_torsion, isOfFinOrder_iff_pow_eq_one]
  

Proof state:
K : Type u_1
inst✝¹ : Field K
x : (↥(𝓞 K))ˣ
inst✝ : NumberField K
⊢ (∃ n, 0 < n ∧ x ^ n = 1) ↔ ∀ (φ : K →+* ℂ), ‖φ ↑↑x‖ = 1

Next tactic:
refine ⟨fun ⟨n, h_pos, h_eq⟩ φ => ?_, fun h => ?_⟩
theorem mem_torsion {x : (𝓞 K)ˣ} [NumberField K] :
    x ∈ torsion K ↔ ∀ w : InfinitePlace K, w x = 1 := by
  rw [eq_iff_eq (x : K) 1, torsion, CommGroup.mem_torsion, isOfFinOrder_iff_pow_eq_one]
  refine ⟨fun ⟨n, h_pos, h_eq⟩ φ => ?_, fun h => ?_⟩
  · 

Proof state:
case refine_1
K : Type u_1
inst✝¹ : Field K
x : (↥(𝓞 K))ˣ
inst✝ : NumberField K
x✝ : ∃ n, 0 < n ∧ x ^ n = 1
φ : K →+* ℂ
n : ℕ
h_pos : 0 < n
h_eq : x ^ n = 1
⊢ ‖φ ↑↑x‖ = 1

Next tactic:
refine norm_map_one_of_pow_eq_one φ.toMonoidHom (k := ⟨n, h_pos⟩) ?_
theorem mem_torsion {x : (𝓞 K)ˣ} [NumberField K] :
    x ∈ torsion K ↔ ∀ w : InfinitePlace K, w x = 1 := by
  rw [eq_iff_eq (x : K) 1, torsion, CommGroup.mem_torsion, isOfFinOrder_iff_pow_eq_one]
  refine ⟨fun ⟨n, h_pos, h_eq⟩ φ => ?_, fun h => ?_⟩
  · refine norm_map_one_of_pow_eq_one φ.toMonoidHom (k := ⟨n, h_pos⟩) ?_
    

Proof state:
case refine_1
K : Type u_1
inst✝¹ : Field K
x : (↥(𝓞 K))ˣ
inst✝ : NumberField K
x✝ : ∃ n, 0 < n ∧ x ^ n = 1
φ : K →+* ℂ
n : ℕ
h_pos : 0 < n
h_eq : x ^ n = 1
⊢ ↑↑x ^ ↑{ val := n, property := h_pos } = 1

Next tactic:
rw [PNat.mk_coe, ← coe_pow, h_eq, coe_one]
theorem mem_torsion {x : (𝓞 K)ˣ} [NumberField K] :
    x ∈ torsion K ↔ ∀ w : InfinitePlace K, w x = 1 := by
  rw [eq_iff_eq (x : K) 1, torsion, CommGroup.mem_torsion, isOfFinOrder_iff_pow_eq_one]
  refine ⟨fun ⟨n, h_pos, h_eq⟩ φ => ?_, fun h => ?_⟩
  · refine norm_map_one_of_pow_eq_one φ.toMonoidHom (k := ⟨n, h_pos⟩) ?_
    rw [PNat.mk_coe, ← coe_pow, h_eq, coe_one]
  · 

Proof state:
case refine_2
K : Type u_1
inst✝¹ : Field K
x : (↥(𝓞 K))ˣ
inst✝ : NumberField K
h : ∀ (φ : K →+* ℂ), ‖φ ↑↑x‖ = 1
⊢ ∃ n, 0 < n ∧ x ^ n = 1

Next tactic:
obtain ⟨n, hn, hx⟩ := Embeddings.pow_eq_one_of_norm_eq_one K ℂ x.val.prop h
theorem mem_torsion {x : (𝓞 K)ˣ} [NumberField K] :
    x ∈ torsion K ↔ ∀ w : InfinitePlace K, w x = 1 := by
  rw [eq_iff_eq (x : K) 1, torsion, CommGroup.mem_torsion, isOfFinOrder_iff_pow_eq_one]
  refine ⟨fun ⟨n, h_pos, h_eq⟩ φ => ?_, fun h => ?_⟩
  · refine norm_map_one_of_pow_eq_one φ.toMonoidHom (k := ⟨n, h_pos⟩) ?_
    rw [PNat.mk_coe, ← coe_pow, h_eq, coe_one]
  · obtain ⟨n, hn, hx⟩ := Embeddings.pow_eq_one_of_norm_eq_one K ℂ x.val.prop h
    

Proof state:
case refine_2.intro.intro
K : Type u_1
inst✝¹ : Field K
x : (↥(𝓞 K))ˣ
inst✝ : NumberField K
h : ∀ (φ : K →+* ℂ), ‖φ ↑↑x‖ = 1
n : ℕ
hn : 0 < n
hx : ↑↑x ^ n = 1
⊢ ∃ n, 0 < n ∧ x ^ n = 1

Next tactic:
exact ⟨n, hn, by ext; rw [coe_pow, hx, coe_one]⟩
theorem mem_torsion {x : (𝓞 K)ˣ} [NumberField K] :
    x ∈ torsion K ↔ ∀ w : InfinitePlace K, w x = 1 := by
  rw [eq_iff_eq (x : K) 1, torsion, CommGroup.mem_torsion, isOfFinOrder_iff_pow_eq_one]
  refine ⟨fun ⟨n, h_pos, h_eq⟩ φ => ?_, fun h => ?_⟩
  · refine norm_map_one_of_pow_eq_one φ.toMonoidHom (k := ⟨n, h_pos⟩) ?_
    rw [PNat.mk_coe, ← coe_pow, h_eq, coe_one]
  · obtain ⟨n, hn, hx⟩ := Embeddings.pow_eq_one_of_norm_eq_one K ℂ x.val.prop h
    exact ⟨n, hn, by 

Proof state:
K : Type u_1
inst✝¹ : Field K
x : (↥(𝓞 K))ˣ
inst✝ : NumberField K
h : ∀ (φ : K →+* ℂ), ‖φ ↑↑x‖ = 1
n : ℕ
hn : 0 < n
hx : ↑↑x ^ n = 1
⊢ x ^ n = 1

Next tactic:
ext
theorem mem_torsion {x : (𝓞 K)ˣ} [NumberField K] :
    x ∈ torsion K ↔ ∀ w : InfinitePlace K, w x = 1 := by
  rw [eq_iff_eq (x : K) 1, torsion, CommGroup.mem_torsion, isOfFinOrder_iff_pow_eq_one]
  refine ⟨fun ⟨n, h_pos, h_eq⟩ φ => ?_, fun h => ?_⟩
  · refine norm_map_one_of_pow_eq_one φ.toMonoidHom (k := ⟨n, h_pos⟩) ?_
    rw [PNat.mk_coe, ← coe_pow, h_eq, coe_one]
  · obtain ⟨n, hn, hx⟩ := Embeddings.pow_eq_one_of_norm_eq_one K ℂ x.val.prop h
    exact ⟨n, hn, by ext; 

Proof state:
case a.a
K : Type u_1
inst✝¹ : Field K
x : (↥(𝓞 K))ˣ
inst✝ : NumberField K
h : ∀ (φ : K →+* ℂ), ‖φ ↑↑x‖ = 1
n : ℕ
hn : 0 < n
hx : ↑↑x ^ n = 1
⊢ ↑↑(x ^ n) = ↑↑1

Next tactic:
rw [coe_pow, hx, coe_one]
/-- The torsion subgroup is finite. -/
instance [NumberField K] : Fintype (torsion K) := by
  

Proof state:
K : Type u_1
inst✝¹ : Field K
inst✝ : NumberField K
⊢ Fintype ↥(torsion K)

Next tactic:
refine @Fintype.ofFinite _ (Set.finite_coe_iff.mpr ?_)
/-- The torsion subgroup is finite. -/
instance [NumberField K] : Fintype (torsion K) := by
  refine @Fintype.ofFinite _ (Set.finite_coe_iff.mpr ?_)
  

Proof state:
K : Type u_1
inst✝¹ : Field K
inst✝ : NumberField K
⊢ Set.Finite ↑(torsion K)

Next tactic:
refine Set.Finite.of_finite_image ?_ ((coe_injective K).injOn _)
/-- The torsion subgroup is finite. -/
instance [NumberField K] : Fintype (torsion K) := by
  refine @Fintype.ofFinite _ (Set.finite_coe_iff.mpr ?_)
  refine Set.Finite.of_finite_image ?_ ((coe_injective K).injOn _)
  

Proof state:
K : Type u_1
inst✝¹ : Field K
inst✝ : NumberField K
⊢ Set.Finite ((fun x => ↑↑x) '' ↑(torsion K))

Next tactic:
refine (Embeddings.finite_of_norm_le K ℂ 1).subset
    (fun a ⟨u, ⟨h_tors, h_ua⟩⟩ => ⟨?_, fun φ => ?_⟩)
/-- The torsion subgroup is finite. -/
instance [NumberField K] : Fintype (torsion K) := by
  refine @Fintype.ofFinite _ (Set.finite_coe_iff.mpr ?_)
  refine Set.Finite.of_finite_image ?_ ((coe_injective K).injOn _)
  refine (Embeddings.finite_of_norm_le K ℂ 1).subset
    (fun a ⟨u, ⟨h_tors, h_ua⟩⟩ => ⟨?_, fun φ => ?_⟩)
  · 

Proof state:
case refine_1
K : Type u_1
inst✝¹ : Field K
inst✝ : NumberField K
a : K
x✝ : a ∈ (fun x => ↑↑x) '' ↑(torsion K)
u : (↥(𝓞 K))ˣ
h_tors : u ∈ ↑(torsion K)
h_ua : (fun x => ↑↑x) u = a
⊢ IsIntegral ℤ a

Next tactic:
rw [← h_ua]