Logic and proofs — theory with a home alarm, truth tables that never lie and step-by-step proofs (and the alarm that went off with the door shut)
One October night, at 3:10 a.m., our home alarm started beeping with the front door shut, and it took me a while to understand that the alarm had not made a mistake: I had. I thought the rule was “if the door opens, it rings”. But the installer had set it up differently: it rings if the door opens or the hallway sensor detects motion, and night mode is on. The living-room fan moved a curtain, the sensor saw it and, since night mode was on, the alarm rang. All correct. The only thing that was wrong was the way I read the rule.
That rule is a compound proposition, and working out when it is true is exactly what this topic teaches. We will see what a proposition is, the six connectives (not, and, or, exclusive or, implication and biconditional), how to build a truth table column by column (the thing that comes up most in the problems exam), what tautologies, contradictions and contingencies are, logical equivalences and their laws, predicates and quantifiers and, in the second half, how to prove things: rules of inference, direct proof, proof by contrapositive, proof by contradiction, counterexamples and induction. It is the first topic of Discrete Mathematics and the foundation of everything else: the sets in topic 2 are logic in different clothes. After this theory you have the guided practice with the classroom problems solved step by step.
In a nutshell: propositional logic studies sentences that are true or false and how they combine with connectives (¬, ∧, ∨, →, ↔); a truth table gives the value of the combination in every case. Proofs chain valid steps (direct, contrapositive, contradiction, induction) to show that something is always true.
Table of Contents
What a proposition is
A proposition is a declarative sentence that is either true or false, but never both at once. Its value is called its truth value: true (T) or false (F). Simple propositions are named with lower-case letters: , , …
The home alarm has three simple propositions:
- : the door is open.
- : the sensor detects motion.
- : night mode is on.
At any given moment each of them is T or F. And are these sentences propositions?
| Sentence | Proposition? | Why |
|---|---|---|
| “Las Palmas is in Gran Canaria” | Yes | It is true |
| ““ | Yes | It is false (a proposition can be false) |
| “Did you lock the door?” | No | It is a question: neither T nor F |
| “Lock the door” | No | It is an order |
| ““ | No | It depends on : it is a predicate (more on that below) |
Thinking a proposition has to be true. “” is a perfectly good proposition: it is false. What it cannot be is ambiguous or dependent on something that has not been fixed.
The six connectives
From simple propositions we build bigger ones with connectives (or logical operators). There are six, and each one has its truth table:
- Negation, (“not “): flips the value. If the door is open, is F.
- Conjunction, (“ and “): T only if both are T.
- Disjunction, (“ or “): T if at least one is T. It is the inclusive or: it also holds when both are T.
- Exclusive or, (XOR): T if exactly one is T. It fails when both are T.
- Implication or conditional, (“if , then “): F only when is T and is F. is called the hypothesis (or premise) and the conclusion.
- Biconditional or double implication, (“ if and only if “): T when both have the same value.
The diagram deserves a minute. The tables of , and are symmetric: the order of and does not matter. The one for is not: it has a single F, in the T–F row, and in both rows where is F the implication is T. That asymmetry is the source of almost every mistake in the topic, so let’s look at it calmly.
Why “false implies anything” is true
Think of an implication as a promise. The installer told me: “if there is motion in night mode, the alarm rings”. When has he lied to me?
| There is motion | It rings | Has he kept the promise? |
|---|---|---|
| Yes | Yes | Yes |
| Yes | No | No: the only way to break it |
| No | Yes | Yes: he promised nothing about when there is no motion |
| No | No | Yes |
When there is no motion, the promise says nothing, so it cannot be broken: that is why and are true. Such an implication is called vacuously true.
If you get stuck on an implication, look for the only row that makes it false: hypothesis T and conclusion F. All the others are T.
Ways of saying “if p, then q”
In everyday language the implication comes in disguise, and that is where most mistakes happen when formalising:
| Sentence | Formula |
|---|---|
| if , then · if · whenever | |
| only if | |
| is sufficient for | |
| is necessary for | |
| unless | |
| if and only if · is necessary and sufficient for |
The trickiest one is “only if”. “The alarm rings only if night mode is on” does not say that in night mode it always rings; it says that, if it rings, night mode was on: .
What is sufficient goes to the left of the arrow and what is necessary, to the right. “Having the key is necessary to open the door” → .
The implication and its three variants
From we build three more:
- Converse: .
- Inverse: .
- Contrapositive: .
In the diagram, the diagonals join the ones with the same truth table. An implication is equivalent to its contrapositive (“if there is motion, it rings” says the same as “if it did not ring, there was no motion”), and the converse is equivalent to the inverse. But the converse does not say the same as the original: the alarm ringing does not mean there was motion (it also rings when the door opens). You will use this in proofs: proving is a valid way to prove .
| p | q | p → q | q → p | ¬p → ¬q | ¬q → ¬p |
|---|---|---|---|---|---|
| T | T | T | T | T | T |
| T | F | F | T | T | F |
| F | T | T | F | F | T |
| F | F | T | T | T | T |
Precedence and brackets
Just as multiplication goes before addition in arithmetic, the connectives have an order of priority:
| Connective | ¬ | ∧ | ∨ | → | ↔ |
|---|---|---|---|---|---|
| Priority | 1 (first) | 2 | 3 | 4 | 5 (last) |
So reads . Even so, in the exam and in your notes always write the brackets: they cost nothing and they prevent misreadings.
Truth tables, column by column
A truth table gives the value of a formula in every possible case. It is the main tool of the topic and what comes up most in the classroom problems, so here is the full method, using the real rule of my alarm:
As in the diagram, the formula is worked out from the inside out, like a circuit: first and then the conjunction with . The method, in four steps:
- Rows: with variables there are rows. With , and , .
- Order of the rows: the first variable alternates every rows (4 T and 4 F), the second every (2 T, 2 F…) and the last one, row by row. That way no combination is repeated or forgotten.
- Columns: one for each subformula, from the innermost to the outermost. It is the formula’s tree read from the bottom up.
- Each cell is filled in with the table of that column’s connective, looking only at the columns it depends on.
The table in the diagram, written out in full:
| p | q | r | p ∨ q | (p ∨ q) ∧ r |
|---|---|---|---|---|
| T | T | T | T | T |
| T | T | F | T | F |
| T | F | T | T | T |
| T | F | F | T | F |
| F | T | T | T | T |
| F | T | F | T | F |
| F | F | T | F | F |
| F | F | F | F | F |
The fifth row is my night: door shut ( F), the curtain moving ( T), night mode on ( T). The alarm rings. The row marked in the diagram is a quiet night: nothing open, nothing moving, night mode on. It does not ring. The rule works; what was wrong was my reading of it.
Skipping the intermediate columns to go faster. In the problems exam, one wrong cell in drags the error into the whole last column, and the answer you choose is the whole last column: either it is all right or it scores nothing.
Before filling in the last column, look at which values make it false (in a conjunction, one F is enough; in an implication, only T → F). Fill in those rows first, and the rest are T.
Tautology, contradiction and contingency
With the last column in front of you, a formula falls into one of three groups:
- Tautology: it is T in every row. For example, : if both are true, the first one is.
- Contradiction: it is F in every row. For example, : the door cannot be open and shut at the same time.
- Contingency: neither of the two; there are T rows and F rows. For example, or the alarm rule itself.
Two related ideas that come up in the classroom practicals:
- A formula is satisfiable if there is at least one row in which it is T. Every tautology and every contingency is satisfiable; only contradictions are not.
- A set of specifications is consistent if some assignment of values makes them all true at once. That is the same as saying that their conjunction is satisfiable. In the practice we check whether the alarm’s specifications are consistent.
The negation of a tautology is a contradiction, and vice versa. The negation of a contingency is still a contingency.
Logical equivalences
Two formulas are logically equivalent if they have the same truth value in every row. We write , which is the same as saying that is a tautology.
Using as if it were one more connective. It is not: is a formula that can be T or F; is a statement about two formulas (“they have the same table”), written outside them.
There are two ways to check an equivalence: build both tables and compare them column by column (it always works) or transform one into the other with the laws of logic, which are equivalences already proved. These are the ones in the course notes, with as “any tautology” and as “any contradiction”:
| Equivalence | Name |
|---|---|
| · | Identity |
| · | Domination |
| · | Idempotent |
| Double negation | |
| · | Commutative |
| · same with | Associative |
| Distributive ( over ) | |
| Distributive ( over ) | |
| · | De Morgan |
| · | Absorption |
| · | Negation |
And the ones with implications, which are the most useful for simplifying:
| Equivalence | What it is for |
|---|---|
| Removing arrows: the most important one | |
| Contrapositive | |
| Negating an implication | |
| Joining conclusions | |
| Joining hypotheses | |
| Removing the double arrow | |
| “Same value”, case by case | |
| Negating a biconditional |
An example with laws: negating the alarm rule
When does the alarm not ring? We have to negate and leave it with no negation in front of brackets:
It reads: it does not ring when the door is shut and there is no motion, or when night mode is off. Each step carries the name of the law that justifies it: that is how an equivalence proof is written.
Another classic, simplifying :
It makes sense: “the door is open and there is motion, or the door is open and there is none” is just “the door is open”.
To simplify, the order that almost always works is: remove arrows (), push the negations in with De Morgan until they only apply to letters, and then distributive, absorption and negation.
Connectives on bits
In a computer, T is 1 and F is 0, and the connectives are applied bitwise to strings of the same length: AND (), OR () and XOR (). That is what the &, | and ^ operators do in Python, C or Java. For example, with the sensors of a house with five zones:
| Zone 1 | 2 | 3 | 4 | 5 | |
|---|---|---|---|---|---|
| Motion | 1 | 0 | 1 | 1 | 0 |
| Armed zones | 1 | 1 | 0 | 1 | 0 |
| AND: alerts | 1 | 0 | 0 | 1 | 0 |
| OR | 1 | 1 | 1 | 1 | 0 |
| XOR | 0 | 1 | 1 | 0 | 0 |
The AND says which zones have motion and are armed: 1 and 4. It is exactly the alarm rule, applied in five places at once.
For the curious. From any truth table you can get an equivalent formula: take each T row, write the conjunction of its letters (negating the ones that are F) and join them all with . That is the disjunctive normal form (DNF). Doing the opposite with the F rows gives the conjunctive one (CNF). They are not in the course notes, but this topic’s simulator gives them to you, and they explain why , and are enough to write any formula.
Predicates and quantifiers
Sentences like “” or “sensor detects motion” are not propositions: their value depends on . They are predicates. We write : is the predicate (“detects motion”) and the variable (“the sensor”). When is given a value from the domain (the set of possible values), becomes a proposition. The part of logic that works with predicates is called predicate logic or first-order logic.
There is another way to turn a predicate into a proposition: quantifying it.
- Universal quantifier, : “for every in the domain, “. It is T if is T for all of them; one failure is enough to make it F.
- Existential quantifier, : “there is at least one with “. It is T if there is one; it is F only if is F for all of them.
If the domain is finite, , the quantifiers are long conjunctions and disjunctions:
With the five sensors in the house, S1 to S5, and : “sensor works”, “all the sensors work” is and “some sensor works” is .
Bound and free variables
In , is bound by the quantifier and is free. While any variable is free, the expression is not a proposition: it is missing a value.
Negating a quantifier
This is the rule that is asked about most. What does “it is not true that all the sensors work” mean? That at least one fails. And “there is no sensor that works” means that they all fail:
These are De Morgan’s laws for quantifiers: the diagram shows that, with a finite domain, they are the usual ones applied to the long conjunction and disjunction.
Negating “all the sensors work” as “no sensor works”. That is going too far: one failure is enough. The negation of “all” is “not all”, that is, “some do not”.
Nested quantifiers
One quantifier can sit inside another: says that every number has an opposite. Here the order matters:
- over the integers: T. For each , can be different ().
- : F. It would say that there is a single that works for every at once.
To negate several, the negation goes through them one by one, flipping each quantifier: .
Read as “you pick and I answer with a “, and as “I pick first and it has to work against anything you say”. The second is far more demanding.
Rules of inference: the valid steps
An argument is a list of hypotheses and a conclusion . It is valid (or correct) if, whenever all the hypotheses are true, the conclusion is true as well; in other words, if
is a tautology. Checking it with a -row table is slow, so we chain rules of inference, which are small arguments already proved:
| Rule | From… | we deduce… | Tautology |
|---|---|---|---|
| Modus ponens | , | ||
| Modus tollens | , | ||
| Hypothetical syllogism | , | ||
| Disjunctive syllogism | , | ||
| Addition | |||
| Simplification | |||
| Conjunction | , | ||
| Resolution | , |
An example with the alarm. Hypotheses: “if the alarm rings, I wake up” (), “if I wake up, I go down to the living room” () and “the alarm has rung” (). By hypothetical syllogism, ; by modus ponens with , : I go downstairs.
And the versions with quantifiers, used to go from “all” to “this one” and back:
| Rule | From… | we deduce… |
|---|---|---|
| Universal instantiation | for a particular | |
| Universal generalisation | for an arbitrary | |
| Existential instantiation | for some | |
| Existential generalisation | for some |
The two classic fallacies look like rules but are not. Affirming the consequent: from and concluding (“if there is motion it rings; it rang; so there was motion”: false, it could have been the door). Denying the antecedent: from and concluding . Both fail for the same reason: mixing up an implication with its converse or its inverse.
Proof methods
A theorem is a statement that has been proved true; a proof is the chain of valid steps that establishes it from axioms, definitions and earlier theorems. Along the way you meet a lemma (a simpler auxiliary result), a corollary (something that follows directly from a theorem) and a conjecture (something believed true but not yet proved).
Almost every theorem has the form (or ), and there are several ways to attack it:
In the examples I use the usual definitions: is even if for some integer , and odd if .
Direct proof
Assume is true and, with definitions and valid steps, reach . Since is only false when is T and is F, if always leads to , that row cannot happen.
Theorem. If is odd, is odd.
Proof. If is odd, . Then , which has the form with an integer. So is odd. ∎
By contrapositive (indirect proof)
Since , you can prove the contrapositive. It is used when the hypothesis gives little to work with and its negation gives more.
Theorem. If is even, is even.
Going straight at it is awkward: from you cannot see what looks like. The contrapositive is “if is not even (it is odd), is not even (it is odd)”, which is exactly the previous theorem. ∎
By contradiction
Assume the opposite of what you want to prove and reach a contradiction (something both T and F). For , assume and look for the clash.
Theorem. is not rational.
Proof. Suppose it is: with and integers with no common factors. Squaring, , so is even and, by the previous theorem, is even: . Substituting, , that is, : is even too. But then and have the factor 2 in common, against our assumption. Contradiction: is not rational. ∎
Vacuous, trivial and case-by-case proofs
- Vacuous: if you show that the hypothesis is false, is true without looking at (rows anything). Example: “if is an integer with , then ” is true, because no integer meets the hypothesis.
- Trivial: if you show that the conclusion is true, is true without looking at .
- By cases: if the hypothesis is , prove each separately, because . Example: “ is even” is proved with even and with odd.
Existence proofs and counterexamples
For a statement :
- Constructive: give a concrete that satisfies . “There is an integer that is a sum of two squares in two different ways”: .
- Non-constructive: show that one exists without saying which, usually by contradiction.
And to knock down a one counterexample is enough: a single in the domain with false, because . “Every number of the form is prime” sounds fine until : .
“proving” a with examples. That is prime for proves nothing about every . Examples are only good for refuting a (counterexample) or for proving an .
Induction
To prove that a property holds for every integer , examples do not work (there are infinitely many) and a direct proof often gets stuck. Mathematical induction solves it in two steps:
- Base case: prove (or the first value of the domain).
- Inductive step: prove that, for any , . is called the induction hypothesis.
It is like the diagram: if the first domino falls and each domino knocks over the next, they all fall. What holds it up is the well-ordering property: every non-empty set of non-negative integers has a smallest element. If failed for some , there would be a first failure , and since does hold, the inductive step would give : a contradiction.
Theorem. For every , .
Base case (): on the left, 1; on the right, . They match.
Inductive step. Assume : . We want to reach , which is . Start from the left and use the hypothesis on the first terms:
which is exactly . By induction, it holds for every . ∎
Quick check with : and .
In the inductive step, first write what you want to get ( with the formula) and then look, inside the expression for , for the piece that is . That is the moment to use the hypothesis; if you do not use it anywhere, the proof is not by induction.
Skipping the base case because “it is obvious”. Without it you can “prove” anything: “” passes the inductive step (if , adding 1 gives ) and is false for every .
Check it with Python
A truth table is a loop over the combinations. With itertools.product they come out in the same order as on paper (starting with T), and the implication is written as (not a) or b, which is exactly the equivalence . This program prints the alarm’s table, classifies it and checks one of the equivalences from the theory:
from itertools import product
def implies(a, b): # p -> q is the same as (not p) or q
return (not a) or b
def alarm(p, q, r): # the installer's rule
return (p or q) and r
def tf(x): # True/False -> T/F, as on paper
return "T" if x else "F"
print(" p q r | p∨q | (p∨q)∧r")
last = []
for p, q, r in product([True, False], repeat=3): # 2^3 = 8 rows
s = alarm(p, q, r)
last.append(s)
print(f" {tf(p)} {tf(q)} {tf(r)} | {tf(p or q)} | {tf(s)}")
if all(last):
print("tautology")
elif not any(last):
print("contradiction")
else:
print("contingency:", last.count(True), "T rows out of", len(last))
# is not((p∨q)∧r) equivalent to (¬p∧¬q)∨¬r? Compare the 8 rows
eq = all((not alarm(p, q, r)) == ((not p and not q) or not r)
for p, q, r in product([True, False], repeat=3))
print("De Morgan checked:", eq)
Output:
p q r | p∨q | (p∨q)∧r T T T | T | T T T F | T | F T F T | T | T T F F | T | F F T T | T | T F T F | T | F F F T | F | F F F F | F | F contingency: 3 T rows out of 8 De Morgan checked: True
What to look at:
- The rows come out in paper order:
product([True, False], repeat=3)changes the last variable first, just like the table above. - The last column has 3 T out of 8: the alarm is a contingency. The three T rows are the ones with T and at least one of or T.
all(...)andany(...)are Python’s quantifiers:allis andanyis over the rows.- The final equivalence is the negation with De Morgan we did by hand: comparing the eight rows is exactly the definition of .
In the “Truth table and equivalences” simulator you type any proposition (with the symbols or with the keyboard) and it builds the table column by column, subformula by subformula, tells you whether it is a tautology, a contradiction or a contingency, and checks whether two formulas are equivalent. It is the best way to check your tables from the exercises.
Summary
| Concept | What it is | How to recognise or use it |
|---|---|---|
| Proposition | Sentence that is T or F, not both | No free variables, no questions or orders |
| F only if T and F | Sufficient on the left, necessary on the right | |
| Contrapositive | Equivalent to ; the converse is not | |
| Truth table | Value in the rows | One column per subformula, inside out |
| Tautology / contradiction / contingency | All T / all F / mixed | Look at the last column |
| Same table | Tables or laws (De Morgan, distributive…) | |
| One counterexample is enough | ||
| Valid argument | a tautology | Modus ponens, tollens, syllogisms |
| Proof | Direct, contrapositive, contradiction, cases | Pick according to what the hypothesis gives |
| Induction | Base case + | For over the integers |
Three ideas to take away:
- An implication is false in only one row (T → F). Almost every mistake in the topic, from “only if” to the fallacies, comes from forgetting it or from mixing it up with its converse.
- A well-built truth table is mechanical: rows in the usual order and one column per subformula. The last column decides whether it is a tautology, a contradiction or a contingency, and two formulas are equivalent if their last columns match.
- Proving is chaining valid steps. If the hypothesis gives you nothing, try the contrapositive or a contradiction; if the statement is about every , induction, and if it is false, one counterexample is enough.
Now it is your turn: in the logic and proofs guided practice we solve the classroom problems step by step (formalising, truth tables, equivalences, quantifiers, proofs and a table in the exam’s format), each one checked with Python. And to check you have got it, the logic and proofs exercises go from easy to hard and come with commented solutions and a theory quiz like the ones on the Campus.
Next step: practiceLogic and proofs — guided practice with the alarm’s rules, eight-row truth tables and an induction that falls like dominoes (and the table I handed in with a row missing)Did this article help you? Here is how you can support SergioLearns →


