boolean algebra - gorski compscigorskicompsci.ca/ics3u/unit1/ppt_booleanalgebra.pdf · boole...

54
Boolean Algebra Result in a True or False

Upload: others

Post on 11-Aug-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Boolean AlgebraResult in a True or False

Page 2: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Named for

GeorgeBoole1815-1865

Page 3: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Boolean Algebra• Mathematical expressions that results in

either true or false.• They can be joined to make more

complex Boolean expression using Boolean Operators like AND, OR, NOT.

• They are used to control if statements and loops. This means that Boolean Algebra is one of the cornerstones of computer science.

Page 4: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

&&

||

!

And

Or

Not

Some Java Symbols for you...

Page 5: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?
Page 6: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Can you read this shirt now?

Page 7: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Boolean Algebra evaluates to only two answers.

True False||

Page 8: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Operator Meaning

> Greater than

>= Greater than or equal to

< Less than

<= Less than or equal to

== Equal to

!= Not equal to

.equals() Equal for strings

Relational Operators

Page 9: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?
Page 10: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

The variable num holds the value of 5.Are these true or false?

num > 6

Page 11: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

The variable num holds the value of 5.Are these true or false?

num > 6

num >= 5

F

Page 12: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

The variable num holds the value of 5.Are these true or false?

num > 6

num >= 5

num != 6

F

T

Page 13: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

The variable num holds the value of 5.Are these true or false?

num > 6

num >= 5

num != 6

num < 2F

T

T

Page 14: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

The variable num holds the value of 5.Are these true or false?

num > 6

num >= 5

num != 6

num < 2

num == 4

F

T

T

F

Page 15: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

The variable num holds the value of 5.Are these true or false?

num > 6

num >= 5

num != 6

num < 2

num == 4

!(num==3)

F

T

T

F

F

Page 16: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

The variable num holds the value of 5.Are these true or false?

num > 6

num >= 5

num != 6

num < 2

num == 4

!(num==3)

F

T

T

F

F

T

Page 17: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

The variable num holds the value of 5.Are these true or false?

num > 6

num >= 5

num != 6

num < 2

num == 4

!(num==3)

F

T

T

F

F

T

Page 18: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

The variable num holds the value of 5.Are these true or false?

num > 6

num >= 5

num != 6

num < 2

num == 4

!(num==3)

F

T

T

F

F

T

Page 19: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

The variable num holds the value of 5.Are these true or false?

num > 6

num >= 5

num != 6

num < 2

num == 4

!(num==3)

F

T

T

F

F

T

Page 20: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

The variable num holds the value of 5.Are these true or false?

num > 6

num >= 5

num != 6

num < 2

num == 4

!(num==3)

F

T

T

F

F

T

Page 21: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Says: “Yes or no? I won’t

take anything else for an answer!”

Page 22: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?
Page 23: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Would you like some cake && ice cream?

Page 24: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Depending on what you give them, the kid is either happy or sad.

True False

Page 25: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

&& =

&& =

&& =

&& =

Where’s my ice cream?

Where’s my cake?

Where’s my cake and ice

cream?

Page 26: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Value 1 Value 2 Answer

T && T = T

T && F = F

F && T = F

F && F = F

And Truth Table

Page 27: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Ans

T && T = T

T && F = F

F && T = F

F && F = F

Evaluate

If x is 4 and y is 7...

(x>3) && (x<9)

Page 28: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Ans

T && T = T

T && F = F

F && T = F

F && F = F

Evaluate

If x is 4 and y is 7...

(x>3) && (x<9)= (4>3) && (4<9)

Page 29: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Ans

T && T = T

T && F = F

F && T = F

F && F = F

Evaluate

If x is 4 and y is 7...

(x>3) && (x<9)= (4>3) && (4<9)= T && T

Page 30: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Ans

T && T = T

T && F = F

F && T = F

F && F = F

Evaluate

If x is 4 and y is 7...

(x>3) && (x<9)= (4>3) && (4<9)= T && T= T

Page 31: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Ans

T && T = T

T && F = F

F && T = F

F && F = F

Evaluate

If x is 4 and y is 7...

(x>3) && (x<9)= (4>3) && (4<9)= T && T= T

Page 32: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

What can go in the recycling bin?

Paper || Plastic

Page 33: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

|| =

|| =

|| =

|| =

Page 34: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Value 1 Value 2 Answer

T || T = T

T || F = T

F || T = T

F || F = F

OR Truth Table

Page 35: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Ans

T && T = T

T && F = F

F && T = F

F && F = F

Evaluate

Ans

T || T = T

T || F = T

F || T = T

F || F = F

If x is 4 and y is 7...

(x==3) || (y>9)

Page 36: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Ans

T && T = T

T && F = F

F && T = F

F && F = F

Evaluate

Ans

T || T = T

T || F = T

F || T = T

F || F = F

If x is 4 and y is 7...

(x==3) || (y>9)= (4==3) || (7>9)

Page 37: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Ans

T && T = T

T && F = F

F && T = F

F && F = F

Evaluate

Ans

T || T = T

T || F = T

F || T = T

F || F = F

If x is 4 and y is 7...

(x==3) || (y>9)= (4==3) || (7>9)= F || F

Page 38: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Ans

T && T = T

T && F = F

F && T = F

F && F = F

Evaluate

Ans

T || T = T

T || F = T

F || T = T

F || F = F

If x is 4 and y is 7...

(x==3) || (y>9)= (4==3) || (7>9)= F || F= F

Page 39: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?
Page 41: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Value Answer

!T = F

!F = T

NOT Truth Table

Page 42: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Ans

T && T = T

T && F = F

F && T = F

F && F = F

Evaluate

Ans

T || T = T

T || F = T

F || T = T

F || F = F

Ans

!T = F

!F = T

If x is 4 and y is 7...

!(!(x<=7) && !(y!=9))

Page 43: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Ans

T && T = T

T && F = F

F && T = F

F && F = F

Evaluate

Ans

T || T = T

T || F = T

F || T = T

F || F = F

Ans

!T = F

!F = T

If x is 4 and y is 7...

!(!(x<=7) && !(y!=9))= !(!(4<=7) && !(7!=9))

Page 44: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Ans

T && T = T

T && F = F

F && T = F

F && F = F

Evaluate

Ans

T || T = T

T || F = T

F || T = T

F || F = F

Ans

!T = F

!F = T

If x is 4 and y is 7...

!(!(x<=7) && !(y!=9))= !(!(4<=7) && !(7!=9))= !(!T && !T)

Page 45: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Ans

T && T = T

T && F = F

F && T = F

F && F = F

Evaluate

Ans

T || T = T

T || F = T

F || T = T

F || F = F

Ans

!T = F

!F = T

If x is 4 and y is 7...

!(!(x<=7) && !(y!=9))= !(!(4<=7) && !(7!=9))= !(!T && !T)= !(F && F)

Page 46: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Ans

T && T = T

T && F = F

F && T = F

F && F = F

Evaluate

Ans

T || T = T

T || F = T

F || T = T

F || F = F

Ans

!T = F

!F = T

If x is 4 and y is 7...

!(!(x<=7) && !(y!=9))= !(!(4<=7) && !(7!=9))= !(!T && !T)= !(F && F)=!F

Page 47: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Ans

T && T = T

T && F = F

F && T = F

F && F = F

Evaluate

Ans

T || T = T

T || F = T

F || T = T

F || F = F

Ans

!T = F

!F = T

If x is 4 and y is 7...

!(!(x<=7) && !(y!=9))= !(!(4<=7) && !(7!=9))= !(!T && !T)= !(F && F)=!F=T

Page 48: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?
Page 49: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?
Page 50: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

Some jokes.

Page 51: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?

You can’t handle the truth!

Page 52: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?
Page 53: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?
Page 54: Boolean Algebra - Gorski CompScigorskicompsci.ca/ICS3U/Unit1/ppt_BooleanAlgebra.pdf · Boole 1815-1865 && ||! And Or Not Some Java Symbols for you... Can you read this shirt now?