fbool
fbool is a Rust workspace for analysing Boolean functions, with support for
entanglement-style measures, information-theoretic metrics, spectral and
structural properties, certificate complexity, frontier graphs, and exact
minimal-gate data for functions of up to 5 variables.
The workspace contains the publishable Rust library crate, a CLI, Python bindings built with PyO3/maturin, and experiment binaries used by the research workflow.
Workspace
fbool/ # Publishable Rust library crate
fbool/src/metrics/ # Entanglement, entropy, fragmentation, frontier, spectral, sensitivity, influence
fbool/src/optimal5.rs # Default Rust API for the integrated optimal5 engine
fbool/cpp/ # C++ sources from Adam P. Goucher's optimal5 engine
fbool/knuthies.dat # Lookup data used by the optimal5 feature
fbool-cli/ # Command-line interface
fbool-py/ # Python extension module named fbool
fbool-experiments/ # Research/analysis binaries
experiments/ # Experiment assets and scripts
clique_solver/ # Standalone clique-solver code retained in the repository
The old standalone optimal5 crate has been folded into fbool as the default
optimal5 feature. There is no separate workspace member for it anymore.
Rust Crate
Add the library from crates.io once published:
[]
= "0.2"
The minimal-gate API backed by the integrated C++ engine is enabled by default.
If you want a pure-Rust build without optimal5, disable default
features and opt back into the Rust-only metric families you need:
[]
= { = "0.2", = false, = ["entanglement", "frontier"] }
For local development inside this repository:
[]
= { = "../fbool" }
Features
| Feature | Enabled by default | Description |
|---|---|---|
entanglement |
yes | Entanglement, entropy, sub-information, equanimity importance, fragmentation |
frontier |
yes | Frontier graph metrics via petgraph |
optimal5 |
yes | C++ optimal5 engine for exact minimal gates up to 5 variables |
fmatrix |
no | Experimental multi-output function helpers |
clique |
no | Clique-based Boolean function constructor |
Basic Example
use ;
use FValue;
With the default optimal5 feature:
use FValue;
use WithMinimalGates;
Function Constructors
FValue<bool> includes:
| Constructor | Description |
|---|---|
majority(n) |
Majority function |
parity(n) |
Parity function |
primality(n) |
Primality predicate over the truth-table index |
equality(n) |
Equality of two n-bit inputs |
ordered(n) |
Ordered comparison of two n-bit inputs |
coprimes(n) |
Coprimality of two n-bit inputs |
sum_is_prime(n) |
Primality of the sum of two n-bit inputs |
product_is_multiple_of(n, multiple) |
Divisibility predicate |
find_zero(vector_size, element_size) |
Search for a zero element in an encoded vector |
constant(n, value) |
Constant Boolean function |
random(n) |
Random Boolean function |
from_usize(fun, n) |
Decode a Boolean truth table from an integer |
clique(n) |
Clique predicate, behind the clique feature |
FValue<usize> includes arithmetic-valued constructors such as sum, product,
max, gcd, multiply, sum_some, and constant.
Metrics
The public API exposes metrics through modules under fbool::metrics and
through top-level compatibility re-exports:
| Area | Examples |
|---|---|
| Entanglement and entropy | entanglement(), minmax_entanglement(), entropy(), entanglement_sets(), entropy_sets() |
| Information | information(vars), sub_infos() |
| Fragmentation | fragmentation_coefficient(), fragmentation_spectrum(), fragmentation_profile(), fragmentation_peak() |
| Frontier | frontier_graph() |
| Sensitivity and influence | max_sensitivity(), mean_sensitivity(), influence(var), total_influence() |
| Spectral analysis | walsh_coeficients(), fourier_coeficients(), degree(), spectral_entropy(), no_linearity() |
| Certificate complexity | certificate_complexity() |
| Optimal 5-variable circuits | minimal_gates() and npn_representant() with the optimal5 feature |
Python Package
The Python package is published on PyPI as fbool and exports a module named
fbool. It requires Python 3.11 or newer.
Install it with uv:
Or with pip:
For local development inside this repository, build the extension from
fbool-py with maturin.
Python Example
=
Python API Highlights
FBool supports construction from a truth table or integer encoding:
| Method | Description |
|---|---|
FBool(repr) |
Construct from a Boolean truth-table list |
FBool.from_number(number, num_vars) |
Construct from integer truth-table encoding |
FBool.majority(n), FBool.parity(n), FBool.primality(n) |
Standard Boolean families |
FBool.coprimes(n), FBool.sum_is_prime(n), FBool.clique(n) |
Additional constructors |
f.repr(), f.eval(i), f.size(), f.n_vars() |
Basic inspection |
f.encode(), FBool.decode(raw) |
Binary serialization |
f.table(vars) |
NumPy table induced by fixing variables |
f.npn_representant() |
NPN representative for 5-variable functions when available |
The Python bindings also expose entanglement, entropy, fragmentation, frontier, sensitivity, spectral, influence, certificate, and optimal5 metrics.
CLI
Build the CLI:
Run help:
On Windows, the binary is target\release\fbool-cli.exe.
CLI Examples
# Entanglement of majority on 4 variables
# All bipartitions, sorted, keeping the first 10 rows
# Min-max entanglement
# Entropy sets
# Per-subset information
# Encode and load a function
Available function subcommands include majority, parity, eq, ordered,
multiply, sum, max, gcd, primality, sum-is-prime, coprimes,
constant, usize-constant, raw, bin, find-zero, and meta.
Experiments
The fbool-experiments crate contains research binaries:
These tools are part of the repository workflow, but the publishable Rust crate
is fbool.
Documentation
The MkDocs Material documentation lives in docs/ and is configured by
mkdocs.yml.
For CI-style validation:
Building And Testing
Requirements:
- Rust stable
- A C++ compiler for default
fboolbuilds, becauseoptimal5is enabled by default - Python 3.11+ for the Python package
uvis optional but recommended for Python development
Common commands:
Releases
Versioning is managed from the repository root with Commitizen via .cz.toml.
Publishing is driven by GitHub Actions on v* tags:
cargo publish -p fboolpublishes the Rust crate to crates.io.- maturin builds Python wheels for Linux, Windows, and macOS ARM.
- the Python wheels are published to PyPI as
fbool.
Citation
If you use this software in academic work, please cite:
The associated paper citation will be added upon publication.
License
This project is licensed under the MIT License. See LICENSE.
The integrated optimal5 C++ engine is derived from Adam P. Goucher's
optimal5, also used under the MIT
License.
Authors
- Eduardo Gonzalez-Vaquero (edugzlez)
- Ricardo Maurizio Paul