Mathematics for Computer Science 201-N11 • CEGEP, Montreal

Revision sheet: Boolean and mathematical logic (201-N11)

Logic is the first course where an English sentence and a Boolean expression must say exactly the same thing. “If it rains, I take my umbrella” says nothing about what happens when it does not rain, and that is precisely what the truth table makes visible.

This sheet gathers the moves that earn marks in 201-N11: negating an implication without producing another one, applying De Morgan all the way, choosing between a truth table and the laws of Boolean algebra, and grouping in a Karnaugh map without inventing rectangles. It is written for CEGEP students in computer science programs; once it is read, the corrected exercise set on the same chapter puts every reflex to the test.

Mark this sheet as read or add it to your favourites: a free account, no password, keeps your read sheets and favourites from one visit to the next, tells you which chapter to tackle next and lets you ask for the method or exercise you are missing. Create your space, an email is enough.

The thread of the chapter

All the logic of the course comes down to the exact meaning of the implication: it is false in only one case, its contrapositive is equivalent to it, and its converse has nothing to do with it.

This chapter is part of 201-N11, Mathematics for Computer Science

The essentials

The implication is false in only one case

  • • p⇒qp\Rightarrow q is false ONLY on the row p=1p=1, q=0q=0. Everywhere else it is true.
  • • In particular, it is vacuously true as soon as pp is false: “if 2+2=52+2=5 then the Moon is square” is a TRUE implication.
  • • p⇒q=¬p∨qp\Rightarrow q=\lnot p\lor q, and therefore ¬(p⇒q)=p∧¬q\lnot(p\Rightarrow q)=p\land\lnot q: the negation of an implication is NOT an implication.
  • • A truth table with nn propositions has 2n2^{n} rows, and there are 22n2^{2^{n}} Boolean functions of nn variables.
pqp implies q111100011001
The only row where the implication is false is the one where the hypothesis is true and the conclusion false; the other three make it true.

Remember the false row rather than the three true ones: it is the only one to memorize, and every other question of the chapter comes back to it.

Contrapositive, converse, negation

  • • Contrapositive of p⇒qp\Rightarrow q: ¬q⇒¬p\lnot q\Rightarrow\lnot p. It is ALWAYS equivalent to it, and that is what justifies proof by contrapositive.
  • • Converse: q⇒pq\Rightarrow p. It has NO truth connection with the original: both can be true, both false, or one without the other.
  • • Negation: p∧¬qp\land\lnot q. It asserts the hypothesis and negates the conclusion, with no arrow at all.
p ⇒ qnot q ⇒ not pq ⇒ pnot p ⇒ not qequivalentequivalentstatement and contrapositive; converse and inverse
p⇒qp\Rightarrow q and its contrapositive ¬q⇒¬p\lnot q\Rightarrow\lnot p always have the same value; the converse q⇒pq\Rightarrow p is only worth what its own contrapositive is worth.

The quick test: the contrapositive swaps AND negates both sides, the converse only swaps them. Only one of the two is equivalent to the original statement.

The Boolean laws that really matter

  • • De Morgan: AB‾=A‾+B‾\overline{AB}=\overline{A}+\overline{B} and A+B‾=A‾ B‾\overline{A+B}=\overline{A}\,\overline{B}. The bar distributes while CHANGING the operator.
  • • Both distributive laws: A(B+C)=AB+ACA(B+C)=AB+AC, but also A+BC=(A+B)(A+C)A+BC=(A+B)(A+C), which has no counterpart in ordinary algebra.
  • • Absorption: A+AB=AA+AB=A and A(A+B)=AA(A+B)=A. Idempotence: AA=AAA=A and A+A=AA+A=A.
  • • Complement: A+A‾=1A+\overline{A}=1 and AA‾=0A\overline{A}=0.
ABAB
Absorption: the lens ABAB (orange) already lies inside AA (blue); adding it changes nothing, A+AB=AA+AB=A.

Absorption is the least used law and the most profitable one: it removes a whole term at once, where factoring only rearranges.

Quantifiers and normal forms

  • • ¬(∀x, P(x))=∃x, ¬P(x)\lnot(\forall x,\ P(x))=\exists x,\ \lnot P(x) and ¬(∃x, P(x))=∀x, ¬P(x)\lnot(\exists x,\ P(x))=\forall x,\ \lnot P(x): the quantifier flips, the property is negated.
  • • Canonical sum-of-products form: one term for each row where the function equals 11, with the variable COMPLEMENTED (barred) if it equals 00 on that row.
  • • Karnaugh map: groups are rectangles of 2k2^{k} cells, opposite edges are adjacent, and a group of 2k2^{k} cells eliminates kk variables.
10010000000010010000010111111010AB | CDa single group of four
In a Karnaugh map, opposite edges are adjacent: the four corners form a group of four cells, which eliminates two variables.

In a Karnaugh map, one group may overlap another: it costs nothing and often makes the groups larger. What costs marks is a group too small that could have been doubled.

The mistakes that cost marks

These are the errors I correct most often in session. Each one costs marks on a paper, even when the reasoning behind it is right.

1. Negating an implication with another implication

2 marks, and the proof by contradiction that follows starts from something false

What not to write

“¬(p⇒q)=p⇒¬q\lnot(p\Rightarrow q)=p\Rightarrow\lnot q.”

What to write

“¬(p⇒q)=p∧¬q\lnot(p\Rightarrow q)=p\land\lnot q: assert the hypothesis and negate the conclusion, with no arrow.”

pqnot(p implies q)p impliesnot q1100101101010001the two columns differ on the last two rows
The two columns agree only on the first two rows, where pp is true; on the last two, where pp is false, the wrong negation says the opposite of the right one.

Why: Negating “if pp then qq” means exhibiting a counterexample: a case where pp is true and qq false. An implication, on the other hand, would stay true as soon as pp is false.

2. Taking the converse for the contrapositive

2 marks, and it is the reasoning error most often penalized in the course

What not to write

“If a number is divisible by 44 then it is even; so if it is even then it is divisible by 44.”

What to write

“The contrapositive is: if it is not even, it is not divisible by 44. The converse is false: 66 is even without being divisible by 44.”

evendivisible by 44867
The multiples of 44 lie inside the even numbers: the implication and its contrapositive hold (the 77, outside the even numbers, is outside them too). The 66 (red) refutes the converse.

Why: The contrapositive swaps AND negates; the converse only swaps. Only the first keeps the truth value, and it is the one used in proofs.

3. Applying De Morgan without changing the operator

1.5 marks, and the whole simplification that follows

What not to write

“A+B‾=A‾+B‾\overline{A+B}=\overline{A}+\overline{B}.”

What to write

“A+B‾=A‾ B‾\overline{A+B}=\overline{A}\,\overline{B}: the bar distributes by turning the OR into an AND.”

ABnot (A or B)= not A and not BABnot (A and B)= not A or not B
The bar distributes while changing the operator: outside A∪BA\cup B means outside AA AND outside BB; outside A∩BA\cap B means outside AA OR outside BB.

Why: “Neither one nor the other” is not “not one or not the other”. The two-row test is enough: for A=1A=1 and B=0B=0, the first equals 00, the second would equal 11.

4. Forgetting the second distributive law

1 mark, and an expression twice as long as necessary

What not to write

“A+BCA+BC cannot be factored, so we leave it as it is.”

What to write

“A+BC=(A+B)(A+C)A+BC=(A+B)(A+C): in Boolean algebra, OR also distributes over AND.”

ABCA + BC = (A + B)(A + C)
The region AA plus the lens B∩CB\cap C is exactly the common part of A∪BA\cup B and A∪CA\cup C: A+BC=(A+B)(A+C)A+BC=(A+B)(A+C).

Why: It is the law with no counterpart in ordinary algebra, so the one nobody thinks of trying. It is mostly useful for bringing out an absorption.

5. Grouping three cells in a Karnaugh map

2 marks, and the expression obtained matches no circuit

What not to write

“These three adjacent cells equal 11, so I make them one group.”

What to write

“A group has 11, 22, 44 or 88 cells and forms a rectangle: I take one group of 22 and another group of 22 that overlap.”

group of 4: allowedgroup of 3: impossiblea group has 1, 2, 4 or 8 cellsnever 3, 5, 6 or 71111111
On the left, a square of four cells, which eliminates two variables; on the right, three cells in an L, which form no term and must be covered by two groups of two.

Why: Each doubling of a group's size eliminates exactly one variable. A group of three cells eliminates nothing at all; it matches no term.

6. Negating a quantifier without flipping it

2 marks, and the negated statement says something else entirely

What not to write

“The negation of “all the servers respond” is “no server responds”.”

What to write

“It is “there is at least one server that does not respond”: the ∀\forall becomes ∃\exists and the property is negated.”

Why: Negating a universal statement takes a single counterexample, not a complete reversal. “None” is the negation of “at least one”, not of “all”.

7. Writing a canonical form without complementing the zero variables

1.5 marks, and a term that equals 11 on the wrong row

What not to write

“The row A=1A=1, B=0B=0, C=1C=1 gives the term ABCABC.”

What to write

“It gives AB‾CA\overline{B}C: a variable that equals 00 on the row appears COMPLEMENTED in the term.”

Why: A term of the canonical form must equal 11 on ITS row and 00 everywhere else. Without the bar, it would equal 00 precisely on the row it is supposed to describe.

8. Rejecting a vacuously true implication

1.5 marks, and two rows of a truth table

What not to write

“pp is false, so p⇒qp\Rightarrow q makes no sense, nothing can be said.”

What to write

“When pp is false, p⇒qp\Rightarrow q is TRUE, whatever qq is: the promise has not been broken.”

Why: The implication claims nothing when its hypothesis is false. That is what makes true any property asserted “for every element” of an empty set.

9. Barring a single term under a NAND gate

2 marks, and the circuit drawn does not implement the required function

What not to write

“The output of a NAND gate is A‾⋅B\overline{A}\cdot B.”

What to write

“It is A⋅B‾\overline{A\cdot B}, that is A‾+B‾\overline{A}+\overline{B}: the bar covers the WHOLE product.”

ABright: not (A · B)ABwrong: not A · B
The bubble of a NAND is on the OUTPUT: it negates the whole product (green). A bubble on a single input (red) implements A‾⋅B\overline{A}\cdot B, a different function.

Why: The long bar is an operator in its own right: it is evaluated after the product. It is also what makes the NAND a universal gate, able to rebuild NOT, AND and OR on its own.

Which method to choose

Simplifying a Boolean expression

Look at the form of the expression, and at the number of variables.

  • If one term is contained in another, as in A+ABA+AB → absorption: the longer term disappears

    Example: A+AB=AA+AB=A

    it is the most profitable simplification, the one to look for first

  • If a bar covers a whole parenthesis → De Morgan, changing the operator at each step down

    Example: A+BC‾=A‾(B‾+C‾)\overline{A+BC}=\overline{A}(\overline{B}+\overline{C})

  • If a common factor appears in several terms → factor, then look for X+X‾=1X+\overline{X}=1

    Example: AB+AB‾=A(B+B‾)=AAB+A\overline{B}=A(B+\overline{B})=A

  • If three or four variables, and a truth table available → Karnaugh map, with groups of 2k2^{k} cells as large as possible

    Example: four minterms giving AB+AC+BCAB+AC+BC

  • If more than four variables → go back to the Boolean laws: the Karnaugh map becomes unreadable

    Example: five variables would give 3232 cells

A simplification is always CHECKED on the complete truth table: two equal expressions must agree on all 2n2^{n} rows, not only on the ones you looked at.

Negating a statement, piece by piece

Find the main connective, the one that structures the statement.

  • If the statement is an implication p⇒qp\Rightarrow q → its negation is p∧¬qp\land\lnot q, with no arrow

    Example: “if the badge is valid then the door opens” is negated by “the badge is valid AND the door does not open”

  • If the statement is a conjunction p∧qp\land q → ¬p∨¬q\lnot p\lor\lnot q

    Example: negating “tall and fast” gives “not tall or not fast”

  • If the statement is a disjunction p∨qp\lor q → ¬p∧¬q\lnot p\land\lnot q

    Example: negating “red or blue” gives “neither red nor blue”

  • If the statement begins with “for all” → “there is at least one... that does not...”

    Example: a single counterexample is enough to negate a universal statement

  • If the statement begins with “there exists” → “for all..., not...”

    Example: negating “there is a solution” requires ruling them all out

When several quantifiers follow one another, flip them one at a time, from left to right, without changing their ORDER: swapping a ∀\forall and an ∃\exists changes the statement.

How the answer is expected to be written

A marker ticks steps. Here they are in order, with the concluding sentence expected word for word.

Proving that two Boolean expressions are equivalent

When to use it: The question asks you to show an identity, or to check a simplification.

  1. 1 Choose the method and state it: complete truth table, or chain of laws.
  2. 2 By table: draw up the 2n2^{n} rows, one column per subexpression, and compare the two final columns.
  3. 3 By the laws: start from the MORE COMPLICATED side and transform it, naming the law used on each line.
  4. 4 Conclude with a sentence, recalling that the equality holds on every row.

Concluding sentence

“A+AB=A(1+B)=A⋅1=AA+AB=A(1+B)=A\cdot 1=A, by distributivity then by 1+B=11+B=1: the two expressions are equivalent.”

The trap: Transforming both sides at once and meeting in the middle without saying so: the work becomes unreadable and the marker can no longer follow the chain.

Marking: 1 mark for stating the method, 1 mark per law correctly named, 1 mark for the conclusion.

Translating a specification into a Boolean expression

When to use it: A problem describes in words the conditions for opening a door, triggering an alarm or validating an input.

  1. 1 Name each condition with a letter and write its meaning in full next to it.
  2. 2 Spot the words that carry the connectives: “and”, “or”, “unless”, “except if”, “only if”.
  3. 3 Write the complete truth table rather than guessing the expression.
  4. 4 Simplify with a Karnaugh map, then check on two chosen rows of the table.

Concluding sentence

“F=AB+AC+BCF=AB+AC+BC: the door opens when at least two of the three authorizations are present.”

The trap: Translating “AA only if BB” as B⇒AB\Rightarrow A: it is A⇒BA\Rightarrow B, the other way around.

Marking: 1 mark for the notation, 2 marks for the table, 1 mark for the simplification, 1 mark for the sentence that returns to the context.

Check before you hand in

Five minutes of checking recover more marks than one more problem started in a hurry.

The typical problem, taken apart

Access control: at least two authorizations out of three

A server room opens when at least two of the three managers AA, BB and CC have swiped their badges.

Draw up the truth table, write the canonical form, then simplify with a Karnaugh map.

badge Abadge Bbadge Cat least two?door
Three badges, one door: the output equals 11 as soon as at least two inputs equal 11, which the truth table will translate.

Step 1

Truth table: F=1F=1 on the rows 011011, 101101, 110110 and 111111, that is four rows out of eight.

Why

Draw up the table BEFORE guessing the expression: “at least two out of three” has no direct translation into connectives, and any attempt to write it down at once goes wrong.

Step 2

Canonical form: F=A‾BC+AB‾C+ABC‾+ABCF=\overline{A}BC+A\overline{B}C+AB\overline{C}+ABC.

Why

One term per row equal to 11, with the zero variables complemented. Four rows give four terms: the count can be checked at a glance.

Step 3

Karnaugh map: three groups of two cells, which overlap on the cell ABCABC.

00011110A = 0A = 1A | BCACAB00100111BC

Why

The overlap costs nothing and lets each group reach size 22. Refusing to overlap would leave groups of a single cell, hence terms with three variables.

Step 4

Reading the groups: F=AB+AC+BCF=AB+AC+BC.

Why

Each group of 212^{1} cells eliminates one variable, the one that changes inside the group. We go from four terms of three letters to three terms of two letters.

Step 5

Check on two rows: for A=1A=1, B=0B=0, C=0C=0, AB+AC+BC=0AB+AC+BC=0; for A=1A=1, B=1B=1, C=0C=0, it equals 11.

Why

One row at 00 and one row at 11 are enough to catch almost all grouping errors, in ten seconds.

Step 6

With NAND gates: F=AB‾⋅AC‾⋅BC‾‾F=\overline{\overline{AB}\cdot\overline{AC}\cdot\overline{BC}}.

Why

A sum of products is built with two levels of NAND gates, by double negation. This is the form required as soon as a circuit must be built with a single type of gate.

The conclusion, written out

“The access control function simplifies to F=AB+AC+BCF=AB+AC+BC: the door opens as soon as at least two of the three managers have swiped their badges.”

The classic mistake on this problem: Writing F=ABCF=ABC by reading “two out of three” as a conjunction, or grouping the three cells of the row A=1A=1 into a single group of three.

Learn by heart

  • • p⇒qp\Rightarrow q is FALSE only on the row p=1p=1, q=0q=0; it is vacuously true as soon as pp is false.
  • • ¬(p⇒q)=p∧¬q\lnot(p\Rightarrow q)=p\land\lnot q: the negation of an implication is not an implication.
  • • The contrapositive ¬q⇒¬p\lnot q\Rightarrow\lnot p is equivalent; the converse q⇒pq\Rightarrow p is not.
  • • De Morgan: the bar distributes while CHANGING the operator, in both directions.
  • • Absorption: A+AB=AA+AB=A and A(A+B)=AA(A+B)=A. Second distributive law: A+BC=(A+B)(A+C)A+BC=(A+B)(A+C).
  • • Negating a quantifier: ∀\forall becomes ∃\exists, and vice versa, while the property is negated.
  • • Karnaugh map: rectangles of 11, 22, 44 or 88 cells, opposite edges adjacent, and a group of 2k2^{k} cells eliminates kk variables.

Frequently asked questions

Why is an implication true when the hypothesis is false?

Because an implication promises something only in the case where its hypothesis comes true. If it does not come true, the promise has not been broken, so the statement is not false. This is what makes true any property asserted for all the elements of an empty set.

What is the difference between the contrapositive and the converse?

The contrapositive swaps the two sides and negates both of them; it is always equivalent to the original statement, which lets you prove one by proving the other. The converse merely swaps the two sides without negating them, and it has no truth connection with the original statement.

How do you negate an implication?

By asserting the hypothesis and negating the conclusion, with no arrow at all in the result. Negating means exhibiting a counterexample: a case where the hypothesis is true and the conclusion false. Writing another implication as the negation is the most frequent error of the chapter.

How many cells can a group contain in a Karnaugh map?

One, two, four or eight, and the group must form a rectangle, with opposite edges of the map counted as adjacent. Each doubling of the size eliminates one variable from the resulting term. A group of three cells matches no term and is never allowed.

Should you use a truth table or the laws of Boolean algebra?

The truth table always proves, but it gets long beyond three variables, with sixteen rows for four. The Boolean laws are faster when an absorption or a De Morgan step jumps out at you. For three or four variables, the Karnaugh map combines both advantages.

Practise it

Corrected exercises: Boolean and mathematical logic, 201-N11

A method is proved on a paper, not on a sheet. The set for the same chapter takes each of these traps into a problem, with the solution written out step by step.

  • 10 corrected exercises
  • 100 points
  • 150 minutes
Do the exercises
Something missing from this sheet? A method, a trap, an exercise to practise it, a mistake you spotted: tell me, I read every request.

Sending goes through your free space: that is how I can answer you and tell you when the exercise is added. An email is enough, no password. Create your space. Rather not create an account? Write to me directly.

What is it about?
I read every request myself, nobody else sees it. No need to write your name or your school.
When your request is dealt with, you hear about it by email and in your space.

By sending, you agree that I read your request to answer it. It is kept with your account, erased with it, and never published: privacy policy.

Next sheet Proof techniques

© Ahmed Squalli Houssaini. Revision sheet published at www.letuteurscientifique.ca/en/fiches/cegep-n11-boolean-logic. Free for personal and classroom use; republishing it elsewhere requires written permission (legal notice).

See also

Looking for a 201-N11 tutor in Montreal?

Get in touch for a first session. With a B.Sc. in computer science from McGill and an M.Sc. in applied computer science from Concordia, I teach Boolean logic the way you will use it next: in the conditions of a program, in database queries and in circuits.

Site by Studio Squalli