CSE 311 Lecture 01: Propositional Logic

Emina Torlak and Kevin Zatloukal

Topics

About CSE 311
What you will learn and why!
Course logistics
A quick summary now; details on the course webpage.
Propositional logic
A language of reasoning

About CSE 311

What you will learn and why!

Learn the calculus of computation

CSE 311 logo

Logic
How do we describe ideas precisely?
Formal proofs
How can we be sure we’re right?
Number theory
How do we keep data secure?
Relations
How do we organize information?
Finite state machines
How do we design hardware and software?
Turing machines
Are there problems computers can’t solve?

And become a better programmer!

By the end of the course, you will have the key technical tools to …

  • reason about difficult problems;
  • automate difficult problems;
  • communicate ideas, methods, and objectives;
  • understand fundamental structures for computer science.

Course logistics

A quick summary now; details on the course webpage.

Instructors: cse311-staff@cs

Emina Torlak
Section A: MWF 09:30-10:20 in SIG 134
Office hours: W 10:30-11:30 in CSE 596

Kevin Zatloukal
Section B: MWF 13:30-14:20 in JHN 102
Office hours: MF 12:45-13:15 in CSE 212

Afternoon section will be recorded

TAs: cse311-staff@cs

  • Philip Garrison
  • Kush Gupta
  • Sarvagya Gupta
  • Siddharth Iyer Vaidynathan
  • Weihan (Joy) Ji
  • Benjamin Lee
  • Benjamin MacMillan
  • Aishwarya Nirmal
  • Zhiheng (Frank) Qin
  • Aditya Saraf
  • Oscar Sprumont
  • Jason Waataja

Textbook, homework, exams, and grading

Optional textbook
Rosen, Discrete Mathematics and Its Applications, 6th Edition, McGraw-Hill.
Homework
Due Wednesday at 23:59 online
Write up individually
Exams
Midterm exam on Wed, Nov 07 in class
Final exam on Mon, Dec 10 at 14:30-16:20 and 16:30-18:20
Grading
Homework: 50%
Midterm: 15-20%
Final: 30-35%
Piazza discussion board
opt out of “careers”

About grades

You may find this hard to accept…

Your grades are a lot less important than you think going forward
(whether into industry or grad school)

Your understanding of CS will be a lot more important than you think

Questions of the form “will I lose points if…”

  • are not worth your time (or mine)
  • your TAs will decide this anyway
  • if you are really worried, then show more work

You are not in competition with your classmates.

Propositional logic

A language of reasoning

What is logic and why do we need it?

Logic is a language, like English or Java, with its own

  • words and rules for combining words into sentences (syntax), and
  • a way to assign meaning to words and sentences (semantics).

So why learn another language when we know English and Java?

Why not use English?

Turn right here.
Does “right” mean the direction or now?
We saw her duck.
Does “duck” mean the animal or crouch down?
Visiting relatives can be fun.
Is the visit fun or the relatives who are visiting?

Natural language can be imprecise.

Why not use Java?

The following method determines …

public static boolean mystery(int x) {
    for(int r = 2; r < x; r++) {
        for(int q = 2; q < x; q++) {
            if (r*q == x) {
                return false;
            }
        }
    }
    return (x > 1);
}

… if its input is a prime number.

Programs can be verbose and take a while to understand.

Logic is both precise and concise!

We need a language of reasoning to

  • state sentences more precisely,
  • state sentences more concisely, and
  • understand sentences more quickly.

Propositions: the basic building blocks of logic

A proposition is a statement that is either true or false.

All cats are mammals.
This is a true proposition.
All mammals are cats.
This is a false proposition.

Are these propositions?

2 + 2 = 5
This is a proposition that is false.
x + 2 = 5
Not a proposition because it doesn’t have a unique truth value.
Who are you?
Not a proposition because it’s a question rather than a statement.
Pay attention.
Not a proposition because it’s a command rather than a statement.
Every positive even integer can be written as the sum of two primes.
This is a proposition. Nobody knows its truth value, but it’s unique!

Abstracting atomic propositions with variables

Propositional variables represent atomic propositions (“words”).

By convention, we use lower-case letters for these variables: $p, q, r$, …

Variable Proposition
$p$ “Garfield has black stripes.”
$q$ “Garfield is an orange cat.”
$r$ “Garfield likes lasagna.”

The truth value of a propositional variable is either

  • $\mathsf{T}$ for true, or
  • $\mathsf{F}$ for false.

Making compound propositions with logical connectives

We combine atomic propositions into compound propositions (“sentences”) using logical connectives.

Here is a compound proposition about Garfield:

Garfield has black stripes if he is an orange cat and likes lasagna, and he is an orange cat or does not like lasagna.

Let’s see how to express it in logic using our atomic propositions:

  • $p$ = “Garfield has black stripes.”
  • $q$ = “Garfield is an orange cat.”
  • $r$ = “Garfield likes lasagna.”

From English to logic

Garfield has black stripes if he is an orange cat and likes lasagna, and he is an orange cat or does not like lasagna.

  • $p$ = “Garfield has black stripes.”
  • $q$ = “Garfield is an orange cat.”
  • $r$ = “Garfield likes lasagna.”

$\downarrow$ Step 1: abstract

($p$ if ($q$ and $r$)) and ($q$ or (not $r$))

$\downarrow$ Step 2: replace English connectives with logical connectives

Logical connectives

Connective Write as Read as True when
Negation $\neg p$ “not $p$” $p$ is false
Conjunction $p \wedge q$ “$p$ and $q$” both $p$ and $q$ are true
Disjunction $p \vee q$ “$p$ or $q$” at least one of $p,q$ is true
Exclusive Or $p \oplus q$ “either $p$ or $q$” exactly one of $p,q$ is true
Implication $p \rightarrow q$ “if $p$ then $q$” $p$ is false, or both $p,q$ are true
Biconditional $p \leftrightarrow q$ “$p$ if and only if $q$” $p,q$ have the same truth value

($p$ if ($q$ and $r$)) and ($q$ or (not $r$))

(($q$ $\wedge$ $r$) $\rightarrow$ $p$) $\wedge$ ($q$ $\vee$ ($\neg$ $r$))

Understanding logical connectives with truth tables

Connective Write as Read as True when
Negation $\neg p$ “not $p$” $p$ is false
Conjunction $p \wedge q$ “$p$ and $q$” both $p$ and $q$ are true
Disjunction $p \vee q$ “$p$ or $q$” at least one of $p,q$ is true
Exclusive Or $p \oplus q$ “either $p$ or $q$” exactly one of $p,q$ is true
$p$ $\neg p$
$\mathsf{T}$
$\mathsf{F}$
$p$ $q$ $p \wedge q$
$\mathsf{F}$
$\mathsf{F}$
$\mathsf{F}$
$\mathsf{T}$
$p$ $q$ $p \vee q$
$\mathsf{F}$
$\mathsf{T}$
$\mathsf{T}$
$\mathsf{T}$
$p$ $q$ $p \oplus q$
$\mathsf{F}$
$\mathsf{T}$
$\mathsf{T}$
$\mathsf{F}$

Understanding implication with a truth table

Connective Write as Read as True when
Implication $p \rightarrow q$ “if $p$ then $q$” $p$ is false, or both $p,q$ are true
$p$ $q$ $p \rightarrow q$
$\mathsf{T}$
$\mathsf{T}$
$\mathsf{F}$
$\mathsf{T}$

Understanding implication as promises

It’s useful to think of implications as promises. That is “Did I lie?”

If it’s raining, then I have my umbrella.

$p$ $q$ $p \rightarrow q$
$\mathsf{T}$
$\mathsf{T}$
$\mathsf{F}$
$\mathsf{T}$
  It’s raining It’s not raining
I have my umbrella Truth Truth
I don’t have my umbrella Lie Truth

The only lie is when:

  • It’s raining AND
  • I don’t have my umbrella

Understanding implication: it’s not causal!

$p$ $q$ $p \rightarrow q$
$\mathsf{T}$
$\mathsf{T}$
$\mathsf{F}$
$\mathsf{T}$

Are these true?

2 + 2 = 4 $\rightarrow$ earth is a planet
The fact that the atomic propositions “2 + 2 = 4” and “earth is a planet” are unrelated doesn’t matter! Both are true, so the implication is true as well.
2 + 2 = 5 $\rightarrow$ 26 is prime
Again, the atomic propositions may or may not be related. Because “2 + 2 = 5” is false, the implication is true. Whether 26 is prime or not is irrelevant.

Understanding implication forward and backward

  1. I have collected all 151 Pokémon if I am a Pokémon master.
  2. I have collected all 151 Pokémon only if I am a Pokémon master.

These sentences are implications in opposite directions:

  1. Pokémon masters have all 151 Pokémon.
  2. People who have 151 Pokémon are Pokémon masters.

So, the implications are:

  1. If I am a Pokémon master, then I have collected all 151 Pokémon.
  2. If I have collected all 151 Pokémon, then I am a Pokémon master.

Understanding implication some more

$p$ $q$ $p \rightarrow q$
$\mathsf{T}$
$\mathsf{T}$
$\mathsf{F}$
$\mathsf{T}$
  • $p$ implies $q$
  • whenever $p$ is true $q$ must be true
  • if $p$ then $q$
  • $q$ if $p$
  • $p$ is sufficient for $q$
  • $p$ only if $q$
  • $q$ is necessary for $p$

Understanding biconditional (bi-implication)

Connective Write as Read as True when
Biconditional $p \leftrightarrow q$ “$p$ if and only if $q$” $p,q$ have the same truth value
$p$ $q$ $p \leftrightarrow q$
$\mathsf{T}$
$\mathsf{F}$
$\mathsf{F}$
$\mathsf{T}$
  • $p$ iff $q$
  • $p$ is equivalent to $q$
  • $p$ implies $q$ and $q$ implies $p$
  • $p$ is necessary and sufficient for $q$

Now back to understanding our Garfield sentence …

Garfield has black stripes if he is an orange cat and likes lasagna, and he is an orange cat or does not like lasagna.

  • $p$ = “Garfield has black stripes.”
  • $q$ = “Garfield is an orange cat.”
  • $r$ = “Garfield likes lasagna.”

$\downarrow$ Step 1: abstract

($p$ if ($q$ and $r$)) and ($q$ or (not $r$))

$\downarrow$ Step 2: replace English connectives with logical connectives

(($q$ $\wedge$ $r$) $\rightarrow$ $p$) $\wedge$ ($q$ $\vee$ ($\neg$ $r$))

Understanding Garfield with a truth table

$p$ $q$ $r$ $\neg r$ $(q \vee (\neg r))$ $(q \wedge r)$ $((q \wedge r) \rightarrow p)$ $((q \wedge r) \rightarrow p) \wedge (q \vee (\neg r))$
$\mathsf{T}$ $\mathsf{T}$ $\mathsf{F}$ $\mathsf{T}$ $\mathsf{T}$
$\mathsf{F}$ $\mathsf{F}$ $\mathsf{F}$ $\mathsf{T}$ $\mathsf{F}$
$\mathsf{T}$ $\mathsf{T}$ $\mathsf{F}$ $\mathsf{T}$ $\mathsf{T}$
$\mathsf{F}$ $\mathsf{T}$ $\mathsf{T}$ $\mathsf{F}$ $\mathsf{F}$
$\mathsf{T}$ $\mathsf{T}$ $\mathsf{F}$ $\mathsf{T}$ $\mathsf{T}$
$\mathsf{F}$ $\mathsf{F}$ $\mathsf{F}$ $\mathsf{T}$ $\mathsf{F}$
$\mathsf{T}$ $\mathsf{T}$ $\mathsf{F}$ $\mathsf{T}$ $\mathsf{T}$
$\mathsf{F}$ $\mathsf{T}$ $\mathsf{T}$ $\mathsf{T}$ $\mathsf{T}$

Garfield has black stripes if he is an orange cat and likes lasagna, and he is an orange cat or does not like lasagna.

  • $p$ = “Garfield has black stripes.”
  • $q$ = “Garfield is an orange cat.”
  • $r$ = “Garfield likes lasagna.”

Summary

Welcome to CSE 311!
All logistics are on the course webpage.
Propositional logic lets us be concise and precise.
Atomic propositions are “words” in propositional logic.
Compound propositions are “sentences” made with logical connectives.
Implication is tricky: when in doubt, write the truth table!