Changeset d2da42 in git


Ignore:
Timestamp:
Dec 6, 2018, 3:31:44 PM (5 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
757eac36df59510348bf034d6ebdc03389e843f8
Parents:
7d0c5307af92569d0d63f695cef1d0431f7d1b9f
Message:
add: mp_DetMu: determinant via mu algorithm
Location:
libpolys/polys
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libpolys/polys/matpol.cc

    r7d0c530 rd2da42  
    241241            poly *cij=&(MATELEM(c,i,j));
    242242            poly s = pp_Mult_qq(aik /*MATELEM(a,i,k)*/, bkj/*MATELEM(b,k,j)*/, R);
    243             if (/*MATELEM(c,i,j)*/ (*cij)==NULL) (*cij)=s;
    244             else (*cij) = p_Add_q((*cij) /*MATELEM(c,i,j)*/ ,s, R);
     243            (*cij)/*MATELEM(c,i,j)*/ = p_Add_q((*cij) /*MATELEM(c,i,j)*/ ,s, R);
    245244          }
    246245        }
     
    20272026}
    20282027
     2028/*
     2029*   mu-Algorithmus:
     2030*/
     2031
     2032//  mu-Matrix
     2033static void mu(matrix A, matrix &X, const ring R)
     2034{
     2035  int n=MATROWS(A);
     2036  assume(MATCOLS(A)==n);
     2037    /*  Die Funktion erstellt die Matrix mu
     2038    *
     2039    *   Input:
     2040    *   int n: Dimension der Matrix
     2041    *   int A: Matrix der Größe n*n
     2042    *   int X: Speicherplatz fÃŒr Output
     2043    *
     2044    *   In der Matrix X speichert man die Matrix mu
     2045    */
     2046
     2047    // X als n*n Null-Matrix initalisieren
     2048    X=mpNew(n,n);
     2049
     2050    //  DiagonaleintrÀge von X berrechnen
     2051    poly sum = NULL;
     2052    for (int i = n-1; i >= 0; i--)
     2053    {
     2054        MATELEM0(X,i,i) = p_Copy(sum,R);
     2055        sum=p_Sub(sum,p_Copy(MATELEM0(A,i,i),R),R);
     2056    }
     2057
     2058    //  EintrÀge aus dem oberen Dreieck von A nach X ÃŒbertragen
     2059    for (int i = 0; i < n; i++)
     2060    {
     2061        for (int j = i+1; j < n; j++)
     2062        {
     2063            MATELEM0(X,i,j)=p_Copy(MATELEM0(A,i,j),R);
     2064        }
     2065    }
     2066}
     2067
     2068// Funktion muDet
     2069poly mp_DetMu(matrix A, const ring R)
     2070{
     2071  int n=MATROWS(A);
     2072  assume(MATCOLS(A)==n);
     2073    /*
     2074    *   Intput:
     2075    *   int n: Dimension der Matrix
     2076    *   int A: n*n Matrix
     2077    *
     2078    *   Berechnet n-1 mal: X = mu(X)*A
     2079    *
     2080    *   Output: det(A)
     2081    */
     2082
     2083    //speichere A ab:
     2084    matrix B=mp_Copy(A,R);
     2085    A=mp_Copy(A,R);
     2086
     2087    // berechen X = mu(X)*A
     2088    matrix X;
     2089    for (int i = 0; i < n-1; i++)
     2090    {
     2091        mu(A,X,R);
     2092        id_Delete((ideal*)&A,R);
     2093        A=mp_Mult(X,B,R);
     2094        id_Delete((ideal*)&X,R);
     2095    }
     2096
     2097    // berrechne det(A)
     2098    poly res;
     2099    if (n%2 == 0)
     2100    {
     2101        res=p_Neg(MATELEM0(A,0,0),R);
     2102    }
     2103    else
     2104    {
     2105        res=MATELEM0(A,0,0);
     2106    }
     2107    MATELEM0(A,0,0)=NULL;
     2108    id_Delete((ideal*)&A,R);
     2109    return res;
     2110}
     2111
  • libpolys/polys/matpol.h

    r7d0c530 rd2da42  
    2626  #define MATROWS(i) ((i)->nrows)
    2727  #define MATCOLS(i) ((i)->ncols)
     28  /// 1-based access to matrix
    2829  #define MATELEM(mat,i,j) ((mat)->m)[MATCOLS((mat)) * ((i)-1) + (j)-1]
     30  /// 0-based access to matrix
     31  #define MATELEM0(mat,i,j) ((mat)->m)[MATCOLS((mat)) * (i) + (j)]
    2932};
    3033
     
    5760
    5861poly mp_DetBareiss (matrix a, const ring r);
     62poly mp_DetMu(matrix A, const ring R);
     63
    5964
    6065//matrix mp_Homogen(matrix a, int v, const ring r);
Note: See TracChangeset for help on using the changeset viewer.