source: git/numeric/mpr_inout.cc @ f5d2647

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