# Approximating comparison function

**URL:** <https://openfhe.discourse.group/t/approximating-comparison-function/1610>\
**Category:** Library Questions\
**Created:** [September 27, 2024, 3:38pm UTC](https://openfhe.discourse.group/t/approximating-comparison-function/1610 "2024-09-27T15:38:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhavinmoriya](https://avatars.discourse-cdn.com/v4/letter/b/e68b1a/32.png) [@bhavinmoriya](https://openfhe.discourse.group/u/bhavinmoriya)\
**Post date:** [September 27, 2024, 3:38pm UTC](https://openfhe.discourse.group/t/approximating-comparison-function/1610/1 "2024-09-27T15:38:53Z")

</div>

Hi,

I am approximating a comparison function with the function f\_n(x) mentioned in the following paper,

> **[Efficient Homomorphic Comparison Methods with Optimal Complexity](https://eprint.iacr.org/2019/1234)**
>
> Comparison of two numbers is one of the most frequently used operations, but it has been a challenging task to efficiently compute the comparison function in homomorphic encryption (HE) which basically support addition and multiplication.
> Recently,...

The function is found on page 232. In order to get the better approximation I need to do more compositions. I am composing the function 17 times and degree n of a function f\_n(x) is 4. I am getting following error while I run the program:  
etup & Key Generation

Using ring dimension: 512, mult depth 80  
terminate called after throwing an instance of ‘lbcrypto::OpenFHEException’  
what(): /home/bhavin/Downloads/openfhe-development/src/core/include/lattice/hal/default/dcrtpoly-impl.h:l.698:DropLastElement(): DropLastElement: Removing last element of DCRTPoly renders it invalid.  
Aborted (core dumped)

I would really appreciate any leads to figure out the problem.

Bhavin.

---

<div class="post-metadata">

**Author:** ![Caesar](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/caesar/32/63_2.png) [@Caesar](https://openfhe.discourse.group/u/Caesar)\
**Post date:** [September 27, 2024, 3:57pm UTC](https://openfhe.discourse.group/t/approximating-comparison-function/1610/2 "2024-09-27T15:57:53Z")

</div>

It looks to me you are running out of levels. Try increasing the multiplicative even further, or consider using bootstrapping if you are using CKKS.

---

<div class="post-metadata">

**Author:** ![bhavinmoriya](https://avatars.discourse-cdn.com/v4/letter/b/e68b1a/32.png) [@bhavinmoriya](https://openfhe.discourse.group/u/bhavinmoriya)\
**Post date:** [September 27, 2024, 10:12pm UTC](https://openfhe.discourse.group/t/approximating-comparison-function/1610/3 "2024-09-27T22:12:30Z")

</div>

Thanks very much @Caesar
