Theorem: Batteries.UnionFind.parentD_linkAux
File: .lake/packages/batteries/Batteries/Data/UnionFind/Lemmas.lean

tactic: dsimp only [linkAux]
state_before: i : Nat
self : Array UFNode
x y : Fin self.size
⊢ parentD (linkAux self x y) i =
    if ↑x = ↑y then parentD self i
    else
      if (self.get y).rank < (self.get x).rank then if ↑y = i then ↑x else parentD self i
      else if ↑x = i then ↑y else parentD self i
state_after: i : Nat
self : Array UFNode
x y : Fin self.size
⊢ parentD
      (if ↑x = ↑y then self
      else
        if (self.get y).rank < (self.get x).rank then self.set y { parent := ↑x, rank := (self.get y).rank }
        else
          if (self.get x).rank = (self.get y).rank then
            (self.set x { parent := ↑y, rank := (self.get x).rank }).set ⟨↑y, ⋯⟩
              { parent := (self.get y).parent, rank := (self.get y).rank + 1 }
          else self.set x { parent := ↑y, rank := (self.get x).rank })
      i =
    if ↑x = ↑y then parentD self i
    else
      if (self.get y).rank < (self.get x).rank then if ↑y = i then ↑x else parentD self i
      else if ↑x = i then ↑y else parentD self i

tactic: split <;> [rfl; split] <;> [rw [parentD_set]; split] <;> rw [parentD_set]
state_before: i : Nat
self : Array UFNode
x y : Fin self.size
⊢ parentD
      (if ↑x = ↑y then self
      else
        if (self.get y).rank < (self.get x).rank then self.set y { parent := ↑x, rank := (self.get y).rank }
        else
          if (self.get x).rank = (self.get y).rank then
            (self.set x { parent := ↑y, rank := (self.get x).rank }).set ⟨↑y, ⋯⟩
              { parent := (self.get y).parent, rank := (self.get y).rank + 1 }
          else self.set x { parent := ↑y, rank := (self.get x).rank })
      i =
    if ↑x = ↑y then parentD self i
    else
      if (self.get y).rank < (self.get x).rank then if ↑y = i then ↑x else parentD self i
      else if ↑x = i then ↑y else parentD self i
state_after: case isFalse.isFalse.isTrue
i : Nat
self : Array UFNode
x y : Fin self.size
h✝² : ¬↑x = ↑y
h✝¹ : ¬(self.get y).rank < (self.get x).rank
h✝ : (self.get x).rank = (self.get y).rank
⊢ (if ↑⟨↑y, ⋯⟩ = i then { parent := (self.get y).parent, rank := (self.get y).rank + 1 }.parent
    else parentD (self.set x { parent := ↑y, rank := (self.get x).rank }) i) =
    if ↑x = i then ↑y else parentD self i

tactic: split <;> [(subst i; rwa [if_neg, parentD_eq]); rw [parentD_set]]
state_before: case isFalse.isFalse.isTrue
i : Nat
self : Array UFNode
x y : Fin self.size
h✝² : ¬↑x = ↑y
h✝¹ : ¬(self.get y).rank < (self.get x).rank
h✝ : (self.get x).rank = (self.get y).rank
⊢ (if ↑⟨↑y, ⋯⟩ = i then { parent := (self.get y).parent, rank := (self.get y).rank + 1 }.parent
    else parentD (self.set x { parent := ↑y, rank := (self.get x).rank }) i) =
    if ↑x = i then ↑y else parentD self i
state_after: no goals

tactic: subst i
state_before: case isFalse.isFalse.isTrue.isTrue
i : Nat
self : Array UFNode
x y : Fin self.size
h✝³ : ¬↑x = ↑y
h✝² : ¬(self.get y).rank < (self.get x).rank
h✝¹ : (self.get x).rank = (self.get y).rank
h✝ : ↑⟨↑y, ⋯⟩ = i
⊢ { parent := (self.get y).parent, rank := (self.get y).rank + 1 }.parent = if ↑x = i then ↑y else parentD self i
state_after: case isFalse.isFalse.isTrue.isTrue
self : Array UFNode
x y : Fin self.size
h✝² : ¬↑x = ↑y
h✝¹ : ¬(self.get y).rank < (self.get x).rank
h✝ : (self.get x).rank = (self.get y).rank
⊢ { parent := (self.get y).parent, rank := (self.get y).rank + 1 }.parent =
    if ↑x = ↑⟨↑y, ⋯⟩ then ↑y else parentD self ↑⟨↑y, ⋯⟩

tactic: rwa [if_neg, parentD_eq]
state_before: case isFalse.isFalse.isTrue.isTrue
self : Array UFNode
x y : Fin self.size
h✝² : ¬↑x = ↑y
h✝¹ : ¬(self.get y).rank < (self.get x).rank
h✝ : (self.get x).rank = (self.get y).rank
⊢ { parent := (self.get y).parent, rank := (self.get y).rank + 1 }.parent =
    if ↑x = ↑⟨↑y, ⋯⟩ then ↑y else parentD self ↑⟨↑y, ⋯⟩
state_after: no goals