56
CSE 20 Lecture 4: Introduction to Boolean algebra CSE 20: Lecture4

CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

CSE 20Lecture 4: Introduction to Boolean algebra

CSE 20: Lecture4

Page 2: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Reminder

First quiz will be on Friday (17th January) in class.

It is a paper quiz.

Syllabus is all that has been done till Wednesday.

If you want you may bring a calculator

CSE 20: Lecture4

Page 3: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Base b representation

Digits: 0, 1, . . . , b− 1

Represented as [x]b. (Like [22001]3)

Base b representation of a number x is the unique way ofwriting

x = x0 ∗ b0 + x1 ∗ b1 + · · ·+ xk ∗ bk,

where x0, x1, . . . , xk ∈ {0, 1, . . . , (b− 1)}

CSE 20: Lecture4

Page 4: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Base b representation

Digits: 0, 1, . . . , b− 1

Represented as [x]b. (Like [22001]3)

Base b representation of a number x is the unique way ofwriting

x = x0 ∗ b0 + x1 ∗ b1 + · · ·+ xk ∗ bk,

where x0, x1, . . . , xk ∈ {0, 1, . . . , (b− 1)}

CSE 20: Lecture4

Page 5: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Base b representation

Digits: 0, 1, . . . , b− 1

Represented as [x]b. (Like [22001]3)

Base b representation of a number x is the unique way ofwriting

x = x0 ∗ b0 + x1 ∗ b1 + · · ·+ xk ∗ bk,

where x0, x1, . . . , xk ∈ {0, 1, . . . , (b− 1)}

CSE 20: Lecture4

Page 6: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Base b representation

Digits: 0, 1, . . . , b− 1

Represented as [x]b. (Like [22001]3)

Base b representation of a number x is the unique way ofwriting

x = x0 ∗ b0 + x1 ∗ b1 + · · ·+ xk ∗ bk,

where x0, x1, . . . , xk ∈ {0, 1, . . . , (b− 1)}

CSE 20: Lecture4

Page 7: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Algorithm for finding representaation in base b

We can find a representation in base b using GREEDYMETHOD.

CSE 20: Lecture4

Page 8: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Unique representation in base “b”

Can an integer be written in base b in two different ways?

Answer may be obvious but we need to prove itmathematically.

CSE 20: Lecture4

Page 9: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Mathematical formulation of the unique

representation in base “b” problem

Let N be a number that be write in base b.

Let there be two different representation in base b:

N = x0 ∗ b0 + x1 ∗ b1 + · · ·+ xk ∗ bk,

N = y0 ∗ b0 + y1 ∗ b1 + · · ·+ yk ∗ bk.

Is it possible that there exists (∃) i such that xi 6= yi?

CSE 20: Lecture4

Page 10: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Mathematical formulation of the unique

representation in base “b” problem

Let N be a number that be write in base b.

Let there be two different representation in base b:

N = x0 ∗ b0 + x1 ∗ b1 + · · ·+ xk ∗ bk,

N = y0 ∗ b0 + y1 ∗ b1 + · · ·+ yk ∗ bk.

Is it possible that there exists (∃) i such that xi 6= yi?

CSE 20: Lecture4

Page 11: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Mathematical formulation of the unique

representation in base “b” problem

Let N be a number that be write in base b.

Let there be two different representation in base b:

N = x0 ∗ b0 + x1 ∗ b1 + · · ·+ xk ∗ bk,

N = y0 ∗ b0 + y1 ∗ b1 + · · ·+ yk ∗ bk.

Is it possible that there exists (∃) i such that xi 6= yi?

CSE 20: Lecture4

Page 12: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Proof style

We prove by contradiction .

We assume that a number can be written in twodifferent ways

Then using this assumption we conclude thatsomething seriously wrong happens, like

2` < 2`

So we conclude that the original assumption waswrong.

CSE 20: Lecture4

Page 13: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Proof style

We prove by contradiction .

We assume that a number can be written in twodifferent ways

Then using this assumption we conclude thatsomething seriously wrong happens, like

2` < 2`

So we conclude that the original assumption waswrong.

CSE 20: Lecture4

Page 14: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Proof style

We prove by contradiction .

We assume that a number can be written in twodifferent ways

Then using this assumption we conclude thatsomething seriously wrong happens, like

2` < 2`

So we conclude that the original assumption waswrong.

CSE 20: Lecture4

Page 15: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Proof style

We prove by contradiction .

We assume that a number can be written in twodifferent ways

Then using this assumption we conclude thatsomething seriously wrong happens, like

2` < 2`

So we conclude that the original assumption waswrong.

CSE 20: Lecture4

Page 16: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Mathematical logic

Every statement (proposition) is either TRUE orFALSE.

A statement can have an unspecified term, calledvariable.

Statements are connected to each other by 5connectives: AND, OR, NOT, IMPLIES and IFF.

CSE 20: Lecture4

Page 17: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Mathematical logic

Every statement (proposition) is either TRUE orFALSE.

A statement can have an unspecified term, calledvariable.

Statements are connected to each other by 5connectives: AND, OR, NOT, IMPLIES and IFF.

CSE 20: Lecture4

Page 18: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Mathematical logic

Every statement (proposition) is either TRUE orFALSE.

A statement can have an unspecified term, calledvariable.

Statements are connected to each other by 5connectives: AND, OR, NOT, IMPLIES and IFF.

CSE 20: Lecture4

Page 19: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

The IMPLIES ( =⇒ )

p q p =⇒ qF F TF T TT F FT T T

CSE 20: Lecture4

Page 20: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

The AND (∧)

p q p ∧ qF F FF T FT F FT T T

CSE 20: Lecture4

Page 21: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

The OR (∨)

p q p ∨ qF F FF T TT F TT T T

CSE 20: Lecture4

Page 22: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

The IMPLIES ( =⇒ )

p q p =⇒ qF F TF T TT F FT T T

CSE 20: Lecture4

Page 23: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

The IFF (⇐⇒ )

p q p ⇐⇒ qF F TF T FT F FT T T

CSE 20: Lecture4

Page 24: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

The NOT (¬)

p ¬pF TT F

CSE 20: Lecture4

Page 25: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Universality

Every logical sentance can be written using the AND, OR,NOT, IMPLIES, IFF and two more symbols:

There exists, ∃

For all, ∀

CSE 20: Lecture4

Page 26: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Proof by contradiction

p q p =⇒ qF F TF T TT F FT T T

CSE 20: Lecture4

Page 27: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Base b representation

Digits: 0, 1, . . . , b− 1

Represented as [x]b. (Like [22001]3)

Base b representation of a number x is the unique way ofwriting

x = x0 ∗ b0 + x1 ∗ b1 + · · ·+ xk ∗ bk,

where x0, x1, . . . , xk ∈ {0, 1, . . . , (b− 1)}

CSE 20: Lecture4

Page 28: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Base b representation

Digits: 0, 1, . . . , b− 1

Represented as [x]b. (Like [22001]3)

Base b representation of a number x is the unique way ofwriting

x = x0 ∗ b0 + x1 ∗ b1 + · · ·+ xk ∗ bk,

where x0, x1, . . . , xk ∈ {0, 1, . . . , (b− 1)}

CSE 20: Lecture4

Page 29: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Base b representation

Digits: 0, 1, . . . , b− 1

Represented as [x]b. (Like [22001]3)

Base b representation of a number x is the unique way ofwriting

x = x0 ∗ b0 + x1 ∗ b1 + · · ·+ xk ∗ bk,

where x0, x1, . . . , xk ∈ {0, 1, . . . , (b− 1)}

CSE 20: Lecture4

Page 30: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Base b representation

Digits: 0, 1, . . . , b− 1

Represented as [x]b. (Like [22001]3)

Base b representation of a number x is the unique way ofwriting

x = x0 ∗ b0 + x1 ∗ b1 + · · ·+ xk ∗ bk,

where x0, x1, . . . , xk ∈ {0, 1, . . . , (b− 1)}

CSE 20: Lecture4

Page 31: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Binary Representation

When one represent a number in base 2 it is calledbinary representation.

Sometimes called Boolean representation after Englishmathematician George Boole.

Computer talks in this language.

CSE 20: Lecture4

Page 32: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Binary Representation

When one represent a number in base 2 it is calledbinary representation.

Sometimes called Boolean representation after Englishmathematician George Boole.

Computer talks in this language.

CSE 20: Lecture4

Page 33: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Binary Representation

When one represent a number in base 2 it is calledbinary representation.

Sometimes called Boolean representation after Englishmathematician George Boole.

Computer talks in this language.

CSE 20: Lecture4

Page 34: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

The world of the computers

Every number is stored in binary

Every number has a certain length (depending of theregister size).

For example:If the register size is 8 then 1 is stored as 00000001.

Cannot store more than a certain number of digits.

CSE 20: Lecture4

Page 35: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

The world of the computers

Every number is stored in binary

Every number has a certain length (depending of theregister size).

For example:If the register size is 8 then 1 is stored as 00000001.

Cannot store more than a certain number of digits.

CSE 20: Lecture4

Page 36: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

The world of the computers

Every number is stored in binary

Every number has a certain length (depending of theregister size).

For example:If the register size is 8 then 1 is stored as 00000001.

Cannot store more than a certain number of digits.

CSE 20: Lecture4

Page 37: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

The world of the computers

Every number is stored in binary

Every number has a certain length (depending of theregister size).

For example:If the register size is 8 then 1 is stored as 00000001.

Cannot store more than a certain number of digits.

CSE 20: Lecture4

Page 38: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Computer Addition

Let the register size in a computer is 8 bits.

Let x = 11111111 and y = 00000001

What is x + y?Ans: x + y = 100000000.

But the computer sees only the last 8 digits. So it sees00000000.

CSE 20: Lecture4

Page 39: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Computer Addition

Let the register size in a computer is 8 bits.

Let x = 11111111 and y = 00000001

What is x + y?

Ans: x + y = 100000000.

But the computer sees only the last 8 digits. So it sees00000000.

CSE 20: Lecture4

Page 40: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Computer Addition

Let the register size in a computer is 8 bits.

Let x = 11111111 and y = 00000001

What is x + y?Ans: x + y = 100000000.

But the computer sees only the last 8 digits. So it sees00000000.

CSE 20: Lecture4

Page 41: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Computer Addition

Let the register size in a computer is 8 bits.

Let x = 11111111 and y = 00000001

What is x + y?Ans: x + y = 100000000.

But the computer sees only the last 8 digits. So it sees00000000.

CSE 20: Lecture4

Page 42: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Boolean Algebra

Boolean Algebra has two basic digit: 1 and 0.

One can think of these as True and False

Used to represent data and used in logic.

CSE 20: Lecture4

Page 43: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Boolean Algebra

Boolean Algebra has two basic digit: 1 and 0.

One can think of these as True and False

Used to represent data and used in logic.

CSE 20: Lecture4

Page 44: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Boolean Algebra

Boolean Algebra has two basic digit: 1 and 0.

One can think of these as True and False

Used to represent data and used in logic.

CSE 20: Lecture4

Page 45: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Boolean Algebra

Boolean Algebra has two basic digit: 1 and 0.

One can think of these as True and False

Used to represent data and used in logic.

CSE 20: Lecture4

Page 46: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Representing Data as sets

Sets

For example:

Set of names of all studentsSet of letters in the english alphabetSet of digits. {0, 1, . . . , 9} or {0, 1}

Unordered Sets

Ordered Sets(Also called LIST/STRINGS/VECTORS)

CSE 20: Lecture4

Page 47: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Representing Data as sets

SetsFor example:

Set of names of all students

Set of letters in the english alphabetSet of digits. {0, 1, . . . , 9} or {0, 1}

Unordered Sets

Ordered Sets(Also called LIST/STRINGS/VECTORS)

CSE 20: Lecture4

Page 48: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Representing Data as sets

SetsFor example:

Set of names of all studentsSet of letters in the english alphabet

Set of digits. {0, 1, . . . , 9} or {0, 1}Unordered Sets

Ordered Sets(Also called LIST/STRINGS/VECTORS)

CSE 20: Lecture4

Page 49: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Representing Data as sets

SetsFor example:

Set of names of all studentsSet of letters in the english alphabetSet of digits. {0, 1, . . . , 9} or {0, 1}

Unordered Sets

Ordered Sets(Also called LIST/STRINGS/VECTORS)

CSE 20: Lecture4

Page 50: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Representing Data as sets

SetsFor example:

Set of names of all studentsSet of letters in the english alphabetSet of digits. {0, 1, . . . , 9} or {0, 1}

Unordered Sets

Ordered Sets(Also called LIST/STRINGS/VECTORS)

CSE 20: Lecture4

Page 51: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Representing Data as sets

SetsFor example:

Set of names of all studentsSet of letters in the english alphabetSet of digits. {0, 1, . . . , 9} or {0, 1}

Unordered Sets

Ordered Sets(Also called LIST/STRINGS/VECTORS)

CSE 20: Lecture4

Page 52: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Cartesian Product

Let A be a set

An is the set of all ordered subsets (with repetitions) Aof size n

{0, 1}n the set of all “strings” of 0 and 1 of length n.

CSE 20: Lecture4

Page 53: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Cartesian Product

Let A be a set

An is the set of all ordered subsets (with repetitions) Aof size n

{0, 1}n the set of all “strings” of 0 and 1 of length n.

CSE 20: Lecture4

Page 54: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

Cartesian Product

Let A be a set

An is the set of all ordered subsets (with repetitions) Aof size n

{0, 1}n the set of all “strings” of 0 and 1 of length n.

CSE 20: Lecture4

Page 55: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

A little bit of counting

Q: How many elements are there in the set {0, 1}n?

Ans: 2n.

CSE 20: Lecture4

Page 56: CSE 20 - Lecture 4: Introduction to Boolean algebra · Sometimes called Boolean representation after English mathematician George Boole. Computer talks in this language. CSE 20: Lecture4

A little bit of counting

Q: How many elements are there in the set {0, 1}n?Ans: 2n.

CSE 20: Lecture4