1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
|
/****************************************
* Computer Algebra System SINGULAR *
****************************************/
/*
* ABSTRACT - multipolynomial resultant
*/
#include <kernel/mod2.h>
//#ifdef HAVE_MPR
//-> includes
#include <omalloc/omalloc.h>
#include <misc/mylimits.h>
#include <misc/options.h>
#include <misc/intvec.h>
#include <coeffs/numbers.h>
#include <coeffs/mpr_global.h>
#include <polys/matpol.h>
#include <kernel/structs.h>
#include <kernel/polys.h>
#include <kernel/ideals.h>
#include <math.h>
#include "mpr_base.h"
#include "mpr_numeric.h"
#include "mpr_inout.h"
// to get detailed timigs, define MPR_TIMING
#ifdef MPR_TIMING
#define TIMING
#endif
#include <factory/timing.h>
TIMING_DEFINE_PRINT(mpr_overall)
TIMING_DEFINE_PRINT(mpr_check)
TIMING_DEFINE_PRINT(mpr_constr)
TIMING_DEFINE_PRINT(mpr_ures)
TIMING_DEFINE_PRINT(mpr_mures)
TIMING_DEFINE_PRINT(mpr_arrange)
TIMING_DEFINE_PRINT(mpr_solver)
#define TIMING_EPR(t,msg) TIMING_END_AND_PRINT(t,msg);TIMING_RESET(t);
//<-
//------------------------------------------------------------------------------
//-> void mprPrintError( mprState state )
void mprPrintError( mprState state, const char * name )
{
switch (state)
{
case mprWrongRType:
WerrorS("Unknown chosen resultant matrix type!");
break;
case mprHasOne:
Werror("One element of the ideal %s is constant!",name);
break;
case mprInfNumOfVars:
Werror("Wrong number of elements in given ideal %s, should be %d resp. %d!",
name,(currRing->N)+1,(currRing->N));
break;
case mprNotZeroDim:
Werror("The given ideal %s must be 0-dimensional!",name);
break;
case mprNotHomog:
Werror("The given ideal %s has to be homogeneous in the first ring variable!",
name);
break;
case mprNotReduced:
Werror("The given ideal %s has to reduced!",name);
break;
case mprUnSupField:
WerrorS("Ground field not implemented!");
break;
default:
break;
}
}
//<-
//-> mprState mprIdealCheck()
mprState mprIdealCheck( const ideal theIdeal,
const char * /*name*/,
uResultant::resMatType mtype,
BOOLEAN rmatrix )
{
mprState state = mprOk;
// int power;
int k;
int numOfVars= mtype == uResultant::denseResMat?(currRing->N)-1:(currRing->N);
if ( rmatrix ) numOfVars++;
if ( mtype == uResultant::none )
state= mprWrongRType;
if ( IDELEMS(theIdeal) != numOfVars )
state= mprInfNumOfVars;
for ( k= IDELEMS(theIdeal) - 1; (state == mprOk) && (k >= 0); k-- )
{
poly p = (theIdeal->m)[k];
if ( pIsConstant(p) ) state= mprHasOne;
else
if ( (mtype == uResultant::denseResMat) && !p_IsHomogeneous(p, currRing) )
state=mprNotHomog;
}
if ( !(rField_is_R(currRing)||
rField_is_Q(currRing)||
rField_is_long_R(currRing)||
rField_is_long_C(currRing)||
(rmatrix && rField_is_Q_a(currRing))) )
state= mprUnSupField;
if ( state != mprOk ) mprPrintError( state, "" /* name */ );
return state;
}
//<-
//-> uResultant::resMatType determineMType( int imtype )
uResultant::resMatType determineMType( int imtype )
{
switch ( imtype )
{
case MPR_DENSE:
return uResultant::denseResMat;
case 0:
case MPR_SPARSE:
return uResultant::sparseResMat;
default:
return uResultant::none;
}
}
//<-
//-> function u_resultant_det
poly u_resultant_det( ideal gls, int imtype )
{
uResultant::resMatType mtype= determineMType( imtype );
poly resdet;
poly emptypoly= pInit();
number smv= NULL;
TIMING_START(mpr_overall);
// check input ideal ( = polynomial system )
if ( mprIdealCheck( gls, "", mtype ) != mprOk )
{
return emptypoly;
}
uResultant *ures;
// main task 1: setup of resultant matrix
TIMING_START(mpr_constr);
ures= new uResultant( gls, mtype );
TIMING_EPR(mpr_constr,"construction");
// if dense resultant, check if minor nonsingular
if ( mtype == uResultant::denseResMat )
{
smv= ures->accessResMat()->getSubDet();
#ifdef mprDEBUG_PROT
PrintS("// Determinant of submatrix: ");nPrint(smv); PrintLn();
#endif
if ( nIsZero(smv) )
{
WerrorS("Unsuitable input ideal: Minor of resultant matrix is singular!");
return emptypoly;
}
}
// main task 2: Interpolate resultant polynomial
TIMING_START(mpr_ures);
resdet= ures->interpolateDense( smv );
TIMING_EPR(mpr_ures,"ures");
// free mem
delete ures;
nDelete( &smv );
pDelete( &emptypoly );
TIMING_EPR(mpr_overall,"overall");
return ( resdet );
}
//<-
//-----------------------------------------------------------------------------
//#endif // HAVE_MPR
// local Variables: ***
// folded-file: t ***
// compile-command-1: "make installg" ***
// compile-command-2: "make install" ***
// End: ***
// in folding: C-c x
// leave fold: C-c y
// foldmode: F10
|