Boolean Algebra Boolean Assertions Statements that will result in true or false outcomes a > 50 = =...
-
Upload
laurence-dixon -
Category
Documents
-
view
220 -
download
3
Transcript of Boolean Algebra Boolean Assertions Statements that will result in true or false outcomes a > 50 = =...
![Page 1: Boolean Algebra Boolean Assertions Statements that will result in true or false outcomes a > 50 = = ba](https://reader036.fdocuments.in/reader036/viewer/2022082613/5697c0301a28abf838cdaac0/html5/thumbnails/1.jpg)
Boolean Algebra
![Page 2: Boolean Algebra Boolean Assertions Statements that will result in true or false outcomes a > 50 = = ba](https://reader036.fdocuments.in/reader036/viewer/2022082613/5697c0301a28abf838cdaac0/html5/thumbnails/2.jpg)
Boolean Assertions
• Statements that will result in true or false outcomes
a > 5 0 = = b a <= b
![Page 3: Boolean Algebra Boolean Assertions Statements that will result in true or false outcomes a > 50 = = ba](https://reader036.fdocuments.in/reader036/viewer/2022082613/5697c0301a28abf838cdaac0/html5/thumbnails/3.jpg)
Negating Boolean Assertions
Rewriting code for easier readability is usually why we negate Boolean assertions
if(!(x < 5))becomes
if( x > = 5)
![Page 4: Boolean Algebra Boolean Assertions Statements that will result in true or false outcomes a > 50 = = ba](https://reader036.fdocuments.in/reader036/viewer/2022082613/5697c0301a28abf838cdaac0/html5/thumbnails/4.jpg)
Boolean Algebra
• Operands(values): true, false• Operators: and (&&) or( | |) not(!)
![Page 5: Boolean Algebra Boolean Assertions Statements that will result in true or false outcomes a > 50 = = ba](https://reader036.fdocuments.in/reader036/viewer/2022082613/5697c0301a28abf838cdaac0/html5/thumbnails/5.jpg)
DeMorgan’s Laws
• not(A or B) = not A and not B!(A || B) = !A && !B
• not(A and B) = not A or not B!(A && B) = !A || ! B
![Page 6: Boolean Algebra Boolean Assertions Statements that will result in true or false outcomes a > 50 = = ba](https://reader036.fdocuments.in/reader036/viewer/2022082613/5697c0301a28abf838cdaac0/html5/thumbnails/6.jpg)
Application of DeMorgan’s Law“Craps”
• If you roll a 7 or 11 on the first roll, you win• If you roll a 2, 3, or 12 on the first roll, you lose• Otherwise on subsequent rolls you want to
roll your original number before you roll a 7 to win
![Page 7: Boolean Algebra Boolean Assertions Statements that will result in true or false outcomes a > 50 = = ba](https://reader036.fdocuments.in/reader036/viewer/2022082613/5697c0301a28abf838cdaac0/html5/thumbnails/7.jpg)
Here is the truth table that proves the first DeMorgan’s Law. not(A or B) = not A and not B
!(A || B) = !A && !B
A B !(A||B) !A !B !A&&!B
true true false false false false
true false false false true false
false true false true false false
false false true true true True
![Page 8: Boolean Algebra Boolean Assertions Statements that will result in true or false outcomes a > 50 = = ba](https://reader036.fdocuments.in/reader036/viewer/2022082613/5697c0301a28abf838cdaac0/html5/thumbnails/8.jpg)
Following is the truth table that proves the second DeMorgan's Law.not(A and B) = not A or not B
!(A && B) = !A || ! B
A B !(A&&B) !A !B !A||!B
true true false false false false
true false true false true true
false true true true false true
false false true true true true
Notice that columns with the titles ! (A && B) and ! A || ! B result in the same answers.
![Page 9: Boolean Algebra Boolean Assertions Statements that will result in true or false outcomes a > 50 = = ba](https://reader036.fdocuments.in/reader036/viewer/2022082613/5697c0301a28abf838cdaac0/html5/thumbnails/9.jpg)
• initial roll – compare• subsequent rolls until you won or lost the game:
do –while with the sentinel: while( !((sum == point) || (sum == 7)) );
while( (sum != point) && (sum != 7) );
![Page 10: Boolean Algebra Boolean Assertions Statements that will result in true or false outcomes a > 50 = = ba](https://reader036.fdocuments.in/reader036/viewer/2022082613/5697c0301a28abf838cdaac0/html5/thumbnails/10.jpg)
Proving Demorgan’s LawI
A B not(A or B) not A not B not A and not B
1 1 0 0 0 0
1 0 0 0 1 0
0 1 0 1 0 0
0 0 1 1 1 1
![Page 11: Boolean Algebra Boolean Assertions Statements that will result in true or false outcomes a > 50 = = ba](https://reader036.fdocuments.in/reader036/viewer/2022082613/5697c0301a28abf838cdaac0/html5/thumbnails/11.jpg)
Proving Demorgan’s LawII
A B not(A and B) not A not B not A or not B
1 1
1 0
0 1
0 0