src/HOL/Library/Function_Growth.thy
author wenzelm
Fri, 22 Jul 2016 11:00:43 +0200
changeset 63540 f8652d0534fa
parent 63060 293ede07b775
permissions -rw-r--r--
tuned proofs -- avoid unstructured calculation;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
61833
c601d3c76362 modernized
haftmann
parents: 61831
diff changeset
     1
  
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
     2
(* Author: Florian Haftmann, TU Muenchen *)
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
     3
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
     4
section \<open>Comparing growth of functions on natural numbers by a preorder relation\<close>
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
     5
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
     6
theory Function_Growth
51542
738598beeb26 tuned imports;
wenzelm
parents: 51264
diff changeset
     7
imports Main Preorder Discrete
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
     8
begin
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
     9
61831
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    10
(* FIXME move *)
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    11
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    12
context linorder
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    13
begin
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    14
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    15
lemma mono_invE:
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    16
  fixes f :: "'a \<Rightarrow> 'b::order"
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    17
  assumes "mono f"
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    18
  assumes "f x < f y"
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    19
  obtains "x < y"
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    20
proof
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    21
  show "x < y"
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    22
  proof (rule ccontr)
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    23
    assume "\<not> x < y"
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    24
    then have "y \<le> x" by simp
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    25
    with \<open>mono f\<close> obtain "f y \<le> f x" by (rule monoE)
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    26
    with \<open>f x < f y\<close> show False by simp
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    27
  qed
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    28
qed
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    29
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    30
end
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    31
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    32
lemma (in semidom_divide) power_diff:
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    33
  fixes a :: 'a
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    34
  assumes "a \<noteq> 0"
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    35
  assumes "m \<ge> n"
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    36
  shows "a ^ (m - n) = (a ^ m) div (a ^ n)"
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    37
proof -
63040
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 61975
diff changeset
    38
  define q where "q = m - n"
63540
f8652d0534fa tuned proofs -- avoid unstructured calculation;
wenzelm
parents: 63060
diff changeset
    39
  with assms have "m = q + n" by (simp add: q_def)
f8652d0534fa tuned proofs -- avoid unstructured calculation;
wenzelm
parents: 63060
diff changeset
    40
  with q_def show ?thesis using \<open>a \<noteq> 0\<close> by (simp add: power_add)
61831
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    41
qed
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    42
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
    43
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
    44
subsection \<open>Motivation\<close>
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
    45
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
    46
text \<open>
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
    47
  When comparing growth of functions in computer science, it is common to adhere
51264
aba03f0c6254 fixed document;
wenzelm
parents: 51263
diff changeset
    48
  on Landau Symbols (``O-Notation'').  However these come at the cost of notational
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
    49
  oddities, particularly writing \<open>f = O(g)\<close> for \<open>f \<in> O(g)\<close> etc.
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
    50
  
59113
3cded6b57a82 tuned spelling;
wenzelm
parents: 58881
diff changeset
    51
  Here we suggest a different way, following Hardy (G.~H.~Hardy and J.~E.~Littlewood,
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
    52
  Some problems of Diophantine approximation, Acta Mathematica 37 (1914), p.~225).
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
    53
  We establish a quasi order relation \<open>\<lesssim>\<close> on functions such that
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
    54
  \<open>f \<lesssim> g \<longleftrightarrow> f \<in> O(g)\<close>.  From a didactic point of view, this does not only
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
    55
  avoid the notational oddities mentioned above but also emphasizes the key insight
59113
3cded6b57a82 tuned spelling;
wenzelm
parents: 58881
diff changeset
    56
  of a growth hierarchy of functions:
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
    57
  \<open>(\<lambda>n. 0) \<lesssim> (\<lambda>n. k) \<lesssim> Discrete.log \<lesssim> Discrete.sqrt \<lesssim> id \<lesssim> \<dots>\<close>.
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
    58
\<close>
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
    59
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
    60
subsection \<open>Model\<close>
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
    61
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
    62
text \<open>
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
    63
  Our growth functions are of type \<open>\<nat> \<Rightarrow> \<nat>\<close>.  This is different
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
    64
  to the usual conventions for Landau symbols for which \<open>\<real> \<Rightarrow> \<real>\<close>
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
    65
  would be appropriate, but we argue that \<open>\<real> \<Rightarrow> \<real>\<close> is more
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
    66
  appropriate for analysis, whereas our setting is discrete.
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
    67
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
    68
  Note that we also restrict the additional coefficients to \<open>\<nat>\<close>, something
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
    69
  we discuss at the particular definitions.
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
    70
\<close>
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
    71
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
    72
subsection \<open>The \<open>\<lesssim>\<close> relation\<close>
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
    73
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
    74
definition less_eq_fun :: "(nat \<Rightarrow> nat) \<Rightarrow> (nat \<Rightarrow> nat) \<Rightarrow> bool" (infix "\<lesssim>" 50)
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
    75
where
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
    76
  "f \<lesssim> g \<longleftrightarrow> (\<exists>c>0. \<exists>n. \<forall>m>n. f m \<le> c * g m)"
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
    77
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
    78
text \<open>
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
    79
  This yields \<open>f \<lesssim> g \<longleftrightarrow> f \<in> O(g)\<close>.  Note that \<open>c\<close> is restricted to
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
    80
  \<open>\<nat>\<close>.  This does not pose any problems since if \<open>f \<in> O(g)\<close> holds for
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
    81
  a \<open>c \<in> \<real>\<close>, it also holds for \<open>\<lceil>c\<rceil> \<in> \<nat>\<close> by transitivity.
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
    82
\<close>
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
    83
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
    84
lemma less_eq_funI [intro?]:
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
    85
  assumes "\<exists>c>0. \<exists>n. \<forall>m>n. f m \<le> c * g m"
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
    86
  shows "f \<lesssim> g"
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
    87
  unfolding less_eq_fun_def by (rule assms)
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
    88
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
    89
lemma not_less_eq_funI:
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
    90
  assumes "\<And>c n. c > 0 \<Longrightarrow> \<exists>m>n. c * g m < f m"
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
    91
  shows "\<not> f \<lesssim> g"
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
    92
  using assms unfolding less_eq_fun_def linorder_not_le [symmetric] by blast
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
    93
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
    94
lemma less_eq_funE [elim?]:
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
    95
  assumes "f \<lesssim> g"
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
    96
  obtains n c where "c > 0" and "\<And>m. m > n \<Longrightarrow> f m \<le> c * g m"
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
    97
  using assms unfolding less_eq_fun_def by blast
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
    98
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
    99
lemma not_less_eq_funE:
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   100
  assumes "\<not> f \<lesssim> g" and "c > 0"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   101
  obtains m where "m > n" and "c * g m < f m"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   102
  using assms unfolding less_eq_fun_def linorder_not_le [symmetric] by blast
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   103
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   104
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
   105
subsection \<open>The \<open>\<approx>\<close> relation, the equivalence relation induced by \<open>\<lesssim>\<close>\<close>
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   106
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   107
definition equiv_fun :: "(nat \<Rightarrow> nat) \<Rightarrow> (nat \<Rightarrow> nat) \<Rightarrow> bool" (infix "\<cong>" 50)
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   108
where
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   109
  "f \<cong> g \<longleftrightarrow>
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   110
    (\<exists>c\<^sub>1>0. \<exists>c\<^sub>2>0. \<exists>n. \<forall>m>n. f m \<le> c\<^sub>1 * g m \<and> g m \<le> c\<^sub>2 * f m)"
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   111
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
   112
text \<open>
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
   113
  This yields \<open>f \<cong> g \<longleftrightarrow> f \<in> \<Theta>(g)\<close>.  Concerning \<open>c\<^sub>1\<close> and \<open>c\<^sub>2\<close>
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
   114
  restricted to @{typ nat}, see note above on \<open>(\<lesssim>)\<close>.
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
   115
\<close>
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   116
61831
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   117
lemma equiv_funI:
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   118
  assumes "\<exists>c\<^sub>1>0. \<exists>c\<^sub>2>0. \<exists>n. \<forall>m>n. f m \<le> c\<^sub>1 * g m \<and> g m \<le> c\<^sub>2 * f m"
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   119
  shows "f \<cong> g"
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   120
  unfolding equiv_fun_def by (rule assms)
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   121
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   122
lemma not_equiv_funI:
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   123
  assumes "\<And>c\<^sub>1 c\<^sub>2 n. c\<^sub>1 > 0 \<Longrightarrow> c\<^sub>2 > 0 \<Longrightarrow>
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   124
    \<exists>m>n. c\<^sub>1 * f m < g m \<or> c\<^sub>2 * g m < f m"
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   125
  shows "\<not> f \<cong> g"
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   126
  using assms unfolding equiv_fun_def linorder_not_le [symmetric] by blast
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   127
61831
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   128
lemma equiv_funE:
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   129
  assumes "f \<cong> g"
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   130
  obtains n c\<^sub>1 c\<^sub>2 where "c\<^sub>1 > 0" and "c\<^sub>2 > 0"
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   131
    and "\<And>m. m > n \<Longrightarrow> f m \<le> c\<^sub>1 * g m \<and> g m \<le> c\<^sub>2 * f m"
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   132
  using assms unfolding equiv_fun_def by blast
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   133
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   134
lemma not_equiv_funE:
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   135
  fixes n c\<^sub>1 c\<^sub>2
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   136
  assumes "\<not> f \<cong> g" and "c\<^sub>1 > 0" and "c\<^sub>2 > 0"
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   137
  obtains m where "m > n"
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   138
    and "c\<^sub>1 * f m < g m \<or> c\<^sub>2 * g m < f m"
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   139
  using assms unfolding equiv_fun_def linorder_not_le [symmetric] by blast
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   140
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   141
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
   142
subsection \<open>The \<open>\<prec>\<close> relation, the strict part of \<open>\<lesssim>\<close>\<close>
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   143
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   144
definition less_fun :: "(nat \<Rightarrow> nat) \<Rightarrow> (nat \<Rightarrow> nat) \<Rightarrow> bool" (infix "\<prec>" 50)
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   145
where
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   146
  "f \<prec> g \<longleftrightarrow> f \<lesssim> g \<and> \<not> g \<lesssim> f"
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   147
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   148
lemma less_funI:
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   149
  assumes "\<exists>c>0. \<exists>n. \<forall>m>n. f m \<le> c * g m"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   150
    and "\<And>c n. c > 0 \<Longrightarrow> \<exists>m>n. c * f m < g m"
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   151
  shows "f \<prec> g"
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   152
  using assms unfolding less_fun_def less_eq_fun_def linorder_not_less [symmetric] by blast
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   153
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   154
lemma not_less_funI:
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   155
  assumes "\<And>c n. c > 0 \<Longrightarrow> \<exists>m>n. c * g m < f m"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   156
    and "\<exists>c>0. \<exists>n. \<forall>m>n. g m \<le> c * f m"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   157
  shows "\<not> f \<prec> g"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   158
  using assms unfolding less_fun_def less_eq_fun_def linorder_not_less [symmetric] by blast
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   159
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   160
lemma less_funE [elim?]:
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   161
  assumes "f \<prec> g"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   162
  obtains n c where "c > 0" and "\<And>m. m > n \<Longrightarrow> f m \<le> c * g m"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   163
    and "\<And>c n. c > 0 \<Longrightarrow> \<exists>m>n. c * f m < g m"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   164
proof -
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   165
  from assms have "f \<lesssim> g" and "\<not> g \<lesssim> f" by (simp_all add: less_fun_def)
63060
293ede07b775 some uses of 'obtain' with structure statement;
wenzelm
parents: 63040
diff changeset
   166
  from \<open>f \<lesssim> g\<close> obtain n c where *:"c > 0" "m > n \<Longrightarrow> f m \<le> c * g m" for m
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   167
    by (rule less_eq_funE) blast
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   168
  { fix c n :: nat
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   169
    assume "c > 0"
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
   170
    with \<open>\<not> g \<lesssim> f\<close> obtain m where "m > n" "c * f m < g m"
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   171
      by (rule not_less_eq_funE) blast
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   172
    then have **: "\<exists>m>n. c * f m < g m" by blast
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   173
  } note ** = this
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   174
  from * ** show thesis by (rule that)
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   175
qed
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   176
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   177
lemma not_less_funE:
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   178
  assumes "\<not> f \<prec> g" and "c > 0"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   179
  obtains m where "m > n" and "c * g m < f m"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   180
    | d q where "\<And>m. d > 0 \<Longrightarrow> m > q \<Longrightarrow> g q \<le> d * f q"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   181
  using assms unfolding less_fun_def linorder_not_less [symmetric] by blast
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   182
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
   183
text \<open>
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
   184
  I did not find a proof for \<open>f \<prec> g \<longleftrightarrow> f \<in> o(g)\<close>.  Maybe this only
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
   185
  holds if \<open>f\<close> and/or \<open>g\<close> are of a certain class of functions.
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
   186
  However \<open>f \<in> o(g) \<longrightarrow> f \<prec> g\<close> is provable, and this yields a
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   187
  handy introduction rule.
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   188
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
   189
  Note that D. Knuth ignores \<open>o\<close> altogether.  So what \dots
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   190
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
   191
  Something still has to be said about the coefficient \<open>c\<close> in
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
   192
  the definition of \<open>(\<prec>)\<close>.  In the typical definition of \<open>o\<close>,
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
   193
  it occurs on the \emph{right} hand side of the \<open>(>)\<close>.  The reason
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
   194
  is that the situation is dual to the definition of \<open>O\<close>: the definition
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
   195
  works since \<open>c\<close> may become arbitrary small.  Since this is not possible
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   196
  within @{term \<nat>}, we push the coefficient to the left hand side instead such
61831
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   197
  that it may become arbitrary big instead.
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
   198
\<close>
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   199
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   200
lemma less_fun_strongI:
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   201
  assumes "\<And>c. c > 0 \<Longrightarrow> \<exists>n. \<forall>m>n. c * f m < g m"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   202
  shows "f \<prec> g"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   203
proof (rule less_funI)
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   204
  have "1 > (0::nat)" by simp
63060
293ede07b775 some uses of 'obtain' with structure statement;
wenzelm
parents: 63040
diff changeset
   205
  with assms [OF this] obtain n where *: "m > n \<Longrightarrow> 1 * f m < g m" for m
293ede07b775 some uses of 'obtain' with structure statement;
wenzelm
parents: 63040
diff changeset
   206
    by blast
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   207
  have "\<forall>m>n. f m \<le> 1 * g m"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   208
  proof (rule allI, rule impI)
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   209
    fix m
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   210
    assume "m > n"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   211
    with * have "1 * f m < g m" by simp
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   212
    then show "f m \<le> 1 * g m" by simp
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   213
  qed
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
   214
  with \<open>1 > 0\<close> show "\<exists>c>0. \<exists>n. \<forall>m>n. f m \<le> c * g m" by blast
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   215
  fix c n :: nat
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   216
  assume "c > 0"
63060
293ede07b775 some uses of 'obtain' with structure statement;
wenzelm
parents: 63040
diff changeset
   217
  with assms obtain q where "m > q \<Longrightarrow> c * f m < g m" for m by blast
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   218
  then have "c * f (Suc (q + n)) < g (Suc (q + n))" by simp
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   219
  moreover have "Suc (q + n) > n" by simp
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   220
  ultimately show "\<exists>m>n. c * f m < g m" by blast
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   221
qed
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   222
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   223
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
   224
subsection \<open>\<open>\<lesssim>\<close> is a preorder\<close>
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   225
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61566
diff changeset
   226
text \<open>This yields all lemmas relating \<open>\<lesssim>\<close>, \<open>\<prec>\<close> and \<open>\<cong>\<close>.\<close>
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   227
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   228
interpretation fun_order: preorder_equiv less_eq_fun less_fun
61831
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   229
  rewrites "fun_order.equiv = equiv_fun"
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   230
proof -
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   231
  interpret preorder: preorder_equiv less_eq_fun less_fun
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   232
  proof
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   233
    fix f g h
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   234
    show "f \<lesssim> f"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   235
    proof
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   236
      have "\<exists>n. \<forall>m>n. f m \<le> 1 * f m" by auto
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   237
      then show "\<exists>c>0. \<exists>n. \<forall>m>n. f m \<le> c * f m" by blast
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   238
    qed
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   239
    show "f \<prec> g \<longleftrightarrow> f \<lesssim> g \<and> \<not> g \<lesssim> f"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   240
      by (fact less_fun_def)
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   241
    assume "f \<lesssim> g" and "g \<lesssim> h"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   242
    show "f \<lesssim> h"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   243
    proof
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
   244
      from \<open>f \<lesssim> g\<close> obtain n\<^sub>1 c\<^sub>1
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   245
        where "c\<^sub>1 > 0" and P\<^sub>1: "\<And>m. m > n\<^sub>1 \<Longrightarrow> f m \<le> c\<^sub>1 * g m"
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   246
        by rule blast
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
   247
      from \<open>g \<lesssim> h\<close> obtain n\<^sub>2 c\<^sub>2
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   248
        where "c\<^sub>2 > 0" and P\<^sub>2: "\<And>m. m > n\<^sub>2 \<Longrightarrow> g m \<le> c\<^sub>2 * h m"
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   249
        by rule blast
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   250
      have "\<forall>m>max n\<^sub>1 n\<^sub>2. f m \<le> (c\<^sub>1 * c\<^sub>2) * h m"
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   251
      proof (rule allI, rule impI)
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   252
        fix m
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   253
        assume Q: "m > max n\<^sub>1 n\<^sub>2"
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   254
        from P\<^sub>1 Q have *: "f m \<le> c\<^sub>1 * g m" by simp
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   255
        from P\<^sub>2 Q have "g m \<le> c\<^sub>2 * h m" by simp
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
   256
        with \<open>c\<^sub>1 > 0\<close> have "c\<^sub>1 * g m \<le> (c\<^sub>1 * c\<^sub>2) * h m" by simp
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   257
        with * show "f m \<le> (c\<^sub>1 * c\<^sub>2) * h m" by (rule order_trans)
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   258
      qed
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   259
      then have "\<exists>n. \<forall>m>n. f m \<le> (c\<^sub>1 * c\<^sub>2) * h m" by rule
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
   260
      moreover from \<open>c\<^sub>1 > 0\<close> \<open>c\<^sub>2 > 0\<close> have "c\<^sub>1 * c\<^sub>2 > 0" by simp
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   261
      ultimately show "\<exists>c>0. \<exists>n. \<forall>m>n. f m \<le> c * h m" by blast
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   262
    qed
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   263
  qed
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   264
  from preorder.preorder_equiv_axioms show "class.preorder_equiv less_eq_fun less_fun" .
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   265
  show "preorder_equiv.equiv less_eq_fun = equiv_fun"
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   266
  proof (rule ext, rule ext, unfold preorder.equiv_def)
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   267
    fix f g
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   268
    show "f \<lesssim> g \<and> g \<lesssim> f \<longleftrightarrow> f \<cong> g"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   269
    proof
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   270
      assume "f \<cong> g"
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   271
      then obtain n c\<^sub>1 c\<^sub>2 where "c\<^sub>1 > 0" and "c\<^sub>2 > 0"
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   272
        and *: "\<And>m. m > n \<Longrightarrow> f m \<le> c\<^sub>1 * g m \<and> g m \<le> c\<^sub>2 * f m"
61831
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   273
        by (rule equiv_funE) blast
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   274
      have "\<forall>m>n. f m \<le> c\<^sub>1 * g m"
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   275
      proof (rule allI, rule impI)
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   276
        fix m
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   277
        assume "m > n"
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   278
        with * show "f m \<le> c\<^sub>1 * g m" by simp
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   279
      qed
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
   280
      with \<open>c\<^sub>1 > 0\<close> have "\<exists>c>0. \<exists>n. \<forall>m>n. f m \<le> c * g m" by blast
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   281
      then have "f \<lesssim> g" ..
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   282
      have "\<forall>m>n. g m \<le> c\<^sub>2 * f m"
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   283
      proof (rule allI, rule impI)
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   284
        fix m
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   285
        assume "m > n"
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   286
        with * show "g m \<le> c\<^sub>2 * f m" by simp
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   287
      qed
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
   288
      with \<open>c\<^sub>2 > 0\<close> have "\<exists>c>0. \<exists>n. \<forall>m>n. g m \<le> c * f m" by blast
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   289
      then have "g \<lesssim> f" ..
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
   290
      from \<open>f \<lesssim> g\<close> and \<open>g \<lesssim> f\<close> show "f \<lesssim> g \<and> g \<lesssim> f" ..
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   291
    next
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   292
      assume "f \<lesssim> g \<and> g \<lesssim> f"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   293
      then have "f \<lesssim> g" and "g \<lesssim> f" by auto
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
   294
      from \<open>f \<lesssim> g\<close> obtain n\<^sub>1 c\<^sub>1 where "c\<^sub>1 > 0"
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   295
        and P\<^sub>1: "\<And>m. m > n\<^sub>1 \<Longrightarrow> f m \<le> c\<^sub>1 * g m" by rule blast
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
   296
      from \<open>g \<lesssim> f\<close> obtain n\<^sub>2 c\<^sub>2 where "c\<^sub>2 > 0"
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   297
        and P\<^sub>2: "\<And>m. m > n\<^sub>2 \<Longrightarrow> g m \<le> c\<^sub>2 * f m" by rule blast
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   298
      have "\<forall>m>max n\<^sub>1 n\<^sub>2. f m \<le> c\<^sub>1 * g m \<and> g m \<le> c\<^sub>2 * f m"
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   299
      proof (rule allI, rule impI)
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   300
        fix m
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   301
        assume Q: "m > max n\<^sub>1 n\<^sub>2"
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   302
        from P\<^sub>1 Q have "f m \<le> c\<^sub>1 * g m" by simp
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   303
        moreover from P\<^sub>2 Q have "g m \<le> c\<^sub>2 * f m" by simp
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   304
        ultimately show "f m \<le> c\<^sub>1 * g m \<and> g m \<le> c\<^sub>2 * f m" ..
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   305
      qed
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
   306
      with \<open>c\<^sub>1 > 0\<close> \<open>c\<^sub>2 > 0\<close> have "\<exists>c\<^sub>1>0. \<exists>c\<^sub>2>0. \<exists>n.
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   307
        \<forall>m>n. f m \<le> c\<^sub>1 * g m \<and> g m \<le> c\<^sub>2 * f m" by blast
61831
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   308
      then show "f \<cong> g" by (rule equiv_funI)
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   309
    qed
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   310
  qed
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   311
qed
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   312
61831
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   313
declare fun_order.antisym [intro?]
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   314
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   315
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
   316
subsection \<open>Simple examples\<close>
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   317
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
   318
text \<open>
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   319
  Most of these are left as constructive exercises for the reader.  Note that additional
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   320
  preconditions to the functions may be necessary.  The list here is by no means to be
59113
3cded6b57a82 tuned spelling;
wenzelm
parents: 58881
diff changeset
   321
  intended as complete construction set for typical functions, here surely something
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   322
  has to be added yet.
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
   323
\<close>
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   324
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
   325
text \<open>@{prop "(\<lambda>n. f n + k) \<cong> f"}\<close>
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   326
61831
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   327
lemma equiv_fun_mono_const:
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   328
  assumes "mono f" and "\<exists>n. f n > 0"
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   329
  shows "(\<lambda>n. f n + k) \<cong> f"
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   330
proof (cases "k = 0")
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   331
  case True then show ?thesis by simp
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   332
next
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   333
  case False
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   334
  show ?thesis
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   335
  proof
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   336
    show "(\<lambda>n. f n + k) \<lesssim> f"
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   337
    proof
61975
b4b11391c676 isabelle update_cartouches -c -t;
wenzelm
parents: 61833
diff changeset
   338
      from \<open>\<exists>n. f n > 0\<close> obtain n where "f n > 0" ..
61831
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   339
      have "\<forall>m>n. f m + k \<le> Suc k * f m"
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   340
      proof (rule allI, rule impI)
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   341
        fix m
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   342
        assume "n < m"
61975
b4b11391c676 isabelle update_cartouches -c -t;
wenzelm
parents: 61833
diff changeset
   343
        with \<open>mono f\<close> have "f n \<le> f m"
61831
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   344
          using less_imp_le_nat monoE by blast
61975
b4b11391c676 isabelle update_cartouches -c -t;
wenzelm
parents: 61833
diff changeset
   345
        with  \<open>0 < f n\<close> have "0 < f m" by auto
61831
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   346
        then obtain l where "f m = Suc l" by (cases "f m") simp_all
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   347
        then show "f m + k \<le> Suc k * f m" by simp
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   348
      qed
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   349
      then show "\<exists>c>0. \<exists>n. \<forall>m>n. f m + k \<le> c * f m" by blast
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   350
    qed
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   351
    show "f \<lesssim> (\<lambda>n. f n + k)"
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   352
    proof
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   353
      have "f m \<le> 1 * (f m + k)" for m by simp
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   354
      then show "\<exists>c>0. \<exists>n. \<forall>m>n. f m \<le> c * (f m + k)" by blast
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   355
    qed
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   356
  qed
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   357
qed
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   358
61831
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   359
lemma
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   360
  assumes "strict_mono f"
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   361
  shows "(\<lambda>n. f n + k) \<cong> f"
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   362
proof (rule equiv_fun_mono_const)
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   363
  from assms show "mono f" by (rule strict_mono_mono)
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   364
  show "\<exists>n. 0 < f n"
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   365
  proof (rule ccontr)
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   366
    assume "\<not> (\<exists>n. 0 < f n)"
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   367
    then have "\<And>n. f n = 0" by simp
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   368
    then have "f 0 = f 1" by simp
61975
b4b11391c676 isabelle update_cartouches -c -t;
wenzelm
parents: 61833
diff changeset
   369
    moreover from \<open>strict_mono f\<close> have "f 0 < f 1"
61831
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   370
      by (simp add: strict_mono_def) 
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   371
    ultimately show False by simp
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   372
  qed
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   373
qed
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   374
  
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   375
lemma
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   376
  "(\<lambda>n. Suc k * f n) \<cong> f"
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   377
proof
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   378
  show "(\<lambda>n. Suc k * f n) \<lesssim> f"
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   379
  proof
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   380
    have "Suc k * f m \<le> Suc k * f m" for m by simp
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   381
    then show "\<exists>c>0. \<exists>n. \<forall>m>n. Suc k * f m \<le> c * f m" by blast
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   382
  qed
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   383
  show "f \<lesssim> (\<lambda>n. Suc k * f n)"
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   384
  proof
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   385
    have "f m \<le> 1 * (Suc k * f m)" for m by simp
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   386
    then show "\<exists>c>0. \<exists>n. \<forall>m>n. f m \<le> c * (Suc k * f m)" by blast
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   387
  qed
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   388
qed
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   389
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   390
lemma
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   391
  "f \<lesssim> (\<lambda>n. f n + g n)"
51264
aba03f0c6254 fixed document;
wenzelm
parents: 51263
diff changeset
   392
  by rule auto
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   393
61831
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   394
lemma
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   395
  "(\<lambda>_. 0) \<prec> (\<lambda>n. Suc k)"
51264
aba03f0c6254 fixed document;
wenzelm
parents: 51263
diff changeset
   396
  by (rule less_fun_strongI) auto
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   397
61831
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   398
lemma
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   399
  "(\<lambda>_. k) \<prec> Discrete.log"
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   400
proof (rule less_fun_strongI)
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   401
  fix c :: nat
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   402
  have "\<forall>m>2 ^ (Suc (c * k)). c * k < Discrete.log m"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   403
  proof (rule allI, rule impI)
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   404
    fix m :: nat
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   405
    assume "2 ^ Suc (c * k) < m"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   406
    then have "2 ^ Suc (c * k) \<le> m" by simp
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   407
    with log_mono have "Discrete.log (2 ^ (Suc (c * k))) \<le> Discrete.log m"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   408
      by (blast dest: monoD)
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   409
    moreover have "c * k < Discrete.log (2 ^ (Suc (c * k)))" by simp
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   410
    ultimately show "c * k < Discrete.log m" by auto
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   411
  qed
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   412
  then show "\<exists>n. \<forall>m>n. c * k < Discrete.log m" ..
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   413
qed
61831
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   414
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   415
(*lemma
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   416
  "Discrete.log \<prec> Discrete.sqrt"
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   417
proof (rule less_fun_strongI)*)
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
   418
text \<open>@{prop "Discrete.log \<prec> Discrete.sqrt"}\<close>
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   419
61831
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   420
lemma
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   421
  "Discrete.sqrt \<prec> id"
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   422
proof (rule less_fun_strongI)
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   423
  fix c :: nat
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   424
  assume "0 < c"
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   425
  have "\<forall>m>(Suc c)\<^sup>2. c * Discrete.sqrt m < id m"
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   426
  proof (rule allI, rule impI)
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   427
    fix m
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   428
    assume "(Suc c)\<^sup>2 < m"
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   429
    then have "(Suc c)\<^sup>2 \<le> m" by simp
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 51542
diff changeset
   430
    with mono_sqrt have "Discrete.sqrt ((Suc c)\<^sup>2) \<le> Discrete.sqrt m" by (rule monoE)
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   431
    then have "Suc c \<le> Discrete.sqrt m" by simp
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   432
    then have "c < Discrete.sqrt m" by simp
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
   433
    moreover from \<open>(Suc c)\<^sup>2 < m\<close> have "Discrete.sqrt m > 0" by simp
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   434
    ultimately have "c * Discrete.sqrt m < Discrete.sqrt m * Discrete.sqrt m" by simp
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   435
    also have "\<dots> \<le> m" by (simp add: power2_eq_square [symmetric])
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   436
    finally show "c * Discrete.sqrt m < id m" by simp
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   437
  qed
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   438
  then show "\<exists>n. \<forall>m>n. c * Discrete.sqrt m < id m" ..
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   439
qed
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   440
61831
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   441
lemma
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   442
  "id \<prec> (\<lambda>n. n\<^sup>2)"
51264
aba03f0c6254 fixed document;
wenzelm
parents: 51263
diff changeset
   443
  by (rule less_fun_strongI) (auto simp add: power2_eq_square)
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   444
61831
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   445
lemma
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   446
  "(\<lambda>n. n ^ k) \<prec> (\<lambda>n. n ^ Suc k)"
51264
aba03f0c6254 fixed document;
wenzelm
parents: 51263
diff changeset
   447
  by (rule less_fun_strongI) auto
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 41413
diff changeset
   448
61831
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   449
(*lemma 
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   450
  "(\<lambda>n. n ^ k) \<prec> (\<lambda>n. 2 ^ n)"
c43f87119d80 modernized
haftmann
parents: 61585
diff changeset
   451
proof (rule less_fun_strongI)*)
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59113
diff changeset
   452
text \<open>@{prop "(\<lambda>n. n ^ k) \<prec> (\<lambda>n. 2 ^ n)"}\<close>
31381
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   453
b3a785a69538 added Landau theory
haftmann
parents:
diff changeset
   454
end