Functions
number2.cc File Reference
#include "kernel/mod2.h"
#include <reporter/reporter.h>
#include <coeffs/numbers.h>
#include <coeffs/rmodulon.h>
#include <coeffs/bigintmat.h>
#include <coeffs/longrat.h>
#include <misc/prime.h>
#include <Singular/blackbox.h>
#include <Singular/ipshell.h>
#include <Singular/ipid.h>
#include <Singular/number2.h>

Go to the source code of this file.

Functions

char * crString (coeffs c)
 
void crPrint (coeffs c)
 
BOOLEAN jjCRING_Zp (leftv res, leftv a, leftv b)
 
BOOLEAN jjCRING_Zm (leftv res, leftv a, leftv b)
 
BOOLEAN jjNUMBER2_OP2 (leftv res, leftv a, leftv b)
 
BOOLEAN jjNUMBER2_OP1 (leftv res, leftv a)
 
BOOLEAN jjNUMBER2CR (leftv res, leftv a, leftv b)
 
BOOLEAN jjN2_CR (leftv res, leftv a)
 
BOOLEAN jjCM_CR (leftv res, leftv a)
 
BOOLEAN jjCMATRIX_3 (leftv res, leftv r, leftv c, leftv cf)
 
BOOLEAN jjN2_N (leftv res, leftv a)
 
BOOLEAN jjEQUAL_CR (leftv res, leftv a, leftv b)
 
number2 n2Copy (const number2 d)
 
void n2Delete (number2 &d)
 
char * n2String (number2 d, BOOLEAN typed)
 
void n2Print (number2 d)
 
BOOLEAN jjBIM2_CR (leftv res, leftv a)
 
BOOLEAN jjR2_CR (leftv res, leftv a)
 

Function Documentation

§ crPrint()

void crPrint ( coeffs  c)

Definition at line 25 of file number2.cc.

26 {
27  char *s=crString(c);
28  PrintS(s);
29  omFree(s);
30 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
char * crString(coeffs c)
Definition: number2.cc:17
#define omFree(addr)
Definition: omAllocDecl.h:261
void PrintS(const char *s)
Definition: reporter.cc:284

§ crString()

char* crString ( coeffs  c)

Definition at line 17 of file number2.cc.

18 {
19  if (c==NULL)
20  {
21  return omStrDup("oo");
22  }
23  return omStrDup(nCoeffName(c));
24 }
static FORCE_INLINE char * nCoeffName(const coeffs cf)
Definition: coeffs.h:977
#define NULL
Definition: omList.c:10
#define omStrDup(s)
Definition: omAllocDecl.h:263

§ jjBIM2_CR()

BOOLEAN jjBIM2_CR ( leftv  res,
leftv  a 
)

Definition at line 319 of file number2.cc.

320 {
321  bigintmat *b=(bigintmat*)a->Data();
322  coeffs cf=b->basecoeffs();
323  cf->ref++;
324  res->data=(void*)cf;
325  return FALSE;
326 }
#define FALSE
Definition: auxiliary.h:97
Matrices of numbers.
Definition: bigintmat.h:51
void * data
Definition: subexpr.h:90
The main handler for Singular numbers which are suitable for Singular polynomials.
CanonicalForm cf
Definition: cfModGcd.cc:4024
coeffs basecoeffs() const
Definition: bigintmat.h:147
void * Data()
Definition: subexpr.cc:1121
const poly b
Definition: syzextra.cc:213

§ jjCM_CR()

BOOLEAN jjCM_CR ( leftv  res,
leftv  a 
)

Definition at line 223 of file number2.cc.

224 {
225  bigintmat *b=(bigintmat*)a->Data();
226  coeffs cf=b->basecoeffs();
227  if (cf!=NULL)
228  {
229  cf->ref++;
230  }
231  res->data=(void*)cf;
232  return FALSE;
233 }
#define FALSE
Definition: auxiliary.h:97
Matrices of numbers.
Definition: bigintmat.h:51
void * data
Definition: subexpr.h:90
The main handler for Singular numbers which are suitable for Singular polynomials.
CanonicalForm cf
Definition: cfModGcd.cc:4024
#define NULL
Definition: omList.c:10
coeffs basecoeffs() const
Definition: bigintmat.h:147
void * Data()
Definition: subexpr.cc:1121
const poly b
Definition: syzextra.cc:213

§ jjCMATRIX_3()

BOOLEAN jjCMATRIX_3 ( leftv  res,
leftv  r,
leftv  c,
leftv  cf 
)

Definition at line 235 of file number2.cc.

236 {
237  bigintmat *b=new bigintmat((int)(long)r->Data(),
238  (int)(long)c->Data(),
239  (coeffs)cf->Data());
240  res->data=(char*)b;
241  return FALSE;
242 }
#define FALSE
Definition: auxiliary.h:97
Matrices of numbers.
Definition: bigintmat.h:51
void * data
Definition: subexpr.h:90
The main handler for Singular numbers which are suitable for Singular polynomials.
void * Data()
Definition: subexpr.cc:1121
const poly b
Definition: syzextra.cc:213

§ jjCRING_Zm()

BOOLEAN jjCRING_Zm ( leftv  res,
leftv  a,
leftv  b 
)

Definition at line 58 of file number2.cc.

59 {
60  coeffs c1=(coeffs)a->Data();
61  number i2=(number)b->Data();
62  if (c1->type==n_Z)
63  {
64  ZnmInfo info;
65  number modBase= (number) omAlloc(sizeof(mpz_t));
66  nlGMP(i2,modBase,coeffs_BIGINT); // FIXME? TODO? // extern void nlGMP(number &i, number n, const coeffs r); // to be replaced with n_MPZ(modBase,i2,coeffs_BIGINT); // ?
67  info.base= (mpz_ptr)modBase;
68  info.exp= 1;
69  res->data=(void *)nInitChar(n_Zn,&info);
70  return FALSE;
71  }
72  return TRUE;
73 }
mpz_ptr base
Definition: rmodulon.h:19
only used if HAVE_RINGS is defined
Definition: coeffs.h:44
#define FALSE
Definition: auxiliary.h:97
#define TRUE
Definition: auxiliary.h:101
void nlGMP(number &i, number n, const coeffs r)
Definition: longrat.cc:1465
coeffs coeffs_BIGINT
Definition: ipid.cc:54
#define omAlloc(size)
Definition: omAllocDecl.h:210
void * data
Definition: subexpr.h:90
The main handler for Singular numbers which are suitable for Singular polynomials.
const ExtensionInfo & info
< [in] sqrfree poly
only used if HAVE_RINGS is defined
Definition: coeffs.h:43
unsigned long exp
Definition: rmodulon.h:19
void * Data()
Definition: subexpr.cc:1121
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:329

§ jjCRING_Zp()

BOOLEAN jjCRING_Zp ( leftv  res,
leftv  a,
leftv  b 
)

Definition at line 35 of file number2.cc.

36 {
37  coeffs c1=(coeffs)a->Data();
38  int i2=(int)(long)b->Data();
39  if (c1->type==n_Z)
40  {
41  if (i2==IsPrime(i2))
42  {
43  res->data=(void *)nInitChar(n_Zp,(void*)(long)i2);
44  }
45  else
46  {
47  ZnmInfo info;
48  mpz_ptr modBase= (mpz_ptr) omAlloc(sizeof(mpz_t));
49  mpz_init_set_ui(modBase,i2);
50  info.base= modBase;
51  info.exp= 1;
52  res->data=(void *)nInitChar(n_Zn,&info);
53  }
54  return FALSE;
55  }
56  return TRUE;
57 }
mpz_ptr base
Definition: rmodulon.h:19
only used if HAVE_RINGS is defined
Definition: coeffs.h:44
#define FALSE
Definition: auxiliary.h:97
{p < 2^31}
Definition: coeffs.h:30
#define TRUE
Definition: auxiliary.h:101
#define omAlloc(size)
Definition: omAllocDecl.h:210
void * data
Definition: subexpr.h:90
The main handler for Singular numbers which are suitable for Singular polynomials.
const ExtensionInfo & info
< [in] sqrfree poly
only used if HAVE_RINGS is defined
Definition: coeffs.h:43
unsigned long exp
Definition: rmodulon.h:19
int IsPrime(int p)
Definition: prime.cc:61
void * Data()
Definition: subexpr.cc:1121
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:329

§ jjEQUAL_CR()

BOOLEAN jjEQUAL_CR ( leftv  res,
leftv  a,
leftv  b 
)

Definition at line 260 of file number2.cc.

261 {
262  coeffs a2=(coeffs)a->Data();
263  coeffs b2=(coeffs)b->Data();
264  res->data=(void*)(long)(a2==b2);
265  return FALSE;
266 }
#define FALSE
Definition: auxiliary.h:97
void * data
Definition: subexpr.h:90
The main handler for Singular numbers which are suitable for Singular polynomials.
void * Data()
Definition: subexpr.cc:1121

§ jjN2_CR()

BOOLEAN jjN2_CR ( leftv  res,
leftv  a 
)

Definition at line 215 of file number2.cc.

216 {
217  number2 n=(number2)a->Data();
218  n->cf->ref++;
219  res->data=(void*)n->cf;
220  return FALSE;
221 }
#define FALSE
Definition: auxiliary.h:97
void * data
Definition: subexpr.h:90
void * Data()
Definition: subexpr.cc:1121

§ jjN2_N()

BOOLEAN jjN2_N ( leftv  res,
leftv  a 
)

Definition at line 244 of file number2.cc.

245 {
246  number2 n2=(number2)a->Data();
247  BOOLEAN bo=TRUE;
248  if (currRing!=NULL)
249  {
250  nMapFunc nMap=n_SetMap(n2->cf,currRing->cf);
251  if (nMap!=NULL)
252  {
253  res->data=(void*)nMap(n2->n,n2->cf,currRing->cf);
254  bo=FALSE;
255  }
256  }
257  return bo;
258 }
#define FALSE
Definition: auxiliary.h:97
#define TRUE
Definition: auxiliary.h:101
void * data
Definition: subexpr.h:90
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:10
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:73
static FORCE_INLINE nMapFunc n_SetMap(const coeffs src, const coeffs dst)
set the mapping function pointers for translating numbers from src to dst
Definition: coeffs.h:725
#define NULL
Definition: omList.c:10
void * Data()
Definition: subexpr.cc:1121
int BOOLEAN
Definition: auxiliary.h:88

§ jjNUMBER2_OP1()

BOOLEAN jjNUMBER2_OP1 ( leftv  res,
leftv  a 
)

Definition at line 146 of file number2.cc.

147 {
148  int op=iiOp;
149  // unary operations for number2
150  number2 a2=(number2)a->Data();
151  number2 r=(number2)omAlloc(sizeof(*r));
152  r->cf=a2->cf;
153  if (a2->cf==NULL) op=0; // force error
154  switch(op)
155  {
156  case '-': r->n=n_Copy(a2->n,a2->cf);r->n=n_InpNeg(r->n,a2->cf);break;
157  default: Werror("unknown unary operation %s(%d)",Tok2Cmdname(op),op);
158  omFree(r);
159  return TRUE;
160  }
161  res->data=(void*)r;
162  r->cf->ref++;
163  return FALSE;
164 }
#define FALSE
Definition: auxiliary.h:97
#define TRUE
Definition: auxiliary.h:101
#define omAlloc(size)
Definition: omAllocDecl.h:210
void * data
Definition: subexpr.h:90
const ring r
Definition: syzextra.cc:208
#define omFree(addr)
Definition: omAllocDecl.h:261
static FORCE_INLINE number n_InpNeg(number n, const coeffs r)
in-place negation of n MUST BE USED: n = n_InpNeg(n) (no copy is returned)
Definition: coeffs.h:561
#define NULL
Definition: omList.c:10
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of &#39;n&#39;
Definition: coeffs.h:455
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:128
void * Data()
Definition: subexpr.cc:1121
int iiOp
Definition: iparith.cc:227
void Werror(const char *fmt,...)
Definition: reporter.cc:189

§ jjNUMBER2_OP2()

BOOLEAN jjNUMBER2_OP2 ( leftv  res,
leftv  a,
leftv  b 
)

Definition at line 78 of file number2.cc.

79 {
80  int op=iiOp;
81  // binary operations for number2
82  number2 a2=NULL;
83  number aa=NULL;
84  number2 b2=NULL;
85  number bb=NULL;
86  if (a->Typ()==CNUMBER_CMD)
87  {
88  a2=(number2)a->Data();
89  aa=a2->n;
90  }
91  if (b->Typ()==CNUMBER_CMD)
92  {
93  b2=(number2)b->Data();
94  if ((a2!=NULL) && (a2->cf!=b2->cf))
95  {
96  WerrorS("Number not compatible");
97  return TRUE;
98  }
99  bb=b2->n;
100  }
101  number2 r=(number2)omAlloc(sizeof(*r));
102  if (a2!=NULL) r->cf=a2->cf;
103  else r->cf=b2->cf;
104  if (r->cf==NULL) op=0; // force error
105  else
106  if (a2==NULL)
107  {
108  if (a->Typ()==INT_CMD) aa=n_Init((long)a->Data(),r->cf);
109  else if (a->Typ()==BIGINT_CMD)
110  {
111  //aa=n_Init_bigint((number)a->Data(),coeffs_BIGINT,r->cf);
112  nMapFunc nMap=n_SetMap(coeffs_BIGINT,r->cf);
113  aa=nMap((number)a->Data(),coeffs_BIGINT,r->cf);
114  }
115  else op=0;
116  }
117  if ((b2==NULL) &&(op!='^') &&(op!=0))
118  {
119  if (b->Typ()==INT_CMD) bb=n_Init((long)b->Data(),r->cf);
120  else if (b->Typ()==BIGINT_CMD)
121  {
122  //bb=n_Init_bigint((number)b->Data(),coeffs_BIGINT,r->cf);
123  nMapFunc nMap=n_SetMap(coeffs_BIGINT,r->cf);
124  bb=nMap((number)b->Data(),coeffs_BIGINT,r->cf);
125  }
126  else op=0;
127  }
128  switch(op)
129  {
130  case '+': r->n=n_Add(aa,bb,r->cf);break;
131  case '-': r->n=n_Sub(aa,bb,r->cf);break;
132  case '*': r->n=n_Mult(aa,bb,r->cf);break;
133  case '/': r->n=n_Div(aa,bb,r->cf);break;
134  case '%': r->n=n_IntMod(aa,bb,r->cf);break;
135 
136  case '^': n_Power(aa,(int)(long)b->Data(),&(r->n),r->cf); break;
137 
138  default: Werror("unknown binary operation %s(%d)",Tok2Cmdname(op),op);
139  omFree(r);
140  return TRUE;
141  }
142  res->data=(void*)r;
143  r->cf->ref++;
144  return FALSE;
145 }
static FORCE_INLINE number n_Sub(number a, number b, const coeffs r)
return the difference of &#39;a&#39; and &#39;b&#39;, i.e., a-b
Definition: coeffs.h:673
static FORCE_INLINE number n_IntMod(number a, number b, const coeffs r)
for r a field, return n_Init(0,r) always: n_Div(a,b,r)*b+n_IntMod(a,b,r)==a n_IntMod(a,b,r) >=0
Definition: coeffs.h:632
Definition: tok.h:94
#define FALSE
Definition: auxiliary.h:97
Definition: tok.h:38
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:542
#define TRUE
Definition: auxiliary.h:101
void WerrorS(const char *s)
Definition: feFopen.cc:24
coeffs coeffs_BIGINT
Definition: ipid.cc:54
int Typ()
Definition: subexpr.cc:979
#define omAlloc(size)
Definition: omAllocDecl.h:210
void * data
Definition: subexpr.h:90
static FORCE_INLINE number n_Mult(number a, number b, const coeffs r)
return the product of &#39;a&#39; and &#39;b&#39;, i.e., a*b
Definition: coeffs.h:640
const ring r
Definition: syzextra.cc:208
#define omFree(addr)
Definition: omAllocDecl.h:261
static FORCE_INLINE number n_Add(number a, number b, const coeffs r)
return the sum of &#39;a&#39; and &#39;b&#39;, i.e., a+b
Definition: coeffs.h:660
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:73
static FORCE_INLINE nMapFunc n_SetMap(const coeffs src, const coeffs dst)
set the mapping function pointers for translating numbers from src to dst
Definition: coeffs.h:725
static FORCE_INLINE void n_Power(number a, int b, number *res, const coeffs r)
fill res with the power a^b
Definition: coeffs.h:636
#define NULL
Definition: omList.c:10
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:128
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of &#39;a&#39; and &#39;b&#39;, i.e., a/b; raises an error if &#39;b&#39; is not invertible in r exceptio...
Definition: coeffs.h:619
void * Data()
Definition: subexpr.cc:1121
int iiOp
Definition: iparith.cc:227
void Werror(const char *fmt,...)
Definition: reporter.cc:189

§ jjNUMBER2CR()

BOOLEAN jjNUMBER2CR ( leftv  res,
leftv  a,
leftv  b 
)

Definition at line 166 of file number2.cc.

167 {
168  number2 r=(number2)omAlloc(sizeof(*r));
169  r->cf=(coeffs)b->CopyD();
170  BOOLEAN bo=FALSE;
171  switch(a->Typ())
172  {
173  case INT_CMD:
174  r->n=n_Init((long)a->Data(),r->cf); break;
175  case BIGINT_CMD:
176  {
177  nMapFunc nMap=n_SetMap(coeffs_BIGINT,r->cf);
178  r->n=nMap((number)a->Data(),coeffs_BIGINT,r->cf); break;
179  }
180  case NUMBER_CMD:
181  {
182  nMapFunc nMap=n_SetMap(currRing->cf,r->cf);
183  if (nMap!=NULL)
184  r->n=nMap((number)a->Data(),currRing->cf,r->cf);
185  else
186  bo=TRUE;
187  break;
188  }
189  case CNUMBER_CMD:
190  {
191  number2 a2=(number2)a->Data();
192  if (a2->cf==NULL) bo=TRUE;
193  else
194  {
195  nMapFunc nMap=n_SetMap(a2->cf,r->cf);
196  if (nMap!=NULL)
197  r->n=nMap(a2->n,a2->cf,r->cf);
198  else
199  bo=TRUE;
200  }
201  break;
202  }
203  default: bo=TRUE; break;
204  }
205  if (bo)
206  {
207  Werror("no conversion to Number from %s",Tok2Cmdname(a->Typ()));
208  omFreeSize(r,sizeof(*r));
209  }
210  else
211  res->data=(void*)r;
212  return bo;
213 }
Definition: tok.h:94
#define FALSE
Definition: auxiliary.h:97
Definition: tok.h:38
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:542
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define TRUE
Definition: auxiliary.h:101
coeffs coeffs_BIGINT
Definition: ipid.cc:54
int Typ()
Definition: subexpr.cc:979
#define omAlloc(size)
Definition: omAllocDecl.h:210
void * data
Definition: subexpr.h:90
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:10
const ring r
Definition: syzextra.cc:208
The main handler for Singular numbers which are suitable for Singular polynomials.
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:73
static FORCE_INLINE nMapFunc n_SetMap(const coeffs src, const coeffs dst)
set the mapping function pointers for translating numbers from src to dst
Definition: coeffs.h:725
#define NULL
Definition: omList.c:10
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:128
void * Data()
Definition: subexpr.cc:1121
int BOOLEAN
Definition: auxiliary.h:88
void Werror(const char *fmt,...)
Definition: reporter.cc:189
void * CopyD(int t)
Definition: subexpr.cc:679

§ jjR2_CR()

BOOLEAN jjR2_CR ( leftv  res,
leftv  a 
)

Definition at line 328 of file number2.cc.

329 {
330  ring r=(ring)a->Data();
331  coeffs cf=r->cf;
332  cf->ref++;
333  res->data=(void*)cf;
334  return FALSE;
335 }
#define FALSE
Definition: auxiliary.h:97
void * data
Definition: subexpr.h:90
const ring r
Definition: syzextra.cc:208
The main handler for Singular numbers which are suitable for Singular polynomials.
CanonicalForm cf
Definition: cfModGcd.cc:4024
void * Data()
Definition: subexpr.cc:1121

§ n2Copy()

number2 n2Copy ( const number2  d)

Definition at line 270 of file number2.cc.

271 {
272  number2 r=NULL;
273  if ((d!=NULL)&&(d->cf!=NULL))
274  {
275  r=(number2)omAlloc(sizeof(*r));
276  d->cf->ref++;
277  r->cf=d->cf;
278  if (d->cf!=NULL)
279  r->n=n_Copy(d->n,d->cf);
280  else
281  r->n=NULL;
282  }
283  return r;
284 }
#define omAlloc(size)
Definition: omAllocDecl.h:210
const ring r
Definition: syzextra.cc:208
#define NULL
Definition: omList.c:10
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of &#39;n&#39;
Definition: coeffs.h:455

§ n2Delete()

void n2Delete ( number2 &  d)

Definition at line 285 of file number2.cc.

286 {
287  if (d!=NULL)
288  {
289  if (d->cf!=NULL)
290  {
291  n_Delete(&d->n,d->cf);
292  nKillChar(d->cf);
293  }
294  omFreeSize(d,sizeof(*d));
295  d=NULL;
296  }
297 }
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define NULL
Definition: omList.c:10
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete &#39;p&#39;
Definition: coeffs.h:459
void nKillChar(coeffs r)
undo all initialisations
Definition: numbers.cc:490

§ n2Print()

void n2Print ( number2  d)

Definition at line 311 of file number2.cc.

312 {
313  char *s=n2String(d,FALSE);
314  PrintS(s);
315  omFree(s);
316 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define FALSE
Definition: auxiliary.h:97
#define omFree(addr)
Definition: omAllocDecl.h:261
void PrintS(const char *s)
Definition: reporter.cc:284
char * n2String(number2 d, BOOLEAN typed)
Definition: number2.cc:298

§ n2String()

char* n2String ( number2  d,
BOOLEAN  typed 
)

Definition at line 298 of file number2.cc.

299 {
300  StringSetS("");
301  if ((d!=NULL) && (d->cf!=NULL))
302  {
303  if (typed) StringAppendS("Number(");
304  n_Write(d->n,d->cf);
305  if (typed) StringAppendS(")");
306  }
307  else StringAppendS("oo");
308  return StringEndS();
309 }
char * StringEndS()
Definition: reporter.cc:151
void StringSetS(const char *st)
Definition: reporter.cc:128
void StringAppendS(const char *st)
Definition: reporter.cc:107
static FORCE_INLINE void n_Write(number &n, const coeffs r, const BOOLEAN bShortOut=TRUE)
Definition: coeffs.h:595
#define NULL
Definition: omList.c:10