- Timestamp:
- Dec 17, 2018, 7:56:25 AM (5 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- c7231560b85e2e1683beb9629db0560ee8ca4255
- Parents:
- 04d263ab0fcd4cc5a8215c12fdf4423b782d3283ee3e7cd650e2cf6d6e770d6b57b1681594c7cda7
- Location:
- libpolys/polys
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
libpolys/polys/matpol.cc
r04d263 r178bd3 23 23 #include "matpol.h" 24 24 #include "prCopy.h" 25 #include "clapsing.h" 25 26 26 27 #include "sparsmat.h" … … 2029 2030 2030 2031 // mu-Matrix 2031 static void mu(matrix A, matrix &X, const ring R)2032 static matrix mu(matrix A, const ring R) 2032 2033 { 2033 2034 int n=MATROWS(A); … … 2044 2045 2045 2046 // X als n*n Null-Matrix initalisieren 2046 X=mpNew(n,n);2047 matrix X=mpNew(n,n); 2047 2048 2048 2049 // Diagonaleintraege von X berrechnen … … 2053 2054 sum=p_Sub(sum,p_Copy(MATELEM0(A,i,i),R),R); 2054 2055 } 2056 p_Delete(&sum,R); 2055 2057 2056 2058 // Eintraege aus dem oberen Dreieck von A nach X uebertragen 2057 for (int i = 0; i < n; i++)2059 for (int i = n-1; i >=0; i--) 2058 2060 { 2059 2061 for (int j = i+1; j < n; j++) … … 2062 2064 } 2063 2065 } 2066 return X; 2064 2067 } 2065 2068 … … 2080 2083 2081 2084 //speichere A ab: 2082 matrix B=mp_Copy(A,R); 2083 A=mp_Copy(A,R); 2085 matrix workA=mp_Copy(A,R); 2084 2086 2085 2087 // berechen X = mu(X)*A 2086 2088 matrix X; 2087 for (int i = 0; i < n-1; i++)2088 { 2089 mu(A,X,R);2090 id_Delete((ideal*)& A,R);2091 A=mp_Mult(X,B,R);2089 for (int i = n-1; i >0; i--) 2090 { 2091 X=mu(workA,R); 2092 id_Delete((ideal*)&workA,R); 2093 workA=mp_Mult(X,A,R); 2092 2094 id_Delete((ideal*)&X,R); 2093 2095 } … … 2097 2099 if (n%2 == 0) 2098 2100 { 2099 res=p_Neg(MATELEM0( A,0,0),R);2101 res=p_Neg(MATELEM0(workA,0,0),R); 2100 2102 } 2101 2103 else 2102 2104 { 2103 res=MATELEM0( A,0,0);2104 } 2105 MATELEM0( A,0,0)=NULL;2106 id_Delete((ideal*)& A,R);2105 res=MATELEM0(workA,0,0); 2106 } 2107 MATELEM0(workA,0,0)=NULL; 2108 id_Delete((ideal*)&workA,R); 2107 2109 return res; 2108 2110 } 2109 2111 2112 DetVariant mp_GetAlgorithmDet(matrix m, const ring r) 2113 { 2114 if (MATROWS(m)+2*r->N>20+5*rField_is_Zp(r)) return DetMu; 2115 if (MATROWS(m)<10+5*rField_is_Zp(r)) return DetSBareiss; 2116 BOOLEAN isConst=TRUE; 2117 int s=0; 2118 for(int i=MATCOLS(m)*MATROWS(m)-1;i>=0;i--) 2119 { 2120 poly p=m->m[i]; 2121 if (p!=NULL) 2122 { 2123 if(!p_IsConstant(p,r)) isConst=FALSE; 2124 s++; 2125 } 2126 } 2127 if (isConst && rField_is_Q(r)) return DetFactory; 2128 if (s*2<MATCOLS(m)*MATROWS(m)) // few entries 2129 return DetSBareiss; 2130 return DetMu; 2131 } 2132 DetVariant mp_GetAlgorithmDet(const char *s) 2133 { 2134 if (strcmp(s,"Bareiss")==0) return DetBareiss; 2135 if (strcmp(s,"SBareiss")==0) return DetSBareiss; 2136 if (strcmp(s,"Mu")==0) return DetMu; 2137 if (strcmp(s,"Factory")==0) return DetFactory; 2138 WarnS("unknown method for det"); 2139 return DetDefault; 2140 } 2141 2142 2143 poly mp_Det(matrix a, const ring r, DetVariant d/*=DetDefault*/) 2144 { 2145 if ((MATCOLS(a)==0) 2146 && (MATROWS(a)==0)) 2147 return p_One(r); 2148 if (d==DetDefault) d=mp_GetAlgorithmDet(a,r); 2149 switch (d) 2150 { 2151 case DetBareiss: return mp_DetBareiss(a,r); 2152 case DetMu: return mp_DetMu(a,r); 2153 case DetFactory: return singclap_det(a,r); 2154 case DetSBareiss: 2155 { 2156 ideal I=id_Matrix2Module(mp_Copy(a, r),r); 2157 poly p=sm_CallDet(I, r); 2158 id_Delete(&I, r); 2159 return p; 2160 } 2161 default: 2162 WerrorS("unknown algorith for det"); 2163 } 2164 } 2165 2166 poly sm_Det(ideal a, const ring r, DetVariant d/*=DetDefault*/) 2167 { 2168 if ((MATCOLS(a)==0) 2169 && (MATROWS(a)==0)) 2170 return p_One(r); 2171 if (d==DetDefault) d=mp_GetAlgorithmDet((matrix)a,r); 2172 if (d==DetSBareiss) return sm_CallDet(a,r); 2173 matrix m=id_Module2Matrix(id_Copy(a,r),r); 2174 poly p=mp_Det(m,r,d); 2175 id_Delete((ideal *)&m,r); 2176 return p; 2177 } -
libpolys/polys/matpol.h
r04d263 r178bd3 32 32 }; 33 33 34 enum DetVariant 35 { 36 DetDefault=0, 37 DetBareiss, 38 DetSBareiss, 39 DetMu, 40 DetFactory 41 }; 42 34 43 typedef ip_smatrix * matrix; 35 44 … … 59 68 // BOOLEAN mpKoszul(leftv res,leftv b/*in*/, leftv c/*ip*/, leftv id=NULL); 60 69 70 poly mp_Det(matrix a, const ring r, DetVariant d=DetDefault); 61 71 poly mp_DetBareiss (matrix a, const ring r); 62 72 poly mp_DetMu(matrix A, const ring R); … … 106 116 BOOLEAN sm_Equal(ideal a, ideal b, const ring R); 107 117 ideal sm_Tensor(ideal A, ideal B, const ring r); 118 poly sm_Det(ideal I, const ring, DetVariant d=DetDefault); 119 DetVariant mp_GetAlgorithmDet(matrix m, const ring r); 120 DetVariant mp_GetAlgorithmDet(const char *s); 108 121 109 122 #define SMATELEM(A,i,j,R) p_Vec2Poly(A->m[j],i+1,R) -
libpolys/polys/shiftop.cc
ree3e7cd r178bd3 368 368 p_GetExpV(m,e,ri); 369 369 370 if (p_mLastVblock(m, e, ri) + sh > ri->N/lV) 371 { 372 Werror("letterplace degree bound is %d, but at least %d is needed for this shift", ri->N/lV, p_mLastVblock(m, e, ri) + sh); 373 } 370 374 for (int i = ri->N - sh*lV; i > 0; i--) 371 375 { … … 506 510 PrintLn(); WriteLPExpV(m2ExpV, ri); 507 511 #endif 508 if (m1Length + m2Length > ri->N) 509 { 510 WarnS("letterplace degree bound too low for this multiplication"); 511 } 512 for (int i = 1 + m1Length; i < 1 + m1Length + m2Length; ++i) 512 int last = m1Length + m2Length; 513 if (last > ri->N) 514 { 515 Werror("letterplace degree bound is %d, but at least %d is needed for this multiplication", ri->N/ri->isLPring, last/ri->isLPring); 516 last = ri->N; 517 } 518 for (int i = 1 + m1Length; i < 1 + last; ++i) 513 519 { 514 520 assume(m2ExpV[i - m1Length] <= 1); … … 531 537 PrintLn(); WriteLPExpV(m2ExpV, ri); 532 538 #endif 533 if (m1Length + m2Length > ri->N) 534 { 535 WarnS("letterplace degree bound too low for this multiplication"); 539 int last = m1Length + m2Length; 540 if (last > ri->N) 541 { 542 Werror("letterplace degree bound is %d, but at least %d is needed for this multiplication", ri->N/ri->isLPring, last/ri->isLPring); 543 last = ri->N; 536 544 } 537 545 538 546 // shift m1 by m2Length 539 for (int i = m2Length + m1Length; i >= 1 + m2Length; --i)547 for (int i = last; i >= 1 + m2Length; --i) 540 548 { 541 549 m1ExpV[i] = m1ExpV[i - m2Length]; -
libpolys/polys/sparsmat.cc
r04d263 r178bd3 295 295 } 296 296 297 /*2298 * Bareiss or Chinese remainder ?299 * I is dXd300 * sw = TRUE -> I Matrix301 * FALSE -> I Module302 * return True -> change Type303 * FALSE -> same Type304 */305 BOOLEAN sm_CheckDet(ideal I, int d, BOOLEAN sw, const ring r)306 {307 int s,t,i;308 poly p;309 310 if (d>100)311 return TRUE;312 if (!rField_is_Q(r))313 return TRUE;314 s = t = 0;315 // now: field is Q, n<=100316 for(i=IDELEMS(I)-1;i>=0;i--)317 {318 p=I->m[i];319 if (p!=NULL)320 {321 if(!p_IsConstant(p,r))322 return TRUE;323 s++;324 t+=n_Size(pGetCoeff(p),r->cf);325 }326 }327 s*=15;328 if (t>s)329 return FALSE;// few large constanst entries330 else331 return TRUE; //many small entries332 }333 334 297 /* ----------------- basics (used from 'C') ------------------ */ 335 298 /*2 -
libpolys/polys/sparsmat.h
r04d263 r178bd3 32 32 void sm_KillModifiedRing(ring r); 33 33 long sm_ExpBound(ideal, int, int, int, const ring); 34 BOOLEAN sm_CheckDet(ideal, int, BOOLEAN, const ring);35 34 #endif
Note: See TracChangeset
for help on using the changeset viewer.