14 #define PLURAL_INTERNAL_DECLARATIONS 1 21 #include "factory/factory.h" 63 #ifdef READLINE_READLINE_H_OK 64 #include <readline/readline.h> 66 #ifndef RL_VERSION_MAJOR 67 #define RL_VERSION_MAJOR 0 72 #include <NTL/version.h> 73 #include <NTL/tools.h> 89 int ui=(int)mpz_get_si(n);
90 if ((((ui<<3)>>3)==ui)
91 && (mpz_cmp_si(n,(
long)ui)==0))
105 if ((((
unsigned long)i)==ui) && (((i<<3)>>3)==i))
124 unsigned *addv =
add;
125 unsigned int failures;
126 int bound_not_reached=1;
131 f = mpz_scan1 (t, 0);
132 mpz_div_2exp (t, t, f);
136 multiplicities[index++] =
f;
142 mpz_tdiv_qr_ui (q, r, t, 3);
151 multiplicities[index++] =
f;
156 mpz_tdiv_qr_ui (q, r, t, 5);
165 multiplicities[index++] =
f;
171 unsigned long last_f=0;
172 while (mpz_cmp_ui (t, 1) != 0)
174 mpz_tdiv_qr_ui (q, r, t, f);
178 if (mpz_cmp_ui (t, f) < 0)
182 if (failures > limit)
184 if ((bound!=0) && (f>
bound))
196 multiplicities[
index]++;
201 multiplicities[index-1]++;
211 return bound_not_reached;
219 unsigned long long k,
l,
i;
223 mpz_init_set_ui (last_f, 0);
224 mpz_init_set_ui (y, 2);
225 mpz_init_set_ui (x, 2);
226 mpz_init_set_ui (x1, 2);
227 mpz_init_set_ui (P, 1);
231 while (mpz_cmp_ui (n, 1) != 0)
239 mpz_add_ui (x, x, a);
247 if (mpz_cmp_ui (t1, 1) != 0)
255 if (mpz_cmp_ui (t1, 1) != 0)
261 for (i = 0; i <
k; i++)
265 mpz_add_ui (x, x, a);
275 mpz_add_ui (y, y, a);
279 while (mpz_cmp_ui (t1, 1) == 0);
281 mpz_divexact (n, n, t1);
283 if (!mpz_probab_prime_p (t1, 10))
288 mpn_random (&a_limb, (mp_size_t) 1);
297 if (mpz_cmp(t1,last_f)==0)
299 multiplicities[index-1]++;
305 multiplicities[index++] = 1;
311 if (mpz_probab_prime_p (n, 10))
313 if (mpz_cmp(n,last_f)==0)
315 multiplicities[index-1]++;
321 multiplicities[index++] = 1;
339 unsigned int division_limit;
341 if (mpz_sgn (t) == 0)
345 division_limit = mpz_sizeinbase (t, 2);
346 if (division_limit > 1000)
347 division_limit = 1000 * 1000;
349 division_limit = division_limit * division_limit;
353 if (mpz_cmp_ui (t, 1) != 0)
355 if (mpz_probab_prime_p (t, 10))
358 multiplicities[index++] = 1;
373 int* multiplicities = (
int*)
omAlloc0(1000*
sizeof(
int));
383 factor_gmp(nn,primes,multiplicities,index,pBound);
387 primesL->
Init(index);
388 for (i = 0; i <
index; i++)
398 multiplicitiesL->
Init(index);
399 for (i = 0; i <
index; i++)
402 multiplicitiesL->
m[
i].
data = (
void*)(
long)multiplicities[
i];
408 if (positive==-1) mpz_neg(nn,nn);
450 while (*ss!=
'\0') ss++;
460 if((lib!=
NULL)&&(*lib!=
'\0'))
462 Print(
"// proc %s from lib %s\n",s,lib);
483 sprintf(sing_file,
"%s/%s.sing", res_m, s);
496 s = (
char*)
omAlloc((length+20)*
sizeof(char));
497 got = fread(s,
sizeof(
char), length, fd);
501 Werror(
"Error while reading file %s", sing_file);
506 strcat(s,
"\n;return();\n\n");
515 Werror(
"no example for %s", str);
607 if(strcmp(n,
"get")==0)
616 if(strcmp(n,
"set")==0)
636 if(strcmp(n,
"none")==0)
642 for (i=0; (i==0) || (optionStruct[i-1].
setval!=0); i++)
644 if (strcmp(n,optionStruct[i].
name)==0)
654 WarnS(
"cannot set option");
665 else if ((strncmp(n,
"no",2)==0)
666 && (strcmp(n+2,optionStruct[i].name)==0))
673 WarnS(
"cannot clear option");
677 for (i=0; (i==0) || (verboseStruct[i-1].
setval!=0); i++)
679 if (strcmp(n,verboseStruct[i].
name)==0)
692 else if ((strncmp(n,
"no",2)==0)
693 && (strcmp(n+2,verboseStruct[i].name)==0))
707 Werror(
"unknown option `%s`",n);
718 else om_sing_opt_show_mem = 0;
734 for (i=0; optionStruct[
i].
setval!=0; i++)
736 if (optionStruct[i].
setval & tmp)
750 for (i=0; verboseStruct[
i].
setval!=0; i++)
752 if (verboseStruct[i].
setval & tmp)
773 #ifndef __GMP_BITS_PER_MP_LIMB 774 #define __GMP_BITS_PER_MP_LIMB GMP_LIMB_BITS 776 #include <flint/flint.h> 780 #ifndef MAKE_DISTRIBUTION 781 const char *singular_date=__DATE__
" " __TIME__;
787 StringAppend(
"Singular for %s version %s (%d, %d bit) %s #%s",
791 VERSION_DATE, GIT_VERSION);
793 singular_date, GIT_VERSION);
797 #if defined(mpir_version) 798 StringAppend(
"MPIR(%s)~GMP(%s),", mpir_version, gmp_version);
799 #elif defined(gmp_version) 817 #if defined(HAVE_DYN_RL) 831 #if defined(HAVE_READLINE) && !defined(FEREAD) 849 #ifdef HAVE_DYNAMIC_LOADING 881 #ifdef __OPTIMIZE_SIZE__ 887 #ifdef HAVE_GENERIC_ADD 892 #ifdef HAVE_GENERIC_MULT 914 #define SI_SHOW_BUILTIN_MODULE(name) StringAppend(" %s", #name); 918 #undef SI_SHOW_BUILTIN_MODULE 921 "CC = %s,FLAGS : %s,\n" 922 "CXX = %s,FLAGS : %s,\n" 923 "DEFS : %s,CPPFLAGS : %s,\n" 924 "LDFLAGS : %s,LIBS : %s " 926 "(ver: " __VERSION__
")" 928 "\n",AC_CONFIGURE_ARGS, CC,CFLAGS
" " PTHREAD_CFLAGS,
929 CXX,CXXFLAGS
" " PTHREAD_CFLAGS, DEFS,CPPFLAGS, LDFLAGS,
930 LIBS
" " PTHREAD_LIBS);
938 #if (OM_TRACK > 2) && defined(OM_TRACK_CUSTOM) 939 void p_SetRingOfLeftv(
leftv l, ring r)
951 poly
p=(poly)l->
data;
959 ideal I=(ideal)l->
data;
971 p_SetRingOfLeftv(&d->arg1, r);
972 if (d->argc>1) p_SetRingOfLeftv(&d->arg2, r);
973 if (d->argc>2) p_SetRingOfLeftv(&d->arg3, r);
977 printf(
"type %d not yet implementd in p_SetRingOfLeftv\n",l->
rtyp);
985 void listall(
int showproc)
988 PrintS(
"====== Top ==============\n");
996 Print(
"::%s, typ %s level %d data %lx",
1009 Print(
"(T)::%s, typ %s level %d data %lx\n",
1015 Print(
"====== %s ==============\n",
IDID(hh));
1026 Print(
"%s::%s, typ %s level %d data %lx\n",
1049 Print(
"%s typ %d in Top (should be in ring)\n",
IDID(hh),
IDTYP(hh));
1083 return si_fstat(fd,buf);
1101 if (File_Profiling!=
NULL) { fclose(File_Profiling); File_Profiling=
NULL; }
1102 m2_end_called =
TRUE;
1103 #ifdef HAVE_SIMPLEIPC 1110 #if PORTABLE_SEMAPHORES 1119 #endif // HAVE_SIMPLEIPC 1170 printf(
"Auf Wiedersehen.\n");
1172 printf(
"\n$Bye.\n");
1184 printf(
"\nhalt %d\n",i);
1196 fprintf(stderr,
"\nSingular error: no more memory\n");
1230 p.
ch=(int)(
long)a->
Data();
1260 float_len=(int)(
long)pnn->
Data();
1261 float_len2=float_len;
1265 float_len2=(int)(
long)pnn->
Data();
1288 if (h==
NULL)
goto crossprod_error;
1310 WerrorS(
"expected `crossprod(coeffs, ...)`");
1321 #ifndef __OPTIMIZE__ 1390 #ifdef _SC_NPROCESSORS_ONLN 1391 if ((cpu_n=sysconf(_SC_NPROCESSORS_ONLN))>cpus) cpus=cpu_n;
1392 #elif defined(_SC_NPROCESSORS_CONF) 1393 if ((cpu_n=sysconf(_SC_NPROCESSORS_CONF))>cpus) cpus=cpu_n;
int iiInitArithmetic()
initialisation of arithmetic structured data
BOOLEAN flintQ_InitChar(coeffs cf, void *infoStruct)
STATIC_VAR n_coeffType n_FlintZn
static void factor_gmp(mpz_t t, lists primes, int *multiplicities, int &index, unsigned long bound)
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.
void omSingOutOfMemoryFunc()
const CanonicalForm int s
This file provides miscellaneous functionality.
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
const CanonicalForm int const CFList const Variable & y
void factoryseed(int s)
random seed initializer
Class used for (list of) interpreter objects.
ideal k_gnc_gr_bba(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat, const ring _currRing)
void singular_example(char *str)
static char * iiGetLibName(const procinfov pi)
find the library of an proc
EXTERN_VAR BBA_Proc gnc_gr_mora
static FORCE_INLINE void number2mpz(number n, mpz_t m)
static CanonicalForm bound(const CFMatrix &M)
void feStringAppendResources(int warn)
only used if HAVE_RINGS is defined
EXTERN_VAR link_list ssiToBeClosed
const BOOLEAN p_procs_dynamic
#define SHORT_REAL_LENGTH
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_gr_bba(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat, const ring _currRing)
Modified Plural's Buchberger's algorithmus.
static void * feOptValue(feOptIndex opt)
coeffs flintQInitCfByName(char *s, n_coeffType n)
EXTERN_VAR volatile BOOLEAN ssiToBeClosed_inactive
BOOLEAN naInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
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.
used for all transcendental extensions, i.e., the top-most extension in an extension tower is transce...
STATIC_VAR n_coeffType n_FlintQ
static int si_min(const int a, const int b)
volatile BOOLEAN m2_end_called
static void factor_using_pollard_rho(mpz_t n, unsigned long a, lists primes, int *multiplicities, int &index)
EXTERN_VAR struct fe_option feOptSpec[]
void setListEntry(lists L, int index, mpz_t n)
static char * feResource(feResourceConfig config, int warn)
const struct soptionStruct optionStruct[]
char * fe_fgets(const char *pr, char *s, int size)
VAR sipc_sem_t * semaphore[SIPC_MAX_SEMAPHORES]
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
int singular_fstat(int fd, struct stat *buf)
static BOOLEAN ii_FlintQ_init(leftv res, leftv a)
char * fe_fgets_dummy(const char *, char *, int)
coeffs nrnInitCfByName(char *s, n_coeffType n)
const char * feSetOptValue(feOptIndex opt, char *optarg)
void feInitResources(const char *argv0)
void WerrorS(const char *s)
static BOOLEAN iiFloat(leftv res, leftv pnn)
static FORCE_INLINE number mpz2number(mpz_t m)
BOOLEAN iiLibCmd(char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
BOOLEAN n2pInitChar(coeffs cf, void *infoStruct)
#define MAKE_DISTRIBUTION
real floating point (GMP) numbers
void monitor(void *F, int mode)
short float_len2
additional char-flags, rInit
static BOOLEAN rField_has_simple_inverse(const ring r)
void feStringAppendBrowsers(int warn)
void setListEntry_ui(lists L, int index, unsigned long ui)
static BOOLEAN iiCrossProd(leftv res, leftv args)
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
single prescision (6,6) real numbers
void nRegisterCfByName(cfInitCfByNameProc p, n_coeffType n)
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
short float_len
additional char-flags, rInit
#define SI_RESTORE_OPT(A, B)
Coefficient rings, fields and other domains suitable for Singular polynomials.
#define TEST_OPT_INTSTRATEGY
n_coeffType nRegister(n_coeffType n, cfInitCharProc p)
#define p_SetRingOfLm(p, r)
The main handler for Singular numbers which are suitable for Singular polynomials.
char * fe_fgets_stdin_emu(const char *pr, char *s, int size)
void StringSetS(const char *st)
int status int void * buf
BOOLEAN slPrepClose(si_link l)
void StringAppendS(const char *st)
static BOOLEAN ii_FlintZn_init(leftv res, leftv a)
void fe_reset_input_mode()
SI_FOREACH_BUILTIN(SI_GET_BUILTIN_MOD_INIT0) }
VAR FILE * File_Profiling
#define OPT_STAIRCASEBOUND
only used if HAVE_RINGS is defined
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
void PrintS(const char *s)
ideal k_gnc_gr_mora(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat, const ring _currRing)
const struct soptionStruct verboseStruct[]
char name(const Variable &v)
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
BOOLEAN iiEStart(char *example, procinfo *pi)
static int index(p_Length length, p_Ord ord)
INLINE_THIS void Init(int l=0)
const Variable & v
< [in] a sqrfree bivariate poly
BOOLEAN flintZn_InitChar(coeffs cf, void *infoStruct)
static BOOLEAN rField_is_Ring(const ring r)
EXTERN_VAR BBA_Proc sca_bba
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...
const char * Tok2Cmdname(int tok)
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic ...
EXTERN_VAR BBA_Proc gnc_gr_bba
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 (...
void killhdl(idhdl h, package proot)
static BOOLEAN length(leftv result, leftv arg)
VAR int sem_acquired[SIPC_MAX_SEMAPHORES]
INST_VAR sleftv sLastPrinted
#define SI_SAVE_OPT(A, B)
#define SIPC_MAX_SEMAPHORES
STATIC_VAR unsigned short primes[]
primes, primes_len: used to step through possible extensions
STATIC_VAR unsigned add[]
coeffs flintZnInitCfByName(char *s, n_coeffType n)
void Clean(ring r=currRing)
#define SI_SHOW_BUILTIN_MODULE(name)
EXTERN_VAR BBA_Proc sca_gr_bba
#define TEST_RINGDEP_OPTS
#define omCheckAddr(addr)
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), where m is the long representing n in C: TRUE iff (Im(n) != 0 and Im(n) >= 0) or (Im(n) == 0 and Re(n) >= 0) in K(a)/<p(a)>: TRUE iff (n != 0 and (LC(n) > 0 or deg(n) > 0)) in K(t_1, ..., t_n): TRUE iff (LC(numerator(n) is a constant and > 0) or (LC(numerator(n) is not a constant) in Z/2^kZ: TRUE iff 0 < n <= 2^(k-1) in Z/mZ: TRUE iff the internal mpz is greater than zero in Z: TRUE iff n > 0
void iiCheckPack(package &p)
int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
BOOLEAN slClose(si_link l)
#define OPT_NOTREGULARITY
char * fe_fgets_stdin_drl(const char *pr, char *s, int size)
static int factor_using_division(mpz_t t, unsigned int limit, lists primes, int *multiplicities, int &index, unsigned long bound)
char * iiGetLibProcBuffer(procinfo *pi, int part)
void Werror(const char *fmt,...)
EXTERN_VAR BBA_Proc sca_mora
used to represent polys as coeffcients
BOOLEAN setOption(leftv res, leftv v)
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
BOOLEAN ntInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
VAR BOOLEAN singular_in_batchmode