reserve
  a,b for object, I,J for set, f for Function, R for Relation,
  i,j,n for Nat, m for (Element of NAT),
  S for non empty non void ManySortedSign,
  s,s1,s2 for SortSymbol of S,
  o for OperSymbol of S,
  X for non-empty ManySortedSet of the carrier of S,
  x,x1,x2 for (Element of X.s), x11 for (Element of X.s1),
  T for all_vars_including inheriting_operations free_in_itself
  (X,S)-terms MSAlgebra over S,
  g for Translation of Free(S,X),s1,s2,
  h for Endomorphism of Free(S,X);
reserve
  r,r1,r2 for (Element of T),
  t,t1,t2 for (Element of Free(S,X));
reserve
  Y for infinite-yielding ManySortedSet of the carrier of S,
  y,y1 for (Element of Y.s), y11 for (Element of Y.s1),
  Q for all_vars_including inheriting_operations free_in_itself
  (Y,S)-terms MSAlgebra over S,
  q,q1 for (Element of Args(o,Free(S,Y))),
  u,u1,u2 for (Element of Q),
  v,v1,v2 for (Element of Free(S,Y)),
  Z for non-trivial ManySortedSet of the carrier of S,
  z,z1 for (Element of Z.s),
  l,l1 for (Element of Free(S,Z)),
  R for all_vars_including inheriting_operations free_in_itself
  (Z,S)-terms MSAlgebra over S,
  k,k1 for Element of Args(o,Free(S,Z));
reserve c,c1,c2 for set, d,d1 for DecoratedTree;

theorem ThL8:
  for p,q being non empty DTree-yielding FinSequence st
  dom q = dom p & (for i,d1 st i in dom p & d1 = p.i holds q.i = (d1,c)<-d)
  holds (b-tree p,c)<-d = b-tree q
  proof
    let p,q be non empty DTree-yielding FinSequence such that
A1: dom q = dom p and
A2: for i,d1 st i in dom p & d1 = p.i holds q.i = (d1,c)<-d;
A3: dom(b-tree p) = tree doms p & dom (b-tree q) = tree doms q by TREES_4:10;
A4: Leaves tree doms p = {<*i*>^q where i where q is FinSequence of NAT,
    d is Tree: q in Leaves d & i+1 in dom doms p & d = (doms p).(i+1)} by ThL0;
A5: dom doms p = dom p & dom doms q = dom q by FUNCT_6:def 2; then
A6: len doms p = len p = len q = len doms q by A1,FINSEQ_3:29;
AA: dom ((b-tree p,c)<-d) = dom(b-tree q)
    proof
      let x be FinSequence of NAT;
      hereby assume x in dom ((b-tree p,c)<-d);
        then reconsider r = x as Node of (b-tree p,c)<-d;
        per cases by TREES_4:def 7;
        suppose r in dom (b-tree p);
          then per cases by A3,TREES_3:def 15;
          suppose r = {};
            hence x in dom(b-tree q) by TREES_1:22;
          end;
          suppose ex n being Nat,q being FinSequence st
            n < len doms p & q in (doms p).(n+1) & x = <*n*>^q;
            then consider n being Nat, w being FinSequence such that
A7:         n < len doms p & w in (doms p).(n+1) & x = <*n*>^w;
A9:         1 <= n+1 <= len doms p by A7,NAT_1:11,13;
            reconsider pn = p.(n+1) as DecoratedTree
            by A5,A9,FINSEQ_3:25,TREES_3:24;
            reconsider qn = q.(n+1) as DecoratedTree
            by A1,A9,A5,FINSEQ_3:25,TREES_3:24;
            qn = (pn,c)<-d by A2,A5,A9,FINSEQ_3:25;
            then (doms p).(n+1) = dom pn c= dom qn = (doms q).(n+1)
            by A1,A5,A9,TREES_4:def 7,FINSEQ_3:25,FUNCT_6:def 2;
            hence x in dom (b-tree q) by A3,A6,A7,TREES_3:def 15;
          end;
        end;
        suppose ex q being Node of b-tree p, s being Node of d st
          q in Leaves dom (b-tree p) & (b-tree p).q = c & r = q^s;
          then consider w being Node of b-tree p, s being Node of d such that
A8:       w in Leaves dom (b-tree p) & (b-tree p).w = c & r = w^s;
          consider i being Nat, u being FinSequence of NAT, d2 being Tree such
          that
A9:       w = <*i*>^u & u in Leaves d2 & i+1 in dom doms p &
          d2 = (doms p).(i+1) by A8,A3,A4;
          reconsider p1 = p.(i+1) as DecoratedTree by A5,A9,TREES_3:24;
B1:       w^s = <*i*>^(u^s) by A9,FINSEQ_1:32;
B2:       q.(i+1) = (p1,c)<-d by A2,A5,A9;
B3:       dom p1 = d2 by A5,A9,FUNCT_6:def 2;
          reconsider u as Node of p1 by A5,A9,FUNCT_6:def 2;
B6:       i+1 <= len doms p by A9,FINSEQ_3:25;
          then
B4:       i < len doms p by NAT_1:13;
          p1.u = c by B6,A6,A8,A9,NAT_1:13,TREES_4:12;
          then
B5:       u^s in dom((p1,c)<-d) = (doms q).(i+1)
          by B3,A1,A5,A9,B2,TREES_4:def 7,FUNCT_6:def 2;
          thus x in dom (b-tree q)
          by B1,B4,B5,A3,A6,A8,TREES_3:def 15;
        end;
      end;
      assume x in dom (b-tree q);
      then reconsider r = x as Node of b-tree q;
      per cases by A3,TREES_3:def 15;
      suppose r = {};
        hence x in dom((b-tree p,c)<-d) by TREES_1:22;
      end;
      suppose ex i st ex w being FinSequence st
        i < len doms q & w in (doms q).(i+1) & x = <*i*>^w;
        then consider n being Nat, w being FinSequence such that
C1:     n < len doms q & w in (doms q).(n+1) & x = <*n*>^w;
C4:     1 <= n+1 <= len doms q by C1,NAT_1:11,13;
        then
C2:     n+1 in dom doms q by FINSEQ_3:25;
        reconsider qi = q.(n+1) as DecoratedTree
        by C4,A5,FINSEQ_3:25,TREES_3:24;
        reconsider p1 = p.(n+1) as DecoratedTree
        by A1,A5,C4,FINSEQ_3:25,TREES_3:24;
C3:     dom qi = (doms q).(n+1) & dom p1 = (doms p).(n+1)
        by A1,A5,C4,FINSEQ_3:25,FUNCT_6:def 2;
        qi = (p1,c)<-d by C4,A1,A2,A5,FINSEQ_3:25;
        then per cases by C1,C3,TREES_4:def 7;
        suppose w in dom p1;
          then x in dom(b-tree p) c= dom((b-tree p,c)<-d)
          by A3,A6,C1,C3,TREES_4:def 7,TREES_3:def 15;
          hence x in dom((b-tree p,c)<-d);
        end;
        suppose ex u being Node of p1, s being Node of d st
          u in Leaves dom p1 & p1.u = c & w = u^s;
          then consider u being Node of p1, s being Node of d such that
C4:       u in Leaves dom p1 & p1.u = c & w = u^s;
C5:       <*n*>^u in Leaves tree doms p by A4,C4,A5,A1,C2,C3;
          (b-tree p).(<*n*>^u) = c by C1,A6,C4,TREES_4:12;
          then <*n*>^u^s in dom((b-tree p,c)<-d) by A3,C5,TREES_4:def 7;
          hence x in dom((b-tree p,c)<-d) by C1,C4,FINSEQ_1:32;
        end;
      end;
    end;
    now
      let x be object;
      assume x in dom (b-tree q);
      then reconsider r = x as Node of b-tree q;
      per cases by A3,TREES_3:def 15;
      suppose
C1:     r = {};
        reconsider r = {} as Node of b-tree p by TREES_1:22;
        not ex i being Nat, q being FinSequence of NAT, d being Tree st
        r = <*i*>^q & q in Leaves d & i+1 in dom doms p & d = (doms p).(i+1);
        then r nin Leaves dom (b-tree p) by A4,A3;
        hence ((b-tree p,c)<-d).x = (b-tree p).r  by C1,TREES_4:def 7
        .= b by TREES_4:def 4 .= (b-tree q).x by C1,TREES_4:def 4;
      end;
      suppose ex i st ex w being FinSequence st
        i < len doms q & w in (doms q).(i+1) & x = <*i*>^w;
        then consider n being Nat, w being FinSequence such that
C1:     n < len doms q & w in (doms q).(n+1) & x = <*n*>^w;
C5:     1 <= n+1 <= len doms q by C1,NAT_1:11,13;
        then
C2:     n+1 in dom doms q by FINSEQ_3:25;
        reconsider qi = q.(n+1) as DecoratedTree
        by C5,A5,FINSEQ_3:25,TREES_3:24;
        reconsider p1 = p.(n+1) as DecoratedTree
        by A1,A5,C5,FINSEQ_3:25,TREES_3:24;
C3:     dom qi = (doms q).(n+1) & dom p1 = (doms p).(n+1)
        by A1,A5,C5,FINSEQ_3:25,FUNCT_6:def 2;
C4:     qi = (p1,c)<-d by C5,A1,A2,A5,FINSEQ_3:25;
        then per cases by C1,C3,TREES_4:def 7;
        suppose
D1:       w in dom p1 & (w nin Leaves dom p1);
D4:       qi.w = p1.w & dom p1 c= dom qi by D1,C4,TREES_4:def 7;
D5:       x is Node of b-tree p by C1,A6,A3,C3,D1,TREES_3:def 15;
          now given i being Nat, q being FinSequence of NAT, d being Tree such
            that
D2:         r = <*i*>^q & q in Leaves d & i+1 in dom doms p &
            d = (doms p).(i+1);
            i = r.1 = n & q = w by C1,D2,FINSEQ_1:41,HILBERT2:2;
            hence contradiction by D1,A5,D2,FUNCT_6:def 2;
          end;
          then r nin Leaves dom (b-tree p) by A4,A3;
          hence ((b-tree p,c)<-d).x = (b-tree p).r  by D5,TREES_4:def 7
          .= p1.w by C1,A6,D1,TREES_4:12
          .= (b-tree q).x by C1,A6,D1,D4,TREES_4:12;
        end;
        suppose
D1:       w in dom p1 & (p1.w <> c);
D4:       qi.w = p1.w & dom p1 c= dom qi by D1,C4,TREES_4:def 7;
D5:       x is Node of b-tree p by C1,A6,A3,C3,D1,TREES_3:def 15;
          (b-tree p).r <> c by C1,A6,D1,TREES_4:12;
          hence ((b-tree p,c)<-d).x = (b-tree p).r  by D5,TREES_4:def 7
          .= p1.w by C1,A6,D1,TREES_4:12
          .= (b-tree q).x by C1,A6,D1,D4,TREES_4:12;
        end;
        suppose
C7:       w in dom p1 & w in Leaves dom p1 & p1.w = c;
          then reconsider u = w as Node of p1;
          reconsider s = {} as Node of d by TREES_1:22;
C71:      w = u^s;
C5:       <*n*>^u in Leaves tree doms p by A4,C7,A5,A1,C2,C3;
C6:       (b-tree p).(<*n*>^u) = c by C1,A6,C7,TREES_4:12;
          ((b-tree p,c)<-d).(<*n*>^u^s) = d.s by A3,C5,C6,TREES_4:def 7
          .= qi.w by C4,C7,C71,TREES_4:def 7
          .= (b-tree q).x by C1,A6,C3,TREES_4:12;
          hence ((b-tree p,c)<-d).x = (b-tree q).x by C1;
        end;
        suppose ex u being Node of p1, s being Node of d st
          u in Leaves dom p1 & p1.u = c & w = u^s;
          then consider u being Node of p1, s being Node of d such that
C7:       u in Leaves dom p1 & p1.u = c & w = u^s;
C5:       <*n*>^u in Leaves tree doms p by A4,C7,A5,A1,C2,C3;
C6:       (b-tree p).(<*n*>^u) = c by C1,A6,C7,TREES_4:12;
          ((b-tree p,c)<-d).(<*n*>^u^s) = d.s by A3,C5,C6,TREES_4:def 7
          .= qi.w by C4,C7,TREES_4:def 7
          .= (b-tree q).x by C1,A6,C3,TREES_4:12;
          hence ((b-tree p,c)<-d).x = (b-tree q).x by C1,C7,FINSEQ_1:32;
        end;
      end;
    end;
    hence thesis by AA,FUNCT_1:2;
  end;
