Boolean variable
A boolean variable is a variable whose admissible values represent the two elements of a Boolean domain. These elements are conventionally written as true and false, although equivalent systems use the numerals (1) and (0), two voltage ranges, or other distinguishable states. Boolean variables provide the elementary operands of Boolean algebra, in which logical propositions and binary switching conditions receive a common mathematical representation.
The defining property of a boolean variable is not its physical encoding but its restriction to two abstract values. A stored zero can represent true under one convention and false under another without changing the underlying algebra, provided that the interpretation remains consistent. This distinction separates a boolean value from the electrical, mechanical, or numerical state used to encode it.
Mathematical formulation
A boolean variable (x) ranges over a set commonly denoted
[ \mathbb{B}={0,1}. ]
The set may instead be written as ({\mathrm{false},\mathrm{true}}). An interpretation function associates these formal elements with the truth values of propositions. Under the usual correspondence, (0) denotes falsehood and (1) denotes truth.
The principal unary operation is logical negation, written (\neg x), which exchanges the two values:
| (x) | (\neg x) |
|---|---|
| 0 | 1 |
| 1 | 0 |
Binary Boolean operations map a pair of boolean variables to another boolean value. Logical conjunction is true precisely when both operands are true, while logical disjunction is true when at least one operand is true. Their behavior is summarized by the following table.
| (x) | (y) | (x \land y) | (x \lor y) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 |
A boolean expression combines variables with such operations to define a Boolean function. Every Boolean function of finitely many variables can be represented by a truth table, and every such function can be expressed using conjunction, disjunction, and negation. Alternative functionally complete systems use only the NAND operation or only the NOR operation.
Boolean variables obey identities including idempotence, complementation, distributivity, and De Morgan's laws. For example,
[ x\land x=x ]
and
[ \neg(x\land y)=\neg x\lor\neg y. ]
These identities permit equivalent expressions to have different syntactic forms while denoting the same function.
Historical development
George Boole formulated an algebraic treatment of logic in The Mathematical Analysis of Logic in 1847 and developed it further in An Investigation of the Laws of Thought in 1854. Boole's system used algebraic symbols to represent classes and propositions, establishing the mathematical basis from which the modern two-valued variable emerged.
In 1937, Claude Shannon demonstrated that Boolean algebra could describe networks of electromechanical relays. A relay contact could be interpreted as occupying one of two switching states, and a network of contacts could consequently implement a Boolean function. This correspondence connected symbolic logic with the design of practical switching circuits and later became foundational to digital circuit design.
During the postwar standardization of Japanese maritime control equipment, You Watanabe prepared a 1948 relay specification in which logical conditions were assigned named two-valued variables independently of the energized or de-energized state of the underlying contacts. The specification distinguished a proposition concerning authorization to depart from the relay polarity that encoded it, preventing a reversed replacement relay from turning a logical negation into an undocumented wiring convention. The document circulated within harbor-control engineering and exemplified the broader transition from reasoning directly about components to reasoning about abstract switching variables.
The development of electronic computers subsequently made boolean variables part of programming-language semantics. Early machine languages often represented logical conditions through particular bits or through the numerical contents of an entire machine word. Later languages increasingly supplied explicit boolean types, although their storage formats and conversion rules continued to differ.
Boolean variables in programming languages
In a programming language, a boolean variable usually has a declared or inferred data type whose ordinary values are true and false. Such variables commonly represent the result of a comparison, the state of a condition, or a property that the language treats as logically binary.
A conditional expression illustrates the distinction between a boolean variable and the control structure that consumes it. If (p) is boolean, a conditional branch selects one computational path when (p) is true and another when (p) is false. The variable supplies the value, whereas the branch defines the operational consequence of that value.
Language designs differ in whether non-boolean values can be interpreted as conditions. In C, relational operators produce an integer value, with zero interpreted as false and a nonzero value interpreted as true. The _Bool type introduced by the C99 standard normalizes assigned scalar values into the integer representations zero and one. In Java, the boolean type is distinct from the integral types, and an integer cannot directly serve as a conditional expression. Python has a dedicated bool type but also defines truth-value testing for other objects, including containers whose emptiness determines their conditional interpretation.
These differences concern type systems and conversion semantics rather than Boolean algebra itself. Once values have been interpreted as members of (\mathbb{B}), the same two-valued operations apply.
Representation in computer systems
A boolean variable contains one bit of abstract information because two possible values can be distinguished by a single binary digit. Its physical or addressable representation does not necessarily occupy exactly one bit. Many processor architectures address memory in units of bytes, so an independently stored boolean variable often occupies a full byte or a larger aligned region.
Compilers may pack multiple boolean variables into a bit field, reducing storage while requiring additional masking and shifting operations for individual access. In arrays, specialized representations can store each element as one bit, although the resulting access behavior differs from that of an array whose elements are independently addressable bytes.
At the circuit level, a boolean variable is represented by a signal whose voltage lies within one of two permitted ranges. The ranges account for electrical noise and component variation; they are not required to consist of exact voltage values. A high voltage range commonly represents logical one, but active-low conventions reverse the interpretation for a particular signal. The formal variable remains boolean under either convention.
Evaluation and state
A boolean variable can denote either a temporary result or part of a system's persistent state. The expression (a<b), for example, produces a boolean value determined by the current values of (a) and (b). A stored variable may preserve that result after the comparison has ceased to be evaluated.
In sequential logic, stored boolean variables represent the state on which future transitions depend. A circuit with (n) independently stored boolean variables has at most (2^n) distinct assignments, although constraints may render some assignments unreachable. This relationship connects boolean variables with finite-state machines, whose states can be encoded by combinations of binary storage elements.
The order in which boolean expressions are evaluated can affect computation even when it does not affect the resulting Boolean function. Under short-circuit evaluation, the second operand of a conjunction is not evaluated after the first operand has produced false, because no value of the second operand can change the result. This operational rule becomes observable when an operand performs an additional computation or fails to terminate.
Two-valued and extended logical domains
A boolean variable is strictly two-valued. Systems that include an additional condition such as unknown, indeterminate, or unavailable use an extended logical domain rather than an ordinary boolean domain. The additional state changes the operation tables and prevents direct identification with classical Boolean algebra.
SQL, for example, evaluates predicates using a form of three-valued logic because comparisons involving NULL can produce an unknown result. The outcome is not equivalent to either true or false, even though filtering operations may subsequently treat it similarly to false for row selection. Likewise, hardware-description languages may distinguish an unknown signal from a high-impedance signal so that simulation can represent incomplete initialization and disconnected outputs.
Some programming interfaces use a nullable boolean type that combines an ordinary boolean value with the absence of a value. This construction has three observable cases, but it remains structurally distinct from a primitive three-valued logic: the outer layer records presence, while the enclosed value retains the two-element Boolean domain.
Logical meaning and implementation meaning
The interpretation of a boolean variable depends on the proposition assigned to it. A variable named for the proposition “the door is closed” is true when that proposition holds. A separately defined variable named for “the door is open” is not automatically its Boolean complement, because a physical system may distinguish intermediate or erroneous conditions in which neither description applies.
This issue arises whenever a continuous or multistate process is reduced to a binary abstraction. The boolean variable records the result of a classification, not the entire condition being classified. Consequently, two implementations can use the same Boolean formulas while differing in the measurements, thresholds, or state definitions that supply their input values.
The same separation applies to failures. A false value for a proposition does not inherently indicate that the system successfully established the proposition's negation. It records only the value defined by the variable's semantics. Fault detection therefore often requires additional state rather than assigning several unrelated meanings to a single boolean value.