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