boofun.analysis
Boolean function analysis module providing spectral analysis tools.
This module implements fundamental algorithms for analyzing Boolean functions including Fourier analysis, influence computation, and noise stability.
Classes
|
Property testing algorithms for Boolean functions. |
|
Spectral analysis tools for Boolean functions. |
- class boofun.analysis.SpectralAnalyzer(function: BooleanFunction)[source]
Spectral analysis tools for Boolean functions.
Provides methods for computing Fourier coefficients, variable influences, total influence, noise stability, and other spectral properties.
- __init__(function: BooleanFunction)[source]
Initialize analyzer with a Boolean function.
- Parameters:
function – BooleanFunction instance to analyze
- fourier_expansion(force_recompute: bool = False) ndarray[source]
Compute Fourier expansion coefficients.
The Fourier expansion represents f: {0,1}^n → {0,1} as: f(x) = Σ_S f̂(S) * χ_S(x) where χ_S(x) = (-1)^(Σ_{i∈S} x_i) are the Walsh functions.
- Parameters:
force_recompute – If True, recompute even if cached
- Returns:
Array of Fourier coefficients indexed by subsets
- influences(force_recompute: bool = False) ndarray[source]
Compute variable influences (also called sensitivities).
The influence of variable i is: Inf_i(f) = Pr[f(x) ≠ f(x ⊕ e_i)] where e_i is the i-th unit vector.
- Parameters:
force_recompute – If True, recompute even if cached
- Returns:
Array of influences for each variable
- total_influence() float[source]
Compute total influence (sum of all variable influences).
- Returns:
Total influence = Σ_i Inf_i(f)
- noise_stability(rho: float) float[source]
Compute noise stability at correlation ρ.
Noise stability is the probability that f(x) = f(y) where y is obtained from x by flipping each bit independently with probability (1-ρ)/2.
- Parameters:
rho – Correlation parameter in [-1, 1]
- Returns:
Noise stability value
- spectral_concentration(degree: int) float[source]
Compute spectral concentration at given degree.
This is the fraction of Fourier weight on coefficients corresponding to sets of size at most ‘degree’.
- Parameters:
degree – Maximum subset size to include
- Returns:
Fraction of spectral weight on low-degree coefficients
- class boofun.analysis.PropertyTester(function: BooleanFunction, random_seed: int | None = None)[source]
Property testing algorithms for Boolean functions.
Implements various randomized and deterministic tests to check if Boolean functions satisfy specific properties.
- __init__(function: BooleanFunction, random_seed: int | None = None)[source]
- constant_test() bool[source]
Test if function is constant.
Deterministic test that checks if all outputs are identical. Time complexity: O(2^n) for exhaustive check.
- Returns:
True if function is constant, False otherwise
- blr_linearity_test(num_queries: int = 100, epsilon: float = 0.1) bool[source]
BLR (Blum-Luby-Rubinfeld) linearity test.
Tests if a function f: {0,1}^n → {0,1} is linear (i.e., f(x ⊕ y) = f(x) ⊕ f(y)). Uses randomized queries to test the linearity property.
QUERY COMPLEXITY: O(3 * num_queries) - safe for arbitrarily large n.
- Parameters:
num_queries – Number of random queries to perform
epsilon – Error tolerance (function passes if error rate < epsilon)
- Returns:
True if function appears linear, False otherwise
- junta_test(k: int, num_queries: int = 1000, confidence: float = 0.9) bool[source]
Test if function is a k-junta (depends on at most k variables).
A function is a k-junta if there exists a set S ⊆ [n] with |S| ≤ k such that f(x) depends only on coordinates in S.
- Parameters:
k – Maximum number of relevant variables
num_queries – Number of random queries
confidence – Confidence level for the test
- Returns:
True if function appears to be a k-junta, False otherwise
- monotonicity_test(num_queries: int = 1000) bool[source]
Test if function is monotone (f(x) ≤ f(y) whenever x ≤ y coordinate-wise).
QUERY COMPLEXITY: O(2 * num_queries) - safe for arbitrarily large n.
- Parameters:
num_queries – Number of random pairs to test
- Returns:
True if function appears monotone, False otherwise
- unateness_test(num_queries: int = 1000) bool[source]
Test if function is unate (monotone in each variable, possibly negated).
A function is unate if for each variable x_i, either: - f is monotone increasing in x_i, OR - f is monotone decreasing in x_i
Unate functions generalize monotone functions - they can be monotone in different “directions” for different variables.
QUERY COMPLEXITY: O(2 * num_queries) - safe for arbitrarily large n.
- Parameters:
num_queries – Number of random pairs to test per variable
- Returns:
True if function appears unate, False otherwise
- symmetry_test(num_queries: int = 1000) bool[source]
Test if function is symmetric (invariant under permutations of variables).
QUERY COMPLEXITY: O(2 * num_queries) - safe for arbitrarily large n.
- Parameters:
num_queries – Number of random permutations to test
- Returns:
True if function appears symmetric, False otherwise
- balanced_test() bool[source]
Test if function is balanced (outputs 0 and 1 equally often).
- Returns:
True if function is balanced, False otherwise
- dictator_test(num_queries: int = 1000, epsilon: float = 0.1) Tuple[bool, int | None][source]
Test if function is a dictator or anti-dictator.
A dictator function is f(x) = x_i for some i. An anti-dictator is f(x) = ¬x_i = 1 - x_i.
From O’Donnell Chapter 7: The FKN theorem states that if f is Boolean and has small total influence, it’s close to a dictator.
- Parameters:
num_queries – Number of random queries
epsilon – Distance threshold
- Returns:
is_dictator_like: True if f is close to a dictator/anti-dictator
dictator_index: The index of the dictator variable (or None)
- Return type:
Tuple of (is_dictator_like, dictator_index) where
- affine_test(num_queries: int = 1000, epsilon: float = 0.1) bool[source]
4-query test for affine functions over GF(2).
From HW1 Problem 4: A function f: F_2^n → F_2 is affine iff f(x) + f(y) + f(z) = f(x + y + z) for all x, y, z.
This is a generalization of the BLR linearity test.
- Parameters:
num_queries – Number of random queries
epsilon – Error tolerance
- Returns:
True if function appears to be affine
Modules
Arrow's Impossibility Theorem and Social Choice Theory. |
|
Basic properties of Boolean functions. |
|
Block sensitivity analysis for Boolean functions. |
|
Canalization Analysis for Boolean Functions. |
|
Certificate utilities (exact search for modest |
|
Communication Complexity Analysis. |
|
Complexity measures for Boolean functions. |
|
Equivalence testing and canonical forms for Boolean functions. |
|
FKN Theorem and related results about functions close to dictators. |
|
Fourier analysis utilities for Boolean functions. |
|
Gaussian analysis of Boolean functions (O'Donnell Chapter 10). |
|
GF(2) analysis for Boolean functions (XOR/Algebraic Normal Form). |
|
Global Hypercontractivity Module |
|
Huang's Sensitivity Theorem and related results. |
|
Hypercontractivity tools for Boolean function analysis. |
|
Invariance principles for Boolean functions (O'Donnell Chapter 11). |
|
Learning algorithms for Boolean functions. |
|
Linear Threshold Function (LTF) Analysis Module. |
|
P-biased Fourier analysis for Boolean functions. |
|
PAC (Probably Approximately Correct) Learning for Boolean functions. |
|
Query complexity measures for Boolean functions. |
|
Random restrictions for Boolean function analysis. |
|
Sensitivity-related helpers ported from legacy routines. |
|
Symmetry helpers informed by Krawchouk polynomials. |