|
25 | 25 | <hypercomplex<>>
|
26 | 26 | <hypercomplex<float>> <meta<hypercomplex<float>>> <hypercomplex<float<single>>> <meta<hypercomplex<float<single>>>>
|
27 | 27 | <hypercomplex<double>> <meta<hypercomplex<double>>> <hypercomplex<float<double>>> <meta<hypercomplex<float<double>>>>)
|
28 |
| - #:re-export (real-part imag-part equal? + - abs conj)) |
| 28 | + #:re-export (real-part imag-part equal? + - abs conj * /)) |
29 | 29 |
|
30 | 30 |
|
31 | 31 | (define-class <hypercomplex> ()
|
|
132 | 132 | (hypercomplex (* (real-part a) b) (* (imag-part a) b) (* (jmag-part a) b) (* (kmag-part a) b)))
|
133 | 133 | (define-method (* (a <scalar>) (b <hypercomplex<>>))
|
134 | 134 | (hypercomplex (* a (real-part b)) (* a (imag-part b)) (* a (jmag-part b)) (* a (kmag-part b))))
|
| 135 | + |
| 136 | +(define (hypercomplex-inverse a) |
| 137 | + (jit-let [(d1 (- (real-part a) (kmag-part a))) |
| 138 | + (d2 (+ (imag-part a) (jmag-part a))) |
| 139 | + (d3 (+ (real-part a) (kmag-part a))) |
| 140 | + (d4 (- (imag-part a) (jmag-part a))) |
| 141 | + (denom (* (+ (* d1 d1) (* d2 d2)) (+ (* d3 d3) (* d4 d4)))) |
| 142 | + (squares (+ (* (real-part a) (real-part a)) |
| 143 | + (* (imag-part a) (imag-part a)) |
| 144 | + (* (jmag-part a) (jmag-part a)) |
| 145 | + (* (kmag-part a) (kmag-part a)))) |
| 146 | + (cross (- (* (real-part a) (kmag-part a)) (* (imag-part a) (jmag-part a)))) |
| 147 | + (c1 (* (kmag-part a) cross)) |
| 148 | + (c2 (* (jmag-part a) cross)) |
| 149 | + (c3 (* (imag-part a) cross)) |
| 150 | + (c4 (* (real-part a) cross))] |
| 151 | + (hypercomplex (/ (- (* (real-part a) squares) (+ c1 c1)) denom) |
| 152 | + (/ (- (- (* (imag-part a) squares)) (+ c2 c2)) denom) |
| 153 | + (/ (- (- (* (jmag-part a) squares)) (+ c3 c3)) denom) |
| 154 | + (/ (- (* (kmag-part a) squares) (+ c4 c4)) denom)))) |
| 155 | +(define (complex-inverse a) |
| 156 | + (jit-let [(denom (+ (* (real-part a) (real-part a)) (* (imag-part a) (imag-part a))))] |
| 157 | + (complex (/ (real-part a) denom) (/ (- (imag-part a)) denom)))) |
| 158 | + |
| 159 | +(define-method (/ (a <hypercomplex<>>) (b <hypercomplex<>>)) |
| 160 | + (jit-let [(inverse (hypercomplex-inverse b))] (* a inverse))) |
| 161 | +(define-method (/ (a <hypercomplex<>>) (b <complex<>>)) |
| 162 | + (jit-let [(inverse (complex-inverse b))] (* a inverse))) |
| 163 | +(define-method (/ (a <complex<>>) (b <hypercomplex<>>)) |
| 164 | + (jit-let [(inverse (hypercomplex-inverse b))] (* a inverse))) |
0 commit comments