WOLFRAM

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.

BooleanCountingFunction[{kmin,kmax},n]

represents a function that gives True if between kmin and kmax variables are True.

BooleanCountingFunction[{{k1,k2,}},n]

represents a function that gives True if exactly ki variables are True.

BooleanCountingFunction[spec,{a1,a2,}]

gives the Boolean expression in variables ai corresponding to the Boolean counting function specified by spec.

BooleanCountingFunction[spec,{a1,a2,},form]

gives the Boolean expression in the form specified by form.

Details

Examples

open allclose all

Basic Examples  (1)Summary of the most common use cases

At most two conditions are true:

Out[1]=1

Convert to a disjunctive normal form:

Out[2]=2

Scope  (6)Survey of the scope of standard use cases

Specify that f is true when at most 2 arguments are true:

Out[1]=1
Out[2]=2

Exactly 2 arguments are true:

Out[3]=3
Out[4]=4

Between 2 and 3 arguments are true:

Out[5]=5
Out[6]=6

1, 3, or 5 arguments are true:

Out[7]=7
Out[8]=8

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

Out[1]=1
Out[2]=2

BooleanCountingFunction is by default preserved in function form:

Out[1]=1

Use BooleanConvert to convert to other forms:

Out[2]=2
Out[3]=3

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

Out[1]=1

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

Out[2]=2

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

Out[4]=4
Out[5]=5

Constant arguments are reduced:

Out[1]=1
Out[2]=2

Extreme cases are automatically converted to formulas:

Out[3]=3
Out[4]=4
Out[5]=5

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:

Create a number of disk regions along the unit circle:

Out[4]=4

Show the newly combined regions:

Out[5]=5

Integrate over these regions:

Out[6]=6
Out[7]=7

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

When k=0 and m=2, you get Xnor:

Out[2]=2

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

Out[3]=3

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

Out[4]=4
Out[5]=5

The 2D truth table:

Out[6]=6

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

The resulting list is always in sorted order:

Out[2]=2
Out[3]=3

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

Out[3]=3

Properties & Relations  (6)Properties of the function, and connections to other functions

BooleanCountingFunction is symmetric in its arguments:

Out[1]=1
Out[2]=2

Logical combinations of BooleanCountingFunction correspond to set operations on indices:

Out[3]=3

The basic specification can equivalently be specified using Range:

Out[1]=1
Out[2]=2
Out[3]=3

Many primitives can be expressed in terms of BooleanCountingFunction:

And:

Out[3]=3

Or:

Out[5]=5

Nand:

Out[7]=7

Nor:

Out[9]=9

Xor:

Out[11]=11

Xnor:

Out[13]=13

Equivalent:

Out[15]=15

Majority:

Out[17]=17

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

Out[1]=1
Out[2]=2

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

Out[1]=1
Out[2]=2
Out[3]=3

Neat Examples  (1)Surprising or curious use cases

BooleanCountingFunction for when exactly i variables are true has disjoint truth sets:

Out[1]=1
Out[2]=2
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.

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 ]}

@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 ]}

@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 ]}