23449
|
1 |
(* Title: HOL/MetisExamples/BigO.thy
|
|
2 |
ID: $Id$
|
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory
|
|
4 |
|
|
5 |
Testing the metis method
|
|
6 |
*)
|
|
7 |
|
|
8 |
header {* Big O notation *}
|
|
9 |
|
|
10 |
theory BigO
|
|
11 |
imports SetsAndFunctions
|
|
12 |
begin
|
|
13 |
|
|
14 |
subsection {* Definitions *}
|
|
15 |
|
|
16 |
constdefs
|
|
17 |
|
|
18 |
bigo :: "('a => 'b::ordered_idom) => ('a => 'b) set" ("(1O'(_'))")
|
|
19 |
"O(f::('a => 'b)) == {h. EX c. ALL x. abs (h x) <= c * abs (f x)}"
|
|
20 |
|
|
21 |
ML{*ResAtp.problem_name := "BigO__bigo_pos_const"*}
|
|
22 |
lemma bigo_pos_const: "(EX (c::'a::ordered_idom).
|
|
23 |
ALL x. (abs (h x)) <= (c * (abs (f x))))
|
|
24 |
= (EX c. 0 < c & (ALL x. (abs(h x)) <= (c * (abs (f x)))))"
|
|
25 |
apply auto
|
|
26 |
apply (case_tac "c = 0", simp)
|
|
27 |
apply (rule_tac x = "1" in exI, simp)
|
|
28 |
apply (rule_tac x = "abs c" in exI, auto);
|
|
29 |
txt{*Version 1: one-shot proof. MUCH SLOWER with types: 24 versus 6.7 seconds*}
|
|
30 |
apply (metis abs_ge_minus_self abs_ge_zero abs_minus_cancel abs_of_nonneg equation_minus_iff Orderings.xt1(6) abs_le_mult)
|
|
31 |
done
|
|
32 |
|
|
33 |
(*** Now various verions with an increasing modulus ***)
|
|
34 |
|
|
35 |
ML{*ResReconstruct.modulus := 1*}
|
|
36 |
|
|
37 |
lemma bigo_pos_const: "(EX (c::'a::ordered_idom).
|
|
38 |
ALL x. (abs (h x)) <= (c * (abs (f x))))
|
|
39 |
= (EX c. 0 < c & (ALL x. (abs(h x)) <= (c * (abs (f x)))))"
|
|
40 |
apply auto
|
|
41 |
apply (case_tac "c = 0", simp)
|
|
42 |
apply (rule_tac x = "1" in exI, simp)
|
|
43 |
apply (rule_tac x = "abs c" in exI, auto)
|
|
44 |
(*hand-modified to give 'a sort ordered_idom and X3 type 'a*)
|
|
45 |
proof (neg_clausify)
|
|
46 |
fix c x
|
|
47 |
assume 0: "\<And>A. \<bar>h A\<bar> \<le> c * \<bar>f A\<bar>"
|
|
48 |
assume 1: "c \<noteq> (0\<Colon>'a::ordered_idom)"
|
|
49 |
assume 2: "\<not> \<bar>h x\<bar> \<le> \<bar>c\<bar> * \<bar>f x\<bar>"
|
|
50 |
have 3: "\<And>X1 X3. \<bar>h X3\<bar> < X1 \<or> \<not> c * \<bar>f X3\<bar> < X1"
|
|
51 |
by (metis order_le_less_trans 0)
|
|
52 |
have 4: "\<And>X3. (1\<Colon>'a) * X3 \<le> X3 \<or> \<not> (1\<Colon>'a) \<le> (1\<Colon>'a)"
|
|
53 |
by (metis mult_le_cancel_right2 order_refl)
|
|
54 |
have 5: "\<And>X3. (1\<Colon>'a) * X3 \<le> X3"
|
|
55 |
by (metis 4 order_refl)
|
|
56 |
have 6: "\<And>X3. \<bar>0\<Colon>'a\<bar> = \<bar>X3\<bar> * (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> (0\<Colon>'a)"
|
|
57 |
by (metis abs_mult_pos mult_cancel_right1)
|
|
58 |
have 7: "\<bar>0\<Colon>'a\<bar> = (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> (0\<Colon>'a)"
|
|
59 |
by (metis 6 mult_cancel_right1)
|
|
60 |
have 8: "\<bar>0\<Colon>'a\<bar> = (0\<Colon>'a)"
|
|
61 |
by (metis 7 order_refl)
|
|
62 |
have 9: "\<not> (0\<Colon>'a) < (0\<Colon>'a)"
|
|
63 |
by (metis abs_not_less_zero 8)
|
|
64 |
have 10: "\<bar>(1\<Colon>'a) * (0\<Colon>'a)\<bar> = - ((1\<Colon>'a) * (0\<Colon>'a))"
|
|
65 |
by (metis abs_of_nonpos 5)
|
|
66 |
have 11: "(0\<Colon>'a) = - ((1\<Colon>'a) * (0\<Colon>'a))"
|
|
67 |
by (metis 10 mult_cancel_right1 8)
|
|
68 |
have 12: "(0\<Colon>'a) = - (0\<Colon>'a)"
|
|
69 |
by (metis 11 mult_cancel_right1)
|
|
70 |
have 13: "\<And>X3. \<bar>X3\<bar> = X3 \<or> X3 \<le> (0\<Colon>'a)"
|
|
71 |
by (metis abs_of_nonneg linorder_linear)
|
|
72 |
have 14: "c \<le> (0\<Colon>'a) \<or> \<not> \<bar>h x\<bar> \<le> c * \<bar>f x\<bar>"
|
|
73 |
by (metis 2 13)
|
|
74 |
have 15: "c \<le> (0\<Colon>'a)"
|
|
75 |
by (metis 14 0)
|
|
76 |
have 16: "c = (0\<Colon>'a) \<or> c < (0\<Colon>'a)"
|
|
77 |
by (metis linorder_antisym_conv2 15)
|
|
78 |
have 17: "\<bar>c\<bar> = - c"
|
|
79 |
by (metis abs_of_nonpos 15)
|
|
80 |
have 18: "c < (0\<Colon>'a)"
|
|
81 |
by (metis 16 1)
|
|
82 |
have 19: "\<not> \<bar>h x\<bar> \<le> - c * \<bar>f x\<bar>"
|
|
83 |
by (metis 2 17)
|
|
84 |
have 20: "\<And>X3. X3 * (1\<Colon>'a) = X3"
|
|
85 |
by (metis mult_cancel_right1 AC_mult.f.commute)
|
|
86 |
have 21: "\<And>X3. (0\<Colon>'a) \<le> X3 * X3"
|
|
87 |
by (metis zero_le_square AC_mult.f.commute)
|
|
88 |
have 22: "(0\<Colon>'a) \<le> (1\<Colon>'a)"
|
|
89 |
by (metis 21 mult_cancel_left1)
|
|
90 |
have 23: "\<And>X3. (0\<Colon>'a) = X3 \<or> (0\<Colon>'a) \<noteq> - X3"
|
|
91 |
by (metis neg_equal_iff_equal 12)
|
|
92 |
have 24: "\<And>X3. (0\<Colon>'a) = - X3 \<or> X3 \<noteq> (0\<Colon>'a)"
|
|
93 |
by (metis 23 minus_equation_iff)
|
|
94 |
have 25: "\<And>X3. \<bar>0\<Colon>'a\<bar> = \<bar>X3\<bar> \<or> X3 \<noteq> (0\<Colon>'a)"
|
|
95 |
by (metis abs_minus_cancel 24)
|
|
96 |
have 26: "\<And>X3. (0\<Colon>'a) = \<bar>X3\<bar> \<or> X3 \<noteq> (0\<Colon>'a)"
|
|
97 |
by (metis 25 8)
|
|
98 |
have 27: "\<And>X1 X3. (0\<Colon>'a) * \<bar>X1\<bar> = \<bar>X3 * X1\<bar> \<or> X3 \<noteq> (0\<Colon>'a)"
|
|
99 |
by (metis abs_mult 26)
|
|
100 |
have 28: "\<And>X1 X3. (0\<Colon>'a) = \<bar>X3 * X1\<bar> \<or> X3 \<noteq> (0\<Colon>'a)"
|
|
101 |
by (metis 27 mult_cancel_left1)
|
|
102 |
have 29: "\<And>X1 X3. (0\<Colon>'a) = X3 * X1 \<or> (0\<Colon>'a) < (0\<Colon>'a) \<or> X3 \<noteq> (0\<Colon>'a)"
|
|
103 |
by (metis zero_less_abs_iff 28)
|
|
104 |
have 30: "\<And>X1 X3. X3 * X1 = (0\<Colon>'a) \<or> X3 \<noteq> (0\<Colon>'a)"
|
|
105 |
by (metis 29 9)
|
|
106 |
have 31: "\<And>X1 X3. (0\<Colon>'a) = X1 * X3 \<or> X3 \<noteq> (0\<Colon>'a)"
|
|
107 |
by (metis AC_mult.f.commute 30)
|
|
108 |
have 32: "\<And>X1 X3. (0\<Colon>'a) = \<bar>X3 * X1\<bar> \<or> \<bar>X1\<bar> \<noteq> (0\<Colon>'a)"
|
|
109 |
by (metis abs_mult 31)
|
|
110 |
have 33: "\<And>X3::'a. \<bar>X3 * X3\<bar> = X3 * X3"
|
|
111 |
by (metis abs_mult_self abs_mult AC_mult.f.commute)
|
|
112 |
have 34: "\<And>X3. (0\<Colon>'a) \<le> \<bar>X3\<bar> \<or> \<not> (0\<Colon>'a) \<le> (1\<Colon>'a)"
|
|
113 |
by (metis abs_ge_zero abs_mult_pos 20)
|
|
114 |
have 35: "\<And>X3. (0\<Colon>'a) \<le> \<bar>X3\<bar>"
|
|
115 |
by (metis 34 22)
|
|
116 |
have 36: "\<And>X3. X3 * (1\<Colon>'a) = (0\<Colon>'a) \<or> \<bar>X3\<bar> \<noteq> (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> (1\<Colon>'a)"
|
|
117 |
by (metis abs_eq_0 abs_mult_pos 20)
|
|
118 |
have 37: "\<And>X3. X3 = (0\<Colon>'a) \<or> \<bar>X3\<bar> \<noteq> (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> (1\<Colon>'a)"
|
|
119 |
by (metis 36 20)
|
|
120 |
have 38: "\<And>X3. X3 = (0\<Colon>'a) \<or> \<bar>X3\<bar> \<noteq> (0\<Colon>'a)"
|
|
121 |
by (metis 37 22)
|
|
122 |
have 39: "\<And>X1 X3. X3 * X1 = (0\<Colon>'a) \<or> \<bar>X1\<bar> \<noteq> (0\<Colon>'a)"
|
|
123 |
by (metis 38 32)
|
|
124 |
have 40: "\<And>X3::'a. \<bar>\<bar>X3\<bar>\<bar> = \<bar>X3\<bar> \<or> \<not> (0\<Colon>'a) \<le> (1\<Colon>'a)"
|
|
125 |
by (metis abs_idempotent abs_mult_pos 20)
|
|
126 |
have 41: "\<And>X3::'a. \<bar>\<bar>X3\<bar>\<bar> = \<bar>X3\<bar>"
|
|
127 |
by (metis 40 22)
|
|
128 |
have 42: "\<And>X3. \<not> \<bar>X3\<bar> < (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> (1\<Colon>'a)"
|
|
129 |
by (metis abs_not_less_zero abs_mult_pos 20)
|
|
130 |
have 43: "\<And>X3. \<not> \<bar>X3\<bar> < (0\<Colon>'a)"
|
|
131 |
by (metis 42 22)
|
|
132 |
have 44: "\<And>X3. X3 * (1\<Colon>'a) = (0\<Colon>'a) \<or> \<not> \<bar>X3\<bar> \<le> (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> (1\<Colon>'a)"
|
|
133 |
by (metis abs_le_zero_iff abs_mult_pos 20)
|
|
134 |
have 45: "\<And>X3. X3 = (0\<Colon>'a) \<or> \<not> \<bar>X3\<bar> \<le> (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> (1\<Colon>'a)"
|
|
135 |
by (metis 44 20)
|
|
136 |
have 46: "\<And>X3. X3 = (0\<Colon>'a) \<or> \<not> \<bar>X3\<bar> \<le> (0\<Colon>'a)"
|
|
137 |
by (metis 45 22)
|
|
138 |
have 47: "\<And>X3. X3 * X3 = (0\<Colon>'a) \<or> \<not> X3 * X3 \<le> (0\<Colon>'a)"
|
|
139 |
by (metis 46 33)
|
|
140 |
have 48: "\<And>X3. X3 * X3 = (0\<Colon>'a) \<or> \<not> X3 \<le> (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> X3"
|
|
141 |
by (metis 47 mult_le_0_iff)
|
|
142 |
have 49: "\<And>X3. \<bar>X3\<bar> = (0\<Colon>'a) \<or> \<not> X3 \<le> (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> X3"
|
|
143 |
by (metis mult_eq_0_iff abs_mult_self 48)
|
|
144 |
have 50: "\<And>X1 X3.
|
|
145 |
(0\<Colon>'a) * \<bar>X1\<bar> = \<bar>\<bar>X3 * X1\<bar>\<bar> \<or>
|
|
146 |
\<not> (0\<Colon>'a) \<le> \<bar>X1\<bar> \<or> \<not> \<bar>X3\<bar> \<le> (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> \<bar>X3\<bar>"
|
|
147 |
by (metis abs_mult_pos abs_mult 49)
|
|
148 |
have 51: "\<And>X1 X3. X3 * X1 = (0\<Colon>'a) \<or> \<not> X1 \<le> (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> X1"
|
|
149 |
by (metis 39 49)
|
|
150 |
have 52: "\<And>X1 X3.
|
|
151 |
(0\<Colon>'a) = \<bar>\<bar>X3 * X1\<bar>\<bar> \<or>
|
|
152 |
\<not> (0\<Colon>'a) \<le> \<bar>X1\<bar> \<or> \<not> \<bar>X3\<bar> \<le> (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> \<bar>X3\<bar>"
|
|
153 |
by (metis 50 mult_cancel_left1)
|
|
154 |
have 53: "\<And>X1 X3.
|
|
155 |
(0\<Colon>'a) = \<bar>X3 * X1\<bar> \<or> \<not> (0\<Colon>'a) \<le> \<bar>X1\<bar> \<or> \<not> \<bar>X3\<bar> \<le> (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> \<bar>X3\<bar>"
|
|
156 |
by (metis 52 41)
|
|
157 |
have 54: "\<And>X1 X3. (0\<Colon>'a) = \<bar>X3 * X1\<bar> \<or> \<not> \<bar>X3\<bar> \<le> (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> \<bar>X3\<bar>"
|
|
158 |
by (metis 53 35)
|
|
159 |
have 55: "\<And>X1 X3. (0\<Colon>'a) = \<bar>X3 * X1\<bar> \<or> \<not> \<bar>X3\<bar> \<le> (0\<Colon>'a)"
|
|
160 |
by (metis 54 35)
|
|
161 |
have 56: "\<And>X1 X3. \<bar>X1 * X3\<bar> = (0\<Colon>'a) \<or> \<not> \<bar>X3\<bar> \<le> (0\<Colon>'a)"
|
|
162 |
by (metis 55 AC_mult.f.commute)
|
|
163 |
have 57: "\<And>X1 X3. X3 * X1 = (0\<Colon>'a) \<or> \<not> \<bar>X1\<bar> \<le> (0\<Colon>'a)"
|
|
164 |
by (metis 38 56)
|
|
165 |
have 58: "\<And>X3. \<bar>h X3\<bar> \<le> (0\<Colon>'a) \<or> \<not> \<bar>f X3\<bar> \<le> (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> \<bar>f X3\<bar>"
|
|
166 |
by (metis 0 51)
|
|
167 |
have 59: "\<And>X3. \<bar>h X3\<bar> \<le> (0\<Colon>'a) \<or> \<not> \<bar>f X3\<bar> \<le> (0\<Colon>'a)"
|
|
168 |
by (metis 58 35)
|
|
169 |
have 60: "\<And>X3. \<bar>h X3\<bar> \<le> (0\<Colon>'a) \<or> (0\<Colon>'a) < \<bar>f X3\<bar>"
|
|
170 |
by (metis 59 linorder_not_le)
|
|
171 |
have 61: "\<And>X1 X3. X3 * X1 = (0\<Colon>'a) \<or> (0\<Colon>'a) < \<bar>X1\<bar>"
|
|
172 |
by (metis 57 linorder_not_le)
|
|
173 |
have 62: "(0\<Colon>'a) < \<bar>\<bar>f x\<bar>\<bar> \<or> \<not> \<bar>h x\<bar> \<le> (0\<Colon>'a)"
|
|
174 |
by (metis 19 61)
|
|
175 |
have 63: "(0\<Colon>'a) < \<bar>f x\<bar> \<or> \<not> \<bar>h x\<bar> \<le> (0\<Colon>'a)"
|
|
176 |
by (metis 62 41)
|
|
177 |
have 64: "(0\<Colon>'a) < \<bar>f x\<bar>"
|
|
178 |
by (metis 63 60)
|
|
179 |
have 65: "\<And>X3. \<bar>h X3\<bar> < (0\<Colon>'a) \<or> \<not> c < (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) < \<bar>f X3\<bar>"
|
|
180 |
by (metis 3 mult_less_0_iff)
|
|
181 |
have 66: "\<And>X3. \<bar>h X3\<bar> < (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) < \<bar>f X3\<bar>"
|
|
182 |
by (metis 65 18)
|
|
183 |
have 67: "\<And>X3. \<not> (0\<Colon>'a) < \<bar>f X3\<bar>"
|
|
184 |
by (metis 66 43)
|
|
185 |
show "False"
|
|
186 |
by (metis 67 64)
|
|
187 |
qed
|
|
188 |
|
|
189 |
lemma (*bigo_pos_const:*) "(EX (c::'a::ordered_idom).
|
|
190 |
ALL x. (abs (h x)) <= (c * (abs (f x))))
|
|
191 |
= (EX c. 0 < c & (ALL x. (abs(h x)) <= (c * (abs (f x)))))"
|
|
192 |
apply auto
|
|
193 |
apply (case_tac "c = 0", simp)
|
|
194 |
apply (rule_tac x = "1" in exI, simp)
|
|
195 |
apply (rule_tac x = "abs c" in exI, auto);
|
|
196 |
ML{*ResReconstruct.modulus:=2*}
|
|
197 |
proof (neg_clausify)
|
|
198 |
fix c x
|
|
199 |
assume 0: "\<And>A. \<bar>h A\<bar> \<le> c * \<bar>f A\<bar>"
|
|
200 |
assume 1: "c \<noteq> (0\<Colon>'a::ordered_idom)"
|
|
201 |
assume 2: "\<not> \<bar>h x\<bar> \<le> \<bar>c\<bar> * \<bar>f x\<bar>"
|
|
202 |
have 3: "\<And>X3. (1\<Colon>'a) * X3 \<le> X3"
|
|
203 |
by (metis mult_le_cancel_right2 order_refl order_refl)
|
|
204 |
have 4: "\<bar>0\<Colon>'a\<bar> = (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> (0\<Colon>'a)"
|
|
205 |
by (metis abs_mult_pos mult_cancel_right1 mult_cancel_right1)
|
|
206 |
have 5: "\<not> (0\<Colon>'a) < (0\<Colon>'a)"
|
|
207 |
by (metis abs_not_less_zero 4 order_refl)
|
|
208 |
have 6: "(0\<Colon>'a) = - ((1\<Colon>'a) * (0\<Colon>'a))"
|
|
209 |
by (metis abs_of_nonpos 3 mult_cancel_right1 4 order_refl)
|
|
210 |
have 7: "\<And>X3. \<bar>X3\<bar> = X3 \<or> X3 \<le> (0\<Colon>'a)"
|
|
211 |
by (metis abs_of_nonneg linorder_linear)
|
|
212 |
have 8: "c \<le> (0\<Colon>'a)"
|
|
213 |
by (metis 2 7 0)
|
|
214 |
have 9: "\<bar>c\<bar> = - c"
|
|
215 |
by (metis abs_of_nonpos 8)
|
|
216 |
have 10: "\<not> \<bar>h x\<bar> \<le> - c * \<bar>f x\<bar>"
|
|
217 |
by (metis 2 9)
|
|
218 |
have 11: "\<And>X3. X3 * (1\<Colon>'a) = X3"
|
|
219 |
by (metis mult_cancel_right1 AC_mult.f.commute)
|
|
220 |
have 12: "(0\<Colon>'a) \<le> (1\<Colon>'a)"
|
|
221 |
by (metis zero_le_square AC_mult.f.commute mult_cancel_left1)
|
|
222 |
have 13: "\<And>X3. (0\<Colon>'a) = - X3 \<or> X3 \<noteq> (0\<Colon>'a)"
|
|
223 |
by (metis neg_equal_iff_equal 6 mult_cancel_right1 minus_equation_iff)
|
|
224 |
have 14: "\<And>X3. (0\<Colon>'a) = \<bar>X3\<bar> \<or> X3 \<noteq> (0\<Colon>'a)"
|
|
225 |
by (metis abs_minus_cancel 13 4 order_refl)
|
|
226 |
have 15: "\<And>X1 X3. (0\<Colon>'a) = \<bar>X3 * X1\<bar> \<or> X3 \<noteq> (0\<Colon>'a)"
|
|
227 |
by (metis abs_mult 14 mult_cancel_left1)
|
|
228 |
have 16: "\<And>X1 X3. X3 * X1 = (0\<Colon>'a) \<or> X3 \<noteq> (0\<Colon>'a)"
|
|
229 |
by (metis zero_less_abs_iff 15 5)
|
|
230 |
have 17: "\<And>X1 X3. (0\<Colon>'a) = \<bar>X3 * X1\<bar> \<or> \<bar>X1\<bar> \<noteq> (0\<Colon>'a)"
|
|
231 |
by (metis abs_mult AC_mult.f.commute 16)
|
|
232 |
have 18: "\<And>X3. (0\<Colon>'a) \<le> \<bar>X3\<bar>"
|
|
233 |
by (metis abs_ge_zero abs_mult_pos 11 12)
|
|
234 |
have 19: "\<And>X3. X3 * (1\<Colon>'a) = (0\<Colon>'a) \<or> \<bar>X3\<bar> \<noteq> (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> (1\<Colon>'a)"
|
|
235 |
by (metis abs_eq_0 abs_mult_pos 11)
|
|
236 |
have 20: "\<And>X3. X3 = (0\<Colon>'a) \<or> \<bar>X3\<bar> \<noteq> (0\<Colon>'a)"
|
|
237 |
by (metis 19 11 12)
|
|
238 |
have 21: "\<And>X3::'a. \<bar>\<bar>X3\<bar>\<bar> = \<bar>X3\<bar> \<or> \<not> (0\<Colon>'a) \<le> (1\<Colon>'a)"
|
|
239 |
by (metis abs_idempotent abs_mult_pos 11)
|
|
240 |
have 22: "\<And>X3. \<not> \<bar>X3\<bar> < (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> (1\<Colon>'a)"
|
|
241 |
by (metis abs_not_less_zero abs_mult_pos 11)
|
|
242 |
have 23: "\<And>X3. X3 = (0\<Colon>'a) \<or> \<not> \<bar>X3\<bar> \<le> (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> (1\<Colon>'a)"
|
|
243 |
by (metis abs_le_zero_iff abs_mult_pos 11 11)
|
|
244 |
have 24: "\<And>X3. X3 * X3 = (0\<Colon>'a) \<or> \<not> X3 * X3 \<le> (0\<Colon>'a)"
|
|
245 |
by (metis 23 12 abs_mult_self abs_mult AC_mult.f.commute)
|
|
246 |
have 25: "\<And>X3. \<bar>X3\<bar> = (0\<Colon>'a) \<or> \<not> X3 \<le> (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> X3"
|
|
247 |
by (metis mult_eq_0_iff abs_mult_self 24 mult_le_0_iff)
|
|
248 |
have 26: "\<And>X1 X3. X3 * X1 = (0\<Colon>'a) \<or> \<not> X1 \<le> (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> X1"
|
|
249 |
by (metis 20 17 25)
|
|
250 |
have 27: "\<And>X1 X3.
|
|
251 |
(0\<Colon>'a) = \<bar>X3 * X1\<bar> \<or> \<not> (0\<Colon>'a) \<le> \<bar>X1\<bar> \<or> \<not> \<bar>X3\<bar> \<le> (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> \<bar>X3\<bar>"
|
|
252 |
by (metis abs_mult_pos abs_mult 25 mult_cancel_left1 21 12)
|
|
253 |
have 28: "\<And>X1 X3. (0\<Colon>'a) = \<bar>X3 * X1\<bar> \<or> \<not> \<bar>X3\<bar> \<le> (0\<Colon>'a)"
|
|
254 |
by (metis 27 18 18)
|
|
255 |
have 29: "\<And>X1 X3. X3 * X1 = (0\<Colon>'a) \<or> \<not> \<bar>X1\<bar> \<le> (0\<Colon>'a)"
|
|
256 |
by (metis 20 28 AC_mult.f.commute)
|
|
257 |
have 30: "\<And>X3. \<bar>h X3\<bar> \<le> (0\<Colon>'a) \<or> \<not> \<bar>f X3\<bar> \<le> (0\<Colon>'a)"
|
|
258 |
by (metis 0 26 18)
|
|
259 |
have 31: "\<And>X1 X3. X3 * X1 = (0\<Colon>'a) \<or> (0\<Colon>'a) < \<bar>X1\<bar>"
|
|
260 |
by (metis 29 linorder_not_le)
|
|
261 |
have 32: "(0\<Colon>'a) < \<bar>f x\<bar> \<or> \<not> \<bar>h x\<bar> \<le> (0\<Colon>'a)"
|
|
262 |
by (metis 10 31 21 12)
|
|
263 |
have 33: "\<And>X3. \<bar>h X3\<bar> < (0\<Colon>'a) \<or> \<not> c < (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) < \<bar>f X3\<bar>"
|
|
264 |
by (metis order_le_less_trans 0 mult_less_0_iff)
|
|
265 |
have 34: "\<And>X3. \<not> (0\<Colon>'a) < \<bar>f X3\<bar>"
|
|
266 |
by (metis 33 linorder_antisym_conv2 8 1 22 12)
|
|
267 |
show "False"
|
|
268 |
by (metis 34 32 30 linorder_not_le)
|
|
269 |
qed
|
|
270 |
|
|
271 |
lemma (*bigo_pos_const:*) "(EX (c::'a::ordered_idom).
|
|
272 |
ALL x. (abs (h x)) <= (c * (abs (f x))))
|
|
273 |
= (EX c. 0 < c & (ALL x. (abs(h x)) <= (c * (abs (f x)))))"
|
|
274 |
apply auto
|
|
275 |
apply (case_tac "c = 0", simp)
|
|
276 |
apply (rule_tac x = "1" in exI, simp)
|
|
277 |
apply (rule_tac x = "abs c" in exI, auto);
|
|
278 |
ML{*ResReconstruct.modulus:=3*}
|
|
279 |
proof (neg_clausify)
|
|
280 |
fix c x
|
|
281 |
assume 0: "\<And>A\<Colon>'b\<Colon>type.
|
|
282 |
\<bar>(h\<Colon>'b\<Colon>type \<Rightarrow> 'a\<Colon>ordered_idom) A\<bar>
|
|
283 |
\<le> (c\<Colon>'a\<Colon>ordered_idom) * \<bar>(f\<Colon>'b\<Colon>type \<Rightarrow> 'a\<Colon>ordered_idom) A\<bar>"
|
|
284 |
assume 1: "(c\<Colon>'a\<Colon>ordered_idom) \<noteq> (0\<Colon>'a\<Colon>ordered_idom)"
|
|
285 |
assume 2: "\<not> \<bar>(h\<Colon>'b\<Colon>type \<Rightarrow> 'a\<Colon>ordered_idom) (x\<Colon>'b\<Colon>type)\<bar>
|
|
286 |
\<le> \<bar>c\<Colon>'a\<Colon>ordered_idom\<bar> * \<bar>(f\<Colon>'b\<Colon>type \<Rightarrow> 'a\<Colon>ordered_idom) x\<bar>"
|
|
287 |
have 3: "\<And>X3\<Colon>'a\<Colon>ordered_idom. (1\<Colon>'a\<Colon>ordered_idom) * X3 \<le> X3"
|
|
288 |
by (metis mult_le_cancel_right2 order_refl order_refl)
|
|
289 |
have 4: "\<bar>0\<Colon>'a\<Colon>ordered_idom\<bar> = (0\<Colon>'a\<Colon>ordered_idom)"
|
|
290 |
by (metis abs_mult_pos mult_cancel_right1 mult_cancel_right1 order_refl)
|
|
291 |
have 5: "(0\<Colon>'a\<Colon>ordered_idom) = - ((1\<Colon>'a\<Colon>ordered_idom) * (0\<Colon>'a\<Colon>ordered_idom))"
|
|
292 |
by (metis abs_of_nonpos 3 mult_cancel_right1 4)
|
|
293 |
have 6: "(c\<Colon>'a\<Colon>ordered_idom) \<le> (0\<Colon>'a\<Colon>ordered_idom)"
|
|
294 |
by (metis 2 abs_of_nonneg linorder_linear 0)
|
|
295 |
have 7: "(c\<Colon>'a\<Colon>ordered_idom) < (0\<Colon>'a\<Colon>ordered_idom)"
|
|
296 |
by (metis linorder_antisym_conv2 6 1)
|
|
297 |
have 8: "\<And>X3\<Colon>'a\<Colon>ordered_idom. X3 * (1\<Colon>'a\<Colon>ordered_idom) = X3"
|
|
298 |
by (metis mult_cancel_right1 AC_mult.f.commute)
|
|
299 |
have 9: "\<And>X3\<Colon>'a\<Colon>ordered_idom. (0\<Colon>'a\<Colon>ordered_idom) = X3 \<or> (0\<Colon>'a\<Colon>ordered_idom) \<noteq> - X3"
|
|
300 |
by (metis neg_equal_iff_equal 5 mult_cancel_right1)
|
|
301 |
have 10: "\<And>X3\<Colon>'a\<Colon>ordered_idom. (0\<Colon>'a\<Colon>ordered_idom) = \<bar>X3\<bar> \<or> X3 \<noteq> (0\<Colon>'a\<Colon>ordered_idom)"
|
|
302 |
by (metis abs_minus_cancel 9 minus_equation_iff 4)
|
|
303 |
have 11: "\<And>(X1\<Colon>'a\<Colon>ordered_idom) X3\<Colon>'a\<Colon>ordered_idom.
|
|
304 |
(0\<Colon>'a\<Colon>ordered_idom) * \<bar>X1\<bar> = \<bar>X3 * X1\<bar> \<or> X3 \<noteq> (0\<Colon>'a\<Colon>ordered_idom)"
|
|
305 |
by (metis abs_mult 10)
|
|
306 |
have 12: "\<And>(X1\<Colon>'a\<Colon>ordered_idom) X3\<Colon>'a\<Colon>ordered_idom.
|
|
307 |
X3 * X1 = (0\<Colon>'a\<Colon>ordered_idom) \<or> X3 \<noteq> (0\<Colon>'a\<Colon>ordered_idom)"
|
|
308 |
by (metis zero_less_abs_iff 11 mult_cancel_left1 abs_not_less_zero 4)
|
|
309 |
have 13: "\<And>X3\<Colon>'a\<Colon>ordered_idom. \<bar>X3 * X3\<bar> = X3 * X3"
|
|
310 |
by (metis abs_mult_self abs_mult AC_mult.f.commute)
|
|
311 |
have 14: "\<And>X3\<Colon>'a\<Colon>ordered_idom. (0\<Colon>'a\<Colon>ordered_idom) \<le> \<bar>X3\<bar>"
|
|
312 |
by (metis abs_ge_zero abs_mult_pos 8 zero_le_square AC_mult.f.commute mult_cancel_left1)
|
|
313 |
have 15: "\<And>X3\<Colon>'a\<Colon>ordered_idom.
|
|
314 |
X3 = (0\<Colon>'a\<Colon>ordered_idom) \<or>
|
|
315 |
\<bar>X3\<bar> \<noteq> (0\<Colon>'a\<Colon>ordered_idom) \<or> \<not> (0\<Colon>'a\<Colon>ordered_idom) \<le> (1\<Colon>'a\<Colon>ordered_idom)"
|
|
316 |
by (metis abs_eq_0 abs_mult_pos 8 8)
|
|
317 |
have 16: "\<And>X3\<Colon>'a\<Colon>ordered_idom.
|
|
318 |
\<bar>\<bar>X3\<bar>\<bar> = \<bar>X3\<bar> \<or> \<not> (0\<Colon>'a\<Colon>ordered_idom) \<le> (1\<Colon>'a\<Colon>ordered_idom)"
|
|
319 |
by (metis abs_idempotent abs_mult_pos 8)
|
|
320 |
have 17: "\<And>X3\<Colon>'a\<Colon>ordered_idom. \<not> \<bar>X3\<bar> < (0\<Colon>'a\<Colon>ordered_idom)"
|
|
321 |
by (metis abs_not_less_zero abs_mult_pos 8 zero_le_square AC_mult.f.commute mult_cancel_left1)
|
|
322 |
have 18: "\<And>X3\<Colon>'a\<Colon>ordered_idom.
|
|
323 |
X3 = (0\<Colon>'a\<Colon>ordered_idom) \<or>
|
|
324 |
\<not> \<bar>X3\<bar> \<le> (0\<Colon>'a\<Colon>ordered_idom) \<or>
|
|
325 |
\<not> (0\<Colon>'a\<Colon>ordered_idom) \<le> (1\<Colon>'a\<Colon>ordered_idom)"
|
|
326 |
by (metis abs_le_zero_iff abs_mult_pos 8 8)
|
|
327 |
have 19: "\<And>X3\<Colon>'a\<Colon>ordered_idom.
|
|
328 |
X3 * X3 = (0\<Colon>'a\<Colon>ordered_idom) \<or>
|
|
329 |
\<not> X3 \<le> (0\<Colon>'a\<Colon>ordered_idom) \<or> \<not> (0\<Colon>'a\<Colon>ordered_idom) \<le> X3"
|
|
330 |
by (metis 18 zero_le_square AC_mult.f.commute mult_cancel_left1 13 mult_le_0_iff)
|
|
331 |
have 20: "\<And>(X1\<Colon>'a\<Colon>ordered_idom) X3\<Colon>'a\<Colon>ordered_idom.
|
|
332 |
X3 * X1 = (0\<Colon>'a\<Colon>ordered_idom) \<or>
|
|
333 |
\<not> X1 \<le> (0\<Colon>'a\<Colon>ordered_idom) \<or> \<not> (0\<Colon>'a\<Colon>ordered_idom) \<le> X1"
|
|
334 |
by (metis 15 zero_le_square AC_mult.f.commute mult_cancel_left1 abs_mult AC_mult.f.commute 12 mult_eq_0_iff abs_mult_self 19)
|
|
335 |
have 21: "\<And>(X1\<Colon>'a\<Colon>ordered_idom) X3\<Colon>'a\<Colon>ordered_idom.
|
|
336 |
(0\<Colon>'a\<Colon>ordered_idom) = \<bar>X3 * X1\<bar> \<or>
|
|
337 |
\<not> \<bar>X3\<bar> \<le> (0\<Colon>'a\<Colon>ordered_idom) \<or> \<not> (0\<Colon>'a\<Colon>ordered_idom) \<le> \<bar>X3\<bar>"
|
|
338 |
by (metis abs_mult_pos abs_mult mult_eq_0_iff abs_mult_self 19 mult_cancel_left1 16 zero_le_square AC_mult.f.commute mult_cancel_left1 14)
|
|
339 |
have 22: "\<And>(X1\<Colon>'a\<Colon>ordered_idom) X3\<Colon>'a\<Colon>ordered_idom.
|
|
340 |
X3 * X1 = (0\<Colon>'a\<Colon>ordered_idom) \<or> \<not> \<bar>X1\<bar> \<le> (0\<Colon>'a\<Colon>ordered_idom)"
|
|
341 |
by (metis 15 zero_le_square AC_mult.f.commute mult_cancel_left1 21 14 AC_mult.f.commute)
|
|
342 |
have 23: "\<And>X3\<Colon>'b\<Colon>type.
|
|
343 |
\<bar>(h\<Colon>'b\<Colon>type \<Rightarrow> 'a\<Colon>ordered_idom) X3\<bar> \<le> (0\<Colon>'a\<Colon>ordered_idom) \<or>
|
|
344 |
(0\<Colon>'a\<Colon>ordered_idom) < \<bar>(f\<Colon>'b\<Colon>type \<Rightarrow> 'a\<Colon>ordered_idom) X3\<bar>"
|
|
345 |
by (metis 0 20 14 linorder_not_le)
|
|
346 |
have 24: "(0\<Colon>'a\<Colon>ordered_idom) < \<bar>(f\<Colon>'b\<Colon>type \<Rightarrow> 'a\<Colon>ordered_idom) (x\<Colon>'b\<Colon>type)\<bar> \<or>
|
|
347 |
\<not> \<bar>(h\<Colon>'b\<Colon>type \<Rightarrow> 'a\<Colon>ordered_idom) x\<bar> \<le> (0\<Colon>'a\<Colon>ordered_idom)"
|
|
348 |
by (metis 2 abs_of_nonpos 6 22 linorder_not_le 16 zero_le_square AC_mult.f.commute mult_cancel_left1)
|
|
349 |
have 25: "\<And>X3\<Colon>'b\<Colon>type.
|
|
350 |
\<bar>(h\<Colon>'b\<Colon>type \<Rightarrow> 'a\<Colon>ordered_idom) X3\<bar> < (0\<Colon>'a\<Colon>ordered_idom) \<or>
|
|
351 |
\<not> (0\<Colon>'a\<Colon>ordered_idom) < \<bar>(f\<Colon>'b\<Colon>type \<Rightarrow> 'a\<Colon>ordered_idom) X3\<bar>"
|
|
352 |
by (metis order_le_less_trans 0 mult_less_0_iff 7)
|
|
353 |
show "False"
|
|
354 |
by (metis 25 17 24 23)
|
|
355 |
qed
|
|
356 |
|
|
357 |
lemma (*bigo_pos_const:*) "(EX (c::'a::ordered_idom).
|
|
358 |
ALL x. (abs (h x)) <= (c * (abs (f x))))
|
|
359 |
= (EX c. 0 < c & (ALL x. (abs(h x)) <= (c * (abs (f x)))))"
|
|
360 |
apply auto
|
|
361 |
apply (case_tac "c = 0", simp)
|
|
362 |
apply (rule_tac x = "1" in exI, simp)
|
|
363 |
apply (rule_tac x = "abs c" in exI, auto);
|
|
364 |
ML{*ResReconstruct.modulus:=4*}
|
|
365 |
ML{*ResReconstruct.recon_sorts:=false*}
|
|
366 |
proof (neg_clausify)
|
|
367 |
fix c x
|
|
368 |
assume 0: "\<And>A. \<bar>h A\<bar> \<le> c * \<bar>f A\<bar>"
|
|
369 |
assume 1: "c \<noteq> (0\<Colon>'a)"
|
|
370 |
assume 2: "\<not> \<bar>h x\<bar> \<le> \<bar>c\<bar> * \<bar>f x\<bar>"
|
|
371 |
have 3: "\<And>X3. (1\<Colon>'a) * X3 \<le> X3"
|
|
372 |
by (metis mult_le_cancel_right2 order_refl order_refl)
|
|
373 |
have 4: "\<not> (0\<Colon>'a) < (0\<Colon>'a)"
|
|
374 |
by (metis abs_not_less_zero abs_mult_pos mult_cancel_right1 mult_cancel_right1 order_refl)
|
|
375 |
have 5: "c \<le> (0\<Colon>'a)"
|
|
376 |
by (metis 2 abs_of_nonneg linorder_linear 0)
|
|
377 |
have 6: "\<not> \<bar>h x\<bar> \<le> - c * \<bar>f x\<bar>"
|
|
378 |
by (metis 2 abs_of_nonpos 5)
|
|
379 |
have 7: "(0\<Colon>'a) \<le> (1\<Colon>'a)"
|
|
380 |
by (metis zero_le_square AC_mult.f.commute mult_cancel_left1)
|
|
381 |
have 8: "\<And>X3. (0\<Colon>'a) = \<bar>X3\<bar> \<or> X3 \<noteq> (0\<Colon>'a)"
|
|
382 |
by (metis abs_minus_cancel neg_equal_iff_equal abs_of_nonpos 3 mult_cancel_right1 abs_mult_pos mult_cancel_right1 mult_cancel_right1 order_refl mult_cancel_right1 minus_equation_iff abs_mult_pos mult_cancel_right1 mult_cancel_right1 order_refl)
|
|
383 |
have 9: "\<And>X1 X3. (0\<Colon>'a) = \<bar>X3 * X1\<bar> \<or> X3 \<noteq> (0\<Colon>'a)"
|
|
384 |
by (metis abs_mult 8 mult_cancel_left1)
|
|
385 |
have 10: "\<And>X1 X3. (0\<Colon>'a) = \<bar>X3 * X1\<bar> \<or> \<bar>X1\<bar> \<noteq> (0\<Colon>'a)"
|
|
386 |
by (metis abs_mult AC_mult.f.commute zero_less_abs_iff 9 4)
|
|
387 |
have 11: "\<And>X3. (0\<Colon>'a) \<le> \<bar>X3\<bar>"
|
|
388 |
by (metis abs_ge_zero abs_mult_pos mult_cancel_right1 AC_mult.f.commute 7)
|
|
389 |
have 12: "\<And>X3. X3 = (0\<Colon>'a) \<or> \<bar>X3\<bar> \<noteq> (0\<Colon>'a)"
|
|
390 |
by (metis abs_eq_0 abs_mult_pos mult_cancel_right1 AC_mult.f.commute mult_cancel_right1 AC_mult.f.commute 7)
|
|
391 |
have 13: "\<And>X3. \<not> \<bar>X3\<bar> < (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> (1\<Colon>'a)"
|
|
392 |
by (metis abs_not_less_zero abs_mult_pos mult_cancel_right1 AC_mult.f.commute)
|
|
393 |
have 14: "\<And>X3. X3 = (0\<Colon>'a) \<or> \<not> \<bar>X3\<bar> \<le> (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> (1\<Colon>'a)"
|
|
394 |
by (metis abs_le_zero_iff abs_mult_pos mult_cancel_right1 AC_mult.f.commute mult_cancel_right1 AC_mult.f.commute)
|
|
395 |
have 15: "\<And>X3. \<bar>X3\<bar> = (0\<Colon>'a) \<or> \<not> X3 \<le> (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> X3"
|
|
396 |
by (metis mult_eq_0_iff abs_mult_self 14 7 abs_mult_self abs_mult AC_mult.f.commute mult_le_0_iff)
|
|
397 |
have 16: "\<And>X1 X3.
|
|
398 |
(0\<Colon>'a) = \<bar>X3 * X1\<bar> \<or> \<not> (0\<Colon>'a) \<le> \<bar>X1\<bar> \<or> \<not> \<bar>X3\<bar> \<le> (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) \<le> \<bar>X3\<bar>"
|
|
399 |
by (metis abs_mult_pos abs_mult 15 mult_cancel_left1 abs_idempotent abs_mult_pos mult_cancel_right1 AC_mult.f.commute 7)
|
|
400 |
have 17: "\<And>X1 X3. X3 * X1 = (0\<Colon>'a) \<or> \<not> \<bar>X1\<bar> \<le> (0\<Colon>'a)"
|
|
401 |
by (metis 12 16 11 11 AC_mult.f.commute)
|
|
402 |
have 18: "\<And>X1 X3. X3 * X1 = (0\<Colon>'a) \<or> (0\<Colon>'a) < \<bar>X1\<bar>"
|
|
403 |
by (metis 17 linorder_not_le)
|
|
404 |
have 19: "\<And>X3. \<bar>h X3\<bar> < (0\<Colon>'a) \<or> \<not> c < (0\<Colon>'a) \<or> \<not> (0\<Colon>'a) < \<bar>f X3\<bar>"
|
|
405 |
by (metis order_le_less_trans 0 mult_less_0_iff)
|
|
406 |
show "False"
|
|
407 |
by (metis 19 linorder_antisym_conv2 5 1 13 7 6 18 abs_idempotent abs_mult_pos mult_cancel_right1 AC_mult.f.commute 7 0 12 10 15 11 linorder_not_le)
|
|
408 |
qed
|
|
409 |
|
|
410 |
|
|
411 |
ML{*ResReconstruct.modulus:=1*}
|
|
412 |
ML{*ResReconstruct.recon_sorts:=true*}
|
|
413 |
|
|
414 |
lemma bigo_alt_def: "O(f) =
|
|
415 |
{h. EX c. (0 < c & (ALL x. abs (h x) <= c * abs (f x)))}"
|
|
416 |
by (auto simp add: bigo_def bigo_pos_const)
|
|
417 |
|
|
418 |
ML{*ResAtp.problem_name := "BigO__bigo_elt_subset"*}
|
|
419 |
lemma bigo_elt_subset [intro]: "f : O(g) ==> O(f) <= O(g)"
|
|
420 |
apply (auto simp add: bigo_alt_def)
|
|
421 |
apply (rule_tac x = "ca * c" in exI)
|
|
422 |
apply (rule conjI)
|
|
423 |
apply (rule mult_pos_pos)
|
|
424 |
apply (assumption)+
|
|
425 |
(*sledgehammer*);
|
|
426 |
apply (rule allI)
|
|
427 |
apply (drule_tac x = "xa" in spec)+
|
|
428 |
apply (subgoal_tac "ca * abs(f xa) <= ca * (c * abs(g xa))");
|
|
429 |
apply (erule order_trans)
|
|
430 |
apply (simp add: mult_ac)
|
|
431 |
apply (rule mult_left_mono, assumption)
|
|
432 |
apply (rule order_less_imp_le, assumption);
|
|
433 |
done
|
|
434 |
|
|
435 |
|
|
436 |
ML{*ResAtp.problem_name := "BigO__bigo_refl"*}
|
|
437 |
lemma bigo_refl [intro]: "f : O(f)"
|
|
438 |
apply(auto simp add: bigo_def)
|
|
439 |
proof (neg_clausify)
|
|
440 |
fix x
|
|
441 |
assume 0: "\<And>mes_pSG\<Colon>'b\<Colon>ordered_idom.
|
|
442 |
\<not> \<bar>(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) ((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a) mes_pSG)\<bar>
|
|
443 |
\<le> mes_pSG * \<bar>f (x mes_pSG)\<bar>"
|
|
444 |
have 1: "\<And>X3\<Colon>'b. X3 \<le> (1\<Colon>'b) * X3 \<or> \<not> (1\<Colon>'b) \<le> (1\<Colon>'b)"
|
|
445 |
by (metis Ring_and_Field.mult_le_cancel_right1 order_refl)
|
|
446 |
have 2: "\<And>X3\<Colon>'b. X3 \<le> (1\<Colon>'b) * X3"
|
|
447 |
by (metis 1 order_refl)
|
|
448 |
show 3: "False"
|
|
449 |
by (metis 0 2)
|
|
450 |
qed
|
|
451 |
|
|
452 |
ML{*ResAtp.problem_name := "BigO__bigo_zero"*}
|
|
453 |
lemma bigo_zero: "0 : O(g)"
|
|
454 |
apply (auto simp add: bigo_def func_zero)
|
|
455 |
proof (neg_clausify)
|
|
456 |
fix x
|
|
457 |
assume 0: "\<And>mes_mVM\<Colon>'b\<Colon>ordered_idom.
|
|
458 |
\<not> (0\<Colon>'b\<Colon>ordered_idom)
|
|
459 |
\<le> mes_mVM *
|
|
460 |
\<bar>(g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom)
|
|
461 |
((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a) mes_mVM)\<bar>"
|
|
462 |
have 1: "(0\<Colon>'b\<Colon>ordered_idom) < (0\<Colon>'b\<Colon>ordered_idom)"
|
|
463 |
by (metis 0 Ring_and_Field.mult_le_cancel_left1)
|
|
464 |
show 2: "False"
|
|
465 |
by (metis Orderings.linorder_class.neq_iff 1)
|
|
466 |
qed
|
|
467 |
|
|
468 |
lemma bigo_zero2: "O(%x.0) = {%x.0}"
|
|
469 |
apply (auto simp add: bigo_def)
|
|
470 |
apply (rule ext)
|
|
471 |
apply auto
|
|
472 |
done
|
|
473 |
|
|
474 |
lemma bigo_plus_self_subset [intro]:
|
|
475 |
"O(f) + O(f) <= O(f)"
|
|
476 |
apply (auto simp add: bigo_alt_def set_plus)
|
|
477 |
apply (rule_tac x = "c + ca" in exI)
|
|
478 |
apply auto
|
|
479 |
apply (simp add: ring_distrib func_plus)
|
|
480 |
apply (blast intro:order_trans abs_triangle_ineq add_mono elim:)
|
|
481 |
done
|
|
482 |
|
|
483 |
lemma bigo_plus_idemp [simp]: "O(f) + O(f) = O(f)"
|
|
484 |
apply (rule equalityI)
|
|
485 |
apply (rule bigo_plus_self_subset)
|
|
486 |
apply (rule set_zero_plus2)
|
|
487 |
apply (rule bigo_zero)
|
|
488 |
done
|
|
489 |
|
|
490 |
lemma bigo_plus_subset [intro]: "O(f + g) <= O(f) + O(g)"
|
|
491 |
apply (rule subsetI)
|
|
492 |
apply (auto simp add: bigo_def bigo_pos_const func_plus set_plus)
|
|
493 |
apply (subst bigo_pos_const [symmetric])+
|
|
494 |
apply (rule_tac x =
|
|
495 |
"%n. if abs (g n) <= (abs (f n)) then x n else 0" in exI)
|
|
496 |
apply (rule conjI)
|
|
497 |
apply (rule_tac x = "c + c" in exI)
|
|
498 |
apply (clarsimp)
|
|
499 |
apply (auto)
|
|
500 |
apply (subgoal_tac "c * abs (f xa + g xa) <= (c + c) * abs (f xa)")
|
|
501 |
apply (erule_tac x = xa in allE)
|
|
502 |
apply (erule order_trans)
|
|
503 |
apply (simp)
|
|
504 |
apply (subgoal_tac "c * abs (f xa + g xa) <= c * (abs (f xa) + abs (g xa))")
|
|
505 |
apply (erule order_trans)
|
|
506 |
apply (simp add: ring_distrib)
|
|
507 |
apply (rule mult_left_mono)
|
|
508 |
apply assumption
|
|
509 |
apply (simp add: order_less_le)
|
|
510 |
apply (rule mult_left_mono)
|
|
511 |
apply (simp add: abs_triangle_ineq)
|
|
512 |
apply (simp add: order_less_le)
|
|
513 |
apply (rule mult_nonneg_nonneg)
|
|
514 |
apply (rule add_nonneg_nonneg)
|
|
515 |
apply auto
|
|
516 |
apply (rule_tac x = "%n. if (abs (f n)) < abs (g n) then x n else 0"
|
|
517 |
in exI)
|
|
518 |
apply (rule conjI)
|
|
519 |
apply (rule_tac x = "c + c" in exI)
|
|
520 |
apply auto
|
|
521 |
apply (subgoal_tac "c * abs (f xa + g xa) <= (c + c) * abs (g xa)")
|
|
522 |
apply (erule_tac x = xa in allE)
|
|
523 |
apply (erule order_trans)
|
|
524 |
apply (simp)
|
|
525 |
apply (subgoal_tac "c * abs (f xa + g xa) <= c * (abs (f xa) + abs (g xa))")
|
|
526 |
apply (erule order_trans)
|
|
527 |
apply (simp add: ring_distrib)
|
|
528 |
apply (rule mult_left_mono)
|
|
529 |
apply (simp add: order_less_le)
|
|
530 |
apply (simp add: order_less_le)
|
|
531 |
apply (rule mult_left_mono)
|
|
532 |
apply (rule abs_triangle_ineq)
|
|
533 |
apply (simp add: order_less_le)
|
|
534 |
apply (rule mult_nonneg_nonneg)
|
|
535 |
apply (rule add_nonneg_nonneg)
|
|
536 |
apply (erule order_less_imp_le)+
|
|
537 |
apply simp
|
|
538 |
apply (rule ext)
|
|
539 |
apply (auto simp add: if_splits linorder_not_le)
|
|
540 |
done
|
|
541 |
|
|
542 |
lemma bigo_plus_subset2 [intro]: "A <= O(f) ==> B <= O(f) ==> A + B <= O(f)"
|
|
543 |
apply (subgoal_tac "A + B <= O(f) + O(f)")
|
|
544 |
apply (erule order_trans)
|
|
545 |
apply simp
|
|
546 |
apply (auto del: subsetI simp del: bigo_plus_idemp)
|
|
547 |
done
|
|
548 |
|
|
549 |
ML{*ResAtp.problem_name := "BigO__bigo_plus_eq"*}
|
|
550 |
lemma bigo_plus_eq: "ALL x. 0 <= f x ==> ALL x. 0 <= g x ==>
|
|
551 |
O(f + g) = O(f) + O(g)"
|
|
552 |
apply (rule equalityI)
|
|
553 |
apply (rule bigo_plus_subset)
|
|
554 |
apply (simp add: bigo_alt_def set_plus func_plus)
|
|
555 |
apply clarify
|
|
556 |
(*sledgehammer*);
|
|
557 |
apply (rule_tac x = "max c ca" in exI)
|
|
558 |
apply (rule conjI)
|
|
559 |
apply (subgoal_tac "c <= max c ca")
|
|
560 |
apply (erule order_less_le_trans)
|
|
561 |
apply assumption
|
|
562 |
apply (rule le_maxI1)
|
|
563 |
apply clarify
|
|
564 |
apply (drule_tac x = "xa" in spec)+
|
|
565 |
apply (subgoal_tac "0 <= f xa + g xa")
|
|
566 |
apply (simp add: ring_distrib)
|
|
567 |
apply (subgoal_tac "abs(a xa + b xa) <= abs(a xa) + abs(b xa)")
|
|
568 |
apply (subgoal_tac "abs(a xa) + abs(b xa) <=
|
|
569 |
max c ca * f xa + max c ca * g xa")
|
|
570 |
apply (blast intro: order_trans)
|
|
571 |
defer 1
|
|
572 |
apply (rule abs_triangle_ineq)
|
|
573 |
apply (rule add_nonneg_nonneg)
|
|
574 |
apply assumption+
|
|
575 |
apply (rule add_mono)
|
|
576 |
ML{*ResAtp.problem_name := "BigO__bigo_plus_eq_simpler"*}
|
|
577 |
(*sledgehammer...fails*);
|
|
578 |
apply (subgoal_tac "c * f xa <= max c ca * f xa")
|
|
579 |
apply (blast intro: order_trans)
|
|
580 |
apply (rule mult_right_mono)
|
|
581 |
apply (rule le_maxI1)
|
|
582 |
apply assumption
|
|
583 |
apply (subgoal_tac "ca * g xa <= max c ca * g xa")
|
|
584 |
apply (blast intro: order_trans)
|
|
585 |
apply (rule mult_right_mono)
|
|
586 |
apply (rule le_maxI2)
|
|
587 |
apply assumption
|
|
588 |
done
|
|
589 |
|
|
590 |
ML{*ResAtp.problem_name := "BigO__bigo_bounded_alt"*}
|
|
591 |
lemma bigo_bounded_alt: "ALL x. 0 <= f x ==> ALL x. f x <= c * g x ==>
|
|
592 |
f : O(g)"
|
|
593 |
apply (auto simp add: bigo_def)
|
|
594 |
(*Version 1: one-shot proof*)
|
|
595 |
apply (metis OrderedGroup.abs_ge_self OrderedGroup.abs_le_D1 OrderedGroup.abs_of_nonneg Orderings.linorder_class.not_less order_less_le Orderings.xt1(12) Ring_and_Field.abs_mult)
|
|
596 |
done
|
|
597 |
|
|
598 |
lemma bigo_bounded_alt: "ALL x. 0 <= f x ==> ALL x. f x <= c * g x ==>
|
|
599 |
f : O(g)"
|
|
600 |
apply (auto simp add: bigo_def)
|
|
601 |
(*Version 2: single-step proof*)
|
|
602 |
proof (neg_clausify)
|
|
603 |
fix x
|
|
604 |
assume 0: "\<And>mes_mbt\<Colon>'a.
|
|
605 |
(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) mes_mbt
|
|
606 |
\<le> (c\<Colon>'b\<Colon>ordered_idom) * (g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) mes_mbt"
|
|
607 |
assume 1: "\<And>mes_mbs\<Colon>'b\<Colon>ordered_idom.
|
|
608 |
\<not> (f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) ((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a) mes_mbs)
|
|
609 |
\<le> mes_mbs * \<bar>(g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x mes_mbs)\<bar>"
|
|
610 |
have 2: "\<And>X3\<Colon>'a.
|
|
611 |
(c\<Colon>'b\<Colon>ordered_idom) * (g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) X3 =
|
|
612 |
(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) X3 \<or>
|
|
613 |
\<not> c * g X3 \<le> f X3"
|
|
614 |
by (metis Lattices.min_max.less_eq_less_inf.antisym_intro 0)
|
|
615 |
have 3: "\<And>X3\<Colon>'b\<Colon>ordered_idom.
|
|
616 |
\<not> (f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) ((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a) \<bar>X3\<bar>)
|
|
617 |
\<le> \<bar>X3 * (g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x \<bar>X3\<bar>)\<bar>"
|
|
618 |
by (metis 1 Ring_and_Field.abs_mult)
|
|
619 |
have 4: "\<And>X3\<Colon>'b\<Colon>ordered_idom. (1\<Colon>'b\<Colon>ordered_idom) * X3 = X3"
|
|
620 |
by (metis Ring_and_Field.mult_cancel_left2 Finite_Set.AC_mult.f.commute)
|
|
621 |
have 5: "\<And>X3\<Colon>'b\<Colon>ordered_idom. X3 * (1\<Colon>'b\<Colon>ordered_idom) = X3"
|
|
622 |
by (metis Ring_and_Field.mult_cancel_right2 Finite_Set.AC_mult.f.commute)
|
|
623 |
have 6: "\<And>X3\<Colon>'b\<Colon>ordered_idom. \<bar>X3\<bar> * \<bar>X3\<bar> = X3 * X3"
|
|
624 |
by (metis Ring_and_Field.abs_mult_self Finite_Set.AC_mult.f.commute)
|
|
625 |
have 7: "\<And>X3\<Colon>'b\<Colon>ordered_idom. (0\<Colon>'b\<Colon>ordered_idom) \<le> X3 * X3"
|
|
626 |
by (metis Ring_and_Field.zero_le_square Finite_Set.AC_mult.f.commute)
|
|
627 |
have 8: "(0\<Colon>'b\<Colon>ordered_idom) \<le> (1\<Colon>'b\<Colon>ordered_idom)"
|
|
628 |
by (metis 7 Ring_and_Field.mult_cancel_left2)
|
|
629 |
have 9: "\<And>X3\<Colon>'b\<Colon>ordered_idom. X3 * X3 = \<bar>X3 * X3\<bar>"
|
|
630 |
by (metis Ring_and_Field.abs_mult 6)
|
|
631 |
have 10: "\<bar>1\<Colon>'b\<Colon>ordered_idom\<bar> = (1\<Colon>'b\<Colon>ordered_idom)"
|
|
632 |
by (metis 9 4)
|
|
633 |
have 11: "\<And>X3\<Colon>'b\<Colon>ordered_idom. \<bar>\<bar>X3\<bar>\<bar> = \<bar>X3\<bar> * \<bar>1\<Colon>'b\<Colon>ordered_idom\<bar>"
|
|
634 |
by (metis Ring_and_Field.abs_mult OrderedGroup.abs_idempotent 5)
|
|
635 |
have 12: "\<And>X3\<Colon>'b\<Colon>ordered_idom. \<bar>\<bar>X3\<bar>\<bar> = \<bar>X3\<bar>"
|
|
636 |
by (metis 11 10 5)
|
|
637 |
have 13: "\<And>(X1\<Colon>'b\<Colon>ordered_idom) X3\<Colon>'b\<Colon>ordered_idom.
|
|
638 |
X3 * (1\<Colon>'b\<Colon>ordered_idom) \<le> X1 \<or>
|
|
639 |
\<not> \<bar>X3\<bar> \<le> X1 \<or> \<not> (0\<Colon>'b\<Colon>ordered_idom) \<le> (1\<Colon>'b\<Colon>ordered_idom)"
|
|
640 |
by (metis OrderedGroup.abs_le_D1 Ring_and_Field.abs_mult_pos 5)
|
|
641 |
have 14: "\<And>(X1\<Colon>'b\<Colon>ordered_idom) X3\<Colon>'b\<Colon>ordered_idom.
|
|
642 |
X3 \<le> X1 \<or> \<not> \<bar>X3\<bar> \<le> X1 \<or> \<not> (0\<Colon>'b\<Colon>ordered_idom) \<le> (1\<Colon>'b\<Colon>ordered_idom)"
|
|
643 |
by (metis 13 5)
|
|
644 |
have 15: "\<And>(X1\<Colon>'b\<Colon>ordered_idom) X3\<Colon>'b\<Colon>ordered_idom. X3 \<le> X1 \<or> \<not> \<bar>X3\<bar> \<le> X1"
|
|
645 |
by (metis 14 8)
|
|
646 |
have 16: "\<And>(X1\<Colon>'b\<Colon>ordered_idom) X3\<Colon>'b\<Colon>ordered_idom. X3 \<le> X1 \<or> X1 \<le> \<bar>X3\<bar>"
|
|
647 |
by (metis 15 Orderings.linorder_class.less_eq_less.linear)
|
|
648 |
have 17: "\<And>X3\<Colon>'b\<Colon>ordered_idom.
|
|
649 |
X3 * (g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) ((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a) \<bar>X3\<bar>)
|
|
650 |
\<le> (f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x \<bar>X3\<bar>)"
|
|
651 |
by (metis 3 16)
|
|
652 |
have 18: "(c\<Colon>'b\<Colon>ordered_idom) *
|
|
653 |
(g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) ((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a) \<bar>c\<bar>) =
|
|
654 |
(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x \<bar>c\<bar>)"
|
|
655 |
by (metis 2 17)
|
|
656 |
have 19: "\<And>(X1\<Colon>'b\<Colon>ordered_idom) X3\<Colon>'b\<Colon>ordered_idom. \<bar>X3 * X1\<bar> \<le> \<bar>\<bar>X3\<bar>\<bar> * \<bar>\<bar>X1\<bar>\<bar>"
|
|
657 |
by (metis 15 Ring_and_Field.abs_le_mult Ring_and_Field.abs_mult)
|
|
658 |
have 20: "\<And>(X1\<Colon>'b\<Colon>ordered_idom) X3\<Colon>'b\<Colon>ordered_idom. \<bar>X3 * X1\<bar> \<le> \<bar>X3\<bar> * \<bar>X1\<bar>"
|
|
659 |
by (metis 19 12 12)
|
|
660 |
have 21: "\<And>(X1\<Colon>'b\<Colon>ordered_idom) X3\<Colon>'b\<Colon>ordered_idom. X3 * X1 \<le> \<bar>X3\<bar> * \<bar>X1\<bar>"
|
|
661 |
by (metis 15 20)
|
|
662 |
have 22: "(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom)
|
|
663 |
((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a) \<bar>c\<Colon>'b\<Colon>ordered_idom\<bar>)
|
|
664 |
\<le> \<bar>c\<bar> * \<bar>(g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x \<bar>c\<bar>)\<bar>"
|
|
665 |
by (metis 21 18)
|
|
666 |
show 23: "False"
|
|
667 |
by (metis 22 1)
|
|
668 |
qed
|
|
669 |
|
|
670 |
|
|
671 |
text{*So here is the easier (and more natural) problem using transitivity*}
|
|
672 |
ML{*ResAtp.problem_name := "BigO__bigo_bounded_alt_trans"*}
|
|
673 |
lemma "ALL x. 0 <= f x ==> ALL x. f x <= c * g x ==> f : O(g)"
|
|
674 |
apply (auto simp add: bigo_def)
|
|
675 |
(*Version 1: one-shot proof*)
|
|
676 |
apply (metis Orderings.leD Orderings.leI abs_ge_self abs_le_D1 abs_mult abs_of_nonneg order_le_less xt1(12));
|
|
677 |
done
|
|
678 |
|
|
679 |
text{*So here is the easier (and more natural) problem using transitivity*}
|
|
680 |
ML{*ResAtp.problem_name := "BigO__bigo_bounded_alt_trans"*}
|
|
681 |
lemma "ALL x. 0 <= f x ==> ALL x. f x <= c * g x ==> f : O(g)"
|
|
682 |
apply (auto simp add: bigo_def)
|
|
683 |
(*Version 2: single-step proof*)
|
|
684 |
proof (neg_clausify)
|
|
685 |
fix x
|
|
686 |
assume 0: "\<And>mes_mb9\<Colon>'a.
|
|
687 |
(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) mes_mb9
|
|
688 |
\<le> (c\<Colon>'b\<Colon>ordered_idom) * (g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) mes_mb9"
|
|
689 |
assume 1: "\<And>mes_mb8\<Colon>'b\<Colon>ordered_idom.
|
|
690 |
\<not> (f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) ((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a) mes_mb8)
|
|
691 |
\<le> mes_mb8 * \<bar>(g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x mes_mb8)\<bar>"
|
|
692 |
have 2: "\<And>X3\<Colon>'a.
|
|
693 |
(c\<Colon>'b\<Colon>ordered_idom) * (g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) X3 =
|
|
694 |
(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) X3 \<or>
|
|
695 |
\<not> c * g X3 \<le> f X3"
|
|
696 |
by (metis Lattices.min_max.less_eq_less_inf.antisym_intro 0)
|
|
697 |
have 3: "\<And>X3\<Colon>'b\<Colon>ordered_idom.
|
|
698 |
\<not> (f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) ((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a) \<bar>X3\<bar>)
|
|
699 |
\<le> \<bar>X3 * (g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x \<bar>X3\<bar>)\<bar>"
|
|
700 |
by (metis 1 Ring_and_Field.abs_mult)
|
|
701 |
have 4: "\<And>X3\<Colon>'b\<Colon>ordered_idom. (1\<Colon>'b\<Colon>ordered_idom) * X3 = X3"
|
|
702 |
by (metis Ring_and_Field.mult_cancel_left2 Finite_Set.AC_mult.f.commute)
|
|
703 |
have 5: "\<And>X3\<Colon>'b\<Colon>ordered_idom. X3 * (1\<Colon>'b\<Colon>ordered_idom) = X3"
|
|
704 |
by (metis Ring_and_Field.mult_cancel_right2 Finite_Set.AC_mult.f.commute)
|
|
705 |
have 6: "\<And>X3\<Colon>'b\<Colon>ordered_idom. \<bar>X3\<bar> * \<bar>X3\<bar> = X3 * X3"
|
|
706 |
by (metis Ring_and_Field.abs_mult_self Finite_Set.AC_mult.f.commute)
|
|
707 |
have 7: "\<And>X3\<Colon>'b\<Colon>ordered_idom. (0\<Colon>'b\<Colon>ordered_idom) \<le> X3 * X3"
|
|
708 |
by (metis Ring_and_Field.zero_le_square Finite_Set.AC_mult.f.commute)
|
|
709 |
have 8: "(0\<Colon>'b\<Colon>ordered_idom) \<le> (1\<Colon>'b\<Colon>ordered_idom)"
|
|
710 |
by (metis 7 Ring_and_Field.mult_cancel_left2)
|
|
711 |
have 9: "\<And>X3\<Colon>'b\<Colon>ordered_idom. X3 * X3 = \<bar>X3 * X3\<bar>"
|
|
712 |
by (metis Ring_and_Field.abs_mult 6)
|
|
713 |
have 10: "\<bar>1\<Colon>'b\<Colon>ordered_idom\<bar> = (1\<Colon>'b\<Colon>ordered_idom)"
|
|
714 |
by (metis 9 4)
|
|
715 |
have 11: "\<And>X3\<Colon>'b\<Colon>ordered_idom. \<bar>\<bar>X3\<bar>\<bar> = \<bar>X3\<bar> * \<bar>1\<Colon>'b\<Colon>ordered_idom\<bar>"
|
|
716 |
by (metis Ring_and_Field.abs_mult OrderedGroup.abs_idempotent 5)
|
|
717 |
have 12: "\<And>X3\<Colon>'b\<Colon>ordered_idom. \<bar>\<bar>X3\<bar>\<bar> = \<bar>X3\<bar>"
|
|
718 |
by (metis 11 10 5)
|
|
719 |
have 13: "\<And>(X1\<Colon>'b\<Colon>ordered_idom) X3\<Colon>'b\<Colon>ordered_idom.
|
|
720 |
X3 * (1\<Colon>'b\<Colon>ordered_idom) \<le> X1 \<or>
|
|
721 |
\<not> \<bar>X3\<bar> \<le> X1 \<or> \<not> (0\<Colon>'b\<Colon>ordered_idom) \<le> (1\<Colon>'b\<Colon>ordered_idom)"
|
|
722 |
by (metis OrderedGroup.abs_le_D1 Ring_and_Field.abs_mult_pos 5)
|
|
723 |
have 14: "\<And>(X1\<Colon>'b\<Colon>ordered_idom) X3\<Colon>'b\<Colon>ordered_idom.
|
|
724 |
X3 \<le> X1 \<or> \<not> \<bar>X3\<bar> \<le> X1 \<or> \<not> (0\<Colon>'b\<Colon>ordered_idom) \<le> (1\<Colon>'b\<Colon>ordered_idom)"
|
|
725 |
by (metis 13 5)
|
|
726 |
have 15: "\<And>(X1\<Colon>'b\<Colon>ordered_idom) X3\<Colon>'b\<Colon>ordered_idom. X3 \<le> X1 \<or> \<not> \<bar>X3\<bar> \<le> X1"
|
|
727 |
by (metis 14 8)
|
|
728 |
have 16: "\<And>(X1\<Colon>'b\<Colon>ordered_idom) X3\<Colon>'b\<Colon>ordered_idom. X3 \<le> X1 \<or> X1 \<le> \<bar>X3\<bar>"
|
|
729 |
by (metis 15 Orderings.linorder_class.less_eq_less.linear)
|
|
730 |
have 17: "\<And>X3\<Colon>'b\<Colon>ordered_idom.
|
|
731 |
X3 * (g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) ((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a) \<bar>X3\<bar>)
|
|
732 |
\<le> (f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x \<bar>X3\<bar>)"
|
|
733 |
by (metis 3 16)
|
|
734 |
have 18: "(c\<Colon>'b\<Colon>ordered_idom) *
|
|
735 |
(g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) ((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a) \<bar>c\<bar>) =
|
|
736 |
(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x \<bar>c\<bar>)"
|
|
737 |
by (metis 2 17)
|
|
738 |
have 19: "\<And>(X1\<Colon>'b\<Colon>ordered_idom) X3\<Colon>'b\<Colon>ordered_idom. \<bar>X3 * X1\<bar> \<le> \<bar>\<bar>X3\<bar>\<bar> * \<bar>\<bar>X1\<bar>\<bar>"
|
|
739 |
by (metis 15 Ring_and_Field.abs_le_mult Ring_and_Field.abs_mult)
|
|
740 |
have 20: "\<And>(X1\<Colon>'b\<Colon>ordered_idom) X3\<Colon>'b\<Colon>ordered_idom. \<bar>X3 * X1\<bar> \<le> \<bar>X3\<bar> * \<bar>X1\<bar>"
|
|
741 |
by (metis 19 12 12)
|
|
742 |
have 21: "\<And>(X1\<Colon>'b\<Colon>ordered_idom) X3\<Colon>'b\<Colon>ordered_idom. X3 * X1 \<le> \<bar>X3\<bar> * \<bar>X1\<bar>"
|
|
743 |
by (metis 15 20)
|
|
744 |
have 22: "(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom)
|
|
745 |
((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a) \<bar>c\<Colon>'b\<Colon>ordered_idom\<bar>)
|
|
746 |
\<le> \<bar>c\<bar> * \<bar>(g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x \<bar>c\<bar>)\<bar>"
|
|
747 |
by (metis 21 18)
|
|
748 |
show 23: "False"
|
|
749 |
by (metis 22 1)
|
|
750 |
qed
|
|
751 |
|
|
752 |
|
|
753 |
lemma bigo_bounded: "ALL x. 0 <= f x ==> ALL x. f x <= g x ==>
|
|
754 |
f : O(g)"
|
|
755 |
apply (erule bigo_bounded_alt [of f 1 g])
|
|
756 |
apply simp
|
|
757 |
done
|
|
758 |
|
|
759 |
ML{*ResAtp.problem_name := "BigO__bigo_bounded2"*}
|
|
760 |
lemma bigo_bounded2: "ALL x. lb x <= f x ==> ALL x. f x <= lb x + g x ==>
|
|
761 |
f : lb +o O(g)"
|
|
762 |
apply (rule set_minus_imp_plus)
|
|
763 |
apply (rule bigo_bounded)
|
|
764 |
apply (auto simp add: diff_minus func_minus func_plus)
|
|
765 |
prefer 2
|
|
766 |
apply (drule_tac x = x in spec)+
|
|
767 |
apply arith (*not clear that it's provable otherwise*)
|
|
768 |
proof (neg_clausify)
|
|
769 |
fix x
|
|
770 |
assume 0: "\<And>y. lb y \<le> f y"
|
|
771 |
assume 1: "\<not> (0\<Colon>'b) \<le> f x + - lb x"
|
|
772 |
have 2: "\<And>X3. (0\<Colon>'b) + X3 = X3"
|
|
773 |
by (metis diff_eq_eq right_minus_eq)
|
|
774 |
have 3: "\<not> (0\<Colon>'b) \<le> f x - lb x"
|
|
775 |
by (metis 1 compare_rls(1))
|
|
776 |
have 4: "\<not> (0\<Colon>'b) + lb x \<le> f x"
|
|
777 |
by (metis 3 le_diff_eq)
|
|
778 |
show "False"
|
|
779 |
by (metis 4 2 0)
|
|
780 |
qed
|
|
781 |
|
|
782 |
ML{*ResAtp.problem_name := "BigO__bigo_abs"*}
|
|
783 |
lemma bigo_abs: "(%x. abs(f x)) =o O(f)"
|
|
784 |
apply (unfold bigo_def)
|
|
785 |
apply auto
|
|
786 |
proof (neg_clausify)
|
|
787 |
fix x
|
|
788 |
assume 0: "!!mes_o43::'b::ordered_idom.
|
|
789 |
~ abs ((f::'a::type => 'b::ordered_idom)
|
|
790 |
((x::'b::ordered_idom => 'a::type) mes_o43))
|
|
791 |
<= mes_o43 * abs (f (x mes_o43))"
|
|
792 |
have 1: "!!X3::'b::ordered_idom.
|
|
793 |
X3 <= (1::'b::ordered_idom) * X3 |
|
|
794 |
~ (1::'b::ordered_idom) <= (1::'b::ordered_idom)"
|
|
795 |
by (metis mult_le_cancel_right1 order_refl)
|
|
796 |
have 2: "!!X3::'b::ordered_idom. X3 <= (1::'b::ordered_idom) * X3"
|
|
797 |
by (metis 1 order_refl)
|
|
798 |
show "False"
|
|
799 |
by (metis 0 2)
|
|
800 |
qed
|
|
801 |
|
|
802 |
ML{*ResAtp.problem_name := "BigO__bigo_abs2"*}
|
|
803 |
lemma bigo_abs2: "f =o O(%x. abs(f x))"
|
|
804 |
apply (unfold bigo_def)
|
|
805 |
apply auto
|
|
806 |
proof (neg_clausify)
|
|
807 |
fix x
|
|
808 |
assume 0: "\<And>mes_o4C\<Colon>'b\<Colon>ordered_idom.
|
|
809 |
\<not> \<bar>(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) ((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a) mes_o4C)\<bar>
|
|
810 |
\<le> mes_o4C * \<bar>f (x mes_o4C)\<bar>"
|
|
811 |
have 1: "\<And>X3\<Colon>'b\<Colon>ordered_idom.
|
|
812 |
X3 \<le> (1\<Colon>'b\<Colon>ordered_idom) * X3 \<or>
|
|
813 |
\<not> (1\<Colon>'b\<Colon>ordered_idom) \<le> (1\<Colon>'b\<Colon>ordered_idom)"
|
|
814 |
by (metis mult_le_cancel_right1 order_refl)
|
|
815 |
have 2: "\<And>X3\<Colon>'b\<Colon>ordered_idom. X3 \<le> (1\<Colon>'b\<Colon>ordered_idom) * X3"
|
|
816 |
by (metis 1 order_refl)
|
|
817 |
show "False"
|
|
818 |
by (metis 0 2)
|
|
819 |
qed
|
|
820 |
|
|
821 |
lemma bigo_abs3: "O(f) = O(%x. abs(f x))"
|
|
822 |
apply (rule equalityI)
|
|
823 |
apply (rule bigo_elt_subset)
|
|
824 |
apply (rule bigo_abs2)
|
|
825 |
apply (rule bigo_elt_subset)
|
|
826 |
apply (rule bigo_abs)
|
|
827 |
done
|
|
828 |
|
|
829 |
lemma bigo_abs4: "f =o g +o O(h) ==>
|
|
830 |
(%x. abs (f x)) =o (%x. abs (g x)) +o O(h)"
|
|
831 |
apply (drule set_plus_imp_minus)
|
|
832 |
apply (rule set_minus_imp_plus)
|
|
833 |
apply (subst func_diff)
|
|
834 |
proof -
|
|
835 |
assume a: "f - g : O(h)"
|
|
836 |
have "(%x. abs (f x) - abs (g x)) =o O(%x. abs(abs (f x) - abs (g x)))"
|
|
837 |
by (rule bigo_abs2)
|
|
838 |
also have "... <= O(%x. abs (f x - g x))"
|
|
839 |
apply (rule bigo_elt_subset)
|
|
840 |
apply (rule bigo_bounded)
|
|
841 |
apply force
|
|
842 |
apply (rule allI)
|
|
843 |
apply (rule abs_triangle_ineq3)
|
|
844 |
done
|
|
845 |
also have "... <= O(f - g)"
|
|
846 |
apply (rule bigo_elt_subset)
|
|
847 |
apply (subst func_diff)
|
|
848 |
apply (rule bigo_abs)
|
|
849 |
done
|
|
850 |
also have "... <= O(h)"
|
23464
|
851 |
using a by (rule bigo_elt_subset)
|
23449
|
852 |
finally show "(%x. abs (f x) - abs (g x)) : O(h)".
|
|
853 |
qed
|
|
854 |
|
|
855 |
lemma bigo_abs5: "f =o O(g) ==> (%x. abs(f x)) =o O(g)"
|
|
856 |
by (unfold bigo_def, auto)
|
|
857 |
|
|
858 |
lemma bigo_elt_subset2 [intro]: "f : g +o O(h) ==> O(f) <= O(g) + O(h)"
|
|
859 |
proof -
|
|
860 |
assume "f : g +o O(h)"
|
|
861 |
also have "... <= O(g) + O(h)"
|
|
862 |
by (auto del: subsetI)
|
|
863 |
also have "... = O(%x. abs(g x)) + O(%x. abs(h x))"
|
|
864 |
apply (subst bigo_abs3 [symmetric])+
|
|
865 |
apply (rule refl)
|
|
866 |
done
|
|
867 |
also have "... = O((%x. abs(g x)) + (%x. abs(h x)))"
|
|
868 |
by (rule bigo_plus_eq [symmetric], auto)
|
|
869 |
finally have "f : ...".
|
|
870 |
then have "O(f) <= ..."
|
|
871 |
by (elim bigo_elt_subset)
|
|
872 |
also have "... = O(%x. abs(g x)) + O(%x. abs(h x))"
|
|
873 |
by (rule bigo_plus_eq, auto)
|
|
874 |
finally show ?thesis
|
|
875 |
by (simp add: bigo_abs3 [symmetric])
|
|
876 |
qed
|
|
877 |
|
|
878 |
ML{*ResAtp.problem_name := "BigO__bigo_mult"*}
|
|
879 |
lemma bigo_mult [intro]: "O(f)*O(g) <= O(f * g)"
|
|
880 |
apply (rule subsetI)
|
|
881 |
apply (subst bigo_def)
|
|
882 |
apply (auto simp del: abs_mult mult_ac
|
|
883 |
simp add: bigo_alt_def set_times func_times)
|
|
884 |
(*sledgehammer*);
|
|
885 |
apply (rule_tac x = "c * ca" in exI)
|
|
886 |
apply(rule allI)
|
|
887 |
apply(erule_tac x = x in allE)+
|
|
888 |
apply(subgoal_tac "c * ca * abs(f x * g x) =
|
|
889 |
(c * abs(f x)) * (ca * abs(g x))")
|
|
890 |
ML{*ResAtp.problem_name := "BigO__bigo_mult_simpler"*}
|
|
891 |
prefer 2
|
|
892 |
apply (metis Finite_Set.AC_mult.f.assoc Finite_Set.AC_mult.f.left_commute OrderedGroup.abs_of_pos OrderedGroup.mult_left_commute Ring_and_Field.abs_mult Ring_and_Field.mult_pos_pos)
|
|
893 |
apply(erule ssubst)
|
|
894 |
apply (subst abs_mult)
|
|
895 |
(*not qute BigO__bigo_mult_simpler_1 (a hard problem!) as abs_mult has
|
|
896 |
just been done*)
|
|
897 |
proof (neg_clausify)
|
|
898 |
fix a c b ca x
|
|
899 |
assume 0: "(0\<Colon>'b\<Colon>ordered_idom) < (c\<Colon>'b\<Colon>ordered_idom)"
|
|
900 |
assume 1: "\<bar>(a\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x\<Colon>'a)\<bar>
|
|
901 |
\<le> (c\<Colon>'b\<Colon>ordered_idom) * \<bar>(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar>"
|
|
902 |
assume 2: "\<bar>(b\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x\<Colon>'a)\<bar>
|
|
903 |
\<le> (ca\<Colon>'b\<Colon>ordered_idom) * \<bar>(g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar>"
|
|
904 |
assume 3: "\<not> \<bar>(a\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x\<Colon>'a)\<bar> *
|
|
905 |
\<bar>(b\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar>
|
|
906 |
\<le> (c\<Colon>'b\<Colon>ordered_idom) * \<bar>(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar> *
|
|
907 |
((ca\<Colon>'b\<Colon>ordered_idom) * \<bar>(g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar>)"
|
|
908 |
have 4: "\<bar>c\<Colon>'b\<Colon>ordered_idom\<bar> = c"
|
|
909 |
by (metis OrderedGroup.abs_of_pos 0)
|
|
910 |
have 5: "\<And>X1\<Colon>'b\<Colon>ordered_idom. (c\<Colon>'b\<Colon>ordered_idom) * \<bar>X1\<bar> = \<bar>c * X1\<bar>"
|
|
911 |
by (metis Ring_and_Field.abs_mult 4)
|
|
912 |
have 6: "(0\<Colon>'b\<Colon>ordered_idom) = (1\<Colon>'b\<Colon>ordered_idom) \<or>
|
|
913 |
(0\<Colon>'b\<Colon>ordered_idom) < (1\<Colon>'b\<Colon>ordered_idom)"
|
|
914 |
by (metis OrderedGroup.abs_not_less_zero Ring_and_Field.abs_one Ring_and_Field.linorder_neqE_ordered_idom)
|
|
915 |
have 7: "(0\<Colon>'b\<Colon>ordered_idom) < (1\<Colon>'b\<Colon>ordered_idom)"
|
|
916 |
by (metis 6 Ring_and_Field.one_neq_zero)
|
|
917 |
have 8: "\<bar>1\<Colon>'b\<Colon>ordered_idom\<bar> = (1\<Colon>'b\<Colon>ordered_idom)"
|
|
918 |
by (metis OrderedGroup.abs_of_pos 7)
|
|
919 |
have 9: "\<And>X1\<Colon>'b\<Colon>ordered_idom. (0\<Colon>'b\<Colon>ordered_idom) \<le> (c\<Colon>'b\<Colon>ordered_idom) * \<bar>X1\<bar>"
|
|
920 |
by (metis OrderedGroup.abs_ge_zero 5)
|
|
921 |
have 10: "\<And>X1\<Colon>'b\<Colon>ordered_idom. X1 * (1\<Colon>'b\<Colon>ordered_idom) = X1"
|
|
922 |
by (metis Ring_and_Field.mult_cancel_right2 Finite_Set.AC_mult.f.commute)
|
|
923 |
have 11: "\<And>X1\<Colon>'b\<Colon>ordered_idom. \<bar>\<bar>X1\<bar>\<bar> = \<bar>X1\<bar> * \<bar>1\<Colon>'b\<Colon>ordered_idom\<bar>"
|
|
924 |
by (metis Ring_and_Field.abs_mult OrderedGroup.abs_idempotent 10)
|
|
925 |
have 12: "\<And>X1\<Colon>'b\<Colon>ordered_idom. \<bar>\<bar>X1\<bar>\<bar> = \<bar>X1\<bar>"
|
|
926 |
by (metis 11 8 10)
|
|
927 |
have 13: "\<And>X1\<Colon>'b\<Colon>ordered_idom. (0\<Colon>'b\<Colon>ordered_idom) \<le> \<bar>X1\<bar>"
|
|
928 |
by (metis OrderedGroup.abs_ge_zero 12)
|
|
929 |
have 14: "\<not> (0\<Colon>'b\<Colon>ordered_idom)
|
|
930 |
\<le> (c\<Colon>'b\<Colon>ordered_idom) * \<bar>(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x\<Colon>'a)\<bar> \<or>
|
|
931 |
\<not> (0\<Colon>'b\<Colon>ordered_idom) \<le> \<bar>(b\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar> \<or>
|
|
932 |
\<not> \<bar>b x\<bar> \<le> (ca\<Colon>'b\<Colon>ordered_idom) * \<bar>(g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar> \<or>
|
|
933 |
\<not> \<bar>(a\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar> \<le> c * \<bar>f x\<bar>"
|
|
934 |
by (metis 3 Ring_and_Field.mult_mono)
|
|
935 |
have 15: "\<not> (0\<Colon>'b\<Colon>ordered_idom) \<le> \<bar>(b\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x\<Colon>'a)\<bar> \<or>
|
|
936 |
\<not> \<bar>b x\<bar> \<le> (ca\<Colon>'b\<Colon>ordered_idom) * \<bar>(g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar> \<or>
|
|
937 |
\<not> \<bar>(a\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar>
|
|
938 |
\<le> (c\<Colon>'b\<Colon>ordered_idom) * \<bar>(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar>"
|
|
939 |
by (metis 14 9)
|
|
940 |
have 16: "\<not> \<bar>(b\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x\<Colon>'a)\<bar>
|
|
941 |
\<le> (ca\<Colon>'b\<Colon>ordered_idom) * \<bar>(g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar> \<or>
|
|
942 |
\<not> \<bar>(a\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar>
|
|
943 |
\<le> (c\<Colon>'b\<Colon>ordered_idom) * \<bar>(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar>"
|
|
944 |
by (metis 15 13)
|
|
945 |
have 17: "\<not> \<bar>(a\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x\<Colon>'a)\<bar>
|
|
946 |
\<le> (c\<Colon>'b\<Colon>ordered_idom) * \<bar>(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar>"
|
|
947 |
by (metis 16 2)
|
|
948 |
show 18: "False"
|
|
949 |
by (metis 17 1)
|
|
950 |
qed
|
|
951 |
|
|
952 |
|
|
953 |
ML{*ResAtp.problem_name := "BigO__bigo_mult2"*}
|
|
954 |
lemma bigo_mult2 [intro]: "f *o O(g) <= O(f * g)"
|
|
955 |
apply (auto simp add: bigo_def elt_set_times_def func_times abs_mult)
|
|
956 |
(*sledgehammer*);
|
|
957 |
apply (rule_tac x = c in exI)
|
|
958 |
apply clarify
|
|
959 |
apply (drule_tac x = x in spec)
|
|
960 |
ML{*ResAtp.problem_name := "BigO__bigo_mult2_simpler"*}
|
|
961 |
(*sledgehammer*);
|
|
962 |
apply (subgoal_tac "abs(f x) * abs(b x) <= abs(f x) * (c * abs(g x))")
|
|
963 |
apply (simp add: mult_ac)
|
|
964 |
apply (rule mult_left_mono, assumption)
|
|
965 |
apply (rule abs_ge_zero)
|
|
966 |
done
|
|
967 |
|
|
968 |
ML{*ResAtp.problem_name:="BigO__bigo_mult3"*}
|
|
969 |
lemma bigo_mult3: "f : O(h) ==> g : O(j) ==> f * g : O(h * j)"
|
|
970 |
by (metis bigo_mult set_times_intro subset_iff)
|
|
971 |
|
|
972 |
ML{*ResAtp.problem_name:="BigO__bigo_mult4"*}
|
|
973 |
lemma bigo_mult4 [intro]:"f : k +o O(h) ==> g * f : (g * k) +o O(g * h)"
|
|
974 |
by (metis bigo_mult2 set_plus_mono_b set_times_intro2 set_times_plus_distrib)
|
|
975 |
|
|
976 |
|
|
977 |
lemma bigo_mult5: "ALL x. f x ~= 0 ==>
|
|
978 |
O(f * g) <= (f::'a => ('b::ordered_field)) *o O(g)"
|
|
979 |
proof -
|
|
980 |
assume "ALL x. f x ~= 0"
|
|
981 |
show "O(f * g) <= f *o O(g)"
|
|
982 |
proof
|
|
983 |
fix h
|
|
984 |
assume "h : O(f * g)"
|
|
985 |
then have "(%x. 1 / (f x)) * h : (%x. 1 / f x) *o O(f * g)"
|
|
986 |
by auto
|
|
987 |
also have "... <= O((%x. 1 / f x) * (f * g))"
|
|
988 |
by (rule bigo_mult2)
|
|
989 |
also have "(%x. 1 / f x) * (f * g) = g"
|
|
990 |
apply (simp add: func_times)
|
|
991 |
apply (rule ext)
|
|
992 |
apply (simp add: prems nonzero_divide_eq_eq mult_ac)
|
|
993 |
done
|
|
994 |
finally have "(%x. (1::'b) / f x) * h : O(g)".
|
|
995 |
then have "f * ((%x. (1::'b) / f x) * h) : f *o O(g)"
|
|
996 |
by auto
|
|
997 |
also have "f * ((%x. (1::'b) / f x) * h) = h"
|
|
998 |
apply (simp add: func_times)
|
|
999 |
apply (rule ext)
|
|
1000 |
apply (simp add: prems nonzero_divide_eq_eq mult_ac)
|
|
1001 |
done
|
|
1002 |
finally show "h : f *o O(g)".
|
|
1003 |
qed
|
|
1004 |
qed
|
|
1005 |
|
|
1006 |
ML{*ResAtp.problem_name := "BigO__bigo_mult6"*}
|
|
1007 |
lemma bigo_mult6: "ALL x. f x ~= 0 ==>
|
|
1008 |
O(f * g) = (f::'a => ('b::ordered_field)) *o O(g)"
|
|
1009 |
by (metis bigo_mult2 bigo_mult5 order_antisym)
|
|
1010 |
|
|
1011 |
(*proof requires relaxing relevance: 2007-01-25*)
|
|
1012 |
ML{*ResAtp.problem_name := "BigO__bigo_mult7"*}
|
|
1013 |
declare bigo_mult6 [simp]
|
|
1014 |
lemma bigo_mult7: "ALL x. f x ~= 0 ==>
|
|
1015 |
O(f * g) <= O(f::'a => ('b::ordered_field)) * O(g)"
|
|
1016 |
(*sledgehammer*)
|
|
1017 |
apply (subst bigo_mult6)
|
|
1018 |
apply assumption
|
|
1019 |
apply (rule set_times_mono3)
|
|
1020 |
apply (rule bigo_refl)
|
|
1021 |
done
|
|
1022 |
declare bigo_mult6 [simp del]
|
|
1023 |
|
|
1024 |
ML{*ResAtp.problem_name := "BigO__bigo_mult8"*}
|
|
1025 |
declare bigo_mult7[intro!]
|
|
1026 |
lemma bigo_mult8: "ALL x. f x ~= 0 ==>
|
|
1027 |
O(f * g) = O(f::'a => ('b::ordered_field)) * O(g)"
|
|
1028 |
by (metis bigo_mult bigo_mult7 order_antisym_conv)
|
|
1029 |
|
|
1030 |
lemma bigo_minus [intro]: "f : O(g) ==> - f : O(g)"
|
|
1031 |
by (auto simp add: bigo_def func_minus)
|
|
1032 |
|
|
1033 |
lemma bigo_minus2: "f : g +o O(h) ==> -f : -g +o O(h)"
|
|
1034 |
apply (rule set_minus_imp_plus)
|
|
1035 |
apply (drule set_plus_imp_minus)
|
|
1036 |
apply (drule bigo_minus)
|
|
1037 |
apply (simp add: diff_minus)
|
|
1038 |
done
|
|
1039 |
|
|
1040 |
lemma bigo_minus3: "O(-f) = O(f)"
|
|
1041 |
by (auto simp add: bigo_def func_minus abs_minus_cancel)
|
|
1042 |
|
|
1043 |
lemma bigo_plus_absorb_lemma1: "f : O(g) ==> f +o O(g) <= O(g)"
|
|
1044 |
proof -
|
|
1045 |
assume a: "f : O(g)"
|
|
1046 |
show "f +o O(g) <= O(g)"
|
|
1047 |
proof -
|
|
1048 |
have "f : O(f)" by auto
|
|
1049 |
then have "f +o O(g) <= O(f) + O(g)"
|
|
1050 |
by (auto del: subsetI)
|
|
1051 |
also have "... <= O(g) + O(g)"
|
|
1052 |
proof -
|
|
1053 |
from a have "O(f) <= O(g)" by (auto del: subsetI)
|
|
1054 |
thus ?thesis by (auto del: subsetI)
|
|
1055 |
qed
|
|
1056 |
also have "... <= O(g)" by (simp add: bigo_plus_idemp)
|
|
1057 |
finally show ?thesis .
|
|
1058 |
qed
|
|
1059 |
qed
|
|
1060 |
|
|
1061 |
lemma bigo_plus_absorb_lemma2: "f : O(g) ==> O(g) <= f +o O(g)"
|
|
1062 |
proof -
|
|
1063 |
assume a: "f : O(g)"
|
|
1064 |
show "O(g) <= f +o O(g)"
|
|
1065 |
proof -
|
|
1066 |
from a have "-f : O(g)" by auto
|
|
1067 |
then have "-f +o O(g) <= O(g)" by (elim bigo_plus_absorb_lemma1)
|
|
1068 |
then have "f +o (-f +o O(g)) <= f +o O(g)" by auto
|
|
1069 |
also have "f +o (-f +o O(g)) = O(g)"
|
|
1070 |
by (simp add: set_plus_rearranges)
|
|
1071 |
finally show ?thesis .
|
|
1072 |
qed
|
|
1073 |
qed
|
|
1074 |
|
|
1075 |
ML{*ResAtp.problem_name:="BigO__bigo_plus_absorb"*}
|
|
1076 |
lemma bigo_plus_absorb [simp]: "f : O(g) ==> f +o O(g) = O(g)"
|
|
1077 |
by (metis bigo_plus_absorb_lemma1 bigo_plus_absorb_lemma2 order_eq_iff);
|
|
1078 |
|
|
1079 |
lemma bigo_plus_absorb2 [intro]: "f : O(g) ==> A <= O(g) ==> f +o A <= O(g)"
|
|
1080 |
apply (subgoal_tac "f +o A <= f +o O(g)")
|
|
1081 |
apply force+
|
|
1082 |
done
|
|
1083 |
|
|
1084 |
lemma bigo_add_commute_imp: "f : g +o O(h) ==> g : f +o O(h)"
|
|
1085 |
apply (subst set_minus_plus [symmetric])
|
|
1086 |
apply (subgoal_tac "g - f = - (f - g)")
|
|
1087 |
apply (erule ssubst)
|
|
1088 |
apply (rule bigo_minus)
|
|
1089 |
apply (subst set_minus_plus)
|
|
1090 |
apply assumption
|
|
1091 |
apply (simp add: diff_minus add_ac)
|
|
1092 |
done
|
|
1093 |
|
|
1094 |
lemma bigo_add_commute: "(f : g +o O(h)) = (g : f +o O(h))"
|
|
1095 |
apply (rule iffI)
|
|
1096 |
apply (erule bigo_add_commute_imp)+
|
|
1097 |
done
|
|
1098 |
|
|
1099 |
lemma bigo_const1: "(%x. c) : O(%x. 1)"
|
|
1100 |
by (auto simp add: bigo_def mult_ac)
|
|
1101 |
|
|
1102 |
declare bigo_const1 [skolem]
|
|
1103 |
|
|
1104 |
ML{*ResAtp.problem_name:="BigO__bigo_const2"*}
|
|
1105 |
lemma (*bigo_const2 [intro]:*) "O(%x. c) <= O(%x. 1)"
|
|
1106 |
by (metis bigo_const1 bigo_elt_subset);
|
|
1107 |
|
|
1108 |
lemma bigo_const2 [intro]: "O(%x. c) <= O(%x. 1)";
|
|
1109 |
(*??FAILS because the two occurrences of COMBK have different polymorphic types
|
|
1110 |
proof (neg_clausify)
|
|
1111 |
assume 0: "\<not> O(COMBK (c\<Colon>'b\<Colon>ordered_idom)) \<subseteq> O(COMBK (1\<Colon>'b\<Colon>ordered_idom))"
|
|
1112 |
have 1: "COMBK (c\<Colon>'b\<Colon>ordered_idom) \<notin> O(COMBK (1\<Colon>'b\<Colon>ordered_idom))"
|
|
1113 |
apply (rule notI)
|
|
1114 |
apply (rule 0 [THEN notE])
|
|
1115 |
apply (rule bigo_elt_subset)
|
|
1116 |
apply assumption;
|
|
1117 |
sorry
|
|
1118 |
by (metis 0 bigo_elt_subset) loops??
|
|
1119 |
show "False"
|
|
1120 |
by (metis 1 bigo_const1)
|
|
1121 |
qed
|
|
1122 |
*)
|
|
1123 |
apply (rule bigo_elt_subset)
|
|
1124 |
apply (rule bigo_const1)
|
|
1125 |
done
|
|
1126 |
|
|
1127 |
declare bigo_const2 [skolem]
|
|
1128 |
|
|
1129 |
ML{*ResAtp.problem_name := "BigO__bigo_const3"*}
|
|
1130 |
lemma bigo_const3: "(c::'a::ordered_field) ~= 0 ==> (%x. 1) : O(%x. c)"
|
|
1131 |
apply (simp add: bigo_def)
|
|
1132 |
proof (neg_clausify)
|
|
1133 |
assume 0: "(c\<Colon>'a\<Colon>ordered_field) \<noteq> (0\<Colon>'a\<Colon>ordered_field)"
|
|
1134 |
assume 1: "\<And>mes_md\<Colon>'a\<Colon>ordered_field. \<not> (1\<Colon>'a\<Colon>ordered_field) \<le> mes_md * \<bar>c\<Colon>'a\<Colon>ordered_field\<bar>"
|
|
1135 |
have 2: "(0\<Colon>'a\<Colon>ordered_field) = \<bar>c\<Colon>'a\<Colon>ordered_field\<bar> \<or>
|
|
1136 |
\<not> (1\<Colon>'a\<Colon>ordered_field) \<le> (1\<Colon>'a\<Colon>ordered_field)"
|
|
1137 |
by (metis 1 field_inverse)
|
|
1138 |
have 3: "\<bar>c\<Colon>'a\<Colon>ordered_field\<bar> = (0\<Colon>'a\<Colon>ordered_field)"
|
|
1139 |
by (metis 2 order_refl)
|
|
1140 |
have 4: "(0\<Colon>'a\<Colon>ordered_field) = (c\<Colon>'a\<Colon>ordered_field)"
|
|
1141 |
by (metis OrderedGroup.abs_eq_0 3)
|
|
1142 |
show 5: "False"
|
|
1143 |
by (metis 4 0)
|
|
1144 |
qed
|
|
1145 |
|
|
1146 |
lemma bigo_const4: "(c::'a::ordered_field) ~= 0 ==> O(%x. 1) <= O(%x. c)"
|
|
1147 |
by (rule bigo_elt_subset, rule bigo_const3, assumption)
|
|
1148 |
|
|
1149 |
lemma bigo_const [simp]: "(c::'a::ordered_field) ~= 0 ==>
|
|
1150 |
O(%x. c) = O(%x. 1)"
|
|
1151 |
by (rule equalityI, rule bigo_const2, rule bigo_const4, assumption)
|
|
1152 |
|
|
1153 |
ML{*ResAtp.problem_name := "BigO__bigo_const_mult1"*}
|
|
1154 |
lemma bigo_const_mult1: "(%x. c * f x) : O(f)"
|
|
1155 |
apply (simp add: bigo_def abs_mult)
|
|
1156 |
proof (neg_clausify)
|
|
1157 |
fix x
|
|
1158 |
assume 0: "\<And>mes_vAL\<Colon>'b.
|
|
1159 |
\<not> \<bar>c\<Colon>'b\<bar> *
|
|
1160 |
\<bar>(f\<Colon>'a \<Rightarrow> 'b) ((x\<Colon>'b \<Rightarrow> 'a) mes_vAL)\<bar>
|
|
1161 |
\<le> mes_vAL * \<bar>f (x mes_vAL)\<bar>"
|
|
1162 |
have 1: "\<And>Y\<Colon>'b. Y \<le> Y"
|
|
1163 |
by (metis order_refl)
|
|
1164 |
show 2: "False"
|
|
1165 |
by (metis 0 1)
|
|
1166 |
qed
|
|
1167 |
|
|
1168 |
lemma bigo_const_mult2: "O(%x. c * f x) <= O(f)"
|
|
1169 |
by (rule bigo_elt_subset, rule bigo_const_mult1)
|
|
1170 |
|
|
1171 |
ML{*ResAtp.problem_name := "BigO__bigo_const_mult3"*}
|
|
1172 |
lemma bigo_const_mult3: "(c::'a::ordered_field) ~= 0 ==> f : O(%x. c * f x)"
|
|
1173 |
apply (simp add: bigo_def)
|
|
1174 |
(*sledgehammer*);
|
|
1175 |
apply (rule_tac x = "abs(inverse c)" in exI)
|
|
1176 |
apply (simp only: abs_mult [symmetric] mult_assoc [symmetric])
|
|
1177 |
apply (subst left_inverse)
|
|
1178 |
apply (auto );
|
|
1179 |
done
|
|
1180 |
|
|
1181 |
lemma bigo_const_mult4: "(c::'a::ordered_field) ~= 0 ==>
|
|
1182 |
O(f) <= O(%x. c * f x)"
|
|
1183 |
by (rule bigo_elt_subset, rule bigo_const_mult3, assumption)
|
|
1184 |
|
|
1185 |
lemma bigo_const_mult [simp]: "(c::'a::ordered_field) ~= 0 ==>
|
|
1186 |
O(%x. c * f x) = O(f)"
|
|
1187 |
by (rule equalityI, rule bigo_const_mult2, erule bigo_const_mult4)
|
|
1188 |
|
|
1189 |
ML{*ResAtp.problem_name := "BigO__bigo_const_mult5"*}
|
|
1190 |
lemma bigo_const_mult5 [simp]: "(c::'a::ordered_field) ~= 0 ==>
|
|
1191 |
(%x. c) *o O(f) = O(f)"
|
|
1192 |
apply (auto del: subsetI)
|
|
1193 |
apply (rule order_trans)
|
|
1194 |
apply (rule bigo_mult2)
|
|
1195 |
apply (simp add: func_times)
|
|
1196 |
apply (auto intro!: subsetI simp add: bigo_def elt_set_times_def func_times)
|
|
1197 |
apply (rule_tac x = "%y. inverse c * x y" in exI)
|
|
1198 |
apply (rename_tac g d)
|
|
1199 |
apply safe;
|
|
1200 |
apply (rule_tac [2] ext)
|
|
1201 |
(*sledgehammer*);
|
|
1202 |
apply (simp_all del: mult_assoc add: mult_assoc [symmetric] abs_mult)
|
|
1203 |
apply (rule_tac x = "abs (inverse c) * d" in exI)
|
|
1204 |
apply (rule allI)
|
|
1205 |
apply (subst mult_assoc)
|
|
1206 |
apply (rule mult_left_mono)
|
|
1207 |
apply (erule spec)
|
|
1208 |
apply (simp add: );
|
|
1209 |
done
|
|
1210 |
|
|
1211 |
|
|
1212 |
ML{*ResAtp.problem_name := "BigO__bigo_const_mult6"*}
|
|
1213 |
lemma bigo_const_mult6 [intro]: "(%x. c) *o O(f) <= O(f)"
|
|
1214 |
apply (auto intro!: subsetI
|
|
1215 |
simp add: bigo_def elt_set_times_def func_times
|
|
1216 |
simp del: abs_mult mult_ac)
|
|
1217 |
(*sledgehammer*);
|
|
1218 |
apply (rule_tac x = "ca * (abs c)" in exI)
|
|
1219 |
apply (rule allI)
|
|
1220 |
apply (subgoal_tac "ca * abs(c) * abs(f x) = abs(c) * (ca * abs(f x))")
|
|
1221 |
apply (erule ssubst)
|
|
1222 |
apply (subst abs_mult)
|
|
1223 |
apply (rule mult_left_mono)
|
|
1224 |
apply (erule spec)
|
|
1225 |
apply simp
|
|
1226 |
apply(simp add: mult_ac)
|
|
1227 |
done
|
|
1228 |
|
|
1229 |
lemma bigo_const_mult7 [intro]: "f =o O(g) ==> (%x. c * f x) =o O(g)"
|
|
1230 |
proof -
|
|
1231 |
assume "f =o O(g)"
|
|
1232 |
then have "(%x. c) * f =o (%x. c) *o O(g)"
|
|
1233 |
by auto
|
|
1234 |
also have "(%x. c) * f = (%x. c * f x)"
|
|
1235 |
by (simp add: func_times)
|
|
1236 |
also have "(%x. c) *o O(g) <= O(g)"
|
|
1237 |
by (auto del: subsetI)
|
|
1238 |
finally show ?thesis .
|
|
1239 |
qed
|
|
1240 |
|
|
1241 |
lemma bigo_compose1: "f =o O(g) ==> (%x. f(k x)) =o O(%x. g(k x))"
|
|
1242 |
by (unfold bigo_def, auto)
|
|
1243 |
|
|
1244 |
lemma bigo_compose2: "f =o g +o O(h) ==> (%x. f(k x)) =o (%x. g(k x)) +o
|
|
1245 |
O(%x. h(k x))"
|
|
1246 |
apply (simp only: set_minus_plus [symmetric] diff_minus func_minus
|
|
1247 |
func_plus)
|
|
1248 |
apply (erule bigo_compose1)
|
|
1249 |
done
|
|
1250 |
|
|
1251 |
subsection {* Setsum *}
|
|
1252 |
|
|
1253 |
lemma bigo_setsum_main: "ALL x. ALL y : A x. 0 <= h x y ==>
|
|
1254 |
EX c. ALL x. ALL y : A x. abs(f x y) <= c * (h x y) ==>
|
|
1255 |
(%x. SUM y : A x. f x y) =o O(%x. SUM y : A x. h x y)"
|
|
1256 |
apply (auto simp add: bigo_def)
|
|
1257 |
apply (rule_tac x = "abs c" in exI)
|
|
1258 |
apply (subst abs_of_nonneg) back back
|
|
1259 |
apply (rule setsum_nonneg)
|
|
1260 |
apply force
|
|
1261 |
apply (subst setsum_right_distrib)
|
|
1262 |
apply (rule allI)
|
|
1263 |
apply (rule order_trans)
|
|
1264 |
apply (rule setsum_abs)
|
|
1265 |
apply (rule setsum_mono)
|
|
1266 |
apply (blast intro: order_trans mult_right_mono abs_ge_self)
|
|
1267 |
done
|
|
1268 |
|
|
1269 |
ML{*ResAtp.problem_name := "BigO__bigo_setsum1"*}
|
|
1270 |
lemma bigo_setsum1: "ALL x y. 0 <= h x y ==>
|
|
1271 |
EX c. ALL x y. abs(f x y) <= c * (h x y) ==>
|
|
1272 |
(%x. SUM y : A x. f x y) =o O(%x. SUM y : A x. h x y)"
|
|
1273 |
apply (rule bigo_setsum_main)
|
|
1274 |
(*sledgehammer*);
|
|
1275 |
apply force
|
|
1276 |
apply clarsimp
|
|
1277 |
apply (rule_tac x = c in exI)
|
|
1278 |
apply force
|
|
1279 |
done
|
|
1280 |
|
|
1281 |
lemma bigo_setsum2: "ALL y. 0 <= h y ==>
|
|
1282 |
EX c. ALL y. abs(f y) <= c * (h y) ==>
|
|
1283 |
(%x. SUM y : A x. f y) =o O(%x. SUM y : A x. h y)"
|
|
1284 |
by (rule bigo_setsum1, auto)
|
|
1285 |
|
|
1286 |
ML{*ResAtp.problem_name := "BigO__bigo_setsum3"*}
|
|
1287 |
lemma bigo_setsum3: "f =o O(h) ==>
|
|
1288 |
(%x. SUM y : A x. (l x y) * f(k x y)) =o
|
|
1289 |
O(%x. SUM y : A x. abs(l x y * h(k x y)))"
|
|
1290 |
apply (rule bigo_setsum1)
|
|
1291 |
apply (rule allI)+
|
|
1292 |
apply (rule abs_ge_zero)
|
|
1293 |
apply (unfold bigo_def)
|
|
1294 |
apply (auto simp add: abs_mult);
|
|
1295 |
(*sledgehammer*);
|
|
1296 |
apply (rule_tac x = c in exI)
|
|
1297 |
apply (rule allI)+
|
|
1298 |
apply (subst mult_left_commute)
|
|
1299 |
apply (rule mult_left_mono)
|
|
1300 |
apply (erule spec)
|
|
1301 |
apply (rule abs_ge_zero)
|
|
1302 |
done
|
|
1303 |
|
|
1304 |
lemma bigo_setsum4: "f =o g +o O(h) ==>
|
|
1305 |
(%x. SUM y : A x. l x y * f(k x y)) =o
|
|
1306 |
(%x. SUM y : A x. l x y * g(k x y)) +o
|
|
1307 |
O(%x. SUM y : A x. abs(l x y * h(k x y)))"
|
|
1308 |
apply (rule set_minus_imp_plus)
|
|
1309 |
apply (subst func_diff)
|
|
1310 |
apply (subst setsum_subtractf [symmetric])
|
|
1311 |
apply (subst right_diff_distrib [symmetric])
|
|
1312 |
apply (rule bigo_setsum3)
|
|
1313 |
apply (subst func_diff [symmetric])
|
|
1314 |
apply (erule set_plus_imp_minus)
|
|
1315 |
done
|
|
1316 |
|
|
1317 |
ML{*ResAtp.problem_name := "BigO__bigo_setsum5"*}
|
|
1318 |
lemma bigo_setsum5: "f =o O(h) ==> ALL x y. 0 <= l x y ==>
|
|
1319 |
ALL x. 0 <= h x ==>
|
|
1320 |
(%x. SUM y : A x. (l x y) * f(k x y)) =o
|
|
1321 |
O(%x. SUM y : A x. (l x y) * h(k x y))"
|
|
1322 |
apply (subgoal_tac "(%x. SUM y : A x. (l x y) * h(k x y)) =
|
|
1323 |
(%x. SUM y : A x. abs((l x y) * h(k x y)))")
|
|
1324 |
apply (erule ssubst)
|
|
1325 |
apply (erule bigo_setsum3)
|
|
1326 |
apply (rule ext)
|
|
1327 |
apply (rule setsum_cong2)
|
|
1328 |
apply (thin_tac "f \<in> O(h)")
|
|
1329 |
(*sledgehammer*);
|
|
1330 |
apply (subst abs_of_nonneg)
|
|
1331 |
apply (rule mult_nonneg_nonneg)
|
|
1332 |
apply auto
|
|
1333 |
done
|
|
1334 |
|
|
1335 |
lemma bigo_setsum6: "f =o g +o O(h) ==> ALL x y. 0 <= l x y ==>
|
|
1336 |
ALL x. 0 <= h x ==>
|
|
1337 |
(%x. SUM y : A x. (l x y) * f(k x y)) =o
|
|
1338 |
(%x. SUM y : A x. (l x y) * g(k x y)) +o
|
|
1339 |
O(%x. SUM y : A x. (l x y) * h(k x y))"
|
|
1340 |
apply (rule set_minus_imp_plus)
|
|
1341 |
apply (subst func_diff)
|
|
1342 |
apply (subst setsum_subtractf [symmetric])
|
|
1343 |
apply (subst right_diff_distrib [symmetric])
|
|
1344 |
apply (rule bigo_setsum5)
|
|
1345 |
apply (subst func_diff [symmetric])
|
|
1346 |
apply (drule set_plus_imp_minus)
|
|
1347 |
apply auto
|
|
1348 |
done
|
|
1349 |
|
|
1350 |
subsection {* Misc useful stuff *}
|
|
1351 |
|
|
1352 |
lemma bigo_useful_intro: "A <= O(f) ==> B <= O(f) ==>
|
|
1353 |
A + B <= O(f)"
|
|
1354 |
apply (subst bigo_plus_idemp [symmetric])
|
|
1355 |
apply (rule set_plus_mono2)
|
|
1356 |
apply assumption+
|
|
1357 |
done
|
|
1358 |
|
|
1359 |
lemma bigo_useful_add: "f =o O(h) ==> g =o O(h) ==> f + g =o O(h)"
|
|
1360 |
apply (subst bigo_plus_idemp [symmetric])
|
|
1361 |
apply (rule set_plus_intro)
|
|
1362 |
apply assumption+
|
|
1363 |
done
|
|
1364 |
|
|
1365 |
lemma bigo_useful_const_mult: "(c::'a::ordered_field) ~= 0 ==>
|
|
1366 |
(%x. c) * f =o O(h) ==> f =o O(h)"
|
|
1367 |
apply (rule subsetD)
|
|
1368 |
apply (subgoal_tac "(%x. 1 / c) *o O(h) <= O(h)")
|
|
1369 |
apply assumption
|
|
1370 |
apply (rule bigo_const_mult6)
|
|
1371 |
apply (subgoal_tac "f = (%x. 1 / c) * ((%x. c) * f)")
|
|
1372 |
apply (erule ssubst)
|
|
1373 |
apply (erule set_times_intro2)
|
|
1374 |
apply (simp add: func_times)
|
|
1375 |
done
|
|
1376 |
|
|
1377 |
ML{*ResAtp.problem_name := "BigO__bigo_fix"*}
|
|
1378 |
lemma bigo_fix: "(%x. f ((x::nat) + 1)) =o O(%x. h(x + 1)) ==> f 0 = 0 ==>
|
|
1379 |
f =o O(h)"
|
|
1380 |
apply (simp add: bigo_alt_def)
|
|
1381 |
(*sledgehammer*);
|
|
1382 |
apply clarify
|
|
1383 |
apply (rule_tac x = c in exI)
|
|
1384 |
apply safe
|
|
1385 |
apply (case_tac "x = 0")
|
|
1386 |
prefer 2
|
|
1387 |
apply (subgoal_tac "x = Suc (x - 1)")
|
|
1388 |
apply (erule ssubst) back
|
|
1389 |
apply (erule spec)
|
|
1390 |
apply (rule Suc_pred')
|
|
1391 |
apply simp
|
|
1392 |
apply (metis OrderedGroup.abs_ge_zero OrderedGroup.abs_zero order_less_le Ring_and_Field.split_mult_pos_le)
|
|
1393 |
done
|
|
1394 |
|
|
1395 |
|
|
1396 |
lemma bigo_fix2:
|
|
1397 |
"(%x. f ((x::nat) + 1)) =o (%x. g(x + 1)) +o O(%x. h(x + 1)) ==>
|
|
1398 |
f 0 = g 0 ==> f =o g +o O(h)"
|
|
1399 |
apply (rule set_minus_imp_plus)
|
|
1400 |
apply (rule bigo_fix)
|
|
1401 |
apply (subst func_diff)
|
|
1402 |
apply (subst func_diff [symmetric])
|
|
1403 |
apply (rule set_plus_imp_minus)
|
|
1404 |
apply simp
|
|
1405 |
apply (simp add: func_diff)
|
|
1406 |
done
|
|
1407 |
|
|
1408 |
subsection {* Less than or equal to *}
|
|
1409 |
|
|
1410 |
constdefs
|
|
1411 |
lesso :: "('a => 'b::ordered_idom) => ('a => 'b) => ('a => 'b)"
|
|
1412 |
(infixl "<o" 70)
|
|
1413 |
"f <o g == (%x. max (f x - g x) 0)"
|
|
1414 |
|
|
1415 |
lemma bigo_lesseq1: "f =o O(h) ==> ALL x. abs (g x) <= abs (f x) ==>
|
|
1416 |
g =o O(h)"
|
|
1417 |
apply (unfold bigo_def)
|
|
1418 |
apply clarsimp
|
|
1419 |
apply (blast intro: order_trans)
|
|
1420 |
done
|
|
1421 |
|
|
1422 |
lemma bigo_lesseq2: "f =o O(h) ==> ALL x. abs (g x) <= f x ==>
|
|
1423 |
g =o O(h)"
|
|
1424 |
apply (erule bigo_lesseq1)
|
|
1425 |
apply (blast intro: abs_ge_self order_trans)
|
|
1426 |
done
|
|
1427 |
|
|
1428 |
lemma bigo_lesseq3: "f =o O(h) ==> ALL x. 0 <= g x ==> ALL x. g x <= f x ==>
|
|
1429 |
g =o O(h)"
|
|
1430 |
apply (erule bigo_lesseq2)
|
|
1431 |
apply (rule allI)
|
|
1432 |
apply (subst abs_of_nonneg)
|
|
1433 |
apply (erule spec)+
|
|
1434 |
done
|
|
1435 |
|
|
1436 |
lemma bigo_lesseq4: "f =o O(h) ==>
|
|
1437 |
ALL x. 0 <= g x ==> ALL x. g x <= abs (f x) ==>
|
|
1438 |
g =o O(h)"
|
|
1439 |
apply (erule bigo_lesseq1)
|
|
1440 |
apply (rule allI)
|
|
1441 |
apply (subst abs_of_nonneg)
|
|
1442 |
apply (erule spec)+
|
|
1443 |
done
|
|
1444 |
|
|
1445 |
ML{*ResAtp.problem_name:="BigO__bigo_lesso1"*}
|
|
1446 |
lemma bigo_lesso1: "ALL x. f x <= g x ==> f <o g =o O(h)"
|
|
1447 |
apply (unfold lesso_def)
|
|
1448 |
apply (subgoal_tac "(%x. max (f x - g x) 0) = 0")
|
|
1449 |
(*
|
|
1450 |
?? abstractions don't work: abstraction function gets the wrong type?
|
|
1451 |
proof (neg_clausify)
|
|
1452 |
assume 0: "llabs_subgoal_1 f g = 0"
|
|
1453 |
assume 1: "llabs_subgoal_1 f g \<notin> O(h)"
|
|
1454 |
show "False"
|
|
1455 |
by (metis 1 0 bigo_zero)
|
|
1456 |
*)
|
|
1457 |
apply (erule ssubst)
|
|
1458 |
apply (rule bigo_zero)
|
|
1459 |
apply (unfold func_zero)
|
|
1460 |
apply (rule ext)
|
|
1461 |
apply (simp split: split_max)
|
|
1462 |
done
|
|
1463 |
|
|
1464 |
|
|
1465 |
ML{*ResAtp.problem_name := "BigO__bigo_lesso2"*}
|
|
1466 |
lemma bigo_lesso2: "f =o g +o O(h) ==>
|
|
1467 |
ALL x. 0 <= k x ==> ALL x. k x <= f x ==>
|
|
1468 |
k <o g =o O(h)"
|
|
1469 |
apply (unfold lesso_def)
|
|
1470 |
apply (rule bigo_lesseq4)
|
|
1471 |
apply (erule set_plus_imp_minus)
|
|
1472 |
apply (rule allI)
|
|
1473 |
apply (rule le_maxI2)
|
|
1474 |
apply (rule allI)
|
|
1475 |
apply (subst func_diff)
|
|
1476 |
apply (erule thin_rl)
|
|
1477 |
(*sledgehammer*);
|
|
1478 |
apply (case_tac "0 <= k x - g x")
|
|
1479 |
apply (simp del: compare_rls diff_minus);
|
|
1480 |
apply (subst abs_of_nonneg)
|
|
1481 |
apply (drule_tac x = x in spec) back
|
|
1482 |
ML{*ResAtp.problem_name := "BigO__bigo_lesso2_simpler"*}
|
|
1483 |
(*sledgehammer*);
|
|
1484 |
apply (simp add: compare_rls del: diff_minus)
|
|
1485 |
apply (subst diff_minus)+
|
|
1486 |
apply (rule add_right_mono)
|
|
1487 |
apply (erule spec)
|
|
1488 |
apply (rule order_trans)
|
|
1489 |
prefer 2
|
|
1490 |
apply (rule abs_ge_zero)
|
|
1491 |
(*
|
|
1492 |
apply (simp only: compare_rls min_max.below_sup.above_sup_conv
|
|
1493 |
linorder_not_le order_less_imp_le)
|
|
1494 |
*)
|
|
1495 |
apply (simp add: compare_rls del: diff_minus)
|
|
1496 |
done
|
|
1497 |
|
|
1498 |
|
|
1499 |
|
|
1500 |
ML{*ResAtp.problem_name := "BigO__bigo_lesso3"*}
|
|
1501 |
lemma bigo_lesso3: "f =o g +o O(h) ==>
|
|
1502 |
ALL x. 0 <= k x ==> ALL x. g x <= k x ==>
|
|
1503 |
f <o k =o O(h)"
|
|
1504 |
apply (unfold lesso_def)
|
|
1505 |
apply (rule bigo_lesseq4)
|
|
1506 |
apply (erule set_plus_imp_minus)
|
|
1507 |
apply (rule allI)
|
|
1508 |
apply (rule le_maxI2)
|
|
1509 |
apply (rule allI)
|
|
1510 |
apply (subst func_diff)
|
|
1511 |
apply (erule thin_rl)
|
|
1512 |
(*sledgehammer*);
|
|
1513 |
apply (case_tac "0 <= f x - k x")
|
|
1514 |
apply (simp del: compare_rls diff_minus);
|
|
1515 |
apply (subst abs_of_nonneg)
|
|
1516 |
apply (drule_tac x = x in spec) back
|
|
1517 |
ML{*ResAtp.problem_name := "BigO__bigo_lesso3_simpler"*}
|
|
1518 |
(*sledgehammer*);
|
|
1519 |
apply (simp del: diff_minus)
|
|
1520 |
apply (subst diff_minus)+
|
|
1521 |
apply (rule add_left_mono)
|
|
1522 |
apply (rule le_imp_neg_le)
|
|
1523 |
apply (erule spec)
|
|
1524 |
apply (rule order_trans)
|
|
1525 |
prefer 2
|
|
1526 |
apply (rule abs_ge_zero)
|
|
1527 |
apply (simp del: diff_minus)
|
|
1528 |
done
|
|
1529 |
|
|
1530 |
lemma bigo_lesso4: "f <o g =o O(k::'a=>'b::ordered_field) ==>
|
|
1531 |
g =o h +o O(k) ==> f <o h =o O(k)"
|
|
1532 |
apply (unfold lesso_def)
|
|
1533 |
apply (drule set_plus_imp_minus)
|
|
1534 |
apply (drule bigo_abs5) back
|
|
1535 |
apply (simp add: func_diff)
|
|
1536 |
apply (drule bigo_useful_add)
|
|
1537 |
apply assumption
|
|
1538 |
apply (erule bigo_lesseq2) back
|
|
1539 |
apply (rule allI)
|
|
1540 |
apply (auto simp add: func_plus func_diff compare_rls
|
|
1541 |
split: split_max abs_split)
|
|
1542 |
done
|
|
1543 |
|
|
1544 |
ML{*ResAtp.problem_name := "BigO__bigo_lesso5"*}
|
|
1545 |
lemma bigo_lesso5: "f <o g =o O(h) ==>
|
|
1546 |
EX C. ALL x. f x <= g x + C * abs(h x)"
|
|
1547 |
apply (simp only: lesso_def bigo_alt_def)
|
|
1548 |
apply clarsimp
|
|
1549 |
(*sledgehammer*);
|
|
1550 |
apply (auto simp add: compare_rls add_ac)
|
|
1551 |
done
|
|
1552 |
|
|
1553 |
end
|