Boolean Algebra
Boolean Assertions Statements that will result in true or false outcomes a > 50 = = ba <= b
Negating Boolean Assertions Rewriting code for easier readability is usually why we negate Boolean assertions if(!(x < 5)) becomes if( x > = 5)
Boolean Algebra Operands(values):true, false Operators:and (&&) or( | |) not(!)
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
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
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 AB !(A||B)!A!B!A&&!B true false truefalse truefalse truefalsetruefalse true True
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 AB !(A&&B)!A!B!A||!B true false truefalsetruefalsetrue falsetrue falsetrue false true Notice that columns with the titles ! (A && B) and ! A || ! B result in the same answers.
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) );
Proving Demorgan’s Law I ABnot(A or B)not Anot Bnot A and not B
Proving Demorgan’s Law II ABnot(A and B)not Anot Bnot A or not B