I am confused by the operator shown for multiset includes because if talking about calculating if A:multiset includes B:multiset using Counters as multisets, you need to write A >= B.
The documentation seems to do B is included in A if B <= A which may well be correct but it has the order of the two names flipped, and there might be confusion because in flipping what is currently written, one might be tempted to use A > B instead of A >= B
The examples show:
c add d
c subtract d
c intersect d
c union d
c equal d
d included in c. # Wrong way round?
My tests
from collections import Counter
from itertools import product
# For testing
ab = [({'x':x, 'y': y, 'z': z}, {'x':x1, 'y': y1, 'z': z1})
for x, y, z, x1, y1, z1 in product([0, 1, 2, 3], repeat=6)]
#%%
"""
## Inclusion
A includes B
This is the same as Counter(A) >= Counter(B)
"""
def includes(A, B):
return (set(A.keys()).issuperset(set(B.keys()))
and all(A[b_key] >= b_val for b_key, b_val in B.items()))
for A, B in ab:
assert (c:=(Counter(A)) >= Counter(B)) == (i:=includes(A, B)), f"{A,B, c, i = }"
\oh! I just re-read the docs as well as Wikipedia and i am confused by thoughts of X Y mapping naturally to adds, subtracts, intersects, unions(?), equals, includes.
Includes seems more part of the progression than a substitution of “included by”
It seems the word stem include has a different meaning when followed with “by” compared to the others?
If I understand your confusion correctly, it’s because “is included” is the passive form of “includes”, so it reverses the roles of the subject and the complement. So “A includes B” is the same as “B is included in A”. This way, A is “bigger” than B, so the notation B <= A is correct.