source: git/numeric/mpr_inout.cc @ 2e4ec14

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