vector Specification Sheet


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

Vector

Inherits from:CAObject

Maturity Index:Relatively mature

Class Description

A vector consists of a number of scalars that can be arbitrary Computer Algebra Kit objects, but they currently have to be either floating-point or elements of a field (see inField) or elements of an integral domain (see inIntegralDomain).

There are methods to access, insert and remove scalars. It's also possible to place or replace a scalar directly at a given index. See the documentation on eachScalar to access the scalar at a given index.

Note: Vector objects are meant for computational tasks. They are no substitute for List or Collection objects, that are better suited for the purpose of storing objects.

Method Types

Creation

Identity

Insertion Scalars

Removing Scalars

Placing and Replacing

Accessing Scalars

Addition

Scalar Multiplication

Multiplication

Expression Object

Printing

Methods



newStrValue:

+ newStrValue :(STR) strValue

Creates a vector from strValue. The process is divided into two steps : first, the method checks the argument to see whether it can recognize the domain of the scalars; it currently can handle <<integer and rational>> coefficients. Then the method creates a vector and invokes -strValue:.

aVector = [CAVector newStrValue:"{1,2,3,4,5,6,-7}"];
See also: - strValue:



newCollection:

+ newCollection : aCltn

Creates a vector containing references to the scalars from aCltn. The collection must not be empty. You remain responsible for freeing the collection.



newScalarZero:numScalars:

+ newScalarZero : aScalarZero numScalars :(int) numScalars

Creates a new vector with numScalars zero scalars.



copy

- copy

Returns a new vector. Sends cheapCopy messages to the scalars in the vector.



deepCopy

- deepCopy

Returns a new vector. Sends deepCopy messages to the scalars in the vector.



clear

- clear

Sends free messages to the scalars in the vector.



scalarZero

- scalarZero

Returns the zero scalar element. You may not free or modify the object returned by this method.



numScalars

- (int) numScalars

Returns the number of scalar objects in the vector. Returns 0 if the vector is empty. The first scalar in the vector is at index 0, the last scalar at numScalars minus one.



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 the two objects are equal. Returns YES if the objects are pointer equal.



insertScalar:

- insertScalar : aScalar

Inserts aScalar as first entry and returns self. The object aScalar belongs to the vector after insertion, and is not necessarily copied. To insert a scalar, the reference count of the vector should be equal to one.



insertScalar:at:

- insertScalar : aScalar at :(int) i

Inserts aScalar as i-th entry and returns self. The object aScalar belongs to the vector after insertion, and is not necessarily copied. If i is equal to zero, this method is identical to -insertScalar:. If i is equal to numScalars, this method inserts the scalar as last element. The reference count of the vector should be equal to one.



removeScalar

- removeScalar

Removes (and returns) the first scalar in the vector (the scalar at index 0). Returns nil if there were no more elements left. This can be used in the following way :

while (c = [vector removeScalar]) { /* do something with c */ }
To remove a scalar, the reference count of the vector should be equal to one.



removeScalarAt:

- removeScalarAt :(int) i

Removes and returns the i-th scalar in the vector. If i is zero, this method is identical to removeScalar. The reference count of the vector should be equal to one. Unlike removeScalar, which returns nil if there are no more scalars in the vector, this method generates an error message if you attempt to remove a scalar at an illegal index.



freeScalarAt:

- freeScalarAt :(int) i

Removes and frees the i-th scalar in the vector. The reference count of the vector should be equal to one. Returns self.



placeScalar:at:

- placeScalar : aScalar at :(int) i

Frees the scalar at position i and replaces it by the scalar object aScalar. Returns self. The scalar aScalar belongs to the receiving vector object; it is not necessarily copied. This is similar to List's -addObject: method. It is an error to use an illegal index i or to attempt to set a scalar in a vector whose reference count is not equal to one.



replaceScalarAt:with:

- replaceScalarAt :(int) i with : aScalar

Similar to placeScalar:at: but returns, rather than frees, the scalar at position i after replacing it by aScalar. It is an error to use an illegal index i or to attempt to replace a scalar in a vector whose reference count is not equal to one.



asCollection

- asCollection

Returns a new collection containing new references to the scalars in the vector.



asNumerical

- asNumerical

Returns a new vector, whose scalars are the numerical value of the scalars of the original vector.



asModp:

- asModp :(unsigned short) p

Returns a new vector, whose scalars are the value of the scalars of the original vector mod p.



onCommonDenominator:

- onCommonDenominator :(id *) denominator

Puts a vector with fractional scalars on a common denominator. Returns a new vector with integral scalars, and, by reference, the common denominator of the scalars in the vector.



eachScalar

- eachScalar

Returns a new sequence object that gives access to the scalars of the vector.



floatValueAt:

- (float) floatValueAt :(int) i

Returns the floatValue of the scalar at the i-th position.



intValueAt:

- (int) intValueAt :(int) i

Returns the intValue of the scalar at the i-th position.



zero

- zero

Returns a vector of the same dimension as the object that receives the message, but all filled with zero scalars.



isZero

- (BOOL) isZero

Whether the object is equal to zero.



isOpposite:

- (BOOL) isOpposite : b

Whether the object is the opposite of b.



negate

- negate

Returns the opposite of the object.



double

- double

Returns a new object, equal to the object multiplied by two i.e., added to itself.



add:

- add : b

Adds b to the object. Returns a new object.



subtract:

- subtract : b

Subtracts b from the object. Returns a new object.



addScalar:at:

- addScalar : s at :(int) i

Returns a new vector. Adds s to the scalar at position i, and replaces the scalar by the sum. i must be between 0 and the number of scalars in the vector. This method is not an insertion method.

See also: insertScalar:at:, replaceScalar:at:



subtractScalar:at:

- subtractScalar : s at :(int) i

Returns a new vector. Subtracts s from the scalar at position i. i must be between 0 and the number of scalars in the vector. This method is not an insertion method.



multiplyScalar:

- multiplyScalar : s

Multiplies by the scalar s. Returns a new object.



divideScalar:

- divideScalar : s

Exact division by the scalar s. Returns a new object, or nil if the division is not exact.



dotSquare

- dotSquare

Returns a new scalar product, the dot product of the vector by itself, defined as the sum of squares of the scalars in the vector.



dotMultiply:

- dotMultiply : aVector

Returns a new scalar product, the dot product of the vector self by aVector, defined as the sum of the products of the scalars in the vectors.



multiplyLeftMatrix:

- multiplyLeftMatrix : aMatrix

Returns a new vector, the product of aMatrix by the column vector self.



asExpression

- asExpression

Returns the vector as a an expression (collection of expressions).



expression:

- expression : anExpression

Attempts to create a vector over the same domain of scalars as the original vector. Returns nil if that fails.



printToFile:

- printToFile :(FILE *) aFile

Prints, between braces, a comma separated list of the scalars (by sending printToFile: messages to the scalars).