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

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

    Theorem: difference-empty-y

    (defthm difference-empty-y
            (implies (empty 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 (empty (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))))