My Project  debian-1:4.1.2-p1+ds-2
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 *parameter)
 
static void SetChar (const coeffs r)
 
static number Mult (number a, number b, const coeffs c)
 
static number Sub (number a, number b, const coeffs c)
 
static number Add (number a, number b, const coeffs c)
 
static number Div (number a, number b, const coeffs c)
 
static number ExactDiv (number a, number b, const coeffs c)
 
static number IntMod (number a, number b, const coeffs c)
 
static number Init (long i, const coeffs r)
 
static number InitMPZ (mpz_t i, const coeffs r)
 
static int Size (number n, const coeffs r)
 
static long Int (number &n, const coeffs r)
 
static void MPZ (mpz_t result, number &n, const coeffs r)
 
static number Neg (number a, const coeffs r)
 
static number Invers (number a, const coeffs r)
 
static number Copy (number a, const coeffs r)
 
static BOOLEAN IsOne (number a, const coeffs r)
 
static BOOLEAN IsZero (number a, const coeffs r)
 
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 r)
 
static BOOLEAN Greater (number a, number b, const coeffs r)
 
static BOOLEAN Equal (number a, number b, const coeffs r)
 
static BOOLEAN IsMOne (number k, const coeffs r)
 
static BOOLEAN GreaterZero (number k, const coeffs r)
 
static void Power (number a, int i, number *result, const coeffs r)
 
static number GetDenom (number &n, const coeffs r)
 
static number GetNumerator (number &n, const coeffs r)
 
static number Gcd (number a, number b, const coeffs r)
 
static number ExtGcd (number a, number b, number *s, number *t, const coeffs r)
 
static number Lcm (number a, number b, const coeffs r)
 
static void Delete (number *a, const coeffs r)
 
static nMapFunc SetMap (const coeffs src, const coeffs dst)
 
static number Init_bigint (number i, const coeffs dummy, const coeffs dst)
 
static number Farey (number p, number n, const coeffs)
 
static number ChineseRemainder (number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs)
 
static int ParDeg (number x, const coeffs r)
 
static number Parameter (const int i, const coeffs r)
 
static void WriteFd (number a, const ssiInfo *d, const coeffs)
 
static number ReadFd (const ssiInfo *d, const coeffs)
 
static number ConvFactoryNSingN (const CanonicalForm n, const coeffs r)
 
static CanonicalForm ConvSingNFactoryN (number n, BOOLEAN setChar, const coeffs r)
 
char * CoeffName (const coeffs r)
 
static char * CoeffString (const coeffs r)
 
static void CoeffWrite (const coeffs r, BOOLEAN details)
 
coeffs flintQInitCfByName (char *s, n_coeffType n)
 
static BOOLEAN DBTest (number a, const char *f, const int l, const coeffs r)
 
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  c 
)
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:4044
CanonicalForm res
Definition: facAbsFact.cc:64
fmpq_poly_struct * fmpq_poly_ptr
Definition: flintcf_Q.cc:22
#define omAlloc(size)
Definition: omAllocDecl.h:210

◆ ChineseRemainder()

static number ChineseRemainder ( number *  x,
number *  q,
int  rl,
BOOLEAN  sym,
CFArray inv_cache,
const  coeffs 
)
static

Definition at line 444 of file flintcf_Q.cc.

445 {
446  WerrorS("not yet: ChineseRemainder");
447 }
void WerrorS(const char *s)
Definition: feFopen.cc:24

◆ CoeffIsEqual()

static BOOLEAN CoeffIsEqual ( const coeffs  r,
n_coeffType  n,
void *  parameter 
)
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 517 of file flintcf_Q.cc.

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

◆ CoeffString()

static char* CoeffString ( const coeffs  r)
static

Definition at line 524 of file flintcf_Q.cc.

525 {
526  char *buf=(char*)omAlloc(12+strlen(r->pParameterNames[0]));
527  sprintf(buf,"flintQ(\"%s\")",r->pParameterNames[0]);
528  return buf;
529 }
int status int void * buf
Definition: si_signals.h:59

◆ CoeffWrite()

static void CoeffWrite ( const coeffs  r,
BOOLEAN  details 
)
static

Definition at line 530 of file flintcf_Q.cc.

531 {
532  PrintS(CoeffName(r));
533 }
char * CoeffName(const coeffs r)
Definition: flintcf_Q.cc:517
void PrintS(const char *s)
Definition: reporter.cc:284

◆ ConvFactoryNSingN()

static number ConvFactoryNSingN ( const CanonicalForm  n,
const coeffs  r 
)
static

Definition at line 509 of file flintcf_Q.cc.

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

◆ ConvSingNFactoryN()

static CanonicalForm ConvSingNFactoryN ( number  n,
BOOLEAN  setChar,
const coeffs  r 
)
static

Definition at line 513 of file flintcf_Q.cc.

514 {
515  WerrorS("not yet: ConvSingNFactoryN");
516 }

◆ Copy()

static number Copy ( number  a,
const coeffs  r 
)
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  a,
const char *  f,
const int  l,
const coeffs  r 
)
static

Definition at line 552 of file flintcf_Q.cc.

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

◆ Delete()

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

Definition at line 408 of file flintcf_Q.cc.

409 {
410  if ((*a)!=NULL)
411  {
412  fmpq_poly_clear((fmpq_poly_ptr)*a);
413  omFree(*a);
414  *a=NULL;
415  }
416 }
#define omFree(addr)
Definition: omAllocDecl.h:261
#define NULL
Definition: omList.c:12

◆ Div()

static number Div ( number  a,
number  b,
const coeffs  c 
)
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 CanonicalForm mod(const CanonicalForm &, const CanonicalForm &)
Definition: cf_inline.cc:564
const char *const nDivBy0
Definition: numbers.h:88

◆ Equal()

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

Definition at line 322 of file flintcf_Q.cc.

323 {
324  return (fmpq_poly_equal((fmpq_poly_ptr)a,(fmpq_poly_ptr)b));
325 }

◆ ExactDiv()

static number ExactDiv ( number  a,
number  b,
const coeffs  c 
)
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  {
103  WerrorS(nDivBy0);
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  r 
)
static

Definition at line 395 of file flintcf_Q.cc.

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

◆ Farey()

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

Definition at line 440 of file flintcf_Q.cc.

441 {
442  WerrorS("not yet: Farey");
443 }

◆ flintQ_InitChar()

BOOLEAN flintQ_InitChar ( coeffs  cf,
void *  infoStruct 
)

Definition at line 562 of file flintcf_Q.cc.

563 {
564  char *pp=(char*)infoStruct;
565  cf->cfCoeffString = CoeffString;
566  cf->cfCoeffName = CoeffName;
567  cf->cfCoeffWrite = CoeffWrite;
568  cf->nCoeffIsEqual = CoeffIsEqual;
569  cf->cfKillChar = KillChar;
570  cf->cfSetChar = SetChar;
571  cf->ch=0; //char 0
572  cf->cfMult = Mult;
573  cf->cfSub = Sub;
574  cf->cfAdd = Add;
575  cf->cfDiv = Div;
576  cf->cfExactDiv = ExactDiv; // ???
577  cf->cfInit =Init;
578  cf->cfInitMPZ =InitMPZ;
579  cf->cfSize = Size;
580  cf->cfInt = Int;
581  cf->cfMPZ = MPZ;
582  cf->cfInpNeg = Neg;
583  cf->cfInvers = Invers;
584  cf->cfCopy = Copy;
585  cf->cfRePart = Copy;
586  // default: cf->cfImPart = ndReturn0;
587  cf->cfWriteLong = WriteShort; //WriteLong;
588  cf->cfWriteShort = WriteShort;
589  cf->cfRead = Read;
590  cf->cfNormalize = Normalize;
591 
592  //cf->cfDivComp=
593  //cf->cfIsUnit=
594  //cf->cfGetUnit=
595  //cf->cfDivBy=
596 
597  cf->cfGreater=Greater;
598  cf->cfEqual =Equal;
599  cf->cfIsZero =IsZero;
600  cf->cfIsOne =IsOne;
601  cf->cfIsMOne =IsMOne;
602  cf->cfGreaterZero=GreaterZero;
603 
604  cf->cfPower = Power;
605  cf->cfGetDenom = GetDenom;
606  cf->cfGetNumerator = GetNumerator;
607  cf->cfGcd = Gcd;
608  cf->cfExtGcd = ExtGcd;
609  cf->cfLcm = Lcm;
610  cf->cfDelete = Delete;
611  cf->cfSetMap = SetMap;
612  // default: cf->cfInpMult
613  // default: cf->cfInpAdd
614  cf->cfFarey =Farey;
615  cf->cfChineseRemainder=ChineseRemainder;
616  cf->cfParDeg = ParDeg;
617  cf->cfParameter = Parameter;
618  // cf->cfClearContent = ClearContent;
619  // cf->cfClearDenominators = ClearDenominators;
620  cf->convFactoryNSingN=ConvFactoryNSingN;
621  cf->convSingNFactoryN=ConvSingNFactoryN;
622  cf->cfWriteFd = WriteFd;
623  cf->cfReadFd = ReadFd;
624 #ifdef LDEBUG
625  cf->cfDBTest = DBTest;
626 #endif
627 
628  cf->iNumberOfParameters = 1;
629  char **pn=(char**)omAlloc0(sizeof(char*));
630  pn[0]=omStrDup(pp);
631  cf->pParameterNames = (const char **)pn;
632  cf->has_simple_Inverse= FALSE;
633  cf->has_simple_Alloc= FALSE;
634  cf->is_field=FALSE;
635 
636  return FALSE;
637 }
#define FALSE
Definition: auxiliary.h:96
CanonicalForm pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition: cf_gcd.cc:248
CanonicalForm cf
Definition: cfModGcd.cc:4024
static void WriteShort(number a, const coeffs r)
Definition: flintcf_Q.cc:218
static number Lcm(number a, number b, const coeffs r)
Definition: flintcf_Q.cc:404
static number ConvFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition: flintcf_Q.cc:509
static void MPZ(mpz_t result, number &n, const coeffs r)
Definition: flintcf_Q.cc:157
static number Neg(number a, const coeffs r)
Definition: flintcf_Q.cc:175
static BOOLEAN Greater(number a, number b, const coeffs r)
Definition: flintcf_Q.cc:318
static number Mult(number a, number b, const coeffs c)
Definition: flintcf_Q.cc:54
static number Sub(number a, number b, const coeffs c)
Definition: flintcf_Q.cc:61
static long Int(number &n, const coeffs r)
Definition: flintcf_Q.cc:134
static number GetDenom(number &n, const coeffs r)
Definition: flintcf_Q.cc:371
static number Init(long i, const coeffs r)
Definition: flintcf_Q.cc:116
static BOOLEAN CoeffIsEqual(const coeffs r, n_coeffType n, void *parameter)
Definition: flintcf_Q.cc:46
static void Normalize(number &a, const coeffs r)
Definition: flintcf_Q.cc:314
static number Gcd(number a, number b, const coeffs r)
Definition: flintcf_Q.cc:388
static char * CoeffString(const coeffs r)
Definition: flintcf_Q.cc:524
static number ExtGcd(number a, number b, number *s, number *t, const coeffs r)
Definition: flintcf_Q.cc:395
static void WriteFd(number a, const ssiInfo *d, const coeffs)
Definition: flintcf_Q.cc:459
static BOOLEAN GreaterZero(number k, const coeffs r)
Definition: flintcf_Q.cc:358
static BOOLEAN DBTest(number a, const char *f, const int l, const coeffs r)
Definition: flintcf_Q.cc:552
static void Delete(number *a, const coeffs r)
Definition: flintcf_Q.cc:408
static CanonicalForm ConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition: flintcf_Q.cc:513
static void KillChar(coeffs cf)
Definition: flintcf_Q.cc:557
static number Copy(number a, const coeffs r)
Definition: flintcf_Q.cc:200
static number GetNumerator(number &n, const coeffs r)
Definition: flintcf_Q.cc:379
static number ReadFd(const ssiInfo *d, const coeffs)
Definition: flintcf_Q.cc:484
static number InitMPZ(mpz_t i, const coeffs r)
Definition: flintcf_Q.cc:123
static number Div(number a, number b, const coeffs c)
Definition: flintcf_Q.cc:75
static void CoeffWrite(const coeffs r, BOOLEAN details)
Definition: flintcf_Q.cc:530
static void Power(number a, int i, number *result, const coeffs r)
Definition: flintcf_Q.cc:364
static BOOLEAN Equal(number a, number b, const coeffs r)
Definition: flintcf_Q.cc:322
static number Add(number a, number b, const coeffs c)
Definition: flintcf_Q.cc:68
static BOOLEAN IsOne(number a, const coeffs r)
Definition: flintcf_Q.cc:330
static number Farey(number p, number n, const coeffs)
Definition: flintcf_Q.cc:440
static BOOLEAN IsZero(number a, const coeffs r)
Definition: flintcf_Q.cc:326
static int ParDeg(number x, const coeffs r)
Definition: flintcf_Q.cc:448
static nMapFunc SetMap(const coeffs src, const coeffs dst)
Definition: flintcf_Q.cc:417
static number ChineseRemainder(number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs)
Definition: flintcf_Q.cc:444
static BOOLEAN IsMOne(number k, const coeffs r)
Definition: flintcf_Q.cc:334
static void SetChar(const coeffs r)
Definition: flintcf_Q.cc:50
static number Parameter(const int i, const coeffs r)
Definition: flintcf_Q.cc:452
static number Invers(number a, const coeffs r)
Definition: flintcf_Q.cc:180
static const char * Read(const char *st, number *a, const coeffs r)
Definition: flintcf_Q.cc:272
static int Size(number n, const coeffs r)
Definition: flintcf_Q.cc:130
static number ExactDiv(number a, number b, const coeffs c)
Definition: flintcf_Q.cc:97
#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 534 of file flintcf_Q.cc.

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

◆ Gcd()

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

Definition at line 388 of file flintcf_Q.cc.

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

◆ GetDenom()

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

Definition at line 371 of file flintcf_Q.cc.

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

◆ GetNumerator()

static number GetNumerator ( number &  n,
const coeffs  r 
)
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_set(res,(fmpq_poly_ptr)n);
384  fmpz_ptr den=fmpq_poly_denref(res);
385  fmpq_poly_scalar_mul_fmpz(res,res,den);
386  return (number)res;
387 }

◆ Greater()

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

Definition at line 318 of file flintcf_Q.cc.

319 {
320  return (fmpq_poly_cmp((fmpq_poly_ptr)a,(fmpq_poly_ptr)b)>0);
321 }

◆ GreaterZero()

static BOOLEAN GreaterZero ( number  k,
const coeffs  r 
)
static

Definition at line 358 of file flintcf_Q.cc.

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

◆ Init()

static number Init ( long  i,
const coeffs  r 
)
static

Definition at line 116 of file flintcf_Q.cc.

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

◆ Init_bigint()

static number Init_bigint ( number  i,
const coeffs  dummy,
const coeffs  dst 
)
static

Definition at line 428 of file flintcf_Q.cc.

429 {
430  fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
431  fmpq_poly_init(res);
432  if (SR_HDL(i) & SR_INT)
433  {
434  fmpq_poly_set_si(res,SR_TO_INT(i));
435  }
436  else
437  fmpq_poly_set_mpz(res,i->z);
438  return (number)res;
439 }
#define SR_INT
Definition: longrat.h:66
#define SR_TO_INT(SR)
Definition: longrat.h:68
#define SR_HDL(A)
Definition: tgb.cc:35

◆ InitMPZ()

static number InitMPZ ( mpz_t  i,
const coeffs  r 
)
static

Definition at line 123 of file flintcf_Q.cc.

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

◆ Int()

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

Definition at line 134 of file flintcf_Q.cc.

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

◆ IntMod()

static number IntMod ( number  a,
number  b,
const coeffs  c 
)
static

Definition at line 109 of file flintcf_Q.cc.

110 {
111  fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
112  fmpq_poly_init(res);
113  fmpq_poly_rem(res,(fmpq_poly_ptr)a,(fmpq_poly_ptr)b);
114  return (number)res;
115 }

◆ Invers()

static number Invers ( number  a,
const coeffs  r 
)
static

Definition at line 180 of file flintcf_Q.cc.

181 {
182  if(fmpq_poly_is_zero((fmpq_poly_ptr)a))
183  {
184  WerrorS(nDivBy0);
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  r 
)
static

Definition at line 334 of file flintcf_Q.cc.

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

◆ IsOne()

static BOOLEAN IsOne ( number  a,
const coeffs  r 
)
static

Definition at line 330 of file flintcf_Q.cc.

331 {
332  return fmpq_poly_is_one((fmpq_poly_ptr)a);
333 }

◆ IsZero()

static BOOLEAN IsZero ( number  a,
const coeffs  r 
)
static

Definition at line 326 of file flintcf_Q.cc.

327 {
328  return fmpq_poly_is_zero((fmpq_poly_ptr)a);
329 }

◆ KillChar()

static void KillChar ( coeffs  cf)
static

Definition at line 557 of file flintcf_Q.cc.

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

◆ Lcm()

static number Lcm ( number  a,
number  b,
const coeffs  r 
)
static

Definition at line 404 of file flintcf_Q.cc.

405 {
406  WerrorS("not yet: Lcm");
407 }

◆ MPZ()

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

Definition at line 157 of file flintcf_Q.cc.

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

◆ Mult()

static number Mult ( number  a,
number  b,
const coeffs  c 
)
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  r 
)
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 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  r 
)
static

Definition at line 314 of file flintcf_Q.cc.

315 {
316  fmpq_poly_canonicalise((fmpq_poly_ptr)a);
317 }

◆ Parameter()

static number Parameter ( const int  i,
const coeffs  r 
)
static

Definition at line 452 of file flintcf_Q.cc.

453 {
454  fmpq_poly_ptr res=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
455  fmpq_poly_init(res);
456  fmpq_poly_set_coeff_si(res,1,1);
457  return (number)res;
458 }

◆ ParDeg()

static int ParDeg ( number  x,
const coeffs  r 
)
static

Definition at line 448 of file flintcf_Q.cc.

449 {
450  return fmpq_poly_degree((fmpq_poly_ptr)x);
451 }
Variable x
Definition: cfModGcd.cc:4023

◆ Power()

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

Definition at line 364 of file flintcf_Q.cc.

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

◆ Read()

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

Definition at line 272 of file flintcf_Q.cc.

273 {
274 // we only read "monomials" (i.e. [-][digits][parameter]),
275 // everythings else (+,*,^,()) is left to the singular interpreter
276  char *s=(char *)st;
277  *a=(number)omAlloc(sizeof(fmpq_poly_t));
278  fmpq_poly_init((fmpq_poly_ptr)(*a));
279  BOOLEAN neg=FALSE;
280  if (*s=='-') { neg=TRUE; s++;}
281  if (isdigit(*s))
282  {
283  mpz_t z;
284  mpz_init(z);
285  s=nlEatLong((char *)s, z);
286  fmpq_poly_set_mpz((fmpq_poly_ptr)(*a),z);
287  if (*s == '/')
288  {
289  s++;
290  s=nlEatLong((char *)s, z);
291  fmpq_poly_scalar_div_mpz((fmpq_poly_ptr)(*a),(fmpq_poly_ptr)(*a),z);
292  }
293  mpz_clear(z);
294  }
295  else if(strncmp(s,r->pParameterNames[0],strlen(r->pParameterNames[0]))==0)
296  {
297  fmpq_poly_set_coeff_si((fmpq_poly_ptr)(*a),1,1);
298  s+=strlen(r->pParameterNames[0]);
299  if(isdigit(*s))
300  {
301  int i=1;
302  s=nEati(s,&i,0);
303  if (i!=1)
304  {
305  fmpq_poly_set_coeff_si((fmpq_poly_ptr)(*a),1,0);
306  fmpq_poly_set_coeff_si((fmpq_poly_ptr)(*a),i,1);
307  }
308  }
309  }
310  if (neg)
311  fmpq_poly_neg((fmpq_poly_ptr)(*a),(fmpq_poly_ptr)(*a));
312  return s;
313 }
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:630

◆ ReadFd()

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

Definition at line 484 of file flintcf_Q.cc.

485 {
486  // format: len a_len .. a_0
487  fmpq_poly_ptr aa=(fmpq_poly_ptr)omAlloc(sizeof(fmpq_poly_t));
488  fmpq_poly_init(aa);
489  int l=s_readint(d->f_read);
490  mpz_t nm;
491  mpz_init(nm);
492  mpq_t m;
493  mpq_init(m);
494  for (int i=l;i>=0;i--)
495  {
496 
497  s_readmpz_base (d->f_read,nm, SSI_BASE);
498  mpq_set_num(m,nm);
499  s_readmpz_base (d->f_read,nm, SSI_BASE);
500  mpq_set_den(m,nm);
501  fmpq_poly_set_coeff_mpq(aa,i,m);
502  }
503  mpz_clear(nm);
504  mpq_clear(m);
505  return (number)aa;
506 }
#define SSI_BASE
Definition: auxiliary.h:151
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  r)
static

Definition at line 50 of file flintcf_Q.cc.

51 {
52  // dummy
53 }

◆ SetMap()

static nMapFunc SetMap ( const coeffs  src,
const coeffs  dst 
)
static

Definition at line 417 of file flintcf_Q.cc.

418 {
419  WerrorS("not yet: SetMap");
420  return NULL;
421 }

◆ Size()

static int Size ( number  n,
const coeffs  r 
)
static

Definition at line 130 of file flintcf_Q.cc.

131 {
132  return fmpq_poly_degree((fmpq_poly_ptr)n);
133 }

◆ Sub()

static number Sub ( number  a,
number  b,
const coeffs  c 
)
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 459 of file flintcf_Q.cc.

460 {
461  // format: len a_len(num den) .. a_0
463  int l=fmpq_poly_length(aa);
464  fprintf(d->f_write,"%d ",l);
465  mpq_t m;
466  mpq_init(m);
467  mpz_t num,den;
468  mpz_init(num);
469  mpz_init(den);
470  for(int i=l; i>=0; i--)
471  {
472  fmpq_poly_get_coeff_mpq(m,(fmpq_poly_ptr)a,i);
473  mpq_get_num(num,m);
474  mpq_get_den(den,m);
475  mpz_out_str (d->f_write,SSI_BASE, num);
476  fputc(' ',d->f_write);
477  mpz_out_str (d->f_write,SSI_BASE, den);
478  fputc(' ',d->f_write);
479  }
480  mpz_clear(den);
481  mpz_clear(num);
482  mpq_clear(m);
483 }
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  mpq_t m;
227  mpq_init(m);
228  mpz_t num,den;
229  mpz_init(num);
230  mpz_init(den);
231  BOOLEAN need_plus=FALSE;
232  for(int i=fmpq_poly_length((fmpq_poly_ptr)a);i>=0;i--)
233  {
234  fmpq_poly_get_coeff_mpq(m,(fmpq_poly_ptr)a,i);
235  mpq_get_num(num,m);
236  mpq_get_den(den,m);
237  if (mpz_sgn1(num)!=0)
238  {
239  if (need_plus && (mpz_sgn1(num)>0))
240  StringAppendS("+");
241  need_plus=TRUE;
242  int l=mpz_sizeinbase(num,10);
243  l=si_max(l,(int)mpz_sizeinbase(den,10));
244  l+=2;
245  char *s=(char*)omAlloc(l);
246  char *z=mpz_get_str(s,10,num);
247  if ((i==0)
248  ||(mpz_cmp_si(num,1)!=0)
249  ||(mpz_cmp_si(den,1)!=0))
250  {
251  StringAppendS(z);
252  if (mpz_cmp_si(den,1)!=0)
253  {
254  StringAppendS("/");
255  z=mpz_get_str(s,10,den);
256  StringAppendS(z);
257  }
258  if (i!=0) StringAppendS("*");
259  }
260  if (i>1)
261  StringAppend("%s^%d",r->pParameterNames[0],i);
262  else if (i==1)
263  StringAppend("%s",r->pParameterNames[0]);
264  }
265  }
266  mpz_clear(den);
267  mpz_clear(num);
268  mpq_clear(m);
269  StringAppendS(")");
270  }
271 }
static int si_max(const int a, const int b)
Definition: auxiliary.h:140
#define StringAppend
Definition: emacs.cc:79
void StringAppendS(const char *st)
Definition: reporter.cc:107
#define mpz_sgn1(A)
Definition: si_gmp.h:13