[0e1846] | 1 | // emacs edit mode for this file is -*- C++ -*- |
---|
[341696] | 2 | // $Id$ |
---|
[8bafbf0] | 3 | |
---|
| 4 | /**************************************** |
---|
| 5 | * Computer Algebra System SINGULAR * |
---|
| 6 | ****************************************/ |
---|
[6227ad] | 7 | /* |
---|
[94d062] | 8 | * ABSTRACT - The FGLM-Algorithm plus extension |
---|
[6227ad] | 9 | * Calculate a reduced groebner basis for one ordering, given a |
---|
[8bafbf0] | 10 | * reduced groebner basis for another ordering. |
---|
| 11 | * In this file the input is checked. Furthermore we decide, if |
---|
| 12 | * the input is 0-dimensional ( then fglmzero.cc is used ) or |
---|
[6227ad] | 13 | * if the input is homogeneous ( then fglmhom.cc is used. Yet |
---|
[8bafbf0] | 14 | * not implemented ). |
---|
[94d062] | 15 | * The extension (finduni) finds minimal univariate Polynomials |
---|
| 16 | * lying in a 0-dimensional ideal. |
---|
[8bafbf0] | 17 | */ |
---|
| 18 | |
---|
[b1dfaf] | 19 | #include <kernel/mod2.h> |
---|
[d720e3] | 20 | |
---|
[da8702] | 21 | #ifdef HAVE_FACTORY |
---|
[599326] | 22 | #include <Singular/tok.h> |
---|
| 23 | #include <kernel/options.h> |
---|
| 24 | #include <kernel/polys.h> |
---|
| 25 | #include <kernel/ideals.h> |
---|
| 26 | #include <kernel/ring.h> |
---|
| 27 | #include <Singular/ipid.h> |
---|
| 28 | #include <Singular/ipshell.h> |
---|
| 29 | #include <kernel/febase.h> |
---|
| 30 | #include <kernel/maps.h> |
---|
[b1dfaf] | 31 | #include <omalloc/omalloc.h> |
---|
[599326] | 32 | #include <kernel/kstd1.h> |
---|
| 33 | #include <kernel/fglm.h> |
---|
[0e1846] | 34 | |
---|
[a21f1f] | 35 | // internal Version: 1.18.1.6 |
---|
[8bafbf0] | 36 | // enumeration to handle the various errors to occour. |
---|
[6227ad] | 37 | enum FglmState{ |
---|
| 38 | FglmOk, |
---|
| 39 | FglmHasOne, |
---|
[8bafbf0] | 40 | FglmNoIdeal, |
---|
| 41 | FglmNotReduced, |
---|
[6227ad] | 42 | FglmNotZeroDim, |
---|
[df83c0] | 43 | FglmIncompatibleRings, |
---|
| 44 | // for fglmquot: |
---|
| 45 | FglmPolyIsOne, |
---|
| 46 | FglmPolyIsZero |
---|
[0e1846] | 47 | }; |
---|
| 48 | |
---|
[8bafbf0] | 49 | // Has to be called, if currQuotient != NULL. ( i.e. qring-case ) |
---|
| 50 | // Then a new ideal is build, consisting of the generators of sourceIdeal |
---|
| 51 | // and the generators of currQuotient, which are completely reduced by |
---|
| 52 | // the sourceIdeal. This means: If sourceIdeal is reduced, then the new |
---|
| 53 | // ideal will be reduced as well. |
---|
| 54 | // Assumes that currRing == sourceRing |
---|
[6227ad] | 55 | ideal fglmUpdatesource( const ideal sourceIdeal ) |
---|
[8bafbf0] | 56 | { |
---|
| 57 | int k, l, offset; |
---|
| 58 | BOOLEAN found; |
---|
| 59 | ideal newSource= idInit( IDELEMS( sourceIdeal ) + IDELEMS( currQuotient ), 1 ); |
---|
| 60 | for ( k= IDELEMS( sourceIdeal )-1; k >=0; k-- ) |
---|
[6227ad] | 61 | (newSource->m)[k]= pCopy( (sourceIdeal->m)[k] ); |
---|
[8bafbf0] | 62 | offset= IDELEMS( sourceIdeal ); |
---|
[894734] | 63 | for ( l= IDELEMS( currQuotient )-1; l >= 0; l-- ) |
---|
| 64 | { |
---|
| 65 | if ( (currQuotient->m)[l] != NULL ) |
---|
| 66 | { |
---|
[6227ad] | 67 | found= FALSE; |
---|
| 68 | for ( k= IDELEMS( sourceIdeal )-1; (k >= 0) && (found == FALSE); k-- ) |
---|
| 69 | if ( pDivisibleBy( (sourceIdeal->m)[k], (currQuotient->m)[l] ) ) |
---|
| 70 | found= TRUE; |
---|
[894734] | 71 | if ( ! found ) |
---|
| 72 | { |
---|
[6227ad] | 73 | (newSource->m)[offset]= pCopy( (currQuotient->m)[l] ); |
---|
| 74 | offset++; |
---|
| 75 | } |
---|
| 76 | } |
---|
[8bafbf0] | 77 | } |
---|
| 78 | idSkipZeroes( newSource ); |
---|
| 79 | return newSource; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | // Has to be called, if currQuotient != NULL, i.e. in qring-case. |
---|
[6227ad] | 83 | // Gets rid of the elements of result which are contained in |
---|
[8bafbf0] | 84 | // currQuotient and skips Zeroes. |
---|
| 85 | // Assumes that currRing == destRing |
---|
[0e1846] | 86 | void |
---|
[6227ad] | 87 | fglmUpdateresult( ideal & result ) |
---|
[0e1846] | 88 | { |
---|
| 89 | int k, l; |
---|
[8bafbf0] | 90 | BOOLEAN found; |
---|
[894734] | 91 | for ( k= IDELEMS( result )-1; k >=0; k-- ) |
---|
| 92 | { |
---|
| 93 | if ( (result->m)[k] != NULL ) |
---|
| 94 | { |
---|
[6227ad] | 95 | found= FALSE; |
---|
| 96 | for ( l= IDELEMS( currQuotient )-1; (l >= 0) && ( found == FALSE ); l-- ) |
---|
| 97 | if ( pDivisibleBy( (currQuotient->m)[l], (result->m)[k] ) ) |
---|
| 98 | found= TRUE; |
---|
| 99 | if ( found ) pDelete( & ((result->m)[k]) ); |
---|
| 100 | } |
---|
[8bafbf0] | 101 | } |
---|
| 102 | idSkipZeroes( result ); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | // Checks if the two rings sringHdl and dringHdl are compatible enough to |
---|
| 106 | // be used for the fglm. This means: |
---|
[6227ad] | 107 | // 1) Same Characteristic, 2) globalOrderings in both rings, |
---|
[8bafbf0] | 108 | // 3) Same number of variables, 4) same number of parameters |
---|
| 109 | // 5) variables in one ring are permutated variables of the other one |
---|
| 110 | // 6) parameters in one ring are permutated parameters of the other one |
---|
| 111 | // 7) either both rings are rings or both rings are qrings |
---|
| 112 | // 8) if they are qrings, the quotientIdeals of both must coincide. |
---|
| 113 | // vperm must be a vector of length pVariables+1, initialized by 0. |
---|
[6227ad] | 114 | // If both rings are compatible, it stores the permutation of the |
---|
| 115 | // variables if mapped from sringHdl to dringHdl. |
---|
[8bafbf0] | 116 | // if the rings are compatible, it returns FglmOk. |
---|
| 117 | // Should be called with currRing= IDRING( sringHdl ); |
---|
[6227ad] | 118 | FglmState |
---|
| 119 | fglmConsistency( idhdl sringHdl, idhdl dringHdl, int * vperm ) |
---|
[0e1846] | 120 | { |
---|
| 121 | int k; |
---|
[8bafbf0] | 122 | FglmState state= FglmOk; |
---|
| 123 | ring dring = IDRING( dringHdl ); |
---|
| 124 | ring sring = IDRING( sringHdl ); |
---|
[6227ad] | 125 | |
---|
[894734] | 126 | if ( rChar(sring) != rChar(dring) ) |
---|
| 127 | { |
---|
[6227ad] | 128 | WerrorS( "rings must have same characteristic" ); |
---|
| 129 | state= FglmIncompatibleRings; |
---|
[8bafbf0] | 130 | } |
---|
[894734] | 131 | if ( (sring->OrdSgn != 1) || (dring->OrdSgn != 1) ) |
---|
| 132 | { |
---|
[6227ad] | 133 | WerrorS( "only works for global orderings" ); |
---|
| 134 | state= FglmIncompatibleRings; |
---|
[8bafbf0] | 135 | } |
---|
[17e692] | 136 | if ( sring->N != dring->N ) |
---|
| 137 | { |
---|
[6227ad] | 138 | WerrorS( "rings must have same number of variables" ); |
---|
| 139 | state= FglmIncompatibleRings; |
---|
[8bafbf0] | 140 | } |
---|
[17e692] | 141 | if ( rPar(sring) != rPar(dring) ) |
---|
| 142 | { |
---|
[6227ad] | 143 | WerrorS( "rings must have same number of parameters" ); |
---|
| 144 | state= FglmIncompatibleRings; |
---|
[8bafbf0] | 145 | } |
---|
| 146 | if ( state != FglmOk ) return state; |
---|
| 147 | // now the rings have the same number of variables resp. parameters. |
---|
| 148 | // check if the names of the variables resp. parameters do agree: |
---|
| 149 | int nvar = sring->N; |
---|
[17e692] | 150 | int npar = rPar(sring); |
---|
[8bafbf0] | 151 | int * pperm; |
---|
[6227ad] | 152 | if ( npar > 0 ) |
---|
[c232af] | 153 | pperm= (int *)omAlloc0( (npar+1)*sizeof( int ) ); |
---|
[8bafbf0] | 154 | else |
---|
[6227ad] | 155 | pperm= NULL; |
---|
[a3bc95e] | 156 | maFindPerm( sring->names, nvar, sring->parameter, npar, |
---|
| 157 | dring->names, nvar, dring->parameter, npar, vperm, pperm, |
---|
[811826] | 158 | dring->ch); |
---|
[8bafbf0] | 159 | for ( k= nvar; (k > 0) && (state == FglmOk); k-- ) |
---|
[894734] | 160 | if ( vperm[k] <= 0 ) |
---|
| 161 | { |
---|
[6227ad] | 162 | WerrorS( "variable names do not agree" ); |
---|
| 163 | state= FglmIncompatibleRings; |
---|
| 164 | } |
---|
[8bafbf0] | 165 | for ( k= npar-1; (k >= 0) && (state == FglmOk); k-- ) |
---|
[894734] | 166 | if ( pperm[k] >= 0 ) |
---|
| 167 | { |
---|
[6227ad] | 168 | WerrorS( "paramater names do not agree" ); |
---|
| 169 | state= FglmIncompatibleRings; |
---|
| 170 | } |
---|
[c232af] | 171 | if (pperm != NULL) // OB: ???? |
---|
| 172 | omFreeSize( (ADDRESS)pperm, (npar+1)*sizeof( int ) ); |
---|
[8bafbf0] | 173 | if ( state != FglmOk ) return state; |
---|
| 174 | // check if both rings are qrings or not |
---|
[894734] | 175 | if ( sring->qideal != NULL ) |
---|
| 176 | { |
---|
| 177 | if ( dring->qideal == NULL ) |
---|
| 178 | { |
---|
[6227ad] | 179 | Werror( "%s is a qring, current ring not", sringHdl->id ); |
---|
| 180 | return FglmIncompatibleRings; |
---|
| 181 | } |
---|
| 182 | // both rings are qrings, now check if both quotients define the same ideal. |
---|
| 183 | // check if sring->qideal is contained in dring->qideal: |
---|
[cf42ab1] | 184 | rSetHdl( dringHdl ); |
---|
[4508ce5] | 185 | nMapFunc nMap=nSetMap( sring ); |
---|
[6227ad] | 186 | ideal sqind = idInit( IDELEMS( sring->qideal ), 1 ); |
---|
| 187 | for ( k= IDELEMS( sring->qideal )-1; k >= 0; k-- ) |
---|
[4508ce5] | 188 | (sqind->m)[k]= pPermPoly( (sring->qideal->m)[k], vperm, sring, nMap); |
---|
[6227ad] | 189 | ideal sqindred = kNF( dring->qideal, NULL, sqind ); |
---|
[894734] | 190 | if ( ! idIs0( sqindred ) ) |
---|
| 191 | { |
---|
[6227ad] | 192 | WerrorS( "the quotients do not agree" ); |
---|
| 193 | state= FglmIncompatibleRings; |
---|
| 194 | } |
---|
| 195 | idDelete( & sqind ); |
---|
| 196 | idDelete( & sqindred ); |
---|
[cf42ab1] | 197 | rSetHdl( sringHdl ); |
---|
[6227ad] | 198 | if ( state != FglmOk ) return state; |
---|
| 199 | // check if dring->qideal is contained in sring->qideal: |
---|
[c232af] | 200 | int * dsvperm = (int *)omAlloc0( (nvar+1)*sizeof( int ) ); |
---|
[a3bc95e] | 201 | maFindPerm( dring->names, nvar, NULL, 0, sring->names, nvar, NULL, 0, |
---|
[811826] | 202 | dsvperm, NULL, sring->ch); |
---|
[4508ce5] | 203 | nMap=nSetMap(dring); |
---|
[6227ad] | 204 | ideal dqins = idInit( IDELEMS( dring->qideal ), 1 ); |
---|
| 205 | for ( k= IDELEMS( dring->qideal )-1; k >= 0; k-- ) |
---|
[4508ce5] | 206 | (dqins->m)[k]=pPermPoly( (dring->qideal->m)[k], dsvperm, sring, nMap); |
---|
[6227ad] | 207 | ideal dqinsred = kNF( sring->qideal, NULL, dqins ); |
---|
[894734] | 208 | if ( ! idIs0( dqinsred ) ) |
---|
| 209 | { |
---|
[6227ad] | 210 | WerrorS( "the quotients do not agree" ); |
---|
| 211 | state= FglmIncompatibleRings; |
---|
| 212 | } |
---|
| 213 | idDelete( & dqins ); |
---|
| 214 | idDelete( & dqinsred ); |
---|
[c232af] | 215 | omFreeSize( (ADDRESS)dsvperm, (nvar+1)*sizeof( int ) ); |
---|
[6227ad] | 216 | if ( state != FglmOk ) return state; |
---|
| 217 | } |
---|
[894734] | 218 | else |
---|
| 219 | { |
---|
| 220 | if ( dring->qideal != NULL ) |
---|
| 221 | { |
---|
[6227ad] | 222 | Werror( "current ring is a qring, %s not", sringHdl->id ); |
---|
| 223 | return FglmIncompatibleRings; |
---|
| 224 | } |
---|
[0e1846] | 225 | } |
---|
[8bafbf0] | 226 | return FglmOk; |
---|
[0e1846] | 227 | } |
---|
| 228 | |
---|
[94d062] | 229 | // Checks if the ideal "theIdeal" is zero-dimensional and minimal. It does |
---|
[6227ad] | 230 | // not check, if it is reduced. |
---|
| 231 | // returns FglmOk if we can use theIdeal for CalculateFunctionals (this |
---|
| 232 | // function reports an error if theIdeal is not reduced, |
---|
[94d062] | 233 | // so this need not to be tested here) |
---|
| 234 | // FglmNotReduced if theIdeal is not minimal |
---|
| 235 | // FglmNotZeroDim if it is not zero-dimensional |
---|
| 236 | // FglmHasOne if 1 belongs to theIdeal |
---|
[6227ad] | 237 | FglmState |
---|
[8bafbf0] | 238 | fglmIdealcheck( const ideal theIdeal ) |
---|
[0e1846] | 239 | { |
---|
| 240 | FglmState state = FglmOk; |
---|
| 241 | int power; |
---|
[6227ad] | 242 | int k; |
---|
[894734] | 243 | BOOLEAN * purePowers = (BOOLEAN *)omAlloc0( pVariables*sizeof( BOOLEAN ) ); |
---|
[0e1846] | 244 | |
---|
[894734] | 245 | for ( k= IDELEMS( theIdeal ) - 1; (state == FglmOk) && (k >= 0); k-- ) |
---|
| 246 | { |
---|
[6227ad] | 247 | poly p = (theIdeal->m)[k]; |
---|
[72292f] | 248 | if (p!=NULL) |
---|
[894734] | 249 | { |
---|
[72292f] | 250 | if( pIsConstant( p ) ) state= FglmHasOne; |
---|
| 251 | else if ( (power= pIsPurePower( p )) > 0 ) |
---|
| 252 | { |
---|
[6227ad] | 253 | fglmASSERT( 0 < power && power <= pVariables, "illegal power" ); |
---|
| 254 | if ( purePowers[power-1] == TRUE ) state= FglmNotReduced; |
---|
| 255 | else purePowers[power-1]= TRUE; |
---|
[72292f] | 256 | } |
---|
| 257 | for ( int l = IDELEMS( theIdeal ) - 1; state == FglmOk && l >= 0; l-- ) |
---|
[6227ad] | 258 | if ( (k != l) && pDivisibleBy( p, (theIdeal->m)[l] ) ) |
---|
| 259 | state= FglmNotReduced; |
---|
[72292f] | 260 | } |
---|
[0e1846] | 261 | } |
---|
[894734] | 262 | if ( state == FglmOk ) |
---|
| 263 | { |
---|
[6227ad] | 264 | for ( k= pVariables-1 ; (state == FglmOk) && (k >= 0); k-- ) |
---|
| 265 | if ( purePowers[k] == FALSE ) state= FglmNotZeroDim; |
---|
[0e1846] | 266 | } |
---|
[c232af] | 267 | omFreeSize( (ADDRESS)purePowers, pVariables*sizeof( BOOLEAN ) ); |
---|
[0e1846] | 268 | return state; |
---|
| 269 | } |
---|
| 270 | |
---|
[6227ad] | 271 | // The main function for the fglm-Algorithm. |
---|
[94d062] | 272 | // Checks the input-data, and calls fglmzero (see fglmzero.cc). |
---|
| 273 | // Returns the new groebnerbasis or 0 if an error occoured. |
---|
[8bafbf0] | 274 | BOOLEAN |
---|
[6227ad] | 275 | fglmProc( leftv result, leftv first, leftv second ) |
---|
[0e1846] | 276 | { |
---|
| 277 | FglmState state = FglmOk; |
---|
[8bafbf0] | 278 | |
---|
[0e1846] | 279 | idhdl destRingHdl = currRingHdl; |
---|
| 280 | ring destRing = currRing; |
---|
[8bafbf0] | 281 | ideal destIdeal = NULL; |
---|
| 282 | idhdl sourceRingHdl = (idhdl)first->data; |
---|
[cf42ab1] | 283 | rSetHdl( sourceRingHdl ); |
---|
[8bafbf0] | 284 | ring sourceRing = currRing; |
---|
[a431ba2] | 285 | |
---|
[c232af] | 286 | int * vperm = (int *)omAlloc0( (pVariables+1)*sizeof( int ) ); |
---|
[8bafbf0] | 287 | state= fglmConsistency( sourceRingHdl, destRingHdl, vperm ); |
---|
[c232af] | 288 | omFreeSize( (ADDRESS)vperm, (pVariables+1)*sizeof(int) ); |
---|
[8bafbf0] | 289 | |
---|
[894734] | 290 | if ( state == FglmOk ) |
---|
| 291 | { |
---|
[6227ad] | 292 | idhdl ih = currRing->idroot->get( second->Name(), myynest ); |
---|
[72292f] | 293 | if ( (ih != NULL) && (IDTYP(ih)==IDEAL_CMD) ) |
---|
| 294 | { |
---|
[6227ad] | 295 | ideal sourceIdeal; |
---|
| 296 | if ( currQuotient != NULL ) |
---|
| 297 | sourceIdeal= fglmUpdatesource( IDIDEAL( ih ) ); |
---|
| 298 | else |
---|
| 299 | sourceIdeal = IDIDEAL( ih ); |
---|
| 300 | state= fglmIdealcheck( sourceIdeal ); |
---|
[894734] | 301 | if ( state == FglmOk ) |
---|
| 302 | { |
---|
[6227ad] | 303 | // Now the settings are compatible with FGLM |
---|
| 304 | assumeStdFlag( (leftv)ih ); |
---|
[eaf66f] | 305 | if ( fglmzero( IDRING(sourceRingHdl), sourceIdeal, destRingHdl, destIdeal, FALSE, (currQuotient != NULL) ) == FALSE ) |
---|
[6227ad] | 306 | state= FglmNotReduced; |
---|
| 307 | } |
---|
| 308 | } else state= FglmNoIdeal; |
---|
[0e1846] | 309 | } |
---|
[8bafbf0] | 310 | if ( currRingHdl != destRingHdl ) |
---|
[cf42ab1] | 311 | rSetHdl( destRingHdl ); |
---|
[894734] | 312 | switch (state) |
---|
| 313 | { |
---|
[6227ad] | 314 | case FglmOk: |
---|
| 315 | if ( currQuotient != NULL ) fglmUpdateresult( destIdeal ); |
---|
| 316 | break; |
---|
| 317 | case FglmHasOne: |
---|
| 318 | destIdeal= idInit(1,1); |
---|
| 319 | (destIdeal->m)[0]= pOne(); |
---|
| 320 | state= FglmOk; |
---|
| 321 | break; |
---|
| 322 | case FglmIncompatibleRings: |
---|
| 323 | Werror( "ring %s and current ring are incompatible", first->Name() ); |
---|
| 324 | destIdeal= idInit(0,0); |
---|
| 325 | break; |
---|
| 326 | case FglmNoIdeal: |
---|
| 327 | Werror( "Can't find ideal %s in ring %s", second->Name(), first->Name() ); |
---|
| 328 | destIdeal= idInit(0,0); |
---|
| 329 | break; |
---|
| 330 | case FglmNotZeroDim: |
---|
| 331 | Werror( "The ideal %s has to be 0-dimensional", second->Name() ); |
---|
| 332 | destIdeal= idInit(0,0); |
---|
| 333 | break; |
---|
| 334 | case FglmNotReduced: |
---|
[0a5ca7] | 335 | Werror( "The ideal %s has to be given by a reduced SB", second->Name() ); |
---|
[6227ad] | 336 | destIdeal= idInit(0,0); |
---|
| 337 | break; |
---|
| 338 | default: |
---|
| 339 | destIdeal= idInit(1,1); |
---|
[0e1846] | 340 | } |
---|
[8bafbf0] | 341 | |
---|
| 342 | result->rtyp = IDEAL_CMD; |
---|
| 343 | result->data= (void *)destIdeal; |
---|
| 344 | setFlag( result, FLAG_STD ); |
---|
[6227ad] | 345 | return (state != FglmOk); |
---|
[0e1846] | 346 | } |
---|
| 347 | |
---|
[df83c0] | 348 | // fglmQuotProc: Calculate I:f with FGLM methods. |
---|
| 349 | // Checks the input-data, and calls fglmquot (see fglmzero.cc). |
---|
| 350 | // Returns the new groebnerbasis if I:f or 0 if an error occoured. |
---|
| 351 | BOOLEAN |
---|
| 352 | fglmQuotProc( leftv result, leftv first, leftv second ) |
---|
| 353 | { |
---|
| 354 | FglmState state = FglmOk; |
---|
| 355 | |
---|
| 356 | // STICKYPROT("quotstart\n"); |
---|
[dedfe4] | 357 | ideal sourceIdeal = (ideal)first->Data(); |
---|
[df83c0] | 358 | poly quot = (poly)second->Data(); |
---|
| 359 | ideal destIdeal = NULL; |
---|
| 360 | |
---|
| 361 | state = fglmIdealcheck( sourceIdeal ); |
---|
[894734] | 362 | if ( state == FglmOk ) |
---|
| 363 | { |
---|
[df83c0] | 364 | if ( quot == NULL ) state= FglmPolyIsZero; |
---|
| 365 | else if ( pIsConstant( quot ) ) state= FglmPolyIsOne; |
---|
| 366 | } |
---|
[a3bc95e] | 367 | |
---|
[894734] | 368 | if ( state == FglmOk ) |
---|
| 369 | { |
---|
[df83c0] | 370 | assumeStdFlag( first ); |
---|
| 371 | if ( fglmquot( sourceIdeal, quot, destIdeal ) == FALSE ) |
---|
| 372 | state= FglmNotReduced; |
---|
| 373 | } |
---|
| 374 | |
---|
[894734] | 375 | switch (state) |
---|
| 376 | { |
---|
[df83c0] | 377 | case FglmOk: |
---|
| 378 | break; |
---|
| 379 | case FglmHasOne: |
---|
| 380 | destIdeal= idInit(1,1); |
---|
| 381 | (destIdeal->m)[0]= pOne(); |
---|
| 382 | state= FglmOk; |
---|
| 383 | break; |
---|
| 384 | case FglmNotZeroDim: |
---|
| 385 | Werror( "The ideal %s has to be 0-dimensional", first->Name() ); |
---|
| 386 | destIdeal= idInit(0,0); |
---|
| 387 | break; |
---|
| 388 | case FglmNotReduced: |
---|
| 389 | Werror( "The poly %s has to be reduced", second->Name() ); |
---|
| 390 | destIdeal= idInit(0,0); |
---|
| 391 | break; |
---|
| 392 | case FglmPolyIsOne: |
---|
[894734] | 393 | int k; |
---|
| 394 | destIdeal= idInit( IDELEMS(sourceIdeal), 1 ); |
---|
| 395 | for ( k= IDELEMS( sourceIdeal )-1; k >=0; k-- ) |
---|
| 396 | (destIdeal->m)[k]= pCopy( (sourceIdeal->m)[k] ); |
---|
[df83c0] | 397 | state= FglmOk; |
---|
| 398 | break; |
---|
| 399 | case FglmPolyIsZero: |
---|
[894734] | 400 | destIdeal= idInit(1,1); |
---|
[df83c0] | 401 | (destIdeal->m)[0]= pOne(); |
---|
| 402 | state= FglmOk; |
---|
| 403 | break; |
---|
| 404 | default: |
---|
| 405 | destIdeal= idInit(1,1); |
---|
| 406 | } |
---|
| 407 | |
---|
| 408 | result->rtyp = IDEAL_CMD; |
---|
| 409 | result->data= (void *)destIdeal; |
---|
| 410 | setFlag( result, FLAG_STD ); |
---|
| 411 | // STICKYPROT("quotend\n"); |
---|
| 412 | return (state != FglmOk); |
---|
| 413 | } // fglmQuotProt |
---|
| 414 | |
---|
[94d062] | 415 | // The main function for finduni(). |
---|
| 416 | // Checks the input-data, and calls FindUnivariateWrapper (see fglmzero.cc). |
---|
| 417 | // Returns an ideal containing the univariate Polynomials or 0 if an error |
---|
| 418 | // has occoured. |
---|
[d9c8d3] | 419 | BOOLEAN |
---|
[6227ad] | 420 | findUniProc( leftv result, leftv first ) |
---|
[d9c8d3] | 421 | { |
---|
| 422 | ideal sourceIdeal; |
---|
[94d062] | 423 | ideal destIdeal = NULL; |
---|
| 424 | FglmState state; |
---|
[6227ad] | 425 | |
---|
[a4f65b] | 426 | sourceIdeal = (ideal)first->Data(); |
---|
[94d062] | 427 | |
---|
| 428 | assumeStdFlag( first ); |
---|
| 429 | state= fglmIdealcheck( sourceIdeal ); |
---|
[894734] | 430 | if ( state == FglmOk ) |
---|
| 431 | { |
---|
| 432 | // check for special cases: if the input contains |
---|
| 433 | // univariate polys, try to reduce the problem |
---|
| 434 | int i,k; |
---|
| 435 | int count=0; |
---|
| 436 | BOOLEAN * purePowers = (BOOLEAN *)omAlloc0( pVariables*sizeof( BOOLEAN ) ); |
---|
| 437 | for ( k= IDELEMS( sourceIdeal ) - 1; k >= 0; k-- ) |
---|
| 438 | { |
---|
| 439 | if((i=pIsUnivariate(sourceIdeal->m[k]))>0) |
---|
[72292f] | 440 | { |
---|
[894734] | 441 | if (purePowers[i-1]==0) |
---|
| 442 | { |
---|
| 443 | purePowers[i-1]=k; |
---|
| 444 | count++; |
---|
| 445 | if (count==pVariables) break; |
---|
| 446 | } |
---|
| 447 | } |
---|
| 448 | } |
---|
| 449 | if (count==pVariables) |
---|
| 450 | { |
---|
| 451 | destIdeal=idInit(pVariables,1); |
---|
| 452 | for(k=pVariables-1; k>=0; k--) destIdeal->m[k]=pCopy(sourceIdeal->m[purePowers[k]]); |
---|
| 453 | } |
---|
| 454 | omFreeSize((ADDRESS)purePowers, pVariables*sizeof( BOOLEAN ) ); |
---|
| 455 | if (destIdeal!=NULL) |
---|
[72292f] | 456 | state = FglmOk; |
---|
[894734] | 457 | else if ( FindUnivariateWrapper( sourceIdeal, destIdeal ) == FALSE ) |
---|
[6227ad] | 458 | state = FglmNotReduced; |
---|
[94d062] | 459 | } |
---|
[894734] | 460 | switch (state) |
---|
| 461 | { |
---|
[6227ad] | 462 | case FglmOk: |
---|
| 463 | break; |
---|
| 464 | case FglmHasOne: |
---|
| 465 | destIdeal= idInit(1,1); |
---|
| 466 | (destIdeal->m)[0]= pOne(); |
---|
| 467 | state= FglmOk; |
---|
| 468 | break; |
---|
| 469 | case FglmNotZeroDim: |
---|
| 470 | Werror( "The ideal %s has to be 0-dimensional", first->Name() ); |
---|
| 471 | destIdeal= idInit(0,0); |
---|
| 472 | break; |
---|
| 473 | case FglmNotReduced: |
---|
| 474 | Werror( "The ideal %s has to be reduced", first->Name() ); |
---|
| 475 | destIdeal= idInit(0,0); |
---|
| 476 | break; |
---|
| 477 | default: |
---|
| 478 | destIdeal= idInit(1,1); |
---|
[94d062] | 479 | } |
---|
[6227ad] | 480 | |
---|
[d9c8d3] | 481 | result->rtyp = IDEAL_CMD; |
---|
| 482 | result->data= (void *)destIdeal; |
---|
[6227ad] | 483 | |
---|
[94d062] | 484 | return FALSE; |
---|
[d9c8d3] | 485 | } |
---|
[34ab5de] | 486 | #endif |
---|
[0e1846] | 487 | // ---------------------------------------------------------------------------- |
---|
| 488 | // Local Variables: *** |
---|
| 489 | // compile-command: "make Singular" *** |
---|
| 490 | // page-delimiter: "^\\(\\|//!\\)" *** |
---|
| 491 | // fold-internal-margins: nil *** |
---|
| 492 | // End: *** |
---|