CSE 311 Lecture 02: Logic, Equivalence, and Circuits
Topics
- CSE 390Z
- A workshop for CSE 311 students.
- Propositional logic
- A brief review of Lecture 01.
- Classifying compound propositions
- Converse, contrapositive, and inverse of implication.
Tautology, contradiction, contingency.
- Logical equivalence
- Equivalence, laws of logic, and properties of logical connectives.
- Application: digital circuits
- Gates, combinational circuits, and circuit equivalence.
CSE 390Z
A workshop for CSE 311 students.
Logistics of CSE 390Z
Build a community within 311, learn collaborative problem solving tactics, and practice study skills.
Meets Thursdays 3:30-4:50pm (maybe also 5:00-6:20pm).
For more information, email Nicole Riley at nriley16@uw.edu and check out the course website.
To sign up, request an add code.
Syntax and semantics of propositional logic
- Syntax
- Atomic propositions are “words” in propositional logic.
- Propositional variables represent atomic propositions.
- Compound propositions are “sentences” made with logical connectives: $\neg,\wedge,\vee,\oplus,\rightarrow,\leftrightarrow$.
- Semantics
- A variable is either true ($\T$) or false ($\F$).
- Truth tables show the meaning of compound propositions.
Connectives and truth tables
$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$ |
$p$ |
$q$ |
$p \rightarrow q$ |
|
|
$\T$ |
|
|
$\T$ |
|
|
$\F$ |
|
|
$\T$ |
$p$ |
$q$ |
$p \leftrightarrow q$ |
|
|
$\T$ |
|
|
$\F$ |
|
|
$\F$ |
|
|
$\T$ |
Implication can be tricky but truth tables don’t lie
$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$
In an implication $p \rightarrow q$:
- $p$ is called the premise or antecedent.
- $q$ is called the conclusion or consequence.
- English translations for $p \to q$ where $p$ is “It’s raining” and $q$ is “I have my umbrella”.
- If it’s raining, then I have my umbrella.
- I have my umbrella if it’s raining.
- It’s raining only if I have my umbrella.
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$
Translating English sentences 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
(($q$ $\wedge$ $r$) $\rightarrow$ $p$)
$\wedge$ ($q$ $\vee$ ($\neg$ $r$))
Understanding sentences with truth tables
$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.”
Precedence of logical connectives
- We’ll use the following precedence rules for propositional connectives:
- $\neg$, $\wedge$, $\vee$, $\to$, $\leftrightarrow$.
- All operators are right-associative.
- When in doubt, use parentheses.
- Example: $\neg p \to q \vee r \leftrightarrow p \vee q \wedge r$
- $(\neg p) \to q \vee r \leftrightarrow p \vee q \wedge r$
- $(\neg p) \to q \vee r \leftrightarrow p \vee (q \wedge r)$
- $(\neg p) \to (q \vee r) \leftrightarrow (p \vee (q \wedge r))$
- $((\neg p) \to (q \vee r)) \leftrightarrow (p \vee (q \wedge r))$
Classifying compound propositions
Converse, contrapositive, and inverse of implication.
Tautology, contradiction, contingency.
Implication and friends
- Implication
- $p \rightarrow q$
- Converse
- $q \rightarrow p$
- Contrapositive
- $\neg q \rightarrow \neg p$
- Inverse
- $\neg p \rightarrow \neg q$
How do these relate to each other?
$p$ |
$q$ |
$p \rightarrow q$ |
$q \rightarrow p$ |
$\neg p$ |
$\neg q$ |
$\neg q \rightarrow \neg p$ |
$\neg p \rightarrow \neg q$ |
|
|
$\T$ |
$\T$ |
$\T$ |
$\T$ |
$\T$ |
$\T$ |
|
|
$\T$ |
$\F$ |
$\T$ |
$\F$ |
$\T$ |
$\F$ |
|
|
$\F$ |
$\T$ |
$\F$ |
$\T$ |
$\F$ |
$\T$ |
|
|
$\T$ |
$\T$ |
$\F$ |
$\F$ |
$\T$ |
$\T$ |
An implication and its contrapositive have the same truth value!
Tautology, contradiction, and contingency
A compound proposition is a
- Tautology if it is always true;
- Contradiction if it is always false;
- Contingency if it can be either true or false.
- $(p \rightarrow q) \wedge p$
- This is a contingency. It’s true when $p = q=\T$ and false when $p=\T, q=\F$.
- $p \vee \neg p$
- This is a tautology. It’s true no matter what truth value $p$ takes on.
- $p \oplus p$
- This is a contradiction. It’s false no matter what truth value $p$ takes on.
Logical equivalence
Equivalence, laws of logic, and properties of logical connectives.
Equivalence of compound propositions
$A$ and $B$ are logically equivalent, written as $A \equiv B$,
if they have the same truth values in all possible cases.
- $p \wedge q \equiv p \wedge q$
- Two formulas that are syntactically identical are also equivalent.
- $p\wedge q \equiv q \wedge p$
- These two formulas are syntactically different but have the same truth table!
- $p\wedge q \not\equiv q \vee p$
- When $p=\T$ and $q=\F$, $p \wedge q$ is false but $p \vee q$ is true!
$A \equiv B$ versus $A \leftrightarrow B$
$A \equiv B$ is an assertion that $A$ and $B$ have the same truth tables.
- This is not a compound proposition (sentence) in propositional logic!
- It is also sometimes called a semantic judgement.
$A \leftrightarrow B$ is a proposition that may be true or false depending on the truth values
of the variables that occur in $A$ and $B$.
$A \equiv B$ and $(A \leftrightarrow B) \equiv \T$ have the same meaning.
$A$ and $B$ are equivalent when $A \leftrightarrow B$ is a tautology.
Important equivalences: DeMorgan’s laws
How do we check that an equivalence $A \equiv B$ holds?
Use truth tables to check that $A \leftrightarrow B$ is a tautology:
$p$ |
$q$ |
$\neg p$ |
$\neg q$ |
$\neg p \vee \neg q$ |
$p \wedge q$ |
$\neg (p \wedge q)$ |
$\neg(p \wedge q) \leftrightarrow (\neg p \vee \neg q$) |
|
|
$\T$ |
$\T$ |
$\T$ |
$\F$ |
$\T$ |
$\T$ |
|
|
$\T$ |
$\F$ |
$\T$ |
$\F$ |
$\T$ |
$\T$ |
|
|
$\F$ |
$\T$ |
$\T$ |
$\F$ |
$\T$ |
$\T$ |
|
|
$\F$ |
$\F$ |
$\F$ |
$\T$ |
$\F$ |
$\T$ |
Fun fact: you can also use a theorem prover to check that $\neg (A \leftrightarrow B)$ is a contradiction!
Important equivalences: law of implication
$p$ |
$q$ |
$p \rightarrow q$ |
$\neg p$ |
$\neg p \vee q$ |
$(p \rightarrow q) \leftrightarrow (\neg p \vee q)$ |
|
|
$\T$ |
$\T$ |
$\T$ |
$\T$ |
|
|
$\T$ |
$\T$ |
$\T$ |
$\T$ |
|
|
$\F$ |
$\F$ |
$\F$ |
$\T$ |
|
|
$\T$ |
$\F$ |
$\T$ |
$\T$ |
- More equivalences related to implication
- $p \rightarrow q \equiv \neg q \rightarrow \neg p $
- $p \leftrightarrow q \equiv (p \rightarrow q) \wedge (q \rightarrow p)$
- $p \leftrightarrow q \equiv \neg p \leftrightarrow \neg q$
Important equivalences: properties of connectives
- Identity
- $p \wedge \T \equiv p$
- $p \vee \F \equiv p$
- Domination
- $p \wedge \F \equiv \F$
- $p \vee \T \equiv \T$
- Idempotence
- $p \wedge p \equiv p$
- $p \vee p \equiv p$
- Commutativity
- $p \wedge q \equiv q \wedge p$
- $p \vee q \equiv q \vee p$
- Associativity
- $(p \wedge q) \wedge r \equiv p \wedge (q \wedge r)$
- $(p \vee q) \vee r \equiv p \vee (q \vee r)$
- Distributivity
- $p \wedge (q \vee r) \equiv (p \wedge q) \vee (p \wedge r)$
- $p \vee (q \wedge r) \equiv (p \vee q) \wedge (p \vee r)$
- Absorption
- $p \wedge (p \vee q) \equiv p$
- $p \vee (p \wedge q) \equiv p$
- Negation
- $p \wedge \neg p \equiv \F$
- $p \vee \neg p \equiv \T$
- Double negation
- $p \equiv \neg \neg p$
Application: digital circuits
Gates, combinational circuits, and circuit equivalence.
Computing with logic
Digital circuits implement propositional logic:
- $\T$ corresponds to 1 or high voltage.
- $\F$ corresponds to 0 or low voltage.
Digital gates are functions that
- take values 0/1 as inputs and produce 0/1 as output;
- correspond to logical connectives (many of them).
AND gate
AND connective
$p$ |
$q$ |
$p \wedge q$ |
|
|
$\F$ |
|
|
$\F$ |
|
|
$\F$ |
|
|
$\T$ |
AND gate
$p$ |
$q$ |
|
0 |
0 |
0 |
0 |
1 |
0 |
1 |
0 |
0 |
1 |
1 |
1 |
“Block looks like the D of an AND.”
OR gate
OR connective
$p$ |
$q$ |
$p \vee q$ |
|
|
$\F$ |
|
|
$\T$ |
|
|
$\T$ |
|
|
$\T$ |
OR gate
$p$ |
$q$ |
|
0 |
0 |
0 |
0 |
1 |
1 |
1 |
0 |
1 |
1 |
1 |
1 |
“Arrowhead block looks like $\vee$.”
Blobs are OK!
You may write gates using blobs instead of shapes.
Combinational logic circuits: wiring up gates
Values get sent along wires connecting gates.
$\neg p \wedge (\neg q \wedge (r \vee s))$
Combinational logic circuits: wiring up gates
Wires can send one value to multiple gates.
$(p \wedge \neg q) \vee (\neg q \wedge r)$
Checking (circuit) equivalence
- Describe an algorithm for checking if two logical expressions (or circuits) are equivalent.
- Compute the entire truth table for both of them!
- What is the run time of the algorithm?
- There are $2^n$ entries in the column for $n$ variables.
- Why do we care?
- Program and hardware verification reduces to logical equivalence checking!
Summary
- Propositions can be tautologies, contradictions, or contingencies.
- Tautologies are always true.
- Contradictions are never true.
- Contingencies are sometimes true.
- Propositions are equivalent when they have the same truth values.
- Use truth tables or laws of logic to establish equivalence.
- Digital circuits implement propositional logic!
- $\F$/$\T$ correspond to 0/1 (low/high voltage), respectively.
- Gates implement logical connectives.
- Combinational circuits implement compound propositions.