reserve i for Nat,
  j for Element of NAT,
  X,Y,x,y,z for set;
reserve C for initialized ConstructorSignature,
  s for SortSymbol of C,
  o for OperSymbol of C,
  c for constructor OperSymbol of C;
reserve a,b for expression of C, an_Adj C;
reserve t, t1,t2 for expression of C, a_Type C;
reserve p for FinSequence of QuasiTerms C;
reserve e for expression of C;
reserve a,a9 for expression of C, an_Adj C;
reserve q for pure expression of C, a_Type C,
  A for finite Subset of QuasiAdjs C;
reserve T for quasi-type of C;

theorem Th120:
  for S being non void Signature for X being ManySortedSet of the carrier of S
  st X is with_missing_variables
  holds
  NonTerminals DTConMSA X = [:the carrier' of S,{the carrier of S}:] &
  Terminals DTConMSA X = Union coprod X
proof
  let S be non void Signature;
  let X be ManySortedSet of the carrier of S such that
A1: X is with_missing_variables;
  set D = DTConMSA X,
  A = [:the carrier' of S,{the carrier of S}:] \/
  Union (coprod (X qua ManySortedSet of the carrier of S));
A2: Union(coprod X) misses [:the carrier' of S,{the carrier of S}:]
  by MSAFREE:4;
A3: (Terminals D) misses (NonTerminals D) by DTCONSTR:8;
  thus
  NonTerminals DTConMSA X c= [:the carrier' of S,{the carrier of S}:]
  by MSAFREE:6;
  thus
A4: [:the carrier' of S,{the carrier of S}:] c= NonTerminals D
  proof
    let o,x2 be object;
    assume
A5: [o,x2] in [:the carrier' of S,{the carrier of S}:];
    then
A6: x2 in {the carrier of S} by ZFMISC_1:87;
    reconsider o as OperSymbol of S by A5,ZFMISC_1:87;
A7: the carrier of S = x2 by A6,TARSKI:def 1;
    then reconsider xa = [o,the carrier of S]
    as Element of (the carrier of D) by A5,XBOOLE_0:def 3;
    set O = the_arity_of o;
    defpred P[object,object] means
    $2 in A &
    (X.(O.$1) <> {} implies $2 in coprod(O.$1,X)) &
    (X.(O.$1) = {} implies ex o being OperSymbol of S st
    $2 = [o,the carrier of S] & the_result_sort_of o = O.$1);
A8: for a be object st a in Seg len O ex b be object st P[a,b]
    proof
      let a be object;
      assume a in Seg len O;
      then
A9:   a in dom O by FINSEQ_1:def 3;
      then
A10:  O.a in rng O by FUNCT_1:def 3;
      then reconsider s = O.a as SortSymbol of S;
      per cases;
      suppose X.(O.a) is non empty;
        then consider x be object such that
A11:    x in X.(O.a) by XBOOLE_0:def 1;
        take y = [x,O.a];
A12:    y in coprod(O.a,X) by A10,A11,MSAFREE:def 2;
A13:    O.a in rng O by A9,FUNCT_1:def 3;
        dom coprod(X) = the carrier of S by PARTFUN1:def 2;
        then (coprod(X)).(O.a) in rng coprod(X) by A13,FUNCT_1:def 3;
        then coprod(O.a,X) in rng coprod(X) by A13,MSAFREE:def 3;
        then y in Union coprod(X) by A12,TARSKI:def 4;
        hence thesis by A10,A11,MSAFREE:def 2,XBOOLE_0:def 3;
      end;
      suppose
A14:    X.(O.a) = {};
        then consider o being OperSymbol of S such that
A15:    the_result_sort_of o = s by A1,Th114;
        take y = [o,the carrier of S];
        the carrier of S in {the carrier of S} by TARSKI:def 1;
        then y in [:the carrier' of S,{the carrier of S}:] by ZFMISC_1:87;
        hence thesis by A14,A15,XBOOLE_0:def 3;
      end;
    end;
    consider b be Function such that
A16: dom b = Seg len O &
    for a be object st a in Seg len O holds P[a,b.a]
   from CLASSES1:sch 1(A8);
    reconsider b as FinSequence by A16,FINSEQ_1:def 2;
    rng b c= A
    proof
      let a be object;
      assume a in rng b;
      then ex c being object st c in dom b & b.c = a by FUNCT_1:def 3;
      hence thesis by A16;
    end;
    then reconsider b as FinSequence of A by FINSEQ_1:def 4;
    reconsider b as Element of A* by FINSEQ_1:def 11;
A17: len b = len O by A16,FINSEQ_1:def 3;
    now
      let c be set;
      assume
A18:  c in dom b;
      then
A19:  P[c,b.c] by A16;
      dom O = Seg len O by FINSEQ_1:def 3;
      then
A20:  O.c in rng O by A16,A18,FUNCT_1:def 3;
      dom coprod(X) = the carrier of S by PARTFUN1:def 2;
      then (coprod(X)).(O.c) in rng coprod(X) by A20,FUNCT_1:def 3;
      then coprod(O.c,X) in rng coprod(X) by A20,MSAFREE:def 3;
      then X.(O.c) <> {} implies b.c in Union coprod(X) by A19,TARSKI:def 4;
      hence b.c in [:the carrier' of S,{the carrier of S}:] implies
      for o1 being OperSymbol of S st [o1,the carrier of S] = b.c
      holds the_result_sort_of o1 = O.c
      by A2,A19,XBOOLE_0:3,XTUPLE_0:1;
      assume
A21:  b.c in Union (coprod X);
      now
        assume X.(O.c) = {};
        then
A22:    ex o being OperSymbol of S st ( b.c = [o,the carrier of S])
        &( the_result_sort_of o = O.c) by A16,A18;
        the carrier of S in {the carrier of S} by TARSKI:def 1;
        then b.c in [:the carrier' of S,{the carrier of S}:]
        by A22,ZFMISC_1:87;
        hence contradiction by A2,A21,XBOOLE_0:3;
      end;
      hence b.c in coprod(O.c,X) by A16,A18;
    end;
    then [xa,b] in REL(X) by A17,MSAFREE:5;
    then xa ==> b;
    hence thesis by A7;
  end;
  thus Terminals D c= Union coprod X
  proof
    let x be object;
    assume
A23: x in Terminals D;
    then not x in [:the carrier' of S,{the carrier of S}:] by A3,A4,XBOOLE_0:3;
    hence thesis by A23,XBOOLE_0:def 3;
  end;
  thus thesis by MSAFREE:6;
end;
