Skip to content

Added complex scalar addition and complex scalar multiplication, with further testing, found that scalar addition with negative numbers doesn't work.#18

Open
lawrencekhlim wants to merge 1 commit intoCAPS-UMU:mainfrom
lawrencekhlim:v2.0-scalar-complex
Open

Conversation

@lawrencekhlim
Copy link

  • 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]);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea of what causes this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants