Homework 1
All problems are to be done using DrRacket. You should be using typed racket, meaning that the first line of your definitions window should be #lang typed/racket.
When working on these problems, you should experiment in the interactions window (the bottom part of the screen). Once you have a solution to a problem, you should copy it to the definitions window (the top part of the screen). To save your work, use File > Save Definitions or File > Save Definitions As to save what's written in the definitions. There is no way to save what's in the interactions window - it is just a place to experiment and test your code. Once you are done, click the Run button to test your code and check the results that appear in the interactions window.
Save your definitions in a file named hw1.rkt and bring the file with you (by any means: email, thumb drive, Google docs, etc.) to lab on Wednesday. During lab, you will learn how to submit your work using subversion.
Problem 1
Write an expression giving the surface area of a sphere with radius 15. Write it as an arithmetic expression involving the built-in constant pi, not simply a number. You do not need to define any variables, just the arithmetic expression.Problem 2
Write an expression for the number of inches in a mile. The value must be computed as a product of familiar constants, not simply a number.Problem 3
Use the substring function to write two expressions that contain the first and second word, respectively, of the string "Hello World". We did not discuss the substring function in lecture: you will have to look it up.Practice Problems
The following problems are not graded, but they are good practice. This sort of thing might appear on a quiz or exam.Expression Trees
You should always be able to convert any expression tree into a Racket expression and vice versa. For each of the problems above, write an expression tree corresponding to the expression you created to answer the problem.Truth Tables
In class, we did simple truth tables for Boolean operations. You can also create truth tables for complex expressions. Try to create a truth table for the following expressions:(not (and p (not q)))
(and p (not (or q r)))