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;
reserve
  w for (Element of Args(o,T)),
  p,p1 for Element of Args(o,Free(S,X));

theorem ThR1:
  vf r = Union (X variables_in r)
  proof
    thus vf r c= Union (X variables_in r)
    proof
      let a; assume a in vf r;
      then consider b such that
A1:   [a,b] in rng r /\ [:Union X, the carrier of S:] by XTUPLE_0:def 12;
A2:   [a,b] in rng r & [a,b] in [:Union X, the carrier of S:]
      by A1,XBOOLE_0:def 4;
      then a in Union X & b in the carrier of S by ZFMISC_1:87;
      then consider c being object such that
A4:   c in dom X & a in X.c by CARD_5:2;
      reconsider b,c as SortSymbol of S by A4,A2,ZFMISC_1:87;
      consider d being object such that
A5:   d in dom r & [a,b] = r.d by A2,FUNCT_1:def 3;
      reconsider d as Element of dom r by A5;
      reconsider t = r|d as Element of T by MSAFREE4:44;
A7:   (X variables_in r).b = (X.b)/\{a`1 where a is Element of rng r: a`2 = b}
      by MSAFREE3:9;
      t is Element of Free(S,X) by MSAFREE4:39;
      then per cases by Th16;
      suppose ex s,x st t = x-term;
        then consider s,x such that
A6:     t = x-term;
        <*>NAT in (dom r)|d by TREES_1:22;
        then r.(d^{}) = t.{} by TREES_2:def 10
        .= [x,s] by A6,TREES_4:3;
        then
A8:     a = x & b = s by A5,XTUPLE_0:1;
        [a,b]`1 = a & [a,b]`2 = b;
        then a in {a`1 where a is Element of rng r: a`2 = b} by A2;
        then a in (X variables_in r).s &
        dom(X variables_in r) = the carrier of S
        by A7,A8,XBOOLE_0:def 4,PARTFUN1:def 2;
        hence thesis by CARD_5:2;
      end;
      suppose ex o,p st t = o-term p;
        then consider o,p such that
A6:     t = o-term p;
        <*>NAT in (dom r)|d by TREES_1:22;
        then r.(d^{}) = t.{} by TREES_2:def 10
        .= [o,the carrier of S] by A6,TREES_4:def 4;
        then
        b in the carrier of S = b by A5,XTUPLE_0:1;
        hence thesis;
      end;
    end;
    let a; assume a in Union (X variables_in r);
    then consider b such that
B1: b in dom (X variables_in r) & a in (X variables_in r).b by CARD_5:2;
    reconsider b as SortSymbol of S by B1;
    (X variables_in r).b = (X.b)/\{a`1 where a is Element of rng r: a`2 = b}
    by MSAFREE3:9;
    then
B2: a in X.b & a in {a`1 where a is Element of rng r: a`2 = b}
    by B1,XBOOLE_0:def 4;
    then consider q being Element of rng r such that
B3: a = q`1 & q`2 = b;
    dom X = the carrier of S by PARTFUN1:def 2;
    then a in Union X by B2,CARD_5:2;
    then
B6: [a,b] in [:Union X, the carrier of S:] by ZFMISC_1:87;
    consider xi being object such that
B4: xi in dom r & q = r.xi by FUNCT_1:def 3;
    reconsider xi as Element of dom r by B4;
    reconsider t = r|xi as Element of T by MSAFREE4:44;
    t is Element of Free(S,X) by MSAFREE4:39;
    then per cases by Th16;
    suppose ex s,x st t = x-term;
      then consider s,x such that
A6:   t = x-term;
      <*>NAT in (dom r)|xi by TREES_1:22;
      then r.(xi^{}) = t.{} by TREES_2:def 10
      .= [x,s] by A6,TREES_4:3;
      then [a,b] in rng r /\ [:Union X, the carrier of S:]
      by B6,B3,B4,XBOOLE_0:def 4;
      hence thesis by XTUPLE_0:def 12;
    end;
    suppose ex o,p st t = o-term p;
      then consider o,p such that
A6:   t = o-term p;
      <*>NAT in (dom r)|xi by TREES_1:22;
      then r.(xi^{}) = t.{} by TREES_2:def 10
      .= [o,the carrier of S] by A6,TREES_4:def 4;
      then
      b in the carrier of S = b by B3,B4;
      hence thesis;
    end;
  end;
