Changeset 2024f6a in git
 Timestamp:
 May 24, 2011, 2:15:59 PM (12 years ago)
 Branches:
 (u'spielwiese', '91fdef05f09f54b8d58d92a472e9c4a43aa4656f')
 Children:
 db33b222f62ceda81505d77c37cc004904d921ba
 Parents:
 fab2cca2c0bc1394ddf0712513e994b18368d0f1
 Location:
 Singular
 Files:

 2 added
 1 edited
Legend:
 Unmodified
 Added
 Removed

Singular/extra.cc
rfab2cca r2024f6a 57 57 #include <kernel/mpr_complex.h> 58 58 #include <kernel/ffields.h> 59 #include <Singular/minpoly.h> 59 60 60 61 #ifdef HAVE_RINGS … … 176 177 static int PyInitialized = 0; 177 178 #endif 179 180 /* expects a SINGULAR square matrix with number entries 181 where currRing is expected to be over some field F_p; 182 returns a long** matrix with the "same", i.e., 183 appropriately mapped entries; 184 leaves singularMatrix unmodified */ 185 unsigned long** singularMatrixToLongMatrix(matrix singularMatrix) 186 { 187 int n = singularMatrix>rows(); 188 assume(n == singularMatrix>cols()); 189 unsigned long **longMatrix = 0; 190 longMatrix = new unsigned long *[n] ; 191 for (int i = 0 ; i < n; i++) 192 longMatrix[i] = new unsigned long [n]; 193 number entry; 194 for (int r = 0; r < n; r++) 195 for (int c = 0; c < n; c++) 196 { 197 entry = p_GetCoeff(MATELEM(singularMatrix, r + 1, c + 1), currRing); 198 int entryAsInt = n_Int(entry, currRing); 199 if (entryAsInt < 0) entryAsInt += currRing>ch; 200 longMatrix[r][c] = (unsigned long)entryAsInt; 201 } 202 return longMatrix; 203 } 204 205 /* expects an array of unsigned longs with valid indices 0..degree; 206 returns the following poly, where x denotes the first ring variable 207 of currRing, and d = degree: 208 polyCoeffs[d] * x^d + polyCoeffs[d1] * x^(d1) + ... + polyCoeffs[0] 209 leaves polyCoeffs unmodified */ 210 poly longCoeffsToSingularPoly(unsigned long *polyCoeffs, const int degree) 211 { 212 poly result = NULL; 213 for (int i = 0; i <= degree; i++) 214 { 215 if ((int)polyCoeffs[i] != 0) 216 { 217 poly term = p_ISet((int)polyCoeffs[i], currRing); 218 if (i > 0) 219 { 220 p_SetExp(term, 1, i, currRing); 221 p_Setm(term, currRing); 222 } 223 result = p_Add_q(result, term, currRing); 224 } 225 } 226 return result; 227 } 178 228 179 229 //void emStart(); … … 2715 2765 else 2716 2766 #endif 2767 /*==== connection to Sebastian Jambor's code ======*/ 2768 /* This code connects Sebastian Jambor's code for 2769 computing the minimal polynomial of an (n x n) matrix 2770 with entries in F_p to SINGULAR. Two conversion methods 2771 are needed; see further up in this file: 2772 (1) conversion of a matrix with long entries to 2773 a SINGULAR matrix with number entries, where 2774 the numbers are coefficients in currRing; 2775 (2) conversion of an array of longs (encoding the 2776 coefficients of the minimal polynomial) to a 2777 SINGULAR poly living in currRing. */ 2778 if (strcmp(sys_cmd, "minpoly") == 0) 2779 { 2780 if ((h == NULL)  (h>Typ() != MATRIX_CMD)  h>next != NULL) 2781 { 2782 Werror("expected exactly one argument: %s", 2783 "a square matrix with number entries"); 2784 return TRUE; 2785 } 2786 else 2787 { 2788 matrix m = (matrix)h>Data(); 2789 int n = m>rows(); 2790 unsigned long p = (unsigned long)currRing>ch; 2791 if (n != m>cols()) 2792 { 2793 Werror("expected exactly one argument: %s", 2794 "a square matrix with number entries"); 2795 return TRUE; 2796 } 2797 unsigned long** ml = singularMatrixToLongMatrix(m); 2798 unsigned long* polyCoeffs = computeMinimalPolynomial(ml, n, p); 2799 poly theMinPoly = longCoeffsToSingularPoly(polyCoeffs, n); 2800 res>rtyp = POLY_CMD; 2801 res>data = (void *)theMinPoly; 2802 for (int i = 0; i < n; i++) delete[] ml[i]; 2803 delete[] ml; 2804 delete[] polyCoeffs; 2805 return FALSE; 2806 } 2807 } 2808 else 2717 2809 /*==================== sdb_flags =================*/ 2718 2810 #ifdef HAVE_SDB
Note: See TracChangeset
for help on using the changeset viewer.