l3lab/ntp-mathlib huggingface dataset:
/-- To show that `[Quiver V]` is an arborescence with root `r : V`, it suffices to
  - provide a height function `V → ℕ` such that every arrow goes from a
    lower vertex to a higher vertex,
  - show that every vertex has at most one arrow to it, and
  - show that every vertex other than `r` has an arrow to it. -/
noncomputable def arborescenceMk {V : Type u} [Quiver V] (r : V) (height : V → ℕ)
    (height_lt : ∀ ⦃a b⦄, (a ⟶ b) → height a < height b)
    (unique_arrow : ∀ ⦃a b c : V⦄ (e : a ⟶ c) (f : b ⟶ c), a = b ∧ HEq e f)
    (root_or_arrow : ∀ b, b = r ∨ ∃ a, Nonempty (a ⟶ b)) :
    Arborescence V where
  root := r
  uniquePath b :=
    ⟨Classical.inhabited_of_nonempty (by
      rcases show ∃ n, height b < n from ⟨_, Nat.lt.base _⟩ with ⟨n, hn⟩
      induction' n with n ih generalizing b
      · exact False.elim (Nat.not_lt_zero _ hn)
      rcases root_or_arrow b with (⟨⟨⟩⟩ | ⟨a, ⟨e⟩⟩)
      · exact ⟨Path.nil⟩
      · rcases ih a (lt_of_lt_of_le (height_lt e) (Nat.lt_succ_iff.mp hn)) with ⟨p⟩
        exact ⟨p.cons e⟩), by
      have height_le : ∀ {a b}, Path a b → height a ≤ height b := by
        intro a b p
        induction' p with b c _ e ih
        rfl
        exact le_of_lt (lt_of_le_of_lt ih (height_lt e))
      suffices ∀ p q : Path r b, p = q by
        intro p
        apply this
      intro p q
      induction' p with a c p e ih <;> cases' q with b _ q f
      · rfl
      · exact False.elim (lt_irrefl _ (lt_of_le_of_lt (height_le q) (height_lt f)))
      · 

Proof state:
case cons.nil
V : Type u
inst✝ : Quiver V
r : V
height : V → ℕ
height_lt : ∀ ⦃a b : V⦄, (a ⟶ b) → height a < height b
unique_arrow : ∀ ⦃a b c : V⦄ (e : a ⟶ c) (f : b ⟶ c), a = b ∧ HEq e f
root_or_arrow : ∀ (b : V), b = r ∨ ∃ a, Nonempty (a ⟶ b)
b : V
height_le : ∀ {a b : V}, Path a b → height a ≤ height b
a : V
p : Path r a
ih : ∀ (q : Path r a), p = q
e : a ⟶ r
⊢ Path.cons p e = Path.nil

Next tactic:
exact False.elim (lt_irrefl _ (lt_of_le_of_lt (height_le p) (height_lt e)))
/-- To show that `[Quiver V]` is an arborescence with root `r : V`, it suffices to
  - provide a height function `V → ℕ` such that every arrow goes from a
    lower vertex to a higher vertex,
  - show that every vertex has at most one arrow to it, and
  - show that every vertex other than `r` has an arrow to it. -/
noncomputable def arborescenceMk {V : Type u} [Quiver V] (r : V) (height : V → ℕ)
    (height_lt : ∀ ⦃a b⦄, (a ⟶ b) → height a < height b)
    (unique_arrow : ∀ ⦃a b c : V⦄ (e : a ⟶ c) (f : b ⟶ c), a = b ∧ HEq e f)
    (root_or_arrow : ∀ b, b = r ∨ ∃ a, Nonempty (a ⟶ b)) :
    Arborescence V where
  root := r
  uniquePath b :=
    ⟨Classical.inhabited_of_nonempty (by
      rcases show ∃ n, height b < n from ⟨_, Nat.lt.base _⟩ with ⟨n, hn⟩
      induction' n with n ih generalizing b
      · exact False.elim (Nat.not_lt_zero _ hn)
      rcases root_or_arrow b with (⟨⟨⟩⟩ | ⟨a, ⟨e⟩⟩)
      · exact ⟨Path.nil⟩
      · rcases ih a (lt_of_lt_of_le (height_lt e) (Nat.lt_succ_iff.mp hn)) with ⟨p⟩
        exact ⟨p.cons e⟩), by
      have height_le : ∀ {a b}, Path a b → height a ≤ height b := by
        intro a b p
        induction' p with b c _ e ih
        rfl
        exact le_of_lt (lt_of_le_of_lt ih (height_lt e))
      suffices ∀ p q : Path r b, p = q by
        intro p
        apply this
      intro p q
      induction' p with a c p e ih <;> cases' q with b _ q f
      · rfl
      · exact False.elim (lt_irrefl _ (lt_of_le_of_lt (height_le q) (height_lt f)))
      · exact False.elim (lt_irrefl _ (lt_of_le_of_lt (height_le p) (height_lt e)))
      · 

Proof state:
case cons.cons
V : Type u
inst✝ : Quiver V
r : V
height : V → ℕ
height_lt : ∀ ⦃a b : V⦄, (a ⟶ b) → height a < height b
unique_arrow : ∀ ⦃a b c : V⦄ (e : a ⟶ c) (f : b ⟶ c), a = b ∧ HEq e f
root_or_arrow : ∀ (b : V), b = r ∨ ∃ a, Nonempty (a ⟶ b)
b✝ : V
height_le : ∀ {a b : V}, Path a b → height a ≤ height b
a c : V
p : Path r a
e : a ⟶ c
ih : ∀ (q : Path r a), p = q
b : V
q : Path r b
f : b ⟶ c
⊢ Path.cons p e = Path.cons q f

Next tactic:
rcases unique_arrow e f with ⟨⟨⟩, ⟨⟩⟩
/-- To show that `[Quiver V]` is an arborescence with root `r : V`, it suffices to
  - provide a height function `V → ℕ` such that every arrow goes from a
    lower vertex to a higher vertex,
  - show that every vertex has at most one arrow to it, and
  - show that every vertex other than `r` has an arrow to it. -/
noncomputable def arborescenceMk {V : Type u} [Quiver V] (r : V) (height : V → ℕ)
    (height_lt : ∀ ⦃a b⦄, (a ⟶ b) → height a < height b)
    (unique_arrow : ∀ ⦃a b c : V⦄ (e : a ⟶ c) (f : b ⟶ c), a = b ∧ HEq e f)
    (root_or_arrow : ∀ b, b = r ∨ ∃ a, Nonempty (a ⟶ b)) :
    Arborescence V where
  root := r
  uniquePath b :=
    ⟨Classical.inhabited_of_nonempty (by
      rcases show ∃ n, height b < n from ⟨_, Nat.lt.base _⟩ with ⟨n, hn⟩
      induction' n with n ih generalizing b
      · exact False.elim (Nat.not_lt_zero _ hn)
      rcases root_or_arrow b with (⟨⟨⟩⟩ | ⟨a, ⟨e⟩⟩)
      · exact ⟨Path.nil⟩
      · rcases ih a (lt_of_lt_of_le (height_lt e) (Nat.lt_succ_iff.mp hn)) with ⟨p⟩
        exact ⟨p.cons e⟩), by
      have height_le : ∀ {a b}, Path a b → height a ≤ height b := by
        intro a b p
        induction' p with b c _ e ih
        rfl
        exact le_of_lt (lt_of_le_of_lt ih (height_lt e))
      suffices ∀ p q : Path r b, p = q by
        intro p
        apply this
      intro p q
      induction' p with a c p e ih <;> cases' q with b _ q f
      · rfl
      · exact False.elim (lt_irrefl _ (lt_of_le_of_lt (height_le q) (height_lt f)))
      · exact False.elim (lt_irrefl _ (lt_of_le_of_lt (height_le p) (height_lt e)))
      · rcases unique_arrow e f with ⟨⟨⟩, ⟨⟩⟩
        

Proof state:
case cons.cons.intro.refl.refl
V : Type u
inst✝ : Quiver V
r : V
height : V → ℕ
height_lt : ∀ ⦃a b : V⦄, (a ⟶ b) → height a < height b
unique_arrow : ∀ ⦃a b c : V⦄ (e : a ⟶ c) (f : b ⟶ c), a = b ∧ HEq e f
root_or_arrow : ∀ (b : V), b = r ∨ ∃ a, Nonempty (a ⟶ b)
b : V
height_le : ∀ {a b : V}, Path a b → height a ≤ height b
a c : V
p : Path r a
e : a ⟶ c
ih : ∀ (q : Path r a), p = q
q : Path r a
β : Sort ?u.237
⊢ Path.cons p e = Path.cons q e

Next tactic:
rw [ih]
noncomputable instance geodesicArborescence : Arborescence (geodesicSubtree r) :=
  arborescenceMk r (fun a => (shortestPath r a).length)
    (by
      

Proof state:
V : Type u
inst✝¹ : Quiver V
r : V
inst✝ : RootedConnected r
⊢ ∀ ⦃a b : WideSubquiver.toType V (geodesicSubtree r)⦄,
    (a ⟶ b) → (fun a => Path.length (shortestPath r a)) a < (fun a => Path.length (shortestPath r a)) b

Next tactic:
rintro a b ⟨e, p, h⟩
noncomputable instance geodesicArborescence : Arborescence (geodesicSubtree r) :=
  arborescenceMk r (fun a => (shortestPath r a).length)
    (by
      rintro a b ⟨e, p, h⟩
      

Proof state:
case mk.intro
V : Type u
inst✝¹ : Quiver V
r : V
inst✝ : RootedConnected r
a b : WideSubquiver.toType V (geodesicSubtree r)
e : a ⟶ b
p : Path r a
h : shortestPath r b = Path.cons p e
⊢ (fun a => Path.length (shortestPath r a)) a < (fun a => Path.length (shortestPath r a)) b

Next tactic:
simp_rw [h, Path.length_cons, Nat.lt_succ_iff]
noncomputable instance geodesicArborescence : Arborescence (geodesicSubtree r) :=
  arborescenceMk r (fun a => (shortestPath r a).length)
    (by
      rintro a b ⟨e, p, h⟩
      simp_rw [h, Path.length_cons, Nat.lt_succ_iff]
      

Proof state:
case mk.intro
V : Type u
inst✝¹ : Quiver V
r : V
inst✝ : RootedConnected r
a b : WideSubquiver.toType V (geodesicSubtree r)
e : a ⟶ b
p : Path r a
h : shortestPath r b = Path.cons p e
⊢ Path.length (shortestPath r a) ≤ Path.length p

Next tactic:
apply shortest_path_spec
noncomputable instance geodesicArborescence : Arborescence (geodesicSubtree r) :=
  arborescenceMk r (fun a => (shortestPath r a).length)
    (by
      rintro a b ⟨e, p, h⟩
      simp_rw [h, Path.length_cons, Nat.lt_succ_iff]
      apply shortest_path_spec)
    (by
      

Proof state:
V : Type u
inst✝¹ : Quiver V
r : V
inst✝ : RootedConnected r
⊢ ∀ ⦃a b c : WideSubquiver.toType V (geodesicSubtree r)⦄ (e : a ⟶ c) (f : b ⟶ c), a = b ∧ HEq e f

Next tactic:
rintro a b c ⟨e, p, h⟩ ⟨f, q, j⟩
noncomputable instance geodesicArborescence : Arborescence (geodesicSubtree r) :=
  arborescenceMk r (fun a => (shortestPath r a).length)
    (by
      rintro a b ⟨e, p, h⟩
      simp_rw [h, Path.length_cons, Nat.lt_succ_iff]
      apply shortest_path_spec)
    (by
      rintro a b c ⟨e, p, h⟩ ⟨f, q, j⟩
      

Proof state:
case mk.intro.mk.intro
V : Type u
inst✝¹ : Quiver V
r : V
inst✝ : RootedConnected r
a b c : WideSubquiver.toType V (geodesicSubtree r)
e : a ⟶ c
p : Path r a
h : shortestPath r c = Path.cons p e
f : b ⟶ c
q : Path r b
j : shortestPath r c = Path.cons q f
⊢ a = b ∧
    HEq { val := e, property := (_ : ∃ p, shortestPath r c = Path.cons p e) }
      { val := f, property := (_ : ∃ p, shortestPath r c = Path.cons p f) }

Next tactic:
cases h.symm.trans j
noncomputable instance geodesicArborescence : Arborescence (geodesicSubtree r) :=
  arborescenceMk r (fun a => (shortestPath r a).length)
    (by
      rintro a b ⟨e, p, h⟩
      simp_rw [h, Path.length_cons, Nat.lt_succ_iff]
      apply shortest_path_spec)
    (by
      rintro a b c ⟨e, p, h⟩ ⟨f, q, j⟩
      cases h.symm.trans j
      

Proof state:
case mk.intro.mk.intro.refl
V : Type u
inst✝¹ : Quiver V
r : V
inst✝ : RootedConnected r
a c : WideSubquiver.toType V (geodesicSubtree r)
e : a ⟶ c
p : Path r a
h j : shortestPath r c = Path.cons p e
⊢ a = a ∧
    HEq { val := e, property := (_ : ∃ p, shortestPath r c = Path.cons p e) }
      { val := e, property := (_ : ∃ p, shortestPath r c = Path.cons p e) }

Next tactic:
constructor
noncomputable instance geodesicArborescence : Arborescence (geodesicSubtree r) :=
  arborescenceMk r (fun a => (shortestPath r a).length)
    (by
      rintro a b ⟨e, p, h⟩
      simp_rw [h, Path.length_cons, Nat.lt_succ_iff]
      apply shortest_path_spec)
    (by
      rintro a b c ⟨e, p, h⟩ ⟨f, q, j⟩
      cases h.symm.trans j
      constructor <;> 

Proof state:
case mk.intro.mk.intro.refl.left
V : Type u
inst✝¹ : Quiver V
r : V
inst✝ : RootedConnected r
a c : WideSubquiver.toType V (geodesicSubtree r)
e : a ⟶ c
p : Path r a
h j : shortestPath r c = Path.cons p e
⊢ a = a

Next tactic:
rfl
noncomputable instance geodesicArborescence : Arborescence (geodesicSubtree r) :=
  arborescenceMk r (fun a => (shortestPath r a).length)
    (by
      rintro a b ⟨e, p, h⟩
      simp_rw [h, Path.length_cons, Nat.lt_succ_iff]
      apply shortest_path_spec)
    (by
      rintro a b c ⟨e, p, h⟩ ⟨f, q, j⟩
      cases h.symm.trans j
      constructor <;> 

Proof state:
case mk.intro.mk.intro.refl.right
V : Type u
inst✝¹ : Quiver V
r : V
inst✝ : RootedConnected r
a c : WideSubquiver.toType V (geodesicSubtree r)
e : a ⟶ c
p : Path r a
h j : shortestPath r c = Path.cons p e
⊢ HEq { val := e, property := (_ : ∃ p, shortestPath r c = Path.cons p e) }
    { val := e, property := (_ : ∃ p, shortestPath r c = Path.cons p e) }

Next tactic:
rfl
noncomputable instance geodesicArborescence : Arborescence (geodesicSubtree r) :=
  arborescenceMk r (fun a => (shortestPath r a).length)
    (by
      rintro a b ⟨e, p, h⟩
      simp_rw [h, Path.length_cons, Nat.lt_succ_iff]
      apply shortest_path_spec)
    (by
      rintro a b c ⟨e, p, h⟩ ⟨f, q, j⟩
      cases h.symm.trans j
      constructor <;> rfl)
    (by
      

Proof state:
V : Type u
inst✝¹ : Quiver V
r : V
inst✝ : RootedConnected r
⊢ ∀ (b : WideSubquiver.toType V (geodesicSubtree r)), b = r ∨ ∃ a, Nonempty (a ⟶ b)

Next tactic:
intro b
noncomputable instance geodesicArborescence : Arborescence (geodesicSubtree r) :=
  arborescenceMk r (fun a => (shortestPath r a).length)
    (by
      rintro a b ⟨e, p, h⟩
      simp_rw [h, Path.length_cons, Nat.lt_succ_iff]
      apply shortest_path_spec)
    (by
      rintro a b c ⟨e, p, h⟩ ⟨f, q, j⟩
      cases h.symm.trans j
      constructor <;> rfl)
    (by
      intro b
      

Proof state:
V : Type u
inst✝¹ : Quiver V
r : V
inst✝ : RootedConnected r
b : WideSubquiver.toType V (geodesicSubtree r)
⊢ b = r ∨ ∃ a, Nonempty (a ⟶ b)

Next tactic:
rcases hp : shortestPath r b with (_ | ⟨p, e⟩)
noncomputable instance geodesicArborescence : Arborescence (geodesicSubtree r) :=
  arborescenceMk r (fun a => (shortestPath r a).length)
    (by
      rintro a b ⟨e, p, h⟩
      simp_rw [h, Path.length_cons, Nat.lt_succ_iff]
      apply shortest_path_spec)
    (by
      rintro a b c ⟨e, p, h⟩ ⟨f, q, j⟩
      cases h.symm.trans j
      constructor <;> rfl)
    (by
      intro b
      rcases hp : shortestPath r b with (_ | ⟨p, e⟩)
      · 

Proof state:
case nil
V : Type u
inst✝¹ : Quiver V
r : V
inst✝ : RootedConnected r
hp : shortestPath r r = Path.nil
⊢ r = r ∨ ∃ a, Nonempty (a ⟶ r)

Next tactic:
exact Or.inl rfl
noncomputable instance geodesicArborescence : Arborescence (geodesicSubtree r) :=
  arborescenceMk r (fun a => (shortestPath r a).length)
    (by
      rintro a b ⟨e, p, h⟩
      simp_rw [h, Path.length_cons, Nat.lt_succ_iff]
      apply shortest_path_spec)
    (by
      rintro a b c ⟨e, p, h⟩ ⟨f, q, j⟩
      cases h.symm.trans j
      constructor <;> rfl)
    (by
      intro b
      rcases hp : shortestPath r b with (_ | ⟨p, e⟩)
      · exact Or.inl rfl
      · 

Proof state:
case cons
V : Type u
inst✝¹ : Quiver V
r : V
inst✝ : RootedConnected r
b : WideSubquiver.toType V (geodesicSubtree r)
b✝ : V
p : Path r b✝
e : b✝ ⟶ b
hp : shortestPath r b = Path.cons p e
⊢ b = r ∨ ∃ a, Nonempty (a ⟶ b)

Next tactic:
exact Or.inr ⟨_, ⟨⟨e, p, hp⟩⟩⟩
@[simp]
theorem Basis.tensorProduct_apply (b : Basis ι R M) (c : Basis κ R N) (i : ι) (j : κ) :
    Basis.tensorProduct b c (i, j) = b i ⊗ₜ c j := by 

Proof state:
R : Type u_1
M : Type u_2
N : Type u_3
ι : Type u_4
κ : Type u_5
inst✝⁴ : CommRing R
inst✝³ : AddCommGroup M
inst✝² : Module R M
inst✝¹ : AddCommGroup N
inst✝ : Module R N
b : Basis ι R M
c : Basis κ R N
i : ι
j : κ
⊢ (tensorProduct b c) (i, j) = b i ⊗ₜ[R] c j

Next tactic:
simp [Basis.tensorProduct]
theorem Basis.tensorProduct_apply' (b : Basis ι R M) (c : Basis κ R N) (i : ι × κ) :
    Basis.tensorProduct b c i = b i.1 ⊗ₜ c i.2 := by 

Proof state:
R : Type u_1
M : Type u_2
N : Type u_3
ι : Type u_4
κ : Type u_5
inst✝⁴ : CommRing R
inst✝³ : AddCommGroup M
inst✝² : Module R M
inst✝¹ : AddCommGroup N
inst✝ : Module R N
b : Basis ι R M
c : Basis κ R N
i : ι × κ
⊢ (tensorProduct b c) i = b i.1 ⊗ₜ[R] c i.2

Next tactic:
simp [Basis.tensorProduct]
@[simp]
theorem Basis.tensorProduct_repr_tmul_apply (b : Basis ι R M) (c : Basis κ R N) (m : M) (n : N)
    (i : ι) (j : κ) :
    (Basis.tensorProduct b c).repr (m ⊗ₜ n) (i, j) = b.repr m i * c.repr n j := by
  

Proof state:
R : Type u_1
M : Type u_2
N : Type u_3
ι : Type u_4
κ : Type u_5
inst✝⁴ : CommRing R
inst✝³ : AddCommGroup M
inst✝² : Module R M
inst✝¹ : AddCommGroup N
inst✝ : Module R N
b : Basis ι R M
c : Basis κ R N
m : M
n : N
i : ι
j : κ
⊢ ((tensorProduct b c).repr (m ⊗ₜ[R] n)) (i, j) = (b.repr m) i * (c.repr n) j

Next tactic:
simp [Basis.tensorProduct]
instance : EmbeddingLike (r ≼i s) α β :=
  { coe := fun f => f.toFun
    coe_injective' := by
      

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
⊢ Injective fun f => f.toFun

Next tactic:
rintro ⟨f, hf⟩ ⟨g, hg⟩ h
instance : EmbeddingLike (r ≼i s) α β :=
  { coe := fun f => f.toFun
    coe_injective' := by
      rintro ⟨f, hf⟩ ⟨g, hg⟩ h
      

Proof state:
case mk.mk
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
f : r ↪r s
hf : ∀ (a : α) (b : β), s b (f a) → ∃ a', f a' = b
g : r ↪r s
hg : ∀ (a : α) (b : β), s b (g a) → ∃ a', g a' = b
h : (fun f => f.toFun) { toRelEmbedding := f, init' := hf } = (fun f => f.toFun) { toRelEmbedding := g, init' := hg }
⊢ { toRelEmbedding := f, init' := hf } = { toRelEmbedding := g, init' := hg }

Next tactic:
congr with x
instance : EmbeddingLike (r ≼i s) α β :=
  { coe := fun f => f.toFun
    coe_injective' := by
      rintro ⟨f, hf⟩ ⟨g, hg⟩ h
      congr with x
      

Proof state:
case mk.mk.e_toRelEmbedding.h
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
f : r ↪r s
hf : ∀ (a : α) (b : β), s b (f a) → ∃ a', f a' = b
g : r ↪r s
hg : ∀ (a : α) (b : β), s b (g a) → ∃ a', g a' = b
h : (fun f => f.toFun) { toRelEmbedding := f, init' := hf } = (fun f => f.toFun) { toRelEmbedding := g, init' := hg }
x : α
⊢ f x = g x

Next tactic:
exact congr_fun h x
theorem init_iff (f : r ≼i s) {a : α} {b : β} : s b (f a) ↔ ∃ a', f a' = b ∧ r a' a :=
  ⟨fun h => by
    

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
f : r ≼i s
a : α
b : β
h : s b (f a)
⊢ ∃ a', f a' = b ∧ r a' a

Next tactic:
rcases f.init h with ⟨a', rfl⟩
theorem init_iff (f : r ≼i s) {a : α} {b : β} : s b (f a) ↔ ∃ a', f a' = b ∧ r a' a :=
  ⟨fun h => by
    rcases f.init h with ⟨a', rfl⟩
    

Proof state:
case intro
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
f : r ≼i s
a a' : α
h : s (f a') (f a)
⊢ ∃ a'_1, f a'_1 = f a' ∧ r a'_1 a

Next tactic:
exact ⟨a', rfl, f.map_rel_iff.1 h⟩
/-- Composition of functions shows that `≼i` is transitive -/
@[trans]
protected def trans (f : r ≼i s) (g : s ≼i t) : r ≼i t :=
  ⟨f.1.trans g.1, fun a c h => 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 : α
c : γ
h : t c ((RelEmbedding.trans f.toRelEmbedding g.toRelEmbedding) a)
⊢ ∃ a', (RelEmbedding.trans f.toRelEmbedding g.toRelEmbedding) a' = c

Next tactic:
simp at h ⊢
/-- Composition of functions shows that `≼i` is transitive -/
@[trans]
protected def trans (f : r ≼i s) (g : s ≼i t) : r ≼i t :=
  ⟨f.1.trans g.1, fun a c h => by
    simp at h ⊢
    

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 : α
c : γ
h : t c (g (f a))
⊢ ∃ a', g (f a') = c

Next tactic:
rcases g.2 _ _ h with ⟨b, rfl⟩
/-- Composition of functions shows that `≼i` is transitive -/
@[trans]
protected def trans (f : r ≼i s) (g : s ≼i t) : r ≼i t :=
  ⟨f.1.trans g.1, fun a c h => by
    simp at h ⊢
    rcases g.2 _ _ h with ⟨b, rfl⟩; 

Proof state:
case intro
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
f : r ≼i s
g : s ≼i t
a : α
b : β
h : t (g.toRelEmbedding b) (g (f a))
⊢ ∃ a', g (f a') = g.toRelEmbedding b

Next tactic:
have h := g.map_rel_iff.1 h
/-- Composition of functions shows that `≼i` is transitive -/
@[trans]
protected def trans (f : r ≼i s) (g : s ≼i t) : r ≼i t :=
  ⟨f.1.trans g.1, fun a c h => by
    simp at h ⊢
    rcases g.2 _ _ h with ⟨b, rfl⟩; have h := g.map_rel_iff.1 h
    

Proof state:
case intro
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
f : r ≼i s
g : s ≼i t
a : α
b : β
h✝ : t (g.toRelEmbedding b) (g (f a))
h : s b (f a)
⊢ ∃ a', g (f a') = g.toRelEmbedding b

Next tactic:
rcases f.2 _ _ h with ⟨a', rfl⟩
/-- Composition of functions shows that `≼i` is transitive -/
@[trans]
protected def trans (f : r ≼i s) (g : s ≼i t) : r ≼i t :=
  ⟨f.1.trans g.1, fun a c h => by
    simp at h ⊢
    rcases g.2 _ _ h with ⟨b, rfl⟩; have h := g.map_rel_iff.1 h
    rcases f.2 _ _ h with ⟨a', rfl⟩; 

Proof state:
case intro.intro
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
f : r ≼i s
g : s ≼i t
a a' : α
h✝ : t (g.toRelEmbedding (f.toRelEmbedding a')) (g (f a))
h : s (f.toRelEmbedding a') (f a)
⊢ ∃ a'_1, g (f a'_1) = g.toRelEmbedding (f.toRelEmbedding a')

Next tactic:
exact ⟨a', rfl⟩
instance subsingleton_of_trichotomous_of_irrefl [IsTrichotomous β s] [IsIrrefl β s]
    [IsWellFounded α r] : 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✝² : IsTrichotomous β s
inst✝¹ : IsIrrefl β s
inst✝ : IsWellFounded α r
f g : r ≼i s
⊢ f = g

Next tactic:
ext a
instance subsingleton_of_trichotomous_of_irrefl [IsTrichotomous β s] [IsIrrefl β s]
    [IsWellFounded α r] : Subsingleton (r ≼i s) :=
  ⟨fun f g => by
    ext a
    

Proof state:
case h
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝² : IsTrichotomous β s
inst✝¹ : IsIrrefl β s
inst✝ : IsWellFounded α r
f g : r ≼i s
a : α
⊢ f a = g a

Next tactic:
refine' IsWellFounded.induction r a fun b IH =>
      extensional_of_trichotomous_of_irrefl s fun x => _
instance subsingleton_of_trichotomous_of_irrefl [IsTrichotomous β s] [IsIrrefl β s]
    [IsWellFounded α r] : Subsingleton (r ≼i s) :=
  ⟨fun f g => by
    ext a
    refine' IsWellFounded.induction r a fun b IH =>
      extensional_of_trichotomous_of_irrefl s fun x => _
    

Proof state:
case h
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝² : IsTrichotomous β s
inst✝¹ : IsIrrefl β s
inst✝ : IsWellFounded α r
f g : r ≼i s
a b : α
IH : ∀ (y : α), r y b → f y = g y
x : β
⊢ s x (f b) ↔ s x (g b)

Next tactic:
rw [f.init_iff, g.init_iff]
instance subsingleton_of_trichotomous_of_irrefl [IsTrichotomous β s] [IsIrrefl β s]
    [IsWellFounded α r] : Subsingleton (r ≼i s) :=
  ⟨fun f g => by
    ext a
    refine' IsWellFounded.induction r a fun b IH =>
      extensional_of_trichotomous_of_irrefl s fun x => _
    rw [f.init_iff, g.init_iff]
    

Proof state:
case h
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝² : IsTrichotomous β s
inst✝¹ : IsIrrefl β s
inst✝ : IsWellFounded α r
f g : r ≼i s
a b : α
IH : ∀ (y : α), r y b → f y = g y
x : β
⊢ (∃ a', f a' = x ∧ r a' b) ↔ ∃ a', g a' = x ∧ r a' b

Next tactic:
exact exists_congr fun x => and_congr_left fun hx => IH _ hx ▸ Iff.rfl
instance [IsWellOrder β s] : Subsingleton (r ≼i s) :=
  ⟨fun a => by 

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝ : IsWellOrder β s
a : r ≼i s
⊢ ∀ (b : r ≼i s), a = b

Next tactic:
let _ := a.isWellFounded
instance [IsWellOrder β s] : Subsingleton (r ≼i s) :=
  ⟨fun a => by let _ := a.isWellFounded; 

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝ : IsWellOrder β s
a : r ≼i s
x✝ : IsWellFounded α r := RelEmbedding.isWellFounded a.toRelEmbedding
⊢ ∀ (b : r ≼i s), a = b

Next tactic:
exact Subsingleton.elim a
protected theorem eq [IsWellOrder β s] (f g : r ≼i s) (a) : f a = g a := 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
a : α
⊢ f a = g a

Next tactic:
rw [Subsingleton.elim f g]
theorem eq_or_principal [IsWellOrder β s] (f : r ≼i s) :
    Surjective f ∨ ∃ b, ∀ x, s x b ↔ ∃ y, f y = x :=
  or_iff_not_imp_right.2 fun h b =>
    Acc.recOn (IsWellFounded.wf.apply b : Acc s b) fun x _ IH =>
      not_forall_not.1 fun hn =>
        h
          ⟨x, fun y =>
            ⟨IH _, fun ⟨a, e⟩ => by
              

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝ : IsWellOrder β s
f : r ≼i s
h : ¬∃ b, ∀ (x : β), s x b ↔ ∃ y, f y = x
b x : β
x✝¹ : ∀ (y : β), s y x → Acc s y
IH : ∀ (y : β), s y x → ∃ a, f a = y
hn : ∀ (x_1 : α), ¬f x_1 = x
y : β
x✝ : ∃ y_1, f y_1 = y
a : α
e : f a = y
⊢ s y x

Next tactic:
rw [← e]
theorem eq_or_principal [IsWellOrder β s] (f : r ≼i s) :
    Surjective f ∨ ∃ b, ∀ x, s x b ↔ ∃ y, f y = x :=
  or_iff_not_imp_right.2 fun h b =>
    Acc.recOn (IsWellFounded.wf.apply b : Acc s b) fun x _ IH =>
      not_forall_not.1 fun hn =>
        h
          ⟨x, fun y =>
            ⟨IH _, fun ⟨a, e⟩ => by
              rw [← e];
                

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
r : α → α → Prop
s : β → β → Prop
t : γ → γ → Prop
inst✝ : IsWellOrder β s
f : r ≼i s
h : ¬∃ b, ∀ (x : β), s x b ↔ ∃ y, f y = x
b x : β
x✝¹ : ∀ (y : β), s y x → Acc s y
IH : ∀ (y : β), s y x → ∃ a, f a = y
hn : ∀ (x_1 : α), ¬f x_1 = x
y : β
x✝ : ∃ y_1, f y_1 = y
a : α
e : f a = y
⊢ s (f a) x

Next tactic:
exact
                  (trichotomous _ _).resolve_right
                    (not_or_of_not (hn a) fun hl => not_exists.2 hn (f.init hl))