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 Th20:
  for S be locally_directed OrderSortedSign, X be non-empty
  ManySortedSet of S, t being Element of TS DTConOSA(X), s being Element of S
  holds ( ex y being Element of TS(DTConOSA X) st [y,s] in (PTClasses X).t )
  implies [t,s] in (PTClasses X).t
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 s being Element of S holds ( ex y being Element of
TS(DTConOSA X) st [y,s] in (PTClasses X).$1 ) implies [$1,s] 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
A4: ts in Args(o,PTA) and
A5: nt-tree ts = Den(o,PTA).ts and
    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;
A6: 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};
    reconsider ts1 = ts as Element of Args(o,PTA) by A4;
    set w = the_arity_of o;
A7: len the_arity_of o = len the_arity_of o;
    let s1 be Element of S;
A8: rng ts c= TS D by FINSEQ_1:def 4;
    dom F = TS D by FUNCT_2:def 1;
    then len x = len ts by A8,FINSEQ_2:29;
    then
A9: dom x = dom ts by FINSEQ_3:29;
A10: dom w = dom ts by A4,MSUALG_3:6;
A11: for y being Nat st y in dom x holds [ts1.y,w/.y] in x.y
    proof
      let y being Nat such that
A12:  y in dom x;
      ts1.y in rng ts1 by A9,A12,FUNCT_1:3;
      then reconsider t1 = ts1.y as Element of TS D by A8;
      ts1.y in SPTA.(w/.y) by A9,A10,A12,MSUALG_6:2;
      then [t1,w/.y] in F.t1 by Th19;
      hence thesis by A9,A12,FUNCT_1:13;
    end;
    assume ex y being Element of TS(DTConOSA X) st [y,s1] in F.(nt-tree ts);
    then consider y being Element of TS(DTConOSA X) such that
A13: [y,s1] in F.(nt-tree ts);
    consider o2 being OperSymbol of S, x2 being Element of Args(o2,PTA), s3
    being Element of S such that
A14: [y,s1] = [Den(o2,PTA).x2,s3] and
A15: 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
    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 A6,A13;
A16: s1 = s3 by A14,XTUPLE_0:1;
    the_result_sort_of o <= s3 by A3,A15,XTUPLE_0:1;
    hence thesis by A3,A5,A9,A10,A11,A6,A16,A7;
  end;
A17: for s being Symbol of D st s in Terminals D holds R3[root-tree s]
  proof
    let sy be Symbol of D;
    assume sy in Terminals D;
    then
A18: F.(root-tree sy) = @(sy) by 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 be Element of S;
    assume ex y being Element of TS(DTConOSA X) st [y,s1] in F.(root-tree sy);
    then consider y being Element of TS(DTConOSA X) such that
A19: [y,s1] in F.(root-tree sy);
    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 A18,A19;
    hence thesis by A19,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(A17,A1);
  hence thesis;
end;
