Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A question about Negative number multiplication #2

Open
siaaron045 opened this issue May 22, 2019 · 8 comments
Open

A question about Negative number multiplication #2

siaaron045 opened this issue May 22, 2019 · 8 comments

Comments

@siaaron045
Copy link

I am sorry to trouble you.
When i use FullRNS-HEAAN to do a negative number multiplication, the answer is wrong.
Can FullRNS-HEAAN do negative number multiplication?(negative number addition is right)
Thanks a million.

@KyoohyungHan
Copy link
Owner

Hi siaaron045

I tested as the following command.

// Encrypt mvec
Ciphertext cipher = scheme.encrypt(mvec, slots, L);

// Multiple negative value (= -0.1)
Ciphertext cmultCipher = scheme.multByConst(cipher, -0.1);
scheme.reScaleByAndEqual(cmultCipher, 1);

I checked the decrypted result. And It seems correct.
It would be better if you can attach some part of your code.

Best, Kyoohyung Han

@siaaron045
Copy link
Author

I test your code and the answer is right,
but when ''cipher'' is a negative number's ciphertext or make multiplication of two negative ciphertext,the answer is wrong.
like this:
//Encrypt mvec=-5 Ciphertext cipher1 = scheme.encrypt(mvec, slots, L); Ciphertext cipher2=cipher1; Ciphertext cmultCipher = scheme.multByConst(cipher1, -1); //or Ciphertext cmultCipher = scheme.mult(cipher1, cipher2); scheme.reScaleByAndEqual(cmultCipher, 1);
both of the answers are wrong.
So the encrypted number can't be negative?

@KyoohyungHan
Copy link
Owner

Oh... when I put -1 instead of -5 it works.

This problem came from the negate function in Context.cpp.
I will fix this problem soon.

Thanks for the report.

@siaaron045
Copy link
Author

Yes,but it works only when mvec=-1, i put -2,-3,-4 the answers are wrong.
And the function scheme.mult(cipher1, cipher2) does not work when make multiplication of two negative ciphertext expect -1.
Thanks.

@siaaron045
Copy link
Author

The error still exist.
I hope you can take some time to fix it.
Thank you.

@pdroalves
Copy link

@KyoohyungHan Looks like you found the error source. Can you be more specific where is it? I think I can submit a patch.

@Cmiiii
Copy link

Cmiiii commented Mar 3, 2023

The error still exist. I hope you can take some time to fix it. Thank you.

Hi~ is this problem solved? I found the same error too,but i have no idea how to fix it?Where exactly does this problem occur?

@czh-rot
Copy link

czh-rot commented Jun 5, 2023

This problem is not because of the negate function, but because of a problem with encode, where for copying simply adding the modulus leads to an encoding error. You can fix it by referring to the encoding functions of OPENFHE or Lattigo.

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

No branches or pull requests

5 participants