#23 Mathematics
7 mins   /

Difference between "if" and "only if" in logic

The "if" and "only if" words might seem to imply the same thing in normal day-to-day English but it turns out that they express completely different things when seen under the light of logic.

In propositional logic, one of the most confusing aspects is that of the difference between "if" and "only if." Back when I learned propositional logic for the first time, I had some trouble in understanding it too.

In this article, I'll explain how "if" differs from "only if" with the help of a simple example and try adding more intuition to the reasoning with the help of the concept of a conditional's contrapositive.

Let's begin.

A simple example

We all know that if a shape is a square, then it's a rectangle by definition. Hence, you'd agree that the following is a true proposition:

If the shape is a square, then it's a rectangle.

What this statement is saying is that given the shape (whatever it is), if it's a square, it follows that it's a rectangle. Another way to write this statement in English is to switch the order of the premise and the conclusion. That is:

The shape is a rectangle if it's a square.

There's nothing difficult to understand thus far. But it's about to become that with the addition of just one word to this statement. Let's bring that on:

The shape is a rectangle only if it's a square.

Take a moment to let this statement soak in. Try to understand what it's trying to say and whether it's the same as the original conditional at the start of this section or not.

To begin with, it's NOT the same conditional. Let's find out how...

With the inclusion of the word "only," you're trying to say that there is only one case in which the shape is a rectangle and that is when it's a square. According to this statement, if the shape is not a square, then it certainly isn't a rectangle.

As you can reason based on the definition of a rectangle, this is totally wrong. For instance, the shape below is not a square, yet it's still a rectangle:

A rectangle

The correct statement is to say:

The shape is a square only if it's a rectangle.

Let's try dissecting this one too. Here, you're trying to say that there's only one case in which the shape is a square and that is when it's a rectangle. That's perfectly in line with the definition of a square, i.e. it is always a rectangle.

Note that this doesn't mean that the shape is a square always when it's a rectangle — there's simply no such claim being made in the statement. It's just saying that for the shape to be a square, it must be a rectangle.

Therefore, by reading this statement, you reason that if the shape is a square, then for sure it is a rectangle. Notice that this is basically the same proposition as the original one (at the start of this section).

But if this is a bit difficult to understand still, let's turn out attention to perhaps a more natural way of comprehending the "only if" construct — using the contrapositive.

Reasoning using the contrapositive

Consider the last "only if" statement above again:

The shape is a square only if it's a rectangle.

It's saying that the shape is a square only on one condition — that it's a rectangle. But another way to think of this is that if the shape is not a rectangle, then it's not a square.

If you're familiar with the idea of the contrapositive of a conditional ::p \to q::, this is precisely the contrapositive of the original statement. Let's see how by analyzing it under the light of a propositional expression.

Suppose the following:

::s: \text{The shape is a square}\\ r: \text{The shape is a rectangle}::

With this in place, the "only if" statement above becomes:

::\neg r \to \neg s::

That is, if the shape is not a rectangle, then it's not a square either. By the contrapositive law, this conditional is equivalent to the following:

::s \to r::

See how this is the original proposition stated at the start of this article. I personally find reasoning about the "only if" construct with the help of a contrapositive much more intuitive.

Bilal Adnan

Hi there! 👋 I'm the founder of Codeguage — basically the guy who's trying to make life easy for self-taught devs. You can follow me on LinkedIn or Medium to stay up-to-date with my conversations.