Average Error: 15.2 → 0.4
Time: 9.8s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -9.984365809073703929848708018230154758947 \cdot 10^{82} \lor \neg \left(y \le 6.617810863587314615453058275008041291286 \cdot 10^{-52}\right):\\ \;\;\;\;\frac{x \cdot 2}{\frac{x}{y} - 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{x - y} \cdot y\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;y \le -9.984365809073703929848708018230154758947 \cdot 10^{82} \lor \neg \left(y \le 6.617810863587314615453058275008041291286 \cdot 10^{-52}\right):\\
\;\;\;\;\frac{x \cdot 2}{\frac{x}{y} - 1}\\

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

\end{array}
double f(double x, double y) {
        double r342783 = x;
        double r342784 = 2.0;
        double r342785 = r342783 * r342784;
        double r342786 = y;
        double r342787 = r342785 * r342786;
        double r342788 = r342783 - r342786;
        double r342789 = r342787 / r342788;
        return r342789;
}

double f(double x, double y) {
        double r342790 = y;
        double r342791 = -9.984365809073704e+82;
        bool r342792 = r342790 <= r342791;
        double r342793 = 6.6178108635873146e-52;
        bool r342794 = r342790 <= r342793;
        double r342795 = !r342794;
        bool r342796 = r342792 || r342795;
        double r342797 = x;
        double r342798 = 2.0;
        double r342799 = r342797 * r342798;
        double r342800 = r342797 / r342790;
        double r342801 = 1.0;
        double r342802 = r342800 - r342801;
        double r342803 = r342799 / r342802;
        double r342804 = r342797 - r342790;
        double r342805 = r342799 / r342804;
        double r342806 = r342805 * r342790;
        double r342807 = r342796 ? r342803 : r342806;
        return r342807;
}

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.2
Target0.3
Herbie0.4
\[\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 < -9.984365809073704e+82 or 6.6178108635873146e-52 < y

    1. Initial program 16.4

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

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

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

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

    if -9.984365809073704e+82 < y < 6.6178108635873146e-52

    1. Initial program 14.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -9.984365809073703929848708018230154758947 \cdot 10^{82} \lor \neg \left(y \le 6.617810863587314615453058275008041291286 \cdot 10^{-52}\right):\\ \;\;\;\;\frac{x \cdot 2}{\frac{x}{y} - 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{x - y} \cdot y\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< x -1.7210442634149447e81) (* (/ (* 2 x) (- x y)) y) (if (< x 83645045635564432) (/ (* x 2) (/ (- x y) y)) (* (/ (* 2 x) (- x y)) y)))

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