Sets are collections (1) without defined order and (2) not allowing duplication. Multisets, also called “bags” are collections without defined order but which permit duplication, i.e., more than one element. We define the function #(a B) to be the number of occurrences of the element a in the bag B. For example, #(1, [1 1 2 3 4 4 5]) is 2 and #(5, [1 1 2 3 4 4 5]) = 1. Bag union and intersection are defined in terms of #. bag-union: List × List -> List This function should take as arguments two lists representing bags and should return the list representing their bag-union. bag-intersection : List × List -> List This function should take as arguments two lists representing bags and should return the list representing their bag-intersection. Allowed functions. Your code must use only the following functions: 1. define, let 2. lambda 3. cons, car, cdr, list, list?, append, empty?, length, equal? 4. and, or, not 5. if, cond 6. +, -, /, * Racket code only please. Thank you!
Sets are collections (1) without defined order and (2) not allowing duplication. Multisets, also called “bags” are collections without defined order but which permit duplication, i.e., more than one element. We define the function #(a B) to be the number of occurrences of the element a in the bag B. For example, #(1, [1 1 2 3 4 4 5]) is 2 and #(5, [1 1 2 3 4 4 5]) = 1. Bag union and intersection are defined in terms of #.
bag-union: List × List -> List
This function should take as arguments two lists representing bags and should return the list representing their bag-union.
bag-intersection : List × List -> List
This function should take as arguments two lists representing bags and should return the list representing their bag-intersection.
Allowed functions. Your code must use only the following functions:
1. define, let
2. lambda
3. cons, car, cdr, list, list?, append, empty?, length, equal?
4. and, or, not
5. if, cond
6. +, -, /, *
Racket code only please. Thank you!
Step by step
Solved in 2 steps