# vector Specification Sheet

Computer Algebra Kit (c) 1993,00 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.

## Methods

### collection:

+collection:aCltn
Creates a vector containing references to the scalars from aCltn. The collection must not be empty.

### scalarZero:numScalars:

+scalarZero:aScalarZeronumScalars:(int)numScalars
Creates a new vector with numScalars zero scalars.

### copy

-copy
Returns a new vector.

### deepCopy

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

### scalarZero

-scalarZero
Returns the zero scalar element.

### 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.

### 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:aScalarat:(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.

### 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. 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.

### placeScalar:at:

-placeScalar:aScalarat:(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)iwith:aScalar
Similar to placeScalar:at: but returns 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.

### addScalar:at:

-addScalar:sat:(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:sat:(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.

### 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.

### printOn:

-printOn:(IOD)aFile
Prints, between braces, a comma separated list of the scalars (by sending printOn: messages to the scalars).