# term Specification Sheet

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

# Term

Inherits from: CAObject

## Class Description

Maturity Index : Relatively Mature

A term consists of a coefficient multiplied by a symbol raised to an integral exponent. The coefficient is a scalar object or a polynomial. The symbol object is nil if the exponent is equal to zero.

## Recursive Polynomials

A polynomial in recursive representation is a sum of terms. If the polynomial is variable sparse, each symbol can be different and the coefficients of the terms are scalar objects or again variable sparse polynomials; if the coefficient is not a scalar object, then the exponent of the term cannot be zero (for example, the term 3 x^0 y^2 z^0 is reduced to 3 y^2 in the variable sparse case). If the polynomial is variable dense, all symbols are equal to each other and the coefficients are either all scalar objects or again all variable dense polynomials; the exponent of a term may be zero, even if the coefficient is a polynomial (3 x^0 y^2 z^0 is a valid object in the variable dense case). In a degree dense polynomial, the coefficients of the terms can be zero; in a degree sparse polynomial they cannot.

## Monomials

A monomial is a product of terms. The coefficients of the terms of a monomial are scalar objects that are equal to one (but it's possible to insert terms with a non-trivial coefficient). In a variable dense monomial, the exponents of the terms can be equal to zero; in a variable sparse monomial, they cannot.

## Factors

A factored polynomial is a product of terms. The coefficients of the terms in the factorization are scalar objects, mostly equal to one, but they can store the content extracted out of the (primitive) factors. The symbol (nucleus) objects of the terms are polynomials i.e., the factors in the factorization.

## Method types

### Creation

- scalar:symbol:exponent:
- coefficient:symbol:exponent:
- copy
- deepCopy
- clear

### Identity

- scalarZero
- coefficient
- symbol
- exponent
- degree
- hash
- isEqual:
- compareExponents:

### Coercion

- intValue
- intValue:
- floatValue
- floatValue:
- asScalar
- asSymbol

### Addition

- zero
- isZero
- isOpposite:
- negate
- double
- add:
- subtract:

### Multiplication

- one
- isOne
- isMinusOne
- square
- inverse
- multiplyScalar:
- multiplyCoefficient:
- multiply:
- divideScalar:
- divideCoefficient:
- divide:

### Exponentation

- power:
- root:
- squareRoot

### Characteristic

- frobenius
- frobeniusInverse

### Derivation and Integration

- derive
- integrate

### Printing

- printsLeadingSign
- printsSum
- printsProduct
- printOn:

## Methods

### scalar:symbol:exponent:

> +scalar:aScalar symbol:aSymbol exponent:(int)anExponent

Creates a new term with coefficient, symbol and exponent set to the specified objects. This method sets scalarZero to the zero element for aScalar.

### coefficient:symbol:exponent:

> +coefficient:aCoefficient symbol:aSymbol exponent:(int)anExponent

Creates a new term with coefficient, symbol and exponent set to the specified objects. This method sets scalarZero to the zero element obtained by sending scalarZero to aCoefficient.

### copy

> -copy

Copies the term object, and if the coefficient is a scalar object, adds a reference to it. If the coefficient is a polynomial, makes a copy of it.

See also: copy (Polynomial)

### deepCopy

> -deepCopy

Makes deep copies of the term object and its coefficient and symbol.

See also: deepCopy (Polynomial)

### clear

> -clear

Frees coefficient and symbol (if non-nil).

### scalarZero

> -scalarZero

Returns the zero scalar of the term; you may not modify or free this object.

### coefficient

> -coefficient

Returns the coefficient of the term; you may not modify or free this object.

### symbol

> -symbol

Returns the symbol of the term; you may not modify or free this object. If the exponent of the term is equal to zero, this method returns nil.

### exponent

> - (int)exponent

Returns the exponent of the term. If the exponent is equal to zero, the symbol of the term is equal to nil.

### degree

> - (int)degree

Equivalent to exponent.

### hash

> - (unsigned)hash

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

### isEqual:

> - (BOOL)isEqual:b

Two terms are equal if they are pointer equal or if the coefficients are equal, if the exponents are equal and if the symbols are equal (or both nil).

### compareExponents:

> - (int)compareExponents:b

Compares two terms with respect to symbols and exponents; this imposes an ordering for the terms in variable sparse polynomials. Returns zero if the terms are pointer equal. A term with symbol nil is less than a term with non-nil symbol. Compares the symbols, and if they are equal, compares the exponents.

### intValue

> - (int)intValue

Returns, if the exponent is equal to zero, the intValue of the coefficient. If not, generates an error message.

### intValue:

> -intValue:(int)aValue

Returns a new term with exponent equal to zero and with a coefficient whose value as int is equal to aValue.

### floatValue

> - (float)floatValue

Returns, if the exponent is equal to zero, the floatValue of the coefficient. If not, generates an error message.

### floatValue:

> -floatValue:(float)aValue

Returns a term with exponent equal to zero and with a coefficient whose value as float is equal to aValue.

### asScalar

> -asScalar

Returns the term as scalar object. Returns nil if the exponent of the term is not equal to zero. If the coefficient of the term is a scalar, the method returns a new reference to it, otherwise the coefficient is a polynomial and the method returns the scalar value of it. Note that in the variable sparse case, a term that is a scalar must have a scalar object as coefficient i.e., the term is always simplified.

### asSymbol

> -asSymbol

Returns the term as symbol object. If the exponent of the term is zero and if the coefficient is a polynomial, returns the symbol value of the polynomial. If the exponent is equal to one and the coefficient is one, returns a new reference to the symbol of the term. Otherwise returns nil.

### zero

> -zero

Returns a new term with coefficient equal to the zero element for the coefficient of the term that receives the message.

### isZero

> - (BOOL)isZero

Whether the coefficient of the term is equal to zero. The exponent of the term may be non-zero.

### isOpposite:

> - (BOOL)isOpposite:b

Whether the coefficients of the term are opposite, and the exponents and symbols are equal to each other.

### negate

> -negate

Negates the coefficient of the term.

### double

> -double

Doubles the coefficient of the term.

### add:

> -add:b

Returns a new term that is the sum of the two terms i.e., the coefficients are added together using add: or addScalar:. The exponents must be equal and the symbols must be both nil or equal to each other.

### subtract:

> -subtract:b

Returns a new term that is the difference of the two terms i.e., the coefficients are subtracted from each other using subtract: or subtractScalar:. The exponents must be equal and the symbols must be both nil or equal to each other.

### one

> -one

Returns a term with coefficient equal to one.

### isOne

> - (BOOL)isOne

Whether the coefficient is one and the exponent is equal to zero.

### isMinusOne

> - (BOOL)isMinusOne

Whether the coefficient is minus one and the exponent is equal to zero.

### square

> -square

Squares coefficient and multiplies exponent by two.

### inverse

> -inverse

Inverts coefficient and negates the exponent. Returns nil if the coefficient has no inverse.

### multiplyScalar:

> -multiplyScalar:b

Returns a new term; multiplies the coefficient of the term by the scalar object b, using multiply: if the coefficient of the term is a scalar object, or multiplyScalar: otherwise. The symbol and exponent of the resulting term are equal to that of the original term.

### multiplyCoefficient:

> -multiplyCoefficient:b

Returns a new term; multiplies the coefficient of the term by the coefficient object b, which must be an instance of the same class as the coefficient of the term. The symbol and exponent of the resulting term are equal to that of the original term. The method is implemented only for terms of variable dense (recursive) polynomials.

### multiply:

> -multiply:b

Returns a new term that is the product of the two terms i.e., the exponents are added together and the coefficients are multiplied using multiply: or multiplyScalar:. If the exponents are both non-zero, then the symbols must be equal to each other. If one of the terms has exponent equal to zero, then the symbol of the resulting term is equal to that of the term with non-zero exponent.

### divideScalar:

> -divideScalar:b

Returns a new term; divides the coefficient of the term by the scalar object b, using divide: if the coefficient of the term is a scalar object, or divideScalar: otherwise. The symbol and exponent of the resulting term are equal to that of the original term. Returns nil if the scalar division is not exact.

### divideCoefficient:

> -divideCoefficient:b

Returns a new term; divides the coefficient of the term by the object b, which is an instance of the same class as the coefficient. The symbol and exponent of the resulting term are equal to that of the original term. Returns nil if the division is not exact. The method is implemented only for terms of a variable dense polynomial.

### divide:

> -divide:b

Returns a new term that is the exact quotient of the two terms i.e., the exponents are subtracted from each other and the coefficients are divided using divide: or divideScalar:. If the exponents are both non-zero, then the symbols must be equal to each other. If one of the terms has exponent equal to zero, then the symbol of the resulting term is equal to that of the term with non-zero exponent. Returns nil if the exponent of the divisor is greater than that of the dividend, or if the coefficient division fails.

### power:

> -power:(int)n

Raises coefficient to the n-th power and multiplies exponent by n.

### root:

> -root:(int)n

Takes the n-th root of the coefficient and divides exponent by n. Returns nil if the coefficient is not an n-th power or if the exponent is not divisible by n.

### squareRoot

> -squareRoot

Takes the square root of the coefficient and divides exponent by two. Returns nil if the coefficient is not a square or if the exponent is not divisible by two.

### frobenius

> -frobenius

Returns the p-th power of the term, obtained by raising the term to a power equal to the characteric of the coefficient.

### frobeniusInverse

> -frobeniusInverse

Returns either nil (if the term is not a p-th power) or a new term that is the p-th root of the term.

### derive

> -derive

Returns the derivative with respect to the variable.

### integrate

> -integrate

Integrates with respect to the variable.

### printsLeadingSign

> - (BOOL)printsLeadingSign

Whether the term prints a leading minus sign.

### printsSum

> - (BOOL)printsSum

Whether the term prints a sum.

### printsProduct

> - (BOOL)printsProduct

Whether the term prints a single product.

### printOn:

> -printOn:(IOD)aFile

Prints, between braces, a comma separated list of the members. If there are no members, the method prints two braces.