ccomplex Specification Sheet


Computer Algebra Kit (c) 1993,98 by Comp.Alg.Objects. All Rights Reserved.

Complex

Inherits from:CAObject

Maturity Index:Relatively immature

Class Description

A complex object consists of two real objects, a real and imaginary part. Real objects could be arbitrary Computer Algebra Kit objects, but the class has been used so far only for the Gaussian integers i.e., complex numbers over the integers. The imaginary unit is represented by the symbol I.

Method Types

Creation

Identity

Conjugation

Addition

Multiplication

Complex Division

Greatest Common Divisor

Printing

Methods



real:

+ real : aReal

Returns a new complex object with real part set to aReal and the imaginary part set to the real zero.



real:imaginary:

+ real : aReal imaginary : anotherReal

Returns a new complex object with real part set to aReal and the imaginary part set to anotherReal. Don't forget to use cheapCopy if you want to keep the arguments in scope.



copy

- copy

Returns a new copy of the complex object; sends cheapCopy messages to real and imaginary part.



deepCopy

- deepCopy

Returns a new copy of the complex object; sends deepCopy messages to real and imaginary part.



clear

- clear

Sends free messages to denominator and numerator.



real

- real

Returns the real part of a complex number. You may not modify or free the object returned by this method.



imaginary

- imaginary

Returns the imaginary part of a complex number. You may not modify or free the object returned by this method.



isReal

- (BOOL) isReal

Whether the imaginary part is equal to zero.



notReal

- (BOOL) notReal

Whether the isReal returns NO.



hash

- (unsigned) hash

Returns a small integer that is the same for objects that are equal in the sense of isEqual:.



isEqual:

- (BOOL) isEqual : b

Whether real and imaginary parts are equal to each other.



conjugate

- conjugate

Returns a new reference to the object if it is real. Otherwise, returns a new object that is equal to the complex conjugate of the object. The conjugate of a + I b is a - I b.



norm

- norm

Returns a new real object, the norm of the complex object i.e., the object multiplied by its conjugate.



asReal

- asReal

If the imaginary part of the object is zero, this method returns a new reference to the real part of the object.



zero

- zero

Returns a new complex object with real and imaginary part equal to zero.



isZero

- (BOOL) isZero

Whether real and imaginary part are equal to zero.



isOpposite:

- (BOOL) isOpposite : b

Whether real and imaginary parts are opposite to each other.



negate

- negate

Returns a new complex number, by negating real and imaginary parts.



double

- double

Returns a new complex number, by doubling real and imaginary parts.



add:

- add : b

Returns the sum of the complex numbers; adds real and imaginary parts together.



subtract:

- subtract : b

Returns the difference of the complex numbers; subtracts real and imaginary parts from each other.



I

- I

Returns a new reference to the imaginary unit.



one

- one

Returns a new object with real part equal to one and imaginary part equal to zero.



isOne

- (BOOL) isOne

Whether the complex object is a multiplicative unit. The complex units consist of the real units and the real units multiplied by the imaginary unit i.



isMinusOne

- (BOOL) isMinusOne

Whether the complex object is a multiplicative unit. The complex units consist of the real units and the real units multiplied by the imaginary unit i.



isUnit

- (BOOL) isUnit

Whether the complex object is a multiplicative unit. The complex units consist of the real units and the real units multiplied by the imaginary unit i.



square

- square

Returns the complex number multiplied by itself, computed by the rule :

(a+I b)^2 == (a^2 - b^2) + I (2 a b)


multiply:

- multiply : b

Returns the product of the two complex numbers, computed by the rule :

(a+I b)(c+I d) == (ac-bd) + I (ad+bc)


power:

- power :(int) n

Returns the complex number raised to the n-th power. If the object is real, simply computes the n-th power as a real. Otherwise, computes the power by the binary exponentation algorithm.



divide:

- divide : b

Returns the exact quotient of the complex number by the complex number b. Multiplies by the conjugate of b and then divides by the norm of b, or returns nil if the latter division is not exact.



inverse

- inverse

Returns the conjugate of the complex number divided by its norm, or nil if the latter division is not exact.



quotient:

- quotient : b

Returns the quotient on division by b.

Note: I'm not sure about the algorithm I'm using here !



remainder:quotient:

- remainder : b quotient :(id *) q

Computes the remainder, and if q is non-NULL pointer, the quotient on division by b.



gcd:

- gcd : b

If both objects are real, returns a complex object with real part set to the (real) gcd of the objects. Otherwise, computes the greatest common divisor by the Euclidean algorithm.



printOn:

- printOn :(IOD) aFile

Prints the number to aStream.