• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
      • Std/lists
      • Std/alists
      • Obags
      • Std/util
      • Std/strings
      • Std/osets
        • Omaps
        • All-by-membership
        • Defset
        • In
        • Primitives
        • Subset
        • Mergesort
        • Intersect
        • Union
        • Pick-a-point-subset-strategy
        • Delete
        • Double-containment
        • Difference
          • Cardinality
          • Set
          • Intersectp
        • Std/io
        • Std/basic
        • Std/system
        • Std/typed-lists
        • Std/bitsets
        • Std/testing
        • Std/typed-alists
        • Std/stobjs
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Std/osets

    Difference

    (difference x y) removes all members of Y from X.

    The logical definition is very simple, and the essential correctness property is given by difference-in.

    The execution uses a better, O(n) algorithm to remove the elements by exploiting the set order.

    Definitions and Theorems

    Function: difference

    (defun difference (x y)
      (declare (xargs :guard (and (setp x) (setp y))))
      (mbe :logic (cond ((emptyp x) (sfix x))
                        ((in (head x) y)
                         (difference (tail x) y))
                        (t (insert (head x)
                                   (difference (tail x) y))))
           :exec (fast-difference x y nil)))

    Theorem: difference-set

    (defthm difference-set
      (setp (difference x y)))

    Theorem: difference-sfix-x

    (defthm difference-sfix-x
      (equal (difference (sfix x) y)
             (difference x y)))

    Theorem: difference-sfix-y

    (defthm difference-sfix-y
      (equal (difference x (sfix y))
             (difference x y)))

    Theorem: difference-emptyp-x

    (defthm difference-emptyp-x
      (implies (emptyp x)
               (equal (difference x y) (sfix x))))

    Theorem: difference-emptyp-y

    (defthm difference-emptyp-y
      (implies (emptyp y)
               (equal (difference x y) (sfix x))))

    Theorem: difference-in

    (defthm difference-in
      (equal (in a (difference x y))
             (and (in a x) (not (in a y)))))

    Theorem: difference-subset-x

    (defthm difference-subset-x
      (subset (difference x y) x))

    Theorem: subset-difference

    (defthm subset-difference
      (equal (emptyp (difference x y))
             (subset x y)))

    Theorem: difference-insert-x

    (defthm difference-insert-x
      (equal (difference (insert a x) y)
             (if (in a y)
                 (difference x y)
               (insert a (difference x y)))))

    Theorem: difference-preserves-subset

    (defthm difference-preserves-subset
      (implies (subset x y)
               (subset (difference x z)
                       (difference y z))))