Propositional Logic | Conditional Statements

Jacob Pelletier
6 min readSep 8, 2021

My discrete mathematics course and explained through CS concepts, once and for all settling the age-old question “When will I ever need this?”.

Acknowledgements: A big thanks to Central Connecticut State University Math Department for great course notes and my Professor for being a great teacher! ✌️

Some basic knowledge of Python might be helpful but is not required.

Propositional Logic | Conditional Statements

Previous lesson on propositions here.

Definition 1.8:

Let p and q be propositions. The conditional statement p → q is the proposition “if p, then q”. p is called the hypothesis, and q is called the conclusion. A conditional statement is also called an implication. There is nothing special about p and q, they are simply placeholders for the concept of some hypothesis and conclusion. You can replace them with a word like “popsicle” or a picture of 💩 if you want!

Example 1.8.a.

If my alarm goes off, then I will wake up.

⏰ → 🥱

(Hypothesis): My alarm goes off.

🥱 (Conclusion): I will wake up.

Example 1.8.b.

If 0 < x < 1, then x² < x

🧀 → 🐭

🧀 (Hypothesis): 0 < x < 1

🐭 (Conclusion): x² < x

Example 1.8.c.

Your mom says she will buy you that new Korean MMORPG you have been wanting if you get all A’s this semester 🥳. In which circumstances, if any, would your mom be a dirty liar?

Here are the steps we would take to answer this question.

  1. Deconstruct the conditional statement. What is the hypothesis and what is the conclusion?

Hypothesis (p): I will get all A’s.

Conclusion (q): My mom will buy me the game.

2. For each possible truth value of p and q (TT, TF, FT, FF), write a conjunction in words using p and q. Then decide which cases would make your mom a liar. Hint: Your mom is a liar when q does not follow p.

3. Fill in the truth table

Why is this the case? Let us discuss.

In row 1, both the hypothesis and the conclusion are true, thus the conditional statement is also true. In other words, a true p(if you get all A’s) then a true q (your mom bought you the game) makes the statement p → q also true (if you get all A’s then your mom will buy you the game).

In row 2, the hypothesis is true but the conclusion was false, thus the conditional statement is false. In other words, a true p (you got all A’s) and a false q (your mom did not buy you the game) will make the statement p → q false, because q did not follow p. You studied hard to get A’s in order to get that game, but your mom did not buy it for you.

In row 3, the hypothesis is false and the conclusion is true. This is strange because even though you did not get all A’s (a false p), your mom still bought you the game you wanted (a true q). q still followed even though p was false, but this does not invalidate the conditional statement “if you get all A’s your mom will buy you that game”, because there may be another reason that your mom bought you the game. This is said to be vacuously true.

In row 4, the hypothesis and the conclusion are both false. You did not get all A’s, and your mom did not buy you that game. Maybe if you studied harder next time you can validate the conditional statement, but for now, this conditional statement remains vacuously true as well.

Side Note 1.8.d.

There are different ways to express conditional statements.

Exercise 1.8.e.

Rewrite the following statements in the form of “If. . . then”.

  1. Whenever I drink coffee I have a bowel movement.
  2. There is always traffic when I am on the road.
  3. I do not have class on Mondays.

How does this relate to CS?

This logical thinking is what underpins conditional statements in a programming language, like say, Python. There are many ways to say → in plain English, for example:

  • q if p,
  • p implies q,
  • p only if q,
  • q whenever p,
  • q follows p,
  • p is sufficient for q,
  • q whenever p.

This is a conditional statement in plain English.

If this, then that.

or . . .

This implies that

or . . .

If this hypothesis is true, then this conclusion is true.

or . . .

p → q

which translates into Python like . . .

This kind of thinking is very fundamental to programming (in all applications or languages). Conditional statements and booleans (True or False values) allow for programs to have a control structure and branched decision making which allows programs to be more dynamic (rather than being a single linear logical sequence of steps to be executed).

Simple conditional statements in Python come in different flavours.

If (some condition), then (some effect). If the first “if” statement is not true, i.e. that some condition is not true, then the logical flow of the program will continue to read these conditional (if, elif, else) statements in sequential order. Thus, the statement under the else clause will only be executed if the first if statement is false, and will never execute if the first statement is true.

“Elif” is short for “else if” and is exactly like if but is used to chain multiple if statements together to evaluate for multiple conditions.

“Else” is simply a catch-all which tells the program what to do if no conditions are met.

Note that a series of “if-elif-elif-elif-etc” will behave differently than a series of “if-if-if-if-etc” statements. If any of the “if-elif” statements or “if-else” and “if-elif-else” statements for that matter are evaluated as true, the remaining statements are not evaluated and executed. In a chained “if” statement situation, all if statements are evaluated and their code potentially executed.

Tired of all this math and looking to get down and dirty with Python? I recommend this site for quickly learning new tech skills (they are not a sponsor).

Challenge problem! If you read the previous lesson, try this out:

The solution will be posted in the next lesson.

Here is our order of operations for our logical symbols so far!

  1. not
  2. and
  3. or
  4. implies

Good Job! Important things we learned so far:

  1. What a conditional statement is and how to read and write them
  2. We can now recognize simple conditionals in Python.

More reading:

  1. https://www.mathbootcamps.com/truth-tables-conditional-biconditional-implies-iff/

About Me

I am a lifelong learner and student debt masochist. I graduated with a bachelor’s degree in nursing and I am currently working as a nurse for hospitals big and small. Currently, I am working on a bachelor’s in computer science. I enjoy cooking, being outside, and thinking about stuff.

--

--