=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/include/ca.h,v retrieving revision 1.71 retrieving revision 1.89 diff -u -p -r1.71 -r1.89 --- OpenXM_contrib2/asir2000/include/ca.h 2008/08/11 16:51:30 1.71 +++ OpenXM_contrib2/asir2000/include/ca.h 2015/08/04 06:20:45 1.89 @@ -45,11 +45,20 @@ * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. * - * $OpenXM: OpenXM_contrib2/asir2000/include/ca.h,v 1.70 2008/08/11 16:23:24 ohara Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/include/ca.h,v 1.88 2015/03/15 19:30:46 ohara Exp $ */ #include #include +#include +#include +/* from mpfr-impl.h */ +#define MPFR_PREC(x) ((x)->_mpfr_prec) +#define MPFR_EXP(x) ((x)->_mpfr_exp) +#define MPFR_MANT(x) ((x)->_mpfr_d) +#define MPFR_LAST_LIMB(x) ((MPFR_PREC (x) - 1) / GMP_NUMB_BITS) +#define MPFR_LIMB_SIZE(x) (MPFR_LAST_LIMB (x) + 1) + #if defined(hpux) #include # define setbuffer(FP,buf,siz) setvbuf(FP,buf,_IOFBF,siz) @@ -57,9 +66,6 @@ #if !defined(VISUAL) #include -#endif - -#if !defined(VISUAL) #include #endif @@ -72,6 +78,7 @@ #endif #if defined(VISUAL) +#include #include #endif @@ -80,6 +87,7 @@ typedef caddr_t pointer; #endif + typedef void * pointer; #if defined(sun) @@ -93,6 +101,8 @@ typedef void * pointer; #endif #endif +#define NULLP ((void *)0) + #define TODO printf("%s: not implemented!\n", __func__) #define COPY(a,b) ((b)=(a)) @@ -136,14 +146,29 @@ typedef void * pointer; #define N_R 1 #define N_A 2 #define N_B 3 -#define N_C 4 -#define N_M 5 -#define N_LM 6 -#define N_GF2N 7 -#define N_GFPN 8 -#define N_GFS 9 -#define N_GFSN 10 -#define N_DA 11 +#define N_NEXT_B (N_B) +#if defined(INTERVAL) +#define N_Quad (N_NEXT_B+1) +#define N_IP (N_NEXT_B+2) +#define N_IntervalDouble (N_NEXT_B+3) +#define N_IntervalQuad (N_NEXT_B+4) +#define N_IntervalBigFloat (N_NEXT_B+5) +#define N_PRE_C N_IntervalBigFloat +#define N_BASE (N_NEXT_B+5) +#else +#define N_BASE N_NEXT_B +#endif +#define N_C (N_BASE+1) +#define N_M (N_BASE+2) +#define N_LM (N_BASE+3) +#define N_GF2N (N_BASE+4) +#define N_GFPN (N_BASE+5) +#define N_GFS (N_BASE+6) +#define N_GFSN (N_BASE+7) +#define N_DA (N_BASE+8) +#define N_GZ (N_BASE+9) +#define N_GQ (N_BASE+10) +#define N_PARIB (N_BASE+11) #define ORD_REVGRADLEX 0 #define ORD_GRADLEX 1 @@ -153,18 +178,16 @@ typedef enum { A_end=0,A_fnode,A_arf,A_int,A_str,A_internal,A_node,A_notimpl,A_func } farg_type; -#if defined(LONG_IS_32BIT) -#if defined(VISUAL) -typedef _int64 L; -typedef unsigned _int64 UL; -#else +#if SIZEOF_LONG == 8 +typedef long L; +typedef unsigned long UL; +#elif defined(HAVE_UNSIGNED_LONG_LONG) typedef long long L; typedef unsigned long long UL; +#elif defined(_MSC_VER) +typedef _int64 L; +typedef unsigned _int64 UL; #endif -#else -typedef long L; -typedef unsigned long UL; -#endif typedef struct oN { int p; @@ -227,7 +250,7 @@ typedef struct oBF { short id; char nid; char pad; - long body[1]; + mpfr_t body; } *BF; typedef struct oC { @@ -266,7 +289,20 @@ typedef struct oDAlg { struct oQ *dn; } *DAlg; +typedef struct oGZ { + short id; + char nid; + char pad; + mpz_t body; +} *GZ; +typedef struct oGQ { + short id; + char nid; + char pad; + mpq_t body; +} *GQ; + typedef struct oNum { short id; char nid; @@ -625,6 +661,8 @@ struct order_spec { int id; Obj obj; int nv; + int ispot; /* 1 means Position over Term (Pos then Term) */ + int pot_nelim; /* size of positions for pot-elimination order */ union { int simple; struct { @@ -727,15 +765,11 @@ typedef unsigned int ModNum; /* memory allocators (W_... : uses alloca) */ -#if 0 #define MALLOC(d) Risa_GC_malloc(d) #define MALLOC_ATOMIC(d) Risa_GC_malloc_atomic(d) +#define MALLOC_ATOMIC_IGNORE_OFF_PAGE(d) Risa_GC_malloc_atomic_ignore_off_page(d) #define REALLOC(p,d) Risa_GC_realloc(p,d) -#else -#define MALLOC(d) GC_malloc(d) -#define MALLOC_ATOMIC(d) GC_malloc_atomic(d) -#define REALLOC(p,d) GC_realloc(p,d) -#endif +#define GCFREE(p) Risa_GC_free(p) #define CALLOC(d,e) MALLOC((d)*(e)) #if !defined(__CYGWIN__) && (defined(__GNUC__) || defined(vax) || defined(apollo) || defined(alloca) || defined(VISUAL)) @@ -807,6 +841,8 @@ bzero((char *)(q)->b,(w)*sizeof(unsigned int))) ((q).b=(unsigned int *)ALLOCA((w)*sizeof(unsigned int))) /* cell allocators */ +#define NEWGZ(q) ((q)=(GZ)MALLOC(sizeof(struct oGZ)),OID(q)=O_N,NID(q)=N_GZ) +#define NEWGQ(q) ((q)=(GQ)MALLOC(sizeof(struct oGQ)),OID(q)=O_N,NID(q)=N_GQ) #define NEWQ(q) ((q)=(Q)MALLOC(sizeof(struct oQ)),OID(q)=O_N,NID(q)=N_Q) #define NEWMQ(q) ((q)=(MQ)MALLOC_ATOMIC(sizeof(struct oMQ)),OID(q)=O_N,NID(q)=N_M) #define NEWGFS(q) ((q)=(GFS)MALLOC_ATOMIC(sizeof(struct oGFS)),OID(q)=O_N,NID(q)=N_GFS) @@ -848,7 +884,8 @@ bzero((char *)(q)->b,(w)*sizeof(unsigned int))) #define NEWReal(q) ((q)=(Real)MALLOC_ATOMIC(sizeof(struct oReal)),OID(q)=O_N,NID(q)=N_R) #define NEWAlg(r) ((r)=(Alg)MALLOC(sizeof(struct oAlg)),OID(r)=O_N,NID(r)=N_A) #define NEWDAlg(r) ((r)=(DAlg)MALLOC(sizeof(struct oDAlg)),OID(r)=O_N,NID(r)=N_DA) -#define NEWBF(q,l) ((q)=(BF)MALLOC_ATOMIC(TRUESIZE(oBF,(l)-1,long)),OID(q)=O_N,NID(q)=N_B) +#define NEWBF(q) ((q)=(BF)MALLOC(sizeof(struct oBF)),OID(q)=O_N,NID(q)=N_B) +#define NEWPARIBF(q,l) ((q)=(BF)MALLOC_ATOMIC(TRUESIZE(oBF,(l)-1,long)),OID(q)=O_N,NID(q)=N_PARIB) #define NEWC(r) ((r)=(C)MALLOC(sizeof(struct oC)),OID(r)=O_N,NID(r)=N_C) #define NEWLM(r) ((r)=(LM)MALLOC(sizeof(struct oLM)),OID(r)=O_N,NID(r)=N_LM) #define NEWGF2N(r) ((r)=(GF2N)MALLOC(sizeof(struct oGF2N)),OID(r)=O_N,NID(r)=N_GF2N) @@ -948,11 +985,7 @@ PL(NM(q))=1,BD(NM(q))[0]=(unsigned int)(n),DN(q)=0,(q) #define SL(n) ((n)->p) #define ZALLOC(d) ((Z)MALLOC_ATOMIC(TRUESIZE(oZ,(d)-1,int))) -#if defined(PARI) -#define ToReal(a) (!(a)?(double)0.0:REAL(a)?BDY((Real)a):RATN(a)?RatnToReal((Q)a):BIGFLOAT(a)?rtodbl(BDY((BF)a)):0) -#else -#define ToReal(a) (!(a)?(double)0.0:REAL(a)?BDY((Real)a):RATN(a)?RatnToReal((Q)a):0.0) -#endif +#define ToReal(a) (!(a)?(double)0.0:REAL(a)?BDY((Real)a):RATN(a)?RatnToReal((Q)a):BIGFLOAT(a)?mpfrtodbl(BDY((BF)a)):0) /* predicates */ #define NUM(p) (OID(p)==O_N) @@ -1321,7 +1354,7 @@ void copyn(N,int,int *); void kmulnmain(N,N,N *); int qcoefp(Obj); int qcoefr(Obj); -long get_allocwords(void); +size_t get_allocwords(void); double get_clock(void); void get_eg(struct oEGT *); void printtime(struct oEGT *,struct oEGT *,double); @@ -1426,9 +1459,13 @@ LUM LUMALLOC(int, int); BM BMALLOC(int, int); Obj ToAlg(Num); UM *berlemain(register int, UM, UM *); +void Risa_GC_set_adj(int,int); +void Risa_GC_get_adj(int *,int *); void *Risa_GC_malloc(size_t); void *Risa_GC_malloc_atomic(size_t); void *Risa_GC_realloc(void *,size_t); +void Risa_GC_free(void *); +void *Risa_GC_malloc_atomic_ignore_off_page(size_t); void *GC_malloc(size_t); void *GC_malloc_atomic(size_t); void *GC_realloc(void *,size_t); @@ -2643,7 +2680,171 @@ void mulnbp(VL vl,NBP p1,NBP p2, NBP *rp); void pwrnbp(VL vl,NBP p1,Q n, NBP *rp); int compnbp(VL vl,NBP p1,NBP p2); -#if defined(PARI23) -#define prec precreal -#define mppgcd(a,b) (gcdii((a),(b))) -#endif +#define WORDSIZE_IN_N(a) (ABS((a)->_mp_size)*GMP_LIMB_BITS/32) + +#define MPZTOGZ(g,q) \ +(!mpz_sgn(g)?((q)=0):(NEWGZ(q),BDY(q)[0]=(g)[0],(q))) +#define MPQTOGQ(g,q) \ +(!mpq_sgn(g)?((q)=0):(NEWGQ(q),BDY(q)[0]=(g)[0],(q))) + +#define INTMPQ(a) (!mpz_cmp_ui(mpq_numref(a),1)) + +#define UNIGZ(a) ((a)&&NID(a)==N_GZ&&!mpz_cmp_ui(BDY(a),1)) +#define MUNIGZ(a) ((a)&&NID(a)==N_GZ&&!mpz_cmp_si(BDY(a),-1)) + +#define INTGQ(a) ((a)&&NID(a)==N_GQ&&!mpz_cmp_ui(mpq_denref(BDY(a)),1)) + +#define UNIGQ(a) \ +((a)&&NID(a)==N_GQ&&!mpz_cmp_ui(mpq_numref(BDY(a)),1)&&!mpz_cmp_ui(mpq_denref(BDY(a)),1)) +#define MUNIGQ(a) \ +((a)&&NID(a)==N_GQ&&!mpz_cmp_si(mpq_numref(BDY(a)),-1)&&!mpz_cmp_ui(mpq_denref(BDY(a)),1)) + +#define MPZTOMPQ(z,q) \ +(mpq_init(q),mpq_numref(q)[0] = (z)[0],mpz_set_ui(mpq_denref(q),1)) + +#define MPFRTOBF(g,q) \ +(NEWBF(q),BDY(q)[0]=(g)[0],(q)) + +extern mpz_t ONEMPZ; +extern GZ ONEGZ; + +void *gc_realloc(void *p,size_t osize,size_t nsize); +void gc_free(void *p,size_t size); +void init_gmpq(); +GQ mpqtogzq(mpq_t a); +GQ qtogq(Q a); +Q gqtoq(GQ a); +GZ ztogz(Q a); +Q gztoz(GZ a); +P ptogp(P a); +P gptop(P a); +void addgz(GZ n1,GZ n2,GZ *nr); +void subgz(GZ n1,GZ n2,GZ *nr); +void mulgz(GZ n1,GZ n2,GZ *nr); +void mul1gz(GZ n1,int n2,GZ *nr); +void divgz(GZ n1,GZ n2,GZ *nq); +void chsgngz(GZ n,GZ *nr); +void pwrgz(GZ n1,Q n,GZ *nr); +int cmpgz(GZ q1,GZ q2); +void gcdgz(GZ n1,GZ n2,GZ *nq); +void gcdvgz(VECT v,GZ *q); +void addgq(GQ n1,GQ n2,GQ *nr); +void subgq(GQ n1,GQ n2,GQ *nr); +void mulgq(GQ n1,GQ n2,GQ *nr); +void divgq(GQ n1,GQ n2,GQ *nq); +void chsgngq(GQ n,GQ *nr); +void pwrgq(GQ n1,Q n,GQ *nr); +int cmpgq(GQ n1,GQ n2); +void mkgwc(int k,int l,GZ *t); +void gz_ptozp(P p,int sgn,GQ *c,P *pr); +void gz_lgp(P p,GZ *g,GZ *l); +void gz_qltozl(GQ *w,int n,GZ *dvr); + +void _mdtodp(DP p,DP *pr); +void add_denomlist(P f); +void algobjtorat(Obj f,Obj *r); +void algtodalg(Alg a,DAlg *r); +void appenduflist(NODE n); +void arf_add(VL,Obj,Obj,Obj *); +void arf_chsgn(Obj,Obj *); +void arf_div(VL,Obj,Obj,Obj *); +void arf_mul(VL,Obj,Obj,Obj *); +void arf_sub(VL,Obj,Obj,Obj *); +void asir_terminate(int); +void check_intr(); +void clctalg(P,VL *); +void comm_muld_trunc(VL vl,DP p1,DP p2,DL dl,DP *pr); +void comm_quod(VL vl,DP p1,DP p2,DP *pr); +void create_modorder_spec(int id,LIST shift,struct modorder_spec **s); +void dalgtoalg(DAlg da,Alg *r); +void divsgz(GZ n1,GZ n2,GZ *nq); +void dp_ht(DP p,DP *rp); +void dp_interreduce(LIST f,LIST v,int field,struct order_spec *ord,LIST *rp); +void dp_mbase(NODE,NODE *); +void dp_nf_tab_f(DP p,LIST *tab,DP *rp); +void dp_ptozp(DP,DP *); +void dp_sort(DP p,DP *rp); +void dp_subd(DP,DP,DP *); +void dp_true_nf(NODE,DP,DP *,int,DP *,P *); +void dp_true_nf_marked(NODE b,DP g,DP *ps,DP *hps,DP *rp,P *nmp,P *dnp); +void dp_true_nf_marked_mod(NODE b,DP g,DP *ps,DP *hps,int mod,DP *rp,P *dnp); +void gbcheck_list(NODE f,int n,VECT *gp,LIST *pp); +void gcdsf(VL vl,P *pa,int k,P *r); +void get_algtree(Obj f,VL *r); +void get_vars(Obj,VL *); +void gfstopgfs(GFS a,V v,P *c); +void henmain_incremental(LUM f,LUM *bqlist,ML cqlist, int np, int mod, int start, int bound); +void iftogfs(int n,GFS *c); +void indextogfs(int index,GFS *c); +void init_denomlist(); +void inva_chrem(P p0,P p,NODE *pr); +void itogfs(int n,GFS *c); +void lcmn(N n1,N n2,N *nr); +void makevar(char *,P *); +void mdtodp(DP p,DP *pr); +void mfctrsf(VL vl,P f,DCP *dcp); +void mulp_trunc(VL vl,P p1,P p2,VN vn,P *pr); +void nd_det(int mod,MAT f,P *rp); +void nd_gr(LIST f,LIST v,int m,int homo,int retdp,int f4,struct order_spec *ord,LIST *rp); +void nd_gr_postproc(LIST f,LIST v,int m,struct order_spec *ord,int do_check,LIST *rp); +void nd_gr_recompute_trace(LIST f,LIST v,int m,struct order_spec *ord,LIST tlist,LIST *rp); +void nd_gr_trace(LIST f,LIST v,int trace,int homo,int f4,struct order_spec *ord,LIST *rp); +void nd_nf_p(Obj f,LIST g,LIST v,int m,struct order_spec *ord,Obj *rp); +void obj_algtodalg(Obj obj,Obj *r); +void obj_dalgtoalg(Obj obj,Obj *r); +void ox_bcast_102(int root); +void ox_reduce_102(int root,void (*func)()); +void print_to_wfep(Obj obj); +void printn(N); +void printz(Z n); +void pthrootgfs(GFS a,GFS *b); +void quop_trunc(VL vl,P p1,P p2,VN vn,P *pr); +void red_by_vect_sf(int m,unsigned int *p,unsigned int *r,unsigned int hc,int len); +void removecont_array(P *c,int n,int full); +void reset_top_weight(); +void setfield_dalg(NODE alist); +void setfield_gb(NODE gb,VL vl,struct order_spec *spec); +void setsecuremode(int value); +void sfbfctr_shift(P f,V x,V y,int degbound,GFS *evp,P *sfp,DCP *dcp); +void sfexgcd_by_hensel(BM g,BM h,int dy,BM *ap,BM *bp); +void sfptopsfp(P f,V v,P *gp); +void simpdalg(DAlg da,DAlg *r); +void simple_derivr(VL vl,Obj a,V v,Obj *b); +void substpp(VL vl,P p,V *vvect,P *svect,int nv,P *pr); +void ufctrsf(P p,DCP *dcp); +void vltopl(VL vl,LIST *l); + +int arf_comp(VL, Obj, Obj); +int available_mcindex(int ind); +int compare_zero(int n,int *u,int row,int **w); +int create_composite_order_spec(VL vl,LIST order,struct order_spec **specp); +int create_order_spec(VL,Obj,struct order_spec **); +int dalgtoup(DAlg da,P *up,Q *dn); +int dl_equal(int nv,DL dl1,DL dl2); +int dp_redble(DP,DP); +int dpv_hp(DPV p); +int generic_gauss_elim_hensel(MAT mat,MAT *nmmat,Q *dn,int **rindp,int **cindp); +int generic_gauss_elim_hensel_dalg(MAT mat,DP *mb,MAT *nmmat,Q *dn,int **rindp,int **cindp); +int generic_gauss_elim_mod(int **mat0,int row,int col,int md,int *colstat); +int generic_gauss_elim_mod2(int **mat0,int row,int col,int md,int *colstat,int *rowstat); +int get_field_type(P p); +int get_ox_server_id(int index); +int getsecuremode(); +int gz_generic_gauss_elim(MAT mat,MAT *nm,GZ *dn,int **rindp,int **cindp); +int gz_generic_gauss_elim_full(MAT mat,MAT *nm,GZ *dn,int **rindp,int **cindp); +int gz_gensolve_check(MAT mat,MAT nm,GZ dn,int *rind,int *cind); +int gz_gensolve_check2(MAT mat,MAT nm,GZ *dn,int *rind,int *cind); +int gz_intmtoratm(MAT mat,GZ md,MAT nm,GZ *dn); +int gz_intmtoratm2(MAT mat,GZ md,MAT nm,GZ *dn,int *stat); +int gz_inttorat(GZ c,GZ m,GZ b,int *sgnp,GZ *nmp,GZ *dnp); +int gz_intvtoratv(GZ *v,int n,GZ md,GZ b,GZ *nm,GZ *dn); +int invdalg(DAlg a,DAlg *c); +int is_eq(Obj a0,Obj a1); +int length(NODE); +int lu_mod(unsigned int **a,int n,unsigned int md,int **rinfo); +int n_bits_gz(GZ a); +int nd_gauss_elim_gz(GZ **mat0,int *sugar,int row,int col,int *colstat); +int poly_is_dependent(P p,V v); +int setsecureflag(char *name,int value); +int sfdegtest(int dy,int bound,UM *d1c,int k,int *in); +int sgnz(Z n);