21 #if 0 // change to #if 1 to get an alternative implementation
23 #define DoubleCRT AltCRT
31 #include <NTL/vec_vec_long.h>
55 virtual void init(vec_long& v) {
105 long apply(
long a,
long b,
long n) {
return AddMod(a, b, n); }
110 long apply(
long a,
long b,
long n) {
return SubMod(a, b, n); }
115 long apply(
long a,
long b,
long n) {
return MulMod(a, b, n); }
121 bool matchIndexSets=
true);
174 DoubleCRT& operator=(
const long num) { *
this = to_ZZ(num);
return *
this; }
182 void toPoly(ZZX& p,
const IndexSet& s,
bool positive=
false)
const;
183 void toPoly(ZZX& p,
bool positive=
false)
const;
193 bool operator==(
const DoubleCRT& other)
const {
194 assert(&context == &other.context);
195 return map == other.map;
198 bool operator!=(
const DoubleCRT& other)
const {
199 return !(*
this==other);
241 DoubleCRT& Negate() {
return Negate(*
this); }
244 return Op(other, AddFun());
248 return Op(poly, AddFun());
252 return Op(num, AddFun());
256 return Op(to_ZZ(num), AddFun());
260 return Op(other,SubFun());
264 return Op(poly,SubFun());
268 return Op(num, SubFun());
272 return Op(to_ZZ(num), SubFun());
276 DoubleCRT& operator++() {
return (*
this += 1); };
277 DoubleCRT& operator--() {
return (*
this -= 1); };
281 void operator++(
int) { *
this += 1; };
282 void operator--(
int) { *
this -= 1; };
287 return Op(other,MulFun());
291 return Op(poly,MulFun());
295 return Op(num,MulFun());
299 return Op(to_ZZ(num),MulFun());
304 void Add(
const DoubleCRT &other,
bool matchIndexSets=
true) {
305 Op(other, AddFun(), matchIndexSets);
308 void Sub(
const DoubleCRT &other,
bool matchIndexSets=
true) {
309 Op(other, SubFun(), matchIndexSets);
312 void Mul(
const DoubleCRT &other,
bool matchIndexSets=
true) {
313 Op(other, MulFun(), matchIndexSets);
318 DoubleCRT& operator/=(
long num) {
return (*
this /= to_ZZ(num)); }
324 void automorph(
long k);
325 DoubleCRT& 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 DoubleCRT &d);
375 friend istream& operator>> (istream &s,
DoubleCRT &d);
381 static bool setDryRun(
bool toWhat=
true) { dryRun=toWhat;
return dryRun; }
387 inline void conv(
DoubleCRT &d,
const ZZX &p) { d=p; }
389 inline DoubleCRT to_DoubleCRT(
const ZZX& p) {
395 inline ZZX to_ZZX(
const DoubleCRT &d) { ZZX p; d.
toPoly(p);
return p; }
400 #endif // #ifndef _DoubleCRT_H_
402 #endif // DoubleCRT or AltCRT