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;
