Why is "A only if B" equivalent to "(not A) or B"?

"A only if B" means that you can't have A without B, i.e. $\neg(A\wedge(\neg B))$, which simplifies (via de Morgan) to $(\neg A)\vee B$.


What you have encountered is a variation on vacuous truth. If the premise is false, then the statement is true. For instance, I can say "If I'm from Mars, then it will rain candy tomorrow", and that will be a true statement. It is true because it is not a lie. It could only be a lie if I really were from Mars, and at the same time it didn't rain candy tomorrow, and it is pretty safe to assume that this is not the case.

Similarily, we can have mathematical statements formulated in the same way. For a famous example, take

If there exists non-zero integers $a, b, c$ and a natural number $n>2$ such that $a^n+b^n = c^n$, then there exists a non-modular elliptic curve.

This statement was proven true a decade before Fermat's last theorem was proven (i.e. there are no such numbers $a, b, c, n$). In fact, the truth of the statement above was explicitly used to prove Fermat's last theorem, by showing that the conclusion was false (in other words, we have $\lnot B$), which forced the premise to be false (i.e. we must have $\lnot A$). This is exactly what $\lnot A\lor B$ means as well.

The fact that the above statement was used to prove Fermat's last theorem makes this a slightly circular example. However, we have since (probably) proven the $abc$-conjecture, which also implies Fermat's last theorem, so it's still viable.


Why is “A only if B” equivalent to “(not A) or B”?

Let's make it less abstract:

A = You can have your pudding
B = You eat your meat

So "A only if B" means "You can have your pudding only if you eat your meat".

How can you avoid having pudding but not eating meat? Either by not having pudding or by eating your meat. Hence $\neg A \lor B$.

It's my understanding that $A \rightarrow B$ means that if $A$ is true, then $B$ is true.

Correct. If we somehow find out that $A$ is true, we can be sure $B$ is true.

But, $\neg A \lor B$ would allow for us to have that $\neg A$ is true and $B$ is true, which seems to be pretty much that exact opposite of $A \rightarrow B$, so how can these be equivalent?

You're saying that you don't have any pudding even though you ate your meat somehow falsifies "if you don't eat your meat, you can't have any pudding". Nobody is saying that you must have pudding just because you ate meat.

If someone follows the rule "if you don't eat your meat, you can't have any pudding", then what we know is that if they had any pudding, they ate their meat. That is, "if you don't eat your meat, you can't have any pudding" is equivalent to "having any pudding implies you ate your meat".

This is perfectly consistent with you eating meat and not having pudding. This is perfectly consistent with you not eating meat and not having pudding. This is perfectly consistent with you eating meat and having pudding.

It is only violated if you have any pudding without eating any meat.