l3lab/ntp-mathlib huggingface dataset:
theorem exists_sum_eq_one_iff_pairwise_coprime [DecidableEq I] (h : t.Nonempty) :
    (∃ μ : I → R, (∑ i in t, μ i * ∏ j in t \ {i}, s j) = 1) ↔
      Pairwise (IsCoprime on fun i : t ↦ s i) := by
  refine' h.cons_induction _ _
  · simp only [sum_singleton, Finset.sdiff_self, prod_empty, mul_one, exists_apply_eq,
               Pairwise, Ne.def, true_iff_iff]
    rintro a ⟨i, hi⟩ ⟨j, hj⟩ h
    rw [Finset.mem_singleton] at hi hj
    

Proof state:
case refine'_1.mk.mk
R : Type u
I : Type v
inst✝¹ : CommSemiring R
x y z : R
s : I → R
t : Finset I
inst✝ : DecidableEq I
h✝ : Finset.Nonempty t
a i : I
hi✝ : i ∈ {a}
hi : i = a
j : I
hj✝ : j ∈ {a}
hj : j = a
h : ¬{ val := i, property := hi✝ } = { val := j, property := hj✝ }
⊢ (IsCoprime on fun i => s ↑i) { val := i, property := hi✝ } { val := j, property := hj✝ }

Next tactic:
simp [hi, hj] at h
theorem exists_sum_eq_one_iff_pairwise_coprime [DecidableEq I] (h : t.Nonempty) :
    (∃ μ : I → R, (∑ i in t, μ i * ∏ j in t \ {i}, s j) = 1) ↔
      Pairwise (IsCoprime on fun i : t ↦ s i) := by
  refine' h.cons_induction _ _
  · simp only [sum_singleton, Finset.sdiff_self, prod_empty, mul_one, exists_apply_eq,
               Pairwise, Ne.def, true_iff_iff]
    rintro a ⟨i, hi⟩ ⟨j, hj⟩ h
    rw [Finset.mem_singleton] at hi hj
    simp [hi, hj] at h
  

Proof state:
case refine'_2
R : Type u
I : Type v
inst✝¹ : CommSemiring R
x y z : R
s : I → R
t : Finset I
inst✝ : DecidableEq I
h : Finset.Nonempty t
⊢ ∀ ⦃a : I⦄ (s_1 : Finset I) (h : a ∉ s_1),
    Finset.Nonempty s_1 →
      ((∃ μ, ∑ i in s_1, μ i * ∏ j in s_1 \ {i}, s j = 1) ↔ Pairwise (IsCoprime on fun i => s ↑i)) →
        ((∃ μ, ∑ i in cons a s_1 h, μ i * ∏ j in cons a s_1 h \ {i}, s j = 1) ↔ Pairwise (IsCoprime on fun i => s ↑i))

Next tactic:
intro a t hat h ih
theorem exists_sum_eq_one_iff_pairwise_coprime [DecidableEq I] (h : t.Nonempty) :
    (∃ μ : I → R, (∑ i in t, μ i * ∏ j in t \ {i}, s j) = 1) ↔
      Pairwise (IsCoprime on fun i : t ↦ s i) := by
  refine' h.cons_induction _ _
  · simp only [sum_singleton, Finset.sdiff_self, prod_empty, mul_one, exists_apply_eq,
               Pairwise, Ne.def, true_iff_iff]
    rintro a ⟨i, hi⟩ ⟨j, hj⟩ h
    rw [Finset.mem_singleton] at hi hj
    simp [hi, hj] at h
  intro a t hat h ih
  

Proof state:
case refine'_2
R : Type u
I : Type v
inst✝¹ : CommSemiring R
x y z : R
s : I → R
t✝ : Finset I
inst✝ : DecidableEq I
h✝ : Finset.Nonempty t✝
a : I
t : Finset I
hat : a ∉ t
h : Finset.Nonempty t
ih : (∃ μ, ∑ i in t, μ i * ∏ j in t \ {i}, s j = 1) ↔ Pairwise (IsCoprime on fun i => s ↑i)
⊢ (∃ μ, ∑ i in cons a t hat, μ i * ∏ j in cons a t hat \ {i}, s j = 1) ↔ Pairwise (IsCoprime on fun i => s ↑i)

Next tactic:
rw [pairwise_cons']
theorem exists_sum_eq_one_iff_pairwise_coprime [DecidableEq I] (h : t.Nonempty) :
    (∃ μ : I → R, (∑ i in t, μ i * ∏ j in t \ {i}, s j) = 1) ↔
      Pairwise (IsCoprime on fun i : t ↦ s i) := by
  refine' h.cons_induction _ _
  · simp only [sum_singleton, Finset.sdiff_self, prod_empty, mul_one, exists_apply_eq,
               Pairwise, Ne.def, true_iff_iff]
    rintro a ⟨i, hi⟩ ⟨j, hj⟩ h
    rw [Finset.mem_singleton] at hi hj
    simp [hi, hj] at h
  intro a t hat h ih
  rw [pairwise_cons']
  

Proof state:
case refine'_2
R : Type u
I : Type v
inst✝¹ : CommSemiring R
x y z : R
s : I → R
t✝ : Finset I
inst✝ : DecidableEq I
h✝ : Finset.Nonempty t✝
a : I
t : Finset I
hat : a ∉ t
h : Finset.Nonempty t
ih : (∃ μ, ∑ i in t, μ i * ∏ j in t \ {i}, s j = 1) ↔ Pairwise (IsCoprime on fun i => s ↑i)
⊢ (∃ μ, ∑ i in cons a t hat, μ i * ∏ j in cons a t hat \ {i}, s j = 1) ↔
    Pairwise (IsCoprime on fun a => s ↑a) ∧ ∀ b ∈ t, IsCoprime (s a) (s b) ∧ IsCoprime (s b) (s a)

Next tactic:
have mem : ∀ x ∈ t, a ∈ insert a t \ {x} := fun x hx ↦ by
    rw [mem_sdiff, mem_singleton]
    refine ⟨mem_insert_self _ _, fun ha ↦ hat (ha ▸ hx)⟩
theorem exists_sum_eq_one_iff_pairwise_coprime [DecidableEq I] (h : t.Nonempty) :
    (∃ μ : I → R, (∑ i in t, μ i * ∏ j in t \ {i}, s j) = 1) ↔
      Pairwise (IsCoprime on fun i : t ↦ s i) := by
  refine' h.cons_induction _ _
  · simp only [sum_singleton, Finset.sdiff_self, prod_empty, mul_one, exists_apply_eq,
               Pairwise, Ne.def, true_iff_iff]
    rintro a ⟨i, hi⟩ ⟨j, hj⟩ h
    rw [Finset.mem_singleton] at hi hj
    simp [hi, hj] at h
  intro a t hat h ih
  rw [pairwise_cons']
  have mem : ∀ x ∈ t, a ∈ insert a t \ {x} := fun x hx ↦ by
    

Proof state:
R : Type u
I : Type v
inst✝¹ : CommSemiring R
x✝ y z : R
s : I → R
t✝ : Finset I
inst✝ : DecidableEq I
h✝ : Finset.Nonempty t✝
a : I
t : Finset I
hat : a ∉ t
h : Finset.Nonempty t
ih : (∃ μ, ∑ i in t, μ i * ∏ j in t \ {i}, s j = 1) ↔ Pairwise (IsCoprime on fun i => s ↑i)
x : I
hx : x ∈ t
⊢ a ∈ insert a t \ {x}

Next tactic:
rw [mem_sdiff, mem_singleton]
theorem exists_sum_eq_one_iff_pairwise_coprime [DecidableEq I] (h : t.Nonempty) :
    (∃ μ : I → R, (∑ i in t, μ i * ∏ j in t \ {i}, s j) = 1) ↔
      Pairwise (IsCoprime on fun i : t ↦ s i) := by
  refine' h.cons_induction _ _
  · simp only [sum_singleton, Finset.sdiff_self, prod_empty, mul_one, exists_apply_eq,
               Pairwise, Ne.def, true_iff_iff]
    rintro a ⟨i, hi⟩ ⟨j, hj⟩ h
    rw [Finset.mem_singleton] at hi hj
    simp [hi, hj] at h
  intro a t hat h ih
  rw [pairwise_cons']
  have mem : ∀ x ∈ t, a ∈ insert a t \ {x} := fun x hx ↦ by
    rw [mem_sdiff, mem_singleton]
    

Proof state:
R : Type u
I : Type v
inst✝¹ : CommSemiring R
x✝ y z : R
s : I → R
t✝ : Finset I
inst✝ : DecidableEq I
h✝ : Finset.Nonempty t✝
a : I
t : Finset I
hat : a ∉ t
h : Finset.Nonempty t
ih : (∃ μ, ∑ i in t, μ i * ∏ j in t \ {i}, s j = 1) ↔ Pairwise (IsCoprime on fun i => s ↑i)
x : I
hx : x ∈ t
⊢ a ∈ insert a t ∧ ¬a = x

Next tactic:
refine ⟨mem_insert_self _ _, fun ha ↦ hat (ha ▸ hx)⟩
theorem exists_sum_eq_one_iff_pairwise_coprime [DecidableEq I] (h : t.Nonempty) :
    (∃ μ : I → R, (∑ i in t, μ i * ∏ j in t \ {i}, s j) = 1) ↔
      Pairwise (IsCoprime on fun i : t ↦ s i) := by
  refine' h.cons_induction _ _
  · simp only [sum_singleton, Finset.sdiff_self, prod_empty, mul_one, exists_apply_eq,
               Pairwise, Ne.def, true_iff_iff]
    rintro a ⟨i, hi⟩ ⟨j, hj⟩ h
    rw [Finset.mem_singleton] at hi hj
    simp [hi, hj] at h
  intro a t hat h ih
  rw [pairwise_cons']
  have mem : ∀ x ∈ t, a ∈ insert a t \ {x} := fun x hx ↦ by
    rw [mem_sdiff, mem_singleton]
    refine ⟨mem_insert_self _ _, fun ha ↦ hat (ha ▸ hx)⟩
  

Proof state:
case refine'_2
R : Type u
I : Type v
inst✝¹ : CommSemiring R
x y z : R
s : I → R
t✝ : Finset I
inst✝ : DecidableEq I
h✝ : Finset.Nonempty t✝
a : I
t : Finset I
hat : a ∉ t
h : Finset.Nonempty t
ih : (∃ μ, ∑ i in t, μ i * ∏ j in t \ {i}, s j = 1) ↔ Pairwise (IsCoprime on fun i => s ↑i)
mem : ∀ x ∈ t, a ∈ insert a t \ {x}
⊢ (∃ μ, ∑ i in cons a t hat, μ i * ∏ j in cons a t hat \ {i}, s j = 1) ↔
    Pairwise (IsCoprime on fun a => s ↑a) ∧ ∀ b ∈ t, IsCoprime (s a) (s b) ∧ IsCoprime (s b) (s a)

Next tactic:
constructor
theorem exists_sum_eq_one_iff_pairwise_coprime [DecidableEq I] (h : t.Nonempty) :
    (∃ μ : I → R, (∑ i in t, μ i * ∏ j in t \ {i}, s j) = 1) ↔
      Pairwise (IsCoprime on fun i : t ↦ s i) := by
  refine' h.cons_induction _ _
  · simp only [sum_singleton, Finset.sdiff_self, prod_empty, mul_one, exists_apply_eq,
               Pairwise, Ne.def, true_iff_iff]
    rintro a ⟨i, hi⟩ ⟨j, hj⟩ h
    rw [Finset.mem_singleton] at hi hj
    simp [hi, hj] at h
  intro a t hat h ih
  rw [pairwise_cons']
  have mem : ∀ x ∈ t, a ∈ insert a t \ {x} := fun x hx ↦ by
    rw [mem_sdiff, mem_singleton]
    refine ⟨mem_insert_self _ _, fun ha ↦ hat (ha ▸ hx)⟩
  constructor
  · 

Proof state:
case refine'_2.mp
R : Type u
I : Type v
inst✝¹ : CommSemiring R
x y z : R
s : I → R
t✝ : Finset I
inst✝ : DecidableEq I
h✝ : Finset.Nonempty t✝
a : I
t : Finset I
hat : a ∉ t
h : Finset.Nonempty t
ih : (∃ μ, ∑ i in t, μ i * ∏ j in t \ {i}, s j = 1) ↔ Pairwise (IsCoprime on fun i => s ↑i)
mem : ∀ x ∈ t, a ∈ insert a t \ {x}
⊢ (∃ μ, ∑ i in cons a t hat, μ i * ∏ j in cons a t hat \ {i}, s j = 1) →
    Pairwise (IsCoprime on fun a => s ↑a) ∧ ∀ b ∈ t, IsCoprime (s a) (s b) ∧ IsCoprime (s b) (s a)

Next tactic:
rintro ⟨μ, hμ⟩
theorem exists_sum_eq_one_iff_pairwise_coprime [DecidableEq I] (h : t.Nonempty) :
    (∃ μ : I → R, (∑ i in t, μ i * ∏ j in t \ {i}, s j) = 1) ↔
      Pairwise (IsCoprime on fun i : t ↦ s i) := by
  refine' h.cons_induction _ _
  · simp only [sum_singleton, Finset.sdiff_self, prod_empty, mul_one, exists_apply_eq,
               Pairwise, Ne.def, true_iff_iff]
    rintro a ⟨i, hi⟩ ⟨j, hj⟩ h
    rw [Finset.mem_singleton] at hi hj
    simp [hi, hj] at h
  intro a t hat h ih
  rw [pairwise_cons']
  have mem : ∀ x ∈ t, a ∈ insert a t \ {x} := fun x hx ↦ by
    rw [mem_sdiff, mem_singleton]
    refine ⟨mem_insert_self _ _, fun ha ↦ hat (ha ▸ hx)⟩
  constructor
  · rintro ⟨μ, hμ⟩
    

Proof state:
case refine'_2.mp.intro
R : Type u
I : Type v
inst✝¹ : CommSemiring R
x y z : R
s : I → R
t✝ : Finset I
inst✝ : DecidableEq I
h✝ : Finset.Nonempty t✝
a : I
t : Finset I
hat : a ∉ t
h : Finset.Nonempty t
ih : (∃ μ, ∑ i in t, μ i * ∏ j in t \ {i}, s j = 1) ↔ Pairwise (IsCoprime on fun i => s ↑i)
mem : ∀ x ∈ t, a ∈ insert a t \ {x}
μ : I → R
hμ : ∑ i in cons a t hat, μ i * ∏ j in cons a t hat \ {i}, s j = 1
⊢ Pairwise (IsCoprime on fun a => s ↑a) ∧ ∀ b ∈ t, IsCoprime (s a) (s b) ∧ IsCoprime (s b) (s a)

Next tactic:
rw [sum_cons, cons_eq_insert, sdiff_singleton_eq_erase, erase_insert hat] at hμ
theorem exists_sum_eq_one_iff_pairwise_coprime [DecidableEq I] (h : t.Nonempty) :
    (∃ μ : I → R, (∑ i in t, μ i * ∏ j in t \ {i}, s j) = 1) ↔
      Pairwise (IsCoprime on fun i : t ↦ s i) := by
  refine' h.cons_induction _ _
  · simp only [sum_singleton, Finset.sdiff_self, prod_empty, mul_one, exists_apply_eq,
               Pairwise, Ne.def, true_iff_iff]
    rintro a ⟨i, hi⟩ ⟨j, hj⟩ h
    rw [Finset.mem_singleton] at hi hj
    simp [hi, hj] at h
  intro a t hat h ih
  rw [pairwise_cons']
  have mem : ∀ x ∈ t, a ∈ insert a t \ {x} := fun x hx ↦ by
    rw [mem_sdiff, mem_singleton]
    refine ⟨mem_insert_self _ _, fun ha ↦ hat (ha ▸ hx)⟩
  constructor
  · rintro ⟨μ, hμ⟩
    rw [sum_cons, cons_eq_insert, sdiff_singleton_eq_erase, erase_insert hat] at hμ
    

Proof state:
case refine'_2.mp.intro
R : Type u
I : Type v
inst✝¹ : CommSemiring R
x y z : R
s : I → R
t✝ : Finset I
inst✝ : DecidableEq I
h✝ : Finset.Nonempty t✝
a : I
t : Finset I
hat : a ∉ t
h : Finset.Nonempty t
ih : (∃ μ, ∑ i in t, μ i * ∏ j in t \ {i}, s j = 1) ↔ Pairwise (IsCoprime on fun i => s ↑i)
mem : ∀ x ∈ t, a ∈ insert a t \ {x}
μ : I → R
hμ : μ a * ∏ j in t, s j + ∑ x in t, μ x * ∏ j in insert a t \ {x}, s j = 1
⊢ Pairwise (IsCoprime on fun a => s ↑a) ∧ ∀ b ∈ t, IsCoprime (s a) (s b) ∧ IsCoprime (s b) (s a)

Next tactic:
refine' ⟨ih.mp ⟨Pi.single h.choose (μ a * s h.choose) + μ * fun _ ↦ s a, ?_⟩, fun b hb ↦ ?_⟩
theorem exists_sum_eq_one_iff_pairwise_coprime [DecidableEq I] (h : t.Nonempty) :
    (∃ μ : I → R, (∑ i in t, μ i * ∏ j in t \ {i}, s j) = 1) ↔
      Pairwise (IsCoprime on fun i : t ↦ s i) := by
  refine' h.cons_induction _ _
  · simp only [sum_singleton, Finset.sdiff_self, prod_empty, mul_one, exists_apply_eq,
               Pairwise, Ne.def, true_iff_iff]
    rintro a ⟨i, hi⟩ ⟨j, hj⟩ h
    rw [Finset.mem_singleton] at hi hj
    simp [hi, hj] at h
  intro a t hat h ih
  rw [pairwise_cons']
  have mem : ∀ x ∈ t, a ∈ insert a t \ {x} := fun x hx ↦ by
    rw [mem_sdiff, mem_singleton]
    refine ⟨mem_insert_self _ _, fun ha ↦ hat (ha ▸ hx)⟩
  constructor
  · rintro ⟨μ, hμ⟩
    rw [sum_cons, cons_eq_insert, sdiff_singleton_eq_erase, erase_insert hat] at hμ
    refine' ⟨ih.mp ⟨Pi.single h.choose (μ a * s h.choose) + μ * fun _ ↦ s a, ?_⟩, fun b hb ↦ ?_⟩
    · 

Proof state:
case refine'_2.mp.intro.refine'_1
R : Type u
I : Type v
inst✝¹ : CommSemiring R
x y z : R
s : I → R
t✝ : Finset I
inst✝ : DecidableEq I
h✝ : Finset.Nonempty t✝
a : I
t : Finset I
hat : a ∉ t
h : Finset.Nonempty t
ih : (∃ μ, ∑ i in t, μ i * ∏ j in t \ {i}, s j = 1) ↔ Pairwise (IsCoprime on fun i => s ↑i)
mem : ∀ x ∈ t, a ∈ insert a t \ {x}
μ : I → R
hμ : μ a * ∏ j in t, s j + ∑ x in t, μ x * ∏ j in insert a t \ {x}, s j = 1
⊢ ∑ i in t, (Pi.single (Exists.choose h) (μ a * s (Exists.choose h)) + μ * fun x => s a) i * ∏ j in t \ {i}, s j = 1

Next tactic:
rw [prod_eq_mul_prod_diff_singleton h.choose_spec, ← mul_assoc, ←
        @if_pos _ _ h.choose_spec R (_ * _) 0, ← sum_pi_single', ← sum_add_distrib] at hμ
theorem exists_sum_eq_one_iff_pairwise_coprime [DecidableEq I] (h : t.Nonempty) :
    (∃ μ : I → R, (∑ i in t, μ i * ∏ j in t \ {i}, s j) = 1) ↔
      Pairwise (IsCoprime on fun i : t ↦ s i) := by
  refine' h.cons_induction _ _
  · simp only [sum_singleton, Finset.sdiff_self, prod_empty, mul_one, exists_apply_eq,
               Pairwise, Ne.def, true_iff_iff]
    rintro a ⟨i, hi⟩ ⟨j, hj⟩ h
    rw [Finset.mem_singleton] at hi hj
    simp [hi, hj] at h
  intro a t hat h ih
  rw [pairwise_cons']
  have mem : ∀ x ∈ t, a ∈ insert a t \ {x} := fun x hx ↦ by
    rw [mem_sdiff, mem_singleton]
    refine ⟨mem_insert_self _ _, fun ha ↦ hat (ha ▸ hx)⟩
  constructor
  · rintro ⟨μ, hμ⟩
    rw [sum_cons, cons_eq_insert, sdiff_singleton_eq_erase, erase_insert hat] at hμ
    refine' ⟨ih.mp ⟨Pi.single h.choose (μ a * s h.choose) + μ * fun _ ↦ s a, ?_⟩, fun b hb ↦ ?_⟩
    · rw [prod_eq_mul_prod_diff_singleton h.choose_spec, ← mul_assoc, ←
        @if_pos _ _ h.choose_spec R (_ * _) 0, ← sum_pi_single', ← sum_add_distrib] at hμ
      

Proof state:
case refine'_2.mp.intro.refine'_1
R : Type u
I : Type v
inst✝¹ : CommSemiring R
x y z : R
s : I → R
t✝ : Finset I
inst✝ : DecidableEq I
h✝ : Finset.Nonempty t✝
a : I
t : Finset I
hat : a ∉ t
h : Finset.Nonempty t
ih : (∃ μ, ∑ i in t, μ i * ∏ j in t \ {i}, s j = 1) ↔ Pairwise (IsCoprime on fun i => s ↑i)
mem : ∀ x ∈ t, a ∈ insert a t \ {x}
μ : I → R
hμ✝ : μ a * s (Exists.choose h) * ∏ x in t \ {Exists.choose h}, s x + ∑ x in t, μ x * ∏ j in insert a t \ {x}, s j = 1
hμ :
  ∑ x in t,
      (Pi.single (Exists.choose h) (μ a * s (Exists.choose h) * ∏ x in t \ {Exists.choose h}, s x) x +
        μ x * ∏ j in insert a t \ {x}, s j) =
    1
⊢ ∑ i in t, (Pi.single (Exists.choose h) (μ a * s (Exists.choose h)) + μ * fun x => s a) i * ∏ j in t \ {i}, s j = 1

Next tactic:
rw [← hμ, sum_congr rfl]
theorem exists_sum_eq_one_iff_pairwise_coprime [DecidableEq I] (h : t.Nonempty) :
    (∃ μ : I → R, (∑ i in t, μ i * ∏ j in t \ {i}, s j) = 1) ↔
      Pairwise (IsCoprime on fun i : t ↦ s i) := by
  refine' h.cons_induction _ _
  · simp only [sum_singleton, Finset.sdiff_self, prod_empty, mul_one, exists_apply_eq,
               Pairwise, Ne.def, true_iff_iff]
    rintro a ⟨i, hi⟩ ⟨j, hj⟩ h
    rw [Finset.mem_singleton] at hi hj
    simp [hi, hj] at h
  intro a t hat h ih
  rw [pairwise_cons']
  have mem : ∀ x ∈ t, a ∈ insert a t \ {x} := fun x hx ↦ by
    rw [mem_sdiff, mem_singleton]
    refine ⟨mem_insert_self _ _, fun ha ↦ hat (ha ▸ hx)⟩
  constructor
  · rintro ⟨μ, hμ⟩
    rw [sum_cons, cons_eq_insert, sdiff_singleton_eq_erase, erase_insert hat] at hμ
    refine' ⟨ih.mp ⟨Pi.single h.choose (μ a * s h.choose) + μ * fun _ ↦ s a, ?_⟩, fun b hb ↦ ?_⟩
    · rw [prod_eq_mul_prod_diff_singleton h.choose_spec, ← mul_assoc, ←
        @if_pos _ _ h.choose_spec R (_ * _) 0, ← sum_pi_single', ← sum_add_distrib] at hμ
      rw [← hμ, sum_congr rfl]
      

Proof state:
case refine'_2.mp.intro.refine'_1
R : Type u
I : Type v
inst✝¹ : CommSemiring R
x y z : R
s : I → R
t✝ : Finset I
inst✝ : DecidableEq I
h✝ : Finset.Nonempty t✝
a : I
t : Finset I
hat : a ∉ t
h : Finset.Nonempty t
ih : (∃ μ, ∑ i in t, μ i * ∏ j in t \ {i}, s j = 1) ↔ Pairwise (IsCoprime on fun i => s ↑i)
mem : ∀ x ∈ t, a ∈ insert a t \ {x}
μ : I → R
hμ✝ : μ a * s (Exists.choose h) * ∏ x in t \ {Exists.choose h}, s x + ∑ x in t, μ x * ∏ j in insert a t \ {x}, s j = 1
hμ :
  ∑ x in t,
      (Pi.single (Exists.choose h) (μ a * s (Exists.choose h) * ∏ x in t \ {Exists.choose h}, s x) x +
        μ x * ∏ j in insert a t \ {x}, s j) =
    1
⊢ ∀ x ∈ t,
    (Pi.single (Exists.choose h) (μ a * s (Exists.choose h)) + μ * fun x => s a) x * ∏ j in t \ {x}, s j =
      Pi.single (Exists.choose h) (μ a * s (Exists.choose h) * ∏ x in t \ {Exists.choose h}, s x) x +
        μ x * ∏ j in insert a t \ {x}, s j

Next tactic:
intro x hx
theorem exists_sum_eq_one_iff_pairwise_coprime [DecidableEq I] (h : t.Nonempty) :
    (∃ μ : I → R, (∑ i in t, μ i * ∏ j in t \ {i}, s j) = 1) ↔
      Pairwise (IsCoprime on fun i : t ↦ s i) := by
  refine' h.cons_induction _ _
  · simp only [sum_singleton, Finset.sdiff_self, prod_empty, mul_one, exists_apply_eq,
               Pairwise, Ne.def, true_iff_iff]
    rintro a ⟨i, hi⟩ ⟨j, hj⟩ h
    rw [Finset.mem_singleton] at hi hj
    simp [hi, hj] at h
  intro a t hat h ih
  rw [pairwise_cons']
  have mem : ∀ x ∈ t, a ∈ insert a t \ {x} := fun x hx ↦ by
    rw [mem_sdiff, mem_singleton]
    refine ⟨mem_insert_self _ _, fun ha ↦ hat (ha ▸ hx)⟩
  constructor
  · rintro ⟨μ, hμ⟩
    rw [sum_cons, cons_eq_insert, sdiff_singleton_eq_erase, erase_insert hat] at hμ
    refine' ⟨ih.mp ⟨Pi.single h.choose (μ a * s h.choose) + μ * fun _ ↦ s a, ?_⟩, fun b hb ↦ ?_⟩
    · rw [prod_eq_mul_prod_diff_singleton h.choose_spec, ← mul_assoc, ←
        @if_pos _ _ h.choose_spec R (_ * _) 0, ← sum_pi_single', ← sum_add_distrib] at hμ
      rw [← hμ, sum_congr rfl]
      intro x hx
      

Proof state:
case refine'_2.mp.intro.refine'_1
R : Type u
I : Type v
inst✝¹ : CommSemiring R
x✝ y z : R
s : I → R
t✝ : Finset I
inst✝ : DecidableEq I
h✝ : Finset.Nonempty t✝
a : I
t : Finset I
hat : a ∉ t
h : Finset.Nonempty t
ih : (∃ μ, ∑ i in t, μ i * ∏ j in t \ {i}, s j = 1) ↔ Pairwise (IsCoprime on fun i => s ↑i)
mem : ∀ x ∈ t, a ∈ insert a t \ {x}
μ : I → R
hμ✝ : μ a * s (Exists.choose h) * ∏ x in t \ {Exists.choose h}, s x + ∑ x in t, μ x * ∏ j in insert a t \ {x}, s j = 1
hμ :
  ∑ x in t,
      (Pi.single (Exists.choose h) (μ a * s (Exists.choose h) * ∏ x in t \ {Exists.choose h}, s x) x +
        μ x * ∏ j in insert a t \ {x}, s j) =
    1
x : I
hx : x ∈ t
⊢ (Pi.single (Exists.choose h) (μ a * s (Exists.choose h)) + μ * fun x => s a) x * ∏ j in t \ {x}, s j =
    Pi.single (Exists.choose h) (μ a * s (Exists.choose h) * ∏ x in t \ {Exists.choose h}, s x) x +
      μ x * ∏ j in insert a t \ {x}, s j

Next tactic:
dsimp
theorem exists_sum_eq_one_iff_pairwise_coprime [DecidableEq I] (h : t.Nonempty) :
    (∃ μ : I → R, (∑ i in t, μ i * ∏ j in t \ {i}, s j) = 1) ↔
      Pairwise (IsCoprime on fun i : t ↦ s i) := by
  refine' h.cons_induction _ _
  · simp only [sum_singleton, Finset.sdiff_self, prod_empty, mul_one, exists_apply_eq,
               Pairwise, Ne.def, true_iff_iff]
    rintro a ⟨i, hi⟩ ⟨j, hj⟩ h
    rw [Finset.mem_singleton] at hi hj
    simp [hi, hj] at h
  intro a t hat h ih
  rw [pairwise_cons']
  have mem : ∀ x ∈ t, a ∈ insert a t \ {x} := fun x hx ↦ by
    rw [mem_sdiff, mem_singleton]
    refine ⟨mem_insert_self _ _, fun ha ↦ hat (ha ▸ hx)⟩
  constructor
  · rintro ⟨μ, hμ⟩
    rw [sum_cons, cons_eq_insert, sdiff_singleton_eq_erase, erase_insert hat] at hμ
    refine' ⟨ih.mp ⟨Pi.single h.choose (μ a * s h.choose) + μ * fun _ ↦ s a, ?_⟩, fun b hb ↦ ?_⟩
    · rw [prod_eq_mul_prod_diff_singleton h.choose_spec, ← mul_assoc, ←
        @if_pos _ _ h.choose_spec R (_ * _) 0, ← sum_pi_single', ← sum_add_distrib] at hμ
      rw [← hμ, sum_congr rfl]
      intro x hx
      dsimp -- porting note: terms were showing as sort of `HAdd.hadd` instead of `+`
      -- this whole proof pretty much breaks and has to be rewritten from scratch
      

Proof state:
case refine'_2.mp.intro.refine'_1
R : Type u
I : Type v
inst✝¹ : CommSemiring R
x✝ y z : R
s : I → R
t✝ : Finset I
inst✝ : DecidableEq I
h✝ : Finset.Nonempty t✝
a : I
t : Finset I
hat : a ∉ t
h : Finset.Nonempty t
ih : (∃ μ, ∑ i in t, μ i * ∏ j in t \ {i}, s j = 1) ↔ Pairwise (IsCoprime on fun i => s ↑i)
mem : ∀ x ∈ t, a ∈ insert a t \ {x}
μ : I → R
hμ✝ : μ a * s (Exists.choose h) * ∏ x in t \ {Exists.choose h}, s x + ∑ x in t, μ x * ∏ j in insert a t \ {x}, s j = 1
hμ :
  ∑ x in t,
      (Pi.single (Exists.choose h) (μ a * s (Exists.choose h) * ∏ x in t \ {Exists.choose h}, s x) x +
        μ x * ∏ j in insert a t \ {x}, s j) =
    1
x : I
hx : x ∈ t
⊢ (Pi.single (Exists.choose h) (μ a * s (Exists.choose h)) x + μ x * s a) * ∏ j in t \ {x}, s j =
    Pi.single (Exists.choose h) (μ a * s (Exists.choose h) * ∏ x in t \ {Exists.choose h}, s x) x +
      μ x * ∏ j in insert a t \ {x}, s j

Next tactic:
rw [add_mul]
theorem exists_sum_eq_one_iff_pairwise_coprime [DecidableEq I] (h : t.Nonempty) :
    (∃ μ : I → R, (∑ i in t, μ i * ∏ j in t \ {i}, s j) = 1) ↔
      Pairwise (IsCoprime on fun i : t ↦ s i) := by
  refine' h.cons_induction _ _
  · simp only [sum_singleton, Finset.sdiff_self, prod_empty, mul_one, exists_apply_eq,
               Pairwise, Ne.def, true_iff_iff]
    rintro a ⟨i, hi⟩ ⟨j, hj⟩ h
    rw [Finset.mem_singleton] at hi hj
    simp [hi, hj] at h
  intro a t hat h ih
  rw [pairwise_cons']
  have mem : ∀ x ∈ t, a ∈ insert a t \ {x} := fun x hx ↦ by
    rw [mem_sdiff, mem_singleton]
    refine ⟨mem_insert_self _ _, fun ha ↦ hat (ha ▸ hx)⟩
  constructor
  · rintro ⟨μ, hμ⟩
    rw [sum_cons, cons_eq_insert, sdiff_singleton_eq_erase, erase_insert hat] at hμ
    refine' ⟨ih.mp ⟨Pi.single h.choose (μ a * s h.choose) + μ * fun _ ↦ s a, ?_⟩, fun b hb ↦ ?_⟩
    · rw [prod_eq_mul_prod_diff_singleton h.choose_spec, ← mul_assoc, ←
        @if_pos _ _ h.choose_spec R (_ * _) 0, ← sum_pi_single', ← sum_add_distrib] at hμ
      rw [← hμ, sum_congr rfl]
      intro x hx
      dsimp -- porting note: terms were showing as sort of `HAdd.hadd` instead of `+`
      -- this whole proof pretty much breaks and has to be rewritten from scratch
      rw [add_mul]
      

Proof state:
case refine'_2.mp.intro.refine'_1
R : Type u
I : Type v
inst✝¹ : CommSemiring R
x✝ y z : R
s : I → R
t✝ : Finset I
inst✝ : DecidableEq I
h✝ : Finset.Nonempty t✝
a : I
t : Finset I
hat : a ∉ t
h : Finset.Nonempty t
ih : (∃ μ, ∑ i in t, μ i * ∏ j in t \ {i}, s j = 1) ↔ Pairwise (IsCoprime on fun i => s ↑i)
mem : ∀ x ∈ t, a ∈ insert a t \ {x}
μ : I → R
hμ✝ : μ a * s (Exists.choose h) * ∏ x in t \ {Exists.choose h}, s x + ∑ x in t, μ x * ∏ j in insert a t \ {x}, s j = 1
hμ :
  ∑ x in t,
      (Pi.single (Exists.choose h) (μ a * s (Exists.choose h) * ∏ x in t \ {Exists.choose h}, s x) x +
        μ x * ∏ j in insert a t \ {x}, s j) =
    1
x : I
hx : x ∈ t
⊢ Pi.single (Exists.choose h) (μ a * s (Exists.choose h)) x * ∏ j in t \ {x}, s j + μ x * s a * ∏ j in t \ {x}, s j =
    Pi.single (Exists.choose h) (μ a * s (Exists.choose h) * ∏ x in t \ {Exists.choose h}, s x) x +
      μ x * ∏ j in insert a t \ {x}, s j

Next tactic:
congr 1