Search Results

1 /* Copyright (C) 2012-2020 IBM Corp.
2  * This program is Licensed under the Apache License, Version 2.0
3  * (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://www.apache.org/licenses/LICENSE-2.0
6  * Unless required by applicable law or agreed to in writing, software
7  * distributed under the License is distributed on an "AS IS" BASIS,
8  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9  * See the License for the specific language governing permissions and
10  * limitations under the License. See accompanying LICENSE file.
11  */
12 #ifndef HELIB_SAMPLE_H
13 #define HELIB_SAMPLE_H
14 
17 #include <vector>
18 #include <NTL/xdouble.h>
19 #include <NTL/ZZX.h>
20 #include <NTL/ZZ_pX.h>
21 #include <helib/zzX.h>
22 
23 namespace helib {
24 
28 void sampleSmall(zzX& poly, long n, double prob = 0.5);
29 void sampleSmall(NTL::ZZX& poly, long n, double prob = 0.5);
30 
32 void sampleHWt(zzX& poly, long n, long Hwt = 100);
33 void sampleHWt(NTL::ZZX& poly, long n, long Hwt = 100);
34 
36 void sampleGaussian(zzX& poly, long n, double stdev);
37 void sampleGaussian(NTL::ZZX& poly, long n, double stdev);
38 
40 void sampleUniform(zzX& poly, long n, long B = 100);
41 void sampleUniform(NTL::ZZX& poly, long n, const NTL::ZZ& B = NTL::ZZ(100L));
42 
44 void sampleGaussian(std::vector<double>& dvec, long n, double stdev);
45 
46 class Context;
47 class PAlgebra;
48 // Same as above, but sample mod X^m-1 and then reduce mod Phi_m(X)
49 double sampleHWt(zzX& poly, const Context& context, long Hwt = 100);
50 double sampleHWtBounded(zzX& poly, const Context& context, long Hwt = 100);
51 
52 double sampleHWtBoundedEffectiveBound(const Context& context, long Hwt = 100);
53 // This just returns the effective bound used by sampleHWt bounded
54 
55 // Return value is high-probability bound on L-infty norm of canonical embedding
56 double sampleSmall(zzX& poly, const Context& context);
57 // Same as above, but ensure the result is not too much larger than typical
58 double sampleSmallBounded(zzX& poly, const Context& context);
59 
60 // Return value is high-probability bound on L-infty norm of canonical embedding
61 double sampleGaussian(zzX& poly, const Context& context, double stdev);
62 // Same as above, but ensure the result is not too much larger than typical
63 double sampleGaussianBounded(zzX& poly, const Context& context, double stdev);
64 
65 double sampleUniform(zzX& poly, const Context& context, long B = 100);
66 NTL::xdouble sampleUniform(NTL::ZZX& poly,
67  const Context& context,
68  const NTL::ZZ& B = NTL::ZZ(100L));
69 
74 double boundFreshNoise(long m, long phim, double sigma, double epsilon = 9e-13);
75 double boundRoundingNoise(long m, long phim, long p2r, double epsilon = 9e-13);
77 
78 void reduceModPhimX(zzX& poly, const PAlgebra& palg);
79 const NTL::zz_pXModulus& getPhimXMod(const PAlgebra& palg);
80 
81 } // namespace helib
82 
83 #endif // ifndef HELIB_SAMPLE_H
double sampleHWtBoundedEffectiveBound(const Context &context, long Hwt=100)
Definition: sample.cpp:255
NTL::Vec< long > zzX
Definition: zzX.h:24
double sampleGaussianBounded(zzX &poly, const Context &context, double stdev)
Definition: sample.cpp:417
double sampleSmallBounded(zzX &poly, const Context &context)
Definition: sample.cpp:342
void sampleSmall(zzX &poly, long n, double prob=0.5)
Definition: sample.cpp:67
The structure of (Z/mZ)* /(p)
Definition: PAlgebra.h:77
double sampleHWtBounded(zzX &poly, const Context &context, long Hwt=100)
Definition: sample.cpp:269
void sampleGaussian(zzX &poly, long n, double stdev)
Sample polynomials with Gaussian coefficients.
Definition: sample.cpp:143
void sampleUniform(zzX &poly, long n, long B=100)
Sample a degree-(n-1) ZZX, with coefficients uniform in [-B,B].
Definition: sample.cpp:199
void reduceModPhimX(zzX &poly, const PAlgebra &palg)
Definition: zzX.cpp:111
Definition: apiAttributes.h:21
double boundFreshNoise(long m, long phim, double sigma, double epsilon=9e-13)
Definition: sample.cpp:519
double boundRoundingNoise(long m, long phim, long p2r, double epsilon=9e-13)
const NTL::zz_pXModulus & getPhimXMod(const PAlgebra &palg)
Definition: zzX.cpp:79
void sampleHWt(zzX &poly, long n, long Hwt=100)
Sample a degree-(n-1) poly as above, with only Hwt nonzero coefficients.
Definition: sample.cpp:29