| author | wenzelm | 
| Fri, 01 Oct 2010 17:23:26 +0200 | |
| changeset 39820 | cd691e2c7a1a | 
| parent 38273 | d31a34569542 | 
| child 42463 | f270e3e18be5 | 
| permissions | -rw-r--r-- | 
| 16487 | 1 | (* Title: HOL/Matrix/SparseMatrix.thy | 
| 2 | Author: Steven Obua | |
| 3 | *) | |
| 4 | ||
| 27484 | 5 | theory SparseMatrix | 
| 28637 | 6 | imports Matrix | 
| 27484 | 7 | begin | 
| 15009 | 8 | |
| 9 | types | |
| 10 | 'a spvec = "(nat * 'a) list" | |
| 11 |   'a spmat = "('a spvec) spvec"
 | |
| 12 | ||
| 38273 | 13 | definition sparse_row_vector :: "('a::ab_group_add) spvec \<Rightarrow> 'a matrix"
 | 
| 14 | where "sparse_row_vector arr = foldl (% m x. m + (singleton_matrix 0 (fst x) (snd x))) 0 arr" | |
| 15009 | 15 | |
| 38273 | 16 | definition sparse_row_matrix :: "('a::ab_group_add) spmat \<Rightarrow> 'a matrix"
 | 
| 17 | where "sparse_row_matrix arr = foldl (% m r. m + (move_matrix (sparse_row_vector (snd r)) (int (fst r)) 0)) 0 arr" | |
| 15009 | 18 | |
| 27484 | 19 | code_datatype sparse_row_vector sparse_row_matrix | 
| 20 | ||
| 21 | lemma sparse_row_vector_empty [simp]: "sparse_row_vector [] = 0" | |
| 15009 | 22 | by (simp add: sparse_row_vector_def) | 
| 23 | ||
| 27484 | 24 | lemma sparse_row_matrix_empty [simp]: "sparse_row_matrix [] = 0" | 
| 15009 | 25 | by (simp add: sparse_row_matrix_def) | 
| 26 | ||
| 28562 | 27 | lemmas [code] = sparse_row_vector_empty [symmetric] | 
| 27484 | 28 | |
| 31817 | 29 | lemma foldl_distrstart: "! a x y. (f (g x y) a = g x (f y a)) \<Longrightarrow> (foldl f (g x y) l = g x (foldl f y l))" | 
| 30 | by (induct l arbitrary: x y, auto) | |
| 15009 | 31 | |
| 27653 | 32 | lemma sparse_row_vector_cons[simp]: | 
| 33 | "sparse_row_vector (a # arr) = (singleton_matrix 0 (fst a) (snd a)) + (sparse_row_vector arr)" | |
| 15009 | 34 | apply (induct arr) | 
| 35 | apply (auto simp add: sparse_row_vector_def) | |
| 27653 | 36 | apply (simp add: foldl_distrstart [of "\<lambda>m x. m + singleton_matrix 0 (fst x) (snd x)" "\<lambda>x m. singleton_matrix 0 (fst x) (snd x) + m"]) | 
| 15009 | 37 | done | 
| 38 | ||
| 27653 | 39 | lemma sparse_row_vector_append[simp]: | 
| 40 | "sparse_row_vector (a @ b) = (sparse_row_vector a) + (sparse_row_vector b)" | |
| 41 | by (induct a) auto | |
| 15009 | 42 | |
| 43 | lemma nrows_spvec[simp]: "nrows (sparse_row_vector x) <= (Suc 0)" | |
| 44 | apply (induct x) | |
| 45 | apply (simp_all add: add_nrows) | |
| 46 | done | |
| 47 | ||
| 48 | lemma sparse_row_matrix_cons: "sparse_row_matrix (a#arr) = ((move_matrix (sparse_row_vector (snd a)) (int (fst a)) 0)) + sparse_row_matrix arr" | |
| 49 | apply (induct arr) | |
| 50 | apply (auto simp add: sparse_row_matrix_def) | |
| 51 | apply (simp add: foldl_distrstart[of "\<lambda>m x. m + (move_matrix (sparse_row_vector (snd x)) (int (fst x)) 0)" | |
| 52 | "% a m. (move_matrix (sparse_row_vector (snd a)) (int (fst a)) 0) + m"]) | |
| 53 | done | |
| 54 | ||
| 55 | lemma sparse_row_matrix_append: "sparse_row_matrix (arr@brr) = (sparse_row_matrix arr) + (sparse_row_matrix brr)" | |
| 56 | apply (induct arr) | |
| 57 | apply (auto simp add: sparse_row_matrix_cons) | |
| 58 | done | |
| 59 | ||
| 38273 | 60 | primrec sorted_spvec :: "'a spvec \<Rightarrow> bool" | 
| 61 | where | |
| 27653 | 62 | "sorted_spvec [] = True" | 
| 38273 | 63 | | sorted_spvec_step: "sorted_spvec (a#as) = (case as of [] \<Rightarrow> True | b#bs \<Rightarrow> ((fst a < fst b) & (sorted_spvec as)))" | 
| 15009 | 64 | |
| 38273 | 65 | primrec sorted_spmat :: "'a spmat \<Rightarrow> bool" | 
| 66 | where | |
| 15009 | 67 | "sorted_spmat [] = True" | 
| 38273 | 68 | | "sorted_spmat (a#as) = ((sorted_spvec (snd a)) & (sorted_spmat as))" | 
| 15009 | 69 | |
| 70 | declare sorted_spvec.simps [simp del] | |
| 71 | ||
| 72 | lemma sorted_spvec_empty[simp]: "sorted_spvec [] = True" | |
| 73 | by (simp add: sorted_spvec.simps) | |
| 74 | ||
| 75 | lemma sorted_spvec_cons1: "sorted_spvec (a#as) \<Longrightarrow> sorted_spvec as" | |
| 76 | apply (induct as) | |
| 77 | apply (auto simp add: sorted_spvec.simps) | |
| 78 | done | |
| 79 | ||
| 80 | lemma sorted_spvec_cons2: "sorted_spvec (a#b#t) \<Longrightarrow> sorted_spvec (a#t)" | |
| 81 | apply (induct t) | |
| 82 | apply (auto simp add: sorted_spvec.simps) | |
| 83 | done | |
| 84 | ||
| 85 | lemma sorted_spvec_cons3: "sorted_spvec(a#b#t) \<Longrightarrow> fst a < fst b" | |
| 86 | apply (auto simp add: sorted_spvec.simps) | |
| 87 | done | |
| 88 | ||
| 31817 | 89 | lemma sorted_sparse_row_vector_zero[rule_format]: "m <= n \<Longrightarrow> sorted_spvec ((n,a)#arr) \<longrightarrow> Rep_matrix (sparse_row_vector arr) j m = 0" | 
| 15009 | 90 | apply (induct arr) | 
| 91 | apply (auto) | |
| 92 | apply (frule sorted_spvec_cons2,simp)+ | |
| 93 | apply (frule sorted_spvec_cons3, simp) | |
| 94 | done | |
| 95 | ||
| 31817 | 96 | lemma sorted_sparse_row_matrix_zero[rule_format]: "m <= n \<Longrightarrow> sorted_spvec ((n,a)#arr) \<longrightarrow> Rep_matrix (sparse_row_matrix arr) m j = 0" | 
| 15009 | 97 | apply (induct arr) | 
| 98 | apply (auto) | |
| 99 | apply (frule sorted_spvec_cons2, simp) | |
| 100 | apply (frule sorted_spvec_cons3, simp) | |
| 101 | apply (simp add: sparse_row_matrix_cons neg_def) | |
| 102 | done | |
| 103 | ||
| 38273 | 104 | primrec minus_spvec :: "('a::ab_group_add) spvec \<Rightarrow> 'a spvec"
 | 
| 105 | where | |
| 15178 | 106 | "minus_spvec [] = []" | 
| 38273 | 107 | | "minus_spvec (a#as) = (fst a, -(snd a))#(minus_spvec as)" | 
| 15178 | 108 | |
| 38273 | 109 | primrec abs_spvec :: "('a::lattice_ab_group_add_abs) spvec \<Rightarrow> 'a spvec"
 | 
| 110 | where | |
| 15178 | 111 | "abs_spvec [] = []" | 
| 38273 | 112 | | "abs_spvec (a#as) = (fst a, abs (snd a))#(abs_spvec as)" | 
| 15178 | 113 | |
| 114 | lemma sparse_row_vector_minus: | |
| 115 | "sparse_row_vector (minus_spvec v) = - (sparse_row_vector v)" | |
| 116 | apply (induct v) | |
| 117 | apply (simp_all add: sparse_row_vector_cons) | |
| 118 | apply (simp add: Rep_matrix_inject[symmetric]) | |
| 119 | apply (rule ext)+ | |
| 120 | apply simp | |
| 121 | done | |
| 122 | ||
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 123 | instance matrix :: (lattice_ab_group_add_abs) lattice_ab_group_add_abs | 
| 27653 | 124 | apply default | 
| 125 | unfolding abs_matrix_def .. (*FIXME move*) | |
| 126 | ||
| 15178 | 127 | lemma sparse_row_vector_abs: | 
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 128 | "sorted_spvec (v :: 'a::lattice_ring spvec) \<Longrightarrow> sparse_row_vector (abs_spvec v) = abs (sparse_row_vector v)" | 
| 15178 | 129 | apply (induct v) | 
| 27653 | 130 | apply simp_all | 
| 15178 | 131 | apply (frule_tac sorted_spvec_cons1, simp) | 
| 132 | apply (simp only: Rep_matrix_inject[symmetric]) | |
| 133 | apply (rule ext)+ | |
| 134 | apply auto | |
| 15236 
f289e8ba2bb3
Proofs needed to be updated because induction now preserves name of
 nipkow parents: 
15197diff
changeset | 135 | apply (subgoal_tac "Rep_matrix (sparse_row_vector v) 0 a = 0") | 
| 15178 | 136 | apply (simp) | 
| 137 | apply (rule sorted_sparse_row_vector_zero) | |
| 138 | apply auto | |
| 139 | done | |
| 140 | ||
| 141 | lemma sorted_spvec_minus_spvec: | |
| 142 | "sorted_spvec v \<Longrightarrow> sorted_spvec (minus_spvec v)" | |
| 143 | apply (induct v) | |
| 144 | apply (simp) | |
| 145 | apply (frule sorted_spvec_cons1, simp) | |
| 15236 
f289e8ba2bb3
Proofs needed to be updated because induction now preserves name of
 nipkow parents: 
15197diff
changeset | 146 | apply (simp add: sorted_spvec.simps split:list.split_asm) | 
| 15178 | 147 | done | 
| 148 | ||
| 149 | lemma sorted_spvec_abs_spvec: | |
| 150 | "sorted_spvec v \<Longrightarrow> sorted_spvec (abs_spvec v)" | |
| 151 | apply (induct v) | |
| 152 | apply (simp) | |
| 153 | apply (frule sorted_spvec_cons1, simp) | |
| 15236 
f289e8ba2bb3
Proofs needed to be updated because induction now preserves name of
 nipkow parents: 
15197diff
changeset | 154 | apply (simp add: sorted_spvec.simps split:list.split_asm) | 
| 15178 | 155 | done | 
| 156 | ||
| 38273 | 157 | definition "smult_spvec y = map (% a. (fst a, y * snd a))" | 
| 15009 | 158 | |
| 159 | lemma smult_spvec_empty[simp]: "smult_spvec y [] = []" | |
| 160 | by (simp add: smult_spvec_def) | |
| 161 | ||
| 162 | lemma smult_spvec_cons: "smult_spvec y (a#arr) = (fst a, y * (snd a)) # (smult_spvec y arr)" | |
| 163 | by (simp add: smult_spvec_def) | |
| 164 | ||
| 38273 | 165 | fun addmult_spvec :: "('a::ring) \<Rightarrow> 'a spvec \<Rightarrow> 'a spvec \<Rightarrow> 'a spvec"
 | 
| 166 | where | |
| 167 | "addmult_spvec y arr [] = arr" | |
| 168 | | "addmult_spvec y [] brr = smult_spvec y brr" | |
| 169 | | "addmult_spvec y ((i,a)#arr) ((j,b)#brr) = ( | |
| 31816 | 170 | if i < j then ((i,a)#(addmult_spvec y arr ((j,b)#brr))) | 
| 171 | else (if (j < i) then ((j, y * b)#(addmult_spvec y ((i,a)#arr) brr)) | |
| 172 | else ((i, a + y*b)#(addmult_spvec y arr brr))))" | |
| 173 | (* Steven used termination "measure (% (y, a, b). length a + (length b))" *) | |
| 15009 | 174 | |
| 31816 | 175 | lemma addmult_spvec_empty1[simp]: "addmult_spvec y [] a = smult_spvec y a" | 
| 27484 | 176 | by (induct a) auto | 
| 15009 | 177 | |
| 31816 | 178 | lemma addmult_spvec_empty2[simp]: "addmult_spvec y a [] = a" | 
| 27484 | 179 | by (induct a) auto | 
| 15009 | 180 | |
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 181 | lemma sparse_row_vector_map: "(! x y. f (x+y) = (f x) + (f y)) \<Longrightarrow> (f::'a\<Rightarrow>('a::lattice_ring)) 0 = 0 \<Longrightarrow> 
 | 
| 15009 | 182 | sparse_row_vector (map (% x. (fst x, f (snd x))) a) = apply_matrix f (sparse_row_vector a)" | 
| 183 | apply (induct a) | |
| 184 | apply (simp_all add: apply_matrix_add) | |
| 185 | done | |
| 186 | ||
| 187 | lemma sparse_row_vector_smult: "sparse_row_vector (smult_spvec y a) = scalar_mult y (sparse_row_vector a)" | |
| 188 | apply (induct a) | |
| 189 | apply (simp_all add: smult_spvec_cons scalar_mult_add) | |
| 190 | done | |
| 191 | ||
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 192 | lemma sparse_row_vector_addmult_spvec: "sparse_row_vector (addmult_spvec (y::'a::lattice_ring) a b) = | 
| 15009 | 193 | (sparse_row_vector a) + (scalar_mult y (sparse_row_vector b))" | 
| 31817 | 194 | apply (induct y a b rule: addmult_spvec.induct) | 
| 15009 | 195 | apply (simp add: scalar_mult_add smult_spvec_cons sparse_row_vector_smult singleton_matrix_add)+ | 
| 196 | done | |
| 197 | ||
| 31817 | 198 | lemma sorted_smult_spvec: "sorted_spvec a \<Longrightarrow> sorted_spvec (smult_spvec y a)" | 
| 15009 | 199 | apply (auto simp add: smult_spvec_def) | 
| 200 | apply (induct a) | |
| 15236 
f289e8ba2bb3
Proofs needed to be updated because induction now preserves name of
 nipkow parents: 
15197diff
changeset | 201 | apply (auto simp add: sorted_spvec.simps split:list.split_asm) | 
| 15009 | 202 | done | 
| 203 | ||
| 31816 | 204 | lemma sorted_spvec_addmult_spvec_helper: "\<lbrakk>sorted_spvec (addmult_spvec y ((a, b) # arr) brr); aa < a; sorted_spvec ((a, b) # arr); | 
| 205 | sorted_spvec ((aa, ba) # brr)\<rbrakk> \<Longrightarrow> sorted_spvec ((aa, y * ba) # addmult_spvec y ((a, b) # arr) brr)" | |
| 15009 | 206 | apply (induct brr) | 
| 207 | apply (auto simp add: sorted_spvec.simps) | |
| 208 | done | |
| 209 | ||
| 210 | lemma sorted_spvec_addmult_spvec_helper2: | |
| 31816 | 211 | "\<lbrakk>sorted_spvec (addmult_spvec y arr ((aa, ba) # brr)); a < aa; sorted_spvec ((a, b) # arr); sorted_spvec ((aa, ba) # brr)\<rbrakk> | 
| 212 | \<Longrightarrow> sorted_spvec ((a, b) # addmult_spvec y arr ((aa, ba) # brr))" | |
| 15009 | 213 | apply (induct arr) | 
| 214 | apply (auto simp add: smult_spvec_def sorted_spvec.simps) | |
| 215 | done | |
| 216 | ||
| 217 | lemma sorted_spvec_addmult_spvec_helper3[rule_format]: | |
| 31816 | 218 | "sorted_spvec (addmult_spvec y arr brr) \<longrightarrow> sorted_spvec ((aa, b) # arr) \<longrightarrow> sorted_spvec ((aa, ba) # brr) | 
| 219 | \<longrightarrow> sorted_spvec ((aa, b + y * ba) # (addmult_spvec y arr brr))" | |
| 220 | apply (induct y arr brr rule: addmult_spvec.induct) | |
| 221 | apply (simp_all add: sorted_spvec.simps smult_spvec_def split:list.split) | |
| 15009 | 222 | done | 
| 223 | ||
| 31817 | 224 | lemma sorted_addmult_spvec: "sorted_spvec a \<Longrightarrow> sorted_spvec b \<Longrightarrow> sorted_spvec (addmult_spvec y a b)" | 
| 225 | apply (induct y a b rule: addmult_spvec.induct) | |
| 15009 | 226 | apply (simp_all add: sorted_smult_spvec) | 
| 227 | apply (rule conjI, intro strip) | |
| 31816 | 228 | apply (case_tac "~(i < j)") | 
| 15009 | 229 | apply (simp_all) | 
| 230 | apply (frule_tac as=brr in sorted_spvec_cons1) | |
| 231 | apply (simp add: sorted_spvec_addmult_spvec_helper) | |
| 232 | apply (intro strip | rule conjI)+ | |
| 233 | apply (frule_tac as=arr in sorted_spvec_cons1) | |
| 234 | apply (simp add: sorted_spvec_addmult_spvec_helper2) | |
| 235 | apply (intro strip) | |
| 236 | apply (frule_tac as=arr in sorted_spvec_cons1) | |
| 237 | apply (frule_tac as=brr in sorted_spvec_cons1) | |
| 238 | apply (simp) | |
| 239 | apply (simp_all add: sorted_spvec_addmult_spvec_helper3) | |
| 240 | done | |
| 241 | ||
| 38273 | 242 | fun mult_spvec_spmat :: "('a::lattice_ring) spvec \<Rightarrow> 'a spvec \<Rightarrow> 'a spmat  \<Rightarrow> 'a spvec"
 | 
| 243 | where | |
| 31816 | 244 | (* recdef mult_spvec_spmat "measure (% (c, arr, brr). (length arr) + (length brr))" *) | 
| 38273 | 245 | "mult_spvec_spmat c [] brr = c" | 
| 246 | | "mult_spvec_spmat c arr [] = c" | |
| 247 | | "mult_spvec_spmat c ((i,a)#arr) ((j,b)#brr) = ( | |
| 31816 | 248 | if (i < j) then mult_spvec_spmat c arr ((j,b)#brr) | 
| 249 | else if (j < i) then mult_spvec_spmat c ((i,a)#arr) brr | |
| 250 | else mult_spvec_spmat (addmult_spvec a c b) arr brr)" | |
| 15009 | 251 | |
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 252 | lemma sparse_row_mult_spvec_spmat[rule_format]: "sorted_spvec (a::('a::lattice_ring) spvec) \<longrightarrow> sorted_spvec B \<longrightarrow> 
 | 
| 31816 | 253 | sparse_row_vector (mult_spvec_spmat c a B) = (sparse_row_vector c) + (sparse_row_vector a) * (sparse_row_matrix B)" | 
| 15009 | 254 | proof - | 
| 255 | have comp_1: "!! a b. a < b \<Longrightarrow> Suc 0 <= nat ((int b)-(int a))" by arith | |
| 256 | have not_iff: "!! a b. a = b \<Longrightarrow> (~ a) = (~ b)" by simp | |
| 257 | have max_helper: "!! a b. ~ (a <= max (Suc a) b) \<Longrightarrow> False" | |
| 258 | by arith | |
| 259 |   {
 | |
| 260 | fix a | |
| 261 | fix v | |
| 262 | assume a:"a < nrows(sparse_row_vector v)" | |
| 263 | have b:"nrows(sparse_row_vector v) <= 1" by simp | |
| 264 | note dummy = less_le_trans[of a "nrows (sparse_row_vector v)" 1, OF a b] | |
| 265 | then have "a = 0" by simp | |
| 266 | } | |
| 267 | note nrows_helper = this | |
| 268 | show ?thesis | |
| 31817 | 269 | apply (induct c a B rule: mult_spvec_spmat.induct) | 
| 15009 | 270 | apply simp+ | 
| 271 | apply (rule conjI) | |
| 272 | apply (intro strip) | |
| 273 | apply (frule_tac as=brr in sorted_spvec_cons1) | |
| 29667 | 274 | apply (simp add: algebra_simps sparse_row_matrix_cons) | 
| 15481 | 275 | apply (simplesubst Rep_matrix_zero_imp_mult_zero) | 
| 15009 | 276 | apply (simp) | 
| 277 | apply (intro strip) | |
| 278 | apply (rule disjI2) | |
| 279 | apply (intro strip) | |
| 280 | apply (subst nrows) | |
| 281 | apply (rule order_trans[of _ 1]) | |
| 282 | apply (simp add: comp_1)+ | |
| 283 | apply (subst Rep_matrix_zero_imp_mult_zero) | |
| 284 | apply (intro strip) | |
| 31816 | 285 | apply (case_tac "k <= j") | 
| 286 | apply (rule_tac m1 = k and n1 = i and a1 = a in ssubst[OF sorted_sparse_row_vector_zero]) | |
| 15009 | 287 | apply (simp_all) | 
| 288 | apply (rule impI) | |
| 289 | apply (rule disjI2) | |
| 290 | apply (rule nrows) | |
| 291 | apply (rule order_trans[of _ 1]) | |
| 292 | apply (simp_all add: comp_1) | |
| 293 | ||
| 294 | apply (intro strip | rule conjI)+ | |
| 295 | apply (frule_tac as=arr in sorted_spvec_cons1) | |
| 29667 | 296 | apply (simp add: algebra_simps) | 
| 15009 | 297 | apply (subst Rep_matrix_zero_imp_mult_zero) | 
| 298 | apply (simp) | |
| 299 | apply (rule disjI2) | |
| 300 | apply (intro strip) | |
| 301 | apply (simp add: sparse_row_matrix_cons neg_def) | |
| 31816 | 302 | apply (case_tac "i <= j") | 
| 15009 | 303 | apply (erule sorted_sparse_row_matrix_zero) | 
| 304 | apply (simp_all) | |
| 305 | apply (intro strip) | |
| 31816 | 306 | apply (case_tac "i=j") | 
| 15009 | 307 | apply (simp_all) | 
| 308 | apply (frule_tac as=arr in sorted_spvec_cons1) | |
| 309 | apply (frule_tac as=brr in sorted_spvec_cons1) | |
| 29667 | 310 | apply (simp add: sparse_row_matrix_cons algebra_simps sparse_row_vector_addmult_spvec) | 
| 15009 | 311 | apply (rule_tac B1 = "sparse_row_matrix brr" in ssubst[OF Rep_matrix_zero_imp_mult_zero]) | 
| 312 | apply (auto) | |
| 313 | apply (rule sorted_sparse_row_matrix_zero) | |
| 314 | apply (simp_all) | |
| 315 | apply (rule_tac A1 = "sparse_row_vector arr" in ssubst[OF Rep_matrix_zero_imp_mult_zero]) | |
| 316 | apply (auto) | |
| 31816 | 317 | apply (rule_tac m=k and n = j and a = a and arr=arr in sorted_sparse_row_vector_zero) | 
| 15009 | 318 | apply (simp_all) | 
| 319 | apply (simp add: neg_def) | |
| 320 | apply (drule nrows_notzero) | |
| 321 | apply (drule nrows_helper) | |
| 322 | apply (arith) | |
| 323 | ||
| 324 | apply (subst Rep_matrix_inject[symmetric]) | |
| 325 | apply (rule ext)+ | |
| 326 | apply (simp) | |
| 327 | apply (subst Rep_matrix_mult) | |
| 31816 | 328 | apply (rule_tac j1=j in ssubst[OF foldseq_almostzero]) | 
| 15009 | 329 | apply (simp_all) | 
| 20432 
07ec57376051
lin_arith_prover: splitting reverted because of performance loss
 webertj parents: 
20283diff
changeset | 330 | apply (intro strip, rule conjI) | 
| 15009 | 331 | apply (intro strip) | 
| 20432 
07ec57376051
lin_arith_prover: splitting reverted because of performance loss
 webertj parents: 
20283diff
changeset | 332 | apply (drule_tac max_helper) | 
| 
07ec57376051
lin_arith_prover: splitting reverted because of performance loss
 webertj parents: 
20283diff
changeset | 333 | apply (simp) | 
| 
07ec57376051
lin_arith_prover: splitting reverted because of performance loss
 webertj parents: 
20283diff
changeset | 334 | apply (auto) | 
| 15009 | 335 | apply (rule zero_imp_mult_zero) | 
| 336 | apply (rule disjI2) | |
| 337 | apply (rule nrows) | |
| 338 | apply (rule order_trans[of _ 1]) | |
| 20432 
07ec57376051
lin_arith_prover: splitting reverted because of performance loss
 webertj parents: 
20283diff
changeset | 339 | apply (simp) | 
| 
07ec57376051
lin_arith_prover: splitting reverted because of performance loss
 webertj parents: 
20283diff
changeset | 340 | apply (simp) | 
| 15009 | 341 | done | 
| 342 | qed | |
| 343 | ||
| 344 | lemma sorted_mult_spvec_spmat[rule_format]: | |
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 345 |   "sorted_spvec (c::('a::lattice_ring) spvec) \<longrightarrow> sorted_spmat B \<longrightarrow> sorted_spvec (mult_spvec_spmat c a B)"
 | 
| 31817 | 346 | apply (induct c a B rule: mult_spvec_spmat.induct) | 
| 15009 | 347 | apply (simp_all add: sorted_addmult_spvec) | 
| 348 | done | |
| 349 | ||
| 38273 | 350 | primrec mult_spmat :: "('a::lattice_ring) spmat \<Rightarrow> 'a spmat \<Rightarrow> 'a spmat"
 | 
| 351 | where | |
| 15009 | 352 | "mult_spmat [] A = []" | 
| 38273 | 353 | | "mult_spmat (a#as) A = (fst a, mult_spvec_spmat [] (snd a) A)#(mult_spmat as A)" | 
| 15009 | 354 | |
| 31817 | 355 | lemma sparse_row_mult_spmat: | 
| 356 | "sorted_spmat A \<Longrightarrow> sorted_spvec B \<Longrightarrow> | |
| 357 | sparse_row_matrix (mult_spmat A B) = (sparse_row_matrix A) * (sparse_row_matrix B)" | |
| 15009 | 358 | apply (induct A) | 
| 29667 | 359 | apply (auto simp add: sparse_row_matrix_cons sparse_row_mult_spvec_spmat algebra_simps move_matrix_mult) | 
| 15009 | 360 | done | 
| 361 | ||
| 362 | lemma sorted_spvec_mult_spmat[rule_format]: | |
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 363 |   "sorted_spvec (A::('a::lattice_ring) spmat) \<longrightarrow> sorted_spvec (mult_spmat A B)"
 | 
| 15009 | 364 | apply (induct A) | 
| 365 | apply (auto) | |
| 366 | apply (drule sorted_spvec_cons1, simp) | |
| 15236 
f289e8ba2bb3
Proofs needed to be updated because induction now preserves name of
 nipkow parents: 
15197diff
changeset | 367 | apply (case_tac A) | 
| 15009 | 368 | apply (auto simp add: sorted_spvec.simps) | 
| 369 | done | |
| 370 | ||
| 31817 | 371 | lemma sorted_spmat_mult_spmat: | 
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 372 |   "sorted_spmat (B::('a::lattice_ring) spmat) \<Longrightarrow> sorted_spmat (mult_spmat A B)"
 | 
| 15009 | 373 | apply (induct A) | 
| 374 | apply (auto simp add: sorted_mult_spvec_spmat) | |
| 375 | done | |
| 376 | ||
| 377 | ||
| 38273 | 378 | fun add_spvec :: "('a::lattice_ab_group_add) spvec \<Rightarrow> 'a spvec \<Rightarrow> 'a spvec"
 | 
| 379 | where | |
| 31816 | 380 | (* "measure (% (a, b). length a + (length b))" *) | 
| 38273 | 381 | "add_spvec arr [] = arr" | 
| 382 | | "add_spvec [] brr = brr" | |
| 383 | | "add_spvec ((i,a)#arr) ((j,b)#brr) = ( | |
| 384 | if i < j then (i,a)#(add_spvec arr ((j,b)#brr)) | |
| 31816 | 385 | else if (j < i) then (j,b) # add_spvec ((i,a)#arr) brr | 
| 386 | else (i, a+b) # add_spvec arr brr)" | |
| 15009 | 387 | |
| 31816 | 388 | lemma add_spvec_empty1[simp]: "add_spvec [] a = a" | 
| 389 | by (cases a, auto) | |
| 15009 | 390 | |
| 31816 | 391 | lemma sparse_row_vector_add: "sparse_row_vector (add_spvec a b) = (sparse_row_vector a) + (sparse_row_vector b)" | 
| 31817 | 392 | apply (induct a b rule: add_spvec.induct) | 
| 15009 | 393 | apply (simp_all add: singleton_matrix_add) | 
| 394 | done | |
| 395 | ||
| 38273 | 396 | fun add_spmat :: "('a::lattice_ab_group_add) spmat \<Rightarrow> 'a spmat \<Rightarrow> 'a spmat"
 | 
| 397 | where | |
| 31816 | 398 | (* "measure (% (A,B). (length A)+(length B))" *) | 
| 38273 | 399 | "add_spmat [] bs = bs" | 
| 400 | | "add_spmat as [] = as" | |
| 401 | | "add_spmat ((i,a)#as) ((j,b)#bs) = ( | |
| 402 | if i < j then | |
| 403 | (i,a) # add_spmat as ((j,b)#bs) | |
| 404 | else if j < i then | |
| 405 | (j,b) # add_spmat ((i,a)#as) bs | |
| 406 | else | |
| 407 | (i, add_spvec a b) # add_spmat as bs)" | |
| 15009 | 408 | |
| 31816 | 409 | lemma add_spmat_Nil2[simp]: "add_spmat as [] = as" | 
| 410 | by(cases as) auto | |
| 411 | ||
| 412 | lemma sparse_row_add_spmat: "sparse_row_matrix (add_spmat A B) = (sparse_row_matrix A) + (sparse_row_matrix B)" | |
| 31817 | 413 | apply (induct A B rule: add_spmat.induct) | 
| 15009 | 414 | apply (auto simp add: sparse_row_matrix_cons sparse_row_vector_add move_matrix_add) | 
| 415 | done | |
| 416 | ||
| 28562 | 417 | lemmas [code] = sparse_row_add_spmat [symmetric] | 
| 418 | lemmas [code] = sparse_row_vector_add [symmetric] | |
| 27484 | 419 | |
| 31816 | 420 | lemma sorted_add_spvec_helper1[rule_format]: "add_spvec ((a,b)#arr) brr = (ab, bb) # list \<longrightarrow> (ab = a | (brr \<noteq> [] & ab = fst (hd brr)))" | 
| 15009 | 421 | proof - | 
| 31816 | 422 | have "(! x ab a. x = (a,b)#arr \<longrightarrow> add_spvec x brr = (ab, bb) # list \<longrightarrow> (ab = a | (ab = fst (hd brr))))" | 
| 31817 | 423 | by (induct brr rule: add_spvec.induct) (auto split:if_splits) | 
| 15009 | 424 | then show ?thesis | 
| 425 | by (case_tac brr, auto) | |
| 426 | qed | |
| 427 | ||
| 31816 | 428 | lemma sorted_add_spmat_helper1[rule_format]: "add_spmat ((a,b)#arr) brr = (ab, bb) # list \<longrightarrow> (ab = a | (brr \<noteq> [] & ab = fst (hd brr)))" | 
| 15009 | 429 | proof - | 
| 31816 | 430 | have "(! x ab a. x = (a,b)#arr \<longrightarrow> add_spmat x brr = (ab, bb) # list \<longrightarrow> (ab = a | (ab = fst (hd brr))))" | 
| 31817 | 431 | by (rule add_spmat.induct) (auto split:if_splits) | 
| 15009 | 432 | then show ?thesis | 
| 433 | by (case_tac brr, auto) | |
| 434 | qed | |
| 435 | ||
| 31817 | 436 | lemma sorted_add_spvec_helper: "add_spvec arr brr = (ab, bb) # list \<Longrightarrow> ((arr \<noteq> [] & ab = fst (hd arr)) | (brr \<noteq> [] & ab = fst (hd brr)))" | 
| 437 | apply (induct arr brr rule: add_spvec.induct) | |
| 438 | apply (auto split:if_splits) | |
| 15009 | 439 | done | 
| 440 | ||
| 31817 | 441 | lemma sorted_add_spmat_helper: "add_spmat arr brr = (ab, bb) # list \<Longrightarrow> ((arr \<noteq> [] & ab = fst (hd arr)) | (brr \<noteq> [] & ab = fst (hd brr)))" | 
| 442 | apply (induct arr brr rule: add_spmat.induct) | |
| 443 | apply (auto split:if_splits) | |
| 15009 | 444 | done | 
| 445 | ||
| 31816 | 446 | lemma add_spvec_commute: "add_spvec a b = add_spvec b a" | 
| 31817 | 447 | by (induct a b rule: add_spvec.induct) auto | 
| 15009 | 448 | |
| 31816 | 449 | lemma add_spmat_commute: "add_spmat a b = add_spmat b a" | 
| 31817 | 450 | apply (induct a b rule: add_spmat.induct) | 
| 15009 | 451 | apply (simp_all add: add_spvec_commute) | 
| 452 | done | |
| 453 | ||
| 31816 | 454 | lemma sorted_add_spvec_helper2: "add_spvec ((a,b)#arr) brr = (ab, bb) # list \<Longrightarrow> aa < a \<Longrightarrow> sorted_spvec ((aa, ba) # brr) \<Longrightarrow> aa < ab" | 
| 15009 | 455 | apply (drule sorted_add_spvec_helper1) | 
| 456 | apply (auto) | |
| 457 | apply (case_tac brr) | |
| 458 | apply (simp_all) | |
| 459 | apply (drule_tac sorted_spvec_cons3) | |
| 460 | apply (simp) | |
| 461 | done | |
| 462 | ||
| 31816 | 463 | lemma sorted_add_spmat_helper2: "add_spmat ((a,b)#arr) brr = (ab, bb) # list \<Longrightarrow> aa < a \<Longrightarrow> sorted_spvec ((aa, ba) # brr) \<Longrightarrow> aa < ab" | 
| 15009 | 464 | apply (drule sorted_add_spmat_helper1) | 
| 465 | apply (auto) | |
| 466 | apply (case_tac brr) | |
| 467 | apply (simp_all) | |
| 468 | apply (drule_tac sorted_spvec_cons3) | |
| 469 | apply (simp) | |
| 470 | done | |
| 471 | ||
| 31816 | 472 | lemma sorted_spvec_add_spvec[rule_format]: "sorted_spvec a \<longrightarrow> sorted_spvec b \<longrightarrow> sorted_spvec (add_spvec a b)" | 
| 31817 | 473 | apply (induct a b rule: add_spvec.induct) | 
| 15009 | 474 | apply (simp_all) | 
| 475 | apply (rule conjI) | |
| 31816 | 476 | apply (clarsimp) | 
| 15009 | 477 | apply (frule_tac as=brr in sorted_spvec_cons1) | 
| 478 | apply (simp) | |
| 479 | apply (subst sorted_spvec_step) | |
| 31816 | 480 | apply (clarsimp simp: sorted_add_spvec_helper2 split: list.split) | 
| 15009 | 481 | apply (clarify) | 
| 482 | apply (rule conjI) | |
| 483 | apply (clarify) | |
| 484 | apply (frule_tac as=arr in sorted_spvec_cons1, simp) | |
| 485 | apply (subst sorted_spvec_step) | |
| 31816 | 486 | apply (clarsimp simp: sorted_add_spvec_helper2 add_spvec_commute split: list.split) | 
| 15009 | 487 | apply (clarify) | 
| 488 | apply (frule_tac as=arr in sorted_spvec_cons1) | |
| 489 | apply (frule_tac as=brr in sorted_spvec_cons1) | |
| 490 | apply (simp) | |
| 491 | apply (subst sorted_spvec_step) | |
| 492 | apply (simp split: list.split) | |
| 31816 | 493 | apply (clarsimp) | 
| 15009 | 494 | apply (drule_tac sorted_add_spvec_helper) | 
| 31816 | 495 | apply (auto simp: neq_Nil_conv) | 
| 15009 | 496 | apply (drule sorted_spvec_cons3) | 
| 497 | apply (simp) | |
| 498 | apply (drule sorted_spvec_cons3) | |
| 499 | apply (simp) | |
| 500 | done | |
| 501 | ||
| 31816 | 502 | lemma sorted_spvec_add_spmat[rule_format]: "sorted_spvec A \<longrightarrow> sorted_spvec B \<longrightarrow> sorted_spvec (add_spmat A B)" | 
| 31817 | 503 | apply (induct A B rule: add_spmat.induct) | 
| 15009 | 504 | apply (simp_all) | 
| 505 | apply (rule conjI) | |
| 506 | apply (intro strip) | |
| 507 | apply (simp) | |
| 508 | apply (frule_tac as=bs in sorted_spvec_cons1) | |
| 509 | apply (simp) | |
| 510 | apply (subst sorted_spvec_step) | |
| 511 | apply (simp split: list.split) | |
| 512 | apply (clarify, simp) | |
| 513 | apply (simp add: sorted_add_spmat_helper2) | |
| 514 | apply (clarify) | |
| 515 | apply (rule conjI) | |
| 516 | apply (clarify) | |
| 517 | apply (frule_tac as=as in sorted_spvec_cons1, simp) | |
| 518 | apply (subst sorted_spvec_step) | |
| 31816 | 519 | apply (clarsimp simp: sorted_add_spmat_helper2 add_spmat_commute split: list.split) | 
| 520 | apply (clarsimp) | |
| 15009 | 521 | apply (frule_tac as=as in sorted_spvec_cons1) | 
| 522 | apply (frule_tac as=bs in sorted_spvec_cons1) | |
| 523 | apply (simp) | |
| 524 | apply (subst sorted_spvec_step) | |
| 525 | apply (simp split: list.split) | |
| 526 | apply (clarify, simp) | |
| 527 | apply (drule_tac sorted_add_spmat_helper) | |
| 31816 | 528 | apply (auto simp:neq_Nil_conv) | 
| 15009 | 529 | apply (drule sorted_spvec_cons3) | 
| 530 | apply (simp) | |
| 531 | apply (drule sorted_spvec_cons3) | |
| 532 | apply (simp) | |
| 533 | done | |
| 534 | ||
| 31817 | 535 | lemma sorted_spmat_add_spmat[rule_format]: "sorted_spmat A \<Longrightarrow> sorted_spmat B \<Longrightarrow> sorted_spmat (add_spmat A B)" | 
| 536 | apply (induct A B rule: add_spmat.induct) | |
| 15009 | 537 | apply (simp_all add: sorted_spvec_add_spvec) | 
| 538 | done | |
| 539 | ||
| 38273 | 540 | fun le_spvec :: "('a::lattice_ab_group_add) spvec \<Rightarrow> 'a spvec \<Rightarrow> bool"
 | 
| 541 | where | |
| 31816 | 542 | (* "measure (% (a,b). (length a) + (length b))" *) | 
| 38273 | 543 | "le_spvec [] [] = True" | 
| 544 | | "le_spvec ((_,a)#as) [] = (a <= 0 & le_spvec as [])" | |
| 545 | | "le_spvec [] ((_,b)#bs) = (0 <= b & le_spvec [] bs)" | |
| 546 | | "le_spvec ((i,a)#as) ((j,b)#bs) = ( | |
| 547 | if (i < j) then a <= 0 & le_spvec as ((j,b)#bs) | |
| 548 | else if (j < i) then 0 <= b & le_spvec ((i,a)#as) bs | |
| 549 | else a <= b & le_spvec as bs)" | |
| 15009 | 550 | |
| 38273 | 551 | fun le_spmat :: "('a::lattice_ab_group_add) spmat \<Rightarrow> 'a spmat \<Rightarrow> bool"
 | 
| 552 | where | |
| 31816 | 553 | (* "measure (% (a,b). (length a) + (length b))" *) | 
| 38273 | 554 | "le_spmat [] [] = True" | 
| 555 | | "le_spmat ((i,a)#as) [] = (le_spvec a [] & le_spmat as [])" | |
| 556 | | "le_spmat [] ((j,b)#bs) = (le_spvec [] b & le_spmat [] bs)" | |
| 557 | | "le_spmat ((i,a)#as) ((j,b)#bs) = ( | |
| 558 | if i < j then (le_spvec a [] & le_spmat as ((j,b)#bs)) | |
| 559 | else if j < i then (le_spvec [] b & le_spmat ((i,a)#as) bs) | |
| 560 | else (le_spvec a b & le_spmat as bs))" | |
| 15009 | 561 | |
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
35028diff
changeset | 562 | definition disj_matrices :: "('a::zero) matrix \<Rightarrow> 'a matrix \<Rightarrow> bool" where
 | 
| 38273 | 563 | "disj_matrices A B \<longleftrightarrow> | 
| 564 | (! j i. (Rep_matrix A j i \<noteq> 0) \<longrightarrow> (Rep_matrix B j i = 0)) & (! j i. (Rep_matrix B j i \<noteq> 0) \<longrightarrow> (Rep_matrix A j i = 0))" | |
| 15009 | 565 | |
| 24124 
4399175e3014
turned simp_depth_limit into configuration option;
 wenzelm parents: 
23477diff
changeset | 566 | declare [[simp_depth_limit = 6]] | 
| 15009 | 567 | |
| 15580 | 568 | lemma disj_matrices_contr1: "disj_matrices A B \<Longrightarrow> Rep_matrix A j i \<noteq> 0 \<Longrightarrow> Rep_matrix B j i = 0" | 
| 569 | by (simp add: disj_matrices_def) | |
| 570 | ||
| 571 | lemma disj_matrices_contr2: "disj_matrices A B \<Longrightarrow> Rep_matrix B j i \<noteq> 0 \<Longrightarrow> Rep_matrix A j i = 0" | |
| 572 | by (simp add: disj_matrices_def) | |
| 573 | ||
| 574 | ||
| 15009 | 575 | lemma disj_matrices_add: "disj_matrices A B \<Longrightarrow> disj_matrices C D \<Longrightarrow> disj_matrices A D \<Longrightarrow> disj_matrices B C \<Longrightarrow> | 
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 576 |   (A + B <= C + D) = (A <= C & B <= (D::('a::lattice_ab_group_add) matrix))"
 | 
| 15009 | 577 | apply (auto) | 
| 578 | apply (simp (no_asm_use) only: le_matrix_def disj_matrices_def) | |
| 579 | apply (intro strip) | |
| 580 | apply (erule conjE)+ | |
| 581 | apply (drule_tac j=j and i=i in spec2)+ | |
| 582 | apply (case_tac "Rep_matrix B j i = 0") | |
| 583 | apply (case_tac "Rep_matrix D j i = 0") | |
| 584 | apply (simp_all) | |
| 585 | apply (simp (no_asm_use) only: le_matrix_def disj_matrices_def) | |
| 586 | apply (intro strip) | |
| 587 | apply (erule conjE)+ | |
| 588 | apply (drule_tac j=j and i=i in spec2)+ | |
| 589 | apply (case_tac "Rep_matrix A j i = 0") | |
| 590 | apply (case_tac "Rep_matrix C j i = 0") | |
| 591 | apply (simp_all) | |
| 592 | apply (erule add_mono) | |
| 593 | apply (assumption) | |
| 594 | done | |
| 595 | ||
| 596 | lemma disj_matrices_zero1[simp]: "disj_matrices 0 B" | |
| 597 | by (simp add: disj_matrices_def) | |
| 598 | ||
| 599 | lemma disj_matrices_zero2[simp]: "disj_matrices A 0" | |
| 600 | by (simp add: disj_matrices_def) | |
| 601 | ||
| 602 | lemma disj_matrices_commute: "disj_matrices A B = disj_matrices B A" | |
| 603 | by (auto simp add: disj_matrices_def) | |
| 604 | ||
| 605 | lemma disj_matrices_add_le_zero: "disj_matrices A B \<Longrightarrow> | |
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 606 |   (A + B <= 0) = (A <= 0 & (B::('a::lattice_ab_group_add) matrix) <= 0)"
 | 
| 15009 | 607 | by (rule disj_matrices_add[of A B 0 0, simplified]) | 
| 608 | ||
| 609 | lemma disj_matrices_add_zero_le: "disj_matrices A B \<Longrightarrow> | |
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 610 |   (0 <= A + B) = (0 <= A & 0 <= (B::('a::lattice_ab_group_add) matrix))"
 | 
| 15009 | 611 | by (rule disj_matrices_add[of 0 0 A B, simplified]) | 
| 612 | ||
| 613 | lemma disj_matrices_add_x_le: "disj_matrices A B \<Longrightarrow> disj_matrices B C \<Longrightarrow> | |
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 614 |   (A <= B + C) = (A <= C & 0 <= (B::('a::lattice_ab_group_add) matrix))"
 | 
| 15009 | 615 | by (auto simp add: disj_matrices_add[of 0 A B C, simplified]) | 
| 616 | ||
| 617 | lemma disj_matrices_add_le_x: "disj_matrices A B \<Longrightarrow> disj_matrices B C \<Longrightarrow> | |
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 618 |   (B + A <= C) = (A <= C &  (B::('a::lattice_ab_group_add) matrix) <= 0)"
 | 
| 15009 | 619 | by (auto simp add: disj_matrices_add[of B A 0 C,simplified] disj_matrices_commute) | 
| 620 | ||
| 621 | lemma disj_sparse_row_singleton: "i <= j \<Longrightarrow> sorted_spvec((j,y)#v) \<Longrightarrow> disj_matrices (sparse_row_vector v) (singleton_matrix 0 i x)" | |
| 622 | apply (simp add: disj_matrices_def) | |
| 623 | apply (rule conjI) | |
| 624 | apply (rule neg_imp) | |
| 625 | apply (simp) | |
| 626 | apply (intro strip) | |
| 627 | apply (rule sorted_sparse_row_vector_zero) | |
| 628 | apply (simp_all) | |
| 629 | apply (intro strip) | |
| 630 | apply (rule sorted_sparse_row_vector_zero) | |
| 631 | apply (simp_all) | |
| 632 | done | |
| 633 | ||
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 634 | lemma disj_matrices_x_add: "disj_matrices A B \<Longrightarrow> disj_matrices A C \<Longrightarrow> disj_matrices (A::('a::lattice_ab_group_add) matrix) (B+C)"
 | 
| 15009 | 635 | apply (simp add: disj_matrices_def) | 
| 636 | apply (auto) | |
| 637 | apply (drule_tac j=j and i=i in spec2)+ | |
| 638 | apply (case_tac "Rep_matrix B j i = 0") | |
| 639 | apply (case_tac "Rep_matrix C j i = 0") | |
| 640 | apply (simp_all) | |
| 641 | done | |
| 642 | ||
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 643 | lemma disj_matrices_add_x: "disj_matrices A B \<Longrightarrow> disj_matrices A C \<Longrightarrow> disj_matrices (B+C) (A::('a::lattice_ab_group_add) matrix)" 
 | 
| 15009 | 644 | by (simp add: disj_matrices_x_add disj_matrices_commute) | 
| 645 | ||
| 646 | lemma disj_singleton_matrices[simp]: "disj_matrices (singleton_matrix j i x) (singleton_matrix u v y) = (j \<noteq> u | i \<noteq> v | x = 0 | y = 0)" | |
| 647 | by (auto simp add: disj_matrices_def) | |
| 648 | ||
| 649 | lemma disj_move_sparse_vec_mat[simplified disj_matrices_commute]: | |
| 650 | "j <= a \<Longrightarrow> sorted_spvec((a,c)#as) \<Longrightarrow> disj_matrices (move_matrix (sparse_row_vector b) (int j) i) (sparse_row_matrix as)" | |
| 651 | apply (auto simp add: neg_def disj_matrices_def) | |
| 652 | apply (drule nrows_notzero) | |
| 653 | apply (drule less_le_trans[OF _ nrows_spvec]) | |
| 654 | apply (subgoal_tac "ja = j") | |
| 655 | apply (simp add: sorted_sparse_row_matrix_zero) | |
| 656 | apply (arith) | |
| 657 | apply (rule nrows) | |
| 658 | apply (rule order_trans[of _ 1 _]) | |
| 659 | apply (simp) | |
| 660 | apply (case_tac "nat (int ja - int j) = 0") | |
| 661 | apply (case_tac "ja = j") | |
| 662 | apply (simp add: sorted_sparse_row_matrix_zero) | |
| 663 | apply arith+ | |
| 664 | done | |
| 665 | ||
| 666 | lemma disj_move_sparse_row_vector_twice: | |
| 667 | "j \<noteq> u \<Longrightarrow> disj_matrices (move_matrix (sparse_row_vector a) j i) (move_matrix (sparse_row_vector b) u v)" | |
| 668 | apply (auto simp add: neg_def disj_matrices_def) | |
| 669 | apply (rule nrows, rule order_trans[of _ 1], simp, drule nrows_notzero, drule less_le_trans[OF _ nrows_spvec], arith)+ | |
| 670 | done | |
| 671 | ||
| 31816 | 672 | lemma le_spvec_iff_sparse_row_le[rule_format]: "(sorted_spvec a) \<longrightarrow> (sorted_spvec b) \<longrightarrow> (le_spvec a b) = (sparse_row_vector a <= sparse_row_vector b)" | 
| 31817 | 673 | apply (induct a b rule: le_spvec.induct) | 
| 15178 | 674 | apply (simp_all add: sorted_spvec_cons1 disj_matrices_add_le_zero disj_matrices_add_zero_le | 
| 675 | disj_sparse_row_singleton[OF order_refl] disj_matrices_commute) | |
| 676 | apply (rule conjI, intro strip) | |
| 677 | apply (simp add: sorted_spvec_cons1) | |
| 678 | apply (subst disj_matrices_add_x_le) | |
| 679 | apply (simp add: disj_sparse_row_singleton[OF less_imp_le] disj_matrices_x_add disj_matrices_commute) | |
| 680 | apply (simp add: disj_sparse_row_singleton[OF order_refl] disj_matrices_commute) | |
| 681 | apply (simp, blast) | |
| 682 | apply (intro strip, rule conjI, intro strip) | |
| 683 | apply (simp add: sorted_spvec_cons1) | |
| 684 | apply (subst disj_matrices_add_le_x) | |
| 685 | apply (simp_all add: disj_sparse_row_singleton[OF order_refl] disj_sparse_row_singleton[OF less_imp_le] disj_matrices_commute disj_matrices_x_add) | |
| 686 | apply (blast) | |
| 687 | apply (intro strip) | |
| 688 | apply (simp add: sorted_spvec_cons1) | |
| 31816 | 689 | apply (case_tac "a=b", simp_all) | 
| 15178 | 690 | apply (subst disj_matrices_add) | 
| 691 | apply (simp_all add: disj_sparse_row_singleton[OF order_refl] disj_matrices_commute) | |
| 15009 | 692 | done | 
| 693 | ||
| 31816 | 694 | lemma le_spvec_empty2_sparse_row[rule_format]: "sorted_spvec b \<longrightarrow> le_spvec b [] = (sparse_row_vector b <= 0)" | 
| 15009 | 695 | apply (induct b) | 
| 696 | apply (simp_all add: sorted_spvec_cons1) | |
| 697 | apply (intro strip) | |
| 698 | apply (subst disj_matrices_add_le_zero) | |
| 31816 | 699 | apply (auto simp add: disj_matrices_commute disj_sparse_row_singleton[OF order_refl] sorted_spvec_cons1) | 
| 15009 | 700 | done | 
| 701 | ||
| 31816 | 702 | lemma le_spvec_empty1_sparse_row[rule_format]: "(sorted_spvec b) \<longrightarrow> (le_spvec [] b = (0 <= sparse_row_vector b))" | 
| 15009 | 703 | apply (induct b) | 
| 704 | apply (simp_all add: sorted_spvec_cons1) | |
| 705 | apply (intro strip) | |
| 706 | apply (subst disj_matrices_add_zero_le) | |
| 31816 | 707 | apply (auto simp add: disj_matrices_commute disj_sparse_row_singleton[OF order_refl] sorted_spvec_cons1) | 
| 15009 | 708 | done | 
| 709 | ||
| 710 | lemma le_spmat_iff_sparse_row_le[rule_format]: "(sorted_spvec A) \<longrightarrow> (sorted_spmat A) \<longrightarrow> (sorted_spvec B) \<longrightarrow> (sorted_spmat B) \<longrightarrow> | |
| 31816 | 711 | le_spmat A B = (sparse_row_matrix A <= sparse_row_matrix B)" | 
| 31817 | 712 | apply (induct A B rule: le_spmat.induct) | 
| 15009 | 713 | apply (simp add: sparse_row_matrix_cons disj_matrices_add_le_zero disj_matrices_add_zero_le disj_move_sparse_vec_mat[OF order_refl] | 
| 714 | disj_matrices_commute sorted_spvec_cons1 le_spvec_empty2_sparse_row le_spvec_empty1_sparse_row)+ | |
| 715 | apply (rule conjI, intro strip) | |
| 716 | apply (simp add: sorted_spvec_cons1) | |
| 717 | apply (subst disj_matrices_add_x_le) | |
| 718 | apply (rule disj_matrices_add_x) | |
| 719 | apply (simp add: disj_move_sparse_row_vector_twice) | |
| 720 | apply (simp add: disj_move_sparse_vec_mat[OF less_imp_le] disj_matrices_commute) | |
| 721 | apply (simp add: disj_move_sparse_vec_mat[OF order_refl] disj_matrices_commute) | |
| 722 | apply (simp, blast) | |
| 723 | apply (intro strip, rule conjI, intro strip) | |
| 724 | apply (simp add: sorted_spvec_cons1) | |
| 725 | apply (subst disj_matrices_add_le_x) | |
| 726 | apply (simp add: disj_move_sparse_vec_mat[OF order_refl]) | |
| 727 | apply (rule disj_matrices_x_add) | |
| 728 | apply (simp add: disj_move_sparse_row_vector_twice) | |
| 729 | apply (simp add: disj_move_sparse_vec_mat[OF less_imp_le] disj_matrices_commute) | |
| 730 | apply (simp, blast) | |
| 731 | apply (intro strip) | |
| 31816 | 732 | apply (case_tac "i=j") | 
| 15009 | 733 | apply (simp_all) | 
| 734 | apply (subst disj_matrices_add) | |
| 735 | apply (simp_all add: disj_matrices_commute disj_move_sparse_vec_mat[OF order_refl]) | |
| 736 | apply (simp add: sorted_spvec_cons1 le_spvec_iff_sparse_row_le) | |
| 737 | done | |
| 738 | ||
| 24124 
4399175e3014
turned simp_depth_limit into configuration option;
 wenzelm parents: 
23477diff
changeset | 739 | declare [[simp_depth_limit = 999]] | 
| 15178 | 740 | |
| 38273 | 741 | primrec abs_spmat :: "('a::lattice_ring) spmat \<Rightarrow> 'a spmat"
 | 
| 742 | where | |
| 743 | "abs_spmat [] = []" | |
| 744 | | "abs_spmat (a#as) = (fst a, abs_spvec (snd a))#(abs_spmat as)" | |
| 15178 | 745 | |
| 38273 | 746 | primrec minus_spmat :: "('a::lattice_ring) spmat \<Rightarrow> 'a spmat"
 | 
| 747 | where | |
| 748 | "minus_spmat [] = []" | |
| 749 | | "minus_spmat (a#as) = (fst a, minus_spvec (snd a))#(minus_spmat as)" | |
| 15178 | 750 | |
| 751 | lemma sparse_row_matrix_minus: | |
| 752 | "sparse_row_matrix (minus_spmat A) = - (sparse_row_matrix A)" | |
| 753 | apply (induct A) | |
| 754 | apply (simp_all add: sparse_row_vector_minus sparse_row_matrix_cons) | |
| 755 | apply (subst Rep_matrix_inject[symmetric]) | |
| 756 | apply (rule ext)+ | |
| 757 | apply simp | |
| 758 | done | |
| 15009 | 759 | |
| 15178 | 760 | lemma Rep_sparse_row_vector_zero: "x \<noteq> 0 \<Longrightarrow> Rep_matrix (sparse_row_vector v) x y = 0" | 
| 761 | proof - | |
| 762 | assume x:"x \<noteq> 0" | |
| 763 | have r:"nrows (sparse_row_vector v) <= Suc 0" by (rule nrows_spvec) | |
| 764 | show ?thesis | |
| 765 | apply (rule nrows) | |
| 766 | apply (subgoal_tac "Suc 0 <= x") | |
| 767 | apply (insert r) | |
| 768 | apply (simp only:) | |
| 769 | apply (insert x) | |
| 770 | apply arith | |
| 771 | done | |
| 772 | qed | |
| 773 | ||
| 774 | lemma sparse_row_matrix_abs: | |
| 775 | "sorted_spvec A \<Longrightarrow> sorted_spmat A \<Longrightarrow> sparse_row_matrix (abs_spmat A) = abs (sparse_row_matrix A)" | |
| 776 | apply (induct A) | |
| 777 | apply (simp_all add: sparse_row_vector_abs sparse_row_matrix_cons) | |
| 778 | apply (frule_tac sorted_spvec_cons1, simp) | |
| 15580 | 779 | apply (simplesubst Rep_matrix_inject[symmetric]) | 
| 15178 | 780 | apply (rule ext)+ | 
| 781 | apply auto | |
| 782 | apply (case_tac "x=a") | |
| 783 | apply (simp) | |
| 15481 | 784 | apply (simplesubst sorted_sparse_row_matrix_zero) | 
| 15178 | 785 | apply auto | 
| 15481 | 786 | apply (simplesubst Rep_sparse_row_vector_zero) | 
| 15178 | 787 | apply (simp_all add: neg_def) | 
| 788 | done | |
| 789 | ||
| 790 | lemma sorted_spvec_minus_spmat: "sorted_spvec A \<Longrightarrow> sorted_spvec (minus_spmat A)" | |
| 791 | apply (induct A) | |
| 792 | apply (simp) | |
| 793 | apply (frule sorted_spvec_cons1, simp) | |
| 15236 
f289e8ba2bb3
Proofs needed to be updated because induction now preserves name of
 nipkow parents: 
15197diff
changeset | 794 | apply (simp add: sorted_spvec.simps split:list.split_asm) | 
| 15178 | 795 | done | 
| 796 | ||
| 797 | lemma sorted_spvec_abs_spmat: "sorted_spvec A \<Longrightarrow> sorted_spvec (abs_spmat A)" | |
| 798 | apply (induct A) | |
| 799 | apply (simp) | |
| 800 | apply (frule sorted_spvec_cons1, simp) | |
| 15236 
f289e8ba2bb3
Proofs needed to be updated because induction now preserves name of
 nipkow parents: 
15197diff
changeset | 801 | apply (simp add: sorted_spvec.simps split:list.split_asm) | 
| 15178 | 802 | done | 
| 803 | ||
| 804 | lemma sorted_spmat_minus_spmat: "sorted_spmat A \<Longrightarrow> sorted_spmat (minus_spmat A)" | |
| 805 | apply (induct A) | |
| 806 | apply (simp_all add: sorted_spvec_minus_spvec) | |
| 807 | done | |
| 808 | ||
| 809 | lemma sorted_spmat_abs_spmat: "sorted_spmat A \<Longrightarrow> sorted_spmat (abs_spmat A)" | |
| 810 | apply (induct A) | |
| 811 | apply (simp_all add: sorted_spvec_abs_spvec) | |
| 812 | done | |
| 15009 | 813 | |
| 38273 | 814 | definition diff_spmat :: "('a::lattice_ring) spmat \<Rightarrow> 'a spmat \<Rightarrow> 'a spmat"
 | 
| 815 | where "diff_spmat A B = add_spmat A (minus_spmat B)" | |
| 15178 | 816 | |
| 817 | lemma sorted_spmat_diff_spmat: "sorted_spmat A \<Longrightarrow> sorted_spmat B \<Longrightarrow> sorted_spmat (diff_spmat A B)" | |
| 818 | by (simp add: diff_spmat_def sorted_spmat_minus_spmat sorted_spmat_add_spmat) | |
| 819 | ||
| 820 | lemma sorted_spvec_diff_spmat: "sorted_spvec A \<Longrightarrow> sorted_spvec B \<Longrightarrow> sorted_spvec (diff_spmat A B)" | |
| 821 | by (simp add: diff_spmat_def sorted_spvec_minus_spmat sorted_spvec_add_spmat) | |
| 822 | ||
| 823 | lemma sparse_row_diff_spmat: "sparse_row_matrix (diff_spmat A B ) = (sparse_row_matrix A) - (sparse_row_matrix B)" | |
| 824 | by (simp add: diff_spmat_def sparse_row_add_spmat sparse_row_matrix_minus) | |
| 825 | ||
| 38273 | 826 | definition sorted_sparse_matrix :: "'a spmat \<Rightarrow> bool" | 
| 827 | where "sorted_sparse_matrix A \<longleftrightarrow> sorted_spvec A & sorted_spmat A" | |
| 15178 | 828 | |
| 829 | lemma sorted_sparse_matrix_imp_spvec: "sorted_sparse_matrix A \<Longrightarrow> sorted_spvec A" | |
| 830 | by (simp add: sorted_sparse_matrix_def) | |
| 831 | ||
| 832 | lemma sorted_sparse_matrix_imp_spmat: "sorted_sparse_matrix A \<Longrightarrow> sorted_spmat A" | |
| 833 | by (simp add: sorted_sparse_matrix_def) | |
| 834 | ||
| 835 | lemmas sorted_sp_simps = | |
| 836 | sorted_spvec.simps | |
| 837 | sorted_spmat.simps | |
| 838 | sorted_sparse_matrix_def | |
| 839 | ||
| 840 | lemma bool1: "(\<not> True) = False" by blast | |
| 841 | lemma bool2: "(\<not> False) = True" by blast | |
| 842 | lemma bool3: "((P\<Colon>bool) \<and> True) = P" by blast | |
| 843 | lemma bool4: "(True \<and> (P\<Colon>bool)) = P" by blast | |
| 844 | lemma bool5: "((P\<Colon>bool) \<and> False) = False" by blast | |
| 845 | lemma bool6: "(False \<and> (P\<Colon>bool)) = False" by blast | |
| 846 | lemma bool7: "((P\<Colon>bool) \<or> True) = True" by blast | |
| 847 | lemma bool8: "(True \<or> (P\<Colon>bool)) = True" by blast | |
| 848 | lemma bool9: "((P\<Colon>bool) \<or> False) = P" by blast | |
| 849 | lemma bool10: "(False \<or> (P\<Colon>bool)) = P" by blast | |
| 850 | lemmas boolarith = bool1 bool2 bool3 bool4 bool5 bool6 bool7 bool8 bool9 bool10 | |
| 851 | ||
| 852 | lemma if_case_eq: "(if b then x else y) = (case b of True => x | False => y)" by simp | |
| 853 | ||
| 38273 | 854 | primrec pprt_spvec :: "('a::{lattice_ab_group_add}) spvec \<Rightarrow> 'a spvec"
 | 
| 855 | where | |
| 856 | "pprt_spvec [] = []" | |
| 857 | | "pprt_spvec (a#as) = (fst a, pprt (snd a)) # (pprt_spvec as)" | |
| 15580 | 858 | |
| 38273 | 859 | primrec nprt_spvec :: "('a::{lattice_ab_group_add}) spvec \<Rightarrow> 'a spvec"
 | 
| 860 | where | |
| 15580 | 861 | "nprt_spvec [] = []" | 
| 38273 | 862 | | "nprt_spvec (a#as) = (fst a, nprt (snd a)) # (nprt_spvec as)" | 
| 15580 | 863 | |
| 38273 | 864 | primrec pprt_spmat :: "('a::{lattice_ab_group_add}) spmat \<Rightarrow> 'a spmat"
 | 
| 865 | where | |
| 15580 | 866 | "pprt_spmat [] = []" | 
| 38273 | 867 | | "pprt_spmat (a#as) = (fst a, pprt_spvec (snd a))#(pprt_spmat as)" | 
| 15580 | 868 | |
| 38273 | 869 | primrec nprt_spmat :: "('a::{lattice_ab_group_add}) spmat \<Rightarrow> 'a spmat"
 | 
| 870 | where | |
| 15580 | 871 | "nprt_spmat [] = []" | 
| 38273 | 872 | | "nprt_spmat (a#as) = (fst a, nprt_spvec (snd a))#(nprt_spmat as)" | 
| 15580 | 873 | |
| 874 | ||
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 875 | lemma pprt_add: "disj_matrices A (B::(_::lattice_ring) matrix) \<Longrightarrow> pprt (A+B) = pprt A + pprt B" | 
| 22452 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
 haftmann parents: 
20432diff
changeset | 876 | apply (simp add: pprt_def sup_matrix_def) | 
| 15580 | 877 | apply (simp add: Rep_matrix_inject[symmetric]) | 
| 878 | apply (rule ext)+ | |
| 879 | apply simp | |
| 880 | apply (case_tac "Rep_matrix A x xa \<noteq> 0") | |
| 881 | apply (simp_all add: disj_matrices_contr1) | |
| 882 | done | |
| 883 | ||
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 884 | lemma nprt_add: "disj_matrices A (B::(_::lattice_ring) matrix) \<Longrightarrow> nprt (A+B) = nprt A + nprt B" | 
| 22452 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
 haftmann parents: 
20432diff
changeset | 885 | apply (simp add: nprt_def inf_matrix_def) | 
| 15580 | 886 | apply (simp add: Rep_matrix_inject[symmetric]) | 
| 887 | apply (rule ext)+ | |
| 888 | apply simp | |
| 889 | apply (case_tac "Rep_matrix A x xa \<noteq> 0") | |
| 890 | apply (simp_all add: disj_matrices_contr1) | |
| 891 | done | |
| 892 | ||
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 893 | lemma pprt_singleton[simp]: "pprt (singleton_matrix j i (x::_::lattice_ring)) = singleton_matrix j i (pprt x)" | 
| 22452 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
 haftmann parents: 
20432diff
changeset | 894 | apply (simp add: pprt_def sup_matrix_def) | 
| 15580 | 895 | apply (simp add: Rep_matrix_inject[symmetric]) | 
| 896 | apply (rule ext)+ | |
| 897 | apply simp | |
| 898 | done | |
| 899 | ||
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 900 | lemma nprt_singleton[simp]: "nprt (singleton_matrix j i (x::_::lattice_ring)) = singleton_matrix j i (nprt x)" | 
| 22452 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
 haftmann parents: 
20432diff
changeset | 901 | apply (simp add: nprt_def inf_matrix_def) | 
| 15580 | 902 | apply (simp add: Rep_matrix_inject[symmetric]) | 
| 903 | apply (rule ext)+ | |
| 904 | apply simp | |
| 905 | done | |
| 906 | ||
| 907 | lemma less_imp_le: "a < b \<Longrightarrow> a <= (b::_::order)" by (simp add: less_def) | |
| 908 | ||
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 909 | lemma sparse_row_vector_pprt: "sorted_spvec (v :: 'a::lattice_ring spvec) \<Longrightarrow> sparse_row_vector (pprt_spvec v) = pprt (sparse_row_vector v)" | 
| 15580 | 910 | apply (induct v) | 
| 911 | apply (simp_all) | |
| 912 | apply (frule sorted_spvec_cons1, auto) | |
| 913 | apply (subst pprt_add) | |
| 914 | apply (subst disj_matrices_commute) | |
| 915 | apply (rule disj_sparse_row_singleton) | |
| 916 | apply auto | |
| 917 | done | |
| 918 | ||
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 919 | lemma sparse_row_vector_nprt: "sorted_spvec (v :: 'a::lattice_ring spvec) \<Longrightarrow> sparse_row_vector (nprt_spvec v) = nprt (sparse_row_vector v)" | 
| 15580 | 920 | apply (induct v) | 
| 921 | apply (simp_all) | |
| 922 | apply (frule sorted_spvec_cons1, auto) | |
| 923 | apply (subst nprt_add) | |
| 924 | apply (subst disj_matrices_commute) | |
| 925 | apply (rule disj_sparse_row_singleton) | |
| 926 | apply auto | |
| 927 | done | |
| 928 | ||
| 929 | ||
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 930 | lemma pprt_move_matrix: "pprt (move_matrix (A::('a::lattice_ring) matrix) j i) = move_matrix (pprt A) j i"
 | 
| 15580 | 931 | apply (simp add: pprt_def) | 
| 22452 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
 haftmann parents: 
20432diff
changeset | 932 | apply (simp add: sup_matrix_def) | 
| 15580 | 933 | apply (simp add: Rep_matrix_inject[symmetric]) | 
| 934 | apply (rule ext)+ | |
| 935 | apply (simp) | |
| 936 | done | |
| 937 | ||
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 938 | lemma nprt_move_matrix: "nprt (move_matrix (A::('a::lattice_ring) matrix) j i) = move_matrix (nprt A) j i"
 | 
| 15580 | 939 | apply (simp add: nprt_def) | 
| 22452 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
 haftmann parents: 
20432diff
changeset | 940 | apply (simp add: inf_matrix_def) | 
| 15580 | 941 | apply (simp add: Rep_matrix_inject[symmetric]) | 
| 942 | apply (rule ext)+ | |
| 943 | apply (simp) | |
| 944 | done | |
| 945 | ||
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 946 | lemma sparse_row_matrix_pprt: "sorted_spvec (m :: 'a::lattice_ring spmat) \<Longrightarrow> sorted_spmat m \<Longrightarrow> sparse_row_matrix (pprt_spmat m) = pprt (sparse_row_matrix m)" | 
| 15580 | 947 | apply (induct m) | 
| 948 | apply simp | |
| 949 | apply simp | |
| 950 | apply (frule sorted_spvec_cons1) | |
| 951 | apply (simp add: sparse_row_matrix_cons sparse_row_vector_pprt) | |
| 952 | apply (subst pprt_add) | |
| 953 | apply (subst disj_matrices_commute) | |
| 954 | apply (rule disj_move_sparse_vec_mat) | |
| 955 | apply auto | |
| 956 | apply (simp add: sorted_spvec.simps) | |
| 957 | apply (simp split: list.split) | |
| 958 | apply auto | |
| 959 | apply (simp add: pprt_move_matrix) | |
| 960 | done | |
| 961 | ||
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 962 | lemma sparse_row_matrix_nprt: "sorted_spvec (m :: 'a::lattice_ring spmat) \<Longrightarrow> sorted_spmat m \<Longrightarrow> sparse_row_matrix (nprt_spmat m) = nprt (sparse_row_matrix m)" | 
| 15580 | 963 | apply (induct m) | 
| 964 | apply simp | |
| 965 | apply simp | |
| 966 | apply (frule sorted_spvec_cons1) | |
| 967 | apply (simp add: sparse_row_matrix_cons sparse_row_vector_nprt) | |
| 968 | apply (subst nprt_add) | |
| 969 | apply (subst disj_matrices_commute) | |
| 970 | apply (rule disj_move_sparse_vec_mat) | |
| 971 | apply auto | |
| 972 | apply (simp add: sorted_spvec.simps) | |
| 973 | apply (simp split: list.split) | |
| 974 | apply auto | |
| 975 | apply (simp add: nprt_move_matrix) | |
| 976 | done | |
| 977 | ||
| 978 | lemma sorted_pprt_spvec: "sorted_spvec v \<Longrightarrow> sorted_spvec (pprt_spvec v)" | |
| 979 | apply (induct v) | |
| 980 | apply (simp) | |
| 981 | apply (frule sorted_spvec_cons1) | |
| 982 | apply simp | |
| 983 | apply (simp add: sorted_spvec.simps split:list.split_asm) | |
| 984 | done | |
| 985 | ||
| 986 | lemma sorted_nprt_spvec: "sorted_spvec v \<Longrightarrow> sorted_spvec (nprt_spvec v)" | |
| 987 | apply (induct v) | |
| 988 | apply (simp) | |
| 989 | apply (frule sorted_spvec_cons1) | |
| 990 | apply simp | |
| 991 | apply (simp add: sorted_spvec.simps split:list.split_asm) | |
| 992 | done | |
| 993 | ||
| 994 | lemma sorted_spvec_pprt_spmat: "sorted_spvec m \<Longrightarrow> sorted_spvec (pprt_spmat m)" | |
| 995 | apply (induct m) | |
| 996 | apply (simp) | |
| 997 | apply (frule sorted_spvec_cons1) | |
| 998 | apply simp | |
| 999 | apply (simp add: sorted_spvec.simps split:list.split_asm) | |
| 1000 | done | |
| 1001 | ||
| 1002 | lemma sorted_spvec_nprt_spmat: "sorted_spvec m \<Longrightarrow> sorted_spvec (nprt_spmat m)" | |
| 1003 | apply (induct m) | |
| 1004 | apply (simp) | |
| 1005 | apply (frule sorted_spvec_cons1) | |
| 1006 | apply simp | |
| 1007 | apply (simp add: sorted_spvec.simps split:list.split_asm) | |
| 1008 | done | |
| 1009 | ||
| 1010 | lemma sorted_spmat_pprt_spmat: "sorted_spmat m \<Longrightarrow> sorted_spmat (pprt_spmat m)" | |
| 1011 | apply (induct m) | |
| 1012 | apply (simp_all add: sorted_pprt_spvec) | |
| 1013 | done | |
| 1014 | ||
| 1015 | lemma sorted_spmat_nprt_spmat: "sorted_spmat m \<Longrightarrow> sorted_spmat (nprt_spmat m)" | |
| 1016 | apply (induct m) | |
| 1017 | apply (simp_all add: sorted_nprt_spvec) | |
| 1018 | done | |
| 1019 | ||
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
35028diff
changeset | 1020 | definition mult_est_spmat :: "('a::lattice_ring) spmat \<Rightarrow> 'a spmat \<Rightarrow> 'a spmat \<Rightarrow> 'a spmat \<Rightarrow> 'a spmat" where
 | 
| 38273 | 1021 | "mult_est_spmat r1 r2 s1 s2 = | 
| 31816 | 1022 | add_spmat (mult_spmat (pprt_spmat s2) (pprt_spmat r2)) (add_spmat (mult_spmat (pprt_spmat s1) (nprt_spmat r2)) | 
| 1023 | (add_spmat (mult_spmat (nprt_spmat s2) (pprt_spmat r1)) (mult_spmat (nprt_spmat s1) (nprt_spmat r1))))" | |
| 15580 | 1024 | |
| 1025 | lemmas sparse_row_matrix_op_simps = | |
| 1026 | sorted_sparse_matrix_imp_spmat sorted_sparse_matrix_imp_spvec | |
| 1027 | sparse_row_add_spmat sorted_spvec_add_spmat sorted_spmat_add_spmat | |
| 1028 | sparse_row_diff_spmat sorted_spvec_diff_spmat sorted_spmat_diff_spmat | |
| 1029 | sparse_row_matrix_minus sorted_spvec_minus_spmat sorted_spmat_minus_spmat | |
| 1030 | sparse_row_mult_spmat sorted_spvec_mult_spmat sorted_spmat_mult_spmat | |
| 1031 | sparse_row_matrix_abs sorted_spvec_abs_spmat sorted_spmat_abs_spmat | |
| 1032 | le_spmat_iff_sparse_row_le | |
| 1033 | sparse_row_matrix_pprt sorted_spvec_pprt_spmat sorted_spmat_pprt_spmat | |
| 1034 | sparse_row_matrix_nprt sorted_spvec_nprt_spmat sorted_spmat_nprt_spmat | |
| 1035 | ||
| 1036 | lemma zero_eq_Numeral0: "(0::_::number_ring) = Numeral0" by simp | |
| 1037 | ||
| 1038 | lemmas sparse_row_matrix_arith_simps[simplified zero_eq_Numeral0] = | |
| 1039 | mult_spmat.simps mult_spvec_spmat.simps | |
| 1040 | addmult_spvec.simps | |
| 1041 | smult_spvec_empty smult_spvec_cons | |
| 1042 | add_spmat.simps add_spvec.simps | |
| 1043 | minus_spmat.simps minus_spvec.simps | |
| 1044 | abs_spmat.simps abs_spvec.simps | |
| 1045 | diff_spmat_def | |
| 1046 | le_spmat.simps le_spvec.simps | |
| 1047 | pprt_spmat.simps pprt_spvec.simps | |
| 1048 | nprt_spmat.simps nprt_spvec.simps | |
| 1049 | mult_est_spmat_def | |
| 1050 | ||
| 1051 | ||
| 1052 | (*lemma spm_linprog_dual_estimate_1: | |
| 15178 | 1053 | assumes | 
| 1054 | "sorted_sparse_matrix A1" | |
| 1055 | "sorted_sparse_matrix A2" | |
| 1056 | "sorted_sparse_matrix c1" | |
| 1057 | "sorted_sparse_matrix c2" | |
| 1058 | "sorted_sparse_matrix y" | |
| 1059 | "sorted_spvec b" | |
| 1060 | "sorted_spvec r" | |
| 1061 | "le_spmat ([], y)" | |
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
32491diff
changeset | 1062 |   "A * x \<le> sparse_row_matrix (b::('a::lattice_ring) spmat)"
 | 
| 15178 | 1063 | "sparse_row_matrix A1 <= A" | 
| 1064 | "A <= sparse_row_matrix A2" | |
| 1065 | "sparse_row_matrix c1 <= c" | |
| 1066 | "c <= sparse_row_matrix c2" | |
| 1067 | "abs x \<le> sparse_row_matrix r" | |
| 1068 | shows | |
| 1069 | "c * x \<le> sparse_row_matrix (add_spmat (mult_spmat y b, mult_spmat (add_spmat (add_spmat (mult_spmat y (diff_spmat A2 A1), | |
| 1070 | abs_spmat (diff_spmat (mult_spmat y A1) c1)), diff_spmat c2 c1)) r))" | |
| 1071 | by (insert prems, simp add: sparse_row_matrix_op_simps linprog_dual_estimate_1[where A=A]) | |
| 15580 | 1072 | *) | 
| 15009 | 1073 | |
| 1074 | end |