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

**Maturity Index:** Relatively mature

Arithmetical operations such as **multiply:** or **add:** are defined only on instances of the same class, or more precisely on objects for which **sameClass:** returns YES. The algebraic properties of a set (class) of objects is tested by sending messages to an element of the set (for example **inOrderedSet**), and control the algorithms being used. Nullary operators, like obtaining the unity element of a set, are made unary : the unity element of a set is obtained by sending **one** to an arbitrary element of the set.

For example, for two Integer objects, **sameClass:** simply returns YES, but for two IntegerModp objects, **sameClass:** returns YES if and only if the moduli are equal. This means that you can sum, using **add:**, any pair of Integer instances, but that you cannot add an object mod *p* to an object mod *q*. Also, you cannot add a Integer instance to a IntegerModp instance using the **add:** method.

- str
- str:
- intValue
- intValue:
- asModp:
- isFloatingPoint
- asNumerical
- floatValue
- floatValue:
- asTotalFraction
- asScalar
- asSymbol

- inAdditiveSemiGroup
- inAdditiveMonoid
- inAdditiveGroup
- isZero
- notZero
- isOpposite:
- notOpposite:
- zero
- negate
- add:
- subtract:
- increment
- decrement
- multiplyIntValue:
- double
- quadruple
- divideIntValue:
- half
- quarter

- commutes
- commutesWith:
- inSemiGroup
- inMonoid
- inGroup
- one
- minusOne
- isOne
- notOne
- isMinusOne
- notMinusOne
- square
- multiply:
- power:
- inverse
- isUnit
- notUnit
- divide:

- characteristic
- isCharacteristicZero
- notCharacteristicZero
- isCharacteristicTwo
- notCharacteristicTwo
- frobenius
- frobeniusInverse
- dimensionOverPrimeField

- scalarZero
- scalarContent
- divideScalarContent
- multiplyScalar:
- divideScalar:
- addScalar:
- subtractScalar:

+ (STR)This method returns the value of the revision stringcakitRevision

+Creates an object given a string description. No default implementation.str:(STR)aString

+Creates an object given an int value. No default.int:(int)intValue

-Creates a copy of the object by sendingcopy

Subclasses must implement their own versions of **copy** to copy additional memory consumed by the copied object.

Note that the message to- copy { self = [super copy]; pointer = malloc(nBytes); return self; }

**See also:** deepCopy

-Creates adeepCopy

Subclasses must implement their own versions of **deepCopy** to make a full independent copy of the object.

- deepCopy { self = [super deepCopy]; companionObject = [companionObject deepCopy]; return self; }

- (BOOL)Whether the objects belong to the same class; the default implementation checks whether thesameClass:a

return [super sameClass:a] && [self modulus] == [a modulus];

- (BOOL)WhetherdifferentClass:a

- (BOOL)Equivalent to :isKindOfSequence

[self isKindOf:(id)[CASequence class]]

- (STR)Returns a string containing a symbolic representation for the object. Suited for small expressions only since output is unbuffered. Works by allocating a small buffer and then invokingstr

You don't have to free the string (it is deallocated when you free or change the object), which makes it easy to use the method as follows :

fprintf(stderr,"Value of this %s is %s\n",[anObject name],[anObject str]);

-Returns a new object, instance of the same class, created fromstr:(STR)aString

- (int)Returns, if it makes sense, the value of the object as C integer. There is no default implementation for this method.intValue

-Returns a new object of the same class withintValue:(int)i

-Returns an object that is the value modulo the small prime numberasModp:(unsigned short)p

- (BOOL)Returns YES if the object is some kind of floating-point arithmetic. The default implementation returns NO. No attempt has been made to integrate floating-point arithmetic into the Computer Algebra Kit's framework of algebraic structures; floating-point numbers are always treated as a special case.isFloatingPoint

-Returns an object that is the numerical value for the object that receives the message. For example, an integer object returns a floating-point object as numerical value; a matrix returns a matrix with numerical values and so on.asNumerical

- (float)Returns, if it makes sense, the value of the object as C floating-point number. There is no default implementation for this method.floatValue

-Returns a new object of the same class withfloatValue:(float)f

-Returns a new fraction with the numerator set to a new reference to the original object, and with the denominator set to one. For example, an integer object returns a rational number.asTotalFraction

-Returns a new scalar object orasScalar

-Returns a new symbol object orasSymbol

**Note:** Symbol itself does *not* implement this method.

- (BOOL)Should test whether the objects are equal. Returns, by default, YES if the two objects are the same (ie. pointer equal)isEqual:a

- (BOOL)WhethernotEqual:a

- (BOOL)Whether the object is an element of a (totally) ordered set. Elements can be compared withinOrderedSet

- (int)This method should return -1, 0, or +1 ifcompare:b

- (int)Returns the sign of the object : plus one if positive (greater than zero), zero if zero and minus one if negative (less than zero). There is no default implementation for this method.sign

- (BOOL)Tests whether the object is less than (but not equal to)isLess:a

- (BOOL)Tests whether the object is greater than (but not equal to)isGreater:a

- (BOOL)Tests whether the object is less than or equal toisLessEqual:a

- (BOOL)Tests whether the object is greater than or equal toisGreaterEqual:a

-Returns the absolute value of the object (a new object). If the object is negative, invokesabsValue

- (BOOL)Should return YES if the object is an element of an additive semigroup ie., a set equiped with a (commutative) additive operation, but not necessarily with a unique zero element. Objects that return YES should be prepared to receiveinAdditiveSemiGroup

- (BOOL)Should return YES if the object is an element of an additive monoid ie., an additive semigroup with a unique zero element : if an object returns YES to this method, and ifinAdditiveMonoid

- (BOOL)Should return YES if the object is an element of an additive group ie., an additive monoid with an additive inverse for each element. There is no default implementation for this method.inAdditiveGroup

- (BOOL)Returns YES if the object is equal to zero. There is no default implementation for this method.isZero

If the object is an element of an additive monoid, the method should test whether the object is the *unique* zero element. Otherwise, **isZero** should return YES if the object is the zero element for itself. Matrices of variable dimension, for example, have zero elements of different dimension.

- (BOOL)WhethernotZero

- (BOOL)Should return YES if the objects are additive inverses. Zero is the only object that is its own additive inverse, unless the characteristic is equal to two.isOpposite:b

- (BOOL)WhethernotOpposite:b

-Returns a new reference to the zero element.zero

If the object is an element of an additive monoid, the zero element is unique. Otherwise, **zero** should return an element *c* such that **self** + *c* = 0. Matrices of variable dimension, for example, have zero elements of different dimension.

There is no default implementation for this method.

-Returns the opposite of the object (a new object). There is no default implementation.negate

-Returns the sumadd:b

-Returns a new object, equal tosubtract:b

-Addsincrement

-Subtractsdecrement

-Returns a new object equal to the productmultiplyIntValue:(int)b

**See also:** zero, double, quadruple

-Multiplies the object by two. Returns a new object. There is no default implementation for this method.double

-Multiplies the object by four. Returns a new object.quadruple

There is no default implementation for this method.

-Returns a new object, thedivideIntValue:(int)b

-Divides the object by two. Returns a new object, orhalf

-Divides the object by four. Returns a new object, orquarter

- (BOOL)Should return YES if multiplication is commutative for all elements of the set that the object belongs to. There is no default implemenation for this method.commutes

- (BOOL)Should return YES if multiplication is commutative for the two objects. There is no default implemenation for this method.commutesWith:b

- (BOOL)Should return YES if the object is an element of a (multiplicative) semigroup, ie. a set equiped with a (possibly non-commutative) multiplicative operation. However, the set doesn't necessarily have a unique unity element. For example, matrices of free dimension don't. There is no default implemenation for this method.inSemiGroup

- (BOOL)Should return YES ifinMonoid

- (BOOL)Should return YES ifinGroup

-Returns a new reference to the multiplicative unity.one

If the object is an element of a multiplicative monoid the unity element is unique. Otherwise, **one** returns the (right) multiplicative unity element for the object itself, ie. an element *c* such that *self c* = 1. Matrices of variable dimension, for example, have unity elements of different dimension.

There is no default implementation for this method.

-Returns a new reference to the opposite of the multiplicative unity. Negates by default the object returned byminusOne

- (BOOL)Should return YES if the object is equal to one. There is no default implementation for this method.isOne

If the object is an element of an multiplicative monoid, the method should test whether the object is the *unique* unity element. Otherwise, **isOne** should return YES if the object is the (right) multiplicative unity element for itself. Matrices of variable dimension, for example, have unity elements of different dimension.

- (BOOL)WhethernotOne

- (BOOL)Should return YES if the object is equal to minus one i.e., the additive inverse of the multiplicative unity. There is no default implementation for this method.isMinusOne

- (BOOL)WhethernotMinusOne

-Returns the square of the object ie., a new object equal to the object multiplied by itself.square

-Returns a new object equal to the productmultiply:b

Note that when multiplication is not commutative, [a multiply:b] is not the same thing as [b multiply:a]. Non-commutative multiplication is currently hardly supported. In general, we have used throughout the Computer Algebra Kit *right* multiplication. Left multiplication will be explicitely indicated.

-Returns the object raised to thepower:(int)n

If *n* is zero, the method invokes **one**, except if the object itself is zero. In that case the method returns **nil**. If *n* is negative, the method raises the inverse of the object to the *-n*-th power, or if the object is not invertible, it returns **nil**.

The default implementation of this method consists of the binary exponentation algorithm (invoking **square**). The method may be overridden in those cases where the binary exponentation algorithm performs worse than, for example, a repeated multiplication strategy (for sufficiently sparse polynomials e.g.).

-Returns the multiplicative inverse (a new object). If there is no inverse, the method returnsinverse

- (BOOL)Tests whether the object has a multiplicative inverse. The default implementation tests whetherisUnit

- (BOOL)WhethernotUnit

-Returns thedivide:b

**Note:** Use **quotient:** to determine the quotient of a division with remainder.

-Dividesremainder:bquotient:(id *)q

**See also:** divide, quotient, remainder

-Returns a new object, the remainder on division ofremainder:b

**Note:** For ordered domains (such as the integers), this method should return a *signed* remainder, while **modulo:** returns an unsigned remainder.

**See also:** modulo

-Returns a new object, the quotient on division of byquotient:b

**See also:** divide

- (BOOL)Returns YES ifinEuclideanDomain

- (BOOL)Tests whether the greatest common divisor ofisCoprime:b

- (BOOL)WhethernotCoprime:b

- (BOOL)WhetherisGcd:a:b

- (BOOL)WhetherisLcm:a:b

-Returns a new object, the greatest common divisor ofgcd:b

-Returns a new object, the bezout coefficient of the object, and if a non NULL pointer is passed forbezout:bgcd:(id *)gcd

There is no default implementation for this method.

-Returns the least common multiple of the objects. The default implementation multiplies the the objects and divides by their gcd. In the case of an additive semi-group, lcm(a,0) = a and lcm(0,b) = b and lcm(0,0) = 0.lcm:b

-Returns a new object, the representant of the object modulomodulo:m

The default implementation invokes **remainder:**. Adds back *m*, if **self** is ordered and the remainder is negative.

-Returns a new object, the productmultiply:bmodulo:m

-Returns a new object, the square ofsquareModulo:m

-Returns a new object, equal topower:(int)nmodulo:m

If **self** and *n* are equal to zero, returns **nil**.

**See also:** genpower:modulo:

-Returns a new object, equal togenpower:nmodulo:m

If **self** and *n* are equal to zero, returns **nil**.

-Returns a new object, the inverse ofinverseModulo:m

-Returns a new random object. For example, for the integers,random

There is no default implementation.

- (int)Returns the characteristic of (the set of) the object, ie. the numbercharacteristic

- (BOOL)WhetherisCharacteristicZero

- (BOOL)WhethernotCharacteristicZero

- (BOOL)WhetherisCharacteristicTwo

- (BOOL)WhethernotCharacteristicTwo

-Returns a new object, the image offrobenius

-Returns a new object, the inverse image offrobeniusInverse

- (int)This method should return the dimension of a finite field over its prime field. For example, the dimension of GaloisField(9) over GaloisField(3) is 2.dimensionOverPrimeField

- (BOOL)The object is in a ring if it's in an additive group and a multiplicative monoid.inRing

- (BOOL)Should return YES if the object is an element of a ring without zero divisors. There is no default implementation of this method. Examples of integral domains in the Computer Algebra Kit include, the integers, the Gaussian (complex) integers and polynomial rings.inIntegralDomain

- (BOOL)Whether the object is element of an additive group and a multiplicative group. Examples of fields in the Computer Algebra Kit include, the integers modinField

- (BOOL)Whether the object is element of a field of fractions. Returns NO by default; overridden by Fraction and used by some linear algebra algorithms to reduce computations over a field of fractions to computations over an integral domain.inFieldOfFractions

-Returns a reference to the zero scalar object.scalarZero

**See also:** zero

-Returns a new scalar object, the (scalar) content of the objects, ie. the gcd of its scalars.scalarContent

There is no default implementation of this method.

-If the scalar content is zero, this method simply returns a copy ofdivideScalarContent

-Returns a new object, equal tomultiplyScalar:s

-Returns a new object, equal todivideScalar:s

-Adds the scalaraddScalar:s

-Subtracts the scalarsubtractScalar:s

- (BOOL)Should return YES if the printing methods for this object print a leading minus sign. This can be used in other implementations to avoid printing a plus sign followed by a minus sign. The default implementation returns NO.printsLeadingSign

- (BOOL)Should return YES if the printing methods for this object print multiple terms separated by a plus or minus sign. This can be used in other implementations to place the expression between parentheses if necessary. The default implementation returns NO.printsSum

- (BOOL)Should return YES if the printing methods for this object print multiple factors separated by a space or multiplication sign. This can be used in other implementations to place the expression between parentheses if necessary. The default implementation returns NO.printsProduct

-Should print a textual representation of the object toprintOn:(IOD)aFile