An object that contains an NTL::ZZX polynomial along with a coefficient modulus p2r and a polynomial modulus G.
More...
#include <PolyMod.h>
Public Member Functions | |
| PolyMod () | |
| Default constructor. More... | |
| PolyMod (const std::shared_ptr< PolyModRing > &ringDescriptor) | |
| No-data constructor. More... | |
| PolyMod (long input, const std::shared_ptr< PolyModRing > &ringDescriptor) | |
| Constant constructor. More... | |
| PolyMod (const std::vector< long > &input, const std::shared_ptr< PolyModRing > &ringDescriptor) | |
| Coefficient vector constructor. More... | |
| PolyMod (const NTL::ZZX &input, const std::shared_ptr< PolyModRing > &ringDescriptor) | |
| Polynomial constructor. More... | |
| PolyMod (const PolyMod &input)=default | |
| Default copy constructor. More... | |
| PolyMod (PolyMod &&input) noexcept=default | |
| Default move constructor. More... | |
| ~PolyMod ()=default | |
| Default destructor. More... | |
| PolyMod & | operator= (const PolyMod &input)=default |
| Assignment operator. More... | |
| PolyMod & | operator= (PolyMod &&input)=default |
| default move assignment operator More... | |
| PolyMod & | operator= (long input) |
long assignment operator, creates a constant polynomial mod G and p2r. More... | |
| PolyMod & | operator= (const std::vector< long > &input) |
std::vector<long> assignment operator, creates a polynomial mod G and p2r. More... | |
| PolyMod & | operator= (const std::initializer_list< long > &input) |
std::initializer_list<long> assignment operator, creates a polynomial mod G and p2r. More... | |
| PolyMod & | operator= (const NTL::ZZX &input) |
NTL::ZZX assignment operator, creates a polynomial mod G and p2r. More... | |
| operator long () const | |
Explicit conversion to a long. More... | |
| operator std::vector< long > () const | |
Explicit conversion to std::vector<long> (coefficient vector). More... | |
| operator NTL::ZZX () const | |
Explicit conversion to an NTL::ZZX. More... | |
| bool | isValid () const |
Gets the validity of this. This will be false iff this was default constructed. More... | |
| long | getp2r () const |
| Get current p^r value. More... | |
| NTL::ZZX | getG () const |
| Get current G value. More... | |
| const NTL::ZZX & | getData () const |
Getter function that returns the data of PolyMod as an NTL::ZZX const reference. More... | |
| bool | operator== (const PolyMod &rhs) const |
Equals operator between two PolyMod objects. More... | |
| bool | operator== (long rhs) const |
Equals operator between a PolyMod and a long. More... | |
| bool | operator== (const std::vector< long > &rhs) const |
Equals operator between two PolyMod objects. More... | |
| bool | operator== (const NTL::ZZX &rhs) const |
Equals operator between two PolyMod objects. More... | |
| template<typename T > | |
| bool | operator!= (T &&rhs) const |
| Not equals operator. More... | |
| PolyMod & | negate () |
| Negate function. More... | |
| PolyMod | operator- () const |
| Unary minus operator. More... | |
| PolyMod | operator* (const PolyMod &rhs) const |
| Infix multiplication operator. More... | |
| PolyMod | operator* (long rhs) const |
Infix multiplication operator with long. More... | |
| PolyMod | operator* (const NTL::ZZX &rhs) const |
Infix multiplication operator with NTL::ZZX. More... | |
| PolyMod | operator+ (const PolyMod &rhs) const |
| Infix plus operator. More... | |
| PolyMod | operator+ (long rhs) const |
Infix plus operator with long. More... | |
| PolyMod | operator+ (const NTL::ZZX &rhs) const |
Infix plus operator with NTL::ZZX. More... | |
| PolyMod | operator- (const PolyMod &rhs) const |
| Infix minus operator. More... | |
| PolyMod | operator- (long rhs) const |
Infix minus operator with long. More... | |
| PolyMod | operator- (const NTL::ZZX &rhs) const |
Infix minus operator with NTL::ZZX. More... | |
| PolyMod & | operator*= (const PolyMod &otherPoly) |
Times equals operator with PolyMod rhs. More... | |
| PolyMod & | operator*= (long scalar) |
Times equals operator with long rhs. More... | |
| PolyMod & | operator*= (const NTL::ZZX &otherPoly) |
Times equals operator with NTL::ZZX rhs. More... | |
| PolyMod & | operator+= (const PolyMod &otherPoly) |
Plus equals operator with PolyMod rhs. More... | |
| PolyMod & | operator+= (long scalar) |
Plus equals operator with long rhs. More... | |
| PolyMod & | operator+= (const NTL::ZZX &otherPoly) |
Plus equals operator with NTL::ZZX rhs. More... | |
| PolyMod & | operator-= (const PolyMod &otherPoly) |
Minus equals operator with PolyMod rhs. More... | |
| PolyMod & | operator-= (long scalar) |
Minus equals operator with long rhs. More... | |
| PolyMod & | operator-= (const NTL::ZZX &otherPoly) |
Minus equals operator with NTL::ZZX rhs. More... | |
| void | writeToJSON (std::ostream &os) const |
Serialize this PolyMod to the output stream os. More... | |
| JsonWrapper | writeToJSON () const |
Serialize this PolyMod to the JsonWrapper object. More... | |
| void | readJSON (std::istream &is) |
In-place deserialize a PolyMod object from the input stream is. More... | |
| void | readJSON (const JsonWrapper &jw) |
In-place deserialize a PolyMod object from the from the JsonWrapper jw. More... | |
Static Public Member Functions | |
| static PolyMod | readFromJSON (std::istream &is, const std::shared_ptr< PolyModRing > &ringDescriptor) |
Deserialize a PolyMod object from the input stream is. More... | |
| static PolyMod | readFromJSON (const JsonWrapper &jw, const std::shared_ptr< PolyModRing > &ringDescriptor) |
Deserialize a PolyMod object from the JsonWrapper jw. More... | |
Friends | |
| std::istream & | operator>> (std::istream &is, PolyMod &poly) |
| Input shift operator. More... | |
| std::ostream & | operator<< (std::ostream &os, const PolyMod &poly) |
| Output shift operator. More... | |
Detailed Description
An object that contains an NTL::ZZX polynomial along with a coefficient modulus p2r and a polynomial modulus G.
A PolyMod object can be considered to be an element of
where
and
are the passed-in parameters p2r and G.
This allows for inter-PolyMod operations with the modulo operations performed automatically.
General usage:
Calling an operation on a default constructed PolyMod will throw an helib::LogicError.
Constructor & Destructor Documentation
◆ PolyMod() [1/7]
| helib::PolyMod::PolyMod | ( | ) |
◆ PolyMod() [2/7]
|
explicit |
No-data constructor.
- Parameters
-
ringDescriptor Descriptor object for the plaintext ring. Contains p^r and G which are to be used for modular reduction.
- Note
- This constructor does not take in input data but can be assigned data later via
operator=.
◆ PolyMod() [3/7]
| helib::PolyMod::PolyMod | ( | long | input, |
| const std::shared_ptr< PolyModRing > & | ringDescriptor | ||
| ) |
Constant constructor.
- Parameters
-
input Input data as a long.ringDescriptor Descriptor object for the plaintext ring. Contains p^r and G which are to be used for modular reduction.
- Note
- This constructor accepts input data as a
longand converts it into anNTL::ZZXpolynomial.
◆ PolyMod() [4/7]
| helib::PolyMod::PolyMod | ( | const std::vector< long > & | input, |
| const std::shared_ptr< PolyModRing > & | ringDescriptor | ||
| ) |
Coefficient vector constructor.
- Parameters
-
input Input data as a vector of long(the i'th element of the vector corresponds to the coefficient of x^i).ringDescriptor Descriptor object for the plaintext ring. Contains p^r and G which are to be used for modular reduction.
- Note
- This constructor accepts input data as a
std::vector<long>and converts it into anNTL::ZZXpolynomial.
◆ PolyMod() [5/7]
| helib::PolyMod::PolyMod | ( | const NTL::ZZX & | input, |
| const std::shared_ptr< PolyModRing > & | ringDescriptor | ||
| ) |
Polynomial constructor.
- Parameters
-
input Input data as an NTL::ZZX.ringDescriptor Descriptor object for the plaintext ring. Contains p^r and G which are to be used for modular reduction.
- Note
- This constructor accepts input data as an
NTL::ZZX.
◆ PolyMod() [6/7]
|
default |
Default copy constructor.
- Parameters
-
input PolyModobject that is copied.
◆ PolyMod() [7/7]
|
defaultnoexcept |
Default move constructor.
◆ ~PolyMod()
|
default |
Default destructor.
Member Function Documentation
◆ getData()
| const NTL::ZZX & helib::PolyMod::getData | ( | ) | const |
Getter function that returns the data of PolyMod as an NTL::ZZX const reference.
◆ getG()
| NTL::ZZX helib::PolyMod::getG | ( | ) | const |
Get current G value.
- Returns
- The current G value in use.
◆ getp2r()
| long helib::PolyMod::getp2r | ( | ) | const |
Get current p^r value.
- Returns
- The current p^r value in use.
◆ isValid()
| bool helib::PolyMod::isValid | ( | ) | const |
Gets the validity of this. This will be false iff this was default constructed.
- Returns
trueifthisis valid,falseotherwise.
◆ negate()
| PolyMod & helib::PolyMod::negate | ( | ) |
Negate function.
- Returns
- Reference to
*thispost negation.
◆ operator long()
|
explicit |
Explicit conversion to a long.
- Note
- This function returns only the constant term even if the polynomial contains higher order terms.
◆ operator NTL::ZZX()
|
explicit |
Explicit conversion to an NTL::ZZX.
◆ operator std::vector< long >()
|
explicit |
Explicit conversion to std::vector<long> (coefficient vector).
◆ operator!=()
|
inline |
Not equals operator.
- Parameters
-
rhs Right-hand side of comparison.
- Returns
trueif not equal,falseotherwise
- Note
- Simply forwards to the correct
operator==method.
◆ operator*() [1/3]
| PolyMod helib::PolyMod::operator* | ( | const NTL::ZZX & | rhs | ) | const |
Infix multiplication operator with NTL::ZZX.
- Parameters
-
rhs Right hand side of multiplication.
- Returns
- Product of the two objects.
◆ operator*() [2/3]
Infix multiplication operator.
- Parameters
-
rhs Right hand side of multiplication.
- Returns
- Product of the two
PolyModobjects.
◆ operator*() [3/3]
| PolyMod helib::PolyMod::operator* | ( | long | rhs | ) | const |
Infix multiplication operator with long.
- Parameters
-
rhs Right hand side of multiplication.
- Returns
- Product of the two values.
◆ operator*=() [1/3]
| PolyMod & helib::PolyMod::operator*= | ( | const NTL::ZZX & | otherPoly | ) |
Times equals operator with NTL::ZZX rhs.
- Parameters
-
otherPoly Right hand side of multiplication.
- Returns
- Reference to
*thispost multiplication.
◆ operator*=() [2/3]
Times equals operator with PolyMod rhs.
- Parameters
-
otherPoly Right hand side of multiplication.
- Returns
- Reference to
*thispost multiplication.
◆ operator*=() [3/3]
| PolyMod & helib::PolyMod::operator*= | ( | long | scalar | ) |
Times equals operator with long rhs.
- Parameters
-
scalar Right hand side of multiplication.
- Returns
- Reference to
*thispost multiplication.
◆ operator+() [1/3]
| PolyMod helib::PolyMod::operator+ | ( | const NTL::ZZX & | rhs | ) | const |
Infix plus operator with NTL::ZZX.
- Parameters
-
rhs Right hand side of addition.
- Returns
- Sum of the two objects.
◆ operator+() [2/3]
Infix plus operator.
- Parameters
-
rhs Right hand side of addition.
- Returns
- Sum of the two
PolyModobjects.
◆ operator+() [3/3]
| PolyMod helib::PolyMod::operator+ | ( | long | rhs | ) | const |
Infix plus operator with long.
- Parameters
-
rhs Right hand side of addition.
- Returns
- Sum of the two values.
◆ operator+=() [1/3]
| PolyMod & helib::PolyMod::operator+= | ( | const NTL::ZZX & | otherPoly | ) |
Plus equals operator with NTL::ZZX rhs.
- Parameters
-
otherPoly Right hand side of addition.
- Returns
- Reference to
*thispost addition.
◆ operator+=() [2/3]
Plus equals operator with PolyMod rhs.
- Parameters
-
otherPoly Right hand side of addition.
- Returns
- Reference to
*thispost addition.
◆ operator+=() [3/3]
| PolyMod & helib::PolyMod::operator+= | ( | long | scalar | ) |
Plus equals operator with long rhs.
- Parameters
-
scalar Right hand side of addition.
- Returns
- Reference to
*thispost addition.
◆ operator-() [1/4]
◆ operator-() [2/4]
| PolyMod helib::PolyMod::operator- | ( | const NTL::ZZX & | rhs | ) | const |
Infix minus operator with NTL::ZZX.
- Parameters
-
rhs Right hand side of subtraction.
- Returns
- Difference of the two objects.
◆ operator-() [3/4]
Infix minus operator.
- Parameters
-
rhs Right hand side of subtraction.
- Returns
- Difference of the two
PolyModobjects.
◆ operator-() [4/4]
| PolyMod helib::PolyMod::operator- | ( | long | rhs | ) | const |
Infix minus operator with long.
- Parameters
-
rhs Right hand side of subtraction.
- Returns
- Difference of the two values.
◆ operator-=() [1/3]
| PolyMod & helib::PolyMod::operator-= | ( | const NTL::ZZX & | otherPoly | ) |
Minus equals operator with NTL::ZZX rhs.
- Parameters
-
otherPoly Right hand side of subtraction.
- Returns
- Reference to
*thispost subtraction.
◆ operator-=() [2/3]
Minus equals operator with PolyMod rhs.
- Parameters
-
otherPoly Right hand side of subtraction.
- Returns
- Reference to
*thispost subtraction.
◆ operator-=() [3/3]
| PolyMod & helib::PolyMod::operator-= | ( | long | scalar | ) |
Minus equals operator with long rhs.
- Parameters
-
scalar Right hand side of subtraction.
- Returns
- Reference to
*thispost subtraction.
◆ operator=() [1/6]
| PolyMod & helib::PolyMod::operator= | ( | const NTL::ZZX & | input | ) |
NTL::ZZX assignment operator, creates a polynomial mod G and p2r.
- Parameters
-
input Polynomial.
◆ operator=() [2/6]
Assignment operator.
- Parameters
-
input Another PolyModto copy.
◆ operator=() [3/6]
| PolyMod & helib::PolyMod::operator= | ( | const std::initializer_list< long > & | input | ) |
std::initializer_list<long> assignment operator, creates a polynomial mod G and p2r.
- Parameters
-
input coefficient vector as an initializer list of long(the i'th element of the vector corresponds to the coefficient of x^i).
◆ operator=() [4/6]
| PolyMod & helib::PolyMod::operator= | ( | const std::vector< long > & | input | ) |
std::vector<long> assignment operator, creates a polynomial mod G and p2r.
- Parameters
-
input Coefficient vector of long(the i'th element of the vector corresponds to the coefficient of x^i).
◆ operator=() [5/6]
| PolyMod & helib::PolyMod::operator= | ( | long | input | ) |
long assignment operator, creates a constant polynomial mod G and p2r.
- Parameters
-
input longdatum.
◆ operator=() [6/6]
◆ operator==() [1/4]
| bool helib::PolyMod::operator== | ( | const NTL::ZZX & | rhs | ) | const |
◆ operator==() [2/4]
| bool helib::PolyMod::operator== | ( | const PolyMod & | rhs | ) | const |
◆ operator==() [3/4]
| bool helib::PolyMod::operator== | ( | const std::vector< long > & | rhs | ) | const |
◆ operator==() [4/4]
| bool helib::PolyMod::operator== | ( | long | rhs | ) | const |
◆ readFromJSON() [1/2]
|
static |
Deserialize a PolyMod object from the JsonWrapper jw.
- Parameters
-
jw Input JsonWrapper.ringDescriptor Descriptor object for the plaintext ring.
- Returns
- The deserialized
PolyModobject.PolyMod my_poly = PolyMod::readFromJSON(..., context);static PolyMod readFromJSON(std::istream &is, const std::shared_ptr< PolyModRing > &ringDescriptor)Deserialize a PolyMod object from the input stream is.Definition: PolyMod.cpp:303
The input stream has to be a JSON list.
Each element of the list will be deserialized as a coefficient of the polynomial.
For example '['coef0', 'coef1', 'coef2']' will be deserialized as a PolyMod object poly where poly[0]=coef0, poly[1]=coef1, poly[2]=coef2 and poly[i]=0 for i>2.
◆ readFromJSON() [2/2]
|
static |
Deserialize a PolyMod object from the input stream is.
- Parameters
-
is Input std::istream.ringDescriptor Descriptor object for the plaintext ring.
- Returns
- The deserialized
PolyModobject.
- Exceptions
-
IOError if the stream is not a valid JSON. PolyMod my_poly = PolyMod::readFromJSON(std::cin, context);
The input stream has to be formatted as a JSON list.
Each element of the list will be deserialized as a coefficient of the polynomial.
For example '['coef0', 'coef1', 'coef2']' will be deserialized as a PolyMod object poly where poly[0]=coef0, poly[1]=coef1, poly[2]=coef2 and poly[i]=0 for i>2.
◆ readJSON() [1/2]
| void helib::PolyMod::readJSON | ( | const JsonWrapper & | jw | ) |
In-place deserialize a PolyMod object from the from the JsonWrapper jw.
- Parameters
-
jw Input JsonWrapper.
- Note
polymust be constructed with an appropriate p2r and G BEFORE calling this function. For example,PolyMod my_poly(p2r, G);my_poly.readJSON(...);
The input stream has to a JSON list.
Each element of the list will be deserialized as a coefficient of the polynomial.
For example '['coef0', 'coef1', 'coef2']' will be deserialized as a PolyMod object poly where poly[0]=coef0, poly[1]=coef1, poly[2]=coef2 and poly[i]=0 for i>2.
◆ readJSON() [2/2]
| void helib::PolyMod::readJSON | ( | std::istream & | is | ) |
In-place deserialize a PolyMod object from the input stream is.
- Parameters
-
is Input std::istream.
- Exceptions
-
IOError if the stream is not a valid JSON.
- Note
polymust be constructed with an appropriate p2r and G BEFORE calling this function. For example,PolyMod my_poly(p2r, G);my_poly.readJSON(std::cin);
The input stream has to be formatted as a JSON list.
Each element of the list will be deserialized as a coefficient of the polynomial.
For example '['coef0', 'coef1', 'coef2']' will be deserialized as a PolyMod object poly where poly[0]=coef0, poly[1]=coef1, poly[2]=coef2 and poly[i]=0 for i>2.
◆ writeToJSON() [1/2]
| JsonWrapper helib::PolyMod::writeToJSON | ( | ) | const |
Serialize this PolyMod to the JsonWrapper object.
- Returns
- The
JsonWrappercontaining the serializedPolyMod.
- Note
- p2r and G are not serialized, see note of
deserialize.
The output will be a JSON list.
Each coefficient of poly will be serialized in an element of such list.
For example if we have a PolyMod object poly such that poly[0]=coef0, poly[1]=coef1, poly[2]=coef2, and poly[i]=0 for i>2, it will be serialized as '['coef0', 'coef1', 'coef2']'.
◆ writeToJSON() [2/2]
| void helib::PolyMod::writeToJSON | ( | std::ostream & | os | ) | const |
Serialize this PolyMod to the output stream os.
- Parameters
-
os Output std::ostream.
- Note
- p2r and G are not serialized, see note of
deserialize.
The output stream will be formatted as a JSON list.
Each coefficient of poly will be serialized in an element of such list.
For example if we have a PolyMod object poly such that poly[0]=coef0, poly[1]=coef1, poly[2]=coef2, and poly[i]=0 for i>2, it will be serialized as '['coef0', 'coef1', 'coef2']'.
Friends And Related Function Documentation
◆ operator<<
|
friend |
Output shift operator.
- Parameters
-
os Output std::ostream.poly PolyModobject to be written.
- Returns
- Input
std::ostreampost writing.
- Note
- p2r and G are not serialized, see note of
operator>>.
The output stream will be formatted as a comma-separated list surrounded by '[' and ']'.
Each coefficient of poly will be serialized in an element of such list by the >> operator.
For example if we have a PolyMod object poly such that poly[0]=coef0, poly[1]=coef1, poly[2]=coef2, and poly[i]=0 for i>2, it will be serialized as '['coef0', 'coef1', 'coef2']'.
◆ operator>>
|
friend |
Input shift operator.
- Parameters
-
is Input std::istream.poly Destination PolyModobject.
- Returns
- Input
std::istreampost reading.
- Note
polymust be constructed with an appropriate p2r and G BEFORE calling this function. For example,PolyMod my_poly(p2r, G);std::cin >> my_poly;
The input stream has to be formatted as a comma-separated list surrounded by '[' and ']'.
Each element of the list will be deserialized as a coefficient of the polynomial.
If the number of tokens in the list is less than the number of coefficients, the higher-degree coefficients will be padded by 0.
For example '['coef0', 'coef1', 'coef2']' will be deserialized as a PolyMod object poly where poly[0]=coef0, poly[1]=coef1, poly[2]=coef2 and poly[i]=0 for i>2.
1.9.1