source: git/libpolys/coeffs/generics.cc @ a3f0fea

fieker-DuValspielwiese
Last change on this file since a3f0fea was a3f0fea, checked in by Reimer Behrends <behrends@…>, 5 years ago
Modify variable declarions for pSingular.
  • Property mode set to 100644
File size: 12.5 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/*
5* ABSTRACT: numbers (integers)
6*/
7
8#include "misc/auxiliary.h"
9
10#include "factory/factory.h"
11
12#include "misc/mylimits.h"
13#include "reporter/reporter.h"
14
15#include "coeffs/coeffs.h"
16#include "coeffs/longrat.h"
17#include "coeffs/numbers.h"
18
19#include "coeffs/si_gmp.h"
20
21#include "coeffs/generics.h"
22
23#include "coeffs/rintegers.h"
24
25#include <string.h>
26
27struct generic_pair
28{
29  number a1;
30  number a2;
31};
32typedef struct generic_pair *gcp;
33VAR coeffs coeffs1,coeffs2;
34
35static void gCoeffWrite(const coeffs r, BOOLEAN b)
36{
37  printf("debug: ");
38  coeffs1->cfCoeffWrite(coeffs1,b);
39}
40
41char* gCoeffString(const coeffs r)
42{
43  return coeffs1->cfCoeffString(coeffs1);
44}
45char* gCoeffName(const coeffs r)
46{
47  return coeffs1->cfCoeffName(coeffs1);
48}
49void gKillChar(coeffs r)
50{
51  coeffs1->cfKillChar(coeffs1);
52  coeffs2->cfKillChar(coeffs2);
53}
54void gSetChar(coeffs r)
55{
56  coeffs1->cfSetChar(coeffs1);
57  coeffs2->cfSetChar(coeffs2);
58}
59
60static number gMult (number a, number b, const coeffs cf)
61{
62  gcp aa=(gcp)a;
63  gcp bb=(gcp)b;
64  gcp cc=(gcp)omalloc(sizeof(*cc));
65  cc->a1=coeffs1->cfMult(aa->a1,bb->a1,coeffs1);
66  cc->a2=coeffs2->cfMult(aa->a2,bb->a2,coeffs2);
67  n_Test((number)cc,cf);
68  return (number)cc;
69}
70static number gSub (number a, number b, const coeffs cf)
71{
72  gcp aa=(gcp)a;
73  gcp bb=(gcp)b;
74  gcp cc=(gcp)omalloc(sizeof(*cc));
75  cc->a1=coeffs1->cfSub(aa->a1,bb->a1,coeffs1);
76  cc->a2=coeffs2->cfSub(aa->a2,bb->a2,coeffs2);
77  n_Test((number)cc,cf);
78  return (number)cc;
79}
80static number gAdd (number a, number b, const coeffs cf)
81{
82  gcp aa=(gcp)a;
83  gcp bb=(gcp)b;
84  gcp cc=(gcp)omalloc(sizeof(*cc));
85  cc->a1=coeffs1->cfAdd(aa->a1,bb->a1,coeffs1);
86  cc->a2=coeffs2->cfAdd(aa->a2,bb->a2,coeffs2);
87  n_Test((number)cc,cf);
88  return (number)cc;
89}
90static number gDiv (number a, number b, const coeffs cf)
91{
92  gcp aa=(gcp)a;
93  gcp bb=(gcp)b;
94  gcp cc=(gcp)omalloc(sizeof(*cc));
95  cc->a1=coeffs1->cfDiv(aa->a1,bb->a1,coeffs1);
96  cc->a2=coeffs2->cfDiv(aa->a2,bb->a2,coeffs2);
97  n_Test((number)cc,cf);
98  return (number)cc;
99}
100static number gIntMod (number a, number b, const coeffs cf)
101{
102  gcp aa=(gcp)a;
103  gcp bb=(gcp)b;
104  gcp cc=(gcp)omalloc(sizeof(*cc));
105  cc->a1=coeffs1->cfIntMod(aa->a1,bb->a1,coeffs1);
106  cc->a2=coeffs2->cfIntMod(aa->a2,bb->a2,coeffs2);
107  n_Test((number)cc,cf);
108  return (number)cc;
109}
110static number gExactDiv (number a, number b, const coeffs cf)
111{
112  gcp aa=(gcp)a;
113  gcp bb=(gcp)b;
114  gcp cc=(gcp)omalloc(sizeof(*cc));
115  cc->a1=coeffs1->cfExactDiv(aa->a1,bb->a1,coeffs1);
116  cc->a2=coeffs2->cfExactDiv(aa->a2,bb->a2,coeffs2);
117  n_Test((number)cc,cf);
118  return (number)cc;
119}
120static number gInit (long i, const coeffs cf)
121{
122  gcp cc=(gcp)omalloc(sizeof(*cc));
123  cc->a1=coeffs1->cfInit(i,coeffs1);
124  cc->a2=coeffs2->cfInit(i,coeffs2);
125  n_Test((number)cc,cf);
126  return (number)cc;
127}
128static number gInitMPZ (mpz_t i, const coeffs cf)
129{
130  gcp cc=(gcp)omalloc(sizeof(*cc));
131  cc->a1=coeffs1->cfInitMPZ(i,coeffs1);
132  cc->a2=coeffs2->cfInitMPZ(i,coeffs2);
133  n_Test((number)cc,cf);
134  return (number)cc;
135}
136static int gSize (number a, const coeffs)
137{
138  gcp aa=(gcp)a;
139  int s1=coeffs1->cfSize(aa->a1,coeffs1);
140  int s2=coeffs2->cfSize(aa->a2,coeffs2);
141  if (s1!=s2)
142  {
143    printf("gSize: %d, %d\n",s1,s2);
144  }
145  return s1;
146}
147static long gInt (number &a, const coeffs)
148{
149  gcp aa=(gcp)a;
150  long s1=coeffs1->cfInt(aa->a1,coeffs1);
151  long s2=coeffs2->cfInt(aa->a2,coeffs2);
152  if (s1!=s2)
153  {
154    printf("gInt: %ld, %ld\n",s1,s2);
155  }
156  return s1;
157}
158static void gMPZ(mpz_t result, number &n, const coeffs r)
159{
160  coeffs1->cfMPZ(result,n,coeffs1);
161  mpz_t r2;
162  coeffs2->cfMPZ(r2,n,coeffs2);
163  if(mpz_cmp(result,r2)!=0)
164  {
165    printf("gMPZ\n");
166  }
167  mpz_clear(r2);
168}
169static number  gInpNeg(number a, const coeffs r)
170{
171  gcp aa=(gcp)a;
172  aa->a1=coeffs1->cfInpNeg(aa->a1,coeffs1);
173  aa->a2=coeffs2->cfInpNeg(aa->a2,coeffs2);
174  return (number)aa;
175}
176static number  gInvers(number a, const coeffs r)
177{
178  gcp aa=(gcp)a;
179  gcp cc=(gcp)omalloc(sizeof(*cc));
180  cc->a1=coeffs1->cfInvers(aa->a1,coeffs1);
181  cc->a2=coeffs2->cfInvers(aa->a2,coeffs2);
182  return (number)cc;
183}
184static number  gCopy(number a, const coeffs r)
185{
186  gcp aa=(gcp)a;
187  gcp cc=(gcp)omalloc(sizeof(*cc));
188  cc->a1=coeffs1->cfCopy(aa->a1,coeffs1);
189  cc->a2=coeffs2->cfCopy(aa->a2,coeffs2);
190  return (number)cc;
191}
192static number  gRePart(number a, const coeffs r)
193{
194  gcp aa=(gcp)a;
195  gcp cc=(gcp)omalloc(sizeof(*cc));
196  cc->a1=coeffs1->cfRePart(aa->a1,coeffs1);
197  cc->a2=coeffs2->cfRePart(aa->a2,coeffs2);
198  return (number)cc;
199}
200static number  gImPart(number a, const coeffs r)
201{
202  gcp aa=(gcp)a;
203  gcp cc=(gcp)omalloc(sizeof(*cc));
204  cc->a1=coeffs1->cfRePart(aa->a1,coeffs1);
205  cc->a2=coeffs2->cfRePart(aa->a2,coeffs2);
206  return (number)cc;
207}
208static void  gWriteLong(number a, const coeffs r)
209{
210  gcp aa=(gcp)a;
211  coeffs1->cfWriteLong(aa->a1,coeffs1);
212}
213static void  gWriteShort(number a, const coeffs r)
214{
215  gcp aa=(gcp)a;
216  coeffs1->cfWriteShort(aa->a1,coeffs1);
217}
218static const char *gRead(const char * s, number * a, const coeffs r)
219{
220  gcp cc=(gcp)omalloc(sizeof(*cc));
221  const char* ss=coeffs1->cfRead(s,&(cc->a1),coeffs1);
222  number tmp=coeffs2->cfInit(1,coeffs2);
223  mpz_ptr tt=(mpz_ptr)tmp;
224  coeffs1->cfMPZ(tt,cc->a1,coeffs1);
225  cc->a2=(number)tt;
226  *a=(number)cc;
227  return ss;
228}
229static void    gNormalize(number &a, const coeffs r)
230{
231  gcp aa=(gcp)a;
232  coeffs1->cfNormalize(aa->a1,coeffs1);
233  coeffs2->cfNormalize(aa->a2,coeffs2);
234}
235static  BOOLEAN gGreater(number a,number b, const coeffs r)
236{
237  gcp aa=(gcp)a;
238  gcp bb=(gcp)b;
239  BOOLEAN b1=coeffs1->cfGreater(aa->a1,bb->a1,coeffs1);
240  BOOLEAN b2=coeffs2->cfGreater(aa->a2,bb->a2,coeffs2);
241  if (b1!=b2)
242  {
243    printf("gGreater\n");
244  }
245  return b1;
246}
247static  BOOLEAN gEqual(number a,number b, const coeffs r)
248{
249  gcp aa=(gcp)a;
250  gcp bb=(gcp)b;
251  BOOLEAN b1=coeffs1->cfEqual(aa->a1,bb->a1,coeffs1);
252  BOOLEAN b2=coeffs2->cfEqual(aa->a2,bb->a2,coeffs2);
253  if (b1!=b2)
254  {
255    printf("gEqual\n");
256  }
257  return b1;
258}
259static  BOOLEAN gIsZero(number a, const coeffs r)
260{
261  if (a==NULL) return TRUE;
262  gcp aa=(gcp)a;
263  BOOLEAN b1=coeffs1->cfIsZero(aa->a1,coeffs1);
264  BOOLEAN b2=coeffs2->cfIsZero(aa->a2,coeffs2);
265  if (b1!=b2)
266  {
267    printf("gIsZero\n");
268  }
269  return b1;
270}
271static  BOOLEAN gIsOne(number a, const coeffs r)
272{
273  gcp aa=(gcp)a;
274  BOOLEAN b1=coeffs1->cfIsOne(aa->a1,coeffs1);
275  BOOLEAN b2=coeffs2->cfIsOne(aa->a2,coeffs2);
276  if (b1!=b2)
277  {
278    printf("gIsOne\n");
279  }
280  return b1;
281}
282static  BOOLEAN gIsMOne(number a, const coeffs r)
283{
284  gcp aa=(gcp)a;
285  BOOLEAN b1=coeffs1->cfIsMOne(aa->a1,coeffs1);
286  BOOLEAN b2=coeffs2->cfIsMOne(aa->a2,coeffs2);
287  if (b1!=b2)
288  {
289    printf("gIsMOne\n");
290  }
291  return b1;
292}
293static  BOOLEAN gGreaterZero(number a, const coeffs r)
294{
295  gcp aa=(gcp)a;
296  BOOLEAN b1=coeffs1->cfGreaterZero(aa->a1,coeffs1);
297  BOOLEAN b2=coeffs2->cfGreaterZero(aa->a2,coeffs2);
298  if (b1!=b2)
299  {
300    printf("gGreaterZero\n");
301  }
302  return b1;
303}
304static void gPower(number a, int i, number * result, const coeffs r)
305{
306  gcp aa=(gcp)a;
307  gcp cc=(gcp)omalloc(sizeof(*cc));
308  coeffs1->cfPower(aa->a1,i,&cc->a1,coeffs1);
309  coeffs2->cfPower(aa->a2,i,&cc->a2,coeffs2);
310  *result=(number)cc;
311}
312static number gGcd (number a, number b, const coeffs)
313{
314  gcp aa=(gcp)a;
315  gcp bb=(gcp)b;
316  gcp cc=(gcp)omalloc(sizeof(*cc));
317  cc->a1=coeffs1->cfGcd(aa->a1,bb->a1,coeffs1);
318  cc->a2=coeffs2->cfGcd(aa->a2,bb->a2,coeffs2);
319  return (number)cc;
320}
321static number gSubringGcd (number a, number b, const coeffs)
322{
323  gcp aa=(gcp)a;
324  gcp bb=(gcp)b;
325  gcp cc=(gcp)omalloc(sizeof(*cc));
326  cc->a1=coeffs1->cfSubringGcd(aa->a1,bb->a1,coeffs1);
327  cc->a2=coeffs2->cfSubringGcd(aa->a2,bb->a2,coeffs2);
328  return (number)cc;
329}
330static number gGetDenom (number &a, const coeffs)
331{
332  gcp aa=(gcp)a;
333  gcp cc=(gcp)omalloc(sizeof(*cc));
334  cc->a1=coeffs1->cfGetDenom(aa->a1,coeffs1);
335  cc->a2=coeffs2->cfGetDenom(aa->a2,coeffs2);
336  return (number)cc;
337}
338static number gGetNumerator (number &a, const coeffs)
339{
340  gcp aa=(gcp)a;
341  gcp cc=(gcp)omalloc(sizeof(*cc));
342  cc->a1=coeffs1->cfGetNumerator(aa->a1,coeffs1);
343  cc->a2=coeffs2->cfGetNumerator(aa->a2,coeffs2);
344  return (number)cc;
345}
346static number  gQuotRem(number a, number b, number *rem, const coeffs r)
347{
348 printf("gQuotRem\n");
349 return NULL;
350}
351static number  gLcm(number a, number b, const coeffs r)
352{
353  gcp aa=(gcp)a;
354  gcp bb=(gcp)b;
355  gcp cc=(gcp)omalloc(sizeof(*cc));
356  cc->a1=coeffs1->cfLcm(aa->a1,bb->a1,coeffs1);
357  cc->a2=coeffs2->cfLcm(aa->a2,bb->a2,coeffs2);
358  return (number)cc;
359}
360static number  gNormalizeHelper(number a, number b, const coeffs r)
361{
362  gcp aa=(gcp)a;
363  gcp bb=(gcp)b;
364  gcp cc=(gcp)omalloc(sizeof(*cc));
365  cc->a1=coeffs1->cfNormalizeHelper(aa->a1,bb->a1,coeffs1);
366  cc->a2=coeffs2->cfNormalizeHelper(aa->a2,bb->a2,coeffs2);
367  return (number)cc;
368}
369static void  gDelete(number * a, const coeffs r)
370{
371  if (*a!=NULL)
372  {
373    gcp aa=(gcp)*a;
374    coeffs1->cfDelete(&aa->a1,coeffs1);
375    coeffs2->cfDelete(&aa->a2,coeffs2);
376    omFree(aa);
377    *a=NULL;
378  }
379}
380static nMapFunc gSetMap(const coeffs src, const coeffs dst)
381{
382  printf("gSetMap\n");
383  return NULL;
384}
385static void gWriteFd(number a, FILE *f, const coeffs r)
386{
387  printf("gWriteFd\n");
388}
389static number gReadFd( s_buff f, const coeffs r)
390{
391  printf("gReadFd\n");
392  return NULL;
393}
394static number  gFarey(number p, number n, const coeffs)
395{
396  gcp aa=(gcp)p;
397  gcp cc=(gcp)omalloc(sizeof(*cc));
398  cc->a1=coeffs1->cfFarey(aa->a1,n,coeffs1);
399  cc->a2=coeffs2->cfFarey(aa->a2,n,coeffs2);
400  return (number)cc;
401}
402static number gChineseRemainder(number *x, number *q,int rl, BOOLEAN sym,CFArray &inv_cache,const coeffs)
403{
404  printf("gChineseREmainder\n");
405  return NULL;
406}
407static  number gRandom(siRandProc p, number p1, number p2, const coeffs cf)
408{
409  printf("gRandom\n");
410  return NULL;
411}
412static BOOLEAN gDivBy (number a,number b, const coeffs)
413{
414  gcp aa=(gcp)a;
415  gcp bb=(gcp)b;
416  BOOLEAN b1=coeffs1->cfDivBy(aa->a1,bb->a1,coeffs1);
417  BOOLEAN b2=coeffs2->cfDivBy(aa->a2,bb->a2,coeffs2);
418  if (b1!=b2)
419  {
420    printf("gDivBy:%d,%d\n",b1,b2);
421  }
422  return b1;
423}
424static number  gExtGcd (number a, number b, number *s, number *t, const coeffs)
425{
426  gcp aa=(gcp)a;
427  gcp bb=(gcp)b;
428  gcp cc=(gcp)omalloc(sizeof(*cc));
429  gcp ss=(gcp)omalloc(sizeof(*ss));
430  gcp tt=(gcp)omalloc(sizeof(*ss));
431  cc->a1=coeffs1->cfExtGcd(aa->a1,bb->a1,&ss->a1,&tt->a1,coeffs1);
432  cc->a2=coeffs2->cfExtGcd(aa->a2,bb->a2,&ss->a2,&tt->a2,coeffs2);
433  return (number)cc;
434}
435static number  gGetUnit (number n, const coeffs r)
436{
437  gcp aa=(gcp)n;
438  gcp cc=(gcp)omalloc(sizeof(*cc));
439  cc->a1=coeffs1->cfGetUnit(aa->a1,coeffs1);
440  cc->a2=coeffs2->cfGetUnit(aa->a2,coeffs2);
441  return (number)cc;
442}
443static BOOLEAN gIsUnit (number a, const coeffs)
444{
445  gcp aa=(gcp)a;
446  BOOLEAN b1=coeffs1->cfIsUnit(aa->a1,coeffs1);
447  BOOLEAN b2=coeffs2->cfIsUnit(aa->a2,coeffs2);
448  if (b1!=b2)
449  {
450    printf("gIsUnit:%d,%d\n",b1,b2);
451  }
452  return b1;
453}
454static int gDivComp(number a, number b, const coeffs r)
455{
456  gcp aa=(gcp)a;
457  gcp bb=(gcp)b;
458  int i1=coeffs1->cfDivComp(aa->a1,bb->a1,coeffs1);
459  int i2=coeffs2->cfDivComp(aa->a2,bb->a2,coeffs2);
460  if (i1!=i2)
461  {
462    printf("gDivComp:%d,%d\n",i1,i2);
463  }
464  return i1;
465}
466static BOOLEAN gDBTest(number a, const char *f, const int l, const coeffs r)
467{
468 if (a==NULL)
469   printf("NULL in %s:%d\n",f,l);
470 return TRUE;
471}
472BOOLEAN gInitChar(coeffs r, void* p)
473{
474  coeffs1=nInitChar(n_Z_1,(void*)1);
475  coeffs2=nInitChar(n_Z_2,(void*)1);
476  r->is_field=FALSE;
477  r->is_domain=TRUE;
478  r->rep=n_rep_unknown;
479  r->ch = 0;
480  r->cfKillChar=gKillChar;
481  //r->nCoeffIsEqual=gCoeffsEqual;
482  r->cfCoeffString=gCoeffString;
483  r->cfCoeffName=gCoeffName;
484  r->cfCoeffWrite=gCoeffWrite;
485
486  r->cfMult  = gMult;
487  r->cfSub   = gSub;
488  r->cfAdd   = gAdd;
489  r->cfDiv   = gDiv;
490  r->cfInit = gInit;
491  r->cfSize  = gSize;
492  r->cfInt  = gInt;
493  #ifdef HAVE_RINGS
494  r->cfDivComp = gDivComp;
495  r->cfIsUnit = gIsUnit;
496  r->cfGetUnit = gGetUnit;
497  r->cfExtGcd = gExtGcd;
498   r->cfDivBy = gDivBy;
499  #endif
500  r->cfInpNeg   = gInpNeg;
501  r->cfInvers= gInvers;
502  r->cfCopy  = gCopy;
503  r->cfRePart = gCopy;
504  //r->cfImPart = ndReturn0;
505  r->cfWriteLong = gWriteLong;
506  r->cfWriteShort = gWriteShort;
507  r->cfRead = gRead;
508  r->cfNormalize=gNormalize;
509  r->cfGreater = gGreater;
510  r->cfEqual = gEqual;
511  r->cfIsZero = gIsZero;
512  r->cfIsOne = gIsOne;
513  r->cfIsMOne = gIsMOne;
514  r->cfGreaterZero = gGreaterZero;
515  r->cfPower = gPower;
516  r->cfGetDenom = gGetDenom;
517  r->cfGetNumerator = gGetNumerator;
518  r->cfGcd  = gGcd;
519  r->cfLcm  = gGcd;
520  r->cfDelete= gDelete;
521  r->cfSetMap = gSetMap;
522  //r->cfInpMult=ndInpMult;
523  r->cfRandom=gRandom;
524  r->cfWriteFd=gWriteFd;
525  r->cfReadFd=gReadFd;
526  r->type=n_Z;
527  #ifdef LDEBUG
528  r->cfDBTest=gDBTest;
529  #endif
530  return FALSE;
531}
532
Note: See TracBrowser for help on using the repository browser.