14#define PLURAL_INTERNAL_DECLARATIONS 1
62 #ifdef READLINE_READLINE_H_OK
63 #include <readline/readline.h>
65 #ifndef RL_VERSION_MAJOR
66 #define RL_VERSION_MAJOR 0
71#include <NTL/version.h>
80 int ui=(int)mpz_get_si(n);
81 if ((((ui<<3)>>3)==ui)
82 && (mpz_cmp_si(n,(
long)ui)==0))
96 if ((((
unsigned long)
i)==ui) && (((
i<<3)>>3)==
i))
115 unsigned *addv =
add;
116 unsigned int failures;
117 int bound_not_reached=1;
122 f = mpz_scan1 (t, 0);
123 mpz_div_2exp (t, t,
f);
127 multiplicities[
index++] =
f;
133 mpz_tdiv_qr_ui (q, r, t, 3);
142 multiplicities[
index++] =
f;
147 mpz_tdiv_qr_ui (q, r, t, 5);
156 multiplicities[
index++] =
f;
162 unsigned long last_f=0;
163 while (mpz_cmp_ui (t, 1) != 0)
165 mpz_tdiv_qr_ui (q, r, t,
f);
169 if (mpz_cmp_ui (t,
f) < 0)
173 if (failures > limit)
187 multiplicities[
index]++;
192 multiplicities[
index-1]++;
202 return bound_not_reached;
210 unsigned long long k,
l,
i;
214 mpz_init_set_ui (last_f, 0);
215 mpz_init_set_ui (
y, 2);
216 mpz_init_set_ui (
x, 2);
217 mpz_init_set_ui (x1, 2);
218 mpz_init_set_ui (P, 1);
222 while (mpz_cmp_ui (n, 1) != 0)
230 mpz_add_ui (
x,
x, a);
238 if (mpz_cmp_ui (t1, 1) != 0)
246 if (mpz_cmp_ui (t1, 1) != 0)
252 for (
i = 0;
i <
k;
i++)
256 mpz_add_ui (
x,
x, a);
266 mpz_add_ui (
y,
y, a);
270 while (mpz_cmp_ui (t1, 1) == 0);
272 mpz_divexact (n, n, t1);
274 if (!mpz_probab_prime_p (t1, 10))
279 mpn_random (&a_limb, (mp_size_t) 1);
288 if (mpz_cmp(t1,last_f)==0)
290 multiplicities[
index-1]++;
296 multiplicities[
index++] = 1;
302 if (mpz_probab_prime_p (n, 10))
304 if (mpz_cmp(n,last_f)==0)
306 multiplicities[
index-1]++;
312 multiplicities[
index++] = 1;
330 unsigned int division_limit;
332 if (mpz_sgn (t) == 0)
336 division_limit = mpz_sizeinbase (t, 2);
337 if (division_limit > 1000)
338 division_limit = 1000 * 1000;
340 division_limit = division_limit * division_limit;
344 if (mpz_cmp_ui (t, 1) != 0)
346 if (mpz_probab_prime_p (t, 10))
349 multiplicities[
index++] = 1;
364 int* multiplicities = (
int*)
omAlloc0(1000*
sizeof(
int));
393 multiplicitiesL->
m[
i].
data = (
void*)(
long)multiplicities[
i];
399 if (positive==-1) mpz_neg(nn,nn);
437 while (*ss!=
'\0') ss++;
447 if((lib!=
NULL)&&(*lib!=
'\0'))
449 Print(
"// proc %s from lib %s\n",
s,lib);
470 snprintf(sing_file,
MAXPATHLEN,
"%s/%s.sing", res_m,
s);
484 got = fread(
s,
sizeof(
char),
length,
fd);
488 Werror(
"Error while reading file %s", sing_file);
493 strcat(
s,
"\n;return();\n\n");
502 Werror(
"no example for %s", str);
596 if(strcmp(n,
"get")==0)
605 if(strcmp(n,
"set")==0)
625 if(strcmp(n,
"none")==0)
643 WarnS(
"cannot set option");
654 else if ((strncmp(n,
"no",2)==0)
662 WarnS(
"cannot clear option");
681 else if ((strncmp(n,
"no",2)==0)
696 Werror(
"unknown option `%s`",n);
761#ifndef __GMP_BITS_PER_MP_LIMB
762#define __GMP_BITS_PER_MP_LIMB GMP_LIMB_BITS
764#include <flint/flint.h>
768#ifndef MAKE_DISTRIBUTION
769const char *singular_date = __DATE__
" " __TIME__;
775 StringAppend(
"Singular for %s version %s (%d, %d bit) %s",
785#if defined(mpir_version)
786 StringAppend(
"MPIR(%s)~GMP(%s),", mpir_version, gmp_version);
787#elif defined(gmp_version)
806#if defined(HAVE_DYN_RL)
820 #if defined(HAVE_READLINE) && !defined(FEREAD)
834 #if defined(__GNUC__) && (__GNUC__<9) &&!defined(__clang__)
845#ifdef HAVE_DYNAMIC_LOADING
848#ifdef HAVE_DYNANIC_PPROCS
882#ifdef __OPTIMIZE_SIZE__
889 #ifdef NTL_AVOID_BRANCHING
890 #undef HAVE_GENERIC_ADD
893#ifdef HAVE_GENERIC_ADD
898#ifdef HAVE_GENERIC_MULT
920#define SI_SHOW_BUILTIN_MODULE(name) StringAppend(" %s", #name);
924#undef SI_SHOW_BUILTIN_MODULE
927 "CC = %s,FLAGS : %s,\n"
928 "CXX = %s,FLAGS : %s,\n"
929 "DEFS : %s,CPPFLAGS : %s,\n"
930 "LDFLAGS : %s,LIBS : %s "
932 "(ver: " __VERSION__
")"
934 "\n",AC_CONFIGURE_ARGS, CC,CFLAGS
" " PTHREAD_CFLAGS,
935 CXX,CXXFLAGS
" " PTHREAD_CFLAGS, DEFS,CPPFLAGS, LDFLAGS,
936 LIBS
" " PTHREAD_LIBS);
944#if (OM_TRACK > 2) && defined(OM_TRACK_CUSTOM)
945void p_SetRingOfLeftv(
leftv l, ring r)
957 poly
p=(poly)
l->data;
965 ideal I=(ideal)
l->data;
977 p_SetRingOfLeftv(&d->arg1, r);
978 if (d->argc>1) p_SetRingOfLeftv(&d->arg2, r);
979 if (d->argc>2) p_SetRingOfLeftv(&d->arg3, r);
983 printf(
"type %d not yet implementd in p_SetRingOfLeftv\n",
l->rtyp);
991void listall(
int showproc)
994 PrintS(
"====== Top ==============\n");
1002 Print(
"::%s, typ %s level %d data %lx",
1015 Print(
"(T)::%s, typ %s level %d data %lx\n",
1021 Print(
"====== %s ==============\n",
IDID(hh));
1032 Print(
"%s::%s, typ %s level %d data %lx\n",
1055 Print(
"%s typ %d in Top (should be in ring)\n",
IDID(hh),
IDTYP(hh));
1089 return si_fstat(
fd,
buf);
1118 snprintf(
buf,20,
"/tmp/sing_log.%d",pid);
1123#ifdef HAVE_SIMPLEIPC
1130#if PORTABLE_SEMAPHORES
1184 printf(
"Auf Wiedersehen.\n");
1188 printf(
"\nhalt %d\n",
i);
1201 fprintf(stderr,
"\nSingular error: no more memory\n");
1219 p.ch=(int)(
long)a->
Data();
1240#if __FLINT_RELEASE >= 20503
1245 WerrorS(
"at least one name required");
1254 par.names=(
char**)
omAlloc(par.N*
sizeof(
char*));
1264 for(
i=par.N-1;
i>=0;
i--)
1274 package save=currPack;
1282#if __FLINT_RELEASE >= 20503
1304 float_len=(int)(
long)pnn->
Data();
1305 float_len2=float_len;
1309 float_len2=(int)(
long)pnn->
Data();
1332 if (
h==
NULL)
goto crossprod_error;
1335 if (
h->Typ()!=
CRING_CMD)
goto crossprod_error;
1354 WerrorS(
"expected `crossprod(coeffs, ...)`");
1442 #ifdef _SC_NPROCESSORS_ONLN
1443 if ((cpu_n=sysconf(_SC_NPROCESSORS_ONLN))>cpus) cpus=cpu_n;
1444 #elif defined(_SC_NPROCESSORS_CONF)
1445 if ((cpu_n=sysconf(_SC_NPROCESSORS_CONF))>cpus) cpus=cpu_n;
1448 char *env_cpu=
getenv(
"SINGULAR_CPUS");
1451 int t=atoi(env_cpu);
1452 if ((t>=0)&&(t<cpus)) cpus=t;
BOOLEAN naInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
BOOLEAN n2pInitChar(coeffs cf, void *infoStruct)
static int si_min(const int a, const int b)
static CanonicalForm bound(const CFMatrix &M)
void factoryseed(int s)
random seed initializer
VAR void(* factoryError)(const char *s)
Class used for (list of) interpreter objects.
INLINE_THIS void Init(int l=0)
VAR BOOLEAN singular_in_batchmode
Coefficient rings, fields and other domains suitable for Singular polynomials.
static FORCE_INLINE void number2mpz(number n, coeffs c, mpz_t m)
static FORCE_INLINE number mpz2number(mpz_t m, coeffs c)
@ n_R
single prescision (6,6) real numbers
@ n_FlintQrat
rational function field over Q
@ n_polyExt
used to represent polys as coefficients
@ n_Q
rational (GMP) numbers
@ n_algExt
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic
@ n_Zn
only used if HAVE_RINGS is defined
@ n_long_R
real floating point (GMP) numbers
@ n_transExt
used for all transcendental extensions, i.e., the top-most extension in an extension tower is transce...
@ n_Z
only used if HAVE_RINGS is defined
@ n_nTupel
n-tupel of cf: ZZ/p1,... ZZ/pn, R, long_R
short float_len2
additional char-flags, rInit
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),...
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
short float_len
additional char-flags, rInit
#define MAKE_DISTRIBUTION
const CanonicalForm int s
const CanonicalForm int const CFList const Variable & y
const Variable & v
< [in] a sqrfree bivariate poly
‘factory.h’ is the user interface to Factory.
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
void WerrorS(const char *s)
const char * feSetOptValue(feOptIndex opt, char *optarg)
static void * feOptValue(feOptIndex opt)
EXTERN_VAR struct fe_option feOptSpec[]
static char * feResource(feResourceConfig config, int warn)
void feInitResources(const char *argv0)
void monitor(void *F, int mode)
void feStringAppendBrowsers(int warn)
char * fe_fgets_dummy(const char *, char *, int)
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
char * fe_fgets(const char *pr, char *s, int size)
char * fe_fgets_stdin_drl(const char *pr, char *s, int size)
char * fe_fgets_stdin_emu(const char *pr, char *s, int size)
void fe_reset_input_mode()
VAR FILE * File_Profiling
VAR BOOLEAN File_Log_written
BOOLEAN flintQ_InitChar(coeffs cf, void *infoStruct)
coeffs flintQInitCfByName(char *s, n_coeffType n)
BOOLEAN flintZn_InitChar(coeffs cf, void *infoStruct)
coeffs flintZnInitCfByName(char *s, n_coeffType n)
EXTERN_VAR BBA_Proc gnc_gr_bba
EXTERN_VAR BBA_Proc gnc_gr_mora
EXTERN_VAR BBA_Proc sca_gr_bba
EXTERN_VAR BBA_Proc sca_mora
EXTERN_VAR BBA_Proc sca_bba
STATIC_VAR unsigned short primes[]
primes, primes_len: used to step through possible extensions
const char * Tok2Cmdname(int tok)
static int RingDependend(int t)
ideal k_gnc_gr_bba(const ideal F, const ideal Q, const intvec *, const bigintmat *, kStrategy strat, const ring _currRing)
ideal k_gnc_gr_mora(const ideal F, const ideal Q, const intvec *, const bigintmat *, kStrategy strat, const ring _currRing)
static BOOLEAN length(leftv result, leftv arg)
int iiInitArithmetic()
initialisation of arithmetic structured data
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
void killhdl(idhdl h, package proot)
const struct soptionStruct verboseStruct[]
const struct soptionStruct optionStruct[]
int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
BOOLEAN iiEStart(char *example, procinfo *pi)
BOOLEAN iiLibCmd(const char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
char * iiGetLibProcBuffer(procinfo *pi, int part)
void iiCheckPack(package &p)
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 (...
static char * iiGetLibName(const procinfov pi)
find the library of an proc
ideal k_sca_bba(const ideal F, const ideal Q, const intvec *, const bigintmat *, kStrategy strat, const ring _currRing)
Modified modern Sinuglar Buchberger's algorithm.
ideal k_sca_gr_bba(const ideal F, const ideal Q, const intvec *, const bigintmat *, kStrategy strat, const ring _currRing)
Modified Plural's Buchberger's algorithmus.
ideal k_sca_mora(const ideal F, const ideal Q, const intvec *, const bigintmat *, kStrategy strat, const ring _currRing)
Modified modern Sinuglar Mora's algorithm.
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.
static int factor_using_division(mpz_t t, unsigned int limit, lists primes, int *multiplicities, int &index, unsigned long bound)
int singular_fstat(int fd, struct stat *buf)
#define SI_SHOW_BUILTIN_MODULE(name)
static void factor_using_pollard_rho(mpz_t n, unsigned long a, lists primes, int *multiplicities, int &index)
static BOOLEAN iiCrossProd(leftv res, leftv args)
static BOOLEAN ii_FlintQ_init(leftv res, leftv a)
int flint_mod_init(SModulFunctions *psModulFunctions)
STATIC_VAR n_coeffType n_FlintQ
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,...
void omSingOutOfMemoryFunc()
BOOLEAN setOption(leftv res, leftv v)
static void factor_gmp(mpz_t t, lists primes, int *multiplicities, int &index, unsigned long bound)
static BOOLEAN iiFloat(leftv res, leftv pnn)
void setListEntry(lists L, int index, mpz_t n)
void singular_example(char *str)
static BOOLEAN ii_FlintZn_init(leftv res, leftv a)
void setListEntry_ui(lists L, int index, unsigned long ui)
STATIC_VAR n_coeffType n_FlintZn
static void callWerrorS(const char *s)
volatile BOOLEAN m2_end_called
STATIC_VAR unsigned add[]
This file provides miscellaneous functionality.
#define SI_FOREACH_BUILTIN(add)
Data for type_of_LIB to determine built-in modules, use add(name) to add built-in library to macro.
#define p_SetRingOfLm(p, r)
The main handler for Singular numbers which are suitable for Singular polynomials.
void nRegisterCfByName(cfInitCfByNameProc p, n_coeffType n)
n_coeffType nRegister(n_coeffType n, cfInitCharProc p)
#define SHORT_REAL_LENGTH
#define omFreeSize(addr, size)
#define omCheckAddr(addr)
#define omFreeBinAddr(addr)
#define SI_SAVE_OPT(A, B)
#define TEST_OPT_INTSTRATEGY
#define OPT_NOTREGULARITY
#define OPT_STAIRCASEBOUND
#define TEST_RINGDEP_OPTS
#define SI_RESTORE_OPT(A, B)
static int index(p_Length length, p_Ord ord)
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
void StringSetS(const char *st)
void StringAppendS(const char *st)
void PrintS(const char *s)
void feStringAppendResources(int warn)
void Werror(const char *fmt,...)
static BOOLEAN rField_has_simple_inverse(const ring r)
#define rField_is_Ring(R)
coeffs nrnInitCfByName(char *s, n_coeffType)
VAR sipc_sem_t * semaphore[SIPC_MAX_SEMAPHORES]
VAR int sem_acquired[SIPC_MAX_SEMAPHORES]
int status int void * buf
BOOLEAN slPrepClose(si_link l)
BOOLEAN slClose(si_link l)
EXTERN_VAR volatile BOOLEAN ssiToBeClosed_inactive
EXTERN_VAR link_list ssiToBeClosed
#define SIPC_MAX_SEMAPHORES
INST_VAR sleftv sLastPrinted
int name
New type name for int.
BOOLEAN ntInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.