reserve x,y,z for set;

theorem Th28:
  for S being non void Signature for X being non-empty
ManySortedSet of the carrier of S for t being Term of S,X holds variables_in t
  c= X
proof
  let S be non void Signature;
  let X be non-empty ManySortedSet of the carrier of S;
  defpred P[DecoratedTree] means S variables_in $1 c= X;
  let t be Term of S,X;
A1: for o being OperSymbol of S, p being ArgumentSeq of Sym(o,X) st for t
being Term of S,X st t in rng p holds P[t] holds P[[o,the carrier of S]-tree p]
  proof
    let o be OperSymbol of S, p be ArgumentSeq of Sym(o, X) such that
A2: for t being Term of S,X st t in rng p holds S variables_in t c= X;
    thus S variables_in ([o, the carrier of S]-tree p) c= X
    proof
      let s be object;
      assume
A3:   s in the carrier of S;
      let x be object;
      assume x in (S variables_in ([o, the carrier of S]-tree p)).s;
      then consider t being DecoratedTree such that
A4:   t in rng p and
A5:   x in (S variables_in t).s by A3,Th11;
      consider i being object such that
A6:   i in dom p and
A7:   t = p.i by A4,FUNCT_1:def 3;
      reconsider i as Nat by A6;
      reconsider t = p.i as Term of S,X by A6,MSATERM:22;
      S variables_in t c= X by A2,A4,A7;
      then (S variables_in t).s c= X.s by A3;
      hence thesis by A5,A7;
    end;
  end;
A8: for s being SortSymbol of S, v being Element of X.s holds P[root-tree [v
  ,s]]
  proof
    let s be SortSymbol of S, x be Element of X.s;
    thus S variables_in root-tree [x,s] c= X
    proof
      let y be object;
      assume y in the carrier of S;
A9:   y <> s implies (S variables_in root-tree [x,s]).y = {} by Th10;
      (S variables_in root-tree [x,s]).s = {x} by Th10;
      hence thesis by A9;
    end;
  end;
  for t being Term of S,X holds P[t] from MSATERM:sch 1(A8,A1);
  hence thesis;
end;
