9 imports SetsAndFunctions |
9 imports SetsAndFunctions |
10 begin |
10 begin |
11 |
11 |
12 text {* |
12 text {* |
13 This library is designed to support asymptotic ``big O'' calculations, |
13 This library is designed to support asymptotic ``big O'' calculations, |
14 i.e.~reasoning with expressions of the form $f = O(g)$ and $f = g + O(h)$. |
14 i.e.~reasoning with expressions of the form $f = O(g)$ and $f = g + |
15 An earlier version of this library is described in detail in |
15 O(h)$. An earlier version of this library is described in detail in |
16 \begin{quote} |
16 \cite{Avigad-Donnelly}. |
17 Avigad, Jeremy, and Kevin Donnelly, \emph{Formalizing O notation in |
17 |
18 Isabelle/HOL}, in David Basin and Micha\"el Rusiowitch, editors, |
|
19 \emph{Automated Reasoning: second international conference, IJCAR 2004}, |
|
20 Springer, 357--371, 2004. |
|
21 \end{quote} |
|
22 The main changes in this version are as follows: |
18 The main changes in this version are as follows: |
23 \begin{itemize} |
19 \begin{itemize} |
24 \item We have eliminated the $O$ operator on sets. (Most uses of this seem |
20 \item We have eliminated the @{text O} operator on sets. (Most uses of this seem |
25 to be inessential.) |
21 to be inessential.) |
26 \item We no longer use $+$ as output syntax for $+o$. |
22 \item We no longer use @{text "+"} as output syntax for @{text "+o"} |
27 \item Lemmas involving ``sumr'' have been replaced by more general lemmas |
23 \item Lemmas involving @{text "sumr"} have been replaced by more general lemmas |
28 involving ``setsum''. |
24 involving `@{text "setsum"}. |
29 \item The library has been expanded, with e.g.~support for expressions of |
25 \item The library has been expanded, with e.g.~support for expressions of |
30 the form $f < g + O(h)$. |
26 the form @{text "f < g + O(h)"}. |
31 \end{itemize} |
27 \end{itemize} |
32 Note that two lemmas at the end of this file are commented out, as they |
28 |
33 require the HOL-Complex library. |
29 See \verb,Complex/ex/BigO_Complex.thy, for additional lemmas that |
34 |
30 require the \verb,HOL-Complex, logic image. |
35 Note also since the Big O library includes rules that demonstrate set |
31 |
36 inclusion, to use the automated reasoners effectively with the library one |
32 Note also since the Big O library includes rules that demonstrate set |
37 should redeclare the theorem ``subsetI'' as an intro rule, rather than as |
33 inclusion, to use the automated reasoners effectively with the library |
38 an intro! rule, for example, using ``declare subsetI [del, intro]''. |
34 one should redeclare the theorem @{text "subsetI"} as an intro rule, |
|
35 rather than as an @{text "intro!"} rule, for example, using |
|
36 \isa{\isakeyword{declare}}~@{text "subsetI [del, intro]"}. |
39 *} |
37 *} |
40 |
38 |
41 subsection {* Definitions *} |
39 subsection {* Definitions *} |
42 |
40 |
43 constdefs |
41 constdefs |
579 lemma bigo_setsum_main: "ALL x. ALL y : A x. 0 <= h x y ==> |
577 lemma bigo_setsum_main: "ALL x. ALL y : A x. 0 <= h x y ==> |
580 EX c. ALL x. ALL y : A x. abs(f x y) <= c * (h x y) ==> |
578 EX c. ALL x. ALL y : A x. abs(f x y) <= c * (h x y) ==> |
581 (%x. SUM y : A x. f x y) =o O(%x. SUM y : A x. h x y)" |
579 (%x. SUM y : A x. f x y) =o O(%x. SUM y : A x. h x y)" |
582 apply (auto simp add: bigo_def) |
580 apply (auto simp add: bigo_def) |
583 apply (rule_tac x = "abs c" in exI) |
581 apply (rule_tac x = "abs c" in exI) |
584 apply (subst abs_of_nonneg);back;back |
582 apply (subst abs_of_nonneg) back back |
585 apply (rule setsum_nonneg) |
583 apply (rule setsum_nonneg) |
586 apply force |
584 apply force |
587 apply (subst setsum_mult) |
585 apply (subst setsum_mult) |
588 apply (rule allI) |
586 apply (rule allI) |
589 apply (rule order_trans) |
587 apply (rule order_trans) |
800 apply (rule allI) |
798 apply (rule allI) |
801 apply (subst func_diff) |
799 apply (subst func_diff) |
802 apply (case_tac "0 <= k x - g x") |
800 apply (case_tac "0 <= k x - g x") |
803 apply simp |
801 apply simp |
804 apply (subst abs_of_nonneg) |
802 apply (subst abs_of_nonneg) |
805 apply (drule_tac x = x in spec)back |
803 apply (drule_tac x = x in spec) back |
806 apply (simp add: compare_rls) |
804 apply (simp add: compare_rls) |
807 apply (subst diff_minus)+ |
805 apply (subst diff_minus)+ |
808 apply (rule add_right_mono) |
806 apply (rule add_right_mono) |
809 apply (erule spec) |
807 apply (erule spec) |
810 apply (rule order_trans) |
808 apply (rule order_trans) |
824 apply (rule allI) |
822 apply (rule allI) |
825 apply (subst func_diff) |
823 apply (subst func_diff) |
826 apply (case_tac "0 <= f x - k x") |
824 apply (case_tac "0 <= f x - k x") |
827 apply simp |
825 apply simp |
828 apply (subst abs_of_nonneg) |
826 apply (subst abs_of_nonneg) |
829 apply (drule_tac x = x in spec)back |
827 apply (drule_tac x = x in spec) back |
830 apply (simp add: compare_rls) |
828 apply (simp add: compare_rls) |
831 apply (subst diff_minus)+ |
829 apply (subst diff_minus)+ |
832 apply (rule add_left_mono) |
830 apply (rule add_left_mono) |
833 apply (rule le_imp_neg_le) |
831 apply (rule le_imp_neg_le) |
834 apply (erule spec) |
832 apply (erule spec) |
840 |
838 |
841 lemma bigo_lesso4: "f <o g =o O(k::'a=>'b::ordered_field) ==> |
839 lemma bigo_lesso4: "f <o g =o O(k::'a=>'b::ordered_field) ==> |
842 g =o h +o O(k) ==> f <o h =o O(k)" |
840 g =o h +o O(k) ==> f <o h =o O(k)" |
843 apply (unfold lesso_def) |
841 apply (unfold lesso_def) |
844 apply (drule set_plus_imp_minus) |
842 apply (drule set_plus_imp_minus) |
845 apply (drule bigo_abs5)back |
843 apply (drule bigo_abs5) back |
846 apply (simp add: func_diff) |
844 apply (simp add: func_diff) |
847 apply (drule bigo_useful_add) |
845 apply (drule bigo_useful_add) |
848 apply assumption |
846 apply assumption |
849 apply (erule bigo_lesseq2)back |
847 apply (erule bigo_lesseq2) back |
850 apply (rule allI) |
848 apply (rule allI) |
851 apply (auto simp add: func_plus func_diff compare_rls |
849 apply (auto simp add: func_plus func_diff compare_rls |
852 split: split_max abs_split) |
850 split: split_max abs_split) |
853 done |
851 done |
854 |
852 |
873 apply assumption |
871 apply assumption |
874 apply (force split: split_max) |
872 apply (force split: split_max) |
875 apply (auto split: split_max simp add: func_plus) |
873 apply (auto split: split_max simp add: func_plus) |
876 done |
874 done |
877 |
875 |
878 (* |
|
879 These last two lemmas require the HOL-Complex library. |
|
880 |
|
881 lemma bigo_LIMSEQ1: "f =o O(g) ==> g ----> 0 ==> f ----> 0" |
|
882 apply (simp add: LIMSEQ_def bigo_alt_def) |
|
883 apply clarify |
|
884 apply (drule_tac x = "r / c" in spec) |
|
885 apply (drule mp) |
|
886 apply (erule divide_pos_pos) |
|
887 apply assumption |
|
888 apply clarify |
|
889 apply (rule_tac x = no in exI) |
|
890 apply (rule allI) |
|
891 apply (drule_tac x = n in spec)+ |
|
892 apply (rule impI) |
|
893 apply (drule mp) |
|
894 apply assumption |
|
895 apply (rule order_le_less_trans) |
|
896 apply assumption |
|
897 apply (rule order_less_le_trans) |
|
898 apply (subgoal_tac "c * abs(g n) < c * (r / c)") |
|
899 apply assumption |
|
900 apply (erule mult_strict_left_mono) |
|
901 apply assumption |
|
902 apply simp |
|
903 done |
|
904 |
|
905 lemma bigo_LIMSEQ2: "f =o g +o O(h) ==> h ----> 0 ==> f ----> a |
|
906 ==> g ----> a" |
|
907 apply (drule set_plus_imp_minus) |
|
908 apply (drule bigo_LIMSEQ1) |
|
909 apply assumption |
|
910 apply (simp only: func_diff) |
|
911 apply (erule LIMSEQ_diff_approach_zero2) |
|
912 apply assumption |
|
913 done |
|
914 |
|
915 *) |
|
916 |
|
917 end |
876 end |