23
New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

Embed Size (px)

Citation preview

Page 1: New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

New Mexico Computer Science For All

Booleans and Logic

Maureen Psaila-Dombrowski

Page 2: New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

Boolean•Boolean - EASY

Can have one of two values ▫true or false▫on or off▫1 or 0

•Boolean Expressions Evaluate to be true or false

•Boolean Operators Operators that are used with Booleans

•Boolean Math/Algebra or Boolean Logic Uses Booleans and Boolean operators Used in computers

Page 3: New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

Boolean Expressions•A simple use of Boolean concept

•Expressions that evaluate to True or False

•They use comparison operators (=, <, >, <= or >=)

Compare two sides – numbers, variables, expressions

Ask a specific question – Is the expression TRUE or FALSE

?

•You have used them in math before. 24 + 13 = ? Addition 3724 + 13 = 37 ? Boolean true24 + 13 = 40 ? Boolean false

Page 4: New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

Boolean Expressions (continued)

Expression(Comparison

Operator) Question Asked

L = R The left equals the right, True or False?

3 + 5 = 8 3 + 5 equals 8, True or False? TRUE

L < R The left is less than the right, True or False?

16/4 < 3 16/4 is less than 3, True or False? FALSE

L > R The left is greater than the right, True or False?

50*100 > 50050*100 is greater than 500, True or False? TRUE

Page 5: New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

Boolean Operators

• Three basic ones: AND, OR , NOT Most other operators are based on these

• Compares Boolean values or expressions or change them

• Evaluates to a Boolean (True or False, On or Off, 1 or 0)

• Rules for each operator are different

BooleanValue

OrExpression

(True or False)

BooleanOperator

BooleanValue

OrExpression

(True or False)

Boolean Value

(True or False)

Page 6: New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

Boolean Logic•Also know as Boolean Algebra or Boolean

Math

•What is it?▫Only two values.▫The Math of comparing and manipulating

Booleans

•So what?▫Most important principle of modern computers.

•Developed in the 1850s by George Boole▫A founder of computer science

Page 7: New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

• Boolean Logic Expression: A AND B• For A AND B to be true BOTH A AND B

must be true (Both Sides Must Be True)• AND Truth Table:

Boolean Logic (continued)

ANDA

Boolean Expression

Boolean Operator

BBoolean

Expression

Evaluates to

TRUE AND TRUE TRUE

TRUE AND FALSE FALSE

FALSE AND TRUE FALSE

FALSE AND FALSE FALSE

Page 8: New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

Boolean Logic

Lets look at an example: Marbles

Page 9: New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

Boolean Logic

Lets look at an example: Marbles

Blue? = falseRed? = true

Marble? = true

Page 10: New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

Boolean LogicWe can group the marbles:• Is there a set of Marble? = true

Marble? = true

Page 11: New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

Boolean Logic

Blue? = true

Red? = true

We can also group the marbles:• The marble is Blue? = true ?• The marble is Red? = true ?

Page 12: New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

Boolean Logic

Blue? = true

Red? = true

Is there a set:(Marble? = true) AND (Blue? = true) is true

Is there a set: (Blue? = true) AND (Red? = true) is true?

Page 13: New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

Blue? = true Red? = true

Boolean Logic

Find the set with (Blue? = true) AND (Red? = true)Find the set with (Blue? = true) AND (Green? = true) Find the set with (Purple? = true) AND (Green? = true)

Page 14: New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

• For A OR B to be true EITHER A OR B can be true (Only One Side Needs to be True)

• OR Truth Table:

Boolean Logic (continued)

ORA

Boolean Expression

Boolean Operator

BBoolean

Expression

Evaluates to

TRUE OR TRUE TRUE

TRUE OR FALSE TRUE

FALSE OR TRUE TRUE

FALSE OR FALSE FALSE

Page 15: New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

Blue? = true

Red? = true

Find the set with (Blue? = true) OR (Red? = true)

Boolean Logic (continued)

Page 16: New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

Blue? = true Red? = true

Find the set with (Blue? = true) OR (Red? = true)Find the set with (Blue? = true) OR (Green? = true)Find the set with (Purple? = true) OR (Green? = true)

Boolean Logic (continued)

Page 17: New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

Boolean Logic (continued)

NOTBoolean

Operator Boolean

ExpressionEvaluates

to

NOT TRUE FALSE

NOT FALSE TRUE

NOT is really easy – it just gives you the opposite value

Page 18: New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

Blue? = true

Red? = true

Find the set with (NOT Blue? = true)Find the set with (NOT Red? = true)Find the set with (NOT Purple? = true)

Boolean Logic (continued)

Page 19: New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

Blue? = true Red

Find the set with (NOT Red? = true)Find the set with (NOT Blue? = true)Find the set with (NOT Purple? = true)

Boolean Logic (continued)

Page 20: New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

•Order of Operation

1. Parenthesis2. NOT3. AND 4. OR

•Examples:

NOT true AND true false AND true FALSE

NOT ( false AND true ) NOT false TRUE

true OR false AND true true OR false TRUE

( true OR false ) AND true true AND true TRUE

Boolean Logic (continued)

Page 21: New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

Booleans in Computer Science

•Search Engines (Average User)▫Use Boolean Logic to limit: AND, OR, NOT▫Boolean Order of Operations holds

•Conditionals (Programmer)▫Boolean Expressions and Boolean Logic▫Used in Conditionals

Page 22: New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

Booleans in Computer Science•Digital Gates (Boolean Gates) in

Chips/Circuits (Hardware Engineer)

▫Fundamental building block of a computer▫Uses Booleans

True and False 1’s and 0’s▫Boolean Logic

To figure out if gate is open/closed

Page 23: New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski

Summary •Booleans can have only two values •Boolean expressions

Use comparison operators (=, <, >) Evaluate to TRUE or FALSE

•Boolean Operators Three Basic Operators: AND, OR, NOT Compare Boolean values/expressions or

change them Evaluate to TRUE or FALSE

•Boolean Logic• Use Boolean Operators: AND, OR, NOT• The math of comparing and manipulating

Booleans.• Order of Operation: ( ), NOT, AND, OR