reserve c, c1, d for Real,
  k for Nat,
  n, m, N, n1, N1, N2, N3, N4, N5, M for Element of NAT,
  x for set;

theorem :: Properties, Part 3 (page 91; Problem 3.33)
  for f,g being eventually-nonnegative Real_Sequence holds max(Big_Oh(f)
  , Big_Oh(g)) = Big_Oh(max(f,g))
proof
  let f,g be eventually-nonnegative Real_Sequence;
  now
    let x be object;
    hereby
      assume x in max(Big_Oh(f), Big_Oh(g));
      then consider t being Element of Funcs(NAT,REAL) such that
A1:   x = t and
A2:   ex f9,g9 being Element of Funcs(NAT,REAL) st f9 in Big_Oh(f) &
      g9 in Big_Oh(g) & for n being Element of NAT holds t.n = max(f9.n, g9.n);
      consider f9,g9 being Element of Funcs(NAT,REAL) such that
A3:   f9 in Big_Oh(f) and
A4:   g9 in Big_Oh(g) and
A5:   for n being Element of NAT holds t.n = max(f9.n, g9.n) by A2;
      consider s being Element of Funcs(NAT, REAL) such that
A6:   s = g9 and
A7:   ex c,N st c > 0 & for n st n >= N holds s.n <= c*g.n & s.n >= 0 by A4;
      consider d,N2 such that
A8:   d > 0 and
A9:   for n st n >= N2 holds s.n <= d*g.n & s.n >= 0 by A7;
      consider r being Element of Funcs(NAT, REAL) such that
A10:  r = f9 and
A11:  ex c,N st c > 0 & for n st n >= N holds r.n <= c*f.n & r.n >= 0 by A3;
      consider c,N1 such that
A12:  c > 0 and
A13:  for n st n >= N1 holds r.n <= c*f.n & r.n >= 0 by A11;
      set e = max(c,d);
A14:  e > 0 by A12,XXREAL_0:25;
      reconsider N = max(N1,N2) as Element of NAT;
A15:  N >= N2 by XXREAL_0:25;
A16:  N >= N1 by XXREAL_0:25;
      now
        let n;
        assume
A17:    n >= N;
        then
A18:    n >= N1 by A16,XXREAL_0:2;
        then r.n <= c*f.n by A13;
        then f.n*c >= 0*c by A13,A18;
        then f.n >= 0 by A12,XREAL_1:68;
        then
A19:    c*f.n <= e*f.n by XREAL_1:64,XXREAL_0:25;
A20:    n >= N2 by A15,A17,XXREAL_0:2;
        then s.n <= d*g.n by A9;
        then g.n*d >= 0*d by A9,A20;
        then g.n >= 0 by A8,XREAL_1:68;
        then
A21:    d*g.n <= e*g.n by XREAL_1:64,XXREAL_0:25;
        s.n <= d*g.n by A9,A20;
        then
A22:    s.n <= e*g.n by A21,XXREAL_0:2;
        e*g.n <= e*max(f.n, g.n) by A14,XREAL_1:64,XXREAL_0:25;
        then
A23:    s.n <= e*max(f.n, g.n) by A22,XXREAL_0:2;
        r.n <= c*f.n by A13,A18;
        then
A24:    r.n <= e*f.n by A19,XXREAL_0:2;
        e*f.n <= e*max(f.n, g.n) by A14,XREAL_1:64,XXREAL_0:25;
        then r.n <= e*max(f.n, g.n) by A24,XXREAL_0:2;
        then max(r.n, s.n) <= e*max(f.n, g.n) by A23,XXREAL_0:28;
        then max(r.n, s.n) <= e*max(f,g).n by Def7;
        hence t.n <= e*max(f,g).n by A5,A10,A6;
        max(f9.n, g9.n) >= f9.n & f9.n >= 0 by A10,A13,A18,XXREAL_0:25;
        hence t.n >= 0 by A5;
      end;
      hence x in Big_Oh(max(f,g)) by A1,A14;
    end;
    assume x in Big_Oh(max(f,g));
    then consider t being Element of Funcs(NAT,REAL) such that
A25: x = t and
A26: ex c,N st c > 0 & for n st n >= N holds t.n <= c*max(f,g).n & t.n >= 0;
    consider c,N3 such that
A27: c > 0 and
A28: for n st n >= N3 holds t.n <= c*max(f,g).n & t.n >= 0 by A26;
    consider N1 being Nat such that
A29: for n being Nat st n >= N1 holds f.n >= 0 by Def2;
    consider N2 being Nat such that
A30: for n being Nat st n >= N2 holds g.n >= 0 by Def2;
    reconsider N = max(N3,max(N1,N2)) as Element of NAT
       by ORDINAL1:def 12;
    defpred P[Element of NAT,Real] means (f.$1 >= g.$1 or $1 < N implies $2 =
    t.$1) & (f.$1 < g.$1 & $1 >= N implies $2 = 0);
    defpred Q[Element of NAT,Real] means (f.$1 >= g.$1 & $1 >= N implies $2 =
    0) & (f.$1 < g.$1 or $1 < N implies $2 = t.$1);
A31: for x being Element of NAT ex y being Element of REAL st P[x,y]
    proof
      let n;
      per cases;
      suppose
        f.n >= g.n;
        hence thesis;
      end;
      suppose
A32:    f.n < g.n;
        thus thesis
        proof
          per cases;
          suppose
            n < N;
            hence thesis;
          end;
          suppose
A33:          n >= N;
            0 in REAL by XREAL_0:def 1;
            hence thesis by A32,A33;
          end;
        end;
      end;
    end;
    consider f9 being sequence of REAL such that
A34: for x being Element of NAT holds P[x,f9.x] from FUNCT_2:sch 3(A31
    );
A35: for x being Element of NAT ex y being Element of REAL st Q[x,y]
    proof
      let n;
      per cases;
      suppose
A36:    f.n >= g.n;
        thus thesis
        proof
          per cases;
          suppose
            n < N;
            hence thesis;
          end;
          suppose
A37:          n >= N;
            0 in REAL by XREAL_0:def 1;
            hence thesis by A36,A37;
          end;
        end;
      end;
      suppose
        f.n < g.n;
        hence thesis;
      end;
    end;
    consider g9 being sequence of REAL such that
A38: for x being Element of NAT holds Q[x,g9.x] from FUNCT_2:sch 3(A35
    );
A39: N >= N3 by XXREAL_0:25;
A40: now
      let n be Element of NAT;
      per cases;
      suppose
        n < N;
        then f9.n = t.n & g9.n = t.n by A34,A38;
        hence t.n = max(f9.n, g9.n);
      end;
      suppose
A41:    n >= N;
        then
A42:    n >= N3 by A39,XXREAL_0:2;
        thus t.n = max(f9.n, g9.n)
        proof
          per cases;
          suppose
A43:        f.n >= g.n;
A44:        t.n >= 0 by A28,A42;
            f9.n = t.n & g9.n = 0 by A34,A38,A41,A43;
            hence thesis by A44,XXREAL_0:def 10;
          end;
          suppose
A45:        f.n < g.n;
A46:        t.n >= 0 by A28,A42;
            f9.n = 0 & g9.n = t.n by A34,A38,A41,A45;
            hence thesis by A46,XXREAL_0:def 10;
          end;
        end;
      end;
    end;
A47: g9 is Element of Funcs(NAT,REAL) by FUNCT_2:8;
A48: N >= max(N1,N2) by XXREAL_0:25;
    max(N1,N2) >= N2 by XXREAL_0:25;
    then
A49: N >= N2 by A48,XXREAL_0:2;
    now
      let n;
      assume
A50:  n >= N;
      then n >= N3 by A39,XXREAL_0:2;
      then
A51:  t.n >= 0 & t.n <= c*max(f,g).n by A28;
      n >= N2 by A49,A50,XXREAL_0:2;
      then g.n >= 0 by A30;
      then
A52:  0*g.n <= c*g.n by A27;
      per cases;
      suppose
        f.n >= g.n;
        hence g9.n <= c*g.n & g9.n >= 0 by A38,A50,A52;
      end;
      suppose
A53:    f.n < g.n;
        then max(f.n,g.n) = g.n by XXREAL_0:def 10;
        then max(f,g).n = g.n by Def7;
        hence g9.n <= c*g.n & g9.n >= 0 by A38,A51,A53;
      end;
    end;
    then
A54: g9 in Big_Oh(g) by A27,A47;
A55: f9 is Element of Funcs(NAT,REAL) by FUNCT_2:8;
    max(N1,N2) >= N1 by XXREAL_0:25;
    then
A56: N >= N1 by A48,XXREAL_0:2;
    now
      let n;
      assume
A57:  n >= N;
      then n >= N3 by A39,XXREAL_0:2;
      then
A58:  t.n >= 0 & t.n <= c*max(f,g).n by A28;
      n >= N1 by A56,A57,XXREAL_0:2;
      then f.n >= 0 by A29;
      then
A59:  0*f.n <= c*f.n by A27;
      per cases;
      suppose
A60:    f.n >= g.n;
        then max(f.n,g.n) = f.n by XXREAL_0:def 10;
        then max(f,g).n = f.n by Def7;
        hence f9.n <= c*f.n & f9.n >= 0 by A34,A58,A60;
      end;
      suppose
        f.n < g.n;
        hence f9.n <= c*f.n & f9.n >= 0 by A34,A57,A59;
      end;
    end;
    then f9 in Big_Oh(f) by A27,A55;
    hence x in max(Big_Oh(f), Big_Oh(g)) by A25,A55,A47,A54,A40;
  end;
  hence thesis by TARSKI:2;
end;
