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

What This Is

A toolkit for teaching, learning, and doing research in Boolean function analysis. Fourier analysis, property testing, query complexity, hypercontractivity, pseudorandomness, and more -- with 23 interactive notebooks aligned to O'Donnell's Analysis of Boolean Functions.

Built at UC Berkeley alongside Avishay Tal's CS 294-92. Cross-validated against SageMath, Tal's toolkit, and known closed-form results.

import boofun as bf

# Create functions, compute properties
maj = bf.majority(5)
maj.fourier()           # Fourier coefficients
maj.influences()        # Per-variable influences
maj.total_influence()   # I[f]
maj.noise_stability(0.9)

# Query complexity
from boofun.analysis import complexity
complexity.D(maj)       # Decision tree depth
complexity.s(maj)       # Max sensitivity

Try it in Colab | All 23 Notebooks | Full Docs

Installation

pip install boofun

Or run notebooks in Docker:

docker-compose up notebook  # localhost:8888, token: boofun

Quick Start

import boofun as bf

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

# Evaluate (callable syntax)
maj_5([1, 1, 0, 0, 1])  # → True (majority satisfied)
maj_5(7)                # → True (7 = 00111 in binary, 3 ones)

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

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

from boofun.analysis import complexity
complexity.D(maj_5)  # Decision tree depth D(f)
complexity.s(maj_5)  # Max sensitivity s(f)

# Full analysis
maj_5.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

Computational companion to O'Donnell's Analysis of Boolean Functions, following Avishay Tal's CS 294-92. Each notebook makes the theorems runnable so the focus stays on the math. Click Scribe for lecture notes, Topic to view the static notebook, or Play to run in Colab.

Lecture Notebooks (11)
Lecture Scribe Topic Play
1 Joyce Lu Fourier Expansion Open In Colab
2 Austin Pechan Linearity Testing Open In Colab
3 Vivien Goyal Social Choice & Influences Open In Colab
4 Patrick Bales Influences & Effects Open In Colab
5 Prastik Mohanraj Noise Stability Open In Colab
6 (upcoming) Spectral Concentration Open In Colab
7 Thomas Culhane Goldreich-Levin Open In Colab
8 Timothe Kasriel Learning Juntas Open In Colab
9 Qinggao Hong DNFs & Restrictions Open In Colab
10 Lucas Ericsson Fourier Concentration Open In Colab
11 Thapen 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
Supplementary Notebooks (8)
Topic Description Play
LTF Visualization 3D hyperplane geometry, influences Open In Colab
Global Hypercontractivity Keevash et al. threshold phenomena Open In Colab
Boolean Functions as Random Variables P-biased measures, threshold curves, Russo Open In Colab
Cryptographic Analysis Walsh spectrum, nonlinearity, SAC Open In Colab
Fractional PRGs Fourier tails, pseudorandomness (CHLT 2019) Open In Colab
Flexible Inputs & Oracles Input formats, lazy evaluation Open In Colab
Real World Applications Cryptography, ML, voting Open In Colab
Asymptotic Visualization Growth rates and scaling Open In Colab

Performance

  • NumPy vectorization throughout (always on)
  • Numba JIT for 2-10x speedups: pip install boofun[performance]
  • CuPy GPU acceleration for large n: pip install boofun[gpu]
  • Sparse/packed representations for memory efficiency
  • Most operations complete in milliseconds for n ≤ 14

Testing

pytest tests/
pytest --cov=boofun tests/

3200+ 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, Fourier analysis utilities. BooFun covers ~90% of Tal's BooleanFunc.py toolkit — see the migration guide for a complete mapping
  • 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.2.0.tar.gz (961.2 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.2.0-py3-none-any.whl (346.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for boofun-1.2.0.tar.gz
Algorithm Hash digest
SHA256 e35b2e8672a64de7ea95b5014f8625d4ff8c4d70b3ffb9bcd519ef96d0204af6
MD5 ed8fa76db8b6673c09d126a020e92911
BLAKE2b-256 6551cb58e6249d59c5e37db091043677beab460807ad7f2d03980e10bdcfa335

See more details on using hashes here.

File details

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

File metadata

  • Download URL: boofun-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 346.9 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fae40917fff6d1fc36d8bbc80303fd3369629c55cb4e7cb479ae6db45c1c65dc
MD5 79d6fd9a0178bede158fb06a69a1a9c9
BLAKE2b-256 f711d9b70d3a33adb7bc60290963ccc1c0c49987a212e6df4801e49a42b984b1

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