

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


This assignment covers material through Chapter 3 of Haskell: The Craft of Functional Programming.
This homework is officially due in the bin in CST 3-212 by noon on Thursday, January 29. However, it comes with an automatic extension: anything submit- ted by noon on Friday, January 30 will be accepted as being on time.
You may work singly or in pairs on this assignment.
The following is based on Chapter 3 of Thompson’s HCFP.
In this homework you will develop a series of little programs about lines in the plane. We start with reviewing some high school math. Also see
http: //mathforum.org/dr.math/faq/formulas/faq.ag2.html#twolines
for a bit more background than covered here. Also, follow Polya’s advice and draw pictures as you are reading this.
Lines and their equations. Each line in the x-y-plane is given by an equation of the form:
a · x + b · y + c = 0 ,
where a, b, and c are real numbers and at least one of a and b are nonzero. Some examples:
Note that any line is given by many equations. For example, the line of example 3 is also given by:
10 · x − 4 · y − 10 = 0 , − 2. 5 · x + y + 2. 5 = 0 , x − 0. 4 · y − 1 = 0 ,...
Degenerate lines. An equation of the form 0 · x + 0 · y + c = 0 (that is, an equa- tion with a = b = 0) is called degenerate. (When c = 0, then every point satisfies the equation. When c 6 = 0, no point satisfies the equation.) By convention, we shall consider a degenerate equation as describing a degenerate line (that is, a nonsense line). That way, every equation of the form a · x + b · y + c = 0 names some sort of line, even if it turns out to be nonsensical.
Horizonal and vertical lines and intercepts. Suppose the equation a · x + b · y + c = 0 is not degenerate.
Pairs of lines. Suppose we have two lines, the first named by a 1 · x + b 1 · y + c 1 = 0 and the second named by a 2 · x + b 2 · y + c 2 = 0. Suppose neither line is degenerate.
x =
b 1 · c 2 − b 2 · c 1 a 1 · b 2 − a 2 · b 1
. y =
a 2 · c 1 − a 1 · c 2 a 1 · b 2 − a 2 · b 1
Here are the Haskell functions you have to define for this assignment. We have done part of the work for you in the file:
http://www.cis.syr.edu/courses/cis252/code/lines.hs
In that file you will find the beginnings of each of the following functions. What is missing for each of the functions is: (i) more examples, (ii) more tests, and (iii) the definition of the function. (Each function in the file has a silly definition that you will have to fix.) You may find it useful to read the Notes section (on the last page of this assign- ment) before you start to write code.
onLine (x1,y1) a b c
tests whether the point (x 1 , y 1 ) is on the line named by a · x + b · y + c = 0.
degenerate a b c
tests whether the equation a · x + b · y + c = 0 is degenerate.
horizonal a b c
tests whether the equation a · x + b · y + c = 0 names a horizonal line. (We assume here that the equation is not degenerate.)
vertical a b c
tests whether the equation a · x + b · y + c = 0 names a vertical line. (We assume here that the equation is not degenerate.)
xIntercept a b c
returns the x-coordinate of the x-intercept of the line named by a · x + b · y + c = 0, when the line is not degenerate and not horizonal. If the line is degenerate or horizonal, 0.0 is returned.
yIntercept a b c
returns the y-coordinate of the y-intercept of the line named by a · x + b · y + c = 0, when the line is not degenerate and not vertical. If the line is degenerate or vertical, 0.0 is returned.