| author | paulson | 
| Thu, 06 Sep 2007 16:54:03 +0200 | |
| changeset 24545 | f406a5744756 | 
| parent 23816 | 3879cb3d0ba7 | 
| child 24855 | 161eb8381b49 | 
| permissions | -rw-r--r-- | 
| 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*}
 | 
|
| 24545 | 412  | 
|
413  | 
(*Vampire finds this structured proof*)  | 
|
414  | 
lemma (*bigo_pos_const:*) "(EX (c::'a::ordered_idom).  | 
|
415  | 
ALL x. (abs (h x)) <= (c * (abs (f x))))  | 
|
416  | 
= (EX c. 0 < c & (ALL x. (abs(h x)) <= (c * (abs (f x)))))"  | 
|
417  | 
apply auto  | 
|
418  | 
apply (case_tac "c = 0", simp)  | 
|
419  | 
apply (rule_tac x = "1" in exI, simp)  | 
|
420  | 
apply (rule_tac x = "abs c" in exI, auto);  | 
|
421  | 
proof (neg_clausify)  | 
|
422  | 
fix c x (*sort/type constraint inserted by hand!*)  | 
|
423  | 
have 0: "\<And>(X1\<Colon>'a\<Colon>ordered_idom) X2. \<bar>X1 * \<bar>X2\<bar>\<bar> = \<bar>X1 * X2\<bar>"  | 
|
424  | 
by (metis abs_ge_zero abs_mult_pos abs_mult)  | 
|
425  | 
assume 1: "\<And>A. \<bar>h A\<bar> \<le> c * \<bar>f A\<bar>"  | 
|
426  | 
have 2: "\<And>X1 X2. \<not> \<bar>X1\<bar> \<le> X2 \<or> (0\<Colon>'a) \<le> X2"  | 
|
427  | 
by (metis abs_ge_zero order_trans)  | 
|
428  | 
have 3: "\<And>X1. (0\<Colon>'a) \<le> c * \<bar>f X1\<bar>"  | 
|
429  | 
by (metis 1 2)  | 
|
430  | 
have 4: "\<And>X1. c * \<bar>f X1\<bar> = \<bar>c * f X1\<bar>"  | 
|
431  | 
by (metis 0 abs_of_nonneg 3)  | 
|
432  | 
have 5: "\<And>X1. - h X1 \<le> c * \<bar>f X1\<bar>"  | 
|
433  | 
by (metis 1 abs_le_D2)  | 
|
434  | 
have 6: "\<And>X1. - h X1 \<le> \<bar>c * f X1\<bar>"  | 
|
435  | 
by (metis 4 5)  | 
|
436  | 
have 7: "\<And>X1. h X1 \<le> c * \<bar>f X1\<bar>"  | 
|
437  | 
by (metis 1 abs_le_D1)  | 
|
438  | 
have 8: "\<And>X1. h X1 \<le> \<bar>c * f X1\<bar>"  | 
|
439  | 
by (metis 4 7)  | 
|
440  | 
assume 9: "\<not> \<bar>h x\<bar> \<le> \<bar>c\<bar> * \<bar>f x\<bar>"  | 
|
441  | 
have 10: "\<not> \<bar>h x\<bar> \<le> \<bar>c * f x\<bar>"  | 
|
442  | 
by (metis abs_mult 9)  | 
|
443  | 
show "False"  | 
|
444  | 
by (metis 6 8 10 abs_leI)  | 
|
445  | 
qed  | 
|
446  | 
||
447  | 
||
| 23449 | 448  | 
ML{*ResReconstruct.recon_sorts:=true*}
 | 
449  | 
||
| 24545 | 450  | 
|
| 23449 | 451  | 
lemma bigo_alt_def: "O(f) =  | 
452  | 
    {h. EX c. (0 < c & (ALL x. abs (h x) <= c * abs (f x)))}"
 | 
|
453  | 
by (auto simp add: bigo_def bigo_pos_const)  | 
|
454  | 
||
455  | 
ML{*ResAtp.problem_name := "BigO__bigo_elt_subset"*}
 | 
|
456  | 
lemma bigo_elt_subset [intro]: "f : O(g) ==> O(f) <= O(g)"  | 
|
457  | 
apply (auto simp add: bigo_alt_def)  | 
|
458  | 
apply (rule_tac x = "ca * c" in exI)  | 
|
459  | 
apply (rule conjI)  | 
|
460  | 
apply (rule mult_pos_pos)  | 
|
461  | 
apply (assumption)+  | 
|
462  | 
(*sledgehammer*);  | 
|
463  | 
apply (rule allI)  | 
|
464  | 
apply (drule_tac x = "xa" in spec)+  | 
|
465  | 
apply (subgoal_tac "ca * abs(f xa) <= ca * (c * abs(g xa))");  | 
|
466  | 
apply (erule order_trans)  | 
|
467  | 
apply (simp add: mult_ac)  | 
|
468  | 
apply (rule mult_left_mono, assumption)  | 
|
469  | 
apply (rule order_less_imp_le, assumption);  | 
|
470  | 
done  | 
|
471  | 
||
472  | 
||
473  | 
ML{*ResAtp.problem_name := "BigO__bigo_refl"*}
 | 
|
474  | 
lemma bigo_refl [intro]: "f : O(f)"  | 
|
475  | 
apply(auto simp add: bigo_def)  | 
|
476  | 
proof (neg_clausify)  | 
|
477  | 
fix x  | 
|
478  | 
assume 0: "\<And>mes_pSG\<Colon>'b\<Colon>ordered_idom.  | 
|
479  | 
\<not> \<bar>(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) ((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a) mes_pSG)\<bar>  | 
|
480  | 
\<le> mes_pSG * \<bar>f (x mes_pSG)\<bar>"  | 
|
481  | 
have 1: "\<And>X3\<Colon>'b. X3 \<le> (1\<Colon>'b) * X3 \<or> \<not> (1\<Colon>'b) \<le> (1\<Colon>'b)"  | 
|
482  | 
by (metis Ring_and_Field.mult_le_cancel_right1 order_refl)  | 
|
483  | 
have 2: "\<And>X3\<Colon>'b. X3 \<le> (1\<Colon>'b) * X3"  | 
|
484  | 
by (metis 1 order_refl)  | 
|
485  | 
show 3: "False"  | 
|
486  | 
by (metis 0 2)  | 
|
487  | 
qed  | 
|
488  | 
||
489  | 
ML{*ResAtp.problem_name := "BigO__bigo_zero"*}
 | 
|
490  | 
lemma bigo_zero: "0 : O(g)"  | 
|
491  | 
apply (auto simp add: bigo_def func_zero)  | 
|
492  | 
proof (neg_clausify)  | 
|
493  | 
fix x  | 
|
494  | 
assume 0: "\<And>mes_mVM\<Colon>'b\<Colon>ordered_idom.  | 
|
495  | 
\<not> (0\<Colon>'b\<Colon>ordered_idom)  | 
|
496  | 
\<le> mes_mVM *  | 
|
497  | 
\<bar>(g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom)  | 
|
498  | 
((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a) mes_mVM)\<bar>"  | 
|
499  | 
have 1: "(0\<Colon>'b\<Colon>ordered_idom) < (0\<Colon>'b\<Colon>ordered_idom)"  | 
|
500  | 
by (metis 0 Ring_and_Field.mult_le_cancel_left1)  | 
|
501  | 
show 2: "False"  | 
|
502  | 
by (metis Orderings.linorder_class.neq_iff 1)  | 
|
503  | 
qed  | 
|
504  | 
||
505  | 
lemma bigo_zero2: "O(%x.0) = {%x.0}"
 | 
|
506  | 
apply (auto simp add: bigo_def)  | 
|
507  | 
apply (rule ext)  | 
|
508  | 
apply auto  | 
|
509  | 
done  | 
|
510  | 
||
511  | 
lemma bigo_plus_self_subset [intro]:  | 
|
512  | 
"O(f) + O(f) <= O(f)"  | 
|
513  | 
apply (auto simp add: bigo_alt_def set_plus)  | 
|
514  | 
apply (rule_tac x = "c + ca" in exI)  | 
|
515  | 
apply auto  | 
|
| 
23477
 
f4b83f03cac9
tuned and renamed group_eq_simps and ring_eq_simps
 
nipkow 
parents: 
23464 
diff
changeset
 | 
516  | 
apply (simp add: ring_distribs func_plus)  | 
| 23449 | 517  | 
apply (blast intro:order_trans abs_triangle_ineq add_mono elim:)  | 
518  | 
done  | 
|
519  | 
||
520  | 
lemma bigo_plus_idemp [simp]: "O(f) + O(f) = O(f)"  | 
|
521  | 
apply (rule equalityI)  | 
|
522  | 
apply (rule bigo_plus_self_subset)  | 
|
523  | 
apply (rule set_zero_plus2)  | 
|
524  | 
apply (rule bigo_zero)  | 
|
525  | 
done  | 
|
526  | 
||
527  | 
lemma bigo_plus_subset [intro]: "O(f + g) <= O(f) + O(g)"  | 
|
528  | 
apply (rule subsetI)  | 
|
529  | 
apply (auto simp add: bigo_def bigo_pos_const func_plus set_plus)  | 
|
530  | 
apply (subst bigo_pos_const [symmetric])+  | 
|
531  | 
apply (rule_tac x =  | 
|
532  | 
"%n. if abs (g n) <= (abs (f n)) then x n else 0" in exI)  | 
|
533  | 
apply (rule conjI)  | 
|
534  | 
apply (rule_tac x = "c + c" in exI)  | 
|
535  | 
apply (clarsimp)  | 
|
536  | 
apply (auto)  | 
|
537  | 
apply (subgoal_tac "c * abs (f xa + g xa) <= (c + c) * abs (f xa)")  | 
|
538  | 
apply (erule_tac x = xa in allE)  | 
|
539  | 
apply (erule order_trans)  | 
|
540  | 
apply (simp)  | 
|
541  | 
apply (subgoal_tac "c * abs (f xa + g xa) <= c * (abs (f xa) + abs (g xa))")  | 
|
542  | 
apply (erule order_trans)  | 
|
| 
23477
 
f4b83f03cac9
tuned and renamed group_eq_simps and ring_eq_simps
 
nipkow 
parents: 
23464 
diff
changeset
 | 
543  | 
apply (simp add: ring_distribs)  | 
| 23449 | 544  | 
apply (rule mult_left_mono)  | 
545  | 
apply assumption  | 
|
546  | 
apply (simp add: order_less_le)  | 
|
547  | 
apply (rule mult_left_mono)  | 
|
548  | 
apply (simp add: abs_triangle_ineq)  | 
|
549  | 
apply (simp add: order_less_le)  | 
|
550  | 
apply (rule mult_nonneg_nonneg)  | 
|
551  | 
apply (rule add_nonneg_nonneg)  | 
|
552  | 
apply auto  | 
|
553  | 
apply (rule_tac x = "%n. if (abs (f n)) < abs (g n) then x n else 0"  | 
|
554  | 
in exI)  | 
|
555  | 
apply (rule conjI)  | 
|
556  | 
apply (rule_tac x = "c + c" in exI)  | 
|
557  | 
apply auto  | 
|
558  | 
apply (subgoal_tac "c * abs (f xa + g xa) <= (c + c) * abs (g xa)")  | 
|
559  | 
apply (erule_tac x = xa in allE)  | 
|
560  | 
apply (erule order_trans)  | 
|
561  | 
apply (simp)  | 
|
562  | 
apply (subgoal_tac "c * abs (f xa + g xa) <= c * (abs (f xa) + abs (g xa))")  | 
|
563  | 
apply (erule order_trans)  | 
|
| 
23477
 
f4b83f03cac9
tuned and renamed group_eq_simps and ring_eq_simps
 
nipkow 
parents: 
23464 
diff
changeset
 | 
564  | 
apply (simp add: ring_distribs)  | 
| 23449 | 565  | 
apply (rule mult_left_mono)  | 
566  | 
apply (simp add: order_less_le)  | 
|
567  | 
apply (simp add: order_less_le)  | 
|
568  | 
apply (rule mult_left_mono)  | 
|
569  | 
apply (rule abs_triangle_ineq)  | 
|
570  | 
apply (simp add: order_less_le)  | 
|
571  | 
apply (rule mult_nonneg_nonneg)  | 
|
572  | 
apply (rule add_nonneg_nonneg)  | 
|
573  | 
apply (erule order_less_imp_le)+  | 
|
574  | 
apply simp  | 
|
575  | 
apply (rule ext)  | 
|
576  | 
apply (auto simp add: if_splits linorder_not_le)  | 
|
577  | 
done  | 
|
578  | 
||
579  | 
lemma bigo_plus_subset2 [intro]: "A <= O(f) ==> B <= O(f) ==> A + B <= O(f)"  | 
|
580  | 
apply (subgoal_tac "A + B <= O(f) + O(f)")  | 
|
581  | 
apply (erule order_trans)  | 
|
582  | 
apply simp  | 
|
583  | 
apply (auto del: subsetI simp del: bigo_plus_idemp)  | 
|
584  | 
done  | 
|
585  | 
||
586  | 
ML{*ResAtp.problem_name := "BigO__bigo_plus_eq"*}
 | 
|
587  | 
lemma bigo_plus_eq: "ALL x. 0 <= f x ==> ALL x. 0 <= g x ==>  | 
|
588  | 
O(f + g) = O(f) + O(g)"  | 
|
589  | 
apply (rule equalityI)  | 
|
590  | 
apply (rule bigo_plus_subset)  | 
|
591  | 
apply (simp add: bigo_alt_def set_plus func_plus)  | 
|
592  | 
apply clarify  | 
|
593  | 
(*sledgehammer*);  | 
|
594  | 
apply (rule_tac x = "max c ca" in exI)  | 
|
595  | 
apply (rule conjI)  | 
|
596  | 
apply (subgoal_tac "c <= max c ca")  | 
|
597  | 
apply (erule order_less_le_trans)  | 
|
598  | 
apply assumption  | 
|
599  | 
apply (rule le_maxI1)  | 
|
600  | 
apply clarify  | 
|
601  | 
apply (drule_tac x = "xa" in spec)+  | 
|
602  | 
apply (subgoal_tac "0 <= f xa + g xa")  | 
|
| 
23477
 
f4b83f03cac9
tuned and renamed group_eq_simps and ring_eq_simps
 
nipkow 
parents: 
23464 
diff
changeset
 | 
603  | 
apply (simp add: ring_distribs)  | 
| 23449 | 604  | 
apply (subgoal_tac "abs(a xa + b xa) <= abs(a xa) + abs(b xa)")  | 
605  | 
apply (subgoal_tac "abs(a xa) + abs(b xa) <=  | 
|
606  | 
max c ca * f xa + max c ca * g xa")  | 
|
607  | 
apply (blast intro: order_trans)  | 
|
608  | 
defer 1  | 
|
609  | 
apply (rule abs_triangle_ineq)  | 
|
610  | 
apply (rule add_nonneg_nonneg)  | 
|
611  | 
apply assumption+  | 
|
612  | 
apply (rule add_mono)  | 
|
613  | 
ML{*ResAtp.problem_name := "BigO__bigo_plus_eq_simpler"*} 
 | 
|
614  | 
(*sledgehammer...fails*);  | 
|
615  | 
apply (subgoal_tac "c * f xa <= max c ca * f xa")  | 
|
616  | 
apply (blast intro: order_trans)  | 
|
617  | 
apply (rule mult_right_mono)  | 
|
618  | 
apply (rule le_maxI1)  | 
|
619  | 
apply assumption  | 
|
620  | 
apply (subgoal_tac "ca * g xa <= max c ca * g xa")  | 
|
621  | 
apply (blast intro: order_trans)  | 
|
622  | 
apply (rule mult_right_mono)  | 
|
623  | 
apply (rule le_maxI2)  | 
|
624  | 
apply assumption  | 
|
625  | 
done  | 
|
626  | 
||
627  | 
ML{*ResAtp.problem_name := "BigO__bigo_bounded_alt"*}
 | 
|
628  | 
lemma bigo_bounded_alt: "ALL x. 0 <= f x ==> ALL x. f x <= c * g x ==>  | 
|
629  | 
f : O(g)"  | 
|
630  | 
apply (auto simp add: bigo_def)  | 
|
631  | 
(*Version 1: one-shot proof*)  | 
|
632  | 
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)  | 
|
633  | 
done  | 
|
634  | 
||
635  | 
lemma bigo_bounded_alt: "ALL x. 0 <= f x ==> ALL x. f x <= c * g x ==>  | 
|
636  | 
f : O(g)"  | 
|
637  | 
apply (auto simp add: bigo_def)  | 
|
638  | 
(*Version 2: single-step proof*)  | 
|
639  | 
proof (neg_clausify)  | 
|
640  | 
fix x  | 
|
641  | 
assume 0: "\<And>mes_mbt\<Colon>'a.  | 
|
642  | 
(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) mes_mbt  | 
|
643  | 
\<le> (c\<Colon>'b\<Colon>ordered_idom) * (g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) mes_mbt"  | 
|
644  | 
assume 1: "\<And>mes_mbs\<Colon>'b\<Colon>ordered_idom.  | 
|
645  | 
\<not> (f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) ((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a) mes_mbs)  | 
|
646  | 
\<le> mes_mbs * \<bar>(g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x mes_mbs)\<bar>"  | 
|
647  | 
have 2: "\<And>X3\<Colon>'a.  | 
|
648  | 
(c\<Colon>'b\<Colon>ordered_idom) * (g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) X3 =  | 
|
649  | 
(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) X3 \<or>  | 
|
650  | 
\<not> c * g X3 \<le> f X3"  | 
|
651  | 
by (metis Lattices.min_max.less_eq_less_inf.antisym_intro 0)  | 
|
652  | 
have 3: "\<And>X3\<Colon>'b\<Colon>ordered_idom.  | 
|
653  | 
\<not> (f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) ((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a) \<bar>X3\<bar>)  | 
|
654  | 
\<le> \<bar>X3 * (g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x \<bar>X3\<bar>)\<bar>"  | 
|
655  | 
by (metis 1 Ring_and_Field.abs_mult)  | 
|
656  | 
have 4: "\<And>X3\<Colon>'b\<Colon>ordered_idom. (1\<Colon>'b\<Colon>ordered_idom) * X3 = X3"  | 
|
657  | 
by (metis Ring_and_Field.mult_cancel_left2 Finite_Set.AC_mult.f.commute)  | 
|
658  | 
have 5: "\<And>X3\<Colon>'b\<Colon>ordered_idom. X3 * (1\<Colon>'b\<Colon>ordered_idom) = X3"  | 
|
659  | 
by (metis Ring_and_Field.mult_cancel_right2 Finite_Set.AC_mult.f.commute)  | 
|
660  | 
have 6: "\<And>X3\<Colon>'b\<Colon>ordered_idom. \<bar>X3\<bar> * \<bar>X3\<bar> = X3 * X3"  | 
|
661  | 
by (metis Ring_and_Field.abs_mult_self Finite_Set.AC_mult.f.commute)  | 
|
662  | 
have 7: "\<And>X3\<Colon>'b\<Colon>ordered_idom. (0\<Colon>'b\<Colon>ordered_idom) \<le> X3 * X3"  | 
|
663  | 
by (metis Ring_and_Field.zero_le_square Finite_Set.AC_mult.f.commute)  | 
|
664  | 
have 8: "(0\<Colon>'b\<Colon>ordered_idom) \<le> (1\<Colon>'b\<Colon>ordered_idom)"  | 
|
665  | 
by (metis 7 Ring_and_Field.mult_cancel_left2)  | 
|
666  | 
have 9: "\<And>X3\<Colon>'b\<Colon>ordered_idom. X3 * X3 = \<bar>X3 * X3\<bar>"  | 
|
667  | 
by (metis Ring_and_Field.abs_mult 6)  | 
|
668  | 
have 10: "\<bar>1\<Colon>'b\<Colon>ordered_idom\<bar> = (1\<Colon>'b\<Colon>ordered_idom)"  | 
|
669  | 
by (metis 9 4)  | 
|
670  | 
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>"  | 
|
671  | 
by (metis Ring_and_Field.abs_mult OrderedGroup.abs_idempotent 5)  | 
|
672  | 
have 12: "\<And>X3\<Colon>'b\<Colon>ordered_idom. \<bar>\<bar>X3\<bar>\<bar> = \<bar>X3\<bar>"  | 
|
673  | 
by (metis 11 10 5)  | 
|
674  | 
have 13: "\<And>(X1\<Colon>'b\<Colon>ordered_idom) X3\<Colon>'b\<Colon>ordered_idom.  | 
|
675  | 
X3 * (1\<Colon>'b\<Colon>ordered_idom) \<le> X1 \<or>  | 
|
676  | 
\<not> \<bar>X3\<bar> \<le> X1 \<or> \<not> (0\<Colon>'b\<Colon>ordered_idom) \<le> (1\<Colon>'b\<Colon>ordered_idom)"  | 
|
677  | 
by (metis OrderedGroup.abs_le_D1 Ring_and_Field.abs_mult_pos 5)  | 
|
678  | 
have 14: "\<And>(X1\<Colon>'b\<Colon>ordered_idom) X3\<Colon>'b\<Colon>ordered_idom.  | 
|
679  | 
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)"  | 
|
680  | 
by (metis 13 5)  | 
|
681  | 
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"  | 
|
682  | 
by (metis 14 8)  | 
|
683  | 
have 16: "\<And>(X1\<Colon>'b\<Colon>ordered_idom) X3\<Colon>'b\<Colon>ordered_idom. X3 \<le> X1 \<or> X1 \<le> \<bar>X3\<bar>"  | 
|
684  | 
by (metis 15 Orderings.linorder_class.less_eq_less.linear)  | 
|
685  | 
have 17: "\<And>X3\<Colon>'b\<Colon>ordered_idom.  | 
|
686  | 
X3 * (g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) ((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a) \<bar>X3\<bar>)  | 
|
687  | 
\<le> (f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x \<bar>X3\<bar>)"  | 
|
688  | 
by (metis 3 16)  | 
|
689  | 
have 18: "(c\<Colon>'b\<Colon>ordered_idom) *  | 
|
690  | 
(g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) ((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a) \<bar>c\<bar>) =  | 
|
691  | 
(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x \<bar>c\<bar>)"  | 
|
692  | 
by (metis 2 17)  | 
|
693  | 
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>"  | 
|
694  | 
by (metis 15 Ring_and_Field.abs_le_mult Ring_and_Field.abs_mult)  | 
|
695  | 
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>"  | 
|
696  | 
by (metis 19 12 12)  | 
|
697  | 
have 21: "\<And>(X1\<Colon>'b\<Colon>ordered_idom) X3\<Colon>'b\<Colon>ordered_idom. X3 * X1 \<le> \<bar>X3\<bar> * \<bar>X1\<bar>"  | 
|
698  | 
by (metis 15 20)  | 
|
699  | 
have 22: "(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom)  | 
|
700  | 
((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a) \<bar>c\<Colon>'b\<Colon>ordered_idom\<bar>)  | 
|
701  | 
\<le> \<bar>c\<bar> * \<bar>(g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x \<bar>c\<bar>)\<bar>"  | 
|
702  | 
by (metis 21 18)  | 
|
703  | 
show 23: "False"  | 
|
704  | 
by (metis 22 1)  | 
|
705  | 
qed  | 
|
706  | 
||
707  | 
||
708  | 
text{*So here is the easier (and more natural) problem using transitivity*}
 | 
|
709  | 
ML{*ResAtp.problem_name := "BigO__bigo_bounded_alt_trans"*}
 | 
|
710  | 
lemma "ALL x. 0 <= f x ==> ALL x. f x <= c * g x ==> f : O(g)"  | 
|
711  | 
apply (auto simp add: bigo_def)  | 
|
712  | 
(*Version 1: one-shot proof*)  | 
|
713  | 
apply (metis Orderings.leD Orderings.leI abs_ge_self abs_le_D1 abs_mult abs_of_nonneg order_le_less xt1(12));  | 
|
714  | 
done  | 
|
715  | 
||
716  | 
text{*So here is the easier (and more natural) problem using transitivity*}
 | 
|
717  | 
ML{*ResAtp.problem_name := "BigO__bigo_bounded_alt_trans"*}
 | 
|
718  | 
lemma "ALL x. 0 <= f x ==> ALL x. f x <= c * g x ==> f : O(g)"  | 
|
719  | 
apply (auto simp add: bigo_def)  | 
|
720  | 
(*Version 2: single-step proof*)  | 
|
721  | 
proof (neg_clausify)  | 
|
722  | 
fix x  | 
|
| 23519 | 723  | 
assume 0: "\<And>A\<Colon>'a\<Colon>type.  | 
724  | 
(f\<Colon>'a\<Colon>type \<Rightarrow> 'b\<Colon>ordered_idom) A  | 
|
725  | 
\<le> (c\<Colon>'b\<Colon>ordered_idom) * (g\<Colon>'a\<Colon>type \<Rightarrow> 'b\<Colon>ordered_idom) A"  | 
|
726  | 
assume 1: "\<And>A\<Colon>'b\<Colon>ordered_idom.  | 
|
727  | 
\<not> (f\<Colon>'a\<Colon>type \<Rightarrow> 'b\<Colon>ordered_idom) ((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a\<Colon>type) A)  | 
|
728  | 
\<le> A * \<bar>(g\<Colon>'a\<Colon>type \<Rightarrow> 'b\<Colon>ordered_idom) (x A)\<bar>"  | 
|
729  | 
have 2: "\<And>X2\<Colon>'a\<Colon>type.  | 
|
730  | 
\<not> (c\<Colon>'b\<Colon>ordered_idom) * (g\<Colon>'a\<Colon>type \<Rightarrow> 'b\<Colon>ordered_idom) X2  | 
|
731  | 
< (f\<Colon>'a\<Colon>type \<Rightarrow> 'b\<Colon>ordered_idom) X2"  | 
|
732  | 
by (metis 0 linorder_not_le)  | 
|
733  | 
have 3: "\<And>X2\<Colon>'b\<Colon>ordered_idom.  | 
|
734  | 
\<not> (f\<Colon>'a\<Colon>type \<Rightarrow> 'b\<Colon>ordered_idom) ((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a\<Colon>type) \<bar>X2\<bar>)  | 
|
735  | 
\<le> \<bar>X2 * (g\<Colon>'a\<Colon>type \<Rightarrow> 'b\<Colon>ordered_idom) (x \<bar>X2\<bar>)\<bar>"  | 
|
736  | 
by (metis abs_mult 1)  | 
|
737  | 
have 4: "\<And>X2\<Colon>'b\<Colon>ordered_idom.  | 
|
738  | 
\<bar>X2 * (g\<Colon>'a\<Colon>type \<Rightarrow> 'b\<Colon>ordered_idom) ((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a\<Colon>type) \<bar>X2\<bar>)\<bar>  | 
|
739  | 
< (f\<Colon>'a\<Colon>type \<Rightarrow> 'b\<Colon>ordered_idom) (x \<bar>X2\<bar>)"  | 
|
740  | 
by (metis 3 linorder_not_less)  | 
|
741  | 
have 5: "\<And>X2\<Colon>'b\<Colon>ordered_idom.  | 
|
742  | 
X2 * (g\<Colon>'a\<Colon>type \<Rightarrow> 'b\<Colon>ordered_idom) ((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a\<Colon>type) \<bar>X2\<bar>)  | 
|
743  | 
< (f\<Colon>'a\<Colon>type \<Rightarrow> 'b\<Colon>ordered_idom) (x \<bar>X2\<bar>)"  | 
|
744  | 
by (metis abs_less_iff 4)  | 
|
745  | 
show "False"  | 
|
746  | 
by (metis 2 5)  | 
|
| 23449 | 747  | 
qed  | 
748  | 
||
749  | 
||
750  | 
lemma bigo_bounded: "ALL x. 0 <= f x ==> ALL x. f x <= g x ==>  | 
|
751  | 
f : O(g)"  | 
|
752  | 
apply (erule bigo_bounded_alt [of f 1 g])  | 
|
753  | 
apply simp  | 
|
754  | 
done  | 
|
755  | 
||
756  | 
ML{*ResAtp.problem_name := "BigO__bigo_bounded2"*}
 | 
|
757  | 
lemma bigo_bounded2: "ALL x. lb x <= f x ==> ALL x. f x <= lb x + g x ==>  | 
|
758  | 
f : lb +o O(g)"  | 
|
759  | 
apply (rule set_minus_imp_plus)  | 
|
760  | 
apply (rule bigo_bounded)  | 
|
761  | 
apply (auto simp add: diff_minus func_minus func_plus)  | 
|
762  | 
prefer 2  | 
|
763  | 
apply (drule_tac x = x in spec)+  | 
|
764  | 
apply arith (*not clear that it's provable otherwise*)  | 
|
765  | 
proof (neg_clausify)  | 
|
766  | 
fix x  | 
|
767  | 
assume 0: "\<And>y. lb y \<le> f y"  | 
|
768  | 
assume 1: "\<not> (0\<Colon>'b) \<le> f x + - lb x"  | 
|
769  | 
have 2: "\<And>X3. (0\<Colon>'b) + X3 = X3"  | 
|
770  | 
by (metis diff_eq_eq right_minus_eq)  | 
|
771  | 
have 3: "\<not> (0\<Colon>'b) \<le> f x - lb x"  | 
|
772  | 
by (metis 1 compare_rls(1))  | 
|
773  | 
have 4: "\<not> (0\<Colon>'b) + lb x \<le> f x"  | 
|
774  | 
by (metis 3 le_diff_eq)  | 
|
775  | 
show "False"  | 
|
776  | 
by (metis 4 2 0)  | 
|
777  | 
qed  | 
|
778  | 
||
779  | 
ML{*ResAtp.problem_name := "BigO__bigo_abs"*}
 | 
|
780  | 
lemma bigo_abs: "(%x. abs(f x)) =o O(f)"  | 
|
781  | 
apply (unfold bigo_def)  | 
|
782  | 
apply auto  | 
|
783  | 
proof (neg_clausify)  | 
|
784  | 
fix x  | 
|
785  | 
assume 0: "!!mes_o43::'b::ordered_idom.  | 
|
786  | 
~ abs ((f::'a::type => 'b::ordered_idom)  | 
|
787  | 
((x::'b::ordered_idom => 'a::type) mes_o43))  | 
|
788  | 
<= mes_o43 * abs (f (x mes_o43))"  | 
|
789  | 
have 1: "!!X3::'b::ordered_idom.  | 
|
790  | 
X3 <= (1::'b::ordered_idom) * X3 |  | 
|
791  | 
~ (1::'b::ordered_idom) <= (1::'b::ordered_idom)"  | 
|
792  | 
by (metis mult_le_cancel_right1 order_refl)  | 
|
793  | 
have 2: "!!X3::'b::ordered_idom. X3 <= (1::'b::ordered_idom) * X3"  | 
|
794  | 
by (metis 1 order_refl)  | 
|
795  | 
show "False"  | 
|
796  | 
by (metis 0 2)  | 
|
797  | 
qed  | 
|
798  | 
||
799  | 
ML{*ResAtp.problem_name := "BigO__bigo_abs2"*}
 | 
|
800  | 
lemma bigo_abs2: "f =o O(%x. abs(f x))"  | 
|
801  | 
apply (unfold bigo_def)  | 
|
802  | 
apply auto  | 
|
803  | 
proof (neg_clausify)  | 
|
804  | 
fix x  | 
|
805  | 
assume 0: "\<And>mes_o4C\<Colon>'b\<Colon>ordered_idom.  | 
|
806  | 
\<not> \<bar>(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) ((x\<Colon>'b\<Colon>ordered_idom \<Rightarrow> 'a) mes_o4C)\<bar>  | 
|
807  | 
\<le> mes_o4C * \<bar>f (x mes_o4C)\<bar>"  | 
|
808  | 
have 1: "\<And>X3\<Colon>'b\<Colon>ordered_idom.  | 
|
809  | 
X3 \<le> (1\<Colon>'b\<Colon>ordered_idom) * X3 \<or>  | 
|
810  | 
\<not> (1\<Colon>'b\<Colon>ordered_idom) \<le> (1\<Colon>'b\<Colon>ordered_idom)"  | 
|
811  | 
by (metis mult_le_cancel_right1 order_refl)  | 
|
812  | 
have 2: "\<And>X3\<Colon>'b\<Colon>ordered_idom. X3 \<le> (1\<Colon>'b\<Colon>ordered_idom) * X3"  | 
|
813  | 
by (metis 1 order_refl)  | 
|
814  | 
show "False"  | 
|
815  | 
by (metis 0 2)  | 
|
816  | 
qed  | 
|
817  | 
||
818  | 
lemma bigo_abs3: "O(f) = O(%x. abs(f x))"  | 
|
819  | 
apply (rule equalityI)  | 
|
820  | 
apply (rule bigo_elt_subset)  | 
|
821  | 
apply (rule bigo_abs2)  | 
|
822  | 
apply (rule bigo_elt_subset)  | 
|
823  | 
apply (rule bigo_abs)  | 
|
824  | 
done  | 
|
825  | 
||
826  | 
lemma bigo_abs4: "f =o g +o O(h) ==>  | 
|
827  | 
(%x. abs (f x)) =o (%x. abs (g x)) +o O(h)"  | 
|
828  | 
apply (drule set_plus_imp_minus)  | 
|
829  | 
apply (rule set_minus_imp_plus)  | 
|
830  | 
apply (subst func_diff)  | 
|
831  | 
proof -  | 
|
832  | 
assume a: "f - g : O(h)"  | 
|
833  | 
have "(%x. abs (f x) - abs (g x)) =o O(%x. abs(abs (f x) - abs (g x)))"  | 
|
834  | 
by (rule bigo_abs2)  | 
|
835  | 
also have "... <= O(%x. abs (f x - g x))"  | 
|
836  | 
apply (rule bigo_elt_subset)  | 
|
837  | 
apply (rule bigo_bounded)  | 
|
838  | 
apply force  | 
|
839  | 
apply (rule allI)  | 
|
840  | 
apply (rule abs_triangle_ineq3)  | 
|
841  | 
done  | 
|
842  | 
also have "... <= O(f - g)"  | 
|
843  | 
apply (rule bigo_elt_subset)  | 
|
844  | 
apply (subst func_diff)  | 
|
845  | 
apply (rule bigo_abs)  | 
|
846  | 
done  | 
|
847  | 
also have "... <= O(h)"  | 
|
| 23464 | 848  | 
using a by (rule bigo_elt_subset)  | 
| 23449 | 849  | 
finally show "(%x. abs (f x) - abs (g x)) : O(h)".  | 
850  | 
qed  | 
|
851  | 
||
852  | 
lemma bigo_abs5: "f =o O(g) ==> (%x. abs(f x)) =o O(g)"  | 
|
853  | 
by (unfold bigo_def, auto)  | 
|
854  | 
||
855  | 
lemma bigo_elt_subset2 [intro]: "f : g +o O(h) ==> O(f) <= O(g) + O(h)"  | 
|
856  | 
proof -  | 
|
857  | 
assume "f : g +o O(h)"  | 
|
858  | 
also have "... <= O(g) + O(h)"  | 
|
859  | 
by (auto del: subsetI)  | 
|
860  | 
also have "... = O(%x. abs(g x)) + O(%x. abs(h x))"  | 
|
861  | 
apply (subst bigo_abs3 [symmetric])+  | 
|
862  | 
apply (rule refl)  | 
|
863  | 
done  | 
|
864  | 
also have "... = O((%x. abs(g x)) + (%x. abs(h x)))"  | 
|
865  | 
by (rule bigo_plus_eq [symmetric], auto)  | 
|
866  | 
finally have "f : ...".  | 
|
867  | 
then have "O(f) <= ..."  | 
|
868  | 
by (elim bigo_elt_subset)  | 
|
869  | 
also have "... = O(%x. abs(g x)) + O(%x. abs(h x))"  | 
|
870  | 
by (rule bigo_plus_eq, auto)  | 
|
871  | 
finally show ?thesis  | 
|
872  | 
by (simp add: bigo_abs3 [symmetric])  | 
|
873  | 
qed  | 
|
874  | 
||
875  | 
ML{*ResAtp.problem_name := "BigO__bigo_mult"*}
 | 
|
876  | 
lemma bigo_mult [intro]: "O(f)*O(g) <= O(f * g)"  | 
|
877  | 
apply (rule subsetI)  | 
|
878  | 
apply (subst bigo_def)  | 
|
879  | 
apply (auto simp del: abs_mult mult_ac  | 
|
880  | 
simp add: bigo_alt_def set_times func_times)  | 
|
881  | 
(*sledgehammer*);  | 
|
882  | 
apply (rule_tac x = "c * ca" in exI)  | 
|
883  | 
apply(rule allI)  | 
|
884  | 
apply(erule_tac x = x in allE)+  | 
|
885  | 
apply(subgoal_tac "c * ca * abs(f x * g x) =  | 
|
886  | 
(c * abs(f x)) * (ca * abs(g x))")  | 
|
887  | 
ML{*ResAtp.problem_name := "BigO__bigo_mult_simpler"*}
 | 
|
888  | 
prefer 2  | 
|
889  | 
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)  | 
|
890  | 
apply(erule ssubst)  | 
|
891  | 
apply (subst abs_mult)  | 
|
892  | 
(*not qute BigO__bigo_mult_simpler_1 (a hard problem!) as abs_mult has  | 
|
893  | 
just been done*)  | 
|
894  | 
proof (neg_clausify)  | 
|
895  | 
fix a c b ca x  | 
|
896  | 
assume 0: "(0\<Colon>'b\<Colon>ordered_idom) < (c\<Colon>'b\<Colon>ordered_idom)"  | 
|
897  | 
assume 1: "\<bar>(a\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x\<Colon>'a)\<bar>  | 
|
898  | 
\<le> (c\<Colon>'b\<Colon>ordered_idom) * \<bar>(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar>"  | 
|
899  | 
assume 2: "\<bar>(b\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x\<Colon>'a)\<bar>  | 
|
900  | 
\<le> (ca\<Colon>'b\<Colon>ordered_idom) * \<bar>(g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar>"  | 
|
901  | 
assume 3: "\<not> \<bar>(a\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x\<Colon>'a)\<bar> *  | 
|
902  | 
\<bar>(b\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar>  | 
|
903  | 
\<le> (c\<Colon>'b\<Colon>ordered_idom) * \<bar>(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar> *  | 
|
904  | 
((ca\<Colon>'b\<Colon>ordered_idom) * \<bar>(g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar>)"  | 
|
905  | 
have 4: "\<bar>c\<Colon>'b\<Colon>ordered_idom\<bar> = c"  | 
|
906  | 
by (metis OrderedGroup.abs_of_pos 0)  | 
|
907  | 
have 5: "\<And>X1\<Colon>'b\<Colon>ordered_idom. (c\<Colon>'b\<Colon>ordered_idom) * \<bar>X1\<bar> = \<bar>c * X1\<bar>"  | 
|
908  | 
by (metis Ring_and_Field.abs_mult 4)  | 
|
909  | 
have 6: "(0\<Colon>'b\<Colon>ordered_idom) = (1\<Colon>'b\<Colon>ordered_idom) \<or>  | 
|
910  | 
(0\<Colon>'b\<Colon>ordered_idom) < (1\<Colon>'b\<Colon>ordered_idom)"  | 
|
911  | 
by (metis OrderedGroup.abs_not_less_zero Ring_and_Field.abs_one Ring_and_Field.linorder_neqE_ordered_idom)  | 
|
912  | 
have 7: "(0\<Colon>'b\<Colon>ordered_idom) < (1\<Colon>'b\<Colon>ordered_idom)"  | 
|
913  | 
by (metis 6 Ring_and_Field.one_neq_zero)  | 
|
914  | 
have 8: "\<bar>1\<Colon>'b\<Colon>ordered_idom\<bar> = (1\<Colon>'b\<Colon>ordered_idom)"  | 
|
915  | 
by (metis OrderedGroup.abs_of_pos 7)  | 
|
916  | 
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>"  | 
|
917  | 
by (metis OrderedGroup.abs_ge_zero 5)  | 
|
918  | 
have 10: "\<And>X1\<Colon>'b\<Colon>ordered_idom. X1 * (1\<Colon>'b\<Colon>ordered_idom) = X1"  | 
|
919  | 
by (metis Ring_and_Field.mult_cancel_right2 Finite_Set.AC_mult.f.commute)  | 
|
920  | 
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>"  | 
|
921  | 
by (metis Ring_and_Field.abs_mult OrderedGroup.abs_idempotent 10)  | 
|
922  | 
have 12: "\<And>X1\<Colon>'b\<Colon>ordered_idom. \<bar>\<bar>X1\<bar>\<bar> = \<bar>X1\<bar>"  | 
|
923  | 
by (metis 11 8 10)  | 
|
924  | 
have 13: "\<And>X1\<Colon>'b\<Colon>ordered_idom. (0\<Colon>'b\<Colon>ordered_idom) \<le> \<bar>X1\<bar>"  | 
|
925  | 
by (metis OrderedGroup.abs_ge_zero 12)  | 
|
926  | 
have 14: "\<not> (0\<Colon>'b\<Colon>ordered_idom)  | 
|
927  | 
\<le> (c\<Colon>'b\<Colon>ordered_idom) * \<bar>(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x\<Colon>'a)\<bar> \<or>  | 
|
928  | 
\<not> (0\<Colon>'b\<Colon>ordered_idom) \<le> \<bar>(b\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar> \<or>  | 
|
929  | 
\<not> \<bar>b x\<bar> \<le> (ca\<Colon>'b\<Colon>ordered_idom) * \<bar>(g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar> \<or>  | 
|
930  | 
\<not> \<bar>(a\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar> \<le> c * \<bar>f x\<bar>"  | 
|
931  | 
by (metis 3 Ring_and_Field.mult_mono)  | 
|
932  | 
have 15: "\<not> (0\<Colon>'b\<Colon>ordered_idom) \<le> \<bar>(b\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x\<Colon>'a)\<bar> \<or>  | 
|
933  | 
\<not> \<bar>b x\<bar> \<le> (ca\<Colon>'b\<Colon>ordered_idom) * \<bar>(g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar> \<or>  | 
|
934  | 
\<not> \<bar>(a\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar>  | 
|
935  | 
\<le> (c\<Colon>'b\<Colon>ordered_idom) * \<bar>(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar>"  | 
|
936  | 
by (metis 14 9)  | 
|
937  | 
have 16: "\<not> \<bar>(b\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x\<Colon>'a)\<bar>  | 
|
938  | 
\<le> (ca\<Colon>'b\<Colon>ordered_idom) * \<bar>(g\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar> \<or>  | 
|
939  | 
\<not> \<bar>(a\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar>  | 
|
940  | 
\<le> (c\<Colon>'b\<Colon>ordered_idom) * \<bar>(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar>"  | 
|
941  | 
by (metis 15 13)  | 
|
942  | 
have 17: "\<not> \<bar>(a\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) (x\<Colon>'a)\<bar>  | 
|
943  | 
\<le> (c\<Colon>'b\<Colon>ordered_idom) * \<bar>(f\<Colon>'a \<Rightarrow> 'b\<Colon>ordered_idom) x\<bar>"  | 
|
944  | 
by (metis 16 2)  | 
|
945  | 
show 18: "False"  | 
|
946  | 
by (metis 17 1)  | 
|
947  | 
qed  | 
|
948  | 
||
949  | 
||
950  | 
ML{*ResAtp.problem_name := "BigO__bigo_mult2"*}
 | 
|
951  | 
lemma bigo_mult2 [intro]: "f *o O(g) <= O(f * g)"  | 
|
952  | 
apply (auto simp add: bigo_def elt_set_times_def func_times abs_mult)  | 
|
953  | 
(*sledgehammer*);  | 
|
954  | 
apply (rule_tac x = c in exI)  | 
|
955  | 
apply clarify  | 
|
956  | 
apply (drule_tac x = x in spec)  | 
|
957  | 
ML{*ResAtp.problem_name := "BigO__bigo_mult2_simpler"*}
 | 
|
958  | 
(*sledgehammer*);  | 
|
959  | 
apply (subgoal_tac "abs(f x) * abs(b x) <= abs(f x) * (c * abs(g x))")  | 
|
960  | 
apply (simp add: mult_ac)  | 
|
961  | 
apply (rule mult_left_mono, assumption)  | 
|
962  | 
apply (rule abs_ge_zero)  | 
|
963  | 
done  | 
|
964  | 
||
965  | 
ML{*ResAtp.problem_name:="BigO__bigo_mult3"*}
 | 
|
966  | 
lemma bigo_mult3: "f : O(h) ==> g : O(j) ==> f * g : O(h * j)"  | 
|
967  | 
by (metis bigo_mult set_times_intro subset_iff)  | 
|
968  | 
||
969  | 
ML{*ResAtp.problem_name:="BigO__bigo_mult4"*}
 | 
|
970  | 
lemma bigo_mult4 [intro]:"f : k +o O(h) ==> g * f : (g * k) +o O(g * h)"  | 
|
971  | 
by (metis bigo_mult2 set_plus_mono_b set_times_intro2 set_times_plus_distrib)  | 
|
972  | 
||
973  | 
||
974  | 
lemma bigo_mult5: "ALL x. f x ~= 0 ==>  | 
|
975  | 
    O(f * g) <= (f::'a => ('b::ordered_field)) *o O(g)"
 | 
|
976  | 
proof -  | 
|
977  | 
assume "ALL x. f x ~= 0"  | 
|
978  | 
show "O(f * g) <= f *o O(g)"  | 
|
979  | 
proof  | 
|
980  | 
fix h  | 
|
981  | 
assume "h : O(f * g)"  | 
|
982  | 
then have "(%x. 1 / (f x)) * h : (%x. 1 / f x) *o O(f * g)"  | 
|
983  | 
by auto  | 
|
984  | 
also have "... <= O((%x. 1 / f x) * (f * g))"  | 
|
985  | 
by (rule bigo_mult2)  | 
|
986  | 
also have "(%x. 1 / f x) * (f * g) = g"  | 
|
987  | 
apply (simp add: func_times)  | 
|
988  | 
apply (rule ext)  | 
|
989  | 
apply (simp add: prems nonzero_divide_eq_eq mult_ac)  | 
|
990  | 
done  | 
|
991  | 
finally have "(%x. (1::'b) / f x) * h : O(g)".  | 
|
992  | 
then have "f * ((%x. (1::'b) / f x) * h) : f *o O(g)"  | 
|
993  | 
by auto  | 
|
994  | 
also have "f * ((%x. (1::'b) / f x) * h) = h"  | 
|
995  | 
apply (simp add: func_times)  | 
|
996  | 
apply (rule ext)  | 
|
997  | 
apply (simp add: prems nonzero_divide_eq_eq mult_ac)  | 
|
998  | 
done  | 
|
999  | 
finally show "h : f *o O(g)".  | 
|
1000  | 
qed  | 
|
1001  | 
qed  | 
|
1002  | 
||
1003  | 
ML{*ResAtp.problem_name := "BigO__bigo_mult6"*}
 | 
|
1004  | 
lemma bigo_mult6: "ALL x. f x ~= 0 ==>  | 
|
1005  | 
    O(f * g) = (f::'a => ('b::ordered_field)) *o O(g)"
 | 
|
1006  | 
by (metis bigo_mult2 bigo_mult5 order_antisym)  | 
|
1007  | 
||
1008  | 
(*proof requires relaxing relevance: 2007-01-25*)  | 
|
1009  | 
ML{*ResAtp.problem_name := "BigO__bigo_mult7"*}
 | 
|
1010  | 
declare bigo_mult6 [simp]  | 
|
1011  | 
lemma bigo_mult7: "ALL x. f x ~= 0 ==>  | 
|
1012  | 
    O(f * g) <= O(f::'a => ('b::ordered_field)) * O(g)"
 | 
|
1013  | 
(*sledgehammer*)  | 
|
1014  | 
apply (subst bigo_mult6)  | 
|
1015  | 
apply assumption  | 
|
1016  | 
apply (rule set_times_mono3)  | 
|
1017  | 
apply (rule bigo_refl)  | 
|
1018  | 
done  | 
|
1019  | 
declare bigo_mult6 [simp del]  | 
|
1020  | 
||
1021  | 
ML{*ResAtp.problem_name := "BigO__bigo_mult8"*}
 | 
|
1022  | 
declare bigo_mult7[intro!]  | 
|
1023  | 
lemma bigo_mult8: "ALL x. f x ~= 0 ==>  | 
|
1024  | 
    O(f * g) = O(f::'a => ('b::ordered_field)) * O(g)"
 | 
|
1025  | 
by (metis bigo_mult bigo_mult7 order_antisym_conv)  | 
|
1026  | 
||
1027  | 
lemma bigo_minus [intro]: "f : O(g) ==> - f : O(g)"  | 
|
1028  | 
by (auto simp add: bigo_def func_minus)  | 
|
1029  | 
||
1030  | 
lemma bigo_minus2: "f : g +o O(h) ==> -f : -g +o O(h)"  | 
|
1031  | 
apply (rule set_minus_imp_plus)  | 
|
1032  | 
apply (drule set_plus_imp_minus)  | 
|
1033  | 
apply (drule bigo_minus)  | 
|
1034  | 
apply (simp add: diff_minus)  | 
|
1035  | 
done  | 
|
1036  | 
||
1037  | 
lemma bigo_minus3: "O(-f) = O(f)"  | 
|
1038  | 
by (auto simp add: bigo_def func_minus abs_minus_cancel)  | 
|
1039  | 
||
1040  | 
lemma bigo_plus_absorb_lemma1: "f : O(g) ==> f +o O(g) <= O(g)"  | 
|
1041  | 
proof -  | 
|
1042  | 
assume a: "f : O(g)"  | 
|
1043  | 
show "f +o O(g) <= O(g)"  | 
|
1044  | 
proof -  | 
|
1045  | 
have "f : O(f)" by auto  | 
|
1046  | 
then have "f +o O(g) <= O(f) + O(g)"  | 
|
1047  | 
by (auto del: subsetI)  | 
|
1048  | 
also have "... <= O(g) + O(g)"  | 
|
1049  | 
proof -  | 
|
1050  | 
from a have "O(f) <= O(g)" by (auto del: subsetI)  | 
|
1051  | 
thus ?thesis by (auto del: subsetI)  | 
|
1052  | 
qed  | 
|
1053  | 
also have "... <= O(g)" by (simp add: bigo_plus_idemp)  | 
|
1054  | 
finally show ?thesis .  | 
|
1055  | 
qed  | 
|
1056  | 
qed  | 
|
1057  | 
||
1058  | 
lemma bigo_plus_absorb_lemma2: "f : O(g) ==> O(g) <= f +o O(g)"  | 
|
1059  | 
proof -  | 
|
1060  | 
assume a: "f : O(g)"  | 
|
1061  | 
show "O(g) <= f +o O(g)"  | 
|
1062  | 
proof -  | 
|
1063  | 
from a have "-f : O(g)" by auto  | 
|
1064  | 
then have "-f +o O(g) <= O(g)" by (elim bigo_plus_absorb_lemma1)  | 
|
1065  | 
then have "f +o (-f +o O(g)) <= f +o O(g)" by auto  | 
|
1066  | 
also have "f +o (-f +o O(g)) = O(g)"  | 
|
1067  | 
by (simp add: set_plus_rearranges)  | 
|
1068  | 
finally show ?thesis .  | 
|
1069  | 
qed  | 
|
1070  | 
qed  | 
|
1071  | 
||
1072  | 
ML{*ResAtp.problem_name:="BigO__bigo_plus_absorb"*}
 | 
|
1073  | 
lemma bigo_plus_absorb [simp]: "f : O(g) ==> f +o O(g) = O(g)"  | 
|
1074  | 
by (metis bigo_plus_absorb_lemma1 bigo_plus_absorb_lemma2 order_eq_iff);  | 
|
1075  | 
||
1076  | 
lemma bigo_plus_absorb2 [intro]: "f : O(g) ==> A <= O(g) ==> f +o A <= O(g)"  | 
|
1077  | 
apply (subgoal_tac "f +o A <= f +o O(g)")  | 
|
1078  | 
apply force+  | 
|
1079  | 
done  | 
|
1080  | 
||
1081  | 
lemma bigo_add_commute_imp: "f : g +o O(h) ==> g : f +o O(h)"  | 
|
1082  | 
apply (subst set_minus_plus [symmetric])  | 
|
1083  | 
apply (subgoal_tac "g - f = - (f - g)")  | 
|
1084  | 
apply (erule ssubst)  | 
|
1085  | 
apply (rule bigo_minus)  | 
|
1086  | 
apply (subst set_minus_plus)  | 
|
1087  | 
apply assumption  | 
|
1088  | 
apply (simp add: diff_minus add_ac)  | 
|
1089  | 
done  | 
|
1090  | 
||
1091  | 
lemma bigo_add_commute: "(f : g +o O(h)) = (g : f +o O(h))"  | 
|
1092  | 
apply (rule iffI)  | 
|
1093  | 
apply (erule bigo_add_commute_imp)+  | 
|
1094  | 
done  | 
|
1095  | 
||
1096  | 
lemma bigo_const1: "(%x. c) : O(%x. 1)"  | 
|
1097  | 
by (auto simp add: bigo_def mult_ac)  | 
|
1098  | 
||
1099  | 
declare bigo_const1 [skolem]  | 
|
1100  | 
||
1101  | 
ML{*ResAtp.problem_name:="BigO__bigo_const2"*}
 | 
|
1102  | 
lemma (*bigo_const2 [intro]:*) "O(%x. c) <= O(%x. 1)"  | 
|
1103  | 
by (metis bigo_const1 bigo_elt_subset);  | 
|
1104  | 
||
1105  | 
lemma bigo_const2 [intro]: "O(%x. c) <= O(%x. 1)";  | 
|
1106  | 
(*??FAILS because the two occurrences of COMBK have different polymorphic types  | 
|
1107  | 
proof (neg_clausify)  | 
|
1108  | 
assume 0: "\<not> O(COMBK (c\<Colon>'b\<Colon>ordered_idom)) \<subseteq> O(COMBK (1\<Colon>'b\<Colon>ordered_idom))"  | 
|
1109  | 
have 1: "COMBK (c\<Colon>'b\<Colon>ordered_idom) \<notin> O(COMBK (1\<Colon>'b\<Colon>ordered_idom))"  | 
|
1110  | 
apply (rule notI)  | 
|
1111  | 
apply (rule 0 [THEN notE])  | 
|
1112  | 
apply (rule bigo_elt_subset)  | 
|
1113  | 
apply assumption;  | 
|
1114  | 
sorry  | 
|
1115  | 
by (metis 0 bigo_elt_subset) loops??  | 
|
1116  | 
show "False"  | 
|
1117  | 
by (metis 1 bigo_const1)  | 
|
1118  | 
qed  | 
|
1119  | 
*)  | 
|
1120  | 
apply (rule bigo_elt_subset)  | 
|
1121  | 
apply (rule bigo_const1)  | 
|
1122  | 
done  | 
|
1123  | 
||
1124  | 
declare bigo_const2 [skolem]  | 
|
1125  | 
||
1126  | 
ML{*ResAtp.problem_name := "BigO__bigo_const3"*}
 | 
|
1127  | 
lemma bigo_const3: "(c::'a::ordered_field) ~= 0 ==> (%x. 1) : O(%x. c)"  | 
|
1128  | 
apply (simp add: bigo_def)  | 
|
1129  | 
proof (neg_clausify)  | 
|
1130  | 
assume 0: "(c\<Colon>'a\<Colon>ordered_field) \<noteq> (0\<Colon>'a\<Colon>ordered_field)"  | 
|
| 23519 | 1131  | 
assume 1: "\<And>A\<Colon>'a\<Colon>ordered_field. \<not> (1\<Colon>'a\<Colon>ordered_field) \<le> A * \<bar>c\<Colon>'a\<Colon>ordered_field\<bar>"  | 
| 23449 | 1132  | 
have 2: "(0\<Colon>'a\<Colon>ordered_field) = \<bar>c\<Colon>'a\<Colon>ordered_field\<bar> \<or>  | 
1133  | 
\<not> (1\<Colon>'a\<Colon>ordered_field) \<le> (1\<Colon>'a\<Colon>ordered_field)"  | 
|
1134  | 
by (metis 1 field_inverse)  | 
|
1135  | 
have 3: "\<bar>c\<Colon>'a\<Colon>ordered_field\<bar> = (0\<Colon>'a\<Colon>ordered_field)"  | 
|
| 23519 | 1136  | 
by (metis linorder_neq_iff linorder_antisym_conv1 2)  | 
| 23449 | 1137  | 
have 4: "(0\<Colon>'a\<Colon>ordered_field) = (c\<Colon>'a\<Colon>ordered_field)"  | 
| 23519 | 1138  | 
by (metis 3 abs_eq_0)  | 
1139  | 
show "False"  | 
|
1140  | 
by (metis 0 4)  | 
|
| 23449 | 1141  | 
qed  | 
1142  | 
||
1143  | 
lemma bigo_const4: "(c::'a::ordered_field) ~= 0 ==> O(%x. 1) <= O(%x. c)"  | 
|
1144  | 
by (rule bigo_elt_subset, rule bigo_const3, assumption)  | 
|
1145  | 
||
1146  | 
lemma bigo_const [simp]: "(c::'a::ordered_field) ~= 0 ==>  | 
|
1147  | 
O(%x. c) = O(%x. 1)"  | 
|
1148  | 
by (rule equalityI, rule bigo_const2, rule bigo_const4, assumption)  | 
|
1149  | 
||
1150  | 
ML{*ResAtp.problem_name := "BigO__bigo_const_mult1"*}
 | 
|
1151  | 
lemma bigo_const_mult1: "(%x. c * f x) : O(f)"  | 
|
1152  | 
apply (simp add: bigo_def abs_mult)  | 
|
1153  | 
proof (neg_clausify)  | 
|
1154  | 
fix x  | 
|
1155  | 
assume 0: "\<And>mes_vAL\<Colon>'b.  | 
|
1156  | 
\<not> \<bar>c\<Colon>'b\<bar> *  | 
|
1157  | 
\<bar>(f\<Colon>'a \<Rightarrow> 'b) ((x\<Colon>'b \<Rightarrow> 'a) mes_vAL)\<bar>  | 
|
1158  | 
\<le> mes_vAL * \<bar>f (x mes_vAL)\<bar>"  | 
|
1159  | 
have 1: "\<And>Y\<Colon>'b. Y \<le> Y"  | 
|
1160  | 
by (metis order_refl)  | 
|
1161  | 
show 2: "False"  | 
|
1162  | 
by (metis 0 1)  | 
|
1163  | 
qed  | 
|
1164  | 
||
1165  | 
lemma bigo_const_mult2: "O(%x. c * f x) <= O(f)"  | 
|
1166  | 
by (rule bigo_elt_subset, rule bigo_const_mult1)  | 
|
1167  | 
||
1168  | 
ML{*ResAtp.problem_name := "BigO__bigo_const_mult3"*}
 | 
|
1169  | 
lemma bigo_const_mult3: "(c::'a::ordered_field) ~= 0 ==> f : O(%x. c * f x)"  | 
|
1170  | 
apply (simp add: bigo_def)  | 
|
1171  | 
(*sledgehammer*);  | 
|
1172  | 
apply (rule_tac x = "abs(inverse c)" in exI)  | 
|
1173  | 
apply (simp only: abs_mult [symmetric] mult_assoc [symmetric])  | 
|
1174  | 
apply (subst left_inverse)  | 
|
1175  | 
apply (auto );  | 
|
1176  | 
done  | 
|
1177  | 
||
1178  | 
lemma bigo_const_mult4: "(c::'a::ordered_field) ~= 0 ==>  | 
|
1179  | 
O(f) <= O(%x. c * f x)"  | 
|
1180  | 
by (rule bigo_elt_subset, rule bigo_const_mult3, assumption)  | 
|
1181  | 
||
1182  | 
lemma bigo_const_mult [simp]: "(c::'a::ordered_field) ~= 0 ==>  | 
|
1183  | 
O(%x. c * f x) = O(f)"  | 
|
1184  | 
by (rule equalityI, rule bigo_const_mult2, erule bigo_const_mult4)  | 
|
1185  | 
||
1186  | 
ML{*ResAtp.problem_name := "BigO__bigo_const_mult5"*}
 | 
|
1187  | 
lemma bigo_const_mult5 [simp]: "(c::'a::ordered_field) ~= 0 ==>  | 
|
1188  | 
(%x. c) *o O(f) = O(f)"  | 
|
1189  | 
apply (auto del: subsetI)  | 
|
1190  | 
apply (rule order_trans)  | 
|
1191  | 
apply (rule bigo_mult2)  | 
|
1192  | 
apply (simp add: func_times)  | 
|
1193  | 
apply (auto intro!: subsetI simp add: bigo_def elt_set_times_def func_times)  | 
|
1194  | 
apply (rule_tac x = "%y. inverse c * x y" in exI)  | 
|
1195  | 
apply (rename_tac g d)  | 
|
1196  | 
apply safe;  | 
|
1197  | 
apply (rule_tac [2] ext)  | 
|
1198  | 
(*sledgehammer*);  | 
|
1199  | 
apply (simp_all del: mult_assoc add: mult_assoc [symmetric] abs_mult)  | 
|
1200  | 
apply (rule_tac x = "abs (inverse c) * d" in exI)  | 
|
1201  | 
apply (rule allI)  | 
|
1202  | 
apply (subst mult_assoc)  | 
|
1203  | 
apply (rule mult_left_mono)  | 
|
1204  | 
apply (erule spec)  | 
|
1205  | 
apply (simp add: );  | 
|
1206  | 
done  | 
|
1207  | 
||
1208  | 
||
1209  | 
ML{*ResAtp.problem_name := "BigO__bigo_const_mult6"*}
 | 
|
1210  | 
lemma bigo_const_mult6 [intro]: "(%x. c) *o O(f) <= O(f)"  | 
|
1211  | 
apply (auto intro!: subsetI  | 
|
1212  | 
simp add: bigo_def elt_set_times_def func_times  | 
|
1213  | 
simp del: abs_mult mult_ac)  | 
|
1214  | 
(*sledgehammer*);  | 
|
1215  | 
apply (rule_tac x = "ca * (abs c)" in exI)  | 
|
1216  | 
apply (rule allI)  | 
|
1217  | 
apply (subgoal_tac "ca * abs(c) * abs(f x) = abs(c) * (ca * abs(f x))")  | 
|
1218  | 
apply (erule ssubst)  | 
|
1219  | 
apply (subst abs_mult)  | 
|
1220  | 
apply (rule mult_left_mono)  | 
|
1221  | 
apply (erule spec)  | 
|
1222  | 
apply simp  | 
|
1223  | 
apply(simp add: mult_ac)  | 
|
1224  | 
done  | 
|
1225  | 
||
1226  | 
lemma bigo_const_mult7 [intro]: "f =o O(g) ==> (%x. c * f x) =o O(g)"  | 
|
1227  | 
proof -  | 
|
1228  | 
assume "f =o O(g)"  | 
|
1229  | 
then have "(%x. c) * f =o (%x. c) *o O(g)"  | 
|
1230  | 
by auto  | 
|
1231  | 
also have "(%x. c) * f = (%x. c * f x)"  | 
|
1232  | 
by (simp add: func_times)  | 
|
1233  | 
also have "(%x. c) *o O(g) <= O(g)"  | 
|
1234  | 
by (auto del: subsetI)  | 
|
1235  | 
finally show ?thesis .  | 
|
1236  | 
qed  | 
|
1237  | 
||
1238  | 
lemma bigo_compose1: "f =o O(g) ==> (%x. f(k x)) =o O(%x. g(k x))"  | 
|
1239  | 
by (unfold bigo_def, auto)  | 
|
1240  | 
||
1241  | 
lemma bigo_compose2: "f =o g +o O(h) ==> (%x. f(k x)) =o (%x. g(k x)) +o  | 
|
1242  | 
O(%x. h(k x))"  | 
|
1243  | 
apply (simp only: set_minus_plus [symmetric] diff_minus func_minus  | 
|
1244  | 
func_plus)  | 
|
1245  | 
apply (erule bigo_compose1)  | 
|
1246  | 
done  | 
|
1247  | 
||
1248  | 
subsection {* Setsum *}
 | 
|
1249  | 
||
1250  | 
lemma bigo_setsum_main: "ALL x. ALL y : A x. 0 <= h x y ==>  | 
|
1251  | 
EX c. ALL x. ALL y : A x. abs(f x y) <= c * (h x y) ==>  | 
|
1252  | 
(%x. SUM y : A x. f x y) =o O(%x. SUM y : A x. h x y)"  | 
|
1253  | 
apply (auto simp add: bigo_def)  | 
|
1254  | 
apply (rule_tac x = "abs c" in exI)  | 
|
1255  | 
apply (subst abs_of_nonneg) back back  | 
|
1256  | 
apply (rule setsum_nonneg)  | 
|
1257  | 
apply force  | 
|
1258  | 
apply (subst setsum_right_distrib)  | 
|
1259  | 
apply (rule allI)  | 
|
1260  | 
apply (rule order_trans)  | 
|
1261  | 
apply (rule setsum_abs)  | 
|
1262  | 
apply (rule setsum_mono)  | 
|
1263  | 
apply (blast intro: order_trans mult_right_mono abs_ge_self)  | 
|
1264  | 
done  | 
|
1265  | 
||
1266  | 
ML{*ResAtp.problem_name := "BigO__bigo_setsum1"*}
 | 
|
1267  | 
lemma bigo_setsum1: "ALL x y. 0 <= h x y ==>  | 
|
1268  | 
EX c. ALL x y. abs(f x y) <= c * (h x y) ==>  | 
|
1269  | 
(%x. SUM y : A x. f x y) =o O(%x. SUM y : A x. h x y)"  | 
|
1270  | 
apply (rule bigo_setsum_main)  | 
|
1271  | 
(*sledgehammer*);  | 
|
1272  | 
apply force  | 
|
1273  | 
apply clarsimp  | 
|
1274  | 
apply (rule_tac x = c in exI)  | 
|
1275  | 
apply force  | 
|
1276  | 
done  | 
|
1277  | 
||
1278  | 
lemma bigo_setsum2: "ALL y. 0 <= h y ==>  | 
|
1279  | 
EX c. ALL y. abs(f y) <= c * (h y) ==>  | 
|
1280  | 
(%x. SUM y : A x. f y) =o O(%x. SUM y : A x. h y)"  | 
|
1281  | 
by (rule bigo_setsum1, auto)  | 
|
1282  | 
||
1283  | 
ML{*ResAtp.problem_name := "BigO__bigo_setsum3"*}
 | 
|
1284  | 
lemma bigo_setsum3: "f =o O(h) ==>  | 
|
1285  | 
(%x. SUM y : A x. (l x y) * f(k x y)) =o  | 
|
1286  | 
O(%x. SUM y : A x. abs(l x y * h(k x y)))"  | 
|
1287  | 
apply (rule bigo_setsum1)  | 
|
1288  | 
apply (rule allI)+  | 
|
1289  | 
apply (rule abs_ge_zero)  | 
|
1290  | 
apply (unfold bigo_def)  | 
|
1291  | 
apply (auto simp add: abs_mult);  | 
|
1292  | 
(*sledgehammer*);  | 
|
1293  | 
apply (rule_tac x = c in exI)  | 
|
1294  | 
apply (rule allI)+  | 
|
1295  | 
apply (subst mult_left_commute)  | 
|
1296  | 
apply (rule mult_left_mono)  | 
|
1297  | 
apply (erule spec)  | 
|
1298  | 
apply (rule abs_ge_zero)  | 
|
1299  | 
done  | 
|
1300  | 
||
1301  | 
lemma bigo_setsum4: "f =o g +o O(h) ==>  | 
|
1302  | 
(%x. SUM y : A x. l x y * f(k x y)) =o  | 
|
1303  | 
(%x. SUM y : A x. l x y * g(k x y)) +o  | 
|
1304  | 
O(%x. SUM y : A x. abs(l x y * h(k x y)))"  | 
|
1305  | 
apply (rule set_minus_imp_plus)  | 
|
1306  | 
apply (subst func_diff)  | 
|
1307  | 
apply (subst setsum_subtractf [symmetric])  | 
|
1308  | 
apply (subst right_diff_distrib [symmetric])  | 
|
1309  | 
apply (rule bigo_setsum3)  | 
|
1310  | 
apply (subst func_diff [symmetric])  | 
|
1311  | 
apply (erule set_plus_imp_minus)  | 
|
1312  | 
done  | 
|
1313  | 
||
1314  | 
ML{*ResAtp.problem_name := "BigO__bigo_setsum5"*}
 | 
|
1315  | 
lemma bigo_setsum5: "f =o O(h) ==> ALL x y. 0 <= l x y ==>  | 
|
1316  | 
ALL x. 0 <= h x ==>  | 
|
1317  | 
(%x. SUM y : A x. (l x y) * f(k x y)) =o  | 
|
1318  | 
O(%x. SUM y : A x. (l x y) * h(k x y))"  | 
|
1319  | 
apply (subgoal_tac "(%x. SUM y : A x. (l x y) * h(k x y)) =  | 
|
1320  | 
(%x. SUM y : A x. abs((l x y) * h(k x y)))")  | 
|
1321  | 
apply (erule ssubst)  | 
|
1322  | 
apply (erule bigo_setsum3)  | 
|
1323  | 
apply (rule ext)  | 
|
1324  | 
apply (rule setsum_cong2)  | 
|
1325  | 
apply (thin_tac "f \<in> O(h)")  | 
|
1326  | 
(*sledgehammer*);  | 
|
1327  | 
apply (subst abs_of_nonneg)  | 
|
1328  | 
apply (rule mult_nonneg_nonneg)  | 
|
1329  | 
apply auto  | 
|
1330  | 
done  | 
|
1331  | 
||
1332  | 
lemma bigo_setsum6: "f =o g +o O(h) ==> ALL x y. 0 <= l x y ==>  | 
|
1333  | 
ALL x. 0 <= h x ==>  | 
|
1334  | 
(%x. SUM y : A x. (l x y) * f(k x y)) =o  | 
|
1335  | 
(%x. SUM y : A x. (l x y) * g(k x y)) +o  | 
|
1336  | 
O(%x. SUM y : A x. (l x y) * h(k x y))"  | 
|
1337  | 
apply (rule set_minus_imp_plus)  | 
|
1338  | 
apply (subst func_diff)  | 
|
1339  | 
apply (subst setsum_subtractf [symmetric])  | 
|
1340  | 
apply (subst right_diff_distrib [symmetric])  | 
|
1341  | 
apply (rule bigo_setsum5)  | 
|
1342  | 
apply (subst func_diff [symmetric])  | 
|
1343  | 
apply (drule set_plus_imp_minus)  | 
|
1344  | 
apply auto  | 
|
1345  | 
done  | 
|
1346  | 
||
1347  | 
subsection {* Misc useful stuff *}
 | 
|
1348  | 
||
1349  | 
lemma bigo_useful_intro: "A <= O(f) ==> B <= O(f) ==>  | 
|
1350  | 
A + B <= O(f)"  | 
|
1351  | 
apply (subst bigo_plus_idemp [symmetric])  | 
|
1352  | 
apply (rule set_plus_mono2)  | 
|
1353  | 
apply assumption+  | 
|
1354  | 
done  | 
|
1355  | 
||
1356  | 
lemma bigo_useful_add: "f =o O(h) ==> g =o O(h) ==> f + g =o O(h)"  | 
|
1357  | 
apply (subst bigo_plus_idemp [symmetric])  | 
|
1358  | 
apply (rule set_plus_intro)  | 
|
1359  | 
apply assumption+  | 
|
1360  | 
done  | 
|
1361  | 
||
1362  | 
lemma bigo_useful_const_mult: "(c::'a::ordered_field) ~= 0 ==>  | 
|
1363  | 
(%x. c) * f =o O(h) ==> f =o O(h)"  | 
|
1364  | 
apply (rule subsetD)  | 
|
1365  | 
apply (subgoal_tac "(%x. 1 / c) *o O(h) <= O(h)")  | 
|
1366  | 
apply assumption  | 
|
1367  | 
apply (rule bigo_const_mult6)  | 
|
1368  | 
apply (subgoal_tac "f = (%x. 1 / c) * ((%x. c) * f)")  | 
|
1369  | 
apply (erule ssubst)  | 
|
1370  | 
apply (erule set_times_intro2)  | 
|
1371  | 
apply (simp add: func_times)  | 
|
1372  | 
done  | 
|
1373  | 
||
1374  | 
ML{*ResAtp.problem_name := "BigO__bigo_fix"*}
 | 
|
1375  | 
lemma bigo_fix: "(%x. f ((x::nat) + 1)) =o O(%x. h(x + 1)) ==> f 0 = 0 ==>  | 
|
1376  | 
f =o O(h)"  | 
|
1377  | 
apply (simp add: bigo_alt_def)  | 
|
1378  | 
(*sledgehammer*);  | 
|
1379  | 
apply clarify  | 
|
1380  | 
apply (rule_tac x = c in exI)  | 
|
1381  | 
apply safe  | 
|
1382  | 
apply (case_tac "x = 0")  | 
|
| 23816 | 1383  | 
apply (metis OrderedGroup.abs_ge_zero OrderedGroup.abs_zero order_less_le Ring_and_Field.split_mult_pos_le)  | 
| 23449 | 1384  | 
apply (subgoal_tac "x = Suc (x - 1)")  | 
| 23816 | 1385  | 
apply metis  | 
| 23449 | 1386  | 
apply simp  | 
1387  | 
done  | 
|
1388  | 
||
1389  | 
||
1390  | 
lemma bigo_fix2:  | 
|
1391  | 
"(%x. f ((x::nat) + 1)) =o (%x. g(x + 1)) +o O(%x. h(x + 1)) ==>  | 
|
1392  | 
f 0 = g 0 ==> f =o g +o O(h)"  | 
|
1393  | 
apply (rule set_minus_imp_plus)  | 
|
1394  | 
apply (rule bigo_fix)  | 
|
1395  | 
apply (subst func_diff)  | 
|
1396  | 
apply (subst func_diff [symmetric])  | 
|
1397  | 
apply (rule set_plus_imp_minus)  | 
|
1398  | 
apply simp  | 
|
1399  | 
apply (simp add: func_diff)  | 
|
1400  | 
done  | 
|
1401  | 
||
1402  | 
subsection {* Less than or equal to *}
 | 
|
1403  | 
||
1404  | 
constdefs  | 
|
1405  | 
  lesso :: "('a => 'b::ordered_idom) => ('a => 'b) => ('a => 'b)"
 | 
|
1406  | 
(infixl "<o" 70)  | 
|
1407  | 
"f <o g == (%x. max (f x - g x) 0)"  | 
|
1408  | 
||
1409  | 
lemma bigo_lesseq1: "f =o O(h) ==> ALL x. abs (g x) <= abs (f x) ==>  | 
|
1410  | 
g =o O(h)"  | 
|
1411  | 
apply (unfold bigo_def)  | 
|
1412  | 
apply clarsimp  | 
|
1413  | 
apply (blast intro: order_trans)  | 
|
1414  | 
done  | 
|
1415  | 
||
1416  | 
lemma bigo_lesseq2: "f =o O(h) ==> ALL x. abs (g x) <= f x ==>  | 
|
1417  | 
g =o O(h)"  | 
|
1418  | 
apply (erule bigo_lesseq1)  | 
|
1419  | 
apply (blast intro: abs_ge_self order_trans)  | 
|
1420  | 
done  | 
|
1421  | 
||
1422  | 
lemma bigo_lesseq3: "f =o O(h) ==> ALL x. 0 <= g x ==> ALL x. g x <= f x ==>  | 
|
1423  | 
g =o O(h)"  | 
|
1424  | 
apply (erule bigo_lesseq2)  | 
|
1425  | 
apply (rule allI)  | 
|
1426  | 
apply (subst abs_of_nonneg)  | 
|
1427  | 
apply (erule spec)+  | 
|
1428  | 
done  | 
|
1429  | 
||
1430  | 
lemma bigo_lesseq4: "f =o O(h) ==>  | 
|
1431  | 
ALL x. 0 <= g x ==> ALL x. g x <= abs (f x) ==>  | 
|
1432  | 
g =o O(h)"  | 
|
1433  | 
apply (erule bigo_lesseq1)  | 
|
1434  | 
apply (rule allI)  | 
|
1435  | 
apply (subst abs_of_nonneg)  | 
|
1436  | 
apply (erule spec)+  | 
|
1437  | 
done  | 
|
1438  | 
||
1439  | 
ML{*ResAtp.problem_name:="BigO__bigo_lesso1"*}
 | 
|
1440  | 
lemma bigo_lesso1: "ALL x. f x <= g x ==> f <o g =o O(h)"  | 
|
1441  | 
apply (unfold lesso_def)  | 
|
1442  | 
apply (subgoal_tac "(%x. max (f x - g x) 0) = 0")  | 
|
1443  | 
(*  | 
|
1444  | 
?? abstractions don't work: abstraction function gets the wrong type?  | 
|
1445  | 
proof (neg_clausify)  | 
|
1446  | 
assume 0: "llabs_subgoal_1 f g = 0"  | 
|
1447  | 
assume 1: "llabs_subgoal_1 f g \<notin> O(h)"  | 
|
1448  | 
show "False"  | 
|
1449  | 
by (metis 1 0 bigo_zero)  | 
|
1450  | 
*)  | 
|
1451  | 
apply (erule ssubst)  | 
|
1452  | 
apply (rule bigo_zero)  | 
|
1453  | 
apply (unfold func_zero)  | 
|
1454  | 
apply (rule ext)  | 
|
1455  | 
apply (simp split: split_max)  | 
|
1456  | 
done  | 
|
1457  | 
||
1458  | 
||
1459  | 
ML{*ResAtp.problem_name := "BigO__bigo_lesso2"*}
 | 
|
1460  | 
lemma bigo_lesso2: "f =o g +o O(h) ==>  | 
|
1461  | 
ALL x. 0 <= k x ==> ALL x. k x <= f x ==>  | 
|
1462  | 
k <o g =o O(h)"  | 
|
1463  | 
apply (unfold lesso_def)  | 
|
1464  | 
apply (rule bigo_lesseq4)  | 
|
1465  | 
apply (erule set_plus_imp_minus)  | 
|
1466  | 
apply (rule allI)  | 
|
1467  | 
apply (rule le_maxI2)  | 
|
1468  | 
apply (rule allI)  | 
|
1469  | 
apply (subst func_diff)  | 
|
1470  | 
apply (erule thin_rl)  | 
|
1471  | 
(*sledgehammer*);  | 
|
1472  | 
apply (case_tac "0 <= k x - g x")  | 
|
| 24545 | 1473  | 
prefer 2 (*re-order subgoals because I don't know what to put after a structured proof*)  | 
1474  | 
apply (metis abs_ge_zero abs_minus_commute linorder_linear min_max.less_eq_less_sup.sup_absorb1 min_max.less_eq_less_sup.sup_commute)  | 
|
1475  | 
proof (neg_clausify)  | 
|
1476  | 
fix x  | 
|
1477  | 
assume 0: "\<And>A. k A \<le> f A"  | 
|
1478  | 
have 1: "\<And>(X1\<Colon>'b\<Colon>ordered_idom) X2. \<not> max X1 X2 < X1"  | 
|
1479  | 
by (metis linorder_not_less le_maxI1) (*sort inserted by hand*)  | 
|
1480  | 
assume 2: "(0\<Colon>'b) \<le> k x - g x"  | 
|
1481  | 
have 3: "\<not> k x - g x < (0\<Colon>'b)"  | 
|
1482  | 
by (metis 2 linorder_not_less)  | 
|
1483  | 
have 4: "\<And>X1 X2. min X1 (k X2) \<le> f X2"  | 
|
1484  | 
by (metis min_max.less_eq_less_inf.inf_le2 min_max.less_eq_less_inf.le_inf_iff min_max.less_eq_less_inf.le_iff_inf 0)  | 
|
1485  | 
have 5: "\<bar>g x - f x\<bar> = f x - g x"  | 
|
1486  | 
by (metis abs_minus_commute combine_common_factor mult_zero_right minus_add_cancel minus_zero abs_if diff_less_eq min_max.less_eq_less_inf.inf_commute 4 linorder_not_le min_max.less_eq_less_inf.le_iff_inf 3 diff_less_0_iff_less linorder_not_less)  | 
|
1487  | 
have 6: "max (0\<Colon>'b) (k x - g x) = k x - g x"  | 
|
1488  | 
by (metis min_max.less_eq_less_sup.le_iff_sup 2)  | 
|
1489  | 
assume 7: "\<not> max (k x - g x) (0\<Colon>'b) \<le> \<bar>f x - g x\<bar>"  | 
|
1490  | 
have 8: "\<not> k x - g x \<le> f x - g x"  | 
|
1491  | 
by (metis 5 abs_minus_commute 7 min_max.less_eq_less_sup.sup_commute 6)  | 
|
1492  | 
show "False"  | 
|
1493  | 
by (metis min_max.less_eq_less_sup.sup_commute min_max.less_eq_less_inf.inf_commute min_max.less_eq_less_inf_sup.sup_inf_absorb min_max.less_eq_less_inf.le_iff_inf 0 max_diff_distrib_left 1 linorder_not_le 8)  | 
|
1494  | 
qed  | 
|
| 23449 | 1495  | 
|
1496  | 
ML{*ResAtp.problem_name := "BigO__bigo_lesso3"*}
 | 
|
1497  | 
lemma bigo_lesso3: "f =o g +o O(h) ==>  | 
|
1498  | 
ALL x. 0 <= k x ==> ALL x. g x <= k x ==>  | 
|
1499  | 
f <o k =o O(h)"  | 
|
1500  | 
apply (unfold lesso_def)  | 
|
1501  | 
apply (rule bigo_lesseq4)  | 
|
1502  | 
apply (erule set_plus_imp_minus)  | 
|
1503  | 
apply (rule allI)  | 
|
1504  | 
apply (rule le_maxI2)  | 
|
1505  | 
apply (rule allI)  | 
|
1506  | 
apply (subst func_diff)  | 
|
1507  | 
apply (erule thin_rl)  | 
|
1508  | 
(*sledgehammer*);  | 
|
1509  | 
apply (case_tac "0 <= f x - k x")  | 
|
1510  | 
apply (simp del: compare_rls diff_minus);  | 
|
1511  | 
apply (subst abs_of_nonneg)  | 
|
1512  | 
apply (drule_tac x = x in spec) back  | 
|
1513  | 
ML{*ResAtp.problem_name := "BigO__bigo_lesso3_simpler"*}
 | 
|
| 24545 | 1514  | 
apply (metis diff_less_0_iff_less linorder_not_le not_leE uminus_add_conv_diff xt1(12) xt1(6))  | 
1515  | 
apply (metis add_minus_cancel diff_le_eq le_diff_eq uminus_add_conv_diff)  | 
|
1516  | 
apply (metis abs_ge_zero linorder_linear min_max.less_eq_less_sup.sup_absorb1 min_max.less_eq_less_sup.sup_commute)  | 
|
| 23449 | 1517  | 
done  | 
1518  | 
||
1519  | 
lemma bigo_lesso4: "f <o g =o O(k::'a=>'b::ordered_field) ==>  | 
|
1520  | 
g =o h +o O(k) ==> f <o h =o O(k)"  | 
|
1521  | 
apply (unfold lesso_def)  | 
|
1522  | 
apply (drule set_plus_imp_minus)  | 
|
1523  | 
apply (drule bigo_abs5) back  | 
|
1524  | 
apply (simp add: func_diff)  | 
|
1525  | 
apply (drule bigo_useful_add)  | 
|
1526  | 
apply assumption  | 
|
1527  | 
apply (erule bigo_lesseq2) back  | 
|
1528  | 
apply (rule allI)  | 
|
1529  | 
apply (auto simp add: func_plus func_diff compare_rls  | 
|
1530  | 
split: split_max abs_split)  | 
|
1531  | 
done  | 
|
1532  | 
||
1533  | 
ML{*ResAtp.problem_name := "BigO__bigo_lesso5"*}
 | 
|
1534  | 
lemma bigo_lesso5: "f <o g =o O(h) ==>  | 
|
1535  | 
EX C. ALL x. f x <= g x + C * abs(h x)"  | 
|
1536  | 
apply (simp only: lesso_def bigo_alt_def)  | 
|
1537  | 
apply clarsimp  | 
|
| 24545 | 1538  | 
apply (metis abs_if abs_mult add_commute diff_le_eq less_not_permute mult_commute)  | 
| 23449 | 1539  | 
done  | 
1540  | 
||
1541  | 
end  |