reserve S for OrderSortedSign;
reserve S for OrderSortedSign,
  X for ManySortedSet of S,
  o for OperSymbol of S ,
  b for Element of ([:the carrier' of S,{the carrier of S}:] \/ Union (coprod X
  ))*;
reserve x for set;

theorem Th21:
  for S be locally_directed OrderSortedSign, X be non-empty
ManySortedSet of S, x,y being Element of TS DTConOSA(X), s1,s2 being Element of
  S st s1 <= s2 & x in (the Sorts of ParsedTermsOSA(X)).s1 & y in (the Sorts of
ParsedTermsOSA(X)).s1 holds [y,s1] in (PTClasses X).x iff [y,s2] in (PTClasses
  X).x
proof
  let S be locally_directed OrderSortedSign, X be non-empty ManySortedSet of S;
  set D = DTConOSA(X), PTA = ParsedTermsOSA(X), C = bool [:TS(D), the carrier
  of S:], SPTA = the Sorts of PTA, F = PTClasses X;
  defpred R3[set] means for s1,s2 being Element of S, y being Element of TS(
  DTConOSA X) st s1 <= s2 & $1 in SPTA.s1 & y in SPTA.s1 holds ([y,s1] in (
  PTClasses X).$1 iff [y,s2] in (PTClasses X).$1);
A1: for nt being Symbol of D, ts being FinSequence of TS(D) st nt ==> roots
  ts & for t being DecoratedTree of the carrier of D st t in rng ts holds R3[t]
  holds R3[nt-tree ts]
  proof
    let nt be Symbol of D, ts be FinSequence of TS(D) such that
A2: nt ==> roots ts and
    for t being DecoratedTree of the carrier of D st t in rng ts holds R3[ t];
    consider o being OperSymbol of S such that
A3: nt = [o,the carrier of S] and
    ts in Args(o,PTA) and
    nt-tree ts = Den(o,PTA).ts and
A4: for s1 being Element of S holds nt-tree ts in (the Sorts of PTA).
    s1 iff the_result_sort_of o <= s1 by A2,Th12;
    reconsider x = F * ts as FinSequence of C;
    let s1,s2 be Element of S, y be Element of TS D such that
A5: s1 <= s2 and
A6: nt-tree ts in SPTA.s1 and
A7: y in SPTA.s1;
A8: F.(nt-tree ts) = @(nt,x) by A2,Def21
      .= {[Den(o2,ParsedTermsOSA(X)).x2,s3] where o2 is OperSymbol of S, x2
is Element of Args(o2,ParsedTermsOSA(X)), s3 is Element of S : ( ex o1 being
OperSymbol of S st nt = [o1,the carrier of S] & o1 ~= o2 & len the_arity_of o1
= len the_arity_of o2 & the_result_sort_of o1 <= s3 & the_result_sort_of o2 <=
    s3 ) & ex w3 being Element of (the carrier of S)* st dom w3 = dom x & for y
    being Nat st y in dom x holds [x2.y,w3/.y] in x.y};
    hereby
      reconsider s21 = s2 as Element of S;
      assume [y,s1] in F.(nt-tree ts);
      then consider
      o2 being OperSymbol of S, x2 being Element of Args(o2,PTA), s3
      being Element of S such that
A9:   [y,s1] = [Den(o2,PTA).x2,s3] and
A10:  ex o1 being OperSymbol of S st nt = [o1,the carrier of S] & o1
~= o2 & len the_arity_of o1 = len the_arity_of o2 & the_result_sort_of o1 <= s3
      & the_result_sort_of o2 <= s3 and
A11:  ex w3 being Element of (the carrier of S)* st dom w3 = dom x &
      for y being Nat st y in dom x holds [x2.y,w3/.y] in x.y by A8;
      consider o1 being OperSymbol of S such that
A12:  nt = [o1,the carrier of S] and
A13:  o1 ~= o2 and
A14:  len the_arity_of o1 = len the_arity_of o2 and
A15:  the_result_sort_of o1 <= s3 and
A16:  the_result_sort_of o2 <= s3 by A10;
A17:  y = Den(o2,PTA).x2 by A9,XTUPLE_0:1;
A18:  s1 = s3 by A9,XTUPLE_0:1;
      then
A19:  the_result_sort_of o2 <= s21 by A5,A16,ORDERS_2:3;
      the_result_sort_of o1 <= s21 by A5,A18,A15,ORDERS_2:3;
      hence [y,s2] in F.(nt-tree ts) by A8,A11,A17,A12,A13,A14,A19;
    end;
    assume [y,s2] in F.(nt-tree ts);
    then consider
    o2 being OperSymbol of S, x2 being Element of Args(o2,PTA), s3
    being Element of S such that
A20: [y,s2] = [Den(o2,PTA).x2,s3] and
A21: ex o1 being OperSymbol of S st nt = [o1,the carrier of S] & o1 ~=
o2 & len the_arity_of o1 = len the_arity_of o2 & the_result_sort_of o1 <= s3 &
    the_result_sort_of o2 <= s3 and
A22: ex w3 being Element of (the carrier of S)* st dom w3 = dom x &
    for y being Nat st y in dom x holds [x2.y,w3/.y] in x.y by A8;
    reconsider x3 = x2 as FinSequence of TS D by Th13;
    OSSym(o2,X) ==> roots x2 by Th13;
    then consider o3 being OperSymbol of S such that
A23: OSSym(o2,X) = [o3,the carrier of S] and
    x3 in Args(o3,PTA) and
A24: OSSym(o2,X)-tree x3 = Den(o3,PTA).x3 and
A25: for s2 being Element of S holds OSSym(o2,X)-tree x3 in (the Sorts
    of PTA).s2 iff the_result_sort_of o3 <= s2 by Th12;
A26: y = Den(o2,PTA).x2 by A20,XTUPLE_0:1;
    o2 = o3 by A23,XTUPLE_0:1;
    then
A27: the_result_sort_of o2 <= s1 by A7,A26,A24,A25;
    consider o1 being OperSymbol of S such that
A28: nt = [o1,the carrier of S] and
A29: o1 ~= o2 and
A30: len the_arity_of o1 = len the_arity_of o2 and
    the_result_sort_of o1 <= s3 and
    the_result_sort_of o2 <= s3 by A21;
    the_result_sort_of o <= s1 by A4,A6;
    then the_result_sort_of o1 <= s1 by A3,A28,XTUPLE_0:1;
    hence thesis by A8,A22,A26,A28,A29,A30,A27;
  end;
A31: for s being Symbol of D st s in Terminals D holds R3[root-tree s]
  proof
    let sy be Symbol of D such that
A32: sy in Terminals D;
    reconsider sy1 = sy as Terminal of D by A32;
A33: F.(root-tree sy) = @(sy) by A32,Def21
      .= {[root-tree sy,s1] where s1 is Element of S: ex s2 be Element of S,
    x be set st x in X.s2 & sy = [x,s2] & s2 <= s1};
    let s1,s2 be Element of S, y be Element of TS D such that
A34: s1 <= s2 and
A35: root-tree sy in SPTA.s1 and
    y in SPTA.s1;
    SPTA.s1 c= SPTA.s2 by A34,OSALG_1:def 16;
    then
A36: [root-tree sy1,s2] in F.(root-tree sy) by A35,Th19;
    hereby
      assume [y,s1] in F.(root-tree sy);
      then
      ex s3 being Element of S st [y,s1] = [root-tree sy,s3] & ex s2 be
      Element of S, x be set st x in X.s2 & sy = [x,s2] & s2 <= s3 by A33;
      hence [y,s2] in F.(root-tree sy) by A36,XTUPLE_0:1;
    end;
    assume [y,s2] in F.(root-tree sy);
    then
A37: ex s3 being Element of S st [y,s2] = [root-tree sy,s3] & ex s4 be
    Element of S, x be set st x in X.s4 & sy = [x,s4] & s4 <= s3 by A33;
    [root-tree sy1,s1] in F.(root-tree sy) by A35,Th19;
    hence thesis by A37,XTUPLE_0:1;
  end;
  for t being DecoratedTree of the carrier of D st t in TS(D) holds R3[t]
  from DTCONSTR:sch 7(A31,A1);
  hence thesis;
end;
