new python syntax: concatenation of functions

Steve dippyd at yahoo.com.au
Fri Mar 12 00:08:06 EST 2004


Gonçalo Rodrigues wrote:

>>>because neither in mathematics people agree on the order:
>>>a°b(x) == a(b(x)) or
>>>a°b(x) == b(a(x)) ?
>>
>>Is this a joke or what?
>>
>>In mathematics people DO agree on the order:
>>
>>if a:B->A and b:X->B, then a°b:X->A and
>>(a°b)(x)=a(b(x))
> 
> No they DON'T. Both notations are used. The notation (using
> concatenation instead of circle to denote composition)
> 
> ba: x -> a(b(x)) 
> 
> is called diagrammatic order, and to be totally consistent we should
> really write
> 
> x -> (x b) a
> 
> and is more often used in Category Theory (and close relatives like
> Homological Algebra, etc. ) where you deal more with commutative
> diagrams and the like and functions being applied to arguments appear
> only very rarely.

Composition of cummutative diagrams is hardly likely to 
be confused with compositions of functions, so I don't 
think this argument is relevent.

It has been my experience that no matter how well-known 
a notation is, there is some field of mathematics that 
will either use the same notation for something 
different, or use completely different notation for the 
same task.

No doubt that there is some obscure field somewhere 
where the expression "1 + 1 = 2" means something other 
than the obvious :-)

Even so, in "ordinary" mathematics, composition a°b(x) 
generally means a(b(x)). Even if it didn't, we are free 
  to pick whatever notation we want, just as we did 
when we choose to use "+" as an infix operator rather 
than either prefix "+ a b" or postfix "a b +".

Needless to say, all three notations are in use, but 
Python only recognises one. This is not a problem.

While a composition operator would be cute, I don't 
think it would be useful enough to justify using a 
non-ASCII operator. Other than saving one character per 
  pair of functions, what else is it good for?


-- 
Steven D'Aprano




More information about the Python-list mailing list