Average Error: 14.9 → 0.3
Time: 26.1s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.75321797851906779486008847671727426178 \cdot 10^{-87} \lor \neg \left(x \le 1.400872302202354975456358848427742881356 \cdot 10^{-45}\right):\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot x}{\frac{x}{y} - 1}\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;x \le -3.75321797851906779486008847671727426178 \cdot 10^{-87} \lor \neg \left(x \le 1.400872302202354975456358848427742881356 \cdot 10^{-45}\right):\\
\;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\

\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot x}{\frac{x}{y} - 1}\\

\end{array}
double f(double x, double y) {
        double r514341 = x;
        double r514342 = 2.0;
        double r514343 = r514341 * r514342;
        double r514344 = y;
        double r514345 = r514343 * r514344;
        double r514346 = r514341 - r514344;
        double r514347 = r514345 / r514346;
        return r514347;
}

double f(double x, double y) {
        double r514348 = x;
        double r514349 = -3.753217978519068e-87;
        bool r514350 = r514348 <= r514349;
        double r514351 = 1.400872302202355e-45;
        bool r514352 = r514348 <= r514351;
        double r514353 = !r514352;
        bool r514354 = r514350 || r514353;
        double r514355 = 2.0;
        double r514356 = r514355 * r514348;
        double r514357 = y;
        double r514358 = r514348 - r514357;
        double r514359 = r514356 / r514358;
        double r514360 = r514359 * r514357;
        double r514361 = r514348 / r514357;
        double r514362 = 1.0;
        double r514363 = r514361 - r514362;
        double r514364 = r514356 / r514363;
        double r514365 = r514354 ? r514360 : r514364;
        return r514365;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original14.9
Target0.4
Herbie0.3
\[\begin{array}{l} \mathbf{if}\;x \lt -1.721044263414944729490876394165887012892 \cdot 10^{81}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \mathbf{elif}\;x \lt 83645045635564432:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -3.753217978519068e-87 or 1.400872302202355e-45 < x

    1. Initial program 13.7

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
    2. Simplified12.6

      \[\leadsto \color{blue}{\frac{x \cdot 2}{\frac{x - y}{y}}}\]
    3. Using strategy rm
    4. Applied div-inv12.7

      \[\leadsto \color{blue}{\left(x \cdot 2\right) \cdot \frac{1}{\frac{x - y}{y}}}\]
    5. Simplified12.1

      \[\leadsto \left(x \cdot 2\right) \cdot \color{blue}{\left(\frac{1}{x - y} \cdot y\right)}\]
    6. Using strategy rm
    7. Applied associate-*r*0.7

      \[\leadsto \color{blue}{\left(\left(x \cdot 2\right) \cdot \frac{1}{x - y}\right) \cdot y}\]
    8. Simplified0.5

      \[\leadsto \color{blue}{\frac{x \cdot 2}{x - y}} \cdot y\]

    if -3.753217978519068e-87 < x < 1.400872302202355e-45

    1. Initial program 16.6

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

      \[\leadsto \color{blue}{\frac{x \cdot 2}{\frac{x - y}{y}}}\]
    3. Using strategy rm
    4. Applied div-sub0.0

      \[\leadsto \frac{x \cdot 2}{\color{blue}{\frac{x}{y} - \frac{y}{y}}}\]
    5. Simplified0.0

      \[\leadsto \frac{x \cdot 2}{\frac{x}{y} - \color{blue}{1}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.75321797851906779486008847671727426178 \cdot 10^{-87} \lor \neg \left(x \le 1.400872302202354975456358848427742881356 \cdot 10^{-45}\right):\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot x}{\frac{x}{y} - 1}\\ \end{array}\]

Reproduce

herbie shell --seed 2019179 
(FPCore (x y)
  :name "Linear.Projection:perspective from linear-1.19.1.3, B"

  :herbie-target
  (if (< x -1.7210442634149447e+81) (* (/ (* 2.0 x) (- x y)) y) (if (< x 8.364504563556443e+16) (/ (* x 2.0) (/ (- x y) y)) (* (/ (* 2.0 x) (- x y)) y)))

  (/ (* (* x 2.0) y) (- x y)))