boolean algebragorskicompsci.ca/ics2o/unit2/ppt1_booleanalgebra.pdf · operator meaning >...

52
Boolean Algebra Result in a True or False

Upload: others

Post on 26-May-2020

28 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

Boolean AlgebraResult in a True or False

Page 2: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

Named for

GeorgeBoole1815-1865

Page 3: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

&&

||

!

And

Or

Not

Some Java Symbols for you...

Page 4: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than
Page 5: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

Can you read this shirt now?

Page 6: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

Boolean Algebra evaluates to only two answers.

True False||

Page 7: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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 8: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than
Page 9: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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

num > 6

Page 10: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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

num > 6

num >= 5

F

Page 11: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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

num > 6

num >= 5

num != 6

F

T

Page 12: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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

num > 6

num >= 5

num != 6

num < 2F

T

T

Page 13: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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 14: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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 15: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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 16: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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 Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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 Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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 Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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 Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

Says: “Yes or no? I won’t

take anything else for an answer!”

Page 21: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than
Page 22: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

Would you like some cake && ice cream?

Page 23: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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

True False

Page 24: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

&& =

&& =

&& =

&& =

Where’s my ice cream?

Where’s my cake?

Where’s my cake and ice

cream?

Page 25: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

Value 1 Value 2 Answer

T && T = T

T && F = F

F && T = F

F && F = F

And Truth Table

Page 26: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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 27: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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 28: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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 29: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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 30: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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 Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

What can go in the recycling bin?

Paper || Plastic

Page 32: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

|| =

|| =

|| =

|| =

Page 33: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

Value 1 Value 2 Answer

T || T = T

T || F = T

F || T = T

F || F = F

OR Truth Table

Page 34: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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 35: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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 36: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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 37: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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 38: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than
Page 40: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

Value Answer

!T = F

!F = T

NOT Truth Table

Page 41: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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 42: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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 43: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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 44: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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 45: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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 46: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

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 47: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than
Page 48: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than
Page 49: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

Some jokes.

Page 50: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than

You can’t handle the truth!

Page 51: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than
Page 52: Boolean Algebragorskicompsci.ca/ICS2O/Unit2/ppt1_BooleanAlgebra.pdf · Operator Meaning > Greater than >= Greater than or equal to < Less than