Demorgan’s Calculator

DeMorgan's Laws Calculator & Boolean Logic Verifier body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; line-height: 1.6; color: #333; max-width: 1200px; margin: 0 auto; padding: 20px; background-color: #f9f9f9; } .calculator-container { background: #ffffff; padding: 30px; border-radius: 12px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); margin-bottom: 40px; border: 1px solid #e0e0e0; } .calc-title { text-align: center; color: #2c3e50; margin-bottom: 25px; font-size: 24px; font-weight: 700; } .input-group { margin-bottom: 20px; } .grid-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; margin-bottom: 20px; } label { display: block; margin-bottom: 8px; font-weight: 600; color: #555; } select, input { width: 100%; padding: 12px; border: 2px solid #ddd; border-radius: 6px; font-size: 16px; transition: border-color 0.3s; box-sizing: border-box; } select:focus, input:focus { border-color: #3498db; outline: none; } button.calc-btn { width: 100%; padding: 15px; background-color: #3498db; color: white; border: none; border-radius: 6px; font-size: 18px; font-weight: bold; cursor: pointer; transition: background-color 0.3s; } button.calc-btn:hover { background-color: #2980b9; } #result-area { margin-top: 30px; padding: 20px; background-color: #f1f8ff; border-radius: 8px; border-left: 5px solid #3498db; display: none; } .result-row { display: flex; justify-content: space-between; margin-bottom: 10px; border-bottom: 1px solid #dae1e7; padding-bottom: 10px; } .result-row:last-child { border-bottom: none; } .result-label { font-weight: 600; color: #444; } .result-value { font-family: 'Courier New', monospace; font-weight: 700; color: #2c3e50; } .equation-display { text-align: center; font-family: 'Courier New', monospace; font-size: 1.2em; background: #2c3e50; color: #fff; padding: 15px; border-radius: 6px; margin-bottom: 20px; } .article-content { background: white; padding: 40px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.05); } .article-content h2 { color: #2c3e50; border-bottom: 2px solid #eee; padding-bottom: 10px; margin-top: 30px; } .article-content p { margin-bottom: 15px; color: #444; } .article-content ul { margin-bottom: 20px; padding-left: 20px; } .logic-table { width: 100%; border-collapse: collapse; margin: 20px 0; } .logic-table th, .logic-table td { border: 1px solid #ddd; padding: 10px; text-align: center; } .logic-table th { background-color: #f2f2f2; } @media (max-width: 768px) { .grid-row { grid-template-columns: 1fr; } }
DeMorgan's Laws Calculator
TRUE (1) FALSE (0)
AND (Conjunction) OR (Disjunction)
TRUE (1) FALSE (0)
Expression:
DeMorgan's Equivalent:
Left Side Result:
Right Side Result:
Verification:

Understanding DeMorgan's Laws in Boolean Algebra

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).

  1. Select the boolean value for Input A (True or False).
  2. Select the Operator connecting them inside the parentheses (AND or OR).
  3. Select the boolean value for Input B (True or False).
  4. 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"; }

Leave a Reply

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