DeMorgan's Laws are a pair of transformation rules that are both valid rules of inference. They are essential in computer science, digital electronics, and discrete mathematics for simplifying boolean expressions and logic gate circuits. The laws provide a systematic way to express the negation of conjunctions and disjunctions.
The Two Fundamental Laws
The laws describe how to negate a group of variables connected by an AND or OR operator. In simple terms, when you move a "NOT" inside parentheses, the operator flips.
First Law (Negation of Conjunction): The negation of a conjunction is the disjunction of the negations.
Formula: NOT (A AND B) = (NOT A) OR (NOT B)
Symbolic: ¬(A ∧ B) ⟺ ¬A ∨ ¬B
Second Law (Negation of Disjunction): The negation of a disjunction is the conjunction of the negations.
Formula: NOT (A OR B) = (NOT A) AND (NOT B)
Symbolic: ¬(A ∨ B) ⟺ ¬A ∧ ¬B
How to Use This Calculator
This tool demonstrates the equivalence of logic statements using DeMorgan's theorems. It acts as a verifier to prove that the left-hand side (the negated group) is mathematically identical to the right-hand side (the negated individuals with a flipped operator).
Select the boolean value for Input A (True or False).
Select the Operator connecting them inside the parentheses (AND or OR).
Select the boolean value for Input B (True or False).
Click Apply DeMorgan's Law to see the transformation and verify the truth values.
Practical Application: Logic Gates
In digital electronics, these laws allow engineers to replace logic gates. For example, a NAND gate (NOT AND) is functionally equivalent to a Negative-OR gate (OR gate with inverted inputs). This is crucial for hardware optimization, as entire circuits can often be built using only NAND or NOR gates to reduce manufacturing costs.
Truth Table Example (NAND)
Below is the truth table verifying DeMorgan's First Law: ¬(A ∧ B) = ¬A ∨ ¬B
A
B
A AND B
NOT (A AND B)
NOT A
NOT B
(NOT A) OR (NOT B)
0
0
0
1
1
1
1
0
1
0
1
1
0
1
1
0
0
1
0
1
1
1
1
1
0
0
0
0
function calculateLogic() {
// Retrieve inputs
var valA_str = document.getElementById("valA").value;
var valB_str = document.getElementById("valB").value;
var op = document.getElementById("operator").value;
// Convert to Boolean
var a = (valA_str === "1");
var b = (valB_str === "1");
// UI Strings
var strA = a ? "TRUE" : "FALSE";
var strB = b ? "TRUE" : "FALSE";
var strNotA = !a ? "TRUE" : "FALSE";
var strNotB = !b ? "TRUE" : "FALSE";
var lhsResult = false;
var rhsResult = false;
var visualEq = "";
var exprText = "";
var equivText = "";
// Calculate based on Operator
if (op === "AND") {
// First Law: NOT (A AND B) = (NOT A) OR (NOT B)
// Left Hand Side Calculation
var inner = a && b;
lhsResult = !inner;
// Right Hand Side Calculation
rhsResult = (!a) || (!b);
// Text Generation
exprText = "NOT (" + strA + " AND " + strB + ")";
equivText = "(NOT " + strA + ") OR (NOT " + strB + ")";
visualEq = "¬(" + (a ? "1" : "0") + " ∧ " + (b ? "1" : "0") + ") ⟺ ¬" + (a ? "1" : "0") + " ∨ ¬" + (b ? "1" : "0");
} else {
// Second Law: NOT (A OR B) = (NOT A) AND (NOT B)
// Left Hand Side Calculation
var inner = a || b;
lhsResult = !inner;
// Right Hand Side Calculation
rhsResult = (!a) && (!b);
// Text Generation
exprText = "NOT (" + strA + " OR " + strB + ")";
equivText = "(NOT " + strA + ") AND (NOT " + strB + ")";
visualEq = "¬(" + (a ? "1" : "0") + " ∨ " + (b ? "1" : "0") + ") ⟺ ¬" + (a ? "1" : "0") + " ∧ ¬" + (b ? "1" : "0");
}
// Display Results
document.getElementById("visualEquation").innerHTML = visualEq;
document.getElementById("exprText").innerText = exprText;
document.getElementById("equivText").innerText = equivText;
document.getElementById("lhsResult").innerText = lhsResult ? "TRUE (1)" : "FALSE (0)";
document.getElementById("rhsResult").innerText = rhsResult ? "TRUE (1)" : "FALSE (0)";
// Verification Logic
var verifyEl = document.getElementById("verificationStatus");
if (lhsResult === rhsResult) {
verifyEl.innerText = "LOGIC VERIFIED: EQUIVALENT";
verifyEl.style.color = "#27ae60";
} else {
// This should mathematically never happen in this script unless logic is broken
verifyEl.innerText = "ERROR: LOGIC MISMATCH";
verifyEl.style.color = "#c0392b";
}
// Show result area
document.getElementById("result-area").style.display = "block";
}