What you will learn and why!
By the end of the course, you will have the key technical tools to …
A quick summary now; details on the course webpage.
Afternoon section will be recorded
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…”
You are not in competition with your classmates.
A language of reasoning
Logic is a language, like English or Java, with its own
So why learn another language when we know English and Java?
Natural language can be imprecise.
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.
We need a language of reasoning to
A proposition is a statement that is either true or false.
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
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:
Garfield has black stripes if he is an orange cat and likes lasagna, and he is an orange cat or does not like lasagna.
$\downarrow$ Step 1: abstract
($p$ if ($q$ and $r$)) and ($q$ or (not $r$))
$\downarrow$ Step 2: replace English connectives with 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$))
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}$ |
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}$ |
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:
$p$ | $q$ | $p \rightarrow q$ |
---|---|---|
$\mathsf{T}$ | ||
$\mathsf{T}$ | ||
$\mathsf{F}$ | ||
$\mathsf{T}$ |
Are these true?
- I have collected all 151 Pokémon if I am a Pokémon master.
- I have collected all 151 Pokémon only if I am a Pokémon master.
These sentences are implications in opposite directions:
So, the implications are:
$p$ | $q$ | $p \rightarrow q$ |
---|---|---|
$\mathsf{T}$ | ||
$\mathsf{T}$ | ||
$\mathsf{F}$ | ||
$\mathsf{T}$ |
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}$ |
Garfield has black stripes if he is an orange cat and likes lasagna, and he is an orange cat or does not like 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$))
$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.