reserve S for non empty non void ManySortedSign,
  V for non-empty ManySortedSet of the carrier of S,
  A for non-empty MSAlgebra over S,
  X for non empty Subset of S-Terms V,
  t for Element of X;
reserve S for non empty non void ManySortedSign,
  A for non-empty finite-yielding MSAlgebra over S,
  V for Variables of A,
  X for SetWithCompoundTerm of S,V;

theorem Th21:
  for s being State of X-Circuit A for f being CompatibleValuation of s
  for t being Term of S,V st t in Subtrees X holds
  Following(s, 1+height dom t) is_stable_at t &
  Following(s, 1+height dom t).t = t@(f,A)
proof
  let q be State of X-Circuit A;
  let f be CompatibleValuation of q;
A1: X-CircuitStr = ManySortedSign(#Subtrees X,
    [:the carrier' of S,{the carrier of S}:]-Subtrees X,
    [:the carrier' of S,{the carrier of S}:]-ImmediateSubtrees X,
    incl([:the carrier' of S,{the carrier of S}:]-Subtrees X)#);
  defpred P[finite DecoratedTree] means $1 in Subtrees X implies
  Following(q, 1+height dom $1) is_stable_at $1 &
  Following(q, 1+height dom $1).$1 = $1@(f,A);
A2: for s being SortSymbol of S, v being Element of V.s holds
  P [ root-tree [ v, s ] ]
  proof
    let s being SortSymbol of S, v being Element of V.s;
    assume
A3: root-tree [v,s] in Subtrees X;
    then
A4: root-tree [v,s] in InputVertices (X-CircuitStr) by Th11;
    hence Following(q, 1+height dom root-tree [v,s])
    is_stable_at root-tree [v,s] by FACIRC_1:18;
    reconsider t = root-tree [v,s] as c-Term of A, V by MSATERM:8;
A5: t is Term of S, V by MSATERM:4;
    q is_stable_at root-tree [v,s] by A4,FACIRC_1:18;
    hence Following(q,1+height dom root-tree [v,s]).root-tree [v,s]
    = q.root-tree [v,s]
      .= f.s.v by A3,Def8
      .= (v-term A)@f by MSATERM:42
      .= t@f by MSATERM:def 4
      .= (root-tree [v,s])@(f, A) by A5,Def7;
  end;
A6: for o being OperSymbol of S, p being ArgumentSeq of Sym(o,V)
  st for t being Term of S,V st t in rng p holds P[t] holds
  P[[o,the carrier of S]-tree p]
  proof
    let o being OperSymbol of S, p being ArgumentSeq of Sym(o,V) such that
A7: for t being Term of S,V st t in rng p & t in Subtrees X holds
    Following(q, 1+height dom t) is_stable_at t &
    Following(q,1+height dom t).t = t@(f, A) and
A8: [o,the carrier of S]-tree p in Subtrees X;
    consider tt being Element of X, n being Node of tt such that
A9: [o,the carrier of S]-tree p = tt|n by A8,TREES_9:19;
A10: <*>NAT in (dom tt)|n by TREES_1:22;
    n^{} = n by FINSEQ_1:34;
    then tt.n = (tt|n).{} by A10,TREES_2:def 10
      .= [o,the carrier of S] by A9,TREES_4:def 4;
    then tt.n in [:the carrier' of S,{the carrier of S}:] by ZFMISC_1:106;
    then reconsider g = [o,the carrier of S]-tree p as Gate of X-CircuitStr
    by A9,TREES_9:24;
A11: the_result_sort_of g = g;
A12: g.{} = [o,the carrier of S] by TREES_4:def 4;
    g = (g.{})-tree the_arity_of g by Th12;
    then
A13: the_arity_of g = p by TREES_4:15;
A14: rng the_arity_of g c= Subtrees X by FINSEQ_1:def 4;
A15: dom ([o,the carrier of S]-tree p) = tree doms p by TREES_4:10;
    now
      let x being set;
      assume
A16:  x in rng the_arity_of g;
      then reconsider t = x as Element of Subtrees X by A14;
      reconsider t as Term of S,V by A1,Th4;
      consider z being object such that
A17:  z in dom p and
A18:  t = p.z by A13,A16,FUNCT_1:def 3;
A19:  z in dom doms p by A17,A18,FUNCT_6:22;
      (doms p).z = dom t by A17,A18,FUNCT_6:22;
      then dom t in rng doms p by A19,FUNCT_1:def 3;
      then height dom t < height tree doms p by TREES_3:78;
      then 1+height dom t <= height tree doms p by NAT_1:13;
      then consider i being Nat such that
A20:  height tree doms p = (1+height dom t)+i by NAT_1:10;
      reconsider i as Element of NAT by ORDINAL1:def 12;
      Following(q,height dom ([o,the carrier of S]-tree p))
      = Following(Following(q,1+height dom t),i) by A15,A20,FACIRC_1:13;
      hence Following(q,height dom ([o,the carrier of S]-tree p))
      is_stable_at x by A7,A13,A16,FACIRC_1:17;
    end;
    then Following Following(q,height dom ([o,the carrier of S]-tree p))
    is_stable_at [o,the carrier of S]-tree p by A11,FACIRC_1:19;
    hence Following(q,1+height dom ([o,the carrier of S]-tree p))
    is_stable_at [o,the carrier of S]-tree p by FACIRC_1:12;
    reconsider t = Sym(o,V)-tree p as c-Term of A,V by MSATERM:27;
A21: Sym(o,(the Sorts of A) (\/) V) = [o, the carrier of S] by MSAFREE:def 9;
A22: Sym(o,V) = [o,the carrier of S] by MSAFREE:def 9;
A23: t = [o,the carrier of S]-tree p by MSAFREE:def 9;
    deffunc f(set) = Following(q,height dom t).(p.$1);
    consider vp being FinSequence such that
A24: len vp = len p and
A25: for i being Nat st i in dom vp holds vp.i = f(i) from FINSEQ_1:sch 2;
A26: dom vp = Seg len p by A24,FINSEQ_1:def 3;
A27: dom p = Seg len p by FINSEQ_1:def 3;
A28: dom p = dom the_arity_of o by MSATERM:22;
    now
      let i be Nat;
      assume
A29:  i in dom p;
      then reconsider t = p.i as Term of S,V by MSATERM:22;
      reconsider t9 = t as c-Term of A,V by MSATERM:27;
      take t9;
      the_sort_of t = the_sort_of t9 by Th1;
      hence t9 = p.i & the_sort_of t9 = (the_arity_of o).i by A29,MSATERM:23;
    end;
    then reconsider p9 = p as ArgumentSeq of o,A,V by A28,MSATERM:24;
    now
      let i be Nat;
      assume
A30:  i in dom p;
      let t being c-Term of A,V;
      assume
A31:  t = p.i;
      then
A32:  t in rng p by A30,FUNCT_1:def 3;
      then reconsider tt = t as Element of Subtrees X by A13,A14;
      reconsider tt as Term of S,V by A1,Th4;
A33:  Following(q, 1+height dom t) is_stable_at tt by A7,A32;
A34:  Following(q, 1+height dom t).tt = tt@(f, A) by A7,A32;
A35:  vp.i = Following(q, height dom ([o,the carrier of S]-tree p)).t
      by A23,A25,A26,A27,A30,A31;
A36:  i in dom doms p by A30,A31,FUNCT_6:22;
      (doms p).i = dom t by A30,A31,FUNCT_6:22;
      then dom t in rng doms p by A36,FUNCT_1:def 3;
      then height dom t < height tree doms p by TREES_3:78;
      then 1+height dom t <= height tree doms p by NAT_1:13;
      then consider j being Nat such that
A37:  height tree doms p = (1+height dom t)+j by NAT_1:10;
      reconsider j as Element of NAT by ORDINAL1:def 12;
      Following(q,height dom ([o,the carrier of S]-tree p))
      = Following(Following(q,1+height dom t),j) by A15,A37,FACIRC_1:13;
      then Following(q,height dom ([o,the carrier of S]-tree p)).t
      = Following(q,1+height dom t).t by A33;
      hence vp.i = t@f by A34,A35,Def7;
    end;
    then
    A38: (
Sym(o,(the Sorts of A) (\/) V)-tree p9 qua c-Term of A,V)@f = Den( o,A).vp
    by A24,MSATERM:43;
    now
A39:  rng p c= the carrier of X-CircuitStr by A13,FINSEQ_1:def 4;
      dom Following(q, height dom t) = the carrier of X-CircuitStr by
CIRCUIT1:3;
      hence dom (Following(q, height dom t)*p) = dom p by A39,RELAT_1:27;
      let z be object;
      assume
A40:  z in Seg len p;
      then reconsider i = z as Element of NAT;
      vp.i = Following(q, height dom t).(p.i) by A25,A26,A40;
      hence vp.z = (Following(q, height dom t)*p).z by A27,A40,FUNCT_1:13;
    end;
    then
A41: vp = Following(q, height dom t)*the_arity_of g by A13,A26,A27,FUNCT_1:2;
    Den(g, X-Circuit A) = Den(o,A) by A12,Th16;
    then Den(o,A).vp = (Following Following(q,height dom t)).t
    by A11,A23,A41,FACIRC_1:10;
    hence Following(q,1+height dom ([o,the carrier of S]-tree p)).
    ([o,the carrier of S]-tree p) = t@f by A21,A22,A38,FACIRC_1:12
      .= ([o,the carrier of S]-tree p)@(f, A) by A22,Def7;
  end;
  thus for t being Term of S,V holds P[t] from MSATERM:sch 1(A2,A6);
end;
