Theorem: Ordnode.dual_balanceL
File: Mathlib/Data/Ordmap/Ordset.lean

Proof steps:
state_before: α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
⊢ (l.balanceL x r).dual = r.dual.balanceR x l.dual
state_after: α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
⊢ (Ordnode.casesOn (motive := fun t => id r = t → Ordnode α) (id r)
        (fun h =>
          Ordnode.casesOn (motive := fun t => id l = t → Ordnode α) (id l) (fun h => Ordnode.singleton x)
            (fun ls ll lx lr h =>
              Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                (fun h =>
                  Ordnode.casesOn (motive := fun t => lr = t → Ordnode α) lr (fun h => node 2 l x nil)
                    (fun size l lrx r h => node 3 (Ordnode.singleton lx) lrx (Ordnode.singleton x)) ⋯)
                (fun lls l x_1 r h =>
                  Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                    (fun h => node 3 ll lx (Ordnode.singleton x))
                    (fun lrs lrl lrx lrr h =>
                      if lrs < ratio * lls then node (ls + 1) ll lx (node (lrs + 1) lr x nil)
                      else node (ls + 1) (node (lls + lrl.size + 1) ll lx lrl) lrx (node (lrr.size + 1) lrr x nil))
                    ⋯)
                ⋯)
            ⋯)
        (fun rs l_1 x_1 r_1 h =>
          Ordnode.casesOn (motive := fun t => id l = t → Ordnode α) (id l) (fun h => node (rs + 1) nil x r)
            (fun ls ll lx lr h =>
              if ls > delta * rs then
                Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll) (fun h => nil)
                  (fun lls l x_2 r_2 h =>
                    Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr) (fun h => nil)
                      (fun lrs lrl lrx lrr h =>
                        if lrs < ratio * lls then node (ls + rs + 1) ll lx (node (rs + lrs + 1) lr x r)
                        else
                          node (ls + rs + 1) (node (lls + lrl.size + 1) ll lx lrl) lrx
                            (node (lrr.size + rs + 1) lrr x r))
                      ⋯)
                  ⋯
              else node (ls + rs + 1) l x r)
            ⋯)
        ⋯).dual =
    Ordnode.casesOn (motive := fun t => id r.dual = t → Ordnode α) (id r.dual)
      (fun h =>
        Ordnode.casesOn (motive := fun t => id l.dual = t → Ordnode α) (id l.dual) (fun h => Ordnode.singleton x)
          (fun rs rl rx rr h =>
            Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
              (fun h =>
                Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl (fun h => node 2 nil x l.dual)
                  (fun size l rlx r h => node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx)) ⋯)
              (fun rrs l x_1 r h =>
                Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                  (fun h => node 3 (Ordnode.singleton x) rx rr)
                  (fun rls rll rlx rlr h =>
                    if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                    else node (rs + 1) (node (rll.size + 1) nil x rll) rlx (node (rlr.size + rrs + 1) rlr rx rr))
                  ⋯)
              ⋯)
          ⋯)
      (fun ls l_1 x_1 r_1 h =>
        Ordnode.casesOn (motive := fun t => id l.dual = t → Ordnode α) (id l.dual) (fun h => node (ls + 1) r.dual x nil)
          (fun rs rl rx rr h =>
            if rs > delta * ls then
              Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr) (fun h => nil)
                (fun rrs l x_2 r_2 h =>
                  Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl) (fun h => nil)
                    (fun rls rll rlx rlr h =>
                      if rls < ratio * rrs then node (ls + rs + 1) (node (ls + rls + 1) r.dual x rl) rx rr
                      else
                        node (ls + rs + 1) (node (ls + rll.size + 1) r.dual x rll) rlx
                          (node (rlr.size + rrs + 1) rlr rx rr))
                    ⋯)
                ⋯
            else node (ls + rs + 1) r.dual x l.dual)
          ⋯)
      ⋯
tactic: unfold balanceL balanceR
state_before: α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
⊢ (Ordnode.casesOn (motive := fun t => id r = t → Ordnode α) (id r)
        (fun h =>
          Ordnode.casesOn (motive := fun t => id l = t → Ordnode α) (id l) (fun h => Ordnode.singleton x)
            (fun ls ll lx lr h =>
              Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                (fun h =>
                  Ordnode.casesOn (motive := fun t => lr = t → Ordnode α) lr (fun h => node 2 l x nil)
                    (fun size l lrx r h => node 3 (Ordnode.singleton lx) lrx (Ordnode.singleton x)) ⋯)
                (fun lls l x_1 r h =>
                  Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                    (fun h => node 3 ll lx (Ordnode.singleton x))
                    (fun lrs lrl lrx lrr h =>
                      if lrs < ratio * lls then node (ls + 1) ll lx (node (lrs + 1) lr x nil)
                      else node (ls + 1) (node (lls + lrl.size + 1) ll lx lrl) lrx (node (lrr.size + 1) lrr x nil))
                    ⋯)
                ⋯)
            ⋯)
        (fun rs l_1 x_1 r_1 h =>
          Ordnode.casesOn (motive := fun t => id l = t → Ordnode α) (id l) (fun h => node (rs + 1) nil x r)
            (fun ls ll lx lr h =>
              if ls > delta * rs then
                Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll) (fun h => nil)
                  (fun lls l x_2 r_2 h =>
                    Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr) (fun h => nil)
                      (fun lrs lrl lrx lrr h =>
                        if lrs < ratio * lls then node (ls + rs + 1) ll lx (node (rs + lrs + 1) lr x r)
                        else
                          node (ls + rs + 1) (node (lls + lrl.size + 1) ll lx lrl) lrx
                            (node (lrr.size + rs + 1) lrr x r))
                      ⋯)
                  ⋯
              else node (ls + rs + 1) l x r)
            ⋯)
        ⋯).dual =
    Ordnode.casesOn (motive := fun t => id r.dual = t → Ordnode α) (id r.dual)
      (fun h =>
        Ordnode.casesOn (motive := fun t => id l.dual = t → Ordnode α) (id l.dual) (fun h => Ordnode.singleton x)
          (fun rs rl rx rr h =>
            Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
              (fun h =>
                Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl (fun h => node 2 nil x l.dual)
                  (fun size l rlx r h => node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx)) ⋯)
              (fun rrs l x_1 r h =>
                Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                  (fun h => node 3 (Ordnode.singleton x) rx rr)
                  (fun rls rll rlx rlr h =>
                    if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                    else node (rs + 1) (node (rll.size + 1) nil x rll) rlx (node (rlr.size + rrs + 1) rlr rx rr))
                  ⋯)
              ⋯)
          ⋯)
      (fun ls l_1 x_1 r_1 h =>
        Ordnode.casesOn (motive := fun t => id l.dual = t → Ordnode α) (id l.dual) (fun h => node (ls + 1) r.dual x nil)
          (fun rs rl rx rr h =>
            if rs > delta * ls then
              Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr) (fun h => nil)
                (fun rrs l x_2 r_2 h =>
                  Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl) (fun h => nil)
                    (fun rls rll rlx rlr h =>
                      if rls < ratio * rrs then node (ls + rs + 1) (node (ls + rls + 1) r.dual x rl) rx rr
                      else
                        node (ls + rs + 1) (node (ls + rll.size + 1) r.dual x rll) rlx
                          (node (rlr.size + rrs + 1) rlr rx rr))
                    ⋯)
                ⋯
            else node (ls + rs + 1) r.dual x l.dual)
          ⋯)
      ⋯
state_after: case nil
α : Type u_1
l : Ordnode α
x : α
⊢ (Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
        (fun h =>
          Ordnode.casesOn (motive := fun t => id l = t → Ordnode α) (id l) (fun h => Ordnode.singleton x)
            (fun ls ll lx lr h =>
              Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                (fun h =>
                  Ordnode.casesOn (motive := fun t => lr = t → Ordnode α) lr (fun h => node 2 l x nil)
                    (fun size l lrx r h => node 3 (Ordnode.singleton lx) lrx (Ordnode.singleton x)) ⋯)
                (fun lls l x_1 r h =>
                  Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                    (fun h => node 3 ll lx (Ordnode.singleton x))
                    (fun lrs lrl lrx lrr h =>
                      if lrs < ratio * lls then node (ls + 1) ll lx (node (lrs + 1) lr x nil)
                      else node (ls + 1) (node (lls + lrl.size + 1) ll lx lrl) lrx (node (lrr.size + 1) lrr x nil))
                    ⋯)
                ⋯)
            ⋯)
        (fun rs l_1 x_1 r h =>
          Ordnode.casesOn (motive := fun t => id l = t → Ordnode α) (id l) (fun h => node (rs + 1) nil x nil)
            (fun ls ll lx lr h =>
              if ls > delta * rs then
                Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll) (fun h => nil)
                  (fun lls l x_2 r h =>
                    Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr) (fun h => nil)
                      (fun lrs lrl lrx lrr h =>
                        if lrs < ratio * lls then node (ls + rs + 1) ll lx (node (rs + lrs + 1) lr x nil)
                        else
                          node (ls + rs + 1) (node (lls + lrl.size + 1) ll lx lrl) lrx
                            (node (lrr.size + rs + 1) lrr x nil))
                      ⋯)
                  ⋯
              else node (ls + rs + 1) l x nil)
            ⋯)
        ⋯).dual =
    Ordnode.casesOn (motive := fun t => id nil.dual = t → Ordnode α) (id nil.dual)
      (fun h =>
        Ordnode.casesOn (motive := fun t => id l.dual = t → Ordnode α) (id l.dual) (fun h => Ordnode.singleton x)
          (fun rs rl rx rr h =>
            Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
              (fun h =>
                Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl (fun h => node 2 nil x l.dual)
                  (fun size l rlx r h => node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx)) ⋯)
              (fun rrs l x_1 r h =>
                Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                  (fun h => node 3 (Ordnode.singleton x) rx rr)
                  (fun rls rll rlx rlr h =>
                    if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                    else node (rs + 1) (node (rll.size + 1) nil x rll) rlx (node (rlr.size + rrs + 1) rlr rx rr))
                  ⋯)
              ⋯)
          ⋯)
      (fun ls l_1 x_1 r h =>
        Ordnode.casesOn (motive := fun t => id l.dual = t → Ordnode α) (id l.dual)
          (fun h => node (ls + 1) nil.dual x nil)
          (fun rs rl rx rr h =>
            if rs > delta * ls then
              Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr) (fun h => nil)
                (fun rrs l x_2 r h =>
                  Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl) (fun h => nil)
                    (fun rls rll rlx rlr h =>
                      if rls < ratio * rrs then node (ls + rs + 1) (node (ls + rls + 1) nil.dual x rl) rx rr
                      else
                        node (ls + rs + 1) (node (ls + rll.size + 1) nil.dual x rll) rlx
                          (node (rlr.size + rrs + 1) rlr rx rr))
                    ⋯)
                ⋯
            else node (ls + rs + 1) nil.dual x l.dual)
          ⋯)
      ⋯

case node
α : Type u_1
l : Ordnode α
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
⊢ (Ordnode.casesOn (motive := fun t => id (node rs rl rx rr) = t → Ordnode α) (id (node rs rl rx rr))
        (fun h =>
          Ordnode.casesOn (motive := fun t => id l = t → Ordnode α) (id l) (fun h => Ordnode.singleton x)
            (fun ls ll lx lr h =>
              Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                (fun h =>
                  Ordnode.casesOn (motive := fun t => lr = t → Ordnode α) lr (fun h => node 2 l x nil)
                    (fun size l lrx r h => node 3 (Ordnode.singleton lx) lrx (Ordnode.singleton x)) ⋯)
                (fun lls l x_1 r h =>
                  Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                    (fun h => node 3 ll lx (Ordnode.singleton x))
                    (fun lrs lrl lrx lrr h =>
                      if lrs < ratio * lls then node (ls + 1) ll lx (node (lrs + 1) lr x nil)
                      else node (ls + 1) (node (lls + lrl.size + 1) ll lx lrl) lrx (node (lrr.size + 1) lrr x nil))
                    ⋯)
                ⋯)
            ⋯)
        (fun rs_1 l_1 x_1 r h =>
          Ordnode.casesOn (motive := fun t => id l = t → Ordnode α) (id l)
            (fun h => node (rs_1 + 1) nil x (node rs rl rx rr))
            (fun ls ll lx lr h =>
              if ls > delta * rs_1 then
                Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll) (fun h => nil)
                  (fun lls l x_2 r h =>
                    Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr) (fun h => nil)
                      (fun lrs lrl lrx lrr h =>
                        if lrs < ratio * lls then
                          node (ls + rs_1 + 1) ll lx (node (rs_1 + lrs + 1) lr x (node rs rl rx rr))
                        else
                          node (ls + rs_1 + 1) (node (lls + lrl.size + 1) ll lx lrl) lrx
                            (node (lrr.size + rs_1 + 1) lrr x (node rs rl rx rr)))
                      ⋯)
                  ⋯
              else node (ls + rs_1 + 1) l x (node rs rl rx rr))
            ⋯)
        ⋯).dual =
    Ordnode.casesOn (motive := fun t => id (node rs rl rx rr).dual = t → Ordnode α) (id (node rs rl rx rr).dual)
      (fun h =>
        Ordnode.casesOn (motive := fun t => id l.dual = t → Ordnode α) (id l.dual) (fun h => Ordnode.singleton x)
          (fun rs rl rx rr h =>
            Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
              (fun h =>
                Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl (fun h => node 2 nil x l.dual)
                  (fun size l rlx r h => node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx)) ⋯)
              (fun rrs l x_1 r h =>
                Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                  (fun h => node 3 (Ordnode.singleton x) rx rr)
                  (fun rls rll rlx rlr h =>
                    if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                    else node (rs + 1) (node (rll.size + 1) nil x rll) rlx (node (rlr.size + rrs + 1) rlr rx rr))
                  ⋯)
              ⋯)
          ⋯)
      (fun ls l_1 x_1 r h =>
        Ordnode.casesOn (motive := fun t => id l.dual = t → Ordnode α) (id l.dual)
          (fun h => node (ls + 1) (node rs rl rx rr).dual x nil)
          (fun rs_1 rl_1 rx_1 rr_1 h =>
            if rs_1 > delta * ls then
              Ordnode.casesOn (motive := fun t => id rr_1 = t → Ordnode α) (id rr_1) (fun h => nil)
                (fun rrs l x_2 r h =>
                  Ordnode.casesOn (motive := fun t => id rl_1 = t → Ordnode α) (id rl_1) (fun h => nil)
                    (fun rls rll rlx rlr h =>
                      if rls < ratio * rrs then
                        node (ls + rs_1 + 1) (node (ls + rls + 1) (node rs rl rx rr).dual x rl_1) rx_1 rr_1
                      else
                        node (ls + rs_1 + 1) (node (ls + rll.size + 1) (node rs rl rx rr).dual x rll) rlx
                          (node (rlr.size + rrs + 1) rlr rx_1 rr_1))
                    ⋯)
                ⋯
            else node (ls + rs_1 + 1) (node rs rl rx rr).dual x l.dual)
          ⋯)
      ⋯
tactic: cases' r with rs rl rx rr