My Project
Macros | Functions | Variables
clapsing.cc File Reference
#include "misc/auxiliary.h"
#include "clapsing.h"
#include "factory/factory.h"
#include "factory/cf_roots.h"
#include "coeffs/numbers.h"
#include "coeffs/coeffs.h"
#include "coeffs/bigintmat.h"
#include "monomials/ring.h"
#include "simpleideals.h"
#include "polys/flintconv.h"
#include "polys/flint_mpoly.h"
#include "ext_fields/transext.h"
#include "clapconv.h"
#include "polys/monomials/p_polys.h"
#include "misc/intvec.h"
#include "polys/matpol.h"

Go to the source code of this file.

Macros

#define TRANSEXT_PRIVATES
 

Functions

void out_cf (const char *s1, const CanonicalForm &f, const char *s2)
 
poly singclap_gcd_r (poly f, poly g, const ring r)
 
poly singclap_gcd_and_divide (poly &f, poly &g, const ring r)
 clears denominators of f and g, divides by gcd(f,g) More...
 
int pGetExp_Var (poly p, int i, const ring r)
 
poly singclap_resultant (poly f, poly g, poly x, const ring r)
 
BOOLEAN singclap_extgcd (poly f, poly g, poly &res, poly &pa, poly &pb, const ring r)
 
poly singclap_pmult (poly f, poly g, const ring r)
 
poly singclap_pdivide (poly f, poly g, const ring r)
 
poly singclap_pmod (poly f, poly g, const ring r)
 
BOOLEAN count_Factors (ideal I, intvec *v, int j, poly &f, poly fac, const ring r)
 
ideal singclap_factorize (poly f, intvec **v, int with_exps, const ring r)
 
ideal singclap_sqrfree (poly f, intvec **v, int with_exps, const ring r)
 
matrix singclap_irrCharSeries (ideal I, const ring r)
 
char * singclap_neworder (ideal I, const ring r)
 
poly singclap_det (const matrix m, const ring s)
 
int singclap_det_i (intvec *m, const ring)
 
number singclap_det_bi (bigintmat *m, const coeffs cf)
 
matrix singntl_HNF (matrix m, const ring s)
 
intvecsingntl_HNF (intvec *m)
 
bigintmatsingntl_HNF (bigintmat *b)
 
matrix singntl_LLL (matrix m, const ring s)
 
intvecsingntl_LLL (intvec *m)
 
ideal singclap_absFactorize (poly f, ideal &mipos, intvec **exps, int &numFactors, const ring r)
 
int * Zp_roots (poly p, const ring r)
 

Variables

VAR int singclap_factorize_retry
 

Macro Definition Documentation

◆ TRANSEXT_PRIVATES

#define TRANSEXT_PRIVATES

Definition at line 28 of file clapsing.cc.

Function Documentation

◆ count_Factors()

BOOLEAN count_Factors ( ideal  I,
intvec v,
int  j,
poly &  f,
poly  fac,
const ring  r 
)

Definition at line 824 of file clapsing.cc.

825 {
826  p_Test(f,r);
827  p_Test(fac,r);
828  int e=0;
829  if (!p_IsConstant(fac,r))
830  {
831 #ifdef FACTORIZE2_DEBUG
832  printf("start count_Factors(%d), Fdeg=%d, factor deg=%d\n",j,p_Totaldegree(f,r),p_Totaldegree(fac,r));
833  p_wrp(fac,r);PrintLn();
834 #endif
835  On(SW_RATIONAL);
836  CanonicalForm F, FAC,Q,R;
837  Variable a;
838  if (rField_is_Zp(r) || rField_is_Q(r)
839  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
840  {
841  F=convSingPFactoryP( f,r );
842  FAC=convSingPFactoryP( fac,r );
843  }
844  else if (r->cf->extRing!=NULL)
845  {
846  if (r->cf->extRing->qideal!=NULL)
847  {
848  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
849  r->cf->extRing);
850  a=rootOf(mipo);
851  F=convSingAPFactoryAP( f,a,r );
852  FAC=convSingAPFactoryAP( fac,a,r );
853  }
854  else
855  {
856  F=convSingTrPFactoryP( f,r );
857  FAC=convSingTrPFactoryP( fac,r );
858  }
859  }
860  else
862 
863  poly q;
864  loop
865  {
866  Q=F;
867  Q/=FAC;
868  R=Q;
869  R*=FAC;
870  R-=F;
871  if (R.isZero())
872  {
873  if (rField_is_Zp(r) || rField_is_Q(r)
874  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
875  {
876  q = convFactoryPSingP( Q,r );
877  }
878  else if (r->cf->extRing!=NULL)
879  {
880  if (r->cf->extRing->qideal!=NULL)
881  {
882  q= convFactoryAPSingAP( Q,r );
883  }
884  else
885  {
886  q= convFactoryPSingTrP( Q,r );
887  }
888  }
889  e++; p_Delete(&f,r); f=q; q=NULL; F=Q;
890  }
891  else
892  {
893  break;
894  }
895  }
896  if (r->cf->extRing!=NULL)
897  if (r->cf->extRing->qideal!=NULL)
898  prune (a);
899  if (e==0)
900  {
901  Off(SW_RATIONAL);
902  return FALSE;
903  }
904  }
905  else e=1;
906  I->m[j]=fac;
907  if (v!=NULL) (*v)[j]=e;
908  Off(SW_RATIONAL);
909  return TRUE;
910 }
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
void On(int sw)
switches
void Off(int sw)
switches
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:30
FILE * f
Definition: checklibs.c:9
CanonicalForm convSingPFactoryP(poly p, const ring r)
Definition: clapconv.cc:136
poly convFactoryPSingTrP(const CanonicalForm &f, const ring r)
Definition: clapconv.cc:366
poly convFactoryAPSingAP(const CanonicalForm &f, const ring r)
Definition: clapconv.cc:184
CanonicalForm convSingAPFactoryAP(poly p, const Variable &a, const ring r)
Definition: clapconv.cc:148
poly convFactoryPSingP(const CanonicalForm &f, const ring r)
Definition: clapconv.cc:40
CanonicalForm convSingTrPFactoryP(poly p, const ring r)
Definition: clapconv.cc:316
factory's main class
Definition: canonicalform.h:86
factory's class for variables
Definition: factory.h:134
CanonicalForm mipo
Definition: facAlgExt.cc:57
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:39
int j
Definition: facHensel.cc:110
Variable FACTORY_PUBLIC rootOf(const CanonicalForm &, char name='@')
returns a symbolic root of polynomial with name name Use it to define algebraic variables
Definition: variable.cc:162
void FACTORY_PUBLIC prune(Variable &alpha)
Definition: variable.cc:261
void WerrorS(const char *s)
Definition: feFopen.cc:24
STATIC_VAR jList * Q
Definition: janet.cc:30
CanonicalForm ndConvSingNFactoryN(number, BOOLEAN, const coeffs)
Definition: numbers.cc:275
#define NULL
Definition: omList.c:12
static BOOLEAN p_IsConstant(const poly p, const ring r)
Definition: p_polys.h:1971
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:861
static long p_Totaldegree(poly p, const ring r)
Definition: p_polys.h:1467
#define p_Test(p, r)
Definition: p_polys.h:162
void p_wrp(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:373
const char feNotImplemented[]
Definition: reporter.cc:54
void PrintLn()
Definition: reporter.cc:310
static BOOLEAN rField_is_Zp(const ring r)
Definition: ring.h:505
static BOOLEAN rField_is_Zn(const ring r)
Definition: ring.h:517
static BOOLEAN rField_is_Q(const ring r)
Definition: ring.h:511
#define R
Definition: sirandom.c:27
#define loop
Definition: structs.h:80

◆ out_cf()

void out_cf ( const char *  s1,
const CanonicalForm f,
const char *  s2 
)

Definition at line 99 of file cf_factor.cc.

100 {
101  printf("%s",s1);
102  if (f.isZero()) printf("+0");
103  //else if (! f.inCoeffDomain() )
104  else if (! f.inBaseDomain() )
105  {
106  int l = f.level();
107  for ( CFIterator i = f; i.hasTerms(); i++ )
108  {
109  int e=i.exp();
110  if (i.coeff().isOne())
111  {
112  printf("+");
113  if (e==0) printf("1");
114  else
115  {
116  printf("%c",'a'+l-1);
117  if (e!=1) printf("^%d",e);
118  }
119  }
120  else
121  {
122  out_cf("+(",i.coeff(),")");
123  if (e!=0)
124  {
125  printf("*%c",'a'+l-1);
126  if (e!=1) printf("^%d",e);
127  }
128  }
129  }
130  }
131  else
132  {
133  if ( f.isImm() )
134  {
136  {
137  long a= imm2int (f.getval());
138  if ( a == gf_q )
139  printf ("+%ld", a);
140  else if ( a == 0L )
141  printf ("+1");
142  else if ( a == 1L )
143  printf ("+%c",gf_name);
144  else
145  {
146  printf ("+%c",gf_name);
147  printf ("^%ld",a);
148  }
149  }
150  else
151  {
152  long l=f.intval();
153  if (l<0) printf("%ld",l);
154  else printf("+%ld",l);
155  }
156  }
157  else
158  {
159  #ifdef NOSTREAMIO
160  if (f.inZ())
161  {
162  mpz_t m;
163  gmp_numerator(f,m);
164  char * str = new char[mpz_sizeinbase( m, 10 ) + 2];
165  str = mpz_get_str( str, 10, m );
166  puts(str);
167  delete[] str;
168  mpz_clear(m);
169  }
170  else if (f.inQ())
171  {
172  mpz_t m;
173  gmp_numerator(f,m);
174  char * str = new char[mpz_sizeinbase( m, 10 ) + 2];
175  str = mpz_get_str( str, 10, m );
176  while(str[strlen(str)]<' ') { str[strlen(str)]='\0'; }
177  puts(str);putchar('/');
178  delete[] str;
179  mpz_clear(m);
181  str = new char[mpz_sizeinbase( m, 10 ) + 2];
182  str = mpz_get_str( str, 10, m );
183  while(str[strlen(str)]<' ') { str[strlen(str)]='\0'; }
184  puts(str);
185  delete[] str;
186  mpz_clear(m);
187  }
188  #else
189  std::cout << f;
190  #endif
191  }
192  //if (f.inZ()) printf("(Z)");
193  //else if (f.inQ()) printf("(Q)");
194  //else if (f.inFF()) printf("(FF)");
195  //else if (f.inPP()) printf("(PP)");
196  //else if (f.inGF()) printf("(PP)");
197  //else
198  if (f.inExtension()) printf("E(%d)",f.level());
199  }
200  printf("%s",s2);
201 }
int l
Definition: cfEzgcd.cc:100
int m
Definition: cfEzgcd.cc:128
int i
Definition: cfEzgcd.cc:132
#define GaloisFieldDomain
Definition: cf_defs.h:24
void out_cf(const char *s1, const CanonicalForm &f, const char *s2)
cf_algorithm.cc - simple mathematical algorithms.
Definition: cf_factor.cc:99
static int gettype()
Definition: cf_factory.h:28
class to iterate through CanonicalForm's
Definition: cf_iter.h:44
void FACTORY_PUBLIC gmp_numerator(const CanonicalForm &f, mpz_ptr result)
Definition: singext.cc:20
void FACTORY_PUBLIC gmp_denominator(const CanonicalForm &f, mpz_ptr result)
Definition: singext.cc:40
VAR int gf_q
Definition: gfops.cc:47
VAR char gf_name
Definition: gfops.cc:52
static long imm2int(const InternalCF *const imm)
Definition: imm.h:70
char * str(leftv arg)
Definition: shared.cc:704

◆ pGetExp_Var()

int pGetExp_Var ( poly  p,
int  i,
const ring  r 
)

Definition at line 297 of file clapsing.cc.

298 {
299  int m=0;
300  int mm;
301  while (p!=NULL)
302  {
303  mm=p_GetExp(p,i,r);
304  if (mm>m) m=mm;
305  pIter(p);
306  }
307  return m;
308 }
int p
Definition: cfModGcd.cc:4080
#define pIter(p)
Definition: monomials.h:37
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent @Note: the integer VarOffset encodes:
Definition: p_polys.h:469

◆ singclap_absFactorize()

ideal singclap_absFactorize ( poly  f,
ideal &  mipos,
intvec **  exps,
int &  numFactors,
const ring  r 
)

Definition at line 1963 of file clapsing.cc.

1964 {
1965  p_Test(f, r);
1966 
1967  ideal res=NULL;
1968 
1969  int offs = rPar(r);
1970  if (f==NULL)
1971  {
1972  res= idInit (1, 1);
1973  mipos= idInit (1, 1);
1974  mipos->m[0]= convFactoryPSingTrP (Variable (offs), r); //overkill
1975  (*exps)=new intvec (1);
1976  (**exps)[0]= 1;
1977  numFactors= 0;
1978  return res;
1979  }
1981 
1982  bool isRat= isOn (SW_RATIONAL);
1983  if (!isRat)
1984  On (SW_RATIONAL);
1985 
1986  CFAFList absFactors= absFactorize (F);
1987 
1988  int n= absFactors.length();
1989  *exps=new intvec (n);
1990 
1991  res= idInit (n, 1);
1992 
1993  mipos= idInit (n, 1);
1994 
1995  Variable x= Variable (offs);
1996  Variable alpha;
1997  int i= 0;
1998  numFactors= 0;
1999  int count;
2000  CFAFListIterator iter= absFactors;
2001  CanonicalForm lead= iter.getItem().factor();
2002  if (iter.getItem().factor().inCoeffDomain())
2003  {
2004  i++;
2005  iter++;
2006  }
2007  for (; iter.hasItem(); iter++, i++)
2008  {
2009  (**exps)[i]= iter.getItem().exp();
2010  alpha= iter.getItem().minpoly().mvar();
2011  if (iter.getItem().minpoly().isOne())
2012  lead /= power (bCommonDen (iter.getItem().factor()), iter.getItem().exp());
2013  else
2014  lead /= power (power (bCommonDen (iter.getItem().factor()), degree (iter.getItem().minpoly())), iter.getItem().exp());
2015  res->m[i]= convFactoryPSingTrP (replacevar (iter.getItem().factor()*bCommonDen (iter.getItem().factor()), alpha, x), r);
2016  if (iter.getItem().minpoly().isOne())
2017  {
2018  count= iter.getItem().exp();
2019  mipos->m[i]= convFactoryPSingTrP (x,r);
2020  }
2021  else
2022  {
2023  count= iter.getItem().exp()*degree (iter.getItem().minpoly());
2024  mipos->m[i]= convFactoryPSingTrP (replacevar (iter.getItem().minpoly(), alpha, x), r);
2025  }
2026  if (!iter.getItem().minpoly().isOne())
2027  prune (alpha);
2028  numFactors += count;
2029  }
2030  if (!isRat)
2031  Off (SW_RATIONAL);
2032 
2033  (**exps)[0]= 1;
2034  res->m[0]= convFactoryPSingTrP (lead, r);
2035  mipos->m[0]= convFactoryPSingTrP (x, r);
2036  return res;
2037 }
bool isOn(int sw)
switches
CanonicalForm power(const CanonicalForm &f, int n)
exponentiation
CanonicalForm FACTORY_PUBLIC replacevar(const CanonicalForm &, const Variable &, const Variable &)
CanonicalForm replacevar ( const CanonicalForm & f, const Variable & x1, const Variable & x2 )
Definition: cf_ops.cc:271
int degree(const CanonicalForm &f)
Variable x
Definition: cfModGcd.cc:4084
CanonicalForm bCommonDen(const CanonicalForm &f)
CanonicalForm bCommonDen ( const CanonicalForm & f )
T & getItem() const
Definition: ftmpl_list.cc:431
int length() const
Definition: ftmpl_list.cc:273
Definition: intvec.h:23
CFFListIterator iter
Definition: facAbsBiFact.cc:53
Variable alpha
Definition: facAbsBiFact.cc:51
CFAFList absFactorize(const CanonicalForm &G)
absolute factorization of a multivariate poly over Q
Definition: facAbsFact.cc:262
CanonicalForm res
Definition: facAbsFact.cc:60
static int rPar(const ring r)
(r->cf->P)
Definition: ring.h:604
int status int void size_t count
Definition: si_signals.h:59
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:35

◆ singclap_det()

poly singclap_det ( const matrix  m,
const ring  s 
)

Definition at line 1723 of file clapsing.cc.

1724 {
1725  int r=m->rows();
1726  if (r!=m->cols())
1727  {
1728  Werror("det of %d x %d matrix",r,m->cols());
1729  return NULL;
1730  }
1731  poly res=NULL;
1732  CFMatrix M(r,r);
1733  int i,j;
1734  for(i=r;i>0;i--)
1735  {
1736  for(j=r;j>0;j--)
1737  {
1739  }
1740  }
1742  Off(SW_RATIONAL);
1743  return res;
1744 }
CanonicalForm FACTORY_PUBLIC determinant(const CFMatrix &M, int n)
Definition: cf_linsys.cc:222
const CanonicalForm int s
Definition: facAbsFact.cc:51
#define MATELEM(mat, i, j)
1-based access to matrix
Definition: matpol.h:29
void Werror(const char *fmt,...)
Definition: reporter.cc:189
#define M
Definition: sirandom.c:25

◆ singclap_det_bi()

number singclap_det_bi ( bigintmat m,
const coeffs  cf 
)

Definition at line 1764 of file clapsing.cc.

1765 {
1766  assume(m->basecoeffs()==cf);
1767  CFMatrix M(m->rows(),m->cols());
1768  int i,j;
1769  BOOLEAN setchar=TRUE;
1770  for(i=m->rows();i>0;i--)
1771  {
1772  for(j=m->cols();j>0;j--)
1773  {
1774  M(i,j)=n_convSingNFactoryN(BIMATELEM(*m,i,j),setchar,cf);
1775  setchar=FALSE;
1776  }
1777  }
1778  number res=n_convFactoryNSingN( determinant(M,m->rows()),cf ) ;
1779  return res;
1780 }
int BOOLEAN
Definition: auxiliary.h:87
#define BIMATELEM(M, I, J)
Definition: bigintmat.h:133
CanonicalForm cf
Definition: cfModGcd.cc:4085
CanonicalForm n_convSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition: numbers.cc:629
number n_convFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition: numbers.cc:624
#define assume(x)
Definition: mod2.h:387

◆ singclap_det_i()

int singclap_det_i ( intvec m,
const  ring 
)

Definition at line 1746 of file clapsing.cc.

1747 {
1748 // assume( r == currRing ); // Anything else is not guaranted to work!
1749 
1750  setCharacteristic( 0 ); // ?
1751  CFMatrix M(m->rows(),m->cols());
1752  int i,j;
1753  for(i=m->rows();i>0;i--)
1754  {
1755  for(j=m->cols();j>0;j--)
1756  {
1757  M(i,j)=IMATELEM(*m,i,j);
1758  }
1759  }
1760  int res= convFactoryISingI( determinant(M,m->rows()) ) ;
1761  return res;
1762 }
void FACTORY_PUBLIC setCharacteristic(int c)
Definition: cf_char.cc:28
int convFactoryISingI(const CanonicalForm &f)
Definition: clapconv.cc:142
#define IMATELEM(M, I, J)
Definition: intvec.h:85

◆ singclap_extgcd()

BOOLEAN singclap_extgcd ( poly  f,
poly  g,
poly &  res,
poly &  pa,
poly &  pb,
const ring  r 
)

Definition at line 455 of file clapsing.cc.

456 {
457  // for now there is only the possibility to handle univariate
458  // polynomials over
459  // Q and Fp ...
460  res=NULL;pa=NULL;pb=NULL;
462  if ( rField_is_Q(r) || rField_is_Zp(r)
463  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
464  {
465  setCharacteristic( rChar(r) );
467  CanonicalForm FpG=F+G;
468  if (!(FpG.isUnivariate()|| FpG.inCoeffDomain()))
469  //if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar())
470  {
471  Off(SW_RATIONAL);
472  WerrorS("not univariate");
473  return TRUE;
474  }
475  CanonicalForm Fa,Gb;
476  On(SW_RATIONAL);
477  res=convFactoryPSingP( extgcd( F, G, Fa, Gb ),r );
478  pa=convFactoryPSingP(Fa,r);
479  pb=convFactoryPSingP(Gb,r);
480  Off(SW_RATIONAL);
481  }
482  // and over Q(a) / Fp(a)
483  else if ( r->cf->extRing!=NULL )
484  {
485  if (rField_is_Q_a(r)) setCharacteristic( 0 );
486  else setCharacteristic( rChar(r) );
487  CanonicalForm Fa,Gb;
488  if (r->cf->extRing->qideal!=NULL)
489  {
490  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
491  r->cf->extRing);
492  Variable a=rootOf(mipo);
493  CanonicalForm F( convSingAPFactoryAP( f,a,r ) ),
494  G( convSingAPFactoryAP( g,a,r ) );
495  CanonicalForm FpG=F+G;
496  if (!(FpG.isUnivariate()|| FpG.inCoeffDomain()))
497  //if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar())
498  {
499  WerrorS("not univariate");
500  return TRUE;
501  }
502  res= convFactoryAPSingAP( extgcd( F, G, Fa, Gb ),r );
503  pa=convFactoryAPSingAP(Fa,r);
504  pb=convFactoryAPSingAP(Gb,r);
505  prune (a);
506  }
507  else
508  {
510  CanonicalForm FpG=F+G;
511  if (!(FpG.isUnivariate()|| FpG.inCoeffDomain()))
512  //if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar())
513  {
514  Off(SW_RATIONAL);
515  WerrorS("not univariate");
516  return TRUE;
517  }
518  res= convFactoryPSingTrP( extgcd( F, G, Fa, Gb ), r );
519  pa=convFactoryPSingTrP(Fa, r);
520  pb=convFactoryPSingTrP(Gb, r);
521  }
522  Off(SW_RATIONAL);
523  }
524  else
525  {
527  return TRUE;
528  }
529 #ifndef SING_NDEBUG
530  // checking the result of extgcd:
531  poly dummy;
532  dummy=p_Sub(p_Add_q(pp_Mult_qq(f,pa,r),pp_Mult_qq(g,pb,r),r),p_Copy(res,r),r);
533  if (dummy!=NULL)
534  {
535  PrintS("extgcd( ");p_Write(f,r);p_Write0(g,r);PrintS(" )\n");
536  PrintS("extgcd( ");p_Write(f,r);p_Write0(g,r);PrintS(" )\n");
537  p_Delete(&dummy,r);
538  }
539 #endif
540  return FALSE;
541 }
g
Definition: cfModGcd.cc:4092
CanonicalForm extgcd(const CanonicalForm &f, const CanonicalForm &g, CanonicalForm &a, CanonicalForm &b)
CanonicalForm extgcd ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & a,...
Definition: cfUnivarGcd.cc:174
static const int SW_SYMMETRIC_FF
set to 1 for symmetric representation over F_q
Definition: cf_defs.h:32
bool inCoeffDomain() const
bool isUnivariate() const
BOOLEAN pa(leftv res, leftv args)
Definition: cohomo.cc:4344
BOOLEAN pb(leftv res, leftv args)
Definition: cohomo.cc:4371
STATIC_VAR TreeM * G
Definition: janet.cc:31
poly p_Sub(poly p1, poly p2, const ring r)
Definition: p_polys.cc:1977
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:896
void p_Write(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:342
void p_Write0(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:332
static poly pp_Mult_qq(poly p, poly q, const ring r)
Definition: p_polys.h:1111
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:812
void PrintS(const char *s)
Definition: reporter.cc:284
int rChar(ring r)
Definition: ring.cc:714
static BOOLEAN rField_is_Q_a(const ring r)
Definition: ring.h:544

◆ singclap_factorize()

ideal singclap_factorize ( poly  f,
intvec **  v,
int  with_exps,
const ring  r 
)

Definition at line 914 of file clapsing.cc.

916 {
917  p_Test(f,r);
918 #ifdef FACTORIZE2_DEBUG
919  printf("singclap_factorize, degree %ld\n",p_Totaldegree(f,r));
920 #endif
921  // with_exps: 3,1 return only true factors, no exponents
922  // 2 return true factors and exponents
923  // 0 return coeff, factors and exponents
924  BOOLEAN save_errorreported=errorreported;
925 
926  ideal res=NULL;
927 
928  // handle factorize(0) =========================================
929  if (f==NULL)
930  {
931  res=idInit(1,1);
932  if (with_exps!=1)
933  {
934  (*v)=new intvec(1);
935  (**v)[0]=1;
936  }
937  return res;
938  }
939  // handle factorize(mon) =========================================
940  if (pNext(f)==NULL)
941  {
942  int i=0;
943  int n=0;
944  int e;
945  for(i=rVar(r);i>0;i--) if(p_GetExp(f,i,r)!=0) n++;
946  if (with_exps==0) n++; // with coeff
947  res=idInit(si_max(n,1),1);
948  switch(with_exps)
949  {
950  case 0: // with coef & exp.
951  res->m[0]=p_NSet(n_Copy(pGetCoeff(f),r->cf),r);
952  // no break
953  case 2: // with exp.
954  (*v)=new intvec(si_max(1,n));
955  (**v)[0]=1;
956  // no break
957  case 1: ;
958 #ifdef TEST
959  default: ;
960 #endif
961  }
962  if (n==0)
963  {
964  if (res->m[0]==NULL) res->m[0]=p_One(r);
965  // (**v)[0]=1; is already done
966  }
967  else
968  {
969  for(i=rVar(r);i>0;i--)
970  {
971  e=p_GetExp(f,i,r);
972  if(e!=0)
973  {
974  n--;
975  poly p=p_One(r);
976  p_SetExp(p,i,1,r);
977  p_Setm(p,r);
978  res->m[n]=p;
979  if (with_exps!=1) (**v)[n]=e;
980  }
981  }
982  }
983  p_Delete(&f,r);
984  return res;
985  }
986  //PrintS("S:");p_Write(f,r);PrintLn();
987  // use factory/libfac in general ==============================
988  Variable dummy(-1); prune(dummy); // remove all (tmp.) extensions
989  Off(SW_RATIONAL);
991  CFFList L;
992  number N=NULL;
993  number NN=NULL;
994  number old_lead_coeff=n_Copy(pGetCoeff(f), r->cf);
995 
996  Variable a;
997  if (r->cf->convSingNFactoryN!=ndConvSingNFactoryN)
998  {
999  if (rField_is_Q(r) || rField_is_Q_a(r) || rField_is_Z(r)) /* Q, Q(a), Z */
1000  {
1001  //if (f!=NULL) // already tested at start of routine
1002  {
1003  number n0=n_Copy(pGetCoeff(f),r->cf);
1004  if (with_exps==0)
1005  N=n_Copy(n0,r->cf);
1006  if (rField_is_Z(r)) p_Content(f, r);
1007  else p_Cleardenom(f, r);
1008  //after here f should not have a denominator!! and no content
1009  //PrintS("S:");p_Write(f,r);PrintLn();
1010  NN=n_Div(n0,pGetCoeff(f),r->cf);
1011  n_Delete(&n0,r->cf);
1012  if (with_exps==0)
1013  {
1014  n_Delete(&N,r->cf);
1015  N=n_Copy(NN,r->cf);
1016  }
1017  }
1018  }
1019  else if (rField_is_Zp_a(r))
1020  {
1021  //if (f!=NULL) // already tested at start of routine
1022  if (singclap_factorize_retry==0)
1023  {
1024  number n0=n_Copy(pGetCoeff(f),r->cf);
1025  if (with_exps==0)
1026  N=n_Copy(n0,r->cf);
1027  p_Norm(f,r);
1028  p_Cleardenom(f, r);
1029  NN=n_Div(n0,pGetCoeff(f),r->cf);
1030  n_Delete(&n0,r->cf);
1031  if (with_exps==0)
1032  {
1033  n_Delete(&N,r->cf);
1034  N=n_Copy(NN,r->cf);
1035  }
1036  }
1037  }
1038  if (rField_is_Q(r) || rField_is_Zp(r) || rField_is_Z(r) || rField_is_Zn(r))
1039  {
1040  setCharacteristic( rChar(r) );
1041  if (errorreported) goto notImpl; // char too large
1042  CanonicalForm F( convSingPFactoryP( f,r ) );
1043  L = factorize( F );
1044  }
1045  // and over Q(a) / Fp(a)
1046  else if (r->cf->extRing!=NULL)
1047  {
1048  if (rField_is_Q_a (r)) setCharacteristic (0);
1049  else setCharacteristic( rChar(r) );
1050  if (errorreported) goto notImpl; // char too large
1051  if (r->cf->extRing->qideal!=NULL) /*algebraic extension */
1052  {
1053  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
1054  r->cf->extRing);
1055  a=rootOf(mipo);
1056  CanonicalForm F( convSingAPFactoryAP( f, a, r ) );
1057  L = factorize( F, a );
1058  prune(a);
1059  }
1060  else /* rational functions */
1061  {
1063  L = factorize( F );
1064  }
1065  }
1066  else
1067  {
1068  goto notImpl;
1069  }
1070  }
1071  else
1072  {
1073  goto notImpl;
1074  }
1075  if (errorreported)
1076  {
1078  }
1079  {
1080  poly ff=p_Copy(f,r); // a copy for the retry stuff
1081  // the first factor should be a constant
1082  if ( ! L.getFirst().factor().inCoeffDomain() )
1083  L.insert(CFFactor(1,1));
1084  // convert into ideal
1085  int n = L.length();
1086  if (n==0) n=1;
1087  CFFListIterator J=L;
1088  int j=0;
1089  if (with_exps!=1)
1090  {
1091  if ((with_exps==2)&&(n>1))
1092  {
1093  n--;
1094  J++;
1095  }
1096  *v = new intvec( n );
1097  }
1098  res = idInit( n ,1);
1099  for ( ; J.hasItem(); J++, j++ )
1100  {
1101  if (with_exps!=1) (**v)[j] = J.getItem().exp();
1102  if (rField_is_Zp(r) || rField_is_Q(r)|| rField_is_Z(r)
1103  || rField_is_Zn(r)) /* Q, Fp, Z */
1104  {
1105  //count_Factors(res,*v,f, j, convFactoryPSingP( J.getItem().factor() );
1106  res->m[j] = convFactoryPSingP( J.getItem().factor(),r );
1107  }
1108 #if 0
1109  else if (rField_is_GF())
1110  res->m[j] = convFactoryGFSingGF( J.getItem().factor() );
1111 #endif
1112  else if (r->cf->extRing!=NULL) /* Q(a), Fp(a) */
1113  {
1114 #ifndef SING_NDEBUG
1115  intvec *w=NULL;
1116  if (v!=NULL) w=*v;
1117 #endif
1118  if (r->cf->extRing->qideal==NULL)
1119  {
1120 #ifdef SING_NDEBUG
1121  res->m[j]= convFactoryPSingTrP( J.getItem().factor(),r );
1122 #else
1123  if(!count_Factors(res,w,j,ff,convFactoryPSingTrP( J.getItem().factor(),r ),r))
1124  {
1125  if (w!=NULL)
1126  (*w)[j]=1;
1127  res->m[j]=p_One(r);
1128  }
1129 #endif
1130  }
1131  else
1132  {
1133 #ifdef SING_NDEBUG
1134  res->m[j]= convFactoryAPSingAP( J.getItem().factor(),r );
1135 #else
1136  if (!count_Factors(res,w,j,ff,convFactoryAPSingAP( J.getItem().factor(),r ),r))
1137  {
1138  if (w!=NULL)
1139  (*w)[j]=1;
1140  res->m[j]=p_One(r);
1141  }
1142 #endif
1143  }
1144  }
1145  }
1146  if (r->cf->extRing!=NULL)
1147  if (r->cf->extRing->qideal!=NULL)
1148  prune (a);
1149 #ifndef SING_NDEBUG
1150  if ((r->cf->extRing!=NULL) && (!p_IsConstant(ff,r)))
1151  {
1154  {
1155  int jj;
1156 #ifdef FACTORIZE2_DEBUG
1157  printf("factorize_retry\n");
1158 #endif
1159  intvec *ww=NULL;
1160  id_Test(res,r);
1161  ideal h=singclap_factorize ( ff, &ww , with_exps, r );
1162  id_Test(h,r);
1163  int l=(*v)->length();
1164  (*v)->resize(l+ww->length());
1165  for(jj=0;jj<ww->length();jj++)
1166  (**v)[jj+l]=(*ww)[jj];
1167  delete ww;
1168  ideal hh=idInit(IDELEMS(res)+IDELEMS(h),1);
1169  for(jj=IDELEMS(res)-1;jj>=0;jj--)
1170  {
1171  hh->m[jj]=res->m[jj];
1172  res->m[jj]=NULL;
1173  }
1174  for(jj=IDELEMS(h)-1;jj>=0;jj--)
1175  {
1176  hh->m[jj+IDELEMS(res)]=h->m[jj];
1177  h->m[jj]=NULL;
1178  }
1179  id_Delete(&res,r);
1180  id_Delete(&h,r);
1181  res=hh;
1182  id_Test(res,r);
1183  ff=NULL;
1184  }
1185  else
1186  {
1187  WarnS("problem with factorize");
1188 #if 0
1189  pWrite(ff);
1190  idShow(res);
1191 #endif
1192  id_Delete(&res,r);
1193  res=idInit(2,1);
1194  res->m[0]=p_One(r);
1195  res->m[1]=ff; ff=NULL;
1196  }
1197  }
1198 #endif
1199  p_Delete(&ff,r);
1200  if (N!=NULL)
1201  {
1202  __p_Mult_nn(res->m[0],N,r);
1203  n_Delete(&N,r->cf);
1204  N=NULL;
1205  }
1206  // delete constants
1207  if (res!=NULL)
1208  {
1209  int i=IDELEMS(res)-1;
1210  int j=0;
1211  for(;i>=0;i--)
1212  {
1213  if ((res->m[i]!=NULL)
1214  && (pNext(res->m[i])==NULL)
1215  && (p_IsConstant(res->m[i],r)))
1216  {
1217  if (with_exps!=0)
1218  {
1219  p_Delete(&(res->m[i]),r);
1220  if ((v!=NULL) && ((*v)!=NULL))
1221  (**v)[i]=0;
1222  j++;
1223  }
1224  else if (i!=0)
1225  {
1226  while ((v!=NULL) && ((*v)!=NULL) && ((**v)[i]>1))
1227  {
1228  res->m[0]=p_Mult_q(res->m[0],p_Copy(res->m[i],r),r);
1229  (**v)[i]--;
1230  }
1231  res->m[0]=p_Mult_q(res->m[0],res->m[i],r);
1232  res->m[i]=NULL;
1233  if ((v!=NULL) && ((*v)!=NULL))
1234  (**v)[i]=1;
1235  j++;
1236  }
1237  }
1238  }
1239  if (j>0)
1240  {
1241  idSkipZeroes(res);
1242  if ((v!=NULL) && ((*v)!=NULL))
1243  {
1244  intvec *w=*v;
1245  int len=IDELEMS(res);
1246  *v = new intvec( len );
1247  for (i=0,j=0;i<si_min(w->length(),len);i++)
1248  {
1249  if((*w)[i]!=0)
1250  {
1251  (**v)[j]=(*w)[i]; j++;
1252  }
1253  }
1254  delete w;
1255  }
1256  }
1257  if (res->m[0]==NULL)
1258  {
1259  res->m[0]=p_One(r);
1260  }
1261  }
1262  }
1263  if (rField_is_Q_a(r) && (r->cf->extRing->qideal!=NULL))
1264  {
1265  int i=IDELEMS(res)-1;
1266  int stop=1;
1267  if (with_exps!=0) stop=0;
1268  for(;i>=stop;i--)
1269  {
1270  p_Norm(res->m[i],r);
1271  }
1272  if (with_exps==0) p_SetCoeff(res->m[0],old_lead_coeff,r);
1273  else n_Delete(&old_lead_coeff,r->cf);
1274  }
1275  else
1276  n_Delete(&old_lead_coeff,r->cf);
1277  errorreported=save_errorreported;
1278 notImpl:
1279  prune(a);
1280  if (res==NULL)
1281  {
1283  if ((v!=NULL) && ((*v)!=NULL) &&(with_exps==2))
1284  {
1285  *v = new intvec( 1 );
1286  (*v)[0]=1;
1287  }
1288  res=idInit(2,1);
1289  res->m[0]=p_One(r);
1290  res->m[1]=f;
1291  }
1292  else p_Delete(&f,r);
1293  if (NN!=NULL)
1294  {
1295  n_Delete(&NN,r->cf);
1296  }
1297  if (N!=NULL)
1298  {
1299  n_Delete(&N,r->cf);
1300  }
1301  return res;
1302 }
static int si_max(const int a, const int b)
Definition: auxiliary.h:124
static int si_min(const int a, const int b)
Definition: auxiliary.h:125
Factor< CanonicalForm > CFFactor
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:56
CFFList FACTORY_PUBLIC factorize(const CanonicalForm &f, bool issqrfree=false)
factorization over or
Definition: cf_factor.cc:405
BOOLEAN count_Factors(ideal I, intvec *v, int j, poly &f, poly fac, const ring r)
Definition: clapsing.cc:824
ideal singclap_factorize(poly f, intvec **v, int with_exps, const ring r)
Definition: clapsing.cc:914
VAR int singclap_factorize_retry
Definition: clapsing.cc:912
T getFirst() const
Definition: ftmpl_list.cc:279
void insert(const T &)
Definition: ftmpl_list.cc:193
int length() const
Definition: intvec.h:94
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
Definition: coeffs.h:452
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of 'a' and 'b', i.e., a/b; raises an error if 'b' is not invertible in r exceptio...
Definition: coeffs.h:616
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:456
#define WarnS
Definition: emacs.cc:78
const CanonicalForm & w
Definition: facAbsFact.cc:51
VAR short errorreported
Definition: feFopen.cc:23
STATIC_VAR Poly * h
Definition: janet.cc:971
#define pNext(p)
Definition: monomials.h:36
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
Definition: monomials.h:44
void p_Content(poly ph, const ring r)
Definition: p_polys.cc:2282
void p_Norm(poly p1, const ring r)
Definition: p_polys.cc:3789
poly p_Cleardenom(poly p, const ring r)
Definition: p_polys.cc:2900
poly p_One(const ring r)
Definition: p_polys.cc:1308
poly p_NSet(number n, const ring r)
returns the poly representing the number n, destroys n
Definition: p_polys.cc:1460
static poly p_Mult_q(poly p, poly q, const ring r)
Definition: p_polys.h:1074
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent @Note: VarOffset encodes the position in p->exp
Definition: p_polys.h:488
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:233
static number p_SetCoeff(poly p, number n, ring r)
Definition: p_polys.h:412
#define __p_Mult_nn(p, n, r)
Definition: p_polys.h:931
void pWrite(poly p)
Definition: polys.h:308
static BOOLEAN rField_is_Zp_a(const ring r)
Definition: ring.h:534
static BOOLEAN rField_is_Z(const ring r)
Definition: ring.h:514
static BOOLEAN rField_is_GF(const ring r)
Definition: ring.h:526
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:597
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)
Definition: simpleideals.cc:57
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
#define IDELEMS(i)
Definition: simpleideals.h:23
#define id_Test(A, lR)
Definition: simpleideals.h:78

◆ singclap_gcd_and_divide()

poly singclap_gcd_and_divide ( poly &  f,
poly &  g,
const ring  r 
)

clears denominators of f and g, divides by gcd(f,g)

Definition at line 136 of file clapsing.cc.

137 {
138  poly res=NULL;
139 
140  if (g == NULL)
141  {
142  res= f;
143  f=p_One (r);
144  return res;
145  }
146  if (f==NULL)
147  {
148  res= g;
149  g=p_One (r);
150  return res;
151  }
152  if (pNext(g)==NULL)
153  {
154  poly G=p_GcdMon(g,f,r);
155  if (!n_IsOne(pGetCoeff(G),r->cf)
156  || (!p_IsConstant(G,r)))
157  {
158  f=p_Div_mm(f,G,r);
159  g=p_Div_mm(g,G,r);
160  }
161  return G;
162  }
163  else if (pNext(f)==NULL)
164  {
165  poly G=p_GcdMon(f,g,r);
166  if (!n_IsOne(pGetCoeff(G),r->cf)
167  || (!p_IsConstant(G,r)))
168  {
169  f=p_Div_mm(f,G,r);
170  g=p_Div_mm(g,G,r);
171  }
172  return G;
173  }
174 
175  Off(SW_RATIONAL);
176  CanonicalForm F,G,GCD;
177  if (rField_is_Q(r) || (rField_is_Zp(r))
178  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
179  {
180  bool b1=isOn(SW_USE_EZGCD_P);
181  setCharacteristic( rChar(r) );
182  F=convSingPFactoryP( f,r );
183  G=convSingPFactoryP( g,r );
184  GCD=gcd(F,G);
185  if (!GCD.isOne())
186  {
187  p_Delete(&f,r);
188  p_Delete(&g,r);
189  if (getCharacteristic() == 0)
190  On (SW_RATIONAL);
191  F /= GCD;
192  G /= GCD;
193  if (getCharacteristic() == 0)
194  {
195  CanonicalForm denF= bCommonDen (F);
196  CanonicalForm denG= bCommonDen (G);
197  G *= denG;
198  F *= denF;
199  Off (SW_RATIONAL);
200  CanonicalForm gcddenFdenG= gcd (denG, denF);
201  denG /= gcddenFdenG;
202  denF /= gcddenFdenG;
203  On (SW_RATIONAL);
204  G *= denF;
205  F *= denG;
206  }
207  f=convFactoryPSingP( F, r);
208  g=convFactoryPSingP( G, r);
209  }
210  res=convFactoryPSingP( GCD , r);
211  if (!b1) Off (SW_USE_EZGCD_P);
212  }
213  // and over Q(a) / Fp(a)
214  else if ( r->cf->extRing )
215  {
216  if ( rField_is_Q_a(r)) setCharacteristic( 0 );
217  else setCharacteristic( rChar(r) );
218  if (r->cf->extRing->qideal!=NULL)
219  {
220  bool b1=isOn(SW_USE_QGCD);
221  if ( rField_is_Q_a(r) ) On(SW_USE_QGCD);
222  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
223  r->cf->extRing);
224  Variable a=rootOf(mipo);
225  F=( convSingAPFactoryAP( f,a,r ) );
226  G=( convSingAPFactoryAP( g,a,r ) );
227  GCD=gcd(F,G);
228  if (!GCD.isOne())
229  {
230  p_Delete(&f,r);
231  p_Delete(&g,r);
232  if (getCharacteristic() == 0)
233  On (SW_RATIONAL);
234  F /= GCD;
235  G /= GCD;
236  if (getCharacteristic() == 0)
237  {
238  CanonicalForm denF= bCommonDen (F);
239  CanonicalForm denG= bCommonDen (G);
240  G *= denG;
241  F *= denF;
242  Off (SW_RATIONAL);
243  CanonicalForm gcddenFdenG= gcd (denG, denF);
244  denG /= gcddenFdenG;
245  denF /= gcddenFdenG;
246  On (SW_RATIONAL);
247  G *= denF;
248  F *= denG;
249  }
250  f= convFactoryAPSingAP( F,r );
251  g= convFactoryAPSingAP( G,r );
252  }
253  res= convFactoryAPSingAP( GCD,r );
254  prune (a);
255  if (!b1) Off(SW_USE_QGCD);
256  }
257  else
258  {
259  F=( convSingTrPFactoryP( f,r ) );
260  G=( convSingTrPFactoryP( g,r ) );
261  GCD=gcd(F,G);
262  if (!GCD.isOne())
263  {
264  p_Delete(&f,r);
265  p_Delete(&g,r);
266  if (getCharacteristic() == 0)
267  On (SW_RATIONAL);
268  F /= GCD;
269  G /= GCD;
270  if (getCharacteristic() == 0)
271  {
272  CanonicalForm denF= bCommonDen (F);
273  CanonicalForm denG= bCommonDen (G);
274  G *= denG;
275  F *= denF;
276  Off (SW_RATIONAL);
277  CanonicalForm gcddenFdenG= gcd (denG, denF);
278  denG /= gcddenFdenG;
279  denF /= gcddenFdenG;
280  On (SW_RATIONAL);
281  G *= denF;
282  F *= denG;
283  }
284  f= convFactoryPSingTrP( F,r );
285  g= convFactoryPSingTrP( G,r );
286  }
287  res= convFactoryPSingTrP( GCD,r );
288  }
289  }
290  else
292  Off(SW_RATIONAL);
293  return res;
294 }
int FACTORY_PUBLIC getCharacteristic()
Definition: cf_char.cc:70
static const int SW_USE_QGCD
set to 1 to use Encarnacion GCD over Q(a)
Definition: cf_defs.h:42
static const int SW_USE_EZGCD_P
set to 1 to use EZGCD over F_q
Definition: cf_defs.h:36
CF_NO_INLINE bool isOne() const
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
Definition: coeffs.h:469
poly p_GcdMon(poly f, poly g, const ring r)
polynomial gcd for f=mon
Definition: p_polys.cc:4966
poly p_Div_mm(poly p, const poly m, const ring r)
divide polynomial by monomial
Definition: p_polys.cc:1525
int gcd(int a, int b)
Definition: walkSupport.cc:836

◆ singclap_gcd_r()

poly singclap_gcd_r ( poly  f,
poly  g,
const ring  r 
)

Definition at line 45 of file clapsing.cc.

46 {
47  poly res=NULL;
48 
49  assume(f!=NULL);
50  assume(g!=NULL);
51 
52  if(pNext(f)==NULL)
53  {
54  return p_GcdMon(f,g,r);
55  }
56  else if(pNext(g)==NULL)
57  {
58  return p_GcdMon(g,f,r);
59  }
60  #ifdef HAVE_FLINT
61  #if __FLINT_RELEASE >= 20503
62  if (rField_is_Zp(r) && (r->cf->ch>10))
63  {
64  nmod_mpoly_ctx_t ctx;
65  if (!convSingRFlintR(ctx,r))
66  {
67  // leading coef. 1
68  return Flint_GCD_MP(f,pLength(f),g,pLength(g),ctx,r);
69  }
70  }
71  else
72  if (rField_is_Q(r))
73  {
74  fmpq_mpoly_ctx_t ctx;
75  if (!convSingRFlintR(ctx,r))
76  {
77  // leading coef. positive, all coeffs in Z
78  poly res=Flint_GCD_MP(f,pLength(f),g,pLength(g),ctx,r);
79  res=p_Cleardenom(res,r);
80  return res;
81  }
82  }
83  #endif
84  #endif
86  if (rField_is_Q(r) || rField_is_Zp(r) || rField_is_Z(r)
87  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
88  {
91  res=convFactoryPSingP( gcd( F, G ) , r);
92  if ( rField_is_Zp(r))
93  p_Norm(res,r); // leading coef. 1
94  else if (rField_is_Q(r) && (!n_GreaterZero(pGetCoeff(res),r->cf)))
95  res = p_Neg(res,r); // leading coef. positive, all coeffs in Z
96  }
97  // and over Q(a) / Fp(a)
98  else if ( r->cf->extRing!=NULL )
99  {
100  if ( rField_is_Q_a(r)) setCharacteristic( 0 );
101  else setCharacteristic( rChar(r) );
102  if (r->cf->extRing->qideal!=NULL)
103  {
104  bool b1=isOn(SW_USE_QGCD);
105  if ( rField_is_Q_a(r) ) On(SW_USE_QGCD);
106  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
107  r->cf->extRing);
108  Variable a=rootOf(mipo);
109  CanonicalForm F( convSingAPFactoryAP( f,a,r ) ),
110  G( convSingAPFactoryAP( g,a,r ) );
111  res= convFactoryAPSingAP( gcd( F, G ),r );
112  prune (a);
113  if (!b1) Off(SW_USE_QGCD);
114  if ( rField_is_Zp_a(r)) p_Norm(res,r); // leading coef. 1
115  }
116  else
117  {
118  convSingTrP(f,r);
119  convSingTrP(g,r);
121  res= convFactoryPSingTrP( gcd( F, G ),r );
122  }
123  }
124  else if (r->cf->convSingNFactoryN==ndConvSingNFactoryN)
126  else
127  { // handle user type coeffs:
128  setCharacteristic( rChar(r) );
130  res=convFactoryPSingP( gcd( F, G ) , r);
131  }
132  Off(SW_RATIONAL);
133  return res;
134 }
BOOLEAN convSingTrP(poly p, const ring r)
Definition: clapconv.cc:352
static FORCE_INLINE BOOLEAN n_GreaterZero(number n, const coeffs r)
ordered fields: TRUE iff 'n' is positive; in Z/pZ: TRUE iff 0 < m <= roundedBelow(p/2),...
Definition: coeffs.h:495
static poly p_Neg(poly p, const ring r)
Definition: p_polys.h:1067
static unsigned pLength(poly a)
Definition: p_polys.h:191

◆ singclap_irrCharSeries()

matrix singclap_irrCharSeries ( ideal  I,
const ring  r 
)

Definition at line 1537 of file clapsing.cc.

1538 {
1539  if (idIs0(I)) return mpNew(1,1);
1540 
1541  // for now there is only the possibility to handle polynomials over
1542  // Q and Fp ...
1543  matrix res=NULL;
1544  int i;
1545  Off(SW_RATIONAL);
1547  CFList L;
1548  ListCFList LL;
1549  if (rField_is_Q(r) || rField_is_Zp(r)
1550  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
1551  {
1552  setCharacteristic( rChar(r) );
1553  for(i=0;i<IDELEMS(I);i++)
1554  {
1555  poly p=I->m[i];
1556  if (p!=NULL)
1557  {
1558  p=p_Copy(p,r);
1559  p_Cleardenom(p, r);
1560  L.append(convSingPFactoryP(p,r));
1561  p_Delete(&p,r);
1562  }
1563  }
1564  }
1565  // and over Q(a) / Fp(a)
1566  else if (nCoeff_is_transExt (r->cf))
1567  {
1568  setCharacteristic( rChar(r) );
1569  for(i=0;i<IDELEMS(I);i++)
1570  {
1571  poly p=I->m[i];
1572  if (p!=NULL)
1573  {
1574  p=p_Copy(p,r);
1575  p_Cleardenom(p, r);
1577  p_Delete(&p,r);
1578  }
1579  }
1580  }
1581  else
1582  {
1584  return res;
1585  }
1586 
1587  // a very bad work-around --- FIX IT in libfac
1588  // should be fixed as of 2001/6/27
1589  int tries=0;
1590  int m,n;
1592  loop
1593  {
1594  LL=irrCharSeries(L);
1595  m= LL.length(); // Anzahl Zeilen
1596  n=0;
1597  for ( LLi = LL; LLi.hasItem(); LLi++ )
1598  {
1599  n = si_max(LLi.getItem().length(),n);
1600  }
1601  if ((m!=0) && (n!=0)) break;
1602  tries++;
1603  if (tries>=5) break;
1604  }
1605  if ((m==0) || (n==0))
1606  {
1607  Warn("char_series returns %d x %d matrix from %d input polys (%d)",
1608  m,n,IDELEMS(I)+1,LL.length());
1609  iiWriteMatrix((matrix)I,"I",2,r,0);
1610  m=si_max(m,1);
1611  n=si_max(n,1);
1612  }
1613  res=mpNew(m,n);
1614  CFListIterator Li;
1615  for ( m=1, LLi = LL; LLi.hasItem(); LLi++, m++ )
1616  {
1617  for (n=1, Li = LLi.getItem(); Li.hasItem(); Li++, n++)
1618  {
1619  if (rField_is_Q(r) || rField_is_Zp(r)
1620  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
1621  MATELEM(res,m,n)=convFactoryPSingP(Li.getItem(),r);
1622  else
1624  }
1625  }
1626  Off(SW_RATIONAL);
1627  return res;
1628 }
ListCFList irrCharSeries(const CFList &PS)
irreducible characteristic series
Definition: cfCharSets.cc:568
void append(const T &)
Definition: ftmpl_list.cc:256
static FORCE_INLINE BOOLEAN nCoeff_is_transExt(const coeffs r)
TRUE iff r represents a transcendental extension field.
Definition: coeffs.h:942
#define Warn
Definition: emacs.cc:77
BOOLEAN idIs0(ideal h)
returns true if h is the zero ideal
matrix mpNew(int r, int c)
create a r x c zero-matrix
Definition: matpol.cc:37
void iiWriteMatrix(matrix im, const char *n, int dim, const ring r, int spaces)
set spaces to zero by default
Definition: matpol.cc:834

◆ singclap_neworder()

char* singclap_neworder ( ideal  I,
const ring  r 
)

Definition at line 1630 of file clapsing.cc.

1631 {
1632  int i;
1633  Off(SW_RATIONAL);
1635  CFList L;
1636  if (rField_is_Q(r) || rField_is_Zp(r)
1637  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
1638  {
1639  setCharacteristic( rChar(r) );
1640  for(i=0;i<IDELEMS(I);i++)
1641  {
1642  poly p=I->m[i];
1643  if (p!=NULL)
1644  {
1645  p=p_Copy(p,r);
1646  p_Cleardenom(p, r);
1647  L.append(convSingPFactoryP(p,r));
1648  }
1649  }
1650  }
1651  // and over Q(a) / Fp(a)
1652  else if (nCoeff_is_transExt (r->cf))
1653  {
1654  setCharacteristic( rChar(r) );
1655  for(i=0;i<IDELEMS(I);i++)
1656  {
1657  poly p=I->m[i];
1658  if (p!=NULL)
1659  {
1660  p=p_Copy(p,r);
1661  p_Cleardenom(p, r);
1663  }
1664  }
1665  }
1666  else
1667  {
1669  return NULL;
1670  }
1671 
1672  List<int> IL=neworderint(L);
1673  ListIterator<int> Li;
1674  StringSetS("");
1675  Li = IL;
1676  int offs=rPar(r);
1677  int* mark=(int*)omAlloc0((rVar(r)+offs)*sizeof(int));
1678  int cnt=rVar(r)+offs;
1679  loop
1680  {
1681  if(! Li.hasItem()) break;
1682  BOOLEAN done=TRUE;
1683  i=Li.getItem()-1;
1684  mark[i]=1;
1685  if (i<offs)
1686  {
1687  done=FALSE;
1688  //StringAppendS(r->parameter[i]);
1689  }
1690  else
1691  {
1692  StringAppendS(r->names[i-offs]);
1693  }
1694  Li++;
1695  cnt--;
1696  if(cnt==0) break;
1697  if (done) StringAppendS(",");
1698  }
1699  for(i=0;i<rVar(r)+offs;i++)
1700  {
1701  BOOLEAN done=TRUE;
1702  if(mark[i]==0)
1703  {
1704  if (i<offs)
1705  {
1706  done=FALSE;
1707  //StringAppendS(r->parameter[i]);
1708  }
1709  else
1710  {
1711  StringAppendS(r->names[i-offs]);
1712  }
1713  cnt--;
1714  if(cnt==0) break;
1715  if (done) StringAppendS(",");
1716  }
1717  }
1718  char * s=StringEndS();
1719  if (s[strlen(s)-1]==',') s[strlen(s)-1]='\0';
1720  return s;
1721 }
IntList neworderint(const CFList &PolyList)
Definition: cfCharSets.cc:88
#define omAlloc0(size)
Definition: omAllocDecl.h:211
std::pair< int, int > mark
void StringSetS(const char *st)
Definition: reporter.cc:128
void StringAppendS(const char *st)
Definition: reporter.cc:107
char * StringEndS()
Definition: reporter.cc:151

◆ singclap_pdivide()

poly singclap_pdivide ( poly  f,
poly  g,
const ring  r 
)

Definition at line 590 of file clapsing.cc.

591 {
592  poly res=NULL;
593 
594  #ifdef HAVE_FLINT
595  #if __FLINT_RELEASE >= 20503
596  /*
597  If the division is not exact, control will pass to factory where the
598  polynomials can be divided using the ordering that factory chooses.
599  */
600  if (rField_is_Zp(r))
601  {
602  nmod_mpoly_ctx_t ctx;
603  if (!convSingRFlintR(ctx,r))
604  {
605  res = Flint_Divide_MP(f,0,g,0,ctx,r);
606  if (res != NULL)
607  return res;
608  }
609  }
610  else
611  if (rField_is_Q(r))
612  {
613  fmpq_mpoly_ctx_t ctx;
614  if (!convSingRFlintR(ctx,r))
615  {
616  res = Flint_Divide_MP(f,0,g,0,ctx,r);
617  if (res != NULL)
618  return res;
619  }
620  }
621  #endif
622  #endif
623 
624  On(SW_RATIONAL);
625  if (rField_is_Zp(r) || rField_is_Q(r)
626  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
627  {
628  setCharacteristic( rChar(r) );
630  res = convFactoryPSingP( F / G,r );
631  }
632  // div is not implemented for ZZ coeffs in factory
633  else if (r->cf->extRing!=NULL)
634  {
635  if (rField_is_Q_a(r)) setCharacteristic( 0 );
636  else setCharacteristic( rChar(r) );
637  if (r->cf->extRing->qideal!=NULL)
638  {
639  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
640  r->cf->extRing);
641  Variable a=rootOf(mipo);
642  CanonicalForm F( convSingAPFactoryAP( f,a,r ) ),
643  G( convSingAPFactoryAP( g,a,r ) );
644  res= convFactoryAPSingAP( F / G, r );
645  prune (a);
646  }
647  else
648  {
650  res= convFactoryPSingTrP( F / G,r );
651  }
652  }
653 #if 0 // not yet working
654  else if (rField_is_GF())
655  {
656  //Print("GF(%d^%d)\n",nfCharP,nfMinPoly[0]);
657  setCharacteristic( nfCharP,nfMinPoly[0], currRing->parameter[0][0] );
658  CanonicalForm F( convSingGFFactoryGF( f ) ), G( convSingGFFactoryGF( g ) );
659  res = convFactoryGFSingGF( F / G );
660  }
661 #endif
662  else
664  Off(SW_RATIONAL);
665  return res;
666 }
STATIC_VAR int nfMinPoly[16]
Definition: ffields.cc:549
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13

◆ singclap_pmod()

poly singclap_pmod ( poly  f,
poly  g,
const ring  r 
)

Definition at line 668 of file clapsing.cc.

669 {
670  poly res=NULL;
671  On(SW_RATIONAL);
672  if (rField_is_Zp(r) || rField_is_Q(r)
673  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
674  {
675  setCharacteristic( rChar(r) );
677  CanonicalForm Q,R;
678  divrem(F,G,Q,R);
679  res = convFactoryPSingP(R,r);
680  //res = convFactoryPSingP( F-(F/G)*G,r );
681  }
682  // mod is not implemented for ZZ coeffs in factory
683  else if (r->cf->extRing!=NULL)
684  {
685  if (rField_is_Q_a(r)) setCharacteristic( 0 );
686  else setCharacteristic( rChar(r) );
687  if (r->cf->extRing->qideal!=NULL)
688  {
689  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
690  r->cf->extRing);
691  Variable a=rootOf(mipo);
692  CanonicalForm F( convSingAPFactoryAP( f,a,r ) ),
693  G( convSingAPFactoryAP( g,a,r ) );
694  CanonicalForm Q,R;
695  divrem(F,G,Q,R);
697  //res= convFactoryAPSingAP( F-(F/G)*G, r );
698  prune (a);
699  }
700  else
701  {
703  CanonicalForm Q,R;
704  divrem(F,G,Q,R);
706  //res= convFactoryPSingTrP( F-(F/G)*G,r );
707  }
708  }
709 #if 0 // not yet working
710  else if (rField_is_GF())
711  {
712  //Print("GF(%d^%d)\n",nfCharP,nfMinPoly[0]);
713  setCharacteristic( nfCharP,nfMinPoly[0], currRing->parameter[0][0] );
714  CanonicalForm F( convSingGFFactoryGF( f ) ), G( convSingGFFactoryGF( g ) );
715  res = convFactoryGFSingGF( F / G );
716  }
717 #endif
718  else
720  Off(SW_RATIONAL);
721  return res;
722 }
void divrem(const CanonicalForm &f, const CanonicalForm &g, CanonicalForm &q, CanonicalForm &r)

◆ singclap_pmult()

poly singclap_pmult ( poly  f,
poly  g,
const ring  r 
)

Definition at line 543 of file clapsing.cc.

544 {
545  poly res=NULL;
546  On(SW_RATIONAL);
547  if (rField_is_Zp(r) || rField_is_Q(r) || rField_is_Z(r)
548  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
549  {
550  if (rField_is_Z(r)) Off(SW_RATIONAL);
551  setCharacteristic( rChar(r) );
553  res = convFactoryPSingP( F * G,r );
554  }
555  else if (r->cf->extRing!=NULL)
556  {
557  if (rField_is_Q_a(r)) setCharacteristic( 0 );
558  else setCharacteristic( rChar(r) );
559  if (r->cf->extRing->qideal!=NULL)
560  {
561  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
562  r->cf->extRing);
563  Variable a=rootOf(mipo);
564  CanonicalForm F( convSingAPFactoryAP( f,a,r ) ),
565  G( convSingAPFactoryAP( g,a,r ) );
566  res= convFactoryAPSingAP( F * G, r );
567  prune (a);
568  }
569  else
570  {
572  res= convFactoryPSingTrP( F * G,r );
573  }
574  }
575 #if 0 // not yet working
576  else if (rField_is_GF())
577  {
578  //Print("GF(%d^%d)\n",nfCharP,nfMinPoly[0]);
579  setCharacteristic( nfCharP,nfMinPoly[0], currRing->parameter[0][0] );
580  CanonicalForm F( convSingGFFactoryGF( f ) ), G( convSingGFFactoryGF( g ) );
581  res = convFactoryGFSingGF( F * G );
582  }
583 #endif
584  else
586  Off(SW_RATIONAL);
587  return res;
588 }

◆ singclap_resultant()

poly singclap_resultant ( poly  f,
poly  g,
poly  x,
const ring  r 
)

Definition at line 311 of file clapsing.cc.

312 {
313  poly res=NULL;
314  int i=p_IsPurePower(x, r);
315  if (i==0)
316  {
317  WerrorS("3rd argument must be a ring variable");
318  goto resultant_returns_res;
319  }
320  if ((f==NULL) || (g==NULL))
321  goto resultant_returns_res;
322  // for now there is only the possibility to handle polynomials over
323  // Q and Fp ...
324  if (rField_is_Zp(r) || rField_is_Q(r)
325  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
326  {
327  Variable X(i);
328  setCharacteristic( rChar(r) );
330  res=convFactoryPSingP( resultant( F, G, X),r );
331  Off(SW_RATIONAL);
332  goto resultant_returns_res;
333  }
334  // and over Q(a) / Fp(a)
335  else if (r->cf->extRing!=NULL)
336  {
337  if (rField_is_Q_a(r)) setCharacteristic( 0 );
338  else setCharacteristic( rChar(r) );
339  Variable X(i+rPar(r));
340  if (r->cf->extRing->qideal!=NULL)
341  {
342  //Variable X(i);
343  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
344  r->cf->extRing);
345  Variable a=rootOf(mipo);
346  CanonicalForm F( convSingAPFactoryAP( f,a,r ) ),
347  G( convSingAPFactoryAP( g,a,r ) );
348  res= convFactoryAPSingAP( resultant( F, G, X ),r );
349  prune (a);
350  }
351  else
352  {
353  //Variable X(i+rPar(currRing));
354  number nf,ng;
356  int ef,eg;
357  ef=pGetExp_Var(f,i,r);
358  eg=pGetExp_Var(g,i,r);
360  res= convFactoryPSingTrP( resultant( F, G, X ),r );
361  if ((nf!=NULL)&&(!n_IsOne(nf,r->cf)))
362  {
363  number n=n_Invers(nf,r->cf);
364  while(eg>0)
365  {
366  res=__p_Mult_nn(res,n,r);
367  eg--;
368  }
369  n_Delete(&n,r->cf);
370  }
371  n_Delete(&nf,r->cf);
372  if ((ng!=NULL)&&(!n_IsOne(ng,r->cf)))
373  {
374  number n=n_Invers(ng,r->cf);
375  while(ef>0)
376  {
377  res=__p_Mult_nn(res,n,r);
378  ef--;
379  }
380  n_Delete(&n,r->cf);
381  }
382  n_Delete(&ng,r->cf);
383  }
384  Off(SW_RATIONAL);
385  goto resultant_returns_res;
386  }
387  else
389 resultant_returns_res:
390  p_Delete(&f,r);
391  p_Delete(&g,r);
392  p_Delete(&x,r);
393  return res;
394 }
CanonicalForm FACTORY_PUBLIC resultant(const CanonicalForm &f, const CanonicalForm &g, const Variable &x)
CanonicalForm resultant ( const CanonicalForm & f, const CanonicalForm & g, const Variable & x )
int pGetExp_Var(poly p, int i, const ring r)
Definition: clapsing.cc:297
static FORCE_INLINE number n_Invers(number a, const coeffs r)
return the multiplicative inverse of 'a'; raise an error if 'a' is not invertible
Definition: coeffs.h:565
int p_IsPurePower(const poly p, const ring r)
return i, if head depends only on var(i)
Definition: p_polys.cc:1221
void p_Cleardenom_n(poly ph, const ring r, number &c)
Definition: p_polys.cc:3009
Definition: gnumpfl.cc:27

◆ singclap_sqrfree()

ideal singclap_sqrfree ( poly  f,
intvec **  v,
int  with_exps,
const ring  r 
)

Definition at line 1304 of file clapsing.cc.

1305 {
1306  p_Test(f,r);
1307 #ifdef FACTORIZE2_DEBUG
1308  printf("singclap_sqrfree, degree %d\n",pTotaldegree(f));
1309 #endif
1310  // with_exps: 3,1 return only true factors, no exponents
1311  // 2 return true factors and exponents
1312  // 0 return coeff, factors and exponents
1313  BOOLEAN save_errorreported=errorreported;
1314 
1315  ideal res=NULL;
1316 
1317  // handle factorize(0) =========================================
1318  if (f==NULL)
1319  {
1320  res=idInit(1,1);
1321  if (with_exps!=1 && with_exps!=3)
1322  {
1323  (*v)=new intvec(1);
1324  (**v)[0]=1;
1325  }
1326  return res;
1327  }
1328  // handle factorize(mon) =========================================
1329  if (pNext(f)==NULL)
1330  {
1331  int i=0;
1332  int n=0;
1333  int e;
1334  for(i=rVar(r);i>0;i--) if(p_GetExp(f,i,r)!=0) n++;
1335  if (with_exps==0 || with_exps==3) n++; // with coeff
1336  res=idInit(si_max(n,1),1);
1337  if(with_exps!=1)
1338  {
1339  (*v)=new intvec(si_max(1,n));
1340  (**v)[0]=1;
1341  }
1342  res->m[0]=p_NSet(n_Copy(pGetCoeff(f),r->cf),r);
1343  if (n==0)
1344  {
1345  res->m[0]=p_One(r);
1346  // (**v)[0]=1; is already done
1347  }
1348  else
1349  {
1350  for(i=rVar(r);i>0;i--)
1351  {
1352  e=p_GetExp(f,i,r);
1353  if(e!=0)
1354  {
1355  n--;
1356  poly p=p_One(r);
1357  p_SetExp(p,i,1,r);
1358  p_Setm(p,r);
1359  res->m[n]=p;
1360  if (with_exps!=1) (**v)[n]=e;
1361  }
1362  }
1363  }
1364  p_Delete(&f,r);
1365  return res;
1366  }
1367  //PrintS("S:");pWrite(f);PrintLn();
1368  // use factory/libfac in general ==============================
1369  Off(SW_RATIONAL);
1371  CFFList L;
1372  number N=NULL;
1373  number NN=NULL;
1374  number old_lead_coeff=n_Copy(pGetCoeff(f), r->cf);
1375  Variable a;
1376 
1377  if (!rField_is_Zp(r) && !rField_is_Zp_a(r)) /* Q, Q(a) */
1378  {
1379  //if (f!=NULL) // already tested at start of routine
1380  number n0=n_Copy(old_lead_coeff,r->cf);
1381  if (with_exps==0 || with_exps==3)
1382  N=n_Copy(n0,r->cf);
1383  p_Cleardenom(f, r);
1384  //after here f should not have a denominator!!
1385  //PrintS("S:");p_Write(f,r);PrintLn();
1386  NN=n_Div(n0,pGetCoeff(f),r->cf);
1387  n_Delete(&n0,r->cf);
1388  if (with_exps==0 || with_exps==3)
1389  {
1390  n_Delete(&N,r->cf);
1391  N=n_Copy(NN,r->cf);
1392  }
1393  }
1394  else if (rField_is_Zp_a(r))
1395  {
1396  //if (f!=NULL) // already tested at start of routine
1397  if (singclap_factorize_retry==0)
1398  {
1399  number n0=n_Copy(old_lead_coeff,r->cf);
1400  if (with_exps==0 || with_exps==3)
1401  N=n_Copy(n0,r->cf);
1402  p_Norm(f,r);
1403  p_Cleardenom(f, r);
1404  NN=n_Div(n0,pGetCoeff(f),r->cf);
1405  n_Delete(&n0,r->cf);
1406  if (with_exps==0 || with_exps==3)
1407  {
1408  n_Delete(&N,r->cf);
1409  N=n_Copy(NN,r->cf);
1410  }
1411  }
1412  }
1413  if (rField_is_Q(r) || rField_is_Zp(r)
1414  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
1415  {
1416  setCharacteristic( rChar(r) );
1417  CanonicalForm F( convSingPFactoryP( f,r ) );
1418  L = sqrFree( F );
1419  }
1420  else if (r->cf->extRing!=NULL)
1421  {
1422  if (rField_is_Q_a (r)) setCharacteristic (0);
1423  else setCharacteristic( rChar(r) );
1424  if (r->cf->extRing->qideal!=NULL)
1425  {
1426  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
1427  r->cf->extRing);
1428  a=rootOf(mipo);
1429  CanonicalForm F( convSingAPFactoryAP( f, a, r ) );
1430  L= sqrFree (F);
1431  }
1432  else
1433  {
1435  L = sqrFree( F );
1436  }
1437  }
1438  #if 0
1439  else if (rField_is_GF())
1440  {
1441  int c=rChar(r);
1442  setCharacteristic( c, primepower(c) );
1443  CanonicalForm F( convSingGFFactoryGF( f ) );
1444  if (F.isUnivariate())
1445  {
1446  L = factorize( F );
1447  }
1448  else
1449  {
1450  goto notImpl;
1451  }
1452  }
1453  #endif
1454  else
1455  {
1456  goto notImpl;
1457  }
1458  {
1459  // convert into ideal
1460  int n = L.length();
1461  if (n==0) n=1;
1462  CFFListIterator J=L;
1463  int j=0;
1464  if (with_exps!=1)
1465  {
1466  if ((with_exps==2)&&(n>1))
1467  {
1468  n--;
1469  J++;
1470  }
1471  *v = new intvec( n );
1472  }
1473  else if (L.getFirst().factor().inCoeffDomain() && with_exps!=3)
1474  {
1475  n--;
1476  J++;
1477  }
1478  res = idInit( n ,1);
1479  for ( ; J.hasItem(); J++, j++ )
1480  {
1481  if (with_exps!=1 && with_exps!=3) (**v)[j] = J.getItem().exp();
1482  if (rField_is_Zp(r) || rField_is_Q(r)
1483  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
1484  res->m[j] = convFactoryPSingP( J.getItem().factor(),r );
1485  else if (r->cf->extRing!=NULL) /* Q(a), Fp(a) */
1486  {
1487  if (r->cf->extRing->qideal==NULL)
1488  res->m[j]=convFactoryPSingTrP( J.getItem().factor(),r );
1489  else
1490  res->m[j]=convFactoryAPSingAP( J.getItem().factor(),r );
1491  }
1492  }
1493  if (res->m[0]==NULL)
1494  {
1495  res->m[0]=p_One(r);
1496  }
1497  if (N!=NULL)
1498  {
1499  __p_Mult_nn(res->m[0],N,r);
1500  n_Delete(&N,r->cf);
1501  N=NULL;
1502  }
1503  }
1504  if (r->cf->extRing!=NULL)
1505  if (r->cf->extRing->qideal!=NULL)
1506  prune (a);
1507  if (rField_is_Q_a(r) && (r->cf->extRing->qideal!=NULL))
1508  {
1509  int i=IDELEMS(res)-1;
1510  int stop=1;
1511  if (with_exps!=0 || with_exps==3) stop=0;
1512  for(;i>=stop;i--)
1513  {
1514  p_Norm(res->m[i],r);
1515  }
1516  if (with_exps==0 || with_exps==3) p_SetCoeff(res->m[0],old_lead_coeff,r);
1517  else n_Delete(&old_lead_coeff,r->cf);
1518  }
1519  else
1520  n_Delete(&old_lead_coeff,r->cf);
1521  p_Delete(&f,r);
1522  errorreported=save_errorreported;
1523 notImpl:
1524  if (res==NULL)
1526  if (NN!=NULL)
1527  {
1528  n_Delete(&NN,r->cf);
1529  }
1530  if (N!=NULL)
1531  {
1532  n_Delete(&N,r->cf);
1533  }
1534  return res;
1535 }
CFFList FACTORY_PUBLIC sqrFree(const CanonicalForm &f, bool sort=false)
squarefree factorization
Definition: cf_factor.cc:946
static long pTotaldegree(poly p)
Definition: polys.h:282

◆ singntl_HNF() [1/3]

bigintmat* singntl_HNF ( bigintmat b)

Definition at line 1850 of file clapsing.cc.

1851 {
1852  int r=b->rows();
1853  if (r!=b->cols())
1854  {
1855  Werror("HNF of %d x %d matrix",r,b->cols());
1856  return NULL;
1857  }
1858  setCharacteristic( 0 );
1859  CFMatrix M(r,r);
1860  int i,j;
1861  for(i=r;i>0;i--)
1862  {
1863  for(j=r;j>0;j--)
1864  {
1865  M(i,j)=n_convSingNFactoryN(BIMATELEM(*b,i,j),FALSE,b->basecoeffs());
1866  }
1867  }
1868  CFMatrix *MM=cf_HNF(M);
1869  bigintmat *mm=bimCopy(b);
1870  for(i=r;i>0;i--)
1871  {
1872  for(j=r;j>0;j--)
1873  {
1874  BIMATELEM(*mm,i,j)=n_convFactoryNSingN((*MM)(i,j),b->basecoeffs());
1875  }
1876  }
1877  delete MM;
1878  return mm;
1879 }
bigintmat * bimCopy(const bigintmat *b)
same as copy constructor - apart from it being able to accept NULL as input
Definition: bigintmat.cc:405
CanonicalForm b
Definition: cfModGcd.cc:4105
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...
Definition: cf_hnf.cc:44
Matrices of numbers.
Definition: bigintmat.h:51

◆ singntl_HNF() [2/3]

intvec* singntl_HNF ( intvec m)

Definition at line 1819 of file clapsing.cc.

1820 {
1821  int r=m->rows();
1822  if (r!=m->cols())
1823  {
1824  Werror("HNF of %d x %d matrix",r,m->cols());
1825  return NULL;
1826  }
1827  setCharacteristic( 0 );
1828  CFMatrix M(r,r);
1829  int i,j;
1830  for(i=r;i>0;i--)
1831  {
1832  for(j=r;j>0;j--)
1833  {
1834  M(i,j)=IMATELEM(*m,i,j);
1835  }
1836  }
1837  CFMatrix *MM=cf_HNF(M);
1838  intvec *mm=ivCopy(m);
1839  for(i=r;i>0;i--)
1840  {
1841  for(j=r;j>0;j--)
1842  {
1843  IMATELEM(*mm,i,j)=convFactoryISingI((*MM)(i,j));
1844  }
1845  }
1846  delete MM;
1847  return mm;
1848 }
intvec * ivCopy(const intvec *o)
Definition: intvec.h:135

◆ singntl_HNF() [3/3]

matrix singntl_HNF ( matrix  m,
const ring  s 
)

Definition at line 1783 of file clapsing.cc.

1784 {
1785  int r=m->rows();
1786  if (r!=m->cols())
1787  {
1788  Werror("HNF of %d x %d matrix",r,m->cols());
1789  return NULL;
1790  }
1791 
1792  matrix res=mpNew(r,r);
1793 
1794  if (rField_is_Q(s))
1795  {
1796 
1797  CFMatrix M(r,r);
1798  int i,j;
1799  for(i=r;i>0;i--)
1800  {
1801  for(j=r;j>0;j--)
1802  {
1803  M(i,j)=convSingPFactoryP(MATELEM(m,i,j),s );
1804  }
1805  }
1806  CFMatrix *MM=cf_HNF(M);
1807  for(i=r;i>0;i--)
1808  {
1809  for(j=r;j>0;j--)
1810  {
1811  MATELEM(res,i,j)=convFactoryPSingP((*MM)(i,j),s);
1812  }
1813  }
1814  delete MM;
1815  }
1816  return res;
1817 }

◆ singntl_LLL() [1/2]

intvec* singntl_LLL ( intvec m)

Definition at line 1910 of file clapsing.cc.

1911 {
1912  int r=m->rows();
1913  int c=m->cols();
1914  setCharacteristic( 0 );
1915  CFMatrix M(r,c);
1916  int i,j;
1917  for(i=r;i>0;i--)
1918  {
1919  for(j=c;j>0;j--)
1920  {
1921  M(i,j)=IMATELEM(*m,i,j);
1922  }
1923  }
1924  CFMatrix *MM=cf_LLL(M);
1925  intvec *mm=ivCopy(m);
1926  for(i=r;i>0;i--)
1927  {
1928  for(j=c;j>0;j--)
1929  {
1930  IMATELEM(*mm,i,j)=convFactoryISingI((*MM)(i,j));
1931  }
1932  }
1933  delete MM;
1934  return mm;
1935 }
CFMatrix * cf_LLL(CFMatrix &A)
performs LLL reduction.
Definition: cf_hnf.cc:66

◆ singntl_LLL() [2/2]

matrix singntl_LLL ( matrix  m,
const ring  s 
)

Definition at line 1881 of file clapsing.cc.

1882 {
1883  int r=m->rows();
1884  int c=m->cols();
1885  matrix res=mpNew(r,c);
1886  if (rField_is_Q(s))
1887  {
1888  CFMatrix M(r,c);
1889  int i,j;
1890  for(i=r;i>0;i--)
1891  {
1892  for(j=c;j>0;j--)
1893  {
1895  }
1896  }
1897  CFMatrix *MM=cf_LLL(M);
1898  for(i=r;i>0;i--)
1899  {
1900  for(j=c;j>0;j--)
1901  {
1902  MATELEM(res,i,j)=convFactoryPSingP((*MM)(i,j),s);
1903  }
1904  }
1905  delete MM;
1906  }
1907  return res;
1908 }

◆ Zp_roots()

int* Zp_roots ( poly  p,
const ring  r 
)

Definition at line 2048 of file clapsing.cc.

2049 {
2051  return Zp_roots(pp);
2052 }
CanonicalForm pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition: cf_gcd.cc:676
int * Zp_roots(poly p, const ring r)
Definition: clapsing.cc:2048

Variable Documentation

◆ singclap_factorize_retry

EXTERN_VAR int singclap_factorize_retry

Definition at line 912 of file clapsing.cc.