CSCI 301 L02 Worksheet

Lecture 2 - Exercises

Part A - define ,lambda

  1. Recall that the formula for the volume of a sphere is \(\frac{4}{3}\pi r^3\). Racket has a built-in function expt to calculate exponents; its two arguments are the base and the exponent. Racket also has a built-in variable pi containing the (approximate) value of \(\pi\). Define a function that takes one argument, radius, and computes the volume of a sphere with that radius.

Part B - let, cond

  1. Write a function plus-root to compute one root (the one resulting from the + of the \(\pm\)) of the quadratic formula. (reproduced below, in case you don’t presently have it memorized). Use let (or let*) to help you make it as readable as possible.

    \[ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} \]

    Here’s a couple test cases in case you try it out: (plus-root 0.5 -3 2.5) 5.0 (plus-root 0.5 -3 5) 3.0+1.0i

  2. Modify your function from #2 to return false if there is no real root. So now it should behave as follows:

    (plus-root 0.5 -3 2.5)
    5.0
    (plus-root 0.5 -3 5)
    #f

(End of what we covered in Lecture 2)

Part C - Subsets and Power Sets

  1. Let \(A = \{a, \varnothing\}\). True or false:
    1. \(a \in A\)
    2. \(\{a\} \in A\)
    3. \(a \subseteq A\)
    4. \(\{a\} \subseteq A\)
    5. \(\varnothing \subseteq A\)
    6. \(\{\varnothing\} \subseteq A\)
    7. \(\{\varnothing\} \in A\)
  2. Compute the power set of each of the following sets:
    1. \(\{1, 2\}\)
    2. {1}
    3. \(\varnothing\)
    4. \(\{1, \{2\}\}\)
  3. [Challenge Question] If \(|S| = n\), what is \(|\mathcal{P}(S)|\)?