9.22 Factored¶
Factored creates a domain whose objects are kept in factored form as long as possible. Thus certain operations like * (multiplication) and gcdgcdFactored 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 factorfactorFactored 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)
237211 |
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 factorListfactorListFactored.
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 factorsfactorsFactored.
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)
237211 |
Type: Factored Integer
To multiply out the factors with their multiplicities, use expandexpandFactored.
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)
237211 |
Type: Factored Integer
We’ll also define this factored integer.
f := factor(246960)
2432573 |
Type: Factored Integer
Operations involving multiplication and division are particularly easy with factored objects.
f * g
273257511 |
Type: Factored Integer
f^500
2200031000550071500 |
Type: Factored Integer
gcd(f,g)
2372 |
Type: Factored Integer
lcm(f,g)
243257311 |
Type: Factored Integer
If we use addition and subtraction things can slow down because we may need to compute greatest common divisors.
f + g
2372641 |
Type: Factored Integer
f - g
2372619 |
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 mapmapFactored operation is used to iterate across the unit and bases of a factored object. See FactoredFunctionsTwoXmpPage for a discussion of mapmapFactored.
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)
242 |
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)
302 |
Type: Factored Integer
This factor is asserted to be irreducible.
irreducibleFactor(13,10)
1310 |
Type: Factored Integer
This factor is asserted to be prime.
primeFactor(11,5)
115 |
Type: Factored Integer
A partial inverse to factorListfactorListFactored is makeFRmakeFRFactored.
h := factor(-720)
-24325 |
Type: Factored Integer
The first argument is the unit and the second is a list of records as returned by factorListfactorListFactored.
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
(4x2-12x+9)y2+(4x2-12x+9)y+28x2-84x+63 |
Type: Polynomial Integer
fp := factor(p)
(2x-3)2(y2+y+7) |
Type: Factored Polynomial Integer
You can differentiate with respect to a variable.
D(p,x)
(8x-12)y2+(8x-12)y+56x-84 |
Type: Polynomial Integer
D(fp,x)
4(2x-3)(y2+y+7) |
Type: Factored Polynomial Integer
numberOfFactors(%)
3 |
Type: PositiveInteger