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