21 #include <factory/factory.h>
51 int ui=(
int)mpz_get_si(n);
52 if ((((ui<<3)>>3)==ui)
53 && (mpz_cmp_si(n,(
long)ui)==0))
67 if ((((
unsigned long)i)==ui) && (((i<<3)>>3)==i))
79 static unsigned add[] = {4, 2, 4, 2, 4, 6, 2, 6};
87 unsigned int failures;
88 int bound_not_reached=1;
94 mpz_div_2exp (t, t, f);
98 multiplicities[index++] =
f;
104 mpz_tdiv_qr_ui (q, r, t, 3);
105 if (mpz_cmp_ui (r, 0) != 0)
113 multiplicities[index++] =
f;
118 mpz_tdiv_qr_ui (q, r, t, 5);
119 if (mpz_cmp_ui (r, 0) != 0)
127 multiplicities[index++] =
f;
133 unsigned long last_f=0;
134 while (mpz_cmp_ui (t, 1) != 0)
136 mpz_tdiv_qr_ui (q, r, t, f);
137 if (mpz_cmp_ui (r, 0) != 0)
140 if (mpz_cmp_ui (t, f) < 0)
144 if (failures > limit)
146 if ((bound!=0) && (f>
bound))
158 multiplicities[
index]++;
163 multiplicities[index-1]++;
173 return bound_not_reached;
181 unsigned long long k,
l,
i;
185 mpz_init_set_si (last_f, 0);
186 mpz_init_set_si (y, 2);
187 mpz_init_set_si (x, 2);
188 mpz_init_set_si (x1, 2);
189 mpz_init_set_ui (P, 1);
193 while (mpz_cmp_ui (n, 1) != 0)
201 mpz_add_ui (x, x, a);
209 if (mpz_cmp_ui (t1, 1) != 0)
217 if (mpz_cmp_ui (t1, 1) != 0)
223 for (i = 0; i <
k; i++)
227 mpz_add_ui (x, x, a);
237 mpz_add_ui (y, y, a);
241 while (mpz_cmp_ui (t1, 1) == 0);
243 mpz_divexact (n, n, t1);
245 if (!mpz_probab_prime_p (t1, 10))
250 mpn_random (&a_limb, (mp_size_t) 1);
259 if (mpz_cmp(t1,last_f)==0)
261 multiplicities[index-1]++;
267 multiplicities[index++] = 1;
273 if (mpz_probab_prime_p (n, 10))
275 if (mpz_cmp(n,last_f)==0)
277 multiplicities[index-1]++;
283 multiplicities[index++] = 1;
301 unsigned int division_limit;
303 if (mpz_sgn (t) == 0)
307 division_limit = mpz_sizeinbase (t, 2);
308 if (division_limit > 1000)
309 division_limit = 1000 * 1000;
311 division_limit = division_limit * division_limit;
315 if (mpz_cmp_ui (t, 1) != 0)
317 if (mpz_probab_prime_p (t, 10))
320 multiplicities[index++] = 1;
335 int* multiplicities = (
int*)
omAlloc0(1000*
sizeof(
int));
345 factor_gmp(nn,primes,multiplicities,index,pBound);
349 primesL->
Init(index);
350 for (i = 0; i <
index; i++)
360 multiplicitiesL->
Init(index);
361 for (i = 0; i <
index; i++)
364 multiplicitiesL->
m[
i].
data = (
void*)(
long)multiplicities[
i];
370 if (positive==-1) mpz_neg(nn,nn);
441 while (*ss!=
'\0') ss++;
451 if((lib!=
NULL)&&(*lib!=
'\0'))
453 Print(
"// proc %s from lib %s\n",s,lib);
474 sprintf(sing_file,
"%s/%s.sing", res_m, s);
487 s = (
char*)
omAlloc((length+20)*
sizeof(char));
488 got = fread(s,
sizeof(
char), length, fd);
492 Werror(
"Error while reading file %s", sing_file);
497 strcat(s,
"\n;return();\n\n");
506 Werror(
"no example for %s", str);
604 if(strcmp(n,
"get")==0)
613 if(strcmp(n,
"set")==0)
635 if(strcmp(n,
"none")==0)
641 for (i=0; (i==0) || (optionStruct[i-1].
setval!=0); i++)
643 if (strcmp(n,optionStruct[i].
name)==0)
653 Warn(
"cannot set option");
666 else if ((strncmp(n,
"no",2)==0)
667 && (strcmp(n+2,optionStruct[i].name)==0))
674 Warn(
"cannot clear option");
678 for (i=0; (i==0) || (verboseStruct[i-1].
setval!=0); i++)
680 if (strcmp(n,verboseStruct[i].
name)==0)
693 else if ((strncmp(n,
"no",2)==0)
694 && (strcmp(n+2,verboseStruct[i].name)==0))
708 Werror(
"unknown option `%s`",n);
716 #ifdef OM_SINGULAR_CONFIG_H
718 extern int om_sing_opt_show_mem;
720 else om_sing_opt_show_mem = 0;
737 for (i=0; optionStruct[
i].
setval!=0; i++)
739 if (optionStruct[i].
setval & tmp)
753 for (i=0; verboseStruct[
i].
setval!=0; i++)
755 if (verboseStruct[i].
setval & tmp)
776 #ifndef __GMP_BITS_PER_MP_LIMB
777 #define __GMP_BITS_PER_MP_LIMB GMP_LIMB_BITS
779 #include <flint/flint.h>
786 StringAppend(
"Singular for %s version %s (%d, %d bit) %s #%s",
791 #if defined(mpir_version)
792 StringAppend(
"MPIR(%s)~GMP(%s),", mpir_version, gmp_version);
793 #elif defined(gmp_version)
799 #include <NTL/version.h>
807 #if defined(HAVE_DYN_RL)
821 #if defined(HAVE_READLINE) && !defined(FEREAD)
839 #ifdef HAVE_DYNAMIC_LOADING
873 #ifdef __OPTIMIZE_SIZE__
890 #define SI_SHOW_BUILTIN_MODULE(name) StringAppend(" %s", #name);
894 #undef SI_SHOW_BUILTIN_MODULE
897 "CC = %s,FLAGS : %s,\n"
898 "CXX = %s,FLAGS : %s,\n"
899 "DEFS : %s,CPPFLAGS : %s,\n"
900 "LDFLAGS : %s,LIBS : %s "
902 "(ver: " __VERSION__
")"
904 "\n",AC_CONFIGURE_ARGS, CC,CFLAGS, CXX,CXXFLAGS, DEFS,CPPFLAGS, LDFLAGS,LIBS);
912 #if (OM_TRACK > 2) && defined(OM_TRACK_CUSTOM)
913 void p_SetRingOfLeftv(
leftv l, ring
r)
945 p_SetRingOfLeftv(&d->arg1, r);
946 if (d->argc>1) p_SetRingOfLeftv(&d->arg2, r);
947 if (d->argc>2) p_SetRingOfLeftv(&d->arg3, r);
951 printf(
"type %d not yet implementd in p_SetRingOfLeftv\n",l->
rtyp);
959 void listall(
int showproc)
962 PrintS(
"====== Top ==============\n");
970 Print(
"::%s, typ %s level %d data %lx",
984 Print(
"(T)::%s, typ %s level %d data %lx\n",
991 Print(
"====== %s ==============\n",
IDID(hh));
1002 Print(
"%s::%s, typ %s level %d data %lx\n",
1025 Print(
"%s typ %d in Top (should be in ring)\n",
IDID(hh),
IDTYP(hh));
1054 #include <sys/types.h>
1055 #include <sys/stat.h>
1061 return si_fstat(fd,buf);
1078 m2_end_called =
TRUE;
1079 #ifdef HAVE_SIMPLEIPC
1091 #endif // HAVE_SIMPLEIPC
1138 printf(
"Auf Wiedersehen.\n");
1140 printf(
"\n$Bye.\n");
1152 printf(
"\nhalt %d\n",i);
1166 fprintf(stderr,
"\nSingular error: no more memory\n");
1208 #ifndef __OPTIMIZE__
1271 #ifdef _SC_NPROCESSORS_ONLN
1272 if ((cpu_n=sysconf(_SC_NPROCESSORS_ONLN))>cpus) cpus=cpu_n;
1273 #elif defined(_SC_NPROCESSORS_CONF)
1274 if ((cpu_n=sysconf(_SC_NPROCESSORS_CONF))>cpus) cpus=cpu_n;
int iiInitArithmetic()
initialisation of arithmetic structured data
const const intvec const intvec const ring _currRing const const intvec const intvec const ring _currRing int
static void factor_gmp(mpz_t t, lists primes, int *multiplicities, int &index, unsigned long bound)
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
BOOLEAN n_AEInitChar(coeffs r, void *)
void factoryseed(int s)
random seed initializer
Class used for (list of) interpreter objects.
void singular_example(char *str)
static FORCE_INLINE void number2mpz(number n, mpz_t m)
static CanonicalForm bound(const CFMatrix &M)
void feStringAppendResources(int warn)
const BOOLEAN p_procs_dynamic
static void * feOptValue(feOptIndex opt)
BOOLEAN naInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
used for all transcendental extensions, i.e., the top-most extension in an extension tower is transce...
volatile BOOLEAN m2_end_called
static void factor_using_pollard_rho(mpz_t n, unsigned long a, lists primes, int *multiplicities, int &index)
void setListEntry(lists L, int index, mpz_t n)
static char * feResource(feResourceConfig config, int warn)
char * fe_fgets(const char *pr, char *s, int size)
static const int SW_USE_EZGCD_P
set to 1 to use EZGCD over F_q
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)
BOOLEAN n_QAEInitChar(coeffs r, void *)
const CanonicalForm CFMap CFMap int &both_non_zero int n
char * fe_fgets_dummy(const char *, char *, int)
static const int SW_USE_NTL_SORT
set to 1 to sort factors in a factorization
static unsigned short primes[]
primes, primes_len: used to step through possible extensions
SI_FOREACH_BUILTIN(SI_GET_BUILTIN_MOD_INIT0)}
const char * feSetOptValue(feOptIndex opt, char *optarg)
void feInitResources(const char *argv0)
void WerrorS(const char *s)
void omPrintStats(FILE *fd)
volatile BOOLEAN ssiToBeClosed_inactive
static FORCE_INLINE number mpz2number(mpz_t m)
BOOLEAN iiLibCmd(char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
static BOOLEAN rField_has_simple_inverse(const ring r)
void feStringAppendBrowsers(int warn)
void setListEntry_ui(lists L, int index, unsigned long ui)
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
sem_t * semaphore[SIPC_MAX_SEMAPHORES]
#define SI_RESTORE_OPT(A, B)
BOOLEAN singular_in_batchmode
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)
struct soptionStruct verboseStruct[]
char * fe_fgets_stdin_emu(const char *pr, char *s, int size)
void StringSetS(const char *st)
int status int void * buf
struct soptionStruct optionStruct[]
BOOLEAN slPrepClose(si_link l)
void StringAppendS(const char *st)
struct fe_option feOptSpec[]
void fe_reset_input_mode()
#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)
static const int SW_USE_CHINREM_GCD
set to 1 to use modular gcd over Z
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 n_pAEInitChar(coeffs r, void *p)
char name(const Variable &v)
static BOOLEAN rField_is_Ring(const ring r)
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 ...
void killhdl(idhdl h, package proot)
const char * singular_date
static const int SW_USE_QGCD
set to 1 to use Encarnacion GCD over Q(a)
static const int SW_USE_EZGCD
set to 1 to use EZGCD over Z
#define SI_SAVE_OPT(A, B)
#define SIPC_MAX_SEMAPHORES
void Clean(ring r=currRing)
char * iiGetLibName(procinfov pi)
#define SI_SHOW_BUILTIN_MODULE(name)
const char factoryVersion[]
extern const char factoryVersion[];
#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)/
: 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)
int sem_acquired[SIPC_MAX_SEMAPHORES]
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)
static BOOLEAN ii_pAE_init(leftv res, leftv a)
void Werror(const char *fmt,...)
void(* factoryError)(const char *s)
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.