Chapter 3. B
bag Very loosely, a "set" that permits duplicates; more precisely, a collection of objects, called elements, in which the same element can appear any number of times. An example is the collection (y,y,x,z,y,z), which can equivalently be written as (x,y,y,y,z,z), since bags, like sets, have no ordering to their elements. The number of times a given element appears in a given bag is the multiplicity (of that element with respect to that bag).
The set theory operations of inclusion, union, intersection, difference, and product (but not complement) can all be generalized to apply to bags. First, inclusion: Let b1 and b2 be bags, and let element x appear exactly n1 times in b1 and exactly n2 times in b2 (n1 0, n2 0). Then bag b1 includes ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access