| 
									
										
										
										
											1992-08-13 12:14:11 +00:00
										 |  |  | # Complex numbers | 
					
						
							| 
									
										
										
										
											1994-10-08 18:56:41 +00:00
										 |  |  | # --------------- | 
					
						
							| 
									
										
										
										
											1992-08-13 12:14:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-07-30 19:02:01 +00:00
										 |  |  | # [Now that Python has a complex data type built-in, this is not very | 
					
						
							|  |  |  | # useful, but it's still a nice example class] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-10-08 18:56:41 +00:00
										 |  |  | # This module represents complex numbers as instances of the class Complex. | 
					
						
							|  |  |  | # A Complex instance z has two data attribues, z.re (the real part) and z.im | 
					
						
							|  |  |  | # (the imaginary part).  In fact, z.re and z.im can have any value -- all | 
					
						
							|  |  |  | # arithmetic operators work regardless of the type of z.re and z.im (as long | 
					
						
							|  |  |  | # as they support numerical operations). | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # The following functions exist (Complex is actually a class): | 
					
						
							|  |  |  | # Complex([re [,im]) -> creates a complex number from a real and an imaginary part | 
					
						
							|  |  |  | # IsComplex(z) -> true iff z is a complex number (== has .re and .im attributes) | 
					
						
							|  |  |  | # ToComplex(z) -> a complex number equal to z; z itself if IsComplex(z) is true | 
					
						
							|  |  |  | #                 if z is a tuple(re, im) it will also be converted | 
					
						
							|  |  |  | # PolarToComplex([r [,phi [,fullcircle]]]) -> | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  | #       the complex number z for which r == z.radius() and phi == z.angle(fullcircle) | 
					
						
							|  |  |  | #       (r and phi default to 0) | 
					
						
							| 
									
										
										
										
											1996-07-30 19:02:01 +00:00
										 |  |  | # exp(z) -> returns the complex exponential of z. Equivalent to pow(math.e,z). | 
					
						
							| 
									
										
										
										
											1994-10-08 18:56:41 +00:00
										 |  |  | # | 
					
						
							|  |  |  | # Complex numbers have the following methods: | 
					
						
							|  |  |  | # z.abs() -> absolute value of z | 
					
						
							|  |  |  | # z.radius() == z.abs() | 
					
						
							|  |  |  | # z.angle([fullcircle]) -> angle from positive X axis; fullcircle gives units | 
					
						
							|  |  |  | # z.phi([fullcircle]) == z.angle(fullcircle) | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # These standard functions and unary operators accept complex arguments: | 
					
						
							|  |  |  | # abs(z) | 
					
						
							|  |  |  | # -z | 
					
						
							|  |  |  | # +z | 
					
						
							|  |  |  | # not z | 
					
						
							|  |  |  | # repr(z) == `z` | 
					
						
							|  |  |  | # str(z) | 
					
						
							|  |  |  | # hash(z) -> a combination of hash(z.re) and hash(z.im) such that if z.im is zero | 
					
						
							|  |  |  | #            the result equals hash(z.re) | 
					
						
							|  |  |  | # Note that hex(z) and oct(z) are not defined. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # These conversions accept complex arguments only if their imaginary part is zero: | 
					
						
							|  |  |  | # int(z) | 
					
						
							|  |  |  | # float(z) | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # The following operators accept two complex numbers, or one complex number | 
					
						
							|  |  |  | # and one real number (int, long or float): | 
					
						
							|  |  |  | # z1 + z2 | 
					
						
							|  |  |  | # z1 - z2 | 
					
						
							|  |  |  | # z1 * z2 | 
					
						
							|  |  |  | # z1 / z2 | 
					
						
							|  |  |  | # pow(z1, z2) | 
					
						
							|  |  |  | # cmp(z1, z2) | 
					
						
							|  |  |  | # Note that z1 % z2 and divmod(z1, z2) are not defined, | 
					
						
							|  |  |  | # nor are shift and mask operations. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # The standard module math does not support complex numbers. | 
					
						
							| 
									
										
										
										
											2005-04-09 14:55:07 +00:00
										 |  |  | # The cmath modules should be used instead. | 
					
						
							| 
									
										
										
										
											1994-10-08 18:56:41 +00:00
										 |  |  | # | 
					
						
							|  |  |  | # Idea: | 
					
						
							|  |  |  | # add a class Polar(r, phi) and mixed-mode arithmetic which | 
					
						
							|  |  |  | # chooses the most appropriate type for the result: | 
					
						
							|  |  |  | # Complex for +,-,cmp | 
					
						
							|  |  |  | # Polar   for *,/,pow | 
					
						
							| 
									
										
										
										
											1992-08-13 12:14:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-09 14:55:07 +00:00
										 |  |  | import math | 
					
						
							| 
									
										
										
										
											2005-04-09 10:51:19 +00:00
										 |  |  | import sys | 
					
						
							| 
									
										
										
										
											1992-08-13 12:14:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-10-08 18:56:41 +00:00
										 |  |  | twopi = math.pi*2.0 | 
					
						
							|  |  |  | halfpi = math.pi/2.0 | 
					
						
							| 
									
										
										
										
											1992-08-13 12:14:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-10-08 18:56:41 +00:00
										 |  |  | def IsComplex(obj): | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |     return hasattr(obj, 're') and hasattr(obj, 'im') | 
					
						
							| 
									
										
										
										
											1993-12-17 14:23:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-10-08 18:56:41 +00:00
										 |  |  | def ToComplex(obj): | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |     if IsComplex(obj): | 
					
						
							|  |  |  |         return obj | 
					
						
							| 
									
										
										
										
											2005-04-09 14:55:07 +00:00
										 |  |  |     elif isinstance(obj, tuple): | 
					
						
							|  |  |  |         return Complex(*obj) | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |     else: | 
					
						
							|  |  |  |         return Complex(obj) | 
					
						
							| 
									
										
										
										
											1994-10-08 18:56:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | def PolarToComplex(r = 0, phi = 0, fullcircle = twopi): | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |     phi = phi * (twopi / fullcircle) | 
					
						
							|  |  |  |     return Complex(math.cos(phi)*r, math.sin(phi)*r) | 
					
						
							| 
									
										
										
										
											1994-10-08 18:56:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | def Re(obj): | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |     if IsComplex(obj): | 
					
						
							|  |  |  |         return obj.re | 
					
						
							| 
									
										
										
										
											2005-04-09 14:55:07 +00:00
										 |  |  |     return obj | 
					
						
							| 
									
										
										
										
											1994-10-08 18:56:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | def Im(obj): | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |     if IsComplex(obj): | 
					
						
							|  |  |  |         return obj.im | 
					
						
							| 
									
										
										
										
											2005-04-09 14:55:07 +00:00
										 |  |  |     return 0 | 
					
						
							| 
									
										
										
										
											1994-10-08 18:56:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | class Complex: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |     def __init__(self, re=0, im=0): | 
					
						
							| 
									
										
										
										
											2005-04-09 10:51:19 +00:00
										 |  |  |         _re = 0 | 
					
						
							|  |  |  |         _im = 0 | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |         if IsComplex(re): | 
					
						
							| 
									
										
										
										
											2005-04-09 10:51:19 +00:00
										 |  |  |             _re = re.re | 
					
						
							|  |  |  |             _im = re.im | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             _re = re | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |         if IsComplex(im): | 
					
						
							| 
									
										
										
										
											2005-04-09 10:51:19 +00:00
										 |  |  |             _re = _re - im.im | 
					
						
							|  |  |  |             _im = _im + im.re | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             _im = _im + im | 
					
						
							|  |  |  |         # this class is immutable, so setting self.re directly is | 
					
						
							|  |  |  |         # not possible. | 
					
						
							|  |  |  |         self.__dict__['re'] = _re | 
					
						
							|  |  |  |         self.__dict__['im'] = _im | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def __setattr__(self, name, value): | 
					
						
							| 
									
										
										
										
											2007-07-17 20:59:35 +00:00
										 |  |  |         raise TypeError('Complex numbers are immutable') | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def __hash__(self): | 
					
						
							| 
									
										
										
										
											2005-04-09 14:55:07 +00:00
										 |  |  |         if not self.im: | 
					
						
							|  |  |  |             return hash(self.re) | 
					
						
							|  |  |  |         return hash((self.re, self.im)) | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def __repr__(self): | 
					
						
							|  |  |  |         if not self.im: | 
					
						
							| 
									
										
										
										
											2004-02-12 17:35:32 +00:00
										 |  |  |             return 'Complex(%r)' % (self.re,) | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2004-02-12 17:35:32 +00:00
										 |  |  |             return 'Complex(%r, %r)' % (self.re, self.im) | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def __str__(self): | 
					
						
							|  |  |  |         if not self.im: | 
					
						
							| 
									
										
										
										
											2004-02-12 17:35:32 +00:00
										 |  |  |             return repr(self.re) | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2004-02-12 17:35:32 +00:00
										 |  |  |             return 'Complex(%r, %r)' % (self.re, self.im) | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def __neg__(self): | 
					
						
							|  |  |  |         return Complex(-self.re, -self.im) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __pos__(self): | 
					
						
							|  |  |  |         return self | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __abs__(self): | 
					
						
							| 
									
										
										
										
											2005-04-09 14:55:07 +00:00
										 |  |  |         return math.hypot(self.re, self.im) | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def __int__(self): | 
					
						
							|  |  |  |         if self.im: | 
					
						
							| 
									
										
										
										
											2007-07-17 20:59:35 +00:00
										 |  |  |             raise ValueError("can't convert Complex with nonzero im to int") | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |         return int(self.re) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __float__(self): | 
					
						
							|  |  |  |         if self.im: | 
					
						
							| 
									
										
										
										
											2007-07-17 20:59:35 +00:00
										 |  |  |             raise ValueError("can't convert Complex with nonzero im to float") | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |         return float(self.re) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-03 22:36:06 +00:00
										 |  |  |     def __eq__(self, other): | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |         other = ToComplex(other) | 
					
						
							| 
									
										
										
										
											2010-07-03 22:36:06 +00:00
										 |  |  |         return (self.re, self.im) == (other.re, other.im) | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-11-28 19:15:13 +00:00
										 |  |  |     def __bool__(self): | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |         return not (self.re == self.im == 0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     abs = radius = __abs__ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def angle(self, fullcircle = twopi): | 
					
						
							|  |  |  |         return (fullcircle/twopi) * ((halfpi - math.atan2(self.re, self.im)) % twopi) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     phi = angle | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __add__(self, other): | 
					
						
							|  |  |  |         other = ToComplex(other) | 
					
						
							|  |  |  |         return Complex(self.re + other.re, self.im + other.im) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     __radd__ = __add__ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __sub__(self, other): | 
					
						
							|  |  |  |         other = ToComplex(other) | 
					
						
							|  |  |  |         return Complex(self.re - other.re, self.im - other.im) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __rsub__(self, other): | 
					
						
							|  |  |  |         other = ToComplex(other) | 
					
						
							|  |  |  |         return other - self | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __mul__(self, other): | 
					
						
							|  |  |  |         other = ToComplex(other) | 
					
						
							|  |  |  |         return Complex(self.re*other.re - self.im*other.im, | 
					
						
							|  |  |  |                        self.re*other.im + self.im*other.re) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     __rmul__ = __mul__ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-03 22:36:06 +00:00
										 |  |  |     def __truediv__(self, other): | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |         other = ToComplex(other) | 
					
						
							|  |  |  |         d = float(other.re*other.re + other.im*other.im) | 
					
						
							| 
									
										
										
										
											2007-07-17 20:59:35 +00:00
										 |  |  |         if not d: raise ZeroDivisionError('Complex division') | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |         return Complex((self.re*other.re + self.im*other.im) / d, | 
					
						
							|  |  |  |                        (self.im*other.re - self.re*other.im) / d) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-03 22:36:06 +00:00
										 |  |  |     def __rtruediv__(self, other): | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |         other = ToComplex(other) | 
					
						
							|  |  |  |         return other / self | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __pow__(self, n, z=None): | 
					
						
							|  |  |  |         if z is not None: | 
					
						
							| 
									
										
										
										
											2007-07-17 20:59:35 +00:00
										 |  |  |             raise TypeError('Complex does not support ternary pow()') | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |         if IsComplex(n): | 
					
						
							|  |  |  |             if n.im: | 
					
						
							| 
									
										
										
										
											2007-07-17 20:59:35 +00:00
										 |  |  |                 if self.im: raise TypeError('Complex to the Complex power') | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |                 else: return exp(math.log(self.re)*n) | 
					
						
							|  |  |  |             n = n.re | 
					
						
							|  |  |  |         r = pow(self.abs(), n) | 
					
						
							|  |  |  |         phi = n*self.angle() | 
					
						
							|  |  |  |         return Complex(math.cos(phi)*r, math.sin(phi)*r) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __rpow__(self, base): | 
					
						
							|  |  |  |         base = ToComplex(base) | 
					
						
							|  |  |  |         return pow(base, self) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-07-30 19:02:01 +00:00
										 |  |  | def exp(z): | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |     r = math.exp(z.re) | 
					
						
							|  |  |  |     return Complex(math.cos(z.im)*r,math.sin(z.im)*r) | 
					
						
							| 
									
										
										
										
											1994-10-08 18:56:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def checkop(expr, a, b, value, fuzz = 1e-6): | 
					
						
							| 
									
										
										
										
											2007-07-17 20:59:35 +00:00
										 |  |  |     print('       ', a, 'and', b, end=' ') | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |     try: | 
					
						
							|  |  |  |         result = eval(expr) | 
					
						
							| 
									
										
										
										
											2010-07-03 22:36:06 +00:00
										 |  |  |     except Exception as e: | 
					
						
							|  |  |  |         print('!!\t!!\t!! error: {}'.format(e)) | 
					
						
							|  |  |  |         return | 
					
						
							| 
									
										
										
										
											2007-07-17 20:59:35 +00:00
										 |  |  |     print('->', result) | 
					
						
							| 
									
										
										
										
											2005-04-09 14:55:07 +00:00
										 |  |  |     if isinstance(result, str) or isinstance(value, str): | 
					
						
							|  |  |  |         ok = (result == value) | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |     else: | 
					
						
							|  |  |  |         ok = abs(result - value) <= fuzz | 
					
						
							|  |  |  |     if not ok: | 
					
						
							| 
									
										
										
										
											2007-07-17 20:59:35 +00:00
										 |  |  |         print('!!\t!!\t!! should be', value, 'diff', abs(result - value)) | 
					
						
							| 
									
										
										
										
											1992-08-13 12:14:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | def test(): | 
					
						
							| 
									
										
										
										
											2007-07-17 20:59:35 +00:00
										 |  |  |     print('test constructors') | 
					
						
							| 
									
										
										
										
											2005-04-09 10:51:19 +00:00
										 |  |  |     constructor_test = ( | 
					
						
							|  |  |  |         # "expect" is an array [re,im] "got" the Complex. | 
					
						
							|  |  |  |             ( (0,0), Complex() ), | 
					
						
							|  |  |  |             ( (0,0), Complex() ), | 
					
						
							|  |  |  |             ( (1,0), Complex(1) ), | 
					
						
							|  |  |  |             ( (0,1), Complex(0,1) ), | 
					
						
							|  |  |  |             ( (1,2), Complex(Complex(1,2)) ), | 
					
						
							|  |  |  |             ( (1,3), Complex(Complex(1,2),1) ), | 
					
						
							|  |  |  |             ( (0,0), Complex(0,Complex(0,0)) ), | 
					
						
							|  |  |  |             ( (3,4), Complex(3,Complex(4)) ), | 
					
						
							|  |  |  |             ( (-1,3), Complex(1,Complex(3,2)) ), | 
					
						
							|  |  |  |             ( (-7,6), Complex(Complex(1,2),Complex(4,8)) ) ) | 
					
						
							|  |  |  |     cnt = [0,0] | 
					
						
							|  |  |  |     for t in constructor_test: | 
					
						
							|  |  |  |         cnt[0] += 1 | 
					
						
							|  |  |  |         if ((t[0][0]!=t[1].re)or(t[0][1]!=t[1].im)): | 
					
						
							| 
									
										
										
										
											2007-07-17 20:59:35 +00:00
										 |  |  |             print("        expected", t[0], "got", t[1]) | 
					
						
							| 
									
										
										
										
											2005-04-09 10:51:19 +00:00
										 |  |  |             cnt[1] += 1 | 
					
						
							| 
									
										
										
										
											2007-07-17 20:59:35 +00:00
										 |  |  |     print("  ", cnt[1], "of", cnt[0], "tests failed") | 
					
						
							| 
									
										
										
										
											2005-04-09 10:51:19 +00:00
										 |  |  |     # test operators | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |     testsuite = { | 
					
						
							|  |  |  |             'a+b': [ | 
					
						
							|  |  |  |                     (1, 10, 11), | 
					
						
							|  |  |  |                     (1, Complex(0,10), Complex(1,10)), | 
					
						
							|  |  |  |                     (Complex(0,10), 1, Complex(1,10)), | 
					
						
							|  |  |  |                     (Complex(0,10), Complex(1), Complex(1,10)), | 
					
						
							|  |  |  |                     (Complex(1), Complex(0,10), Complex(1,10)), | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |             'a-b': [ | 
					
						
							|  |  |  |                     (1, 10, -9), | 
					
						
							|  |  |  |                     (1, Complex(0,10), Complex(1,-10)), | 
					
						
							|  |  |  |                     (Complex(0,10), 1, Complex(-1,10)), | 
					
						
							|  |  |  |                     (Complex(0,10), Complex(1), Complex(-1,10)), | 
					
						
							|  |  |  |                     (Complex(1), Complex(0,10), Complex(1,-10)), | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |             'a*b': [ | 
					
						
							|  |  |  |                     (1, 10, 10), | 
					
						
							|  |  |  |                     (1, Complex(0,10), Complex(0, 10)), | 
					
						
							|  |  |  |                     (Complex(0,10), 1, Complex(0,10)), | 
					
						
							|  |  |  |                     (Complex(0,10), Complex(1), Complex(0,10)), | 
					
						
							|  |  |  |                     (Complex(1), Complex(0,10), Complex(0,10)), | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |             'a/b': [ | 
					
						
							|  |  |  |                     (1., 10, 0.1), | 
					
						
							|  |  |  |                     (1, Complex(0,10), Complex(0, -0.1)), | 
					
						
							|  |  |  |                     (Complex(0, 10), 1, Complex(0, 10)), | 
					
						
							|  |  |  |                     (Complex(0, 10), Complex(1), Complex(0, 10)), | 
					
						
							|  |  |  |                     (Complex(1), Complex(0,10), Complex(0, -0.1)), | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |             'pow(a,b)': [ | 
					
						
							|  |  |  |                     (1, 10, 1), | 
					
						
							|  |  |  |                     (1, Complex(0,10), 1), | 
					
						
							|  |  |  |                     (Complex(0,10), 1, Complex(0,10)), | 
					
						
							|  |  |  |                     (Complex(0,10), Complex(1), Complex(0,10)), | 
					
						
							|  |  |  |                     (Complex(1), Complex(0,10), 1), | 
					
						
							|  |  |  |                     (2, Complex(4,0), 16), | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2005-04-09 14:55:07 +00:00
										 |  |  |     for expr in sorted(testsuite): | 
					
						
							| 
									
										
										
										
											2007-07-17 20:59:35 +00:00
										 |  |  |         print(expr + ':') | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |         t = (expr,) | 
					
						
							|  |  |  |         for item in testsuite[expr]: | 
					
						
							| 
									
										
										
										
											2005-04-09 14:55:07 +00:00
										 |  |  |             checkop(*(t+item)) | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-10-08 18:56:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | if __name__ == '__main__': | 
					
						
							| 
									
										
										
										
											2003-04-24 17:13:18 +00:00
										 |  |  |     test() |