My Project
Typedefs | Functions
flintcf_Q.cc File Reference
#include <ctype.h>
#include "misc/auxiliary.h"
#include <flint/flint.h>
#include <flint/fmpz.h>
#include <flint/fmpq.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 24 of file flintcf_Q.cc.

◆ fmpz_ptr

typedef fmpz* fmpz_ptr

Definition at line 25 of file flintcf_Q.cc.

Function Documentation

◆ Add()

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

Definition at line 70 of file flintcf_Q.cc.

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

◆ ChineseRemainder()

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

Definition at line 439 of file flintcf_Q.cc.

440{
441 WerrorS("not yet: ChineseRemainder");
442 return NULL;
443}
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 48 of file flintcf_Q.cc.

49{
50 return (r->type==n);
51}

◆ CoeffName()

char * CoeffName ( const coeffs  r)

Definition at line 519 of file flintcf_Q.cc.

520{
521 STATIC_VAR char CoeffName_flint_Q[20];
522 sprintf(CoeffName_flint_Q,"flintQp[%s]",r->pParameterNames[0]);
523 return (char*)CoeffName_flint_Q;
524
525}
#define STATIC_VAR
Definition: globaldefs.h:7

◆ ConvFactoryNSingN()

static number ConvFactoryNSingN ( const  CanonicalForm,
const  coeffs 
)
static

Definition at line 509 of file flintcf_Q.cc.

510{
511 WerrorS("not yet: ConvFactoryNSingN");
512 return NULL;
513}

◆ ConvSingNFactoryN()

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

Definition at line 514 of file flintcf_Q.cc.

515{
516 WerrorS("not yet: ConvSingNFactoryN");
517 return CanonicalForm(0);
518}
factory's main class
Definition: canonicalform.h:86

◆ Copy()

static number Copy ( number  a,
const  coeffs 
)
static

Definition at line 200 of file flintcf_Q.cc.

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

◆ DBTest()

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

Definition at line 544 of file flintcf_Q.cc.

545{
546 return TRUE;
547}
#define TRUE
Definition: auxiliary.h:100

◆ Delete()

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

Definition at line 400 of file flintcf_Q.cc.

401{
402 if ((*a)!=NULL)
403 {
404 fmpq_poly_clear((fmpq_poly_ptr)*a);
405 omFree(*a);
406 *a=NULL;
407 }
408}
#define omFree(addr)
Definition: omAllocDecl.h:261

◆ Div()

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

Definition at line 77 of file flintcf_Q.cc.

78{
79 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
80 fmpq_poly_init(res);
81 if(fmpq_poly_is_zero((fmpq_poly_ptr)b))
82 {
84 }
85 else
86 {
87 fmpq_poly_div(res,(fmpq_poly_ptr)a,(fmpq_poly_ptr)b);
88 fmpq_poly_t mod;
89 fmpq_poly_init(mod);
90 fmpq_poly_rem(mod,(fmpq_poly_ptr)a,(fmpq_poly_ptr)b);
91 if (!fmpq_poly_is_zero((fmpq_poly_ptr)mod))
92 {
93 WerrorS("cannot divide");
94 }
95 fmpq_poly_clear(mod);
96 }
97 return (number)res;
98}
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 320 of file flintcf_Q.cc.

321{
322 return (fmpq_poly_equal((fmpq_poly_ptr)a,(fmpq_poly_ptr)b));
323}

◆ ExactDiv()

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

Definition at line 99 of file flintcf_Q.cc.

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

◆ ExtGcd()

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

Definition at line 386 of file flintcf_Q.cc.

387{
388 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
389 fmpq_poly_init(res);
390 fmpq_poly_init((fmpq_poly_ptr)*s);
391 fmpq_poly_init((fmpq_poly_ptr)*t);
392 fmpq_poly_xgcd(res,(fmpq_poly_ptr)*s,(fmpq_poly_ptr)*t,(fmpq_poly_ptr)a,(fmpq_poly_ptr)b);
393 return (number)res;
394}
const CanonicalForm int s
Definition: facAbsFact.cc:51

◆ Farey()

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

Definition at line 434 of file flintcf_Q.cc.

435{
436 WerrorS("not yet: Farey");
437 return NULL;
438}

◆ flintQ_InitChar()

BOOLEAN flintQ_InitChar ( coeffs  cf,
void *  infoStruct 
)

Definition at line 554 of file flintcf_Q.cc.

555{
556 char *pp=(char*)infoStruct;
557 cf->cfCoeffName = CoeffName;
558 cf->nCoeffIsEqual = CoeffIsEqual;
559 cf->cfKillChar = KillChar;
560 cf->cfSetChar = SetChar;
561 cf->ch=0; //char 0
562 cf->cfMult = Mult;
563 cf->cfSub = Sub;
564 cf->cfAdd = Add;
565 cf->cfDiv = Div;
566 cf->cfExactDiv = ExactDiv; // ???
567 cf->cfInit =Init;
568 cf->cfInitMPZ =InitMPZ;
569 cf->cfSize = Size;
570 cf->cfInt = Int;
571 cf->cfMPZ = MPZ;
572 cf->cfInpNeg = Neg;
573 cf->cfInvers = Invers;
574 cf->cfCopy = Copy;
575 cf->cfRePart = Copy;
576 // default: cf->cfImPart = ndReturn0;
577 cf->cfWriteLong = WriteShort; //WriteLong;
578 cf->cfWriteShort = WriteShort;
579 cf->cfRead = Read;
580 cf->cfNormalize = Normalize;
581
582 //cf->cfDivComp=
583 //cf->cfIsUnit=
584 //cf->cfGetUnit=
585 //cf->cfDivBy=
586
587 cf->cfGreater=Greater;
588 cf->cfEqual =Equal;
589 cf->cfIsZero =IsZero;
590 cf->cfIsOne =IsOne;
591 cf->cfIsMOne =IsMOne;
592 cf->cfGreaterZero=GreaterZero;
593
594 cf->cfPower = Power;
595 cf->cfGetDenom = GetDenom;
596 cf->cfGetNumerator = GetNumerator;
597 cf->cfGcd = Gcd;
598 cf->cfExtGcd = ExtGcd;
599 cf->cfLcm = Lcm;
600 cf->cfDelete = Delete;
601 cf->cfSetMap = SetMap;
602 // default: cf->cfInpMult
603 // default: cf->cfInpAdd
604 cf->cfFarey =Farey;
605 cf->cfChineseRemainder=ChineseRemainder;
606 cf->cfParDeg = ParDeg;
607 cf->cfParameter = Parameter;
608 // cf->cfClearContent = ClearContent;
609 // cf->cfClearDenominators = ClearDenominators;
610 cf->convFactoryNSingN=ConvFactoryNSingN;
611 cf->convSingNFactoryN=ConvSingNFactoryN;
612 cf->cfWriteFd = WriteFd;
613 cf->cfReadFd = ReadFd;
614#ifdef LDEBUG
615 cf->cfDBTest = DBTest;
616#endif
617
618 cf->iNumberOfParameters = 1;
619 char **pn=(char**)omAlloc0(sizeof(char*));
620 pn[0]=omStrDup(pp);
621 cf->pParameterNames = (const char **)pn;
622 cf->has_simple_Inverse= FALSE;
623 cf->has_simple_Alloc= FALSE;
624 cf->is_field=FALSE;
625
626 return FALSE;
627}
#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:386
static void WriteShort(number a, const coeffs r)
Definition: flintcf_Q.cc:218
static number Copy(number a, const coeffs)
Definition: flintcf_Q.cc:200
static number ChineseRemainder(number *, number *, int, BOOLEAN, CFArray &, const coeffs)
Definition: flintcf_Q.cc:439
static void Normalize(number &a, const coeffs)
Definition: flintcf_Q.cc:312
static void SetChar(const coeffs)
Definition: flintcf_Q.cc:52
static nMapFunc SetMap(const coeffs, const coeffs)
Definition: flintcf_Q.cc:409
static number Farey(number, number, const coeffs)
Definition: flintcf_Q.cc:434
static number GetDenom(number &n, const coeffs)
Definition: flintcf_Q.cc:362
static const char * Read(const char *st, number *a, const coeffs r)
Definition: flintcf_Q.cc:265
static BOOLEAN IsOne(number a, const coeffs)
Definition: flintcf_Q.cc:328
char * CoeffName(const coeffs r)
Definition: flintcf_Q.cc:519
static number ConvFactoryNSingN(const CanonicalForm, const coeffs)
Definition: flintcf_Q.cc:509
static number InitMPZ(mpz_t i, const coeffs)
Definition: flintcf_Q.cc:127
static int Size(number n, const coeffs)
Definition: flintcf_Q.cc:138
static number Add(number a, number b, const coeffs)
Definition: flintcf_Q.cc:70
static number Div(number a, number b, const coeffs)
Definition: flintcf_Q.cc:77
static void WriteFd(number a, const ssiInfo *d, const coeffs)
Definition: flintcf_Q.cc:455
static void Delete(number *a, const coeffs)
Definition: flintcf_Q.cc:400
static number Parameter(const int, const coeffs)
Definition: flintcf_Q.cc:448
static BOOLEAN DBTest(number, const char *, const int, const coeffs)
Definition: flintcf_Q.cc:544
static void KillChar(coeffs cf)
Definition: flintcf_Q.cc:549
static CanonicalForm ConvSingNFactoryN(number, BOOLEAN, const coeffs)
Definition: flintcf_Q.cc:514
static number Init(long i, const coeffs)
Definition: flintcf_Q.cc:120
static void MPZ(mpz_t result, number &n, const coeffs)
Definition: flintcf_Q.cc:158
static number ReadFd(const ssiInfo *d, const coeffs)
Definition: flintcf_Q.cc:479
static number ExactDiv(number a, number b, const coeffs)
Definition: flintcf_Q.cc:99
static void Power(number a, int i, number *result, const coeffs)
Definition: flintcf_Q.cc:355
static BOOLEAN IsMOne(number k, const coeffs)
Definition: flintcf_Q.cc:332
static number Sub(number a, number b, const coeffs)
Definition: flintcf_Q.cc:63
static number GetNumerator(number &n, const coeffs)
Definition: flintcf_Q.cc:370
static BOOLEAN GreaterZero(number, const coeffs)
Definition: flintcf_Q.cc:349
static number Gcd(number a, number b, const coeffs)
Definition: flintcf_Q.cc:379
static BOOLEAN CoeffIsEqual(const coeffs r, n_coeffType n, void *)
Definition: flintcf_Q.cc:48
static number Mult(number a, number b, const coeffs)
Definition: flintcf_Q.cc:56
static number Invers(number a, const coeffs)
Definition: flintcf_Q.cc:180
static number Lcm(number, number, const coeffs)
Definition: flintcf_Q.cc:395
static int ParDeg(number x, const coeffs)
Definition: flintcf_Q.cc:444
static BOOLEAN IsZero(number a, const coeffs)
Definition: flintcf_Q.cc:324
static number Neg(number a, const coeffs)
Definition: flintcf_Q.cc:175
static BOOLEAN Equal(number a, number b, const coeffs)
Definition: flintcf_Q.cc:320
static BOOLEAN Greater(number a, number b, const coeffs)
Definition: flintcf_Q.cc:316
static long Int(number &n, const coeffs)
Definition: flintcf_Q.cc:142
#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 526 of file flintcf_Q.cc.

527{
528 const char start[]="flintQp[";
529 const int start_len=strlen(start);
530 if (strncmp(s,start,start_len)==0)
531 {
532 s+=start_len;
533 char st[10];
534 int l=sscanf(s,"%s",st);
535 if (l==1)
536 {
537 while (st[strlen(st)-1]==']') st[strlen(st)-1]='\0';
538 return nInitChar(n,(void*)st);
539 }
540 }
541 return NULL;
542}
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:414

◆ Gcd()

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

Definition at line 379 of file flintcf_Q.cc.

380{
381 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
382 fmpq_poly_init(res);
383 fmpq_poly_gcd(res,(fmpq_poly_ptr)a,(fmpq_poly_ptr)b);
384 return (number)res;
385}

◆ GetDenom()

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

Definition at line 362 of file flintcf_Q.cc.

363{
364 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
365 fmpq_poly_init(res);
366 fmpz_ptr den=fmpq_poly_denref((fmpq_poly_ptr)n);
367 fmpq_poly_set_fmpz(res,den);
368 return (number)res;
369}
CanonicalForm den(const CanonicalForm &f)
fmpz * fmpz_ptr
Definition: flintcf_Q.cc:25

◆ GetNumerator()

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

Definition at line 370 of file flintcf_Q.cc.

371{
372 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
373 fmpq_poly_init(res);
374 fmpq_poly_set(res,(fmpq_poly_ptr)n);
375 fmpz_ptr den=fmpq_poly_denref(res);
376 fmpq_poly_scalar_mul_fmpz(res,res,den);
377 return (number)res;
378}

◆ Greater()

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

Definition at line 316 of file flintcf_Q.cc.

317{
318 return (fmpq_poly_cmp((fmpq_poly_ptr)a,(fmpq_poly_ptr)b)>0);
319}

◆ GreaterZero()

static BOOLEAN GreaterZero ( number  ,
const  coeffs 
)
static

Definition at line 349 of file flintcf_Q.cc.

350{
351 // does it have a leading sign?
352 // no: 0 and 1 do not have, everything else is in (...)
353 return TRUE;
354}

◆ Init()

static number Init ( long  i,
const  coeffs 
)
static

Definition at line 120 of file flintcf_Q.cc.

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

◆ InitMPZ()

static number InitMPZ ( mpz_t  i,
const  coeffs 
)
static

Definition at line 127 of file flintcf_Q.cc.

128{
129 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
130 fmpq_poly_init(res);
131 fmpq_poly_fit_length(res, 1);
132 fmpz_set_mpz(res->coeffs, i);
133 fmpz_one(res->den);
134 _fmpq_poly_set_length(res, 1);
135 _fmpq_poly_normalise(res);
136 return (number)res;
137}
CanonicalForm den() const
den() returns the denominator of CO if CO is a rational number, 1 (from the current domain!...

◆ Int()

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

Definition at line 142 of file flintcf_Q.cc.

143{
144 if (fmpq_poly_degree((fmpq_poly_ptr)n)==0)
145 {
146 fmpq_t m;
147 fmpq_init(m);
148 fmpq_poly_get_coeff_fmpq(m,(fmpq_poly_ptr)n,0);
149 long nl=fmpz_get_si(fmpq_numref(m));
150 if (fmpz_cmp_si(fmpq_numref(m),nl)!=0) nl=0;
151 long dl=fmpz_get_si(fmpq_denref(m));
152 if ((dl!=1)||(fmpz_cmp_si(fmpq_denref(m),dl)!=0)) nl=0;
153 fmpq_clear(m);
154 return nl;
155 }
156 return 0;
157}
int m
Definition: cfEzgcd.cc:128

◆ Invers()

static number Invers ( number  a,
const  coeffs 
)
static

Definition at line 180 of file flintcf_Q.cc.

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

◆ IsMOne()

static BOOLEAN IsMOne ( number  k,
const  coeffs 
)
static

Definition at line 332 of file flintcf_Q.cc.

333{
334 if (fmpq_poly_length((fmpq_poly_ptr)k)>0) return FALSE;
335 fmpq_poly_canonicalise((fmpq_poly_ptr)k);
336 fmpq_t m;
337 fmpq_init(m);
338 fmpq_poly_get_coeff_fmpq(m,(fmpq_poly_ptr)k,0);
340 if (fmpz_cmp_si(fmpq_numref(m),(long)-1)!=0) result=FALSE;
341 else
342 {
343 int dl=(int)fmpz_get_si(fmpq_denref(m));
344 if ((dl!=1)||(fmpz_cmp_si(fmpq_denref(m),(long)dl)!=0)) result=FALSE;
345 }
346 fmpq_clear(m);
347 return (result);
348}
int BOOLEAN
Definition: auxiliary.h:87
int k
Definition: cfEzgcd.cc:99
return result
Definition: facAbsBiFact.cc:76

◆ IsOne()

static BOOLEAN IsOne ( number  a,
const  coeffs 
)
static

Definition at line 328 of file flintcf_Q.cc.

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

◆ IsZero()

static BOOLEAN IsZero ( number  a,
const  coeffs 
)
static

Definition at line 324 of file flintcf_Q.cc.

325{
326 return fmpq_poly_is_zero((fmpq_poly_ptr)a);
327}

◆ KillChar()

static void KillChar ( coeffs  cf)
static

Definition at line 549 of file flintcf_Q.cc.

550{
551 omFree((ADDRESS)(cf->pParameterNames[0]));
552 omFreeSize(cf->pParameterNames,sizeof(char*));
553}
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 395 of file flintcf_Q.cc.

396{
397 WerrorS("not yet: Lcm");
398 return NULL;
399}

◆ MPZ()

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

Definition at line 158 of file flintcf_Q.cc.

159{
160 mpz_init(result);
161 if (fmpq_poly_degree((fmpq_poly_ptr)n)==0)
162 {
163 fmpq_t m;
164 fmpq_init(m);
165 fmpq_poly_get_coeff_fmpq(m,(fmpq_poly_ptr)n,0);
166 mpz_t den;
167 mpz_init(den);
168 fmpq_get_mpz_frac(result,den,m);
169 int dl=(int)mpz_get_si(den);
170 if ((dl!=1)||(mpz_cmp_si(den,(long)dl)!=0)) mpz_set_ui(result,0);
171 mpz_clear(den);
172 fmpq_clear(m);
173 }
174}

◆ Mult()

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

Definition at line 56 of file flintcf_Q.cc.

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

◆ Neg()

static number Neg ( number  a,
const  coeffs 
)
static

Definition at line 175 of file flintcf_Q.cc.

176{
177 fmpq_poly_neg((fmpq_poly_ptr)a,(fmpq_poly_ptr)a);
178 return a;
179}

◆ nlEatLong()

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

Definition at line 29 of file flintcf_Q.cc.

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

◆ Normalize()

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

Definition at line 312 of file flintcf_Q.cc.

313{
314 fmpq_poly_canonicalise((fmpq_poly_ptr)a);
315}

◆ Parameter()

static number Parameter ( const int  ,
const  coeffs 
)
static

Definition at line 448 of file flintcf_Q.cc.

449{
450 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
451 fmpq_poly_init(res);
452 fmpq_poly_set_coeff_si(res,1,1);
453 return (number)res;
454}

◆ ParDeg()

static int ParDeg ( number  x,
const  coeffs 
)
static

Definition at line 444 of file flintcf_Q.cc.

445{
446 return fmpq_poly_degree((fmpq_poly_ptr)x);
447}
Variable x
Definition: cfModGcd.cc:4082

◆ Power()

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

Definition at line 355 of file flintcf_Q.cc.

356{
357 fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
358 fmpq_poly_init(res);
359 *result=(number)res;
360 fmpq_poly_pow((fmpq_poly_ptr)(*result),(fmpq_poly_ptr)a,i);
361}

◆ Read()

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

Definition at line 265 of file flintcf_Q.cc.

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

◆ ReadFd()

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

Definition at line 479 of file flintcf_Q.cc.

480{
481 // format: len a_len .. a_0
482 fmpq_poly_ptr aa=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
483 fmpq_poly_init(aa);
484 int l=s_readint(d->f_read);
485 mpz_t tmp;
486 mpz_init(tmp);
487 fmpq_t m;
488 fmpq_init(m);
489 fmpz_t num,den;
490 fmpz_init(num);
491 fmpz_init(den);
492 for (int i=l;i>=0;i--)
493 {
495 fmpz_set_mpz(num, tmp);
497 fmpz_set_mpz(den, tmp);
498 fmpq_set_fmpz_frac(m,num,den);
499 fmpq_poly_set_coeff_fmpq(aa,i,m);
500 }
501 mpz_clear(tmp);
502 fmpz_clear(den);
503 fmpz_clear(num);
504 fmpq_clear(m);
505 return (number)aa;
506}
#define SSI_BASE
Definition: auxiliary.h:135
CanonicalForm num(const CanonicalForm &f)
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 52 of file flintcf_Q.cc.

53{
54 // dummy
55}

◆ SetMap()

static nMapFunc SetMap ( const  coeffs,
const  coeffs 
)
static

Definition at line 409 of file flintcf_Q.cc.

410{
411 WerrorS("not yet: SetMap");
412 return NULL;
413}

◆ Size()

static int Size ( number  n,
const  coeffs 
)
static

Definition at line 138 of file flintcf_Q.cc.

139{
140 return fmpq_poly_degree((fmpq_poly_ptr)n);
141}

◆ Sub()

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

Definition at line 63 of file flintcf_Q.cc.

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

◆ WriteFd()

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

Definition at line 455 of file flintcf_Q.cc.

456{
457 // format: len a_len(num den) .. a_0
459 int l=fmpq_poly_length(aa);
460 fprintf(d->f_write,"%d ",l);
461 fmpq_t m;
462 fmpq_init(m);
463 mpz_t num,den;
464 mpz_init(num);
465 mpz_init(den);
466 for(int i=l; i>=0; i--)
467 {
468 fmpq_poly_get_coeff_fmpq(m,(fmpq_poly_ptr)a,i);
469 fmpq_get_mpz_frac(num,den,m);
470 mpz_out_str (d->f_write,SSI_BASE, num);
471 fputc(' ',d->f_write);
472 mpz_out_str (d->f_write,SSI_BASE, den);
473 fputc(' ',d->f_write);
474 }
475 mpz_clear(den);
476 mpz_clear(num);
477 fmpq_clear(m);
478}
FILE * f_write
Definition: s_buff.h:23

◆ WriteShort()

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

Definition at line 218 of file flintcf_Q.cc.

219{
220 //fmpq_poly_print_pretty((fmpq_poly_ptr)a,r->pParameterNames[0]);
221 if (IsOne(a,r)) StringAppendS("1");
222 else if (IsZero(a,r)) StringAppendS("0");
223 else
224 {
225 StringAppendS("(");
226 fmpq_t m;
227 fmpq_init(m);
228 BOOLEAN need_plus=FALSE;
229 for(int i=fmpq_poly_length((fmpq_poly_ptr)a);i>=0;i--)
230 {
231 fmpq_poly_get_coeff_fmpq(m,(fmpq_poly_ptr)a,i);
232 if (!fmpq_is_zero(m))
233 {
234 if (need_plus && (fmpq_cmp_ui(m,0)>0))
235 StringAppendS("+");
236 need_plus=TRUE;
237 int l=fmpz_sizeinbase(fmpq_numref(m),10);
238 l=si_max(l,(int)fmpz_sizeinbase(fmpq_denref(m),10));
239 l+=2;
240 char *s=(char*)omAlloc(l);
241 char *z=fmpz_get_str(s,10,fmpq_numref(m));
242 if ((i==0)
243 ||(fmpz_cmp_si(fmpq_numref(m),1)!=0)
244 ||(fmpz_cmp_si(fmpq_denref(m),1)!=0))
245 {
246 StringAppendS(z);
247 if (fmpz_cmp_si(fmpq_denref(m),1)!=0)
248 {
249 StringAppendS("/");
250 z=fmpz_get_str(s,10,fmpq_denref(m));
251 StringAppendS(z);
252 }
253 if (i!=0) StringAppendS("*");
254 }
255 if (i>1)
256 StringAppend("%s^%d",r->pParameterNames[0],i);
257 else if (i==1)
258 StringAppend("%s",r->pParameterNames[0]);
259 }
260 }
261 fmpq_clear(m);
262 StringAppendS(")");
263 }
264}
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