Average Error: 19.5 → 4.7
Time: 16.3s
Precision: 64
\[0 \lt x \lt 1 \land y \lt 1\]
\[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -1.3622257246714918 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -4.0918058340644614 \cdot 10^{-167}:\\ \;\;\;\;\sqrt[3]{\left(\left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right) \cdot \left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right)\right) \cdot \left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right)}\\ \mathbf{elif}\;y \le -1.9618167972718326 \cdot 10^{-179}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 3.050134070228654 \cdot 10^{-166}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \log \left(e^{\frac{y \cdot y}{x \cdot x + y \cdot y}}\right)\\ \end{array}\]
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\begin{array}{l}
\mathbf{if}\;y \le -1.3622257246714918 \cdot 10^{+154}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -4.0918058340644614 \cdot 10^{-167}:\\
\;\;\;\;\sqrt[3]{\left(\left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right) \cdot \left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right)\right) \cdot \left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right)}\\

\mathbf{elif}\;y \le -1.9618167972718326 \cdot 10^{-179}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le 3.050134070228654 \cdot 10^{-166}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \log \left(e^{\frac{y \cdot y}{x \cdot x + y \cdot y}}\right)\\

\end{array}
double f(double x, double y) {
        double r3551175 = x;
        double r3551176 = y;
        double r3551177 = r3551175 - r3551176;
        double r3551178 = r3551175 + r3551176;
        double r3551179 = r3551177 * r3551178;
        double r3551180 = r3551175 * r3551175;
        double r3551181 = r3551176 * r3551176;
        double r3551182 = r3551180 + r3551181;
        double r3551183 = r3551179 / r3551182;
        return r3551183;
}

double f(double x, double y) {
        double r3551184 = y;
        double r3551185 = -1.3622257246714918e+154;
        bool r3551186 = r3551184 <= r3551185;
        double r3551187 = -1.0;
        double r3551188 = -4.0918058340644614e-167;
        bool r3551189 = r3551184 <= r3551188;
        double r3551190 = x;
        double r3551191 = r3551190 * r3551190;
        double r3551192 = r3551184 * r3551184;
        double r3551193 = r3551191 + r3551192;
        double r3551194 = r3551191 / r3551193;
        double r3551195 = r3551192 / r3551193;
        double r3551196 = r3551194 - r3551195;
        double r3551197 = r3551196 * r3551196;
        double r3551198 = r3551197 * r3551196;
        double r3551199 = cbrt(r3551198);
        double r3551200 = -1.9618167972718326e-179;
        bool r3551201 = r3551184 <= r3551200;
        double r3551202 = 3.050134070228654e-166;
        bool r3551203 = r3551184 <= r3551202;
        double r3551204 = 1.0;
        double r3551205 = exp(r3551195);
        double r3551206 = log(r3551205);
        double r3551207 = r3551194 - r3551206;
        double r3551208 = r3551203 ? r3551204 : r3551207;
        double r3551209 = r3551201 ? r3551187 : r3551208;
        double r3551210 = r3551189 ? r3551199 : r3551209;
        double r3551211 = r3551186 ? r3551187 : r3551210;
        return r3551211;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original19.5
Target0.1
Herbie4.7
\[\begin{array}{l} \mathbf{if}\;0.5 \lt \left|\frac{x}{y}\right| \lt 2:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{2}{1 + \frac{x}{y} \cdot \frac{x}{y}}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if y < -1.3622257246714918e+154 or -4.0918058340644614e-167 < y < -1.9618167972718326e-179

    1. Initial program 61.9

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Simplified61.9

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}}\]
    3. Using strategy rm
    4. Applied add-log-exp61.9

      \[\leadsto \frac{x \cdot x}{x \cdot x + y \cdot y} - \color{blue}{\log \left(e^{\frac{y \cdot y}{x \cdot x + y \cdot y}}\right)}\]
    5. Taylor expanded around 0 2.0

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

    if -1.3622257246714918e+154 < y < -4.0918058340644614e-167

    1. Initial program 0.4

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Simplified0.4

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}}\]
    3. Using strategy rm
    4. Applied add-log-exp0.4

      \[\leadsto \frac{x \cdot x}{x \cdot x + y \cdot y} - \color{blue}{\log \left(e^{\frac{y \cdot y}{x \cdot x + y \cdot y}}\right)}\]
    5. Using strategy rm
    6. Applied add-cbrt-cube0.4

      \[\leadsto \color{blue}{\sqrt[3]{\left(\left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \log \left(e^{\frac{y \cdot y}{x \cdot x + y \cdot y}}\right)\right) \cdot \left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \log \left(e^{\frac{y \cdot y}{x \cdot x + y \cdot y}}\right)\right)\right) \cdot \left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \log \left(e^{\frac{y \cdot y}{x \cdot x + y \cdot y}}\right)\right)}}\]
    7. Simplified0.4

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

    if -1.9618167972718326e-179 < y < 3.050134070228654e-166

    1. Initial program 28.5

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Simplified28.5

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}}\]
    3. Using strategy rm
    4. Applied add-log-exp28.5

      \[\leadsto \frac{x \cdot x}{x \cdot x + y \cdot y} - \color{blue}{\log \left(e^{\frac{y \cdot y}{x \cdot x + y \cdot y}}\right)}\]
    5. Taylor expanded around -inf 14.5

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

    if 3.050134070228654e-166 < y

    1. Initial program 0.4

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Simplified0.4

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}}\]
    3. Using strategy rm
    4. Applied add-log-exp0.4

      \[\leadsto \frac{x \cdot x}{x \cdot x + y \cdot y} - \color{blue}{\log \left(e^{\frac{y \cdot y}{x \cdot x + y \cdot y}}\right)}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification4.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3622257246714918 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -4.0918058340644614 \cdot 10^{-167}:\\ \;\;\;\;\sqrt[3]{\left(\left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right) \cdot \left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right)\right) \cdot \left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right)}\\ \mathbf{elif}\;y \le -1.9618167972718326 \cdot 10^{-179}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 3.050134070228654 \cdot 10^{-166}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \log \left(e^{\frac{y \cdot y}{x \cdot x + y \cdot y}}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019143 
(FPCore (x y)
  :name "Kahan p9 Example"
  :pre (and (< 0 x 1) (< y 1))

  :herbie-target
  (if (< 0.5 (fabs (/ x y)) 2) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1 (/ 2 (+ 1 (* (/ x y) (/ x y))))))

  (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))