Annotation of OpenXM_contrib2/asir2000/builtin/parif.c, Revision 1.30
1.30 ! noro 1: /* $OpenXM: OpenXM_contrib2/asir2000/builtin/parif.c,v 1.29 2015/08/19 05:29:23 noro Exp $ */
1.1 noro 2: #include "ca.h"
3: #include "parse.h"
1.19 noro 4: #include "ox.h"
1.1 noro 5:
1.19 noro 6: Q ox_pari_stream;
7: int ox_pari_stream_initialized = 0;
1.29 noro 8: int ox_get_pari_result = 0;
1.1 noro 9:
1.24 noro 10: typedef void (*mpfr_func)(NODE,Obj *);
11:
12: void Pmpfr_ai();
13: void Pmpfr_eint(), Pmpfr_erf(),Pmpfr_li2();
14: void Pmpfr_zeta();
15: void Pmpfr_j0(), Pmpfr_j1();
16: void Pmpfr_y0(), Pmpfr_y1();
17: void Pmpfr_gamma(), Pmpfr_lngamma(), Pmpfr_digamma();
18: void Pmpfr_floor(), Pmpfr_round(), Pmpfr_ceil();
19:
20: struct mpfr_tab_rec {
21: char *name;
22: mpfr_func func;
23: } mpfr_tab[] = {
24: {"ai",Pmpfr_ai},
25: {"zeta",Pmpfr_zeta},
26: {"j0",Pmpfr_j0},
27: {"j1",Pmpfr_j1},
28: {"y0",Pmpfr_y0},
29: {"y1",Pmpfr_y1},
30: {"eint",Pmpfr_eint},
31: {"erf",Pmpfr_erf},
32: {"li2",Pmpfr_li2},
33: {"gamma",Pmpfr_gamma},
34: {"lngamma",Pmpfr_gamma},
35: {"digamma",Pmpfr_gamma},
36: {"floor",Pmpfr_floor},
37: {"ceil",Pmpfr_ceil},
38: {"round",Pmpfr_round},
39: };
40:
41: mpfr_func mpfr_search(char *name)
42: {
43: int i,n;
44:
45: n = sizeof(mpfr_tab)/sizeof(struct mpfr_tab_rec);
46: for ( i = 0; i < n; i++ )
47: if ( !strcmp(name,mpfr_tab[i].name) )
48: return mpfr_tab[i].func;
49: return 0;
50: }
51:
1.28 noro 52: Obj list_to_vect(Obj a)
53: {
54: int len,i;
55: VECT v;
56: NODE nd;
57:
58: if ( !a || OID(a) != O_LIST ) return a;
59: len = length(BDY((LIST)a));
60: MKVECT(v,len);
61: for ( i = 0, nd = BDY((LIST)a); nd; nd = NEXT(nd), i++ )
62: v->body[i] = (pointer)list_to_vect((Obj)BDY(nd));
63: return (Obj)v;
64: }
65:
1.30 ! noro 66: Obj vect_to_mat(VECT v)
! 67: {
! 68: MAT m;
! 69: int len,col,i,j;
! 70:
! 71: len = v->len;
! 72: if ( v->body[0] && OID((Obj)v->body[0]) == O_VECT ) {
! 73: col = ((VECT)v->body[0])->len;
! 74: for ( i = 1; i < len; i++ )
! 75: if ( !v->body[i] || OID((Obj)v->body[i]) != O_VECT
! 76: || ((VECT)v->body[i])->len != col )
! 77: break;
! 78: if ( i == len ) {
! 79: /* convert to a matrix */
! 80: MKMAT(m,len,col);
! 81: for ( i = 0; i < len; i++ )
! 82: for ( j = 0; j < col; j++ )
! 83: m->body[i][j] = ((VECT)v->body[i])->body[j];
! 84: return (Obj)m;
! 85: }
! 86: }
! 87: return (Obj)v;
! 88: }
! 89:
1.29 noro 90: void reset_ox_pari()
91: {
92: NODE nd;
93: Obj r;
94:
95: if ( ox_get_pari_result ) {
96: nd = mknode(1,ox_pari_stream);
97: Pox_shutdown(nd,&r);
98: ox_get_pari_result = 0;
99: ox_pari_stream_initialized = 0;
100: }
101: }
102:
1.19 noro 103: pointer evalparif(FUNC f,NODE arg)
1.1 noro 104: {
1.19 noro 105: int ac,intarg,opt,prec;
106: Q q,r,narg;
1.25 noro 107: NODE nd,oxarg,t,t1,n;
1.19 noro 108: STRING name;
109: USINT ui;
110: Obj ret,dmy;
1.24 noro 111: mpfr_func mpfr_function;
1.19 noro 112:
1.24 noro 113: if ( mpfr_function = mpfr_search(f->name) ) {
114: (*mpfr_function)(arg,&ret);
115: return (pointer) ret;
1.20 takayama 116: }
1.24 noro 117:
1.19 noro 118: if ( !ox_pari_stream_initialized ) {
1.29 noro 119: MKSTR(name,"ox_pari");
120: nd = mknode(2,NULL,name);
121: Pox_launch_nox(nd,&r);
122: ox_pari_stream = r;
1.19 noro 123: ox_pari_stream_initialized = 1;
124: }
1.25 noro 125:
126: ac = argc(arg);
127: /* reverse the arg list */
128: for ( n = arg, t = 0; n; n = NEXT(n) ) {
129: MKNODE(t1,BDY(n),t); t = t1;
130: }
131: /* push the reversed arg list */
132: for ( ; t; t = NEXT(t) ) {
133: oxarg = mknode(2,ox_pari_stream,BDY(t));
134: Pox_push_cmo(oxarg,&dmy);
135: }
136: MKSTR(name,f->name);
137: STOQ(ac,narg);
138: oxarg = mknode(3,ox_pari_stream,name,narg);
139: Pox_execute_function(oxarg,&dmy);
140: oxarg = mknode(1,ox_pari_stream);
1.29 noro 141: ox_get_pari_result = 1;
1.28 noro 142: Pox_pop_cmo(oxarg,&ret);
1.29 noro 143: ox_get_pari_result = 0;
1.30 ! noro 144: if ( ret && OID(ret) == O_LIST ) {
1.28 noro 145: ret = list_to_vect(ret);
1.30 ! noro 146: ret = vect_to_mat((VECT)ret);
! 147: }
1.28 noro 148: return ret;
1.1 noro 149: }
150:
151: struct pariftab {
152: char *name;
1.19 noro 153: int dmy;
1.1 noro 154: int type;
155: };
156:
1.8 noro 157: /*
158: * type = 1 => argc = 1, second arg = precision
159: * type = 2 => argc = 1, second arg = optional (long int)
160: *
161: */
1.19 noro 162: /*
163: {"abs",0,1},
164: {"adj",0,1},
165: */
1.8 noro 166:
1.1 noro 167: struct pariftab pariftab[] = {
1.19 noro 168: {"arg",0,1},
169: {"bigomega",0,1},
170: {"binary",0,1},
171: {"ceil",0,1},
172: {"centerlift",0,1},
173: {"cf",0,1},
174: {"classno",0,1},
175: {"classno2",0,1},
176: {"conj",0,1},
177: {"content",0,1},
178: {"denom",0,1},
179: {"det",0,1},
180: {"det2",0,1},
181: {"dilog",0,1},
182: {"disc",0,1},
183: {"discf",0,1},
184: {"divisors",0,1},
185: {"eigen",0,1},
186: {"eintg1",0,1},
187: {"erfc",0,1},
188: {"eta",0,1},
189: {"floor",0,1},
190: {"frac",0,1},
191: {"galois",0,1},
192: {"galoisconj",0,1},
193: {"gamh",0,1},
194: {"gamma",0,1},
195: {"hclassno",0,1},
196: {"hermite",0,1},
197: {"hess",0,1},
198: {"imag",0,1},
199: {"image",0,1},
200: {"image2",0,1},
201: {"indexrank",0,1},
202: {"indsort",0,1},
203: {"initalg",0,1},
204: {"isfund",0,1},
205: {"ispsp",0,1},
206: {"isqrt",0,1},
207: {"issqfree",0,1},
208: {"issquare",0,1},
209: {"jacobi",0,1},
210: {"jell",0,1},
211: {"ker",0,1},
212: {"keri",0,1},
213: {"kerint",0,1},
214: {"kerintg1",0,1},
215: {"length",0,1},
216: {"lexsort",0,1},
217: {"lift",0,1},
218: {"lindep",0,1},
219: {"lll",0,1},
220: {"lllgen",0,1},
221: {"lllgram",0,1},
222: {"lllgramgen",0,1},
223: {"lllgramint",0,1},
224: {"lllgramkerim",0,1},
225: {"lllgramkerimgen",0,1},
226: {"lllint",0,1},
227: {"lllkerim",0,1},
228: {"lllkerimgen",0,1},
229: {"lngamma",0,1},
230: {"logagm",0,1},
231: {"mat",0,1},
232: {"matrixqz2",0,1},
233: {"matrixqz3",0,1},
234: {"matsize",0,1},
235: {"modreverse",0,1},
236: {"mu",0,1},
237: {"nextprime",0,1},
238: {"norm",0,1},
239: {"norml2",0,1},
240: {"numdiv",0,1},
241: {"numer",0,1},
242: {"omega",0,1},
243: {"order",0,1},
244: {"ordred",0,1},
245: {"phi",0,1},
246: {"pnqn",0,1},
247: {"polred",0,1},
248: {"polred2",0,1},
249: {"primroot",0,1},
250: {"psi",0,1},
251: {"quadgen",0,1},
252: {"quadpoly",0,1},
253: {"real",0,1},
254: {"recip",0,1},
255: {"redreal",0,1},
256: {"regula",0,1},
257: {"reorder",0,1},
258: {"reverse",0,1},
259: {"rhoreal",0,1},
260: {"roots",0,1},
261: {"round",0,1},
262: {"sigma",0,1},
263: {"signat",0,1},
264: {"simplify",0,1},
265: {"smalldiscf",0,1},
266: {"smallfact",0,1},
267: {"smallpolred",0,1},
268: {"smallpolred2",0,1},
269: {"smith",0,1},
270: {"smith2",0,1},
271: {"sort",0,1},
272: {"sqr",0,1},
273: {"sqred",0,1},
274: {"sqrt",0,1},
275: {"supplement",0,1},
276: {"trace",0,1},
277: {"trans",0,1},
278: {"trunc",0,1},
279: {"unit",0,1},
280: {"vec",0,1},
281: {"wf",0,1},
282: {"wf2",0,1},
283: {"zeta",0,1},
284: {"factor",0,1},
285:
286: {"allocatemem",0,0},
287:
288: {"isprime",0,2},
289: {"factorint",0,2},
1.1 noro 290: {0,0,0},
291: };
292:
293: void parif_init() {
294: int i;
295:
296: for ( i = 0, parif = 0; pariftab[i].name; i++ )
1.19 noro 297: appendparif(&parif,pariftab[i].name, 0,pariftab[i].type);
1.1 noro 298: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>