]>
Book Contents Previous Section 9.21 Expression Next Section 9.23 FactoredFunctions2 Book Index

## 9.22 Factored

Factored creates a domain whose objects are kept in factored form as long as possible. Thus certain operations like * (multiplication) and gcd gcd Factored are relatively easy to do. Others, such as addition, require somewhat more work, and the result may not be completely factored unless the argument domain R provides a factor factor Factored operation. Each object consists of a unit and a list of factors, where each factor consists of a member of R (the base), an exponent, and a flag indicating what is known about the base. A flag may be one of ``nil'', ``sqfr'', ``irred'' or ``prime'', which mean that nothing is known about the base, it is square-free, it is irreducible, or it is prime, respectively. The current restriction to factored objects of integral domains allows simplification to be performed without worrying about multiplication order.

### 9.22.1 Decomposing Factored Objects

In this section we will work with a factored integer.

g := factor(4312)

2 3 7 2 11

Type: Factored Integer

Let's begin by decomposing g into pieces. The only possible units for integers are 1 and -1.

unit(g)

1

Type: PositiveInteger

There are three factors.

numberOfFactors(g)

3

Type: PositiveInteger

We can make a list of the bases, ...

[nthFactor(g,i) for i in 1..numberOfFactors(g)]

[2,7,11]

Type: List Integer

and the exponents, ...

[nthExponent(g,i) for i in 1..numberOfFactors(g)]

[3,2,1]

Type: List Integer

and the flags. You can see that all the bases (factors) are prime.

[nthFlag(g,i) for i in 1..numberOfFactors(g)]

["prime","prime","prime"]

Type: List Union("nil","sqfr","irred","prime")

A useful operation for pulling apart a factored object into a list of records of the components is factorList factorList Factored.

factorList(g)

[[flg="prime",fctr=2,xpnt=3],[flg="prime",fctr=7,xpnt=2],[flg="prime",fctr=11,xpnt=1]]

Type: List Record(flg: Union("nil","sqfr","irred","prime"), fctr: Integer,xpnt: Integer)

If you don't care about the flags, use factors factors Factored.

factors(g)

[[factor=2,exponent=3],[factor=7,exponent=2],[factor=11,exponent=1]]

Type: List Record(factor: Integer,exponent: Integer)

Neither of these operations returns the unit.

first(%).factor

2

Type: PositiveInteger

### 9.22.2 Expanding Factored Objects

Recall that we are working with this factored integer.

g := factor(4312)

2 3 7 2 11

Type: Factored Integer

To multiply out the factors with their multiplicities, use expand expand Factored.

expand(g)

4312

Type: PositiveInteger

If you would like, say, the distinct factors multiplied together but with multiplicity one, you could do it this way.

reduce(*,[t.factor for t in factors(g)])

154

Type: PositiveInteger

### 9.22.3 Arithmetic with Factored Objects

We're still working with this factored integer.

g := factor(4312)

2 3 7 2 11

Type: Factored Integer

We'll also define this factored integer.

f := factor(246960)

2 4 3 2 5 7 3

Type: Factored Integer

Operations involving multiplication and division are particularly easy with factored objects.

f * g

2 7 3 2 5 7 5 11

Type: Factored Integer
f**500

2 2000 3 1000 5 500 7 1500

Type: Factored Integer
gcd(f,g)

2 3 7 2

Type: Factored Integer
lcm(f,g)

2 4 3 2 5 7 3 11

Type: Factored Integer

If we use addition and subtraction things can slow down because we may need to compute greatest common divisors.

f + g

2 3 7 2 641

Type: Factored Integer
f - g

2 3 7 2 619

Type: Factored Integer

Test for equality with 0 and 1 by using zero?zero?Factored and one?one?Factored, respectively.

zero?(factor(0))

true

Type: Boolean
zero?(g)

false

Type: Boolean
one?(factor(1))

true

Type: Boolean
one?(f)

false

Type: Boolean

Another way to get the zero and one factored objects is to use package calling (see ugTypesPkgCallPage in Section ugTypesPkgCallNumber ).

0$Factored(Integer)

0

Type: Factored Integer
1$Factored(Integer)

1

Type: Factored Integer

### 9.22.4 Creating New Factored Objects

The map map Factored operation is used to iterate across the unit and bases of a factored object. See FactoredFunctionsTwoXmpPage for a discussion of map map Factored.

The following four operations take a base and an exponent and create a factored object. They differ in handling the flag component.

nilFactor(24,2)

24 2

Type: Factored Integer

This factor has no associated information.

nthFlag(%,1)

"nil"

Type: Union("nil",...)

This factor is asserted to be square-free.

sqfrFactor(30,2)

30 2

Type: Factored Integer

This factor is asserted to be irreducible.

irreducibleFactor(13,10)

13 10

Type: Factored Integer

This factor is asserted to be prime.

primeFactor(11,5)

11 5

Type: Factored Integer

A partial inverse to factorList factorList Factored is makeFR makeFR Factored.

h := factor(-720)

-2 4 3 2 5

Type: Factored Integer

The first argument is the unit and the second is a list of records as returned by factorList factorList Factored.

h - makeFR(unit(h),factorList(h))

0

Type: Factored Integer

### 9.22.5 Factored Objects with Variables

Some of the operations available for polynomials are also available for factored polynomials.

p := (4*x*x-12*x+9)*y*y + (4*x*x-12*x+9)*y + 28*x*x - 84*x + 63

(4 x 2-12 x+9)y 2+(4 x 2-12 x+9)y+28 x 2-84 x+63

Type: Polynomial Integer
fp := factor(p)

(2 x-3)2(y 2+y+7)

Type: Factored Polynomial Integer

You can differentiate with respect to a variable.

D(p,x)

(8 x-12)y 2+(8 x-12)y+56 x-84

Type: Polynomial Integer
D(fp,x)

4(2 x-3)(y 2+y+7)

Type: Factored Polynomial Integer
numberOfFactors(%)

3

Type: PositiveInteger
Book Contents Previous Section 9.21 Expression Next Section 9.23 FactoredFunctions2 Book Index