Test the logical equivalence of boolean expressions using De Morgan's Laws.
TRUE
FALSE
TRUE
FALSE
First Law: Negation of a Conjunction (AND)
NOT (A AND B) ≡ (NOT A) OR (NOT B)
Result:
Second Law: Negation of a Disjunction (OR)
NOT (A OR B) ≡ (NOT A) AND (NOT B)
Result:
What is De Morgan's Law?
De Morgan's Laws are two fundamental rules in Boolean algebra and set theory that relate the intersection and union of sets (or logical AND and OR operators) through negation.
The Two Laws Simplified:
The First Law: The negation of a conjunction (AND) is the disjunction (OR) of the negations. In programming terms: !(A && B) is the same as !A || !B.
The Second Law: The negation of a disjunction (OR) is the conjunction (AND) of the negations. In programming terms: !(A || B) is the same as !A && !B.
Why It Matters
In software development and digital logic design, these laws are essential for simplifying complex if statements and optimizing circuit gates. They allow programmers to rewrite logic in a way that is often more readable or requires fewer computational resources.
Truth Table Reference
A
B
NOT (A AND B)
(!A) OR (!B)
Result
T
T
F
F
Equivalent
T
F
T
T
Equivalent
F
T
T
T
Equivalent
F
F
T
T
Equivalent
Example Calculation
Suppose you have a condition: "It is NOT both raining AND sunny."
Proposition A: It is raining.
Proposition B: It is sunny.
Original:¬(A ∧ B)
De Morgan's Equivalent: "It is NOT raining OR it is NOT sunny." (¬A ∨ ¬B)
function calculateDeMorgan() {
var valA_str = document.getElementById('valA').value;
var valB_str = document.getElementById('valB').value;
var a = (valA_str === 'true');
var b = (valB_str === 'true');
var resultsDiv = document.getElementById('dmResults');
resultsDiv.style.display = 'block';
// Logic Law 1: NOT (A AND B) == (!A OR !B)
var lhs1 = !(a && b);
var rhs1 = (!a) || (!b);
var res1_text = lhs1 ? "TRUE" : "FALSE";
var res1_elem = document.getElementById('law1_res');
res1_elem.innerText = res1_text;
res1_elem.className = lhs1 ? "dm-val" : "dm-val dm-val-false";
var steps1 = "Step-by-step: !(" + (a ? "T" : "F") + " AND " + (b ? "T" : "F") + ") = " + (lhs1 ? "T" : "F") + " | Equivalency Check: " + (!a ? "T" : "F") + " OR " + (!b ? "T" : "F") + " = " + (rhs1 ? "T" : "F");
document.getElementById('law1_steps').innerText = steps1;
// Logic Law 2: NOT (A OR B) == (!A AND !B)
var lhs2 = !(a || b);
var rhs2 = (!a) && (!b);
var res2_text = lhs2 ? "TRUE" : "FALSE";
var res2_elem = document.getElementById('law2_res');
res2_elem.innerText = res2_text;
res2_elem.className = lhs2 ? "dm-val" : "dm-val dm-val-false";
var steps2 = "Step-by-step: !(" + (a ? "T" : "F") + " OR " + (b ? "T" : "F") + ") = " + (lhs2 ? "T" : "F") + " | Equivalency Check: " + (!a ? "T" : "F") + " AND " + (!b ? "T" : "F") + " = " + (rhs2 ? "T" : "F");
document.getElementById('law2_steps').innerText = steps2;
// Smooth scroll to results
resultsDiv.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
}