# sicp-ex-2.79

``` ;; -----------------------------------------------
;; EXERCISE 2.79
;; -----------------------------------------------

(define (install-scheme-number-package)
;; ...
(put 'equ? '(scheme-number scheme-number) =)
'done)

(define (install-rational-package)
;; ...
(define (equ? x y)
(= (* (numer x) (denom y)) (* (numer y) (denom x))))
;; ...
(put 'equ? '(rational rational) equ?)
'done)

(define (install-complex-package)
;; ...
(define (equ? x y)
(and (= (real-part x) (real-part y)) (= (imag-part x) (imag-part y))))
;; ...
(put 'equ? '(complex complex) equ?)
'done)

(define (equ? x y) (apply-generic 'equ? x y))
```

I think it's best to define equ? in each implementation of complex:

``` (define (install-rectangular-package)
;; ...
(put 'equ? '(rectangular rectangular)
(lambda (x y) (and (= (real-part x) (real-part y))
(= (imag-part x) (imag-part y)))))
'done)

(define (install-polar-package)
;; ...
(put 'equ? '(polar polar)
(lambda (x y) (and (= (magnitude x) (magnitude y))
(= (angle x) (angle y)))))
'done)

(define (equ? x y) (apply-generic 'equ? x y))

(define (install-complex-packages)
;; ...
(put 'equ? '(complex complex) equ?)
'done)
```

The above solution for defining equality for polar terms is incorrect. Two polar numbers are equal when they have the same magnitude and have angles that are congruent modulo 2π (where the angles are measured in radians). Additionally, if the magnitude of a polar form is 0, it is equal to all other polar values with magnitude 0, regardless of their angle (i.e. r=0, theta=10 is equivalent to r=0, theta=0).

Another issue with this second solution is now you need to consider 4 cases:

(1) `(rectangular rectangular)

(2) `(polar rectangular)

(3) `(rectangular polar)

(4) `(polar polar)

In my opinion, leaving equ? up to the complex number package is a far better abstraction.