Skip to main content
Z3 4.17.0 introduced a new FiniteSets theory solver for reasoning about finite sets. This theory provides operations for creating, manipulating, and querying finite sets over any base sort.
The FiniteSets theory was added in Z3 version 4.17.0. Support for set.range and set.map is partial. Support for set.size exists but without optimization.

Overview

The FiniteSets theory provides:
  • Set construction: Empty sets, singletons, ranges
  • Set operations: Union, intersection, difference
  • Predicates: Membership, subset
  • Functions: Size, map, filter
  • Base sorts: Sets over any sort (integers, booleans, custom datatypes, etc.)

Basic Set Operations

Creating Sets

Set Operations

Set Cardinality

Membership and Subset Constraints

Membership Constraints

Subset Relationships

Advanced Operations

Set Mapping

Apply a function to all elements of a set:
Support for set.map is currently partial in Z3 4.17.0. Some complex mapping operations may not be fully supported.

Set Filtering

Filter elements based on a predicate:

Integer Ranges

Support for set.range is partial in the current implementation. Basic range operations work, but complex range constraints may have limitations.

Sets Over Different Sorts

Boolean Sets

Sets of Bit-Vectors

Sets of Custom Datatypes

Practical Examples

Sudoku Constraints

Set Partitioning Problem

C API Reference

The C API for finite sets (defined in api_finite_set.cpp):

Key Functions

Current Limitations

As noted in the Z3 4.17.0 release notes:
  • set.range support is partial: Basic integer ranges work, but complex range operations may be limited
  • set.map support is partial: Simple mappings work, but complex transformations may not be fully supported
  • set.size lacks optimization: Cardinality constraints work but are not optimized. Performance may be slower for large sets or complex size constraints
For production use, test your specific use case and file GitHub issues for improvements.

See Also