Skip to content

Commit

Permalink
chg: substitution in the top level routines
Browse files Browse the repository at this point in the history
  • Loading branch information
mmklee authored and Oleksandr Motsak committed Feb 10, 2012
1 parent 3af6b6d commit f9b796e
Show file tree
Hide file tree
Showing 4 changed files with 411 additions and 41 deletions.
57 changes: 51 additions & 6 deletions factory/facBivar.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ biFactorize (const CanonicalForm& F, ///< [in] a bivariate poly
/// element is the leading coefficient.
#ifdef HAVE_NTL
inline
CFList ratBiSqrfFactorize (const CanonicalForm & G, ///< [in] a bivariate poly
const Variable& v
)
CFList
ratBiSqrfFactorize (const CanonicalForm & G, ///< [in] a bivariate poly
const Variable& v ///< [in] algebraic variable
)
{
CFMap N;
CanonicalForm F= compress (G, N);
Expand Down Expand Up @@ -93,12 +94,56 @@ CFList ratBiSqrfFactorize (const CanonicalForm & G, ///< [in] a bivariate poly
/// @return @a ratBiFactorize returns a list of monic factors with
/// multiplicity, the first element is the leading coefficient.
inline
CFFList ratBiFactorize (const CanonicalForm & G, ///< [in] a bivariate poly
const Variable& v
)
CFFList
ratBiFactorize (const CanonicalForm & G, ///< [in] a bivariate poly
const Variable& v, ///< [in] algebraic variable
bool substCheck= true ///< [in] enables substitute check
)
{
CFMap N;
CanonicalForm F= compress (G, N);

if (substCheck)
{
bool foundOne= false;
int * substDegree= new int [F.level()];
for (int i= 1; i <= F.level(); i++)
{
substDegree[i-1]= substituteCheck (F, Variable (i));
if (substDegree [i-1] > 1)
{
foundOne= true;
subst (F, F, substDegree[i-1], Variable (i));
}
}
if (foundOne)
{
CFFList result= ratBiFactorize (F, v, false);
CFFList newResult, tmp;
CanonicalForm tmp2;
newResult.insert (result.getFirst());
result.removeFirst();
for (CFFListIterator i= result; i.hasItem(); i++)
{
tmp2= i.getItem().factor();
for (int j= 1; j <= F.level(); j++)
{
if (substDegree[j-1] > 1)
tmp2= reverseSubst (tmp2, substDegree[j-1], Variable (j));
}
tmp= ratBiFactorize (tmp2, v, false);
tmp.removeFirst();
for (CFFListIterator j= tmp; j.hasItem(); j++)
newResult.append (CFFactor (j.getItem().factor(),
j.getItem().exp()*i.getItem().exp()));
}
decompress (newResult, N);
delete [] substDegree;
return newResult;
}
delete [] substDegree;
}

CanonicalForm LcF= Lc (F);
CanonicalForm contentX= content (F, 1);
CanonicalForm contentY= content (F, 2);
Expand Down
61 changes: 55 additions & 6 deletions factory/facFactorize.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ multiFactorize (const CanonicalForm& F, ///< [in] poly to be factored
/// element is the leading coefficient.
#ifdef HAVE_NTL
inline
CFList ratSqrfFactorize (const CanonicalForm & G, ///< [in] a multivariate poly
const Variable& v
)
CFList
ratSqrfFactorize (const CanonicalForm & G, ///<[in] a multivariate poly
const Variable& v ///<[in] algebraic variable
)
{
if (getNumVars (G) == 2)
return ratBiSqrfFactorize (G, v);
Expand All @@ -57,16 +58,64 @@ CFList ratSqrfFactorize (const CanonicalForm & G, ///< [in] a multivariate poly
/// @return @a ratFactorize returns a list of monic factors with
/// multiplicity, the first element is the leading coefficient.
inline
CFFList ratFactorize (const CanonicalForm& G, ///< [in] a multivariate poly
const Variable& v
)
CFFList
ratFactorize (const CanonicalForm& G, ///<[in] a multivariate poly
const Variable& v, ///<[in] algebraic variable
bool substCheck= true ///<[in] enables substitute check
)
{
if (getNumVars (G) == 2)
{
CFFList result= ratBiFactorize (G,v);
return result;
}
CanonicalForm F= G;

if (substCheck)
{
bool foundOne= false;
int * substDegree= new int [F.level()];
for (int i= 1; i <= F.level(); i++)
{
if (degree (F, i) > 0)
{
substDegree[i-1]= substituteCheck (F, Variable (i));
if (substDegree [i-1] > 1)
{
foundOne= true;
subst (F, F, substDegree[i-1], Variable (i));
}
}
else
substDegree[i-1]= -1;
}
if (foundOne)
{
CFFList result= ratFactorize (F, v, false);
CFFList newResult, tmp;
CanonicalForm tmp2;
newResult.insert (result.getFirst());
result.removeFirst();
for (CFFListIterator i= result; i.hasItem(); i++)
{
tmp2= i.getItem().factor();
for (int j= 1; j <= G.level(); j++)
{
if (substDegree[j-1] > 1)
tmp2= reverseSubst (tmp2, substDegree[j-1], Variable (j));
}
tmp= ratFactorize (tmp2, v, false);
tmp.removeFirst();
for (CFFListIterator j= tmp; j.hasItem(); j++)
newResult.append (CFFactor (j.getItem().factor(),
j.getItem().exp()*i.getItem().exp()));
}
delete [] substDegree;
return newResult;
}
delete [] substDegree;
}

CanonicalForm LcF= Lc (F);
if (isOn (SW_RATIONAL))
F *= bCommonDen (F);
Expand Down
158 changes: 145 additions & 13 deletions factory/facFqBivar.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,56 @@ CFList GFBiSqrfFactorize (const CanonicalForm & G ///< [in] a bivariate poly
/// multiplicity, the first element is the leading coefficient.
/// @sa FqBiFactorize(), GFBiFactorize()
inline
CFFList FpBiFactorize (const CanonicalForm & G ///< [in] a bivariate poly
)
CFFList
FpBiFactorize (const CanonicalForm & G, ///< [in] a bivariate poly
bool substCheck= true ///< [in] enables substitute check
)
{
ExtensionInfo info= ExtensionInfo (false);
CFMap N;
CanonicalForm F= compress (G, N);

if (substCheck)
{
bool foundOne= false;
int * substDegree= new int [F.level()];
for (int i= 1; i <= F.level(); i++)
{
substDegree[i-1]= substituteCheck (F, Variable (i));
if (substDegree [i-1] > 1)
{
foundOne= true;
subst (F, F, substDegree[i-1], Variable (i));
}
}
if (foundOne)
{
CFFList result= FpBiFactorize (F, false);
CFFList newResult, tmp;
CanonicalForm tmp2;
newResult.insert (result.getFirst());
result.removeFirst();
for (CFFListIterator i= result; i.hasItem(); i++)
{
tmp2= i.getItem().factor();
for (int j= 1; j <= F.level(); j++)
{
if (substDegree[j-1] > 1)
tmp2= reverseSubst (tmp2, substDegree[j-1], Variable (j));
}
tmp= FpBiFactorize (tmp2, false);
tmp.removeFirst();
for (CFFListIterator j= tmp; j.hasItem(); j++)
newResult.append (CFFactor (j.getItem().factor(),
j.getItem().exp()*i.getItem().exp()));
}
decompress (newResult, N);
delete [] substDegree;
return newResult;
}
delete [] substDegree;
}

CanonicalForm LcF= Lc (F);
CanonicalForm contentX= content (F, 1);
CanonicalForm contentY= content (F, 2);
Expand Down Expand Up @@ -237,7 +281,7 @@ CFFList FpBiFactorize (const CanonicalForm & G ///< [in] a bivariate poly
if (degree (pthRoot) > 0)
{
pthRoot= maxpthRoot (pthRoot, p, l);
result= FpBiFactorize (pthRoot);
result= FpBiFactorize (pthRoot, false);
result.removeFirst();
for (CFFListIterator i= result; i.hasItem(); i++)
i.getItem()= CFFactor (N (decompress (i.getItem().factor(), M, S)),
Expand All @@ -259,7 +303,7 @@ CFFList FpBiFactorize (const CanonicalForm & G ///< [in] a bivariate poly
}
if (degree (A) > 0)
{
resultRoot= FpBiFactorize (A);
resultRoot= FpBiFactorize (A, false);
resultRoot.removeFirst();
for (CFFListIterator i= resultRoot; i.hasItem(); i++)
i.getItem()= CFFactor (N (decompress (i.getItem().factor(), M, S)),
Expand All @@ -279,13 +323,57 @@ CFFList FpBiFactorize (const CanonicalForm & G ///< [in] a bivariate poly
/// multiplicity, the first element is the leading coefficient.
/// @sa FpBiFactorize(), FqBiFactorize()
inline
CFFList FqBiFactorize (const CanonicalForm & G, ///< [in] a bivariate poly
const Variable & alpha ///< [in] algebraic variable
)
CFFList
FqBiFactorize (const CanonicalForm & G, ///< [in] a bivariate poly
const Variable & alpha, ///< [in] algebraic variable
bool substCheck= true ///< [in] enables substitute check
)
{
ExtensionInfo info= ExtensionInfo (alpha, false);
CFMap N;
CanonicalForm F= compress (G, N);

if (substCheck)
{
bool foundOne= false;
int * substDegree= new int [F.level()];
for (int i= 1; i <= F.level(); i++)
{
substDegree[i-1]= substituteCheck (F, Variable (i));
if (substDegree [i-1] > 1)
{
foundOne= true;
subst (F, F, substDegree[i-1], Variable (i));
}
}
if (foundOne)
{
CFFList result= FqBiFactorize (F, alpha, false);
CFFList newResult, tmp;
CanonicalForm tmp2;
newResult.insert (result.getFirst());
result.removeFirst();
for (CFFListIterator i= result; i.hasItem(); i++)
{
tmp2= i.getItem().factor();
for (int j= 1; j <= F.level(); j++)
{
if (substDegree[j-1] > 1)
tmp2= reverseSubst (tmp2, substDegree[j-1], Variable (j));
}
tmp= FqBiFactorize (tmp2, alpha, false);
tmp.removeFirst();
for (CFFListIterator j= tmp; j.hasItem(); j++)
newResult.append (CFFactor (j.getItem().factor(),
j.getItem().exp()*i.getItem().exp()));
}
decompress (newResult, N);
delete [] substDegree;
return newResult;
}
delete [] substDegree;
}

CanonicalForm LcF= Lc (F);
CanonicalForm contentX= content (F, 1);
CanonicalForm contentY= content (F, 2);
Expand Down Expand Up @@ -320,7 +408,7 @@ CFFList FqBiFactorize (const CanonicalForm & G, ///< [in] a bivariate poly
if (degree (pthRoot) > 0)
{
pthRoot= maxpthRoot (pthRoot, q, l);
result= FqBiFactorize (pthRoot, alpha);
result= FqBiFactorize (pthRoot, alpha, false);
result.removeFirst();
for (CFFListIterator i= result; i.hasItem(); i++)
i.getItem()= CFFactor (N (decompress (i.getItem().factor(), M, S)),
Expand All @@ -342,7 +430,7 @@ CFFList FqBiFactorize (const CanonicalForm & G, ///< [in] a bivariate poly
}
if (degree (A) > 0)
{
resultRoot= FqBiFactorize (A, alpha);
resultRoot= FqBiFactorize (A, alpha, false);
resultRoot.removeFirst();
for (CFFListIterator i= resultRoot; i.hasItem(); i++)
i.getItem()= CFFactor (N (decompress (i.getItem().factor(), M, S)),
Expand All @@ -362,14 +450,58 @@ CFFList FqBiFactorize (const CanonicalForm & G, ///< [in] a bivariate poly
/// multiplicity, the first element is the leading coefficient.
/// @sa FpBiFactorize(), FqBiFactorize()
inline
CFFList GFBiFactorize (const CanonicalForm & G ///< [in] a bivariate poly
)
CFFList
GFBiFactorize (const CanonicalForm & G, ///< [in] a bivariate poly
bool substCheck= true ///< [in] enables substitute check
)
{
ASSERT (CFFactory::gettype() == GaloisFieldDomain,
"GF as base field expected");
ExtensionInfo info= ExtensionInfo (getGFDegree(), gf_name, false);
CFMap N;
CanonicalForm F= compress (G, N);

if (substCheck)
{
bool foundOne= false;
int * substDegree= new int [F.level()];
for (int i= 1; i <= F.level(); i++)
{
substDegree[i-1]= substituteCheck (F, Variable (i));
if (substDegree [i-1] > 1)
{
foundOne= true;
subst (F, F, substDegree[i-1], Variable (i));
}
}
if (foundOne)
{
CFFList result= GFBiFactorize (F, false);
CFFList newResult, tmp;
CanonicalForm tmp2;
newResult.insert (result.getFirst());
result.removeFirst();
for (CFFListIterator i= result; i.hasItem(); i++)
{
tmp2= i.getItem().factor();
for (int j= 1; j <= F.level(); j++)
{
if (substDegree[j-1] > 1)
tmp2= reverseSubst (tmp2, substDegree[j-1], Variable (j));
}
tmp= GFBiFactorize (tmp2, false);
tmp.removeFirst();
for (CFFListIterator j= tmp; j.hasItem(); j++)
newResult.append (CFFactor (j.getItem().factor(),
j.getItem().exp()*i.getItem().exp()));
}
decompress (newResult, N);
delete [] substDegree;
return newResult;
}
delete [] substDegree;
}

CanonicalForm LcF= Lc (F);
CanonicalForm contentX= content (F, 1);
CanonicalForm contentY= content (F, 2);
Expand Down Expand Up @@ -403,7 +535,7 @@ CFFList GFBiFactorize (const CanonicalForm & G ///< [in] a bivariate poly
if (degree (pthRoot) > 0)
{
pthRoot= maxpthRoot (pthRoot, q, l);
result= GFBiFactorize (pthRoot);
result= GFBiFactorize (pthRoot, false);
result.removeFirst();
for (CFFListIterator i= result; i.hasItem(); i++)
i.getItem()= CFFactor (N (decompress (i.getItem().factor(), M, S)),
Expand All @@ -425,7 +557,7 @@ CFFList GFBiFactorize (const CanonicalForm & G ///< [in] a bivariate poly
}
if (degree (A) > 0)
{
resultRoot= GFBiFactorize (A);
resultRoot= GFBiFactorize (A, false);
resultRoot.removeFirst();
for (CFFListIterator i= resultRoot; i.hasItem(); i++)
i.getItem()= CFFactor (N (decompress (i.getItem().factor(), M, S)),
Expand Down
Loading

0 comments on commit f9b796e

Please sign in to comment.