[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.34

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

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