• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
          • Implementation
          • Setp
          • Right
          • Left
          • Head
          • Double-containment
          • Subset
          • Intersect
          • Insert
          • In
          • Delete
          • Union
          • Diff
          • From-list
          • To-list
          • Set-equiv
          • Sfix
          • Pick-a-point
          • Cardinality
          • Set-induct
          • Set-bi-induct
          • Emptyp
        • Soft
        • C
        • Bv
        • Imp-language
        • Event-macros
        • Java
        • Bitcoin
        • Ethereum
        • Yul
        • Zcash
        • ACL2-programming-language
        • Prime-fields
        • Json
        • Syntheto
        • File-io-light
        • Cryptography
        • Number-theory
        • Lists-light
        • Axe
        • Builtins
        • Solidity
        • Helpers
        • Htclient
        • Typed-lists-light
        • Arithmetic-light
      • X86isa
      • Axe
      • Execloader
    • Math
    • Testing-utilities
  • Kestrel-books

Set

A tree-based implementation of finite sets.

This implementation of finite sets offers practically logarithmic worst-case performance for the core set operations (in, insert, delete) while also insisting on a canonical internal structure which allows equal to represent true set equivalence.

Differences from ACL2::std/osets

This library closely follows ACL2::std/osets. The first major difference, from an external user-perspective, is performance. Below are the practical worst-case complexities of core operations:

  • setp — O(n^2) (Note: the current implementation is inefficient. This should eventually be O(n) once we introduce a more efficient binary search tree property check via an mbe.)
  • in — O(\log(n))
  • insert — O(\log(n))
  • delete — O(\log(n))
  • union — O(n\log(m/n))
  • intersect — O(n\log(m/n))
  • diff — O(n\log(m/n))

The other major difference is in how one iterates over or traverses a set. In ACL2::std/osets, set::head provides the minimal element of a nonempty set, and tail provides the rest. For treesets, head provides the hash-maximal element of a nonempty set. Instead of tail, we have left and right, providing two disjoint subsets with all elements less than and all elements greater than the head, respectively.

In practice, the set::head/head values are typically considered arbitrary elements of the set (and this perspective is encouraged). So the only meaningful difference is the tree-traversal with left and right in contrast to the flat list traversal of tail. Alternatively, one may use to-list to get a flat list to iterate over more easily.

Subtopics

Implementation
Implementation details of sets.
Setp
Recognizer for sets.
Right
Get the "right" subset of the nonempty set.
Left
Get the "left" subset of the nonempty set.
Head
Get an element of the nonempty set.
Double-containment
Prove set equalities via subset antisymmetry.
Subset
Check if one set is a subset of the other.
Intersect
An n-ary set intersection.
Insert
Add a value (or multiples values) to the set.
In
Determine if a value is a member of the set.
Delete
Remove a value from the set.
Union
An n-ary set union.
Diff
Set difference.
From-list
Create a set from a list of values.
To-list
Create a list of values from a set.
Set-equiv
Equivalence up to sfix.
Sfix
Fixer for sets.
Pick-a-point
Pick-a-point automation for subset.
Cardinality
The number of elements in a set.
Set-induct
Induct over the structure of a set.
Set-bi-induct
Induct over the structure of two sets simultaneously.
Emptyp
Check if a set is empty.