1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | |
---|
5 | /* $Id: mpr_inout.cc,v 1.1.1.1 2003-10-06 12:15:56 Singular Exp $ */ |
---|
6 | |
---|
7 | /* |
---|
8 | * ABSTRACT - multipolynomial resultant |
---|
9 | */ |
---|
10 | |
---|
11 | #include "mod2.h" |
---|
12 | //#ifdef HAVE_MPR |
---|
13 | |
---|
14 | //-> includes |
---|
15 | #include "structs.h" |
---|
16 | #include "polys.h" |
---|
17 | #include "ideals.h" |
---|
18 | #include "ring.h" |
---|
19 | #include "febase.h" |
---|
20 | #include "omalloc.h" |
---|
21 | #include "numbers.h" |
---|
22 | #include "matpol.h" |
---|
23 | |
---|
24 | #include <math.h> |
---|
25 | |
---|
26 | #include "mpr_global.h" |
---|
27 | #include "mpr_inout.h" |
---|
28 | #include "mpr_base.h" |
---|
29 | #include "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" |
---|
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 | extern size_t gmp_output_digits; |
---|
47 | //<- |
---|
48 | |
---|
49 | //-> nPrint(number n) |
---|
50 | void 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 ) |
---|
62 | void 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("Numer of elements in given ideal %s must be equal to %d!", |
---|
74 | name,pVariables+1); |
---|
75 | break; |
---|
76 | case mprNotZeroDim: |
---|
77 | Werror("The given ideal %s must 0-dimensional!",name); |
---|
78 | break; |
---|
79 | case mprNotHomog: |
---|
80 | Werror("The given ideal %s has to be homogeneous in" |
---|
81 | " the first ring variable!",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() |
---|
96 | mprState mprIdealCheck( const ideal theIdeal, |
---|
97 | const char * name, |
---|
98 | uResultant::resMatType mtype, |
---|
99 | BOOLEAN rmatrix= false ) |
---|
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 ) |
---|
137 | uResultant::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 |
---|
153 | poly 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 |
---|