Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
35 lines (28 sloc) 1.05 KB

如果要把常规数、有理数加入复数系统,那么我们需要把之前复数系统中的add*等基本运算换成一般意义的addmul

例如:

;复数的四种基本运算
(define (add-complex z1 z2)
  (make-from-real-imag (add (real-part z1) (real-part z2))
                       (add (imag-part z1) (imag-part z2)))

(define (sub-complex z1 z2)
  (make-from-real-imag (sub (real-part z1) (real-part z2))
                       (sub (imag-part z1) (imag-part z2)))

(define (mul-complex z1 z2)
  (make-from-mag-ang (mul (magnitude z1) (magnitude z2))
                     (add (angle z1) (angle z2)))

(define (div-complex z1 z2)
  (make-from-mag-ang (div (magnitude z1) (magnitude z2))
                     (sub (angle z1) (angle z2)))

定义cossin

(put 'sine 'scheme-number 
  (lambda (x) (tag (sin x)))) 
(put 'cosine 'scheme-number 
  (lambda (x) (tag (cos x)))) 

(put 'sine 'rational 
  (lambda (x) (sine (/ (numer x) (denom x)))))  
(put 'cosine 'rational 
  (lambda (x) (cosine (/ (numer x) (denom x)))))