New submission from Paul <pyt...@paulkoppen.com>:

The collections docs state: "Several mathematical operations are provided for 
combining Counter objects to produce multisets (counters that have counts 
greater than zero)."

I am surprised at the clear level of decision into conflating counters with 
multisets. Why break all functionality for negative counts in favour of 
multisets? Why not create a Multiset object for multisets?

One example use of negative counts is in factorisation 
(https://bugs.python.org/msg368298 will be surprised counters don't count)
18   = 2**1 * 3**2  --> x18 = Counter({2: 1, 3: 2})
 4   = 2**2         --> x4 = Counter({2: 2})

To compute 18/4 in this representation (which I believe is exactly precisely a 
count), one would expect

18/4 = 2**-1 * 3**2 --> x4_5 = x18 - x4 = Counter({2: -1, 3: 2})

But instead,

x18 - x4 = Counter({3: 2}) = 9 ???

This is just an example. The use case for negative counts is plain and obvious. 
The question is: why does collections break counter behaviour in favour of 
conflation with multisets? Why not have two objects: Counter for counters and 
Multiset for multisets?

----------
components: Library (Lib)
messages: 369867
nosy: wpk-
priority: normal
severity: normal
status: open
title: Conflation of Counter with Multiset
type: behavior
versions: Python 3.10, Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 
3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40764>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to