Polynomial Coeﬃcient Arithmetic
Date: 2020-10-07 18:10:00

Up | Next | Prev | PrevTail | Tail

### 9.12 Polynomial Coeﬃcient Arithmetic

REDUCE allows for a variety of numerical domains for the numerical coeﬃcients of polynomials used in calculations. The default mode is integer arithmetic, although the possibility of using real coeﬃcients has been discussed elsewhere. Rational coeﬃcients have also been available by using integer coeﬃcients in both the numerator and denominator of an expression, using the ON DIV option to print the coeﬃcients as rationals. However, REDUCE includes several other coeﬃcient options in its basic version which we shall describe in this section. All such coeﬃcient modes are supported in a table-driven manner so that it is straightforward to extend the range of possibilities. A description of how to do this is given in R.J. Bradford, A.C. Hearn, J.A. Padget and E. Schrüfer, “Enlarging the REDUCE Domain of Computation,” Proc. of SYMSAC ’86, ACM, New York (1986), 100–106.

#### 9.12.1 Rational Coeﬃcients in Polynomials

Instead of treating rational numbers as the numerator and denominator of a rational expression, it is also possible to use them as polynomial coeﬃcients directly. This is accomplished by turning on the switch RATIONAL.

Example: With RATIONAL oﬀ, the input expression a/2 would be converted into a rational expression, whose numerator was A and denominator 2. With RATIONAL on, the same input would become a rational expression with numerator 1/2*A and denominator 1. Thus the latter can be used in operations that require polynomial input whereas the former could not.

#### 9.12.2 Real Coeﬃcients in Polynomials

The switch ROUNDED permits the use of arbitrary sized real coeﬃcients in polynomial expressions. The actual precision of these coeﬃcients can be set by the operator PRECISION. For example, precision 50; sets the precision to ﬁfty decimal digits. The default precision is system dependent and can be found by precision 0;. In this mode, denominators are automatically made monic, and an appropriate adjustment is made to the numerator.

Example: With ROUNDED on, the input expression a/2 would be converted into a rational expression whose numerator is 0.5*A and denominator 1.

Internally, REDUCE uses ﬂoating point numbers up to the precision supported by the underlying machine hardware, and so-called bigﬂoats for higher precision or whenever necessary to represent numbers whose value cannot be represented in ﬂoating point. The internal precision is two decimal digits greater than the external precision to guard against roundoﬀ inaccuracies. Bigﬂoats represent the fraction and exponent parts of a ﬂoating-point number by means of (arbitrary precision) integers, which is a more precise representation in many cases than the machine ﬂoating point arithmetic, but not as eﬃcient. If a case arises where use of the machine arithmetic leads to problems, a user can force REDUCE to use the bigﬂoat representation at all precisions by turning on the switch ROUNDBF. In rare cases, this switch is turned on by the system, and the user informed by the message

ROUNDBF turned on to increase accuracy

Rounded numbers are normally printed to the speciﬁed precision. However, if the user wishes to print such numbers with less precision, the printing precision can be set by the command PRINT_PRECISION. For example, print_precision 5; will cause such numbers to be printed with ﬁve digits maximum.

Under normal circumstances when ROUNDED is on, REDUCE converts the number 1.0 to the integer 1. If this is not desired, the switch NOCONVERT can be turned on.

Numbers that are stored internally as bigﬂoats are normally printed with a space between every ﬁve digits to improve readability. If this feature is not required, it can be suppressed by turning oﬀ the switch BFSPACE.

Further information on the bigﬂoat arithmetic may be found in T. Sasaki, “Manual for Arbitrary Precision Real Arithmetic System in REDUCE”, Department of Computer Science, University of Utah, Technical Note No. TR-8 (1979).

When a real number is input, it is normally truncated to the precision in eﬀect at the time the number is read. If it is desired to keep the full precision of all numbers input, the switch ADJPREC (for adjust precision) can be turned on. While on, ADJPREC will automatically increase the precision, when necessary, to match that of any integer or real input, and a message printed to inform the user of the precision increase.

When ROUNDED is on, rational numbers are normally converted to rounded representation. However, if a user wishes to keep such numbers in a rational form until used in an operation that returns a real number, the switch ROUNDALL can be turned oﬀ. This switch is normally on.

Results from rounded calculations are returned in rounded form with two exceptions: if the result is recognized as 0 or 1 to the current precision, the integer result is returned.

#### 9.12.3 Modular Number Coeﬃcients in Polynomials

REDUCE includes facilities for manipulating polynomials whose coeﬃcients are computed modulo a given base. To use this option, two commands must be used; SETMOD ⟨integer⟩, to set the prime modulus, and ON MODULAR to cause the actual modular calculations to occur. For example, with setmod 3; and on modular;, the polynomial (a+2*b)^3 would become A^3+2*B^3.

The argument of SETMOD is evaluated algebraically, except that non-modular (integer) arithmetic is used. Thus the sequence

setmod 3; on modular; setmod 7;

will correctly set the modulus to 7.

Modular numbers are by default represented by integers in the interval [0,p-1] where p is the current modulus. Sometimes it is more convenient to use an equivalent symmetric representation in the interval [-p/2+1,p/2], or more precisely [-ﬂoor((p-1)/2), ceiling((p-1)/2)], especially if the modular numbers map objects that include negative quantities. The switch BALANCED_MOD allows you to select the symmetric representation for output.

Users should note that the modular calculations are on the polynomial coeﬃcients only. It is not currently possible to reduce the exponents since no check for a prime modulus is made (which would allow xp−1 to be reduced to 1 mod p). Note also that any division by a number not co-prime with the modulus will result in the error “Invalid modular division”.

#### 9.12.4 Complex Number Coeﬃcients in Polynomials

Although REDUCE routinely treats the square of the variable i as equivalent to −1, this is not suﬃcient to reduce expressions involving i to lowest terms, or to factor such expressions over the complex numbers. For example, in the default case,

factorize(a^2+1);

gives the result

{{A**2+1,1}}

and

(a^2+b^2)/(a+i*b)

is not reduced further. However, if the switch COMPLEX is turned on, full complex arithmetic is then carried out. In other words, the above factorization will give the result

{{A + I,1},{A - I,1}}

and the quotient will be reduced to A-I*B.

The switch COMPLEX may be combined with ROUNDED to give complex real numbers; the appropriate arithmetic is performed in this case.

Complex conjugation is used to remove complex numbers from denominators of expressions. To do this if COMPLEX is oﬀ, you must turn the switch RATIONALIZE on.

Up | Next | Prev | PrevTail | Front