[BACK]Return to const CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / lib

Annotation of OpenXM_contrib2/asir2000/lib/const, Revision 1.3

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.3     ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/lib/const,v 1.2 2000/08/21 08:31:41 noro Exp $
1.2       noro       49: */
1.1       noro       50: def cat(D) {
                     51:        tstart;
                     52:        for ( S = T = P = idiv(10^D,2), I = 1, J = 3; T; I++, J += 2 ) {
                     53:                P = idiv(P*I,J); T = idiv(T*I+P,J); S += T;
                     54:        }
                     55:        tstop;
                     56:        return S;
                     57: }
                     58:
                     59: def e(D,N)
                     60: {
                     61:        for ( F = 1, S = 1, I = 1; I <= N; I++ ) {
                     62:                S = S*I + 1;
                     63:                F *= I;
                     64:        }
                     65:        T = red(S/F);
                     66:        return idiv(nm(T)*10^D,dn(T));
                     67: }
                     68:
                     69: def at0(X,D)
                     70: {
                     71:        for ( S = T = idiv(D,X), I = 1, Y = X^2, Sgn = -1;
                     72:                T;
                     73:                I += 2, Sgn *= -1 ) {
                     74:                T = idiv(T*I,Y*(I+2)); S += (Sgn*T);
                     75:        }
                     76:        return S;
                     77: }
                     78:
                     79: def pi(D)
                     80: {
                     81:        tstart; Y = 10^D; X = 16*at0(5,Y)-4*at0(239,Y); tstop;
                     82:        return X;
                     83: }
                     84:
                     85: def at1(M,D) {
                     86: for (N = 1, SGN = 1, MM = M*M, A = 0, XN = idiv(D,M);
                     87:        XN;
                     88:        N += 2, XN = idiv(XN,MM), SGN *= -1)
                     89:                A += (SGN*idiv(XN,N));
                     90:        return A;
                     91: }
                     92:
                     93: def pi1(D) {
                     94:        tstart; Y = 10^D; X = 16*at1(5,Y)-4*at1(239,Y); tstop;
                     95:        return X;
                     96: }
                     97:
                     98: def pi2(D) {
                     99:        tstart; Y = 10^D;
                    100:        X = 48*at1(49,Y)+128*at1(57,Y)-20*at1(239,Y)+48*at1(110443,Y);
                    101:        tstop;
                    102:        return X;
                    103: }
                    104:
                    105:
                    106: def bn(N)
                    107: {
                    108:        B = newvect(N+1); C = c2(N+1);
                    109:        for ( I = 1, B[0] = 1; I <= N; I++ ) {
                    110:                for ( D = C[I+1], J = 0, S = 0; J < I; J++ )
                    111:                        S += D[J]*B[J];
                    112:                B[I] = red(-S/(I+1));
                    113:        }
                    114:        return [B,C];
                    115: }
                    116:
                    117: def bp(N,B,C,V)
                    118: {
                    119:        for ( I = 0, S = 0; I <= N; I++ )
                    120:                S += C[I]*B[N-I]*V^I;
                    121:        return S;
                    122: }
                    123:
                    124: /*
                    125:  * sum(N) = 1^N+2^N+...+n^N
                    126:  */
                    127:
                    128: def sum(N)
                    129: {
                    130:        L = bn(N+1);
                    131:        R = car(L); C = car(cdr(L));
                    132:        S = bp(N+1,R,C[N+1],n);
                    133:        return red((subst(S,n,n+1)-subst(S,n,1))/(N+1));
                    134: }
                    135:
                    136: def c(N,I)
                    137: {
                    138:        for ( M = 1, J = 0; J < I; J++ )
                    139:                M *= N-J;
                    140:        return red(M/f(I));
                    141: }
                    142:
                    143: def c1(N)
                    144: {
                    145:        A = newvect(N+1); B = newvect(N+1); A[0] = 1;
                    146:        for ( K = 1; K <= N; K++ ) {
                    147:                B[0] = B[K] = 1;
                    148:                for ( J = 1; J < K; J++ ) B[J] = A[J-1]+A[J];
                    149:                T = A; A = B; B = T;
                    150:        }
                    151:        return A;
                    152: }
                    153:
                    154: def c2(N)
                    155: {
                    156:        A = newvect(N+1); A[0] = B = newvect(1); B[0] = 1;
                    157:        for ( K = 1; K <= N; K++ ) {
                    158:                A[K] = B = newvect(K+1); B[0] = B[K] = 1;
                    159:                for ( P = A[K-1], J = 1; J < K; J++ )
                    160:                        B[J] = P[J-1]+P[J];
                    161:        }
                    162:        return A;
                    163: }
                    164:
                    165: def f(N)
                    166: {
                    167:        for ( I = 1, M = 1; I <= N; I++ )
                    168:                M *= I;
                    169:        return M;
                    170: }
                    171:
                    172: def sumd(N,M)
                    173: {
                    174:        for ( I = 1, S = 0; I <= M; I++ )
                    175:                S += I^N;
                    176:        return S;
                    177: }
                    178:
                    179: #if 0
                    180: def sqrt(A,N) {
                    181:        for ( I = 0, X = 1, B = A; I < N; I++, B *= 100, X *= 10 ) {
                    182:                while ( 1 ) {
                    183:                        T = idiv(idiv(B,X) + X,2);
                    184: /*
                    185:                        if ((Y = T - X)== 0)
                    186:                                if ( B == X^2) return (X/(10^I));
                    187:                                else break;
                    188:                        else if ( (Y == 1) || (Y == -1) ) break;
                    189: */
                    190:                        if ( ( (Y = T - X) == 0 ) || (Y == 1) || (Y == -1) ) break;
                    191:                        X = T;
                    192:                }
                    193:        }
                    194:        return (X/(10^I));
                    195: }
                    196: #endif
                    197:
                    198: def sqrt(A) {
                    199:        for ( J = 0, T = A; T >= 2^27; J++ ) {
                    200:                T = idiv(T,2^27)+1;
                    201:        }
                    202:        for ( I = 0; T >= 2; I++ ) {
                    203:                S = idiv(T,2);
                    204:                if ( T = S+S )
                    205:                        T = S;
                    206:                else
                    207:                        T = S+1;
                    208:        }
                    209:        X = (2^27)^idiv(J,2)*2^idiv(I,2);
                    210:        while ( 1 ) {
                    211:                if ( (Y=X^2) < A )
                    212:                        X += X;
                    213:                else if ( Y == A )
                    214:                        return X;
                    215:                else
                    216:                        break;
                    217:        }
                    218:        while ( 1 )
                    219:                if ( (Y = X^2) <= A )
                    220:                        return X;
                    221:                else
                    222:                        X = idiv(A + Y,2*X);
                    223: }
                    224: end$

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