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