Score:1

How to compute the absolute value of a float number using only addition and multiplication (or using an and-xor circuit)?

ck flag

Hi I am trying to calculate the abs or a float number $x$, however, I want to apply this operation when $x$ is under fully homomorphic encryption (typically CKKS Scheme). So I come up with the idea that if we can use only addition and multiplication (some constant value like $2^k$ could be involved) to get abs, then we can just encrypt the whole operation and thus get an abs for encrypted data.

Note that here I am only dealing with the float point in some specific range, e.g., $-2^{28}\le x\le 2^{28}$, so I'm pretty sure at least there must exists some particular and-xor circuit for abs in general case.

But to directly adapt the abs operation of the float point to the homomorphic encryption scheme, I can't come up with some arithmetic methods to deal with it. Could any please offer me some help?

itabline avatar
ck flag
Actually not only the accuracy could suffer from fix-point method, but also other approximation methods are acceptable.
swineone avatar
ru flag
I'm unfamiliar with FHE, so pardon me if this makes no sense. I'm thinking from the standpoint of bit manipulations to get the absolute value of a (cleartext) IEEE-754 number. In that case, you just need to clear the sign bit, since IEEE-754 uses a sign and magnitude representation.
swineone avatar
ru flag
Since the sign bit is the MSB, it would be enough to perform an integer addition with $2^{31}$ (single precision) or $2^{63}$ (double precision). XORing with the same values would also work, or ANDing with the complement of them.
itabline avatar
ck flag
Hi swineone, thanks for your idea. I am not quite familiar with FHE either, but during the encryption scheme of FHE, the float points are usually turned into integer (or encoded into integer polynomial) through fix-point method. And I don't think it's obvious that the overflow bits of the float number work well in this scenario. So I think it's better to do some arithmetic operation.
swineone avatar
ru flag
Do you mean it gets turned into a 2's complement integer? In that case, would [this](https://graphics.stanford.edu/~seander/bithacks.html#IntegerAbs) answer your question?
itabline avatar
ck flag
Sorry I didn't get your point about 2's complement integer. The problem here is that I would like to do the abs operation arithmetically, since it would be attempted further into the FHE protocol. However, the reference you've mentioned is about the bit twidding tricks, which maybe not very helpful for this problem I think.
swineone avatar
ru flag
Since you mentioned both addition and multiplication, as well as an AND-XOR circuit, in the question, I understood you could use either or even both. In this case, the linked solution employs an addition and an XOR, and I thought it would fit.
itabline avatar
ck flag
Sorry there is a misrepresentation in my statement. I mentioned the and-xor circuit to imply the general setting for the adaption for homomorphic encryption. But here the problem of method mentioned in the link is that I don't see how to directly adapt this method to the float point scenario (the original method is designed for the integer) and the ``mask`` it used is from the bit twiddling which I'm not sure whether it could implemented in the encrypted scheme since all numbers are encoded and encrypted in a different form. I will change my statement of the problem to make it clear.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.