# CKKS ModDown operation

**URL:** <https://openfhe.discourse.group/t/ckks-moddown-operation/445>\
**Category:** FHE Questions\
**Created:** [April 2, 2023, 7:19pm UTC](https://openfhe.discourse.group/t/ckks-moddown-operation/445 "2023-04-02T19:19:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Desuemi](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@Desuemi](https://openfhe.discourse.group/u/Desuemi)\
**Post date:** [April 2, 2023, 7:19pm UTC](https://openfhe.discourse.group/t/ckks-moddown-operation/445/1 "2023-04-02T19:19:41Z")

</div>

In the “A full RNS variant of approximate homomorphic encryption” paper, we need to times p^{-1} during the ModDown operaiton.  
Should this multiplication of p^{-1} be performed to the ciphertext in the coefficient representation or evalution representation (NTT) domian?

---

<div class="post-metadata">

**Author:** ![saroja](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@saroja](https://openfhe.discourse.group/u/saroja)\
**Post date:** [April 4, 2023, 3:20pm UTC](https://openfhe.discourse.group/t/ckks-moddown-operation/445/2 "2023-04-04T15:20:40Z")

</div>

You can do it in either. In OpenFHE, we perform it in the evaluation representation. See the ApproxModDown function in [dcrtpoly.cpp](https://github.com/openfheorg/openfhe-development/blob/main/src/core/lib/lattice/hal/default/dcrtpoly.cpp).

---

<div class="post-metadata">

**Author:** ![Desuemi](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@Desuemi](https://openfhe.discourse.group/u/Desuemi)\
**Post date:** [April 4, 2023, 3:41pm UTC](https://openfhe.discourse.group/t/ckks-moddown-operation/445/3 "2023-04-04T15:41:47Z")

</div>

Thank you for your reply. It is very helpful. May I ask a follow up question?  
Should we change from NTT representation to coefficient representation when we change the modulus of CRT? Meanwhile, the change of modulus also happened in the ModDown operation.

---

<div class="post-metadata">

**Author:** ![Desuemi](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@Desuemi](https://openfhe.discourse.group/u/Desuemi)\
**Post date:** [April 4, 2023, 3:44pm UTC](https://openfhe.discourse.group/t/ckks-moddown-operation/445/4 "2023-04-04T15:44:08Z")

</div>

Also, in the line 1537 of dcrtpoly.cpp, it looks like transfer to the coefficient representation before performing any operations in the ModDown procedure.

---

<div class="post-metadata">

**Author:** ![saroja](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@saroja](https://openfhe.discourse.group/u/saroja)\
**Post date:** [April 4, 2023, 4:22pm UTC](https://openfhe.discourse.group/t/ckks-moddown-operation/445/5 "2023-04-04T16:22:35Z")

</div>

Yes, we should do the modulus basis change in coefficient representation since we need to perform modulus reductions. We change to coefficient in line 1537, and we change back to EVALUATION in line 1564, before we multiply by P^{-1} .

---

<div class="post-metadata">

**Author:** ![Desuemi](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@Desuemi](https://openfhe.discourse.group/u/Desuemi)\
**Post date:** [April 4, 2023, 5:16pm UTC](https://openfhe.discourse.group/t/ckks-moddown-operation/445/6 "2023-04-04T17:16:46Z")

</div>

Thank you for the detailed explanation. May I know the reason for transferring from NTT representation to coefficient representation to perform modulus basis change? Could you suggest any reference papers that contain the proof?

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![saroja](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@saroja](https://openfhe.discourse.group/u/saroja)\
**Post date:** [April 4, 2023, 5:46pm UTC](https://openfhe.discourse.group/t/ckks-moddown-operation/445/7 "2023-04-04T17:46:14Z")

</div>

The `ApproxSwitchCRTBasis` method is described in Section 2.3 in the [paper](https://eprint.iacr.org/2018/931.pdf) you mentioned. Performing the \pmod{q\_j} operation requires the polynomial to be in coefficient representation.

---

<div class="post-metadata">

**Author:** ![Desuemi](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@Desuemi](https://openfhe.discourse.group/u/Desuemi)\
**Post date:** [April 4, 2023, 6:07pm UTC](https://openfhe.discourse.group/t/ckks-moddown-operation/445/8 "2023-04-04T18:07:06Z")

</div>

Thank you for your help.
