Factored
Objects kept in factored form
Syntax
Factored(list
, <type
>, <ring
>)
Factored(f
, <type
>, <ring
>)
Description
Factored
is the domain of objects kept in
factored form, such as prime factorization of integers, squarefree
factorization of polynomials, or the factorization of polynomials
in irreducible factors.
The argument list
must be a list of odd length
and of the form [u, f1, e1, f2, e2, ..., fr, er]
,
where the entries u and f_{i} are
elements of the domain ring
, or can be converted
into such elements. The e_{i} must
be integers. Here, i ranges
from 1 to r.
See section "Operands" below for the meaning of
the entries of that list.
An error message is reported, if one of the list entries is
of wrong type.
An arithmetical expression f
given as the
first argument is the same as giving the list [ring::one,
f, 1]
.
See section "Operands" below for the meaning of
the entries of that list.
f
must be an element of the domain ring
,
or must be convertible into such an element, otherwise an error message
would be given.
The argument type
indicates what is known
about the factorization. Currently, the following types are known:
"unknown"
– nothing is known
about the factorization.
"irreducible"
– the f_{i} are
irreducible over the domain ring
.
"squarefree"
– the f_{i} are
squarefree over the domain ring
.
If this argument is missing, then the type of the created factored
object is set to "unknown"
.
The type of factorization is known to any element of Factored
.
Use the methods "getType"
and "setType"
(see
below) to read and set the type of factorization of a given factored
object.
The argument ring
is the ring of factorization.
It must be an integral domain, i.e., a domain of category Cat::IntegralDomain
.
If this argument is missing, then the domain Dom::ExpressionField()
is
used.
The ring of factorization is known to any element of Factored
.
Use the methods "getRing"
and "setRing"
(see
below) to read and set the ring of factorization of a given factored
object.
You can use the index operator [ ]
to extract the factors
of an element f
of the domain Factored
.
E.g., for f = u f_{1}^{e1} f_{2}^{e2} …,
you have f [1] = u, f [2]
= f_{1}^{e1}, f [3]
= f_{2}^{e2} etc.
You can also use the methods "factors"
and "exponents"
(see
below) to access the operands, i.e., the call Factored::factors(f)
returns
a list of the factors f_{i},
and Factored::exponents(g)
returns a list of the
exponents e_{i} (1
≤ i ≤ r).
The system functions ifactor
, factor
and polylib::sqrfree
are
the main application of this domain, they return their result in form
of such factored objects (see their help pages for information about
the type and ring of factorization).
There may be no need to explicitly create factored objects,
but to work with the results of the mentioned system functions.
Note that an element of Factored
is printed
like an expression and behaves like that. As an example, the result
of f := factor(x^2 + 2*x + 1)
is an element of Factored
and
printed as (x + 1)^2
. The call type(f)
returns "_power"
as
the expression type of f
.
For an element f
of Factored
,
the call Factored::convert(f, DOM_LIST)
gives a
list of all operands of f
.
Examples
Example 1
The following computes the prime factorization of the integer 20:
The result is an element of the domain Factored
:
which consists of the following five operands:
They represent the integer 20 in
the following form: 20 = 1 2^{2} 5.
The factors are prime numbers and can be extracted via Factor::factors
:
ifactor
kept
the information that the factorization ring is the ring of integers
(represented by the domain Dom::Integer
),
and that the factors of f
are prime (and therefore
irreducible, because ℤ is
an integral domain):
We can convert such an object into different forms, such as
into a list of its operands:
or into an unevaluated expression, keeping the factored form:
or back into an integer:
You may also use the system function coerce
here, which has the same effect.
Example 2
We compute the factorization of the integers 108 and 512:
The multiplication of these two integers gives the prime factorization
of 55296 = 108 512:
Note that the most operations on such objects lead to an unfactored
form, such as adding these two integers:
You may apply the function ifactor
to the result, if you are interested
in its prime factorization:
You an apply (almost) each function to factored objects, functions
that mainly expect arithmetical expressions as their input. Note that,
before the operation is applied, the factored object is converted
into an arithmetical expression in unfactored form:
Example 3
The second system function which deals with elements of Factored
,
is factor
, which
computes all irreducible factors of a polynomial.
For example, if we define the following polynomial of ℤ_{101}:
and compute its factorization into irreducible factors, we get:
If we multiply the factored object with an element that can
be converted into an element of the ring of factorization, then we
get a new factored object, which then is of the factorization type "unknown"
:
You may use the function expand
which returns the factored object
in expanded form as an element of the factorization ring:
Example 4
The third system function which return elements of Factored
is polylib::sqrfree
, which
computes the squarefree factorization of polynomials. For example:
The factorization type, of course, is "squarefree"
:
Parameters
list

A list of odd length

f

An arithmetical expression

type

A string (default: "unknown" )

ring

A domain of category Cat::IntegralDomain (default: Dom::ExpressionField() )

Function Calls
Calling a factored object as a function yields the object itself,
regardless of the arguments. The arguments are not evaluated.
Operations
You can apply (almost) every function to factored objects, functions
that mainly expect arithmetical expressions as their input.
For example, one may add or multiply those objects, or apply
functions such as expand
and diff
to them. But the
result of such an operation then is usually not any longer of the
domain Factored
, as the factored form could be
lost due to the operation (see examples below).
Call expr(f)
to convert the factored object f
into
an arithmetical expression (as an element of a kernel domain).
The call coerce(f, DOM_LIST)
returns a list
of operands of the factored object f
(see method "convert_to"
below).
Operands
An element f of Factored
consists
of the r + 1 operands u, f_{1}, e_{1}, f_{2}, e_{2},
…, f_{r}, e_{r},
such that f = u f_{1}^{e1} f_{2}^{e2} … f_{r}^{er}.
The first operand u and
the factors f_{i} are
elements of the domain ring
. The exponents e_{i} are integers.
Methods
expand all
Mathematical Methods
_mult
— Multiply factored objects
_mult(f
, g, …
)
Suppose that g
is an element of the domain ring
(or
can be converted into such an element).
If g
is a unit of ring
or
a factor of f
, then the result is a factored object
of the same factorization type as f
. Otherwise,
the result is an element of Factored
with the factorization
type "unknown"
.
If both f
and g
are factored
objects with factorization type "irreducible"
,
then the result is again a factored object of this type, i.e., the
result is still in factored form.
Otherwise, the factored form of f
is lost,
and the result of this method is an element of ring
.
This method overloads the function _mult
for factored objects,
i.e., one may use it in the form f*g*...
, or in
functional notation: _mult(f, g, ...)
.
_power
— Raise a factored object to a certain power
_power(f
, n
)
If n
is a positive integer and f
a
factored object with factorization type "irreducible"
or "squarefree"
,
then the result is still a factored object of this type.
Otherwise, the factored form of f
is lost,
and the result of this method is an element of ring
.
This method overloads the function _power
for factored objects, i.e., one
may use it in the form f^n
, or in functional notation: _power(f,
n)
.
expand
— Expand a factored object
exponents
— Get the exponents of a factored object
factor
— Factor a factored object
factor(f
)
If f
already is of the factorization type "irreducible"
,
then this method just return f
.
Otherwise, this method converts f
into an
element of the domain ring
and calls the method "factor"
of ring
.
This method returns a factored object of the domain Factored
with
factorization type "irreducible"
, if the factorization
of f
can be computed (otherwise, FAIL
is
returned).
This method overloads the function factor
for factored objects, i.e., one
may use it in the form factor(f)
.
factors
— Get the factors of a factored object
irreducible
— Test if a factored object is irreducible
irreducible(f
)
The test on irreducible is trivial, if f
has
the factorization type "irreducible"
.
Otherwise, this method converts f
into an
element of ring
and calls the method "irreducible"
of ring
.
The value FAIL
is returned, if the domain ring
cannot
test if f
is irreducible.
iszero
— Test on zero for factored objects
iszero(f
)
This method overloads the function iszero
for factored objects, i.e., one
may use it in the form iszero(f)
.
sqrfree
— Compute a squarefree factorization of a factored object
sqrfree(f
)
If f
already is of the factorization type "squarefree"
,
then this method just return f
.
Otherwise, this method converts f
into an
element of the domain ring
and calls the method "squarefree"
of ring
.
This method returns a factored object of the domain Factored
with
factorization type "squarefree"
, if the squarefree
factorization of f
can be computed (otherwise, FAIL
is
returned).
This method overloads the function polylib::sqrfree
for factored objects,
i.e., one may use it in the form polylib::sqrfree(f)
.
Access Methods
_index
— Extract a term of a factored object
_index(f
, i
)
Responds with an error message, if i
is greater
than the number of terms of f
.
This method overloads the index operator [ ]
for factored objects,
i.e., one may use it in the form f[i]
.
getRing
— Get the ring of factorization
getType
— Get the type of factorization
has
— Existence of an object in a factored object
has(f
, x, …
)
This method overloads the function has
for factored objects, i.e., one may
use it in the form has(f, x, ...)
.
map
— Map a function to the operands of factored objects
map(f
, func, …
)
See the system function map
for details.
This method overloads the function map
for factored objects, i.e., one may
use it in the form map(f, func, ...)
.
nops
— Number of operands of a factored object
nops(f
)
This method overloads the function nops
for factored objects, i.e., one
may use it in the form nops(f)
.
op
— Extract an operand of a factored object
op(f
, i
)
Returns FAIL
, if i
is
greater than the number of operands of f
.
This method overloads the function op
for factored objects, i.e., one may
use it in the form op(f, i)
.
select
— Select operands of a factored object
select(f
, func, …
)
This method overloads the function select
for factored objects, i.e., one
may use it in the form select(f, func, ...)
.
set_index
— Set/change a term of a factored object
set_index(f
, i
, x
)
Responds with an error message, if i
is greater
than the number of terms of f
.
Note:
Make sure that x either is an element of
the domain ring , or an integer. 
This method overloads the index operator [ ]
for factored objects,
i.e., one may use it in the form f[i] := x
.
setRing
— Set the ring of factorization
setRing(f
, ring
)
Note:
Use this method with caution! Make sure that the factorization
of f is still valid over the new ring, and that
the operands of f have the correct domain type. ring must be a domain of category Cat::IntegralDomain , which
is not checked by this method.

setType
— Set the type of factorization
setType(f
, type
)
Note:
Use this method with caution! Make sure that the factorization
type corresponds with the factorization of f . 
subs
— Substitute subexpressions in the operands of a factored object
subs(f
, x = a, …
)
This method overloads the function subs
for factored objects, i.e., one
may use it in the form subs(f, x = a, ...)
.
subsop
— Substitute operands of a factored object
subsop(f
, i = a, …
)
This method overloads the function subsop
for factored objects, i.e., one
may use it in the form subsop(f, i = a, ...)
.
type
— Expression type of factored objects
Conversion Methods
convert
— Convert an object into a factored object
convert(x
)
If the conversion fails, then FAIL
is returned.
x
may either be a list of the form [u,
f1, e1, ..., fr, er]
of odd length (where u, f1,
..., fr
are of the domain type ring
,
or can be converted into such elements, and e1, ..., er
are
integers), or an element that can be converted into the domain ring
.
The latter case corresponds to the list [ring::one,x,1]
.
convert_to
— Convert factored objects into other domains
convert_to(f
, T
)
If the conversion fails, then FAIL
is returned.
If T
is the domain DOM_LIST
, then the list
of operands of f
is returned.
If T
is the domain DOM_EXPR
, then the unevaluated
expression u*f1^e1*f2^e2*...*fr^er
is returned,
where u, f1, e1, ...
are the operands of f
.
Otherwise, the method "convert"
of the domain T
is
called to convert f
into an element of the domain T
(which
could return FAIL
).
Use the function expr
to
convert f
into an object of a kernel domain (see
below).
create
— Create simple and fast a factored objects
create(list
)
create(x
)
This method creates a new factored object with the operands ring::one,
x, 1
.
expr
— Convert a factored object into a kernel domain
expr(f
)
Note:
Note that the factored form of f may be lost
due to this conversion. 
expr2text
— Convert a factored object into a string
testtype
— Type testing for factored objects
testtype(f
, T
)
This method is called from the system function testtype
.
TeX
— LaTeX formatting of a factored object
TeX(f
)
The method "TeX"
of the domain ring
is
used to get the LaTeXrepresentation of the corresponding operands
of f
.
This method is called from the system function generate::TeX
.
Technical Methods
_concat
— Concatenate operands of factored objects
_concat(f
, g
)
f
and g
must have the
same factorization type and factorization ring, otherwise an error
message is given.
maprec
— Allow recursive mapping for factored objects
maprec(f
, x, …
)
First f
is converted into the unevaluated
expression u*f1^e1*f2^e2*...*fr^er
, where u,
f1, e1, ...
are the operands of f
. Then
the function misc::maprec
is called with this expression
as its first parameter.
Note that the result of this method is not longer an object
of Factored
!
print
— Prettyprint routine for factored objects
unapply
— Create a procedure from a factored object
unapply(f
, <x
>)
This method overloads the function fp::unapply
for
factored objects, i.e., one may use it in the form fp::unapply(f)
.
See fp::unapply
for
details.