My Project
Loading...
Searching...
No Matches
flintcf_Q.cc
Go to the documentation of this file.
1/****************************************
2* Computer Algebra System SINGULAR *
3****************************************/
4/*
5* ABSTRACT: flint: fmpq_poly
6*/
7#include <ctype.h> /* isdigit*/
8
9#include "misc/auxiliary.h"
10
11#ifdef HAVE_FLINT
12
13#include <gmp.h>
14#include <flint/flint.h>
15#include <flint/fmpz.h>
16#include <flint/fmpq.h>
17#include <flint/fmpq_poly.h>
18#include "factory/factory.h"
19
20#include "coeffs/coeffs.h"
21
22#include "coeffs/numbers.h"
23#include "coeffs/longrat.h"
24
25typedef fmpq_poly_struct *fmpq_poly_ptr;
26typedef fmpz *fmpz_ptr;
27/*2
28* extracts a long integer from s, returns the rest
29*/
30static char * nlEatLong(char *s, mpz_ptr i)
31{
32 const char * start=s;
33
34 while (*s >= '0' && *s <= '9') s++;
35 if (*s=='\0')
36 {
37 mpz_set_str(i,start,10);
38 }
39 else
40 {
41 char c=*s;
42 *s='\0';
43 mpz_set_str(i,start,10);
44 *s=c;
45 }
46 return s;
47}
48
49static BOOLEAN CoeffIsEqual(const coeffs r, n_coeffType n, void *)
50{
51 return (r->type==n);
52}
53static void SetChar(const coeffs)
54{
55 // dummy
56}
57static number Mult(number a, number b, const coeffs)
58{
59 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
60 fmpq_poly_init(res);
61 fmpq_poly_mul(res,(fmpq_poly_ptr)a,(fmpq_poly_ptr)b);
62 return (number)res;
63}
64static number Sub(number a, number b, const coeffs)
65{
66 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
67 fmpq_poly_init(res);
68 fmpq_poly_sub(res,(fmpq_poly_ptr)a,(fmpq_poly_ptr)b);
69 return (number)res;
70}
71static number Add(number a, number b, const coeffs)
72{
73 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
74 fmpq_poly_init(res);
75 fmpq_poly_add(res,(fmpq_poly_ptr)a,(fmpq_poly_ptr)b);
76 return (number)res;
77}
78static number Div(number a, number b, const coeffs)
79{
80 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
81 fmpq_poly_init(res);
82 if(fmpq_poly_is_zero((fmpq_poly_ptr)b))
83 {
85 }
86 else
87 {
88 fmpq_poly_div(res,(fmpq_poly_ptr)a,(fmpq_poly_ptr)b);
89 fmpq_poly_t mod;
90 fmpq_poly_init(mod);
91 fmpq_poly_rem(mod,(fmpq_poly_ptr)a,(fmpq_poly_ptr)b);
92 if (!fmpq_poly_is_zero((fmpq_poly_ptr)mod))
93 {
94 WerrorS("cannot divide");
95 }
96 fmpq_poly_clear(mod);
97 }
98 return (number)res;
99}
100static number ExactDiv(number a, number b, const coeffs)
101{
102 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
103 fmpq_poly_init(res);
104 if(fmpq_poly_is_zero((fmpq_poly_ptr)b))
105 {
107 }
108 else
109 fmpq_poly_div(res,(fmpq_poly_ptr)a,(fmpq_poly_ptr)b);
110 return (number)res;
111}
112#if 0
113static number IntMod(number a, number b, const coeffs)
114{
115 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
116 fmpq_poly_init(res);
117 fmpq_poly_rem(res,(fmpq_poly_ptr)a,(fmpq_poly_ptr)b);
118 return (number)res;
119}
120#endif
121static number Init (long i, const coeffs)
122{
123 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
124 fmpq_poly_init(res);
125 fmpq_poly_set_si(res,i);
126 return (number)res;
127}
128static number InitMPZ (mpz_t i, const coeffs)
129{
130 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
131 fmpq_poly_init(res);
132 fmpq_poly_fit_length(res, 1);
133 fmpz_set_mpz(res->coeffs, i);
134 fmpz_one(res->den);
135 _fmpq_poly_set_length(res, 1);
136 _fmpq_poly_normalise(res);
137 return (number)res;
138}
139static int Size (number n, const coeffs)
140{
141 return fmpq_poly_degree((fmpq_poly_ptr)n);
142}
143static long Int (number &n, const coeffs)
144{
145 if (fmpq_poly_degree((fmpq_poly_ptr)n)==0)
146 {
147 fmpq_t m;
148 fmpq_init(m);
149 fmpq_poly_get_coeff_fmpq(m,(fmpq_poly_ptr)n,0);
150 long nl=fmpz_get_si(fmpq_numref(m));
151 if (fmpz_cmp_si(fmpq_numref(m),nl)!=0) nl=0;
152 long dl=fmpz_get_si(fmpq_denref(m));
153 if ((dl!=1)||(fmpz_cmp_si(fmpq_denref(m),dl)!=0)) nl=0;
154 fmpq_clear(m);
155 return nl;
156 }
157 return 0;
158}
159static void MPZ(mpz_t result, number &n, const coeffs)
160{
161 mpz_init(result);
162 if (fmpq_poly_degree((fmpq_poly_ptr)n)==0)
163 {
164#if __FLINT_RELEASE >= 20503
165 fmpq_t m;
166 fmpq_init(m);
167 fmpq_poly_get_coeff_fmpq(m,(fmpq_poly_ptr)n,0);
168 mpz_t den;
169 mpz_init(den);
170 fmpq_get_mpz_frac(result,den,m);
171 int dl=(int)mpz_get_si(den);
172 if ((dl!=1)||(mpz_cmp_si(den,(long)dl)!=0)) mpz_set_ui(result,0);
173 mpz_clear(den);
174 fmpq_clear(m);
175#else
176 mpq_t m;
177 mpq_init(m);
178 fmpq_poly_get_coeff_mpq(m,(fmpq_poly_ptr)n,0);
179 mpz_t den;
180 mpz_init(den);
181 mpq_get_num(result,m);
182 mpq_get_den(den,m);
183 int dl=(int)mpz_get_si(den);
184 if ((dl!=1)||(mpz_cmp_si(den,(long)dl)!=0)) mpz_set_ui(result,0);
185 mpz_clear(den);
186 mpq_clear(m);
187#endif
188 }
189}
190static number Neg(number a, const coeffs)
191{
192 fmpq_poly_neg((fmpq_poly_ptr)a,(fmpq_poly_ptr)a);
193 return a;
194}
195static number Invers(number a, const coeffs)
196{
197 if(fmpq_poly_is_zero((fmpq_poly_ptr)a))
198 {
200 return NULL;
201 }
202 if (fmpq_poly_degree((fmpq_poly_ptr)a)==0)
203 {
204 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
205 fmpq_poly_init(res);
206 fmpq_poly_inv(res,(fmpq_poly_ptr)a);
207 return (number)res;
208 }
209 else
210 {
211 WerrorS("not invertable");
212 return NULL;
213 }
214}
215static number Copy(number a, const coeffs)
216{
217 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
218 fmpq_poly_init(res);
219 fmpq_poly_set(res,(fmpq_poly_ptr)a);
220 return (number)res;
221}
222//static number RePart(number a, const coeffs)
223//{
224//}
225//static number ImPart(number a, const coeffs)
226//{
227//}
228static BOOLEAN IsOne (number a, const coeffs);
229static BOOLEAN IsZero (number a, const coeffs);
230//static void WriteLong(number &a, const coeffs)
231//{
232//}
233static void WriteShort(number a, const coeffs r)
234{
235 //fmpq_poly_print_pretty((fmpq_poly_ptr)a,r->pParameterNames[0]);
236 if (IsOne(a,r)) StringAppendS("1");
237 else if (IsZero(a,r)) StringAppendS("0");
238 else
239 {
240 StringAppendS("(");
241#if __FLINT_RELEASE >= 20503
242 fmpq_t m;
243 fmpq_init(m);
244 BOOLEAN need_plus=FALSE;
245 for(int i=fmpq_poly_length((fmpq_poly_ptr)a);i>=0;i--)
246 {
247 fmpq_poly_get_coeff_fmpq(m,(fmpq_poly_ptr)a,i);
248 if (!fmpq_is_zero(m))
249 {
250 if (need_plus && (fmpq_cmp_ui(m,0)>0))
251 StringAppendS("+");
252 need_plus=TRUE;
253 int l=fmpz_sizeinbase(fmpq_numref(m),10);
254 l=si_max(l,(int)fmpz_sizeinbase(fmpq_denref(m),10));
255 l+=2;
256 char *s=(char*)omAlloc(l);
257 char *z=fmpz_get_str(s,10,fmpq_numref(m));
258 if ((i==0)
259 ||(fmpz_cmp_si(fmpq_numref(m),1)!=0)
260 ||(fmpz_cmp_si(fmpq_denref(m),1)!=0))
261 {
262 StringAppendS(z);
263 if (fmpz_cmp_si(fmpq_denref(m),1)!=0)
264 {
265 StringAppendS("/");
266 z=fmpz_get_str(s,10,fmpq_denref(m));
267 StringAppendS(z);
268 }
269 if (i!=0) StringAppendS("*");
270 }
271 if (i>1)
272 StringAppend("%s^%d",r->pParameterNames[0],i);
273 else if (i==1)
274 StringAppend("%s",r->pParameterNames[0]);
275 }
276 }
277 fmpq_clear(m);
278#else
279 mpq_t m;
280 mpq_init(m);
281 mpz_t num,den;
282 mpz_init(num);
283 mpz_init(den);
284 BOOLEAN need_plus=FALSE;
285 for(int i=fmpq_poly_length((fmpq_poly_ptr)a);i>=0;i--)
286 {
287 fmpq_poly_get_coeff_mpq(m,(fmpq_poly_ptr)a,i);
288 mpq_get_num(num,m);
289 mpq_get_den(den,m);
290 if (mpz_sgn1(num)!=0)
291 {
292 if (need_plus && (mpz_sgn1(num)>0))
293 StringAppendS("+");
294 need_plus=TRUE;
295 int l=mpz_sizeinbase(num,10);
296 l=si_max(l,(int)mpz_sizeinbase(den,10));
297 l+=2;
298 char *s=(char*)omAlloc(l);
299 char *z=mpz_get_str(s,10,num);
300 if ((i==0)
301 ||(mpz_cmp_si(num,1)!=0)
302 ||(mpz_cmp_si(den,1)!=0))
303 {
304 StringAppendS(z);
305 if (mpz_cmp_si(den,1)!=0)
306 {
307 StringAppendS("/");
308 z=mpz_get_str(s,10,den);
309 StringAppendS(z);
310 }
311 if (i!=0) StringAppendS("*");
312 }
313 if (i>1)
314 StringAppend("%s^%d",r->pParameterNames[0],i);
315 else if (i==1)
316 StringAppend("%s",r->pParameterNames[0]);
317 }
318 }
319 mpz_clear(den);
320 mpz_clear(num);
321 mpq_clear(m);
322#endif
323 StringAppendS(")");
324 }
325}
326static const char* Read(const char * st, number * a, const coeffs r)
327{
328// we only read "monomials" (i.e. [-][digits][parameter]),
329// everything else (+,*,^,()) is left to the singular interpreter
330 char *s=(char *)st;
331 *a=(number)omAlloc(sizeof(fmpq_poly_t));
332 fmpq_poly_init((fmpq_poly_ptr)(*a));
333 BOOLEAN neg=FALSE;
334 if (*s=='-') { neg=TRUE; s++;}
335 if (isdigit(*s))
336 {
337 mpz_t z;
338 mpz_init(z);
339 fmpz_t z1;
340 fmpz_init(z1);
341 s=nlEatLong((char *)s, z);
342 fmpz_set_mpz(z1,z);
343 fmpq_poly_set_fmpz((fmpq_poly_ptr)(*a),z1);
344 if (*s == '/')
345 {
346 s++;
347 s=nlEatLong((char *)s, z);
348 fmpz_set_mpz(z1,z);
349 fmpq_poly_scalar_div_fmpz((fmpq_poly_ptr)(*a),(fmpq_poly_ptr)(*a),z1);
350 }
351 fmpz_clear(z1);
352 mpz_clear(z);
353 }
354 else if(strncmp(s,r->pParameterNames[0],strlen(r->pParameterNames[0]))==0)
355 {
356 fmpq_poly_set_coeff_si((fmpq_poly_ptr)(*a),1,1);
357 s+=strlen(r->pParameterNames[0]);
358 if(isdigit(*s))
359 {
360 int i=1;
361 s=nEati(s,&i,0);
362 if (i!=1)
363 {
364 fmpq_poly_set_coeff_si((fmpq_poly_ptr)(*a),1,0);
365 fmpq_poly_set_coeff_si((fmpq_poly_ptr)(*a),i,1);
366 }
367 }
368 }
369 if (neg)
370 fmpq_poly_neg((fmpq_poly_ptr)(*a),(fmpq_poly_ptr)(*a));
371 return s;
372}
373static void Normalize(number &a, const coeffs)
374{
375 fmpq_poly_canonicalise((fmpq_poly_ptr)a);
376}
377static BOOLEAN Greater (number a, number b, const coeffs)
378{
379 return (fmpq_poly_cmp((fmpq_poly_ptr)a,(fmpq_poly_ptr)b)>0);
380}
381static BOOLEAN Equal (number a, number b, const coeffs)
382{
383 return (fmpq_poly_equal((fmpq_poly_ptr)a,(fmpq_poly_ptr)b));
384}
385static BOOLEAN IsZero (number a, const coeffs)
386{
387 return fmpq_poly_is_zero((fmpq_poly_ptr)a);
388}
389static BOOLEAN IsOne (number a, const coeffs)
390{
391 return fmpq_poly_is_one((fmpq_poly_ptr)a);
392}
393static BOOLEAN IsMOne (number k, const coeffs)
394{
395 if (fmpq_poly_length((fmpq_poly_ptr)k)>0) return FALSE;
396 fmpq_poly_canonicalise((fmpq_poly_ptr)k);
397 fmpq_t m;
398 fmpq_init(m);
399 fmpq_poly_get_coeff_fmpq(m,(fmpq_poly_ptr)k,0);
401 if (fmpz_cmp_si(fmpq_numref(m),(long)-1)!=0) result=FALSE;
402 else
403 {
404 int dl=(int)fmpz_get_si(fmpq_denref(m));
405 if ((dl!=1)||(fmpz_cmp_si(fmpq_denref(m),(long)dl)!=0)) result=FALSE;
406 }
407 fmpq_clear(m);
408 return (result);
409}
410static BOOLEAN GreaterZero (number, const coeffs)
411{
412 // does it have a leading sign?
413 // no: 0 and 1 do not have, everything else is in (...)
414 return TRUE;
415}
416static void Power(number a, int i, number * result, const coeffs)
417{
418 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
419 fmpq_poly_init(res);
420 *result=(number)res;
421 fmpq_poly_pow((fmpq_poly_ptr)(*result),(fmpq_poly_ptr)a,i);
422}
423static number GetDenom(number &n, const coeffs)
424{
425 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
426 fmpq_poly_init(res);
427 fmpz_ptr den=fmpq_poly_denref((fmpq_poly_ptr)n);
428 fmpq_poly_set_fmpz(res,den);
429 return (number)res;
430}
431static number GetNumerator(number &n, const coeffs)
432{
433 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
434 fmpq_poly_init(res);
435 fmpq_poly_set(res,(fmpq_poly_ptr)n);
436 fmpz_ptr den=fmpq_poly_denref(res);
437 fmpq_poly_scalar_mul_fmpz(res,res,den);
438 return (number)res;
439}
440static number Gcd(number a, number b, const coeffs)
441{
442 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
443 fmpq_poly_init(res);
444 fmpq_poly_gcd(res,(fmpq_poly_ptr)a,(fmpq_poly_ptr)b);
445 return (number)res;
446}
447static number ExtGcd(number a, number b, number *s, number *t,const coeffs)
448{
449 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
450 fmpq_poly_init(res);
451 fmpq_poly_init((fmpq_poly_ptr)*s);
452 fmpq_poly_init((fmpq_poly_ptr)*t);
453 fmpq_poly_xgcd(res,(fmpq_poly_ptr)*s,(fmpq_poly_ptr)*t,(fmpq_poly_ptr)a,(fmpq_poly_ptr)b);
454 return (number)res;
455}
456static number Lcm(number, number, const coeffs)
457{
458 WerrorS("not yet: Lcm");
459 return NULL;
460}
461static void Delete(number * a, const coeffs)
462{
463 if ((*a)!=NULL)
464 {
465 fmpq_poly_clear((fmpq_poly_ptr)*a);
466 omFree(*a);
467 *a=NULL;
468 }
469}
470static nMapFunc SetMap(const coeffs, const coeffs)
471{
472 WerrorS("not yet: SetMap");
473 return NULL;
474}
475//static void InpMult(number &a, number b, const coeffs)
476//{
477//}
478//static void InpAdd(number &a, number b, const coeffs)
479//{
480//}
481#if 0
482static number Init_bigint(number i, const coeffs, const coeffs)
483{
484 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
485 fmpq_poly_init(res);
486 if (SR_HDL(i) & SR_INT)
487 {
488 fmpq_poly_set_si(res,SR_TO_INT(i));
489 }
490 else
491 fmpq_poly_set_mpz(res,i->z);
492 return (number)res;
493}
494#endif
495static number Farey(number, number, const coeffs)
496{
497 WerrorS("not yet: Farey");
498 return NULL;
499}
500static number ChineseRemainder(number *, number *,int , BOOLEAN ,CFArray &,const coeffs)
501{
502 WerrorS("not yet: ChineseRemainder");
503 return NULL;
504}
505static int ParDeg(number x,const coeffs)
506{
507 return fmpq_poly_degree((fmpq_poly_ptr)x);
508}
509static number Parameter(const int, const coeffs)
510{
511 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
512 fmpq_poly_init(res);
513 fmpq_poly_set_coeff_si(res,1,1);
514 return (number)res;
515}
516static void WriteFd(number a, const ssiInfo *d, const coeffs)
517{
518 // format: len a_len(num den) .. a_0
520 int l=fmpq_poly_length(aa);
521 fprintf(d->f_write,"%d ",l);
522#if __FLINT_RELEASE >= 20503
523 fmpq_t m;
524 fmpq_init(m);
525 mpz_t num,den;
526 mpz_init(num);
527 mpz_init(den);
528 for(int i=l; i>=0; i--)
529 {
530 fmpq_poly_get_coeff_fmpq(m,(fmpq_poly_ptr)a,i);
531 fmpq_get_mpz_frac(num,den,m);
532 mpz_out_str (d->f_write,SSI_BASE, num);
533 fputc(' ',d->f_write);
534 mpz_out_str (d->f_write,SSI_BASE, den);
535 fputc(' ',d->f_write);
536 }
537 mpz_clear(den);
538 mpz_clear(num);
539 fmpq_clear(m);
540#else
541 mpq_t m;
542 mpq_init(m);
543 mpz_t num,den;
544 mpz_init(num);
545 mpz_init(den);
546 for(int i=l; i>=0; i--)
547 {
548 fmpq_poly_get_coeff_mpq(m,(fmpq_poly_ptr)a,i);
549 mpq_get_num(num,m);
550 mpq_get_den(den,m);
551 mpz_out_str (d->f_write,SSI_BASE, num);
552 fputc(' ',d->f_write);
553 mpz_out_str (d->f_write,SSI_BASE, den);
554 fputc(' ',d->f_write);
555 }
556 mpz_clear(den);
557 mpz_clear(num);
558 mpq_clear(m);
559#endif
560}
561static number ReadFd(const ssiInfo *d, const coeffs)
562{
563 // format: len a_len .. a_0
564 fmpq_poly_ptr aa=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
565 fmpq_poly_init(aa);
566 int l=s_readint(d->f_read);
567 mpz_t tmp;
568 mpz_init(tmp);
569 fmpq_t m;
570 fmpq_init(m);
571 fmpz_t num,den;
572 fmpz_init(num);
573 fmpz_init(den);
574 for (int i=l;i>=0;i--)
575 {
577 fmpz_set_mpz(num, tmp);
579 fmpz_set_mpz(den, tmp);
580 fmpq_set_fmpz_frac(m,num,den);
581 fmpq_poly_set_coeff_fmpq(aa,i,m);
582 }
583 mpz_clear(tmp);
584 fmpz_clear(den);
585 fmpz_clear(num);
586 fmpq_clear(m);
587 return (number)aa;
588}
589// cfClearContent
590// cfClearDenominators
591static number ConvFactoryNSingN( const CanonicalForm, const coeffs)
592{
593 WerrorS("not yet: ConvFactoryNSingN");
594 return NULL;
595}
597{
598 WerrorS("not yet: ConvSingNFactoryN");
599 return CanonicalForm(0);
600}
601char * CoeffName(const coeffs r)
602{
603 STATIC_VAR char CoeffName_flint_Q[20];
604 sprintf(CoeffName_flint_Q,"flintQp[%s]",r->pParameterNames[0]);
605 return (char*)CoeffName_flint_Q;
606
607}
609{
610 const char start[]="flintQp[";
611 const int start_len=strlen(start);
612 if (strncmp(s,start,start_len)==0)
613 {
614 s+=start_len;
615 char st[10];
616 int l=sscanf(s,"%s",st);
617 if (l==1)
618 {
619 while (st[strlen(st)-1]==']') st[strlen(st)-1]='\0';
620 return nInitChar(n,(void*)st);
621 }
622 }
623 return NULL;
624}
625#ifdef LDEBUG
626static BOOLEAN DBTest(number, const char *, const int, const coeffs)
627{
628 return TRUE;
629}
630#endif
631static void KillChar(coeffs cf)
632{
633 omFree((ADDRESS)(cf->pParameterNames[0]));
634 omFreeSize(cf->pParameterNames,sizeof(char*));
635}
636BOOLEAN flintQ_InitChar(coeffs cf, void * infoStruct)
637{
638 char *pp=(char*)infoStruct;
639 cf->cfCoeffName = CoeffName;
640 cf->nCoeffIsEqual = CoeffIsEqual;
641 cf->cfKillChar = KillChar;
642 cf->cfSetChar = SetChar;
643 cf->ch=0; //char 0
644 cf->cfMult = Mult;
645 cf->cfSub = Sub;
646 cf->cfAdd = Add;
647 cf->cfDiv = Div;
648 cf->cfExactDiv = ExactDiv; // ???
649 cf->cfInit =Init;
650 cf->cfInitMPZ =InitMPZ;
651 cf->cfSize = Size;
652 cf->cfInt = Int;
653 cf->cfMPZ = MPZ;
654 cf->cfInpNeg = Neg;
655 cf->cfInvers = Invers;
656 cf->cfCopy = Copy;
657 cf->cfRePart = Copy;
658 // default: cf->cfImPart = ndReturn0;
659 cf->cfWriteLong = WriteShort; //WriteLong;
660 cf->cfWriteShort = WriteShort;
661 cf->cfRead = Read;
662 cf->cfNormalize = Normalize;
663
664 //cf->cfDivComp=
665 //cf->cfIsUnit=
666 //cf->cfGetUnit=
667 //cf->cfDivBy=
668
669 cf->cfGreater=Greater;
670 cf->cfEqual =Equal;
671 cf->cfIsZero =IsZero;
672 cf->cfIsOne =IsOne;
673 cf->cfIsMOne =IsMOne;
674 cf->cfGreaterZero=GreaterZero;
675
676 cf->cfPower = Power;
677 cf->cfGetDenom = GetDenom;
678 cf->cfGetNumerator = GetNumerator;
679 cf->cfGcd = Gcd;
680 cf->cfExtGcd = ExtGcd;
681 cf->cfLcm = Lcm;
682 cf->cfDelete = Delete;
683 cf->cfSetMap = SetMap;
684 // default: cf->cfInpMult
685 // default: cf->cfInpAdd
686 cf->cfFarey =Farey;
687 cf->cfChineseRemainder=ChineseRemainder;
688 cf->cfParDeg = ParDeg;
689 cf->cfParameter = Parameter;
690 // cf->cfClearContent = ClearContent;
691 // cf->cfClearDenominators = ClearDenominators;
692 cf->convFactoryNSingN=ConvFactoryNSingN;
693 cf->convSingNFactoryN=ConvSingNFactoryN;
694 cf->cfWriteFd = WriteFd;
695 cf->cfReadFd = ReadFd;
696#ifdef LDEBUG
697 cf->cfDBTest = DBTest;
698#endif
699
700 cf->iNumberOfParameters = 1;
701 char **pn=(char**)omAlloc0(sizeof(char*));
702 pn[0]=omStrDup(pp);
703 cf->pParameterNames = (const char **)pn;
704 cf->has_simple_Inverse= FALSE;
705 cf->has_simple_Alloc= FALSE;
706 cf->is_field=FALSE;
707
708 return FALSE;
709}
710#endif
All the auxiliary stuff.
#define SSI_BASE
Definition auxiliary.h:136
static int si_max(const int a, const int b)
Definition auxiliary.h:125
int BOOLEAN
Definition auxiliary.h:88
#define TRUE
Definition auxiliary.h:101
#define FALSE
Definition auxiliary.h:97
void * ADDRESS
Definition auxiliary.h:120
CF_NO_INLINE FACTORY_PUBLIC CanonicalForm mod(const CanonicalForm &, const CanonicalForm &)
CanonicalForm FACTORY_PUBLIC pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition cf_gcd.cc:676
Array< CanonicalForm > CFArray
CanonicalForm num(const CanonicalForm &f)
CanonicalForm den(const CanonicalForm &f)
int l
Definition cfEzgcd.cc:100
int m
Definition cfEzgcd.cc:128
int i
Definition cfEzgcd.cc:132
int k
Definition cfEzgcd.cc:99
Variable x
Definition cfModGcd.cc:4090
CanonicalForm cf
Definition cfModGcd.cc:4091
CanonicalForm b
Definition cfModGcd.cc:4111
factory's main class
Coefficient rings, fields and other domains suitable for Singular polynomials.
n_coeffType
Definition coeffs.h:27
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition numbers.cc:406
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition coeffs.h:80
#define StringAppend
Definition emacs.cc:79
return result
const CanonicalForm int s
Definition facAbsFact.cc:51
CanonicalForm res
Definition facAbsFact.cc:60
‘factory.h’ is the user interface to Factory.
void WerrorS(const char *s)
Definition feFopen.cc:24
static number ExtGcd(number a, number b, number *s, number *t, const coeffs)
Definition flintcf_Q.cc:447
static void WriteShort(number a, const coeffs r)
Definition flintcf_Q.cc:233
static number Copy(number a, const coeffs)
Definition flintcf_Q.cc:215
static number ChineseRemainder(number *, number *, int, BOOLEAN, CFArray &, const coeffs)
Definition flintcf_Q.cc:500
static void Normalize(number &a, const coeffs)
Definition flintcf_Q.cc:373
static void SetChar(const coeffs)
Definition flintcf_Q.cc:53
static nMapFunc SetMap(const coeffs, const coeffs)
Definition flintcf_Q.cc:470
static number Farey(number, number, const coeffs)
Definition flintcf_Q.cc:495
static number GetDenom(number &n, const coeffs)
Definition flintcf_Q.cc:423
static const char * Read(const char *st, number *a, const coeffs r)
Definition flintcf_Q.cc:326
static BOOLEAN IsOne(number a, const coeffs)
Definition flintcf_Q.cc:389
char * CoeffName(const coeffs r)
Definition flintcf_Q.cc:601
static number ConvFactoryNSingN(const CanonicalForm, const coeffs)
Definition flintcf_Q.cc:591
BOOLEAN flintQ_InitChar(coeffs cf, void *infoStruct)
Definition flintcf_Q.cc:636
fmpq_poly_struct * fmpq_poly_ptr
Definition flintcf_Q.cc:25
static number InitMPZ(mpz_t i, const coeffs)
Definition flintcf_Q.cc:128
static int Size(number n, const coeffs)
Definition flintcf_Q.cc:139
static number Add(number a, number b, const coeffs)
Definition flintcf_Q.cc:71
static number Div(number a, number b, const coeffs)
Definition flintcf_Q.cc:78
static void WriteFd(number a, const ssiInfo *d, const coeffs)
Definition flintcf_Q.cc:516
fmpz * fmpz_ptr
Definition flintcf_Q.cc:26
coeffs flintQInitCfByName(char *s, n_coeffType n)
Definition flintcf_Q.cc:608
static void Delete(number *a, const coeffs)
Definition flintcf_Q.cc:461
static number Parameter(const int, const coeffs)
Definition flintcf_Q.cc:509
static BOOLEAN DBTest(number, const char *, const int, const coeffs)
Definition flintcf_Q.cc:626
static void KillChar(coeffs cf)
Definition flintcf_Q.cc:631
static CanonicalForm ConvSingNFactoryN(number, BOOLEAN, const coeffs)
Definition flintcf_Q.cc:596
static number Init(long i, const coeffs)
Definition flintcf_Q.cc:121
static void MPZ(mpz_t result, number &n, const coeffs)
Definition flintcf_Q.cc:159
static number ReadFd(const ssiInfo *d, const coeffs)
Definition flintcf_Q.cc:561
static number ExactDiv(number a, number b, const coeffs)
Definition flintcf_Q.cc:100
static void Power(number a, int i, number *result, const coeffs)
Definition flintcf_Q.cc:416
static BOOLEAN IsMOne(number k, const coeffs)
Definition flintcf_Q.cc:393
static number Sub(number a, number b, const coeffs)
Definition flintcf_Q.cc:64
static number GetNumerator(number &n, const coeffs)
Definition flintcf_Q.cc:431
static BOOLEAN GreaterZero(number, const coeffs)
Definition flintcf_Q.cc:410
static number Gcd(number a, number b, const coeffs)
Definition flintcf_Q.cc:440
static BOOLEAN CoeffIsEqual(const coeffs r, n_coeffType n, void *)
Definition flintcf_Q.cc:49
static number Mult(number a, number b, const coeffs)
Definition flintcf_Q.cc:57
static number Invers(number a, const coeffs)
Definition flintcf_Q.cc:195
static number Lcm(number, number, const coeffs)
Definition flintcf_Q.cc:456
static int ParDeg(number x, const coeffs)
Definition flintcf_Q.cc:505
static BOOLEAN IsZero(number a, const coeffs)
Definition flintcf_Q.cc:385
static number Neg(number a, const coeffs)
Definition flintcf_Q.cc:190
static BOOLEAN Equal(number a, number b, const coeffs)
Definition flintcf_Q.cc:381
static BOOLEAN Greater(number a, number b, const coeffs)
Definition flintcf_Q.cc:377
static long Int(number &n, const coeffs)
Definition flintcf_Q.cc:143
static char * nlEatLong(char *s, mpz_ptr i)
Definition flintcf_Q.cc:30
static number Init_bigint(number i, const coeffs dummy, const coeffs dst)
static number IntMod(number a, number b, const coeffs c)
#define STATIC_VAR
Definition globaldefs.h:7
static bool Greater(mono_type m1, mono_type m2)
#define SR_INT
Definition longrat.h:67
#define SR_TO_INT(SR)
Definition longrat.h:69
The main handler for Singular numbers which are suitable for Singular polynomials.
char * nEati(char *s, int *i, int m)
divide by the first (leading) number and return it, i.e. make monic
Definition numbers.cc:665
const char *const nDivBy0
Definition numbers.h:89
#define omStrDup(s)
#define omFreeSize(addr, size)
#define omAlloc(size)
#define omFree(addr)
#define omAlloc0(size)
#define NULL
Definition omList.c:12
void StringAppendS(const char *st)
Definition reporter.cc:107
void s_readmpz_base(s_buff F, mpz_ptr a, int base)
Definition s_buff.cc:210
int s_readint(s_buff F)
Definition s_buff.cc:113
s_buff f_read
Definition s_buff.h:22
FILE * f_write
Definition s_buff.h:23
#define mpz_sgn1(A)
Definition si_gmp.h:18
#define SR_HDL(A)
Definition tgb.cc:35