• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
      • Std/lists
      • Std/alists
      • Obags
        • Bagp
        • Bag
        • Tail
        • Head
        • Subbag
        • Intersect
        • Empty
        • Difference
        • Union
        • Insert
          • Bfix
          • Delete
          • Cardinality
          • Occs
          • In
        • Std/util
        • Std/strings
        • Std/io
        • Std/osets
        • 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
    • Obags

    Insert

    Add (an occurrence of) a value to an obag.

    Signature
    (insert x bag) → bag1
    Arguments
    bag — Guard (bagp bag).
    Returns
    bag1 — Type (bagp bag1).

    This is similar to set::insert on osets.

    Definitions and Theorems

    Function: insert

    (defun insert (x bag)
           (declare (xargs :guard (bagp bag)))
           (let ((__function__ 'insert))
                (declare (ignorable __function__))
                (cond ((empty bag) (list x))
                      ((equal x (head bag)) (cons x bag))
                      ((<< x (head bag)) (cons x bag))
                      (t (cons (head bag)
                               (insert x (tail bag)))))))

    Theorem: bagp-of-insert

    (defthm bagp-of-insert
            (b* ((bag1 (insert x bag))) (bagp bag1))
            :rule-classes :rewrite)