| author | huffman | 
| Wed, 07 Dec 2011 10:50:30 +0100 | |
| changeset 45775 | 6c340de26a0d | 
| parent 45705 | a25ff4283352 | 
| child 46364 | abab10d1f4a3 | 
| permissions | -rw-r--r-- | 
| 43197 | 1  | 
(* Title: HOL/Metis_Examples/Big_O.thy  | 
2  | 
Author: Lawrence C. Paulson, Cambridge University Computer Laboratory  | 
|
| 41144 | 3  | 
Author: Jasmin Blanchette, TU Muenchen  | 
| 23449 | 4  | 
|
| 43197 | 5  | 
Metis example featuring the Big O notation.  | 
| 23449 | 6  | 
*)  | 
7  | 
||
| 43197 | 8  | 
header {* Metis Example Featuring the Big O Notation *}
 | 
| 23449 | 9  | 
|
| 43197 | 10  | 
theory Big_O  | 
| 
41413
 
64cd30d6b0b8
explicit file specifications -- avoid secondary load path;
 
wenzelm 
parents: 
41144 
diff
changeset
 | 
11  | 
imports  | 
| 
 
64cd30d6b0b8
explicit file specifications -- avoid secondary load path;
 
wenzelm 
parents: 
41144 
diff
changeset
 | 
12  | 
"~~/src/HOL/Decision_Procs/Dense_Linear_Order"  | 
| 
 
64cd30d6b0b8
explicit file specifications -- avoid secondary load path;
 
wenzelm 
parents: 
41144 
diff
changeset
 | 
13  | 
"~~/src/HOL/Library/Function_Algebras"  | 
| 
 
64cd30d6b0b8
explicit file specifications -- avoid secondary load path;
 
wenzelm 
parents: 
41144 
diff
changeset
 | 
14  | 
"~~/src/HOL/Library/Set_Algebras"  | 
| 23449 | 15  | 
begin  | 
16  | 
||
17  | 
subsection {* Definitions *}
 | 
|
18  | 
||
| 45575 | 19  | 
definition bigo :: "('a => 'b\<Colon>{linordered_idom,number_ring}) => ('a => 'b) set" ("(1O'(_'))") where
 | 
20  | 
  "O(f\<Colon>('a => 'b)) == {h. \<exists>c. \<forall>x. abs (h x) <= c * abs (f x)}"
 | 
|
| 23449 | 21  | 
|
| 45575 | 22  | 
lemma bigo_pos_const:  | 
23  | 
"(\<exists>(c\<Colon>'a\<Colon>linordered_idom).  | 
|
24  | 
\<forall>x. (abs (h x)) <= (c * (abs (f x))))  | 
|
25  | 
= (\<exists>c. 0 < c & (\<forall>x. (abs(h x)) <= (c * (abs (f x)))))"  | 
|
26  | 
by (metis (hide_lams, no_types) abs_ge_zero  | 
|
27  | 
comm_semiring_1_class.normalizing_semiring_rules(7) mult.comm_neutral  | 
|
28  | 
mult_nonpos_nonneg not_leE order_trans zero_less_one)  | 
|
| 23449 | 29  | 
|
| 36407 | 30  | 
(*** Now various verions with an increasing shrink factor ***)  | 
| 23449 | 31  | 
|
| 36925 | 32  | 
sledgehammer_params [isar_proof, isar_shrink_factor = 1]  | 
| 23449 | 33  | 
|
| 45575 | 34  | 
lemma  | 
35  | 
"(\<exists>(c\<Colon>'a\<Colon>linordered_idom).  | 
|
36  | 
\<forall>x. (abs (h x)) <= (c * (abs (f x))))  | 
|
37  | 
= (\<exists>c. 0 < c & (\<forall>x. (abs(h x)) <= (c * (abs (f x)))))"  | 
|
| 23449 | 38  | 
apply auto  | 
39  | 
apply (case_tac "c = 0", simp)  | 
|
40  | 
apply (rule_tac x = "1" in exI, simp)  | 
|
41  | 
apply (rule_tac x = "abs c" in exI, auto)  | 
|
| 36561 | 42  | 
proof -  | 
43  | 
fix c :: 'a and x :: 'b  | 
|
44  | 
assume A1: "\<forall>x. \<bar>h x\<bar> \<le> c * \<bar>f x\<bar>"  | 
|
45  | 
have F1: "\<forall>x\<^isub>1\<Colon>'a\<Colon>linordered_idom. 0 \<le> \<bar>x\<^isub>1\<bar>" by (metis abs_ge_zero)  | 
|
| 36844 | 46  | 
have F2: "\<forall>x\<^isub>1\<Colon>'a\<Colon>linordered_idom. 1 * x\<^isub>1 = x\<^isub>1" by (metis mult_1)  | 
| 36561 | 47  | 
have F3: "\<forall>x\<^isub>1 x\<^isub>3. x\<^isub>3 \<le> \<bar>h x\<^isub>1\<bar> \<longrightarrow> x\<^isub>3 \<le> c * \<bar>f x\<^isub>1\<bar>" by (metis A1 order_trans)  | 
48  | 
have F4: "\<forall>x\<^isub>2 x\<^isub>3\<Colon>'a\<Colon>linordered_idom. \<bar>x\<^isub>3\<bar> * \<bar>x\<^isub>2\<bar> = \<bar>x\<^isub>3 * x\<^isub>2\<bar>"  | 
|
49  | 
by (metis abs_mult)  | 
|
50  | 
have F5: "\<forall>x\<^isub>3 x\<^isub>1\<Colon>'a\<Colon>linordered_idom. 0 \<le> x\<^isub>1 \<longrightarrow> \<bar>x\<^isub>3 * x\<^isub>1\<bar> = \<bar>x\<^isub>3\<bar> * x\<^isub>1"  | 
|
51  | 
by (metis abs_mult_pos)  | 
|
52  | 
hence "\<forall>x\<^isub>1\<ge>0. \<bar>x\<^isub>1\<Colon>'a\<Colon>linordered_idom\<bar> = \<bar>1\<bar> * x\<^isub>1" by (metis F2)  | 
|
53  | 
hence "\<forall>x\<^isub>1\<ge>0. \<bar>x\<^isub>1\<Colon>'a\<Colon>linordered_idom\<bar> = x\<^isub>1" by (metis F2 abs_one)  | 
|
54  | 
hence "\<forall>x\<^isub>3. 0 \<le> \<bar>h x\<^isub>3\<bar> \<longrightarrow> \<bar>c * \<bar>f x\<^isub>3\<bar>\<bar> = c * \<bar>f x\<^isub>3\<bar>" by (metis F3)  | 
|
55  | 
hence "\<forall>x\<^isub>3. \<bar>c * \<bar>f x\<^isub>3\<bar>\<bar> = c * \<bar>f x\<^isub>3\<bar>" by (metis F1)  | 
|
56  | 
hence "\<forall>x\<^isub>3. (0\<Colon>'a) \<le> \<bar>f x\<^isub>3\<bar> \<longrightarrow> c * \<bar>f x\<^isub>3\<bar> = \<bar>c\<bar> * \<bar>f x\<^isub>3\<bar>" by (metis F5)  | 
|
57  | 
hence "\<forall>x\<^isub>3. (0\<Colon>'a) \<le> \<bar>f x\<^isub>3\<bar> \<longrightarrow> c * \<bar>f x\<^isub>3\<bar> = \<bar>c * f x\<^isub>3\<bar>" by (metis F4)  | 
|
58  | 
hence "\<forall>x\<^isub>3. c * \<bar>f x\<^isub>3\<bar> = \<bar>c * f x\<^isub>3\<bar>" by (metis F1)  | 
|
59  | 
hence "\<bar>h x\<bar> \<le> \<bar>c * f x\<bar>" by (metis A1)  | 
|
60  | 
thus "\<bar>h x\<bar> \<le> \<bar>c\<bar> * \<bar>f x\<bar>" by (metis F4)  | 
|
| 23449 | 61  | 
qed  | 
62  | 
||
| 36925 | 63  | 
sledgehammer_params [isar_proof, isar_shrink_factor = 2]  | 
| 
25710
 
4cdf7de81e1b
Replaced refs by config params; finer critical section in mets method
 
paulson 
parents: 
25592 
diff
changeset
 | 
64  | 
|
| 45575 | 65  | 
lemma  | 
66  | 
"(\<exists>(c\<Colon>'a\<Colon>linordered_idom).  | 
|
67  | 
\<forall>x. (abs (h x)) <= (c * (abs (f x))))  | 
|
68  | 
= (\<exists>c. 0 < c & (\<forall>x. (abs(h x)) <= (c * (abs (f x)))))"  | 
|
| 23449 | 69  | 
apply auto  | 
70  | 
apply (case_tac "c = 0", simp)  | 
|
71  | 
apply (rule_tac x = "1" in exI, simp)  | 
|
| 36844 | 72  | 
apply (rule_tac x = "abs c" in exI, auto)  | 
| 36561 | 73  | 
proof -  | 
74  | 
fix c :: 'a and x :: 'b  | 
|
75  | 
assume A1: "\<forall>x. \<bar>h x\<bar> \<le> c * \<bar>f x\<bar>"  | 
|
| 36844 | 76  | 
have F1: "\<forall>x\<^isub>1\<Colon>'a\<Colon>linordered_idom. 1 * x\<^isub>1 = x\<^isub>1" by (metis mult_1)  | 
| 36561 | 77  | 
have F2: "\<forall>x\<^isub>2 x\<^isub>3\<Colon>'a\<Colon>linordered_idom. \<bar>x\<^isub>3\<bar> * \<bar>x\<^isub>2\<bar> = \<bar>x\<^isub>3 * x\<^isub>2\<bar>"  | 
78  | 
by (metis abs_mult)  | 
|
79  | 
have "\<forall>x\<^isub>1\<ge>0. \<bar>x\<^isub>1\<Colon>'a\<Colon>linordered_idom\<bar> = x\<^isub>1" by (metis F1 abs_mult_pos abs_one)  | 
|
80  | 
hence "\<forall>x\<^isub>3. \<bar>c * \<bar>f x\<^isub>3\<bar>\<bar> = c * \<bar>f x\<^isub>3\<bar>" by (metis A1 abs_ge_zero order_trans)  | 
|
81  | 
hence "\<forall>x\<^isub>3. 0 \<le> \<bar>f x\<^isub>3\<bar> \<longrightarrow> c * \<bar>f x\<^isub>3\<bar> = \<bar>c * f x\<^isub>3\<bar>" by (metis F2 abs_mult_pos)  | 
|
82  | 
hence "\<bar>h x\<bar> \<le> \<bar>c * f x\<bar>" by (metis A1 abs_ge_zero)  | 
|
83  | 
thus "\<bar>h x\<bar> \<le> \<bar>c\<bar> * \<bar>f x\<bar>" by (metis F2)  | 
|
| 23449 | 84  | 
qed  | 
85  | 
||
| 36925 | 86  | 
sledgehammer_params [isar_proof, isar_shrink_factor = 3]  | 
| 
25710
 
4cdf7de81e1b
Replaced refs by config params; finer critical section in mets method
 
paulson 
parents: 
25592 
diff
changeset
 | 
87  | 
|
| 45575 | 88  | 
lemma  | 
89  | 
"(\<exists>(c\<Colon>'a\<Colon>linordered_idom).  | 
|
90  | 
\<forall>x. (abs (h x)) <= (c * (abs (f x))))  | 
|
91  | 
= (\<exists>c. 0 < c & (\<forall>x. (abs(h x)) <= (c * (abs (f x)))))"  | 
|
| 23449 | 92  | 
apply auto  | 
93  | 
apply (case_tac "c = 0", simp)  | 
|
94  | 
apply (rule_tac x = "1" in exI, simp)  | 
|
| 36561 | 95  | 
apply (rule_tac x = "abs c" in exI, auto)  | 
96  | 
proof -  | 
|
97  | 
fix c :: 'a and x :: 'b  | 
|
98  | 
assume A1: "\<forall>x. \<bar>h x\<bar> \<le> c * \<bar>f x\<bar>"  | 
|
| 36844 | 99  | 
have F1: "\<forall>x\<^isub>1\<Colon>'a\<Colon>linordered_idom. 1 * x\<^isub>1 = x\<^isub>1" by (metis mult_1)  | 
| 36561 | 100  | 
have F2: "\<forall>x\<^isub>3 x\<^isub>1\<Colon>'a\<Colon>linordered_idom. 0 \<le> x\<^isub>1 \<longrightarrow> \<bar>x\<^isub>3 * x\<^isub>1\<bar> = \<bar>x\<^isub>3\<bar> * x\<^isub>1" by (metis abs_mult_pos)  | 
101  | 
hence "\<forall>x\<^isub>1\<ge>0. \<bar>x\<^isub>1\<Colon>'a\<Colon>linordered_idom\<bar> = x\<^isub>1" by (metis F1 abs_one)  | 
|
102  | 
hence "\<forall>x\<^isub>3. 0 \<le> \<bar>f x\<^isub>3\<bar> \<longrightarrow> c * \<bar>f x\<^isub>3\<bar> = \<bar>c\<bar> * \<bar>f x\<^isub>3\<bar>" by (metis F2 A1 abs_ge_zero order_trans)  | 
|
103  | 
thus "\<bar>h x\<bar> \<le> \<bar>c\<bar> * \<bar>f x\<bar>" by (metis A1 abs_mult abs_ge_zero)  | 
|
| 23449 | 104  | 
qed  | 
105  | 
||
| 36925 | 106  | 
sledgehammer_params [isar_proof, isar_shrink_factor = 4]  | 
| 24545 | 107  | 
|
| 45575 | 108  | 
lemma  | 
109  | 
"(\<exists>(c\<Colon>'a\<Colon>linordered_idom).  | 
|
110  | 
\<forall>x. (abs (h x)) <= (c * (abs (f x))))  | 
|
111  | 
= (\<exists>c. 0 < c & (\<forall>x. (abs(h x)) <= (c * (abs (f x)))))"  | 
|
| 24545 | 112  | 
apply auto  | 
113  | 
apply (case_tac "c = 0", simp)  | 
|
114  | 
apply (rule_tac x = "1" in exI, simp)  | 
|
| 36561 | 115  | 
apply (rule_tac x = "abs c" in exI, auto)  | 
116  | 
proof -  | 
|
117  | 
fix c :: 'a and x :: 'b  | 
|
118  | 
assume A1: "\<forall>x. \<bar>h x\<bar> \<le> c * \<bar>f x\<bar>"  | 
|
| 36844 | 119  | 
have "\<forall>x\<^isub>1\<Colon>'a\<Colon>linordered_idom. 1 * x\<^isub>1 = x\<^isub>1" by (metis mult_1)  | 
| 36561 | 120  | 
hence "\<forall>x\<^isub>3. \<bar>c * \<bar>f x\<^isub>3\<bar>\<bar> = c * \<bar>f x\<^isub>3\<bar>"  | 
121  | 
by (metis A1 abs_ge_zero order_trans abs_mult_pos abs_one)  | 
|
122  | 
hence "\<bar>h x\<bar> \<le> \<bar>c * f x\<bar>" by (metis A1 abs_ge_zero abs_mult_pos abs_mult)  | 
|
123  | 
thus "\<bar>h x\<bar> \<le> \<bar>c\<bar> * \<bar>f x\<bar>" by (metis abs_mult)  | 
|
| 24545 | 124  | 
qed  | 
125  | 
||
| 36925 | 126  | 
sledgehammer_params [isar_proof, isar_shrink_factor = 1]  | 
| 24545 | 127  | 
|
| 45575 | 128  | 
lemma bigo_alt_def: "O(f) = {h. \<exists>c. (0 < c & (\<forall>x. abs (h x) <= c * abs (f x)))}"
 | 
| 23449 | 129  | 
by (auto simp add: bigo_def bigo_pos_const)  | 
130  | 
||
| 45575 | 131  | 
lemma bigo_elt_subset [intro]: "f : O(g) \<Longrightarrow> O(f) <= O(g)"  | 
132  | 
apply (auto simp add: bigo_alt_def)  | 
|
133  | 
apply (rule_tac x = "ca * c" in exI)  | 
|
134  | 
apply (rule conjI)  | 
|
135  | 
apply (rule mult_pos_pos)  | 
|
| 43197 | 136  | 
apply (assumption)+  | 
| 45575 | 137  | 
(* sledgehammer *)  | 
138  | 
apply (rule allI)  | 
|
139  | 
apply (drule_tac x = "xa" in spec)+  | 
|
140  | 
apply (subgoal_tac "ca * abs (f xa) <= ca * (c * abs (g xa))")  | 
|
141  | 
apply (metis comm_semiring_1_class.normalizing_semiring_rules(19)  | 
|
142  | 
comm_semiring_1_class.normalizing_semiring_rules(7) order_trans)  | 
|
143  | 
by (metis mult_le_cancel_left_pos)  | 
|
| 23449 | 144  | 
|
145  | 
lemma bigo_refl [intro]: "f : O(f)"  | 
|
| 36561 | 146  | 
apply (auto simp add: bigo_def)  | 
| 36844 | 147  | 
by (metis mult_1 order_refl)  | 
| 23449 | 148  | 
|
149  | 
lemma bigo_zero: "0 : O(g)"  | 
|
| 36561 | 150  | 
apply (auto simp add: bigo_def func_zero)  | 
| 36844 | 151  | 
by (metis mult_zero_left order_refl)  | 
| 23449 | 152  | 
|
| 45575 | 153  | 
lemma bigo_zero2: "O(\<lambda>x. 0) = {\<lambda>x. 0}"
 | 
154  | 
by (auto simp add: bigo_def)  | 
|
| 23449 | 155  | 
|
| 43197 | 156  | 
lemma bigo_plus_self_subset [intro]:  | 
| 
26814
 
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
 
berghofe 
parents: 
26645 
diff
changeset
 | 
157  | 
"O(f) \<oplus> O(f) <= O(f)"  | 
| 45575 | 158  | 
apply (auto simp add: bigo_alt_def set_plus_def)  | 
159  | 
apply (rule_tac x = "c + ca" in exI)  | 
|
160  | 
apply auto  | 
|
161  | 
apply (simp add: ring_distribs func_plus)  | 
|
162  | 
by (metis order_trans abs_triangle_ineq add_mono)  | 
|
| 23449 | 163  | 
|
| 
26814
 
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
 
berghofe 
parents: 
26645 
diff
changeset
 | 
164  | 
lemma bigo_plus_idemp [simp]: "O(f) \<oplus> O(f) = O(f)"  | 
| 45575 | 165  | 
by (metis bigo_plus_self_subset bigo_zero set_eq_subset set_zero_plus2)  | 
| 23449 | 166  | 
|
| 
26814
 
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
 
berghofe 
parents: 
26645 
diff
changeset
 | 
167  | 
lemma bigo_plus_subset [intro]: "O(f + g) <= O(f) \<oplus> O(g)"  | 
| 45575 | 168  | 
apply (rule subsetI)  | 
169  | 
apply (auto simp add: bigo_def bigo_pos_const func_plus set_plus_def)  | 
|
170  | 
apply (subst bigo_pos_const [symmetric])+  | 
|
171  | 
apply (rule_tac x = "\<lambda>n. if abs (g n) <= (abs (f n)) then x n else 0" in exI)  | 
|
172  | 
apply (rule conjI)  | 
|
173  | 
apply (rule_tac x = "c + c" in exI)  | 
|
174  | 
apply clarsimp  | 
|
175  | 
apply auto  | 
|
| 23449 | 176  | 
apply (subgoal_tac "c * abs (f xa + g xa) <= (c + c) * abs (f xa)")  | 
| 45575 | 177  | 
apply (metis mult_2 order_trans)  | 
| 23449 | 178  | 
apply (subgoal_tac "c * abs (f xa + g xa) <= c * (abs (f xa) + abs (g xa))")  | 
| 45575 | 179  | 
apply (erule order_trans)  | 
180  | 
apply (simp add: ring_distribs)  | 
|
| 23449 | 181  | 
apply (rule mult_left_mono)  | 
| 45575 | 182  | 
apply (simp add: abs_triangle_ineq)  | 
| 23449 | 183  | 
apply (simp add: order_less_le)  | 
| 45575 | 184  | 
apply (rule mult_nonneg_nonneg)  | 
| 23449 | 185  | 
apply auto  | 
| 45575 | 186  | 
apply (rule_tac x = "\<lambda>n. if (abs (f n)) < abs (g n) then x n else 0" in exI)  | 
187  | 
apply (rule conjI)  | 
|
188  | 
apply (rule_tac x = "c + c" in exI)  | 
|
189  | 
apply auto  | 
|
190  | 
apply (subgoal_tac "c * abs (f xa + g xa) <= (c + c) * abs (g xa)")  | 
|
191  | 
apply (metis order_trans semiring_mult_2)  | 
|
192  | 
apply (subgoal_tac "c * abs (f xa + g xa) <= c * (abs (f xa) + abs (g xa))")  | 
|
| 23449 | 193  | 
apply (erule order_trans)  | 
| 
23477
 
f4b83f03cac9
tuned and renamed group_eq_simps and ring_eq_simps
 
nipkow 
parents: 
23464 
diff
changeset
 | 
194  | 
apply (simp add: ring_distribs)  | 
| 45575 | 195  | 
apply (metis abs_triangle_ineq mult_le_cancel_left_pos)  | 
196  | 
by (metis abs_ge_zero abs_of_pos zero_le_mult_iff)  | 
|
| 23449 | 197  | 
|
| 45575 | 198  | 
lemma bigo_plus_subset2 [intro]: "A <= O(f) \<Longrightarrow> B <= O(f) \<Longrightarrow> A \<oplus> B <= O(f)"  | 
199  | 
by (metis bigo_plus_idemp set_plus_mono2)  | 
|
| 23449 | 200  | 
|
| 45575 | 201  | 
lemma bigo_plus_eq: "\<forall>x. 0 <= f x \<Longrightarrow> \<forall>x. 0 <= g x \<Longrightarrow> O(f + g) = O(f) \<oplus> O(g)"  | 
202  | 
apply (rule equalityI)  | 
|
203  | 
apply (rule bigo_plus_subset)  | 
|
204  | 
apply (simp add: bigo_alt_def set_plus_def func_plus)  | 
|
205  | 
apply clarify  | 
|
206  | 
(* sledgehammer *)  | 
|
207  | 
apply (rule_tac x = "max c ca" in exI)  | 
|
208  | 
apply (rule conjI)  | 
|
209  | 
apply (metis less_max_iff_disj)  | 
|
210  | 
apply clarify  | 
|
211  | 
apply (drule_tac x = "xa" in spec)+  | 
|
212  | 
apply (subgoal_tac "0 <= f xa + g xa")  | 
|
213  | 
apply (simp add: ring_distribs)  | 
|
214  | 
apply (subgoal_tac "abs (a xa + b xa) <= abs (a xa) + abs (b xa)")  | 
|
215  | 
apply (subgoal_tac "abs (a xa) + abs (b xa) <=  | 
|
216  | 
max c ca * f xa + max c ca * g xa")  | 
|
217  | 
apply (metis order_trans)  | 
|
| 23449 | 218  | 
defer 1  | 
| 45575 | 219  | 
apply (metis abs_triangle_ineq)  | 
220  | 
apply (metis add_nonneg_nonneg)  | 
|
221  | 
apply (rule add_mono)  | 
|
222  | 
apply (metis le_maxI2 linorder_linear min_max.sup_absorb1 mult_right_mono xt1(6))  | 
|
223  | 
by (metis le_maxI2 linorder_not_le mult_le_cancel_right order_trans)  | 
|
| 23449 | 224  | 
|
| 45575 | 225  | 
lemma bigo_bounded_alt: "\<forall>x. 0 <= f x \<Longrightarrow> \<forall>x. f x <= c * g x \<Longrightarrow> f : O(g)"  | 
226  | 
apply (auto simp add: bigo_def)  | 
|
| 36561 | 227  | 
(* Version 1: one-line proof *)  | 
| 45575 | 228  | 
by (metis abs_le_D1 linorder_class.not_less order_less_le Orderings.xt1(12) abs_mult)  | 
| 23449 | 229  | 
|
| 45575 | 230  | 
lemma "\<forall>x. 0 <= f x \<Longrightarrow> \<forall>x. f x <= c * g x \<Longrightarrow> f : O(g)"  | 
| 36561 | 231  | 
apply (auto simp add: bigo_def)  | 
232  | 
(* Version 2: structured proof *)  | 
|
233  | 
proof -  | 
|
234  | 
assume "\<forall>x. f x \<le> c * g x"  | 
|
235  | 
thus "\<exists>c. \<forall>x. f x \<le> c * \<bar>g x\<bar>" by (metis abs_mult abs_ge_self order_trans)  | 
|
| 23449 | 236  | 
qed  | 
237  | 
||
| 45575 | 238  | 
lemma bigo_bounded: "\<forall>x. 0 <= f x \<Longrightarrow> \<forall>x. f x <= g x \<Longrightarrow> f : O(g)"  | 
239  | 
apply (erule bigo_bounded_alt [of f 1 g])  | 
|
240  | 
by (metis mult_1)  | 
|
| 23449 | 241  | 
|
| 45575 | 242  | 
lemma bigo_bounded2: "\<forall>x. lb x <= f x \<Longrightarrow> \<forall>x. f x <= lb x + g x \<Longrightarrow> f : lb +o O(g)"  | 
| 36561 | 243  | 
apply (rule set_minus_imp_plus)  | 
244  | 
apply (rule bigo_bounded)  | 
|
245  | 
apply (auto simp add: diff_minus fun_Compl_def func_plus)  | 
|
246  | 
prefer 2  | 
|
247  | 
apply (drule_tac x = x in spec)+  | 
|
| 36844 | 248  | 
apply (metis add_right_mono add_commute diff_add_cancel diff_minus_eq_add le_less order_trans)  | 
| 36561 | 249  | 
proof -  | 
250  | 
fix x :: 'a  | 
|
251  | 
assume "\<forall>x. lb x \<le> f x"  | 
|
252  | 
thus "(0\<Colon>'b) \<le> f x + - lb x" by (metis not_leE diff_minus less_iff_diff_less_0 less_le_not_le)  | 
|
| 23449 | 253  | 
qed  | 
254  | 
||
| 45575 | 255  | 
lemma bigo_abs: "(\<lambda>x. abs(f x)) =o O(f)"  | 
| 36561 | 256  | 
apply (unfold bigo_def)  | 
257  | 
apply auto  | 
|
| 36844 | 258  | 
by (metis mult_1 order_refl)  | 
| 23449 | 259  | 
|
| 45575 | 260  | 
lemma bigo_abs2: "f =o O(\<lambda>x. abs(f x))"  | 
| 36561 | 261  | 
apply (unfold bigo_def)  | 
262  | 
apply auto  | 
|
| 36844 | 263  | 
by (metis mult_1 order_refl)  | 
| 43197 | 264  | 
|
| 45575 | 265  | 
lemma bigo_abs3: "O(f) = O(\<lambda>x. abs(f x))"  | 
| 36561 | 266  | 
proof -  | 
267  | 
have F1: "\<forall>v u. u \<in> O(v) \<longrightarrow> O(u) \<subseteq> O(v)" by (metis bigo_elt_subset)  | 
|
268  | 
have F2: "\<forall>u. (\<lambda>R. \<bar>u R\<bar>) \<in> O(u)" by (metis bigo_abs)  | 
|
269  | 
have "\<forall>u. u \<in> O(\<lambda>R. \<bar>u R\<bar>)" by (metis bigo_abs2)  | 
|
270  | 
thus "O(f) = O(\<lambda>x. \<bar>f x\<bar>)" using F1 F2 by auto  | 
|
| 43197 | 271  | 
qed  | 
| 23449 | 272  | 
|
| 45575 | 273  | 
lemma bigo_abs4: "f =o g +o O(h) \<Longrightarrow> (\<lambda>x. abs (f x)) =o (\<lambda>x. abs (g x)) +o O(h)"  | 
| 23449 | 274  | 
apply (drule set_plus_imp_minus)  | 
275  | 
apply (rule set_minus_imp_plus)  | 
|
| 
26814
 
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
 
berghofe 
parents: 
26645 
diff
changeset
 | 
276  | 
apply (subst fun_diff_def)  | 
| 23449 | 277  | 
proof -  | 
278  | 
assume a: "f - g : O(h)"  | 
|
| 45575 | 279  | 
have "(\<lambda>x. abs (f x) - abs (g x)) =o O(\<lambda>x. abs(abs (f x) - abs (g x)))"  | 
| 23449 | 280  | 
by (rule bigo_abs2)  | 
| 45575 | 281  | 
also have "... <= O(\<lambda>x. abs (f x - g x))"  | 
| 23449 | 282  | 
apply (rule bigo_elt_subset)  | 
283  | 
apply (rule bigo_bounded)  | 
|
284  | 
apply force  | 
|
285  | 
apply (rule allI)  | 
|
286  | 
apply (rule abs_triangle_ineq3)  | 
|
287  | 
done  | 
|
288  | 
also have "... <= O(f - g)"  | 
|
289  | 
apply (rule bigo_elt_subset)  | 
|
| 
26814
 
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
 
berghofe 
parents: 
26645 
diff
changeset
 | 
290  | 
apply (subst fun_diff_def)  | 
| 23449 | 291  | 
apply (rule bigo_abs)  | 
292  | 
done  | 
|
293  | 
also have "... <= O(h)"  | 
|
| 23464 | 294  | 
using a by (rule bigo_elt_subset)  | 
| 45575 | 295  | 
finally show "(\<lambda>x. abs (f x) - abs (g x)) : O(h)".  | 
| 23449 | 296  | 
qed  | 
297  | 
||
| 45575 | 298  | 
lemma bigo_abs5: "f =o O(g) \<Longrightarrow> (\<lambda>x. abs(f x)) =o O(g)"  | 
| 23449 | 299  | 
by (unfold bigo_def, auto)  | 
300  | 
||
| 45575 | 301  | 
lemma bigo_elt_subset2 [intro]: "f : g +o O(h) \<Longrightarrow> O(f) <= O(g) \<oplus> O(h)"  | 
| 23449 | 302  | 
proof -  | 
303  | 
assume "f : g +o O(h)"  | 
|
| 
26814
 
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
 
berghofe 
parents: 
26645 
diff
changeset
 | 
304  | 
also have "... <= O(g) \<oplus> O(h)"  | 
| 23449 | 305  | 
by (auto del: subsetI)  | 
| 45575 | 306  | 
also have "... = O(\<lambda>x. abs(g x)) \<oplus> O(\<lambda>x. abs(h x))"  | 
| 23449 | 307  | 
apply (subst bigo_abs3 [symmetric])+  | 
308  | 
apply (rule refl)  | 
|
309  | 
done  | 
|
| 45575 | 310  | 
also have "... = O((\<lambda>x. abs(g x)) + (\<lambda>x. abs(h x)))"  | 
| 23449 | 311  | 
by (rule bigo_plus_eq [symmetric], auto)  | 
312  | 
finally have "f : ...".  | 
|
313  | 
then have "O(f) <= ..."  | 
|
314  | 
by (elim bigo_elt_subset)  | 
|
| 45575 | 315  | 
also have "... = O(\<lambda>x. abs(g x)) \<oplus> O(\<lambda>x. abs(h x))"  | 
| 23449 | 316  | 
by (rule bigo_plus_eq, auto)  | 
317  | 
finally show ?thesis  | 
|
318  | 
by (simp add: bigo_abs3 [symmetric])  | 
|
319  | 
qed  | 
|
320  | 
||
| 
26814
 
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
 
berghofe 
parents: 
26645 
diff
changeset
 | 
321  | 
lemma bigo_mult [intro]: "O(f)\<otimes>O(g) <= O(f * g)"  | 
| 23449 | 322  | 
apply (rule subsetI)  | 
323  | 
apply (subst bigo_def)  | 
|
324  | 
apply (auto simp del: abs_mult mult_ac  | 
|
| 
26814
 
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
 
berghofe 
parents: 
26645 
diff
changeset
 | 
325  | 
simp add: bigo_alt_def set_times_def func_times)  | 
| 45575 | 326  | 
(* sledgehammer *)  | 
| 23449 | 327  | 
apply (rule_tac x = "c * ca" in exI)  | 
328  | 
apply(rule allI)  | 
|
329  | 
apply(erule_tac x = x in allE)+  | 
|
| 43197 | 330  | 
apply(subgoal_tac "c * ca * abs(f x * g x) =  | 
| 23449 | 331  | 
(c * abs(f x)) * (ca * abs(g x))")  | 
| 43197 | 332  | 
prefer 2  | 
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25710 
diff
changeset
 | 
333  | 
apply (metis mult_assoc mult_left_commute  | 
| 
35050
 
9f841f20dca6
renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
 
haftmann 
parents: 
35028 
diff
changeset
 | 
334  | 
abs_of_pos mult_left_commute  | 
| 
 
9f841f20dca6
renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
 
haftmann 
parents: 
35028 
diff
changeset
 | 
335  | 
abs_mult mult_pos_pos)  | 
| 43197 | 336  | 
apply (erule ssubst)  | 
| 23449 | 337  | 
apply (subst abs_mult)  | 
| 36561 | 338  | 
(* not quite as hard as BigO__bigo_mult_simpler_1 (a hard problem!) since  | 
339  | 
abs_mult has just been done *)  | 
|
340  | 
by (metis abs_ge_zero mult_mono')  | 
|
| 23449 | 341  | 
|
342  | 
lemma bigo_mult2 [intro]: "f *o O(g) <= O(f * g)"  | 
|
343  | 
apply (auto simp add: bigo_def elt_set_times_def func_times abs_mult)  | 
|
| 45575 | 344  | 
(* sledgehammer *)  | 
| 23449 | 345  | 
apply (rule_tac x = c in exI)  | 
346  | 
apply clarify  | 
|
347  | 
apply (drule_tac x = x in spec)  | 
|
| 
41865
 
4e8483cc2cc5
declare ext [intro]: Extensionality now available by default
 
paulson 
parents: 
41541 
diff
changeset
 | 
348  | 
(*sledgehammer [no luck]*)  | 
| 23449 | 349  | 
apply (subgoal_tac "abs(f x) * abs(b x) <= abs(f x) * (c * abs(g x))")  | 
350  | 
apply (simp add: mult_ac)  | 
|
351  | 
apply (rule mult_left_mono, assumption)  | 
|
352  | 
apply (rule abs_ge_zero)  | 
|
353  | 
done  | 
|
354  | 
||
| 45575 | 355  | 
lemma bigo_mult3: "f : O(h) \<Longrightarrow> g : O(j) \<Longrightarrow> f * g : O(h * j)"  | 
| 36561 | 356  | 
by (metis bigo_mult set_rev_mp set_times_intro)  | 
| 23449 | 357  | 
|
| 45575 | 358  | 
lemma bigo_mult4 [intro]:"f : k +o O(h) \<Longrightarrow> g * f : (g * k) +o O(g * h)"  | 
| 23449 | 359  | 
by (metis bigo_mult2 set_plus_mono_b set_times_intro2 set_times_plus_distrib)  | 
360  | 
||
| 45575 | 361  | 
lemma bigo_mult5: "\<forall>x. f x ~= 0 \<Longrightarrow>  | 
362  | 
    O(f * g) <= (f\<Colon>'a => ('b\<Colon>{linordered_field,number_ring})) *o O(g)"
 | 
|
| 23449 | 363  | 
proof -  | 
| 45575 | 364  | 
assume a: "\<forall>x. f x ~= 0"  | 
| 23449 | 365  | 
show "O(f * g) <= f *o O(g)"  | 
366  | 
proof  | 
|
367  | 
fix h  | 
|
| 41541 | 368  | 
assume h: "h : O(f * g)"  | 
| 45575 | 369  | 
then have "(\<lambda>x. 1 / (f x)) * h : (\<lambda>x. 1 / f x) *o O(f * g)"  | 
| 23449 | 370  | 
by auto  | 
| 45575 | 371  | 
also have "... <= O((\<lambda>x. 1 / f x) * (f * g))"  | 
| 23449 | 372  | 
by (rule bigo_mult2)  | 
| 45575 | 373  | 
also have "(\<lambda>x. 1 / f x) * (f * g) = g"  | 
| 43197 | 374  | 
apply (simp add: func_times)  | 
| 23449 | 375  | 
apply (rule ext)  | 
| 41541 | 376  | 
apply (simp add: a h nonzero_divide_eq_eq mult_ac)  | 
| 23449 | 377  | 
done  | 
| 45575 | 378  | 
finally have "(\<lambda>x. (1\<Colon>'b) / f x) * h : O(g)".  | 
379  | 
then have "f * ((\<lambda>x. (1\<Colon>'b) / f x) * h) : f *o O(g)"  | 
|
| 23449 | 380  | 
by auto  | 
| 45575 | 381  | 
also have "f * ((\<lambda>x. (1\<Colon>'b) / f x) * h) = h"  | 
| 43197 | 382  | 
apply (simp add: func_times)  | 
| 23449 | 383  | 
apply (rule ext)  | 
| 41541 | 384  | 
apply (simp add: a h nonzero_divide_eq_eq mult_ac)  | 
| 23449 | 385  | 
done  | 
386  | 
finally show "h : f *o O(g)".  | 
|
387  | 
qed  | 
|
388  | 
qed  | 
|
389  | 
||
| 45575 | 390  | 
lemma bigo_mult6: "\<forall>x. f x ~= 0 \<Longrightarrow>  | 
391  | 
    O(f * g) = (f\<Colon>'a => ('b\<Colon>{linordered_field,number_ring})) *o O(g)"
 | 
|
| 23449 | 392  | 
by (metis bigo_mult2 bigo_mult5 order_antisym)  | 
393  | 
||
394  | 
(*proof requires relaxing relevance: 2007-01-25*)  | 
|
| 45705 | 395  | 
declare bigo_mult6 [simp]  | 
396  | 
||
| 45575 | 397  | 
lemma bigo_mult7: "\<forall>x. f x ~= 0 \<Longrightarrow>  | 
398  | 
    O(f * g) <= O(f\<Colon>'a => ('b\<Colon>{linordered_field,number_ring})) \<otimes> O(g)"
 | 
|
399  | 
(* sledgehammer *)  | 
|
| 23449 | 400  | 
apply (subst bigo_mult6)  | 
401  | 
apply assumption  | 
|
| 43197 | 402  | 
apply (rule set_times_mono3)  | 
| 23449 | 403  | 
apply (rule bigo_refl)  | 
404  | 
done  | 
|
405  | 
||
| 45575 | 406  | 
declare bigo_mult6 [simp del]  | 
407  | 
declare bigo_mult7 [intro!]  | 
|
408  | 
||
409  | 
lemma bigo_mult8: "\<forall>x. f x ~= 0 \<Longrightarrow>  | 
|
410  | 
    O(f * g) = O(f\<Colon>'a => ('b\<Colon>{linordered_field,number_ring})) \<otimes> O(g)"
 | 
|
| 23449 | 411  | 
by (metis bigo_mult bigo_mult7 order_antisym_conv)  | 
412  | 
||
| 45575 | 413  | 
lemma bigo_minus [intro]: "f : O(g) \<Longrightarrow> - f : O(g)"  | 
| 
26814
 
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
 
berghofe 
parents: 
26645 
diff
changeset
 | 
414  | 
by (auto simp add: bigo_def fun_Compl_def)  | 
| 23449 | 415  | 
|
| 45575 | 416  | 
lemma bigo_minus2: "f : g +o O(h) \<Longrightarrow> -f : -g +o O(h)"  | 
| 23449 | 417  | 
apply (rule set_minus_imp_plus)  | 
418  | 
apply (drule set_plus_imp_minus)  | 
|
419  | 
apply (drule bigo_minus)  | 
|
420  | 
apply (simp add: diff_minus)  | 
|
421  | 
done  | 
|
422  | 
||
423  | 
lemma bigo_minus3: "O(-f) = O(f)"  | 
|
| 
26814
 
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
 
berghofe 
parents: 
26645 
diff
changeset
 | 
424  | 
by (auto simp add: bigo_def fun_Compl_def abs_minus_cancel)  | 
| 23449 | 425  | 
|
| 45575 | 426  | 
lemma bigo_plus_absorb_lemma1: "f : O(g) \<Longrightarrow> f +o O(g) <= O(g)"  | 
| 23449 | 427  | 
proof -  | 
428  | 
assume a: "f : O(g)"  | 
|
429  | 
show "f +o O(g) <= O(g)"  | 
|
430  | 
proof -  | 
|
431  | 
have "f : O(f)" by auto  | 
|
| 
26814
 
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
 
berghofe 
parents: 
26645 
diff
changeset
 | 
432  | 
then have "f +o O(g) <= O(f) \<oplus> O(g)"  | 
| 23449 | 433  | 
by (auto del: subsetI)  | 
| 
26814
 
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
 
berghofe 
parents: 
26645 
diff
changeset
 | 
434  | 
also have "... <= O(g) \<oplus> O(g)"  | 
| 23449 | 435  | 
proof -  | 
436  | 
from a have "O(f) <= O(g)" by (auto del: subsetI)  | 
|
437  | 
thus ?thesis by (auto del: subsetI)  | 
|
438  | 
qed  | 
|
439  | 
also have "... <= O(g)" by (simp add: bigo_plus_idemp)  | 
|
440  | 
finally show ?thesis .  | 
|
441  | 
qed  | 
|
442  | 
qed  | 
|
443  | 
||
| 45575 | 444  | 
lemma bigo_plus_absorb_lemma2: "f : O(g) \<Longrightarrow> O(g) <= f +o O(g)"  | 
| 23449 | 445  | 
proof -  | 
446  | 
assume a: "f : O(g)"  | 
|
447  | 
show "O(g) <= f +o O(g)"  | 
|
448  | 
proof -  | 
|
449  | 
from a have "-f : O(g)" by auto  | 
|
450  | 
then have "-f +o O(g) <= O(g)" by (elim bigo_plus_absorb_lemma1)  | 
|
451  | 
then have "f +o (-f +o O(g)) <= f +o O(g)" by auto  | 
|
452  | 
also have "f +o (-f +o O(g)) = O(g)"  | 
|
453  | 
by (simp add: set_plus_rearranges)  | 
|
454  | 
finally show ?thesis .  | 
|
455  | 
qed  | 
|
456  | 
qed  | 
|
457  | 
||
| 45575 | 458  | 
lemma bigo_plus_absorb [simp]: "f : O(g) \<Longrightarrow> f +o O(g) = O(g)"  | 
| 
41865
 
4e8483cc2cc5
declare ext [intro]: Extensionality now available by default
 
paulson 
parents: 
41541 
diff
changeset
 | 
459  | 
by (metis bigo_plus_absorb_lemma1 bigo_plus_absorb_lemma2 order_eq_iff)  | 
| 23449 | 460  | 
|
| 45575 | 461  | 
lemma bigo_plus_absorb2 [intro]: "f : O(g) \<Longrightarrow> A <= O(g) \<Longrightarrow> f +o A <= O(g)"  | 
| 23449 | 462  | 
apply (subgoal_tac "f +o A <= f +o O(g)")  | 
463  | 
apply force+  | 
|
464  | 
done  | 
|
465  | 
||
| 45575 | 466  | 
lemma bigo_add_commute_imp: "f : g +o O(h) \<Longrightarrow> g : f +o O(h)"  | 
| 23449 | 467  | 
apply (subst set_minus_plus [symmetric])  | 
468  | 
apply (subgoal_tac "g - f = - (f - g)")  | 
|
469  | 
apply (erule ssubst)  | 
|
470  | 
apply (rule bigo_minus)  | 
|
471  | 
apply (subst set_minus_plus)  | 
|
472  | 
apply assumption  | 
|
| 45575 | 473  | 
apply (simp add: diff_minus add_ac)  | 
| 23449 | 474  | 
done  | 
475  | 
||
476  | 
lemma bigo_add_commute: "(f : g +o O(h)) = (g : f +o O(h))"  | 
|
477  | 
apply (rule iffI)  | 
|
478  | 
apply (erule bigo_add_commute_imp)+  | 
|
479  | 
done  | 
|
480  | 
||
| 45575 | 481  | 
lemma bigo_const1: "(\<lambda>x. c) : O(\<lambda>x. 1)"  | 
| 23449 | 482  | 
by (auto simp add: bigo_def mult_ac)  | 
483  | 
||
| 45575 | 484  | 
lemma (*bigo_const2 [intro]:*) "O(\<lambda>x. c) <= O(\<lambda>x. 1)"  | 
| 
41865
 
4e8483cc2cc5
declare ext [intro]: Extensionality now available by default
 
paulson 
parents: 
41541 
diff
changeset
 | 
485  | 
by (metis bigo_const1 bigo_elt_subset)  | 
| 23449 | 486  | 
|
| 45575 | 487  | 
lemma bigo_const2 [intro]: "O(\<lambda>x. c\<Colon>'b\<Colon>{linordered_idom,number_ring}) <= O(\<lambda>x. 1)"
 | 
| 36561 | 488  | 
proof -  | 
| 45575 | 489  | 
have "\<forall>u. (\<lambda>Q. u) \<in> O(\<lambda>Q. 1)" by (metis bigo_const1)  | 
490  | 
thus "O(\<lambda>x. c) \<subseteq> O(\<lambda>x. 1)" by (metis bigo_elt_subset)  | 
|
| 23449 | 491  | 
qed  | 
492  | 
||
| 45575 | 493  | 
lemma bigo_const3: "(c\<Colon>'a\<Colon>{linordered_field,number_ring}) ~= 0 \<Longrightarrow> (\<lambda>x. 1) : O(\<lambda>x. c)"
 | 
| 23449 | 494  | 
apply (simp add: bigo_def)  | 
| 36561 | 495  | 
by (metis abs_eq_0 left_inverse order_refl)  | 
| 23449 | 496  | 
|
| 45575 | 497  | 
lemma bigo_const4: "(c\<Colon>'a\<Colon>{linordered_field,number_ring}) ~= 0 \<Longrightarrow> O(\<lambda>x. 1) <= O(\<lambda>x. c)"
 | 
| 23449 | 498  | 
by (rule bigo_elt_subset, rule bigo_const3, assumption)  | 
499  | 
||
| 45575 | 500  | 
lemma bigo_const [simp]: "(c\<Colon>'a\<Colon>{linordered_field,number_ring}) ~= 0 \<Longrightarrow>
 | 
501  | 
O(\<lambda>x. c) = O(\<lambda>x. 1)"  | 
|
| 23449 | 502  | 
by (rule equalityI, rule bigo_const2, rule bigo_const4, assumption)  | 
503  | 
||
| 45575 | 504  | 
lemma bigo_const_mult1: "(\<lambda>x. c * f x) : O(f)"  | 
| 
24937
 
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
 
paulson 
parents: 
24855 
diff
changeset
 | 
505  | 
apply (simp add: bigo_def abs_mult)  | 
| 36561 | 506  | 
by (metis le_less)  | 
| 23449 | 507  | 
|
| 45575 | 508  | 
lemma bigo_const_mult2: "O(\<lambda>x. c * f x) <= O(f)"  | 
| 23449 | 509  | 
by (rule bigo_elt_subset, rule bigo_const_mult1)  | 
510  | 
||
| 45575 | 511  | 
lemma bigo_const_mult3: "(c\<Colon>'a\<Colon>{linordered_field,number_ring}) ~= 0 \<Longrightarrow> f : O(\<lambda>x. c * f x)"
 | 
512  | 
apply (simp add: bigo_def)  | 
|
513  | 
(* sledgehammer *)  | 
|
514  | 
apply (rule_tac x = "abs(inverse c)" in exI)  | 
|
515  | 
apply (simp only: abs_mult [symmetric] mult_assoc [symmetric])  | 
|
| 43197 | 516  | 
apply (subst left_inverse)  | 
| 45575 | 517  | 
by auto  | 
| 23449 | 518  | 
|
| 45575 | 519  | 
lemma bigo_const_mult4: "(c\<Colon>'a\<Colon>{linordered_field,number_ring}) ~= 0 \<Longrightarrow>
 | 
520  | 
O(f) <= O(\<lambda>x. c * f x)"  | 
|
| 23449 | 521  | 
by (rule bigo_elt_subset, rule bigo_const_mult3, assumption)  | 
522  | 
||
| 45575 | 523  | 
lemma bigo_const_mult [simp]: "(c\<Colon>'a\<Colon>{linordered_field,number_ring}) ~= 0 \<Longrightarrow>
 | 
524  | 
O(\<lambda>x. c * f x) = O(f)"  | 
|
| 23449 | 525  | 
by (rule equalityI, rule bigo_const_mult2, erule bigo_const_mult4)  | 
526  | 
||
| 45575 | 527  | 
lemma bigo_const_mult5 [simp]: "(c\<Colon>'a\<Colon>{linordered_field,number_ring}) ~= 0 \<Longrightarrow>
 | 
528  | 
(\<lambda>x. c) *o O(f) = O(f)"  | 
|
| 23449 | 529  | 
apply (auto del: subsetI)  | 
530  | 
apply (rule order_trans)  | 
|
531  | 
apply (rule bigo_mult2)  | 
|
532  | 
apply (simp add: func_times)  | 
|
533  | 
apply (auto intro!: subsetI simp add: bigo_def elt_set_times_def func_times)  | 
|
| 45575 | 534  | 
apply (rule_tac x = "\<lambda>y. inverse c * x y" in exI)  | 
| 43197 | 535  | 
apply (rename_tac g d)  | 
| 24942 | 536  | 
apply safe  | 
| 43197 | 537  | 
apply (rule_tac [2] ext)  | 
538  | 
prefer 2  | 
|
| 
26041
 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 
haftmann 
parents: 
25710 
diff
changeset
 | 
539  | 
apply simp  | 
| 24942 | 540  | 
apply (simp add: mult_assoc [symmetric] abs_mult)  | 
| 
39259
 
194014eb4f9f
replace two slow "metis" proofs with faster proofs
 
blanchet 
parents: 
38991 
diff
changeset
 | 
541  | 
(* couldn't get this proof without the step above *)  | 
| 
 
194014eb4f9f
replace two slow "metis" proofs with faster proofs
 
blanchet 
parents: 
38991 
diff
changeset
 | 
542  | 
proof -  | 
| 
 
194014eb4f9f
replace two slow "metis" proofs with faster proofs
 
blanchet 
parents: 
38991 
diff
changeset
 | 
543  | 
fix g :: "'b \<Rightarrow> 'a" and d :: 'a  | 
| 
 
194014eb4f9f
replace two slow "metis" proofs with faster proofs
 
blanchet 
parents: 
38991 
diff
changeset
 | 
544  | 
assume A1: "c \<noteq> (0\<Colon>'a)"  | 
| 
 
194014eb4f9f
replace two slow "metis" proofs with faster proofs
 
blanchet 
parents: 
38991 
diff
changeset
 | 
545  | 
assume A2: "\<forall>x\<Colon>'b. \<bar>g x\<bar> \<le> d * \<bar>f x\<bar>"  | 
| 
 
194014eb4f9f
replace two slow "metis" proofs with faster proofs
 
blanchet 
parents: 
38991 
diff
changeset
 | 
546  | 
have F1: "inverse \<bar>c\<bar> = \<bar>inverse c\<bar>" using A1 by (metis nonzero_abs_inverse)  | 
| 
 
194014eb4f9f
replace two slow "metis" proofs with faster proofs
 
blanchet 
parents: 
38991 
diff
changeset
 | 
547  | 
have F2: "(0\<Colon>'a) < \<bar>c\<bar>" using A1 by (metis zero_less_abs_iff)  | 
| 
 
194014eb4f9f
replace two slow "metis" proofs with faster proofs
 
blanchet 
parents: 
38991 
diff
changeset
 | 
548  | 
have "(0\<Colon>'a) < \<bar>c\<bar> \<longrightarrow> (0\<Colon>'a) < \<bar>inverse c\<bar>" using F1 by (metis positive_imp_inverse_positive)  | 
| 
 
194014eb4f9f
replace two slow "metis" proofs with faster proofs
 
blanchet 
parents: 
38991 
diff
changeset
 | 
549  | 
hence "(0\<Colon>'a) < \<bar>inverse c\<bar>" using F2 by metis  | 
| 
 
194014eb4f9f
replace two slow "metis" proofs with faster proofs
 
blanchet 
parents: 
38991 
diff
changeset
 | 
550  | 
hence F3: "(0\<Colon>'a) \<le> \<bar>inverse c\<bar>" by (metis order_le_less)  | 
| 
 
194014eb4f9f
replace two slow "metis" proofs with faster proofs
 
blanchet 
parents: 
38991 
diff
changeset
 | 
551  | 
have "\<exists>(u\<Colon>'a) SKF\<^isub>7\<Colon>'a \<Rightarrow> 'b. \<bar>g (SKF\<^isub>7 (\<bar>inverse c\<bar> * u))\<bar> \<le> u * \<bar>f (SKF\<^isub>7 (\<bar>inverse c\<bar> * u))\<bar>"  | 
| 
 
194014eb4f9f
replace two slow "metis" proofs with faster proofs
 
blanchet 
parents: 
38991 
diff
changeset
 | 
552  | 
using A2 by metis  | 
| 
 
194014eb4f9f
replace two slow "metis" proofs with faster proofs
 
blanchet 
parents: 
38991 
diff
changeset
 | 
553  | 
hence F4: "\<exists>(u\<Colon>'a) SKF\<^isub>7\<Colon>'a \<Rightarrow> 'b. \<bar>g (SKF\<^isub>7 (\<bar>inverse c\<bar> * u))\<bar> \<le> u * \<bar>f (SKF\<^isub>7 (\<bar>inverse c\<bar> * u))\<bar> \<and> (0\<Colon>'a) \<le> \<bar>inverse c\<bar>"  | 
| 
 
194014eb4f9f
replace two slow "metis" proofs with faster proofs
 
blanchet 
parents: 
38991 
diff
changeset
 | 
554  | 
using F3 by metis  | 
| 
 
194014eb4f9f
replace two slow "metis" proofs with faster proofs
 
blanchet 
parents: 
38991 
diff
changeset
 | 
555  | 
hence "\<exists>(v\<Colon>'a) (u\<Colon>'a) SKF\<^isub>7\<Colon>'a \<Rightarrow> 'b. \<bar>inverse c\<bar> * \<bar>g (SKF\<^isub>7 (u * v))\<bar> \<le> u * (v * \<bar>f (SKF\<^isub>7 (u * v))\<bar>)"  | 
| 
 
194014eb4f9f
replace two slow "metis" proofs with faster proofs
 
blanchet 
parents: 
38991 
diff
changeset
 | 
556  | 
by (metis comm_mult_left_mono)  | 
| 
 
194014eb4f9f
replace two slow "metis" proofs with faster proofs
 
blanchet 
parents: 
38991 
diff
changeset
 | 
557  | 
thus "\<exists>ca\<Colon>'a. \<forall>x\<Colon>'b. \<bar>inverse c\<bar> * \<bar>g x\<bar> \<le> ca * \<bar>f x\<bar>"  | 
| 
 
194014eb4f9f
replace two slow "metis" proofs with faster proofs
 
blanchet 
parents: 
38991 
diff
changeset
 | 
558  | 
using A2 F4 by (metis ab_semigroup_mult_class.mult_ac(1) comm_mult_left_mono)  | 
| 
 
194014eb4f9f
replace two slow "metis" proofs with faster proofs
 
blanchet 
parents: 
38991 
diff
changeset
 | 
559  | 
qed  | 
| 23449 | 560  | 
|
| 45575 | 561  | 
lemma bigo_const_mult6 [intro]: "(\<lambda>x. c) *o O(f) <= O(f)"  | 
| 23449 | 562  | 
apply (auto intro!: subsetI  | 
563  | 
simp add: bigo_def elt_set_times_def func_times  | 
|
564  | 
simp del: abs_mult mult_ac)  | 
|
| 45575 | 565  | 
(* sledgehammer *)  | 
| 23449 | 566  | 
apply (rule_tac x = "ca * (abs c)" in exI)  | 
567  | 
apply (rule allI)  | 
|
568  | 
apply (subgoal_tac "ca * abs(c) * abs(f x) = abs(c) * (ca * abs(f x))")  | 
|
569  | 
apply (erule ssubst)  | 
|
570  | 
apply (subst abs_mult)  | 
|
571  | 
apply (rule mult_left_mono)  | 
|
572  | 
apply (erule spec)  | 
|
573  | 
apply simp  | 
|
574  | 
apply(simp add: mult_ac)  | 
|
575  | 
done  | 
|
576  | 
||
| 45575 | 577  | 
lemma bigo_const_mult7 [intro]: "f =o O(g) \<Longrightarrow> (\<lambda>x. c * f x) =o O(g)"  | 
| 23449 | 578  | 
proof -  | 
579  | 
assume "f =o O(g)"  | 
|
| 45575 | 580  | 
then have "(\<lambda>x. c) * f =o (\<lambda>x. c) *o O(g)"  | 
| 23449 | 581  | 
by auto  | 
| 45575 | 582  | 
also have "(\<lambda>x. c) * f = (\<lambda>x. c * f x)"  | 
| 23449 | 583  | 
by (simp add: func_times)  | 
| 45575 | 584  | 
also have "(\<lambda>x. c) *o O(g) <= O(g)"  | 
| 23449 | 585  | 
by (auto del: subsetI)  | 
586  | 
finally show ?thesis .  | 
|
587  | 
qed  | 
|
588  | 
||
| 45575 | 589  | 
lemma bigo_compose1: "f =o O(g) \<Longrightarrow> (\<lambda>x. f(k x)) =o O(\<lambda>x. g(k x))"  | 
| 23449 | 590  | 
by (unfold bigo_def, auto)  | 
591  | 
||
| 45575 | 592  | 
lemma bigo_compose2: "f =o g +o O(h) \<Longrightarrow> (\<lambda>x. f(k x)) =o (\<lambda>x. g(k x)) +o  | 
593  | 
O(\<lambda>x. h(k x))"  | 
|
| 
26814
 
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
 
berghofe 
parents: 
26645 
diff
changeset
 | 
594  | 
apply (simp only: set_minus_plus [symmetric] diff_minus fun_Compl_def  | 
| 23449 | 595  | 
func_plus)  | 
596  | 
apply (erule bigo_compose1)  | 
|
597  | 
done  | 
|
598  | 
||
599  | 
subsection {* Setsum *}
 | 
|
600  | 
||
| 45575 | 601  | 
lemma bigo_setsum_main: "\<forall>x. \<forall>y \<in> A x. 0 <= h x y \<Longrightarrow>  | 
602  | 
\<exists>c. \<forall>x. \<forall>y \<in> A x. abs (f x y) <= c * (h x y) \<Longrightarrow>  | 
|
603  | 
(\<lambda>x. SUM y : A x. f x y) =o O(\<lambda>x. SUM y : A x. h x y)"  | 
|
| 23449 | 604  | 
apply (auto simp add: bigo_def)  | 
605  | 
apply (rule_tac x = "abs c" in exI)  | 
|
606  | 
apply (subst abs_of_nonneg) back back  | 
|
607  | 
apply (rule setsum_nonneg)  | 
|
608  | 
apply force  | 
|
609  | 
apply (subst setsum_right_distrib)  | 
|
610  | 
apply (rule allI)  | 
|
611  | 
apply (rule order_trans)  | 
|
612  | 
apply (rule setsum_abs)  | 
|
613  | 
apply (rule setsum_mono)  | 
|
| 43197 | 614  | 
apply (blast intro: order_trans mult_right_mono abs_ge_self)  | 
| 23449 | 615  | 
done  | 
616  | 
||
| 45575 | 617  | 
lemma bigo_setsum1: "\<forall>x y. 0 <= h x y \<Longrightarrow>  | 
618  | 
\<exists>c. \<forall>x y. abs (f x y) <= c * (h x y) \<Longrightarrow>  | 
|
619  | 
(\<lambda>x. SUM y : A x. f x y) =o O(\<lambda>x. SUM y : A x. h x y)"  | 
|
620  | 
by (metis (no_types) bigo_setsum_main)  | 
|
| 23449 | 621  | 
|
| 45575 | 622  | 
lemma bigo_setsum2: "\<forall>y. 0 <= h y \<Longrightarrow>  | 
623  | 
\<exists>c. \<forall>y. abs(f y) <= c * (h y) \<Longrightarrow>  | 
|
624  | 
(\<lambda>x. SUM y : A x. f y) =o O(\<lambda>x. SUM y : A x. h y)"  | 
|
| 43197 | 625  | 
by (rule bigo_setsum1, auto)  | 
| 23449 | 626  | 
|
| 45575 | 627  | 
lemma bigo_setsum3: "f =o O(h) \<Longrightarrow>  | 
628  | 
(\<lambda>x. SUM y : A x. (l x y) * f(k x y)) =o  | 
|
629  | 
O(\<lambda>x. SUM y : A x. abs(l x y * h(k x y)))"  | 
|
630  | 
apply (rule bigo_setsum1)  | 
|
631  | 
apply (rule allI)+  | 
|
632  | 
apply (rule abs_ge_zero)  | 
|
633  | 
apply (unfold bigo_def)  | 
|
634  | 
apply (auto simp add: abs_mult)  | 
|
635  | 
(* sledgehammer *)  | 
|
636  | 
apply (rule_tac x = c in exI)  | 
|
637  | 
apply (rule allI)+  | 
|
638  | 
apply (subst mult_left_commute)  | 
|
639  | 
apply (rule mult_left_mono)  | 
|
640  | 
apply (erule spec)  | 
|
641  | 
by (rule abs_ge_zero)  | 
|
| 23449 | 642  | 
|
| 45575 | 643  | 
lemma bigo_setsum4: "f =o g +o O(h) \<Longrightarrow>  | 
644  | 
(\<lambda>x. SUM y : A x. l x y * f(k x y)) =o  | 
|
645  | 
(\<lambda>x. SUM y : A x. l x y * g(k x y)) +o  | 
|
646  | 
O(\<lambda>x. SUM y : A x. abs(l x y * h(k x y)))"  | 
|
647  | 
apply (rule set_minus_imp_plus)  | 
|
648  | 
apply (subst fun_diff_def)  | 
|
649  | 
apply (subst setsum_subtractf [symmetric])  | 
|
650  | 
apply (subst right_diff_distrib [symmetric])  | 
|
651  | 
apply (rule bigo_setsum3)  | 
|
652  | 
apply (subst fun_diff_def [symmetric])  | 
|
653  | 
by (erule set_plus_imp_minus)  | 
|
| 23449 | 654  | 
|
| 45575 | 655  | 
lemma bigo_setsum5: "f =o O(h) \<Longrightarrow> \<forall>x y. 0 <= l x y \<Longrightarrow>  | 
656  | 
\<forall>x. 0 <= h x \<Longrightarrow>  | 
|
657  | 
(\<lambda>x. SUM y : A x. (l x y) * f(k x y)) =o  | 
|
658  | 
O(\<lambda>x. SUM y : A x. (l x y) * h(k x y))"  | 
|
659  | 
apply (subgoal_tac "(\<lambda>x. SUM y : A x. (l x y) * h(k x y)) =  | 
|
660  | 
(\<lambda>x. SUM y : A x. abs((l x y) * h(k x y)))")  | 
|
| 23449 | 661  | 
apply (erule ssubst)  | 
662  | 
apply (erule bigo_setsum3)  | 
|
663  | 
apply (rule ext)  | 
|
664  | 
apply (rule setsum_cong2)  | 
|
| 43197 | 665  | 
apply (thin_tac "f \<in> O(h)")  | 
| 24942 | 666  | 
apply (metis abs_of_nonneg zero_le_mult_iff)  | 
| 23449 | 667  | 
done  | 
668  | 
||
| 45575 | 669  | 
lemma bigo_setsum6: "f =o g +o O(h) \<Longrightarrow> \<forall>x y. 0 <= l x y \<Longrightarrow>  | 
670  | 
\<forall>x. 0 <= h x \<Longrightarrow>  | 
|
671  | 
(\<lambda>x. SUM y : A x. (l x y) * f(k x y)) =o  | 
|
672  | 
(\<lambda>x. SUM y : A x. (l x y) * g(k x y)) +o  | 
|
673  | 
O(\<lambda>x. SUM y : A x. (l x y) * h(k x y))"  | 
|
| 23449 | 674  | 
apply (rule set_minus_imp_plus)  | 
| 
26814
 
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
 
berghofe 
parents: 
26645 
diff
changeset
 | 
675  | 
apply (subst fun_diff_def)  | 
| 23449 | 676  | 
apply (subst setsum_subtractf [symmetric])  | 
677  | 
apply (subst right_diff_distrib [symmetric])  | 
|
678  | 
apply (rule bigo_setsum5)  | 
|
| 
26814
 
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
 
berghofe 
parents: 
26645 
diff
changeset
 | 
679  | 
apply (subst fun_diff_def [symmetric])  | 
| 23449 | 680  | 
apply (drule set_plus_imp_minus)  | 
681  | 
apply auto  | 
|
682  | 
done  | 
|
683  | 
||
684  | 
subsection {* Misc useful stuff *}
 | 
|
685  | 
||
| 45575 | 686  | 
lemma bigo_useful_intro: "A <= O(f) \<Longrightarrow> B <= O(f) \<Longrightarrow>  | 
| 
26814
 
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
 
berghofe 
parents: 
26645 
diff
changeset
 | 
687  | 
A \<oplus> B <= O(f)"  | 
| 23449 | 688  | 
apply (subst bigo_plus_idemp [symmetric])  | 
689  | 
apply (rule set_plus_mono2)  | 
|
690  | 
apply assumption+  | 
|
691  | 
done  | 
|
692  | 
||
| 45575 | 693  | 
lemma bigo_useful_add: "f =o O(h) \<Longrightarrow> g =o O(h) \<Longrightarrow> f + g =o O(h)"  | 
| 23449 | 694  | 
apply (subst bigo_plus_idemp [symmetric])  | 
695  | 
apply (rule set_plus_intro)  | 
|
696  | 
apply assumption+  | 
|
697  | 
done  | 
|
| 43197 | 698  | 
|
| 45575 | 699  | 
lemma bigo_useful_const_mult: "(c\<Colon>'a\<Colon>{linordered_field,number_ring}) ~= 0 \<Longrightarrow>
 | 
700  | 
(\<lambda>x. c) * f =o O(h) \<Longrightarrow> f =o O(h)"  | 
|
| 23449 | 701  | 
apply (rule subsetD)  | 
| 45575 | 702  | 
apply (subgoal_tac "(\<lambda>x. 1 / c) *o O(h) <= O(h)")  | 
| 23449 | 703  | 
apply assumption  | 
704  | 
apply (rule bigo_const_mult6)  | 
|
| 45575 | 705  | 
apply (subgoal_tac "f = (\<lambda>x. 1 / c) * ((\<lambda>x. c) * f)")  | 
| 23449 | 706  | 
apply (erule ssubst)  | 
707  | 
apply (erule set_times_intro2)  | 
|
| 43197 | 708  | 
apply (simp add: func_times)  | 
| 23449 | 709  | 
done  | 
710  | 
||
| 45575 | 711  | 
lemma bigo_fix: "(\<lambda>x. f ((x\<Colon>nat) + 1)) =o O(\<lambda>x. h(x + 1)) \<Longrightarrow> f 0 = 0 \<Longrightarrow>  | 
| 23449 | 712  | 
f =o O(h)"  | 
| 45575 | 713  | 
apply (simp add: bigo_alt_def)  | 
714  | 
by (metis abs_ge_zero abs_mult abs_of_pos abs_zero not0_implies_Suc)  | 
|
| 23449 | 715  | 
|
| 43197 | 716  | 
lemma bigo_fix2:  | 
| 45575 | 717  | 
"(\<lambda>x. f ((x\<Colon>nat) + 1)) =o (\<lambda>x. g(x + 1)) +o O(\<lambda>x. h(x + 1)) \<Longrightarrow>  | 
718  | 
f 0 = g 0 \<Longrightarrow> f =o g +o O(h)"  | 
|
| 23449 | 719  | 
apply (rule set_minus_imp_plus)  | 
720  | 
apply (rule bigo_fix)  | 
|
| 
26814
 
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
 
berghofe 
parents: 
26645 
diff
changeset
 | 
721  | 
apply (subst fun_diff_def)  | 
| 
 
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
 
berghofe 
parents: 
26645 
diff
changeset
 | 
722  | 
apply (subst fun_diff_def [symmetric])  | 
| 23449 | 723  | 
apply (rule set_plus_imp_minus)  | 
724  | 
apply simp  | 
|
| 
26814
 
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
 
berghofe 
parents: 
26645 
diff
changeset
 | 
725  | 
apply (simp add: fun_diff_def)  | 
| 23449 | 726  | 
done  | 
727  | 
||
728  | 
subsection {* Less than or equal to *}
 | 
|
729  | 
||
| 45575 | 730  | 
definition lesso :: "('a => 'b\<Colon>linordered_idom) => ('a => 'b) => ('a => 'b)" (infixl "<o" 70) where
 | 
731  | 
"f <o g == (\<lambda>x. max (f x - g x) 0)"  | 
|
| 23449 | 732  | 
|
| 45575 | 733  | 
lemma bigo_lesseq1: "f =o O(h) \<Longrightarrow> \<forall>x. abs (g x) <= abs (f x) \<Longrightarrow>  | 
| 23449 | 734  | 
g =o O(h)"  | 
735  | 
apply (unfold bigo_def)  | 
|
736  | 
apply clarsimp  | 
|
| 43197 | 737  | 
apply (blast intro: order_trans)  | 
| 23449 | 738  | 
done  | 
739  | 
||
| 45575 | 740  | 
lemma bigo_lesseq2: "f =o O(h) \<Longrightarrow> \<forall>x. abs (g x) <= f x \<Longrightarrow>  | 
| 23449 | 741  | 
g =o O(h)"  | 
742  | 
apply (erule bigo_lesseq1)  | 
|
| 43197 | 743  | 
apply (blast intro: abs_ge_self order_trans)  | 
| 23449 | 744  | 
done  | 
745  | 
||
| 45575 | 746  | 
lemma bigo_lesseq3: "f =o O(h) \<Longrightarrow> \<forall>x. 0 <= g x \<Longrightarrow> \<forall>x. g x <= f x \<Longrightarrow>  | 
| 23449 | 747  | 
g =o O(h)"  | 
748  | 
apply (erule bigo_lesseq2)  | 
|
749  | 
apply (rule allI)  | 
|
750  | 
apply (subst abs_of_nonneg)  | 
|
751  | 
apply (erule spec)+  | 
|
752  | 
done  | 
|
753  | 
||
| 45575 | 754  | 
lemma bigo_lesseq4: "f =o O(h) \<Longrightarrow>  | 
755  | 
\<forall>x. 0 <= g x \<Longrightarrow> \<forall>x. g x <= abs (f x) \<Longrightarrow>  | 
|
| 23449 | 756  | 
g =o O(h)"  | 
757  | 
apply (erule bigo_lesseq1)  | 
|
758  | 
apply (rule allI)  | 
|
759  | 
apply (subst abs_of_nonneg)  | 
|
760  | 
apply (erule spec)+  | 
|
761  | 
done  | 
|
762  | 
||
| 45575 | 763  | 
lemma bigo_lesso1: "\<forall>x. f x <= g x \<Longrightarrow> f <o g =o O(h)"  | 
| 36561 | 764  | 
apply (unfold lesso_def)  | 
| 45575 | 765  | 
apply (subgoal_tac "(\<lambda>x. max (f x - g x) 0) = 0")  | 
766  | 
apply (metis bigo_zero)  | 
|
767  | 
by (metis (lam_lifting, no_types) func_zero le_fun_def le_iff_diff_le_0  | 
|
768  | 
min_max.sup_absorb2 order_eq_iff)  | 
|
| 23449 | 769  | 
|
| 45575 | 770  | 
lemma bigo_lesso2: "f =o g +o O(h) \<Longrightarrow>  | 
771  | 
\<forall>x. 0 <= k x \<Longrightarrow> \<forall>x. k x <= f x \<Longrightarrow>  | 
|
| 23449 | 772  | 
k <o g =o O(h)"  | 
773  | 
apply (unfold lesso_def)  | 
|
774  | 
apply (rule bigo_lesseq4)  | 
|
775  | 
apply (erule set_plus_imp_minus)  | 
|
776  | 
apply (rule allI)  | 
|
777  | 
apply (rule le_maxI2)  | 
|
778  | 
apply (rule allI)  | 
|
| 
26814
 
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
 
berghofe 
parents: 
26645 
diff
changeset
 | 
779  | 
apply (subst fun_diff_def)  | 
| 23449 | 780  | 
apply (erule thin_rl)  | 
| 45575 | 781  | 
(* sledgehammer *)  | 
782  | 
apply (case_tac "0 <= k x - g x")  | 
|
783  | 
apply (metis (hide_lams, no_types) abs_le_iff add_le_imp_le_right diff_minus le_less  | 
|
784  | 
le_max_iff_disj min_max.le_supE min_max.sup_absorb2  | 
|
785  | 
min_max.sup_commute)  | 
|
786  | 
by (metis abs_ge_zero le_cases min_max.sup_absorb2)  | 
|
| 23449 | 787  | 
|
| 45575 | 788  | 
lemma bigo_lesso3: "f =o g +o O(h) \<Longrightarrow>  | 
789  | 
\<forall>x. 0 <= k x \<Longrightarrow> \<forall>x. g x <= k x \<Longrightarrow>  | 
|
| 23449 | 790  | 
f <o k =o O(h)"  | 
791  | 
apply (unfold lesso_def)  | 
|
792  | 
apply (rule bigo_lesseq4)  | 
|
793  | 
apply (erule set_plus_imp_minus)  | 
|
794  | 
apply (rule allI)  | 
|
795  | 
apply (rule le_maxI2)  | 
|
796  | 
apply (rule allI)  | 
|
| 
26814
 
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
 
berghofe 
parents: 
26645 
diff
changeset
 | 
797  | 
apply (subst fun_diff_def)  | 
| 45575 | 798  | 
apply (erule thin_rl)  | 
799  | 
(* sledgehammer *)  | 
|
| 23449 | 800  | 
apply (case_tac "0 <= f x - k x")  | 
| 45575 | 801  | 
apply simp  | 
| 23449 | 802  | 
apply (subst abs_of_nonneg)  | 
803  | 
apply (drule_tac x = x in spec) back  | 
|
| 45705 | 804  | 
apply (metis diff_less_0_iff_less linorder_not_le not_leE xt1(12) xt1(6))  | 
| 45575 | 805  | 
apply (metis add_minus_cancel diff_le_eq le_diff_eq uminus_add_conv_diff)  | 
| 
29511
 
7071b017cb35
migrated class package to new locale implementation
 
haftmann 
parents: 
28592 
diff
changeset
 | 
806  | 
apply (metis abs_ge_zero linorder_linear min_max.sup_absorb1 min_max.sup_commute)  | 
| 23449 | 807  | 
done  | 
808  | 
||
| 45705 | 809  | 
lemma bigo_lesso4:  | 
810  | 
  "f <o g =o O(k\<Colon>'a=>'b\<Colon>{linordered_field,number_ring}) \<Longrightarrow>
 | 
|
811  | 
g =o h +o O(k) \<Longrightarrow> f <o h =o O(k)"  | 
|
812  | 
apply (unfold lesso_def)  | 
|
813  | 
apply (drule set_plus_imp_minus)  | 
|
814  | 
apply (drule bigo_abs5) back  | 
|
815  | 
apply (simp add: fun_diff_def)  | 
|
816  | 
apply (drule bigo_useful_add, assumption)  | 
|
817  | 
apply (erule bigo_lesseq2) back  | 
|
818  | 
apply (rule allI)  | 
|
819  | 
by (auto simp add: func_plus fun_diff_def algebra_simps  | 
|
| 23449 | 820  | 
split: split_max abs_split)  | 
821  | 
||
| 45705 | 822  | 
lemma bigo_lesso5: "f <o g =o O(h) \<Longrightarrow> \<exists>C. \<forall>x. f x <= g x + C * abs (h x)"  | 
823  | 
apply (simp only: lesso_def bigo_alt_def)  | 
|
824  | 
apply clarsimp  | 
|
825  | 
by (metis abs_if abs_mult add_commute diff_le_eq less_not_permute)  | 
|
| 23449 | 826  | 
|
827  | 
end  |