Formula Bro

Math and physics formulas, explained like you are new.


De Morgan's Laws

In one sentence: De Morgan’s laws say that a NOT in front of a group of AND or OR conditions flips the group: AND becomes OR, and OR becomes AND.

¬(A∧B)=¬A∨¬B¬(A∨B)=¬A∧¬B\neg(A \land B) = \neg A \lor \neg B \qquad \neg(A \lor B) = \neg A \land \neg B

Read it out loud: “Not, open bracket, A and B, close bracket, equals not A or not B. And not, open bracket, A or B, close bracket, equals not A and not B.”

What each symbol means

SymbolMeaning

AA

A statement that is either true or false, such as “it is raining”.

BB

A second statement that is either true or false, such as “it is cold”.

¬\neg

NOT. It flips a statement: true becomes false and false becomes true.

∧\land

AND. The result is true only when both statements are true.

∨\lor

OR. The result is true when at least one of the statements is true.

What the formula is doing

Programmers write conditions with three words: NOT, AND and OR. A condition such as not (raining and cold) can be hard to read at a glance. De Morgan’s laws give an equal form that is often easier to understand or to code.

The first law reads: NOT (A AND B) means the same as (NOT A) OR (NOT B). The NOT moves inside the bracket and the AND turns into an OR. The second law works the other way: NOT (A OR B) equals (NOT A) AND (NOT B), so the OR turns into an AND.

The reason is plain English. “Not both” means at least one of them fails, which is the same as saying “at least one is not true”. “Not either” means neither one holds, which means both are not true.

The laws hold for every combination of true and false. You can check that with a truth table that lists all four combinations of A and B, which the example does. Both sides agree in every row, so the two forms are the same condition.

An everyday picture

Think of a club rule: you get in only if you are a member and you are over 18. Being turned away means you are not a member, or you are not over 18. Saying “not both” in the rule turns into “at least one missing” when you turn it around. That is De Morgan’s first law in everyday words.

Worked example: Rewriting a rain-and-cold rule in code

A park app runs a walking tour when ¬(A∧B)\neg(A \land B) is true. Here AA means it is raining and BB means it is cold. So the tour runs unless it is both raining and cold.

  1. Apply the first law: ¬(A∧B)=¬A∨¬B\neg(A \land B) = \neg A \lor \neg B. In words, the tour runs when it is not raining, or it is not cold.
  2. In code, if not (raining and cold): becomes if (not raining) or (not cold):. Both lines give the same answer every time.
  3. Row 1, not raining and not cold (AA false, BB false): left side ¬(F∧F)=¬F=T\neg(F \land F) = \neg F = T. Right side ¬F∨¬F=T∨T=T\neg F \lor \neg F = T \lor T = T. They match.
  4. Row 2, not raining and cold (AA false, BB true): left side ¬(F∧T)=¬F=T\neg(F \land T) = \neg F = T. Right side ¬F∨¬T=T∨F=T\neg F \lor \neg T = T \lor F = T. They match.
  5. Row 3, raining and not cold (AA true, BB false): left side ¬(T∧F)=¬F=T\neg(T \land F) = \neg F = T. Right side ¬T∨¬F=F∨T=T\neg T \lor \neg F = F \lor T = T. They match.
  6. Row 4, raining and cold (AA true, BB true): left side ¬(T∧T)=¬T=F\neg(T \land T) = \neg T = F. Right side ¬T∨¬T=F∨F=F\neg T \lor \neg T = F \lor F = F. They match.

Answer: The two forms are the same rule. The tour runs in three of the four weather cases and is off only when it is both raining and cold. Both versions of the code give that same result in all four cases, so you can pick whichever one reads more clearly.

The numbers in this example are recomputed by script every time the site is built.

Common mistakes

Where you will meet it

Questions people ask

What is the difference between AND and OR?

AND is true only when both parts are true. OR is true when at least one part is true. For example, “has a ticket AND is over 12” needs both, while “has a ticket OR has a pass” needs only one.

Why are they called De Morgan's laws?

They are named after Augustus De Morgan, a British mathematician of the 1800s who described them in his work on formal logic.

Do the laws work for more than two statements?

Yes. NOT (A AND B AND C) equals NOT A OR NOT B OR NOT C, and the same pattern works for OR. Each NOT flips one statement and the operator flips too.

Sources

  1. De Morgan's laws, Wikipedia
  2. Truth table, Wikipedia

| All Computer Science formulas |

Published 2026-10-22. Plain-text copy for AI agents and readers: computer-science/de-morgans-laws.md.