Average Error: 14.6 → 0.8
Time: 18.4s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -57238629659.91823577880859375:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \mathbf{elif}\;x \le 1.021719397133276368228592954796657675009 \cdot 10^{-140}:\\ \;\;\;\;\frac{2 \cdot x}{\frac{x - y}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;x \le -57238629659.91823577880859375:\\
\;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\

\mathbf{elif}\;x \le 1.021719397133276368228592954796657675009 \cdot 10^{-140}:\\
\;\;\;\;\frac{2 \cdot x}{\frac{x - y}{y}}\\

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

\end{array}
double f(double x, double y) {
        double r19474741 = x;
        double r19474742 = 2.0;
        double r19474743 = r19474741 * r19474742;
        double r19474744 = y;
        double r19474745 = r19474743 * r19474744;
        double r19474746 = r19474741 - r19474744;
        double r19474747 = r19474745 / r19474746;
        return r19474747;
}

double f(double x, double y) {
        double r19474748 = x;
        double r19474749 = -57238629659.918236;
        bool r19474750 = r19474748 <= r19474749;
        double r19474751 = 2.0;
        double r19474752 = r19474751 * r19474748;
        double r19474753 = y;
        double r19474754 = r19474748 - r19474753;
        double r19474755 = r19474752 / r19474754;
        double r19474756 = r19474755 * r19474753;
        double r19474757 = 1.0217193971332764e-140;
        bool r19474758 = r19474748 <= r19474757;
        double r19474759 = r19474754 / r19474753;
        double r19474760 = r19474752 / r19474759;
        double r19474761 = r19474758 ? r19474760 : r19474756;
        double r19474762 = r19474750 ? r19474756 : r19474761;
        return r19474762;
}

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.4
Herbie0.8
\[\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 < -57238629659.918236 or 1.0217193971332764e-140 < x

    1. Initial program 14.0

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

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

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

    if -57238629659.918236 < x < 1.0217193971332764e-140

    1. Initial program 15.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -57238629659.91823577880859375:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \mathbf{elif}\;x \le 1.021719397133276368228592954796657675009 \cdot 10^{-140}:\\ \;\;\;\;\frac{2 \cdot x}{\frac{x - y}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \end{array}\]

Reproduce

herbie shell --seed 2019168 +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)))