This paper describes a purely functional library for computing level-$p$-complexity of Boolean functions, and applies it to two-level iterated majority. Boolean functions are simply functions from $n$ bits to one bit, and they can describe digital circuits, voting systems, etc. An example of a Boolean function is majority, which returns the value that has majority among the $n$ input bits for odd $n$. The complexity of a Boolean function $f$ measures the cost of evaluating it: how many bits of the input are needed to be certain about the result of $f$. There are many competing complexity measures but we focus on level-$p$-complexity -- a function of the probability $p$ that a bit is 1. The level-$p$-complexity $D_p(f)$ is the minimum expected cost when the input bits are independent and identically distributed with Bernoulli($p$) distribution. We specify the problem as choosing the minimum expected cost of all possible decision trees -- which directly translates to a clearly correct, but very inefficient implementation. The library uses thinning and memoization for efficiency and type classes for separation of concerns. The complexity is represented using polynomials, and the order relation used for thinning is implemented using polynomial factorisation and root-counting. Finally we compute the complexity for two-level iterated majority and improve on an earlier result by J.~Jansson.
翻译:本文描述了一个纯函数式库,用于计算布尔函数的水平-p复杂度,并将其应用于两层迭代多数函数。布尔函数即从 $n$ 个比特到一个比特的映射,可描述数字电路、投票系统等。多数函数是布尔函数的一个实例,当 $n$ 为奇数时,它返回输入 $n$ 个比特中占多数的值。布尔函数 $f$ 的复杂度衡量其求值成本:需要输入中多少比特才能确定 $f$ 的结果。存在多种竞争性复杂度度量,我们聚焦于水平-p复杂度——它是比特为1的概率 $p$ 的函数。水平-p复杂度 $D_p(f)$ 是在输入比特独立同分布且服从伯努利($p$)分布时,期望成本的最小值。我们将问题形式化为选择所有可能决策树中的最小期望成本——这直接转化为一个正确但效率极低的实现。该库使用剪枝和记忆化提高效率,并通过类型类实现关注点分离。复杂度用多项式表示,用于剪枝的序关系通过多项式因式分解和根计数实现。最后,我们计算了两层迭代多数函数的复杂度,并改进了 J. Jansson 先前的结果。