administrivia Course web: http://www.cs.washington.edu/311 Office - - PowerPoint PPT Presentation

administrivia
SMART_READER_LITE
LIVE PREVIEW

administrivia Course web: http://www.cs.washington.edu/311 Office - - PowerPoint PPT Presentation

administrivia Course web: http://www.cs.washington.edu/311 Office hours: 12 office hours each week Me/James: MW 10:30-11:30/2:30-3:30pm or by appointment TA Section: Start next week Call me: Shayan Dont: Actually call me. Homework #1:


slide-1
SLIDE 1

administrivia

Course web: http://www.cs.washington.edu/311 Office hours: 12 office hours each week Me/James: MW 10:30-11:30/2:30-3:30pm or by appointment Homework #1: Will be posted today, due next Friday by midnight (Oct 9th) Gradescope! (stay tuned) Extra credit: Not required to get a 4.0. Counts separately. In total, may raise grade by ~0.1 Call me: Shayan Don’t: Actually call me.

If you are not CSE yet, please do well! Don’t be shy (raise your hand in the back)! Do space out your participation.

TA Section: Start next week

slide-2
SLIDE 2

logical connectives

p

  • p

T F F T p q p  q T T T T F F F T F F F F p q p  q T T T T F T F T T F F F p q p  q T T F T F T F T T F F F NOT AND OR XOR

slide-3
SLIDE 3

𝑞 → 𝑟

  • “If p, then q” is a promise:
  • Whenever p is true, then q is true
  • Ask “has the promise been broken”

p q p  q F F T F T T T F F T T T

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

slide-4
SLIDE 4

related implications

  • Implication:

p  q

  • Converse:

q  p

  • Contrapositive:
  • q  p
  • Inverse:
  • p  q

How do these relate to each other? How to see this?

slide-5
SLIDE 5

𝑞 ↔ 𝑟

  • p iff q
  • p is equivalent to q
  • p implies q and q implies p

p q p  q

slide-6
SLIDE 6

Let’s think about fruits

A fruit is an apple only if it is either red or green and a fruit is not red and green.

𝑞 : “Fruit is an apple” 𝑟 : “Fruit is red” 𝑠 : “Fruit is green”

slide-7
SLIDE 7

Let’s think about fruits

A fruit is an apple only if it is either red or green and a fruit is not red and green.

(FApple only if (FGreen xor FRed)) and (not (FGreen and FRed))

p : FApple q : FGreen r : FRed

(FApple → (FGreen ⊕ FRed )) ∧ ( ¬ (FGreen ∧ Fred))

slide-8
SLIDE 8

Fruit Sentence with a truth table

p q r 𝒓 ⊕ 𝒔 𝒒 → (𝒓 ⊕ 𝐬) 𝒓 ∧ 𝒔 ¬(𝒓 ∧ 𝒔) (𝒒 → 𝒓 ⊕ 𝐬 ) ∧ (¬ 𝒓 ∧ 𝒔 )

T T T T T F T F T T F F F T T F T F F F T F F F

slide-9
SLIDE 9

cse 311: foundations of computing Spring 2015 Lecture 2: Digital circuits & more logic

slide-10
SLIDE 10

digital circuits

Computing with logic – T corresponds to 1 or “high” voltage – F corresponds to 0 or “low” voltage Gates: – Take inputs and produce outputs (functions) – Several kinds of gates – Correspond to propositional connectives

slide-11
SLIDE 11

AND gate

p q p  q T T T T F F F T F F F F p q

OUT

1 1 1 1 1

AND Connective AND Gate

q p

OUT AND

“block looks like D of AND”

p

OUT AND

q

p  q

vs.

slide-12
SLIDE 12

OR gate

p q p  q T T T T F T F T T F F F p q

OUT

1 1 1 1 1 1 1

OR Connective OR Gate

p

OUT

OR

q

p  q

vs. p q

OR

“arrowhead block looks like ∨”

OUT

slide-13
SLIDE 13

NOT gate

  • p

NOT Gate

p

  • p

T F F T p

OUT

1 1

vs.

NOT Connective

(Also called inverter)

p

OUT NOT

p

OUT NOT

slide-14
SLIDE 14

blobs are okay

p

OUT NOT

p q

OUT AND

p q

OUT OR

You can write gates using blobs instead of shapes.

“gee, thanks.”

slide-15
SLIDE 15

combinational logic circuits

Values get sent along wires connecting gates

NOT OR AND AND NOT

slide-16
SLIDE 16

combinational logic circuits

Wires can send one value to multiple gates!

OR AND NOT AND

slide-17
SLIDE 17

logical equivalence Terminology: 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   p p  p (p  q)  p (p  q)  (p   q)  ( p  q)  ( p   q)

Classify!

slide-18
SLIDE 18

logical equivalence Terminology: 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 𝑞 ∧ 𝑟 ∧ 𝑠 ∨ ¬𝑞 ∧ 𝑟 ∧ ¬𝑠 ∧ 𝑞 ∨ 𝑟 ∨ ¬𝑡 ∨ 𝑞 ∧ 𝑟 ∧ 𝑡

Classify!

NOT OR AND AND NOT

slide-19
SLIDE 19

logical equivalence

A and B are logically equivalent if and only if A  B is a tautology

i.e. A and B have the same truth table

The notation A  B denotes A and B are logically equivalent. Example: p    p

p

  • p   p

p    p

slide-20
SLIDE 20

A  B vs. A  B

A  B says that two propositions A and B always mean the same thing. A  B is a single proposition that may be true or false depending on the truth values of the variables in A and B. but A  B and (A  B)  T have the same meaning. Note: Why write A  B and not A=B ?

[We use A=B to say that A and B are precisely the same proposition (same sequence of symbols)]

slide-21
SLIDE 21

My code compiles or there is a bug.

[let’s negate it]

de Morgan’s laws

Write NAND using NOT and OR:

“Always wear breathable fabrics when you get your picture taken.”

slide-22
SLIDE 22

de Morgan’s laws

p q  p

  • q
  • p   q

p  q

  • (p  q)
  • (p  q)  ( p   q)

T T T F F T F F

Verify:  𝑞  𝑟 ≡ (¬ 𝑞 ∨ ¬ 𝑟)

slide-23
SLIDE 23
  • 𝑞 ∧ 𝑟 ≡ ¬ 𝑞 ∨ ¬ 𝑟
  • 𝑞 ∨ 𝑟 ≡ ¬ 𝑞 ∧ ¬ 𝑟

if !(front != null && value > front.data) front = new ListNode(value, front); else { ListNode current = front; while !(current.next == null || current.next.data >= value) current = current.next; current.next = new ListNode(value, current.next); }

de Morgan’s laws

slide-24
SLIDE 24

law of implication

p q p  q

  • p  p  q

(p  q)  ( p  q)

T T T F F T F F

𝑞 → 𝑟 ≡ (¬ 𝑞 ∨ 𝑟)

slide-25
SLIDE 25

computing equivalence Describe an algorithm for computing if two logical expressions/circuits are equivalent. What is the run time of the algorithm?

slide-26
SLIDE 26

some familiar properties of arithmetic

  • 𝑦 + 𝑧 = 𝑧 + 𝑦

(commutativity)

  • 𝑦 ⋅ 𝑧 + 𝑨 = 𝑦 ⋅ 𝑧 + 𝑦 ⋅ 𝑨 (distributivity)
  • 𝑦 + 𝑧 + 𝑨 = 𝑦 + (𝑧 + 𝑨) (associativity)

Logic has similar algebraic properties

slide-27
SLIDE 27

some familiar properties of arithmetic

  • 𝑦 + 𝑧 = 𝑧 + 𝑦

(commutativity)

– 𝑞 ∨ 𝑟 ≡ 𝑟 ∨ 𝑞 – 𝑞 ∧ 𝑟 ≡ 𝑟 ∧ 𝑞

  • 𝑦 ⋅ 𝑧 + 𝑨 = 𝑦 ⋅ 𝑧 + 𝑦 ⋅ 𝑨

(distributivity)

– 𝑞 ∧ 𝑟 ∨ 𝑠 ≡ 𝑞 ∧ 𝑟 ∨ (𝑞 ∧ 𝑠) – 𝑞 ∨ 𝑟 ∧ 𝑠 ≡ 𝑞 ∨ 𝑟 ∧ (𝑞 ∨ 𝑠)

  • 𝑦 + 𝑧 + 𝑨 = 𝑦 + (𝑧 + 𝑨)

(associativity)

– 𝑞 ∨ 𝑟 ∨ 𝑠 ≡ 𝑞 ∨ 𝑟 ∨ 𝑠 – 𝑞 ∧ 𝑟 ∧ 𝑠 ≡ 𝑞 ∧ (𝑟 ∧ 𝑠)

slide-28
SLIDE 28

properties of logical connectives

  • Identity

– 𝑞 ∧ T ≡ 𝑞 – 𝑞 ∨ F ≡ 𝑞

  • Domination

– 𝑞 ∨ T ≡ T – 𝑞 ∧ F ≡ F

  • Idempotent

– 𝑞 ∨ 𝑞 ≡ 𝑞 – 𝑞 ∧ 𝑞 ≡ 𝑞

  • Commutative

– 𝑞 ∨ 𝑟 ≡ 𝑟 ∨ 𝑞 – 𝑞 ∧ 𝑟 ≡ 𝑟 ∧ 𝑞 You will always get this list.

  • Associative

𝑞 ∨ 𝑟 ∨ 𝑠 ≡ 𝑞 ∨ 𝑟 ∨ 𝑠 𝑞 ∧ 𝑟 ∧ 𝑠 ≡ 𝑞 ∧ 𝑟 ∧ 𝑠

  • Distributive

𝑞 ∧ 𝑟 ∨ 𝑠 ≡ 𝑞 ∧ 𝑟 ∨ (𝑞 ∧ 𝑠) 𝑞 ∨ 𝑟 ∧ 𝑠 ≡ 𝑞 ∨ 𝑟 ∧ (𝑞 ∨ 𝑠)

  • Absorption

𝑞 ∨ 𝑞 ∧ 𝑟 ≡ 𝑞 𝑞 ∧ 𝑞 ∨ 𝑟 ≡ 𝑞

  • Negation

𝑞 ∨ ¬𝑞 ≡ T 𝑞 ∧ ¬𝑞 ≡ F