On Sat, Mar 15, 2014 at 10:21 AM, Nathaniel Smith <n...@pobox.com> wrote:
> On Fri, Mar 14, 2014 at 8:48 PM, William Stein <wst...@gmail.com> wrote:
>> In retrospect, it appears that the OP should have asked the following
>> question:   From the perspective of Sage, if Python were to have
>> another arithmetic operator (denoted @) with identical precedence
>> rules to *, would we use it for anything?  Would we extend the
>> coercion model, etc.?   Are there any algebraic structures at all that
>> have two different "multiplications"?
>
> Indeed, this probably would have been the correct question, if only
> I'd known! But the end result is that I learned a lot about how Sage
> approaches things that I didn't know before, and the PEP got much
> stronger from getting this feedback from a perspective I hadn't
> understood before -- in fact I rewrote large parts of it in response
> to comments here and on the sympy list. Thank you very much to
> everyone who took the time to comment.
>
> The current status, in case anyone is curious, is that it looks like
> '@' will in fact appear in Python 3.5, once some details are worked
> out:
>   https://github.com/numpy/numpy/pull/4351#issuecomment-37717330
> If anyone here does have any opinions on those details then I'd love
> to hear them.
>
>> His actual
>> PEP had something claiming we had added something to the preparser,
>> but that was not a multiplication operator, but simply a backslash
>> shorthand for matrix inversion, like in Matlab, that nobody uses or
>> cares about  -- I just added it one day for fun in the early days --
>> based on no demand.
>
> Hmm, I don't remember saying this, and the text changed quite a bit
> from what I originally sent around, but if you see any remaining
> inaccuracies then please let me know so I can fix them! :-):
>    http://legacy.python.org/dev/peps/pep-0465/
> (In fact I know there's one inaccuracy in that version -- it says that
> sage & sympy don't implement elementwise multiplication at all. My
> local draft changes that to "Projects which currently use * for matrix
> multiplication, and
> which don't really care about elementwise multiplication at all",
> which I think is closer to the truth?)

It's not that we don't care about elementwise multiplication of
*arrays*, it's that we don't care about elementwise multiplication of
*matrices* (and I've yet to find any use of the latter at all).

I think the problem of numpy.matrix is
http://en.wikipedia.org/wiki/Composition_over_inheritance There's
currently only a single example (after much searching) where the two
need to be mixed--an explicit conversion would be fine here.

I am also opposed to this PEP as it singles out one (or two) special
operators that behave differently than any other operator w.r.t. *not*
being elementwise. The current behavior is much easier to understand.
(I'm also not a fan of @ being both an operator and being used for
decorators... but that's a different issue.)

Also, this is not just about multiplication (or exponentiation). Note
that for a matrix M and a scalar a the sum M + a is M + I a (where I
is the identity matrix), again not elementwise.

sage: import numpy as np
sage: a = np.array([[1,2],[3,4]])
sage: a
array([[1, 2],
       [3, 4]])
sage: a + 100
array([[101, 102],
       [103, 104]])

sage: M = matrix([[1,2],[3,4]]); M
[1 2]
[3 4]
sage: M + 100
[101   2]
[  3 104]

- Robert

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to