Changeset bd7a8b in git


Ignore:
Timestamp:
Apr 30, 1997, 2:34:43 PM (27 years ago)
Author:
Jens Schmidt <schmidt@…>
Branches:
(u'spielwiese', '82fc009ea2b0098c1a4896c841bb70860976bdfc')
Children:
25c3c2b4e326c16a14b5b6376e33bc99ec4b299d
Parents:
699a1847b77bff0ee5e4ed7bdd8d0188f12c1973
Message:
o #define MAXTABLE replaced by const gf_maxtable
o maximal length of a line replaced by const gf_maxbuffer
o gf_get_table(): uses Singulars tables if they are present
    uses stdio instead of streamio to read the tables
o gf_isff(): rewritten
o intVec2GF(): new function


git-svn-id: file:///usr/local/Singular/svn/trunk@210 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • factory/gfops.cc

    r699a18 rbd7a8b  
    11// emacs edit mode for this file is -*- C++ -*-
    2 // $Id: gfops.cc,v 1.0 1996-05-17 10:59:46 stobbe Exp $
     2// $Id: gfops.cc,v 1.1 1997-04-30 12:34:43 schmidt Exp $
    33
    44/*
    55$Log: not supported by cvs2svn $
     6Revision 1.0  1996/05/17 10:59:46  stobbe
     7Initial revision
     8
    69*/
    710
    8 #include <iostream.h>
    9 #include <fstream.h>
    10 #include <strstream.h>
     11#include <config.h>
     12
     13#include <stdio.h>
     14#include <string.h>
    1115
    1216#include "assert.h"
     17
    1318#include "cf_defs.h"
    1419#include "gfops.h"
     
    1621#include "cf_util.h"
    1722#include "canonicalform.h"
    18 
    19 
    20 #define MAXTABLE 32767
    21 
    22 int gf_q = 0;
    23 int gf_p = 0;
    24 int gf_n = 0;
    25 int gf_q1 = 0;
    26 int gf_m1 = 0;
    27 char gf_name = 'Z';
    28 
    29 unsigned short * gf_table = 0;
     23#include "variable.h"
     24#ifdef SINGULAR
     25#include "singext.h"
     26#endif
     27
     28
     29const int gf_maxtable = 32767;
     30const int gf_maxbuffer = 200;
    3031
    3132const int gf_primes_len = 42;
    32 
    3333static unsigned short gf_primes [] =
    3434{
     
    4141};
    4242
     43int gf_q = 0;
     44int gf_p = 0;
     45int gf_n = 0;
     46int gf_q1 = 0;
     47int gf_m1 = 0;
     48char gf_name = 'Z';
     49
     50unsigned short * gf_table = 0;
     51
    4352CanonicalForm gf_mipo = 0;
    4453
    45 static void gf_get_table ( int p, int n )
    46 {
     54static CanonicalForm
     55intVec2CF ( int degree, int * coeffs, int level )
     56{
     57    int i;
     58    CanonicalForm result;
     59    for ( i = 0; i <= degree; i++ ) {
     60        result += CanonicalForm( coeffs[ i ] ) * power( Variable( level ), degree - i );
     61    }
     62    return result;
     63}
     64
     65static void
     66gf_get_table ( int p, int n )
     67{
     68    char buffer[gf_maxbuffer];
     69    int q = ipower( p, n );
    4770    if ( gf_table == 0 )
    48         gf_table = new unsigned short[MAXTABLE];
    49     ostrstream fname;
    50     fname << "gftables/gftable." << p << "." << n << '\0';
    51     char * fn = fname.str();
    52     ifstream inputfile( fn, ios::in );
     71        gf_table = new unsigned short[gf_maxtable];
     72
     73    // do not read the table a second time
     74    if ( gf_q == q ) {
     75        return;
     76    }
     77
     78#ifdef SINGULAR
     79    // just copy the table if Singular already read it
     80    if ( q == nfCharQ ) {
     81        gf_p = p; gf_n = n;
     82        gf_q = q; gf_q1 = q - 1;
     83        gf_m1 = nfM1;
     84        gf_mipo = intVec2CF( nfMinPoly[0], nfMinPoly + 1, 1 );
     85        (void)memcpy( gf_table, nfPlus1Table, gf_q * sizeof( unsigned short ) );
     86        gf_table[gf_q] = 0;
     87        return;
     88    }
     89#endif
     90
     91    // try to open file
     92#ifndef SINGULAR
     93    sprintf( buffer, GFTABLEDIR "/gftable.%d.%d", p, n );
     94#else
     95    sprintf( buffer, GFTABLEDIR "/%d", q );
     96#endif
     97    FILE * inputfile = fopen( buffer, "r" );
    5398    STICKYASSERT( inputfile, "can not open GF(q) table" );
    54     delete [] fn;
    55     int i, k, pp, nn, digs;
    56     gf_q = ipower( p, n );
    57     gf_p = p;
    58     gf_q1 = gf_q-1;
    59     digs = gf_tab_numdigits62( gf_q );
    60     char * buffer = new char[100];
     99
     100    // read ID
    61101    char * bufptr;
    62     inputfile.getline( buffer, 99, '\n' );
    63     STICKYASSERT( strcmp( buffer, "@@ factory GF(q) table @@" ) == 0, "illegal table" );
    64     inputfile >> pp;
    65     inputfile >> nn;
    66     STICKYASSERT( p == pp && n == nn, "illegal table" );
    67     inputfile >> gf_mipo;
    68     inputfile.getline( buffer, 99, '\n' );
     102    char * success;
     103    success = fgets( buffer, gf_maxbuffer, inputfile );
     104    STICKYASSERT( success, "illegal table (reading ID)" );
     105    STICKYASSERT( strcmp( buffer, "@@ factory GF(q) table @@\n" ) == 0, "illegal table" );
     106    // read p and n from file
     107    int pFile, nFile;
     108    success = fgets( buffer, gf_maxbuffer, inputfile );
     109    STICKYASSERT( success, "illegal table (reading p and n)" );
     110    sscanf( buffer, "%d %d", &pFile, &nFile );
     111    STICKYASSERT( p == pFile && n == nFile, "illegal table" );
     112    // skip (sic!) factory-representation of mipo
     113    // and terminating "; "
     114    bufptr = strchr( buffer, ';' ) + 2;
     115    // read simple representation of mipo
     116    int i, degree;
     117    sscanf( bufptr, "%d", &degree );
     118    bufptr = strchr( bufptr, ' ' ) + 1;
     119    int * mipo = new int[degree + 1];
     120    for ( i = 0; i <= degree; i++ ) {
     121        sscanf( bufptr, "%d", mipo + i );
     122        bufptr = strchr( bufptr, ' ' ) + 1;
     123    }
     124
     125    gf_p = p; gf_n = n;
     126    gf_q = q; gf_q1 = q-1;
     127    gf_mipo = intVec2CF( degree, mipo, 1 );
     128    delete [] mipo;
     129
     130    // now for the table
     131    int k, digs = gf_tab_numdigits62( gf_q );
    69132    i = 1;
    70133    while ( i < gf_q ) {
    71         inputfile.getline( buffer, 99, '\n' );
    72         STICKYASSERT( strlen( buffer ) == (size_t)digs * 30, "illegal table" );
     134        success = fgets( buffer, gf_maxbuffer, inputfile );
     135        STICKYASSERT( strlen( buffer ) - 1 == (size_t)digs * 30, "illegal table" );
    73136        bufptr = buffer;
    74137        k = 0;
     
    85148    }
    86149    gf_table[0] = gf_table[gf_q1];
    87 }
    88 
    89 static bool gf_valid_combination ( int p, int n )
     150    gf_table[gf_q] = 0;
     151
     152    (void)fclose( inputfile );
     153}
     154
     155static bool
     156gf_valid_combination ( int p, int n )
    90157{
    91158    int i = 0;
     
    94161        return false;
    95162    else {
    96         int m = MAXTABLE;
    97163        i = n;
    98164        int a = 1;
    99         while ( a < m && i > 0 ) {
     165        while ( a < gf_maxtable && i > 0 ) {
    100166            a *= p;
    101167            i--;
    102168        }
    103         if ( i > 0 || a > m )
     169        if ( i > 0 || a > gf_maxtable )
    104170            return false;
    105171        else
     
    107173    }
    108174}
    109    
    110 void gf_setcharacteristic ( int p, int n, char name )
     175
     176void
     177gf_setcharacteristic ( int p, int n, char name )
    111178{
    112179    ASSERT( gf_valid_combination( p, n ), "illegal immediate GF(q)" );
     
    115182}
    116183
    117 int gf_gf2ff ( int a )
     184int
     185gf_gf2ff ( int a )
    118186{
    119187    if ( gf_iszero( a ) )
    120188        return 0;
    121189    else {
     190        // starting from z^0=1, step through the table
     191        // counting the steps until we hit z^a or z^0
     192        // again.  since we are working in char(p), the
     193        // latter is guaranteed to be fulfilled.
    122194        int i = 0, ff = 1;
    123195        do {
     
    131203}
    132204
    133 bool gf_isff ( int a )
     205bool
     206gf_isff ( int a )
    134207{
    135208    if ( gf_iszero( a ) )
    136209        return true;
    137210    else {
    138         int i = 0;
    139         do {
    140             if ( i == a )
    141                 return true;
    142             i = gf_table[i];
    143         } while ( i != 0 );
    144         return false;
    145     }
    146 }
     211        // z^a in GF(p) iff (z^a)^p-1=1
     212        return gf_isone( gf_power( a, gf_p - 1 ) );
     213    }
     214}
Note: See TracChangeset for help on using the changeset viewer.