DeMorgans Laws

35
Warm-up A Little Boolean Review DeMorgan’s Laws: !(P&&Q) = ___________________ !(P || Q) = ____________________

description

DeMorgans Laws practice Q&A for AP Computer Science A

Transcript of DeMorgans Laws

Page 1: DeMorgans Laws

Warm-upA Little Boolean Review

DeMorgan’s Laws:!(P&&Q) = ___________________!(P || Q) = ____________________

Page 2: DeMorgans Laws

Warm-upA Little Boolean Review

DeMorgan’s Laws:!(P&&Q) = !P || !Q!(P || Q) = !P && !Q

Page 3: DeMorgans Laws

Warm-upA Little Boolean Review

! (x > = y ) = _______________

! ( x > y ) = _______________

Page 4: DeMorgans Laws

Warm-upA Little Boolean Review

Use DeMorgan’s Law to change these:

! (x > = y && a < b ) = ____________

! ( x >= y || a >= b ) = _____________

Page 5: DeMorgans Laws

Warm-upA Little Boolean Review

Use DeMorgan’s Law to change these:

! (x > = y && a < b ) = x<y || a>=b

! ( x >= y || a >= b ) = x<y || a<b

Page 6: DeMorgans Laws

More Boolean!

(y>10000) || ( x>1000 && x<1500 )

a. (y>10000 || x>1000) && (y>10000 || x<1500)

b. (y>10000 || x>1000) || (y>10000 || x<1500)

c. (y>10000) && (x>1000 || x<1500 )

d. (y>10000 && x>1000) || (y>10000 && x<1500)

e. (y > 10000 && x>1000) && (y>10000 && x<1500)

Page 7: DeMorgans Laws

Use the old distributive property:

(y>10000) || ( x>1000 && x<1500 )

A * (B + C) = A * B + A * C

a. (y>10000 || x>1000) && (y>10000 || x<1500)

b. (y>10000 || x>1000) || (y>10000 || x<1500)

c. (y>10000) && (x>1000 || x<1500 )

d. (y>10000 && x>1000) || (y>10000 && x<1500)

e. (y > 10000 && x>1000) && (y>10000 && x<1500)

Page 8: DeMorgans Laws

Use the old distributive property:

(y>10000) || ( x>1000 && x<1500 )

A * (B + C) = A * B + A * C

(y>10000 || x>1000)

a. (y>10000 || x>1000) && (y>10000 || x<1500)

b. (y>10000 || x>1000) || (y>10000 || x<1500)

c. (y>10000) && (x>1000 || x<1500 )

d. (y>10000 && x>1000) || (y>10000 && x<1500)

e. (y > 10000 && x>1000) && (y>10000 && x<1500)

Page 9: DeMorgans Laws

Use the old distributive property:

(y>10000) || ( x>1000 && x<1500 )

A * (B + C) = A * B + A * C

(y>10000 || x>1000) &&

a. (y>10000 || x>1000) && (y>10000 || x<1500)

b. (y>10000 || x>1000) || (y>10000 || x<1500)

c. (y>10000) && (x>1000 || x<1500 )

d. (y>10000 && x>1000) || (y>10000 && x<1500)

e. (y > 10000 && x>1000) && (y>10000 && x<1500)

Page 10: DeMorgans Laws

Use the old distributive property:

(y>10000) || ( x>1000 && x<1500 )

A * (B + C) = A * B + A * C

(y>10000 || x>1000) && (y>10000 || x<1500)

a. (y>10000 || x>1000) && (y>10000 || x<1500)

b. (y>10000 || x>1000) || (y>10000 || x<1500)

c. (y>10000) && (x>1000 || x<1500 )

d. (y>10000 && x>1000) || (y>10000 && x<1500)

e. (y > 10000 && x>1000) && (y>10000 && x<1500)

Page 11: DeMorgans Laws

Use the old distributive property:

(y>10000) || ( x>1000 && x<1500 )

A * (B + C) = A * B + A * C

(y>10000 || x>1000) && (y>10000 || x<1500)

a. (y>10000 || x>1000) && (y>10000 || x<1500)

b. (y>10000 || x>1000) || (y>10000 || x<1500)

c. (y>10000) && (x>1000 || x<1500 )

d. (y>10000 && x>1000) || (y>10000 && x<1500)

e. (y > 10000 && x>1000) && (y>10000 && x<1500)

Page 12: DeMorgans Laws

(x==y && x!=z) || (x!=y && x==z)

(x==y || x==z) && (x!=y || x!= z)

(x==y) != (x==z)Let’s see what happens if the last statement is true.

Page 13: DeMorgans Laws

(x==y && x!=z) || (x!=y && x==z)

(x==y || x==z) && (x!=y || x!= z)

(x==y) != (x==z)Let’s see what happens if the last statement is true.

The value of the left side and the right side can’t be the same. They must be “Not Equal”. One side must be true and the other side must be false.

Page 14: DeMorgans Laws

(x==y && x!=z) || (x!=y && x==z)

(x==y || x==z) && (x!=y || x!= z)

(x==y) != (x==z)Since x = y or x = z, but x doesn’t equal y and z. If all three are equal, then both the left and right would be true, and would not meet the != condition

Page 15: DeMorgans Laws

(x==y && x!=z) || (x!=y && x==z)

(x==y || x==z) && (x!=y || x!= z)

(x==y) != (x==z)In other words, they can’t all be the same.

Furthermore, if all three are different, then both the left and right side would be false, which means they don’t meet the != condition.

Page 16: DeMorgans Laws

(x==y && x!=z) || (x!=y && x==z)

(x==y || x==z) && (x!=y || x!= z)

(x==y) != (x==z)Conclusion: x is equal to either y or z. Does this condition make the two statements above true?

Page 17: DeMorgans Laws

(x==y && x!=z) || (x!=y && x==z)

(x==y || x==z) && (x!=y || x!= z)

(x==y) != (x==z)

Knowing this, let’s look at this statement.

Do the same conditions make it true?

Page 18: DeMorgans Laws

(x==y && x!=z) || (x!=y && x==z)

(x==y || x==z) && (x!=y || x!= z)

(x==y) != (x==z)

If x equals y and does not equal z, the left side is true

Since the operator is OR, the statement is true no matter what is on the right side.

Page 19: DeMorgans Laws

(x==y && x!=z) || (x!=y && x==z)

(x==y || x==z) && (x!=y || x!= z)

(x==y) != (x==z)

If x equals z and does not equal y, the right side is true

Since the operator is OR, the statement is true no matter what is on the left side.

Page 20: DeMorgans Laws

(x==y && x!=z) || (x!=y && x==z)

(x==y || x==z) && (x!=y || x!= z)

(x==y) != (x==z)

So, the third and first meet the same conditions

when evaluating to “true”. How about the middle?

Page 21: DeMorgans Laws

(x==y && x!=z) || (x!=y && x==z)

(x==y || x==z) && (x!=y || x!= z)

(x==y) != (x==z)

If x equals either ‘y’ or ‘z’, the left is true. If the ‘x’

is different than either ‘y’ or ‘z’, the right is true.

Page 22: DeMorgans Laws

(x==y && x!=z) || (x!=y && x==z)

(x==y || x==z) && (x!=y || x!= z)

(x==y) != (x==z)

So given the exact conditions again, that x equals

either y or z, but not both, the middle statement is true.

Page 23: DeMorgans Laws

(x==y && x!=z) || (x!=y && x==z)

(x==y || x==z) && (x!=y || x!= z)

(x==y) != (x==z)You may figure out the condition that make the last statement false and follow the same steps to compare those conditions to the other two statements

Page 24: DeMorgans Laws

(x==y && x!=z) || (x!=y && x==z)

(x==y || x==z) && (x!=y || x!= z)

(x==y) != (x==z)Hint: This statement is false only if

* all three are the same, * all three are different, * or y = z but not x.

Page 25: DeMorgans Laws

De Morgan’s Laws

• !(a&&b) = !a || !b

• !(a || b) = !a && !b

Page 26: DeMorgans Laws

Using DeMorgans LawsThe expression !((x<=y) && (y>5)) is

equivilant to which of the following?

• A. (x<=y) && (y>5)

• B. (x<=y) || (y>5)

• C. (x>=y) || (y<5)

• D. (x>y) || (y<=5)

• E. (x>y) && (y<=5)

Page 27: DeMorgans Laws

Using DeMorgans LawsThe expression !((x<=y) && (y>5)) is

equivilant to which of the following?

• A. (x<=y) && (y>5)

• B. (x<=y) || (y>5)

• C. (x>=y) || (y<5)

• D. (x>y) || (y<=5)

• E. (x>y) && (y<=5)

Page 28: DeMorgans Laws

Using DeMorgans LawsThe expression !(x>y && y<=0) is equivilant

to which of the following?

• A. !(x<=y) || (y>0)

• B. x>y && y<=0

• C. x<=y || y>0

• D. x>y || y<0

• E. x<=y && y<=0

Page 29: DeMorgans Laws

Using DeMorgans LawsThe expression !(x>y && y<=0) is equivilant

to which of the following?

• A. !(x<=y) || (y>0)

• B. x>y && y<=0

• C. x<=y || y>0

• D. x>y || y<0

• E. x<=y && y<=0

Page 30: DeMorgans Laws

Given that x is true, y is true, and z is false, which of the following expressions will evaluate to false?

A. (x&&y) || zB. (x || y) && zC. y || (x&&z)D. x || (y && z)E. x && (y || z)

Page 31: DeMorgans Laws

Given that x is true, y is true, and z is false, which of the following expressions will evaluate to false?

A. (x&&y) || zB. (x || y) && zC. y || (x&&z)D. x || (y && z)E. x && (y || z)

Page 32: DeMorgans Laws

Assuming that c and d are boolean variables, the expression !c || d is equivalent to which of the following?

• A. !(c && d)

• B. !(c && !d)

• C. c && !d

• D. !(c || !d)

• E. !(!c && d)

Page 33: DeMorgans Laws

Assuming that c and d are boolean variables, the expression !c || d is equivalent to which of the following?

• A. !(c && d)

• B. !(c && !d)

• C. c && !d

• D. !(c || !d)

• E. !(!c && d)

Page 34: DeMorgans Laws

Assuming that a and b are boolean when is the following expression true:

!(!a || b) || (!a && b)

• A. If and only if a and b have different values

• B. If and only if a and b have the same value

• C. If and only if both a and b are true

• D. If and only if both a and b are false

• E. None

Page 35: DeMorgans Laws

Assuming that a and b are boolean when is the following expression true:

!(!a || b) || (!a && b)

• A. If and only if a and b have different values

• B. If and only if a and b have the same value

• C. If and only if both a and b are true

• D. If and only if both a and b are false

• E. None