src/HOL/Metis_Examples/Big_O.thy
author wenzelm
Sat, 07 Apr 2012 16:41:59 +0200
changeset 47389 e8552cba702d
parent 47108 2a1953f0d20d
child 47445 69e96e5500df
permissions -rw-r--r--
explicit checks stable_finished_theory/stable_command allow parallel asynchronous command transactions; tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43197
c71657bbdbc0 tuned Metis examples
blanchet
parents: 42103
diff changeset
     1
(*  Title:      HOL/Metis_Examples/Big_O.thy
c71657bbdbc0 tuned Metis examples
blanchet
parents: 42103
diff changeset
     2
    Author:     Lawrence C. Paulson, Cambridge University Computer Laboratory
41144
509e51b7509a example tuning
blanchet
parents: 39259
diff changeset
     3
    Author:     Jasmin Blanchette, TU Muenchen
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
     4
43197
c71657bbdbc0 tuned Metis examples
blanchet
parents: 42103
diff changeset
     5
Metis example featuring the Big O notation.
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
     6
*)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
     7
43197
c71657bbdbc0 tuned Metis examples
blanchet
parents: 42103
diff changeset
     8
header {* Metis Example Featuring the Big O Notation *}
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
     9
43197
c71657bbdbc0 tuned Metis examples
blanchet
parents: 42103
diff changeset
    10
theory Big_O
41413
64cd30d6b0b8 explicit file specifications -- avoid secondary load path;
wenzelm
parents: 41144
diff changeset
    11
imports
64cd30d6b0b8 explicit file specifications -- avoid secondary load path;
wenzelm
parents: 41144
diff changeset
    12
  "~~/src/HOL/Decision_Procs/Dense_Linear_Order"
64cd30d6b0b8 explicit file specifications -- avoid secondary load path;
wenzelm
parents: 41144
diff changeset
    13
  "~~/src/HOL/Library/Function_Algebras"
64cd30d6b0b8 explicit file specifications -- avoid secondary load path;
wenzelm
parents: 41144
diff changeset
    14
  "~~/src/HOL/Library/Set_Algebras"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    15
begin
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    16
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    17
subsection {* Definitions *}
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    18
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46644
diff changeset
    19
definition bigo :: "('a => 'b\<Colon>linordered_idom) => ('a => 'b) set" ("(1O'(_'))") where
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
    20
  "O(f\<Colon>('a => 'b)) == {h. \<exists>c. \<forall>x. abs (h x) <= c * abs (f x)}"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    21
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
    22
lemma bigo_pos_const:
46364
abab10d1f4a3 example tuning
blanchet
parents: 45705
diff changeset
    23
  "(\<exists>c\<Colon>'a\<Colon>linordered_idom.
abab10d1f4a3 example tuning
blanchet
parents: 45705
diff changeset
    24
    \<forall>x. abs (h x) \<le> c * abs (f x))
abab10d1f4a3 example tuning
blanchet
parents: 45705
diff changeset
    25
    \<longleftrightarrow> (\<exists>c. 0 < c \<and> (\<forall>x. abs(h x) \<le> c * abs (f x)))"
abab10d1f4a3 example tuning
blanchet
parents: 45705
diff changeset
    26
by (metis (no_types) abs_ge_zero
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
    27
      comm_semiring_1_class.normalizing_semiring_rules(7) mult.comm_neutral
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
    28
      mult_nonpos_nonneg not_leE order_trans zero_less_one)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    29
36407
d733c1a624f4 renamed option
blanchet
parents: 36067
diff changeset
    30
(*** Now various verions with an increasing shrink factor ***)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    31
36925
ffad77bb3046 renamed Sledgehammer options
blanchet
parents: 36844
diff changeset
    32
sledgehammer_params [isar_proof, isar_shrink_factor = 1]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    33
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
    34
lemma
46364
abab10d1f4a3 example tuning
blanchet
parents: 45705
diff changeset
    35
  "(\<exists>c\<Colon>'a\<Colon>linordered_idom.
abab10d1f4a3 example tuning
blanchet
parents: 45705
diff changeset
    36
    \<forall>x. abs (h x) \<le> c * abs (f x))
abab10d1f4a3 example tuning
blanchet
parents: 45705
diff changeset
    37
    \<longleftrightarrow> (\<exists>c. 0 < c \<and> (\<forall>x. abs(h x) \<le> c * abs (f x)))"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    38
  apply auto
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    39
  apply (case_tac "c = 0", simp)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    40
  apply (rule_tac x = "1" in exI, simp)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    41
  apply (rule_tac x = "abs c" in exI, auto)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    42
proof -
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    43
  fix c :: 'a and x :: 'b
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    44
  assume A1: "\<forall>x. \<bar>h x\<bar> \<le> c * \<bar>f x\<bar>"
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    45
  have F1: "\<forall>x\<^isub>1\<Colon>'a\<Colon>linordered_idom. 0 \<le> \<bar>x\<^isub>1\<bar>" by (metis abs_ge_zero)
36844
5f9385ecc1a7 Removed usage of normalizating locales.
hoelzl
parents: 36725
diff changeset
    46
  have F2: "\<forall>x\<^isub>1\<Colon>'a\<Colon>linordered_idom. 1 * x\<^isub>1 = x\<^isub>1" by (metis mult_1)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    47
  have F3: "\<forall>x\<^isub>1 x\<^isub>3. x\<^isub>3 \<le> \<bar>h x\<^isub>1\<bar> \<longrightarrow> x\<^isub>3 \<le> c * \<bar>f x\<^isub>1\<bar>" by (metis A1 order_trans)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    48
  have F4: "\<forall>x\<^isub>2 x\<^isub>3\<Colon>'a\<Colon>linordered_idom. \<bar>x\<^isub>3\<bar> * \<bar>x\<^isub>2\<bar> = \<bar>x\<^isub>3 * x\<^isub>2\<bar>"
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    49
    by (metis abs_mult)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    50
  have F5: "\<forall>x\<^isub>3 x\<^isub>1\<Colon>'a\<Colon>linordered_idom. 0 \<le> x\<^isub>1 \<longrightarrow> \<bar>x\<^isub>3 * x\<^isub>1\<bar> = \<bar>x\<^isub>3\<bar> * x\<^isub>1"
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    51
    by (metis abs_mult_pos)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    52
  hence "\<forall>x\<^isub>1\<ge>0. \<bar>x\<^isub>1\<Colon>'a\<Colon>linordered_idom\<bar> = \<bar>1\<bar> * x\<^isub>1" by (metis F2)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    53
  hence "\<forall>x\<^isub>1\<ge>0. \<bar>x\<^isub>1\<Colon>'a\<Colon>linordered_idom\<bar> = x\<^isub>1" by (metis F2 abs_one)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    54
  hence "\<forall>x\<^isub>3. 0 \<le> \<bar>h x\<^isub>3\<bar> \<longrightarrow> \<bar>c * \<bar>f x\<^isub>3\<bar>\<bar> = c * \<bar>f x\<^isub>3\<bar>" by (metis F3)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    55
  hence "\<forall>x\<^isub>3. \<bar>c * \<bar>f x\<^isub>3\<bar>\<bar> = c * \<bar>f x\<^isub>3\<bar>" by (metis F1)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    56
  hence "\<forall>x\<^isub>3. (0\<Colon>'a) \<le> \<bar>f x\<^isub>3\<bar> \<longrightarrow> c * \<bar>f x\<^isub>3\<bar> = \<bar>c\<bar> * \<bar>f x\<^isub>3\<bar>" by (metis F5)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    57
  hence "\<forall>x\<^isub>3. (0\<Colon>'a) \<le> \<bar>f x\<^isub>3\<bar> \<longrightarrow> c * \<bar>f x\<^isub>3\<bar> = \<bar>c * f x\<^isub>3\<bar>" by (metis F4)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    58
  hence "\<forall>x\<^isub>3. c * \<bar>f x\<^isub>3\<bar> = \<bar>c * f x\<^isub>3\<bar>" by (metis F1)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    59
  hence "\<bar>h x\<bar> \<le> \<bar>c * f x\<bar>" by (metis A1)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    60
  thus "\<bar>h x\<bar> \<le> \<bar>c\<bar> * \<bar>f x\<bar>" by (metis F4)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    61
qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    62
36925
ffad77bb3046 renamed Sledgehammer options
blanchet
parents: 36844
diff changeset
    63
sledgehammer_params [isar_proof, isar_shrink_factor = 2]
25710
4cdf7de81e1b Replaced refs by config params; finer critical section in mets method
paulson
parents: 25592
diff changeset
    64
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
    65
lemma
46364
abab10d1f4a3 example tuning
blanchet
parents: 45705
diff changeset
    66
  "(\<exists>c\<Colon>'a\<Colon>linordered_idom.
abab10d1f4a3 example tuning
blanchet
parents: 45705
diff changeset
    67
    \<forall>x. abs (h x) \<le> c * abs (f x))
abab10d1f4a3 example tuning
blanchet
parents: 45705
diff changeset
    68
    \<longleftrightarrow> (\<exists>c. 0 < c \<and> (\<forall>x. abs(h x) \<le> c * abs (f x)))"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    69
  apply auto
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    70
  apply (case_tac "c = 0", simp)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    71
  apply (rule_tac x = "1" in exI, simp)
36844
5f9385ecc1a7 Removed usage of normalizating locales.
hoelzl
parents: 36725
diff changeset
    72
  apply (rule_tac x = "abs c" in exI, auto)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    73
proof -
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    74
  fix c :: 'a and x :: 'b
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    75
  assume A1: "\<forall>x. \<bar>h x\<bar> \<le> c * \<bar>f x\<bar>"
36844
5f9385ecc1a7 Removed usage of normalizating locales.
hoelzl
parents: 36725
diff changeset
    76
  have F1: "\<forall>x\<^isub>1\<Colon>'a\<Colon>linordered_idom. 1 * x\<^isub>1 = x\<^isub>1" by (metis mult_1)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    77
  have F2: "\<forall>x\<^isub>2 x\<^isub>3\<Colon>'a\<Colon>linordered_idom. \<bar>x\<^isub>3\<bar> * \<bar>x\<^isub>2\<bar> = \<bar>x\<^isub>3 * x\<^isub>2\<bar>"
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    78
    by (metis abs_mult)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    79
  have "\<forall>x\<^isub>1\<ge>0. \<bar>x\<^isub>1\<Colon>'a\<Colon>linordered_idom\<bar> = x\<^isub>1" by (metis F1 abs_mult_pos abs_one)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    80
  hence "\<forall>x\<^isub>3. \<bar>c * \<bar>f x\<^isub>3\<bar>\<bar> = c * \<bar>f x\<^isub>3\<bar>" by (metis A1 abs_ge_zero order_trans)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    81
  hence "\<forall>x\<^isub>3. 0 \<le> \<bar>f x\<^isub>3\<bar> \<longrightarrow> c * \<bar>f x\<^isub>3\<bar> = \<bar>c * f x\<^isub>3\<bar>" by (metis F2 abs_mult_pos)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    82
  hence "\<bar>h x\<bar> \<le> \<bar>c * f x\<bar>" by (metis A1 abs_ge_zero)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    83
  thus "\<bar>h x\<bar> \<le> \<bar>c\<bar> * \<bar>f x\<bar>" by (metis F2)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    84
qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    85
36925
ffad77bb3046 renamed Sledgehammer options
blanchet
parents: 36844
diff changeset
    86
sledgehammer_params [isar_proof, isar_shrink_factor = 3]
25710
4cdf7de81e1b Replaced refs by config params; finer critical section in mets method
paulson
parents: 25592
diff changeset
    87
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
    88
lemma
46364
abab10d1f4a3 example tuning
blanchet
parents: 45705
diff changeset
    89
  "(\<exists>c\<Colon>'a\<Colon>linordered_idom.
abab10d1f4a3 example tuning
blanchet
parents: 45705
diff changeset
    90
    \<forall>x. abs (h x) \<le> c * abs (f x))
abab10d1f4a3 example tuning
blanchet
parents: 45705
diff changeset
    91
    \<longleftrightarrow> (\<exists>c. 0 < c \<and> (\<forall>x. abs(h x) \<le> c * abs (f x)))"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    92
  apply auto
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    93
  apply (case_tac "c = 0", simp)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    94
  apply (rule_tac x = "1" in exI, simp)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    95
  apply (rule_tac x = "abs c" in exI, auto)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    96
proof -
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    97
  fix c :: 'a and x :: 'b
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    98
  assume A1: "\<forall>x. \<bar>h x\<bar> \<le> c * \<bar>f x\<bar>"
36844
5f9385ecc1a7 Removed usage of normalizating locales.
hoelzl
parents: 36725
diff changeset
    99
  have F1: "\<forall>x\<^isub>1\<Colon>'a\<Colon>linordered_idom. 1 * x\<^isub>1 = x\<^isub>1" by (metis mult_1)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   100
  have F2: "\<forall>x\<^isub>3 x\<^isub>1\<Colon>'a\<Colon>linordered_idom. 0 \<le> x\<^isub>1 \<longrightarrow> \<bar>x\<^isub>3 * x\<^isub>1\<bar> = \<bar>x\<^isub>3\<bar> * x\<^isub>1" by (metis abs_mult_pos)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   101
  hence "\<forall>x\<^isub>1\<ge>0. \<bar>x\<^isub>1\<Colon>'a\<Colon>linordered_idom\<bar> = x\<^isub>1" by (metis F1 abs_one)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   102
  hence "\<forall>x\<^isub>3. 0 \<le> \<bar>f x\<^isub>3\<bar> \<longrightarrow> c * \<bar>f x\<^isub>3\<bar> = \<bar>c\<bar> * \<bar>f x\<^isub>3\<bar>" by (metis F2 A1 abs_ge_zero order_trans)
46644
bd03e0890699 rephrase some slow "metis" calls
blanchet
parents: 46369
diff changeset
   103
  thus "\<bar>h x\<bar> \<le> \<bar>c\<bar> * \<bar>f x\<bar>" by (metis A1 abs_ge_zero)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   104
qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   105
36925
ffad77bb3046 renamed Sledgehammer options
blanchet
parents: 36844
diff changeset
   106
sledgehammer_params [isar_proof, isar_shrink_factor = 4]
24545
f406a5744756 new proofs found
paulson
parents: 23816
diff changeset
   107
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   108
lemma
46364
abab10d1f4a3 example tuning
blanchet
parents: 45705
diff changeset
   109
  "(\<exists>c\<Colon>'a\<Colon>linordered_idom.
abab10d1f4a3 example tuning
blanchet
parents: 45705
diff changeset
   110
    \<forall>x. abs (h x) \<le> c * abs (f x))
abab10d1f4a3 example tuning
blanchet
parents: 45705
diff changeset
   111
    \<longleftrightarrow> (\<exists>c. 0 < c \<and> (\<forall>x. abs(h x) \<le> c * abs (f x)))"
24545
f406a5744756 new proofs found
paulson
parents: 23816
diff changeset
   112
  apply auto
f406a5744756 new proofs found
paulson
parents: 23816
diff changeset
   113
  apply (case_tac "c = 0", simp)
f406a5744756 new proofs found
paulson
parents: 23816
diff changeset
   114
  apply (rule_tac x = "1" in exI, simp)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   115
  apply (rule_tac x = "abs c" in exI, auto)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   116
proof -
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   117
  fix c :: 'a and x :: 'b
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   118
  assume A1: "\<forall>x. \<bar>h x\<bar> \<le> c * \<bar>f x\<bar>"
36844
5f9385ecc1a7 Removed usage of normalizating locales.
hoelzl
parents: 36725
diff changeset
   119
  have "\<forall>x\<^isub>1\<Colon>'a\<Colon>linordered_idom. 1 * x\<^isub>1 = x\<^isub>1" by (metis mult_1)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   120
  hence "\<forall>x\<^isub>3. \<bar>c * \<bar>f x\<^isub>3\<bar>\<bar> = c * \<bar>f x\<^isub>3\<bar>"
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   121
    by (metis A1 abs_ge_zero order_trans abs_mult_pos abs_one)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   122
  hence "\<bar>h x\<bar> \<le> \<bar>c * f x\<bar>" by (metis A1 abs_ge_zero abs_mult_pos abs_mult)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   123
  thus "\<bar>h x\<bar> \<le> \<bar>c\<bar> * \<bar>f x\<bar>" by (metis abs_mult)
24545
f406a5744756 new proofs found
paulson
parents: 23816
diff changeset
   124
qed
f406a5744756 new proofs found
paulson
parents: 23816
diff changeset
   125
36925
ffad77bb3046 renamed Sledgehammer options
blanchet
parents: 36844
diff changeset
   126
sledgehammer_params [isar_proof, isar_shrink_factor = 1]
24545
f406a5744756 new proofs found
paulson
parents: 23816
diff changeset
   127
46364
abab10d1f4a3 example tuning
blanchet
parents: 45705
diff changeset
   128
lemma bigo_alt_def: "O(f) = {h. \<exists>c. (0 < c \<and> (\<forall>x. abs (h x) <= c * abs (f x)))}"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   129
by (auto simp add: bigo_def bigo_pos_const)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   130
46364
abab10d1f4a3 example tuning
blanchet
parents: 45705
diff changeset
   131
lemma bigo_elt_subset [intro]: "f : O(g) \<Longrightarrow> O(f) \<le> O(g)"
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   132
apply (auto simp add: bigo_alt_def)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   133
apply (rule_tac x = "ca * c" in exI)
46364
abab10d1f4a3 example tuning
blanchet
parents: 45705
diff changeset
   134
by (metis comm_semiring_1_class.normalizing_semiring_rules(7,19)
abab10d1f4a3 example tuning
blanchet
parents: 45705
diff changeset
   135
          mult_le_cancel_left_pos order_trans mult_pos_pos)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   136
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   137
lemma bigo_refl [intro]: "f : O(f)"
46364
abab10d1f4a3 example tuning
blanchet
parents: 45705
diff changeset
   138
unfolding bigo_def mem_Collect_eq
36844
5f9385ecc1a7 Removed usage of normalizating locales.
hoelzl
parents: 36725
diff changeset
   139
by (metis mult_1 order_refl)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   140
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   141
lemma bigo_zero: "0 : O(g)"
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   142
apply (auto simp add: bigo_def func_zero)
36844
5f9385ecc1a7 Removed usage of normalizating locales.
hoelzl
parents: 36725
diff changeset
   143
by (metis mult_zero_left order_refl)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   144
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   145
lemma bigo_zero2: "O(\<lambda>x. 0) = {\<lambda>x. 0}"
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   146
by (auto simp add: bigo_def)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   147
43197
c71657bbdbc0 tuned Metis examples
blanchet
parents: 42103
diff changeset
   148
lemma bigo_plus_self_subset [intro]:
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   149
  "O(f) \<oplus> O(f) <= O(f)"
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   150
apply (auto simp add: bigo_alt_def set_plus_def)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   151
apply (rule_tac x = "c + ca" in exI)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   152
apply auto
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   153
apply (simp add: ring_distribs func_plus)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   154
by (metis order_trans abs_triangle_ineq add_mono)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   155
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   156
lemma bigo_plus_idemp [simp]: "O(f) \<oplus> O(f) = O(f)"
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   157
by (metis bigo_plus_self_subset bigo_zero set_eq_subset set_zero_plus2)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   158
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   159
lemma bigo_plus_subset [intro]: "O(f + g) <= O(f) \<oplus> O(g)"
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   160
apply (rule subsetI)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   161
apply (auto simp add: bigo_def bigo_pos_const func_plus set_plus_def)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   162
apply (subst bigo_pos_const [symmetric])+
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   163
apply (rule_tac x = "\<lambda>n. if abs (g n) <= (abs (f n)) then x n else 0" in exI)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   164
apply (rule conjI)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   165
 apply (rule_tac x = "c + c" in exI)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   166
 apply clarsimp
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   167
 apply auto
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   168
  apply (subgoal_tac "c * abs (f xa + g xa) <= (c + c) * abs (f xa)")
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   169
   apply (metis mult_2 order_trans)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   170
  apply (subgoal_tac "c * abs (f xa + g xa) <= c * (abs (f xa) + abs (g xa))")
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   171
   apply (erule order_trans)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   172
   apply (simp add: ring_distribs)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   173
  apply (rule mult_left_mono)
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   174
   apply (simp add: abs_triangle_ineq)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   175
  apply (simp add: order_less_le)
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   176
 apply (rule mult_nonneg_nonneg)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   177
  apply auto
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   178
apply (rule_tac x = "\<lambda>n. if (abs (f n)) < abs (g n) then x n else 0" in exI)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   179
apply (rule conjI)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   180
 apply (rule_tac x = "c + c" in exI)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   181
 apply auto
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   182
 apply (subgoal_tac "c * abs (f xa + g xa) <= (c + c) * abs (g xa)")
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46644
diff changeset
   183
  apply (metis order_trans mult_2)
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   184
 apply (subgoal_tac "c * abs (f xa + g xa) <= c * (abs (f xa) + abs (g xa))")
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   185
  apply (erule order_trans)
23477
f4b83f03cac9 tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents: 23464
diff changeset
   186
  apply (simp add: ring_distribs)
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   187
 apply (metis abs_triangle_ineq mult_le_cancel_left_pos)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   188
by (metis abs_ge_zero abs_of_pos zero_le_mult_iff)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   189
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   190
lemma bigo_plus_subset2 [intro]: "A <= O(f) \<Longrightarrow> B <= O(f) \<Longrightarrow> A \<oplus> B <= O(f)"
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   191
by (metis bigo_plus_idemp set_plus_mono2)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   192
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   193
lemma bigo_plus_eq: "\<forall>x. 0 <= f x \<Longrightarrow> \<forall>x. 0 <= g x \<Longrightarrow> O(f + g) = O(f) \<oplus> O(g)"
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   194
apply (rule equalityI)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   195
apply (rule bigo_plus_subset)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   196
apply (simp add: bigo_alt_def set_plus_def func_plus)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   197
apply clarify
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   198
(* sledgehammer *)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   199
apply (rule_tac x = "max c ca" in exI)
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   200
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   201
apply (rule conjI)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   202
 apply (metis less_max_iff_disj)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   203
apply clarify
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   204
apply (drule_tac x = "xa" in spec)+
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   205
apply (subgoal_tac "0 <= f xa + g xa")
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   206
 apply (simp add: ring_distribs)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   207
 apply (subgoal_tac "abs (a xa + b xa) <= abs (a xa) + abs (b xa)")
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   208
  apply (subgoal_tac "abs (a xa) + abs (b xa) <=
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   209
           max c ca * f xa + max c ca * g xa")
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   210
   apply (metis order_trans)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   211
  defer 1
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   212
  apply (metis abs_triangle_ineq)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   213
 apply (metis add_nonneg_nonneg)
46644
bd03e0890699 rephrase some slow "metis" calls
blanchet
parents: 46369
diff changeset
   214
apply (rule add_mono)
bd03e0890699 rephrase some slow "metis" calls
blanchet
parents: 46369
diff changeset
   215
 apply (metis le_maxI2 linorder_linear min_max.sup_absorb1 mult_right_mono xt1(6))
bd03e0890699 rephrase some slow "metis" calls
blanchet
parents: 46369
diff changeset
   216
by (metis le_maxI2 linorder_not_le mult_le_cancel_right order_trans)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   217
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   218
lemma bigo_bounded_alt: "\<forall>x. 0 <= f x \<Longrightarrow> \<forall>x. f x <= c * g x \<Longrightarrow> f : O(g)"
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   219
apply (auto simp add: bigo_def)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   220
(* Version 1: one-line proof *)
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   221
by (metis abs_le_D1 linorder_class.not_less order_less_le Orderings.xt1(12) abs_mult)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   222
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   223
lemma "\<forall>x. 0 <= f x \<Longrightarrow> \<forall>x. f x <= c * g x \<Longrightarrow> f : O(g)"
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   224
apply (auto simp add: bigo_def)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   225
(* Version 2: structured proof *)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   226
proof -
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   227
  assume "\<forall>x. f x \<le> c * g x"
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   228
  thus "\<exists>c. \<forall>x. f x \<le> c * \<bar>g x\<bar>" by (metis abs_mult abs_ge_self order_trans)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   229
qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   230
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   231
lemma bigo_bounded: "\<forall>x. 0 <= f x \<Longrightarrow> \<forall>x. f x <= g x \<Longrightarrow> f : O(g)"
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   232
apply (erule bigo_bounded_alt [of f 1 g])
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   233
by (metis mult_1)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   234
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   235
lemma bigo_bounded2: "\<forall>x. lb x <= f x \<Longrightarrow> \<forall>x. f x <= lb x + g x \<Longrightarrow> f : lb +o O(g)"
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   236
apply (rule set_minus_imp_plus)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   237
apply (rule bigo_bounded)
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   238
 apply (metis add_le_cancel_left diff_add_cancel diff_self minus_apply
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   239
              comm_semiring_1_class.normalizing_semiring_rules(24))
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   240
by (metis add_le_cancel_left diff_add_cancel func_plus le_fun_def
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   241
          comm_semiring_1_class.normalizing_semiring_rules(24))
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   242
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   243
lemma bigo_abs: "(\<lambda>x. abs(f x)) =o O(f)"
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   244
apply (unfold bigo_def)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   245
apply auto
36844
5f9385ecc1a7 Removed usage of normalizating locales.
hoelzl
parents: 36725
diff changeset
   246
by (metis mult_1 order_refl)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   247
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   248
lemma bigo_abs2: "f =o O(\<lambda>x. abs(f x))"
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   249
apply (unfold bigo_def)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   250
apply auto
36844
5f9385ecc1a7 Removed usage of normalizating locales.
hoelzl
parents: 36725
diff changeset
   251
by (metis mult_1 order_refl)
43197
c71657bbdbc0 tuned Metis examples
blanchet
parents: 42103
diff changeset
   252
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   253
lemma bigo_abs3: "O(f) = O(\<lambda>x. abs(f x))"
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   254
proof -
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   255
  have F1: "\<forall>v u. u \<in> O(v) \<longrightarrow> O(u) \<subseteq> O(v)" by (metis bigo_elt_subset)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   256
  have F2: "\<forall>u. (\<lambda>R. \<bar>u R\<bar>) \<in> O(u)" by (metis bigo_abs)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   257
  have "\<forall>u. u \<in> O(\<lambda>R. \<bar>u R\<bar>)" by (metis bigo_abs2)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   258
  thus "O(f) = O(\<lambda>x. \<bar>f x\<bar>)" using F1 F2 by auto
43197
c71657bbdbc0 tuned Metis examples
blanchet
parents: 42103
diff changeset
   259
qed
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   260
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   261
lemma bigo_abs4: "f =o g +o O(h) \<Longrightarrow> (\<lambda>x. abs (f x)) =o (\<lambda>x. abs (g x)) +o O(h)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   262
  apply (drule set_plus_imp_minus)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   263
  apply (rule set_minus_imp_plus)
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   264
  apply (subst fun_diff_def)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   265
proof -
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   266
  assume a: "f - g : O(h)"
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   267
  have "(\<lambda>x. abs (f x) - abs (g x)) =o O(\<lambda>x. abs(abs (f x) - abs (g x)))"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   268
    by (rule bigo_abs2)
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   269
  also have "... <= O(\<lambda>x. abs (f x - g x))"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   270
    apply (rule bigo_elt_subset)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   271
    apply (rule bigo_bounded)
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   272
     apply (metis abs_ge_zero)
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   273
    by (metis abs_triangle_ineq3)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   274
  also have "... <= O(f - g)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   275
    apply (rule bigo_elt_subset)
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   276
    apply (subst fun_diff_def)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   277
    apply (rule bigo_abs)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   278
    done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   279
  also have "... <= O(h)"
23464
bc2563c37b1a tuned proofs -- avoid implicit prems;
wenzelm
parents: 23449
diff changeset
   280
    using a by (rule bigo_elt_subset)
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   281
  finally show "(\<lambda>x. abs (f x) - abs (g x)) : O(h)".
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   282
qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   283
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   284
lemma bigo_abs5: "f =o O(g) \<Longrightarrow> (\<lambda>x. abs(f x)) =o O(g)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   285
by (unfold bigo_def, auto)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   286
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   287
lemma bigo_elt_subset2 [intro]: "f : g +o O(h) \<Longrightarrow> O(f) <= O(g) \<oplus> O(h)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   288
proof -
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   289
  assume "f : g +o O(h)"
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   290
  also have "... <= O(g) \<oplus> O(h)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   291
    by (auto del: subsetI)
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   292
  also have "... = O(\<lambda>x. abs(g x)) \<oplus> O(\<lambda>x. abs(h x))"
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   293
    by (metis bigo_abs3)
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   294
  also have "... = O((\<lambda>x. abs(g x)) + (\<lambda>x. abs(h x)))"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   295
    by (rule bigo_plus_eq [symmetric], auto)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   296
  finally have "f : ...".
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   297
  then have "O(f) <= ..."
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   298
    by (elim bigo_elt_subset)
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   299
  also have "... = O(\<lambda>x. abs(g x)) \<oplus> O(\<lambda>x. abs(h x))"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   300
    by (rule bigo_plus_eq, auto)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   301
  finally show ?thesis
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   302
    by (simp add: bigo_abs3 [symmetric])
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   303
qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   304
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   305
lemma bigo_mult [intro]: "O(f) \<otimes> O(g) <= O(f * g)"
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   306
apply (rule subsetI)
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   307
apply (subst bigo_def)
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   308
apply (auto simp del: abs_mult mult_ac
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   309
            simp add: bigo_alt_def set_times_def func_times)
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   310
(* sledgehammer *)
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   311
apply (rule_tac x = "c * ca" in exI)
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   312
apply (rule allI)
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   313
apply (erule_tac x = x in allE)+
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   314
apply (subgoal_tac "c * ca * abs (f x * g x) = (c * abs(f x)) * (ca * abs (g x))")
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   315
 apply (metis (no_types) abs_ge_zero abs_mult mult_mono')
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   316
by (metis mult_assoc mult_left_commute abs_of_pos mult_left_commute abs_mult)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   317
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   318
lemma bigo_mult2 [intro]: "f *o O(g) <= O(f * g)"
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   319
by (metis bigo_mult bigo_refl set_times_mono3 subset_trans)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   320
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   321
lemma bigo_mult3: "f : O(h) \<Longrightarrow> g : O(j) \<Longrightarrow> f * g : O(h * j)"
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   322
by (metis bigo_mult set_rev_mp set_times_intro)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   323
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   324
lemma bigo_mult4 [intro]:"f : k +o O(h) \<Longrightarrow> g * f : (g * k) +o O(g * h)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   325
by (metis bigo_mult2 set_plus_mono_b set_times_intro2 set_times_plus_distrib)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   326
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   327
lemma bigo_mult5: "\<forall>x. f x ~= 0 \<Longrightarrow>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46644
diff changeset
   328
    O(f * g) <= (f\<Colon>'a => ('b\<Colon>linordered_field)) *o O(g)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   329
proof -
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   330
  assume a: "\<forall>x. f x ~= 0"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   331
  show "O(f * g) <= f *o O(g)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   332
  proof
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   333
    fix h
41541
1fa4725c4656 eliminated global prems;
wenzelm
parents: 41413
diff changeset
   334
    assume h: "h : O(f * g)"
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   335
    then have "(\<lambda>x. 1 / (f x)) * h : (\<lambda>x. 1 / f x) *o O(f * g)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   336
      by auto
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   337
    also have "... <= O((\<lambda>x. 1 / f x) * (f * g))"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   338
      by (rule bigo_mult2)
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   339
    also have "(\<lambda>x. 1 / f x) * (f * g) = g"
43197
c71657bbdbc0 tuned Metis examples
blanchet
parents: 42103
diff changeset
   340
      apply (simp add: func_times)
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   341
      by (metis (lifting, no_types) a ext mult_ac(2) nonzero_divide_eq_eq)
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   342
    finally have "(\<lambda>x. (1\<Colon>'b) / f x) * h : O(g)".
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   343
    then have "f * ((\<lambda>x. (1\<Colon>'b) / f x) * h) : f *o O(g)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   344
      by auto
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   345
    also have "f * ((\<lambda>x. (1\<Colon>'b) / f x) * h) = h"
43197
c71657bbdbc0 tuned Metis examples
blanchet
parents: 42103
diff changeset
   346
      apply (simp add: func_times)
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   347
      by (metis (lifting, no_types) a eq_divide_imp ext
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   348
                comm_semiring_1_class.normalizing_semiring_rules(7))
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   349
    finally show "h : f *o O(g)".
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   350
  qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   351
qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   352
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   353
lemma bigo_mult6:
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46644
diff changeset
   354
"\<forall>x. f x \<noteq> 0 \<Longrightarrow> O(f * g) = (f\<Colon>'a \<Rightarrow> ('b\<Colon>linordered_field)) *o O(g)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   355
by (metis bigo_mult2 bigo_mult5 order_antisym)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   356
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   357
(*proof requires relaxing relevance: 2007-01-25*)
45705
blanchet
parents: 45575
diff changeset
   358
declare bigo_mult6 [simp]
blanchet
parents: 45575
diff changeset
   359
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   360
lemma bigo_mult7:
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46644
diff changeset
   361
"\<forall>x. f x \<noteq> 0 \<Longrightarrow> O(f * g) \<le> O(f\<Colon>'a \<Rightarrow> ('b\<Colon>linordered_field)) \<otimes> O(g)"
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   362
by (metis bigo_refl bigo_mult6 set_times_mono3)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   363
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   364
declare bigo_mult6 [simp del]
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   365
declare bigo_mult7 [intro!]
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   366
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   367
lemma bigo_mult8:
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46644
diff changeset
   368
"\<forall>x. f x \<noteq> 0 \<Longrightarrow> O(f * g) = O(f\<Colon>'a \<Rightarrow> ('b\<Colon>linordered_field)) \<otimes> O(g)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   369
by (metis bigo_mult bigo_mult7 order_antisym_conv)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   370
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   371
lemma bigo_minus [intro]: "f : O(g) \<Longrightarrow> - f : O(g)"
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   372
by (auto simp add: bigo_def fun_Compl_def)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   373
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   374
lemma bigo_minus2: "f : g +o O(h) \<Longrightarrow> -f : -g +o O(h)"
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   375
by (metis (no_types) bigo_elt_subset bigo_minus bigo_mult4 bigo_refl
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   376
          comm_semiring_1_class.normalizing_semiring_rules(11) minus_mult_left
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   377
          set_plus_mono_b)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   378
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   379
lemma bigo_minus3: "O(-f) = O(f)"
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   380
by (metis bigo_elt_subset bigo_minus bigo_refl equalityI minus_minus)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   381
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   382
lemma bigo_plus_absorb_lemma1: "f : O(g) \<Longrightarrow> f +o O(g) \<le> O(g)"
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   383
by (metis bigo_plus_idemp set_plus_mono3)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   384
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   385
lemma bigo_plus_absorb_lemma2: "f : O(g) \<Longrightarrow> O(g) \<le> f +o O(g)"
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   386
by (metis (no_types) bigo_minus bigo_plus_absorb_lemma1 right_minus
46644
bd03e0890699 rephrase some slow "metis" calls
blanchet
parents: 46369
diff changeset
   387
          set_plus_mono set_plus_rearrange2 set_zero_plus subsetD subset_refl
bd03e0890699 rephrase some slow "metis" calls
blanchet
parents: 46369
diff changeset
   388
          subset_trans)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   389
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   390
lemma bigo_plus_absorb [simp]: "f : O(g) \<Longrightarrow> f +o O(g) = O(g)"
41865
4e8483cc2cc5 declare ext [intro]: Extensionality now available by default
paulson
parents: 41541
diff changeset
   391
by (metis bigo_plus_absorb_lemma1 bigo_plus_absorb_lemma2 order_eq_iff)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   392
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   393
lemma bigo_plus_absorb2 [intro]: "f : O(g) \<Longrightarrow> A <= O(g) \<Longrightarrow> f +o A \<le> O(g)"
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   394
by (metis bigo_plus_absorb set_plus_mono)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   395
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   396
lemma bigo_add_commute_imp: "f : g +o O(h) \<Longrightarrow> g : f +o O(h)"
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   397
by (metis bigo_minus minus_diff_eq set_plus_imp_minus set_minus_plus)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   398
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   399
lemma bigo_add_commute: "(f : g +o O(h)) = (g : f +o O(h))"
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   400
by (metis bigo_add_commute_imp)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   401
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   402
lemma bigo_const1: "(\<lambda>x. c) : O(\<lambda>x. 1)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   403
by (auto simp add: bigo_def mult_ac)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   404
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   405
lemma bigo_const2 [intro]: "O(\<lambda>x. c) \<le> O(\<lambda>x. 1)"
41865
4e8483cc2cc5 declare ext [intro]: Extensionality now available by default
paulson
parents: 41541
diff changeset
   406
by (metis bigo_const1 bigo_elt_subset)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   407
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46644
diff changeset
   408
lemma bigo_const3: "(c\<Colon>'a\<Colon>linordered_field) ~= 0 \<Longrightarrow> (\<lambda>x. 1) : O(\<lambda>x. c)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   409
apply (simp add: bigo_def)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   410
by (metis abs_eq_0 left_inverse order_refl)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   411
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46644
diff changeset
   412
lemma bigo_const4: "(c\<Colon>'a\<Colon>linordered_field) ~= 0 \<Longrightarrow> O(\<lambda>x. 1) <= O(\<lambda>x. c)"
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   413
by (metis bigo_elt_subset bigo_const3)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   414
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46644
diff changeset
   415
lemma bigo_const [simp]: "(c\<Colon>'a\<Colon>linordered_field) ~= 0 \<Longrightarrow>
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   416
    O(\<lambda>x. c) = O(\<lambda>x. 1)"
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   417
by (metis bigo_const2 bigo_const4 equalityI)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   418
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   419
lemma bigo_const_mult1: "(\<lambda>x. c * f x) : O(f)"
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   420
apply (simp add: bigo_def abs_mult)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   421
by (metis le_less)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   422
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   423
lemma bigo_const_mult2: "O(\<lambda>x. c * f x) \<le> O(f)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   424
by (rule bigo_elt_subset, rule bigo_const_mult1)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   425
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46644
diff changeset
   426
lemma bigo_const_mult3: "(c\<Colon>'a\<Colon>linordered_field) ~= 0 \<Longrightarrow> f : O(\<lambda>x. c * f x)"
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   427
apply (simp add: bigo_def)
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   428
by (metis (no_types) abs_mult mult_assoc mult_1 order_refl left_inverse)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   429
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   430
lemma bigo_const_mult4:
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46644
diff changeset
   431
"(c\<Colon>'a\<Colon>linordered_field) \<noteq> 0 \<Longrightarrow> O(f) \<le> O(\<lambda>x. c * f x)"
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   432
by (metis bigo_elt_subset bigo_const_mult3)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   433
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46644
diff changeset
   434
lemma bigo_const_mult [simp]: "(c\<Colon>'a\<Colon>linordered_field) ~= 0 \<Longrightarrow>
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   435
    O(\<lambda>x. c * f x) = O(f)"
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   436
by (metis equalityI bigo_const_mult2 bigo_const_mult4)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   437
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46644
diff changeset
   438
lemma bigo_const_mult5 [simp]: "(c\<Colon>'a\<Colon>linordered_field) ~= 0 \<Longrightarrow>
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   439
    (\<lambda>x. c) *o O(f) = O(f)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   440
  apply (auto del: subsetI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   441
  apply (rule order_trans)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   442
  apply (rule bigo_mult2)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   443
  apply (simp add: func_times)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   444
  apply (auto intro!: subsetI simp add: bigo_def elt_set_times_def func_times)
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   445
  apply (rule_tac x = "\<lambda>y. inverse c * x y" in exI)
43197
c71657bbdbc0 tuned Metis examples
blanchet
parents: 42103
diff changeset
   446
  apply (rename_tac g d)
24942
39a23aadc7e1 more metis proofs
paulson
parents: 24937
diff changeset
   447
  apply safe
43197
c71657bbdbc0 tuned Metis examples
blanchet
parents: 42103
diff changeset
   448
  apply (rule_tac [2] ext)
c71657bbdbc0 tuned Metis examples
blanchet
parents: 42103
diff changeset
   449
   prefer 2
26041
c2e15e65165f locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents: 25710
diff changeset
   450
   apply simp
24942
39a23aadc7e1 more metis proofs
paulson
parents: 24937
diff changeset
   451
  apply (simp add: mult_assoc [symmetric] abs_mult)
39259
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   452
  (* couldn't get this proof without the step above *)
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   453
proof -
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   454
  fix g :: "'b \<Rightarrow> 'a" and d :: 'a
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   455
  assume A1: "c \<noteq> (0\<Colon>'a)"
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   456
  assume A2: "\<forall>x\<Colon>'b. \<bar>g x\<bar> \<le> d * \<bar>f x\<bar>"
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   457
  have F1: "inverse \<bar>c\<bar> = \<bar>inverse c\<bar>" using A1 by (metis nonzero_abs_inverse)
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   458
  have F2: "(0\<Colon>'a) < \<bar>c\<bar>" using A1 by (metis zero_less_abs_iff)
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   459
  have "(0\<Colon>'a) < \<bar>c\<bar> \<longrightarrow> (0\<Colon>'a) < \<bar>inverse c\<bar>" using F1 by (metis positive_imp_inverse_positive)
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   460
  hence "(0\<Colon>'a) < \<bar>inverse c\<bar>" using F2 by metis
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   461
  hence F3: "(0\<Colon>'a) \<le> \<bar>inverse c\<bar>" by (metis order_le_less)
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   462
  have "\<exists>(u\<Colon>'a) SKF\<^isub>7\<Colon>'a \<Rightarrow> 'b. \<bar>g (SKF\<^isub>7 (\<bar>inverse c\<bar> * u))\<bar> \<le> u * \<bar>f (SKF\<^isub>7 (\<bar>inverse c\<bar> * u))\<bar>"
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   463
    using A2 by metis
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   464
  hence F4: "\<exists>(u\<Colon>'a) SKF\<^isub>7\<Colon>'a \<Rightarrow> 'b. \<bar>g (SKF\<^isub>7 (\<bar>inverse c\<bar> * u))\<bar> \<le> u * \<bar>f (SKF\<^isub>7 (\<bar>inverse c\<bar> * u))\<bar> \<and> (0\<Colon>'a) \<le> \<bar>inverse c\<bar>"
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   465
    using F3 by metis
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   466
  hence "\<exists>(v\<Colon>'a) (u\<Colon>'a) SKF\<^isub>7\<Colon>'a \<Rightarrow> 'b. \<bar>inverse c\<bar> * \<bar>g (SKF\<^isub>7 (u * v))\<bar> \<le> u * (v * \<bar>f (SKF\<^isub>7 (u * v))\<bar>)"
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   467
    by (metis comm_mult_left_mono)
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   468
  thus "\<exists>ca\<Colon>'a. \<forall>x\<Colon>'b. \<bar>inverse c\<bar> * \<bar>g x\<bar> \<le> ca * \<bar>f x\<bar>"
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   469
    using A2 F4 by (metis ab_semigroup_mult_class.mult_ac(1) comm_mult_left_mono)
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   470
qed
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   471
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   472
lemma bigo_const_mult6 [intro]: "(\<lambda>x. c) *o O(f) <= O(f)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   473
  apply (auto intro!: subsetI
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   474
    simp add: bigo_def elt_set_times_def func_times
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   475
    simp del: abs_mult mult_ac)
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   476
(* sledgehammer *)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   477
  apply (rule_tac x = "ca * (abs c)" in exI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   478
  apply (rule allI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   479
  apply (subgoal_tac "ca * abs(c) * abs(f x) = abs(c) * (ca * abs(f x))")
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   480
  apply (erule ssubst)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   481
  apply (subst abs_mult)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   482
  apply (rule mult_left_mono)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   483
  apply (erule spec)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   484
  apply simp
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   485
  apply (simp add: mult_ac)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   486
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   487
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   488
lemma bigo_const_mult7 [intro]: "f =o O(g) \<Longrightarrow> (\<lambda>x. c * f x) =o O(g)"
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   489
by (metis bigo_const_mult1 bigo_elt_subset order_less_le psubsetD)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   490
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   491
lemma bigo_compose1: "f =o O(g) \<Longrightarrow> (\<lambda>x. f(k x)) =o O(\<lambda>x. g(k x))"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   492
by (unfold bigo_def, auto)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   493
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   494
lemma bigo_compose2:
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   495
"f =o g +o O(h) \<Longrightarrow> (\<lambda>x. f(k x)) =o (\<lambda>x. g(k x)) +o O(\<lambda>x. h(k x))"
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   496
apply (simp only: set_minus_plus [symmetric] diff_minus fun_Compl_def func_plus)
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   497
by (erule bigo_compose1)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   498
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   499
subsection {* Setsum *}
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   500
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   501
lemma bigo_setsum_main: "\<forall>x. \<forall>y \<in> A x. 0 <= h x y \<Longrightarrow>
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   502
    \<exists>c. \<forall>x. \<forall>y \<in> A x. abs (f x y) <= c * (h x y) \<Longrightarrow>
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   503
      (\<lambda>x. SUM y : A x. f x y) =o O(\<lambda>x. SUM y : A x. h x y)"
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   504
apply (auto simp add: bigo_def)
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   505
apply (rule_tac x = "abs c" in exI)
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   506
apply (subst abs_of_nonneg) back back
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   507
 apply (rule setsum_nonneg)
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   508
 apply force
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   509
apply (subst setsum_right_distrib)
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   510
apply (rule allI)
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   511
apply (rule order_trans)
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   512
 apply (rule setsum_abs)
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   513
apply (rule setsum_mono)
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   514
by (metis abs_ge_self abs_mult_pos order_trans)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   515
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   516
lemma bigo_setsum1: "\<forall>x y. 0 <= h x y \<Longrightarrow>
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   517
    \<exists>c. \<forall>x y. abs (f x y) <= c * (h x y) \<Longrightarrow>
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   518
      (\<lambda>x. SUM y : A x. f x y) =o O(\<lambda>x. SUM y : A x. h x y)"
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   519
by (metis (no_types) bigo_setsum_main)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   520
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   521
lemma bigo_setsum2: "\<forall>y. 0 <= h y \<Longrightarrow>
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   522
    \<exists>c. \<forall>y. abs (f y) <= c * (h y) \<Longrightarrow>
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   523
      (\<lambda>x. SUM y : A x. f y) =o O(\<lambda>x. SUM y : A x. h y)"
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   524
apply (rule bigo_setsum1)
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   525
by metis+
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   526
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   527
lemma bigo_setsum3: "f =o O(h) \<Longrightarrow>
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   528
    (\<lambda>x. SUM y : A x. (l x y) * f(k x y)) =o
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   529
      O(\<lambda>x. SUM y : A x. abs(l x y * h(k x y)))"
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   530
apply (rule bigo_setsum1)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   531
 apply (rule allI)+
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   532
 apply (rule abs_ge_zero)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   533
apply (unfold bigo_def)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   534
apply (auto simp add: abs_mult)
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   535
by (metis abs_ge_zero mult_left_commute mult_left_mono)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   536
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   537
lemma bigo_setsum4: "f =o g +o O(h) \<Longrightarrow>
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   538
    (\<lambda>x. SUM y : A x. l x y * f(k x y)) =o
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   539
      (\<lambda>x. SUM y : A x. l x y * g(k x y)) +o
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   540
        O(\<lambda>x. SUM y : A x. abs(l x y * h(k x y)))"
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   541
apply (rule set_minus_imp_plus)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   542
apply (subst fun_diff_def)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   543
apply (subst setsum_subtractf [symmetric])
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   544
apply (subst right_diff_distrib [symmetric])
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   545
apply (rule bigo_setsum3)
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   546
by (metis (lifting, no_types) fun_diff_def set_plus_imp_minus ext)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   547
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   548
lemma bigo_setsum5: "f =o O(h) \<Longrightarrow> \<forall>x y. 0 <= l x y \<Longrightarrow>
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   549
    \<forall>x. 0 <= h x \<Longrightarrow>
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   550
      (\<lambda>x. SUM y : A x. (l x y) * f(k x y)) =o
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   551
        O(\<lambda>x. SUM y : A x. (l x y) * h(k x y))"
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   552
apply (subgoal_tac "(\<lambda>x. SUM y : A x. (l x y) * h(k x y)) =
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   553
      (\<lambda>x. SUM y : A x. abs((l x y) * h(k x y)))")
46369
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   554
 apply (erule ssubst)
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   555
 apply (erule bigo_setsum3)
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   556
apply (rule ext)
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   557
apply (rule setsum_cong2)
9ac0c64ad8e7 example tuning
blanchet
parents: 46364
diff changeset
   558
by (metis abs_of_nonneg zero_le_mult_iff)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   559
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   560
lemma bigo_setsum6: "f =o g +o O(h) \<Longrightarrow> \<forall>x y. 0 <= l x y \<Longrightarrow>
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   561
    \<forall>x. 0 <= h x \<Longrightarrow>
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   562
      (\<lambda>x. SUM y : A x. (l x y) * f(k x y)) =o
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   563
        (\<lambda>x. SUM y : A x. (l x y) * g(k x y)) +o
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   564
          O(\<lambda>x. SUM y : A x. (l x y) * h(k x y))"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   565
  apply (rule set_minus_imp_plus)
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   566
  apply (subst fun_diff_def)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   567
  apply (subst setsum_subtractf [symmetric])
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   568
  apply (subst right_diff_distrib [symmetric])
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   569
  apply (rule bigo_setsum5)
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   570
  apply (subst fun_diff_def [symmetric])
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   571
  apply (drule set_plus_imp_minus)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   572
  apply auto
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   573
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   574
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   575
subsection {* Misc useful stuff *}
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   576
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   577
lemma bigo_useful_intro: "A <= O(f) \<Longrightarrow> B <= O(f) \<Longrightarrow>
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   578
  A \<oplus> B <= O(f)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   579
  apply (subst bigo_plus_idemp [symmetric])
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   580
  apply (rule set_plus_mono2)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   581
  apply assumption+
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   582
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   583
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   584
lemma bigo_useful_add: "f =o O(h) \<Longrightarrow> g =o O(h) \<Longrightarrow> f + g =o O(h)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   585
  apply (subst bigo_plus_idemp [symmetric])
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   586
  apply (rule set_plus_intro)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   587
  apply assumption+
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   588
done
43197
c71657bbdbc0 tuned Metis examples
blanchet
parents: 42103
diff changeset
   589
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46644
diff changeset
   590
lemma bigo_useful_const_mult: "(c\<Colon>'a\<Colon>linordered_field) ~= 0 \<Longrightarrow>
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   591
    (\<lambda>x. c) * f =o O(h) \<Longrightarrow> f =o O(h)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   592
  apply (rule subsetD)
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   593
  apply (subgoal_tac "(\<lambda>x. 1 / c) *o O(h) <= O(h)")
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   594
  apply assumption
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   595
  apply (rule bigo_const_mult6)
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   596
  apply (subgoal_tac "f = (\<lambda>x. 1 / c) * ((\<lambda>x. c) * f)")
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   597
  apply (erule ssubst)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   598
  apply (erule set_times_intro2)
43197
c71657bbdbc0 tuned Metis examples
blanchet
parents: 42103
diff changeset
   599
  apply (simp add: func_times)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   600
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   601
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   602
lemma bigo_fix: "(\<lambda>x. f ((x\<Colon>nat) + 1)) =o O(\<lambda>x. h(x + 1)) \<Longrightarrow> f 0 = 0 \<Longrightarrow>
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   603
    f =o O(h)"
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   604
apply (simp add: bigo_alt_def)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   605
by (metis abs_ge_zero abs_mult abs_of_pos abs_zero not0_implies_Suc)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   606
43197
c71657bbdbc0 tuned Metis examples
blanchet
parents: 42103
diff changeset
   607
lemma bigo_fix2:
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   608
    "(\<lambda>x. f ((x\<Colon>nat) + 1)) =o (\<lambda>x. g(x + 1)) +o O(\<lambda>x. h(x + 1)) \<Longrightarrow>
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   609
       f 0 = g 0 \<Longrightarrow> f =o g +o O(h)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   610
  apply (rule set_minus_imp_plus)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   611
  apply (rule bigo_fix)
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   612
  apply (subst fun_diff_def)
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   613
  apply (subst fun_diff_def [symmetric])
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   614
  apply (rule set_plus_imp_minus)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   615
  apply simp
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   616
  apply (simp add: fun_diff_def)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   617
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   618
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   619
subsection {* Less than or equal to *}
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   620
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   621
definition lesso :: "('a => 'b\<Colon>linordered_idom) => ('a => 'b) => ('a => 'b)" (infixl "<o" 70) where
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   622
  "f <o g == (\<lambda>x. max (f x - g x) 0)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   623
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   624
lemma bigo_lesseq1: "f =o O(h) \<Longrightarrow> \<forall>x. abs (g x) <= abs (f x) \<Longrightarrow>
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   625
    g =o O(h)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   626
  apply (unfold bigo_def)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   627
  apply clarsimp
43197
c71657bbdbc0 tuned Metis examples
blanchet
parents: 42103
diff changeset
   628
apply (blast intro: order_trans)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   629
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   630
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   631
lemma bigo_lesseq2: "f =o O(h) \<Longrightarrow> \<forall>x. abs (g x) <= f x \<Longrightarrow>
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   632
      g =o O(h)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   633
  apply (erule bigo_lesseq1)
43197
c71657bbdbc0 tuned Metis examples
blanchet
parents: 42103
diff changeset
   634
apply (blast intro: abs_ge_self order_trans)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   635
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   636
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   637
lemma bigo_lesseq3: "f =o O(h) \<Longrightarrow> \<forall>x. 0 <= g x \<Longrightarrow> \<forall>x. g x <= f x \<Longrightarrow>
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   638
      g =o O(h)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   639
  apply (erule bigo_lesseq2)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   640
  apply (rule allI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   641
  apply (subst abs_of_nonneg)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   642
  apply (erule spec)+
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   643
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   644
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   645
lemma bigo_lesseq4: "f =o O(h) \<Longrightarrow>
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   646
    \<forall>x. 0 <= g x \<Longrightarrow> \<forall>x. g x <= abs (f x) \<Longrightarrow>
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   647
      g =o O(h)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   648
  apply (erule bigo_lesseq1)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   649
  apply (rule allI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   650
  apply (subst abs_of_nonneg)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   651
  apply (erule spec)+
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   652
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   653
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   654
lemma bigo_lesso1: "\<forall>x. f x <= g x \<Longrightarrow> f <o g =o O(h)"
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   655
apply (unfold lesso_def)
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   656
apply (subgoal_tac "(\<lambda>x. max (f x - g x) 0) = 0")
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   657
 apply (metis bigo_zero)
46364
abab10d1f4a3 example tuning
blanchet
parents: 45705
diff changeset
   658
by (metis (lifting, no_types) func_zero le_fun_def le_iff_diff_le_0
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   659
      min_max.sup_absorb2 order_eq_iff)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   660
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   661
lemma bigo_lesso2: "f =o g +o O(h) \<Longrightarrow>
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   662
    \<forall>x. 0 <= k x \<Longrightarrow> \<forall>x. k x <= f x \<Longrightarrow>
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   663
      k <o g =o O(h)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   664
  apply (unfold lesso_def)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   665
  apply (rule bigo_lesseq4)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   666
  apply (erule set_plus_imp_minus)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   667
  apply (rule allI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   668
  apply (rule le_maxI2)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   669
  apply (rule allI)
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   670
  apply (subst fun_diff_def)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   671
apply (erule thin_rl)
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   672
(* sledgehammer *)
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   673
apply (case_tac "0 <= k x - g x")
46644
bd03e0890699 rephrase some slow "metis" calls
blanchet
parents: 46369
diff changeset
   674
 apply (metis (lifting) abs_le_D1 linorder_linear min_diff_distrib_left
bd03e0890699 rephrase some slow "metis" calls
blanchet
parents: 46369
diff changeset
   675
          min_max.inf_absorb1 min_max.inf_absorb2 min_max.sup_absorb1)
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   676
by (metis abs_ge_zero le_cases min_max.sup_absorb2)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   677
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   678
lemma bigo_lesso3: "f =o g +o O(h) \<Longrightarrow>
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   679
    \<forall>x. 0 <= k x \<Longrightarrow> \<forall>x. g x <= k x \<Longrightarrow>
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   680
      f <o k =o O(h)"
46644
bd03e0890699 rephrase some slow "metis" calls
blanchet
parents: 46369
diff changeset
   681
apply (unfold lesso_def)
bd03e0890699 rephrase some slow "metis" calls
blanchet
parents: 46369
diff changeset
   682
apply (rule bigo_lesseq4)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   683
  apply (erule set_plus_imp_minus)
46644
bd03e0890699 rephrase some slow "metis" calls
blanchet
parents: 46369
diff changeset
   684
 apply (rule allI)
bd03e0890699 rephrase some slow "metis" calls
blanchet
parents: 46369
diff changeset
   685
 apply (rule le_maxI2)
bd03e0890699 rephrase some slow "metis" calls
blanchet
parents: 46369
diff changeset
   686
apply (rule allI)
bd03e0890699 rephrase some slow "metis" calls
blanchet
parents: 46369
diff changeset
   687
apply (subst fun_diff_def)
bd03e0890699 rephrase some slow "metis" calls
blanchet
parents: 46369
diff changeset
   688
apply (erule thin_rl)
bd03e0890699 rephrase some slow "metis" calls
blanchet
parents: 46369
diff changeset
   689
(* sledgehammer *)
bd03e0890699 rephrase some slow "metis" calls
blanchet
parents: 46369
diff changeset
   690
apply (case_tac "0 <= f x - k x")
bd03e0890699 rephrase some slow "metis" calls
blanchet
parents: 46369
diff changeset
   691
 apply simp
bd03e0890699 rephrase some slow "metis" calls
blanchet
parents: 46369
diff changeset
   692
 apply (subst abs_of_nonneg)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   693
  apply (drule_tac x = x in spec) back
45705
blanchet
parents: 45575
diff changeset
   694
  apply (metis diff_less_0_iff_less linorder_not_le not_leE xt1(12) xt1(6))
45575
3a865fc42bbf more "metis" calls in example
blanchet
parents: 45532
diff changeset
   695
 apply (metis add_minus_cancel diff_le_eq le_diff_eq uminus_add_conv_diff)
46644
bd03e0890699 rephrase some slow "metis" calls
blanchet
parents: 46369
diff changeset
   696
by (metis abs_ge_zero linorder_linear min_max.sup_absorb1 min_max.sup_commute)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   697
45705
blanchet
parents: 45575
diff changeset
   698
lemma bigo_lesso4:
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46644
diff changeset
   699
  "f <o g =o O(k\<Colon>'a=>'b\<Colon>{linordered_field}) \<Longrightarrow>
45705
blanchet
parents: 45575
diff changeset
   700
   g =o h +o O(k) \<Longrightarrow> f <o h =o O(k)"
blanchet
parents: 45575
diff changeset
   701
apply (unfold lesso_def)
blanchet
parents: 45575
diff changeset
   702
apply (drule set_plus_imp_minus)
blanchet
parents: 45575
diff changeset
   703
apply (drule bigo_abs5) back
blanchet
parents: 45575
diff changeset
   704
apply (simp add: fun_diff_def)
blanchet
parents: 45575
diff changeset
   705
apply (drule bigo_useful_add, assumption)
blanchet
parents: 45575
diff changeset
   706
apply (erule bigo_lesseq2) back
blanchet
parents: 45575
diff changeset
   707
apply (rule allI)
blanchet
parents: 45575
diff changeset
   708
by (auto simp add: func_plus fun_diff_def algebra_simps
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   709
    split: split_max abs_split)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   710
45705
blanchet
parents: 45575
diff changeset
   711
lemma bigo_lesso5: "f <o g =o O(h) \<Longrightarrow> \<exists>C. \<forall>x. f x <= g x + C * abs (h x)"
blanchet
parents: 45575
diff changeset
   712
apply (simp only: lesso_def bigo_alt_def)
blanchet
parents: 45575
diff changeset
   713
apply clarsimp
blanchet
parents: 45575
diff changeset
   714
by (metis abs_if abs_mult add_commute diff_le_eq less_not_permute)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   715
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   716
end