Message228441
On Sat, Oct 04, 2014 at 07:57:16AM +0000, Serhiy Storchaka wrote:
> There are some properties of set comparison:
>
> (a < b) == (a <= b and a != b)
> (a <= b) == (a < b or a == b)
> (a <= b and b <= a) == (a == b)
> (a < b and b < a) == False
> (a <= b) == (a - b == set())
> if (a <= b and b <= c) then (a <= c)
> (a <= b and a <= c) == (a <= (b & c))
> (a <= c and b <= c) == ((a | b) <= c)
>
> Is this true for Counter?
I believe these are all true for multisets.
But Counter is not *just* a multiset (a.k.a. bag) since the "counts" are
not limited to non-negative integers (the natural numbers).
py> C = Counter()
py> C['a'] = -3
py> C['b'] = 'spam'
py> C['c'] = 0.5
py> C
Counter({'c': 0.5, 'b': 'spam', 'a': -3})
I don't know of any standard definition for subset and superset for
multisets like C above. I think that we should raise an exception in
cases like that: TypeError for cases where any "count" is non-numeric,
and ValueError for cases where any count is not a non-negative integer.
(Later, if somebody comes up with a sensible meaning for sub/superset of
such a Counter, we can relax that restriction.)
Another issue: are missing elements treated as if they have count 0?
E.g. what are these?
Counter({'a': 0, 'b': 1}) <= Counter({'a': 1, 'b': 1})
Counter({'a': 0, 'b': 1}) <= Counter({'b': 1})
According to these pages:
http://singularcontiguity.wordpress.com/2008/05/07/multiset-equality-and-submultisets/
http://singularcontiguity.wordpress.com/2008/04/28/multiset-membership/
I would argue that they should both return True (based on the idea that
the "support" of a multiset is the set of those elements with non-zero
count). But I don't know how authoritative that blog is. (The author
even mentions that he only has a passing familiarity with some aspects
of multisets.)
Anyone familiar with Haskell? What does this bag class do?
http://hackage.haskell.org/package/uulib-0.9.8/docs/UU-DData-IntBag.html
This may also be helpful. Sets and bags in Z language:
http://www.cs.ox.ac.uk/people/michael.wooldridge/teaching/soft-eng/lect08.pdf
http://www.cs.ox.ac.uk/people/michael.wooldridge/teaching/soft-eng/lect14.pdf |
|
Date |
User |
Action |
Args |
2014-10-04 09:58:52 | steven.daprano | set | recipients:
+ steven.daprano, rhettinger, mark.dickinson, pitrou, scoder, eric.smith, r.david.murray, cool-RR, ethan.furman, serhiy.storchaka, Saimadhav.Heblikar, josh.r |
2014-10-04 09:58:52 | steven.daprano | link | issue22515 messages |
2014-10-04 09:58:51 | steven.daprano | create | |
|