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