No history yet

Logic and Truth

The Math of On and Off

Computers don't see the world in shades of gray. For them, everything is either on or off, true or false, 1 or 0. This is the core idea behind discrete mathematics, the math that powers the digital world. It's not about smooth curves and infinite possibilities; it's about distinct, separate values.

The basic unit of this world is a proposition. A proposition is just a statement that can be definitively labeled as either true or false. It can't be both, and it can't be a matter of opinion.

"The sky is blue" is a proposition. (True) "Pigs can fly" is a proposition. (False) "This movie is boring" is not a proposition, because it's an opinion.

This simple true-or-false structure is the foundation for all decision-making in computers. By linking propositions together, we can build complex logic from simple, two-state building blocks.

The Basic Logic Tools

To combine propositions, we use a few simple tools called logical operators. The three most fundamental are NOT, AND, and OR. Think of them as the grammar rules for the language of logic.

NOT

other

The NOT operator simply flips the truth value of a proposition. If a statement is true, NOT makes it false. If it's false, NOT makes it true.

The AND operator connects two propositions. The combined statement is only true if both individual propositions are true. Think about baking: a recipe might say you need flour AND sugar. If you only have one, the recipe won't work.

Lesson image

The OR operator also connects two propositions. The combined statement is true if at least one of the individual propositions is true. It could be one, or the other, or both. If a cafe offers you coffee OR tea, you can have either one and the offer is fulfilled.

We can map out all the possible outcomes for these operators using something called a truth table An 'A' or 'B' represents a proposition, T stands for True, and F for False.

ABA AND B
TTT
TFF
FTF
FFF
ABA OR B
TTT
TFT
FTT
FFF

Making Decisions with If-Then

One of the most common ways we use logic is through conditional statements, often phrased as "If..., then..." sentences. These statements connect a condition (the 'if' part) to a result (the 'then' part).

For example: "If it is raining, then I will take an umbrella."

The entire statement's truth depends on the relationship between the two parts. Logic has a specific way of evaluating this, which can sometimes feel a little strange. The only time an "If-Then" statement is considered false is when the 'if' part is true, but the 'then' part is false. In our example, this would mean it is raining, but I don't take an umbrella. That's a broken promise.

What if the 'if' part is false? For example, "If pigs fly, then the sky is green." In logic, this entire statement is considered vacuously true because the initial condition (pigs flying) is false. Since the condition never happened, the promise wasn't broken. This rule prevents us from getting stuck on absurd scenarios.

A (If...)B (Then...)If A, then B
TTT
TFF
FTT
FFT

Logic in Action

This might seem abstract, but it's exactly how simple programs make decisions. A computer doesn't understand "raining" or "umbrellas," but it can evaluate whether propositions are true or false. A weather app might use logic like this:

# This isn't real code, just an example of the logic.

# First, the computer checks the facts (propositions).
is_raining = True
is_cold = False

# Now, it evaluates a rule.
IF (is_raining is True AND is_cold is True):
  wear_a_raincoat()
ELSE IF (is_raining is True):
  take_an_umbrella()

The computer would check the first condition. Is is_raining true AND is_cold true? Since one is false, the whole AND statement is false. So, it skips to the next rule. Is is_raining true? Yes. So it runs the take_an_umbrella() command.

Every complex app on your phone is built on top of millions of these simple, lightning-fast logical decisions.

Now, let's test your understanding of these core concepts.

Quiz Questions 1/5

Which of the following is a proposition?

Quiz Questions 2/5

Let proposition P be "It is raining" and proposition Q be "I have an umbrella". The statement "P AND Q" is true only if...

By understanding propositions and the basic operators, you've learned the fundamental alphabet of computing. These simple rules are the building blocks for every decision a computer makes.