Hi Nathaniel,

are you sure that you talk about actual matrices? Or do you just talk
about 2-dimensional arrays?

By the way, how could your PEP possibly be relevant to Python? IIRC,
there neither is a matrix type nor an array type in Python, thus, it
makes no sense whatsoever to theoretise about special symbols for matrix
multiplication and component-wise action on arrays in *Python*.

Such discussion sure makes sense in a CAS, though..

On 2014-03-09, Nathaniel Smith <n...@pobox.com> wrote:
> ...
> R alsos use * for elementwise mul. And really, it does work fine and
> is useful in many application areas, I promise! :-) I've sent similar
> heads-up emails to 13 projects now, and so far you guys are the only
> ones who have blinked at this part;

Quite bizarre indeed, as I'd thought that your suggestion will seem rather
odd to most mathematicians and computer scientists.

> Even * is pretty
> arbitrary the first time you see it -- real mathematical notation uses
> \cdot or occasionally \times, not \star -- but we forget this because
> we already learned it a while ago :-).

In mathematics, a lot of different multiplication symbols are in use.
For example, usually \cdot denotes pointwise multiplication, whereas
\star denotes convolution and \circ denotes composition, and there
is also cartesian product \times and tensor product \otimes. In
principal, all these operations can occur at the same time, thus, there
is no way around using a variety of symbols, to avoid confusion.

Thus, it would certainly be a reasonable PEP to provide a framework in
Python to define custom infix operators (say, operator.compose), by
providing a character (say: '@') and the name of a custom "magical
method" (say: '__composition__') that is called on the operator's
arguments, in the same way as operator.mul uses '*' and results in
calling '__mul__'.

However, in all algebraic textbooks I am aware of, \cdot is consistently
used to denote...
- multiplication in fields,
- the componentwise action of a field on vectors resp. matrices, aka
  scalar multiplication,
- the dot product of vectors (resulting in a field element)
- matrix multiplication,
- generally multiplication in a ring, unless different kinds of
  multiplication occur

It may seem natural to multiply two 2-dimensional ARRAYS component-wise.
However, if you have MATRICES that deserve such a title (say, they
encode a linear map) then "Matrix \cdot Matrix" clearly is matrix
multiplication and nothing else.

Python does not know about rings and vector spaces, whereas Sage does:
Sage uses '*' for multiplication in rings and for module actions. In
particular, by consistency, Sage must use '*' to denote multiplication
of square matrices (since this is multiplication in a matrix ring)

Python uses * to denote multiplication of numbers, which is \cdot in
textbooks. Hence, according to the "principle of least surprise", one
has to use * for what is commonly denoted by \cdot in textbooks. And
this includes matrix multiplication.

In conclusion:
1) Python has no array or matrix types, thus adding a special symbol for
   matrix multiplication makes no sense in Python.
2) It makes sense to support adding custom infix operators to Python.
3) Python could of course add an array type with component-wise
   multiplication and a matrix type with matrix multiplication. But
   please keep "arrays" and "matrices" apart.
4) It is common to use the same operator symbol for various types of
   operands. There is 'ab'+'cd' and 'ab'*3 in contrast to 3+4 and 4*3.
   So, why should one suddenly start using new symbols if the operand
   types happens to be "matrix"?

Best regards,
Simon


-- 
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