13. Intro Exercises 0

Simplification of Boolean expressions.

Objectives:

  • I can simplify Boolean expressions.
  • I know the two key simplifications of boolean=?.
  1. Simplify each as much as possible.

    1. (< 30 50)
    2. (string=? "move" "button-down")
    3. (<= 30 40 60 50)
    4. (image? 100)
    5. (string-ci<? "cat" "DOG")
    6. (and (>= 50 40) (string<=? "wet" "frog"))
    7. (not (string=? "button-down "drag"))
  2. Assume each variable mentioned below has the correct type to be used in the comparisons. Simplify as much as possible.

    1. (and (string=? word "apple") (string=? word "banana"))
    2. (and (<= x 100) (>= x 30) (not (= x 120)))
  3. What is wrong with the following code? Briefly explain how to fix it.

    1. (= x (or 5 10 15))
    2. (boolean=? wet? "true")
  4. What’s wrong with the following code? How would you fix it?

     (define (bad-apple? fruit)
         (string=? "rotten apple"))
    
  5. This code is not wrong to Racket, but a human will not like it. Why not?

     (define name? "Micah")
    
  6. Make a “truth table” with columns cold? (not cold?) and (boolean=? cold? true). Can you see a simpler way to write the boolean=? column?

  7. Make a “truth table” with columns cold? (not cold?) and (boolean=? cold? false). Can you see a simpler way to write the boolean=? column?

  8. Quick, edit this code so it has better programming style. I found four edits.

     (define (bad-day raining clothes)
         (and (string=? "wet" (substring clothes 0 3)) raining))
    
  9. Simplify as much as possible.

    1. (boolean=? legs-hurt? false)
    2. (or (boolean=? cross-fit? true) (and (< 0 miles-ran) (>= miles-ran 2.0)))
  10. The function home-early? takes in a booleans baby-dolphin-day?, family-pickup?, and fast-bus?. You get home early if you get picked up by your family or if it is a baby dolphin day and you ride a fast bus. Write this function.