27#include <NTL/config.h>
32# define OSTREAM std::ostream
33# define ISTREAM std::istream
34# elif defined(HAVE_IOSTREAM_H)
36# define OSTREAM ostream
37# define ISTREAM istream
41#include <NTL/mat_ZZ.h>
42#include <NTL/mat_lzz_p.h>
51#define TRANSEXT_PRIVATES
66#define MAX_CHAR_FACTORY 536870909
86 #if __FLINT_RELEASE >= 20503
87 if (rField_is_Zp(r) && (r->cf->ch>10))
90 if (!convSingRFlintR(ctx,r))
93 return Flint_GCD_MP(
f,pLength(
f),
g,pLength(
g),ctx,r);
100 if (!convSingRFlintR(ctx,r))
103 poly
res=Flint_GCD_MP(
f,pLength(
f),
g,pLength(
g),ctx,r);
111 fmpz_mpoly_ctx_t ctx;
112 if (!convSingRFlintR(ctx,r))
115 poly
res=Flint_GCD_MP(
f,pLength(
f),
g,pLength(
g),ctx,r);
122 if (rField_is_Q(r) || rField_is_Zp(r) || rField_is_Z(r)
130 if ( rField_is_Zp(r))
132 else if (rField_is_Q(r) && (!n_GreaterZero(pGetCoeff(
res),r->cf)))
136 else if ( r->cf->extRing!=
NULL )
142 if (r->cf->extRing->qideal!=
NULL)
197 if (!n_IsOne(pGetCoeff(
G),r->cf)
198 || (!p_IsConstant(
G,r)))
208 if (!n_IsOne(pGetCoeff(
G),r->cf)
209 || (!p_IsConstant(
G,r)))
219 if (rField_is_Q(r) || (rField_is_Zp(r))
258 else if ( r->cf->extRing )
264 if (r->cf->extRing->qideal!=
NULL)
363 WerrorS(
"3rd argument must be a ring variable");
364 goto resultant_returns_res;
367 goto resultant_returns_res;
370 if (rField_is_Zp(r) || rField_is_Q(r) || rField_is_Z(r)
380 goto resultant_returns_res;
383 else if (r->cf->extRing!=
NULL)
390 if (r->cf->extRing->qideal!=
NULL)
411 if ((
nf!=
NULL)&&(!n_IsOne(
nf,r->cf)))
413 number n=n_Invers(
nf,r->cf);
422 if ((ng!=
NULL)&&(!n_IsOne(ng,r->cf)))
424 number n=n_Invers(ng,r->cf);
435 goto resultant_returns_res;
439resultant_returns_res:
512 if ( rField_is_Q(r) || rField_is_Zp(r)
535 else if ( r->cf->extRing!=
NULL )
542 if (r->cf->extRing->qideal!=
NULL)
586 dummy=
p_Sub(p_Add_q(pp_Mult_qq(
f,pa,r),pp_Mult_qq(
g,pb,r),r),p_Copy(
res,r),r);
601 if (rField_is_Zp(r) || rField_is_Q(r) || rField_is_Z(r)
604 if (rField_is_Z(r))
Off(SW_RATIONAL);
611 else if (r->cf->extRing!=
NULL)
617 if (r->cf->extRing->qideal!=
NULL)
634 else if (rField_is_GF())
640 res = convFactoryGFSingGF( F *
G );
654 #if __FLINT_RELEASE >= 20503
661 nmod_mpoly_ctx_t ctx;
662 if (!convSingRFlintR(ctx,r))
664 res = Flint_Divide_MP(
f,0,
g,0,ctx,r);
672 fmpq_mpoly_ctx_t ctx;
673 if (!convSingRFlintR(ctx,r))
675 res = Flint_Divide_MP(
f,0,
g,0,ctx,r);
684 if (rField_is_Zp(r) || rField_is_Q(r)
694 else if (r->cf->extRing!=
NULL)
700 if (r->cf->extRing->qideal!=
NULL)
717 else if (rField_is_GF())
723 res = convFactoryGFSingGF( F /
G );
736 if (rField_is_Zp(r) || rField_is_Q(r)
749 else if (r->cf->extRing!=
NULL)
755 if (r->cf->extRing->qideal!=
NULL)
778 else if (rField_is_GF())
784 res = convFactoryGFSingGF( F /
G );
795void singclap_divide_content ( poly
f,
const ring r )
803 p_SetCoeff(
f, n_Init( 1, r->cf ), r );
808 if ( rField_is_Q_a(r) )
810 else if ( rField_is_Zp_a(r) )
821 number g1=pGetCoeff(
f);
822 number g2=pGetCoeff(
p);
824 int sz1=n_Size(g1, r->cf);
825 int sz2=n_Size(g2, r->cf);
835 int n_sz=n_Size(pGetCoeff(
p),r->cf);
858 while ( (
p !=
NULL) && (
g != 1) && (
g != 0))
867 if ((
g == 1 ) || (
g == 0))
877 fraction c=(fraction)pGetCoeff(
p);
878 p_Delete(&(
NUM(c)),r->cf->extRing);
898 if (!p_IsConstant(fac,r))
900#ifdef FACTORIZE2_DEBUG
901 printf(
"start count_Factors(%d), Fdeg=%d, factor deg=%d\n",
j,p_Totaldegree(
f,r),p_Totaldegree(fac,r));
907 if (rField_is_Zp(r) || rField_is_Q(r)
913 else if (r->cf->extRing!=
NULL)
915 if (r->cf->extRing->qideal!=
NULL)
942 if (rField_is_Zp(r) || rField_is_Q(r)
947 else if (r->cf->extRing!=
NULL)
949 if (r->cf->extRing->qideal!=
NULL)
958 e++; p_Delete(&
f,r);
f=q; q=
NULL; F=
Q;
965 if (r->cf->extRing!=
NULL)
966 if (r->cf->extRing->qideal!=
NULL)
987#ifdef FACTORIZE2_DEBUG
988 printf(
"singclap_factorize, degree %ld\n",p_Totaldegree(
f,r));
1014 for(
i=rVar(r);
i>0;
i--)
if(p_GetExp(
f,
i,r)!=0) n++;
1015 if (with_exps==0) n++;
1020 res->m[0]=
p_NSet(n_Copy(pGetCoeff(
f),r->cf),r);
1023 (*v)=
new intvec(si_max(1,n));
1038 for(
i=rVar(r);
i>0;
i--)
1048 if (with_exps!=1) (**v)[n]=e;
1063 number old_lead_coeff=n_Copy(pGetCoeff(
f), r->cf);
1068 if (rField_is_Q(r) || rField_is_Q_a(r) || rField_is_Z(r))
1072 number n0=n_Copy(pGetCoeff(
f),r->cf);
1079 NN=n_Div(n0,pGetCoeff(
f),r->cf);
1080 n_Delete(&n0,r->cf);
1088 else if (rField_is_Zp_a(r))
1093 number n0=n_Copy(pGetCoeff(
f),r->cf);
1098 NN=n_Div(n0,pGetCoeff(
f),r->cf);
1099 n_Delete(&n0,r->cf);
1107 if (rField_is_Q(r) || rField_is_Zp(r) || rField_is_Z(r) || rField_is_Zn(r))
1117 else if (r->cf->extRing!=
NULL)
1124 if (r->cf->extRing->qideal!=
NULL)
1153 poly ff=p_Copy(
f,r);
1164 if ((with_exps==2)&&(n>1))
1175 if (rField_is_Zp(r) || rField_is_Q(r)|| rField_is_Z(r)
1182 else if (rField_is_GF())
1185 else if (r->cf->extRing!=
NULL)
1191 if (r->cf->extRing->qideal==
NULL)
1219 if (r->cf->extRing!=
NULL)
1220 if (r->cf->extRing->qideal!=
NULL)
1223 if ((r->cf->extRing!=
NULL) && (!p_IsConstant(ff,r)))
1229#ifdef FACTORIZE2_DEBUG
1230 printf(
"factorize_retry\n");
1236 int l=(*v)->length();
1238 for(jj=0;jj<ww->
length();jj++)
1239 (**
v)[jj+
l]=(*ww)[jj];
1244 hh->m[jj]=
res->m[jj];
1260 WarnS(
"problem with factorize");
1288 && (p_IsConstant(
res->m[
i],r)))
1292 p_Delete(&(
res->m[
i]),r);
1301 res->m[0]=p_Mult_q(
res->m[0],p_Copy(
res->m[
i],r),r);
1320 for (
i=0,
j=0;
i<si_min(
w->length(),len);
i++)
1324 (**v)[
j]=(*w)[
i];
j++;
1336 if (rField_is_Q_a(r) && (r->cf->extRing->qideal!=
NULL))
1340 if (with_exps!=0) stop=0;
1345 if (with_exps==0) p_SetCoeff(
res->m[0],old_lead_coeff,r);
1346 else n_Delete(&old_lead_coeff,r->cf);
1349 n_Delete(&old_lead_coeff,r->cf);
1356 if ((
v!=
NULL) && ((*
v)!=
NULL) &&(with_exps==2))
1365 else p_Delete(&
f,r);
1368 n_Delete(&NN,r->cf);
1380#ifdef FACTORIZE2_DEBUG
1381 printf(
"singclap_sqrfree, degree %d\n",pTotaldegree(
f));
1394 if (with_exps!=1 && with_exps!=3)
1407 for(
i=rVar(r);
i>0;
i--)
if(p_GetExp(
f,
i,r)!=0) n++;
1408 if (with_exps==0 || with_exps==3) n++;
1412 (*v)=
new intvec(si_max(1,n));
1415 res->m[0]=
p_NSet(n_Copy(pGetCoeff(
f),r->cf),r);
1423 for(
i=rVar(r);
i>0;
i--)
1433 if (with_exps!=1) (**v)[n]=e;
1447 number old_lead_coeff=n_Copy(pGetCoeff(
f), r->cf);
1450 if (!rField_is_Zp(r) && !rField_is_Zp_a(r))
1453 number n0=n_Copy(old_lead_coeff,r->cf);
1454 if (with_exps==0 || with_exps==3)
1459 NN=n_Div(n0,pGetCoeff(
f),r->cf);
1460 n_Delete(&n0,r->cf);
1461 if (with_exps==0 || with_exps==3)
1467 else if (rField_is_Zp_a(r))
1472 number n0=n_Copy(old_lead_coeff,r->cf);
1473 if (with_exps==0 || with_exps==3)
1477 NN=n_Div(n0,pGetCoeff(
f),r->cf);
1478 n_Delete(&n0,r->cf);
1479 if (with_exps==0 || with_exps==3)
1486 if (rField_is_Q(r) || rField_is_Zp(r)
1495 else if (r->cf->extRing!=
NULL)
1501 if (r->cf->extRing->qideal!=
NULL)
1516 else if (rField_is_GF())
1518 int c=rInternalChar(r);
1543 if ((with_exps==2)&&(n>1))
1558 if (with_exps!=1 && with_exps!=3) (**v)[
j] = J.
getItem().
exp();
1559 if (rField_is_Zp(r) || rField_is_Q(r)
1562 else if (r->cf->extRing!=
NULL)
1564 if (r->cf->extRing->qideal==
NULL)
1581 if (r->cf->extRing!=
NULL)
1582 if (r->cf->extRing->qideal!=
NULL)
1584 if (rField_is_Q_a(r) && (r->cf->extRing->qideal!=
NULL))
1588 if (with_exps!=0 || with_exps==3) stop=0;
1593 if (with_exps==0 || with_exps==3) p_SetCoeff(
res->m[0],old_lead_coeff,r);
1594 else n_Delete(&old_lead_coeff,r->cf);
1597 n_Delete(&old_lead_coeff,r->cf);
1605 n_Delete(&NN,r->cf);
1626 if (rField_is_Q(r) || rField_is_Zp(r)
1678 for ( LLi = LL; LLi.
hasItem(); LLi++ )
1680 n = si_max(LLi.
getItem().length(),n);
1682 if ((
m!=0) && (n!=0))
break;
1684 if (tries>=5)
break;
1686 if ((
m==0) || (n==0))
1688 Warn(
"char_series returns %d x %d matrix from %d input polys (%d)",
1696 for (
m=1, LLi = LL; LLi.
hasItem(); LLi++,
m++ )
1700 if (rField_is_Q(r) || rField_is_Zp(r)
1718 if (rField_is_Q(r) || rField_is_Zp(r)
1766 int cnt=rVar(r)+offs;
1787 for(
i=0;
i<rVar(r)+offs;
i++)
1807 if (
s[strlen(
s)-1]==
',')
s[strlen(
s)-1]=
'\0';
1816 Werror(
"det of %d x %d matrix",r,
m->cols());
1841 for(
i=
m->rows();
i>0;
i--)
1843 for(
j=
m->cols();
j>0;
j--)
1858 for(
i=
m->rows();
i>0;
i--)
1860 for(
j=
m->cols();
j>0;
j--)
1870#if defined(HAVE_NTL) || defined(HAVE_FLINT)
1876 Werror(
"HNF of %d x %d matrix",r,
m->cols());
1912 Werror(
"HNF of %d x %d matrix",r,
m->cols());
1943 Werror(
"HNF of %d x %d matrix",r,
b->cols());
2057 if (rField_is_Zp(
R))
2060 mat_zz_p *NTLM=
new mat_zz_p;
2069 if (p_Totaldegree(
h,
R)==0)
2075 WerrorS(
"smatrix for rref is not constant");
2086 number n=n_Init(rep((*NTLM)(
i,
j)),
R->cf);
2087 if(!n_IsZero(n,
R->cf))
2098 WerrorS(
"not implemented for these coefficients");
2111 if (rField_is_Zp(
R))
2114 mat_zz_p *NTLM=
new mat_zz_p;
2122 if (p_Totaldegree(
h,
R)==0)
2126 WerrorS(
"smatrix for rref is not constant");
2137 number n=n_Init(rep((*NTLM)(
i,
j)),
R->cf);
2138 if(!n_IsZero(n,
R->cf))
2142 M->m[
j-1]=p_Add_q(
M->m[
j-1],
p,
R);
2150 WerrorS(
"not implemented for these coefficients");
2156#if defined(HAVE_NTL) || defined(HAVE_FLINT)
2176 bool isRat=
isOn (SW_RATIONAL);
2182 int n= absFactors.
length();
2222 numFactors +=
count;
2236 WerrorS(
"NTL/FLINT missing: absFactorize");
bigintmat * bimCopy(const bigintmat *b)
same as copy constructor - apart from it being able to accept NULL as input
#define BIMATELEM(M, I, J)
ListCFList irrCharSeries(const CFList &PS)
irreducible characteristic series
IntList neworderint(const CFList &PolyList)
const CanonicalForm CFMap CFMap & N
CanonicalForm extgcd(const CanonicalForm &f, const CanonicalForm &g, CanonicalForm &a, CanonicalForm &b)
CanonicalForm extgcd ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & a,...
CanonicalForm bCommonDen(const CanonicalForm &f)
void psqr ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & q, CanonicalForm & r,...
CanonicalForm FACTORY_PUBLIC determinant(const CFMatrix &M, int n)
CFFList FACTORY_PUBLIC sqrFree(const CanonicalForm &f, bool sort=false)
squarefree factorization
CFFList FACTORY_PUBLIC factorize(const CanonicalForm &f, bool issqrfree=false)
factorization over or
CanonicalForm FACTORY_PUBLIC resultant(const CanonicalForm &f, const CanonicalForm &g, const Variable &x)
CanonicalForm resultant ( const CanonicalForm & f, const CanonicalForm & g, const Variable & x ).
static const int SW_USE_QGCD
set to 1 to use Encarnacion GCD over Q(a)
static const int SW_USE_EZGCD_P
set to 1 to use EZGCD over F_q
static const int SW_SYMMETRIC_FF
set to 1 for symmetric representation over F_q
CFMatrix * cf_LLL(CFMatrix &A)
performs LLL reduction.
CFMatrix * cf_HNF(CFMatrix &A)
The input matrix A is an n x m matrix of rank m (so n >= m), and D is a multiple of the determinant o...
CanonicalForm convSingPFactoryP(poly p, const ring r)
BOOLEAN convSingTrP(poly p, const ring r)
poly convFactoryPSingTrP(const CanonicalForm &f, const ring r)
poly convFactoryAPSingAP(const CanonicalForm &f, const ring r)
CanonicalForm convSingAPFactoryAP(poly p, const Variable &a, const ring r)
poly convFactoryPSingP(const CanonicalForm &f, const ring r)
int convFactoryISingI(const CanonicalForm &f)
void out_cf(const char *s1, const CanonicalForm &f, const char *s2)
CanonicalForm convSingTrPFactoryP(poly p, const ring r)
poly singclap_resultant(poly f, poly g, poly x, const ring r)
BOOLEAN count_Factors(ideal I, intvec *v, int j, poly &f, poly fac, const ring r)
matrix singntl_HNF(matrix m, const ring s)
poly singclap_pmod(poly f, poly g, const ring r)
ideal singclap_factorize(poly f, intvec **v, int with_exps, const ring r)
matrix singclap_irrCharSeries(ideal I, const ring r)
int pGetExp_Var(poly p, int i, const ring r)
VAR int singclap_factorize_retry
poly singclap_pdivide(poly f, poly g, const ring r)
int * Zp_roots(poly p, const ring r)
BOOLEAN singclap_extgcd(poly f, poly g, poly &res, poly &pa, poly &pb, const ring r)
matrix singntl_rref(matrix m, const ring R)
poly singclap_det(const matrix m, const ring s)
poly singclap_gcd_and_divide(poly &f, poly &g, const ring r)
clears denominators of f and g, divides by gcd(f,g)
matrix singntl_LLL(matrix m, const ring s)
number singclap_det_bi(bigintmat *m, const coeffs cf)
poly singclap_pmult(poly f, poly g, const ring r)
poly singclap_gcd_r(poly f, poly g, const ring r)
int singclap_det_i(intvec *m, const ring)
ideal singclap_absFactorize(poly f, ideal &mipos, intvec **exps, int &numFactors, const ring r)
ideal singclap_sqrfree(poly f, intvec **v, int with_exps, const ring r)
char * singclap_neworder(ideal I, const ring r)
factory's class for variables
Coefficient rings, fields and other domains suitable for Singular polynomials.
static FORCE_INLINE number n_convFactoryNSingN(const CanonicalForm n, const coeffs r)
static FORCE_INLINE CanonicalForm n_convSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
static FORCE_INLINE BOOLEAN nCoeff_is_transExt(const coeffs r)
TRUE iff r represents a transcendental extension field.
CFAFList absFactorize(const CanonicalForm &G)
absolute factorization of a multivariate poly over Q
const CanonicalForm int s
const Variable & v
< [in] a sqrfree bivariate poly
factory.h' is the user interface to Factory.
Variable FACTORY_PUBLIC rootOf(const CanonicalForm &, char name='@')
returns a symbolic root of polynomial with name name Use it to define algebraic variables
void FACTORY_PUBLIC prune(Variable &alpha)
void WerrorS(const char *s)
STATIC_VAR int nfMinPoly[16]
This file is work in progress and currently not part of the official Singular.
BOOLEAN idIs0(ideal h)
returns true if h is the zero ideal
intvec * ivCopy(const intvec *o)
#define IMATELEM(M, I, J)
matrix mpNew(int r, int c)
create a r x c zero-matrix
void iiWriteMatrix(matrix im, const char *n, int dim, const ring r, int spaces)
set spaces to zero by default
#define MATELEM(mat, i, j)
1-based access to matrix
The main handler for Singular numbers which are suitable for Singular polynomials.
CanonicalForm ndConvSingNFactoryN(number, BOOLEAN, const coeffs)
int p_IsPurePower(const poly p, const ring r)
return i, if head depends only on var(i)
void p_Cleardenom_n(poly ph, const ring r, number &c)
poly p_GcdMon(poly f, poly g, const ring r)
polynomial gcd for f=mon
void p_Content(poly ph, const ring r)
void p_Norm(poly p1, const ring r)
poly p_Div_mm(poly p, const poly m, const ring r)
divide polynomial by monomial
poly p_Cleardenom(poly p, const ring r)
poly p_Sub(poly p1, poly p2, const ring r)
poly p_NSet(number n, const ring r)
returns the poly representing the number n, destroys n
void p_Write(poly p, ring lmRing, ring tailRing)
void p_Write0(poly p, ring lmRing, ring tailRing)
#define __p_Mult_nn(p, n, r)
void p_wrp(poly p, ring lmRing, ring tailRing)
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
std::pair< int, int > mark
void StringSetS(const char *st)
void StringAppendS(const char *st)
const char feNotImplemented[]
void PrintS(const char *s)
void Werror(const char *fmt,...)
int status int void size_t count
ideal idInit(int idsize, int rank)
initialise an ideal / module
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
void idShow(const ideal id, const ring lmRing, const ring tailRing, const int debugPrint)
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size