# [Gretl-devel] matrix transposition/multiplication operator precedence

Allin Cottrell cottrell at wfu.edu
Sat Jul 2 13:45:39 EDT 2016

```On Sat, 2 Jul 2016, Riccardo (Jack) Lucchetti wrote:

> On Sat, 2 Jul 2016, Sven Schreiber wrote:
>
>>> "Kind of". But couldn't this be interpreted as a case of simple
>>> left-to-right evaluation in the absence of another deciding criterion?
>>
>> Well, I admit that according to table 3.1 in the command reference the
>> unary transpose and the binary transpose-multiply have the same priority,
>> and so it would boil down to left-to-right.
>>
>> But I'm not sure that's right. Semantically it's clear that
>> transpose-multiply just exists to mimick mathematical handwriting (on the
>> blackboard or on paper). So wherever it's meaningful, "'" must be replaced
>> by "'*". And then in the expression "a'*b'" the right precedence kicks in.
>>
>> Or to put it differently: Nobody would ever write "(a'b)'" on the
>> blackboard as "a'b'", because I think it's a broad consensus that the two
>> expressions are different.
>
> I agree with Sven on this, but OTOH what people expect on the basis of their
> mathematical background counts up to a point. The important thing is to stick
> as closely as possible to the principle of least surprise, which is, in turn,
> dictated by what other matrix-oriented languages do: as far as I can tell,
> the expression
>
> a'b'
>
> * is equivalent to (a') * (b') in Ox, Gauss and Julia
> * is illegal in Octave (which doesn't have, I think, the binary ' operator)
>
> so we're the exception. So I guess it's just another case of choice between
> backward-compatibility and pragamtism.

I take the point here, but changing gretl's behavior in this regard
will not be trivial. Unary transpose is unique as an operator that
appears to the right of its operand, and we cannot in general tell
unary transpose from binary transpose-multiply without "look
behind", which we don't have in our parser at present.

I'll think about this some more, but I'm not going to attempt a
change before the forthcoming release.

Allin
```