text\<open>\noindent
A vector-space like structure of lists and arithmetic operations on them. Is only a vector space if restricted to lists of the same length.\<close>
text\<open>Multiplication with a scalar:\<close>
abbreviation scale :: "('a::times) \ 'a list \ 'a list" (infix \*\<^sub>s\ 70) where"x *\<^sub>s xs \ map ((*) x) xs"
subsection \<open>\<open>+\<close> and \<open>-\<close>\<close>
fun zipwith0 :: "('a::zero \ 'b::zero \ 'c) \ 'a list \ 'b list \ 'c list" where "zipwith0 f [] [] = []" | "zipwith0 f (x#xs) (y#ys) = f x y # zipwith0 f xs ys" | "zipwith0 f (x#xs) [] = f x 0 # zipwith0 f xs []" | "zipwith0 f [] (y#ys) = f 0 y # zipwith0 f [] ys"
instantiation list :: ("{zero, plus}") plus begin
definition
list_add_def: "(+) = zipwith0 (+)"
instance ..
end
instantiation list :: ("{zero, uminus}") uminus begin
definition
list_uminus_def: "uminus = map uminus"
instance ..
end
instantiation list :: ("{zero,minus}") minus begin
lemma iprod0_if_coeffs0: "\c\set cs. c = 0 \ \cs,xs\ = 0" proof (induct cs arbitrary: xs) case Nil thenshow ?caseby simp next case (Cons a cs xs) thenshow ?case by (cases xs; fastforce) qed
lemma iprod_left_add_distrib: "\xs + ys,zs\ = \xs,zs\ + \ys,zs\" proof (induct xs arbitrary: ys zs) case Nil thenshow ?caseby simp next case (Cons a xs ys zs) show ?case by (cases ys; cases zs; simp add: distrib_right Cons) qed
lemma iprod_left_diff_distrib: "\xs - ys, zs\ = \xs,zs\ - \ys,zs\" proof (induct xs arbitrary: ys zs) case Nil thenshow ?caseby simp next case (Cons a xs ys zs) show ?case by (cases ys; cases zs; simp add: left_diff_distrib Cons) qed
lemma iprod_assoc: "\x *\<^sub>s xs, ys\ = x * \xs,ys\" proof (induct xs arbitrary: ys) case Nil thenshow ?caseby simp next case (Cons a xs ys) show ?case by (cases ys; simp add: distrib_left mult.assoc Cons) qed
end
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.