My Project
Loading...
Searching...
No Matches
Typedefs | Functions
flintcf_Q.cc File Reference
#include <ctype.h>
#include "misc/auxiliary.h"
#include <flint/flint.h>
#include <flint/fmpq_poly.h>
#include "factory/factory.h"
#include "coeffs/coeffs.h"
#include "coeffs/numbers.h"
#include "coeffs/longrat.h"

Go to the source code of this file.

Typedefs

typedef fmpq_poly_struct * fmpq_poly_ptr
 
typedef fmpz * fmpz_ptr
 

Functions

static char * nlEatLong (char *s, mpz_ptr i)
 
static BOOLEAN CoeffIsEqual (const coeffs r, n_coeffType n, void *)
 
static void SetChar (const coeffs)
 
static number Mult (number a, number b, const coeffs)
 
static number Sub (number a, number b, const coeffs)
 
static number Add (number a, number b, const coeffs)
 
static number Div (number a, number b, const coeffs)
 
static number ExactDiv (number a, number b, const coeffs)
 
static number Init (long i, const coeffs)
 
static number InitMPZ (mpz_t i, const coeffs)
 
static int Size (number n, const coeffs)
 
static long Int (number &n, const coeffs)
 
static void MPZ (mpz_t result, number &n, const coeffs)
 
static number Neg (number a, const coeffs)
 
static number Invers (number a, const coeffs)
 
static number Copy (number a, const coeffs)
 
static BOOLEAN IsOne (number a, const coeffs)
 
static BOOLEAN IsZero (number a, const coeffs)
 
static void WriteShort (number a, const coeffs r)
 
static const char * Read (const char *st, number *a, const coeffs r)
 
static void Normalize (number &a, const coeffs)
 
static BOOLEAN Greater (number a, number b, const coeffs)
 
static BOOLEAN Equal (number a, number b, const coeffs)
 
static BOOLEAN IsMOne (number k, const coeffs)
 
static BOOLEAN GreaterZero (number, const coeffs)
 
static void Power (number a, int i, number *result, const coeffs)
 
static number GetDenom (number &n, const coeffs)
 
static number GetNumerator (number &n, const coeffs)
 
static number Gcd (number a, number b, const coeffs)
 
static number ExtGcd (number a, number b, number *s, number *t, const coeffs)
 
static number Lcm (number, number, const coeffs)
 
static void Delete (number *a, const coeffs)
 
static nMapFunc SetMap (const coeffs, const coeffs)
 
static number Farey (number, number, const coeffs)
 
static number ChineseRemainder (number *, number *, int, BOOLEAN, CFArray &, const coeffs)
 
static int ParDeg (number x, const coeffs)
 
static number Parameter (const int, const coeffs)
 
static void WriteFd (number a, const ssiInfo *d, const coeffs)
 
static number ReadFd (const ssiInfo *d, const coeffs)
 
static number ConvFactoryNSingN (const CanonicalForm, const coeffs)
 
static CanonicalForm ConvSingNFactoryN (number, BOOLEAN, const coeffs)
 
char * CoeffName (const coeffs r)
 
coeffs flintQInitCfByName (char *s, n_coeffType n)
 
static BOOLEAN DBTest (number, const char *, const int, const coeffs)
 
static void KillChar (coeffs cf)
 
BOOLEAN flintQ_InitChar (coeffs cf, void *infoStruct)
 

Typedef Documentation

◆ fmpq_poly_ptr

typedef fmpq_poly_struct* fmpq_poly_ptr

Definition at line 22 of file flintcf_Q.cc.

◆ fmpz_ptr

typedef fmpz* fmpz_ptr

Definition at line 23 of file flintcf_Q.cc.

Function Documentation

◆ Add()

static number Add ( number  a,
number  b,
const  coeffs 
)
static

Definition at line 68 of file flintcf_Q.cc.

69{
70 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
71 fmpq_poly_init(res);
72 fmpq_poly_add(res,(fmpq_poly_ptr)a,(fmpq_poly_ptr)b);
73 return (number)res;
74}
CanonicalForm b
Definition: cfModGcd.cc:4103
CanonicalForm res
Definition: facAbsFact.cc:60
fmpq_poly_struct * fmpq_poly_ptr
Definition: flintcf_Q.cc:22
#define omAlloc(size)
Definition: omAllocDecl.h:210

◆ ChineseRemainder()

static number ChineseRemainder ( number *  ,
number *  ,
int  ,
BOOLEAN  ,
CFArray ,
const  coeffs 
)
static

Definition at line 450 of file flintcf_Q.cc.

451{
452 WerrorS("not yet: ChineseRemainder");
453 return NULL;
454}
void WerrorS(const char *s)
Definition: feFopen.cc:24
#define NULL
Definition: omList.c:12

◆ CoeffIsEqual()

static BOOLEAN CoeffIsEqual ( const coeffs  r,
n_coeffType  n,
void *   
)
static

Definition at line 46 of file flintcf_Q.cc.

47{
48 return (r->type==n);
49}

◆ CoeffName()

char * CoeffName ( const coeffs  r)

Definition at line 526 of file flintcf_Q.cc.

527{
528 STATIC_VAR char CoeffName_flint_Q[20];
529 sprintf(CoeffName_flint_Q,"flintQp[%s]",r->pParameterNames[0]);
530 return (char*)CoeffName_flint_Q;
531
532}
#define STATIC_VAR
Definition: globaldefs.h:7

◆ ConvFactoryNSingN()

static number ConvFactoryNSingN ( const  CanonicalForm,
const  coeffs 
)
static

Definition at line 516 of file flintcf_Q.cc.

517{
518 WerrorS("not yet: ConvFactoryNSingN");
519 return NULL;
520}

◆ ConvSingNFactoryN()

static CanonicalForm ConvSingNFactoryN ( number  ,
BOOLEAN  ,
const  coeffs 
)
static

Definition at line 521 of file flintcf_Q.cc.

522{
523 WerrorS("not yet: ConvSingNFactoryN");
524 return CanonicalForm(0);
525}
factory's main class
Definition: canonicalform.h:86

◆ Copy()

static number Copy ( number  a,
const  coeffs 
)
static

Definition at line 202 of file flintcf_Q.cc.

203{
204 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
205 fmpq_poly_init(res);
206 fmpq_poly_set(res,(fmpq_poly_ptr)a);
207 return (number)res;
208}

◆ DBTest()

static BOOLEAN DBTest ( number  ,
const char *  ,
const int  ,
const  coeffs 
)
static

Definition at line 551 of file flintcf_Q.cc.

552{
553 return TRUE;
554}
#define TRUE
Definition: auxiliary.h:100

◆ Delete()

static void Delete ( number *  a,
const  coeffs 
)
static

Definition at line 411 of file flintcf_Q.cc.

412{
413 if ((*a)!=NULL)
414 {
415 fmpq_poly_clear((fmpq_poly_ptr)*a);
416 omFree(*a);
417 *a=NULL;
418 }
419}
#define omFree(addr)
Definition: omAllocDecl.h:261

◆ Div()

static number Div ( number  a,
number  b,
const  coeffs 
)
static

Definition at line 75 of file flintcf_Q.cc.

76{
77 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
78 fmpq_poly_init(res);
79 if(fmpq_poly_is_zero((fmpq_poly_ptr)b))
80 {
82 }
83 else
84 {
85 fmpq_poly_div(res,(fmpq_poly_ptr)a,(fmpq_poly_ptr)b);
86 fmpq_poly_t mod;
87 fmpq_poly_init(mod);
88 fmpq_poly_rem(mod,(fmpq_poly_ptr)a,(fmpq_poly_ptr)b);
89 if (!fmpq_poly_is_zero((fmpq_poly_ptr)mod))
90 {
91 WerrorS("cannot divide");
92 }
93 fmpq_poly_clear(mod);
94 }
95 return (number)res;
96}
CF_NO_INLINE FACTORY_PUBLIC CanonicalForm mod(const CanonicalForm &, const CanonicalForm &)
const char *const nDivBy0
Definition: numbers.h:89

◆ Equal()

static BOOLEAN Equal ( number  a,
number  b,
const  coeffs 
)
static

Definition at line 324 of file flintcf_Q.cc.

325{
326 return (fmpq_poly_equal((fmpq_poly_ptr)a,(fmpq_poly_ptr)b));
327}

◆ ExactDiv()

static number ExactDiv ( number  a,
number  b,
const  coeffs 
)
static

Definition at line 97 of file flintcf_Q.cc.

98{
99 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
100 fmpq_poly_init(res);
101 if(fmpq_poly_is_zero((fmpq_poly_ptr)b))
102 {
104 }
105 else
106 fmpq_poly_div(res,(fmpq_poly_ptr)a,(fmpq_poly_ptr)b);
107 return (number)res;
108}

◆ ExtGcd()

static number ExtGcd ( number  a,
number  b,
number *  s,
number *  t,
const  coeffs 
)
static

Definition at line 397 of file flintcf_Q.cc.

398{
399 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
400 fmpq_poly_init(res);
401 fmpq_poly_init((fmpq_poly_ptr)*s);
402 fmpq_poly_init((fmpq_poly_ptr)*t);
403 fmpq_poly_xgcd(res,(fmpq_poly_ptr)*s,(fmpq_poly_ptr)*t,(fmpq_poly_ptr)a,(fmpq_poly_ptr)b);
404 return (number)res;
405}
const CanonicalForm int s
Definition: facAbsFact.cc:51

◆ Farey()

static number Farey ( number  ,
number  ,
const  coeffs 
)
static

Definition at line 445 of file flintcf_Q.cc.

446{
447 WerrorS("not yet: Farey");
448 return NULL;
449}

◆ flintQ_InitChar()

BOOLEAN flintQ_InitChar ( coeffs  cf,
void *  infoStruct 
)

Definition at line 561 of file flintcf_Q.cc.

562{
563 char *pp=(char*)infoStruct;
564 cf->cfCoeffName = CoeffName;
565 cf->nCoeffIsEqual = CoeffIsEqual;
566 cf->cfKillChar = KillChar;
567 cf->cfSetChar = SetChar;
568 cf->ch=0; //char 0
569 cf->cfMult = Mult;
570 cf->cfSub = Sub;
571 cf->cfAdd = Add;
572 cf->cfDiv = Div;
573 cf->cfExactDiv = ExactDiv; // ???
574 cf->cfInit =Init;
575 cf->cfInitMPZ =InitMPZ;
576 cf->cfSize = Size;
577 cf->cfInt = Int;
578 cf->cfMPZ = MPZ;
579 cf->cfInpNeg = Neg;
580 cf->cfInvers = Invers;
581 cf->cfCopy = Copy;
582 cf->cfRePart = Copy;
583 // default: cf->cfImPart = ndReturn0;
584 cf->cfWriteLong = WriteShort; //WriteLong;
585 cf->cfWriteShort = WriteShort;
586 cf->cfRead = Read;
587 cf->cfNormalize = Normalize;
588
589 //cf->cfDivComp=
590 //cf->cfIsUnit=
591 //cf->cfGetUnit=
592 //cf->cfDivBy=
593
594 cf->cfGreater=Greater;
595 cf->cfEqual =Equal;
596 cf->cfIsZero =IsZero;
597 cf->cfIsOne =IsOne;
598 cf->cfIsMOne =IsMOne;
599 cf->cfGreaterZero=GreaterZero;
600
601 cf->cfPower = Power;
602 cf->cfGetDenom = GetDenom;
603 cf->cfGetNumerator = GetNumerator;
604 cf->cfGcd = Gcd;
605 cf->cfExtGcd = ExtGcd;
606 cf->cfLcm = Lcm;
607 cf->cfDelete = Delete;
608 cf->cfSetMap = SetMap;
609 // default: cf->cfInpMult
610 // default: cf->cfInpAdd
611 cf->cfFarey =Farey;
612 cf->cfChineseRemainder=ChineseRemainder;
613 cf->cfParDeg = ParDeg;
614 cf->cfParameter = Parameter;
615 // cf->cfClearContent = ClearContent;
616 // cf->cfClearDenominators = ClearDenominators;
617 cf->convFactoryNSingN=ConvFactoryNSingN;
618 cf->convSingNFactoryN=ConvSingNFactoryN;
619 cf->cfWriteFd = WriteFd;
620 cf->cfReadFd = ReadFd;
621#ifdef LDEBUG
622 cf->cfDBTest = DBTest;
623#endif
624
625 cf->iNumberOfParameters = 1;
626 char **pn=(char**)omAlloc0(sizeof(char*));
627 pn[0]=omStrDup(pp);
628 cf->pParameterNames = (const char **)pn;
629 cf->has_simple_Inverse= FALSE;
630 cf->has_simple_Alloc= FALSE;
631 cf->is_field=FALSE;
632
633 return FALSE;
634}
#define FALSE
Definition: auxiliary.h:96
CanonicalForm FACTORY_PUBLIC pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition: cf_gcd.cc:676
CanonicalForm cf
Definition: cfModGcd.cc:4083
static number ExtGcd(number a, number b, number *s, number *t, const coeffs)
Definition: flintcf_Q.cc:397
static void WriteShort(number a, const coeffs r)
Definition: flintcf_Q.cc:220
static number Copy(number a, const coeffs)
Definition: flintcf_Q.cc:202
static number ChineseRemainder(number *, number *, int, BOOLEAN, CFArray &, const coeffs)
Definition: flintcf_Q.cc:450
static void Normalize(number &a, const coeffs)
Definition: flintcf_Q.cc:316
static void SetChar(const coeffs)
Definition: flintcf_Q.cc:50
static nMapFunc SetMap(const coeffs, const coeffs)
Definition: flintcf_Q.cc:420
static number Farey(number, number, const coeffs)
Definition: flintcf_Q.cc:445
static number GetDenom(number &n, const coeffs)
Definition: flintcf_Q.cc:373
static const char * Read(const char *st, number *a, const coeffs r)
Definition: flintcf_Q.cc:274
static BOOLEAN IsOne(number a, const coeffs)
Definition: flintcf_Q.cc:332
char * CoeffName(const coeffs r)
Definition: flintcf_Q.cc:526
static number ConvFactoryNSingN(const CanonicalForm, const coeffs)
Definition: flintcf_Q.cc:516
static number InitMPZ(mpz_t i, const coeffs)
Definition: flintcf_Q.cc:125
static int Size(number n, const coeffs)
Definition: flintcf_Q.cc:132
static number Add(number a, number b, const coeffs)
Definition: flintcf_Q.cc:68
static number Div(number a, number b, const coeffs)
Definition: flintcf_Q.cc:75
static void WriteFd(number a, const ssiInfo *d, const coeffs)
Definition: flintcf_Q.cc:466
static void Delete(number *a, const coeffs)
Definition: flintcf_Q.cc:411
static number Parameter(const int, const coeffs)
Definition: flintcf_Q.cc:459
static BOOLEAN DBTest(number, const char *, const int, const coeffs)
Definition: flintcf_Q.cc:551
static void KillChar(coeffs cf)
Definition: flintcf_Q.cc:556
static CanonicalForm ConvSingNFactoryN(number, BOOLEAN, const coeffs)
Definition: flintcf_Q.cc:521
static number Init(long i, const coeffs)
Definition: flintcf_Q.cc:118
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:491
static number ExactDiv(number a, number b, const coeffs)
Definition: flintcf_Q.cc:97
static void Power(number a, int i, number *result, const coeffs)
Definition: flintcf_Q.cc:366
static BOOLEAN IsMOne(number k, const coeffs)
Definition: flintcf_Q.cc:336
static number Sub(number a, number b, const coeffs)
Definition: flintcf_Q.cc:61
static number GetNumerator(number &n, const coeffs)
Definition: flintcf_Q.cc:381
static BOOLEAN GreaterZero(number, const coeffs)
Definition: flintcf_Q.cc:360
static number Gcd(number a, number b, const coeffs)
Definition: flintcf_Q.cc:390
static BOOLEAN CoeffIsEqual(const coeffs r, n_coeffType n, void *)
Definition: flintcf_Q.cc:46
static number Mult(number a, number b, const coeffs)
Definition: flintcf_Q.cc:54
static number Invers(number a, const coeffs)
Definition: flintcf_Q.cc:182
static number Lcm(number, number, const coeffs)
Definition: flintcf_Q.cc:406
static int ParDeg(number x, const coeffs)
Definition: flintcf_Q.cc:455
static BOOLEAN IsZero(number a, const coeffs)
Definition: flintcf_Q.cc:328
static number Neg(number a, const coeffs)
Definition: flintcf_Q.cc:177
static BOOLEAN Equal(number a, number b, const coeffs)
Definition: flintcf_Q.cc:324
static BOOLEAN Greater(number a, number b, const coeffs)
Definition: flintcf_Q.cc:320
static long Int(number &n, const coeffs)
Definition: flintcf_Q.cc:136
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define omAlloc0(size)
Definition: omAllocDecl.h:211

◆ flintQInitCfByName()

coeffs flintQInitCfByName ( char *  s,
n_coeffType  n 
)

Definition at line 533 of file flintcf_Q.cc.

534{
535 const char start[]="flintQp[";
536 const int start_len=strlen(start);
537 if (strncmp(s,start,start_len)==0)
538 {
539 s+=start_len;
540 char st[10];
541 int l=sscanf(s,"%s",st);
542 if (l==1)
543 {
544 while (st[strlen(st)-1]==']') st[strlen(st)-1]='\0';
545 return nInitChar(n,(void*)st);
546 }
547 }
548 return NULL;
549}
int l
Definition: cfEzgcd.cc:100
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:413

◆ Gcd()

static number Gcd ( number  a,
number  b,
const  coeffs 
)
static

Definition at line 390 of file flintcf_Q.cc.

391{
392 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
393 fmpq_poly_init(res);
394 fmpq_poly_gcd(res,(fmpq_poly_ptr)a,(fmpq_poly_ptr)b);
395 return (number)res;
396}

◆ GetDenom()

static number GetDenom ( number &  n,
const  coeffs 
)
static

Definition at line 373 of file flintcf_Q.cc.

374{
375 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
376 fmpq_poly_init(res);
377 fmpz_ptr den=fmpq_poly_denref((fmpq_poly_ptr)n);
378 fmpq_poly_set_fmpz(res,den);
379 return (number)res;
380}
CanonicalForm den(const CanonicalForm &f)
fmpz * fmpz_ptr
Definition: flintcf_Q.cc:23

◆ GetNumerator()

static number GetNumerator ( number &  n,
const  coeffs 
)
static

Definition at line 381 of file flintcf_Q.cc.

382{
383 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
384 fmpq_poly_init(res);
385 fmpq_poly_set(res,(fmpq_poly_ptr)n);
386 fmpz_ptr den=fmpq_poly_denref(res);
387 fmpq_poly_scalar_mul_fmpz(res,res,den);
388 return (number)res;
389}

◆ Greater()

static BOOLEAN Greater ( number  a,
number  b,
const  coeffs 
)
static

Definition at line 320 of file flintcf_Q.cc.

321{
322 return (fmpq_poly_cmp((fmpq_poly_ptr)a,(fmpq_poly_ptr)b)>0);
323}

◆ GreaterZero()

static BOOLEAN GreaterZero ( number  ,
const  coeffs 
)
static

Definition at line 360 of file flintcf_Q.cc.

361{
362 // does it have a leading sign?
363 // no: 0 and 1 do not have, everything else is in (...)
364 return TRUE;
365}

◆ Init()

static number Init ( long  i,
const  coeffs 
)
static

Definition at line 118 of file flintcf_Q.cc.

119{
120 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
121 fmpq_poly_init(res);
122 fmpq_poly_set_si(res,i);
123 return (number)res;
124}
int i
Definition: cfEzgcd.cc:132

◆ InitMPZ()

static number InitMPZ ( mpz_t  i,
const  coeffs 
)
static

Definition at line 125 of file flintcf_Q.cc.

126{
127 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
128 fmpq_poly_init(res);
129 fmpq_poly_set_mpz(res,i);
130 return (number)res;
131}

◆ Int()

static long Int ( number &  n,
const  coeffs 
)
static

Definition at line 136 of file flintcf_Q.cc.

137{
138 if (fmpq_poly_degree((fmpq_poly_ptr)n)==0)
139 {
140 mpq_t m;
141 mpq_init(m);
142 fmpq_poly_get_coeff_mpq(m,(fmpq_poly_ptr)n,0);
143 mpz_t num,den;
144 mpz_init(num);
145 mpz_init(den);
146 mpq_get_num(num,m);
147 mpq_get_den(den,m);
148 long nl=mpz_get_si(num);
149 if (mpz_cmp_si(num,nl)!=0) nl=0;
150 long dl=mpz_get_si(den);
151 if ((dl!=1)||(mpz_cmp_si(den,dl)!=0)) nl=0;
152 mpz_clear(num);
153 mpz_clear(den);
154 mpq_clear(m);
155 return nl;
156 }
157 return 0;
158}
CanonicalForm num(const CanonicalForm &f)
int m
Definition: cfEzgcd.cc:128

◆ Invers()

static number Invers ( number  a,
const  coeffs 
)
static

Definition at line 182 of file flintcf_Q.cc.

183{
184 if(fmpq_poly_is_zero((fmpq_poly_ptr)a))
185 {
187 return NULL;
188 }
189 if (fmpq_poly_degree((fmpq_poly_ptr)a)==0)
190 {
191 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
192 fmpq_poly_init(res);
193 fmpq_poly_inv(res,(fmpq_poly_ptr)a);
194 return (number)res;
195 }
196 else
197 {
198 WerrorS("not invertable");
199 return NULL;
200 }
201}

◆ IsMOne()

static BOOLEAN IsMOne ( number  k,
const  coeffs 
)
static

Definition at line 336 of file flintcf_Q.cc.

337{
338 if (fmpq_poly_length((fmpq_poly_ptr)k)>0) return FALSE;
339 fmpq_poly_canonicalise((fmpq_poly_ptr)k);
340 mpq_t m;
341 mpq_init(m);
342 fmpq_poly_get_coeff_mpq(m,(fmpq_poly_ptr)k,0);
343 mpz_t num,den;
344 mpz_init(num);
345 mpq_get_num(num,m);
347 if (mpz_cmp_si(num,(long)-1)!=0) result=FALSE;
348 else
349 {
350 mpz_init(den);
351 mpq_get_den(den,m);
352 int dl=(int)mpz_get_si(den);
353 if ((dl!=1)||(mpz_cmp_si(den,(long)dl)!=0)) result=FALSE;
354 mpz_clear(den);
355 }
356 mpz_clear(num);
357 mpq_clear(m);
358 return (result);
359}
int BOOLEAN
Definition: auxiliary.h:87
int k
Definition: cfEzgcd.cc:99
return result
Definition: facAbsBiFact.cc:75

◆ IsOne()

static BOOLEAN IsOne ( number  a,
const  coeffs 
)
static

Definition at line 332 of file flintcf_Q.cc.

333{
334 return fmpq_poly_is_one((fmpq_poly_ptr)a);
335}

◆ IsZero()

static BOOLEAN IsZero ( number  a,
const  coeffs 
)
static

Definition at line 328 of file flintcf_Q.cc.

329{
330 return fmpq_poly_is_zero((fmpq_poly_ptr)a);
331}

◆ KillChar()

static void KillChar ( coeffs  cf)
static

Definition at line 556 of file flintcf_Q.cc.

557{
558 omFree((ADDRESS)(cf->pParameterNames[0]));
559 omFreeSize(cf->pParameterNames,sizeof(char*));
560}
void * ADDRESS
Definition: auxiliary.h:119
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260

◆ Lcm()

static number Lcm ( number  ,
number  ,
const  coeffs 
)
static

Definition at line 406 of file flintcf_Q.cc.

407{
408 WerrorS("not yet: Lcm");
409 return NULL;
410}

◆ MPZ()

static void MPZ ( mpz_t  result,
number &  n,
const  coeffs 
)
static

Definition at line 159 of file flintcf_Q.cc.

160{
161 mpz_init(result);
162 if (fmpq_poly_degree((fmpq_poly_ptr)n)==0)
163 {
164 mpq_t m;
165 mpq_init(m);
166 fmpq_poly_get_coeff_mpq(m,(fmpq_poly_ptr)n,0);
167 mpz_t den;
168 mpz_init(den);
169 mpq_get_num(result,m);
170 mpq_get_den(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 mpq_clear(m);
175 }
176}

◆ Mult()

static number Mult ( number  a,
number  b,
const  coeffs 
)
static

Definition at line 54 of file flintcf_Q.cc.

55{
56 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
57 fmpq_poly_init(res);
58 fmpq_poly_mul(res,(fmpq_poly_ptr)a,(fmpq_poly_ptr)b);
59 return (number)res;
60}

◆ Neg()

static number Neg ( number  a,
const  coeffs 
)
static

Definition at line 177 of file flintcf_Q.cc.

178{
179 fmpq_poly_neg((fmpq_poly_ptr)a,(fmpq_poly_ptr)a);
180 return a;
181}

◆ nlEatLong()

static char * nlEatLong ( char *  s,
mpz_ptr  i 
)
static

Definition at line 27 of file flintcf_Q.cc.

28{
29 const char * start=s;
30
31 while (*s >= '0' && *s <= '9') s++;
32 if (*s=='\0')
33 {
34 mpz_set_str(i,start,10);
35 }
36 else
37 {
38 char c=*s;
39 *s='\0';
40 mpz_set_str(i,start,10);
41 *s=c;
42 }
43 return s;
44}

◆ Normalize()

static void Normalize ( number &  a,
const  coeffs 
)
static

Definition at line 316 of file flintcf_Q.cc.

317{
318 fmpq_poly_canonicalise((fmpq_poly_ptr)a);
319}

◆ Parameter()

static number Parameter ( const int  ,
const  coeffs 
)
static

Definition at line 459 of file flintcf_Q.cc.

460{
461 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
462 fmpq_poly_init(res);
463 fmpq_poly_set_coeff_si(res,1,1);
464 return (number)res;
465}

◆ ParDeg()

static int ParDeg ( number  x,
const  coeffs 
)
static

Definition at line 455 of file flintcf_Q.cc.

456{
457 return fmpq_poly_degree((fmpq_poly_ptr)x);
458}
Variable x
Definition: cfModGcd.cc:4082

◆ Power()

static void Power ( number  a,
int  i,
number *  result,
const  coeffs 
)
static

Definition at line 366 of file flintcf_Q.cc.

367{
368 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
369 fmpq_poly_init(res);
370 *result=(number)res;
371 fmpq_poly_pow((fmpq_poly_ptr)(*result),(fmpq_poly_ptr)a,i);
372}

◆ Read()

static const char * Read ( const char *  st,
number *  a,
const coeffs  r 
)
static

Definition at line 274 of file flintcf_Q.cc.

275{
276// we only read "monomials" (i.e. [-][digits][parameter]),
277// everythings else (+,*,^,()) is left to the singular interpreter
278 char *s=(char *)st;
279 *a=(number)omAlloc(sizeof(fmpq_poly_t));
280 fmpq_poly_init((fmpq_poly_ptr)(*a));
281 BOOLEAN neg=FALSE;
282 if (*s=='-') { neg=TRUE; s++;}
283 if (isdigit(*s))
284 {
285 mpz_t z;
286 mpz_init(z);
287 s=nlEatLong((char *)s, z);
288 fmpq_poly_set_mpz((fmpq_poly_ptr)(*a),z);
289 if (*s == '/')
290 {
291 s++;
292 s=nlEatLong((char *)s, z);
293 fmpq_poly_scalar_div_mpz((fmpq_poly_ptr)(*a),(fmpq_poly_ptr)(*a),z);
294 }
295 mpz_clear(z);
296 }
297 else if(strncmp(s,r->pParameterNames[0],strlen(r->pParameterNames[0]))==0)
298 {
299 fmpq_poly_set_coeff_si((fmpq_poly_ptr)(*a),1,1);
300 s+=strlen(r->pParameterNames[0]);
301 if(isdigit(*s))
302 {
303 int i=1;
304 s=nEati(s,&i,0);
305 if (i!=1)
306 {
307 fmpq_poly_set_coeff_si((fmpq_poly_ptr)(*a),1,0);
308 fmpq_poly_set_coeff_si((fmpq_poly_ptr)(*a),i,1);
309 }
310 }
311 }
312 if (neg)
313 fmpq_poly_neg((fmpq_poly_ptr)(*a),(fmpq_poly_ptr)(*a));
314 return s;
315}
static char * nlEatLong(char *s, mpz_ptr i)
Definition: flintcf_Q.cc:27
char * nEati(char *s, int *i, int m)
divide by the first (leading) number and return it, i.e. make monic
Definition: numbers.cc:677

◆ ReadFd()

static number ReadFd ( const ssiInfo d,
const  coeffs 
)
static

Definition at line 491 of file flintcf_Q.cc.

492{
493 // format: len a_len .. a_0
494 fmpq_poly_ptr aa=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
495 fmpq_poly_init(aa);
496 int l=s_readint(d->f_read);
497 mpz_t nm;
498 mpz_init(nm);
499 mpq_t m;
500 mpq_init(m);
501 for (int i=l;i>=0;i--)
502 {
503
505 mpq_set_num(m,nm);
507 mpq_set_den(m,nm);
508 fmpq_poly_set_coeff_mpq(aa,i,m);
509 }
510 mpz_clear(nm);
511 mpq_clear(m);
512 return (number)aa;
513}
#define SSI_BASE
Definition: auxiliary.h:135
void s_readmpz_base(s_buff F, mpz_ptr a, int base)
Definition: s_buff.cc:209
int s_readint(s_buff F)
Definition: s_buff.cc:112
s_buff f_read
Definition: s_buff.h:22

◆ SetChar()

static void SetChar ( const  coeffs)
static

Definition at line 50 of file flintcf_Q.cc.

51{
52 // dummy
53}

◆ SetMap()

static nMapFunc SetMap ( const  coeffs,
const  coeffs 
)
static

Definition at line 420 of file flintcf_Q.cc.

421{
422 WerrorS("not yet: SetMap");
423 return NULL;
424}

◆ Size()

static int Size ( number  n,
const  coeffs 
)
static

Definition at line 132 of file flintcf_Q.cc.

133{
134 return fmpq_poly_degree((fmpq_poly_ptr)n);
135}

◆ Sub()

static number Sub ( number  a,
number  b,
const  coeffs 
)
static

Definition at line 61 of file flintcf_Q.cc.

62{
63 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
64 fmpq_poly_init(res);
65 fmpq_poly_sub(res,(fmpq_poly_ptr)a,(fmpq_poly_ptr)b);
66 return (number)res;
67}

◆ WriteFd()

static void WriteFd ( number  a,
const ssiInfo d,
const  coeffs 
)
static

Definition at line 466 of file flintcf_Q.cc.

467{
468 // format: len a_len(num den) .. a_0
470 int l=fmpq_poly_length(aa);
471 fprintf(d->f_write,"%d ",l);
472 mpq_t m;
473 mpq_init(m);
474 mpz_t num,den;
475 mpz_init(num);
476 mpz_init(den);
477 for(int i=l; i>=0; i--)
478 {
479 fmpq_poly_get_coeff_mpq(m,(fmpq_poly_ptr)a,i);
480 mpq_get_num(num,m);
481 mpq_get_den(den,m);
482 mpz_out_str (d->f_write,SSI_BASE, num);
483 fputc(' ',d->f_write);
484 mpz_out_str (d->f_write,SSI_BASE, den);
485 fputc(' ',d->f_write);
486 }
487 mpz_clear(den);
488 mpz_clear(num);
489 mpq_clear(m);
490}
FILE * f_write
Definition: s_buff.h:23

◆ WriteShort()

static void WriteShort ( number  a,
const coeffs  r 
)
static

Definition at line 220 of file flintcf_Q.cc.

221{
222 //fmpq_poly_print_pretty((fmpq_poly_ptr)a,r->pParameterNames[0]);
223 if (IsOne(a,r)) StringAppendS("1");
224 else if (IsZero(a,r)) StringAppendS("0");
225 else
226 {
227 StringAppendS("(");
228 mpq_t m;
229 mpq_init(m);
230 mpz_t num,den;
231 mpz_init(num);
232 mpz_init(den);
233 BOOLEAN need_plus=FALSE;
234 for(int i=fmpq_poly_length((fmpq_poly_ptr)a);i>=0;i--)
235 {
236 fmpq_poly_get_coeff_mpq(m,(fmpq_poly_ptr)a,i);
237 mpq_get_num(num,m);
238 mpq_get_den(den,m);
239 if (mpz_sgn1(num)!=0)
240 {
241 if (need_plus && (mpz_sgn1(num)>0))
242 StringAppendS("+");
243 need_plus=TRUE;
244 int l=mpz_sizeinbase(num,10);
245 l=si_max(l,(int)mpz_sizeinbase(den,10));
246 l+=2;
247 char *s=(char*)omAlloc(l);
248 char *z=mpz_get_str(s,10,num);
249 if ((i==0)
250 ||(mpz_cmp_si(num,1)!=0)
251 ||(mpz_cmp_si(den,1)!=0))
252 {
253 StringAppendS(z);
254 if (mpz_cmp_si(den,1)!=0)
255 {
256 StringAppendS("/");
257 z=mpz_get_str(s,10,den);
258 StringAppendS(z);
259 }
260 if (i!=0) StringAppendS("*");
261 }
262 if (i>1)
263 StringAppend("%s^%d",r->pParameterNames[0],i);
264 else if (i==1)
265 StringAppend("%s",r->pParameterNames[0]);
266 }
267 }
268 mpz_clear(den);
269 mpz_clear(num);
270 mpq_clear(m);
271 StringAppendS(")");
272 }
273}
static int si_max(const int a, const int b)
Definition: auxiliary.h:124
#define StringAppend
Definition: emacs.cc:79
void StringAppendS(const char *st)
Definition: reporter.cc:107
#define mpz_sgn1(A)
Definition: si_gmp.h:18