BooleanFunction[k,n]
represents the k
Boolean function in n variables.
BooleanFunction[values]
represents the Boolean function corresponding to the specified vector of truth values.
BooleanFunction[{{i11,i12,…}o1,…}]
represents the Boolean function defined by the specified mapping from inputs to outputs.
BooleanFunction[spec,{a1,a2,…}]
gives the Boolean expression in variables ai corresponding to the Boolean function specified by spec.
BooleanFunction[spec,{a1,a2,…},form]
gives the Boolean expression in the form specified by form.
BooleanFunction
BooleanFunction[k,n]
represents the k
Boolean function in n variables.
BooleanFunction[values]
represents the Boolean function corresponding to the specified vector of truth values.
BooleanFunction[{{i11,i12,…}o1,…}]
represents the Boolean function defined by the specified mapping from inputs to outputs.
BooleanFunction[spec,{a1,a2,…}]
gives the Boolean expression in variables ai corresponding to the Boolean function specified by spec.
BooleanFunction[spec,{a1,a2,…},form]
gives the Boolean expression in the form specified by form.
Details
- BooleanFunction[spec] gives a Boolean function object that works like Function.
- BooleanFunction[fun] converts a Boolean pure function fun to a Boolean function object.
- BooleanFunction[spec][a1,a2,…] gives an implicit representation equivalent to the explicit Boolean expression BooleanFunction[spec,{a1,a2,…}].
- BooleanConvert converts BooleanFunction[spec][vars] to an explicit Boolean expression.
- In BooleanFunction[values] etc., values can be specified either as True and False or as 1 and 0.
- The functions represented by BooleanFunction always return True or False.
- In BooleanFunction[values], the values are specified in binary order starting with 111, ….
- BooleanFunction[k,n] is equivalent to BooleanFunction[IntegerDigits[k,2,2^n]].
- In BooleanFunction[values], each value can be a list, representing a vector-valued Boolean function.
- In BooleanFunction[{{i11,i12,…}->o1,…}] the oi can be lists, representing vector-valued Boolean functions.
- Elements of both inputs and outputs can be specified either as True and False or as 1 and 0.
- Elements of inputs and outputs can also include any number of _, representing "don't cares".
- They can also include up to one __, representing a sequence of "don't cares".
- In BooleanFunction[spec,{a1,a2,…},form], the possible forms are as given for BooleanConvert.
- BooleanFunction[spec,{a1,a2,…}] by default gives an expression in DNF.
- BooleanFunction[k] gives the k
Boolean function in n variables, where n has the smallest value for which
. - The numbering of Boolean functions in BooleanFunction[k,…] is consistent with CellularAutomaton.
- BooleanFunction[CellularAutomaton[n]] is equivalent to BooleanFunction[n,3].
- BooleanFunction[CellularAutomaton[{n,2,r}]] is equivalent to BooleanFunction[n,2r+1].
- Operations such as BooleanMinimize, BooleanTable, etc. can operate directly on BooleanFunction objects.
- BooleanFunction objects can be applied to variables just like other Boolean functions such as And, Or, etc.
- In StandardForm and related formats, BooleanFunction objects are printed in elided form, with only their number of variables displayed.
- BooleanVariables gives the number of variables of a BooleanFunction object.
Examples
open all close allBasic Examples (4)
Generate the 30
Boolean function of 3 variables:
f = BooleanFunction[30, 3]Use f like any other Boolean operator:
f[True, False, True]BooleanConvert[f[x, y, z], "DNF"]Generate the formula directly:
BooleanFunction[30, {x, y, z}]Specify a Boolean function based on a table of truth rules:
BooleanFunction[{{False, False} -> True, {False, True} -> False, {True, False} -> True, {True, True} -> True}, {x, y}]Use an incompletely specified truth table:
BooleanFunction[{{True, True, False} -> True, {False, __} -> False}, {x, y, z}]Convert a Boolean expression to a BooleanFunction:
f = BooleanConvert[Xor[x, y, z], "BooleanFunction"]Test that they represent the same function:
BooleanTable[{f, Xor[x, y, z]}, {x, y, z}]Convert Boolean pure functions to BooleanFunction objects:
BooleanFunction[#1 && #2 || #3&]BooleanFunction[BooleanCountingFunction[3, 5]]Scope (15)
Basic Uses (3)
Create a BooleanFunction with two arguments by indexing:
f = BooleanFunction[11, 2]Compute its value for particular arguments:
f[False, True]The function remains unevaluated for symbolic arguments:
f[x, y]BooleanFunction can be used just like any other Boolean operator:
FindInstance[f[x, y], {x, y}, Booleans]RegionPlot[f[x ^ 2 + y < 1, x - y ^ 2 > 0], {x, -2, 2}, {y, -2, 2}]Integrate[Boole[f[x ^ 2 + y < 1, x - y ^ 2 > 0]], {x, 0, 2}, {y, 0, 2}]Reduce[f[x + y < 1, x + y ^ 2 > 0], {x, y}]Sum[Boole[f[x ^ 2 + y < 1, x - y ^ 2 > 0]], {x, 0, 10}, {y, 0, 10}]Any Boolean expression can be converted to a BooleanFunction expression:
BooleanConvert[x && (y || z), "BFF"]Including combinations of BooleanFunction expressions:
BooleanConvert[f[%, w], "BFF"]A BooleanFunction expression that is equivalent to True or False automatically simplifies:
{g, h} = {BooleanFunction[0, 10], BooleanFunction[2 ^ 2 ^ 10 - 1, 10]}g@@Array[x, 10]h@@Array[x, 10]BooleanFunction is a canonical representation, and equivalence can be tested using SameQ:
g = BooleanConvert[a && b, "BFF"]h = BooleanConvert[x && y, "BFF"]Head[g] === Head[h]Working with Truth Tables (7)
Create a truth table in standard order:
f1 = x && (y || z);t1 = BooleanTable[f1, {x, y, z}]Create an equivalent BooleanFunction expression:
f2 = BooleanFunction[t1][x, y, z]Show that they are equivalent:
TautologyQ[Equivalent[f1, f2]]Alternatively, show that the resulting truth tables are the same:
t2 = BooleanTable[f2, {x, y, z}]t1 === t2Create a complete list of truth rules:
f1 = x && (y || z);t1 = BooleanTable[{x, y, z} -> f1, {x, y, z}]Create the corresponding BooleanFunction expression:
f2 = BooleanFunction[t1][x, y, z]The ordering of truth rules for complete lists has no effect:
f3 = BooleanFunction[Reverse[t1]][x, y, z]TautologyQ[Equivalent[f1, f2, f3]]Use _ to indicate "don't cares" in a truth table:
t1 = {False, _, _, True};Create a BooleanFunction:
f1 = BooleanFunction[t1][x, y]The resulting truth table matches the original specification:
t2 = BooleanTable[f1, {x, y}]MatchQ[t2, t1]Use _ and __ to indicate "don't cares" in truth rules:
r1 = {{True, True, _} -> True, {__} -> False};Create a BooleanFunction:
f1 = BooleanFunction[r1][x, y, z]r2 = BooleanTable[{x, y, z} -> f1, {x, y, z}]The original rules completely specify the function and the resulting truth tables are identical:
Replace[Tuples[{True, False}, 3], r1, {1}]Replace[Tuples[{True, False}, 3], r2, {1}]Use lists of lists to indicate a vector-valued truth table:
t1 = {{True, False}, {__}, {_, False}, {False, True}};Create a BooleanFunction:
f1 = BooleanFunction[t1][x, y]The resulting output matches the original specification:
t2 = BooleanTable[f1, {x, y}]MatchQ[t2, t1]Use vector-valued truth rules:
r1 = {{True, True, False} -> {False, True}, {False, __} -> {True, False}};Create a BooleanFunction:
f1 = BooleanFunction[r1][x, y, z]r2 = BooleanTable[{x, y, z} -> f1, {x, y, z}]The resulting truth rules match the original specification:
t1 = Replace[Tuples[{True, False}, 3], Append[r1, _ -> _], {1}]t2 = Replace[Tuples[{True, False}, 3], r2, {1}]MatchQ[t2, t1]Truth tables can also be given using 0 in place of False and 1 in place of True:
t1 = RandomInteger[{0, 1}, 8]f = BooleanFunction[t1][x, y, z]t2 = Boole@BooleanTable[f, {x, y, z}]The resulting truth tables are identical:
t1 === t2Working with Other Representations (5)
Convert any Boolean expression to a BooleanFunction expression:
f1 = Nand[Nor[x, y], Xor[y, z]];f2 = BooleanConvert[f1, "BFF"]Show that they are equivalent:
TautologyQ[Equivalent[f1, f2]]Construct a BooleanFunction expression in a specified standard form:
f = BooleanFunction[123, {x, y, z}, "DNF"]f = BooleanFunction[123, {x, y, z}, "CNF"]f = BooleanFunction[123, {x, y, z}, "ANF"]f = BooleanFunction[123, {x, y, z}, "NAND"]f = BooleanFunction[123, {x, y, z}, "NOR"]f = BooleanFunction[123, {x, y, z}, "Implies"]Convert expressions involving any Boolean operators:
f1 = BooleanMinterms[{1, 4, 7}, 3][x, BooleanFunction[110, 3][x, y, z], BooleanCountingFunction[{3, 5}, 5][x, y, x, y, z]]f2 = BooleanConvert[f1, "BFF"]Show that they are equivalent:
TautologyQ[Equivalent[f1, f2]]Convert a BooleanFunction expression to other standard forms:
f = BooleanFunction[123, 3][x, y, z]A number of different standard forms:
BooleanConvert[f, "DNF"]BooleanConvert[f, "CNF"]BooleanConvert[f, "ANF"]BooleanConvert[f, "NAND"]BooleanConvert[f, "NOR"]BooleanConvert[f, "Implies"]BooleanTable[f, {x, y, z}]BooleanTable[{x, y, z} -> f, {x, y, z}]Specify BooleanFunction using CellularAutomaton:
BooleanFunction[CellularAutomaton[77]]% === BooleanFunction[77, 3]BooleanFunction[CellularAutomaton[{123, 2, 7 / 2}]]% === BooleanFunction[123, 2 7 / 2 + 1]Applications (4)
Enumerating Boolean Functions (2)
Enumerate all 2-variable Boolean functions:
Table[ArrayPlot[BooleanTable[BooleanFunction[i, 2][x, y], {x}, {y}], ColorRules -> {False -> White, True -> Black}, ImageSize -> 15, PlotLabel -> Style[i, Small]], {i, 0, 15}]All 3-variable Boolean functions:
Table[ArrayPlot[BooleanTable[BooleanFunction[i, 3][x, y, z], {x}, {y, z}], ColorRules -> {False -> White, True -> Black}, ImageSize -> 25, PlotLabel -> Style[i, Small]], {i, 0, 255}]Randomly sample 50 functions of 4 variables:
Table[ArrayPlot[BooleanTable[BooleanFunction[i, 4][x, y, z, w], {x, y}, {z, w}], ColorRules -> {False -> White, True -> Black}, ImageSize -> 30, PlotLabel -> Style[i, Small]], {i, RandomInteger[{0, 2 ^ 2 ^ 4 - 1}, 50]}]Compare the sizes of Boolean functions in their standard and minimized forms:
size[h_] := If[Head[h] === Or, Length[h], 1]Tally@Table[size@BooleanFunction[i, {x, y, z}], {i, 0, 2 ^ 2 ^ 3 - 1}]Tally@Table[size@BooleanMinimize[BooleanFunction[i, {x, y, z}]], {i, 0, 2 ^ 2 ^ 3 - 1}]ListLinePlot[{%%, %}]Four variables, the first 1000 functions:
Tally@Table[size@BooleanFunction[i, {x, y, z, w}], {i, 0, 1000}]Tally@Table[size@BooleanMinimize[BooleanFunction[i, {x, y, z, w}]], {i, 0, 1000}]ListLinePlot[{%%, %}]Creating New Primitives (1)
Create new Boolean primitives corresponding to ≤, ≥, <, and >:
BooleanLessEqual = BooleanFunction[{{0, 0} -> 1, {0, 1} -> 1, {1, 0} -> 0, {1, 1} -> 1}];BooleanGreaterEqual = BooleanFunction[{{0, 0} -> 1, {0, 1} -> 0, {1, 0} -> 1, {1, 1} -> 1}];BooleanLess = BooleanFunction[{{0, 0} -> 0, {0, 1} -> 1, {1, 0} -> 0, {1, 1} -> 0}];BooleanGreater = BooleanFunction[{{0, 0} -> 0, {0, 1} -> 0, {1, 0} -> 1, {1, 1} -> 0}];TautologyQ[Equivalent[Not[BooleanLessEqual[x, y]], BooleanGreater[x, y]]]TautologyQ[Equivalent[Not[BooleanGreaterEqual[x, y]], BooleanLess[x, y]]]Implies is equivalent to x<=y:
TautologyQ[Equivalent[BooleanLessEqual[x, y], Implies[x, y]]]Define a relation for Boolean functions f≼g iff
f[u]≤g[u]:
Conjunction[BooleanLessEqual[x, x∨y], {x, y}]Here you have x≼x∨y as reflected in the truth tables:
BooleanTable[{x, x∨y}, {x, y}]BooleanLessEqual@@@%Boole@BooleanTable[{x, x∨y}, {x, y}]LessEqual@@@%For all Boolean functions f and g, f∧g≼f≼f∨g:
Conjunction[BooleanLessEqual[f∧g, f], {f, g}]Conjunction[BooleanLessEqual[f, f∨g], {f, g}]This proves that f≼g iff f∧g⇔f:
TautologyQ[Equivalent[BooleanLessEqual[f, g], Equivalent[f∧g, f]]]TautologyQ[Equivalent[BooleanLessEqual[f, g], Equivalent[f∨g, g]]]Or that f≼g and g≼h implies f≼h:
TautologyQ[Implies[BooleanLessEqual[f, g]∧BooleanLessEqual[g, h], BooleanLessEqual[f, h]]]Cellular Automata (1)
Generate the rule 30 elementary cellular automaton rule:
f = Function[{v, i}, BooleanFunction[30, 3]@@v]CellularAutomaton[{f, {}, 1}, {False, False, True, False, False}, 2]Compare to the standard encoding:
Boole[%]CellularAutomaton[30, {0, 0, 1, 0, 0}, 2]Properties & Relations (7)
BooleanFunction displays in an elided form indicating the number of arguments:
f = BooleanFunction[30, 3]{AtomQ[f], Length[f]}The InputForm gives an encoding that can be used to reconstruct the object:
InputForm[f]Use the encoding to construct a BooleanFunction:
g = BooleanFunction["BDD" -> {-3, 0, 2, -2, 1, 1, 3, 2, 1, -1}]The result is identical to the original:
f === gThe order of values for BooleanFunction is the same as BooleanTable:
t1 = BooleanTable[Xor[x, y], {x, y}]The corresponding BooleanFunction has an identical truth table:
f = BooleanFunction[t1]BooleanTable[f[x, y], {x, y}]The ordering is consistent with Tuples:
f@@@Tuples[{True, False}, 2]Indexing of BooleanFunction is consistent with IntegerDigits:
With[{m = 1234, k = 5}, BooleanFunction[m, k] === BooleanFunction[IntegerDigits[m, 2, 2 ^ k]]]Convert from a BooleanFunction to its index:
f = BooleanFunction[1234, 5]FromDigits[Boole@BooleanTable[f], 2]Convert from any Boolean expression to its index:
FromDigits[Boole@BooleanTable[Xor[x, y, x || z], {x, y, z}], 2]Show that it is equivalent with the indexed BooleanFunction expression:
TautologyQ[Equivalent[BooleanFunction[%, 3][x, y, z], Xor[x, y, x || z]]]The indexing of Boolean functions agrees with the indexing of cellular automata:
CellularAutomaton[30, #][[2]]& /@ Tuples[{1, 0}, 3]Boole@BooleanTable[BooleanFunction[30, 3]]More generally, for CellularAutomaton[{k,2,r}] with integer
and
, the relation reads:
With[{k = 123, r = 5 / 2}, CellularAutomaton[{k, 2, r}, #][[Ceiling[r] + 1]]& /@ Tuples[{1, 0}, 2r + 1] === Boole@BooleanTable[BooleanFunction[k, 2r + 1]]]CellularAutomaton satisfying the preceding properties can be used to specify BooleanFunction:
BooleanFunction[CellularAutomaton[30]] === BooleanFunction[30, 3]BooleanFunction[CellularAutomaton[{123, 2, 5 / 2}]] === BooleanFunction[123, 6]BooleanMinterms can also represent any BooleanFunction:
f1 = BooleanMinterms[{1, 5, 7}, 3]f2 = BooleanFunction[FromDigits[{1, 0, 1, 0, 0, 0, 1, 0}, 2], 3]f1 === f2The mapping from minterms to index:
mindex[l_, k_] := FromDigits[Table[If[MemberQ[l, i], 1, 0], {i, 2 ^ k - 1, 0, -1}], 2]mindex[{1, 5, 7}, 3]The mapping from index to minterms:
indmin[m_, k_] := Flatten@Position[Reverse[IntegerDigits[m, 2, 2 ^ k]], 1] - 1indmin[162, 3]With[{m = 123, k = 4}, BooleanMinterms[Select[Range[0, 2^k - 1], BitAnd[2^#, m] ≠ 0&], k] === BooleanFunction[m, k]]Use BooleanConvert to convert to BooleanFunction from other forms:
f1 = Xor[x, y && z];f2 = BooleanConvert[f1, "BFF"]Also use BooleanConvert to convert from BooleanFunction to other forms:
f3 = BooleanConvert[f2, "NAND"]Show that they are all equivalent:
TautologyQ[Equivalent[f1, f2, f3]]Use BooleanTable to convert BooleanFunction to truth tables:
f = BooleanFunction[23, 3]BooleanTable[f]BooleanTable[{x, y, z} -> f[x, y, z], {x, y, z}]Related Guides
History
Text
Wolfram Research (2008), BooleanFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/BooleanFunction.html.
CMS
Wolfram Language. 2008. "BooleanFunction." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/BooleanFunction.html.
APA
Wolfram Language. (2008). BooleanFunction. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/BooleanFunction.html
BibTeX
@misc{reference.wolfram_2026_booleanfunction, author="Wolfram Research", title="{BooleanFunction}", year="2008", howpublished="\url{https://reference.wolfram.com/language/ref/BooleanFunction.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_booleanfunction, organization={Wolfram Research}, title={BooleanFunction}, year={2008}, url={https://reference.wolfram.com/language/ref/BooleanFunction.html}, note=[Accessed: 12-June-2026]}