14 #define PLURAL_INTERNAL_DECLARATIONS 1
24 #include "factory/factory.h"
68 #ifdef READLINE_READLINE_H_OK
69 #include <readline/readline.h>
71 #ifndef RL_VERSION_MAJOR
72 #define RL_VERSION_MAJOR 0
77 #include <NTL/version.h>
78 #include <NTL/tools.h>
94 int ui=(int)mpz_get_si(n);
95 if ((((ui<<3)>>3)==ui)
96 && (mpz_cmp_si(n,(
long)ui)==0))
110 if ((((
unsigned long)
i)==ui) && (((i<<3)>>3)==
i))
122 static unsigned add[] = {4, 2, 4, 2, 4, 6, 2, 6};
129 unsigned *addv =
add;
130 unsigned int failures;
131 int bound_not_reached=1;
136 f = mpz_scan1 (t, 0);
137 mpz_div_2exp (t, t,
f);
141 multiplicities[
index++] =
f;
147 mpz_tdiv_qr_ui (q, r, t, 3);
156 multiplicities[
index++] =
f;
161 mpz_tdiv_qr_ui (q, r, t, 5);
170 multiplicities[
index++] =
f;
176 unsigned long last_f=0;
177 while (mpz_cmp_ui (t, 1) != 0)
179 mpz_tdiv_qr_ui (q, r, t,
f);
183 if (mpz_cmp_ui (t,
f) < 0)
187 if (failures > limit)
201 multiplicities[
index]++;
206 multiplicities[
index-1]++;
216 return bound_not_reached;
224 unsigned long long k,
l,
i;
228 mpz_init_set_ui (last_f, 0);
229 mpz_init_set_ui (
y, 2);
230 mpz_init_set_ui (
x, 2);
231 mpz_init_set_ui (x1, 2);
232 mpz_init_set_ui (P, 1);
236 while (mpz_cmp_ui (n, 1) != 0)
244 mpz_add_ui (
x,
x, a);
252 if (mpz_cmp_ui (t1, 1) != 0)
260 if (mpz_cmp_ui (t1, 1) != 0)
266 for (
i = 0;
i <
k;
i++)
270 mpz_add_ui (
x,
x, a);
280 mpz_add_ui (
y,
y, a);
284 while (mpz_cmp_ui (t1, 1) == 0);
286 mpz_divexact (n, n, t1);
288 if (!mpz_probab_prime_p (t1, 10))
293 mpn_random (&a_limb, (mp_size_t) 1);
302 if (mpz_cmp(t1,last_f)==0)
304 multiplicities[
index-1]++;
310 multiplicities[
index++] = 1;
316 if (mpz_probab_prime_p (n, 10))
318 if (mpz_cmp(n,last_f)==0)
320 multiplicities[
index-1]++;
326 multiplicities[
index++] = 1;
344 unsigned int division_limit;
346 if (mpz_sgn (t) == 0)
350 division_limit = mpz_sizeinbase (t, 2);
351 if (division_limit > 1000)
352 division_limit = 1000 * 1000;
354 division_limit = division_limit * division_limit;
358 if (mpz_cmp_ui (t, 1) != 0)
360 if (mpz_probab_prime_p (t, 10))
363 multiplicities[
index++] = 1;
378 int* multiplicities = (
int*)
omAlloc0(1000*
sizeof(
int));
407 multiplicitiesL->
m[
i].
data = (
void*)(
long)multiplicities[
i];
413 if (positive==-1) mpz_neg(nn,nn);
455 while (*ss!=
'\0') ss++;
465 if((lib!=
NULL)&&(*lib!=
'\0'))
467 Print(
"// proc %s from lib %s\n",
s,lib);
488 sprintf(sing_file,
"%s/%s.sing", res_m,
s);
502 got = fread(
s,
sizeof(
char),
length,
fd);
506 Werror(
"Error while reading file %s", sing_file);
511 strcat(
s,
"\n;return();\n\n");
520 Werror(
"no example for %s", str);
612 if(strcmp(n,
"get")==0)
621 if(strcmp(n,
"set")==0)
641 if(strcmp(n,
"none")==0)
659 WarnS(
"cannot set option");
670 else if ((strncmp(n,
"no",2)==0)
678 WarnS(
"cannot clear option");
697 else if ((strncmp(n,
"no",2)==0)
712 Werror(
"unknown option `%s`",n);
721 extern int om_sing_opt_show_mem;
723 else om_sing_opt_show_mem = 0;
778 #ifndef __GMP_BITS_PER_MP_LIMB
779 #define __GMP_BITS_PER_MP_LIMB GMP_LIMB_BITS
781 #include <flint/flint.h>
785 #ifndef MAKE_DISTRIBUTION
792 StringAppend(
"Singular for %s version %s (%d, %d bit) %s #%s",
795 #ifdef MAKE_DISTRIBUTION
796 VERSION_DATE, GIT_VERSION);
802 #if defined(mpir_version)
803 StringAppend(
"MPIR(%s)~GMP(%s),", mpir_version, gmp_version);
804 #elif defined(gmp_version)
822 #if defined(HAVE_DYN_RL)
836 #if defined(HAVE_READLINE) && !defined(FEREAD)
854 #ifdef HAVE_DYNAMIC_LOADING
886 #ifdef __OPTIMIZE_SIZE__
892 #ifdef HAVE_GENERIC_ADD
897 #ifdef HAVE_GENERIC_MULT
919 #define SI_SHOW_BUILTIN_MODULE(name) StringAppend(" %s", #name);
923 #undef SI_SHOW_BUILTIN_MODULE
926 "CC = %s,FLAGS : %s,\n"
927 "CXX = %s,FLAGS : %s,\n"
928 "DEFS : %s,CPPFLAGS : %s,\n"
929 "LDFLAGS : %s,LIBS : %s "
931 "(ver: " __VERSION__
")"
933 "\n",AC_CONFIGURE_ARGS, CC,CFLAGS
" " PTHREAD_CFLAGS,
934 CXX,CXXFLAGS
" " PTHREAD_CFLAGS, DEFS,CPPFLAGS, LDFLAGS,
935 LIBS
" " PTHREAD_LIBS);
943 #if (OM_TRACK > 2) && defined(OM_TRACK_CUSTOM)
944 void p_SetRingOfLeftv(
leftv l, ring r)
956 poly
p=(poly)
l->data;
964 ideal I=(ideal)
l->data;
976 p_SetRingOfLeftv(&d->arg1, r);
977 if (d->argc>1) p_SetRingOfLeftv(&d->arg2, r);
978 if (d->argc>2) p_SetRingOfLeftv(&d->arg3, r);
982 printf(
"type %d not yet implementd in p_SetRingOfLeftv\n",
l->rtyp);
990 void listall(
int showproc)
993 PrintS(
"====== Top ==============\n");
1001 Print(
"::%s, typ %s level %d data %lx",
1014 Print(
"(T)::%s, typ %s level %d data %lx\n",
1020 Print(
"====== %s ==============\n",
IDID(hh));
1031 Print(
"%s::%s, typ %s level %d data %lx\n",
1054 Print(
"%s typ %d in Top (should be in ring)\n",
IDID(hh),
IDTYP(hh));
1088 return si_fstat(
fd,
buf);
1108 #ifdef HAVE_SIMPLEIPC
1115 #if PORTABLE_SEMAPHORES
1175 printf(
"Auf Wiedersehen.\n");
1177 printf(
"\n$Bye.\n");
1189 printf(
"\nhalt %d\n",
i);
1201 fprintf(stderr,
"\nSingular error: no more memory\n");
1235 p.ch=(int)(
long)a->
Data();
1265 float_len=(int)(
long)pnn->
Data();
1266 float_len2=float_len;
1270 float_len2=(int)(
long)pnn->
Data();
1293 if (
h==
NULL)
goto crossprod_error;
1296 if (
h->Typ()!=
CRING_CMD)
goto crossprod_error;
1315 WerrorS(
"expected `crossprod(coeffs, ...)`");
1326 #ifndef __OPTIMIZE__
1395 #ifdef _SC_NPROCESSORS_ONLN
1396 if ((cpu_n=sysconf(_SC_NPROCESSORS_ONLN))>cpus) cpus=cpu_n;
1397 #elif defined(_SC_NPROCESSORS_CONF)
1398 if ((cpu_n=sysconf(_SC_NPROCESSORS_CONF))>cpus) cpus=cpu_n;
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
Class used for (list of) interpreter objects.
INLINE_THIS void Init(int l=0)
BOOLEAN singular_in_batchmode
Coefficient rings, fields and other domains suitable for Singular polynomials.
@ n_R
single prescision (6,6) real numbers
@ n_polyExt
used to represent polys as coeffcients
@ 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,...
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
const CanonicalForm int s
const CanonicalForm int const CFList const Variable & y
const Variable & v
< [in] a sqrfree bivariate poly
char name(const Variable &v)
void WerrorS(const char *s)
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
const char * feSetOptValue(feOptIndex opt, char *optarg)
static void * feOptValue(feOptIndex opt)
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_stdin_emu(const char *pr, char *s, int size)
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_dummy(const char *, char *, int)
void fe_reset_input_mode()
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)
static unsigned short primes[]
primes, primes_len: used to step through possible extensions
const char * Tok2Cmdname(int tok)
ideal k_gnc_gr_mora(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat, const ring _currRing)
ideal k_gnc_gr_bba(const ideal F, const ideal Q, const intvec *, const intvec *, 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)
BOOLEAN iiLibCmd(char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
BOOLEAN iiEStart(char *example, procinfo *pi)
SI_FOREACH_BUILTIN(SI_GET_BUILTIN_MOD_INIT0) }
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 intvec *, kStrategy strat, const ring _currRing)
Modified modern Sinuglar Buchberger's algorithm.
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.
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.
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)
const struct soptionStruct verboseStruct[]
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)
const char * singular_date
static FORCE_INLINE number mpz2number(mpz_t m)
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)
static FORCE_INLINE void number2mpz(number n, mpz_t m)
void singular_example(char *str)
static BOOLEAN ii_FlintZn_init(leftv res, leftv a)
static n_coeffType n_FlintQ
const struct soptionStruct optionStruct[]
void setListEntry_ui(lists L, int index, unsigned long ui)
volatile BOOLEAN m2_end_called
static n_coeffType n_FlintZn
This file provides miscellaneous functionality.
#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 omCheckAddr(addr)
void omPrintStats(FILE *fd)
#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)
const BOOLEAN p_procs_dynamic
static int index(p_Length length, p_Ord ord)
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_is_Ring(const ring r)
static BOOLEAN rField_has_simple_inverse(const ring r)
coeffs nrnInitCfByName(char *s, n_coeffType n)
int sem_acquired[SIPC_MAX_SEMAPHORES]
sipc_sem_t * semaphore[SIPC_MAX_SEMAPHORES]
int status int void * buf
BOOLEAN slPrepClose(si_link l)
BOOLEAN slClose(si_link l)
volatile BOOLEAN ssiToBeClosed_inactive
#define SIPC_MAX_SEMAPHORES
BOOLEAN ntInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.