Home >  Term: bag
bag

An unordered collection of values that may have duplicates. Formal Definition: A bag has a single query function, numberIn(v, B), which tells how many copies of an element are in the bag, and two modifier functions, add(v, B) and remove(v, B). These may be defined with axiomatic semantics as follows.

  1. new() returns a bag
  2. numberIn(v, new()) = 0
  3. numberIn(v, add(v, B)) = 1 + numberIn(v, B)
  4. numberIn(v, add(u, B)) = numberIn(v, B) if v ≠ u
  5. remove(v, new()) = new()
  6. remove(v, add(v, B)) = B
  7. remove(v, add(u, B)) = add(u, remove(v, B)) if v ≠ u
where B is a bag and u and v are elements.

0 0

ผู้สร้าง

  • GeorgeV
  •  (Gold) 1123 points
  • 100% positive feedback
© 2024 CSOFT International, Ltd.