CSE 311 Lecture 02: Logic, Equivalence, and Circuits

Emina Torlak and Kevin Zatloukal

Topics

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.
Digital circuits
Gates, combinational circuits, and circuit equivalence.

Propositional logic

A brief review of Lecture 01.

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 ($\mathsf{T}$) or false ($\mathsf{F}$).
Truth tables show the meaning of compound propositions.

Connectives and truth tables

$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}$
$p$ $q$ $p \rightarrow q$
$\mathsf{T}$
$\mathsf{T}$
$\mathsf{F}$
$\mathsf{T}$
$p$ $q$ $p \leftrightarrow q$
$\mathsf{T}$
$\mathsf{F}$
$\mathsf{F}$
$\mathsf{T}$

Implication can be tricky but truth tables don’t lie

$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$

In an implication $p \rightarrow q$:

  • $p$ is called the premise or antecedent.
  • $q$ is called the conclusion or consequence.

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))$
$\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.”

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$
$\mathsf{T}$ $\mathsf{T}$ $\mathsf{T}$ $\mathsf{T}$ $\mathsf{T}$ $\mathsf{T}$
$\mathsf{T}$ $\mathsf{F}$ $\mathsf{T}$ $\mathsf{F}$ $\mathsf{T}$ $\mathsf{F}$
$\mathsf{F}$ $\mathsf{T}$ $\mathsf{F}$ $\mathsf{T}$ $\mathsf{F}$ $\mathsf{T}$
$\mathsf{T}$ $\mathsf{T}$ $\mathsf{F}$ $\mathsf{F}$ $\mathsf{T}$ $\mathsf{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=\mathsf{T}$ and false when $p=\mathsf{T}, q=\mathsf{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=\mathsf{T}$ and $q=\mathsf{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 \mathsf{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$)
$\mathsf{T}$ $\mathsf{T}$ $\mathsf{T}$ $\mathsf{F}$ $\mathsf{T}$ $\mathsf{T}$
$\mathsf{T}$ $\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{F}$ $\mathsf{T}$ $\mathsf{F}$ $\mathsf{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)$
$\mathsf{T}$ $\mathsf{T}$ $\mathsf{T}$ $\mathsf{T}$
$\mathsf{T}$ $\mathsf{T}$ $\mathsf{T}$ $\mathsf{T}$
$\mathsf{F}$ $\mathsf{F}$ $\mathsf{F}$ $\mathsf{T}$
$\mathsf{T}$ $\mathsf{F}$ $\mathsf{T}$ $\mathsf{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 \mathsf{T} \equiv p$
$p \vee \mathsf{F} \equiv p$
Domination
$p \wedge \mathsf{F} \equiv \mathsf{F}$
$p \vee \mathsf{T} \equiv \mathsf{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 \mathsf{F}$
$p \vee \neg p \equiv \mathsf{T}$
Double negation
$p \equiv \neg \neg p$

We will always give you this list!

Digital circuits

Gates, combinational circuits, and circuit equivalence.

Computing with logic

Digital circuits implement propositional logic:

  • $\mathsf{T}$ corresponds to 1 or high voltage.
  • $\mathsf{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$
$\mathsf{F}$
$\mathsf{F}$
$\mathsf{F}$
$\mathsf{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$
$\mathsf{F}$
$\mathsf{T}$
$\mathsf{T}$
$\mathsf{T}$

OR gate

$p$ $q$
0 0 0
0 1 1
1 0 1
1 1 1

“Arrowhead block looks like $\vee$.”

NOT gate

NOT connective

$p$ $\neg p$
$\mathsf{T}$
$\mathsf{F}$

NOT gate

$p$
0 1
1 0

Also called an inverter.

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!
$\mathsf{F}$/$\mathsf{T}$ correspond to 0/1 (low/high voltage), respectively.
Gates implement logical connectives.
Combinational circuits implement compound propositions.