[BACK]Return to parif.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / builtin

Annotation of OpenXM_contrib2/asir2000/builtin/parif.c, Revision 1.28

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>