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 Th19:
  for S be locally_directed OrderSortedSign, X be non-empty
  ManySortedSet of S, t being Element of TS DTConOSA(X) holds ( for s being
  Element of S holds t in (the Sorts of ParsedTermsOSA(X)).s iff [t,s] in (
PTClasses X).t ) & for s being Element of S, y being Element of TS(DTConOSA X)
  holds [y,s] in (PTClasses X).t implies [t,s] in (PTClasses X).y
proof
  let S be locally_directed OrderSortedSign, X be non-empty ManySortedSet of S
  , t be Element of TS DTConOSA(X);
  set PTA = ParsedTermsOSA(X), SPTA = the Sorts of PTA, D = DTConOSA(X), C =
  bool [:TS(D), the carrier of S:], F = PTClasses X;
  defpred R1[set] means for s being Element of S holds $1 in SPTA.s iff [$1,s]
  in F.$1;
  defpred R2[set] means for s being Element of S, y being Element of TS(D)
  holds [y,s] in F.$1 implies [$1,s] in F.y;
  defpred P[DecoratedTree of the carrier of D] means R1[$1] & R2[$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 P[t]
  holds P[nt-tree ts]
  proof
    let nt be Symbol of D, ts be FinSequence of TS(D) such that
A2: nt ==> roots ts and
A3: for t being DecoratedTree of the carrier of D st t in rng ts
    holds R1[t] & R2[t];
    consider o being OperSymbol of S such that
A4: nt = [o,the carrier of S] and
A5: ts in Args(o,PTA) and
A6: nt-tree ts = Den(o,PTA).ts and
A7: 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;
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};
    reconsider ts1 = ts as Element of Args(o,PTA) by A5;
    set w = the_arity_of o;
A9: 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 A9,FINSEQ_2:29;
    then
A10: dom x = dom ts by FINSEQ_3:29;
A11: dom w = dom ts by A5,MSUALG_3:6;
A12: for y being Nat st y in dom x holds [ts1.y,w/.y] in x.y
    proof
      let y being Nat such that
A13:  y in dom x;
A14:  ts1.y in rng ts1 by A10,A13,FUNCT_1:3;
      then reconsider t1 = ts1.y as Element of TS D by A9;
      ts1.y in SPTA.(w/.y) by A10,A11,A13,MSUALG_6:2;
      then [t1,w/.y] in F.t1 by A3,A14;
      hence thesis by A10,A13,FUNCT_1:13;
    end;
    thus R1[nt-tree ts]
    proof
      let s1 be Element of S;
      hereby
        assume nt-tree ts in SPTA.s1;
        then
A15:    the_result_sort_of o <= s1 by A7;
        len the_arity_of o = len the_arity_of o;
        hence [nt-tree ts,s1] in F.(nt-tree ts) by A4,A6,A10,A11,A12,A8,A15;
      end;
      assume [nt-tree ts,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
A16:  [nt-tree ts,s1] = [Den(o2,PTA).x2,s3] and
A17:  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 A8;
      s1 = s3 by A16,XTUPLE_0:1;
      then
A18:  SPTA.(the_result_sort_of o2) c= SPTA.s1 by A17,OSALG_1:def 16;
A19:  Den(o2,PTA).x2 in SPTA.(the_result_sort_of o2) by MSUALG_9:18;
      nt-tree ts = Den(o2,PTA).x2 by A16,XTUPLE_0:1;
      hence thesis by A19,A18;
    end;
    thus R2[nt-tree ts]
    proof
      let s1 be Element of S, y be Element of TS(D);
      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
A20:  [y,s1] = [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;
      consider w3 being Element of (the carrier of S)* such that
A23:  dom w3 = dom x and
A24:  for y being Nat st y in dom x holds [x2.y,w3/.y] in x.y by A22;
      consider o1 being OperSymbol of S such that
A25:  nt = [o1,the carrier of S] and
A26:  o1 ~= o2 and
A27:  len the_arity_of o1 = len the_arity_of o2 and
A28:  the_result_sort_of o1 <= s3 and
A29:  the_result_sort_of o2 <= s3 by A21;
A30:  y = Den(o2,PTA).x2 by A20,XTUPLE_0:1;
      reconsider x3 = x2 as FinSequence of TS D by Th13;
      reconsider xy = F * x3 as FinSequence of C;
A31:  OSSym(o2,X) ==> roots x2 by Th13;
      then consider o3 being OperSymbol of S such that
A32:  OSSym(o2,X) = [o3,the carrier of S] and
      x3 in Args(o3,PTA) and
A33:  OSSym(o2,X)-tree x3 = Den(o3,PTA).x3 and
      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;
      o2 = o3 by A32,XTUPLE_0:1;
      then
A34:  F.y = @(OSSym(o2,X),xy) by A30,A31,A33,Def21
        .= {[Den(o4,PTA).x4,s4] where o4 is OperSymbol of S, x4 is Element
of Args(o4,PTA), s4 is Element of S : ( ex o1 being OperSymbol of S st OSSym(o2
,X) = [o1,the carrier of S] & o1 ~= o4 & len the_arity_of o1 = len the_arity_of
o4 & the_result_sort_of o1 <= s4 & the_result_sort_of o4 <= s4 ) & ex w4 being
Element of (the carrier of S)* st dom w4 = dom xy & for y being Nat st y in dom
      xy holds [x4.y,w4/.y] in xy.y};
A35:  rng x3 c= TS D by FINSEQ_1:def 4;
      then rng x3 c= dom F by FUNCT_2:def 1;
      then len xy = len x3 by FINSEQ_2:29;
      then
A36:  dom x3 = dom xy by FINSEQ_3:29;
A37:  o1 = o by A4,A25,XTUPLE_0:1;
      then
A38:  dom the_arity_of o2 = dom the_arity_of o by A27,FINSEQ_3:29;
      then
A39:  dom w3 = dom xy by A10,A11,A23,A36,MSUALG_3:6;
A40:  dom x2 = dom x by A10,A11,A38,MSUALG_3:6;
A41:  for y being Nat st y in dom xy holds [ts1.y,w3/.y] in xy.y
      proof
        let y be Nat such that
A42:    y in dom xy;
A43:    ts1.y in rng ts1 by A10,A23,A39,A42,FUNCT_1:3;
        x2.y in rng x3 by A36,A42,FUNCT_1:3;
        then reconsider t1 = ts1.y,t2 = x2.y as Element of TS D by A9,A35,A43;
        [x2.y,w3/.y] in x.y by A24,A36,A40,A42;
        then [x2.y,w3/.y] in F.(ts1.y) by A10,A23,A39,A42,FUNCT_1:13;
        then [t1,w3/.y] in F.(t2) by A3,A43;
        hence thesis by A42,FUNCT_1:12;
      end;
A44:  the_result_sort_of o2 <= s1 by A20,A29,XTUPLE_0:1;
      the_result_sort_of o <= s1 by A20,A28,A37,XTUPLE_0:1;
      hence thesis by A6,A26,A27,A37,A39,A41,A34,A44;
    end;
  end;
A45: for s being Symbol of D st s in Terminals D holds P[root-tree s]
  proof
    let sy be Symbol of D such that
A46: sy in Terminals D;
    reconsider sy1 = sy as Terminal of D by A46;
    consider s being Element of S, x being set such that
A47: x in X.s and
A48: sy = [x,s] by A46,Th4;
A49: F.(root-tree sy) = @(sy) by A46,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};
    root-tree sy1 in {a where a is Element of TS(DTConOSA(X)): (ex s1
being Element of S, x be object
st s1 <= s & x in X.s1 & a = root-tree [x,s1]) or
ex o be OperSymbol of S st [o,the carrier of S] = a.{} & the_result_sort_of o
    <= s} by A47,A48;
    then
A50: root-tree sy1 in SPTA.s by Th9;
    thus R1[root-tree sy]
    proof
      let s1 be Element of S;
      hereby
        assume root-tree sy in SPTA.s1;
        then s <= s1 by A47,A48,Th10;
        hence [root-tree sy,s1] in F.(root-tree sy) by A47,A48,A49;
      end;
      assume [root-tree sy,s1] in F.(root-tree sy);
      then consider s3 being Element of S such that
A51:  [root-tree sy,s1] = [root-tree sy,s3] and
A52:  ex s2 be Element of S, x be set st x in X.s2 & sy = [x,s2] & s2
      <= s3 by A49;
A53:  s1 = s3 by A51,XTUPLE_0:1;
      consider s2 be Element of S, x2 be set such that
      x2 in X.s2 and
A54:  sy = [x2,s2] and
A55:  s2 <= s3 by A52;
      s2 = s by A48,A54,XTUPLE_0:1;
      then SPTA.s c= SPTA.s1 by A53,A55,OSALG_1:def 16;
      hence thesis by A50;
    end;
    thus R2[root-tree sy]
    proof
      let s1 be Element of S, y be Element of TS(D);
      assume
A56:  [y,s1] in F.(root-tree sy);
      then
      ex s2 being Element of S st [y,s1] = [root-tree sy,s2] & ex s3 be
      Element of S, x be set st x in X.s3 & sy = [x,s3] & s3 <= s2 by A49;
      then y = root-tree sy by XTUPLE_0:1;
      hence thesis by A56;
    end;
  end;
  for t being DecoratedTree of the carrier of D st t in TS(D) holds P[t]
  from DTCONSTR:sch 7(A45,A1);
  hence thesis;
end;
