
theorem Th24:
  for A being Universal_Algebra, B being Subset of A ex C being Subset of A
  st C = union the set of all B|^n where n is Element of NAT &
  C is opers_closed
proof
  let A be Universal_Algebra;
  let B be Subset of A;
  set X = the set of all B|^n where n is Element of NAT;
  set C = union X;
A1: union bool the carrier of A = the carrier of A by ZFMISC_1:81;
  X c= bool the carrier of A
  proof
    let x be object;
    assume x in X;
    then ex n being Element of NAT st x = B|^n;
    hence thesis;
  end;
  then reconsider C as Subset of A by A1,ZFMISC_1:77;
  take C;
  thus
  C = union the set of all B|^n where n is Element of NAT;
  let o be Element of Operations A;
  consider s being object such that
A2: s in dom the charact of A and
A3: o = (the charact of A).s by FUNCT_1:def 3;
  reconsider s as OperSymbol of A by A2;
A4: dom o = (arity o)-tuples_on the carrier of A by MARGREL1:22;
  let p be FinSequence of C;
  assume len p = arity o;
  then p is Element of dom Den(s,A) by A3,A4,FINSEQ_2:92;
  then
A5: p in dom Den(s,A);
  defpred P[set,Nat] means $1 in B|^$2;
A6: rng p is finite;
A7: for x being Element of A st x in rng p ex n being Nat st P[x,n]
  proof
    let x be Element of A;
    assume
A8: x in rng p;
    rng p c= C by FINSEQ_1:def 4;
    then consider Y being set such that
A9: x in Y and
A10: Y in X by A8,TARSKI:def 4;
    consider n being Element of NAT such that
A11: Y = B|^n by A10;
    take n;
    thus thesis by A9,A11;
  end;
A12: for x being Element of A for n,m being Nat st P[x,n] & n <= m holds P[x,m]
  proof
    let x be Element of A;
    let n,m be Nat;
    assume
A13: P[x,n];
    assume n <= m;
    then B|^n c= B|^m by Th21;
    hence thesis by A13;
  end;
  consider n being Nat such that
A14: for x being Element of A st x in rng p holds P[x,n] from MaxVal(A6,A7
  ,A12
  );
  rng p c= B|^n
  by A14;
  then Den(s,A).p in {Den(a,A).r where a is (Element of dom the charact of A
  ), r is Element of (the carrier of A)*: r in dom Den(a,A) & rng r c= B|^n}
  by A5;
  then o.p in (B|^n)\/{Den(a,A).r where a is (Element of dom the charact of A),
  r is Element of (the carrier of A)*: r in dom Den(a,A) & rng r c= B|^n} &
  n+1 in NAT by A3,XBOOLE_0:def 3;
  then
A15: o.p in B|^(n+1) by Th19;
  B|^(n+1) in X;
  hence thesis by A15,TARSKI:def 4;
end;
