# set-4

## Exercise 2.95

Define `P`_{1}, `P`_{2}, and `P`_{3} to be the polynomials

Now define `Q`_{1} to be the product of `P`_{1} and `P`_{2} and `Q`_{2} to be the product of `P`_{1} and `P`_{3}, and use `greatest-common-divisor`

(exercise 2.94) to compute the GCD of `Q`_{1} and `Q`_{2}. Note that the answer is not the same as `P`_{1}. This example introduces noninteger operations into the computation, causing difficulties with the GCD algorithm.[61] To understand what is happening, try tracing `gcd-terms`

while computing the GCD or try performing the division by hand.

## Exercise 2.94

Using `div-terms`

, implement the procedure `remainder-terms`

and use this to define `gcd-terms`

as above. Now write a procedure `gcd-poly`

that computes the polynomial GCD of two polys. (The procedure should signal an error if the two polys are not in the same variable.) Install in the system a generic operation `greatest-common-divisor`

that reduces to `gcd-poly`

for polynomials and to ordinary `gcd`

for ordinary numbers. As a test, try

```
(define p1 (make-polynomial 'x '((4 1) (3 -1) (2 -2) (1 2))))
(define p2 (make-polynomial 'x '((3 1) (1 -1))))
(greatest-common-divisor p1 p2)
```

and check your result by hand.

## Exercise 2.49

`segments->painter`

to define the following primitive painters:

- The painter that draws the outline of the designated frame.
- The painter that draws an “X” by connecting opposite corners of the frame.
- The painter that draws a diamond shape by connecting the midpoints of the sides of the frame.
- The
`wave`

painter.

## Exercise 2.48

A directed line segment in the plane can be represented as a pair of vectors — the
vector running from the origin to the start-point of the segment, and
the vector running from the origin to the end-point of the segment. Use your vector representation from exercise 2.46 to define a representation for segments with a constructor `make-segment`

and selectors `start-segment`

and `end-segment`

.