src/HOL/Metis_Examples/BigO.thy
author wenzelm
Wed, 29 Dec 2010 17:34:41 +0100
changeset 41413 64cd30d6b0b8
parent 41144 509e51b7509a
child 41541 1fa4725c4656
permissions -rw-r--r--
explicit file specifications -- avoid secondary load path;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33027
9cf389429f6d modernized session Metis_Examples;
wenzelm
parents: 32864
diff changeset
     1
(*  Title:      HOL/Metis_Examples/BigO.thy
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
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
41144
509e51b7509a example tuning
blanchet
parents: 39259
diff changeset
     5
Testing Metis.
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
     6
*)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
     7
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
     8
header {* Big O notation *}
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
     9
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    10
theory BigO
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
  Main
64cd30d6b0b8 explicit file specifications -- avoid secondary load path;
wenzelm
parents: 41144
diff changeset
    14
  "~~/src/HOL/Library/Function_Algebras"
64cd30d6b0b8 explicit file specifications -- avoid secondary load path;
wenzelm
parents: 41144
diff changeset
    15
  "~~/src/HOL/Library/Set_Algebras"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    16
begin
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    17
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    18
subsection {* Definitions *}
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    19
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33027
diff changeset
    20
definition bigo :: "('a => 'b::linordered_idom) => ('a => 'b) set"    ("(1O'(_'))") where
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    21
  "O(f::('a => 'b)) ==   {h. EX c. ALL x. abs (h x) <= c * abs (f x)}"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    22
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
    23
declare [[ sledgehammer_problem_prefix = "BigO__bigo_pos_const" ]]
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33027
diff changeset
    24
lemma bigo_pos_const: "(EX (c::'a::linordered_idom). 
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    25
    ALL x. (abs (h x)) <= (c * (abs (f x))))
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    26
      = (EX c. 0 < c & (ALL x. (abs(h x)) <= (c * (abs (f x)))))"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    27
  apply auto
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    28
  apply (case_tac "c = 0", simp)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    29
  apply (rule_tac x = "1" in exI, simp)
25304
7491c00f0915 removed subclass edge ordered_ring < lordered_ring
haftmann
parents: 25087
diff changeset
    30
  apply (rule_tac x = "abs c" in exI, auto)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    31
  apply (metis abs_ge_zero abs_of_nonneg Orderings.xt1(6) abs_mult)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    32
  done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    33
36407
d733c1a624f4 renamed option
blanchet
parents: 36067
diff changeset
    34
(*** Now various verions with an increasing shrink factor ***)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    35
36925
ffad77bb3046 renamed Sledgehammer options
blanchet
parents: 36844
diff changeset
    36
sledgehammer_params [isar_proof, isar_shrink_factor = 1]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    37
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33027
diff changeset
    38
lemma (*bigo_pos_const:*) "(EX (c::'a::linordered_idom). 
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    39
    ALL x. (abs (h x)) <= (c * (abs (f x))))
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    40
      = (EX c. 0 < c & (ALL x. (abs(h x)) <= (c * (abs (f x)))))"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    41
  apply auto
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    42
  apply (case_tac "c = 0", simp)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    43
  apply (rule_tac x = "1" in exI, simp)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    44
  apply (rule_tac x = "abs c" in exI, auto)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    45
proof -
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    46
  fix c :: 'a and x :: 'b
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    47
  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
    48
  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
    49
  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
    50
  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
    51
  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
    52
    by (metis abs_mult)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    53
  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
    54
    by (metis abs_mult_pos)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    55
  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
    56
  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
    57
  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
    58
  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
    59
  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
    60
  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
    61
  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
    62
  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
    63
  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
    64
qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    65
36925
ffad77bb3046 renamed Sledgehammer options
blanchet
parents: 36844
diff changeset
    66
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
    67
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33027
diff changeset
    68
lemma (*bigo_pos_const:*) "(EX (c::'a::linordered_idom). 
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    69
    ALL x. (abs (h x)) <= (c * (abs (f x))))
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    70
      = (EX c. 0 < c & (ALL x. (abs(h x)) <= (c * (abs (f x)))))"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    71
  apply auto
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    72
  apply (case_tac "c = 0", simp)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    73
  apply (rule_tac x = "1" in exI, simp)
36844
5f9385ecc1a7 Removed usage of normalizating locales.
hoelzl
parents: 36725
diff changeset
    74
  apply (rule_tac x = "abs c" in exI, auto)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    75
proof -
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    76
  fix c :: 'a and x :: 'b
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    77
  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
    78
  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
    79
  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
    80
    by (metis abs_mult)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    81
  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
    82
  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
    83
  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
    84
  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
    85
  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
    86
qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    87
36925
ffad77bb3046 renamed Sledgehammer options
blanchet
parents: 36844
diff changeset
    88
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
    89
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33027
diff changeset
    90
lemma (*bigo_pos_const:*) "(EX (c::'a::linordered_idom). 
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    91
    ALL x. (abs (h x)) <= (c * (abs (f x))))
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    92
      = (EX c. 0 < c & (ALL x. (abs(h x)) <= (c * (abs (f x)))))"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    93
  apply auto
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    94
  apply (case_tac "c = 0", simp)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
    95
  apply (rule_tac x = "1" in exI, simp)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    96
  apply (rule_tac x = "abs c" in exI, auto)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    97
proof -
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    98
  fix c :: 'a and x :: 'b
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
    99
  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
   100
  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
   101
  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
   102
  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
   103
  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)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   104
  thus "\<bar>h x\<bar> \<le> \<bar>c\<bar> * \<bar>f x\<bar>" by (metis A1 abs_mult abs_ge_zero)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   105
qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   106
36925
ffad77bb3046 renamed Sledgehammer options
blanchet
parents: 36844
diff changeset
   107
sledgehammer_params [isar_proof, isar_shrink_factor = 4]
24545
f406a5744756 new proofs found
paulson
parents: 23816
diff changeset
   108
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33027
diff changeset
   109
lemma (*bigo_pos_const:*) "(EX (c::'a::linordered_idom). 
24545
f406a5744756 new proofs found
paulson
parents: 23816
diff changeset
   110
    ALL x. (abs (h x)) <= (c * (abs (f x))))
f406a5744756 new proofs found
paulson
parents: 23816
diff changeset
   111
      = (EX c. 0 < c & (ALL x. (abs(h x)) <= (c * (abs (f x)))))"
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
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   128
lemma bigo_alt_def: "O(f) = 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   129
    {h. EX c. (0 < c & (ALL x. abs (h x) <= c * abs (f x)))}"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   130
by (auto simp add: bigo_def bigo_pos_const)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   131
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   132
declare [[ sledgehammer_problem_prefix = "BigO__bigo_elt_subset" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   133
lemma bigo_elt_subset [intro]: "f : O(g) ==> O(f) <= O(g)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   134
  apply (auto simp add: bigo_alt_def)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   135
  apply (rule_tac x = "ca * c" in exI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   136
  apply (rule conjI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   137
  apply (rule mult_pos_pos)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   138
  apply (assumption)+ 
36844
5f9385ecc1a7 Removed usage of normalizating locales.
hoelzl
parents: 36725
diff changeset
   139
(*sledgehammer*)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   140
  apply (rule allI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   141
  apply (drule_tac x = "xa" in spec)+
36844
5f9385ecc1a7 Removed usage of normalizating locales.
hoelzl
parents: 36725
diff changeset
   142
  apply (subgoal_tac "ca * abs(f xa) <= ca * (c * abs(g xa))")
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   143
  apply (erule order_trans)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   144
  apply (simp add: mult_ac)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   145
  apply (rule mult_left_mono, assumption)
36844
5f9385ecc1a7 Removed usage of normalizating locales.
hoelzl
parents: 36725
diff changeset
   146
  apply (rule order_less_imp_le, assumption)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   147
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   148
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   149
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   150
declare [[ sledgehammer_problem_prefix = "BigO__bigo_refl" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   151
lemma bigo_refl [intro]: "f : O(f)"
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   152
apply (auto simp add: bigo_def)
36844
5f9385ecc1a7 Removed usage of normalizating locales.
hoelzl
parents: 36725
diff changeset
   153
by (metis mult_1 order_refl)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   154
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   155
declare [[ sledgehammer_problem_prefix = "BigO__bigo_zero" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   156
lemma bigo_zero: "0 : O(g)"
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   157
apply (auto simp add: bigo_def func_zero)
36844
5f9385ecc1a7 Removed usage of normalizating locales.
hoelzl
parents: 36725
diff changeset
   158
by (metis mult_zero_left order_refl)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   159
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   160
lemma bigo_zero2: "O(%x.0) = {%x.0}"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   161
  apply (auto simp add: bigo_def) 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   162
  apply (rule ext)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   163
  apply auto
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   164
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   165
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   166
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
   167
  "O(f) \<oplus> O(f) <= O(f)"
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   168
  apply (auto simp add: bigo_alt_def set_plus_def)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   169
  apply (rule_tac x = "c + ca" in exI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   170
  apply auto
23477
f4b83f03cac9 tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents: 23464
diff changeset
   171
  apply (simp add: ring_distribs func_plus)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   172
  apply (blast intro:order_trans abs_triangle_ineq add_mono elim:) 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   173
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   174
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   175
lemma bigo_plus_idemp [simp]: "O(f) \<oplus> O(f) = O(f)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   176
  apply (rule equalityI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   177
  apply (rule bigo_plus_self_subset)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   178
  apply (rule set_zero_plus2) 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   179
  apply (rule bigo_zero)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   180
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   181
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   182
lemma bigo_plus_subset [intro]: "O(f + g) <= O(f) \<oplus> O(g)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   183
  apply (rule subsetI)
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   184
  apply (auto simp add: bigo_def bigo_pos_const func_plus set_plus_def)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   185
  apply (subst bigo_pos_const [symmetric])+
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   186
  apply (rule_tac x = 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   187
    "%n. if abs (g n) <= (abs (f n)) then x n else 0" in exI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   188
  apply (rule conjI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   189
  apply (rule_tac x = "c + c" in exI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   190
  apply (clarsimp)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   191
  apply (auto)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   192
  apply (subgoal_tac "c * abs (f xa + g xa) <= (c + c) * abs (f xa)")
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   193
  apply (erule_tac x = xa in allE)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   194
  apply (erule order_trans)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   195
  apply (simp)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   196
  apply (subgoal_tac "c * abs (f xa + g xa) <= c * (abs (f xa) + abs (g xa))")
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   197
  apply (erule order_trans)
23477
f4b83f03cac9 tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents: 23464
diff changeset
   198
  apply (simp add: ring_distribs)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   199
  apply (rule mult_left_mono)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   200
  apply assumption
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   201
  apply (simp add: order_less_le)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   202
  apply (rule mult_left_mono)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   203
  apply (simp add: abs_triangle_ineq)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   204
  apply (simp add: order_less_le)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   205
  apply (rule mult_nonneg_nonneg)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   206
  apply (rule add_nonneg_nonneg)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   207
  apply auto
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   208
  apply (rule_tac x = "%n. if (abs (f n)) <  abs (g n) then x n else 0" 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   209
     in exI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   210
  apply (rule conjI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   211
  apply (rule_tac x = "c + c" in exI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   212
  apply auto
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   213
  apply (subgoal_tac "c * abs (f xa + g xa) <= (c + c) * abs (g xa)")
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   214
  apply (erule_tac x = xa in allE)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   215
  apply (erule order_trans)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   216
  apply (simp)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   217
  apply (subgoal_tac "c * abs (f xa + g xa) <= c * (abs (f xa) + abs (g xa))")
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   218
  apply (erule order_trans)
23477
f4b83f03cac9 tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents: 23464
diff changeset
   219
  apply (simp add: ring_distribs)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   220
  apply (rule mult_left_mono)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   221
  apply (simp add: order_less_le)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   222
  apply (simp add: order_less_le)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   223
  apply (rule mult_left_mono)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   224
  apply (rule abs_triangle_ineq)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   225
  apply (simp add: order_less_le)
25087
5908591fb881 some more metis calls
paulson
parents: 25082
diff changeset
   226
apply (metis abs_not_less_zero double_less_0_iff less_not_permute linorder_not_less mult_less_0_iff)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   227
  apply (rule ext)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   228
  apply (auto simp add: if_splits linorder_not_le)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   229
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   230
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   231
lemma bigo_plus_subset2 [intro]: "A <= O(f) ==> B <= O(f) ==> A \<oplus> B <= O(f)"
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   232
  apply (subgoal_tac "A \<oplus> B <= O(f) \<oplus> O(f)")
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   233
  apply (erule order_trans)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   234
  apply simp
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   235
  apply (auto del: subsetI simp del: bigo_plus_idemp)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   236
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   237
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   238
declare [[ sledgehammer_problem_prefix = "BigO__bigo_plus_eq" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   239
lemma bigo_plus_eq: "ALL x. 0 <= f x ==> ALL x. 0 <= g x ==> 
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   240
  O(f + g) = O(f) \<oplus> O(g)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   241
  apply (rule equalityI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   242
  apply (rule bigo_plus_subset)
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   243
  apply (simp add: bigo_alt_def set_plus_def func_plus)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   244
  apply clarify 
36844
5f9385ecc1a7 Removed usage of normalizating locales.
hoelzl
parents: 36725
diff changeset
   245
(*sledgehammer*) 
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   246
  apply (rule_tac x = "max c ca" in exI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   247
  apply (rule conjI)
25087
5908591fb881 some more metis calls
paulson
parents: 25082
diff changeset
   248
   apply (metis Orderings.less_max_iff_disj)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   249
  apply clarify
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   250
  apply (drule_tac x = "xa" in spec)+
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   251
  apply (subgoal_tac "0 <= f xa + g xa")
23477
f4b83f03cac9 tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents: 23464
diff changeset
   252
  apply (simp add: ring_distribs)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   253
  apply (subgoal_tac "abs(a xa + b xa) <= abs(a xa) + abs(b xa)")
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   254
  apply (subgoal_tac "abs(a xa) + abs(b xa) <= 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   255
      max c ca * f xa + max c ca * g xa")
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   256
  apply (blast intro: order_trans)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   257
  defer 1
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   258
  apply (rule abs_triangle_ineq)
25087
5908591fb881 some more metis calls
paulson
parents: 25082
diff changeset
   259
  apply (metis add_nonneg_nonneg)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   260
  apply (rule add_mono)
39259
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   261
using [[ sledgehammer_problem_prefix = "BigO__bigo_plus_eq_simpler" ]]
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   262
  apply (metis le_maxI2 linorder_linear min_max.sup_absorb1 mult_right_mono xt1(6))
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   263
  apply (metis le_maxI2 linorder_not_le mult_le_cancel_right order_trans)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   264
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   265
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   266
declare [[ sledgehammer_problem_prefix = "BigO__bigo_bounded_alt" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   267
lemma bigo_bounded_alt: "ALL x. 0 <= f x ==> ALL x. f x <= c * g x ==> 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   268
    f : O(g)" 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   269
  apply (auto simp add: bigo_def)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   270
(* Version 1: one-line proof *)
35050
9f841f20dca6 renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
haftmann
parents: 35028
diff changeset
   271
  apply (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
   272
  done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   273
26312
e9a65675e5e8 avoid rebinding of existing facts;
wenzelm
parents: 26165
diff changeset
   274
lemma (*bigo_bounded_alt:*) "ALL x. 0 <= f x ==> ALL x. f x <= c * g x ==> 
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   275
    f : O(g)"
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   276
apply (auto simp add: bigo_def)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   277
(* Version 2: structured proof *)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   278
proof -
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   279
  assume "\<forall>x. f x \<le> c * g x"
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   280
  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
   281
qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   282
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   283
text{*So here is the easier (and more natural) problem using transitivity*}
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   284
declare [[ sledgehammer_problem_prefix = "BigO__bigo_bounded_alt_trans" ]]
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   285
lemma "ALL x. 0 <= f x ==> ALL x. f x <= c * g x ==> f : O(g)" 
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   286
apply (auto simp add: bigo_def)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   287
(* Version 1: one-line proof *)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   288
by (metis abs_ge_self abs_mult order_trans)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   289
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   290
text{*So here is the easier (and more natural) problem using transitivity*}
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   291
declare [[ sledgehammer_problem_prefix = "BigO__bigo_bounded_alt_trans" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   292
lemma "ALL x. 0 <= f x ==> ALL x. f x <= c * g x ==> f : O(g)" 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   293
  apply (auto simp add: bigo_def)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   294
(* Version 2: structured proof *)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   295
proof -
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   296
  assume "\<forall>x. f x \<le> c * g x"
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   297
  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
   298
qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   299
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   300
lemma bigo_bounded: "ALL x. 0 <= f x ==> ALL x. f x <= g x ==> 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   301
    f : O(g)" 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   302
  apply (erule bigo_bounded_alt [of f 1 g])
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   303
  apply simp
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   304
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   305
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   306
declare [[ sledgehammer_problem_prefix = "BigO__bigo_bounded2" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   307
lemma bigo_bounded2: "ALL x. lb x <= f x ==> ALL x. f x <= lb x + g x ==>
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   308
    f : lb +o O(g)"
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   309
apply (rule set_minus_imp_plus)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   310
apply (rule bigo_bounded)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   311
 apply (auto simp add: diff_minus fun_Compl_def func_plus)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   312
 prefer 2
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   313
 apply (drule_tac x = x in spec)+
36844
5f9385ecc1a7 Removed usage of normalizating locales.
hoelzl
parents: 36725
diff changeset
   314
 apply (metis add_right_mono add_commute diff_add_cancel diff_minus_eq_add le_less order_trans)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   315
proof -
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   316
  fix x :: 'a
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   317
  assume "\<forall>x. lb x \<le> f x"
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   318
  thus "(0\<Colon>'b) \<le> f x + - lb x" by (metis not_leE diff_minus less_iff_diff_less_0 less_le_not_le)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   319
qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   320
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   321
declare [[ sledgehammer_problem_prefix = "BigO__bigo_abs" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   322
lemma bigo_abs: "(%x. abs(f x)) =o O(f)" 
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   323
apply (unfold bigo_def)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   324
apply auto
36844
5f9385ecc1a7 Removed usage of normalizating locales.
hoelzl
parents: 36725
diff changeset
   325
by (metis mult_1 order_refl)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   326
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   327
declare [[ sledgehammer_problem_prefix = "BigO__bigo_abs2" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   328
lemma bigo_abs2: "f =o O(%x. abs(f x))"
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   329
apply (unfold bigo_def)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   330
apply auto
36844
5f9385ecc1a7 Removed usage of normalizating locales.
hoelzl
parents: 36725
diff changeset
   331
by (metis mult_1 order_refl)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   332
 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   333
lemma bigo_abs3: "O(f) = O(%x. abs(f x))"
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   334
proof -
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   335
  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
   336
  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
   337
  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
   338
  thus "O(f) = O(\<lambda>x. \<bar>f x\<bar>)" using F1 F2 by auto
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   339
qed 
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   340
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   341
lemma bigo_abs4: "f =o g +o O(h) ==> 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   342
    (%x. abs (f x)) =o (%x. abs (g x)) +o O(h)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   343
  apply (drule set_plus_imp_minus)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   344
  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
   345
  apply (subst fun_diff_def)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   346
proof -
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   347
  assume a: "f - g : O(h)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   348
  have "(%x. abs (f x) - abs (g x)) =o O(%x. abs(abs (f x) - abs (g x)))"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   349
    by (rule bigo_abs2)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   350
  also have "... <= O(%x. abs (f x - g x))"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   351
    apply (rule bigo_elt_subset)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   352
    apply (rule bigo_bounded)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   353
    apply force
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   354
    apply (rule allI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   355
    apply (rule abs_triangle_ineq3)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   356
    done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   357
  also have "... <= O(f - g)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   358
    apply (rule bigo_elt_subset)
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   359
    apply (subst fun_diff_def)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   360
    apply (rule bigo_abs)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   361
    done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   362
  also have "... <= O(h)"
23464
bc2563c37b1a tuned proofs -- avoid implicit prems;
wenzelm
parents: 23449
diff changeset
   363
    using a by (rule bigo_elt_subset)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   364
  finally show "(%x. abs (f x) - abs (g x)) : O(h)".
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   365
qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   366
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   367
lemma bigo_abs5: "f =o O(g) ==> (%x. abs(f x)) =o O(g)" 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   368
by (unfold bigo_def, auto)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   369
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   370
lemma bigo_elt_subset2 [intro]: "f : g +o O(h) ==> O(f) <= O(g) \<oplus> O(h)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   371
proof -
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   372
  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
   373
  also have "... <= O(g) \<oplus> O(h)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   374
    by (auto del: subsetI)
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   375
  also have "... = O(%x. abs(g x)) \<oplus> O(%x. abs(h x))"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   376
    apply (subst bigo_abs3 [symmetric])+
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   377
    apply (rule refl)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   378
    done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   379
  also have "... = O((%x. abs(g x)) + (%x. abs(h x)))"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   380
    by (rule bigo_plus_eq [symmetric], auto)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   381
  finally have "f : ...".
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   382
  then have "O(f) <= ..."
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   383
    by (elim bigo_elt_subset)
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   384
  also have "... = O(%x. abs(g x)) \<oplus> O(%x. abs(h x))"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   385
    by (rule bigo_plus_eq, auto)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   386
  finally show ?thesis
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   387
    by (simp add: bigo_abs3 [symmetric])
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   388
qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   389
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   390
declare [[ sledgehammer_problem_prefix = "BigO__bigo_mult" ]]
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   391
lemma bigo_mult [intro]: "O(f)\<otimes>O(g) <= O(f * g)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   392
  apply (rule subsetI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   393
  apply (subst bigo_def)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   394
  apply (auto simp del: abs_mult mult_ac
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   395
              simp add: bigo_alt_def set_times_def func_times)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   396
(*sledgehammer*); 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   397
  apply (rule_tac x = "c * ca" in exI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   398
  apply(rule allI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   399
  apply(erule_tac x = x in allE)+
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   400
  apply(subgoal_tac "c * ca * abs(f x * g x) = 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   401
      (c * abs(f x)) * (ca * abs(g x))")
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   402
using [[ sledgehammer_problem_prefix = "BigO__bigo_mult_simpler" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   403
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
   404
apply (metis mult_assoc mult_left_commute
35050
9f841f20dca6 renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
haftmann
parents: 35028
diff changeset
   405
  abs_of_pos mult_left_commute
9f841f20dca6 renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
haftmann
parents: 35028
diff changeset
   406
  abs_mult mult_pos_pos)
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
   407
  apply (erule ssubst) 
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   408
  apply (subst abs_mult)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   409
(* not quite as hard as BigO__bigo_mult_simpler_1 (a hard problem!) since
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   410
   abs_mult has just been done *)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   411
by (metis abs_ge_zero mult_mono')
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   412
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   413
declare [[ sledgehammer_problem_prefix = "BigO__bigo_mult2" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   414
lemma bigo_mult2 [intro]: "f *o O(g) <= O(f * g)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   415
  apply (auto simp add: bigo_def elt_set_times_def func_times abs_mult)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   416
(*sledgehammer*); 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   417
  apply (rule_tac x = c in exI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   418
  apply clarify
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   419
  apply (drule_tac x = x in spec)
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   420
using [[ sledgehammer_problem_prefix = "BigO__bigo_mult2_simpler" ]]
24942
39a23aadc7e1 more metis proofs
paulson
parents: 24937
diff changeset
   421
(*sledgehammer [no luck]*); 
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   422
  apply (subgoal_tac "abs(f x) * abs(b x) <= abs(f x) * (c * abs(g x))")
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   423
  apply (simp add: mult_ac)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   424
  apply (rule mult_left_mono, assumption)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   425
  apply (rule abs_ge_zero)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   426
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   427
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   428
declare [[ sledgehammer_problem_prefix = "BigO__bigo_mult3" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   429
lemma bigo_mult3: "f : O(h) ==> g : O(j) ==> f * g : O(h * j)"
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   430
by (metis bigo_mult set_rev_mp set_times_intro)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   431
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   432
declare [[ sledgehammer_problem_prefix = "BigO__bigo_mult4" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   433
lemma bigo_mult4 [intro]:"f : k +o O(h) ==> g * f : (g * k) +o O(g * h)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   434
by (metis bigo_mult2 set_plus_mono_b set_times_intro2 set_times_plus_distrib)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   435
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   436
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   437
lemma bigo_mult5: "ALL x. f x ~= 0 ==>
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33027
diff changeset
   438
    O(f * g) <= (f::'a => ('b::linordered_field)) *o O(g)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   439
proof -
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   440
  assume "ALL x. f x ~= 0"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   441
  show "O(f * g) <= f *o O(g)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   442
  proof
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   443
    fix h
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   444
    assume "h : O(f * g)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   445
    then have "(%x. 1 / (f x)) * h : (%x. 1 / f x) *o O(f * g)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   446
      by auto
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   447
    also have "... <= O((%x. 1 / f x) * (f * g))"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   448
      by (rule bigo_mult2)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   449
    also have "(%x. 1 / f x) * (f * g) = g"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   450
      apply (simp add: func_times) 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   451
      apply (rule ext)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   452
      apply (simp add: prems nonzero_divide_eq_eq mult_ac)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   453
      done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   454
    finally have "(%x. (1::'b) / f x) * h : O(g)".
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   455
    then have "f * ((%x. (1::'b) / f x) * h) : f *o O(g)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   456
      by auto
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   457
    also have "f * ((%x. (1::'b) / f x) * h) = h"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   458
      apply (simp add: func_times) 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   459
      apply (rule ext)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   460
      apply (simp add: prems nonzero_divide_eq_eq mult_ac)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   461
      done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   462
    finally show "h : f *o O(g)".
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   463
  qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   464
qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   465
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   466
declare [[ sledgehammer_problem_prefix = "BigO__bigo_mult6" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   467
lemma bigo_mult6: "ALL x. f x ~= 0 ==>
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33027
diff changeset
   468
    O(f * g) = (f::'a => ('b::linordered_field)) *o O(g)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   469
by (metis bigo_mult2 bigo_mult5 order_antisym)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   470
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   471
(*proof requires relaxing relevance: 2007-01-25*)
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   472
declare [[ sledgehammer_problem_prefix = "BigO__bigo_mult7" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   473
  declare bigo_mult6 [simp]
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   474
lemma bigo_mult7: "ALL x. f x ~= 0 ==>
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33027
diff changeset
   475
    O(f * g) <= O(f::'a => ('b::linordered_field)) \<otimes> O(g)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   476
(*sledgehammer*)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   477
  apply (subst bigo_mult6)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   478
  apply assumption
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   479
  apply (rule set_times_mono3) 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   480
  apply (rule bigo_refl)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   481
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   482
  declare bigo_mult6 [simp del]
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   483
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   484
declare [[ sledgehammer_problem_prefix = "BigO__bigo_mult8" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   485
  declare bigo_mult7[intro!]
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   486
lemma bigo_mult8: "ALL x. f x ~= 0 ==>
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33027
diff changeset
   487
    O(f * g) = O(f::'a => ('b::linordered_field)) \<otimes> O(g)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   488
by (metis bigo_mult bigo_mult7 order_antisym_conv)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   489
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   490
lemma bigo_minus [intro]: "f : O(g) ==> - f : O(g)"
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   491
  by (auto simp add: bigo_def fun_Compl_def)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   492
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   493
lemma bigo_minus2: "f : g +o O(h) ==> -f : -g +o O(h)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   494
  apply (rule set_minus_imp_plus)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   495
  apply (drule set_plus_imp_minus)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   496
  apply (drule bigo_minus)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   497
  apply (simp add: diff_minus)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   498
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   499
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   500
lemma bigo_minus3: "O(-f) = O(f)"
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   501
  by (auto simp add: bigo_def fun_Compl_def abs_minus_cancel)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   502
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   503
lemma bigo_plus_absorb_lemma1: "f : O(g) ==> f +o O(g) <= O(g)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   504
proof -
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   505
  assume a: "f : O(g)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   506
  show "f +o O(g) <= O(g)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   507
  proof -
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   508
    have "f : O(f)" by auto
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   509
    then have "f +o O(g) <= O(f) \<oplus> O(g)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   510
      by (auto del: subsetI)
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   511
    also have "... <= O(g) \<oplus> O(g)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   512
    proof -
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   513
      from a have "O(f) <= O(g)" by (auto del: subsetI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   514
      thus ?thesis by (auto del: subsetI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   515
    qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   516
    also have "... <= O(g)" by (simp add: bigo_plus_idemp)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   517
    finally show ?thesis .
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   518
  qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   519
qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   520
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   521
lemma bigo_plus_absorb_lemma2: "f : O(g) ==> O(g) <= f +o O(g)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   522
proof -
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   523
  assume a: "f : O(g)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   524
  show "O(g) <= f +o O(g)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   525
  proof -
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   526
    from a have "-f : O(g)" by auto
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   527
    then have "-f +o O(g) <= O(g)" by (elim bigo_plus_absorb_lemma1)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   528
    then have "f +o (-f +o O(g)) <= f +o O(g)" by auto
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   529
    also have "f +o (-f +o O(g)) = O(g)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   530
      by (simp add: set_plus_rearranges)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   531
    finally show ?thesis .
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   532
  qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   533
qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   534
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   535
declare [[ sledgehammer_problem_prefix = "BigO__bigo_plus_absorb" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   536
lemma bigo_plus_absorb [simp]: "f : O(g) ==> f +o O(g) = O(g)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   537
by (metis bigo_plus_absorb_lemma1 bigo_plus_absorb_lemma2 order_eq_iff);
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   538
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   539
lemma bigo_plus_absorb2 [intro]: "f : O(g) ==> A <= O(g) ==> f +o A <= O(g)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   540
  apply (subgoal_tac "f +o A <= f +o O(g)")
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   541
  apply force+
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   542
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   543
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   544
lemma bigo_add_commute_imp: "f : g +o O(h) ==> g : f +o O(h)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   545
  apply (subst set_minus_plus [symmetric])
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   546
  apply (subgoal_tac "g - f = - (f - g)")
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   547
  apply (erule ssubst)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   548
  apply (rule bigo_minus)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   549
  apply (subst set_minus_plus)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   550
  apply assumption
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   551
  apply  (simp add: diff_minus add_ac)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   552
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   553
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   554
lemma bigo_add_commute: "(f : g +o O(h)) = (g : f +o O(h))"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   555
  apply (rule iffI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   556
  apply (erule bigo_add_commute_imp)+
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   557
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   558
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   559
lemma bigo_const1: "(%x. c) : O(%x. 1)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   560
by (auto simp add: bigo_def mult_ac)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   561
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   562
declare [[ sledgehammer_problem_prefix = "BigO__bigo_const2" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   563
lemma (*bigo_const2 [intro]:*) "O(%x. c) <= O(%x. 1)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   564
by (metis bigo_const1 bigo_elt_subset);
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   565
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33027
diff changeset
   566
lemma bigo_const2 [intro]: "O(%x. c::'b::linordered_idom) <= O(%x. 1)";
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   567
(* "thus" had to be replaced by "show" with an explicit reference to "F1" *)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   568
proof -
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   569
  have F1: "\<forall>u. (\<lambda>Q. u) \<in> O(\<lambda>Q. 1)" by (metis bigo_const1)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   570
  show "O(\<lambda>x. c) \<subseteq> O(\<lambda>x. 1)" by (metis F1 bigo_elt_subset)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   571
qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   572
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   573
declare [[ sledgehammer_problem_prefix = "BigO__bigo_const3" ]]
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33027
diff changeset
   574
lemma bigo_const3: "(c::'a::linordered_field) ~= 0 ==> (%x. 1) : O(%x. c)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   575
apply (simp add: bigo_def)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   576
by (metis abs_eq_0 left_inverse order_refl)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   577
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33027
diff changeset
   578
lemma bigo_const4: "(c::'a::linordered_field) ~= 0 ==> O(%x. 1) <= O(%x. c)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   579
by (rule bigo_elt_subset, rule bigo_const3, assumption)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   580
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33027
diff changeset
   581
lemma bigo_const [simp]: "(c::'a::linordered_field) ~= 0 ==> 
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   582
    O(%x. c) = O(%x. 1)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   583
by (rule equalityI, rule bigo_const2, rule bigo_const4, assumption)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   584
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   585
declare [[ sledgehammer_problem_prefix = "BigO__bigo_const_mult1" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   586
lemma bigo_const_mult1: "(%x. c * f x) : O(f)"
24937
340523598914 context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents: 24855
diff changeset
   587
  apply (simp add: bigo_def abs_mult)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   588
by (metis le_less)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   589
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   590
lemma bigo_const_mult2: "O(%x. c * f x) <= O(f)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   591
by (rule bigo_elt_subset, rule bigo_const_mult1)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   592
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   593
declare [[ sledgehammer_problem_prefix = "BigO__bigo_const_mult3" ]]
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33027
diff changeset
   594
lemma bigo_const_mult3: "(c::'a::linordered_field) ~= 0 ==> f : O(%x. c * f x)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   595
  apply (simp add: bigo_def)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   596
(*sledgehammer [no luck]*)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   597
  apply (rule_tac x = "abs(inverse c)" in exI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   598
  apply (simp only: abs_mult [symmetric] mult_assoc [symmetric])
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   599
apply (subst left_inverse) 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   600
apply (auto ); 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   601
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   602
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33027
diff changeset
   603
lemma bigo_const_mult4: "(c::'a::linordered_field) ~= 0 ==> 
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   604
    O(f) <= O(%x. c * f x)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   605
by (rule bigo_elt_subset, rule bigo_const_mult3, assumption)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   606
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33027
diff changeset
   607
lemma bigo_const_mult [simp]: "(c::'a::linordered_field) ~= 0 ==> 
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   608
    O(%x. c * f x) = O(f)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   609
by (rule equalityI, rule bigo_const_mult2, erule bigo_const_mult4)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   610
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   611
declare [[ sledgehammer_problem_prefix = "BigO__bigo_const_mult5" ]]
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33027
diff changeset
   612
lemma bigo_const_mult5 [simp]: "(c::'a::linordered_field) ~= 0 ==> 
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   613
    (%x. c) *o O(f) = O(f)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   614
  apply (auto del: subsetI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   615
  apply (rule order_trans)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   616
  apply (rule bigo_mult2)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   617
  apply (simp add: func_times)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   618
  apply (auto intro!: subsetI simp add: bigo_def elt_set_times_def func_times)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   619
  apply (rule_tac x = "%y. inverse c * x y" in exI)
24942
39a23aadc7e1 more metis proofs
paulson
parents: 24937
diff changeset
   620
  apply (rename_tac g d) 
39a23aadc7e1 more metis proofs
paulson
parents: 24937
diff changeset
   621
  apply safe
39a23aadc7e1 more metis proofs
paulson
parents: 24937
diff changeset
   622
  apply (rule_tac [2] ext) 
39a23aadc7e1 more metis proofs
paulson
parents: 24937
diff changeset
   623
   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
   624
   apply simp
24942
39a23aadc7e1 more metis proofs
paulson
parents: 24937
diff changeset
   625
  apply (simp add: mult_assoc [symmetric] abs_mult)
39259
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   626
  (* couldn't get this proof without the step above *)
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   627
proof -
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   628
  fix g :: "'b \<Rightarrow> 'a" and d :: 'a
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   629
  assume A1: "c \<noteq> (0\<Colon>'a)"
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   630
  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
   631
  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
   632
  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
   633
  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
   634
  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
   635
  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
   636
  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
   637
    using A2 by metis
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   638
  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
   639
    using F3 by metis
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   640
  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
   641
    by (metis comm_mult_left_mono)
194014eb4f9f replace two slow "metis" proofs with faster proofs
blanchet
parents: 38991
diff changeset
   642
  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
   643
    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
   644
qed
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   645
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   646
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   647
declare [[ sledgehammer_problem_prefix = "BigO__bigo_const_mult6" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   648
lemma bigo_const_mult6 [intro]: "(%x. c) *o O(f) <= O(f)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   649
  apply (auto intro!: subsetI
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   650
    simp add: bigo_def elt_set_times_def func_times
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   651
    simp del: abs_mult mult_ac)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   652
(*sledgehammer*); 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   653
  apply (rule_tac x = "ca * (abs c)" in exI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   654
  apply (rule allI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   655
  apply (subgoal_tac "ca * abs(c) * abs(f x) = abs(c) * (ca * abs(f x))")
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   656
  apply (erule ssubst)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   657
  apply (subst abs_mult)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   658
  apply (rule mult_left_mono)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   659
  apply (erule spec)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   660
  apply simp
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   661
  apply(simp add: mult_ac)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   662
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   663
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   664
lemma bigo_const_mult7 [intro]: "f =o O(g) ==> (%x. c * f x) =o O(g)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   665
proof -
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   666
  assume "f =o O(g)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   667
  then have "(%x. c) * f =o (%x. c) *o O(g)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   668
    by auto
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   669
  also have "(%x. c) * f = (%x. c * f x)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   670
    by (simp add: func_times)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   671
  also have "(%x. c) *o O(g) <= O(g)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   672
    by (auto del: subsetI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   673
  finally show ?thesis .
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   674
qed
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   675
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   676
lemma bigo_compose1: "f =o O(g) ==> (%x. f(k x)) =o O(%x. g(k x))"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   677
by (unfold bigo_def, auto)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   678
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   679
lemma bigo_compose2: "f =o g +o O(h) ==> (%x. f(k x)) =o (%x. g(k x)) +o 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   680
    O(%x. h(k x))"
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   681
  apply (simp only: set_minus_plus [symmetric] diff_minus fun_Compl_def
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   682
      func_plus)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   683
  apply (erule bigo_compose1)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   684
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   685
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   686
subsection {* Setsum *}
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   687
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   688
lemma bigo_setsum_main: "ALL x. ALL y : A x. 0 <= h x y ==> 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   689
    EX c. ALL x. ALL y : A x. abs(f x y) <= c * (h x y) ==>
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   690
      (%x. SUM y : A x. f x y) =o O(%x. SUM y : A x. h x y)"  
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   691
  apply (auto simp add: bigo_def)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   692
  apply (rule_tac x = "abs c" in exI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   693
  apply (subst abs_of_nonneg) back back
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   694
  apply (rule setsum_nonneg)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   695
  apply force
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   696
  apply (subst setsum_right_distrib)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   697
  apply (rule allI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   698
  apply (rule order_trans)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   699
  apply (rule setsum_abs)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   700
  apply (rule setsum_mono)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   701
apply (blast intro: order_trans mult_right_mono abs_ge_self) 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   702
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   703
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   704
declare [[ sledgehammer_problem_prefix = "BigO__bigo_setsum1" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   705
lemma bigo_setsum1: "ALL x y. 0 <= h x y ==> 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   706
    EX c. ALL x y. abs(f x y) <= c * (h x y) ==>
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   707
      (%x. SUM y : A x. f x y) =o O(%x. SUM y : A x. h x y)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   708
  apply (rule bigo_setsum_main)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   709
(*sledgehammer*); 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   710
  apply force
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   711
  apply clarsimp
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   712
  apply (rule_tac x = c in exI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   713
  apply force
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   714
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   715
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   716
lemma bigo_setsum2: "ALL y. 0 <= h y ==> 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   717
    EX c. ALL y. abs(f y) <= c * (h y) ==>
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   718
      (%x. SUM y : A x. f y) =o O(%x. SUM y : A x. h y)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   719
by (rule bigo_setsum1, auto)  
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   720
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   721
declare [[ sledgehammer_problem_prefix = "BigO__bigo_setsum3" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   722
lemma bigo_setsum3: "f =o O(h) ==>
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   723
    (%x. SUM y : A x. (l x y) * f(k x y)) =o
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   724
      O(%x. SUM y : A x. abs(l x y * h(k x y)))"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   725
  apply (rule bigo_setsum1)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   726
  apply (rule allI)+
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   727
  apply (rule abs_ge_zero)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   728
  apply (unfold bigo_def)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   729
  apply (auto simp add: abs_mult);
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   730
(*sledgehammer*); 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   731
  apply (rule_tac x = c in exI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   732
  apply (rule allI)+
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   733
  apply (subst mult_left_commute)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   734
  apply (rule mult_left_mono)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   735
  apply (erule spec)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   736
  apply (rule abs_ge_zero)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   737
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   738
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   739
lemma bigo_setsum4: "f =o g +o O(h) ==>
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   740
    (%x. SUM y : A x. l x y * f(k x y)) =o
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   741
      (%x. SUM y : A x. l x y * g(k x y)) +o
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   742
        O(%x. SUM y : A x. abs(l x y * h(k x y)))"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   743
  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
   744
  apply (subst fun_diff_def)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   745
  apply (subst setsum_subtractf [symmetric])
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   746
  apply (subst right_diff_distrib [symmetric])
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   747
  apply (rule bigo_setsum3)
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   748
  apply (subst fun_diff_def [symmetric])
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   749
  apply (erule set_plus_imp_minus)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   750
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   751
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   752
declare [[ sledgehammer_problem_prefix = "BigO__bigo_setsum5" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   753
lemma bigo_setsum5: "f =o O(h) ==> ALL x y. 0 <= l x y ==> 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   754
    ALL x. 0 <= h x ==>
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   755
      (%x. SUM y : A x. (l x y) * f(k x y)) =o
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   756
        O(%x. SUM y : A x. (l x y) * h(k x y))" 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   757
  apply (subgoal_tac "(%x. SUM y : A x. (l x y) * h(k x y)) = 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   758
      (%x. SUM y : A x. abs((l x y) * h(k x y)))")
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   759
  apply (erule ssubst)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   760
  apply (erule bigo_setsum3)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   761
  apply (rule ext)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   762
  apply (rule setsum_cong2)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   763
  apply (thin_tac "f \<in> O(h)") 
24942
39a23aadc7e1 more metis proofs
paulson
parents: 24937
diff changeset
   764
apply (metis abs_of_nonneg zero_le_mult_iff)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   765
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   766
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   767
lemma bigo_setsum6: "f =o g +o O(h) ==> ALL x y. 0 <= l x y ==>
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   768
    ALL x. 0 <= h x ==>
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   769
      (%x. SUM y : A x. (l x y) * f(k x y)) =o
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   770
        (%x. SUM y : A x. (l x y) * g(k x y)) +o
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   771
          O(%x. SUM y : A x. (l x y) * h(k x y))" 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   772
  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
   773
  apply (subst fun_diff_def)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   774
  apply (subst setsum_subtractf [symmetric])
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   775
  apply (subst right_diff_distrib [symmetric])
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   776
  apply (rule bigo_setsum5)
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   777
  apply (subst fun_diff_def [symmetric])
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   778
  apply (drule set_plus_imp_minus)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   779
  apply auto
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   780
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   781
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   782
subsection {* Misc useful stuff *}
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   783
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   784
lemma bigo_useful_intro: "A <= O(f) ==> B <= O(f) ==>
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   785
  A \<oplus> B <= O(f)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   786
  apply (subst bigo_plus_idemp [symmetric])
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   787
  apply (rule set_plus_mono2)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   788
  apply assumption+
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   789
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   790
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   791
lemma bigo_useful_add: "f =o O(h) ==> g =o O(h) ==> f + g =o O(h)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   792
  apply (subst bigo_plus_idemp [symmetric])
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   793
  apply (rule set_plus_intro)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   794
  apply assumption+
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   795
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   796
  
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33027
diff changeset
   797
lemma bigo_useful_const_mult: "(c::'a::linordered_field) ~= 0 ==> 
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   798
    (%x. c) * f =o O(h) ==> f =o O(h)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   799
  apply (rule subsetD)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   800
  apply (subgoal_tac "(%x. 1 / c) *o O(h) <= O(h)")
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   801
  apply assumption
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   802
  apply (rule bigo_const_mult6)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   803
  apply (subgoal_tac "f = (%x. 1 / c) * ((%x. c) * f)")
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   804
  apply (erule ssubst)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   805
  apply (erule set_times_intro2)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   806
  apply (simp add: func_times) 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   807
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   808
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   809
declare [[ sledgehammer_problem_prefix = "BigO__bigo_fix" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   810
lemma bigo_fix: "(%x. f ((x::nat) + 1)) =o O(%x. h(x + 1)) ==> f 0 = 0 ==>
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   811
    f =o O(h)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   812
  apply (simp add: bigo_alt_def)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   813
(*sledgehammer*); 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   814
  apply clarify
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   815
  apply (rule_tac x = c in exI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   816
  apply safe
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   817
  apply (case_tac "x = 0")
35050
9f841f20dca6 renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
haftmann
parents: 35028
diff changeset
   818
apply (metis abs_ge_zero  abs_zero  order_less_le  split_mult_pos_le) 
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   819
  apply (subgoal_tac "x = Suc (x - 1)")
23816
3879cb3d0ba7 tidied using sledgehammer
paulson
parents: 23519
diff changeset
   820
  apply metis
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   821
  apply simp
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   822
  done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   823
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   824
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   825
lemma bigo_fix2: 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   826
    "(%x. f ((x::nat) + 1)) =o (%x. g(x + 1)) +o O(%x. h(x + 1)) ==> 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   827
       f 0 = g 0 ==> f =o g +o O(h)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   828
  apply (rule set_minus_imp_plus)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   829
  apply (rule bigo_fix)
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   830
  apply (subst fun_diff_def)
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   831
  apply (subst fun_diff_def [symmetric])
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   832
  apply (rule set_plus_imp_minus)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   833
  apply simp
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   834
  apply (simp add: fun_diff_def)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   835
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   836
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   837
subsection {* Less than or equal to *}
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   838
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 35050
diff changeset
   839
definition lesso :: "('a => 'b::linordered_idom) => ('a => 'b) => ('a => 'b)" (infixl "<o" 70) where
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   840
  "f <o g == (%x. max (f x - g x) 0)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   841
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   842
lemma bigo_lesseq1: "f =o O(h) ==> ALL x. abs (g x) <= abs (f x) ==>
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   843
    g =o O(h)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   844
  apply (unfold bigo_def)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   845
  apply clarsimp
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   846
apply (blast intro: order_trans) 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   847
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   848
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   849
lemma bigo_lesseq2: "f =o O(h) ==> ALL x. abs (g x) <= f x ==>
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   850
      g =o O(h)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   851
  apply (erule bigo_lesseq1)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   852
apply (blast intro: abs_ge_self order_trans) 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   853
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   854
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   855
lemma bigo_lesseq3: "f =o O(h) ==> ALL x. 0 <= g x ==> ALL x. g x <= f x ==>
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   856
      g =o O(h)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   857
  apply (erule bigo_lesseq2)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   858
  apply (rule allI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   859
  apply (subst abs_of_nonneg)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   860
  apply (erule spec)+
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   861
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   862
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   863
lemma bigo_lesseq4: "f =o O(h) ==>
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   864
    ALL x. 0 <= g x ==> ALL x. g x <= abs (f x) ==>
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   865
      g =o O(h)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   866
  apply (erule bigo_lesseq1)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   867
  apply (rule allI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   868
  apply (subst abs_of_nonneg)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   869
  apply (erule spec)+
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   870
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   871
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   872
declare [[ sledgehammer_problem_prefix = "BigO__bigo_lesso1" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   873
lemma bigo_lesso1: "ALL x. f x <= g x ==> f <o g =o O(h)"
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   874
apply (unfold lesso_def)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   875
apply (subgoal_tac "(%x. max (f x - g x) 0) = 0")
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   876
proof -
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   877
  assume "(\<lambda>x. max (f x - g x) 0) = 0"
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   878
  thus "(\<lambda>x. max (f x - g x) 0) \<in> O(h)" by (metis bigo_zero)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   879
next
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   880
  show "\<forall>x\<Colon>'a. f x \<le> g x \<Longrightarrow> (\<lambda>x\<Colon>'a. max (f x - g x) (0\<Colon>'b)) = (0\<Colon>'a \<Rightarrow> 'b)"
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   881
  apply (unfold func_zero)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   882
  apply (rule ext)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   883
  by (simp split: split_max)
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   884
qed
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   885
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   886
declare [[ sledgehammer_problem_prefix = "BigO__bigo_lesso2" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   887
lemma bigo_lesso2: "f =o g +o O(h) ==>
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   888
    ALL x. 0 <= k x ==> ALL x. k x <= f x ==>
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   889
      k <o g =o O(h)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   890
  apply (unfold lesso_def)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   891
  apply (rule bigo_lesseq4)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   892
  apply (erule set_plus_imp_minus)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   893
  apply (rule allI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   894
  apply (rule le_maxI2)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   895
  apply (rule allI)
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   896
  apply (subst fun_diff_def)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   897
apply (erule thin_rl)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   898
(*sledgehammer*);  
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   899
  apply (case_tac "0 <= k x - g x")
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   900
(* apply (metis abs_le_iff add_le_imp_le_right diff_minus le_less
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   901
                le_max_iff_disj min_max.le_supE min_max.sup_absorb2
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   902
                min_max.sup_commute) *)
37320
06c7a2f231fe kill another neg_clausify proof
blanchet
parents: 36925
diff changeset
   903
proof -
06c7a2f231fe kill another neg_clausify proof
blanchet
parents: 36925
diff changeset
   904
  fix x :: 'a
06c7a2f231fe kill another neg_clausify proof
blanchet
parents: 36925
diff changeset
   905
  assume "\<forall>x\<Colon>'a. k x \<le> f x"
06c7a2f231fe kill another neg_clausify proof
blanchet
parents: 36925
diff changeset
   906
  hence F1: "\<forall>x\<^isub>1\<Colon>'a. max (k x\<^isub>1) (f x\<^isub>1) = f x\<^isub>1" by (metis min_max.sup_absorb2)
06c7a2f231fe kill another neg_clausify proof
blanchet
parents: 36925
diff changeset
   907
  assume "(0\<Colon>'b) \<le> k x - g x"
06c7a2f231fe kill another neg_clausify proof
blanchet
parents: 36925
diff changeset
   908
  hence F2: "max (0\<Colon>'b) (k x - g x) = k x - g x" by (metis min_max.sup_absorb2)
06c7a2f231fe kill another neg_clausify proof
blanchet
parents: 36925
diff changeset
   909
  have F3: "\<forall>x\<^isub>1\<Colon>'b. x\<^isub>1 \<le> \<bar>x\<^isub>1\<bar>" by (metis abs_le_iff le_less)
06c7a2f231fe kill another neg_clausify proof
blanchet
parents: 36925
diff changeset
   910
  have "\<forall>(x\<^isub>2\<Colon>'b) x\<^isub>1\<Colon>'b. max x\<^isub>1 x\<^isub>2 \<le> x\<^isub>2 \<or> max x\<^isub>1 x\<^isub>2 \<le> x\<^isub>1" by (metis le_less le_max_iff_disj)
06c7a2f231fe kill another neg_clausify proof
blanchet
parents: 36925
diff changeset
   911
  hence "\<forall>(x\<^isub>3\<Colon>'b) (x\<^isub>2\<Colon>'b) x\<^isub>1\<Colon>'b. x\<^isub>1 - x\<^isub>2 \<le> x\<^isub>3 - x\<^isub>2 \<or> x\<^isub>3 \<le> x\<^isub>1" by (metis add_le_imp_le_right diff_minus min_max.le_supE)
06c7a2f231fe kill another neg_clausify proof
blanchet
parents: 36925
diff changeset
   912
  hence "k x - g x \<le> f x - g x" by (metis F1 le_less min_max.sup_absorb2 min_max.sup_commute)
06c7a2f231fe kill another neg_clausify proof
blanchet
parents: 36925
diff changeset
   913
  hence "k x - g x \<le> \<bar>f x - g x\<bar>" by (metis F3 le_max_iff_disj min_max.sup_absorb2)
06c7a2f231fe kill another neg_clausify proof
blanchet
parents: 36925
diff changeset
   914
  thus "max (k x - g x) (0\<Colon>'b) \<le> \<bar>f x - g x\<bar>" by (metis F2 min_max.sup_commute)
36561
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   915
next
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   916
  show "\<And>x\<Colon>'a.
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   917
       \<lbrakk>\<forall>x\<Colon>'a. (0\<Colon>'b) \<le> k x; \<forall>x\<Colon>'a. k x \<le> f x; \<not> (0\<Colon>'b) \<le> k x - g x\<rbrakk>
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   918
       \<Longrightarrow> max (k x - g x) (0\<Colon>'b) \<le> \<bar>f x - g x\<bar>"
f91c71982811 redo more Metis/Sledgehammer example
blanchet
parents: 36498
diff changeset
   919
    by (metis abs_ge_zero le_cases min_max.sup_absorb2)
24545
f406a5744756 new proofs found
paulson
parents: 23816
diff changeset
   920
qed
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   921
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   922
declare [[ sledgehammer_problem_prefix = "BigO__bigo_lesso3" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   923
lemma bigo_lesso3: "f =o g +o O(h) ==>
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   924
    ALL x. 0 <= k x ==> ALL x. g x <= k x ==>
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   925
      f <o k =o O(h)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   926
  apply (unfold lesso_def)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   927
  apply (rule bigo_lesseq4)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   928
  apply (erule set_plus_imp_minus)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   929
  apply (rule allI)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   930
  apply (rule le_maxI2)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   931
  apply (rule allI)
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   932
  apply (subst fun_diff_def)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   933
apply (erule thin_rl) 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   934
(*sledgehammer*); 
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   935
  apply (case_tac "0 <= f x - k x")
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29511
diff changeset
   936
  apply (simp)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   937
  apply (subst abs_of_nonneg)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   938
  apply (drule_tac x = x in spec) back
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   939
using [[ sledgehammer_problem_prefix = "BigO__bigo_lesso3_simpler" ]]
24545
f406a5744756 new proofs found
paulson
parents: 23816
diff changeset
   940
apply (metis diff_less_0_iff_less linorder_not_le not_leE uminus_add_conv_diff xt1(12) xt1(6))
f406a5744756 new proofs found
paulson
parents: 23816
diff changeset
   941
apply (metis add_minus_cancel diff_le_eq le_diff_eq uminus_add_conv_diff)
29511
7071b017cb35 migrated class package to new locale implementation
haftmann
parents: 28592
diff changeset
   942
apply (metis abs_ge_zero linorder_linear min_max.sup_absorb1 min_max.sup_commute)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   943
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   944
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33027
diff changeset
   945
lemma bigo_lesso4: "f <o g =o O(k::'a=>'b::linordered_field) ==>
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   946
    g =o h +o O(k) ==> f <o h =o O(k)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   947
  apply (unfold lesso_def)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   948
  apply (drule set_plus_imp_minus)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   949
  apply (drule bigo_abs5) back
26814
b3e8d5ec721d Replaced + and * on sets by \<oplus> and \<otimes>, to avoid clash with
berghofe
parents: 26645
diff changeset
   950
  apply (simp add: fun_diff_def)
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   951
  apply (drule bigo_useful_add)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   952
  apply assumption
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   953
  apply (erule bigo_lesseq2) back
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   954
  apply (rule allI)
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29511
diff changeset
   955
  apply (auto simp add: func_plus fun_diff_def algebra_simps
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   956
    split: split_max abs_split)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   957
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   958
38991
0e2798f30087 rename sledgehammer config attributes
blanchet
parents: 38622
diff changeset
   959
declare [[ sledgehammer_problem_prefix = "BigO__bigo_lesso5" ]]
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   960
lemma bigo_lesso5: "f <o g =o O(h) ==>
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   961
    EX C. ALL x. f x <= g x + C * abs(h x)"
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   962
  apply (simp only: lesso_def bigo_alt_def)
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   963
  apply clarsimp
24855
161eb8381b49 metis method: used theorems
paulson
parents: 24545
diff changeset
   964
  apply (metis abs_if abs_mult add_commute diff_le_eq less_not_permute)  
23449
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   965
done
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   966
dd874e6a3282 integration of Metis prover
paulson
parents:
diff changeset
   967
end