1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | |
---|
5 | /* $Id: mpsr_PutPoly.cc,v 1.12 1998-04-21 10:59:29 obachman Exp $ */ |
---|
6 | |
---|
7 | /*************************************************************** |
---|
8 | * |
---|
9 | * File: mpsr_PutPoly.cc |
---|
10 | * Purpose: rotines which put polys and polynomails (i.e. ring) annotations |
---|
11 | * Author: Olaf Bachmann (10/95) |
---|
12 | * |
---|
13 | * Change History (most recent first): |
---|
14 | * o 1/97 obachman |
---|
15 | * Updated routines to MP and MPP v1.1 |
---|
16 | * |
---|
17 | ***************************************************************/ |
---|
18 | #include "mod2.h" |
---|
19 | |
---|
20 | #ifdef HAVE_MPSR |
---|
21 | |
---|
22 | #include "mpsr_Put.h" |
---|
23 | #include "mpsr_Tok.h" |
---|
24 | #include "longalg.h" |
---|
25 | #include "mmemory.h" |
---|
26 | #include "ring.h" |
---|
27 | #include "polys.h" |
---|
28 | #include "ipid.h" |
---|
29 | |
---|
30 | #ifdef PARI_BIGINT_TEST |
---|
31 | #include "MP_PariBigInt.h" |
---|
32 | MP_Status_t MP_MyPutApIntPacket(MP_Link_pt link, MP_ApInt_t mp_apint, |
---|
33 | MP_NumAnnot_t num_annots) |
---|
34 | { |
---|
35 | GEN pnum = _gmp_to_pari((mpz_ptr) mp_apint); |
---|
36 | return MP_PutApIntPacket(link, (MP_ApInt_t) pnum, num_annots); |
---|
37 | } |
---|
38 | |
---|
39 | #else |
---|
40 | |
---|
41 | #define MP_MyPutApIntPacket MP_PutApIntPacket |
---|
42 | |
---|
43 | #endif |
---|
44 | |
---|
45 | /*************************************************************** |
---|
46 | * |
---|
47 | * global variable definitions |
---|
48 | * |
---|
49 | ***************************************************************/ |
---|
50 | |
---|
51 | static mpsr_Status_t (*PutCoeff)(MP_Link_pt link, number x); |
---|
52 | static mpsr_Status_t (*PutAlgAlgNumber)(MP_Link_pt link, number x); |
---|
53 | static MP_Uint32_t gNalgvars = 0; |
---|
54 | static MP_Sint32_t gNvars = 0; |
---|
55 | static ring CurrPutRing = NULL; |
---|
56 | |
---|
57 | MP_Sint32_t *gTa = NULL; |
---|
58 | MP_Sint32_t gTa_Length = 0; |
---|
59 | |
---|
60 | /*************************************************************** |
---|
61 | * |
---|
62 | * prototype declarations |
---|
63 | * |
---|
64 | ***************************************************************/ |
---|
65 | static void SetPutFuncs(ring r); |
---|
66 | static mpsr_Status_t PutModuloNumber(MP_Link_pt link, number a); |
---|
67 | static mpsr_Status_t PutFloatNumber(MP_Link_pt link, number a); |
---|
68 | static mpsr_Status_t PutRationalNumber(MP_Link_pt link, number a); |
---|
69 | static mpsr_Status_t PutAlgPoly(MP_Link_pt link, alg a); |
---|
70 | static mpsr_Status_t PutAlgNumber(MP_Link_pt link, number a); |
---|
71 | |
---|
72 | static mpsr_Status_t PutVarNamesAnnot(MP_Link_pt link, ring r); |
---|
73 | static mpsr_Status_t PutVarNumberAnnot(MP_Link_pt link, ring r, BOOLEAN mv); |
---|
74 | static mpsr_Status_t PutOrderingAnnot(MP_Link_pt link, ring r, BOOLEAN mv); |
---|
75 | static mpsr_Status_t PutSimpleOrdering(MP_Link_pt link, ring r, short index); |
---|
76 | static mpsr_Status_t PutProtoTypeAnnot(MP_Link_pt link, ring r, BOOLEAN mv); |
---|
77 | static mpsr_Status_t PutMinPolyAnnot(MP_Link_pt link, ring r); |
---|
78 | static mpsr_Status_t PutDefRelsAnnot(MP_Link_pt link, ring r); |
---|
79 | |
---|
80 | |
---|
81 | /*************************************************************** |
---|
82 | * |
---|
83 | * Setting the global Put Functions |
---|
84 | * |
---|
85 | ***************************************************************/ |
---|
86 | static void SetPutFuncs(ring r) |
---|
87 | { |
---|
88 | CurrPutRing = r; |
---|
89 | // first, we set the PutNumber function |
---|
90 | gNvars = r->N; |
---|
91 | mpsr_InitTempArray(gNvars+1); |
---|
92 | |
---|
93 | if ((r->ch) == 0) |
---|
94 | // rational numbers |
---|
95 | PutCoeff= PutRationalNumber; |
---|
96 | else if ((r->ch) > 1) |
---|
97 | // Form our point of view, ModuloP numbers and numbers from |
---|
98 | // GF(p,n) are the same, here. They only differ in the annots |
---|
99 | PutCoeff = PutModuloNumber; |
---|
100 | else if ((r->ch) == -1) |
---|
101 | PutCoeff = PutFloatNumber; |
---|
102 | else |
---|
103 | { |
---|
104 | // now we come to algebraic numbers |
---|
105 | gNalgvars = rPar(r); |
---|
106 | mpsr_InitTempArray(gNalgvars); |
---|
107 | PutCoeff = PutAlgNumber; |
---|
108 | if ((r->ch) < 0) |
---|
109 | // first, Z/p(a) |
---|
110 | PutAlgAlgNumber = PutModuloNumber; |
---|
111 | else |
---|
112 | PutAlgAlgNumber = PutRationalNumber; |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | |
---|
117 | |
---|
118 | /*************************************************************** |
---|
119 | * |
---|
120 | * modulo numbers (i.e. char p, or p^n) |
---|
121 | * |
---|
122 | ***************************************************************/ |
---|
123 | // we always put modulo numbers without a header, since |
---|
124 | // we have type-spec this before |
---|
125 | static mpsr_Status_t PutModuloNumber(MP_Link_pt link, number a) |
---|
126 | { |
---|
127 | mp_return(IMP_PutUint32(link, (MP_Uint32_t) a)); |
---|
128 | } |
---|
129 | |
---|
130 | static mpsr_Status_t PutFloatNumber(MP_Link_pt link, number a) |
---|
131 | { |
---|
132 | mp_return(IMP_PutReal32(link , Number_2_Real32(a))); |
---|
133 | } |
---|
134 | |
---|
135 | /*************************************************************** |
---|
136 | * |
---|
137 | * rational (i.e. char 0) numbers |
---|
138 | * |
---|
139 | ***************************************************************/ |
---|
140 | // This supposes that number is of char 0, i.e. a rational number |
---|
141 | static mpsr_Status_t PutRationalNumber(MP_Link_pt link, number a) |
---|
142 | { |
---|
143 | // Check for case number == NULL == 0 |
---|
144 | if (a == NULL) |
---|
145 | mp_return( MP_PutSint32Packet(link, 0, 0)); |
---|
146 | |
---|
147 | // check for SR_INT type |
---|
148 | if (SR_HDL(a) & SR_INT) |
---|
149 | mp_return( MP_PutSint32Packet(link, SR_TO_INT(a), 0)); |
---|
150 | |
---|
151 | // check for single GMP integer |
---|
152 | if ((a->s) == 3) |
---|
153 | mp_return(MP_MyPutApIntPacket(link, (MP_ApInt_t) &(a->z), 0)); |
---|
154 | |
---|
155 | // Now we have a fraction |
---|
156 | // normalize, if necessary |
---|
157 | // if ((a->s) == 0) |
---|
158 | // { |
---|
159 | // // nlNormalize(a); |
---|
160 | // return PutRationalNumber(link, a); |
---|
161 | // } |
---|
162 | |
---|
163 | // send number itself |
---|
164 | mp_failr(MP_PutCommonOperatorPacket(link, |
---|
165 | MP_BasicDict, |
---|
166 | MP_CopBasicDiv, |
---|
167 | 0, |
---|
168 | 2)); |
---|
169 | // and now sent nominator and denominator |
---|
170 | mp_failr(MP_MyPutApIntPacket(link, (MP_ApInt_t) &(a->z), 0)); |
---|
171 | mp_return(MP_MyPutApIntPacket(link, (MP_ApInt_t) &(a->n), 0)); |
---|
172 | } |
---|
173 | |
---|
174 | /*************************************************************** |
---|
175 | * |
---|
176 | * Algebraic Numbers (a la Singular) |
---|
177 | * |
---|
178 | ***************************************************************/ |
---|
179 | inline MP_Uint32_t GetPlength(alg a) |
---|
180 | { |
---|
181 | MP_Uint32_t i = 0; |
---|
182 | while (a != NULL) |
---|
183 | { |
---|
184 | i++; |
---|
185 | a = a->ne; |
---|
186 | } |
---|
187 | return i; |
---|
188 | } |
---|
189 | |
---|
190 | static mpsr_Status_t PutAlgNumber(MP_Link_pt link, number a) |
---|
191 | { |
---|
192 | lnumber b; |
---|
193 | |
---|
194 | if (a == NULL) |
---|
195 | mp_return(IMP_PutUint32(link, 0)); |
---|
196 | |
---|
197 | b = (lnumber) a; |
---|
198 | if ((b->n) == NULL) // NULL means there is only one number |
---|
199 | { |
---|
200 | // hence, we use the first case of the union |
---|
201 | mp_failr(IMP_PutUint32(link, 1)); |
---|
202 | mp_failr(IMP_PutUint32(link, GetPlength(b->z))); |
---|
203 | return PutAlgPoly(link, (alg) (b->z)); |
---|
204 | } |
---|
205 | else |
---|
206 | { |
---|
207 | // we use the 2nd case of the union |
---|
208 | mp_failr(IMP_PutUint32(link, 2)); |
---|
209 | mp_failr(IMP_PutUint32(link, GetPlength(b->z))); |
---|
210 | failr(PutAlgPoly(link, (alg) (b->z))); |
---|
211 | mp_failr(IMP_PutUint32(link, GetPlength(b->n))); |
---|
212 | return PutAlgPoly(link, (alg) (b->n)); |
---|
213 | } |
---|
214 | } |
---|
215 | |
---|
216 | // this is very similar to putting a Poly |
---|
217 | static mpsr_Status_t PutAlgPoly(MP_Link_pt link, alg a) |
---|
218 | { |
---|
219 | unsigned int i; |
---|
220 | int *exp; |
---|
221 | |
---|
222 | if (gNalgvars > 1) |
---|
223 | while (a != NULL) |
---|
224 | { |
---|
225 | failr(PutAlgAlgNumber(link, a->ko)); |
---|
226 | #if (SIZEOF_INT == SIZEOF_PARAMETER) |
---|
227 | mp_failr(IMP_PutSint32Vector(link, (MP_Sint32_t *) a->e, gNalgvars)); |
---|
228 | #else |
---|
229 | for (i=0; i<gNalgvars; i++) |
---|
230 | gTa[i] = a->e[i]; |
---|
231 | mp_failr(IMP_PutSint32Vector(link, gTa, gNalgvars)); |
---|
232 | #endif |
---|
233 | a = a->ne; |
---|
234 | } |
---|
235 | else |
---|
236 | { |
---|
237 | while (a != NULL) |
---|
238 | { |
---|
239 | failr(PutAlgAlgNumber(link, a->ko)); |
---|
240 | IMP_PutSint32(link, (MP_Sint32_t) a->e[0]); |
---|
241 | a = a->ne; |
---|
242 | } |
---|
243 | } |
---|
244 | return mpsr_Success; |
---|
245 | } |
---|
246 | |
---|
247 | /*************************************************************** |
---|
248 | * |
---|
249 | * Putting polys |
---|
250 | * |
---|
251 | ***************************************************************/ |
---|
252 | mpsr_Status_t mpsr_PutPolyData(MP_Link_pt link, poly p, ring cring) |
---|
253 | { |
---|
254 | if (cring != CurrPutRing) |
---|
255 | SetPutFuncs(cring); |
---|
256 | |
---|
257 | #ifdef MPSR_DEBUG |
---|
258 | if (currRing == cring) |
---|
259 | pTest(p); |
---|
260 | #endif |
---|
261 | |
---|
262 | if (gNvars > 1) |
---|
263 | { |
---|
264 | short i; |
---|
265 | MP_Sint32_t *ta1 = &(gTa[1]); |
---|
266 | |
---|
267 | while (p != NULL) |
---|
268 | { |
---|
269 | failr(PutCoeff(link, pGetCoeff(p))); |
---|
270 | for (i=1; i<=gNvars; i++) |
---|
271 | gTa[i] = (MP_Sint32_t) pGetExp(p, i); |
---|
272 | mp_failr(IMP_PutSint32Vector(link, ta1, gNvars)); |
---|
273 | pIter(p); |
---|
274 | } |
---|
275 | } |
---|
276 | else |
---|
277 | while (p != NULL) |
---|
278 | { |
---|
279 | failr(PutCoeff(link, pGetCoeff(p))); |
---|
280 | IMP_PutSint32(link, (MP_Sint32_t) pGetExp(p,1)); |
---|
281 | pIter(p); |
---|
282 | } |
---|
283 | return mpsr_Success; |
---|
284 | } |
---|
285 | |
---|
286 | mpsr_Status_t mpsr_PutPolyVectorData(MP_Link_pt link, poly p, ring cring) |
---|
287 | { |
---|
288 | short i, n1; |
---|
289 | |
---|
290 | if (cring != CurrPutRing) |
---|
291 | SetPutFuncs(cring); |
---|
292 | |
---|
293 | if (gNvars > 1) |
---|
294 | { |
---|
295 | short i, n1= gNvars + 1; |
---|
296 | while (p != NULL) |
---|
297 | { |
---|
298 | failr(PutCoeff(link, pGetCoeff(p))); |
---|
299 | gTa[0] = pGetComp(p); |
---|
300 | for (i=1; i< n1; i++) |
---|
301 | gTa[i] = (MP_Sint32_t) pGetExp(p,i); |
---|
302 | mp_failr(IMP_PutSint32Vector(link, gTa, n1)); |
---|
303 | pIter(p); |
---|
304 | } |
---|
305 | } |
---|
306 | else |
---|
307 | while (p != NULL) |
---|
308 | { |
---|
309 | failr(PutCoeff(link, pGetCoeff(p))); |
---|
310 | IMP_PutSint32(link, (MP_Sint32_t) pGetComp(p)); |
---|
311 | IMP_PutSint32(link, (MP_Sint32_t) pGetExp(p,1)); |
---|
312 | pIter(p); |
---|
313 | } |
---|
314 | return mpsr_Success; |
---|
315 | } |
---|
316 | |
---|
317 | /*************************************************************** |
---|
318 | * |
---|
319 | * The putting annotation buisness |
---|
320 | * |
---|
321 | ***************************************************************/ |
---|
322 | int mpsr_GetNumOfRingAnnots(ring r, BOOLEAN mv) |
---|
323 | { |
---|
324 | short annots = 4; |
---|
325 | |
---|
326 | if (mv) annots++; |
---|
327 | if (r->qideal != NULL) annots++; |
---|
328 | // we sent the minpoly with the coefficient ring |
---|
329 | if (r->minpoly != NULL & r->parameter == NULL) annots++; |
---|
330 | |
---|
331 | return annots; |
---|
332 | } |
---|
333 | |
---|
334 | mpsr_Status_t mpsr_PutRingAnnots(MP_Link_pt link, ring r, BOOLEAN mv) |
---|
335 | { |
---|
336 | failr(PutProtoTypeAnnot(link,r, mv)); |
---|
337 | failr(PutVarNumberAnnot(link, r, mv)); |
---|
338 | failr(PutVarNamesAnnot(link,r)); |
---|
339 | failr(PutOrderingAnnot(link,r, mv)); |
---|
340 | |
---|
341 | if (mv) |
---|
342 | mp_failr(MP_PutAnnotationPacket(link, |
---|
343 | MP_PolyDict, |
---|
344 | MP_AnnotPolyModuleVector, |
---|
345 | MP_AnnotRequired)); |
---|
346 | // Hmm .. this is not according to a "proper" Singular ring, |
---|
347 | // but to be used in a recursive call of mpsr_PutRingAnnots |
---|
348 | if (r->minpoly != NULL && r->parameter == NULL && r->ch > 0) |
---|
349 | failr(PutMinPolyAnnot(link,r)); |
---|
350 | |
---|
351 | if (r->qideal != NULL) |
---|
352 | return PutDefRelsAnnot(link, r); |
---|
353 | |
---|
354 | return mpsr_Success; |
---|
355 | } |
---|
356 | |
---|
357 | static mpsr_Status_t PutProtoTypeAnnot(MP_Link_pt link, ring r, |
---|
358 | BOOLEAN mv) |
---|
359 | { |
---|
360 | // each element of the poly is a |
---|
361 | mp_failr(MP_PutAnnotationPacket(link, |
---|
362 | MP_ProtoDict, |
---|
363 | MP_AnnotProtoPrototype, |
---|
364 | MP_AnnotReqValNode)); |
---|
365 | // Monom represented as a struct of 2 elements |
---|
366 | mp_failr(MP_PutCommonOperatorPacket(link, |
---|
367 | MP_ProtoDict, |
---|
368 | MP_CopProtoStruct, |
---|
369 | 0, |
---|
370 | 2)); |
---|
371 | |
---|
372 | // First element is the coefficient |
---|
373 | if ((r->ch) == 0) |
---|
374 | { |
---|
375 | // rational numbers |
---|
376 | mp_failr(MP_PutCommonMetaTypePacket(link, |
---|
377 | MP_NumberDict, |
---|
378 | MP_CmtNumberRational, |
---|
379 | 1)); |
---|
380 | // are always normalized (and made that way, if necessary) |
---|
381 | mp_failr(MP_PutAnnotationPacket(link, |
---|
382 | MP_NumberDict, |
---|
383 | MP_AnnotNumberIsNormalized, |
---|
384 | 0)); |
---|
385 | } |
---|
386 | else if ((r->ch) > 1) |
---|
387 | { |
---|
388 | // modulo p numbers |
---|
389 | // are communicated as IMP_Uint32's |
---|
390 | mp_failr(MP_PutCommonMetaTypePacket(link, |
---|
391 | MP_ProtoDict, |
---|
392 | MP_CmtProtoIMP_Uint32, |
---|
393 | 1)); |
---|
394 | // but are taken as modulo numbers |
---|
395 | mp_failr(MP_PutAnnotationPacket(link, |
---|
396 | MP_NumberDict, |
---|
397 | MP_AnnotNumberModulos, |
---|
398 | MP_AnnotValuated)); |
---|
399 | // with Modulo |
---|
400 | mp_failr(MP_PutUint32Packet(link, r->ch, 1)); |
---|
401 | if (r->parameter == NULL) |
---|
402 | { |
---|
403 | // which is (in our case) always a prime number |
---|
404 | mp_failr(MP_PutAnnotationPacket(link, |
---|
405 | MP_NumberDict, |
---|
406 | MP_AnnotNumberIsPrime, |
---|
407 | 0)); |
---|
408 | } |
---|
409 | else |
---|
410 | { |
---|
411 | mp_failr(MP_PutAnnotationPacket(link, |
---|
412 | MP_SingularDict, |
---|
413 | MP_AnnotSingularGalois, |
---|
414 | MP_AnnotValuated)); |
---|
415 | mp_failr(MP_PutStringPacket(link, r->parameter[0], 0)); |
---|
416 | } |
---|
417 | } |
---|
418 | else if ((r->ch) == -1) |
---|
419 | { |
---|
420 | // floats |
---|
421 | mp_failr(MP_PutCommonMetaTypePacket(link, |
---|
422 | MP_ProtoDict, |
---|
423 | MP_CmtProtoIMP_Real32, |
---|
424 | 0)); |
---|
425 | } |
---|
426 | else |
---|
427 | { |
---|
428 | // alg numbers |
---|
429 | // create temporary ring for describing the coeeficient domain |
---|
430 | ring alg_r = (ring) Alloc0(sizeof(sip_sring)); |
---|
431 | |
---|
432 | alg_r->N = rPar(r); |
---|
433 | alg_r->ch = (r->ch < 0 ? - (r->ch) : 0); |
---|
434 | alg_r->order = (int *) Alloc(3*sizeof(int)); |
---|
435 | alg_r->order[2] = ringorder_no; |
---|
436 | alg_r->order[1] = ringorder_C; |
---|
437 | alg_r->order[0] = ringorder_lp; |
---|
438 | alg_r->names = r->parameter; |
---|
439 | alg_r->minpoly = r->minpoly; |
---|
440 | |
---|
441 | // Algebraic numbers are |
---|
442 | // a fraction of two Dense Dist Polys |
---|
443 | mp_failr(MP_PutCommonMetaOperatorPacket(link, |
---|
444 | MP_BasicDict, |
---|
445 | MP_CopBasicDiv, |
---|
446 | 1, |
---|
447 | 0)); |
---|
448 | mp_failr(MP_PutAnnotationPacket(link, |
---|
449 | MP_ProtoDict, |
---|
450 | MP_AnnotProtoPrototype, |
---|
451 | MP_AnnotReqValNode)); |
---|
452 | mp_failr(MP_PutCommonMetaOperatorPacket(link, |
---|
453 | MP_PolyDict, |
---|
454 | MP_CopPolyDenseDistPoly, |
---|
455 | mpsr_GetNumOfRingAnnots(alg_r, 0), |
---|
456 | 0)); |
---|
457 | failr(mpsr_PutRingAnnots(link, alg_r, 0)); |
---|
458 | |
---|
459 | // destroy temporary ring |
---|
460 | Free(alg_r->order, 3*sizeof(int)); |
---|
461 | Free(alg_r, sizeof(sip_sring)); |
---|
462 | } |
---|
463 | |
---|
464 | // second element is the exponent vector |
---|
465 | mp_failr(MP_PutCommonMetaOperatorPacket(link, |
---|
466 | MP_ProtoDict, |
---|
467 | MP_CopProtoArray, |
---|
468 | 1, |
---|
469 | (mv ? r->N + 1 : r->N))); |
---|
470 | mp_failr(MP_PutAnnotationPacket(link, |
---|
471 | MP_ProtoDict, |
---|
472 | MP_AnnotProtoPrototype, |
---|
473 | MP_AnnotReqValNode)); |
---|
474 | mp_return(MP_PutCommonMetaTypePacket(link, |
---|
475 | MP_ProtoDict, |
---|
476 | MP_CmtProtoIMP_Sint32, |
---|
477 | 0)); |
---|
478 | } |
---|
479 | |
---|
480 | |
---|
481 | static mpsr_Status_t PutVarNamesAnnot(MP_Link_pt link, ring r) |
---|
482 | { |
---|
483 | // first, we put the annot packet, with flags (1, 0, 1, 0) |
---|
484 | mp_failr(MP_PutAnnotationPacket(link, |
---|
485 | MP_PolyDict, |
---|
486 | MP_AnnotPolyVarNames, |
---|
487 | MP_AnnotValuated)); |
---|
488 | // now, the varnames follow |
---|
489 | if ((r->N) == 1) |
---|
490 | { |
---|
491 | // only 1 varname |
---|
492 | mp_return(MP_PutIdentifierPacket(link, MP_SingularDict, *(r->names), 0)); |
---|
493 | } |
---|
494 | else |
---|
495 | { |
---|
496 | // more than one varname |
---|
497 | char **names = r->names; |
---|
498 | int i, n = r->N; |
---|
499 | |
---|
500 | mp_failr(MP_PutCommonOperatorPacket(link, |
---|
501 | MP_ProtoDict, |
---|
502 | MP_CopProtoArray, |
---|
503 | 1, |
---|
504 | r->N)); |
---|
505 | mp_failr(MP_PutAnnotationPacket(link, |
---|
506 | MP_ProtoDict, |
---|
507 | MP_AnnotProtoPrototype, |
---|
508 | MP_AnnotReqValNode)); |
---|
509 | |
---|
510 | mp_failr(MP_PutCommonMetaTypePacket(link, |
---|
511 | MP_ProtoDict, |
---|
512 | MP_CmtProtoIMP_Identifier, |
---|
513 | 0)); |
---|
514 | for (i=0; i<n; i++) |
---|
515 | mp_failr(IMP_PutString(link, names[i])); |
---|
516 | |
---|
517 | return mpsr_Success; |
---|
518 | } |
---|
519 | } |
---|
520 | |
---|
521 | static mpsr_Status_t PutVarNumberAnnot(MP_Link_pt link, ring r, BOOLEAN mv) |
---|
522 | { |
---|
523 | mp_failr(MP_PutAnnotationPacket(link, |
---|
524 | MP_PolyDict, |
---|
525 | MP_AnnotPolyVarNumber, |
---|
526 | MP_AnnotValuated)); |
---|
527 | mp_return(MP_PutUint32Packet(link, (mv ? r->N + 1 : r->N), 0)); |
---|
528 | } |
---|
529 | |
---|
530 | |
---|
531 | static mpsr_Status_t PutOrderingAnnot(MP_Link_pt link, ring r, BOOLEAN mv) |
---|
532 | { |
---|
533 | int index = 0, nblocks = 0; |
---|
534 | int *order = r->order; |
---|
535 | |
---|
536 | mp_failr(MP_PutAnnotationPacket(link, |
---|
537 | MP_PolyDict, |
---|
538 | MP_AnnotPolyOrdering, |
---|
539 | MP_AnnotValuated)); |
---|
540 | |
---|
541 | // let's see whether we have a simple ordering to sent |
---|
542 | if ((mv == 0) && (order[2] == ringorder_no)) |
---|
543 | { |
---|
544 | if (order[1] == ringorder_C || order[1] == ringorder_c) |
---|
545 | index = 0; |
---|
546 | else |
---|
547 | index = 1; |
---|
548 | |
---|
549 | return PutSimpleOrdering(link, r, index); |
---|
550 | } |
---|
551 | |
---|
552 | // No -- so we are dealing with a product ordering |
---|
553 | // First, let's find out how many blocks there are |
---|
554 | while (order[nblocks] != ringorder_no) nblocks++; |
---|
555 | // if we deal with a non-vector, we are not going to sent |
---|
556 | // the vector ordering |
---|
557 | mp_failr(MP_PutCommonOperatorPacket(link, |
---|
558 | MP_BasicDict, |
---|
559 | MP_CopBasicList, |
---|
560 | 0, |
---|
561 | (mv ? nblocks : nblocks - 1))); |
---|
562 | |
---|
563 | for (index = 0; index < nblocks; index ++) |
---|
564 | // Do not sent vector ordering, if we are sending pure polys |
---|
565 | if (! (mv == 0 && (order[index] == ringorder_C || |
---|
566 | order[index] == ringorder_c))) |
---|
567 | { |
---|
568 | // a product ordering is sent as triple |
---|
569 | mp_failr(MP_PutCommonOperatorPacket(link, |
---|
570 | MP_BasicDict, |
---|
571 | MP_CopBasicList, |
---|
572 | 0, |
---|
573 | 3)); |
---|
574 | // first element is the simple ordering |
---|
575 | failr(PutSimpleOrdering(link, r, index)); |
---|
576 | // second and third for covered variables |
---|
577 | mp_failr(MP_PutUint32Packet(link, (MP_Uint32_t) r->block0[index], 0)); |
---|
578 | mp_failr(MP_PutUint32Packet(link, (MP_Uint32_t) r->block1[index], 0)); |
---|
579 | } |
---|
580 | |
---|
581 | return mpsr_Success; |
---|
582 | } |
---|
583 | |
---|
584 | |
---|
585 | static mpsr_Status_t PutSimpleOrdering(MP_Link_pt link, ring r, short index) |
---|
586 | { |
---|
587 | MP_Uint32_t vlength = 0, i; |
---|
588 | |
---|
589 | // find out the length of the weight-vector |
---|
590 | if (r->wvhdl && r->wvhdl[index] != NULL) |
---|
591 | vlength = r->block1[index] - r->block0[index] + 1; |
---|
592 | |
---|
593 | mp_failr(MP_PutCommonConstantPacket(link, |
---|
594 | MP_PolyDict, |
---|
595 | mpsr_ord2mp(r->order[index]), |
---|
596 | (vlength == 0 ? 0 : 1))); |
---|
597 | |
---|
598 | if (vlength == 0) return mpsr_Success; |
---|
599 | |
---|
600 | // deal with the weights |
---|
601 | mp_failr(MP_PutAnnotationPacket(link, |
---|
602 | MP_PolyDict, |
---|
603 | MP_AnnotPolyWeights, |
---|
604 | MP_AnnotValuated)); |
---|
605 | if (r->order[index] == ringorder_M) |
---|
606 | { |
---|
607 | // put the matrix header |
---|
608 | mp_failr(MP_PutCommonOperatorPacket(link, |
---|
609 | MP_MatrixDict, |
---|
610 | MP_CopMatrixDenseMatrix, |
---|
611 | 2, |
---|
612 | vlength*vlength)); |
---|
613 | mp_failr(MP_PutAnnotationPacket(link, |
---|
614 | MP_ProtoDict, |
---|
615 | MP_AnnotProtoPrototype, |
---|
616 | MP_AnnotReqValNode)); |
---|
617 | mp_failr(MP_PutCommonMetaTypePacket(link, |
---|
618 | MP_ProtoDict, |
---|
619 | MP_CmtProtoIMP_Sint32, |
---|
620 | 0)); |
---|
621 | mp_failr(MP_PutAnnotationPacket(link, |
---|
622 | MP_MatrixDict, |
---|
623 | MP_AnnotMatrixDimension, |
---|
624 | MP_AnnotReqValNode)); |
---|
625 | mp_failr(MP_PutCommonOperatorPacket(link, |
---|
626 | MP_BasicDict, |
---|
627 | MP_CopBasicList, |
---|
628 | 0, 2)); |
---|
629 | mp_failr(MP_PutUint32Packet(link, (MP_Uint32_t) vlength, 0)); |
---|
630 | mp_failr(MP_PutUint32Packet(link, (MP_Uint32_t) vlength, 0)); |
---|
631 | vlength *= vlength; |
---|
632 | } |
---|
633 | else |
---|
634 | { |
---|
635 | // vector header |
---|
636 | mp_failr(MP_PutCommonOperatorPacket(link, |
---|
637 | MP_MatrixDict, |
---|
638 | MP_CopMatrixDenseVector, |
---|
639 | 1, |
---|
640 | vlength)); |
---|
641 | mp_failr(MP_PutAnnotationPacket(link, |
---|
642 | MP_ProtoDict, |
---|
643 | MP_AnnotProtoPrototype, |
---|
644 | MP_AnnotReqValNode)); |
---|
645 | mp_failr(MP_PutCommonMetaTypePacket(link, |
---|
646 | MP_ProtoDict, |
---|
647 | MP_CmtProtoIMP_Sint32, |
---|
648 | 0)); |
---|
649 | } |
---|
650 | |
---|
651 | // weights are all what remains |
---|
652 | for (i=0; i<vlength; i++) |
---|
653 | mp_failr(IMP_PutSint32(link, (MP_Sint32_t) r->wvhdl[index][i])); |
---|
654 | |
---|
655 | return mpsr_Success; |
---|
656 | } |
---|
657 | |
---|
658 | static mpsr_Status_t PutMinPolyAnnot(MP_Link_pt link, ring r) |
---|
659 | { |
---|
660 | mpsr_assume(r->minpoly != NULL && r->ch > 0 && r->parameter == NULL); |
---|
661 | |
---|
662 | number minpoly = r->minpoly; |
---|
663 | r->minpoly = 0; |
---|
664 | |
---|
665 | mp_failr(MP_PutAnnotationPacket(link, |
---|
666 | MP_PolyDict, |
---|
667 | MP_AnnotPolyDefRel, |
---|
668 | MP_AnnotValuated)); |
---|
669 | mp_failr(MP_PutCommonOperatorPacket(link, |
---|
670 | MP_PolyDict, |
---|
671 | MP_CopPolyDenseDistPoly, |
---|
672 | 5, |
---|
673 | GetPlength( ((lnumber) minpoly)->z))); |
---|
674 | failr(PutProtoTypeAnnot(link, r, 0)); |
---|
675 | failr(PutVarNamesAnnot(link, r)); |
---|
676 | failr(PutVarNumberAnnot(link, r,0)); |
---|
677 | failr(PutOrderingAnnot(link, r, 0)); |
---|
678 | mp_failr(MP_PutAnnotationPacket(link, |
---|
679 | MP_PolyDict, |
---|
680 | MP_AnnotPolyIrreducible, |
---|
681 | 0)); |
---|
682 | |
---|
683 | // need to set PutAlgAlgnumber and gNalgVars |
---|
684 | CurrPutRing = r; |
---|
685 | if (r->ch > 0) |
---|
686 | PutAlgAlgNumber = PutModuloNumber; |
---|
687 | else |
---|
688 | PutAlgAlgNumber = PutRationalNumber; |
---|
689 | gNalgvars = r->N; |
---|
690 | |
---|
691 | r->minpoly = minpoly; |
---|
692 | return PutAlgPoly(link, ((lnumber) minpoly)->z); |
---|
693 | } |
---|
694 | |
---|
695 | |
---|
696 | static mpsr_Status_t PutDefRelsAnnot(MP_Link_pt link, ring r) |
---|
697 | { |
---|
698 | int i, idn; |
---|
699 | ideal id; |
---|
700 | |
---|
701 | id = r->qideal; |
---|
702 | r->qideal = NULL; |
---|
703 | |
---|
704 | mp_failr(MP_PutAnnotationPacket(link, |
---|
705 | MP_PolyDict, |
---|
706 | MP_AnnotPolyDefRel, |
---|
707 | MP_AnnotValuated)); |
---|
708 | failr(mpsr_PutIdeal(link, id, r)); |
---|
709 | r->qideal = id; |
---|
710 | return mpsr_Success; |
---|
711 | } |
---|
712 | |
---|
713 | #endif |
---|