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

Annotation of OpenXM_contrib2/asir2000/engine/A.c, Revision 1.4

1.2       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.3       noro       26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.2       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.4     ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/engine/A.c,v 1.3 2000/08/22 05:04:03 noro Exp $
1.2       noro       49: */
1.1       noro       50: #include "ca.h"
                     51:
                     52: void pdiva(vl,p0,p1,p2,pr)
                     53: VL vl;
                     54: P p1,p2,p0;
                     55: P *pr;
                     56: {
                     57:        Q m,d;
                     58:        P t,q,r;
                     59:
                     60:        if ( VR(p2) == VR(p0) ) {
                     61:                *pr = p1;
                     62:                return;
                     63:        }
                     64:        if ( VR(p1) == VR(p0) ) {
                     65:                error("pdiva : ???");
                     66:                return;
                     67:        }
                     68:        subq(DEG(DC(p1)),DEG(DC(p2)),&m); addq(m,ONE,&d);
                     69:        pwrq((Q)COEF(DC(p2)),d,&m); mulp(vl,p1,(P)m,&t);
                     70:        divsrp(vl,t,p2,&q,&r); remsdcp(vl,q,p0,pr);
                     71: }
                     72:
                     73: void rema(vl,p0,p1,p2,pr)
                     74: VL vl;
                     75: P p1,p2,p0,*pr;
                     76: {
                     77:        P m,m1,m2,g,lc,x,t;
                     78:        Q q;
                     79:        V v;
                     80:        int d1,d2;
                     81:
                     82:        if ( !p1 || !p2 || NUM(p2) || ( VR(p2) == VR(p0) ) )
                     83:                *pr = 0;
                     84:        else if ( NUM(p1) )
                     85:                *pr = p1;
                     86:        else if ( ( v = VR(p1) ) == VR(p0) )
                     87:                remsdcp(vl,p1,p0,pr);
                     88:        else if ( ( d1 = deg(v,p1) ) < ( d2 = deg(v,p2) ) )
                     89:                *pr = p1;
                     90:        else if ( d1 == d2 ) {
                     91:                mulp(vl,p1,LC(p2),&m); mulp(vl,p2,LC(p1),&m1);
                     92:                subp(vl,m,m1,&m2);
                     93:                remsdcp(vl,m2,p0,pr);
                     94:        } else {
                     95:                g = p1; lc = LC(p2); MKV(v,x);
                     96:                while ( ( d1 = deg(v,g) ) >= d2 ) {
                     97:                        mulp(vl,g,lc,&m); mulp(vl,p2,LC(g),&m1);
                     98:                        STOQ(d1-d2,q); pwrp(vl,x,q,&t);
                     99:                        mulp(vl,m1,t,&m2); subp(vl,m,m2,&m1);
                    100:                        remsdcp(vl,m1,p0,&g);
                    101:                }
                    102:                *pr = g;
                    103:        }
                    104: }
                    105:
                    106: void gcda(vl,p0,p1,p2,pr)
                    107: VL vl;
                    108: P p1,p2,p0,*pr;
                    109: {
                    110:        P g1,g2,r,t,c;
                    111:
                    112:        remsdcp(vl,p1,p0,&t); pcp(vl,t,&g1,&c); remsdcp(vl,p2,p0,&g2);
                    113:        while ( 1 ) {
                    114:                if ( NUM(g2) || (VR(g2) == VR(p0)) ) {
                    115:                        *pr = (P)ONE;
                    116:                        return;
                    117:                }
                    118:                pcp(vl,g2,&t,&c); pmonic(vl,p0,t,&g2); rema(vl,p0,g1,g2,&r);
                    119:                if ( !r ) {
                    120:                        pmonic(vl,p0,g2,pr);
                    121:                        return;
                    122:                }
                    123:                g1 = g2; g2 = r;
                    124:        }
                    125: }
                    126:
                    127: void sqa(vl,p0,p,dcp)
                    128: VL vl;
                    129: P p,p0;
                    130: DCP *dcp;
                    131: {
                    132:        V v;
                    133:        int i,j,n;
                    134:        P f,f1,f2,gcd,flat,q,r,t;
                    135:        P *a;
                    136:        int *b;
                    137:        DCP dc,dc0;
                    138:
                    139:        if ( ( v = VR(p) ) == VR(p0) ) {
                    140:                NEWDC(dc); *dcp = dc; COEF(dc) = (P)ONE; DEG(dc) = ONE;
                    141:                NEXT(dc) = 0;
                    142:        } else {
                    143:                n = deg(v,p); W_CALLOC(n,P,a); W_CALLOC(n,int,b);
                    144:                for ( i = 0, f = p; ;i++ ) {
                    145:                        if ( VR(f) != v )
                    146:                                break;
                    147:                        remsdcp(vl,f,p0,&f1); diffp(vl,f1,VR(f1),&f2);
                    148:                        while ( 1 ) {
                    149:                                pmonic(vl,p0,f2,&t); f2 = t; rema(vl,p0,f1,f2,&r);
                    150:                                if ( !r ) {
                    151:                                        pmonic(vl,p0,f2,&gcd); pqra(vl,p0,f,gcd,&flat,&r);
                    152:                                        break;
                    153:                                }
                    154:                                f1 = f2; f2 = r;
                    155:                        }
                    156:                        if ( VR(gcd) != v ) {
                    157:                                a[i] = f; b[i] = 1;
                    158:                                break;
                    159:                        }
                    160:                        for ( j = 1, f = gcd; ; j++ ) {
                    161:                                pqra(vl,p0,f,flat,&q,&r);
                    162:                                if ( r )
                    163:                                        break;
                    164:                                else
                    165:                                        f = q;
                    166:                        }
                    167:                        a[i] = flat; b[i] = j;
                    168:                }
                    169:                for ( i = 0, j = 0, dc0 = 0; a[i]; i++ ) {
                    170:                        NEXTDC(dc0,dc); j += b[i]; STOQ(j,DEG(dc));
                    171:                        if ( a[i+1] )
                    172:                                pqra(vl,p0,a[i],a[i+1],&COEF(dc),&t);
                    173:                        else
                    174:                                COEF(dc) = a[i];
                    175:                }
                    176:                NEXT(dc) = 0; *dcp = dc0;
                    177:        }
                    178: }
                    179:
                    180: void pqra(vl, p0, p1, p2, p, pr)
                    181: VL vl;
                    182: P p0,p1,p2;
                    183: P *p,*pr;
                    184: {
                    185:        V v,v1;
                    186:        P  m,m1,q,r;
                    187:        Q tq;
                    188:        int n;
                    189:
                    190:        if ( ( v = VR(p1) ) != ( v1 = VR(p2) ) ) {
                    191:                while ( ( VR(vl) != v ) && ( VR(vl) != v1 ) )
                    192:                        vl = NEXT(vl);
                    193:                if ( VR(vl) == v ) {
                    194:                        *p = p1; *pr = 0;
                    195:                } else {
                    196:                        *p = 0; *pr = p1;
                    197:                }
                    198:        } else if ( (n = deg(v,p1) - deg(v,p2)) < 0 ) {
                    199:                *pr = p1; *p = 0;
                    200:        } else {
                    201:                n++; STOQ(n,tq);
                    202:                pwrp(vl,LC(p2),tq,&m); mulp(vl,m,p1,&m1); divsrp(vl,m1,p2,&q,&r);
                    203:                remsdcp(vl,q,p0,p); remsdcp(vl,r,p0,pr);
                    204:        }
                    205: }
                    206:
                    207: void pmonic(vl, p0, p, pr)
                    208: VL vl;
                    209: P p,p0,*pr;
                    210: {
                    211:        P d,m,pp,c,t;
                    212:
                    213:        if ( NUM(p) || ( VR(p) == VR(p0) ) )
                    214:                *pr = (P)ONE;
                    215:        else if ( NUM(COEF(DC(p))) )
                    216:                *pr = p;
                    217:        else {
                    218:                ptozp(COEF(DC(p)),1,(Q *)&c,&pp); pinva(p0,pp,&d);
                    219:                mulp(vl,p,d,&m); remsdcp(vl,m,p0,&t); ptozp(t,1,(Q *)&c,pr);
                    220:        }
                    221: }
                    222:
                    223: void remsdcp(vl, p, p0, pr)
                    224: VL vl;
                    225: P p,p0,*pr;
                    226: {
                    227:        P q,r,c;
                    228:        DCP dc,dcr,dcr0;
                    229:
                    230:        if ( !p )
                    231:                *pr = 0;
                    232:        else if ( NUM(p) )
                    233:                *pr = (P)ONE;
                    234:        else if ( VR(p) == VR(p0) ) {
                    235:                divsrp(vl,p,p0,&q,&r); ptozp(r,1,(Q *)&c,pr);
                    236:        } else {
                    237:                for ( dcr = dcr0 = 0, dc = DC(p); dc; dc = NEXT(dc) ) {
                    238:                        divsrp(vl,COEF(dc),p0,&q,&r);
                    239:                        if ( r ) {
                    240:                                NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc); COEF(dcr) = r;
                    241:                        }
                    242:                }
                    243:                if ( !dcr0 )
                    244:                        *pr = 0;
                    245:                else {
                    246:                        NEXT(dcr) = 0; MKP(VR(p),dcr0,r); ptozp(r,1,(Q *)&c,pr);
                    247:                }
                    248:        }
                    249: }
                    250:
                    251: void pinva(p0, p, pr)
                    252: P p,p0,*pr;
                    253: {
                    254:        V v;
                    255:        Q f,q,q1;
                    256:        Q u,t,a,b,s;
                    257:        P c,c1;
                    258:        P tg,th,tr;
                    259:        P z,zz,zzz;
                    260:        UM wg,wh,ws,wt,wm;
                    261:        int n,m,modres,mod,index,i;
                    262:
                    263:        v = VR(p); n=deg(v,p); m=deg(v,p0);
                    264:        norm(p,&a); norm(p0,&b);
                    265:        STOQ(m,u); pwrq(a,u,&t); STOQ(n,u); pwrq(b,u,&s);
                    266:        mulq(t,s,&u);
                    267:        factorial(n+m,&t); mulq(u,t,&s); addq(s,s,&f);
                    268:        wg = W_UMALLOC(m+n); wh = W_UMALLOC(m+n);
                    269:        wt = W_UMALLOC(m+n); ws = W_UMALLOC(m+n);
                    270:        wm = W_UMALLOC(m+n);
                    271:        for ( q = ONE, t = 0, c = 0, index = 0; ; ) {
1.4     ! noro      272:                mod = get_lprime(index++);
1.1       noro      273:                if ( !rem(NM((Q)LC(p)),mod) || !rem(NM((Q)LC(p0)),mod) )
                    274:                        continue;
                    275:                ptomp(mod,p,&tg); ptomp(mod,p0,&th); srchump(mod,tg,th,&tr);
                    276:                if ( !tr )
                    277:                        continue;
                    278:                else
                    279:                        modres = CONT((MQ)tr);
                    280:                mptoum(tg,wg); mptoum(th,wh);
                    281:                eucum(mod,wg,wh,ws,wt); /* wg * ws + wh * wt = 1 */
                    282:                DEG(wm) = 0; COEF(wm)[0] = modres;
                    283:                mulum(mod,ws,wm,wt);
                    284:                for ( i = DEG(wt); i >= 0; i-- )
                    285:                        if ( ( COEF(wt)[i] * 2 ) > mod )
                    286:                                COEF(wt)[i] -= mod;
                    287:                chnrem(mod,v,c,q,wt,&c1,&q1);
                    288:                if ( !ucmpp(c,c1) ) {
                    289:                        mulp(CO,c,p,&z); divsrp(CO,z,p0,&zz,&zzz);
                    290:                        if ( NUM(zzz) ) {
                    291:                                q = q1; c = c1; break;
                    292:                        }
                    293:                }
                    294:                q = q1; c = c1;
                    295:                if ( cmpq(f,q) < 0 )
                    296:                        break;
                    297:        }
                    298:        ptozp(c,1,&s,pr);
                    299: }

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