## Truth Tables and De Morgan's Rules

Read this chapter, which discusses Boolean variables as used in decision tables. Truth tables are used to collect variables and their values relative to decisions that have to be made within control structures.

### 9. Equivalent Boolean Expressions

**Answer:**

speed > 2000 | (speed <= 2000) | !(speed <= 2000) |
---|---|---|

F | T | F |

T | F | T |

# Equivalent Boolean Expressions

The original program fragment used this boolean expression

!(speed > 2000 && memory > 512)

which is explained in the following truth table (repeated from a previous page):

speed > 2000 | memory > 512 | speed > 2000 && memory > 512 | !(speed > 2000 && memory > 512) |
---|---|---|---|

F | F | F | T |

F | T | F | T |

T | F | F | T |

T | T | T | F |

An equivalent program fragment used this boolean expression

speed <= 2000 || memory <= 512

which is explained in the following truth table:

speed > 2000 | memory > 512 | speed <= 2000 | memory <= 512 | speed <= 2000 || memory <= 512 |
---|---|---|---|---|

F | F | T | T | T |

F | T | T | F | T |

T | F | F | T | T |

T | T | F | F | F |

Each table has the same first two columns. The true/false values in the last column of each table are the same, which shows that the two boolean expressions are equivalent. One expression can be used in place of the other in a program.

**Question 9:**

Is there only one correct way to write an `if`

statement in a program?