Warning, /frameworks/syntax-highlighting/autotests/input/highlight.mac is written in an unsupported language. File is not indexed.

0001 /*
0002 ------------------------------------------------------------------------
0003 Efficient Galois Fields in Maxima
0004 
0005 by Alasdair McAndrew
0006 and later extended by Fabrizio Caruso and Jacopo Daurizio
0007 
0008 it is distribuited together with gf_roots by Jacopo Daurizio
0009 
0010 Authors:
0011 
0012 Fabrizio Caruso   (optimizations, testing)
0013 Jacopo D'Aurizio   (optimizations, modular roots)
0014 Alasdair McAndrew (original version of the package, pohlig-helman log, etc... )
0015 ------------------------------------------------------------------------*/
0016 
0017 /* Released under terms of the GNU General Public License, version 2,
0018  * by permission of the authors to Robert Dodier circa 2007-12-02.
0019  */
0020 
0021 /* Defines a flag for dealing with large fields.  If it is set to "false",
0022 then lookup tables are used for exponentiation and logarithms.  Otherwise
0023 other algorithms are used */
0024 
0025 define_variable(largefield,true,bool)$
0026 define_variable(gf_char,0,integer)$
0027 define_variable(gf_exp,0,integer)$
0028 define_variable(gf_order,0,integer)$
0029 define_variable (gf_one, 'gf_one, any_check)$
0030 define_variable (gf_prim, 'gf_prim, any_check)$
0031 define_variable (gf_irr, 'gf_irr, any_check)$
0032 define_variable (gf_list, 'gf_list, any_check)$
0033 define_variable (gen_powers, 'gf_list, any_check)$
0034 remvalue(x,z,gf_char,gf_exp,gf_irr,pg,gp,lg,gf_prim,gf_one,gf_order,gf_list,gen_powers)$
0035 
0036 
0037 /* --------------------------------------------------------------------------------------------- */
0038 /* Settings */
0039 
0040 GF_VERBOSE:false; /* Verbosity */
0041 GF_WARNING: true; /* Warnings */
0042 GF_IRREDUCIBILITY_CHECK:false;   /* Irreducibility test for the minimal polynomial of the extension */
0043 
0044 /*
0045 ------------------------------------------------------------------------------------------------ */
0046 
0047 
0048 /* It defines a new current field with gf_char=b, min. pol.= p of deg= e*/
0049 gf_set([ars]):=block([gj,m,i,j,dg],
0050   if length(ars)=1 then
0051     (
0052     gf_setp(ars[1]),
0053     return(true)
0054     )
0055   else
0056     (
0057     if length(ars)=2 then
0058        (
0059        if numberp(ars[2]) then
0060          (
0061          if ars[2]=0 and GF_WARNING then
0062            (
0063            print("WARNING: the irreducible is zero! We assume GF(",ars[1],")"),
0064            gf_setp(ars[1]),
0065            return(true)
0066            )
0067          else
0068            (
0069            error("ERROR: you tried to extend with a non-zero constant!"),
0070            return(false)
0071            )
0072          )
0073        else
0074          (
0075          dg:hipow(ars[2],x),
0076 
0077          if dg=1 then
0078            gf_setp(ars[1]),
0079          gf_irr:ars[2],
0080          gf_exp:dg,
0081          return(true)
0082          )
0083        )
0084     else
0085        (
0086        gf_exp:ars[2],
0087        if gf_exp=1 then
0088           (
0089           gf_setp(ars[1]),
0090           gf_irr:rat(ars[3]),
0091           return(true)
0092           ),
0093        gf_irr:rat(ars[3])
0094        )
0095     ),
0096 
0097   gf_char:ars[1],
0098   gf_one:rat(1,x),
0099   gf_order:gf_char^gf_exp-1,
0100 
0101   m:makelist(coeff(gf_irr,x,i),i,0,gf_exp),
0102   gf_list:[[first(m),0]],j:1,
0103   for i:2 thru gf_exp+1 do if m[i]=0 then j:j+1 else ( gf_list:endcons([m[i],j],gf_list), j:1 ),
0104 
0105   if not(primep(gf_char)) then error("ERROR: Gf_Char must be a prime number.")
0106     else
0107       modulus:gf_char,
0108   if GF_IRREDUCIBILITY_CHECK and
0109        hipow(args(factor(ars[3]))[1],x)#hipow(rat(ars[3]),x) then
0110       error("ERROR: Polynomial is not irreducible"),
0111 
0112   if not(largefield) then
0113      (
0114      pg:mkpowers(),
0115      lg:mklogs()
0116      )
0117   else
0118      (
0119      if GF_VERBOSE then
0120        print("finding a primitive element..."),
0121 
0122      gf_prim:rat(gf_findprim(),x),
0123      if GF_VERBOSE then
0124      print("...primitive element found.")
0125 
0126      ),
0127   modulus:false, /* it resets the modulus */
0128   return(true)
0129 
0130   )$
0131 
0132 
0133 /* Prints out information about the field */
0134 gf_info():=block(
0135   print("Prime gf_char value: ",gf_char),
0136   print("Exponent: ", gf_exp),
0137   print("Multiplicative order: ",gf_order),
0138   print("Irreducible polynomial: ",gf_irr),
0139   print("Primitive element: ",gf_prim),
0140   if (largefield) then
0141     print("Largefield flag is true; powers and logarithms not computed.")
0142     else
0143     print("Largefield flag is false; powers and logarithms computed."),
0144   disp()
0145 )$