[m-rev.] diff: remove reverse modes of extras/complex_numbers arithmetic functions

Simon Taylor stayl at cs.mu.OZ.AU
Sat Sep 22 22:21:07 AEST 2001


Estimated hours taken: 0.5
Branches: main, release

extras/complex_numbers/*.m:
	Remove reverse modes of arithmetic functions (as with the
	reverse modes of the functions in float.m, these functions
	aren't actually reversible because of rounding errors).

extras/complex_numbers/complex_numbers.m:
	Add missing `:- include module' declarations for complex_float.m
	and float_complex.m.

extras/complex_numbers/complex_float.m:
extras/complex_numbers/float_complex.m:
	Fix some compile errors.

NEWS:
	Document the changes.


Index: NEWS
===================================================================
RCS file: /home/mercury1/repository/mercury/NEWS,v
retrieving revision 1.217
diff -u -u -r1.217 NEWS
--- NEWS	2001/09/02 12:20:07	1.217
+++ NEWS	2001/09/22 09:02:09
@@ -27,8 +27,8 @@
   out-of-bounds array accesses.
 
 * We've removed the buggy reverse modes of the arithmetic functions in
-  float.m (because of rounding errors the functions aren't actually
-  reversible).
+  float.m and extras/complex_numbers (because of rounding errors the
+  functions aren't actually reversible).
  
 * The exception module has a new predicate `try_store', which is
   like `try_io', but which works with stores rather than io__states.
Index: extras/complex_numbers//complex.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/complex_numbers/complex.m,v
retrieving revision 1.4
diff -u -u -r1.4 complex.m
--- extras/complex_numbers//complex.m	1998/05/29 09:08:20	1.4
+++ extras/complex_numbers//complex.m	2001/09/22 12:08:00
@@ -1,5 +1,5 @@
 %---------------------------------------------------------------------------%
-% Copyright (C) 1997-1998 The University of Melbourne.
+% Copyright (C) 1997-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.
 %---------------------------------------------------------------------------%
@@ -57,14 +57,10 @@
 	% addition
 :- func complex + complex = complex.
 :- mode in  + in  = uo  is det.
-:- mode uo  + in  = in  is det.
-:- mode in  + uo  = in  is det.
 
 	% subtraction
 :- func complex - complex = complex.
 :- mode in  - in  = uo  is det.
-:- mode uo  - in  = in  is det.
-:- mode in  - uo  = in  is det.
 
 	% multiplication
 :- func complex * complex = complex.
Index: extras/complex_numbers//complex_float.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/complex_numbers/complex_float.m,v
retrieving revision 1.3
diff -u -u -r1.3 complex_float.m
--- extras/complex_numbers//complex_float.m	1998/05/29 09:08:21	1.3
+++ extras/complex_numbers//complex_float.m	2001/09/22 12:08:11
@@ -1,5 +1,5 @@
 %---------------------------------------------------------------------------%
-% Copyright (C) 1997-1998 The University of Melbourne.
+% Copyright (C) 1997-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.
 %---------------------------------------------------------------------------%
@@ -22,26 +22,18 @@
 	% addition
 :- func complex + float = complex.
 :- mode in   + in   = uo  is det.
-:- mode uo   + in   = in  is det.
-:- mode in   + uo   = in  is det.
 
 	% subtraction
 :- func complex - float = complex.
 :- mode in   - in   = uo  is det.
-:- mode uo   - in   = in  is det.
-:- mode in   - uo   = in  is det.
 
 	% multiplication
 :- func complex * float = complex.
 :- mode in   * in   = uo  is det.
-:- mode uo   * in   = in  is det.
-:- mode in   * uo   = in  is det.
 
 	% division
 :- func complex / float = complex.
 :- mode in   / in   = uo  is det.
-:- mode uo   / in   = in  is det.
-:- mode in   / uo   = in  is det.
 
 	% exponentiation
 :- func pow(complex, float) = complex.
@@ -50,18 +42,18 @@
 %---------------------------------------------------------------------------%
 
 :- implementation.
-:- import_module complex_numbers:complex_float.
+:- 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).
+cmplx(XR, XI) - YR = cmplx(XR - YR, + XI).
 cmplx(XR, XI) * YR = cmplx(XR * YR, XI * YR).
 cmplx(XR, XI) / YR = cmplx(XR / YR, XI / YR).
 
-pow(cmplx(Re0, Im0), P) = cmplx(Re, Im) :-
-	cartesian_to_polar(Re0, Im0, L0, Th0),
-	L = pow(L0, P),
+pow(Z0, P) = Z :-
+	complex_to_polar(Z0, L0, Th0),
+	L = math__pow(L0, P),
 	Th = Th0 * P,
-	polar_to_cartesian(L, Th, Re, Im).
+	Z = polar_to_complex(L, Th).
 
 %---------------------------------------------------------------------------%
 %---------------------------------------------------------------------------%
Index: extras/complex_numbers//complex_imag.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/complex_numbers/complex_imag.m,v
retrieving revision 1.3
diff -u -u -r1.3 complex_imag.m
--- extras/complex_numbers//complex_imag.m	1998/05/29 09:08:22	1.3
+++ extras/complex_numbers//complex_imag.m	2001/09/22 12:08:22
@@ -1,5 +1,5 @@
 %---------------------------------------------------------------------------%
-% Copyright (C) 1997-1998 The University of Melbourne.
+% Copyright (C) 1997-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.
 %---------------------------------------------------------------------------%
@@ -22,26 +22,18 @@
 	% addition
 :- func complex + imag = complex.
 :- mode in   + in   = uo  is det.
-:- mode uo   + in   = in  is det.
-:- mode in   + uo   = in  is semidet.
 
 	% subtraction
 :- func complex - imag = complex.
 :- mode in   - in   = uo  is det.
-:- mode uo   - in   = in  is det.
-:- mode in   - uo   = in  is semidet.
 
 	% multiplication
 :- func complex * imag = complex.
 :- mode in   * in   = uo  is det.
-:- mode uo   * in   = in  is det.
-:- mode in   * out   = in  is semidet.
 
 	% division
 :- func complex / imag = complex.
 :- mode in   / in   = uo  is det.
-:- mode uo   / in   = in  is det.
-:- mode in   / out   = in  is semidet.
 
 %---------------------------------------------------------------------------%
 
Index: extras/complex_numbers//complex_numbers.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/complex_numbers/complex_numbers.m,v
retrieving revision 1.1
diff -u -u -r1.1 complex_numbers.m
--- extras/complex_numbers//complex_numbers.m	1998/05/30 12:10:12	1.1
+++ extras/complex_numbers//complex_numbers.m	2001/09/22 12:08:32
@@ -1,10 +1,11 @@
 %---------------------------------------------------------------------------%
-% Copyright (C) 1997-1998 The University of Melbourne.
+% Copyright (C) 1997-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.
Index: extras/complex_numbers//float_complex.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/complex_numbers/float_complex.m,v
retrieving revision 1.3
diff -u -u -r1.3 float_complex.m
--- extras/complex_numbers//float_complex.m	1998/05/29 09:08:23	1.3
+++ extras/complex_numbers//float_complex.m	2001/09/22 12:08:41
@@ -1,5 +1,5 @@
 %---------------------------------------------------------------------------%
-% Copyright (C) 1997-1998 The University of Melbourne.
+% Copyright (C) 1997-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.
 %---------------------------------------------------------------------------%
@@ -22,33 +22,25 @@
 	% addition
 :- func float + complex = complex.
 :- mode in   + in   = uo  is det.
-:- mode uo   + in   = in  is det.
-:- mode in   + uo   = in  is det.
 
 	% subtraction
 :- func float - complex = complex.
 :- mode in   - in   = uo  is det.
-:- mode uo   - in   = in  is det.
-:- mode in   - uo   = in  is det.
 
 	% multiplication
 :- func float * complex = complex.
 :- mode in   * in   = uo  is det.
-:- mode uo   * in   = in  is det.
-:- mode in   * uo   = in  is det.
 
 	% division
 :- func float / complex = complex.
 :- mode in   / in   = uo  is det.
-:- mode uo   / in   = in  is det.
-:- mode in   / uo   = in  is det.
 
 %---------------------------------------------------------------------------%
 
 :- implementation.
 :- import_module complex_numbers:complex_float.
 
-XR + cmplx(YR, YI) = cmplx(XR + YR, + XI).
+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) :-
Index: extras/complex_numbers//float_imag.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/complex_numbers/float_imag.m,v
retrieving revision 1.3
diff -u -u -r1.3 float_imag.m
--- extras/complex_numbers//float_imag.m	1998/05/29 09:08:24	1.3
+++ extras/complex_numbers//float_imag.m	2001/09/22 12:08:51
@@ -1,5 +1,5 @@
 %---------------------------------------------------------------------------%
-% Copyright (C) 1997-1998 The University of Melbourne.
+% Copyright (C) 1997-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.
 %---------------------------------------------------------------------------%
@@ -22,24 +22,18 @@
 	% addition
 :- func float + imag = complex.
 :- mode in    + in   = uo  is det.
-:- mode uo    + uo   = in  is det.
 
 	% subtraction
 :- func float - imag = complex.
 :- mode in    - in   = uo  is det.
-:- mode uo    - uo   = in  is det.
 
 	% multiplication
 :- func float * imag = imag.
 :- mode in    * in   = uo  is det.
-:- mode in    * uo   = in  is det.
-:- mode uo    * in   = in  is det.
 
 	% division
 :- func float / imag = imag.
 :- mode in    / in   = uo  is det.
-:- mode in    / uo   = in  is det.
-:- mode uo    / in   = in  is det.
 
 %---------------------------------------------------------------------------%
 
Index: extras/complex_numbers//imag.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/complex_numbers/imag.m,v
retrieving revision 1.3
diff -u -u -r1.3 imag.m
--- extras/complex_numbers//imag.m	1998/05/29 09:08:25	1.3
+++ extras/complex_numbers//imag.m	2001/09/22 12:09:01
@@ -1,5 +1,5 @@
 %---------------------------------------------------------------------------%
-% Copyright (C) 1997-1998 The University of Melbourne.
+% Copyright (C) 1997-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.
 %---------------------------------------------------------------------------%
@@ -38,26 +38,18 @@
 	% addition
 :- func imag + imag = imag.
 :- mode in   + in   = uo  is det.
-:- mode uo   + in   = in  is det.
-:- mode in   + uo   = in  is det.
 
 	% subtraction
 :- func imag - imag = imag.
 :- mode in   - in   = uo  is det.
-:- mode uo   - in   = in  is det.
-:- mode in   - uo   = in  is det.
 
 	% multiplication
 :- func imag * imag = float.
 :- mode in   * in   = uo  is det.
-:- mode uo   * in   = in  is det.
-:- mode in   * uo   = in  is det.
 
 	% division
 :- func imag / imag = float.
 :- mode in   / in   = uo  is det.
-:- mode uo   / in   = in  is det.
-:- mode in   / uo   = in  is det.
 
 	% unary plus
 :- func + imag = imag.
Index: extras/complex_numbers//imag_complex.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/complex_numbers/imag_complex.m,v
retrieving revision 1.3
diff -u -u -r1.3 imag_complex.m
--- extras/complex_numbers//imag_complex.m	1998/05/29 09:08:26	1.3
+++ extras/complex_numbers//imag_complex.m	2001/09/22 12:09:11
@@ -1,5 +1,5 @@
 %---------------------------------------------------------------------------%
-% Copyright (C) 1997-1998 The University of Melbourne.
+% Copyright (C) 1997-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.
 %---------------------------------------------------------------------------%
@@ -22,14 +22,10 @@
 	% addition
 :- func imag + complex = complex.
 :- mode in   + in   = uo  is det.
-:- mode uo   + in   = in  is semidet.
-:- mode in   + uo   = in  is det.
 
 	% subtraction
 :- func imag - complex = complex.
 :- mode in   - in   = uo  is det.
-:- mode uo   - in   = in  is semidet.
-:- mode in   - uo   = in  is det.
 
 	% multiplication
 :- func imag * complex = complex.
Index: extras/complex_numbers//imag_float.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/complex_numbers/imag_float.m,v
retrieving revision 1.3
diff -u -u -r1.3 imag_float.m
--- extras/complex_numbers//imag_float.m	1998/05/29 09:08:26	1.3
+++ extras/complex_numbers//imag_float.m	2001/09/22 12:09:19
@@ -1,5 +1,5 @@
 %---------------------------------------------------------------------------%
-% Copyright (C) 1997-1998 The University of Melbourne.
+% Copyright (C) 1997-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.
 %---------------------------------------------------------------------------%
@@ -22,24 +22,18 @@
 	% addition
 :- func imag + float = complex.
 :- mode in   + in   = uo  is det.
-:- mode uo   + uo   = in  is det.
 
 	% subtraction
 :- func imag - float = complex.
 :- mode in   - in   = uo  is det.
-:- mode uo   - uo   = in  is det.
 
 	% multiplication
 :- func imag * float = imag.
 :- mode in   * in   = uo  is det.
-:- mode in   * uo   = in  is det.
-:- mode uo   * in   = in  is det.
 
 	% division
 :- func imag / float = imag.
 :- mode in   / in   = uo  is det.
-:- mode in   / uo   = in  is det.
-:- mode uo   / in   = in  is det.
 
 %---------------------------------------------------------------------------%
 
--------------------------------------------------------------------------
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