12 #ifndef HELIB_NUMBTH_H
13 #define HELIB_NUMBTH_H
32 #include <NTL/version.h>
36 #include <NTL/ZZ_pX.h>
37 #include <NTL/xdouble.h>
39 #include <NTL/mat_GF2.h>
40 #include <NTL/mat_GF2E.h>
41 #include <NTL/GF2XFactoring.h>
43 #include <NTL/mat_lzz_p.h>
44 #include <NTL/mat_lzz_pE.h>
45 #include <NTL/lzz_pXFactoring.h>
47 #include <NTL/GF2EX.h>
48 #include <NTL/lzz_pEX.h>
53 #if (NTL_MAJOR_VERSION < 11)
54 #error "This version of HElib requires NTL version 11.0.0 or above"
57 #include <helib/assertions.h>
58 #include <helib/apiAttributes.h>
62 extern const long double PI;
64 namespace FHEglobals {
135 long mcMod(
long a,
long b);
136 long mcDiv(
long a,
long b);
149 inline double fsquare(
double x) {
return x * x; }
162 void ppsolve(NTL::vec_zz_pE& x,
163 const NTL::mat_zz_pE& A,
164 const NTL::vec_zz_pE& b,
170 const NTL::mat_GF2E& A,
171 const NTL::vec_GF2E& b,
180 void ppInvert(NTL::mat_zz_p& X,
const NTL::mat_zz_p& A,
long p,
long r);
181 void ppInvert(NTL::mat_zz_pE& X,
const NTL::mat_zz_pE& A,
long p,
long r);
185 const NTL::mat_GF2& A,
193 const NTL::mat_GF2E& A,
211 const NTL::vec_zz_pE& L,
217 const NTL::vec_GF2E& L,
226 const NTL::vec_zz_pE& C,
227 const NTL::zz_pE& alpha,
232 const NTL::vec_GF2E& C,
233 const NTL::GF2E& alpha,
237 inline double log2(
const NTL::xdouble& x) {
return log(x) * 1.442695040889; }
241 void factorize(std::vector<long>& factors,
long N);
242 void factorize(std::vector<NTL::ZZ>& factors,
const NTL::ZZ& N);
246 void factorize(NTL::Vec<NTL::Pair<long, long>>& factors,
long N);
252 void phiN(
long&
phiN, std::vector<long>& facts,
long N);
253 void phiN(NTL::ZZ&
phiN, std::vector<NTL::ZZ>& facts,
const NTL::ZZ& N);
261 std::vector<long>& ords,
264 const std::vector<long>& candidates = std::vector<long>());
283 long ord(
long N,
long p);
287 long k = NTL::NextPowerOfTwo(m);
288 return (((
unsigned long)m) == (1UL << k));
298 NTL::ZZX
RandPoly(
long n,
const NTL::ZZ& p);
307 void PolyRed(NTL::ZZX& out,
const NTL::ZZX& in,
long q,
bool abs =
false);
313 inline void PolyRed(NTL::ZZX& F,
long q,
bool abs =
false)
318 inline void PolyRed(NTL::ZZX& F,
const NTL::ZZ& q,
bool abs =
false)
323 void vecRed(NTL::Vec<NTL::ZZ>& out,
324 const NTL::Vec<NTL::ZZ>& in,
328 void vecRed(NTL::Vec<NTL::ZZ>& out,
329 const NTL::Vec<NTL::ZZ>& in,
339 void MulMod(NTL::ZZX& out,
const NTL::ZZX& f,
long a,
long q,
bool abs);
341 [[deprecated(
"Please use MulMod with explicit abs argument.")]]
inline void
342 MulMod(NTL::ZZX& out,
const NTL::ZZX& f,
long a,
long q)
344 MulMod(out, f, a, q,
false);
347 inline NTL::ZZX
MulMod(
const NTL::ZZX& f,
long a,
long q,
bool abs)
350 MulMod(res, f, a, q, abs);
354 [[deprecated(
"Please use MulMod with explicit abs argument.")]]
inline NTL::ZZX
355 MulMod(
const NTL::ZZX& f,
long a,
long q)
358 MulMod(res, f, a, q,
false);
364 void balanced_MulMod(NTL::ZZX& out,
const NTL::ZZX& f,
long a,
long q);
368 inline void convert(
long& x1,
const NTL::GF2X& x2) { x1 = rep(ConstTerm(x2)); }
369 inline void convert(
long& x1,
const NTL::zz_pX& x2) { x1 = rep(ConstTerm(x2)); }
370 void convert(NTL::vec_zz_pE& X,
const std::vector<NTL::ZZX>& A);
371 void convert(NTL::mat_zz_pE& X,
const std::vector<std::vector<NTL::ZZX>>& A);
372 void convert(std::vector<NTL::ZZX>& X,
const NTL::vec_zz_pE& A);
373 void convert(std::vector<std::vector<NTL::ZZX>>& X,
const NTL::mat_zz_pE& A);
374 void convert(NTL::Vec<long>& out,
const NTL::ZZX& in);
376 void convert(NTL::Vec<long>& out,
const NTL::zz_pX& in,
bool symmetric =
false);
378 void convert(NTL::Vec<long>& out,
const NTL::GF2X& in);
379 void convert(NTL::ZZX& out,
const NTL::Vec<long>& in);
380 void convert(NTL::GF2X& out,
const NTL::Vec<long>& in);
387 template <
typename T1,
typename T2>
394 inline void convert(
long& x1,
bool x2) { x1 = x2; }
395 inline void convert(
double& x1,
bool x2) { x1 = x2; }
396 inline void convert(std::complex<double>& x1,
bool x2) { x1 = x2; }
397 inline void convert(std::complex<double>& x1,
long x2) { x1 = x2; }
398 inline void convert(std::complex<double>& x1,
double x2) { x1 = x2; }
400 inline void convert(NTL::ZZX& x1, NTL::GF2 x2) { x1 = rep(x2); }
401 inline void convert(NTL::ZZX& x1, NTL::zz_p x2) { x1 = rep(x2); }
404 template <
typename T1,
typename T2>
405 void convert(std::vector<T1>& v1,
const std::vector<T2>& v2)
409 for (
long i = 0; i < n; i++) {
413 convert(v1[i],
static_cast<const T2&
>(v2[i]));
417 template <
typename T1,
typename T2>
418 void convert(std::vector<T1>& v1,
const NTL::Vec<T2>& v2)
420 long n = v2.length();
422 for (
long i = 0; i < n; i++)
426 template <
typename T1,
typename T2>
427 void convert(NTL::Vec<T1>& v1,
const std::vector<T2>& v2)
431 for (
long i = 0; i < n; i++) {
435 convert(v1[i],
static_cast<const T2&
>(v2[i]));
440 template <
typename T>
441 void convert(std::vector<T>& v1,
const std::vector<T>& v2)
446 template <
typename T1,
typename T2>
454 template <
typename T>
459 for (
long i = 0; i < n; i++)
464 template <
typename T>
469 for (
long i = 0; i < n; i++)
476 const std::vector<std::complex<double>>& in)
480 for (
long i = 0; i < n; i++)
481 out[i] = in[i].real();
485 const std::vector<std::complex<double>>& in)
489 for (
long i = 0; i < n; i++)
490 out[i] = std::round(in[i].real());
498 void mul(std::vector<NTL::ZZX>& x,
const std::vector<NTL::ZZX>& a,
long b);
499 void div(std::vector<NTL::ZZX>& x,
const std::vector<NTL::ZZX>& a,
long b);
500 void add(std::vector<NTL::ZZX>& x,
501 const std::vector<NTL::ZZX>& a,
502 const std::vector<NTL::ZZX>& b);
506 long is_in(
long x,
int* X,
long sz);
510 inline long CRTcoeff(
long p,
long q,
bool symmetric =
false)
512 long pInv = NTL::InvMod(p, q);
513 if (symmetric && 2 * pInv >= q)
514 return p * (pInv - q);
533 template <
class zzvec>
534 bool intVecCRT(NTL::vec_ZZ& vp,
const NTL::ZZ& p,
const zzvec& vq,
long q);
546 template <
typename T,
bool maxFlag>
551 unsigned long idx = 0;
553 for (
unsigned long i = 1; i < v.size(); i++)
568 template <
typename T>
571 return argminmax<T, true>(v);
574 template <
typename T>
577 return argminmax<T, false>(v);
582 inline long argmax(std::vector<long>& v,
bool (*moreThan)(
long,
long))
586 unsigned long idx = 0;
588 for (
unsigned long i = 1; i < v.size(); i++)
589 if ((*moreThan)(v[i], target)) {
599 double pinv = 1.0 / p;
600 return (x < (1.0 + pinv) && x > (1 - pinv));
604 std::pair<long, long>
rationalApprox(
double x,
long denomBound = 0);
607 NTL::xdouble denomBound = NTL::xdouble(0.0));
636 RandomBits(state, 512);
661 template <
typename T>
662 void reverse(NTL::Vec<T>& v,
long lo,
long hi)
665 assertInRange(lo, 0l, hi,
"Invalid argument: Bad interval",
true);
666 assertTrue(hi < n,
"Invalid argument: Interval exceeds vector size");
671 for (
long i = lo, j = hi; i < j; i++, j--)
678 template <
typename T>
700 template <
typename T>
701 inline long lsize(
const std::vector<T>& v)
703 return (
long)v.size();
709 template <
typename T>
712 std::vector<T>().swap(vec);
715 template <
typename T>
722 template <
typename T>
726 vec.resize(0, vec[0]);
729 template <
typename T>
732 if (vec.length() > 0)
733 vec.SetLength(0, vec[0]);
736 template <
typename T>
737 inline long lsize(
const NTL::Vec<T>& v)
742 template <
typename T>
743 void resize(NTL::Vec<T>& v,
long sz,
const T& val)
745 return v.SetLength(sz, val);
748 template <
typename T>
749 void resize(std::vector<T>& v,
long sz,
const T& val)
751 return v.resize(sz, val);
754 template <
typename T>
757 return v.SetLength(sz);
760 template <
typename T>
768 template <
typename T1,
typename T2>
771 return dynamic_cast<const void*
>(p1) ==
dynamic_cast<const void*
>(p2);
781 long polyEvalMod(
const NTL::ZZX& poly,
long x,
long p);
786 const NTL::vec_long& x,
787 const NTL::vec_long& y,
792 inline long divc(
long a,
long b) {
return (a + b - 1) / b; }
809 NTL::zz_pXModulus
fm;
813 const NTL::zz_pXModulus&
upcast()
const {
return fm; }
816 void rem(NTL::zz_pX& r,
const NTL::zz_pX& a,
const zz_pXModulus1& ff);
823 const NTL::ZZ_pXModulus&
upcast()
const {
return *
this; }
826 template <
typename T>
833 for (
long i = 0; i < (long)v.size() - 1; i++)
835 return (s << v[v.size() - 1] <<
']');
838 template <
typename T>
847 template <
typename T>
850 std::stringstream ss;
855 template <
typename T>
860 std::stringstream ss(s);
865 template <
typename T>
868 NTL::Vec<T> v1 = atoVec<T>(a);
874 #ifndef NTL_PROVIDES_TRUNC_FFT
883 TofftRep(y, x, k, lo, hi);
898 template <
typename T>
901 static_assert(std::is_same<T, double>::value ||
902 std::is_same<T, std::complex<double>>::value,
903 "Error: type T is not double or std::complex<double>.");
906 template <
typename T>
909 AssertRealOrComplex<T>();
913 template <
typename T,
typename U>
916 AssertRealOrComplex<T>();
917 AssertRealOrComplex<U>();
918 return std::abs(x - y);
922 template <
typename T>
923 double Norm(
const std::vector<T>& x)
927 for (
long i = 0; i < n; i++)
928 res = std::max(res,
Norm(x[i]));
933 template <
typename T,
typename U>
934 double Distance(
const std::vector<T>& x,
const std::vector<U>& y)
936 assertTrue(x.size() == y.size(),
"Distance: mismatched vector sizes");
939 for (
long i = 0; i < n; i++)
940 res = std::max(res,
Distance(x[i], y[i]));
953 template <
typename T,
typename U>
954 inline bool approx_equal(
const T& x,
const U& y,
double tolerance,
double floor)
956 return Distance(x, y) <= tolerance * std::max(
Norm(y), floor);
977 template <
class T,
class U>
983 template <
class T,
class U>
1004 OptLong(
long _data) : data(_data), defined(true) {}
1008 operator long()
const {
return data; }
1015 template <
typename T,
typename P,
typename... Args>
1018 typename NTL::Lazy<T, P>::Builder builder(obj);
1021 NTL::UniquePtr<T, P> ptr;
1022 ptr.make(std::forward<Args>(args)...);
1029 template <
typename T,
typename P,
typename F,
typename... Args>
1032 typename NTL::Lazy<T, P>::Builder builder(obj);
1035 NTL::UniquePtr<T, P> ptr;
1037 f(*ptr, std::forward<Args>(args)...);
1045 0.6744897501960817432,
1046 1.1503493803760081782,
1047 1.5341205443525463117,
1048 1.8627318674216514554,
1049 2.1538746940614562129,
1050 2.4175590162365050618,
1051 2.6600674686174596585,
1052 2.8856349124267571473,
1053 3.0972690781987844623,
1054 3.2971933456919633418,
1055 3.4871041041144311068,
1056 3.6683292851213230192,
1057 3.8419306855019108708,
1058 4.0087725941685849622,
1059 4.1695693233491057549,
1060 4.3249190408260462571,
1061 4.4753284246542033544,
1062 4.6212310014992471565,
1063 4.7630010342678139569,
1064 4.9009642079631930118};
1066 #define ERFC_INVERSE_SIZE (long(sizeof(erfc_inverse) / sizeof(erfc_inverse[0])))
Represents the set of long int's plus a distinguished value that can be used to denote "undefined"....
Definition: NumbTh.h:998
OptLong()
Definition: NumbTh.h:1003
bool isDefined() const
Definition: NumbTh.h:1007
OptLong(long _data)
Definition: NumbTh.h:1004
Facility for "restoring" the NTL PRG state.
Definition: NumbTh.h:628
~RandomState()
Definition: NumbTh.h:649
void restore()
Restore the PRG state of NTL.
Definition: NumbTh.h:641
RandomState()
Definition: NumbTh.h:634
placeholder for pXModulus ...no optimizations
Definition: NumbTh.h:820
ZZ_pXModulus1(UNUSED long _m, const NTL::ZZ_pX &_f)
Definition: NumbTh.h:822
const NTL::ZZ_pXModulus & upcast() const
Definition: NumbTh.h:823
Auxiliary classes to facilitate faster reduction mod Phi_m(X) when the input has degree less than m.
Definition: NumbTh.h:798
NTL::zz_pX f
Definition: NumbTh.h:801
long n
Definition: NumbTh.h:802
NTL::zz_pXModulus fm
Definition: NumbTh.h:809
NTL::fftRep R0
Definition: NumbTh.h:807
NTL::fftRep R1
Definition: NumbTh.h:807
long k1
Definition: NumbTh.h:806
long k
Definition: NumbTh.h:806
const NTL::zz_pXModulus & upcast() const
Definition: NumbTh.h:813
zz_pXModulus1(long _m, const NTL::zz_pX &_f)
Definition: NumbTh.cpp:1738
bool specialLogic
Definition: NumbTh.h:804
long m
Definition: NumbTh.h:800
std::set< long > * automorphVals2
Definition: Ctxt.cpp:100
bool dryRun
A dry-run flag The dry-run option disables most operations, to save time. This lets us quickly go ove...
Definition: NumbTh.cpp:27
std::set< long > * automorphVals
A list of required automorphisms When non-nullptr, causes Ctxt::smartAutomorphism to just record the ...
Definition: Ctxt.cpp:99
Definition: apiAttributes.h:21
void balanced_MulMod(NTL::ZZX &out, const NTL::ZZX &f, long a, long q)
Definition: NumbTh.cpp:873
std::pair< long, long > rationalApprox(double x, long denomBound=0)
Definition: NumbTh.cpp:1598
void make_lazy_with_fun(const NTL::Lazy< T, P > &obj, F f, Args &&... args)
Definition: NumbTh.h:1030
void mul(const EncryptedArray &ea, PlaintextArray &pa, const PlaintextArray &other)
Definition: EncryptedArray.cpp:1612
void applyLinPoly(NTL::zz_pE &beta, const NTL::vec_zz_pE &C, const NTL::zz_pE &alpha, long p)
Apply a linearized polynomial with coefficient vector C.
Definition: NumbTh.cpp:1551
void seekPastChar(std::istream &str, int cc)
Advance the input stream beyond white spaces and a single instance of the char cc.
Definition: NumbTh.cpp:1069
NTL::Vec< T > atoVec(const char *a)
Definition: NumbTh.h:856
long polyEvalMod(const NTL::ZZX &poly, long x, long p)
Evaluates a modular integer polynomial, returns poly(x) mod p.
Definition: NumbTh.cpp:979
long is_in(long x, int *X, long sz)
Finds whether x is an element of the set X of size sz, Returns -1 it not and the location if true.
Definition: NumbTh.cpp:890
NTL::ZZX Cyclotomic(long N)
Compute cyclotomic polynomial.
Definition: NumbTh.cpp:531
double NextPow2(double x)
Compute next power of two in floating point NextPow2(x) returns 1 if x < 1, and otherwise returns 2^(...
Definition: NumbTh.cpp:1803
void setAutomorphVals(std::set< long > *aVals)
Definition: NumbTh.h:89
bool sameObject(const T1 *p1, const T2 *p2)
Testing if two vectors point to the same object.
Definition: NumbTh.h:769
std::vector< T > Vec_replicate(const T &a, long n)
Definition: NumbTh.h:465
void project_and_round(std::vector< long > &out, const std::vector< std::complex< double >> &in)
Definition: NumbTh.h:484
bool closeToOne(const NTL::xdouble &x, long p)
Definition: NumbTh.h:597
void killVec(std::vector< T > &vec)
NTL/std compatibility.
Definition: NumbTh.h:710
std::vector< T > vector_replicate(const T &a, long n)
Definition: NumbTh.h:455
long mcMod(long a, long b)
Routines for computing mathematically correct mod and div.
Definition: NumbTh.cpp:45
void pp_factorize(std::vector< long > &factors, long N)
Prime-power factorization.
Definition: NumbTh.cpp:203
void add(const EncryptedArray &ea, PlaintextArray &pa, const PlaintextArray &other)
Definition: EncryptedArray.cpp:1537
long argmin(std::vector< T > &v)
Definition: NumbTh.h:575
void make_lazy(const NTL::Lazy< T, P > &obj, Args &&... args)
Definition: NumbTh.h:1016
void recordAutomorphVal2(long k)
Definition: NumbTh.h:111
bool intVecCRT(NTL::vec_ZZ &vp, const NTL::ZZ &p, const zzvec &vq, long q)
Incremental integer CRT for vectors.
Definition: NumbTh.cpp:915
long mcDiv(long a, long b)
Definition: NumbTh.cpp:55
void buildLinPolyCoeffs(NTL::vec_zz_pE &C, const NTL::vec_zz_pE &L, long p, long r)
Combination of buildLinPolyMatrix and ppsolve.
Definition: NumbTh.cpp:1511
bool is2power(long m)
Definition: NumbTh.h:285
long findGenerators(std::vector< long > &gens, std::vector< long > &ords, long m, long p, const std::vector< long > &candidates=std::vector< long >())
Definition: NumbTh.cpp:342
void ppInvert(NTL::mat_zz_p &X, const NTL::mat_zz_p &A, long p, long r)
Compute the inverse mod p^r of an n x n matrix.
Definition: NumbTh.cpp:1455
void recordAutomorphVal(long k)
Definition: NumbTh.h:99
void buildLinPolyMatrix(NTL::mat_zz_pE &M, long p)
Definition: NumbTh.cpp:1096
std::istream & operator>>(std::istream &s, CtxtPart &p)
Definition: Ctxt.cpp:2762
long ord(long N, long p)
Compute the highest power of p that divides N.
Definition: NumbTh.cpp:697
void convert(long &x1, const NTL::GF2X &x2)
Definition: NumbTh.h:368
void factorize(std::vector< long > &factors, long N)
Factoring by trial division, only works for N<2^{60}, only the primes are recorded,...
Definition: NumbTh.cpp:155
void reverse(NTL::Vec< T > &v, long lo, long hi)
Reverse a vector in place.
Definition: NumbTh.h:662
void assertInRange(const T &elem, const T &min, const T &max, const std::string &message, bool right_inclusive=false)
Definition: assertions.h:183
bool approx_equal(const T &x, const U &y, double tolerance, double floor)
Definition: NumbTh.h:954
void setAutomorphVals2(std::set< long > *aVals)
Definition: NumbTh.h:101
void MulMod(NTL::ZZX &out, const NTL::ZZX &f, long a, long q, bool abs)
Definition: NumbTh.cpp:852
long phi_N(long N)
Compute Phi(N).
Definition: NumbTh.cpp:235
long multOrd(long p, long m)
Return multiplicative order of p modulo m, or 0 if GCD(p, m) != 1.
Definition: NumbTh.cpp:68
long computeProd(const NTL::Vec< long > &vec)
returns \prod_d vec[d]
Definition: NumbTh.cpp:92
void div(std::vector< NTL::ZZX > &x, const std::vector< NTL::ZZX > &a, long b)
Definition: NumbTh.cpp:1227
void AssertRealOrComplex()
Definition: NumbTh.h:899
long primroot(long N, long phiN)
Find a primitive root modulo N.
Definition: NumbTh.cpp:673
bool operator==(const PtxtArray &a, const PtxtArray &b)
Definition: EncryptedArray.h:2426
void vecRed(NTL::Vec< NTL::ZZ > &out, const NTL::Vec< NTL::ZZ > &in, long q, bool abs)
Definition: NumbTh.cpp:802
void FindPrimitiveRoot(NTL::zz_p &r, unsigned long e)
Find e-th root of unity modulo the current modulus.
Definition: NumbTh.cpp:492
void interpolateMod(NTL::ZZX &poly, const NTL::vec_long &x, const NTL::vec_long &y, long p, long e=1)
Interpolate polynomial such that poly(x[i] mod p)=y[i] (mod p^e) It is assumed that the points x[i] a...
Definition: NumbTh.cpp:1040
const long double PI
Definition: NumbTh.cpp:24
bool isDryRun()
Definition: NumbTh.h:87
double Distance(const EncryptedArray &ea, const PlaintextArray &pa, const PlaintextArray &other)
Definition: EncryptedArray.cpp:1943
std::string vecToStr(const std::vector< T > &v)
Definition: NumbTh.h:848
long argminmax(std::vector< T > &v)
Find the index of the (first) largest/smallest element.
Definition: NumbTh.h:547
void TofftRep_trunc(NTL::fftRep &y, const NTL::zz_pX &x, long k, UNUSED long len, long lo, long hi)
Definition: NumbTh.h:876
const double erfc_inverse[]
Definition: NumbTh.h:1044
double log2(const NTL::xdouble &x)
Base-2 logarithm.
Definition: NumbTh.h:237
double RandomReal()
returns a pseudo-random number in uniform in [0, 1)
Definition: NumbTh.cpp:707
void rotate(Ctxt &ctxt, long k)
Definition: EncryptedArray.h:1969
bool isSetAutomorphVals()
Definition: NumbTh.h:94
void assertTrue(const T &value, const std::string &message)
Definition: assertions.h:61
void ppsolve(NTL::vec_zz_pE &x, const NTL::mat_zz_pE &A, const NTL::vec_zz_pE &b, long p, long r)
Prime power solver.
Definition: NumbTh.cpp:1251
std::vector< T > atovector(const char *a)
Definition: NumbTh.h:866
std::ostream & operator<<(std::ostream &os, const ContextBuilder< SCHEME > &cb)
ostream operator for serializing the ContextBuilder object.
NTL::ZZX RandPoly(long n, const NTL::ZZ &p)
Definition: NumbTh.cpp:728
long mobius(long n)
Compute mobius function (naive method as n is small).
Definition: NumbTh.cpp:502
void resize(NTL::Vec< T > &v, long sz, const T &val)
Definition: NumbTh.h:743
long LONG
Definition: NumbTh.h:116
void ModComp(NTL::ZZX &res, const NTL::ZZX &g, const NTL::ZZX &h, const NTL::ZZX &f)
Modular composition of polynomials: res = g(h) mod f.
Definition: NumbTh.cpp:961
long divc(long a, long b)
returns ceiling(a/b); assumes a >=0, b>0, a+b <= MAX_LONG
Definition: NumbTh.h:792
double fsquare(double x)
Return the square of a number as a double.
Definition: NumbTh.h:149
std::complex< double > RandomComplex()
returns a pseudo-random number comomlex number z with |z| < 1
Definition: NumbTh.cpp:718
NTL::ZZX makeIrredPoly(long p, long d)
Return a degree-d irreducible polynomial mod p.
Definition: NumbTh.cpp:102
void phiN(long &phiN, std::vector< long > &facts, long N)
Compute Phi(N) and also factorize N.
Definition: NumbTh.cpp:228
void setLengthZero(std::vector< T > &vec)
Definition: NumbTh.h:723
long argmax(std::vector< T > &v)
Definition: NumbTh.h:569
long lsize(const std::vector< T > &v)
Size of STL vector as a long (rather than unsigned long)
Definition: NumbTh.h:701
void PolyRed(NTL::ZZX &out, const NTL::ZZX &in, long q, bool abs=false)
Reduce all the coefficients of a polynomial modulo q.
Definition: NumbTh.cpp:772
long balRem(long a, long q)
Definition: NumbTh.h:140
ApproxClass< T > Approx(const T &val, double tolerance=0.01, double floor=1.0)
Definition: NumbTh.h:972
long bitSetToLong(long bits, long bitSize)
Considers bits as a vector of bits and returns the value it represents when interpreted as a n-bit 2'...
Definition: NumbTh.cpp:32
void project(std::vector< double > &out, const std::vector< std::complex< double >> &in)
Definition: NumbTh.h:475
void rem(NTL::zz_pX &r, const NTL::zz_pX &a, const zz_pXModulus1 &ff)
Definition: NumbTh.cpp:1764
bool operator!=(const PtxtArray &a, const PtxtArray &b)
Definition: EncryptedArray.h:2432
bool setDryRun(bool toWhat=true)
Definition: NumbTh.h:82
double Norm(const EncryptedArray &ea, const PlaintextArray &pa)
Definition: EncryptedArray.cpp:1936
long CRTcoeff(long p, long q, bool symmetric=false)
Returns a CRT coefficient: x = (0 mod p, 1 mod q). If symmetric is set then x \in [-pq/2,...
Definition: NumbTh.h:510
bool isSetAutomorphVals2()
Definition: NumbTh.h:106
ApproxClass(const T &val_, double tolerance_, double floor_)
Definition: NumbTh.h:966
const T & val
Definition: NumbTh.h:962
double floor
Definition: NumbTh.h:964
double tolerance
Definition: NumbTh.h:963