REDUCE

9.2 Factorization of Polynomials

REDUCE is capable of factorizing univariate and multivariate polynomials that have integer coefficients, finding all factors that also have integer coefficients. The package for doing this was written by Dr. Arthur C. Norman and Ms. P. Mary Ann Moore at The University of Cambridge. It is described in P. M. A. Moore and A. C. Norman, “Implementing a Polynomial Factorization and GCD Package”, Proc. SYMSAC ’81, ACM (New York) (1981), 109-116.

The easiest way to use this facility is to turn on the switch FACTOR, which causes all expressions to be output in a factored form. For example, with FACTOR on, the expression A^2-B^2 is returned as (A+B)*(A-B).

It is also possible to factorize a given expression explicitly. The operator FACTORIZE that invokes this facility is used with the syntax

     FACTORIZE(EXPRN:polynomial[,INTEXP:prime integer]):list,

the optional argument of which will be described later. Thus to find and display all factors of the cyclotomic polynomial x105 - 1, one could write:

        factorize(x^105-1);

The result is a list of factor,exponent pairs. In the above example, there is no overall numerical factor in the result, so the results will consist only of polynomials in x. The number of such polynomials can be found by using the operator LENGTH. If there is a numerical factor, as in factorizing 12x2 - 12, that factor will appear as the first member of the result. It will however not be factored further. Prime factors of such numbers can be found, using a probabilistic algorithm, by turning on the switch IFACTOR. For example,

        on ifactor; factorize(12x^2-12);

would result in the output

        {{2,2},{3,1},{X + 1,1},{X - 1,1}}.

If the first argument of FACTORIZE is an integer, it will be decomposed into its prime components, whether or not IFACTOR is on.

Note that the IFACTOR switch only affects the result of FACTORIZE. It has no effect if the FACTOR switch is also on.

The order in which the factors occur in the result (with the exception of a possible overall numerical coefficient which comes first) can be system dependent and should not be relied on. Similarly it should be noted that any pair of individual factors can be negated without altering their product, and that REDUCE may sometimes do that.

The factorizer works by first reducing multivariate problems to univariate ones and then solving the univariate ones modulo small primes. It normally selects both evaluation points and primes using a random number generator that should lead to different detailed behavior each time any particular problem is tackled. If, for some reason, it is known that a certain (probably univariate) factorization can be performed effectively with a known prime, P say, this value of P can be handed to FACTORIZE as a second argument. An error will occur if a non-prime is provided to FACTORIZE in this manner. It is also an error to specify a prime that divides the discriminant of the polynomial being factored, but users should note that this condition is not checked by the program, so this capability should be used with care.

Factorization can be performed over a number of polynomial coefficient domains in addition to integers. The particular description of the relevant domain should be consulted to see if factorization is supported. For example, the following statements will factorize x4 + 1 modulo 7:

        setmod 7;  
        on modular;  
        factorize(x^4+1);

The factorization module is provided with a trace facility that may be useful as a way of monitoring progress on large problems, and of satisfying curiosity about the internal workings of the package. The most simple use of this is enabled by issuing the REDUCE command on trfac; . Following this, all calls to the factorizer will generate informative messages reporting on such things as the reduction of multivariate to univariate cases, the choice of a prime and the reconstruction of full factors from their images. Further levels of detail in the trace are intended mainly for system tuners and for the investigation of suspected bugs. For example, TRALLFAC gives tracing information at all levels of detail. The switch that can be set by on timings; makes it possible for one who is familiar with the algorithms used to determine what part of the factorization code is consuming the most resources. on overview; reduces the amount of detail presented in other forms of trace. Other forms of trace output are enabled by directives of the form

        symbolic set!-trace!-factor(<number>,<filename>);

where useful numbers are 1, 2, 3 and 100, 101, ... . This facility is intended to make it possible to discover in fairly great detail what just some small part of the code has been doing — the numbers refer mainly to depths of recursion when the factorizer calls itself, and to the split between its work forming and factorizing images and reconstructing full factors from these. If NIL is used in place of a filename the trace output requested is directed to the standard output stream. After use of this trace facility the generated trace files should be closed by calling

        symbolic close!-trace!-files();

NOTE: Using the factorizer with MCD off will result in an error.