reserve n,k,k1,m,m1,n1,n2,l for Nat;
reserve r,r1,r2,p,p1,g,g1,g2,s,s1,s2,t for Real;
reserve seq,seq1,seq2 for Real_Sequence;
reserve Nseq for increasing sequence of NAT;
reserve x for set;
reserve X,Y for Subset of REAL;

theorem Th39:
  for seq ex Nseq st seq*Nseq is monotone
proof
  let seq;
  defpred X[Nat] means for m st $1<m holds seq.$1<seq.m;
  consider XN being Subset of NAT such that
A1: for n being Element of NAT holds n in XN iff X[n] from SUBSET_1:sch 3;
A2: now
    given k1 such that
A3: for n st n in XN holds n<=k1;
    set seq1=seq ^\(1+k1);
    defpred P[set,set,set] means for k,l st k=$2 & l=$3 holds k<l & seq1.l<=
    seq1.k & for m st k<m & seq1.m<=seq1.k holds l<=m;
A4: now
      let k;
A5:   k in NAT by ORDINAL1:def 12;
      assume k1<k;
      then not k in XN by A3;
      then consider m such that
A6:   k<m and
A7:   not seq.k<seq.m by A1,A5;
      take n=m;
      thus k<n by A6;
      thus seq.n<=seq.k by A7;
    end;
A8: now
      let k;
      (0 qua Nat)+k1<k+1+k1 by XREAL_1:8;
      then consider n such that
A9:   k+1+k1<n and
A10:   seq.n<=seq.(k+1+k1) by A4;
      consider m be Nat such that
A11:  n=k+1+k1+m by A9,NAT_1:10;
      reconsider m as Element of NAT by ORDINAL1:def 12;
      n-(1+k1)=k+(0 qua Nat)+m by A11;
      then consider n1 be Element of NAT such that
A12:  n1=n-(1+k1);
      seq.n<=seq.(k+(1+k1)) by A10;
      then
A13:  seq.n<=seq1.k by NAT_1:def 3;
      take l=n1;
      now
        assume not k<l;
        then n-(1+k1)+(1+k1)<=k+(1+k1) by A12,XREAL_1:6;
        hence contradiction by A9;
      end;
      hence k<l;
      n=l+(1+k1) by A12;
      hence seq1.l<=seq1.k by A13,NAT_1:def 3;
    end;
A14: for n being Nat for x being Element of NAT ex y being
    Element of NAT st P[n,x,y]
    proof
      let n be Nat,x be Element of NAT;
      defpred X[Nat] means x<$1 & seq1.$1<=seq1.x;
      ex n be Element of NAT st X[n] by A8;
      then
A15:  ex n be Nat st X[n];
      ex l be Nat st X[l] & for m be Nat st X[m] holds l <= m from NAT_1:
      sch 5(A15);
      then consider l be Nat such that
A16:  x<l & seq1.l<=seq1.x & for m be Nat st x<m & seq1.m<=seq1.x holds l <= m;
      take l;
      l in NAT by ORDINAL1:def 12;
      hence thesis by A16;
    end;
    consider f being sequence of NAT such that
    f.0 = 0 and
A17: for n being Nat holds P[n,f.n,f.(n+1)] from RECDEF_1:
    sch 2 (A14);
A18: dom f =NAT by FUNCT_2:def 1;
    rng f c= REAL;
    then reconsider f as Real_Sequence by A18,RELSET_1:4;
    for n holds f.n<f.(n+1) by A17;
    then reconsider f as increasing sequence of NAT by SEQM_3:def 6;
    consider Nseq such that
A19: seq1=seq*Nseq by VALUED_0:def 17;
    reconsider Nseq1=Nseq*f as increasing sequence of NAT;
    take Nseq1;
    now
      let n;
A20:   n in NAT & n+1 in NAT by ORDINAL1:def 12;
      seq1.(f.(n+1))<=seq1.(f.n) by A17;
      then (seq1*f).(n+1)<=seq1.(f.n) by FUNCT_2:15;
      then (seq*Nseq*f).(n+1)<=(seq1*f).n by A19,FUNCT_2:15,A20;
      then (seq*Nseq1).(n+1)<=(seq*Nseq*f).n by A19,RELAT_1:36;
      hence (seq*Nseq1).(n+1)<=(seq*Nseq1).n by RELAT_1:36;
    end;
    then seq*Nseq1 is non-increasing;
    hence seq*Nseq1 is monotone by SEQM_3:def 5;
  end;
  now
    defpred P[set,set,set] means for k,l being Element of NAT st k=$2 & l=$3
    holds l in XN & k<l & for m st m in XN & k<m holds l<=m;
    assume
A21: for l ex n st n in XN & not n<=l;
    then consider n1 such that
A22: n1 in XN and
    not n1<=0;
    reconsider O9=n1 as Element of NAT by ORDINAL1:def 12;
A23: for n being Nat for x being Element of NAT ex y being
    Element of NAT st P[n,x,y]
    proof
      let n be Nat,x be Element of NAT;
      defpred X[Nat] means $1 in XN & x<$1;
      ex n be Nat st X[n] by A21;
      then ex n be Element of NAT st X[n];
      then
A24:  ex n be Nat st X[n];
      ex l be Nat st X[l] & for m be Nat st X[m] holds l <= m from NAT_1:
      sch 5(A24);
      then consider l be Nat such that
A25:  l in XN & x<l & for m be Nat st m in XN & x<m holds l <= m;
      reconsider l as Element of NAT by ORDINAL1:def 12;
      take l;
      thus thesis by A25;
    end;
    consider f being sequence of NAT such that
A26: f.0 = O9 and
A27: for n being Nat holds P[n,f.n,f.(n+1)] from RECDEF_1:
    sch 2 (A23);
A28: dom f =NAT by FUNCT_2:def 1;
    rng f c= REAL;
    then reconsider f as Real_Sequence by A28,RELSET_1:4;
A29: for n holds n is Element of NAT & f.n is Element of NAT
       by ORDINAL1:def 12;
A30: now
      let n;
      f.n is Element of NAT & f.(n+1) is Element of NAT by A29;
      hence f.n<f.(n+1) by A27;
    end;
A31: now
      defpred X[Nat] means f.$1 in XN;
      let n;
A32:  now
        let k such that
        X[k];
        f.k is Element of NAT & f.(k+1) is Element of NAT by A29;
        hence X[k+1] by A27;
      end;
A33:  X[0] by A22,A26;
      thus for n holds X[n] from NAT_1:sch 2(A33,A32);
    end;
    reconsider f as increasing sequence of NAT by A30,SEQM_3:def 6;
    take Nseq=f;
    now
      let n;
A34:   n in NAT by ORDINAL1:def 12;
      Nseq.n in XN & Nseq.n<Nseq.(n+1) by A31,A30;
      then seq.(Nseq.n)<seq.(Nseq.(n+1)) by A1;
      then (seq*Nseq).n<seq.(Nseq.(n+1)) by FUNCT_2:15,A34;
      hence (seq*Nseq).n<(seq*Nseq).(n+1) by FUNCT_2:15;
    end;
    then seq*Nseq is increasing;
    hence seq*Nseq is monotone by SEQM_3:def 5;
  end;
  hence thesis by A2;
end;
