12 #ifndef HELIB_POWERFUL_H
13 #define HELIB_POWERFUL_H
18 #include <helib/NumbTh.h>
19 #include <helib/ClonedPtr.h>
20 #include <helib/bluestein.h>
21 #include <helib/hypercube.h>
22 #include <helib/DoubleCRT.h>
23 #include <helib/Context.h>
86 NTL::zz_pContext zzpContext;
87 NTL::Vec<NTL::zz_pXModulus> cycVec_p;
88 NTL::zz_pXModulus phimX_p;
101 if (indexes !=
nullptr)
105 cycVec_p.SetLength(ind.
cycVec.length());
107 for (
long i = 0; i < ind.
cycVec.length(); i++) {
109 NTL::conv<NTL::zz_pX>(ind.
cycVec[i]);
111 phimX_p = NTL::conv<NTL::zz_pX>(ind.
phimX);
123 const NTL::zz_pX& poly)
const;
137 NTL::Vec<PowerfulConversion> pConvVec;
140 NTL::Vec<long> product_bits;
143 long to_pwfl_excess_bits;
144 long to_poly_excess_bits;
161 void ZZXtoPowerful(NTL::Vec<NTL::ZZ>& powerful,
const NTL::ZZX& poly)
const;
162 void powerfulToZZX(NTL::ZZX& poly,
const NTL::Vec<NTL::ZZ>& powerful)
const;
171 long computeProd(
const Vec< Pair<long, long> >& vec);
174 inline long computePhi(
const Pair<long, long>& x)
178 return power_long(p, e - 1) * (p-1);
183 void computePhiVec(Vec<long>& phiVec,
184 const Vec< Pair<long, long> >& factors);
189 const Vec<long>& powVec);
194 const Vec<long>& divVec,
const Vec<long>& powVec);
202 void computeShortToLongMap(Vec<long>& shortToLongMap,
203 const CubeSignature& shortSig,
204 const CubeSignature& longSig);
208 void computeLongToShortMap(Vec<long>& longToShortMap,
210 const Vec<long>& shortToLongMap);
219 void recursiveReduce(
const CubeSlice<zz_p>& s,
220 const Vec<zz_pXModulus>& cycVec,
231 void convertPolyToPowerful(HyperCube<zz_p>& cube,
232 HyperCube<zz_p>& tmpCube,
234 const Vec<zz_pXModulus>& cycVec,
235 const Vec<long>& polyToCubeMap,
236 const Vec<long>& shortToLongMap);
239 void convertPowerfulToPoly(zz_pX& poly,
240 const HyperCube<zz_p>& cube,
242 const Vec<long>& shortToLongMap,
243 const Vec<long>& cubeToPolyMap,
244 const zz_pXModulus& phimX);
249 inline long computePow(
const Pair<long, long>& x)
253 return power_long(p, e);
257 void computePowVec(Vec<long>& powVec,
258 const Vec< Pair<long, long> >& factors);
262 void mapIndexToPowerful(Vec<long>& pow,
long j,
const Vec<long>& phiVec);
265 void computeCycVec(Vec<zz_pXModulus>& cycVec,
const Vec<long>& powVec);
277 void computePowerToCubeMap(Vec<long>& polyToCubeMap,
278 Vec<long>& cubeToPolyMap,
280 const Vec<long>& powVec,
281 const Vec<long>& invVec,
282 const CubeSignature& longSig);
287 void computeMultiEvalPoints(Vec< Vec<zz_p> >& multiEvalPoints,
290 const Vec<long>& powVec,
291 const Vec<long>& phiVec);
294 void computeLinearEvalPoints(Vec<zz_p>& linearEvalPoints,
303 void computeCompressedIndex(Vec< Vec<long> >& compressedIndex,
304 const Vec<long>& powVec);
310 void computePowToCompressedIndexMap(Vec<long>& powToCompressedIndexMap,
312 const Vec<long>& powVec,
313 const Vec< Vec<long> >& compressedIndex,
314 const CubeSignature& shortSig);
316 void recursiveEval(
const CubeSlice<zz_p>& s,
317 const Vec< Vec<zz_p> >& multiEvalPoints,
322 inline void eval(HyperCube<zz_p>& cube,
323 const Vec< Vec<zz_p> >& multiEvalPoints)
328 recursiveEval(CubeSlice<zz_p>(cube), multiEvalPoints, 0, tmp1, tmp2);
331 void mapPowerfulToPoly(ZZX& poly,
332 const Vec<long>& pow,
333 const Vec<long>& divVec,
360 mutable zz_pX powers, ipowers;
361 mutable Vec<mulmod_precon_t> powers_aux, ipowers_aux;
362 mutable fftRep Rb, iRb;
363 mutable fftrep_aux Rb_aux, iRb_aux;
368 FFTHelper(
long _m, zz_p x);
370 void FFT(
const zz_pX& f, Vec<zz_p>& v)
const;
372 void iFFT(zz_pX& f,
const Vec<zz_p>& v,
bool normalize =
true)
const;
375 const zz_p& get_m_inv()
const {
return m_inv; }
383 void computeMultiEvalPoints(Vec< CopiedPtr<FFTHelper> >& multiEvalPoints,
386 const Vec<long>& powVec,
387 const Vec<long>& phiVec);
389 void recursiveEval(
const CubeSlice<zz_p>& s,
390 const Vec< CopiedPtr<FFTHelper> >& multiEvalPoints,
395 inline void eval(HyperCube<zz_p>& cube,
396 const Vec< CopiedPtr<FFTHelper> >& multiEvalPoints)
401 recursiveEval(CubeSlice<zz_p>(cube), multiEvalPoints, 0, tmp1, tmp2);
404 void recursiveInterp(
const CubeSlice<zz_p>& s,
405 const Vec< CopiedPtr<FFTHelper> >& multiEvalPoints,
410 void interp(HyperCube<zz_p>& cube,
411 const Vec< CopiedPtr<FFTHelper> >& multiEvalPoints);
Maintaining the HE scheme parameters.
Definition: Context.h:100
Holds a vector of dimensions for a hypercube and some additional data.
Definition: hypercube.h:28
Implementing polynomials (elements in the ring R_Q) in double-CRT form.
Definition: DoubleCRT.h:76
A multi-dimensional cube.
Definition: hypercube.h:221
Conversion between powerful representation in R_m/(q) and zz_pX.
Definition: powerful.h:84
PowerfulConversion()
Definition: powerful.h:91
void restoreModulus() const
Definition: powerful.h:114
void initPConv(const PowerfulTranslationIndexes &ind)
Definition: powerful.h:99
PowerfulConversion(const PowerfulTranslationIndexes &ind)
Definition: powerful.h:93
const CubeSignature & getShortSig() const
Definition: powerful.h:116
long polyToPowerful(HyperCube< NTL::zz_p > &powerful, const NTL::zz_pX &poly) const
Definition: powerful.cpp:199
const CubeSignature & getLongSig() const
Definition: powerful.h:115
long powerfulToPoly(NTL::zz_pX &poly, const HyperCube< NTL::zz_p > &powerful) const
Definition: powerful.cpp:223
Conversion between powerful representation, DoubleCRT, and ZZX.
Definition: powerful.h:131
void ZZXtoPowerful(NTL::Vec< NTL::ZZ > &powerful, const NTL::ZZX &poly) const
Definition: powerful.cpp:309
const PowerfulConversion & getPConv(long i) const
Definition: powerful.h:155
void powerfulToZZX(NTL::ZZX &poly, const NTL::Vec< NTL::ZZ > &powerful) const
Definition: powerful.cpp:354
const PowerfulTranslationIndexes & getIndexTranslation() const
Definition: powerful.h:151
PowerfulDCRT(const Context &_context, const NTL::Vec< long > &mvec)
Definition: powerful.cpp:246
void dcrtToPowerful(NTL::Vec< NTL::ZZ > &powerful, const DoubleCRT &dcrt) const
Definition: powerful.cpp:393
Holds index tables for translation between powerful and zz_pX.
Definition: powerful.h:30
NTL::Vec< long > cubeToPolyMap
Definition: powerful.h:43
NTL::Vec< long > mvec
Definition: powerful.h:34
NTL::Vec< long > shortToLongMap
Definition: powerful.h:44
CubeSignature shortSig
Definition: powerful.h:40
NTL::Vec< long > phivec
Definition: powerful.h:35
NTL::Vec< long > invvec
Definition: powerful.h:37
NTL::Vec< long > polyToCubeMap
Definition: powerful.h:42
NTL::Vec< long > divvec
Definition: powerful.h:36
CubeSignature longSig
Definition: powerful.h:39
PowerfulTranslationIndexes(const NTL::Vec< long > &mv)
Definition: powerful.cpp:152
NTL::ZZX phimX
Definition: powerful.h:47
long phim
Definition: powerful.h:33
NTL::Vec< NTL::ZZX > cycVec
Definition: powerful.h:46
long m
Definition: powerful.h:32
Definition: apiAttributes.h:21
void computeDivVec(NTL::Vec< long > &divVec, long m, const NTL::Vec< long > &powVec)
Definition: powerful.cpp:22
long computeProd(const NTL::Vec< long > &vec)
returns \prod_d vec[d]
Definition: NumbTh.cpp:92
void computeInvVec(NTL::Vec< long > &invVec, const NTL::Vec< long > &divVec, const NTL::Vec< long > &powVec)
Definition: powerful.cpp:35
void normalize(zzX &f)
Definition: zzX.cpp:65