author | haftmann |
Sun, 19 Feb 2012 15:30:35 +0100 | |
changeset 46553 | 50a7e97fe653 |
parent 46369 | 9ac0c64ad8e7 |
child 46644 | bd03e0890699 |
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: |
46364 | 23 |
"(\<exists>c\<Colon>'a\<Colon>linordered_idom. |
24 |
\<forall>x. abs (h x) \<le> c * abs (f x)) |
|
25 |
\<longleftrightarrow> (\<exists>c. 0 < c \<and> (\<forall>x. abs(h x) \<le> c * abs (f x)))" |
|
26 |
by (metis (no_types) abs_ge_zero |
|
45575 | 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 |
46364 | 35 |
"(\<exists>c\<Colon>'a\<Colon>linordered_idom. |
36 |
\<forall>x. abs (h x) \<le> c * abs (f x)) |
|
37 |
\<longleftrightarrow> (\<exists>c. 0 < c \<and> (\<forall>x. abs(h x) \<le> 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 |
46364 | 66 |
"(\<exists>c\<Colon>'a\<Colon>linordered_idom. |
67 |
\<forall>x. abs (h x) \<le> c * abs (f x)) |
|
68 |
\<longleftrightarrow> (\<exists>c. 0 < c \<and> (\<forall>x. abs(h x) \<le> 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 |
46364 | 89 |
"(\<exists>c\<Colon>'a\<Colon>linordered_idom. |
90 |
\<forall>x. abs (h x) \<le> c * abs (f x)) |
|
91 |
\<longleftrightarrow> (\<exists>c. 0 < c \<and> (\<forall>x. abs(h x) \<le> 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 |
46364 | 109 |
"(\<exists>c\<Colon>'a\<Colon>linordered_idom. |
110 |
\<forall>x. abs (h x) \<le> c * abs (f x)) |
|
111 |
\<longleftrightarrow> (\<exists>c. 0 < c \<and> (\<forall>x. abs(h x) \<le> 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 |
|
46364 | 128 |
lemma bigo_alt_def: "O(f) = {h. \<exists>c. (0 < c \<and> (\<forall>x. abs (h x) <= c * abs (f x)))}" |
23449 | 129 |
by (auto simp add: bigo_def bigo_pos_const) |
130 |
||
46364 | 131 |
lemma bigo_elt_subset [intro]: "f : O(g) \<Longrightarrow> O(f) \<le> O(g)" |
45575 | 132 |
apply (auto simp add: bigo_alt_def) |
133 |
apply (rule_tac x = "ca * c" in exI) |
|
46364 | 134 |
by (metis comm_semiring_1_class.normalizing_semiring_rules(7,19) |
135 |
mult_le_cancel_left_pos order_trans mult_pos_pos) |
|
23449 | 136 |
|
137 |
lemma bigo_refl [intro]: "f : O(f)" |
|
46364 | 138 |
unfolding bigo_def mem_Collect_eq |
36844 | 139 |
by (metis mult_1 order_refl) |
23449 | 140 |
|
141 |
lemma bigo_zero: "0 : O(g)" |
|
36561 | 142 |
apply (auto simp add: bigo_def func_zero) |
36844 | 143 |
by (metis mult_zero_left order_refl) |
23449 | 144 |
|
45575 | 145 |
lemma bigo_zero2: "O(\<lambda>x. 0) = {\<lambda>x. 0}" |
146 |
by (auto simp add: bigo_def) |
|
23449 | 147 |
|
43197 | 148 |
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
|
149 |
"O(f) \<oplus> O(f) <= O(f)" |
45575 | 150 |
apply (auto simp add: bigo_alt_def set_plus_def) |
151 |
apply (rule_tac x = "c + ca" in exI) |
|
152 |
apply auto |
|
153 |
apply (simp add: ring_distribs func_plus) |
|
154 |
by (metis order_trans abs_triangle_ineq add_mono) |
|
23449 | 155 |
|
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
156 |
lemma bigo_plus_idemp [simp]: "O(f) \<oplus> O(f) = O(f)" |
45575 | 157 |
by (metis bigo_plus_self_subset bigo_zero set_eq_subset set_zero_plus2) |
23449 | 158 |
|
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
159 |
lemma bigo_plus_subset [intro]: "O(f + g) <= O(f) \<oplus> O(g)" |
45575 | 160 |
apply (rule subsetI) |
161 |
apply (auto simp add: bigo_def bigo_pos_const func_plus set_plus_def) |
|
162 |
apply (subst bigo_pos_const [symmetric])+ |
|
163 |
apply (rule_tac x = "\<lambda>n. if abs (g n) <= (abs (f n)) then x n else 0" in exI) |
|
164 |
apply (rule conjI) |
|
165 |
apply (rule_tac x = "c + c" in exI) |
|
166 |
apply clarsimp |
|
167 |
apply auto |
|
23449 | 168 |
apply (subgoal_tac "c * abs (f xa + g xa) <= (c + c) * abs (f xa)") |
45575 | 169 |
apply (metis mult_2 order_trans) |
23449 | 170 |
apply (subgoal_tac "c * abs (f xa + g xa) <= c * (abs (f xa) + abs (g xa))") |
45575 | 171 |
apply (erule order_trans) |
172 |
apply (simp add: ring_distribs) |
|
23449 | 173 |
apply (rule mult_left_mono) |
45575 | 174 |
apply (simp add: abs_triangle_ineq) |
23449 | 175 |
apply (simp add: order_less_le) |
45575 | 176 |
apply (rule mult_nonneg_nonneg) |
23449 | 177 |
apply auto |
45575 | 178 |
apply (rule_tac x = "\<lambda>n. if (abs (f n)) < abs (g n) then x n else 0" in exI) |
179 |
apply (rule conjI) |
|
180 |
apply (rule_tac x = "c + c" in exI) |
|
181 |
apply auto |
|
182 |
apply (subgoal_tac "c * abs (f xa + g xa) <= (c + c) * abs (g xa)") |
|
183 |
apply (metis order_trans semiring_mult_2) |
|
184 |
apply (subgoal_tac "c * abs (f xa + g xa) <= c * (abs (f xa) + abs (g xa))") |
|
23449 | 185 |
apply (erule order_trans) |
23477
f4b83f03cac9
tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents:
23464
diff
changeset
|
186 |
apply (simp add: ring_distribs) |
45575 | 187 |
apply (metis abs_triangle_ineq mult_le_cancel_left_pos) |
188 |
by (metis abs_ge_zero abs_of_pos zero_le_mult_iff) |
|
23449 | 189 |
|
45575 | 190 |
lemma bigo_plus_subset2 [intro]: "A <= O(f) \<Longrightarrow> B <= O(f) \<Longrightarrow> A \<oplus> B <= O(f)" |
191 |
by (metis bigo_plus_idemp set_plus_mono2) |
|
23449 | 192 |
|
45575 | 193 |
lemma bigo_plus_eq: "\<forall>x. 0 <= f x \<Longrightarrow> \<forall>x. 0 <= g x \<Longrightarrow> O(f + g) = O(f) \<oplus> O(g)" |
194 |
apply (rule equalityI) |
|
195 |
apply (rule bigo_plus_subset) |
|
196 |
apply (simp add: bigo_alt_def set_plus_def func_plus) |
|
197 |
apply clarify |
|
198 |
(* sledgehammer *) |
|
199 |
apply (rule_tac x = "max c ca" in exI) |
|
46369 | 200 |
|
45575 | 201 |
apply (rule conjI) |
202 |
apply (metis less_max_iff_disj) |
|
203 |
apply clarify |
|
204 |
apply (drule_tac x = "xa" in spec)+ |
|
205 |
apply (subgoal_tac "0 <= f xa + g xa") |
|
206 |
apply (simp add: ring_distribs) |
|
207 |
apply (subgoal_tac "abs (a xa + b xa) <= abs (a xa) + abs (b xa)") |
|
208 |
apply (subgoal_tac "abs (a xa) + abs (b xa) <= |
|
209 |
max c ca * f xa + max c ca * g xa") |
|
210 |
apply (metis order_trans) |
|
23449 | 211 |
defer 1 |
45575 | 212 |
apply (metis abs_triangle_ineq) |
213 |
apply (metis add_nonneg_nonneg) |
|
46369 | 214 |
by (metis (no_types) add_mono le_maxI2 linorder_linear min_max.sup_absorb1 |
215 |
mult_right_mono xt1(6)) |
|
23449 | 216 |
|
45575 | 217 |
lemma bigo_bounded_alt: "\<forall>x. 0 <= f x \<Longrightarrow> \<forall>x. f x <= c * g x \<Longrightarrow> f : O(g)" |
218 |
apply (auto simp add: bigo_def) |
|
36561 | 219 |
(* Version 1: one-line proof *) |
45575 | 220 |
by (metis abs_le_D1 linorder_class.not_less order_less_le Orderings.xt1(12) abs_mult) |
23449 | 221 |
|
45575 | 222 |
lemma "\<forall>x. 0 <= f x \<Longrightarrow> \<forall>x. f x <= c * g x \<Longrightarrow> f : O(g)" |
36561 | 223 |
apply (auto simp add: bigo_def) |
224 |
(* Version 2: structured proof *) |
|
225 |
proof - |
|
226 |
assume "\<forall>x. f x \<le> c * g x" |
|
227 |
thus "\<exists>c. \<forall>x. f x \<le> c * \<bar>g x\<bar>" by (metis abs_mult abs_ge_self order_trans) |
|
23449 | 228 |
qed |
229 |
||
45575 | 230 |
lemma bigo_bounded: "\<forall>x. 0 <= f x \<Longrightarrow> \<forall>x. f x <= g x \<Longrightarrow> f : O(g)" |
231 |
apply (erule bigo_bounded_alt [of f 1 g]) |
|
232 |
by (metis mult_1) |
|
23449 | 233 |
|
45575 | 234 |
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 | 235 |
apply (rule set_minus_imp_plus) |
236 |
apply (rule bigo_bounded) |
|
46369 | 237 |
apply (metis add_le_cancel_left diff_add_cancel diff_self minus_apply |
238 |
comm_semiring_1_class.normalizing_semiring_rules(24)) |
|
239 |
by (metis add_le_cancel_left diff_add_cancel func_plus le_fun_def |
|
240 |
comm_semiring_1_class.normalizing_semiring_rules(24)) |
|
23449 | 241 |
|
45575 | 242 |
lemma bigo_abs: "(\<lambda>x. abs(f x)) =o O(f)" |
36561 | 243 |
apply (unfold bigo_def) |
244 |
apply auto |
|
36844 | 245 |
by (metis mult_1 order_refl) |
23449 | 246 |
|
45575 | 247 |
lemma bigo_abs2: "f =o O(\<lambda>x. abs(f x))" |
36561 | 248 |
apply (unfold bigo_def) |
249 |
apply auto |
|
36844 | 250 |
by (metis mult_1 order_refl) |
43197 | 251 |
|
45575 | 252 |
lemma bigo_abs3: "O(f) = O(\<lambda>x. abs(f x))" |
36561 | 253 |
proof - |
254 |
have F1: "\<forall>v u. u \<in> O(v) \<longrightarrow> O(u) \<subseteq> O(v)" by (metis bigo_elt_subset) |
|
255 |
have F2: "\<forall>u. (\<lambda>R. \<bar>u R\<bar>) \<in> O(u)" by (metis bigo_abs) |
|
256 |
have "\<forall>u. u \<in> O(\<lambda>R. \<bar>u R\<bar>)" by (metis bigo_abs2) |
|
257 |
thus "O(f) = O(\<lambda>x. \<bar>f x\<bar>)" using F1 F2 by auto |
|
43197 | 258 |
qed |
23449 | 259 |
|
45575 | 260 |
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 | 261 |
apply (drule set_plus_imp_minus) |
262 |
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
|
263 |
apply (subst fun_diff_def) |
23449 | 264 |
proof - |
265 |
assume a: "f - g : O(h)" |
|
45575 | 266 |
have "(\<lambda>x. abs (f x) - abs (g x)) =o O(\<lambda>x. abs(abs (f x) - abs (g x)))" |
23449 | 267 |
by (rule bigo_abs2) |
45575 | 268 |
also have "... <= O(\<lambda>x. abs (f x - g x))" |
23449 | 269 |
apply (rule bigo_elt_subset) |
270 |
apply (rule bigo_bounded) |
|
46369 | 271 |
apply (metis abs_ge_zero) |
272 |
by (metis abs_triangle_ineq3) |
|
23449 | 273 |
also have "... <= O(f - g)" |
274 |
apply (rule bigo_elt_subset) |
|
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
275 |
apply (subst fun_diff_def) |
23449 | 276 |
apply (rule bigo_abs) |
277 |
done |
|
278 |
also have "... <= O(h)" |
|
23464 | 279 |
using a by (rule bigo_elt_subset) |
45575 | 280 |
finally show "(\<lambda>x. abs (f x) - abs (g x)) : O(h)". |
23449 | 281 |
qed |
282 |
||
45575 | 283 |
lemma bigo_abs5: "f =o O(g) \<Longrightarrow> (\<lambda>x. abs(f x)) =o O(g)" |
23449 | 284 |
by (unfold bigo_def, auto) |
285 |
||
45575 | 286 |
lemma bigo_elt_subset2 [intro]: "f : g +o O(h) \<Longrightarrow> O(f) <= O(g) \<oplus> O(h)" |
23449 | 287 |
proof - |
288 |
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
|
289 |
also have "... <= O(g) \<oplus> O(h)" |
23449 | 290 |
by (auto del: subsetI) |
45575 | 291 |
also have "... = O(\<lambda>x. abs(g x)) \<oplus> O(\<lambda>x. abs(h x))" |
46369 | 292 |
by (metis bigo_abs3) |
45575 | 293 |
also have "... = O((\<lambda>x. abs(g x)) + (\<lambda>x. abs(h x)))" |
23449 | 294 |
by (rule bigo_plus_eq [symmetric], auto) |
295 |
finally have "f : ...". |
|
296 |
then have "O(f) <= ..." |
|
297 |
by (elim bigo_elt_subset) |
|
45575 | 298 |
also have "... = O(\<lambda>x. abs(g x)) \<oplus> O(\<lambda>x. abs(h x))" |
23449 | 299 |
by (rule bigo_plus_eq, auto) |
300 |
finally show ?thesis |
|
301 |
by (simp add: bigo_abs3 [symmetric]) |
|
302 |
qed |
|
303 |
||
46369 | 304 |
lemma bigo_mult [intro]: "O(f) \<otimes> O(g) <= O(f * g)" |
305 |
apply (rule subsetI) |
|
306 |
apply (subst bigo_def) |
|
307 |
apply (auto simp del: abs_mult mult_ac |
|
308 |
simp add: bigo_alt_def set_times_def func_times) |
|
45575 | 309 |
(* sledgehammer *) |
46369 | 310 |
apply (rule_tac x = "c * ca" in exI) |
311 |
apply (rule allI) |
|
312 |
apply (erule_tac x = x in allE)+ |
|
313 |
apply (subgoal_tac "c * ca * abs (f x * g x) = (c * abs(f x)) * (ca * abs (g x))") |
|
314 |
apply (metis (no_types) abs_ge_zero abs_mult mult_mono') |
|
315 |
by (metis mult_assoc mult_left_commute abs_of_pos mult_left_commute abs_mult) |
|
23449 | 316 |
|
317 |
lemma bigo_mult2 [intro]: "f *o O(g) <= O(f * g)" |
|
46369 | 318 |
by (metis bigo_mult bigo_refl set_times_mono3 subset_trans) |
23449 | 319 |
|
45575 | 320 |
lemma bigo_mult3: "f : O(h) \<Longrightarrow> g : O(j) \<Longrightarrow> f * g : O(h * j)" |
36561 | 321 |
by (metis bigo_mult set_rev_mp set_times_intro) |
23449 | 322 |
|
45575 | 323 |
lemma bigo_mult4 [intro]:"f : k +o O(h) \<Longrightarrow> g * f : (g * k) +o O(g * h)" |
23449 | 324 |
by (metis bigo_mult2 set_plus_mono_b set_times_intro2 set_times_plus_distrib) |
325 |
||
45575 | 326 |
lemma bigo_mult5: "\<forall>x. f x ~= 0 \<Longrightarrow> |
327 |
O(f * g) <= (f\<Colon>'a => ('b\<Colon>{linordered_field,number_ring})) *o O(g)" |
|
23449 | 328 |
proof - |
45575 | 329 |
assume a: "\<forall>x. f x ~= 0" |
23449 | 330 |
show "O(f * g) <= f *o O(g)" |
331 |
proof |
|
332 |
fix h |
|
41541 | 333 |
assume h: "h : O(f * g)" |
45575 | 334 |
then have "(\<lambda>x. 1 / (f x)) * h : (\<lambda>x. 1 / f x) *o O(f * g)" |
23449 | 335 |
by auto |
45575 | 336 |
also have "... <= O((\<lambda>x. 1 / f x) * (f * g))" |
23449 | 337 |
by (rule bigo_mult2) |
45575 | 338 |
also have "(\<lambda>x. 1 / f x) * (f * g) = g" |
43197 | 339 |
apply (simp add: func_times) |
46369 | 340 |
by (metis (lifting, no_types) a ext mult_ac(2) nonzero_divide_eq_eq) |
45575 | 341 |
finally have "(\<lambda>x. (1\<Colon>'b) / f x) * h : O(g)". |
342 |
then have "f * ((\<lambda>x. (1\<Colon>'b) / f x) * h) : f *o O(g)" |
|
23449 | 343 |
by auto |
45575 | 344 |
also have "f * ((\<lambda>x. (1\<Colon>'b) / f x) * h) = h" |
43197 | 345 |
apply (simp add: func_times) |
46369 | 346 |
by (metis (lifting, no_types) a eq_divide_imp ext |
347 |
comm_semiring_1_class.normalizing_semiring_rules(7)) |
|
23449 | 348 |
finally show "h : f *o O(g)". |
349 |
qed |
|
350 |
qed |
|
351 |
||
46369 | 352 |
lemma bigo_mult6: |
353 |
"\<forall>x. f x \<noteq> 0 \<Longrightarrow> O(f * g) = (f\<Colon>'a \<Rightarrow> ('b\<Colon>{linordered_field,number_ring})) *o O(g)" |
|
23449 | 354 |
by (metis bigo_mult2 bigo_mult5 order_antisym) |
355 |
||
356 |
(*proof requires relaxing relevance: 2007-01-25*) |
|
45705 | 357 |
declare bigo_mult6 [simp] |
358 |
||
46369 | 359 |
lemma bigo_mult7: |
360 |
"\<forall>x. f x \<noteq> 0 \<Longrightarrow> O(f * g) \<le> O(f\<Colon>'a \<Rightarrow> ('b\<Colon>{linordered_field,number_ring})) \<otimes> O(g)" |
|
361 |
by (metis bigo_refl bigo_mult6 set_times_mono3) |
|
23449 | 362 |
|
45575 | 363 |
declare bigo_mult6 [simp del] |
364 |
declare bigo_mult7 [intro!] |
|
365 |
||
46369 | 366 |
lemma bigo_mult8: |
367 |
"\<forall>x. f x \<noteq> 0 \<Longrightarrow> O(f * g) = O(f\<Colon>'a \<Rightarrow> ('b\<Colon>{linordered_field,number_ring})) \<otimes> O(g)" |
|
23449 | 368 |
by (metis bigo_mult bigo_mult7 order_antisym_conv) |
369 |
||
45575 | 370 |
lemma bigo_minus [intro]: "f : O(g) \<Longrightarrow> - f : O(g)" |
46369 | 371 |
by (auto simp add: bigo_def fun_Compl_def) |
23449 | 372 |
|
45575 | 373 |
lemma bigo_minus2: "f : g +o O(h) \<Longrightarrow> -f : -g +o O(h)" |
46369 | 374 |
by (metis (no_types) bigo_elt_subset bigo_minus bigo_mult4 bigo_refl |
375 |
comm_semiring_1_class.normalizing_semiring_rules(11) minus_mult_left |
|
376 |
set_plus_mono_b) |
|
23449 | 377 |
|
378 |
lemma bigo_minus3: "O(-f) = O(f)" |
|
46369 | 379 |
by (metis bigo_elt_subset bigo_minus bigo_refl equalityI minus_minus) |
23449 | 380 |
|
46369 | 381 |
lemma bigo_plus_absorb_lemma1: "f : O(g) \<Longrightarrow> f +o O(g) \<le> O(g)" |
382 |
by (metis bigo_plus_idemp set_plus_mono3) |
|
23449 | 383 |
|
46369 | 384 |
lemma bigo_plus_absorb_lemma2: "f : O(g) \<Longrightarrow> O(g) \<le> f +o O(g)" |
385 |
by (metis (no_types) bigo_minus bigo_plus_absorb_lemma1 right_minus |
|
386 |
set_plus_mono_b set_plus_rearrange2 set_zero_plus subsetI) |
|
23449 | 387 |
|
45575 | 388 |
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
|
389 |
by (metis bigo_plus_absorb_lemma1 bigo_plus_absorb_lemma2 order_eq_iff) |
23449 | 390 |
|
46369 | 391 |
lemma bigo_plus_absorb2 [intro]: "f : O(g) \<Longrightarrow> A <= O(g) \<Longrightarrow> f +o A \<le> O(g)" |
392 |
by (metis bigo_plus_absorb set_plus_mono) |
|
23449 | 393 |
|
45575 | 394 |
lemma bigo_add_commute_imp: "f : g +o O(h) \<Longrightarrow> g : f +o O(h)" |
46369 | 395 |
by (metis bigo_minus minus_diff_eq set_plus_imp_minus set_minus_plus) |
23449 | 396 |
|
397 |
lemma bigo_add_commute: "(f : g +o O(h)) = (g : f +o O(h))" |
|
46369 | 398 |
by (metis bigo_add_commute_imp) |
23449 | 399 |
|
45575 | 400 |
lemma bigo_const1: "(\<lambda>x. c) : O(\<lambda>x. 1)" |
23449 | 401 |
by (auto simp add: bigo_def mult_ac) |
402 |
||
46369 | 403 |
lemma bigo_const2 [intro]: "O(\<lambda>x. c) \<le> O(\<lambda>x. 1)" |
41865
4e8483cc2cc5
declare ext [intro]: Extensionality now available by default
paulson
parents:
41541
diff
changeset
|
404 |
by (metis bigo_const1 bigo_elt_subset) |
23449 | 405 |
|
45575 | 406 |
lemma bigo_const3: "(c\<Colon>'a\<Colon>{linordered_field,number_ring}) ~= 0 \<Longrightarrow> (\<lambda>x. 1) : O(\<lambda>x. c)" |
23449 | 407 |
apply (simp add: bigo_def) |
36561 | 408 |
by (metis abs_eq_0 left_inverse order_refl) |
23449 | 409 |
|
45575 | 410 |
lemma bigo_const4: "(c\<Colon>'a\<Colon>{linordered_field,number_ring}) ~= 0 \<Longrightarrow> O(\<lambda>x. 1) <= O(\<lambda>x. c)" |
46369 | 411 |
by (metis bigo_elt_subset bigo_const3) |
23449 | 412 |
|
45575 | 413 |
lemma bigo_const [simp]: "(c\<Colon>'a\<Colon>{linordered_field,number_ring}) ~= 0 \<Longrightarrow> |
414 |
O(\<lambda>x. c) = O(\<lambda>x. 1)" |
|
46369 | 415 |
by (metis bigo_const2 bigo_const4 equalityI) |
23449 | 416 |
|
45575 | 417 |
lemma bigo_const_mult1: "(\<lambda>x. c * f x) : O(f)" |
46369 | 418 |
apply (simp add: bigo_def abs_mult) |
36561 | 419 |
by (metis le_less) |
23449 | 420 |
|
46369 | 421 |
lemma bigo_const_mult2: "O(\<lambda>x. c * f x) \<le> O(f)" |
23449 | 422 |
by (rule bigo_elt_subset, rule bigo_const_mult1) |
423 |
||
45575 | 424 |
lemma bigo_const_mult3: "(c\<Colon>'a\<Colon>{linordered_field,number_ring}) ~= 0 \<Longrightarrow> f : O(\<lambda>x. c * f x)" |
425 |
apply (simp add: bigo_def) |
|
46369 | 426 |
by (metis (no_types) abs_mult mult_assoc mult_1 order_refl left_inverse) |
23449 | 427 |
|
46369 | 428 |
lemma bigo_const_mult4: |
429 |
"(c\<Colon>'a\<Colon>{linordered_field,number_ring}) \<noteq> 0 \<Longrightarrow> O(f) \<le> O(\<lambda>x. c * f x)" |
|
430 |
by (metis bigo_elt_subset bigo_const_mult3) |
|
23449 | 431 |
|
45575 | 432 |
lemma bigo_const_mult [simp]: "(c\<Colon>'a\<Colon>{linordered_field,number_ring}) ~= 0 \<Longrightarrow> |
433 |
O(\<lambda>x. c * f x) = O(f)" |
|
46369 | 434 |
by (metis equalityI bigo_const_mult2 bigo_const_mult4) |
23449 | 435 |
|
45575 | 436 |
lemma bigo_const_mult5 [simp]: "(c\<Colon>'a\<Colon>{linordered_field,number_ring}) ~= 0 \<Longrightarrow> |
437 |
(\<lambda>x. c) *o O(f) = O(f)" |
|
23449 | 438 |
apply (auto del: subsetI) |
439 |
apply (rule order_trans) |
|
440 |
apply (rule bigo_mult2) |
|
441 |
apply (simp add: func_times) |
|
442 |
apply (auto intro!: subsetI simp add: bigo_def elt_set_times_def func_times) |
|
45575 | 443 |
apply (rule_tac x = "\<lambda>y. inverse c * x y" in exI) |
43197 | 444 |
apply (rename_tac g d) |
24942 | 445 |
apply safe |
43197 | 446 |
apply (rule_tac [2] ext) |
447 |
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
|
448 |
apply simp |
24942 | 449 |
apply (simp add: mult_assoc [symmetric] abs_mult) |
39259
194014eb4f9f
replace two slow "metis" proofs with faster proofs
blanchet
parents:
38991
diff
changeset
|
450 |
(* couldn't get this proof without the step above *) |
194014eb4f9f
replace two slow "metis" proofs with faster proofs
blanchet
parents:
38991
diff
changeset
|
451 |
proof - |
194014eb4f9f
replace two slow "metis" proofs with faster proofs
blanchet
parents:
38991
diff
changeset
|
452 |
fix g :: "'b \<Rightarrow> 'a" and d :: 'a |
194014eb4f9f
replace two slow "metis" proofs with faster proofs
blanchet
parents:
38991
diff
changeset
|
453 |
assume A1: "c \<noteq> (0\<Colon>'a)" |
194014eb4f9f
replace two slow "metis" proofs with faster proofs
blanchet
parents:
38991
diff
changeset
|
454 |
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
|
455 |
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
|
456 |
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
|
457 |
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
|
458 |
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
|
459 |
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
|
460 |
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
|
461 |
using A2 by metis |
194014eb4f9f
replace two slow "metis" proofs with faster proofs
blanchet
parents:
38991
diff
changeset
|
462 |
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
|
463 |
using F3 by metis |
194014eb4f9f
replace two slow "metis" proofs with faster proofs
blanchet
parents:
38991
diff
changeset
|
464 |
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
|
465 |
by (metis comm_mult_left_mono) |
194014eb4f9f
replace two slow "metis" proofs with faster proofs
blanchet
parents:
38991
diff
changeset
|
466 |
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
|
467 |
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
|
468 |
qed |
23449 | 469 |
|
45575 | 470 |
lemma bigo_const_mult6 [intro]: "(\<lambda>x. c) *o O(f) <= O(f)" |
23449 | 471 |
apply (auto intro!: subsetI |
472 |
simp add: bigo_def elt_set_times_def func_times |
|
473 |
simp del: abs_mult mult_ac) |
|
45575 | 474 |
(* sledgehammer *) |
23449 | 475 |
apply (rule_tac x = "ca * (abs c)" in exI) |
476 |
apply (rule allI) |
|
477 |
apply (subgoal_tac "ca * abs(c) * abs(f x) = abs(c) * (ca * abs(f x))") |
|
478 |
apply (erule ssubst) |
|
479 |
apply (subst abs_mult) |
|
480 |
apply (rule mult_left_mono) |
|
481 |
apply (erule spec) |
|
482 |
apply simp |
|
46369 | 483 |
apply (simp add: mult_ac) |
23449 | 484 |
done |
485 |
||
45575 | 486 |
lemma bigo_const_mult7 [intro]: "f =o O(g) \<Longrightarrow> (\<lambda>x. c * f x) =o O(g)" |
46369 | 487 |
by (metis bigo_const_mult1 bigo_elt_subset order_less_le psubsetD) |
23449 | 488 |
|
45575 | 489 |
lemma bigo_compose1: "f =o O(g) \<Longrightarrow> (\<lambda>x. f(k x)) =o O(\<lambda>x. g(k x))" |
23449 | 490 |
by (unfold bigo_def, auto) |
491 |
||
46369 | 492 |
lemma bigo_compose2: |
493 |
"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))" |
|
494 |
apply (simp only: set_minus_plus [symmetric] diff_minus fun_Compl_def func_plus) |
|
495 |
by (erule bigo_compose1) |
|
23449 | 496 |
|
497 |
subsection {* Setsum *} |
|
498 |
||
45575 | 499 |
lemma bigo_setsum_main: "\<forall>x. \<forall>y \<in> A x. 0 <= h x y \<Longrightarrow> |
500 |
\<exists>c. \<forall>x. \<forall>y \<in> A x. abs (f x y) <= c * (h x y) \<Longrightarrow> |
|
501 |
(\<lambda>x. SUM y : A x. f x y) =o O(\<lambda>x. SUM y : A x. h x y)" |
|
46369 | 502 |
apply (auto simp add: bigo_def) |
503 |
apply (rule_tac x = "abs c" in exI) |
|
504 |
apply (subst abs_of_nonneg) back back |
|
505 |
apply (rule setsum_nonneg) |
|
506 |
apply force |
|
507 |
apply (subst setsum_right_distrib) |
|
508 |
apply (rule allI) |
|
509 |
apply (rule order_trans) |
|
510 |
apply (rule setsum_abs) |
|
511 |
apply (rule setsum_mono) |
|
512 |
by (metis abs_ge_self abs_mult_pos order_trans) |
|
23449 | 513 |
|
45575 | 514 |
lemma bigo_setsum1: "\<forall>x y. 0 <= h x y \<Longrightarrow> |
515 |
\<exists>c. \<forall>x y. abs (f x y) <= c * (h x y) \<Longrightarrow> |
|
516 |
(\<lambda>x. SUM y : A x. f x y) =o O(\<lambda>x. SUM y : A x. h x y)" |
|
517 |
by (metis (no_types) bigo_setsum_main) |
|
23449 | 518 |
|
45575 | 519 |
lemma bigo_setsum2: "\<forall>y. 0 <= h y \<Longrightarrow> |
46369 | 520 |
\<exists>c. \<forall>y. abs (f y) <= c * (h y) \<Longrightarrow> |
45575 | 521 |
(\<lambda>x. SUM y : A x. f y) =o O(\<lambda>x. SUM y : A x. h y)" |
46369 | 522 |
apply (rule bigo_setsum1) |
523 |
by metis+ |
|
23449 | 524 |
|
45575 | 525 |
lemma bigo_setsum3: "f =o O(h) \<Longrightarrow> |
526 |
(\<lambda>x. SUM y : A x. (l x y) * f(k x y)) =o |
|
527 |
O(\<lambda>x. SUM y : A x. abs(l x y * h(k x y)))" |
|
528 |
apply (rule bigo_setsum1) |
|
529 |
apply (rule allI)+ |
|
530 |
apply (rule abs_ge_zero) |
|
531 |
apply (unfold bigo_def) |
|
532 |
apply (auto simp add: abs_mult) |
|
46369 | 533 |
by (metis abs_ge_zero mult_left_commute mult_left_mono) |
23449 | 534 |
|
45575 | 535 |
lemma bigo_setsum4: "f =o g +o O(h) \<Longrightarrow> |
536 |
(\<lambda>x. SUM y : A x. l x y * f(k x y)) =o |
|
537 |
(\<lambda>x. SUM y : A x. l x y * g(k x y)) +o |
|
538 |
O(\<lambda>x. SUM y : A x. abs(l x y * h(k x y)))" |
|
539 |
apply (rule set_minus_imp_plus) |
|
540 |
apply (subst fun_diff_def) |
|
541 |
apply (subst setsum_subtractf [symmetric]) |
|
542 |
apply (subst right_diff_distrib [symmetric]) |
|
543 |
apply (rule bigo_setsum3) |
|
46369 | 544 |
by (metis (lifting, no_types) fun_diff_def set_plus_imp_minus ext) |
23449 | 545 |
|
45575 | 546 |
lemma bigo_setsum5: "f =o O(h) \<Longrightarrow> \<forall>x y. 0 <= l x y \<Longrightarrow> |
547 |
\<forall>x. 0 <= h x \<Longrightarrow> |
|
548 |
(\<lambda>x. SUM y : A x. (l x y) * f(k x y)) =o |
|
549 |
O(\<lambda>x. SUM y : A x. (l x y) * h(k x y))" |
|
46369 | 550 |
apply (subgoal_tac "(\<lambda>x. SUM y : A x. (l x y) * h(k x y)) = |
45575 | 551 |
(\<lambda>x. SUM y : A x. abs((l x y) * h(k x y)))") |
46369 | 552 |
apply (erule ssubst) |
553 |
apply (erule bigo_setsum3) |
|
554 |
apply (rule ext) |
|
555 |
apply (rule setsum_cong2) |
|
556 |
by (metis abs_of_nonneg zero_le_mult_iff) |
|
23449 | 557 |
|
45575 | 558 |
lemma bigo_setsum6: "f =o g +o O(h) \<Longrightarrow> \<forall>x y. 0 <= l x y \<Longrightarrow> |
559 |
\<forall>x. 0 <= h x \<Longrightarrow> |
|
560 |
(\<lambda>x. SUM y : A x. (l x y) * f(k x y)) =o |
|
561 |
(\<lambda>x. SUM y : A x. (l x y) * g(k x y)) +o |
|
562 |
O(\<lambda>x. SUM y : A x. (l x y) * h(k x y))" |
|
23449 | 563 |
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
|
564 |
apply (subst fun_diff_def) |
23449 | 565 |
apply (subst setsum_subtractf [symmetric]) |
566 |
apply (subst right_diff_distrib [symmetric]) |
|
567 |
apply (rule bigo_setsum5) |
|
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
568 |
apply (subst fun_diff_def [symmetric]) |
23449 | 569 |
apply (drule set_plus_imp_minus) |
570 |
apply auto |
|
571 |
done |
|
572 |
||
573 |
subsection {* Misc useful stuff *} |
|
574 |
||
45575 | 575 |
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
|
576 |
A \<oplus> B <= O(f)" |
23449 | 577 |
apply (subst bigo_plus_idemp [symmetric]) |
578 |
apply (rule set_plus_mono2) |
|
579 |
apply assumption+ |
|
580 |
done |
|
581 |
||
45575 | 582 |
lemma bigo_useful_add: "f =o O(h) \<Longrightarrow> g =o O(h) \<Longrightarrow> f + g =o O(h)" |
23449 | 583 |
apply (subst bigo_plus_idemp [symmetric]) |
584 |
apply (rule set_plus_intro) |
|
585 |
apply assumption+ |
|
586 |
done |
|
43197 | 587 |
|
45575 | 588 |
lemma bigo_useful_const_mult: "(c\<Colon>'a\<Colon>{linordered_field,number_ring}) ~= 0 \<Longrightarrow> |
589 |
(\<lambda>x. c) * f =o O(h) \<Longrightarrow> f =o O(h)" |
|
23449 | 590 |
apply (rule subsetD) |
45575 | 591 |
apply (subgoal_tac "(\<lambda>x. 1 / c) *o O(h) <= O(h)") |
23449 | 592 |
apply assumption |
593 |
apply (rule bigo_const_mult6) |
|
45575 | 594 |
apply (subgoal_tac "f = (\<lambda>x. 1 / c) * ((\<lambda>x. c) * f)") |
23449 | 595 |
apply (erule ssubst) |
596 |
apply (erule set_times_intro2) |
|
43197 | 597 |
apply (simp add: func_times) |
23449 | 598 |
done |
599 |
||
45575 | 600 |
lemma bigo_fix: "(\<lambda>x. f ((x\<Colon>nat) + 1)) =o O(\<lambda>x. h(x + 1)) \<Longrightarrow> f 0 = 0 \<Longrightarrow> |
23449 | 601 |
f =o O(h)" |
45575 | 602 |
apply (simp add: bigo_alt_def) |
603 |
by (metis abs_ge_zero abs_mult abs_of_pos abs_zero not0_implies_Suc) |
|
23449 | 604 |
|
43197 | 605 |
lemma bigo_fix2: |
45575 | 606 |
"(\<lambda>x. f ((x\<Colon>nat) + 1)) =o (\<lambda>x. g(x + 1)) +o O(\<lambda>x. h(x + 1)) \<Longrightarrow> |
607 |
f 0 = g 0 \<Longrightarrow> f =o g +o O(h)" |
|
23449 | 608 |
apply (rule set_minus_imp_plus) |
609 |
apply (rule bigo_fix) |
|
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
610 |
apply (subst fun_diff_def) |
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
611 |
apply (subst fun_diff_def [symmetric]) |
23449 | 612 |
apply (rule set_plus_imp_minus) |
613 |
apply simp |
|
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
614 |
apply (simp add: fun_diff_def) |
23449 | 615 |
done |
616 |
||
617 |
subsection {* Less than or equal to *} |
|
618 |
||
45575 | 619 |
definition lesso :: "('a => 'b\<Colon>linordered_idom) => ('a => 'b) => ('a => 'b)" (infixl "<o" 70) where |
620 |
"f <o g == (\<lambda>x. max (f x - g x) 0)" |
|
23449 | 621 |
|
45575 | 622 |
lemma bigo_lesseq1: "f =o O(h) \<Longrightarrow> \<forall>x. abs (g x) <= abs (f x) \<Longrightarrow> |
23449 | 623 |
g =o O(h)" |
624 |
apply (unfold bigo_def) |
|
625 |
apply clarsimp |
|
43197 | 626 |
apply (blast intro: order_trans) |
23449 | 627 |
done |
628 |
||
45575 | 629 |
lemma bigo_lesseq2: "f =o O(h) \<Longrightarrow> \<forall>x. abs (g x) <= f x \<Longrightarrow> |
23449 | 630 |
g =o O(h)" |
631 |
apply (erule bigo_lesseq1) |
|
43197 | 632 |
apply (blast intro: abs_ge_self order_trans) |
23449 | 633 |
done |
634 |
||
45575 | 635 |
lemma bigo_lesseq3: "f =o O(h) \<Longrightarrow> \<forall>x. 0 <= g x \<Longrightarrow> \<forall>x. g x <= f x \<Longrightarrow> |
23449 | 636 |
g =o O(h)" |
637 |
apply (erule bigo_lesseq2) |
|
638 |
apply (rule allI) |
|
639 |
apply (subst abs_of_nonneg) |
|
640 |
apply (erule spec)+ |
|
641 |
done |
|
642 |
||
45575 | 643 |
lemma bigo_lesseq4: "f =o O(h) \<Longrightarrow> |
644 |
\<forall>x. 0 <= g x \<Longrightarrow> \<forall>x. g x <= abs (f x) \<Longrightarrow> |
|
23449 | 645 |
g =o O(h)" |
646 |
apply (erule bigo_lesseq1) |
|
647 |
apply (rule allI) |
|
648 |
apply (subst abs_of_nonneg) |
|
649 |
apply (erule spec)+ |
|
650 |
done |
|
651 |
||
45575 | 652 |
lemma bigo_lesso1: "\<forall>x. f x <= g x \<Longrightarrow> f <o g =o O(h)" |
36561 | 653 |
apply (unfold lesso_def) |
45575 | 654 |
apply (subgoal_tac "(\<lambda>x. max (f x - g x) 0) = 0") |
655 |
apply (metis bigo_zero) |
|
46364 | 656 |
by (metis (lifting, no_types) func_zero le_fun_def le_iff_diff_le_0 |
45575 | 657 |
min_max.sup_absorb2 order_eq_iff) |
23449 | 658 |
|
45575 | 659 |
lemma bigo_lesso2: "f =o g +o O(h) \<Longrightarrow> |
660 |
\<forall>x. 0 <= k x \<Longrightarrow> \<forall>x. k x <= f x \<Longrightarrow> |
|
23449 | 661 |
k <o g =o O(h)" |
662 |
apply (unfold lesso_def) |
|
663 |
apply (rule bigo_lesseq4) |
|
664 |
apply (erule set_plus_imp_minus) |
|
665 |
apply (rule allI) |
|
666 |
apply (rule le_maxI2) |
|
667 |
apply (rule allI) |
|
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
668 |
apply (subst fun_diff_def) |
23449 | 669 |
apply (erule thin_rl) |
45575 | 670 |
(* sledgehammer *) |
671 |
apply (case_tac "0 <= k x - g x") |
|
672 |
apply (metis (hide_lams, no_types) abs_le_iff add_le_imp_le_right diff_minus le_less |
|
673 |
le_max_iff_disj min_max.le_supE min_max.sup_absorb2 |
|
674 |
min_max.sup_commute) |
|
675 |
by (metis abs_ge_zero le_cases min_max.sup_absorb2) |
|
23449 | 676 |
|
45575 | 677 |
lemma bigo_lesso3: "f =o g +o O(h) \<Longrightarrow> |
678 |
\<forall>x. 0 <= k x \<Longrightarrow> \<forall>x. g x <= k x \<Longrightarrow> |
|
23449 | 679 |
f <o k =o O(h)" |
680 |
apply (unfold lesso_def) |
|
681 |
apply (rule bigo_lesseq4) |
|
682 |
apply (erule set_plus_imp_minus) |
|
683 |
apply (rule allI) |
|
684 |
apply (rule le_maxI2) |
|
685 |
apply (rule allI) |
|
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
686 |
apply (subst fun_diff_def) |
45575 | 687 |
apply (erule thin_rl) |
688 |
(* sledgehammer *) |
|
23449 | 689 |
apply (case_tac "0 <= f x - k x") |
45575 | 690 |
apply simp |
23449 | 691 |
apply (subst abs_of_nonneg) |
692 |
apply (drule_tac x = x in spec) back |
|
45705 | 693 |
apply (metis diff_less_0_iff_less linorder_not_le not_leE xt1(12) xt1(6)) |
45575 | 694 |
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
|
695 |
apply (metis abs_ge_zero linorder_linear min_max.sup_absorb1 min_max.sup_commute) |
23449 | 696 |
done |
697 |
||
45705 | 698 |
lemma bigo_lesso4: |
699 |
"f <o g =o O(k\<Colon>'a=>'b\<Colon>{linordered_field,number_ring}) \<Longrightarrow> |
|
700 |
g =o h +o O(k) \<Longrightarrow> f <o h =o O(k)" |
|
701 |
apply (unfold lesso_def) |
|
702 |
apply (drule set_plus_imp_minus) |
|
703 |
apply (drule bigo_abs5) back |
|
704 |
apply (simp add: fun_diff_def) |
|
705 |
apply (drule bigo_useful_add, assumption) |
|
706 |
apply (erule bigo_lesseq2) back |
|
707 |
apply (rule allI) |
|
708 |
by (auto simp add: func_plus fun_diff_def algebra_simps |
|
23449 | 709 |
split: split_max abs_split) |
710 |
||
45705 | 711 |
lemma bigo_lesso5: "f <o g =o O(h) \<Longrightarrow> \<exists>C. \<forall>x. f x <= g x + C * abs (h x)" |
712 |
apply (simp only: lesso_def bigo_alt_def) |
|
713 |
apply clarsimp |
|
714 |
by (metis abs_if abs_mult add_commute diff_le_eq less_not_permute) |
|
23449 | 715 |
|
716 |
end |