% The plain TeX file SqrFree.tex
\magnification=\magstep1
\font\sf=cmss10
 
\baselineskip=14pt
 
\centerline {\bf The {\sf SqrFree} Routine}
 
\centerline {\bf Steven L. Swanson}
 
\centerline {Department of Mathematics, Purdue University, West Lafayette, IN 47907} 
 
\vskip 3\jot
 
This note describes my Maple {\sf SqrFree} routine,
an extension of the standard Maple routine {\sf Sqrfree}
for finite fields.
The {\sf Sqrfree} routine computes the square-free
decomposition of univariate polynomials over finite
fields.
The {\sf SqrFree} routine does the same for
multivariate polynomials.
 
\beginsection Goal
 
Suppose $f(X_1,\ldots,X_n)$ is a multivariate polynomial
over a finite field.
I want to separate factors of $f$ according
to their multiplicity.
In particular, I want to find $u, f_1,\ldots,f_s$ so that
$$ f = u \cdot \prod_{i=1}^s f_i^i $$
where $u$ is a constant, each $f_i$ has no
multiple factors,
and $\gcd(f_i,f_j) = 1$ for $i \ne j$.
 
The routine currently computes the decomposition with
respect to all the variables in $f$.
I could modify the routine so that one could
compute the square-free decomposition with respect to, say,
$X,Y,Z$ and treat other variables as constants ---
however, I've never seen a use for this.
 
\beginsection Data Structure
 
I use the standard Maple data structure for this
decomposition which is a list containing the
relevant information
$$ [u,[[f_1,1],[f_2,2],\ldots,[f_s,s]]] ,$$
and if $f_i = 1$ then that part is omited.
In particular, the decomposition of a constant $u$
is $[u,[]]$.
 
\beginsection Algorithm
 
If the polynomial $f$ is univariate, I simply use the Maple
library function {\sf Sqrfree}.
This uses the standard technique, described by Davenport.
 
For a true multivariate polynomial,
I first make sure it is primitive,
i.e. doesn't have any factors which include only
a proper subset of the variables.
If the polynomial is not primitive,
I can write (using {\sf Content}), $f = c \cdot p$,
where $c$ has fewer variables than $f$.
Combining {\sf SqrFree($c$)} and {\sf SqrFree($p$)},
I get what I want.
Note that since the factors of $c$ and $p$ are
relatively prime,
this combining is easy:
if $c = u_c \cdot \prod_{i=1}^{s_c} c_i^i$
and $p = u_p \cdot \prod_{j=1}^{s_p} p_j^j$
are square-free decompositions then
$f = (u_c \cdot u_p) \cdot \prod_{k=1}^{\max(s_c,s_p)}
(c_k \cdot p_k)^k$
is a square-free decomposition (here $c_i = 1$ or
$p_j = 1$ if not otherwise defined).
 
The core of my algorithm is based on a partial
decomposition algorithm I learned from Martinelli.
The idea here is to do as much as possible
with each variable without working too hard.
Suppose, relabeling variables,
that $f(X) \in R[X]$ where $R$ is a commutative
UFD of characteristic $p$ and
$$ f = \prod g_i^{c_i p + e_i} \cdot \prod h_j^{d_j}
\eqno(*) $$
is a decomposition of $f$ into irreducible factors
where ${\partial g_i \over \partial X} \ne 0$ for each $i$
and ${\partial h_j \over \partial X} = 0$ for each j,
and $e_i < p$ for each $i$.
The following algorithm computes the square-free
decomposition of
$g = \prod g_i^{e_i}$
and also returns $f/g$.
 
\vskip 3\jot
\sf
\settabs\+MMMM&MMMM&MMMM&MMMM&MMMM&MMMM\cr
\+Algorithm P-SqrFree \cr
\+&$m = \gcd(f, {\partial f \over \partial X})$ \cr
\+&$r = f/m$ \cr
\+&$list = [1,[]]$, $m^* = m$, $r^* = r$ \cr
\+&For $i = 1, 2,\ldots\ $ While $\deg(r,X) > 0$ \cr
\+&&$m^* = m$, $r^* = r$ \cr
\+&&$m = \gcd(m^*,{\partial m^* \over \partial X})$,
$r = m^*/m$ \cr
\+&&If $r \ne r^*$ Then \cr
\+&&&Append$(list,[r^*/r,i])$ \cr
\+&Return$([list,m^*])$ \cr
\+End \cr
 
\rm
\vskip 2\jot
\noindent
For example, with $f = (x^3+2y)^4$ over $Z/3$
I get
$$\eqalign{
\hbox{\sf P-SqrFree}(f,y) \longrightarrow&\ %
[[1,[[x^{3}+2y,1]]],\ x^{9}+2y^{3}] \cr
\hbox{\sf P-SqrFree}(f,x) \longrightarrow&\ %
[[1,[]],\ x^{12}+2x^{9}y+2x^{3}y^{3}+y^{4}]}$$
 
The rest of the algorithm follows easily from
this tool.
Apply {\sf P-SqrFree} to $f$ with one of the
variables.
Then apply {\sf P-SqrFree} to the remainder
polynomial from the last step with one of the
other variables.
Go through all the variables if necessary.
If something is left as a remainder, considering $(*)$,
its factors are either $p^{\hbox{th}}$ powers or
have derivative zero with respect to all the variables.
But if a polynomial has derivative zero with respect
to all its variables, then each exponent of each
variable must be a multiple of $p$, hence over
a finite field that polynomial is a $p^{\hbox{th}}$
power.
Take a $p^{\hbox{th}}$ root, apply {\sf SqrFree}
to that root and then adjust the exponents.
 
Having done the above, I am left with a bunch
of square-free decompositions whose product is $f$.
Combining these, I get the square-free decomposition.
Note that the entries in the different decompositions
are not necessarily relatively prime, hence I have
to check if they are so, and if not, modify the
decompositions and the multiplicities.
 
\vskip 3\jot
\sf
\settabs\+MMMM&MMMM&MMMM&MMMM&MMMM&MMMM\cr
\+Algorithm SqrFree \cr
\+&Make $f$ primitive \cr
\+&Let $X$ be a variable in $f$ \cr
\+&$[list_X,g] = \hbox{\sf P-SqrFree}(f,X)$ \cr
\+&For each other variable $V$ \cr
\+&&$[list_V,g] = \hbox{\sf P-SqrFree}(g,V)$ \cr
\+&If $g \ne 1$ Then \cr
\+&&$\hbox{\sf SqrFree}(g^{1 \over p})$ \cr
\+&&Multiply exponents by $p$ \cr
\+&Combine all the lists \cr
\+End \cr
 
\rm
\beginsection Examples
 
% emulate the \beginverbatim macro to include listing.
{\frenchspacing
\def\par{\leavevmode\endgraf} \catcode`\`=\active
\obeylines \obeyspaces \tt {\obeyspaces\global\let =\ }
MAPLE> SqrFree(a) mod 11;
                                                        2
         [1, [[z + y + x, 1], [x + 2 z + 10 y, 2], [10 z  + x, 3]]]
 
MAPLE> SqrFree(b) mod 3;
                                                   2
             [1, [[2 y + x, 1], [x + 2 y + RootOf(Z  + 1), 2]]]
 
MAPLE> SqrFree(c) mod 2;
                                        2            2
                 [1, [[x + y, 2], [x + y , 3], [y + x , 4]]]
 
MAPLE> SqrFree(d) mod 2;
                                    2    2
                        [1, [[(x + y ) (x  + y), 1]]]
 
 
}
 
Notice in the last example that the result is factored
more than is required by the definition.
 
\vskip 15\jot
 
\centerline{\bf References}
 
\vskip 2\jot
 
\item{} J.~H.~Davenport, {\sl On the Integration of
Algebraic Functions}, Springer-Verlag, 1979.
 
\item{} J.~H.~Davenport, Y.~Siret and E.~Tournier,
{\sl Computer Algebra --- Systems and Algorithms for
Algebraic Computation}, Academic Press, 1988.
 
\item{} S.~Martelli, {\sl Factoring Polynomials over
Algebraic Function Fields}, manuscript, 1993.
 
\bye
