boofun.analysis.complexity
Complexity measures for Boolean functions.
This module implements various complexity measures including: - Decision tree depth (deterministic query complexity) - Decision tree size - Sensitivity and block sensitivity - Certificate complexity
These are fundamental measures in computational complexity theory as discussed in O’Donnell’s book and related literature.
Functions
Compute the average sensitivity of f. |
|
|
Compute the certificate complexity at input x. |
Compute the optimal deterministic decision tree depth for function f. |
|
|
Compute the optimal decision tree size for function f. |
|
Compute the maximum certificate complexity of f. |
|
Compute the maximum sensitivity of f. |
|
Compute the minimum sensitivity of f (over non-trivial inputs). |
|
Compute the sensitivity of f at input x. |
Classes
Compute and store various complexity measures for a Boolean function. |
- boofun.analysis.complexity.decision_tree_depth(f: BooleanFunction) int[source]
Compute the optimal deterministic decision tree depth for function f.
The decision tree depth D(f) is the minimum number of adaptive queries needed to compute f on any input in the worst case.
This uses dynamic programming over sub-cubes, computing the optimal depth for all partial assignments simultaneously.
- Parameters:
f – BooleanFunction to analyze
- Returns:
Optimal decision tree depth
Note
Time complexity: O(3^n) where n is the number of variables. Memory complexity: O(3^n)
Example
>>> majority = bf.BooleanFunctionBuiltins.majority(3) >>> decision_tree_depth(majority) 2 # Can determine majority with 2 queries
- boofun.analysis.complexity.decision_tree_size(f: BooleanFunction, minimize_depth_first: bool = False) Tuple[int, int][source]
Compute the optimal decision tree size for function f.
- Parameters:
f – BooleanFunction to analyze
minimize_depth_first – If True, minimize depth first, then size. If False, minimize size first, then depth.
- Returns:
Tuple of (size, depth) where size is the number of leaves
Note
Size measures the total number of leaves in the decision tree, while depth measures the longest root-to-leaf path.
- boofun.analysis.complexity.sensitivity(f: BooleanFunction, x: int) int[source]
Compute the sensitivity of f at input x.
The sensitivity s(f, x) counts how many single-bit flips change the output.
- Parameters:
f – BooleanFunction to analyze
x – Input index (integer representation)
- Returns:
Number of sensitive coordinates at x
- boofun.analysis.complexity.max_sensitivity(f: BooleanFunction, value: int | None = None) int[source]
Compute the maximum sensitivity of f.
- Parameters:
f – BooleanFunction to analyze
value – If specified (0 or 1), only consider inputs where f(x) = value
- Returns:
Maximum sensitivity across all (relevant) inputs
- boofun.analysis.complexity.min_sensitivity(f: BooleanFunction, value: int | None = None) int[source]
Compute the minimum sensitivity of f (over non-trivial inputs).
- Parameters:
f – BooleanFunction to analyze
value – If specified (0 or 1), only consider inputs where f(x) = value
- Returns:
Minimum sensitivity across relevant inputs
- boofun.analysis.complexity.average_sensitivity(f: BooleanFunction) float[source]
Compute the average sensitivity of f.
The average sensitivity equals the total influence I(f) = sum_i Inf_i(f).
- Parameters:
f – BooleanFunction to analyze
- Returns:
Average sensitivity (total influence)
- boofun.analysis.complexity.certificate_complexity(f: BooleanFunction, x: int) Tuple[int, List[int]][source]
Compute the certificate complexity at input x.
A certificate for f at x is a minimal set of coordinates S such that fixing the coordinates in S to their values in x determines f.
- Parameters:
f – BooleanFunction to analyze
x – Input index
- Returns:
Tuple of (certificate_size, list_of_certificate_variables)
- class boofun.analysis.complexity.ComplexityProfile(f: BooleanFunction)[source]
Compute and store various complexity measures for a Boolean function.
This class provides a comprehensive analysis of function complexity, computing multiple measures and checking known relationships between them.
- __init__(f: BooleanFunction)[source]
Initialize and compute complexity profile.
- Parameters:
f – BooleanFunction to analyze