My Project  debian-1:4.1.1-p2+ds-4build4
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 r)
 
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)
 
static void WriteFd (number a, FILE *f, const coeffs)
 
static number ReadFd (s_buff f, 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 82 of file flintcf_Zn.cc.

83 {
84  nmod_poly_ptr res=(nmod_poly_ptr)omAlloc(sizeof(nmod_poly_t));
85  nmod_poly_init(res,c->ch);
86  nmod_poly_add(res,(nmod_poly_ptr)a,(nmod_poly_ptr)b);
87  return (number)res;
88 }
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 397 of file flintcf_Zn.cc.

398 {
399  WerrorS("not yet: ChineseRemainder");
400 }
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:253
#define NULL
Definition: omList.c:10

◆ CoeffName()

static char* CoeffName ( const coeffs  r)
static

Definition at line 421 of file flintcf_Zn.cc.

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

◆ CoeffString()

static char* CoeffString ( const coeffs  r)
static

Definition at line 427 of file flintcf_Zn.cc.

428 {
429  char *buf=(char*)omAlloc(12+10 /*ch*/+strlen(r->pParameterNames[0]));
430  sprintf(buf,"flintZ(%d,\"%s\")",r->ch,r->pParameterNames[0]);
431  return buf;
432 }
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 414 of file flintcf_Zn.cc.

415 {
416 }

◆ ConvSingNFactoryN()

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

Definition at line 417 of file flintcf_Zn.cc.

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

◆ Copy()

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

Definition at line 202 of file flintcf_Zn.cc.

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

◆ DBTest()

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

Definition at line 460 of file flintcf_Zn.cc.

461 {
462  return TRUE;
463 }
#define TRUE
Definition: auxiliary.h:98

◆ Delete()

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

Definition at line 353 of file flintcf_Zn.cc.

354 {
355  if ((*a)!=NULL)
356  {
358  omFree(*a);
359  *a=NULL;
360  }
361 }
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 89 of file flintcf_Zn.cc.

90 {
91  nmod_poly_ptr res=(nmod_poly_ptr)omAlloc(sizeof(nmod_poly_t));
92  nmod_poly_init(res,c->ch);
93  if(nmod_poly_is_zero((nmod_poly_ptr)b))
94  {
96  }
97  else
98  {
99  nmod_poly_div(res,(nmod_poly_ptr)a,(nmod_poly_ptr)b);
100  nmod_poly_t mod;
101  nmod_poly_init(mod,c->ch);
102  nmod_poly_rem(mod,(nmod_poly_ptr)a,(nmod_poly_ptr)b);
103  if (!nmod_poly_is_zero((nmod_poly_ptr)mod))
104  {
105  WerrorS("cannot divide");
106  }
108  }
109  return (number)res;
110 }
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 302 of file flintcf_Zn.cc.

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

◆ ExactDiv()

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

Definition at line 111 of file flintcf_Zn.cc.

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

◆ ExtGcd()

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

Definition at line 340 of file flintcf_Zn.cc.

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

◆ Farey()

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

Definition at line 393 of file flintcf_Zn.cc.

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

◆ flintZn_InitChar()

BOOLEAN flintZn_InitChar ( coeffs  cf,
void *  infoStruct 
)

Definition at line 465 of file flintcf_Zn.cc.

466 {
467  flintZn_struct *pp=(flintZn_struct*)infoStruct;
468  cf->ch=pp->ch;
469 
470  cf->cfCoeffString = CoeffString;
471  cf->cfCoeffName = CoeffName;
472  cf->cfCoeffWrite = CoeffWrite;
473  cf->nCoeffIsEqual = CoeffIsEqual;
474  cf->cfKillChar = KillChar;
475  cf->cfSetChar = SetChar;
476  cf->cfMult = Mult;
477  cf->cfSub = Sub;
478  cf->cfAdd = Add;
479  cf->cfDiv = Div;
480  cf->cfExactDiv = ExactDiv; // ???
481  cf->cfInit =Init;
482  cf->cfInitMPZ =InitMPZ;
483  cf->cfSize = Size;
484  cf->cfInt = Int;
485  cf->cfMPZ = MPZ;
486  cf->cfInpNeg = Neg;
487  cf->cfInvers = Invers;
488  cf->cfCopy = Copy;
489  cf->cfRePart = Copy;
490  // default: cf->cfImPart = ndReturn0;
491  cf->cfWriteLong = WriteShort; //WriteLong;
492  cf->cfWriteShort = WriteShort;
493  cf->cfRead = Read;
494  cf->cfNormalize = Normalize;
495 
496  //cf->cfDivComp=
497  //cf->cfIsUnit=
498  //cf->cfGetUnit=
499  //cf->cfDivBy=
500 
501  cf->cfGreater=Greater;
502  cf->cfEqual =Equal;
503  cf->cfIsZero =IsZero;
504  cf->cfIsOne =IsOne;
505  cf->cfIsMOne =IsMOne;
506  cf->cfGreaterZero=GreaterZero;
507 
508  cf->cfPower = Power;
509  //default: cf->cfGetDenom = GetDenom;
510  //default: cf->cfGetNumerator = GetNumerator;
511  cf->cfGcd = Gcd;
512  cf->cfExtGcd = ExtGcd;
513  cf->cfLcm = Lcm;
514  cf->cfDelete = Delete;
515  cf->cfSetMap = SetMap;
516  // default: cf->cfInpMult
517  // default: cf->cfInpAdd
518  cf->cfFarey =Farey;
519  cf->cfChineseRemainder=ChineseRemainder;
520  cf->cfParDeg = ParDeg;
521  cf->cfParameter = Parameter;
522  // cf->cfClearContent = ClearContent;
523  // cf->cfClearDenominators = ClearDenominators;
524  cf->convFactoryNSingN=ConvFactoryNSingN;
525  cf->convSingNFactoryN=ConvSingNFactoryN;
526  cf->cfWriteFd = WriteFd;
527  cf->cfReadFd = ReadFd;
528 #ifdef LDEBUG
529  cf->cfDBTest = DBTest;
530 #endif
531 
532  cf->iNumberOfParameters = 1;
533  char **pn=(char**)omAlloc0(sizeof(char*));
534  pn[0]=(char*)omStrDup(pp->name);
535  cf->pParameterNames = (const char **)pn;
536  cf->has_simple_Inverse= FALSE;
537  cf->has_simple_Alloc= FALSE;
538  cf->is_field=FALSE;
539 
540  return FALSE;
541 }
#define FALSE
Definition: auxiliary.h:94
CanonicalForm cf
Definition: cfModGcd.cc:4024
static void WriteShort(number a, const coeffs r)
Definition: flintcf_Zn.cc:220
static number Lcm(number a, number b, const coeffs r)
Definition: flintcf_Zn.cc:349
static number ConvFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition: flintcf_Zn.cc:414
static void MPZ(mpz_t result, number &n, const coeffs r)
Definition: flintcf_Zn.cc:164
static number Neg(number a, const coeffs r)
Definition: flintcf_Zn.cc:174
static BOOLEAN Greater(number a, number b, const coeffs r)
Definition: flintcf_Zn.cc:287
static number Mult(number a, number b, const coeffs c)
Definition: flintcf_Zn.cc:68
static number Sub(number a, number b, const coeffs c)
Definition: flintcf_Zn.cc:75
static long Int(number &n, const coeffs r)
Definition: flintcf_Zn.cc:154
static number Init(long i, const coeffs r)
Definition: flintcf_Zn.cc:130
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:284
static number Gcd(number a, number b, const coeffs r)
Definition: flintcf_Zn.cc:333
static char * CoeffString(const coeffs r)
Definition: flintcf_Zn.cc:427
static number ExtGcd(number a, number b, number *s, number *t, const coeffs r)
Definition: flintcf_Zn.cc:340
static BOOLEAN GreaterZero(number k, const coeffs r)
Definition: flintcf_Zn.cc:320
static BOOLEAN DBTest(number a, const char *f, const int l, const coeffs r)
Definition: flintcf_Zn.cc:460
static void Delete(number *a, const coeffs r)
Definition: flintcf_Zn.cc:353
static CanonicalForm ConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition: flintcf_Zn.cc:417
static void KillChar(coeffs r)
Definition: flintcf_Zn.cc:60
static number Copy(number a, const coeffs r)
Definition: flintcf_Zn.cc:202
static number InitMPZ(mpz_t i, const coeffs r)
Definition: flintcf_Zn.cc:139
static number Div(number a, number b, const coeffs c)
Definition: flintcf_Zn.cc:89
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:326
static BOOLEAN Equal(number a, number b, const coeffs r)
Definition: flintcf_Zn.cc:302
static number Add(number a, number b, const coeffs c)
Definition: flintcf_Zn.cc:82
static BOOLEAN IsOne(number a, const coeffs r)
Definition: flintcf_Zn.cc:310
static number Farey(number p, number n, const coeffs)
Definition: flintcf_Zn.cc:393
static BOOLEAN IsZero(number a, const coeffs r)
Definition: flintcf_Zn.cc:306
static int ParDeg(number x, const coeffs r)
Definition: flintcf_Zn.cc:401
static nMapFunc SetMap(const coeffs src, const coeffs dst)
Definition: flintcf_Zn.cc:362
static number ChineseRemainder(number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs)
Definition: flintcf_Zn.cc:397
static BOOLEAN IsMOne(number k, const coeffs r)
Definition: flintcf_Zn.cc:314
static void SetChar(const coeffs r)
Definition: flintcf_Zn.cc:64
static number ReadFd(s_buff f, const coeffs r)
Definition: flintcf_Zn.cc:445
static number Parameter(const int i, const coeffs r)
Definition: flintcf_Zn.cc:405
static number Invers(number a, const coeffs r)
Definition: flintcf_Zn.cc:179
static char * CoeffName(const coeffs r)
Definition: flintcf_Zn.cc:421
static const char * Read(const char *st, number *a, const coeffs r)
Definition: flintcf_Zn.cc:250
static int Size(number n, const coeffs r)
Definition: flintcf_Zn.cc:150
static number ExactDiv(number a, number b, const coeffs c)
Definition: flintcf_Zn.cc:111
static void WriteFd(number a, FILE *f, const coeffs)
Definition: flintcf_Zn.cc:433
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define omAlloc0(size)
Definition: omAllocDecl.h:211

◆ Gcd()

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

Definition at line 333 of file flintcf_Zn.cc.

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

◆ Greater()

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

Definition at line 287 of file flintcf_Zn.cc.

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

◆ GreaterZero()

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

Definition at line 320 of file flintcf_Zn.cc.

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

◆ Init()

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

Definition at line 130 of file flintcf_Zn.cc.

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

◆ Init_bigint()

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

Definition at line 373 of file flintcf_Zn.cc.

374 {
375  nmod_poly_ptr res=(nmod_poly_ptr)omAlloc(sizeof(nmod_poly_t));
376  nmod_poly_init(res,dst->ch);
377  long ii;
378  if (SR_HDL(i) & SR_INT)
379  {
380  ii=SR_TO_INT(i) % dst->ch;
381  }
382  else
383  {
384  mpz_t tmp;
385  mpz_init(tmp);
386  ii=mpz_mod_ui(tmp,i->z,dst->ch);
387  mpz_clear(tmp);
388  }
389  if (ii<0) ii+=dst->ch;
390  nmod_poly_set_coeff_ui(res,0,ii);
391  return (number)res;
392 }
#define SR_INT
Definition: longrat.h:68
#define SR_TO_INT(SR)
Definition: longrat.h:70
#define SR_HDL(A)
Definition: tgb.cc:35

◆ InitMPZ()

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

Definition at line 139 of file flintcf_Zn.cc.

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

◆ Int()

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

Definition at line 154 of file flintcf_Zn.cc.

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

◆ IntMod()

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

Definition at line 123 of file flintcf_Zn.cc.

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

◆ Invers()

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

Definition at line 179 of file flintcf_Zn.cc.

180 {
181  if(nmod_poly_is_zero((nmod_poly_ptr)a))
182  {
183  WerrorS(nDivBy0);
184  return NULL;
185  }
186  if (nmod_poly_degree((nmod_poly_ptr)a)==0)
187  {
188  nmod_poly_ptr res=(nmod_poly_ptr)omAlloc(sizeof(nmod_poly_t));
189  nmod_poly_init(res,r->ch);
190  slong c=nmod_poly_get_coeff_ui((nmod_poly_ptr)a,0);
191  extern number nvInvers (number c, const coeffs r);
192  c=(slong)nvInvers((number)c,r);
193  nmod_poly_set_coeff_ui((nmod_poly_ptr)a,0,c);
194  return (number)res;
195  }
196  else
197  {
198  WerrorS("not invertable");
199  return NULL;
200  }
201 }
number nvInvers(number c, const coeffs r)
Definition: modulop.cc:847
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 314 of file flintcf_Zn.cc.

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

◆ IsOne()

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

Definition at line 310 of file flintcf_Zn.cc.

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

◆ IsZero()

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

Definition at line 306 of file flintcf_Zn.cc.

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

◆ KillChar()

static void KillChar ( coeffs  r)
static

Definition at line 60 of file flintcf_Zn.cc.

61 {
62  // not yet
63 }

◆ Lcm()

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

Definition at line 349 of file flintcf_Zn.cc.

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

◆ MPZ()

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

Definition at line 164 of file flintcf_Zn.cc.

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

◆ Mult()

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

Definition at line 68 of file flintcf_Zn.cc.

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

◆ Neg()

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

Definition at line 174 of file flintcf_Zn.cc.

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

◆ Normalize()

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

Definition at line 284 of file flintcf_Zn.cc.

285 {
286 }

◆ Parameter()

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

Definition at line 405 of file flintcf_Zn.cc.

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

◆ ParDeg()

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

Definition at line 401 of file flintcf_Zn.cc.

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

◆ Power()

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

Definition at line 326 of file flintcf_Zn.cc.

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

◆ Read()

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

Definition at line 250 of file flintcf_Zn.cc.

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

◆ ReadFd()

static number ReadFd ( s_buff  f,
const coeffs  r 
)
static

Definition at line 445 of file flintcf_Zn.cc.

446 {
447  // format: len a_len .. a_0
448  nmod_poly_ptr aa=(nmod_poly_ptr)omAlloc(sizeof(nmod_poly_t));
449  nmod_poly_init(aa,r->ch);
450  int l=s_readint(f);
451  unsigned long ul;
452  for (int i=l;i>=0;i--)
453  {
454  unsigned long ul=s_readlong(f);
455  nmod_poly_set_coeff_ui(aa,i,ul);
456  }
457  return (number)aa;
458 }
int l
Definition: cfEzgcd.cc:93
FILE * f
Definition: checklibs.c:9
int s_readint(s_buff F)
Definition: s_buff.cc:110
long s_readlong(s_buff F)
Definition: s_buff.cc:138

◆ SetChar()

static void SetChar ( const coeffs  r)
static

Definition at line 64 of file flintcf_Zn.cc.

65 {
66  // dummy
67 }

◆ SetMap()

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

Definition at line 362 of file flintcf_Zn.cc.

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

◆ Size()

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

Definition at line 150 of file flintcf_Zn.cc.

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

◆ Sub()

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

Definition at line 75 of file flintcf_Zn.cc.

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

◆ WriteFd()

static void WriteFd ( number  a,
FILE *  f,
const  coeffs 
)
static

Definition at line 433 of file flintcf_Zn.cc.

434 {
435  // format: len a_len .. a_0
437  int l=nmod_poly_length(aa);
438  fprintf(f,"%d ",l);
439  for(int i=l; i>=0; i--)
440  {
441  ulong ul=nmod_poly_get_coeff_ui(aa,i);
442  fprintf(f,"%lu ", ul);
443  }
444 }

◆ WriteShort()

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

Definition at line 220 of file flintcf_Zn.cc.

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