src/HOL/Inequalities.thy
author haftmann
Tue, 13 Oct 2015 09:21:15 +0200
changeset 61424 c3658c18b7bc
parent 60758 d8d85a8172b5
child 61609 77b453bd616f
permissions -rw-r--r--
prod_case as canonical name for product type eliminator
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59720
f893472fff31 proper headers;
wenzelm
parents: 59712
diff changeset
     1
(*  Title:     HOL/Inequalities.thy
59712
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
     2
    Author:    Tobias Nipkow
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
     3
    Author:    Johannes Hölzl
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
     4
*)
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
     5
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
     6
theory Inequalities
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
     7
  imports Real_Vector_Spaces
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
     8
begin
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
     9
60167
9a97407488cd simplified statement and proof
nipkow
parents: 60150
diff changeset
    10
lemma Setsum_Icc_int: "(m::int) \<le> n \<Longrightarrow> \<Sum> {m..n} = (n*(n+1) - m*(m-1)) div 2"
9a97407488cd simplified statement and proof
nipkow
parents: 60150
diff changeset
    11
proof(induct i == "nat(n-m)" arbitrary: m n)
9a97407488cd simplified statement and proof
nipkow
parents: 60150
diff changeset
    12
  case 0
9a97407488cd simplified statement and proof
nipkow
parents: 60150
diff changeset
    13
  hence "m = n" by arith
9a97407488cd simplified statement and proof
nipkow
parents: 60150
diff changeset
    14
  thus ?case by (simp add: algebra_simps)
9a97407488cd simplified statement and proof
nipkow
parents: 60150
diff changeset
    15
next
9a97407488cd simplified statement and proof
nipkow
parents: 60150
diff changeset
    16
  case (Suc i)
9a97407488cd simplified statement and proof
nipkow
parents: 60150
diff changeset
    17
  have 0: "i = nat((n-1) - m)" "m \<le> n-1" using Suc(2,3) by arith+
9a97407488cd simplified statement and proof
nipkow
parents: 60150
diff changeset
    18
  have "\<Sum> {m..n} = \<Sum> {m..1+(n-1)}" by simp
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60167
diff changeset
    19
  also have "\<dots> = \<Sum> {m..n-1} + n" using \<open>m \<le> n\<close>
60167
9a97407488cd simplified statement and proof
nipkow
parents: 60150
diff changeset
    20
    by(subst atLeastAtMostPlus1_int_conv) simp_all
9a97407488cd simplified statement and proof
nipkow
parents: 60150
diff changeset
    21
  also have "\<dots> = ((n-1)*(n-1+1) - m*(m-1)) div 2 + n"
9a97407488cd simplified statement and proof
nipkow
parents: 60150
diff changeset
    22
    by(simp add: Suc(1)[OF 0])
9a97407488cd simplified statement and proof
nipkow
parents: 60150
diff changeset
    23
  also have "\<dots> = ((n-1)*(n-1+1) - m*(m-1) + 2*n) div 2" by simp
9a97407488cd simplified statement and proof
nipkow
parents: 60150
diff changeset
    24
  also have "\<dots> = (n*(n+1) - m*(m-1)) div 2" by(simp add: algebra_simps)
9a97407488cd simplified statement and proof
nipkow
parents: 60150
diff changeset
    25
  finally show ?case .
59712
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    26
qed
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    27
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    28
lemma Setsum_Icc_nat: assumes "(m::nat) \<le> n"
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    29
shows "\<Sum> {m..n} = (n*(n+1) - m*(m-1)) div 2"
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    30
proof -
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    31
  have "m*(m-1) \<le> n*(n + 1)"
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    32
   using assms by (meson diff_le_self order_trans le_add1 mult_le_mono)
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    33
  hence "int(\<Sum> {m..n}) = int((n*(n+1) - m*(m-1)) div 2)" using assms
60167
9a97407488cd simplified statement and proof
nipkow
parents: 60150
diff changeset
    34
    by (auto simp: Setsum_Icc_int[transferred, OF assms] zdiv_int int_mult
59712
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    35
      split: zdiff_int_split)
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    36
  thus ?thesis by simp
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    37
qed
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    38
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    39
lemma Setsum_Ico_nat: assumes "(m::nat) \<le> n"
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    40
shows "\<Sum> {m..<n} = (n*(n-1) - m*(m-1)) div 2"
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    41
proof cases
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    42
  assume "m < n"
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    43
  hence "{m..<n} = {m..n-1}" by auto
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    44
  hence "\<Sum>{m..<n} = \<Sum>{m..n-1}" by simp
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    45
  also have "\<dots> = (n*(n-1) - m*(m-1)) div 2"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60167
diff changeset
    46
    using assms \<open>m < n\<close> by (simp add: Setsum_Icc_nat mult.commute)
59712
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    47
  finally show ?thesis .
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    48
next
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    49
  assume "\<not> m < n" with assms show ?thesis by simp
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    50
qed
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    51
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    52
lemma Chebyshev_sum_upper:
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    53
  fixes a b::"nat \<Rightarrow> 'a::linordered_idom"
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    54
  assumes "\<And>i j. i \<le> j \<Longrightarrow> j < n \<Longrightarrow> a i \<le> a j"
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    55
  assumes "\<And>i j. i \<le> j \<Longrightarrow> j < n \<Longrightarrow> b i \<ge> b j"
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    56
  shows "of_nat n * (\<Sum>k=0..<n. a k * b k) \<le> (\<Sum>k=0..<n. a k) * (\<Sum>k=0..<n. b k)"
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    57
proof -
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    58
  let ?S = "(\<Sum>j=0..<n. (\<Sum>k=0..<n. (a j - a k) * (b j - b k)))"
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    59
  have "2 * (of_nat n * (\<Sum>j=0..<n. (a j * b j)) - (\<Sum>j=0..<n. b j) * (\<Sum>k=0..<n. a k)) = ?S"
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    60
    unfolding one_add_one[symmetric] algebra_simps
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    61
    by (simp add: algebra_simps setsum_subtractf setsum.distrib setsum.commute[of "\<lambda>i j. a i * b j"] setsum_right_distrib)
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    62
  also
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    63
  { fix i j::nat assume "i<n" "j<n"
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    64
    hence "a i - a j \<le> 0 \<and> b i - b j \<ge> 0 \<or> a i - a j \<ge> 0 \<and> b i - b j \<le> 0"
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    65
      using assms by (cases "i \<le> j") (auto simp: algebra_simps)
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    66
  } hence "?S \<le> 0"
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    67
    by (auto intro!: setsum_nonpos simp: mult_le_0_iff)
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    68
       (auto simp: field_simps)
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    69
  finally show ?thesis by (simp add: algebra_simps)
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    70
qed
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    71
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    72
lemma Chebyshev_sum_upper_nat:
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    73
  fixes a b :: "nat \<Rightarrow> nat"
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    74
  shows "(\<And>i j. \<lbrakk> i\<le>j; j<n \<rbrakk> \<Longrightarrow> a i \<le> a j) \<Longrightarrow>
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    75
         (\<And>i j. \<lbrakk> i\<le>j; j<n \<rbrakk> \<Longrightarrow> b i \<ge> b j) \<Longrightarrow>
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    76
    n * (\<Sum>i=0..<n. a i * b i) \<le> (\<Sum>i=0..<n. a i) * (\<Sum>i=0..<n. b i)"
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    77
using Chebyshev_sum_upper[where 'a=real, of n a b]
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    78
by (simp del: real_of_nat_mult real_of_nat_setsum
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    79
  add: real_of_nat_mult[symmetric] real_of_nat_setsum[symmetric] real_of_nat_def[symmetric])
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    80
6c013328b885 add inequalities (move from AFP/Amortized_Complexity)
hoelzl
parents:
diff changeset
    81
end