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