# In CKKS, what happens to the imaginary component "under the hood"?

**URL:** <https://openfhe.discourse.group/t/in-ckks-what-happens-to-the-imaginary-component-under-the-hood/1061>\
**Category:** Library Questions\
**Created:** [January 31, 2024, 5:54pm UTC](https://openfhe.discourse.group/t/in-ckks-what-happens-to-the-imaginary-component-under-the-hood/1061 "2024-01-31T17:54:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![iquah](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/iquah/32/8_2.png) [@iquah](https://openfhe.discourse.group/u/iquah)\
**Post date:** [January 31, 2024, 5:54pm UTC](https://openfhe.discourse.group/t/in-ckks-what-happens-to-the-imaginary-component-under-the-hood/1061/1 "2024-01-31T17:54:41Z")

</div>

I know that we don’t typically use the imaginary component in CKKS, but there’s something I’m trying to explore that involves math on the imaginary component. The following uses the [OpenFHE python](https://github.com/openfheorg/openfhe-python) library. The following is some simple sample code that was adapted from [simple-real-numbers.py](https://raw.githubusercontent.com/openfheorg/openfhe-python/main/examples/pke/simple-real-numbers.py)

```python
import openfhe

if __name__ == ' __main__':
    mult_depth = 1
    scale_mod_size = 50
    batch_size = 8

    parameters = openfhe.CCParamsCKKSRNS()
    parameters.SetMultiplicativeDepth(mult_depth)
    parameters.SetScalingModSize(scale_mod_size)
    parameters.SetBatchSize(batch_size)

    cc = openfhe.GenCryptoContext(parameters)
    cc.Enable(openfhe.PKESchemeFeature.PKE)
    cc.Enable(openfhe.PKESchemeFeature.KEYSWITCH)
    cc.Enable(openfhe.PKESchemeFeature.LEVELEDSHE)

    print("The CKKS scheme is using ring dimension: " + str(cc.GetRingDimension()))

    keys = cc.KeyGen()
    cc.EvalMultKeyGen(keys.secretKey)
    cc.EvalRotateKeyGen(keys.secretKey, [1, -2])

    x1 = [0.25, 0.5, 0.75, 1.0, 2.0, 3.0, 4.0, 5.0]
    for i, el in enumerate(x1):
        x1[i] = el + (2 * el * 1j)

    ptx1 = cc.MakeCKKSPackedPlaintext(x1)

    print("Input x1: " + str(ptx1))

    # Encrypt the encoded vectors
    c1 = cc.Encrypt(keys.publicKey, ptx1)

    c_add = cc.EvalAdd(c1, c1)
    c_mult = cc.EvalMult(c1, c1)

    precision = 8
    print("Results of homomorphic computations:")
    result = cc.Decrypt(c_add, keys.secretKey)
    result.SetLength(batch_size)
    print("x1 + x1 = " + str(result))
    print("Estimated precision in bits: " + str(result.GetLogPrecision()))

    # Decrypt the result of multiplication
    result = cc.Decrypt(c_mult,keys.secretKey)
    result.SetLength(batch_size)
    print("x1 * x1 = " + str(result))

```

I’m guessing that I can’t expect to get meaningful math operations out of the imaginary component?

---

<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:** [February 1, 2024, 4:36pm UTC](https://openfhe.discourse.group/t/in-ckks-what-happens-to-the-imaginary-component-under-the-hood/1061/2 "2024-02-01T16:36:23Z")

</div>

Currently, the imaginary part of messages in CKKS is used to estimate the magnitude of the error to be used in the decryption noise flooding [openfhe-development/src/pke/examples/CKKS\_NOISE\_FLOODING.md at main · openfheorg/openfhe-development · GitHub](https://github.com/openfheorg/openfhe-development/blob/main/src/pke/examples/CKKS_NOISE_FLOODING.md). Prior to this design choice (and maybe again in the future), CKKS was supporting computations on complex numbers, meaning that you should have seen correct results in the imaginary component as well.

---

<div class="post-metadata">

**Author:** ![iquah](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/iquah/32/8_2.png) [@iquah](https://openfhe.discourse.group/u/iquah)\
**Post date:** [February 1, 2024, 5:17pm UTC](https://openfhe.discourse.group/t/in-ckks-what-happens-to-the-imaginary-component-under-the-hood/1061/3 "2024-02-01T17:17:12Z")

</div>

Gotcha! Security concerns aside, do you know, off the top of your head, how far back I’d need to go to get the math on complex numbers to work out?

---

<div class="post-metadata">

**Author:** ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)\
**Post date:** [February 2, 2024, 1:09am UTC](https://openfhe.discourse.group/t/in-ckks-what-happens-to-the-imaginary-component-under-the-hood/1061/4 "2024-02-02T01:09:36Z")

</div>

To PALISADE v1.10.5 [October 2, 2020] 🙂 You can access that release at [v1.10.5 · PALISADE / PALISADE Release · GitLab](https://gitlab.com/palisade/palisade-release/-/releases/v1.10.5)
