Average Error: 14.6 → 0.6
Time: 9.0s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -4.287284232108416106066864366743565298507 \cdot 10^{48}:\\ \;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -1.589170604265435174984094851901889510014 \cdot 10^{-299}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -0.0:\\ \;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le 1.970871734171082082394253114435156426509 \cdot 10^{-7}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{-1 + \frac{x}{y}}{2}}\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -4.287284232108416106066864366743565298507 \cdot 10^{48}:\\
\;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\

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

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

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

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

\end{array}
double f(double x, double y) {
        double r326789 = x;
        double r326790 = 2.0;
        double r326791 = r326789 * r326790;
        double r326792 = y;
        double r326793 = r326791 * r326792;
        double r326794 = r326789 - r326792;
        double r326795 = r326793 / r326794;
        return r326795;
}

double f(double x, double y) {
        double r326796 = x;
        double r326797 = 2.0;
        double r326798 = r326796 * r326797;
        double r326799 = y;
        double r326800 = r326798 * r326799;
        double r326801 = r326796 - r326799;
        double r326802 = r326800 / r326801;
        double r326803 = -4.287284232108416e+48;
        bool r326804 = r326802 <= r326803;
        double r326805 = r326799 / r326801;
        double r326806 = r326798 * r326805;
        double r326807 = -1.5891706042654352e-299;
        bool r326808 = r326802 <= r326807;
        double r326809 = -0.0;
        bool r326810 = r326802 <= r326809;
        double r326811 = 1.970871734171082e-07;
        bool r326812 = r326802 <= r326811;
        double r326813 = -1.0;
        double r326814 = r326796 / r326799;
        double r326815 = r326813 + r326814;
        double r326816 = r326815 / r326797;
        double r326817 = r326796 / r326816;
        double r326818 = r326812 ? r326802 : r326817;
        double r326819 = r326810 ? r326806 : r326818;
        double r326820 = r326808 ? r326802 : r326819;
        double r326821 = r326804 ? r326806 : r326820;
        return r326821;
}

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.6
Target0.3
Herbie0.6
\[\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 3 regimes
  2. if (/ (* (* x 2.0) y) (- x y)) < -4.287284232108416e+48 or -1.5891706042654352e-299 < (/ (* (* x 2.0) y) (- x y)) < -0.0

    1. Initial program 47.1

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

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

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

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

    if -4.287284232108416e+48 < (/ (* (* x 2.0) y) (- x y)) < -1.5891706042654352e-299 or -0.0 < (/ (* (* x 2.0) y) (- x y)) < 1.970871734171082e-07

    1. Initial program 4.8

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

    if 1.970871734171082e-07 < (/ (* (* x 2.0) y) (- x y))

    1. Initial program 29.8

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

      \[\leadsto \color{blue}{\frac{x \cdot 2}{\frac{x - y}{y}}}\]
    4. Using strategy rm
    5. Applied associate-/l*0.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -4.287284232108416106066864366743565298507 \cdot 10^{48}:\\ \;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -1.589170604265435174984094851901889510014 \cdot 10^{-299}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -0.0:\\ \;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le 1.970871734171082082394253114435156426509 \cdot 10^{-7}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{-1 + \frac{x}{y}}{2}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019347 +o rules:numerics
(FPCore (x y)
  :name "Linear.Projection:perspective from linear-1.19.1.3, B"
  :precision binary64

  :herbie-target
  (if (< x -1.7210442634149447e+81) (* (/ (* 2 x) (- x y)) y) (if (< x 83645045635564432) (/ (* x 2) (/ (- x y) y)) (* (/ (* 2 x) (- x y)) y)))

  (/ (* (* x 2) y) (- x y)))