BooleanCountingFunction
✖
BooleanCountingFunction
represents a Boolean function of n variables that gives True if at most kmax variables are True.
represents a function of n variables that gives True if exactly k variables are True.
represents a function that gives True if between kmin and kmax variables are True.
represents a function that gives True if exactly ki variables are True.
gives the Boolean expression in variables ai corresponding to the Boolean counting function specified by spec.
gives the Boolean expression in the form specified by form.
Details

- BooleanCountingFunction[spec] gives a Boolean function object that works like Function.
- BooleanCountingFunction[spec][a1,a2,…] gives an implicit representation equivalent to the explicit Boolean expression BooleanCountingFunction[spec,{a1,a2,…}].
- BooleanConvert converts BooleanCountingFunction[spec][vars] to an explicit Boolean expression.
- BooleanCountingFunction[{kmin,kmax,s},…] represents a function that gives True if kmin, kmin+s, …, kmax variables are True.
- Any symmetric Boolean function can be represented uniquely using BooleanCountingFunction.
- In BooleanCountingFunction[spec,{a1,a2,…},form], the possible forms are as given for BooleanConvert.
- BooleanCountingFunction[spec,{a1,a2,…}] by default gives an expression in disjunctive normal form (DNF).
Examples
open allclose allBasic Examples (1)Summary of the most common use cases
Scope (6)Survey of the scope of standard use cases
Specify that f is true when at most 2 arguments are true:

https://wolfram.com/xid/0tqle3yb8m54ya-jahxll


https://wolfram.com/xid/0tqle3yb8m54ya-cned8o


https://wolfram.com/xid/0tqle3yb8m54ya-i0r30v


https://wolfram.com/xid/0tqle3yb8m54ya-ihro3s

Between 2 and 3 arguments are true:

https://wolfram.com/xid/0tqle3yb8m54ya-bl3pgk


https://wolfram.com/xid/0tqle3yb8m54ya-e6ss

1, 3, or 5 arguments are true:

https://wolfram.com/xid/0tqle3yb8m54ya-jzvgdc


https://wolfram.com/xid/0tqle3yb8m54ya-epiiq5

Specify that f is true when exactly 1, 4, or 5 arguments are true:

https://wolfram.com/xid/0tqle3yb8m54ya-b0u073


https://wolfram.com/xid/0tqle3yb8m54ya-cf24sd

BooleanCountingFunction is by default preserved in function form:

https://wolfram.com/xid/0tqle3yb8m54ya-2e8xg

Use BooleanConvert to convert to other forms:

https://wolfram.com/xid/0tqle3yb8m54ya-dkn988


https://wolfram.com/xid/0tqle3yb8m54ya-bn11gc

BooleanCountingFunction is automatically converted when given an explicit list of variables:

https://wolfram.com/xid/0tqle3yb8m54ya-ejkjco

The expanded forms can be large when the number of variables grows:

https://wolfram.com/xid/0tqle3yb8m54ya-b27wio

The performance gain in evaluating the function form can be substantial:

https://wolfram.com/xid/0tqle3yb8m54ya-fjzd0o

https://wolfram.com/xid/0tqle3yb8m54ya-fs4nab

https://wolfram.com/xid/0tqle3yb8m54ya-b8bbm9

https://wolfram.com/xid/0tqle3yb8m54ya-f80wda


https://wolfram.com/xid/0tqle3yb8m54ya-lz42bz

Constant arguments are reduced:

https://wolfram.com/xid/0tqle3yb8m54ya-mo6wp0


https://wolfram.com/xid/0tqle3yb8m54ya-bie7ev

Extreme cases are automatically converted to formulas:

https://wolfram.com/xid/0tqle3yb8m54ya-cuk5ig


https://wolfram.com/xid/0tqle3yb8m54ya-nvq12z


https://wolfram.com/xid/0tqle3yb8m54ya-vu18f

Applications (4)Sample problems that can be solved with this function
Create new primitives that are true when at most, at least, or exactly k arguments are true:

https://wolfram.com/xid/0tqle3yb8m54ya-gnlgrn

https://wolfram.com/xid/0tqle3yb8m54ya-u9w97

https://wolfram.com/xid/0tqle3yb8m54ya-i4i779
Create a number of disk regions along the unit circle:

https://wolfram.com/xid/0tqle3yb8m54ya-euib0u

Show the newly combined regions:

https://wolfram.com/xid/0tqle3yb8m54ya-f67h3j


https://wolfram.com/xid/0tqle3yb8m54ya-bfs2st


https://wolfram.com/xid/0tqle3yb8m54ya-ebxzrw

Define a Boolean function that is true when the number of true arguments is k modulo m:

https://wolfram.com/xid/0tqle3yb8m54ya-k8e0ul
When k=0 and m=2, you get Xnor:

https://wolfram.com/xid/0tqle3yb8m54ya-dzd0k3

When k=1 and m=2, you get Xor:

https://wolfram.com/xid/0tqle3yb8m54ya-gao3o0

For other values of k and m, you get new functionality:

https://wolfram.com/xid/0tqle3yb8m54ya-e7rznf


https://wolfram.com/xid/0tqle3yb8m54ya-ff5pf5


https://wolfram.com/xid/0tqle3yb8m54ya-dk5vss

Define a Boolean function that sorts a list of truth values:

https://wolfram.com/xid/0tqle3yb8m54ya-i8bnt
The resulting list is always in sorted order:

https://wolfram.com/xid/0tqle3yb8m54ya-jffmd2


https://wolfram.com/xid/0tqle3yb8m54ya-b6fozv

Find the mean time to failure for a system that needs two out of three components to work:

https://wolfram.com/xid/0tqle3yb8m54ya-c42t61

https://wolfram.com/xid/0tqle3yb8m54ya-hk7kx

https://wolfram.com/xid/0tqle3yb8m54ya-dkkjpx

Properties & Relations (6)Properties of the function, and connections to other functions
BooleanCountingFunction is symmetric in its arguments:

https://wolfram.com/xid/0tqle3yb8m54ya-h2ycoq


https://wolfram.com/xid/0tqle3yb8m54ya-gm06jw

Logical combinations of BooleanCountingFunction correspond to set operations on indices:

https://wolfram.com/xid/0tqle3yb8m54ya-bp412r

https://wolfram.com/xid/0tqle3yb8m54ya-k6hgq4

https://wolfram.com/xid/0tqle3yb8m54ya-q552hg

The basic specification can equivalently be specified using Range:

https://wolfram.com/xid/0tqle3yb8m54ya-br2ddu


https://wolfram.com/xid/0tqle3yb8m54ya-egh492


https://wolfram.com/xid/0tqle3yb8m54ya-7z83f

Many primitives can be expressed in terms of BooleanCountingFunction:

https://wolfram.com/xid/0tqle3yb8m54ya-ls69v
And:

https://wolfram.com/xid/0tqle3yb8m54ya-bds5ax

https://wolfram.com/xid/0tqle3yb8m54ya-fas5ju

Or:

https://wolfram.com/xid/0tqle3yb8m54ya-gsmhqw

https://wolfram.com/xid/0tqle3yb8m54ya-k45jm

Nand:

https://wolfram.com/xid/0tqle3yb8m54ya-hcois

https://wolfram.com/xid/0tqle3yb8m54ya-g18qck

Nor:

https://wolfram.com/xid/0tqle3yb8m54ya-fxv720

https://wolfram.com/xid/0tqle3yb8m54ya-h7j9y

Xor:

https://wolfram.com/xid/0tqle3yb8m54ya-jjq35g

https://wolfram.com/xid/0tqle3yb8m54ya-r2zp

Xnor:

https://wolfram.com/xid/0tqle3yb8m54ya-ew8qcf

https://wolfram.com/xid/0tqle3yb8m54ya-buefqp


https://wolfram.com/xid/0tqle3yb8m54ya-c8xadt

https://wolfram.com/xid/0tqle3yb8m54ya-fiw5x


https://wolfram.com/xid/0tqle3yb8m54ya-irqnwk

https://wolfram.com/xid/0tqle3yb8m54ya-ccslh

The size of the truth set for BooleanCountingFunction is the length of Subsets:

https://wolfram.com/xid/0tqle3yb8m54ya-d6h3kx


https://wolfram.com/xid/0tqle3yb8m54ya-hm4qde

The size of the truth set for BooleanCountingFunction can be given by a combinatorial sum:

https://wolfram.com/xid/0tqle3yb8m54ya-2b3nj


https://wolfram.com/xid/0tqle3yb8m54ya-gh069s


https://wolfram.com/xid/0tqle3yb8m54ya-g7h9j

Neat Examples (1)Surprising or curious use cases
BooleanCountingFunction for when exactly i variables are true has disjoint truth sets:

https://wolfram.com/xid/0tqle3yb8m54ya-bx1d5t


https://wolfram.com/xid/0tqle3yb8m54ya-h2r9w

Wolfram Research (2008), BooleanCountingFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/BooleanCountingFunction.html.
Text
Wolfram Research (2008), BooleanCountingFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/BooleanCountingFunction.html.
Wolfram Research (2008), BooleanCountingFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/BooleanCountingFunction.html.
CMS
Wolfram Language. 2008. "BooleanCountingFunction." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/BooleanCountingFunction.html.
Wolfram Language. 2008. "BooleanCountingFunction." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/BooleanCountingFunction.html.
APA
Wolfram Language. (2008). BooleanCountingFunction. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/BooleanCountingFunction.html
Wolfram Language. (2008). BooleanCountingFunction. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/BooleanCountingFunction.html
BibTeX
@misc{reference.wolfram_2025_booleancountingfunction, author="Wolfram Research", title="{BooleanCountingFunction}", year="2008", howpublished="\url{https://reference.wolfram.com/language/ref/BooleanCountingFunction.html}", note=[Accessed: 01-April-2025
]}
BibLaTeX
@online{reference.wolfram_2025_booleancountingfunction, organization={Wolfram Research}, title={BooleanCountingFunction}, year={2008}, url={https://reference.wolfram.com/language/ref/BooleanCountingFunction.html}, note=[Accessed: 01-April-2025
]}