develooper Front page | perl.perl6.language | Postings from January 2004

Re: Semantics of vector operations

Thread Previous | Thread Next
Larry Wall
January 22, 2004 16:37
Re: Semantics of vector operations
Message ID:
On Thu, Jan 22, 2004 at 02:28:09PM -0700, Luke Palmer wrote:
: Well, for being called "vector operators", they're ending up pretty
: useless as far as working with mathematical vectors.

Which is why I suggested calling them distributors or some such.

: As a
: mathematician, I'd want:
:     @vec1 »*« @vec2
: To do an inner or an outer product (probably outer, as it has no
: implicit connotations of the + operator).  That is, it would come out
: either a matrix or a scalar.
: But there are other times when I'd want that to call the operator
: respectively.  Then you get this for the inner product:
:     sum(@vec1 »*« @vec2)
: Which isn't so bad, after all.

Yes, and I think we have to stick with the naive view of what »*« would
do, since there are times you simply want to do a bunch of multiplications
in parallel.

: Hmm, but if it does give an outer product, then a generic tensor product
: is as easy as:
:     reduce { $^a »+« $^b } @A »*« @B
: And nobody can fathom how happy that would make me.

I'd think it would make you even happier to just use the appropriate
Unicode operators directly (presuming there are such).

: Also, you'd get the nice consistency that:
:     @A »+« @B
: Is the same as both:
:     map { @A »+ $^b } @B
:     map { $^a +« @B } @A
: Which is undoubtedly what the mathematician would expect  (It's very
: reminiscent of how junctions currently work).
: But then there's the problem of how you express the oft-wanted:
:     map -> $i { @A[$i] + @B[$i] } 0..^min(+@A, +@B)
: (Hopefully when @A and @B are of equal length).

Yes, though in fact »« is supposed to do max() rather than min() here.
Which, in the case of arrays of equal length, comes out to the same

: Maybe there's a way to do it so that we can both be happy: one syntax
: that does one thing, another that does the other.  Like:
:     @A »+« @B           # One-at-a-time
:     @A «+» @B           # Outer product
: Or something.  Hmm, then both:
:     @A »+ $b
:     @A «+ $b
: Would mean the same thing. 

Which says to me that outer product really wants to be something like
X or ✕ or even ∘ (shades of APL).  In the for-what-it's-worth department,
it looks like Python might be using @ for that.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About