l3lab/ntp-mathlib huggingface dataset:
/-- Restrict the codomain of an initial segment -/
def codRestrict (p : Set β) (f : r ≼i s) (H : ∀ a, f a ∈ p) : r ≼i Subrel s p :=
  ⟨RelEmbedding.codRestrict p f H, fun a ⟨b, m⟩ h =>
    let ⟨a', e⟩ := f.init h
    ⟨a', by 

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
p : Set β
f : r ≼i s
H : ∀ (a : α), f a ∈ p
a : α
x✝ : ↑p
b : β
m : b ∈ p
h : Subrel s p { val := b, property := m } ((RelEmbedding.codRestrict p f.toRelEmbedding H) a)
a' : α
e : f a' = ↑{ val := b, property := m }
⊢ (RelEmbedding.codRestrict p f.toRelEmbedding H) a' = { val := b, property := m }

Next tactic:
subst e
/-- Restrict the codomain of an initial segment -/
def codRestrict (p : Set β) (f : r ≼i s) (H : ∀ a, f a ∈ p) : r ≼i Subrel s p :=
  ⟨RelEmbedding.codRestrict p f H, fun a ⟨b, m⟩ h =>
    let ⟨a', e⟩ := f.init h
    ⟨a', by subst e; 

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
p : Set β
f : r ≼i s
H : ∀ (a : α), f a ∈ p
a : α
x✝ : ↑p
a' : α
m : f a' ∈ p
h : Subrel s p { val := f a', property := m } ((RelEmbedding.codRestrict p f.toRelEmbedding H) a)
⊢ (RelEmbedding.codRestrict p f.toRelEmbedding H) a' = { val := f a', property := m }

Next tactic:
rfl
/-- Initial segment embedding of an order `r` into the disjoint union of `r` and `s`. -/
def leAdd (r : α → α → Prop) (s : β → β → Prop) : r ≼i Sum.Lex r s :=
  ⟨⟨⟨Sum.inl, fun _ _ => Sum.inl.inj⟩, Sum.lex_inl_inl⟩, fun a b => by
    

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r✝ : α → α → Prop
s✝ : β → β → Prop
t : γ → γ → Prop
r : α → α → Prop
s : β → β → Prop
a : α
b : α ⊕ β
⊢ Sum.Lex r s b
      ({ toEmbedding := { toFun := Sum.inl, inj' := (_ : ∀ (x x_1 : α), Sum.inl x = Sum.inl x_1 → x = x_1) },
          map_rel_iff' := (_ : ∀ {a b : α}, Sum.Lex r s (Sum.inl a) (Sum.inl b) ↔ r a b) }
        a) →
    ∃ a',
      { toEmbedding := { toFun := Sum.inl, inj' := (_ : ∀ (x x_1 : α), Sum.inl x = Sum.inl x_1 → x = x_1) },
            map_rel_iff' := (_ : ∀ {a b : α}, Sum.Lex r s (Sum.inl a) (Sum.inl b) ↔ r a b) }
          a' =
        b

Next tactic:
cases b <;> [exact fun _ => ⟨_, rfl⟩; exact False.elim ∘ Sum.lex_inr_inl]
/-- Initial segment embedding of an order `r` into the disjoint union of `r` and `s`. -/
def leAdd (r : α → α → Prop) (s : β → β → Prop) : r ≼i Sum.Lex r s :=
  ⟨⟨⟨Sum.inl, fun _ _ => Sum.inl.inj⟩, Sum.lex_inl_inl⟩, fun a b => by
    

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r✝ : α → α → Prop
s✝ : β → β → Prop
t : γ → γ → Prop
r : α → α → Prop
s : β → β → Prop
a : α
b : α ⊕ β
⊢ Sum.Lex r s b
      ({ toEmbedding := { toFun := Sum.inl, inj' := (_ : ∀ (x x_1 : α), Sum.inl x = Sum.inl x_1 → x = x_1) },
          map_rel_iff' := (_ : ∀ {a b : α}, Sum.Lex r s (Sum.inl a) (Sum.inl b) ↔ r a b) }
        a) →
    ∃ a',
      { toEmbedding := { toFun := Sum.inl, inj' := (_ : ∀ (x x_1 : α), Sum.inl x = Sum.inl x_1 → x = x_1) },
            map_rel_iff' := (_ : ∀ {a b : α}, Sum.Lex r s (Sum.inl a) (Sum.inl b) ↔ r a b) }
          a' =
        b

Next tactic:
cases b
/-- Initial segment embedding of an order `r` into the disjoint union of `r` and `s`. -/
def leAdd (r : α → α → Prop) (s : β → β → Prop) : r ≼i Sum.Lex r s :=
  ⟨⟨⟨Sum.inl, fun _ _ => Sum.inl.inj⟩, Sum.lex_inl_inl⟩, fun a b => by
    cases b <;> [

Proof state:
case inl
α : Type u_1
β : Type u_2
γ : Type u_3
r✝ : α → α → Prop
s✝ : β → β → Prop
t : γ → γ → Prop
r : α → α → Prop
s : β → β → Prop
a val✝ : α
⊢ Sum.Lex r s (Sum.inl val✝)
      ({ toEmbedding := { toFun := Sum.inl, inj' := (_ : ∀ (x x_1 : α), Sum.inl x = Sum.inl x_1 → x = x_1) },
          map_rel_iff' := (_ : ∀ {a b : α}, Sum.Lex r s (Sum.inl a) (Sum.inl b) ↔ r a b) }
        a) →
    ∃ a',
      { toEmbedding := { toFun := Sum.inl, inj' := (_ : ∀ (x x_1 : α), Sum.inl x = Sum.inl x_1 → x = x_1) },
            map_rel_iff' := (_ : ∀ {a b : α}, Sum.Lex r s (Sum.inl a) (Sum.inl b) ↔ r a b) }
          a' =
        Sum.inl val✝

Next tactic:
exact fun _ => ⟨_, rfl⟩
/-- Initial segment embedding of an order `r` into the disjoint union of `r` and `s`. -/
def leAdd (r : α → α → Prop) (s : β → β → Prop) : r ≼i Sum.Lex r s :=
  ⟨⟨⟨Sum.inl, fun _ _ => Sum.inl.inj⟩, Sum.lex_inl_inl⟩, fun a b => by
    cases b <;> [exact fun _ => ⟨_, rfl⟩; 

Proof state:
case inr
α : Type u_1
β : Type u_2
γ : Type u_3
r✝ : α → α → Prop
s✝ : β → β → Prop
t : γ → γ → Prop
r : α → α → Prop
s : β → β → Prop
a : α
val✝ : β
⊢ Sum.Lex r s (Sum.inr val✝)
      ({ toEmbedding := { toFun := Sum.inl, inj' := (_ : ∀ (x x_1 : α), Sum.inl x = Sum.inl x_1 → x = x_1) },
          map_rel_iff' := (_ : ∀ {a b : α}, Sum.Lex r s (Sum.inl a) (Sum.inl b) ↔ r a b) }
        a) →
    ∃ a',
      { toEmbedding := { toFun := Sum.inl, inj' := (_ : ∀ (x x_1 : α), Sum.inl x = Sum.inl x_1 → x = x_1) },
            map_rel_iff' := (_ : ∀ {a b : α}, Sum.Lex r s (Sum.inl a) (Sum.inl b) ↔ r a b) }
          a' =
        Sum.inr val✝

Next tactic:
exact False.elim ∘ Sum.lex_inr_inl
protected theorem acc (f : r ≼i s) (a : α) : Acc r a ↔ Acc s (f a) :=
  ⟨by
    

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
f : r ≼i s
a : α
⊢ Acc r a → Acc s (f a)

Next tactic:
refine' fun h => Acc.recOn h fun a _ ha => Acc.intro _ fun b hb => _
protected theorem acc (f : r ≼i s) (a : α) : Acc r a ↔ Acc s (f a) :=
  ⟨by
    refine' fun h => Acc.recOn h fun a _ ha => Acc.intro _ fun b hb => _
    

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
f : r ≼i s
a✝ : α
h : Acc r a✝
a : α
x✝ : ∀ (y : α), r y a → Acc r y
ha : ∀ (y : α), r y a → Acc s (f y)
b : β
hb : s b (f a)
⊢ Acc s b

Next tactic:
obtain ⟨a', rfl⟩ := f.init hb
protected theorem acc (f : r ≼i s) (a : α) : Acc r a ↔ Acc s (f a) :=
  ⟨by
    refine' fun h => Acc.recOn h fun a _ ha => Acc.intro _ fun b hb => _
    obtain ⟨a', rfl⟩ := f.init hb
    

Proof state:
case intro
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
f : r ≼i s
a✝ : α
h : Acc r a✝
a : α
x✝ : ∀ (y : α), r y a → Acc r y
ha : ∀ (y : α), r y a → Acc s (f y)
a' : α
hb : s (f a') (f a)
⊢ Acc s (f a')

Next tactic:
exact ha _ (f.map_rel_iff.mp hb)
theorem irrefl {r : α → α → Prop} [IsWellOrder α r] (f : r ≺i r) : False := by
  

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r✝ : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
r : α → α → Prop
inst✝ : IsWellOrder α r
f : r ≺i r
⊢ False

Next tactic:
have h := f.lt_top f.top
theorem irrefl {r : α → α → Prop} [IsWellOrder α r] (f : r ≺i r) : False := by
  have h := f.lt_top f.top
  

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r✝ : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
r : α → α → Prop
inst✝ : IsWellOrder α r
f : r ≺i r
h : r (f.toRelEmbedding f.top) f.top
⊢ False

Next tactic:
rw [show f f.top = f.top from InitialSeg.eq (↑f) (InitialSeg.refl r) f.top] at h
theorem irrefl {r : α → α → Prop} [IsWellOrder α r] (f : r ≺i r) : False := by
  have h := f.lt_top f.top
  rw [show f f.top = f.top from InitialSeg.eq (↑f) (InitialSeg.refl r) f.top] at h
  

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r✝ : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
r : α → α → Prop
inst✝ : IsWellOrder α r
f : r ≺i r
h : r f.top f.top
⊢ False

Next tactic:
exact _root_.irrefl _ h
/-- Composition of a principal segment with an initial segment, as a principal segment -/
def ltLe (f : r ≺i s) (g : s ≼i t) : r ≺i t :=
  ⟨@RelEmbedding.trans _ _ _ r s t f g, g f.top, fun a => by
    

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
f : r ≺i s
g : s ≼i t
a : γ
⊢ t a (g f.top) ↔ ∃ a_1, (RelEmbedding.trans f.toRelEmbedding g.toRelEmbedding) a_1 = a

Next tactic:
simp only [g.init_iff, PrincipalSeg.down, exists_and_left.symm, exists_swap,
        RelEmbedding.trans_apply, exists_eq_right', InitialSeg.coe_coe_fn]
/-- Composition of an order isomorphism with a principal segment, as a principal segment -/
def equivLT (f : r ≃r s) (g : s ≺i t) : r ≺i t :=
  ⟨@RelEmbedding.trans _ _ _ r s t f g, g.top, fun c =>
    suffices (∃ a : β, g a = c) ↔ ∃ a : α, g (f a) = c by simpa [PrincipalSeg.down]
    ⟨fun ⟨b, h⟩ => ⟨f.symm b, by 

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
f : r ≃r s
g : s ≺i t
c : γ
x✝ : ∃ a, g.toRelEmbedding a = c
b : β
h : g.toRelEmbedding b = c
⊢ g.toRelEmbedding (f ((RelIso.symm f) b)) = c

Next tactic:
simp only [h, RelIso.apply_symm_apply]
/-- Composition of an order isomorphism with a principal segment, as a principal segment -/
def equivLT (f : r ≃r s) (g : s ≺i t) : r ≺i t :=
  ⟨@RelEmbedding.trans _ _ _ r s t f g, g.top, fun c =>
    suffices (∃ a : β, g a = c) ↔ ∃ a : α, g (f a) = c by 

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
f : r ≃r s
g : s ≺i t
c : γ
this : (∃ a, g.toRelEmbedding a = c) ↔ ∃ a, g.toRelEmbedding (f a) = c
⊢ t c g.top ↔ ∃ a, (RelEmbedding.trans (RelIso.toRelEmbedding f) g.toRelEmbedding) a = c

Next tactic:
simpa [PrincipalSeg.down]
/-- Composition of a principal segment with an order isomorphism, as a principal segment -/
def ltEquiv {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop} (f : PrincipalSeg r s)
    (g : s ≃r t) : PrincipalSeg r t :=
  ⟨@RelEmbedding.trans _ _ _ r s t f g, g f.top, by
    

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r✝ : α → α → Prop
s✝ : β → β → Prop
t✝ : γ → γ → Prop
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
f : r ≺i s
g : s ≃r t
⊢ ∀ (b : γ), t b (g f.top) ↔ ∃ a, (RelEmbedding.trans f.toRelEmbedding (RelIso.toRelEmbedding g)) a = b

Next tactic:
intro x
/-- Composition of a principal segment with an order isomorphism, as a principal segment -/
def ltEquiv {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop} (f : PrincipalSeg r s)
    (g : s ≃r t) : PrincipalSeg r t :=
  ⟨@RelEmbedding.trans _ _ _ r s t f g, g f.top, by
    intro x
    

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r✝ : α → α → Prop
s✝ : β → β → Prop
t✝ : γ → γ → Prop
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
f : r ≺i s
g : s ≃r t
x : γ
⊢ t x (g f.top) ↔ ∃ a, (RelEmbedding.trans f.toRelEmbedding (RelIso.toRelEmbedding g)) a = x

Next tactic:
rw [← g.apply_symm_apply x, g.map_rel_iff, f.down', exists_congr]
/-- Composition of a principal segment with an order isomorphism, as a principal segment -/
def ltEquiv {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop} (f : PrincipalSeg r s)
    (g : s ≃r t) : PrincipalSeg r t :=
  ⟨@RelEmbedding.trans _ _ _ r s t f g, g f.top, by
    intro x
    rw [← g.apply_symm_apply x, g.map_rel_iff, f.down', exists_congr]
    

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r✝ : α → α → Prop
s✝ : β → β → Prop
t✝ : γ → γ → Prop
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
f : r ≺i s
g : s ≃r t
x : γ
⊢ ∀ (a : α),
    f.toRelEmbedding a = (RelIso.symm g) x ↔
      (RelEmbedding.trans f.toRelEmbedding (RelIso.toRelEmbedding g)) a = g ((RelIso.symm g) x)

Next tactic:
intro y
/-- Composition of a principal segment with an order isomorphism, as a principal segment -/
def ltEquiv {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop} (f : PrincipalSeg r s)
    (g : s ≃r t) : PrincipalSeg r t :=
  ⟨@RelEmbedding.trans _ _ _ r s t f g, g f.top, by
    intro x
    rw [← g.apply_symm_apply x, g.map_rel_iff, f.down', exists_congr]
    intro y; 

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r✝ : α → α → Prop
s✝ : β → β → Prop
t✝ : γ → γ → Prop
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
f : r ≺i s
g : s ≃r t
x : γ
y : α
⊢ f.toRelEmbedding y = (RelIso.symm g) x ↔
    (RelEmbedding.trans f.toRelEmbedding (RelIso.toRelEmbedding g)) y = g ((RelIso.symm g) x)

Next tactic:
exact ⟨congr_arg g, fun h => g.toEquiv.bijective.1 h⟩
/-- Given a well order `s`, there is a most one principal segment embedding of `r` into `s`. -/
instance [IsWellOrder β s] : Subsingleton (r ≺i s) :=
  ⟨fun f g => by
    

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝ : IsWellOrder β s
f g : r ≺i s
⊢ f = g

Next tactic:
have ef : (f : α → β) = g := by
      show ((f : r ≼i s) : α → β) = (g : r ≼i s)
      rw [@Subsingleton.elim _ _ (f : r ≼i s) g]
/-- Given a well order `s`, there is a most one principal segment embedding of `r` into `s`. -/
instance [IsWellOrder β s] : Subsingleton (r ≺i s) :=
  ⟨fun f g => by
    have ef : (f : α → β) = g := by
      

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝ : IsWellOrder β s
f g : r ≺i s
⊢ ⇑f.toRelEmbedding = ⇑g.toRelEmbedding

Next tactic:
show ((f : r ≼i s) : α → β) = (g : r ≼i s)
/-- Given a well order `s`, there is a most one principal segment embedding of `r` into `s`. -/
instance [IsWellOrder β s] : Subsingleton (r ≺i s) :=
  ⟨fun f g => by
    have ef : (f : α → β) = g := by
      show ((f : r ≼i s) : α → β) = (g : r ≼i s)
      

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝ : IsWellOrder β s
f g : r ≺i s
⊢ ⇑{ toRelEmbedding := f.toRelEmbedding,
        init' := (_ : ∀ (x : α) (x_1 : β), s x_1 (f.toRelEmbedding x) → ∃ a', f.toRelEmbedding a' = x_1) } =
    ⇑{ toRelEmbedding := g.toRelEmbedding,
        init' := (_ : ∀ (x : α) (x_1 : β), s x_1 (g.toRelEmbedding x) → ∃ a', g.toRelEmbedding a' = x_1) }

Next tactic:
rw [@Subsingleton.elim _ _ (f : r ≼i s) g]
/-- Given a well order `s`, there is a most one principal segment embedding of `r` into `s`. -/
instance [IsWellOrder β s] : Subsingleton (r ≺i s) :=
  ⟨fun f g => by
    have ef : (f : α → β) = g := by
      show ((f : r ≼i s) : α → β) = (g : r ≼i s)
      rw [@Subsingleton.elim _ _ (f : r ≼i s) g]
    

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝ : IsWellOrder β s
f g : r ≺i s
ef : ⇑f.toRelEmbedding = ⇑g.toRelEmbedding
⊢ f = g

Next tactic:
have et : f.top = g.top := by
      refine' extensional_of_trichotomous_of_irrefl s fun x => _
      simp only [PrincipalSeg.down, ef]
/-- Given a well order `s`, there is a most one principal segment embedding of `r` into `s`. -/
instance [IsWellOrder β s] : Subsingleton (r ≺i s) :=
  ⟨fun f g => by
    have ef : (f : α → β) = g := by
      show ((f : r ≼i s) : α → β) = (g : r ≼i s)
      rw [@Subsingleton.elim _ _ (f : r ≼i s) g]
    have et : f.top = g.top := by
      

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝ : IsWellOrder β s
f g : r ≺i s
ef : ⇑f.toRelEmbedding = ⇑g.toRelEmbedding
⊢ f.top = g.top

Next tactic:
refine' extensional_of_trichotomous_of_irrefl s fun x => _
/-- Given a well order `s`, there is a most one principal segment embedding of `r` into `s`. -/
instance [IsWellOrder β s] : Subsingleton (r ≺i s) :=
  ⟨fun f g => by
    have ef : (f : α → β) = g := by
      show ((f : r ≼i s) : α → β) = (g : r ≼i s)
      rw [@Subsingleton.elim _ _ (f : r ≼i s) g]
    have et : f.top = g.top := by
      refine' extensional_of_trichotomous_of_irrefl s fun x => _
      

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝ : IsWellOrder β s
f g : r ≺i s
ef : ⇑f.toRelEmbedding = ⇑g.toRelEmbedding
x : β
⊢ s x f.top ↔ s x g.top

Next tactic:
simp only [PrincipalSeg.down, ef]
/-- Given a well order `s`, there is a most one principal segment embedding of `r` into `s`. -/
instance [IsWellOrder β s] : Subsingleton (r ≺i s) :=
  ⟨fun f g => by
    have ef : (f : α → β) = g := by
      show ((f : r ≼i s) : α → β) = (g : r ≼i s)
      rw [@Subsingleton.elim _ _ (f : r ≼i s) g]
    have et : f.top = g.top := by
      refine' extensional_of_trichotomous_of_irrefl s fun x => _
      simp only [PrincipalSeg.down, ef]
    

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝ : IsWellOrder β s
f g : r ≺i s
ef : ⇑f.toRelEmbedding = ⇑g.toRelEmbedding
et : f.top = g.top
⊢ f = g

Next tactic:
cases f
/-- Given a well order `s`, there is a most one principal segment embedding of `r` into `s`. -/
instance [IsWellOrder β s] : Subsingleton (r ≺i s) :=
  ⟨fun f g => by
    have ef : (f : α → β) = g := by
      show ((f : r ≼i s) : α → β) = (g : r ≼i s)
      rw [@Subsingleton.elim _ _ (f : r ≼i s) g]
    have et : f.top = g.top := by
      refine' extensional_of_trichotomous_of_irrefl s fun x => _
      simp only [PrincipalSeg.down, ef]
    cases f
    

Proof state:
case mk
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝ : IsWellOrder β s
g : r ≺i s
toRelEmbedding✝ : r ↪r s
top✝ : β
down'✝ : ∀ (b : β), s b top✝ ↔ ∃ a, toRelEmbedding✝ a = b
ef : ⇑{ toRelEmbedding := toRelEmbedding✝, top := top✝, down' := down'✝ }.toRelEmbedding = ⇑g.toRelEmbedding
et : { toRelEmbedding := toRelEmbedding✝, top := top✝, down' := down'✝ }.top = g.top
⊢ { toRelEmbedding := toRelEmbedding✝, top := top✝, down' := down'✝ } = g

Next tactic:
cases g
/-- Given a well order `s`, there is a most one principal segment embedding of `r` into `s`. -/
instance [IsWellOrder β s] : Subsingleton (r ≺i s) :=
  ⟨fun f g => by
    have ef : (f : α → β) = g := by
      show ((f : r ≼i s) : α → β) = (g : r ≼i s)
      rw [@Subsingleton.elim _ _ (f : r ≼i s) g]
    have et : f.top = g.top := by
      refine' extensional_of_trichotomous_of_irrefl s fun x => _
      simp only [PrincipalSeg.down, ef]
    cases f
    cases g
    

Proof state:
case mk.mk
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝ : IsWellOrder β s
toRelEmbedding✝¹ : r ↪r s
top✝¹ : β
down'✝¹ : ∀ (b : β), s b top✝¹ ↔ ∃ a, toRelEmbedding✝¹ a = b
toRelEmbedding✝ : r ↪r s
top✝ : β
down'✝ : ∀ (b : β), s b top✝ ↔ ∃ a, toRelEmbedding✝ a = b
ef :
  ⇑{ toRelEmbedding := toRelEmbedding✝¹, top := top✝¹, down' := down'✝¹ }.toRelEmbedding =
    ⇑{ toRelEmbedding := toRelEmbedding✝, top := top✝, down' := down'✝ }.toRelEmbedding
et :
  { toRelEmbedding := toRelEmbedding✝¹, top := top✝¹, down' := down'✝¹ }.top =
    { toRelEmbedding := toRelEmbedding✝, top := top✝, down' := down'✝ }.top
⊢ { toRelEmbedding := toRelEmbedding✝¹, top := top✝¹, down' := down'✝¹ } =
    { toRelEmbedding := toRelEmbedding✝, top := top✝, down' := down'✝ }

Next tactic:
have := RelEmbedding.coe_fn_injective ef
/-- Given a well order `s`, there is a most one principal segment embedding of `r` into `s`. -/
instance [IsWellOrder β s] : Subsingleton (r ≺i s) :=
  ⟨fun f g => by
    have ef : (f : α → β) = g := by
      show ((f : r ≼i s) : α → β) = (g : r ≼i s)
      rw [@Subsingleton.elim _ _ (f : r ≼i s) g]
    have et : f.top = g.top := by
      refine' extensional_of_trichotomous_of_irrefl s fun x => _
      simp only [PrincipalSeg.down, ef]
    cases f
    cases g
    have := RelEmbedding.coe_fn_injective ef; 

Proof state:
case mk.mk
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝ : IsWellOrder β s
toRelEmbedding✝¹ : r ↪r s
top✝¹ : β
down'✝¹ : ∀ (b : β), s b top✝¹ ↔ ∃ a, toRelEmbedding✝¹ a = b
toRelEmbedding✝ : r ↪r s
top✝ : β
down'✝ : ∀ (b : β), s b top✝ ↔ ∃ a, toRelEmbedding✝ a = b
ef :
  ⇑{ toRelEmbedding := toRelEmbedding✝¹, top := top✝¹, down' := down'✝¹ }.toRelEmbedding =
    ⇑{ toRelEmbedding := toRelEmbedding✝, top := top✝, down' := down'✝ }.toRelEmbedding
et :
  { toRelEmbedding := toRelEmbedding✝¹, top := top✝¹, down' := down'✝¹ }.top =
    { toRelEmbedding := toRelEmbedding✝, top := top✝, down' := down'✝ }.top
this :
  { toRelEmbedding := toRelEmbedding✝¹, top := top✝¹, down' := down'✝¹ }.toRelEmbedding =
    { toRelEmbedding := toRelEmbedding✝, top := top✝, down' := down'✝ }.toRelEmbedding
⊢ { toRelEmbedding := toRelEmbedding✝¹, top := top✝¹, down' := down'✝¹ } =
    { toRelEmbedding := toRelEmbedding✝, top := top✝, down' := down'✝ }

Next tactic:
congr
theorem top_eq [IsWellOrder γ t] (e : r ≃r s) (f : r ≺i t) (g : s ≺i t) : f.top = g.top := by
  

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝ : IsWellOrder γ t
e : r ≃r s
f : r ≺i t
g : s ≺i t
⊢ f.top = g.top

Next tactic:
rw [Subsingleton.elim f (PrincipalSeg.equivLT e g)]
theorem top_eq [IsWellOrder γ t] (e : r ≃r s) (f : r ≺i t) (g : s ≺i t) : f.top = g.top := by
  rw [Subsingleton.elim f (PrincipalSeg.equivLT e g)]; 

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝ : IsWellOrder γ t
e : r ≃r s
f : r ≺i t
g : s ≺i t
⊢ (equivLT e g).top = g.top

Next tactic:
rfl
theorem topLTTop {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop} [IsWellOrder γ t]
    (f : PrincipalSeg r s) (g : PrincipalSeg s t) (h : PrincipalSeg r t) : t h.top g.top := by
  

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r✝ : α → α → Prop
s✝ : β → β → Prop
t✝ : γ → γ → Prop
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝ : IsWellOrder γ t
f : r ≺i s
g : s ≺i t
h : r ≺i t
⊢ t h.top g.top

Next tactic:
rw [Subsingleton.elim h (f.trans g)]
theorem topLTTop {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop} [IsWellOrder γ t]
    (f : PrincipalSeg r s) (g : PrincipalSeg s t) (h : PrincipalSeg r t) : t h.top g.top := by
  rw [Subsingleton.elim h (f.trans g)]
  

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r✝ : α → α → Prop
s✝ : β → β → Prop
t✝ : γ → γ → Prop
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝ : IsWellOrder γ t
f : r ≺i s
g : s ≺i t
h : r ≺i t
⊢ t (PrincipalSeg.trans f g).top g.top

Next tactic:
apply PrincipalSeg.lt_top
/-- Principal segment from an empty type into a type with a minimal element. -/
def ofIsEmpty (r : α → α → Prop) [IsEmpty α] {b : β} (H : ∀ b', ¬s b' b) : r ≺i s :=
  { RelEmbedding.ofIsEmpty r s with
    top := b
    down' := by 

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r✝ : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
r : α → α → Prop
inst✝ : IsEmpty α
b : β
H : ∀ (b' : β), ¬s b' b
src✝ : r ↪r s := RelEmbedding.ofIsEmpty r s
⊢ ∀ (b_1 : β),
    s b_1 b ↔
      ∃ a,
        { toEmbedding := src✝.toEmbedding,
              map_rel_iff' := (_ : ∀ {a b : α}, s (src✝.toEmbedding a) (src✝.toEmbedding b) ↔ r a b) }
            a =
          b_1

Next tactic:
simp [H]
/-- A relation is well-founded iff every principal segment of it is well-founded.

In this lemma we use `Subrel` to indicate its principal segments because it's usually more
convenient to use.
-/
theorem wellFounded_iff_wellFounded_subrel {β : Type*} {s : β → β → Prop} [IsTrans β s] :
    WellFounded s ↔ ∀ b, WellFounded (Subrel s { b' | s b' b }) := by
  

Proof state:
α : Type u_1
β✝ : Type u_2
γ : Type u_3
r : α → α → Prop
s✝ : β✝ → β✝ → Prop
t : γ → γ → Prop
β : Type u_4
s : β → β → Prop
inst✝ : IsTrans β s
⊢ WellFounded s ↔ ∀ (b : β), WellFounded (Subrel s {b' | s b' b})

Next tactic:
refine'
    ⟨fun wf b => ⟨fun b' => ((PrincipalSeg.ofElement _ b).acc b').mpr (wf.apply b')⟩, fun wf =>
      ⟨fun b => Acc.intro _ fun b' hb' => _⟩⟩
/-- A relation is well-founded iff every principal segment of it is well-founded.

In this lemma we use `Subrel` to indicate its principal segments because it's usually more
convenient to use.
-/
theorem wellFounded_iff_wellFounded_subrel {β : Type*} {s : β → β → Prop} [IsTrans β s] :
    WellFounded s ↔ ∀ b, WellFounded (Subrel s { b' | s b' b }) := by
  refine'
    ⟨fun wf b => ⟨fun b' => ((PrincipalSeg.ofElement _ b).acc b').mpr (wf.apply b')⟩, fun wf =>
      ⟨fun b => Acc.intro _ fun b' hb' => _⟩⟩
  

Proof state:
α : Type u_1
β✝ : Type u_2
γ : Type u_3
r : α → α → Prop
s✝ : β✝ → β✝ → Prop
t : γ → γ → Prop
β : Type u_4
s : β → β → Prop
inst✝ : IsTrans β s
wf : ∀ (b : β), WellFounded (Subrel s {b' | s b' b})
b b' : β
hb' : s b' b
⊢ Acc s b'

Next tactic:
let f := PrincipalSeg.ofElement s b