CSE 311 Lecture 01: Propositional Logic

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

Emina Torlak
Section B: MWF 9:30–10:20 AM
Office hours: Th 12:30-1:30 PM

Sami Davies
Section A: MWF 1:30–2:20 PM
Office hours: W 2:30-3:30 PM

TAs

  • Austin Chan
  • Daniel Jones
  • Daniel Thomas Fuchs
  • Logan Gnanapragasam
  • Harrison Bay
  • Kevin Pham
  • Karishma Ramesh Mandyam
  • Leana Chen
  • Louis Maliyam
  • Mrigank Arora
  • Oscar Sprumont
  • Pemi Nguyen
  • Frank Qin

Communication

Zoom
For lectures, sections, and office hours. Lectures will be recorded.
Canvas
For grades, important announcements, and links to Zoom meetings.
Gradescope
For submitting your work. You will receive an email invitation.
Piazza
To discuss the content of the course. Opt out of Piazza Careers.
Email
For other matters, send email to cse311-staff@cs, which will reach both the instructors and the TAs.

Textbook, work, and grading

Optional textbook
Rosen, Discrete Mathematics and Its Applications, 6th Edition, McGraw-Hill.
Homework Assignments
Due at 11:59:59 PM on the due date.
Collaborate but write up individually.
List your collaborators.
Do not leave with any part of the solution in writing or photographs.
Wait at least 30 minutes before writing your own solution.
Grading
Weekly homework assignments: 88%
Final homework assignment: 12%

About grades

Grades were very important up until now …

Your grades are a lot less important than you think going forward.

  • Companies care much more about your interviews.
  • Grad schools care much more about recommendations.

Understanding the material is much more important.

  • Interviews test your knowledge from these classes.
  • Good recommendations involve knowledge beyond the classes.

Please relax and focus on learning!

  • Try to avoid asking “will I lose points if…”.
  • Most such questions are not worthwhile, either for you or for us.
  • If you are really worried, then show more work.

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

  • $\T$ for true, or
  • $\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$
$\T$
$\F$
$p$ $q$ $p \wedge q$
$\F$
$\F$
$\F$
$\T$
$p$ $q$ $p \vee q$
$\F$
$\T$
$\T$
$\T$
$p$ $q$ $p \oplus q$
$\F$
$\T$
$\T$
$\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$
$\T$
$\T$
$\F$
$\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$
$\T$
$\T$
$\F$
$\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$
$\T$
$\T$
$\F$
$\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 Pokemon if I am a Pokemon master.
  2. I have collected all 151 Pokemon only if I am a Pokemon master.

These sentences are implications in opposite directions:

  1. Pokemon masters have all 151 Pokemon.
  2. People who have 151 Pokemon are Pokemon masters.

So, the implications are:

  1. If I am a Pokemon master, then I have collected all 151 Pokemon.
  2. If I have collected all 151 Pokemon, then I am a Pokemon master.

Understanding implication some more

$p$ $q$ $p \rightarrow q$
$\T$
$\T$
$\F$
$\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$
$\T$
$\F$
$\F$
$\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))$
$\T$ $\T$ $\F$ $\T$ $\T$
$\F$ $\F$ $\F$ $\T$ $\F$
$\T$ $\T$ $\F$ $\T$ $\T$
$\F$ $\T$ $\T$ $\F$ $\F$
$\T$ $\T$ $\F$ $\T$ $\T$
$\F$ $\F$ $\F$ $\T$ $\F$
$\T$ $\T$ $\F$ $\T$ $\T$
$\F$ $\T$ $\T$ $\T$ $\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!