My Project
Macros | Functions | Variables
misc_ip.cc File Reference

This file provides miscellaneous functionality. More...

#include "kernel/mod2.h"
#include "misc/sirandom.h"
#include "omalloc/omalloc.h"
#include "misc/mylimits.h"
#include "reporter/si_signals.h"
#include "factory/factory.h"
#include "coeffs/si_gmp.h"
#include "coeffs/coeffs.h"
#include "coeffs/flintcf_Q.h"
#include "coeffs/flintcf_Qrat.h"
#include "coeffs/flintcf_Zn.h"
#include "coeffs/rmodulon.h"
#include "polys/ext_fields/algext.h"
#include "polys/ext_fields/transext.h"
#include "polys/nc/gb_hack.h"
#include "Singular/links/simpleipc.h"
#include "misc_ip.h"
#include "ipid.h"
#include "feOpt.h"
#include "links/silink.h"
#include "mod_lib.h"
#include "Singular/distrib.h"
#include "misc/options.h"
#include "misc/intvec.h"
#include "polys/monomials/ring.h"
#include "polys/templates/p_Procs.h"
#include "kernel/GBEngine/kstd1.h"
#include "kernel/oswrapper/timer.h"
#include "resources/feResource.h"
#include "kernel/oswrapper/feread.h"
#include "subexpr.h"
#include "cntrlc.h"
#include "ipshell.h"
#include "fehelp.h"
#include <NTL/version.h>
#include <NTL/tools.h>
#include <flint/flint.h>

Go to the source code of this file.

Macros

#define PLURAL_INTERNAL_DECLARATIONS   1
 
#define SI_SHOW_BUILTIN_MODULE(name)   StringAppend(" %s", #name);
 

Functions

static FORCE_INLINE void number2mpz (number n, mpz_t m)
 
static FORCE_INLINE number mpz2number (mpz_t m)
 
void setListEntry (lists L, int index, mpz_t n)
 
void setListEntry_ui (lists L, int index, unsigned long ui)
 
static int factor_using_division (mpz_t t, unsigned int limit, lists primes, int *multiplicities, int &index, unsigned long bound)
 
static void factor_using_pollard_rho (mpz_t n, unsigned long a, lists primes, int *multiplicities, int &index)
 
static void factor_gmp (mpz_t t, lists primes, int *multiplicities, int &index, unsigned long bound)
 
lists primeFactorisation (const number n, const int pBound)
 Factorises a given bigint number n into its prime factors less than or equal to a given bound, with corresponding multiplicities. More...
 
void singular_example (char *str)
 
BOOLEAN setOption (leftv res, leftv v)
 
char * showOption ()
 
char * versionString ()
 
int singular_fstat (int fd, struct stat *buf)
 
void m2_end (int i)
 
void omSingOutOfMemoryFunc ()
 
static BOOLEAN ii_FlintZn_init (leftv res, leftv a)
 
static BOOLEAN ii_FlintQ_init (leftv res, leftv a)
 
int flint_mod_init (SModulFunctions *psModulFunctions)
 
static BOOLEAN iiFloat (leftv res, leftv pnn)
 
static BOOLEAN iiCrossProd (leftv res, leftv args)
 
static void callWerrorS (const char *s)
 
void siInit (char *name)
 

Variables

STATIC_VAR unsigned add [] = {4, 2, 4, 2, 4, 6, 2, 6}
 
const struct soptionStruct optionStruct []
 
const struct soptionStruct verboseStruct []
 
const char * singular_date =__DATE__ " " __TIME__
 
volatile BOOLEAN m2_end_called = FALSE
 
STATIC_VAR n_coeffType n_FlintZn =n_unknown
 
STATIC_VAR n_coeffType n_FlintQ =n_unknown
 

Detailed Description

This file provides miscellaneous functionality.

For more general information, see the documentation in misc_ip.h.

Definition in file misc_ip.cc.

Macro Definition Documentation

◆ PLURAL_INTERNAL_DECLARATIONS

#define PLURAL_INTERNAL_DECLARATIONS   1

Definition at line 14 of file misc_ip.cc.

◆ SI_SHOW_BUILTIN_MODULE

#define SI_SHOW_BUILTIN_MODULE (   name)    StringAppend(" %s", #name);

Function Documentation

◆ callWerrorS()

static void callWerrorS ( const char *  s)
static

Definition at line 1357 of file misc_ip.cc.

1357 { WerrorS(s); }
const CanonicalForm int s
Definition: facAbsFact.cc:51
void WerrorS(const char *s)
Definition: feFopen.cc:24

◆ factor_gmp()

static void factor_gmp ( mpz_t  t,
lists  primes,
int *  multiplicities,
int &  index,
unsigned long  bound 
)
static

Definition at line 335 of file misc_ip.cc.

336 {
337  unsigned int division_limit;
338 
339  if (mpz_sgn (t) == 0)
340  return;
341 
342  /* Set the trial division limit according the size of t. */
343  division_limit = mpz_sizeinbase (t, 2);
344  if (division_limit > 1000)
345  division_limit = 1000 * 1000;
346  else
347  division_limit = division_limit * division_limit;
348 
349  if (factor_using_division (t, division_limit,primes,multiplicities,index,bound))
350  {
351  if (mpz_cmp_ui (t, 1) != 0)
352  {
353  if (mpz_probab_prime_p (t, 10))
354  {
356  multiplicities[index++] = 1;
357  mpz_set_ui(t,1);
358  }
359  else
360  factor_using_pollard_rho (t, 1L, primes,multiplicities,index);
361  }
362  }
363 }
static CanonicalForm bound(const CFMatrix &M)
Definition: cf_linsys.cc:460
STATIC_VAR unsigned short primes[]
primes, primes_len: used to step through possible extensions
static int factor_using_division(mpz_t t, unsigned int limit, lists primes, int *multiplicities, int &index, unsigned long bound)
Definition: misc_ip.cc:117
static void factor_using_pollard_rho(mpz_t n, unsigned long a, lists primes, int *multiplicities, int &index)
Definition: misc_ip.cc:212
void setListEntry(lists L, int index, mpz_t n)
Definition: misc_ip.cc:82
static int index(p_Length length, p_Ord ord)
Definition: p_Procs_Impl.h:592

◆ factor_using_division()

static int factor_using_division ( mpz_t  t,
unsigned int  limit,
lists  primes,
int *  multiplicities,
int &  index,
unsigned long  bound 
)
static

Definition at line 117 of file misc_ip.cc.

118 {
119  mpz_t q, r;
120  unsigned long int f;
121  int ai;
122  unsigned *addv = add;
123  unsigned int failures;
124  int bound_not_reached=1;
125 
126  mpz_init (q);
127  mpz_init (r);
128 
129  f = mpz_scan1 (t, 0);
130  mpz_div_2exp (t, t, f);
131  if (f>0)
132  {
134  multiplicities[index++] = f;
135  }
136 
137  f=0;
138  loop
139  {
140  mpz_tdiv_qr_ui (q, r, t, 3);
141  if (mpz_sgn1 (r) != 0)
142  break;
143  mpz_set (t, q);
144  f++;
145  }
146  if (f>0)
147  {
149  multiplicities[index++] = f;
150  }
151  f=0;
152  loop
153  {
154  mpz_tdiv_qr_ui (q, r, t, 5);
155  if (mpz_sgn1 (r) != 0)
156  break;
157  mpz_set (t, q);
158  f++;
159  }
160  if (f>0)
161  {
163  multiplicities[index++] = f;
164  }
165 
166  failures = 0;
167  f = 7;
168  ai = 0;
169  unsigned long last_f=0;
170  while (mpz_cmp_ui (t, 1) != 0)
171  {
172  mpz_tdiv_qr_ui (q, r, t, f);
173  if (mpz_sgn1 (r) != 0)
174  {
175  f += addv[ai];
176  if (mpz_cmp_ui (t, f) < 0)
177  break;
178  ai = (ai + 1) & 7;
179  failures++;
180  if (failures > limit)
181  break;
182  if ((bound!=0) && (f>bound))
183  {
184  bound_not_reached=0;
185  break;
186  }
187  }
188  else
189  {
190  mpz_swap (t, q);
191  if (f!=last_f)
192  {
194  multiplicities[index]++;
195  index++;
196  }
197  else
198  {
199  multiplicities[index-1]++;
200  }
201  last_f=f;
202  failures = 0;
203  }
204  }
205 
206  mpz_clear (q);
207  mpz_clear (r);
208  //printf("bound=%d,f=%d,failures=%d, reached=%d\n",bound,f,failures,bound_not_reached);
209  return bound_not_reached;
210 }
FILE * f
Definition: checklibs.c:9
void setListEntry_ui(lists L, int index, unsigned long ui)
Definition: misc_ip.cc:99
STATIC_VAR unsigned add[]
Definition: misc_ip.cc:115
#define mpz_sgn1(A)
Definition: si_gmp.h:13
#define loop
Definition: structs.h:80

◆ factor_using_pollard_rho()

static void factor_using_pollard_rho ( mpz_t  n,
unsigned long  a,
lists  primes,
int *  multiplicities,
int &  index 
)
static

Definition at line 212 of file misc_ip.cc.

213 {
214  mpz_t x, x1, y, P;
215  mpz_t t1, t2;
216  mpz_t last_f;
217  unsigned long long k, l, i;
218 
219  mpz_init (t1);
220  mpz_init (t2);
221  mpz_init_set_ui (last_f, 0);
222  mpz_init_set_ui (y, 2);
223  mpz_init_set_ui (x, 2);
224  mpz_init_set_ui (x1, 2);
225  mpz_init_set_ui (P, 1);
226  k = 1;
227  l = 1;
228 
229  while (mpz_cmp_ui (n, 1) != 0)
230  {
231  loop
232  {
233  do
234  {
235  mpz_mul (t1, x, x);
236  mpz_mod (x, t1, n);
237  mpz_add_ui (x, x, a);
238  mpz_sub (t1, x1, x);
239  mpz_mul (t2, P, t1);
240  mpz_mod (P, t2, n);
241 
242  if (k % 32 == 1)
243  {
244  mpz_gcd (t1, P, n);
245  if (mpz_cmp_ui (t1, 1) != 0)
246  goto factor_found;
247  mpz_set (y, x);
248  }
249  }
250  while (--k != 0);
251 
252  mpz_gcd (t1, P, n);
253  if (mpz_cmp_ui (t1, 1) != 0)
254  goto factor_found;
255 
256  mpz_set (x1, x);
257  k = l;
258  l = 2 * l;
259  for (i = 0; i < k; i++)
260  {
261  mpz_mul (t1, x, x);
262  mpz_mod (x, t1, n);
263  mpz_add_ui (x, x, a);
264  }
265  mpz_set (y, x);
266  }
267 
268  factor_found:
269  do
270  {
271  mpz_mul (t1, y, y);
272  mpz_mod (y, t1, n);
273  mpz_add_ui (y, y, a);
274  mpz_sub (t1, x1, y);
275  mpz_gcd (t1, t1, n);
276  }
277  while (mpz_cmp_ui (t1, 1) == 0);
278 
279  mpz_divexact (n, n, t1); /* divide by t1, before t1 is overwritten */
280 
281  if (!mpz_probab_prime_p (t1, 10))
282  {
283  do
284  {
285  mp_limb_t a_limb;
286  mpn_random (&a_limb, (mp_size_t) 1);
287  a = a_limb;
288  }
289  while (a == 0);
290 
291  factor_using_pollard_rho (t1, a, primes,multiplicities,index);
292  }
293  else
294  {
295  if (mpz_cmp(t1,last_f)==0)
296  {
297  multiplicities[index-1]++;
298  }
299  else
300  {
301  mpz_set(last_f,t1);
302  setListEntry(primes, index, t1);
303  multiplicities[index++] = 1;
304  }
305  }
306  mpz_mod (x, x, n);
307  mpz_mod (x1, x1, n);
308  mpz_mod (y, y, n);
309  if (mpz_probab_prime_p (n, 10))
310  {
311  if (mpz_cmp(n,last_f)==0)
312  {
313  multiplicities[index-1]++;
314  }
315  else
316  {
317  mpz_set(last_f,n);
319  multiplicities[index++] = 1;
320  }
321  mpz_set_ui(n,1);
322  break;
323  }
324  }
325 
326  mpz_clear (P);
327  mpz_clear (t2);
328  mpz_clear (t1);
329  mpz_clear (x1);
330  mpz_clear (x);
331  mpz_clear (y);
332  mpz_clear (last_f);
333 }
int l
Definition: cfEzgcd.cc:100
int i
Definition: cfEzgcd.cc:132
int k
Definition: cfEzgcd.cc:99
Variable x
Definition: cfModGcd.cc:4084
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:53

◆ flint_mod_init()

int flint_mod_init ( SModulFunctions psModulFunctions)

Definition at line 1269 of file misc_ip.cc.

1270 {
1271  package save=currPack;
1274  if (n_FlintQ!=n_unknown)
1275  {
1276  iiAddCproc("kernel","flintQp",FALSE,ii_FlintQ_init);
1278  }
1279 #if __FLINT_RELEASE >= 20503
1280  iiAddCproc("kernel","flintQ",FALSE,ii_FlintQrat_init);
1282 #endif
1284  if (n_FlintZn!=n_unknown)
1285  {
1286  iiAddCproc("kernel","flintZn",FALSE,ii_FlintZn_init);
1288  }
1289  currPack=save;
1290  return MAX_TOK;
1291 }
#define FALSE
Definition: auxiliary.h:96
@ n_unknown
Definition: coeffs.h:29
BOOLEAN flintQ_InitChar(coeffs cf, void *infoStruct)
Definition: flintcf_Q.cc:561
coeffs flintQInitCfByName(char *s, n_coeffType n)
Definition: flintcf_Q.cc:533
BOOLEAN flintZn_InitChar(coeffs cf, void *infoStruct)
Definition: flintcf_Zn.cc:476
coeffs flintZnInitCfByName(char *s, n_coeffType n)
Definition: flintcf_Zn.cc:422
VAR package basePack
Definition: ipid.cc:58
VAR package currPack
Definition: ipid.cc:57
int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: iplib.cc:1059
static BOOLEAN ii_FlintQ_init(leftv res, leftv a)
Definition: misc_ip.cc:1224
STATIC_VAR n_coeffType n_FlintQ
Definition: misc_ip.cc:1208
static BOOLEAN ii_FlintZn_init(leftv res, leftv a)
Definition: misc_ip.cc:1210
STATIC_VAR n_coeffType n_FlintZn
Definition: misc_ip.cc:1207
void nRegisterCfByName(cfInitCfByNameProc p, n_coeffType n)
Definition: numbers.cc:582
n_coeffType nRegister(n_coeffType n, cfInitCharProc p)
Definition: numbers.cc:541
@ MAX_TOK
Definition: tok.h:218

◆ ii_FlintQ_init()

static BOOLEAN ii_FlintQ_init ( leftv  res,
leftv  a 
)
static

Definition at line 1224 of file misc_ip.cc.

1225 {
1226  const short t[]={1,STRING_CMD};
1227  if (iiCheckTypes(a,t,1))
1228  {
1229  char* p;
1230  p=(char*)a->Data();
1231  res->rtyp=CRING_CMD;
1232  res->data=(void*)nInitChar(n_FlintQ,(void*)p);
1233  return FALSE;
1234  }
1235  return TRUE;
1236 }
#define TRUE
Definition: auxiliary.h:100
int p
Definition: cfModGcd.cc:4080
void * Data()
Definition: subexpr.cc:1154
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:353
CanonicalForm res
Definition: facAbsFact.cc:60
BOOLEAN iiCheckTypes(leftv args, const short *type_list, int report)
check a list of arguemys against a given field of types return TRUE if the types match return FALSE (...
Definition: ipshell.cc:6564
@ CRING_CMD
Definition: tok.h:56
@ STRING_CMD
Definition: tok.h:185

◆ ii_FlintZn_init()

static BOOLEAN ii_FlintZn_init ( leftv  res,
leftv  a 
)
static

Definition at line 1210 of file misc_ip.cc.

1211 {
1212  const short t[]={2,INT_CMD,STRING_CMD};
1213  if (iiCheckTypes(a,t,1))
1214  {
1215  flintZn_struct p;
1216  p.ch=(int)(long)a->Data();
1217  p.name=(char*)a->next->Data();
1218  res->rtyp=CRING_CMD;
1219  res->data=(void*)nInitChar(n_FlintZn,(void*)&p);
1220  return FALSE;
1221  }
1222  return TRUE;
1223 }
leftv next
Definition: subexpr.h:86
@ INT_CMD
Definition: tok.h:96

◆ iiCrossProd()

static BOOLEAN iiCrossProd ( leftv  res,
leftv  args 
)
static

Definition at line 1323 of file misc_ip.cc.

1324 {
1325  leftv h=args;
1326  coeffs *c=NULL;
1327  coeffs cf=NULL;
1328  int i=0;
1329  if (h==NULL) goto crossprod_error;
1330  while (h!=NULL)
1331  {
1332  if (h->Typ()!=CRING_CMD) goto crossprod_error;
1333  i++;
1334  h=h->next;
1335  }
1336  c=(coeffs*)omAlloc0((i+1)*sizeof(coeffs));
1337  h=args;
1338  i=0;
1339  while (h!=NULL)
1340  {
1341  c[i]=(coeffs)h->CopyD();
1342  i++;
1343  h=h->next;
1344  }
1345  cf=nInitChar(n_nTupel,c);
1346  res->data=cf;
1347  res->rtyp=CRING_CMD;
1348  return FALSE;
1349 
1350  crossprod_error:
1351  WerrorS("expected `crossprod(coeffs, ...)`");
1352  return TRUE;
1353 }
CanonicalForm cf
Definition: cfModGcd.cc:4085
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
@ n_nTupel
n-tupel of cf: ZZ/p1,...
Definition: coeffs.h:43
STATIC_VAR Poly * h
Definition: janet.cc:971
The main handler for Singular numbers which are suitable for Singular polynomials.
#define omAlloc0(size)
Definition: omAllocDecl.h:211
#define NULL
Definition: omList.c:12

◆ iiFloat()

static BOOLEAN iiFloat ( leftv  res,
leftv  pnn 
)
static

Definition at line 1294 of file misc_ip.cc.

1295 {
1296  short float_len=3;
1297  short float_len2=SHORT_REAL_LENGTH;
1298  coeffs cf=NULL;
1299  if ((pnn!=NULL) && (pnn->Typ()==INT_CMD))
1300  {
1301  float_len=(int)(long)pnn->Data();
1302  float_len2=float_len;
1303  pnn=pnn->next;
1304  if ((pnn!=NULL) && (pnn->Typ()==INT_CMD))
1305  {
1306  float_len2=(int)(long)pnn->Data();
1307  pnn=pnn->next;
1308  }
1309  }
1310  if (float_len2 <= (short)SHORT_REAL_LENGTH)
1311  cf=nInitChar(n_R, NULL);
1312  else // longR or longC?
1313  {
1314  LongComplexInfo param;
1315  param.float_len = si_min (float_len, 32767);
1316  param.float_len2 = si_min (float_len2, 32767);
1317  cf = nInitChar(n_long_R, (void*)&param);
1318  }
1319  res->rtyp=CRING_CMD;
1320  res->data=cf;
1321  return cf==NULL;
1322 }
static int si_min(const int a, const int b)
Definition: auxiliary.h:125
int Typ()
Definition: subexpr.cc:1011
@ n_R
single prescision (6,6) real numbers
Definition: coeffs.h:32
@ n_long_R
real floating point (GMP) numbers
Definition: coeffs.h:34
short float_len2
additional char-flags, rInit
Definition: coeffs.h:103
short float_len
additional char-flags, rInit
Definition: coeffs.h:102
#define SHORT_REAL_LENGTH
Definition: numbers.h:57

◆ m2_end()

void m2_end ( int  i)

Definition at line 1098 of file misc_ip.cc.

1099 {
1100  if (!m2_end_called)
1101  {
1102  EXTERN_VAR FILE* File_Profiling;
1104  m2_end_called = TRUE;
1105 #ifdef HAVE_SIMPLEIPC
1106  for (int j = SIPC_MAX_SEMAPHORES-1; j >= 0; j--)
1107  {
1108  if (semaphore[j] != NULL)
1109  {
1110  while (sem_acquired[j] > 0)
1111  {
1112 #if PORTABLE_SEMAPHORES
1113  sem_post(semaphore[j]->sig);
1114 #else
1115  sem_post(semaphore[j]);
1116 #endif
1117  sem_acquired[j]--;
1118  }
1119  }
1120  }
1121 #endif // HAVE_SIMPLEIPC
1123  monitor(NULL,0);
1124 #ifdef PAGE_TEST
1125  mmEndStat();
1126 #endif
1129  {
1131  while(hh!=NULL)
1132  {
1133  //Print("close %s\n",hh->l->name);
1134  slPrepClose(hh->l);
1135  hh=(link_list)hh->next;
1136  }
1138 
1139  idhdl h = currPack->idroot;
1140  while(h != NULL)
1141  {
1142  if(IDTYP(h) == LINK_CMD)
1143  {
1144  idhdl hh=h->next;
1145  //Print("kill %s\n",IDID(h));
1146  killhdl(h, currPack);
1147  h = hh;
1148  }
1149  else
1150  {
1151  h = h->next;
1152  }
1153  }
1154  hh=ssiToBeClosed;
1155  while(hh!=NULL)
1156  {
1157  //Print("close %s\n",hh->l->name);
1158  slClose(hh->l);
1159  hh=ssiToBeClosed;
1160  }
1161  }
1162  if (!singular_in_batchmode)
1163  {
1164  if (i<=0)
1165  {
1166  //extern long all_farey;
1167  //extern long farey_cnt;
1168  //if (all_farey!=0L) printf("farey:%ld, cnt=%ld\n",all_farey,farey_cnt);
1169  if (TEST_V_QUIET)
1170  {
1171  if (i==0)
1172  printf("Auf Wiedersehen.\n");
1173  else
1174  printf("\n$Bye.\n");
1175  }
1176  //#ifdef sun
1177  // #ifndef __svr4__
1178  // _cleanup();
1179  // _exit(0);
1180  // #endif
1181  //#endif
1182  i=0;
1183  }
1184  else
1185  {
1186  printf("\nhalt %d\n",i);
1187  }
1188  }
1189  exit(i);
1190  }
1191 }
Definition: idrec.h:35
VAR BOOLEAN singular_in_batchmode
Definition: cntrlc.cc:70
int j
Definition: facHensel.cc:110
void monitor(void *F, int mode)
Definition: febase.cc:68
void fe_reset_input_mode()
Definition: fereadl.c:827
VAR FILE * File_Profiling
Definition: fevoices.cc:32
#define EXTERN_VAR
Definition: globaldefs.h:6
void killhdl(idhdl h, package proot)
Definition: ipid.cc:406
#define IDTYP(a)
Definition: ipid.h:119
volatile BOOLEAN m2_end_called
Definition: misc_ip.cc:1096
#define TEST_V_QUIET
Definition: options.h:132
VAR sipc_sem_t * semaphore[SIPC_MAX_SEMAPHORES]
Definition: semaphore.c:24
VAR int sem_acquired[SIPC_MAX_SEMAPHORES]
Definition: semaphore.c:25
#define SIPC_MAX_SEMAPHORES
Definition: simpleipc.h:10
@ LINK_CMD
Definition: tok.h:117

◆ mpz2number()

static FORCE_INLINE number mpz2number ( mpz_t  m)
static

Definition at line 79 of file misc_ip.cc.

79 { return mpz2number(m, coeffs_BIGINT); }
int m
Definition: cfEzgcd.cc:128
VAR coeffs coeffs_BIGINT
Definition: ipid.cc:50
static FORCE_INLINE number mpz2number(mpz_t m)
Definition: misc_ip.cc:79

◆ number2mpz()

static FORCE_INLINE void number2mpz ( number  n,
mpz_t  m 
)
static

Definition at line 78 of file misc_ip.cc.

78 { number2mpz(n, coeffs_BIGINT, m); }
static FORCE_INLINE void number2mpz(number n, mpz_t m)
Definition: misc_ip.cc:78

◆ omSingOutOfMemoryFunc()

void omSingOutOfMemoryFunc ( )

Definition at line 1196 of file misc_ip.cc.

1197  {
1198  fprintf(stderr, "\nSingular error: no more memory\n");
1199  omPrintStats(stderr);
1200  m2_end(14);
1201  /* should never get here */
1202  exit(1);
1203  }
void m2_end(int i)
Definition: misc_ip.cc:1098
#define omPrintStats(F)
Definition: xalloc.h:275

◆ primeFactorisation()

lists primeFactorisation ( const number  n,
const int  pBound 
)

Factorises a given bigint number n into its prime factors less than or equal to a given bound, with corresponding multiplicities.

The method finds all prime factors with multiplicities. If a positive bound is given, then only the prime factors <= pBound are being found. In this case, there may remain an unfactored portion m of n. Also, when n is negative, m will contain the sign. If n is zero, m will be zero. The method returns a list L filled with three entries: L[1] a list; L[1][i] contains the i-th prime factor of |n| as int or bigint (sorted in ascending order), L[2] a list; L[2][i] contains the multiplicity of L[1, i] in |n| as int L[3] contains the remainder m as int or bigint, depending on the size,

We thus have: n = L[1][1]^L[2][1] * ... * L[1][k]^L[2][k] * L[3], where k is the number of mutually distinct prime factors (<= a provided non- zero bound). Note that for n = 0, L[1] and L[2] will be emtpy lists and L[3] will be zero.

Returns
the factorisation data in a SINGULAR-internal list
Parameters
[in]nthe bigint > 0 to be factorised
[in]pBoundbound on the prime factors seeked

Definition at line 365 of file misc_ip.cc.

366 {
367  int i;
368  int index=0;
369  mpz_t nn; number2mpz(n, nn);
370  lists primes = (lists)omAllocBin(slists_bin); primes->Init(1000);
371  int* multiplicities = (int*)omAlloc0(1000*sizeof(int));
372  int positive=1;
373 
374  if (!n_IsZero(n, coeffs_BIGINT))
375  {
376  if (!n_GreaterZero(n, coeffs_BIGINT))
377  {
378  positive=-1;
379  mpz_neg(nn,nn);
380  }
381  factor_gmp(nn,primes,multiplicities,index,pBound);
382  }
383 
384  lists primesL = (lists)omAllocBin(slists_bin);
385  primesL->Init(index);
386  for (i = 0; i < index; i++)
387  {
388  primesL->m[i].rtyp = primes->m[i].rtyp;
389  primesL->m[i].data = primes->m[i].data;
390  primes->m[i].rtyp=0;
391  primes->m[i].data=NULL;
392  }
393  primes->Clean(NULL);
394 
395  lists multiplicitiesL = (lists)omAllocBin(slists_bin);
396  multiplicitiesL->Init(index);
397  for (i = 0; i < index; i++)
398  {
399  multiplicitiesL->m[i].rtyp = INT_CMD;
400  multiplicitiesL->m[i].data = (void*)(long)multiplicities[i];
401  }
402  omFree(multiplicities);
403 
405  L->Init(3);
406  if (positive==-1) mpz_neg(nn,nn);
407  L->m[0].rtyp = LIST_CMD; L->m[0].data = (void*)primesL;
408  L->m[1].rtyp = LIST_CMD; L->m[1].data = (void*)multiplicitiesL;
409  setListEntry(L, 2, nn);
410 
411  mpz_clear(nn);
412 
413  return L;
414 }
int rtyp
Definition: subexpr.h:91
void * data
Definition: subexpr.h:88
Definition: lists.h:24
sleftv * m
Definition: lists.h:46
INLINE_THIS void Init(int l=0)
static FORCE_INLINE BOOLEAN n_GreaterZero(number n, const coeffs r)
ordered fields: TRUE iff 'n' is positive; in Z/pZ: TRUE iff 0 < m <= roundedBelow(p/2),...
Definition: coeffs.h:495
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition: coeffs.h:465
VAR omBin slists_bin
Definition: lists.cc:23
static void factor_gmp(mpz_t t, lists primes, int *multiplicities, int &index, unsigned long bound)
Definition: misc_ip.cc:335
slists * lists
Definition: mpr_numeric.h:146
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
#define omFree(addr)
Definition: omAllocDecl.h:261
@ LIST_CMD
Definition: tok.h:118

◆ setListEntry()

void setListEntry ( lists  L,
int  index,
mpz_t  n 
)

Definition at line 82 of file misc_ip.cc.

83 { /* assumes n > 0 */
84  /* try to fit nn into an int: */
85  if (mpz_size1(n)<=1)
86  {
87  int ui=(int)mpz_get_si(n);
88  if ((((ui<<3)>>3)==ui)
89  && (mpz_cmp_si(n,(long)ui)==0))
90  {
91  L->m[index].rtyp = INT_CMD; L->m[index].data = (void*)(long)ui;
92  return;
93  }
94  }
95  number nn = mpz2number(n);
96  L->m[index].rtyp = BIGINT_CMD; L->m[index].data = (void*)nn;
97 }
#define mpz_size1(A)
Definition: si_gmp.h:12
@ BIGINT_CMD
Definition: tok.h:38

◆ setListEntry_ui()

void setListEntry_ui ( lists  L,
int  index,
unsigned long  ui 
)

Definition at line 99 of file misc_ip.cc.

100 { /* assumes n > 0 */
101  /* try to fit nn into an int: */
102  int i=(int)ui;
103  if ((((unsigned long)i)==ui) && (((i<<3)>>3)==i))
104  {
105  L->m[index].rtyp = INT_CMD; L->m[index].data = (void*)(long)i;
106  }
107  else
108  {
109  number nn = n_Init(ui, coeffs_BIGINT);
110  L->m[index].rtyp = BIGINT_CMD; L->m[index].data = (void*)nn;
111  }
112 }
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:539

◆ setOption()

BOOLEAN setOption ( leftv  res,
leftv  v 
)

Definition at line 580 of file misc_ip.cc.

581 {
582  const char *n;
583  do
584  {
585  if (v->Typ()==STRING_CMD)
586  {
587  n=(const char *)v->CopyD(STRING_CMD);
588  }
589  else
590  {
591  if (v->name==NULL)
592  return TRUE;
593  if (v->rtyp==0)
594  {
595  n=v->name;
596  v->name=NULL;
597  }
598  else
599  {
600  n=omStrDup(v->name);
601  }
602  }
603 
604  int i;
605 
606  if(strcmp(n,"get")==0)
607  {
608  intvec *w=new intvec(2);
609  (*w)[0]=si_opt_1;
610  (*w)[1]=si_opt_2;
611  res->rtyp=INTVEC_CMD;
612  res->data=(void *)w;
613  goto okay;
614  }
615  if(strcmp(n,"set")==0)
616  {
617  if((v->next!=NULL)
618  &&(v->next->Typ()==INTVEC_CMD))
619  {
620  v=v->next;
621  intvec *w=(intvec*)v->Data();
622  si_opt_1=(*w)[0];
623  si_opt_2=(*w)[1];
624 #if 0
628  ) {
630  }
631 #endif
632  goto okay;
633  }
634  }
635  if(strcmp(n,"none")==0)
636  {
637  si_opt_1=0;
638  si_opt_2=0;
639  goto okay;
640  }
641  for (i=0; (i==0) || (optionStruct[i-1].setval!=0); i++)
642  {
643  if (strcmp(n,optionStruct[i].name)==0)
644  {
645  if (optionStruct[i].setval & validOpts)
646  {
648  // optOldStd disables redthrough
649  if (optionStruct[i].setval == Sy_bit(OPT_OLDSTD))
651  }
652  else
653  WarnS("cannot set option");
654 #if 0
658  ) {
660  }
661 #endif
662  goto okay;
663  }
664  else if ((strncmp(n,"no",2)==0)
665  && (strcmp(n+2,optionStruct[i].name)==0))
666  {
667  if (optionStruct[i].setval & validOpts)
668  {
670  }
671  else
672  WarnS("cannot clear option");
673  goto okay;
674  }
675  }
676  for (i=0; (i==0) || (verboseStruct[i-1].setval!=0); i++)
677  {
678  if (strcmp(n,verboseStruct[i].name)==0)
679  {
681  #ifdef YYDEBUG
682  #if YYDEBUG
683  /*debugging the bison grammar --> grammar.cc*/
684  EXTERN_VAR int yydebug;
685  if (BVERBOSE(V_YACC)) yydebug=1;
686  else yydebug=0;
687  #endif
688  #endif
689  goto okay;
690  }
691  else if ((strncmp(n,"no",2)==0)
692  && (strcmp(n+2,verboseStruct[i].name)==0))
693  {
695  #ifdef YYDEBUG
696  #if YYDEBUG
697  /*debugging the bison grammar --> grammar.cc*/
698  EXTERN_VAR int yydebug;
699  if (BVERBOSE(V_YACC)) yydebug=1;
700  else yydebug=0;
701  #endif
702  #endif
703  goto okay;
704  }
705  }
706  Werror("unknown option `%s`",n);
707  okay:
708  if (currRing != NULL)
709  currRing->options = si_opt_1 & TEST_RINGDEP_OPTS;
710  omFree((ADDRESS)n);
711  v=v->next;
712  } while (v!=NULL);
713 
714  // set global variable to show memory usage
716  else om_sing_opt_show_mem = 0;
717 
718  return FALSE;
719 }
void * ADDRESS
Definition: auxiliary.h:119
CanonicalForm test
Definition: cfModGcd.cc:4098
char name() const
Definition: variable.cc:122
Variable next() const
Definition: factory.h:153
Definition: intvec.h:23
#define WarnS
Definition: emacs.cc:78
const CanonicalForm & w
Definition: facAbsFact.cc:51
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:39
char name(const Variable &v)
Definition: factory.h:196
VAR int yydebug
Definition: grammar.cc:1805
unsigned resetval
Definition: ipid.h:154
unsigned setval
Definition: ipid.h:153
VAR BITSET validOpts
Definition: kstd1.cc:60
const struct soptionStruct verboseStruct[]
Definition: misc_ip.cc:550
const struct soptionStruct optionStruct[]
Definition: misc_ip.cc:519
#define omStrDup(s)
Definition: omAllocDecl.h:263
int om_sing_opt_show_mem
VAR unsigned si_opt_2
Definition: options.c:6
VAR unsigned si_opt_1
Definition: options.c:5
#define OPT_INTSTRATEGY
Definition: options.h:91
#define TEST_OPT_INTSTRATEGY
Definition: options.h:109
#define BVERBOSE(a)
Definition: options.h:34
#define V_SHOW_MEM
Definition: options.h:42
#define V_YACC
Definition: options.h:43
#define OPT_REDTHROUGH
Definition: options.h:81
#define Sy_bit(x)
Definition: options.h:31
#define TEST_RINGDEP_OPTS
Definition: options.h:99
#define OPT_OLDSTD
Definition: options.h:85
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
void Werror(const char *fmt,...)
Definition: reporter.cc:189
static BOOLEAN rField_is_Ring(const ring r)
Definition: ring.h:489
static BOOLEAN rField_has_simple_inverse(const ring r)
Definition: ring.h:553
@ INTVEC_CMD
Definition: tok.h:101

◆ showOption()

char* showOption ( )

Definition at line 721 of file misc_ip.cc.

722 {
723  int i;
724  BITSET tmp;
725 
726  StringSetS("//options:");
727  if ((si_opt_1!=0)||(si_opt_2!=0))
728  {
729  tmp=si_opt_1;
730  if(tmp)
731  {
732  for (i=0; optionStruct[i].setval!=0; i++)
733  {
734  if (optionStruct[i].setval & tmp)
735  {
737  tmp &=optionStruct[i].resetval;
738  }
739  }
740  for (i=0; i<32; i++)
741  {
742  if (tmp & Sy_bit(i)) StringAppend(" %d",i);
743  }
744  }
745  tmp=si_opt_2;
746  if (tmp)
747  {
748  for (i=0; verboseStruct[i].setval!=0; i++)
749  {
750  if (verboseStruct[i].setval & tmp)
751  {
753  tmp &=verboseStruct[i].resetval;
754  }
755  }
756  for (i=1; i<32; i++)
757  {
758  if (tmp & Sy_bit(i)) StringAppend(" %d",i+32);
759  }
760  }
761  return StringEndS();
762  }
763  StringAppendS(" none");
764  return StringEndS();
765 }
#define StringAppend
Definition: emacs.cc:79
void StringSetS(const char *st)
Definition: reporter.cc:128
void StringAppendS(const char *st)
Definition: reporter.cc:107
char * StringEndS()
Definition: reporter.cc:151
#define BITSET
Definition: structs.h:20

◆ siInit()

void siInit ( char *  name)

Definition at line 1358 of file misc_ip.cc.

1359 {
1360 // memory initialization: -----------------------------------------------
1361  om_Opts.OutOfMemoryFunc = omSingOutOfMemoryFunc;
1362 #ifndef OM_NDEBUG
1363 #ifndef __OPTIMIZE__
1364  om_Opts.ErrorHook = dErrorBreak;
1365 #else
1366  om_Opts.Keep = 0; /* !OM_NDEBUG, __OPTIMIZE__*/
1367 #endif
1368 #else
1369  om_Opts.Keep = 0; /* OM_NDEBUG */
1370 #endif
1371  omInitInfo();
1372 // factory
1373 #ifndef HAVE_NTL
1374  extern void initPT();
1375  initPT();
1376 #endif
1377 // options ---------------------------------------------------------------
1378  si_opt_1=0;
1379 // interpreter tables etc.: -----------------------------------------------
1380  memset(&sLastPrinted,0,sizeof(sleftv));
1382 
1383  extern int iiInitArithmetic(); iiInitArithmetic(); // iparith.cc
1384 
1385  basePack=(package)omAlloc0(sizeof(*basePack));
1387  idhdl h;
1388  h=enterid("Top", 0, PACKAGE_CMD, &IDROOT, FALSE);
1389  IDPACKAGE(h)=basePack;
1390  IDPACKAGE(h)->language = LANG_TOP;
1391  currPackHdl=h;
1392  basePackHdl=h;
1393 
1394  coeffs_BIGINT = nInitChar(n_Q,(void*)1);
1395 
1396 #if 1
1397  // def HAVE_POLYEXTENSIONS
1398  if(TRUE)
1399  {
1400  n_coeffType type;
1401  #ifdef SINGULAR_4_2
1402  type = nRegister(n_polyExt, n2pInitChar);
1403  assume(type == n_polyExt);
1404  #endif
1405 
1406  type = nRegister(n_algExt, naInitChar);
1407  assume(type == n_algExt);
1408 
1409  type = nRegister(n_transExt, ntInitChar);
1410  assume(type == n_transExt);
1411 
1412  (void)type;
1413  }
1414 #endif
1415 
1416 // random generator: -----------------------------------------------
1417  int t=initTimer();
1418  if (t==0) t=1;
1419  initRTimer();
1420  siSeed=t;
1421  factoryseed(t);
1422  siRandomStart=t;
1423  feOptSpec[FE_OPT_RANDOM].value = (void*) ((long)siRandomStart);
1424 
1425 // ressource table: ----------------------------------------------------
1426  // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
1427  // hack such that all shared' libs in the bindir are loaded correctly
1429 
1430 // singular links: --------------------------------------------------
1431  slStandardInit();
1432  myynest=0;
1433 // how many processes ? -----------------------------------------------------
1434  int cpus=2;
1435  int cpu_n;
1436  #ifdef _SC_NPROCESSORS_ONLN
1437  if ((cpu_n=sysconf(_SC_NPROCESSORS_ONLN))>cpus) cpus=cpu_n;
1438  #elif defined(_SC_NPROCESSORS_CONF)
1439  if ((cpu_n=sysconf(_SC_NPROCESSORS_CONF))>cpus) cpus=cpu_n;
1440  #endif
1441  feSetOptValue(FE_OPT_CPUS, cpus);
1442 // how many threads ? -----------------------------------------------------
1443  feSetOptValue(FE_OPT_THREADS, cpus);
1444 
1445 // default coeffs
1446  {
1447  idhdl h;
1448  h=enterid("QQ",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1449  IDDATA(h)=(char*)nInitChar(n_Q,NULL);
1450  h=enterid("ZZ",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1451  IDDATA(h)=(char*)nInitChar(n_Z,NULL);
1452  nRegisterCfByName(nrnInitCfByName,n_Zn); // and n_Znm
1453  iiAddCproc("kernel","crossprod",FALSE,iiCrossProd);
1454  iiAddCproc("kernel","Float",FALSE,iiFloat);
1455  //h=enterid("RR",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1456  //IDDATA(h)=(char*)nInitChar(n_R,NULL);
1457  //h=enterid("CC",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1458  //IDDATA(h)=(char*)nInitChar(n_long_C,NULL);
1459  }
1460 // setting routines for PLURAL QRINGS:
1461 // allowing to use libpolys without libSingular(kStd)
1462 #ifdef HAVE_PLURAL
1463  nc_NF=k_NF;
1469 #endif
1470 // loading standard.lib -----------------------------------------------
1471  if (! feOptValue(FE_OPT_NO_STDLIB))
1472  {
1473  BITSET save1,save2;
1474  SI_SAVE_OPT(save1,save2);
1475  si_opt_2 &= ~Sy_bit(V_LOAD_LIB);
1476  iiLibCmd("standard.lib", TRUE,TRUE,TRUE);
1477  SI_RESTORE_OPT(save1,save2);
1478  }
1479  // interpreter error handling
1480  #ifndef __CYGWIN__
1481  factoryError=callWerrorS; // to honour later changes of variable WerrorS
1482  #endif
1483  errorreported = 0;
1484 }
BOOLEAN naInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
Definition: algext.cc:1373
BOOLEAN n2pInitChar(coeffs cf, void *infoStruct)
Definition: algext.cc:1627
void initPT()
void factoryseed(int s)
random seed initializer
Definition: cf_random.cc:189
VAR void(* factoryError)(const char *s)
Definition: cf_util.cc:80
VAR int siRandomStart
Definition: cntrlc.cc:101
n_coeffType
Definition: coeffs.h:28
@ n_polyExt
used to represent polys as coeffcients
Definition: coeffs.h:35
@ n_Q
rational (GMP) numbers
Definition: coeffs.h:31
@ n_algExt
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic
Definition: coeffs.h:36
@ n_Zn
only used if HAVE_RINGS is defined
Definition: coeffs.h:45
@ n_transExt
used for all transcendental extensions, i.e., the top-most extension in an extension tower is transce...
Definition: coeffs.h:39
@ n_Z
only used if HAVE_RINGS is defined
Definition: coeffs.h:44
VAR short errorreported
Definition: feFopen.cc:23
const char * feSetOptValue(feOptIndex opt, char *optarg)
Definition: feOpt.cc:154
static void * feOptValue(feOptIndex opt)
Definition: feOpt.h:40
EXTERN_VAR struct fe_option feOptSpec[]
Definition: feOpt.h:17
void feInitResources(const char *argv0)
Definition: feResource.cc:170
VAR int myynest
Definition: febase.cc:41
void * value
Definition: fegetopt.h:93
EXTERN_VAR BBA_Proc gnc_gr_bba
Definition: gb_hack.h:10
EXTERN_VAR BBA_Proc gnc_gr_mora
Definition: gb_hack.h:10
EXTERN_VAR BBA_Proc sca_gr_bba
Definition: gb_hack.h:10
EXTERN_VAR NF_Proc nc_NF
Definition: gb_hack.h:9
EXTERN_VAR BBA_Proc sca_mora
Definition: gb_hack.h:10
EXTERN_VAR BBA_Proc sca_bba
Definition: gb_hack.h:10
ideal k_gnc_gr_mora(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat, const ring _currRing)
Definition: gr_kstd2.cc:1289
ideal k_gnc_gr_bba(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat, const ring _currRing)
Definition: gr_kstd2.cc:1030
int iiInitArithmetic()
initialisation of arithmetic structured data
Definition: iparith.cc:9662
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:278
VAR idhdl currPackHdl
Definition: ipid.cc:55
VAR idhdl basePackHdl
Definition: ipid.cc:56
#define IDDATA(a)
Definition: ipid.h:126
#define IDROOT
Definition: ipid.h:19
#define IDPACKAGE(a)
Definition: ipid.h:139
BOOLEAN iiLibCmd(const char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
Definition: iplib.cc:880
ideal k_sca_bba(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat, const ring _currRing)
Modified modern Sinuglar Buchberger's algorithm.
Definition: sca.cc:368
ideal k_sca_mora(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat, const ring _currRing)
Modified modern Sinuglar Mora's algorithm.
Definition: sca.cc:885
ideal k_sca_gr_bba(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat, const ring _currRing)
Modified Plural's Buchberger's algorithmus.
Definition: sca.cc:95
poly k_NF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce, const ring _currRing)
NOTE: this is just a wrapper which sets currRing for the actual kNF call.
Definition: kstd1.cc:3369
static BOOLEAN iiCrossProd(leftv res, leftv args)
Definition: misc_ip.cc:1323
void omSingOutOfMemoryFunc()
Definition: misc_ip.cc:1196
static BOOLEAN iiFloat(leftv res, leftv pnn)
Definition: misc_ip.cc:1294
static void callWerrorS(const char *s)
Definition: misc_ip.cc:1357
#define assume(x)
Definition: mod2.h:387
void dErrorBreak()
Definition: dError.cc:139
omOpts_t om_Opts
Definition: omOpts.c:13
#define SI_SAVE_OPT(A, B)
Definition: options.h:20
#define V_LOAD_LIB
Definition: options.h:46
#define SI_RESTORE_OPT(A, B)
Definition: options.h:23
coeffs nrnInitCfByName(char *s, n_coeffType)
Definition: rmodulon.cc:35
VAR int siSeed
Definition: sirandom.c:30
ip_package * package
Definition: structs.h:48
INST_VAR sleftv sLastPrinted
Definition: subexpr.cc:46
@ LANG_TOP
Definition: subexpr.h:22
int initTimer()
Definition: timer.cc:67
void initRTimer()
Definition: timer.cc:156
@ PACKAGE_CMD
Definition: tok.h:149
#define NONE
Definition: tok.h:221
BOOLEAN ntInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
Definition: transext.cc:2544
#define omInitInfo()
Definition: xalloc.h:272

◆ singular_example()

void singular_example ( char *  str)

Definition at line 442 of file misc_ip.cc.

443 {
444  assume(str!=NULL);
445  char *s=str;
446  while (*s==' ') s++;
447  char *ss=s;
448  while (*ss!='\0') ss++;
449  while (*ss<=' ')
450  {
451  *ss='\0';
452  ss--;
453  }
454  idhdl h=IDROOT->get_level(s,0);
455  if ((h!=NULL) && (IDTYP(h)==PROC_CMD))
456  {
457  char *lib=iiGetLibName(IDPROC(h));
458  if((lib!=NULL)&&(*lib!='\0'))
459  {
460  Print("// proc %s from lib %s\n",s,lib);
462  if (s!=NULL)
463  {
464  if (strlen(s)>5)
465  {
466  iiEStart(s,IDPROC(h));
467  omFree((ADDRESS)s);
468  return;
469  }
470  else omFree((ADDRESS)s);
471  }
472  }
473  }
474  else
475  {
476  char sing_file[MAXPATHLEN];
477  FILE *fd=NULL;
478  char *res_m=feResource('m', 0);
479  if (res_m!=NULL)
480  {
481  sprintf(sing_file, "%s/%s.sing", res_m, s);
482  fd = feFopen(sing_file, "r");
483  }
484  if (fd != NULL)
485  {
486 
487  int old_echo = si_echo;
488  int length, got;
489  char* s;
490 
491  fseek(fd, 0, SEEK_END);
492  length = ftell(fd);
493  fseek(fd, 0, SEEK_SET);
494  s = (char*) omAlloc((length+20)*sizeof(char));
495  got = fread(s, sizeof(char), length, fd);
496  fclose(fd);
497  if (got != length)
498  {
499  Werror("Error while reading file %s", sing_file);
500  }
501  else
502  {
503  s[length] = '\0';
504  strcat(s, "\n;return();\n\n");
505  si_echo = 2;
506  iiEStart(s, NULL);
507  si_echo = old_echo;
508  }
509  omFree(s);
510  }
511  else
512  {
513  Werror("no example for %s", str);
514  }
515  }
516 }
#define Print
Definition: emacs.cc:80
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition: feFopen.cc:47
static char * feResource(feResourceConfig config, int warn)
Definition: feResource.cc:258
VAR int si_echo
Definition: febase.cc:35
@ PROC_CMD
Definition: grammar.cc:280
static BOOLEAN length(leftv result, leftv arg)
Definition: interval.cc:257
#define IDPROC(a)
Definition: ipid.h:140
BOOLEAN iiEStart(char *example, procinfo *pi)
Definition: iplib.cc:750
char * iiGetLibProcBuffer(procinfo *pi, int part)
Definition: iplib.cc:193
static char * iiGetLibName(const procinfov pi)
find the library of an proc
Definition: ipshell.h:66
#define SEEK_SET
Definition: mod2.h:113
#define SEEK_END
Definition: mod2.h:109
char * str(leftv arg)
Definition: shared.cc:704
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define MAXPATHLEN
Definition: omRet2Info.c:22
int status int fd
Definition: si_signals.h:59

◆ singular_fstat()

int singular_fstat ( int  fd,
struct stat *  buf 
)

Definition at line 1083 of file misc_ip.cc.

1084 {
1085  return si_fstat(fd,buf);
1086 }
int status int void * buf
Definition: si_signals.h:59

◆ versionString()

char* versionString ( )

Definition at line 782 of file misc_ip.cc.

783 {
784  StringSetS("");
785  StringAppend("Singular for %s version %s (%d, %d bit) %s",
786  S_UNAME, VERSION, // SINGULAR_VERSION,
787  SINGULAR_VERSION, sizeof(void*)*8,
788 #ifdef MAKE_DISTRIBUTION
789  VERSION_DATE);
790 #else
791  singular_date);
792 #endif
793  StringAppendS("\nwith\n\t");
794 
795 #if defined(mpir_version)
796  StringAppend("MPIR(%s)~GMP(%s),", mpir_version, gmp_version);
797 #elif defined(gmp_version)
798  // #if defined (__GNU_MP_VERSION) && defined (__GNU_MP_VERSION_MINOR)
799  // StringAppend("GMP(%d.%d),",__GNU_MP_VERSION,__GNU_MP_VERSION_MINOR);
800  StringAppend("GMP(%s),", gmp_version);
801 #endif
802 #ifdef HAVE_NTL
803  StringAppend("NTL(%s),",NTL_VERSION);
804 #endif
805 
806 #ifdef HAVE_FLINT
807  StringAppend("FLINT(%s),",FLINT_VERSION);
808 #endif
809 // StringAppendS("factory(" FACTORYVERSION "),");
810  StringAppendS("\n\t");
811 #ifndef HAVE_OMALLOC
812  StringAppendS("xalloc,");
813 #else
814  StringAppendS("omalloc,");
815 #endif
816 #if defined(HAVE_DYN_RL)
818  StringAppendS("no input,");
819  else if (fe_fgets_stdin==fe_fgets)
820  StringAppendS("fgets,");
822  StringAppend("dynamic readline%d),",RL_VERSION_MAJOR);
823  #ifdef HAVE_FEREAD
825  StringAppendS("emulated readline,");
826  #endif
827  else
828  StringAppendS("unknown fgets method,");
829 #else
830  #if defined(HAVE_READLINE) && !defined(FEREAD)
831  StringAppend("static readline(%d),",RL_VERSION_MAJOR);
832  #else
833  #ifdef HAVE_FEREAD
834  StringAppendS("emulated readline,");
835  #else
836  StringAppendS("fgets,");
837  #endif
838  #endif
839 #endif
840 #ifdef HAVE_PLURAL
841  StringAppendS("Plural,");
842 #endif
843 #ifdef HAVE_VSPACE
844  StringAppendS("vspace,");
845 #endif
846 #ifdef HAVE_DBM
847  StringAppendS("DBM,\n\t");
848 #else
849  StringAppendS("\n\t");
850 #endif
851 #ifdef HAVE_DYNAMIC_LOADING
852  StringAppendS("dynamic modules,");
853 #endif
854  if (p_procs_dynamic) StringAppendS("dynamic p_Procs,");
855 #if YYDEBUG
856  StringAppendS("YYDEBUG=1,");
857 #endif
858 #ifdef MDEBUG
859  StringAppend("MDEBUG=%d,",MDEBUG);
860 #endif
861 #ifdef OM_CHECK
862  StringAppend("OM_CHECK=%d,",OM_CHECK);
863 #endif
864 #ifdef OM_TRACK
865  StringAppend("OM_TRACK=%d,",OM_TRACK);
866 #endif
867 #ifdef OM_NDEBUG
868  StringAppendS("OM_NDEBUG,");
869 #endif
870 #ifdef SING_NDEBUG
871  StringAppendS("SING_NDEBUG,");
872 #endif
873 #ifdef PDEBUG
874  StringAppendS("PDEBUG,");
875 #endif
876 #ifdef KDEBUG
877  StringAppendS("KDEBUG,");
878 #endif
879  StringAppendS("\n\t");
880 #ifdef __OPTIMIZE__
881  StringAppendS("CC:OPTIMIZE,");
882 #endif
883 #ifdef __OPTIMIZE_SIZE__
884  StringAppendS("CC:OPTIMIZE_SIZE,");
885 #endif
886 #ifdef __NO_INLINE__
887  StringAppendS("CC:NO_INLINE,");
888 #endif
889 #ifdef HAVE_GENERIC_ADD
890  StringAppendS("GenericAdd,");
891 #else
892  StringAppendS("AvoidBranching,");
893 #endif
894 #ifdef HAVE_GENERIC_MULT
895  StringAppendS("GenericMult,");
896 #else
897  StringAppendS("TableMult,");
898 #endif
899 #ifdef HAVE_INVTABLE
900  StringAppendS("invTable,");
901 #else
902  StringAppendS("no invTable,");
903 #endif
904  StringAppendS("\n\t");
905 #ifdef HAVE_EIGENVAL
906  StringAppendS("eigenvalues,");
907 #endif
908 #ifdef HAVE_GMS
909  StringAppendS("Gauss-Manin system,");
910 #endif
911 #ifdef HAVE_RATGRING
912  StringAppendS("ratGB,");
913 #endif
914  StringAppend("random=%d\n",siRandomStart);
915 
916 #define SI_SHOW_BUILTIN_MODULE(name) StringAppend(" %s", #name);
917  StringAppendS("built-in modules: {");
919  StringAppendS("}\n");
920 #undef SI_SHOW_BUILTIN_MODULE
921 
922  StringAppend("AC_CONFIGURE_ARGS = %s,\n"
923  "CC = %s,FLAGS : %s,\n"
924  "CXX = %s,FLAGS : %s,\n"
925  "DEFS : %s,CPPFLAGS : %s,\n"
926  "LDFLAGS : %s,LIBS : %s "
927 #ifdef __GNUC__
928  "(ver: " __VERSION__ ")"
929 #endif
930  "\n",AC_CONFIGURE_ARGS, CC,CFLAGS " " PTHREAD_CFLAGS,
931  CXX,CXXFLAGS " " PTHREAD_CFLAGS, DEFS,CPPFLAGS, LDFLAGS,
932  LIBS " " PTHREAD_LIBS);
935  StringAppendS("\n");
936  return StringEndS();
937 }
#define VERSION
Definition: factoryconf.h:282
void feStringAppendBrowsers(int warn)
Definition: fehelp.cc:340
char * fe_fgets_stdin_emu(const char *pr, char *s, int size)
Definition: feread.cc:254
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
Definition: feread.cc:34
char * fe_fgets(const char *pr, char *s, int size)
Definition: feread.cc:310
char * fe_fgets_stdin_drl(const char *pr, char *s, int size)
Definition: feread.cc:270
char * fe_fgets_dummy(const char *, char *, int)
Definition: feread.cc:451
SI_FOREACH_BUILTIN(SI_GET_BUILTIN_MOD_INIT0) }
#define SI_SHOW_BUILTIN_MODULE(name)
const char * singular_date
Definition: misc_ip.cc:779
#define SINGULAR_VERSION
Definition: mod2.h:85
#define MDEBUG
Definition: mod2.h:178
#define OM_TRACK
Definition: omalloc_debug.c:10
#define OM_CHECK
Definition: omalloc_debug.c:15
const BOOLEAN p_procs_dynamic
void feStringAppendResources(int warn)
Definition: reporter.cc:398

Variable Documentation

◆ add

STATIC_VAR unsigned add[] = {4, 2, 4, 2, 4, 6, 2, 6}

Definition at line 115 of file misc_ip.cc.

◆ m2_end_called

volatile BOOLEAN m2_end_called = FALSE

Definition at line 1096 of file misc_ip.cc.

◆ n_FlintQ

Definition at line 1208 of file misc_ip.cc.

◆ n_FlintZn

Definition at line 1207 of file misc_ip.cc.

◆ optionStruct

const struct soptionStruct optionStruct[]
Initial value:
=
{
{"prot", Sy_bit(OPT_PROT), ~Sy_bit(OPT_PROT) },
{"redSB", Sy_bit(OPT_REDSB), ~Sy_bit(OPT_REDSB) },
{"teach", Sy_bit(OPT_DEBUG), ~Sy_bit(OPT_DEBUG) },
{"fastHC", Sy_bit(OPT_FASTHC), ~Sy_bit(OPT_FASTHC) },
{"degBound", Sy_bit(OPT_DEGBOUND), ~Sy_bit(OPT_DEGBOUND) },
{"redTail", Sy_bit(OPT_REDTAIL), ~Sy_bit(OPT_REDTAIL) },
{"weightM", Sy_bit(OPT_WEIGHTM), ~Sy_bit(OPT_WEIGHTM) },
{"ne", 0, 0 }
}
#define OPT_SUGARCRIT
Definition: options.h:79
#define OPT_PROT
Definition: options.h:74
#define OPT_INFREDTAIL
Definition: options.h:93
#define OPT_WEIGHTM
Definition: options.h:96
#define OPT_REDTAIL_SYZ
Definition: options.h:86
#define OPT_REDTAIL
Definition: options.h:90
#define OPT_RETURN_SB
Definition: options.h:83
#define OPT_NOT_SUGAR
Definition: options.h:77
#define OPT_REDSB
Definition: options.h:75
#define OPT_NOTREGULARITY
Definition: options.h:95
#define OPT_DEBUG
Definition: options.h:80
#define OPT_MULTBOUND
Definition: options.h:88
#define OPT_STAIRCASEBOUND
Definition: options.h:87
#define OPT_INTERRUPT
Definition: options.h:78
#define OPT_DEGBOUND
Definition: options.h:89
#define OPT_NOT_BUCKETS
Definition: options.h:76
#define OPT_FASTHC
Definition: options.h:84
#define OPT_NO_SYZ_MINIM
Definition: options.h:82

Definition at line 442 of file misc_ip.cc.

◆ singular_date

const char* singular_date =__DATE__ " " __TIME__

Definition at line 779 of file misc_ip.cc.

◆ verboseStruct

const struct soptionStruct verboseStruct[]
Initial value:
=
{
{"yacc", Sy_bit(V_YACC), ~Sy_bit(V_YACC) },
{"redefine", Sy_bit(V_REDEFINE), ~Sy_bit(V_REDEFINE) },
{"reading", Sy_bit(V_READING), ~Sy_bit(V_READING) },
{"loadLib", Sy_bit(V_LOAD_LIB), ~Sy_bit(V_LOAD_LIB) },
{"debugLib", Sy_bit(V_DEBUG_LIB), ~Sy_bit(V_DEBUG_LIB) },
{"loadProc", Sy_bit(V_LOAD_PROC), ~Sy_bit(V_LOAD_PROC) },
{"defRes", Sy_bit(V_DEF_RES), ~Sy_bit(V_DEF_RES) },
{"Imap", Sy_bit(V_IMAP), ~Sy_bit(V_IMAP) },
{"prompt", Sy_bit(V_PROMPT), ~Sy_bit(V_PROMPT) },
{"length", Sy_bit(V_LENGTH), ~Sy_bit(V_LENGTH) },
{"notWarnSB",Sy_bit(V_NSB), ~Sy_bit(V_NSB) },
{"contentSB",Sy_bit(V_CONTENTSB), ~Sy_bit(V_CONTENTSB) },
{"findMonomials",Sy_bit(V_FINDMONOM),~Sy_bit(V_FINDMONOM)},
{"coefStrat",Sy_bit(V_COEFSTRAT), ~Sy_bit(V_COEFSTRAT)},
{"qringNF", Sy_bit(V_QRING), ~Sy_bit(V_QRING)},
{"ne", 0, 0 }
}
#define V_QRING
Definition: options.h:41
#define V_DEF_RES
Definition: options.h:49
#define V_INTERSECT_SYZ
Definition: options.h:68
#define V_ALLWARN
Definition: options.h:66
#define V_READING
Definition: options.h:45
#define V_COEFSTRAT
Definition: options.h:60
#define V_ASSIGN_NONE
Definition: options.h:69
#define V_CONTENTSB
Definition: options.h:55
#define V_DEBUG_LIB
Definition: options.h:47
#define V_MODPSOLVSB
Definition: options.h:57
#define V_LOAD_PROC
Definition: options.h:48
#define V_UPTORADICAL
Definition: options.h:58
#define V_FINDMONOM
Definition: options.h:59
#define V_CANCELUNIT
Definition: options.h:56
#define V_REDEFINE
Definition: options.h:44
#define V_INTERSECT_ELIM
Definition: options.h:67
#define V_NSB
Definition: options.h:54
#define V_LENGTH
Definition: options.h:63
#define V_IMAP
Definition: options.h:52
#define V_PROMPT
Definition: options.h:53
#define V_SHOW_USE
Definition: options.h:51

Definition at line 442 of file misc_ip.cc.