equal
deleted
inserted
replaced
293 definition "scalar_product v w = (\<Sum> (x, y)\<leftarrow>zip v w. x * y)" |
293 definition "scalar_product v w = (\<Sum> (x, y)\<leftarrow>zip v w. x * y)" |
294 |
294 |
295 definition mv :: "('a :: semiring_0) list list \<Rightarrow> 'a list \<Rightarrow> 'a list" |
295 definition mv :: "('a :: semiring_0) list list \<Rightarrow> 'a list \<Rightarrow> 'a list" |
296 where [simp]: "mv M v = map (scalar_product v) M" |
296 where [simp]: "mv M v = map (scalar_product v) M" |
297 text \<open> |
297 text \<open> |
298 This defines the matrix vector multiplication. To work properly @{term |
298 This defines the matrix vector multiplication. To work properly \<^term>\<open>matrix M m n \<and> length v = n\<close> must hold. |
299 "matrix M m n \<and> length v = n"} must hold. |
|
300 \<close> |
299 \<close> |
301 |
300 |
302 subsection "Compressed matrix" |
301 subsection "Compressed matrix" |
303 |
302 |
304 definition "sparsify xs = [i \<leftarrow> zip [0..<length xs] xs. snd i \<noteq> 0]" |
303 definition "sparsify xs = [i \<leftarrow> zip [0..<length xs] xs. snd i \<noteq> 0]" |