-- Mathlib/.lake/packages/batteries/Batteries/Data/RBMap/WF.lean
theorem Ordered.append {l : RBNode α} {v : α} {r : RBNode α}
    (lv : l.All (cmpLT cmp · v)) (vr : r.All (cmpLT cmp v ·))
    (hl : l.Ordered cmp) (hr : r.Ordered cmp) : (append l r).Ordered cmp

Proof state:
case h_3.h_2
α : Type u_1
cmp : α → α → Ordering
v : α
x✝³ x✝² a✝ : RBNode α
x✝¹ : α
b✝ c✝ : RBNode α
y✝ : α
d✝ : RBNode α
lv : All (fun x => cmpLT cmp x v) (node red a✝ x✝¹ b✝)
hl : Ordered cmp (node red a✝ x✝¹ b✝)
vr : All (fun x => cmpLT cmp v x) (node red c✝ y✝ d✝)
hr : Ordered cmp (node red c✝ y✝ d✝)
xv : (fun x => cmpLT cmp x v) x✝¹
left✝ : All (fun x => cmpLT cmp x v) a✝
bv : All (fun x => cmpLT cmp x v) b✝
ax : All (fun x => cmpLT cmp x x✝¹) a✝
xb : All (fun x => cmpLT cmp x✝¹ x) b✝
ha : Ordered cmp a✝
hb : Ordered cmp b✝
vy : (fun x => cmpLT cmp v x) y✝
vc : All (fun x => cmpLT cmp v x) c✝
right✝ : All (fun x => cmpLT cmp v x) d✝
cy : All (fun x => cmpLT cmp x y✝) c✝
yd : All (fun x => cmpLT cmp y✝ x) d✝
hc : Ordered cmp c✝
hd : Ordered cmp d✝
this :
  Ordered cmp (b✝.append c✝) ∧
    All (fun x => cmpLT cmp x✝¹ x) (b✝.append c✝) ∧ All (fun x => cmpLT cmp x y✝) (b✝.append c✝)
l✝ : RBNode α
x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), b✝.append c✝ = node red a x b → False
hbc : Ordered cmp (b✝.append c✝)
xbc : All (fun x => cmpLT cmp x✝¹ x) (b✝.append c✝)
bcy : All (fun x => cmpLT cmp x y✝) (b✝.append c✝)
xy : cmpLT cmp x✝¹ y✝
⊢ Ordered cmp (node red a✝ x✝¹ (node red (b✝.append c✝) y✝ d✝))

Tactic:
exact ⟨ax, ⟨xy, xbc, xy.trans_l yd⟩, ha, bcy, yd, hbc, hd⟩

Result:
no goals

Proof state:
case h_3.h_1
α : Type u_1
cmp : α → α → Ordering
v : α
x✝³ x✝² a✝¹ : RBNode α
x✝¹ : α
b✝¹ c✝ : RBNode α
y✝ : α
d✝ : RBNode α
lv : All (fun x => cmpLT cmp x v) (node red a✝¹ x✝¹ b✝¹)
hl : Ordered cmp (node red a✝¹ x✝¹ b✝¹)
vr : All (fun x => cmpLT cmp v x) (node red c✝ y✝ d✝)
hr : Ordered cmp (node red c✝ y✝ d✝)
xv : (fun x => cmpLT cmp x v) x✝¹
left✝ : All (fun x => cmpLT cmp x v) a✝¹
bv : All (fun x => cmpLT cmp x v) b✝¹
ax : All (fun x => cmpLT cmp x x✝¹) a✝¹
xb : All (fun x => cmpLT cmp x✝¹ x) b✝¹
ha : Ordered cmp a✝¹
hb : Ordered cmp b✝¹
vy : (fun x => cmpLT cmp v x) y✝
vc : All (fun x => cmpLT cmp v x) c✝
right✝ : All (fun x => cmpLT cmp v x) d✝
cy : All (fun x => cmpLT cmp x y✝) c✝
yd : All (fun x => cmpLT cmp y✝ x) d✝
hc : Ordered cmp c✝
hd : Ordered cmp d✝
this :
  Ordered cmp (b✝¹.append c✝) ∧
    All (fun x => cmpLT cmp x✝¹ x) (b✝¹.append c✝) ∧ All (fun x => cmpLT cmp x y✝) (b✝¹.append c✝)
l✝ a✝ : RBNode α
x✝ : α
b✝ : RBNode α
heq✝ : b✝¹.append c✝ = node red a✝ x✝ b✝
⊢ Ordered cmp (node red (node red a✝¹ x✝¹ a✝) x✝ (node red b✝ y✝ d✝))

Tactic:
next H =>
have ⟨⟨b'z, c'z, hb', hc'⟩, ⟨xz, xb', _⟩, zy, _, c'y⟩ := H ▸ this
have az := xz.trans_r ax; have zd := zy.trans_l yd
exact ⟨⟨xz, az, b'z⟩, ⟨zy, c'z, zd⟩, ⟨ax, xb', ha, hb'⟩, c'y, yd, hc', hd⟩

Result:
no goals

Proof state:
case h_5
α : Type u_1
cmp : α → α → Ordering
v : α
x✝² x✝¹ l✝ : RBNode α
v✝ : α
r✝ b✝ : RBNode α
x✝ : α
c✝ : RBNode α
lv : All (fun x => cmpLT cmp x v) (node black l✝ v✝ r✝)
hl : Ordered cmp (node black l✝ v✝ r✝)
vr : All (fun x => cmpLT cmp v x) (node red b✝ x✝ c✝)
hr : Ordered cmp (node red b✝ x✝ c✝)
vx : (fun x => cmpLT cmp v x) x✝
vb : All (fun x => cmpLT cmp v x) b✝
right✝ : All (fun x => cmpLT cmp v x) c✝
bx : All (fun x => cmpLT cmp x x✝) b✝
yc : All (fun x => cmpLT cmp x✝ x) c✝
hb : Ordered cmp b✝
hc : Ordered cmp c✝
⊢ Ordered cmp (node red ((node black l✝ v✝ r✝).append b✝) x✝ c✝)

Tactic:
exact ⟨(vx.trans_r lv).append bx, yc, hl.append lv vb hb, hc⟩

Result:
no goals

Proof state:
case h_3.h_2
α : Type u_1
cmp : α → α → Ordering
v : α
x✝³ x✝² a✝ : RBNode α
x✝¹ : α
b✝ c✝ : RBNode α
y✝ : α
d✝ : RBNode α
lv : All (fun x => cmpLT cmp x v) (node red a✝ x✝¹ b✝)
hl : Ordered cmp (node red a✝ x✝¹ b✝)
vr : All (fun x => cmpLT cmp v x) (node red c✝ y✝ d✝)
hr : Ordered cmp (node red c✝ y✝ d✝)
xv : (fun x => cmpLT cmp x v) x✝¹
left✝ : All (fun x => cmpLT cmp x v) a✝
bv : All (fun x => cmpLT cmp x v) b✝
ax : All (fun x => cmpLT cmp x x✝¹) a✝
xb : All (fun x => cmpLT cmp x✝¹ x) b✝
ha : Ordered cmp a✝
hb : Ordered cmp b✝
vy : (fun x => cmpLT cmp v x) y✝
vc : All (fun x => cmpLT cmp v x) c✝
right✝ : All (fun x => cmpLT cmp v x) d✝
cy : All (fun x => cmpLT cmp x y✝) c✝
yd : All (fun x => cmpLT cmp y✝ x) d✝
hc : Ordered cmp c✝
hd : Ordered cmp d✝
this :
  Ordered cmp (b✝.append c✝) ∧
    All (fun x => cmpLT cmp x✝¹ x) (b✝.append c✝) ∧ All (fun x => cmpLT cmp x y✝) (b✝.append c✝)
l✝ : RBNode α
x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), b✝.append c✝ = node red a x b → False
⊢ Ordered cmp (node red a✝ x✝¹ (node red (b✝.append c✝) y✝ d✝))

Tactic:
have ⟨hbc, xbc, bcy⟩ := this

Result:
case h_3.h_2
α : Type u_1
cmp : α → α → Ordering
v : α
x✝³ x✝² a✝ : RBNode α
x✝¹ : α
b✝ c✝ : RBNode α
y✝ : α
d✝ : RBNode α
lv : All (fun x => cmpLT cmp x v) (node red a✝ x✝¹ b✝)
hl : Ordered cmp (node red a✝ x✝¹ b✝)
vr : All (fun x => cmpLT cmp v x) (node red c✝ y✝ d✝)
hr : Ordered cmp (node red c✝ y✝ d✝)
xv : (fun x => cmpLT cmp x v) x✝¹
left✝ : All (fun x => cmpLT cmp x v) a✝
bv : All (fun x => cmpLT cmp x v) b✝
ax : All (fun x => cmpLT cmp x x✝¹) a✝
xb : All (fun x => cmpLT cmp x✝¹ x) b✝
ha : Ordered cmp a✝
hb : Ordered cmp b✝
vy : (fun x => cmpLT cmp v x) y✝
vc : All (fun x => cmpLT cmp v x) c✝
right✝ : All (fun x => cmpLT cmp v x) d✝
cy : All (fun x => cmpLT cmp x y✝) c✝
yd : All (fun x => cmpLT cmp y✝ x) d✝
hc : Ordered cmp c✝
hd : Ordered cmp d✝
this :
  Ordered cmp (b✝.append c✝) ∧
    All (fun x => cmpLT cmp x✝¹ x) (b✝.append c✝) ∧ All (fun x => cmpLT cmp x y✝) (b✝.append c✝)
l✝ : RBNode α
x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), b✝.append c✝ = node red a x b → False
hbc : Ordered cmp (b✝.append c✝)
xbc : All (fun x => cmpLT cmp x✝¹ x) (b✝.append c✝)
bcy : All (fun x => cmpLT cmp x y✝) (b✝.append c✝)
⊢ Ordered cmp (node red a✝ x✝¹ (node red (b✝.append c✝) y✝ d✝))

Proof state:
case h_4.h_2
α : Type u_1
cmp : α → α → Ordering
v : α
x✝³ x✝² a✝ : RBNode α
x✝¹ : α
b✝ c✝ : RBNode α
y✝ : α
d✝ : RBNode α
lv : All (fun x => cmpLT cmp x v) (node black a✝ x✝¹ b✝)
hl : Ordered cmp (node black a✝ x✝¹ b✝)
vr : All (fun x => cmpLT cmp v x) (node black c✝ y✝ d✝)
hr : Ordered cmp (node black c✝ y✝ d✝)
xv : (fun x => cmpLT cmp x v) x✝¹
left✝ : All (fun x => cmpLT cmp x v) a✝
bv : All (fun x => cmpLT cmp x v) b✝
ax : All (fun x => cmpLT cmp x x✝¹) a✝
xb : All (fun x => cmpLT cmp x✝¹ x) b✝
ha : Ordered cmp a✝
hb : Ordered cmp b✝
vy : (fun x => cmpLT cmp v x) y✝
vc : All (fun x => cmpLT cmp v x) c✝
right✝ : All (fun x => cmpLT cmp v x) d✝
cy : All (fun x => cmpLT cmp x y✝) c✝
yd : All (fun x => cmpLT cmp y✝ x) d✝
hc : Ordered cmp c✝
hd : Ordered cmp d✝
this :
  Ordered cmp (b✝.append c✝) ∧
    All (fun x => cmpLT cmp x✝¹ x) (b✝.append c✝) ∧ All (fun x => cmpLT cmp x y✝) (b✝.append c✝)
l✝ : RBNode α
x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), b✝.append c✝ = node red a x b → False
hbc : Ordered cmp (b✝.append c✝)
xbc : All (fun x => cmpLT cmp x✝¹ x) (b✝.append c✝)
bcy : All (fun x => cmpLT cmp x y✝) (b✝.append c✝)
xy : cmpLT cmp x✝¹ y✝
⊢ Ordered cmp (a✝.balLeft x✝¹ (node black (b✝.append c✝) y✝ d✝))

Tactic:
exact ha.balLeft ax ⟨xy, xbc, xy.trans_l yd⟩ ⟨bcy, yd, hbc, hd⟩

Result:
no goals