30 #include <NTL/lzz_pX.h>
53 virtual void init(zz_pX& v) {
54 v.rep.SetMaxLength(val);
93 void apply(zz_pX& a,
const zz_pX& b,
const zz_pXModulus& f)
94 {
return add(a, a, b); }
96 void apply(zz_pX& a, zz_p b)
97 {
return add(a, a, b); }
102 void apply(zz_pX& a,
const zz_pX& b,
const zz_pXModulus& f)
103 {
return sub(a, a, b); }
105 void apply(zz_pX& a, zz_p b)
106 {
return sub(a, a, b); }
111 void apply(zz_pX& a,
const zz_pX& b,
const zz_pXModulus& f)
112 {
return MulMod(a, a, b, f); }
114 void apply(zz_pX& a, zz_p b)
115 {
return mul(a, a, b); }
121 bool matchIndexSets=
true);
124 AltCRT& Op(
const ZZ &num, Fun fun);
127 AltCRT& Op(
const ZZX &poly, Fun fun);
153 explicit AltCRT(
const ZZX&poly);
170 AltCRT& operator=(
const ZZX& poly);
171 AltCRT& operator=(
const ZZ& num);
172 AltCRT& operator=(
const long num) { *
this = to_ZZ(num);
return *
this; }
175 void toPoly(ZZX& p,
bool positive=
false)
const;
183 void toPoly(ZZX& p,
const IndexSet& s,
bool positive=
false)
const;
193 bool operator==(
const AltCRT& other)
const {
194 assert(&context == &other.context);
195 return map == other.map;
198 bool operator!=(
const AltCRT& other)
const {
199 return !(*
this==other);
239 AltCRT& Negate() {
return Negate(*
this); }
242 return Op(other, AddFun());
245 AltCRT& operator+=(
const ZZX &poly) {
246 return Op(poly, AddFun());
249 AltCRT& operator+=(
const ZZ &num) {
250 return Op(num, AddFun());
253 AltCRT& operator+=(
long num) {
254 return Op(to_ZZ(num), AddFun());
258 return Op(other,SubFun());
261 AltCRT& operator-=(
const ZZX &poly) {
262 return Op(poly,SubFun());
265 AltCRT& operator-=(
const ZZ &num) {
266 return Op(num, SubFun());
269 AltCRT& operator-=(
long num) {
270 return Op(to_ZZ(num), SubFun());
274 AltCRT& operator++() {
return (*
this += 1); };
275 AltCRT& operator--() {
return (*
this -= 1); };
279 void operator++(
int) { *
this += 1; };
280 void operator--(
int) { *
this -= 1; };
285 return Op(other,MulFun());
288 AltCRT& operator*=(
const ZZX &poly) {
289 return Op(poly,MulFun());
292 AltCRT& operator*=(
const ZZ &num) {
293 return Op(num,MulFun());
296 AltCRT& operator*=(
long num) {
297 return Op(to_ZZ(num),MulFun());
302 void Add(
const AltCRT &other,
bool matchIndexSets=
true) {
303 Op(other, AddFun(), matchIndexSets);
306 void Sub(
const AltCRT &other,
bool matchIndexSets=
true) {
307 Op(other, SubFun(), matchIndexSets);
310 void Mul(
const AltCRT &other,
bool matchIndexSets=
true) {
311 Op(other, MulFun(), matchIndexSets);
315 AltCRT& operator/=(
const ZZ &num);
316 AltCRT& operator/=(
long num) {
return (*
this /= to_ZZ(num)); }
324 void automorph(
long k);
325 AltCRT& operator>>=(
long k) { automorph(k);
return *
this; }
330 const FHEcontext& getContext()
const {
return context; }
356 if (stdev==0.0) stdev=to_double(context.
stdev);
369 void scaleDownToSet(
const IndexSet& s,
long ptxtSpace);
374 friend ostream& operator<< (ostream &s,
const AltCRT &d);
375 friend istream& operator>> (istream &s,
AltCRT &d);
381 static bool setDryRun(
bool toWhat=
true) { dryRun=toWhat;
return dryRun; }
385 inline void conv(
AltCRT &d,
const ZZX &p) { d=p; }
387 inline AltCRT to_AltCRT(
const ZZX& p) {
391 inline void conv(ZZX &p,
const AltCRT &d) { d.
toPoly(p); }
393 inline ZZX to_ZZX(
const AltCRT &d) { ZZX p; d.
toPoly(p);
return p; }