# Vector operations on vectors with different lenghts

**URL:** <https://openfhe.discourse.group/t/vector-operations-on-vectors-with-different-lenghts/1719>\
**Category:** Library Questions\
**Tags:** openfhe-help\
**Created:** [November 13, 2024, 2:23pm UTC](https://openfhe.discourse.group/t/vector-operations-on-vectors-with-different-lenghts/1719 "2024-11-13T14:23:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DenisRed](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/denisred/32/303_2.png) [@DenisRed](https://openfhe.discourse.group/u/DenisRed)\
**Post date:** [November 13, 2024, 2:23pm UTC](https://openfhe.discourse.group/t/vector-operations-on-vectors-with-different-lenghts/1719/1 "2024-11-13T14:23:04Z")

</div>

Hello,

I have two vectors:

```auto
    vector<double> lat = {52.5212};
    vector<double> lats = {52.5115, 52.5122, 52.5125, 52.5121, 52.5195, 52.5132, 52.5105, 52.5047};

    auto subtraction = clientCC->EvalSub(ctLats, ctLat);

```

I want to subtract the value in `lat` from all values in `lats` homomorphically.

The results from the pseudocode above is:

`(-0.0097, 52.5122, 52.5125, 52.5121, 52.5195, 52.5132, 52.5105, 52.5047, ... ); Estimated precision: 37 bits`

The first element is obviously correct. My first thought was to create vector of same size like `lats` like:  
`vector<double> latConstants = {52.5212, 52.5212, 52.5212, 52.5212, 52.5212, 52.5212, 52.5212, 52.5212};`

and then do the same `EvalSub` operation again. The problem is that `lat` is not existing in plaintext in the process. I only have `Enc(lat)` and i dont know how to get from `Enc(lat)` to `Enc(latConstants)`  
What are your thoughts?

---

<div class="post-metadata">

**Author:** ![andreea.alexandru](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/andreea.alexandru/32/378_2.png) [@andreea.alexandru](https://openfhe.discourse.group/u/andreea.alexandru)\
**Post date:** [November 13, 2024, 4:34pm UTC](https://openfhe.discourse.group/t/vector-operations-on-vectors-with-different-lenghts/1719/2 "2024-11-13T16:34:32Z")

</div>

Please read about SIMD capabilities and homomorphic rotations, for instance, from the [webinars](https://www.openfhe.org/webinars/) or by searching in the forum.

If you have your ciphertext encrypting ct = [lat, 0, 0, …], you can obtain an encryption of ct\_rep = [lat, lat, lat, …], by repeatedly rotating and summing: ct\_rep = ct + EvalAtIndex(ct, -1); ct\_rep = ct\_rep + EvalAtIndex(ct\_rep, -2); etc (it is you can also do it with a linear number of rotations but it is more efficient to do it with a logarithmic number of rotations). This is done internally by the EvalSum() function.

---

<div class="post-metadata">

**Author:** ![DenisRed](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/denisred/32/303_2.png) [@DenisRed](https://openfhe.discourse.group/u/DenisRed)\
**Post date:** [November 14, 2024, 10:51am UTC](https://openfhe.discourse.group/t/vector-operations-on-vectors-with-different-lenghts/1719/3 "2024-11-14T10:51:48Z")

</div>

Thank you very much! Your information was very useful. Espacially the way how the `EvalSum()` function works =)
