# InnerProduct question

**URL:** https://openfhe.discourse.group/t/innerproduct-question/1966
**Category:** Library Questions
**Tags:** openfhe-help, questions
**Created:** [March 28, 2025, 11:44am UTC](https://openfhe.discourse.group/t/innerproduct-question/1966 "2025-03-28T11:44:51Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![wowblk8](https://avatars.discourse-cdn.com/v4/letter/w/e79b87/32.png) [@wowblk8](https://openfhe.discourse.group/u/wowblk8)
#### Post date: [March 28, 2025, 11:44am UTC](https://openfhe.discourse.group/t/innerproduct-question/1966/1 "2025-03-28T11:44:51Z")

</div>

Hi openfhe team!

I would like to know how to determine whether my inner product operation is correct based on the given parameters, ensuring that the calculation results are accurate. Currently, with the given parameter, the results start to become incorrect at around 200values. How to accurately determine the boundary value that this parameter can support?

```c++
 bool innerProductBFV(std::vector<int64_t>& incomingVector) {
     int64_t expectedResult = plainInnerProduct(incomingVector);
     /////////////////////////////////////////////////////////
     // Crypto CryptoParams
     /////////////////////////////////////////////////////////
     CCParams<CryptoContextBFVRNS> parameters;
     parameters.SetPlaintextModulus(65537);
     parameters.SetMultiplicativeDepth(20);
     parameters.SetSecurityLevel(lbcrypto::HEStd_NotSet);
     parameters.SetRingDim(1 << 7);
     uint32_t batchSize = parameters.GetRingDim() / 2;
 
     /////////////////////////////////////////////////////////
     // Set crypto params and create context
     /////////////////////////////////////////////////////////
     lbcrypto::CryptoContext<lbcrypto::DCRTPoly> cc;
     cc = GenCryptoContext(parameters);
 
     // Enable the features that you wish to use.
     cc->Enable(PKE);
     cc->Enable(LEVELEDSHE);
     cc->Enable(ADVANCEDSHE);
 
     KeyPair keys = cc->KeyGen();
     cc->EvalMultKeyGen(keys.secretKey);
     cc->EvalSumKeyGen(keys.secretKey);
 
     Plaintext plaintext1 = cc->MakePackedPlaintext(incomingVector);
     auto ct1 = cc->Encrypt(keys.publicKey, plaintext1);
     auto finalResult = cc->EvalInnerProduct(ct1, ct1, batchSize);
     lbcrypto::Plaintext res;
     cc->Decrypt(keys.secretKey, finalResult, &res);
     auto final = res->GetPackedValue()[0];
 
     std::cout << "Expected Result: " << expectedResult << " Inner Product Result: " << final << std::endl;
     return expectedResult == final;
 }

```

---

<div class="post-metadata">

### Author: ![wowblk8](https://avatars.discourse-cdn.com/v4/letter/w/e79b87/32.png) [@wowblk8](https://openfhe.discourse.group/u/wowblk8)
#### Post date: [March 28, 2025, 11:50am UTC](https://openfhe.discourse.group/t/innerproduct-question/1966/2 "2025-03-28T11:50:11Z")

</div>

Like I set the values = {190}  
And the result is `Expected Result: 36100 Inner Product Result: -29437`  
The problem is i dont know it was buggy or just my parameter-setting was wrong

---

<div class="post-metadata">

### Author: ![jdumezy](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/jdumezy/32/357_2.png) [@jdumezy](https://openfhe.discourse.group/u/jdumezy)
#### Post date: [March 28, 2025, 12:50pm UTC](https://openfhe.discourse.group/t/innerproduct-question/1966/3 "2025-03-28T12:50:33Z")

</div>

This is linked to the definition of the plaintext space. The values are not in [0, 65536], but in [-32768, 32768]. In your case, 36100 exceeds 32768, so it is represented as 36100 - 65537 = -29437. Therefore, you have the correct result.
