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 Th7:
  for S be OrderSortedSign, X be non-empty ManySortedSet of S, o be
OperSymbol of S, p be FinSequence of TS(DTConOSA(X)) holds OSSym(o,X) ==> roots
  p iff p in ((ParsedTerms X)# * (the Arity of S)).o
proof
  let S be OrderSortedSign, X be non-empty ManySortedSet of S, o be OperSymbol
  of S, p be FinSequence of TS(DTConOSA(X));
  set D = DTConOSA(X), ar = the_arity_of o;
  set r = roots p, OU = [:the carrier' of S,{the carrier of S}:] \/ Union (
  coprod X);
A1: dom p = dom r by TREES_3:def 18;
  thus OSSym(o,X) ==> roots p implies p in ((ParsedTerms X)# * (the Arity of S
  )).o
  proof
    assume OSSym(o,X) ==> roots p;
    then
A2: [[o,the carrier of S],roots p] in OSREL(X) by LANG1:def 1;
    then reconsider
    r = roots p as Element of ([:the carrier' of S,{the carrier of
    S}:] \/ Union (coprod X))* by ZFMISC_1:87;
A3: dom p = dom r by TREES_3:def 18;
A4: for n be Nat st n in dom p holds p.n in ParsedTerms(X,ar/.n)
    proof
      let n be Nat;
      set s = ar/.n;
A5:   rng r c= [:the carrier' of S,{the carrier of S}:] \/ Union (coprod
      X) by FINSEQ_1:def 4;
A6:   rng p c= TS D by FINSEQ_1:def 4;
      assume
A7:   n in dom p;
      then consider T be DecoratedTree such that
A8:   T = p.n and
A9:   r.n = T.{} by TREES_3:def 18;
      p.n in rng p by A7,FUNCT_1:def 3;
      then reconsider T as Element of TS(D) by A8,A6;
A10:  r.n in rng r by A3,A7,FUNCT_1:def 3;
      per cases by A5,A10,XBOOLE_0:def 3;
      suppose
A11:    r.n in [:the carrier' of S,{the carrier of S}:];
        then consider
        o1 being Element of the carrier' of S, x2 being Element of {
        the carrier of S} such that
A12:    r.n = [o1,x2] by DOMAIN_1:1;
A13:    x2 = the carrier of S by TARSKI:def 1;
        then the_result_sort_of o1 <= ar/.n by A2,A3,A7,A11,A12,Th2;
        then ex o be OperSymbol of S st [o,the carrier of S] = T.{} &
        the_result_sort_of o <= s by A9,A12,A13;
        hence thesis by A8;
      end;
      suppose
A14:    r.n in Union (coprod X);
        then reconsider t = r.n as Terminal of D by Th3;
A15:    T = root-tree t by A9,DTCONSTR:9;
        consider i being Element of S such that
A16:    i <= ar/.n and
A17:    r.n in coprod(i,X) by A2,A3,A7,A14,Th2;
        ex a be set st a in X.i & r.n = [a,i] by A17,MSAFREE:def 2;
        hence thesis by A8,A16,A15;
      end;
    end;
A18: Seg len ar = dom ar by FINSEQ_1:def 3;
A19: dom r = Seg len r by FINSEQ_1:def 3;
    len r = len ar by A2,Th2;
    hence thesis by A3,A19,A18,A4,Th6;
  end;
  assume
A20: p in ((ParsedTerms X)# * (the Arity of S)).o;
A21: dom r = Seg len r by FINSEQ_1:def 3;
  reconsider r as FinSequence of OU;
  reconsider r as Element of OU* by FINSEQ_1:def 11;
A22: Union (coprod X) misses [:the carrier' of S,{the carrier of S}:] by
MSAFREE:4;
A23: for x be set st x in dom r holds (r.x in [:the carrier' of S,{the
carrier of S}:] implies for o1 be OperSymbol of S st [o1,the carrier of S] = r.
x holds the_result_sort_of o1 <= ar/.x) & (r.x in Union (coprod X) implies ex i
  being Element of S st i <= ar/.x & r.x in coprod(i,X))
  proof
    let x be set;
    assume
A24: x in dom r;
    then reconsider n = x as Nat;
    set s = ar/.n;
    p.n in ParsedTerms(X,s) by A20,A1,A24,Th6;
    then consider a be Element of TS D such that
A25: a = p.n and
A26: (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;
A27: ex T be DecoratedTree st T = p.n & r.n = T.{} by A1,A24,TREES_3:def 18;
    thus r.x in [:the carrier' of S,{the carrier of S}:] implies for o1 be
OperSymbol of S st [o1,the carrier of S] = r.x holds the_result_sort_of o1 <=
    ar/.x
    proof
      assume
A28:  r.x in [:the carrier' of S,{the carrier of S}:];
A29:  now
        given s1 being Element of S, y be set such that
        s1 <= s and
A30:    y in X.s1 and
A31:    a = root-tree [y,s1];
A32:    [y,s1] in coprod(s1,X) by A30,MSAFREE:def 2;
        dom coprod(X) = the carrier of S by PARTFUN1:def 2;
        then (coprod(X)).s1 in rng coprod(X) by FUNCT_1:def 3;
        then
A33:    coprod(s1,X) in rng coprod(X) by MSAFREE:def 3;
        r.x = [y,s1] by A25,A27,A31,TREES_4:3;
        then r.x in union rng coprod(X) by A32,A33,TARSKI:def 4;
        then r.x in Union (coprod X) by CARD_3:def 4;
        hence contradiction by A22,A28,XBOOLE_0:3;
      end;
      let o1 be OperSymbol of S;
      assume [o1,the carrier of S] = r.x;
      hence thesis by A25,A26,A27,A29,XTUPLE_0:1;
    end;
    assume
A34: r.x in Union (coprod X);
    now
      given o1 be OperSymbol of S such that
A35:  [o1,the carrier of S] = a.{} and
      the_result_sort_of o1 <= s;
      the carrier of S in {the carrier of S} by TARSKI:def 1;
      then [o1,the carrier of S] in [:the carrier' of S,{the carrier of S}:]
      by ZFMISC_1:87;
      hence contradiction by A22,A25,A27,A34,A35,XBOOLE_0:3;
    end;
    then consider s1 being Element of S, y be set such that
A36: s1 <= s and
A37: y in X.s1 and
A38: a = root-tree [y,s1] by A26;
    take s1;
    r.x = [y,s1] by A25,A27,A38,TREES_4:3;
    hence thesis by A36,A37,MSAFREE:def 2;
  end;
  dom p = dom ar by A20,Th6;
  then len r = len ar by A1,A21,FINSEQ_1:def 3;
  then [[o,the carrier of S],r] in OSREL X by A23,Th2;
  hence thesis by LANG1:def 1;
end;
