Boolean operation Created 2026-09-24 Updated 2026-10-14
A Boolean operation is a Boolean function taking truth values encoded as bits: means false and means true. These operations supply the concrete two-valued interpretation of a Boolean algebra. A Boolean valuation fixes the inputs; a truth table lists every possible input. With two input bits there are four rows.
The basic logical connectives are logical conjunction (AND, , both true), logical disjunction (OR, , at least one true), exclusive or (XOR, , exactly one true), and logical negation (NOT, , the opposite value). OR is inclusive: it accepts the case where both inputs are true.[ref]
For an original program-condition example, let mean “the backup is recent” and mean “the backup is verified”. A rule requiring a recent, verified backup uses logical conjunction; one accepting either qualification uses logical disjunction. A rule flagging a mismatch between the two qualifications uses exclusive or. A recent, verified backup gives : AND and OR accept it, while XOR does not flag it. The last row of the truth table makes this difference explicit.
The same small Boolean operations build larger tests and Boolean circuits. In a programming language, the value of a condition and the procedure for evaluating it both matter. For Boolean operands, Python's and, or, and not implement these logical connectives. Evaluation proceeds from the left; and skips its right operand if the left is false, and or skips it if the left is true. More generally, and and or return an operand, whereas not returns a Boolean.[ref]
For example, the Python condition denominator != 0 and numerator / denominator > 2 avoids division by zero because the logical conjunction's second test is evaluated only when the first succeeds. Reversing the tests preserves the abstract truth table for defined operands but can raise a division-by-zero error handled through exception handling. A rewrite involving a side effect must also preserve the needed evaluation behavior.
Events turn Boolean operations into operations on sets. For a die with sample space , let be the event “even outcome” and the event “outcome at least four”. At outcome , use the indicator functions and . Then
Thus logical conjunction becomes set intersection, logical disjunction becomes set union, exclusive or becomes symmetric difference, and logical negation becomes the complement of a set within . Outcome four satisfies both events, so inclusive logical disjunction includes it and exclusive or excludes it. If the die is fair, these four events have probabilities , , , and , respectively. No assumption of independent events is needed for the set identities; indeed and here are not independent, since .
Coherent logic Created 2026-10-06 Updated 2026-10-07
Coherent logic uses atomic formulas and equality, finite logical conjunctions and logical disjunctions, truth, falsity and existential quantification. Sequents are universally interpreted in a finite variable context. Its categorical semantics is provided by coherent categories, where conjunction is intersection, disjunction is finite union and existential quantification is image.
Complement of a set Created 2026-10-05 Updated 2026-10-14
The complement of a subset within a specified universal set contains exactly the set elements of excluded from :
Here depends on the chosen universal set. Within , taking a complement performs logical negation (NOT) on membership. Writing keeps the ambient set visible when there could be ambiguity.
For , , and :
If the universal set grows to , the same sets have different complements: and . In a database illustration, “records that fail this condition” therefore requires deciding which records are eligible to begin with; those eligible records form .
For subsets , De Morgan's laws exchange union and intersection when taking complements:
For the same example, failing both conditions leaves . Failing at least one condition leaves . This is useful for rewriting exclusion rules into separate membership tests. The symmetry is also pleasing: exchanging union with intersection turns one rule into its partner.
Figure 1.
De Morgan's laws: excluding a union means failing both tests, while excluding an intersection means failing at least one
. Details.
A brief membership proof works in classical propositional logic. For any , let mean and mean . The truth table below checks all four possibilities, with meaning true and false:
Each paired column agrees. Translating logical disjunction (OR), logical conjunction (AND), and logical negation (NOT) back into membership proves the two set equalities. For the general method of reducing set equalities to equivalences in propositional logic, see Lehman, Leighton and Meyer, Mathematics for Computer Science (2015), §4.1.5 and Problem 4.5.
A historical perspective appears in Augustus De Morgan's [ref]: he describes treating each name together with its contradictory name. In the membership viewpoint here, a set and its complement likewise pair a condition with its logical negation.
The logic extends first-order logic by countable logical conjunctions and logical disjunctions. Each formula has finitely many free variables, and quantifier strings are finite. In a countable first-order language, every countable structure has a Scott sentence in this logic that characterizes its isomorphism class among countable structures.
For a Boolean function of input bits, define its De Morgan dual by complementing every input, applying , and complementing the output:
De Morgan's laws say that the De Morgan dual of logical conjunction is logical disjunction, and conversely. The constant zero Boolean function becomes constant one. This is different from merely negating the output: for AND, output logical negation gives one at , whereas the De Morgan dual gives zero there.
Taking the De Morgan dual twice restores the original Boolean function:
Here each input is complemented twice as well. For a Boolean formula built from AND, OR, NOT and constants, its De Morgan dual can therefore be obtained by exchanging AND with OR and zero with one throughout, leaving input names and NOT in place. A structural induction proves the rule: it holds for an input and each constant, De Morgan's laws handle the two binary logical connectives, and double logical negation handles NOT. This symmetry lets one translate a complex test systematically instead of guessing where its failures occur.
De Morgan's laws Created 2026-09-28 Updated 2026-10-14
De Morgan's laws exchange logical conjunction and logical disjunction when a logical negation moves across them:
Here denotes logical equivalence: the two propositional formulas agree under every Boolean valuation.[ref]
A complete verification uses the four rows of a truth table. In input order , both sides of the first logical equivalence have output sequence ; both sides of the second have . A proof in words is equally short: failure of “both” means at least one failure, whereas failure of “at least one” means both fail. The differing middle rows explain why simply pushing logical negation inward without changing AND to OR is wrong.
For the events in Boolean operations on events, the corresponding set identities are
One can prove these identities by checking an arbitrary set element : its two membership truth values obey De Morgan's laws. The same reasoning works for any two subsets of a common universal set.
Figure 1.
De Morgan's laws shade the same set whether a compound event is complemented first or its component events are complemented first
. Details.
For a nested program test, let mean “backup recent”, mean “backup verified”, and mean “manual override authorized”. Rejecting when neither an acceptable backup nor an override is present gives
The transformed condition reads “backup stale or unverified, and no override”. Apply the second of De Morgan's laws at the outside, then the first at the inner logical conjunction. For it rejects; changing only to one makes it accept. With Boolean operands in Python, not ((recent and verified) or override) and ((not recent) or (not verified)) and (not override) have the same result and inspect the operands in the same order, with the same skipped operands.
Exclusive or Created 2026-09-28 Updated 2026-10-14
Exclusive or returns one exactly when its two input bits differ. Its truth table gives , , , and . The identities
express exclusive or using logical conjunction, logical disjunction, and logical negation. The first expression accepts at least one input and then excludes both; the second explicitly lists the two accepted input pairs.
For numerical bits, exclusive or is addition in modular arithmetic modulo two:
The binary operation is commutative and associative, because addition modulo two has those properties. It satisfies , , and . These identities explain why a bit can be toggled and restored with the same operation.
On binary strings of equal length, bitwise exclusive or applies the one-bit rule separately at each position. For example,
A bit mask of toggles exactly the middle two bits. Applying the mask twice restores the original binary string: each selected bit changes twice, and each unselected bit stays fixed. This positional operation is distinct from taking the exclusive or of the overall truth values of two integers.
For an atomic formula (including logical equality), put , and put . Preserve logical conjunction, logical implication and universal quantification recursively, while setting
Logical negation is logical implication to logical falsity, so . The displayed logical disjunction and existence clauses are intuitionistically equivalent to the usual negative forms and . Every translated first-order formula is stable by stability of a formula under double negation. In classical logic the translation is equivalent to the original first-order formula by mathematical induction and double-negation elimination.
Logical connective Created 2026-09-28 Updated 2026-10-14
A logical connective forms a compound proposition from component propositions; logical truth and logical falsity are the zero-input cases. Logical negation has one input, while logical conjunction, logical disjunction, and logical implication each have two. In classical propositional logic, these logical connectives are truth-functional: their output value is determined by their input values, as listed in a truth table. This does not characterize every kind of logical connective in every logic. See forall x: Calgary, section 10.1.
Łoś-Tarski preservation theorem Created 2026-10-05 Updated 2026-10-06
A first-order theory has its class of first-order models closed under substructures of a first-order structure exactly when it is equivalent to its universal consequences . If , then is consistent. Otherwise a finite logical conjunction of signed diagram of a structure sentences yields a universal consequence false in . The compactness theorem gives a first-order model of containing an embedded copy of , and closure under substructures of a first-order structure implies . The converse is preservation of universal sentences. The diagram of a structure must include negated as well as positive atomic sentences so that the resulting map is an embedding, not just a homomorphism.
The Gödel-Gentzen negative translation transforms into . Induct on a natural deduction derivation. The translated logical conjunction, logical implication and universal rules are ordinary intuitionistic rules. Logical disjunction and existential introduction add double logical negation; their elimination rules first derive the double logical negation of the stable translated conclusion, then use its stability. Classical double-negation elimination translates precisely to stability. If logical equality atoms are double-negated, transport a stable translated conclusion through a logical equality by contradiction and then remove the resulting double logical negation. Original nonlogical axioms must also be translated; the result does not say arbitrary untranslated classical first-order theories are intuitionistically valid.
Fix an effective syntax encoding for the language. Let be the finite set of axioms observed in the first steps of an enumeration of the given semidecidable axiomatization. These finite approximations can be computed in bounded time, even if the original axiom set is empty or finite. For each , form the precisely bracketed logical conjunction
with . Let .
Each is logically equivalent to , so all members of follow from the original axioms. Every original axiom eventually belongs to some , and its corresponding member implies it. Hence axiomatizes exactly the same theory.
To decide whether a candidate sentence belongs to , let be its syntactic length. A conjunction of copies has length at least , so a representation can only use . Compute each for , construct its finitely many candidates, and compare them literally with . This finite procedure always terminates and accepts exactly . It does not wait for a nonexistent next axiom, nor assume that conjunction parsing determines the original repeated formula uniquely. Thus is a decidable equivalent axiomatization, proving the Craig trick.
A proposed assignment for 2UN-SAT can be checked in polynomial time, including checking the syntactic restriction, so the language belongs to NP.
For an explicit reduction, parse any Boolean formula into a Boolean circuit over binary AND (logical conjunction), binary OR (logical disjunction) and unary NOT (negation), and apply the gate equivalences in part (a), asserting its output. Every gate clause has at most two positive literals: the AND clauses have respectively one, one and one; the OR clauses have one, one and two; and the NOT clauses have two and zero. The unit output/constant clauses also obey the restriction. Hence the resulting formula is an instance of 2UN-SAT.
The Tseitin transformation is linear in the gate description, and its auxiliary variables enforce the gate values rather than relaxing their relation to the inputs. Therefore the original formula is satisfiable if and only if the transformed restricted formula is satisfiable. This is a polynomial-time many-one reduction from SAT, whose hardness follows from the Cook-Levin theorem. Consequently
The condition limits positive literals, without limiting total clause length.
The AND-NOT circuit value problem belongs to P: validate the Boolean circuit and evaluate its gates in a topological ordering. Evaluation takes polynomial time even if its description is not already in a topological ordering.
For P-completeness we use logspace many-one reductions. Start from the supplied circuit value problem over the usual AND (logical conjunction), OR (logical disjunction) and NOT (negation) basis. Retain AND and NOT gates, and replace every OR gate by the De Morgan's laws gadget
This adds only a constant number of gates per old gate, preserves its truth value for all inputs and keeps the Boolean circuit acyclic. If the format includes constant source nodes, replace them by additional input nodes assigned fixed bits zero and one; these are inputs, not disallowed gates. Larger fan-in gates can first be replaced by binary trees of their inputs.
To output the new description, keep the old gate index and a constant-size gadget position, rescan old references when necessary, and assign consistent new indices to each gadget's terminal output. These counters and references occupy bits; the input assignment is copied with any constant-source bits appended. Thus the construction is a logspace many-one reduction preserving acceptance. Since Boolean circuit Value is P-complete under such reductions,
A Cartesian theory has a many-sorted first-order signature, with finite arities, and axioms expressed as sequents between Cartesian formulas. Those formulas use atomic relations and equality, truth and finite logical conjunctions. They also admit existential quantification when the quantified witness is provably unique: to form , require relative to the theory. One can quantify a finite tuple in the same way. Arbitrary existential quantifiers, disjunction, negation and universal quantifiers are not formula constructors in this fragment. In particular falsity is not included as an additional finite-limit constructor. The universal force of a sequent comes from its free-variable context. This is the fragment whose categorical semantics requires exactly finite limits.
The Cartesian syntactic category has objects , identifying harmless renamings and provably equivalent formulas-in-context. An arrow from to is represented by a provably functional Cartesian relation : it entails , is total on , and has a unique output tuple. Provable equivalence identifies arrows. Equality supplies identity arrows; composition quantifies the uniquely determined intermediate tuple in a conjunction. Totality and uniqueness prove that the composite is again functional.
The empty truth context is terminal. Products concatenate disjoint contexts and conjoin their formulas. A pullback of two functional relations adds the condition that their outputs agree; the common output is unique, so the existential quantification used to express it is Cartesian. This gives all finite limits and makes the usual equality diagrams into equalizers.
An internal model in a finite-limit category interprets each sort by an object, functions by arrows and relations by subobjects. Equality is a diagonal and conjunction is a pullback intersection. A uniquely witnessed relation projects monomorphically onto the context, so its existential interpretation needs no general image operation: it is that mono. Evaluating formulas and functional relations yields a finite-limit-preserving functor .
Conversely, the canonical syntactic model uses the single-sort truth contexts, term graphs and atomic subobjects. Its interpretation of a formula is the formula-in-context object itself. Applying any finite-limit-preserving functor supplies a model and preserves its axioms. These constructions are inverse up to the natural interpretation isomorphisms; model homomorphisms correspond to natural transformations. Therefore
For completeness, let a sequent in context be represented by subobjects and for its antecedent and consequent. Derivability is exactly the existence of a factorization in the syntactic category. Consider the covariant representable functor , which preserves all existing limits, and hence corresponds to a set-valued model. In that model the element belongs to the antecedent, because it is the image of . If the sequent holds, it also belongs to the consequent, so for some . That is precisely a derivation of the sequent. Thus validity in all set-valued models implies Cartesian derivability. More concretely, every underivable sequent is refuted by this representable model. No assumption that every sort is inhabited is needed: some hom-sets may be empty.