<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>~/ntl-11.4.2/doc/lzz_pE.cpp.html</title>
<meta name="Generator" content="Vim/8.0">
<meta name="plugin-version" content="vim7.4_v2">
<meta name="syntax" content="cpp">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="macvim">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #ffffff; }
body { font-family: monospace; color: #000000; background-color: #ffffff; }
* { font-size: 1em; }
.String { color: #4a708b; }
.PreProc { color: #1874cd; }
.Statement { color: #b03060; font-weight: bold; }
.Comment { color: #0000ee; font-style: italic; }
.Type { color: #008b00; font-weight: bold; }
-->
</style>
<script type='text/javascript'>
<!--
-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">/*</span><span class="Comment">*************************************************************************\</span>
<span class="Comment">MODULE: zz_pE</span>
<span class="Comment">SUMMARY:</span>
<span class="Comment">The class zz_pE is used to represent polynomials in Z_p[X] modulo a</span>
<span class="Comment">polynomial P. The modulus P may be any polynomial with deg(P) > 0,</span>
<span class="Comment">not necessarily irreducible. The modulus p defining Z_p need</span>
<span class="Comment">not be prime either.</span>
<span class="Comment">Objects of the class zz_pE are represented as a zz_pX of degree < deg(P).</span>
<span class="Comment">An executing program maintains a "current modulus", which is set to P</span>
<span class="Comment">using zz_pE::init(P). The current modulus for zz_pE (as well as for zz_p)</span>
<span class="Comment">*must* be initialized before an operations on zz_pE's are performed.</span>
<span class="Comment">The modulus may be changed, and a mechanism is provided for saving and</span>
<span class="Comment">restoring a modulus (see classes zz_pEPush and zz_pEContext below).</span>
<span class="Comment">\*************************************************************************</span><span class="Comment">*/</span>
<span class="PreProc">#include </span><span class="String"><NTL/lzz_pX.h></span>
<span class="Type">class</span> zz_pE {
<span class="Statement">public</span>:
zz_pE(); <span class="Comment">// initial value 0</span>
zz_pE(<span class="Type">const</span> zz_pE& a); <span class="Comment">// copy constructor</span>
<span class="Type">explicit</span> zz_pE(<span class="Type">const</span> zz_p& a); <span class="Comment">// promotion </span>
<span class="Type">explicit</span> zz_pE(<span class="Type">long</span> a); <span class="Comment">// promotion </span>
zz_pE& <span class="Statement">operator</span>=(<span class="Type">const</span> zz_pE& a); <span class="Comment">// assignment</span>
zz_pE& <span class="Statement">operator</span>=(<span class="Type">const</span> zz_p& a); <span class="Comment">// assignment</span>
zz_pE& <span class="Statement">operator</span>=(<span class="Type">long</span> a); <span class="Comment">// assignment</span>
~zz_pE(); <span class="Comment">// destructor</span>
zz_pE(zz_pE&& a);
<span class="Comment">// move constructor (C++11 only)</span>
<span class="Comment">// declared noexcept unless NTL_EXCEPTIONS flag is set</span>
<span class="PreProc">#ifndef NTL_DISABLE_MOVE_ASSIGN</span>
zz_pE& <span class="Statement">operator</span>=(zz_pE&& a);
<span class="Comment">// move assignment (C++11 only)</span>
<span class="Comment">// declared noexcept unless NTL_EXCEPTIONS flag is set</span>
<span class="PreProc">#endif</span>
<span class="Type">static</span> <span class="Type">void</span> init(<span class="Type">const</span> zz_pX& P);
<span class="Comment">// zz_pE::init(P) initializes the current modulus to P;</span>
<span class="Comment">// required: deg(P) >= 1.</span>
<span class="Type">static</span> <span class="Type">const</span> zz_pXModulus& modulus();
<span class="Comment">// zz_pE::modulus() yields read-only reference to the current modulus </span>
<span class="Type">static</span> <span class="Type">long</span> degree();
<span class="Comment">// zz_pE::degree() returns deg(P)</span>
<span class="Comment">// typedefs to aid generic programming</span>
<span class="Type">typedef</span> zz_pX rep_type;
<span class="Type">typedef</span> zz_pEContext context_type;
<span class="Type">typedef</span> zz_pEBak bak_type;
<span class="Type">typedef</span> zz_pEPush push_type;
<span class="Type">typedef</span> zz_pEX poly_type;
};
<span class="Type">const</span> zz_pX& rep(<span class="Type">const</span> zz_pE& a); <span class="Comment">// read-only access to representation of a</span>
<span class="Comment">/*</span><span class="Comment">*************************************************************************\</span>
<span class="Comment"> Comparison</span>
<span class="Comment">\*************************************************************************</span><span class="Comment">*/</span>
<span class="Type">long</span> <span class="Statement">operator</span>==(<span class="Type">const</span> zz_pE& a, <span class="Type">const</span> zz_pE& b);
<span class="Type">long</span> <span class="Statement">operator</span>!=(<span class="Type">const</span> zz_pE& a, <span class="Type">const</span> zz_pE& b);
<span class="Type">long</span> IsZero(<span class="Type">const</span> zz_pE& a); <span class="Comment">// test for 0</span>
<span class="Type">long</span> IsOne(<span class="Type">const</span> zz_pE& a); <span class="Comment">// test for 1</span>
<span class="Comment">// PROMOTIONS: ==, != promote {long, zz_p} to zz_pE on (a, b).</span>
<span class="Comment">/*</span><span class="Comment">*************************************************************************\</span>
<span class="Comment"> Addition </span>
<span class="Comment">\*************************************************************************</span><span class="Comment">*/</span>
<span class="Comment">// operator notation:</span>
zz_pE <span class="Statement">operator</span>+(<span class="Type">const</span> zz_pE& a, <span class="Type">const</span> zz_pE& b);
zz_pE <span class="Statement">operator</span>-(<span class="Type">const</span> zz_pE& a, <span class="Type">const</span> zz_pE& b);
zz_pE <span class="Statement">operator</span>-(<span class="Type">const</span> zz_pE& a);
zz_pE& <span class="Statement">operator</span>+=(zz_pE& x, <span class="Type">const</span> zz_pE& a);
zz_pE& <span class="Statement">operator</span>+=(zz_pE& x, <span class="Type">const</span> zz_p& a);
zz_pE& <span class="Statement">operator</span>+=(zz_pE& x, <span class="Type">long</span> a);
zz_pE& <span class="Statement">operator</span>++(zz_pE& x); <span class="Comment">// prefix</span>
<span class="Type">void</span> <span class="Statement">operator</span>++(zz_pE& x, <span class="Type">int</span>); <span class="Comment">// postfix</span>
zz_pE& <span class="Statement">operator</span>-=(zz_pE& x, <span class="Type">const</span> zz_pE& a);
zz_pE& <span class="Statement">operator</span>-=(zz_pE& x, <span class="Type">const</span> zz_p& a);
zz_pE& <span class="Statement">operator</span>-=(zz_pE& x, <span class="Type">long</span> a);
zz_pE& <span class="Statement">operator</span>--(zz_pE& x); <span class="Comment">// prefix</span>
<span class="Type">void</span> <span class="Statement">operator</span>--(zz_pE& x, <span class="Type">int</span>); <span class="Comment">// postfix</span>
<span class="Comment">// procedural versions:</span>
<span class="Type">void</span> add(zz_pE& x, <span class="Type">const</span> zz_pE& a, <span class="Type">const</span> zz_pE& b); <span class="Comment">// x = a + b</span>
<span class="Type">void</span> sub(zz_pE& x, <span class="Type">const</span> zz_pE& a, <span class="Type">const</span> zz_pE& b); <span class="Comment">// x = a - b </span>
<span class="Type">void</span> negate(zz_pE& x, <span class="Type">const</span> zz_pE& a); <span class="Comment">// x = - a </span>
<span class="Comment">// PROMOTIONS: +, -, add, sub promote {long, zz_p} to zz_pE on (a, b).</span>
<span class="Comment">/*</span><span class="Comment">*************************************************************************\</span>
<span class="Comment"> Multiplication </span>
<span class="Comment">\*************************************************************************</span><span class="Comment">*/</span>
<span class="Comment">// operator notation:</span>
zz_pE <span class="Statement">operator</span>*(<span class="Type">const</span> zz_pE& a, <span class="Type">const</span> zz_pE& b);
zz_pE& <span class="Statement">operator</span>*=(zz_pE& x, <span class="Type">const</span> zz_pE& a);
zz_pE& <span class="Statement">operator</span>*=(zz_pE& x, <span class="Type">const</span> zz_p& a);
zz_pE& <span class="Statement">operator</span>*=(zz_pE& x, <span class="Type">long</span> a);
<span class="Comment">// procedural versions:</span>
<span class="Type">void</span> mul(zz_pE& x, <span class="Type">const</span> zz_pE& a, <span class="Type">const</span> zz_pE& b); <span class="Comment">// x = a * b</span>
<span class="Type">void</span> sqr(zz_pE& x, <span class="Type">const</span> zz_pE& a); <span class="Comment">// x = a^2</span>
zz_pE sqr(<span class="Type">const</span> zz_pE& a);
<span class="Comment">// PROMOTIONS: *, mul promote {long, zz_p} to zz_pE on (a, b).</span>
<span class="Comment">/*</span><span class="Comment">*************************************************************************\</span>
<span class="Comment"> Division</span>
<span class="Comment">\*************************************************************************</span><span class="Comment">*/</span>
<span class="Comment">// operator notation:</span>
zz_pE <span class="Statement">operator</span>/(<span class="Type">const</span> zz_pE& a, <span class="Type">const</span> zz_pE& b);
zz_pE& <span class="Statement">operator</span>/=(zz_pE& x, <span class="Type">const</span> zz_pE& a);
zz_pE& <span class="Statement">operator</span>/=(zz_pE& x, <span class="Type">const</span> zz_p& a);
zz_pE& <span class="Statement">operator</span>/=(zz_pE& x, <span class="Type">long</span> a);
<span class="Comment">// procedural versions:</span>
<span class="Type">void</span> div(zz_pE& x, <span class="Type">const</span> zz_pE& a, <span class="Type">const</span> zz_pE& b);
<span class="Comment">// x = a/b. If b is not invertible, an error is raised.</span>
<span class="Type">void</span> inv(zz_pE& x, <span class="Type">const</span> zz_pE& a);
zz_pE inv(<span class="Type">const</span> zz_pE& a);
<span class="Comment">// x = 1/a</span>
<span class="Statement">PROMOTIONS</span>: /, div promote {<span class="Type">long</span>, zz_p} to zz_pE on (a, b).
<span class="Comment">/*</span><span class="Comment">*************************************************************************\</span>
<span class="Comment"> Exponentiation</span>
<span class="Comment">\*************************************************************************</span><span class="Comment">*/</span>
<span class="Type">void</span> power(zz_pE& x, <span class="Type">const</span> zz_pE& a, <span class="Type">const</span> ZZ& e);
zz_pE power(<span class="Type">const</span> zz_pE& a, <span class="Type">const</span> ZZ& e);
<span class="Type">void</span> power(zz_pE& x, <span class="Type">const</span> zz_pE& a, <span class="Type">long</span> e);
zz_pE power(<span class="Type">const</span> zz_pE& a, <span class="Type">long</span> e);
<span class="Comment">// x = a^e (e may be negative)</span>
<span class="Comment">/*</span><span class="Comment">*************************************************************************\</span>
<span class="Comment"> Random Elements</span>
<span class="Comment">\*************************************************************************</span><span class="Comment">*/</span>
<span class="Type">void</span> random(zz_pE& x);
zz_pE random_zz_pE();
<span class="Comment">// x = random element in zz_pE.</span>
<span class="Comment">/*</span><span class="Comment">*************************************************************************\</span>
<span class="Comment"> Norms and Traces</span>
<span class="Comment">\*************************************************************************</span><span class="Comment">*/</span>
<span class="Type">void</span> trace(zz_p& x, <span class="Type">const</span> zz_pE& a); <span class="Comment">// x = trace of a</span>
zz_p trace(<span class="Type">const</span> zz_pE& a);
<span class="Type">void</span> norm(zz_p& x, <span class="Type">const</span> zz_pE& a); <span class="Comment">// x = norm of a</span>
zz_p norm(<span class="Type">const</span> zz_pE& a);
<span class="Comment">/*</span><span class="Comment">*************************************************************************\</span>
<span class="Comment"> Input/Output</span>
<span class="Comment">\*************************************************************************</span><span class="Comment">*/</span>
ostream& <span class="Statement">operator</span><<(ostream& s, <span class="Type">const</span> zz_pE& a);
istream& <span class="Statement">operator</span>>>(istream& s, zz_pE& x);
<span class="Comment">// a zz_pX is read and reduced mod p</span>
<span class="Comment">/*</span><span class="Comment">*************************************************************************\</span>
<span class="Comment"> Modulus Switching </span>
<span class="Comment">A class zz_pEPush is provided for "backing up" the current modulus</span>
<span class="Comment">and installing a new one.</span>
<span class="Comment">Here is what you do to save the current modulus, temporarily</span>
<span class="Comment">set it to P, and automatically restore it:</span>
<span class="Comment"> { </span>
<span class="Comment"> zz_pEPush push(P); </span>
<span class="Comment"> ...</span>
<span class="Comment"> }</span>
<span class="Comment">The constructor for push will save the current modulus, and install P as the</span>
<span class="Comment">current modulus. The destructor for push will restore the old modulus when the</span>
<span class="Comment">scope enclosing it exits. This is the so-called RAII (resource acquisition is</span>
<span class="Comment">initialization) paradigm.</span>
<span class="Comment">You could also do the following:</span>
<span class="Comment"> {</span>
<span class="Comment"> zz_pEPush push; // just backup current modulus</span>
<span class="Comment"> ...</span>
<span class="Comment"> zz_pE::init(P1); // install P1 </span>
<span class="Comment"> ...</span>
<span class="Comment"> zz_pE::init(P2); // install P2</span>
<span class="Comment"> // reinstall original modulus as close of scope</span>
<span class="Comment"> }</span>
<span class="Comment"> </span>
<span class="Comment">The zz_pEPush interface is good for implementing simple stack-like</span>
<span class="Comment">modulus "context switching". For more general context switching,</span>
<span class="Comment">see zz_pEContext below. There is also an older zz_pEBak class</span>
<span class="Comment">that may also be useful.</span>
<span class="Comment">..........................................................................</span>
<span class="Comment">It is critical that zz_pE objects created under one zz_pE modulus are not used in</span>
<span class="Comment">any non-trivial way "out of context", i.e., under a different (or undefined)</span>
<span class="Comment">zz_pE modulus. However, for ease-of-use, some operations may be safely</span>
<span class="Comment">performed out of context. These safe operations include: the default and copy</span>
<span class="Comment">constructor, the destructor, and the assignment operator. In addition is is</span>
<span class="Comment">generally safe to read any zz_pE object out of context (i.e., printing it out, or</span>
<span class="Comment">fetching its underlying representive using the rep() function).</span>
<span class="Comment">Any unsafe uses out of context are not in general checked, and may </span>
<span class="Comment">lead to unpredictable behavior.</span>
<span class="Comment">\*************************************************************************</span><span class="Comment">*/</span>
<span class="Comment">// A convenient interface for common cases</span>
<span class="Type">class</span> zz_pEPush {
<span class="Statement">public</span>:
zz_pEPush(); <span class="Comment">// backup current modulus</span>
<span class="Type">explicit</span> zz_pEPush(<span class="Type">const</span> zz_pX& p);
<span class="Type">explicit</span> zz_pEPush(<span class="Type">const</span> zz_pEContext& context);
<span class="Comment">// backup current modulus and install the given one</span>
<span class="Statement">private</span>:
zz_pEPush(<span class="Type">const</span> zz_pEPush&); <span class="Comment">// disabled</span>
<span class="Type">void</span> <span class="Statement">operator</span>=(<span class="Type">const</span> zz_pEPush&); <span class="Comment">// disabled</span>
};
<span class="Comment">// more general context switching:</span>
<span class="Comment">// A zz_pEContext object has a modulus Q (possibly "null"),</span>
<span class="Type">class</span> zz_pEContext {
<span class="Statement">public</span>:
zz_pEContext(); <span class="Comment">// Q = "null"</span>
<span class="Type">explicit</span> zz_pEContext(<span class="Type">const</span> zz_pX& P); <span class="Comment">// Q = P</span>
<span class="Type">void</span> save(); <span class="Comment">// Q = CurrentModulus</span>
<span class="Type">void</span> restore() <span class="Type">const</span>; <span class="Comment">// CurrentModulus = Q</span>
zz_pEContext(<span class="Type">const</span> zz_pEContext&); <span class="Comment">// copy</span>
zz_pEContext& <span class="Statement">operator</span>=(<span class="Type">const</span> zz_pEContext&); <span class="Comment">// assignment</span>
~zz_pEContext(); <span class="Comment">// destructor</span>
};
<span class="Comment">// An older interface:</span>
<span class="Comment">// To describe this logic, think of a zz_pEBak object</span>
<span class="Comment">// of having two components: a modulus Q (possibly "null") and </span>
<span class="Comment">// an "auto-restore bit" b.</span>
<span class="Type">class</span> zz_pEBak {
<span class="Statement">public</span>:
zz_pEBak(); <span class="Comment">// Q = "null", b = 0</span>
~zz_pEBak(); <span class="Comment">// if (b) CurrentModulus = Q</span>
<span class="Type">void</span> save(); <span class="Comment">// Q = CurrentModulus, b = 1 </span>
<span class="Type">void</span> restore(); <span class="Comment">// CurrentModulus = Q, b = 0</span>
<span class="Statement">private</span>:
zz_pEBak(<span class="Type">const</span> zz_pEBak&); <span class="Comment">// copy disabled</span>
<span class="Type">void</span> <span class="Statement">operator</span>=(<span class="Type">const</span> zz_pEBak&); <span class="Comment">// assignment disabled</span>
};
<span class="Comment">/*</span><span class="Comment">*************************************************************************\</span>
<span class="Comment"> Miscellany</span>
<span class="Comment">\*************************************************************************</span><span class="Comment">*/</span>
<span class="Type">void</span> clear(zz_pE& x); <span class="Comment">// x = 0</span>
<span class="Type">void</span> set(zz_pE& x); <span class="Comment">// x = 1</span>
<span class="Type">static</span> <span class="Type">const</span> zz_pE& zz_pE::zero();
<span class="Comment">// zz_pE::zero() yields a read-only reference to zero</span>
<span class="Type">void</span> zz_pE::swap(zz_pE& x);
<span class="Type">void</span> swap(zz_pE& x, zz_pE& y);
<span class="Comment">// swap (done by "pointer swapping", if possible).</span>
<span class="Type">static</span> ZZ& zz_pE::cardinality();
<span class="Comment">// yields the cardinality, i.e., p^{zz_pE::degree()}</span>
zz_pE::zz_pE(INIT_NO_ALLOC_TYPE);
<span class="Comment">// special constructor: invoke as zz_pE x(INIT_NO_ALLOC);</span>
<span class="Comment">// initializes x to 0, but allocates no space (this is now the default)</span>
zz_pE::zz_pE(INIT_ALLOC_TYPE);
<span class="Comment">// special constructor: invoke as zz_pE x(INIT_ALLOC);</span>
<span class="Comment">// initializes x to 0, but allocates space</span>
zz_pE::allocate();
<span class="Comment">// useful in conjunction with the INIT_NO_ALLLOC constructor:</span>
<span class="Comment">// x.allocate() will pre-allocate space for x, using the</span>
<span class="Comment">// current modulus</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->