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 Th18:
  for S be locally_directed OrderSortedSign, X be non-empty
  ManySortedSet of S, o be OperSymbol of S, x be FinSequence of TS DTConOSA(X)
  holds LeastSorts x <= the_arity_of o iff x in Args(o,ParsedTermsOSA(X))
proof
  let S be locally_directed OrderSortedSign, X be non-empty ManySortedSet of S
  , o be OperSymbol of S, x be FinSequence of TS DTConOSA(X);
  set PTA = ParsedTermsOSA(X), D = DTConOSA(X), w = the_arity_of o, LSx =
  LeastSorts x;
  reconsider SPTA = the Sorts of PTA as OrderSortedSet of S;
A1: dom LSx = dom x by Def13;
  hereby
    assume
A2: LeastSorts x <= w;
    then
A3: len LSx = len w;
    then
A4: dom LSx = dom w by FINSEQ_3:29;
A5: for k be Nat st k in dom x holds x.k in (the Sorts of PTA).(w/.k)
    proof
      let k be Nat such that
A6:   k in dom x;
      consider t2 being Element of TS DTConOSA(X) such that
A7:   t2 = x.k and
A8:   LSx.k = LeastSort t2 by A6,Def13;
      reconsider wk = (w/.k) as Element of S;
      (w/.k) = w.k by A1,A4,A6,PARTFUN1:def 6;
      then LeastSort t2 <= wk by A1,A2,A6,A8;
      then
A9:   SPTA.(LeastSort t2) c= SPTA.wk by OSALG_1:def 16;
      t2 in (the Sorts of PTA).(LeastSort t2) by Def12;
      hence thesis by A7,A9;
    end;
    len x = len w by A1,A3,FINSEQ_3:29;
    hence x in Args(o,PTA) by A5,MSAFREE2:5;
  end;
  assume
A10: x in Args(o,PTA);
  then
A11: dom x = dom w by MSUALG_6:2;
  hence len LSx = len w by A1,FINSEQ_3:29;
  let i be set such that
A12: i in dom LSx;
  reconsider k = i as Nat by A12;
  i in dom w by A11,A12,Def13;
  then
A13: x.k in (the Sorts of PTA).(w/.k) by A10,MSUALG_6:2;
  i in dom x by A12,Def13;
  then
A14: ex t2 being Element of TS D st t2 = x.k & LSx.k = LeastSort t2 by Def13;
  let s1,s2 be Element of S such that
A15: s1 = LSx.i and
A16: s2 = w.i;
  w/.k = w.k by A1,A11,A12,PARTFUN1:def 6;
  hence thesis by A15,A16,A14,A13,Def12;
end;
