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