My Project
Loading...
Searching...
No Matches
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 <NTL/config.h>
#include <NTL/mat_ZZ.h>
#include <NTL/mat_lzz_p.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
#define MAX_CHAR_FACTORY   536870909

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)
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)
matrix singntl_rref (matrix m, const ring R)
ideal singntl_rref (ideal m, const ring R)
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

◆ MAX_CHAR_FACTORY

#define MAX_CHAR_FACTORY   536870909

Definition at line 66 of file clapsing.cc.

◆ TRANSEXT_PRIVATES

#define TRANSEXT_PRIVATES

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

894{
895 p_Test(f,r);
896 p_Test(fac,r);
897 int e=0;
898 if (!p_IsConstant(fac,r))
899 {
900#ifdef FACTORIZE2_DEBUG
901 printf("start count_Factors(%d), Fdeg=%d, factor deg=%d\n",j,p_Totaldegree(f,r),p_Totaldegree(fac,r));
902 p_wrp(fac,r);PrintLn();
903#endif
905 CanonicalForm F, FAC,Q,R;
906 Variable a;
907 if (rField_is_Zp(r) || rField_is_Q(r)
908 || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
909 {
910 F=convSingPFactoryP( f,r );
911 FAC=convSingPFactoryP( fac,r );
912 }
913 else if (r->cf->extRing!=NULL)
914 {
915 if (r->cf->extRing->qideal!=NULL)
916 {
917 CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
918 r->cf->extRing);
919 a=rootOf(mipo);
920 F=convSingAPFactoryAP( f,a,r );
921 FAC=convSingAPFactoryAP( fac,a,r );
922 }
923 else
924 {
925 F=convSingTrPFactoryP( f,r );
926 FAC=convSingTrPFactoryP( fac,r );
927 }
928 }
929 else
931
932 poly q;
933 loop
934 {
935 Q=F;
936 Q/=FAC;
937 R=Q;
938 R*=FAC;
939 R-=F;
940 if (R.isZero())
941 {
942 if (rField_is_Zp(r) || rField_is_Q(r)
943 || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
944 {
945 q = convFactoryPSingP( Q,r );
946 }
947 else if (r->cf->extRing!=NULL)
948 {
949 if (r->cf->extRing->qideal!=NULL)
950 {
951 q= convFactoryAPSingAP( Q,r );
952 }
953 else
954 {
955 q= convFactoryPSingTrP( Q,r );
956 }
957 }
958 e++; p_Delete(&f,r); f=q; q=NULL; F=Q;
959 }
960 else
961 {
962 break;
963 }
964 }
965 if (r->cf->extRing!=NULL)
966 if (r->cf->extRing->qideal!=NULL)
967 prune (a);
968 if (e==0)
969 {
971 return FALSE;
972 }
973 }
974 else e=1;
975 I->m[j]=fac;
976 if (v!=NULL) (*v)[j]=e;
978 return TRUE;
979}
#define TRUE
Definition auxiliary.h:101
#define FALSE
Definition auxiliary.h:97
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:31
FILE * f
Definition checklibs.c:9
CanonicalForm convSingPFactoryP(poly p, const ring r)
Definition clapconv.cc:138
poly convFactoryPSingTrP(const CanonicalForm &f, const ring r)
Definition clapconv.cc:389
poly convFactoryAPSingAP(const CanonicalForm &f, const ring r)
Definition clapconv.cc:207
CanonicalForm convSingAPFactoryAP(poly p, const Variable &a, const ring r)
Definition clapconv.cc:171
poly convFactoryPSingP(const CanonicalForm &f, const ring r)
Definition clapconv.cc:40
CanonicalForm convSingTrPFactoryP(poly p, const ring r)
Definition clapconv.cc:339
factory's main class
factory's class for variables
Definition factory.h:127
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
CanonicalForm ndConvSingNFactoryN(number, BOOLEAN, const coeffs)
Definition numbers.cc:313
#define NULL
Definition omList.c:12
static BOOLEAN p_IsConstant(const poly p, const ring r)
Definition p_polys.h:1985
static void p_Delete(poly *p, const ring r)
Definition p_polys.h:903
static long p_Totaldegree(poly p, const ring r)
Definition p_polys.h:1528
#define p_Test(p, r)
Definition p_polys.h:161
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:314
static BOOLEAN rField_is_Zp(const ring r)
Definition ring.h:506
static BOOLEAN rField_is_Zn(const ring r)
Definition ring.h:523
static BOOLEAN rField_is_Q(const ring r)
Definition ring.h:517
#define R
Definition sirandom.c:27
#define Q
Definition sirandom.c:26
#define loop
Definition structs.h:71

◆ out_cf()

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

Definition at line 105 of file cf_factor.cc.

106{
107 printf("%s",s1);
108 if (f.isZero()) printf("+0");
109 //else if (! f.inCoeffDomain() )
110 else if (! f.inBaseDomain() )
111 {
112 int l = f.level();
113 for ( CFIterator i = f; i.hasTerms(); i++ )
114 {
115 int e=i.exp();
116 if (i.coeff().isOne())
117 {
118 printf("+");
119 if (e==0) printf("1");
120 else
121 {
122 printf("%c",'a'+l-1);
123 if (e!=1) printf("^%d",e);
124 }
125 }
126 else
127 {
128 out_cf("+(",i.coeff(),")");
129 if (e!=0)
130 {
131 printf("*%c",'a'+l-1);
132 if (e!=1) printf("^%d",e);
133 }
134 }
135 }
136 }
137 else
138 {
139 if ( f.isImm() )
140 {
142 {
143 long a= imm2int (f.getval());
144 if ( a == gf_q )
145 printf ("+%ld", a);
146 else if ( a == 0L )
147 printf ("+1");
148 else if ( a == 1L )
149 printf ("+%c",gf_name);
150 else
151 {
152 printf ("+%c",gf_name);
153 printf ("^%ld",a);
154 }
155 }
156 else
157 {
158 long l=f.intval();
159 if (l<0) printf("%ld",l);
160 else printf("+%ld",l);
161 }
162 }
163 else
164 {
165 #ifdef NOSTREAMIO
166 if (f.inZ())
167 {
168 mpz_t m;
170 char * str = new char[mpz_sizeinbase( m, 10 ) + 2];
171 str = mpz_get_str( str, 10, m );
172 puts(str);
173 delete[] str;
174 mpz_clear(m);
175 }
176 else if (f.inQ())
177 {
178 mpz_t m;
180 char * str = new char[mpz_sizeinbase( m, 10 ) + 2];
181 str = mpz_get_str( str, 10, m );
182 while(str[strlen(str)]<' ') { str[strlen(str)]='\0'; }
183 puts(str);putchar('/');
184 delete[] str;
185 mpz_clear(m);
187 str = new char[mpz_sizeinbase( m, 10 ) + 2];
188 str = mpz_get_str( str, 10, m );
189 while(str[strlen(str)]<' ') { str[strlen(str)]='\0'; }
190 puts(str);
191 delete[] str;
192 mpz_clear(m);
193 }
194 #else
195 std::cout << f;
196 #endif
197 }
198 //if (f.inZ()) printf("(Z)");
199 //else if (f.inQ()) printf("(Q)");
200 //else if (f.inFF()) printf("(FF)");
201 //else if (f.inPP()) printf("(PP)");
202 //else if (f.inGF()) printf("(PP)");
203 //else
204 if (f.inExtension()) printf("E(%d)",f.level());
205 }
206 printf("%s",s2);
207}
int l
Definition cfEzgcd.cc:100
int m
Definition cfEzgcd.cc:128
int i
Definition cfEzgcd.cc:132
#define GaloisFieldDomain
Definition cf_defs.h:18
void out_cf(const char *s1, const CanonicalForm &f, const char *s2)
Definition cf_factor.cc:105
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:699

◆ pGetExp_Var()

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

Definition at line 343 of file clapsing.cc.

344{
345 int m=0;
346 int mm;
347 while (p!=NULL)
348 {
349 mm=p_GetExp(p,i,r);
350 if (mm>m) m=mm;
351 pIter(p);
352 }
353 return m;
354}
int p
Definition cfModGcd.cc:4086
#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:471

◆ singclap_absFactorize()

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

Definition at line 2157 of file clapsing.cc.

2158{
2159 p_Test(f, r);
2160
2161 ideal res=NULL;
2162
2163 int offs = rPar(r);
2164 if (f==NULL)
2165 {
2166 res= idInit (1, 1);
2167 mipos= idInit (1, 1);
2168 mipos->m[0]= convFactoryPSingTrP (Variable (offs), r); //overkill
2169 (*exps)=new intvec (1);
2170 (**exps)[0]= 1;
2171 numFactors= 0;
2172 return res;
2173 }
2175
2176 bool isRat= isOn (SW_RATIONAL);
2177 if (!isRat)
2178 On (SW_RATIONAL);
2179
2180 CFAFList absFactors= absFactorize (F);
2181
2182 int n= absFactors.length();
2183 *exps=new intvec (n);
2184
2185 res= idInit (n, 1);
2186
2187 mipos= idInit (n, 1);
2188
2189 Variable x= Variable (offs);
2191 int i= 0;
2192 numFactors= 0;
2193 int count;
2194 CFAFListIterator iter= absFactors;
2195 CanonicalForm lead= iter.getItem().factor();
2196 if (iter.getItem().factor().inCoeffDomain())
2197 {
2198 i++;
2199 iter++;
2200 }
2201 for (; iter.hasItem(); iter++, i++)
2202 {
2203 (**exps)[i]= iter.getItem().exp();
2204 alpha= iter.getItem().minpoly().mvar();
2205 if (iter.getItem().minpoly().isOne())
2206 lead /= power (bCommonDen (iter.getItem().factor()), iter.getItem().exp());
2207 else
2208 lead /= power (power (bCommonDen (iter.getItem().factor()), degree (iter.getItem().minpoly())), iter.getItem().exp());
2209 res->m[i]= convFactoryPSingTrP (replacevar (iter.getItem().factor()*bCommonDen (iter.getItem().factor()), alpha, x), r);
2210 if (iter.getItem().minpoly().isOne())
2211 {
2212 count= iter.getItem().exp();
2213 mipos->m[i]= convFactoryPSingTrP (x,r);
2214 }
2215 else
2216 {
2217 count= iter.getItem().exp()*degree (iter.getItem().minpoly());
2218 mipos->m[i]= convFactoryPSingTrP (replacevar (iter.getItem().minpoly(), alpha, x), r);
2219 }
2220 if (!iter.getItem().minpoly().isOne())
2221 prune (alpha);
2222 numFactors += count;
2223 }
2224 if (!isRat)
2225 Off (SW_RATIONAL);
2226
2227 (**exps)[0]= 1;
2228 res->m[0]= convFactoryPSingTrP (lead, r);
2229 mipos->m[0]= convFactoryPSingTrP (x, r);
2230 return res;
2231}
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
ListIterator< CFAFactor > CFAFListIterator
int degree(const CanonicalForm &f)
List< CFAFactor > CFAFList
Variable x
Definition cfModGcd.cc:4090
CanonicalForm bCommonDen(const CanonicalForm &f)
void psqr ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & q, CanonicalForm & r,...
int length() const
CFFListIterator iter
Variable alpha
CFAFList absFactorize(const CanonicalForm &G)
absolute factorization of a multivariate poly over Q
CanonicalForm res
Definition facAbsFact.cc:60
static int rPar(const ring r)
(r->cf->P)
Definition ring.h:610
int status int void size_t count
Definition si_signals.h:69
ideal idInit(int idsize, int rank)
initialise an ideal / module

◆ singclap_det()

poly singclap_det ( const matrix m,
const ring s )

Definition at line 1811 of file clapsing.cc.

1812{
1813 int r=m->rows();
1814 if (r!=m->cols())
1815 {
1816 Werror("det of %d x %d matrix",r,m->cols());
1817 return NULL;
1818 }
1819 poly res=NULL;
1820 CFMatrix M(r,r);
1821 int i,j;
1822 for(i=r;i>0;i--)
1823 {
1824 for(j=r;j>0;j--)
1825 {
1827 }
1828 }
1831 return res;
1832}
Matrix< CanonicalForm > CFMatrix
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 1852 of file clapsing.cc.

1853{
1854 assume(m->basecoeffs()==cf);
1855 CFMatrix M(m->rows(),m->cols());
1856 int i,j;
1857 BOOLEAN setchar=TRUE;
1858 for(i=m->rows();i>0;i--)
1859 {
1860 for(j=m->cols();j>0;j--)
1861 {
1862 M(i,j)=n_convSingNFactoryN(BIMATELEM(*m,i,j),setchar,cf);
1863 setchar=FALSE;
1864 }
1865 }
1866 number res=n_convFactoryNSingN( determinant(M,m->rows()),cf ) ;
1867 return res;
1868}
int BOOLEAN
Definition auxiliary.h:88
#define BIMATELEM(M, I, J)
Definition bigintmat.h:133
CanonicalForm cf
Definition cfModGcd.cc:4091
static FORCE_INLINE number n_convFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition coeffs.h:984
static FORCE_INLINE CanonicalForm n_convSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition coeffs.h:987
#define assume(x)
Definition mod2.h:389

◆ singclap_det_i()

int singclap_det_i ( intvec * m,
const ring r )

Definition at line 1834 of file clapsing.cc.

1835{
1836// assume( r == currRing ); // Anything else is not guaranteed to work!
1837
1838 setCharacteristic( 0 );
1839 CFMatrix M(m->rows(),m->cols());
1840 int i,j;
1841 for(i=m->rows();i>0;i--)
1842 {
1843 for(j=m->cols();j>0;j--)
1844 {
1845 M(i,j)=IMATELEM(*m,i,j);
1846 }
1847 }
1848 int res= convFactoryISingI( determinant(M,m->rows()) ) ;
1849 return res;
1850}
void FACTORY_PUBLIC setCharacteristic(int c)
Definition cf_char.cc:28
int convFactoryISingI(const CanonicalForm &f)
Definition clapconv.cc:165
#define IMATELEM(M, I, J)
Definition intvec.h:86

◆ singclap_extgcd()

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

Definition at line 505 of file clapsing.cc.

506{
507 // for now there is only the possibility to handle univariate
508 // polynomials over
509 // Q and Fp ...
512 if ( rField_is_Q(r) || rField_is_Zp(r)
513 || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
514 {
519 CanonicalForm FpG=F+G;
520 if (!(FpG.isUnivariate()|| FpG.inCoeffDomain()))
521 //if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar())
522 {
524 WerrorS("not univariate");
525 return TRUE;
526 }
527 CanonicalForm Fa,Gb;
529 res=convFactoryPSingP( extgcd( F, G, Fa, Gb ),r );
530 pa=convFactoryPSingP(Fa,r);
531 pb=convFactoryPSingP(Gb,r);
533 }
534 // and over Q(a) / Fp(a)
535 else if ( r->cf->extRing!=NULL )
536 {
537 if (rField_is_Q_a(r)) setCharacteristic( 0 );
541 CanonicalForm Fa,Gb;
542 if (r->cf->extRing->qideal!=NULL)
543 {
544 CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
545 r->cf->extRing);
548 G( convSingAPFactoryAP( g,a,r ) );
549 CanonicalForm FpG=F+G;
550 if (!(FpG.isUnivariate()|| FpG.inCoeffDomain()))
551 //if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar())
552 {
553 WerrorS("not univariate");
554 return TRUE;
555 }
556 res= convFactoryAPSingAP( extgcd( F, G, Fa, Gb ),r );
559 prune (a);
560 }
561 else
562 {
564 CanonicalForm FpG=F+G;
565 if (!(FpG.isUnivariate()|| FpG.inCoeffDomain()))
566 //if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar())
567 {
569 WerrorS("not univariate");
570 return TRUE;
571 }
572 res= convFactoryPSingTrP( extgcd( F, G, Fa, Gb ), r );
573 pa=convFactoryPSingTrP(Fa, r);
574 pb=convFactoryPSingTrP(Gb, r);
575 }
577 }
578 else
579 {
581 return TRUE;
582 }
583#ifndef SING_NDEBUG
584 // checking the result of extgcd:
585 poly dummy;
586 dummy=p_Sub(p_Add_q(pp_Mult_qq(f,pa,r),pp_Mult_qq(g,pb,r),r),p_Copy(res,r),r);
587 if (dummy!=NULL)
588 {
589 PrintS("extgcd( ");p_Write(f,r);p_Write0(g,r);PrintS(" )\n");
590 PrintS("extgcd( ");p_Write(f,r);p_Write0(g,r);PrintS(" )\n");
591 p_Delete(&dummy,r);
592 }
593#endif
594 return FALSE;
595}
g
Definition cfModGcd.cc:4098
CanonicalForm extgcd(const CanonicalForm &f, const CanonicalForm &g, CanonicalForm &a, CanonicalForm &b)
CanonicalForm extgcd ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & a,...
static const int SW_SYMMETRIC_FF
set to 1 for symmetric representation over F_q
Definition cf_defs.h:33
#define MAX_CHAR_FACTORY
Definition clapsing.cc:66
bool inCoeffDomain() const
bool isUnivariate() const
static BOOLEAN pa(leftv res, leftv args)
Definition cohomo.cc:3770
static BOOLEAN pb(leftv res, leftv args)
Definition cohomo.cc:3796
STATIC_VAR TreeM * G
Definition janet.cc:31
poly p_Sub(poly p1, poly p2, const ring r)
Definition p_polys.cc:1994
static poly p_Add_q(poly p, poly q, const ring r)
Definition p_polys.h:938
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:1167
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition p_polys.h:848
void PrintS(const char *s)
Definition reporter.cc:288
static int rInternalChar(const ring r)
Definition ring.h:700
static BOOLEAN rField_is_Q_a(const ring r)
Definition ring.h:550

◆ singclap_factorize()

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

Definition at line 983 of file clapsing.cc.

985{
986 p_Test(f,r);
987#ifdef FACTORIZE2_DEBUG
988 printf("singclap_factorize, degree %ld\n",p_Totaldegree(f,r));
989#endif
990 // with_exps: 3,1 return only true factors, no exponents
991 // 2 return true factors and exponents
992 // 0 return coeff, factors and exponents
993 BOOLEAN save_errorreported=errorreported;
994
995 ideal res=NULL;
996
997 // handle factorize(0) =========================================
998 if (f==NULL)
999 {
1000 res=idInit(1,1);
1001 if (with_exps!=1)
1002 {
1003 (*v)=new intvec(1);
1004 (**v)[0]=1;
1005 }
1006 return res;
1007 }
1008 // handle factorize(mon) =========================================
1009 if (pNext(f)==NULL)
1010 {
1011 int i=0;
1012 int n=0;
1013 int e;
1014 for(i=rVar(r);i>0;i--) if(p_GetExp(f,i,r)!=0) n++;
1015 if (with_exps==0) n++; // with coeff
1016 res=idInit(si_max(n,1),1);
1017 switch(with_exps)
1018 {
1019 case 0: // with coef & exp.
1020 res->m[0]=p_NSet(n_Copy(pGetCoeff(f),r->cf),r);
1021 // no break
1022 case 2: // with exp.
1023 (*v)=new intvec(si_max(1,n));
1024 (**v)[0]=1;
1025 // no break
1026 case 1: ;
1027#ifdef TEST
1028 default: ;
1029#endif
1030 }
1031 if (n==0)
1032 {
1033 if (res->m[0]==NULL) res->m[0]=p_One(r);
1034 // (**v)[0]=1; is already done
1035 }
1036 else
1037 {
1038 for(i=rVar(r);i>0;i--)
1039 {
1040 e=p_GetExp(f,i,r);
1041 if(e!=0)
1042 {
1043 n--;
1044 poly p=p_One(r);
1045 p_SetExp(p,i,1,r);
1046 p_Setm(p,r);
1047 res->m[n]=p;
1048 if (with_exps!=1) (**v)[n]=e;
1049 }
1050 }
1051 }
1052 p_Delete(&f,r);
1053 return res;
1054 }
1055 //PrintS("S:");p_Write(f,r);PrintLn();
1056 // use factory/libfac in general ==============================
1057 Variable dummy(-1); prune(dummy); // remove all (tmp.) extensions
1060 CFFList L;
1061 number N=NULL;
1062 number NN=NULL;
1063 number old_lead_coeff=n_Copy(pGetCoeff(f), r->cf);
1064
1065 Variable a;
1066 if (r->cf->convSingNFactoryN!=ndConvSingNFactoryN)
1067 {
1068 if (rField_is_Q(r) || rField_is_Q_a(r) || rField_is_Z(r)) /* Q, Q(a), Z */
1069 {
1070 //if (f!=NULL) // already tested at start of routine
1071 {
1072 number n0=n_Copy(pGetCoeff(f),r->cf);
1073 if (with_exps==0)
1074 N=n_Copy(n0,r->cf);
1075 if (rField_is_Z(r)) p_Content(f, r);
1076 else p_Cleardenom(f, r);
1077 //after here f should not have a denominator!! and no content
1078 //PrintS("S:");p_Write(f,r);PrintLn();
1079 NN=n_Div(n0,pGetCoeff(f),r->cf);
1080 n_Delete(&n0,r->cf);
1081 if (with_exps==0)
1082 {
1083 n_Delete(&N,r->cf);
1084 N=n_Copy(NN,r->cf);
1085 }
1086 }
1087 }
1088 else if (rField_is_Zp_a(r))
1089 {
1090 //if (f!=NULL) // already tested at start of routine
1092 {
1093 number n0=n_Copy(pGetCoeff(f),r->cf);
1094 if (with_exps==0)
1095 N=n_Copy(n0,r->cf);
1096 p_Norm(f,r);
1097 p_Cleardenom(f, r);
1098 NN=n_Div(n0,pGetCoeff(f),r->cf);
1099 n_Delete(&n0,r->cf);
1100 if (with_exps==0)
1101 {
1102 n_Delete(&N,r->cf);
1103 N=n_Copy(NN,r->cf);
1104 }
1105 }
1106 }
1107 if (rField_is_Q(r) || rField_is_Zp(r) || rField_is_Z(r) || rField_is_Zn(r))
1108 {
1112 if (errorreported) goto notImpl; // char too large
1114 L = factorize( F );
1115 }
1116 // and over Q(a) / Fp(a)
1117 else if (r->cf->extRing!=NULL)
1118 {
1119 if (rField_is_Q_a (r)) setCharacteristic (0);
1123 if (errorreported) goto notImpl; // char too large
1124 if (r->cf->extRing->qideal!=NULL) /*algebraic extension */
1125 {
1126 CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
1127 r->cf->extRing);
1128 a=rootOf(mipo);
1129 CanonicalForm F( convSingAPFactoryAP( f, a, r ) );
1130 L = factorize( F, a );
1131 prune(a);
1132 }
1133 else /* rational functions */
1134 {
1136 L = factorize( F );
1137 }
1138 }
1139 else
1140 {
1141 goto notImpl;
1142 }
1143 }
1144 else
1145 {
1146 goto notImpl;
1147 }
1148 if (errorreported)
1149 {
1151 }
1152 {
1153 poly ff=p_Copy(f,r); // a copy for the retry stuff
1154 // the first factor should be a constant
1155 if ( ! L.getFirst().factor().inCoeffDomain() )
1156 L.insert(CFFactor(1,1));
1157 // convert into ideal
1158 int n = L.length();
1159 if (n==0) n=1;
1160 CFFListIterator J=L;
1161 int j=0;
1162 if (with_exps!=1)
1163 {
1164 if ((with_exps==2)&&(n>1))
1165 {
1166 n--;
1167 J++;
1168 }
1169 *v = new intvec( n );
1170 }
1171 res = idInit( n ,1);
1172 for ( ; J.hasItem(); J++, j++ )
1173 {
1174 if (with_exps!=1) (**v)[j] = J.getItem().exp();
1175 if (rField_is_Zp(r) || rField_is_Q(r)|| rField_is_Z(r)
1176 || rField_is_Zn(r)) /* Q, Fp, Z */
1177 {
1178 //count_Factors(res,*v,f, j, convFactoryPSingP( J.getItem().factor() );
1179 res->m[j] = convFactoryPSingP( J.getItem().factor(),r );
1180 }
1181#if 0
1182 else if (rField_is_GF())
1183 res->m[j] = convFactoryGFSingGF( J.getItem().factor() );
1184#endif
1185 else if (r->cf->extRing!=NULL) /* Q(a), Fp(a) */
1186 {
1187#ifndef SING_NDEBUG
1188 intvec *w=NULL;
1189 if (v!=NULL) w=*v;
1190#endif
1191 if (r->cf->extRing->qideal==NULL)
1192 {
1193#ifdef SING_NDEBUG
1194 res->m[j]= convFactoryPSingTrP( J.getItem().factor(),r );
1195#else
1196 if(!count_Factors(res,w,j,ff,convFactoryPSingTrP( J.getItem().factor(),r ),r))
1197 {
1198 if (w!=NULL)
1199 (*w)[j]=1;
1200 res->m[j]=p_One(r);
1201 }
1202#endif
1203 }
1204 else
1205 {
1206#ifdef SING_NDEBUG
1207 res->m[j]= convFactoryAPSingAP( J.getItem().factor(),r );
1208#else
1209 if (!count_Factors(res,w,j,ff,convFactoryAPSingAP( J.getItem().factor(),r ),r))
1210 {
1211 if (w!=NULL)
1212 (*w)[j]=1;
1213 res->m[j]=p_One(r);
1214 }
1215#endif
1216 }
1217 }
1218 }
1219 if (r->cf->extRing!=NULL)
1220 if (r->cf->extRing->qideal!=NULL)
1221 prune (a);
1222#ifndef SING_NDEBUG
1223 if ((r->cf->extRing!=NULL) && (!p_IsConstant(ff,r)))
1224 {
1227 {
1228 int jj;
1229#ifdef FACTORIZE2_DEBUG
1230 printf("factorize_retry\n");
1231#endif
1232 intvec *ww=NULL;
1233 id_Test(res,r);
1234 ideal h=singclap_factorize ( ff, &ww , with_exps, r );
1235 id_Test(h,r);
1236 int l=(*v)->length();
1237 (*v)->resize(l+ww->length());
1238 for(jj=0;jj<ww->length();jj++)
1239 (**v)[jj+l]=(*ww)[jj];
1240 delete ww;
1241 ideal hh=idInit(IDELEMS(res)+IDELEMS(h),1);
1242 for(jj=IDELEMS(res)-1;jj>=0;jj--)
1243 {
1244 hh->m[jj]=res->m[jj];
1245 res->m[jj]=NULL;
1246 }
1247 for(jj=IDELEMS(h)-1;jj>=0;jj--)
1248 {
1249 hh->m[jj+IDELEMS(res)]=h->m[jj];
1250 h->m[jj]=NULL;
1251 }
1252 id_Delete(&res,r);
1253 id_Delete(&h,r);
1254 res=hh;
1255 id_Test(res,r);
1256 ff=NULL;
1257 }
1258 else
1259 {
1260 WarnS("problem with factorize");
1261#if 0
1262 pWrite(ff);
1263 idShow(res);
1264#endif
1265 id_Delete(&res,r);
1266 res=idInit(2,1);
1267 res->m[0]=p_One(r);
1268 res->m[1]=ff; ff=NULL;
1269 }
1270 }
1271#endif
1272 p_Delete(&ff,r);
1273 if (N!=NULL)
1274 {
1275 __p_Mult_nn(res->m[0],N,r);
1276 n_Delete(&N,r->cf);
1277 N=NULL;
1278 }
1279 // delete constants
1280 if (res!=NULL)
1281 {
1282 int i=IDELEMS(res)-1;
1283 int j=0;
1284 for(;i>=0;i--)
1285 {
1286 if ((res->m[i]!=NULL)
1287 && (pNext(res->m[i])==NULL)
1288 && (p_IsConstant(res->m[i],r)))
1289 {
1290 if (with_exps!=0)
1291 {
1292 p_Delete(&(res->m[i]),r);
1293 if ((v!=NULL) && ((*v)!=NULL))
1294 (**v)[i]=0;
1295 j++;
1296 }
1297 else if (i!=0)
1298 {
1299 while ((v!=NULL) && ((*v)!=NULL) && ((**v)[i]>1))
1300 {
1301 res->m[0]=p_Mult_q(res->m[0],p_Copy(res->m[i],r),r);
1302 (**v)[i]--;
1303 }
1304 res->m[0]=p_Mult_q(res->m[0],res->m[i],r);
1305 res->m[i]=NULL;
1306 if ((v!=NULL) && ((*v)!=NULL))
1307 (**v)[i]=1;
1308 j++;
1309 }
1310 }
1311 }
1312 if (j>0)
1313 {
1315 if ((v!=NULL) && ((*v)!=NULL))
1316 {
1317 intvec *w=*v;
1318 int len=IDELEMS(res);
1319 *v = new intvec( len );
1320 for (i=0,j=0;i<si_min(w->length(),len);i++)
1321 {
1322 if((*w)[i]!=0)
1323 {
1324 (**v)[j]=(*w)[i]; j++;
1325 }
1326 }
1327 delete w;
1328 }
1329 }
1330 if (res->m[0]==NULL)
1331 {
1332 res->m[0]=p_One(r);
1333 }
1334 }
1335 }
1336 if (rField_is_Q_a(r) && (r->cf->extRing->qideal!=NULL))
1337 {
1338 int i=IDELEMS(res)-1;
1339 int stop=1;
1340 if (with_exps!=0) stop=0;
1341 for(;i>=stop;i--)
1342 {
1343 p_Norm(res->m[i],r);
1344 }
1345 if (with_exps==0) p_SetCoeff(res->m[0],old_lead_coeff,r);
1346 else n_Delete(&old_lead_coeff,r->cf);
1347 }
1348 else
1349 n_Delete(&old_lead_coeff,r->cf);
1350 errorreported=save_errorreported;
1351notImpl:
1352 prune(a);
1353 if (res==NULL)
1354 {
1356 if ((v!=NULL) && ((*v)!=NULL) &&(with_exps==2))
1357 {
1358 *v = new intvec( 1 );
1359 (*v)[0]=1;
1360 }
1361 res=idInit(2,1);
1362 res->m[0]=p_One(r);
1363 res->m[1]=f;
1364 }
1365 else p_Delete(&f,r);
1366 if (NN!=NULL)
1367 {
1368 n_Delete(&NN,r->cf);
1369 }
1370 if (N!=NULL)
1371 {
1372 n_Delete(&N,r->cf);
1373 }
1374 return res;
1375}
static int si_max(const int a, const int b)
Definition auxiliary.h:125
static int si_min(const int a, const int b)
Definition auxiliary.h:126
ListIterator< CFFactor > CFFListIterator
List< CFFactor > CFFList
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:411
BOOLEAN count_Factors(ideal I, intvec *v, int j, poly &f, poly fac, const ring r)
Definition clapsing.cc:893
ideal singclap_factorize(poly f, intvec **v, int with_exps, const ring r)
Definition clapsing.cc:983
VAR int singclap_factorize_retry
Definition clapsing.cc:981
int exp() const
T factor() const
T & getItem() const
T getFirst() const
void insert(const T &)
int length() const
Definition intvec.h:95
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
Definition coeffs.h:457
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:618
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition coeffs.h:461
#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:2343
void p_Norm(poly p1, const ring r)
Definition p_polys.cc:3844
poly p_Cleardenom(poly p, const ring r)
Definition p_polys.cc:2893
poly p_One(const ring r)
Definition p_polys.cc:1314
poly p_NSet(number n, const ring r)
returns the poly representing the number n, destroys n
Definition p_polys.cc:1474
static poly p_Mult_q(poly p, poly q, const ring r)
Definition p_polys.h:1125
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:490
static void p_Setm(poly p, const ring r)
Definition p_polys.h:235
static number p_SetCoeff(poly p, number n, ring r)
Definition p_polys.h:414
#define __p_Mult_nn(p, n, r)
Definition p_polys.h:973
void pWrite(poly p)
Definition polys.h:309
static BOOLEAN rField_is_Zp_a(const ring r)
Definition ring.h:540
static BOOLEAN rField_is_Z(const ring r)
Definition ring.h:520
static BOOLEAN rField_is_GF(const ring r)
Definition ring.h:532
static short rVar(const ring r)
define rVar(r) (r->N)
Definition ring.h:603
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
void idShow(const ideal id, const ring lmRing, const ring tailRing, const int debugPrint)
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
#define IDELEMS(i)
#define id_Test(A, lR)

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

179{
180 poly res=NULL;
181
182 if (g == NULL)
183 {
184 res= f;
185 f=p_One (r);
186 return res;
187 }
188 if (f==NULL)
189 {
190 res= g;
191 g=p_One (r);
192 return res;
193 }
194 if (pNext(g)==NULL)
195 {
196 poly G=p_GcdMon(g,f,r);
197 if (!n_IsOne(pGetCoeff(G),r->cf)
198 || (!p_IsConstant(G,r)))
199 {
200 f=p_Div_mm(f,G,r);
201 g=p_Div_mm(g,G,r);
202 }
203 return G;
204 }
205 else if (pNext(f)==NULL)
206 {
207 poly G=p_GcdMon(f,g,r);
208 if (!n_IsOne(pGetCoeff(G),r->cf)
209 || (!p_IsConstant(G,r)))
210 {
211 f=p_Div_mm(f,G,r);
212 g=p_Div_mm(g,G,r);
213 }
214 return G;
215 }
216
218 CanonicalForm F,G,GCD;
219 if (rField_is_Q(r) || (rField_is_Zp(r))
220 || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
221 {
222 bool b1=isOn(SW_USE_EZGCD_P);
226 F=convSingPFactoryP( f,r );
227 G=convSingPFactoryP( g,r );
228 GCD=gcd(F,G);
229 if (!GCD.isOne())
230 {
231 p_Delete(&f,r);
232 p_Delete(&g,r);
233 if (getCharacteristic() == 0)
234 On (SW_RATIONAL);
235 F /= GCD;
236 G /= GCD;
237 if (getCharacteristic() == 0)
238 {
239 CanonicalForm denF= bCommonDen (F);
240 CanonicalForm denG= bCommonDen (G);
241 G *= denG;
242 F *= denF;
244 CanonicalForm gcddenFdenG= gcd (denG, denF);
245 denG /= gcddenFdenG;
246 denF /= gcddenFdenG;
247 On (SW_RATIONAL);
248 G *= denF;
249 F *= denG;
250 }
251 f=convFactoryPSingP( F, r);
252 g=convFactoryPSingP( G, r);
253 }
254 res=convFactoryPSingP( GCD , r);
255 if (!b1) Off (SW_USE_EZGCD_P);
256 }
257 // and over Q(a) / Fp(a)
258 else if ( r->cf->extRing )
259 {
260 if ( rField_is_Q_a(r)) setCharacteristic( 0 );
264 if (r->cf->extRing->qideal!=NULL)
265 {
266 bool b1=isOn(SW_USE_QGCD);
267 if ( rField_is_Q_a(r) ) On(SW_USE_QGCD);
268 CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
269 r->cf->extRing);
271 F=( convSingAPFactoryAP( f,a,r ) );
272 G=( convSingAPFactoryAP( g,a,r ) );
273 GCD=gcd(F,G);
274 if (!GCD.isOne())
275 {
276 p_Delete(&f,r);
277 p_Delete(&g,r);
278 if (getCharacteristic() == 0)
279 On (SW_RATIONAL);
280 F /= GCD;
281 G /= GCD;
282 if (getCharacteristic() == 0)
283 {
284 CanonicalForm denF= bCommonDen (F);
285 CanonicalForm denG= bCommonDen (G);
286 G *= denG;
287 F *= denF;
289 CanonicalForm gcddenFdenG= gcd (denG, denF);
290 denG /= gcddenFdenG;
291 denF /= gcddenFdenG;
292 On (SW_RATIONAL);
293 G *= denF;
294 F *= denG;
295 }
296 f= convFactoryAPSingAP( F,r );
297 g= convFactoryAPSingAP( G,r );
298 }
299 res= convFactoryAPSingAP( GCD,r );
300 prune (a);
301 if (!b1) Off(SW_USE_QGCD);
302 }
303 else
304 {
305 F=( convSingTrPFactoryP( f,r ) );
306 G=( convSingTrPFactoryP( g,r ) );
307 GCD=gcd(F,G);
308 if (!GCD.isOne())
309 {
310 p_Delete(&f,r);
311 p_Delete(&g,r);
312 if (getCharacteristic() == 0)
313 On (SW_RATIONAL);
314 F /= GCD;
315 G /= GCD;
316 if (getCharacteristic() == 0)
317 {
318 CanonicalForm denF= bCommonDen (F);
319 CanonicalForm denG= bCommonDen (G);
320 G *= denG;
321 F *= denF;
323 CanonicalForm gcddenFdenG= gcd (denG, denF);
324 denG /= gcddenFdenG;
325 denF /= gcddenFdenG;
326 On (SW_RATIONAL);
327 G *= denF;
328 F *= denG;
329 }
330 f= convFactoryPSingTrP( F,r );
331 g= convFactoryPSingTrP( G,r );
332 }
333 res= convFactoryPSingTrP( GCD,r );
334 }
335 }
336 else
339 return res;
340}
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:43
static const int SW_USE_EZGCD_P
set to 1 to use EZGCD over F_q
Definition cf_defs.h:37
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:474
poly p_GcdMon(poly f, poly g, const ring r)
polynomial gcd for f=mon
Definition p_polys.cc:5097
poly p_Div_mm(poly p, const poly m, const ring r)
divide polynomial by monomial
Definition p_polys.cc:1542
int gcd(int a, int b)

◆ singclap_gcd_r()

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

Definition at line 70 of file clapsing.cc.

71{
72 poly res=NULL;
73
74 assume(f!=NULL);
75 assume(g!=NULL);
76
77 if(pNext(f)==NULL)
78 {
79 return p_GcdMon(f,g,r);
80 }
81 else if(pNext(g)==NULL)
82 {
83 return p_GcdMon(g,f,r);
84 }
85 #ifdef HAVE_FLINT
86 #if __FLINT_RELEASE >= 20503
87 if (rField_is_Zp(r) && (r->cf->ch>10))
88 {
89 nmod_mpoly_ctx_t ctx;
90 if (!convSingRFlintR(ctx,r))
91 {
92 // leading coef. 1
93 return Flint_GCD_MP(f,pLength(f),g,pLength(g),ctx,r);
94 }
95 }
96 else
97 if (rField_is_Q(r))
98 {
99 fmpq_mpoly_ctx_t ctx;
100 if (!convSingRFlintR(ctx,r))
101 {
102 // leading coef. positive, all coeffs in Z
103 poly res=Flint_GCD_MP(f,pLength(f),g,pLength(g),ctx,r);
105 return res;
106 }
107 }
108 else
109 if (rField_is_Z(r))
110 {
111 fmpz_mpoly_ctx_t ctx;
112 if (!convSingRFlintR(ctx,r))
113 {
114 // leading coef. positive, all coeffs in Z
115 poly res=Flint_GCD_MP(f,pLength(f),g,pLength(g),ctx,r);
116 return res;
117 }
118 }
119 #endif
120 #endif
122 if (rField_is_Q(r) || rField_is_Zp(r) || rField_is_Z(r)
123 || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
124 {
129 res=convFactoryPSingP( gcd( F, G ) , r);
130 if ( rField_is_Zp(r))
131 p_Norm(res,r); // leading coef. 1
132 else if (rField_is_Q(r) && (!n_GreaterZero(pGetCoeff(res),r->cf)))
133 res = p_Neg(res,r); // leading coef. positive, all coeffs in Z
134 }
135 // and over Q(a) / Fp(a)
136 else if ( r->cf->extRing!=NULL )
137 {
138 if ( rField_is_Q_a(r)) setCharacteristic( 0 );
142 if (r->cf->extRing->qideal!=NULL)
143 {
144 bool b1=isOn(SW_USE_QGCD);
145 if ( rField_is_Q_a(r) ) On(SW_USE_QGCD);
146 CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
147 r->cf->extRing);
150 G( convSingAPFactoryAP( g,a,r ) );
151 res= convFactoryAPSingAP( gcd( F, G ),r );
152 prune (a);
153 if (!b1) Off(SW_USE_QGCD);
154 if ( rField_is_Zp_a(r)) p_Norm(res,r); // leading coef. 1
155 }
156 else
157 {
158 convSingTrP(f,r);
159 convSingTrP(g,r);
161 res= convFactoryPSingTrP( gcd( F, G ),r );
162 }
163 }
164 else if (r->cf->convSingNFactoryN==ndConvSingNFactoryN)
166 else
167 { // handle user type coeffs:
172 res=convFactoryPSingP( gcd( F, G ) , r);
173 }
175 return res;
176}
BOOLEAN convSingTrP(poly p, const ring r)
Definition clapconv.cc:375
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:500
static poly p_Neg(poly p, const ring r)
Definition p_polys.h:1114
static int pLength(poly a)
Definition p_polys.h:190

◆ singclap_irrCharSeries()

matrix singclap_irrCharSeries ( ideal I,
const ring r )

Definition at line 1614 of file clapsing.cc.

1615{
1616 if (idIs0(I)) return mpNew(1,1);
1617
1618 // for now there is only the possibility to handle polynomials over
1619 // Q and Fp ...
1620 matrix res=NULL;
1621 int i;
1624 CFList L;
1625 ListCFList LL;
1626 if (rField_is_Q(r) || rField_is_Zp(r)
1627 || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
1628 {
1632 for(i=0;i<IDELEMS(I);i++)
1633 {
1634 poly p=I->m[i];
1635 if (p!=NULL)
1636 {
1637 p=p_Copy(p,r);
1638 p_Cleardenom(p, r);
1640 p_Delete(&p,r);
1641 }
1642 }
1643 }
1644 // and over Q(a) / Fp(a)
1645 else if (nCoeff_is_transExt (r->cf))
1646 {
1650 for(i=0;i<IDELEMS(I);i++)
1651 {
1652 poly p=I->m[i];
1653 if (p!=NULL)
1654 {
1655 p=p_Copy(p,r);
1656 p_Cleardenom(p, r);
1658 p_Delete(&p,r);
1659 }
1660 }
1661 }
1662 else
1663 {
1665 return res;
1666 }
1667
1668 // a very bad work-around --- FIX IT in libfac
1669 // should be fixed as of 2001/6/27
1670 int tries=0;
1671 int m,n;
1673 loop
1674 {
1675 LL=irrCharSeries(L);
1676 m= LL.length(); // Anzahl Zeilen
1677 n=0;
1678 for ( LLi = LL; LLi.hasItem(); LLi++ )
1679 {
1680 n = si_max(LLi.getItem().length(),n);
1681 }
1682 if ((m!=0) && (n!=0)) break;
1683 tries++;
1684 if (tries>=5) break;
1685 }
1686 if ((m==0) || (n==0))
1687 {
1688 Warn("char_series returns %d x %d matrix from %d input polys (%d)",
1689 m,n,IDELEMS(I)+1,LL.length());
1690 iiWriteMatrix((matrix)I,"I",2,r,0);
1691 m=si_max(m,1);
1692 n=si_max(n,1);
1693 }
1694 res=mpNew(m,n);
1695 CFListIterator Li;
1696 for ( m=1, LLi = LL; LLi.hasItem(); LLi++, m++ )
1697 {
1698 for (n=1, Li = LLi.getItem(); Li.hasItem(); Li++, n++)
1699 {
1700 if (rField_is_Q(r) || rField_is_Zp(r)
1701 || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
1703 else
1705 }
1706 }
1708 return res;
1709}
List< CFList > ListCFList
ListIterator< CanonicalForm > CFListIterator
List< CanonicalForm > CFList
ListCFList irrCharSeries(const CFList &PS)
irreducible characteristic series
void append(const T &)
static FORCE_INLINE BOOLEAN nCoeff_is_transExt(const coeffs r)
TRUE iff r represents a transcendental extension field.
Definition coeffs.h:916
#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:828
ip_smatrix * matrix
Definition matpol.h:43

◆ singclap_neworder()

char * singclap_neworder ( ideal I,
const ring r )

Definition at line 1711 of file clapsing.cc.

1712{
1713 if(idIs0(I)) return rVarStr(r);
1714 int i;
1717 CFList L;
1718 if (rField_is_Q(r) || rField_is_Zp(r)
1719 || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
1720 {
1724 for(i=0;i<IDELEMS(I);i++)
1725 {
1726 poly p=I->m[i];
1727 if (p!=NULL)
1728 {
1729 p=p_Copy(p,r);
1730 p_Cleardenom(p, r);
1732 p_Delete(&p,r);
1733 }
1734 }
1735 }
1736 // and over Q(a) / Fp(a)
1737 else if (nCoeff_is_transExt (r->cf))
1738 {
1742 for(i=0;i<IDELEMS(I);i++)
1743 {
1744 poly p=I->m[i];
1745 if (p!=NULL)
1746 {
1747 p=p_Copy(p,r);
1748 p_Cleardenom(p, r);
1750 p_Delete(&p,r);
1751 }
1752 }
1753 }
1754 else
1755 {
1757 return NULL;
1758 }
1759
1760 List<int> IL=neworderint(L);
1762 StringSetS("");
1763 Li = IL;
1764 int offs=rPar(r);
1765 int* mark=(int*)omAlloc0((rVar(r)+offs)*sizeof(int));
1766 int cnt=rVar(r)+offs;
1767 loop
1768 {
1769 if(! Li.hasItem()) break;
1770 BOOLEAN done=TRUE;
1771 i=Li.getItem()-1;
1772 mark[i]=1;
1773 if (i<offs)
1774 {
1775 done=FALSE;
1776 //StringAppendS(r->parameter[i]);
1777 }
1778 else
1779 {
1780 StringAppendS(r->names[i-offs]);
1781 }
1782 Li++;
1783 cnt--;
1784 if(cnt==0) break;
1785 if (done) StringAppendS(",");
1786 }
1787 for(i=0;i<rVar(r)+offs;i++)
1788 {
1789 BOOLEAN done=TRUE;
1790 if(mark[i]==0)
1791 {
1792 if (i<offs)
1793 {
1794 done=FALSE;
1795 //StringAppendS(r->parameter[i]);
1796 }
1797 else
1798 {
1799 StringAppendS(r->names[i-offs]);
1800 }
1801 cnt--;
1802 if(cnt==0) break;
1803 if (done) StringAppendS(",");
1804 }
1805 }
1806 char * s=StringEndS();
1807 if (s[strlen(s)-1]==',') s[strlen(s)-1]='\0';
1808 return s;
1809}
IntList neworderint(const CFList &PolyList)
Definition cfCharSets.cc:88
#define omAlloc0(size)
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
char * rVarStr(ring r)
Definition ring.cc:628

◆ singclap_pdivide()

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

Definition at line 649 of file clapsing.cc.

650{
651 poly res=NULL;
652
653 #ifdef HAVE_FLINT
654 #if __FLINT_RELEASE >= 20503
655 /*
656 If the division is not exact, control will pass to factory where the
657 polynomials can be divided using the ordering that factory chooses.
658 */
659 if (rField_is_Zp(r))
660 {
661 nmod_mpoly_ctx_t ctx;
662 if (!convSingRFlintR(ctx,r))
663 {
664 res = Flint_Divide_MP(f,0,g,0,ctx,r);
665 if (res != NULL)
666 return res;
667 }
668 }
669 else
670 if (rField_is_Q(r))
671 {
672 fmpq_mpoly_ctx_t ctx;
673 if (!convSingRFlintR(ctx,r))
674 {
675 res = Flint_Divide_MP(f,0,g,0,ctx,r);
676 if (res != NULL)
677 return res;
678 }
679 }
680 #endif
681 #endif
682
684 if (rField_is_Zp(r) || rField_is_Q(r)
685 || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
686 {
691 res = convFactoryPSingP( F / G,r );
692 }
693 // div is not implemented for ZZ coeffs in factory
694 else if (r->cf->extRing!=NULL)
695 {
696 if (rField_is_Q_a(r)) setCharacteristic( 0 );
700 if (r->cf->extRing->qideal!=NULL)
701 {
702 CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
703 r->cf->extRing);
706 G( convSingAPFactoryAP( g,a,r ) );
707 res= convFactoryAPSingAP( F / G, r );
708 prune (a);
709 }
710 else
711 {
713 res= convFactoryPSingTrP( F / G,r );
714 }
715 }
716#if 0 // not yet working
717 else if (rField_is_GF())
718 {
719 //Print("GF(%d^%d)\n",nfCharP,nfMinPoly[0]);
720 setCharacteristic( nfCharP,nfMinPoly[0], currRing->parameter[0][0] );
722 CanonicalForm F( convSingGFFactoryGF( f ) ), G( convSingGFFactoryGF( g ) );
723 res = convFactoryGFSingGF( F / G );
724 }
725#endif
726 else
729 return res;
730}
STATIC_VAR int nfMinPoly[16]
Definition ffields.cc:545
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 732 of file clapsing.cc.

733{
734 poly res=NULL;
736 if (rField_is_Zp(r) || rField_is_Q(r)
737 || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
738 {
744 divrem(F,G,Q,R);
746 //res = convFactoryPSingP( F-(F/G)*G,r );
747 }
748 // mod is not implemented for ZZ coeffs in factory
749 else if (r->cf->extRing!=NULL)
750 {
751 if (rField_is_Q_a(r)) setCharacteristic( 0 );
755 if (r->cf->extRing->qideal!=NULL)
756 {
757 CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
758 r->cf->extRing);
761 G( convSingAPFactoryAP( g,a,r ) );
763 divrem(F,G,Q,R);
765 //res= convFactoryAPSingAP( F-(F/G)*G, r );
766 prune (a);
767 }
768 else
769 {
772 divrem(F,G,Q,R);
774 //res= convFactoryPSingTrP( F-(F/G)*G,r );
775 }
776 }
777#if 0 // not yet working
778 else if (rField_is_GF())
779 {
780 //Print("GF(%d^%d)\n",nfCharP,nfMinPoly[0]);
781 setCharacteristic( nfCharP,nfMinPoly[0], currRing->parameter[0][0] );
783 CanonicalForm F( convSingGFFactoryGF( f ) ), G( convSingGFFactoryGF( g ) );
784 res = convFactoryGFSingGF( F / G );
785 }
786#endif
787 else
790 return res;
791}
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 597 of file clapsing.cc.

598{
599 poly res=NULL;
601 if (rField_is_Zp(r) || rField_is_Q(r) || rField_is_Z(r)
602 || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
603 {
604 if (rField_is_Z(r)) Off(SW_RATIONAL);
609 res = convFactoryPSingP( F * G,r );
610 }
611 else if (r->cf->extRing!=NULL)
612 {
613 if (rField_is_Q_a(r)) setCharacteristic( 0 );
617 if (r->cf->extRing->qideal!=NULL)
618 {
619 CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
620 r->cf->extRing);
623 G( convSingAPFactoryAP( g,a,r ) );
624 res= convFactoryAPSingAP( F * G, r );
625 prune (a);
626 }
627 else
628 {
630 res= convFactoryPSingTrP( F * G,r );
631 }
632 }
633#if 0 // not yet working
634 else if (rField_is_GF())
635 {
636 //Print("GF(%d^%d)\n",nfCharP,nfMinPoly[0]);
637 setCharacteristic( nfCharP,nfMinPoly[0], currRing->parameter[0][0] );
639 CanonicalForm F( convSingGFFactoryGF( f ) ), G( convSingGFFactoryGF( g ) );
640 res = convFactoryGFSingGF( F * G );
641 }
642#endif
643 else
646 return res;
647}

◆ singclap_resultant()

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

Definition at line 357 of file clapsing.cc.

358{
359 poly res=NULL;
360 int i=p_IsPurePower(x, r);
361 if (i==0)
362 {
363 WerrorS("3rd argument must be a ring variable");
364 goto resultant_returns_res;
365 }
366 if ((f==NULL) || (g==NULL))
367 goto resultant_returns_res;
368 // for now there is only the possibility to handle polynomials over
369 // Q and Fp ...
370 if (rField_is_Zp(r) || rField_is_Q(r) || rField_is_Z(r)
371 || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
372 {
373 Variable X(i);
378 res=convFactoryPSingP( resultant( F, G, X),r );
380 goto resultant_returns_res;
381 }
382 // and over Q(a) / Fp(a)
383 else if (r->cf->extRing!=NULL)
384 {
385 if (rField_is_Q_a(r)) setCharacteristic( 0 );
389 Variable X(i+rPar(r));
390 if (r->cf->extRing->qideal!=NULL)
391 {
392 //Variable X(i);
393 CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
394 r->cf->extRing);
397 G( convSingAPFactoryAP( g,a,r ) );
398 res= convFactoryAPSingAP( resultant( F, G, X ),r );
399 prune (a);
400 }
401 else
402 {
403 //Variable X(i+rPar(currRing));
404 number nf,ng;
406 int ef,eg;
407 ef=pGetExp_Var(f,i,r);
408 eg=pGetExp_Var(g,i,r);
410 res= convFactoryPSingTrP( resultant( F, G, X ),r );
411 if ((nf!=NULL)&&(!n_IsOne(nf,r->cf)))
412 {
413 number n=n_Invers(nf,r->cf);
414 while(eg>0)
415 {
416 res=__p_Mult_nn(res,n,r);
417 eg--;
418 }
419 n_Delete(&n,r->cf);
420 }
421 n_Delete(&nf,r->cf);
422 if ((ng!=NULL)&&(!n_IsOne(ng,r->cf)))
423 {
424 number n=n_Invers(ng,r->cf);
425 while(ef>0)
426 {
427 res=__p_Mult_nn(res,n,r);
428 ef--;
429 }
430 n_Delete(&n,r->cf);
431 }
432 n_Delete(&ng,r->cf);
433 }
435 goto resultant_returns_res;
436 }
437 else
439resultant_returns_res:
440 p_Delete(&f,r);
441 p_Delete(&g,r);
442 p_Delete(&x,r);
443 return res;
444}
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:343
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:567
int p_IsPurePower(const poly p, const ring r)
return i, if head depends only on var(i)
Definition p_polys.cc:1227
void p_Cleardenom_n(poly ph, const ring r, number &c)
Definition p_polys.cc:3002
Definition gnumpfl.cc:25

◆ singclap_sqrfree()

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

Definition at line 1377 of file clapsing.cc.

1378{
1379 p_Test(f,r);
1380#ifdef FACTORIZE2_DEBUG
1381 printf("singclap_sqrfree, degree %d\n",pTotaldegree(f));
1382#endif
1383 // with_exps: 3,1 return only true factors, no exponents
1384 // 2 return true factors and exponents
1385 // 0 return coeff, factors and exponents
1386 BOOLEAN save_errorreported=errorreported;
1387
1388 ideal res=NULL;
1389
1390 // handle factorize(0) =========================================
1391 if (f==NULL)
1392 {
1393 res=idInit(1,1);
1394 if (with_exps!=1 && with_exps!=3)
1395 {
1396 (*v)=new intvec(1);
1397 (**v)[0]=1;
1398 }
1399 return res;
1400 }
1401 // handle factorize(mon) =========================================
1402 if (pNext(f)==NULL)
1403 {
1404 int i=0;
1405 int n=0;
1406 int e;
1407 for(i=rVar(r);i>0;i--) if(p_GetExp(f,i,r)!=0) n++;
1408 if (with_exps==0 || with_exps==3) n++; // with coeff
1409 res=idInit(si_max(n,1),1);
1410 if(with_exps!=1)
1411 {
1412 (*v)=new intvec(si_max(1,n));
1413 (**v)[0]=1;
1414 }
1415 res->m[0]=p_NSet(n_Copy(pGetCoeff(f),r->cf),r);
1416 if (n==0)
1417 {
1418 res->m[0]=p_One(r);
1419 // (**v)[0]=1; is already done
1420 }
1421 else
1422 {
1423 for(i=rVar(r);i>0;i--)
1424 {
1425 e=p_GetExp(f,i,r);
1426 if(e!=0)
1427 {
1428 n--;
1429 poly p=p_One(r);
1430 p_SetExp(p,i,1,r);
1431 p_Setm(p,r);
1432 res->m[n]=p;
1433 if (with_exps!=1) (**v)[n]=e;
1434 }
1435 }
1436 }
1437 p_Delete(&f,r);
1438 return res;
1439 }
1440 //PrintS("S:");pWrite(f);PrintLn();
1441 // use factory/libfac in general ==============================
1444 CFFList L;
1445 number N=NULL;
1446 number NN=NULL;
1447 number old_lead_coeff=n_Copy(pGetCoeff(f), r->cf);
1448 Variable a;
1449
1450 if (!rField_is_Zp(r) && !rField_is_Zp_a(r)) /* Q, Q(a) */
1451 {
1452 //if (f!=NULL) // already tested at start of routine
1453 number n0=n_Copy(old_lead_coeff,r->cf);
1454 if (with_exps==0 || with_exps==3)
1455 N=n_Copy(n0,r->cf);
1456 p_Cleardenom(f, r);
1457 //after here f should not have a denominator!!
1458 //PrintS("S:");p_Write(f,r);PrintLn();
1459 NN=n_Div(n0,pGetCoeff(f),r->cf);
1460 n_Delete(&n0,r->cf);
1461 if (with_exps==0 || with_exps==3)
1462 {
1463 n_Delete(&N,r->cf);
1464 N=n_Copy(NN,r->cf);
1465 }
1466 }
1467 else if (rField_is_Zp_a(r))
1468 {
1469 //if (f!=NULL) // already tested at start of routine
1471 {
1472 number n0=n_Copy(old_lead_coeff,r->cf);
1473 if (with_exps==0 || with_exps==3)
1474 N=n_Copy(n0,r->cf);
1475 p_Norm(f,r);
1476 p_Cleardenom(f, r);
1477 NN=n_Div(n0,pGetCoeff(f),r->cf);
1478 n_Delete(&n0,r->cf);
1479 if (with_exps==0 || with_exps==3)
1480 {
1481 n_Delete(&N,r->cf);
1482 N=n_Copy(NN,r->cf);
1483 }
1484 }
1485 }
1486 if (rField_is_Q(r) || rField_is_Zp(r)
1487 || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
1488 {
1493 L = sqrFree( F );
1494 }
1495 else if (r->cf->extRing!=NULL)
1496 {
1497 if (rField_is_Q_a (r)) setCharacteristic (0);
1501 if (r->cf->extRing->qideal!=NULL)
1502 {
1503 CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
1504 r->cf->extRing);
1505 a=rootOf(mipo);
1506 CanonicalForm F( convSingAPFactoryAP( f, a, r ) );
1507 L= sqrFree (F);
1508 }
1509 else
1510 {
1512 L = sqrFree( F );
1513 }
1514 }
1515 #if 0
1516 else if (rField_is_GF())
1517 {
1518 int c=rInternalChar(r);
1519 setCharacteristic( c, primepower(c) );
1520 CanonicalForm F( convSingGFFactoryGF( f ) );
1521 if (F.isUnivariate())
1522 {
1523 L = factorize( F );
1524 }
1525 else
1526 {
1527 goto notImpl;
1528 }
1529 }
1530 #endif
1531 else
1532 {
1533 goto notImpl;
1534 }
1535 {
1536 // convert into ideal
1537 int n = L.length();
1538 if (n==0) n=1;
1539 CFFListIterator J=L;
1540 int j=0;
1541 if (with_exps!=1)
1542 {
1543 if ((with_exps==2)&&(n>1))
1544 {
1545 n--;
1546 J++;
1547 }
1548 *v = new intvec( n );
1549 }
1550 else if (L.getFirst().factor().inCoeffDomain() && with_exps!=3)
1551 {
1552 n--;
1553 J++;
1554 }
1555 res = idInit( n ,1);
1556 for ( ; J.hasItem(); J++, j++ )
1557 {
1558 if (with_exps!=1 && with_exps!=3) (**v)[j] = J.getItem().exp();
1559 if (rField_is_Zp(r) || rField_is_Q(r)
1560 || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
1561 res->m[j] = convFactoryPSingP( J.getItem().factor(),r );
1562 else if (r->cf->extRing!=NULL) /* Q(a), Fp(a) */
1563 {
1564 if (r->cf->extRing->qideal==NULL)
1565 res->m[j]=convFactoryPSingTrP( J.getItem().factor(),r );
1566 else
1567 res->m[j]=convFactoryAPSingAP( J.getItem().factor(),r );
1568 }
1569 }
1570 if (res->m[0]==NULL)
1571 {
1572 res->m[0]=p_One(r);
1573 }
1574 if (N!=NULL)
1575 {
1576 __p_Mult_nn(res->m[0],N,r);
1577 n_Delete(&N,r->cf);
1578 N=NULL;
1579 }
1580 }
1581 if (r->cf->extRing!=NULL)
1582 if (r->cf->extRing->qideal!=NULL)
1583 prune (a);
1584 if (rField_is_Q_a(r) && (r->cf->extRing->qideal!=NULL))
1585 {
1586 int i=IDELEMS(res)-1;
1587 int stop=1;
1588 if (with_exps!=0 || with_exps==3) stop=0;
1589 for(;i>=stop;i--)
1590 {
1591 p_Norm(res->m[i],r);
1592 }
1593 if (with_exps==0 || with_exps==3) p_SetCoeff(res->m[0],old_lead_coeff,r);
1594 else n_Delete(&old_lead_coeff,r->cf);
1595 }
1596 else
1597 n_Delete(&old_lead_coeff,r->cf);
1598 p_Delete(&f,r);
1599 errorreported=save_errorreported;
1600notImpl:
1601 if (res==NULL)
1603 if (NN!=NULL)
1604 {
1605 n_Delete(&NN,r->cf);
1606 }
1607 if (N!=NULL)
1608 {
1609 n_Delete(&N,r->cf);
1610 }
1611 return res;
1612}
CFFList FACTORY_PUBLIC sqrFree(const CanonicalForm &f, bool sort=false)
squarefree factorization
Definition cf_factor.cc:963
static long pTotaldegree(poly p)
Definition polys.h:283

◆ singntl_HNF() [1/3]

bigintmat * singntl_HNF ( bigintmat * b)

Definition at line 1938 of file clapsing.cc.

1939{
1940 int r=b->rows();
1941 if (r!=b->cols())
1942 {
1943 Werror("HNF of %d x %d matrix",r,b->cols());
1944 return NULL;
1945 }
1946 setCharacteristic( 0 );
1947 CFMatrix M(r,r);
1948 int i,j;
1949 for(i=r;i>0;i--)
1950 {
1951 for(j=r;j>0;j--)
1952 {
1953 M(i,j)=n_convSingNFactoryN(BIMATELEM(*b,i,j),FALSE,b->basecoeffs());
1954 }
1955 }
1956 CFMatrix *MM=cf_HNF(M);
1957 bigintmat *mm=bimCopy(b);
1958 for(i=r;i>0;i--)
1959 {
1960 for(j=r;j>0;j--)
1961 {
1962 BIMATELEM(*mm,i,j)=n_convFactoryNSingN((*MM)(i,j),b->basecoeffs());
1963 }
1964 }
1965 delete MM;
1966 return mm;
1967}
bigintmat * bimCopy(const bigintmat *b)
same as copy constructor - apart from it being able to accept NULL as input
Definition bigintmat.cc:403
CanonicalForm b
Definition cfModGcd.cc:4111
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 1907 of file clapsing.cc.

1908{
1909 int r=m->rows();
1910 if (r!=m->cols())
1911 {
1912 Werror("HNF of %d x %d matrix",r,m->cols());
1913 return NULL;
1914 }
1915 setCharacteristic( 0 );
1916 CFMatrix M(r,r);
1917 int i,j;
1918 for(i=r;i>0;i--)
1919 {
1920 for(j=r;j>0;j--)
1921 {
1922 M(i,j)=IMATELEM(*m,i,j);
1923 }
1924 }
1925 CFMatrix *MM=cf_HNF(M);
1926 intvec *mm=ivCopy(m);
1927 for(i=r;i>0;i--)
1928 {
1929 for(j=r;j>0;j--)
1930 {
1931 IMATELEM(*mm,i,j)=convFactoryISingI((*MM)(i,j));
1932 }
1933 }
1934 delete MM;
1935 return mm;
1936}
intvec * ivCopy(const intvec *o)
Definition intvec.h:146

◆ singntl_HNF() [3/3]

matrix singntl_HNF ( matrix m,
const ring s )

Definition at line 1871 of file clapsing.cc.

1872{
1873 int r=m->rows();
1874 if (r!=m->cols())
1875 {
1876 Werror("HNF of %d x %d matrix",r,m->cols());
1877 return NULL;
1878 }
1879
1880 matrix res=mpNew(r,r);
1881
1882 if (rField_is_Q(s))
1883 {
1884
1885 CFMatrix M(r,r);
1886 int i,j;
1887 for(i=r;i>0;i--)
1888 {
1889 for(j=r;j>0;j--)
1890 {
1892 }
1893 }
1894 CFMatrix *MM=cf_HNF(M);
1895 for(i=r;i>0;i--)
1896 {
1897 for(j=r;j>0;j--)
1898 {
1899 MATELEM(res,i,j)=convFactoryPSingP((*MM)(i,j),s);
1900 }
1901 }
1902 delete MM;
1903 }
1904 return res;
1905}

◆ singntl_LLL() [1/2]

intvec * singntl_LLL ( intvec * m)

Definition at line 1998 of file clapsing.cc.

1999{
2000 int r=m->rows();
2001 int c=m->cols();
2002 setCharacteristic( 0 );
2003 CFMatrix M(r,c);
2004 int i,j;
2005 for(i=r;i>0;i--)
2006 {
2007 for(j=c;j>0;j--)
2008 {
2009 M(i,j)=IMATELEM(*m,i,j);
2010 }
2011 }
2012 CFMatrix *MM=cf_LLL(M);
2013 intvec *mm=ivCopy(m);
2014 for(i=r;i>0;i--)
2015 {
2016 for(j=c;j>0;j--)
2017 {
2018 IMATELEM(*mm,i,j)=convFactoryISingI((*MM)(i,j));
2019 }
2020 }
2021 delete MM;
2022 return mm;
2023}
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 1969 of file clapsing.cc.

1970{
1971 int r=m->rows();
1972 int c=m->cols();
1973 matrix res=mpNew(r,c);
1974 if (rField_is_Q(s))
1975 {
1976 CFMatrix M(r,c);
1977 int i,j;
1978 for(i=r;i>0;i--)
1979 {
1980 for(j=c;j>0;j--)
1981 {
1983 }
1984 }
1985 CFMatrix *MM=cf_LLL(M);
1986 for(i=r;i>0;i--)
1987 {
1988 for(j=c;j>0;j--)
1989 {
1990 MATELEM(res,i,j)=convFactoryPSingP((*MM)(i,j),s);
1991 }
1992 }
1993 delete MM;
1994 }
1995 return res;
1996}

◆ singntl_rref() [1/2]

ideal singntl_rref ( ideal m,
const ring R )

Definition at line 2105 of file clapsing.cc.

2106{
2107 int r=m->rank;
2108 int c=m->ncols;
2109 int i,j;
2110 ideal M=idInit(c,r);
2111 if (rField_is_Zp(R))
2112 {
2113 zz_p::init(rChar(R));
2114 mat_zz_p *NTLM=new mat_zz_p;
2115 NTLM->SetDims(r,c);
2116 for(j=c-1;j>=0;j--)
2117 {
2118 poly h=m->m[j];
2119 while(h!=NULL)
2120 {
2121 i=p_GetComp(h,R);
2122 if (p_Totaldegree(h,R)==0)
2123 (*NTLM)(i,j+1)=(long)p_GetCoeff(h,R);
2124 else
2125 {
2126 WerrorS("smatrix for rref is not constant");
2127 return M;
2128 }
2129 pIter(h);
2130 }
2131 }
2132 gauss(*NTLM);
2133 for(i=r;i>0;i--)
2134 {
2135 for(j=c;j>0;j--)
2136 {
2137 number n=n_Init(rep((*NTLM)(i,j)),R->cf);
2138 if(!n_IsZero(n,R->cf))
2139 {
2140 poly p=p_NSet(n,R);
2141 p_SetComp(p,i,R);
2142 M->m[j-1]=p_Add_q(M->m[j-1],p,R);
2143 }
2144 }
2145 }
2146 delete NTLM;
2147 }
2148 else
2149 {
2150 WerrorS("not implemented for these coefficients");
2151 }
2152 return M;
2153}
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition coeffs.h:470
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition coeffs.h:541
#define p_GetComp(p, r)
Definition monomials.h:64
#define p_GetCoeff(p, r)
Definition monomials.h:50
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition p_polys.h:249
int rChar(ring r)
Definition ring.cc:719

◆ singntl_rref() [2/2]

matrix singntl_rref ( matrix m,
const ring R )

Definition at line 2051 of file clapsing.cc.

2052{
2053 int r=m->rows();
2054 int c=m->cols();
2055 int i,j;
2056 matrix M=mpNew(r,c);
2057 if (rField_is_Zp(R))
2058 {
2059 zz_p::init(rChar(R));
2060 mat_zz_p *NTLM=new mat_zz_p;
2061 NTLM->SetDims(r,c);
2062 for(i=r;i>0;i--)
2063 {
2064 for(j=c;j>0;j--)
2065 {
2066 poly h=MATELEM(m,i,j);
2067 if (h!=NULL)
2068 {
2069 if (p_Totaldegree(h,R)==0)
2070 {
2071 (*NTLM)(i,j)=(long)p_GetCoeff(h,R);
2072 }
2073 else
2074 {
2075 WerrorS("smatrix for rref is not constant");
2076 return M;
2077 }
2078 }
2079 }
2080 }
2081 gauss(*NTLM);
2082 for(i=r;i>0;i--)
2083 {
2084 for(j=c;j>0;j--)
2085 {
2086 number n=n_Init(rep((*NTLM)(i,j)),R->cf);
2087 if(!n_IsZero(n,R->cf))
2088 {
2089 poly p=p_NSet(n,R);
2090 MATELEM(M,i,j)=p;
2091 }
2092 }
2093 }
2094 delete NTLM;
2095 }
2096 else
2097 {
2098 WerrorS("not implemented for these coefficients");
2099 }
2100 return M;
2101}

◆ Zp_roots()

int * Zp_roots ( poly p,
const ring r )

Definition at line 2242 of file clapsing.cc.

2243{
2245 return Zp_roots(pp);
2246}
CanonicalForm FACTORY_PUBLIC pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f ).
Definition cf_gcd.cc:676
int * Zp_roots(poly p, const ring r)
Definition clapsing.cc:2242

Variable Documentation

◆ singclap_factorize_retry

EXTERN_VAR int singclap_factorize_retry

Definition at line 981 of file clapsing.cc.