Please provide a complete example (minimum working example). It is not clear what paramPK is set to. If the starting modulus in paramsPK is too small (so that multiplying by 17 wraps around the modulus used there), then you can easily get non-zero values.
Another question, what are you actually trying to do?
I tried to change to use discrete uniform, but I guess I am missing on how is the DCRT polynomial representation, since it is a lot of big values. I am only trying to learn the library but got confused with both polynomial representations I guess.
How can I multiply the full polynomial by a value? I want to multiply a small poly (sampled by a gaussian) by a small number, I tried sampling with ternary as well and gives me wrong values. Only binary and other pp`s worked for now. For ternary, I don’t know why the values are 5, they should be 4 if the modulus operation is not balanced.
The main problem is that the sampler is centered on 0 but the operations (at least Times) are not using balanced modulo, do we have a workaround for this? If you have a polynomial (-x2 + x%101)*3, it should be (-3x2 + 3x)%101 and not (98x**2 + 3x)%101
Here is a properly working example. There were a couple of errors. First, dug (random number mod) was used instead of dgg. Second, ToNativePoly() was called, which is used for a different purpose. Now the result is all 0’s.
#include "openfhe.h"
#include "openfhecore.h"
using namespace lbcrypto;
int main() {
CCParams<CryptoContextBFVRNS> parameters;
parameters.SetPlaintextModulus(65537);
parameters.SetMultiplicativeDepth(2);
CryptoContext<DCRTPoly> cryptoContext = GenCryptoContext(parameters);
const auto cryptoParams = cryptoContext->GetCryptoParameters();
const auto paramsPK = cryptoParams->GetParamsPK();
std::cout << "ParamsPK:" << paramsPK->GetParams()[0]->GetModulus() << std::endl;
// this code generates random numbers between 0 and modulus - 1
// DCRTPoly::DugType dug;
DCRTPoly::DggType dgg(3.19);
int pp = 17;
DCRTPoly gg(dgg, paramsPK, Format::EVALUATION);
gg.SetFormat(Format::COEFFICIENT);
std::cout << "gg: " << gg << std::endl;
auto ggg = gg.Times(pp);
std::cout << "ggg: " << ggg << std::endl;
auto gggg = ggg.GetAllElements()[0];
std::cout << "gggg: " << gggg << std::endl;
gggg.SwitchModulus(pp, 1, 0, 0);
std::cout << "gggg: " << gggg << std::endl;
return 0;
}