Intersection of all (the occurrences of) all the elements of two obags.
This is similar to set::intersect for osets.
Function:
(defun intersect (bag1 bag2) (declare (xargs :guard (and (bagp bag1) (bagp bag2)))) (let ((__function__ 'intersect)) (declare (ignorable __function__)) (cond ((emptyp bag1) nil) ((in (head bag1) bag2) (insert (head bag1) (intersect (tail bag1) bag2))) (t (intersect (tail bag1) bag2)))))
Theorem:
(defthm bagp-of-intersect (b* ((bag (intersect bag1 bag2))) (bagp bag)) :rule-classes :rewrite)