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;
reserve
  S9 for sufficiently_rich non empty non void ManySortedSign,
  s9 for SortSymbol of S9,
  o9 for s9-dependent OperSymbol of S9,
  X9 for non-trivial ManySortedSet of the carrier of S9,
  x9 for (Element of X9.s9);
reserve h1 for x-constant Homomorphism of Free(S,X), T,
  h2 for y-constant Homomorphism of Free(S,Y), Q;
reserve
  s2 for s1-reachable SortSymbol of S,
  g1 for Translation of Free(S,Y),s1,s2,
  g for Translation of Free(S,X),s1,s2;

theorem Th118:
  X is non-trivial implies
  for xi being Element of dom C st C.xi = [x,s]
  holds the_sort_of t = s implies C-sub t = C with-replacement (xi,t)
  proof
    assume ZZ: X is non-trivial;
    let xi be Element of dom C;
    assume Z0: C.xi = [x,s];
    assume Z1: the_sort_of t = s;
    defpred P[Element of Free(S,X)] means for C being context of x st C = $1
    for xi being Element of dom C st C.xi = [x,s]
    holds C-sub t = C with-replacement (xi,t);
A1: P[x-term]
    proof
      let C such that
A2:   C = x-term;
      let xi be Element of dom C;
      xi in {{}} by A2,TREES_1:29;
      then xi = <*>NAT;
      hence thesis by Z1,A2,Th41;
    end;
A3: for o being OperSymbol of S
    for w being Element of Args(o, Free(S,X))
    st w is x-context_including
    holds P[x-context_in w] implies
    for C being context of x st C = o-term w holds P[C]
    proof
      let o be OperSymbol of S;
      let w be Element of Args(o, Free(S,X));
      assume Z2: w is x-context_including;
      assume Z3: P[x-context_in w];
      let C be context of x;
      assume Z4: C = o-term w;
      let D be context of x;
      assume Z5: D = C;
      let xi be Element of dom D;
      assume Z6: D.xi = [x,s];
      dom D = tree doms w by Z4,Z5,TREES_4:10;
      then per cases by TREES_3:def 15;
      suppose xi = {};
        then D.xi = [o,the carrier of S] by Z4,Z5,TREES_4:def 4;
        then s in the carrier of S = s by Z6,XTUPLE_0:1;
        hence thesis;
      end;
      suppose ex i being Nat, r being FinSequence st i < len doms w &
        r in (doms w).(i+1) & xi = <*i*>^r;
        then consider i being Nat, r being FinSequence such that
A4:     i < len doms w & r in (doms w).(i+1) & xi = <*i*>^r;
A5:     len doms w = len w by TREES_3:38;
        then
AB:     1 <= i+1 <= len w by A4,NAT_1:12,13;
        then
A6:     i+1 in dom w by FINSEQ_3:25;
        then
A7:     w/.(i+1) = w.(i+1) in rng w & (doms w).(i+1) = dom (w.(i+1))
        by PARTFUN1:def 6,FUNCT_6:def 2,FUNCT_1:def 3;
        then reconsider r as Element of dom (w/.(i+1)) by A4;
A8:     D.xi = (w/.(i+1)).r & [x,s] in {[x,s]}
        by Z4,Z5,A4,A5,A7,TARSKI:def 1,TREES_4:12;
        then w/.(i+1) is not x-omitting by Z6,FUNCT_1:def 7;
        then
AA:     x-context_pos_in w = i+1 by Z2,AB,Th72,FINSEQ_3:25;
        then
A9:     x-context_in w = w/.(i+1) by Z2,A7,Th71;
        the_sort_of (x-context_in w) =
        (the_arity_of o)/.(x-context_pos_in w) by A6,AA,A9,Th4A;
        then
        reconsider u = w+*(x-context_pos_in w, (x-context_in w)-sub t)
        as Element of Args(o,Free(S,X)) by MSUALG_6:7;
A11:    D-sub t = o-term u by ZZ,Z1,Z2,Z4,Z5,Th43;
        xi in dom D; then
        i < len w & xi in tree doms w &
        x-context_in w = w.(i+1) &
        u = w+*(i+1,(x-context_in w) with-replacement (r, t))
        by Z4,Z5,A4,AA,A9,Z3,Z6,A8,A6,TREES_3:38,TREES_4:10,PARTFUN1:def 6;
        hence thesis by A11,Z4,Z5,A4,Th123;
      end;
    end;
    P[C] from ContextInd(A1,A3);
    hence C-sub t = C with-replacement (xi,t) by Z0;
  end;
