Lesson 6 of 15
De Morgan's Laws
De Morgan's Laws
De Morgan's laws are two identities that connect AND, OR, and NOT:
Law 1: NOT(A AND B) = NOT(A) OR NOT(B) Law 2: NOT(A OR B) = NOT(A) AND NOT(B)
These are essential for simplifying Boolean expressions and for circuit optimization. For example, a NAND gate directly implements Law 1.
Verifying Law 1
| A | B | NOT(A AND B) | NOT(A) OR NOT(B) |
|---|---|---|---|
| 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 |
Both columns are identical — the law holds for all inputs.
Your Task
Implement two functions:
deMorgan1(a, b)— computes NOT(A AND B) and NOT(A) OR NOT(B), then returns1if they are equal (law verified),0otherwisedeMorgan2(a, b)— same verification for Law 2: NOT(A OR B) vs NOT(A) AND NOT(B)
Print verification for all four input combinations for each law.
JavaScript loading...
Loading...
Click "Run" to execute your code.