Theorem: Std.RBNode.Ordered.alter
File: Std/Data/RBMap/Alter.lean

tactic: simp [alter]
state_before: α : Type u_1
cut : α → Ordering
f : Option α → Option α
cmp : α → α → Ordering
t : RBNode α
H :
  ∀ {x : α} {t' : RBNode α} {p : Path α},
    RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t'
h : Ordered cmp t
⊢ Ordered cmp (alter cut f t)

tactic: split
state_before: α : Type u_1
cut : α → Ordering
f : Option α → Option α
cmp : α → α → Ordering
t : RBNode α
H :
  ∀ {x : α} {t' : RBNode α} {p : Path α},
    RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t'
h : Ordered cmp t
⊢ Ordered cmp
    (match RBNode.zoom cut t Path.root with
    | (nil, path) =>
      match f none with
      | none => t
      | some y => Path.insertNew path y
    | (node c a x b, path) =>
      match f (some x) with
      | none => Path.del path (append a b) c
      | some y => Path.fill path (node c a y b))

tactic: have ⟨_, hp, _, _⟩ := h.zoom eq
state_before: α : Type u_1
cut : α → Ordering
f : Option α → Option α
cmp : α → α → Ordering
t : RBNode α
H :
  ∀ {x : α} {t' : RBNode α} {p : Path α},
    RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t'
h : Ordered cmp t
x✝ : RBNode α × Path α
path : Path α
eq : RBNode.zoom cut t Path.root = (nil, path)
⊢ Ordered cmp
    (match f none with
    | none => t
    | some y => Path.insertNew path y)

tactic: split
state_before: α : Type u_1
cut : α → Ordering
f : Option α → Option α
cmp : α → α → Ordering
t : RBNode α
H :
  ∀ {x : α} {t' : RBNode α} {p : Path α},
    RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t'
h : Ordered cmp t
x✝ : RBNode α × Path α
path : Path α
eq : RBNode.zoom cut t Path.root = (nil, path)
left✝¹ : Ordered cmp nil
hp : Path.Ordered cmp path
left✝ : All (Path.RootOrdered cmp path) nil
right✝ : Path.Zoomed cut path
⊢ Ordered cmp
    (match f none with
    | none => t
    | some y => Path.insertNew path y)

tactic: exact h
state_before: case h_1
α : Type u_1
cut : α → Ordering
f : Option α → Option α
cmp : α → α → Ordering
t : RBNode α
H :
  ∀ {x : α} {t' : RBNode α} {p : Path α},
    RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t'
h : Ordered cmp t
x✝¹ : RBNode α × Path α
path : Path α
eq : RBNode.zoom cut t Path.root = (nil, path)
left✝¹ : Ordered cmp nil
hp : Path.Ordered cmp path
left✝ : All (Path.RootOrdered cmp path) nil
right✝ : Path.Zoomed cut path
x✝ : Option α
heq✝ : f none = none
⊢ Ordered cmp t

tactic: next hf => exact hp.insertNew (H eq hf).1
state_before: case h_2
α : Type u_1
cut : α → Ordering
f : Option α → Option α
cmp : α → α → Ordering
t : RBNode α
H :
  ∀ {x : α} {t' : RBNode α} {p : Path α},
    RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t'
h : Ordered cmp t
x✝¹ : RBNode α × Path α
path : Path α
eq : RBNode.zoom cut t Path.root = (nil, path)
left✝¹ : Ordered cmp nil
hp : Path.Ordered cmp path
left✝ : All (Path.RootOrdered cmp path) nil
right✝ : Path.Zoomed cut path
x✝ : Option α
y✝ : α
heq✝ : f none = some y✝
⊢ Ordered cmp (Path.insertNew path y✝)

tactic: exact hp.insertNew (H eq hf).1
state_before: α : Type u_1
cut : α → Ordering
f : Option α → Option α
cmp : α → α → Ordering
t : RBNode α
H :
  ∀ {x : α} {t' : RBNode α} {p : Path α},
    RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t'
h : Ordered cmp t
x✝¹ : RBNode α × Path α
path : Path α
eq : RBNode.zoom cut t Path.root = (nil, path)
left✝¹ : Ordered cmp nil
hp : Path.Ordered cmp path
left✝ : All (Path.RootOrdered cmp path) nil
right✝ : Path.Zoomed cut path
x✝ : Option α
y✝ : α
hf : f none = some y✝
⊢ Ordered cmp (Path.insertNew path y✝)

tactic: have ⟨⟨ax, xb, ha, hb⟩, hp, ⟨_, ap, bp⟩, _⟩ := h.zoom eq
state_before: α : Type u_1
cut : α → Ordering
f : Option α → Option α
cmp : α → α → Ordering
t : RBNode α
H :
  ∀ {x : α} {t' : RBNode α} {p : Path α},
    RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t'
h : Ordered cmp t
x✝¹ : RBNode α × Path α
c✝ : RBColor
a✝ : RBNode α
x✝ : α
b✝ : RBNode α
path : Path α
eq : RBNode.zoom cut t Path.root = (node c✝ a✝ x✝ b✝, path)
⊢ Ordered cmp
    (match f (some x✝) with
    | none => Path.del path (append a✝ b✝) c✝
    | some y => Path.fill path (node c✝ a✝ y b✝))

tactic: split
state_before: α : Type u_1
cut : α → Ordering
f : Option α → Option α
cmp : α → α → Ordering
t : RBNode α
H :
  ∀ {x : α} {t' : RBNode α} {p : Path α},
    RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t'
h : Ordered cmp t
x✝¹ : RBNode α × Path α
c✝ : RBColor
a✝ : RBNode α
x✝ : α
b✝ : RBNode α
path : Path α
eq : RBNode.zoom cut t Path.root = (node c✝ a✝ x✝ b✝, path)
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✝
hp : Path.Ordered cmp path
left✝ : Path.RootOrdered cmp path x✝
ap : All (Path.RootOrdered cmp path) a✝
bp : All (Path.RootOrdered cmp path) b✝
right✝ : Path.Zoomed cut path
⊢ Ordered cmp
    (match f (some x✝) with
    | none => Path.del path (append a✝ b✝) c✝
    | some y => Path.fill path (node c✝ a✝ y b✝))

tactic: exact hp.del (ha.append ax xb hb) (ap.append bp)
state_before: case h_1
α : Type u_1
cut : α → Ordering
f : Option α → Option α
cmp : α → α → Ordering
t : RBNode α
H :
  ∀ {x : α} {t' : RBNode α} {p : Path α},
    RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t'
h : Ordered cmp t
x✝² : RBNode α × Path α
c✝ : RBColor
a✝ : RBNode α
x✝¹ : α
b✝ : RBNode α
path : Path α
eq : RBNode.zoom cut t Path.root = (node c✝ a✝ x✝¹ b✝, path)
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✝
hp : Path.Ordered cmp path
left✝ : Path.RootOrdered cmp path x✝¹
ap : All (Path.RootOrdered cmp path) a✝
bp : All (Path.RootOrdered cmp path) b✝
right✝ : Path.Zoomed cut path
x✝ : Option α
heq✝ : f (some x✝¹) = none
⊢ Ordered cmp (Path.del path (append a✝ b✝) c✝)

tactic: next hf =>
have ⟨yp, xy⟩ := H eq hf
apply Path.Ordered.fill.2
exact ⟨hp, ⟨ax.imp xy.lt_congr_right.2, xb.imp xy.lt_congr_left.2, ha, hb⟩, yp, ap, bp⟩
state_before: case h_2
α : Type u_1
cut : α → Ordering
f : Option α → Option α
cmp : α → α → Ordering
t : RBNode α
H :
  ∀ {x : α} {t' : RBNode α} {p : Path α},
    RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t'
h : Ordered cmp t
x✝² : RBNode α × Path α
c✝ : RBColor
a✝ : RBNode α
x✝¹ : α
b✝ : RBNode α
path : Path α
eq : RBNode.zoom cut t Path.root = (node c✝ a✝ x✝¹ b✝, path)
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✝
hp : Path.Ordered cmp path
left✝ : Path.RootOrdered cmp path x✝¹
ap : All (Path.RootOrdered cmp path) a✝
bp : All (Path.RootOrdered cmp path) b✝
right✝ : Path.Zoomed cut path
x✝ : Option α
y✝ : α
heq✝ : f (some x✝¹) = some y✝
⊢ Ordered cmp (Path.fill path (node c✝ a✝ y✝ b✝))

tactic: have ⟨yp, xy⟩ := H eq hf
state_before: α : Type u_1
cut : α → Ordering
f : Option α → Option α
cmp : α → α → Ordering
t : RBNode α
H :
  ∀ {x : α} {t' : RBNode α} {p : Path α},
    RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t'
h : Ordered cmp t
x✝² : RBNode α × Path α
c✝ : RBColor
a✝ : RBNode α
x✝¹ : α
b✝ : RBNode α
path : Path α
eq : RBNode.zoom cut t Path.root = (node c✝ a✝ x✝¹ b✝, path)
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✝
hp : Path.Ordered cmp path
left✝ : Path.RootOrdered cmp path x✝¹
ap : All (Path.RootOrdered cmp path) a✝
bp : All (Path.RootOrdered cmp path) b✝
right✝ : Path.Zoomed cut path
x✝ : Option α
y✝ : α
hf : f (some x✝¹) = some y✝
⊢ Ordered cmp (Path.fill path (node c✝ a✝ y✝ b✝))

tactic: apply Path.Ordered.fill.2
state_before: α : Type u_1
cut : α → Ordering
f : Option α → Option α
cmp : α → α → Ordering
t : RBNode α
H :
  ∀ {x : α} {t' : RBNode α} {p : Path α},
    RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t'
h : Ordered cmp t
x✝² : RBNode α × Path α
c✝ : RBColor
a✝ : RBNode α
x✝¹ : α
b✝ : RBNode α
path : Path α
eq : RBNode.zoom cut t Path.root = (node c✝ a✝ x✝¹ b✝, path)
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✝
hp : Path.Ordered cmp path
left✝ : Path.RootOrdered cmp path x✝¹
ap : All (Path.RootOrdered cmp path) a✝
bp : All (Path.RootOrdered cmp path) b✝
right✝ : Path.Zoomed cut path
x✝ : Option α
y✝ : α
hf : f (some x✝¹) = some y✝
yp : Path.RootOrdered cmp path y✝
xy : OnRoot (cmpEq cmp y✝) (node c✝ a✝ x✝¹ b✝)
⊢ Ordered cmp (Path.fill path (node c✝ a✝ y✝ b✝))

tactic: exact ⟨hp, ⟨ax.imp xy.lt_congr_right.2, xb.imp xy.lt_congr_left.2, ha, hb⟩, yp, ap, bp⟩
state_before: α : Type u_1
cut : α → Ordering
f : Option α → Option α
cmp : α → α → Ordering
t : RBNode α
H :
  ∀ {x : α} {t' : RBNode α} {p : Path α},
    RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t'
h : Ordered cmp t
x✝² : RBNode α × Path α
c✝ : RBColor
a✝ : RBNode α
x✝¹ : α
b✝ : RBNode α
path : Path α
eq : RBNode.zoom cut t Path.root = (node c✝ a✝ x✝¹ b✝, path)
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✝
hp : Path.Ordered cmp path
left✝ : Path.RootOrdered cmp path x✝¹
ap : All (Path.RootOrdered cmp path) a✝
bp : All (Path.RootOrdered cmp path) b✝
right✝ : Path.Zoomed cut path
x✝ : Option α
y✝ : α
hf : f (some x✝¹) = some y✝
yp : Path.RootOrdered cmp path y✝
xy : OnRoot (cmpEq cmp y✝) (node c✝ a✝ x✝¹ b✝)
⊢ Path.Ordered cmp path ∧ Ordered cmp (node c✝ a✝ y✝ b✝) ∧ All (Path.RootOrdered cmp path) (node c✝ a✝ y✝ b✝)