Changeset 077e9c in git


Ignore:
Timestamp:
Apr 18, 1997, 5:49:41 PM (26 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
Children:
87e1dea02069a0384ad19ed8f56dbff5d465e597
Parents:
5ec6957bea2ca39b00d7f174d456bba93f41ea83
Message:
* hannes: fixed length bug in ffields.cc
          added string(minpoly), print(minpoly),.. for GF(q)


git-svn-id: file:///usr/local/Singular/svn/trunk@178 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
Singular
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • Singular/ffields.cc

    r5ec695 r077e9c  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: ffields.cc,v 1.7 1997-04-16 18:38:06 Singular Exp $ */
     4/* $Id: ffields.cc,v 1.8 1997-04-18 15:49:40 Singular Exp $ */
    55/*
    66* ABSTRACT: finite fields with a none-prime number of elements (via tables)
     
    2626    4,  8, 16, 32, 64, 128, 256, 512,1024,2048,4096,8192,16384,
    2727/*2^2 2^3 2^4 2^5 2^6  2^7  2^8  2^9 2^10 2^11 2^12 2^13  2^14*/
    28     9, 27, 81,243,729,2187,6561,19683,
     28    9, 27, 81,243,729,2187, 6561,19683,
    2929/*3^2 3^3 3^4 3^5 3^6  3^7  3^8   3^9*/
    3030   25,125,625,3125,15625,
     
    3232   49,343,2401,16807,
    3333/*7^2 7^3  7^4 7^5*/
    34    121,1331,14641,
     34   121,1331, 14641,
    3535/*11^2 11^3  11^4*/
    36   169, 2197,28561,
     36  169, 2197, 28561,
    3737/*13^2 13^3  13^4*/
    3838  289, 4913,
     
    117117*/
    118118
     119#ifdef LDEBUG
     120/*2
     121* debugging: is a a valid representation of a number ?
     122*/
     123BOOLEAN nfDBTest (number a, char *f, int l)
     124{
     125  if (((int)a<0) || ((int)a>nfCharQ))
     126  {
     127    Print("wrong %d in %s:%d\n",(int)a,f,l);
     128    return FALSE;
     129  }
     130  int i=0;
     131  do
     132  {
     133    if (nfPlus1Table[i]>nfCharQ)
     134    {
     135      Print("wrong table %d=%d in %s:%d\n",i,nfPlus1Table[i],f,l);
     136      return FALSE;
     137    }
     138    i++;
     139  } while (i<nfCharQ);
     140  return TRUE;
     141}
     142#define nfTest(N) nfDBTest(N,__FILE__,__LINE__)
     143#endif
     144           
    119145/*2
    120146* k >= 0 ?
     
    122148BOOLEAN nfGreaterZero (number k)
    123149{
     150#ifdef LDEBUG
     151  nfTest(k);
     152#endif
    124153  return !nfIsZero(k);
    125154}
     
    130159number nfMult (number a,number b)
    131160{
     161#ifdef LDEBUG
     162  nfTest(a);
     163  nfTest(b);
     164#endif
    132165  if (((int)a == nfCharQ) || ((int)b == nfCharQ))
    133166    return (number)nfCharQ;
     
    135168  int i=(int)a+(int)b;
    136169  if (i>=nfCharQ1) i-=nfCharQ1;
     170#ifdef LDEBUG
     171  nfTest((number)i);
     172#endif
    137173  return (number)i;
    138174}
     
    152188    i--;
    153189  }
     190#ifdef LDEBUG
     191  nfTest((number)c);
     192#endif
    154193  return (number)c;
    155194}
     
    168207int nfParDeg(number n)
    169208{
     209#ifdef LDEBUG
     210  nfTest(n);
     211#endif
    170212  if(nfCharQ == (int)n) return -1;
    171213  return (int)n;
     
    183225* copy a number
    184226*/
    185 number nfCopy (number  k1)
    186 {
    187   return k1;
     227number nfCopy (number  k)
     228{
     229#ifdef LDEBUG
     230  nfTest(k);
     231#endif
     232  return k;
    188233}
    189234
     
    195240/*4 z^a+z^b=z^b*(z^(a-b)+1), if a>=b; *
    196241*          =z^a*(z^(b-a)+1)  if a<b  */
     242#ifdef LDEBUG
     243  nfTest(a);
     244  nfTest(b);
     245#endif
    197246  int zb,zab,r;
    198247  if ((int)a >= (int)b)
     
    206255    zab = (int)b-(int)a;
    207256  }
     257#ifdef LDEBUG
     258  nfTest((number)zab);
     259#endif
    208260  if (nfPlus1Table[zab]==nfCharQ) r=nfCharQ; /*if z^(a-b)+1 =0*/
    209261  else
     
    212264    if(r>=nfCharQ1) r-=nfCharQ1;
    213265  }
     266#ifdef LDEBUG
     267  nfTest((number)r);
     268#endif
    214269  return (number)r;
    215270}
     
    229284BOOLEAN nfIsZero (number  a)
    230285{
     286#ifdef LDEBUG
     287  nfTest(a);
     288#endif
    231289  return nfCharQ == (int)a;
    232290}
     
    237295BOOLEAN nfIsOne (number a)
    238296{
     297#ifdef LDEBUG
     298  nfTest(a);
     299#endif
    239300  return 0 == (int)a;
    240301}
     
    245306BOOLEAN nfIsMOne (number a)
    246307{
     308#ifdef LDEBUG
     309  nfTest(a);
     310#endif
    247311  return nfM1 == (int)a;
    248312}
     
    253317number nfDiv (number a,number b)
    254318{
     319#ifdef LDEBUG
     320  nfTest(b);
     321#endif
    255322  if ((int)b==nfCharQ)
    256323  {
     
    258325    return (number)nfCharQ;
    259326  }
     327#ifdef LDEBUG
     328  nfTest(a);
     329#endif
    260330  if ((int)a==nfCharQ)
    261331    return (number)nfCharQ;
     
    264334  if (s < 0)
    265335    s += nfCharQ1;
     336#ifdef LDEBUG
     337  nfTest((number)s);
     338#endif
    266339  return (number)s;
    267340}
     
    272345number  nfInvers (number c)
    273346{
     347#ifdef LDEBUG
     348  nfTest(c);
     349#endif
    274350  if ((int)c==nfCharQ)
    275351  {
     
    277353    return (number)nfCharQ;
    278354  }
     355#ifdef LDEBUG
     356  nfTest(((number)(nfCharQ1-(int)c)));
     357#endif
    279358  return (number)(nfCharQ1-(int)c);
    280359}
     
    286365{
    287366/*4 -z^c=z^c*(-1)=z^c*nfM1*/
     367#ifdef LDEBUG
     368  nfTest(c);
     369#endif
    288370  int i=(int)c+nfM1;
    289371  if (i>=nfCharQ1) i-=nfCharQ1;
     372#ifdef LDEBUG
     373  nfTest((number)i);
     374#endif
    290375  return (number)i;
    291376}
     
    296381BOOLEAN nfGreater (number a,number b)
    297382{
     383#ifdef LDEBUG
     384  nfTest(a);
     385  nfTest(b);
     386#endif
    298387  return (int)a != (int)b;
    299388}
     
    304393BOOLEAN nfEqual (number a,number b)
    305394{
     395#ifdef LDEBUG
     396  nfTest(a);
     397  nfTest(b);
     398#endif
    306399  return (int)a == (int)b;
    307400}
     
    312405void nfWrite (number &a)
    313406{
     407#ifdef LDEBUG
     408  nfTest(a);
     409#endif
    314410  if ((int)a==nfCharQ)  StringAppendS("0");
    315411  else if ((int)a==0)   StringAppendS("1");
     
    330426char * nfName(number a)
    331427{
     428#ifdef LDEBUG
     429  nfTest(a);
     430#endif
    332431  char *s;
    333432  if (((int)a==nfCharQ) || ((int)a==0)) return NULL;
     
    348447void nfPower (number a, int i, number * result)
    349448{
     449#ifdef LDEBUG
     450  nfTest(a);
     451#endif
    350452  if (i==0)
    351453  {
    352454    //*result=nfInit(1);
    353     *(int *)result = 0;
     455    *result = (number)0;
    354456  }
    355457  else if (i==1)
     
    363465    *result = nfMult(a,*result);
    364466  }
     467#ifdef LDEBUG
     468  nfTest(*result);
     469#endif
    365470}
    366471
     
    418523    *a=nfMult(*a,z);
    419524  }
     525#ifdef LDEBUG
     526  nfTest(*a);
     527#endif
    420528  return s;
    421529}
     
    442550}
    443551
    444 static int convertback62 ( char * p, int n )
     552static int convertback62 ( char * p, int n , int q)
    445553{
    446554    int r = 0;
     
    451559#endif
    452560
    453 int nfMinPoly[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
     561int nfMinPoly[16];
    454562
    455563void nfShowMipo()
     
    461569    j++;
    462570    if (nfMinPoly[j]!=0)
    463       Print("%d*%s^%d",nfMinPoly[j],nfParameter,i);
     571      StringAppend("%d*%s^%d",nfMinPoly[j],nfParameter,i);
    464572    i--;
    465573    if(i<0) break;
    466574    if (nfMinPoly[j]!=0)
    467       PrintS("+");
    468   } 
     575      StringAppendS("+");
     576  }
    469577}
    470578
     
    512620    if (c>1) nfCharQ = c;
    513621    else     nfCharQ = -c;
    514     char buf[80];
     622    char buf[100];
    515623    sprintf(buf,"gftables/%d",nfCharQ);
    516624    FILE * fp = feFopen(buf,"r",NULL,FALSE);
     
    552660      {
    553661        nfPlus1Table[i] = convertback62( bufptr, digs );
     662        if(nfPlus1Table[i]>nfCharQ)
     663        {
     664          Print("wrong entry %d: %d(%c%c%c)\n",i,nfPlus1Table[i],bufptr[0],bufptr[1],bufptr[2]);
     665        } 
    554666        bufptr += digs;
     667        if (nfPlus1Table[i]==nfCharQ)
     668        {
     669          if(i==nfCharQ1)
     670          {
     671            nfM1=0;
     672          }
     673          else
     674          {
     675            nfM1=i;
     676          }
     677        }
    555678        i++; k++;
    556679      }
    557       nfPlus1Table[0]=nfPlus1Table[nfCharQ1];
    558680    }
     681    nfPlus1Table[0]=nfPlus1Table[nfCharQ1];
    559682  }
    560683  else
    561684    nfCharQ=0;
     685#ifdef LDEBUG
     686  nfTest((number)0); 
     687#endif
    562688  return;
    563689err:
     
    565691}
    566692
    567 #ifdef LDEBUG
    568 /*2
    569 * debugging: is a a valid representation of a number ?
    570 */
    571 BOOLEAN nfDBTest (number a, char *f, int l)
    572 {
    573   if (((int)a<0) || ((int)a>nfCharQ))
    574   {
    575     return FALSE;
    576   }
    577   return TRUE;
    578 }
    579 #endif
    580 
    581693/*2
    582694* map Z/p -> GF(p,n)
  • Singular/ring.cc

    r5ec695 r077e9c  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: ring.cc,v 1.7 1997-04-17 17:52:21 Singular Exp $ */
     4/* $Id: ring.cc,v 1.8 1997-04-18 15:49:40 Singular Exp $ */
    55
    66/*
     
    715715      if (r==currRing)
    716716      {
    717         PrintS("//   minpoly        : ");
    718         nfShowMipo();PrintLn();
     717        StringSetS("//   minpoly        : ");
     718        nfShowMipo();PrintS(StringAppend("\n"));
    719719      } 
    720720    } 
  • Singular/subexpr.cc

    r5ec695 r077e9c  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: subexpr.cc,v 1.13 1997-04-18 11:25:03 obachman Exp $ */
     4/* $Id: subexpr.cc,v 1.14 1997-04-18 15:49:41 Singular Exp $ */
    55
    66/*
     
    3030#include "timer.h"
    3131#include "ring.h"
     32#include "ffields.h"
    3233#include "numbers.h"
    3334#include "ipshell.h"
     
    632633          data=(char *)n;
    633634        }
     635        else if((rtyp==VMINPOLY)&&(currRing->ch>2))
     636        {
     637          nfShowMipo();
     638        }
    634639        else
    635640        {
     
    805810      case TRACE:      return (void *)traceit;
    806811      case VSHORTOUT:  return (void *)pShortOut;
    807       case VMINPOLY:   if (currRing->minpoly!=NULL)
     812      case VMINPOLY:   if ((currRing->minpoly!=NULL)&&(currRing->ch<2))
     813                       /* Q(a), Fp(a), but not GF(q) */
    808814                         return (void *)currRing->minpoly;
    809815                       else
Note: See TracChangeset for help on using the changeset viewer.