src/HOL/MetisExamples/BigO.thy
 author wenzelm Wed Sep 17 21:27:14 2008 +0200 (2008-09-17) changeset 28263 69eaa97e7e96 parent 26814 b3e8d5ec721d child 28486 873726bdfd47 permissions -rw-r--r--
moved global ML bindings to global place;
 paulson@23449 ` 1` ```(* Title: HOL/MetisExamples/BigO.thy ``` paulson@23449 ` 2` ``` ID: \$Id\$ ``` paulson@23449 ` 3` ``` Author: Lawrence C Paulson, Cambridge University Computer Laboratory ``` paulson@23449 ` 4` paulson@23449 ` 5` ```Testing the metis method ``` paulson@23449 ` 6` ```*) ``` paulson@23449 ` 7` paulson@23449 ` 8` ```header {* Big O notation *} ``` paulson@23449 ` 9` paulson@23449 ` 10` ```theory BigO ``` chaieb@26165 ` 11` ```imports Dense_Linear_Order Main SetsAndFunctions ``` paulson@23449 ` 12` ```begin ``` paulson@23449 ` 13` paulson@23449 ` 14` ```subsection {* Definitions *} ``` paulson@23449 ` 15` paulson@23449 ` 16` ```constdefs ``` paulson@23449 ` 17` paulson@23449 ` 18` ``` bigo :: "('a => 'b::ordered_idom) => ('a => 'b) set" ("(1O'(_'))") ``` paulson@23449 ` 19` ``` "O(f::('a => 'b)) == {h. EX c. ALL x. abs (h x) <= c * abs (f x)}" ``` paulson@23449 ` 20` wenzelm@26483 ` 21` ```ML_command{*ResAtp.problem_name := "BigO__bigo_pos_const"*} ``` paulson@23449 ` 22` ```lemma bigo_pos_const: "(EX (c::'a::ordered_idom). ``` paulson@23449 ` 23` ``` ALL x. (abs (h x)) <= (c * (abs (f x)))) ``` paulson@23449 ` 24` ``` = (EX c. 0 < c & (ALL x. (abs(h x)) <= (c * (abs (f x)))))" ``` paulson@23449 ` 25` ``` apply auto ``` paulson@23449 ` 26` ``` apply (case_tac "c = 0", simp) ``` paulson@23449 ` 27` ``` apply (rule_tac x = "1" in exI, simp) ``` haftmann@25304 ` 28` ``` apply (rule_tac x = "abs c" in exI, auto) ``` haftmann@25304 ` 29` ``` apply (metis abs_ge_minus_self abs_ge_zero abs_minus_cancel abs_of_nonneg equation_minus_iff Orderings.xt1(6) abs_mult) ``` paulson@23449 ` 30` ``` done ``` paulson@23449 ` 31` paulson@23449 ` 32` ```(*** Now various verions with an increasing modulus ***) ``` paulson@23449 ` 33` paulson@26333 ` 34` ```declare [[sledgehammer_modulus = 1]] ``` paulson@23449 ` 35` wenzelm@26312 ` 36` ```lemma (*bigo_pos_const:*) "(EX (c::'a::ordered_idom). ``` paulson@23449 ` 37` ``` ALL x. (abs (h x)) <= (c * (abs (f x)))) ``` paulson@23449 ` 38` ``` = (EX c. 0 < c & (ALL x. (abs(h x)) <= (c * (abs (f x)))))" ``` paulson@23449 ` 39` ``` apply auto ``` paulson@23449 ` 40` ``` apply (case_tac "c = 0", simp) ``` paulson@23449 ` 41` ``` apply (rule_tac x = "1" in exI, simp) ``` paulson@23449 ` 42` ``` apply (rule_tac x = "abs c" in exI, auto) ``` paulson@23449 ` 43` ```proof (neg_clausify) ``` paulson@23449 ` 44` ```fix c x ``` paulson@24937 ` 45` ```have 0: "\(X1\'a\ordered_idom) X2\'a\ordered_idom. \X1 * X2\ = \X2 * X1\" ``` paulson@24937 ` 46` ``` by (metis abs_mult mult_commute) ``` paulson@24937 ` 47` ```have 1: "\(X1\'a\ordered_idom) X2\'a\ordered_idom. ``` paulson@24937 ` 48` ``` X1 \ (0\'a\ordered_idom) \ \X2\ * X1 = \X2 * X1\" ``` paulson@24937 ` 49` ``` by (metis abs_mult_pos linorder_linear) ``` paulson@24937 ` 50` ```have 2: "\(X1\'a\ordered_idom) X2\'a\ordered_idom. ``` paulson@24937 ` 51` ``` \ (0\'a\ordered_idom) < X1 * X2 \ ``` paulson@24937 ` 52` ``` \ (0\'a\ordered_idom) \ X2 \ \ X1 \ (0\'a\ordered_idom)" ``` paulson@24937 ` 53` ``` by (metis linorder_not_less mult_nonneg_nonpos2) ``` paulson@24937 ` 54` ```assume 3: "\x\'b\type. ``` paulson@24937 ` 55` ``` \(h\'b\type \ 'a\ordered_idom) x\ ``` paulson@24937 ` 56` ``` \ (c\'a\ordered_idom) * \(f\'b\type \ 'a\ordered_idom) x\" ``` paulson@24937 ` 57` ```assume 4: "\ \(h\'b\type \ 'a\ordered_idom) (x\'b\type)\ ``` paulson@24937 ` 58` ``` \ \c\'a\ordered_idom\ * \(f\'b\type \ 'a\ordered_idom) x\" ``` paulson@24937 ` 59` ```have 5: "\ \(h\'b\type \ 'a\ordered_idom) (x\'b\type)\ ``` paulson@24937 ` 60` ``` \ \(c\'a\ordered_idom) * (f\'b\type \ 'a\ordered_idom) x\" ``` paulson@24937 ` 61` ``` by (metis 4 abs_mult) ``` paulson@24937 ` 62` ```have 6: "\(X1\'a\ordered_idom) X2\'a\ordered_idom. ``` paulson@24937 ` 63` ``` \ X1 \ (0\'a\ordered_idom) \ X1 \ \X2\" ``` paulson@24937 ` 64` ``` by (metis abs_ge_zero xt1(6)) ``` paulson@24937 ` 65` ```have 7: "\(X1\'a\ordered_idom) X2\'a\ordered_idom. ``` paulson@24937 ` 66` ``` X1 \ \X2\ \ (0\'a\ordered_idom) < X1" ``` paulson@24937 ` 67` ``` by (metis not_leE 6) ``` paulson@24937 ` 68` ```have 8: "(0\'a\ordered_idom) < \(h\'b\type \ 'a\ordered_idom) (x\'b\type)\" ``` paulson@24937 ` 69` ``` by (metis 5 7) ``` paulson@24937 ` 70` ```have 9: "\X1\'a\ordered_idom. ``` paulson@24937 ` 71` ``` \ \(h\'b\type \ 'a\ordered_idom) (x\'b\type)\ \ X1 \ ``` paulson@24937 ` 72` ``` (0\'a\ordered_idom) < X1" ``` paulson@24937 ` 73` ``` by (metis 8 order_less_le_trans) ``` paulson@24937 ` 74` ```have 10: "(0\'a\ordered_idom) ``` paulson@24937 ` 75` ```< (c\'a\ordered_idom) * \(f\'b\type \ 'a\ordered_idom) (x\'b\type)\" ``` paulson@24937 ` 76` ``` by (metis 3 9) ``` paulson@24937 ` 77` ```have 11: "\ (c\'a\ordered_idom) \ (0\'a\ordered_idom)" ``` paulson@24937 ` 78` ``` by (metis abs_ge_zero 2 10) ``` paulson@24937 ` 79` ```have 12: "\X1\'a\ordered_idom. (c\'a\ordered_idom) * \X1\ = \X1 * c\" ``` paulson@24937 ` 80` ``` by (metis mult_commute 1 11) ``` paulson@24937 ` 81` ```have 13: "\X1\'b\type. ``` paulson@24937 ` 82` ``` - (h\'b\type \ 'a\ordered_idom) X1 ``` paulson@24937 ` 83` ``` \ (c\'a\ordered_idom) * \(f\'b\type \ 'a\ordered_idom) X1\" ``` paulson@24937 ` 84` ``` by (metis 3 abs_le_D2) ``` paulson@24937 ` 85` ```have 14: "\X1\'b\type. ``` paulson@24937 ` 86` ``` - (h\'b\type \ 'a\ordered_idom) X1 ``` paulson@24937 ` 87` ``` \ \(c\'a\ordered_idom) * (f\'b\type \ 'a\ordered_idom) X1\" ``` paulson@24937 ` 88` ``` by (metis 0 12 13) ``` paulson@24937 ` 89` ```have 15: "\(X1\'a\ordered_idom) X2\'a\ordered_idom. \X1 * \X2\\ = \X1 * X2\" ``` paulson@24937 ` 90` ``` by (metis abs_mult abs_mult_pos abs_ge_zero) ``` paulson@24937 ` 91` ```have 16: "\(X1\'a\ordered_idom) X2\'a\ordered_idom. X1 \ \X2\ \ \ X1 \ X2" ``` paulson@24937 ` 92` ``` by (metis xt1(6) abs_ge_self) ``` paulson@24937 ` 93` ```have 17: "\(X1\'a\ordered_idom) X2\'a\ordered_idom. \ \X1\ \ X2 \ X1 \ \X2\" ``` paulson@24937 ` 94` ``` by (metis 16 abs_le_D1) ``` paulson@24937 ` 95` ```have 18: "\X1\'b\type. ``` paulson@24937 ` 96` ``` (h\'b\type \ 'a\ordered_idom) X1 ``` paulson@24937 ` 97` ``` \ \(c\'a\ordered_idom) * (f\'b\type \ 'a\ordered_idom) X1\" ``` paulson@24937 ` 98` ``` by (metis 17 3 15) ``` paulson@23449 ` 99` ```show "False" ``` paulson@24937 ` 100` ``` by (metis abs_le_iff 5 18 14) ``` paulson@23449 ` 101` ```qed ``` paulson@23449 ` 102` paulson@26333 ` 103` ```declare [[sledgehammer_modulus = 2]] ``` paulson@25710 ` 104` paulson@23449 ` 105` ```lemma (*bigo_pos_const:*) "(EX (c::'a::ordered_idom). ``` paulson@23449 ` 106` ``` ALL x. (abs (h x)) <= (c * (abs (f x)))) ``` paulson@23449 ` 107` ``` = (EX c. 0 < c & (ALL x. (abs(h x)) <= (c * (abs (f x)))))" ``` paulson@23449 ` 108` ``` apply auto ``` paulson@23449 ` 109` ``` apply (case_tac "c = 0", simp) ``` paulson@23449 ` 110` ``` apply (rule_tac x = "1" in exI, simp) ``` paulson@23449 ` 111` ``` apply (rule_tac x = "abs c" in exI, auto); ``` paulson@23449 ` 112` ```proof (neg_clausify) ``` paulson@23449 ` 113` ```fix c x ``` paulson@24937 ` 114` ```have 0: "\(X1\'a\ordered_idom) X2\'a\ordered_idom. \X1 * X2\ = \X2 * X1\" ``` paulson@24937 ` 115` ``` by (metis abs_mult mult_commute) ``` paulson@24937 ` 116` ```assume 1: "\x\'b\type. ``` paulson@24937 ` 117` ``` \(h\'b\type \ 'a\ordered_idom) x\ ``` paulson@24937 ` 118` ``` \ (c\'a\ordered_idom) * \(f\'b\type \ 'a\ordered_idom) x\" ``` paulson@24937 ` 119` ```assume 2: "\ \(h\'b\type \ 'a\ordered_idom) (x\'b\type)\ ``` paulson@24937 ` 120` ``` \ \c\'a\ordered_idom\ * \(f\'b\type \ 'a\ordered_idom) x\" ``` paulson@24937 ` 121` ```have 3: "\ \(h\'b\type \ 'a\ordered_idom) (x\'b\type)\ ``` paulson@24937 ` 122` ``` \ \(c\'a\ordered_idom) * (f\'b\type \ 'a\ordered_idom) x\" ``` paulson@24937 ` 123` ``` by (metis 2 abs_mult) ``` paulson@24937 ` 124` ```have 4: "\(X1\'a\ordered_idom) X2\'a\ordered_idom. ``` paulson@24937 ` 125` ``` \ X1 \ (0\'a\ordered_idom) \ X1 \ \X2\" ``` paulson@24937 ` 126` ``` by (metis abs_ge_zero xt1(6)) ``` paulson@24937 ` 127` ```have 5: "(0\'a\ordered_idom) < \(h\'b\type \ 'a\ordered_idom) (x\'b\type)\" ``` paulson@24937 ` 128` ``` by (metis not_leE 4 3) ``` paulson@24937 ` 129` ```have 6: "(0\'a\ordered_idom) ``` paulson@24937 ` 130` ```< (c\'a\ordered_idom) * \(f\'b\type \ 'a\ordered_idom) (x\'b\type)\" ``` paulson@24937 ` 131` ``` by (metis 1 order_less_le_trans 5) ``` paulson@24937 ` 132` ```have 7: "\X1\'a\ordered_idom. (c\'a\ordered_idom) * \X1\ = \X1 * c\" ``` paulson@24937 ` 133` ``` by (metis abs_ge_zero linorder_not_less mult_nonneg_nonpos2 6 linorder_linear abs_mult_pos mult_commute) ``` paulson@24937 ` 134` ```have 8: "\X1\'b\type. ``` paulson@24937 ` 135` ``` - (h\'b\type \ 'a\ordered_idom) X1 ``` paulson@24937 ` 136` ``` \ \(c\'a\ordered_idom) * (f\'b\type \ 'a\ordered_idom) X1\" ``` paulson@24937 ` 137` ``` by (metis 0 7 abs_le_D2 1) ``` paulson@24937 ` 138` ```have 9: "\(X1\'a\ordered_idom) X2\'a\ordered_idom. \ \X1\ \ X2 \ X1 \ \X2\" ``` paulson@24937 ` 139` ``` by (metis abs_ge_self xt1(6) abs_le_D1) ``` paulson@23449 ` 140` ```show "False" ``` paulson@24937 ` 141` ``` by (metis 8 abs_ge_zero abs_mult_pos abs_mult 1 9 3 abs_le_iff) ``` paulson@23449 ` 142` ```qed ``` paulson@23449 ` 143` paulson@26333 ` 144` ```declare [[sledgehammer_modulus = 3]] ``` paulson@25710 ` 145` paulson@23449 ` 146` ```lemma (*bigo_pos_const:*) "(EX (c::'a::ordered_idom). ``` paulson@23449 ` 147` ``` ALL x. (abs (h x)) <= (c * (abs (f x)))) ``` paulson@23449 ` 148` ``` = (EX c. 0 < c & (ALL x. (abs(h x)) <= (c * (abs (f x)))))" ``` paulson@23449 ` 149` ``` apply auto ``` paulson@23449 ` 150` ``` apply (case_tac "c = 0", simp) ``` paulson@23449 ` 151` ``` apply (rule_tac x = "1" in exI, simp) ``` paulson@23449 ` 152` ``` apply (rule_tac x = "abs c" in exI, auto); ``` paulson@23449 ` 153` ```proof (neg_clausify) ``` paulson@23449 ` 154` ```fix c x ``` paulson@24937 ` 155` ```assume 0: "\x\'b\type. ``` paulson@24937 ` 156` ``` \(h\'b\type \ 'a\ordered_idom) x\ ``` paulson@24937 ` 157` ``` \ (c\'a\ordered_idom) * \(f\'b\type \ 'a\ordered_idom) x\" ``` paulson@24937 ` 158` ```assume 1: "\ \(h\'b\type \ 'a\ordered_idom) (x\'b\type)\ ``` paulson@23449 ` 159` ``` \ \c\'a\ordered_idom\ * \(f\'b\type \ 'a\ordered_idom) x\" ``` paulson@24937 ` 160` ```have 2: "\(X1\'a\ordered_idom) X2\'a\ordered_idom. ``` paulson@24937 ` 161` ``` X1 \ \X2\ \ (0\'a\ordered_idom) < X1" ``` paulson@24937 ` 162` ``` by (metis abs_ge_zero xt1(6) not_leE) ``` paulson@24937 ` 163` ```have 3: "\ (c\'a\ordered_idom) \ (0\'a\ordered_idom)" ``` paulson@24937 ` 164` ``` by (metis abs_ge_zero mult_nonneg_nonpos2 linorder_not_less order_less_le_trans 1 abs_mult 2 0) ``` paulson@24937 ` 165` ```have 4: "\(X1\'a\ordered_idom) X2\'a\ordered_idom. \X1 * \X2\\ = \X1 * X2\" ``` paulson@24937 ` 166` ``` by (metis abs_ge_zero abs_mult_pos abs_mult) ``` paulson@24937 ` 167` ```have 5: "\X1\'b\type. ``` paulson@24937 ` 168` ``` (h\'b\type \ 'a\ordered_idom) X1 ``` paulson@24937 ` 169` ``` \ \(c\'a\ordered_idom) * (f\'b\type \ 'a\ordered_idom) X1\" ``` paulson@24937 ` 170` ``` by (metis 4 0 xt1(6) abs_ge_self abs_le_D1) ``` paulson@23449 ` 171` ```show "False" ``` paulson@24937 ` 172` ``` by (metis abs_mult mult_commute 3 abs_mult_pos linorder_linear 0 abs_le_D2 5 1 abs_le_iff) ``` paulson@23449 ` 173` ```qed ``` paulson@23449 ` 174` paulson@23449 ` 175` paulson@26333 ` 176` ```declare [[sledgehammer_modulus = 1]] ``` paulson@24545 ` 177` paulson@24545 ` 178` ```lemma (*bigo_pos_const:*) "(EX (c::'a::ordered_idom). ``` paulson@24545 ` 179` ``` ALL x. (abs (h x)) <= (c * (abs (f x)))) ``` paulson@24545 ` 180` ``` = (EX c. 0 < c & (ALL x. (abs(h x)) <= (c * (abs (f x)))))" ``` paulson@24545 ` 181` ``` apply auto ``` paulson@24545 ` 182` ``` apply (case_tac "c = 0", simp) ``` paulson@24545 ` 183` ``` apply (rule_tac x = "1" in exI, simp) ``` paulson@24545 ` 184` ``` apply (rule_tac x = "abs c" in exI, auto); ``` paulson@24545 ` 185` ```proof (neg_clausify) ``` paulson@24545 ` 186` ```fix c x (*sort/type constraint inserted by hand!*) ``` paulson@24545 ` 187` ```have 0: "\(X1\'a\ordered_idom) X2. \X1 * \X2\\ = \X1 * X2\" ``` paulson@24545 ` 188` ``` by (metis abs_ge_zero abs_mult_pos abs_mult) ``` paulson@24545 ` 189` ```assume 1: "\A. \h A\ \ c * \f A\" ``` paulson@24545 ` 190` ```have 2: "\X1 X2. \ \X1\ \ X2 \ (0\'a) \ X2" ``` paulson@24545 ` 191` ``` by (metis abs_ge_zero order_trans) ``` paulson@24545 ` 192` ```have 3: "\X1. (0\'a) \ c * \f X1\" ``` paulson@24545 ` 193` ``` by (metis 1 2) ``` paulson@24545 ` 194` ```have 4: "\X1. c * \f X1\ = \c * f X1\" ``` paulson@24545 ` 195` ``` by (metis 0 abs_of_nonneg 3) ``` paulson@24545 ` 196` ```have 5: "\X1. - h X1 \ c * \f X1\" ``` paulson@24545 ` 197` ``` by (metis 1 abs_le_D2) ``` paulson@24545 ` 198` ```have 6: "\X1. - h X1 \ \c * f X1\" ``` paulson@24545 ` 199` ``` by (metis 4 5) ``` paulson@24545 ` 200` ```have 7: "\X1. h X1 \ c * \f X1\" ``` paulson@24545 ` 201` ``` by (metis 1 abs_le_D1) ``` paulson@24545 ` 202` ```have 8: "\X1. h X1 \ \c * f X1\" ``` paulson@24545 ` 203` ``` by (metis 4 7) ``` paulson@24545 ` 204` ```assume 9: "\ \h x\ \ \c\ * \f x\" ``` paulson@24545 ` 205` ```have 10: "\ \h x\ \ \c * f x\" ``` paulson@24545 ` 206` ``` by (metis abs_mult 9) ``` paulson@24545 ` 207` ```show "False" ``` paulson@24545 ` 208` ``` by (metis 6 8 10 abs_leI) ``` paulson@24545 ` 209` ```qed ``` paulson@24545 ` 210` paulson@24545 ` 211` paulson@26333 ` 212` ```declare [[sledgehammer_sorts = true]] ``` paulson@24545 ` 213` paulson@23449 ` 214` ```lemma bigo_alt_def: "O(f) = ``` paulson@23449 ` 215` ``` {h. EX c. (0 < c & (ALL x. abs (h x) <= c * abs (f x)))}" ``` paulson@23449 ` 216` ```by (auto simp add: bigo_def bigo_pos_const) ``` paulson@23449 ` 217` wenzelm@26483 ` 218` ```ML_command{*ResAtp.problem_name := "BigO__bigo_elt_subset"*} ``` paulson@23449 ` 219` ```lemma bigo_elt_subset [intro]: "f : O(g) ==> O(f) <= O(g)" ``` paulson@23449 ` 220` ``` apply (auto simp add: bigo_alt_def) ``` paulson@23449 ` 221` ``` apply (rule_tac x = "ca * c" in exI) ``` paulson@23449 ` 222` ``` apply (rule conjI) ``` paulson@23449 ` 223` ``` apply (rule mult_pos_pos) ``` paulson@23449 ` 224` ``` apply (assumption)+ ``` paulson@23449 ` 225` ```(*sledgehammer*); ``` paulson@23449 ` 226` ``` apply (rule allI) ``` paulson@23449 ` 227` ``` apply (drule_tac x = "xa" in spec)+ ``` paulson@23449 ` 228` ``` apply (subgoal_tac "ca * abs(f xa) <= ca * (c * abs(g xa))"); ``` paulson@23449 ` 229` ``` apply (erule order_trans) ``` paulson@23449 ` 230` ``` apply (simp add: mult_ac) ``` paulson@23449 ` 231` ``` apply (rule mult_left_mono, assumption) ``` paulson@23449 ` 232` ``` apply (rule order_less_imp_le, assumption); ``` paulson@23449 ` 233` ```done ``` paulson@23449 ` 234` paulson@23449 ` 235` wenzelm@26483 ` 236` ```ML_command{*ResAtp.problem_name := "BigO__bigo_refl"*} ``` paulson@23449 ` 237` ```lemma bigo_refl [intro]: "f : O(f)" ``` paulson@23449 ` 238` ``` apply(auto simp add: bigo_def) ``` paulson@23449 ` 239` ```proof (neg_clausify) ``` paulson@23449 ` 240` ```fix x ``` paulson@24937 ` 241` ```assume 0: "\xa. \ \f (x xa)\ \ xa * \f (x xa)\" ``` paulson@24937 ` 242` ```have 1: "\X2. X2 \ (1\'b) * X2 \ \ (1\'b) \ (1\'b)" ``` paulson@24937 ` 243` ``` by (metis mult_le_cancel_right1 order_eq_iff) ``` paulson@24937 ` 244` ```have 2: "\X2. X2 \ (1\'b) * X2" ``` paulson@24937 ` 245` ``` by (metis order_eq_iff 1) ``` paulson@24937 ` 246` ```show "False" ``` paulson@23449 ` 247` ``` by (metis 0 2) ``` paulson@23449 ` 248` ```qed ``` paulson@23449 ` 249` wenzelm@26483 ` 250` ```ML_command{*ResAtp.problem_name := "BigO__bigo_zero"*} ``` paulson@23449 ` 251` ```lemma bigo_zero: "0 : O(g)" ``` paulson@23449 ` 252` ``` apply (auto simp add: bigo_def func_zero) ``` paulson@23449 ` 253` ```proof (neg_clausify) ``` paulson@23449 ` 254` ```fix x ``` paulson@24937 ` 255` ```assume 0: "\xa. \ (0\'b) \ xa * \g (x xa)\" ``` paulson@24937 ` 256` ```have 1: "\ (0\'b) \ (0\'b)" ``` paulson@24937 ` 257` ``` by (metis 0 mult_eq_0_iff) ``` paulson@24937 ` 258` ```show "False" ``` paulson@24937 ` 259` ``` by (metis 1 linorder_neq_iff linorder_antisym_conv1) ``` paulson@23449 ` 260` ```qed ``` paulson@23449 ` 261` paulson@23449 ` 262` ```lemma bigo_zero2: "O(%x.0) = {%x.0}" ``` paulson@23449 ` 263` ``` apply (auto simp add: bigo_def) ``` paulson@23449 ` 264` ``` apply (rule ext) ``` paulson@23449 ` 265` ``` apply auto ``` paulson@23449 ` 266` ```done ``` paulson@23449 ` 267` paulson@23449 ` 268` ```lemma bigo_plus_self_subset [intro]: ``` berghofe@26814 ` 269` ``` "O(f) \ O(f) <= O(f)" ``` berghofe@26814 ` 270` ``` apply (auto simp add: bigo_alt_def set_plus_def) ``` paulson@23449 ` 271` ``` apply (rule_tac x = "c + ca" in exI) ``` paulson@23449 ` 272` ``` apply auto ``` nipkow@23477 ` 273` ``` apply (simp add: ring_distribs func_plus) ``` paulson@23449 ` 274` ``` apply (blast intro:order_trans abs_triangle_ineq add_mono elim:) ``` paulson@23449 ` 275` ```done ``` paulson@23449 ` 276` berghofe@26814 ` 277` ```lemma bigo_plus_idemp [simp]: "O(f) \ O(f) = O(f)" ``` paulson@23449 ` 278` ``` apply (rule equalityI) ``` paulson@23449 ` 279` ``` apply (rule bigo_plus_self_subset) ``` paulson@23449 ` 280` ``` apply (rule set_zero_plus2) ``` paulson@23449 ` 281` ``` apply (rule bigo_zero) ``` paulson@23449 ` 282` ```done ``` paulson@23449 ` 283` berghofe@26814 ` 284` ```lemma bigo_plus_subset [intro]: "O(f + g) <= O(f) \ O(g)" ``` paulson@23449 ` 285` ``` apply (rule subsetI) ``` berghofe@26814 ` 286` ``` apply (auto simp add: bigo_def bigo_pos_const func_plus set_plus_def) ``` paulson@23449 ` 287` ``` apply (subst bigo_pos_const [symmetric])+ ``` paulson@23449 ` 288` ``` apply (rule_tac x = ``` paulson@23449 ` 289` ``` "%n. if abs (g n) <= (abs (f n)) then x n else 0" in exI) ``` paulson@23449 ` 290` ``` apply (rule conjI) ``` paulson@23449 ` 291` ``` apply (rule_tac x = "c + c" in exI) ``` paulson@23449 ` 292` ``` apply (clarsimp) ``` paulson@23449 ` 293` ``` apply (auto) ``` paulson@23449 ` 294` ``` apply (subgoal_tac "c * abs (f xa + g xa) <= (c + c) * abs (f xa)") ``` paulson@23449 ` 295` ``` apply (erule_tac x = xa in allE) ``` paulson@23449 ` 296` ``` apply (erule order_trans) ``` paulson@23449 ` 297` ``` apply (simp) ``` paulson@23449 ` 298` ``` apply (subgoal_tac "c * abs (f xa + g xa) <= c * (abs (f xa) + abs (g xa))") ``` paulson@23449 ` 299` ``` apply (erule order_trans) ``` nipkow@23477 ` 300` ``` apply (simp add: ring_distribs) ``` paulson@23449 ` 301` ``` apply (rule mult_left_mono) ``` paulson@23449 ` 302` ``` apply assumption ``` paulson@23449 ` 303` ``` apply (simp add: order_less_le) ``` paulson@23449 ` 304` ``` apply (rule mult_left_mono) ``` paulson@23449 ` 305` ``` apply (simp add: abs_triangle_ineq) ``` paulson@23449 ` 306` ``` apply (simp add: order_less_le) ``` paulson@23449 ` 307` ``` apply (rule mult_nonneg_nonneg) ``` paulson@23449 ` 308` ``` apply (rule add_nonneg_nonneg) ``` paulson@23449 ` 309` ``` apply auto ``` paulson@23449 ` 310` ``` apply (rule_tac x = "%n. if (abs (f n)) < abs (g n) then x n else 0" ``` paulson@23449 ` 311` ``` in exI) ``` paulson@23449 ` 312` ``` apply (rule conjI) ``` paulson@23449 ` 313` ``` apply (rule_tac x = "c + c" in exI) ``` paulson@23449 ` 314` ``` apply auto ``` paulson@23449 ` 315` ``` apply (subgoal_tac "c * abs (f xa + g xa) <= (c + c) * abs (g xa)") ``` paulson@23449 ` 316` ``` apply (erule_tac x = xa in allE) ``` paulson@23449 ` 317` ``` apply (erule order_trans) ``` paulson@23449 ` 318` ``` apply (simp) ``` paulson@23449 ` 319` ``` apply (subgoal_tac "c * abs (f xa + g xa) <= c * (abs (f xa) + abs (g xa))") ``` paulson@23449 ` 320` ``` apply (erule order_trans) ``` nipkow@23477 ` 321` ``` apply (simp add: ring_distribs) ``` paulson@23449 ` 322` ``` apply (rule mult_left_mono) ``` paulson@23449 ` 323` ``` apply (simp add: order_less_le) ``` paulson@23449 ` 324` ``` apply (simp add: order_less_le) ``` paulson@23449 ` 325` ``` apply (rule mult_left_mono) ``` paulson@23449 ` 326` ``` apply (rule abs_triangle_ineq) ``` paulson@23449 ` 327` ``` apply (simp add: order_less_le) ``` paulson@25087 ` 328` ```apply (metis abs_not_less_zero double_less_0_iff less_not_permute linorder_not_less mult_less_0_iff) ``` paulson@23449 ` 329` ``` apply (rule ext) ``` paulson@23449 ` 330` ``` apply (auto simp add: if_splits linorder_not_le) ``` paulson@23449 ` 331` ```done ``` paulson@23449 ` 332` berghofe@26814 ` 333` ```lemma bigo_plus_subset2 [intro]: "A <= O(f) ==> B <= O(f) ==> A \ B <= O(f)" ``` berghofe@26814 ` 334` ``` apply (subgoal_tac "A \ B <= O(f) \ O(f)") ``` paulson@23449 ` 335` ``` apply (erule order_trans) ``` paulson@23449 ` 336` ``` apply simp ``` paulson@23449 ` 337` ``` apply (auto del: subsetI simp del: bigo_plus_idemp) ``` paulson@23449 ` 338` ```done ``` paulson@23449 ` 339` wenzelm@26483 ` 340` ```ML_command{*ResAtp.problem_name := "BigO__bigo_plus_eq"*} ``` paulson@23449 ` 341` ```lemma bigo_plus_eq: "ALL x. 0 <= f x ==> ALL x. 0 <= g x ==> ``` berghofe@26814 ` 342` ``` O(f + g) = O(f) \ O(g)" ``` paulson@23449 ` 343` ``` apply (rule equalityI) ``` paulson@23449 ` 344` ``` apply (rule bigo_plus_subset) ``` berghofe@26814 ` 345` ``` apply (simp add: bigo_alt_def set_plus_def func_plus) ``` paulson@23449 ` 346` ``` apply clarify ``` paulson@23449 ` 347` ```(*sledgehammer*); ``` paulson@23449 ` 348` ``` apply (rule_tac x = "max c ca" in exI) ``` paulson@23449 ` 349` ``` apply (rule conjI) ``` paulson@25087 ` 350` ``` apply (metis Orderings.less_max_iff_disj) ``` paulson@23449 ` 351` ``` apply clarify ``` paulson@23449 ` 352` ``` apply (drule_tac x = "xa" in spec)+ ``` paulson@23449 ` 353` ``` apply (subgoal_tac "0 <= f xa + g xa") ``` nipkow@23477 ` 354` ``` apply (simp add: ring_distribs) ``` paulson@23449 ` 355` ``` apply (subgoal_tac "abs(a xa + b xa) <= abs(a xa) + abs(b xa)") ``` paulson@23449 ` 356` ``` apply (subgoal_tac "abs(a xa) + abs(b xa) <= ``` paulson@23449 ` 357` ``` max c ca * f xa + max c ca * g xa") ``` paulson@23449 ` 358` ``` apply (blast intro: order_trans) ``` paulson@23449 ` 359` ``` defer 1 ``` paulson@23449 ` 360` ``` apply (rule abs_triangle_ineq) ``` paulson@25087 ` 361` ``` apply (metis add_nonneg_nonneg) ``` paulson@23449 ` 362` ``` apply (rule add_mono) ``` wenzelm@26483 ` 363` ```ML_command{*ResAtp.problem_name := "BigO__bigo_plus_eq_simpler"*} ``` paulson@24942 ` 364` ```(*Found by SPASS; SLOW*) ``` paulson@25710 ` 365` ```apply (metis le_maxI2 linorder_linear linorder_not_le min_max.less_eq_less_sup.sup_absorb1 mult_le_cancel_right order_trans) ``` paulson@25710 ` 366` ```apply (metis le_maxI2 linorder_not_le mult_le_cancel_right order_trans) ``` paulson@23449 ` 367` ```done ``` paulson@23449 ` 368` wenzelm@26483 ` 369` ```ML_command{*ResAtp.problem_name := "BigO__bigo_bounded_alt"*} ``` paulson@23449 ` 370` ```lemma bigo_bounded_alt: "ALL x. 0 <= f x ==> ALL x. f x <= c * g x ==> ``` paulson@23449 ` 371` ``` f : O(g)" ``` paulson@23449 ` 372` ``` apply (auto simp add: bigo_def) ``` paulson@23449 ` 373` ```(*Version 1: one-shot proof*) ``` ballarin@26645 ` 374` ``` apply (metis OrderedGroup.abs_le_D1 linorder_class.not_less order_less_le Orderings.xt1(12) Ring_and_Field.abs_mult) ``` paulson@23449 ` 375` ``` done ``` paulson@23449 ` 376` wenzelm@26312 ` 377` ```lemma (*bigo_bounded_alt:*) "ALL x. 0 <= f x ==> ALL x. f x <= c * g x ==> ``` paulson@23449 ` 378` ``` f : O(g)" ``` paulson@23449 ` 379` ``` apply (auto simp add: bigo_def) ``` paulson@23449 ` 380` ```(*Version 2: single-step proof*) ``` paulson@23449 ` 381` ```proof (neg_clausify) ``` paulson@23449 ` 382` ```fix x ``` paulson@24937 ` 383` ```assume 0: "\x. f x \ c * g x" ``` paulson@24937 ` 384` ```assume 1: "\xa. \ f (x xa) \ xa * \g (x xa)\" ``` paulson@24937 ` 385` ```have 2: "\X3. c * g X3 = f X3 \ \ c * g X3 \ f X3" ``` paulson@24937 ` 386` ``` by (metis 0 order_antisym_conv) ``` paulson@24937 ` 387` ```have 3: "\X3. \ f (x \X3\) \ \X3 * g (x \X3\)\" ``` paulson@24937 ` 388` ``` by (metis 1 abs_mult) ``` paulson@24937 ` 389` ```have 4: "\X1 X3\'b\ordered_idom. X3 \ X1 \ X1 \ \X3\" ``` paulson@24937 ` 390` ``` by (metis linorder_linear abs_le_D1) ``` paulson@24937 ` 391` ```have 5: "\X3::'b. \X3\ * \X3\ = X3 * X3" ``` haftmann@26041 ` 392` ``` by (metis abs_mult_self) ``` paulson@24937 ` 393` ```have 6: "\X3. \ X3 * X3 < (0\'b\ordered_idom)" ``` haftmann@26041 ` 394` ``` by (metis not_square_less_zero) ``` paulson@24937 ` 395` ```have 7: "\X1 X3::'b. \X1\ * \X3\ = \X3 * X1\" ``` haftmann@26041 ` 396` ``` by (metis abs_mult mult_commute) ``` paulson@24937 ` 397` ```have 8: "\X3::'b. X3 * X3 = \X3 * X3\" ``` paulson@24937 ` 398` ``` by (metis abs_mult 5) ``` paulson@24937 ` 399` ```have 9: "\X3. X3 * g (x \X3\) \ f (x \X3\)" ``` paulson@24937 ` 400` ``` by (metis 3 4) ``` paulson@24937 ` 401` ```have 10: "c * g (x \c\) = f (x \c\)" ``` paulson@24937 ` 402` ``` by (metis 2 9) ``` paulson@24937 ` 403` ```have 11: "\X3::'b. \X3\ * \\X3\\ = \X3\ * \X3\" ``` paulson@24937 ` 404` ``` by (metis abs_idempotent abs_mult 8) ``` paulson@24937 ` 405` ```have 12: "\X3::'b. \X3 * \X3\\ = \X3\ * \X3\" ``` haftmann@26041 ` 406` ``` by (metis mult_commute 7 11) ``` paulson@24937 ` 407` ```have 13: "\X3::'b. \X3 * \X3\\ = X3 * X3" ``` paulson@24937 ` 408` ``` by (metis 8 7 12) ``` paulson@24937 ` 409` ```have 14: "\X3. X3 \ \X3\ \ X3 < (0\'b)" ``` paulson@24937 ` 410` ``` by (metis abs_ge_self abs_le_D1 abs_if) ``` paulson@24937 ` 411` ```have 15: "\X3. X3 \ \X3\ \ \X3\ < (0\'b)" ``` paulson@24937 ` 412` ``` by (metis abs_ge_self abs_le_D1 abs_if) ``` paulson@24937 ` 413` ```have 16: "\X3. X3 * X3 < (0\'b) \ X3 * \X3\ \ X3 * X3" ``` paulson@24937 ` 414` ``` by (metis 15 13) ``` paulson@24937 ` 415` ```have 17: "\X3::'b. X3 * \X3\ \ X3 * X3" ``` paulson@24937 ` 416` ``` by (metis 16 6) ``` paulson@24937 ` 417` ```have 18: "\X3. X3 \ \X3\ \ \ X3 < (0\'b)" ``` paulson@24937 ` 418` ``` by (metis mult_le_cancel_left 17) ``` paulson@24937 ` 419` ```have 19: "\X3::'b. X3 \ \X3\" ``` paulson@24937 ` 420` ``` by (metis 18 14) ``` paulson@24937 ` 421` ```have 20: "\ f (x \c\) \ \f (x \c\)\" ``` paulson@24937 ` 422` ``` by (metis 3 10) ``` paulson@24937 ` 423` ```show "False" ``` paulson@24937 ` 424` ``` by (metis 20 19) ``` paulson@23449 ` 425` ```qed ``` paulson@23449 ` 426` paulson@23449 ` 427` paulson@23449 ` 428` ```text{*So here is the easier (and more natural) problem using transitivity*} ``` wenzelm@26483 ` 429` ```ML_command{*ResAtp.problem_name := "BigO__bigo_bounded_alt_trans"*} ``` paulson@23449 ` 430` ```lemma "ALL x. 0 <= f x ==> ALL x. f x <= c * g x ==> f : O(g)" ``` paulson@23449 ` 431` ``` apply (auto simp add: bigo_def) ``` paulson@23449 ` 432` ``` (*Version 1: one-shot proof*) ``` paulson@25710 ` 433` ``` apply (metis Orderings.leD Orderings.leI abs_ge_self abs_le_D1 abs_mult abs_of_nonneg order_le_less) ``` paulson@23449 ` 434` ``` done ``` paulson@23449 ` 435` paulson@23449 ` 436` ```text{*So here is the easier (and more natural) problem using transitivity*} ``` wenzelm@26483 ` 437` ```ML_command{*ResAtp.problem_name := "BigO__bigo_bounded_alt_trans"*} ``` paulson@23449 ` 438` ```lemma "ALL x. 0 <= f x ==> ALL x. f x <= c * g x ==> f : O(g)" ``` paulson@23449 ` 439` ``` apply (auto simp add: bigo_def) ``` paulson@23449 ` 440` ```(*Version 2: single-step proof*) ``` paulson@23449 ` 441` ```proof (neg_clausify) ``` paulson@23449 ` 442` ```fix x ``` paulson@23519 ` 443` ```assume 0: "\A\'a\type. ``` paulson@23519 ` 444` ``` (f\'a\type \ 'b\ordered_idom) A ``` paulson@23519 ` 445` ``` \ (c\'b\ordered_idom) * (g\'a\type \ 'b\ordered_idom) A" ``` paulson@23519 ` 446` ```assume 1: "\A\'b\ordered_idom. ``` paulson@23519 ` 447` ``` \ (f\'a\type \ 'b\ordered_idom) ((x\'b\ordered_idom \ 'a\type) A) ``` paulson@23519 ` 448` ``` \ A * \(g\'a\type \ 'b\ordered_idom) (x A)\" ``` paulson@23519 ` 449` ```have 2: "\X2\'a\type. ``` paulson@23519 ` 450` ``` \ (c\'b\ordered_idom) * (g\'a\type \ 'b\ordered_idom) X2 ``` paulson@23519 ` 451` ``` < (f\'a\type \ 'b\ordered_idom) X2" ``` paulson@23519 ` 452` ``` by (metis 0 linorder_not_le) ``` paulson@23519 ` 453` ```have 3: "\X2\'b\ordered_idom. ``` paulson@23519 ` 454` ``` \ (f\'a\type \ 'b\ordered_idom) ((x\'b\ordered_idom \ 'a\type) \X2\) ``` paulson@23519 ` 455` ``` \ \X2 * (g\'a\type \ 'b\ordered_idom) (x \X2\)\" ``` paulson@23519 ` 456` ``` by (metis abs_mult 1) ``` paulson@23519 ` 457` ```have 4: "\X2\'b\ordered_idom. ``` paulson@23519 ` 458` ``` \X2 * (g\'a\type \ 'b\ordered_idom) ((x\'b\ordered_idom \ 'a\type) \X2\)\ ``` paulson@23519 ` 459` ``` < (f\'a\type \ 'b\ordered_idom) (x \X2\)" ``` paulson@23519 ` 460` ``` by (metis 3 linorder_not_less) ``` paulson@23519 ` 461` ```have 5: "\X2\'b\ordered_idom. ``` paulson@23519 ` 462` ``` X2 * (g\'a\type \ 'b\ordered_idom) ((x\'b\ordered_idom \ 'a\type) \X2\) ``` paulson@23519 ` 463` ``` < (f\'a\type \ 'b\ordered_idom) (x \X2\)" ``` paulson@23519 ` 464` ``` by (metis abs_less_iff 4) ``` paulson@23519 ` 465` ```show "False" ``` paulson@23519 ` 466` ``` by (metis 2 5) ``` paulson@23449 ` 467` ```qed ``` paulson@23449 ` 468` paulson@23449 ` 469` paulson@23449 ` 470` ```lemma bigo_bounded: "ALL x. 0 <= f x ==> ALL x. f x <= g x ==> ``` paulson@23449 ` 471` ``` f : O(g)" ``` paulson@23449 ` 472` ``` apply (erule bigo_bounded_alt [of f 1 g]) ``` paulson@23449 ` 473` ``` apply simp ``` paulson@23449 ` 474` ```done ``` paulson@23449 ` 475` wenzelm@26483 ` 476` ```ML_command{*ResAtp.problem_name := "BigO__bigo_bounded2"*} ``` paulson@23449 ` 477` ```lemma bigo_bounded2: "ALL x. lb x <= f x ==> ALL x. f x <= lb x + g x ==> ``` paulson@23449 ` 478` ``` f : lb +o O(g)" ``` paulson@23449 ` 479` ``` apply (rule set_minus_imp_plus) ``` paulson@23449 ` 480` ``` apply (rule bigo_bounded) ``` berghofe@26814 ` 481` ``` apply (auto simp add: diff_minus fun_Compl_def func_plus) ``` paulson@23449 ` 482` ``` prefer 2 ``` paulson@23449 ` 483` ``` apply (drule_tac x = x in spec)+ ``` paulson@23449 ` 484` ``` apply arith (*not clear that it's provable otherwise*) ``` paulson@23449 ` 485` ```proof (neg_clausify) ``` paulson@23449 ` 486` ```fix x ``` paulson@23449 ` 487` ```assume 0: "\y. lb y \ f y" ``` paulson@23449 ` 488` ```assume 1: "\ (0\'b) \ f x + - lb x" ``` paulson@23449 ` 489` ```have 2: "\X3. (0\'b) + X3 = X3" ``` paulson@23449 ` 490` ``` by (metis diff_eq_eq right_minus_eq) ``` paulson@23449 ` 491` ```have 3: "\ (0\'b) \ f x - lb x" ``` paulson@23449 ` 492` ``` by (metis 1 compare_rls(1)) ``` paulson@23449 ` 493` ```have 4: "\ (0\'b) + lb x \ f x" ``` paulson@23449 ` 494` ``` by (metis 3 le_diff_eq) ``` paulson@23449 ` 495` ```show "False" ``` paulson@23449 ` 496` ``` by (metis 4 2 0) ``` paulson@23449 ` 497` ```qed ``` paulson@23449 ` 498` wenzelm@26483 ` 499` ```ML_command{*ResAtp.problem_name := "BigO__bigo_abs"*} ``` paulson@23449 ` 500` ```lemma bigo_abs: "(%x. abs(f x)) =o O(f)" ``` paulson@23449 ` 501` ``` apply (unfold bigo_def) ``` paulson@23449 ` 502` ``` apply auto ``` paulson@23449 ` 503` ```proof (neg_clausify) ``` paulson@23449 ` 504` ```fix x ``` paulson@24937 ` 505` ```assume 0: "\xa. \ \f (x xa)\ \ xa * \f (x xa)\" ``` paulson@24937 ` 506` ```have 1: "\X2. X2 \ (1\'b) * X2 \ \ (1\'b) \ (1\'b)" ``` paulson@24937 ` 507` ``` by (metis mult_le_cancel_right1 order_eq_iff) ``` paulson@24937 ` 508` ```have 2: "\X2. X2 \ (1\'b) * X2" ``` paulson@24937 ` 509` ``` by (metis order_eq_iff 1) ``` paulson@23449 ` 510` ```show "False" ``` paulson@23449 ` 511` ``` by (metis 0 2) ``` paulson@23449 ` 512` ```qed ``` paulson@23449 ` 513` wenzelm@26483 ` 514` ```ML_command{*ResAtp.problem_name := "BigO__bigo_abs2"*} ``` paulson@23449 ` 515` ```lemma bigo_abs2: "f =o O(%x. abs(f x))" ``` paulson@23449 ` 516` ``` apply (unfold bigo_def) ``` paulson@23449 ` 517` ``` apply auto ``` paulson@23449 ` 518` ```proof (neg_clausify) ``` paulson@23449 ` 519` ```fix x ``` paulson@24937 ` 520` ```assume 0: "\xa. \ \f (x xa)\ \ xa * \f (x xa)\" ``` paulson@24937 ` 521` ```have 1: "\X2. X2 \ (1\'b) * X2 \ \ (1\'b) \ (1\'b)" ``` paulson@24937 ` 522` ``` by (metis mult_le_cancel_right1 order_eq_iff) ``` paulson@24937 ` 523` ```have 2: "\X2. X2 \ (1\'b) * X2" ``` paulson@24937 ` 524` ``` by (metis order_eq_iff 1) ``` paulson@23449 ` 525` ```show "False" ``` paulson@23449 ` 526` ``` by (metis 0 2) ``` paulson@23449 ` 527` ```qed ``` paulson@23449 ` 528` ``` ``` paulson@23449 ` 529` ```lemma bigo_abs3: "O(f) = O(%x. abs(f x))" ``` paulson@23449 ` 530` ``` apply (rule equalityI) ``` paulson@23449 ` 531` ``` apply (rule bigo_elt_subset) ``` paulson@23449 ` 532` ``` apply (rule bigo_abs2) ``` paulson@23449 ` 533` ``` apply (rule bigo_elt_subset) ``` paulson@23449 ` 534` ``` apply (rule bigo_abs) ``` paulson@23449 ` 535` ```done ``` paulson@23449 ` 536` paulson@23449 ` 537` ```lemma bigo_abs4: "f =o g +o O(h) ==> ``` paulson@23449 ` 538` ``` (%x. abs (f x)) =o (%x. abs (g x)) +o O(h)" ``` paulson@23449 ` 539` ``` apply (drule set_plus_imp_minus) ``` paulson@23449 ` 540` ``` apply (rule set_minus_imp_plus) ``` berghofe@26814 ` 541` ``` apply (subst fun_diff_def) ``` paulson@23449 ` 542` ```proof - ``` paulson@23449 ` 543` ``` assume a: "f - g : O(h)" ``` paulson@23449 ` 544` ``` have "(%x. abs (f x) - abs (g x)) =o O(%x. abs(abs (f x) - abs (g x)))" ``` paulson@23449 ` 545` ``` by (rule bigo_abs2) ``` paulson@23449 ` 546` ``` also have "... <= O(%x. abs (f x - g x))" ``` paulson@23449 ` 547` ``` apply (rule bigo_elt_subset) ``` paulson@23449 ` 548` ``` apply (rule bigo_bounded) ``` paulson@23449 ` 549` ``` apply force ``` paulson@23449 ` 550` ``` apply (rule allI) ``` paulson@23449 ` 551` ``` apply (rule abs_triangle_ineq3) ``` paulson@23449 ` 552` ``` done ``` paulson@23449 ` 553` ``` also have "... <= O(f - g)" ``` paulson@23449 ` 554` ``` apply (rule bigo_elt_subset) ``` berghofe@26814 ` 555` ``` apply (subst fun_diff_def) ``` paulson@23449 ` 556` ``` apply (rule bigo_abs) ``` paulson@23449 ` 557` ``` done ``` paulson@23449 ` 558` ``` also have "... <= O(h)" ``` wenzelm@23464 ` 559` ``` using a by (rule bigo_elt_subset) ``` paulson@23449 ` 560` ``` finally show "(%x. abs (f x) - abs (g x)) : O(h)". ``` paulson@23449 ` 561` ```qed ``` paulson@23449 ` 562` paulson@23449 ` 563` ```lemma bigo_abs5: "f =o O(g) ==> (%x. abs(f x)) =o O(g)" ``` paulson@23449 ` 564` ```by (unfold bigo_def, auto) ``` paulson@23449 ` 565` berghofe@26814 ` 566` ```lemma bigo_elt_subset2 [intro]: "f : g +o O(h) ==> O(f) <= O(g) \ O(h)" ``` paulson@23449 ` 567` ```proof - ``` paulson@23449 ` 568` ``` assume "f : g +o O(h)" ``` berghofe@26814 ` 569` ``` also have "... <= O(g) \ O(h)" ``` paulson@23449 ` 570` ``` by (auto del: subsetI) ``` berghofe@26814 ` 571` ``` also have "... = O(%x. abs(g x)) \ O(%x. abs(h x))" ``` paulson@23449 ` 572` ``` apply (subst bigo_abs3 [symmetric])+ ``` paulson@23449 ` 573` ``` apply (rule refl) ``` paulson@23449 ` 574` ``` done ``` paulson@23449 ` 575` ``` also have "... = O((%x. abs(g x)) + (%x. abs(h x)))" ``` paulson@23449 ` 576` ``` by (rule bigo_plus_eq [symmetric], auto) ``` paulson@23449 ` 577` ``` finally have "f : ...". ``` paulson@23449 ` 578` ``` then have "O(f) <= ..." ``` paulson@23449 ` 579` ``` by (elim bigo_elt_subset) ``` berghofe@26814 ` 580` ``` also have "... = O(%x. abs(g x)) \ O(%x. abs(h x))" ``` paulson@23449 ` 581` ``` by (rule bigo_plus_eq, auto) ``` paulson@23449 ` 582` ``` finally show ?thesis ``` paulson@23449 ` 583` ``` by (simp add: bigo_abs3 [symmetric]) ``` paulson@23449 ` 584` ```qed ``` paulson@23449 ` 585` wenzelm@26483 ` 586` ```ML_command{*ResAtp.problem_name := "BigO__bigo_mult"*} ``` berghofe@26814 ` 587` ```lemma bigo_mult [intro]: "O(f)\O(g) <= O(f * g)" ``` paulson@23449 ` 588` ``` apply (rule subsetI) ``` paulson@23449 ` 589` ``` apply (subst bigo_def) ``` paulson@23449 ` 590` ``` apply (auto simp del: abs_mult mult_ac ``` berghofe@26814 ` 591` ``` simp add: bigo_alt_def set_times_def func_times) ``` paulson@23449 ` 592` ```(*sledgehammer*); ``` paulson@23449 ` 593` ``` apply (rule_tac x = "c * ca" in exI) ``` paulson@23449 ` 594` ``` apply(rule allI) ``` paulson@23449 ` 595` ``` apply(erule_tac x = x in allE)+ ``` paulson@23449 ` 596` ``` apply(subgoal_tac "c * ca * abs(f x * g x) = ``` paulson@23449 ` 597` ``` (c * abs(f x)) * (ca * abs(g x))") ``` wenzelm@26483 ` 598` ```ML_command{*ResAtp.problem_name := "BigO__bigo_mult_simpler"*} ``` paulson@23449 ` 599` ```prefer 2 ``` haftmann@26041 ` 600` ```apply (metis mult_assoc mult_left_commute ``` haftmann@26041 ` 601` ``` OrderedGroup.abs_of_pos OrderedGroup.mult_left_commute ``` haftmann@26041 ` 602` ``` Ring_and_Field.abs_mult Ring_and_Field.mult_pos_pos) ``` haftmann@26041 ` 603` ``` apply (erule ssubst) ``` paulson@23449 ` 604` ``` apply (subst abs_mult) ``` paulson@23449 ` 605` ```(*not qute BigO__bigo_mult_simpler_1 (a hard problem!) as abs_mult has ``` paulson@23449 ` 606` ``` just been done*) ``` paulson@23449 ` 607` ```proof (neg_clausify) ``` paulson@23449 ` 608` ```fix a c b ca x ``` paulson@23449 ` 609` ```assume 0: "(0\'b\ordered_idom) < (c\'b\ordered_idom)" ``` paulson@23449 ` 610` ```assume 1: "\(a\'a \ 'b\ordered_idom) (x\'a)\ ``` paulson@23449 ` 611` ```\ (c\'b\ordered_idom) * \(f\'a \ 'b\ordered_idom) x\" ``` paulson@23449 ` 612` ```assume 2: "\(b\'a \ 'b\ordered_idom) (x\'a)\ ``` paulson@23449 ` 613` ```\ (ca\'b\ordered_idom) * \(g\'a \ 'b\ordered_idom) x\" ``` paulson@23449 ` 614` ```assume 3: "\ \(a\'a \ 'b\ordered_idom) (x\'a)\ * ``` paulson@23449 ` 615` ``` \(b\'a \ 'b\ordered_idom) x\ ``` paulson@23449 ` 616` ``` \ (c\'b\ordered_idom) * \(f\'a \ 'b\ordered_idom) x\ * ``` paulson@23449 ` 617` ``` ((ca\'b\ordered_idom) * \(g\'a \ 'b\ordered_idom) x\)" ``` paulson@23449 ` 618` ```have 4: "\c\'b\ordered_idom\ = c" ``` paulson@23449 ` 619` ``` by (metis OrderedGroup.abs_of_pos 0) ``` paulson@23449 ` 620` ```have 5: "\X1\'b\ordered_idom. (c\'b\ordered_idom) * \X1\ = \c * X1\" ``` paulson@23449 ` 621` ``` by (metis Ring_and_Field.abs_mult 4) ``` paulson@23449 ` 622` ```have 6: "(0\'b\ordered_idom) = (1\'b\ordered_idom) \ ``` paulson@23449 ` 623` ```(0\'b\ordered_idom) < (1\'b\ordered_idom)" ``` paulson@23449 ` 624` ``` by (metis OrderedGroup.abs_not_less_zero Ring_and_Field.abs_one Ring_and_Field.linorder_neqE_ordered_idom) ``` paulson@23449 ` 625` ```have 7: "(0\'b\ordered_idom) < (1\'b\ordered_idom)" ``` paulson@23449 ` 626` ``` by (metis 6 Ring_and_Field.one_neq_zero) ``` paulson@23449 ` 627` ```have 8: "\1\'b\ordered_idom\ = (1\'b\ordered_idom)" ``` paulson@23449 ` 628` ``` by (metis OrderedGroup.abs_of_pos 7) ``` paulson@23449 ` 629` ```have 9: "\X1\'b\ordered_idom. (0\'b\ordered_idom) \ (c\'b\ordered_idom) * \X1\" ``` paulson@23449 ` 630` ``` by (metis OrderedGroup.abs_ge_zero 5) ``` paulson@23449 ` 631` ```have 10: "\X1\'b\ordered_idom. X1 * (1\'b\ordered_idom) = X1" ``` haftmann@26041 ` 632` ``` by (metis Ring_and_Field.mult_cancel_right2 mult_commute) ``` paulson@23449 ` 633` ```have 11: "\X1\'b\ordered_idom. \\X1\\ = \X1\ * \1\'b\ordered_idom\" ``` paulson@23449 ` 634` ``` by (metis Ring_and_Field.abs_mult OrderedGroup.abs_idempotent 10) ``` paulson@23449 ` 635` ```have 12: "\X1\'b\ordered_idom. \\X1\\ = \X1\" ``` paulson@23449 ` 636` ``` by (metis 11 8 10) ``` paulson@23449 ` 637` ```have 13: "\X1\'b\ordered_idom. (0\'b\ordered_idom) \ \X1\" ``` paulson@23449 ` 638` ``` by (metis OrderedGroup.abs_ge_zero 12) ``` paulson@23449 ` 639` ```have 14: "\ (0\'b\ordered_idom) ``` paulson@23449 ` 640` ``` \ (c\'b\ordered_idom) * \(f\'a \ 'b\ordered_idom) (x\'a)\ \ ``` paulson@23449 ` 641` ```\ (0\'b\ordered_idom) \ \(b\'a \ 'b\ordered_idom) x\ \ ``` paulson@23449 ` 642` ```\ \b x\ \ (ca\'b\ordered_idom) * \(g\'a \ 'b\ordered_idom) x\ \ ``` paulson@23449 ` 643` ```\ \(a\'a \ 'b\ordered_idom) x\ \ c * \f x\" ``` paulson@23449 ` 644` ``` by (metis 3 Ring_and_Field.mult_mono) ``` paulson@23449 ` 645` ```have 15: "\ (0\'b\ordered_idom) \ \(b\'a \ 'b\ordered_idom) (x\'a)\ \ ``` paulson@23449 ` 646` ```\ \b x\ \ (ca\'b\ordered_idom) * \(g\'a \ 'b\ordered_idom) x\ \ ``` paulson@23449 ` 647` ```\ \(a\'a \ 'b\ordered_idom) x\ ``` paulson@23449 ` 648` ``` \ (c\'b\ordered_idom) * \(f\'a \ 'b\ordered_idom) x\" ``` paulson@23449 ` 649` ``` by (metis 14 9) ``` paulson@23449 ` 650` ```have 16: "\ \(b\'a \ 'b\ordered_idom) (x\'a)\ ``` paulson@23449 ` 651` ``` \ (ca\'b\ordered_idom) * \(g\'a \ 'b\ordered_idom) x\ \ ``` paulson@23449 ` 652` ```\ \(a\'a \ 'b\ordered_idom) x\ ``` paulson@23449 ` 653` ``` \ (c\'b\ordered_idom) * \(f\'a \ 'b\ordered_idom) x\" ``` paulson@23449 ` 654` ``` by (metis 15 13) ``` paulson@23449 ` 655` ```have 17: "\ \(a\'a \ 'b\ordered_idom) (x\'a)\ ``` paulson@23449 ` 656` ``` \ (c\'b\ordered_idom) * \(f\'a \ 'b\ordered_idom) x\" ``` paulson@23449 ` 657` ``` by (metis 16 2) ``` paulson@23449 ` 658` ```show 18: "False" ``` paulson@23449 ` 659` ``` by (metis 17 1) ``` paulson@23449 ` 660` ```qed ``` paulson@23449 ` 661` paulson@23449 ` 662` wenzelm@26483 ` 663` ```ML_command{*ResAtp.problem_name := "BigO__bigo_mult2"*} ``` paulson@23449 ` 664` ```lemma bigo_mult2 [intro]: "f *o O(g) <= O(f * g)" ``` paulson@23449 ` 665` ``` apply (auto simp add: bigo_def elt_set_times_def func_times abs_mult) ``` paulson@23449 ` 666` ```(*sledgehammer*); ``` paulson@23449 ` 667` ``` apply (rule_tac x = c in exI) ``` paulson@23449 ` 668` ``` apply clarify ``` paulson@23449 ` 669` ``` apply (drule_tac x = x in spec) ``` wenzelm@26483 ` 670` ```ML_command{*ResAtp.problem_name := "BigO__bigo_mult2_simpler"*} ``` paulson@24942 ` 671` ```(*sledgehammer [no luck]*); ``` paulson@23449 ` 672` ``` apply (subgoal_tac "abs(f x) * abs(b x) <= abs(f x) * (c * abs(g x))") ``` paulson@23449 ` 673` ``` apply (simp add: mult_ac) ``` paulson@23449 ` 674` ``` apply (rule mult_left_mono, assumption) ``` paulson@23449 ` 675` ``` apply (rule abs_ge_zero) ``` paulson@23449 ` 676` ```done ``` paulson@23449 ` 677` wenzelm@26483 ` 678` ```ML_command{*ResAtp.problem_name:="BigO__bigo_mult3"*} ``` paulson@23449 ` 679` ```lemma bigo_mult3: "f : O(h) ==> g : O(j) ==> f * g : O(h * j)" ``` paulson@23449 ` 680` ```by (metis bigo_mult set_times_intro subset_iff) ``` paulson@23449 ` 681` wenzelm@26483 ` 682` ```ML_command{*ResAtp.problem_name:="BigO__bigo_mult4"*} ``` paulson@23449 ` 683` ```lemma bigo_mult4 [intro]:"f : k +o O(h) ==> g * f : (g * k) +o O(g * h)" ``` paulson@23449 ` 684` ```by (metis bigo_mult2 set_plus_mono_b set_times_intro2 set_times_plus_distrib) ``` paulson@23449 ` 685` paulson@23449 ` 686` paulson@23449 ` 687` ```lemma bigo_mult5: "ALL x. f x ~= 0 ==> ``` paulson@23449 ` 688` ``` O(f * g) <= (f::'a => ('b::ordered_field)) *o O(g)" ``` paulson@23449 ` 689` ```proof - ``` paulson@23449 ` 690` ``` assume "ALL x. f x ~= 0" ``` paulson@23449 ` 691` ``` show "O(f * g) <= f *o O(g)" ``` paulson@23449 ` 692` ``` proof ``` paulson@23449 ` 693` ``` fix h ``` paulson@23449 ` 694` ``` assume "h : O(f * g)" ``` paulson@23449 ` 695` ``` then have "(%x. 1 / (f x)) * h : (%x. 1 / f x) *o O(f * g)" ``` paulson@23449 ` 696` ``` by auto ``` paulson@23449 ` 697` ``` also have "... <= O((%x. 1 / f x) * (f * g))" ``` paulson@23449 ` 698` ``` by (rule bigo_mult2) ``` paulson@23449 ` 699` ``` also have "(%x. 1 / f x) * (f * g) = g" ``` paulson@23449 ` 700` ``` apply (simp add: func_times) ``` paulson@23449 ` 701` ``` apply (rule ext) ``` paulson@23449 ` 702` ``` apply (simp add: prems nonzero_divide_eq_eq mult_ac) ``` paulson@23449 ` 703` ``` done ``` paulson@23449 ` 704` ``` finally have "(%x. (1::'b) / f x) * h : O(g)". ``` paulson@23449 ` 705` ``` then have "f * ((%x. (1::'b) / f x) * h) : f *o O(g)" ``` paulson@23449 ` 706` ``` by auto ``` paulson@23449 ` 707` ``` also have "f * ((%x. (1::'b) / f x) * h) = h" ``` paulson@23449 ` 708` ``` apply (simp add: func_times) ``` paulson@23449 ` 709` ``` apply (rule ext) ``` paulson@23449 ` 710` ``` apply (simp add: prems nonzero_divide_eq_eq mult_ac) ``` paulson@23449 ` 711` ``` done ``` paulson@23449 ` 712` ``` finally show "h : f *o O(g)". ``` paulson@23449 ` 713` ``` qed ``` paulson@23449 ` 714` ```qed ``` paulson@23449 ` 715` wenzelm@26483 ` 716` ```ML_command{*ResAtp.problem_name := "BigO__bigo_mult6"*} ``` paulson@23449 ` 717` ```lemma bigo_mult6: "ALL x. f x ~= 0 ==> ``` paulson@23449 ` 718` ``` O(f * g) = (f::'a => ('b::ordered_field)) *o O(g)" ``` paulson@23449 ` 719` ```by (metis bigo_mult2 bigo_mult5 order_antisym) ``` paulson@23449 ` 720` paulson@23449 ` 721` ```(*proof requires relaxing relevance: 2007-01-25*) ``` wenzelm@26483 ` 722` ```ML_command{*ResAtp.problem_name := "BigO__bigo_mult7"*} ``` paulson@23449 ` 723` ``` declare bigo_mult6 [simp] ``` paulson@23449 ` 724` ```lemma bigo_mult7: "ALL x. f x ~= 0 ==> ``` berghofe@26814 ` 725` ``` O(f * g) <= O(f::'a => ('b::ordered_field)) \ O(g)" ``` paulson@23449 ` 726` ```(*sledgehammer*) ``` paulson@23449 ` 727` ``` apply (subst bigo_mult6) ``` paulson@23449 ` 728` ``` apply assumption ``` paulson@23449 ` 729` ``` apply (rule set_times_mono3) ``` paulson@23449 ` 730` ``` apply (rule bigo_refl) ``` paulson@23449 ` 731` ```done ``` paulson@23449 ` 732` ``` declare bigo_mult6 [simp del] ``` paulson@23449 ` 733` wenzelm@26483 ` 734` ```ML_command{*ResAtp.problem_name := "BigO__bigo_mult8"*} ``` paulson@23449 ` 735` ``` declare bigo_mult7[intro!] ``` paulson@23449 ` 736` ```lemma bigo_mult8: "ALL x. f x ~= 0 ==> ``` berghofe@26814 ` 737` ``` O(f * g) = O(f::'a => ('b::ordered_field)) \ O(g)" ``` paulson@23449 ` 738` ```by (metis bigo_mult bigo_mult7 order_antisym_conv) ``` paulson@23449 ` 739` paulson@23449 ` 740` ```lemma bigo_minus [intro]: "f : O(g) ==> - f : O(g)" ``` berghofe@26814 ` 741` ``` by (auto simp add: bigo_def fun_Compl_def) ``` paulson@23449 ` 742` paulson@23449 ` 743` ```lemma bigo_minus2: "f : g +o O(h) ==> -f : -g +o O(h)" ``` paulson@23449 ` 744` ``` apply (rule set_minus_imp_plus) ``` paulson@23449 ` 745` ``` apply (drule set_plus_imp_minus) ``` paulson@23449 ` 746` ``` apply (drule bigo_minus) ``` paulson@23449 ` 747` ``` apply (simp add: diff_minus) ``` paulson@23449 ` 748` ```done ``` paulson@23449 ` 749` paulson@23449 ` 750` ```lemma bigo_minus3: "O(-f) = O(f)" ``` berghofe@26814 ` 751` ``` by (auto simp add: bigo_def fun_Compl_def abs_minus_cancel) ``` paulson@23449 ` 752` paulson@23449 ` 753` ```lemma bigo_plus_absorb_lemma1: "f : O(g) ==> f +o O(g) <= O(g)" ``` paulson@23449 ` 754` ```proof - ``` paulson@23449 ` 755` ``` assume a: "f : O(g)" ``` paulson@23449 ` 756` ``` show "f +o O(g) <= O(g)" ``` paulson@23449 ` 757` ``` proof - ``` paulson@23449 ` 758` ``` have "f : O(f)" by auto ``` berghofe@26814 ` 759` ``` then have "f +o O(g) <= O(f) \ O(g)" ``` paulson@23449 ` 760` ``` by (auto del: subsetI) ``` berghofe@26814 ` 761` ``` also have "... <= O(g) \ O(g)" ``` paulson@23449 ` 762` ``` proof - ``` paulson@23449 ` 763` ``` from a have "O(f) <= O(g)" by (auto del: subsetI) ``` paulson@23449 ` 764` ``` thus ?thesis by (auto del: subsetI) ``` paulson@23449 ` 765` ``` qed ``` paulson@23449 ` 766` ``` also have "... <= O(g)" by (simp add: bigo_plus_idemp) ``` paulson@23449 ` 767` ``` finally show ?thesis . ``` paulson@23449 ` 768` ``` qed ``` paulson@23449 ` 769` ```qed ``` paulson@23449 ` 770` paulson@23449 ` 771` ```lemma bigo_plus_absorb_lemma2: "f : O(g) ==> O(g) <= f +o O(g)" ``` paulson@23449 ` 772` ```proof - ``` paulson@23449 ` 773` ``` assume a: "f : O(g)" ``` paulson@23449 ` 774` ``` show "O(g) <= f +o O(g)" ``` paulson@23449 ` 775` ``` proof - ``` paulson@23449 ` 776` ``` from a have "-f : O(g)" by auto ``` paulson@23449 ` 777` ``` then have "-f +o O(g) <= O(g)" by (elim bigo_plus_absorb_lemma1) ``` paulson@23449 ` 778` ``` then have "f +o (-f +o O(g)) <= f +o O(g)" by auto ``` paulson@23449 ` 779` ``` also have "f +o (-f +o O(g)) = O(g)" ``` paulson@23449 ` 780` ``` by (simp add: set_plus_rearranges) ``` paulson@23449 ` 781` ``` finally show ?thesis . ``` paulson@23449 ` 782` ``` qed ``` paulson@23449 ` 783` ```qed ``` paulson@23449 ` 784` wenzelm@26483 ` 785` ```ML_command{*ResAtp.problem_name:="BigO__bigo_plus_absorb"*} ``` paulson@23449 ` 786` ```lemma bigo_plus_absorb [simp]: "f : O(g) ==> f +o O(g) = O(g)" ``` paulson@23449 ` 787` ```by (metis bigo_plus_absorb_lemma1 bigo_plus_absorb_lemma2 order_eq_iff); ``` paulson@23449 ` 788` paulson@23449 ` 789` ```lemma bigo_plus_absorb2 [intro]: "f : O(g) ==> A <= O(g) ==> f +o A <= O(g)" ``` paulson@23449 ` 790` ``` apply (subgoal_tac "f +o A <= f +o O(g)") ``` paulson@23449 ` 791` ``` apply force+ ``` paulson@23449 ` 792` ```done ``` paulson@23449 ` 793` paulson@23449 ` 794` ```lemma bigo_add_commute_imp: "f : g +o O(h) ==> g : f +o O(h)" ``` paulson@23449 ` 795` ``` apply (subst set_minus_plus [symmetric]) ``` paulson@23449 ` 796` ``` apply (subgoal_tac "g - f = - (f - g)") ``` paulson@23449 ` 797` ``` apply (erule ssubst) ``` paulson@23449 ` 798` ``` apply (rule bigo_minus) ``` paulson@23449 ` 799` ``` apply (subst set_minus_plus) ``` paulson@23449 ` 800` ``` apply assumption ``` paulson@23449 ` 801` ``` apply (simp add: diff_minus add_ac) ``` paulson@23449 ` 802` ```done ``` paulson@23449 ` 803` paulson@23449 ` 804` ```lemma bigo_add_commute: "(f : g +o O(h)) = (g : f +o O(h))" ``` paulson@23449 ` 805` ``` apply (rule iffI) ``` paulson@23449 ` 806` ``` apply (erule bigo_add_commute_imp)+ ``` paulson@23449 ` 807` ```done ``` paulson@23449 ` 808` paulson@23449 ` 809` ```lemma bigo_const1: "(%x. c) : O(%x. 1)" ``` paulson@23449 ` 810` ```by (auto simp add: bigo_def mult_ac) ``` paulson@23449 ` 811` wenzelm@26483 ` 812` ```ML_command{*ResAtp.problem_name:="BigO__bigo_const2"*} ``` paulson@23449 ` 813` ```lemma (*bigo_const2 [intro]:*) "O(%x. c) <= O(%x. 1)" ``` paulson@23449 ` 814` ```by (metis bigo_const1 bigo_elt_subset); ``` paulson@23449 ` 815` paulson@24855 ` 816` ```lemma bigo_const2 [intro]: "O(%x. c::'b::ordered_idom) <= O(%x. 1)"; ``` paulson@23449 ` 817` ```(*??FAILS because the two occurrences of COMBK have different polymorphic types ``` paulson@23449 ` 818` ```proof (neg_clausify) ``` paulson@23449 ` 819` ```assume 0: "\ O(COMBK (c\'b\ordered_idom)) \ O(COMBK (1\'b\ordered_idom))" ``` paulson@23449 ` 820` ```have 1: "COMBK (c\'b\ordered_idom) \ O(COMBK (1\'b\ordered_idom))" ``` paulson@23449 ` 821` ```apply (rule notI) ``` paulson@23449 ` 822` ```apply (rule 0 [THEN notE]) ``` paulson@23449 ` 823` ```apply (rule bigo_elt_subset) ``` paulson@23449 ` 824` ```apply assumption; ``` paulson@23449 ` 825` ```sorry ``` paulson@23449 ` 826` ``` by (metis 0 bigo_elt_subset) loops?? ``` paulson@23449 ` 827` ```show "False" ``` paulson@23449 ` 828` ``` by (metis 1 bigo_const1) ``` paulson@23449 ` 829` ```qed ``` paulson@23449 ` 830` ```*) ``` paulson@23449 ` 831` ``` apply (rule bigo_elt_subset) ``` paulson@23449 ` 832` ``` apply (rule bigo_const1) ``` paulson@23449 ` 833` ```done ``` paulson@23449 ` 834` wenzelm@26483 ` 835` ```ML_command{*ResAtp.problem_name := "BigO__bigo_const3"*} ``` paulson@23449 ` 836` ```lemma bigo_const3: "(c::'a::ordered_field) ~= 0 ==> (%x. 1) : O(%x. c)" ``` paulson@23449 ` 837` ```apply (simp add: bigo_def) ``` paulson@23449 ` 838` ```proof (neg_clausify) ``` paulson@23449 ` 839` ```assume 0: "(c\'a\ordered_field) \ (0\'a\ordered_field)" ``` paulson@23519 ` 840` ```assume 1: "\A\'a\ordered_field. \ (1\'a\ordered_field) \ A * \c\'a\ordered_field\" ``` paulson@23449 ` 841` ```have 2: "(0\'a\ordered_field) = \c\'a\ordered_field\ \ ``` paulson@23449 ` 842` ```\ (1\'a\ordered_field) \ (1\'a\ordered_field)" ``` paulson@23449 ` 843` ``` by (metis 1 field_inverse) ``` paulson@23449 ` 844` ```have 3: "\c\'a\ordered_field\ = (0\'a\ordered_field)" ``` paulson@23519 ` 845` ``` by (metis linorder_neq_iff linorder_antisym_conv1 2) ``` paulson@23449 ` 846` ```have 4: "(0\'a\ordered_field) = (c\'a\ordered_field)" ``` paulson@23519 ` 847` ``` by (metis 3 abs_eq_0) ``` paulson@23519 ` 848` ```show "False" ``` paulson@23519 ` 849` ``` by (metis 0 4) ``` paulson@23449 ` 850` ```qed ``` paulson@23449 ` 851` paulson@23449 ` 852` ```lemma bigo_const4: "(c::'a::ordered_field) ~= 0 ==> O(%x. 1) <= O(%x. c)" ``` paulson@23449 ` 853` ```by (rule bigo_elt_subset, rule bigo_const3, assumption) ``` paulson@23449 ` 854` paulson@23449 ` 855` ```lemma bigo_const [simp]: "(c::'a::ordered_field) ~= 0 ==> ``` paulson@23449 ` 856` ``` O(%x. c) = O(%x. 1)" ``` paulson@23449 ` 857` ```by (rule equalityI, rule bigo_const2, rule bigo_const4, assumption) ``` paulson@23449 ` 858` wenzelm@26483 ` 859` ```ML_command{*ResAtp.problem_name := "BigO__bigo_const_mult1"*} ``` paulson@23449 ` 860` ```lemma bigo_const_mult1: "(%x. c * f x) : O(f)" ``` paulson@24937 ` 861` ``` apply (simp add: bigo_def abs_mult) ``` paulson@23449 ` 862` ```proof (neg_clausify) ``` paulson@23449 ` 863` ```fix x ``` haftmann@25304 ` 864` ```assume 0: "\xa\'b\ordered_idom. ``` haftmann@25304 ` 865` ``` \ \c\'b\ordered_idom\ * ``` haftmann@25304 ` 866` ``` \(f\'a\type \ 'b\ordered_idom) ((x\'b\ordered_idom \ 'a\type) xa)\ ``` haftmann@25304 ` 867` ``` \ xa * \f (x xa)\" ``` paulson@24937 ` 868` ```show "False" ``` haftmann@25304 ` 869` ``` by (metis linorder_neq_iff linorder_antisym_conv1 0) ``` paulson@23449 ` 870` ```qed ``` paulson@23449 ` 871` paulson@23449 ` 872` ```lemma bigo_const_mult2: "O(%x. c * f x) <= O(f)" ``` paulson@23449 ` 873` ```by (rule bigo_elt_subset, rule bigo_const_mult1) ``` paulson@23449 ` 874` wenzelm@26483 ` 875` ```ML_command{*ResAtp.problem_name := "BigO__bigo_const_mult3"*} ``` paulson@23449 ` 876` ```lemma bigo_const_mult3: "(c::'a::ordered_field) ~= 0 ==> f : O(%x. c * f x)" ``` paulson@23449 ` 877` ``` apply (simp add: bigo_def) ``` paulson@24942 ` 878` ```(*sledgehammer [no luck]*); ``` paulson@23449 ` 879` ``` apply (rule_tac x = "abs(inverse c)" in exI) ``` paulson@23449 ` 880` ``` apply (simp only: abs_mult [symmetric] mult_assoc [symmetric]) ``` paulson@23449 ` 881` ```apply (subst left_inverse) ``` paulson@23449 ` 882` ```apply (auto ); ``` paulson@23449 ` 883` ```done ``` paulson@23449 ` 884` paulson@23449 ` 885` ```lemma bigo_const_mult4: "(c::'a::ordered_field) ~= 0 ==> ``` paulson@23449 ` 886` ``` O(f) <= O(%x. c * f x)" ``` paulson@23449 ` 887` ```by (rule bigo_elt_subset, rule bigo_const_mult3, assumption) ``` paulson@23449 ` 888` paulson@23449 ` 889` ```lemma bigo_const_mult [simp]: "(c::'a::ordered_field) ~= 0 ==> ``` paulson@23449 ` 890` ``` O(%x. c * f x) = O(f)" ``` paulson@23449 ` 891` ```by (rule equalityI, rule bigo_const_mult2, erule bigo_const_mult4) ``` paulson@23449 ` 892` wenzelm@26483 ` 893` ```ML_command{*ResAtp.problem_name := "BigO__bigo_const_mult5"*} ``` paulson@23449 ` 894` ```lemma bigo_const_mult5 [simp]: "(c::'a::ordered_field) ~= 0 ==> ``` paulson@23449 ` 895` ``` (%x. c) *o O(f) = O(f)" ``` paulson@23449 ` 896` ``` apply (auto del: subsetI) ``` paulson@23449 ` 897` ``` apply (rule order_trans) ``` paulson@23449 ` 898` ``` apply (rule bigo_mult2) ``` paulson@23449 ` 899` ``` apply (simp add: func_times) ``` paulson@23449 ` 900` ``` apply (auto intro!: subsetI simp add: bigo_def elt_set_times_def func_times) ``` paulson@23449 ` 901` ``` apply (rule_tac x = "%y. inverse c * x y" in exI) ``` paulson@24942 ` 902` ``` apply (rename_tac g d) ``` paulson@24942 ` 903` ``` apply safe ``` paulson@24942 ` 904` ``` apply (rule_tac [2] ext) ``` paulson@24942 ` 905` ``` prefer 2 ``` haftmann@26041 ` 906` ``` apply simp ``` paulson@24942 ` 907` ``` apply (simp add: mult_assoc [symmetric] abs_mult) ``` paulson@24942 ` 908` ``` (*couldn't get this proof without the step above; SLOW*) ``` haftmann@26041 ` 909` ``` apply (metis mult_assoc abs_ge_zero mult_left_mono) ``` paulson@23449 ` 910` ```done ``` paulson@23449 ` 911` paulson@23449 ` 912` wenzelm@26483 ` 913` ```ML_command{*ResAtp.problem_name := "BigO__bigo_const_mult6"*} ``` paulson@23449 ` 914` ```lemma bigo_const_mult6 [intro]: "(%x. c) *o O(f) <= O(f)" ``` paulson@23449 ` 915` ``` apply (auto intro!: subsetI ``` paulson@23449 ` 916` ``` simp add: bigo_def elt_set_times_def func_times ``` paulson@23449 ` 917` ``` simp del: abs_mult mult_ac) ``` paulson@23449 ` 918` ```(*sledgehammer*); ``` paulson@23449 ` 919` ``` apply (rule_tac x = "ca * (abs c)" in exI) ``` paulson@23449 ` 920` ``` apply (rule allI) ``` paulson@23449 ` 921` ``` apply (subgoal_tac "ca * abs(c) * abs(f x) = abs(c) * (ca * abs(f x))") ``` paulson@23449 ` 922` ``` apply (erule ssubst) ``` paulson@23449 ` 923` ``` apply (subst abs_mult) ``` paulson@23449 ` 924` ``` apply (rule mult_left_mono) ``` paulson@23449 ` 925` ``` apply (erule spec) ``` paulson@23449 ` 926` ``` apply simp ``` paulson@23449 ` 927` ``` apply(simp add: mult_ac) ``` paulson@23449 ` 928` ```done ``` paulson@23449 ` 929` paulson@23449 ` 930` ```lemma bigo_const_mult7 [intro]: "f =o O(g) ==> (%x. c * f x) =o O(g)" ``` paulson@23449 ` 931` ```proof - ``` paulson@23449 ` 932` ``` assume "f =o O(g)" ``` paulson@23449 ` 933` ``` then have "(%x. c) * f =o (%x. c) *o O(g)" ``` paulson@23449 ` 934` ``` by auto ``` paulson@23449 ` 935` ``` also have "(%x. c) * f = (%x. c * f x)" ``` paulson@23449 ` 936` ``` by (simp add: func_times) ``` paulson@23449 ` 937` ``` also have "(%x. c) *o O(g) <= O(g)" ``` paulson@23449 ` 938` ``` by (auto del: subsetI) ``` paulson@23449 ` 939` ``` finally show ?thesis . ``` paulson@23449 ` 940` ```qed ``` paulson@23449 ` 941` paulson@23449 ` 942` ```lemma bigo_compose1: "f =o O(g) ==> (%x. f(k x)) =o O(%x. g(k x))" ``` paulson@23449 ` 943` ```by (unfold bigo_def, auto) ``` paulson@23449 ` 944` paulson@23449 ` 945` ```lemma bigo_compose2: "f =o g +o O(h) ==> (%x. f(k x)) =o (%x. g(k x)) +o ``` paulson@23449 ` 946` ``` O(%x. h(k x))" ``` berghofe@26814 ` 947` ``` apply (simp only: set_minus_plus [symmetric] diff_minus fun_Compl_def ``` paulson@23449 ` 948` ``` func_plus) ``` paulson@23449 ` 949` ``` apply (erule bigo_compose1) ``` paulson@23449 ` 950` ```done ``` paulson@23449 ` 951` paulson@23449 ` 952` ```subsection {* Setsum *} ``` paulson@23449 ` 953` paulson@23449 ` 954` ```lemma bigo_setsum_main: "ALL x. ALL y : A x. 0 <= h x y ==> ``` paulson@23449 ` 955` ``` EX c. ALL x. ALL y : A x. abs(f x y) <= c * (h x y) ==> ``` paulson@23449 ` 956` ``` (%x. SUM y : A x. f x y) =o O(%x. SUM y : A x. h x y)" ``` paulson@23449 ` 957` ``` apply (auto simp add: bigo_def) ``` paulson@23449 ` 958` ``` apply (rule_tac x = "abs c" in exI) ``` paulson@23449 ` 959` ``` apply (subst abs_of_nonneg) back back ``` paulson@23449 ` 960` ``` apply (rule setsum_nonneg) ``` paulson@23449 ` 961` ``` apply force ``` paulson@23449 ` 962` ``` apply (subst setsum_right_distrib) ``` paulson@23449 ` 963` ``` apply (rule allI) ``` paulson@23449 ` 964` ``` apply (rule order_trans) ``` paulson@23449 ` 965` ``` apply (rule setsum_abs) ``` paulson@23449 ` 966` ``` apply (rule setsum_mono) ``` paulson@23449 ` 967` ```apply (blast intro: order_trans mult_right_mono abs_ge_self) ``` paulson@23449 ` 968` ```done ``` paulson@23449 ` 969` wenzelm@26483 ` 970` ```ML_command{*ResAtp.problem_name := "BigO__bigo_setsum1"*} ``` paulson@23449 ` 971` ```lemma bigo_setsum1: "ALL x y. 0 <= h x y ==> ``` paulson@23449 ` 972` ``` EX c. ALL x y. abs(f x y) <= c * (h x y) ==> ``` paulson@23449 ` 973` ``` (%x. SUM y : A x. f x y) =o O(%x. SUM y : A x. h x y)" ``` paulson@23449 ` 974` ``` apply (rule bigo_setsum_main) ``` paulson@23449 ` 975` ```(*sledgehammer*); ``` paulson@23449 ` 976` ``` apply force ``` paulson@23449 ` 977` ``` apply clarsimp ``` paulson@23449 ` 978` ``` apply (rule_tac x = c in exI) ``` paulson@23449 ` 979` ``` apply force ``` paulson@23449 ` 980` ```done ``` paulson@23449 ` 981` paulson@23449 ` 982` ```lemma bigo_setsum2: "ALL y. 0 <= h y ==> ``` paulson@23449 ` 983` ``` EX c. ALL y. abs(f y) <= c * (h y) ==> ``` paulson@23449 ` 984` ``` (%x. SUM y : A x. f y) =o O(%x. SUM y : A x. h y)" ``` paulson@23449 ` 985` ```by (rule bigo_setsum1, auto) ``` paulson@23449 ` 986` wenzelm@26483 ` 987` ```ML_command{*ResAtp.problem_name := "BigO__bigo_setsum3"*} ``` paulson@23449 ` 988` ```lemma bigo_setsum3: "f =o O(h) ==> ``` paulson@23449 ` 989` ``` (%x. SUM y : A x. (l x y) * f(k x y)) =o ``` paulson@23449 ` 990` ``` O(%x. SUM y : A x. abs(l x y * h(k x y)))" ``` paulson@23449 ` 991` ``` apply (rule bigo_setsum1) ``` paulson@23449 ` 992` ``` apply (rule allI)+ ``` paulson@23449 ` 993` ``` apply (rule abs_ge_zero) ``` paulson@23449 ` 994` ``` apply (unfold bigo_def) ``` paulson@23449 ` 995` ``` apply (auto simp add: abs_mult); ``` paulson@23449 ` 996` ```(*sledgehammer*); ``` paulson@23449 ` 997` ``` apply (rule_tac x = c in exI) ``` paulson@23449 ` 998` ``` apply (rule allI)+ ``` paulson@23449 ` 999` ``` apply (subst mult_left_commute) ``` paulson@23449 ` 1000` ``` apply (rule mult_left_mono) ``` paulson@23449 ` 1001` ``` apply (erule spec) ``` paulson@23449 ` 1002` ``` apply (rule abs_ge_zero) ``` paulson@23449 ` 1003` ```done ``` paulson@23449 ` 1004` paulson@23449 ` 1005` ```lemma bigo_setsum4: "f =o g +o O(h) ==> ``` paulson@23449 ` 1006` ``` (%x. SUM y : A x. l x y * f(k x y)) =o ``` paulson@23449 ` 1007` ``` (%x. SUM y : A x. l x y * g(k x y)) +o ``` paulson@23449 ` 1008` ``` O(%x. SUM y : A x. abs(l x y * h(k x y)))" ``` paulson@23449 ` 1009` ``` apply (rule set_minus_imp_plus) ``` berghofe@26814 ` 1010` ``` apply (subst fun_diff_def) ``` paulson@23449 ` 1011` ``` apply (subst setsum_subtractf [symmetric]) ``` paulson@23449 ` 1012` ``` apply (subst right_diff_distrib [symmetric]) ``` paulson@23449 ` 1013` ``` apply (rule bigo_setsum3) ``` berghofe@26814 ` 1014` ``` apply (subst fun_diff_def [symmetric]) ``` paulson@23449 ` 1015` ``` apply (erule set_plus_imp_minus) ``` paulson@23449 ` 1016` ```done ``` paulson@23449 ` 1017` wenzelm@26483 ` 1018` ```ML_command{*ResAtp.problem_name := "BigO__bigo_setsum5"*} ``` paulson@23449 ` 1019` ```lemma bigo_setsum5: "f =o O(h) ==> ALL x y. 0 <= l x y ==> ``` paulson@23449 ` 1020` ``` ALL x. 0 <= h x ==> ``` paulson@23449 ` 1021` ``` (%x. SUM y : A x. (l x y) * f(k x y)) =o ``` paulson@23449 ` 1022` ``` O(%x. SUM y : A x. (l x y) * h(k x y))" ``` paulson@23449 ` 1023` ``` apply (subgoal_tac "(%x. SUM y : A x. (l x y) * h(k x y)) = ``` paulson@23449 ` 1024` ``` (%x. SUM y : A x. abs((l x y) * h(k x y)))") ``` paulson@23449 ` 1025` ``` apply (erule ssubst) ``` paulson@23449 ` 1026` ``` apply (erule bigo_setsum3) ``` paulson@23449 ` 1027` ``` apply (rule ext) ``` paulson@23449 ` 1028` ``` apply (rule setsum_cong2) ``` paulson@23449 ` 1029` ``` apply (thin_tac "f \ O(h)") ``` paulson@24942 ` 1030` ```apply (metis abs_of_nonneg zero_le_mult_iff) ``` paulson@23449 ` 1031` ```done ``` paulson@23449 ` 1032` paulson@23449 ` 1033` ```lemma bigo_setsum6: "f =o g +o O(h) ==> ALL x y. 0 <= l x y ==> ``` paulson@23449 ` 1034` ``` ALL x. 0 <= h x ==> ``` paulson@23449 ` 1035` ``` (%x. SUM y : A x. (l x y) * f(k x y)) =o ``` paulson@23449 ` 1036` ``` (%x. SUM y : A x. (l x y) * g(k x y)) +o ``` paulson@23449 ` 1037` ``` O(%x. SUM y : A x. (l x y) * h(k x y))" ``` paulson@23449 ` 1038` ``` apply (rule set_minus_imp_plus) ``` berghofe@26814 ` 1039` ``` apply (subst fun_diff_def) ``` paulson@23449 ` 1040` ``` apply (subst setsum_subtractf [symmetric]) ``` paulson@23449 ` 1041` ``` apply (subst right_diff_distrib [symmetric]) ``` paulson@23449 ` 1042` ``` apply (rule bigo_setsum5) ``` berghofe@26814 ` 1043` ``` apply (subst fun_diff_def [symmetric]) ``` paulson@23449 ` 1044` ``` apply (drule set_plus_imp_minus) ``` paulson@23449 ` 1045` ``` apply auto ``` paulson@23449 ` 1046` ```done ``` paulson@23449 ` 1047` paulson@23449 ` 1048` ```subsection {* Misc useful stuff *} ``` paulson@23449 ` 1049` paulson@23449 ` 1050` ```lemma bigo_useful_intro: "A <= O(f) ==> B <= O(f) ==> ``` berghofe@26814 ` 1051` ``` A \ B <= O(f)" ``` paulson@23449 ` 1052` ``` apply (subst bigo_plus_idemp [symmetric]) ``` paulson@23449 ` 1053` ``` apply (rule set_plus_mono2) ``` paulson@23449 ` 1054` ``` apply assumption+ ``` paulson@23449 ` 1055` ```done ``` paulson@23449 ` 1056` paulson@23449 ` 1057` ```lemma bigo_useful_add: "f =o O(h) ==> g =o O(h) ==> f + g =o O(h)" ``` paulson@23449 ` 1058` ``` apply (subst bigo_plus_idemp [symmetric]) ``` paulson@23449 ` 1059` ``` apply (rule set_plus_intro) ``` paulson@23449 ` 1060` ``` apply assumption+ ``` paulson@23449 ` 1061` ```done ``` paulson@23449 ` 1062` ``` ``` paulson@23449 ` 1063` ```lemma bigo_useful_const_mult: "(c::'a::ordered_field) ~= 0 ==> ``` paulson@23449 ` 1064` ``` (%x. c) * f =o O(h) ==> f =o O(h)" ``` paulson@23449 ` 1065` ``` apply (rule subsetD) ``` paulson@23449 ` 1066` ``` apply (subgoal_tac "(%x. 1 / c) *o O(h) <= O(h)") ``` paulson@23449 ` 1067` ``` apply assumption ``` paulson@23449 ` 1068` ``` apply (rule bigo_const_mult6) ``` paulson@23449 ` 1069` ``` apply (subgoal_tac "f = (%x. 1 / c) * ((%x. c) * f)") ``` paulson@23449 ` 1070` ``` apply (erule ssubst) ``` paulson@23449 ` 1071` ``` apply (erule set_times_intro2) ``` paulson@23449 ` 1072` ``` apply (simp add: func_times) ``` paulson@23449 ` 1073` ```done ``` paulson@23449 ` 1074` wenzelm@26483 ` 1075` ```ML_command{*ResAtp.problem_name := "BigO__bigo_fix"*} ``` paulson@23449 ` 1076` ```lemma bigo_fix: "(%x. f ((x::nat) + 1)) =o O(%x. h(x + 1)) ==> f 0 = 0 ==> ``` paulson@23449 ` 1077` ``` f =o O(h)" ``` paulson@23449 ` 1078` ``` apply (simp add: bigo_alt_def) ``` paulson@23449 ` 1079` ```(*sledgehammer*); ``` paulson@23449 ` 1080` ``` apply clarify ``` paulson@23449 ` 1081` ``` apply (rule_tac x = c in exI) ``` paulson@23449 ` 1082` ``` apply safe ``` paulson@23449 ` 1083` ``` apply (case_tac "x = 0") ``` paulson@23816 ` 1084` ```apply (metis OrderedGroup.abs_ge_zero OrderedGroup.abs_zero order_less_le Ring_and_Field.split_mult_pos_le) ``` paulson@23449 ` 1085` ``` apply (subgoal_tac "x = Suc (x - 1)") ``` paulson@23816 ` 1086` ``` apply metis ``` paulson@23449 ` 1087` ``` apply simp ``` paulson@23449 ` 1088` ``` done ``` paulson@23449 ` 1089` paulson@23449 ` 1090` paulson@23449 ` 1091` ```lemma bigo_fix2: ``` paulson@23449 ` 1092` ``` "(%x. f ((x::nat) + 1)) =o (%x. g(x + 1)) +o O(%x. h(x + 1)) ==> ``` paulson@23449 ` 1093` ``` f 0 = g 0 ==> f =o g +o O(h)" ``` paulson@23449 ` 1094` ``` apply (rule set_minus_imp_plus) ``` paulson@23449 ` 1095` ``` apply (rule bigo_fix) ``` berghofe@26814 ` 1096` ``` apply (subst fun_diff_def) ``` berghofe@26814 ` 1097` ``` apply (subst fun_diff_def [symmetric]) ``` paulson@23449 ` 1098` ``` apply (rule set_plus_imp_minus) ``` paulson@23449 ` 1099` ``` apply simp ``` berghofe@26814 ` 1100` ``` apply (simp add: fun_diff_def) ``` paulson@23449 ` 1101` ```done ``` paulson@23449 ` 1102` paulson@23449 ` 1103` ```subsection {* Less than or equal to *} ``` paulson@23449 ` 1104` paulson@23449 ` 1105` ```constdefs ``` paulson@23449 ` 1106` ``` lesso :: "('a => 'b::ordered_idom) => ('a => 'b) => ('a => 'b)" ``` paulson@23449 ` 1107` ``` (infixl " ALL x. abs (g x) <= abs (f x) ==> ``` paulson@23449 ` 1111` ``` g =o O(h)" ``` paulson@23449 ` 1112` ``` apply (unfold bigo_def) ``` paulson@23449 ` 1113` ``` apply clarsimp ``` paulson@23449 ` 1114` ```apply (blast intro: order_trans) ``` paulson@23449 ` 1115` ```done ``` paulson@23449 ` 1116` paulson@23449 ` 1117` ```lemma bigo_lesseq2: "f =o O(h) ==> ALL x. abs (g x) <= f x ==> ``` paulson@23449 ` 1118` ``` g =o O(h)" ``` paulson@23449 ` 1119` ``` apply (erule bigo_lesseq1) ``` paulson@23449 ` 1120` ```apply (blast intro: abs_ge_self order_trans) ``` paulson@23449 ` 1121` ```done ``` paulson@23449 ` 1122` paulson@23449 ` 1123` ```lemma bigo_lesseq3: "f =o O(h) ==> ALL x. 0 <= g x ==> ALL x. g x <= f x ==> ``` paulson@23449 ` 1124` ``` g =o O(h)" ``` paulson@23449 ` 1125` ``` apply (erule bigo_lesseq2) ``` paulson@23449 ` 1126` ``` apply (rule allI) ``` paulson@23449 ` 1127` ``` apply (subst abs_of_nonneg) ``` paulson@23449 ` 1128` ``` apply (erule spec)+ ``` paulson@23449 ` 1129` ```done ``` paulson@23449 ` 1130` paulson@23449 ` 1131` ```lemma bigo_lesseq4: "f =o O(h) ==> ``` paulson@23449 ` 1132` ``` ALL x. 0 <= g x ==> ALL x. g x <= abs (f x) ==> ``` paulson@23449 ` 1133` ``` g =o O(h)" ``` paulson@23449 ` 1134` ``` apply (erule bigo_lesseq1) ``` paulson@23449 ` 1135` ``` apply (rule allI) ``` paulson@23449 ` 1136` ``` apply (subst abs_of_nonneg) ``` paulson@23449 ` 1137` ``` apply (erule spec)+ ``` paulson@23449 ` 1138` ```done ``` paulson@23449 ` 1139` wenzelm@26483 ` 1140` ```ML_command{*ResAtp.problem_name:="BigO__bigo_lesso1"*} ``` paulson@23449 ` 1141` ```lemma bigo_lesso1: "ALL x. f x <= g x ==> f ``` paulson@23449 ` 1154` ``` ALL x. 0 <= k x ==> ALL x. k x <= f x ==> ``` paulson@23449 ` 1155` ``` k A. k A \ f A" ``` paulson@24545 ` 1171` ```have 1: "\(X1\'b\ordered_idom) X2. \ max X1 X2 < X1" ``` paulson@24545 ` 1172` ``` by (metis linorder_not_less le_maxI1) (*sort inserted by hand*) ``` paulson@24545 ` 1173` ```assume 2: "(0\'b) \ k x - g x" ``` paulson@24545 ` 1174` ```have 3: "\ k x - g x < (0\'b)" ``` paulson@24545 ` 1175` ``` by (metis 2 linorder_not_less) ``` paulson@24545 ` 1176` ```have 4: "\X1 X2. min X1 (k X2) \ f X2" ``` paulson@24545 ` 1177` ``` 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) ``` paulson@24545 ` 1178` ```have 5: "\g x - f x\ = f x - g x" ``` paulson@24545 ` 1179` ``` 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) ``` paulson@24545 ` 1180` ```have 6: "max (0\'b) (k x - g x) = k x - g x" ``` paulson@24545 ` 1181` ``` by (metis min_max.less_eq_less_sup.le_iff_sup 2) ``` paulson@24545 ` 1182` ```assume 7: "\ max (k x - g x) (0\'b) \ \f x - g x\" ``` paulson@24545 ` 1183` ```have 8: "\ k x - g x \ f x - g x" ``` paulson@24545 ` 1184` ``` by (metis 5 abs_minus_commute 7 min_max.less_eq_less_sup.sup_commute 6) ``` paulson@24545 ` 1185` ```show "False" ``` paulson@24545 ` 1186` ``` 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) ``` paulson@24545 ` 1187` ```qed ``` paulson@23449 ` 1188` wenzelm@26483 ` 1189` ```ML_command{*ResAtp.problem_name := "BigO__bigo_lesso3"*} ``` paulson@23449 ` 1190` ```lemma bigo_lesso3: "f =o g +o O(h) ==> ``` paulson@23449 ` 1191` ``` ALL x. 0 <= k x ==> ALL x. g x <= k x ==> ``` paulson@23449 ` 1192` ``` f 'b::ordered_field) ==> ``` paulson@23449 ` 1213` ``` g =o h +o O(k) ==> f ``` paulson@23449 ` 1228` ``` EX C. ALL x. f x <= g x + C * abs(h x)" ``` paulson@23449 ` 1229` ``` apply (simp only: lesso_def bigo_alt_def) ``` paulson@23449 ` 1230` ``` apply clarsimp ``` paulson@24855 ` 1231` ``` apply (metis abs_if abs_mult add_commute diff_le_eq less_not_permute) ``` paulson@23449 ` 1232` ```done ``` paulson@23449 ` 1233` paulson@23449 ` 1234` ```end ```