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