Average Error: 0.0 → 15.4
Time: 3.5s
Precision: binary64
\[\frac{x - y}{2 - \left(x + y\right)} \]
\[\begin{array}{l} t_0 := \frac{x - y}{2 - \left(x + y\right)}\\ t_1 := \left|\left|t_0\right|\right|\\ t_2 := {\left(2 - x\right)}^{2}\\ t_3 := \left(\frac{x}{2 - x} + \left(\frac{y \cdot x}{t_2} + \frac{x \cdot \left(y \cdot y\right)}{{\left(2 - x\right)}^{3}}\right)\right) - \left(\frac{y}{2 - x} + \frac{y \cdot y}{t_2}\right)\\ \mathbf{if}\;y \leq -4.5557276941455826 \cdot 10^{-36}:\\ \;\;\;\;\left|\mathsf{log1p}\left(\mathsf{expm1}\left(t_0\right)\right)\right|\\ \mathbf{elif}\;y \leq -2.938866461636586 \cdot 10^{-246}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -3.8606393500957805 \cdot 10^{-277}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.992168364127104 \cdot 10^{-76}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 6.6951920115568245 \cdot 10^{+78}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.135141610076587 \cdot 10^{+127}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 1.868197491650569 \cdot 10^{+215}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.2577735983466184 \cdot 10^{+240}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;{\left(\sqrt{t_0}\right)}^{2}\\ \end{array} \]
\frac{x - y}{2 - \left(x + y\right)}
\begin{array}{l}
t_0 := \frac{x - y}{2 - \left(x + y\right)}\\
t_1 := \left|\left|t_0\right|\right|\\
t_2 := {\left(2 - x\right)}^{2}\\
t_3 := \left(\frac{x}{2 - x} + \left(\frac{y \cdot x}{t_2} + \frac{x \cdot \left(y \cdot y\right)}{{\left(2 - x\right)}^{3}}\right)\right) - \left(\frac{y}{2 - x} + \frac{y \cdot y}{t_2}\right)\\
\mathbf{if}\;y \leq -4.5557276941455826 \cdot 10^{-36}:\\
\;\;\;\;\left|\mathsf{log1p}\left(\mathsf{expm1}\left(t_0\right)\right)\right|\\

\mathbf{elif}\;y \leq -2.938866461636586 \cdot 10^{-246}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;y \leq -3.8606393500957805 \cdot 10^{-277}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq 5.992168364127104 \cdot 10^{-76}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;y \leq 6.6951920115568245 \cdot 10^{+78}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq 2.135141610076587 \cdot 10^{+127}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq 1.868197491650569 \cdot 10^{+215}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq 3.2577735983466184 \cdot 10^{+240}:\\
\;\;\;\;-1\\

\mathbf{else}:\\
\;\;\;\;{\left(\sqrt{t_0}\right)}^{2}\\


\end{array}
(FPCore (x y) :precision binary64 (/ (- x y) (- 2.0 (+ x y))))
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ (- x y) (- 2.0 (+ x y))))
        (t_1 (fabs (fabs t_0)))
        (t_2 (pow (- 2.0 x) 2.0))
        (t_3
         (-
          (+
           (/ x (- 2.0 x))
           (+ (/ (* y x) t_2) (/ (* x (* y y)) (pow (- 2.0 x) 3.0))))
          (+ (/ y (- 2.0 x)) (/ (* y y) t_2)))))
   (if (<= y -4.5557276941455826e-36)
     (fabs (log1p (expm1 t_0)))
     (if (<= y -2.938866461636586e-246)
       t_3
       (if (<= y -3.8606393500957805e-277)
         t_1
         (if (<= y 5.992168364127104e-76)
           t_3
           (if (<= y 6.6951920115568245e+78)
             t_1
             (if (<= y 2.135141610076587e+127)
               -1.0
               (if (<= y 1.868197491650569e+215)
                 t_1
                 (if (<= y 3.2577735983466184e+240)
                   -1.0
                   (pow (sqrt t_0) 2.0)))))))))))
double code(double x, double y) {
	return (x - y) / (2.0 - (x + y));
}
double code(double x, double y) {
	double t_0 = (x - y) / (2.0 - (x + y));
	double t_1 = fabs(fabs(t_0));
	double t_2 = pow((2.0 - x), 2.0);
	double t_3 = ((x / (2.0 - x)) + (((y * x) / t_2) + ((x * (y * y)) / pow((2.0 - x), 3.0)))) - ((y / (2.0 - x)) + ((y * y) / t_2));
	double tmp;
	if (y <= -4.5557276941455826e-36) {
		tmp = fabs(log1p(expm1(t_0)));
	} else if (y <= -2.938866461636586e-246) {
		tmp = t_3;
	} else if (y <= -3.8606393500957805e-277) {
		tmp = t_1;
	} else if (y <= 5.992168364127104e-76) {
		tmp = t_3;
	} else if (y <= 6.6951920115568245e+78) {
		tmp = t_1;
	} else if (y <= 2.135141610076587e+127) {
		tmp = -1.0;
	} else if (y <= 1.868197491650569e+215) {
		tmp = t_1;
	} else if (y <= 3.2577735983466184e+240) {
		tmp = -1.0;
	} else {
		tmp = pow(sqrt(t_0), 2.0);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original0.0
Target0.0
Herbie15.4
\[\frac{x}{2 - \left(x + y\right)} - \frac{y}{2 - \left(x + y\right)} \]

Derivation

  1. Split input into 5 regimes
  2. if y < -4.5557276941455826e-36

    1. Initial program 0.0

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Applied egg-rr17.5

      \[\leadsto \color{blue}{\left|\frac{x - y}{2 - \left(x + y\right)}\right|} \]
    3. Applied egg-rr17.5

      \[\leadsto \left|\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{x - y}{2 - \left(x + y\right)}\right)\right)}\right| \]

    if -4.5557276941455826e-36 < y < -2.93886646163658617e-246 or -3.8606393500957805e-277 < y < 5.9921683641271037e-76

    1. Initial program 0.0

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Applied egg-rr15.1

      \[\leadsto \color{blue}{\sqrt[3]{{\left(\frac{x - y}{2 - \left(x + y\right)}\right)}^{3}}} \]
    3. Taylor expanded in y around 0 0.0

      \[\leadsto \color{blue}{\left(\frac{x}{2 - x} + \left(\frac{y \cdot x}{{\left(2 - x\right)}^{2}} + \frac{{y}^{2} \cdot x}{{\left(2 - x\right)}^{3}}\right)\right) - \left(\frac{y}{2 - x} + \frac{{y}^{2}}{{\left(2 - x\right)}^{2}}\right)} \]
    4. Simplified0.0

      \[\leadsto \color{blue}{\left(\frac{x}{2 - x} + \left(\frac{y \cdot x}{{\left(2 - x\right)}^{2}} + \frac{x \cdot \left(y \cdot y\right)}{{\left(2 - x\right)}^{3}}\right)\right) - \left(\frac{y}{2 - x} + \frac{y \cdot y}{{\left(2 - x\right)}^{2}}\right)} \]

    if -2.93886646163658617e-246 < y < -3.8606393500957805e-277 or 5.9921683641271037e-76 < y < 6.6951920115568245e78 or 2.1351416100765869e127 < y < 1.86819749165056882e215

    1. Initial program 0.0

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Applied egg-rr34.7

      \[\leadsto \color{blue}{\left|\frac{x - y}{2 - \left(x + y\right)}\right|} \]
    3. Applied egg-rr34.7

      \[\leadsto \left|\color{blue}{\left|\frac{x - y}{2 - \left(x + y\right)}\right|}\right| \]

    if 6.6951920115568245e78 < y < 2.1351416100765869e127 or 1.86819749165056882e215 < y < 3.2577735983466184e240

    1. Initial program 0.0

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Taylor expanded in x around inf 47.3

      \[\leadsto \color{blue}{-1} \]

    if 3.2577735983466184e240 < y

    1. Initial program 0.0

      \[\frac{x - y}{2 - \left(x + y\right)} \]
    2. Applied egg-rr2.4

      \[\leadsto \color{blue}{{\left(\sqrt{\frac{x - y}{2 - \left(x + y\right)}}\right)}^{2}} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification15.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4.5557276941455826 \cdot 10^{-36}:\\ \;\;\;\;\left|\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{x - y}{2 - \left(x + y\right)}\right)\right)\right|\\ \mathbf{elif}\;y \leq -2.938866461636586 \cdot 10^{-246}:\\ \;\;\;\;\left(\frac{x}{2 - x} + \left(\frac{y \cdot x}{{\left(2 - x\right)}^{2}} + \frac{x \cdot \left(y \cdot y\right)}{{\left(2 - x\right)}^{3}}\right)\right) - \left(\frac{y}{2 - x} + \frac{y \cdot y}{{\left(2 - x\right)}^{2}}\right)\\ \mathbf{elif}\;y \leq -3.8606393500957805 \cdot 10^{-277}:\\ \;\;\;\;\left|\left|\frac{x - y}{2 - \left(x + y\right)}\right|\right|\\ \mathbf{elif}\;y \leq 5.992168364127104 \cdot 10^{-76}:\\ \;\;\;\;\left(\frac{x}{2 - x} + \left(\frac{y \cdot x}{{\left(2 - x\right)}^{2}} + \frac{x \cdot \left(y \cdot y\right)}{{\left(2 - x\right)}^{3}}\right)\right) - \left(\frac{y}{2 - x} + \frac{y \cdot y}{{\left(2 - x\right)}^{2}}\right)\\ \mathbf{elif}\;y \leq 6.6951920115568245 \cdot 10^{+78}:\\ \;\;\;\;\left|\left|\frac{x - y}{2 - \left(x + y\right)}\right|\right|\\ \mathbf{elif}\;y \leq 2.135141610076587 \cdot 10^{+127}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 1.868197491650569 \cdot 10^{+215}:\\ \;\;\;\;\left|\left|\frac{x - y}{2 - \left(x + y\right)}\right|\right|\\ \mathbf{elif}\;y \leq 3.2577735983466184 \cdot 10^{+240}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;{\left(\sqrt{\frac{x - y}{2 - \left(x + y\right)}}\right)}^{2}\\ \end{array} \]

Reproduce

herbie shell --seed 2022127 
(FPCore (x y)
  :name "Data.Colour.RGB:hslsv from colour-2.3.3, C"
  :precision binary64

  :herbie-target
  (- (/ x (- 2.0 (+ x y))) (/ y (- 2.0 (+ x y))))

  (/ (- x y) (- 2.0 (+ x y))))