fbool
A Rust library for analyzing Boolean functions, with a focus on entanglement, information-theoretic measures, and circuit complexity. Includes Python bindings and a command-line interface.
This library was developed to support research on entanglement measures for Boolean functions. If you use it in your work, please cite the associated paper (see Citation).
Overview
fbool provides data structures and algorithms for:
- Representing Boolean functions compactly (truth-table encoding)
- Computing entanglement and min-max entanglement via bipartitions of variables
- Computing Shannon entropy of variable partitions
- Measuring influence, sensitivity, spectral properties (Walsh-Hadamard transform), and frontier structure
- Estimating certificate complexity
- Finding the minimum gate count for functions of up to 5 variables (via an integrated C++ optimizer)
The workspace also ships a Python package (fbool) built with PyO3 and maturin, and a CLI tool (fbool-cli).
Repository Structure
fbool/ # Core Rust library
fbool-cli/ # Command-line interface
fbool-py/ # Python bindings (PyO3 + maturin)
clique_solver/ # CLIQUE-problem solver used internally
optimal5/ # Rust wrapper around Adam P. Goucher's optimal5 C++ engine (minimal-gate optimizer)
Theoretical Background
Boolean Functions
A Boolean function f : {0,1}^n -> {0,1} is represented as a truth table: a vector of 2^n Boolean values indexed by the binary encoding of each input.
Entanglement
Given a bipartition (A, B) of the n input variables, the information I(S) of a set S counts the number of distinct sub-functions obtained by fixing all variables outside S. The two entanglement measures defined in this work are:
Entanglement(f) = min_{A,B} [ I(A) + I(B) ]
MinMax-Entanglement(f) = min_{A,B} max( I(A), I(B) )
Both minimize over all non-trivial bipartitions of {0, ..., n-1}.
Entropy
For a bipartition (A, B), the entropy is computed as the sum of the Shannon entropies of the empirical distributions induced by each partition. The minimum over all bipartitions gives the entropy measure of the function.
Rust Usage
Add fbool to your Cargo.toml:
[]
= { = "https://github.com/edugzlez/fbool" }
Basic Example
use FValue;
use ;
Available Boolean Functions
FValue provides constructors for many classical families:
| Constructor | Description |
|---|---|
FValue::majority(n) |
Majority function |
FValue::parity(n) |
Parity (XOR) function |
FValue::primality(n) |
Primality test |
FValue::zero_search(n) |
Zero-search function |
FValue::sum(n) |
Arithmetic sum |
FValue::product(n) |
Arithmetic product |
FValue::gcd(n) |
GCD function |
FValue::clique(n) |
Clique decision function |
Metrics
| Trait | Methods |
|---|---|
Entanglement |
entanglement(), entanglement_sets(), minmax_entanglement(), minmax_entanglement_sets() |
Entropy |
entropy(), entropy_sets() |
Sensitivity |
sensitivity() |
Influence |
influence() |
CertificateComplexity |
certificate_complexity() |
Frontier |
frontier_graph() |
WithMinimalGates |
minimal_gates() (5-variable functions only) |
Python Usage
Installation
Build and install locally with maturin:
Or with uv:
Example
# Construct a Boolean function (primality on 4 variables)
=
# Entanglement
# All bipartitions
# Entropy
# Truth table as NumPy array
=
FBool API
| Method | Description |
|---|---|
FBool(repr) |
Construct from a truth-table list |
FBool.from_number(n, num_vars) |
Construct from integer encoding |
FBool.majority(n) |
Majority function |
FBool.parity(n) |
Parity function |
FBool.primality(n) |
Primality function |
f.entanglement() |
Minimum entanglement value |
f.entanglement_sets() |
All bipartition entanglement values |
f.minmax_entanglement() |
Minimum max-entanglement value |
f.entropy() |
Minimum entropy value |
f.entropy_sets() |
All bipartition entropy values |
f.sensitivity() |
Sensitivity measure |
f.truth_table() |
Truth table as numpy.ndarray |
f.save(path) / FBool.load(path) |
Binary serialization |
CLI Usage
Build and run:
Examples
# Entanglement of the majority function with 4 variables
# All bipartitions, sorted by entanglement value
# Entropy
# Per-variable information
# Serialize a function to binary
Building
Requirements: Rust 1.70+, a C++ compiler (for optimal5), Python 3.11+ (for Python bindings).
# Build the full workspace
# Run all tests
# Run lints
License
This project is licensed under the MIT License. See LICENSE for details.
Citation
If you use this software in academic work, please cite:
The associated paper citation will be added upon publication.
Authors
- Eduardo González-Vaquero — edugzlez
- Ricardo Maurizio Paul
Acknowledgements
The optimal5 crate is a Rust wrapper around the optimal5 C++ engine by Adam P. Goucher, used under the MIT License. The original engine computes the minimum number of logic gates required to implement any Boolean function of up to 5 variables using a precomputed exhaustive lookup table.