# Computing 1/x Over \[-100, 100\] with EvalDivide

**URL:** <https://openfhe.discourse.group/t/computing-1-x-over-100-100-with-evaldivide/2048>\
**Category:** FHE Questions\
**Created:** [May 31, 2025, 3:48am UTC](https://openfhe.discourse.group/t/computing-1-x-over-100-100-with-evaldivide/2048 "2025-05-31T03:48:01Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![yuucyf](https://avatars.discourse-cdn.com/v4/letter/y/d07c76/32.png) [@yuucyf](https://openfhe.discourse.group/u/yuucyf)\
**Post date:** [May 31, 2025, 3:48am UTC](https://openfhe.discourse.group/t/computing-1-x-over-100-100-with-evaldivide/2048/1 "2025-05-31T03:48:01Z")

</div>

Hello!  
I’m working on computing the reciprocal, `1/x` , for values `x` within the range `[-100, 100]` using OpenFHE primitives.  
I am using OpenFHE to compute 1/x, but the value of x is in the interval [-100, 100]. However, since x = 0 would cause an error, I need to divide it into two intervals:  
[-100, -1] and [1, 100]. Does that mean it is impossible to compute if x falls within [-1, 1]?  
Another issue is that x belongs to two intervals. How can I use EvalDivide to compute a value close to the correct 1/x?

---

<div class="post-metadata">

**Author:** ![lujoho](https://avatars.discourse-cdn.com/v4/letter/l/a587f6/32.png) [@lujoho](https://openfhe.discourse.group/u/lujoho)\
**Post date:** [June 1, 2025, 5:09pm UTC](https://openfhe.discourse.group/t/computing-1-x-over-100-100-with-evaldivide/2048/2 "2025-06-01T17:09:02Z")

</div>

Hi,

I think such a large interval is rather difficult for HE. When looking at 1/x in this interval we have values ranging from negative infinity to positive infinity. This can hardly be represented by a polynomial. Even with a very large degree, there still will be a large error around x=0.  
So I would suggest looking if it is possible to reduce the size of your interval.  
Furthermore, I recommend having a look into [this](https://link.springer.com/article/10.1007/s10207-023-00781-0) publication, where the Newton-Raphson method is used. The starting values then have to be selected very carefully but it is possible to get a better approximation than with polynomials.

---

<div class="post-metadata">

**Author:** ![yuucyf](https://avatars.discourse-cdn.com/v4/letter/y/d07c76/32.png) [@yuucyf](https://openfhe.discourse.group/u/yuucyf)\
**Post date:** [June 3, 2025, 9:33am UTC](https://openfhe.discourse.group/t/computing-1-x-over-100-100-with-evaldivide/2048/3 "2025-06-03T09:33:59Z")

</div>

If I restrict the interval to [-10, 0) U (0, 10], how do I implement 1/x using OpenFHE?

---

<div class="post-metadata">

**Author:** ![lujoho](https://avatars.discourse-cdn.com/v4/letter/l/a587f6/32.png) [@lujoho](https://openfhe.discourse.group/u/lujoho)\
**Post date:** [June 3, 2025, 8:52pm UTC](https://openfhe.discourse.group/t/computing-1-x-over-100-100-with-evaldivide/2048/4 "2025-06-03T20:52:22Z")

</div>

Hi @yuucyf,

as previously stated, I’d consider looking into the Newton-Raphson method.  
If you want to use polynomials, I do not see a simple way here. You  
could think about looking into splines, but that typically requires some  
kind of comparison.  
Generally speaking, you could consider applying scheme switching to do a  
comparison and then evaluate a polynomial for either of that two intervals.  
Nevertheless, I still suggest Newton-Raphson. It can be implemented  
quickly and you are then able to check if the provided accuracy suffices  
for your application.

---

<div class="post-metadata">

**Author:** ![yuucyf](https://avatars.discourse-cdn.com/v4/letter/y/d07c76/32.png) [@yuucyf](https://openfhe.discourse.group/u/yuucyf)\
**Post date:** [June 4, 2025, 3:21am UTC](https://openfhe.discourse.group/t/computing-1-x-over-100-100-with-evaldivide/2048/5 "2025-06-04T03:21:58Z")

</div>

Thanks @lujoho !  
I understand that in OpenFHE, the EvalDivide function can compute 1/x, but only within either positive or negative intervals such as: [-5, -1] or [1, 5].  
When the sign of x (positive/negative) is unknown, it becomes impossible to set the ​ **​lower bound of argument​** ​ and ​ **​upper bound of argument​** ​ in EvalDivide.

---

<div class="post-metadata">

**Author:** ![narger](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/narger/32/420_2.png) [@narger](https://openfhe.discourse.group/u/narger)\
**Post date:** [June 4, 2025, 8:10am UTC](https://openfhe.discourse.group/t/computing-1-x-over-100-100-with-evaldivide/2048/6 "2025-06-04T08:10:02Z")

</div>

One thing you could try (perhaps dumb, warned ^^), is to approximate

f(x) = \begin{cases} 1/x &\text{if } x \> 1\\ x & \text{if } -1 \leq x \leq 1\\ -1/x & \text{otherwise} \end{cases}

It can be horror though, I don’t think Chebyshev roots can deal with this monster without issues… but it might be worth a try – this is its plot:

 ![Screenshot 2025-06-04 alle 10.09.05](https://canada1.discourse-cdn.com/flex031/uploads/openfhe/original/1X/eb2a5921436fb117ad45d32822299590b85a5568.png)

---

<div class="post-metadata">

**Author:** ![narger](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/narger/32/420_2.png) [@narger](https://openfhe.discourse.group/u/narger)\
**Post date:** [June 4, 2025, 8:47am UTC](https://openfhe.discourse.group/t/computing-1-x-over-100-100-with-evaldivide/2048/7 "2025-06-04T08:47:46Z")

</div>

It turns out that maybe is not that bad, I tried to approximate in [-4, 4] with degree 40 and looks fine

 ![Screenshot 2025-06-04 alle 10.47.07](https://canada1.discourse-cdn.com/flex031/uploads/openfhe/original/1X/46735f4c070f6f0ef180d267cf280fb116c2a7bf.jpeg)

---

<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:** [June 9, 2025, 8:22pm UTC](https://openfhe.discourse.group/t/computing-1-x-over-100-100-with-evaldivide/2048/8 "2025-06-09T20:22:03Z")

</div>

A commonly used approximate division algorithm in FHE is Goldschmidt’s division. You could give it a try.  
There are a few FHE papers that used it. Check the paper [Privacy-Preserving Large Language Model Inference via GPU-Accelerated Fully Homomorphic Encryption](https://openreview.net/pdf?id=Rs7h1od6ov) for an example.

---

<div class="post-metadata">

**Author:** ![yuucyf](https://avatars.discourse-cdn.com/v4/letter/y/d07c76/32.png) [@yuucyf](https://openfhe.discourse.group/u/yuucyf)\
**Post date:** [June 11, 2025, 10:13am UTC](https://openfhe.discourse.group/t/computing-1-x-over-100-100-with-evaldivide/2048/9 "2025-06-11T10:13:20Z")

</div>

@Caesar Thanks for sharing the link! Unfortunately, I can’t seem to access it. Is there another way you could share the information?

---

<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:** [June 11, 2025, 1:46pm UTC](https://openfhe.discourse.group/t/computing-1-x-over-100-100-with-evaldivide/2048/10 "2025-06-11T13:46:45Z")

</div>

There was a typo in the link. Now it should work.
