Should we add `a * b` for vectors?

jmh530 john.michael.hall at gmail.com
Sun Sep 24 23:55:36 UTC 2017


On Sunday, 24 September 2017 at 18:18:38 UTC, Mark wrote:
>
> Generally I expect that a binary operation denoted by + or * 
> would produce an element from the original domain, e.g. 
> multiplying two matrices yields a matrix, concatenating two 
> strings yields a string, etc. So personally I don't like this 
> notation.

This is true of element-wise operators. + works, - works, but * 
(and by implication /) only has that property for Hadamard/Schur 
products. It also would work for inverse. Even matrix 
multiplication could have A*B produce a matrix, but if A is 1XN 
and B is MX1, then you may as well return the scalar.

>
> Note that in the case of 3-dimensional vectors, people might 
> confuse this for the cross product. I would go with dot(a,b) 
> and cross(a,b) (if you support it).

I assure you, no one would confuse dot for cross. No language or 
linear algebra library does this. The typical option is matrix 
multiplication for *, but languages like Python and Matlab can't 
do things like have a special version that is dot for vectors and 
matrix multiplication for matrices.


More information about the Digitalmars-d mailing list