Batch size and rotation

Using some ideeas of the simple-real-numbers example ( openfhe-development/src/pke/examples/simple-real-numbers.cpp at main · openfheorg/openfhe-development · GitHub ), I would like to do some computations on the following sequences :

seq_1 = (a_0, a_1, a_2, a_3, a_4);

seq_2 = rotate(seq_1, -1);
= (a_4, a_0, a_1, a_2, a_3);

And then, I could do something like :

seq_3 = seq_1 + seq_2

I have the following problem : it seems that the batch size, which controls the length of my sequence, is supposed to be a power of 2 (even if not specified in the examples …).

Is there a way to achieve this type of seq_2 on a sequence with a fixed length ?

My use case might not be covered by rotate …

Yes, batchSize is assumed to be a power of 2 (by default it is set to the maximum number of slots, i.e., N/2). In your example, you could set the batch size to 8 (the top three components would be zero-padded). If you want to use a more compact representation (use only 5 slots, e.g., if you want to linearize a matrix with one dimension 5 of in a single ciphertext), you could achieve the desired effect using masking and two rotations (instead of one). One rotation would be forward (in the desired direction) and the other one would be inverse.

Thank you very much !

I have a follow-up question. This method of yours with masks is killing my multiplicative depth. Is there a way to implement a rotation-like function (i.e. without multiplicative depth cost) directly for my case ? Can the rotation operation be extended to support other types of permutations ?
This is not a feature request, just genuine interest.

Is there a way to implement a rotation-like function (i.e. without multiplicative depth cost) directly for my case ?

I don’t see how it can be done without a plaintext multiplication. On the other hand, the noise cost of this multiplication is smaller as we multiply by a plaintext vector composed of zeros and ones. For instance in the case of BFV, the noise increase would not be larger than N (in the worst case, and it would be O(\sqrt{N}) in the average case), where N is the ring dimension. However, in the case of CKKS it would still be relatively large (because of converting real numbers to scaled integers), but still smaller than homomorphic multiplication noise cost.