Remove from the first obag all (the occurrences of) the elements of the second obag.
Function:
(defun difference (bag1 bag2) (declare (xargs :guard (and (bagp bag1) (bagp bag2)))) (let ((__function__ 'difference)) (declare (ignorable __function__)) (cond ((emptyp bag1) nil) ((in (head bag1) bag2) (difference (tail bag1) bag2)) (t (insert (head bag1) (difference (tail bag1) bag2))))))
Theorem:
(defthm bagp-of-difference (b* ((bag (difference bag1 bag2))) (bagp bag)) :rule-classes :rewrite)