src/HOL/Matrix_LP/LP.thy
author wenzelm
Tue Oct 10 19:23:03 2017 +0200 (2017-10-10)
changeset 66831 29ea2b900a05
parent 66453 cc19f7ca2ed6
permissions -rw-r--r--
tuned: each session has at most one defining entry;
wenzelm@47455
     1
(*  Title:      HOL/Matrix_LP/LP.thy
obua@19453
     2
    Author:     Steven Obua
obua@19453
     3
*)
obua@19453
     4
obua@19453
     5
theory LP 
wenzelm@66453
     6
imports Main "HOL-Library.Lattice_Algebras"
obua@19453
     7
begin
obua@19453
     8
haftmann@37884
     9
lemma le_add_right_mono: 
haftmann@37884
    10
  assumes 
haftmann@37884
    11
  "a <= b + (c::'a::ordered_ab_group_add)"
haftmann@37884
    12
  "c <= d"    
haftmann@37884
    13
  shows "a <= b + d"
haftmann@37884
    14
  apply (rule_tac order_trans[where y = "b+c"])
wenzelm@41550
    15
  apply (simp_all add: assms)
haftmann@37884
    16
  done
haftmann@37884
    17
obua@19453
    18
lemma linprog_dual_estimate:
obua@19453
    19
  assumes
haftmann@35028
    20
  "A * x \<le> (b::'a::lattice_ring)"
obua@19453
    21
  "0 \<le> y"
wenzelm@61945
    22
  "\<bar>A - A'\<bar> \<le> \<delta>_A"
obua@19453
    23
  "b \<le> b'"
wenzelm@61945
    24
  "\<bar>c - c'\<bar> \<le> \<delta>_c"
wenzelm@61945
    25
  "\<bar>x\<bar> \<le> r"
obua@19453
    26
  shows
wenzelm@61945
    27
  "c * x \<le> y * b' + (y * \<delta>_A + \<bar>y * A' - c'\<bar> + \<delta>_c) * r"
obua@19453
    28
proof -
wenzelm@41550
    29
  from assms have 1: "y * b <= y * b'" by (simp add: mult_left_mono)
wenzelm@41550
    30
  from assms have 2: "y * (A * x) <= y * b" by (simp add: mult_left_mono) 
nipkow@29667
    31
  have 3: "y * (A * x) = c * x + (y * (A - A') + (y * A' - c') + (c'-c)) * x" by (simp add: algebra_simps)  
obua@19453
    32
  from 1 2 3 have 4: "c * x + (y * (A - A') + (y * A' - c') + (c'-c)) * x <= y * b'" by simp
wenzelm@61945
    33
  have 5: "c * x <= y * b' + \<bar>(y * (A - A') + (y * A' - c') + (c'-c)) * x\<bar>"
obua@19453
    34
    by (simp only: 4 estimate_by_abs)  
wenzelm@61945
    35
  have 6: "\<bar>(y * (A - A') + (y * A' - c') + (c'-c)) * x\<bar> <= \<bar>y * (A - A') + (y * A' - c') + (c'-c)\<bar> * \<bar>x\<bar>"
obua@19453
    36
    by (simp add: abs_le_mult)
wenzelm@61945
    37
  have 7: "(\<bar>y * (A - A') + (y * A' - c') + (c'-c)\<bar>) * \<bar>x\<bar> <= (\<bar>y * (A-A') + (y*A'-c')\<bar> + \<bar>c' - c\<bar>) * \<bar>x\<bar>"
obua@19453
    38
    by(rule abs_triangle_ineq [THEN mult_right_mono]) simp
wenzelm@61945
    39
  have 8: "(\<bar>y * (A-A') + (y*A'-c')\<bar> + \<bar>c' - c\<bar>) * \<bar>x\<bar> <= (\<bar>y * (A-A')\<bar> + \<bar>y*A'-c'\<bar> + \<bar>c' - c\<bar>) * \<bar>x\<bar>"
obua@19453
    40
    by (simp add: abs_triangle_ineq mult_right_mono)    
wenzelm@61945
    41
  have 9: "(\<bar>y * (A-A')\<bar> + \<bar>y*A'-c'\<bar> + \<bar>c'-c\<bar>) * \<bar>x\<bar> <= (\<bar>y\<bar> * \<bar>A-A'\<bar> + \<bar>y*A'-c'\<bar> + \<bar>c'-c\<bar>) * \<bar>x\<bar>"
obua@19453
    42
    by (simp add: abs_le_mult mult_right_mono)  
nipkow@29667
    43
  have 10: "c'-c = -(c-c')" by (simp add: algebra_simps)
wenzelm@61945
    44
  have 11: "\<bar>c'-c\<bar> = \<bar>c-c'\<bar>"
obua@19453
    45
    by (subst 10, subst abs_minus_cancel, simp)
wenzelm@61945
    46
  have 12: "(\<bar>y\<bar> * \<bar>A-A'\<bar> + \<bar>y*A'-c'\<bar> + \<bar>c'-c\<bar>) * \<bar>x\<bar> <= (\<bar>y\<bar> * \<bar>A-A'\<bar> + \<bar>y*A'-c'\<bar> + \<delta>_c) * \<bar>x\<bar>"
wenzelm@41550
    47
    by (simp add: 11 assms mult_right_mono)
wenzelm@61945
    48
  have 13: "(\<bar>y\<bar> * \<bar>A-A'\<bar> + \<bar>y*A'-c'\<bar> + \<delta>_c) * \<bar>x\<bar> <= (\<bar>y\<bar> * \<delta>_A + \<bar>y*A'-c'\<bar> + \<delta>_c) * \<bar>x\<bar>"
wenzelm@41550
    49
    by (simp add: assms mult_right_mono mult_left_mono)  
wenzelm@61945
    50
  have r: "(\<bar>y\<bar> * \<delta>_A + \<bar>y*A'-c'\<bar> + \<delta>_c) * \<bar>x\<bar> <= (\<bar>y\<bar> * \<delta>_A + \<bar>y*A'-c'\<bar> + \<delta>_c) * r"
obua@19453
    51
    apply (rule mult_left_mono)
wenzelm@41550
    52
    apply (simp add: assms)
obua@19453
    53
    apply (rule_tac add_mono[of "0::'a" _ "0", simplified])+
wenzelm@50252
    54
    apply (rule mult_left_mono[of "0" "\<delta>_A", simplified])
obua@19453
    55
    apply (simp_all)
wenzelm@61945
    56
    apply (rule order_trans[where y="\<bar>A-A'\<bar>"], simp_all add: assms)
wenzelm@61945
    57
    apply (rule order_trans[where y="\<bar>c-c'\<bar>"], simp_all add: assms)
obua@19453
    58
    done    
wenzelm@61945
    59
  from 6 7 8 9 12 13 r have 14: "\<bar>(y * (A - A') + (y * A' - c') + (c'-c)) * x\<bar> <= (\<bar>y\<bar> * \<delta>_A + \<bar>y*A'-c'\<bar> + \<delta>_c) * r"
obua@19453
    60
    by (simp)
haftmann@37884
    61
  show ?thesis
wenzelm@61945
    62
    apply (rule le_add_right_mono[of _ _ "\<bar>(y * (A - A') + (y * A' - c') + (c'-c)) * x\<bar>"])
wenzelm@41550
    63
    apply (simp_all only: 5 14[simplified abs_of_nonneg[of y, simplified assms]])
obua@19453
    64
    done
obua@19453
    65
qed
obua@19453
    66
obua@19453
    67
lemma le_ge_imp_abs_diff_1:
obua@19453
    68
  assumes
haftmann@35028
    69
  "A1 <= (A::'a::lattice_ring)"
obua@19453
    70
  "A <= A2" 
wenzelm@61945
    71
  shows "\<bar>A-A1\<bar> <= A2-A1"
obua@19453
    72
proof -
obua@19453
    73
  have "0 <= A - A1"    
obua@19453
    74
  proof -
haftmann@54230
    75
    from assms add_right_mono [of A1 A "- A1"] show ?thesis by simp
obua@19453
    76
  qed
wenzelm@61945
    77
  then have "\<bar>A-A1\<bar> = A-A1" by (rule abs_of_nonneg)
wenzelm@61945
    78
  with assms show "\<bar>A-A1\<bar> <= (A2-A1)" by simp
obua@19453
    79
qed
obua@19453
    80
obua@19453
    81
lemma mult_le_prts:
obua@19453
    82
  assumes
haftmann@35028
    83
  "a1 <= (a::'a::lattice_ring)"
obua@19453
    84
  "a <= a2"
obua@19453
    85
  "b1 <= b"
obua@19453
    86
  "b <= b2"
obua@19453
    87
  shows
obua@19453
    88
  "a * b <= pprt a2 * pprt b2 + pprt a1 * nprt b2 + nprt a2 * pprt b1 + nprt a1 * nprt b1"
obua@19453
    89
proof - 
obua@19453
    90
  have "a * b = (pprt a + nprt a) * (pprt b + nprt b)" 
obua@19453
    91
    apply (subst prts[symmetric])+
obua@19453
    92
    apply simp
obua@19453
    93
    done
obua@19453
    94
  then have "a * b = pprt a * pprt b + pprt a * nprt b + nprt a * pprt b + nprt a * nprt b"
nipkow@29667
    95
    by (simp add: algebra_simps)
obua@19453
    96
  moreover have "pprt a * pprt b <= pprt a2 * pprt b2"
wenzelm@41550
    97
    by (simp_all add: assms mult_mono)
obua@19453
    98
  moreover have "pprt a * nprt b <= pprt a1 * nprt b2"
obua@19453
    99
  proof -
obua@19453
   100
    have "pprt a * nprt b <= pprt a * nprt b2"
wenzelm@41550
   101
      by (simp add: mult_left_mono assms)
obua@19453
   102
    moreover have "pprt a * nprt b2 <= pprt a1 * nprt b2"
wenzelm@41550
   103
      by (simp add: mult_right_mono_neg assms)
obua@19453
   104
    ultimately show ?thesis
obua@19453
   105
      by simp
obua@19453
   106
  qed
obua@19453
   107
  moreover have "nprt a * pprt b <= nprt a2 * pprt b1"
obua@19453
   108
  proof - 
obua@19453
   109
    have "nprt a * pprt b <= nprt a2 * pprt b"
wenzelm@41550
   110
      by (simp add: mult_right_mono assms)
obua@19453
   111
    moreover have "nprt a2 * pprt b <= nprt a2 * pprt b1"
wenzelm@41550
   112
      by (simp add: mult_left_mono_neg assms)
obua@19453
   113
    ultimately show ?thesis
obua@19453
   114
      by simp
obua@19453
   115
  qed
obua@19453
   116
  moreover have "nprt a * nprt b <= nprt a1 * nprt b1"
obua@19453
   117
  proof -
obua@19453
   118
    have "nprt a * nprt b <= nprt a * nprt b1"
wenzelm@41550
   119
      by (simp add: mult_left_mono_neg assms)
obua@19453
   120
    moreover have "nprt a * nprt b1 <= nprt a1 * nprt b1"
wenzelm@41550
   121
      by (simp add: mult_right_mono_neg assms)
obua@19453
   122
    ultimately show ?thesis
obua@19453
   123
      by simp
obua@19453
   124
  qed
obua@19453
   125
  ultimately show ?thesis
obua@19453
   126
    by - (rule add_mono | simp)+
obua@19453
   127
qed
obua@19453
   128
    
obua@19453
   129
lemma mult_le_dual_prts: 
obua@19453
   130
  assumes
haftmann@35028
   131
  "A * x \<le> (b::'a::lattice_ring)"
obua@19453
   132
  "0 \<le> y"
obua@19453
   133
  "A1 \<le> A"
obua@19453
   134
  "A \<le> A2"
obua@19453
   135
  "c1 \<le> c"
obua@19453
   136
  "c \<le> c2"
obua@19453
   137
  "r1 \<le> x"
obua@19453
   138
  "x \<le> r2"
obua@19453
   139
  shows
obua@19453
   140
  "c * x \<le> y * b + (let s1 = c1 - y * A2; s2 = c2 - y * A1 in pprt s2 * pprt r2 + pprt s1 * nprt r2 + nprt s2 * pprt r1 + nprt s1 * nprt r1)"
obua@19453
   141
  (is "_ <= _ + ?C")
obua@19453
   142
proof -
wenzelm@41550
   143
  from assms have "y * (A * x) <= y * b" by (simp add: mult_left_mono) 
nipkow@29667
   144
  moreover have "y * (A * x) = c * x + (y * A - c) * x" by (simp add: algebra_simps)  
obua@19453
   145
  ultimately have "c * x + (y * A - c) * x <= y * b" by simp
obua@19453
   146
  then have "c * x <= y * b - (y * A - c) * x" by (simp add: le_diff_eq)
nipkow@29667
   147
  then have cx: "c * x <= y * b + (c - y * A) * x" by (simp add: algebra_simps)
obua@19453
   148
  have s2: "c - y * A <= c2 - y * A1"
haftmann@54230
   149
    by (simp add: assms add_mono mult_left_mono algebra_simps)
obua@19453
   150
  have s1: "c1 - y * A2 <= c - y * A"
haftmann@54230
   151
    by (simp add: assms add_mono mult_left_mono algebra_simps)
obua@19453
   152
  have prts: "(c - y * A) * x <= ?C"
obua@19453
   153
    apply (simp add: Let_def)
obua@19453
   154
    apply (rule mult_le_prts)
wenzelm@41550
   155
    apply (simp_all add: assms s1 s2)
obua@19453
   156
    done
obua@19453
   157
  then have "y * b + (c - y * A) * x <= y * b + ?C"
obua@19453
   158
    by simp
obua@19453
   159
  with cx show ?thesis
obua@19453
   160
    by(simp only:)
obua@19453
   161
qed
obua@19453
   162
nipkow@62390
   163
end