Changeset 395bff in git


Ignore:
Timestamp:
Dec 12, 2016, 6:11:38 PM (7 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', '17f1d200f27c5bd38f5dfc6e8a0879242279d1d8')
Children:
90f715a0b0b2d389f393a20365b7afde7cb4b18c
Parents:
69f579ab8cbfafd79a2045061aa0a279ac135fc5
Message:
use static routines in ffields.cc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpolys/coeffs/ffields.cc

    r69f579 r395bff  
    1616#include "numbers.h"
    1717#include "longrat.h"
     18#include "ffields.h"
    1819
    1920#include <string.h>
     
    2122#include <errno.h>
    2223
    23 BOOLEAN nfGreaterZero (number k, const coeffs r);
    24 number  nfMult        (number a, number b, const coeffs r);
    25 number  nfInit        (long i, const coeffs r);
    26 number  nfParameter   (int i, const coeffs r);
    27 long    nfInt         (number &n, const coeffs r);
    28 number  nfAdd         (number a, number b, const coeffs r);
    29 number  nfSub         (number a, number b, const coeffs r);
    30 void    nfPower       (number a, int i, number * result, const coeffs r);
    31 BOOLEAN nfIsZero      (number a, const coeffs r);
    32 BOOLEAN nfIsOne       (number a, const coeffs r);
    33 BOOLEAN nfIsMOne      (number a, const coeffs r);
    34 number  nfDiv         (number a, number b, const coeffs r);
    35 number  nfNeg         (number c, const coeffs r);
    36 number  nfInvers      (number c, const coeffs r);
    37 BOOLEAN nfGreater     (number a, number b, const coeffs r);
    38 BOOLEAN nfEqual       (number a, number b, const coeffs r);
    39 const char *  nfRead  (const char *s, number *a, const coeffs r);
    4024#ifdef LDEBUG
    4125BOOLEAN nfDBTest      (number a, const char *f, const int l, const coeffs r);
    4226#endif
    43 //void    nfSetChar     (const coeffs r);
    44 
    45 nMapFunc nfSetMap     (const coeffs src, const coeffs dst);
    46 char *  nfName        (number n, const coeffs r);
    47 void    nfReadTable   (const int c, const coeffs r);
    48 
    49 void    nfCoeffWrite(const coeffs r, BOOLEAN details);
    50 void    nfShowMipo(const coeffs r);
    51 
    52 
    5327
    5428/// Our Type!
     
    5731//unsigned short *nfPlus1Table=NULL; /* the table i=log(z^i) -> log(z^i+1) */
    5832
    59 const double sixteenlog2= 11.09035489;
    6033/* the q's from the table 'fftable' */
    6134const unsigned short fftable[]={
     
    163136
    164137/*2
     138* a == 0 ?
     139*/
     140static BOOLEAN nfIsZero (number  a, const coeffs r)
     141{
     142#ifdef LDEBUG
     143  nfTest(a, r);
     144#endif
     145  return (long)r->m_nfCharQ == (long)a;
     146}
     147
     148/*2
     149* a == -1 ?
     150*/
     151static BOOLEAN nfIsMOne (number a, const coeffs r)
     152{
     153#ifdef LDEBUG
     154  nfTest(a, r);
     155#endif
     156  if (0L == (long)a) return FALSE; /* special handling of char 2*/
     157  return (long)r->m_nfM1 == (long)a;
     158}
     159
     160/*2
    165161* k >= 0 ?
    166162*/
    167 BOOLEAN nfGreaterZero (number k, const coeffs r)
     163static BOOLEAN nfGreaterZero (number k, const coeffs r)
    168164{
    169165#ifdef LDEBUG
     
    176172* a*b
    177173*/
    178 number nfMult (number a,number b, const coeffs r)
     174static number nfMult (number a,number b, const coeffs r)
    179175{
    180176#ifdef LDEBUG
     
    196192* int -> number
    197193*/
    198 number nfInit (long i, const coeffs r)
     194static number nfInit (long i, const coeffs r)
    199195{
    200196  assume( r->m_nfPlus1Table != NULL );
     
    220216* the generating element `z`
    221217*/
    222 number nfParameter (int i, const coeffs)
     218static number nfParameter (int i, const coeffs)
    223219{
    224220  assume(i==1);
     
    245241* number -> int
    246242*/
    247 long nfInt (number &n, const coeffs )
     243static long nfInt (number &n, const coeffs )
    248244{
    249245  return (long)n;
     
    253249* a + b
    254250*/
    255 number nfAdd (number a, number b, const coeffs R)
     251static number nfAdd (number a, number b, const coeffs R)
    256252{
    257253/*4 z^a+z^b=z^b*(z^(a-b)+1), if a>=b; *
     
    290286
    291287/*2
     288* -c
     289*/
     290static number nfNeg (number c, const coeffs r)
     291{
     292/*4 -z^c=z^c*(-1)=z^c*nfM1*/
     293#ifdef LDEBUG
     294  nfTest(c, r);
     295#endif
     296  if ((long)r->m_nfCharQ == (long)c) return c;
     297  long i=(long)c+(long)r->m_nfM1;
     298  if (i>=(long)r->m_nfCharQ1) i-=(long)r->m_nfCharQ1;
     299#ifdef LDEBUG
     300  nfTest((number)i, r);
     301#endif
     302  return (number)i;
     303}
     304
     305/*2
    292306* a - b
    293307*/
    294 number nfSub (number a, number b, const coeffs r)
     308static number nfSub (number a, number b, const coeffs r)
    295309{
    296310  number mb = nfNeg(b, r);
     
    299313
    300314/*2
    301 * a == 0 ?
    302 */
    303 BOOLEAN nfIsZero (number a, const coeffs r)
     315* a == 1 ?
     316*/
     317static BOOLEAN nfIsOne (number a, const coeffs r)
    304318{
    305319#ifdef LDEBUG
    306320  nfTest(a, r);
    307321#endif
    308   return (long)r->m_nfCharQ == (long)a;
    309 }
    310 
    311 /*2
    312 * a == 1 ?
    313 */
    314 BOOLEAN nfIsOne (number a, const coeffs r)
    315 {
    316 #ifdef LDEBUG
    317   nfTest(a, r);
    318 #endif
    319322  return 0L == (long)a;
    320323}
    321324
    322325/*2
    323 * a == -1 ?
    324 */
    325 BOOLEAN nfIsMOne (number a, const coeffs r)
    326 {
    327 #ifdef LDEBUG
    328   nfTest(a, r);
    329 #endif
    330   if (0L == (long)a) return FALSE; /* special handling of char 2*/
    331   return (long)r->m_nfM1 == (long)a;
    332 }
    333 
    334 /*2
    335326* a / b
    336327*/
    337 number nfDiv (number a,number b, const coeffs r)
     328static number nfDiv (number a,number b, const coeffs r)
    338329{
    339330#ifdef LDEBUG
     
    363354* 1 / c
    364355*/
    365 number  nfInvers (number c, const coeffs r)
     356static number  nfInvers (number c, const coeffs r)
    366357{
    367358#ifdef LDEBUG
     
    380371
    381372/*2
    382 * -c
    383 */
    384 number nfNeg (number c, const coeffs r)
    385 {
    386 /*4 -z^c=z^c*(-1)=z^c*nfM1*/
    387 #ifdef LDEBUG
    388   nfTest(c, r);
    389 #endif
    390   if ((long)r->m_nfCharQ == (long)c) return c;
    391   long i=(long)c+(long)r->m_nfM1;
    392   if (i>=(long)r->m_nfCharQ1) i-=(long)r->m_nfCharQ1;
    393 #ifdef LDEBUG
    394   nfTest((number)i, r);
    395 #endif
    396   return (number)i;
    397 }
    398 
    399 /*2
    400373* a > b ?
    401374*/
    402 BOOLEAN nfGreater (number a,number b, const coeffs r)
     375static BOOLEAN nfGreater (number a,number b, const coeffs r)
    403376{
    404377#ifdef LDEBUG
     
    412385* a == b ?
    413386*/
    414 BOOLEAN nfEqual (number a,number b, const coeffs r)
     387static BOOLEAN nfEqual (number a,number b, const coeffs r)
    415388{
    416389#ifdef LDEBUG
     
    465438
    466439/*2
    467 *
    468 */
    469 char * nfName(number a, const coeffs r)
    470 {
    471 #ifdef LDEBUG
    472   nfTest(a, r);
    473 #endif
    474   char *s;
    475   const char * const nf_Parameter=n_ParameterNames(r)[0];
    476   if (((long)a==(long)r->m_nfCharQ) || ((long)a==0L)) return NULL;
    477   else if ((long)a==1L)
    478   {
    479     return omStrDup(nf_Parameter);
    480   }
    481   else
    482   {
    483     s=(char *)omAlloc(4+strlen(nf_Parameter));
    484     sprintf(s,"%s%d",nf_Parameter,(int)((long)a));
    485   }
    486   return s;
    487 }
    488 /*2
    489440* c ^ i with i>=0
    490441*/
    491 void nfPower (number a, int i, number * result, const coeffs r)
     442static void nfPower (number a, int i, number * result, const coeffs r)
    492443{
    493444#ifdef LDEBUG
     
    538489* read a number
    539490*/
    540 const char * nfRead (const char *s, number *a, const coeffs r)
     491static const char * nfRead (const char *s, number *a, const coeffs r)
    541492{
    542493  int i;
     
    575526}
    576527
    577 int gf_tab_numdigits62 ( int q );
    578 int convertback62 ( char * p, int n );
    579 
    580 int nfMinPoly[16];
     528int gf_tab_numdigits62 ( int q ); /*factory/gf_tabitil.cc */
     529int convertback62 ( char * p, int n ); /*factory/gf_tabitil.cc */
     530
     531static int nfMinPoly[16];
    581532
    582533void nfShowMipo(const coeffs r)
     
    621572* init global variables from files 'gftables/%d'
    622573*/
    623 void nfReadTable(const int c, const coeffs r)
     574static void nfReadTable(const int c, const coeffs r)
    624575{
    625576  //Print("GF(%d)\n",c);
     
    721672* map Z/p -> GF(p,n)
    722673*/
    723 number nfMapP(number c, const coeffs, const coeffs dst)
     674static number nfMapP(number c, const coeffs, const coeffs dst)
    724675{
    725676  return nfInit((int)((long)c), dst);
     
    729680* map GF(p,n1) -> GF(p,n2), n1 < n2, n1 | n2
    730681*/
    731 int nfMapGG_factor;
    732 number nfMapGG(number c, const coeffs src, const coeffs)
     682static int nfMapGG_factor;
     683static number nfMapGG(number c, const coeffs src, const coeffs)
    733684{
    734685  int i=(long)c;
     
    740691* map GF(p,n1) -> GF(p,n2), n1 > n2, n2 | n1
    741692*/
    742 number nfMapGGrev(number c, const coeffs src, const coeffs)
     693static number nfMapGGrev(number c, const coeffs src, const coeffs)
    743694{
    744695  int ex=(int)((long)c);
     
    752703* set map function nMap ... -> GF(p,n)
    753704*/
    754 nMapFunc nfSetMap(const coeffs src, const coeffs dst)
     705static nMapFunc nfSetMap(const coeffs src, const coeffs dst)
    755706{
    756707  if (nCoeff_is_GF(src,src->m_nfCharQ))
     
    841792}
    842793
     794static void nfCoeffWrite  (const coeffs r, BOOLEAN details)
     795{
     796  // m_nfCharQ = p^k where p is the characteristic (r->CharP) and k is GFDegree
     797  Print("ZZ/%d[%s]",r->m_nfCharQ,n_ParameterNames(r)[0]);
     798  if ( details )
     799  {
     800    StringSetS("\n//   minpoly        : ");
     801    nfShowMipo(r);
     802    StringAppendS("");
     803    char *s=StringEndS(); PrintS(s); omFree(s);
     804  }
     805  else PrintS("//   minpoly        : ...");
     806}
     807
     808static BOOLEAN nfCoeffIsEqual (const coeffs r, n_coeffType n, void * parameter)
     809{
     810  if (n==n_GF) {
     811    GFInfo* p = (GFInfo *)(parameter);
     812    int c = pow (p->GFChar, p->GFDegree);
     813    if ((c == r->m_nfCharQ) && (strcmp(n_ParameterNames(r)[0], p->GFPar_name) == 0))
     814      return TRUE;
     815  }
     816  return FALSE;
     817}
    843818BOOLEAN nfInitChar(coeffs r,  void * parameter)
    844819{
     
    948923  const double check= log ((double) (p->GFChar));
    949924
     925  static const double sixteenlog2= 11.09035489;
    950926  if( (p->GFDegree * check) > sixteenlog2 )
    951927  {
     
    975951}
    976952
    977 void    nfCoeffWrite  (const coeffs r, BOOLEAN details)
    978 {
    979   // m_nfCharQ = p^k where p is the characteristic (r->CharP) and k is GFDegree
    980   Print("ZZ/%d[%s]",r->m_nfCharQ,n_ParameterNames(r)[0]);
    981   if ( details )
    982   {
    983     StringSetS("\n//   minpoly        : ");
    984     nfShowMipo(r);
    985     StringAppendS("");
    986     char *s=StringEndS(); PrintS(s); omFree(s);
    987   }
    988   else PrintS("//   minpoly        : ...");
    989 }
    990 
    991 static BOOLEAN nfCoeffIsEqual (const coeffs r, n_coeffType n, void * parameter)
    992 {
    993   if (n==n_GF) {
    994     GFInfo* p = (GFInfo *)(parameter);
    995     int c = pow (p->GFChar, p->GFDegree);
    996     if ((c == r->m_nfCharQ) && (strcmp(n_ParameterNames(r)[0], p->GFPar_name) == 0))
    997       return TRUE;
    998   }
    999   return FALSE;
    1000 }
Note: See TracChangeset for help on using the changeset viewer.