Added complex scalar addition and complex scalar multiplication, with further testing, found that scalar addition with negative numbers doesn't work.#18
Conversation
lawrencekhlim
commented
Feb 8, 2026
- Addition to FIDESlib APIs for complex scalar addition and complex scalar multiplication.
- Added Complex CKKS datatype (must use in order to create plaintexts with complex values).
- Added scalar addition and multiplication to src/CKKS/Ciphertext.cpp.
- Scalar multiplication was tested and works fine, but scalar addition is buggy for negative real or imaginary components.
- GetLogPrecision() does not work when complex values are supported, based on what's in OpenFHE
… further testing, found that scalar addition with negative numbers doesn't work.
| std::vector<uint64_t> vec(cc.N, 0); | ||
| // Code works for positive values only, doesn't work for negative values. | ||
| vec[0] = (c.real() > 0) ? elem1[i] % (moduli[i]) : (-elem1[i] % (moduli[i]) + moduli[i]) % (moduli[i]); | ||
| vec[cc.N / 2] = (c.imag() > 0) ? elem2[i] % (moduli[i]) : (-elem2[i] % (moduli[i]) + moduli[i]) % (moduli[i]); |
There was a problem hiding this comment.
There's a bug here on lines 753 and 754 for addition of negative complex numbers, whether the real or imaginary part is negative. Apologies, I didn't realize I tested it further just now. The multiplication doesn't have the same problems.
There was a problem hiding this comment.
Any idea of what causes this?
There was a problem hiding this comment.
I think the cause is that those two lines don't quite match up to what OpenFHE has in these two lines. Specifically, the mod.ModSub(elemsRe[i], mod) in OpenFHE (which is used when the real and likewise imaginary part are negative) doesn't match with (-elem1[i] % (moduli[i]) + moduli[i]) % (moduli[i]). It's possible that the positive part may have a subtle bug as well.