Average Error: 15.1 → 0.1
Time: 27.5s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -6.30586821746719046822219898487595819847 \cdot 10^{45}:\\ \;\;\;\;\frac{y}{x - y} \cdot \left(x \cdot 2\right)\\ \mathbf{elif}\;y \le 5.377814118926896018584556610780517528545 \cdot 10^{-32}:\\ \;\;\;\;\frac{x}{x - y} \cdot \left(2 \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{x - y} \cdot \left(x \cdot 2\right)\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;y \le -6.30586821746719046822219898487595819847 \cdot 10^{45}:\\
\;\;\;\;\frac{y}{x - y} \cdot \left(x \cdot 2\right)\\

\mathbf{elif}\;y \le 5.377814118926896018584556610780517528545 \cdot 10^{-32}:\\
\;\;\;\;\frac{x}{x - y} \cdot \left(2 \cdot y\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{y}{x - y} \cdot \left(x \cdot 2\right)\\

\end{array}
double f(double x, double y) {
        double r29518902 = x;
        double r29518903 = 2.0;
        double r29518904 = r29518902 * r29518903;
        double r29518905 = y;
        double r29518906 = r29518904 * r29518905;
        double r29518907 = r29518902 - r29518905;
        double r29518908 = r29518906 / r29518907;
        return r29518908;
}

double f(double x, double y) {
        double r29518909 = y;
        double r29518910 = -6.30586821746719e+45;
        bool r29518911 = r29518909 <= r29518910;
        double r29518912 = x;
        double r29518913 = r29518912 - r29518909;
        double r29518914 = r29518909 / r29518913;
        double r29518915 = 2.0;
        double r29518916 = r29518912 * r29518915;
        double r29518917 = r29518914 * r29518916;
        double r29518918 = 5.377814118926896e-32;
        bool r29518919 = r29518909 <= r29518918;
        double r29518920 = r29518912 / r29518913;
        double r29518921 = r29518915 * r29518909;
        double r29518922 = r29518920 * r29518921;
        double r29518923 = r29518919 ? r29518922 : r29518917;
        double r29518924 = r29518911 ? r29518917 : r29518923;
        return r29518924;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original15.1
Target0.4
Herbie0.1
\[\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 y < -6.30586821746719e+45 or 5.377814118926896e-32 < y

    1. Initial program 16.7

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity16.7

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

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

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

    if -6.30586821746719e+45 < y < 5.377814118926896e-32

    1. Initial program 13.6

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
    2. Using strategy rm
    3. Applied associate-/l*14.8

      \[\leadsto \color{blue}{\frac{x \cdot 2}{\frac{x - y}{y}}}\]
    4. Using strategy rm
    5. Applied div-inv14.9

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -6.30586821746719046822219898487595819847 \cdot 10^{45}:\\ \;\;\;\;\frac{y}{x - y} \cdot \left(x \cdot 2\right)\\ \mathbf{elif}\;y \le 5.377814118926896018584556610780517528545 \cdot 10^{-32}:\\ \;\;\;\;\frac{x}{x - y} \cdot \left(2 \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{x - y} \cdot \left(x \cdot 2\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019171 
(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)))