
theorem
for f being real-valued FinSequence, n being Nat
 st card f = n^2+1 & f is one-to-one
  ex g being real-valued FinSubsequence
   st g c= f & card g >= n+1 & (g is increasing or g is decreasing)
proof
  let f be real-valued FinSequence, n be Nat such that
A1: card f = n^2+1 and
A2: f is one-to-one;
  set cP = f;
  defpred P[object,object] means
  ex i,j being Nat, r, s being Real
   st $1 = [i,r] & $2 = [j,s] & i<j & r<s;
  consider iP being Relation of f, f such that
A3: for x, y being object holds [x,y] in iP iff x in f & y in f & P[x,y]
    from RELSET_1:sch 1;
    set P = RelStr (# cP, iP #);
A4: dom f = Seg len f by FINSEQ_1:def 3;
A5: P is antisymmetric proof
     let x, y be object such that
        x in the carrier of P and y in the carrier of P and
    A6: [x,y] in the InternalRel of P and
    A7: [y,x] in the InternalRel of P;
        consider i,j being Nat, r, s being Real such that
    A8: x = [i,r] and
    A9: y = [j,s] and
    A10: i<j & r<s by A6,A3;
        consider j1,i1 being Nat, s1, r1 being Real such that
    A11: y = [j1,s1] and
    A12: x = [i1,r1] and
    A13: j1<i1 & s1<r1 by A7,A3;
        i = i1 & j = j1 by A8,A9,A11,A12,XTUPLE_0:1;
     hence x = y by A10,A13;
    end;
 P is transitive proof
     let x, y, z be object such that
    A14: x in the carrier of P and y in the carrier of P and
    A15: z in the carrier of P and
    A16: [x,y] in the InternalRel of P and
    A17: [y,z] in the InternalRel of P;
        consider ix,jy being Nat, rx, sy being Real such that
    A18: x = [ix,rx] and
    A19: y = [jy,sy] and
    A20: ix<jy & rx<sy by A16,A3;
        consider iy,jz being Nat, ry, sz being Real such that
    A21: y = [iy,ry] and
    A22: z = [jz,sz] and
    A23: iy<jz & ry<sz by A17,A3;
     jy = iy & sy = ry by A19,A21,XTUPLE_0:1;
         then ix<jz & rx<sz by A20,A23,XXREAL_0:2;
        hence [x,z] in the InternalRel of P by A18,A22,A14,A15,A3;
    end;
    then reconsider P as finite antisymmetric transitive RelStr by A5;
A24: card P = card f;
   per cases by A24,A1,Th55;
   suppose ex C being Clique of P st card C >= n+1;
      then consider C being Clique of P such that
   A25: card C >= n+1;
       set g = C;
       reconsider g as Subset of f;
       reconsider g as Function;
       dom g c= Seg len f proof
         let x be object;
         assume x in dom g;
         then consider y being object such that
       A26: [x,y] in g by XTUPLE_0:def 12;
         x in dom f by A26,XTUPLE_0:def 12;
        hence thesis by FINSEQ_1:def 3;
       end;
       then reconsider g as FinSubsequence by FINSEQ_1:def 12;
       reconsider g as real-valued FinSubsequence;
       take g;
       thus g c= f;
       thus card g >= n+1 by A25;
       g is increasing proof
         let e1, e2 be ExtReal such that
       A27: e1 in dom g and
       A28: e2 in dom g and
       A29: e1 < e2;
       A30: [e1,g.e1] in g by A27,FUNCT_1:1;
       A31: [e2,g.e2] in g by A28,FUNCT_1:1;
           then
reconsider p1 = [e1,g.e1], p2 = [e2,g.e2] as Element of P by A30;
       A32: p1 <> p2 by A29,XTUPLE_0:1;
         per cases by A30,A31,A32,Th6;
         suppose p1 <= p2;
           then [p1,p2] in iP;
           then consider i,j being Nat, r, s being Real such that
         A33: p1 = [i,r] and
         A34: p2 = [j,s] and
         A35: i<j & r<s by A3;
          j = e2 & s = g.e2 by A34,XTUPLE_0:1;
           hence g.e1 < g.e2 by A35,A33,XTUPLE_0:1;
         end;
         suppose p2 <= p1;
           then [p2,p1] in iP;
           then consider i,j being Nat, r, s being Real such that
         A36: p2 = [i,r] and
         A37: p1 = [j,s] and
         A38: i<j & r<s by A3;
             i = e2 & j = e1 by A36,A37,XTUPLE_0:1;
           hence g.e1 < g.e2 by A29,A38;
         end;
       end;
     hence thesis;
   end;
   suppose ex A being StableSet of P st card A >= n+1;
      then consider A being StableSet of P such that
   A39: card A >= n+1;
       set g = A;
       reconsider g as Subset of f;
       reconsider g as Function;
   A40: dom g c= Seg len f proof
         let x be object;
         assume x in dom g;
         then consider y being object such that
       A41: [x,y] in g by XTUPLE_0:def 12;
         x in dom f by A41,XTUPLE_0:def 12;
        hence thesis by FINSEQ_1:def 3;
       end;
       then reconsider g as FinSubsequence by FINSEQ_1:def 12;
       reconsider g as real-valued FinSubsequence;
       take g;
       thus g c= f;
       thus card g >= n+1 by A39;
       g is decreasing proof
         let e1, e2 be ExtReal such that
       A42: e1 in dom g and
       A43: e2 in dom g and
       A44: e1 < e2;
       A45: [e1,g.e1] in g by A42,FUNCT_1:1;
       A46: [e2,g.e2] in g by A43,FUNCT_1:1;
           then
reconsider p1 = [e1,g.e1], p2 = [e2,g.e2] as Element of P by A45;
       A47: p1 <> p2 by A44,XTUPLE_0:1;
        g.e1 = f.e1 & g.e2 = f.e2 by A42,A43,GRFUNC_1:2;
       then A48: g.e1 <> g.e2 by A4,A40,A42,A43,A44,A2;
           reconsider i = e1, j = e2 as Nat by A42,A43;
           reconsider r = g.e1, s = g.e2 as Real;
       A49: p1 = [i,r] & p2 = [j,s];
         per cases by A48,XXREAL_0:1;
         suppose g.e1 < g.e2;
           then [p1,p2] in iP by A45,A3,A44,A49;
           then p1 <= p2;
           hence g.e1 > g.e2 by A45,A46,A47,Def2;
         end;
         suppose g.e1 > g.e2;
           hence thesis;
         end;
       end;
     hence thesis;
   end;
end;
