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

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

case nil.node
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
⊢ dual
      (Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
        (fun h =>
          (_ : nil = id nil) ▸
            Ordnode.casesOn (motive := fun t => id (node ls ll lx lr) = t → Ordnode α) (id (node ls ll lx lr))
              (fun h => (_ : nil = id (node ls ll lx lr)) ▸ Ordnode.singleton x)
              (fun ls_1 ll_1 lx_1 lr_1 h =>
                (_ : node ls_1 ll_1 lx_1 lr_1 = id (node ls ll lx lr)) ▸
                  Ordnode.casesOn (motive := fun t => id ll_1 = t → Ordnode α) (id ll_1)
                    (fun h =>
                      (_ : nil = id ll_1) ▸
                        Ordnode.casesOn (motive := fun t => lr_1 = t → Ordnode α) lr_1
                          (fun h => (_ : nil = lr_1) ▸ node 2 (node ls ll lx lr) x nil)
                          (fun size l lrx r h =>
                            (_ : node size l lrx r = lr_1) ▸ node 3 (Ordnode.singleton lx_1) lrx (Ordnode.singleton x))
                          (_ : lr_1 = lr_1))
                    (fun lls l x_1 r h =>
                      (_ : node lls l x_1 r = id ll_1) ▸
                        Ordnode.casesOn (motive := fun t => id lr_1 = t → Ordnode α) (id lr_1)
                          (fun h => (_ : nil = id lr_1) ▸ node 3 ll_1 lx_1 (Ordnode.singleton x))
                          (fun lrs lrl lrx lrr h =>
                            (_ : node lrs lrl lrx lrr = id lr_1) ▸
                              if lrs < ratio * lls then node (ls_1 + 1) ll_1 lx_1 (node (lrs + 1) lr_1 x nil)
                              else
                                node (ls_1 + 1) (node (lls + size lrl + 1) ll_1 lx_1 lrl) lrx
                                  (node (size lrr + 1) lrr x nil))
                          (_ : id lr_1 = id lr_1))
                    (_ : id ll_1 = id ll_1))
              (_ : id (node ls ll lx lr) = id (node ls ll lx lr)))
        (fun rs l x_1 r h =>
          (_ : node rs l x_1 r = id nil) ▸
            Ordnode.casesOn (motive := fun t => id (node ls ll lx lr) = t → Ordnode α) (id (node ls ll lx lr))
              (fun h => (_ : nil = id (node ls ll lx lr)) ▸ node (rs + 1) nil x nil)
              (fun ls_1 ll_1 lx_1 lr_1 h =>
                (_ : node ls_1 ll_1 lx_1 lr_1 = id (node ls ll lx lr)) ▸
                  if ls_1 > delta * rs then
                    Ordnode.casesOn (motive := fun t => id ll_1 = t → Ordnode α) (id ll_1)
                      (fun h => (_ : nil = id ll_1) ▸ nil)
                      (fun lls l x_2 r h =>
                        (_ : node lls l x_2 r = id ll_1) ▸
                          Ordnode.casesOn (motive := fun t => id lr_1 = t → Ordnode α) (id lr_1)
                            (fun h => (_ : nil = id lr_1) ▸ nil)
                            (fun lrs lrl lrx lrr h =>
                              (_ : node lrs lrl lrx lrr = id lr_1) ▸
                                if lrs < ratio * lls then
                                  node (ls_1 + rs + 1) ll_1 lx_1 (node (rs + lrs + 1) lr_1 x nil)
                                else
                                  node (ls_1 + rs + 1) (node (lls + size lrl + 1) ll_1 lx_1 lrl) lrx
                                    (node (size lrr + rs + 1) lrr x nil))
                            (_ : id lr_1 = id lr_1))
                      (_ : id ll_1 = id ll_1)
                  else node (ls_1 + rs + 1) (node ls ll lx lr) x nil)
              (_ : id (node ls ll lx lr) = id (node ls ll lx lr)))
        (_ : id nil = id nil)) =
    Ordnode.casesOn (motive := fun t => id (dual nil) = t → Ordnode α) (id (dual nil))
      (fun h =>
        (_ : nil = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual (node ls ll lx lr)) = t → Ordnode α)
            (id (dual (node ls ll lx lr))) (fun h => (_ : nil = id (dual (node ls ll lx lr))) ▸ Ordnode.singleton x)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual (node ls ll lx lr))) ▸
                Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
                  (fun h =>
                    (_ : nil = id rr) ▸
                      Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl
                        (fun h => (_ : nil = rl) ▸ node 2 nil x (dual (node ls ll lx lr)))
                        (fun size l rlx r h =>
                          (_ : node size l rlx r = rl) ▸ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx))
                        (_ : rl = rl))
                  (fun rrs l x_1 r h =>
                    (_ : node rrs l x_1 r = id rr) ▸
                      Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                        (fun h => (_ : nil = id rl) ▸ node 3 (Ordnode.singleton x) rx rr)
                        (fun rls rll rlx rlr h =>
                          (_ : node rls rll rlx rlr = id rl) ▸
                            if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                            else
                              node (rs + 1) (node (size rll + 1) nil x rll) rlx (node (size rlr + rrs + 1) rlr rx rr))
                        (_ : id rl = id rl))
                  (_ : id rr = id rr))
            (_ : id (dual (node ls ll lx lr)) = id (dual (node ls ll lx lr))))
      (fun ls_1 l x_1 r h =>
        (_ : node ls_1 l x_1 r = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual (node ls ll lx lr)) = t → Ordnode α)
            (id (dual (node ls ll lx lr)))
            (fun h => (_ : nil = id (dual (node ls ll lx lr))) ▸ node (ls_1 + 1) (dual nil) x nil)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual (node ls ll lx lr))) ▸
                if rs > delta * ls_1 then
                  Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr) (fun h => (_ : nil = id rr) ▸ nil)
                    (fun rrs l x_2 r h =>
                      (_ : node rrs l x_2 r = id rr) ▸
                        Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                          (fun h => (_ : nil = id rl) ▸ nil)
                          (fun rls rll rlx rlr h =>
                            (_ : node rls rll rlx rlr = id rl) ▸
                              if rls < ratio * rrs then
                                node (ls_1 + rs + 1) (node (ls_1 + rls + 1) (dual nil) x rl) rx rr
                              else
                                node (ls_1 + rs + 1) (node (ls_1 + size rll + 1) (dual nil) x rll) rlx
                                  (node (size rlr + rrs + 1) rlr rx rr))
                          (_ : id rl = id rl))
                    (_ : id rr = id rr)
                else node (ls_1 + rs + 1) (dual nil) x (dual (node ls ll lx lr)))
            (_ : id (dual (node ls ll lx lr)) = id (dual (node ls ll lx lr))))
      (_ : id (dual nil) = id (dual nil))
case nil
α : Type u_1
l : Ordnode α
x : α
⊢ dual
      (Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
        (fun h =>
          (_ : nil = id nil) ▸
            Ordnode.casesOn (motive := fun t => id l = t → Ordnode α) (id l)
              (fun h => (_ : nil = id l) ▸ Ordnode.singleton x)
              (fun ls ll lx lr h =>
                (_ : node ls ll lx lr = id l) ▸
                  Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                    (fun h =>
                      (_ : nil = id ll) ▸
                        Ordnode.casesOn (motive := fun t => lr = t → Ordnode α) lr
                          (fun h => (_ : nil = lr) ▸ node 2 l x nil)
                          (fun size l lrx r h =>
                            (_ : node size l lrx r = lr) ▸ node 3 (Ordnode.singleton lx) lrx (Ordnode.singleton x))
                          (_ : lr = lr))
                    (fun lls l x_1 r h =>
                      (_ : node lls l x_1 r = id ll) ▸
                        Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                          (fun h => (_ : nil = id lr) ▸ node 3 ll lx (Ordnode.singleton x))
                          (fun lrs lrl lrx lrr h =>
                            (_ : node lrs lrl lrx lrr = id lr) ▸
                              if lrs < ratio * lls then node (ls + 1) ll lx (node (lrs + 1) lr x nil)
                              else
                                node (ls + 1) (node (lls + size lrl + 1) ll lx lrl) lrx (node (size lrr + 1) lrr x nil))
                          (_ : id lr = id lr))
                    (_ : id ll = id ll))
              (_ : id l = id l))
        (fun rs l_1 x_1 r h =>
          (_ : node rs l_1 x_1 r = id nil) ▸
            Ordnode.casesOn (motive := fun t => id l = t → Ordnode α) (id l)
              (fun h => (_ : nil = id l) ▸ node (rs + 1) nil x nil)
              (fun ls ll lx lr h =>
                (_ : node ls ll lx lr = id l) ▸
                  if ls > delta * rs then
                    Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                      (fun h => (_ : nil = id ll) ▸ nil)
                      (fun lls l x_2 r h =>
                        (_ : node lls l x_2 r = id ll) ▸
                          Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                            (fun h => (_ : nil = id lr) ▸ nil)
                            (fun lrs lrl lrx lrr h =>
                              (_ : node lrs lrl lrx lrr = id lr) ▸
                                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 + size lrl + 1) ll lx lrl) lrx
                                    (node (size lrr + rs + 1) lrr x nil))
                            (_ : id lr = id lr))
                      (_ : id ll = id ll)
                  else node (ls + rs + 1) l x nil)
              (_ : id l = id l))
        (_ : id nil = id nil)) =
    Ordnode.casesOn (motive := fun t => id (dual nil) = t → Ordnode α) (id (dual nil))
      (fun h =>
        (_ : nil = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual l) = t → Ordnode α) (id (dual l))
            (fun h => (_ : nil = id (dual l)) ▸ Ordnode.singleton x)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual l)) ▸
                Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
                  (fun h =>
                    (_ : nil = id rr) ▸
                      Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl
                        (fun h => (_ : nil = rl) ▸ node 2 nil x (dual l))
                        (fun size l rlx r h =>
                          (_ : node size l rlx r = rl) ▸ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx))
                        (_ : rl = rl))
                  (fun rrs l x_1 r h =>
                    (_ : node rrs l x_1 r = id rr) ▸
                      Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                        (fun h => (_ : nil = id rl) ▸ node 3 (Ordnode.singleton x) rx rr)
                        (fun rls rll rlx rlr h =>
                          (_ : node rls rll rlx rlr = id rl) ▸
                            if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                            else
                              node (rs + 1) (node (size rll + 1) nil x rll) rlx (node (size rlr + rrs + 1) rlr rx rr))
                        (_ : id rl = id rl))
                  (_ : id rr = id rr))
            (_ : id (dual l) = id (dual l)))
      (fun ls l_1 x_1 r h =>
        (_ : node ls l_1 x_1 r = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual l) = t → Ordnode α) (id (dual l))
            (fun h => (_ : nil = id (dual l)) ▸ node (ls + 1) (dual nil) x nil)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual l)) ▸
                if rs > delta * ls then
                  Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr) (fun h => (_ : nil = id rr) ▸ nil)
                    (fun rrs l x_2 r h =>
                      (_ : node rrs l x_2 r = id rr) ▸
                        Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                          (fun h => (_ : nil = id rl) ▸ nil)
                          (fun rls rll rlx rlr h =>
                            (_ : node rls rll rlx rlr = id rl) ▸
                              if rls < ratio * rrs then node (ls + rs + 1) (node (ls + rls + 1) (dual nil) x rl) rx rr
                              else
                                node (ls + rs + 1) (node (ls + size rll + 1) (dual nil) x rll) rlx
                                  (node (size rlr + rrs + 1) rlr rx rr))
                          (_ : id rl = id rl))
                    (_ : id rr = id rr)
                else node (ls + rs + 1) (dual nil) x (dual l))
            (_ : id (dual l) = id (dual l)))
      (_ : id (dual nil) = id (dual nil))
cases' l with ls ll lx lr
case nil.node.node.node
α : Type u_1
x : α
ls : ℕ
lx : α
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
⊢ dual
      (if lrs < ratio * lls then node (ls + 1) (node lls lll llx llr) lx (node (lrs + 1) (node lrs lrl lrx lrr) x nil)
      else
        node (ls + 1) (node (lls + size lrl + 1) (node lls lll llx llr) lx lrl) lrx (node (size lrr + 1) lrr x nil)) =
    if lrs < ratio * lls then
      node (ls + 1) (node (lrs + 1) nil x (node lrs (dual lrr) lrx (dual lrl))) lx (node lls (dual llr) llx (dual lll))
    else
      node (ls + 1) (node (size (dual lrr) + 1) nil x (dual lrr)) lrx
        (node (size (dual lrl) + lls + 1) (dual lrl) lx (node lls (dual llr) llx (dual lll)))
case nil.node
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
⊢ dual
      (Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
        (fun h =>
          (_ : nil = id nil) ▸
            Ordnode.casesOn (motive := fun t => id (node ls ll lx lr) = t → Ordnode α) (id (node ls ll lx lr))
              (fun h => (_ : nil = id (node ls ll lx lr)) ▸ Ordnode.singleton x)
              (fun ls_1 ll_1 lx_1 lr_1 h =>
                (_ : node ls_1 ll_1 lx_1 lr_1 = id (node ls ll lx lr)) ▸
                  Ordnode.casesOn (motive := fun t => id ll_1 = t → Ordnode α) (id ll_1)
                    (fun h =>
                      (_ : nil = id ll_1) ▸
                        Ordnode.casesOn (motive := fun t => lr_1 = t → Ordnode α) lr_1
                          (fun h => (_ : nil = lr_1) ▸ node 2 (node ls ll lx lr) x nil)
                          (fun size l lrx r h =>
                            (_ : node size l lrx r = lr_1) ▸ node 3 (Ordnode.singleton lx_1) lrx (Ordnode.singleton x))
                          (_ : lr_1 = lr_1))
                    (fun lls l x_1 r h =>
                      (_ : node lls l x_1 r = id ll_1) ▸
                        Ordnode.casesOn (motive := fun t => id lr_1 = t → Ordnode α) (id lr_1)
                          (fun h => (_ : nil = id lr_1) ▸ node 3 ll_1 lx_1 (Ordnode.singleton x))
                          (fun lrs lrl lrx lrr h =>
                            (_ : node lrs lrl lrx lrr = id lr_1) ▸
                              if lrs < ratio * lls then node (ls_1 + 1) ll_1 lx_1 (node (lrs + 1) lr_1 x nil)
                              else
                                node (ls_1 + 1) (node (lls + size lrl + 1) ll_1 lx_1 lrl) lrx
                                  (node (size lrr + 1) lrr x nil))
                          (_ : id lr_1 = id lr_1))
                    (_ : id ll_1 = id ll_1))
              (_ : id (node ls ll lx lr) = id (node ls ll lx lr)))
        (fun rs l x_1 r h =>
          (_ : node rs l x_1 r = id nil) ▸
            Ordnode.casesOn (motive := fun t => id (node ls ll lx lr) = t → Ordnode α) (id (node ls ll lx lr))
              (fun h => (_ : nil = id (node ls ll lx lr)) ▸ node (rs + 1) nil x nil)
              (fun ls_1 ll_1 lx_1 lr_1 h =>
                (_ : node ls_1 ll_1 lx_1 lr_1 = id (node ls ll lx lr)) ▸
                  if ls_1 > delta * rs then
                    Ordnode.casesOn (motive := fun t => id ll_1 = t → Ordnode α) (id ll_1)
                      (fun h => (_ : nil = id ll_1) ▸ nil)
                      (fun lls l x_2 r h =>
                        (_ : node lls l x_2 r = id ll_1) ▸
                          Ordnode.casesOn (motive := fun t => id lr_1 = t → Ordnode α) (id lr_1)
                            (fun h => (_ : nil = id lr_1) ▸ nil)
                            (fun lrs lrl lrx lrr h =>
                              (_ : node lrs lrl lrx lrr = id lr_1) ▸
                                if lrs < ratio * lls then
                                  node (ls_1 + rs + 1) ll_1 lx_1 (node (rs + lrs + 1) lr_1 x nil)
                                else
                                  node (ls_1 + rs + 1) (node (lls + size lrl + 1) ll_1 lx_1 lrl) lrx
                                    (node (size lrr + rs + 1) lrr x nil))
                            (_ : id lr_1 = id lr_1))
                      (_ : id ll_1 = id ll_1)
                  else node (ls_1 + rs + 1) (node ls ll lx lr) x nil)
              (_ : id (node ls ll lx lr) = id (node ls ll lx lr)))
        (_ : id nil = id nil)) =
    Ordnode.casesOn (motive := fun t => id (dual nil) = t → Ordnode α) (id (dual nil))
      (fun h =>
        (_ : nil = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual (node ls ll lx lr)) = t → Ordnode α)
            (id (dual (node ls ll lx lr))) (fun h => (_ : nil = id (dual (node ls ll lx lr))) ▸ Ordnode.singleton x)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual (node ls ll lx lr))) ▸
                Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
                  (fun h =>
                    (_ : nil = id rr) ▸
                      Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl
                        (fun h => (_ : nil = rl) ▸ node 2 nil x (dual (node ls ll lx lr)))
                        (fun size l rlx r h =>
                          (_ : node size l rlx r = rl) ▸ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx))
                        (_ : rl = rl))
                  (fun rrs l x_1 r h =>
                    (_ : node rrs l x_1 r = id rr) ▸
                      Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                        (fun h => (_ : nil = id rl) ▸ node 3 (Ordnode.singleton x) rx rr)
                        (fun rls rll rlx rlr h =>
                          (_ : node rls rll rlx rlr = id rl) ▸
                            if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                            else
                              node (rs + 1) (node (size rll + 1) nil x rll) rlx (node (size rlr + rrs + 1) rlr rx rr))
                        (_ : id rl = id rl))
                  (_ : id rr = id rr))
            (_ : id (dual (node ls ll lx lr)) = id (dual (node ls ll lx lr))))
      (fun ls_1 l x_1 r h =>
        (_ : node ls_1 l x_1 r = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual (node ls ll lx lr)) = t → Ordnode α)
            (id (dual (node ls ll lx lr)))
            (fun h => (_ : nil = id (dual (node ls ll lx lr))) ▸ node (ls_1 + 1) (dual nil) x nil)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual (node ls ll lx lr))) ▸
                if rs > delta * ls_1 then
                  Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr) (fun h => (_ : nil = id rr) ▸ nil)
                    (fun rrs l x_2 r h =>
                      (_ : node rrs l x_2 r = id rr) ▸
                        Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                          (fun h => (_ : nil = id rl) ▸ nil)
                          (fun rls rll rlx rlr h =>
                            (_ : node rls rll rlx rlr = id rl) ▸
                              if rls < ratio * rrs then
                                node (ls_1 + rs + 1) (node (ls_1 + rls + 1) (dual nil) x rl) rx rr
                              else
                                node (ls_1 + rs + 1) (node (ls_1 + size rll + 1) (dual nil) x rll) rlx
                                  (node (size rlr + rrs + 1) rlr rx rr))
                          (_ : id rl = id rl))
                    (_ : id rr = id rr)
                else node (ls_1 + rs + 1) (dual nil) x (dual (node ls ll lx lr)))
            (_ : id (dual (node ls ll lx lr)) = id (dual (node ls ll lx lr))))
      (_ : id (dual nil) = id (dual nil))
cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp only [dual, id] <;>
  try rfl
no goals
case nil.node.node.node
α : Type u_1
x : α
ls : ℕ
lx : α
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
⊢ dual
      (if lrs < ratio * lls then node (ls + 1) (node lls lll llx llr) lx (node (lrs + 1) (node lrs lrl lrx lrr) x nil)
      else
        node (ls + 1) (node (lls + size lrl + 1) (node lls lll llx llr) lx lrl) lrx (node (size lrr + 1) lrr x nil)) =
    if lrs < ratio * lls then
      node (ls + 1) (node (lrs + 1) nil x (node lrs (dual lrr) lrx (dual lrl))) lx (node lls (dual llr) llx (dual lll))
    else
      node (ls + 1) (node (size (dual lrr) + 1) nil x (dual lrr)) lrx
        (node (size (dual lrl) + lls + 1) (dual lrl) lx (node lls (dual llr) llx (dual lll)))
split_ifs with h <;> repeat simp [h, add_comm]
no goals
case nil.nil
α : Type u_1
x : α
⊢ dual
      (Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
        (fun h =>
          (_ : nil = id nil) ▸
            Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
              (fun h => (_ : nil = id nil) ▸ Ordnode.singleton x)
              (fun ls ll lx lr h =>
                (_ : node ls ll lx lr = id nil) ▸
                  Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                    (fun h =>
                      (_ : nil = id ll) ▸
                        Ordnode.casesOn (motive := fun t => lr = t → Ordnode α) lr
                          (fun h => (_ : nil = lr) ▸ node 2 nil x nil)
                          (fun size l lrx r h =>
                            (_ : node size l lrx r = lr) ▸ node 3 (Ordnode.singleton lx) lrx (Ordnode.singleton x))
                          (_ : lr = lr))
                    (fun lls l x_1 r h =>
                      (_ : node lls l x_1 r = id ll) ▸
                        Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                          (fun h => (_ : nil = id lr) ▸ node 3 ll lx (Ordnode.singleton x))
                          (fun lrs lrl lrx lrr h =>
                            (_ : node lrs lrl lrx lrr = id lr) ▸
                              if lrs < ratio * lls then node (ls + 1) ll lx (node (lrs + 1) lr x nil)
                              else
                                node (ls + 1) (node (lls + size lrl + 1) ll lx lrl) lrx (node (size lrr + 1) lrr x nil))
                          (_ : id lr = id lr))
                    (_ : id ll = id ll))
              (_ : id nil = id nil))
        (fun rs l x_1 r h =>
          (_ : node rs l x_1 r = id nil) ▸
            Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
              (fun h => (_ : nil = id nil) ▸ node (rs + 1) nil x nil)
              (fun ls ll lx lr h =>
                (_ : node ls ll lx lr = id nil) ▸
                  if ls > delta * rs then
                    Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                      (fun h => (_ : nil = id ll) ▸ nil)
                      (fun lls l x_2 r h =>
                        (_ : node lls l x_2 r = id ll) ▸
                          Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                            (fun h => (_ : nil = id lr) ▸ nil)
                            (fun lrs lrl lrx lrr h =>
                              (_ : node lrs lrl lrx lrr = id lr) ▸
                                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 + size lrl + 1) ll lx lrl) lrx
                                    (node (size lrr + rs + 1) lrr x nil))
                            (_ : id lr = id lr))
                      (_ : id ll = id ll)
                  else node (ls + rs + 1) nil x nil)
              (_ : id nil = id nil))
        (_ : id nil = id nil)) =
    Ordnode.casesOn (motive := fun t => id (dual nil) = t → Ordnode α) (id (dual nil))
      (fun h =>
        (_ : nil = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual nil) = t → Ordnode α) (id (dual nil))
            (fun h => (_ : nil = id (dual nil)) ▸ Ordnode.singleton x)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual nil)) ▸
                Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
                  (fun h =>
                    (_ : nil = id rr) ▸
                      Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl
                        (fun h => (_ : nil = rl) ▸ node 2 nil x (dual nil))
                        (fun size l rlx r h =>
                          (_ : node size l rlx r = rl) ▸ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx))
                        (_ : rl = rl))
                  (fun rrs l x_1 r h =>
                    (_ : node rrs l x_1 r = id rr) ▸
                      Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                        (fun h => (_ : nil = id rl) ▸ node 3 (Ordnode.singleton x) rx rr)
                        (fun rls rll rlx rlr h =>
                          (_ : node rls rll rlx rlr = id rl) ▸
                            if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                            else
                              node (rs + 1) (node (size rll + 1) nil x rll) rlx (node (size rlr + rrs + 1) rlr rx rr))
                        (_ : id rl = id rl))
                  (_ : id rr = id rr))
            (_ : id (dual nil) = id (dual nil)))
      (fun ls l x_1 r h =>
        (_ : node ls l x_1 r = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual nil) = t → Ordnode α) (id (dual nil))
            (fun h => (_ : nil = id (dual nil)) ▸ node (ls + 1) (dual nil) x nil)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual nil)) ▸
                if rs > delta * ls then
                  Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr) (fun h => (_ : nil = id rr) ▸ nil)
                    (fun rrs l x_2 r h =>
                      (_ : node rrs l x_2 r = id rr) ▸
                        Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                          (fun h => (_ : nil = id rl) ▸ nil)
                          (fun rls rll rlx rlr h =>
                            (_ : node rls rll rlx rlr = id rl) ▸
                              if rls < ratio * rrs then node (ls + rs + 1) (node (ls + rls + 1) (dual nil) x rl) rx rr
                              else
                                node (ls + rs + 1) (node (ls + size rll + 1) (dual nil) x rll) rlx
                                  (node (size rlr + rrs + 1) rlr rx rr))
                          (_ : id rl = id rl))
                    (_ : id rr = id rr)
                else node (ls + rs + 1) (dual nil) x (dual nil))
            (_ : id (dual nil) = id (dual nil)))
      (_ : id (dual nil) = id (dual nil))
rfl
case nil.node.node.node
α : Type u_1
x : α
ls : ℕ
lx : α
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
⊢ dual
      (if lrs < ratio * lls then node (ls + 1) (node lls lll llx llr) lx (node (lrs + 1) (node lrs lrl lrx lrr) x nil)
      else
        node (ls + 1) (node (lls + size lrl + 1) (node lls lll llx llr) lx lrl) lrx (node (size lrr + 1) lrr x nil)) =
    if lrs < ratio * lls then
      node (ls + 1) (node (lrs + 1) nil x (node lrs (dual lrr) lrx (dual lrl))) lx (node lls (dual llr) llx (dual lll))
    else
      node (ls + 1) (node (size (dual lrr) + 1) nil x (dual lrr)) lrx
        (node (size (dual lrl) + lls + 1) (dual lrl) lx (node lls (dual llr) llx (dual lll)))
case nil.node.node.node
α : Type u_1
x : α
ls : ℕ
lx : α
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
⊢ dual
      (if lrs < ratio * lls then node (ls + 1) (node lls lll llx llr) lx (node (lrs + 1) (node lrs lrl lrx lrr) x nil)
      else
        node (ls + 1) (node (lls + size lrl + 1) (node lls lll llx llr) lx lrl) lrx (node (size lrr + 1) lrr x nil)) =
    if lrs < ratio * lls then
      node (ls + 1) (node (lrs + 1) nil x (node lrs (dual lrr) lrx (dual lrl))) lx (node lls (dual llr) llx (dual lll))
    else
      node (ls + 1) (node (size (dual lrr) + 1) nil x (dual lrr)) lrx
        (node (size (dual lrl) + lls + 1) (dual lrl) lx (node lls (dual llr) llx (dual lll)))
rfl
case node.nil
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
⊢ dual
      (Ordnode.casesOn (motive := fun t => id (node rs rl rx rr) = t → Ordnode α) (id (node rs rl rx rr))
        (fun h =>
          (_ : nil = id (node rs rl rx rr)) ▸
            Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
              (fun h => (_ : nil = id nil) ▸ Ordnode.singleton x)
              (fun ls ll lx lr h =>
                (_ : node ls ll lx lr = id nil) ▸
                  Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                    (fun h =>
                      (_ : nil = id ll) ▸
                        Ordnode.casesOn (motive := fun t => lr = t → Ordnode α) lr
                          (fun h => (_ : nil = lr) ▸ node 2 nil x nil)
                          (fun size l lrx r h =>
                            (_ : node size l lrx r = lr) ▸ node 3 (Ordnode.singleton lx) lrx (Ordnode.singleton x))
                          (_ : lr = lr))
                    (fun lls l x_1 r h =>
                      (_ : node lls l x_1 r = id ll) ▸
                        Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                          (fun h => (_ : nil = id lr) ▸ node 3 ll lx (Ordnode.singleton x))
                          (fun lrs lrl lrx lrr h =>
                            (_ : node lrs lrl lrx lrr = id lr) ▸
                              if lrs < ratio * lls then node (ls + 1) ll lx (node (lrs + 1) lr x nil)
                              else
                                node (ls + 1) (node (lls + size lrl + 1) ll lx lrl) lrx (node (size lrr + 1) lrr x nil))
                          (_ : id lr = id lr))
                    (_ : id ll = id ll))
              (_ : id nil = id nil))
        (fun rs_1 l x_1 r h =>
          (_ : node rs_1 l x_1 r = id (node rs rl rx rr)) ▸
            Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
              (fun h => (_ : nil = id nil) ▸ node (rs_1 + 1) nil x (node rs rl rx rr))
              (fun ls ll lx lr h =>
                (_ : node ls ll lx lr = id nil) ▸
                  if ls > delta * rs_1 then
                    Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                      (fun h => (_ : nil = id ll) ▸ nil)
                      (fun lls l x_2 r h =>
                        (_ : node lls l x_2 r = id ll) ▸
                          Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                            (fun h => (_ : nil = id lr) ▸ nil)
                            (fun lrs lrl lrx lrr h =>
                              (_ : node lrs lrl lrx lrr = id lr) ▸
                                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 + size lrl + 1) ll lx lrl) lrx
                                    (node (size lrr + rs_1 + 1) lrr x (node rs rl rx rr)))
                            (_ : id lr = id lr))
                      (_ : id ll = id ll)
                  else node (ls + rs_1 + 1) nil x (node rs rl rx rr))
              (_ : id nil = id nil))
        (_ : id (node rs rl rx rr) = id (node rs rl rx rr))) =
    Ordnode.casesOn (motive := fun t => id (dual (node rs rl rx rr)) = t → Ordnode α) (id (dual (node rs rl rx rr)))
      (fun h =>
        (_ : nil = id (dual (node rs rl rx rr))) ▸
          Ordnode.casesOn (motive := fun t => id (dual nil) = t → Ordnode α) (id (dual nil))
            (fun h => (_ : nil = id (dual nil)) ▸ Ordnode.singleton x)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual nil)) ▸
                Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
                  (fun h =>
                    (_ : nil = id rr) ▸
                      Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl
                        (fun h => (_ : nil = rl) ▸ node 2 nil x (dual nil))
                        (fun size l rlx r h =>
                          (_ : node size l rlx r = rl) ▸ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx))
                        (_ : rl = rl))
                  (fun rrs l x_1 r h =>
                    (_ : node rrs l x_1 r = id rr) ▸
                      Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                        (fun h => (_ : nil = id rl) ▸ node 3 (Ordnode.singleton x) rx rr)
                        (fun rls rll rlx rlr h =>
                          (_ : node rls rll rlx rlr = id rl) ▸
                            if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                            else
                              node (rs + 1) (node (size rll + 1) nil x rll) rlx (node (size rlr + rrs + 1) rlr rx rr))
                        (_ : id rl = id rl))
                  (_ : id rr = id rr))
            (_ : id (dual nil) = id (dual nil)))
      (fun ls l x_1 r h =>
        (_ : node ls l x_1 r = id (dual (node rs rl rx rr))) ▸
          Ordnode.casesOn (motive := fun t => id (dual nil) = t → Ordnode α) (id (dual nil))
            (fun h => (_ : nil = id (dual nil)) ▸ node (ls + 1) (dual (node rs rl rx rr)) x nil)
            (fun rs_1 rl_1 rx_1 rr_1 h =>
              (_ : node rs_1 rl_1 rx_1 rr_1 = id (dual nil)) ▸
                if rs_1 > delta * ls then
                  Ordnode.casesOn (motive := fun t => id rr_1 = t → Ordnode α) (id rr_1)
                    (fun h => (_ : nil = id rr_1) ▸ nil)
                    (fun rrs l x_2 r h =>
                      (_ : node rrs l x_2 r = id rr_1) ▸
                        Ordnode.casesOn (motive := fun t => id rl_1 = t → Ordnode α) (id rl_1)
                          (fun h => (_ : nil = id rl_1) ▸ nil)
                          (fun rls rll rlx rlr h =>
                            (_ : node rls rll rlx rlr = id rl_1) ▸
                              if rls < ratio * rrs then
                                node (ls + rs_1 + 1) (node (ls + rls + 1) (dual (node rs rl rx rr)) x rl_1) rx_1 rr_1
                              else
                                node (ls + rs_1 + 1) (node (ls + size rll + 1) (dual (node rs rl rx rr)) x rll) rlx
                                  (node (size rlr + rrs + 1) rlr rx_1 rr_1))
                          (_ : id rl_1 = id rl_1))
                    (_ : id rr_1 = id rr_1)
                else node (ls + rs_1 + 1) (dual (node rs rl rx rr)) x (dual nil))
            (_ : id (dual nil) = id (dual nil)))
      (_ : id (dual (node rs rl rx rr)) = id (dual (node rs rl rx rr)))

case node.node
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
⊢ dual
      (Ordnode.casesOn (motive := fun t => id (node rs rl rx rr) = t → Ordnode α) (id (node rs rl rx rr))
        (fun h =>
          (_ : nil = id (node rs rl rx rr)) ▸
            Ordnode.casesOn (motive := fun t => id (node ls ll lx lr) = t → Ordnode α) (id (node ls ll lx lr))
              (fun h => (_ : nil = id (node ls ll lx lr)) ▸ Ordnode.singleton x)
              (fun ls_1 ll_1 lx_1 lr_1 h =>
                (_ : node ls_1 ll_1 lx_1 lr_1 = id (node ls ll lx lr)) ▸
                  Ordnode.casesOn (motive := fun t => id ll_1 = t → Ordnode α) (id ll_1)
                    (fun h =>
                      (_ : nil = id ll_1) ▸
                        Ordnode.casesOn (motive := fun t => lr_1 = t → Ordnode α) lr_1
                          (fun h => (_ : nil = lr_1) ▸ node 2 (node ls ll lx lr) x nil)
                          (fun size l lrx r h =>
                            (_ : node size l lrx r = lr_1) ▸ node 3 (Ordnode.singleton lx_1) lrx (Ordnode.singleton x))
                          (_ : lr_1 = lr_1))
                    (fun lls l x_1 r h =>
                      (_ : node lls l x_1 r = id ll_1) ▸
                        Ordnode.casesOn (motive := fun t => id lr_1 = t → Ordnode α) (id lr_1)
                          (fun h => (_ : nil = id lr_1) ▸ node 3 ll_1 lx_1 (Ordnode.singleton x))
                          (fun lrs lrl lrx lrr h =>
                            (_ : node lrs lrl lrx lrr = id lr_1) ▸
                              if lrs < ratio * lls then node (ls_1 + 1) ll_1 lx_1 (node (lrs + 1) lr_1 x nil)
                              else
                                node (ls_1 + 1) (node (lls + size lrl + 1) ll_1 lx_1 lrl) lrx
                                  (node (size lrr + 1) lrr x nil))
                          (_ : id lr_1 = id lr_1))
                    (_ : id ll_1 = id ll_1))
              (_ : id (node ls ll lx lr) = id (node ls ll lx lr)))
        (fun rs_1 l x_1 r h =>
          (_ : node rs_1 l x_1 r = id (node rs rl rx rr)) ▸
            Ordnode.casesOn (motive := fun t => id (node ls ll lx lr) = t → Ordnode α) (id (node ls ll lx lr))
              (fun h => (_ : nil = id (node ls ll lx lr)) ▸ node (rs_1 + 1) nil x (node rs rl rx rr))
              (fun ls_1 ll_1 lx_1 lr_1 h =>
                (_ : node ls_1 ll_1 lx_1 lr_1 = id (node ls ll lx lr)) ▸
                  if ls_1 > delta * rs_1 then
                    Ordnode.casesOn (motive := fun t => id ll_1 = t → Ordnode α) (id ll_1)
                      (fun h => (_ : nil = id ll_1) ▸ nil)
                      (fun lls l x_2 r h =>
                        (_ : node lls l x_2 r = id ll_1) ▸
                          Ordnode.casesOn (motive := fun t => id lr_1 = t → Ordnode α) (id lr_1)
                            (fun h => (_ : nil = id lr_1) ▸ nil)
                            (fun lrs lrl lrx lrr h =>
                              (_ : node lrs lrl lrx lrr = id lr_1) ▸
                                if lrs < ratio * lls then
                                  node (ls_1 + rs_1 + 1) ll_1 lx_1 (node (rs_1 + lrs + 1) lr_1 x (node rs rl rx rr))
                                else
                                  node (ls_1 + rs_1 + 1) (node (lls + size lrl + 1) ll_1 lx_1 lrl) lrx
                                    (node (size lrr + rs_1 + 1) lrr x (node rs rl rx rr)))
                            (_ : id lr_1 = id lr_1))
                      (_ : id ll_1 = id ll_1)
                  else node (ls_1 + rs_1 + 1) (node ls ll lx lr) x (node rs rl rx rr))
              (_ : id (node ls ll lx lr) = id (node ls ll lx lr)))
        (_ : id (node rs rl rx rr) = id (node rs rl rx rr))) =
    Ordnode.casesOn (motive := fun t => id (dual (node rs rl rx rr)) = t → Ordnode α) (id (dual (node rs rl rx rr)))
      (fun h =>
        (_ : nil = id (dual (node rs rl rx rr))) ▸
          Ordnode.casesOn (motive := fun t => id (dual (node ls ll lx lr)) = t → Ordnode α)
            (id (dual (node ls ll lx lr))) (fun h => (_ : nil = id (dual (node ls ll lx lr))) ▸ Ordnode.singleton x)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual (node ls ll lx lr))) ▸
                Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
                  (fun h =>
                    (_ : nil = id rr) ▸
                      Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl
                        (fun h => (_ : nil = rl) ▸ node 2 nil x (dual (node ls ll lx lr)))
                        (fun size l rlx r h =>
                          (_ : node size l rlx r = rl) ▸ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx))
                        (_ : rl = rl))
                  (fun rrs l x_1 r h =>
                    (_ : node rrs l x_1 r = id rr) ▸
                      Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                        (fun h => (_ : nil = id rl) ▸ node 3 (Ordnode.singleton x) rx rr)
                        (fun rls rll rlx rlr h =>
                          (_ : node rls rll rlx rlr = id rl) ▸
                            if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                            else
                              node (rs + 1) (node (size rll + 1) nil x rll) rlx (node (size rlr + rrs + 1) rlr rx rr))
                        (_ : id rl = id rl))
                  (_ : id rr = id rr))
            (_ : id (dual (node ls ll lx lr)) = id (dual (node ls ll lx lr))))
      (fun ls_1 l x_1 r h =>
        (_ : node ls_1 l x_1 r = id (dual (node rs rl rx rr))) ▸
          Ordnode.casesOn (motive := fun t => id (dual (node ls ll lx lr)) = t → Ordnode α)
            (id (dual (node ls ll lx lr)))
            (fun h => (_ : nil = id (dual (node ls ll lx lr))) ▸ node (ls_1 + 1) (dual (node rs rl rx rr)) x nil)
            (fun rs_1 rl_1 rx_1 rr_1 h =>
              (_ : node rs_1 rl_1 rx_1 rr_1 = id (dual (node ls ll lx lr))) ▸
                if rs_1 > delta * ls_1 then
                  Ordnode.casesOn (motive := fun t => id rr_1 = t → Ordnode α) (id rr_1)
                    (fun h => (_ : nil = id rr_1) ▸ nil)
                    (fun rrs l x_2 r h =>
                      (_ : node rrs l x_2 r = id rr_1) ▸
                        Ordnode.casesOn (motive := fun t => id rl_1 = t → Ordnode α) (id rl_1)
                          (fun h => (_ : nil = id rl_1) ▸ nil)
                          (fun rls rll rlx rlr h =>
                            (_ : node rls rll rlx rlr = id rl_1) ▸
                              if rls < ratio * rrs then
                                node (ls_1 + rs_1 + 1) (node (ls_1 + rls + 1) (dual (node rs rl rx rr)) x rl_1) rx_1
                                  rr_1
                              else
                                node (ls_1 + rs_1 + 1) (node (ls_1 + size rll + 1) (dual (node rs rl rx rr)) x rll) rlx
                                  (node (size rlr + rrs + 1) rlr rx_1 rr_1))
                          (_ : id rl_1 = id rl_1))
                    (_ : id rr_1 = id rr_1)
                else node (ls_1 + rs_1 + 1) (dual (node rs rl rx rr)) x (dual (node ls ll lx lr)))
            (_ : id (dual (node ls ll lx lr)) = id (dual (node ls ll lx lr))))
      (_ : id (dual (node rs rl rx rr)) = id (dual (node rs rl rx rr)))
case node
α : Type u_1
l : Ordnode α
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
⊢ dual
      (Ordnode.casesOn (motive := fun t => id (node rs rl rx rr) = t → Ordnode α) (id (node rs rl rx rr))
        (fun h =>
          (_ : nil = id (node rs rl rx rr)) ▸
            Ordnode.casesOn (motive := fun t => id l = t → Ordnode α) (id l)
              (fun h => (_ : nil = id l) ▸ Ordnode.singleton x)
              (fun ls ll lx lr h =>
                (_ : node ls ll lx lr = id l) ▸
                  Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                    (fun h =>
                      (_ : nil = id ll) ▸
                        Ordnode.casesOn (motive := fun t => lr = t → Ordnode α) lr
                          (fun h => (_ : nil = lr) ▸ node 2 l x nil)
                          (fun size l lrx r h =>
                            (_ : node size l lrx r = lr) ▸ node 3 (Ordnode.singleton lx) lrx (Ordnode.singleton x))
                          (_ : lr = lr))
                    (fun lls l x_1 r h =>
                      (_ : node lls l x_1 r = id ll) ▸
                        Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                          (fun h => (_ : nil = id lr) ▸ node 3 ll lx (Ordnode.singleton x))
                          (fun lrs lrl lrx lrr h =>
                            (_ : node lrs lrl lrx lrr = id lr) ▸
                              if lrs < ratio * lls then node (ls + 1) ll lx (node (lrs + 1) lr x nil)
                              else
                                node (ls + 1) (node (lls + size lrl + 1) ll lx lrl) lrx (node (size lrr + 1) lrr x nil))
                          (_ : id lr = id lr))
                    (_ : id ll = id ll))
              (_ : id l = id l))
        (fun rs_1 l_1 x_1 r h =>
          (_ : node rs_1 l_1 x_1 r = id (node rs rl rx rr)) ▸
            Ordnode.casesOn (motive := fun t => id l = t → Ordnode α) (id l)
              (fun h => (_ : nil = id l) ▸ node (rs_1 + 1) nil x (node rs rl rx rr))
              (fun ls ll lx lr h =>
                (_ : node ls ll lx lr = id l) ▸
                  if ls > delta * rs_1 then
                    Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                      (fun h => (_ : nil = id ll) ▸ nil)
                      (fun lls l x_2 r h =>
                        (_ : node lls l x_2 r = id ll) ▸
                          Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                            (fun h => (_ : nil = id lr) ▸ nil)
                            (fun lrs lrl lrx lrr h =>
                              (_ : node lrs lrl lrx lrr = id lr) ▸
                                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 + size lrl + 1) ll lx lrl) lrx
                                    (node (size lrr + rs_1 + 1) lrr x (node rs rl rx rr)))
                            (_ : id lr = id lr))
                      (_ : id ll = id ll)
                  else node (ls + rs_1 + 1) l x (node rs rl rx rr))
              (_ : id l = id l))
        (_ : id (node rs rl rx rr) = id (node rs rl rx rr))) =
    Ordnode.casesOn (motive := fun t => id (dual (node rs rl rx rr)) = t → Ordnode α) (id (dual (node rs rl rx rr)))
      (fun h =>
        (_ : nil = id (dual (node rs rl rx rr))) ▸
          Ordnode.casesOn (motive := fun t => id (dual l) = t → Ordnode α) (id (dual l))
            (fun h => (_ : nil = id (dual l)) ▸ Ordnode.singleton x)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual l)) ▸
                Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
                  (fun h =>
                    (_ : nil = id rr) ▸
                      Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl
                        (fun h => (_ : nil = rl) ▸ node 2 nil x (dual l))
                        (fun size l rlx r h =>
                          (_ : node size l rlx r = rl) ▸ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx))
                        (_ : rl = rl))
                  (fun rrs l x_1 r h =>
                    (_ : node rrs l x_1 r = id rr) ▸
                      Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                        (fun h => (_ : nil = id rl) ▸ node 3 (Ordnode.singleton x) rx rr)
                        (fun rls rll rlx rlr h =>
                          (_ : node rls rll rlx rlr = id rl) ▸
                            if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                            else
                              node (rs + 1) (node (size rll + 1) nil x rll) rlx (node (size rlr + rrs + 1) rlr rx rr))
                        (_ : id rl = id rl))
                  (_ : id rr = id rr))
            (_ : id (dual l) = id (dual l)))
      (fun ls l_1 x_1 r h =>
        (_ : node ls l_1 x_1 r = id (dual (node rs rl rx rr))) ▸
          Ordnode.casesOn (motive := fun t => id (dual l) = t → Ordnode α) (id (dual l))
            (fun h => (_ : nil = id (dual l)) ▸ node (ls + 1) (dual (node rs rl rx rr)) x nil)
            (fun rs_1 rl_1 rx_1 rr_1 h =>
              (_ : node rs_1 rl_1 rx_1 rr_1 = id (dual l)) ▸
                if rs_1 > delta * ls then
                  Ordnode.casesOn (motive := fun t => id rr_1 = t → Ordnode α) (id rr_1)
                    (fun h => (_ : nil = id rr_1) ▸ nil)
                    (fun rrs l x_2 r h =>
                      (_ : node rrs l x_2 r = id rr_1) ▸
                        Ordnode.casesOn (motive := fun t => id rl_1 = t → Ordnode α) (id rl_1)
                          (fun h => (_ : nil = id rl_1) ▸ nil)
                          (fun rls rll rlx rlr h =>
                            (_ : node rls rll rlx rlr = id rl_1) ▸
                              if rls < ratio * rrs then
                                node (ls + rs_1 + 1) (node (ls + rls + 1) (dual (node rs rl rx rr)) x rl_1) rx_1 rr_1
                              else
                                node (ls + rs_1 + 1) (node (ls + size rll + 1) (dual (node rs rl rx rr)) x rll) rlx
                                  (node (size rlr + rrs + 1) rlr rx_1 rr_1))
                          (_ : id rl_1 = id rl_1))
                    (_ : id rr_1 = id rr_1)
                else node (ls + rs_1 + 1) (dual (node rs rl rx rr)) x (dual l))
            (_ : id (dual l) = id (dual l)))
      (_ : id (dual (node rs rl rx rr)) = id (dual (node rs rl rx rr)))
cases' l with ls ll lx lr
case node.node
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
⊢ dual
      (if ls > delta * rs then
        rec (motive := fun t => ll = t → Ordnode α) (fun h => (_ : nil = id ll) ▸ nil)
          (fun size l x_1 r l_ih r_ih h =>
            (_ : node size l x_1 r = id ll) ▸
              rec (motive := fun t => lr = t → Ordnode α) (fun h => (_ : nil = id lr) ▸ nil)
                (fun size_1 l x_2 r l_ih r_ih h =>
                  (_ : node size_1 l x_2 r = id lr) ▸
                    if size_1 < ratio * size then
                      node (ls + rs + 1) ll lx (node (rs + size_1 + 1) lr x (node rs rl rx rr))
                    else
                      node (ls + rs + 1) (node (size + Ordnode.size l + 1) ll lx l) x_2
                        (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
                lr (_ : id lr = id lr))
          ll (_ : id ll = id ll)
      else node (ls + rs + 1) (node ls ll lx lr) x (node rs rl rx rr)) =
    if ls > delta * rs then
      rec (motive := fun t => dual ll = t → Ordnode α) (fun h => (_ : nil = id (dual ll)) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id (dual ll)) ▸
            rec (motive := fun t => dual lr = t → Ordnode α) (fun h => (_ : nil = id (dual lr)) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id (dual lr)) ▸
                  if size_1 < ratio * size then
                    node (rs + ls + 1) (node (rs + size_1 + 1) (node rs (dual rr) rx (dual rl)) x (dual lr)) lx
                      (dual ll)
                  else
                    node (rs + ls + 1) (node (rs + Ordnode.size l + 1) (node rs (dual rr) rx (dual rl)) x l) x_2
                      (node (Ordnode.size r + size + 1) r lx (dual ll)))
              (dual lr) (_ : id (dual lr) = id (dual lr)))
        (dual ll) (_ : id (dual ll) = id (dual ll))
    else node (rs + ls + 1) (node rs (dual rr) rx (dual rl)) x (node ls (dual lr) lx (dual ll))
case node.node
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
⊢ dual
      (Ordnode.casesOn (motive := fun t => id (node rs rl rx rr) = t → Ordnode α) (id (node rs rl rx rr))
        (fun h =>
          (_ : nil = id (node rs rl rx rr)) ▸
            Ordnode.casesOn (motive := fun t => id (node ls ll lx lr) = t → Ordnode α) (id (node ls ll lx lr))
              (fun h => (_ : nil = id (node ls ll lx lr)) ▸ Ordnode.singleton x)
              (fun ls_1 ll_1 lx_1 lr_1 h =>
                (_ : node ls_1 ll_1 lx_1 lr_1 = id (node ls ll lx lr)) ▸
                  Ordnode.casesOn (motive := fun t => id ll_1 = t → Ordnode α) (id ll_1)
                    (fun h =>
                      (_ : nil = id ll_1) ▸
                        Ordnode.casesOn (motive := fun t => lr_1 = t → Ordnode α) lr_1
                          (fun h => (_ : nil = lr_1) ▸ node 2 (node ls ll lx lr) x nil)
                          (fun size l lrx r h =>
                            (_ : node size l lrx r = lr_1) ▸ node 3 (Ordnode.singleton lx_1) lrx (Ordnode.singleton x))
                          (_ : lr_1 = lr_1))
                    (fun lls l x_1 r h =>
                      (_ : node lls l x_1 r = id ll_1) ▸
                        Ordnode.casesOn (motive := fun t => id lr_1 = t → Ordnode α) (id lr_1)
                          (fun h => (_ : nil = id lr_1) ▸ node 3 ll_1 lx_1 (Ordnode.singleton x))
                          (fun lrs lrl lrx lrr h =>
                            (_ : node lrs lrl lrx lrr = id lr_1) ▸
                              if lrs < ratio * lls then node (ls_1 + 1) ll_1 lx_1 (node (lrs + 1) lr_1 x nil)
                              else
                                node (ls_1 + 1) (node (lls + size lrl + 1) ll_1 lx_1 lrl) lrx
                                  (node (size lrr + 1) lrr x nil))
                          (_ : id lr_1 = id lr_1))
                    (_ : id ll_1 = id ll_1))
              (_ : id (node ls ll lx lr) = id (node ls ll lx lr)))
        (fun rs_1 l x_1 r h =>
          (_ : node rs_1 l x_1 r = id (node rs rl rx rr)) ▸
            Ordnode.casesOn (motive := fun t => id (node ls ll lx lr) = t → Ordnode α) (id (node ls ll lx lr))
              (fun h => (_ : nil = id (node ls ll lx lr)) ▸ node (rs_1 + 1) nil x (node rs rl rx rr))
              (fun ls_1 ll_1 lx_1 lr_1 h =>
                (_ : node ls_1 ll_1 lx_1 lr_1 = id (node ls ll lx lr)) ▸
                  if ls_1 > delta * rs_1 then
                    Ordnode.casesOn (motive := fun t => id ll_1 = t → Ordnode α) (id ll_1)
                      (fun h => (_ : nil = id ll_1) ▸ nil)
                      (fun lls l x_2 r h =>
                        (_ : node lls l x_2 r = id ll_1) ▸
                          Ordnode.casesOn (motive := fun t => id lr_1 = t → Ordnode α) (id lr_1)
                            (fun h => (_ : nil = id lr_1) ▸ nil)
                            (fun lrs lrl lrx lrr h =>
                              (_ : node lrs lrl lrx lrr = id lr_1) ▸
                                if lrs < ratio * lls then
                                  node (ls_1 + rs_1 + 1) ll_1 lx_1 (node (rs_1 + lrs + 1) lr_1 x (node rs rl rx rr))
                                else
                                  node (ls_1 + rs_1 + 1) (node (lls + size lrl + 1) ll_1 lx_1 lrl) lrx
                                    (node (size lrr + rs_1 + 1) lrr x (node rs rl rx rr)))
                            (_ : id lr_1 = id lr_1))
                      (_ : id ll_1 = id ll_1)
                  else node (ls_1 + rs_1 + 1) (node ls ll lx lr) x (node rs rl rx rr))
              (_ : id (node ls ll lx lr) = id (node ls ll lx lr)))
        (_ : id (node rs rl rx rr) = id (node rs rl rx rr))) =
    Ordnode.casesOn (motive := fun t => id (dual (node rs rl rx rr)) = t → Ordnode α) (id (dual (node rs rl rx rr)))
      (fun h =>
        (_ : nil = id (dual (node rs rl rx rr))) ▸
          Ordnode.casesOn (motive := fun t => id (dual (node ls ll lx lr)) = t → Ordnode α)
            (id (dual (node ls ll lx lr))) (fun h => (_ : nil = id (dual (node ls ll lx lr))) ▸ Ordnode.singleton x)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual (node ls ll lx lr))) ▸
                Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
                  (fun h =>
                    (_ : nil = id rr) ▸
                      Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl
                        (fun h => (_ : nil = rl) ▸ node 2 nil x (dual (node ls ll lx lr)))
                        (fun size l rlx r h =>
                          (_ : node size l rlx r = rl) ▸ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx))
                        (_ : rl = rl))
                  (fun rrs l x_1 r h =>
                    (_ : node rrs l x_1 r = id rr) ▸
                      Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                        (fun h => (_ : nil = id rl) ▸ node 3 (Ordnode.singleton x) rx rr)
                        (fun rls rll rlx rlr h =>
                          (_ : node rls rll rlx rlr = id rl) ▸
                            if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                            else
                              node (rs + 1) (node (size rll + 1) nil x rll) rlx (node (size rlr + rrs + 1) rlr rx rr))
                        (_ : id rl = id rl))
                  (_ : id rr = id rr))
            (_ : id (dual (node ls ll lx lr)) = id (dual (node ls ll lx lr))))
      (fun ls_1 l x_1 r h =>
        (_ : node ls_1 l x_1 r = id (dual (node rs rl rx rr))) ▸
          Ordnode.casesOn (motive := fun t => id (dual (node ls ll lx lr)) = t → Ordnode α)
            (id (dual (node ls ll lx lr)))
            (fun h => (_ : nil = id (dual (node ls ll lx lr))) ▸ node (ls_1 + 1) (dual (node rs rl rx rr)) x nil)
            (fun rs_1 rl_1 rx_1 rr_1 h =>
              (_ : node rs_1 rl_1 rx_1 rr_1 = id (dual (node ls ll lx lr))) ▸
                if rs_1 > delta * ls_1 then
                  Ordnode.casesOn (motive := fun t => id rr_1 = t → Ordnode α) (id rr_1)
                    (fun h => (_ : nil = id rr_1) ▸ nil)
                    (fun rrs l x_2 r h =>
                      (_ : node rrs l x_2 r = id rr_1) ▸
                        Ordnode.casesOn (motive := fun t => id rl_1 = t → Ordnode α) (id rl_1)
                          (fun h => (_ : nil = id rl_1) ▸ nil)
                          (fun rls rll rlx rlr h =>
                            (_ : node rls rll rlx rlr = id rl_1) ▸
                              if rls < ratio * rrs then
                                node (ls_1 + rs_1 + 1) (node (ls_1 + rls + 1) (dual (node rs rl rx rr)) x rl_1) rx_1
                                  rr_1
                              else
                                node (ls_1 + rs_1 + 1) (node (ls_1 + size rll + 1) (dual (node rs rl rx rr)) x rll) rlx
                                  (node (size rlr + rrs + 1) rlr rx_1 rr_1))
                          (_ : id rl_1 = id rl_1))
                    (_ : id rr_1 = id rr_1)
                else node (ls_1 + rs_1 + 1) (dual (node rs rl rx rr)) x (dual (node ls ll lx lr)))
            (_ : id (dual (node ls ll lx lr)) = id (dual (node ls ll lx lr))))
      (_ : id (dual (node rs rl rx rr)) = id (dual (node rs rl rx rr)))
dsimp only [dual, id]
case node.node.inl
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
h✝ : ls > delta * rs
⊢ dual
      (rec (motive := fun t => ll = t → Ordnode α) (fun h => (_ : nil = id ll) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id ll) ▸
            rec (motive := fun t => lr = t → Ordnode α) (fun h => (_ : nil = id lr) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id lr) ▸
                  if size_1 < ratio * size then
                    node (ls + rs + 1) ll lx (node (rs + size_1 + 1) lr x (node rs rl rx rr))
                  else
                    node (ls + rs + 1) (node (size + Ordnode.size l + 1) ll lx l) x_2
                      (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
              lr (_ : id lr = id lr))
        ll (_ : id ll = id ll)) =
    rec (motive := fun t => dual ll = t → Ordnode α) (fun h => (_ : nil = id (dual ll)) ▸ nil)
      (fun size l x_1 r l_ih r_ih h =>
        (_ : node size l x_1 r = id (dual ll)) ▸
          rec (motive := fun t => dual lr = t → Ordnode α) (fun h => (_ : nil = id (dual lr)) ▸ nil)
            (fun size_1 l x_2 r l_ih r_ih h =>
              (_ : node size_1 l x_2 r = id (dual lr)) ▸
                if size_1 < ratio * size then
                  node (rs + ls + 1) (node (rs + size_1 + 1) (node rs (dual rr) rx (dual rl)) x (dual lr)) lx (dual ll)
                else
                  node (rs + ls + 1) (node (rs + Ordnode.size l + 1) (node rs (dual rr) rx (dual rl)) x l) x_2
                    (node (Ordnode.size r + size + 1) r lx (dual ll)))
            (dual lr) (_ : id (dual lr) = id (dual lr)))
      (dual ll) (_ : id (dual ll) = id (dual ll))

case node.node.inr
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
h✝ : ¬ls > delta * rs
⊢ dual (node (ls + rs + 1) (node ls ll lx lr) x (node rs rl rx rr)) =
    node (rs + ls + 1) (node rs (dual rr) rx (dual rl)) x (node ls (dual lr) lx (dual ll))
case node.node
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
⊢ dual
      (if ls > delta * rs then
        rec (motive := fun t => ll = t → Ordnode α) (fun h => (_ : nil = id ll) ▸ nil)
          (fun size l x_1 r l_ih r_ih h =>
            (_ : node size l x_1 r = id ll) ▸
              rec (motive := fun t => lr = t → Ordnode α) (fun h => (_ : nil = id lr) ▸ nil)
                (fun size_1 l x_2 r l_ih r_ih h =>
                  (_ : node size_1 l x_2 r = id lr) ▸
                    if size_1 < ratio * size then
                      node (ls + rs + 1) ll lx (node (rs + size_1 + 1) lr x (node rs rl rx rr))
                    else
                      node (ls + rs + 1) (node (size + Ordnode.size l + 1) ll lx l) x_2
                        (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
                lr (_ : id lr = id lr))
          ll (_ : id ll = id ll)
      else node (ls + rs + 1) (node ls ll lx lr) x (node rs rl rx rr)) =
    if ls > delta * rs then
      rec (motive := fun t => dual ll = t → Ordnode α) (fun h => (_ : nil = id (dual ll)) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id (dual ll)) ▸
            rec (motive := fun t => dual lr = t → Ordnode α) (fun h => (_ : nil = id (dual lr)) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id (dual lr)) ▸
                  if size_1 < ratio * size then
                    node (rs + ls + 1) (node (rs + size_1 + 1) (node rs (dual rr) rx (dual rl)) x (dual lr)) lx
                      (dual ll)
                  else
                    node (rs + ls + 1) (node (rs + Ordnode.size l + 1) (node rs (dual rr) rx (dual rl)) x l) x_2
                      (node (Ordnode.size r + size + 1) r lx (dual ll)))
              (dual lr) (_ : id (dual lr) = id (dual lr)))
        (dual ll) (_ : id (dual ll) = id (dual ll))
    else node (rs + ls + 1) (node rs (dual rr) rx (dual rl)) x (node ls (dual lr) lx (dual ll))
split_ifs
case node.node.inr
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
h✝ : ¬ls > delta * rs
⊢ dual (node (ls + rs + 1) (node ls ll lx lr) x (node rs rl rx rr)) =
    node (rs + ls + 1) (node rs (dual rr) rx (dual rl)) x (node ls (dual lr) lx (dual ll))

case node.node.inl
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
h✝ : ls > delta * rs
⊢ dual
      (rec (motive := fun t => ll = t → Ordnode α) (fun h => (_ : nil = id ll) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id ll) ▸
            rec (motive := fun t => lr = t → Ordnode α) (fun h => (_ : nil = id lr) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id lr) ▸
                  if size_1 < ratio * size then
                    node (ls + rs + 1) ll lx (node (rs + size_1 + 1) lr x (node rs rl rx rr))
                  else
                    node (ls + rs + 1) (node (size + Ordnode.size l + 1) ll lx l) x_2
                      (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
              lr (_ : id lr = id lr))
        ll (_ : id ll = id ll)) =
    rec (motive := fun t => dual ll = t → Ordnode α) (fun h => (_ : nil = id (dual ll)) ▸ nil)
      (fun size l x_1 r l_ih r_ih h =>
        (_ : node size l x_1 r = id (dual ll)) ▸
          rec (motive := fun t => dual lr = t → Ordnode α) (fun h => (_ : nil = id (dual lr)) ▸ nil)
            (fun size_1 l x_2 r l_ih r_ih h =>
              (_ : node size_1 l x_2 r = id (dual lr)) ▸
                if size_1 < ratio * size then
                  node (rs + ls + 1) (node (rs + size_1 + 1) (node rs (dual rr) rx (dual rl)) x (dual lr)) lx (dual ll)
                else
                  node (rs + ls + 1) (node (rs + Ordnode.size l + 1) (node rs (dual rr) rx (dual rl)) x l) x_2
                    (node (Ordnode.size r + size + 1) r lx (dual ll)))
            (dual lr) (_ : id (dual lr) = id (dual lr)))
      (dual ll) (_ : id (dual ll) = id (dual ll))
case node.node.inl
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
h✝ : ls > delta * rs
⊢ dual
      (rec (motive := fun t => ll = t → Ordnode α) (fun h => (_ : nil = id ll) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id ll) ▸
            rec (motive := fun t => lr = t → Ordnode α) (fun h => (_ : nil = id lr) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id lr) ▸
                  if size_1 < ratio * size then
                    node (ls + rs + 1) ll lx (node (rs + size_1 + 1) lr x (node rs rl rx rr))
                  else
                    node (ls + rs + 1) (node (size + Ordnode.size l + 1) ll lx l) x_2
                      (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
              lr (_ : id lr = id lr))
        ll (_ : id ll = id ll)) =
    rec (motive := fun t => dual ll = t → Ordnode α) (fun h => (_ : nil = id (dual ll)) ▸ nil)
      (fun size l x_1 r l_ih r_ih h =>
        (_ : node size l x_1 r = id (dual ll)) ▸
          rec (motive := fun t => dual lr = t → Ordnode α) (fun h => (_ : nil = id (dual lr)) ▸ nil)
            (fun size_1 l x_2 r l_ih r_ih h =>
              (_ : node size_1 l x_2 r = id (dual lr)) ▸
                if size_1 < ratio * size then
                  node (rs + ls + 1) (node (rs + size_1 + 1) (node rs (dual rr) rx (dual rl)) x (dual lr)) lx (dual ll)
                else
                  node (rs + ls + 1) (node (rs + Ordnode.size l + 1) (node rs (dual rr) rx (dual rl)) x l) x_2
                    (node (Ordnode.size r + size + 1) r lx (dual ll)))
            (dual lr) (_ : id (dual lr) = id (dual lr)))
      (dual ll) (_ : id (dual ll) = id (dual ll))

case node.node.inr
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
h✝ : ¬ls > delta * rs
⊢ dual (node (ls + rs + 1) (node ls ll lx lr) x (node rs rl rx rr)) =
    node (rs + ls + 1) (node rs (dual rr) rx (dual rl)) x (node ls (dual lr) lx (dual ll))
swap
case node.node.inl.node.node
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
lx : α
h✝ : ls > delta * rs
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
⊢ dual
      (rec (motive := fun t => node lls lll llx llr = t → Ordnode α)
        (fun h => (_ : nil = id (node lls lll llx llr)) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id (node lls lll llx llr)) ▸
            rec (motive := fun t => node lrs lrl lrx lrr = t → Ordnode α)
              (fun h => (_ : nil = id (node lrs lrl lrx lrr)) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id (node lrs lrl lrx lrr)) ▸
                  if size_1 < ratio * size then
                    node (ls + rs + 1) (node lls lll llx llr) lx
                      (node (rs + size_1 + 1) (node lrs lrl lrx lrr) x (node rs rl rx rr))
                  else
                    node (ls + rs + 1) (node (size + Ordnode.size l + 1) (node lls lll llx llr) lx l) x_2
                      (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
              (node lrs lrl lrx lrr) (_ : id (node lrs lrl lrx lrr) = id (node lrs lrl lrx lrr)))
        (node lls lll llx llr) (_ : id (node lls lll llx llr) = id (node lls lll llx llr))) =
    rec (motive := fun t => dual (node lls lll llx llr) = t → Ordnode α)
      (fun h => (_ : nil = id (dual (node lls lll llx llr))) ▸ nil)
      (fun size l x_1 r l_ih r_ih h =>
        (_ : node size l x_1 r = id (dual (node lls lll llx llr))) ▸
          rec (motive := fun t => dual (node lrs lrl lrx lrr) = t → Ordnode α)
            (fun h => (_ : nil = id (dual (node lrs lrl lrx lrr))) ▸ nil)
            (fun size_1 l x_2 r l_ih r_ih h =>
              (_ : node size_1 l x_2 r = id (dual (node lrs lrl lrx lrr))) ▸
                if size_1 < ratio * size then
                  node (rs + ls + 1)
                    (node (rs + size_1 + 1) (node rs (dual rr) rx (dual rl)) x (dual (node lrs lrl lrx lrr))) lx
                    (dual (node lls lll llx llr))
                else
                  node (rs + ls + 1) (node (rs + Ordnode.size l + 1) (node rs (dual rr) rx (dual rl)) x l) x_2
                    (node (Ordnode.size r + size + 1) r lx (dual (node lls lll llx llr))))
            (dual (node lrs lrl lrx lrr)) (_ : id (dual (node lrs lrl lrx lrr)) = id (dual (node lrs lrl lrx lrr))))
      (dual (node lls lll llx llr)) (_ : id (dual (node lls lll llx llr)) = id (dual (node lls lll llx llr)))
case node.node.inl
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
h✝ : ls > delta * rs
⊢ dual
      (rec (motive := fun t => ll = t → Ordnode α) (fun h => (_ : nil = id ll) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id ll) ▸
            rec (motive := fun t => lr = t → Ordnode α) (fun h => (_ : nil = id lr) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id lr) ▸
                  if size_1 < ratio * size then
                    node (ls + rs + 1) ll lx (node (rs + size_1 + 1) lr x (node rs rl rx rr))
                  else
                    node (ls + rs + 1) (node (size + Ordnode.size l + 1) ll lx l) x_2
                      (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
              lr (_ : id lr = id lr))
        ll (_ : id ll = id ll)) =
    rec (motive := fun t => dual ll = t → Ordnode α) (fun h => (_ : nil = id (dual ll)) ▸ nil)
      (fun size l x_1 r l_ih r_ih h =>
        (_ : node size l x_1 r = id (dual ll)) ▸
          rec (motive := fun t => dual lr = t → Ordnode α) (fun h => (_ : nil = id (dual lr)) ▸ nil)
            (fun size_1 l x_2 r l_ih r_ih h =>
              (_ : node size_1 l x_2 r = id (dual lr)) ▸
                if size_1 < ratio * size then
                  node (rs + ls + 1) (node (rs + size_1 + 1) (node rs (dual rr) rx (dual rl)) x (dual lr)) lx (dual ll)
                else
                  node (rs + ls + 1) (node (rs + Ordnode.size l + 1) (node rs (dual rr) rx (dual rl)) x l) x_2
                    (node (Ordnode.size r + size + 1) r lx (dual ll)))
            (dual lr) (_ : id (dual lr) = id (dual lr)))
      (dual ll) (_ : id (dual ll) = id (dual ll))
cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> try rfl
case node.node.inl.node.node
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
lx : α
h✝ : ls > delta * rs
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
⊢ dual
      (if lrs < ratio * lls then
        node (ls + rs + 1) (node lls lll llx llr) lx (node (rs + lrs + 1) (node lrs lrl lrx lrr) x (node rs rl rx rr))
      else
        node (ls + rs + 1) (node (lls + size lrl + 1) (node lls lll llx llr) lx lrl) lrx
          (node (size lrr + rs + 1) lrr x (node rs rl rx rr))) =
    if lrs < ratio * lls then
      node (rs + ls + 1) (node (rs + lrs + 1) (node rs (dual rr) rx (dual rl)) x (node lrs (dual lrr) lrx (dual lrl)))
        lx (node lls (dual llr) llx (dual lll))
    else
      node (rs + ls + 1) (node (rs + size (dual lrr) + 1) (node rs (dual rr) rx (dual rl)) x (dual lrr)) lrx
        (node (size (dual lrl) + lls + 1) (dual lrl) lx (node lls (dual llr) llx (dual lll)))
case node.node.inl.node.node
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
lx : α
h✝ : ls > delta * rs
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
⊢ dual
      (rec (motive := fun t => node lls lll llx llr = t → Ordnode α)
        (fun h => (_ : nil = id (node lls lll llx llr)) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id (node lls lll llx llr)) ▸
            rec (motive := fun t => node lrs lrl lrx lrr = t → Ordnode α)
              (fun h => (_ : nil = id (node lrs lrl lrx lrr)) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id (node lrs lrl lrx lrr)) ▸
                  if size_1 < ratio * size then
                    node (ls + rs + 1) (node lls lll llx llr) lx
                      (node (rs + size_1 + 1) (node lrs lrl lrx lrr) x (node rs rl rx rr))
                  else
                    node (ls + rs + 1) (node (size + Ordnode.size l + 1) (node lls lll llx llr) lx l) x_2
                      (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
              (node lrs lrl lrx lrr) (_ : id (node lrs lrl lrx lrr) = id (node lrs lrl lrx lrr)))
        (node lls lll llx llr) (_ : id (node lls lll llx llr) = id (node lls lll llx llr))) =
    rec (motive := fun t => dual (node lls lll llx llr) = t → Ordnode α)
      (fun h => (_ : nil = id (dual (node lls lll llx llr))) ▸ nil)
      (fun size l x_1 r l_ih r_ih h =>
        (_ : node size l x_1 r = id (dual (node lls lll llx llr))) ▸
          rec (motive := fun t => dual (node lrs lrl lrx lrr) = t → Ordnode α)
            (fun h => (_ : nil = id (dual (node lrs lrl lrx lrr))) ▸ nil)
            (fun size_1 l x_2 r l_ih r_ih h =>
              (_ : node size_1 l x_2 r = id (dual (node lrs lrl lrx lrr))) ▸
                if size_1 < ratio * size then
                  node (rs + ls + 1)
                    (node (rs + size_1 + 1) (node rs (dual rr) rx (dual rl)) x (dual (node lrs lrl lrx lrr))) lx
                    (dual (node lls lll llx llr))
                else
                  node (rs + ls + 1) (node (rs + Ordnode.size l + 1) (node rs (dual rr) rx (dual rl)) x l) x_2
                    (node (Ordnode.size r + size + 1) r lx (dual (node lls lll llx llr))))
            (dual (node lrs lrl lrx lrr)) (_ : id (dual (node lrs lrl lrx lrr)) = id (dual (node lrs lrl lrx lrr))))
      (dual (node lls lll llx llr)) (_ : id (dual (node lls lll llx llr)) = id (dual (node lls lll llx llr)))
dsimp only [dual, id]
no goals
case node.node.inl.node.node
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
lx : α
h✝ : ls > delta * rs
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
⊢ dual
      (if lrs < ratio * lls then
        node (ls + rs + 1) (node lls lll llx llr) lx (node (rs + lrs + 1) (node lrs lrl lrx lrr) x (node rs rl rx rr))
      else
        node (ls + rs + 1) (node (lls + size lrl + 1) (node lls lll llx llr) lx lrl) lrx
          (node (size lrr + rs + 1) lrr x (node rs rl rx rr))) =
    if lrs < ratio * lls then
      node (rs + ls + 1) (node (rs + lrs + 1) (node rs (dual rr) rx (dual rl)) x (node lrs (dual lrr) lrx (dual lrl)))
        lx (node lls (dual llr) llx (dual lll))
    else
      node (rs + ls + 1) (node (rs + size (dual lrr) + 1) (node rs (dual rr) rx (dual rl)) x (dual lrr)) lrx
        (node (size (dual lrl) + lls + 1) (dual lrl) lx (node lls (dual llr) llx (dual lll)))
split_ifs with h <;> simp [h, add_comm]
no goals
case node.nil
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
⊢ dual
      (Ordnode.casesOn (motive := fun t => id (node rs rl rx rr) = t → Ordnode α) (id (node rs rl rx rr))
        (fun h =>
          (_ : nil = id (node rs rl rx rr)) ▸
            Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
              (fun h => (_ : nil = id nil) ▸ Ordnode.singleton x)
              (fun ls ll lx lr h =>
                (_ : node ls ll lx lr = id nil) ▸
                  Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                    (fun h =>
                      (_ : nil = id ll) ▸
                        Ordnode.casesOn (motive := fun t => lr = t → Ordnode α) lr
                          (fun h => (_ : nil = lr) ▸ node 2 nil x nil)
                          (fun size l lrx r h =>
                            (_ : node size l lrx r = lr) ▸ node 3 (Ordnode.singleton lx) lrx (Ordnode.singleton x))
                          (_ : lr = lr))
                    (fun lls l x_1 r h =>
                      (_ : node lls l x_1 r = id ll) ▸
                        Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                          (fun h => (_ : nil = id lr) ▸ node 3 ll lx (Ordnode.singleton x))
                          (fun lrs lrl lrx lrr h =>
                            (_ : node lrs lrl lrx lrr = id lr) ▸
                              if lrs < ratio * lls then node (ls + 1) ll lx (node (lrs + 1) lr x nil)
                              else
                                node (ls + 1) (node (lls + size lrl + 1) ll lx lrl) lrx (node (size lrr + 1) lrr x nil))
                          (_ : id lr = id lr))
                    (_ : id ll = id ll))
              (_ : id nil = id nil))
        (fun rs_1 l x_1 r h =>
          (_ : node rs_1 l x_1 r = id (node rs rl rx rr)) ▸
            Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
              (fun h => (_ : nil = id nil) ▸ node (rs_1 + 1) nil x (node rs rl rx rr))
              (fun ls ll lx lr h =>
                (_ : node ls ll lx lr = id nil) ▸
                  if ls > delta * rs_1 then
                    Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                      (fun h => (_ : nil = id ll) ▸ nil)
                      (fun lls l x_2 r h =>
                        (_ : node lls l x_2 r = id ll) ▸
                          Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                            (fun h => (_ : nil = id lr) ▸ nil)
                            (fun lrs lrl lrx lrr h =>
                              (_ : node lrs lrl lrx lrr = id lr) ▸
                                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 + size lrl + 1) ll lx lrl) lrx
                                    (node (size lrr + rs_1 + 1) lrr x (node rs rl rx rr)))
                            (_ : id lr = id lr))
                      (_ : id ll = id ll)
                  else node (ls + rs_1 + 1) nil x (node rs rl rx rr))
              (_ : id nil = id nil))
        (_ : id (node rs rl rx rr) = id (node rs rl rx rr))) =
    Ordnode.casesOn (motive := fun t => id (dual (node rs rl rx rr)) = t → Ordnode α) (id (dual (node rs rl rx rr)))
      (fun h =>
        (_ : nil = id (dual (node rs rl rx rr))) ▸
          Ordnode.casesOn (motive := fun t => id (dual nil) = t → Ordnode α) (id (dual nil))
            (fun h => (_ : nil = id (dual nil)) ▸ Ordnode.singleton x)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual nil)) ▸
                Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
                  (fun h =>
                    (_ : nil = id rr) ▸
                      Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl
                        (fun h => (_ : nil = rl) ▸ node 2 nil x (dual nil))
                        (fun size l rlx r h =>
                          (_ : node size l rlx r = rl) ▸ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx))
                        (_ : rl = rl))
                  (fun rrs l x_1 r h =>
                    (_ : node rrs l x_1 r = id rr) ▸
                      Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                        (fun h => (_ : nil = id rl) ▸ node 3 (Ordnode.singleton x) rx rr)
                        (fun rls rll rlx rlr h =>
                          (_ : node rls rll rlx rlr = id rl) ▸
                            if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                            else
                              node (rs + 1) (node (size rll + 1) nil x rll) rlx (node (size rlr + rrs + 1) rlr rx rr))
                        (_ : id rl = id rl))
                  (_ : id rr = id rr))
            (_ : id (dual nil) = id (dual nil)))
      (fun ls l x_1 r h =>
        (_ : node ls l x_1 r = id (dual (node rs rl rx rr))) ▸
          Ordnode.casesOn (motive := fun t => id (dual nil) = t → Ordnode α) (id (dual nil))
            (fun h => (_ : nil = id (dual nil)) ▸ node (ls + 1) (dual (node rs rl rx rr)) x nil)
            (fun rs_1 rl_1 rx_1 rr_1 h =>
              (_ : node rs_1 rl_1 rx_1 rr_1 = id (dual nil)) ▸
                if rs_1 > delta * ls then
                  Ordnode.casesOn (motive := fun t => id rr_1 = t → Ordnode α) (id rr_1)
                    (fun h => (_ : nil = id rr_1) ▸ nil)
                    (fun rrs l x_2 r h =>
                      (_ : node rrs l x_2 r = id rr_1) ▸
                        Ordnode.casesOn (motive := fun t => id rl_1 = t → Ordnode α) (id rl_1)
                          (fun h => (_ : nil = id rl_1) ▸ nil)
                          (fun rls rll rlx rlr h =>
                            (_ : node rls rll rlx rlr = id rl_1) ▸
                              if rls < ratio * rrs then
                                node (ls + rs_1 + 1) (node (ls + rls + 1) (dual (node rs rl rx rr)) x rl_1) rx_1 rr_1
                              else
                                node (ls + rs_1 + 1) (node (ls + size rll + 1) (dual (node rs rl rx rr)) x rll) rlx
                                  (node (size rlr + rrs + 1) rlr rx_1 rr_1))
                          (_ : id rl_1 = id rl_1))
                    (_ : id rr_1 = id rr_1)
                else node (ls + rs_1 + 1) (dual (node rs rl rx rr)) x (dual nil))
            (_ : id (dual nil) = id (dual nil)))
      (_ : id (dual (node rs rl rx rr)) = id (dual (node rs rl rx rr)))
rfl
no goals
case node.node.inr
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
h✝ : ¬ls > delta * rs
⊢ dual (node (ls + rs + 1) (node ls ll lx lr) x (node rs rl rx rr)) =
    node (rs + ls + 1) (node rs (dual rr) rx (dual rl)) x (node ls (dual lr) lx (dual ll))
simp [add_comm]
case node.node.inl.node.node
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
lx : α
h✝ : ls > delta * rs
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
⊢ dual
      (rec (motive := fun t => node lls lll llx llr = t → Ordnode α)
        (fun h => (_ : nil = id (node lls lll llx llr)) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id (node lls lll llx llr)) ▸
            rec (motive := fun t => node lrs lrl lrx lrr = t → Ordnode α)
              (fun h => (_ : nil = id (node lrs lrl lrx lrr)) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id (node lrs lrl lrx lrr)) ▸
                  if size_1 < ratio * size then
                    node (ls + rs + 1) (node lls lll llx llr) lx
                      (node (rs + size_1 + 1) (node lrs lrl lrx lrr) x (node rs rl rx rr))
                  else
                    node (ls + rs + 1) (node (size + Ordnode.size l + 1) (node lls lll llx llr) lx l) x_2
                      (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
              (node lrs lrl lrx lrr) (_ : id (node lrs lrl lrx lrr) = id (node lrs lrl lrx lrr)))
        (node lls lll llx llr) (_ : id (node lls lll llx llr) = id (node lls lll llx llr))) =
    rec (motive := fun t => dual (node lls lll llx llr) = t → Ordnode α)
      (fun h => (_ : nil = id (dual (node lls lll llx llr))) ▸ nil)
      (fun size l x_1 r l_ih r_ih h =>
        (_ : node size l x_1 r = id (dual (node lls lll llx llr))) ▸
          rec (motive := fun t => dual (node lrs lrl lrx lrr) = t → Ordnode α)
            (fun h => (_ : nil = id (dual (node lrs lrl lrx lrr))) ▸ nil)
            (fun size_1 l x_2 r l_ih r_ih h =>
              (_ : node size_1 l x_2 r = id (dual (node lrs lrl lrx lrr))) ▸
                if size_1 < ratio * size then
                  node (rs + ls + 1)
                    (node (rs + size_1 + 1) (node rs (dual rr) rx (dual rl)) x (dual (node lrs lrl lrx lrr))) lx
                    (dual (node lls lll llx llr))
                else
                  node (rs + ls + 1) (node (rs + Ordnode.size l + 1) (node rs (dual rr) rx (dual rl)) x l) x_2
                    (node (Ordnode.size r + size + 1) r lx (dual (node lls lll llx llr))))
            (dual (node lrs lrl lrx lrr)) (_ : id (dual (node lrs lrl lrx lrr)) = id (dual (node lrs lrl lrx lrr))))
      (dual (node lls lll llx llr)) (_ : id (dual (node lls lll llx llr)) = id (dual (node lls lll llx llr)))
case node.node.inl.node.node
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
lx : α
h✝ : ls > delta * rs
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
⊢ dual
      (rec (motive := fun t => node lls lll llx llr = t → Ordnode α)
        (fun h => (_ : nil = id (node lls lll llx llr)) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id (node lls lll llx llr)) ▸
            rec (motive := fun t => node lrs lrl lrx lrr = t → Ordnode α)
              (fun h => (_ : nil = id (node lrs lrl lrx lrr)) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id (node lrs lrl lrx lrr)) ▸
                  if size_1 < ratio * size then
                    node (ls + rs + 1) (node lls lll llx llr) lx
                      (node (rs + size_1 + 1) (node lrs lrl lrx lrr) x (node rs rl rx rr))
                  else
                    node (ls + rs + 1) (node (size + Ordnode.size l + 1) (node lls lll llx llr) lx l) x_2
                      (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
              (node lrs lrl lrx lrr) (_ : id (node lrs lrl lrx lrr) = id (node lrs lrl lrx lrr)))
        (node lls lll llx llr) (_ : id (node lls lll llx llr) = id (node lls lll llx llr))) =
    rec (motive := fun t => dual (node lls lll llx llr) = t → Ordnode α)
      (fun h => (_ : nil = id (dual (node lls lll llx llr))) ▸ nil)
      (fun size l x_1 r l_ih r_ih h =>
        (_ : node size l x_1 r = id (dual (node lls lll llx llr))) ▸
          rec (motive := fun t => dual (node lrs lrl lrx lrr) = t → Ordnode α)
            (fun h => (_ : nil = id (dual (node lrs lrl lrx lrr))) ▸ nil)
            (fun size_1 l x_2 r l_ih r_ih h =>
              (_ : node size_1 l x_2 r = id (dual (node lrs lrl lrx lrr))) ▸
                if size_1 < ratio * size then
                  node (rs + ls + 1)
                    (node (rs + size_1 + 1) (node rs (dual rr) rx (dual rl)) x (dual (node lrs lrl lrx lrr))) lx
                    (dual (node lls lll llx llr))
                else
                  node (rs + ls + 1) (node (rs + Ordnode.size l + 1) (node rs (dual rr) rx (dual rl)) x l) x_2
                    (node (Ordnode.size r + size + 1) r lx (dual (node lls lll llx llr))))
            (dual (node lrs lrl lrx lrr)) (_ : id (dual (node lrs lrl lrx lrr)) = id (dual (node lrs lrl lrx lrr))))
      (dual (node lls lll llx llr)) (_ : id (dual (node lls lll llx llr)) = id (dual (node lls lll llx llr)))
rfl