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