Skip to main content

A Python library for Boolean function analysis and spectral methods

Project description

BooFun Logo

Boolean Function Analysis in Python

PyPI version PyPI Downloads Python 3.8+ MIT License Documentation codecov Typed OpenSSF Scorecard

What This Is

A toolkit for Boolean function analysis: Fourier analysis, property testing, query complexity, and more. Built while studying O'Donnell's Analysis of Boolean Functions.

Full Documentation · Quick Start

Installation

pip install boofun

Quick Start

import boofun as bf

# Create functions
maj = bf.majority(5)
xor = bf.create([0, 1, 1, 0])

# Evaluate
maj.evaluate([1, 1, 0, 0, 1])  # → 1

# Fourier analysis
maj.fourier()           # Fourier coefficients
maj.influences()        # Per-variable influences
maj.total_influence()   # I[f]
maj.noise_stability(0.9)

# Properties and complexity
maj.is_monotone()
maj.is_balanced()

from boofun.analysis import complexity
complexity.decision_tree_depth(maj)  # D(f)
complexity.max_sensitivity(maj)      # s(f)

# Full analysis
maj.analyze()  # dict with all metrics

Features

Category What's Included
Built-in Functions Majority, Parity, AND, OR, Tribes, Threshold, Dictator, weighted LTF, random
Representations Truth tables (dense/sparse/packed), Fourier, ANF, DNF/CNF, BDD, circuits, LTF
Fourier Analysis WHT, influences, noise stability, spectral concentration, p-biased analysis
Query Complexity D(f), R(f), Q(f), sensitivity, block sensitivity, certificates, Ambainis bound
Property Testing BLR linearity, junta, monotonicity, symmetry, balance
Hypercontractivity Noise operator, Bonami's Lemma, KKL theorem, Friedgut's junta theorem
Learning Theory Goldreich-Levin, PAC learning, junta learning, LMN algorithm
Cryptographic Nonlinearity, bent functions, Walsh spectrum, LAT/DDT, S-box analysis
Advanced Gaussian analysis, invariance principle, communication complexity, LTF analysis
Visualization Influence plots, Fourier spectrum, truth table heatmaps, decision trees

Guides

Detailed documentation for each topic:

Flexible Input

bf.create([0, 1, 1, 0])              # List → truth table
bf.create(lambda x: x[0] ^ x[1], n=2) # Callable
bf.create("x0 and not x1", n=2)      # String → symbolic
bf.load("function.cnf")              # DIMACS CNF

Built-in Functions

majority(n), parity(n), tribes(k, n), threshold(n, k), AND(n), OR(n), dictator(n, i), weighted_majority(weights), random(n)

Examples

File Topic
01_getting_started.py Basics
02_fourier_basics.py WHT, Parseval
03_common_families.py Majority, Parity, Tribes
04_property_testing.py BLR, junta tests
05_query_complexity.py Sensitivity, certificates

Course Notebooks

Interactive notebooks following CS294-92 (Analysis of Boolean Functions). Click Topic to view or Play to run in Colab.

Lecture Notebooks (11)
Lecture Topic Play
1 Fourier Expansion Open In Colab
2 Linearity Testing Open In Colab
3 Social Choice & Influences Open In Colab
4 Influences & Effects Open In Colab
5 Noise Stability Open In Colab
6 Spectral Concentration Open In Colab
7 Goldreich-Levin Open In Colab
8 Learning Juntas Open In Colab
9 DNFs & Restrictions Open In Colab
10 Fourier Concentration Open In Colab
11 Invariance Principle Open In Colab
Homework Notebooks (4)
HW Topic Play
1 Fourier Expansion Open In Colab
2 LTFs & Decision Trees Open In Colab
3 DNFs & Restrictions Open In Colab
4 Hypercontractivity Open In Colab

Performance

  • NumPy vectorization throughout
  • Optional Numba JIT, CuPy GPU acceleration
  • Sparse/packed representations for large n
  • Most operations complete in milliseconds for n ≤ 14

Testing

pytest tests/
pytest --cov=boofun tests/

3000+ tests with 72% coverage. Cross-validation against known results in tests/test_cross_validation.py.

Convention

O'Donnell standard: Boolean 0 → +1, Boolean 1 → −1. This ensures f̂(∅) = E[f].

Contributing

See CONTRIBUTING.md. Bug reports and test cases are especially valuable.

Acknowledgments

  • Avishay Tal: Course instructor, sensitivity analysis, p-biased measures, decision tree algorithms
  • Patrick Bales: Course materials and notebook review
  • O'Donnell's Analysis of Boolean Functions (Cambridge, 2014): Theoretical foundation
  • Scott Aaronson's Boolean Function Wizard (2000): Query complexity foundations

License

MIT. See LICENSE.

Citation

@software{boofun2026,
  title={BooFun: A Python Library for Boolean Function Analysis},
  author={Gabriel Taboada},
  year={2026},
  url={https://github.com/GabbyTab/boofun}
}

BooFun Logo

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

boofun-1.1.1.tar.gz (918.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

boofun-1.1.1-py3-none-any.whl (336.5 kB view details)

Uploaded Python 3

File details

Details for the file boofun-1.1.1.tar.gz.

File metadata

  • Download URL: boofun-1.1.1.tar.gz
  • Upload date:
  • Size: 918.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for boofun-1.1.1.tar.gz
Algorithm Hash digest
SHA256 cd6df5c5aa5ea3d15b32ef5544c8151da25c864ef7782a9a4c314ab094e377b7
MD5 0b7b0f2d3dff2cecc34726a5265edaf3
BLAKE2b-256 70c15372b60065c8ce3826eb5518340296a96a8a187033bcca43af20a806c4da

See more details on using hashes here.

File details

Details for the file boofun-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: boofun-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 336.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for boofun-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d656e2f38b380ef684dca6e9678413ed6cef110c8190c7d8e546f1387e14a662
MD5 868fcd0bdcdc21cf55bb82f59023b154
BLAKE2b-256 641e0ecdf122f1aa0a4eb5227dab5b4e96c7d57f11bb7bc7efab6cb9baac19d0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page