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

ABNOT(A AND B)NOT(A) OR NOT(B)
0011
0111
1011
1100

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 returns 1 if they are equal (law verified), 0 otherwise
  • deMorgan2(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.