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