Select boolean values for variables A and B to verify De Morgan's First and Second Laws.
TRUE (1)
FALSE (0)
TRUE (1)
FALSE (0)
Understanding De Morgan's Laws in Logic and Set Theory
De Morgan's Laws are a pair of transformation rules that are both valid rules of inference. They provide a mathematical way to understand how the negation operation distributes over the conjunction (AND) and disjunction (OR) of propositions. These laws are fundamental in the fields of Boolean algebra, computer science, and digital logic design.
The First Law: Negation of a Conjunction
The first law states that the negation of a conjunction ("A and B") is equal to the disjunction of their negations ("Not A or Not B").
Formula:¬(A ∧ B) ⟺ (¬A) ∨ (¬B)
In set theory notation, this is expressed as the complement of the intersection of two sets being equal to the union of their complements: (A ∩ B)' = A' ∪ B'.
The Second Law: Negation of a Disjunction
The second law states that the negation of a disjunction ("A or B") is equal to the conjunction of their negations ("Not A and Not B").
Formula:¬(A ∨ B) ⟺ (¬A) ∧ (¬B)
In set theory notation: (A ∪ B)' = A' ∩ B'.
How to Use This Calculator
This calculator acts as an interactive truth table verifier. By selecting the truth values (True/1 or False/0) for two distinct propositions, A and B, the tool calculates the boolean result for both sides of the equations simultaneously.
Variable A & B: Select the input state (True or False) for your logical variables.
Verify Logic: Click the button to process the boolean operations.
Analysis: Review the step-by-step breakdown to see how the Left-Hand Side (LHS) and Right-Hand Side (RHS) of the equations resolve to the same value.
Applications of De Morgan's Law
These laws are critical in simplifying logical expressions in computer programming (conditional statements), optimizing digital circuits (converting AND gates to NOR gates), and solving probability problems involving independent events.
function verifyDeMorgan() {
// 1. Get Input Values
var valA_raw = document.getElementById("inputA").value;
var valB_raw = document.getElementById("inputB").value;
// 2. Parse Integers (0 or 1)
var a = parseInt(valA_raw, 10);
var b = parseInt(valB_raw, 10);
// 3. Helper function to format boolean text
function formatBool(val) {
if (val === 1 || val === true) {
return 'TRUE (1)';
} else {
return 'FALSE (0)';
}
}
// — LAW 1: NOT (A AND B) = (NOT A) OR (NOT B) —
// Logic Steps
var a_and_b = a & b; // A AND B
var lhs_1 = a_and_b === 1 ? 0 : 1; // NOT (A AND B)
var not_a = a === 1 ? 0 : 1; // NOT A
var not_b = b === 1 ? 0 : 1; // NOT B
var rhs_1 = not_a | not_b; // (NOT A) OR (NOT B)
// — LAW 2: NOT (A OR B) = (NOT A) AND (NOT B) —
// Logic Steps
var a_or_b = a | b; // A OR B
var lhs_2 = a_or_b === 1 ? 0 : 1; // NOT (A OR B)
// not_a and not_b are already calculated
var rhs_2 = not_a & not_b; // (NOT A) AND (NOT B)
// 4. Construct Output HTML
var outputHtml = ";
// Law 1 Block
outputHtml += '
';
outputHtml += '
First Law: ¬(A ∧ B) ⇔ (¬A) ∨ (¬B)
';
outputHtml += '
A ∧ B' + formatBool(a_and_b) + '
';
outputHtml += '
LHS: ¬(A ∧ B)' + formatBool(lhs_1) + '
';
outputHtml += '
¬A' + formatBool(not_a) + '
';
outputHtml += '
¬B' + formatBool(not_b) + '
';
outputHtml += '
RHS: (¬A) ∨ (¬B)' + formatBool(rhs_1) + '
';
if (lhs_1 === rhs_1) {
outputHtml += '
VERIFIED: LHS EQUALS RHS
';
} else {
outputHtml += '
ERROR IN CALCULATION
';
}
outputHtml += '
';
// Law 2 Block
outputHtml += '
';
outputHtml += '
Second Law: ¬(A ∨ B) ⇔ (¬A) ∧ (¬B)
';
outputHtml += '
A ∨ B' + formatBool(a_or_b) + '
';
outputHtml += '
LHS: ¬(A ∨ B)' + formatBool(lhs_2) + '
';
outputHtml += '
¬A' + formatBool(not_a) + '
';
outputHtml += '
¬B' + formatBool(not_b) + '
';
outputHtml += '
RHS: (¬A) ∧ (¬B)' + formatBool(rhs_2) + '
';
if (lhs_2 === rhs_2) {
outputHtml += '
VERIFIED: LHS EQUALS RHS
';
} else {
outputHtml += '
ERROR IN CALCULATION
';
}
outputHtml += '
';
// 5. Display Result
var resultContainer = document.getElementById("result-container");
resultContainer.innerHTML = outputHtml;
resultContainer.style.display = "block";
}