l3lab/ntp-mathlib huggingface dataset:
/-- Stronger version of `WellFounded.prod_lex`. Instead of requiring `rβ on g` to be well-founded,
we only require it to be well-founded on fibers of `f`.-/
theorem WellFounded.prod_lex_of_wellFoundedOn_fiber (hα : WellFounded (rα on f))
    (hβ : ∀ a, (f ⁻¹' {a}).WellFoundedOn (rβ on g)) :
    WellFounded (Prod.Lex rα rβ on fun c => (f c, g c)) := by
  refine' (PSigma.lex_wf (wellFoundedOn_range.2 hα) fun a => hβ a).onFun.mono fun c c' h => _
  

Proof state:
case refine'_1
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rα : α → α → Prop
rβ : β → β → Prop
f : γ → α
g : γ → β
s : Set γ
hα : WellFounded (rα on f)
hβ : ∀ (a : α), WellFoundedOn (f ⁻¹' {a}) (rβ on g)
⊢ γ → (a : ↑(range f)) ×' ↑(f ⁻¹' {↑a})
case refine'_2
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rα : α → α → Prop
rβ : β → β → Prop
f : γ → α
g : γ → β
s : Set γ
hα : WellFounded (rα on f)
hβ : ∀ (a : α), WellFoundedOn (f ⁻¹' {a}) (rβ on g)
c c' : γ
h : (Prod.Lex rα rβ on fun c => (f c, g c)) c c'
⊢ ((PSigma.Lex (fun a b => rα ↑a ↑b) fun a a_1 b => (rβ on g) ↑a_1 ↑b) on ?refine'_1) c c'

Next tactic:
exact fun c => ⟨⟨_, c, rfl⟩, c, rfl⟩
/-- Stronger version of `WellFounded.prod_lex`. Instead of requiring `rβ on g` to be well-founded,
we only require it to be well-founded on fibers of `f`.-/
theorem WellFounded.prod_lex_of_wellFoundedOn_fiber (hα : WellFounded (rα on f))
    (hβ : ∀ a, (f ⁻¹' {a}).WellFoundedOn (rβ on g)) :
    WellFounded (Prod.Lex rα rβ on fun c => (f c, g c)) := by
  refine' (PSigma.lex_wf (wellFoundedOn_range.2 hα) fun a => hβ a).onFun.mono fun c c' h => _
  exact fun c => ⟨⟨_, c, rfl⟩, c, rfl⟩
  

Proof state:
case refine'_2
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rα : α → α → Prop
rβ : β → β → Prop
f : γ → α
g : γ → β
s : Set γ
hα : WellFounded (rα on f)
hβ : ∀ (a : α), WellFoundedOn (f ⁻¹' {a}) (rβ on g)
c c' : γ
h : (Prod.Lex rα rβ on fun c => (f c, g c)) c c'
⊢ ((PSigma.Lex (fun a b => rα ↑a ↑b) fun a a_1 b => (rβ on g) ↑a_1 ↑b) on fun c =>
      { fst := { val := f c, property := (_ : ∃ y, f y = f c) }, snd := { val := c, property := (_ : f c = f c) } })
    c c'

Next tactic:
obtain h' | h' := Prod.lex_iff.1 h
/-- Stronger version of `WellFounded.prod_lex`. Instead of requiring `rβ on g` to be well-founded,
we only require it to be well-founded on fibers of `f`.-/
theorem WellFounded.prod_lex_of_wellFoundedOn_fiber (hα : WellFounded (rα on f))
    (hβ : ∀ a, (f ⁻¹' {a}).WellFoundedOn (rβ on g)) :
    WellFounded (Prod.Lex rα rβ on fun c => (f c, g c)) := by
  refine' (PSigma.lex_wf (wellFoundedOn_range.2 hα) fun a => hβ a).onFun.mono fun c c' h => _
  exact fun c => ⟨⟨_, c, rfl⟩, c, rfl⟩
  obtain h' | h' := Prod.lex_iff.1 h
  · 

Proof state:
case refine'_2.inl
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rα : α → α → Prop
rβ : β → β → Prop
f : γ → α
g : γ → β
s : Set γ
hα : WellFounded (rα on f)
hβ : ∀ (a : α), WellFoundedOn (f ⁻¹' {a}) (rβ on g)
c c' : γ
h : (Prod.Lex rα rβ on fun c => (f c, g c)) c c'
h' : rα ((fun c => (f c, g c)) c).1 ((fun c => (f c, g c)) c').1
⊢ ((PSigma.Lex (fun a b => rα ↑a ↑b) fun a a_1 b => (rβ on g) ↑a_1 ↑b) on fun c =>
      { fst := { val := f c, property := (_ : ∃ y, f y = f c) }, snd := { val := c, property := (_ : f c = f c) } })
    c c'

Next tactic:
exact PSigma.Lex.left _ _ h'
/-- Stronger version of `WellFounded.prod_lex`. Instead of requiring `rβ on g` to be well-founded,
we only require it to be well-founded on fibers of `f`.-/
theorem WellFounded.prod_lex_of_wellFoundedOn_fiber (hα : WellFounded (rα on f))
    (hβ : ∀ a, (f ⁻¹' {a}).WellFoundedOn (rβ on g)) :
    WellFounded (Prod.Lex rα rβ on fun c => (f c, g c)) := by
  refine' (PSigma.lex_wf (wellFoundedOn_range.2 hα) fun a => hβ a).onFun.mono fun c c' h => _
  exact fun c => ⟨⟨_, c, rfl⟩, c, rfl⟩
  obtain h' | h' := Prod.lex_iff.1 h
  · exact PSigma.Lex.left _ _ h'
  · 

Proof state:
case refine'_2.inr
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rα : α → α → Prop
rβ : β → β → Prop
f : γ → α
g : γ → β
s : Set γ
hα : WellFounded (rα on f)
hβ : ∀ (a : α), WellFoundedOn (f ⁻¹' {a}) (rβ on g)
c c' : γ
h : (Prod.Lex rα rβ on fun c => (f c, g c)) c c'
h' :
  ((fun c => (f c, g c)) c).1 = ((fun c => (f c, g c)) c').1 ∧
    rβ ((fun c => (f c, g c)) c).2 ((fun c => (f c, g c)) c').2
⊢ ((PSigma.Lex (fun a b => rα ↑a ↑b) fun a a_1 b => (rβ on g) ↑a_1 ↑b) on fun c =>
      { fst := { val := f c, property := (_ : ∃ y, f y = f c) }, snd := { val := c, property := (_ : f c = f c) } })
    c c'

Next tactic:
dsimp only [InvImage, (· on ·)] at h' ⊢
/-- Stronger version of `WellFounded.prod_lex`. Instead of requiring `rβ on g` to be well-founded,
we only require it to be well-founded on fibers of `f`.-/
theorem WellFounded.prod_lex_of_wellFoundedOn_fiber (hα : WellFounded (rα on f))
    (hβ : ∀ a, (f ⁻¹' {a}).WellFoundedOn (rβ on g)) :
    WellFounded (Prod.Lex rα rβ on fun c => (f c, g c)) := by
  refine' (PSigma.lex_wf (wellFoundedOn_range.2 hα) fun a => hβ a).onFun.mono fun c c' h => _
  exact fun c => ⟨⟨_, c, rfl⟩, c, rfl⟩
  obtain h' | h' := Prod.lex_iff.1 h
  · exact PSigma.Lex.left _ _ h'
  · dsimp only [InvImage, (· on ·)] at h' ⊢
    

Proof state:
case refine'_2.inr
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rα : α → α → Prop
rβ : β → β → Prop
f : γ → α
g : γ → β
s : Set γ
hα : WellFounded (rα on f)
hβ : ∀ (a : α), WellFoundedOn (f ⁻¹' {a}) (rβ on g)
c c' : γ
h : (Prod.Lex rα rβ on fun c => (f c, g c)) c c'
h' : f c = f c' ∧ rβ (g c) (g c')
⊢ PSigma.Lex (fun a b => rα ↑a ↑b) (fun a a_1 b => rβ (g ↑a_1) (g ↑b))
    { fst := { val := f c, property := (_ : ∃ y, f y = f c) }, snd := { val := c, property := (_ : f c = f c) } }
    { fst := { val := f c', property := (_ : ∃ y, f y = f c') }, snd := { val := c', property := (_ : f c' = f c') } }

Next tactic:
convert PSigma.Lex.right (⟨_, c', rfl⟩ : range f) _ using 1
/-- Stronger version of `WellFounded.prod_lex`. Instead of requiring `rβ on g` to be well-founded,
we only require it to be well-founded on fibers of `f`.-/
theorem WellFounded.prod_lex_of_wellFoundedOn_fiber (hα : WellFounded (rα on f))
    (hβ : ∀ a, (f ⁻¹' {a}).WellFoundedOn (rβ on g)) :
    WellFounded (Prod.Lex rα rβ on fun c => (f c, g c)) := by
  refine' (PSigma.lex_wf (wellFoundedOn_range.2 hα) fun a => hβ a).onFun.mono fun c c' h => _
  exact fun c => ⟨⟨_, c, rfl⟩, c, rfl⟩
  obtain h' | h' := Prod.lex_iff.1 h
  · exact PSigma.Lex.left _ _ h'
  · dsimp only [InvImage, (· on ·)] at h' ⊢
    convert PSigma.Lex.right (⟨_, c', rfl⟩ : range f) _ using 1; 

Proof state:
case h.e'_5.h
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rα : α → α → Prop
rβ : β → β → Prop
f : γ → α
g : γ → β
s : Set γ
hα : WellFounded (rα on f)
hβ : ∀ (a : α), WellFoundedOn (f ⁻¹' {a}) (rβ on g)
c c' : γ
h : (Prod.Lex rα rβ on fun c => (f c, g c)) c c'
h' : f c = f c' ∧ rβ (g c) (g c')
⊢ { fst := { val := f c, property := (_ : ∃ y, f y = f c) }, snd := { val := c, property := (_ : f c = f c) } } =
    { fst := { val := f c', property := (_ : ∃ y, f y = f c') }, snd := ?refine'_2.inr.convert_4 }
case refine'_2.inr.convert_4
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rα : α → α → Prop
rβ : β → β → Prop
f : γ → α
g : γ → β
s : Set γ
hα : WellFounded (rα on f)
hβ : ∀ (a : α), WellFoundedOn (f ⁻¹' {a}) (rβ on g)
c c' : γ
h : (Prod.Lex rα rβ on fun c => (f c, g c)) c c'
h' : f c = f c' ∧ rβ (g c) (g c')
⊢ ↑(f ⁻¹' {↑{ val := f c', property := (_ : ∃ y, f y = f c') }})
case refine'_2.inr.convert_6
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rα : α → α → Prop
rβ : β → β → Prop
f : γ → α
g : γ → β
s : Set γ
hα : WellFounded (rα on f)
hβ : ∀ (a : α), WellFoundedOn (f ⁻¹' {a}) (rβ on g)
c c' : γ
h : (Prod.Lex rα rβ on fun c => (f c, g c)) c c'
h' : f c = f c' ∧ rβ (g c) (g c')
⊢ rβ (g ↑?refine'_2.inr.convert_4) (g ↑{ val := c', property := (_ : f c' = f c') })

Next tactic:
swap
/-- Stronger version of `WellFounded.prod_lex`. Instead of requiring `rβ on g` to be well-founded,
we only require it to be well-founded on fibers of `f`.-/
theorem WellFounded.prod_lex_of_wellFoundedOn_fiber (hα : WellFounded (rα on f))
    (hβ : ∀ a, (f ⁻¹' {a}).WellFoundedOn (rβ on g)) :
    WellFounded (Prod.Lex rα rβ on fun c => (f c, g c)) := by
  refine' (PSigma.lex_wf (wellFoundedOn_range.2 hα) fun a => hβ a).onFun.mono fun c c' h => _
  exact fun c => ⟨⟨_, c, rfl⟩, c, rfl⟩
  obtain h' | h' := Prod.lex_iff.1 h
  · exact PSigma.Lex.left _ _ h'
  · dsimp only [InvImage, (· on ·)] at h' ⊢
    convert PSigma.Lex.right (⟨_, c', rfl⟩ : range f) _ using 1; swap
    

Proof state:
case refine'_2.inr.convert_4
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rα : α → α → Prop
rβ : β → β → Prop
f : γ → α
g : γ → β
s : Set γ
hα : WellFounded (rα on f)
hβ : ∀ (a : α), WellFoundedOn (f ⁻¹' {a}) (rβ on g)
c c' : γ
h : (Prod.Lex rα rβ on fun c => (f c, g c)) c c'
h' : f c = f c' ∧ rβ (g c) (g c')
⊢ ↑(f ⁻¹' {↑{ val := f c', property := (_ : ∃ y, f y = f c') }})
case h.e'_5.h
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rα : α → α → Prop
rβ : β → β → Prop
f : γ → α
g : γ → β
s : Set γ
hα : WellFounded (rα on f)
hβ : ∀ (a : α), WellFoundedOn (f ⁻¹' {a}) (rβ on g)
c c' : γ
h : (Prod.Lex rα rβ on fun c => (f c, g c)) c c'
h' : f c = f c' ∧ rβ (g c) (g c')
⊢ { fst := { val := f c, property := (_ : ∃ y, f y = f c) }, snd := { val := c, property := (_ : f c = f c) } } =
    { fst := { val := f c', property := (_ : ∃ y, f y = f c') }, snd := ?refine'_2.inr.convert_4 }
case refine'_2.inr.convert_6
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rα : α → α → Prop
rβ : β → β → Prop
f : γ → α
g : γ → β
s : Set γ
hα : WellFounded (rα on f)
hβ : ∀ (a : α), WellFoundedOn (f ⁻¹' {a}) (rβ on g)
c c' : γ
h : (Prod.Lex rα rβ on fun c => (f c, g c)) c c'
h' : f c = f c' ∧ rβ (g c) (g c')
⊢ rβ (g ↑?refine'_2.inr.convert_4) (g ↑{ val := c', property := (_ : f c' = f c') })

Next tactic:
exacts [⟨c, h'.1⟩, PSigma.subtype_ext (Subtype.ext h'.1) rfl, h'.2]
theorem Set.WellFoundedOn.prod_lex_of_wellFoundedOn_fiber (hα : s.WellFoundedOn (rα on f))
    (hβ : ∀ a, (s ∩ f ⁻¹' {a}).WellFoundedOn (rβ on g)) :
    s.WellFoundedOn (Prod.Lex rα rβ on fun c => (f c, g c)) := by
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rα : α → α → Prop
rβ : β → β → Prop
f : γ → α
g : γ → β
s : Set γ
hα : WellFoundedOn s (rα on f)
hβ : ∀ (a : α), WellFoundedOn (s ∩ f ⁻¹' {a}) (rβ on g)
⊢ WellFoundedOn s (Prod.Lex rα rβ on fun c => (f c, g c))

Next tactic:
refine' WellFounded.prod_lex_of_wellFoundedOn_fiber hα fun a ↦ (hβ a).onFun.mono (fun b c h ↦ _)
theorem Set.WellFoundedOn.prod_lex_of_wellFoundedOn_fiber (hα : s.WellFoundedOn (rα on f))
    (hβ : ∀ a, (s ∩ f ⁻¹' {a}).WellFoundedOn (rβ on g)) :
    s.WellFoundedOn (Prod.Lex rα rβ on fun c => (f c, g c)) := by
  refine' WellFounded.prod_lex_of_wellFoundedOn_fiber hα fun a ↦ (hβ a).onFun.mono (fun b c h ↦ _)
  

Proof state:
case refine'_1
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rα : α → α → Prop
rβ : β → β → Prop
f : γ → α
g : γ → β
s : Set γ
hα : WellFoundedOn s (rα on f)
hβ : ∀ (a : α), WellFoundedOn (s ∩ f ⁻¹' {a}) (rβ on g)
a : α
b c : ↑((fun a => f ↑a) ⁻¹' {a})
h : (rβ on fun a => g ↑a) ↑b ↑c
⊢ ((fun a_1 b => (rβ on g) ↑a_1 ↑b) on ?refine'_2 a) b c
case refine'_2
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rα : α → α → Prop
rβ : β → β → Prop
f : γ → α
g : γ → β
s : Set γ
hα : WellFoundedOn s (rα on f)
hβ : ∀ (a : α), WellFoundedOn (s ∩ f ⁻¹' {a}) (rβ on g)
⊢ (a : α) → ↑((fun a => f ↑a) ⁻¹' {a}) → ↑(s ∩ f ⁻¹' {a})

Next tactic:
swap
theorem Set.WellFoundedOn.prod_lex_of_wellFoundedOn_fiber (hα : s.WellFoundedOn (rα on f))
    (hβ : ∀ a, (s ∩ f ⁻¹' {a}).WellFoundedOn (rβ on g)) :
    s.WellFoundedOn (Prod.Lex rα rβ on fun c => (f c, g c)) := by
  refine' WellFounded.prod_lex_of_wellFoundedOn_fiber hα fun a ↦ (hβ a).onFun.mono (fun b c h ↦ _)
  swap
  

Proof state:
case refine'_2
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rα : α → α → Prop
rβ : β → β → Prop
f : γ → α
g : γ → β
s : Set γ
hα : WellFoundedOn s (rα on f)
hβ : ∀ (a : α), WellFoundedOn (s ∩ f ⁻¹' {a}) (rβ on g)
⊢ (a : α) → ↑((fun a => f ↑a) ⁻¹' {a}) → ↑(s ∩ f ⁻¹' {a})
case refine'_1
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rα : α → α → Prop
rβ : β → β → Prop
f : γ → α
g : γ → β
s : Set γ
hα : WellFoundedOn s (rα on f)
hβ : ∀ (a : α), WellFoundedOn (s ∩ f ⁻¹' {a}) (rβ on g)
a : α
b c : ↑((fun a => f ↑a) ⁻¹' {a})
h : (rβ on fun a => g ↑a) ↑b ↑c
⊢ ((fun a_1 b => (rβ on g) ↑a_1 ↑b) on ?refine'_2 a) b c

Next tactic:
exact fun _ x => ⟨x, x.1.2, x.2⟩
theorem Set.WellFoundedOn.prod_lex_of_wellFoundedOn_fiber (hα : s.WellFoundedOn (rα on f))
    (hβ : ∀ a, (s ∩ f ⁻¹' {a}).WellFoundedOn (rβ on g)) :
    s.WellFoundedOn (Prod.Lex rα rβ on fun c => (f c, g c)) := by
  refine' WellFounded.prod_lex_of_wellFoundedOn_fiber hα fun a ↦ (hβ a).onFun.mono (fun b c h ↦ _)
  swap
  exact fun _ x => ⟨x, x.1.2, x.2⟩
  

Proof state:
case refine'_1
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rα : α → α → Prop
rβ : β → β → Prop
f : γ → α
g : γ → β
s : Set γ
hα : WellFoundedOn s (rα on f)
hβ : ∀ (a : α), WellFoundedOn (s ∩ f ⁻¹' {a}) (rβ on g)
a : α
b c : ↑((fun a => f ↑a) ⁻¹' {a})
h : (rβ on fun a => g ↑a) ↑b ↑c
⊢ ((fun a_1 b => (rβ on g) ↑a_1 ↑b) on fun x => { val := ↑↑x, property := (_ : ↑↑x ∈ s ∧ ↑↑x ∈ f ⁻¹' {a}) }) b c

Next tactic:
assumption
/-- Stronger version of `PSigma.lex_wf`. Instead of requiring `rπ on g` to be well-founded, we only
require it to be well-founded on fibers of `f`.-/
theorem WellFounded.sigma_lex_of_wellFoundedOn_fiber (hι : WellFounded (rι on f))
    (hπ : ∀ i, (f ⁻¹' {i}).WellFoundedOn (rπ i on g i)) :
    WellFounded (Sigma.Lex rι rπ on fun c => ⟨f c, g (f c) c⟩) := by
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rι : ι → ι → Prop
rπ : (i : ι) → π i → π i → Prop
f : γ → ι
g : (i : ι) → γ → π i
s : Set γ
hι : WellFounded (rι on f)
hπ : ∀ (i : ι), WellFoundedOn (f ⁻¹' {i}) (rπ i on g i)
⊢ WellFounded (Sigma.Lex rι rπ on fun c => { fst := f c, snd := g (f c) c })

Next tactic:
refine' (PSigma.lex_wf (wellFoundedOn_range.2 hι) fun a => hπ a).onFun.mono fun c c' h => _
/-- Stronger version of `PSigma.lex_wf`. Instead of requiring `rπ on g` to be well-founded, we only
require it to be well-founded on fibers of `f`.-/
theorem WellFounded.sigma_lex_of_wellFoundedOn_fiber (hι : WellFounded (rι on f))
    (hπ : ∀ i, (f ⁻¹' {i}).WellFoundedOn (rπ i on g i)) :
    WellFounded (Sigma.Lex rι rπ on fun c => ⟨f c, g (f c) c⟩) := by
  refine' (PSigma.lex_wf (wellFoundedOn_range.2 hι) fun a => hπ a).onFun.mono fun c c' h => _
  

Proof state:
case refine'_1
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rι : ι → ι → Prop
rπ : (i : ι) → π i → π i → Prop
f : γ → ι
g : (i : ι) → γ → π i
s : Set γ
hι : WellFounded (rι on f)
hπ : ∀ (i : ι), WellFoundedOn (f ⁻¹' {i}) (rπ i on g i)
⊢ γ → (a : ↑(range f)) ×' ↑(f ⁻¹' {↑a})
case refine'_2
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rι : ι → ι → Prop
rπ : (i : ι) → π i → π i → Prop
f : γ → ι
g : (i : ι) → γ → π i
s : Set γ
hι : WellFounded (rι on f)
hπ : ∀ (i : ι), WellFoundedOn (f ⁻¹' {i}) (rπ i on g i)
c c' : γ
h : (Sigma.Lex rι rπ on fun c => { fst := f c, snd := g (f c) c }) c c'
⊢ ((PSigma.Lex (fun a b => rι ↑a ↑b) fun a a_1 b => (rπ ↑a on g ↑a) ↑a_1 ↑b) on ?refine'_1) c c'

Next tactic:
exact fun c => ⟨⟨_, c, rfl⟩, c, rfl⟩
/-- Stronger version of `PSigma.lex_wf`. Instead of requiring `rπ on g` to be well-founded, we only
require it to be well-founded on fibers of `f`.-/
theorem WellFounded.sigma_lex_of_wellFoundedOn_fiber (hι : WellFounded (rι on f))
    (hπ : ∀ i, (f ⁻¹' {i}).WellFoundedOn (rπ i on g i)) :
    WellFounded (Sigma.Lex rι rπ on fun c => ⟨f c, g (f c) c⟩) := by
  refine' (PSigma.lex_wf (wellFoundedOn_range.2 hι) fun a => hπ a).onFun.mono fun c c' h => _
  exact fun c => ⟨⟨_, c, rfl⟩, c, rfl⟩
  

Proof state:
case refine'_2
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rι : ι → ι → Prop
rπ : (i : ι) → π i → π i → Prop
f : γ → ι
g : (i : ι) → γ → π i
s : Set γ
hι : WellFounded (rι on f)
hπ : ∀ (i : ι), WellFoundedOn (f ⁻¹' {i}) (rπ i on g i)
c c' : γ
h : (Sigma.Lex rι rπ on fun c => { fst := f c, snd := g (f c) c }) c c'
⊢ ((PSigma.Lex (fun a b => rι ↑a ↑b) fun a a_1 b => (rπ ↑a on g ↑a) ↑a_1 ↑b) on fun c =>
      { fst := { val := f c, property := (_ : ∃ y, f y = f c) }, snd := { val := c, property := (_ : f c = f c) } })
    c c'

Next tactic:
obtain h' | ⟨h', h''⟩ := Sigma.lex_iff.1 h
/-- Stronger version of `PSigma.lex_wf`. Instead of requiring `rπ on g` to be well-founded, we only
require it to be well-founded on fibers of `f`.-/
theorem WellFounded.sigma_lex_of_wellFoundedOn_fiber (hι : WellFounded (rι on f))
    (hπ : ∀ i, (f ⁻¹' {i}).WellFoundedOn (rπ i on g i)) :
    WellFounded (Sigma.Lex rι rπ on fun c => ⟨f c, g (f c) c⟩) := by
  refine' (PSigma.lex_wf (wellFoundedOn_range.2 hι) fun a => hπ a).onFun.mono fun c c' h => _
  exact fun c => ⟨⟨_, c, rfl⟩, c, rfl⟩
  obtain h' | ⟨h', h''⟩ := Sigma.lex_iff.1 h
  · 

Proof state:
case refine'_2.inl
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rι : ι → ι → Prop
rπ : (i : ι) → π i → π i → Prop
f : γ → ι
g : (i : ι) → γ → π i
s : Set γ
hι : WellFounded (rι on f)
hπ : ∀ (i : ι), WellFoundedOn (f ⁻¹' {i}) (rπ i on g i)
c c' : γ
h : (Sigma.Lex rι rπ on fun c => { fst := f c, snd := g (f c) c }) c c'
h' : rι ((fun c => { fst := f c, snd := g (f c) c }) c).fst ((fun c => { fst := f c, snd := g (f c) c }) c').fst
⊢ ((PSigma.Lex (fun a b => rι ↑a ↑b) fun a a_1 b => (rπ ↑a on g ↑a) ↑a_1 ↑b) on fun c =>
      { fst := { val := f c, property := (_ : ∃ y, f y = f c) }, snd := { val := c, property := (_ : f c = f c) } })
    c c'

Next tactic:
exact PSigma.Lex.left _ _ h'
/-- Stronger version of `PSigma.lex_wf`. Instead of requiring `rπ on g` to be well-founded, we only
require it to be well-founded on fibers of `f`.-/
theorem WellFounded.sigma_lex_of_wellFoundedOn_fiber (hι : WellFounded (rι on f))
    (hπ : ∀ i, (f ⁻¹' {i}).WellFoundedOn (rπ i on g i)) :
    WellFounded (Sigma.Lex rι rπ on fun c => ⟨f c, g (f c) c⟩) := by
  refine' (PSigma.lex_wf (wellFoundedOn_range.2 hι) fun a => hπ a).onFun.mono fun c c' h => _
  exact fun c => ⟨⟨_, c, rfl⟩, c, rfl⟩
  obtain h' | ⟨h', h''⟩ := Sigma.lex_iff.1 h
  · exact PSigma.Lex.left _ _ h'
  · 

Proof state:
case refine'_2.inr.intro
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rι : ι → ι → Prop
rπ : (i : ι) → π i → π i → Prop
f : γ → ι
g : (i : ι) → γ → π i
s : Set γ
hι : WellFounded (rι on f)
hπ : ∀ (i : ι), WellFoundedOn (f ⁻¹' {i}) (rπ i on g i)
c c' : γ
h : (Sigma.Lex rι rπ on fun c => { fst := f c, snd := g (f c) c }) c c'
h' : ((fun c => { fst := f c, snd := g (f c) c }) c).fst = ((fun c => { fst := f c, snd := g (f c) c }) c').fst
h'' :
  rπ ((fun c => { fst := f c, snd := g (f c) c }) c').fst (h' ▸ ((fun c => { fst := f c, snd := g (f c) c }) c).snd)
    ((fun c => { fst := f c, snd := g (f c) c }) c').snd
⊢ ((PSigma.Lex (fun a b => rι ↑a ↑b) fun a a_1 b => (rπ ↑a on g ↑a) ↑a_1 ↑b) on fun c =>
      { fst := { val := f c, property := (_ : ∃ y, f y = f c) }, snd := { val := c, property := (_ : f c = f c) } })
    c c'

Next tactic:
dsimp only [InvImage, (· on ·)] at h' ⊢
/-- Stronger version of `PSigma.lex_wf`. Instead of requiring `rπ on g` to be well-founded, we only
require it to be well-founded on fibers of `f`.-/
theorem WellFounded.sigma_lex_of_wellFoundedOn_fiber (hι : WellFounded (rι on f))
    (hπ : ∀ i, (f ⁻¹' {i}).WellFoundedOn (rπ i on g i)) :
    WellFounded (Sigma.Lex rι rπ on fun c => ⟨f c, g (f c) c⟩) := by
  refine' (PSigma.lex_wf (wellFoundedOn_range.2 hι) fun a => hπ a).onFun.mono fun c c' h => _
  exact fun c => ⟨⟨_, c, rfl⟩, c, rfl⟩
  obtain h' | ⟨h', h''⟩ := Sigma.lex_iff.1 h
  · exact PSigma.Lex.left _ _ h'
  · dsimp only [InvImage, (· on ·)] at h' ⊢
    

Proof state:
case refine'_2.inr.intro
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rι : ι → ι → Prop
rπ : (i : ι) → π i → π i → Prop
f : γ → ι
g : (i : ι) → γ → π i
s : Set γ
hι : WellFounded (rι on f)
hπ : ∀ (i : ι), WellFoundedOn (f ⁻¹' {i}) (rπ i on g i)
c c' : γ
h : (Sigma.Lex rι rπ on fun c => { fst := f c, snd := g (f c) c }) c c'
h' : f c = f c'
h'' :
  rπ ((fun c => { fst := f c, snd := g (f c) c }) c').fst (h' ▸ ((fun c => { fst := f c, snd := g (f c) c }) c).snd)
    ((fun c => { fst := f c, snd := g (f c) c }) c').snd
⊢ PSigma.Lex (fun a b => rι ↑a ↑b) (fun a a_1 b => rπ (↑a) (g ↑a ↑a_1) (g ↑a ↑b))
    { fst := { val := f c, property := (_ : ∃ y, f y = f c) }, snd := { val := c, property := (_ : f c = f c) } }
    { fst := { val := f c', property := (_ : ∃ y, f y = f c') }, snd := { val := c', property := (_ : f c' = f c') } }

Next tactic:
convert PSigma.Lex.right (⟨_, c', rfl⟩ : range f) _ using 1
/-- Stronger version of `PSigma.lex_wf`. Instead of requiring `rπ on g` to be well-founded, we only
require it to be well-founded on fibers of `f`.-/
theorem WellFounded.sigma_lex_of_wellFoundedOn_fiber (hι : WellFounded (rι on f))
    (hπ : ∀ i, (f ⁻¹' {i}).WellFoundedOn (rπ i on g i)) :
    WellFounded (Sigma.Lex rι rπ on fun c => ⟨f c, g (f c) c⟩) := by
  refine' (PSigma.lex_wf (wellFoundedOn_range.2 hι) fun a => hπ a).onFun.mono fun c c' h => _
  exact fun c => ⟨⟨_, c, rfl⟩, c, rfl⟩
  obtain h' | ⟨h', h''⟩ := Sigma.lex_iff.1 h
  · exact PSigma.Lex.left _ _ h'
  · dsimp only [InvImage, (· on ·)] at h' ⊢
    convert PSigma.Lex.right (⟨_, c', rfl⟩ : range f) _ using 1; 

Proof state:
case h.e'_5.h
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rι : ι → ι → Prop
rπ : (i : ι) → π i → π i → Prop
f : γ → ι
g : (i : ι) → γ → π i
s : Set γ
hι : WellFounded (rι on f)
hπ : ∀ (i : ι), WellFoundedOn (f ⁻¹' {i}) (rπ i on g i)
c c' : γ
h : (Sigma.Lex rι rπ on fun c => { fst := f c, snd := g (f c) c }) c c'
h' : f c = f c'
h'' :
  rπ ((fun c => { fst := f c, snd := g (f c) c }) c').fst (h' ▸ ((fun c => { fst := f c, snd := g (f c) c }) c).snd)
    ((fun c => { fst := f c, snd := g (f c) c }) c').snd
⊢ { fst := { val := f c, property := (_ : ∃ y, f y = f c) }, snd := { val := c, property := (_ : f c = f c) } } =
    { fst := { val := f c', property := (_ : ∃ y, f y = f c') }, snd := ?refine'_2.inr.intro.convert_4 }
case refine'_2.inr.intro.convert_4
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rι : ι → ι → Prop
rπ : (i : ι) → π i → π i → Prop
f : γ → ι
g : (i : ι) → γ → π i
s : Set γ
hι : WellFounded (rι on f)
hπ : ∀ (i : ι), WellFoundedOn (f ⁻¹' {i}) (rπ i on g i)
c c' : γ
h : (Sigma.Lex rι rπ on fun c => { fst := f c, snd := g (f c) c }) c c'
h' : f c = f c'
h'' :
  rπ ((fun c => { fst := f c, snd := g (f c) c }) c').fst (h' ▸ ((fun c => { fst := f c, snd := g (f c) c }) c).snd)
    ((fun c => { fst := f c, snd := g (f c) c }) c').snd
⊢ ↑(f ⁻¹' {↑{ val := f c', property := (_ : ∃ y, f y = f c') }})
case refine'_2.inr.intro.convert_6
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rι : ι → ι → Prop
rπ : (i : ι) → π i → π i → Prop
f : γ → ι
g : (i : ι) → γ → π i
s : Set γ
hι : WellFounded (rι on f)
hπ : ∀ (i : ι), WellFoundedOn (f ⁻¹' {i}) (rπ i on g i)
c c' : γ
h : (Sigma.Lex rι rπ on fun c => { fst := f c, snd := g (f c) c }) c c'
h' : f c = f c'
h'' :
  rπ ((fun c => { fst := f c, snd := g (f c) c }) c').fst (h' ▸ ((fun c => { fst := f c, snd := g (f c) c }) c).snd)
    ((fun c => { fst := f c, snd := g (f c) c }) c').snd
⊢ rπ (↑{ val := f c', property := (_ : ∃ y, f y = f c') })
    (g ↑{ val := f c', property := (_ : ∃ y, f y = f c') } ↑?refine'_2.inr.intro.convert_4)
    (g ↑{ val := f c', property := (_ : ∃ y, f y = f c') } ↑{ val := c', property := (_ : f c' = f c') })

Next tactic:
swap