[m-rev.] diff: cleanup extras/complex_numbers

Julien Fischer juliensf at cs.mu.OZ.AU
Mon Apr 10 16:32:50 AEST 2006


Estimated hours taken: 1
Branches: main, release

Cleanups for the complex numbers library.

extras/complex_numbers/*.m:
extras/complex_numbers/samples/fft.m:
extras/complex_numbers/tests/complex_test.m:
	Convert these modules to four-space indentation.

	Conform to our current coding standard.

Julien.

Index: complex.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/complex_numbers/complex.m,v
retrieving revision 1.7
diff -u -b -r1.7 complex.m
--- complex.m	9 Feb 2005 12:50:23 -0000	1.7
+++ complex.m	10 Apr 2006 05:43:34 -0000
@@ -1,13 +1,15 @@
-%---------------------------------------------------------------------------%
-% Copyright (C) 1997-1998,2001, 2005 The University of Melbourne.
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
+% Copyright (C) 1997-1998, 2001, 2005 The University of Melbourne.
 % This file may only be copied under the terms of the GNU Library General
 % Public License - see the file COPYING.LIB in the Mercury distribution.
-%---------------------------------------------------------------------------%
-%
+%-----------------------------------------------------------------------------%
+
 % File: complex.m.
 % Main author: fjh.
 % Stability: medium.
-%
+
 % Complex numbers.
 %
 % Note that the overloaded versions of the binary operators that
@@ -16,93 +18,120 @@
 % See also:
 %	complex_float.m, float_complex.m
 %	imag.m, complex_imag.m, imag_complex.m
-%
-%---------------------------------------------------------------------------%
+
+%-----------------------------------------------------------------------------%

 :- module complex_numbers.complex.
 :- interface.

-:- type complex ---> cmplx(float, float).	% real part, imag part
+%-----------------------------------------------------------------------------%

-% The constructor cmplx/2 is made public, but
-% generally it is most convenient to use the syntax `X + Y*i' for
-% complex numbers, where `i' is declared in module `imag'.
-% Due to the wonders of logic programming, this works fine for
+% The constructor cmplx/2 is made public, but generally it is most convenient
+% to use the syntax `X + Y*i' for complex numbers, where `i' is declared in
+% module `imag'.  Due to the wonders of logic programming, this works fine for
 % both constructing and pattern matching; with intermodule optimization
 % enabled, the compiler should generate equally good code for it.

-	% convert float to complex
+:- type complex
+    --->    cmplx(
+                float,      % real part
+                float       % imag part
+            ).
+
+%-----------------------------------------------------------------------------%
+
+    % Convert float to complex.
+    %
 :- func complex(float) = complex.

-	% extract real part
+    % Extract real part.
+    %
 :- func real(complex) = float.

-	% extract imaginary part
+    % Extract imaginary part.
+    %
 :- func imag(complex) = float.

-	% square of absolute value
+    % Square of absolute value.
+    %
 :- func abs2(complex) = float.

-	% absolute value (a.k.a. modulus)
+    % Absolute value (a.k.a. modulus).
+    %
 :- func abs(complex) = float.

-	% argument (a.k.a. phase, or amplitude, or angle)
+    % Argument (a.k.a. phase, or amplitude, or angle).
 	% This function returns the principle value:
+    %
 	% for all Z, -pi < arg(Z) and arg(Z) =< pi.
+    %
 :- func arg(complex) = float.

-	% complex conjugate
+    % Complex conjugate.
+    %
 :- func conj(complex) = complex.

-	% addition
+    % Addition.
+    %
 :- func complex + complex = complex.
 :- mode in  + in  = uo  is det.

-	% subtraction
+    % Subtraction.
+    %
 :- func complex - complex = complex.
 :- mode in  - in  = uo  is det.

-	% multiplication
+    % Multiplication.
+    %
 :- func complex * complex = complex.
 :- mode in  * in  = uo  is det.

-	% division
+    % Division.
+    %
 :- func complex / complex = complex.
 :- mode in  / in  = uo  is det.

-	% unary plus
+    % Unary plus.
+    %
 :- func + complex = complex.
 :- mode + in    = uo  is det.

-	% unary minus
+    % Unary minus.
+    %
 :- func - complex = complex.
 :- mode - in    = uo  is det.

 	% sqr(X) = X * X.
+    %
 :- func sqr(complex) = complex.
-:- mode sqr(in) = out is det.

-	% square root
+    % Square root.
+    %
 :- func sqrt(complex) = complex.
-:- mode sqrt(in) = out is det.

 	% cis(Theta) = cos(Theta) + i * sin(Theta)
+    %
 :- func cis(float) = complex.

-	% polar_to_complex(R, Theta):
-	% conversion from polar coordinates
+    % polar_to_complex(R, Theta).
+    % Conversion from polar coordinates.
+    %
 :- func polar_to_complex(float, float) = complex.
-:- mode polar_to_complex(in, in) = out is det.

-	% polar_to_complex(Z, R, Theta):
-	% conversion to polar coordinates
-:- pred complex_to_polar(complex, float, float).
-:- mode complex_to_polar(in, out, out) is det.
+    % polar_to_complex(Z, R, Theta).
+    % Conversion to polar coordinates.
+    %
+:- pred complex_to_polar(complex::in, float::out, float::out) is det.

 %---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%

 :- implementation.
-:- import_module float, math.
+
+:- import_module float.
+:- import_module math.
+
+%---------------------------------------------------------------------------%

 complex(Real) = cmplx(Real, 0.0).

@@ -155,4 +184,5 @@

 cis(Theta) = cmplx(cos(Theta), sin(Theta)).

-%------------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
Index: complex_float.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/complex_numbers/complex_float.m,v
retrieving revision 1.7
diff -u -b -r1.7 complex_float.m
--- complex_float.m	9 Feb 2005 12:50:23 -0000	1.7
+++ complex_float.m	10 Apr 2006 05:40:39 -0000
@@ -1,49 +1,63 @@
-%---------------------------------------------------------------------------%
-% Copyright (C) 1997-1998,2001, 2004-2005 The University of Melbourne.
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
+% Copyright (C) 1997-1998, 2001, 2004-2005 The University of Melbourne.
 % This file may only be copied under the terms of the GNU Library General
 % Public License - see the file COPYING.LIB in the Mercury distribution.
-%---------------------------------------------------------------------------%
-%
+%-----------------------------------------------------------------------------%
+
 % File: complex_float.m.
 % Main author: fjh.
 % Stability: medium.
-%
+
 % This module provides binary operators on (complex, float).
 %
-% See also:
-%	complex, float, complex_float.
-%
-%---------------------------------------------------------------------------%
+% See also: complex, float, complex_float.
+
+%-----------------------------------------------------------------------------%

 :- module complex_numbers.complex_float.
 :- interface.
-:- import_module complex_numbers.complex, float.

-	% addition
+:- import_module complex_numbers.complex.
+
+:- import_module float.
+
+%-----------------------------------------------------------------------------%
+
+    % Addition.
+    %
 :- func complex + float = complex.
 :- mode in   + in   = uo  is det.

-	% subtraction
+    % Subtraction.
+    %
 :- func complex - float = complex.
 :- mode in   - in   = uo  is det.

-	% multiplication
+    % Multiplication.
+    %
 :- func complex * float = complex.
 :- mode in   * in   = uo  is det.

-	% division
+    % Division.
+    %
 :- func complex / float = complex.
 :- mode in   / in   = uo  is det.

-	% exponentiation
+    % Exponentiation.
+    %
 :- func pow(complex, float) = complex.
-:- mode pow(in, in) = out is det.

-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

 :- implementation.
+
 :- import_module math.

+%-----------------------------------------------------------------------------%
+
 cmplx(XR, XI) + YR = cmplx(XR + YR, + XI).
 cmplx(XR, XI) - YR = cmplx(XR - YR, + XI).
 cmplx(XR, XI) * YR = cmplx(XR * YR, XI * YR).
@@ -55,5 +69,5 @@
 	Th = Th0 * P,
 	Z = polar_to_complex(L, Th).

-%---------------------------------------------------------------------------%
-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
Index: complex_imag.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/complex_numbers/complex_imag.m,v
retrieving revision 1.7
diff -u -b -r1.7 complex_imag.m
--- complex_imag.m	9 Feb 2005 12:50:23 -0000	1.7
+++ complex_imag.m	10 Apr 2006 05:41:20 -0000
@@ -1,45 +1,58 @@
-%---------------------------------------------------------------------------%
-% Copyright (C) 1997-1998,2001, 2004-2005 The University of Melbourne.
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
+% Copyright (C) 1997-1998, 2001, 2004-2005 The University of Melbourne.
 % This file may only be copied under the terms of the GNU Library General
 % Public License - see the file COPYING.LIB in the Mercury distribution.
-%---------------------------------------------------------------------------%
-%
+%-----------------------------------------------------------------------------%
+
 % File: complex_imag.m.
 % Main author: fjh.
 % Stability: medium.
-%
+
 % This module provides binary operators on (complex, imag).
 %
-% See also:
-%	complex.m, imag.m, imag_complex.m.
-%
-%---------------------------------------------------------------------------%
+% See also: complex.m, imag.m, imag_complex.m.
+
+%-----------------------------------------------------------------------------%

 :- module complex_numbers.complex_imag.
 :- interface.
-:- import_module complex_numbers.complex, complex_numbers.imag.

-	% addition
+:- import_module complex_numbers.complex.
+:- import_module complex_numbers.imag.
+
+%-----------------------------------------------------------------------------%
+
+    % Addition.
+    %
 :- func complex + imag = complex.
 :- mode in   + in   = uo  is det.

-	% subtraction
+    % Subtraction.
+    %
 :- func complex - imag = complex.
 :- mode in   - in   = uo  is det.

-	% multiplication
+    % Multiplication.
+    %
 :- func complex * imag = complex.
 :- mode in   * in   = uo  is det.

-	% division
+    % Division.
+    %
 :- func complex / imag = complex.
 :- mode in   / in   = uo  is det.

-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

 :- implementation.
+
 :- import_module float.

+%-----------------------------------------------------------------------------%
+
 cmplx(XR, XI) + im(YI) = cmplx(0.0 + XR, XI + YI).
 cmplx(XR, XI) - im(YI) = cmplx(0.0 + XR, XI - YI).
 cmplx(XR, XI) * im(YI) = cmplx(0.0 - XI * YI, 0.0 + XR * YI).
@@ -50,5 +63,5 @@
 %		cmplx((Xr * Yr + Xi * Yi) / Div, (Xi * Yr - Xr * Yi) / Div) :-
 %	Div = (Yr * Yr + Yi * Yi).

-%---------------------------------------------------------------------------%
-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
Index: complex_numbers.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/complex_numbers/complex_numbers.m,v
retrieving revision 1.3
diff -u -b -r1.3 complex_numbers.m
--- complex_numbers.m	23 Sep 2001 06:35:21 -0000	1.3
+++ complex_numbers.m	10 Apr 2006 05:43:58 -0000
@@ -1,11 +1,20 @@
-%---------------------------------------------------------------------------%
-% Copyright (C) 1997-1998,2001 The University of Melbourne.
+%-----------------------------------------------------------------------------%
+% Copyright (C) 1997-1998, 2001 The University of Melbourne.
 % This file may only be copied under the terms of the GNU Library General
 % Public License - see the file COPYING.LIB in the Mercury distribution.
-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
 :- module complex_numbers.
 :- interface.
-:- include_module complex, imag.
-:- include_module complex_float, float_complex.
-:- include_module complex_imag, imag_complex.
-:- include_module float_imag, imag_float.
+
+:- include_module complex.
+:- include_module complex_float.
+:- include_module complex_imag.
+:- include_module float_complex.
+:- include_module float_imag.
+:- include_module imag.
+:- include_module imag_complex.
+:- include_module imag_float.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
Index: float_complex.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/complex_numbers/float_complex.m,v
retrieving revision 1.7
diff -u -b -r1.7 float_complex.m
--- float_complex.m	9 Feb 2005 12:50:23 -0000	1.7
+++ float_complex.m	10 Apr 2006 05:44:41 -0000
@@ -1,58 +1,71 @@
-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
 % Copyright (C) 1997-1998,2001, 2004-2005 The University of Melbourne.
 % This file may only be copied under the terms of the GNU Library General
 % Public License - see the file COPYING.LIB in the Mercury distribution.
-%---------------------------------------------------------------------------%
-%
+%-----------------------------------------------------------------------------%
+
 % File: float_complex.m.
 % Main author: fjh.
 % Stability: medium.
 %
 % This module provides binary operators on (float, complex).
-%
-% See also:
-%	complex.m, float.m, complex_float.m.
-%
-%---------------------------------------------------------------------------%
+
+% See also: complex.m, float.m, complex_float.m.
+
+%-----------------------------------------------------------------------------%

 :- module complex_numbers.float_complex.
 :- interface.
-:- import_module float, complex_numbers.complex.

-	% addition
+:- import_module complex_numbers.complex.
+:- import_module float.
+
+%-----------------------------------------------------------------------------%
+
+    % Addition.
+    %
 :- func float + complex = complex.
 :- mode in   + in   = uo  is det.

-	% subtraction
+    % Subtraction.
+    %
 :- func float - complex = complex.
 :- mode in   - in   = uo  is det.

-	% multiplication
+    % Multiplication.
+    %
 :- func float * complex = complex.
 :- mode in   * in   = uo  is det.

-	% division
+    % Division.
+    %
 :- func float / complex = complex.
 :- mode in   / in   = uo  is det.

-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

 :- implementation.
+
 :- import_module complex_numbers.complex_float.

+%-----------------------------------------------------------------------------%
+
 XR + cmplx(YR, YI) = cmplx(XR + YR, + YI).
 XR - cmplx(YR, YI) = cmplx(XR - YR, - YI).
 XR * cmplx(YR, YI) = cmplx(XR * YR, XR * YI).
 XR / cmplx(YR, YI) = cmplx(XR * YR / Div, - XR * YI / Div) :-
 	Div = YR * YR + YI * YI.

-%---------------------------------------------------------------------------%
-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

 % Division of float / complex formula obtained by simplifying this one:
 % cmplx(Xr, Xi) / cmplx(Yr, Yi) =
 %		cmplx((Xr * Yr + Xi * Yi) / Div, (Xi * Yr - Xr * Yi) / Div) :-
 %	Div = (Yr * Yr + Yi * Yi).

-%---------------------------------------------------------------------------%
-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
Index: float_imag.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/complex_numbers/float_imag.m,v
retrieving revision 1.7
diff -u -b -r1.7 float_imag.m
--- float_imag.m	9 Feb 2005 12:50:23 -0000	1.7
+++ float_imag.m	10 Apr 2006 05:46:03 -0000
@@ -1,41 +1,54 @@
-%---------------------------------------------------------------------------%
-% Copyright (C) 1997-1998,2001, 2004-2005 The University of Melbourne.
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
+% Copyright (C) 1997-1998, 2001, 2004-2005 The University of Melbourne.
 % This file may only be copied under the terms of the GNU Library General
 % Public License - see the file COPYING.LIB in the Mercury distribution.
-%---------------------------------------------------------------------------%
-%
+%-----------------------------------------------------------------------------%
+
 % File: float_imag.m.
 % Main author: fjh.
 % Stability: medium.
-%
+
 % This module provides binary operators on (float, imag).
 %
-% See also:
-%	complex.m, imag.m, float.m, imag_float.m.
-%
-%---------------------------------------------------------------------------%
+% See also: complex.m, imag.m, float.m, imag_float.m.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

 :- module complex_numbers.float_imag.
 :- interface.
-:- import_module float, complex_numbers.imag, complex_numbers.complex.

-	% addition
+:- import_module complex_numbers.complex.
+:- import_module complex_numbers.imag.
+
+:- import_module float.
+
+%-----------------------------------------------------------------------------%
+
+    % Addition.
+    %
 :- func float + imag = complex.
 :- mode in    + in   = uo  is det.

-	% subtraction
+    % Subtraction.
+    %
 :- func float - imag = complex.
 :- mode in    - in   = uo  is det.

-	% multiplication
+    % Multiplication.
+    %
 :- func float * imag = imag.
 :- mode in    * in   = uo  is det.

-	% division
+    % Division.
+    %
 :- func float / imag = imag.
 :- mode in    / in   = uo  is det.

-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

 :- implementation.

@@ -44,5 +57,5 @@
 XR * im(YI) = im(XR * YI).
 XR / im(YI) = im(0.0 - XR / YI).

-%---------------------------------------------------------------------------%
-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
Index: imag.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/complex_numbers/imag.m,v
retrieving revision 1.7
diff -u -b -r1.7 imag.m
--- imag.m	9 Feb 2005 12:50:23 -0000	1.7
+++ imag.m	10 Apr 2006 06:07:24 -0000
@@ -1,71 +1,90 @@
-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
 % Copyright (C) 1997-1998,2001, 2004-2005 The University of Melbourne.
 % This file may only be copied under the terms of the GNU Library General
 % Public License - see the file COPYING.LIB in the Mercury distribution.
-%---------------------------------------------------------------------------%
-%
+%-----------------------------------------------------------------------------%
+
 % File: imag.m.
 % Main author: fjh.
 % Stability: medium.
-%
+
 % Imaginary numbers.
 %
 % There are several reasons for supporting a separate type for imaginary
-% numbers rather than just treating them as a special case of complex
-% numbers.  It is sometimes more convenient, and can be slightly more
-% efficient.   But perhaps the most important reason is to get correct
-% handling of infinity and not-a-number on platforms that support IEEE
-% floating point.
-%
-% Note that the overloaded versions of the binary operators which
-% provide mixed type arithmetic are defined in different modules.
+% numbers rather than just treating them as a special case of complex numbers.
+% It is sometimes more convenient, and can be slightly more efficient.  But
+% perhaps the most important reason is to get correct handling of infinity and
+% not-a-number on platforms that support IEEE floating point.
 %
+% Note that the overloaded versions of the binary operators that provide
+% mixed type arithmetic are defined in different modules.
+
 % See also:
 %	float.m, imag_float.m, float_imag.m,
 %	complex.m, imag_complex.m, complex_imag.m.
-%
-%---------------------------------------------------------------------------%
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

 :- module complex_numbers.imag.
 :- interface.
+
 :- import_module float.

-:- type imag ---> im(float).
+%-----------------------------------------------------------------------------%
+
+:- type imag
+    --->    im(float).

 :- func i = imag.	% i = sqrt(-1)
 :- func j = imag.	% another name for `i'

-	% addition
+%-----------------------------------------------------------------------------%
+
+    % Addition.
+    %
 :- func imag + imag = imag.
 :- mode in   + in   = uo  is det.

-	% subtraction
+    % Subtraction.
+    %
 :- func imag - imag = imag.
 :- mode in   - in   = uo  is det.

-	% multiplication
+    % Multiplication.
+    %
 :- func imag * imag = float.
 :- mode in   * in   = uo  is det.

-	% division
+    % Division.
+    %
 :- func imag / imag = float.
 :- mode in   / in   = uo  is det.

-	% unary plus
+    % Unary plus.
+    %
 :- func + imag = imag.
 :- mode + in   = uo  is det.

-	% unary minus
+    % Unary minus.
+    %
 :- func - imag = imag.
 :- mode - in   = uo  is det.

-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

 :- implementation.

+%-----------------------------------------------------------------------------%
+
 i = im(1.0).
 j = i.

+%-----------------------------------------------------------------------------%
+
 +im(X) = im(X + 0.0).
 -im(X) = im(-X).
 im(X) + im(Y) = im(X + Y).
@@ -73,5 +92,5 @@
 im(X) * im(Y) = 0.0 - X * Y.
 im(X) / im(Y) = X / Y.

-%---------------------------------------------------------------------------%
-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
Index: imag_complex.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/complex_numbers/imag_complex.m,v
retrieving revision 1.7
diff -u -b -r1.7 imag_complex.m
--- imag_complex.m	9 Feb 2005 12:50:23 -0000	1.7
+++ imag_complex.m	10 Apr 2006 05:46:21 -0000
@@ -1,58 +1,72 @@
-%---------------------------------------------------------------------------%
-% Copyright (C) 1997-1998,2001, 2004-2005 The University of Melbourne.
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
+% Copyright (C) 1997-1998, 2001, 2004-2005 The University of Melbourne.
 % This file may only be copied under the terms of the GNU Library General
 % Public License - see the file COPYING.LIB in the Mercury distribution.
-%---------------------------------------------------------------------------%
-%
+%-----------------------------------------------------------------------------%
+
 % File: imag_complex.m.
 % Main author: fjh.
 % Stability: medium.
-%
+
 % This module provides binary operators on (imag, complex).
 %
-% See also:
-%	complex.m, imag.m, complex_imag.m.
-%
-%---------------------------------------------------------------------------%
+% See also: complex.m, imag.m, complex_imag.m.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

 :- module complex_numbers.imag_complex.
 :- interface.
-:- import_module complex_numbers.imag, complex_numbers.complex.

-	% addition
+:- import_module complex_numbers.complex.
+:- import_module complex_numbers.imag.
+
+%-----------------------------------------------------------------------------%
+
+    % Addition.
+    %
 :- func imag + complex = complex.
 :- mode in   + in   = uo  is det.

-	% subtraction
+    % Subtraction.
+    %
 :- func imag - complex = complex.
 :- mode in   - in   = uo  is det.

-	% multiplication
+    % Multiplication.
+    %
 :- func imag * complex = complex.
 :- mode in   * in   = uo  is det.

-	% division
+    % Division.
+    %
 :- func imag / complex = complex.
 :- mode in   / in   = uo  is det.

-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

 :- implementation.
+
 :- import_module float.

+%-----------------------------------------------------------------------------%
+
 im(XI) + cmplx(YR, YI) = cmplx(0.0 + YR, XI + YI).
 im(XI) - cmplx(YR, YI) = cmplx(0.0 - YR, XI - YI).
 im(XI) * cmplx(YR, YI) = cmplx(-XI * YI, XI * YR).
 im(XI) / cmplx(YR, YI) = cmplx((XI * YI) / Div, (XI * YR) / Div) :-
 	Div = (YR * YR + YI * YI).

-%---------------------------------------------------------------------------%
-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

 % Division of imag / complex formula obtained by simplifying this one:
 % cmplx(Xr, Xi) / cmplx(Yr, Yi) =
 %		cmplx((Xr * Yr + Xi * Yi) / Div, (Xi * Yr - Xr * Yi) / Div) :-
 %	Div = (Yr * Yr + Yi * Yi).

-%---------------------------------------------------------------------------%
-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
Index: imag_float.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/complex_numbers/imag_float.m,v
retrieving revision 1.7
diff -u -b -r1.7 imag_float.m
--- imag_float.m	9 Feb 2005 12:50:23 -0000	1.7
+++ imag_float.m	10 Apr 2006 06:07:47 -0000
@@ -1,48 +1,63 @@
-%---------------------------------------------------------------------------%
-% Copyright (C) 1997-1998,2001, 2004-2005 The University of Melbourne.
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
+% Copyright (C) 1997-1998, 2001, 2004-2005 The University of Melbourne.
 % This file may only be copied under the terms of the GNU Library General
 % Public License - see the file COPYING.LIB in the Mercury distribution.
-%---------------------------------------------------------------------------%
-%
+%-----------------------------------------------------------------------------%
+
 % File: imag_float.m.
 % Main author: fjh.
 % Stability: medium.
-%
+
 % This module provides binary operators on (imag, float).
 %
-% See also:
-%	complex.m, imag.m, float_imag.m.
-%
-%---------------------------------------------------------------------------%
+% See also: complex.m, imag.m, float_imag.m.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

 :- module complex_numbers.imag_float.
 :- interface.
-:- import_module complex_numbers.imag, float, complex_numbers.complex.

-	% addition
+:- import_module complex_numbers.complex.
+:- import_module complex_numbers.imag.
+
+:- import_module float.
+
+%-----------------------------------------------------------------------------%
+
+    % Addition.
+    %
 :- func imag + float = complex.
 :- mode in   + in   = uo  is det.

-	% subtraction
+    % Subtraction.
+    %
 :- func imag - float = complex.
 :- mode in   - in   = uo  is det.

-	% multiplication
+    % Multiplication.
+    %
 :- func imag * float = imag.
 :- mode in   * in   = uo  is det.

-	% division
+    % Division.
+    %
 :- func imag / float = imag.
 :- mode in   / in   = uo  is det.

-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

 :- implementation.

+%-----------------------------------------------------------------------------%
+
 im(XI) + YR = cmplx(0.0 + YR, 0.0 + XI).
 im(XI) - YR = cmplx(0.0 - YR, 0.0 + XI).
 im(XI) * YR = im(XI * YR).
 im(XI) / YR = im(XI / YR).

-%---------------------------------------------------------------------------%
-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
Index: samples/fft.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/complex_numbers/samples/fft.m,v
retrieving revision 1.8
diff -u -b -r1.8 fft.m
--- samples/fft.m	12 Sep 2005 04:34:45 -0000	1.8
+++ samples/fft.m	10 Apr 2006 05:58:46 -0000
@@ -1,50 +1,66 @@
-%------------------------------------------------------------------------------%
-%
-% file: fft.m
-% main author: conway.
-% data: August 1996
-%
-% This source file is hereby placed in the public domain. -conway (the author).
-%
-% This module provides a predicate for performing the Fast Fourier Transfrom
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
+
+% File: fft.m.
+% Main author: conway.
+% Date: August 1996.
+
+% This source file is hereby placed in the public domain.
+%   -conway (the author).
+
+% This module provides a predicate for performing the Fast Fourier Transform
 % (fft) on a list of complex numbers. The list must be a power of 2 in length
 % (ie 4, 8, 16, ... elements).
 %
 % The algorithm used here is derived from a few sources:
 %	- "Numerical Recipes in C": Press, et al
 %	- "Elements of Computer Music": Moore
-%	- Lecture notes from 433-325 "Mathemematical Software B": Dr Rex Harris
+%   - Lecture notes from 433-325 "Mathematical Software B": Dr Rex Harris
 %
 % It actually took the combination of these sources for me to uncover the
 % algorithm for combining the component transforms. This code is not maximally
 % efficient, but rather is intended as a clear presentation of the FFT
 % algorithm.
-%
-%------------------------------------------------------------------------------%
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
 :- module fft.
-%------------------------------------------------------------------------------%
 :- interface.

 :- import_module io.

+%-----------------------------------------------------------------------------%
+
 :- pred main(io::di, io::uo) is det.

-%------------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
 :- implementation.

-:- import_module float, int, list, math, require.
-:- import_module complex_numbers, complex_numbers.complex.
-:- import_module complex_numbers.float_imag, complex_numbers.imag.
+:- import_module complex_numbers.
+:- import_module complex_numbers.complex.
+:- import_module complex_numbers.float_imag.
+:- import_module complex_numbers.imag.
+
+:- import_module float.
+:- import_module int.
+:- import_module list.
+:- import_module math.
+:- import_module require.
+
+%-----------------------------------------------------------------------------%

 main(!IO) :-
-	Zero = 0.0 + 0.0*i,
-	One  = 1.0 + 0.0*i,
+    Zero = 0.0 + 0.0 * i,
+    One  = 1.0 + 0.0 * i,
 	fft([One, Zero, One, Zero], T),
 	io.write(T, !IO),
 	io.nl(!IO).

-:- pred fft(list(complex), list(complex)).
-:- mode fft(in, out) is det.
+:- pred fft(list(complex)::in, list(complex)::out) is det.

 fft(Ins, Outs) :-
 		% First put the list into bit-reversed order.
@@ -55,19 +71,17 @@
 		% Now recombine the component transforms
 	combine(N, 1.0, R, Shuffle, Outs).

-:- pred bit_rev(list(T), list(T)).
-:- mode bit_rev(in, out) is det.
+:- pred bit_rev(list(T)::in, list(T)::out) is det.

 bit_rev([], []).
 bit_rev([X], [X]).
-bit_rev([X1,X2|Xs], List) :-
-	split([X1,X2|Xs], List1, List2),
+bit_rev([X1, X2 | Xs], List) :-
+    split([X1, X2 | Xs], List1, List2),
 	bit_rev(List1, List3),
 	bit_rev(List2, List4),
 	list.append(List3, List4, List).

-:- pred split(list(T), list(T), list(T)).
-:- mode split(in, out, out) is det.
+:- pred split(list(T)::in, list(T)::out, list(T)::out) is det.

 split([], [], []).
 split([_], _, _) :-
@@ -75,8 +89,8 @@
 split([X1, X2|Xs], [X1|Ys], [X2|Zs]) :-
 	split(Xs, Ys, Zs).

-:- pred combine(float, float, int, list(complex), list(complex)).
-:- mode combine(in, in, in, in, out) is det.
+:- pred combine(float::in, float::in, int::in,
+    list(complex)::in, list(complex)::out) is det.

 combine(N, K, R, Ins, Outs) :-
 	(
@@ -97,23 +111,21 @@
 		list.append(Rs0, Rs1, Outs)
 	).

-:- pred xform(list(complex), list(complex), complex, complex,
-		list(complex), list(complex)).
-:- mode xform(in, in, in, in, out, out) is det.
+:- pred xform(list(complex)::in, list(complex)::in, complex::in, complex::in,
+    list(complex)::out, list(complex)::out) is det.

-xform([], [_|_], _WJN, _WKN, _, _) :-
+xform([], [_ | _], _WJN, _WKN, _, _) :-
 	error("ran out of Di's").
-xform([_|_], [], _WJN, _WKN, _, _) :-
+xform([_ | _], [], _WJN, _WKN, _, _) :-
 	error("ran out of Dj's").
 xform([], [], _WJN, _WKN, [], []).
-xform([Di0|Dis0], [Dj0|Djs0], WJN, WKN, [Di|Dis], [Dj|Djs]) :-
+xform([Di0 | Dis0], [Dj0 | Djs0], WJN, WKN, [Di | Dis], [Dj | Djs]) :-
 	Tmp = WJN * Dj0,
 	Di = Di0 + Tmp,
 	Dj = Di0 - Tmp,
-	xform(Dis0, Djs0, WJN*WKN, WKN, Dis, Djs).
+    xform(Dis0, Djs0, WJN * WKN, WKN, Dis, Djs).

-:- pred divide(int, list(T), list(T), list(T)).
-:- mode divide(in, in, out, out) is det.
+:- pred divide(int::in, list(T)::in, list(T)::out, list(T)::out) is det.

 divide(R, Ins, Fs, Ss) :-
 	(
@@ -126,9 +138,9 @@
 			Ins = [],
 			error("divide error!")
 		;
-			Ins = [F|Ins1],
-			divide(R-1, Ins1, Fs1, Ss),
-			Fs = [F|Fs1]
+            Ins = [F | Ins1],
+            divide(R - 1, Ins1, Fs1, Ss),
+            Fs = [F | Fs1]
 		)
 	).

@@ -137,4 +149,5 @@
 w(J, N) = cis(Theta) :-
 	Theta = J * 2.0 * pi / N.

-%------------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
Index: tests/complex_test.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/complex_numbers/tests/complex_test.m,v
retrieving revision 1.4
diff -u -b -r1.4 complex_test.m
--- tests/complex_test.m	9 Feb 2005 12:50:24 -0000	1.4
+++ tests/complex_test.m	10 Apr 2006 06:10:59 -0000
@@ -6,22 +6,32 @@

 :- pred main(io::di, io::uo) is det.

+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
 :- implementation.
-:- import_module float.
+
 :- import_module complex_numbers.
-:- import_module complex_numbers.complex, complex_numbers.imag.
-:- import_module complex_numbers.complex_imag, complex_numbers.imag_complex.
-:- import_module complex_numbers.float_imag, complex_numbers.imag_float.
+:- import_module complex_numbers.complex.
+:- import_module complex_numbers.complex_imag.
+:- import_module complex_numbers.float_imag.
+:- import_module complex_numbers.imag.
+:- import_module complex_numbers.imag_complex.
+:- import_module complex_numbers.imag_float.
+
+:- import_module float.
+
+%-----------------------------------------------------------------------------%

 main -->
 	print("tests of (complex op complex)"), nl,
-	{ X = 3.0 + 4.0 * i},
+	{ X = 3.0 + 4.0 * i },
 	print("X = "), print(X), nl,
 	print("X + X = "), print(X + X), nl,
 	print("X - X = "), print(X - X), nl,
 	print("X * X = "), print(X * X), nl,
 	print("X / X = "), print(X / X), nl,
-	{ Y = - 5.0 + 6.0 * i},
+	{ Y = - 5.0 + 6.0 * i },
 	print("Y = "), print(Y), nl,
 	print("Y + Y = "), print(Y + Y), nl,
 	print("Y - Y = "), print(Y - Y), nl,
@@ -34,7 +44,7 @@
 	nl,

 	print("tests of (imag op imag)"), nl,
-	{ Z = 4.0 * i},
+	{ Z = 4.0 * i },
 	print("Z = "), print(Z), nl,
 	print("Z + Z = "), print(Z + Z), nl,
 	print("Z - Z = "), print(Z - Z), nl,
@@ -76,3 +86,6 @@
 	print("Z - Y = "), print(Z - Y), nl,
 	print("Z * Y = "), print(Z * Y), nl,
 	print("Z / Y = "), print(Z / Y), nl.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list