source: git/kernel/mpr_inout.cc @ 76e501

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