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