Demorgans Law Calculator

.dm-calc-container { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; max-width: 800px; margin: 20px auto; padding: 25px; border: 1px solid #ddd; border-radius: 12px; background-color: #f9f9f9; box-shadow: 0 4px 15px rgba(0,0,0,0.05); } .dm-calc-header { text-align: center; margin-bottom: 25px; } .dm-calc-header h2 { color: #2c3e50; margin-bottom: 10px; } .dm-calc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 25px; } @media (max-width: 600px) { .dm-calc-grid { grid-template-columns: 1fr; } } .dm-input-group { display: flex; flex-direction: column; } .dm-input-group label { font-weight: 600; margin-bottom: 8px; color: #34495e; } .dm-input-group select { padding: 12px; border: 2px solid #3498db; border-radius: 6px; font-size: 16px; background-color: white; } .dm-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; } .dm-btn:hover { background-color: #2980b9; } .dm-results { margin-top: 30px; padding: 20px; background-color: #fff; border-radius: 8px; border-left: 5px solid #3498db; display: none; } .dm-law-box { margin-bottom: 20px; padding: 15px; border-bottom: 1px dashed #eee; } .dm-law-box:last-child { border-bottom: none; } .dm-formula { font-family: "Courier New", Courier, monospace; font-weight: bold; color: #e67e22; background: #fdf2e9; padding: 4px 8px; border-radius: 4px; } .dm-val { font-weight: bold; color: #27ae60; } .dm-val-false { color: #e74c3c; } .dm-explanation-section { margin-top: 40px; line-height: 1.6; color: #333; } .dm-explanation-section h3 { color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 5px; } .dm-truth-table { width: 100%; border-collapse: collapse; margin: 20px 0; } .dm-truth-table th, .dm-truth-table td { border: 1px solid #ddd; padding: 10px; text-align: center; } .dm-truth-table th { background-color: #f2f2f2; }

De Morgan's Law Logic Calculator

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:

  1. 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.
  2. 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
TTFFEquivalent
TFTTEquivalent
FTTTEquivalent
FFTTEquivalent

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' }); }

Leave a Reply

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