On Mon, Mar 17, 2014 at 6:33 PM, Christophe Bal <projetmbc@gmail.com> wrote:
I think that weak-left is a little strange, just think a little of the operators used by mathematicians that always follow a hierarchy. 

A parser is mostly done using grammars : see http://docs.python.org/3.1/reference/grammar.html.

Defining *-product to have stronger priority than the @-product, and this last having stronger priority than +, will make the changes in the grammar easier.

I'm now convinced of the usefulness of @ and @@ too but I also think that you must think of other uses than only for numpy. In other words, numpy is a the good argument for this new operators, but this can also open new perspectives for other uses.

My main problem with weak-left (* higher) and tight-left (@ higher) compared to same-left is that I don't see any obvious choice between the weak and tight. 
I don't think I would have problems with readability.

Wikipedia doesn't say anything about precedence of Hadamard versus matrix product.

matlab, IDL and Gauss (I checked the manual) all use same-left, as Nathaniel pointed out.

For scalar * together with dot product which is more common in formulas, we would just read it sequentially, i.e. same-left.

I don't remember when I have seen dot-in-a-circle in a paper, but I don't think there was any precedence either.

I guess the same applies for other (mis)uses of @

from math import sqrt

class MyOp(object):
    def __init__(self, func):
        self.func = func
    def __at__(self, x):
        return [self.func(xi) for xi in x]

myop = MyOp(lambda x: sqrt(x))

print myop.__at__(range(3))   # myop @ range(5)
print myop.__at__(range(3) * 2)  # myop @ (range(5) * 2)
print myop.__at__(range(3)) * 3  # myop @ range(5) * 3

[0.0, 1.0, 1.4142135623730951]
[0.0, 1.0, 1.4142135623730951, 0.0, 1.0, 1.4142135623730951]
[0.0, 1.0, 1.4142135623730951, 0.0, 1.0, 1.4142135623730951, 0.0, 1.0, 1.4142135623730951]




NumPy-Discussion mailing list