src/HOL/Library/BigO.thy
author avigad
Fri, 29 Jul 2005 19:47:34 +0200
changeset 16961 9c5871b16553
parent 16932 0bca871f5a21
child 17199 59c1bfc81d91
permissions -rwxr-xr-x
fixed minor typo in comments
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16932
0bca871f5a21 proper header;
wenzelm
parents: 16908
diff changeset
     1
(*  Title:      HOL/Library/BigO.thy
0bca871f5a21 proper header;
wenzelm
parents: 16908
diff changeset
     2
    ID:		$Id$
16908
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
     3
    Authors:    Jeremy Avigad and Kevin Donnelly
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
     4
*)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
     5
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
     6
header {* Big O notation *}
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
     7
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
     8
theory BigO
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
     9
imports SetsAndFunctions
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    10
begin
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    11
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    12
text {*
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    13
This library is designed to support asymptotic ``big O'' calculations,
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    14
i.e.~reasoning with expressions of the form $f = O(g)$ and $f = g + O(h)$.
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    15
An earlier version of this library is described in detail in
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    16
\begin{quote}
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    17
Avigad, Jeremy, and Kevin Donnelly, \emph{Formalizing O notation in 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    18
Isabelle/HOL}, in David Basin and Micha\"el Rusiowitch, editors, 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    19
\emph{Automated Reasoning: second international conference, IJCAR 2004}, 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    20
Springer, 357--371, 2004.
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    21
\end{quote}
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    22
The main changes in this version are as follows:
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    23
\begin{itemize}
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    24
\item We have eliminated the $O$ operator on sets. (Most uses of this seem
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    25
  to be inessential.)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    26
\item We no longer use $+$ as output syntax for $+o$.
16961
9c5871b16553 fixed minor typo in comments
avigad
parents: 16932
diff changeset
    27
\item Lemmas involving ``sumr'' have been replaced by more general lemmas 
9c5871b16553 fixed minor typo in comments
avigad
parents: 16932
diff changeset
    28
  involving ``setsum''.
16908
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    29
\item The library has been expanded, with e.g.~support for expressions of
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    30
  the form $f < g + O(h)$.
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    31
\end{itemize}
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    32
Note that two lemmas at the end of this file are commented out, as they 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    33
require the HOL-Complex library.
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    34
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    35
Note also since the Big O library includes rules that demonstrate set 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    36
inclusion, to use the automated reasoners effectively with the library one 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    37
should redeclare the theorem ``subsetI'' as an intro rule, rather than as 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    38
an intro! rule, for example, using ``declare subsetI [del, intro]''.
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    39
*}
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    40
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    41
subsection {* Definitions *}
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    42
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    43
constdefs 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    44
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    45
  bigo :: "('a => 'b::ordered_idom) => ('a => 'b) set"    ("(1O'(_'))")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    46
  "O(f::('a => 'b)) == 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    47
      {h. EX c. ALL x. abs (h x) <= c * abs (f x)}"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    48
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    49
lemma bigo_pos_const: "(EX (c::'a::ordered_idom). 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    50
    ALL x. (abs (h x)) <= (c * (abs (f x))))
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    51
      = (EX c. 0 < c & (ALL x. (abs(h x)) <= (c * (abs (f x)))))"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    52
  apply auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    53
  apply (case_tac "c = 0")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    54
  apply simp
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    55
  apply (rule_tac x = "1" in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    56
  apply simp
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    57
  apply (rule_tac x = "abs c" in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    58
  apply auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    59
  apply (subgoal_tac "c * abs(f x) <= abs c * abs (f x)")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    60
  apply (erule_tac x = x in allE)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    61
  apply force
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    62
  apply (rule mult_right_mono)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    63
  apply (rule abs_ge_self)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    64
  apply (rule abs_ge_zero)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    65
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    66
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    67
lemma bigo_alt_def: "O(f) = 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    68
    {h. EX c. (0 < c & (ALL x. abs (h x) <= c * abs (f x)))}"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    69
by (auto simp add: bigo_def bigo_pos_const)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    70
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    71
lemma bigo_elt_subset [intro]: "f : O(g) ==> O(f) <= O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    72
  apply (auto simp add: bigo_alt_def)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    73
  apply (rule_tac x = "ca * c" in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    74
  apply (rule conjI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    75
  apply (rule mult_pos_pos)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    76
  apply (assumption)+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    77
  apply (rule allI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    78
  apply (drule_tac x = "xa" in spec)+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    79
  apply (subgoal_tac "ca * abs(f xa) <= ca * (c * abs(g xa))")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    80
  apply (erule order_trans)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    81
  apply (simp add: mult_ac)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    82
  apply (rule mult_left_mono, assumption)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    83
  apply (rule order_less_imp_le, assumption)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    84
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    85
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    86
lemma bigo_refl [intro]: "f : O(f)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    87
  apply(auto simp add: bigo_def)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    88
  apply(rule_tac x = 1 in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    89
  apply simp
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    90
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    91
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    92
lemma bigo_zero: "0 : O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    93
  apply (auto simp add: bigo_def func_zero)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    94
  apply (rule_tac x = 0 in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    95
  apply auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    96
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    97
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    98
lemma bigo_zero2: "O(%x.0) = {%x.0}"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
    99
  apply (auto simp add: bigo_def) 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   100
  apply (rule ext)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   101
  apply auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   102
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   103
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   104
lemma bigo_plus_self_subset [intro]: 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   105
  "O(f) + O(f) <= O(f)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   106
  apply (auto simp add: bigo_alt_def set_plus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   107
  apply (rule_tac x = "c + ca" in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   108
  apply auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   109
  apply (simp add: ring_distrib func_plus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   110
  apply (rule order_trans)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   111
  apply (rule abs_triangle_ineq)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   112
  apply (rule add_mono)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   113
  apply force
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   114
  apply force
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   115
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   116
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   117
lemma bigo_plus_idemp [simp]: "O(f) + O(f) = O(f)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   118
  apply (rule equalityI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   119
  apply (rule bigo_plus_self_subset)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   120
  apply (rule set_zero_plus2) 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   121
  apply (rule bigo_zero)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   122
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   123
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   124
lemma bigo_plus_subset [intro]: "O(f + g) <= O(f) + O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   125
  apply (rule subsetI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   126
  apply (auto simp add: bigo_def bigo_pos_const func_plus set_plus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   127
  apply (subst bigo_pos_const [symmetric])+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   128
  apply (rule_tac x = 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   129
    "%n. if abs (g n) <= (abs (f n)) then x n else 0" in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   130
  apply (rule conjI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   131
  apply (rule_tac x = "c + c" in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   132
  apply (clarsimp)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   133
  apply (auto)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   134
  apply (subgoal_tac "c * abs (f xa + g xa) <= (c + c) * abs (f xa)")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   135
  apply (erule_tac x = xa in allE)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   136
  apply (erule order_trans)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   137
  apply (simp)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   138
  apply (subgoal_tac "c * abs (f xa + g xa) <= c * (abs (f xa) + abs (g xa))")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   139
  apply (erule order_trans)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   140
  apply (simp add: ring_distrib)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   141
  apply (rule mult_left_mono)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   142
  apply assumption
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   143
  apply (simp add: order_less_le)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   144
  apply (rule mult_left_mono)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   145
  apply (simp add: abs_triangle_ineq)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   146
  apply (simp add: order_less_le)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   147
  apply (rule mult_nonneg_nonneg)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   148
  apply (rule add_nonneg_nonneg)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   149
  apply auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   150
  apply (rule_tac x = "%n. if (abs (f n)) <  abs (g n) then x n else 0" 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   151
     in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   152
  apply (rule conjI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   153
  apply (rule_tac x = "c + c" in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   154
  apply auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   155
  apply (subgoal_tac "c * abs (f xa + g xa) <= (c + c) * abs (g xa)")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   156
  apply (erule_tac x = xa in allE)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   157
  apply (erule order_trans)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   158
  apply (simp)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   159
  apply (subgoal_tac "c * abs (f xa + g xa) <= c * (abs (f xa) + abs (g xa))")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   160
  apply (erule order_trans)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   161
  apply (simp add: ring_distrib)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   162
  apply (rule mult_left_mono)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   163
  apply (simp add: order_less_le)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   164
  apply (simp add: order_less_le)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   165
  apply (rule mult_left_mono)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   166
  apply (rule abs_triangle_ineq)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   167
  apply (simp add: order_less_le)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   168
  apply (rule mult_nonneg_nonneg)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   169
  apply (rule add_nonneg_nonneg)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   170
  apply (erule order_less_imp_le)+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   171
  apply simp
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   172
  apply (rule ext)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   173
  apply (auto simp add: if_splits linorder_not_le)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   174
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   175
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   176
lemma bigo_plus_subset2 [intro]: "A <= O(f) ==> B <= O(f) ==> A + B <= O(f)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   177
  apply (subgoal_tac "A + B <= O(f) + O(f)")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   178
  apply (erule order_trans)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   179
  apply simp
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   180
  apply (auto del: subsetI simp del: bigo_plus_idemp)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   181
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   182
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   183
lemma bigo_plus_eq: "ALL x. 0 <= f x ==> ALL x. 0 <= g x ==> 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   184
  O(f + g) = O(f) + O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   185
  apply (rule equalityI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   186
  apply (rule bigo_plus_subset)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   187
  apply (simp add: bigo_alt_def set_plus func_plus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   188
  apply clarify
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   189
  apply (rule_tac x = "max c ca" in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   190
  apply (rule conjI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   191
  apply (subgoal_tac "c <= max c ca")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   192
  apply (erule order_less_le_trans)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   193
  apply assumption
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   194
  apply (rule le_maxI1)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   195
  apply clarify
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   196
  apply (drule_tac x = "xa" in spec)+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   197
  apply (subgoal_tac "0 <= f xa + g xa")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   198
  apply (simp add: ring_distrib)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   199
  apply (subgoal_tac "abs(a xa + b xa) <= abs(a xa) + abs(b xa)")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   200
  apply (subgoal_tac "abs(a xa) + abs(b xa) <= 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   201
      max c ca * f xa + max c ca * g xa")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   202
  apply (force)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   203
  apply (rule add_mono)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   204
  apply (subgoal_tac "c * f xa <= max c ca * f xa")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   205
  apply (force)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   206
  apply (rule mult_right_mono)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   207
  apply (rule le_maxI1)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   208
  apply assumption
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   209
  apply (subgoal_tac "ca * g xa <= max c ca * g xa")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   210
  apply (force)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   211
  apply (rule mult_right_mono)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   212
  apply (rule le_maxI2)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   213
  apply assumption
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   214
  apply (rule abs_triangle_ineq)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   215
  apply (rule add_nonneg_nonneg)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   216
  apply assumption+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   217
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   218
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   219
lemma bigo_bounded_alt: "ALL x. 0 <= f x ==> ALL x. f x <= c * g x ==> 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   220
    f : O(g)" 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   221
  apply (auto simp add: bigo_def)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   222
  apply (rule_tac x = "abs c" in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   223
  apply auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   224
  apply (drule_tac x = x in spec)+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   225
  apply (simp add: abs_mult [symmetric])
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   226
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   227
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   228
lemma bigo_bounded: "ALL x. 0 <= f x ==> ALL x. f x <= g x ==> 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   229
    f : O(g)" 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   230
  apply (erule bigo_bounded_alt [of f 1 g])
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   231
  apply simp
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   232
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   233
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   234
lemma bigo_bounded2: "ALL x. lb x <= f x ==> ALL x. f x <= lb x + g x ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   235
    f : lb +o O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   236
  apply (rule set_minus_imp_plus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   237
  apply (rule bigo_bounded)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   238
  apply (auto simp add: diff_minus func_minus func_plus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   239
  apply (drule_tac x = x in spec)+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   240
  apply force
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   241
  apply (drule_tac x = x in spec)+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   242
  apply force
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   243
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   244
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   245
lemma bigo_abs: "(%x. abs(f x)) =o O(f)" 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   246
  apply (unfold bigo_def)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   247
  apply auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   248
  apply (rule_tac x = 1 in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   249
  apply auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   250
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   251
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   252
lemma bigo_abs2: "f =o O(%x. abs(f x))"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   253
  apply (unfold bigo_def)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   254
  apply auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   255
  apply (rule_tac x = 1 in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   256
  apply auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   257
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   258
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   259
lemma bigo_abs3: "O(f) = O(%x. abs(f x))"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   260
  apply (rule equalityI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   261
  apply (rule bigo_elt_subset)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   262
  apply (rule bigo_abs2)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   263
  apply (rule bigo_elt_subset)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   264
  apply (rule bigo_abs)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   265
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   266
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   267
lemma bigo_abs4: "f =o g +o O(h) ==> 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   268
    (%x. abs (f x)) =o (%x. abs (g x)) +o O(h)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   269
  apply (drule set_plus_imp_minus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   270
  apply (rule set_minus_imp_plus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   271
  apply (subst func_diff)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   272
proof -
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   273
  assume a: "f - g : O(h)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   274
  have "(%x. abs (f x) - abs (g x)) =o O(%x. abs(abs (f x) - abs (g x)))"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   275
    by (rule bigo_abs2)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   276
  also have "... <= O(%x. abs (f x - g x))"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   277
    apply (rule bigo_elt_subset)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   278
    apply (rule bigo_bounded)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   279
    apply force
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   280
    apply (rule allI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   281
    apply (rule abs_triangle_ineq3)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   282
    done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   283
  also have "... <= O(f - g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   284
    apply (rule bigo_elt_subset)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   285
    apply (subst func_diff)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   286
    apply (rule bigo_abs)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   287
    done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   288
  also have "... <= O(h)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   289
    by (rule bigo_elt_subset)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   290
  finally show "(%x. abs (f x) - abs (g x)) : O(h)".
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   291
qed
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   292
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   293
lemma bigo_abs5: "f =o O(g) ==> (%x. abs(f x)) =o O(g)" 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   294
by (unfold bigo_def, auto)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   295
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   296
lemma bigo_elt_subset2 [intro]: "f : g +o O(h) ==> O(f) <= O(g) + O(h)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   297
proof -
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   298
  assume "f : g +o O(h)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   299
  also have "... <= O(g) + O(h)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   300
    by (auto del: subsetI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   301
  also have "... = O(%x. abs(g x)) + O(%x. abs(h x))"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   302
    apply (subst bigo_abs3 [symmetric])+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   303
    apply (rule refl)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   304
    done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   305
  also have "... = O((%x. abs(g x)) + (%x. abs(h x)))"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   306
    by (rule bigo_plus_eq [symmetric], auto)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   307
  finally have "f : ...".
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   308
  then have "O(f) <= ..."
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   309
    by (elim bigo_elt_subset)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   310
  also have "... = O(%x. abs(g x)) + O(%x. abs(h x))"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   311
    by (rule bigo_plus_eq, auto)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   312
  finally show ?thesis
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   313
    by (simp add: bigo_abs3 [symmetric])
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   314
qed
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   315
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   316
lemma bigo_mult [intro]: "O(f)*O(g) <= O(f * g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   317
  apply (rule subsetI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   318
  apply (subst bigo_def)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   319
  apply (auto simp add: bigo_alt_def set_times func_times)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   320
  apply (rule_tac x = "c * ca" in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   321
  apply(rule allI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   322
  apply(erule_tac x = x in allE)+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   323
  apply(subgoal_tac "c * ca * abs(f x * g x) = 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   324
      (c * abs(f x)) * (ca * abs(g x))")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   325
  apply(erule ssubst)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   326
  apply (subst abs_mult)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   327
  apply (rule mult_mono)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   328
  apply assumption+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   329
  apply (rule mult_nonneg_nonneg)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   330
  apply auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   331
  apply (simp add: mult_ac abs_mult)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   332
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   333
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   334
lemma bigo_mult2 [intro]: "f *o O(g) <= O(f * g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   335
  apply (auto simp add: bigo_def elt_set_times_def func_times abs_mult)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   336
  apply (rule_tac x = c in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   337
  apply auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   338
  apply (drule_tac x = x in spec)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   339
  apply (subgoal_tac "abs(f x) * abs(b x) <= abs(f x) * (c * abs(g x))")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   340
  apply (force simp add: mult_ac)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   341
  apply (rule mult_left_mono, assumption)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   342
  apply (rule abs_ge_zero)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   343
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   344
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   345
lemma bigo_mult3: "f : O(h) ==> g : O(j) ==> f * g : O(h * j)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   346
  apply (rule subsetD)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   347
  apply (rule bigo_mult)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   348
  apply (erule set_times_intro, assumption)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   349
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   350
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   351
lemma bigo_mult4 [intro]:"f : k +o O(h) ==> g * f : (g * k) +o O(g * h)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   352
  apply (drule set_plus_imp_minus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   353
  apply (rule set_minus_imp_plus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   354
  apply (drule bigo_mult3 [where g = g and j = g])
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   355
  apply (auto simp add: ring_eq_simps mult_ac)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   356
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   357
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   358
lemma bigo_mult5: "ALL x. f x ~= 0 ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   359
    O(f * g) <= (f::'a => ('b::ordered_field)) *o O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   360
proof -
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   361
  assume "ALL x. f x ~= 0"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   362
  show "O(f * g) <= f *o O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   363
  proof
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   364
    fix h
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   365
    assume "h : O(f * g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   366
    then have "(%x. 1 / (f x)) * h : (%x. 1 / f x) *o O(f * g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   367
      by auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   368
    also have "... <= O((%x. 1 / f x) * (f * g))"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   369
      by (rule bigo_mult2)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   370
    also have "(%x. 1 / f x) * (f * g) = g"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   371
      apply (simp add: func_times) 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   372
      apply (rule ext)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   373
      apply (simp add: prems nonzero_divide_eq_eq mult_ac)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   374
      done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   375
    finally have "(%x. (1::'b) / f x) * h : O(g)".
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   376
    then have "f * ((%x. (1::'b) / f x) * h) : f *o O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   377
      by auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   378
    also have "f * ((%x. (1::'b) / f x) * h) = h"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   379
      apply (simp add: func_times) 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   380
      apply (rule ext)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   381
      apply (simp add: prems nonzero_divide_eq_eq mult_ac)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   382
      done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   383
    finally show "h : f *o O(g)".
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   384
  qed
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   385
qed
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   386
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   387
lemma bigo_mult6: "ALL x. f x ~= 0 ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   388
    O(f * g) = (f::'a => ('b::ordered_field)) *o O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   389
  apply (rule equalityI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   390
  apply (erule bigo_mult5)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   391
  apply (rule bigo_mult2)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   392
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   393
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   394
lemma bigo_mult7: "ALL x. f x ~= 0 ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   395
    O(f * g) <= O(f::'a => ('b::ordered_field)) * O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   396
  apply (subst bigo_mult6)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   397
  apply assumption
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   398
  apply (rule set_times_mono3)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   399
  apply (rule bigo_refl)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   400
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   401
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   402
lemma bigo_mult8: "ALL x. f x ~= 0 ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   403
    O(f * g) = O(f::'a => ('b::ordered_field)) * O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   404
  apply (rule equalityI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   405
  apply (erule bigo_mult7)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   406
  apply (rule bigo_mult)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   407
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   408
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   409
lemma bigo_minus [intro]: "f : O(g) ==> - f : O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   410
  by (auto simp add: bigo_def func_minus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   411
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   412
lemma bigo_minus2: "f : g +o O(h) ==> -f : -g +o O(h)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   413
  apply (rule set_minus_imp_plus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   414
  apply (drule set_plus_imp_minus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   415
  apply (drule bigo_minus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   416
  apply (simp add: diff_minus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   417
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   418
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   419
lemma bigo_minus3: "O(-f) = O(f)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   420
  by (auto simp add: bigo_def func_minus abs_minus_cancel)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   421
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   422
lemma bigo_plus_absorb_lemma1: "f : O(g) ==> f +o O(g) <= O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   423
proof -
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   424
  assume a: "f : O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   425
  show "f +o O(g) <= O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   426
  proof -
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   427
    have "f : O(f)" by auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   428
    then have "f +o O(g) <= O(f) + O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   429
      by (auto del: subsetI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   430
    also have "... <= O(g) + O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   431
    proof -
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   432
      from a have "O(f) <= O(g)" by (auto del: subsetI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   433
      thus ?thesis by (auto del: subsetI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   434
    qed
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   435
    also have "... <= O(g)" by (simp add: bigo_plus_idemp)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   436
    finally show ?thesis .
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   437
  qed
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   438
qed
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   439
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   440
lemma bigo_plus_absorb_lemma2: "f : O(g) ==> O(g) <= f +o O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   441
proof -
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   442
  assume a: "f : O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   443
  show "O(g) <= f +o O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   444
  proof -
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   445
    from a have "-f : O(g)" by auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   446
    then have "-f +o O(g) <= O(g)" by (elim bigo_plus_absorb_lemma1)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   447
    then have "f +o (-f +o O(g)) <= f +o O(g)" by auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   448
    also have "f +o (-f +o O(g)) = O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   449
      by (simp add: set_plus_rearranges)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   450
    finally show ?thesis .
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   451
  qed
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   452
qed
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   453
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   454
lemma bigo_plus_absorb [simp]: "f : O(g) ==> f +o O(g) = O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   455
  apply (rule equalityI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   456
  apply (erule bigo_plus_absorb_lemma1)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   457
  apply (erule bigo_plus_absorb_lemma2)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   458
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   459
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   460
lemma bigo_plus_absorb2 [intro]: "f : O(g) ==> A <= O(g) ==> f +o A <= O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   461
  apply (subgoal_tac "f +o A <= f +o O(g)")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   462
  apply force+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   463
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   464
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   465
lemma bigo_add_commute_imp: "f : g +o O(h) ==> g : f +o O(h)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   466
  apply (subst set_minus_plus [symmetric])
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   467
  apply (subgoal_tac "g - f = - (f - g)")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   468
  apply (erule ssubst)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   469
  apply (rule bigo_minus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   470
  apply (subst set_minus_plus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   471
  apply assumption
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   472
  apply  (simp add: diff_minus add_ac)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   473
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   474
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   475
lemma bigo_add_commute: "(f : g +o O(h)) = (g : f +o O(h))"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   476
  apply (rule iffI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   477
  apply (erule bigo_add_commute_imp)+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   478
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   479
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   480
lemma bigo_const1: "(%x. c) : O(%x. 1)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   481
by (auto simp add: bigo_def mult_ac)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   482
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   483
lemma bigo_const2 [intro]: "O(%x. c) <= O(%x. 1)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   484
  apply (rule bigo_elt_subset)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   485
  apply (rule bigo_const1)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   486
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   487
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   488
lemma bigo_const3: "(c::'a::ordered_field) ~= 0 ==> (%x. 1) : O(%x. c)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   489
  apply (simp add: bigo_def)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   490
  apply (rule_tac x = "abs(inverse c)" in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   491
  apply (simp add: abs_mult [symmetric])
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   492
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   493
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   494
lemma bigo_const4: "(c::'a::ordered_field) ~= 0 ==> O(%x. 1) <= O(%x. c)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   495
by (rule bigo_elt_subset, rule bigo_const3, assumption)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   496
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   497
lemma bigo_const [simp]: "(c::'a::ordered_field) ~= 0 ==> 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   498
    O(%x. c) = O(%x. 1)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   499
by (rule equalityI, rule bigo_const2, rule bigo_const4, assumption)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   500
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   501
lemma bigo_const_mult1: "(%x. c * f x) : O(f)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   502
  apply (simp add: bigo_def)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   503
  apply (rule_tac x = "abs(c)" in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   504
  apply (auto simp add: abs_mult [symmetric])
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   505
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   506
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   507
lemma bigo_const_mult2: "O(%x. c * f x) <= O(f)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   508
by (rule bigo_elt_subset, rule bigo_const_mult1)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   509
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   510
lemma bigo_const_mult3: "(c::'a::ordered_field) ~= 0 ==> f : O(%x. c * f x)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   511
  apply (simp add: bigo_def)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   512
  apply (rule_tac x = "abs(inverse c)" in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   513
  apply (simp add: abs_mult [symmetric] mult_assoc [symmetric])
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   514
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   515
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   516
lemma bigo_const_mult4: "(c::'a::ordered_field) ~= 0 ==> 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   517
    O(f) <= O(%x. c * f x)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   518
by (rule bigo_elt_subset, rule bigo_const_mult3, assumption)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   519
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   520
lemma bigo_const_mult [simp]: "(c::'a::ordered_field) ~= 0 ==> 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   521
    O(%x. c * f x) = O(f)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   522
by (rule equalityI, rule bigo_const_mult2, erule bigo_const_mult4)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   523
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   524
lemma bigo_const_mult5 [simp]: "(c::'a::ordered_field) ~= 0 ==> 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   525
    (%x. c) *o O(f) = O(f)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   526
  apply (auto del: subsetI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   527
  apply (rule order_trans)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   528
  apply (rule bigo_mult2)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   529
  apply (simp add: func_times)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   530
  apply (auto intro!: subsetI simp add: bigo_def elt_set_times_def func_times)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   531
  apply (rule_tac x = "%y. inverse c * x y" in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   532
  apply (simp add: mult_assoc [symmetric] abs_mult)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   533
  apply (rule_tac x = "abs (inverse c) * ca" in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   534
  apply (rule allI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   535
  apply (subst mult_assoc)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   536
  apply (rule mult_left_mono)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   537
  apply (erule spec)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   538
  apply force
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   539
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   540
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   541
lemma bigo_const_mult6 [intro]: "(%x. c) *o O(f) <= O(f)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   542
  apply (auto intro!: subsetI
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   543
    simp add: bigo_def elt_set_times_def func_times)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   544
  apply (rule_tac x = "ca * (abs c)" in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   545
  apply (rule allI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   546
  apply (subgoal_tac "ca * abs(c) * abs(f x) = abs(c) * (ca * abs(f x))")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   547
  apply (erule ssubst)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   548
  apply (subst abs_mult)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   549
  apply (rule mult_left_mono)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   550
  apply (erule spec)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   551
  apply simp
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   552
  apply(simp add: mult_ac)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   553
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   554
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   555
lemma bigo_const_mult7 [intro]: "f =o O(g) ==> (%x. c * f x) =o O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   556
proof -
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   557
  assume "f =o O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   558
  then have "(%x. c) * f =o (%x. c) *o O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   559
    by auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   560
  also have "(%x. c) * f = (%x. c * f x)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   561
    by (simp add: func_times)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   562
  also have "(%x. c) *o O(g) <= O(g)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   563
    by (auto del: subsetI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   564
  finally show ?thesis .
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   565
qed
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   566
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   567
lemma bigo_compose1: "f =o O(g) ==> (%x. f(k x)) =o O(%x. g(k x))"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   568
by (unfold bigo_def, auto)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   569
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   570
lemma bigo_compose2: "f =o g +o O(h) ==> (%x. f(k x)) =o (%x. g(k x)) +o 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   571
    O(%x. h(k x))"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   572
  apply (simp only: set_minus_plus [symmetric] diff_minus func_minus
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   573
      func_plus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   574
  apply (erule bigo_compose1)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   575
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   576
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   577
subsection {* Setsum *}
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   578
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   579
lemma bigo_setsum_main: "ALL x. ALL y : A x. 0 <= h x y ==> 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   580
    EX c. ALL x. ALL y : A x. abs(f x y) <= c * (h x y) ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   581
      (%x. SUM y : A x. f x y) =o O(%x. SUM y : A x. h x y)"  
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   582
  apply (auto simp add: bigo_def)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   583
  apply (rule_tac x = "abs c" in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   584
  apply (subst abs_of_nonneg);back;back
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   585
  apply (rule setsum_nonneg)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   586
  apply force
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   587
  apply (subst setsum_mult)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   588
  apply (rule allI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   589
  apply (rule order_trans)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   590
  apply (rule setsum_abs)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   591
  apply (rule setsum_mono)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   592
  apply (rule order_trans)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   593
  apply (drule spec)+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   594
  apply (drule bspec)+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   595
  apply assumption+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   596
  apply (drule bspec)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   597
  apply assumption+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   598
  apply (rule mult_right_mono) 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   599
  apply (rule abs_ge_self)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   600
  apply force
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   601
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   602
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   603
lemma bigo_setsum1: "ALL x y. 0 <= h x y ==> 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   604
    EX c. ALL x y. abs(f x y) <= c * (h x y) ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   605
      (%x. SUM y : A x. f x y) =o O(%x. SUM y : A x. h x y)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   606
  apply (rule bigo_setsum_main)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   607
  apply force
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   608
  apply clarsimp
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   609
  apply (rule_tac x = c in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   610
  apply force
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   611
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   612
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   613
lemma bigo_setsum2: "ALL y. 0 <= h y ==> 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   614
    EX c. ALL y. abs(f y) <= c * (h y) ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   615
      (%x. SUM y : A x. f y) =o O(%x. SUM y : A x. h y)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   616
by (rule bigo_setsum1, auto)  
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   617
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   618
lemma bigo_setsum3: "f =o O(h) ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   619
    (%x. SUM y : A x. (l x y) * f(k x y)) =o
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   620
      O(%x. SUM y : A x. abs(l x y * h(k x y)))"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   621
  apply (rule bigo_setsum1)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   622
  apply (rule allI)+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   623
  apply (rule abs_ge_zero)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   624
  apply (unfold bigo_def)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   625
  apply auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   626
  apply (rule_tac x = c in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   627
  apply (rule allI)+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   628
  apply (subst abs_mult)+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   629
  apply (subst mult_left_commute)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   630
  apply (rule mult_left_mono)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   631
  apply (erule spec)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   632
  apply (rule abs_ge_zero)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   633
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   634
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   635
lemma bigo_setsum4: "f =o g +o O(h) ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   636
    (%x. SUM y : A x. l x y * f(k x y)) =o
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   637
      (%x. SUM y : A x. l x y * g(k x y)) +o
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   638
        O(%x. SUM y : A x. abs(l x y * h(k x y)))"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   639
  apply (rule set_minus_imp_plus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   640
  apply (subst func_diff)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   641
  apply (subst setsum_subtractf [symmetric])
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   642
  apply (subst right_diff_distrib [symmetric])
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   643
  apply (rule bigo_setsum3)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   644
  apply (subst func_diff [symmetric])
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   645
  apply (erule set_plus_imp_minus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   646
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   647
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   648
lemma bigo_setsum5: "f =o O(h) ==> ALL x y. 0 <= l x y ==> 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   649
    ALL x. 0 <= h x ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   650
      (%x. SUM y : A x. (l x y) * f(k x y)) =o
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   651
        O(%x. SUM y : A x. (l x y) * h(k x y))" 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   652
  apply (subgoal_tac "(%x. SUM y : A x. (l x y) * h(k x y)) = 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   653
      (%x. SUM y : A x. abs((l x y) * h(k x y)))")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   654
  apply (erule ssubst)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   655
  apply (erule bigo_setsum3)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   656
  apply (rule ext)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   657
  apply (rule setsum_cong2)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   658
  apply (subst abs_of_nonneg)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   659
  apply (rule mult_nonneg_nonneg)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   660
  apply auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   661
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   662
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   663
lemma bigo_setsum6: "f =o g +o O(h) ==> ALL x y. 0 <= l x y ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   664
    ALL x. 0 <= h x ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   665
      (%x. SUM y : A x. (l x y) * f(k x y)) =o
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   666
        (%x. SUM y : A x. (l x y) * g(k x y)) +o
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   667
          O(%x. SUM y : A x. (l x y) * h(k x y))" 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   668
  apply (rule set_minus_imp_plus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   669
  apply (subst func_diff)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   670
  apply (subst setsum_subtractf [symmetric])
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   671
  apply (subst right_diff_distrib [symmetric])
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   672
  apply (rule bigo_setsum5)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   673
  apply (subst func_diff [symmetric])
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   674
  apply (drule set_plus_imp_minus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   675
  apply auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   676
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   677
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   678
subsection {* Misc useful stuff *}
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   679
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   680
lemma bigo_useful_intro: "A <= O(f) ==> B <= O(f) ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   681
  A + B <= O(f)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   682
  apply (subst bigo_plus_idemp [symmetric])
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   683
  apply (rule set_plus_mono2)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   684
  apply assumption+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   685
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   686
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   687
lemma bigo_useful_add: "f =o O(h) ==> g =o O(h) ==> f + g =o O(h)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   688
  apply (subst bigo_plus_idemp [symmetric])
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   689
  apply (rule set_plus_intro)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   690
  apply assumption+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   691
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   692
  
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   693
lemma bigo_useful_const_mult: "(c::'a::ordered_field) ~= 0 ==> 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   694
    (%x. c) * f =o O(h) ==> f =o O(h)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   695
  apply (rule subsetD)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   696
  apply (subgoal_tac "(%x. 1 / c) *o O(h) <= O(h)")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   697
  apply assumption
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   698
  apply (rule bigo_const_mult6)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   699
  apply (subgoal_tac "f = (%x. 1 / c) * ((%x. c) * f)")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   700
  apply (erule ssubst)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   701
  apply (erule set_times_intro2)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   702
  apply (simp add: func_times) 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   703
  apply (rule ext)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   704
  apply (subst times_divide_eq_left [symmetric])
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   705
  apply (subst divide_self)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   706
  apply (assumption, simp)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   707
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   708
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   709
lemma bigo_fix: "(%x. f ((x::nat) + 1)) =o O(%x. h(x + 1)) ==> f 0 = 0 ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   710
    f =o O(h)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   711
  apply (simp add: bigo_alt_def)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   712
  apply auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   713
  apply (rule_tac x = c in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   714
  apply auto
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   715
  apply (case_tac "x = 0")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   716
  apply simp
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   717
  apply (rule mult_nonneg_nonneg)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   718
  apply force
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   719
  apply force
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   720
  apply (subgoal_tac "x = Suc (x - 1)")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   721
  apply (erule ssubst)back
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   722
  apply (erule spec)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   723
  apply simp
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   724
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   725
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   726
lemma bigo_fix2: 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   727
    "(%x. f ((x::nat) + 1)) =o (%x. g(x + 1)) +o O(%x. h(x + 1)) ==> 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   728
       f 0 = g 0 ==> f =o g +o O(h)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   729
  apply (rule set_minus_imp_plus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   730
  apply (rule bigo_fix)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   731
  apply (subst func_diff)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   732
  apply (subst func_diff [symmetric])
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   733
  apply (rule set_plus_imp_minus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   734
  apply simp
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   735
  apply (simp add: func_diff)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   736
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   737
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   738
subsection {* Less than or equal to *}
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   739
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   740
constdefs 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   741
  lesso :: "('a => 'b::ordered_idom) => ('a => 'b) => ('a => 'b)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   742
      (infixl "<o" 70)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   743
  "f <o g == (%x. max (f x - g x) 0)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   744
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   745
lemma bigo_lesseq1: "f =o O(h) ==> ALL x. abs (g x) <= abs (f x) ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   746
    g =o O(h)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   747
  apply (unfold bigo_def)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   748
  apply clarsimp
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   749
  apply (rule_tac x = c in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   750
  apply (rule allI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   751
  apply (rule order_trans)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   752
  apply (erule spec)+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   753
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   754
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   755
lemma bigo_lesseq2: "f =o O(h) ==> ALL x. abs (g x) <= f x ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   756
      g =o O(h)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   757
  apply (erule bigo_lesseq1)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   758
  apply (rule allI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   759
  apply (drule_tac x = x in spec)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   760
  apply (rule order_trans)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   761
  apply assumption
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   762
  apply (rule abs_ge_self)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   763
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   764
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   765
lemma bigo_lesseq3: "f =o O(h) ==> ALL x. 0 <= g x ==> ALL x. g x <= f x ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   766
      g =o O(h)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   767
  apply (erule bigo_lesseq2)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   768
  apply (rule allI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   769
  apply (subst abs_of_nonneg)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   770
  apply (erule spec)+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   771
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   772
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   773
lemma bigo_lesseq4: "f =o O(h) ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   774
    ALL x. 0 <= g x ==> ALL x. g x <= abs (f x) ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   775
      g =o O(h)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   776
  apply (erule bigo_lesseq1)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   777
  apply (rule allI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   778
  apply (subst abs_of_nonneg)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   779
  apply (erule spec)+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   780
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   781
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   782
lemma bigo_lesso1: "ALL x. f x <= g x ==> f <o g =o O(h)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   783
  apply (unfold lesso_def)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   784
  apply (subgoal_tac "(%x. max (f x - g x) 0) = 0")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   785
  apply (erule ssubst)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   786
  apply (rule bigo_zero)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   787
  apply (unfold func_zero)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   788
  apply (rule ext)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   789
  apply (simp split: split_max)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   790
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   791
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   792
lemma bigo_lesso2: "f =o g +o O(h) ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   793
    ALL x. 0 <= k x ==> ALL x. k x <= f x ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   794
      k <o g =o O(h)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   795
  apply (unfold lesso_def)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   796
  apply (rule bigo_lesseq4)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   797
  apply (erule set_plus_imp_minus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   798
  apply (rule allI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   799
  apply (rule le_maxI2)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   800
  apply (rule allI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   801
  apply (subst func_diff)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   802
  apply (case_tac "0 <= k x - g x")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   803
  apply simp
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   804
  apply (subst abs_of_nonneg)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   805
  apply (drule_tac x = x in spec)back
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   806
  apply (simp add: compare_rls)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   807
  apply (subst diff_minus)+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   808
  apply (rule add_right_mono)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   809
  apply (erule spec)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   810
  apply (rule order_trans) 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   811
  prefer 2
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   812
  apply (rule abs_ge_zero)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   813
  apply (simp add: compare_rls)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   814
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   815
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   816
lemma bigo_lesso3: "f =o g +o O(h) ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   817
    ALL x. 0 <= k x ==> ALL x. g x <= k x ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   818
      f <o k =o O(h)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   819
  apply (unfold lesso_def)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   820
  apply (rule bigo_lesseq4)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   821
  apply (erule set_plus_imp_minus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   822
  apply (rule allI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   823
  apply (rule le_maxI2)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   824
  apply (rule allI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   825
  apply (subst func_diff)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   826
  apply (case_tac "0 <= f x - k x")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   827
  apply simp
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   828
  apply (subst abs_of_nonneg)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   829
  apply (drule_tac x = x in spec)back
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   830
  apply (simp add: compare_rls)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   831
  apply (subst diff_minus)+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   832
  apply (rule add_left_mono)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   833
  apply (rule le_imp_neg_le)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   834
  apply (erule spec)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   835
  apply (rule order_trans) 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   836
  prefer 2
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   837
  apply (rule abs_ge_zero)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   838
  apply (simp add: compare_rls)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   839
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   840
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   841
lemma bigo_lesso4: "f <o g =o O(k::'a=>'b::ordered_field) ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   842
    g =o h +o O(k) ==> f <o h =o O(k)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   843
  apply (unfold lesso_def)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   844
  apply (drule set_plus_imp_minus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   845
  apply (drule bigo_abs5)back
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   846
  apply (simp add: func_diff)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   847
  apply (drule bigo_useful_add)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   848
  apply assumption
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   849
  apply (erule bigo_lesseq2)back
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   850
  apply (rule allI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   851
  apply (auto simp add: func_plus func_diff compare_rls 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   852
    split: split_max abs_split)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   853
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   854
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   855
lemma bigo_lesso5: "f <o g =o O(h) ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   856
    EX C. ALL x. f x <= g x + C * abs(h x)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   857
  apply (simp only: lesso_def bigo_alt_def)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   858
  apply clarsimp
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   859
  apply (rule_tac x = c in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   860
  apply (rule allI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   861
  apply (drule_tac x = x in spec)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   862
  apply (subgoal_tac "abs(max (f x - g x) 0) = max (f x - g x) 0")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   863
  apply (clarsimp simp add: compare_rls add_ac) 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   864
  apply (rule abs_of_nonneg)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   865
  apply (rule le_maxI2)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   866
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   867
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   868
lemma lesso_add: "f <o g =o O(h) ==>
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   869
      k <o l =o O(h) ==> (f + k) <o (g + l) =o O(h)"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   870
  apply (unfold lesso_def)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   871
  apply (rule bigo_lesseq3)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   872
  apply (erule bigo_useful_add)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   873
  apply assumption
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   874
  apply (force split: split_max)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   875
  apply (auto split: split_max simp add: func_plus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   876
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   877
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   878
(* 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   879
These last two lemmas require the HOL-Complex library.
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   880
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   881
lemma bigo_LIMSEQ1: "f =o O(g) ==> g ----> 0 ==> f ----> 0"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   882
  apply (simp add: LIMSEQ_def bigo_alt_def)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   883
  apply clarify
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   884
  apply (drule_tac x = "r / c" in spec)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   885
  apply (drule mp)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   886
  apply (erule divide_pos_pos)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   887
  apply assumption
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   888
  apply clarify
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   889
  apply (rule_tac x = no in exI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   890
  apply (rule allI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   891
  apply (drule_tac x = n in spec)+
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   892
  apply (rule impI)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   893
  apply (drule mp)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   894
  apply assumption
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   895
  apply (rule order_le_less_trans)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   896
  apply assumption
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   897
  apply (rule order_less_le_trans)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   898
  apply (subgoal_tac "c * abs(g n) < c * (r / c)")
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   899
  apply assumption
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   900
  apply (erule mult_strict_left_mono)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   901
  apply assumption
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   902
  apply simp
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   903
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   904
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   905
lemma bigo_LIMSEQ2: "f =o g +o O(h) ==> h ----> 0 ==> f ----> a 
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   906
    ==> g ----> a"
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   907
  apply (drule set_plus_imp_minus)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   908
  apply (drule bigo_LIMSEQ1)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   909
  apply assumption
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   910
  apply (simp only: func_diff)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   911
  apply (erule LIMSEQ_diff_approach_zero2)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   912
  apply assumption
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   913
done
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   914
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   915
*)
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   916
d374530bfaaa Added two new theories to HOL/Library: SetsAndFunctions.thy and BigO.thy
avigad
parents:
diff changeset
   917
end