Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If a+b != b+a that breaks the commutativity property of addition.


Yes, but I still want this for combining dictionaries. Python already violates this property, I don't find it confusing.

    Python 3.7.2 (default, Dec 30 2018, 08:55:50) 
    [Clang 10.0.0 (clang-1000.11.45.5)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 'foo' + 'bar' == 'bar' + 'foo'
    False
    >>> ['foo'] + ['bar'] == ['bar'] + ['foo']
    False


"a"+"b" != "b"+"a" already.


That property is not universal, and it is currently being defined for Python dictionaries. You can't break a property that isn't defined yet. ;-)


Is this what changed in 3.5?


Commutatitivity does not need to always hold. Multiplication is not commutative on matrices, but we still use it often and write it as a product nonetheless


In mathematics, the ‘multiplication’ operation is not assumed to be commutative, whereas the ‘addition’ operator is used specifically to indicate commutativity. So, for example, using the plus sign for string concatenation goes against this tradition.


Python actually supports a special operator @ for non-commutative matrix products.


To be fair, IEEE fp addition is noncommutative in corner cases.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: