My Project  debian-1:4.1.2-p1+ds-2
Macros | Functions | Variables
clapsing.cc File Reference
#include "misc/auxiliary.h"
#include "clapsing.h"
#include "factory/factory.h"
#include "coeffs/numbers.h"
#include "coeffs/coeffs.h"
#include "coeffs/bigintmat.h"
#include "monomials/ring.h"
#include "simpleideals.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)
 

Variables

VAR int singclap_factorize_retry
 

Macro Definition Documentation

◆ TRANSEXT_PRIVATES

#define TRANSEXT_PRIVATES

Definition at line 25 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 752 of file clapsing.cc.

753 {
754  p_Test(f,r);
755  p_Test(fac,r);
756  int e=0;
757  if (!p_IsConstantPoly(fac,r))
758  {
759 #ifdef FACTORIZE2_DEBUG
760  printf("start count_Factors(%d), Fdeg=%d, factor deg=%d\n",j,p_Totaldegree(f,r),p_Totaldegree(fac,r));
761  p_wrp(fac,r);PrintLn();
762 #endif
763  On(SW_RATIONAL);
764  CanonicalForm F, FAC,Q,R;
765  Variable a;
766  if (rField_is_Zp(r) || rField_is_Q(r)
767  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
768  {
769  F=convSingPFactoryP( f,r );
770  FAC=convSingPFactoryP( fac,r );
771  }
772  else if (r->cf->extRing!=NULL)
773  {
774  if (r->cf->extRing->qideal!=NULL)
775  {
776  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
777  r->cf->extRing);
778  a=rootOf(mipo);
779  F=convSingAPFactoryAP( f,a,r );
780  FAC=convSingAPFactoryAP( fac,a,r );
781  }
782  else
783  {
784  F=convSingTrPFactoryP( f,r );
785  FAC=convSingTrPFactoryP( fac,r );
786  }
787  }
788  else
790 
791  poly q;
792  loop
793  {
794  Q=F;
795  Q/=FAC;
796  R=Q;
797  R*=FAC;
798  R-=F;
799  if (R.isZero())
800  {
801  if (rField_is_Zp(r) || rField_is_Q(r)
802  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
803  {
804  q = convFactoryPSingP( Q,r );
805  }
806  else if (r->cf->extRing!=NULL)
807  {
808  if (r->cf->extRing->qideal!=NULL)
809  {
810  q= convFactoryAPSingAP( Q,r );
811  }
812  else
813  {
814  q= convFactoryPSingTrP( Q,r );
815  }
816  }
817  e++; p_Delete(&f,r); f=q; q=NULL; F=Q;
818  }
819  else
820  {
821  break;
822  }
823  }
824  if (r->cf->extRing!=NULL)
825  if (r->cf->extRing->qideal!=NULL)
826  prune (a);
827  if (e==0)
828  {
829  Off(SW_RATIONAL);
830  return FALSE;
831  }
832  }
833  else e=1;
834  I->m[j]=fac;
835  if (v!=NULL) (*v)[j]=e;
836  Off(SW_RATIONAL);
837  return TRUE;
838 }
#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:29
FILE * f
Definition: checklibs.c:9
CanonicalForm convSingPFactoryP(poly p, const ring r)
Definition: clapconv.cc:85
poly convFactoryPSingTrP(const CanonicalForm &f, const ring r)
Definition: clapconv.cc:334
poly convFactoryAPSingAP(const CanonicalForm &f, const ring r)
Definition: clapconv.cc:151
CanonicalForm convSingAPFactoryAP(poly p, const Variable &a, const ring r)
Definition: clapconv.cc:116
poly convFactoryPSingP(const CanonicalForm &f, const ring r)
Definition: clapconv.cc:40
CanonicalForm convSingTrPFactoryP(poly p, const ring r)
Definition: clapconv.cc:284
factory's main class
Definition: canonicalform.h:83
factory's class for variables
Definition: factory.h:118
CanonicalForm mipo
Definition: facAlgExt.cc:57
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
int j
Definition: facHensel.cc:105
Variable 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 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:272
#define NULL
Definition: omList.c:12
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:860
static long p_Totaldegree(poly p, const ring r)
Definition: p_polys.h:1446
#define p_Test(p, r)
Definition: p_polys.h:162
static BOOLEAN p_IsConstantPoly(const poly p, const ring r)
Definition: p_polys.h:1945
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:495
static BOOLEAN rField_is_Zn(const ring r)
Definition: ring.h:507
static BOOLEAN rField_is_Q(const ring r)
Definition: ring.h:501
#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 90 of file cf_factor.cc.

91 {
92  printf("%s",s1);
93  if (f.isZero()) printf("+0");
94  //else if (! f.inCoeffDomain() )
95  else if (! f.inBaseDomain() )
96  {
97  int l = f.level();
98  for ( CFIterator i = f; i.hasTerms(); i++ )
99  {
100  int e=i.exp();
101  if (i.coeff().isOne())
102  {
103  printf("+");
104  if (e==0) printf("1");
105  else
106  {
107  printf("v(%d)",l);
108  if (e!=1) printf("^%d",e);
109  }
110  }
111  else
112  {
113  out_cf("+(",i.coeff(),")");
114  if (e!=0)
115  {
116  printf("*v(%d)",l);
117  if (e!=1) printf("^%d",e);
118  }
119  }
120  }
121  }
122  else
123  {
124  if ( f.isImm() )
125  {
127  {
128  long a= imm2int (f.getval());
129  if ( a == gf_q )
130  printf ("+%ld", a);
131  else if ( a == 0L )
132  printf ("+1");
133  else if ( a == 1L )
134  printf ("+%c",gf_name);
135  else
136  {
137  printf ("+%c",gf_name);
138  printf ("^%ld",a);
139  }
140  }
141  else
142  printf("+%ld",f.intval());
143  }
144  else
145  {
146  #ifdef NOSTREAMIO
147  if (f.inZ())
148  {
149  mpz_t m;
150  gmp_numerator(f,m);
151  char * str = new char[mpz_sizeinbase( m, 10 ) + 2];
152  str = mpz_get_str( str, 10, m );
153  puts(str);
154  delete[] str;
155  mpz_clear(m);
156  }
157  else if (f.inQ())
158  {
159  mpz_t m;
160  gmp_numerator(f,m);
161  char * str = new char[mpz_sizeinbase( m, 10 ) + 2];
162  str = mpz_get_str( str, 10, m );
163  puts(str);putchar('/');
164  delete[] str;
165  mpz_clear(m);
167  str = new char[mpz_sizeinbase( m, 10 ) + 2];
168  str = mpz_get_str( str, 10, m );
169  puts(str);
170  delete[] str;
171  mpz_clear(m);
172  }
173  #else
174  std::cout << f;
175  #endif
176  }
177  //if (f.inZ()) printf("(Z)");
178  //else if (f.inQ()) printf("(Q)");
179  //else if (f.inFF()) printf("(FF)");
180  //else if (f.inPP()) printf("(PP)");
181  //else if (f.inGF()) printf("(PP)");
182  //else
183  if (f.inExtension()) printf("E(%d)",f.level());
184  }
185  printf("%s",s2);
186 }
int l
Definition: cfEzgcd.cc:93
int m
Definition: cfEzgcd.cc:121
int i
Definition: cfEzgcd.cc:125
#define GaloisFieldDomain
Definition: cf_defs.h:23
void out_cf(const char *s1, const CanonicalForm &f, const char *s2)
cf_algorithm.cc - simple mathematical algorithms.
Definition: cf_factor.cc:90
static int gettype()
Definition: cf_factory.h:28
class to iterate through CanonicalForm's
Definition: cf_iter.h:44
void gmp_denominator(const CanonicalForm &f, mpz_ptr result)
Definition: singext.cc:40
void gmp_numerator(const CanonicalForm &f, mpz_ptr result)
Definition: singext.cc:20
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

◆ pGetExp_Var()

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

Definition at line 265 of file clapsing.cc.

266 {
267  int m=0;
268  int mm;
269  while (p!=NULL)
270  {
271  mm=p_GetExp(p,i,r);
272  if (mm>m) m=mm;
273  pIter(p);
274  }
275  return m;
276 }
int p
Definition: cfModGcd.cc:4019
#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:468

◆ singclap_absFactorize()

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

Definition at line 1853 of file clapsing.cc.

1854 {
1855  p_Test(f, r);
1856 
1857  ideal res=NULL;
1858 
1859  int offs = rPar(r);
1860  if (f==NULL)
1861  {
1862  res= idInit (1, 1);
1863  mipos= idInit (1, 1);
1864  mipos->m[0]= convFactoryPSingTrP (Variable (offs), r); //overkill
1865  (*exps)=new intvec (1);
1866  (**exps)[0]= 1;
1867  numFactors= 0;
1868  return res;
1869  }
1871 
1872  bool isRat= isOn (SW_RATIONAL);
1873  if (!isRat)
1874  On (SW_RATIONAL);
1875 
1876  CFAFList absFactors= absFactorize (F);
1877 
1878  int n= absFactors.length();
1879  *exps=new intvec (n);
1880 
1881  res= idInit (n, 1);
1882 
1883  mipos= idInit (n, 1);
1884 
1885  Variable x= Variable (offs);
1886  Variable alpha;
1887  int i= 0;
1888  numFactors= 0;
1889  int count;
1890  CFAFListIterator iter= absFactors;
1891  CanonicalForm lead= iter.getItem().factor();
1892  if (iter.getItem().factor().inCoeffDomain())
1893  {
1894  i++;
1895  iter++;
1896  }
1897  for (; iter.hasItem(); iter++, i++)
1898  {
1899  (**exps)[i]= iter.getItem().exp();
1900  alpha= iter.getItem().minpoly().mvar();
1901  if (iter.getItem().minpoly().isOne())
1902  lead /= power (bCommonDen (iter.getItem().factor()), iter.getItem().exp());
1903  else
1904  lead /= power (power (bCommonDen (iter.getItem().factor()), degree (iter.getItem().minpoly())), iter.getItem().exp());
1905  res->m[i]= convFactoryPSingTrP (replacevar (iter.getItem().factor()*bCommonDen (iter.getItem().factor()), alpha, x), r);
1906  if (iter.getItem().minpoly().isOne())
1907  {
1908  count= iter.getItem().exp();
1909  mipos->m[i]= convFactoryPSingTrP (x,r);
1910  }
1911  else
1912  {
1913  count= iter.getItem().exp()*degree (iter.getItem().minpoly());
1914  mipos->m[i]= convFactoryPSingTrP (replacevar (iter.getItem().minpoly(), alpha, x), r);
1915  }
1916  if (!iter.getItem().minpoly().isOne())
1917  prune (alpha);
1918  numFactors += count;
1919  }
1920  if (!isRat)
1921  Off (SW_RATIONAL);
1922 
1923  (**exps)[0]= 1;
1924  res->m[0]= convFactoryPSingTrP (lead, r);
1925  mipos->m[0]= convFactoryPSingTrP (x, r);
1926  return res;
1927 }
bool isOn(int sw)
switches
CanonicalForm power(const CanonicalForm &f, int n)
exponentiation
int degree(const CanonicalForm &f)
CanonicalForm replacevar(const CanonicalForm &, const Variable &, const Variable &)
CanonicalForm replacevar ( const CanonicalForm & f, const Variable & x1, const Variable & x2 )
Definition: cf_ops.cc:271
Variable x
Definition: cfModGcd.cc:4023
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:54
Variable alpha
Definition: facAbsBiFact.cc:52
CFAFList absFactorize(const CanonicalForm &G)
absolute factorization of a multivariate poly over Q
Definition: facAbsFact.cc:267
CanonicalForm res
Definition: facAbsFact.cc:64
static int rPar(const ring r)
(r->cf->P)
Definition: ring.h:594
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 1639 of file clapsing.cc.

1640 {
1641  int r=m->rows();
1642  if (r!=m->cols())
1643  {
1644  Werror("det of %d x %d matrix",r,m->cols());
1645  return NULL;
1646  }
1647  poly res=NULL;
1648  CFMatrix M(r,r);
1649  int i,j;
1650  for(i=r;i>0;i--)
1651  {
1652  for(j=r;j>0;j--)
1653  {
1655  }
1656  }
1658  Off(SW_RATIONAL);
1659  return res;
1660 }
CanonicalForm determinant(const CFMatrix &M, int n)
Definition: cf_linsys.cc:222
const CanonicalForm int s
Definition: facAbsFact.cc:55
#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 1680 of file clapsing.cc.

1681 {
1682  assume(m->basecoeffs()==cf);
1683  CFMatrix M(m->rows(),m->cols());
1684  int i,j;
1685  BOOLEAN setchar=TRUE;
1686  for(i=m->rows();i>0;i--)
1687  {
1688  for(j=m->cols();j>0;j--)
1689  {
1690  M(i,j)=n_convSingNFactoryN(BIMATELEM(*m,i,j),setchar,cf);
1691  setchar=FALSE;
1692  }
1693  }
1694  number res=n_convFactoryNSingN( determinant(M,m->rows()),cf ) ;
1695  return res;
1696 }
int BOOLEAN
Definition: auxiliary.h:87
#define BIMATELEM(M, I, J)
Definition: bigintmat.h:133
CanonicalForm cf
Definition: cfModGcd.cc:4024
CanonicalForm n_convSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition: numbers.cc:626
number n_convFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition: numbers.cc:621
#define assume(x)
Definition: mod2.h:390

◆ singclap_det_i()

int singclap_det_i ( intvec m,
const  ring 
)

Definition at line 1662 of file clapsing.cc.

1663 {
1664 // assume( r == currRing ); // Anything else is not guaranted to work!
1665 
1666  setCharacteristic( 0 ); // ?
1667  CFMatrix M(m->rows(),m->cols());
1668  int i,j;
1669  for(i=m->rows();i>0;i--)
1670  {
1671  for(j=m->cols();j>0;j--)
1672  {
1673  M(i,j)=IMATELEM(*m,i,j);
1674  }
1675  }
1676  int res= convFactoryISingI( determinant(M,m->rows()) ) ;
1677  return res;
1678 }
void setCharacteristic(int c)
Definition: cf_char.cc:23
int convFactoryISingI(const CanonicalForm &f)
Definition: clapconv.cc:110
#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 423 of file clapsing.cc.

424 {
425  // for now there is only the possibility to handle univariate
426  // polynomials over
427  // Q and Fp ...
428  res=NULL;pa=NULL;pb=NULL;
430  if ( rField_is_Q(r) || rField_is_Zp(r)
431  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
432  {
433  setCharacteristic( rChar(r) );
435  CanonicalForm FpG=F+G;
436  if (!(FpG.isUnivariate()|| FpG.inCoeffDomain()))
437  //if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar())
438  {
439  Off(SW_RATIONAL);
440  WerrorS("not univariate");
441  return TRUE;
442  }
443  CanonicalForm Fa,Gb;
444  On(SW_RATIONAL);
445  res=convFactoryPSingP( extgcd( F, G, Fa, Gb ),r );
446  pa=convFactoryPSingP(Fa,r);
447  pb=convFactoryPSingP(Gb,r);
448  Off(SW_RATIONAL);
449  }
450  // and over Q(a) / Fp(a)
451  else if ( r->cf->extRing!=NULL )
452  {
453  if (rField_is_Q_a(r)) setCharacteristic( 0 );
454  else setCharacteristic( rChar(r) );
455  CanonicalForm Fa,Gb;
456  if (r->cf->extRing->qideal!=NULL)
457  {
458  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
459  r->cf->extRing);
460  Variable a=rootOf(mipo);
461  CanonicalForm F( convSingAPFactoryAP( f,a,r ) ),
462  G( convSingAPFactoryAP( g,a,r ) );
463  CanonicalForm FpG=F+G;
464  if (!(FpG.isUnivariate()|| FpG.inCoeffDomain()))
465  //if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar())
466  {
467  WerrorS("not univariate");
468  return TRUE;
469  }
470  res= convFactoryAPSingAP( extgcd( F, G, Fa, Gb ),r );
471  pa=convFactoryAPSingAP(Fa,r);
472  pb=convFactoryAPSingAP(Gb,r);
473  prune (a);
474  }
475  else
476  {
478  CanonicalForm FpG=F+G;
479  if (!(FpG.isUnivariate()|| FpG.inCoeffDomain()))
480  //if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar())
481  {
482  Off(SW_RATIONAL);
483  WerrorS("not univariate");
484  return TRUE;
485  }
486  res= convFactoryPSingTrP( extgcd( F, G, Fa, Gb ), r );
487  pa=convFactoryPSingTrP(Fa, r);
488  pb=convFactoryPSingTrP(Gb, r);
489  }
490  Off(SW_RATIONAL);
491  }
492  else
493  {
495  return TRUE;
496  }
497 #ifndef SING_NDEBUG
498  // checking the result of extgcd:
499  poly dummy;
500  dummy=p_Sub(p_Add_q(pp_Mult_qq(f,pa,r),pp_Mult_qq(g,pb,r),r),p_Copy(res,r),r);
501  if (dummy!=NULL)
502  {
503  PrintS("extgcd( ");p_Write(f,r);p_Write0(g,r);PrintS(" )\n");
504  PrintS("extgcd( ");p_Write(f,r);p_Write0(g,r);PrintS(" )\n");
505  p_Delete(&dummy,r);
506  }
507 #endif
508  return FALSE;
509 }
g
Definition: cfModGcd.cc:4031
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:173
static const int SW_SYMMETRIC_FF
set to 1 for symmetric representation over F_q
Definition: cf_defs.h:31
bool inCoeffDomain() const
bool isUnivariate() const
BOOLEAN pa(leftv res, leftv args)
Definition: cohomo.cc:4346
BOOLEAN pb(leftv res, leftv args)
Definition: cohomo.cc:4373
STATIC_VAR TreeM * G
Definition: janet.cc:31
poly p_Sub(poly p1, poly p2, const ring r)
Definition: p_polys.cc:1965
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:895
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:1090
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:811
void PrintS(const char *s)
Definition: reporter.cc:284
int rChar(ring r)
Definition: ring.cc:713
static BOOLEAN rField_is_Q_a(const ring r)
Definition: ring.h:534

◆ singclap_factorize()

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

Definition at line 842 of file clapsing.cc.

844 {
845  p_Test(f,r);
846 #ifdef FACTORIZE2_DEBUG
847  printf("singclap_factorize, degree %ld\n",p_Totaldegree(f,r));
848 #endif
849  // with_exps: 3,1 return only true factors, no exponents
850  // 2 return true factors and exponents
851  // 0 return coeff, factors and exponents
852  BOOLEAN save_errorreported=errorreported;
853 
854  ideal res=NULL;
855 
856  // handle factorize(0) =========================================
857  if (f==NULL)
858  {
859  res=idInit(1,1);
860  if (with_exps!=1)
861  {
862  (*v)=new intvec(1);
863  (**v)[0]=1;
864  }
865  return res;
866  }
867  // handle factorize(mon) =========================================
868  if (pNext(f)==NULL)
869  {
870  int i=0;
871  int n=0;
872  int e;
873  for(i=rVar(r);i>0;i--) if(p_GetExp(f,i,r)!=0) n++;
874  if (with_exps==0) n++; // with coeff
875  res=idInit(si_max(n,1),1);
876  switch(with_exps)
877  {
878  case 0: // with coef & exp.
879  res->m[0]=p_NSet(n_Copy(pGetCoeff(f),r->cf),r);
880  // no break
881  case 2: // with exp.
882  (*v)=new intvec(si_max(1,n));
883  (**v)[0]=1;
884  // no break
885  case 1: ;
886 #ifdef TEST
887  default: ;
888 #endif
889  }
890  if (n==0)
891  {
892  if (res->m[0]==NULL) res->m[0]=p_One(r);
893  // (**v)[0]=1; is already done
894  }
895  else
896  {
897  for(i=rVar(r);i>0;i--)
898  {
899  e=p_GetExp(f,i,r);
900  if(e!=0)
901  {
902  n--;
903  poly p=p_One(r);
904  p_SetExp(p,i,1,r);
905  p_Setm(p,r);
906  res->m[n]=p;
907  if (with_exps!=1) (**v)[n]=e;
908  }
909  }
910  }
911  p_Delete(&f,r);
912  return res;
913  }
914  //PrintS("S:");p_Write(f,r);PrintLn();
915  // use factory/libfac in general ==============================
916  Variable dummy(-1); prune(dummy); // remove all (tmp.) extensions
917  Off(SW_RATIONAL);
919  CFFList L;
920  number N=NULL;
921  number NN=NULL;
922  number old_lead_coeff=n_Copy(pGetCoeff(f), r->cf);
923 
924  Variable a;
925  if (!rField_is_Zp(r) && !rField_is_Zp_a(r) && !rField_is_Z(r)
926  && !(rField_is_Zn(r) && (r->cf->convSingNFactoryN!=ndConvSingNFactoryN))) /* Q, Q(a) */
927  {
928  //if (f!=NULL) // already tested at start of routine
929  {
930  number n0=n_Copy(pGetCoeff(f),r->cf);
931  if (with_exps==0)
932  N=n_Copy(n0,r->cf);
933  p_Cleardenom(f, r);
934  //after here f should not have a denominator!!
935  //PrintS("S:");p_Write(f,r);PrintLn();
936  NN=n_Div(n0,pGetCoeff(f),r->cf);
937  n_Delete(&n0,r->cf);
938  if (with_exps==0)
939  {
940  n_Delete(&N,r->cf);
941  N=n_Copy(NN,r->cf);
942  }
943  }
944  }
945  else if (rField_is_Zp_a(r))
946  {
947  //if (f!=NULL) // already tested at start of routine
949  {
950  number n0=n_Copy(pGetCoeff(f),r->cf);
951  if (with_exps==0)
952  N=n_Copy(n0,r->cf);
953  p_Norm(f,r);
954  p_Cleardenom(f, r);
955  NN=n_Div(n0,pGetCoeff(f),r->cf);
956  n_Delete(&n0,r->cf);
957  if (with_exps==0)
958  {
959  n_Delete(&N,r->cf);
960  N=n_Copy(NN,r->cf);
961  }
962  }
963  }
964  if ((rField_is_Q(r) || rField_is_Zp(r) || (rField_is_Z(r)))
965  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
966  {
967  setCharacteristic( rChar(r) );
969  L = factorize( F );
970  }
971  // and over Q(a) / Fp(a)
972  else if ((r->cf->extRing!=NULL)
973  &&(r->cf->extRing->cf->convSingNFactoryN!=ndConvSingNFactoryN))
974  {
975  if (rField_is_Q_a (r)) setCharacteristic (0);
976  else setCharacteristic( rChar(r) );
977  if (r->cf->extRing->qideal!=NULL)
978  {
979  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
980  r->cf->extRing);
981  a=rootOf(mipo);
982  CanonicalForm F( convSingAPFactoryAP( f, a, r ) );
983  if (rField_is_Zp_a(r))
984  {
985  L = factorize( F, a );
986  }
987  else
988  {
989  // over Q(a)
990  L= factorize (F, a);
991  }
992  prune(a);
993  }
994  else
995  {
997  L = factorize( F );
998  }
999  }
1000  else
1001  {
1002  goto notImpl;
1003  }
1004  {
1005  poly ff=p_Copy(f,r); // a copy for the retry stuff
1006  // the first factor should be a constant
1007  if ( ! L.getFirst().factor().inCoeffDomain() )
1008  L.insert(CFFactor(1,1));
1009  // convert into ideal
1010  int n = L.length();
1011  if (n==0) n=1;
1012  CFFListIterator J=L;
1013  int j=0;
1014  if (with_exps!=1)
1015  {
1016  if ((with_exps==2)&&(n>1))
1017  {
1018  n--;
1019  J++;
1020  }
1021  *v = new intvec( n );
1022  }
1023  res = idInit( n ,1);
1024  for ( ; J.hasItem(); J++, j++ )
1025  {
1026  if (with_exps!=1) (**v)[j] = J.getItem().exp();
1027  if (rField_is_Zp(r) || rField_is_Q(r)|| rField_is_Z(r)
1028  || (rField_is_Zn(r) && r->cf->convSingNFactoryN!=ndConvSingNFactoryN)) /* Q, Fp, Z */
1029  {
1030  //count_Factors(res,*v,f, j, convFactoryPSingP( J.getItem().factor() );
1031  res->m[j] = convFactoryPSingP( J.getItem().factor(),r );
1032  }
1033 #if 0
1034  else if (rField_is_GF())
1035  res->m[j] = convFactoryGFSingGF( J.getItem().factor() );
1036 #endif
1037  else if (r->cf->extRing!=NULL) /* Q(a), Fp(a) */
1038  {
1039 #ifndef SING_NDEBUG
1040  intvec *w=NULL;
1041  if (v!=NULL) w=*v;
1042 #endif
1043  if (r->cf->extRing->qideal==NULL)
1044  {
1045 #ifdef SING_NDEBUG
1046  res->m[j]= convFactoryPSingTrP( J.getItem().factor(),r );
1047 #else
1048  if(!count_Factors(res,w,j,ff,convFactoryPSingTrP( J.getItem().factor(),r ),r))
1049  {
1050  if (w!=NULL)
1051  (*w)[j]=1;
1052  res->m[j]=p_One(r);
1053  }
1054 #endif
1055  }
1056  else
1057  {
1058 #ifdef SING_NDEBUG
1059  res->m[j]= convFactoryAPSingAP( J.getItem().factor(),r );
1060 #else
1061  if (!count_Factors(res,w,j,ff,convFactoryAPSingAP( J.getItem().factor(),r ),r))
1062  {
1063  if (w!=NULL)
1064  (*w)[j]=1;
1065  res->m[j]=p_One(r);
1066  }
1067 #endif
1068  }
1069  }
1070  }
1071  if (r->cf->extRing!=NULL)
1072  if (r->cf->extRing->qideal!=NULL)
1073  prune (a);
1074 #ifndef SING_NDEBUG
1075  if ((r->cf->extRing!=NULL) && (!p_IsConstantPoly(ff,r)))
1076  {
1079  {
1080  int jj;
1081 #ifdef FACTORIZE2_DEBUG
1082  printf("factorize_retry\n");
1083 #endif
1084  intvec *ww=NULL;
1085  id_Test(res,r);
1086  ideal h=singclap_factorize ( ff, &ww , with_exps, r );
1087  id_Test(h,r);
1088  int l=(*v)->length();
1089  (*v)->resize(l+ww->length());
1090  for(jj=0;jj<ww->length();jj++)
1091  (**v)[jj+l]=(*ww)[jj];
1092  delete ww;
1093  ideal hh=idInit(IDELEMS(res)+IDELEMS(h),1);
1094  for(jj=IDELEMS(res)-1;jj>=0;jj--)
1095  {
1096  hh->m[jj]=res->m[jj];
1097  res->m[jj]=NULL;
1098  }
1099  for(jj=IDELEMS(h)-1;jj>=0;jj--)
1100  {
1101  hh->m[jj+IDELEMS(res)]=h->m[jj];
1102  h->m[jj]=NULL;
1103  }
1104  id_Delete(&res,r);
1105  id_Delete(&h,r);
1106  res=hh;
1107  id_Test(res,r);
1108  ff=NULL;
1109  }
1110  else
1111  {
1112  WarnS("problem with factorize");
1113 #if 0
1114  pWrite(ff);
1115  idShow(res);
1116 #endif
1117  id_Delete(&res,r);
1118  res=idInit(2,1);
1119  res->m[0]=p_One(r);
1120  res->m[1]=ff; ff=NULL;
1121  }
1122  }
1123 #endif
1124  p_Delete(&ff,r);
1125  if (N!=NULL)
1126  {
1127  __p_Mult_nn(res->m[0],N,r);
1128  n_Delete(&N,r->cf);
1129  N=NULL;
1130  }
1131  // delete constants
1132  if (res!=NULL)
1133  {
1134  int i=IDELEMS(res)-1;
1135  int j=0;
1136  for(;i>=0;i--)
1137  {
1138  if ((res->m[i]!=NULL)
1139  && (pNext(res->m[i])==NULL)
1140  && (p_IsConstant(res->m[i],r)))
1141  {
1142  if (with_exps!=0)
1143  {
1144  p_Delete(&(res->m[i]),r);
1145  if ((v!=NULL) && ((*v)!=NULL))
1146  (**v)[i]=0;
1147  j++;
1148  }
1149  else if (i!=0)
1150  {
1151  while ((v!=NULL) && ((*v)!=NULL) && ((**v)[i]>1))
1152  {
1153  res->m[0]=p_Mult_q(res->m[0],p_Copy(res->m[i],r),r);
1154  (**v)[i]--;
1155  }
1156  res->m[0]=p_Mult_q(res->m[0],res->m[i],r);
1157  res->m[i]=NULL;
1158  if ((v!=NULL) && ((*v)!=NULL))
1159  (**v)[i]=1;
1160  j++;
1161  }
1162  }
1163  }
1164  if (j>0)
1165  {
1166  idSkipZeroes(res);
1167  if ((v!=NULL) && ((*v)!=NULL))
1168  {
1169  intvec *w=*v;
1170  int len=IDELEMS(res);
1171  *v = new intvec( len );
1172  for (i=0,j=0;i<si_min(w->length(),len);i++)
1173  {
1174  if((*w)[i]!=0)
1175  {
1176  (**v)[j]=(*w)[i]; j++;
1177  }
1178  }
1179  delete w;
1180  }
1181  }
1182  if (res->m[0]==NULL)
1183  {
1184  res->m[0]=p_One(r);
1185  }
1186  }
1187  }
1188  if (rField_is_Q_a(r) && (r->cf->extRing->qideal!=NULL))
1189  {
1190  int i=IDELEMS(res)-1;
1191  int stop=1;
1192  if (with_exps!=0) stop=0;
1193  for(;i>=stop;i--)
1194  {
1195  p_Norm(res->m[i],r);
1196  }
1197  if (with_exps==0) p_SetCoeff(res->m[0],old_lead_coeff,r);
1198  else n_Delete(&old_lead_coeff,r->cf);
1199  }
1200  else
1201  n_Delete(&old_lead_coeff,r->cf);
1202  errorreported=save_errorreported;
1203 notImpl:
1204  prune(a);
1205  if (res==NULL)
1207  if (NN!=NULL)
1208  {
1209  n_Delete(&NN,r->cf);
1210  }
1211  if (N!=NULL)
1212  {
1213  n_Delete(&N,r->cf);
1214  }
1215  if (f!=NULL) p_Delete(&f,r);
1216  //PrintS("......S\n");
1217  return res;
1218 }
static int si_max(const int a, const int b)
Definition: auxiliary.h:140
static int si_min(const int a, const int b)
Definition: auxiliary.h:141
Factor< CanonicalForm > CFFactor
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
CFFList factorize(const CanonicalForm &f, bool issqrfree=false)
factorization over or
Definition: cf_factor.cc:390
BOOLEAN count_Factors(ideal I, intvec *v, int j, poly &f, poly fac, const ring r)
Definition: clapsing.cc:752
ideal singclap_factorize(poly f, intvec **v, int with_exps, const ring r)
Definition: clapsing.cc:842
VAR int singclap_factorize_retry
Definition: clapsing.cc:840
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:451
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:615
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
#define WarnS
Definition: emacs.cc:78
const CanonicalForm & w
Definition: facAbsFact.cc:55
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_Norm(poly p1, const ring r)
Definition: p_polys.cc:3679
poly p_Cleardenom(poly p, const ring r)
Definition: p_polys.cc:2791
poly p_One(const ring r)
Definition: p_polys.cc:1303
poly p_NSet(number n, const ring r)
returns the poly representing the number n, destroys n
Definition: p_polys.cc:1455
static poly p_Mult_q(poly p, poly q, const ring r)
Definition: p_polys.h:1053
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:487
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:232
static number p_SetCoeff(poly p, number n, ring r)
Definition: p_polys.h:411
static BOOLEAN p_IsConstant(const poly p, const ring r)
Definition: p_polys.h:1931
#define __p_Mult_nn(p, n, r)
Definition: p_polys.h:930
void pWrite(poly p)
Definition: polys.h:304
static BOOLEAN rField_is_Zp_a(const ring r)
Definition: ring.h:524
static BOOLEAN rField_is_Z(const ring r)
Definition: ring.h:504
static BOOLEAN rField_is_GF(const ring r)
Definition: ring.h:516
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:587
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:79

◆ 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 104 of file clapsing.cc.

105 {
106  poly res=NULL;
107 
108  if (g == NULL)
109  {
110  res= f;
111  f=p_One (r);
112  return res;
113  }
114  if (f==NULL)
115  {
116  res= g;
117  g=p_One (r);
118  return res;
119  }
120  if (pNext(g)==NULL)
121  {
122  poly G=p_GcdMon(g,f,r);
123  if (!n_IsOne(pGetCoeff(G),r->cf)
124  || (!p_IsConstant(G,r)))
125  {
126  f=p_Div_mm(f,G,r);
127  g=p_Div_mm(g,G,r);
128  }
129  return G;
130  }
131  else if (pNext(f)==NULL)
132  {
133  poly G=p_GcdMon(f,g,r);
134  if (!n_IsOne(pGetCoeff(G),r->cf)
135  || (!p_IsConstant(G,r)))
136  {
137  f=p_Div_mm(f,G,r);
138  g=p_Div_mm(g,G,r);
139  }
140  return G;
141  }
142 
143  Off(SW_RATIONAL);
144  CanonicalForm F,G,GCD;
145  if (rField_is_Q(r) || (rField_is_Zp(r))
146  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
147  {
148  bool b1=isOn(SW_USE_EZGCD_P);
149  setCharacteristic( rChar(r) );
150  F=convSingPFactoryP( f,r );
151  G=convSingPFactoryP( g,r );
152  GCD=gcd(F,G);
153  if (!GCD.isOne())
154  {
155  p_Delete(&f,r);
156  p_Delete(&g,r);
157  if (getCharacteristic() == 0)
158  On (SW_RATIONAL);
159  F /= GCD;
160  G /= GCD;
161  if (getCharacteristic() == 0)
162  {
163  CanonicalForm denF= bCommonDen (F);
164  CanonicalForm denG= bCommonDen (G);
165  G *= denG;
166  F *= denF;
167  Off (SW_RATIONAL);
168  CanonicalForm gcddenFdenG= gcd (denG, denF);
169  denG /= gcddenFdenG;
170  denF /= gcddenFdenG;
171  On (SW_RATIONAL);
172  G *= denF;
173  F *= denG;
174  }
175  f=convFactoryPSingP( F, r);
176  g=convFactoryPSingP( G, r);
177  }
178  res=convFactoryPSingP( GCD , r);
179  if (!b1) Off (SW_USE_EZGCD_P);
180  }
181  // and over Q(a) / Fp(a)
182  else if ( r->cf->extRing )
183  {
184  if ( rField_is_Q_a(r)) setCharacteristic( 0 );
185  else setCharacteristic( rChar(r) );
186  if (r->cf->extRing->qideal!=NULL)
187  {
188  bool b1=isOn(SW_USE_QGCD);
189  if ( rField_is_Q_a(r) ) On(SW_USE_QGCD);
190  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
191  r->cf->extRing);
192  Variable a=rootOf(mipo);
193  F=( convSingAPFactoryAP( f,a,r ) );
194  G=( convSingAPFactoryAP( g,a,r ) );
195  GCD=gcd(F,G);
196  if (!GCD.isOne())
197  {
198  p_Delete(&f,r);
199  p_Delete(&g,r);
200  if (getCharacteristic() == 0)
201  On (SW_RATIONAL);
202  F /= GCD;
203  G /= GCD;
204  if (getCharacteristic() == 0)
205  {
206  CanonicalForm denF= bCommonDen (F);
207  CanonicalForm denG= bCommonDen (G);
208  G *= denG;
209  F *= denF;
210  Off (SW_RATIONAL);
211  CanonicalForm gcddenFdenG= gcd (denG, denF);
212  denG /= gcddenFdenG;
213  denF /= gcddenFdenG;
214  On (SW_RATIONAL);
215  G *= denF;
216  F *= denG;
217  }
218  f= convFactoryAPSingAP( F,r );
219  g= convFactoryAPSingAP( G,r );
220  }
221  res= convFactoryAPSingAP( GCD,r );
222  prune (a);
223  if (!b1) Off(SW_USE_QGCD);
224  }
225  else
226  {
227  F=( convSingTrPFactoryP( f,r ) );
228  G=( convSingTrPFactoryP( g,r ) );
229  GCD=gcd(F,G);
230  if (!GCD.isOne())
231  {
232  p_Delete(&f,r);
233  p_Delete(&g,r);
234  if (getCharacteristic() == 0)
235  On (SW_RATIONAL);
236  F /= GCD;
237  G /= GCD;
238  if (getCharacteristic() == 0)
239  {
240  CanonicalForm denF= bCommonDen (F);
241  CanonicalForm denG= bCommonDen (G);
242  G *= denG;
243  F *= denF;
244  Off (SW_RATIONAL);
245  CanonicalForm gcddenFdenG= gcd (denG, denF);
246  denG /= gcddenFdenG;
247  denF /= gcddenFdenG;
248  On (SW_RATIONAL);
249  G *= denF;
250  F *= denG;
251  }
252  f= convFactoryPSingTrP( F,r );
253  g= convFactoryPSingTrP( G,r );
254  }
255  res= convFactoryPSingTrP( GCD,r );
256  }
257  }
258  else
260  Off(SW_RATIONAL);
261  return res;
262 }
int getCharacteristic()
Definition: cf_char.cc:51
static const int SW_USE_QGCD
set to 1 to use Encarnacion GCD over Q(a)
Definition: cf_defs.h:41
static const int SW_USE_EZGCD_P
set to 1 to use EZGCD over F_q
Definition: cf_defs.h:35
CF_NO_INLINE bool isOne() const
CF_INLINE bool CanonicalForm::isOne, isZero () const.
Definition: cf_inline.cc:354
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
Definition: coeffs.h:468
poly p_GcdMon(poly f, poly g, const ring r)
polynomial gcd for f=mon
Definition: p_polys.cc:4846
poly p_Div_mm(poly p, const poly m, const ring r)
divide polynomial by monomial
Definition: p_polys.cc:1520
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 42 of file clapsing.cc.

43 {
44  poly res=NULL;
45 
46  assume(f!=NULL);
47  assume(g!=NULL);
48 
49  if(pNext(f)==NULL)
50  {
51  return p_GcdMon(f,g,r);
52  }
53  else if(pNext(g)==NULL)
54  {
55  return p_GcdMon(g,f,r);
56  }
57 
59  if (rField_is_Q(r) || rField_is_Zp(r) || rField_is_Z(r)
60  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
61  {
64  res=convFactoryPSingP( gcd( F, G ) , r);
65  }
66  // and over Q(a) / Fp(a)
67  else if ( r->cf->extRing!=NULL )
68  {
69  if ( rField_is_Q_a(r)) setCharacteristic( 0 );
70  else setCharacteristic( rChar(r) );
71  if (r->cf->extRing->qideal!=NULL)
72  {
73  bool b1=isOn(SW_USE_QGCD);
74  if ( rField_is_Q_a(r) ) On(SW_USE_QGCD);
75  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
76  r->cf->extRing);
77  Variable a=rootOf(mipo);
79  G( convSingAPFactoryAP( g,a,r ) );
80  res= convFactoryAPSingAP( gcd( F, G ),r );
81  prune (a);
82  if (!b1) Off(SW_USE_QGCD);
83  }
84  else
85  {
86  convSingTrP(f,r);
87  convSingTrP(g,r);
89  res= convFactoryPSingTrP( gcd( F, G ),r );
90  }
91  }
92  else if (r->cf->convSingNFactoryN==ndConvSingNFactoryN)
94  else
95  { // handle user type coeffs:
98  res=convFactoryPSingP( gcd( F, G ) , r);
99  }
100  Off(SW_RATIONAL);
101  return res;
102 }
BOOLEAN convSingTrP(poly p, const ring r)
Definition: clapconv.cc:320

◆ singclap_irrCharSeries()

matrix singclap_irrCharSeries ( ideal  I,
const ring  r 
)

Definition at line 1453 of file clapsing.cc.

1454 {
1455  if (idIs0(I)) return mpNew(1,1);
1456 
1457  // for now there is only the possibility to handle polynomials over
1458  // Q and Fp ...
1459  matrix res=NULL;
1460  int i;
1461  Off(SW_RATIONAL);
1463  CFList L;
1464  ListCFList LL;
1465  if (rField_is_Q(r) || rField_is_Zp(r)
1466  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
1467  {
1468  setCharacteristic( rChar(r) );
1469  for(i=0;i<IDELEMS(I);i++)
1470  {
1471  poly p=I->m[i];
1472  if (p!=NULL)
1473  {
1474  p=p_Copy(p,r);
1475  p_Cleardenom(p, r);
1476  L.append(convSingPFactoryP(p,r));
1477  p_Delete(&p,r);
1478  }
1479  }
1480  }
1481  // and over Q(a) / Fp(a)
1482  else if (nCoeff_is_transExt (r->cf))
1483  {
1484  setCharacteristic( rChar(r) );
1485  for(i=0;i<IDELEMS(I);i++)
1486  {
1487  poly p=I->m[i];
1488  if (p!=NULL)
1489  {
1490  p=p_Copy(p,r);
1491  p_Cleardenom(p, r);
1493  p_Delete(&p,r);
1494  }
1495  }
1496  }
1497  else
1498  {
1500  return res;
1501  }
1502 
1503  // a very bad work-around --- FIX IT in libfac
1504  // should be fixed as of 2001/6/27
1505  int tries=0;
1506  int m,n;
1508  loop
1509  {
1510  LL=irrCharSeries(L);
1511  m= LL.length(); // Anzahl Zeilen
1512  n=0;
1513  for ( LLi = LL; LLi.hasItem(); LLi++ )
1514  {
1515  n = si_max(LLi.getItem().length(),n);
1516  }
1517  if ((m!=0) && (n!=0)) break;
1518  tries++;
1519  if (tries>=5) break;
1520  }
1521  if ((m==0) || (n==0))
1522  {
1523  Warn("char_series returns %d x %d matrix from %d input polys (%d)",
1524  m,n,IDELEMS(I)+1,LL.length());
1525  iiWriteMatrix((matrix)I,"I",2,r,0);
1526  m=si_max(m,1);
1527  n=si_max(n,1);
1528  }
1529  res=mpNew(m,n);
1530  CFListIterator Li;
1531  for ( m=1, LLi = LL; LLi.hasItem(); LLi++, m++ )
1532  {
1533  for (n=1, Li = LLi.getItem(); Li.hasItem(); Li++, n++)
1534  {
1535  if (rField_is_Q(r) || rField_is_Zp(r)
1536  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
1537  MATELEM(res,m,n)=convFactoryPSingP(Li.getItem(),r);
1538  else
1540  }
1541  }
1542  Off(SW_RATIONAL);
1543  return res;
1544 }
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:940
#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 1546 of file clapsing.cc.

1547 {
1548  int i;
1549  Off(SW_RATIONAL);
1551  CFList L;
1552  if (rField_is_Q(r) || rField_is_Zp(r)
1553  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
1554  {
1555  setCharacteristic( rChar(r) );
1556  for(i=0;i<IDELEMS(I);i++)
1557  {
1558  poly p=I->m[i];
1559  if (p!=NULL)
1560  {
1561  p=p_Copy(p,r);
1562  p_Cleardenom(p, r);
1563  L.append(convSingPFactoryP(p,r));
1564  }
1565  }
1566  }
1567  // and over Q(a) / Fp(a)
1568  else if (nCoeff_is_transExt (r->cf))
1569  {
1570  setCharacteristic( rChar(r) );
1571  for(i=0;i<IDELEMS(I);i++)
1572  {
1573  poly p=I->m[i];
1574  if (p!=NULL)
1575  {
1576  p=p_Copy(p,r);
1577  p_Cleardenom(p, r);
1579  }
1580  }
1581  }
1582  else
1583  {
1585  return NULL;
1586  }
1587 
1588  List<int> IL=neworderint(L);
1589  ListIterator<int> Li;
1590  StringSetS("");
1591  Li = IL;
1592  int offs=rPar(r);
1593  int* mark=(int*)omAlloc0((rVar(r)+offs)*sizeof(int));
1594  int cnt=rVar(r)+offs;
1595  loop
1596  {
1597  if(! Li.hasItem()) break;
1598  BOOLEAN done=TRUE;
1599  i=Li.getItem()-1;
1600  mark[i]=1;
1601  if (i<offs)
1602  {
1603  done=FALSE;
1604  //StringAppendS(r->parameter[i]);
1605  }
1606  else
1607  {
1608  StringAppendS(r->names[i-offs]);
1609  }
1610  Li++;
1611  cnt--;
1612  if(cnt==0) break;
1613  if (done) StringAppendS(",");
1614  }
1615  for(i=0;i<rVar(r)+offs;i++)
1616  {
1617  BOOLEAN done=TRUE;
1618  if(mark[i]==0)
1619  {
1620  if (i<offs)
1621  {
1622  done=FALSE;
1623  //StringAppendS(r->parameter[i]);
1624  }
1625  else
1626  {
1627  StringAppendS(r->names[i-offs]);
1628  }
1629  cnt--;
1630  if(cnt==0) break;
1631  if (done) StringAppendS(",");
1632  }
1633  }
1634  char * s=StringEndS();
1635  if (s[strlen(s)-1]==',') s[strlen(s)-1]='\0';
1636  return s;
1637 }
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 558 of file clapsing.cc.

559 {
560  poly res=NULL;
561  On(SW_RATIONAL);
562  if (rField_is_Zp(r) || rField_is_Q(r)
563  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
564  {
565  setCharacteristic( rChar(r) );
567  res = convFactoryPSingP( F / G,r );
568  }
569  // div is not implemented for ZZ coeffs in factory
570  else if (r->cf->extRing!=NULL)
571  {
572  if (rField_is_Q_a(r)) setCharacteristic( 0 );
573  else setCharacteristic( rChar(r) );
574  if (r->cf->extRing->qideal!=NULL)
575  {
576  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
577  r->cf->extRing);
578  Variable a=rootOf(mipo);
579  CanonicalForm F( convSingAPFactoryAP( f,a,r ) ),
580  G( convSingAPFactoryAP( g,a,r ) );
581  res= convFactoryAPSingAP( F / G, r );
582  prune (a);
583  }
584  else
585  {
587  res= convFactoryPSingTrP( F / G,r );
588  }
589  }
590 #if 0 // not yet working
591  else if (rField_is_GF())
592  {
593  //Print("GF(%d^%d)\n",nfCharP,nfMinPoly[0]);
594  setCharacteristic( nfCharP,nfMinPoly[0], currRing->parameter[0][0] );
595  CanonicalForm F( convSingGFFactoryGF( f ) ), G( convSingGFFactoryGF( g ) );
596  res = convFactoryGFSingGF( F / G );
597  }
598 #endif
599  else
601  Off(SW_RATIONAL);
602  return res;
603 }
STATIC_VAR int nfMinPoly[16]
Definition: ffields.cc:548
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 605 of file clapsing.cc.

606 {
607  poly res=NULL;
608  On(SW_RATIONAL);
609  if (rField_is_Zp(r) || rField_is_Q(r)
610  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
611  {
612  setCharacteristic( rChar(r) );
614  res = convFactoryPSingP( F-(F/G)*G,r );
615  }
616  // mod is not implemented for ZZ coeffs in factory
617  else if (r->cf->extRing!=NULL)
618  {
619  if (rField_is_Q_a(r)) setCharacteristic( 0 );
620  else setCharacteristic( rChar(r) );
621  if (r->cf->extRing->qideal!=NULL)
622  {
623  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
624  r->cf->extRing);
625  Variable a=rootOf(mipo);
626  CanonicalForm F( convSingAPFactoryAP( f,a,r ) ),
627  G( convSingAPFactoryAP( g,a,r ) );
628  res= convFactoryAPSingAP( F-(F/G)*G, r );
629  prune (a);
630  }
631  else
632  {
634  res= convFactoryPSingTrP( F-(F/G)*G,r );
635  }
636  }
637 #if 0 // not yet working
638  else if (rField_is_GF())
639  {
640  //Print("GF(%d^%d)\n",nfCharP,nfMinPoly[0]);
641  setCharacteristic( nfCharP,nfMinPoly[0], currRing->parameter[0][0] );
642  CanonicalForm F( convSingGFFactoryGF( f ) ), G( convSingGFFactoryGF( g ) );
643  res = convFactoryGFSingGF( F / G );
644  }
645 #endif
646  else
648  Off(SW_RATIONAL);
649  return res;
650 }

◆ singclap_pmult()

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

Definition at line 511 of file clapsing.cc.

512 {
513  poly res=NULL;
514  On(SW_RATIONAL);
515  if (rField_is_Zp(r) || rField_is_Q(r) || rField_is_Z(r)
516  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
517  {
518  if (rField_is_Z(r)) Off(SW_RATIONAL);
519  setCharacteristic( rChar(r) );
521  res = convFactoryPSingP( F * G,r );
522  }
523  else if (r->cf->extRing!=NULL)
524  {
525  if (rField_is_Q_a(r)) setCharacteristic( 0 );
526  else setCharacteristic( rChar(r) );
527  if (r->cf->extRing->qideal!=NULL)
528  {
529  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
530  r->cf->extRing);
531  Variable a=rootOf(mipo);
532  CanonicalForm F( convSingAPFactoryAP( f,a,r ) ),
533  G( convSingAPFactoryAP( g,a,r ) );
534  res= convFactoryAPSingAP( F * G, r );
535  prune (a);
536  }
537  else
538  {
540  res= convFactoryPSingTrP( F * G,r );
541  }
542  }
543 #if 0 // not yet working
544  else if (rField_is_GF())
545  {
546  //Print("GF(%d^%d)\n",nfCharP,nfMinPoly[0]);
547  setCharacteristic( nfCharP,nfMinPoly[0], currRing->parameter[0][0] );
548  CanonicalForm F( convSingGFFactoryGF( f ) ), G( convSingGFFactoryGF( g ) );
549  res = convFactoryGFSingGF( F * G );
550  }
551 #endif
552  else
554  Off(SW_RATIONAL);
555  return res;
556 }

◆ singclap_resultant()

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

Definition at line 279 of file clapsing.cc.

280 {
281  poly res=NULL;
282  int i=p_IsPurePower(x, r);
283  if (i==0)
284  {
285  WerrorS("3rd argument must be a ring variable");
286  goto resultant_returns_res;
287  }
288  if ((f==NULL) || (g==NULL))
289  goto resultant_returns_res;
290  // for now there is only the possibility to handle polynomials over
291  // Q and Fp ...
292  if (rField_is_Zp(r) || rField_is_Q(r)
293  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
294  {
295  Variable X(i);
296  setCharacteristic( rChar(r) );
298  res=convFactoryPSingP( resultant( F, G, X),r );
299  Off(SW_RATIONAL);
300  goto resultant_returns_res;
301  }
302  // and over Q(a) / Fp(a)
303  else if (r->cf->extRing!=NULL)
304  {
305  if (rField_is_Q_a(r)) setCharacteristic( 0 );
306  else setCharacteristic( rChar(r) );
307  Variable X(i+rPar(r));
308  if (r->cf->extRing->qideal!=NULL)
309  {
310  //Variable X(i);
311  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
312  r->cf->extRing);
313  Variable a=rootOf(mipo);
314  CanonicalForm F( convSingAPFactoryAP( f,a,r ) ),
315  G( convSingAPFactoryAP( g,a,r ) );
316  res= convFactoryAPSingAP( resultant( F, G, X ),r );
317  prune (a);
318  }
319  else
320  {
321  //Variable X(i+rPar(currRing));
322  number nf,ng;
324  int ef,eg;
325  ef=pGetExp_Var(f,i,r);
326  eg=pGetExp_Var(g,i,r);
328  res= convFactoryPSingTrP( resultant( F, G, X ),r );
329  if ((nf!=NULL)&&(!n_IsOne(nf,r->cf)))
330  {
331  number n=n_Invers(nf,r->cf);
332  while(eg>0)
333  {
334  res=__p_Mult_nn(res,n,r);
335  eg--;
336  }
337  n_Delete(&n,r->cf);
338  }
339  n_Delete(&nf,r->cf);
340  if ((ng!=NULL)&&(!n_IsOne(ng,r->cf)))
341  {
342  number n=n_Invers(ng,r->cf);
343  while(ef>0)
344  {
345  res=__p_Mult_nn(res,n,r);
346  ef--;
347  }
348  n_Delete(&n,r->cf);
349  }
350  n_Delete(&ng,r->cf);
351  }
352  Off(SW_RATIONAL);
353  goto resultant_returns_res;
354  }
355  else
357 resultant_returns_res:
358  p_Delete(&f,r);
359  p_Delete(&g,r);
360  p_Delete(&x,r);
361  return res;
362 }
CanonicalForm 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:265
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:564
int p_IsPurePower(const poly p, const ring r)
return i, if head depends only on var(i)
Definition: p_polys.cc:1216
void p_Cleardenom_n(poly ph, const ring r, number &c)
Definition: p_polys.cc:2900
Definition: gnumpfl.cc:27

◆ singclap_sqrfree()

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

Definition at line 1220 of file clapsing.cc.

1221 {
1222  p_Test(f,r);
1223 #ifdef FACTORIZE2_DEBUG
1224  printf("singclap_sqrfree, degree %d\n",pTotaldegree(f));
1225 #endif
1226  // with_exps: 3,1 return only true factors, no exponents
1227  // 2 return true factors and exponents
1228  // 0 return coeff, factors and exponents
1229  BOOLEAN save_errorreported=errorreported;
1230 
1231  ideal res=NULL;
1232 
1233  // handle factorize(0) =========================================
1234  if (f==NULL)
1235  {
1236  res=idInit(1,1);
1237  if (with_exps!=1 && with_exps!=3)
1238  {
1239  (*v)=new intvec(1);
1240  (**v)[0]=1;
1241  }
1242  return res;
1243  }
1244  // handle factorize(mon) =========================================
1245  if (pNext(f)==NULL)
1246  {
1247  int i=0;
1248  int n=0;
1249  int e;
1250  for(i=rVar(r);i>0;i--) if(p_GetExp(f,i,r)!=0) n++;
1251  if (with_exps==0 || with_exps==3) n++; // with coeff
1252  res=idInit(si_max(n,1),1);
1253  if(with_exps!=1)
1254  {
1255  (*v)=new intvec(si_max(1,n));
1256  (**v)[0]=1;
1257  }
1258  res->m[0]=p_NSet(n_Copy(pGetCoeff(f),r->cf),r);
1259  if (n==0)
1260  {
1261  res->m[0]=p_One(r);
1262  // (**v)[0]=1; is already done
1263  }
1264  else
1265  {
1266  for(i=rVar(r);i>0;i--)
1267  {
1268  e=p_GetExp(f,i,r);
1269  if(e!=0)
1270  {
1271  n--;
1272  poly p=p_One(r);
1273  p_SetExp(p,i,1,r);
1274  p_Setm(p,r);
1275  res->m[n]=p;
1276  if (with_exps!=1) (**v)[n]=e;
1277  }
1278  }
1279  }
1280  p_Delete(&f,r);
1281  return res;
1282  }
1283  //PrintS("S:");pWrite(f);PrintLn();
1284  // use factory/libfac in general ==============================
1285  Off(SW_RATIONAL);
1287  CFFList L;
1288  number N=NULL;
1289  number NN=NULL;
1290  number old_lead_coeff=n_Copy(pGetCoeff(f), r->cf);
1291  Variable a;
1292 
1293  if (!rField_is_Zp(r) && !rField_is_Zp_a(r)) /* Q, Q(a) */
1294  {
1295  //if (f!=NULL) // already tested at start of routine
1296  number n0=n_Copy(pGetCoeff(f),r->cf);
1297  if (with_exps==0 || with_exps==3)
1298  N=n_Copy(n0,r->cf);
1299  p_Cleardenom(f, r);
1300  //after here f should not have a denominator!!
1301  //PrintS("S:");p_Write(f,r);PrintLn();
1302  NN=n_Div(n0,pGetCoeff(f),r->cf);
1303  n_Delete(&n0,r->cf);
1304  if (with_exps==0 || with_exps==3)
1305  {
1306  n_Delete(&N,r->cf);
1307  N=n_Copy(NN,r->cf);
1308  }
1309  }
1310  else if (rField_is_Zp_a(r))
1311  {
1312  //if (f!=NULL) // already tested at start of routine
1313  if (singclap_factorize_retry==0)
1314  {
1315  number n0=n_Copy(pGetCoeff(f),r->cf);
1316  if (with_exps==0 || with_exps==3)
1317  N=n_Copy(n0,r->cf);
1318  p_Norm(f,r);
1319  p_Cleardenom(f, r);
1320  NN=n_Div(n0,pGetCoeff(f),r->cf);
1321  n_Delete(&n0,r->cf);
1322  if (with_exps==0 || with_exps==3)
1323  {
1324  n_Delete(&N,r->cf);
1325  N=n_Copy(NN,r->cf);
1326  }
1327  }
1328  }
1329  if (rField_is_Q(r) || rField_is_Zp(r)
1330  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
1331  {
1332  setCharacteristic( rChar(r) );
1333  CanonicalForm F( convSingPFactoryP( f,r ) );
1334  L = sqrFree( F );
1335  }
1336  else if (r->cf->extRing!=NULL)
1337  {
1338  if (rField_is_Q_a (r)) setCharacteristic (0);
1339  else setCharacteristic( rChar(r) );
1340  if (r->cf->extRing->qideal!=NULL)
1341  {
1342  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
1343  r->cf->extRing);
1344  a=rootOf(mipo);
1345  CanonicalForm F( convSingAPFactoryAP( f, a, r ) );
1346  L= sqrFree (F);
1347  }
1348  else
1349  {
1351  L = sqrFree( F );
1352  }
1353  }
1354  #if 0
1355  else if (rField_is_GF())
1356  {
1357  int c=rChar(r);
1358  setCharacteristic( c, primepower(c) );
1359  CanonicalForm F( convSingGFFactoryGF( f ) );
1360  if (F.isUnivariate())
1361  {
1362  L = factorize( F );
1363  }
1364  else
1365  {
1366  goto notImpl;
1367  }
1368  }
1369  #endif
1370  else
1371  {
1372  goto notImpl;
1373  }
1374  {
1375  // convert into ideal
1376  int n = L.length();
1377  if (n==0) n=1;
1378  CFFListIterator J=L;
1379  int j=0;
1380  if (with_exps!=1)
1381  {
1382  if ((with_exps==2)&&(n>1))
1383  {
1384  n--;
1385  J++;
1386  }
1387  *v = new intvec( n );
1388  }
1389  else if (L.getFirst().factor().inCoeffDomain() && with_exps!=3)
1390  {
1391  n--;
1392  J++;
1393  }
1394  res = idInit( n ,1);
1395  for ( ; J.hasItem(); J++, j++ )
1396  {
1397  if (with_exps!=1 && with_exps!=3) (**v)[j] = J.getItem().exp();
1398  if (rField_is_Zp(r) || rField_is_Q(r)
1399  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
1400  res->m[j] = convFactoryPSingP( J.getItem().factor(),r );
1401  else if (r->cf->extRing!=NULL) /* Q(a), Fp(a) */
1402  {
1403  if (r->cf->extRing->qideal==NULL)
1404  res->m[j]=convFactoryPSingTrP( J.getItem().factor(),r );
1405  else
1406  res->m[j]=convFactoryAPSingAP( J.getItem().factor(),r );
1407  }
1408  }
1409  if (res->m[0]==NULL)
1410  {
1411  res->m[0]=p_One(r);
1412  }
1413  if (N!=NULL)
1414  {
1415  __p_Mult_nn(res->m[0],N,r);
1416  n_Delete(&N,r->cf);
1417  N=NULL;
1418  }
1419  }
1420  if (r->cf->extRing!=NULL)
1421  if (r->cf->extRing->qideal!=NULL)
1422  prune (a);
1423  if (rField_is_Q_a(r) && (r->cf->extRing->qideal!=NULL))
1424  {
1425  int i=IDELEMS(res)-1;
1426  int stop=1;
1427  if (with_exps!=0 || with_exps==3) stop=0;
1428  for(;i>=stop;i--)
1429  {
1430  p_Norm(res->m[i],r);
1431  }
1432  if (with_exps==0 || with_exps==3) p_SetCoeff(res->m[0],old_lead_coeff,r);
1433  else n_Delete(&old_lead_coeff,r->cf);
1434  }
1435  else
1436  n_Delete(&old_lead_coeff,r->cf);
1437  p_Delete(&f,r);
1438  errorreported=save_errorreported;
1439 notImpl:
1440  if (res==NULL)
1442  if (NN!=NULL)
1443  {
1444  n_Delete(&NN,r->cf);
1445  }
1446  if (N!=NULL)
1447  {
1448  n_Delete(&N,r->cf);
1449  }
1450  return res;
1451 }
CFFList sqrFree(const CanonicalForm &f, bool sort=false)
squarefree factorization
Definition: cf_factor.cc:757
static long pTotaldegree(poly p)
Definition: polys.h:278

◆ singntl_HNF() [1/3]

bigintmat* singntl_HNF ( bigintmat b)

Definition at line 1766 of file clapsing.cc.

1767 {
1768  int r=b->rows();
1769  if (r!=b->cols())
1770  {
1771  Werror("HNF of %d x %d matrix",r,b->cols());
1772  return NULL;
1773  }
1774  setCharacteristic( 0 );
1775  CFMatrix M(r,r);
1776  int i,j;
1777  for(i=r;i>0;i--)
1778  {
1779  for(j=r;j>0;j--)
1780  {
1781  M(i,j)=n_convSingNFactoryN(BIMATELEM(*b,i,j),FALSE,b->basecoeffs());
1782  }
1783  }
1784  CFMatrix *MM=cf_HNF(M);
1785  bigintmat *mm=bimCopy(b);
1786  for(i=r;i>0;i--)
1787  {
1788  for(j=r;j>0;j--)
1789  {
1790  BIMATELEM(*mm,i,j)=n_convFactoryNSingN((*MM)(i,j),b->basecoeffs());
1791  }
1792  }
1793  delete MM;
1794  return mm;
1795 }
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:4044
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:38
Matrices of numbers.
Definition: bigintmat.h:51

◆ singntl_HNF() [2/3]

intvec* singntl_HNF ( intvec m)

Definition at line 1735 of file clapsing.cc.

1736 {
1737  int r=m->rows();
1738  if (r!=m->cols())
1739  {
1740  Werror("HNF of %d x %d matrix",r,m->cols());
1741  return NULL;
1742  }
1743  setCharacteristic( 0 );
1744  CFMatrix M(r,r);
1745  int i,j;
1746  for(i=r;i>0;i--)
1747  {
1748  for(j=r;j>0;j--)
1749  {
1750  M(i,j)=IMATELEM(*m,i,j);
1751  }
1752  }
1753  CFMatrix *MM=cf_HNF(M);
1754  intvec *mm=ivCopy(m);
1755  for(i=r;i>0;i--)
1756  {
1757  for(j=r;j>0;j--)
1758  {
1759  IMATELEM(*mm,i,j)=convFactoryISingI((*MM)(i,j));
1760  }
1761  }
1762  delete MM;
1763  return mm;
1764 }
intvec * ivCopy(const intvec *o)
Definition: intvec.h:135

◆ singntl_HNF() [3/3]

matrix singntl_HNF ( matrix  m,
const ring  s 
)

Definition at line 1699 of file clapsing.cc.

1700 {
1701  int r=m->rows();
1702  if (r!=m->cols())
1703  {
1704  Werror("HNF of %d x %d matrix",r,m->cols());
1705  return NULL;
1706  }
1707 
1708  matrix res=mpNew(r,r);
1709 
1710  if (rField_is_Q(s))
1711  {
1712 
1713  CFMatrix M(r,r);
1714  int i,j;
1715  for(i=r;i>0;i--)
1716  {
1717  for(j=r;j>0;j--)
1718  {
1719  M(i,j)=convSingPFactoryP(MATELEM(m,i,j),s );
1720  }
1721  }
1722  CFMatrix *MM=cf_HNF(M);
1723  for(i=r;i>0;i--)
1724  {
1725  for(j=r;j>0;j--)
1726  {
1727  MATELEM(res,i,j)=convFactoryPSingP((*MM)(i,j),s);
1728  }
1729  }
1730  delete MM;
1731  }
1732  return res;
1733 }

◆ singntl_LLL() [1/2]

intvec* singntl_LLL ( intvec m)

Definition at line 1826 of file clapsing.cc.

1827 {
1828  int r=m->rows();
1829  int c=m->cols();
1830  setCharacteristic( 0 );
1831  CFMatrix M(r,c);
1832  int i,j;
1833  for(i=r;i>0;i--)
1834  {
1835  for(j=c;j>0;j--)
1836  {
1837  M(i,j)=IMATELEM(*m,i,j);
1838  }
1839  }
1840  CFMatrix *MM=cf_LLL(M);
1841  intvec *mm=ivCopy(m);
1842  for(i=r;i>0;i--)
1843  {
1844  for(j=c;j>0;j--)
1845  {
1846  IMATELEM(*mm,i,j)=convFactoryISingI((*MM)(i,j));
1847  }
1848  }
1849  delete MM;
1850  return mm;
1851 }
CFMatrix * cf_LLL(CFMatrix &A)
performs LLL reduction.
Definition: cf_hnf.cc:48

◆ singntl_LLL() [2/2]

matrix singntl_LLL ( matrix  m,
const ring  s 
)

Definition at line 1797 of file clapsing.cc.

1798 {
1799  int r=m->rows();
1800  int c=m->cols();
1801  matrix res=mpNew(r,c);
1802  if (rField_is_Q(s))
1803  {
1804  CFMatrix M(r,c);
1805  int i,j;
1806  for(i=r;i>0;i--)
1807  {
1808  for(j=c;j>0;j--)
1809  {
1811  }
1812  }
1813  CFMatrix *MM=cf_LLL(M);
1814  for(i=r;i>0;i--)
1815  {
1816  for(j=c;j>0;j--)
1817  {
1818  MATELEM(res,i,j)=convFactoryPSingP((*MM)(i,j),s);
1819  }
1820  }
1821  delete MM;
1822  }
1823  return res;
1824 }

Variable Documentation

◆ singclap_factorize_retry

EXTERN_VAR int singclap_factorize_retry

Definition at line 840 of file clapsing.cc.