Skip to content

Commit

Permalink
chg: avoid adding of constant factors to squarefree factorization
Browse files Browse the repository at this point in the history
chg: divide out contents first in squarefree factorization
  • Loading branch information
mmklee committed Apr 4, 2012
1 parent 9ebec2d commit 6caa2a6
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 17 deletions.
14 changes: 7 additions & 7 deletions factory/facFqSquarefree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ sqrfPosDer (const CanonicalForm & F, const Variable & x,
while (j < p - 1 && degree(u) >= 0)
{
g= gcd (w, u);
if (degree(g) > 0)
if (!g.inCoeffDomain())
result.append (CFFactor (g, j));
w= w/g;
c= c/w;
v= u/g;
u= v - deriv (w, x);
j++;
}
if (degree(w) > 0)
if (!w.inCoeffDomain())
result.append (CFFactor (w, j));
return result;
}
Expand Down Expand Up @@ -131,7 +131,7 @@ squarefreeFactorization (const CanonicalForm & F, const Variable & alpha)
{
found= false;
CFFListIterator k= tmp2;
if (!k.hasItem()) tmp2.append (j.getItem());
if (!k.hasItem() && !j.getItem().factor().inCoeffDomain()) tmp2.append (j.getItem());
else
{
for (; k.hasItem(); k++)
Expand All @@ -143,7 +143,7 @@ squarefreeFactorization (const CanonicalForm & F, const Variable & alpha)
found= true;
}
}
if (found == false)
if (found == false && !j.getItem().factor().inCoeffDomain())
tmp2.append(j.getItem());
}
}
Expand Down Expand Up @@ -171,7 +171,7 @@ squarefreeFactorization (const CanonicalForm & F, const Variable & alpha)
tmp= gcd (i.getItem().factor(), j.getItem().factor());
i.getItem()= CFFactor (i.getItem().factor()/tmp, i.getItem().exp());
j.getItem()= CFFactor (j.getItem().factor()/tmp, j.getItem().exp());
if (degree (tmp) > 0 && tmp.level() > 0)
if (!tmp.inCoeffDomain())
{
tmp= M (tmp);
result.append (CFFactor (tmp/Lc(tmp),
Expand All @@ -181,15 +181,15 @@ squarefreeFactorization (const CanonicalForm & F, const Variable & alpha)
}
for (CFFListIterator i= tmp2; i.hasItem(); i++)
{
if (degree (i.getItem().factor()) > 0 && i.getItem().factor().level() >= 0)
if (!i.getItem().factor().inCoeffDomain())
{
tmp= M (i.getItem().factor());
result.append (CFFactor (tmp/Lc(tmp), i.getItem().exp()));
}
}
for (CFFListIterator j= tmp1; j.hasItem(); j++)
{
if (degree (j.getItem().factor()) > 0 && j.getItem().factor().level() >= 0)
if (!j.getItem().factor().inCoeffDomain())
{
tmp= M (j.getItem().factor());
result.append (CFFactor (tmp/Lc(tmp), j.getItem().exp()*p));
Expand Down
68 changes: 58 additions & 10 deletions factory/facFqSquarefree.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "cf_assert.h"
#include "cf_factory.h"

#include "fac_sqrfree.h"

/// squarefree factorization over a finite field
/// @a return a list of squarefree factors with multiplicity
Expand All @@ -36,11 +36,36 @@ squarefreeFactorization
///
/// @return a list of squarefree factors with multiplicity
inline
CFFList FpSqrf (const CanonicalForm& F ///< [in] a poly
CFFList FpSqrf (const CanonicalForm& F, ///< [in] a poly
bool sort= true ///< [in] sort factors by exponent?
)
{
Variable a= 1;
CFFList result= squarefreeFactorization (F, a);
int n= F.level();
CanonicalForm cont, bufF= F;
CFFList bufResult;

CFFList result;
for (int i= n; i >= 1; i++)
{
cont= content (bufF, i);
bufResult= squarefreeFactorization (cont, a);
if (bufResult.getFirst().factor().inCoeffDomain())
bufResult.removeFirst();
result= Union (result, bufResult);
bufF /= cont;
if (bufF.inCoeffDomain())
break;
}
if (!bufF.inCoeffDomain())
{
bufResult= squarefreeFactorization (bufF, a);
if (bufResult.getFirst().factor().inCoeffDomain())
bufResult.removeFirst();
result= Union (result, bufResult);
}
if (sort)
result= sortCFFList (result);
result.insert (CFFactor (Lc(F), 1));
return result;
}
Expand All @@ -51,10 +76,35 @@ CFFList FpSqrf (const CanonicalForm& F ///< [in] a poly
/// @return a list of squarefree factors with multiplicity
inline
CFFList FqSqrf (const CanonicalForm& F, ///< [in] a poly
const Variable& alpha ///< [in] algebraic variable
const Variable& alpha, ///< [in] algebraic variable
bool sort= true ///< [in] sort factors by exponent?
)
{
CFFList result= squarefreeFactorization (F, alpha);
int n= F.level();
CanonicalForm cont, bufF= F;
CFFList bufResult;

CFFList result;
for (int i= n; i >= 1; i++)
{
cont= content (bufF, i);
bufResult= squarefreeFactorization (cont, alpha);
if (bufResult.getFirst().factor().inCoeffDomain())
bufResult.removeFirst();
result= Union (result, bufResult);
bufF /= cont;
if (bufF.inCoeffDomain())
break;
}
if (!bufF.inCoeffDomain())
{
bufResult= squarefreeFactorization (bufF, alpha);
if (bufResult.getFirst().factor().inCoeffDomain())
bufResult.removeFirst();
result= Union (result, bufResult);
}
if (sort)
result= sortCFFList (result);
result.insert (CFFactor (Lc(F), 1));
return result;
}
Expand All @@ -64,15 +114,13 @@ CFFList FqSqrf (const CanonicalForm& F, ///< [in] a poly
///
/// @return a list of squarefree factors with multiplicity
inline
CFFList GFSqrf (const CanonicalForm& F ///< [in] a poly
CFFList GFSqrf (const CanonicalForm& F, ///< [in] a poly
bool sort= true ///< [in] sort factors by exponent?
)
{
ASSERT (CFFactory::gettype() == GaloisFieldDomain,
"GF as base field expected");
Variable a= 1;
CFFList result= squarefreeFactorization (F, a);
result.insert (CFFactor (Lc(F), 1));
return result;
return FpSqrf (F, sort);
}

/// squarefree part of @a F/g, where g is the product of those squarefree
Expand Down

0 comments on commit 6caa2a6

Please sign in to comment.