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;

theorem Th51:
  for p being DTree-yielding FinSequence holds
  [c, the carrier of C]-tree p is expression of C
  iff len p = len the_arity_of c & p in (QuasiTerms C)*
proof
  set o = c;
A1: o <> * by Def11;
A2: o <> non_op by Def11;
  let p be DTree-yielding FinSequence;
  set V = (MSVars C) (\/) ((the carrier of C) --> {0});
A3: the Sorts of Free(C, MSVars C) = C-Terms(MSVars C, V) by MSAFREE3:24;
  thus
  now
    assume
A4: [o, the carrier of C]-tree p is expression of C;
    then
A5: [o, the carrier of C]-tree p is Term of C, V by MSAFREE3:8;
    then
A6: p is ArgumentSeq of Sym(o,V) by MSATERM:1;
    hence len p = len the_arity_of o by MSATERM:22;
    reconsider q = p as ArgumentSeq of Sym(o,V) by A5,MSATERM:1;
A7: the_sort_of ((Sym(o,V))-tree q) = the_result_sort_of o by MSATERM:20;
A8: variables_in ((Sym(o,V))-tree q) c= MSVars C by A4,MSAFREE3:27;
    (C-Terms(MSVars C,V)).the_result_sort_of o =
    {t where t is Term of C,V: the_sort_of t = the_result_sort_of o &
    variables_in t c= MSVars C} by MSAFREE3:def 5;
    then Sym(o,V)-tree p in (C-Terms(MSVars C,V)).the_result_sort_of o
    by A7,A8;
    then
A9: rng p c= Union (C-Terms(MSVars C,V)) by A6,MSAFREE3:19;
    rng p c= QuasiTerms C
    proof
      let a be object;
      assume
A10:  a in rng p;
      then reconsider ta = a as expression of C by A9,MSAFREE3:24;
      consider i being object such that
A11:  i in dom p and
A12:  a = p.i by A10,FUNCT_1:def 3;
      reconsider i as Nat by A11;
      reconsider t = p.i as Term of C, V by A6,A11,MSATERM:22;
A13:  (the Arity of C).o in {a_Term}* by A1,A2,Def9;
A14:  dom p = dom the_arity_of o by A6,MSATERM:22;
A15:  the_arity_of o is FinSequence of {a_Term} by A13,FINSEQ_1:def 11;
A16:  (the_arity_of o).i in rng the_arity_of o by A11,A14,FUNCT_1:def 3;
      rng the_arity_of o c= {a_Term C} by A15,FINSEQ_1:def 4;
      then (the_arity_of o).i = a_Term C by A16,TARSKI:def 1;
      then
A17:  the_sort_of t = a_Term C by A6,A11,MSATERM:23;
      t = ta by A12;
      then variables_in t c= MSVars C by MSAFREE3:27;
      then t in {T where T is Term of C,V: the_sort_of T = a_Term C &
      variables_in T c= MSVars C} by A17;
      then t in (C-Terms(MSVars C,V)).a_Term C by MSAFREE3:def 5;
      hence thesis by A12,MSAFREE3:23;
    end;
    then p is FinSequence of QuasiTerms C by FINSEQ_1:def 4;
    hence p in (QuasiTerms C)* by FINSEQ_1:def 11;
  end;
  assume
A18: len p = len the_arity_of o;
  assume
A19: p in (QuasiTerms C)*;
  Free(C, MSVars C) = (FreeMSA V)|(C-Terms(MSVars C, V)) by MSAFREE3:25;
  then the Sorts of Free(C, MSVars C) is ManySortedSubset of
  the Sorts of FreeMSA V by MSUALG_2:def 9;
  then the Sorts of Free(C, MSVars C) c= the Sorts of FreeMSA V
  by PBOOLE:def 18;
  then
A20: QuasiTerms C c= (the Sorts of FreeMSA V).a_Term C;
A21: p is FinSequence of QuasiTerms C by A19,FINSEQ_1:def 11;
  then
A22: rng p c= QuasiTerms C by FINSEQ_1:def 4;
  now
    let i be Nat;
    assume
A23: i in dom p;
    then p.i in rng p by FUNCT_1:def 3;
    then
A24: p.i in QuasiTerms C by A22;
    then reconsider t = p.i as expression of C;
A25: (the Arity of C).o in {a_Term}* by A1,A2,Def9;
A26: dom p = dom the_arity_of o by A18,FINSEQ_3:29;
A27: the_arity_of o is FinSequence of {a_Term} by A25,FINSEQ_1:def 11;
A28: (the_arity_of o).i in rng the_arity_of o by A23,A26,FUNCT_1:def 3;
    rng the_arity_of o c= {a_Term C} by A27,FINSEQ_1:def 4;
    then
A29: (the_arity_of o).i = a_Term C by A28,TARSKI:def 1;
    reconsider T = t as Term of C,V by MSAFREE3:8;
    take T;
    thus T = p.i;
    T in (the Sorts of FreeMSA V).a_Term C by A20,A24;
    then T in FreeSort(V, a_Term C) by MSAFREE:def 11;
    hence the_sort_of T = (the_arity_of o).i by A29,MSATERM:def 5;
  end;
  then
A30: p is ArgumentSeq of Sym(o,V) by A18,MSATERM:24;
A31: dom the Sorts of Free(C, MSVars C) = the carrier of C by PARTFUN1:def 2;
  rng p c= Union (C-Terms(MSVars C, V)) by A3,A21,FINSEQ_1:def 4;
  then Sym(o,V)-tree p in (C-Terms(MSVars C, V)).the_result_sort_of o
  by A30,MSAFREE3:19;
  hence thesis by A3,A31,CARD_5:2;
end;
