copyright © texas education agency, 20131 computer programming boolean logic
TRANSCRIPT
![Page 1: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/1.jpg)
Copyright © Texas Education Agency, 2013 1
Computer Programming
Boolean Logic
![Page 2: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/2.jpg)
What is Boolean Logic?
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 2
Boolean logic is a system for determining the truth of a statement (or expression) based on whether certain variables are true or false.
For example: In the statement, “I will go for a walk if it is sunny,” the decision is based on whether it is true that it is ‘sunny.’
Copyright © Texas Education Agency, 2013 2
![Page 3: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/3.jpg)
Historical Note
George Boole (1815-1864) was an English mathematician who devised a system of symbols and equations to represent logical decisions.
Boolean Algebra was not widely used until the invention of computers. Boolean logic expressions are used to design electronic circuits and to represent decision-making in software
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 3Copyright © Texas Education Agency, 2013 3
![Page 4: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/4.jpg)
How is Boolean Logic used?
A combination of conditions, variables, and operators are used to determine if an expression is True or False.
It can also be used to determine which elements can be members of a given set.
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 4Copyright © Texas Education Agency, 2013 4
![Page 5: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/5.jpg)
How are these categories different?
Brown-eyed AND Male
Brown-eyed OR Male
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 5Copyright © Texas Education Agency, 2013 5
![Page 6: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/6.jpg)
Who would be in these groups?
NOT male AND wearing jeans
NOT <16
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 6Copyright © Texas Education Agency, 2013 6
![Page 7: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/7.jpg)
Like Mathematics, Boolean logic has operators
Mathematic Operators + - x / =
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 7Copyright © Texas Education Agency, 2013 7
![Page 8: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/8.jpg)
Boolean Operators
&& ( AND )
|| ( OR )
! ( NOT )
Cheese || Pepperoni && !Anchovies
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 8Copyright © Texas Education Agency, 2013 8
![Page 9: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/9.jpg)
Like Math, Boolean logic has an order of operations
Mathematic Order of Operations is PEMDAS Parentheses first Exponents next Multiplication and Division Addition and Subtraction
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 9Copyright © Texas Education Agency, 2013 9
![Page 10: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/10.jpg)
Order of Boolean Operations
Parentheses are not operators, but indicate grouping, consider these first.
NOT (!) must be considered next.
AND ( && ) is considered next.
OR ( || ) is considered last.
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 10Copyright © Texas Education Agency, 2013 10
![Page 11: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/11.jpg)
!Tall && Blonde || Rich
1. Consider the NOT first. !Tall is short.
2. Consider the AND next. !Tall and Blonde, in other words, Short and Blonde.
3. Consider the OR next.
This person can be either Short and Blonde, or they can be Rich. They can also be Short, Blonde, and Rich.
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 11Copyright © Texas Education Agency, 2013 11
![Page 12: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/12.jpg)
Order of Operations
Parentheses first, then NOT (!) , then && , then ||
!Tall && Blonde || Rich
!(Tall && Blonde) || Rich
!Tall && !Blonde || Rich
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 12Copyright © Texas Education Agency, 2013 12
![Page 13: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/13.jpg)
Venn Diagrams
Venn Diagrams can be used to visualize Boolean expressions.
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 13Copyright © Texas Education Agency, 2013 13
![Page 14: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/14.jpg)
Venn Diagram
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 14
A B
A && B
Copyright © Texas Education Agency, 2013 14
![Page 15: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/15.jpg)
Where is !A
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 15
A B
Copyright © Texas Education Agency, 2013 15
![Page 16: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/16.jpg)
Where is A || B ?
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 16
A B
Copyright © Texas Education Agency, 2013 16
![Page 17: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/17.jpg)
Truth Tables
Truth tables are used to evaluate possible combinations of variables and operators.
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 17Copyright © Texas Education Agency, 2013 17
![Page 18: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/18.jpg)
A || B (A OR B)
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 18
A B A || B
True True True
True False True
False True True
False False False
Copyright © Texas Education Agency, 2013 18
![Page 19: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/19.jpg)
A && B (A AND B)
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 19
A B A && B
True True True
True False False
False True False
False False False
Copyright © Texas Education Agency, 2013 19
![Page 20: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/20.jpg)
!A (NOT A)
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 20
A !A
True False
False True
Copyright © Texas Education Agency, 2013 20
![Page 21: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/21.jpg)
!A || B (NOT A OR B)
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 21
A B !A || B
True True True
True False False
False True True
False False True
Copyright © Texas Education Agency, 2013 21
![Page 22: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/22.jpg)
Check for Understanding
Determining the results of a Boolean expression is known as evaluating it.
All Boolean expressions evaluate to either True or False
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 22Copyright © Texas Education Agency, 2013 22
![Page 23: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/23.jpg)
Evaluate: What would be printed, A or B?
boolean blonde = false;
if ( blonde)
System.out.println(“A”);
if ( !blonde)
System.out.println(“B”);
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 23Copyright © Texas Education Agency, 2013 23
![Page 24: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/24.jpg)
Evaluate: What would be printed, A or B?
boolean tall = false;
boolean male = true;
if ( male && tall)
System.out.println(“A”);
if ( male || tall)
System.out.println(“B”);
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 24Copyright © Texas Education Agency, 2013 24
![Page 25: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/25.jpg)
Evaluate: What would be printed, A or B?
boolean x = false;
boolean y = true;
if ( x && y)
System.out.println(“A”);
if ( !x && y)
System.out.println(“B”);
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 25Copyright © Texas Education Agency, 2013 25
![Page 26: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/26.jpg)
Shade in A || !B
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 26
A B
Copyright © Texas Education Agency, 2013 26
![Page 27: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/27.jpg)
Shade in A && !B
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 27
A B
Copyright © Texas Education Agency, 2013 27
![Page 28: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/28.jpg)
Shade in !A && !B
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 28
A B
Copyright © Texas Education Agency, 2013 28
![Page 29: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/29.jpg)
Will it print?
boolean x = true;
boolean y = false;
if ( x && !y)
System.out.print(“A”);
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 29Copyright © Texas Education Agency, 2013 29
![Page 30: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/30.jpg)
Will it print?
boolean x = true;
boolean y = false;
if (! x || y)
System.out.print(“A”);
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 30Copyright © Texas Education Agency, 2013 30
![Page 31: Copyright © Texas Education Agency, 20131 Computer Programming Boolean Logic](https://reader036.vdocuments.site/reader036/viewer/2022062806/5697c0301a28abf838cdaab8/html5/thumbnails/31.jpg)
With what you know…
Can you evaluate a boolean expression?
© UNT in partnership with TEA IT: [Computer Programming] - [Boolean Logic] 31Copyright © Texas Education Agency, 2013 31