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

Annotation of OpenXM_contrib2/asir2000/lib/mat, 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/mat,v 1.2 2000/08/21 08:31:41 noro Exp $
1.2       noro       49: */
1.1       noro       50: /* fraction free gaussian elimination; detructive */
                     51:
                     52: def deter(MAT)
                     53: {
                     54:        S = size(MAT);
                     55:        if ( car(S) != car(cdr(S)) )
                     56:                return 0;
                     57:        N = car(S);
                     58:        for ( J = 0, D = 1; J < N; J++ ) {
                     59:                for ( I = J; (I<N)&&(MAT[I][J] == 0); I++ );
                     60:                if ( I != N ) {
                     61:                        for ( L = I; L < N; L++ )
                     62:                                if ( MAT[L][J] && (nmono(MAT[L][J]) < nmono(MAT[I][J])) )
                     63:                                        I = L;
                     64:                        if ( J != I )
                     65:                                for ( K = 0; K < N; K++ ) {
                     66:                                        B = MAT[J][K]; MAT[J][K] = MAT[I][K]; MAT[I][K] = B;
                     67:                                }
                     68:
                     69:                        for ( I = J + 1, V = MAT[J][J]; I < N; I++ )
                     70:                                for ( K = J + 1, U = MAT[I][J]; K < N; K++ )
                     71:                                        MAT[I][K] = sdiv(MAT[I][K]*V-MAT[J][K]*U,D);
                     72:                        D = V;
                     73:                } else
                     74:                        return ( 0 );
                     75:        }
                     76:        return (D);
                     77: }
                     78:
                     79: /* characteristic polynomial */
                     80:
                     81: def cp(M)
                     82: {
                     83:        tstart;
                     84:        S = size(M);
                     85:        if ( car(S) != car(cdr(S)) )
                     86:                return 0;
                     87:        N = car(S);
                     88:        MAT = newmat(N,N);
                     89:        for ( I = 0; I < N; I++ )
                     90:                for ( J = 0; J < N; J++ )
                     91:                        if ( I == J )
                     92:                                MAT[I][J] = red(M[I][J]-x);
                     93:                        else
                     94:                                MAT[I][J] = red(M[I][J]);
                     95:        D = deter(MAT);
                     96:        tstop;
                     97:        return (D);
                     98: }
                     99:
                    100: /* calculation of charpoly by danilevskii's method */
                    101:
                    102: def da(MAT)
                    103: {
                    104:        tstart;
                    105:        S = size(MAT);
                    106:        if ( car(S) != car(cdr(S)) )
                    107:                return 0;
                    108:        N = car(S);
                    109:        M = newmat(N,N);
                    110:        for ( I = 0; I < N; I++ )
                    111:                for ( J = 0; J < N; J++ )
                    112:                        M[I][J] = red(MAT[I][J]);
                    113:
                    114:        for ( W = newvect(N), J = 0, K = 0, D = 1; J < N; J++ ) {
                    115:                for ( I = J + 1; (I<N) && (M[I][J] == 0); I++ );
                    116:                if ( I == N ) {
                    117:                        for ( L = J, S = 1; L >= K; L-- )
                    118:                                S = S*x-M[L][J];
                    119:                        D *= S;
                    120:                        K = J + 1;
                    121:                } else {
                    122:                        B = J + 1;
                    123:                        for ( L = 0; L < N; L++ ) {
                    124:                                T = M[I][L]; M[I][L] = M[B][L]; M[B][L] = T;
                    125:                        }
                    126:                        for ( L = 0; L < N; L++ ) {
                    127:                                T = M[L][B]; M[L][B] = M[L][I]; M[L][I] = T;
                    128:                                W[L] = M[L][J];
                    129:                        }
                    130:                        for ( L = K, T = red(1/M[B][J]); L < N; L++ )
                    131:                                M[B][L] *= T;
                    132:                        for ( L = K; L < N; L++ )
                    133:                                if ( W[L] && (L != J + 1) )
                    134:                                        for ( B = K, T = W[L]; B < N; B++ )
                    135:                                                M[L][B] -= M[J+1][B]*T;
                    136:                        for ( L = K; L < N; L++ ) {
                    137:                                for ( B = 0, T = 0; B < N ; B++ )
                    138:                                        T += M[L][B] * W[B];
                    139:                                M[L][J + 1] = T;
                    140:                        }
                    141:                }
                    142:        }
                    143:        tstop;
                    144:        return ( D );
                    145: }
                    146:
                    147: def newvmat(N) {
                    148:        M = newmat(N,N);
                    149:        for ( I = 0; I < N; I++ )
                    150:                for ( J = 0; J < N; J++ )
                    151:                        M[I][J] = strtov(rtostr(x)+rtostr(I))^J;
                    152:        return M;
                    153: }
                    154:
                    155: def newssmat(N) {
                    156:        M = newmat(N,N);
                    157:        for ( I = 0; I < N; I++ )
                    158:                for ( J = 0; J < N; J++ )
                    159:                        M[I][J] = strtov(rtostr(x)+rtostr(I)+"_"+rtostr(J));
                    160:        return M;
                    161: }
                    162:
                    163: def newasssmat(N) {
                    164:        N *= 2;
                    165:        M = newmat(N,N);
                    166:        for ( I = 0; I < N; I++ )
                    167:                for ( J = 0; J < I; J++ )
                    168:                        M[I][J] = strtov(rtostr(x)+rtostr(I)+"_"+rtostr(J));
                    169:        for ( I = 0; I < N; I++ )
                    170:                for ( J = I + 1; J < N; J++ )
                    171:                        M[I][J] = -M[J][I];
                    172:        return M;
                    173: }
                    174:
                    175: /* calculation of determinant by minor expansion */
                    176:
                    177: def edet(M) {
                    178:        S = size(M);
                    179:        if ( S[0] == 1 )
                    180:                return M[0][0];
                    181:        else {
                    182:                N = S[0];
                    183:                L = newmat(N-1,N-1);
                    184:                for ( I = 0, R = 0; I < N; I++ ) {
                    185:                        for ( J = 1; J < N; J++ ) {
                    186:                                for ( K = 0; K < I; K++ )
                    187:                                        L[J-1][K] = M[J][K];
                    188:                                for ( K = I+1; K < N; K++ )
                    189:                                        L[J-1][K-1] = M[J][K];
                    190:                        }
                    191:                        R += (-1)^I*edet(L)*M[0][I];
                    192:                }
                    193:                return R;
                    194:        }
                    195: }
                    196:
                    197: /* sylvester's matrix */
                    198:
                    199: def syl(V,P1,P2) {
                    200:        D1 = deg(P1,V); D2 = deg(P2,V);
                    201:        M = newmat(D1+D2,D1+D2);
                    202:        for ( J = 0; J <= D2; J++ )
                    203:                M[0][J] = coef(P2,D2-J,V);
                    204:        for ( I = 1; I < D1; I++ )
                    205:                for ( J = 0; J <= D2; J++ )
                    206:                M[I][I+J] = M[0][J];
                    207:        for ( J = 0; J <= D1; J++ )
                    208:                M[D1][J] = coef(P1,D1-J,V);
                    209:        for ( I = 1; I < D2; I++ )
                    210:                for ( J = 0; J <= D1; J++ )
                    211:                M[D1+I][I+J] = M[D1][J];
                    212:        return M;
                    213: }
                    214:
                    215: /* calculation of resultant by edet() */
                    216:
                    217: def res_minor(V,P1,P2)
                    218: {
                    219:        D1 = deg(P1,V); D2 = deg(P2,V);
                    220:        M = newmat(D1+D2,D1+D2);
                    221:        for ( J = 0; J <= D2; J++ )
                    222:                M[0][J] = coef(P2,D2-J,V);
                    223:        for ( I = 1; I < D1; I++ )
                    224:                for ( J = 0; J <= D2; J++ )
                    225:                M[I][I+J] = M[0][J];
                    226:        for ( J = 0; J <= D1; J++ )
                    227:                M[D1][J] = coef(P1,D1-J,V);
                    228:        for ( I = 1; I < D2; I++ )
                    229:                for ( J = 0; J <= D1; J++ )
                    230:                M[D1+I][I+J] = M[D1][J];
                    231:        return edet(M);
                    232: }
                    233: end$

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