author | haftmann |
Mon, 12 Jul 2010 08:58:27 +0200 | |
changeset 37766 | a779f463bae4 |
parent 37320 | 06c7a2f231fe |
child 38622 | 86fc906dcd86 |
permissions | -rw-r--r-- |
33027 | 1 |
(* Title: HOL/Metis_Examples/BigO.thy |
23449 | 2 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
3 |
||
33027 | 4 |
Testing the metis method. |
23449 | 5 |
*) |
6 |
||
7 |
header {* Big O notation *} |
|
8 |
||
9 |
theory BigO |
|
29823
0ab754d13ccd
session Reflecion renamed to Decision_Procs, moved Dense_Linear_Order there
haftmann
parents:
29667
diff
changeset
|
10 |
imports "~~/src/HOL/Decision_Procs/Dense_Linear_Order" Main SetsAndFunctions |
23449 | 11 |
begin |
12 |
||
13 |
subsection {* Definitions *} |
|
14 |
||
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33027
diff
changeset
|
15 |
definition bigo :: "('a => 'b::linordered_idom) => ('a => 'b) set" ("(1O'(_'))") where |
23449 | 16 |
"O(f::('a => 'b)) == {h. EX c. ALL x. abs (h x) <= c * abs (f x)}" |
17 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
18 |
declare [[ atp_problem_prefix = "BigO__bigo_pos_const" ]] |
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33027
diff
changeset
|
19 |
lemma bigo_pos_const: "(EX (c::'a::linordered_idom). |
23449 | 20 |
ALL x. (abs (h x)) <= (c * (abs (f x)))) |
21 |
= (EX c. 0 < c & (ALL x. (abs(h x)) <= (c * (abs (f x)))))" |
|
22 |
apply auto |
|
23 |
apply (case_tac "c = 0", simp) |
|
24 |
apply (rule_tac x = "1" in exI, simp) |
|
25304
7491c00f0915
removed subclass edge ordered_ring < lordered_ring
haftmann
parents:
25087
diff
changeset
|
25 |
apply (rule_tac x = "abs c" in exI, auto) |
36561 | 26 |
apply (metis abs_ge_zero abs_of_nonneg Orderings.xt1(6) abs_mult) |
23449 | 27 |
done |
28 |
||
36407 | 29 |
(*** Now various verions with an increasing shrink factor ***) |
23449 | 30 |
|
36925 | 31 |
sledgehammer_params [isar_proof, isar_shrink_factor = 1] |
23449 | 32 |
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33027
diff
changeset
|
33 |
lemma (*bigo_pos_const:*) "(EX (c::'a::linordered_idom). |
23449 | 34 |
ALL x. (abs (h x)) <= (c * (abs (f x)))) |
35 |
= (EX c. 0 < c & (ALL x. (abs(h x)) <= (c * (abs (f x)))))" |
|
36 |
apply auto |
|
37 |
apply (case_tac "c = 0", simp) |
|
38 |
apply (rule_tac x = "1" in exI, simp) |
|
39 |
apply (rule_tac x = "abs c" in exI, auto) |
|
36561 | 40 |
proof - |
41 |
fix c :: 'a and x :: 'b |
|
42 |
assume A1: "\<forall>x. \<bar>h x\<bar> \<le> c * \<bar>f x\<bar>" |
|
43 |
have F1: "\<forall>x\<^isub>1\<Colon>'a\<Colon>linordered_idom. 0 \<le> \<bar>x\<^isub>1\<bar>" by (metis abs_ge_zero) |
|
36844 | 44 |
have F2: "\<forall>x\<^isub>1\<Colon>'a\<Colon>linordered_idom. 1 * x\<^isub>1 = x\<^isub>1" by (metis mult_1) |
36561 | 45 |
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) |
46 |
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>" |
|
47 |
by (metis abs_mult) |
|
48 |
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" |
|
49 |
by (metis abs_mult_pos) |
|
50 |
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) |
|
51 |
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) |
|
52 |
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) |
|
53 |
hence "\<forall>x\<^isub>3. \<bar>c * \<bar>f x\<^isub>3\<bar>\<bar> = c * \<bar>f x\<^isub>3\<bar>" by (metis F1) |
|
54 |
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) |
|
55 |
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) |
|
56 |
hence "\<forall>x\<^isub>3. c * \<bar>f x\<^isub>3\<bar> = \<bar>c * f x\<^isub>3\<bar>" by (metis F1) |
|
57 |
hence "\<bar>h x\<bar> \<le> \<bar>c * f x\<bar>" by (metis A1) |
|
58 |
thus "\<bar>h x\<bar> \<le> \<bar>c\<bar> * \<bar>f x\<bar>" by (metis F4) |
|
23449 | 59 |
qed |
60 |
||
36925 | 61 |
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
|
62 |
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33027
diff
changeset
|
63 |
lemma (*bigo_pos_const:*) "(EX (c::'a::linordered_idom). |
23449 | 64 |
ALL x. (abs (h x)) <= (c * (abs (f x)))) |
65 |
= (EX c. 0 < c & (ALL x. (abs(h x)) <= (c * (abs (f x)))))" |
|
66 |
apply auto |
|
67 |
apply (case_tac "c = 0", simp) |
|
68 |
apply (rule_tac x = "1" in exI, simp) |
|
36844 | 69 |
apply (rule_tac x = "abs c" in exI, auto) |
36561 | 70 |
proof - |
71 |
fix c :: 'a and x :: 'b |
|
72 |
assume A1: "\<forall>x. \<bar>h x\<bar> \<le> c * \<bar>f x\<bar>" |
|
36844 | 73 |
have F1: "\<forall>x\<^isub>1\<Colon>'a\<Colon>linordered_idom. 1 * x\<^isub>1 = x\<^isub>1" by (metis mult_1) |
36561 | 74 |
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>" |
75 |
by (metis abs_mult) |
|
76 |
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) |
|
77 |
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) |
|
78 |
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) |
|
79 |
hence "\<bar>h x\<bar> \<le> \<bar>c * f x\<bar>" by (metis A1 abs_ge_zero) |
|
80 |
thus "\<bar>h x\<bar> \<le> \<bar>c\<bar> * \<bar>f x\<bar>" by (metis F2) |
|
23449 | 81 |
qed |
82 |
||
36925 | 83 |
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
|
84 |
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33027
diff
changeset
|
85 |
lemma (*bigo_pos_const:*) "(EX (c::'a::linordered_idom). |
23449 | 86 |
ALL x. (abs (h x)) <= (c * (abs (f x)))) |
87 |
= (EX c. 0 < c & (ALL x. (abs(h x)) <= (c * (abs (f x)))))" |
|
88 |
apply auto |
|
89 |
apply (case_tac "c = 0", simp) |
|
90 |
apply (rule_tac x = "1" in exI, simp) |
|
36561 | 91 |
apply (rule_tac x = "abs c" in exI, auto) |
92 |
proof - |
|
93 |
fix c :: 'a and x :: 'b |
|
94 |
assume A1: "\<forall>x. \<bar>h x\<bar> \<le> c * \<bar>f x\<bar>" |
|
36844 | 95 |
have F1: "\<forall>x\<^isub>1\<Colon>'a\<Colon>linordered_idom. 1 * x\<^isub>1 = x\<^isub>1" by (metis mult_1) |
36561 | 96 |
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) |
97 |
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) |
|
98 |
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) |
|
99 |
thus "\<bar>h x\<bar> \<le> \<bar>c\<bar> * \<bar>f x\<bar>" by (metis A1 abs_mult abs_ge_zero) |
|
23449 | 100 |
qed |
101 |
||
36925 | 102 |
sledgehammer_params [isar_proof, isar_shrink_factor = 4] |
24545 | 103 |
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33027
diff
changeset
|
104 |
lemma (*bigo_pos_const:*) "(EX (c::'a::linordered_idom). |
24545 | 105 |
ALL x. (abs (h x)) <= (c * (abs (f x)))) |
106 |
= (EX c. 0 < c & (ALL x. (abs(h x)) <= (c * (abs (f x)))))" |
|
107 |
apply auto |
|
108 |
apply (case_tac "c = 0", simp) |
|
109 |
apply (rule_tac x = "1" in exI, simp) |
|
36561 | 110 |
apply (rule_tac x = "abs c" in exI, auto) |
111 |
proof - |
|
112 |
fix c :: 'a and x :: 'b |
|
113 |
assume A1: "\<forall>x. \<bar>h x\<bar> \<le> c * \<bar>f x\<bar>" |
|
36844 | 114 |
have "\<forall>x\<^isub>1\<Colon>'a\<Colon>linordered_idom. 1 * x\<^isub>1 = x\<^isub>1" by (metis mult_1) |
36561 | 115 |
hence "\<forall>x\<^isub>3. \<bar>c * \<bar>f x\<^isub>3\<bar>\<bar> = c * \<bar>f x\<^isub>3\<bar>" |
116 |
by (metis A1 abs_ge_zero order_trans abs_mult_pos abs_one) |
|
117 |
hence "\<bar>h x\<bar> \<le> \<bar>c * f x\<bar>" by (metis A1 abs_ge_zero abs_mult_pos abs_mult) |
|
118 |
thus "\<bar>h x\<bar> \<le> \<bar>c\<bar> * \<bar>f x\<bar>" by (metis abs_mult) |
|
24545 | 119 |
qed |
120 |
||
36925 | 121 |
sledgehammer_params [isar_proof, isar_shrink_factor = 1] |
24545 | 122 |
|
23449 | 123 |
lemma bigo_alt_def: "O(f) = |
124 |
{h. EX c. (0 < c & (ALL x. abs (h x) <= c * abs (f x)))}" |
|
125 |
by (auto simp add: bigo_def bigo_pos_const) |
|
126 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
127 |
declare [[ atp_problem_prefix = "BigO__bigo_elt_subset" ]] |
23449 | 128 |
lemma bigo_elt_subset [intro]: "f : O(g) ==> O(f) <= O(g)" |
129 |
apply (auto simp add: bigo_alt_def) |
|
130 |
apply (rule_tac x = "ca * c" in exI) |
|
131 |
apply (rule conjI) |
|
132 |
apply (rule mult_pos_pos) |
|
133 |
apply (assumption)+ |
|
36844 | 134 |
(*sledgehammer*) |
23449 | 135 |
apply (rule allI) |
136 |
apply (drule_tac x = "xa" in spec)+ |
|
36844 | 137 |
apply (subgoal_tac "ca * abs(f xa) <= ca * (c * abs(g xa))") |
23449 | 138 |
apply (erule order_trans) |
139 |
apply (simp add: mult_ac) |
|
140 |
apply (rule mult_left_mono, assumption) |
|
36844 | 141 |
apply (rule order_less_imp_le, assumption) |
23449 | 142 |
done |
143 |
||
144 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
145 |
declare [[ atp_problem_prefix = "BigO__bigo_refl" ]] |
23449 | 146 |
lemma bigo_refl [intro]: "f : O(f)" |
36561 | 147 |
apply (auto simp add: bigo_def) |
36844 | 148 |
by (metis mult_1 order_refl) |
23449 | 149 |
|
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
150 |
declare [[ atp_problem_prefix = "BigO__bigo_zero" ]] |
23449 | 151 |
lemma bigo_zero: "0 : O(g)" |
36561 | 152 |
apply (auto simp add: bigo_def func_zero) |
36844 | 153 |
by (metis mult_zero_left order_refl) |
23449 | 154 |
|
155 |
lemma bigo_zero2: "O(%x.0) = {%x.0}" |
|
156 |
apply (auto simp add: bigo_def) |
|
157 |
apply (rule ext) |
|
158 |
apply auto |
|
159 |
done |
|
160 |
||
161 |
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
|
162 |
"O(f) \<oplus> O(f) <= O(f)" |
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
163 |
apply (auto simp add: bigo_alt_def set_plus_def) |
23449 | 164 |
apply (rule_tac x = "c + ca" in exI) |
165 |
apply auto |
|
23477
f4b83f03cac9
tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents:
23464
diff
changeset
|
166 |
apply (simp add: ring_distribs func_plus) |
23449 | 167 |
apply (blast intro:order_trans abs_triangle_ineq add_mono elim:) |
168 |
done |
|
169 |
||
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
170 |
lemma bigo_plus_idemp [simp]: "O(f) \<oplus> O(f) = O(f)" |
23449 | 171 |
apply (rule equalityI) |
172 |
apply (rule bigo_plus_self_subset) |
|
173 |
apply (rule set_zero_plus2) |
|
174 |
apply (rule bigo_zero) |
|
175 |
done |
|
176 |
||
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
177 |
lemma bigo_plus_subset [intro]: "O(f + g) <= O(f) \<oplus> O(g)" |
23449 | 178 |
apply (rule subsetI) |
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
179 |
apply (auto simp add: bigo_def bigo_pos_const func_plus set_plus_def) |
23449 | 180 |
apply (subst bigo_pos_const [symmetric])+ |
181 |
apply (rule_tac x = |
|
182 |
"%n. if abs (g n) <= (abs (f n)) then x n else 0" in exI) |
|
183 |
apply (rule conjI) |
|
184 |
apply (rule_tac x = "c + c" in exI) |
|
185 |
apply (clarsimp) |
|
186 |
apply (auto) |
|
187 |
apply (subgoal_tac "c * abs (f xa + g xa) <= (c + c) * abs (f xa)") |
|
188 |
apply (erule_tac x = xa in allE) |
|
189 |
apply (erule order_trans) |
|
190 |
apply (simp) |
|
191 |
apply (subgoal_tac "c * abs (f xa + g xa) <= c * (abs (f xa) + abs (g xa))") |
|
192 |
apply (erule order_trans) |
|
23477
f4b83f03cac9
tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents:
23464
diff
changeset
|
193 |
apply (simp add: ring_distribs) |
23449 | 194 |
apply (rule mult_left_mono) |
195 |
apply assumption |
|
196 |
apply (simp add: order_less_le) |
|
197 |
apply (rule mult_left_mono) |
|
198 |
apply (simp add: abs_triangle_ineq) |
|
199 |
apply (simp add: order_less_le) |
|
200 |
apply (rule mult_nonneg_nonneg) |
|
201 |
apply (rule add_nonneg_nonneg) |
|
202 |
apply auto |
|
203 |
apply (rule_tac x = "%n. if (abs (f n)) < abs (g n) then x n else 0" |
|
204 |
in exI) |
|
205 |
apply (rule conjI) |
|
206 |
apply (rule_tac x = "c + c" in exI) |
|
207 |
apply auto |
|
208 |
apply (subgoal_tac "c * abs (f xa + g xa) <= (c + c) * abs (g xa)") |
|
209 |
apply (erule_tac x = xa in allE) |
|
210 |
apply (erule order_trans) |
|
211 |
apply (simp) |
|
212 |
apply (subgoal_tac "c * abs (f xa + g xa) <= c * (abs (f xa) + abs (g xa))") |
|
213 |
apply (erule order_trans) |
|
23477
f4b83f03cac9
tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents:
23464
diff
changeset
|
214 |
apply (simp add: ring_distribs) |
23449 | 215 |
apply (rule mult_left_mono) |
216 |
apply (simp add: order_less_le) |
|
217 |
apply (simp add: order_less_le) |
|
218 |
apply (rule mult_left_mono) |
|
219 |
apply (rule abs_triangle_ineq) |
|
220 |
apply (simp add: order_less_le) |
|
25087 | 221 |
apply (metis abs_not_less_zero double_less_0_iff less_not_permute linorder_not_less mult_less_0_iff) |
23449 | 222 |
apply (rule ext) |
223 |
apply (auto simp add: if_splits linorder_not_le) |
|
224 |
done |
|
225 |
||
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
226 |
lemma bigo_plus_subset2 [intro]: "A <= O(f) ==> B <= O(f) ==> A \<oplus> B <= O(f)" |
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
227 |
apply (subgoal_tac "A \<oplus> B <= O(f) \<oplus> O(f)") |
23449 | 228 |
apply (erule order_trans) |
229 |
apply simp |
|
230 |
apply (auto del: subsetI simp del: bigo_plus_idemp) |
|
231 |
done |
|
232 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
233 |
declare [[ atp_problem_prefix = "BigO__bigo_plus_eq" ]] |
23449 | 234 |
lemma bigo_plus_eq: "ALL x. 0 <= f x ==> ALL x. 0 <= g x ==> |
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
235 |
O(f + g) = O(f) \<oplus> O(g)" |
23449 | 236 |
apply (rule equalityI) |
237 |
apply (rule bigo_plus_subset) |
|
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
238 |
apply (simp add: bigo_alt_def set_plus_def func_plus) |
23449 | 239 |
apply clarify |
36844 | 240 |
(*sledgehammer*) |
23449 | 241 |
apply (rule_tac x = "max c ca" in exI) |
242 |
apply (rule conjI) |
|
25087 | 243 |
apply (metis Orderings.less_max_iff_disj) |
23449 | 244 |
apply clarify |
245 |
apply (drule_tac x = "xa" in spec)+ |
|
246 |
apply (subgoal_tac "0 <= f xa + g xa") |
|
23477
f4b83f03cac9
tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents:
23464
diff
changeset
|
247 |
apply (simp add: ring_distribs) |
23449 | 248 |
apply (subgoal_tac "abs(a xa + b xa) <= abs(a xa) + abs(b xa)") |
249 |
apply (subgoal_tac "abs(a xa) + abs(b xa) <= |
|
250 |
max c ca * f xa + max c ca * g xa") |
|
251 |
apply (blast intro: order_trans) |
|
252 |
defer 1 |
|
253 |
apply (rule abs_triangle_ineq) |
|
25087 | 254 |
apply (metis add_nonneg_nonneg) |
23449 | 255 |
apply (rule add_mono) |
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
256 |
using [[ atp_problem_prefix = "BigO__bigo_plus_eq_simpler" ]] |
24942 | 257 |
(*Found by SPASS; SLOW*) |
29511
7071b017cb35
migrated class package to new locale implementation
haftmann
parents:
28592
diff
changeset
|
258 |
apply (metis le_maxI2 linorder_linear linorder_not_le min_max.sup_absorb1 mult_le_cancel_right order_trans) |
25710
4cdf7de81e1b
Replaced refs by config params; finer critical section in mets method
paulson
parents:
25592
diff
changeset
|
259 |
apply (metis le_maxI2 linorder_not_le mult_le_cancel_right order_trans) |
23449 | 260 |
done |
261 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
262 |
declare [[ atp_problem_prefix = "BigO__bigo_bounded_alt" ]] |
23449 | 263 |
lemma bigo_bounded_alt: "ALL x. 0 <= f x ==> ALL x. f x <= c * g x ==> |
264 |
f : O(g)" |
|
265 |
apply (auto simp add: bigo_def) |
|
36561 | 266 |
(* Version 1: one-line proof *) |
35050
9f841f20dca6
renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
haftmann
parents:
35028
diff
changeset
|
267 |
apply (metis abs_le_D1 linorder_class.not_less order_less_le Orderings.xt1(12) abs_mult) |
23449 | 268 |
done |
269 |
||
26312 | 270 |
lemma (*bigo_bounded_alt:*) "ALL x. 0 <= f x ==> ALL x. f x <= c * g x ==> |
36561 | 271 |
f : O(g)" |
272 |
apply (auto simp add: bigo_def) |
|
273 |
(* Version 2: structured proof *) |
|
274 |
proof - |
|
275 |
assume "\<forall>x. f x \<le> c * g x" |
|
276 |
thus "\<exists>c. \<forall>x. f x \<le> c * \<bar>g x\<bar>" by (metis abs_mult abs_ge_self order_trans) |
|
23449 | 277 |
qed |
278 |
||
36561 | 279 |
text{*So here is the easier (and more natural) problem using transitivity*} |
280 |
declare [[ atp_problem_prefix = "BigO__bigo_bounded_alt_trans" ]] |
|
281 |
lemma "ALL x. 0 <= f x ==> ALL x. f x <= c * g x ==> f : O(g)" |
|
282 |
apply (auto simp add: bigo_def) |
|
283 |
(* Version 1: one-line proof *) |
|
284 |
by (metis abs_ge_self abs_mult order_trans) |
|
23449 | 285 |
|
286 |
text{*So here is the easier (and more natural) problem using transitivity*} |
|
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
287 |
declare [[ atp_problem_prefix = "BigO__bigo_bounded_alt_trans" ]] |
23449 | 288 |
lemma "ALL x. 0 <= f x ==> ALL x. f x <= c * g x ==> f : O(g)" |
289 |
apply (auto simp add: bigo_def) |
|
36561 | 290 |
(* Version 2: structured proof *) |
291 |
proof - |
|
292 |
assume "\<forall>x. f x \<le> c * g x" |
|
293 |
thus "\<exists>c. \<forall>x. f x \<le> c * \<bar>g x\<bar>" by (metis abs_mult abs_ge_self order_trans) |
|
23449 | 294 |
qed |
295 |
||
296 |
lemma bigo_bounded: "ALL x. 0 <= f x ==> ALL x. f x <= g x ==> |
|
297 |
f : O(g)" |
|
298 |
apply (erule bigo_bounded_alt [of f 1 g]) |
|
299 |
apply simp |
|
300 |
done |
|
301 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
302 |
declare [[ atp_problem_prefix = "BigO__bigo_bounded2" ]] |
23449 | 303 |
lemma bigo_bounded2: "ALL x. lb x <= f x ==> ALL x. f x <= lb x + g x ==> |
304 |
f : lb +o O(g)" |
|
36561 | 305 |
apply (rule set_minus_imp_plus) |
306 |
apply (rule bigo_bounded) |
|
307 |
apply (auto simp add: diff_minus fun_Compl_def func_plus) |
|
308 |
prefer 2 |
|
309 |
apply (drule_tac x = x in spec)+ |
|
36844 | 310 |
apply (metis add_right_mono add_commute diff_add_cancel diff_minus_eq_add le_less order_trans) |
36561 | 311 |
proof - |
312 |
fix x :: 'a |
|
313 |
assume "\<forall>x. lb x \<le> f x" |
|
314 |
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 | 315 |
qed |
316 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
317 |
declare [[ atp_problem_prefix = "BigO__bigo_abs" ]] |
23449 | 318 |
lemma bigo_abs: "(%x. abs(f x)) =o O(f)" |
36561 | 319 |
apply (unfold bigo_def) |
320 |
apply auto |
|
36844 | 321 |
by (metis mult_1 order_refl) |
23449 | 322 |
|
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
323 |
declare [[ atp_problem_prefix = "BigO__bigo_abs2" ]] |
23449 | 324 |
lemma bigo_abs2: "f =o O(%x. abs(f x))" |
36561 | 325 |
apply (unfold bigo_def) |
326 |
apply auto |
|
36844 | 327 |
by (metis mult_1 order_refl) |
23449 | 328 |
|
329 |
lemma bigo_abs3: "O(f) = O(%x. abs(f x))" |
|
36561 | 330 |
proof - |
331 |
have F1: "\<forall>v u. u \<in> O(v) \<longrightarrow> O(u) \<subseteq> O(v)" by (metis bigo_elt_subset) |
|
332 |
have F2: "\<forall>u. (\<lambda>R. \<bar>u R\<bar>) \<in> O(u)" by (metis bigo_abs) |
|
333 |
have "\<forall>u. u \<in> O(\<lambda>R. \<bar>u R\<bar>)" by (metis bigo_abs2) |
|
334 |
thus "O(f) = O(\<lambda>x. \<bar>f x\<bar>)" using F1 F2 by auto |
|
335 |
qed |
|
23449 | 336 |
|
337 |
lemma bigo_abs4: "f =o g +o O(h) ==> |
|
338 |
(%x. abs (f x)) =o (%x. abs (g x)) +o O(h)" |
|
339 |
apply (drule set_plus_imp_minus) |
|
340 |
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
|
341 |
apply (subst fun_diff_def) |
23449 | 342 |
proof - |
343 |
assume a: "f - g : O(h)" |
|
344 |
have "(%x. abs (f x) - abs (g x)) =o O(%x. abs(abs (f x) - abs (g x)))" |
|
345 |
by (rule bigo_abs2) |
|
346 |
also have "... <= O(%x. abs (f x - g x))" |
|
347 |
apply (rule bigo_elt_subset) |
|
348 |
apply (rule bigo_bounded) |
|
349 |
apply force |
|
350 |
apply (rule allI) |
|
351 |
apply (rule abs_triangle_ineq3) |
|
352 |
done |
|
353 |
also have "... <= O(f - g)" |
|
354 |
apply (rule bigo_elt_subset) |
|
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
355 |
apply (subst fun_diff_def) |
23449 | 356 |
apply (rule bigo_abs) |
357 |
done |
|
358 |
also have "... <= O(h)" |
|
23464 | 359 |
using a by (rule bigo_elt_subset) |
23449 | 360 |
finally show "(%x. abs (f x) - abs (g x)) : O(h)". |
361 |
qed |
|
362 |
||
363 |
lemma bigo_abs5: "f =o O(g) ==> (%x. abs(f x)) =o O(g)" |
|
364 |
by (unfold bigo_def, auto) |
|
365 |
||
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
366 |
lemma bigo_elt_subset2 [intro]: "f : g +o O(h) ==> O(f) <= O(g) \<oplus> O(h)" |
23449 | 367 |
proof - |
368 |
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
|
369 |
also have "... <= O(g) \<oplus> O(h)" |
23449 | 370 |
by (auto del: subsetI) |
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
371 |
also have "... = O(%x. abs(g x)) \<oplus> O(%x. abs(h x))" |
23449 | 372 |
apply (subst bigo_abs3 [symmetric])+ |
373 |
apply (rule refl) |
|
374 |
done |
|
375 |
also have "... = O((%x. abs(g x)) + (%x. abs(h x)))" |
|
376 |
by (rule bigo_plus_eq [symmetric], auto) |
|
377 |
finally have "f : ...". |
|
378 |
then have "O(f) <= ..." |
|
379 |
by (elim bigo_elt_subset) |
|
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
380 |
also have "... = O(%x. abs(g x)) \<oplus> O(%x. abs(h x))" |
23449 | 381 |
by (rule bigo_plus_eq, auto) |
382 |
finally show ?thesis |
|
383 |
by (simp add: bigo_abs3 [symmetric]) |
|
384 |
qed |
|
385 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
386 |
declare [[ atp_problem_prefix = "BigO__bigo_mult" ]] |
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
387 |
lemma bigo_mult [intro]: "O(f)\<otimes>O(g) <= O(f * g)" |
23449 | 388 |
apply (rule subsetI) |
389 |
apply (subst bigo_def) |
|
390 |
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
|
391 |
simp add: bigo_alt_def set_times_def func_times) |
23449 | 392 |
(*sledgehammer*); |
393 |
apply (rule_tac x = "c * ca" in exI) |
|
394 |
apply(rule allI) |
|
395 |
apply(erule_tac x = x in allE)+ |
|
396 |
apply(subgoal_tac "c * ca * abs(f x * g x) = |
|
397 |
(c * abs(f x)) * (ca * abs(g x))") |
|
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
398 |
using [[ atp_problem_prefix = "BigO__bigo_mult_simpler" ]] |
23449 | 399 |
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
|
400 |
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
|
401 |
abs_of_pos mult_left_commute |
9f841f20dca6
renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
haftmann
parents:
35028
diff
changeset
|
402 |
abs_mult mult_pos_pos) |
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
|
403 |
apply (erule ssubst) |
23449 | 404 |
apply (subst abs_mult) |
36561 | 405 |
(* not quite as hard as BigO__bigo_mult_simpler_1 (a hard problem!) since |
406 |
abs_mult has just been done *) |
|
407 |
by (metis abs_ge_zero mult_mono') |
|
23449 | 408 |
|
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
409 |
declare [[ atp_problem_prefix = "BigO__bigo_mult2" ]] |
23449 | 410 |
lemma bigo_mult2 [intro]: "f *o O(g) <= O(f * g)" |
411 |
apply (auto simp add: bigo_def elt_set_times_def func_times abs_mult) |
|
412 |
(*sledgehammer*); |
|
413 |
apply (rule_tac x = c in exI) |
|
414 |
apply clarify |
|
415 |
apply (drule_tac x = x in spec) |
|
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
416 |
using [[ atp_problem_prefix = "BigO__bigo_mult2_simpler" ]] |
24942 | 417 |
(*sledgehammer [no luck]*); |
23449 | 418 |
apply (subgoal_tac "abs(f x) * abs(b x) <= abs(f x) * (c * abs(g x))") |
419 |
apply (simp add: mult_ac) |
|
420 |
apply (rule mult_left_mono, assumption) |
|
421 |
apply (rule abs_ge_zero) |
|
422 |
done |
|
423 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
424 |
declare [[ atp_problem_prefix = "BigO__bigo_mult3" ]] |
23449 | 425 |
lemma bigo_mult3: "f : O(h) ==> g : O(j) ==> f * g : O(h * j)" |
36561 | 426 |
by (metis bigo_mult set_rev_mp set_times_intro) |
23449 | 427 |
|
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
428 |
declare [[ atp_problem_prefix = "BigO__bigo_mult4" ]] |
23449 | 429 |
lemma bigo_mult4 [intro]:"f : k +o O(h) ==> g * f : (g * k) +o O(g * h)" |
430 |
by (metis bigo_mult2 set_plus_mono_b set_times_intro2 set_times_plus_distrib) |
|
431 |
||
432 |
||
433 |
lemma bigo_mult5: "ALL x. f x ~= 0 ==> |
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33027
diff
changeset
|
434 |
O(f * g) <= (f::'a => ('b::linordered_field)) *o O(g)" |
23449 | 435 |
proof - |
436 |
assume "ALL x. f x ~= 0" |
|
437 |
show "O(f * g) <= f *o O(g)" |
|
438 |
proof |
|
439 |
fix h |
|
440 |
assume "h : O(f * g)" |
|
441 |
then have "(%x. 1 / (f x)) * h : (%x. 1 / f x) *o O(f * g)" |
|
442 |
by auto |
|
443 |
also have "... <= O((%x. 1 / f x) * (f * g))" |
|
444 |
by (rule bigo_mult2) |
|
445 |
also have "(%x. 1 / f x) * (f * g) = g" |
|
446 |
apply (simp add: func_times) |
|
447 |
apply (rule ext) |
|
448 |
apply (simp add: prems nonzero_divide_eq_eq mult_ac) |
|
449 |
done |
|
450 |
finally have "(%x. (1::'b) / f x) * h : O(g)". |
|
451 |
then have "f * ((%x. (1::'b) / f x) * h) : f *o O(g)" |
|
452 |
by auto |
|
453 |
also have "f * ((%x. (1::'b) / f x) * h) = h" |
|
454 |
apply (simp add: func_times) |
|
455 |
apply (rule ext) |
|
456 |
apply (simp add: prems nonzero_divide_eq_eq mult_ac) |
|
457 |
done |
|
458 |
finally show "h : f *o O(g)". |
|
459 |
qed |
|
460 |
qed |
|
461 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
462 |
declare [[ atp_problem_prefix = "BigO__bigo_mult6" ]] |
23449 | 463 |
lemma bigo_mult6: "ALL x. f x ~= 0 ==> |
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33027
diff
changeset
|
464 |
O(f * g) = (f::'a => ('b::linordered_field)) *o O(g)" |
23449 | 465 |
by (metis bigo_mult2 bigo_mult5 order_antisym) |
466 |
||
467 |
(*proof requires relaxing relevance: 2007-01-25*) |
|
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
468 |
declare [[ atp_problem_prefix = "BigO__bigo_mult7" ]] |
23449 | 469 |
declare bigo_mult6 [simp] |
470 |
lemma bigo_mult7: "ALL x. f x ~= 0 ==> |
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33027
diff
changeset
|
471 |
O(f * g) <= O(f::'a => ('b::linordered_field)) \<otimes> O(g)" |
23449 | 472 |
(*sledgehammer*) |
473 |
apply (subst bigo_mult6) |
|
474 |
apply assumption |
|
475 |
apply (rule set_times_mono3) |
|
476 |
apply (rule bigo_refl) |
|
477 |
done |
|
478 |
declare bigo_mult6 [simp del] |
|
479 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
480 |
declare [[ atp_problem_prefix = "BigO__bigo_mult8" ]] |
23449 | 481 |
declare bigo_mult7[intro!] |
482 |
lemma bigo_mult8: "ALL x. f x ~= 0 ==> |
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33027
diff
changeset
|
483 |
O(f * g) = O(f::'a => ('b::linordered_field)) \<otimes> O(g)" |
23449 | 484 |
by (metis bigo_mult bigo_mult7 order_antisym_conv) |
485 |
||
486 |
lemma bigo_minus [intro]: "f : O(g) ==> - f : O(g)" |
|
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
487 |
by (auto simp add: bigo_def fun_Compl_def) |
23449 | 488 |
|
489 |
lemma bigo_minus2: "f : g +o O(h) ==> -f : -g +o O(h)" |
|
490 |
apply (rule set_minus_imp_plus) |
|
491 |
apply (drule set_plus_imp_minus) |
|
492 |
apply (drule bigo_minus) |
|
493 |
apply (simp add: diff_minus) |
|
494 |
done |
|
495 |
||
496 |
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
|
497 |
by (auto simp add: bigo_def fun_Compl_def abs_minus_cancel) |
23449 | 498 |
|
499 |
lemma bigo_plus_absorb_lemma1: "f : O(g) ==> f +o O(g) <= O(g)" |
|
500 |
proof - |
|
501 |
assume a: "f : O(g)" |
|
502 |
show "f +o O(g) <= O(g)" |
|
503 |
proof - |
|
504 |
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
|
505 |
then have "f +o O(g) <= O(f) \<oplus> O(g)" |
23449 | 506 |
by (auto del: subsetI) |
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
507 |
also have "... <= O(g) \<oplus> O(g)" |
23449 | 508 |
proof - |
509 |
from a have "O(f) <= O(g)" by (auto del: subsetI) |
|
510 |
thus ?thesis by (auto del: subsetI) |
|
511 |
qed |
|
512 |
also have "... <= O(g)" by (simp add: bigo_plus_idemp) |
|
513 |
finally show ?thesis . |
|
514 |
qed |
|
515 |
qed |
|
516 |
||
517 |
lemma bigo_plus_absorb_lemma2: "f : O(g) ==> O(g) <= f +o O(g)" |
|
518 |
proof - |
|
519 |
assume a: "f : O(g)" |
|
520 |
show "O(g) <= f +o O(g)" |
|
521 |
proof - |
|
522 |
from a have "-f : O(g)" by auto |
|
523 |
then have "-f +o O(g) <= O(g)" by (elim bigo_plus_absorb_lemma1) |
|
524 |
then have "f +o (-f +o O(g)) <= f +o O(g)" by auto |
|
525 |
also have "f +o (-f +o O(g)) = O(g)" |
|
526 |
by (simp add: set_plus_rearranges) |
|
527 |
finally show ?thesis . |
|
528 |
qed |
|
529 |
qed |
|
530 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
531 |
declare [[ atp_problem_prefix = "BigO__bigo_plus_absorb" ]] |
23449 | 532 |
lemma bigo_plus_absorb [simp]: "f : O(g) ==> f +o O(g) = O(g)" |
533 |
by (metis bigo_plus_absorb_lemma1 bigo_plus_absorb_lemma2 order_eq_iff); |
|
534 |
||
535 |
lemma bigo_plus_absorb2 [intro]: "f : O(g) ==> A <= O(g) ==> f +o A <= O(g)" |
|
536 |
apply (subgoal_tac "f +o A <= f +o O(g)") |
|
537 |
apply force+ |
|
538 |
done |
|
539 |
||
540 |
lemma bigo_add_commute_imp: "f : g +o O(h) ==> g : f +o O(h)" |
|
541 |
apply (subst set_minus_plus [symmetric]) |
|
542 |
apply (subgoal_tac "g - f = - (f - g)") |
|
543 |
apply (erule ssubst) |
|
544 |
apply (rule bigo_minus) |
|
545 |
apply (subst set_minus_plus) |
|
546 |
apply assumption |
|
547 |
apply (simp add: diff_minus add_ac) |
|
548 |
done |
|
549 |
||
550 |
lemma bigo_add_commute: "(f : g +o O(h)) = (g : f +o O(h))" |
|
551 |
apply (rule iffI) |
|
552 |
apply (erule bigo_add_commute_imp)+ |
|
553 |
done |
|
554 |
||
555 |
lemma bigo_const1: "(%x. c) : O(%x. 1)" |
|
556 |
by (auto simp add: bigo_def mult_ac) |
|
557 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
558 |
declare [[ atp_problem_prefix = "BigO__bigo_const2" ]] |
23449 | 559 |
lemma (*bigo_const2 [intro]:*) "O(%x. c) <= O(%x. 1)" |
560 |
by (metis bigo_const1 bigo_elt_subset); |
|
561 |
||
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33027
diff
changeset
|
562 |
lemma bigo_const2 [intro]: "O(%x. c::'b::linordered_idom) <= O(%x. 1)"; |
36561 | 563 |
(* "thus" had to be replaced by "show" with an explicit reference to "F1" *) |
564 |
proof - |
|
565 |
have F1: "\<forall>u. (\<lambda>Q. u) \<in> O(\<lambda>Q. 1)" by (metis bigo_const1) |
|
566 |
show "O(\<lambda>x. c) \<subseteq> O(\<lambda>x. 1)" by (metis F1 bigo_elt_subset) |
|
23449 | 567 |
qed |
568 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
569 |
declare [[ atp_problem_prefix = "BigO__bigo_const3" ]] |
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33027
diff
changeset
|
570 |
lemma bigo_const3: "(c::'a::linordered_field) ~= 0 ==> (%x. 1) : O(%x. c)" |
23449 | 571 |
apply (simp add: bigo_def) |
36561 | 572 |
by (metis abs_eq_0 left_inverse order_refl) |
23449 | 573 |
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33027
diff
changeset
|
574 |
lemma bigo_const4: "(c::'a::linordered_field) ~= 0 ==> O(%x. 1) <= O(%x. c)" |
23449 | 575 |
by (rule bigo_elt_subset, rule bigo_const3, assumption) |
576 |
||
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33027
diff
changeset
|
577 |
lemma bigo_const [simp]: "(c::'a::linordered_field) ~= 0 ==> |
23449 | 578 |
O(%x. c) = O(%x. 1)" |
579 |
by (rule equalityI, rule bigo_const2, rule bigo_const4, assumption) |
|
580 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
581 |
declare [[ atp_problem_prefix = "BigO__bigo_const_mult1" ]] |
23449 | 582 |
lemma bigo_const_mult1: "(%x. c * f x) : O(f)" |
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24855
diff
changeset
|
583 |
apply (simp add: bigo_def abs_mult) |
36561 | 584 |
by (metis le_less) |
23449 | 585 |
|
586 |
lemma bigo_const_mult2: "O(%x. c * f x) <= O(f)" |
|
587 |
by (rule bigo_elt_subset, rule bigo_const_mult1) |
|
588 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
589 |
declare [[ atp_problem_prefix = "BigO__bigo_const_mult3" ]] |
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33027
diff
changeset
|
590 |
lemma bigo_const_mult3: "(c::'a::linordered_field) ~= 0 ==> f : O(%x. c * f x)" |
23449 | 591 |
apply (simp add: bigo_def) |
36561 | 592 |
(*sledgehammer [no luck]*) |
23449 | 593 |
apply (rule_tac x = "abs(inverse c)" in exI) |
594 |
apply (simp only: abs_mult [symmetric] mult_assoc [symmetric]) |
|
595 |
apply (subst left_inverse) |
|
596 |
apply (auto ); |
|
597 |
done |
|
598 |
||
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33027
diff
changeset
|
599 |
lemma bigo_const_mult4: "(c::'a::linordered_field) ~= 0 ==> |
23449 | 600 |
O(f) <= O(%x. c * f x)" |
601 |
by (rule bigo_elt_subset, rule bigo_const_mult3, assumption) |
|
602 |
||
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33027
diff
changeset
|
603 |
lemma bigo_const_mult [simp]: "(c::'a::linordered_field) ~= 0 ==> |
23449 | 604 |
O(%x. c * f x) = O(f)" |
605 |
by (rule equalityI, rule bigo_const_mult2, erule bigo_const_mult4) |
|
606 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
607 |
declare [[ atp_problem_prefix = "BigO__bigo_const_mult5" ]] |
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33027
diff
changeset
|
608 |
lemma bigo_const_mult5 [simp]: "(c::'a::linordered_field) ~= 0 ==> |
23449 | 609 |
(%x. c) *o O(f) = O(f)" |
610 |
apply (auto del: subsetI) |
|
611 |
apply (rule order_trans) |
|
612 |
apply (rule bigo_mult2) |
|
613 |
apply (simp add: func_times) |
|
614 |
apply (auto intro!: subsetI simp add: bigo_def elt_set_times_def func_times) |
|
615 |
apply (rule_tac x = "%y. inverse c * x y" in exI) |
|
24942 | 616 |
apply (rename_tac g d) |
617 |
apply safe |
|
618 |
apply (rule_tac [2] ext) |
|
619 |
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
|
620 |
apply simp |
24942 | 621 |
apply (simp add: mult_assoc [symmetric] abs_mult) |
622 |
(*couldn't get this proof without the step above; SLOW*) |
|
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
|
623 |
apply (metis mult_assoc abs_ge_zero mult_left_mono) |
23449 | 624 |
done |
625 |
||
626 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
627 |
declare [[ atp_problem_prefix = "BigO__bigo_const_mult6" ]] |
23449 | 628 |
lemma bigo_const_mult6 [intro]: "(%x. c) *o O(f) <= O(f)" |
629 |
apply (auto intro!: subsetI |
|
630 |
simp add: bigo_def elt_set_times_def func_times |
|
631 |
simp del: abs_mult mult_ac) |
|
632 |
(*sledgehammer*); |
|
633 |
apply (rule_tac x = "ca * (abs c)" in exI) |
|
634 |
apply (rule allI) |
|
635 |
apply (subgoal_tac "ca * abs(c) * abs(f x) = abs(c) * (ca * abs(f x))") |
|
636 |
apply (erule ssubst) |
|
637 |
apply (subst abs_mult) |
|
638 |
apply (rule mult_left_mono) |
|
639 |
apply (erule spec) |
|
640 |
apply simp |
|
641 |
apply(simp add: mult_ac) |
|
642 |
done |
|
643 |
||
644 |
lemma bigo_const_mult7 [intro]: "f =o O(g) ==> (%x. c * f x) =o O(g)" |
|
645 |
proof - |
|
646 |
assume "f =o O(g)" |
|
647 |
then have "(%x. c) * f =o (%x. c) *o O(g)" |
|
648 |
by auto |
|
649 |
also have "(%x. c) * f = (%x. c * f x)" |
|
650 |
by (simp add: func_times) |
|
651 |
also have "(%x. c) *o O(g) <= O(g)" |
|
652 |
by (auto del: subsetI) |
|
653 |
finally show ?thesis . |
|
654 |
qed |
|
655 |
||
656 |
lemma bigo_compose1: "f =o O(g) ==> (%x. f(k x)) =o O(%x. g(k x))" |
|
657 |
by (unfold bigo_def, auto) |
|
658 |
||
659 |
lemma bigo_compose2: "f =o g +o O(h) ==> (%x. f(k x)) =o (%x. g(k x)) +o |
|
660 |
O(%x. h(k x))" |
|
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
661 |
apply (simp only: set_minus_plus [symmetric] diff_minus fun_Compl_def |
23449 | 662 |
func_plus) |
663 |
apply (erule bigo_compose1) |
|
664 |
done |
|
665 |
||
666 |
subsection {* Setsum *} |
|
667 |
||
668 |
lemma bigo_setsum_main: "ALL x. ALL y : A x. 0 <= h x y ==> |
|
669 |
EX c. ALL x. ALL y : A x. abs(f x y) <= c * (h x y) ==> |
|
670 |
(%x. SUM y : A x. f x y) =o O(%x. SUM y : A x. h x y)" |
|
671 |
apply (auto simp add: bigo_def) |
|
672 |
apply (rule_tac x = "abs c" in exI) |
|
673 |
apply (subst abs_of_nonneg) back back |
|
674 |
apply (rule setsum_nonneg) |
|
675 |
apply force |
|
676 |
apply (subst setsum_right_distrib) |
|
677 |
apply (rule allI) |
|
678 |
apply (rule order_trans) |
|
679 |
apply (rule setsum_abs) |
|
680 |
apply (rule setsum_mono) |
|
681 |
apply (blast intro: order_trans mult_right_mono abs_ge_self) |
|
682 |
done |
|
683 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
684 |
declare [[ atp_problem_prefix = "BigO__bigo_setsum1" ]] |
23449 | 685 |
lemma bigo_setsum1: "ALL x y. 0 <= h x y ==> |
686 |
EX c. ALL x y. abs(f x y) <= c * (h x y) ==> |
|
687 |
(%x. SUM y : A x. f x y) =o O(%x. SUM y : A x. h x y)" |
|
688 |
apply (rule bigo_setsum_main) |
|
689 |
(*sledgehammer*); |
|
690 |
apply force |
|
691 |
apply clarsimp |
|
692 |
apply (rule_tac x = c in exI) |
|
693 |
apply force |
|
694 |
done |
|
695 |
||
696 |
lemma bigo_setsum2: "ALL y. 0 <= h y ==> |
|
697 |
EX c. ALL y. abs(f y) <= c * (h y) ==> |
|
698 |
(%x. SUM y : A x. f y) =o O(%x. SUM y : A x. h y)" |
|
699 |
by (rule bigo_setsum1, auto) |
|
700 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
701 |
declare [[ atp_problem_prefix = "BigO__bigo_setsum3" ]] |
23449 | 702 |
lemma bigo_setsum3: "f =o O(h) ==> |
703 |
(%x. SUM y : A x. (l x y) * f(k x y)) =o |
|
704 |
O(%x. SUM y : A x. abs(l x y * h(k x y)))" |
|
705 |
apply (rule bigo_setsum1) |
|
706 |
apply (rule allI)+ |
|
707 |
apply (rule abs_ge_zero) |
|
708 |
apply (unfold bigo_def) |
|
709 |
apply (auto simp add: abs_mult); |
|
710 |
(*sledgehammer*); |
|
711 |
apply (rule_tac x = c in exI) |
|
712 |
apply (rule allI)+ |
|
713 |
apply (subst mult_left_commute) |
|
714 |
apply (rule mult_left_mono) |
|
715 |
apply (erule spec) |
|
716 |
apply (rule abs_ge_zero) |
|
717 |
done |
|
718 |
||
719 |
lemma bigo_setsum4: "f =o g +o O(h) ==> |
|
720 |
(%x. SUM y : A x. l x y * f(k x y)) =o |
|
721 |
(%x. SUM y : A x. l x y * g(k x y)) +o |
|
722 |
O(%x. SUM y : A x. abs(l x y * h(k x y)))" |
|
723 |
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
|
724 |
apply (subst fun_diff_def) |
23449 | 725 |
apply (subst setsum_subtractf [symmetric]) |
726 |
apply (subst right_diff_distrib [symmetric]) |
|
727 |
apply (rule bigo_setsum3) |
|
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
728 |
apply (subst fun_diff_def [symmetric]) |
23449 | 729 |
apply (erule set_plus_imp_minus) |
730 |
done |
|
731 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
732 |
declare [[ atp_problem_prefix = "BigO__bigo_setsum5" ]] |
23449 | 733 |
lemma bigo_setsum5: "f =o O(h) ==> ALL x y. 0 <= l x y ==> |
734 |
ALL x. 0 <= h x ==> |
|
735 |
(%x. SUM y : A x. (l x y) * f(k x y)) =o |
|
736 |
O(%x. SUM y : A x. (l x y) * h(k x y))" |
|
737 |
apply (subgoal_tac "(%x. SUM y : A x. (l x y) * h(k x y)) = |
|
738 |
(%x. SUM y : A x. abs((l x y) * h(k x y)))") |
|
739 |
apply (erule ssubst) |
|
740 |
apply (erule bigo_setsum3) |
|
741 |
apply (rule ext) |
|
742 |
apply (rule setsum_cong2) |
|
743 |
apply (thin_tac "f \<in> O(h)") |
|
24942 | 744 |
apply (metis abs_of_nonneg zero_le_mult_iff) |
23449 | 745 |
done |
746 |
||
747 |
lemma bigo_setsum6: "f =o g +o O(h) ==> ALL x y. 0 <= l x y ==> |
|
748 |
ALL x. 0 <= h x ==> |
|
749 |
(%x. SUM y : A x. (l x y) * f(k x y)) =o |
|
750 |
(%x. SUM y : A x. (l x y) * g(k x y)) +o |
|
751 |
O(%x. SUM y : A x. (l x y) * h(k x y))" |
|
752 |
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
|
753 |
apply (subst fun_diff_def) |
23449 | 754 |
apply (subst setsum_subtractf [symmetric]) |
755 |
apply (subst right_diff_distrib [symmetric]) |
|
756 |
apply (rule bigo_setsum5) |
|
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
757 |
apply (subst fun_diff_def [symmetric]) |
23449 | 758 |
apply (drule set_plus_imp_minus) |
759 |
apply auto |
|
760 |
done |
|
761 |
||
762 |
subsection {* Misc useful stuff *} |
|
763 |
||
764 |
lemma bigo_useful_intro: "A <= O(f) ==> B <= O(f) ==> |
|
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
765 |
A \<oplus> B <= O(f)" |
23449 | 766 |
apply (subst bigo_plus_idemp [symmetric]) |
767 |
apply (rule set_plus_mono2) |
|
768 |
apply assumption+ |
|
769 |
done |
|
770 |
||
771 |
lemma bigo_useful_add: "f =o O(h) ==> g =o O(h) ==> f + g =o O(h)" |
|
772 |
apply (subst bigo_plus_idemp [symmetric]) |
|
773 |
apply (rule set_plus_intro) |
|
774 |
apply assumption+ |
|
775 |
done |
|
776 |
||
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33027
diff
changeset
|
777 |
lemma bigo_useful_const_mult: "(c::'a::linordered_field) ~= 0 ==> |
23449 | 778 |
(%x. c) * f =o O(h) ==> f =o O(h)" |
779 |
apply (rule subsetD) |
|
780 |
apply (subgoal_tac "(%x. 1 / c) *o O(h) <= O(h)") |
|
781 |
apply assumption |
|
782 |
apply (rule bigo_const_mult6) |
|
783 |
apply (subgoal_tac "f = (%x. 1 / c) * ((%x. c) * f)") |
|
784 |
apply (erule ssubst) |
|
785 |
apply (erule set_times_intro2) |
|
786 |
apply (simp add: func_times) |
|
787 |
done |
|
788 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
789 |
declare [[ atp_problem_prefix = "BigO__bigo_fix" ]] |
23449 | 790 |
lemma bigo_fix: "(%x. f ((x::nat) + 1)) =o O(%x. h(x + 1)) ==> f 0 = 0 ==> |
791 |
f =o O(h)" |
|
792 |
apply (simp add: bigo_alt_def) |
|
793 |
(*sledgehammer*); |
|
794 |
apply clarify |
|
795 |
apply (rule_tac x = c in exI) |
|
796 |
apply safe |
|
797 |
apply (case_tac "x = 0") |
|
35050
9f841f20dca6
renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
haftmann
parents:
35028
diff
changeset
|
798 |
apply (metis abs_ge_zero abs_zero order_less_le split_mult_pos_le) |
23449 | 799 |
apply (subgoal_tac "x = Suc (x - 1)") |
23816 | 800 |
apply metis |
23449 | 801 |
apply simp |
802 |
done |
|
803 |
||
804 |
||
805 |
lemma bigo_fix2: |
|
806 |
"(%x. f ((x::nat) + 1)) =o (%x. g(x + 1)) +o O(%x. h(x + 1)) ==> |
|
807 |
f 0 = g 0 ==> f =o g +o O(h)" |
|
808 |
apply (rule set_minus_imp_plus) |
|
809 |
apply (rule bigo_fix) |
|
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
810 |
apply (subst fun_diff_def) |
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
811 |
apply (subst fun_diff_def [symmetric]) |
23449 | 812 |
apply (rule set_plus_imp_minus) |
813 |
apply simp |
|
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
814 |
apply (simp add: fun_diff_def) |
23449 | 815 |
done |
816 |
||
817 |
subsection {* Less than or equal to *} |
|
818 |
||
35416
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents:
35050
diff
changeset
|
819 |
definition lesso :: "('a => 'b::linordered_idom) => ('a => 'b) => ('a => 'b)" (infixl "<o" 70) where |
23449 | 820 |
"f <o g == (%x. max (f x - g x) 0)" |
821 |
||
822 |
lemma bigo_lesseq1: "f =o O(h) ==> ALL x. abs (g x) <= abs (f x) ==> |
|
823 |
g =o O(h)" |
|
824 |
apply (unfold bigo_def) |
|
825 |
apply clarsimp |
|
826 |
apply (blast intro: order_trans) |
|
827 |
done |
|
828 |
||
829 |
lemma bigo_lesseq2: "f =o O(h) ==> ALL x. abs (g x) <= f x ==> |
|
830 |
g =o O(h)" |
|
831 |
apply (erule bigo_lesseq1) |
|
832 |
apply (blast intro: abs_ge_self order_trans) |
|
833 |
done |
|
834 |
||
835 |
lemma bigo_lesseq3: "f =o O(h) ==> ALL x. 0 <= g x ==> ALL x. g x <= f x ==> |
|
836 |
g =o O(h)" |
|
837 |
apply (erule bigo_lesseq2) |
|
838 |
apply (rule allI) |
|
839 |
apply (subst abs_of_nonneg) |
|
840 |
apply (erule spec)+ |
|
841 |
done |
|
842 |
||
843 |
lemma bigo_lesseq4: "f =o O(h) ==> |
|
844 |
ALL x. 0 <= g x ==> ALL x. g x <= abs (f x) ==> |
|
845 |
g =o O(h)" |
|
846 |
apply (erule bigo_lesseq1) |
|
847 |
apply (rule allI) |
|
848 |
apply (subst abs_of_nonneg) |
|
849 |
apply (erule spec)+ |
|
850 |
done |
|
851 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
852 |
declare [[ atp_problem_prefix = "BigO__bigo_lesso1" ]] |
23449 | 853 |
lemma bigo_lesso1: "ALL x. f x <= g x ==> f <o g =o O(h)" |
36561 | 854 |
apply (unfold lesso_def) |
855 |
apply (subgoal_tac "(%x. max (f x - g x) 0) = 0") |
|
856 |
proof - |
|
857 |
assume "(\<lambda>x. max (f x - g x) 0) = 0" |
|
858 |
thus "(\<lambda>x. max (f x - g x) 0) \<in> O(h)" by (metis bigo_zero) |
|
859 |
next |
|
860 |
show "\<forall>x\<Colon>'a. f x \<le> g x \<Longrightarrow> (\<lambda>x\<Colon>'a. max (f x - g x) (0\<Colon>'b)) = (0\<Colon>'a \<Rightarrow> 'b)" |
|
23449 | 861 |
apply (unfold func_zero) |
862 |
apply (rule ext) |
|
36561 | 863 |
by (simp split: split_max) |
864 |
qed |
|
23449 | 865 |
|
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
866 |
declare [[ atp_problem_prefix = "BigO__bigo_lesso2" ]] |
23449 | 867 |
lemma bigo_lesso2: "f =o g +o O(h) ==> |
868 |
ALL x. 0 <= k x ==> ALL x. k x <= f x ==> |
|
869 |
k <o g =o O(h)" |
|
870 |
apply (unfold lesso_def) |
|
871 |
apply (rule bigo_lesseq4) |
|
872 |
apply (erule set_plus_imp_minus) |
|
873 |
apply (rule allI) |
|
874 |
apply (rule le_maxI2) |
|
875 |
apply (rule allI) |
|
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
876 |
apply (subst fun_diff_def) |
23449 | 877 |
apply (erule thin_rl) |
878 |
(*sledgehammer*); |
|
879 |
apply (case_tac "0 <= k x - g x") |
|
36561 | 880 |
(* apply (metis abs_le_iff add_le_imp_le_right diff_minus le_less |
881 |
le_max_iff_disj min_max.le_supE min_max.sup_absorb2 |
|
882 |
min_max.sup_commute) *) |
|
37320 | 883 |
proof - |
884 |
fix x :: 'a |
|
885 |
assume "\<forall>x\<Colon>'a. k x \<le> f x" |
|
886 |
hence F1: "\<forall>x\<^isub>1\<Colon>'a. max (k x\<^isub>1) (f x\<^isub>1) = f x\<^isub>1" by (metis min_max.sup_absorb2) |
|
887 |
assume "(0\<Colon>'b) \<le> k x - g x" |
|
888 |
hence F2: "max (0\<Colon>'b) (k x - g x) = k x - g x" by (metis min_max.sup_absorb2) |
|
889 |
have F3: "\<forall>x\<^isub>1\<Colon>'b. x\<^isub>1 \<le> \<bar>x\<^isub>1\<bar>" by (metis abs_le_iff le_less) |
|
890 |
have "\<forall>(x\<^isub>2\<Colon>'b) x\<^isub>1\<Colon>'b. max x\<^isub>1 x\<^isub>2 \<le> x\<^isub>2 \<or> max x\<^isub>1 x\<^isub>2 \<le> x\<^isub>1" by (metis le_less le_max_iff_disj) |
|
891 |
hence "\<forall>(x\<^isub>3\<Colon>'b) (x\<^isub>2\<Colon>'b) x\<^isub>1\<Colon>'b. x\<^isub>1 - x\<^isub>2 \<le> x\<^isub>3 - x\<^isub>2 \<or> x\<^isub>3 \<le> x\<^isub>1" by (metis add_le_imp_le_right diff_minus min_max.le_supE) |
|
892 |
hence "k x - g x \<le> f x - g x" by (metis F1 le_less min_max.sup_absorb2 min_max.sup_commute) |
|
893 |
hence "k x - g x \<le> \<bar>f x - g x\<bar>" by (metis F3 le_max_iff_disj min_max.sup_absorb2) |
|
894 |
thus "max (k x - g x) (0\<Colon>'b) \<le> \<bar>f x - g x\<bar>" by (metis F2 min_max.sup_commute) |
|
36561 | 895 |
next |
896 |
show "\<And>x\<Colon>'a. |
|
897 |
\<lbrakk>\<forall>x\<Colon>'a. (0\<Colon>'b) \<le> k x; \<forall>x\<Colon>'a. k x \<le> f x; \<not> (0\<Colon>'b) \<le> k x - g x\<rbrakk> |
|
898 |
\<Longrightarrow> max (k x - g x) (0\<Colon>'b) \<le> \<bar>f x - g x\<bar>" |
|
899 |
by (metis abs_ge_zero le_cases min_max.sup_absorb2) |
|
24545 | 900 |
qed |
23449 | 901 |
|
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
902 |
declare [[ atp_problem_prefix = "BigO__bigo_lesso3" ]] |
23449 | 903 |
lemma bigo_lesso3: "f =o g +o O(h) ==> |
904 |
ALL x. 0 <= k x ==> ALL x. g x <= k x ==> |
|
905 |
f <o k =o O(h)" |
|
906 |
apply (unfold lesso_def) |
|
907 |
apply (rule bigo_lesseq4) |
|
908 |
apply (erule set_plus_imp_minus) |
|
909 |
apply (rule allI) |
|
910 |
apply (rule le_maxI2) |
|
911 |
apply (rule allI) |
|
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
912 |
apply (subst fun_diff_def) |
23449 | 913 |
apply (erule thin_rl) |
914 |
(*sledgehammer*); |
|
915 |
apply (case_tac "0 <= f x - k x") |
|
29667 | 916 |
apply (simp) |
23449 | 917 |
apply (subst abs_of_nonneg) |
918 |
apply (drule_tac x = x in spec) back |
|
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
919 |
using [[ atp_problem_prefix = "BigO__bigo_lesso3_simpler" ]] |
24545 | 920 |
apply (metis diff_less_0_iff_less linorder_not_le not_leE uminus_add_conv_diff xt1(12) xt1(6)) |
921 |
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
|
922 |
apply (metis abs_ge_zero linorder_linear min_max.sup_absorb1 min_max.sup_commute) |
23449 | 923 |
done |
924 |
||
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33027
diff
changeset
|
925 |
lemma bigo_lesso4: "f <o g =o O(k::'a=>'b::linordered_field) ==> |
23449 | 926 |
g =o h +o O(k) ==> f <o h =o O(k)" |
927 |
apply (unfold lesso_def) |
|
928 |
apply (drule set_plus_imp_minus) |
|
929 |
apply (drule bigo_abs5) back |
|
26814
b3e8d5ec721d
Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents:
26645
diff
changeset
|
930 |
apply (simp add: fun_diff_def) |
23449 | 931 |
apply (drule bigo_useful_add) |
932 |
apply assumption |
|
933 |
apply (erule bigo_lesseq2) back |
|
934 |
apply (rule allI) |
|
29667 | 935 |
apply (auto simp add: func_plus fun_diff_def algebra_simps |
23449 | 936 |
split: split_max abs_split) |
937 |
done |
|
938 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
29823
diff
changeset
|
939 |
declare [[ atp_problem_prefix = "BigO__bigo_lesso5" ]] |
23449 | 940 |
lemma bigo_lesso5: "f <o g =o O(h) ==> |
941 |
EX C. ALL x. f x <= g x + C * abs(h x)" |
|
942 |
apply (simp only: lesso_def bigo_alt_def) |
|
943 |
apply clarsimp |
|
24855 | 944 |
apply (metis abs_if abs_mult add_commute diff_le_eq less_not_permute) |
23449 | 945 |
done |
946 |
||
947 |
end |