My Project  UNKNOWN_GIT_VERSION
Typedefs | Functions
flintcf_Zn.cc File Reference
#include <ctype.h>
#include "misc/auxiliary.h"
#include <flint/flint.h>
#include <flint/nmod_poly.h>
#include "factory/factory.h"
#include "omalloc/omalloc.h"
#include "coeffs/coeffs.h"
#include "coeffs/numbers.h"
#include "coeffs/longrat.h"
#include "coeffs/modulop.h"
#include "coeffs/flintcf_Zn.h"

Go to the source code of this file.

Typedefs

typedef nmod_poly_struct * nmod_poly_ptr
 

Functions

static const char * Eati (const char *s, int *i)
 
static void CoeffWrite (const coeffs r, BOOLEAN details)
 
static BOOLEAN CoeffIsEqual (const coeffs r, n_coeffType n, void *parameter)
 
static void KillChar (coeffs cf)
 
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 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 number ConvFactoryNSingN (const CanonicalForm n, const coeffs r)
 
static CanonicalForm ConvSingNFactoryN (number n, BOOLEAN setChar, const coeffs r)
 
static char * CoeffName (const coeffs r)
 
static char * CoeffString (const coeffs r)
 
coeffs flintZnInitCfByName (char *s, n_coeffType n)
 
static void WriteFd (number a, const ssiInfo *d, const coeffs)
 
static number ReadFd (const ssiInfo *d, const coeffs r)
 
static BOOLEAN DBTest (number a, const char *f, const int l, const coeffs r)
 
BOOLEAN flintZn_InitChar (coeffs cf, void *infoStruct)
 

Typedef Documentation

◆ nmod_poly_ptr

typedef nmod_poly_struct* nmod_poly_ptr

Definition at line 25 of file flintcf_Zn.cc.

Function Documentation

◆ Add()

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

Definition at line 83 of file flintcf_Zn.cc.

84 {
85  nmod_poly_ptr res=(nmod_poly_ptr)omAlloc(sizeof(nmod_poly_t));
86  nmod_poly_init(res,c->ch);
87  nmod_poly_add(res,(nmod_poly_ptr)a,(nmod_poly_ptr)b);
88  return (number)res;
89 }
CanonicalForm b
Definition: cfModGcd.cc:4044
CanonicalForm res
Definition: facAbsFact.cc:64
nmod_poly_init(FLINTmipo, getCharacteristic())
nmod_poly_struct * nmod_poly_ptr
Definition: flintcf_Zn.cc:25
#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 398 of file flintcf_Zn.cc.

399 {
400  WerrorS("not yet: ChineseRemainder");
401 }
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 53 of file flintcf_Zn.cc.

54 {
55  flintZn_struct *pp=(flintZn_struct*)parameter;
56  return (r->type==n) &&(r->ch==pp->ch)
57  &&(r->pParameterNames!=NULL)
58  &&(strcmp(r->pParameterNames[0],pp->name)==0);
59 }
CanonicalForm pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition: cf_gcd.cc:248
#define NULL
Definition: omList.c:10

◆ CoeffName()

static char* CoeffName ( const coeffs  r)
static

Definition at line 422 of file flintcf_Zn.cc.

423 {
424  static char CoeffName_flint_Zn[20];
425  sprintf(CoeffName_flint_Zn,"flint:Z/%d[%s]",r->ch,r->pParameterNames[0]);
426  return (char*)CoeffName_flint_Zn;
427 }

◆ CoeffString()

static char* CoeffString ( const coeffs  r)
static

Definition at line 428 of file flintcf_Zn.cc.

429 {
430  char *buf=(char*)omAlloc(12+10 /*ch*/+strlen(r->pParameterNames[0]));
431  sprintf(buf,"flintZn(%d,\"%s\")",r->ch,r->pParameterNames[0]);
432  return buf;
433 }
int status int void * buf
Definition: si_signals.h:59

◆ CoeffWrite()

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

Definition at line 48 of file flintcf_Zn.cc.

49 {
50  Print("flint:Z/%d[%s]",r->ch,r->pParameterNames[0]);
51 }
#define Print
Definition: emacs.cc:80

◆ ConvFactoryNSingN()

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

Definition at line 415 of file flintcf_Zn.cc.

416 {
417 }

◆ ConvSingNFactoryN()

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

Definition at line 418 of file flintcf_Zn.cc.

419 {
420  WerrorS("not yet: ConvSingNFactoryN");
421 }

◆ Copy()

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

Definition at line 203 of file flintcf_Zn.cc.

204 {
205  nmod_poly_ptr res=(nmod_poly_ptr)omAlloc(sizeof(nmod_poly_t));
206  nmod_poly_init(res,r->ch);
207  nmod_poly_set(res,(nmod_poly_ptr)a);
208  return (number)res;
209 }

◆ DBTest()

static BOOLEAN DBTest ( number  a,
const char *  f,
const int  l,
const coeffs  r 
)
static

Definition at line 483 of file flintcf_Zn.cc.

484 {
485  return TRUE;
486 }
#define TRUE
Definition: auxiliary.h:98

◆ Delete()

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

Definition at line 354 of file flintcf_Zn.cc.

355 {
356  if ((*a)!=NULL)
357  {
359  omFree(*a);
360  *a=NULL;
361  }
362 }
nmod_poly_clear(FLINTmipo)
#define omFree(addr)
Definition: omAllocDecl.h:261

◆ Div()

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

Definition at line 90 of file flintcf_Zn.cc.

91 {
92  nmod_poly_ptr res=(nmod_poly_ptr)omAlloc(sizeof(nmod_poly_t));
93  nmod_poly_init(res,c->ch);
94  if(nmod_poly_is_zero((nmod_poly_ptr)b))
95  {
97  }
98  else
99  {
100  nmod_poly_div(res,(nmod_poly_ptr)a,(nmod_poly_ptr)b);
101  nmod_poly_t mod;
102  nmod_poly_init(mod,c->ch);
103  nmod_poly_rem(mod,(nmod_poly_ptr)a,(nmod_poly_ptr)b);
104  if (!nmod_poly_is_zero((nmod_poly_ptr)mod))
105  {
106  WerrorS("cannot divide");
107  }
109  }
110  return (number)res;
111 }
CF_NO_INLINE CanonicalForm mod(const CanonicalForm &, const CanonicalForm &)
Definition: cf_inline.cc:564
const char *const nDivBy0
Definition: numbers.h:89

◆ Eati()

static const char* Eati ( const char *  s,
int *  i 
)
static

Definition at line 30 of file flintcf_Zn.cc.

31 {
32 
33  if (((*s) >= '0') && ((*s) <= '9'))
34  {
35  unsigned long ii=0L;
36  do
37  {
38  ii *= 10;
39  ii += *s++ - '0';
40  }
41  while (((*s) >= '0') && ((*s) <= '9'));
42  *i=(int)ii;
43  }
44  else (*i) = 1;
45  return s;
46 }
int i
Definition: cfEzgcd.cc:125
const CanonicalForm int s
Definition: facAbsFact.cc:55

◆ Equal()

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

Definition at line 303 of file flintcf_Zn.cc.

304 {
305  return (nmod_poly_equal((nmod_poly_ptr)a,(nmod_poly_ptr)b));
306 }

◆ ExactDiv()

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

Definition at line 112 of file flintcf_Zn.cc.

113 {
114  nmod_poly_ptr res=(nmod_poly_ptr)omAlloc(sizeof(nmod_poly_t));
115  nmod_poly_init(res,c->ch);
116  if(nmod_poly_is_zero((nmod_poly_ptr)b))
117  {
118  WerrorS(nDivBy0);
119  }
120  else
121  nmod_poly_div(res,(nmod_poly_ptr)a,(nmod_poly_ptr)b);
122  return (number)res;
123 }

◆ ExtGcd()

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

Definition at line 341 of file flintcf_Zn.cc.

342 {
343  nmod_poly_ptr res=(nmod_poly_ptr)omAlloc(sizeof(nmod_poly_t));
344  nmod_poly_init(res,r->ch);
345  nmod_poly_init((nmod_poly_ptr)*s,r->ch);
346  nmod_poly_init((nmod_poly_ptr)*t,r->ch);
347  nmod_poly_xgcd(res,(nmod_poly_ptr)*s,(nmod_poly_ptr)*t,(nmod_poly_ptr)a,(nmod_poly_ptr)b);
348  return (number)res;
349 }

◆ Farey()

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

Definition at line 394 of file flintcf_Zn.cc.

395 {
396  WerrorS("not yet: Farey");
397 }

◆ flintZn_InitChar()

BOOLEAN flintZn_InitChar ( coeffs  cf,
void *  infoStruct 
)

Definition at line 488 of file flintcf_Zn.cc.

489 {
490  flintZn_struct *pp=(flintZn_struct*)infoStruct;
491  cf->ch=pp->ch;
492 
493  cf->cfCoeffString = CoeffString;
494  cf->cfCoeffName = CoeffName;
495  cf->cfCoeffWrite = CoeffWrite;
496  cf->nCoeffIsEqual = CoeffIsEqual;
497  cf->cfKillChar = KillChar;
498  cf->cfSetChar = SetChar;
499  cf->cfMult = Mult;
500  cf->cfSub = Sub;
501  cf->cfAdd = Add;
502  cf->cfDiv = Div;
503  cf->cfExactDiv = ExactDiv; // ???
504  cf->cfInit = Init;
505  cf->cfInitMPZ = InitMPZ;
506  cf->cfSize = Size;
507  cf->cfInt = Int;
508  cf->cfMPZ = MPZ;
509  cf->cfInpNeg = Neg;
510  cf->cfInvers = Invers;
511  cf->cfCopy = Copy;
512  cf->cfRePart = Copy;
513  // default: cf->cfImPart = ndReturn0;
514  cf->cfWriteLong = WriteShort; //WriteLong;
515  cf->cfWriteShort = WriteShort;
516  cf->cfRead = Read;
517  cf->cfNormalize = Normalize;
518 
519  //cf->cfDivComp=
520  //cf->cfIsUnit=
521  //cf->cfGetUnit=
522  //cf->cfDivBy=
523 
524  cf->cfGreater=Greater;
525  cf->cfEqual =Equal;
526  cf->cfIsZero =IsZero;
527  cf->cfIsOne =IsOne;
528  cf->cfIsMOne =IsMOne;
529  cf->cfGreaterZero=GreaterZero;
530 
531  cf->cfPower = Power;
532  //default: cf->cfGetDenom = GetDenom;
533  //default: cf->cfGetNumerator = GetNumerator;
534  cf->cfGcd = Gcd;
535  cf->cfExtGcd = ExtGcd;
536  cf->cfLcm = Lcm;
537  cf->cfDelete = Delete;
538  cf->cfSetMap = SetMap;
539  // default: cf->cfInpMult
540  // default: cf->cfInpAdd
541  cf->cfFarey =Farey;
542  cf->cfChineseRemainder=ChineseRemainder;
543  cf->cfParDeg = ParDeg;
544  cf->cfParameter = Parameter;
545  // cf->cfClearContent = ClearContent;
546  // cf->cfClearDenominators = ClearDenominators;
547  cf->convFactoryNSingN=ConvFactoryNSingN;
548  cf->convSingNFactoryN=ConvSingNFactoryN;
549  cf->cfWriteFd = WriteFd;
550  cf->cfReadFd = ReadFd;
551 #ifdef LDEBUG
552  cf->cfDBTest = DBTest;
553 #endif
554 
555  cf->iNumberOfParameters = 1;
556  char **pn=(char**)omAlloc0(sizeof(char*));
557  pn[0]=(char*)omStrDup(pp->name);
558  cf->pParameterNames = (const char **)pn;
559  cf->has_simple_Inverse= FALSE;
560  cf->has_simple_Alloc= FALSE;
561  cf->is_field=FALSE;
562 
563  return FALSE;
564 }
#define FALSE
Definition: auxiliary.h:94
CanonicalForm cf
Definition: cfModGcd.cc:4024
static void WriteShort(number a, const coeffs r)
Definition: flintcf_Zn.cc:221
static number Lcm(number a, number b, const coeffs r)
Definition: flintcf_Zn.cc:350
static number ConvFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition: flintcf_Zn.cc:415
static void MPZ(mpz_t result, number &n, const coeffs r)
Definition: flintcf_Zn.cc:165
static number Neg(number a, const coeffs r)
Definition: flintcf_Zn.cc:175
static BOOLEAN Greater(number a, number b, const coeffs r)
Definition: flintcf_Zn.cc:288
static number Mult(number a, number b, const coeffs c)
Definition: flintcf_Zn.cc:69
static number Sub(number a, number b, const coeffs c)
Definition: flintcf_Zn.cc:76
static long Int(number &n, const coeffs r)
Definition: flintcf_Zn.cc:155
static number Init(long i, const coeffs r)
Definition: flintcf_Zn.cc:131
static BOOLEAN CoeffIsEqual(const coeffs r, n_coeffType n, void *parameter)
Definition: flintcf_Zn.cc:53
static void Normalize(number &a, const coeffs r)
Definition: flintcf_Zn.cc:285
static number Gcd(number a, number b, const coeffs r)
Definition: flintcf_Zn.cc:334
static char * CoeffString(const coeffs r)
Definition: flintcf_Zn.cc:428
static number ExtGcd(number a, number b, number *s, number *t, const coeffs r)
Definition: flintcf_Zn.cc:341
static void WriteFd(number a, const ssiInfo *d, const coeffs)
Definition: flintcf_Zn.cc:455
static BOOLEAN GreaterZero(number k, const coeffs r)
Definition: flintcf_Zn.cc:321
static BOOLEAN DBTest(number a, const char *f, const int l, const coeffs r)
Definition: flintcf_Zn.cc:483
static void Delete(number *a, const coeffs r)
Definition: flintcf_Zn.cc:354
static number ReadFd(const ssiInfo *d, const coeffs r)
Definition: flintcf_Zn.cc:468
static CanonicalForm ConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition: flintcf_Zn.cc:418
static void KillChar(coeffs cf)
Definition: flintcf_Zn.cc:60
static number Copy(number a, const coeffs r)
Definition: flintcf_Zn.cc:203
static number InitMPZ(mpz_t i, const coeffs r)
Definition: flintcf_Zn.cc:140
static number Div(number a, number b, const coeffs c)
Definition: flintcf_Zn.cc:90
static void CoeffWrite(const coeffs r, BOOLEAN details)
Definition: flintcf_Zn.cc:48
static void Power(number a, int i, number *result, const coeffs r)
Definition: flintcf_Zn.cc:327
static BOOLEAN Equal(number a, number b, const coeffs r)
Definition: flintcf_Zn.cc:303
static number Add(number a, number b, const coeffs c)
Definition: flintcf_Zn.cc:83
static BOOLEAN IsOne(number a, const coeffs r)
Definition: flintcf_Zn.cc:311
static number Farey(number p, number n, const coeffs)
Definition: flintcf_Zn.cc:394
static BOOLEAN IsZero(number a, const coeffs r)
Definition: flintcf_Zn.cc:307
static int ParDeg(number x, const coeffs r)
Definition: flintcf_Zn.cc:402
static nMapFunc SetMap(const coeffs src, const coeffs dst)
Definition: flintcf_Zn.cc:363
static number ChineseRemainder(number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs)
Definition: flintcf_Zn.cc:398
static BOOLEAN IsMOne(number k, const coeffs r)
Definition: flintcf_Zn.cc:315
static void SetChar(const coeffs r)
Definition: flintcf_Zn.cc:65
static number Parameter(const int i, const coeffs r)
Definition: flintcf_Zn.cc:406
static number Invers(number a, const coeffs r)
Definition: flintcf_Zn.cc:180
static char * CoeffName(const coeffs r)
Definition: flintcf_Zn.cc:422
static const char * Read(const char *st, number *a, const coeffs r)
Definition: flintcf_Zn.cc:251
static int Size(number n, const coeffs r)
Definition: flintcf_Zn.cc:151
static number ExactDiv(number a, number b, const coeffs c)
Definition: flintcf_Zn.cc:112
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define omAlloc0(size)
Definition: omAllocDecl.h:211

◆ flintZnInitCfByName()

coeffs flintZnInitCfByName ( char *  s,
n_coeffType  n 
)

Definition at line 434 of file flintcf_Zn.cc.

435 {
436  const char start[]="flint:Z/";
437  const int start_len=strlen(start);
438  if (strncmp(s,start,start_len)==0)
439  {
440  s+=start_len;
441  int p;
442  char st[10];
443  int l=sscanf(s,"%d[%s",&p,st);
444  if (l==2)
445  {
447  info.ch=p;
448  while (st[strlen(st)-1]==']') st[strlen(st)-1]='\0';
449  info.name=st;
450  return nInitChar(n,(void*)&info);
451  }
452  }
453  return NULL;
454 }
int l
Definition: cfEzgcd.cc:93
int p
Definition: cfModGcd.cc:4019
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:350
const ExtensionInfo & info
< [in] sqrfree poly

◆ Gcd()

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

Definition at line 334 of file flintcf_Zn.cc.

335 {
336  nmod_poly_ptr res=(nmod_poly_ptr)omAlloc(sizeof(nmod_poly_t));
337  nmod_poly_init(res,r->ch);
338  nmod_poly_gcd(res,(nmod_poly_ptr)a,(nmod_poly_ptr)b);
339  return (number)res;
340 }

◆ Greater()

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

Definition at line 288 of file flintcf_Zn.cc.

289 {
290  if (nmod_poly_length((nmod_poly_ptr)a)>nmod_poly_length((nmod_poly_ptr)b))
291  return TRUE;
292  else if (nmod_poly_length((nmod_poly_ptr)a)<nmod_poly_length((nmod_poly_ptr)b))
293  return FALSE;
294  for(int i=nmod_poly_length((nmod_poly_ptr)a);i>=0;i--)
295  {
296  slong ac=nmod_poly_get_coeff_ui((nmod_poly_ptr)a,i);
297  slong bc=nmod_poly_get_coeff_ui((nmod_poly_ptr)b,i);
298  if (ac>bc) return TRUE;
299  else if (ac<bc) return FALSE;
300  }
301  return FALSE;
302 }
#define slong

◆ GreaterZero()

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

Definition at line 321 of file flintcf_Zn.cc.

322 {
323  // does it have a leading sign?
324  // no: 0 and 1 do not have, everything else is in (...)
325  return TRUE;
326 }

◆ Init()

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

Definition at line 131 of file flintcf_Zn.cc.

132 {
133  nmod_poly_ptr res=(nmod_poly_ptr)omAlloc(sizeof(nmod_poly_t));
134  nmod_poly_init(res,r->ch);
135  i= i%r->ch;
136  if (i<0) i+=r->ch;
137  nmod_poly_set_coeff_ui(res,0,i);
138  return (number)res;
139 }

◆ Init_bigint()

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

Definition at line 374 of file flintcf_Zn.cc.

375 {
376  nmod_poly_ptr res=(nmod_poly_ptr)omAlloc(sizeof(nmod_poly_t));
377  nmod_poly_init(res,dst->ch);
378  long ii;
379  if (SR_HDL(i) & SR_INT)
380  {
381  ii=SR_TO_INT(i) % dst->ch;
382  }
383  else
384  {
385  mpz_t tmp;
386  mpz_init(tmp);
387  ii=mpz_mod_ui(tmp,i->z,dst->ch);
388  mpz_clear(tmp);
389  }
390  if (ii<0) ii+=dst->ch;
391  nmod_poly_set_coeff_ui(res,0,ii);
392  return (number)res;
393 }
#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 140 of file flintcf_Zn.cc.

141 {
142  nmod_poly_ptr res=(nmod_poly_ptr)omAlloc(sizeof(nmod_poly_t));
143  nmod_poly_init(res,r->ch);
144  mpz_t tmp;
145  mpz_init(tmp);
146  slong ii=mpz_mod_ui(tmp,i,r->ch);
147  mpz_clear(tmp);
148  nmod_poly_set_coeff_ui(res,0,ii);
149  return (number)res;
150 }

◆ Int()

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

Definition at line 155 of file flintcf_Zn.cc.

156 {
157  if (nmod_poly_degree((nmod_poly_ptr)n)==0)
158  {
159  slong m;
160  m=nmod_poly_get_coeff_ui((nmod_poly_ptr)n,0);
161  return (long)m;
162  }
163  return 0;
164 }
int m
Definition: cfEzgcd.cc:121

◆ IntMod()

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

Definition at line 124 of file flintcf_Zn.cc.

125 {
126  nmod_poly_ptr res=(nmod_poly_ptr)omAlloc(sizeof(nmod_poly_t));
127  nmod_poly_init(res,c->ch);
128  nmod_poly_rem(res,(nmod_poly_ptr)a,(nmod_poly_ptr)b);
129  return (number)res;
130 }

◆ Invers()

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

Definition at line 180 of file flintcf_Zn.cc.

181 {
182  if(nmod_poly_is_zero((nmod_poly_ptr)a))
183  {
184  WerrorS(nDivBy0);
185  return NULL;
186  }
187  if (nmod_poly_degree((nmod_poly_ptr)a)==0)
188  {
189  nmod_poly_ptr res=(nmod_poly_ptr)omAlloc(sizeof(nmod_poly_t));
190  nmod_poly_init(res,r->ch);
191  slong c=nmod_poly_get_coeff_ui((nmod_poly_ptr)a,0);
192  extern number nvInvers (number c, const coeffs r);
193  c=(slong)nvInvers((number)c,r);
194  nmod_poly_set_coeff_ui((nmod_poly_ptr)a,0,c);
195  return (number)res;
196  }
197  else
198  {
199  WerrorS("not invertable");
200  return NULL;
201  }
202 }
number nvInvers(number c, const coeffs r)
Definition: modulop.cc:737
The main handler for Singular numbers which are suitable for Singular polynomials.

◆ IsMOne()

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

Definition at line 315 of file flintcf_Zn.cc.

316 {
317  if (nmod_poly_length((nmod_poly_ptr)k)>0) return FALSE;
318  slong m=nmod_poly_get_coeff_ui((nmod_poly_ptr)k,0);
319  return (m+1==r->ch);
320 }
int k
Definition: cfEzgcd.cc:92

◆ IsOne()

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

Definition at line 311 of file flintcf_Zn.cc.

312 {
313  return nmod_poly_is_one((nmod_poly_ptr)a);
314 }

◆ IsZero()

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

Definition at line 307 of file flintcf_Zn.cc.

308 {
309  return nmod_poly_is_zero((nmod_poly_ptr)a);
310 }

◆ KillChar()

static void KillChar ( coeffs  cf)
static

Definition at line 60 of file flintcf_Zn.cc.

61 {
62  omFree((ADDRESS)(cf->pParameterNames[0]));
63  omFreeSize(cf->pParameterNames,sizeof(char*));
64 }
void * ADDRESS
Definition: auxiliary.h:133
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260

◆ Lcm()

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

Definition at line 350 of file flintcf_Zn.cc.

351 {
352  WerrorS("not yet: Lcm");
353 }

◆ MPZ()

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

Definition at line 165 of file flintcf_Zn.cc.

166 {
167  mpz_init(result);
168  if (nmod_poly_degree((nmod_poly_ptr)n)==0)
169  {
170  slong m;
171  m=nmod_poly_get_coeff_ui((nmod_poly_ptr)n,0);
172  mpz_set_ui(result,m);
173  }
174 }
return result
Definition: facAbsBiFact.cc:76

◆ Mult()

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

Definition at line 69 of file flintcf_Zn.cc.

70 {
72  nmod_poly_init(res,c->ch);
73  nmod_poly_mul(res,(nmod_poly_ptr)a,(nmod_poly_ptr)b);
74  return (number)res;
75 }

◆ Neg()

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

Definition at line 175 of file flintcf_Zn.cc.

176 {
177  nmod_poly_neg((nmod_poly_ptr)a,(nmod_poly_ptr)a);
178  return a;
179 }

◆ Normalize()

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

Definition at line 285 of file flintcf_Zn.cc.

286 {
287 }

◆ Parameter()

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

Definition at line 406 of file flintcf_Zn.cc.

407 {
408  nmod_poly_ptr res=(nmod_poly_ptr)omAlloc(sizeof(nmod_poly_t));
409  nmod_poly_init(res,r->ch);
410  nmod_poly_set_coeff_ui(res,1,1);
411  return (number)res;
412 }

◆ ParDeg()

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

Definition at line 402 of file flintcf_Zn.cc.

403 {
404  return nmod_poly_degree((nmod_poly_ptr)x);
405 }
Variable x
Definition: cfModGcd.cc:4023

◆ Power()

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

Definition at line 327 of file flintcf_Zn.cc.

328 {
329  nmod_poly_ptr res=(nmod_poly_ptr)omAlloc(sizeof(nmod_poly_t));
330  nmod_poly_init(res,r->ch);
331  *result=(number)res;
332  nmod_poly_pow((nmod_poly_ptr)(*result),(nmod_poly_ptr)a,i);
333 }

◆ Read()

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

Definition at line 251 of file flintcf_Zn.cc.

252 {
253 // we only read "monomials" (i.e. [-][digits][parameter]),
254 // everythings else (+,*,^,()) is left to the singular interpreter
255  const char *s=st;
256  *a=(number)omAlloc(sizeof(nmod_poly_t));
257  nmod_poly_init((nmod_poly_ptr)(*a),r->ch);
258  BOOLEAN neg=FALSE;
259  if (*s=='-') { neg=TRUE; s++;}
260  if (isdigit(*s))
261  {
262  int z;
263  s=Eati((char *)s, &z);
264  nmod_poly_set_coeff_ui((nmod_poly_ptr)(*a),0,z);
265  }
266  else if(strncmp(s,r->pParameterNames[0],strlen(r->pParameterNames[0]))==0)
267  {
268  nmod_poly_set_coeff_ui((nmod_poly_ptr)(*a),1,1);
269  s+=strlen(r->pParameterNames[0]);
270  if(isdigit(*s))
271  {
272  int i=1;
273  s=Eati(s,&i);
274  if (i!=1)
275  {
276  nmod_poly_set_coeff_ui((nmod_poly_ptr)(*a),1,0);
277  nmod_poly_set_coeff_ui((nmod_poly_ptr)(*a),i,1);
278  }
279  }
280  }
281  if (neg)
282  nmod_poly_neg((nmod_poly_ptr)(*a),(nmod_poly_ptr)(*a));
283  return s;
284 }
int BOOLEAN
Definition: auxiliary.h:85
static const char * Eati(const char *s, int *i)
Definition: flintcf_Zn.cc:30

◆ ReadFd()

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

Definition at line 468 of file flintcf_Zn.cc.

469 {
470  // format: len a_len .. a_0
471  nmod_poly_ptr aa=(nmod_poly_ptr)omAlloc(sizeof(nmod_poly_t));
472  nmod_poly_init(aa,r->ch);
473  int l=s_readint(d->f_read);
474  unsigned long ul;
475  for (int i=l;i>=0;i--)
476  {
477  unsigned long ul=s_readlong(d->f_read);
478  nmod_poly_set_coeff_ui(aa,i,ul);
479  }
480  return (number)aa;
481 }
int s_readint(s_buff F)
Definition: s_buff.cc:110
long s_readlong(s_buff F)
Definition: s_buff.cc:138
s_buff f_read
Definition: s_buff.h:22

◆ SetChar()

static void SetChar ( const coeffs  r)
static

Definition at line 65 of file flintcf_Zn.cc.

66 {
67  // dummy
68 }

◆ SetMap()

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

Definition at line 363 of file flintcf_Zn.cc.

364 {
365  WerrorS("not yet: SetMap");
366  return NULL;
367 }

◆ Size()

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

Definition at line 151 of file flintcf_Zn.cc.

152 {
153  return nmod_poly_degree((nmod_poly_ptr)n);
154 }

◆ Sub()

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

Definition at line 76 of file flintcf_Zn.cc.

77 {
78  nmod_poly_ptr res=(nmod_poly_ptr)omAlloc(sizeof(nmod_poly_t));
79  nmod_poly_init(res,c->ch);
80  nmod_poly_sub(res,(nmod_poly_ptr)a,(nmod_poly_ptr)b);
81  return (number)res;
82 }

◆ WriteFd()

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

Definition at line 455 of file flintcf_Zn.cc.

456 {
457  // format: len a_len .. a_0
459  int l=nmod_poly_length(aa);
460  fprintf(d->f_write,"%d ",l);
461  for(int i=l; i>=0; i--)
462  {
463  ulong ul=nmod_poly_get_coeff_ui(aa,i);
464  fprintf(d->f_write,"%lu ", ul);
465  }
466 }
FILE * f_write
Definition: s_buff.h:23

◆ WriteShort()

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

Definition at line 221 of file flintcf_Zn.cc.

222 {
223  //nmod_poly_print_pretty((nmod_poly_ptr)a,r->pParameterNames[0]);
224  if (IsOne(a,r)) StringAppendS("1");
225  else if (IsZero(a,r)) StringAppendS("0");
226  else
227  {
228  StringAppendS("(");
229  BOOLEAN need_plus=FALSE;
230  for(int i=nmod_poly_length((nmod_poly_ptr)a);i>=0;i--)
231  {
232  slong m=nmod_poly_get_coeff_ui((nmod_poly_ptr)a,i);
233  if (m!=0)
234  {
235  if (need_plus) StringAppendS("+");
236  need_plus=TRUE;
237  if (i>0)
238  {
239  if (m!=1) StringAppend("%d*",(int)m);
240  if (i>1)
241  StringAppend("%s^%d",r->pParameterNames[0],i);
242  else if (i==1)
243  StringAppend("%s",r->pParameterNames[0]);
244  }
245  else StringAppend("%d",(int)m);
246  }
247  }
248  StringAppendS(")");
249  }
250 }
#define StringAppend
Definition: emacs.cc:79
void StringAppendS(const char *st)
Definition: reporter.cc:107