Neither. There already is a perfectly good notation for the dot product of two vectors:
vec1⋅vec2
Why do you want to invent a new one?
Here is a simple example in Haskell:
a ⋅ b = foldl1 (+) $ zipWith (*) a b
infixl 7 ⋅
main = putStrLn $ show $ [1, 3, -5] ⋅ [4, -2, -1]
-- 3
This declares ⋅ to be a left-associative infix operator at precedence level 7, which is the same associativity, fixity and precedence as Haskell’s other multiplication operators. (Although, generally speaking, the dot product is usually non-associative, so you might want to make it infix 7 instead, to avoid confusion.)
Here is another example in Scala:
sealed case class Vector[T](ns: T*)(implicit n: Numeric[T]) {
def ⋅(o: Vector[T]) =
ns zip o.ns map {case (a, b) => n.times(a, b) } reduceLeft (n.plus _)
}
println(Vector(1, 3, -5)⋅Vector(4, -2, -1))
// 3
Unfortunately, Scala doesn’t support user-defined precedence or associativity.
And even in a very restrictive language like Ruby, which unfortunately doesn’t support user-defined operators at all, you can still get a pretty reasonable result by just using a plain old method instead of an operator:
#encoding: UTF-8
class Vector
def initialize(*ns)
@ns = ns
end
def ⋅ o
ns.zip(o.ns).map{|a, b| a*b }.reduce(:+)
end
protected
attr_reader :ns
end
def Vector(*ns)
Vector.new(*ns)
end
puts Vector(1, 3, -5).⋅ Vector(4, -2, -1)
# 3
Or in Clojure:
(defn ⋅ [a b] (reduce + (map * a b)))
(println (⋅ [1 3 -5] [4 -2 -1]))
[Note: the example is obviously very simplistic, since it uses a simple list of numbers for the vector representation. Obviously, in a real vector implementation, you would use a proper Vector type.]
NumPylibrary do? – Job Apr 13 '11 at 16:39