Changeset aa5055 in git for factory/gfops.cc
- Timestamp:
- Dec 17, 2008, 4:06:45 PM (15 years ago)
- Branches:
- (u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
- Children:
- 5d68a6461c92be4d1e47a759b7bafae1be5ffb12
- Parents:
- 35e3a67b3cf2f0f3347c117abbfc926bf620ca3a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/gfops.cc
r35e3a6 raa5055 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: gfops.cc,v 1. 8 2008-08-20 14:44:49Singular Exp $ */2 /* $Id: gfops.cc,v 1.9 2008-12-17 15:06:24 Singular Exp $ */ 3 3 4 4 #include <config.h> … … 59 59 for ( i = 0; i <= degree; i++ ) 60 60 { 61 61 result += CanonicalForm( coeffs[ i ] ) * power( Variable( level ), degree - i ); 62 62 } 63 63 return result; … … 69 69 char buffer[gf_maxbuffer]; 70 70 int q = ipower( p, n ); 71 if ( gf_table == 0 )72 gf_table = new unsigned short[gf_maxtable];73 71 74 72 // do not read the table a second time 75 73 if ( gf_q == q ) 76 74 { 77 return; 78 } 75 return; 76 } 77 78 if ( gf_table == 0 ) 79 gf_table = new unsigned short[gf_maxtable]; 79 80 80 81 #ifdef SINGULAR 81 82 // just copy the table if Singular already read it 83 //printf("init_gf(gf_get_table) q=%d, nfCharQ=%d\n",q,nfCharQ); 82 84 if ( q == nfCharQ ) 83 85 { 84 85 86 87 88 89 90 86 gf_p = p; gf_n = n; 87 gf_q = q; gf_q1 = q - 1; 88 gf_m1 = nfM1; 89 gf_mipo = intVec2CF( nfMinPoly[0], nfMinPoly + 1, 1 ); 90 (void)memcpy( gf_table, nfPlus1Table, gf_q * sizeof( unsigned short ) ); 91 gf_table[gf_q] = 0; 92 return; 91 93 } 92 94 #endif … … 124 126 for ( i = 0; i <= degree; i++ ) 125 127 { 126 127 128 sscanf( bufptr, "%d", mipo + i ); 129 bufptr = (char *)strchr( bufptr, ' ' ) + 1; 128 130 } 129 131 … … 138 140 while ( i < gf_q ) 139 141 { 140 141 142 143 144 142 success = fgets( buffer, gf_maxbuffer, inputfile ); 143 STICKYASSERT( strlen( buffer ) - 1 == (size_t)digs * 30, "illegal table" ); 144 bufptr = buffer; 145 k = 0; 146 while ( i < gf_q && k < 30 ) 145 147 { 146 147 148 gf_table[i] = convertback62( bufptr, digs ); 149 bufptr += digs; 148 150 if ( gf_table[i] == gf_q ) 149 150 151 152 153 154 151 if ( i == gf_q1 ) 152 gf_m1 = 0; 153 else 154 gf_m1 = i; 155 i++; k++; 156 } 155 157 } 156 158 gf_table[0] = gf_table[gf_q1]; … … 166 168 while ( i < gf_primes_len && gf_primes[i] != p ) i++; 167 169 if ( i == gf_primes_len ) 168 170 return false; 169 171 else 170 172 { 171 172 173 173 i = n; 174 int a = 1; 175 while ( a < gf_maxtable && i > 0 ) 174 176 { 175 176 177 178 179 180 181 177 a *= p; 178 i--; 179 } 180 if ( i > 0 || a > gf_maxtable ) 181 return false; 182 else 183 return true; 182 184 } 183 185 } … … 195 197 { 196 198 if ( gf_iszero( a ) ) 197 199 return 0; 198 200 else 199 201 { 200 201 202 203 204 205 202 // starting from z^0=1, step through the table 203 // counting the steps until we hit z^a or z^0 204 // again. since we are working in char(p), the 205 // latter is guaranteed to be fulfilled. 206 int i = 0, ff = 1; 207 do 206 208 { 207 208 209 210 211 212 209 if ( i == a ) 210 return ff; 211 ff++; 212 i = gf_table[i]; 213 } while ( i != 0 ); 214 return -1; 213 215 } 214 216 } … … 218 220 { 219 221 if ( gf_iszero( a ) ) 220 222 return true; 221 223 else 222 224 { 223 224 225 } 226 } 225 // z^a in GF(p) iff (z^a)^p-1=1 226 return gf_isone( gf_power( a, gf_p - 1 ) ); 227 } 228 }
Note: See TracChangeset
for help on using the changeset viewer.