De Morgan’s Law Calculator

De Morgan's Law Calculator .demorgan-wrapper { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; background: #f9f9f9; border: 1px solid #ddd; border-radius: 8px; } .demorgan-header { text-align: center; margin-bottom: 30px; } .demorgan-input-group { display: flex; justify-content: space-around; flex-wrap: wrap; gap: 20px; margin-bottom: 25px; background: #fff; padding: 20px; border-radius: 6px; box-shadow: 0 2px 5px rgba(0,0,0,0.05); } .input-field { display: flex; flex-direction: column; min-width: 150px; } .input-field label { font-weight: 600; margin-bottom: 8px; color: #333; } .input-field select { padding: 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 16px; } .calc-btn { display: block; width: 100%; padding: 15px; background-color: #0073aa; color: white; border: none; border-radius: 5px; font-size: 18px; cursor: pointer; transition: background 0.3s; font-weight: bold; } .calc-btn:hover { background-color: #005177; } #result-container { margin-top: 30px; display: none; } .law-section { background: #fff; border: 1px solid #e1e1e1; padding: 20px; margin-bottom: 20px; border-radius: 6px; border-left: 5px solid #0073aa; } .law-title { font-size: 1.2em; font-weight: bold; color: #2c3e50; margin-bottom: 15px; border-bottom: 1px solid #eee; padding-bottom: 10px; } .logic-step { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed #eee; } .logic-step:last-child { border-bottom: none; } .step-label { font-family: "Courier New", monospace; color: #555; } .step-value { font-weight: bold; } .val-true { color: #27ae60; } .val-false { color: #c0392b; } .final-verdict { margin-top: 15px; text-align: center; font-weight: bold; background: #f0f9eb; color: #27ae60; padding: 10px; border-radius: 4px; } .seo-content { margin-top: 40px; line-height: 1.6; color: #444; } .seo-content h2 { color: #23282d; margin-top: 30px; } .seo-content h3 { color: #23282d; } .seo-content code { background: #eee; padding: 2px 5px; border-radius: 3px; } .truth-table { width: 100%; border-collapse: collapse; margin: 20px 0; font-size: 0.9em; } .truth-table th, .truth-table td { border: 1px solid #ddd; padding: 8px; text-align: center; } .truth-table th { background-color: #f2f2f2; }

De Morgan's Laws Verification Calculator

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"; }

Leave a Reply

Your email address will not be published. Required fields are marked *