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

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.5     ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/builtin/parif.c,v 1.4 2000/08/22 05:03:59 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: #if defined(THINK_C)
                     59: void patori(GEN,Obj *);
                     60: void patori_i(GEN,N *);
                     61: void ritopa(Obj,GEN *);
                     62: void ritopa_i(N,int,GEN *);
                     63: #else
                     64: void patori();
                     65: void patori_i();
                     66: void ritopa();
                     67: void ritopa_i();
                     68: #endif
                     69:
                     70: void Peval(),Psetprec(),p_pi(),p_e(),p_mul(),p_gcd();
1.5     ! noro       71: void asir_cgiv(GEN);
1.1       noro       72:
                     73: struct ftab pari_tab[] = {
                     74:        {"eval",Peval,-2}, {"setprec",Psetprec,-1}, {0,0,0},
                     75: };
                     76:
                     77: #define MKPREC(a,i,b) (argc(a)==(i)?mkprec(QTOS((Q)(b))):prec)
                     78:
                     79: #define CALLPARI1(f,a,p,r)\
1.5     ! noro       80: ritopa((Obj)a,&_pt1_); _pt2_ = f(_pt1_,p); patori(_pt2_,r); asir_cgiv(_pt2_); asir_cgiv(_pt1_)
1.1       noro       81: #define CALLPARI2(f,a,b,p,r)\
1.5     ! noro       82: 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       83:
                     84: #define PARIF1P(f,pf)\
                     85: void f(NODE,Obj *);\
                     86: void f(ar,rp) NODE ar; Obj *rp;\
                     87: { GEN _pt1_,_pt2_; CALLPARI1(pf,ARG0(ar),MKPREC(ar,2,ARG1(ar)),rp); }
                     88: #define PARIF2P(f,pf)\
                     89: void f(NODE,Obj *);\
                     90: void f(ar,rp) NODE ar; Obj *rp;\
                     91: { GEN _pt1_,_pt2_,_pt3_; CALLPARI2(pf,ARG0(ar),ARG1(ar),MKPREC(ar,3,ARG2(ar)),rp); }
                     92:
                     93: #if defined(LONG_IS_32BIT)
                     94: #define PREC_CONV              0.103810253
                     95: #endif
                     96: #if defined(LONG_IS_64BIT)
                     97: #define PREC_CONV              0.051905126
                     98: #endif
                     99:
1.5     ! noro      100: /* XXX : we should be more careful when we free PARI pointers. */
        !           101:
        !           102: void asir_cgiv(ptr)
        !           103: GEN ptr;
        !           104: {
        !           105:        if ( ptr != gzero && ptr != gun
        !           106:        && ptr != gdeux && ptr != ghalf
        !           107:        && ptr != polvar && ptr != gi )
        !           108:                cgiv(ptr);
        !           109: }
        !           110:
1.1       noro      111: mkprec(p)
                    112: int p;
                    113: {
                    114:        if ( p > 0 )
                    115:                return (int)(p*PREC_CONV+3);
                    116: }
                    117:
                    118: void Peval(arg,rp)
                    119: NODE arg;
                    120: Obj *rp;
                    121: {
                    122:        asir_assert(ARG0(arg),O_R,"eval");
                    123:        evalr(CO,(Obj)ARG0(arg),argc(arg)==2?QTOS((Q)ARG1(arg)):0,rp);
                    124: }
                    125:
                    126: void Psetprec(arg,rp)
                    127: NODE arg;
                    128: Obj *rp;
                    129: {
                    130:        int p;
                    131:        Q q;
                    132:
                    133:        p = (int)((prec-3)/PREC_CONV); STOQ(p,q); *rp = (Obj)q;
                    134:        if ( arg ) {
                    135:                asir_assert(ARG0(arg),O_N,"setprec");
                    136:                prec = mkprec(QTOS((Q)ARG0(arg)));
                    137:        }
                    138: }
                    139:
                    140: void p_pi(arg,rp)
                    141: NODE arg;
                    142: Obj *rp;
                    143: {
                    144:        GEN x;
                    145:
                    146:        x = mppi(MKPREC(arg,1,ARG0(arg)));
1.5     ! noro      147:        patori(x,rp); asir_cgiv(x);
1.1       noro      148: }
                    149:
                    150: void p_e(arg,rp)
                    151: NODE arg;
                    152: Obj *rp;
                    153: {
                    154:        GEN x;
                    155:
1.5     ! noro      156:        x = gexp(gun,MKPREC(arg,1,ARG0(arg))); patori(x,rp); asir_cgiv(x);
1.1       noro      157: }
                    158:
                    159: void p_mul(a,b,r)
                    160: Obj a,b,*r;
                    161: {
                    162:        GEN p1,p2,p3;
                    163:
                    164:        ritopa((Obj)a,&p1); ritopa((Obj)b,&p2);
                    165:        p3 = mulii(p1,p2);
1.5     ! noro      166:        patori(p3,r); asir_cgiv(p3); asir_cgiv(p2); asir_cgiv(p1);
1.1       noro      167: }
                    168:
                    169: void p_gcd(a,b,r)
                    170: N a,b,*r;
                    171: {
                    172:        GEN p1,p2,p3;
                    173:
                    174:        ritopa_i(a,1,&p1); ritopa_i(b,1,&p2);
                    175:        p3 = mppgcd(p1,p2);
1.5     ! noro      176:        patori_i(p3,r); asir_cgiv(p3); asir_cgiv(p2); asir_cgiv(p1);
1.1       noro      177: }
                    178:
                    179: PARIF1P(p_sin,gsin) PARIF1P(p_cos,gcos) PARIF1P(p_tan,gtan)
                    180: PARIF1P(p_asin,gasin) PARIF1P(p_acos,gacos) PARIF1P(p_atan,gatan)
                    181: PARIF1P(p_sinh,gsh) PARIF1P(p_cosh,gch) PARIF1P(p_tanh,gth)
                    182: PARIF1P(p_asinh,gash) PARIF1P(p_acosh,gach) PARIF1P(p_atanh,gath)
                    183: PARIF1P(p_exp,gexp) PARIF1P(p_log,glog)
                    184: PARIF1P(p_dilog,dilog) PARIF1P(p_erf,gerfc)
                    185: PARIF1P(p_eigen,eigen) PARIF1P(p_roots,roots)
                    186:
                    187: PARIF2P(p_pow,gpui)
                    188:
                    189: pointer evalparif(f,arg)
                    190: FUNC f;
                    191: NODE arg;
                    192: {
                    193:        GEN a,v;
                    194:        long ltop,lbot;
                    195:        pointer r;
                    196:        int ac;
                    197:        char buf[BUFSIZ];
                    198:
                    199:        if ( !f->f.binf ) {
                    200:                sprintf(buf,"pari : %s undefined.",f->name);
                    201:                error(buf);
                    202:        }
                    203:        switch ( f->type ) {
                    204:                case 1:
                    205:                        ac = argc(arg);
                    206:                        if ( !ac || ( ac > 2 ) ) {
                    207:                                fprintf(stderr,"argument mismatch in %s()\n",NAME(f));
                    208:                                error("");
                    209:                        }
                    210:                        ltop = avma;
                    211:                        ritopa((Obj)ARG0(arg),&a);
                    212: #if 1 || defined(__MWERKS__)
                    213:                {
                    214:                        GEN (*dmy)();
                    215:
                    216:                        dmy = (GEN (*)())f->f.binf;
                    217:                        v = (*dmy)(a,MKPREC(arg,2,ARG1(arg)));
                    218:                }
                    219: #else
                    220:                        v = (GEN)(*f->f.binf)(a,MKPREC(arg,2,ARG1(arg)));
                    221: #endif
                    222:                        lbot = avma;
                    223:                        patori(v,(Obj *)&r); gerepile(ltop,lbot,0);
                    224:                        return r;
                    225:                default:
                    226:                        error("evalparif : not implemented yet.");
                    227:        }
                    228: }
                    229:
                    230: struct pariftab {
                    231:        char *name;
                    232:        GEN (*f)();
                    233:        int type;
                    234: };
                    235:
                    236: struct pariftab pariftab[] = {
                    237: {"abs",(GEN (*)())gabs,1},
                    238: {"adj",adj,1},
                    239: {"arg",garg,1},
                    240: {"bigomega",gbigomega,1},
                    241: {"binary",binaire,1},
                    242: {"ceil",gceil,1},
                    243: {"centerlift",centerlift,1},
                    244: {"cf",gcf,1},
                    245: {"classno",classno,1},
                    246: {"classno2",classno2,1},
                    247: {"conj",gconj,1},
                    248: {"content",content,1},
                    249: {"denom",denom,1},
                    250: {"det",det,1},
                    251: {"det2",det2,1},
                    252: {"dilog",dilog,1},
                    253: {"disc",discsr,1},
                    254: {"discf",discf,1},
                    255: {"divisors",divisors,1},
                    256: {"eigen",eigen,1},
                    257: {"eintg1",eint1,1},
                    258: {"erfc",gerfc,1},
                    259: {"eta",eta,1},
                    260: {"floor",gfloor,1},
                    261: {"frac",gfrac,1},
                    262: {"galois",galois,1},
                    263: {"galoisconj",galoisconj,1},
                    264: {"gamh",ggamd,1},
                    265: {"gamma",ggamma,1},
                    266: {"hclassno",classno3,1},
                    267: {"hermite",hnf,1},
                    268: {"hess",hess,1},
                    269: {"imag",gimag,1},
                    270: {"image",image,1},
                    271: {"image2",image2,1},
                    272: {"indexrank",indexrank,1},
                    273: {"indsort",indexsort,1},
                    274: {"initalg",initalg,1},
                    275: {"isfund",gisfundamental,1},
                    276: {"isprime",gisprime,1},
                    277: {"ispsp",gispsp,1},
                    278: {"isqrt",racine,1},
                    279: {"issqfree",gissquarefree,1},
                    280: {"issquare",gcarreparfait,1},
                    281: {"jacobi",jacobi,1},
                    282: {"jell",jell,1},
                    283: {"ker",ker,1},
                    284: {"keri",keri,1},
                    285: {"kerint",kerint,1},
                    286: {"kerintg1",kerint1,1},
                    287: {"kerint2",kerint2,1},
                    288: {"length",(GEN(*)())glength,1},
                    289: {"lexsort",lexsort,1},
                    290: {"lift",lift,1},
                    291: {"lindep",lindep,1},
                    292: {"lll",lll,1},
                    293: {"lllg1",lll1,1},
                    294: {"lllgen",lllgen,1},
                    295: {"lllgram",lllgram,1},
                    296: {"lllgramg1",lllgram1,1},
                    297: {"lllgramgen",lllgramgen,1},
                    298: {"lllgramint",lllgramint,1},
                    299: {"lllgramkerim",lllgramkerim,1},
                    300: {"lllgramkerimgen",lllgramkerimgen,1},
                    301: {"lllint",lllint,1},
                    302: {"lllkerim",lllkerim,1},
                    303: {"lllkerimgen",lllkerimgen,1},
                    304: {"lllrat",lllrat,1},
                    305: {"lngamma",glngamma,1},
                    306: {"logagm",glogagm,1},
                    307: {"mat",gtomat,1},
                    308: {"matrixqz2",matrixqz2,1},
                    309: {"matrixqz3",matrixqz3,1},
                    310: {"matsize",matsize,1},
                    311: {"modreverse",polymodrecip,1},
                    312: {"mu",gmu,1},
                    313: {"nextprime",nextprime,1},
                    314: {"norm",gnorm,1},
                    315: {"norml2",gnorml2,1},
                    316: {"numdiv",numbdiv,1},
                    317: {"numer",numer,1},
                    318: {"omega",gomega,1},
                    319: {"order",order,1},
                    320: {"ordred",ordred,1},
                    321: {"phi",phi,1},
                    322: {"pnqn",pnqn,1},
                    323: {"polred",polred,1},
                    324: {"polred2",polred2,1},
                    325: {"primroot",gener,1},
                    326: {"psi",gpsi,1},
                    327: {"quadgen",quadgen    ,1},
                    328: {"quadpoly",quadpoly    ,1},
                    329: {"real",greal,1},
                    330: {"recip",polrecip       ,1},
                    331: {"redreal",redreal       ,1},
                    332: {"regula",regula  ,1},
                    333: {"reorder",reorder  ,1},
                    334: {"reverse",recip  ,1},
                    335: {"rhoreal",rhoreal       ,1},
                    336: {"roots",roots,1},
                    337: {"round",ground,1},
                    338: {"sigma",sumdiv,1},
                    339: {"signat",signat,1},
                    340: {"simplify",simplify,1},
                    341: {"smalldiscf",smalldiscf,1},
                    342: {"smallfact",smallfact,1},
                    343: {"smallpolred",smallpolred,1},
                    344: {"smallpolred2",smallpolred2,1},
                    345: {"smith",smith,1},
                    346: {"smith2",smith2,1},
                    347: {"sort",sort,1},
                    348: {"sqr",gsqr,1},
                    349: {"sqred",sqred,1},
                    350: {"sqrt",gsqrt,1},
                    351: {"supplement",suppl,1},
                    352: {"trace",gtrace,1},
                    353: {"trans",gtrans,1},
                    354: {"trunc",gtrunc,1},
                    355: {"unit",fundunit,1},
                    356: {"vec",gtovec,1},
                    357: {"wf",wf,1},
                    358: {"wf2",wf2,1},
                    359: {"zeta",gzeta,1},
                    360: {0,0,0},
                    361: };
                    362:
                    363: void parif_init() {
                    364:        int i;
                    365:
                    366:        for ( i = 0, parif = 0; pariftab[i].name; i++ )
                    367:                 appendparif(&parif,pariftab[i].name, (int (*)())pariftab[i].f,pariftab[i].type);
                    368: }
                    369: #else /* PARI */
                    370:
                    371: struct ftab pari_tab[] = {
                    372:        {0,0,0},
                    373: };
                    374:
                    375: void parif_init() {}
                    376:
1.2       noro      377: pointer evalparif(f,arg)
                    378: FUNC f;
                    379: NODE arg;
                    380: {
1.1       noro      381:        error("evalparif : PARI is not combined.");
                    382: }
                    383: #endif /*PARI */

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