
wenzelm@16932: (*  Title:      HOL/Library/BigO.thy
avigad@16908:     Authors:    Jeremy Avigad and Kevin Donnelly
avigad@16908: *)
avigad@16908: 
avigad@16908: header {* Big O notation *}
avigad@16908: 
avigad@16908: theory BigO
haftmann@29786: imports Complex_Main SetsAndFunctions
avigad@16908: begin
avigad@16908: 
avigad@16908: text {*
avigad@16908: This library is designed to support asymptotic ``big O'' calculations,
wenzelm@17199: i.e.~reasoning with expressions of the form $f = O(g)$ and $f = g +
wenzelm@17199: O(h)$.  An earlier version of this library is described in detail in
wenzelm@17199: \cite{Avigad-Donnelly}.
wenzelm@17199: 
avigad@16908: The main changes in this version are as follows:
avigad@16908: \begin{itemize}
wenzelm@17199: \item We have eliminated the @{text O} operator on sets. (Most uses of this seem
avigad@16908:   to be inessential.)
wenzelm@17199: \item We no longer use @{text "+"} as output syntax for @{text "+o"}
wenzelm@17199: \item Lemmas involving @{text "sumr"} have been replaced by more general lemmas 
wenzelm@17199:   involving `@{text "setsum"}.
avigad@16908: \item The library has been expanded, with e.g.~support for expressions of
wenzelm@17199:   the form @{text "f < g + O(h)"}.
avigad@16908: \end{itemize}
wenzelm@17199: 
wenzelm@17199: See \verb,Complex/ex/BigO_Complex.thy, for additional lemmas that
wenzelm@17199: require the \verb,HOL-Complex, logic image.
avigad@16908: 
wenzelm@17199: Note also since the Big O library includes rules that demonstrate set
wenzelm@17199: inclusion, to use the automated reasoners effectively with the library
wenzelm@17199: one should redeclare the theorem @{text "subsetI"} as an intro rule,
wenzelm@17199: rather than as an @{text "intro!"} rule, for example, using
wenzelm@17199: \isa{\isakeyword{declare}}~@{text "subsetI [del, intro]"}.
avigad@16908: *}
avigad@16908: 
avigad@16908: subsection {* Definitions *}
avigad@16908: 
wenzelm@19736: definition
wenzelm@21404:   bigo :: "('a => 'b::ordered_idom) => ('a => 'b) set"  ("(1O'(_'))") where
wenzelm@19736:   "O(f::('a => 'b)) =
avigad@16908:       {h. EX c. ALL x. abs (h x) <= c * abs (f x)}"
avigad@16908: 
avigad@16908: lemma bigo_pos_const: "(EX (c::'a::ordered_idom). 
avigad@16908:     ALL x. (abs (h x)) <= (c * (abs (f x))))
avigad@16908:       = (EX c. 0 < c & (ALL x. (abs(h x)) <= (c * (abs (f x)))))"
avigad@16908:   apply auto
avigad@16908:   apply (case_tac "c = 0")
avigad@16908:   apply simp
avigad@16908:   apply (rule_tac x = "1" in exI)
avigad@16908:   apply simp
avigad@16908:   apply (rule_tac x = "abs c" in exI)
avigad@16908:   apply auto
avigad@16908:   apply (subgoal_tac "c * abs(f x) <= abs c * abs (f x)")
avigad@16908:   apply (erule_tac x = x in allE)
avigad@16908:   apply force
avigad@16908:   apply (rule mult_right_mono)
avigad@16908:   apply (rule abs_ge_self)
avigad@16908:   apply (rule abs_ge_zero)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_alt_def: "O(f) = 
avigad@16908:     {h. EX c. (0 < c & (ALL x. abs (h x) <= c * abs (f x)))}"
wenzelm@22665:   by (auto simp add: bigo_def bigo_pos_const)
avigad@16908: 
avigad@16908: lemma bigo_elt_subset [intro]: "f : O(g) ==> O(f) <= O(g)"
avigad@16908:   apply (auto simp add: bigo_alt_def)
avigad@16908:   apply (rule_tac x = "ca * c" in exI)
avigad@16908:   apply (rule conjI)
avigad@16908:   apply (rule mult_pos_pos)
avigad@16908:   apply (assumption)+
avigad@16908:   apply (rule allI)
avigad@16908:   apply (drule_tac x = "xa" in spec)+
avigad@16908:   apply (subgoal_tac "ca * abs(f xa) <= ca * (c * abs(g xa))")
avigad@16908:   apply (erule order_trans)
avigad@16908:   apply (simp add: mult_ac)
avigad@16908:   apply (rule mult_left_mono, assumption)
avigad@16908:   apply (rule order_less_imp_le, assumption)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_refl [intro]: "f : O(f)"
avigad@16908:   apply(auto simp add: bigo_def)
avigad@16908:   apply(rule_tac x = 1 in exI)
avigad@16908:   apply simp
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_zero: "0 : O(g)"
avigad@16908:   apply (auto simp add: bigo_def func_zero)
avigad@16908:   apply (rule_tac x = 0 in exI)
avigad@16908:   apply auto
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_zero2: "O(%x.0) = {%x.0}"
avigad@16908:   apply (auto simp add: bigo_def) 
avigad@16908:   apply (rule ext)
avigad@16908:   apply auto
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_plus_self_subset [intro]: 
berghofe@26814:   "O(f) \<oplus> O(f) <= O(f)"
berghofe@26814:   apply (auto simp add: bigo_alt_def set_plus_def)
avigad@16908:   apply (rule_tac x = "c + ca" in exI)
avigad@16908:   apply auto
nipkow@23477:   apply (simp add: ring_distribs func_plus)
avigad@16908:   apply (rule order_trans)
avigad@16908:   apply (rule abs_triangle_ineq)
avigad@16908:   apply (rule add_mono)
avigad@16908:   apply force
avigad@16908:   apply force
avigad@16908: done
avigad@16908: 
berghofe@26814: lemma bigo_plus_idemp [simp]: "O(f) \<oplus> O(f) = O(f)"
avigad@16908:   apply (rule equalityI)
avigad@16908:   apply (rule bigo_plus_self_subset)
avigad@16908:   apply (rule set_zero_plus2) 
avigad@16908:   apply (rule bigo_zero)
wenzelm@22665:   done
avigad@16908: 
berghofe@26814: lemma bigo_plus_subset [intro]: "O(f + g) <= O(f) \<oplus> O(g)"
avigad@16908:   apply (rule subsetI)
berghofe@26814:   apply (auto simp add: bigo_def bigo_pos_const func_plus set_plus_def)
avigad@16908:   apply (subst bigo_pos_const [symmetric])+
avigad@16908:   apply (rule_tac x = 
avigad@16908:     "%n. if abs (g n) <= (abs (f n)) then x n else 0" in exI)
avigad@16908:   apply (rule conjI)
avigad@16908:   apply (rule_tac x = "c + c" in exI)
avigad@16908:   apply (clarsimp)
avigad@16908:   apply (auto)
avigad@16908:   apply (subgoal_tac "c * abs (f xa + g xa) <= (c + c) * abs (f xa)")
avigad@16908:   apply (erule_tac x = xa in allE)
avigad@16908:   apply (erule order_trans)
avigad@16908:   apply (simp)
avigad@16908:   apply (subgoal_tac "c * abs (f xa + g xa) <= c * (abs (f xa) + abs (g xa))")
avigad@16908:   apply (erule order_trans)
nipkow@23477:   apply (simp add: ring_distribs)
avigad@16908:   apply (rule mult_left_mono)
avigad@16908:   apply assumption
avigad@16908:   apply (simp add: order_less_le)
avigad@16908:   apply (rule mult_left_mono)
avigad@16908:   apply (simp add: abs_triangle_ineq)
avigad@16908:   apply (simp add: order_less_le)
avigad@16908:   apply (rule mult_nonneg_nonneg)
avigad@16908:   apply (rule add_nonneg_nonneg)
avigad@16908:   apply auto
avigad@16908:   apply (rule_tac x = "%n. if (abs (f n)) <  abs (g n) then x n else 0" 
avigad@16908:      in exI)
avigad@16908:   apply (rule conjI)
avigad@16908:   apply (rule_tac x = "c + c" in exI)
avigad@16908:   apply auto
avigad@16908:   apply (subgoal_tac "c * abs (f xa + g xa) <= (c + c) * abs (g xa)")
avigad@16908:   apply (erule_tac x = xa in allE)
avigad@16908:   apply (erule order_trans)
avigad@16908:   apply (simp)
avigad@16908:   apply (subgoal_tac "c * abs (f xa + g xa) <= c * (abs (f xa) + abs (g xa))")
avigad@16908:   apply (erule order_trans)
nipkow@23477:   apply (simp add: ring_distribs)
avigad@16908:   apply (rule mult_left_mono)
avigad@16908:   apply (simp add: order_less_le)
avigad@16908:   apply (simp add: order_less_le)
avigad@16908:   apply (rule mult_left_mono)
avigad@16908:   apply (rule abs_triangle_ineq)
avigad@16908:   apply (simp add: order_less_le)
avigad@16908:   apply (rule mult_nonneg_nonneg)
avigad@16908:   apply (rule add_nonneg_nonneg)
avigad@16908:   apply (erule order_less_imp_le)+
avigad@16908:   apply simp
avigad@16908:   apply (rule ext)
avigad@16908:   apply (auto simp add: if_splits linorder_not_le)
wenzelm@22665:   done
avigad@16908: 
berghofe@26814: lemma bigo_plus_subset2 [intro]: "A <= O(f) ==> B <= O(f) ==> A \<oplus> B <= O(f)"
berghofe@26814:   apply (subgoal_tac "A \<oplus> B <= O(f) \<oplus> O(f)")
avigad@16908:   apply (erule order_trans)
avigad@16908:   apply simp
avigad@16908:   apply (auto del: subsetI simp del: bigo_plus_idemp)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_plus_eq: "ALL x. 0 <= f x ==> ALL x. 0 <= g x ==> 
berghofe@26814:     O(f + g) = O(f) \<oplus> O(g)"
avigad@16908:   apply (rule equalityI)
avigad@16908:   apply (rule bigo_plus_subset)
berghofe@26814:   apply (simp add: bigo_alt_def set_plus_def func_plus)
avigad@16908:   apply clarify
avigad@16908:   apply (rule_tac x = "max c ca" in exI)
avigad@16908:   apply (rule conjI)
avigad@16908:   apply (subgoal_tac "c <= max c ca")
avigad@16908:   apply (erule order_less_le_trans)
avigad@16908:   apply assumption
avigad@16908:   apply (rule le_maxI1)
avigad@16908:   apply clarify
avigad@16908:   apply (drule_tac x = "xa" in spec)+
avigad@16908:   apply (subgoal_tac "0 <= f xa + g xa")
nipkow@23477:   apply (simp add: ring_distribs)
avigad@16908:   apply (subgoal_tac "abs(a xa + b xa) <= abs(a xa) + abs(b xa)")
avigad@16908:   apply (subgoal_tac "abs(a xa) + abs(b xa) <= 
avigad@16908:       max c ca * f xa + max c ca * g xa")
avigad@16908:   apply (force)
avigad@16908:   apply (rule add_mono)
avigad@16908:   apply (subgoal_tac "c * f xa <= max c ca * f xa")
avigad@16908:   apply (force)
avigad@16908:   apply (rule mult_right_mono)
avigad@16908:   apply (rule le_maxI1)
avigad@16908:   apply assumption
avigad@16908:   apply (subgoal_tac "ca * g xa <= max c ca * g xa")
avigad@16908:   apply (force)
avigad@16908:   apply (rule mult_right_mono)
avigad@16908:   apply (rule le_maxI2)
avigad@16908:   apply assumption
avigad@16908:   apply (rule abs_triangle_ineq)
avigad@16908:   apply (rule add_nonneg_nonneg)
avigad@16908:   apply assumption+
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_bounded_alt: "ALL x. 0 <= f x ==> ALL x. f x <= c * g x ==> 
avigad@16908:     f : O(g)" 
avigad@16908:   apply (auto simp add: bigo_def)
avigad@16908:   apply (rule_tac x = "abs c" in exI)
avigad@16908:   apply auto
avigad@16908:   apply (drule_tac x = x in spec)+
avigad@16908:   apply (simp add: abs_mult [symmetric])
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_bounded: "ALL x. 0 <= f x ==> ALL x. f x <= g x ==> 
avigad@16908:     f : O(g)" 
avigad@16908:   apply (erule bigo_bounded_alt [of f 1 g])
avigad@16908:   apply simp
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_bounded2: "ALL x. lb x <= f x ==> ALL x. f x <= lb x + g x ==>
avigad@16908:     f : lb +o O(g)"
avigad@16908:   apply (rule set_minus_imp_plus)
avigad@16908:   apply (rule bigo_bounded)
berghofe@26814:   apply (auto simp add: diff_minus fun_Compl_def func_plus)
avigad@16908:   apply (drule_tac x = x in spec)+
avigad@16908:   apply force
avigad@16908:   apply (drule_tac x = x in spec)+
avigad@16908:   apply force
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_abs: "(%x. abs(f x)) =o O(f)" 
avigad@16908:   apply (unfold bigo_def)
avigad@16908:   apply auto
avigad@16908:   apply (rule_tac x = 1 in exI)
avigad@16908:   apply auto
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_abs2: "f =o O(%x. abs(f x))"
avigad@16908:   apply (unfold bigo_def)
avigad@16908:   apply auto
avigad@16908:   apply (rule_tac x = 1 in exI)
avigad@16908:   apply auto
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_abs3: "O(f) = O(%x. abs(f x))"
avigad@16908:   apply (rule equalityI)
avigad@16908:   apply (rule bigo_elt_subset)
avigad@16908:   apply (rule bigo_abs2)
avigad@16908:   apply (rule bigo_elt_subset)
avigad@16908:   apply (rule bigo_abs)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_abs4: "f =o g +o O(h) ==> 
avigad@16908:     (%x. abs (f x)) =o (%x. abs (g x)) +o O(h)"
avigad@16908:   apply (drule set_plus_imp_minus)
avigad@16908:   apply (rule set_minus_imp_plus)
berghofe@26814:   apply (subst fun_diff_def)
avigad@16908: proof -
avigad@16908:   assume a: "f - g : O(h)"
avigad@16908:   have "(%x. abs (f x) - abs (g x)) =o O(%x. abs(abs (f x) - abs (g x)))"
avigad@16908:     by (rule bigo_abs2)
avigad@16908:   also have "... <= O(%x. abs (f x - g x))"
avigad@16908:     apply (rule bigo_elt_subset)
avigad@16908:     apply (rule bigo_bounded)
avigad@16908:     apply force
avigad@16908:     apply (rule allI)
avigad@16908:     apply (rule abs_triangle_ineq3)
avigad@16908:     done
avigad@16908:   also have "... <= O(f - g)"
avigad@16908:     apply (rule bigo_elt_subset)
berghofe@26814:     apply (subst fun_diff_def)
avigad@16908:     apply (rule bigo_abs)
avigad@16908:     done
wenzelm@23373:   also from a have "... <= O(h)"
avigad@16908:     by (rule bigo_elt_subset)
avigad@16908:   finally show "(%x. abs (f x) - abs (g x)) : O(h)".
avigad@16908: qed
avigad@16908: 
avigad@16908: lemma bigo_abs5: "f =o O(g) ==> (%x. abs(f x)) =o O(g)" 
wenzelm@22665:   by (unfold bigo_def, auto)
avigad@16908: 
berghofe@26814: lemma bigo_elt_subset2 [intro]: "f : g +o O(h) ==> O(f) <= O(g) \<oplus> O(h)"
avigad@16908: proof -
avigad@16908:   assume "f : g +o O(h)"
berghofe@26814:   also have "... <= O(g) \<oplus> O(h)"
avigad@16908:     by (auto del: subsetI)
berghofe@26814:   also have "... = O(%x. abs(g x)) \<oplus> O(%x. abs(h x))"
avigad@16908:     apply (subst bigo_abs3 [symmetric])+
avigad@16908:     apply (rule refl)
avigad@16908:     done
avigad@16908:   also have "... = O((%x. abs(g x)) + (%x. abs(h x)))"
avigad@16908:     by (rule bigo_plus_eq [symmetric], auto)
avigad@16908:   finally have "f : ...".
avigad@16908:   then have "O(f) <= ..."
avigad@16908:     by (elim bigo_elt_subset)
berghofe@26814:   also have "... = O(%x. abs(g x)) \<oplus> O(%x. abs(h x))"
avigad@16908:     by (rule bigo_plus_eq, auto)
avigad@16908:   finally show ?thesis
avigad@16908:     by (simp add: bigo_abs3 [symmetric])
avigad@16908: qed
avigad@16908: 
berghofe@26814: lemma bigo_mult [intro]: "O(f)\<otimes>O(g) <= O(f * g)"
avigad@16908:   apply (rule subsetI)
avigad@16908:   apply (subst bigo_def)
berghofe@26814:   apply (auto simp add: bigo_alt_def set_times_def func_times)
avigad@16908:   apply (rule_tac x = "c * ca" in exI)
avigad@16908:   apply(rule allI)
avigad@16908:   apply(erule_tac x = x in allE)+
avigad@16908:   apply(subgoal_tac "c * ca * abs(f x * g x) = 
avigad@16908:       (c * abs(f x)) * (ca * abs(g x))")
avigad@16908:   apply(erule ssubst)
avigad@16908:   apply (subst abs_mult)
avigad@16908:   apply (rule mult_mono)
avigad@16908:   apply assumption+
avigad@16908:   apply (rule mult_nonneg_nonneg)
avigad@16908:   apply auto
avigad@16908:   apply (simp add: mult_ac abs_mult)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_mult2 [intro]: "f *o O(g) <= O(f * g)"
avigad@16908:   apply (auto simp add: bigo_def elt_set_times_def func_times abs_mult)
avigad@16908:   apply (rule_tac x = c in exI)
avigad@16908:   apply auto
avigad@16908:   apply (drule_tac x = x in spec)
avigad@16908:   apply (subgoal_tac "abs(f x) * abs(b x) <= abs(f x) * (c * abs(g x))")
avigad@16908:   apply (force simp add: mult_ac)
avigad@16908:   apply (rule mult_left_mono, assumption)
avigad@16908:   apply (rule abs_ge_zero)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_mult3: "f : O(h) ==> g : O(j) ==> f * g : O(h * j)"
avigad@16908:   apply (rule subsetD)
avigad@16908:   apply (rule bigo_mult)
avigad@16908:   apply (erule set_times_intro, assumption)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_mult4 [intro]:"f : k +o O(h) ==> g * f : (g * k) +o O(g * h)"
avigad@16908:   apply (drule set_plus_imp_minus)
avigad@16908:   apply (rule set_minus_imp_plus)
avigad@16908:   apply (drule bigo_mult3 [where g = g and j = g])
nipkow@29667:   apply (auto simp add: algebra_simps)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_mult5: "ALL x. f x ~= 0 ==>
avigad@16908:     O(f * g) <= (f::'a => ('b::ordered_field)) *o O(g)"
avigad@16908: proof -
avigad@16908:   assume "ALL x. f x ~= 0"
avigad@16908:   show "O(f * g) <= f *o O(g)"
avigad@16908:   proof
avigad@16908:     fix h
avigad@16908:     assume "h : O(f * g)"
avigad@16908:     then have "(%x. 1 / (f x)) * h : (%x. 1 / f x) *o O(f * g)"
avigad@16908:       by auto
avigad@16908:     also have "... <= O((%x. 1 / f x) * (f * g))"
avigad@16908:       by (rule bigo_mult2)
avigad@16908:     also have "(%x. 1 / f x) * (f * g) = g"
avigad@16908:       apply (simp add: func_times) 
avigad@16908:       apply (rule ext)
avigad@16908:       apply (simp add: prems nonzero_divide_eq_eq mult_ac)
avigad@16908:       done
avigad@16908:     finally have "(%x. (1::'b) / f x) * h : O(g)".
avigad@16908:     then have "f * ((%x. (1::'b) / f x) * h) : f *o O(g)"
avigad@16908:       by auto
avigad@16908:     also have "f * ((%x. (1::'b) / f x) * h) = h"
avigad@16908:       apply (simp add: func_times) 
avigad@16908:       apply (rule ext)
avigad@16908:       apply (simp add: prems nonzero_divide_eq_eq mult_ac)
avigad@16908:       done
avigad@16908:     finally show "h : f *o O(g)".
avigad@16908:   qed
avigad@16908: qed
avigad@16908: 
avigad@16908: lemma bigo_mult6: "ALL x. f x ~= 0 ==>
avigad@16908:     O(f * g) = (f::'a => ('b::ordered_field)) *o O(g)"
avigad@16908:   apply (rule equalityI)
avigad@16908:   apply (erule bigo_mult5)
avigad@16908:   apply (rule bigo_mult2)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_mult7: "ALL x. f x ~= 0 ==>
berghofe@26814:     O(f * g) <= O(f::'a => ('b::ordered_field)) \<otimes> O(g)"
avigad@16908:   apply (subst bigo_mult6)
avigad@16908:   apply assumption
avigad@16908:   apply (rule set_times_mono3)
avigad@16908:   apply (rule bigo_refl)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_mult8: "ALL x. f x ~= 0 ==>
berghofe@26814:     O(f * g) = O(f::'a => ('b::ordered_field)) \<otimes> O(g)"
avigad@16908:   apply (rule equalityI)
avigad@16908:   apply (erule bigo_mult7)
avigad@16908:   apply (rule bigo_mult)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_minus [intro]: "f : O(g) ==> - f : O(g)"
berghofe@26814:   by (auto simp add: bigo_def fun_Compl_def)
avigad@16908: 
avigad@16908: lemma bigo_minus2: "f : g +o O(h) ==> -f : -g +o O(h)"
avigad@16908:   apply (rule set_minus_imp_plus)
avigad@16908:   apply (drule set_plus_imp_minus)
avigad@16908:   apply (drule bigo_minus)
avigad@16908:   apply (simp add: diff_minus)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_minus3: "O(-f) = O(f)"
berghofe@26814:   by (auto simp add: bigo_def fun_Compl_def abs_minus_cancel)
avigad@16908: 
avigad@16908: lemma bigo_plus_absorb_lemma1: "f : O(g) ==> f +o O(g) <= O(g)"
avigad@16908: proof -
avigad@16908:   assume a: "f : O(g)"
avigad@16908:   show "f +o O(g) <= O(g)"
avigad@16908:   proof -
avigad@16908:     have "f : O(f)" by auto
berghofe@26814:     then have "f +o O(g) <= O(f) \<oplus> O(g)"
avigad@16908:       by (auto del: subsetI)
berghofe@26814:     also have "... <= O(g) \<oplus> O(g)"
avigad@16908:     proof -
avigad@16908:       from a have "O(f) <= O(g)" by (auto del: subsetI)
avigad@16908:       thus ?thesis by (auto del: subsetI)
avigad@16908:     qed
avigad@16908:     also have "... <= O(g)" by (simp add: bigo_plus_idemp)
avigad@16908:     finally show ?thesis .
avigad@16908:   qed
avigad@16908: qed
avigad@16908: 
avigad@16908: lemma bigo_plus_absorb_lemma2: "f : O(g) ==> O(g) <= f +o O(g)"
avigad@16908: proof -
avigad@16908:   assume a: "f : O(g)"
avigad@16908:   show "O(g) <= f +o O(g)"
avigad@16908:   proof -
avigad@16908:     from a have "-f : O(g)" by auto
avigad@16908:     then have "-f +o O(g) <= O(g)" by (elim bigo_plus_absorb_lemma1)
avigad@16908:     then have "f +o (-f +o O(g)) <= f +o O(g)" by auto
avigad@16908:     also have "f +o (-f +o O(g)) = O(g)"
avigad@16908:       by (simp add: set_plus_rearranges)
avigad@16908:     finally show ?thesis .
avigad@16908:   qed
avigad@16908: qed
avigad@16908: 
avigad@16908: lemma bigo_plus_absorb [simp]: "f : O(g) ==> f +o O(g) = O(g)"
avigad@16908:   apply (rule equalityI)
avigad@16908:   apply (erule bigo_plus_absorb_lemma1)
avigad@16908:   apply (erule bigo_plus_absorb_lemma2)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_plus_absorb2 [intro]: "f : O(g) ==> A <= O(g) ==> f +o A <= O(g)"
avigad@16908:   apply (subgoal_tac "f +o A <= f +o O(g)")
avigad@16908:   apply force+
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_add_commute_imp: "f : g +o O(h) ==> g : f +o O(h)"
avigad@16908:   apply (subst set_minus_plus [symmetric])
avigad@16908:   apply (subgoal_tac "g - f = - (f - g)")
avigad@16908:   apply (erule ssubst)
avigad@16908:   apply (rule bigo_minus)
avigad@16908:   apply (subst set_minus_plus)
avigad@16908:   apply assumption
avigad@16908:   apply  (simp add: diff_minus add_ac)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_add_commute: "(f : g +o O(h)) = (g : f +o O(h))"
avigad@16908:   apply (rule iffI)
avigad@16908:   apply (erule bigo_add_commute_imp)+
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_const1: "(%x. c) : O(%x. 1)"
wenzelm@22665:   by (auto simp add: bigo_def mult_ac)
avigad@16908: 
avigad@16908: lemma bigo_const2 [intro]: "O(%x. c) <= O(%x. 1)"
avigad@16908:   apply (rule bigo_elt_subset)
avigad@16908:   apply (rule bigo_const1)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_const3: "(c::'a::ordered_field) ~= 0 ==> (%x. 1) : O(%x. c)"
avigad@16908:   apply (simp add: bigo_def)
avigad@16908:   apply (rule_tac x = "abs(inverse c)" in exI)
avigad@16908:   apply (simp add: abs_mult [symmetric])
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_const4: "(c::'a::ordered_field) ~= 0 ==> O(%x. 1) <= O(%x. c)"
wenzelm@22665:   by (rule bigo_elt_subset, rule bigo_const3, assumption)
avigad@16908: 
avigad@16908: lemma bigo_const [simp]: "(c::'a::ordered_field) ~= 0 ==> 
avigad@16908:     O(%x. c) = O(%x. 1)"
wenzelm@22665:   by (rule equalityI, rule bigo_const2, rule bigo_const4, assumption)
avigad@16908: 
avigad@16908: lemma bigo_const_mult1: "(%x. c * f x) : O(f)"
avigad@16908:   apply (simp add: bigo_def)
avigad@16908:   apply (rule_tac x = "abs(c)" in exI)
avigad@16908:   apply (auto simp add: abs_mult [symmetric])
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_const_mult2: "O(%x. c * f x) <= O(f)"
wenzelm@22665:   by (rule bigo_elt_subset, rule bigo_const_mult1)
avigad@16908: 
avigad@16908: lemma bigo_const_mult3: "(c::'a::ordered_field) ~= 0 ==> f : O(%x. c * f x)"
avigad@16908:   apply (simp add: bigo_def)
avigad@16908:   apply (rule_tac x = "abs(inverse c)" in exI)
avigad@16908:   apply (simp add: abs_mult [symmetric] mult_assoc [symmetric])
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_const_mult4: "(c::'a::ordered_field) ~= 0 ==> 
avigad@16908:     O(f) <= O(%x. c * f x)"
wenzelm@22665:   by (rule bigo_elt_subset, rule bigo_const_mult3, assumption)
avigad@16908: 
avigad@16908: lemma bigo_const_mult [simp]: "(c::'a::ordered_field) ~= 0 ==> 
avigad@16908:     O(%x. c * f x) = O(f)"
wenzelm@22665:   by (rule equalityI, rule bigo_const_mult2, erule bigo_const_mult4)
avigad@16908: 
avigad@16908: lemma bigo_const_mult5 [simp]: "(c::'a::ordered_field) ~= 0 ==> 
avigad@16908:     (%x. c) *o O(f) = O(f)"
avigad@16908:   apply (auto del: subsetI)
avigad@16908:   apply (rule order_trans)
avigad@16908:   apply (rule bigo_mult2)
avigad@16908:   apply (simp add: func_times)
avigad@16908:   apply (auto intro!: subsetI simp add: bigo_def elt_set_times_def func_times)
avigad@16908:   apply (rule_tac x = "%y. inverse c * x y" in exI)
avigad@16908:   apply (simp add: mult_assoc [symmetric] abs_mult)
avigad@16908:   apply (rule_tac x = "abs (inverse c) * ca" in exI)
avigad@16908:   apply (rule allI)
avigad@16908:   apply (subst mult_assoc)
avigad@16908:   apply (rule mult_left_mono)
avigad@16908:   apply (erule spec)
avigad@16908:   apply force
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_const_mult6 [intro]: "(%x. c) *o O(f) <= O(f)"
avigad@16908:   apply (auto intro!: subsetI
avigad@16908:     simp add: bigo_def elt_set_times_def func_times)
avigad@16908:   apply (rule_tac x = "ca * (abs c)" in exI)
avigad@16908:   apply (rule allI)
avigad@16908:   apply (subgoal_tac "ca * abs(c) * abs(f x) = abs(c) * (ca * abs(f x))")
avigad@16908:   apply (erule ssubst)
avigad@16908:   apply (subst abs_mult)
avigad@16908:   apply (rule mult_left_mono)
avigad@16908:   apply (erule spec)
avigad@16908:   apply simp
avigad@16908:   apply(simp add: mult_ac)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_const_mult7 [intro]: "f =o O(g) ==> (%x. c * f x) =o O(g)"
avigad@16908: proof -
avigad@16908:   assume "f =o O(g)"
avigad@16908:   then have "(%x. c) * f =o (%x. c) *o O(g)"
avigad@16908:     by auto
avigad@16908:   also have "(%x. c) * f = (%x. c * f x)"
avigad@16908:     by (simp add: func_times)
avigad@16908:   also have "(%x. c) *o O(g) <= O(g)"
avigad@16908:     by (auto del: subsetI)
avigad@16908:   finally show ?thesis .
avigad@16908: qed
avigad@16908: 
avigad@16908: lemma bigo_compose1: "f =o O(g) ==> (%x. f(k x)) =o O(%x. g(k x))"
avigad@16908: by (unfold bigo_def, auto)
avigad@16908: 
avigad@16908: lemma bigo_compose2: "f =o g +o O(h) ==> (%x. f(k x)) =o (%x. g(k x)) +o 
avigad@16908:     O(%x. h(k x))"
berghofe@26814:   apply (simp only: set_minus_plus [symmetric] diff_minus fun_Compl_def
avigad@16908:       func_plus)
avigad@16908:   apply (erule bigo_compose1)
avigad@16908: done
avigad@16908: 
wenzelm@22665: 
avigad@16908: subsection {* Setsum *}
avigad@16908: 
avigad@16908: lemma bigo_setsum_main: "ALL x. ALL y : A x. 0 <= h x y ==> 
avigad@16908:     EX c. ALL x. ALL y : A x. abs(f x y) <= c * (h x y) ==>
avigad@16908:       (%x. SUM y : A x. f x y) =o O(%x. SUM y : A x. h x y)"  
avigad@16908:   apply (auto simp add: bigo_def)
avigad@16908:   apply (rule_tac x = "abs c" in exI)
wenzelm@17199:   apply (subst abs_of_nonneg) back back
avigad@16908:   apply (rule setsum_nonneg)
avigad@16908:   apply force
ballarin@19279:   apply (subst setsum_right_distrib)
avigad@16908:   apply (rule allI)
avigad@16908:   apply (rule order_trans)
avigad@16908:   apply (rule setsum_abs)
avigad@16908:   apply (rule setsum_mono)
avigad@16908:   apply (rule order_trans)
avigad@16908:   apply (drule spec)+
avigad@16908:   apply (drule bspec)+
avigad@16908:   apply assumption+
avigad@16908:   apply (drule bspec)
avigad@16908:   apply assumption+
avigad@16908:   apply (rule mult_right_mono) 
avigad@16908:   apply (rule abs_ge_self)
avigad@16908:   apply force
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_setsum1: "ALL x y. 0 <= h x y ==> 
avigad@16908:     EX c. ALL x y. abs(f x y) <= c * (h x y) ==>
avigad@16908:       (%x. SUM y : A x. f x y) =o O(%x. SUM y : A x. h x y)"
avigad@16908:   apply (rule bigo_setsum_main)
avigad@16908:   apply force
avigad@16908:   apply clarsimp
avigad@16908:   apply (rule_tac x = c in exI)
avigad@16908:   apply force
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_setsum2: "ALL y. 0 <= h y ==> 
avigad@16908:     EX c. ALL y. abs(f y) <= c * (h y) ==>
avigad@16908:       (%x. SUM y : A x. f y) =o O(%x. SUM y : A x. h y)"
wenzelm@22665:   by (rule bigo_setsum1, auto)  
avigad@16908: 
avigad@16908: lemma bigo_setsum3: "f =o O(h) ==>
avigad@16908:     (%x. SUM y : A x. (l x y) * f(k x y)) =o
avigad@16908:       O(%x. SUM y : A x. abs(l x y * h(k x y)))"
avigad@16908:   apply (rule bigo_setsum1)
avigad@16908:   apply (rule allI)+
avigad@16908:   apply (rule abs_ge_zero)
avigad@16908:   apply (unfold bigo_def)
avigad@16908:   apply auto
avigad@16908:   apply (rule_tac x = c in exI)
avigad@16908:   apply (rule allI)+
avigad@16908:   apply (subst abs_mult)+
avigad@16908:   apply (subst mult_left_commute)
avigad@16908:   apply (rule mult_left_mono)
avigad@16908:   apply (erule spec)
avigad@16908:   apply (rule abs_ge_zero)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_setsum4: "f =o g +o O(h) ==>
avigad@16908:     (%x. SUM y : A x. l x y * f(k x y)) =o
avigad@16908:       (%x. SUM y : A x. l x y * g(k x y)) +o
avigad@16908:         O(%x. SUM y : A x. abs(l x y * h(k x y)))"
avigad@16908:   apply (rule set_minus_imp_plus)
berghofe@26814:   apply (subst fun_diff_def)
avigad@16908:   apply (subst setsum_subtractf [symmetric])
avigad@16908:   apply (subst right_diff_distrib [symmetric])
avigad@16908:   apply (rule bigo_setsum3)
berghofe@26814:   apply (subst fun_diff_def [symmetric])
avigad@16908:   apply (erule set_plus_imp_minus)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_setsum5: "f =o O(h) ==> ALL x y. 0 <= l x y ==> 
avigad@16908:     ALL x. 0 <= h x ==>
avigad@16908:       (%x. SUM y : A x. (l x y) * f(k x y)) =o
avigad@16908:         O(%x. SUM y : A x. (l x y) * h(k x y))" 
avigad@16908:   apply (subgoal_tac "(%x. SUM y : A x. (l x y) * h(k x y)) = 
avigad@16908:       (%x. SUM y : A x. abs((l x y) * h(k x y)))")
avigad@16908:   apply (erule ssubst)
avigad@16908:   apply (erule bigo_setsum3)
avigad@16908:   apply (rule ext)
avigad@16908:   apply (rule setsum_cong2)
avigad@16908:   apply (subst abs_of_nonneg)
avigad@16908:   apply (rule mult_nonneg_nonneg)
avigad@16908:   apply auto
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_setsum6: "f =o g +o O(h) ==> ALL x y. 0 <= l x y ==>
avigad@16908:     ALL x. 0 <= h x ==>
avigad@16908:       (%x. SUM y : A x. (l x y) * f(k x y)) =o
avigad@16908:         (%x. SUM y : A x. (l x y) * g(k x y)) +o
avigad@16908:           O(%x. SUM y : A x. (l x y) * h(k x y))" 
avigad@16908:   apply (rule set_minus_imp_plus)
berghofe@26814:   apply (subst fun_diff_def)
avigad@16908:   apply (subst setsum_subtractf [symmetric])
avigad@16908:   apply (subst right_diff_distrib [symmetric])
avigad@16908:   apply (rule bigo_setsum5)
berghofe@26814:   apply (subst fun_diff_def [symmetric])
avigad@16908:   apply (drule set_plus_imp_minus)
avigad@16908:   apply auto
wenzelm@22665:   done
wenzelm@22665: 
avigad@16908: 
avigad@16908: subsection {* Misc useful stuff *}
avigad@16908: 
avigad@16908: lemma bigo_useful_intro: "A <= O(f) ==> B <= O(f) ==>
berghofe@26814:   A \<oplus> B <= O(f)"
avigad@16908:   apply (subst bigo_plus_idemp [symmetric])
avigad@16908:   apply (rule set_plus_mono2)
avigad@16908:   apply assumption+
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_useful_add: "f =o O(h) ==> g =o O(h) ==> f + g =o O(h)"
avigad@16908:   apply (subst bigo_plus_idemp [symmetric])
avigad@16908:   apply (rule set_plus_intro)
avigad@16908:   apply assumption+
wenzelm@22665:   done
avigad@16908:   
avigad@16908: lemma bigo_useful_const_mult: "(c::'a::ordered_field) ~= 0 ==> 
avigad@16908:     (%x. c) * f =o O(h) ==> f =o O(h)"
avigad@16908:   apply (rule subsetD)
avigad@16908:   apply (subgoal_tac "(%x. 1 / c) *o O(h) <= O(h)")
avigad@16908:   apply assumption
avigad@16908:   apply (rule bigo_const_mult6)
avigad@16908:   apply (subgoal_tac "f = (%x. 1 / c) * ((%x. c) * f)")
avigad@16908:   apply (erule ssubst)
avigad@16908:   apply (erule set_times_intro2)
nipkow@23413:   apply (simp add: func_times)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_fix: "(%x. f ((x::nat) + 1)) =o O(%x. h(x + 1)) ==> f 0 = 0 ==>
avigad@16908:     f =o O(h)"
avigad@16908:   apply (simp add: bigo_alt_def)
avigad@16908:   apply auto
avigad@16908:   apply (rule_tac x = c in exI)
avigad@16908:   apply auto
avigad@16908:   apply (case_tac "x = 0")
avigad@16908:   apply simp
avigad@16908:   apply (rule mult_nonneg_nonneg)
avigad@16908:   apply force
avigad@16908:   apply force
avigad@16908:   apply (subgoal_tac "x = Suc (x - 1)")
wenzelm@17199:   apply (erule ssubst) back
avigad@16908:   apply (erule spec)
avigad@16908:   apply simp
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_fix2: 
avigad@16908:     "(%x. f ((x::nat) + 1)) =o (%x. g(x + 1)) +o O(%x. h(x + 1)) ==> 
avigad@16908:        f 0 = g 0 ==> f =o g +o O(h)"
avigad@16908:   apply (rule set_minus_imp_plus)
avigad@16908:   apply (rule bigo_fix)
berghofe@26814:   apply (subst fun_diff_def)
berghofe@26814:   apply (subst fun_diff_def [symmetric])
avigad@16908:   apply (rule set_plus_imp_minus)
avigad@16908:   apply simp
berghofe@26814:   apply (simp add: fun_diff_def)
wenzelm@22665:   done
wenzelm@22665: 
avigad@16908: 
avigad@16908: subsection {* Less than or equal to *}
avigad@16908: 
wenzelm@19736: definition
avigad@16908:   lesso :: "('a => 'b::ordered_idom) => ('a => 'b) => ('a => 'b)"
wenzelm@21404:     (infixl "<o" 70) where
wenzelm@19736:   "f <o g = (%x. max (f x - g x) 0)"
avigad@16908: 
avigad@16908: lemma bigo_lesseq1: "f =o O(h) ==> ALL x. abs (g x) <= abs (f x) ==>
avigad@16908:     g =o O(h)"
avigad@16908:   apply (unfold bigo_def)
avigad@16908:   apply clarsimp
avigad@16908:   apply (rule_tac x = c in exI)
avigad@16908:   apply (rule allI)
avigad@16908:   apply (rule order_trans)
avigad@16908:   apply (erule spec)+
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_lesseq2: "f =o O(h) ==> ALL x. abs (g x) <= f x ==>
avigad@16908:       g =o O(h)"
avigad@16908:   apply (erule bigo_lesseq1)
avigad@16908:   apply (rule allI)
avigad@16908:   apply (drule_tac x = x in spec)
avigad@16908:   apply (rule order_trans)
avigad@16908:   apply assumption
avigad@16908:   apply (rule abs_ge_self)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_lesseq3: "f =o O(h) ==> ALL x. 0 <= g x ==> ALL x. g x <= f x ==>
wenzelm@22665:     g =o O(h)"
avigad@16908:   apply (erule bigo_lesseq2)
avigad@16908:   apply (rule allI)
avigad@16908:   apply (subst abs_of_nonneg)
avigad@16908:   apply (erule spec)+
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_lesseq4: "f =o O(h) ==>
avigad@16908:     ALL x. 0 <= g x ==> ALL x. g x <= abs (f x) ==>
avigad@16908:       g =o O(h)"
avigad@16908:   apply (erule bigo_lesseq1)
avigad@16908:   apply (rule allI)
avigad@16908:   apply (subst abs_of_nonneg)
avigad@16908:   apply (erule spec)+
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_lesso1: "ALL x. f x <= g x ==> f <o g =o O(h)"
avigad@16908:   apply (unfold lesso_def)
avigad@16908:   apply (subgoal_tac "(%x. max (f x - g x) 0) = 0")
avigad@16908:   apply (erule ssubst)
avigad@16908:   apply (rule bigo_zero)
avigad@16908:   apply (unfold func_zero)
avigad@16908:   apply (rule ext)
avigad@16908:   apply (simp split: split_max)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_lesso2: "f =o g +o O(h) ==>
avigad@16908:     ALL x. 0 <= k x ==> ALL x. k x <= f x ==>
avigad@16908:       k <o g =o O(h)"
avigad@16908:   apply (unfold lesso_def)
avigad@16908:   apply (rule bigo_lesseq4)
avigad@16908:   apply (erule set_plus_imp_minus)
avigad@16908:   apply (rule allI)
avigad@16908:   apply (rule le_maxI2)
avigad@16908:   apply (rule allI)
berghofe@26814:   apply (subst fun_diff_def)
avigad@16908:   apply (case_tac "0 <= k x - g x")
avigad@16908:   apply simp
avigad@16908:   apply (subst abs_of_nonneg)
wenzelm@17199:   apply (drule_tac x = x in spec) back
nipkow@29667:   apply (simp add: algebra_simps)
avigad@16908:   apply (subst diff_minus)+
avigad@16908:   apply (rule add_right_mono)
avigad@16908:   apply (erule spec)
avigad@16908:   apply (rule order_trans) 
avigad@16908:   prefer 2
avigad@16908:   apply (rule abs_ge_zero)
nipkow@29667:   apply (simp add: algebra_simps)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_lesso3: "f =o g +o O(h) ==>
avigad@16908:     ALL x. 0 <= k x ==> ALL x. g x <= k x ==>
avigad@16908:       f <o k =o O(h)"
avigad@16908:   apply (unfold lesso_def)
avigad@16908:   apply (rule bigo_lesseq4)
avigad@16908:   apply (erule set_plus_imp_minus)
avigad@16908:   apply (rule allI)
avigad@16908:   apply (rule le_maxI2)
avigad@16908:   apply (rule allI)
berghofe@26814:   apply (subst fun_diff_def)
avigad@16908:   apply (case_tac "0 <= f x - k x")
avigad@16908:   apply simp
avigad@16908:   apply (subst abs_of_nonneg)
wenzelm@17199:   apply (drule_tac x = x in spec) back
nipkow@29667:   apply (simp add: algebra_simps)
avigad@16908:   apply (subst diff_minus)+
avigad@16908:   apply (rule add_left_mono)
avigad@16908:   apply (rule le_imp_neg_le)
avigad@16908:   apply (erule spec)
avigad@16908:   apply (rule order_trans) 
avigad@16908:   prefer 2
avigad@16908:   apply (rule abs_ge_zero)
nipkow@29667:   apply (simp add: algebra_simps)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_lesso4: "f <o g =o O(k::'a=>'b::ordered_field) ==>
avigad@16908:     g =o h +o O(k) ==> f <o h =o O(k)"
avigad@16908:   apply (unfold lesso_def)
avigad@16908:   apply (drule set_plus_imp_minus)
wenzelm@17199:   apply (drule bigo_abs5) back
berghofe@26814:   apply (simp add: fun_diff_def)
avigad@16908:   apply (drule bigo_useful_add)
avigad@16908:   apply assumption
wenzelm@17199:   apply (erule bigo_lesseq2) back
avigad@16908:   apply (rule allI)
nipkow@29667:   apply (auto simp add: func_plus fun_diff_def algebra_simps
avigad@16908:     split: split_max abs_split)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma bigo_lesso5: "f <o g =o O(h) ==>
avigad@16908:     EX C. ALL x. f x <= g x + C * abs(h x)"
avigad@16908:   apply (simp only: lesso_def bigo_alt_def)
avigad@16908:   apply clarsimp
avigad@16908:   apply (rule_tac x = c in exI)
avigad@16908:   apply (rule allI)
avigad@16908:   apply (drule_tac x = x in spec)
avigad@16908:   apply (subgoal_tac "abs(max (f x - g x) 0) = max (f x - g x) 0")
nipkow@29667:   apply (clarsimp simp add: algebra_simps) 
avigad@16908:   apply (rule abs_of_nonneg)
avigad@16908:   apply (rule le_maxI2)
wenzelm@22665:   done
avigad@16908: 
avigad@16908: lemma lesso_add: "f <o g =o O(h) ==>
avigad@16908:       k <o l =o O(h) ==> (f + k) <o (g + l) =o O(h)"
avigad@16908:   apply (unfold lesso_def)
avigad@16908:   apply (rule bigo_lesseq3)
avigad@16908:   apply (erule bigo_useful_add)
avigad@16908:   apply assumption
avigad@16908:   apply (force split: split_max)
avigad@16908:   apply (auto split: split_max simp add: func_plus)
wenzelm@22665:   done
avigad@16908: 
haftmann@29786: lemma bigo_LIMSEQ1: "f =o O(g) ==> g ----> 0 ==> f ----> (0::real)"
huffman@31337:   apply (simp add: LIMSEQ_iff bigo_alt_def)
haftmann@29786:   apply clarify
haftmann@29786:   apply (drule_tac x = "r / c" in spec)
haftmann@29786:   apply (drule mp)
haftmann@29786:   apply (erule divide_pos_pos)
haftmann@29786:   apply assumption
haftmann@29786:   apply clarify
haftmann@29786:   apply (rule_tac x = no in exI)
haftmann@29786:   apply (rule allI)
haftmann@29786:   apply (drule_tac x = n in spec)+
haftmann@29786:   apply (rule impI)
haftmann@29786:   apply (drule mp)
haftmann@29786:   apply assumption
haftmann@29786:   apply (rule order_le_less_trans)
haftmann@29786:   apply assumption
haftmann@29786:   apply (rule order_less_le_trans)
haftmann@29786:   apply (subgoal_tac "c * abs(g n) < c * (r / c)")
haftmann@29786:   apply assumption
haftmann@29786:   apply (erule mult_strict_left_mono)
haftmann@29786:   apply assumption
haftmann@29786:   apply simp
haftmann@29786: done
haftmann@29786: 
haftmann@29786: lemma bigo_LIMSEQ2: "f =o g +o O(h) ==> h ----> 0 ==> f ----> a 
haftmann@29786:     ==> g ----> (a::real)"
haftmann@29786:   apply (drule set_plus_imp_minus)
haftmann@29786:   apply (drule bigo_LIMSEQ1)
haftmann@29786:   apply assumption
haftmann@29786:   apply (simp only: fun_diff_def)
haftmann@29786:   apply (erule LIMSEQ_diff_approach_zero2)
haftmann@29786:   apply assumption
haftmann@29786: done
haftmann@29786: 
avigad@16908: end




