# [Python-ideas] [Python-Dev] hello, new dict addition for new eve ?

Terry Reedy tjreedy at udel.edu
Fri Dec 30 21:29:01 CET 2011

```> On Fri, Dec 30, 2011 at 7:26 AM, julien tayon
> <julien at tayon.net
> <mailto:julien at tayon.net>> wrote:

>     I quite noticed people were
>     1) wanting to have a new dict for Xmas

Someone has proposed a modified version of the current dict type. The
questions are whether a) it will behave correctly in all situations; b)
give better overall performance; and c) be as easily maintainable.

>     2) strongly resenting dict addition.

This strikes me as a nonsensical statement. As noted below, we already
have a type of 'dict addition' -- and even 'dict subtraction'.
Counterfactual negative statements like this lead to the impression that
you are trolling, even if you do not intend to.

>     I propose the following code to validate my point of view regarding
>     the dictionnatry addition as a proof of concept :

This link any gives the tests, not the accu_dict itself. So there is no
way to know from the above exactly what you are proposing. From what
Guido wrote in his next response, I am guessing that it is something
like collections.Counter, which is an implementation of the multiset idea.

>>> c = Counter(a=3, b=1)
>>> d = Counter(a=1, b=2)
>>> c + d                       # add two counters together:  c[x] + d[x]
Counter({'a': 4, 'b': 3})

>>> c - d                       # subtract (keeping only positive counts)
Counter({'a': 2})

Tagging numbers by keys is a generalization of tagging them by position
(index).  So this is generalized vector arithmetic and that is what your
tests test.

------------------------
You have mixed up some of the terminology.

"""( a + b ) + c = a + ( b + c )"""

This is the associative law, not 'permutative'.

def test_permut_scal_mul(self):
""" ( an_int * other_scalar ) * a = an_int ( other_scalar * a )"""

Again, associativity (of scalar multiplication).
---

def test_other_mul_scal_commut(self):
""" ( an_int + other_scalar ) a = an_int * a + other_scalar * a """

This is a distributive law.

def test_scal_lin_combo(self):
""" an_int ( a + b) = an_int *a + an_int * b """

So is this.
---
def test_permutation(self):
"""a + b = b + a """

This is commutivity, which you had right earlier in the file:

def test_commutativity(self):
""" a + b = b + a """
---

def test_neutral(self):
""" a + neutral = a """

Not exactly incorrect, but this is a test of the additive identify,
which is usually called 'zero' rather than 'neutral'.

def test_neutral_mul_scal(self):
""" 1 * a = a """

while this tests the scalar multiplicative identify

--
Terry Jan Reedy

```