Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/tests/nofib/spectral/fft2/Complex_Vectors.lhs

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


> module Complex_Vectors
>         (ComplexF, rootsOfUnity,thetas, norm,distance)
> where
> import Complex --

> type ComplexF = Complex Double

> rootsOfUnity:: Int -> [ComplexF]
> rootsOfUnity n = zipWith (:+) (map cos (thetas n)) 
>                               (map sin (thetas n))

> thetas:: Int -> [Double]
> thetas n = [(2*pi/fromInt n)*fromInt k | k<-[0 .. n-1]]
>   -- partain addition:
>   where
>     fromInt :: (Num a) => Int -> a
>     fromInt i = fromInteger (toInteger i)

> norm:: [ComplexF] -> Double
> norm = sqrt.sum.map((^2).magnitude)

> distance:: [ComplexF] -> [ComplexF] -> Double
> distance z w = norm(zipWith (-) z w)

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].