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

1.3       noro        1: /*
                      2:  * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
                      3:  * All rights reserved.
                      4:  *
                      5:  * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
                      6:  * non-exclusive and royalty-free license to use, copy, modify and
                      7:  * redistribute, solely for non-commercial and non-profit purposes, the
                      8:  * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
                      9:  * conditions of this Agreement. For the avoidance of doubt, you acquire
                     10:  * only a limited right to use the SOFTWARE hereunder, and FLL or any
                     11:  * third party developer retains all rights, including but not limited to
                     12:  * copyrights, in and to the SOFTWARE.
                     13:  *
                     14:  * (1) FLL does not grant you a license in any way for commercial
                     15:  * purposes. You may use the SOFTWARE only for non-commercial and
                     16:  * non-profit purposes only, such as academic, research and internal
                     17:  * business use.
                     18:  * (2) The SOFTWARE is protected by the Copyright Law of Japan and
                     19:  * international copyright treaties. If you make copies of the SOFTWARE,
                     20:  * with or without modification, as permitted hereunder, you shall affix
                     21:  * to all such copies of the SOFTWARE the above copyright notice.
                     22:  * (3) An explicit reference to this SOFTWARE and its copyright owner
                     23:  * shall be made on your publication or presentation in any form of the
                     24:  * results obtained by use of the SOFTWARE.
                     25:  * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.4       noro       26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.3       noro       27:  * for such modification or the source code of the modified part of the
                     28:  * SOFTWARE.
                     29:  *
                     30:  * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
                     31:  * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
                     32:  * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
                     33:  * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
                     34:  * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
                     35:  * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
                     36:  * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
                     37:  * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
                     38:  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
                     39:  * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
                     40:  * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
                     41:  * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
                     42:  * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
                     43:  * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
                     44:  * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
                     45:  * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
                     46:  * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
                     47:  *
1.10    ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/builtin/parif.c,v 1.9 2001/10/03 01:47:30 noro Exp $
1.3       noro       49: */
1.1       noro       50: #include "ca.h"
                     51: #include "parse.h"
                     52:
                     53: #if PARI
                     54: #include "genpari.h"
                     55:
                     56: extern long prec;
                     57:
                     58: void patori(GEN,Obj *);
                     59: void patori_i(GEN,N *);
                     60: void ritopa(Obj,GEN *);
                     61: void ritopa_i(N,int,GEN *);
                     62:
                     63: void Peval(),Psetprec(),p_pi(),p_e(),p_mul(),p_gcd();
1.5       noro       64: void asir_cgiv(GEN);
1.1       noro       65:
1.7       saito      66: #if defined(INTERVAL) || 1
                     67: void Psetprecword();
                     68: #endif
                     69:
1.1       noro       70: struct ftab pari_tab[] = {
1.7       saito      71:        {"eval",Peval,-2},
                     72:        {"setprec",Psetprec,-1},
                     73: #if defined(INTERVAL) || 1
                     74:        {"setprecword",Psetprecword,-1},
                     75: #endif
                     76:        {0,0,0},
1.1       noro       77: };
                     78:
                     79: #define MKPREC(a,i,b) (argc(a)==(i)?mkprec(QTOS((Q)(b))):prec)
                     80:
                     81: #define CALLPARI1(f,a,p,r)\
1.5       noro       82: ritopa((Obj)a,&_pt1_); _pt2_ = f(_pt1_,p); patori(_pt2_,r); asir_cgiv(_pt2_); asir_cgiv(_pt1_)
1.1       noro       83: #define CALLPARI2(f,a,b,p,r)\
1.5       noro       84: ritopa((Obj)a,&_pt1_); ritopa((Obj)b,&_pt2_); _pt3_ = f(_pt1_,_pt2_,p); patori(_pt3_,r); asir_cgiv(_pt3_); asir_cgiv(_pt2_); asir_cgiv(_pt1_)
1.1       noro       85:
                     86: #define PARIF1P(f,pf)\
                     87: void f(NODE,Obj *);\
                     88: void f(ar,rp) NODE ar; Obj *rp;\
                     89: { GEN _pt1_,_pt2_; CALLPARI1(pf,ARG0(ar),MKPREC(ar,2,ARG1(ar)),rp); }
                     90: #define PARIF2P(f,pf)\
                     91: void f(NODE,Obj *);\
                     92: void f(ar,rp) NODE ar; Obj *rp;\
                     93: { GEN _pt1_,_pt2_,_pt3_; CALLPARI2(pf,ARG0(ar),ARG1(ar),MKPREC(ar,3,ARG2(ar)),rp); }
                     94:
1.7       saito      95: #if defined(INTERVAL)
                     96: #define        PREC_CONV       pariK1
                     97: #else
1.1       noro       98: #if defined(LONG_IS_32BIT)
                     99: #define PREC_CONV              0.103810253
                    100: #endif
                    101: #if defined(LONG_IS_64BIT)
                    102: #define PREC_CONV              0.051905126
                    103: #endif
1.7       saito     104: #endif
1.1       noro      105:
1.5       noro      106: /* XXX : we should be more careful when we free PARI pointers. */
                    107:
                    108: void asir_cgiv(ptr)
                    109: GEN ptr;
                    110: {
                    111:        if ( ptr != gzero && ptr != gun
                    112:        && ptr != gdeux && ptr != ghalf
                    113:        && ptr != polvar && ptr != gi )
                    114:                cgiv(ptr);
                    115: }
                    116:
1.1       noro      117: mkprec(p)
                    118: int p;
                    119: {
1.10    ! noro      120:        if ( p <= 0 )
        !           121:                p = 1;
        !           122:        return (int)(p*PREC_CONV+3);
1.1       noro      123: }
                    124:
                    125: void Peval(arg,rp)
                    126: NODE arg;
                    127: Obj *rp;
                    128: {
                    129:        asir_assert(ARG0(arg),O_R,"eval");
                    130:        evalr(CO,(Obj)ARG0(arg),argc(arg)==2?QTOS((Q)ARG1(arg)):0,rp);
                    131: }
                    132:
                    133: void Psetprec(arg,rp)
                    134: NODE arg;
                    135: Obj *rp;
                    136: {
                    137:        int p;
                    138:        Q q;
                    139:
1.7       saito     140: #if defined(INTERVAL) || 1
                    141:        p = (int)((prec-2)/PREC_CONV); STOQ(p,q); *rp = (Obj)q;
                    142:        if ( arg ) {
                    143:                asir_assert(ARG0(arg),O_N,"setprec");
                    144:                p = QTOS((Q)ARG0(arg));
                    145:                if ( p > 0 )
                    146:                        prec = (long)(p*PREC_CONV+3);
                    147:        }
                    148: #else
1.1       noro      149:        p = (int)((prec-3)/PREC_CONV); STOQ(p,q); *rp = (Obj)q;
                    150:        if ( arg ) {
                    151:                asir_assert(ARG0(arg),O_N,"setprec");
                    152:                prec = mkprec(QTOS((Q)ARG0(arg)));
                    153:        }
1.7       saito     154: #endif
1.1       noro      155: }
1.7       saito     156:
                    157: #if defined(INTERVAL) || 1
                    158: void Psetprecword(arg,rp)
                    159: NODE arg;
                    160: Obj *rp;
                    161: {
                    162:        int p;
                    163:        Q q;
                    164:
                    165:        p = (int)((prec-2)); STOQ(p,q); *rp = (Obj)q;
                    166:        if ( arg ) {
                    167:                asir_assert(ARG0(arg),O_N,"setprecword");
                    168:                p = QTOS((Q)ARG0(arg));
                    169:                if ( p > 0 ) {
                    170:                        prec = p + 2;
                    171:                }
                    172:        }
                    173: }
                    174: #endif
1.1       noro      175:
                    176: void p_pi(arg,rp)
                    177: NODE arg;
                    178: Obj *rp;
                    179: {
                    180:        GEN x;
                    181:
                    182:        x = mppi(MKPREC(arg,1,ARG0(arg)));
1.5       noro      183:        patori(x,rp); asir_cgiv(x);
1.1       noro      184: }
                    185:
                    186: void p_e(arg,rp)
                    187: NODE arg;
                    188: Obj *rp;
                    189: {
                    190:        GEN x;
                    191:
1.5       noro      192:        x = gexp(gun,MKPREC(arg,1,ARG0(arg))); patori(x,rp); asir_cgiv(x);
1.1       noro      193: }
                    194:
                    195: void p_mul(a,b,r)
                    196: Obj a,b,*r;
                    197: {
                    198:        GEN p1,p2,p3;
                    199:
                    200:        ritopa((Obj)a,&p1); ritopa((Obj)b,&p2);
                    201:        p3 = mulii(p1,p2);
1.5       noro      202:        patori(p3,r); asir_cgiv(p3); asir_cgiv(p2); asir_cgiv(p1);
1.1       noro      203: }
                    204:
                    205: void p_gcd(a,b,r)
                    206: N a,b,*r;
                    207: {
                    208:        GEN p1,p2,p3;
                    209:
                    210:        ritopa_i(a,1,&p1); ritopa_i(b,1,&p2);
                    211:        p3 = mppgcd(p1,p2);
1.5       noro      212:        patori_i(p3,r); asir_cgiv(p3); asir_cgiv(p2); asir_cgiv(p1);
1.1       noro      213: }
                    214:
                    215: PARIF1P(p_sin,gsin) PARIF1P(p_cos,gcos) PARIF1P(p_tan,gtan)
                    216: PARIF1P(p_asin,gasin) PARIF1P(p_acos,gacos) PARIF1P(p_atan,gatan)
                    217: PARIF1P(p_sinh,gsh) PARIF1P(p_cosh,gch) PARIF1P(p_tanh,gth)
                    218: PARIF1P(p_asinh,gash) PARIF1P(p_acosh,gach) PARIF1P(p_atanh,gath)
                    219: PARIF1P(p_exp,gexp) PARIF1P(p_log,glog)
                    220: PARIF1P(p_dilog,dilog) PARIF1P(p_erf,gerfc)
                    221: PARIF1P(p_eigen,eigen) PARIF1P(p_roots,roots)
                    222:
                    223: PARIF2P(p_pow,gpui)
                    224:
                    225: pointer evalparif(f,arg)
                    226: FUNC f;
                    227: NODE arg;
                    228: {
                    229:        GEN a,v;
                    230:        long ltop,lbot;
                    231:        pointer r;
1.9       noro      232:        int ac,opt,intarg,ret;
1.1       noro      233:        char buf[BUFSIZ];
1.9       noro      234:        Q q;
1.8       noro      235:        GEN (*dmy)();
1.1       noro      236:
                    237:        if ( !f->f.binf ) {
                    238:                sprintf(buf,"pari : %s undefined.",f->name);
                    239:                error(buf);
1.10    ! noro      240:                /* NOTREACHED */
        !           241:                return 0;
1.1       noro      242:        }
                    243:        switch ( f->type ) {
1.9       noro      244:                case 0: /* in/out : integer */
                    245:                        ac = argc(arg);
                    246:                        if ( ac > 2 ) {
                    247:                                fprintf(stderr,"argument mismatch in %s()\n",NAME(f));
                    248:                                error("");
1.10    ! noro      249:                                /* NOTREACHED */
        !           250:                                return 0;
1.9       noro      251:                        }
                    252:                        intarg = !ac ? 0 : QTOS((Q)ARG0(arg));
                    253:                        dmy = (GEN (*)())f->f.binf;
1.10    ! noro      254:                        ret = (int)(*dmy)(intarg);
1.9       noro      255:                        STOQ(ret,q);
                    256:                        return (pointer)q;
                    257:
1.1       noro      258:                case 1:
                    259:                        ac = argc(arg);
                    260:                        if ( !ac || ( ac > 2 ) ) {
                    261:                                fprintf(stderr,"argument mismatch in %s()\n",NAME(f));
                    262:                                error("");
1.10    ! noro      263:                                /* NOTREACHED */
        !           264:                                return 0;
1.1       noro      265:                        }
                    266:                        ltop = avma;
                    267:                        ritopa((Obj)ARG0(arg),&a);
                    268:                        dmy = (GEN (*)())f->f.binf;
                    269:                        v = (*dmy)(a,MKPREC(arg,2,ARG1(arg)));
                    270:                        lbot = avma;
                    271:                        patori(v,(Obj *)&r); gerepile(ltop,lbot,0);
                    272:                        return r;
1.8       noro      273:
                    274:                case 2:
                    275:                        ac = argc(arg);
                    276:                        if ( !ac || ( ac > 2 ) ) {
                    277:                                fprintf(stderr,"argument mismatch in %s()\n",NAME(f));
                    278:                                error("");
1.10    ! noro      279:                                /* NOTREACHED */
        !           280:                                return 0;
1.8       noro      281:                        }
                    282:                        if ( ac == 1 )
                    283:                                opt = 0;
                    284:                        else
                    285:                                opt = QTOS((Q)ARG1(arg));
                    286:                        ltop = avma;
                    287:                        ritopa((Obj)ARG0(arg),&a);
                    288:                        dmy = (GEN (*)())f->f.binf;
                    289:                        v = (*dmy)(a,opt);
                    290:                        lbot = avma;
                    291:                        patori(v,(Obj *)&r); gerepile(ltop,lbot,0);
                    292:                        return r;
                    293:
1.1       noro      294:                default:
                    295:                        error("evalparif : not implemented yet.");
1.10    ! noro      296:                        /* NOTREACHED */
        !           297:                        return 0;
1.1       noro      298:        }
                    299: }
                    300:
                    301: struct pariftab {
                    302:        char *name;
                    303:        GEN (*f)();
                    304:        int type;
                    305: };
                    306:
1.8       noro      307: /*
                    308:  * type = 1 => argc = 1, second arg = precision
                    309:  * type = 2 => argc = 1, second arg = optional (long int)
                    310:  *
                    311:  */
                    312:
1.1       noro      313: struct pariftab pariftab[] = {
1.10    ! noro      314: {"allocatemem",(GEN(*)())allocatemoremem,0},
1.1       noro      315: {"abs",(GEN (*)())gabs,1},
                    316: {"adj",adj,1},
                    317: {"arg",garg,1},
                    318: {"bigomega",gbigomega,1},
                    319: {"binary",binaire,1},
                    320: {"ceil",gceil,1},
                    321: {"centerlift",centerlift,1},
                    322: {"cf",gcf,1},
                    323: {"classno",classno,1},
                    324: {"classno2",classno2,1},
                    325: {"conj",gconj,1},
                    326: {"content",content,1},
                    327: {"denom",denom,1},
                    328: {"det",det,1},
                    329: {"det2",det2,1},
                    330: {"dilog",dilog,1},
                    331: {"disc",discsr,1},
                    332: {"discf",discf,1},
                    333: {"divisors",divisors,1},
                    334: {"eigen",eigen,1},
                    335: {"eintg1",eint1,1},
                    336: {"erfc",gerfc,1},
                    337: {"eta",eta,1},
                    338: {"floor",gfloor,1},
                    339: {"frac",gfrac,1},
                    340: {"galois",galois,1},
                    341: {"galoisconj",galoisconj,1},
                    342: {"gamh",ggamd,1},
                    343: {"gamma",ggamma,1},
                    344: {"hclassno",classno3,1},
                    345: {"hermite",hnf,1},
                    346: {"hess",hess,1},
                    347: {"imag",gimag,1},
                    348: {"image",image,1},
                    349: {"image2",image2,1},
                    350: {"indexrank",indexrank,1},
                    351: {"indsort",indexsort,1},
                    352: {"initalg",initalg,1},
                    353: {"isfund",gisfundamental,1},
                    354: {"isprime",gisprime,1},
                    355: {"ispsp",gispsp,1},
                    356: {"isqrt",racine,1},
                    357: {"issqfree",gissquarefree,1},
                    358: {"issquare",gcarreparfait,1},
                    359: {"jacobi",jacobi,1},
                    360: {"jell",jell,1},
                    361: {"ker",ker,1},
                    362: {"keri",keri,1},
                    363: {"kerint",kerint,1},
                    364: {"kerintg1",kerint1,1},
                    365: {"kerint2",kerint2,1},
                    366: {"length",(GEN(*)())glength,1},
                    367: {"lexsort",lexsort,1},
                    368: {"lift",lift,1},
                    369: {"lindep",lindep,1},
                    370: {"lll",lll,1},
                    371: {"lllg1",lll1,1},
                    372: {"lllgen",lllgen,1},
                    373: {"lllgram",lllgram,1},
                    374: {"lllgramg1",lllgram1,1},
                    375: {"lllgramgen",lllgramgen,1},
                    376: {"lllgramint",lllgramint,1},
                    377: {"lllgramkerim",lllgramkerim,1},
                    378: {"lllgramkerimgen",lllgramkerimgen,1},
                    379: {"lllint",lllint,1},
                    380: {"lllkerim",lllkerim,1},
                    381: {"lllkerimgen",lllkerimgen,1},
                    382: {"lllrat",lllrat,1},
                    383: {"lngamma",glngamma,1},
                    384: {"logagm",glogagm,1},
                    385: {"mat",gtomat,1},
                    386: {"matrixqz2",matrixqz2,1},
                    387: {"matrixqz3",matrixqz3,1},
                    388: {"matsize",matsize,1},
                    389: {"modreverse",polymodrecip,1},
                    390: {"mu",gmu,1},
                    391: {"nextprime",nextprime,1},
                    392: {"norm",gnorm,1},
                    393: {"norml2",gnorml2,1},
                    394: {"numdiv",numbdiv,1},
                    395: {"numer",numer,1},
                    396: {"omega",gomega,1},
                    397: {"order",order,1},
                    398: {"ordred",ordred,1},
                    399: {"phi",phi,1},
                    400: {"pnqn",pnqn,1},
                    401: {"polred",polred,1},
                    402: {"polred2",polred2,1},
                    403: {"primroot",gener,1},
                    404: {"psi",gpsi,1},
                    405: {"quadgen",quadgen    ,1},
                    406: {"quadpoly",quadpoly    ,1},
                    407: {"real",greal,1},
                    408: {"recip",polrecip       ,1},
                    409: {"redreal",redreal       ,1},
                    410: {"regula",regula  ,1},
                    411: {"reorder",reorder  ,1},
                    412: {"reverse",recip  ,1},
                    413: {"rhoreal",rhoreal       ,1},
                    414: {"roots",roots,1},
                    415: {"round",ground,1},
                    416: {"sigma",sumdiv,1},
                    417: {"signat",signat,1},
                    418: {"simplify",simplify,1},
                    419: {"smalldiscf",smalldiscf,1},
                    420: {"smallfact",smallfact,1},
                    421: {"smallpolred",smallpolred,1},
                    422: {"smallpolred2",smallpolred2,1},
                    423: {"smith",smith,1},
                    424: {"smith2",smith2,1},
                    425: {"sort",sort,1},
                    426: {"sqr",gsqr,1},
                    427: {"sqred",sqred,1},
                    428: {"sqrt",gsqrt,1},
                    429: {"supplement",suppl,1},
                    430: {"trace",gtrace,1},
                    431: {"trans",gtrans,1},
                    432: {"trunc",gtrunc,1},
                    433: {"unit",fundunit,1},
                    434: {"vec",gtovec,1},
                    435: {"wf",wf,1},
                    436: {"wf2",wf2,1},
                    437: {"zeta",gzeta,1},
1.9       noro      438: {"factor",factor,1},
1.8       noro      439: {"factorint",factorint,2},
1.1       noro      440: {0,0,0},
                    441: };
                    442:
                    443: void parif_init() {
                    444:        int i;
                    445:
                    446:        for ( i = 0, parif = 0; pariftab[i].name; i++ )
                    447:                 appendparif(&parif,pariftab[i].name, (int (*)())pariftab[i].f,pariftab[i].type);
                    448: }
                    449: #else /* PARI */
                    450:
                    451: struct ftab pari_tab[] = {
                    452:        {0,0,0},
                    453: };
                    454:
                    455: void parif_init() {}
                    456:
1.2       noro      457: pointer evalparif(f,arg)
                    458: FUNC f;
                    459: NODE arg;
                    460: {
1.1       noro      461:        error("evalparif : PARI is not combined.");
                    462: }
                    463: #endif /*PARI */

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