[0e1846] | 1 | // emacs edit mode for this file is -*- C++ -*- |
---|
[e2f1c7] | 2 | /**************************************** |
---|
| 3 | * Computer Algebra System SINGULAR * |
---|
| 4 | ****************************************/ |
---|
[40edb03] | 5 | // $Id: clapsing.cc,v 1.5 1997-04-25 15:03:53 obachman Exp $ |
---|
[e2f1c7] | 6 | /* |
---|
| 7 | * ABSTRACT: interface between Singular and factory |
---|
| 8 | */ |
---|
| 9 | |
---|
[0e1846] | 10 | |
---|
| 11 | #include "mod2.h" |
---|
[40edb03] | 12 | #ifdef HAVE_FACTORY |
---|
[0e1846] | 13 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
| 14 | #include "tok.h" |
---|
| 15 | #include "clapsing.h" |
---|
| 16 | #include "ipid.h" |
---|
| 17 | #include "numbers.h" |
---|
| 18 | #include "subexpr.h" |
---|
| 19 | #include "ipshell.h" |
---|
| 20 | #include <singfactory.h> |
---|
| 21 | #include "clapconv.h" |
---|
| 22 | #ifdef HAVE_LIBFAC_P |
---|
| 23 | #include <factor.h> |
---|
| 24 | #endif |
---|
| 25 | |
---|
| 26 | poly singclap_gcd ( poly f, poly g ) |
---|
| 27 | { |
---|
| 28 | // for now there is only the possibility to handle polynomials over |
---|
| 29 | // Q and Fp ... |
---|
| 30 | if ( nGetChar() == 0 || nGetChar() > 1 ) |
---|
| 31 | { |
---|
| 32 | setCharacteristic( nGetChar() ); |
---|
| 33 | CanonicalForm F( convSingPClapP( f ) ), G( convSingPClapP( g ) ); |
---|
| 34 | poly res=convClapPSingP( gcd( F, G ) ); |
---|
| 35 | Off(SW_RATIONAL); |
---|
| 36 | return res; |
---|
| 37 | } |
---|
| 38 | // and over Q(a) / Fp(a) |
---|
| 39 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
| 40 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
| 41 | { |
---|
| 42 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
| 43 | else setCharacteristic( -nGetChar() ); |
---|
| 44 | poly res; |
---|
| 45 | if (currRing->minpoly!=NULL) |
---|
| 46 | { |
---|
| 47 | CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); |
---|
| 48 | Variable a=rootOf(mipo); |
---|
| 49 | CanonicalForm F( convSingAPClapAP( f,a ) ), G( convSingAPClapAP( g,a ) ); |
---|
| 50 | res= convClapAPSingAP( gcd( F, G ) ); |
---|
| 51 | } |
---|
| 52 | else |
---|
| 53 | { |
---|
| 54 | CanonicalForm F( convSingTrPClapP( f ) ), G( convSingTrPClapP( g ) ); |
---|
| 55 | res= convClapPSingTrP( gcd( F, G ) ); |
---|
| 56 | } |
---|
| 57 | Off(SW_RATIONAL); |
---|
| 58 | return res; |
---|
| 59 | } |
---|
| 60 | else |
---|
| 61 | WerrorS( "not implemented" ); |
---|
| 62 | return NULL; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | poly singclap_resultant ( poly f, poly g , poly x) |
---|
| 66 | { |
---|
| 67 | int i=pIsPurePower(x); |
---|
| 68 | if (i==0) |
---|
| 69 | { |
---|
| 70 | WerrorS("3rd argument must be a ring variable"); |
---|
| 71 | return NULL; |
---|
| 72 | } |
---|
| 73 | Variable X(i); |
---|
| 74 | // for now there is only the possibility to handle polynomials over |
---|
| 75 | // Q and Fp ... |
---|
| 76 | if ( nGetChar() == 0 || nGetChar() > 1 ) |
---|
| 77 | { |
---|
| 78 | setCharacteristic( nGetChar() ); |
---|
| 79 | CanonicalForm F( convSingPClapP( f ) ), G( convSingPClapP( g ) ); |
---|
| 80 | poly res=convClapPSingP( resultant( F, G, X ) ); |
---|
| 81 | Off(SW_RATIONAL); |
---|
| 82 | return res; |
---|
| 83 | } |
---|
| 84 | // and over Q(a) / Fp(a) |
---|
| 85 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
| 86 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
| 87 | { |
---|
| 88 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
| 89 | else setCharacteristic( -nGetChar() ); |
---|
| 90 | poly res; |
---|
| 91 | if (currRing->minpoly!=NULL) |
---|
| 92 | { |
---|
| 93 | CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); |
---|
| 94 | Variable a=rootOf(mipo); |
---|
| 95 | CanonicalForm F( convSingAPClapAP( f,a ) ), G( convSingAPClapAP( g,a ) ); |
---|
| 96 | res= convClapAPSingAP( resultant( F, G, X ) ); |
---|
| 97 | } |
---|
| 98 | else |
---|
| 99 | { |
---|
| 100 | CanonicalForm F( convSingTrPClapP( f ) ), G( convSingTrPClapP( g ) ); |
---|
| 101 | res= convClapPSingTrP( resultant( F, G, X ) ); |
---|
| 102 | } |
---|
| 103 | Off(SW_RATIONAL); |
---|
| 104 | return res; |
---|
| 105 | } |
---|
| 106 | else |
---|
| 107 | WerrorS( "not implemented" ); |
---|
| 108 | return NULL; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | lists singclap_extgcd ( poly f, poly g ) |
---|
| 112 | { |
---|
| 113 | // for now there is only the possibility to handle univariate |
---|
| 114 | // polynomials over |
---|
| 115 | // Q and Fp ... |
---|
| 116 | poly res=NULL,pa=NULL,pb=NULL; |
---|
| 117 | On(SW_SYMMETRIC_FF); |
---|
| 118 | if ( nGetChar() == 0 || nGetChar() > 1 ) |
---|
| 119 | { |
---|
| 120 | setCharacteristic( nGetChar() ); |
---|
| 121 | CanonicalForm F( convSingPClapP( f ) ), G( convSingPClapP( g ) ); |
---|
| 122 | if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar()) |
---|
| 123 | { |
---|
| 124 | Off(SW_RATIONAL); |
---|
| 125 | WerrorS("not univariate"); |
---|
| 126 | return NULL; |
---|
| 127 | } |
---|
| 128 | CanonicalForm Fa,Gb; |
---|
| 129 | res=convClapPSingP( extgcd( F, G, Fa, Gb ) ); |
---|
| 130 | pa=convClapPSingP(Fa); |
---|
| 131 | pb=convClapPSingP(Gb); |
---|
| 132 | Off(SW_RATIONAL); |
---|
| 133 | } |
---|
| 134 | // and over Q(a) / Fp(a) |
---|
| 135 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
| 136 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
| 137 | { |
---|
| 138 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
| 139 | else setCharacteristic( -nGetChar() ); |
---|
| 140 | CanonicalForm Fa,Gb; |
---|
| 141 | if (currRing->minpoly!=NULL) |
---|
| 142 | { |
---|
| 143 | CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); |
---|
| 144 | Variable a=rootOf(mipo); |
---|
| 145 | CanonicalForm F( convSingAPClapAP( f,a ) ), G( convSingAPClapAP( g,a ) ); |
---|
| 146 | if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar()) |
---|
| 147 | { |
---|
| 148 | WerrorS("not univariate"); |
---|
| 149 | return NULL; |
---|
| 150 | } |
---|
| 151 | res= convClapAPSingAP( extgcd( F, G, Fa, Gb ) ); |
---|
| 152 | pa=convClapAPSingAP(Fa); |
---|
| 153 | pb=convClapAPSingAP(Gb); |
---|
| 154 | } |
---|
| 155 | else |
---|
| 156 | { |
---|
| 157 | CanonicalForm F( convSingTrPClapP( f ) ), G( convSingTrPClapP( g ) ); |
---|
| 158 | if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar()) |
---|
| 159 | { |
---|
| 160 | Off(SW_RATIONAL); |
---|
| 161 | WerrorS("not univariate"); |
---|
| 162 | return NULL; |
---|
| 163 | } |
---|
| 164 | res= convClapPSingTrP( extgcd( F, G, Fa, Gb ) ); |
---|
| 165 | pa=convClapPSingTrP(Fa); |
---|
| 166 | pb=convClapPSingTrP(Gb); |
---|
| 167 | } |
---|
| 168 | Off(SW_RATIONAL); |
---|
| 169 | } |
---|
| 170 | else |
---|
| 171 | { |
---|
| 172 | WerrorS( "not implemented" ); |
---|
| 173 | return NULL; |
---|
| 174 | } |
---|
| 175 | lists L=(lists)Alloc(sizeof(slists)); |
---|
| 176 | L->Init(3); |
---|
| 177 | L->m[0].rtyp=POLY_CMD; |
---|
| 178 | L->m[0].data=(void *)res; |
---|
| 179 | L->m[1].rtyp=POLY_CMD; |
---|
| 180 | L->m[1].data=(void *)pa; |
---|
| 181 | L->m[2].rtyp=POLY_CMD; |
---|
| 182 | L->m[2].data=(void *)pb; |
---|
| 183 | return L; |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | poly singclap_pdivide ( poly f, poly g ) |
---|
| 187 | { |
---|
| 188 | // for now there is only the possibility to handle polynomials over |
---|
| 189 | // Q and Fp ... |
---|
| 190 | if ( nGetChar() == 0 || nGetChar() > 1 ) |
---|
| 191 | { |
---|
| 192 | setCharacteristic( nGetChar() ); |
---|
| 193 | CanonicalForm F( convSingPClapP( f ) ), G( convSingPClapP( g ) ); |
---|
| 194 | return convClapPSingP( F / G ); |
---|
| 195 | } |
---|
| 196 | // and over Q(a) / Fp(a) |
---|
| 197 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
| 198 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
| 199 | { |
---|
| 200 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
| 201 | else setCharacteristic( -nGetChar() ); |
---|
| 202 | poly res; |
---|
| 203 | if (currRing->minpoly!=NULL) |
---|
| 204 | { |
---|
| 205 | CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); |
---|
| 206 | Variable a=rootOf(mipo); |
---|
| 207 | CanonicalForm F( convSingAPClapAP( f,a ) ), G( convSingAPClapAP( g,a ) ); |
---|
| 208 | res= convClapAPSingAP( F / G ); |
---|
| 209 | } |
---|
| 210 | else |
---|
| 211 | { |
---|
| 212 | CanonicalForm F( convSingTrPClapP( f ) ), G( convSingTrPClapP( g ) ); |
---|
| 213 | res= convClapPSingTrP( F / G ); |
---|
| 214 | } |
---|
| 215 | Off(SW_RATIONAL); |
---|
| 216 | return res; |
---|
| 217 | } |
---|
| 218 | else |
---|
| 219 | WerrorS( "not implemented" ); |
---|
| 220 | return NULL; |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | void singclap_divide_content ( poly f ) |
---|
| 224 | { |
---|
| 225 | if ( nGetChar() == 1 ) |
---|
| 226 | setCharacteristic( 0 ); |
---|
| 227 | else if ( nGetChar() < 0 ) |
---|
| 228 | setCharacteristic( -nGetChar() ); |
---|
| 229 | else |
---|
| 230 | setCharacteristic( nGetChar() ); |
---|
| 231 | if ( f==NULL ) |
---|
| 232 | { |
---|
| 233 | return; |
---|
| 234 | } |
---|
| 235 | else if ( pNext( f ) == NULL ) |
---|
| 236 | { |
---|
| 237 | pSetCoeff( f, nInit( 1 ) ); |
---|
| 238 | pTest(f); |
---|
| 239 | return; |
---|
| 240 | } |
---|
| 241 | else |
---|
| 242 | { |
---|
| 243 | CFList L; |
---|
| 244 | CanonicalForm g, h; |
---|
| 245 | poly p = pNext(f); |
---|
| 246 | g = convSingTrClapP( ((lnumber)pGetCoeff(f))->z ); |
---|
| 247 | L.append( g ); |
---|
| 248 | while ( p && (g != 1) ) |
---|
| 249 | { |
---|
| 250 | h = convSingTrClapP( ((lnumber)pGetCoeff(p))->z ); |
---|
| 251 | p = pNext( p ); |
---|
| 252 | g = gcd( g, h ); |
---|
| 253 | L.append( h ); |
---|
| 254 | } |
---|
| 255 | if ( g == 1 ) |
---|
| 256 | { |
---|
| 257 | pTest(f); |
---|
| 258 | return; |
---|
| 259 | } |
---|
| 260 | else |
---|
| 261 | { |
---|
| 262 | CFListIterator i; |
---|
| 263 | for ( i = L, p = f; i.hasItem(); i++, p=pNext(p) ) |
---|
| 264 | { |
---|
| 265 | lnumber c=(lnumber)pGetCoeff(p); |
---|
| 266 | napDelete(&c->z); |
---|
| 267 | c->z=convClapPSingTr( i.getItem() / g ); |
---|
| 268 | } |
---|
| 269 | } |
---|
| 270 | pTest(f); |
---|
| 271 | } |
---|
| 272 | } |
---|
| 273 | |
---|
| 274 | ideal singclap_factorize ( poly f, intvec ** v , int with_exps) |
---|
| 275 | { |
---|
| 276 | // with_exps: 1 return only true factors |
---|
| 277 | // 2 return true factors and exponents |
---|
| 278 | // 0 return factors and exponents |
---|
| 279 | |
---|
| 280 | ideal res=NULL; |
---|
| 281 | Off(SW_RATIONAL); |
---|
| 282 | On(SW_SYMMETRIC_FF); |
---|
| 283 | CFFList L; |
---|
[56f7c5] | 284 | number N=NULL; |
---|
| 285 | |
---|
[0e1846] | 286 | if ( (nGetChar() == 0) || (nGetChar() > 1) ) |
---|
| 287 | { |
---|
| 288 | setCharacteristic( nGetChar() ); |
---|
| 289 | if (nGetChar()==0) /* Q */ |
---|
| 290 | { |
---|
[56f7c5] | 291 | if ((with_exps!=0)&&(f!=NULL)) |
---|
| 292 | { |
---|
| 293 | N=nCopy(pGetCoeff(f)); |
---|
| 294 | pContent(f); |
---|
| 295 | number nn=nDiv(N,pGetCoeff(f)); |
---|
| 296 | nDelete(&N); |
---|
| 297 | N=nn; |
---|
| 298 | } |
---|
[0e1846] | 299 | } |
---|
| 300 | CanonicalForm F( convSingPClapP( f ) ); |
---|
| 301 | if (nGetChar()==0) /* Q */ |
---|
| 302 | { |
---|
| 303 | L = factorize( F ); |
---|
| 304 | } |
---|
| 305 | else /* Fp */ |
---|
| 306 | { |
---|
| 307 | #ifdef HAVE_LIBFAC_P |
---|
| 308 | L = Factorize( F ); |
---|
| 309 | #else |
---|
| 310 | return NULL; |
---|
| 311 | #endif |
---|
| 312 | } |
---|
| 313 | } |
---|
| 314 | // and over Q(a) / Fp(a) |
---|
| 315 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
| 316 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
| 317 | { |
---|
| 318 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
| 319 | else setCharacteristic( -nGetChar() ); |
---|
| 320 | if (currRing->minpoly!=NULL) |
---|
| 321 | { |
---|
| 322 | //if (nGetChar()==1) |
---|
| 323 | //{ |
---|
| 324 | // WerrorS("not implemented"); |
---|
| 325 | // return NULL; |
---|
| 326 | //} |
---|
| 327 | CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); |
---|
| 328 | Variable a=rootOf(mipo); |
---|
| 329 | CanonicalForm F( convSingAPClapAP( f,a ) ); |
---|
| 330 | L = factorize( F, a ); |
---|
| 331 | } |
---|
| 332 | else |
---|
| 333 | { |
---|
| 334 | CanonicalForm F( convSingTrPClapP( f ) ); |
---|
| 335 | if (nGetChar()==1) /* Q(a) */ |
---|
| 336 | { |
---|
| 337 | L = factorize( F ); |
---|
| 338 | } |
---|
| 339 | else /* Fp(a) */ |
---|
| 340 | { |
---|
| 341 | #ifdef HAVE_LIBFAC_P |
---|
| 342 | L = Factorize( F ); |
---|
| 343 | #else |
---|
| 344 | return NULL; |
---|
| 345 | #endif |
---|
| 346 | } |
---|
| 347 | } |
---|
| 348 | } |
---|
| 349 | else |
---|
| 350 | { |
---|
| 351 | WerrorS( "not implemented" ); |
---|
| 352 | goto end; |
---|
| 353 | } |
---|
| 354 | { |
---|
| 355 | // the first factor should be a constant |
---|
| 356 | if ( getNumVars(L.getFirst().factor()) != 0 ) |
---|
| 357 | L.insert(CFFactor(1,1)); |
---|
| 358 | // convert into ideal |
---|
| 359 | int n = L.length(); |
---|
| 360 | CFFListIterator J=L; |
---|
| 361 | int j=0; |
---|
| 362 | if (with_exps!=1) |
---|
| 363 | { |
---|
| 364 | if (with_exps==2) |
---|
| 365 | { |
---|
| 366 | n--; |
---|
| 367 | J++; |
---|
| 368 | } |
---|
| 369 | *v = new intvec( n ); |
---|
| 370 | } |
---|
| 371 | res = idInit( n ,1); |
---|
| 372 | for ( ; J.hasItem(); J++, j++ ) |
---|
| 373 | { |
---|
| 374 | if (with_exps!=1) (**v)[j] = J.getItem().exp(); |
---|
| 375 | if ((nGetChar()==0)||(nGetChar()>1)) /* Q, Fp */ |
---|
| 376 | res->m[j] = convClapPSingP( J.getItem().factor() ); |
---|
| 377 | else if ((nGetChar()==1)||(nGetChar()<-1)) /* Q(a), Fp(a) */ |
---|
| 378 | { |
---|
| 379 | if (currRing->minpoly==NULL) |
---|
| 380 | res->m[j] = convClapPSingTrP( J.getItem().factor() ); |
---|
| 381 | else |
---|
| 382 | res->m[j] = convClapAPSingAP( J.getItem().factor() ); |
---|
| 383 | } |
---|
| 384 | } |
---|
[56f7c5] | 385 | if (N!=NULL) |
---|
| 386 | { |
---|
| 387 | pMultN(res->m[0],N); |
---|
| 388 | nDelete(&N); |
---|
| 389 | } |
---|
[0e1846] | 390 | // delete constants |
---|
| 391 | if ((with_exps!=0) && (res!=NULL)) |
---|
| 392 | { |
---|
| 393 | int i=IDELEMS(res)-1; |
---|
| 394 | for(;i>=0;i--) |
---|
| 395 | { |
---|
| 396 | if (pIsConstant(res->m[i])) |
---|
| 397 | pDelete(&(res->m[i])); |
---|
| 398 | } |
---|
| 399 | idSkipZeroes(res); |
---|
| 400 | if (res->m[0]==NULL) |
---|
| 401 | { |
---|
| 402 | res->m[0]=pOne(); |
---|
| 403 | } |
---|
| 404 | } |
---|
| 405 | } |
---|
| 406 | end: |
---|
| 407 | return res; |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | matrix singclap_irrCharSeries ( ideal I) |
---|
| 411 | { |
---|
| 412 | #ifdef HAVE_LIBFAC_P |
---|
| 413 | // for now there is only the possibility to handle polynomials over |
---|
| 414 | // Q and Fp ... |
---|
| 415 | matrix res=NULL; |
---|
| 416 | int i; |
---|
| 417 | Off(SW_RATIONAL); |
---|
| 418 | On(SW_SYMMETRIC_FF); |
---|
| 419 | CFList L; |
---|
| 420 | ListCFList LL; |
---|
| 421 | if ( (nGetChar() == 0) || (nGetChar() > 1) ) |
---|
| 422 | { |
---|
| 423 | setCharacteristic( nGetChar() ); |
---|
| 424 | for(i=0;i<IDELEMS(I);i++) |
---|
| 425 | { |
---|
| 426 | L.append(convSingPClapP(I->m[i])); |
---|
| 427 | } |
---|
| 428 | } |
---|
| 429 | // and over Q(a) / Fp(a) |
---|
| 430 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
| 431 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
| 432 | { |
---|
| 433 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
| 434 | else setCharacteristic( -nGetChar() ); |
---|
| 435 | for(i=0;i<IDELEMS(I);i++) |
---|
| 436 | { |
---|
| 437 | L.append(convSingTrPClapP(I->m[i])); |
---|
| 438 | } |
---|
| 439 | } |
---|
| 440 | else |
---|
| 441 | { |
---|
| 442 | WerrorS("not implemented"); |
---|
| 443 | return res; |
---|
| 444 | } |
---|
| 445 | |
---|
| 446 | LL=IrrCharSeries(L); |
---|
| 447 | int m= LL.length(); // Anzahl Zeilen |
---|
| 448 | int n=0; |
---|
| 449 | ListIterator<CFList> LLi; |
---|
| 450 | CFListIterator Li; |
---|
| 451 | for ( LLi = LL; LLi.hasItem(); LLi++ ) |
---|
| 452 | { |
---|
| 453 | n = max(LLi.getItem().length(),n); |
---|
| 454 | } |
---|
| 455 | res=mpNew(m,n); |
---|
| 456 | if ((m==0) || (n==0)) |
---|
| 457 | { |
---|
| 458 | Warn("char_series returns %d x %d matrix from %d input polys (%d)\n",m,n,IDELEMS(I)+1,LL.length()); |
---|
| 459 | iiWriteMatrix((matrix)I,"I",2,0); |
---|
| 460 | } |
---|
| 461 | for ( m=1, LLi = LL; LLi.hasItem(); LLi++, m++ ) |
---|
| 462 | { |
---|
| 463 | for (n=1, Li = LLi.getItem(); Li.hasItem(); Li++, n++) |
---|
| 464 | { |
---|
| 465 | if ( (nGetChar() == 0) || (nGetChar() > 1) ) |
---|
| 466 | MATELEM(res,m,n)=convClapPSingP(Li.getItem()); |
---|
| 467 | else |
---|
| 468 | MATELEM(res,m,n)=convClapPSingTrP(Li.getItem()); |
---|
| 469 | } |
---|
| 470 | } |
---|
| 471 | Off(SW_RATIONAL); |
---|
| 472 | return res; |
---|
| 473 | #else |
---|
| 474 | return NULL; |
---|
| 475 | #endif |
---|
| 476 | } |
---|
| 477 | |
---|
| 478 | char* singclap_neworder ( ideal I) |
---|
| 479 | { |
---|
| 480 | #ifdef HAVE_LIBFAC_P |
---|
| 481 | int i; |
---|
| 482 | Off(SW_RATIONAL); |
---|
| 483 | On(SW_SYMMETRIC_FF); |
---|
| 484 | CFList L; |
---|
| 485 | if ( (nGetChar() == 0) || (nGetChar() > 1) ) |
---|
| 486 | { |
---|
| 487 | setCharacteristic( nGetChar() ); |
---|
| 488 | for(i=0;i<IDELEMS(I);i++) |
---|
| 489 | { |
---|
| 490 | L.append(convSingPClapP(I->m[i])); |
---|
| 491 | } |
---|
| 492 | } |
---|
| 493 | // and over Q(a) / Fp(a) |
---|
| 494 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
| 495 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
| 496 | { |
---|
| 497 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
| 498 | else setCharacteristic( -nGetChar() ); |
---|
| 499 | for(i=0;i<IDELEMS(I);i++) |
---|
| 500 | { |
---|
| 501 | L.append(convSingTrPClapP(I->m[i])); |
---|
| 502 | } |
---|
| 503 | } |
---|
| 504 | else |
---|
| 505 | { |
---|
| 506 | WerrorS("not implemented"); |
---|
| 507 | return NULL; |
---|
| 508 | } |
---|
| 509 | |
---|
| 510 | List<int> IL=neworderint(L); |
---|
| 511 | ListIterator<int> Li; |
---|
| 512 | StringSet(""); |
---|
| 513 | Li = IL; |
---|
| 514 | int* mark=(int*)Alloc0(pVariables*sizeof(int)); |
---|
| 515 | int cnt=pVariables; |
---|
| 516 | loop |
---|
| 517 | { |
---|
| 518 | i=Li.getItem()-1; |
---|
| 519 | mark[i]=1; |
---|
| 520 | StringAppend(currRing->names[i]); |
---|
| 521 | Li++; |
---|
| 522 | cnt--; |
---|
| 523 | if(cnt==0) break; |
---|
| 524 | StringAppend(","); |
---|
| 525 | if(! Li.hasItem()) break; |
---|
| 526 | } |
---|
| 527 | for(i=0;i<pVariables;i++) |
---|
| 528 | { |
---|
| 529 | if(mark[i]==0) |
---|
| 530 | { |
---|
| 531 | StringAppend(currRing->names[i]); |
---|
| 532 | cnt--; |
---|
| 533 | if(cnt==0) break; |
---|
| 534 | StringAppend(","); |
---|
| 535 | } |
---|
| 536 | } |
---|
| 537 | return mstrdup(StringAppend("")); |
---|
| 538 | #else |
---|
| 539 | return NULL; |
---|
| 540 | #endif |
---|
| 541 | } |
---|
| 542 | |
---|
| 543 | BOOLEAN singclap_isSqrFree(poly f) |
---|
| 544 | { |
---|
| 545 | BOOLEAN b=FALSE; |
---|
| 546 | Off(SW_RATIONAL); |
---|
| 547 | // Q / Fp |
---|
| 548 | if ( (nGetChar() == 0) || (nGetChar() > 1) ) |
---|
| 549 | { |
---|
| 550 | setCharacteristic( nGetChar() ); |
---|
| 551 | CanonicalForm F( convSingPClapP( f ) ); |
---|
| 552 | if((nGetChar()>1)&&(!F.isUnivariate())) |
---|
| 553 | goto err; |
---|
| 554 | b=(BOOLEAN)isSqrFree(F); |
---|
| 555 | } |
---|
| 556 | // and over Q(a) / Fp(a) |
---|
| 557 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
| 558 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
| 559 | { |
---|
| 560 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
| 561 | else setCharacteristic( -nGetChar() ); |
---|
| 562 | //if (currRing->minpoly!=NULL) |
---|
| 563 | //{ |
---|
| 564 | // CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); |
---|
| 565 | // Variable a=rootOf(mipo); |
---|
| 566 | // CanonicalForm F( convSingAPClapAP( f,a ) ); |
---|
| 567 | // ... |
---|
| 568 | //} |
---|
| 569 | //else |
---|
| 570 | { |
---|
| 571 | CanonicalForm F( convSingTrPClapP( f ) ); |
---|
| 572 | b=(BOOLEAN)isSqrFree(F); |
---|
| 573 | } |
---|
| 574 | Off(SW_RATIONAL); |
---|
| 575 | } |
---|
| 576 | else |
---|
| 577 | { |
---|
| 578 | err: |
---|
| 579 | WerrorS( "not implemented" ); |
---|
| 580 | } |
---|
| 581 | return b; |
---|
| 582 | } |
---|
| 583 | |
---|
| 584 | poly singclap_det( const matrix m ) |
---|
| 585 | { |
---|
| 586 | poly res=NULL; |
---|
| 587 | if ( nGetChar() == 0 || nGetChar() > 1 ) |
---|
| 588 | { |
---|
| 589 | setCharacteristic( nGetChar() ); |
---|
| 590 | CFMatrix M(m->rows(),m->cols()); |
---|
| 591 | int i,j; |
---|
| 592 | for(i=1;i<=m->rows();i++) |
---|
| 593 | { |
---|
| 594 | for(j=1;j<=m->cols();j++) |
---|
| 595 | { |
---|
| 596 | M(i,j)=convSingPClapP(MATELEM(m,i,j)); |
---|
| 597 | } |
---|
| 598 | } |
---|
| 599 | res= convClapPSingP( determinant(M,m->rows())) ; |
---|
| 600 | } |
---|
| 601 | // and over Q(a) / Fp(a) |
---|
| 602 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
| 603 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
| 604 | { |
---|
| 605 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
| 606 | else setCharacteristic( -nGetChar() ); |
---|
| 607 | CFMatrix M(m->rows(),m->cols()); |
---|
| 608 | poly res; |
---|
| 609 | if (currRing->minpoly!=NULL) |
---|
| 610 | { |
---|
| 611 | CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); |
---|
| 612 | Variable a=rootOf(mipo); |
---|
| 613 | int i,j; |
---|
| 614 | for(i=1;i<=m->rows();i++) |
---|
| 615 | { |
---|
| 616 | for(j=1;j<=m->cols();j++) |
---|
| 617 | { |
---|
| 618 | M(i,j)=convSingAPClapAP(MATELEM(m,i,j),a); |
---|
| 619 | } |
---|
| 620 | } |
---|
| 621 | res= convClapAPSingAP( determinant(M,m->rows())) ; |
---|
| 622 | } |
---|
| 623 | else |
---|
| 624 | { |
---|
| 625 | int i,j; |
---|
| 626 | for(i=1;i<=m->rows();i++) |
---|
| 627 | { |
---|
| 628 | for(j=1;j<=m->cols();j++) |
---|
| 629 | { |
---|
| 630 | M(i,j)=convSingTrPClapP(MATELEM(m,i,j)); |
---|
| 631 | } |
---|
| 632 | } |
---|
| 633 | res= convClapPSingTrP( determinant(M,m->rows())); |
---|
| 634 | } |
---|
| 635 | } |
---|
| 636 | else |
---|
| 637 | WerrorS( "not implemented" ); |
---|
| 638 | Off(SW_RATIONAL); |
---|
| 639 | return res; |
---|
| 640 | } |
---|
[6ae4f5] | 641 | |
---|
| 642 | int singclap_det_i( intvec * m ) |
---|
| 643 | { |
---|
| 644 | setCharacteristic( 0 ); |
---|
| 645 | CFMatrix M(m->rows(),m->cols()); |
---|
| 646 | int i,j; |
---|
| 647 | for(i=1;i<=m->rows();i++) |
---|
| 648 | { |
---|
| 649 | for(j=1;j<=m->cols();j++) |
---|
| 650 | { |
---|
| 651 | M(i,j)=IMATELEM(*m,i,j); |
---|
| 652 | } |
---|
| 653 | } |
---|
| 654 | int res= convClapISingI( determinant(M,m->rows())) ; |
---|
| 655 | Off(SW_RATIONAL); |
---|
| 656 | return res; |
---|
| 657 | } |
---|
[0e1846] | 658 | /*==============================================================*/ |
---|
| 659 | /* interpreter interface : */ |
---|
| 660 | BOOLEAN jjGCD_P(leftv res, leftv u, leftv v) |
---|
| 661 | { |
---|
| 662 | res->data=(void *)singclap_gcd((poly)(u->Data()),((poly)v->Data())); |
---|
| 663 | return FALSE; |
---|
| 664 | } |
---|
| 665 | |
---|
| 666 | BOOLEAN jjFAC_P(leftv res, leftv u) |
---|
| 667 | { |
---|
| 668 | intvec *v=NULL; |
---|
| 669 | ideal f=singclap_factorize((poly)(u->Data()), &v, 0); |
---|
| 670 | #ifndef HAVE_LIBFAC_P |
---|
| 671 | if (f==NULL) return TRUE; |
---|
| 672 | #endif |
---|
| 673 | lists l=(lists)Alloc(sizeof(slists)); |
---|
| 674 | l->Init(2); |
---|
| 675 | l->m[0].rtyp=IDEAL_CMD; |
---|
| 676 | l->m[0].data=(void *)f; |
---|
| 677 | l->m[1].rtyp=INTVEC_CMD; |
---|
| 678 | l->m[1].data=(void *)v; |
---|
| 679 | res->data=(void *)l; |
---|
| 680 | return FALSE; |
---|
| 681 | } |
---|
| 682 | |
---|
| 683 | BOOLEAN jjSQR_FREE_DEC(leftv res, leftv u,leftv dummy) |
---|
| 684 | { |
---|
| 685 | intvec *v=NULL; |
---|
| 686 | int sw=(int)dummy->Data(); |
---|
| 687 | ideal f=singclap_factorize((poly)(u->Data()), &v, sw); |
---|
| 688 | switch(sw) |
---|
| 689 | { |
---|
| 690 | case 0: |
---|
| 691 | case 2: |
---|
| 692 | { |
---|
| 693 | lists l=(lists)Alloc(sizeof(slists)); |
---|
| 694 | l->Init(2); |
---|
| 695 | l->m[0].rtyp=IDEAL_CMD; |
---|
| 696 | l->m[0].data=(void *)f; |
---|
| 697 | l->m[1].rtyp=INTVEC_CMD; |
---|
| 698 | l->m[1].data=(void *)v; |
---|
| 699 | res->data=(void *)l; |
---|
| 700 | res->rtyp=LIST_CMD; |
---|
| 701 | return FALSE; |
---|
| 702 | } |
---|
| 703 | case 1: |
---|
| 704 | res->data=(void *)f; |
---|
| 705 | return f==NULL; |
---|
| 706 | } |
---|
| 707 | WerrorS("invalid switch"); |
---|
| 708 | return TRUE; |
---|
| 709 | } |
---|
| 710 | |
---|
| 711 | #if 0 |
---|
| 712 | BOOLEAN jjIS_SQR_FREE(leftv res, leftv u) |
---|
| 713 | { |
---|
| 714 | BOOLEAN b=singclap_factorize((poly)(u->Data()), &v, 0); |
---|
| 715 | res->data=(void *)b; |
---|
| 716 | } |
---|
| 717 | #endif |
---|
| 718 | |
---|
| 719 | BOOLEAN jjEXTGCD_P(leftv res, leftv u, leftv v) |
---|
| 720 | { |
---|
| 721 | res->data=singclap_extgcd((poly)u->Data(),(poly)v->Data()); |
---|
| 722 | return (res->data==NULL); |
---|
| 723 | } |
---|
| 724 | BOOLEAN jjRESULTANT(leftv res, leftv u, leftv v, leftv w) |
---|
| 725 | { |
---|
| 726 | res->data=singclap_resultant((poly)u->Data(),(poly)v->Data(), (poly)w->Data()); |
---|
| 727 | return (res->data==NULL); |
---|
| 728 | } |
---|
| 729 | BOOLEAN jjCHARSERIES(leftv res, leftv u) |
---|
| 730 | { |
---|
| 731 | res->data=singclap_irrCharSeries((ideal)u->Data()); |
---|
| 732 | return (res->data==NULL); |
---|
| 733 | } |
---|
| 734 | #endif |
---|