Average Error: 14.9 → 0.3
Time: 27.0s
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):\\ \;\;\;\;\left(y \cdot 2\right) \cdot \frac{x}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{\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):\\
\;\;\;\;\left(y \cdot 2\right) \cdot \frac{x}{x - y}\\

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

\end{array}
double f(double x, double y) {
        double r463339 = x;
        double r463340 = 2.0;
        double r463341 = r463339 * r463340;
        double r463342 = y;
        double r463343 = r463341 * r463342;
        double r463344 = r463339 - r463342;
        double r463345 = r463343 / r463344;
        return r463345;
}

double f(double x, double y) {
        double r463346 = x;
        double r463347 = -3.753217978519068e-87;
        bool r463348 = r463346 <= r463347;
        double r463349 = 1.400872302202355e-45;
        bool r463350 = r463346 <= r463349;
        double r463351 = !r463350;
        bool r463352 = r463348 || r463351;
        double r463353 = y;
        double r463354 = 2.0;
        double r463355 = r463353 * r463354;
        double r463356 = r463346 - r463353;
        double r463357 = r463346 / r463356;
        double r463358 = r463355 * r463357;
        double r463359 = r463346 * r463354;
        double r463360 = r463346 / r463353;
        double r463361 = 1.0;
        double r463362 = r463360 - r463361;
        double r463363 = r463359 / r463362;
        double r463364 = r463352 ? r463358 : r463363;
        return r463364;
}

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.8

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

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

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

    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 *-un-lft-identity0.0

      \[\leadsto \frac{x \cdot 2}{\frac{x - y}{\color{blue}{1 \cdot y}}}\]
    5. Applied *-un-lft-identity0.0

      \[\leadsto \frac{x \cdot 2}{\frac{\color{blue}{1 \cdot \left(x - y\right)}}{1 \cdot y}}\]
    6. Applied times-frac0.0

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

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

      \[\leadsto \frac{x \cdot 2}{1 \cdot \color{blue}{\left(\frac{x}{y} - 1\right)}}\]
  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):\\ \;\;\;\;\left(y \cdot 2\right) \cdot \frac{x}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x}{y} - 1}\\ \end{array}\]

Reproduce

herbie shell --seed 2019179 +o rules:numerics
(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)))