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));
reserve C for (context of x), C1 for (context of y), C9 for (context of z),
  C11 for (context of x11), C12 for (context of y11), D for context of s,X;

theorem Th53:
  p is x-context_including iff o-term p is context of x
  proof
    set I = {[x,s]}; set k = p;
    reconsider J = [o,the carrier of S] as set;
    s in the carrier of S; then s <> the carrier of S;
    then [o,the carrier of S] <> [x,s] by XTUPLE_0:1;
    then [o,the carrier of S] nin I by TARSKI:def 1;
    then IFIN(J,I,{{}},{}) = {} by MATRIX_7:def 1;
    then
A5: (o-term k)"I = {} \/ union {<*i*>^^((k.(i+1))"I): i < len k} by Th80;
    thus k is x-context_including implies o-term k is context of x
    proof
      given i such that
A6:   i in dom k & k.i is context of x &
      for j for t being Element of Free(S,X) st j in dom k & j <> i & t = k.j
      holds t is x-omitting;
      reconsider C = k.i as context of x by A6;
      card Coim(C,[x,s]) = 1 by CONTEXT;
      then consider a such that
A9:   C"I = {a} by CARD_2:42;
      a in C"I by A9,TARSKI:def 1;
      then reconsider a as FinSequence;
      consider j such that
A7:   i = 1+j by A6,FINSEQ_3:25,NAT_1:10;
      1+j <= len k by A6,A7,FINSEQ_3:25;
      then
A8:   j < len k by NAT_1:13;
      union {<*i*>^^((k.(i+1))"I) where i: i < len k} = {<*j*>^a}
      proof
        thus union {<*i*>^^((k.(i+1))"I) where i: i < len k} c= {<*j*>^a}
        proof
          let b; assume b in union {<*i*>^^((k.(i+1))"I) where i: i < len k};
          then consider J such that
B1:       b in J in {<*i*>^^((k.(i+1))"I) where i: i < len k} by TARSKI:def 4;
          consider n being Nat such that
B2:       J = <*n*>^^((k.(n+1))"I) & n < len k by B1;
B4:       1 <= n+1 <= len k by B2,NAT_1:11,13;
          then n+1 in dom k by FINSEQ_3:25;
          then reconsider t = k.(n+1) as Element of Free(S,X) by FUNCT_1:102;
          per cases;
          suppose n = j;
            hence thesis by B1,B2,A9,A7,Th6;
          end;
          suppose n <> j;
            then n+1 <> j+1;
            then t is x-omitting by A6,A7,B4,FINSEQ_3:25;
            hence thesis by B1,B2;
          end;
        end;
        let b; assume b in {<*j*>^a};
        then b in <*j*>^^(C"I) in {<*i*>^^((k.(i+1))"I) where i: i < len k}
        by A7,A8,A9,Th6;
        hence thesis by TARSKI:def 4;
      end;
      then card Coim(o-term k,[x,s]) = 1 by A5,CARD_1:30;
      hence thesis by CONTEXT;
    end;
    assume o-term k is context of x;
    then card Coim(o-term k, [x,s]) = 1 by CONTEXT;
    then consider a such that
D1: Coim(o-term k, [x,s]) = {a} by CARD_2:42;
    a in (o-term k)"I by D1,TARSKI:def 1;
    then consider J such that
D2: a in J in {<*i*>^^((k.(i+1))"I): i < len k} by A5,TARSKI:def 4;
    consider i such that
D3: J = <*i*>^^((k.(i+1))"I) & i < len k by D2;
    consider p being Element of (k.(i+1))"I such that
D4: a = <*i*>^p & p in (k.(i+1))"I by D2,D3;
    take n = i+1;
    1 <= n <= len k by D3,NAT_1:11,13;
    hence n in dom k by FINSEQ_3:25;
    then reconsider kn = k.n as Element of Free(S,X) by FUNCT_1:102;
D6: {p} c= kn"I by D4,ZFMISC_1:31;
    J c= {a} = <*i*>^^{p} by A5,D1,D2,D4,Th6,ZFMISC_1:74;
    then kn"I c= {p} by D3,Th18;
    then kn"I = {p} by D6,XBOOLE_0:def 10;
    then card Coim(kn,[x,s]) = 1 by CARD_1:30;
    hence k.n is context of x by CONTEXT;
    let j;
    let t be Element of Free(S,X); assume
D7: j in dom k & j <> n & t = k.j;
    assume Coim(t,[x,s]) <> {};
    then consider c being object such that
D8: c in Coim(t,[x,s]) by XBOOLE_0:7;
    reconsider c as Node of t by D8,FUNCT_1:def 7;
    consider m being Nat such that
D9: j = 1+m by D7,FINSEQ_3:25,NAT_1:10;
    1+m <= len k by D7,D9,FINSEQ_3:25;
    then m < len k by NAT_1:13;
    then <*m*>^c in <*m*>^^(t"I) in
    {<*i*>^^((k.(i+1))"I) where i: i < len k} by D7,D8,D9;
    then <*m*>^c in {a} by A5,D1,TARSKI:def 4;
    then <*m*>^c = <*i*>^p by D4,TARSKI:def 1;
    then m = (<*m*>^c).1 = i by FINSEQ_1:41;
    hence contradiction by D7,D9;
  end;
