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 :: Threshold Rule for Big_Theta (page 87)
  for f,t being positive Real_Sequence holds t in Big_Theta(f) iff ex c,
  d st c > 0 & d > 0 & for n holds d*f.n <= t.n & t.n <= c*f.n
proof
  let f,t be positive Real_Sequence;
A1: Big_Theta(f) = { s where s is Element of Funcs(NAT, REAL) : ex c,d,N st
  c > 0 & d > 0 & for n st n >= N holds d*f.n <= s.n & s.n <= c*f.n } by Th27;
  hereby
    assume t in Big_Theta(f);
    then consider s being Element of Funcs(NAT, REAL) such that
A2: s = t and
A3: ex c,d,N st c > 0 & d > 0 & for n st n >= N holds d*f.n <= s.n & s
    .n <= c*f.n by A1;
    consider c,d,N such that
A4: c > 0 and
A5: d > 0 and
A6: for n st n >= N holds d*f.n <= s.n & s.n <= c*f.n by A3;
    per cases;
    suppose
A7:   N = 0;
      take c,d;
      thus c > 0 by A4;
      thus d > 0 by A5;
      let n;
      thus d*f.n <= t.n & t.n <= c*f.n by A2,A6,A7;
    end;
    suppose
A8:   N > 0;
      deffunc F(Element of NAT) = t.$1 / f.$1;
      reconsider B = { F(n) : n < N } as finite non empty Subset of REAL from
      FinImInit2(A8);
      set b = max B;
      set a = min B;
A9:   for n st n < N holds t.n >= a*f.n
      proof
        let n;
A10:    f.n > 0 by Def3;
        assume n < N;
        then t.n / f.n in B;
        then t.n / f.n >= a by XXREAL_2:def 7;
        then t.n / f.n * f.n >= a * f.n by A10,XREAL_1:64;
        hence thesis by A10,XCMPLX_1:87;
      end;
A11:  for n st n < N holds t.n <= b*f.n
      proof
        let n;
A12:    f.n > 0 by Def3;
        assume n < N;
        then t.n / f.n in B;
        then t.n / f.n <= b by XXREAL_2:def 8;
        then t.n / f.n * f.n <= b * f.n by A12,XREAL_1:64;
        hence thesis by A12,XCMPLX_1:87;
      end;
      thus ex c,d st c > 0 & d > 0 & for n holds d*f.n <= t.n & t.n <= c*f.n
      proof
        set D = min( a, d );
        set C = max( b, c );
        reconsider C,D as Element of REAL by XREAL_0:def 1;
        take C,D;
        thus C > 0 by A4,XXREAL_0:25;
A13:    now
          let n;
          f.n > 0 & t.n > 0 by Def3;
          then 0*(f.n)" < t.n*(f.n)" by XREAL_1:68;
          hence 0 < t.n / f.n by XCMPLX_0:def 9;
        end;
        a > 0
        proof
          a in B by XXREAL_2:def 7;
          then ex n st a = t.n / f.n & n < N;
          hence thesis by A13;
        end;
        hence D > 0 by A5,XXREAL_0:15;
        let n;
A14:    f.n > 0 by Def3;
        per cases;
        suppose
A15:      n < N;
A16:      D*f.n <= a*f.n by A14,XREAL_1:64,XXREAL_0:17;
          a*f.n <= t.n by A9,A15;
          hence D*f.n <= t.n by A16,XXREAL_0:2;
A17:      b*f.n <= C*f.n by A14,XREAL_1:64,XXREAL_0:25;
          t.n <= b*f.n by A11,A15;
          hence thesis by A17,XXREAL_0:2;
        end;
        suppose
A18:      n >= N;
A19:      D*f.n <= d*f.n by A14,XREAL_1:64,XXREAL_0:17;
          d*f.n <= t.n by A2,A6,A18;
          hence D*f.n <= t.n by A19,XXREAL_0:2;
A20:      c*f.n <= C*f.n by A14,XREAL_1:64,XXREAL_0:25;
          t.n <= c*f.n by A2,A6,A18;
          hence thesis by A20,XXREAL_0:2;
        end;
      end;
    end;
  end;
  given c,d such that
A21: c > 0 & d > 0 and
A22: for n holds d*f.n <= t.n & t.n <= c*f.n;
  t is Element of Funcs(NAT, REAL) & for n st n >= 0 holds d*f.n <= t.n &
  t.n <= c*f.n by A22,FUNCT_2:8;
  hence thesis by A1,A21;
end;
