reserve n,m for Nat;

theorem
  for f being real-valued FinSequence,r1,r2 being Real st f=<*r1,r2*> holds
  max f=max(r1,r2) & max_p f=IFEQ(r1,max(r1,r2),1,2)
proof
  let f be real-valued FinSequence,r1,r2 be Real;
  assume
A1: f=<*r1,r2*>;
  then
A2: len f=2 by FINSEQ_1:44;
  then
A3: f.2<=f.(max_p f) by Th1;
A4: f.1=r1 by A1;
A5: (max_p f) in dom f by A2,Def1;
  then
A6: 1<= (max_p f) by FINSEQ_3:25;
A7: (max_p f)<=len f by A5,FINSEQ_3:25;
A8: f.2=r2 by A1;
A9: f.1<=f.(max_p f) by A2,Th1;
  now
    per cases;
    case
      r1>=r2;
      then
A10:  max(r1,r2)<=max f by A4,A9,XXREAL_0:def 10;
      now
        per cases;
        case
          max_p f<len f;
          then max_p f <1+1 by A1,FINSEQ_1:44;
          then max_p f <=1 by NAT_1:13;
          then
A11:      max_p f=1 by A6,XXREAL_0:1;
          then max f <=max(r1,r2) by A4,XXREAL_0:25;
          then max f=max(r1,r2) by A10,XXREAL_0:1;
          hence thesis by A4,A11,FUNCOP_1:def 8;
        end;
        case
          max_p f>=len f;
          then
A12:      max_p f=2 by A2,A7,XXREAL_0:1;
          then max f <=max(r1,r2) by A8,XXREAL_0:25;
          then
A13:      max f=max(r1,r2) by A10,XXREAL_0:1;
          1 in dom f by A2,FINSEQ_3:25;
          then r1<>r2 by A2,A4,A8,A12,Def1;
          hence thesis by A8,A12,A13,FUNCOP_1:def 8;
        end;
      end;
      hence thesis;
    end;
    case
      r1<r2;
      then
A14:  max(r1,r2)<=max f by A8,A3,XXREAL_0:def 10;
      now
        per cases;
        case
          max_p f<len f;
          then max_p f <1+1 by A1,FINSEQ_1:44;
          then max_p f <=1 by NAT_1:13;
          then
A15:      max_p f=1 by A6,XXREAL_0:1;
          then max f <=max(r1,r2) by A4,XXREAL_0:25;
          then max f=max(r1,r2) by A14,XXREAL_0:1;
          hence thesis by A4,A15,FUNCOP_1:def 8;
        end;
        case
          max_p f>=len f;
          then
A16:      max_p f=2 by A2,A7,XXREAL_0:1;
          then max f <=max(r1,r2) by A8,XXREAL_0:25;
          then
A17:      max f=max(r1,r2) by A14,XXREAL_0:1;
          1 in dom f by A2,FINSEQ_3:25;
          then r1<>r2 by A2,A4,A8,A16,Def1;
          hence thesis by A8,A16,A17,FUNCOP_1:def 8;
        end;
      end;
      hence thesis;
    end;
  end;
  hence thesis;
end;
