Theorem: Batteries.UnionFind.findAux_root
File: .lake/packages/batteries/Batteries/Data/UnionFind/Basic.lean

tactic: rw [findAux, root]
state_before: self : UnionFind
x : Fin self.size
⊢ (self.findAux x).root = self.root x
state_after: self : UnionFind
x : Fin self.size
⊢ (if h : (self.arr.get x).parent = ↑x then { s := self.arr, root := x, size_eq := ⋯ }
      else
        let_fun this := ⋯;
        match self.findAux ⟨(self.arr.get x).parent, ⋯⟩ with
        | { s := arr₁, root := root, size_eq := H } =>
          { s := arr₁.modify ↑x fun s => { parent := ↑root, rank := s.rank }, root := root, size_eq := ⋯ }).root =
    if h : (self.arr.get x).parent = ↑x then x
    else
      let_fun this := ⋯;
      self.root ⟨(self.arr.get x).parent, ⋯⟩

tactic: simp
state_before: self : UnionFind
x : Fin self.size
⊢ (if h : (self.arr.get x).parent = ↑x then { s := self.arr, root := x, size_eq := ⋯ }
      else
        let_fun this := ⋯;
        match self.findAux ⟨(self.arr.get x).parent, ⋯⟩ with
        | { s := arr₁, root := root, size_eq := H } =>
          { s := arr₁.modify ↑x fun s => { parent := ↑root, rank := s.rank }, root := root, size_eq := ⋯ }).root =
    if h : (self.arr.get x).parent = ↑x then x
    else
      let_fun this := ⋯;
      self.root ⟨(self.arr.get x).parent, ⋯⟩
state_after: self : UnionFind
x : Fin self.size
⊢ (if self.arr[↑x].parent = ↑x then { s := self.arr, root := x, size_eq := ⋯ }
      else
        {
          s :=
            (self.findAux ⟨self.arr[↑x].parent, ⋯⟩).s.modify ↑x fun s =>
              { parent := ↑(self.findAux ⟨self.arr[↑x].parent, ⋯⟩).root, rank := s.rank },
          root := (self.findAux ⟨self.arr[↑x].parent, ⋯⟩).root, size_eq := ⋯ }).root =
    if self.arr[↑x].parent = ↑x then x else self.root ⟨self.arr[↑x].parent, ⋯⟩

tactic: split <;> simp
state_before: self : UnionFind
x : Fin self.size
⊢ (if self.arr[↑x].parent = ↑x then { s := self.arr, root := x, size_eq := ⋯ }
      else
        {
          s :=
            (self.findAux ⟨self.arr[↑x].parent, ⋯⟩).s.modify ↑x fun s =>
              { parent := ↑(self.findAux ⟨self.arr[↑x].parent, ⋯⟩).root, rank := s.rank },
          root := (self.findAux ⟨self.arr[↑x].parent, ⋯⟩).root, size_eq := ⋯ }).root =
    if self.arr[↑x].parent = ↑x then x else self.root ⟨self.arr[↑x].parent, ⋯⟩
state_after: case isFalse
self : UnionFind
x : Fin self.size
h✝ : ¬self.arr[↑x].parent = ↑x
⊢ (self.findAux ⟨self.arr[↑x].parent, ⋯⟩).root = self.root ⟨self.arr[↑x].parent, ⋯⟩

tactic: have := Nat.sub_lt_sub_left (self.lt_rankMax x) (self.rank'_lt _ ‹_›)
state_before: case isFalse
self : UnionFind
x : Fin self.size
h✝ : ¬self.arr[↑x].parent = ↑x
⊢ (self.findAux ⟨self.arr[↑x].parent, ⋯⟩).root = self.root ⟨self.arr[↑x].parent, ⋯⟩
state_after: case isFalse
self : UnionFind
x : Fin self.size
h✝ : ¬self.arr[↑x].parent = ↑x
this : self.rankMax - self.rank (self.arr.get x).parent < self.rankMax - self.rank ↑x
⊢ (self.findAux ⟨self.arr[↑x].parent, ⋯⟩).root = self.root ⟨self.arr[↑x].parent, ⋯⟩

tactic: exact findAux_root
state_before: case isFalse
self : UnionFind
x : Fin self.size
h✝ : ¬self.arr[↑x].parent = ↑x
this : self.rankMax - self.rank (self.arr.get x).parent < self.rankMax - self.rank ↑x
⊢ (self.findAux ⟨self.arr[↑x].parent, ⋯⟩).root = self.root ⟨self.arr[↑x].parent, ⋯⟩
state_after: no goals