# Is there a function for taking absolute values in ciphertext

**URL:** <https://openfhe.discourse.group/t/is-there-a-function-for-taking-absolute-values-in-ciphertext/663>\
**Category:** FHE Questions\
**Created:** [June 25, 2023, 2:46pm UTC](https://openfhe.discourse.group/t/is-there-a-function-for-taking-absolute-values-in-ciphertext/663 "2023-06-25T14:46:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kenan](https://avatars.discourse-cdn.com/v4/letter/k/e495f1/32.png) [@kenan](https://openfhe.discourse.group/u/kenan)\
**Post date:** [June 25, 2023, 2:46pm UTC](https://openfhe.discourse.group/t/is-there-a-function-for-taking-absolute-values-in-ciphertext/663/1 "2023-06-25T14:46:22Z")

</div>

Is there a function for taking absolute values in ciphertext？

Is there a function to sum the ciphertext content of a batch？  
such as  
batchsize=5;  
v={1,2,3,4,5}  
v1=MakePackedPlaintext(v)  
cpv=encryption(v1)  
a function like sum(cpv) =encryption(MakePackedPlaintext(1))+encryption(MakePackedPlaintext(2))+…+encryption(MakePackedPlaintext(5));

---

<div class="post-metadata">

**Author:** ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)\
**Post date:** [June 27, 2023, 3:24pm UTC](https://openfhe.discourse.group/t/is-there-a-function-for-taking-absolute-values-in-ciphertext/663/2 "2023-06-27T15:24:40Z")

</div>

> Is there a function for taking absolute values in ciphertext？

One option is to use the algorithm described in Section 3.2 of [Numerical Method for Comparison on Homomorphically Encrypted Numbers](https://eprint.iacr.org/2019/417) (this is in the context of the CKKS scheme). For the square root function, one could also use the Chebyshev series interpolation (`EvalChebyshevFunction` in OpenFHE).

The other alternative is to use FHEW/TFHE bootstrapping to evaluate a lookup table for the absolute value function, as described in [Large-Precision Homomorphic Sign Evaluation using FHEW/TFHE Bootstrapping](https://eprint.iacr.org/2021/1337).

> Is there a function to sum the ciphertext content of a batch？

`EvalSum` in OpenFHE can be used for this purpose. The batch size should be a power of two (8 in this case).
